edit.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. //#pragma varargck argpos editerror 1
  10. typedef struct Addr Addr;
  11. typedef struct Address Address;
  12. typedef struct Cmd Cmd;
  13. typedef struct List List;
  14. typedef struct String String;
  15. struct String
  16. {
  17. int n; /* excludes NUL */
  18. Rune *r; /* includes NUL */
  19. int nalloc;
  20. };
  21. struct Addr
  22. {
  23. char type; /* # (char addr), l (line addr), / ? . $ + - , ; */
  24. union{
  25. String *re;
  26. Addr *left; /* left side of , and ; */
  27. };
  28. uint32_t num;
  29. Addr *next; /* or right side of , and ; */
  30. };
  31. struct Address
  32. {
  33. Range r;
  34. File *f;
  35. };
  36. struct Cmd
  37. {
  38. Addr *addr; /* address (range of text) */
  39. String *re; /* regular expression for e.g. 'x' */
  40. union{
  41. Cmd *cmd; /* target of x, g, {, etc. */
  42. String *text; /* text of a, c, i; rhs of s */
  43. Addr *mtaddr; /* address for m, t */
  44. };
  45. Cmd *next; /* pointer to next element in {} */
  46. short num;
  47. uint16_t flag; /* whatever */
  48. uint16_t cmdc; /* command character; 'x' etc. */
  49. };
  50. extern struct cmdtab{
  51. uint16_t cmdc; /* command character */
  52. uint8_t text; /* takes a textual argument? */
  53. uint8_t regexp; /* takes a regular expression? */
  54. uint8_t addr; /* takes an address (m or t)? */
  55. uint8_t defcmd; /* default command; 0==>none */
  56. uint8_t defaddr; /* default address */
  57. uint8_t count; /* takes a count e.g. s2/// */
  58. char *token; /* takes text terminated by one of these */
  59. int (*fn)(Text*, Cmd*); /* function to call with parse tree */
  60. }cmdtab[];
  61. #define INCR 25 /* delta when growing list */
  62. struct List
  63. {
  64. int nalloc;
  65. int nused;
  66. union{
  67. void *listptr;
  68. void* *ptr;
  69. uint8_t* *uint8_tptr;
  70. String* *stringptr;
  71. };
  72. };
  73. enum Defaddr{ /* default addresses */
  74. aNo,
  75. aDot,
  76. aAll,
  77. };
  78. int nl_cmd(Text*, Cmd*), a_cmd(Text*, Cmd*), b_cmd(Text*, Cmd*);
  79. int c_cmd(Text*, Cmd*), d_cmd(Text*, Cmd*);
  80. int B_cmd(Text*, Cmd*), D_cmd(Text*, Cmd*), e_cmd(Text*, Cmd*);
  81. int f_cmd(Text*, Cmd*), g_cmd(Text*, Cmd*), i_cmd(Text*, Cmd*);
  82. int k_cmd(Text*, Cmd*), m_cmd(Text*, Cmd*), n_cmd(Text*, Cmd*);
  83. int p_cmd(Text*, Cmd*);
  84. int s_cmd(Text*, Cmd*), u_cmd(Text*, Cmd*), w_cmd(Text*, Cmd*);
  85. int x_cmd(Text*, Cmd*), X_cmd(Text*, Cmd*), pipe_cmd(Text*, Cmd*);
  86. int eq_cmd(Text*, Cmd*);
  87. String *allocstring(int);
  88. void freestring(String*);
  89. String *getregexp(int);
  90. Addr *newaddr(void);
  91. Address cmdaddress(Addr*, Address, int);
  92. int cmdexec(Text*, Cmd*);
  93. void editerror(char*, ...);
  94. int cmdlookup(int);
  95. void resetxec(void);
  96. void Straddc(String*, int);