home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / h / hldevkit.zip / EDLIST.C < prev    next >
C/C++ Source or Header  |  1992-04-28  |  5KB  |  145 lines

  1. /*
  2.  * edlist.c - a program to list all editions available to the curently
  3.  *            logged in user.
  4.  *
  5.  */
  6.  
  7. #include <proto/exec.h>
  8. #include <proto/hotlinks.h>
  9. #include <lattice/stdio.h>
  10. #include <hotlinks/hotlinks.h>
  11.  
  12. /* standard library base declaraion */
  13. struct HotLinksBase *HotLinksBase;
  14.  
  15. /* version string */
  16. char     VERSTAG[]="\0$VER: edlist B7 (2.6.92)";
  17. char *months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  18. char datebuff[32];
  19.  
  20. int main()
  21. {
  22.         struct PubBlock *pb;
  23.         char *t1, *t2;
  24.         int test, hlh, len, totlen, toted;
  25.         char hltype[5], accstr[7];
  26.         
  27.         /* try to open the hotlink library 
  28.          * The library will not open if the hotlink resident code is not
  29.          * running.
  30.          */
  31.         if((HotLinksBase=(struct HotLinksBase *)OpenLibrary("hotlinks.library", 0))==0)
  32.         {
  33.                 /* in this program not having hotinks available is
  34.                  * a fatal error.
  35.                  */
  36.                 printf("ERROR - could not open the hotlinks.library\n");
  37.                 exit(20);
  38.         }
  39.  
  40.         /* register this program with the hotlinks system */
  41.         hlh = HLRegister(1,0,0);
  42.         
  43.         /* get a PubBlock pointer for the program to use */
  44.         pb=AllocPBlock(hlh);
  45.         
  46.         /* check for errors */
  47.         if((pb==(struct PubBlock *)NOMEMORY)||(pb==(struct PubBlock *)NOPRIV))
  48.         {
  49.                 printf("ERROR - AllocPBlock call failed: error=%d\n", pb);
  50.                 UnRegister(hlh);
  51.                 CloseLibrary((struct Library *)HotLinksBase);
  52.                 exit(0);
  53.         }
  54.                 
  55.         /* init the counters */
  56.         totlen=0;
  57.         toted=0;
  58.         
  59.         /* get the first publication in the list */
  60.         test=FirstPub(pb);
  61.         
  62.         /* loop until it runs out of publications */
  63.         while(test!=NOMOREBLOCKS)
  64.         {
  65.                 /*increment the total edition counter*/
  66.                 toted++;
  67.                 
  68.                 /*get the edition length*/
  69.                 len = -1;
  70.                 if(OpenPub(pb, OPEN_READ)==NOERROR)
  71.                 {
  72.                         SeekPub(pb, 4, SEEK_BEGINNING);
  73.                         ReadPub(pb, (char *)&len, 4);
  74.                         ClosePub(pb);
  75.                         len += 8;       /* add in for the FORM xxxx */
  76.                         
  77.                         /*increment the total length counter*/
  78.                         totlen += len;
  79.                 }
  80.                 
  81.                 /* get the edition type - 4 chars */
  82.                 strncpy(hltype, (char *)&pb->PRec.Type, 4);
  83.                 hltype[4]=0;
  84.                 
  85.                 /* set up the access code output string */
  86.                 strcpy(accstr, "------");
  87.                 if(pb->PRec.Access&ACC_AREAD)
  88.                 {
  89.                         accstr[0] = 'r';
  90.                 }
  91.                 if(pb->PRec.Access&ACC_AWRITE)
  92.                 {
  93.                         accstr[1] = 'w';
  94.                 }
  95.                 if(pb->PRec.Access&ACC_GREAD)
  96.                 {
  97.                         accstr[2] = 'r';
  98.                 }
  99.                 if(pb->PRec.Access&ACC_GWRITE)
  100.                 {
  101.                         accstr[3] = 'w';
  102.                 }
  103.                 if(pb->PRec.Access&ACC_OREAD)
  104.                 {
  105.                         accstr[4] = 'r';
  106.                 }
  107.                 if(pb->PRec.Access&ACC_OWRITE)
  108.                 {
  109.                         accstr[5] = 'w';
  110.                 }
  111.                 
  112.                 /* get the time of last modification */
  113.                 t1 = (char *)&pb->PRec.MDate;
  114.                 t2 = (char *)&pb->PRec.MTime;
  115.                 
  116.                 /* sanity check it */
  117.                 if(((t1[2]<13)&&(t1[2]>0))&&((t1[3]>0)&&(t1[3]<32)))
  118.                 {
  119.                         sprintf(datebuff, "%s %2.2d %2.2d:%02.2d:%02.2d", months[t1[2]-1], t1[3], t2[0], t2[1], t2[2]);
  120.                 }
  121.                 else    /* bad date values */
  122.                 {
  123.                         strcpy(datebuff, "<Date Corrupt> ");
  124.                 }
  125.                 
  126.                 /* print the string to STDOUT */
  127.                 printf("%s %8.8d  %s  %s  %s\n", accstr, len, hltype, datebuff, pb->PRec.Name);
  128.                 
  129.                 /* get the next one */
  130.                 test = NextPub(pb);
  131.         }
  132.         
  133.         /* print the totals */
  134.         printf("Editions: %d     Bytes: %d\n", toted, totlen);
  135.         
  136.         /* free the PubBlock pointer obtained by AllocPBlock() */
  137.         (void)FreePBlock(pb);
  138.         
  139.         /* Unregister this program from the hotlinks system */
  140.         UnRegister(hlh);
  141.         
  142.         /* close the hotlink library and exit */
  143.         CloseLibrary((struct Library *)HotLinksBase);
  144. }
  145.