OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [demos/] [nxscribble/] [util.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/***********************************************************************
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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.