home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / unix / patch12.zoo / tcpatch6.dif < prev    next >
Encoding:
Text File  |  1990-08-07  |  6.7 KB  |  233 lines

  1. TurboC2.0 Patches to fix backup name generation
  2. Prereq: 5
  3. *** tcpatlev.h    Tue Aug 07 08:31:10 1990
  4. --- tcpatlev.new    Tue Aug 07 12:09:15 1990
  5. ***************
  6. *** 1,1 ****
  7. ! #define TCPATCHLEVEL 5
  8. --- 1,1 ----
  9. ! #define TCPATCHLEVEL 6
  10. *** readme    Tue Aug 07 08:31:10 1990
  11. --- readme.new    Tue Aug 07 12:13:20 1990
  12. ***************
  13. *** 198,200 ****
  14. --- 198,221 ----
  15.   was snarfed from an old edition of lharc and is more limited than the fancy
  16.   one I posted but it works just fine with patch (it does stdin redirection
  17.   from the invocation of the spawned COMMAND.COM - quite foolproof).
  18. + *** OFFICIAL PATCHLEVEL 12, TurboC2.0 PATCHLEVEL 6
  19. + From: ward@sneezy.cs.wisc.edu (Mike Ward)
  20. + Date: Tue, 07 Aug 90 12:13:00 EST
  21. + The problem is that to generate a backup name the program simply appends
  22. + the suffix (or prepends the prefix). This doesn't go over too well under
  23. + MSDOS.
  24. +
  25. + I modified this procedure to know about file name/extension limits for the
  26. + append case (prepend still messed up). The code now appends only the first
  27. + char of the suffix (hopefully this will be the whole suffix), and if the
  28. + file name is still no good, it starts appending version digits/letters.
  29. + For example:
  30. +
  31. +     filexyz.sou  -> filexyzs.ou~ -> ilexyzso.u~0 -> ilexyzso.u~1 ->
  32. +     ilexyzso.u~2 -> ...          -> ilexyzso.u~9 -> ilexyzso.u~A ->
  33. +     ilexyzso.u~B -> ...          -> ilexyzso.u~Z -> lexyzsou.~0A -> ...
  34. +
  35. *** util.c    Tue Aug 07 10:46:34 1990
  36. --- util.new    Tue Aug 07 13:15:38 1990
  37. ***************
  38. *** 15,20 ****
  39. --- 15,117 ----
  40.   #include "INTERN.h"
  41.   #include "util.h"
  42.   
  43. + #ifdef TURBOC20
  44. + #include <dir.h>
  45. + /* fnappend : Append first char of bext to a MSDOS file name.
  46. +  *            bext should not start with a letter or digit.
  47. +  */
  48. + void
  49. + fnappend(fspec,bext)
  50. + char *fspec, *bext;
  51. + {
  52. +     char *fnmex;
  53. +     char fname[MAXFILE];
  54. +     char fext[MAXEXT];
  55. +     int i,j;
  56. +     int fnlen;
  57. +     int felen;
  58. +     /* fnmex should point to first char of file name/extension
  59. +      * (not path or drive)
  60. +      */
  61. +     fnmex = fspec + strlen(fspec);
  62. +     while ((fnmex!=fspec) && (strchr("/\\:",*(fnmex-1))==NULL)) {
  63. +         fnmex--;
  64. +     }
  65. +     /* get file name and length */
  66. +     for (fnlen=i=0; fnmex[i] && fnmex[i]!= '.' && i<MAXFILE-1; i++) {
  67. +         fname[i] =  fnmex[i];
  68. +         fnlen++;
  69. +     }
  70. +     fname[fnlen] = '\0';
  71. +     /* get file ext and len */
  72. +     while (fnmex[i] && fnmex[i]!='.') {
  73. +         i++;
  74. +     }
  75. +     if (fnmex[i] == '.')
  76. +         i++;
  77. +     for (felen=j=0; fnmex[j+i] && j<MAXEXT-2; j++) {
  78. +         fext[j] =  fnmex[j+i];
  79. +         felen++;
  80. +     }
  81. +     fext[felen] = '\0';
  82. +     /* Three cases:
  83. +      * full filename/ext: 12345678.ABC -> 2345678A.BCX
  84. +      * full file ext:     1234567.ABC  -> 1234567A.BCX
  85. +      * other:             12345678.AB  -> 12345678.ABX
  86. +      */
  87. +     if ((fnlen == MAXFILE-1) && (felen == MAXEXT-2)) {
  88. +         sprintf(fnmex,"%s%c.%s%c",fname+1,fext[0],fext+1,*bext);
  89. +     } else if (felen == MAXEXT-2) {
  90. +         sprintf(fnmex,"%s%c.%s%c",fname,fext[0],fext+1,*bext);
  91. +     } else {
  92. +         sprintf(fnmex,"%s.%s%c",fname,fext,*bext);
  93. +     }
  94. + }
  95. + /* fninc : increment/add last char of/to fspec.
  96. +  *         used with fappend (call fnappend once, then fninc many times
  97. +  */
  98. + void
  99. + fninc(fspec)
  100. + char *fspec;
  101. + {
  102. +     char *cp;
  103. +     int lastp,lastc;
  104. +     lastc = fspec[lastp = strlen(fspec)-1];
  105. +     if (strchr("012345678ABCDEFGHIJKLMNOPQRSTUVWXY",lastc) != NULL) {
  106. +         fspec[lastp]++;
  107. +     } else if (lastc == '9') {
  108. +         fspec[lastp] = 'A';
  109. +     } else if (lastc == 'Z') {
  110. +         for (cp=&fspec[lastp]; *cp=='Z' || *cp=='.'; cp--) {
  111. +             if (*cp == 'Z') {
  112. +                 *cp = '0';
  113. +             }
  114. +         }
  115. +         if (strchr("012345678ABCDEFGHIJKLMNOPQRSTUVWXY",*cp) != NULL) {
  116. +             (*cp)++;
  117. +         } else if (*cp == '9') {
  118. +             *cp = 'A';
  119. +         } else {
  120. +             if (*(cp+1) == '.') cp++;
  121. +             *(cp+1) = '1';
  122. +             fnappend(fspec,"0");
  123. +         }
  124. +     } else {
  125. +         fnappend(fspec,"0");
  126. +     }
  127. + }
  128. + #endif
  129.   /* Rename a file, copying it if necessary. */
  130.   
  131.   int
  132. ***************
  133. *** 44,65 ****
  134.       }
  135.   
  136.       if (origprae) {
  137. !         Strcpy (bakname, origprae);
  138. !         Strcat(bakname, to);
  139.       } else {
  140. !            Strcpy(bakname, to);
  141. !         Strcat(bakname, origext?origext:ORIGEXT);
  142.       }
  143.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  144. - #ifdef TURBOC20
  145.       short to_device = filestat.st_dev;
  146.       short to_mode = filestat.st_mode;
  147.       long  to_size  = filestat.st_size;
  148.       long  to_time  = filestat.st_mtime;
  149.   #else
  150.        dev_t to_device = filestat.st_dev;
  151.        ino_t to_inode  = filestat.st_ino;
  152. - #endif
  153.       char *simplename = bakname;
  154.       
  155.       for (s=bakname; *s; s++) {
  156. --- 141,175 ----
  157.       }
  158.   
  159.       if (origprae) {
  160. !             Strcpy (bakname, origprae);
  161. !             Strcat(bakname, to);
  162.       } else {
  163. !             Strcpy(bakname, to);
  164. ! #ifdef TURBOC20
  165. !             fnappend(bakname, origext?origext:ORIGEXT);
  166.       }
  167.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  168.       short to_device = filestat.st_dev;
  169.       short to_mode = filestat.st_mode;
  170.       long  to_size  = filestat.st_size;
  171.       long  to_time  = filestat.st_mtime;
  172. +     /* find a backup name that is not the same file */
  173. +     while (stat(bakname, &filestat) >= 0 &&
  174. +         to_device == filestat.st_dev &&
  175. +         to_mode == filestat.st_mode &&
  176. +                 to_size == filestat.st_size &&
  177. +                 to_time == filestat.st_mtime
  178. +               ) {
  179. +         fninc(bakname);
  180. +     }
  181.   #else
  182. +             Strcat(bakname, origext?origext:ORIGEXT);
  183. +     }
  184. +     if (stat(to, &filestat) >= 0) {    /* output file exists */
  185.        dev_t to_device = filestat.st_dev;
  186.        ino_t to_inode  = filestat.st_ino;
  187.       char *simplename = bakname;
  188.       
  189.       for (s=bakname; *s; s++) {
  190. ***************
  191. *** 69,81 ****
  192.       /* find a backup name that is not the same file */
  193.       while (stat(bakname, &filestat) >= 0 &&
  194.           to_device == filestat.st_dev &&
  195. - #ifdef TURBOC20
  196. -         to_mode == filestat.st_mode &&
  197. -                 to_size == filestat.st_size &&
  198. -                 to_time == filestat.st_mtime
  199. - #else
  200.                   to_inode == filestat.st_ino
  201. - #endif                
  202.                 ) {
  203.           for (s=simplename; *s && !islower(*s); s++) ;
  204.           if (*s)
  205. --- 179,185 ----
  206. ***************
  207. *** 83,88 ****
  208. --- 187,193 ----
  209.           else
  210.           Strcpy(simplename, simplename+1);
  211.       }
  212. + #endif                
  213.       while (unlink(bakname) >= 0) ;    /* while() is for benefit of Eunice */
  214.   #ifdef DEBUGGING
  215.       if (debug & 4)
  216.