Skip to content

Commit 1aa5b16

Browse files
kiwi1969TuKo1982WDrijver
authored
Fix bug with previous enhancement (#128)
Co-authored-by: Renaud Schweingruber <TuKo1982@users.noreply.github.com> Co-authored-by: Willem Drijver <60568860+WDrijver@users.noreply.github.com>
1 parent f3f8e58 commit 1aa5b16

4 files changed

Lines changed: 87 additions & 58 deletions

File tree

workbench/libs/datatypes/lockdatatype.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "datatypes_intern.h"
88
#include <datatypes/datatypes.h>
99
#include <proto/exec.h>
10+
//#define DEBUG 1
11+
#include <aros/debug.h>
1012

1113
/*****************************************************************************
1214
@@ -55,11 +57,14 @@
5557
{
5658
AROS_LIBFUNC_INIT
5759

60+
D(bug("datatypes.library/LockDataType: Entered with datatype(%x)\n", dt));
61+
5862
if(dt == NULL || dt->dtn_Length == 0)
5963
return;
6064

6165
ObtainSemaphoreShared(&(GPB(DataTypesBase)->dtb_DTList)->dtl_Lock);
62-
66+
67+
D(bug("datatypes.library/LockDataType: Datatype %x OpenCount being incremented to %d\n", dt, ((struct CompoundDataType *)dt)->OpenCount + 1));
6368
((struct CompoundDataType *)dt)->OpenCount++;
6469

6570
ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_DTList)->dtl_Lock);

workbench/libs/datatypes/obtaindatatypea.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <dos/dos.h>
1212
#include <datatypes/datatypesclass.h>
1313
#include <libraries/iffparse.h>
14-
14+
//#define DEBUG 1
1515
#include <aros/debug.h>
1616

1717
static inline struct DataType *DataTypeFromANode(struct Node *aNode)
@@ -210,15 +210,17 @@ static inline struct DataType *DataTypeFromANode(struct Node *aNode)
210210
break;
211211
}
212212

213-
if(cdt)
213+
if(cdt) {
214+
D(bug("[datatypes.library/ObtainDataTypeA] : Datatype %x OpenCount being incremented to %d\n", cdt, cdt->OpenCount + 1));
214215
cdt->OpenCount++;
216+
}
215217

216218
ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_DTList->dtl_Lock));
217219

218220
if(IoErr() == ERROR_OBJECT_NOT_FOUND)
219221
SetIoErr(DTERROR_COULDNT_OPEN);
220222

221-
D(bug("datatypes.library/ObtainDataType: Done. Returning %x\n", cdt));
223+
D(bug("[datatypes.library/ObtainDataType] : Done. Returning %x\n", cdt));
222224

223225
return (struct DataType *)cdt;
224226

workbench/libs/datatypes/releasedatatype.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "datatypes_intern.h"
88
#include <proto/exec.h>
99
#include <exec/alerts.h>
10+
//#define DEBUG 1
11+
#include <aros/debug.h>
1012

1113
/*****************************************************************************
1214
@@ -50,17 +52,21 @@
5052
{
5153
AROS_LIBFUNC_INIT
5254

53-
if(!dt)
54-
return;
55-
56-
ObtainSemaphoreShared(&(GPB(DataTypesBase)->dtb_DTList)->dtl_Lock);
57-
58-
if(((struct CompoundDataType *)dt)->OpenCount)
59-
((struct CompoundDataType*)dt)->OpenCount--;
60-
else
61-
Alert(AN_Unknown);
62-
63-
ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_DTList)->dtl_Lock);
64-
55+
D(bug("datatypes.library/ReleaseDataType: Entered with datatype(%x)\n", dt));
56+
57+
if (dt)
58+
{
59+
ObtainSemaphoreShared(&(GPB(DataTypesBase)->dtb_DTList)->dtl_Lock);
60+
61+
if(((struct CompoundDataType *)dt)->OpenCount)
62+
((struct CompoundDataType*)dt)->OpenCount--;
63+
else
64+
{
65+
D(bug("datatypes.library/ReleaseDataType : Datatype %x has invalid OpenCount value of %d\n", dt, ((struct CompoundDataType *)dt)->OpenCount));
66+
//Alert(AN_Unknown);
67+
}
68+
69+
ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_DTList)->dtl_Lock);
70+
}
6571
AROS_LIBFUNC_EXIT
6672
} /* ReleaseDataType */

workbench/utilities/MultiView/main.c

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#include "global.h"
1212
#include "compilerspecific.h"
13-
#include "debug.h"
13+
//#define DEBUG 1
14+
#include <aros/debug.h>
1415
#include "arossupport.h"
1516

1617
#include <setjmp.h>
@@ -213,8 +214,8 @@ void Cleanup(CONST_STRPTR msg)
213214
if (cd != BNULL)
214215
CurrentDir(cd); /* restore current directory */
215216

216-
CloseLibs();
217217
CleanupLocale();
218+
CloseLibs();
218219

219220
longjmp(exit_buf, 0);
220221
}
@@ -371,8 +372,18 @@ static void GetFileToolTypes(STRPTR fname)
371372
char *s;
372373

