parse.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. extern struct cmdtab{
  33. ushort cmdc; /* command character */
  34. uchar text; /* takes a textual argument? */
  35. uchar regexp; /* takes a regular expression? */
  36. uchar addr; /* takes an address (m or t)? */
  37. uchar defcmd; /* default command; 0==>none */
  38. uchar defaddr; /* default address */
  39. uchar count; /* takes a count e.g. s2/// */
  40. char *token; /* takes text terminated by one of these */
  41. int (*fn)(File*, Cmd*); /* function to call with parse tree */
  42. }cmdtab[];
  43. enum Defaddr{ /* default addresses */
  44. aNo,
  45. aDot,
  46. aAll,
  47. };
  48. int nl_cmd(File*, Cmd*), a_cmd(File*, Cmd*), b_cmd(File*, Cmd*);
  49. int c_cmd(File*, Cmd*), cd_cmd(File*, Cmd*), d_cmd(File*, Cmd*);
  50. int D_cmd(File*, Cmd*), e_cmd(File*, Cmd*);
  51. int f_cmd(File*, Cmd*), g_cmd(File*, Cmd*), i_cmd(File*, Cmd*);
  52. int k_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
  53. int p_cmd(File*, Cmd*), q_cmd(File*, Cmd*);
  54. int s_cmd(File*, Cmd*), u_cmd(File*, Cmd*), w_cmd(File*, Cmd*);
  55. int x_cmd(File*, Cmd*), X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*);
  56. int eq_cmd(File*, Cmd*);
  57. String *getregexp(int);
  58. Addr *newaddr(void);
  59. Address address(Addr*, Address, int);
  60. int cmdexec(File*, Cmd*);