home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 150_01 / ltype.c < prev    next >
Text File  |  1985-09-07  |  4KB  |  190 lines

  1. /*
  2.        HEADER:  150.??;
  3.         TITLE:  LTYPE - Type Library Member to STDOUT;
  4.       VERSION:  3.0;
  5.          DATE:  01/03/1984;
  6.   DESCRIPTION:  "Copies the specified library member to the STDOUT file.    
  7.                  Usage is:  LTYPE <library file> <member name>             
  8.                  A library file is a single large file to the operating system 
  9.                  which has been built from many smaller files.  The purpose of 
  10.                  a library file is to save the diskette space which otherwise 
  11.                  would be wasted, due to the allocation of disk space in units 
  12.                  of fixed size.";
  13.      KEYWORDS:  Library File, .LBR file, Disk Space;
  14.        SYSTEM:  MSDOS;
  15.      FILENAME:  LTYPE.C;
  16.      WARNINGS:  "User documentation not included.";
  17.      SEE-ALSO:  Library Utility, LU, LDIR.C;
  18.       AUTHORS:  S. Kluger for CP/M, modified by Pete Mack for MSDOS;
  19.     COMPILERS:  Lattice C; 
  20.    REFERENCES:  AUTHORS: S. Kluger/P. H. Mack; TITLE: "LTYPE";
  21.                 CITATION: "PC-SIG Disk 50 or 142" 
  22.        ENDREF;
  23. */
  24. /* LTYPE - TYPE LIBRARY MEMBER TO STDOUT  */
  25.  
  26. #define    VERSION        3
  27. #define REVISION    0
  28. #define MOD_DATE    "84-03-01"
  29.  
  30. /* This program will type a member of a LBR file... any member,
  31.    BUT anything other than an ASCII file will produce a screenful
  32.    of garbage.
  33.  
  34.    USE: LTYPE <library> <member>
  35.    COMPILE/LINK: cc1 ltype
  36.          nl2 ltype libacc
  37.    By S. Kluger 01-13-83
  38.  
  39.    vers 3.0   3-1-84
  40.    Upgrade to lattice c ms dos P. H. Mack.
  41. */
  42.  
  43. #include "stdio.h"
  44.  
  45. char curdsk, fcb[36];
  46. char fnam[12], libnam[16], dirbuf[128], *dirp;
  47. int  fd, dirsiz, filsiz;
  48.  
  49. #define OK    0
  50.  
  51. /************************************************
  52.  main
  53. *************************************************/
  54.  
  55. main(argc,argv)
  56. int argc;
  57. char **argv;
  58. {
  59.     cprintf("\n\rLTYPE vers:%d.%02d  %s\n\r\n",
  60.     VERSION,REVISION,MOD_DATE);
  61.  
  62.     opnlib(argv[1]);
  63.     if (fndmem(argv[2]) == ERROR) erxit("\n\rMember not in LBR file!\n\r");
  64.     cprintf("\n\rFile present - %d sectors.\n\r",filsiz);
  65.     doit();
  66. }
  67.  
  68. /************************************************
  69.  Typing function 
  70. *************************************************/
  71.  
  72. doit()
  73.  
  74. {
  75.     int    j;
  76.     int    c;
  77.  
  78.     dirsiz = filsiz;
  79.     do
  80.     {
  81.         reload();
  82.  
  83.         for (j=0; j<128; j++){
  84.  
  85.             if (*dirp == 0x1a)
  86.                 exit();
  87.             putchar(*dirp);
  88.             if(*dirp == 0x0a)
  89.             putchar('0x0d');
  90.             dirp++;
  91.         }
  92.     }while(dirsiz != 0);
  93. }
  94.  
  95. /************************************************
  96.  open library file
  97. *************************************************/
  98.  
  99.  
  100. opnlib(file)
  101. char *file;
  102. {
  103.     char l, *npnt;
  104.  
  105.     strcpy(libnam,file);
  106.     l = matchr(libnam,'.');
  107.     if (l == 0) strcat(libnam, ".LBR");
  108.     setfcb(fcb,libnam);    /* build name in fcb */
  109.     movmem(fcb,fnam,12);    /* get from dfcb2 for log */
  110.  
  111.     if(strcmp(fcb+9, "LBR")){
  112.         printf("got %s\n",libnam);
  113.         erxit("Invalid file spec, MUST be type .LBR\n");
  114.     }
  115.  
  116.     fd = open(libnam,0x8000);
  117.     if(fd == -1) erxit("Library file not found.\n");
  118. }
  119.  
  120. /************************************************
  121.  find library member
  122. *************************************************/
  123.  
  124. fndmem(file)
  125. char *file;
  126. {
  127.     char dnam[16], fname[36];
  128.     long int    floc;
  129.  
  130.     setfcb(fname, file);
  131.     read(fd,dirbuf,128);
  132.     dirp = dirbuf;
  133.     dirsiz = *(dirp+14);
  134.     dirp += 32;
  135.  
  136.     do{
  137.         if (*dirp == 255) return(ERROR);
  138.         if (*dirp == 0){
  139.             strcpy(dnam, dirp+1);
  140.             dnam[11]=0;
  141.             if(strcmp(dnam, fname+1) == 0){
  142.                 filsiz = (*(dirp+14)) + ((*(dirp+15)) * 256);
  143.                 floc=(*(dirp+12)) + ((*(dirp+13)) * 256);
  144.                 lseek(fd,floc *128,0);
  145.                 return(OK);
  146.             }
  147.         }
  148.         dirp += 32;
  149.         if(dirp > dirbuf+128) reload();
  150.     }
  151.     while(dirsiz);
  152.     return(ERROR);
  153. }
  154.  
  155. /************************************************
  156.  reload
  157. *************************************************/
  158.  
  159. reload()
  160. {
  161.     read(fd,dirbuf,128);
  162.     dirp = dirbuf;
  163.     dirsiz--;
  164. }
  165.  
  166. /************************************************
  167.  match char
  168. *************************************************/
  169.  
  170. char matchr(st,ch)
  171. char *st,ch;
  172. {
  173.     int i;
  174.     for(i=0; st[i]; i++){
  175.         if(st[i] == ch) return(i);
  176.     }
  177.     return(0);
  178. }
  179.  
  180. /************************************************
  181.  error exit
  182. *************************************************/
  183.  
  184. erxit(strg)
  185. char *strg;
  186. {
  187.     printf(strg);
  188.     exit();
  189. }
  190.