home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 165_01 / headers.d < prev    next >
Text File  |  1988-02-19  |  18KB  |  524 lines

  1. ###bin_io.h
  2. /* bin_io.h - header for binary file I/O functions 
  3.  * SYSTEM DEPENDENT - MUST BE CONFIGURED FOR EACH TARGET SYSTEM
  4.  */
  5. #ifndef BIN_IO_H
  6. #define BIN_IO_H
  7. #include "local.h"
  8.  
  9. #include "fcntl.h"        /* provide your own if not standard on system */
  10.  
  11. typedef int bin_fd;        /* "binary file descriptor" {0:BIN_NFILE-1} */
  12.  
  13. #define BIN_NFILE 20    /* adjust to local system */
  14.  
  15. #define O_RWMODE (O_RDONLY|O_WRONLY|O_RDWR)    /* uses symbols from fcntl.h */
  16.  
  17. #ifndef IDRIS
  18. #define bin_open(s, m)        open(s, m)
  19. #endif
  20. #define bin_close(f)        close(f)
  21. #define bin_lseek(f, o, w)    lseek(f, o, w)
  22. #define bin_read(f, b, n)    read(f, b, n)
  23. #define bin_write(f, b, n)    write(f, b, n)
  24.  
  25. #endif
  26. ###fcntl.h
  27. /* fcntl.h - definitions for binary  open
  28.  * Compatible with UNIX Sys V, ...
  29.  */
  30. #ifndef FCNTL_H
  31. #define FCNTL_H
  32. #define O_RDONLY 0        /* delete or change to conform to local */
  33. #define O_WRONLY 1        /* delete or change to conform to local */
  34. #define O_RDWR   2        /* delete or change to conform to local */
  35. #define O_NDELAY 4        /* NOT USED BY bin_io FUNCTIONS */
  36. #define O_APPEND 8        /* delete or change to conform to local */
  37. #define O_CREAT  0x100    /* delete or change to conform to local */
  38. #define O_TRUNC  0x200    /* delete or change to conform to local */
  39. #define O_EXCL   0x400    /* delete or change to conform to local */
  40. #endif
  41. ###local.h
  42. /* local.h - Definitions for use with Reliable Data Structures in C */
  43. #ifndef LOCAL_H
  44. #define LOCAL_H
  45. #include <stdio.h>
  46. #include <ctype.h>
  47. #include <math.h>
  48. #define FALSE            0            /* Boolean value */
  49. #define FOREVER            for(;;)        /* endless loop */
  50. #define NO                0            /* Boolean value */
  51. #define TRUE            1            /* Boolean value */
  52. #define YES                1            /* Boolean value */
  53. #define getln(s, n)        ((fgets(s, n, stdin)==NULL) ? EOF : strlen(s))
  54. #define ABS(x)            (((x) < 0) ? -(x) : (x))
  55. #define MAX(x, y)        (((x) < (y)) ? (y) : (x))
  56. #define MIN(x, y)        (((x) < (y)) ? (x) : (y))
  57. #define DIM(a)            (sizeof(a) / sizeof(a[0]))
  58. #define IN_RANGE(n, lo, hi) ((lo) <= (n) && (n) <= (hi))
  59. #ifndef NDEBUG
  60. #define asserts(cond, str) \
  61.     {if (!(cond)) fprintf(stderr, "Assertion '%s' failed\n", str);}
  62. #else
  63. #define asserts(cond, str)
  64. #endif
  65. #define SWAP(a, b, t)     ((t) = (a), (a) = (b), (b) = (t))
  66. #define LOOPDN(r, n)    for ((r) = (n)+1; --(r) > 0; )
  67. #define STREQ(s, t)        (strcmp(s, t) == 0)
  68. #define STRLT(s, t)        (strcmp(s, t) < 0)
  69. #define STRGT(s, t)        (strcmp(s, t) > 0)
  70. #include "portdefs.h"    /* portability definitions */
  71. #include "stddef.h"        /* (ANSI) standard definitions */
  72. #include "limits.h"        /* (ANSI) machine parameters */
  73. #include "string.h"        /* (ANSI) string functions */
  74. #include "stdlib.h"        /* (ANSI) miscellaneous standard functions */
  75. #include "rdslib.h"        /* functions from Reliable Data Structures in C */
  76. #endif
  77. ###menu.h
  78. /* menu.h - header for menu pgm */
  79. #ifndef MENU_H
  80. #define MENU_H
  81. #include "local.h"
  82. #include "screen.h"
  83. typedef struct string_val
  84.     {
  85.     char edit_type;        /* 'n' = numeric, 'd' = short int, 'a' = anything */
  86.     char *string;        /* ptr to the string value */
  87.     short maxsize;        /* maximum size of string: {2:SHORT_MAX} */
  88.     short *pnum;        /* if non-NULL, ptr to numeric storage */
  89.     } STRING_VAL;
  90. typedef struct choice_val
  91.     {
  92.     short nchoices;        /* number of possible choices: {2:10} */
  93.     char **choices;        /* ptr to start of array of choice strings */
  94.     char *pc;            /* ptr to the one-char coded choice value */
  95.     } CHOICE_VAL;
  96. /* (more)
  97. .PE
  98. .PS 33
  99.  */
  100. typedef struct field
  101.     {
  102.     short line, col;    /* co-ordinates of screen display position */
  103.     char *desc;            /* description (title) of this field: string */
  104.     char val_type;        /* what type of field is this?  */
  105.     STRING_VAL *psv;    /* non-NULL iff val_type == 's' or 'S' */
  106.     CHOICE_VAL *pcv;    /* non-NULL iff val_type == 'c' */
  107.     struct menu *pmenu;    /* non-NULL iff val_type == 'm' */
  108.     bool (*pfn)();        /* function to do after str or choice field */
  109.     } FIELD;
  110. typedef struct menu
  111.     {
  112.     char *title;        /* alphabetic title for menu: string */
  113.     FIELD *fields;        /* ptr to beginning of array of FIELDs */
  114.     short nfields;        /* how many fields in this menu */
  115.     short cur_field;    /* index of the current field */
  116.     } MENU;
  117. FIELD *mu_ask();        /* PARMS(MENU *pm) */
  118. SCR_CMDCHAR mu_chv();    /* PARMS(FIELD *pf) */
  119. void mu_do();            /* PARMS(MENU *pm) */
  120. void mu_pr();            /* PARMS(MENU *pm) */
  121. int mu_reply();            /* PARMS(char *prompt, char *reply, int size) */
  122. SCR_CMDCHAR mu_str();    /* PARMS(FIELD *pf) */
  123. SCR_CMDCHAR mu_sval();    /* PARMS(STRING_VAL *psv) */
  124. #endif
  125. ###part.h
  126. /* part.h - header for parts structure
  127.  */
  128. #ifndef PART_H
  129. #define PART_H
  130. typedef struct part
  131.     {
  132.     char part_no[14];    /* part number; string */
  133.     char lead_time[3];    /* lead time (in weeks); num string {0:99} */
  134.     char unit_meas[2];    /* unit of measure; coded string */
  135.                         /* {"0"=each, "1"=lb, "2"=box, other=each} */
  136.     char unit_cost[8];    /* cost; num string {0.00:9999.99} */
  137.     char cost_qty[5];    /* qty required for price */
  138.                         /* num string {0:9999} */
  139.     } PART;
  140. extern PART part1;
  141. #endif
  142. ###part.h1
  143. /* part.h - header for PART structure */
  144. #ifndef PART_H
  145. #define PART_H
  146. typedef struct part
  147.     {
  148.     char part_no[14];    /* part number: string */
  149.     short lead_time;    /* lead time (in weeks): {0:99} */
  150.     char unit_meas[6];    /* unit of measure: string {"each", "lb", "box"}  */
  151.     float unit_cost;    /* cost for one unit_meas: {0.00:9999.99} */
  152.     short cost_qty;        /* quantity required for price: {0:9999} */
  153.     } PART;
  154. #endif
  155. ###part.h2
  156. /* part.h - header for parts structure
  157.  */
  158. #ifndef PART_H
  159. #define PART_H
  160. typedef struct part
  161.     {
  162.     char part_no[14];    /* part number: string */
  163.     char lead_time[3];    /* lead time (in weeks): num string {0:99} */
  164.     char unit_meas[2];    /* unit of measure: coded string */
  165.                         /* {"0"=each, "1"=lb, "2"=box, other=each} */
  166.     char unit_cost[8];    /* cost: num string {0.00 : 9999.99} */
  167.     char cost_qty[5];    /* qty required for price: num string {0:9999} */
  168.     } PART;
  169. extern PART part1;
  170. #endif
  171. ###pointer.h
  172. /* pointer.h - concise macros for pointer checking and casting */
  173. /* PNN(p)         - test that p is not NULL, return p */
  174. /* PNNC(p, t)     - test that p is not NULL, return p cast to type t */
  175. #ifndef POINTER_H
  176. #define POINTER_H
  177. #ifndef NDEBUG
  178. #define PNN(p)            ((p) != NULL ? (p) : PNN_BAD(p))
  179. #define PNNC(p, t)        ((p) != NULL ? (t)(p) : (t)PNN_BAD(p))
  180. #define PNN_BAD(p)        (fprintf(stderr, "NULL\n"), p)
  181. #else
  182. #define PNN(p)            (p)
  183. #define PNNC(p,t)        ((t)(p))
  184. #endif
  185. #endif
  186. ###queue.h
  187. /* queue.h - header for queue package */
  188. #ifndef QUEUE_H
  189. #define QUEUE_H
  190. #include "local.h"
  191. #include "pointer.h"
  192. #define Q_NODE struct q_node
  193. Q_NODE
  194.     {
  195.     Q_NODE *next;
  196.     /* ... */
  197.     };
  198.  
  199. void q_append();    /* PARMS(Q_NODE **frontp, Q_NODE **rearp, Q_NODE *p) */
  200. void q_close();        /* PARMS(Q_NODE **frontp, Q_NODE **rearp) */
  201. void q_insert();
  202.     /* PARMS(Q_NODE **frontp, Q_NODE **rearp, Q_NODE *p, int (*cmpfn)()) */
  203. Q_NODE **q_lfind();
  204.     /* PARMS(Q_NODE **frontp, Q_NODE **rearp, Q_NODE *p, int (*cmpfn)()) */
  205. Q_NODE *q_pop();    /* PARMS(Q_NODE **frontp, Q_NODE **rearp) */
  206. void q_push();        /* PARMS(Q_NODE **frontp, Q_NODE **rearp, Q_NODE *p) */
  207. Q_NODE *q_r_detach();
  208.     /* PARMS(Q_NODE **frontp, Q_NODE **rearp, Q_NODE **pp) */
  209. void q_r_insert();
  210.     /* PARMS(Q_NODE **frontp, Q_NODE **rearp, Q_NODE *p, Q_NODE **pp) */
  211.  
  212. /* (more)
  213. .PE
  214. .PS 20
  215.  */
  216.  
  217. #define Q_PP(p)        PNNC(p, Q_NODE **)
  218. #define Q_P(p)        PNNC(p, Q_NODE *)
  219.  
  220. #define Q_APPEND(fp, rp, p)        q_append(Q_PP(fp), Q_PP(rp), Q_P(p))
  221. #define Q_CLOSE(fp, rp)            q_close(Q_PP(fp), Q_PP(rp))
  222. #define Q_INSERT(fp, rp, p, fn)    q_insert(Q_PP(fp), Q_PP(rp), Q_P(p), fn)
  223. #define Q_LFIND(fp, rp, p, fn)    q_lfind(Q_PP(fp), Q_PP(rp), Q_P(p), fn)
  224. #define Q_POP(fp, rp)            q_pop(Q_PP(fp), Q_PP(rp))
  225. #define Q_PUSH(fp, rp, p)        q_push(Q_PP(fp), Q_PP(rp), Q_P(p))
  226. #define Q_R_DETACH(fp, rp, pp)    q_r_detach(Q_PP(fp), Q_PP(rp), Q_PP(pp))
  227. #define Q_R_INSERT(fp, rp, p, pp) q_r_insert(Q_PP(fp), Q_PP(rp), Q_P(p), Q_PP(pp))
  228.  
  229. #define Q_IS_EMPTY(front)       ((front) == NULL)
  230. #define Q_OPEN(frontp, rearp)   (*(frontp) = *(rearp) = NULL)
  231. #define Q_NEXT(p)               ((p)->next)
  232. #define EACH_Q(front, p)        for ((p) = front; (p) != NULL; p = (p)->next)
  233. #endif
  234. #