1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
/*
* $Date: 2007/12/10 22:13:07 $
* $Source: /cvsroot/videoteco/videoteco/teco.h,v $
* $Revision: 1.2 $
* $Locker: $
*/
/**
* \file teco.h
* \brief Global TECO Definitions
*/
/*
* COPYRIGHT (c) 1985-2007 BY Paul Cantrell
*
* Copyright (C) <year> <name of author>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define YES 1
#define NO 0
#define FAIL 0
#define SUCCESS 1
#if 0
#define CREATE_OLD_FILES /**< Create \c .OLD backup files */
#endif
#define BLOCKED 2
#define INVALIDATE 3
#define VMAJOR 7
#define VMINOR 0
#define AUTO_DATE "$Date: 2007/12/10 22:13:07 $"
#define TECO_FILENAME_TOTAL_LENGTH 1024
#define TECO_FILENAME_COMPONENT_LENGTH 256
#define TECO_READONLY_NAME "visit"
#define TECO_INTERNAL_BUFFER_NAME "TECO-"
#define TERMCAP_BUFFER_SIZE 2048
#define SCREEN_OUTPUT_BUFFER_SIZE 4096
#define SCREEN_RESERVED_LINES 2
#define SCREEN_MAX_LABEL_FIELDS 4
#define SCREEN_NOMINAL_LINE_WIDTH 132
#define SCREEN_MAX_LINES 1024
#define SCREEN_MINIMUM_WINDOW_HEIGHT 4
#define IO_BUFFER_SIZE 512
#define LINE_BUFFER_SIZE 1024
#define DEFAULT_CHECKPOINT (5*60)
#define TAG_HASH_ENTRIES 1024
#if defined(MSDOS) && !defined(__HUGE__)
/* make sure that all variables fit into 64kb */
#define PARSER_STRING_MAX 512
#else
#define PARSER_STRING_MAX 1024
#endif
#define SEARCH_STRING_MAX PARSER_STRING_MAX
#define NORMAL_TAB_WIDTH 8
#define MAX_TAB_WIDTH 16
#define MAXOF( a,b) (a) > (b) ? (a) : (b)
#define INITIAL_LINE_BUFFER_SIZE 32
#define INCREMENTAL_LINE_BUFFER_SIZE 32
#define MINIMUM_ALLOCATION_BLOCK 32
#if defined(MSDOS) && !defined(__HUGE__)
/*
* FIXME: The lookaside mechanism needs to be revised.
* It has been disabled, so that all tec_alloc() are
* more or less directly passed to malloc().
*/
#define LOOKASIDE_COUNT 1
#define LARGEST_LOOKASIDE_BLOCK 0
#else
#define LOOKASIDE_COUNT 32
#define LARGEST_LOOKASIDE_BLOCK (LOOKASIDE_COUNT * MINIMUM_ALLOCATION_BLOCK)
#endif
#define BIG_MALLOC_HUNK_SIZE (LARGEST_LOOKASIDE_BLOCK * 64)
#define NORMAL_TAB_WIDTH 8
/*
* The following is where the different machines are described so that
* conditional compilation based on different machines quirks can be done.
*/
#ifndef BITS_PER_CHAR
/**
* Unless defined otherwise, we assume 8 bits / char
*/
#define BITS_PER_CHAR 8
#endif
#ifndef BITS_PER_INT
#define BITS_PER_INT (BITS_PER_CHAR * (int)sizeof(int))
#endif
#define ESCAPE 27
#define RUBOUT 127
#define CNTRL_A 1
#define CNTRL_D 4
#define CNTRL_E 5
#define CNTRL_G 7
#define CNTRL_N 14
#define CNTRL_R 18
#define CNTRL_U 21
#define CNTRL_V 22
#define CNTRL_W 23
#define CNTRL_X 24
#define CNTRL_Z 26
#define BELL 7
/*
* Define memory allocation block types
*/
#define TYPE_C_MINTYPE 33
#define TYPE_C_CBUFF 33
#define TYPE_C_CPERM 34
#define TYPE_C_CMD 35
#define TYPE_C_UNDO 36
#define TYPE_C_SCR 37
#define TYPE_C_SCRBUF 38
#define TYPE_C_SCREEN 39
#define TYPE_C_SCREENBUF 40
#define TYPE_C_LINE 41
#define TYPE_C_LINEBUF 42
#define TYPE_C_BHDR 43
#define TYPE_C_WINDOW 44
#define TYPE_C_LABELFIELD 45
#define TYPE_C_WILD 46
#define TYPE_C_TAGS 47
#define TYPE_C_TAGENT 48
#define TYPE_C_TAGSTR 49
#define TYPE_C_MAXTYPE 49
#define MAGIC_SCREEN ((int)0x01010101)
#define MAGIC_BUFFER ((int)0x02020202)
#define MAGIC_LINE ((int)0x03030303)
#define MAGIC_LINE_LOOKASIDE ((int)0x04040404)
#define MAGIC_FORMAT ((int)0x05050505)
#define MAGIC_FORMAT_LOOKASIDE ((int)0x06060606)
#ifdef DEBUG1
void do_preamble_checks(void);
void do_return_checks(void);
#define PREAMBLE() \
do_preamble_checks();
#define RETURN \
do_return_checks(); \
return;
#define RETURN_VAL(val) \
do_return_checks(); \
return(val);
#else
#define PREAMBLE()
#define RETURN
#define RETURN_VAL()
#endif /* DEBUG1 */
#define ELEMENTS(xyzzy) (sizeof(xyzzy)/sizeof(xyzzy[0]))
/*
* Define structures used throughout TECO
*/
struct position_cache {
struct buff_line *lbp;
int base;
};
#define BUFF_CACHE_CONTENTS(pos_cache) \
(pos_cache)->lbp->buffer[(pos_cache)->base]
#define BUFF_INCREMENT_CACHE_POSITION(pos_cache) \
if(++((pos_cache)->base) >= (pos_cache)->lbp->byte_count){ \
(pos_cache)->lbp = (pos_cache)->lbp->next_line; (pos_cache)->base = 0; \
}
#define BUFF_DECREMENT_CACHE_POSITION(pos_cache) \
{ \
if((pos_cache)->base == 0){ \
(pos_cache)->lbp = (pos_cache)->lbp->prev_line; \
(pos_cache)->base = (pos_cache)->lbp->byte_count; \
} \
(pos_cache)->base -= 1; \
}
struct buff_header {
int buf_magic;
unsigned int buf_hash;
char *name;
int buffer_number;
struct buff_header *next_header;
char ismodified;
char isreadonly;
char isbackedup;
int dot;
int zee;
int ivalue;
struct position_cache pos_cache;
struct buff_line *first_line;
};
struct buff_line {
int lin_magic;
int buffer_size;
int byte_count;
char *buffer;
struct buff_line *next_line;
struct buff_line *prev_line;
struct format_line *format_line;
};
struct format_line {
int fmt_magic;
struct buff_header *fmt_owning_buffer;
struct buff_line *fmt_buffer_line;
int fmt_buffer_size;
short *fmt_buffer;
int fmt_sequence;
struct format_line *fmt_next_line;
struct format_line *fmt_prev_line;
struct format_line *fmt_next_alloc;
struct format_line *fmt_prev_alloc;
struct format_line *fmt_next_window;
struct format_line *fmt_prev_window;
char fmt_in_use;
char fmt_permanent;
struct screen_line *fmt_saved_line;
short fmt_visible_line_position;
struct window *fmt_window_ptr;
};
struct screen_line {
int scr_magic;
short *buffer;
struct format_line *companion;
int sequence;
};
struct window {
struct window *win_next_window;
int win_window_number;
int win_x_size;
int win_y_size;
int win_y_base;
int win_y_end;
struct buff_header *win_buffer;
struct format_line win_label_line;
struct format_line *win_dot_format_line;
int win_dot_screen_offset;
char *win_label_field_contents[SCREEN_MAX_LABEL_FIELDS];
};
struct search_element {
unsigned char type;
unsigned char value;
union {
int intarray[256/BITS_PER_INT];
char bytearray[256/BITS_PER_CHAR];
}bitmask;
union {
int intarray[256/BITS_PER_INT];
char bytearray[256/BITS_PER_CHAR];
}repmask;
};
struct search_buff {
int length;
char input[PARSER_STRING_MAX];
struct search_element data[PARSER_STRING_MAX];
char error_message_given;
};
struct wildcard_expansion {
struct wildcard_expansion *we_next;
char we_name[TECO_FILENAME_TOTAL_LENGTH-4];
};
struct tagent {
char *te_symbol;
char *te_filename;
char *te_lineno;
char *te_search_string;
struct tagent *te_next;
};
struct tags {
struct tagent *current_entry;
struct tagent *tagents[TAG_HASH_ENTRIES];
};
/*
* Define the various flags in a screen display short int
*/
#define SCREEN_M_DATA 0x00FF
#define SCREEN_M_FLAGS 0xFF00
#define SCREEN_M_REVERSE 0x0100
/*
* Define constants for the label line fields
*/
#define LABEL_C_TECONAME 0
#define LABEL_C_FILENAME 1
#define LABEL_C_READONLY 2
#define LABEL_C_MODIFIED 3
/*
* Define constants for EJ command
*/
#define SETOPTION_MIN_OPTION 1
#define SETOPTION_ALTERNATE_ESCAPE_CHAR 1
#define SETOPTION_SCREEN_HEIGHT 2
#define SETOPTION_SCREEN_WIDTH 3
#define SETOPTION_ALTERNATE_DELETE_CHAR 4
#define SETOPTION_FORCE_8_BIT_CHARS 5
#define SETOPTION_TAB_WIDTH 6
#define SETOPTION_HIDE_CR_CHARS 7
#define SETOPTION_MAX_OPTION 7
/*
* Define constants for FT command
*/
#define TAGS_MIN_OPTION 0
#define TAGS_LOAD_TAGS_FILE 0
#define TAGS_SEARCH_TAGS_FILE 1
#define TAGS_TEST_FOR_LOADED_TAGS 2
#define TAGS_INSERT_TARGET_FILE 3
#define TAGS_INSERT_SEARCH_STRING 4
#define TAGS_INSERT_LINENO 5
#define TAGS_INSERT_ALL 6
#define TAGS_MAX_OPTION 6
/*
* Define useful macros
*/
#define UPCASE(char) (islower(char) ? TOUPPER(char) : char)
#ifdef SYS_III_UNIX
#define TOUPPER(char) _toupper(char)
#define TOLOWER(char) _tolower(char)
#else
#define TOUPPER(char) toupper(char)
#define TOLOWER(char) tolower(char)
#endif
typedef unsigned long teco_ptrint_t;
/**
* We define unix except for the really different operating systems, like
* vms. It lets us write our own version of functions which simply do not
* exist outside of unix.
*/
#if !defined(VMS) && !defined(MSDOS)
#define UNIX
#define JOB_CONTROL
#endif
/*
* Include Files From GNU Autoconf/Autoheader
*
* FIXME: The Autoconf build system does not pass down -DHAVE_CONFIG_H.
* This should be fixed by rewriting it as the original sources
* are missing.
*/
//#ifdef HAVE_CONFIG_H
#ifndef __WATCOMC__
#include "config.h"
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
/*
* sys/filio.h has the FIONREAD definition
*/
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#ifdef FIONREAD
#define HAS_FIONREAD
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#if HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#else
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif
#if HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
# if !HAVE_STRCHR
# if !defined(strchr)
# define strchr index
# endif
# if !defined(strrchr)
# define strrchr rindex
# endif
# endif
#endif
/* on SGI this gets us BZERO */
#if HAVE_STRINGS_H
#include <strings.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#else
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_DIRENT_H
#include <dirent.h>
#define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#define dirent direct
#define NAMLEN(dirent) (dirent)->d_namlen
#if HAVE_SYS_NDIR_H
#include <sys/ndir.h>
#endif
#if HAVE_SYS_DIR_H
#include <sys/dir.h>
#endif
#if HAVE_NDIR_H
#include <ndir.h>
#endif
#endif
#if HAVE_DIRECT_H
#include <direct.h>
#endif
#if HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
#if GWINSZ_IN_SYS_IOCTL
# include <sys/ioctl.h>
#define SUN_STYLE_WINDOW_SIZING 1
#else
#if HAVE_TERMIOS_H
# include <termios.h>
#define SUN_STYLE_WINDOW_SIZING 1
#endif
#endif
#if HAVE_TERMIO_H
# include <termio.h>
#endif
#if HAVE_IO_H
#include <io.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if !defined(HAVE_TERMIO_H) && !defined(HAVE_TERMIOS_H)
#if HAVE_SGTTY_H
#include <sgtty.h>
#endif
#endif
#if HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#if HAVE_STDIO_H
#include <stdio.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#if HAVE_PWD_H
#include <pwd.h>
#endif
#if HAVE_TERMCAP_H
#include <termcap.h>
#endif
/* current end of autoconf stuff*/
#if HAVE_LIBTERMCAP
#define TERMCAP
#else
#if defined(HAVE_LIBTERMINFO)
#define TERMINFO
#endif
#endif
#if !defined(TERMCAP) && !defined(TERMINFO)
#if defined(HAVE_LIBNCURSES)
#define TERMINFO
#endif
#endif
/* we prefer select over poll */
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#define HAS_SELECT
#else
#if HAVE_POLL_H
#include <poll.h>
#define HAS_POLL
#endif
#endif
/*
* Digital Equpment VMS Operating System
*/
#ifdef VMS
#include "tecvms.h"
#endif
#ifndef CAUSE_BUS_ERROR
#define CAUSE_BUS_ERROR() \
{ \
int fake_destination; \
fake_destination = *((int *)(0x0FFFFFFF)); \
(void)fake_destination; \
}
#endif
#ifdef MSDOS
#include <conio.h>
#endif
/* method declarations */
void error_message(char * string);
void tec_release(unsigned char type, char *addr);
void tec_panic( char *string);
int buff_switch(struct buff_header *hbp,int map_flag);
int buff_read(struct buff_header *hbp,char *name);
int buff_readfd(struct buff_header *hbp,char *name,int iochan);
int buff_insert(struct buff_header *hbp,int position,char *buffer,int length);
int screen_label_line(struct buff_header *buffer,char *string,int field);
int buff_write(struct buff_header *hbp,int chan,int start,int end);
void tecmem_stats(void);
void screen_free_format_lines(struct format_line *sbp);
int buff_delete_char(struct buff_header *hbp,int position);
int compile_search_string(struct search_buff *search_tbl);
int cmd_forward_search(int pos1,int pos2,struct search_buff *search_tbl);
int cmd_reverse_search(int pos1,int pos2,struct search_buff *search_tbl);
int buff_cached_contents(struct buff_header *,int,struct position_cache *);
int buff_contents(struct buff_header *hbp,int position);
void pause_while_in_input_wait(void);
void restore_tty(void);
void initialize_tty(void);
void screen_redraw(void);
void screen_resize(void);
void screen_refresh(void);
void screen_message(char *string);
int tty_input_pending(void);
void screen_format_windows(void);
void load_qname_register(void);
void buff_delete(struct buff_header *,int,int);
void screen_reformat_windows(void);
int tag_calc_hash(char *string);
void tag_free_struct(struct tags *tp);
void tecdebug_check_screen_magic(void);
void tecdebug_check_buffer_magic(void);
void tecdebug_check_line_magic(void);
void tecdebug_check_format_magic(void);
void tecdebug_check_companion_pointers(void);
void tecdebug_check_window_pointers(void);
void term_init(void);
int term_goto( int dest_x,int dest_y);
void term_clrtobot(void);
void parser_reset_echo(void);
void term_finish(void);
void term_standend(void);
void term_clrtoeol(void);
void term_standout(void);
void screen_save_current_message(char *,int);
int window_switch(int window_number);
void screen_delete_window( struct window *old_wptr);
void buff_reopenbuff(struct buff_header *bp);
void buff_free_line_buffer_list(struct buff_line *);
int screen_display_window(struct window *wptr);
int buff_find_offset(struct buff_header *,struct buff_line *,int);
int buff_openbuffnum(int,int);
int parse_illegal_buffer_position(int,int,char *);
int buff_insert_char(struct buff_header *,int,char);
int push_qregister(char);
void buff_bulk_insert(struct buff_header *,int,int,struct buff_line *);
void buff_destroy(struct buff_header *);
int cmd_wordmove(int count);
int cmd_search(int,int,struct search_buff *);
int buff_openbuffer(char *,int,int);
int cmd_write(struct buff_header *,char *);
void screen_scroll(int);
void parser_dump_command_line(struct buff_header *);
int parser_replace_command_line(struct buff_header *);
void tec_gc_lists(void);
void screen_deallocate_format_lookaside_list(void);
void buff_deallocate_line_buffer_lookaside_list(void);
int buff_init(void);
void tec_error(int, char *);
int handle_command_line(int,int,char **);
void tecparse(void);
//void term_putc(char);
int term_putc(int);
void term_flush(void);
int screen_init(void);
void screen_finish(void);
int exec_doq0(void);
void punt(int);
void screen_reset_message(void);
int tecparse_syntax(int);
void screen_echo(char);
void cmd_pause(void);
void cmd_suspend(void);
int term_putnum(char *,int,int);
int term_scroll_region(int,int);
int init_term_description(void);
char *tec_alloc(int,int);
void initialize_memory_stats( void );
struct buff_header *buff_qfind(char,char);
char *error_text(int);
struct buff_line *buff_find_line(struct buff_header *hbp,int);
void term_insert_line(int,int);
void term_delete_line(int,int);
struct buff_header *buff_find(char *);
struct buff_header *buff_duplicate(struct buff_header *);
struct window *screen_split_window(struct window *,int,int);
|