1/*
2 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like.  Any license provided herein, whether implied or
15 * otherwise, applies only to this software file.  Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA  94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 *
32 */
33/* $Id: debug.c,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
34#include <stdio.h>
35#include <string.h>
36#include "reporter.h"
37
38#ifdef DEBUGGING
39int Debug[MAXDEBUG];		/* Debug level in their areas */
40#endif
41
42/*
43 *	set debug areas & levels
44 *
45 * Syntax:   area[,area]:level[,area[,area]:level]...
46 */
47int set_debug(char *optarg)
48{
49#ifdef DEBUGGING
50	/* pointers to the debug area and level in the option's arguments */
51	char *d_area, *d_level;
52	/* debug area and level after converted to integers */
53	int db_area, db_level;
54
55	d_area = optarg;
56
57	while (*d_area) {
58		d_level = strchr(d_area, ':');
59		*d_level++ = '\0';
60		db_level = atoi(d_level);
61		db_area = atoi(d_area);
62
63		if (db_area > MAXDEBUG) {
64			printf("Error - Debug area %s > maximum of %d\n",
65			       d_area, MAXDEBUG);
66			exit(-1);
67		}
68
69		while (d_area != NULL) {
70			db_area = atoi(d_area);
71			printf("Debug area %d set to %d\n", db_area, db_level);
72			Debug[db_area] = db_level;
73			if ((d_area = strchr(d_area, ',')) != NULL)
74				d_area++;
75		}
76		if ((d_area = strchr(d_level, ',')) == NULL)
77			break;
78	}
79#else
80	printf("Debugging is not enabled.  -D has been ignored\n");
81#endif
82
83	return 0;
84}
85