Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / icon / bumprevision.c
blobbfe922e7e8370ee1dd5bbb00a7c9777c5e8dfeb1
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include "icon_intern.h"
9 /*****************************************************************************
11 NAME */
12 #include <proto/icon.h>
14 AROS_LH2(UBYTE *, BumpRevision,
16 /* SYNOPSIS */
17 AROS_LHA(UBYTE *, newname, A0),
18 AROS_LHA(UBYTE *, oldname, A1),
20 /* LOCATION */
21 struct Library *, IconBase, 18, Icon)
23 /* FUNCTION
24 Computes the right copy revision for a file name.
26 INPUTS
27 newname - a buffer for the new string. Should be at leas 31 bytes.
28 oldname - the old name to be revisioned.
30 RESULT
31 pointer to the supplied buffer.o
33 NOTES
35 EXAMPLE
37 BUGS
39 SEE ALSO
41 INTERNALS
43 *****************************************************************************/
45 AROS_LIBFUNC_INIT
46 UBYTE tempstr[50]; /* A string to hold the new string, this one is big
47 enough to hold any new possible string. Then we
48 truncate this one into the newstr */
49 LONG copy_number = 0;
50 BOOL founddigit = FALSE;
51 UBYTE c;
52 UBYTE * tempstrptr;
53 UBYTE * oldnameptr;
55 tempstrptr = tempstr;
56 oldnameptr = oldname;
58 if (!strncmp (oldname, "copy_", 5))
60 /* Just a usual filename */
61 strcpy (tempstr, "copy_of_");
62 strcpy (tempstr + 8, oldname);
64 else
66 /* Possible double or multiple-copy */
67 if (!strncmp (oldname,"copy_of_", 8)) /* Is this a first copy ?*/
69 /* A double copy */
70 strcpy (tempstr, "copy_2_of_");
71 strcat (tempstr, oldname + 8);
73 else
75 /* Possible multiple copy */
76 /* Step past "copy_" */
77 oldnameptr += 5;
79 /* Convert number from text into integer */
80 while (c = *oldnameptr, ((c>='0') && (c<='9')) )
82 /* Get the number of this copy. (copy_xxx_of_) */
83 copy_number *= 10;
84 copy_number += (c - 0x30);
85 oldnameptr ++;
86 founddigit = TRUE;
89 /* Valid ? (multiple copy or rubbish ?) */
91 if (((!strncmp(oldnameptr,"_of_",4)) && founddigit))
93 /* convert back from num to text, but first increase copycount */
94 copy_number ++;
96 snprintf (tempstr,
97 sizeof (tempstr),
98 "copy_%ld%s",
99 copy_number,
100 oldnameptr
103 else
105 /* Rubbish, add copy_of_ and move into tempstr */
106 strcpy (tempstr, "copy_of_");
107 strcpy (tempstr + 8, oldname);
112 /* Truncate tempstr into newstr */
113 strncpy (newname, tempstr, 30);
115 /* Be sure that it is nullterminated */
116 newname[30] = 0; /* The 31th character */
118 return newname;
119 AROS_LIBFUNC_EXIT
120 } /* BumpRevision */