home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Docs / cxref-1.4a.lha / html.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-07  |  31.9 KB  |  1,195 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/RCS/html.c 1.22 1997/11/20 19:19:06 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.4a.
  5.  
  6.   Writes the HTML output.
  7.   ******************/ /******************
  8.   Written by Andrew M. Bishop
  9.  
  10.   This file Copyright 1995,96,97 Andrew M. Bishop
  11.   It may be distributed under the GNU Public License, version 2, or
  12.   any higher version.  See section COPYING of the GNU Public license
  13.   for conditions under which this file may be redistributed.
  14.   ***************************************/
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <unistd.h>
  22.  
  23. #ifdef AMIGA
  24. #include "amiga.h"
  25. #endif /* AMIGA */
  26.  
  27. #include "memory.h"
  28. #include "datatype.h"
  29. #include "cxref.h"
  30.  
  31. /*+ The name of the output tex file that includes each of the others. +*/
  32. #define HTML_FILE        ".html"
  33. #define HTML_FILE_BACKUP ".html~"
  34.  
  35. /*+ The name of the output tex file that contains the appendix. +*/
  36. #define HTML_APDX        ".apdx"
  37.  
  38. /*+ The comments are to be inserted verbatim. +*/
  39. extern int option_verbatim_comments;
  40.  
  41. /*+ The name of the directory for the output. +*/
  42. extern char* option_odir;
  43.  
  44. /*+ The base name of the file for the output. +*/
  45. extern char* option_name;
  46.  
  47. /*+ The directories to go back to get to the base output directory. +*/
  48. static char* goback=NULL;
  49.  
  50. static void WriteHTMLFilePart(File file);
  51. static void WriteHTMLInclude(Include inc);
  52. static void WriteHTMLSubInclude(Include inc,int depth);
  53. static void WriteHTMLDefine(Define def);
  54. static void WriteHTMLTypedef(Typedef type);
  55. static void WriteHTMLStructUnion(StructUnion su,int depth);
  56. static void WriteHTMLVariable(Variable var);
  57. static void WriteHTMLFunction(Function func);
  58.  
  59. static void WriteHTMLDocument(char* name,int appendix);
  60. static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile);
  61. static void WriteHTMLPostamble(FILE* f,int sourcefile);
  62.  
  63. static char* html(char* c);
  64.  
  65. /*+ The output file for the HTML. +*/
  66. static FILE* of;
  67.  
  68. /*++++++++++++++++++++++++++++++++++++++
  69.   Write an html file for a complete File structure and all components.
  70.  
  71.   File file The File structure to output.
  72.   ++++++++++++++++++++++++++++++++++++++*/
  73.  
  74. void WriteHTMLFile(File file)
  75. {
  76.  char* ofile;
  77.  int i;
  78.  
  79.  /* Write the including file. */
  80.  
  81.  WriteHTMLDocument(file->name,0);
  82.  
  83.  /* Open the file */
  84.  
  85.  ofile=ConcatStrings(4,option_odir,"/",file->name,HTML_FILE);
  86.  
  87.  of=fopen(ofile,"w");
  88.  if(!of)
  89.    {
  90.     struct stat stat_buf;
  91.     int i,ofl=strlen(ofile);
  92.  
  93.     for(i=strlen(option_odir)+1;i<ofl;i++)
  94.        if(ofile[i]=='/')
  95.          {
  96.           ofile[i]=0;
  97.           if(stat(ofile,&stat_buf))
  98.              mkdir(ofile,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
  99.           ofile[i]='/';
  100.          }
  101.  
  102.     of=fopen(ofile,"w");
  103.    }
  104.  
  105.  if(!of)
  106.    {fprintf(stderr,"cxref: Failed to open the HTML output file '%s'\n",ofile);exit(1);}
  107.  
  108.  for(goback="",i=strlen(file->name);i>0;i--)
  109.     if(file->name[i]=='/')
  110.        goback=ConcatStrings(2,goback,"../");
  111.  
  112.  /* Write out a header. */
  113.  
  114.  WriteHTMLPreamble(of,ConcatStrings(5,"Cross reference for ",file->name," of ",option_name,"."),0);
  115.  
  116.  /*+ The file structure is broken into its components and they are each written out. +*/
  117.  
  118.  WriteHTMLFilePart(file);
  119.  
  120.  if(file->includes)
  121.    {
  122.     Include inc =file->includes;
  123.     fprintf(of,"\n<hr>\n<h2>Included Files</h2>\n\n");
  124.     do{
  125.        WriteHTMLInclude(inc);
  126.       }
  127.     while((inc=inc->next));
  128.    }
  129.  
  130.  if(file->defines)
  131.    {
  132.     Define def =file->defines;
  133.     fprintf(of,"\n<hr>\n<h2>Preprocessor definitions</h2>\n\n");
  134.     do{
  135.        if(def!=file->defines)
  136.           fprintf(of,"<p>\n");
  137.        WriteHTMLDefine(def);
  138.       }
  139.     while((def=def->next));
  140.    }
  141.  
  142.  if(file->typedefs)
  143.    {
  144.     Typedef type=file->typedefs;
  145.     do{
  146.        WriteHTMLTypedef(type);
  147.       }
  148.     while((type=type->next));
  149.    }
  150.  
  151.  if(file->variables)
  152.    {
  153.     int any_to_mention=0;
  154.     Variable var=file->variables;
  155.  
  156.     do{
  157.        if(var->scope&(GLOBAL|LOCAL|EXTERNAL|EXTERN_F))
  158.           any_to_mention=1;
  159.       }
  160.     while((var=var->next));
  161.  
  162.     if(any_to_mention)
  163.       {
  164.        int first_ext=1,first_local=1;
  165.        Variable var=file->variables;
  166.        do{
  167.           if(var->scope&GLOBAL)
  168.              WriteHTMLVariable(var);
  169.          }
  170.        while((var=var->next));
  171.        var=file->variables;
  172.        do{
  173.           if(var->scope&(EXTERNAL|EXTERN_F) && !(var->scope&GLOBAL))
  174.             {
  175.              if(first_ext)
  176.                {fprintf(of,"\n<hr>\n<h2>External Variables</h2>\n\n"); first_ext=0;}
  177.              else
  178.                 fprintf(of,"<p>\n");
  179.              WriteHTMLVariable(var);
  180.             }
  181.          }
  182.        while((var=var->next));
  183.        var=file->variables;
  184.        do{
  185.           if(var->scope&LOCAL)
  186.             {
  187.              if(first_local)
  188.                {fprintf(of,"\n<hr>\n<h2>Local Variables</h2>\n\n"); first_local=0;}
  189.              else
  190.                 fprintf(of,"<p>\n");
  191.              WriteHTMLVariable(var);
  192.             }
  193.          }
  194.        while((var=var->next));
  195.       }
  196.    }
  197.  
  198.  if(file->functions)
  199.    {
  200.     Function func=file->functions;
  201.     do{
  202.        if(func->scope&(GLOBAL|EXTERNAL))
  203.           WriteHTMLFunction(func);
  204.       }
  205.     while((func=func->next));
  206.     func=file->functions;
  207.     do{
  208.        if(func->scope&LOCAL)
  209.           WriteHTMLFunction(func);
  210.       }
  211.     while((func=func->next));
  212.    }
  213.  
  214.  WriteHTMLPostamble(of,0);
  215.  
  216.  fclose(of);
  217.  
  218. /* Clear the memory in html() */
  219.  
  220.  html(NULL); html(NULL); html(NULL); html(NULL);
  221. }
  222.  
  223.  
  224. /*++++++++++++++++++++++++++++++++++++++
  225.   Write a File structure out.
  226.  
  227.   File file The File to output.
  228.   ++++++++++++++++++++++++++++++++++++++*/
  229.  
  230. static void WriteHTMLFilePart(File file)
  231. {
  232.  int i;
  233.  
  234.  fprintf(of,"<h1><a name=\"file\">File %s</a></h1>\n",html(file->name));
  235.  
  236.  if(file->comment)
  237.     if(option_verbatim_comments)
  238.        fprintf(of,"<pre>\n%s\n</pre>\n\n",html(file->comment));
  239.     else
  240.       {
  241.        char *rcs1=strstr(file->comment,"$Header"),*rcs2=NULL;
  242.        if(rcs1)
  243.          {
  244.           rcs2=strstr(&rcs1[1],"$");
  245.           if(rcs2)
  246.             {
  247.              rcs2[0]=0;
  248.              fprintf(of,"<b>RCS %s</b>\n<p>\n",html(&rcs1[1]));
  249.              rcs2[0]='$';
  250.             }
  251.          }
  252.        if(rcs2)
  253.           fprintf(of,"%s\n<p>\n",html(&rcs2[2]));
  254.        else
  255.           fprintf(of,"%s\n<p>\n",html(file->comment));
  256.       }
  257.  
  258.  if(file->inc_in->n)
  259.    {
  260.     int i;
  261.  
  262.     fprintf(of,"<dl compact>\n<dt>Included in:\n<dd><ul>\n");
  263.     for(i=0;i<file->inc_in->n;i++)
  264.        fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#file\">%s</a><br>\n",goback,file->inc_in->s[i],html(file->inc_in->s[i]));
  265.     fprintf(of,"</ul></dl>\n");
  266.    }
  267.  
  268.  if(file->f_refs->n || file->v_refs->n)
  269.     fprintf(of,"<dl compact>\n");
  270.  
  271.  if(file->f_refs->n)
  272.    {
  273.     int others=0;
  274.     fprintf(of,"<dt>References Functions:\n<dd><ul>\n");
  275.     for(i=0;i<file->f_refs->n;i++)
  276.        if(file->f_refs->s2[i])
  277.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i]),html(file->f_refs->s2[i]));
  278.        else
  279.           others++;
  280.  
  281.     if(others)
  282.       {
  283.        fprintf(of,"<li>");
  284.        for(i=0;i<file->f_refs->n;i++)
  285.           if(!file->f_refs->s2[i])
  286.              fprintf(of,--others?" %s(),":" %s()",html(file->f_refs->s1[i]));
  287.        fprintf(of,"\n");
  288.       }
  289.     fprintf(of,"</ul>\n");
  290.    }
  291.  
  292.  if(file->v_refs->n)
  293.    {
  294.     int others=0;
  295.     fprintf(of,"<dt>References Variables:\n<dd><ul>\n");
  296.     for(i=0;i<file->v_refs->n;i++)
  297.       {
  298.        if(file->v_refs->s2[i])
  299.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s  :  %s</a>\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i]),html(file->v_refs->s2[i]));
  300.        else
  301.           others++;
  302.       }
  303.  
  304.     if(others)
  305.       {
  306.        fprintf(of,"<li>");
  307.        for(i=0;i<file->v_refs->n;i++)
  308.           if(!file->v_refs->s2[i])
  309.              fprintf(of,--others?" %s,":" %s",html(file->v_refs->s1[i]));
  310.        fprintf(of,"\n");
  311.       }
  312.     fprintf(of,"</ul>\n");
  313.    }
  314.  
  315.  if(file->f_refs->n || file->v_refs->n)
  316.     fprintf(of,"</dl>\n");
  317. }
  318.  
  319.  
  320. /*++++++++++++++++++++++++++++++++++++++
  321.   Write an Include structure out.
  322.  
  323.   Include inc The Include structure to output.
  324.   ++++++++++++++++++++++++++++++++++++++*/
  325.  
  326. static void WriteHTMLInclude(Include inc)
  327. {
  328.  if(inc->comment)
  329.     fprintf(of,"%s\n<p>\n",html(inc->comment));
  330.  
  331.  fprintf(of,"<ul>\n");
  332.  
  333.  if(inc->scope==LOCAL)
  334.     fprintf(of,"<li><tt><a href=\"%s%s"HTML_FILE"#file\">#include "%s"</a></tt>\n",goback,inc->name,html(inc->name));
  335.  else
  336.     fprintf(of,"<li><tt>#include <%s></tt>\n",html(inc->name));
  337.  
  338.  if(inc->includes)
  339.     WriteHTMLSubInclude(inc->includes,1);
  340.  
  341.  fprintf(of,"</ul>\n");
  342. }
  343.  
  344.  
  345. /*++++++++++++++++++++++++++++++++++++++
  346.   Write an Sub Include structure out. (An include structure that is included from another file.)
  347.  
  348.   Include inc The Include structure to output.
  349.  
  350.   int depth The depth of the include hierarchy.
  351.   ++++++++++++++++++++++++++++++++++++++*/
  352.  
  353. static void WriteHTMLSubInclude(Include inc,int depth)
  354. {
  355.  fprintf(of,"<ul>\n");
  356.  
  357.  while(inc)
  358.    {
  359.     if(inc->scope==LOCAL)
  360.        fprintf(of,"<li><tt><a href=\"%s%s"HTML_FILE"#file\">#include "%s"</a></tt>\n",goback,inc->name,html(inc->name));
  361.     else
  362.        fprintf(of,"<li><tt>#include <%s></tt>\n",html(inc->name));
  363.  
  364.     if(inc->includes)
  365.        WriteHTMLSubInclude(inc->includes,depth+1);
  366.  
  367.     inc=inc->next;
  368.    }
  369.  
  370.  fprintf(of,"</ul>\n");
  371. }
  372.  
  373.  
  374. /*++++++++++++++++++++++++++++++++++++++
  375.   Write a Define structure out.
  376.  
  377.   Define def The Define structure to output.
  378.   ++++++++++++++++++++++++++++++++++++++*/
  379.  
  380. static void WriteHTMLDefine(Define def)
  381. {
  382.  int i;
  383.  int pargs=0;
  384.  
  385.  if(def->comment)
  386.     fprintf(of,"%s\n<p>\n",html(def->comment));
  387.  
  388.  fprintf(of,"<tt>#define %s",html(def->name));
  389.  
  390.  if(def->value)
  391.     fprintf(of," %s",html(def->value));
  392.  
  393.  if(def->args->n)
  394.    {
  395.     fprintf(of,"( ");
  396.     for(i=0;i<def->args->n;i++)
  397.        fprintf(of,i?", %s":"%s",html(def->args->s1[i]));
  398.     fprintf(of," )");
  399.    }
  400.  fprintf(of,"</tt><br>\n");
  401.  
  402.  for(i=0;i<def->args->n;i++)
  403.     if(def->args->s2[i])
  404.        pargs=1;
  405.  
  406.  if(pargs)
  407.    {
  408.     fprintf(of,"<dl compact>\n");
  409.     for(i=0;i<def->args->n;i++)
  410.        fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(def->args->s1[i]),def->args->s2[i]?html(def->args->s2[i]):"");
  411.     fprintf(of,"</dl>\n");
  412.    }
  413. }
  414.  
  415.  
  416. /*++++++++++++++++++++++++++++++++++++++
  417.   Write a Typedef structure out.
  418.  
  419.   Typedef type The Typedef structure to output.
  420.   ++++++++++++++++++++++++++++++++++++++*/
  421.  
  422. static void WriteHTMLTypedef(Typedef type)
  423. {
  424.  fprintf(of,"\n<hr>\n<h2>");
  425.  
  426.  if(!strncmp("enum",type->name,4))
  427.     fprintf(of,"<a name=\"type-enum-%s\">",&type->name[5]);
  428.  else
  429.     if(!strncmp("union",type->name,5))
  430.        fprintf(of,"<a name=\"type-union-%s\">",&type->name[6]);
  431.     else
  432.        if(!strncmp("struct",type->name,6))
  433.           fprintf(of,"<a name=\"type-struct-%s\">",&type->name[7]);
  434.        else
  435.           fprintf(of,"<a name=\"type-%s\">",type->name);
  436.  
  437.  if(type->type)
  438.     fprintf(of,"Typedef %s",html(type->name));
  439.  else
  440.     fprintf(of,"Type %s",html(type->name));
  441.  
  442.  fprintf(of,"</a></h2>\n");
  443.  
  444.  if(type->comment)
  445.     fprintf(of,"%s\n<p>\n",html(type->comment));
  446.  
  447.  if(type->type)
  448.     fprintf(of,"<tt>typedef %s</tt><br>\n",html(type->type));
  449.  
  450.  if(type->sutype)
  451.    {
  452.     fprintf(of,"<ul>\n");
  453.     WriteHTMLStructUnion(type->sutype,0);
  454.     fprintf(of,"</ul>\n");
  455.    }
  456.  else
  457.     if(type->typexref)
  458.       {
  459.        fprintf(of,"<dl compact>\n<dt>See:\n<dd><ul>\n");
  460.        if(type->typexref->type)
  461.           fprintf(of,"<li><a href=\"#type-%s\">Typedef %s</a>\n",type->typexref->name,html(type->typexref->name));
  462.        else
  463.           if(!strncmp("enum",type->typexref->name,4))
  464.              fprintf(of,"<li><a href=\"#type-enum-%s\">Type %s</a>\n",&type->typexref->name[5],html(type->typexref->name));
  465.           else
  466.              if(!strncmp("union",type->typexref->name,5))
  467.                 fprintf(of,"<li><a href=\"#type-union-%s\">Type %s</a>\n",&type->typexref->name[6],html(type->typexref->name));
  468.              else
  469.                 if(!strncmp("struct",type->typexref->name,6))
  470.                    fprintf(of,"<li><a href=\"#type-struct-%s\">Type %s</a>\n",&type->typexref->name[7],html(type->typexref->name));
  471.        fprintf(of,"</ul></dl>\n");
  472.       }
  473. }
  474.  
  475.  
  476. /*++++++++++++++++++++++++++++++++++++++
  477.   Write a structure / union structure out.
  478.  
  479.   StructUnion su The structure / union to write.
  480.  
  481.   int depth The current depth within the structure.
  482.   ++++++++++++++++++++++++++++++++++++++*/
  483.  
  484. static void WriteHTMLStructUnion(StructUnion su, int depth)
  485. {
  486.  int i;
  487.  char* splitsu=NULL;
  488.  
  489.  splitsu=strstr(su->name,"{...}");
  490.  if(splitsu) splitsu[-1]=0;
  491.  
  492.  if(depth && su->comment && !su->comps)
  493.     fprintf(of,"<li><tt>%s;      </tt>%s<br>\n",html(su->name),html(su->comment));
  494.  else
  495.     fprintf(of,"<li><tt>%s%s</tt><br>\n",html(su->name),su->comps?"":";");
  496.  
  497.  if(su->comps)
  498.    {
  499.     fprintf(of,"<ul>\n");
  500.  
  501.     fprintf(of,"<li><tt>{</tt><br>\n");
  502.  
  503.     for(i=0;i<su->n_comp;i++)
  504.        WriteHTMLStructUnion(su->comps[i],depth+1);
  505.  
  506.     fprintf(of,"<li><tt>}</tt><br>\n");
  507.  
  508.     fprintf(of,"</ul>\n");
  509.  
  510.     if(splitsu)
  511.       {
  512.        if(depth && su->comment)
  513.           fprintf(of,"<li><tt>%s;      </tt>%s<br>\n",splitsu[5]?html(&splitsu[6]):"",html(su->comment));
  514.        else
  515.           fprintf(of,"<li><tt>%s;</tt><br>\n",splitsu[5]?html(&splitsu[6]):"");
  516.       }
  517.    }
  518.  
  519.  if(splitsu) splitsu[-1]=' ';
  520. }
  521.  
  522.  
  523. /*++++++++++++++++++++++++++++++++++++++
  524.   Write a Variable structure out.
  525.  
  526.   Variable var The Variable structure to output.
  527.   ++++++++++++++++++++++++++++++++++++++*/
  528.  
  529. static void WriteHTMLVariable(Variable var)
  530. {
  531.  int i;
  532.  
  533.  if(var->scope&GLOBAL)
  534.     fprintf(of,"\n<hr>\n<h2><a name=\"var-%s\">Global Variable %s</a></h2>\n",var->name,html(var->name));
  535.  else
  536.     fprintf(of,"<b><a name=\"var-%s\">%s</a></b><br>\n",var->name,html(var->name));
  537.  
  538.  if(var->comment)
  539.     fprintf(of,"%s\n<p>\n",html(var->comment));
  540.  
  541.  fprintf(of,"<tt>");
  542.  
  543.  if(var->scope&LOCAL)
  544.     fprintf(of,"static ");
  545.  else
  546.     if(!(var->scope&GLOBAL) && var->scope&(EXTERNAL|EXTERN_F))
  547.        fprintf(of,"extern ");
  548.  
  549.  fprintf(of,"%s</tt><br>\n",html(var->type));
  550.  
  551.  if(var->scope&(GLOBAL|LOCAL))
  552.    {
  553.     if(var->incfrom || var->visible->n || var->used->n)
  554.        fprintf(of,"<dl compact>\n");
  555.  
  556.     if(var->incfrom)
  557.       {
  558.        fprintf(of,"<dt>Included from:\n<dd><ul>\n");
  559.        fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",goback,var->incfrom,var->name,html(var->incfrom));
  560.        fprintf(of,"</ul>\n");
  561.       }
  562.  
  563.     if(var->visible->n)
  564.       {
  565.        fprintf(of,"<dt>Visible in:\n<dd><ul>\n");
  566.        for(i=0;i<var->visible->n;i++)
  567.           if(var->visible->s1[i][0]=='$')
  568.              fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",goback,var->visible->s2[i],html(var->visible->s2[i]));
  569.           else
  570.              fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s1[i]),html(var->visible->s2[i]));
  571.        fprintf(of,"</ul>\n");
  572.       }
  573.  
  574.     if(var->used->n)
  575.       {
  576.        fprintf(of,"<dt>Used in:\n<dd><ul>\n");
  577.        for(i=0;i<var->used->n;i++)
  578.          {
  579.           if(var->used->s1[i][0]=='$')
  580.              fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",goback,var->used->s2[i],html(var->used->s2[i]));
  581.           else
  582.             {
  583.              if(var->scope&LOCAL)
  584.                 fprintf(of,"<li><a href=\"#func-%s\">%s()</a>\n",var->used->s1[i],html(var->used->s1[i]));
  585.              else
  586.                 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s1[i]),html(var->used->s2[i]));
  587.             }
  588.          }
  589.        fprintf(of,"</ul>\n");
  590.       }
  591.  
  592.     if(var->incfrom || var->visible->n || var->used->n)
  593.        fprintf(of,"</dl>\n");
  594.    }
  595.  else
  596.     if(var->scope&(EXTERNAL|EXTERN_F) && var->defined)
  597.       {
  598.        fprintf(of,"<dl compact>\n<dt>Defined in:\n<dd><ul>\n");
  599.        fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>",goback,var->defined,html(var->name),var->defined);
  600.        fprintf(of,"</ul></dl>\n");
  601.       }
  602. }
  603.  
  604.  
  605. /*++++++++++++++++++++++++++++++++++++++
  606.   Write a Function structure out.
  607.  
  608.   Function func The Function structure to output.
  609.   ++++++++++++++++++++++++++++++++++++++*/
  610.  
  611. static void WriteHTMLFunction(Function func)
  612. {
  613.  int i,pret,pargs;
  614.  char* comment2=NULL,*type;
  615.  
  616.  if(func->scope&GLOBAL)
  617.     fprintf(of,"\n<hr>\n<h2><a name=\"func-%s\">Global Function %s()</a></h2>\n",func->name,html(func->name));
  618.  else
  619.     fprintf(of,"\n<hr>\n<h2><a name=\"func-%s\">Local Function %s()</a></h2>\n",func->name,html(func->name));
  620.  
  621.  if(func->comment)
  622.     if(option_verbatim_comments)
  623.        fprintf(of,"<pre>\n%s\n</pre>\n\n",html(func->comment));
  624.     else
  625.       {
  626.        comment2=strstr(func->comment,"\n\n");
  627.        if(comment2)
  628.           comment2[0]=0;
  629.        fprintf(of,"%s\n<p>\n",html(func->comment));
  630.       }
  631.  
  632.  fprintf(of,"<tt>");
  633.  
  634.  if(func->scope&LOCAL)
  635.     fprintf(of,"static ");
  636.  if(func->scope&INLINED)
  637.    fprintf(of,"inline ");
  638.  
  639.  if((type=strstr(func->type,"()")))
  640.     type[0]=0;
  641.  fprintf(of,"%s ( ",html(func->type));
  642.  
  643.  for(i=0;i<func->args->n;i++)
  644.     fprintf(of,i?", %s":"%s",html(func->args->s1[i]));
  645.  
  646.  if(type)
  647.    {fprintf(of," %s</tt><br>\n",html(&type[1]));type[0]='(';}
  648.  else
  649.     fprintf(of," )</tt><br>\n");
  650.  
  651.  pret =strncmp("void ",func->type,5) && func->cret;
  652.  for(pargs=0,i=0;i<func->args->n;i++)
  653.     pargs = pargs || ( strcmp("void",func->args->s1[i]) && func->args->s2[i] );
  654.  
  655.  if(pret || pargs)
  656.    {
  657.     fprintf(of,"<dl compact>\n");
  658.     if(pret)
  659.        fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(func->type),func->cret?html(func->cret):"&nbs;");
  660.     if(pargs)
  661.        for(i=0;i<func->args->n;i++)
  662.           fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(func->args->s1[i]),func->args->s2[i]?html(func->args->s2[i]):"&nbs;");
  663.     fprintf(of,"</dl>\n");
  664.    }
  665.  
  666.  if(comment2)
  667.    {
  668.     fprintf(of,"%s\n<p>\n",html(&comment2[2]));
  669.     comment2[0]='\n';
  670.    }
  671.  
  672.  if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n)
  673.     fprintf(of,"<dl compact>\n");
  674.  
  675.  if(func->protofile)
  676.    {
  677.     fprintf(of,"<dt>Prototyped in:\n<dd><ul>\n");
  678.     fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",goback,func->protofile,html(func->protofile));
  679.     fprintf(of,"</ul>\n");
  680.    }
  681.  
  682.  if(func->incfrom)
  683.    {
  684.     fprintf(of,"<dt>Included from:\n<dd><ul>\n");
  685.     fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->incfrom,func->name,html(func->incfrom));
  686.     fprintf(of,"</ul>\n");
  687.    }
  688.  
  689.  if(func->calls->n)
  690.    {
  691.     int others=0;
  692.     fprintf(of,"<dt>Calls:\n<dd><ul>\n");
  693.     for(i=0;i<func->calls->n;i++)
  694.       {
  695.        if(func->calls->s2[i])
  696.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s1[i]),html(func->calls->s2[i]));
  697.        else
  698.           others++;
  699.       }
  700.  
  701.     if(others)
  702.       {
  703.        fprintf(of,"<li>");
  704.        for(i=0;i<func->calls->n;i++)
  705.           if(!func->calls->s2[i])
  706.              fprintf(of,--others?"%s(), ":"%s()",html(func->calls->s1[i]));
  707.        fprintf(of,"\n");
  708.       }
  709.     fprintf(of,"</ul>\n");
  710.    }
  711.  
  712.  if(func->called->n)
  713.    {
  714.     fprintf(of,"<dt>Called by:\n<dd><ul>\n");
  715.     for(i=0;i<func->called->n;i++)
  716.        fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s1[i]),html(func->called->s2[i]));
  717.     fprintf(of,"</ul>\n");
  718.    }
  719.  
  720.  if(func->used->n)
  721.    {
  722.     fprintf(of,"<dt>Used in:\n<dd><ul>\n");
  723.     for(i=0;i<func->used->n;i++)
  724.       {
  725.        if(func->used->s1[i][0]=='$')
  726.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",goback,func->used->s2[i],html(func->used->s2[i]));
  727.        else
  728.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s1[i]),html(func->used->s2[i]));
  729.       }
  730.     fprintf(of,"</ul>\n");
  731.    }
  732.  
  733.  if(func->f_refs->n)
  734.    {
  735.     int others=0;
  736.     fprintf(of,"<dt>References Functions:\n<dd><ul>\n");
  737.     for(i=0;i<func->f_refs->n;i++)
  738.       {
  739.        if(func->f_refs->s2[i])
  740.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s1[i]),html(func->f_refs->s2[i]));
  741.        else
  742.           others++;
  743.       }
  744.  
  745.     if(others)
  746.       {
  747.        fprintf(of,"<li>");
  748.        for(i=0;i<func->f_refs->n;i++)
  749.           if(!func->f_refs->s2[i])
  750.              fprintf(of,--others?"%s(), ":"%s()",html(func->f_refs->s1[i]));
  751.        fprintf(of,"\n");
  752.       }
  753.     fprintf(of,"</ul>\n");
  754.    }
  755.  
  756.  if(func->v_refs->n)
  757.    {
  758.     int others=0;
  759.     fprintf(of,"<dt>References Variables:\n<dd><ul>\n");
  760.     for(i=0;i<func->v_refs->n;i++)
  761.       {
  762.        if(func->v_refs->s2[i])
  763.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s  :  %s</a>\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s1[i]),html(func->v_refs->s2[i]));
  764.        else
  765.           others++;
  766.       }
  767.  
  768.     if(others)
  769.       {
  770.        fprintf(of,"<li>");
  771.        for(i=0;i<func->v_refs->n;i++)
  772.           if(!func->v_refs->s2[i])
  773.              fprintf(of,--others?"%s, ":"%s",html(func->v_refs->s1[i]));
  774.        fprintf(of,"\n");
  775.       }
  776.     fprintf(of,"</ul>\n");
  777.    }
  778.  
  779.  if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n)
  780.     fprintf(of,"</dl>\n");
  781. }
  782.  
  783.  
  784. /*++++++++++++++++++++++++++++++++++++++
  785.   Write out a file that will include the current information.
  786.  
  787.   char* name The name of the file.
  788.  
  789.   int appendix set to non-zero if the appendix file is to be added, else a normal source file.  
  790.   ++++++++++++++++++++++++++++++++++++++*/
  791.  
  792. static void WriteHTMLDocument(char* name,int appendix)
  793. {
  794.  FILE *in,*out;
  795.  char line[256];
  796.  int seen=0;
  797.  char *inc_file,*ofile,*ifile;
  798.  
  799.  if(appendix)
  800.     inc_file=ConcatStrings(4,"<a href=\"",name,HTML_FILE,"\">Appendix</a><br>\n");
  801.  else
  802.     inc_file=ConcatStrings(6,"<a href=\"",name,HTML_FILE,"#file\">",name,"</a><br>\n");
  803.  ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE);
  804.  ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP);
  805.  
  806.  in =fopen(ifile,"r");
  807.  if(!in)
  808.    {
  809.     in =fopen(ifile,"w");
  810.     if(!in)
  811.       {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ifile);exit(1);}
  812.  
  813.     WriteHTMLPreamble(in,ConcatStrings(3,"Cross reference of ",option_name,"."),1);
  814.     WriteHTMLPostamble(in,1);
  815.     fclose(in);
  816.  
  817.     in =fopen(ifile,"r");
  818.    }
  819.  
  820.  out=fopen(ofile,"w");
  821.  
  822.  if(!out)
  823.    {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);exit(1);}
  824.  
  825.  while(fgets(line,256,in))
  826.    {
  827.     if(!strcmp(inc_file,line) ||
  828.        (!strncmp("<!--",line,4) && !strncmp(inc_file,line+4,strlen(inc_file))) ||
  829.        (!strncmp("<!-- ",line,5) && !strncmp(inc_file,line+5,strlen(inc_file))))
  830.       {seen=1;break;}
  831.     if(line[0]=='<' && !strcmp("<!-- End-Of-Source-Files -->\n",line))
  832.       {
  833.        if(appendix)
  834.          {
  835.           fputs(line,out);
  836.           fputs("\n",out);
  837.           fputs("<!-- Appendix -->\n",out);
  838.           fputs("\n",out);
  839.           fputs("<hr>\n",out);
  840.           fputs("<h1>Appendix</h1>\n",out);
  841.           fputs("\n",out);
  842.           fputs(inc_file,out);
  843.          }
  844.        else
  845.          {
  846.           fputs(inc_file,out);
  847.           fputs("\n",out);
  848.           fputs(line,out);
  849.          }
  850.       }
  851.     else
  852.        fputs(line,out);
  853.    }
  854.  
  855.  fclose(in);
  856.  fclose(out);
  857.  
  858.  if(!seen)
  859.    {
  860.     unlink(ifile);
  861.     rename(ofile,ifile);
  862.    }
  863.  else
  864.     unlink(ofile);
  865. }
  866.  
  867.  
  868. /*++++++++++++++++++++++++++++++++++++++
  869.   Write out a standard pre-amble.
  870.  
  871.   FILE* f The file to write the pre amble to.
  872.  
  873.   char* title The title of the file.
  874.  
  875.   int sourcefile True if the Source-Files line is to be included.
  876.   ++++++++++++++++++++++++++++++++++++++*/
  877.  
  878. static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile)
  879. {
  880.  fputs("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n",f);
  881.  fputs("\n",f);
  882.  fputs("<!-- This HTML file generated by cxref. -->\n",f);
  883.  fputs("<!-- cxref program (c) Andrew M. Bishop 1995,96,97. -->\n",f);
  884.  fputs("\n",f);
  885.  fputs("<HTML>\n",f);
  886.  fputs("\n",f);
  887.  fputs("<HEAD>\n",f);
  888.  fputs("<TITLE>",f);
  889.  fputs(title,f);
  890.  fputs("</TITLE>\n",f);
  891.  fputs("</HEAD>\n",f);
  892.  fputs("\n",f);
  893.  fputs("<BODY>\n",f);
  894.  fputs("\n",f);
  895.  if(sourcefile)
  896.    {
  897.     fputs("<h1>Source Files</h1>\n",f);
  898.     fputs("\n",f);
  899.     fputs("<!-- Begin-Of-Source-Files -->\n",f);
  900.    }
  901. }
  902.  
  903.  
  904. /*++++++++++++++++++++++++++++++++++++++
  905.   Write out a standard post-amble. This includes the end of document marker.
  906.  
  907.   FILE* f The file to write the post amble to.
  908.  
  909.   int sourcefile True if the Source-Files line is to be included.
  910.   ++++++++++++++++++++++++++++++++++++++*/
  911.  
  912. static void WriteHTMLPostamble(FILE* f,int sourcefile)
  913. {
  914.  if(sourcefile)
  915.    {
  916.     fputs("\n",f);
  917.     fputs("<!-- End-Of-Source-Files -->\n",f);
  918.    }
  919.  fputs("\n",f);
  920.  fputs("</BODY>\n",f);
  921.  fputs("</HTML>\n",f);
  922. }
  923.  
  924.  
  925. /*++++++++++++++++++++++++++++++++++++++
  926.   Write out the appendix information.
  927.  
  928.   StringList files The list of files to write.
  929.  
  930.   StringList2 funcs The list of functions to write.
  931.  
  932.   StringList2 vars The list of variables to write.
  933.  
  934.   StringList2 types The list of types to write.
  935.   ++++++++++++++++++++++++++++++++++++++*/
  936.  
  937. void WriteHTMLAppendix(StringList files,StringList2 funcs,StringList2 vars,StringList2 types)
  938. {
  939.  char* ofile;
  940.  int i;
  941.  
  942.  /* Write the bits to the including file. */
  943.  
  944.  WriteHTMLDocument(ConcatStrings(2,option_name,HTML_APDX),1);
  945.  
  946.  /* Open the file */
  947.  
  948.  ofile=ConcatStrings(5,option_odir,"/",option_name,HTML_APDX,HTML_FILE);
  949.  
  950.  of=fopen(ofile,"w");
  951.  
  952.  if(!of)
  953.    {fprintf(stderr,"cxref: Failed to open the HTML appendix file '%s'\n",ofile);exit(1);}
  954.  
  955.  /* Write the file structure out */
  956.  
  957.  WriteHTMLPreamble(of,ConcatStrings(3,"Cross reference index of ",option_name,"."),0);
  958.  
  959.  fprintf(of,"<h1>Cross References</h1>\n");
  960.  
  961.  /* Write out the appendix of files. */
  962.  
  963.  if(files->n)
  964.    {
  965.     fprintf(of,"\n<hr>\n<h2><a name=\"files\">Files</a></h2>\n");
  966.     fprintf(of,"<ul>\n");
  967.     for(i=0;i<files->n;i++)
  968.        fprintf(of,"<li><a href=\"%s"HTML_FILE"#file\">%s</a>\n",files->s[i],html(files->s[i]));
  969.     fprintf(of,"</ul>\n");
  970.    }
  971.  
  972.  /* Write out the appendix of functions. */
  973.  
  974.  if(funcs->n)
  975.    {
  976.     fprintf(of,"\n<hr>\n<h2><a name=\"functions\">Global Functions</a></h2>\n");
  977.     fprintf(of,"<ul>\n");
  978.     for(i=0;i<funcs->n;i++)
  979.        fprintf(of,"<li><a href=\"%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",funcs->s2[i],funcs->s1[i],html(funcs->s1[i]),html(funcs->s2[i]));
  980.     fprintf(of,"</ul>\n");
  981.    }
  982.  
  983.  /* Write out the appendix of variables. */
  984.  
  985.  if(vars->n)
  986.    {
  987.     fprintf(of,"\n<hr><h2><a name=\"variables\">Global Variables</a></h2>\n");
  988.     fprintf(of,"<ul>\n");
  989.     for(i=0;i<vars->n;i++)
  990.        fprintf(of,"<li><a href=\"%s"HTML_FILE"#var-%s\">%s  :  %s</a>\n",vars->s2[i],vars->s1[i],html(vars->s1[i]),html(vars->s2[i]));
  991.     fprintf(of,"</ul>\n");
  992.    }
  993.  
  994.  /* Write out the appendix of types. */
  995.  
  996.  if(types->n)
  997.    {
  998.     fprintf(of,"\n<hr><h2><a name=\"types\">Defined Types</a></h2>\n");
  999.     fprintf(of,"<ul>\n");
  1000.     for(i=0;i<types->n;i++)
  1001.        if(!strncmp("enum",types->s1[i],4))
  1002.           fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-enum-%s\">%s  :  %s</a>\n",types->s2[i],&types->s1[i][5],html(types->s1[i]),html(types->s2[i]));
  1003.        else
  1004.           if(!strncmp("union",types->s1[i],5))
  1005.              fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-union-%s\">%s  :  %s</a>\n",types->s2[i],&types->s1[i][6],html(types->s1[i]),html(types->s2[i]));
  1006.           else
  1007.              if(!strncmp("struct",types->s1[i],6))
  1008.                 fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-struct-%s\">%s  :  %s</a>\n",types->s2[i],&types->s1[i][7],html(types->s1[i]),html(types->s2[i]));
  1009.              else
  1010.                 fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-%s\">%s  :  %s</a>\n",types->s2[i],types->s1[i],html(types->s1[i]),html(types->s2[i]));
  1011.     fprintf(of,"</ul>\n");
  1012.    }
  1013.  
  1014.  WriteHTMLPostamble(of,0);
  1015.  
  1016.  fclose(of);
  1017.  
  1018. /* Clear the memory in html() */
  1019.  
  1020.  html(NULL); html(NULL); html(NULL); html(NULL);
  1021. }
  1022.  
  1023.  
  1024. /*++++++++++++++++++++++++++++++++++++++
  1025.   Delete the HTML file and main file reference that belong to the named file.
  1026.  
  1027.   char *name The name of the file to delete.
  1028.   ++++++++++++++++++++++++++++++++++++++*/
  1029.  
  1030. void WriteHTMLFileDelete(char *name)
  1031. {
  1032.  FILE *in,*out;
  1033.  char line[256];
  1034.  int seen=0;
  1035.  char *inc_file,*ofile,*ifile;
  1036.  
  1037.  ofile=ConcatStrings(4,option_odir,"/",name,HTML_FILE);
  1038.  unlink(ofile);
  1039.  
  1040.  inc_file=ConcatStrings(6,"<a href=\"",name,HTML_FILE,"#file\">",name,"</a><br>\n");
  1041.  ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE);
  1042.  ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP);
  1043.  
  1044.  in =fopen(ifile,"r");
  1045.  out=fopen(ofile,"w");
  1046.  
  1047.  if(in && !out)
  1048.    {fprintf(stderr,"cxref: Failed to open the main LaTeX output file '%s'\n",ofile);fclose(in);}
  1049.  else if(in)
  1050.    {
  1051.     while(fgets(line,256,in))
  1052.       {
  1053.        if(!strcmp(inc_file,line) ||
  1054.           (!strncmp("<!--",line,4) && !strncmp(inc_file,line+4,strlen(inc_file)-1)) ||
  1055.           (!strncmp("<!-- ",line,5) && !strncmp(inc_file,line+5,strlen(inc_file)-1)))
  1056.           seen=1;
  1057.        else
  1058.           fputs(line,out);
  1059.       }
  1060.  
  1061.     fclose(in);
  1062.     fclose(out);
  1063.  
  1064.     if(seen)
  1065.       {
  1066.        unlink(ifile);
  1067.        rename(ofile,ifile);
  1068.       }
  1069.     else
  1070.        unlink(ofile);
  1071.    }
  1072.  else if(out)
  1073.    {
  1074.     fclose(out);
  1075.     unlink(ofile);
  1076.    }
  1077. }
  1078.  
  1079.  
  1080. /*++++++++++++++++++++++++++++++++++++++
  1081.   Make the input string safe to output as HTML ( not < > & " ).
  1082.  
  1083.   char* html Returns a safe HTML string.
  1084.  
  1085.   char* c A non-safe HTML string.
  1086.  
  1087.   The function can only be called four times in each fprintf() since it returns one of only four static strings.
  1088.   ++++++++++++++++++++++++++++++++++++++*/
  1089.  
  1090. static char* html(char* c)
  1091. {
  1092.  static char safe[4][256],*malloced[4]={NULL,NULL,NULL,NULL};
  1093.  static int which=0;
  1094.  int i=0,j=0,len=256-5;              /* 5 is the longest possible inserted amount */
  1095.  int eol=1,copy=0,skip=0;
  1096.  char* ret;
  1097.  
  1098.  which=(which+1)%4;
  1099.  ret=safe[which];
  1100.  
  1101.  if(malloced[which])
  1102.    {Free(malloced[which]);malloced[which]=NULL;}
  1103.  
  1104.  if(c)
  1105.     do
  1106.       {
  1107.        for(;j<len && c[i];i++)
  1108.           if(copy)
  1109.             {ret[j++]=c[i]; if(c[i]=='\n') copy=0;}
  1110.           else if(skip)
  1111.             {               if(c[i]=='\n') skip=0;}
  1112.           else switch(c[i])
  1113.             {
  1114.             case '<':
  1115.              eol=0;
  1116.              ret[j++]='&';
  1117.              ret[j++]='l';
  1118.              ret[j++]='t';
  1119.              ret[j++]=';';
  1120.              break;
  1121.             case '>':
  1122.              eol=0;
  1123.              ret[j++]='&';
  1124.              ret[j++]='g';
  1125.              ret[j++]='t';
  1126.              ret[j++]=';';
  1127.              break;
  1128.             case '"':
  1129.              eol=0;
  1130.              ret[j++]='&';
  1131.              ret[j++]='q';
  1132.              ret[j++]='u';
  1133.              ret[j++]='o';
  1134.              ret[j++]='t';
  1135.              ret[j++]=';';
  1136.              break;
  1137.             case '&':
  1138.              eol=0;
  1139.              ret[j++]='&';
  1140.              ret[j++]='a';
  1141.              ret[j++]='m';
  1142.              ret[j++]='p';
  1143.              ret[j++]=';';
  1144.              break;
  1145.             case '\n':
  1146.              eol=1;
  1147.              if(j && ret[j-1]=='\n')
  1148.                {
  1149.                 ret[j-1]='<';
  1150.                 ret[j++]='b';
  1151.                 ret[j++]='r';
  1152.                 ret[j++]='>';
  1153.                }
  1154.              ret[j++]=c[i];
  1155.              break;
  1156.             default:
  1157.              if(eol)
  1158.                {
  1159.                 if(!strncmp(c+i,"+html+",6) || !strncmp(c+i,"-latex-",7))
  1160.                   {
  1161.                    do { i++; } while(c[i]!='-' && c[i]!='+'); i++;
  1162.                    copy=1;
  1163.                    break;
  1164.                   }
  1165.                 if(!strncmp(c+i,"-html-",6) || !strncmp(c+i,"+latex+",7) || !strncmp(c+i,"+none+",6))
  1166.                   {
  1167.                    do { i++; } while(c[i]!='-' && c[i]!='+'); i++;
  1168.                    skip=1;
  1169.                    break;
  1170.                   }
  1171.                 if(c[i]!=' ' && c[i]!='\t')
  1172.                    eol=0;
  1173.                }
  1174.              ret[j++]=c[i];
  1175.             }
  1176.  
  1177.        if(c[i])                 /* Not finished */
  1178.          {
  1179.           if(malloced[which])
  1180.              malloced[which]=Realloc(malloced[which],len+256+5);
  1181.           else
  1182.             {malloced[which]=Malloc(len+256+5); strncpy(malloced[which],ret,(unsigned)j);}
  1183.           ret=malloced[which];
  1184.           len+=256;
  1185.          }
  1186.        else
  1187.          {ret[j]=0; ret=NULL;}
  1188.       }
  1189.     while(ret);
  1190.  else
  1191.     safe[which][0]=0;
  1192.  
  1193.  return(malloced[which]?malloced[which]:safe[which]);
  1194. }
  1195.