home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / rh2 / part01 / rhdata.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-21  |  2.7 KB  |  112 lines

  1.  
  2. /* ----------------------------------------------------------------------
  3.  * FILE: rhdata.c
  4.  * VERSION: 2
  5.  * Written by: Ken Stauffer
  6.  * This file contains the predefined symbol table, and related data
  7.  * structures.
  8.  *
  9.  * ---------------------------------------------------------------------- */
  10.  
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #define DATA
  14. #include "rh.h"
  15.  
  16. struct symbol    *symbols;
  17.  
  18. struct symbol    *tokensym;
  19. long        tokenval;
  20. long        token;
  21.  
  22. char        Strbuf[ STRLEN+1 ];
  23. int        strfree=0;
  24.  
  25. struct instr    StackProgram[ LENGTH ];
  26. int        PC;
  27. int        startPC;
  28.  
  29. long        Stack[ MEM+3 ];
  30. int        SP;
  31. int        FP;
  32.  
  33. struct runtime    attr;
  34.  
  35. /*
  36.  * The following variables specify where the input is comming from.
  37.  * If expstr == NULL then the input is certainly not from there, and
  38.  * instead is taken from expfile.
  39.  * else expstr is used as input.
  40.  *
  41.  */
  42.  
  43. char        *expstr;
  44. FILE        *expfile;
  45. char        *expfname;
  46.  
  47. static struct symbol init_syms[]={
  48.     { "NOW",    NUMBER,    0,        c_number,    NULL },
  49.     { "IFBLK",    NUMBER,    S_IFBLK,    c_number,    NULL },
  50.     { "IFCHR",    NUMBER,    S_IFCHR,    c_number,    NULL },
  51.     { "IFDIR",    NUMBER,    S_IFDIR,    c_number,    NULL },
  52.     { "IFMT",    NUMBER,    S_IFMT,        c_number,    NULL },
  53.     { "IFREG",    NUMBER,    S_IFREG,    c_number,    NULL },
  54.     { "ISGID",    NUMBER,    S_ISGID,    c_number,    NULL },
  55.     { "ISUID",    NUMBER,    S_ISUID,    c_number,    NULL },
  56.     { "ISVTX",    NUMBER,    S_ISVTX,    c_number,    NULL },
  57. #ifdef S_IFLNK
  58.     { "IFLNK",    NUMBER,    S_IFLNK,    c_number,    NULL },
  59. #endif
  60. #ifdef S_IFSOCK
  61.     { "IFSOCK",    NUMBER,    S_IFSOCK,    c_number,    NULL },
  62. #endif
  63. #ifdef S_IFIFO
  64.     { "IFIFO",    NUMBER,    S_IFIFO,    c_number,    NULL },
  65. #endif
  66.     { "atime",    FIELD,    0,        c_atime,    NULL },
  67.     { "ctime",    FIELD,    0,        c_ctime,    NULL },
  68.     { "dev",    FIELD,    0,        c_dev,        NULL },
  69.     { "gid",    FIELD,    0,        c_gid,        NULL },
  70.     { "ino",    FIELD,    0,        c_ino,        NULL },
  71.     { "mode",    FIELD,    0,        c_mode,        NULL },
  72.     { "mtime",    FIELD,    0,        c_mtime,    NULL },
  73.     { "nlink",    FIELD,    0,        c_nlink,    NULL },
  74.     { "rdev",    FIELD,    0,        c_rdev,        NULL },
  75.     { "size",    FIELD,    0,        c_size,        NULL },
  76.     { "uid",    FIELD,    0,        c_uid,        NULL },
  77.     { "depth",    FIELD,    0,        c_depth,    NULL },
  78.     { "prune",    FIELD,    0,        c_prune,    NULL },
  79.     { "days",    NUMBER,    24*3600,    c_number,    NULL },
  80.     { "weeks",    NUMBER,    24*3600*7,    c_number,    NULL },
  81.     { "hours",    NUMBER, 3600,        c_number,    NULL },
  82.     { "strlen",    FIELD,  0,        c_baselen,    NULL },
  83.     { "return",    RETURN,    0,        c_return,    NULL }
  84. };
  85.  
  86. rhinit()
  87. {
  88.     int i;
  89.     struct symbol *s,*locatename();
  90.  
  91.     symbols = &init_syms[0];
  92.  
  93.     for(i=0; i< sizeof(init_syms)/sizeof(struct symbol)-1; i++ )
  94.         init_syms[i].next = &init_syms[i+1];
  95.  
  96.     /* initialize the NOW variable to the time right now */
  97.     s = locatename( "NOW" );
  98.     s->value = time(0);
  99. }
  100.  
  101. rhfinish()
  102. {
  103.     struct symbol *s;
  104.  
  105.     while(symbols->type == PARAM || symbols->type == FUNCTION) {
  106.         s = symbols;
  107.         symbols = symbols->next;
  108.         free(s->name);
  109.         free(s);
  110.     }
  111. }
  112.