home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / amiga / programm / 15983 < prev    next >
Encoding:
Text File  |  1992-11-17  |  13.0 KB  |  448 lines

  1. Path: sparky!uunet!caen!zaphod.mps.ohio-state.edu!sdd.hp.com!nobody
  2. From: briang@sdd.hp.com (Brian Gragg)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: AutoDocs -> AmigaGuide creater
  5. Date: 17 Nov 1992 21:36:57 GMT
  6. Organization: Hewlett-Packard, San Diego Division
  7. Lines: 436
  8. Distribution: world
  9. Message-ID: <1ebolpINNrq2@hpsdlss3.sdd.hp.com>
  10. NNTP-Posting-Host: hpsdlm16.sdd.hp.com
  11.  
  12. Hi all,
  13.  
  14. I've written a relatively small C program (using SAS/C 6.0) to read in the
  15. Commodore Autodocs and create an amigaguide data file.  It isn't perfect
  16. since there are some typos in the Autodocs.  The program is small enough that
  17. I've included it here.  Please no flames as they just go to /dev/null.
  18.  
  19. It converts any entry in the Autodocs with a    NAME -    (name spaces dash)
  20. as in FREEMEM -- frees memory  to be made into a FREEMEM() entry in the
  21. amigaguide data file.  You will find a few places that didn't work quite
  22. right, but you can edit the database and fix them as you find them.  I've only
  23. run across 4 so far.  Also, if you see a mention of a function (like
  24. AllocMem() ) you can click on the word (even if it isn't highlighted) to 
  25. jump you straight to the AllocMem() entry (in amigaguide of course).  
  26. If the AutoDocs just say  AllocMem  you would need to edit the file and add 
  27. the ()'s to be able to automatically jump it.
  28.  
  29. It is easy to then add a command to your editor (like in sc) that will look
  30. up the word under your cursor.  So from the editor, I can type 
  31. BltClear, put the cursor on it, hit a key sequence, and have the autodoc for
  32. BltClear() brought up for me in amigaguide.
  33.  
  34. The data file created is around 1.2 meg (as I remeber) but it includes the
  35. entire autodocs.  The code here is not elegent, especially since I have no 
  36. documentation on how amigaguide works or the format of the files.
  37.  
  38. You will find it creates a amigaguide file that is first broken up by 
  39. library/device and then the funcions found in that library or device file.
  40.  
  41. Have fun and let me know what you think.
  42.  
  43.   Brian Gragg    briang@sdd.hp.com   hp-sdd!briang  uunet!ucsd!hp-sdd!briang
  44.  
  45. -------------------------------cut here----------------------------------- 
  46.  
  47. /*  GenADocGuide.c
  48.  *
  49.  *  Generates an amigaguide database for the Commodore Amiga AutoDocs
  50.  *
  51.  *  1992 Brian Gragg, San Diego, CA  (31.10.92)
  52.  *  Released to the Public Domain.  
  53.  */
  54.  
  55. #define DEFAULTGUIDEFILE "autodocs.guide"
  56. #define CANCEL           (0)
  57. #define OK               (1)
  58. #define NAMEBYTES        (4000)
  59. #define CTRL_L           (12)
  60. #define BSIZE            (255)
  61. #define SPACE            (32)
  62.  
  63. #include <stdlib.h>
  64. #include <stdio.h>
  65. #include <string.h>
  66. #include <time.h>
  67. #include <dos.h>
  68. #include <sys/dir.h>
  69. #include <exec/types.h>
  70. #include <exec/memory.h>
  71. #include <dos/dos.h>
  72. #include <libraries/asl.h>
  73. #include <intuition/intuition.h>
  74.  
  75. #include <proto/all.h>
  76. /*
  77. #include <clib/sys_protos.h>
  78. #include <clib/exec_protos.h>
  79. #include <clib/dos_protos.h>
  80. #include <clib/intuition_protos.h>
  81. #include <clib/asl_protos.h>
  82. */
  83.  
  84. /* VERSION STRING */
  85. UBYTE vers[] = "\0$VER: GenADocGuide 1.1  (11-1-92)";
  86.  
  87. /*extern struct DosLibrary *DOSBase = NULL;*/
  88. /*extern struct IntuitionBase *IntuitionBase;*/
  89. /*extern struct Library *SysBase;*/
  90. extern int _OSERR;
  91.  
  92. struct EasyStruct failedES = {
  93.     sizeof(struct EasyStruct), 0, vers,
  94.     "%s",
  95.     "OK",
  96. };
  97.  
  98. struct EasyStruct OkCanES = {
  99.     sizeof(struct EasyStruct), 0, vers,
  100.     "%s",
  101.     "OK|CANCEL",
  102. };
  103.  
  104. #ifdef LATTICE
  105. int  CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  106. void chkabort(void) { return; } 
  107. #endif
  108.  
  109.  
  110. char  buffer[BSIZE];
  111. char  *nullstr      = "";
  112. char  adDir[BSIZE];
  113. char  adGuide[BSIZE]= DEFAULTGUIDEFILE;
  114. BPTR  adDirLock     = NULL;
  115. BPTR  adGuideLock   = NULL;
  116. FILE  *guidefp      = NULL;
  117. char  *names        = NULL;
  118.  
  119.  
  120. /* my protos */
  121. void cleanExit(char *);
  122. void Usage (void);
  123. void doFile (char *);
  124. void doMainMenu (char *);
  125. int getbasename (FILE *, char *, char **);
  126.  
  127. void
  128. main(int argc, char *argv[])
  129. {
  130.     char    exten[100];
  131.     long    t;
  132.     int     count, i;
  133.     char    *name_ptrs[60];
  134.     char    adGuidename[100];
  135.     int     args = argc - 1;
  136.  
  137.     /* Check for valide autodocs directory */
  138.     if (( args < 1 ) || ( !stricmp(argv[1],"?")) || (!stricmp(argv[1],"H")) ||
  139.        ( args > 2 ))
  140.    
  141.     {
  142.         Usage();
  143.         cleanExit(nullstr);
  144.     }
  145.         if ( NULL == (adDirLock = Lock(argv[1],ACCESS_READ))) 
  146.         {
  147.             sprintf(buffer,"AutoDocs directory %s not found.\n",argv[1]);
  148.             cleanExit(buffer);
  149.         }
  150.    
  151.     /* Get autodocs directory */
  152.     if (getpath(adDirLock, adDir))
  153.     {
  154.         sprintf(buffer,"Unable to get path for %s.\n",argv[1]);
  155.         cleanExit(buffer);
  156.     }
  157.    
  158.     /* Get output guide file - note adGuide is already set to the default */
  159.     if ( args==2 ) 
  160.     {
  161.         strcpy(adGuide,argv[2]);
  162.         stcgfe(exten, adGuide);
  163.         
  164.         if (strcmpi(exten,"guide"));
  165.             strcat(adGuide,".guide");
  166.         
  167.         if ( -1 != (adGuideLock = findpath(adGuide))) 
  168.         {
  169.             sprintf(buffer,"File %s exists.\nDelete and overwrite file?",argv[2]);
  170.             if (OK != EasyRequest(NULL, &OkCanES, NULL,buffer))
  171.                 cleanExit(nullstr);
  172.             
  173.             UnLock(adGuideLock);
  174.             adGuideLock = NULL;
  175.             
  176.             if (!remove(argv[2])) 
  177.             {
  178.                 sprintf(buffer,"Couldn't delete %s.",argv[2]);
  179.                 cleanExit(buffer);
  180.             }
  181.         }
  182.     }
  183.     adGuideLock = NULL;
  184.     
  185.     /* Open Guide file for output */
  186.     if (NULL == (guidefp = fopen( adGuide, "w" )))
  187.     {
  188.         sprintf(buffer,"Couldn't open %s.",adGuide);
  189.         cleanExit(buffer);
  190.     }
  191.     
  192.     /* Initialize the guide file */
  193.     if ( stcgfn(adGuidename,adGuide) < 1 )  /* strip the file path */
  194.         strcpy(adGuidename,adGuide);
  195.     fprintf(guidefp,
  196.         "@database \"%s\"\n\n",strncpy(buffer,adGuide,strlen(adGuide)-6));
  197.     fprintf(guidefp,"\n\n@master \"%s\"\n\n",adGuidename);
  198.         time(&t);
  199.     fprintf(guidefp,"@Remark $VER: %s, built %s",adGuidename,ctime(&t));
  200.     fprintf(guidefp,"@Remark AutoDocs database for amigaguide.\n");
  201.     fprintf(guidefp,"@Remark Produced with %s\n\n",vers+7);
  202.     fprintf(guidefp,"@Node Main \"%s\"\n",adGuidename);
  203.  
  204.     /* Read the files in the directory */
  205.     if (NULL == (names = (UBYTE *) AllocMem( NAMEBYTES, MEMF_CLEAR )))
  206.         cleanExit("Couldn't allocate space for filenames.");
  207.   
  208.     sprintf(buffer,"%s/#?.doc",adDir);
  209.     (count = getfnl(buffer,names,NAMEBYTES,0));
  210.     if ( count <= 0 )
  211.     {
  212.         if ( _OSERR )
  213.         {
  214.             sprintf(buffer,"Error accessing the files\nin %s.",adDir);
  215.             cleanExit(buffer);
  216.         }
  217.         else
  218.             cleanExit("Too many files in the\nAutoDocs directory!");
  219.     }
  220.          
  221.     if (strbpl(name_ptrs,300,names) != count)
  222.         cleanExit("Too many file names in the \nAutoDocs directory!");
  223.  
  224.     tqsort(name_ptrs,count);
  225.  
  226.     for ( i=0; i<count; i++ )
  227.         doMainMenu(name_ptrs[i]);
  228.     
  229.     fprintf(guidefp,"@EndNode\n\n");         
  230.  
  231.     for ( i=0; i<count; i++ )
  232.         doFile(name_ptrs[i]);
  233.         
  234.     /* All Done */
  235.     cleanExit(nullstr);
  236. }
  237.  
  238.  
  239. /*************************************************************************
  240. *   cleanExit("ExitMsg")
  241. *
  242. *   puts "ExitMsg" up in a requester and then quits.
  243. *************************************************************************/
  244. void
  245. cleanExit(char *exitMsg)
  246. {
  247.     if ( strlen(exitMsg) > 0 )
  248.         EasyRequest(NULL, &failedES, NULL, exitMsg);
  249.     
  250.     if ( guidefp     != NULL )   fclose( guidefp );
  251.     if ( adDirLock   != NULL )   UnLock( adDirLock );
  252.     if ( adGuideLock != NULL )   UnLock( adGuideLock );
  253.     if ( names       != NULL )   FreeMem( names, NAMEBYTES );
  254.            
  255.     exit(0);
  256. }
  257.  
  258. /***************************************************************************
  259. *   Usage()
  260. *
  261. *   displays the usage 
  262. ***************************************************************************/
  263. void
  264. Usage(void)
  265. {
  266.     printf("%s\n\n",vers);
  267.     printf("USAGE: GenADocGuide directory [guidefile]\n");
  268.     printf("       default guidefile is %s\n",DEFAULTGUIDEFILE);
  269. }
  270.  
  271. /***************************************************************************
  272. *   doFile(*fname)
  273. *
  274. *   Creates the amigaguide database for the file fname
  275. ***************************************************************************/
  276. void
  277. doFile(char *fname)
  278. {
  279.     FILE *docfp;
  280.     char *dashptr;
  281.     char *slashptr;
  282.     char *nodename;
  283.     char nodeline[BSIZE];
  284.     char basename[BSIZE];
  285.     char mybuf[BSIZE];
  286.     char *fail;
  287.     
  288.     if (NULL == (docfp = fopen( fname, "r" )))
  289.     {
  290.         sprintf(buffer,"Couldn't open %s",fname);
  291.         EasyRequest(NULL, &failedES, NULL,buffer);
  292.         return;
  293.     }
  294.  
  295.     if (getbasename(docfp, basename, &slashptr))
  296.     {
  297.         /* Couldn't get base name from inside file.  Use filename instead. */
  298.         if (stcgfn(basename,fname) == 0)
  299.         {
  300.            sprintf(buffer,"Couldn't get name from file %s",fname);
  301.            EasyRequest(NULL, &failedES, NULL,buffer);
  302.            fclose(docfp);
  303.            return;
  304.         }
  305.         basename[strlen(basename)-4] = '\0';  /* strip off the .doc */
  306.         fprintf(guidefp,"@Node \"%s\"\n",basename);
  307.     }
  308.     else
  309.         fprintf(guidefp,"@Node \"%s\"\n",basename);
  310.  
  311.     /* Build node list */
  312.     /* 1st node was already found in getbasename */
  313.     slashptr[strlen(slashptr+1)] = '\0';   /* get rid of trailing \n */
  314.     fprintf(guidefp,"@{\" %s() \" Link \"%s()\"}\n",slashptr+1,slashptr+1);
  315.     
  316.     fail = fgets( mybuf, BSIZE, docfp );
  317.     
  318.     while (( mybuf[0] != CTRL_L ) && ( fail != NULL ))
  319.     {
  320.         if (NULL == (slashptr = strchr(mybuf,'/')))
  321.             break;
  322.         slashptr[strlen(slashptr+1)] = '\0';   /* get rid of trailing \n */
  323.         fprintf(guidefp,"@{\" %s() \" Link \"%s()\"}\n",slashptr+1,slashptr+1);
  324.         fail = fgets( mybuf, BSIZE, docfp );
  325.     }
  326.     fprintf(guidefp,"@EndNode\n\n");
  327.  
  328.     
  329.     /* Do functions in file as nodes */
  330.     while (fail != NULL)
  331.     {
  332.        /* Wait for NAME field */
  333.        fail = fgets( nodeline, BSIZE, docfp );
  334.        if (fail == NULL) break;
  335.    
  336.        while ( strstr(nodeline,"NAME") == NULL )
  337.            if (NULL == (fail = fgets( nodeline, BSIZE, docfp ))) break;
  338.        
  339.        fail = fgets( nodeline, BSIZE, docfp );
  340.        while (( fail != NULL ) && ( strlen(nodeline) < 3 )) 
  341.            (fail = fgets( nodeline, BSIZE, docfp ));
  342.        
  343.        if (fail == NULL) break;
  344.        
  345.        if (NULL == (dashptr = strchr(nodeline,'-')))
  346.            dashptr = nodeline + strlen(nodeline);  /* just use full line */
  347.        strcpy(mybuf,nodeline);
  348.        
  349.      /* Set nodename & first line of data*/
  350.        *(dashptr-1) = '\0';
  351.        nodename = nodeline;
  352.        while ( nodename[0] <= SPACE )  /* remove spaces, tabs, etc... */
  353.            nodename++;
  354.  
  355.        nodename[strlen(nodename)] = '\0';   /* get rid of trailing \n */
  356.  
  357.        fprintf(guidefp,"@Node \"%s()\"\n",nodename);
  358.        fprintf(guidefp,"   NAME                                          %s\n",basename);
  359.        
  360.    
  361.        /* Transfer the rest of the data for this node */
  362.        while ((mybuf[0] != CTRL_L) && (fail != NULL))
  363.        {
  364.            fprintf(guidefp,"%s",mybuf);
  365.            fail = fgets( mybuf, BSIZE, docfp );
  366.        }
  367.        fprintf(guidefp,"@EndNode\n\n");
  368.     }
  369.     
  370.     fclose(docfp);
  371.     return;
  372. }
  373.  
  374.     
  375. /***************************************************************************
  376. *   doMainMenu(*fname)
  377. *
  378. *   Creates the amigaguide main index for the file 
  379. ***************************************************************************/
  380. void
  381. doMainMenu(char *fname)
  382. {
  383.     FILE *docfp;
  384.     char *slashptr;
  385.     char mybuf[BSIZE];
  386.     
  387.     if (NULL == (docfp = fopen( fname, "r" )))
  388.     {
  389.         sprintf(buffer,"Couldn't open %s.",fname);
  390.         EasyRequest(NULL, &failedES, NULL,buffer);
  391.         return;
  392.     }
  393.  
  394.     if (getbasename(docfp, mybuf, &slashptr))
  395.     {
  396.         /* Couldn't get base name from inside file.  Use filename instead. */
  397.         if (stcgfn(mybuf,fname) == 0)
  398.         {
  399.            sprintf(buffer,"Couldn't get name from file %s",fname);
  400.            EasyRequest(NULL, &failedES, NULL,buffer);
  401.            fclose(docfp);
  402.            return;
  403.         }
  404.         mybuf[strlen(mybuf)-4] = '\0';  /* strip off the .doc */
  405.     }
  406.  
  407.     fprintf(guidefp,"   @{\" %s \" link \"%s\"}\n",mybuf,mybuf);
  408.  
  409.     fclose(docfp);
  410. }    
  411.  
  412.  
  413. /***************************************************************************
  414. *   success = getbasename(*fileptr, *buf, *slashptr)
  415. *
  416. *   Sets buf to point to the base name of the opend file and slashptr to point
  417. *   to the slash before the first function.
  418. *   success = 0 if ok   1 if failed
  419. ***************************************************************************/
  420. int
  421. getbasename(FILE *fileptr, char *buf, char **slashptrptr)
  422. {
  423.     BOOL cont;
  424.     char *fail;
  425.     
  426.     do
  427.     {
  428.        cont = FALSE;
  429.        fail = fgets( buf, BSIZE, fileptr );
  430.        while ((( buf[0] == '\n' ) || ( strnicmp(buf,"TABLE",5) == 0 )) 
  431.                                  && (fail != NULL ))
  432.            fail = fgets( buf, BSIZE, fileptr );
  433.        
  434.        if ( fail == NULL ) 
  435.            return(1);
  436.        
  437.        if ( (*slashptrptr = strchr(buf,'/')) == NULL )
  438.            cont = TRUE;
  439.     } while (cont == TRUE);
  440.               
  441.     **slashptrptr = '\0';
  442.     
  443.     return(0);
  444. }
  445.            
  446.  
  447.  
  448.