home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / bbs / programs / amiga / makeindex.lha / makeindex-2.12 / src / scanst.c < prev    next >
C/C++ Source or Header  |  1993-05-26  |  15KB  |  617 lines

  1. /*
  2.  *
  3.  *  This file is part of
  4.  *    MakeIndex - A formatter and format independent index processor
  5.  *
  6.  *  Copyright (C) 1989 by Chen & Harrison International Systems, Inc.
  7.  *  Copyright (C) 1988 by Olivetti Research Center
  8.  *  Copyright (C) 1987 by Regents of the University of California
  9.  *
  10.  *  Author:
  11.  *    Pehong Chen
  12.  *    Chen & Harrison International Systems, Inc.
  13.  *    Palo Alto, California
  14.  *    USA
  15.  *    (phc@renoir.berkeley.edu or chen@orc.olivetti.com)
  16.  *
  17.  *  Contributors:
  18.  *    Please refer to the CONTRIB file that comes with this release
  19.  *    for a list of people who have contributed to this and/or previous
  20.  *    release(s) of MakeIndex.
  21.  *
  22.  *  All rights reserved by the copyright holders.  See the copyright
  23.  *  notice distributed with this software for a complete description of
  24.  *  the conditions under which it is made available.
  25.  *
  26.  */
  27.  
  28. #include    "mkind.h"
  29. #include    "scanst.h"
  30.  
  31. static int sty_lc = 0;                 /* line count */
  32. static int sty_tc = 0;                 /* total count */
  33. static int sty_ec = 0;                 /* error count */
  34.  
  35. char    idx_keyword[ARRAY_MAX] = IDX_KEYWORD;
  36. char    idx_aopen = IDX_AOPEN;
  37. char    idx_aclose = IDX_ACLOSE;
  38. char    idx_level = IDX_LEVEL;
  39. char    idx_ropen = IDX_ROPEN;
  40. char    idx_rclose = IDX_RCLOSE;
  41. char    idx_quote = IDX_QUOTE;
  42. char    idx_actual = IDX_ACTUAL;
  43. char    idx_encap = IDX_ENCAP;
  44. char    idx_escape = IDX_ESCAPE;
  45.  
  46. char    preamble[ARRAY_MAX] = PREAMBLE_DEF;
  47. char    postamble[ARRAY_MAX] = POSTAMBLE_DEF;
  48. int     prelen = PREAMBLE_LEN;
  49. int     postlen = POSTAMBLE_LEN;
  50.  
  51. char    setpage_open[ARRAY_MAX] = SETPAGEOPEN_DEF;
  52. char    setpage_close[ARRAY_MAX] = SETPAGECLOSE_DEF;
  53. int     setpagelen = SETPAGE_LEN;
  54.  
  55. char    group_skip[ARRAY_MAX] = GROUPSKIP_DEF;
  56. int     skiplen = GROUPSKIP_LEN;
  57.  
  58. int     headings_flag = HEADINGSFLAG_DEF;
  59. char    heading_pre[ARRAY_MAX] = HEADINGPRE_DEF;
  60. char    heading_suf[ARRAY_MAX] = HEADINGSUF_DEF;
  61. int     headprelen = HEADINGPRE_LEN;
  62. int     headsuflen = HEADINGSUF_LEN;
  63.  
  64. char    symhead_pos[ARRAY_MAX] = SYMHEADPOS_DEF;
  65. char    symhead_neg[ARRAY_MAX] = SYMHEADNEG_DEF;
  66.  
  67. char    numhead_pos[ARRAY_MAX] = NUMHEADPOS_DEF;
  68. char    numhead_neg[ARRAY_MAX] = NUMHEADNEG_DEF;
  69.  
  70. char    item_r[FIELD_MAX][ARRAY_MAX] = {ITEM0_DEF, ITEM1_DEF, ITEM2_DEF};
  71. char    item_u[FIELD_MAX][ARRAY_MAX] = {"", ITEM1_DEF, ITEM2_DEF};
  72. char    item_x[FIELD_MAX][ARRAY_MAX] = {"", ITEM1_DEF, ITEM2_DEF};
  73.  
  74. int     ilen_r[FIELD_MAX] = {ITEM_LEN, ITEM_LEN, ITEM_LEN};
  75. int     ilen_u[FIELD_MAX] = {0, ITEM_LEN, ITEM_LEN};
  76. int     ilen_x[FIELD_MAX] = {0, ITEM_LEN, ITEM_LEN};
  77.  
  78. char    delim_p[FIELD_MAX][ARRAY_MAX] = {DELIM_DEF, DELIM_DEF, DELIM_DEF};
  79. char    delim_n[ARRAY_MAX] = DELIM_DEF; /* page number separator */
  80. char    delim_r[ARRAY_MAX] = DELIMR_DEF;/* page range designator */
  81. char    delim_t[ARRAY_MAX] = DELIMT_DEF;/* page list terminating delimiter */
  82.  
  83. char    suffix_2p[ARRAY_MAX] = "";      /* suffix for two page ranges */
  84. char    suffix_3p[ARRAY_MAX] = "";      /* suffix for three page ranges */
  85. char    suffix_mp[ARRAY_MAX] = "";      /* suffix for multiple page ranges */
  86.  
  87. char    encap_p[ARRAY_MAX] = ENCAP0_DEF;/* encapsulator prefix */
  88. char    encap_i[ARRAY_MAX] = ENCAP1_DEF;/* encapsulator infix */
  89. char    encap_s[ARRAY_MAX] = ENCAP2_DEF;/* encapsulator postfix */
  90.  
  91. int     linemax = LINE_MAX;
  92.  
  93. int     indent_length = INDENTLEN_DEF;
  94. char    indent_space[ARRAY_MAX] = INDENTSPC_DEF;
  95.  
  96. char    page_comp[ARRAY_MAX] = COMPOSITOR_DEF;
  97. int     page_offset[PAGETYPE_MAX] = {
  98. 0,
  99. ROMAN_LOWER_OFFSET,
  100. ROMAN_LOWER_OFFSET + ARABIC_OFFSET,
  101. ROMAN_LOWER_OFFSET + ARABIC_OFFSET + ALPHA_LOWER_OFFSET,
  102. ROMAN_LOWER_OFFSET + ARABIC_OFFSET + ALPHA_LOWER_OFFSET + ROMAN_UPPER_OFFSET
  103. };
  104. static char page_prec[ARRAY_MAX] = PRECEDENCE_DEF;
  105.  
  106. static int put_dot;
  107.  
  108. static    int    count_lfd ARGS((char *str));
  109. static    int    next_nonblank ARGS((void));
  110. static    int    process_precedence ARGS((void));
  111. static    int    scan_char ARGS((char *c));
  112. static    int    scan_spec ARGS((char *spec));
  113. static    int    scan_string ARGS((char *str));
  114.  
  115. void
  116. scan_sty(VOID_ARG)
  117. {
  118.     char    spec[STRING_MAX];
  119.     int     tmp;
  120.  
  121.     MESSAGE("Scanning style file %s", sty_fn);
  122.     while (scan_spec(spec)) {
  123.     sty_tc++;
  124.     put_dot = TRUE;
  125.  
  126.     /* output pre- and post-ambles */
  127.     if (STREQ(spec, PREAMBLE)) {
  128.         (void) scan_string(preamble);
  129.         prelen = count_lfd(preamble);
  130.     } else if (STREQ(spec, POSTAMBLE)) {
  131.         (void) scan_string(postamble);
  132.         postlen = count_lfd(postamble);
  133.     } else if (STREQ(spec, GROUP_SKIP)) {
  134.         (void) scan_string(group_skip);
  135.         skiplen = count_lfd(group_skip);
  136.     } else if (STREQ(spec, HEADINGS_FLAG)) {
  137.         SCAN_NO(&headings_flag);
  138.     } else if (STREQ(spec, HEADING_PRE)) {
  139.         (void) scan_string(heading_pre);
  140.         headprelen = count_lfd(heading_pre);
  141.     } else if (STREQ(spec, HEADING_SUF)) {
  142.         (void) scan_string(heading_suf);
  143.         headsuflen = count_lfd(heading_suf);
  144.     } else if (STREQ(spec, SYMHEAD_POS)) {
  145.         (void) scan_string(symhead_pos);
  146.     } else if (STREQ(spec, SYMHEAD_NEG)) {
  147.         (void) scan_string(symhead_neg);
  148.     } else if (STREQ(spec, NUMHEAD_POS)) {
  149.         (void) scan_string(numhead_pos);
  150.     } else if (STREQ(spec, NUMHEAD_NEG)) {
  151.         (void) scan_string(numhead_neg);
  152.     } else if (STREQ(spec, SETPAGEOPEN)) {
  153.         (void) scan_string(setpage_open);
  154.         setpagelen = count_lfd(setpage_open);
  155.     } else if (STREQ(spec, SETPAGECLOSE)) {
  156.         (void) scan_string(setpage_close);
  157.         setpagelen = count_lfd(setpage_close);
  158.         /* output index item commands */
  159.     } else if (STREQ(spec, ITEM_0)) {
  160.         (void) scan_string(item_r[0]);
  161.         ilen_r[0] = count_lfd(item_r[0]);
  162.     } else if (STREQ(spec, ITEM_1)) {
  163.         (void) scan_string(item_r[1]);
  164.         ilen_r[1] = count_lfd(item_r[1]);
  165.     } else if (STREQ(spec, ITEM_2)) {
  166.         (void) scan_string(item_r[2]);
  167.         ilen_r[2] = count_lfd(item_r[2]);
  168.     } else if (STREQ(spec, ITEM_01)) {
  169.         (void) scan_string(item_u[1]);
  170.         ilen_u[1] = count_lfd(item_u[1]);
  171.     } else if (STREQ(spec, ITEM_12)) {
  172.         (void) scan_string(item_u[2]);
  173.         ilen_u[2] = count_lfd(item_u[2]);
  174.     } else if (STREQ(spec, ITEM_x1)) {
  175.         (void) scan_string(item_x[1]);
  176.         ilen_x[1] = count_lfd(item_x[1]);
  177.     } else if (STREQ(spec, ITEM_x2)) {
  178.         (void) scan_string(item_x[2]);
  179.         ilen_x[2] = count_lfd(item_x[2]);
  180.         /* output encapsulators */
  181.     } else if (STREQ(spec, ENCAP_0))
  182.         (void) scan_string(encap_p);
  183.     else if (STREQ(spec, ENCAP_1))
  184.         (void) scan_string(encap_i);
  185.     else if (STREQ(spec, ENCAP_2))
  186.         (void) scan_string(encap_s);
  187.     /* output delimiters */
  188.     else if (STREQ(spec, DELIM_0))
  189.         (void) scan_string(delim_p[0]);
  190.     else if (STREQ(spec, DELIM_1))
  191.         (void) scan_string(delim_p[1]);
  192.     else if (STREQ(spec, DELIM_2))
  193.         (void) scan_string(delim_p[2]);
  194.     else if (STREQ(spec, DELIM_N))
  195.         (void) scan_string(delim_n);
  196.     else if (STREQ(spec, DELIM_R))
  197.         (void) scan_string(delim_r);
  198.     else if (STREQ(spec, DELIM_T))
  199.         (void) scan_string(delim_t);
  200.     else if (STREQ(spec, SUFFIX_2P))
  201.         (void) scan_string(suffix_2p);
  202.     else if (STREQ(spec, SUFFIX_3P))
  203.         (void) scan_string(suffix_3p);
  204.     else if (STREQ(spec, SUFFIX_MP))
  205.         (void) scan_string(suffix_mp);
  206.     /* output line width */
  207.     else if (STREQ(spec, LINEMAX)) {
  208.         SCAN_NO(&tmp);
  209.         if (tmp > 0)
  210.         linemax = tmp;
  211.         else
  212.         STY_ERROR2("%s must be positive (got %d)",
  213.                LINEMAX, tmp);
  214.         /* output line indentation length */
  215.     } else if (STREQ(spec, INDENT_LENGTH)) {
  216.         SCAN_NO(&tmp);
  217.         if (tmp >= 0)
  218.         indent_length = tmp;
  219.         else
  220.         STY_ERROR2("%s must be nonnegative (got %d)",
  221.                INDENT_LENGTH, tmp);
  222.         /* output line indentation */
  223.     } else if (STREQ(spec, INDENT_SPACE)) {
  224.         (void) scan_string(indent_space);
  225.         /* composite page delimiter */
  226.     } else if (STREQ(spec, COMPOSITOR)) {
  227.         (void) scan_string(page_comp);
  228.         /* page precedence */
  229.     } else if (STREQ(spec, PRECEDENCE)) {
  230.         (void) scan_string(page_prec);
  231.         (void) process_precedence();
  232.         /* index input format */
  233.     } else if (STREQ(spec, KEYWORD))
  234.         (void) scan_string(idx_keyword);
  235.     else if (STREQ(spec, AOPEN))
  236.         (void) scan_char(&idx_aopen);
  237.     else if (STREQ(spec, ACLOSE))
  238.         (void) scan_char(&idx_aclose);
  239.     else if (STREQ(spec, LEVEL))
  240.         (void) scan_char(&idx_level);
  241.     else if (STREQ(spec, ROPEN))