373374
D(bug("[MultiView] %s()\n", __func__));
374-
375-
if ((fname) && (dobj=GetDiskObject(fname)))
375+
if (!fname)
376+
return;
377+
378+
D(bug("[Multiview] Checking ToolTypes in filename = '%s.info'\n", fname));
379+
380+
dobj=GetDiskObject(fname);
381+
if (!dobj)
382+
{
383+
char errtext[81];
384+
Fault(IoErr(), "GetDiskObject() Failed", errtext, 80);
385+
}
386+
else
376387
{
377388
/* We have read the DiskObject (icon) for this arg */
378389
toolarray = (char **)dobj->do_ToolTypes;
@@ -736,7 +747,7 @@ static void OpenDTO(void)
736747

737748
do
738749
{
739-
D(bug("[MultiView] calling NewDTObject\n"));
750+
D(bug("[MultiView] %s calling NewDTObject\n", __func__));
740751

741752
if (!old_dto && bClipBoard)
742753
{
@@ -754,7 +765,7 @@ static void OpenDTO(void)
754765
DTA_TextAttr , (IPTR)&textattr,
755766
TAG_DONE);
756767
}
757-
D(bug("[MultiView] NewDTObject returned %x\n", dto));
768+
D(bug("[MultiView] %s NewDTObject returned %x\n", __func__, dto));
758769

759770
if (!dto)
760771
{
@@ -768,6 +779,7 @@ static void OpenDTO(void)
768779
struct DataType *dtn;
769780
if ((dtn = ObtainDataTypeA(DTST_FILE, (APTR)lock, NULL)))
770781
{
782+
D(bug("[MultiView] %s ObtainDataTypeA returned %x\n", __func__, dtn));
771783
if (!Stricmp(dtn->dtn_Header->dth_Name, "directory"))
772784
{
773785
/* file is a directory and no directory.datatype is installed */
@@ -784,15 +796,17 @@ static void OpenDTO(void)
784796
filename = GetFileName(MSG_ASL_OPEN_TITLE);
785797
if (filename)
786798
{
799+
D(bug("[MultiView] %s calling ReleaseDataType(%x)\n", __func__, dtn));
787800
ReleaseDataType(dtn);
788801
UnLock(lock);
789802
continue;
790803
}
791804
}
805+
D(bug("[MultiView] %s calling ReleaseDataType(%x)\n", __func__, dtn));
792806
ReleaseDataType(dtn);
793807
}
794808
UnLock(lock);
795-
}
809+
}
796810
}
797811

