home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / libs / icon / bumprevision.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-04  |  2.7 KB  |  126 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: bumprevision.c,v 1.2 1997/02/04 16:06:19 digulla Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include <stdio.h>
  9. #include "icon_intern.h"
  10.  
  11. /*****************************************************************************
  12.  
  13.     NAME */
  14. #include <proto/icon.h>
  15.  
  16.     AROS_LH2(UBYTE *, BumpRevision,
  17.  
  18. /*  SYNOPSIS */
  19.     AROS_LHA(UBYTE *, newname, A0),
  20.     AROS_LHA(UBYTE *, oldname, A1),
  21.  
  22. /*  LOCATION */
  23.     struct Library *, IconBase, 18, Icon)
  24.  
  25. /*  FUNCTION
  26.     Computes the right copy revision for a file name.
  27.  
  28.     INPUTS
  29.     newname  -  a buffer for the new string. Should be at leas 31 bytes.
  30.     oldname  -  the old name to be revisioned.
  31.  
  32.     RESULT
  33.     pointer to the supplied buffer.o
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.  
  41.     SEE ALSO
  42.  
  43.     INTERNALS
  44.  
  45.     HISTORY
  46.  
  47. *****************************************************************************/
  48. {
  49.     AROS_LIBFUNC_INIT
  50.     AROS_LIBBASE_EXT_DECL(struct Library *,IconBase)
  51.     UBYTE tempstr[50]; /* A string to hold the new string, this one is big
  52.               enough to hold any new possible string. Then we
  53.               truncate this one into the newstr  */
  54.     LONG    copy_number = 0;
  55.     BOOL    founddigit    = FALSE;
  56.     UBYTE   c;
  57.     UBYTE * tempstrptr;
  58.     UBYTE * oldnameptr;
  59.  
  60.     tempstrptr = tempstr;
  61.     oldnameptr = oldname;
  62.  
  63.     if (!strncmp (oldname, "copy_", 5))
  64.     {
  65.     /* Just a  usual filename */
  66.     strcpy (tempstr, "copy_of_");
  67.     strcpy (tempstr + 8, oldname);
  68.     }
  69.     else
  70.     {
  71.     /* Possible double or multiple-copy */
  72.     if (!strncmp (oldname,"copy_of_", 8)) /* Is this a first copy ?*/
  73.     {
  74.         /* A double copy */
  75.         strcpy (tempstr, "copy_2_of_");
  76.         strcat (tempstr, oldname + 8);
  77.     }
  78.     else
  79.     {
  80.         /* Possible multiple copy */
  81.         /* Step past "copy_" */
  82.         oldnameptr += 5;
  83.  
  84.         /* Convert number from text into integer */
  85.         while (c = *oldnameptr, ((c>='0') && (c<='9')) )
  86.         {
  87.         /* Get the number of this copy. (copy_xxx_of_) */
  88.         copy_number *= 10;
  89.         copy_number += (c - 0x30);
  90.         oldnameptr  ++;
  91.         founddigit = TRUE;
  92.         }
  93.  
  94.         /* Valid ?    (multiple copy or rubbish ?) */
  95.  
  96.         if (((!strncmp(oldnameptr,"_of_",4)) && founddigit))
  97.         {
  98.         /* convert back from num to text, but first increase copycount */
  99.         copy_number ++;
  100.  
  101.         snprintf (tempstr,
  102.             sizeof (tempstr),
  103.             "copy_%d%s",
  104.             copy_number,
  105.             oldnameptr
  106.         );
  107.         }
  108.         else
  109.         {
  110.         /* Rubbish, add copy_of_ and move into tempstr */
  111.         strcpy (tempstr, "copy_of_");
  112.         strcpy (tempstr + 8, oldname);
  113.         }
  114.     }
  115.     }
  116.  
  117.     /* Truncate tempstr into newstr */
  118.     strncpy (newname, tempstr, 30);
  119.  
  120.     /* Be sure that it is nullterminated */
  121.     newname[30] = 0; /* The 31th character */
  122.  
  123.     return newname;
  124.     AROS_LIBFUNC_EXIT
  125. } /* BumpRevision */
  126.