1 /***************************************************************************
3 BetterString.mcc - A better String gadget MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005 by BetterString.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 BetterString class Support Site: http://www.sf.net/projects/bstring-mcc/
21 ***************************************************************************/
26 #include <proto/dos.h>
27 #include <proto/exec.h>
28 #include <proto/intuition.h>
29 #include <proto/utility.h>
31 #include "BetterString_mcc.h"
34 BOOL
OverwriteA (STRPTR text
, UWORD x
, UWORD length
, UWORD ptrn_length
, struct InstData
*data
)
38 if(length
< ptrn_length
)
40 UWORD expand
= ptrn_length
-length
;
42 if(data
->MaxLength
&& strlen(data
->Contents
)+expand
> data
->MaxLength
-1)
44 ptrn_length
-= expand
;
45 ptrn_length
+= (data
->MaxLength
-1)-strlen(data
->Contents
);
48 data
->Contents
= (STRPTR
)ExpandPool(data
->Pool
, data
->Contents
, expand
);
49 strcpyback(data
->Contents
+x
+ptrn_length
, data
->Contents
+x
+length
);
53 strcpy(data
->Contents
+x
+ptrn_length
, data
->Contents
+x
+length
);
55 CopyMem(text
, data
->Contents
+x
, ptrn_length
);
57 if(data
->BufferPos
>= x
)
59 data
->BufferPos
+= ptrn_length
-length
;
60 if(data
->BufferPos
< x
)
70 BOOL
Overwrite (STRPTR text
, UWORD x
, UWORD length
, struct InstData
*data
)
72 return(OverwriteA(text
, x
, length
, strlen(text
), data
));
75 WORD
VolumeStart (STRPTR text
, WORD pos
)
77 BOOL searching
= TRUE
;
79 while(pos
> 0 && searching
)
96 LONG
FileNameStart (struct MUIP_BetterString_FileNameStart
*msg
)
98 STRPTR buffer
= msg
->buffer
;
101 while(pos
&& buffer
[pos
] != ':')
104 if(buffer
[pos
] == ':')
105 pos
= VolumeStart(buffer
, pos
);
106 else pos
= MUIR_BetterString_FileNameStart_Volume
;
111 VOID
InsertFileName (UWORD namestart
, struct InstData
*data
)
113 struct ExAllData
*ead1
= &data
->FNCBuffer
->buffer
;
114 struct ExAllData
*ead2
;
115 struct FNCData
*fncframe
;
116 struct FNCData
*fncframe1
= data
->FNCBuffer
;
118 UWORD findnum
= data
->FileNumber
;
124 fncframe
= data
->FNCBuffer
;
125 ead2
= &fncframe
->buffer
;
128 //if(CmpStrings(ead1->ed_Name, ead2->ed_Name) > 0)
129 if(strcmp(ead1
->ed_Name
, ead2
->ed_Name
) > 0)
132 ead2
= ead2
->ed_Next
;
133 if(!ead2
&& fncframe
->next
)
135 fncframe
= fncframe
->next
;
136 ead2
= &fncframe
->buffer
;
140 if(entrynum
!= findnum
)
141 ead1
= ead1
->ed_Next
;
142 if(!ead1
&& fncframe1
->next
)
144 fncframe1
= fncframe1
->next
;
145 ead1
= &fncframe1
->buffer
;
147 } while(entrynum
!= findnum
);
149 strcpy(tmpname
, ead1
->ed_Name
);
150 strcat(tmpname
, ead1
->ed_Type
== 2 ? "/" : " ");
152 Overwrite(tmpname
, namestart
, data
->BufferPos
-namestart
, data
);
155 BOOL
FileNameComplete (Object
*obj
, BOOL backwards
, struct InstData
*data
)
160 if(data
->FileEntries
== 1)
168 if(--data
->FileNumber
< 0)
169 data
->FileNumber
= data
->FileEntries
-1;
173 if(++data
->FileNumber
>= data
->FileEntries
)
174 data
->FileNumber
= 0;
177 InsertFileName(data
->FileNameStart
, data
);
183 switch(pos
= DoMethod(obj
, MUIM_BetterString_FileNameStart
, data
->Contents
, data
->BufferPos
))
185 case MUIR_BetterString_FileNameStart_Volume
:
188 STRPTR VolumeName
= NULL
;
191 pos
= VolumeStart(data
->Contents
, data
->BufferPos
);
192 if((cut
= data
->BufferPos
-pos
))
194 dl
= LockDosList(LDF_READ
|LDF_DEVICES
|LDF_VOLUMES
|LDF_ASSIGNS
);
195 while((dl
= NextDosEntry(dl
, LDF_READ
|LDF_DEVICES
|LDF_VOLUMES
|LDF_ASSIGNS
)))
198 STRPTR NodeName
= dl
->dol_Ext
.dol_AROS
.dol_DevName
;
200 STRPTR NodeName
= (STRPTR
)((dl
->dol_Name
<< 2)+1);
202 if(!Strnicmp(NodeName
, data
->Contents
+pos
, cut
))
204 VolumeName
= NodeName
;
212 if(OverwriteA(VolumeName
, pos
, cut
, strlen(VolumeName
)+1, data
))
213 data
->Contents
[data
->BufferPos
-1] = ':';
215 if(OverwriteA(VolumeName
, pos
, cut
, *(VolumeName
-1)+1, data
))
216 data
->Contents
[data
->BufferPos
-1] = ':';
220 UnLockDosList(LDF_READ
|LDF_DEVICES
|LDF_VOLUMES
|LDF_ASSIGNS
);
227 struct FNCData
*fncbuffer
;
228 struct FNCData
*fncframe
;
229 struct ExAllControl
*control
;
232 UWORD namestart
= data
->BufferPos
;
234 BOOL filename
= TRUE
;
238 switch(*(data
->Contents
+namestart
-1))
250 if((data
->BufferPos
-namestart
) < 32)
252 strncpy(pattern
, data
->Contents
+namestart
, data
->BufferPos
-namestart
);
253 oldletter
= data
->Contents
[namestart
];
254 strcpy(pattern
+(data
->BufferPos
-namestart
), "~(#?.info)");
255 data
->Contents
[namestart
] = '\0';
257 if((fncbuffer
= (struct FNCData
*)MyAllocPooled(data
->Pool
, 4100)))
259 fncbuffer
->next
= NULL
;
261 if((control
= (struct ExAllControl
*)AllocDosObject(DOS_EXALLCONTROL
, NULL
)))
265 if(ParsePatternNoCase(pattern
, tokenized
, 40) != -1)
266 control
->eac_MatchString
= tokenized
;
268 if((dirlock
= Lock(data
->Contents
+pos
, ACCESS_READ
)))
272 fncframe
= fncbuffer
;
273 while(fncframe
&& ExAll(dirlock
, &fncframe
->buffer
, 4096, ED_TYPE
, control
))
275 entries
+= control
->eac_Entries
;
277 if((fncframe
->next
= (struct FNCData
*)MyAllocPooled(data
->Pool
, 4100)))
278 fncframe
->next
->next
= NULL
;
280 fncframe
= fncframe
->next
;
282 control
->eac_Entries
+= entries
;
284 data
->FileNumber
= backwards
? control
->eac_Entries
-1 : 0;
285 data
->FileEntries
= control
->eac_Entries
;
286 data
->FileNameStart
= namestart
;
287 data
->FNCBuffer
= fncbuffer
;
289 if(control
->eac_Entries
)
291 data
->Contents
[namestart
] = oldletter
;
292 InsertFileName(namestart
, data
);
297 FreeDosObject(DOS_EXALLCONTROL
, (APTR
)control
);
302 data
->Contents
[namestart
] = oldletter
;