xref: /csrg-svn/old/dbx/defs.h (revision 16608)
114605Ssam /*
214605Ssam  * Public definitions, common to all.
314605Ssam  */
414605Ssam 
514605Ssam #include <stdio.h>
614605Ssam 
714605Ssam #define new(type)           ((type) malloc(sizeof(struct type)))
814605Ssam #define newarr(type, n)     ((type *) malloc((unsigned) (n) * sizeof(type)))
914605Ssam #define dispose(ptr)        { free((char *) ptr); ptr = 0; }
1014605Ssam 
1114605Ssam #define public
1214605Ssam #define private static
1314605Ssam 
1414605Ssam #define ord(enumcon) ((unsigned int) enumcon)
1514605Ssam #define nil 0
1614605Ssam #define and &&
1714605Ssam #define or ||
1814605Ssam #define not !
1914605Ssam #define div /
2014605Ssam #define mod %
2114605Ssam #define max(a, b)    ((a) > (b) ? (a) : (b))
2214605Ssam #define min(a, b)    ((a) < (b) ? (a) : (b))
2314605Ssam 
2414605Ssam #define assert(b) { \
2514605Ssam     if (not(b)) { \
2614605Ssam 	panic("assertion failed at line %d in file %s", __LINE__, __FILE__); \
2714605Ssam     } \
2814605Ssam }
2914605Ssam 
3014605Ssam #define badcaseval(v) { \
3114605Ssam     panic("unexpected value %d at line %d in file %s", v, __LINE__, __FILE__); \
3214605Ssam }
3314605Ssam 
3414605Ssam #define checkref(p) { \
3514605Ssam     if (p == nil) { \
3614605Ssam 	panic("reference through nil pointer at line %d in file %s", \
3714605Ssam 	    __LINE__, __FILE__); \
3814605Ssam     } \
3914605Ssam }
4014605Ssam 
4114605Ssam typedef int Integer;
42*16608Ssam typedef int integer;
4314605Ssam typedef char Char;
4414605Ssam typedef double Real;
45*16608Ssam typedef double real;
4614605Ssam typedef enum { false, true } Boolean;
47*16608Ssam typedef Boolean boolean;
4814605Ssam typedef char *String;
4914605Ssam 
5014605Ssam #define strdup(s)       strcpy(malloc((unsigned) strlen(s) + 1), s)
5114605Ssam #define streq(s1, s2)   (strcmp(s1, s2) == 0)
5214605Ssam 
5314605Ssam typedef FILE *File;
5414605Ssam typedef int Fileid;
5514605Ssam typedef String Filename;
5614605Ssam 
5714605Ssam #define get(f, var) fread((char *) &(var), sizeof(var), 1, f)
5814605Ssam #define put(f, var) fwrite((char *) &(var), sizeof(var), 1, f)
5914605Ssam 
6014605Ssam #undef FILE
6114605Ssam 
6214605Ssam extern long atol();
6314605Ssam extern double atof();
6414605Ssam extern char *malloc();
6514605Ssam extern String strcpy(), index(), rindex();
6614605Ssam extern int strlen();
6714605Ssam 
6814605Ssam extern String cmdname;
6914605Ssam extern String errfilename;
7014605Ssam extern short errlineno;
7114605Ssam extern int debug_flag[];
72