home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / nuweb / nuwebsrc / Nuweb / src / html.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  14.8 KB  |  482 lines

  1.  
  2. #line 623 "nuweb.w"
  3. #include "global.h"
  4.  
  5. #line 1636 "nuweb.w"
  6. static void copy_scrap(FILE *file);     /* formats the body of a scrap */
  7. static void display_scrap_ref(FILE *html_file, int num);
  8.      /* formats a scrap reference */
  9. static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps);
  10.      /* formats a list of scrap numbers */
  11. static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps);
  12.      /* pluralizes scrap formats list */
  13. static void format_entry(Name *name, FILE *html_file, int file_flag);
  14.      /* formats an index entry */
  15. static void format_user_entry(Name *name, FILE *html_file);
  16.  
  17. #line 1654 "nuweb.w"
  18. void write_html(char *file_name, char *html_name)
  19. {
  20.   FILE *html_file = fopen(html_name, "w");
  21.   if (html_file) {
  22.     if (verbose_flag)
  23.       fprintf(stderr, "writing %s\n", html_name);
  24.     source_open(file_name);
  25.     
  26. #line 1677 "nuweb.w"
  27.     {
  28.       int scraps = 1;
  29.       int c = source_get();
  30.       while (c != EOF) {
  31.         if (c == '@')
  32.           
  33. #line 1693 "nuweb.w"
  34.           {
  35.             c = source_get();
  36.             switch (c) {
  37.               case 'O':
  38.               case 'o': 
  39. #line 1754 "nuweb.w"
  40.                         {
  41.                           Name *name = collect_file_name();
  42.                           
  43. #line 1804 "nuweb.w"
  44.                           {
  45.                             if (hw_flag) fputs("\\begin{rawhtml}\n", html_file);
  46.                             fputs("<pre>\n", html_file);
  47.                           }
  48.                           
  49. #line 1756 "nuweb.w"
  50.                         
  51.                           
  52. #line 1767 "nuweb.w"
  53.                             fputs("<a name=\"nuweb", html_file);
  54.                             write_single_scrap_ref(html_file, scraps);
  55.                             fprintf(html_file, "\"><code>\"%s\"</code> ", name->spelling);
  56.                             write_single_scrap_ref(html_file, scraps);
  57.                             fputs("</a> =\n", html_file);
  58.                           
  59. #line 1757 "nuweb.w"
  60.                         
  61.                           scraps++;
  62.                           
  63. #line 1814 "nuweb.w"
  64.                           {
  65.                             copy_scrap(html_file);
  66.                             fputs("<></pre>\n", html_file);
  67.                           }
  68.                           
  69. #line 1759 "nuweb.w"
  70.                         
  71.                           
  72. #line 1836 "nuweb.w"
  73.                           {
  74.                             if (name->defs->next) {
  75.                               fputs("File defined by ", html_file);
  76.                               print_scrap_numbers(html_file, name->defs);
  77.                               fputs("<br>\n", html_file);
  78.                             }
  79.                           }
  80.                           
  81. #line 1760 "nuweb.w"
  82.                         
  83.                           
  84. #line 1825 "nuweb.w"
  85.                           {
  86.                             if (hw_flag) fputs("\\end{rawhtml}\n", html_file);
  87.                             c = source_get(); /* Get rid of current at command. */
  88.                           }
  89.                           
  90. #line 1761 "nuweb.w"
  91.                         
  92.                         }
  93.                         
  94. #line 1697 "nuweb.w"
  95.           
  96.                         break;
  97.               case 'D':
  98.               case 'd': 
  99. #line 1776 "nuweb.w"
  100.                         {
  101.                           Name *name = collect_macro_name();
  102.                           
  103. #line 1804 "nuweb.w"
  104.                           {
  105.                             if (hw_flag) fputs("\\begin{rawhtml}\n", html_file);
  106.                             fputs("<pre>\n", html_file);
  107.                           }
  108.                           
  109. #line 1778 "nuweb.w"
  110.                         
  111.                           
  112. #line 1795 "nuweb.w"
  113.                             fputs("<a name=\"nuweb", html_file);
  114.                             write_single_scrap_ref(html_file, scraps);
  115.                             fprintf(html_file, "\"><%s ", name->spelling);
  116.                             write_single_scrap_ref(html_file, scraps);
  117.                             fputs("></a> =\n", html_file);
  118.                           
  119. #line 1779 "nuweb.w"
  120.                         
  121.                           scraps++;
  122.                           
  123. #line 1814 "nuweb.w"
  124.                           {
  125.                             copy_scrap(html_file);
  126.                             fputs("<></pre>\n", html_file);
  127.                           }
  128.                           
  129. #line 1781 "nuweb.w"
  130.                         
  131.                           
  132. #line 1847 "nuweb.w"
  133.                           {
  134.                             if (name->defs->next) {
  135.                               fputs("Macro defined by ", html_file);
  136.                               print_scrap_numbers(html_file, name->defs);
  137.                               fputs("<br>\n", html_file);
  138.                             }
  139.                           }
  140.                           
  141. #line 1782 "nuweb.w"
  142.                         
  143.                           
  144. #line 1858 "nuweb.w"
  145.                           {
  146.                             if (name->uses) {
  147.                               fputs("Macro referenced in ", html_file);
  148.                               print_scrap_numbers(html_file, name->uses);
  149.                             }
  150.                             else {
  151.                               fputs("Macro never referenced.\n", html_file);
  152.                               fprintf(stderr, "%s: <%s> never referenced.\n",
  153.                                       command_name, name->spelling);
  154.                             }
  155.                             fputs("<br>\n", html_file);
  156.                           }
  157.                           
  158. #line 1783 "nuweb.w"
  159.                         
  160.                           
  161. #line 1825 "nuweb.w"
  162.                           {
  163.                             if (hw_flag) fputs("\\end{rawhtml}\n", html_file);
  164.                             c = source_get(); /* Get rid of current at command. */
  165.                           }
  166.                           
  167. #line 1784 "nuweb.w"
  168.                         
  169.                         }
  170.                         
  171. #line 1700 "nuweb.w"
  172.           
  173.                         break;
  174.               case 'f': 
  175. #line 2000 "nuweb.w"
  176.                         {
  177.                           if (file_names) {
  178.                             if (hw_flag) fputs("\\begin{rawhtml}\n", html_file);
  179.                             fputs("<dl compact>\n", html_file);
  180.                             format_entry(file_names, html_file, TRUE);
  181.                             fputs("</dl>\n", html_file);
  182.                             if (hw_flag) fputs("\\end{rawhtml}\n", html_file);
  183.                           }
  184.                           c = source_get();
  185.                         }
  186.                         
  187. #line 1702 "nuweb.w"
  188.           
  189.                         break;
  190.               case 'm': 
  191. #line 2015 "nuweb.w"
  192.                         {
  193.                           if (macro_names) {
  194.                             if (hw_flag) fputs("\\begin{rawhtml}\n", html_file);
  195.                             fputs("<dl compact>\n", html_file);
  196.                             format_entry(macro_names, html_file, FALSE);
  197.                             fputs("</dl>\n", html_file);
  198.                             if (hw_flag) fputs("\\end{rawhtml}\n", html_file);
  199.                           }
  200.                           c = source_get();
  201.                         }
  202.                         
  203. #line 1704 "nuweb.w"
  204.           
  205.                         break;
  206.               case 'u': 
  207. #line 2094 "nuweb.w"
  208.                         {
  209.                           if (user_names) {
  210.                             if (hw_flag) fputs("\\begin{rawhtml}\n", html_file);
  211.                             fputs("<dl compact>\n", html_file);
  212.                             format_user_entry(user_names, html_file);
  213.                             fputs("</dl>\n", html_file);
  214.                             if (hw_flag) fputs("\\end{rawhtml}\n", html_file);
  215.                           }
  216.                           c = source_get();
  217.                         }
  218.                         
  219. #line 1706 "nuweb.w"
  220.           
  221.                         break;
  222.               case '@': putc(c, html_file);
  223.               default:  c = source_get();
  224.                         break;
  225.             }
  226.           }
  227.           
  228. #line 1682 "nuweb.w"
  229.     
  230.         else {
  231.           putc(c, html_file);
  232.           c = source_get();
  233.         }
  234.       }
  235.     }
  236.     
  237. #line 1661 "nuweb.w"
  238.  
  239.     fclose(html_file);
  240.   }
  241.   else
  242.     fprintf(stderr, "%s: can't open %s\n", command_name, html_name);
  243. }
  244.  
  245. #line 1874 "nuweb.w"
  246. static void display_scrap_ref(FILE *html_file, int num)
  247. {
  248.   fputs("<a href=\"#nuweb", html_file);
  249.   write_single_scrap_ref(html_file, num);
  250.   fputs("\">", html_file);
  251.   write_single_scrap_ref(html_file, num);
  252.   fputs("</a>", html_file);
  253. }
  254.  
  255. #line 1886 "nuweb.w"
  256. static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
  257. {
  258.   display_scrap_ref(html_file, scraps->scrap);
  259.   scraps = scraps->next;
  260.   while (scraps) {
  261.     fputs(", ", html_file);
  262.     display_scrap_ref(html_file, scraps->scrap);
  263.     scraps = scraps->next;
  264.   }
  265. }
  266.  
  267. #line 1900 "nuweb.w"
  268. static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
  269. {
  270.   fputs("scrap", html_file);
  271.   if (scraps->next) putc('s', html_file);
  272.   putc(' ', html_file);
  273.   display_scrap_numbers(html_file, scraps);
  274.   fputs(".\n", html_file);
  275. }
  276.  
  277. #line 1917 "nuweb.w"
  278. static void copy_scrap(FILE *file)
  279. {
  280.   int indent = 0;
  281.   int c = source_get();
  282.   while (1) {
  283.     switch (c) {
  284.       case '@':  
  285. #line 1950 "nuweb.w"
  286.                  {
  287.                    c = source_get();
  288.                    switch (c) {
  289.                      case '@': putc(c, file);
  290.                                break;
  291.                      case '|': 
  292. #line 1412 "nuweb.w"
  293.                                {
  294.                                  do {
  295.                                    do
  296.                                      c = source_get();
  297.                                    while (c != '@');
  298.                                    c = source_get();
  299.                                  } while (c != '}');
  300.                                }
  301.                                
  302. #line 1955 "nuweb.w"
  303.                  
  304.                      case '}': return;
  305.                      case '<': 
  306. #line 1970 "nuweb.w"
  307.                                {
  308.                                  Name *name = collect_scrap_name();
  309.                                  fprintf(file, "<%s ", name->spelling);
  310.                                  if (name->defs)
  311.                                    
  312. #line 1987 "nuweb.w"
  313.                                    {
  314.                                      Scrap_Node *p = name->defs;
  315.                                      display_scrap_ref(file, p->scrap);
  316.                                      if (p->next)
  317.                                        fputs(", ... ", file);
  318.                                    }
  319.                                    
  320. #line 1974 "nuweb.w"
  321.                                
  322.                                  else {
  323.                                    putc('?', file);
  324.                                    fprintf(stderr, "%s: scrap never defined <%s>\n",
  325.                                            command_name, name->spelling);
  326.                                  }
  327.                                  fputs(">", file);
  328.                                }
  329.                                
  330. #line 1957 "nuweb.w"
  331.                  
  332.                                break;
  333.                      default:  /* ignore these since pass1 will have warned about them */
  334.                                break;
  335.                    }
  336.                  }
  337.                  
  338. #line 1923 "nuweb.w"
  339.  
  340.                  break;
  341.       case '<' : fputs("<", file);
  342.                  indent++;
  343.                  break;
  344.       case '>' : fputs(">", file);
  345.                  indent++;
  346.                  break;
  347.       case '&' : fputs("&", file);
  348.                  indent++;
  349.                  break;
  350.       case '\n': putc(c, file);
  351.                  indent = 0;
  352.                  break;
  353.       case '\t': 
  354. #line 1382 "nuweb.w"
  355.                  {
  356.                    int delta = 8 - (indent % 8);
  357.                    indent += delta;
  358.                    while (delta > 0) {
  359.                      putc(' ', file);
  360.                      delta--;
  361.                    }
  362.                  }
  363.                  
  364. #line 1937 "nuweb.w"
  365.  
  366.                  break;
  367.       default:   putc(c, file);
  368.                  indent++;
  369.                  break;
  370.     }
  371.     c = source_get();
  372.   }
  373. }
  374.  
  375. #line 2030 "nuweb.w"
  376. static void format_entry(Name *name, FILE *html_file, int file_flag)
  377. {
  378.   while (name) {
  379.     format_entry(name->llink, html_file, file_flag);
  380.     
  381. #line 2043 "nuweb.w"
  382.     {
  383.       fputs("<dt> ", html_file);
  384.       if (file_flag) {
  385.         fprintf(html_file, "<code>\"%s\"</code>\n<dd> ", name->spelling);
  386.         
  387. #line 2062 "nuweb.w"
  388.         {
  389.           fputs("Defined by ", html_file);
  390.           print_scrap_numbers(html_file, name->defs);
  391.         }
  392.         
  393. #line 2047 "nuweb.w"
  394.     
  395.       }
  396.       else {
  397.         fprintf(html_file, "<%s ", name->spelling);
  398.         
  399. #line 2070 "nuweb.w"
  400.         {
  401.           if (name->defs)
  402.             display_scrap_numbers(html_file, name->defs);
  403.           else
  404.             putc('?', html_file);
  405.         }
  406.         
  407. #line 2051 "nuweb.w"
  408.     
  409.         fputs(">\n<dd> ", html_file);
  410.         
  411. #line 2080 "nuweb.w"
  412.         {
  413.           Scrap_Node *p = name->uses;
  414.           if (p) {
  415.             fputs("Referenced in ", html_file);
  416.             print_scrap_numbers(html_file, p);
  417.           }
  418.           else
  419.             fputs("Not referenced.\n", html_file);
  420.         }
  421.         
  422. #line 2053 "nuweb.w"
  423.     
  424.       }
  425.       putc('\n', html_file);
  426.     }
  427.     
  428. #line 2034 "nuweb.w"
  429.  
  430.     name = name->rlink;
  431.   }
  432. }
  433.  
  434. #line 2109 "nuweb.w"
  435. static void format_user_entry(Name *name, FILE *html_file)
  436. {
  437.   while (name) {
  438.     format_user_entry(name->llink, html_file);
  439.     
  440. #line 2122 "nuweb.w"
  441.     {
  442.       Scrap_Node *uses = name->uses;
  443.       if (uses) {
  444.         Scrap_Node *defs = name->defs;
  445.         fprintf(html_file, "<dt><code>%s</code>:\n<dd> ", name->spelling);
  446.         if (uses->scrap < defs->scrap) {
  447.           display_scrap_ref(html_file, uses->scrap);
  448.           uses = uses->next;
  449.         }
  450.         else {
  451.           if (defs->scrap == uses->scrap)
  452.             uses = uses->next;
  453.           fputs("<strong>", html_file);
  454.           display_scrap_ref(html_file, defs->scrap);
  455.           fputs("</strong>", html_file);
  456.           defs = defs->next;
  457.         }
  458.         while (uses || defs) {
  459.           fputs(", ", html_file);
  460.           if (uses && (!defs || uses->scrap < defs->scrap)) {
  461.             display_scrap_ref(html_file, uses->scrap);
  462.             uses = uses->next;
  463.           }
  464.           else {
  465.             if (uses && defs->scrap == uses->scrap)
  466.               uses = uses->next;
  467.             fputs("<strong>", html_file);
  468.             display_scrap_ref(html_file, defs->scrap);
  469.             fputs("</strong>", html_file);
  470.             defs = defs->next;
  471.           }
  472.         }
  473.         fputs(".\n", html_file);
  474.       }
  475.     }
  476.     
  477. #line 2113 "nuweb.w"
  478.  
  479.     name = name->rlink;
  480.   }
  481. }
  482.