home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / AUTODOC.ZIP / AUTODOC.C next >
Encoding:
C/C++ Source or Header  |  1988-06-21  |  21.7 KB  |  943 lines

  1. #define TURBOC
  2. #include <stdio.h>
  3. #ifdef AMIGA
  4. #include <functions.h>
  5. #endif
  6. #ifdef DATAGENERAL
  7. #include <packets:filestatus.h>
  8. #include <time.h>
  9. #endif
  10. #ifdef TURBOC
  11. #include <io.h>
  12. #include <fcntl.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <stddef.h>
  16. #include <time.h>
  17. #endif
  18. /* definition of whitespace macro */
  19. #define iswhitespace(c) (if((c) == ' ' || (c) == '\n' || (c) == '\011' || (c) == '\014') ? 1L : 0L)
  20. #ifdef AMIGA
  21. struct stat {
  22.     char st_attr;
  23.     long st_mtime;
  24.     long st_size;
  25.     long st_rsize;
  26. };
  27.  
  28. /* settings of the st_attr field */
  29. #define    ST_DELETE    0x01
  30. #define    ST_EXECUTE    0x02
  31. #define    ST_WRITE    0x04
  32. #define    ST_READ        0x08
  33.  
  34. /* the format of the st_mtime field is:
  35.     seconds since Jan 1, 1978 */
  36. #endif
  37.  
  38. /* misc useful definitions */
  39. #define true 1
  40. #define false 0
  41. typedef int BOOL;
  42. #define MAXNAME 50
  43. #define SINGLEQUOTE '\047'
  44.  
  45. /* important Boolean global states of things */
  46. BOOL needfiledef;
  47. BOOL needmoddef;
  48. BOOL renamefiles;
  49. BOOL updatemode;
  50. BOOL hasauthor;
  51. BOOL dofuncfile;
  52. BOOL displayonly;
  53. BOOL noheader;
  54.  
  55. /* other important ints */
  56. long flength; /* length of original file in bytes */
  57.  
  58. /* global character strings - names of stuff */
  59. char author[MAXNAME];
  60. char filename[100];
  61. char newfilename[100];
  62. char funcfile[100];
  63. char LastWord[40];
  64. char revdate[10];
  65. /* and the files themselves */
  66. FILE *fin;
  67. FILE *fout;
  68. FILE *ffunc;
  69.  
  70. /* the pointers into the buffer containing the input source code */
  71. char *beginning, *current, *marker;
  72.  
  73. /* some useful character strings */
  74. char *allstars = "**************************************************************";
  75. char *startcomment = "/*+*";
  76. char * endcomment = "*+*/";
  77. char * shortstar = "****";
  78.  
  79. /* the module definition structure */
  80. #define MAXARGS 20
  81. struct moddef {
  82.         struct moddef *next;
  83.     char name[MAXNAME];
  84.     char *simplename;
  85.     char *offset;
  86.     short numargs;
  87.     short typemask;
  88.     struct argdef {
  89.         char argname[MAXNAME];
  90.         char typestring[40];
  91.         short typemask;
  92.         } args[MAXARGS];
  93.     } *firstdef;
  94. #define STRUCT 0x0001 /*  typemask for is a structure */
  95. #define SHRT 0x0002 /* typemask for is short */
  96. #define LNG 0x0004 /* is long */
  97. #define TYPEINT 0x0008 /* is an int */
  98. #define CHR 0x0010 /* is a character */
  99. #define UNS 0x0020 /* is unsigned */
  100. #define PTR 0x0040 /* is a pointer */
  101. #define FLT 0x0080 /* is floating point */
  102. #define VOID 0x0100 /* void funciton type */
  103. #define HASSTRING 0x0200 /* has a string description (usually structure) */
  104. /* the file definition packet */
  105.  
  106. struct filedef{
  107.         short numlines;
  108.     char *start;
  109.     char desc[1000];
  110.     } fdef;
  111.  
  112. /* masks for parsing the c source code file */
  113. #define INCOMMENT 0x0001
  114. #define OUTCOMMENT 0xfffe
  115. #define INDOUBQUOTE 0x0002
  116. #define OUTDOUBQUOTE 0xfffd
  117. #define INSINGQUOTE 0x0004
  118. #define OUTSINGQUOTE 0xfffb
  119.  
  120. /* function declarations */
  121. void decodeargs(), copytoend(),writemodule(),badnews(),
  122.     dofiledef(),getmoddef(),findmoddef(),renfiles(),dohelp(),writetype();
  123. long filesize();
  124. short setmask();
  125. BOOL copybytes();
  126. char *strchr(),*writeheader();
  127. /*%%*/
  128. /* And here we go */
  129.  
  130. main(argc,argv)
  131. int argc;
  132. char *argv[];
  133. {
  134.     long offset,bytescopied;
  135.     struct moddef *nextmodule,*prevmodule;
  136.     int err;
  137.     char *cptr;
  138.  
  139.     offset = bytescopied = 0; /*haven't done anything yet */
  140.     noheader = true;
  141.     decodeargs(argc,argv);
  142.     if(needfiledef) dofiledef();
  143.     if(needmoddef) getmoddef();
  144.     if(updatemode) findmoddef();
  145.    if(!displayonly)
  146.    {
  147.      cptr = writeheader();
  148.      nextmodule = firstdef;
  149.      if(!cptr) cptr = beginning;
  150.      while(nextmodule)
  151.      {
  152.        while( cptr <  nextmodule->offset)
  153.         {
  154.        err = putc(*cptr,fout);
  155.        if(err == -1) badnews("Error writing file\n");
  156.        ++cptr;
  157.         }
  158.         writemodule(nextmodule);
  159.         prevmodule = nextmodule;
  160.           nextmodule = nextmodule->next;
  161.         free(prevmodule); /* we're done with this data */
  162.      }
  163.      while(cptr < beginning + flength)
  164.         {
  165.        err = putc(*cptr,fout);
  166.        if(err == -1) badnews("Error writing file\n");
  167.        ++cptr;
  168.         }
  169.    } /* end of if not displayonly */
  170.     if(renamefiles) renfiles();
  171.     if(beginning) free(beginning);
  172. }
  173.  
  174. void badnews(mesg)
  175. char *mesg;
  176. {
  177.   printf("Bad news! %s\n",mesg);
  178.   exit(1);
  179. }
  180.  
  181. void decodeargs(argc,argv)
  182. int argc;
  183. char *argv[];
  184. {
  185.   register short i;
  186.   BOOL OK;
  187.   char *firstcptr,firstchar;
  188.   void GetDate();
  189.  
  190.   /* the intial state of things */
  191.   hasauthor = false;
  192.   needfiledef = false;
  193.   updatemode = true;
  194.   dofuncfile = false;
  195.   renamefiles = false;
  196.   needmoddef = true;
  197.   displayonly = false;
  198.   fin = fout = ffunc = (FILE *)NULL;  
  199.  
  200.   for(i=1;i<argc;++i)
  201.   {
  202.     if(*argv[i]=='-')   /* switch argument */
  203.     {
  204.         firstcptr = ++argv[i];
  205.         firstchar = toupper( *firstcptr);
  206.         switch (firstchar)
  207.         {
  208.             case 'A':
  209.                 ++firstcptr;
  210.                 strncpy(&author[0],firstcptr,30);
  211.                 hasauthor = true;
  212.                 break;
  213.  
  214.             case 'F':
  215.                 ++firstcptr;
  216.         if(*firstcptr)
  217.         {
  218.                   strncpy(&funcfile[0],firstcptr,100);
  219.                   ffunc = fopen(&funcfile[0],"a");
  220.             }
  221.                 dofuncfile = true;
  222.                 break;
  223.  
  224.             case 'X':
  225.                  ;
  226.                 break;
  227.  
  228.             case 'N':
  229.                 ++firstcptr;
  230.                 strncpy(&newfilename[0],firstcptr,100);
  231.                 fout = fopen(&newfilename[0],"w+");
  232.         break;
  233.  
  234.             case 'I':
  235.                 updatemode = false;
  236.                 break;
  237.  
  238.         case 'V':
  239.             displayonly = true;
  240.         break;
  241.  
  242.         case 'D':
  243.         ++firstcptr;
  244.         strncpy(&revdate[0],firstcptr,8);
  245.         break;
  246.  
  247.         } /*end of switch on switches */
  248.     } /* end of if arg starts with a '-'*/
  249.     else if(fin)
  250.     {
  251.       /* input filename already open so they screwed up */
  252.       dohelp("Two input files specified. I handle only 1");
  253.     }
  254.     else
  255.     { /* got a filename - open it */
  256.          strncpy(&filename[0],argv[i],100);
  257.          if(!(fin = fopen(&filename[0],"r+")))
  258.                 {
  259.                     printf("Could not open input file %s \n",&filename[0]);
  260.                     exit(1);
  261.             }
  262.     }
  263.   } /* for loop */
  264.      if(!fin) dohelp("No file specified.\n"); /*no input file specified */
  265.      if(displayonly) 
  266.     { updatemode = true;
  267.       renamefiles = false;
  268.     }
  269.      if(!fout) 
  270.           {
  271.              fout = fopen("tempout","w+");
  272.              strcpy(&newfilename[0],"ram:tempout");
  273.              renamefiles = true;
  274.         }
  275.      flength = filesize(&filename[0]);
  276.      printf("Input file is %dL bytes long.\n",flength);
  277.      if(flength <0) 
  278.     exit(1);
  279.      if(dofuncfile && !ffunc)
  280.        { /* open default functionfile - filename.h */
  281.           strncpy(&funcfile[0],&filename[0],100);
  282.        funcfile[strlen(funcfile)-1] = 'h';
  283.              if(!(     ffunc = fopen(&funcfile[0],"a")))
  284.          printf("Warning! could not open function file %s\n",
  285.             &funcfile[0]);
  286.        }
  287.  
  288.      if(!(beginning = (char *)calloc(flength,1)))
  289.     { dohelp("Not enough memory to read source file.\n");
  290.     }
  291.      checkforheader();
  292.      if(!hasauthor && !displayonly)
  293.     { printf("Author? ");
  294.       gets(&author[0]);
  295.     }
  296.      if(updatemode)
  297.     {
  298.        needfiledef = false;
  299.        needmoddef = false;
  300.     }
  301.       if(!revdate[0])
  302.     GetDate(&revdate[0]);
  303.  
  304. }
  305.  
  306.  
  307. checkforheader()
  308. {
  309.     needfiledef = true;
  310. }
  311.  
  312. #ifdef DATAGENERAL
  313.  
  314. long filesize(fname)
  315. char *fname;
  316. {
  317.     P_FSTAT fstat_pack,*AC2;
  318.     long AC1,size;
  319.  
  320.     AC1 = 0;
  321.     AC2 = &fstat_pack;
  322.     size =(sys($FSTAT,&fname,&AC1,&AC2) ? 1L : fstat_pack.sefm);
  323.     return(size); 
  324. }
  325.  
  326. void GetDate(string)
  327. char *string;
  328. { struct tm *now; 
  329.  
  330.    now = dg_localtime (0L);   /* first get todays date/time info */
  331.    sprintf(string,"%02d/%02d/%02d",(now->tm_mon+1),now->tm_mday,
  332.              (now->tm_year % 100));
  333. }
  334.  
  335. #endif
  336. #ifdef AMIGA
  337.  
  338. long filesize(fname)
  339. char *fname;
  340. {
  341.     struct stat fstat_pak;
  342.     long size;
  343.  
  344.     if((stat(fname,&fstat_pak)) != -1) return(fstat_pak.st_size);
  345.     else
  346.        return(1);
  347.  
  348. }
  349. #endif
  350. #ifdef TURBOC
  351.  
  352. long filesize(fname)
  353. char *fname;
  354. {
  355. int fp;
  356. long flen;
  357.  
  358.   fp=open(fname,O_RDONLY);
  359.   if (fp==-1)
  360.     return(1);
  361.   else {
  362.     flen = filelength(fp);
  363.     close(fp);
  364.     return(flen);
  365.   }
  366. }
  367.  
  368. void GetDate(string)
  369. char *string;
  370. {
  371.  struct tm *now;
  372.  time_t t;
  373.  
  374.    t   = time(NULL);
  375.    now = localtime (&t);   /* first get todays date/time info */
  376.    sprintf(string,"%02d/%02d/%02d",(now->tm_mon+1),now->tm_mday,
  377.             (now->tm_year % 100));
  378. }
  379.  
  380. #endif
  381.  
  382. void dohelp(cptr)
  383. char *cptr;
  384. {
  385.    printf("%s\n",cptr);
  386.    printf("Usage: autodoc filename [options]\n   Where options are:\n");
  387.    printf("   -aauthor\n");
  388.    printf("   -f[functionfilename]   writes function declaration file\n");
  389.    printf("   -v      display only (lists undocumented functions)\n");
  390.    printf("   -i      input data from keyboard instead of updating file\n");
  391.    printf("   -nnewfilename    writes output to newfilename\n");
  392.    printf("   -dMM/DD/YY  use MM/DD/YY as release date\n");
  393.    if(beginning) free(beginning);
  394.    exit(1);
  395. }
  396.  
  397.  
  398.  
  399. void dofiledef()
  400. {
  401.     char linebuffer[200],*cptr;
  402.     short i,ilen;
  403.     long readerr;
  404.     BOOL more;
  405.     
  406.     i=1;
  407.     printf("Enter description for file %s\n",&filename[0]);
  408.     cptr = &fdef.desc[0];
  409.     more = true;
  410.     do
  411.        {
  412.       printf("%3d) ",i);
  413.       gets(cptr);
  414.       if( ilen = strlen(cptr))
  415.         { cptr += ilen+1;
  416.                   ++i;
  417.               ++ fdef.numlines;
  418.           }
  419.       else
  420.       {
  421.           more = false;
  422.       }
  423.     }
  424.     while(more);
  425.  }
  426.  
  427.  
  428. char *writeheader ()
  429. {
  430.     struct moddef *nextmodule;
  431.     short i;
  432.     char *cptr;
  433.     
  434.  if(noheader)
  435.   {
  436.      fprintf(fout,"%s%s\n%s\n",startcomment,allstars,shortstar);
  437.        fprintf(fout,"%s File %s by  %s  Created %s\n",shortstar,&filename[0],
  438.         &author[0],&revdate[0]);
  439.      if(ffunc)
  440.     fprintf(ffunc,"/***** Function declarations for %s ****/\n",
  441.           &filename[0]);        
  442.     for(i=0,cptr = &fdef.desc[0]; i< fdef.numlines; ++i)
  443.     {
  444.         fprintf(fout,"%s    %s\n",shortstar,cptr);
  445.         cptr += strlen(cptr)+1;
  446.     }
  447.         
  448.     fprintf(fout,"%s\n%s   Contains functions: \n%s    ",
  449.       shortstar,shortstar,shortstar);
  450.      cptr = (char *)0;
  451.   } /* end of noheader at all */
  452.   else /* there is a header */
  453.    { cptr = beginning;
  454.      while(cptr < fdef.start)
  455.     { putc(*cptr,fout);
  456.       ++cptr;
  457.     }
  458.      if(firstdef)
  459.     fprintf(fout,"%s    ",shortstar);
  460.  
  461.     }
  462.     nextmodule = firstdef;
  463.     while(nextmodule)
  464.     {
  465.  
  466.        if(noheader)
  467.          fprintf(fout,"%s() \n%s   ",&nextmodule->name[0],shortstar);
  468.        else
  469.      fprintf(fout,"%s() added %s\n%s    ",&nextmodule->name[0],
  470.         &revdate[0],shortstar);
  471.        if(ffunc)
  472.          fprintf(ffunc,"%s ();\n",&nextmodule->name[0]);
  473.           nextmodule = nextmodule->next;
  474.     }
  475.     if(!cptr)
  476.      fprintf(fout,"\n%s\n%s%s\n",shortstar,allstars,endcomment);
  477.      return (cptr);
  478. }
  479.  
  480. void copytoend()
  481. {
  482. ;
  483. }
  484.  
  485. struct moddef *makemodule(linebuf,startofline)
  486. char *startofline;
  487. char *linebuf;
  488. { char *cptr1,*cptr2,*cptr3;
  489.   static char simplename[30];
  490.   short slen,namelen;
  491.   struct moddef *mod,*prevmod;
  492.     cptr1 = current -1;
  493.     namelen = min(cptr1 - linebuf,MAXNAME);
  494.     while(*cptr1 == ' ' || *cptr1 == '\011')
  495.        --cptr1;
  496.     cptr2 = cptr1;
  497.     while(*cptr1 != ' ' && *cptr1 != '\011' &&
  498.         *cptr1 != ',' && *cptr1 != '\n')
  499.        --cptr1;
  500.         for(cptr3 = cptr1+1,slen=0; cptr3 <= cptr2;++slen, ++cptr3)
  501.              simplename[slen] = *cptr3;
  502.     simplename[slen] = '\0';
  503.     /* now check to see if we already used this simple name */
  504.     prevmod = mod = firstdef;
  505.     while(mod)
  506.     {
  507.       if(!(strcmp(mod->simplename ,&simplename[0]))) break;
  508.       prevmod = mod;
  509.       mod = mod->next;
  510.     }
  511.     if(!mod)
  512.     {
  513.         mod = calloc(sizeof(struct moddef),1);
  514.         if(prevmod) prevmod->next = mod;
  515.         else firstdef = mod;
  516.     }
  517.         for(cptr3 = linebuf,slen=0,++cptr1; cptr3 <= cptr2;++slen, ++cptr3)
  518.     {  mod->name[slen] = *cptr3;
  519.        if(cptr3 == cptr1) mod->simplename = &mod->name[slen];
  520.         }
  521.     mod->numargs = 0;
  522.     mod->offset = startofline;
  523.     printf(" Found function %s\n",mod->simplename);
  524.     return(mod);
  525.  
  526. }
  527.  
  528.  
  529. void processword(curmod,wordstack,type,lastchptr)
  530. struct moddef *curmod;
  531. char *wordstack,*lastchptr;
  532. short *type;
  533. {
  534. BOOL isvar;
  535. short i;
  536. char *cptr,cword[40];
  537.  
  538.     for(cptr = &cword[0];wordstack < lastchptr;++wordstack,++cptr)
  539.     { *cptr = *wordstack;
  540.     }
  541.     *cptr = '\0';
  542.     if(!strcmp(&cword[0],"short"))
  543.        *type |= SHRT;
  544.         else if(!strcmp(&cword[0],"long"))
  545.        *type |= LNG;
  546.         else if(!strcmp(&cword[0],"struct"))
  547.        *type |= STRUCT;
  548.         else if(!strcmp(&cword[0],"char"))
  549.        *type |= CHR;
  550.     else if(!strcmp(&cword[0],"int"))
  551.        *type |= TYPEINT;
  552.     else if(!strcmp(&cword[0],"*"))
  553.        *type |= PTR;
  554.     else if(!strcmp(&cword[0],"unsigned"))
  555.        *type |= UNS;
  556.     else
  557.     {
  558.        isvar = false;
  559.        for(i=0; i<curmod->numargs && !isvar; ++i)
  560.        {
  561.          if(!strcmp(&cword[0],curmod->args[i].argname))
  562.         {
  563.             curmod->args[i].typemask = *type;
  564.                 isvar = true;
  565.                 if(*type & HASSTRING)
  566.                   strcpy(&curmod->args[i].typestring[0],
  567.                      LastWord);
  568.         }
  569.         }
  570.         if(!isvar)
  571.         { strcpy(LastWord,&cword[0]);
  572.           *type |= HASSTRING;
  573.         }
  574.     }
  575. }
  576.  
  577. void findmoddef()
  578. {
  579.     short slen,level,currenttype;
  580.     register short InFlag;
  581.     struct moddef *curmod;
  582.     BOOL indef,makingmodule,FoundStart,typingargs;
  583.     BOOL foundfuncheader,inblockcomment;
  584.     char *cptr,stack,*startofline,*argptr,*startofmod,*wordstack;
  585.     
  586.     InFlag = indef = makingmodule = typingargs = 0;
  587.     foundfuncheader = inblockcomment = 0;
  588.     currenttype = 0;
  589.     current = beginning;
  590.     stack = 0;
  591.     level = 0;
  592.     inblockcomment = 0;
  593.     FoundStart = false;
  594.     while(fgets(current,500,fin))
  595.     {
  596.           startofline = current;
  597.       startofmod = startofline;
  598.       indef = false; /* assumes only one line macros */
  599.       while(*current)
  600.       {
  601.        if(InFlag) /* we are inside a comment, a single quote or a double
  602.             quote */
  603.          {
  604.           switch (*current)
  605.           {
  606.              case '/':
  607.              if(stack == '*' && (InFlag & INCOMMENT))
  608.                 {InFlag = 0; /* clear comment */
  609.              if(!FoundStart && inblockcomment)
  610.                 fdef.start = startofline;
  611.              inblockcomment = false;
  612.             }
  613.              break;
  614.          case '"':
  615.               if(InFlag & INDOUBQUOTE)
  616.              InFlag = 0; /* clear double quote */
  617.               break;
  618.          case SINGLEQUOTE:
  619.               if(InFlag & INSINGQUOTE)
  620.             InFlag = 0; /* clear single quote */
  621.               break;
  622.              case '%':
  623.                  if(InFlag & INCOMMENT && stack == '%')
  624.             FoundStart = true;
  625.              break;
  626.              case '+':
  627.                  if(InFlag & INCOMMENT && stack == '*')
  628.             inblockcomment = true;
  629.              if(inblockcomment && !FoundStart)
  630.                 noheader = false;
  631.              if(inblockcomment && level == 0 && FoundStart)
  632.             foundfuncheader = true;
  633.              break;
  634.             } /*end of switch */
  635.          } /* end of if inside something */
  636.         else /* not inside something */
  637.         {
  638.          switch (*current)
  639.          {
  640.                 case '*':
  641.                if(stack == '/')
  642.             InFlag |= INCOMMENT;/*set comment flag */
  643.               else if (typingargs)
  644.             currenttype |= PTR;
  645.              break;
  646.                   case '#':
  647.              if(stack == '\n')
  648.             indef = true;
  649.              break;
  650.             case '{':
  651.               ++level;
  652.               typingargs = false;
  653.               foundfuncheader = false;
  654.               break;
  655.              case '}':
  656.                --level;
  657.             break;
  658.                  case SINGLEQUOTE:
  659.             InFlag |= INSINGQUOTE;
  660.             break;
  661.              case '"':
  662.             InFlag |= INDOUBQUOTE;
  663.             break;
  664.              case '(':
  665.                 if (level == 0 && !indef && FoundStart &&
  666.                  !foundfuncheader && !typingargs)
  667.               {
  668.                  makingmodule = true;
  669.                  curmod = makemodule(startofmod,startofline);
  670.                  argptr = &curmod->args[0].argname[0];
  671.               }
  672.                    ++ level;
  673.             break;
  674.              case ')':
  675.             startofmod = current+1;
  676.             if(makingmodule)
  677.               {
  678.                 wordstack = current;
  679.                 typingargs = true;
  680.               }
  681.             makingmodule = false;
  682.             -- level;
  683.                     break;
  684.              default :
  685.              if(makingmodule)
  686.             {
  687.               if(isalpha(*current))
  688.                { if(argptr == &curmod->args[0].argname[0])
  689.                 curmod->numargs = 1;
  690.                  *argptr = *current;
  691.                  ++argptr;
  692.                }
  693.               else if(*current == ',')
  694.                {
  695.                   *argptr = '\0';
  696.                    argptr =
  697.                    &curmod->args[curmod->numargs].argname[0];
  698.                   ++curmod->numargs;
  699.                }
  700.             } /* end of if makingmodule */
  701.                 else if(typingargs)
  702.             {
  703.               if(!isalpha(*wordstack))
  704.                 wordstack = current; /* ignore leading
  705.                             whitespace */
  706.               else
  707.                  { if (!isalpha(*current) && *current != '*')
  708.                 {
  709.                  processword(curmod,wordstack,¤ttype,
  710.                       current);
  711.                  wordstack = current;
  712.                 }
  713.                 if(*current == ';') currenttype = 0;
  714.                  }
  715.             } /* end of typing args */
  716.                     break; /* end of default case */
  717.                    } /* end of switch on current */
  718.              } /* end of else implying not inside something */
  719.          stack = *current;
  720.                  ++current;
  721.  
  722.           } /* end of while more data in line to process
  723.             } /* end of more data to read */
  724.     }
  725. }
  726.  
  727. void getmoddef()
  728. {
  729.     struct moddef *next,*previous;
  730.     char linebuffer[100],*cptr,*typeptr,*nameptr;
  731.     short i,j,ich;
  732.     BOOL morefuncs,moreargs;
  733.  
  734.     /* first find the end of the module definition list */
  735.     previous = firstdef;
  736.     while(previous && previous->next)
  737.     {
  738.     previous = previous->next;
  739.  
  740.     }
  741.  
  742.     /* keep accepting definitions for modules until they don't want any more */
  743.     morefuncs = true;
  744.     printf("First enter the modules that you want to add documentation for\n\n");
  745.     j=1;
  746.     while(morefuncs)
  747.     {
  748.     printf("Enter the name for module %d :",j++);
  749.     gets(linebuffer);
  750.         if(linebuffer[0])
  751.     {
  752.         next = (struct moddef *)calloc(sizeof(struct moddef),1);
  753.         if (previous) previous->next = next;
  754.         else
  755.         { previous = next;
  756.           firstdef = next;
  757.         }
  758.         if(linebuffer[0] == '-')
  759.           {
  760.            cptr = strchr(&linebuffer[1],' ');
  761.            if(cptr)
  762.             {
  763.          nameptr = cptr+1;
  764.          *cptr = '\0';
  765.              typeptr = &linebuffer[1];
  766.         }
  767.             else
  768.         {
  769.          nameptr = &linebuffer[0];
  770.          typeptr = (char *) 0 ;
  771.             }
  772.            }
  773.         else
  774.         {
  775.          nameptr = &linebuffer[0];
  776.          typeptr = (char *) 0;
  777.             }
  778.  
  779.         strncpy(&next->name[0],nameptr,MAXNAME);
  780.         if(!typeptr)
  781.           { printf("Type function (i,s,l,c,f and/or u) : ");
  782.            gets(linebuffer);
  783.            typeptr = &linebuffer[0];
  784.           }
  785.         next->typemask = setmask(typeptr);
  786.         /* now keep accepting argument definitions until done */
  787.         i=0;
  788.         moreargs = true;
  789.         while(moreargs && i < MAXARGS)
  790.         {
  791.             printf("\n Enter the name for argument %d: ",i+1);
  792.           gets(linebuffer);
  793.           if(linebuffer[0])
  794.           {
  795.                if(linebuffer[0] == '-')
  796.             {
  797.              cptr = strchr(&linebuffer[1],' ');
  798.                   if(cptr)
  799.                      {
  800.                 nameptr = cptr+1;
  801.               *cptr = '\0';
  802.                typeptr = &linebuffer[1];
  803.                  }
  804.               else
  805.              {
  806.                 nameptr = &linebuffer[0];
  807.                   typeptr = (char *) 0;
  808.               }
  809.                 }
  810.              else
  811.         {
  812.                 nameptr = &linebuffer[0];
  813.                  typeptr = (char *) 0;
  814.             }
  815.            strncpy(&(next->args[i].argname[0]),nameptr,MAXNAME);
  816.                if(!typeptr)
  817.             {
  818.                    printf("Type argument (i,s,l,c,f and/or u) : ");
  819.                gets(linebuffer);
  820.                typeptr = &linebuffer[0];
  821.             }
  822.            next->args[i].typemask = setmask(typeptr);
  823.            ++next->numargs;
  824.          }
  825.           else
  826.         moreargs = false;
  827.           ++i;
  828.           } 
  829.     } /* input to functions */
  830.     else
  831.        morefuncs = false;
  832.       }
  833.  
  834. }
  835.  
  836. void renfiles()
  837. {
  838. ;
  839. }
  840.  
  841. short setmask(cptr)
  842. char *cptr;
  843. {
  844.     short mask;
  845.     mask = 0;
  846.         while(*cptr)
  847.          {
  848.         switch(tolower(*cptr))
  849.         {
  850.           case 'i':
  851.             mask |= TYPEINT;
  852.             break;
  853.           case 's':
  854.             mask |= SHRT;
  855.             break;
  856.           case '*':
  857.             mask |= PTR ;
  858.             break;
  859.           case 'f':
  860.             mask |= FLT;
  861.             break;
  862.           case 'u':
  863.             mask |= UNS;
  864.             break;
  865.           case 'c':
  866.             mask |= CHR;
  867.             break;
  868.           case 'v':
  869.             mask |= VOID;
  870.             break;
  871.         }
  872.           ++cptr;
  873.         } /* end of while cptr */
  874.     return (mask);
  875. }
  876.  
  877.  
  878.  
  879. void writemodule(module)
  880. struct moddef *module;
  881. {
  882.    short i;
  883.    fprintf(fout,"%s%s\n%s\n%s   ",startcomment,allstars,shortstar,shortstar);
  884.     writetype(module->typemask,fout);
  885.     fprintf(fout,"%s (",&module->name[0]);
  886.     for    (i=0;i<module->numargs;++i)
  887.     {
  888.     writetype(module->args[i].typemask,fout);
  889.     if(module->args[i].typemask & HASSTRING)
  890.       {
  891.          fprintf(fout,"%s ",&module->args[i].typestring[0]);
  892.          if(module->args[i].typemask & PTR)
  893.         fprintf(fout,"*");
  894.       }
  895.     fprintf(fout,"%s",
  896.         &(module->args[i].argname[0]));
  897.     if(i+1 < module->numargs)
  898.         fprintf(fout,",\n%s              ",shortstar);
  899.  
  900.     }
  901.      fprintf(fout,")\n%s",shortstar);
  902.     fprintf(fout,"\n%s\n%s    Author: %s\n",shortstar,
  903.         shortstar,&author[0]);
  904.     fprintf(fout,"%s    Revision History:\n%s    %s Original Release\n%s\n%s%s\n\n",
  905.     shortstar,shortstar,&revdate[0],
  906.     shortstar,allstars,endcomment);
  907.  
  908. }
  909.  
  910.  
  911. void writetype(mask,f)
  912. short mask;
  913. FILE *f;
  914. {
  915.     if (mask & UNS)
  916.     fprintf(f,"unsigned ");
  917.     if (mask & LNG)
  918.     fprintf(f,"long ");
  919.     if (mask & SHRT)
  920.     fprintf(f,"short ");
  921.     if (mask & TYPEINT)
  922.     fprintf(f,"int ");
  923.     if (mask & CHR)
  924.     fprintf(f,"char ");
  925.     if (mask & FLT)
  926.     fprintf(f,"float ");
  927.     if (mask & VOID)
  928.     fprintf(f,"void ");
  929.     if (mask & STRUCT)
  930.     fprintf(f,"struct ");
  931.     if (mask & PTR && !(mask  & HASSTRING))
  932.     fprintf(f,"*");
  933.  
  934. }
  935.  
  936.  
  937.  
  938. BOOL copybytes(numbytes)
  939. long numbytes;
  940. {;
  941.  return (true);
  942. }
  943.