You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmd.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* $Header: cmd.h,v 1.0.1.1 88/01/28 10:23:07 root Exp $
  2. *
  3. * $Log: cmd.h,v $
  4. * Revision 1.0.1.1 88/01/28 10:23:07 root
  5. * patch8: added eval_root for eval operator.
  6. *
  7. * Revision 1.0 87/12/18 13:04:59 root
  8. * Initial revision
  9. *
  10. */
  11. #define C_NULL 0
  12. #define C_IF 1
  13. #define C_WHILE 2
  14. #define C_EXPR 3
  15. #define C_BLOCK 4
  16. #ifndef DOINIT
  17. extern char *cmdname[];
  18. #else
  19. char *cmdname[] = {
  20. "NULL",
  21. "IF",
  22. "WHILE",
  23. "EXPR",
  24. "BLOCK",
  25. "5",
  26. "6",
  27. "7",
  28. "8",
  29. "9",
  30. "10",
  31. "11",
  32. "12",
  33. "13",
  34. "14",
  35. "15",
  36. "16"
  37. };
  38. #endif
  39. #define CF_OPTIMIZE 077 /* type of optimization */
  40. #define CF_FIRSTNEG 0100/* conditional is ($register NE 'string') */
  41. #define CF_NESURE 0200 /* if first doesn't match we're sure */
  42. #define CF_EQSURE 0400 /* if first does match we're sure */
  43. #define CF_COND 01000 /* test c_expr as conditional first, if not null. */
  44. /* Set for everything except do {} while currently */
  45. #define CF_LOOP 02000 /* loop on the c_expr conditional (loop modifiers) */
  46. #define CF_INVERT 04000 /* it's an "unless" or an "until" */
  47. #define CF_ONCE 010000 /* we've already pushed the label on the stack */
  48. #define CF_FLIP 020000 /* on a match do flipflop */
  49. #define CFT_FALSE 0 /* c_expr is always false */
  50. #define CFT_TRUE 1 /* c_expr is always true */
  51. #define CFT_REG 2 /* c_expr is a simple register */
  52. #define CFT_ANCHOR 3 /* c_expr is an anchored search /^.../ */
  53. #define CFT_STROP 4 /* c_expr is a string comparison */
  54. #define CFT_SCAN 5 /* c_expr is an unanchored search /.../ */
  55. #define CFT_GETS 6 /* c_expr is $reg = <filehandle> */
  56. #define CFT_EVAL 7 /* c_expr is not optimized, so call eval() */
  57. #define CFT_UNFLIP 8 /* 2nd half of range not optimized */
  58. #define CFT_CHOP 9 /* c_expr is a chop on a register */
  59. #ifndef DOINIT
  60. extern char *cmdopt[];
  61. #else
  62. char *cmdopt[] = {
  63. "FALSE",
  64. "TRUE",
  65. "REG",
  66. "ANCHOR",
  67. "STROP",
  68. "SCAN",
  69. "GETS",
  70. "EVAL",
  71. "UNFLIP",
  72. "CHOP",
  73. "10"
  74. };
  75. #endif
  76. struct acmd {
  77. STAB *ac_stab; /* a symbol table entry */
  78. ARG *ac_expr; /* any associated expression */
  79. };
  80. struct ccmd {
  81. CMD *cc_true; /* normal code to do on if and while */
  82. CMD *cc_alt; /* else code or continue code */
  83. };
  84. struct cmd {
  85. CMD *c_next; /* the next command at this level */
  86. ARG *c_expr; /* conditional expression */
  87. CMD *c_head; /* head of this command list */
  88. STR *c_first; /* head of string to match as shortcut */
  89. STAB *c_stab; /* a symbol table entry, mostly for fp */
  90. SPAT *c_spat; /* pattern used by optimization */
  91. char *c_label; /* label for this construct */
  92. union ucmd {
  93. struct acmd acmd; /* normal command */
  94. struct ccmd ccmd; /* compound command */
  95. } ucmd;
  96. short c_flen; /* len of c_first, if not null */
  97. short c_flags; /* optimization flags--see above */
  98. char c_type; /* what this command does */
  99. };
  100. #define Nullcmd Null(CMD*)
  101. EXT CMD *main_root INIT(Nullcmd);
  102. EXT CMD *eval_root INIT(Nullcmd);
  103. EXT struct compcmd {
  104. CMD *comp_true;
  105. CMD *comp_alt;
  106. } foo; /* rhaamo: foo required or will get:
  107. * warning: useless storage class specifier in empty declaration!
  108. */
  109. #ifndef DOINIT
  110. extern struct compcmd Nullccmd;
  111. #else
  112. struct compcmd Nullccmd = {Nullcmd, Nullcmd};
  113. #endif
  114. void opt_arg();
  115. void evalstatic();
  116. STR *cmd_exec();