comparison packages/services/gfx/mw/current/src/demos/nxscribble/util.c @ 208:e0c0827131d1 ecos

Merge from eCos master repository on 2002-05-20-20:11:54-BST
author jlarmour
date Mon, 20 May 2002 22:19:26 +0000
parents
children
comparison
equal deleted inserted replaced
207:74c807ddde34 208:e0c0827131d1
1 /***********************************************************************
2
3 util.c - memory allocation, error reporting, and other mundane stuff
4
5 Copyright (C) 1991 Dean Rubine
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License. See ../COPYING for
9 the full agreement.
10
11 **********************************************************************/
12 /*
13 * Mundane utility routines
14 * see util.h
15 */
16
17 /*LINTLIBRARY*/
18
19 #include "util.h"
20 #include <stdio.h>
21 #include <ctype.h>
22 #include <setjmp.h>
23 /* ari -- for strlen */
24 #include <string.h>
25
26 extern char* li_err_msg;
27 static char err_msg[BUFSIZ];
28
29 /*
30 * Function used by allocation macro
31 */
32
33 char *
34 myalloc(nitems, itemsize, typename)
35 char *typename;
36 {
37 register unsigned int bytes = nitems * itemsize;
38 register char *p = malloc(bytes);
39 if(p == NULL)
40 error("Can't get mem for %d %s's (each %d bytes, %d total bytes)",
41 nitems, typename, itemsize, bytes);
42 return p;
43 }
44
45 /*
46 * Return a copy of a string
47 */
48
49 char *
50 scopy(s)
51 char *s;
52 {
53 register char *p = allocate(strlen(s) + 1, char);
54 (void) strcpy(p, s);
55 return p;
56 }
57
58 /*
59 * Save error message, then return to recognition manager.
60 */
61
62 /*VARARGS1*/
63 void
64 error(a, b, c, d, e, f, g, h, i, j)
65 char *a;
66 {
67 sprintf(err_msg, a, b, c, d, e, f, g, h, i, j);
68 li_err_msg = err_msg;
69 }
70
71 /*
72 * Print error message, exit.
73 */
74
75
76 /*VARARGS1*/
77 void
78 exit_error(a, b, c, d, e, f, g, h, i, j)
79 char *a;
80 {
81 fprintf(stderr, a, b, c, d, e, f, g, h, i, j);
82 exit(1);
83 }
84
85
86 /*
87 * print a message if DebugFlag is non-zero
88 */
89
90 int DebugFlag = 1;
91
92 void
93 debug(a, b, c, d, e, f, g)
94 char *a;
95 {
96 if(DebugFlag)
97 fprintf(stderr, a, b, c, d, e, f, g);
98 }
99
100 #define upper(c) (islower(c) ? toupper(c) : (c))
101
102 int
103 ucstrcmp(s1, s2)
104 register char *s1, *s2;
105 {
106 register int i;
107
108 for(; *s1 && *s2; s1++, s2++)
109 if( (i = (upper(*s1) - upper(*s2))) != 0)
110 return i;
111 return (upper(*s1) - upper(*s2));
112 }
113
114 #define NSTRINGS 3
115
116 char *
117 tempstring()
118 {
119 static char strings[NSTRINGS][100];
120 static int index;
121 if(index >= NSTRINGS) index = 0;
122 return strings[index++];
123 }