defs.h 1.6 KB

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