5 Copyright (C) 2001-2008 Neil Cafferkey
7 This file is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 This file is distributed in the hope that it will be useful, but
13 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 You should have received a copy of the GNU Lesser General Public
18 License along with this file; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 #include "handler_protos.h"
29 /****i* ram.handler/SetString **********************************************
35 * block_diff = SetString(field, new_str)
37 * PINT SetString(TEXT **, TEXT *);
53 ****************************************************************************
57 PINT
SetString(struct Handler
*handler
, TEXT
**field
, const TEXT
*new_str
)
61 TEXT
*str_copy
= NULL
, *old_str
;
64 /* Allocate new string */
66 size
= StrSize(new_str
);
69 str_copy
= AllocPooled(handler
->muddy_pool
, size
);
72 CopyMem(new_str
, str_copy
, size
);
75 error
= ERROR_DISK_FULL
;
82 /* Deallocate old string */
85 block_diff
= MEMBLOCKS(size
);
89 size
= StrSize(old_str
);
90 FreePooled(handler
->muddy_pool
, old_str
, size
);
91 block_diff
-= MEMBLOCKS(size
);
94 /* Store new string */
99 /* Store error and return difference in block utilisation */
107 /****i* ram.handler/SwapStrings ********************************************
113 * block_diff = SwapStrings(field1, field2)
115 * PINT SwapStrings(TEXT **, TEXT **);
131 ****************************************************************************
135 PINT
SwapStrings(TEXT
**field1
, TEXT
**field2
)
142 block_diff
= MEMBLOCKS(StrSize(str1
));
146 block_diff
-= MEMBLOCKS(StrSize(str2
));
151 /* Return difference in block utilisation */
158 /****i* ram.handler/StrLen *************************************************
166 * UPINT StrLen(TEXT *);
182 ****************************************************************************
186 UPINT
StrLen(const TEXT
*s
)
190 for(p
= s
; *p
!= '\0'; p
++);
196 /****i* ram.handler/StrSize ************************************************
204 * UPINT StrSize(TEXT *);
209 * s - The string (may be NULL).
212 * size - Size of the string in bytes including terminating NUL.
222 ****************************************************************************
226 UPINT
StrSize(const TEXT
*s
)
240 return length
* sizeof(TEXT
);
245 /****i* ram.handler/FindNameNoCase *****************************************
251 * node = FindNameNoCase(handler, start, name)
253 * struct Node *FindNameNoCase(struct Handler *handler, struct List *, TEXT *);
269 ****************************************************************************
273 struct Node
*FindNameNoCase(struct Handler
*handler
, struct List
*start
, const TEXT
*name
)
275 struct Node
*node
, *next_node
, *matching_node
;
278 matching_node
= NULL
;
279 node
= start
->lh_Head
;
283 next_node
= node
->ln_Succ
;
284 if(next_node
!= NULL
)
286 node_name
= node
->ln_Name
;
287 if(node_name
!= NULL
)
288 if(Stricmp(name
, node_name
) == 0)
290 matching_node
= node
;
297 return matching_node
;
302 /****i* ram.handler/MyMakeDosEntry *****************************************
308 * dos_entry = MyMakeDosEntry(handler, name, type)
310 * struct DosList *MyMakeDosEntry(struct Handler *handler, TEXT *, LONG);
326 ****************************************************************************
330 struct DosList
*MyMakeDosEntry(struct Handler
*handler
, const TEXT
*name
, LONG type
)
332 struct DosList
*entry
;
335 entry
= AllocMem(sizeof(struct DosList
), MEMF_CLEAR
| MEMF_PUBLIC
);
339 if(!MyRenameDosEntry(handler
, entry
, name
))
341 entry
->dol_Type
= type
;
348 MyFreeDosEntry(handler
, entry
);
358 /****i* ram.handler/MyFreeDosEntry *****************************************
364 * MyFreeDosEntry(handler, entry)
366 * VOID MyFreeDosEntry(struct Handler *handler, struct DosList *);
382 ****************************************************************************
386 VOID
MyFreeDosEntry(struct Handler
*handler
, struct DosList
*entry
)
390 MyRenameDosEntry(handler
, entry
, NULL
);
391 FreeMem(entry
, sizeof(struct DosList
));
399 /****i* ram.handler/MyRenameDosEntry ***************************************
402 * MyRenameDosEntry --
405 * success = MyRenameDosEntry(entry, name)
407 * BOOL MyRenameDosEntry(struct DosList *, TEXT *);
423 ****************************************************************************
428 BOOL
MyRenameDosEntry(struct Handler
*handler
, struct DosList
*entry
, const TEXT
*name
)
432 TEXT
*name_copy
, *old_name
;
434 /* Allocate new string */
439 length
= StrLen(name
);
440 #ifdef AROS_FAST_BPTR
441 name_copy
= AllocVec(length
+ 1, MEMF_PUBLIC
);
442 if(name_copy
!= NULL
)
444 CopyMem(name
, name_copy
, length
+ 1);
447 name_copy
= AllocVec(length
+ 2, MEMF_PUBLIC
);
448 if(name_copy
!= NULL
)
450 name_copy
[0] = (UBYTE
)(length
> 255 ? 255 : length
);
451 CopyMem(name
, name_copy
+ 1, length
+ 1);
458 /* Deallocate old string and set new one */
462 old_name
= BADDR(entry
->dol_Name
);
465 entry
->dol_Name
= MKBADDR(name_copy
);
468 /* Store error code and return success flag */
477 BOOL
MyRenameDosEntry(struct DosList
*entry
, const TEXT
*name
)
481 TEXT
*name_copy
, *old_name
;
483 /* Allocate new string */
488 length
= StrLen(name
);
489 name_copy
= AllocVec(length
+ 2, MEMF_PUBLIC
);
490 if(name_copy
!= NULL
)
492 CopyMem(name
, name_copy
+ 1, length
+ 1);
499 /* Deallocate old string and set new one */
503 old_name
= BADDR(entry
->dol_Name
);
506 entry
->dol_Name
= MKBADDR(name_copy
);
509 /* Store error code and return success flag */