parse.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. typedef struct Addr Addr;
  2. typedef struct Cmd Cmd;
  3. struct Addr
  4. {
  5. char type; /* # (char addr), l (line addr), / ? . $ + - , ; */
  6. union{
  7. String *re;
  8. Addr *aleft; /* left side of , and ; */
  9. } g;
  10. Posn num;
  11. Addr *next; /* or right side of , and ; */
  12. };
  13. #define are g.re
  14. #define left g.aleft
  15. struct Cmd
  16. {
  17. Addr *addr; /* address (range of text) */
  18. String *re; /* regular expression for e.g. 'x' */
  19. union{
  20. Cmd *cmd; /* target of x, g, {, etc. */
  21. String *text; /* text of a, c, i; rhs of s */
  22. Addr *addr; /* address for m, t */
  23. } g;
  24. Cmd *next; /* pointer to next element in {} */
  25. short num;
  26. ushort flag; /* whatever */
  27. ushort cmdc; /* command character; 'x' etc. */
  28. };
  29. #define ccmd g.cmd
  30. #define ctext g.text
  31. #define caddr g.addr
  32. typedef struct Cmdtab Cmdtab;
  33. struct Cmdtab
  34. {
  35. ushort cmdc; /* command character */
  36. uchar text; /* takes a textual argument? */
  37. uchar regexp; /* takes a regular expression? */
  38. uchar addr; /* takes an address (m or t)? */
  39. uchar defcmd; /* default command; 0==>none */
  40. uchar defaddr; /* default address */
  41. uchar count; /* takes a count e.g. s2/// */
  42. char *token; /* takes text terminated by one of these */
  43. int (*fn)(File*, Cmd*); /* function to call with parse tree */
  44. }cmdtab[];
  45. enum Defaddr{ /* default addresses */
  46. aNo,
  47. aDot,
  48. aAll,
  49. };
  50. int nl_cmd(File*, Cmd*), a_cmd(File*, Cmd*), b_cmd(File*, Cmd*);
  51. int c_cmd(File*, Cmd*), cd_cmd(File*, Cmd*), d_cmd(File*, Cmd*);
  52. int D_cmd(File*, Cmd*), e_cmd(File*, Cmd*);
  53. int f_cmd(File*, Cmd*), g_cmd(File*, Cmd*), i_cmd(File*, Cmd*);
  54. int k_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
  55. int p_cmd(File*, Cmd*), q_cmd(File*, Cmd*);
  56. int s_cmd(File*, Cmd*), u_cmd(File*, Cmd*), w_cmd(File*, Cmd*);
  57. int x_cmd(File*, Cmd*), X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*);
  58. int eq_cmd(File*, Cmd*);
  59. String *getregexp(int);
  60. Addr *newaddr(void);
  61. Address address(Addr*, Address, int);
  62. int cmdexec(File*, Cmd*);