798812
if (errnum >= DTERROR_UNKNOWN_DATATYPE)
@@ -931,6 +945,7 @@ static void OpenDTO(void)
931945
if (old_dto)
932946
{
933947
if (win) RemoveDTObject(win, old_dto);
948+
D(bug("[MultiView] %s: calling DisposeDTOObject(%x)\n", __func__, old_dto));
934949
DisposeDTObject(old_dto);
935950

936951
if (win)
@@ -975,6 +990,7 @@ static void CloseDTO(void)
975990
if (dto)
976991
{
977992
if (win) RemoveDTObject(win, dto);
993+
D(bug("[MultiView] %s: calling DisposeDTOObject(%x)\n", __func__, dto));
978994
DisposeDTObject(dto);
979995
dto = NULL;
980996
}
@@ -1810,49 +1826,46 @@ int main(int argc, char **argv)
18101826
tdt_text_wordwrap = TRUE;
18111827
separate_screen = FALSE;
18121828

1829+
OpenLibs();
18131830
InitDefaultFont(); /* May be overridden in GetArguments() if user specifies a font */
18141831
InitLocale("System/Utilities/MultiView.catalog", 2);
18151832
InitMenus(nm);
18161833
InitMenus(nmpict);
18171834
InitMenus(nmtext);
1818-
OpenLibs();
18191835

18201836
if (FromWb)
18211837
{
18221838
WBenchMsg = (struct WBStartup *) argv;
1823-
wbarg = WBenchMsg->sm_ArgList;
1824-
1825-
/* Note wbarg++ at end of FOR statement steps through wbargs.
1826-
* First arg is our executable (tool). Any additional args
1827-
* are projects/icons passed to us via either extend select
1828-
* or default tool method.
1829-
* In our case, we only care about 2nd arg which is the filename
1830-
*/
1831-
1839+
char filepath[256];
1840+
18321841
if ( WBenchMsg->sm_NumArgs > 0)
1833-
{
1834-
/* Pass 1 gets any Tooltypes from MultiView Icon
1835-
Pass 2 gets any Tooltypes from file icon, overlaying MultiView Icon Tooltypes
1836-
*/
1837-
for (int i = 0; i < 2 && i < WBenchMsg->sm_NumArgs; i++)
1842+
{
1843+
wbarg = WBenchMsg->sm_ArgList;
1844+
/* Look at icon for Multiview program */
1845+
if (wbarg->wa_Lock)
18381846
{
1839-
if ( *wbarg->wa_Name )
1840-
{
1841-
/* if there's a directory lock for this wbarg, CD there */
1842-
cd = -1;
1843-
if (wbarg->wa_Lock)
1844-
cd = CurrentDir(wbarg->wa_Lock);
1845-
1846-
if (i > 0 )
1847-
filename = wbarg->wa_Name;
1848-
1849-
GetFileToolTypes(wbarg->wa_Name);
1850-
1851-
if (cd != -1)
1852-
CurrentDir(cd); /* CD back where we were */
1853-
}
1854-
wbarg++;
1847+
NameFromLock(wbarg->wa_Lock, filepath, 256);
1848+
strcat(filepath,"/");
1849+
strcat(filepath, wbarg->wa_Name);
1850+
GetFileToolTypes(filepath); /*defaults from Multiview Icon*/
18551851
}
1852+
else
1853+
D(bug("[MultiView] No wa_lock exits for program = %s\n", wbarg->wa_Name));
1854+
}
1855+
if ( WBenchMsg->sm_NumArgs > 1)
1856+
{
1857+
wbarg++; /* skip to input file */
1858+
D(bug("[MultiView] filename = %s\n", wbarg->wa_Name));
1859+
if (wbarg->wa_Lock)
1860+
{
1861+
NameFromLock(wbarg->wa_Lock, filepath, 256);
1862+
strcat(filepath,"/");
1863+
strcat(filepath, wbarg->wa_Name);
1864+
filename = filepath;
1865+
D(bug("[MultiView] Fully qualified filename = %s\n", filename));
1866+
}
1867+
else
1868+
D(bug("[MultiView] No lock exits for filename = %s\n", wbarg->wa_Name));
18561869
}
18571870
}
18581871
else /* from CLI */
@@ -1861,17 +1874,20 @@ int main(int argc, char **argv)
18611874
{
18621875
Fault(IoErr(), 0, s, 256);
18631876
Cleanup(s);
1864-
}
1865-
GetArguments();
1877+
}
1878+
1879+
GetArguments(); /* get filename and other options also */
18661880
}
18671881

1882+
/* if running with no filename, then maybe bring up a requester */
18681883
if (!filename && bRequester && !bWindow && !bClipBoard)
18691884
filename = GetFileName(MSG_ASL_OPEN_TITLE);
18701885

1871-
if (filename)
1886+
/* did we select a file ? If so, check to see if it has an icon to get options from*/
1887+
if (filename)
18721888
GetFileToolTypes(filename);
18731889

1874-
/* ensure CLI parms beat icon parms */
1890+
/* ensure CLI parms (other than filename) beat icon parms */
18751891
if (!FromWb)
18761892
GetArguments();
18771893

0 commit comments

Comments
 (0)