home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / inter33c.zip / INT2QH.ZIP / INT2QH.C next >
C/C++ Source or Header  |  1990-11-11  |  4KB  |  237 lines

  1. /* INT2QH.C
  2.  *
  3.  * Author:   Kai Uwe Rommel
  4.  * Date:     Sun 07-Oct-1990
  5.  * Update:   Sat 20-Oct-1990
  6.  * Update:   Sun 11-Nov-1990  Ralf Brown
  7.  *
  8.  * Compiler: MS C 5.00 and newer / compact model, or TC 2.0 / compact model
  9.  * System:   PC/MS-DOS 3.20 and newer, OS/2 1.0 and newer
  10.  *
  11.  */
  12.  
  13. #define LABEL    "int2qh.c"
  14. #define VERSION  "1.2"
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20.  
  21. #define divider_line(s) (strncmp(s,"--------",8)==0)
  22.  
  23.  
  24. FILE *input, *output, *topics, *subtopics;
  25.  
  26. char line1[128];
  27. char line2[128];
  28. char category[128];
  29. char parent[128];
  30.  
  31. int sub;
  32.  
  33.  
  34. int _fputs(char *line, FILE *stream)
  35. {
  36.   char buffer[128];
  37.   int cnt = 0;
  38.  
  39.   while ( *line )
  40.   {
  41.     if ( *line == '\\' )
  42.       buffer[cnt++] = '\\';
  43.  
  44.     buffer[cnt++] = *line++;
  45.   }
  46.  
  47.   buffer[cnt] = 0;
  48.  
  49.   return fputs(buffer, stream);
  50. }
  51.  
  52.  
  53. void Initialize(void)
  54. {
  55.   input     = fopen("interrup.lst", "r");
  56.   output    = stdout;
  57.   topics    = fopen("topic.tmp", "w");
  58.   subtopics = fopen("subtopic.tmp", "w");
  59.  
  60.   fprintf(topics,
  61.     ".context List Categories\n.list\nInterrupt-List\n"
  62.     ".context Interrupt-List\n.context INTLIST\n.topic Interrupt-List\n.list\n"
  63.     );
  64. }
  65.  
  66.  
  67. void Cleanup(void)
  68. {
  69.   fclose(topics);
  70.   fclose(subtopics);
  71.  
  72.   topics = fopen("topic.tmp", "r");
  73.   subtopics = fopen("subtopic.tmp", "r");
  74.  
  75.   while ( fgets(line1, sizeof(line1), topics) )
  76.     fputs(line1, output);
  77.  
  78.   while ( fgets(line1, sizeof(line1), subtopics) )
  79.     fputs(line1, output);
  80.  
  81.   fcloseall();
  82.  
  83.   unlink("topic.tmp");
  84.   unlink("subtopic.tmp");
  85. }
  86.  
  87.  
  88. void CopyMemory(void)
  89. {
  90.   FILE *temp = fopen("memory.lst", "r");
  91.  
  92.   while ( fgets(line2, sizeof(line2), temp) )
  93.     _fputs(line2, output);
  94.  
  95.   fclose(temp);
  96. }
  97.  
  98.  
  99. void StartTopic(char *name, char *desc)
  100. {
  101.   fprintf(sub ? subtopics : topics, "%s  %s\n", name, desc);
  102.   fprintf(output, ".context %s\n.category %s\n.topic %s\n", name, parent, desc);
  103. }
  104.  
  105.  
  106. void StartList(char *name, char *desc)
  107. {
  108.   fprintf(topics, "%s  %s (list)\n", name, desc);
  109.   fprintf(subtopics, ".context %s\n.category %s\n.topic %s\n.list\n", name, parent, desc);
  110.  
  111.   strcpy(category, desc);
  112.   strcpy(parent, name);
  113.   sub = 1;
  114. }
  115.  
  116.  
  117. void EndList(void)
  118. {
  119.   strcpy(category, "Interrupt-List");
  120.   strcpy(parent, "INTLIST");
  121.   sub = 0;
  122. }
  123.  
  124.  
  125. char *NextID(void)
  126. {
  127.   static char ID[32];
  128.   static unsigned long CurrentID = 0;
  129.  
  130.   CurrentID++;
  131.   sprintf(ID, "IL%04ld", CurrentID);
  132.  
  133.   return ID;
  134. }
  135.  
  136.  
  137. int RecognizedTopic(void)
  138. {
  139.   char *ptr, topic[64], desc[128];
  140.  
  141.   if ( fgets(line2, sizeof(line2), input) == NULL )
  142.     return 0;
  143.  
  144.   if ( (ptr = strchr(line1, '-')) == NULL )
  145.     return 0;
  146.  
  147.   *--ptr = 0;
  148.   strcpy(topic, line1);
  149.   *ptr = ' ';
  150.  
  151.   if ( topic[strlen(topic) - 1] == 'h' )
  152.     topic[strlen(topic) - 1] = 0;
  153.  
  154.   if ( strcmp(category, topic) && sub )
  155.     EndList();
  156.  
  157.   strcpy(desc, line1);
  158.   desc[strlen(desc) - 1] = 0;
  159.  
  160.   for (ptr = line2 ; isspace(*ptr) ; ptr++)
  161.      ;
  162.  
  163.   if ( (!strncmp(ptr, "AX =", 4) ||
  164.     !strncmp(ptr, "AH =", 4) ||
  165.     !strncmp(ptr, "AL =", 4))
  166.        && !sub )
  167.     StartList(NextID(), topic);
  168.  
  169.   StartTopic(NextID(), desc);
  170.  
  171.   _fputs(line1, output);
  172.   if ( !divider_line(line2) )
  173.     _fputs(line2, output);
  174.  
  175.   return 1;
  176. }
  177.  
  178.  
  179. void CopyTopic(void)
  180. {
  181.   if ( divider_line(line2) )
  182.   { /* kludge for one-line interrupts */
  183.     fgets(line1, sizeof(line2), input);
  184.     return;
  185.   }
  186.  
  187.   for (;;)
  188.   {
  189.     if ( fgets(line1, sizeof(line1), input) == NULL )
  190.       break;
  191.  
  192.     if ( !divider_line(line1) )
  193.       _fputs(line1, output);
  194.     else
  195.     {
  196.       if ( fgets(line2, sizeof(line2), input) == NULL )
  197.     break;
  198.  
  199.       if ( strncmp(line2, "INT ", 4) )
  200.       {
  201.     _fputs(line1, output);
  202.     _fputs(line2, output);
  203.       }
  204.       else
  205.       {
  206.     strcpy(line1, line2);
  207.     break;
  208.       }
  209.     }
  210.   }
  211. }
  212.  
  213.  
  214. void main(void)
  215. {
  216.   fprintf(stderr, "\nINT2QH %s - (c) Kai Uwe Rommel - %s\n", VERSION, __DATE__);
  217.  
  218.   Initialize();
  219.   EndList();
  220.  
  221.   StartTopic("HEADER", "Overview of the Interrupt List");
  222.   CopyTopic();
  223.  
  224.   StartTopic("MEMLIST", "BIOS Memory List");
  225.   CopyMemory();
  226.  
  227.   while ( RecognizedTopic() )
  228.     CopyTopic();
  229.  
  230.   Cleanup();
  231.  
  232.   exit(0);
  233. }
  234.  
  235.  
  236. /* End of INT2QH.C */
  237.