home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / fido / pup_v2b.zip / MS-C.C < prev    next >
C/C++ Source or Header  |  1987-11-16  |  5KB  |  170 lines

  1. #include <puppy.h>
  2.  
  3. /*
  4.  
  5.     MSDOS dependent C routines
  6.  
  7.     T. Jennings
  8.     Fido Software
  9.     164 Shipley
  10.     San Francisco CA 94107
  11.     (415)-764-1688
  12.  
  13.     (k) all rights reversed
  14.  
  15.  
  16. char *strfnd(text,pattern)
  17.         Search through the text for the specified pattern,
  18.         return a pointer to the text if found else zero. This
  19.         is a case insensitive match.
  20.  
  21. getinfo(filename,n,fileinfo)
  22.         Returns specific information on the requested filename.
  23.         This also is used for search first/next to locate a 
  24.         series of matching files, using the usual wildcards
  25.         * and ?. The function returns 0 when no matching file
  26.         is found.
  27.  
  28.         filename is a string specifying the file; it is fully
  29.         qualified, ie. it has drive letter/pathname info in it.
  30.         It may be in either upper or lower case.
  31.  
  32.         N is an integer that indicates which pass # this is. N is 0
  33.         for the first time, and increments for each subsequent
  34.         call.
  35.  
  36.         fileinfo is the structure defined in puppy.h that the 
  37.         information is returned in. Its generic enough that it
  38.         should be easy enough to fill in for most DOSs, or the
  39.         information left zeroed. The contents of the structure
  40.         is preserved between calls; it can be used to store stuff
  41.         between iterations. n == 0 should be used to set the info
  42.         for later calls. (The MSDOS version uses the _find()
  43.         function defined in MS-ASM.ASM, which stores its info
  44.         in added space in the fileinfo structure.)
  45.  
  46.  
  47.         Unlike search first/next in CP/M, there may be any number
  48.         of file system calls made in between calls to getinfo().
  49.         If this is a problem (CP/M ...) then getinfo() should make
  50.         a list of files when n == 0 and return them one by one
  51.         in each call.
  52.  
  53.         It is even possible to merely get basic file info when
  54.         n == 0, and return 0 for all other calls; the only effect
  55.         will be that wildcards cant be used in various places.
  56.  
  57. badname(s)    Returns true if the passed filename is not legal for
  58.         this DOS. MSDOS: Checks for devices, directories, etc.
  59.  
  60. close_up()    MSDOS kludge: when carrier is lost (and we stack jump
  61.         out) we gotta close any open files else the handles
  62.         stay busy and unavailable. MSDOS: just close all
  63.         handles 6 - 20. 1 - 5 are standard devices stdin, stdout,
  64.         stdprn, etc.
  65.  
  66. lconout(c)    Output a character to the local console.
  67.  
  68. lconin()    Get a character from the local keyboard.
  69.  
  70. keyhit()    Get a character from the local keyboard if one is
  71.         available, else return 0.
  72. */
  73.  
  74. /* Find a string, return a pointer to it or null if not found. */
  75.  
  76. char *strfnd(string,pattern)
  77. char *string,*pattern;
  78. {
  79. char *s,*p;
  80.  
  81.     while (1) {
  82.         s= string; p= pattern;
  83.         if ((*s == 0) || (*s == 26)) break;    /* NUL or ^Z is end */
  84.         while (*p && (tolower(*s) == tolower(*p))) {
  85.             ++s; ++p;            /* mismatch or */
  86.         }                    /* end of pattern, */
  87.         if (*p == 0) return(string);        /* found it! */
  88.         ++string;                /* next ... */
  89.     }
  90.     return(0);
  91. }
  92.  
  93. /* Get file info. */
  94.  
  95. getinfo(name,n,fileinfo)
  96. char *name;            /* filename, */
  97. int n;                /* interation counter */
  98. struct _fileinfo *fileinfo;    /* returned file information */
  99. {
  100.     fileinfo-> xfbuf.s_attrib= 0;        /* set search attribute */
  101.     if (!_find(name,n,&fileinfo-> xfbuf))    /* do the MSDOS thing, */
  102.         return(0);            /* no matches */
  103.  
  104.     strcpy(fileinfo-> name,fileinfo-> xfbuf.name);
  105.     fileinfo-> size= fileinfo-> xfbuf.fsize; /* copy in the basic info */
  106.  
  107.     fileinfo-> time.day= fileinfo-> xfbuf.date & 0x0f;
  108.     fileinfo-> time.month= (fileinfo-> xfbuf.date >> 5) & 0x0f;
  109.     fileinfo-> time.year= ((fileinfo-> xfbuf.date >> 9) & 0x3f) + 80;
  110.  
  111. /* Unpack the MSDOS time. MSDOS keeps file time seconds in 2 sec. 
  112. resolution. Who needs it anyways. */
  113.  
  114.     fileinfo-> time.hour= fileinfo-> xfbuf.time >> 11;
  115.     fileinfo-> time.minute= (fileinfo-> xfbuf.time >> 5) & 0x3f;
  116.     fileinfo-> time.second= 0;
  117.  
  118.     return(1);
  119. }
  120.  
  121. /* Return true if this name is a reserved MSDOS filename. ie. a 
  122. directory or device name. */
  123.  
  124. badname(name)
  125. char *name;
  126. {
  127. int i,f;
  128.  
  129.     if (*name == '.') return(1);    /* directory */
  130.     f= open(name,2);        /* if we can't open it */
  131.     if (f == -1) return(0);        /* it aint there */
  132.     i= _ioctl(0,f,0,0);        /* see if device */
  133.     close(f);            /* close handle */
  134.     if (i == -1) return(0);        /* some error */
  135.     return(i & 0x80);        /* 0x80 is the 'device' bit */
  136. }
  137.  
  138. /* Since we may have been aborted at any point, we probably
  139. had open files. This is gross, but this closes all possible handles
  140. except the ones we know of (log file, nodemap file)  */
  141.  
  142. close_up() {
  143. int i;
  144.  
  145.     for (i= 6; i < 20; i++) {
  146.         close(i);
  147.     }
  148. }
  149. /* get a character from the console. */
  150.  
  151. lconin()
  152. {
  153.     return(bdos(7));
  154. }
  155. /* If a key is hit, return the key, else 0. */
  156.  
  157. keyhit() {
  158. char c;
  159.     c= bdos(6,0xff);
  160.     return(c);
  161. }
  162.  
  163. /* Type a character, dont change cursor position. */
  164.  
  165. lconout(c)
  166. char c;
  167. {
  168.     bdos(6,c);
  169. }
  170.