home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume1 / 8707 / 66 / arcmisc.c < prev    next >
C/C++ Source or Header  |  1990-07-13  |  2KB  |  70 lines

  1. #include <stdio.h>
  2. #include "arc.h"
  3.  
  4. /*    split up a file name (subroutine for makefnam)
  5.  *
  6.  * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
  7.  *     Bludgeoned into submission for VAX 11/780 BSD4.2
  8.  *    (ugly code, but fewer core dumps)
  9. */
  10.  
  11. static INT _makefn(source,dest)
  12. unsigned char *source;
  13. unsigned char *dest;
  14. {
  15.  INT j;
  16.  
  17.     setmem (dest, 17, 0);    /* clear result field */
  18.     if (strlen (source) > 1 && source[1] == ':')
  19.     for (j = 0; j < 2;)
  20.         dest[j++] = *source++;
  21.     for (j = 3; *source && *source != '.'; ++source)
  22.     if (j < 11)
  23.         dest[j++] = *source;
  24.     for (j = 12; *source; ++source)
  25.     if (j < 16)
  26.         dest[j++] = *source;
  27. }
  28. /*    make a file name using a template
  29. */
  30.  
  31. char *makefnam(rawfn,template,result)
  32. unsigned char *rawfn;            /* the original file name */
  33. unsigned char *template;        /* the template data */
  34. unsigned char *result;            /* where to place the result */
  35. {
  36.   unsigned char et[17],er[17];
  37.  
  38.   _makefn(template,et);
  39.   _makefn(rawfn,er);
  40.   *result=0;            /* assure no data */
  41.   strcat(result,er[0]?er:et);
  42.   strcat(result,er[3]?er+3:et+3);
  43.   strcat(result,er[12]?er+12:et+12);
  44.   return ((char *)&result[0]);
  45. }
  46.  
  47. INT freedir(dirs)
  48. register struct direct **dirs;
  49. {
  50.     register INT ii;
  51.  
  52.     if(dirs == (struct direct **)0)
  53.         return(-1);
  54.     for(ii = 0; dirs[ii] != (struct direct *)0; ii++)
  55.         free(dirs[ii]);
  56.     free(dirs);
  57.     return(0);
  58. }
  59.  
  60. #if MSDOS
  61. #include <dir.h>
  62.  
  63. INT alphasort(dirptr1, dirptr2)
  64. struct direct **dirptr1, **dirptr2;
  65. {
  66.     return(strcmp((*dirptr1)->d_name, (*dirptr2)->d_name));
  67. }
  68.  
  69. #endif
  70.