home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / emacs-18.59-bin.lha / lib / emacs / 18.59 / etc / etags-vmslib.c < prev    next >
C/C++ Source or Header  |  1992-01-19  |  4KB  |  160 lines

  1. /* File name wild card expansion for VMS.
  2.    This file is part of the etags program.
  3.    Copyright (C) 1987 Free Software Foundation, Inc. 3 Feb 1987
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 1, or (at your option)
  8.     any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. In other words, you are welcome to use, share and improve this program.
  20. You are forbidden to forbid anyone else to use, share and improve
  21. what you give them.   Help stamp out software-hoarding!  */
  22.  
  23. #include    <stdio.h>
  24. typedef    char    tbool;
  25.  
  26. /* This is a BUG!  ANY arbitrary limit is a BUG!
  27.    Won't someone please fix this?  */
  28. #define    MAX_FILE_SPEC_LEN    255
  29. typedef struct    {
  30.   short   curlen;
  31.   char    body[MAX_FILE_SPEC_LEN + 1];
  32. } vspec;
  33. #define    EOS    '\0'
  34. #define    NO    0
  35. #define    YES    1
  36. #define    NULL    0
  37.  
  38. /* v1.01 nmm 19-Aug-85 gfnames - return in successive calls the 
  39.  name of each file specified by all the remaining args in the command-line
  40.  expanding wild cards and 
  41.  stepping over arguments when they have been processed completely
  42. */
  43. char*
  44. gfnames(pac, pav, p_error)
  45.     int    *pac;
  46.     char    **pav[];
  47.     tbool    *p_error;
  48. {
  49.     static    vspec    filename = {MAX_FILE_SPEC_LEN, "\0"};
  50.     short    fn_exp();
  51.  
  52.     while (1)
  53.         if (*pac == 0)
  54.             {
  55.             *p_error = NO;
  56.             return(NULL);
  57.             }
  58.         else switch(fn_exp(&filename, **pav))
  59.             {
  60.         case 1:
  61.             *p_error = NO;
  62.             return(filename.body);
  63.             break;
  64.         case 0:
  65.             --*pac;
  66.             ++*pav;
  67.             break;
  68.         default:
  69.             *p_error = YES;
  70.             return(filename.body);
  71.             break;
  72.             }
  73.                 
  74. }
  75.  
  76. /* v1.05 nmm 26-Jun-86 fn_exp - expand specification of list of file names
  77.  returning in each successive call the next filename matching the input
  78.  spec. The function expects that each in_spec passed
  79.  to it will be processed to completion; in particular, up to and
  80.  including the call following that in which the last matching name
  81.  is returned, the function ignores the value of in_spec, and will
  82.  only start processing a new spec with the following call. 
  83.  If an error occurs, on return out_spec contains the value
  84.  of in_spec when the error occurred.
  85.  
  86.  With each successive filename returned in out_spec, the
  87.  function's return value is one. When there are no more matching
  88.  names the function returns zero. If on the first call no file
  89.  matches in_spec, or there is any other error, -1 is returned. 
  90. */
  91.  
  92. #include    <rmsdef.h>
  93. #include    <descrip.h>
  94. #define        OUTSIZE    MAX_FILE_SPEC_LEN
  95. short
  96. fn_exp(out, in)
  97.     vspec    *out;
  98.     char    *in;
  99. {
  100.     static    long    context = 0;
  101.     static    struct    dsc$descriptor_s    o;
  102.     static    struct    dsc$descriptor_s    i;
  103.     static    tbool    pass1 = YES;
  104.         long    status;
  105.         short    retval;
  106.  
  107.     if (pass1)
  108.         {
  109.         pass1 = NO;
  110.         o.dsc$a_pointer = (char *) out;
  111.         o.dsc$w_length = (short)OUTSIZE;
  112.         i.dsc$a_pointer = in;
  113.         i.dsc$w_length = (short)strlen(in);
  114.         i.dsc$b_dtype = DSC$K_DTYPE_T;
  115.         i.dsc$b_class = DSC$K_CLASS_S;
  116.         o.dsc$b_dtype = DSC$K_DTYPE_VT;
  117.         o.dsc$b_class = DSC$K_CLASS_VS;
  118.         }
  119.     if ( (status = lib$find_file(&i, &o, &context, 0, 0)) == RMS$_NORMAL)
  120.         {
  121.         out->body[out->curlen] = EOS;
  122.         return(1);
  123.         }
  124.     else if (status == RMS$_NMF)
  125.         retval = 0;
  126.     else
  127.         {
  128.         strcpy(out->body, in);
  129.         retval = -1;
  130.         }
  131.     lib$find_file_end(&context);
  132.     pass1 = YES;
  133.     return(retval);
  134. }    
  135.  
  136. #ifndef OLD  /* Newer versions of VMS do provide `system'.  */
  137. system(cmd)
  138.      char *cmd;
  139. {
  140.   fprintf(stderr, "system() function not implemented under VMS\n");
  141. }
  142. #endif
  143.  
  144. #define    VERSION_DELIM    ';'
  145. char *massage_name(s)
  146.     char    *s;
  147. {
  148.     char    *start = s;    
  149.  
  150.     for ( ; *s; s++)
  151.         if (*s == VERSION_DELIM)
  152.             {
  153.             *s = EOS;
  154.             break;
  155.             }
  156.         else
  157.             *s = tolower(*s);
  158.     return(start);
  159. }
  160.