home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / doc / intlist / int2guid / int2guid.c < prev    next >
C/C++ Source or Header  |  1992-12-19  |  22KB  |  718 lines

  1. /* INT2GUID.C
  2.  *
  3.  * from:
  4.  * INT2QH.C
  5.  *
  6.  * Author:   Kai Uwe Rommel
  7.  * Date:     Sun 07-Oct-1990
  8.  * Update:   Sat 20-Oct-1990
  9.  * Update:   Sun 11-Nov-1990  Ralf Brown
  10.  *
  11.  * Compiler: MS C 5.00 and newer / compact model, or TC 2.0 / compact model
  12.  * System:   PC/MS-DOS 3.20 and newer, OS/2 1.0 and newer
  13.  *
  14.  *
  15.  * INT2GUID.C is a GUIDE/MAKEHELP version of INT2QH.C. GUIDE and MAKEHELP
  16.  * are programs for pop-up help included the TurboPower Software package
  17.  * Turbo Professional.
  18.  *
  19.  * Transscriptor:    Bent Lynggaard
  20.  * Date:    1.00    Sun 24-Mar-1991
  21.  * Update:    1.01    Tue 02-Apr-1991    - test '!', ';' in line pos 1.
  22.  *                    - test disk full
  23.  *        1.02    Sun 14-Apr-1991    - smaller index pages
  24.  *                    - main index always leads to start of
  25.  *                      an INT #
  26.  *        1.03    Sun 12-May-1991    - configuration file.
  27.  *        1.04    Sat 18-May-1991 - conditional mask in *.cfg
  28.  *        1.05    Sun 29-Dec-1991 - fixed \n bug in configure()
  29.  *        1.06    Sun 09-May-1992 - adjusted for change in file format
  30.  *                    - "dividerline" info as headings
  31.  *                    - all registers can carry parameters
  32.  *        1.07    Sat 19-Dec-1992 - fixed bug (reading from closed file)
  33.  *                    - "dividerline" info as topics
  34.  *                    - "dividerline" char 9 function info
  35.  *                    - new subtopic criteria
  36.  *                    - program initialization in
  37.  *                        configuration file
  38.  *                    - splitting up long topics
  39.  *
  40.  * This program creates output to the standard output device. The output
  41.  * should be redirected to a file INTERRUP.TXT. The created file should
  42.  * be compiled by the TurboPower MAKEHELP program to a INTERRUP.HLP file,
  43.  * which can be interpreted by the TurboPower GUIDE TSR program:
  44.  *    INT2GUID > [ramdisk:]INTERRUP.TXT
  45.  *    MAKEHELP [ramdisk:INTERRUPT] INTERRUP[.HLP] /Q
  46.  *    GUIDE INTERRUP    (or enter GUIDE with a hot key, press F3,
  47.  *            enter INTERRUP)
  48.  *
  49.  * TurboPower Software supplies a program called POPHELP in their Object
  50.  * Professional package, which is a successor to GUIDE. INT2GUID has
  51.  * facilities for conditional interpretation of supplementary files, so
  52.  * these files can include code optimized for both GUIDE and POPHELP, and
  53.  * the parts compiled depends on a mask defined in the configuration file.
  54.  *
  55.  * The following is considered in creating the topic (and popup window)
  56.  * headers:
  57.  * The first word in the header is the interrupt number, so that GUIDE's
  58.  * search mechanism can find the entry if the hot key is pressed when
  59.  * the cursor is at an interrupt number.
  60.  * MAKEHELP restricts the (length of longest header + 1) times the number
  61.  * of topics to 64 kB. INTER191 had about 2200 topics, so the length of
  62.  * the headers should be limited to 25 characters. However, rather than
  63.  * truncating the INTERRUP.LST header lines to some nonsense, this
  64.  * program uses only the interrupt number as topic headings, plus the
  65.  * AH or AX values where applicable.
  66.  * (v. 1.06: "divider line" info (e.g. "214C" in "--------214C------...")
  67.  * is used for headings, thus allowing a more selective search by GUIDE's
  68.  * cursor-word search.)
  69.  * The main index references some subindeces. The subindeces use the
  70.  * MAKEHELP cross reference facility. MAKEHELP limits the number of cross
  71.  * references to 50 per topic, however, this program limits each subindex
  72.  * to 18 entries, so each "topic" can be shown on one single screen with
  73.  * height 20 lines. For each interrupt number, the entries are temporarily
  74.  * stored, and written to the current subindex page only if all entries
  75.  * for the interrupt number fit on the page.
  76.  *
  77.  * MAKEHELP's text wrapping mechanism is disabled, and as the active
  78.  * window is limited to 76 characters, some lines are missing one or two
  79.  * characters.
  80.  * The amount of text that can be displayed per topic is limited by
  81.  * GUIDE's setting of pages/topic (default = 20) and the screen height
  82.  * defined when GUIDE was initialized.
  83.  *
  84.  */
  85.  
  86. #define LABEL    "int2guid.c"
  87. #define VERSION  "1.07"
  88.  
  89. #include <stdio.h>
  90. #include <stdlib.h>
  91. #include <string.h>
  92. #include <ctype.h>
  93.  
  94. #define divider_line(s) (strncmp(s,"--------",8)==0)
  95. #define maxIndeces 18
  96.   /* max 50, 18 gives one page with height 20 (18 active lines) */
  97. #define mainIndex 200
  98.   /* 1-99 reserved for program, 100-199 reserved for user */
  99. #define false 0
  100. #define true 1
  101.  
  102. FILE *input, *output, *topics, *subtopics, *config;
  103.  
  104. char line1[128];
  105. char line2[128];
  106. char configline[128];
  107. char tempBuffer[50 * 128];
  108. char *tempPtr;
  109. char category[4] = "--";
  110. char nextHeader[16] = "??"; /* v. 1.07: 16 rather than 14 */
  111. char infilename[14] = "interrup.lst";
  112. #define infileExt 9
  113. int splitInfile = 0;
  114. int classification = 0;
  115. int WIDTH = 80;
  116.   /* WIDTH is the screen with for GUIDE/POPHELP. 80 is the best choice for
  117.      GUIDE, 78 is the best choice for POPHELP (which does not count the
  118.      frame as a part of the screen). The configuration file can change
  119.      this value. v. 1.07.
  120.   */
  121. long topicStart = 0; /* v. 1.07 */
  122. unsigned maxTopicLength = 32000; /* v. 1.07 */
  123.   /* texts longer than maxTopicLength are split into two or more topics.
  124.      The configuration file can change this value.
  125.   */
  126. char currentHeader[16]; /* v. 1.07 */
  127.  
  128. char configfile[14] = "int2guid.cfg";
  129. char configmarker[18] = "INT2GUIDE CONFIG";
  130.  
  131. char missingFile[] = "Missing include file.";
  132.  
  133. int sub = 0, indexed = 1;
  134. unsigned currentID = 1, activeID = 1, indeces = 0, indexNo = 0, buffered = 0,
  135.   subindeces, activeSub, mask;
  136. int headerlength; /* v. 1.07 */
  137. unsigned reservedID = mainIndex; /* v. 1.07 */
  138.   /* reservedID reserves some topic numbers for long texts that are split
  139.      into more than one topic. currentID must then be incremented via a
  140.      function call in order to skip the reserved topics.
  141.   */
  142.  
  143. void exitfunc(void)
  144. {
  145.   fcloseall();
  146.   unlink("topic.tmp");
  147.   unlink("subtopic.tmp");
  148. }
  149.  
  150. void errorexit(char *msg)
  151. /* writes msg to stderr and exits with error code 1 */
  152. {
  153.   fputs(msg, stderr);
  154.   exit(1);
  155. } /* errorexit */
  156.  
  157. void diskFull(int temporary)
  158. /* reports disk full and exits */
  159. {
  160.   char msg[80];
  161.   sprintf(msg,"\n\nDisk full, %s file\n", temporary ? "temporary" : "output");
  162.   errorexit(msg);
  163. } /* diskFull */
  164.  
  165.  
  166. int _fputs(char *line, FILE *stream)
  167. /* filters TABs to spaces, and inserts a leading space in lines starting
  168.    with the MAKEHELP command and comment characters '!' and ';'. "_fputs"
  169.    should be used when copying from unknown sources. Use "fputs" when
  170.    copying files with information specifically for this program.
  171. */
  172. {
  173.   char buffer[128];
  174.   int cnt = 0;
  175.  
  176.   if ( (*line=='!') || (*line==';') ) /* MAKEHELP command/comment? */
  177.     buffer[cnt++] = ' '; /* start with a space */
  178.  
  179.   while ( *line )
  180.   {
  181.     switch ( *line )
  182.     {
  183.       case '\t': do buffer[cnt++] = ' '; while ( cnt & 7 ); break;
  184.             /* MAKEHELP does not interpret tabs */
  185.       default  : buffer[cnt++] = *line;
  186.     }
  187.     line++;
  188.   }
  189.  
  190.   buffer[cnt] = 0;
  191.  
  192.   if ( (cnt = fputs(buffer, stream)) == EOF )
  193.     diskFull(stream != output);
  194.  
  195.   return cnt;
  196. }
  197.  
  198. char *_fgets(char *s, int n, FILE *stream)
  199. {
  200.   char *ptr;
  201.   ptr = fgets(s, n, stream);
  202.   if ( (ptr==NULL) && (stream==input) && splitInfile )
  203.   {
  204.     fclose(input);
  205.     infilename[infileExt]++;
  206.     input = fopen(infilename, "r");
  207.     if ( input != NULL )
  208.     {
  209.       fprintf(stderr, "%s\n", infilename);
  210.       ptr = fgets(s, n, input);
  211.     }
  212.   }
  213.   return ptr;
  214. } /* _fgets */
  215.  
  216. void Initialize(void)
  217. {
  218.   input     = fopen(infilename, "r");
  219.   if ( input == NULL )
  220.   {
  221.     infilename[infileExt] = 'a';
  222.     infilename[infileExt+1] = 0;
  223.     input = fopen(infilename, "r");
  224.     if ( input == NULL )
  225.     {
  226.       fputs("Cannot open input file (INTERRUP.LST or INTERRUP.A)\n", stderr);
  227.       exit(1);
  228.     }
  229.     splitInfile = 1;
  230.   }
  231.   fprintf(stderr, "%s\n", infilename);
  232.   output    = stdout;
  233.   topics    = fopen("topic.tmp", "w");
  234.   subtopics = fopen("subtopic.tmp", "w");
  235.  
  236.   tempPtr = tempBuffer;
  237.  
  238.   fprintf(output,
  239.     ";INTERRUPT help text for MAKEHELP/GUIDE.\n;\n!WIDTH %u\n;\n",WIDTH);
  240.     /* v. 1.07: WIDTH  rather than constant 80. WIDTH is initialized to 80
  241.        and can be changed in the configuration file.
  242.     */
  243.   fprintf(topics, "!TOPIC 1 Interrupt List\n!INDEX %u\n", mainIndex);
  244. }
  245.  
  246. int incrementID(void)
  247. /* v. 1.07: introduced in order to skip reserved IDs when incrementing currentID */
  248. {
  249.   ++currentID;
  250.   if (currentID == mainIndex)
  251.     currentID = reservedID;
  252.   return currentID;
  253. } /* incrementID */
  254.  
  255. void testTopic(void) /* limit xrefs/topic to maxIndeces */
  256. {
  257.   if ( indeces+buffered >= maxIndeces ) /* leave one entry for forw. ref */
  258.   {
  259.     incrementID();
  260.     fprintf(topics, "\004%u\005INT %s\005 (index continued)\n"
  261.       "!TOPIC %u INT %s (cont)\n!INDEX %u\n"
  262.       "(continued \004%u\005from\005)\n",
  263.       currentID, category, currentID, category, ++indexNo, activeID);
  264.     indeces = 1; /* the backwards ref */
  265.     activeID = currentID;
  266.   }
  267. } /* testTopic */
  268.  
  269. void copyBuffer(void)
  270. {
  271.   if ( buffered == 0 )
  272.     return;
  273.  
  274.   testTopic();
  275.   if ( fputs(tempBuffer, topics) == EOF )
  276.       diskFull(true);
  277.   indeces += buffered;
  278.   buffered = 0;
  279.   tempPtr = tempBuffer;
  280. } /* copyBuffer */
  281.  
  282. void Cleanup(void)
  283. {
  284.   copyBuffer();
  285.   fclose(topics);
  286.   fclose(subtopics);
  287.   fputs("Cleaning up\n", stderr);
  288.  
  289.   topics = fopen("topic.tmp", "r");
  290.   subtopics = fopen("subtopic.tmp", "r");
  291.  
  292.   while ( fgets(line1, sizeof(line1), topics) )
  293.     if ( fputs(line1, output) == EOF )
  294.       diskFull(false);
  295.  
  296.   while ( fgets(line1, sizeof(line1), subtopics) )
  297.     if ( fputs(line1, output) == EOF )
  298.       diskFull(false);
  299. } /* Cleanup */
  300.  
  301. void putAndCount(int putFunc(), char *line)
  302. /* split topic if maxTopicLength is exceeded. v. 1.07 */
  303. {
  304.   int ID, rID;
  305.   if ((ftell(output) - topicStart) > maxTopicLength)
  306.   {
  307.     ID = currentID;
  308.     rID = (reservedID > currentID) ? reservedID++ : ++currentID;
  309.     if (fprintf(output,"\004%u\005(text continues)\005\n"
  310.       "!TOPIC %u %s\n!NOINDEX\n"
  311.       "\004%u\005(text continued from)\005\n",
  312.       rID, rID, currentHeader, ID) == EOF)
  313.     diskFull(false);
  314.     topicStart = ftell(output);
  315.   }
  316.   if (putFunc(line, output) == EOF)
  317.     diskFull(false);
  318. } /* putAndCount */
  319.  
  320. int CopyFile(char *name, int commands)
  321. /* copies a file to the database, returns 0 for success or 1 for error */
  322.  
  323. /* If commands!=0, also interprets lines starting with "!! <number>" as
  324.    an update to variable "condition", and copies lines to the database
  325.    only if condition == 0 or (condition & mask) != 0
  326. */
  327. {
  328.   int condition = 0;
  329.   FILE *temp = fopen(name, "r");
  330.   char s[128];
  331.   fprintf(stderr, "%s\n", name);
  332.   if ( temp == NULL )
  333.   {
  334.     fprintf(stderr, "WARNING: Could not open %s\n", name);
  335.     fputs("Information was not available\n", output);
  336.     return 1;
  337.   }
  338.   else
  339.   {
  340.     while ( fgets(line2, sizeof(line2), temp) )
  341.       if ( !commands )
  342.     putAndCount(_fputs, line2);
  343.       else
  344.     /* does line start with "!! <number>" ? */
  345.     if ( sscanf(line2, "!!%i", &condition) != 1 )
  346.       /* yes: condition updated, sscanf returns 1 */
  347.       if ( (condition==0) || (condition & mask) )
  348.       {
  349.         if (sscanf(line2, "!%s", s) == 1)
  350.           if (strcmp(strupr(s), "TOPIC") == 0)
  351.             topicStart = ftell(output);
  352.         putAndCount(fputs, line2);
  353.       }
  354.     fputs("!NOWRAP\n", output); /* in case it was left in !WRAP state */
  355.     fclose(temp);
  356.     return 0;
  357.   }
  358. } /* CopyFile */
  359.  
  360. void testTemp(void)
  361. /* v. 1.06: allow no more than 50 entries in tempBuffer */
  362. /* v. 1.07: allow no more than 48 entries in tempBuffer */
  363. {
  364.   if (buffered >= 48)
  365.   {
  366.     copyBuffer();
  367.     fprintf(stderr,"INT %s has more than 48 subtopics and therefore more than one entry\n"
  368.       "in the main index (topic %u).\n", category, currentID);
  369.   }
  370. } /* testTemp */
  371.  
  372. void testSubtopic(char *marker)
  373. {
  374.   if ( ++subindeces >= maxIndeces )
  375.   {
  376.     testTemp();
  377.     sprintf(tempPtr, "\004%u\005%s\005  (list cont.)\n",
  378.       incrementID(), marker);
  379.     tempPtr += strlen(tempPtr);
  380.     buffered++;
  381.     fprintf(subtopics,
  382.       "\004%u\005%s\005  (list cont.)\n!TOPIC %u %s (list cont)\n!NOINDEX\n"
  383.       "(continued \004%u\005from\005)\n",
  384.       currentID, marker, currentID, category, activeSub);
  385.       activeSub = currentID;
  386.     subindeces = 2;
  387.   }
  388. } /* testSubtopic */
  389.  
  390.  
  391. void StartTopic(char *header, char *marker, char *desc)
  392. {
  393.   topicStart = ftell(output); /* v. 1.07 */
  394.   strncpy(currentHeader, header, sizeof(currentHeader));
  395.   currentHeader[sizeof(currentHeader)-1] = 0;
  396.   if (sub)
  397.   {
  398.     testSubtopic(marker);
  399.     if ( fprintf(subtopics, "\004%u\005%s\005  %s",
  400.       incrementID(), marker, desc) == EOF )
  401.     diskFull(true);
  402.     if (fprintf(output, "\004%u\005INT %s\005 (continued)\n",
  403.       currentID, category) == EOF)
  404.         diskFull(false);
  405.     /* insert a reference to this one in the former topic */
  406.   } /* if (sub) */
  407.   else
  408.   {
  409.     testTemp();
  410.     sprintf(tempPtr, "\004%u\005%s\005  %s", incrementID(), marker, desc);
  411.     tempPtr += strlen(tempPtr);
  412.     buffered++;
  413.   } /* else */
  414.  
  415.   fprintf(output, "!TOPIC %u %s\n", currentID, header);
  416.   if ( indexed )
  417.     indexNo++;
  418.   fprintf(output, indexed ? "!INDEX %u\n" : "!NOINDEX\n", indexNo);
  419. } /* StartTopic */
  420.  
  421. void StartList(void)
  422. /* v. 1.07: reorganized and edited */
  423. {
  424.   fprintf(subtopics, "!TOPIC %u %s (list)\n!NOINDEX\n", incrementID(), category);
  425.   if (fputs(tempBuffer, subtopics) == NULL)
  426.     diskFull(true); /* copy one entry in buffer to subtopics */
  427.   sub = 1;
  428.   subindeces = 1;
  429.   activeSub = currentID;
  430.   tempPtr = tempBuffer; /* reset buffer pointer */
  431.   buffered = 1; /* the entry we are going to use now */
  432.   sprintf(tempPtr, "\004%u\005%s\005  (list)\n", currentID, category);
  433.   tempPtr += strlen(tempPtr);
  434. } /* StartList */
  435.  
  436. /* void EndList(void) - not used */
  437.  
  438. /* char *NextID(void) - not used */
  439.  
  440. int RecognizedTopic(void)
  441. {
  442. /* v. 1.07: revised to use newheader info for marker string rather than
  443.    interpreting lines 1 and 2, and to use subtopics when there is more
  444.    than one entry rather than when there are entries with parameters.
  445. */
  446.   char *ptr, *pdesc, topic[4], marker[20];
  447.  
  448.   if (input == NULL)
  449.     return 0; /* v. 1.07: check input == NULL rather than read second line */
  450.  
  451.   if ( (pdesc = strchr(line1, '-')) == NULL )
  452.     pdesc = "(description not found)";
  453.  
  454.   if (headerlength==0) /* if info was missing in the dividerline */
  455.   { /* take INT # from line1[4]-[5] */
  456.     strncpy(nextHeader, &line1[4], 2);
  457.     nextHeader[2] = '\0';
  458.     fprintf(stderr,"Missing divider line info in:\n%s", line1);
  459.   }
  460.   strncpy(topic, nextHeader, 2); /* interrupt number */
  461.   topic[2] = '\0';
  462.  
  463.   if ( strcmp(category, topic) )
  464.   {
  465.     sub = 0;
  466.     copyBuffer();
  467.     strcpy(category, topic);
  468.     fprintf(stderr, "%s\015", topic); /* show progress */
  469.   }
  470.   else
  471.   {
  472.     if (sub==0) /* v. 1.07 */
  473.       StartList();
  474.     /* v. 1.07: insert reference was moved to StartTopic */
  475.   }
  476.  
  477.   strcpy(marker, nextHeader); /* v. 1.07: use nextHeader for marker */
  478.   /* nextheader format: IIAHALXXNNNN_F (_F only if headerlength<0 */
  479.   /* marker format: II AHAL XXNNNN F */
  480.   if (headerlength < 0)
  481.   {
  482.     headerlength = abs(headerlength);
  483.     marker[headerlength-2] = ' '; /* '_' to space */
  484.   }
  485.  
  486.   if (headerlength > 2)
  487.   {
  488.     for (ptr = marker+headerlength+1; ptr >= &marker[2]; ptr--)
  489.       ptr[1] = *ptr;
  490.     /* memcpy(&marker[3], &marker[2], headerlength - 1);
  491.        did not work properly (compiler direction handling error)
  492.     */
  493.     marker[2] = ' ';
  494.     if (headerlength > 6+2)
  495.     {
  496.       for (ptr = marker+headerlength+2; ptr >= &marker[7]; ptr--)
  497.     ptr[1] = *ptr;
  498.       /* memcpy(&marker[8], &marker[7], headerlength - 5);
  499.         again. compiler error
  500.       */
  501.       marker[7] = ' ';
  502.       ptr = &marker[6];
  503.       while (*ptr == '_')
  504.     *ptr-- = ' '; /* spaces for AL or AX if unused */
  505.     } /* if (headerlength > 6+2) */
  506.   } /* if (headerlength > 2) *
  507.  
  508. /* v. 1.06: use global "nextHeader" rather than local "header" */
  509. /* v. 1.07: local "header" deleted */
  510.   StartTopic(nextHeader, marker, pdesc);
  511.  
  512.   _fputs(line1, output);
  513.  
  514.   return 1;
  515. } /* RecognizedTopic */
  516.  
  517. void CopyTopic(void)
  518. {
  519. /* v. 1.07: edited to split long texts into two or more topics */
  520.   char *ptr, *ptr2;
  521.  
  522.   for (;;)
  523.   {
  524.     if ( _fgets(line1, sizeof(line1), input) == NULL )
  525.       break;
  526.  
  527.     if ( !divider_line(line1) )
  528.       putAndCount(_fputs, line1);
  529.     else
  530.     {
  531.       if ( _fgets(line2, sizeof(line2), input) == NULL )
  532.     break;
  533.  
  534.       if ( strncmp(line2, "INT ", 4) )
  535.       {
  536.     putAndCount(_fputs, line1);
  537.     putAndCount(_fputs, line2);
  538.       }
  539.       else
  540.       {
  541.     /* v. 1.06: store divider line info as a header */
  542.     /* v. 1.07: edited */
  543.     strncpy(nextHeader, line1+10, 12);
  544.     for (ptr=nextHeader+11; *ptr=='-'; ptr--)
  545.       ;
  546.     if (ptr>&nextHeader[4])
  547.       for (ptr2=&nextHeader[2]; ptr2<ptr && ptr2<&nextHeader[6]; ptr2++)
  548.         if (*ptr2 == '-')
  549.           *ptr2 = '_';
  550.     headerlength = ptr - nextHeader + 1;
  551.     if (classification && line1[8]!='-')
  552.     {
  553.       *++ptr='_'; /* add char. 9 function classification */
  554.       *++ptr=line1[8];
  555.       headerlength = -headerlength-2;
  556.     }
  557.     *++ptr=0;
  558.     strcpy(line1, line2);
  559.     break;
  560.       } /* else */
  561.     } /* else */
  562.   } /* for (;;) */
  563. } /* CopyTopic */
  564.  
  565. void configError(void)
  566. {
  567.   errorexit("\nFormat error in configuration file.\n");
  568. } /* configError */
  569.  
  570. void readconfig(void)
  571. /* reads one line from file config to configline */
  572. {
  573.   if ( fgets(configline, sizeof(configline), config) == NULL )
  574.     configError();
  575. } /* readconfig */
  576.  
  577. void openconfig(void)
  578. /* opens configuration file and reads the initial part up to a line starting
  579.    with "=". This code defines how the initial lines are interpreted.
  580.    v. 1.07 defines:
  581.    configline[0] == '=': end of initial part
  582.    configline[0] == ';': comment
  583.    configline[0] == 'W': assign value to WIDTH
  584.    configline[0] == 'M': assign value to maxTopicLength
  585.    configline[0] == 'C': assign true to classification
  586.    The definitions are case sensitive.
  587. */
  588. {
  589.   int confv, confsubv;
  590.   char dummy[128];
  591.   config = fopen(configfile, "r");
  592.   if ( config == NULL )
  593.   {
  594.     fputs("\nWarning: No configuration file.\n", stderr);
  595.     return;
  596.   }
  597.   readconfig();
  598.   if (strncmp(configline, configmarker, strlen(configmarker)))
  599.     configError();
  600.   readconfig();
  601.   if (sscanf(configline, "%u%u", &confv, &confsubv) < 2)
  602.     configError();
  603.   if ((confv = ((confv << 8) + confsubv)) < 0x104)
  604.     errorexit ("\nThe configuration file is incompatible with this"
  605.     " version of INT2GUID");
  606.   if (confv < 0x107)
  607.     return;
  608.   while (!feof(config))
  609.   {
  610.     readconfig();
  611.     switch (configline[0])
  612.     {
  613.       case '=': return; /* done */
  614.       case ';': break; /* comment */
  615.       case 'W':
  616.       case 'M':
  617.     if ( sscanf(configline, "%s%u", &dummy,
  618.       configline[0]=='W' ? &WIDTH : &maxTopicLength) < 2 )
  619.       configError();
  620.     break;
  621.       case 'C': classification = true; break; /* include classification */
  622.       default: fprintf(stderr, "\nWARNING: Error in configuration file:\n%s",
  623.     configline);
  624.     } /* switch */
  625.   } /* while */
  626. } /* openconfig */
  627.  
  628. void copyline(char *str, int len)
  629. /* copies configline (after deleting the terminating '\n') to str
  630.     for max len characters. */
  631. {
  632.   configline[strlen(configline)-1] = 0; /* ignore '\n' */
  633.   strncpy(str, configline, len);
  634.   str[len] = 0; /* edited: v. 1.05 */
  635. } /* copyline */
  636.  
  637. void configure(void)
  638. /* parses configuration file */
  639. {
  640. #define maxHeader 14
  641. #define markerLen 12
  642.   int command, extraTopics, i;
  643.   char header[(maxHeader+2) & 0xFE], marker[(markerLen+2) & 0xFE],
  644.     desc[(76-markerLen) & 0xFE], filename[80];
  645.   /* v. 1.07: initial part moved to openconfig() */
  646.   while ( !feof(config) )
  647.   {
  648.     while ( (fgets(configline, sizeof(configline), config) != NULL)
  649.       && (configline[0] == ';') ) ;
  650.     if feof(config) break;
  651.     copyline(filename, 79);
  652.     readconfig();
  653.     copyline(header, maxHeader);
  654.     readconfig();
  655.     copyline(marker, markerLen);
  656.     i = strlen(marker);
  657.     while ( i<markerLen-1 ) /* pad with spaces if short */
  658.       marker[i++] = ' '; /* is already 0-terminated at markerLen */
  659.     readconfig();
  660.     copyline(desc, 76-markerLen-2);
  661.     i = strlen(desc); /* edited: v. 1.05 */
  662.     desc[i] = '\n';
  663.     desc[++i] = 0;
  664.     readconfig();
  665.     if ( sscanf(configline, "%u%u%i", &command, &extraTopics, &mask) < 3 )
  666.       configError();
  667.  
  668.     StartTopic(header, marker, desc);
  669.     CopyFile(filename, command);
  670.     currentID += extraTopics;
  671.   }
  672.   fclose(config);
  673. #undef maxHeader
  674. #undef markerLen
  675. } /* configure */
  676.  
  677. void main(void)
  678. {
  679.   fprintf(stderr, "\nINT2GUID %s - (c) Kai Uwe Rommel/Bent Lynggaard - %s\n",
  680.     VERSION, __DATE__);
  681.   atexit(exitfunc);
  682.  
  683.   openconfig();
  684.  
  685.   Initialize(); /* uses topic 1 */
  686.  
  687.   fputs("Including:\n",stderr);
  688.   StartTopic("Copyright etc.", "Copyright  ", "and references.\n");
  689.   if ( CopyFile("int2guid.ref", true) ) /* topic 2 */
  690.     errorexit(missingFile);
  691.  
  692.   StartTopic("INTERRUP.LST", "HEADER     ", "Overview of the Interrupt List\n");
  693.   fputs("(See also \4""4\5INTERRUP.1ST\5)\n", output); /* insert reference */
  694.   CopyTopic(); /* topic 3 */
  695.  
  696.   StartTopic("INTERRUP.1ST", "Mail etc.  ", "How to get/update INTERRUP.LST\n");
  697.   if ( CopyFile("interrup.1st", false) ) /* topic 4 */
  698.     errorexit(missingFile);
  699.  
  700.   StartTopic("GUIDE Program", "GUIDE      ", "Popup Reference Engine.\n");
  701.   if ( CopyFile("int2guid.gui", true) ) /* topic 5 */
  702.     errorexit(missingFile);
  703.  
  704.   configure();
  705.  
  706.   indexed = 0;
  707.   indexNo = mainIndex;
  708.  
  709.   while ( RecognizedTopic() )
  710.     CopyTopic();
  711.  
  712.   Cleanup();
  713.  
  714.   exit(0);
  715. }
  716.  
  717. /* End of INT2GUID.C */
  718.