00001
00002
00003
00004
00005 #include <minix/config.h>
00006 #include <sys/types.h>
00007 #include <fcntl.h>
00008 #include <stdlib.h>
00009 #include <unistd.h>
00010 #include <limits.h>
00011
00012 #ifndef YMAX
00013 #ifdef UNIX
00014 #include <stdio.h>
00015 #undef putchar
00016 #undef getchar
00017 #undef NULL
00018 #undef EOF
00019 extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
00020 #define YMAX 49
00021 #else
00022 #define YMAX 24
00023
00024 extern char *enter_string;
00025 extern char *rev_video;
00026 extern char *normal_video;
00027 extern char *rev_scroll;
00028 extern char *pos_string;
00029 #define X_PLUS ' '
00030 #define Y_PLUS ' '
00031 #endif
00032
00033 #define XMAX 79
00034 #define SCREENMAX (YMAX - 1)
00035 #define XBREAK (XMAX - 0)
00036 #define SHIFT_SIZE 25
00037 #define SHIFT_MARK '!'
00038 #define MAX_CHARS 1024
00039
00040
00041 #define LINE_START (((-MAX_CHARS - 1) / SHIFT_SIZE) * SHIFT_SIZE \
00042 - SHIFT_SIZE)
00043 #define LINE_END (MAX_CHARS + 1)
00044
00045 #define LINE_LEN (XMAX + 1)
00046 #define SCREEN_SIZE (XMAX * YMAX)
00047 #define BLOCK_SIZE 1024
00048
00049
00050 #define ERRORS -1
00051 #define NO_LINE (ERRORS - 1)
00052 #define FINE (ERRORS + 1)
00053 #define NO_INPUT (ERRORS + 2)
00054
00055 #define STD_OUT 1
00056
00057 #if (CHIP == INTEL)
00058 #define MEMORY_SIZE (50 * 1024)
00059 #endif
00060
00061 #define REPORT 2
00062
00063 typedef int FLAG;
00064
00065
00066 #define FALSE 0
00067 #define TRUE 1
00068 #define NOT_VALID 2
00069 #define VALID 3
00070 #define OFF 4
00071 #define ON 5
00072
00073
00074 #define FORWARD 6
00075 #define REVERSE 7
00076
00077
00078 #define SMALLER 8
00079 #define BIGGER 9
00080 #define SAME 10
00081 #define EMPTY 11
00082 #define NO_DELETE 12
00083 #define DELETE 13
00084 #define READ 14
00085 #define WRITE 15
00086
00087
00088
00089
00090
00091
00092 struct Line {
00093 struct Line *next;
00094 struct Line *prev;
00095 char *text;
00096 unsigned char shift_count;
00097 };
00098
00099 typedef struct Line LINE;
00100
00101
00102 #define DUMMY 0x80
00103 #define DUMMY_MASK 0x7F
00104
00105
00106 #define NO_MATCH 0
00107 #define MATCH 1
00108 #define REG_ERROR 2
00109
00110 #define BEGIN_LINE (2 * REG_ERROR)
00111 #define END_LINE (2 * BEGIN_LINE)
00112
00113
00114
00115
00116
00117
00118 struct regex {
00119 union {
00120 char *err_mess;
00121 int *expression;
00122 } result;
00123 char status;
00124 char *start_ptr;
00125 char *end_ptr;
00126 };
00127
00128 typedef struct regex REGEX;
00129
00130
00131 #define NIL_PTR ((char *) 0)
00132 #define NIL_LINE ((LINE *) 0)
00133 #define NIL_REG ((REGEX *) 0)
00134 #define NIL_INT ((int *) 0)
00135
00136
00137
00138
00139 extern int nlines;
00140 extern LINE *header;
00141 extern LINE *tail;
00142 extern LINE *top_line;
00143 extern LINE *bot_line;
00144 extern LINE *cur_line;
00145 extern char *cur_text;
00146 extern int last_y;
00147 extern int ymax;
00148 extern int screenmax;
00149 extern char screen[SCREEN_SIZE];
00150
00151 extern int x, y;
00152 extern FLAG modified;
00153 extern FLAG stat_visible;
00154 extern FLAG writable;
00155 extern FLAG quit;
00156 extern FLAG rpipe;
00157 extern int input_fd;
00158 extern FLAG loading;
00159 extern int out_count;
00160 extern char file_name[LINE_LEN];
00161 extern char text_buffer[MAX_CHARS];
00162 extern char *blank_line;
00163
00164 extern char yank_file[];
00165 extern FLAG yank_status;
00166 extern long chars_saved;
00167
00168
00169
00170
00171 #define clear_buffer() (out_count = 0)
00172
00173
00174
00175
00176 #define putchar(c) (void) write_char(STD_OUT, (c))
00177
00178
00179
00180
00181 #define ring_bell() putchar('\07')
00182
00183
00184
00185
00186 #define string_print(str) (void) writeline(STD_OUT, (str))
00187
00188
00189
00190
00191 #define flush() (void) flush_buffer(STD_OUT)
00192
00193
00194
00195
00196 #define tab(cnt) (((cnt) + 8) & ~07)
00197 #define is_tab(c) ((c) == '\t')
00198
00199
00200
00201
00202 #define white_space(c) ((c) == ' ' || (c) == '\t')
00203 #define alpha(c) ((c) != ' ' && (c) != '\t' && (c) != '\n')
00204
00205
00206
00207
00208 #define line_print(line) put_line(line, 0, TRUE)
00209
00210
00211
00212
00213 #define move_to(nx, ny) move((nx), NIL_PTR, (ny))
00214
00215
00216
00217
00218 #define move_address(address) move(0, (address), y)
00219
00220
00221
00222
00223 #define status_line(str1, str2) (void) bottom_line(ON, (str1), \
00224 (str2), NIL_PTR, FALSE)
00225 #define error(str1, str2) (void) bottom_line(ON, (str1), \
00226 (str2), NIL_PTR, FALSE)
00227 #define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
00228 #define clear_status() (void) bottom_line(OFF, NIL_PTR, NIL_PTR, \
00229 NIL_PTR, FALSE)
00230
00231
00232
00233
00234 #define fstatus(mess, cnt) file_status((mess), (cnt), file_name, \
00235 nlines, writable, modified)
00236
00237
00238
00239
00240 #define get_shift(cnt) ((cnt) & DUMMY_MASK)
00241
00242 #endif
00243
00244
00245
00246 _PROTOTYPE(void FS, (void));
00247 _PROTOTYPE(void VI, (void));
00248 _PROTOTYPE(int WT, (void));
00249 _PROTOTYPE(void XWT, (void));
00250 _PROTOTYPE(void SH, (void));
00251 _PROTOTYPE(LINE *proceed, (LINE *line, int count ));
00252 _PROTOTYPE(int bottom_line, (FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl ));
00253 _PROTOTYPE(int count_chars, (LINE *line ));
00254 _PROTOTYPE(void move, (int new_x, char *new_address, int new_y ));
00255 _PROTOTYPE(int find_x, (LINE *line, char *address ));
00256 _PROTOTYPE(char *find_address, (LINE *line, int x_coord, int *old_x ));
00257 _PROTOTYPE(int length_of, (char *string ));
00258 _PROTOTYPE(void copy_string, (char *to, char *from ));
00259 _PROTOTYPE(void reset, (LINE *head_line, int screen_y ));
00260 _PROTOTYPE(void set_cursor, (int nx, int ny ));
00261 _PROTOTYPE(void open_device, (void));
00262 _PROTOTYPE(int getchar, (void));
00263 _PROTOTYPE(void display, (int x_coord, int y_coord, LINE *line, int count ));
00264 _PROTOTYPE(int write_char, (int fd, int c ));
00265 _PROTOTYPE(int writeline, (int fd, char *text ));
00266 _PROTOTYPE(void put_line, (LINE *line, int offset, FLAG clear_line ));
00267 _PROTOTYPE(int flush_buffer, (int fd ));
00268 _PROTOTYPE(void bad_write, (int fd ));
00269 _PROTOTYPE(void catch, (int sig ));
00270 _PROTOTYPE(void abort_mined, (void));
00271 _PROTOTYPE(void raw_mode, (FLAG state ));
00272 _PROTOTYPE(void panic, (char *message ));
00273 _PROTOTYPE(char *alloc, (int bytes ));
00274 _PROTOTYPE(void free_space, (char *p ));
00275
00276
00277
00278
00279
00280
00281
00282 _PROTOTYPE(void initialize, (void));
00283 _PROTOTYPE(char *basename, (char *path ));
00284 _PROTOTYPE(void load_file, (char *file ));
00285 _PROTOTYPE(int get_line, (int fd, char *buffer ));
00286 _PROTOTYPE(LINE *install_line, (char *buffer, int length ));
00287 _PROTOTYPE(void main, (int argc, char *argv []));
00288 _PROTOTYPE(void RD, (void));
00289 _PROTOTYPE(void I, (void));
00290 _PROTOTYPE(void XT, (void));
00291 _PROTOTYPE(void ESC, (void));
00292 _PROTOTYPE(int ask_save, (void));
00293 _PROTOTYPE(int line_number, (void));
00294 _PROTOTYPE(void file_status, (char *message, long count, char *file, int lines,
00295 FLAG writefl, FLAG changed ));
00296 #if __STDC__
00297 void build_string(char *buf, char *fmt, ...);
00298 #else
00299 void build_string();
00300 #endif
00301 _PROTOTYPE(char *num_out, (long number ));
00302 _PROTOTYPE(int get_number, (char *message, int *result ));
00303 _PROTOTYPE(int input, (char *inbuf, FLAG clearfl ));
00304 _PROTOTYPE(int get_file, (char *message, char *file ));
00305 _PROTOTYPE(int _getchar, (void));
00306 _PROTOTYPE(void _flush, (void));
00307 _PROTOTYPE(void _putchar, (int c ));
00308 _PROTOTYPE(void get_term, (void));
00309
00310
00311
00312 _PROTOTYPE(void UP, (void));
00313 _PROTOTYPE(void DN, (void));
00314 _PROTOTYPE(void LF, (void));
00315 _PROTOTYPE(void RT, (void));
00316 _PROTOTYPE(void HIGH, (void));
00317 _PROTOTYPE(void LOW, (void));
00318 _PROTOTYPE(void BL, (void));
00319 _PROTOTYPE(void EL, (void));
00320 _PROTOTYPE(void GOTO, (void));
00321 _PROTOTYPE(void PD, (void));
00322 _PROTOTYPE(void PU, (void));
00323 _PROTOTYPE(void HO, (void));
00324 _PROTOTYPE(void EF, (void));
00325 _PROTOTYPE(void SU, (void));
00326 _PROTOTYPE(void SD, (void));
00327 _PROTOTYPE(int forward_scroll, (void));
00328 _PROTOTYPE(int reverse_scroll, (void));
00329 _PROTOTYPE(void MP, (void));
00330 _PROTOTYPE(void move_previous_word, (FLAG remove ));
00331 _PROTOTYPE(void MN, (void));
00332 _PROTOTYPE(void move_next_word, (FLAG remove ));
00333 _PROTOTYPE(void DCC, (void));
00334 _PROTOTYPE(void DPC, (void));
00335 _PROTOTYPE(void DLN, (void));
00336 _PROTOTYPE(void DNW, (void));
00337 _PROTOTYPE(void DPW, (void));
00338 _PROTOTYPE(void S, (int character ));
00339 _PROTOTYPE(void CTL, (void));
00340 _PROTOTYPE(void LIB, (void));
00341 _PROTOTYPE(LINE *line_insert, (LINE *line, char *string, int len ));
00342 _PROTOTYPE(int insert, (LINE *line, char *location, char *string ));
00343 _PROTOTYPE(LINE *line_delete, (LINE *line ));
00344 _PROTOTYPE(void delete, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp ));
00345 _PROTOTYPE(void PT, (void));
00346 _PROTOTYPE(void IF, (void));
00347 _PROTOTYPE(void file_insert, (int fd, FLAG old_pos ));
00348 _PROTOTYPE(void WB, (void));
00349 _PROTOTYPE(void MA, (void));
00350 _PROTOTYPE(void YA, (void));
00351 _PROTOTYPE(void DT, (void));
00352 _PROTOTYPE(void set_up, (FLAG remove ));
00353 _PROTOTYPE(FLAG checkmark, (void));
00354 _PROTOTYPE(int legal, (void));
00355 _PROTOTYPE(void yank, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp, FLAG remove ));
00356 _PROTOTYPE(int scratch_file, (FLAG mode ));
00357 _PROTOTYPE(void SF, (void));
00358 _PROTOTYPE(void SR, (void));
00359 _PROTOTYPE(REGEX *get_expression, (char *message ));
00360 _PROTOTYPE(void GR, (void));
00361 _PROTOTYPE(void LR, (void));
00362 _PROTOTYPE(void change, (char *message, FLAG file ));
00363 _PROTOTYPE(char *substitute, (LINE *line, REGEX *program, char *replacement ));
00364 _PROTOTYPE(void search, (char *message, FLAG method ));
00365 _PROTOTYPE(int find_y, (LINE *match_line ));
00366 _PROTOTYPE(void finished, (REGEX *program, int *last_exp ));
00367 _PROTOTYPE(void compile, (char *pattern, REGEX *program ));
00368 _PROTOTYPE(LINE *match, (REGEX *program, char *string, FLAG method ));
00369 _PROTOTYPE(int line_check, (REGEX *program, char *string, FLAG method ));
00370 _PROTOTYPE(int check_string, (REGEX *program, char *string, int *expression ));
00371 _PROTOTYPE(int star, (REGEX *program, char *end_position, char *string, int *expression ));
00372 _PROTOTYPE(int in_list, (int *list, int c, int list_length, int opcode ));
00373 _PROTOTYPE(void dummy_line, (void));