grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / icon / bumprevision.c
blobbbed2bf28a0c74870fffa9c6177b9fe2f4e98b90
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 IconBase *, 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 * oldnameptr;
54 oldnameptr = oldname;
56 if (!strncmp (oldname, "copy_", 5))
58 /* Just a usual filename */
59 strcpy (tempstr, "copy_of_");
60 strcpy (tempstr + 8, oldname);
62 else
64 /* Possible double or multiple-copy */
65 if (!strncmp (oldname,"copy_of_", 8)) /* Is this a first copy ?*/
67 /* A double copy */
68 strcpy (tempstr, "copy_2_of_");
69 strcat (tempstr, oldname + 8);
71 else
73 /* Possible multiple copy */
74 /* Step past "copy_" */
75 oldnameptr += 5;
77 /* Convert number from text into integer */
78 while (c = *oldnameptr, ((c>='0') && (c<='9')) )
80 /* Get the number of this copy. (copy_xxx_of_) */
81 copy_number *= 10;
82 copy_number += (c - 0x30);
83 oldnameptr ++;
84 founddigit = TRUE;
87 /* Valid ? (multiple copy or rubbish ?) */
89 if (((!strncmp(oldnameptr,"_of_",4)) && founddigit))
91 /* convert back from num to text, but first increase copycount */
92 copy_number ++;
94 snprintf (tempstr,
95 sizeof (tempstr),
96 "copy_%ld%s",
97 (long)copy_number,
98 oldnameptr
101 else
103 /* Rubbish, add copy_of_ and move into tempstr */
104 strcpy (tempstr, "copy_of_");
105 strcpy (tempstr + 8, oldname);
110 /* Truncate tempstr into newstr */
111 strncpy (newname, tempstr, 30);
113 /* Be sure that it is nullterminated */
114 newname[30] = 0; /* The 31th character */
116 return newname;
117 AROS_LIBFUNC_EXIT
118 } /* BumpRevision */