home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 93 / applic / sdbio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-15  |  6.7 KB  |  228 lines

  1. /* SDB - definition file */
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5.  
  6. /* useful definitions */
  7. #define TRUE        1
  8. #define FALSE        0
  9.  
  10. /* make sure that NULL gets passed as a pointer */
  11. #undef NULL
  12. #define NULL        (char *)0
  13.  
  14. /* program limits */
  15. #define LINEMAX        132    /* maximum input line length */
  16. #define TABLEMAX    132    /* maximum table output line */
  17. #define KEYWORDMAX    10    /* maximum keyword length */
  18. #define NUMBERMAX    20    /* maximum number length */
  19. #define STRINGMAX    132    /* maximum string length */
  20. #define CODEMAX        100    /* maximum length of code array */
  21. #define STACKMAX    20    /* maximum interpreter stack size */
  22.  
  23. /* token definitions */
  24. #define    EOS        0
  25. #define    LSS        -1
  26. #define    LEQ        -2
  27. #define    EQL        -3
  28. #define    NEQ        -4
  29. #define    GEQ        -5
  30. #define    GTR        -6
  31. #define SELECT        -7
  32. #define FROM        -8
  33. #define WHERE        -9
  34. #define CREATE        -10
  35. #define DELETE        -11
  36. #define INSERT        -12
  37. #define EXIT        -13
  38. #define CHAR        -14
  39. #define NUM        -15
  40. #define ID        -16
  41. #define STRING        -17
  42. #define NUMBER        -18
  43. #define UPDATE        -19
  44. #define PRINT        -20
  45. #define IMPORT        -21
  46. #define EXPORT        -22
  47. #define INTO        -23
  48. #define HELP        -24
  49. #define COMPRESS    -25
  50. #define EXTRACT        -26
  51. #define DEFINE        -27
  52. #define SHOW        -28
  53. #define USING        -29
  54. #define SORT        -30
  55. #define BY        -31
  56. #define ASCENDING    -32
  57. #define DESCENDING    -33
  58. #define SET        -34
  59.  
  60. /* operand types */
  61. #define LITERAL    1
  62. #define ATTR    2
  63. #define TEMP    3
  64.  
  65. /* attribute data types */
  66. #define TCHAR    1
  67. #define TNUM    2
  68.  
  69. /* tuple status codes */
  70. #define UNUSED    0
  71. #define ACTIVE    1
  72. #define DELETED    2
  73.  
  74. /* relation header page format definitions */
  75. #define RNSIZE        10    /* size of a relation name */
  76. #define HSIZE        16    /* size of a relation entry */
  77. #define ASIZE        16    /* size of a attribute entry */
  78. #define ANSIZE        10    /* size of a attribute name */
  79. #define NATTRS        31    /* number of attributes in header block */
  80.  
  81. /* error code definitions */
  82. #define END        0    /* end of retrieval set */
  83. #define INSMEM        1    /* insufficient memory */
  84. #define RELFNF        2    /* relation file not found */
  85. #define BADHDR        3    /* bad relation file header */
  86. #define TUPINP        4    /* tuple input error */
  87. #define TUPOUT        5    /* tuple output error */
  88. #define RELFUL        6    /* relation file full */
  89. #define RELCRE        7    /* error creating relation file */
  90. #define DUPATT        8    /* duplicate attribute on relation create */
  91. #define MAXATT        9    /* too many attributes on relation create */
  92. #define INSBLK        10    /* insufficient disk blocks */
  93. #define SYNTAX        11    /* command syntax error */
  94. #define ATUNDF        12    /* attribute name undefined */
  95. #define ATAMBG        13    /* attribute name ambiguous */
  96. #define RLUNDF        14    /* relation name undefined */
  97. #define CDSIZE        15    /* boolean expression code too big */
  98. #define INPFNF        16    /* input file not found */
  99. #define OUTCRE        17    /* output file creation error */
  100. #define INDFNF        18    /* indirect command file not found */
  101. #define BADSET        19    /* bad set parameter */
  102.  
  103. struct attribute {
  104.     char at_name[ANSIZE];    /* attribute name */
  105.     char at_type;        /* attribute type */
  106.     char at_size;        /* attribute size in bytes */
  107.     char at_scale;        /* attribute scale factor (for numeric only) */
  108.     char at_unused[ASIZE-ANSIZE-3];    /* unused space */
  109. };
  110.  
  111. struct header {        /* sizeof(struct header) must be 512 bytes */
  112.     char hd_tcnt[2];        /* # of tuples in relation */
  113.     char hd_tmax[2];        /* maximum # of tuples */
  114.     char hd_text[2];        /* # of tuples to extend by */
  115.     char hd_data[2];        /* offset to first data byte */
  116.     char hd_size[2];        /* size of each tuple in bytes */
  117.     char hd_unused[HSIZE-6];    /* unused space */
  118.     struct attribute hd_attrs[NATTRS];    /* table of attributes */
  119. };
  120.  
  121. struct relation {
  122.     char rl_name[RNSIZE];    /* relation name */
  123.     unsigned int rl_tcnt;    /* # of tuples in relation (from hd_tcnt) */
  124.     unsigned int rl_tmax;    /* maximum # of tuples (from hd_tmax) */
  125.     unsigned int rl_text;    /* # of tuples to extend by */
  126.     int rl_data;        /* offset to first data byte (from hd_data) */
  127.     int rl_size;        /* size of eachtuple in bytes (from hd_size) */
  128.     int rl_store;        /* flag indicating a store happened */
  129.     int rl_fd;            /* file descriptor for relation file */
  130.     int rl_scnref;        /* number of scans referencing this relation */
  131.     struct header rl_header;    /* the relation file header block */
  132.     struct relation *rl_next;    /* pointer to next relation */
  133. };
  134.  
  135. struct scan {
  136.     struct relation *sc_relation;    /* pointer to relation definition */
  137.     unsigned int sc_dtnum;        /* desired tuple number */
  138.     unsigned int sc_atnum;        /* actual tuple number */
  139.     int sc_store;            /* flag indicating a store happened */
  140.     char *sc_tuple;            /* tuple buffer */
  141. };
  142.  
  143. struct srel {
  144.     char *sr_name;            /* alternate relation name */
  145.     struct scan *sr_scan;        /* relation scan structure ptr */
  146.     int sr_ctuple;            /* current tuple flag */
  147.     int sr_update;            /* updated tuple flag */
  148.     struct srel *sr_next;        /* next selected relation in list */
  149. };
  150.  
  151. struct sattr {
  152.     char *sa_rname;            /* relation name */
  153.     char *sa_aname;            /* attribute name */
  154.     char *sa_name;            /* alternate attribute name */
  155.     char *sa_aptr;            /* pointer to attr in tuple buffer */
  156.     struct srel *sa_srel;        /* pointer to the selected relation */
  157.     struct attribute *sa_attr;        /* attribute structure ptr */
  158.     struct sattr *sa_next;        /* next selected attribute in list */
  159. };
  160.  
  161. struct operand {
  162.     int o_type;
  163.     union  {
  164.     struct {
  165.             int ovc_type;
  166.         char *ovc_string;
  167.         int ovc_length;
  168.     } ov_char;
  169.     int ov_boolean;
  170.     } o_value;
  171. };
  172.  
  173. union codecell {
  174.     int (*c_operator)();
  175.     struct operand *c_operand;
  176. };
  177.  
  178. struct binding {
  179.     struct attribute *bd_attr;        /* bound attribute */
  180.     char *bd_vtuple;            /* pointer to value in tuple */
  181.     char *bd_vuser;            /* pointer to user buffer */
  182.     struct binding *bd_next;        /* next binding */
  183. };
  184.  
  185. struct sel {
  186.     struct srel *sl_rels;        /* selected relations */
  187.     struct sattr *sl_attrs;        /* selected attributes */
  188.     union codecell *sl_where;        /* where clause */
  189.     struct binding *sl_bindings;    /* user variable bindings */
  190. };
  191.  
  192. struct mtext {
  193.     char *mt_text;
  194.     struct mtext *mt_next;
  195. };
  196.  
  197. struct macro {
  198.     char *mc_name;
  199.     struct mtext *mc_mtext;
  200.     struct macro *mc_next;
  201. };
  202.  
  203. struct ifile {
  204.     FILE *if_fp;
  205.     struct mtext *if_mtext;
  206.     char *if_cmdline;
  207.     int if_savech;
  208.     char *if_lptr;
  209.     struct ifile *if_next;
  210. };
  211.  
  212. struct skey {
  213.     int sk_type;
  214.     struct attribute *sk_aptr;
  215.     int sk_start;
  216.     struct skey *sk_next;
  217. };
  218.  
  219. /* external routines */
  220. extern struct sel *db_select();
  221. extern struct sel *db_retrieve();
  222. extern struct relation *db_rcreate();
  223. extern struct scan *db_ropen();
  224. extern char *db_nerror();
  225. extern char *db_gline();
  226. extern char *malloc();
  227. extern char *calloc();
  228.