File: utils.c

package info (click to toggle)
cvsgraph 1.4.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 376 kB
  • ctags: 458
  • sloc: ansic: 3,921; yacc: 372; lex: 183; makefile: 79; php: 42; sh: 14
file content (118 lines) | stat: -rw-r--r-- 2,192 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * CvsGraph graphical representation generator of brances and revisions
 * of a file in cvs/rcs.
 *
 * Copyright (C) 2001  B. Stultiens
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include "utils.h"
#include "readconf.h"

const char *input_file;
int quiet;		/* Set if warnings should be suppressed */

void *xmalloc(size_t s)
{
	void *p = malloc(s);
	if(!p)
	{
		printf("Out of memory");
		exit(1);
	}
	memset(p, 0, s);
	return p;
}

void *xrealloc(void *a, size_t s)
{
	void *p;
	if(!a)
		return malloc(s);
	p = realloc(a, s);
	if(!p)
	{
		printf("Out of memory");
		exit(1);
	}
	return p;
}

char *xstrdup(const char *s)
{
	char *c;
	if(!s)
		s = "";
	c = xmalloc(strlen(s)+1);
	strcpy(c, s);
	return c;
}

void xfree(void *p)
{
	if(p)
		free(p);
}

static int do_msg(const char *type, const char *fmt, va_list va)
{
	fprintf(stderr, "%s: ", input_file);
	if(line_number)
		fprintf(stderr, "%d: ", line_number);
	if(type)
		fprintf(stderr, "%s: ", type);
	vfprintf(stderr, fmt, va);
	fprintf(stderr, "\n");
	return 0;
}

int yyerror(const char *fmt, ...)
{
	va_list va;
	va_start(va, fmt);
	do_msg(NULL, fmt, va);
	va_end(va);
	exit(2);
	return 0;
}

int yywarning(const char *fmt, ...)
{
	va_list va;
	if(!quiet)
	{
		va_start(va, fmt);
		do_msg("warning", fmt, va);
		va_end(va);
	}
	return 0;
}

int rcserror(const char *fmt, ...)
{
	va_list va;
	va_start(va, fmt);
	do_msg(NULL, fmt, va);
	va_end(va);
	exit(2);
	return 0;
}