home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource5 / 345_01 / tlcsetp.c < prev    next >
C/C++ Source or Header  |  1989-07-11  |  13KB  |  532 lines

  1. /* TLCSETP.C - "The Last Cross-referencer" - Set Parm routine            */
  2. /*    Last Modified:    02/10/89                                            */
  3.  
  4. /*
  5. ---------------------------------------------------------------------
  6. Copyright (c) 1987-1989, Eduard Schwan Programs [esp] - All rights reserved
  7. TLC (The Last C-Cross-Referencer) and TLP (same, but for Pascal) are
  8. Cross-Reference Generators crafted and shot into the Public Domain by
  9. Eduard Schwan.  The source code and executable program may be freely
  10. distributed as long as the copyright/author notices remain intact, and
  11. it is not used in part or whole as the basis of a commercial product.
  12. Any comments, bug-fixes, or enhancements are welcome.
  13. Also, if you find TLC and it's source code useful, a contribution of
  14. $20 (check/money order) is encouraged!  Hopefully we will all see more
  15. source code distributed!
  16.     Eduard Schwan, 1112 Oceanic Drive, Encinitas, Calif. 92024
  17. ---------------------------------------------------------------------
  18. */
  19.  
  20. /*
  21. HEADER:        The Last Cross-Referencer;
  22. TITLE:        TLC/TLP - The Last Cross-Referencer;
  23. VERSION:    1.01;
  24.  
  25. DESCRIPTION: "TLC/TLP.
  26.             Set Parm routine";
  27.  
  28. KEYWORDS:    Utility, Cross-reference, C, Pascal, Apple, Macintosh, APW, Aztec;
  29. SYSTEM:        Macintosh MPW, v3.0;
  30. FILENAME:    TLCSETP.C;
  31. WARNINGS:    "Has not yet been ported to MS-DOS.
  32.             Shareware, $20 Check/Money Order suggested.";
  33.  
  34. SEE-ALSO:    README.TLC,TLCHELP.DOC,TLPHELP.DOC;
  35. AUTHORS:    Eduard Schwan;
  36. COMPILERS:    AZTEC C65 v3.2b, APPLEIIGS APW C v1.0, APPLE MACINTOSH MPW C v3.0;
  37. */
  38.  
  39.  
  40. /*------------------------ include files -------------------------*/
  41.  
  42. #include    <stdio.h>
  43. #include    "tlc.h"
  44.  
  45.  
  46. /*------------------------- definitions -------------------------*/
  47.  
  48. #include    "tlcparm.h"
  49.  
  50.  
  51. /*--------------------- external declarations --------------------*/
  52.  
  53. #include    "tlc.ext"
  54.  
  55. extern VOID     expand_str_chars();
  56.  
  57.  
  58. /*------------------------ static variables -----------------------*/
  59.  
  60. struct    parmsym_type
  61.     {
  62.     char        *parm_name;
  63.     byte        parm_index;
  64.     };
  65.  
  66. static    struct parmsym_type parm_table[] =
  67. {
  68.  
  69. /* GENERAL */
  70.  
  71.     {"doincludes",            DO_INCLUDES},
  72.     {"dolisting",            DO_LISTING},
  73.     {"doxref",                DO_XREF},
  74.     {"dostats",             DO_STATS},
  75.     {"outfname",            OUT_FNAME},
  76.  
  77. /* PRINTER */
  78.  
  79.     {"pagelines",            PAGE_LINES},
  80.     {"pagecolumns",         PAGE_COLUMNS},
  81.     {"topline",             TOP_LINE},
  82.     {"botline",             BOT_LINE},
  83.     {"leftcolumn",            LEFT_COLUMN},
  84.     {"rightcolumn",         RIGHT_COLUMN},
  85.     {"userheading",         USER_HEADING},
  86.     {"dosingleshts",        DO_SINGLE_SHTS},
  87.     {"printerinit",         PRINTER_INIT},
  88.     {"hasformfeed",         HAS_FORM_FEED},
  89.     {"firstpage",            FIRST_PAGE},
  90.     {"lastpage",            LAST_PAGE},
  91.  
  92.     {"emph1leadin",         EMPH1_LEADIN},    /* printer emphasis strings */
  93.     {"emph2leadin",         EMPH2_LEADIN},
  94.     {"emph3leadin",         EMPH3_LEADIN},
  95.     {"emph1leadout",        EMPH1_LEADOUT},
  96.     {"emph2leadout",        EMPH2_LEADOUT},
  97.     {"emph3leadout",        EMPH3_LEADOUT},
  98.  
  99. /* LISTING */
  100.  
  101.     {"tabwidth",            TAB_WIDTH},
  102.     {"emphcomments",        EMPH_COMMENTS},
  103.     {"emphheading",         EMPH_HEADING},
  104.     {"emphreserved",        EMPH_RESERVED},
  105.     {"emphfuncheads",        EMPH_FUNCHEADS},
  106.     {"pagingstring",        PAGING_STRING},
  107.  
  108. /* XREF */
  109.  
  110.     {"symbolsize",            SYMBOL_SIZE},
  111.     {"xrefnums",            XREF_NUMS},
  112.     {"xrefstrings",         XREF_STRINGS},
  113.     {"doconditionals",        DO_CONDITIONALS},
  114.     {"doconditionals",        DO_CONDITIONALS},
  115.     {"docasesens",            DO_CASE_SENS},
  116.     {"doxcasesens",         DO_XCASE_SENS},
  117.     {"dounderscores",        DO_UNDERSCORES},
  118.     {"emphsymbols",         EMPH_SYMBOLS},
  119.  
  120. /* STATS */
  121.  
  122. /* THE END */
  123.  
  124.     {NULL,                    0}
  125. };
  126.  
  127.  
  128. /*=================[ find_parm ]===================*/
  129.  
  130. static byte find_parm(parm_name)
  131. char    *parm_name;
  132.  
  133.     { /* find_parm() */
  134.     struct parmsym_type *ptable_ptr;
  135.  
  136.     ptable_ptr = parm_table;
  137.     while (ptable_ptr->parm_name != NULL)
  138.         {
  139. /*
  140. debug(printf("find_parm:targ:'%s' curr:'%s'\n",parm_name,ptable_ptr->parm_name);)
  141. */
  142.         if (strcmp(parm_name, ptable_ptr->parm_name)==0)
  143.             { /* found a match, return corresponding index */
  144. /*
  145. debug(printf("find_parm:found '%s'[%u]\n",\
  146.             ptable_ptr->parm_name,ptable_ptr->parm_index);)
  147. */
  148.             return(ptable_ptr->parm_index);
  149.             }
  150.         else
  151.             { /* keep looking */
  152.             ptable_ptr++;
  153.             }
  154.         } /*while*/
  155.             return(0);
  156.     } /* find_parm() */
  157.  
  158.  
  159. /*=================[ bad_type ]===================*/
  160.  
  161. static VOID bad_type(line_num, parm_name, expected_type)
  162. int         line_num;
  163. fname_type    parm_name;
  164. int         expected_type;
  165.  
  166.     { /* bad_type() */
  167.     fprintf(stderr, "Expected a");
  168.     switch (expected_type)
  169.         {
  170.         case TOK_ID:
  171.             fprintf(stderr, "n ID");
  172.             break;
  173.         case TOK_NCONST:
  174.             fprintf(stderr, " Number");
  175.             break;
  176.         case TOK_SCONST:
  177.             fprintf(stderr, " String");
  178.             break;
  179.         default:
  180.             fprintf(stderr, " Type %d", expected_type);
  181.         }
  182.     fprintf(stderr, " for parm '%s'\n", parm_name);
  183.     fprintf(stderr, "in line %d of Parm File '%s'\n",
  184.              line_num, file_rec.parm_fname);
  185.     exit(1);
  186.     } /* bad_type() */
  187.  
  188.  
  189.  
  190. /*=================[ bad_numrange ]===================*/
  191.  
  192. static VOID bad_numrange(line_num, parm_name, lo_bound, hi_bound)
  193. int             line_num;
  194. char*            parm_name;
  195. unsigned long    lo_bound;
  196. unsigned long    hi_bound;
  197.  
  198.     { /* bad_numrange() */
  199.     fprintf(stderr, "Illegal value for parm '%s'\n", parm_name);
  200.     fprintf(stderr, "in line %d of Parm File '%s'\n",
  201.             line_num, file_rec.parm_fname);
  202.     fprintf(stderr, "Valid range for parm is %lu to %lu\n",
  203.             lo_bound, hi_bound);
  204.     exit(1);
  205.     } /* bad_numrange() */
  206.  
  207.  
  208. /*=================[ bad_strlen ]===================*/
  209.  
  210. static VOID bad_strlen(line_num, parm_name, max_len)
  211. int         line_num;
  212. char*        parm_name;
  213. pos_int     max_len;
  214.  
  215.     { /* bad_strlen() */
  216.     fprintf(stderr, "String too long for parm '%s'\n", parm_name);
  217.     fprintf(stderr, "in line %d of Parm File '%s'\n",
  218.             line_num, file_rec.parm_fname);
  219.     fprintf(stderr, "Maximum length for parm is %u\n",
  220.             max_len);
  221.     exit(1);
  222.     } /* bad_strlen() */
  223.  
  224.  
  225. /*=================[ set_byteval ]===================*/
  226.  
  227. static VOID set_byteval(line_num, parm_name, parm_fld_ptr, lo_bound, hi_bound)
  228. int         line_num;
  229. char*        parm_name;
  230. byte*        parm_fld_ptr;
  231. int         lo_bound;
  232. int         hi_bound;
  233.  
  234.     { /* set_byteval() */
  235. /*
  236. debug(printf("set_byte:'%s'=%ld [%d,%d]\n",parm_name,token.tok_value,lo_bound,hi_bound);)
  237. */
  238.     if (token.tok_type == TOK_NCONST)
  239.         { /* right type, check range */
  240.         if (token.tok_value>=lo_bound && token.tok_value<=hi_bound)
  241.             *parm_fld_ptr = (byte)token.tok_value;
  242.         else
  243.             bad_numrange(line_num, parm_name, (long)lo_bound, (long)hi_bound);
  244.         }
  245.     else
  246.         bad_type(line_num, parm_name, TOK_NCONST);
  247.     } /* set_byteval() */
  248.  
  249.  
  250. /*=================[ set_intval ]===================*/
  251.  
  252. static VOID set_intval(line_num, parm_name, parm_fld_ptr, lo_bound, hi_bound)
  253. int         line_num;
  254. char*        parm_name;
  255. pos_int*    parm_fld_ptr;
  256. pos_int     lo_bound;
  257. pos_int     hi_bound;
  258.  
  259.     { /* set_intval() */
  260. /*
  261. debug(printf("set_int:'%s'=%ld [%d,%d]\n",parm_name,token.tok_value,lo_bound,hi_bound);)
  262. */
  263.     if (token.tok_type == TOK_NCONST)
  264.         { /* right type, check range */
  265.         if (token.tok_value >= lo_bound && token.tok_value <= hi_bound)
  266.             *parm_fld_ptr = (pos_int)token.tok_value;
  267.         else
  268.             bad_numrange(line_num, parm_name, (long)lo_bound, (long)hi_bound);
  269.         }
  270.     else
  271.         bad_type(line_num, parm_name, TOK_NCONST);
  272.     } /* set_intval() */
  273.  
  274.  
  275. /*=================[ set_strval ]===================*/
  276.  
  277. static VOID set_strval(line_num, parm_name, parm_fld_ptr, max_len)
  278. int         line_num;
  279. char*        parm_name;
  280. char**        parm_fld_ptr;
  281. int         max_len;
  282.  
  283.     { /* set_strval() */
  284. /*
  285. debug(printf("set_str:'%s'='%s' max=%d\n",parm_name,token.tok_string,max_len);)
  286. */
  287.     if (token.tok_type == TOK_SCONST)
  288.         { /* right type, check length */
  289.         /* crunch backslash escape sequences into true chars first */
  290.         expand_str_chars(token.tok_string);
  291.         if (strlen(token.tok_string)<=max_len)
  292.             {
  293.             *parm_fld_ptr = malloc(strlen(token.tok_string)+1);
  294.             strcpy(*parm_fld_ptr, token.tok_string);
  295.             }
  296.         else
  297.             {
  298.             bad_strlen(line_num, parm_name, max_len);
  299.             }
  300.         }
  301.     else
  302.         bad_type(line_num, parm_name, TOK_SCONST);
  303.     } /* set_intval() */
  304.  
  305.  
  306. /*=================[ set_parm ]===================*/
  307.  
  308. VOID set_parm(line_num, parm_name)
  309. int         line_num;
  310. fname_type    parm_name;
  311.  
  312.     {