1 /*
2  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
3  * Copyright (C) 1991-2001 Mark Hessling
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to:
17  *
18  *    The Free Software Foundation, Inc.
19  *    675 Mass Ave,
20  *    Cambridge, MA 02139 USA.
21  *
22  *
23  * If you make modifications to this software that you feel increases
24  * it usefulness for the rest of the community, please email the
25  * changes, enhancements, bug fixes as well as any and all ideas to me.
26  * This software is going to be maintained and enhanced as deemed
27  * necessary by the community.
28  *
29  * Mark Hessling,  M.Hessling@qut.edu.au  http://www.lightlink.com/hessling/
30  */
31 
32 /*
33 $Id: the.h,v 1.81 2013/11/08 06:48:26 mark Exp $
34 */
35 
36 #include "thedefs.h"
37 /*
38  * Handle Win32 console when using PDCurses GUI
39  */
40 #if defined(USE_WINGUICURSES)
41 # include <windows.h>
42 # undef MOUSE_MOVED
43 extern int gotOutput;
44 extern void StartupConsole( void );
45 extern void ClosedownConsole( void );
46 # define STARTUPCONSOLE() StartupConsole()
47 # define CLOSEDOWNCONSOLE() ClosedownConsole()
48 #else
49 # define STARTUPCONSOLE()
50 # define CLOSEDOWNCONSOLE()
51 #endif
52 
53 #if defined(USE_XCURSES)
54 #  define XCURSES
55 #  include <xcurses.h>
56 #  define CURSES_H_INCLUDED
57 #endif
58 
59 #if defined(USE_NCURSES)
60 # if defined(USE_UTF8)
61 #  define _XOPEN_SOURCE_EXTENDED
62 #  include <ncursesw/ncurses.h>
63 # else
64 #  include <ncurses.h>
65 # endif
66 # define CURSES_H_INCLUDED
67 #endif
68 
69 #if defined(USE_EXTCURSES)
70 #  include <cur00.h>
71 #  define A_COLOR
72 #  define COLOR_BLACK   0
73 #  define COLOR_BLUE    1
74 #  define COLOR_GREEN   2
75 #  define COLOR_CYAN    3
76 #  define COLOR_RED     4
77 #  define COLOR_MAGENTA 5
78 #  define COLOR_YELLOW  6
79 #  define COLOR_WHITE   7
80    typedef char bool;
81 #  ifdef chtype
82 #    undef chtype
83 #  endif
84 #  define chtype NLSCHAR
85 #  define COLORS       8
86 #  define COLOR_PAIRS 64
87    extern chtype color_pair[COLOR_PAIRS];
88 #  define COLOR_PAIR(n) color_pair[n]
89 #  ifndef HAVE_WATTRSET
90 #    define HAVE_WATTRSET
91 #    define wattrset(win,attr) xstandout(win,attr)
92 #    define attrset(attr) xstandout(stdscr,attr)
93 #  endif
94 #  ifndef HAVE_NOCBREAK
95 #    define HAVE_NOCBREAK
96 #    define nocbreak() nocrmode()
97 #  endif
98 #  ifndef HAVE_CBREAK
99 #    define HAVE_CBREAK
100 #    define cbreak() crmode()
101 #  endif
102 #  define CURSES_H_INCLUDED
103 #endif
104 
105 #ifndef CURSES_H_INCLUDED
106 #  include <curses.h>
107 #endif
108 
109 #ifdef HAVE_PROTO
110 # define Args(a) a
111 #else
112 # define Args(a) ()
113 #endif
114 
115 /*
116  * The following required because IBM AIX 4.3 defines curses colors
117  * incorrectly :-(
118  */
119 #if defined(HAVE_BROKEN_COLORS)
120 # undef COLOR_BLACK
121 # undef COLOR_BLUE
122 # undef COLOR_GREEN
123 # undef COLOR_CYAN
124 # undef COLOR_RED
125 # undef COLOR_MAGENTA
126 # undef COLOR_YELLOW
127 # undef COLOR_WHITE
128 # define COLOR_BLACK    0
129 # define COLOR_BLUE     1
130 # define COLOR_GREEN    2
131 # define COLOR_CYAN     3
132 # define COLOR_RED      4
133 # define COLOR_MAGENTA  5
134 # define COLOR_YELLOW   6
135 # define COLOR_WHITE    7
136 #endif
137 
138 #if defined(__OS2__)
139 #  if defined(MSDOS) && defined(EMX)
140 #     undef __OS2__
141 #     if !defined(DOS)
142 #        define DOS
143 #     endif
144 #     if defined(OS2)
145 #        undef OS2
146 #     endif
147 #  else
148 #     undef MSDOS          /* in case you are using MSC 6.0 for OS/2 */
149 #     define INCL_VIO
150 #     include <os2.h>
151 #  endif
152 #  include <stdlib.h>
153 #  include <memory.h>
154 #  include <string.h>
155 #  include <process.h>
156 #  include <errno.h>
157 #  include <ctype.h>
158 #  include <fcntl.h>
159 #  include <io.h>
160 #  include <sys\types.h>
161 #  include <sys\stat.h>
162 #  define ESLASH '\\'
163 #  define ESTR_SLASH (CHARTYPE *)"\\"
164 #  if defined(EMX)
165 #    define OSLASH '\\'
166 #    define OSTR_SLASH (CHARTYPE *)"\\"
167 #    define ISLASH '/'
168 #    define ISTR_SLASH (CHARTYPE *)"/"
169 #    define HAVE_BROKEN_TMPNAM 1
170 #  else
171 #    define OSLASH '/'
172 #    define OSTR_SLASH (CHARTYPE *)"/"
173 #    define ISLASH '\\'
174 #    define ISTR_SLASH (CHARTYPE *)"\\"
175 #  endif
176 #  define CURRENT_DIR (CHARTYPE *)"."
177 #  if defined(MSC)
178 /* the following 2 defines are to make MSC recognise the new names */
179 /* of the following OS/2 calls */
180 #    define DosSetDefaultDisk DosSelectDisk
181 #    define DosQueryCurrentDisk DosQCurDisk
182 #  endif
183 #  if defined(__PDCURSES__)
184 #    if PDC_BUILD >= 3000
185 #      define HAVE_CURSES_VERSION 1
186 #    endif
187 #  endif
188 /* the following #define is to eliminate need for the getch.c/getch.h */
189 /* modules in the OS/2 compilation */
190 #  define my_getch(win)  wgetch(win)
191 #endif
192 
193 #if defined(__MSDOS__) || defined(MSDOS)
194 #  include <stdlib.h>
195 #  include <memory.h>
196 #  include <string.h>
197 #  include <fcntl.h>
198 #  include <io.h>
199 #  if defined(GO32)
200 #    include <dir.h>
201 #  else
202 #    include <process.h>
203 #    if !defined(EMX)
204 #      include <direct.h>
205 #    endif
206 #  endif
207 #  include <errno.h>
208 #  include <io.h>
209 #  include <ctype.h>
210 #  include <sys\types.h>
211 #  include <sys\stat.h>
212 #  define ESLASH '\\'
213 #  define ESTR_SLASH (CHARTYPE *)"\\"
214 #  if defined(GO32) || defined(EMX)
215 #    define OSLASH '\\'
216 #    define OSTR_SLASH (CHARTYPE *)"\\"
217 #    define ISLASH '/'
218 #    define ISTR_SLASH (CHARTYPE *)"/"
219 #  else
220 #    define OSLASH '/'
221 #    define OSTR_SLASH (CHARTYPE *)"/"
222 #    define ISLASH '\\'
223 #    define ISTR_SLASH (CHARTYPE *)"\\"
224 #  endif
225 #  if defined(__TURBOC__) || defined(MSC)
226 #    define HAVE_BROKEN_TMPNAM 1
227 #  endif
228 #  define CURRENT_DIR (CHARTYPE *)"."
229 #  if defined(__PDCURSES__)
230 #    if PDC_BUILD >= 3000
231 #      define HAVE_CURSES_VERSION 1
232 #    endif
233 #  endif
234 /* the following #define is to eliminate need for the getch.c/getch.h */
235 /* modules in the DOS compilation */
236 #  define my_getch(win)  wgetch(win)
237 #endif
238 
239 #if (defined(__NT__) || defined(WIN32) ) && !defined(__CYGWIN32__)
240 #  include <stdlib.h>
241 #  include <memory.h>
242 #  include <string.h>
243 #  include <process.h>
244 #  include <errno.h>
245 #  include <ctype.h>
246 #  include <wctype.h>
247 #  include <fcntl.h>
248 #  include <io.h>
249 #  include <direct.h>
250 #  include <sys\types.h>
251 #  include <sys\stat.h>
252 #  define ESLASH '\\'
253 #  define ESTR_SLASH (CHARTYPE *)"\\"
254 #  define OSLASH '/'
255 #  define OSTR_SLASH (CHARTYPE *)"/"
256 #  define ISLASH '\\'
257 #  define ISTR_SLASH (CHARTYPE *)"\\"
258 #  if defined(__WATCOMC__)
259 #    define HAVE_BROKEN_TMPNAM 1
260 #    define HAVE_TIME_H 1
261 #    include <dos.h>     /* may exist under other flavours, too */
262 #  endif
263 #  define CURRENT_DIR (CHARTYPE *)"."
264 #  define CAN_RESIZE 1
265 /* the following #define is to eliminate need for the getch.c/getch.h */
266 /* modules in the WIN32 compilation */
267 #  define my_getch(win)  wgetch(win)
268 #  if defined(__PDCURSES__)
269 #    define PDCURSES_MOUSE_ENABLED 1
270 #    if PDC_BUILD >= 3000
271 #      define HAVE_CURSES_VERSION 1
272 #    endif
273 #  endif
274 #endif
275 
276 #if defined(__CYGWIN32__) && defined(USE_PDCURSES)
277 /* the following #define is to eliminate need for the getch.c/getch.h */
278 /* modules in the DOS compilation */
279 #  define my_getch(win)  wgetch(win)
280 #endif
281 
282 #if defined(AMIGA) && defined(GCC)
283 #  include <stdlib.h>
284 #  include <memory.h>
285 #  include <string.h>
286 #  include <errno.h>
287 #  include <ctype.h>
288 #  include <fcntl.h>
289 #  include <sys/types.h>
290 #  include <sys/stat.h>
291 #  define ESLASH '/'
292 #  define ESTR_SLASH (CHARTYPE *)"/"
293 #  define OSLASH '/'
294 #  define OSTR_SLASH (CHARTYPE *)"/"
295 #  define ISLASH '/'
296 #  define ISTR_SLASH (CHARTYPE *)"/"
297 #  define CURRENT_DIR (CHARTYPE *)"."
298 /* #  define CAN_RESIZE 1 */
299 #endif
300 
301 #ifdef HAVE_CONFIG_H
302 # ifndef HAVE_WATTRSET
303 #  define wattrset(win,attr) ((attr == A_NORMAL) ? wstandend(win) : wstandout(win))
304 #  define attrset(attr)      wattrset(stdscr,attr)
305 # endif
306 # ifndef HAVE_KEYPAD
307 #  define keypad(win,bf)
308 # endif
309 # ifndef HAVE_NOTIMEOUT
310 #  define notimeout(win,bf)
311 # endif
312 # ifndef HAVE_RAW
313 #  define raw()
314 # endif
315 # ifndef HAVE_NOCBREAK
316 #  define nocbreak()
317 # endif
318 # ifndef HAVE_CBREAK
319 #  define cbreak()
320 # endif
321 # ifndef HAVE_WNOUTREFRESH
322 #  define wnoutrefresh(win) wrefresh(win)
323 # endif
324 # ifndef HAVE_TOUCHLINE
325 #  define touchline(win,start,num) touchwin(win)
326 # endif
327 # ifndef HAVE_RESET_SHELL_MODE
328 #  define reset_shell_mode()
329 # endif
330 # ifndef HAVE_RESET_PROG_MODE
331 #  define reset_prog_mode()
332 # endif
333 #endif
334 
335 #ifdef M_XENIX
336 #  define UNIX 1
337 #endif
338 
339 #ifdef MINIX
340 #  define short int
341 #  define UNIX 1
342 #endif
343 
344 #if defined(UNIX) || defined(VMS)
345 #  define ESLASH '/'
346 #  define ESTR_SLASH (CHARTYPE *)"/"
347 #  define OSLASH '\\'
348 #  define OSTR_SLASH (CHARTYPE *)"\\"
349 #  define ISLASH ESLASH
350 #  define ISTR_SLASH ESTR_SLASH
351 #  define CURRENT_DIR (CHARTYPE *)"."
352 #endif
353 
354 #ifdef VMS
355 # define chtype short
356 #endif
357 
358 #ifdef VMS1
359 #  define ISLASH ']'
360 #  define ISTR_SLASH (CHARTYPE *)"]"
361 #  define OSLASH ISLASH
362 #  define OSTR_SLASH ISTR_SLASH
363 #  define ESLASH ISLASH
364 #  define ESTR_SLASH ISTR_SLASH
365 #  define CURRENT_DIR (CHARTYPE *)"[]"
366 #  ifdef BSD
367 #    define chtype short
368 #    define BSDcurses 1
369 #  endif
370 #  define touchline(WIN,START,NUM)       touchwin(WIN)
371 /* #define isdigit(c)   (_ctype[(c) + 1] & 2)
372 #  define islower(c)   (_ctype[(c) + 1] & 8)
373 #  define isupper(c)   (_ctype[(c) + 1] & 4)*/
374 #  define NO_KEYPAD 1
375 #endif
376 
377 #ifdef HAVE_ERRNO_H
378 # include <errno.h>
379 #endif
380 
381 #ifdef HAVE_CTYPE_H
382 # include <ctype.h>
383 #endif
384 
385 #if defined(HAVE_WCTYPE_H) && defined(DUSE_WIDE_CHAR)
386 # include <wctype.h>
387 #endif
388 
389 #ifdef HAVE_SYS_TYPES_H
390 # include <sys/types.h>
391 #endif
392 
393 #ifdef HAVE_UNISTD_H
394 # include <unistd.h>
395 #endif
396 
397 #ifdef HAVE_STDLIB_H
398 # include <stdlib.h>
399 #endif
400 
401 #ifdef USE_UTF8
402 # include "utf8.h"
403 #endif
404 
405 #if HAVE_ALLOCA_H
406 # include <alloca.h>
407 #endif
408 
409 #if defined(WIN32) && defined(_MSC_VER)
410 # define alloca(x) _alloca(x)
411 #endif
412 
413 /*
414  * The following mess is because some versions of g++ (RedHat 7.1)
415  * cannot compile <string.h> :-(
416  */
417 #ifdef HAVE_BROKEN_CXX_WITH_STRING_H
418 # define MH_SAVE__USE_BSD __USE_BSD
419 # undef __USE_BSD
420 #endif
421 #ifdef HAVE_STRING_H
422 # include <string.h>
423 #endif
424 #ifdef HAVE_BROKEN_CXX_WITH_STRING_H
425 # define __USE_BSD MH_SAVE__USE_BSD
426 # undef MH_SAVE__USE_BSD
427 #endif
428 
429 #ifdef HAVE_SYS_STAT_H
430 # include <sys/stat.h>
431 #endif
432 
433 #ifdef HAVE_SYS_FILE_H
434 # include <sys/file.h>
435 #endif
436 
437 #ifdef HAVE_MEMORY_H
438 # include <memory.h>
439 #endif
440 
441 #ifdef HAVE_FCNTL_H
442 # include <fcntl.h>
443 #endif
444 
445 #ifdef HAVE_LOCALE_H
446 # include <locale.h>
447 #endif
448 
449 #ifdef TIME_WITH_SYS_TIME
450 # ifdef HAVE_TIME_H
451 #  include <time.h>
452 # endif
453 # ifdef HAVE_SYS_TIME_H
454 #  include <sys/time.h>
455 # endif
456 #else
457 # ifdef HAVE_TIME_H
458 #   include <time.h>
459 # else
460 #  ifdef HAVE_SYS_TIME_H
461 #   include <sys/time.h>
462 #  endif
463 # endif
464 #endif
465 
466 #include <signal.h>
467 
468 #include "regex.h"
469 
470 #if defined(USE_XCURSES)
471 #  if defined(SIGWINCH) && defined(HAVE_RESIZE_TERM)
472 #    define CAN_RESIZE
473 #  endif
474 #  define PDCURSES_MOUSE_ENABLED 1
475 /* the following #define is to eliminate need for the getch.c/getch.h */
476 /* modules under XCurses */
477 #  define my_getch(win)  wgetch(win)
478 #endif
479 
480 #if defined(USE_SDLCURSES)
481 #  define CAN_RESIZE
482 #  define PDCURSES_MOUSE_ENABLED 1
483 /* the following #define is to eliminate need for the getch.c/getch.h */
484 /* modules under SDL */
485 #  define my_getch(win)  wgetch(win)
486 #endif
487 
488 #if defined(USE_NCURSES) && defined(SIGWINCH) && defined(HAVE_RESIZETERM)
489 #  define CAN_RESIZE
490 #endif
491 
492 #if defined(HAVE_SLK_INIT)
493 # if defined(__PDCURSES__)
494 #  define MAX_SLK    12
495 #  define MAX_SLK_FORMAT 5
496 # elif defined(USE_NCURSES)
497 #  define MAX_SLK    12
498 #  define MAX_SLK_FORMAT 4
499 # else
500 #  define MAX_SLK     8
501 #  define MAX_SLK_FORMAT 2
502 # endif
503 #else
504 # define MAX_SLK      0
505 # define MAX_SLK_FORMAT 2
506 #endif
507 
508 #ifndef F_OK
509 #  define         F_OK          00
510 #endif
511 #ifndef W_OK
512 #  define         W_OK          02
513 #endif
514 #ifndef R_OK
515 #  define         R_OK          04
516 #endif
517 /*---------------------------------------------------------------------*/
518 /* End of OS-specific defines                                          */
519 /*---------------------------------------------------------------------*/
520 /*
521  * This define ensures that any changes in the configure
522  * cause the user to have to re-run configure.
523  * This is set in defines.h or config.h
524  */
525 #ifndef BUILD3001
526 # include "This release requires that you run configure again"
527 #endif
528 
529 /*
530  * This define ensures that any mismatching of version of
531  * THE and PDCurses are picked up
532  *
533  */
534 #if defined(PDCURSES)
535 # if PDC_BUILD < 2601
536 # include "You need a version of PDCurses with PDC_BUILD >= 2601 defined in curses.h"
537 # endif
538 #endif
539 
540 #if defined(PDCURSES) && PDC_BUILD >= 2601 && defined(WIN32)
541 # define THE_SINGLE_INSTANCE_ENABLED 1
542 #endif
543 
544 #if defined(HAVE_SELECT) && defined(HAVE_MKFIFO)
545 # define THE_SINGLE_INSTANCE_ENABLED 1
546 #endif
547 
548 #if defined(A_COLOR)
549 # define set_colour(attr) ((colour_support) ? (((attr)->pair) ? COLOR_PAIR((attr)->pair) | (attr)->mod : (attr)->mod) \
550                                            : ((attr)->mono))
551 #else
552 # define set_colour(attr)     ((attr)->mono)
553 # define COLOR_BLACK    0
554 # define COLOR_BLUE     0
555 # define COLOR_GREEN    0
556 # define COLOR_CYAN     0
557 # define COLOR_RED      0
558 # define COLOR_MAGENTA  0
559 # define COLOR_YELLOW   0
560 # define COLOR_WHITE    0
561 #endif
562 
563 #ifndef A_NORMAL
564 /* Various video attributes */
565 # define A_STANDOUT      BSD_STANDOUT /* for compatibility with BSD curses */
566 # define A_REVERSE       BSD_STANDOUT /* for compatibility with BSD curses */
567 # define A_UNDERLINE     0
568 # define A_BLINK         0
569 # define A_DIM           0
570 # define A_BOLD          BSD_STANDOUT
571 
572 /* The next two are subject to change so don't depend on them */
573 # define A_INVIS         0
574 # define A_PROTECT       0
575 
576 # define A_NORMAL        0
577 # define A_CHARTEXT      0x007F
578 # define A_ATTRIBUTES    ~A_CHARTEXT
579 # define A_ALTCHARSET    0
580 #endif
581 
582 #if THE_FOLLOWING_REMOVED_IN_22
583 #ifndef A_NORMAL
584 /* Various video attributes */
585 # ifdef HAVE_BSD_CURSES
586 #  define A_STANDOUT      BSD_STANDOUT /* for compatibility with BSD curses */
587 #  define A_REVERSE       BSD_STANDOUT /* for compatibility with BSD curses */
588 #  define A_UNDERLINE     0
589 #  define A_BLINK         0
590 #  define A_DIM           0
591 #  define A_BOLD          BSD_STANDOUT
592 
593 /* The next two are subject to change so don't depend on them */
594 #  define A_INVIS         0
595 #  define A_PROTECT       0
596 
597 #  define A_NORMAL        0
598 #  define A_CHARTEXT      0x007F
599 #  define A_ATTRIBUTES    ~A_CHARTEXT
600 #  define A_ALTCHARSET    0
601 
602 # else
603 
604 #  define A_STANDOUT      000000200000L
605 #  define A_UNDERLINE     000000400000L
606 #  define A_REVERSE       000001000000L
607 #  define A_BLINK         000002000000L
608 #  define A_DIM           000004000000L
609 #  define A_BOLD          000010000000L
610 #  define A_ALTCHARSET    000100000000L
611 
612 /* The next two are subject to change so don't depend on them */
613 #  define A_INVIS         000020000000L
614 #  define A_PROTECT       000040000000L
615 
616 #  define A_NORMAL        000000000000L
617 #  define A_ATTRIBUTES    037777600000L   /* 0xFFFF0000 */
618 #  define A_CHARTEXT      000000177777L   /* 0x0000FFFF */
619 
620 # endif
621 #endif
622 #endif
623 
624 #define ATTR2PAIR(fg,bg) (bg|(fg<<3))
625 #define FOREFROMPAIR(p)  (p>>3)
626 #define BACKFROMPAIR(p)  (p&0x07)
627 
628 #ifndef max
629 # define max(a,b)        (((a) > (b)) ? (a) : (b))
630 #endif
631 
632 #ifndef min
633 # define min(a,b)        (((a) < (b)) ? (a) : (b))
634 #endif
635 
636 #ifndef getmaxy
637 # ifdef VMS
638 #  ifdef _BSD44_CURSES
639 #   define getmaxy(win)    ((win)->maxy)
640 #  else
641 #   define getmaxy(win)    ((win)->_max_y)
642 #  endif
643 # else
644 #  if defined(HAVE_UNDERSCORE_MAXY)
645 #   define getmaxy(win)    ((win)->_maxy)
646 #  endif
647 #  if defined(HAVE_MAXY)
648 #   define getmaxy(win)    ((win)->maxy)
649 #  endif
650 # endif
651 #endif
652 
653 #ifndef getmaxx
654 # ifdef VMS
655 #  ifdef _BSD44_CURSES
656 #   define getmaxx(win)    ((win)->maxx)
657 #  else
658 #   define getmaxx(win)    ((win)->_max_x)
659 #  endif
660 # else
661 #  if defined(HAVE_UNDERSCORE_MAXY)
662 #   define getmaxx(win)    ((win)->_maxx)
663 #  endif
664 #  if defined(HAVE_MAXY)
665 #   define getmaxx(win)    ((win)->maxx)
666 #  endif
667 # endif
668 #endif
669 
670 #ifndef getmaxyx
671 # define getmaxyx(win,y,x)  ((y) = getmaxy(win), (x) = getmaxx(win))
672 #endif
673 
674 #if defined(SIGWINCH) && defined(USE_NCURSES)
675 # define is_termresized()  (ncurses_screen_resized)
676 #endif
677 
678 #define QUIT          (-127)
679 #define SKIP          (-126)
680 #define QUITOK        (-125)
681 #define RAW_KEY       (128)
682 
683 #define MAX_SCREENS         2              /* maximum number of screens*/
684 #define VIEW_WINDOWS        6            /* number of windows per view */
685 #define MAX_INT             32766          /* maximum size for integer */
686 #define MAX_LONG            2147483001L       /* maximum size for long */
687 #define WORD_DELIMS        (CHARTYPE *)" \t"
688 
689 #define TOP_OF_FILE        (CHARTYPE *)"*** Top of File ***"
690 #define BOTTOM_OF_FILE     (CHARTYPE *)"*** Bottom of File ***"
691 
692 #define DIRECTION_NONE      0
693 #define DIRECTION_FORWARD   1
694 #define DIRECTION_BACKWARD  (-1)
695 
696 #define UNDEFINED_OPERAND (-1)
697 
698 #define STATAREA_OFFSET  10
699 
700 /* the first 6 windows MUST be numbered 0-5 */
701 #define WINDOW_FILEAREA  0
702 #define WINDOW_PREFIX    1
703 #define WINDOW_COMMAND   2
704 #define WINDOW_ARROW     3
705 #define WINDOW_IDLINE    4
706 #define WINDOW_GAP       5
707 #define WINDOW_STATAREA  6
708 #define WINDOW_ERROR     7
709 #define WINDOW_DIVIDER   8
710 #define WINDOW_RESERVED  9
711 #define WINDOW_SLK      10
712 #define WINDOW_FILETABS 11
713 #define MAX_THE_WINDOWS 12 /* one more than maximum window number */
714 #define WINDOW_ALL      99
715 
716 #define MAX_PREFIX_WIDTH     20
717 #define DEFAULT_PREFIX_WIDTH  6
718 #define DEFAULT_PREFIX_GAP    0
719 
720 #define MAX_CTLCHARS                64
721 #define MAX_DELIMITER_LENGTH        20
722 #define MAX_PARSER_NAME_LENGTH      30
723 
724 #define CURRENT_SCREEN              screen[current_screen]
725 #define other_screen                ((current_screen==0)?1:0)
726 #define OTHER_SCREEN                screen[other_screen]
727 
728 #define PREVIOUS_VIEW               (vd_current->prev)
729 #define NEXT_VIEW                   (vd_current->next)
730 
731 #define CURRENT_VIEW                (vd_current)
732 #define CURRENT_FILE                (vd_current->file_for_view)
733 #define CURRENT_WINDOW              (CURRENT_SCREEN.win[vd_current->current_window])
734 #define CURRENT_PREV_WINDOW         (CURRENT_SCREEN.win[vd_current->previous_window])
735 #define CURRENT_WINDOW_FILEAREA     (CURRENT_SCREEN.win[WINDOW_FILEAREA])
736 #define CURRENT_WINDOW_PREFIX       (CURRENT_SCREEN.win[WINDOW_PREFIX])
737 #define CURRENT_WINDOW_GAP          (CURRENT_SCREEN.win[WINDOW_GAP])
738 #define CURRENT_WINDOW_COMMAND      (CURRENT_SCREEN.win[WINDOW_COMMAND])
739 #define CURRENT_WINDOW_ARROW        (CURRENT_SCREEN.win[WINDOW_ARROW])
740 #define CURRENT_WINDOW_IDLINE       (CURRENT_SCREEN.win[WINDOW_IDLINE])
741 
742 #define VIEW_VIEW(view)             (vd_current)
743 #define VIEW_FILE(view)             (view->file_for_view)
744 #define VIEW_WINDOW(scr,view)       (screen[(scr)].win[view->current_window])
745 #define VIEW_PREV_WINDOW(scr,view)  (screen[(scr)].win[view->previous_window])
746 
747 #define OTHER_VIEW                  (OTHER_SCREEN.screen_view)
748 #define OTHER_FILE                  (OTHER_VIEW->file_for_view)
749 #define OTHER_WINDOW                (OTHER_SCREEN.win[OTHER_VIEW->current_window])
750 #define OTHER_PREV_WINDOW           (OTHER_SCREEN.win[OTHER_VIEW->previous_window])
751 #define OTHER_WINDOW_FILEAREA       (OTHER_SCREEN.win[WINDOW_FILEAREA])
752 #define OTHER_WINDOW_PREFIX         (OTHER_SCREEN.win[WINDOW_PREFIX])
753 #define OTHER_WINDOW_GAP            (OTHER_SCREEN.win[WINDOW_GAP])
754 #define OTHER_WINDOW_COMMAND        (OTHER_SCREEN.win[WINDOW_COMMAND])
755 #define OTHER_WINDOW_ARROW          (OTHER_SCREEN.win[WINDOW_ARROW])
756 #define OTHER_WINDOW_IDLINE         (OTHER_SCREEN.win[WINDOW_IDLINE])
757 
758 #define SCREEN_VIEW(scr)            (screen[(scr)].screen_view)
759 #define SCREEN_FILE(scr)            (screen[(scr)].screen_view->file_for_view)
760 #define SCREEN_WINDOW(scr)          (screen[(scr)].win[screen[(scr)].screen_view->current_window])
761 #define SCREEN_PREV_WINDOW(scr)     (screen[(scr)].win[screen[(scr)].screen_view->previous_window])
762 #define SCREEN_WINDOW_FILEAREA(scr) (screen[(scr)].win[WINDOW_FILEAREA])
763 #define SCREEN_WINDOW_PREFIX(scr)   (screen[(scr)].win[WINDOW_PREFIX])
764 #define SCREEN_WINDOW_GAP(scr)      (screen[(scr)].win[WINDOW_GAP])
765 #define SCREEN_WINDOW_COMMAND(scr)  (screen[(scr)].win[WINDOW_COMMAND])
766 #define SCREEN_WINDOW_ARROW(scr)    (screen[(scr)].win[WINDOW_ARROW])
767 #define SCREEN_WINDOW_IDLINE(scr)   (screen[(scr)].win[WINDOW_IDLINE])
768 
769 #define MARK_VIEW (vd_mark)
770 #define MARK_FILE (vd_mark->file_for_view)
771 
772 /*------------------------ split/join actions ------------------------*/
773 #define SPLTJOIN_SPLIT           1
774 #define SPLTJOIN_JOIN            2
775 #define SPLTJOIN_SPLTJOIN        3
776 /*----------------- adjustments for calculating rec_len --------------*/
777 #define ADJUST_DELETE            1
778 #define ADJUST_INSERT            2
779 #define ADJUST_OVERWRITE         3
780 /*------------------------ column command types ----------------------*/
781 #define COLUMN_CAPPEND           1
782 #define COLUMN_CINSERT           2
783 #define COLUMN_CREPLACE          3
784 #define COLUMN_COVERLAY          4
785 /*------------------------ block move command types ------------------*/
786 #define COMMAND_COPY             1
787 #define COMMAND_DELETE           2
788 #define COMMAND_DUPLICATE        3
789 #define COMMAND_MOVE_COPY_SAME   4
790 #define COMMAND_MOVE_COPY_DIFF   5
791 #define COMMAND_MOVE_DELETE_SAME 6
792 #define COMMAND_MOVE_DELETE_DIFF 7
793 #define COMMAND_OVERLAY_COPY     8
794 #define COMMAND_OVERLAY_DELETE   9
795 /*------------------------ block move source types -------------------*/
796 #define SOURCE_UNKNOWN      0
797 #define SOURCE_COMMAND      1
798 #define SOURCE_PREFIX       2
799 #define SOURCE_BLOCK        3
800 #define SOURCE_BLOCK_RESET  4
801 /*---------------------- return code constants ------------------------*/
802 #define RC_OK                  0
803 #define RC_NOT_COMMAND        -1
804 #define RC_INVALID_ENVIRON    -3
805 #define RC_TOF_EOF_REACHED     1
806 #define RC_TARGET_NOT_FOUND    2
807 #define RC_TRUNCATED           3
808 #define RC_NO_LINES_CHANGED    4
809 #define RC_INVALID_OPERAND     5
810 #define RC_COMMAND_NO_FILES    6
811 #define RC_FILE_CHANGED       12
812 #define RC_ACCESS_DENIED      12
813 #define RC_DISK_FULL          13
814 #define RC_BAD_FILEID         20
815 #define RC_BAD_DRIVE          24
816 #define RC_FILE_NOT_FOUND     28
817 #define RC_OUT_OF_MEMORY      94
818 #define RC_NOREXX_ERROR       98
819 #define RC_SYSTEM_ERROR       99
820 #define RC_IO_ERROR          100
821 #define RC_READV_TERM        101
822 #define RC_READV_TERM_MOUSE  102
823 #define RC_TERMINATE_MACRO   111
824 /*---------------------- global parameters ----------------------------*/
825 #define EOLOUT_NONE              0
826 #define EOLOUT_LF                1
827 #define EOLOUT_CRLF              2
828 #define EOLOUT_CR                3
829 /*---------------------- extract return codes -------------------------*/
830 #define EXTRACT_ARG_ERROR        (-2)
831 #define EXTRACT_VARIABLES_SET    (-1)
832 /*---------------------- attribute defines ----------------------------*/
833 #define ATTR_FILEAREA    0
834 #define ATTR_CURLINE     1
835 #define ATTR_BLOCK       2
836 #define ATTR_CBLOCK      3
837 #define ATTR_CMDLINE     4
838 #define ATTR_IDLINE      5
839 #define ATTR_MSGLINE     6
840 #define ATTR_ARROW       7
841 #define ATTR_PREFIX      8
842 #define ATTR_CPREFIX     9
843 #define ATTR_PENDING    10
844 #define ATTR_SCALE      11
845 #define ATTR_TOFEOF     12
846 #define ATTR_CTOFEOF    13
847 #define ATTR_TABLINE    14
848 #define ATTR_SHADOW     15
849 #define ATTR_STATAREA   16
850 #define ATTR_DIVIDER    17
851 #define ATTR_RESERVED   18
852 #define ATTR_NONDISP    19
853 #define ATTR_HIGHLIGHT  20
854 #define ATTR_CHIGHLIGHT 21
855 #define ATTR_THIGHLIGHT 22
856 #define ATTR_SLK        23
857 #define ATTR_GAP        24
858 #define ATTR_CGAP       25
859 #define ATTR_ALERT      26
860 #define ATTR_DIALOG     27
861 #define ATTR_BOUNDMARK  28
862 #define ATTR_FILETABS   29
863 #define ATTR_FILETABSDIV 30
864 #define ATTR_CURSORLINE 31
865 #define ATTR_DIA_BORDER 32
866 #define ATTR_DIA_EDITFIELD 33
867 #define ATTR_DIA_BUTTON 34
868 #define ATTR_DIA_ABUTTON 35
869 #define ATTR_POP_BORDER 36
870 #define ATTR_POP_CURLINE 37
871 #define ATTR_POPUP 38
872 #define ATTR_POP_DIVIDER 39
873 #define ATTR_MAX        40
874 /*--------------------- -- ecolour defines -----------------------------*/
875 #define ECOLOUR_COMMENTS               0
876 #define ECOLOUR_STRINGS                1
877 #define ECOLOUR_NUMBERS                2
878 #define ECOLOUR_KEYWORDS               3
879 #define ECOLOUR_LABEL                  4
880 #define ECOLOUR_PREDIR                 5
881 #define ECOLOUR_HEADER                 6
882 #define ECOLOUR_EXTRA_R_PAREN          7
883 #define ECOLOUR_LEVEL_1_PAREN          8
884 #define ECOLOUR_LEVEL_1_KEYWORD        9
885 #define ECOLOUR_LEVEL_1_PREDIR        10
886 #define ECOLOUR_LEVEL_2_PAREN         11
887 #define ECOLOUR_LEVEL_3_PAREN         12
888 #define ECOLOUR_LEVEL_4_PAREN         13
889 #define ECOLOUR_LEVEL_5_PAREN         14
890 #define ECOLOUR_LEVEL_6_PAREN         15
891 #define ECOLOUR_LEVEL_7_PAREN         16
892 #define ECOLOUR_LEVEL_8_PAREN         17
893 #define ECOLOUR_INC_STRING            18
894 #define ECOLOUR_HTML_TAG              19
895 #define ECOLOUR_HTML_CHAR             20
896 #define ECOLOUR_FUNCTIONS             21
897 #define ECOLOUR_DIRECTORY             22
898 #define ECOLOUR_LINK                  23
899 #define ECOLOUR_EXECUTABLE            24
900 #define ECOLOUR_NOTUSED1              25
901 #define ECOLOUR_ALT_KEYWORD_1         26
902 #define ECOLOUR_ALT_KEYWORD_2         27
903 #define ECOLOUR_ALT_KEYWORD_3         28
904 #define ECOLOUR_ALT_KEYWORD_4         29
905 #define ECOLOUR_ALT_KEYWORD_5         30
906 #define ECOLOUR_ALT_KEYWORD_6         31
907 #define ECOLOUR_ALT_KEYWORD_7         32
908 #define ECOLOUR_ALT_KEYWORD_8         33
909 #define ECOLOUR_ALT_KEYWORD_9         34
910 #define ECOLOUR_MAX                   35
911 /*---------------------- display line types --------------------------*/
912 #define LINE_LINE                  0
913 #define LINE_TABLINE               1
914 #define LINE_SCALE                 2
915 #define LINE_BOUNDS                4
916 #define LINE_SHADOW                8
917 #define LINE_TOF                  16
918 #define LINE_EOF                  32
919 #define LINE_RESERVED             64
920 #define LINE_OUT_OF_BOUNDS_ABOVE 128
921 #define LINE_OUT_OF_BOUNDS_BELOW 256
922 #define LINE_HEXSHOW             512
923 /*--------------------------- target types ---------------------------*/
924 #define TARGET_ERR          (-1)
925 #define TARGET_UNFOUND        0x00000
926 #define TARGET_ABSOLUTE       0x00001
927 #define TARGET_RELATIVE       0x00002
928 #define TARGET_STRING         0x00004
929 #define TARGET_POINT          0x00008
930 #define TARGET_BLANK          0x00010
931 #define TARGET_ALL            0x00020
932 #define TARGET_BLOCK          0x00040
933 #define TARGET_BLOCK_ANY      0x00080
934 #define TARGET_BLOCK_CURRENT  0x00100
935 #define TARGET_SPARE          0x00200
936 #define TARGET_FIND           0x00400
937 #define TARGET_NFIND          0x00800
938 #define TARGET_FINDUP         0x01000
939 #define TARGET_NFINDUP        0x02000
940 #define TARGET_REGEXP         0x04000
941 #define TARGET_NEW            0x08000
942 #define TARGET_CHANGED        0x10000
943 #define TARGET_TAGGED         0x20000
944 #define TARGET_ALTERED        0x40000
945 #define TARGET_NORMAL         TARGET_ABSOLUTE|TARGET_RELATIVE|TARGET_STRING|TARGET_POINT|TARGET_BLANK|TARGET_NEW|TARGET_CHANGED|TARGET_TAGGED|TARGET_ALTERED
946 /*--------------------------- compatiblility modes -------------------*/
947 #define COMPAT_THE            1
948 #define COMPAT_XEDIT          2
949 #define COMPAT_KEDIT          4
950 #define COMPAT_KEDITW         8
951 #define COMPAT_ISPF          16
952 /*--------------------------- cursor commands ------------------------*/
953 #define CURSOR_START          (-1)
954 #define CURSOR_ERROR          (-2)
955 #define CURSOR_HOME           0
956 #define CURSOR_HOME_LAST      1
957 #define CURSOR_SCREEN         2
958 #define CURSOR_ESCREEN        3
959 #define CURSOR_CUA            4
960 #define CURSOR_COLUMN         5
961 #define CURSOR_FILE           6
962 #define CURSOR_CMDLINE        7
963 #define CURSOR_KEDIT          8
964 #define CURSOR_MOUSE          9
965 #define CURSOR_GOTO          10
966 #define CURSOR_PREFIX        11
967 /*--------------------------- defines for tabbing to fields ----------*/
968 #define WHERE_WINDOW_MASK             0x0000FF00L
969 #define WHERE_WINDOW_FILEAREA         0x00000100L
970 #define WHERE_WINDOW_PREFIX_LEFT      0x00000200L
971 #define WHERE_WINDOW_PREFIX_RIGHT     0x00000400L
972 #define WHERE_WINDOW_CMDLINE_TOP      0x00000800L
973 #define WHERE_WINDOW_CMDLINE_BOTTOM   0x00001000L
974 #define WHERE_ROW_MASK                0x000000FFL
975 #define WHERE_SCREEN_MASK             0x000F0000L
976 #define WHERE_SCREEN_FIRST            0x00010000L
977 #define WHERE_SCREEN_LAST             0x00020000L
978 #define WHERE_SCREEN_ONLY             0x00040000L
979 /*--------------------------- defines for headers for syntax highlighting -----------*/
980 #define HEADER_NUMBER                 0x001
981 #define HEADER_COMMENT                0x002
982 #define HEADER_STRING                 0x004
983 #define HEADER_KEYWORD                0x008
984 #define HEADER_FUNCTION               0x010
985 #define HEADER_HEADER                 0x020
986 #define HEADER_LABEL                  0x040
987 #define HEADER_MATCH                  0x080
988 #define HEADER_COLUMN                 0x100
989 #define HEADER_POSTCOMPARE            0x200
990 #define HEADER_MARKUP                 0x400
991 #define HEADER_DIRECTORY              0x800
992 #define HEADER_ALL                    (HEADER_NUMBER|HEADER_COMMENT|HEADER_STRING|HEADER_KEYWORD|HEADER_FUNCTION|HEADER_HEADER|HEADER_LABEL|HEADER_MATCH|HEADER_COLUMN|HEADER_POSTCOMPARE|HEADER_MARKUP|HEADER_DIRECTORY)
993 /*--------------------------- defines for syntax highlighting status -----------*/
994 #define THE_SYNTAX_NONE               ' '
995 #define THE_SYNTAX_UNKNOWN            '?'
996 #define THE_SYNTAX_COMMENT            'C'
997 #define THE_SYNTAX_FUNCTION           'F'
998 #define THE_SYNTAX_HEADER             'H'
999 #define THE_SYNTAX_INCOMPLETESTRING   's'
1000 #define THE_SYNTAX_KEYWORD            'K'
1001 #define THE_SYNTAX_LABEL              'L'
1002 #define THE_SYNTAX_MARKUP             'M'
1003 #define THE_SYNTAX_MATCH              'm'
1004 #define THE_SYNTAX_NUMBER             'N'
1005 #define THE_SYNTAX_POSTCOMPARE        'P'
1006 #define THE_SYNTAX_PREPROCESSOR       '#'
1007 #define THE_SYNTAX_STRING             'S'
1008 #define THE_SYNTAX_DIRECTORY          'd'
1009 #define THE_SYNTAX_LINK               'l'
1010 #define THE_SYNTAX_EXTENSION          'e'
1011 #define THE_SYNTAX_EXECUTABLE         'E'
1012 /*--------------------------- defines for EXTRACT DEFINE -----------------------*/
1013 #define KEY_TYPE_ALL        0
1014 #define KEY_TYPE_KEY        1
1015 #define KEY_TYPE_MOUSE      2
1016 
1017 #define THE_MAX_SCREEN_WIDTH          1000
1018 /*
1019  * Structure for generic linked list item
1020  */
1021 struct thelist
1022 {
1023    struct thelist *prev;
1024    struct thelist *next;
1025    void *data;
1026 };
1027 typedef struct thelist THELIST;
1028 /*
1029  * prototype for a linked list delete function
1030  */
1031 typedef void (*THELIST_DEL)( void*);
1032 
1033 /*
1034  * struct for LASTOP fields
1035  */
1036 struct lastop_struct
1037 {
1038    CHARTYPE *value;
1039    short value_len;
1040    CHARTYPE *command;
1041    int min_len;
1042 };
1043 typedef struct lastop_struct LASTOP;
1044 
1045 #define LASTOP_ALTER                  0
1046 #define LASTOP_CHANGE                 1
1047 #define LASTOP_CLOCATE                2
1048 #define LASTOP_COUNT                  3
1049 #define LASTOP_FIND                   4
1050 #define LASTOP_LOCATE                 5
1051 #define LASTOP_SCHANGE                6
1052 #define LASTOP_TFIND                  7
1053 #define LASTOP_SEARCH                 8
1054 #define LASTOP_MAX                    9
1055 
1056 #define PPC_OPERANDS                  3
1057 struct pending_prefix_command
1058 {
1059    struct pending_prefix_command *next;
1060    struct pending_prefix_command *prev;
1061    CHARTYPE ppc_orig_command[MAX_PREFIX_WIDTH+1];          /* prefix command */
1062    CHARTYPE ppc_command[MAX_PREFIX_WIDTH+1];          /* prefix command */
1063    CHARTYPE ppc_op[PPC_OPERANDS][MAX_PREFIX_WIDTH+1];       /* operands */
1064    LINETYPE ppc_line_number;                     /* line number in file */
1065    LINETYPE ppc_cmd_param;                     /* prefix command target */
1066    short ppc_cmd_idx;                           /* prefix command index */
1067    bool ppc_block_command;                     /* is it a BLOCK command */
1068    bool ppc_shadow_line;        /* was command entered on SHADOW line ? */
1069    bool ppc_set_by_pending;     /* was command created by SET PENDING ? */
1070    bool ppc_processed;                  /* has command been processed ? */
1071    bool ppc_current_command; /* is this command the current executing one ? */
1072 };
1073 typedef struct pending_prefix_command THE_PPC;
1074 
1075 typedef struct
1076 {
1077    unsigned int new_flag;
1078    unsigned int changed_flag;
1079    unsigned int tag_flag;
1080    unsigned int save_tag_flag;
1081    unsigned int unused1 ;
1082    unsigned int unused2 ;
1083    unsigned int unused3 ;
1084    unsigned int unused4 ;
1085 } lineflags ;
1086 
1087 struct line
1088 {
1089    struct line *prev;                       /* pointer to previous line */
1090    struct line *next;                           /* pointer to next line */
1091    CHARTYPE *name;  /* used for other structures; NOT for a LINE in THE */
1092    THELIST *first_name;      /* pointer to first name for list of names */
1093    CHARTYPE *line;                       /* pointer to contents of line */
1094    LENGTHTYPE length;                   /* number of characters in line */
1095 #ifdef FILENAME_LENGTH
1096    LENGTHTYPE filename_length;    /* length of filename in DIR.DIR file */
1097 #endif
1098    THE_PPC *pre;
1099    SELECTTYPE select;                     /* select level for each line */
1100    SELECTTYPE save_select;          /* saved select level (used by ALL) */
1101    lineflags flags;
1102 };
1103 typedef struct line LINE;
1104 
1105 struct colour_attr
1106 {
1107    int pair;                                  /* pair number for colour */
1108    chtype mod;                                       /* colour modifier */
1109    chtype mono;                                      /* mono attributes */
1110 };
1111 typedef struct colour_attr COLOUR_ATTR;
1112 
1113 struct reserved
1114 {
1115    struct reserved *prev;          /* pointer to previous reserved line */
1116    struct reserved *next;              /* pointer to next reserved line */
1117    CHARTYPE *line;                       /* pointer to contents of line */
1118    CHARTYPE *disp; /* pointer to contents of line after CTLCHAR applied */
1119    CHARTYPE *spec;                        /* row position specification */
1120    short length;                             /* length of reserved line */
1121    short disp_length;  /* length of reserved line after CTLCHAR applied */
1122    short base;                                              /* row base */
1123    short off;                                   /* row offset from base */
1124    chtype *highlighting;           /* array of colours for highlighting */
1125    COLOUR_ATTR *attr;                              /* colour attributes */
1126    bool autoscroll;  /* does the reserved line scroll with autoscroll settings */
1127 };
1128 typedef struct reserved RESERVED;
1129 
1130 struct prefix_commands
1131 {
1132    CHARTYPE *cmd;                                     /* prefix command */
1133    LENGTHTYPE cmd_len;                      /* length of prefix command */
1134    bool action_prefix;              /* is command an action or a target */
1135    bool multiples_allowed;                     /* are multiples allowed */
1136    bool full_target_allowed;            /* full target multiple allowed */
1137    bool block_prefix_command;             /* is command a block command */
1138    bool target_required;                 /* does command require target */
1139    bool valid_on_tof;         /* is command allowed on Top of File line */
1140    bool valid_on_bof;      /* is command allowed on Bottom of File line */
1141    bool valid_in_readonly;    /* TRUE if command valid in readonly mode */
1142    short (*function) Args((THE_PPC *,short,LINETYPE));
1143    LINETYPE default_target;/* number of lines to process if not specified */
1144    bool ignore_scope;/* TRUE if scope to be ignored when finding target */
1145    bool use_last_not_in_scope;/* TRUE if starting at end of shadow lines*/
1146    int  priority;                         /* priority of prefix command */
1147    short (*post_function) Args((THE_PPC *,short,LINETYPE));
1148    bool text_arg;        /* is argument a plain text arg like for '.' ? */
1149    bool allowed_on_shadow_line;  /* is command allowed on shadow line ? */
1150 };
1151 typedef struct prefix_commands PREFIX_COMMAND;
1152 #define PC_IS_ACTION      TRUE
1153 #define PC_NOT_ACTION     FALSE
1154 #define PC_MULTIPLES      TRUE
1155 #define PC_NO_MULTIPLES     FALSE
1156 #define PC_FULL_TARGET      TRUE
1157 #define PC_NO_FULL_TARGET     FALSE
1158 #define PC_IS_BLOCK      TRUE
1159 #define PC_NOT_BLOCK     FALSE
1160 #define PC_TARGET_REQD     TRUE
1161 #define PC_TARGET_NOT_REQD     FALSE
1162 #define PC_VALID_TOF      TRUE
1163 #define PC_INVALID_TOF         FALSE
1164 #define PC_VALID_BOF       TRUE
1165 #define PC_INVALID_BOF     FALSE
1166 #define PC_VALID_RO     TRUE
1167 #define PC_INVALID_RO     FALSE
1168 #define PC_IGNORE_SCOPE     TRUE
1169 #define PC_RESPECT_SCOPE     FALSE
1170 #define PC_USE_LAST_IN_SCOPE     TRUE
1171 #define PC_NO_USE_LAST_IN_SCOPE     FALSE
1172 
1173 struct parse_comments
1174 {
1175    struct parse_comments *prev;
1176    struct parse_comments *next;
1177    bool line_comment;                /* TRUE if this is a LINE comment */
1178    LENGTHTYPE column;      /* 0-ANY MAX_INT-FIRSTNONBLANK other-column */
1179    CHARTYPE start_delim[MAX_DELIMITER_LENGTH+1];  /* delimiter string for start of comment */
1180    CHARTYPE end_delim[MAX_DELIMITER_LENGTH+1];    /* delimiter string for end of comment */
1181    short len_start_delim;
1182    short len_end_delim;
1183    bool nested;                       /* can paired comments be nested */
1184    bool single_line; /* is this comment only allowed on a single line ?*/
1185 };
1186 typedef struct parse_comments PARSE_COMMENTS;
1187 
1188 struct parse_keywords
1189 {
1190    struct parse_keywords *prev;
1191    struct parse_keywords *next;
1192    CHARTYPE *keyword;
1193    short keyword_length;
1194    CHARTYPE alternate;
1195    CHARTYPE type;
1196 };
1197 typedef struct parse_keywords PARSE_KEYWORDS;
1198 
1199 struct parse_functions
1200 {
1201    struct parse_functions *prev;
1202    struct parse_functions *next;
1203    CHARTYPE *function;
1204    short function_length;
1205    CHARTYPE alternate;
1206 };
1207 typedef struct parse_functions PARSE_FUNCTIONS;
1208 
1209 struct parse_extension
1210 {
1211    struct parse_extension *prev;
1212    struct parse_extension *next;
1213    CHARTYPE *extension;
1214    short extension_length;
1215    CHARTYPE alternate;
1216 };
1217 typedef struct parse_extension PARSE_EXTENSION;
1218 
1219 struct parse_headers
1220 {
1221    struct parse_headers *prev;
1222    struct parse_headers *next;
1223    CHARTYPE header_delim[MAX_DELIMITER_LENGTH+1];
1224    short len_header_delim;
1225    LENGTHTYPE header_column;      /* 0-ANY MAX_INT-FIRSTNONBLANK other-column */
1226    CHARTYPE alternate;
1227 };
1228 typedef struct parse_headers PARSE_HEADERS;
1229 
1230 struct parse_postcompare
1231 {
1232    struct parse_postcompare *prev;
1233    struct parse_postcompare *next;
1234    bool is_class_type;
1235    struct re_pattern_buffer pattern_buffer;
1236    CHARTYPE *string;
1237    short string_length;
1238    CHARTYPE alternate;
1239 };
1240 typedef struct parse_postcompare PARSE_POSTCOMPARE;
1241 
1242 struct parser_details
1243 {
1244    struct parser_details *prev;
1245    struct parser_details *next;
1246    /*
1247     * Parser-level features
1248     */
1249    CHARTYPE parser_name[MAX_PARSER_NAME_LENGTH+1];
1250    CHARTYPE filename[MAX_FILE_NAME+1];
1251    struct re_pattern_buffer body_pattern_buffer;
1252    bool have_body_pattern_buffer;
1253    /*
1254     * string features
1255     */
1256    bool have_string;
1257    bool check_single_quote;
1258    bool backslash_single_quote;
1259    bool check_double_quote;
1260    bool backslash_double_quote;
1261    CHARTYPE string_delimiter;
1262    bool backslash_delimiter;
1263    /*
1264     * comments features
1265     */
1266    PARSE_COMMENTS *first_comments;
1267    PARSE_COMMENTS *current_comments;
1268    bool have_paired_comments;
1269    bool have_line_comments;
1270    /*
1271     * keyword features
1272     */
1273    PARSE_KEYWORDS *first_keyword;
1274    PARSE_KEYWORDS *current_keyword;
1275    short min_keyword_length;
1276    /*
1277     * function features
1278     */
1279    PARSE_FUNCTIONS *first_function;
1280    PARSE_FUNCTIONS *current_function;
1281    short min_function_length;
1282    struct re_pattern_buffer function_pattern_buffer;
1283    bool have_function_pattern_buffer;
1284    bool have_function_option_alternate;
1285    CHARTYPE function_option_alternate;
1286    /*
1287     * case features
1288     */
1289    bool case_sensitive;
1290    /*
1291     * option
1292     */
1293    bool rexx_option;
1294    bool preprocessor_option;
1295    bool function_option;
1296    CHARTYPE preprocessor_char;
1297    CHARTYPE function_char;
1298    bool function_blank;
1299    /*
1300     * match features - minimal at the moment
1301     */
1302    bool have_match;
1303    /*
1304     * header features
1305     */
1306    PARSE_HEADERS *first_header;
1307    PARSE_HEADERS *current_header;
1308    bool have_headers;
1309    /*
1310     * label features
1311     */
1312    CHARTYPE label_delim[11];
1313    short len_label_delim;
1314    LENGTHTYPE label_column;      /* 0-ANY MAX_INT-FIRSTNONBLANK other-column */
1315    /*
1316     * markup features
1317     */
1318    bool have_markup_tag;
1319    CHARTYPE markup_tag_start_delim[MAX_DELIMITER_LENGTH+1];
1320    short len_markup_tag_start_delim;
1321    CHARTYPE markup_tag_end_delim[MAX_DELIMITER_LENGTH+1];
1322    short len_markup_tag_end_delim;
1323    bool have_markup_reference;
1324    CHARTYPE markup_reference_start_delim[MAX_DELIMITER_LENGTH+1];
1325    short len_markup_reference_start_delim;
1326    CHARTYPE markup_reference_end_delim[MAX_DELIMITER_LENGTH+1];
1327    short len_markup_reference_end_delim;
1328    /*
1329     * postcompare features
1330     */
1331    bool have_postcompare;
1332    PARSE_POSTCOMPARE *first_postcompare;
1333    PARSE_POSTCOMPARE *current_postcompare;
1334    /*
1335     * column features
1336     */
1337 #define MAX_PARSER_COLUMNS 20
1338    bool have_columns;
1339    LENGTHTYPE first_column[MAX_PARSER_COLUMNS];
1340    LENGTHTYPE last_column[MAX_PARSER_COLUMNS];
1341    short number_columns;
1342    CHARTYPE column_alternate[MAX_PARSER_COLUMNS];
1343    /*
1344     * number features
1345     */
1346    struct re_pattern_buffer number_pattern_buffer;
1347    bool have_number_pattern_buffer;
1348    /*
1349     *  link features
1350     */
1351    bool have_directory_link;
1352    CHARTYPE link_option_alternate;
1353    /*
1354     *  directory features
1355     */
1356    bool have_directory_directory;
1357    CHARTYPE directory_option_alternate;
1358    /*
1359     * extensions features
1360     */
1361    bool have_extensions;
1362    PARSE_EXTENSION *first_extension;
1363    PARSE_EXTENSION *current_extension;
1364    /*
1365     *  executable features
1366     */
1367    bool have_executable;
1368    CHARTYPE executable_option_alternate;
1369 };
1370 typedef struct parser_details PARSER_DETAILS;
1371 
1372  struct parser_mapping
1373 {
1374    struct parser_mapping *prev;
1375    struct parser_mapping *next;
1376    CHARTYPE *parser_name;
1377    CHARTYPE *filemask;
1378    CHARTYPE *magic_number;
1379    int magic_number_length;
1380    PARSER_DETAILS *parser;
1381 } ;
1382 typedef struct parser_mapping PARSER_MAPPING;
1383 
1384 /* structure for repeating targets */
1385 struct rtarget
1386 {
1387    CHARTYPE *string;                               /* pointer to target */
1388    LENGTHTYPE length;             /* length of specified target: string */
1389    LENGTHTYPE found_length;                /* length of matching string */
1390    LENGTHTYPE start;          /* starting column of found string target */
1391    CHARTYPE boolean;                                /* boolean operator */
1392    bool not_target;                               /* TRUE if NOT target */
1393    LINETYPE numeric_target;                     /* numeric target value */
1394    long target_type;                                  /* type of target */
1395    bool negative;                         /* TRUE if direction backward */
1396    bool found;               /* TRUE if this repeating target was found */
1397    bool have_compiled_re;              /* TRUE if we have a compiled RE */
1398    struct re_pattern_buffer pattern_buffer;   /* compiled RE for REGEXP */
1399 };
1400 typedef struct rtarget RTARGET;
1401 
1402 /* structure for targets */
1403 struct target
1404 {
1405    CHARTYPE *string;                      /* pointer to original target */
1406    LINETYPE num_lines;                     /* number of lines to target */
1407    LINETYPE true_line;                     /* line number to start with */
1408    LINETYPE last_line;            /* line number of last line in target */
1409    RTARGET *rt;                         /* pointer to repeating targets */
1410    short num_targets;                        /* number of targets found */
1411    short spare;             /* index to which repeating target is spare */
1412    bool ignore_scope;/* TRUE if scope to be ignored when finding target */
1413    bool search_semantics;                          /* TRUE if SEARCHing */
1414    long focus_column;                            /* used when SEARCHing */
1415    bool all_tag_command;    /* true if finding rtargets with TAG or ALL */
1416 };
1417 typedef struct target TARGET;
1418 
1419 typedef struct
1420 {
1421    CHARTYPE autosave;
1422    short backup;
1423    COLOUR_ATTR *attr;
1424    COLOUR_ATTR *ecolour;             /* array of ECOLOURS for this file */
1425    CHARTYPE eolout;
1426    bool tabsout_on;
1427    bool display_actual_filename;
1428    bool undoing;
1429    bool timecheck;
1430    CHARTYPE tabsout_num;
1431    short trailing;       /* how to handle trailing spaces on file write */
1432    bool colouring;            /* specifies if syntax highlighting is on */
1433    bool autocolour;                    /* specifies if AUTOCOLOUR is on */
1434    PARSER_DETAILS *parser;     /* parser to use for syntax highlighting */
1435 } PRESERVED_FILE_DETAILS;
1436 
1437 typedef struct
1438 {
1439    CHARTYPE autosave;        /* number of alterations before autosaving */
1440    short backup;           /* indicates type of backup file to be saved */
1441    COLOUR_ATTR *attr;                              /* colour attributes */
1442    COLOUR_ATTR *ecolour;             /* array of ECOLOURS for this file */
1443    CHARTYPE eolout;     /* indicates how lines are terminated on output */
1444    bool tabsout_on;      /* indicates if tabs to replace spaces on file */
1445    bool display_actual_filename;
1446    bool undoing;
1447    bool timecheck;                          /* file time stamp checking */
1448    CHARTYPE tabsout_num;                 /* length of tab stops on file */
1449    short trailing;       /* how to handle trailing spaces on file write */
1450    bool colouring;            /* specifies if syntax highlighting is on */
1451    bool autocolour;                    /* specifies if AUTOCOLOUR is on */
1452    PARSER_DETAILS *parser;     /* parser to use for syntax highlighting */
1453    /*
1454     * All settings above this line are saveable.
1455     * Ensure that PRESERVED_FILE_DETAILS structure reflects this.
1456     */
1457    PRESERVED_FILE_DETAILS *preserved_file_details;
1458    ROWTYPE status_row;         /* row on which status line is displayed */
1459    CHARTYPE pseudo_file;   /* indicates if file is a "pseudo" file and if so, what sort */
1460    CHARTYPE disposition;        /* indicates if file is new or existing */
1461    unsigned short autosave_alt;  /* number of alterations since last autosave */
1462    unsigned short save_alt;    /* number of alterations since last save */
1463    CHARTYPE *autosave_fname;             /* file name for AUTOSAVE file */
1464    FILE *fp;                               /* file handle for this file */
1465    CHARTYPE *fname;                                        /* file name */
1466    CHARTYPE *fpath;                                        /* file path */
1467    CHARTYPE *actualfname;                         /* filename specified */
1468    CHARTYPE *efileid;                         /* original full filename */
1469    unsigned short fmode;                           /* file mode of file */
1470 #if defined(HAVE_CHOWN)
1471    uid_t uid;                                         /* userid of file */
1472    gid_t gid;                                        /* groupid of file */
1473 #endif
1474    long modtime;                      /* timestamp of file modification */
1475    LINE *first_line;                           /* pointer to first line */
1476    LINE *last_line;                             /* pointer to last line */
1477    LINE *editv;                          /* pointer for EDITV variables */
1478    LINETYPE  number_lines;            /* number of actual lines in file */
1479    LINETYPE  max_line_length;            /* Maximum line length in file */
1480    CHARTYPE file_views;              /* number of views of current file */
1481    RESERVED *first_reserved;          /* pointer to first reserved line */
1482    THE_PPC *first_ppc;                      /* first pending prefix command */
1483    THE_PPC *last_ppc;                        /* last pending prefix command */
1484    CHARTYPE eolfirst;       /* indicates termination of first line read */
1485    int readonly;                 /* have we set the file to be readonly */
1486 } FILE_DETAILS;
1487 
1488 typedef struct
1489 {
1490    struct view_details *prev;               /* pointer to previous view */
1491    struct view_details *next;                   /* pointer to next view */
1492    bool arbchar_status;                   /* indicates if arbchar is on */
1493    CHARTYPE arbchar_single;         /* single arbitrary character value */
1494    CHARTYPE arbchar_multiple;     /* multiple arbitrary character value */
1495    bool arrow_on;                    /* indicates if arrow is displayed */
1496    CHARTYPE case_enter;               /* indicates case of data entered */
1497    CHARTYPE case_enter_cmdline;  /* indicates case of data entered on cmdline */
1498    CHARTYPE case_enter_prefix;   /* indicates case of data entered in prefix */
1499    CHARTYPE case_locate;              /* indicates case of data located */
1500    CHARTYPE case_change;              /* indicates case of data changed */
1501    CHARTYPE case_sort;       /* indicates case significance for sorting */
1502    ROWTYPE cmd_line;                        /* position of command line */
1503    ROWTYPE current_row;                     /* row which is current row */
1504    short current_base;   /* indicates relative position of current line */
1505    short current_off;       /* offset from current_base for current_row */
1506    SELECTTYPE display_low;                /* low range of display level */
1507    SELECTTYPE display_high;              /* high range of display level */
1508    bool hex;       /* TRUE if hex conversion is done on string operands */
1509    bool hexshow_on;                                /* status of hexshow */
1510    short hexshow_base;     /* base position for starting row of hexshow */
1511    short hexshow_off;           /* offset from base of start of hexshow */
1512    CHARTYPE highlight;                    /* lines to highlight, if any */
1513    SELECTTYPE highlight_high; /* high select level of highlighted lines */
1514    SELECTTYPE highlight_low;   /* low select level of highlighted lines */
1515    bool id_line;                            /* TRUE if IDLINE displayed */
1516    bool imp_macro;       /* indicates if implied macro processing is on */
1517    bool imp_os;             /* indicates if implied os processing is on */
1518    CHARTYPE inputmode;            /* indicates type of input processing */
1519    bool linend_status; /* indicates if multiple commands allowed on command line */
1520    CHARTYPE linend_value;                /* specifies command delimiter */
1521    bool macro;      /* indicates if macros are executed before commands */
1522    LENGTHTYPE margin_left;                /* left margin column 1 based */
1523    LENGTHTYPE margin_right;              /* right margin column 1 based */
1524    LENGTHTYPE margin_indent;                   /* paragraph indentation */
1525    bool margin_indent_offset_status; /* TRUE if paragraph indentation is an offset from left margin */
1526    short msgline_base;        /* indicates relative position of msgline */
1527    short msgline_off;           /* offset from msgline_base for msgline */
1528    ROWTYPE msgline_rows;                   /* number of rows in msgline */
1529    bool msgmode_status;    /* indicates if messages are to be displayed */
1530    bool newline_aligned; /* TRUE if adding a new line results in cursor appearing under 1st non-blank of previous line */
1531    bool number;   /* indicates if numbers in prefix are to be displayed */
1532    bool position_status;     /* TRUE if LINE/COL is displayed on IDLINE */
1533    CHARTYPE prefix;       /* indicates if and where prefix is displayed */
1534    short prefix_width;                       /* overall width of prefix */
1535    short prefix_gap;        /* width of gap between prefix and filearea */
1536    bool scale_on;                    /* indicates if scale is displayed */
1537    short scale_base;   /* base position on which scale row is displayed */
1538    short scale_off; /* offset from base position on which scale row is displayed */
1539    bool scope_all; /* indicates if commands act on All lines or only those Displayed */
1540    bool shadow;        /* indicates if shadow lines are to be displayed */
1541    bool stay;                               /* indicates status of STAY */
1542    bool synonym;       /* indicates if synonym processing is in effect */
1543    bool tab_on;             /* indicates if tab line is to be displayed */
1544    short tab_base;      /* base position on which tab line is displayed */
1545    short tab_off;  /* offset from base position on which tab line is displayed */
1546    bool tabsinc;                    /* tab increment or 0 if fixed tabs */
1547    COLTYPE numtabs;                      /* number of tab stops defined */
1548    LENGTHTYPE tabs[MAX_NUMTABS];      /* tab settings for each tab stop */
1549    LENGTHTYPE verify_col;                /* left col for current verify */
1550    LENGTHTYPE verify_start;                   /* col of start of verify */
1551    LENGTHTYPE verify_end;                       /* col of end of verify */
1552    bool verify_end_max;        /* TRUE if verify end was specified as * */
1553    CHARTYPE word;                                       /* word setting */
1554    bool wordwrap;                                   /* wordwrap setting */
1555    bool wrap;                                           /* wrap setting */
1556    bool tofeof;                /* true if want to display TOF/EOF lines */
1557    LENGTHTYPE zone_start;                       /* col of start of zone */
1558    LENGTHTYPE zone_end;                           /* col of end of zone */
1559    bool zone_end_max;            /* TRUE if zone end was specified as * */
1560    LINETYPE autoscroll;     /* 0 - no autoscroll, -1 half, other number */
1561    CHARTYPE boundmark;                             /* type of boundmark */
1562    LINETYPE syntax_headers;       /* which syntax headers to be applied */
1563    bool thighlight_on;                 /* indicates if THIGHLIGHT is on */
1564    bool thighlight_active;         /* indicates if THIGHLIGHT is active */
1565    TARGET thighlight_target;          /* details of target to highlight */
1566 } PRESERVED_VIEW_DETAILS;
1567 
1568 struct view_details
1569 {
1570    struct view_details *prev;               /* pointer to previous view */
1571    struct view_details *next;                   /* pointer to next view */
1572    bool arbchar_status;                   /* indicates if arbchar is on */
1573    CHARTYPE arbchar_single;         /* single arbitrary character value */
1574    CHARTYPE arbchar_multiple;     /* multiple arbitrary character value */
1575    bool arrow_on;                    /* indicates if arrow is displayed */
1576    CHARTYPE case_enter;               /* indicates case of data entered */
1577    CHARTYPE case_enter_cmdline;  /* indicates case of data entered on cmdline */
1578    CHARTYPE case_enter_prefix;   /* indicates case of data entered in prefix */
1579    CHARTYPE case_locate;              /* indicates case of data located */
1580    CHARTYPE case_change;              /* indicates case of data changed */
1581    CHARTYPE case_sort;       /* indicates case significance for sorting */
1582    ROWTYPE cmd_line;                        /* position of command line */
1583    ROWTYPE current_row;                     /* row which is current row */
1584    short current_base;   /* indicates relative position of current line */
1585    short current_off;       /* offset from current_base for current_row */
1586    SELECTTYPE display_low;                /* low range of display level */
1587    SELECTTYPE display_high;              /* high range of display level */
1588    bool hex;       /* TRUE if hex conversion is done on string operands */
1589    bool hexshow_on;                                /* status of hexshow */
1590    short hexshow_base;     /* base position for starting row of hexshow */
1591    short hexshow_off;           /* offset from base of start of hexshow */
1592    CHARTYPE highlight;                    /* lines to highlight, if any */
1593    SELECTTYPE highlight_high; /* high select level of highlighted lines */
1594    SELECTTYPE highlight_low;   /* low select level of highlighted lines */
1595    bool id_line;                            /* TRUE if IDLINE displayed */
1596    bool imp_macro;       /* indicates if implied macro processing is on */
1597    bool imp_os;             /* indicates if implied os processing is on */
1598    CHARTYPE inputmode;            /* indicates type of input processing */
1599    bool linend_status; /* indicates if multiple commands allowed on command line */
1600    CHARTYPE linend_value;                /* specifies command delimiter */
1601    bool macro;      /* indicates if macros are executed before commands */
1602    LENGTHTYPE margin_left;                /* left margin column 1 based */
1603    LENGTHTYPE margin_right;              /* right margin column 1 based */
1604    LENGTHTYPE margin_indent;                        /* paragraph indentation */
1605    bool margin_indent_offset_status; /* TRUE if paragraph indentation is an offset from left margin */
1606    short msgline_base;        /* indicates relative position of msgline */
1607    short msgline_off;           /* offset from msgline_base for msgline */
1608    ROWTYPE msgline_rows;                   /* number of rows in msgline */
1609    bool msgmode_status;    /* indicates if messages are to be displayed */
1610    bool newline_aligned; /* TRUE if adding a new line results in cursor appearing under 1st non-blank of previous line */
1611    bool number;   /* indicates if numbers in prefix are to be displayed */
1612    bool position_status;     /* TRUE if LINE/COL is displayed on IDLINE */
1613    CHARTYPE prefix;       /* indicates if and where prefix is displayed */
1614    short prefix_width;                       /* overall width of prefix */
1615    short prefix_gap;        /* width of gap between prefix and filearea */
1616    bool scale_on;                    /* indicates if scale is displayed */
1617    short scale_base;   /* base position on which scale row is displayed */
1618    short scale_off; /* offset from base position on which scale row is displayed */
1619    bool scope_all; /* indicates if commands act on All lines or only those Displayed */
1620    bool shadow;        /* indicates if shadow lines are to be displayed */
1621    bool stay;                               /* indicates status of STAY */
1622    bool synonym;       /* indicates if synonym processing is in effect */
1623    bool tab_on;             /* indicates if tab line is to be displayed */
1624    short tab_base;      /* base position on which tab line is displayed */
1625    short tab_off;  /* offset from base position on which tab line is displayed */
1626    bool tabsinc;                    /* tab increment or 0 if fixed tabs */
1627    COLTYPE numtabs;                      /* number of tab stops defined */
1628    LENGTHTYPE tabs[MAX_NUMTABS];      /* tab settings for each tab stop */
1629    LENGTHTYPE verify_col;                /* left col for current verify */
1630    LENGTHTYPE verify_start;                   /* col of start of verify */
1631    LENGTHTYPE verify_end;                       /* col of end of verify */
1632    bool verify_end_max;        /* TRUE if verify end was specified as * */
1633    CHARTYPE word;                                       /* word setting */
1634    bool wordwrap;                                   /* wordwrap setting */
1635    bool wrap;                                           /* wrap setting */
1636    bool tofeof;                /* true if want to display TOF/EOF lines */
1637    LENGTHTYPE zone_start;                       /* col of start of zone */
1638    LENGTHTYPE zone_end;                           /* col of end of zone */
1639    bool zone_end_max;            /* TRUE if zone end was specified as * */
1640    LINETYPE autoscroll;     /* 0 - no autoscroll, -1 half, other number */
1641    CHARTYPE boundmark;                             /* type of boundmark */
1642    LINETYPE syntax_headers;       /* which syntax headers to be applied */
1643    bool thighlight_on;                 /* indicates if THIGHLIGHT is on */
1644    bool thighlight_active;         /* indicates if THIGHLIGHT is active */
1645    TARGET thighlight_target;          /* details of target to highlight */
1646    /*
1647     * All settings above this line are saveable.
1648     * Ensure that PRESERVED_VIEW_DETAILS structure reflects this.
1649     */
1650    PRESERVED_VIEW_DETAILS *preserved_view_details;
1651    LINETYPE current_line;      /* line in file displayed on current row */
1652    LENGTHTYPE current_column;   /* column in line of last column target */
1653    short y[VIEW_WINDOWS];               /* y coordinate for each window */
1654    short x[VIEW_WINDOWS];               /* x coordinate for each window */
1655    LINETYPE focus_line;                 /* line in file where cursor is */
1656    short mark_type;                             /* type of marked block */
1657    LINETYPE mark_start_line;                 /* first line to be marked */
1658    LINETYPE mark_end_line;                    /* last line to be marked */
1659    bool marked_line;                             /* TRUE if line marked */
1660    bool in_ring;                   /* TRUE if file already in edit ring */
1661    LENGTHTYPE mark_start_col;                    /* first column marked */
1662    LENGTHTYPE mark_end_col;                       /* last column marked */
1663    bool marked_col;                            /* TRUE if column marked */
1664    int cmdline_col;                     /* column to display in cmdline */
1665    CHARTYPE current_window;        /* current window for current screen */
1666    CHARTYPE previous_window;      /* previous window for current screen */
1667    FILE_DETAILS *file_for_view;            /* pointer to file structure */
1668 };
1669 typedef struct view_details VIEW_DETAILS;
1670 
1671 /* structure for each line to be displayed */
1672 struct show_line
1673 {
1674    CHARTYPE *contents;                   /* pointer to contents of line */
1675    RESERVED *rsrvd; /* pointer to reserved line struct if a reserved line */
1676    LINETYPE number_lines_excluded;          /* number of lines excluded */
1677    LINETYPE line_number;                     /* line number within file */
1678    LINE *current;                            /* pointer to current line */
1679    short line_type;                                     /* type of line */
1680    bool prefix_enterable;            /* TRUE if prefix can be tabbed to */
1681    bool main_enterable;            /* TRUE if filearea can be tabbed to */
1682    bool highlight;                       /* TRUE if line is highlighted */
1683 
1684    /* NOTE: The following entries are only for displaying. They are NOT
1685     * updated by a call to build_screen. Therefore you can't access them.
1686     */
1687 
1688    LENGTHTYPE length;                   /* number of characters in line */
1689    chtype normal_colour;                      /* normal colour for line */
1690    chtype other_colour;                        /* other colour for line */
1691    LENGTHTYPE other_start_col; /* start column of other colour from col 0 */
1692    LENGTHTYPE other_end_col;   /* end column of other colour from col 0 */
1693    chtype prefix_colour;                            /* colour of prefix */
1694    chtype gap_colour;                           /* colour of prefix gap */
1695    CHARTYPE prefix[MAX_PREFIX_WIDTH+1];      /* contents of prefix area */
1696    chtype prefix_highlighting[MAX_PREFIX_WIDTH+1];    /* array of colours for syntax highlighting */
1697    CHARTYPE gap[MAX_PREFIX_WIDTH+1];          /* contents of prefix gap */
1698    chtype gap_highlighting[MAX_PREFIX_WIDTH+1];    /* array of colours for syntax highlighting */
1699    /*
1700     * The following 2 array MUST be the same size
1701     */
1702    chtype highlighting[THE_MAX_SCREEN_WIDTH];    /* array of colours for syntax highlighting */
1703 //   CHARTYPE highlight_type[THE_MAX_SCREEN_WIDTH];    /* array of syntax types for later querying */
1704    unsigned char *highlight_type;
1705    bool is_highlighting;  /* TRUE if this line contains syntax highlighting */
1706    bool is_current_line;       /* TRUE if this line is the current line */
1707    bool is_cursor_line; /* TRUE if this line is the cursor line of the filearea */
1708    bool is_cursor_line_filearea_different; /* TRUE if the filearea/cursorline colours are different */
1709 };
1710 typedef struct show_line SHOW_LINE;
1711 
1712 /* structure for each screen */
1713 typedef struct
1714 {
1715    ROWTYPE screen_start_row;                     /* start row of screen */
1716    COLTYPE screen_start_col;                     /* start col of screen */
1717    ROWTYPE screen_rows;                                /* physical rows */
1718    COLTYPE screen_cols;                                /* physical cols */
1719    ROWTYPE rows[VIEW_WINDOWS];                        /* rows in window */
1720    COLTYPE cols[VIEW_WINDOWS];                        /* cols in window */
1721    ROWTYPE start_row[VIEW_WINDOWS];              /* start row of window */
1722    COLTYPE start_col[VIEW_WINDOWS];              /* start col of window */
1723    WINDOW *win[VIEW_WINDOWS];  /* curses windows for the screen display */
1724    VIEW_DETAILS *screen_view;    /* view being displayed in this screen */
1725    SHOW_LINE *sl;       /* pointer to SHOW_DETAILS structure for screen */
1726 } SCREEN_DETAILS;
1727 
1728 /* structure for colour definitions */
1729 typedef struct
1730 {
1731    chtype fore;
1732    chtype back;
1733    chtype mod;
1734    chtype mono;
1735 } COLOUR_DEF;
1736 
1737 /* structure for regular expression syntaxes */
1738 struct regexp_syntax
1739 {
1740    char *name;
1741    int value;
1742 };
1743 
1744 #define STATUS_ROW         (screen_rows-1)
1745 #define COMMAND_ROW        (screen_rows-2)
1746 #define ERROR_ROW          1
1747 #define TAB_ROW            6
1748 #define TAB_ON             NO
1749 #define SCALE_ROW          6
1750 #define SCALE_ON           NO
1751 #define CURSOR_ROW         COMMAND_ROW
1752 #define CURSOR_COL         5
1753 #define CURRENT_ROW_POS    0
1754 #define CURRENT_ROW        0
1755 #define ZONE_START         1
1756 
1757 /* column where filename starts in DIR.DIR */
1758 #define FILE_START         38
1759 
1760 /* defines for base value for relative row positions */
1761 #define POSITION_TOP       0
1762 #define POSITION_MIDDLE    1
1763 #define POSITION_BOTTOM    2
1764 
1765 /* defines for function_key() function calling */
1766 #define OPTION_NORMAL      0
1767 #define OPTION_EXTRACT     1
1768 #define OPTION_READV       2
1769 
1770 /* defines for pseudo file types */
1771 #define PSEUDO_REAL        0
1772 #define PSEUDO_DIR         1
1773 #define PSEUDO_REXX        2
1774 #define PSEUDO_KEY         3
1775 #define PSEUDO_REMOTE      4
1776 
1777 /* defines for prefix settings */
1778 #define PREFIX_OFF           0x00
1779 #define PREFIX_ON            0x10
1780 #define PREFIX_NULLS         0x20
1781 #define PREFIX_LEFT          0x01
1782 #define PREFIX_RIGHT         0x02
1783 #define PREFIX_LOCATION_MASK 0x0F
1784 #define PREFIX_STATUS_MASK   0xF0
1785 
1786 /* defines for query types */
1787 #define QUERY_NONE         0
1788 #define QUERY_QUERY        1
1789 #define QUERY_STATUS       2
1790 #define QUERY_EXTRACT      4
1791 #define QUERY_FUNCTION     8
1792 #define QUERY_MODIFY      16
1793 #define QUERY_READV       32
1794 
1795 /* defines for case settings */
1796 #define CASE_MIXED         (CHARTYPE)'M'
1797 #define CASE_UPPER         (CHARTYPE)'U'
1798 #define CASE_LOWER         (CHARTYPE)'L'
1799 #define CASE_IGNORE        (CHARTYPE)'I'
1800 #define CASE_RESPECT       (CHARTYPE)'R'
1801 
1802 /* type of marked blocks - do not change these values!! SET BLOCK needs them */
1803 #define M_NONE             0
1804 #define M_LINE             1
1805 #define M_BOX              2
1806 #define M_STREAM           3
1807 #define M_COLUMN           4
1808 #define M_WORD             5
1809 #define M_CUA              6
1810 
1811 /* defines for temporary space allocation */
1812 #define TEMP_PARAM         1
1813 #define TEMP_MACRO         2
1814 #define TEMP_TMP_CMD       3
1815 #define TEMP_TEMP_CMD      4
1816 
1817 /* defines for [SET] BACKUP */
1818 #define BACKUP_OFF         1
1819 #define BACKUP_TEMP        2
1820 #define BACKUP_KEEP        3
1821 #define BACKUP_ON          BACKUP_KEEP
1822 #define BACKUP_INPLACE     4
1823 
1824 /* defines for [SET] DIRSORT */
1825 #define DIRSORT_NONE       0
1826 #define DIRSORT_DIR        1
1827 #define DIRSORT_SIZE       2
1828 #define DIRSORT_NAME       3
1829 #define DIRSORT_DATE       4
1830 #define DIRSORT_TIME       5
1831 #define DIRSORT_ASC        0
1832 #define DIRSORT_DESC       1
1833 
1834 /* box opertaions */
1835 #define BOX_C           1
1836 #define BOX_M           2
1837 #define BOX_D           3
1838 #define BOX_F           4
1839 #define BOX_S           5
1840 
1841 /* defines for highlighting */
1842 #define HIGHLIGHT_NONE     0
1843 #define HIGHLIGHT_TAG      1
1844 #define HIGHLIGHT_ALT      2
1845 #define HIGHLIGHT_SELECT   3
1846 
1847 /* defines for INPUTMODE */
1848 #define INPUTMODE_OFF      0
1849 #define INPUTMODE_FULL     1
1850 #define INPUTMODE_LINE     2
1851 
1852 /* defines for EDITV - suprise! */
1853 #define EDITV_GET    1
1854 #define EDITV_PUT    2
1855 #define EDITV_SET    3
1856 #define EDITV_SETL   4
1857 #define EDITV_LIST   5
1858 
1859 #ifndef FILE_NORMAL
1860 #define FILE_NORMAL        0
1861 #endif
1862 
1863 #ifndef FILE_READONLY
1864 #define FILE_READONLY      1
1865 #endif
1866 
1867 #ifndef FILE_NEW
1868 #define FILE_NEW          99
1869 #endif
1870 
1871 #define COMMAND_ONLY_TRUE    TRUE
1872 #define COMMAND_ONLY_FALSE   FALSE
1873 
1874 #define ADDCHAR            0
1875 #define INSCHAR            1
1876 
1877 #define LVL_GLOB  1
1878 #define LVL_FILE  2
1879 #define LVL_VIEW  3
1880 
1881 #define CHAR_OTHER     0
1882 #define CHAR_ALPHANUM  1
1883 #define CHAR_SPACE     2
1884 
1885 /*
1886  * Following defines for KEY shift status
1887  */
1888 #define SHIFT_ALT            1
1889 #define SHIFT_CTRL           2
1890 #define SHIFT_SHIFT          4
1891 #define SHIFT_MODIFIER_ONLY  8
1892 /*
1893  * Following defines for MOUSE shift status - yes they are different to the KEY shift status
1894  */
1895 #define SHIFT_MOUSE_SHIFT    1
1896 #define SHIFT_MOUSE_CTRL     2
1897 #define SHIFT_MOUSE_ALT      4
1898 
1899 #define INTERFACE_CLASSIC    1
1900 #define INTERFACE_CUA        2
1901 /*
1902  * #defines for SET TRAILING
1903  */
1904 #define TRAILING_OFF       0
1905 #define TRAILING_ON        1
1906 #define TRAILING_SINGLE    2
1907 #define TRAILING_EMPTY     3
1908 #define TRAILING_REMOVE    4
1909 /*
1910  * #defines for behaviour of commands when a CUA block is current
1911  */
1912 #define CUA_NONE           0
1913 #define CUA_DELETE_BLOCK   1
1914 #define CUA_RESET_BLOCK    2
1915 /*
1916  * #defines for behaviour of commands with a THIGHLIGHT area
1917  */
1918 #define THIGHLIGHT_NONE        0
1919 #define THIGHLIGHT_RESET_ALL   1
1920 #define THIGHLIGHT_RESET_FOCUS 2
1921 
1922 /*
1923  * #defines for BOUNDMARK
1924  */
1925 #define BOUNDMARK_OFF       0
1926 #define BOUNDMARK_ZONE      1
1927 #define BOUNDMARK_TRUNC     2
1928 #define BOUNDMARK_MARGINS   3
1929 #define BOUNDMARK_TABS      4
1930 #define BOUNDMARK_VERIFY    5
1931 
1932 /*
1933  * following #defines for MyStrip() function
1934  */
1935 #define STRIP_NONE         0
1936 #define STRIP_LEADING      1
1937 #define STRIP_TRAILING     2
1938 #define STRIP_INTERNAL     4
1939 #define STRIP_BOTH         (STRIP_LEADING|STRIP_TRAILING)
1940 #define STRIP_ALL          (STRIP_LEADING|STRIP_TRAILING|STRIP_INTERNAL)
1941 /*
1942  * following #defines for button types for DIALOG command
1943  */
1944 #define BUTTON_OK          0
1945 #define BUTTON_OKCANCEL    1
1946 #define BUTTON_YESNO       2
1947 #define BUTTON_YESNOCANCEL 3
1948 /*
1949  * following #defines for icon types for DIALOG command
1950  */
1951 #define ICON_NONE          0
1952 #define ICON_EXCLAMATION   1
1953 #define ICON_INFORMATION   2
1954 #define ICON_QUESTION      3
1955 #define ICON_STOP          4
1956 /*
1957  * following #defines for SET READONLY
1958  */
1959 #define READONLY_OFF       0
1960 #define READONLY_ON        1
1961 #define READONLY_FORCE     2
1962 /*
1963  * following #defines for get_key_definition() format
1964  */
1965 #define THE_KEY_DEFINE_SHOW   1
1966 #define THE_KEY_DEFINE_DEFINE 2
1967 #define THE_KEY_DEFINE_RAW    3
1968 #define THE_KEY_DEFINE_QUERY  4
1969 /*
1970  * following #defines for file_exists()
1971  */
1972 #define THE_FILE_UNKNOWN       0
1973 #define THE_FILE_EXISTS        1
1974 #define THE_FILE_NAME_TOO_LONG 2
1975 /*
1976  * Following are used for determining the button action of the mouse
1977  */
1978 #if !defined(BUTTON_RELEASED)
1979 # define BUTTON_RELEASED 0
1980 #endif
1981 #if !defined(BUTTON_PRESSED)
1982 # define BUTTON_PRESSED 1
1983 #endif
1984 #if !defined(BUTTON_CLICKED)
1985 # define BUTTON_CLICKED 2
1986 #endif
1987 #if !defined(BUTTON_DOUBLE_CLICKED)
1988 # define BUTTON_DOUBLE_CLICKED 3
1989 #endif
1990 #if !defined(BUTTON_MOVED)
1991 # define BUTTON_MOVED 5
1992 #endif
1993 
1994 #ifndef getbegyx
1995 # if defined(HAVE_BEGY)
1996 #  define getbegyx(win,y,x)       (y = (win)->begy, x = (win)->begx)
1997 # endif
1998 # if defined(HAVE_UNDERSCORE_BEGY)
1999 #  define getbegyx(win,y,x)       (y = (win)->_begy, x = (win)->_begx)
2000 # endif
2001 #endif
2002 
2003 #if defined(USE_WINGUICURSES)
2004 # define HIT_ANY_KEY "** Command completed **"
2005 #else
2006 # define HIT_ANY_KEY "Hit any key to continue..."
2007 #endif
2008 
2009 /*---------------------- useful macros --------------------------------*/
2010 #define     TOF(line)           ((line == 0L) ? TRUE : FALSE)
2011 #define     BOF(line)           ((line == CURRENT_FILE->number_lines+1L) ? TRUE : FALSE)
2012 #define     VIEW_TOF(view,line) ((line == 0L) ? TRUE : FALSE)
2013 #define     VIEW_BOF(view,line) ((line == view->file_for_view->number_lines+1L) ? TRUE : FALSE)
2014 #define     CURRENT_TOF         ((CURRENT_VIEW->current_line == 0L) ? TRUE : FALSE)
2015 #define     CURRENT_BOF         ((CURRENT_VIEW->current_line == CURRENT_FILE->number_lines+1L) ? TRUE : FALSE)
2016 #define     FOCUS_TOF           ((CURRENT_VIEW->focus_line == 0L) ? TRUE : FALSE)
2017 #define     FOCUS_BOF           ((CURRENT_VIEW->focus_line == CURRENT_FILE->number_lines+1L) ? TRUE : FALSE)
2018 #define     VIEW_FOCUS_TOF(view) ((view->focus_line == 0L) ? TRUE : FALSE)
2019 #define     VIEW_FOCUS_BOF(view) ((view->focus_line == view->file_for_view->number_lines+1L) ? TRUE : FALSE)
2020 #define     IN_VIEW(view,line)   ((line >= (view->current_line - (LINETYPE)view->current_row)) && (line <= (view->current_line + ((LINETYPE)CURRENT_SCREEN.rows[WINDOW_FILEAREA] - (LINETYPE)view->current_row))))
2021 #define     IN_SCOPE(view,line) ((line)->select >= (view)->display_low && (line)->select <= (view)->display_high)
2022 /*---------------------- system specific redefines --------------------*/
2023 #ifdef VAX
2024 #define     wattrset     wsetattr
2025 #define     A_REVERSE    _REVERSE
2026 #define     A_BOLD       _BOLD
2027 #endif
2028 
2029 #define ISREADONLY(x)  (the_readonly || (READONLYx==READONLY_FORCE) || (READONLYx==READONLY_ON && x->disposition == FILE_READONLY) || !(x->readonly==READONLY_OFF))
2030 #define STATUSLINEON() ((STATUSLINEx == 'T') || (STATUSLINEx == 'B'))
2031 
2032 extern VIEW_DETAILS *vd_current;
2033 extern CHARTYPE current_screen;
2034 extern SCREEN_DETAILS screen[MAX_SCREENS];
2035 
2036 #ifdef MAIN
2037 LENGTHTYPE max_line_length=MAX_LENGTH_OF_LINE;
2038 #else
2039 extern LENGTHTYPE max_line_length;
2040 #endif
2041 
2042 #define PARACOL (CURRENT_VIEW->margin_indent_offset_status?CURRENT_VIEW->margin_left+CURRENT_VIEW->margin_indent:CURRENT_VIEW->margin_indent)
2043 
2044 /* structure for passing queryable values parameters */
2045 struct query_values
2046 {
2047    CHARTYPE *value;                                    /* value of item */
2048    LENGTHTYPE len;               /* length of string representation of value */
2049 };
2050 typedef struct query_values VALUE;
2051 
2052 /* structure for function key redefinition */
2053 struct defines
2054 {
2055    struct defines *prev;
2056    struct defines *next;
2057    int def_funkey;
2058    short def_command;
2059    CHARTYPE *def_params;
2060    CHARTYPE *synonym;
2061    CHARTYPE *pcode;
2062    int pcode_len;
2063    CHARTYPE linend;
2064 };
2065 typedef struct defines DEFINE;
2066 
2067 /* structure for window areas */
2068 struct window_areas
2069 {
2070    CHARTYPE *area;            /* window area - used for COLOUR command */
2071    short area_min_len;                     /* min abbrev for area name */
2072    short area_window;                          /* window where area is */
2073    bool  actual_window;                    /* TRUE if area is a window */
2074 };
2075 typedef struct window_areas AREAS;
2076 
2077 typedef short (ExtractFunction) Args(( short, short, CHARTYPE *, CHARTYPE ,LINETYPE ,CHARTYPE *, LINETYPE ));
2078 
2079 /* structure for query and implied extract */
2080 struct query_item
2081 {
2082    CHARTYPE *name;                                      /* name of item */
2083    short name_length;                        /* length of function name */
2084    short min_len;                     /* minimum length of abbreviation */
2085    short item_number;                         /* unique number for item */
2086    short number_values;                    /* number of values returned (from query/extract)*/
2087    short item_values;     /* number of values this item can have (implied extract) (excludes 0th value ) */
2088    short level;                    /* level of item; global, file, view */
2089    CHARTYPE query;                            /* valid query response ? */
2090    ExtractFunction *ext_func;  /* function that generates extract details */
2091 };
2092 typedef struct query_item QUERY_ITEM;
2093 
2094 /* maximum number of variables that can be returned via EXTRACT */
2095 /* this MUST be max of ECOLOUR_MAX and ATTR_MAX */
2096 #define MAX_VARIABLES_RETURNED               ECOLOUR_MAX
2097 
2098 /* structure for list of TLD headers */
2099 typedef struct
2100 {
2101    char *the_header_name;
2102    int the_header_name_len;
2103    LINETYPE the_header;
2104 } the_header_mapping;
2105 
2106 #if defined(HAVE_STRICMP)
2107 # define my_stricmp stricmp
2108 #elif defined(HAVE_STRCMPI)
2109 # define my_stricmp strcmpi
2110 #elif defined(HAVE_STRCASECMP)
2111 # define my_stricmp strcasecmp
2112 #endif
2113 
2114 #if defined(MAIN)
2115 # ifdef MSWIN
2116 #  define _THE_FAR __far
2117 void far * (*the_malloc)(unsigned long);             /* ptr to some malloc(size) */
2118 void far * (*the_calloc)();                          /* ptr to some ecalloc(num,size)*/
2119 void  (*the_free)();                            /* ptr to some free(ptr) */
2120 void far * (*the_realloc)(void far *,unsigned long); /* ptr to some realloc(ptr,size) */
2121 # else
2122 #  define _THE_FAR
2123 #  ifdef HAVE_PROTO
2124 void* (*the_malloc)(size_t);  /* ptr to some malloc(size) */
2125 void* (*the_calloc)(size_t,size_t);  /* ptr to some calloc(num,size)*/
2126 void  (*the_free)(void *);    /* ptr to some free(ptr) */
2127 void* (*the_realloc)(void *, size_t); /* ptr to some realloc(ptr,size) */
2128 #  else
2129 void* (*the_malloc)();  /* ptr to some malloc(size) */
2130 void* (*the_calloc)();  /* ptr to some calloc(num,size)*/
2131 void  (*the_free)();    /* ptr to some free(ptr) */
2132 void* (*the_realloc)(); /* ptr to some realloc(ptr,size) */
2133 #  endif
2134 # endif
2135 #else
2136 # ifdef MSWIN
2137 #  define _THE_FAR __far
2138 #  ifdef HAVE_PROTO
2139 extern void far * (*the_malloc)(unsigned long);
2140 extern void far * (*the_calloc)(unsigned long);
2141 extern void  (*the_free)(void *);
2142 extern void far * (*the_realloc)(void far *,unsigned long);
2143 #  else
2144 extern void far * (*the_malloc)();
2145 extern void far * (*the_calloc)();
2146 extern void  (*the_free)();
2147 extern void far * (*the_realloc)();
2148 #  endif
2149 # else
2150 #  define _THE_FAR
2151 extern void* (*the_malloc)(unsigned long);
2152 extern void* (*the_calloc)(unsigned long);
2153 extern void  (*the_free)(void *);
2154 extern void* (*the_realloc)(void *, unsigned long);
2155 # endif
2156 #endif
2157 
2158 #if defined(THE_TRACE)
2159 void trace_initialise Args((void));
2160 void trace_function Args((char *));
2161 void trace_return Args((void));
2162 void trace_string Args((char *,...));
2163 void trace_constant Args((char *));
2164 # define TRACE_RETURN()     trace_return()
2165 # define TRACE_FUNCTION(x)  trace_function(x)
2166 # define TRACE_INITIALISE() trace_initialise()
2167 # define TRACE_CONSTANT(x) trace_constant(x)
2168 #else
2169 # define TRACE_RETURN()
2170 # define TRACE_FUNCTION(x)
2171 # define TRACE_INITIALISE()
2172 # define TRACE_CONSTANT(x)
2173 #endif
2174 #include "vars.h"
2175 
2176 #define THE_SEARCH_SEMANTICS                   TRUE
2177 #define THE_NOT_SEARCH_SEMANTICS               FALSE
2178 
2179 #define MAX_WIDTH_NUM  2000000000L
2180 
2181 /*
2182  * Don't call the *prog_mode functions when using PDCurses
2183  */
2184 #ifdef HAVE_RESET_PROG_MODE
2185 # ifndef PDCURSES
2186 #  define USE_PROG_MODE 1
2187 # endif
2188 #else
2189 #endif
2190 #include "directry.h"
2191