home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / c_spec / poole_cp / cpinput.c < prev    next >
Text File  |  1989-11-21  |  9KB  |  298 lines

  1. /***********************************************************************
  2.                    cpinput.c
  3.        void near nasty( int );
  4.        void near process_arguments( int, int, char **, int );
  5. ************************************************************************/
  6. #define  MAIN  0
  7. #include "cpheader.h"
  8.  
  9. #if VMS
  10.        void nasty( int );
  11.        void process_arguments( int, int, char **, int );
  12. #endif
  13.  
  14. #if MSDOS
  15.        void near nasty( int );
  16.        void near process_arguments( int, int, char **, int );
  17. #endif
  18.  
  19. /************************************************************************/
  20.  
  21. #if MSDOS
  22. void near nasty( argc )
  23. #else
  24. void nasty( argc )
  25. #endif
  26. int argc;
  27. {
  28. if( argc < 2 )
  29.    {
  30.    (void)printf( "\ncp listfile [ outfile ] [\n" );
  31.    (void)printf(
  32.    "     /p:nn /w:nn /m:nn /r:nn /t:main /f:nnnn /b:nn\n"
  33.            );
  34.    (void)printf(
  35.    "     /l /n /s /q /d /o /u /c /h /x\n"
  36.            );
  37.    (void)printf(   "                        ]\n" );
  38.    (void)printf(
  39.    "     outfile            = prn\n" );
  40.    (void)printf(
  41.    "     p: page length     = %3d   [ 0, 50 -255 ]\n", defined_page_length
  42.            );
  43.    (void)printf(
  44.    "     w: page width      = %3d   [ 80 - 255 ]\n", defined_page_width
  45.            );
  46.    (void)printf(
  47.    "     m: left margin     = %2d    [ 0 - 30 ]\n", defined_left_margin
  48.            );
  49.    (void)printf(
  50.    "     r: right margin     = %2d    [ 0 - 30 ]\n", defined_right_margin
  51.            );
  52.    (void)printf(
  53.    "     t: target function  = %s\n", target
  54.            );
  55.    (void)printf(
  56.    "     f: # of function calls = %4d    [ 2 - 5461 ]\n", MAX_functions
  57.            );
  58.    (void)printf(
  59.    "     b: width of func. box  = %2d    [ 20 - 255 ]\n", defined_box_width
  60.            );
  61.    (void)printf(
  62.    "     n: normal characters( ie not ibm character graphics )\n"
  63.            );
  64.    (void)printf(
  65.    "     l  output library functions\n"
  66.            );
  67.    (void)printf(
  68.    "     c  output file\'s 1st comment\n"
  69.            );
  70.    (void)printf(
  71.    "     s  output statistics only\n"
  72.            );
  73.    (void)printf(
  74.    "     d  show declarations and definitions\n"
  75.            );
  76.    (void)printf(
  77.    "     o  show overlay information\n"
  78.            );
  79.    (void)printf(
  80.    "     u  show unused sorted by filename\n"
  81.            );
  82.    (void)printf(
  83.    "     q  show no messages\n"
  84.            );
  85.    (void)printf(
  86.    "     h  show more help\n"
  87.            );
  88.    (void)printf(
  89.    "     x  show tech info\n"
  90.            );
  91.  
  92.    (void)printf( "\n" );
  93.    exit( 0 );
  94.    }
  95. }
  96. /**********************************************************************/
  97. #if MSDOS
  98. void near process_arguments( index, argc, argv, an_error )
  99. #else
  100. void process_arguments( index, argc, argv, an_error )
  101. #endif
  102. int index, argc, an_error;
  103. char **argv;
  104. {
  105. char c;
  106. int i, tmp;
  107.  
  108. for( i = index; i < argc; ++i )
  109.    {
  110.    if( ( argv[ i ][ 0 ] == '/' ) || ( argv[ i ][ 0 ] == '-' ) )
  111.       {
  112.       if(islower((int)argv[i][1]))
  113.      c = argv[i][1];
  114.       else
  115.      c = (char)tolower( (int)argv[ i ][ 1 ] );
  116.       switch( c )
  117.      {
  118.      case 'n':
  119.         ibm_flag = ( ibm_flag )? false: true;
  120.         break;
  121.      case 'l':
  122.         g_lib_flag = ( g_lib_flag )? false: true;
  123.         break;
  124.      case 'c':
  125.         g_comment_flag = ( g_comment_flag )? false: true;
  126.         break;
  127.      case 'd':
  128.         g_dec_def_flag = ( g_dec_def_flag )? false: true;
  129.         break;
  130.      case 's':
  131.         stats_only = ( stats_only )? false: true;
  132.         break;
  133.      case 'q':
  134.         g_quiet_flag = ( g_quiet_flag )? false: true;
  135.         break;
  136.      case 'o':
  137.         g_ov_flag = true;
  138.         break;
  139.      case 'u':
  140.         g_un_flag = true;
  141.         break;
  142.      case 'h':
  143.         g_help_flag = true;
  144.         break;
  145.      case 'x':
  146.         g_tech_flag = true;
  147.         break;
  148.      default:
  149.       if( ( strlen( argv[ i ] ) > 3 ) && ( argv[ i ][ 2 ] == ':' ) )
  150.           {
  151.            tmp = atoi( &argv[ i ][ 3 ] );
  152.            switch( c )
  153.           {
  154.           case 'p':
  155.            if( ( ( 50 < tmp ) && ( tmp < 256 ) ) || ( tmp == 0 ) )
  156.                defined_page_length = tmp;
  157.            break;
  158.           case 'm':
  159.              if( ( 0 <= tmp ) && ( tmp <= 30 ) )
  160.             defined_left_margin = tmp;
  161.              break;
  162.           case 'r':
  163.              if( ( 0 <= tmp ) && ( tmp <= 30 ) )
  164.             defined_right_margin = tmp;
  165.              break;
  166.           case 't':
  167.              (void)strcpy( target, &argv[ i ][ 3 ] );
  168.              target_flag = true;
  169.              break;
  170.           case 'w':
  171.              if( ( 79 < tmp ) && ( tmp < 256 ) )
  172.             defined_page_width = tmp;
  173.              break;
  174.           case 'f':
  175.              if( ( 1 < tmp ) && ( tmp < 5462 ) )
  176.             Max_functions = tmp;
  177.              break;
  178.           case 'b':
  179.              if( ( 20 < tmp ) && ( tmp < 255 ) )
  180.             defined_box_width = tmp;
  181.              break;
  182.           default:
  183.              (void)printf(
  184.              "\nUnknown argument character: %c, ignored!\n",
  185.                argv[ i ][ 1 ]
  186.                   );
  187.              break;
  188.           }  /* end of switch on character after / or - */
  189.            }     /* end of if :something */
  190.         else
  191.            (void)printf( "\nMissing : for argument %s, ignored!\n",
  192.                  argv[ i ] );
  193.         break;
  194.      }         /* end of switch on character after / or - */
  195.       }          /* end of if / or - */
  196.    else
  197.       (void)printf( "\nUnknown argument: %s, ignored!\n", argv[ i ] );
  198.    }             /* end of for loop on arguments */
  199.  
  200. if( g_tech_flag )
  201.    {
  202.    (void)printf( "\n" );
  203.    (void)printf( "Notes: 1. Max recursive function displacement of %d.\n",
  204.          Max_Recursion
  205.            );
  206.    (void)printf(
  207. "         2. Max # of unique function calls per defined function\n\
  208.         for all defined functions is %d.\n",
  209.    Max_functions );
  210.    (void)printf( "         3. Max # of defined functions is %d.\n",
  211.       Max_defined_functions );
  212.    (void)printf( "\n" );
  213.    (void)printf( "sizeof()\'s:\n" );
  214.    (void)printf(
  215. " function table = %u, contents = %u, data base = %u,\
  216.  database = %u, lib = %u\n",
  217.       sizeof( function_type ),
  218.       sizeof( file_record_type ),
  219.       sizeof( data_base_record_type ),
  220.       sizeof( array_of_ptrs_to_records ),
  221.       sizeof( sorted_called_list_ptrs )
  222.            );
  223.    (void)printf( "\n" );
  224.    (void)printf(
  225.    "The program will tend to show certain \'c\' functions as unused.\n" );
  226.    (void)printf(
  227.    "1. defined functions assigned to declared pointers to function names\n" );
  228.    (void)printf(
  229.    "   and executed as pointers to those function names won't be seen.\n" );
  230.    (void)printf(
  231.    "2. #if(s) controlling the generation of code especially with\n" );
  232.    (void)printf(
  233.    "   braces( { } ) in the conditional code section will especially\n" );
  234.    (void)printf(
  235.    "   screw up if there is an #else code part.  This program will work\n" );
  236.    (void)printf(
  237.    "   on both code parts of the conditional and most probably get out\n" );
  238.    (void)printf(
  239.    "   of sync with the braces. One might do a preprocessor pass compile\n" );
  240.    (void)printf(
  241.    "   and heave it\'s output files as input files at this program.\n" );
  242.    (void)printf(
  243.    "3. #define(s) that expand to functions and call functions will also\n" );
  244.    (void)printf(
  245.    "   be neglected.  The preprocessor may be used as stated above.\n" );
  246. /******
  247.    (void)printf(
  248.    "\n" );
  249. ******/
  250.    (void)printf( "\n" );
  251.    }
  252.  
  253. if( g_help_flag )
  254.    {
  255.    (void)printf( "\n" );
  256.    (void)printf(
  257.    "The listfile argument is an ascii text file containing the list of\n"
  258.            );
  259.    (void)printf(
  260.    "filenames to process, one filename per line (optional overlay number.)\n"
  261.            );
  262.    (void)printf(
  263.    "The output file may be a device or a filename. If there is no\n"
  264.            );
  265.    (void)printf(
  266.    "output filename, \'prn\' is assumed. Note that one may put \'con\'\n"
  267.            );
  268.    (void)printf(
  269.    "here and view the output of the program before printing or saving\n"
  270.            );
  271.    (void)printf(
  272.    "to a filename.\n"
  273.            );
  274.    (void)printf(
  275.    "Also note that the output filename and the input filenames in the\n"
  276.            );
  277.    (void)printf(
  278.    "listfile may be full pathnames with drives and or paths.\n"
  279.            );
  280.    (void)printf( "/ arguments accept the alternate - form.\n" );
  281.    (void)printf( "For example: cp x y -s, cp /h, cp x -x /d -t:junk\n" );
  282.    (void)printf( "arguments may be in upper or lower case.\n" );
  283.    (void)printf( "Note that the target function is case sensitive\n" );
  284.    (void)printf( "since it is a \'c\' function name.\n" );
  285.    (void)printf( "\n" );
  286.    }
  287. if( an_error )
  288.    {
  289.    if( g_help_flag || g_tech_flag )
  290.       exit( 0 );
  291.    else
  292.       (void)printf( "Oops..." );
  293.    }
  294. }
  295. /***********************************************************************/
  296.   else
  297.       (void)printf( "Oops..." );
  298.    }