home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / rcs / arcmisc.c,v < prev    next >
Text File  |  1998-04-23  |  22KB  |  1,223 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  patch1:1.8;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.8
  10. date     88.07.31.18.50.56;  author hyc;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     88.06.12.19.23.13;  author hyc;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     88.06.12.18.47.09;  author hyc;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     88.06.01.19.41.20;  author hyc;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     88.06.01.16.06.37;  author hyc;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     88.06.01.15.54.35;  author hyc;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     88.04.11.18.26.38;  author hyc;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     88.04.11.18.21.31;  author hyc;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.8
  55. log
  56. @Fix declarations, add memset() for BSD, removed a few revisions back.
  57. Fix args to fopen.
  58. @
  59. text
  60. @/*
  61.  * Miscellaneous routines to get ARC running on non-MSDOS systems...
  62.  * $Header: arcmisc.c,v 1.7 88/06/12 19:23:13 hyc Locked $ 
  63.  */
  64.  
  65. #include <stdio.h>
  66. #include <ctype.h>
  67. #include "arc.h"
  68.  
  69. #if    MSDOS
  70. #include <dir.h>
  71. #include <stat.h>
  72. #endif
  73.  
  74. #if    GEMDOS
  75. #include <osbind.h>
  76. #include <stat.h>
  77. char           *index(), *rindex();
  78.  
  79. void 
  80. exitpause()
  81. {
  82.     while (Cconis())
  83.         Cnecin();
  84.     fprintf(stderr, "Press any key to continue: ");
  85.     fflush(stderr);
  86.     Cnecin();
  87.     fprintf(stderr, "\n");
  88. }
  89.  
  90. int
  91. chdir(dirname)
  92.     char           *dirname;
  93. {
  94.     char           *i;
  95.     int             drv;
  96.  
  97.     i = dirname;
  98.     if ((i = index(dirname, ':')) != NULL) {
  99.         drv = i[-1];
  100.         i++;        /* Move past device spec */
  101.         if (drv > '\'')
  102.             drv -= 'a';
  103.         else
  104.             drv -= 'A';
  105.         if (drv >= 0 && drv < 16)
  106.             Dsetdrv(drv);
  107.     }
  108.     if (*i != '\0')
  109.         return (Dsetpath(i));
  110. }
  111. #endif
  112.  
  113. #if    UNIX
  114. #include <sys/types.h>
  115. #include <sys/dir.h>
  116. #include <sys/stat.h>
  117.     int    rename(), unlink();
  118. #endif
  119.  
  120. #if    SYSV
  121. #include <dirent.h>
  122. #define DIRECT dirent
  123. #else
  124. #define DIRECT direct
  125. #endif
  126.  
  127. #if    BSD
  128. char    *
  129. memset(s, c, n)        /* oops. Thought it was standard BSD, but my Sun */
  130.     char    *s;    /* fooled me again. -- hyc */
  131.     int    c, n;
  132. {
  133.     register int i;
  134.     for(i=0;i<n;i++)
  135.         s[i]=c;
  136.     return(s);
  137. }
  138. #endif
  139.  
  140. char           *strcpy(), *strcat(), *malloc();
  141. int             strlen(), strcmp(), match();
  142.  
  143. int
  144. move(oldnam, newnam)
  145.     char           *oldnam, *newnam;
  146. {
  147.     FILE           *fopen(), *old, *new;
  148. #if    !MTS
  149.     struct stat     oldstat;
  150. #endif
  151.     char           *strcpy();
  152.     void        filecopy();
  153. #if    GEMDOS
  154.     if (Frename(0, oldnam, newnam))
  155. #else
  156.     if (rename(oldnam, newnam))
  157. #endif
  158. #if    !MTS
  159.     {
  160.         if (stat(oldnam, &oldstat))    /* different partition? */
  161.             return (-1);
  162.         old = fopen(oldnam, OPEN_R);
  163.         if (old == NULL)
  164.             return (-1);
  165.         new = fopen(newnam, OPEN_W);
  166.         if (new == NULL)
  167.             return (-1);
  168.         filecopy(old, new, oldstat.st_size);
  169.         return(unlink(oldnam));
  170.     }
  171.     return 0;
  172. #else
  173.     return(-1);
  174. #endif
  175. }
  176.  
  177. static void
  178. _makefn(source, dest)
  179.     char           *source;
  180.     char           *dest;
  181. {
  182.     int             j;
  183. #if    MSDOS
  184.     char           *setmem();
  185. #else
  186.     char           *memset();
  187. #endif
  188.  
  189.     setmem(dest, 17, 0);    /* clear result field */
  190.     for (j = 0; *source && *source != '.'; ++source)
  191.         if (j < 8)
  192.             dest[j++] = *source;
  193.     for (j = 9; *source; ++source)
  194.         if (j < 13)
  195.             dest[j++] = *source;
  196. }
  197. /*
  198.  * make a file name using a template 
  199.  */
  200.  
  201. char           *
  202. makefnam(rawfn, template, result)
  203.     char           *rawfn;    /* the original file name */
  204.     char           *template;    /* the template data */
  205.     char           *result;    /* where to place the result */
  206. {
  207.     char            et[17], er[17], rawbuf[STRLEN], *i, *rindex();
  208.  
  209.     *rawbuf = 0;
  210.     strcpy(rawbuf, rawfn);
  211. #if    MTS
  212.     i = rawbuf;
  213.     if (rawbuf[0] == tmpchr[0]) {
  214.         i++;
  215.         strcpy(rawfn, i);
  216.     } else
  217. #endif
  218.     if ((i = rindex(rawbuf, CUTOFF))) {
  219.         i++;
  220.         strcpy(rawfn, i);
  221.     }
  222. #if    DOS
  223.     else if ((i = rindex(rawbuf, ':'))) {
  224.         i++;
  225.         strcpy(rawfn, i);
  226.     }
  227. #endif
  228.     if (i)
  229.         *i = 0;
  230.     else
  231.         *rawbuf = 0;
  232.  
  233.     _makefn(template, et);
  234.     _makefn(rawfn, er);
  235.     *result = 0;        /* assure no data */
  236.     strcat(result, rawbuf);
  237.     strcat(result, er[0] ? er : et);
  238.     strcat(result, er[9] ? er + 9 : et + 9);
  239.     return ((char *) &result[0]);
  240. }
  241.  
  242. #if    MSDOS || SYSV
  243.  
  244. int
  245. alphasort(dirptr1, dirptr2)
  246.     struct DIRECT **dirptr1, **dirptr2;
  247. {
  248.     return (strcmp((*dirptr1)->d_name, (*dirptr2)->d_name));
  249. }
  250.  
  251. #endif
  252.  
  253. void
  254. upper(string)
  255.     char           *string;
  256. {
  257.     char           *p;
  258.  
  259.     for (p = string; *p; p++)
  260.         if (islower(*p))
  261.             *p = toupper(*p);
  262. }
  263. /* VARARGS1 */
  264. void
  265. abort(s, arg1, arg2, arg3)
  266.     char           *s;
  267. {
  268.     fprintf(stderr, "ARC: ");
  269.     fprintf(stderr, s, arg1, arg2, arg3);
  270.     fprintf(stderr, "\n");
  271. #if    UNIX
  272.     perror("UNIX");
  273. #endif
  274. #if    GEMDOS
  275.     exitpause();
  276. #endif
  277.     exit(1);
  278. }
  279.  
  280. #if    !MTS
  281.  
  282. char           *
  283. gcdir(dirname)
  284.     char           *dirname;
  285.  
  286. {
  287.     char           *getwd();
  288. #if    GEMDOS
  289.     int             drv;
  290.     char           *buf;
  291. #endif
  292.     if (dirname == NULL || strlen(dirname) == 0)
  293.         dirname = (char *) malloc(1024);
  294.  
  295. #if    !GEMDOS
  296.     getwd(dirname);
  297. #else
  298.     buf = dirname;
  299.     *buf++ = (drv = Dgetdrv()) + 'A';
  300.     *buf++ = ':';
  301.     Dgetpath(buf, 0);
  302. #endif
  303.     return (dirname);
  304. }
  305.  
  306. #if    UNIX
  307. char           *pattern;    /* global so that fmatch can use it */
  308. #endif
  309.  
  310. char           *
  311. dir(filename)        /* get files, one by one */
  312.     char           *filename;    /* template, or NULL */
  313. {
  314. #if    GEMDOS
  315.     static int      Nnum = 0;
  316.     static DMABUFFER dbuf, *saved;
  317.     char           *name;
  318.  
  319.     if (Nnum == 0) {    /* first call */
  320.         saved = (DMABUFFER *) Fgetdta();
  321.         Fsetdta(&dbuf);
  322.         if (Fsfirst(filename, 0) == 0) {
  323.             name = malloc(FNLEN);
  324.             strcpy(name, dbuf.d_fname);
  325.             Nnum++;
  326.             return (name);
  327.         } else {
  328.             Fsetdta(saved);
  329.             return (NULL);
  330.         }
  331.     } else {
  332.         if (Fsnext() == 0) {
  333.             name = malloc(FNLEN);
  334.             strcpy(name, dbuf.d_fname);
  335.             return (name);
  336.         } else {
  337.             Nnum = 0;
  338.             Fsetdta(saved);
  339.             return (NULL);
  340.         }
  341.     }
  342. }
  343. #else
  344.     static struct DIRECT **namelist;
  345.     static char   **NameList;
  346.     static char    namecopy[STRLEN], *dirname;
  347. #if    UNIX
  348.     int             alphasort();
  349.     int             scandir();
  350. #endif                /* UNIX */
  351.     int             fmatch(), free();
  352.     static int      Nnum = 0, ii;
  353.     char        *rindex();
  354.  
  355.  
  356.     if (Nnum == 0) {    /* first call */
  357.         strcpy(namecopy,filename);
  358.         if(pattern=rindex(namecopy,CUTOFF)) {
  359.             *pattern = 0;
  360.             pattern++;
  361.             dirname = namecopy;
  362.         } else {
  363.             pattern = filename;
  364.             dirname = ".";
  365.         }
  366.         Nnum = scandir(dirname, &namelist, fmatch, alphasort);
  367.         NameList = (char **) malloc(Nnum * sizeof(char *));
  368.         for (ii = 0; ii < Nnum; ii++) {
  369.             (NameList)[ii] = malloc(strlen(namelist[ii]->d_name) + 1);
  370.             strcpy((NameList)[ii], namelist[ii]->d_name);
  371.         }
  372.         ii = 0;
  373.     }
  374.     if (ii >= Nnum) {    /* all out of files */
  375.         if (Nnum) {    /* there were some files found */
  376.             for (ii = 0; ii < Nnum; ii++)
  377.                 free(namelist[ii]);
  378.             free(namelist);
  379.         }
  380.         Nnum = 0;
  381.         return (NULL);
  382.     } else {
  383.         return ((NameList)[ii++]);
  384.     }
  385. }
  386.  
  387. /*
  388.  * Filename match - here, * matches everything 
  389.  */
  390.  
  391. int
  392. fmatch(direntry)
  393.     struct DIRECT  *direntry;
  394. {
  395.     char           *string;
  396.  
  397.     string = direntry->d_name;
  398.  
  399.     if (!strcmp(pattern, "") || !strcmp(pattern, "*.*") || !strcmp(pattern, "*"))
  400.         return (1);
  401.     return (match(string, pattern));
  402. }
  403. #endif                /* GEMDOS */
  404. #else
  405. /* dir code for MTS under Bell Labs C... */
  406.  
  407. char           *
  408. dir(filepattern)
  409.     char           *filepattern;    /* template or NULL */
  410. {
  411.     char           *malloc(), *index();
  412. #if    USECATSCAN
  413.     fortran void    catscan(), fileinfo();
  414.  
  415.     struct catname {
  416.         short           len;
  417.         char            name[257];
  418.     }               pattern;
  419.  
  420.     struct catval {
  421.         int             maxlen;
  422.         int             actlen;
  423.         char            name[257];
  424.     }               catreturn;
  425.  
  426.     char           *i;
  427.     int             j, RETCODE;
  428.  
  429.     static int      catptr = 0;
  430.     static int      catflag = 0x200;
  431.     static int      cattype = 1;
  432.     static int      patflag = 0;
  433.  
  434.     catreturn.maxlen = 256;
  435.  
  436.     if (patflag) {
  437.         patflag = 0;
  438.         catptr = 0;
  439.         return (NULL);
  440.     }
  441.     if (filepattern) {
  442.         strcpy(pattern.name, filepattern);
  443.         pattern.len = strlen(filepattern);
  444.         if (!index(filepattern, '?'))
  445.             patflag = 1;
  446.     }
  447.     if (patflag) {
  448.         fileinfo(&pattern, &cattype, "CINAME  ", &catreturn, _retcode RETCODE);
  449.         catptr = RETCODE ? 0 : 1;
  450.     } else
  451.         catscan(&pattern, &catflag, &cattype, &catreturn, &catptr);
  452.  
  453.     if (!catptr)
  454.         return (NULL);
  455.     else {
  456.         char           *k;
  457.  
  458.         k = index(catreturn.name, ' ');
  459.         if (k)
  460.             *k = 0;
  461.         else {
  462.             j = catreturn.actlen;
  463.             catreturn.name[j] = 0;
  464.         }
  465.         k = catreturn.name;
  466.         if (catreturn.name[0] == tmpchr[0])
  467.             k++;
  468.         else if ((k = index(catreturn.name, sepchr[0])))
  469.             k++;
  470.         else
  471.             k = catreturn.name;
  472.         j = strlen(k);
  473.         i = malloc(++j);
  474.         strcpy(i, k);
  475.         return (i);
  476.     }
  477. #else
  478.     fortran void    gfinfo();
  479.     static char     gfname[24];
  480.     static char     pattern[20];
  481.     static int      gfdummy[2] = {
  482.                       0, 0
  483.     },              gfflags;
  484.     int             i, RETCODE;
  485.     char           *j, *k;
  486.  
  487.     if (filepattern) {
  488.         strcpy(pattern, filepattern);
  489.         strcat(pattern, " ");
  490.         for (i = 20; i < 24; i++)
  491.             gfname[i] = '\0';
  492.         if (index(pattern, '?'))
  493.             gfflags = 0x0C;
  494.         else
  495.             gfflags = 0x09;
  496.     } else if (gfflags == 0x09)
  497.         return (NULL);
  498.  
  499.     gfinfo(pattern, gfname, &gfflags, gfdummy, gfdummy, gfdummy, _retcode RETCODE);
  500.     if (RETCODE)
  501.         return (NULL);
  502.     else {
  503.         k = index(gfname, ' ');
  504.         *k = '\0';
  505.         k = gfname;
  506.         if (gfname[0] == tmpchr[0])
  507.             k++;
  508.         else if ((k = index(gfname, sepchr[0])))
  509.             k++;
  510.         else
  511.             k = gfname;
  512.         i = strlen(k);
  513.         j = malloc(++i);
  514.         strcpy(j, k);
  515.         return (j);
  516.     }
  517. #endif
  518. }
  519.  
  520. int
  521. unlink(path)
  522.     char           *path;    /* name of file to delete */
  523. {
  524.     fortran void    destroy();
  525.     int             RETCODE;
  526.  
  527.     char            name[258];
  528.  
  529.     strcpy(name, path);
  530.     strcat(name, " ");
  531.     destroy(name, _retcode RETCODE);
  532.     if (RETCODE)
  533.         return (-1);
  534.     else
  535.         return (0);
  536. }
  537. #endif
  538. @
  539.  
  540.  
  541. 1.7
  542. log
  543. @Fixed to allow specifying pathnames of target files.
  544. @
  545. text
  546. @d3 1
  547. a3 1
  548.  * $Header: arcmisc.c,v 1.6 88/06/12 18:47:09 hyc Locked $ 
  549. d58 1
  550. d68 13
  551. d82 1
  552. a82 1
  553. int             strlen();
  554. d89 1
  555. d91 1
  556. d93 1
  557. d99 1
  558. d103 1
  559. a103 1
  560.         old = fopen(oldnam, "rb");
  561. d106 1
  562. a106 1
  563.         new = fopen(newnam, "wb");
  564. d110 6
  565. a115 3
  566.         unlink(oldnam);
  567.     } else
  568.         return 0;
  569. d124 5
  570. d183 1
  571. a183 1
  572. #if    MSDOS
  573. d292 1
  574. a292 1
  575.     int             fmatch();
  576. @
  577.  
  578.  
  579. 1.6
  580. log
  581. @Removed 'mode' parameter from dir, since it wasn't used anywhere.
  582. @
  583. text
  584. @d3 1
  585. a3 1
  586.  * $Header: arcmisc.c,v 1.5 88/06/01 19:41:20 hyc Locked $ 
  587. d261 1
  588. d268 1
  589. d270 1
  590. a270 1
  591.     pattern = filename;    /* set up for fmatch */
  592. d272 10
  593. a281 1
  594.         Nnum = scandir(".", &namelist, fmatch, alphasort);
  595. @
  596.  
  597.  
  598. 1.5
  599. log
  600. @Changed compilation conditionals
  601. @
  602. text
  603. @d3 1
  604. a3 1
  605.  * $Header: arcmisc.c,v 1.4 88/06/01 16:06:37 hyc Locked $ 
  606. d12 1
  607. a31 23
  608. rename(oldnam, newnam)
  609.     char           *oldnam, *newnam;
  610. {
  611.     FILE           *fopen(), *old, *new;
  612.     struct stat     oldstat;
  613.     char           *strcpy();
  614.  
  615.     if (Frename(0, oldnam, newnam)) {    /* assume different drive */
  616.         if (stat(oldnam, &oldstat))
  617.             return (-1);
  618.         old = fopen(oldnam, "rb");
  619.         if (old == NULL)
  620.             return (-1);
  621.         new = fopen(newnam, "wb");
  622.         if (new == NULL)
  623.             return (-1);
  624.         filecopy(old, new, oldstat.st_size);
  625.         unlink(oldnam);
  626.     } else
  627.         return 0;
  628. }
  629.  
  630. int
  631. d57 1
  632. d70 26
  633. a95 6
  634. /*
  635.  * char           * setmem(dest, size, c) char           *dest; unsigned
  636.  * short    size; char        c; { unsigned short    i; 
  637.  *
  638.  * for (i = 0; i < size; dest[i] = c, i++); return (&dest[0]); } 
  639.  */
  640. d221 3
  641. a223 2
  642. char           *pattern;    /* global so that fmatch can use them */
  643. int             filemode;
  644. d226 1
  645. a226 1
  646. dir(filename, mode)        /* get files, one by one */
  647. a227 1
  648.     int             mode;    /* search mode bits */
  649. d268 1
  650. a268 2
  651.     pattern = filename;
  652.     filemode = mode;    /* set up globals for fmatch */
  653. d312 1
  654. a312 1
  655. dir(filepattern, junk)
  656. a313 1
  657.     int             junk;    /* unused on MTS */
  658. @
  659.  
  660.  
  661. 1.4
  662. log
  663. @Merge Atari ST code
  664. @
  665. text
  666. @d1 5
  667. d10 1
  668. a10 1
  669. #ifdef MSDOS
  670. d14 1
  671. a14 1
  672. #ifdef GEMDOS
  673. d17 1
  674. a17 1
  675. char *index(), *rindex();
  676. d19 2
  677. a20 1
  678. void exitpause()
  679. d22 6
  680. a27 6
  681.       while(Cconis())
  682.               Cnecin();
  683.       fprintf(stderr,"Press any key to continue: ");
  684.       fflush(stderr);
  685.       Cnecin();
  686.       fprintf(stderr,"\n");
  687. d32 1
  688. a32 1
  689.       char            *oldnam, *newnam;
  690. d34 3
  691. a36 3
  692.       FILE *fopen(), *old, *new;
  693.       struct stat oldstat;
  694.       char    *strcpy();
  695. d38 13
  696. a50 12
  697.       if(Frename(0, oldnam, newnam)) {  /* assume different drive */
  698.               if(stat(oldnam,&oldstat))
  699.                       return(-1);
  700.               old=fopen(oldnam, "rb");
  701.               if (old == NULL)
  702.                       return(-1);
  703.               new=fopen(newnam, "wb");
  704.               if (new == NULL)
  705.                       return(-1);
  706.               filecopy(old, new, oldstat.st_size);
  707.               unlink(oldnam);
  708.       } else return 0;
  709. d55 1
  710. a55 1
  711.       char            *dirname;
  712. d57 2
  713. a58 2
  714.       char *i;
  715.       int drv;
  716. d60 13
  717. a72 13
  718.       i=dirname;
  719.       if ((i=index(dirname,':')) != NULL) {
  720.               drv=i[-1];
  721.               i++;                    /* Move past device spec */
  722.               if(drv > '\'')
  723.                       drv -= 'a';
  724.               else
  725.                       drv -= 'A';
  726.               if (drv >= 0 && drv < 16)
  727.                       Dsetdrv(drv);
  728.       }
  729.       if (*i != '\0')
  730.               return(Dsetpath(i));
  731. d76 1
  732. a76 1
  733. #ifdef BSD
  734. d81 1
  735. a81 1
  736. #ifdef SYSV
  737. d88 2
  738. a89 2
  739. char    *strcpy(), *strcat(), *malloc();
  740. int    strlen();
  741. d92 4
  742. a95 2
  743.  * Miscellaneous routines to get ARC running on BSD 4.2...
  744.  * $Header: arcmisc.c,v 1.3 88/06/01 15:54:35 hyc Locked $
  745. d98 3
  746. a100 2
  747. char           *
  748. setmem(dest, size, c)
  749. a101 2
  750.     unsigned short    size;
  751.     char        c;
  752. a102 11
  753.     unsigned short    i;
  754.  
  755.     for (i = 0; i < size; dest[i] = c, i++);
  756.     return (&dest[0]);
  757. }
  758.  
  759. static    void
  760. _makefn(source, dest)
  761.     char  *source;
  762.     char  *dest;
  763. {
  764. d114 1
  765. a114 1
  766.  * make a file name using a template
  767. d119 3
  768. a121 3
  769.     char  *rawfn;    /* the original file name */
  770.     char  *template;    /* the template data */
  771.     char  *result;    /* where to place the result */
  772. d123 1
  773. a123 1
  774.     char   et[17], er[17], rawbuf[STRLEN], *i, *rindex();
  775. d127 1
  776. a127 1
  777. #ifdef MTS
  778. d138 1
  779. a138 1
  780. #ifdef DOS
  781. d158 1
  782. a158 1
  783. #if MSDOS
  784. d179 1
  785. a179 1
  786. /*VARARGS1*/
  787. d187 2
  788. a188 2
  789. #ifdef BSD
  790.     perror("BSD");
  791. d190 1
  792. a190 1
  793. #ifdef    GEMDOS
  794. d196 1
  795. a196 1
  796. #ifndef MTS
  797. d203 4
  798. a206 4
  799.     char    *getwd();
  800. #ifdef    GEMDOS
  801.     int    drv;
  802.     char    *buf;
  803. d211 1
  804. a211 1
  805. #ifndef    GEMDOS
  806. d214 4
  807. a217 4
  808.     buf=dirname;
  809.     *buf++=(drv=Dgetdrv())+'A';
  810.     *buf++=':';
  811.     Dgetpath(buf,0);
  812. d219 1
  813. a219 1
  814.     return(dirname);
  815. d230 4
  816. a233 4
  817. #ifdef GEMDOS
  818.       static  int     Nnum = 0;
  819.       static  DMABUFFER       dbuf, *saved;
  820.       char   *name;
  821. d235 23
  822. a257 26
  823.       if (Nnum == 0) {        /* first call */
  824.               saved = (DMABUFFER *)Fgetdta();
  825.               Fsetdta(&dbuf);
  826.               if (Fsfirst(filename, 0) == 0) {
  827.                       name = malloc(FNLEN);
  828.                       strcpy(name, dbuf.d_fname);
  829.                       Nnum++;
  830.                       return(name);
  831.               }
  832.               else {
  833.                       Fsetdta(saved);
  834.                       return(NULL);
  835.               }
  836.       }
  837.       else {
  838.               if (Fsnext() == 0) {
  839.                       name = malloc(FNLEN);
  840.                       strcpy(name, dbuf.d_fname);
  841.                       return(name);
  842.               }
  843.               else {
  844.                       Nnum=0;
  845.                       Fsetdta(saved);
  846.                       return(NULL);
  847.               }
  848.       }
  849. d262 1
  850. a262 1
  851. #ifdef BSD
  852. d265 1
  853. a265 1
  854. #endif    /* BSD */
  855. d294 1
  856. a294 1
  857.  * Filename match - here, * matches everything
  858. d309 1
  859. a309 1
  860. #endif    /* GEMDOS */
  861. d319 2
  862. a320 2
  863. #ifdef USECATSCAN
  864.     fortran         catscan(), fileinfo();
  865. d385 1
  866. a385 1
  867.     fortran         gfinfo();
  868. d431 2
  869. a432 2
  870.     fortran         destroy();
  871.     int        RETCODE;
  872. @
  873.  
  874.  
  875. 1.3
  876. log
  877. @Fix declarations
  878. @
  879. text
  880. @d9 60
  881. d86 1
  882. a86 1
  883.  * $Header: arcmisc.c,v 1.9 88/04/19 01:40:05 hyc Exp $
  884. a100 10
  885. #ifdef MTS
  886. #define CUTOFF sepchr[0]
  887. #endif
  888. #ifdef MSDOS
  889. #define CUTOFF '\\'
  890. #endif
  891. #ifdef BSD
  892. #define CUTOFF '/'
  893. #endif
  894.  
  895. d141 1
  896. a141 1
  897. #ifdef MSDOS
  898. d178 1
  899. a178 1
  900.     for (p = string; *p != NULL; p++)
  901. d193 3
  902. d207 4
  903. d214 1
  904. d216 6
  905. d233 33
  906. d315 1
  907. @
  908.  
  909.  
  910. 1.2
  911. log
  912. @re-synch with MTS, changes for CBELL to C87...
  913. @
  914. text
  915. @d4 1
  916. d8 1
  917. d14 6
  918. a19 1
  919. /* Miscellaneous routines to get ARC running on BSD 4.2... */
  920. d21 2
  921. d24 5
  922. d32 1
  923. a32 1
  924.     unsigned INT    size;
  925. d35 1
  926. a35 1
  927.     unsigned INT    i;
  928. d51 1
  929. a51 1
  930. static          INT
  931. d53 2
  932. a54 2
  933.     unsigned char  *source;
  934.     unsigned char  *dest;
  935. d56 1
  936. a56 1
  937.     INT             j;
  938. d72 3
  939. a74 3
  940.     unsigned char  *rawfn;    /* the original file name */
  941.     unsigned char  *template;    /* the template data */
  942.     unsigned char  *result;    /* where to place the result */
  943. d76 1
  944. a76 1
  945.     unsigned char   et[17], er[17], rawbuf[100], *i, *rindex();
  946. d113 1
  947. a113 1
  948. INT
  949. d115 1
  950. a115 1
  951.     struct direct **dirptr1, **dirptr2;
  952. d122 1
  953. a122 1
  954. INT
  955. d132 2
  956. a133 1
  957. INT
  958. d153 1
  959. d158 1
  960. d162 1
  961. a162 1
  962. INT             filemode;
  963. d167 1
  964. a167 1
  965.     INT             mode;    /* search mode bits */
  966. d169 1
  967. a169 1
  968.     static struct direct **namelist;
  969. d176 1
  970. a176 2
  971.     static INT      Nnum = 0, ii;
  972.     char           *result = NULL;
  973. d184 1
  974. a184 1
  975.             (NameList)[ii] = (char *) malloc(namelist[ii]->d_namlen + 1);
  976. a201 20
  977.  
  978. #define ASTERISK '*'        /* The '*' metacharacter */
  979. #define QUESTION '?'        /* The '?' metacharacter */
  980. #define LEFT_BRACKET '['    /* The '[' metacharacter */
  981. #define RIGHT_BRACKET ']'    /* The ']' metacharacter */
  982.  
  983. #define IS_OCTAL(ch) (ch >= '0' && ch <= '7')
  984.  
  985. typedef INT     BOOLEAN;
  986. #define VOID short
  987. #define TRUE 1
  988. #define FALSE 0
  989. #define EOS '\000'
  990.  
  991. static BOOLEAN  do_list();
  992. static char     nextch();
  993. static VOID     list_parse();
  994.  
  995.  
  996.  
  997. a202 180
  998.  * FUNCTION
  999.  * 
  1000.  * do_list    process a list and following substring
  1001.  * 
  1002.  * SYNOPSIS
  1003.  * 
  1004.  * static BOOLEAN do_list (string, pattern) register char *string; register char
  1005.  * *pattern;
  1006.  * 
  1007.  * DESCRIPTION
  1008.  * 
  1009.  * Called when a list is found in the pattern.  Returns TRUE if the current
  1010.  * character matches the list and the remaining substring matches the
  1011.  * remaining pattern.
  1012.  * 
  1013.  * Returns FALSE if either the current character fails to match the list or the
  1014.  * list matches but the remaining substring and subpattern's don't.
  1015.  * 
  1016.  * RESTRICTIONS
  1017.  * 
  1018.  * The mechanism used to match characters in an inclusive pair (I.E. [a-d]) may
  1019.  * not be portable to machines in which the native character set is not
  1020.  * ASCII.
  1021.  * 
  1022.  * The rules implemented here are:
  1023.  * 
  1024.  * (1)  The backslash character may be used to quote any special character.
  1025.  * I.E.  "\]" and "\-" anywhere in list, or "\!" at start of list.
  1026.  * 
  1027.  * (2)  The sequence \nnn becomes the character given by nnn (in octal).
  1028.  * 
  1029.  * (3)  Any non-escaped ']' marks the end of list.
  1030.  * 
  1031.  * (4)  A list beginning with the special character '!' matches any character
  1032.  * NOT in list. The '!' character is only special if it is the first
  1033.  * character in the list.
  1034.  * 
  1035.  */
  1036.  
  1037.  
  1038.  
  1039. /*
  1040.  * PSEUDO CODE
  1041.  * 
  1042.  * Begin do_list Default result is no match Skip over the opening left bracket
  1043.  * If the next pattern character is a '!' then List match gives FALSE Skip
  1044.  * over the '!' character Else List match gives TRUE End if While not at
  1045.  * closing bracket or EOS Get lower and upper bounds If character in bounds
  1046.  * then Result is same as sense flag. Skip over rest of list End if End while
  1047.  * If match found then If not at end of pattern then Call match with rest of
  1048.  * pattern End if End if Return match result End do_list
  1049.  * 
  1050.  */
  1051.  
  1052. static          BOOLEAN
  1053. do_list(string, pattern)
  1054.     register char  *string;
  1055.     char           *pattern;
  1056. {
  1057.     register BOOLEAN ismatch;
  1058.     register BOOLEAN if_found;
  1059.     register BOOLEAN if_not_found;
  1060.     auto char       lower;
  1061.     auto char       upper;
  1062.  
  1063.     pattern++;
  1064.     if (*pattern == '!') {
  1065.         if_found = FALSE;
  1066.         if_not_found = TRUE;
  1067.         pattern++;
  1068.     } else {
  1069.         if_found = TRUE;
  1070.         if_not_found = FALSE;
  1071.     }
  1072.     ismatch = if_not_found;
  1073.     while (*pattern != ']' && *pattern != EOS) {
  1074.         list_parse(&pattern, &lower, &upper);
  1075.         if (*string >= lower && *string <= upper) {
  1076.             ismatch = if_found;
  1077.             while (*pattern != ']' && *pattern != EOS) {
  1078.                 pattern++;
  1079.             }
  1080.         }
  1081.     }
  1082.     if (*pattern++ != ']') {
  1083.         fprintf(stderr, "warning - character class error\n");
  1084.     } else {
  1085.         if (ismatch) {
  1086.             ismatch = match(++string, pattern);
  1087.         }
  1088.     }
  1089.     return (ismatch);
  1090. }
  1091.  
  1092.  
  1093.  
  1094. /*
  1095.  * FUNCTION
  1096.  * 
  1097.  * list_parse    parse part of list into lower and upper bounds
  1098.  * 
  1099.  * SYNOPSIS
  1100.  * 
  1101.  * static VOID list_parse (patp, lowp, highp) char **patp; char *lowp; char
  1102.  * *highp;
  1103.  * 
  1104.  * DESCRIPTION
  1105.  * 
  1106.  * Given pointer to a pattern pointer (patp), pointer to a place to store lower
  1107.  * bound (lowp), and pointer to a place to store upper bound (highp), parses
  1108.  * part of the list, updating the pattern pointer in the process.
  1109.  * 
  1110.  * For list characters which are not part of a range, the lower and upper bounds
  1111.  * are set to that character.
  1112.  * 
  1113.  */
  1114.  
  1115. static          VOID
  1116. list_parse(patp, lowp, highp)
  1117.     char          **patp;
  1118.     char           *lowp;
  1119.     char           *highp;
  1120. {
  1121.     *lowp = nextch(patp);
  1122.     if (**patp == '-') {
  1123.         (*patp)++;
  1124.         *highp = nextch(patp);
  1125.     } else {
  1126.         *highp = *lowp;
  1127.     }
  1128. }
  1129.  
  1130.  
  1131.  
  1132. /*
  1133.  * FUNCTION
  1134.  * 
  1135.  * nextch    determine next character in a pattern
  1136.  * 
  1137.  * SYNOPSIS
  1138.  * 
  1139.  * static char nextch (patp) char **patp;
  1140.  * 
  1141.  * DESCRIPTION
  1142.  * 
  1143.  * Given pointer to a pointer to a pattern, uses the pattern pointer to
  1144.  * determine the next character in the pattern, subject to translation of
  1145.  * backslash-char and backslash-octal sequences.
  1146.  * 
  1147.  * The character pointer is updated to point at the next pattern character to be
  1148.  * processed.
  1149.  * 
  1150.  */
  1151.  
  1152. static char
  1153. nextch(patp)
  1154.     char          **patp;
  1155. {
  1156.     register char   ch;
  1157.     register char   chsum;
  1158.     register INT    count;
  1159.  
  1160.     ch = *(*patp)++;
  1161.     if (ch == '\\') {
  1162.         ch = *(*patp)++;
  1163.         if (IS_OCTAL(ch)) {
  1164.             chsum = 0;
  1165.             for (count = 0; count < 3 && IS_OCTAL(ch); count++) {
  1166.                 chsum *= 8;
  1167.                 chsum += ch - '0';
  1168.                 ch = *(*patp)++;
  1169.             }
  1170.             (*patp)--;
  1171.             ch = chsum;
  1172.         }
  1173.     }
  1174.     return (ch);
  1175. }
  1176.  
  1177. /*
  1178. d208 1
  1179. a208 1
  1180.     struct direct  *direntry;
  1181. d210 1
  1182. a210 1
  1183.     char           *ptr, *string;
  1184. d224 1
  1185. a224 1
  1186.     INT             junk;    /* unused on MTS */
  1187. d335 1
  1188. @
  1189.  
  1190.  
  1191. 1.1
  1192. log
  1193. @Initial revision
  1194. @
  1195. text
  1196. @d17 3
  1197. a19 2
  1198.     char           *dest, c;
  1199.     INT             size;
  1200. d21 1
  1201. a21 1
  1202.     INT             i;
  1203. d157 1
  1204. a157 1
  1205. #endif BSD
  1206. d426 1
  1207. a426 1
  1208.     int             j;
  1209. d447 1
  1210. a447 1
  1211.         fileinfo(&pattern, &cattype, "CINAME  ", &catreturn);
  1212. d483 1
  1213. a483 1
  1214.     int             i;
  1215. d498 1
  1216. a498 1
  1217.     gfinfo(pattern, gfname, &gfflags, gfdummy, gfdummy, gfdummy);
  1218. d523 1
  1219. d529 1
  1220. a529 1
  1221.     destroy(name);
  1222. @
  1223.