xref: /csrg-svn/old/dbx/defs.h (revision 14605)
1*14605Ssam /*	defs.h	1.1	83/08/13	*/
2*14605Ssam 
3*14605Ssam /*
4*14605Ssam  * Public definitions, common to all.
5*14605Ssam  */
6*14605Ssam 
7*14605Ssam #include <stdio.h>
8*14605Ssam 
9*14605Ssam #define new(type)           ((type) malloc(sizeof(struct type)))
10*14605Ssam #define newarr(type, n)     ((type *) malloc((unsigned) (n) * sizeof(type)))
11*14605Ssam #define dispose(ptr)        { free((char *) ptr); ptr = 0; }
12*14605Ssam 
13*14605Ssam #define public
14*14605Ssam #define private static
15*14605Ssam 
16*14605Ssam #define ord(enumcon) ((unsigned int) enumcon)
17*14605Ssam #define nil 0
18*14605Ssam #define and &&
19*14605Ssam #define or ||
20*14605Ssam #define not !
21*14605Ssam #define div /
22*14605Ssam #define mod %
23*14605Ssam #define max(a, b)    ((a) > (b) ? (a) : (b))
24*14605Ssam #define min(a, b)    ((a) < (b) ? (a) : (b))
25*14605Ssam 
26*14605Ssam #define assert(b) { \
27*14605Ssam     if (not(b)) { \
28*14605Ssam 	panic("assertion failed at line %d in file %s", __LINE__, __FILE__); \
29*14605Ssam     } \
30*14605Ssam }
31*14605Ssam 
32*14605Ssam #define badcaseval(v) { \
33*14605Ssam     panic("unexpected value %d at line %d in file %s", v, __LINE__, __FILE__); \
34*14605Ssam }
35*14605Ssam 
36*14605Ssam #define checkref(p) { \
37*14605Ssam     if (p == nil) { \
38*14605Ssam 	panic("reference through nil pointer at line %d in file %s", \
39*14605Ssam 	    __LINE__, __FILE__); \
40*14605Ssam     } \
41*14605Ssam }
42*14605Ssam 
43*14605Ssam typedef int Integer;
44*14605Ssam typedef char Char;
45*14605Ssam typedef double Real;
46*14605Ssam typedef enum { false, true } Boolean;
47*14605Ssam typedef char *String;
48*14605Ssam 
49*14605Ssam #define strdup(s)       strcpy(malloc((unsigned) strlen(s) + 1), s)
50*14605Ssam #define streq(s1, s2)   (strcmp(s1, s2) == 0)
51*14605Ssam 
52*14605Ssam typedef FILE *File;
53*14605Ssam typedef int Fileid;
54*14605Ssam typedef String Filename;
55*14605Ssam 
56*14605Ssam #define get(f, var) fread((char *) &(var), sizeof(var), 1, f)
57*14605Ssam #define put(f, var) fwrite((char *) &(var), sizeof(var), 1, f)
58*14605Ssam 
59*14605Ssam #undef FILE
60*14605Ssam 
61*14605Ssam extern long atol();
62*14605Ssam extern double atof();
63*14605Ssam extern char *malloc();
64*14605Ssam extern String strcpy(), index(), rindex();
65*14605Ssam extern int strlen();
66*14605Ssam 
67*14605Ssam extern String cmdname;
68*14605Ssam extern String errfilename;
69*14605Ssam extern short errlineno;
70*14605Ssam extern int debug_flag[];
71