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 >
Wrap
Text File
|
1991-06-20
|
3KB
|
88 lines
/* ---------------------------------------------------------
CSWITCH.C
This module contains functions that support a genneric
command-line switch.
Global Functions Defined Herein:
csw_ison(), csw_parse()
Local Functions Defined Herein:
strupr()
Written by: William J. McMahon on: August 25, 1990
---------------------------------------------------------- */
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include "cswitch.h"
#define FNAME_SIZE 8
#define MAX_CSW_AREAS 10
/* ... defines an area for which a swtich is "turned on". */
static struct {
char file[FNAME_SIZE]; /* ... source (name only). */
int min; /* First line that is "on".*/
int max; /* Last line that is "on". */
} csw_area[MAX_CSW_AREAS];
static int n_csw_areas = 0; /* Number of areas in use. */
#ifdef TEST /* ----------- Test Harness ----------- */
main(argc, argv)
int argc;
char *argv[];
{
csw_parse(argc, argv);
CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
CSW_EXEC(printf("\nSwitch @ line %d is on.", __LINE__));
}
#endif /* ------------------------------------ */
/* ---------------------------------------------------------
CSW_ISON
Test whether a source file location (file name and line
number) has been switched "on".
If 'file' is NULL it will test for ANY switch on.
If 'line' is zero it will test for ANY line in the file.
Returns: TRUE or FALSE
---------------------------------------------------------- */
BOOL csw_ison(
char *file,
int line)
{
char name[FNAME_SIZE + 1];
char *p;
int i;
if (n_csw_areas == 0) /* If no debug areas */
return (FALSE); /* are set quick exit. */
if (file == NULL) /* NULL 'file' asks */
return (TRUE); /* if ANY are on. */
p = strrchr(file, '\\'); /* Find begining of */
if (p != NULL) /* file name. */
++p; /* Skip past \. */
else
p = file; /* No path was spec'd. */
strncpy(name, p, FNAME_SIZE);
name[FNAME_SIZE] = '\0'; /* Terminate string. */