home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tags18.zip / FLAGS.C < prev    next >
C/C++ Source or Header  |  1992-03-28  |  12KB  |  402 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: flags.c
  5.    Author: J. Kercheval
  6.    Created: Thu, 09/05/1991  20:15:26
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Thu, 09/05/1991  20:19:46  creation
  12.    J. Kercheval  Wed, 09/11/1991  01:43:31  add support for -cx
  13.    J. Kercheval  Tue, 09/17/1991  19:39:31  add support for case_sensitive flag
  14.    J. Kercheval  Fri, 10/04/1991  10:43:10  add ck flag
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #include "flags.h"
  21. #include "log.h"
  22.  
  23.  
  24. /*----------------------------------------------------------------------------
  25.  *
  26.  * init_ASM_flagsa() set the initial values of the ASM language option flags
  27.  *
  28.  ---------------------------------------------------------------------------*/
  29.  
  30. void init_ASM_flags(Flags * flags)
  31. {
  32.     flags->af = TRUE;           /* parse procedure labels by default */
  33.     flags->al = TRUE;           /* parse local labels by default */
  34.     flags->am = TRUE;           /* parse macro labels by default */
  35.     flags->as = TRUE;           /* parse struc labels by default */
  36.     flags->au = TRUE;           /* parse union labels by default */
  37.     flags->ad = TRUE;           /* parse catstr labels by default */
  38. }
  39.  
  40.  
  41. /*----------------------------------------------------------------------------
  42.  *
  43.  * init_C_flags() set the initial values of the c language option flags
  44.  *
  45.  ---------------------------------------------------------------------------*/
  46.  
  47. void init_C_flags(Flags * flags)
  48. {
  49.     flags->cf = TRUE;           /* parse function calls by default */
  50.     flags->cp = TRUE;           /* parse function prototypes by default */
  51.     flags->cm = TRUE;           /* parse macros by default */
  52.     flags->cs = TRUE;           /* parse global structs by default */
  53.     flags->ct = TRUE;           /* parse global typedefs default */
  54.     flags->ce = TRUE;           /* parse global enums by default */
  55.     flags->ck = TRUE;           /* parse global enum constants by default */
  56.     flags->cu = TRUE;           /* parse global unions by default */
  57.     flags->cv = TRUE;           /* parse global variables by default */
  58.     flags->cc = TRUE;           /* parse global classes by default */
  59.     flags->cd = TRUE;           /* parse defines by default */
  60.     flags->cx = TRUE;           /* parse externs by default */
  61.     flags->ci = TRUE;           /* parse statics by default */
  62. }
  63.  
  64.  
  65. /*----------------------------------------------------------------------------
  66.  *
  67.  * init_output_flags() set the initial values of the output option flags
  68.  *
  69.  ---------------------------------------------------------------------------*/
  70.  
  71. void init_output_flags(Flags * flags)
  72. {
  73.     flags->oe = TRUE;           /* The Epsilon tags format is default */
  74.     flags->o5 = FALSE;          /* Epsilon tags format for V5.03 */
  75.     flags->og = FALSE;          /* GNU tags format used in GNU EMACS */
  76.     flags->os = FALSE;          /* Space delimited format */
  77.     flags->om = FALSE;          /* MicroSoft Error format */
  78. }
  79.  
  80.  
  81. /*----------------------------------------------------------------------------
  82.  *
  83.  * init_flags() set the initial values of the all option flags in FLAGS struct
  84.  *
  85.  ---------------------------------------------------------------------------*/
  86.  
  87. void init_flags(Flags * flags)
  88. {
  89.     /* tag_type is initially C type parsing */
  90.     flags->tag_type = C;
  91.  
  92.     /* normally use the fully qualified pathname */
  93.     flags->use_relative_pathnames = FALSE;
  94.  
  95.     /* normally we are noisy and verbose */
  96.     flags->quiet = FALSE;
  97.  
  98.     /* normal logging defaults to overwrite */
  99.     flags->log_overwrite = TRUE;
  100.  
  101.     /* normally we will sort the output to remove duplicate lines */
  102.     flags->sort_tags = TRUE;
  103.  
  104.     /* normally a case insensitive sort is performed */
  105.     flags->case_sensitive = FALSE;
  106.  
  107.     /* normally we will output to stdout */
  108.     flags->output_file = FALSE;
  109.  
  110.     /* init the language specific flags */
  111.     init_ASM_flags(flags);
  112.     init_C_flags(flags);
  113.  
  114.     /* init the output flags */
  115.     init_output_flags(flags);
  116. }
  117.  
  118.  
  119. /*----------------------------------------------------------------------------
  120.  *
  121.  * parse_ASM_flags() set the option flags for ASM command line switch
  122.  *
  123.  ---------------------------------------------------------------------------*/
  124.  
  125. void parse_ASM_flags(char *argv, Flags * flags)
  126. {
  127.     int i, end;
  128.     char message[80];
  129.  
  130.     /* set tag_type */
  131.     if (flags->tag_type != MERGE && flags->tag_type != SORT) {
  132.         flags->tag_type = ASM;
  133.         log_message("# Using ASM style tagging");
  134.     }
  135.     else {
  136.         return;
  137.     }
  138.  
  139.     /* determine the number of modifiers */
  140.     end = strlen(argv);
  141.  
  142.     /* if customized parsing, all flags start off false */
  143.     if (end > 2) {
  144.  
  145.         flags->af = FALSE;
  146.         flags->am = FALSE;
  147.         flags->al = FALSE;
  148.         flags->as = FALSE;
  149.         flags->au = FALSE;
  150.         flags->ad = FALSE;
  151.     }
  152.     else {
  153.  
  154.         /* init flags */
  155.         init_ASM_flags(flags);
  156.     }
  157.  
  158.     /* parse the standard modifiers */
  159.     for (i = 2; i < end; i++) {
  160.  
  161.         /* set flags as required */
  162.         switch (argv[i]) {
  163.  
  164.             case 'f':           /* proc labels */
  165.             case 'F':
  166.                 flags->af = TRUE;
  167.                 break;
  168.  
  169.             case 'l':           /* local labels */
  170.             case 'L':
  171.                 flags->al = TRUE;
  172.                 break;
  173.  
  174.             case 'm':           /* macros */
  175.             case 'M':
  176.                 flags->am = TRUE;
  177.                 break;
  178.  
  179.             case 's':           /* struc labels */
  180.             case 'S':
  181.                 flags->as = TRUE;
  182.                 break;
  183.  
  184.             case 'u':           /* union labels */
  185.             case 'U':
  186.                 flags->au = TRUE;
  187.                 break;
  188.  
  189.             case 'd':           /* data definition labels */
  190.             case 'D':
  191.                 flags->ad = TRUE;
  192.                 break;
  193.  
  194.             default:
  195.                 sprintf(message,
  196.                         "# Ignoring unknown ASM switch modifier ( %c )",
  197.                         argv[i]);
  198.                 log_message(message);
  199.                 break;
  200.         }
  201.     }
  202. }
  203.  
  204.  
  205. /*----------------------------------------------------------------------------
  206.  *
  207.  * parse_C_flags() set the option flags for C command line switch
  208.  *
  209.  ---------------------------------------------------------------------------*/
  210.  
  211. void parse_C_flags(char *argv, Flags * flags)
  212. {
  213.     int i, end;
  214.     char message[80];
  215.  
  216.     /* set tag_type */
  217.     if (flags->tag_type != MERGE && flags->tag_type != SORT) {
  218.         flags->tag_type = C;
  219.         log_message("# Using C style tagging");
  220.     }
  221.     else {
  222.         return;
  223.     }
  224.  
  225.     /* determine the number of modifiers */
  226.     end = strlen(argv);
  227.  
  228.     /* if customized parsing, all flags start off false */
  229.     if (end > 2) {
  230.  
  231.         flags->cf = FALSE;
  232.         flags->cp = FALSE;
  233.         flags->cm = FALSE;
  234.         flags->cs = FALSE;
  235.         flags->ct = FALSE;
  236.         flags->ce = FALSE;
  237.         flags->ck = FALSE;
  238.         flags->cu = FALSE;
  239.         flags->cv = FALSE;
  240.         flags->cc = FALSE;
  241.         flags->cd = FALSE;
  242.         flags->cx = FALSE;
  243.         flags->ci = FALSE;
  244.     }
  245.     else {
  246.  
  247.         /* init flags */
  248.         init_C_flags(flags);
  249.     }
  250.  
  251.     /* parse the switch modifiers */
  252.     for (i = 2; i < end; i++) {
  253.  
  254.         /* set flags as required */
  255.         switch (argv[i]) {
  256.             case 'f':           /* function calls (procedures) */
  257.             case 'F':
  258.                 flags->cf = TRUE;
  259.                 break;
  260.  
  261.             case 'p':           /* function calls (procedures) */
  262.             case 'P':
  263.                 flags->cp = TRUE;
  264.                 break;
  265.  
  266.             case 'm':           /* global macros */
  267.             case 'M':
  268.                 flags->cm = TRUE;
  269.                 break;
  270.  
  271.             case 's':           /* global struct */
  272.             case 'S':
  273.                 flags->cs = TRUE;
  274.                 break;
  275.  
  276.             case 't':           /* global typedef */
  277.             case 'T':
  278.                 flags->ct = TRUE;
  279.                 break;
  280.  
  281.             case 'e':           /* global enum */
  282.             case 'E':
  283.                 flags->ce = TRUE;
  284.                 break;
  285.  
  286.             case 'k':           /* global enum constants */
  287.             case 'K':
  288.                 flags->ck = TRUE;
  289.                 break;
  290.  
  291.             case 'u':           /* global union */
  292.             case 'U':
  293.                 flags->cu = TRUE;
  294.                 break;
  295.  
  296.             case 'v':           /* global variables */
  297.             case 'V':
  298.                 flags->cv = TRUE;
  299.                 break;
  300.  
  301.             case 'c':           /* global classes */
  302.             case 'C':
  303.                 flags->cc = TRUE;
  304.                 break;
  305.  
  306.             case 'd':           /* defines */
  307.             case 'D':
  308.                 flags->cd = TRUE;
  309.                 break;
  310.  
  311.             case 'x':           /* extern defines */
  312.             case 'X':
  313.                 flags->cx = TRUE;
  314.                 break;
  315.  
  316.             case 'i':           /* static declarations */
  317.             case 'I':
  318.                 flags->ci = TRUE;
  319.                 break;
  320.  
  321.             default:
  322.                 sprintf(message,
  323.                         "# Ignoring unknown C switch modifier ( %c )",
  324.                         argv[i]);
  325.                 log_message(message);
  326.                 break;
  327.         }
  328.     }
  329. }
  330.  
  331.  
  332. /*----------------------------------------------------------------------------
  333.  *
  334.  * parse_output_flag() set the option flag for output format, These formats
  335.  * are mutually exclusive from the point of view of this routine.
  336.  *
  337.  ---------------------------------------------------------------------------*/
  338.  
  339. void parse_output_flags(char *argv, Flags * flags)
  340. {
  341.     int i, end;
  342.  
  343.     /* init flags */
  344.     init_output_flags(flags);
  345.  
  346.     end = strlen(argv);
  347.  
  348.     /* parse the switch modifiers */
  349.     for (i = 2; i < end; i++) {
  350.  
  351.         /* set flags as required */
  352.         switch (argv[i]) {
  353.             case 'e':           /* Use Epsilon format */
  354.             case 'E':
  355.                 flags->oe = TRUE;
  356.                 flags->o5 = FALSE;
  357.                 flags->og = FALSE;
  358.                 flags->os = FALSE;
  359.                 flags->om = FALSE;
  360.                 break;
  361.  
  362.             case '5':           /* Use Epsilon format for V5.03 and previous */
  363.                 flags->oe = FALSE;
  364.                 flags->o5 = TRUE;
  365.                 flags->og = FALSE;
  366.                 flags->os = FALSE;
  367.                 flags->om = FALSE;
  368.                 break;
  369.  
  370.             case 'g':           /* Use GNU format */
  371.             case 'G':
  372.                 flags->oe = FALSE;
  373.                 flags->o5 = FALSE;
  374.                 flags->og = TRUE;
  375.                 flags->os = FALSE;
  376.                 flags->om = FALSE;
  377.                 break;
  378.  
  379.             case 's':           /* Use Space Delimite format */
  380.             case 'S':
  381.                 flags->oe = FALSE;
  382.                 flags->o5 = FALSE;
  383.                 flags->og = FALSE;
  384.                 flags->os = TRUE;
  385.                 flags->om = FALSE;
  386.                 break;
  387.  
  388.             case 'm':           /* Use Space Delimite format */
  389.             case 'M':
  390.                 flags->oe = FALSE;
  391.                 flags->o5 = FALSE;
  392.                 flags->og = FALSE;
  393.                 flags->os = FALSE;
  394.                 flags->om = TRUE;
  395.                 break;
  396.  
  397.             default:
  398.                 break;
  399.         }
  400.     }
  401. }
  402.