edit.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma varargck argpos editerror 1
  2. typedef struct Addr Addr;
  3. typedef struct Address Address;
  4. typedef struct Cmd Cmd;
  5. typedef struct List List;
  6. typedef struct String String;
  7. struct String
  8. {
  9. int n; /* excludes NUL */
  10. Rune *r; /* includes NUL */
  11. int nalloc;
  12. };
  13. struct Addr
  14. {
  15. char type; /* # (char addr), l (line addr), / ? . $ + - , ; */
  16. union{
  17. String *re;
  18. Addr *left; /* left side of , and ; */
  19. };
  20. ulong num;
  21. Addr *next; /* or right side of , and ; */
  22. };
  23. struct Address
  24. {
  25. Range r;
  26. File *f;
  27. };
  28. struct Cmd
  29. {
  30. Addr *addr; /* address (range of text) */
  31. String *re; /* regular expression for e.g. 'x' */
  32. union{
  33. Cmd *cmd; /* target of x, g, {, etc. */
  34. String *text; /* text of a, c, i; rhs of s */
  35. Addr *mtaddr; /* address for m, t */
  36. };
  37. Cmd *next; /* pointer to next element in {} */
  38. short num;
  39. ushort flag; /* whatever */
  40. ushort cmdc; /* command character; 'x' etc. */
  41. };
  42. extern struct cmdtab{
  43. ushort cmdc; /* command character */
  44. uchar text; /* takes a textual argument? */
  45. uchar regexp; /* takes a regular expression? */
  46. uchar addr; /* takes an address (m or t)? */
  47. uchar defcmd; /* default command; 0==>none */
  48. uchar defaddr; /* default address */
  49. uchar count; /* takes a count e.g. s2/// */
  50. char *token; /* takes text terminated by one of these */
  51. int (*fn)(Text*, Cmd*); /* function to call with parse tree */
  52. }cmdtab[];
  53. #define INCR 25 /* delta when growing list */
  54. struct List /* code depends on a long being able to hold a pointer */
  55. {
  56. int nalloc;
  57. int nused;
  58. union{
  59. void *listptr;
  60. Block *blkptr;
  61. long *longptr;
  62. uchar* *ucharptr;
  63. String* *stringptr;
  64. File* *fileptr;
  65. };
  66. };
  67. enum Defaddr{ /* default addresses */
  68. aNo,
  69. aDot,
  70. aAll,
  71. };
  72. int nl_cmd(Text*, Cmd*), a_cmd(Text*, Cmd*), b_cmd(Text*, Cmd*);
  73. int c_cmd(Text*, Cmd*), d_cmd(Text*, Cmd*);
  74. int B_cmd(Text*, Cmd*), D_cmd(Text*, Cmd*), e_cmd(Text*, Cmd*);
  75. int f_cmd(Text*, Cmd*), g_cmd(Text*, Cmd*), i_cmd(Text*, Cmd*);
  76. int k_cmd(Text*, Cmd*), m_cmd(Text*, Cmd*), n_cmd(Text*, Cmd*);
  77. int p_cmd(Text*, Cmd*);
  78. int s_cmd(Text*, Cmd*), u_cmd(Text*, Cmd*), w_cmd(Text*, Cmd*);
  79. int x_cmd(Text*, Cmd*), X_cmd(Text*, Cmd*), pipe_cmd(Text*, Cmd*);
  80. int eq_cmd(Text*, Cmd*);
  81. String *allocstring(int);
  82. void freestring(String*);
  83. String *getregexp(int);
  84. Addr *newaddr(void);
  85. Address cmdaddress(Addr*, Address, int);
  86. int cmdexec(Text*, Cmd*);
  87. void editerror(char*, ...);
  88. int cmdlookup(int);
  89. void resetxec(void);
  90. void Straddc(String*, int);