home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 164_01 / ltype.c < prev    next >
Text File  |  1984-04-08  |  3KB  |  167 lines

  1. /* LTYPE -  */
  2.  
  3. #define    VERSION        3
  4. #define REVISION    0
  5. #define MOD_DATE    "84-03-01"
  6.  
  7. /* This program will type a member of a LBR file... any member,
  8.    BUT anything other than an ASCII file will produce a screenful
  9.    of garbage.
  10.  
  11.    USE: LTYPE <library> <member>
  12.    COMPILE/LINK: cc1 ltype
  13.          nl2 ltype libacc
  14.    By S. Kluger 01-13-83
  15.  
  16.    vers 3.0   3-1-84
  17.    Upgrade to lattice c ms dos P. H. Mack.
  18. */
  19.  
  20. #include "stdio.h"
  21.  
  22. char curdsk, fcb[36];
  23. char fnam[12], libnam[16], dirbuf[128], *dirp;
  24. int  fd, dirsiz, filsiz;
  25.  
  26. #define OK    0
  27.  
  28. /************************************************
  29.  main
  30. *************************************************/
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char **argv;
  35. {
  36.     cprintf("\n\rLTYPE vers:%d.%02d  %s\n\r\n",
  37.     VERSION,REVISION,MOD_DATE);
  38.  
  39.     opnlib(argv[1]);
  40.     if (fndmem(argv[2]) == ERROR) erxit("\n\rMember not in LBR file!\n\r");
  41.     cprintf("\n\rFile present - %d sectors.\n\r",filsiz);
  42.     doit();
  43. }
  44.  
  45. /************************************************
  46.  Typing function 
  47. *************************************************/
  48.  
  49. doit()
  50.  
  51. {
  52.     int    j;
  53.     int    c;
  54.  
  55.     dirsiz = filsiz;
  56.     do
  57.     {
  58.         reload();
  59.  
  60.         for (j=0; j<128; j++){
  61.  
  62.             if (*dirp == 0x1a)
  63.                 exit();
  64.             putchar(*dirp);
  65.             if(*dirp == 0x0a)
  66.             putchar('0x0d');
  67.             dirp++;
  68.         }
  69.     }while(dirsiz != 0);
  70. }
  71.  
  72. /************************************************
  73.  open library file
  74. *************************************************/
  75.  
  76.  
  77. opnlib(file)
  78. char *file;
  79. {
  80.     char l, *npnt;
  81.  
  82.     strcpy(libnam,file);
  83.     l = matchr(libnam,'.');
  84.     if (l == 0) strcat(libnam, ".LBR");
  85.     setfcb(fcb,libnam);    /* build name in fcb */
  86.     movmem(fcb,fnam,12);    /* get from dfcb2 for log */
  87.  
  88.     if(strcmp(fcb+9, "LBR")){
  89.         printf("got %s\n",libnam);
  90.         erxit("Invalid file spec, MUST be type .LBR\n");
  91.     }
  92.  
  93.     fd = open(libnam,0x8000);
  94.     if(fd == -1) erxit("Library file not found.\n");
  95. }
  96.  
  97. /************************************************
  98.  find library member
  99. *************************************************/
  100.  
  101. fndmem(file)
  102. char *file;
  103. {
  104.     char dnam[16], fname[36];
  105.     long int    floc;
  106.  
  107.     setfcb(fname, file);
  108.     read(fd,dirbuf,128);
  109.     dirp = dirbuf;
  110.     dirsiz = *(dirp+14);
  111.     dirp += 32;
  112.  
  113.     do{
  114.         if (*dirp == 255) return(ERROR);
  115.         if (*dirp == 0){
  116.             strcpy(dnam, dirp+1);
  117.             dnam[11]=0;
  118.             if(strcmp(dnam, fname+1) == 0){
  119.                 filsiz = (*(dirp+14)) + ((*(dirp+15)) * 256);
  120.                 floc=(*(dirp+12)) + ((*(dirp+13)) * 256);
  121.                 lseek(fd,floc *128,0);
  122.                 return(OK);
  123.             }
  124.         }
  125.         dirp += 32;
  126.         if(dirp > dirbuf+128) reload();
  127.     }
  128.     while(dirsiz);
  129.     return(ERROR);
  130. }
  131.  
  132. /************************************************
  133.  reload
  134. *************************************************/
  135.  
  136. reload()
  137. {
  138.     read(fd,dirbuf,128);
  139.     dirp = dirbuf;
  140.     dirsiz--;
  141. }
  142.  
  143. /************************************************
  144.  match char
  145. *************************************************/
  146.  
  147. char matchr(st,ch)
  148. char *st,ch;
  149. {
  150.     int i;
  151.     for(i=0; st[i]; i++){
  152.         if(st[i] == ch) return(i);
  153.     }
  154.     return(0);
  155. }
  156.  
  157. /************************************************
  158.  error exit
  159. *************************************************/
  160.  
  161. erxit(strg)
  162. char *strg;
  163. {
  164.     printf(strg);
  165.     exit();
  166. }
  167.