home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / jove-4.16-src.tgz / tar.out / bsd / jove / jove.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  12KB  |  412 lines

  1. /************************************************************************
  2.  * This program is Copyright (C) 1986-1996 by Jonathan Payne.  JOVE is  *
  3.  * provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is *
  5.  * included in all the files.                                           *
  6.  ************************************************************************/
  7.  
  8. /* jove.h header file to be included by EVERYONE */
  9.  
  10. #include <setjmp.h>
  11. #ifndef TUNED
  12. # include "tune.h"
  13. #endif
  14.  
  15. #include <string.h>
  16.  
  17. #ifndef MAC
  18. # include <sys/types.h>
  19. #else
  20. # include <types.h>
  21. # include <time.h>    /* for time_t */
  22. #endif
  23.  
  24. /* proto: macro to allow us to prototype any function declaration
  25.  * without upsetting old compilers.
  26.  */
  27.  
  28. #ifdef REALSTDC
  29. # define    USE_PROTOTYPES  1
  30. #endif
  31.  
  32. #ifdef USE_PROTOTYPES
  33. # define proto(x)        x
  34. # ifdef NO_PTRPROTO
  35.    /* on these systems, a prototype cannot be used for a pointer to function */
  36. #  define ptrproto(x)        ()
  37. # else
  38. #  define ptrproto(x)        x
  39. # endif
  40. #else
  41. # define proto(x)        ()
  42. # define ptrproto(x)        ()
  43. #endif
  44.  
  45. /* There are two ways to handle functions with a variable number of args.
  46.  * The old portable way uses varargs.h.  The way sanctioned by ANSI X3J11
  47.  * uses stdarg.h.
  48.  */
  49. #ifdef REALSTDC
  50. #define    STDARGS    1
  51. #endif
  52.  
  53. #ifdef STDARGS
  54. # include <stdarg.h>
  55. # define    va_init(ap, parmN)    { va_start((ap), (parmN)); }
  56. #else
  57. # include <varargs.h>
  58. # define    va_init(ap, parmN)    { va_start((ap)); }
  59. #endif
  60.  
  61. /* ANSI Goodies and their substitutes
  62.  *
  63.  * const: readonly type qualifier
  64.  *
  65.  * volatile: type qualifier indicating one of two kinds of magic.
  66.  * 1. This object may be modified by an event unknown to the implementation
  67.  *    (eg. asynchronous signal or memory-mapped I/O device).
  68.  * 2. This automatic variable might be modified between a setjmp()
  69.  *    and a longjmp(), and we wish it to have the correct value after
  70.  *    the longjmp().  This second meaning is an X3J11 abomination.
  71.  * So far, only the second meaning is used.
  72.  *
  73.  * UnivPtr: universal pointer type
  74.  *
  75.  * UnivConstPtr: universal pointer to const
  76.  */
  77.  
  78. #ifdef REALSTDC
  79.  
  80.   typedef void    *UnivPtr;
  81.   typedef const void    *UnivConstPtr;
  82.  
  83. #else /* !REALSTDC */
  84.  
  85. # ifndef const
  86. #  define    const    /* Only in ANSI C.  Pity */
  87. # endif
  88. # ifndef volatile
  89. #  define    volatile
  90. # endif
  91.   typedef char    *UnivPtr;
  92.   typedef const char    *UnivConstPtr;
  93.  
  94. #endif /* !REALSTDC */
  95.  
  96. /* According to the ANSI standard for C, any library routine may
  97.  * be defined as a macro with parameters.  In order to prevent
  98.  * the expansion of this macro in a declaration of the routine,
  99.  * ANSI suggests parenthesizing the identifier.  This is a reasonable
  100.  * and legal approach, even for K&R C.
  101.  *
  102.  * A bug in the MIPS compiler used on MIPS, IRIS, and probably other
  103.  * MIPS R[23]000 based systems, causes the compiler to reject
  104.  * these declarations (at least at the current time, 1989 August).
  105.  * To avoid this bug, we conditionally define and use UNMACRO.
  106.  */
  107. #ifdef MIPS_CC_BUG
  108. # define UNMACRO(proc)    proc
  109. #else
  110. # define UNMACRO(proc)    (proc)
  111. #endif
  112.  
  113. /* Since we don't use stdio.h, we may have to define NULL and EOF */
  114.  
  115. #ifndef NULL
  116. # define NULL    0
  117. #endif
  118.  
  119. #ifndef EOF
  120. #define EOF    (-1)
  121. #endif
  122.  
  123. #define private        static
  124.  
  125. typedef int    bool;
  126. #define NO        0
  127. #define YES        1
  128.  
  129. #define elemsof(a)    (sizeof(a) / sizeof(*(a)))    /* number of array elements */
  130.  
  131. /* Safe-where-possible signal handling.
  132.  *
  133.  * SIGHANDLERTYPE: the type of a pointer to a signal handler
  134.  * setsighandler: the best way to establish a signal handler
  135.  * resetsighandler: the best way to re-establish a signal handler
  136.  */
  137.  
  138. typedef SIGRESTYPE (*SIGHANDLERTYPE) ptrproto((int));
  139.  
  140. #ifdef POSIX_SIGS
  141. extern SIGHANDLERTYPE setsighandler proto((int, SIGHANDLERTYPE));
  142. # define resetsighandler(signo, handler)    /* nothing */
  143. #else /* !POSIX_SIGS */
  144. # ifdef USE_SIGSET
  145. #  define setsighandler(signo, handler)    sigset((signo), (handler))
  146. #  define resetsighandler(signo, handler)    /* nothing */
  147. # else /* !USE_SIGSET */
  148.    /* BSD_SIGS or default: use signal() */
  149. #  define setsighandler(signo, handler)    signal((signo), (handler))
  150. # endif /* !USE_SIGSET */
  151. #endif /* !POSIX_SIGS */
  152.  
  153. #ifndef resetsighandler
  154.  /* On some systems, the signal handler is left established,
  155.   * but this is not the case with original UNIX signals.
  156.   * This code adjusts to the system at hand, at fairly low cost.
  157.   * This code is even used for BSD_SIGS, even though it should not
  158.   * be needed: it compensates for mis-configuration.
  159.   * Note: this routine will only work if every execution of a particular
  160.   * call is for the same handler.  Furthermore, all executions should
  161.   * be due to the handler being invoked by a signal.  These restrictions
  162.   * ensure that the setting of the static variable indicates whether
  163.   * signal handlers need to be re-established.
  164.   */
  165. # define resetsighandler(signo, handler)    { \
  166.     static SIGHANDLERTYPE   reset_handler = NULL; \
  167.  \
  168.     if (reset_handler != (handler)) \
  169.         reset_handler = setsighandler((signo), (handler)); \
  170. }
  171. #endif
  172.  
  173. /* Principles of character representation in JOVE:
  174.  *
  175.  * - Only legal characters (excluding NUL) may be stored in the buffer.
  176.  *
  177.  * - Only legal characters will be found in the input stream, as
  178.  *   delivered by getch and kbd_getch (the meta-key feature
  179.  *   may cause invalid characters to be read, but they will be
  180.  *   confined within kbd_getch).
  181.  *
  182.  * - Bad characters from a file should be discarded.  Perhaps a message
  183.  *   should be generated.  NUL should be considered one of these bad
  184.  *   characters.  [The elimination of these characters is the duty of
  185.  *   callers of jgetc.]
  186.  *
  187.  * - The type of a string (ignoring const or volatile) should be "char *".
  188.  *   This is the standard type specified by the ANSI/ISO C standard.
  189.  *   As such, it is the type expected by the standard library.
  190.  *
  191.  * - In general, it is reasonable to use a plain char type
  192.  *   to represent an individual character, avoiding the expense and
  193.  *   fuss of widening.
  194.  *
  195.  *   + The character must be known not to be an EOF.
  196.  *
  197.  *   + The character must only be used in ways in which sign extension
  198.  *     is known to not cause problems:
  199.  *
  200.  *     * The value is coerced into a char type (the most common example
  201.  *       is assignment to a char; another is the search character in a
  202.  *       call to strchr).  Of course, EOF must not appear in these
  203.  *       contexts.
  204.  *
  205.  *     * The value is used for equality or inequality comparison where
  206.  *       all operands are subject to identical char widening.  A
  207.  *       special case of this is 7-bit ASCII char literals:
  208.  *       they can be safely compared for equality or inequality with
  209.  *       chars widened explicitly or implicitly.
  210.  *
  211.  * - ZXchar is the type for a character that has been widened without
  212.  *   sign extension.  It can represent EOF distinctly from characters.
  213.  *   The ZXC and ZXRC functions should be used to do the widening.
  214.  *
  215.  * - DAPchar is the type that results from the "default argument promotions"
  216.  *   applied to the char type.  Since most of our function definitions are
  217.  *   in the old style, formals declared in these definitions to be of type
  218.  *   char should be declared to be of type DAPchar in any prototype (this is
  219.  *   an arcane ANSI C rule).  The widening involved might be sign-extension
  220.  *   or it might not, but we don't care because it will be immediately
  221.  *   narrowed. A C implementation can legally make the type "unsigned int",
  222.  *   but this is highly unlikely.  By extension, a value of this type may be
  223.  *   used anywhere a char is needed.
  224.  *
  225.  * The following functions widen char type to an int, without sign
  226.  * extension.  There are two kinds:
  227.  *
  228.  * ZXC(c): zero-extend an internal char.  It is presumed that
  229.  *    the character is clean, but we may have to prevent sign extension.
  230.  *
  231.  * ZXRC(c): zero-extend a external (raw) char.  The purpose is to prevent
  232.  *    sign extension, even if the char is invalid.
  233.  */
  234.  
  235. typedef int ZXchar;    /* type for expanded char (possibly EOF) */
  236.  
  237. #ifndef DAPchar
  238. # define DAPchar    int    /* DefaultArgPromotion(char) */
  239. #endif
  240.  
  241. #ifndef UCHAR_ROOF
  242. # define UCHAR_ROOF    256    /* better be true! */
  243. #endif
  244.  
  245. #if NCHARS == 128
  246. # ifndef ZXC
  247. #  define ZXC(c)    (c)    /* identity op -- sign bit must be off */
  248. # endif
  249. #else
  250. # if NCHARS == UCHAR_ROOF
  251. #  ifndef ZXC
  252. #   define ZXC(c)    ((ZXchar) (unsigned char) (c))
  253. #  endif
  254. # else
  255.    /* ??? */
  256. # endif
  257. #endif
  258.  
  259. #ifndef ZXRC
  260. # define ZXRC(c)    ((ZXchar) (unsigned char) (c))
  261. #endif
  262.  
  263. /* Pervasive exports of other modules */
  264.  
  265. /* disp.c */
  266. extern volatile bool    UpdModLine;    /* Does the mode line need to be updated? */
  267.  
  268. /* term.c: universal termcap-like declarations */
  269.  
  270. #define MAXCOLS        256    /* maximum number of columns */
  271.  
  272. extern int
  273.     SG,        /* number of magic cookies left by SO and SE */
  274.     LI,        /* number of lines */
  275.     ILI,        /* number of internal lines (LI - 1) */
  276.     CO;        /* number of columns (CO <= MAXCOLS) */
  277.  
  278. extern bool
  279.     TABS;        /* terminal supports tabs */
  280.  
  281. /* typedef pervasive structure definitions */
  282.  
  283. typedef struct window    Window;    /* wind.h */
  284. typedef struct position    Bufpos;    /* buf.h */
  285. typedef struct mark    Mark;    /* buf.h (not mark.h!) */
  286. typedef struct buffer    Buffer;    /* buf.h */
  287. #ifdef FAR_LINES
  288. typedef struct line _far    *LinePtr;    /* buf.h */
  289. #else
  290. typedef struct line    *LinePtr;    /* buf.h */
  291. #endif
  292. typedef struct FileStruct    File;    /* fp.h */
  293.  
  294. #include "buf.h"
  295. #include "io.h"
  296. #include "dataobj.h"
  297. #include "keymaps.h"
  298. #include "argcount.h"
  299. #include "util.h"
  300.  
  301. #include "externs.h"
  302.  
  303. #define FORWARD        1
  304. #define BACKWARD    (-1)
  305.  
  306. /* jove.c exports: */
  307.  
  308. /* paths */
  309.  
  310. extern char
  311.     ShareDir[FILESIZE],    /* path of machine-independent library */
  312.     TmpDir[FILESIZE];    /* VAR: directory/device to store tmp files */
  313.  
  314. #ifdef SUBSHELL
  315. extern char
  316.     Shell[FILESIZE],    /* VAR: shell to use */
  317.     ShFlags[16];    /* VAR: flags to shell */
  318. #endif
  319.  
  320.  
  321. /* setjmp/longjmp args for DoKeys() mainjmp */
  322. #define JMP_FIRSTCALL    0
  323. #define JMP_ERROR        1
  324. #define JMP_COMPLAIN    2    /* do the error without a getDOT */
  325. #define JMP_QUIT        3    /* leave this level of recursion */
  326.  
  327. extern jmp_buf    mainjmp;
  328.  
  329.  
  330. extern char    NullStr[];
  331.  
  332.  
  333. extern ZXchar
  334.     peekchar,    /* holds pushed-back getch output */
  335.     LastKeyStruck;    /* used by SelfInsert and friends */
  336.  
  337. extern int
  338.     RecDepth,    /* recursion depth (used by disp.c for modeline) */
  339.     SlowCmd;    /* depth of nesting of slow commands */
  340.  
  341. extern bool
  342.     TOabort,    /* flag set by Typeout() */
  343.     stickymsg,    /* the last message should stick around */
  344.     InputPending,    /* is there input waiting to be processed? */
  345.     Interactive;
  346.  
  347. #ifdef UNIX
  348. extern bool
  349.     InSlowRead;    /* Can we do a redisplay in a signal handler? */
  350. #endif
  351.  
  352. extern char    *Inputp;
  353.  
  354. #ifdef WINRESIZE
  355. # define PreEmptOutput()    (ResizePending || (SlowCmd == 0 && charp()))
  356. # define CheapPreEmptOutput()    (ResizePending || (SlowCmd == 0 && InputPending))
  357. #else
  358. # define PreEmptOutput()    (SlowCmd == 0 && charp())
  359. # define CheapPreEmptOutput()    (SlowCmd == 0 && InputPending)
  360. #endif
  361.  
  362. #ifdef SUBSHELL
  363. extern void    jcloseall proto((void));
  364. #endif
  365.  
  366. extern SIGRESTYPE
  367.     finish proto((int code)),    /* doesn't return at all! */
  368.     win_reshape proto((int /*junk*/));
  369.  
  370. extern bool
  371.     charp proto((void));
  372.  
  373. extern ZXchar
  374.     getch proto((void)),
  375.     kbd_getch proto((void)),
  376.     waitchar proto((void)),
  377.     ask_ks proto((void));
  378.  
  379. extern void
  380.     cmd_sync proto((void)),
  381.     add_stroke proto((ZXchar)),
  382.     error proto((const char *, ...)),
  383.     complain proto((const char *, ...)),
  384.     raw_complain proto((const char *, ...)),
  385.     confirm proto((const char *, ...)),
  386.     SitFor proto((int delay)),
  387.     pp_key_strokes proto((char *buffer, size_t size)),
  388.     tty_adjust proto ((void)),
  389.     Ungetc proto((ZXchar c)),
  390.     kbd_ungetch proto((ZXchar c));
  391.  
  392. /* Commands: */
  393.  
  394. extern void
  395. #ifdef JOB_CONTROL
  396.     PauseJove proto((void)),
  397. #endif
  398. #ifdef SUBSHELL
  399.     Push proto((void)),
  400. #endif
  401.     Recur proto((void)),
  402.     ShowVersion proto((void));
  403.  
  404. /* Variables: */
  405.  
  406. extern bool    MetaKey;        /* VAR: this terminal has a meta key */
  407. extern bool    TimeDisplayed;    /* is time actually displayed in modeline? */
  408. #ifdef UNIX
  409. extern int    UpdFreq;        /* VAR: how often to update modeline */
  410. extern void    SetClockAlarm proto((bool unset));
  411. #endif
  412.