home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_10 / 9n10098a < prev    next >
Text File  |  1991-06-20  |  3KB  |  88 lines

  1.  
  2. /* ---------------------------------------------------------
  3.     CSWITCH.C
  4.  
  5.     This module contains functions that support a genneric
  6.     command-line switch.
  7.  
  8.     Global Functions Defined Herein:
  9.         csw_ison(), csw_parse()
  10.  
  11.     Local Functions Defined Herein:
  12.         strupr()
  13.  
  14.     Written by: William J. McMahon     on: August 25, 1990
  15. ---------------------------------------------------------- */
  16. #include <stdio.h>
  17. #include <ctype.h>
  18. #include <limits.h>
  19. #include <string.h>
  20. #include "cswitch.h"
  21.  
  22. #define FNAME_SIZE       8
  23. #define MAX_CSW_AREAS   10
  24.  
  25. /* ... defines an area for which a swtich is "turned on". */
  26. static struct {
  27.     char file[FNAME_SIZE];     /* ... source (name only). */
  28.     int  min;                  /* First line that is "on".*/
  29.     int  max;                  /* Last line that is "on". */
  30.     } csw_area[MAX_CSW_AREAS];
  31.  
  32. static int n_csw_areas = 0;    /* Number of areas in use. */
  33.  
  34. #ifdef TEST       /* ----------- Test Harness ----------- */
  35. main(argc, argv)
  36.     int argc;
  37.     char *argv[];
  38. {
  39.     csw_parse(argc, argv);
  40.  
  41.     CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
  42.  
  43.     CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
  44.  
  45.     CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
  46.  
  47.     CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
  48.  
  49.     CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
  50.  
  51. }
  52. #endif            /* ------------------------------------ */
  53.  
  54. /* ---------------------------------------------------------
  55.                             CSW_ISON
  56.  
  57.     Test whether a source file location (file name and line
  58.     number) has been switched "on".
  59.  
  60.     If 'file' is NULL it will test for ANY switch on.
  61.     If 'line' is zero it will test for ANY line in the file.
  62.  
  63.     Returns: TRUE or FALSE
  64. ---------------------------------------------------------- */
  65. BOOL csw_ison(
  66.     char *file,
  67.     int line)
  68. {
  69.     char  name[FNAME_SIZE + 1];
  70.     char *p;
  71.     int   i;
  72.  
  73.     if (n_csw_areas == 0)          /* If no debug areas   */
  74.         return (FALSE);            /* are set quick exit. */
  75.  
  76.     if (file == NULL)              /* NULL 'file' asks    */
  77.         return (TRUE);             /* if ANY are on.      */
  78.  
  79.     p = strrchr(file, '\\');       /* Find begining of    */
  80.     if (p != NULL)                 /* file name.          */
  81.         ++p;                       /* Skip past \.        */
  82.     else
  83.         p = file;                  /* No path was spec'd. */
  84.  
  85.     strncpy(name, p, FNAME_SIZE);
  86.     name[FNAME_SIZE] = '\0';       /* Terminate string.   */
  87.  
  88.