[BACK]Return to def.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/def.h, Revision 1.1

1.1     ! deraadt     1: /*
        !             2:  * This file is the general header file for all parts
        !             3:  * of the MicroEMACS display editor. It contains all of the
        !             4:  * general definitions and macros. It also contains some
        !             5:  * conditional compilation flags. All of the per-system and
        !             6:  * per-terminal definitions are in special header files.
        !             7:  * The most common reason to edit this file would be to zap
        !             8:  * the definition of CVMVAS or BACKUP.
        !             9:  */
        !            10: #include       "sysdef.h"              /* Order is critical.           */
        !            11: #include       "ttydef.h"
        !            12: #include       "chrdef.h"
        !            13:
        !            14: /*
        !            15:  * If your system and/or compiler does not support the "void" type
        !            16:  * then define NO_VOID_TYPE in sysdef.h.  In the absence of some
        !            17:  * other definition for VOID, the default in that case will be to
        !            18:  * turn it into an int, which works with most compilers that don't
        !            19:  * support void.  In the absence of any definition of VOID or
        !            20:  * NO_VOID_TYPE, the default is to assume void is supported, which
        !            21:  * should be the case for most modern C compilers.
        !            22:  */
        !            23:
        !            24: #ifdef NO_VOID_TYPE
        !            25: #  undef VOID
        !            26: #  define VOID int                     /* Default for no void is int */
        !            27: #else
        !            28: #ifndef VOID
        !            29: #  define VOID void                    /* Just use normal void */
        !            30: #endif /* VOID */
        !            31: #endif /* NO_VOID_TYPE */
        !            32:
        !            33: #ifdef NO_MACRO
        !            34: #ifndef NO_STARTUP
        !            35: #define NO_STARTUP                     /* NO_MACRO implies NO_STARTUP */
        !            36: #endif
        !            37: #endif
        !            38:
        !            39: typedef int (*PF)();                   /* generaly useful type */
        !            40:
        !            41: /*
        !            42:  * Table sizes, etc.
        !            43:  */
        !            44: #define NFILEN 80                      /* Length, file name.           */
        !            45: #define NBUFN  24                      /* Length, buffer name.         */
        !            46: #define NLINE  256                     /* Length, line.                */
        !            47: #define PBMODES 4                      /* modes per buffer             */
        !            48: #define NKBDM  256                     /* Length, keyboard macro.      */
        !            49: #define NPAT   80                      /* Length, pattern.             */
        !            50: #define HUGE   1000                    /* A rather large number.       */
        !            51: #define NSRCH  128                     /* Undoable search commands.    */
        !            52: #define NXNAME 64                      /* Length, extended command.    */
        !            53: #define NKNAME 20                      /* Length, key names            */
        !            54: /*
        !            55:  * Universal.
        !            56:  */
        !            57: #define FALSE  0                       /* False, no, bad, etc.         */
        !            58: #define TRUE   1                       /* True, yes, good, etc.        */
        !            59: #define ABORT  2                       /* Death, ^G, abort, etc.       */
        !            60:
        !            61: #define KPROMPT 2                      /* keyboard prompt              */
        !            62:
        !            63: /*
        !            64:  * These flag bits keep track of
        !            65:  * some aspects of the last command. The CFCPCN
        !            66:  * flag controls goal column setting. The CFKILL
        !            67:  * flag controls the clearing versus appending
        !            68:  * of data in the kill buffer.
        !            69:  */
        !            70: #define CFCPCN 0x0001                  /* Last command was C-P, C-N    */
        !            71: #define CFKILL 0x0002                  /* Last command was a kill      */
        !            72: #define CFINS  0x0004                  /* Last command was self-insert */
        !            73:
        !            74: /*
        !            75:  * File I/O.
        !            76:  */
        !            77: #define FIOSUC 0                       /* Success.                     */
        !            78: #define FIOFNF 1                       /* File not found.              */
        !            79: #define FIOEOF 2                       /* End of file.                 */
        !            80: #define FIOERR 3                       /* Error.                       */
        !            81: #define FIOLONG 4                      /* long line partially read     */
        !            82:
        !            83: /*
        !            84:  * Directory I/O.
        !            85:  */
        !            86: #define DIOSUC 0                       /* Success.                     */
        !            87: #define DIOEOF 1                       /* End of file.                 */
        !            88: #define DIOERR 2                       /* Error.                       */
        !            89:
        !            90: /*
        !            91:  * Display colors.
        !            92:  */
        !            93: #define CNONE  0                       /* Unknown color.               */
        !            94: #define CTEXT  1                       /* Text color.                  */
        !            95: #define CMODE  2                       /* Mode line color.             */
        !            96:
        !            97: /* Flags for keyboard involked functions */
        !            98:
        !            99: #define FFUNIV         1               /* universal argument           */
        !           100: #define FFNEGARG       2               /* negitive only argument       */
        !           101: #define FFOTHARG       4               /* other argument               */
        !           102: #define FFARG          7               /* any argument                 */
        !           103: #define FFRAND         8               /* Called by other function     */
        !           104:
        !           105: /*
        !           106:  * Flags for "eread".
        !           107:  */
        !           108: #define EFFUNC 0x0001                  /* Autocomplete functions.      */
        !           109: #define EFBUF  0x0002                  /* Autocomplete buffers.        */
        !           110: #define EFFILE 0x0004                  /* " files (maybe someday)      */
        !           111: #define EFAUTO 0x0007                  /* Some autocompleteion on      */
        !           112: #define EFNEW  0x0008                  /* New prompt.                  */
        !           113: #define EFCR   0x0010                  /* Echo CR at end; last read.   */
        !           114:
        !           115: /*
        !           116:  * Flags for "ldelete"/"kinsert"
        !           117:  */
        !           118:
        !           119: #define KNONE  0
        !           120: #define KFORW  1
        !           121: #define KBACK  2
        !           122:
        !           123: /*
        !           124:  * All text is kept in circularly linked
        !           125:  * lists of "LINE" structures. These begin at the
        !           126:  * header line (which is the blank line beyond the
        !           127:  * end of the buffer). This line is pointed to by
        !           128:  * the "BUFFER". Each line contains a the number of
        !           129:  * bytes in the line (the "used" size), the size
        !           130:  * of the text array, and the text. The end of line
        !           131:  * is not stored as a byte; it's implied. Future
        !           132:  * additions will include update hints, and a
        !           133:  * list of marks into the line.
        !           134:  */
        !           135: typedef struct LINE {
        !           136:        struct  LINE *l_fp;             /* Link to the next line        */
        !           137:        struct  LINE *l_bp;             /* Link to the previous line    */
        !           138:        int     l_size;                 /* Allocated size               */
        !           139:        int     l_used;                 /* Used size                    */
        !           140: #ifndef ZEROARRAY
        !           141:        char    l_text[1];              /* A bunch of characters.       */
        !           142: #else
        !           143:        char    l_text[];               /* A bunch of characters.       */
        !           144: #endif
        !           145: }      LINE;
        !           146:
        !           147: /*
        !           148:  * The rationale behind these macros is that you
        !           149:  * could (with some editing, like changing the type of a line
        !           150:  * link from a "LINE *" to a "REFLINE", and fixing the commands
        !           151:  * like file reading that break the rules) change the actual
        !           152:  * storage representation of lines to use something fancy on
        !           153:  * machines with small address spaces.
        !           154:  */
        !           155: #define lforw(lp)      ((lp)->l_fp)
        !           156: #define lback(lp)      ((lp)->l_bp)
        !           157: #define lgetc(lp, n)   (CHARMASK((lp)->l_text[(n)]))
        !           158: #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
        !           159: #define llength(lp)    ((lp)->l_used)
        !           160: #define ltext(lp)      ((lp)->l_text)
        !           161:
        !           162: /*
        !           163:  * All repeated structures are kept as linked lists of structures.
        !           164:  * All of these start with a LIST structure (except lines, which
        !           165:  * have their own abstraction). This will allow for
        !           166:  * later conversion to generic list manipulation routines should
        !           167:  * I decide to do that. it does mean that there are four extra
        !           168:  * bytes per window. I feel that this is an acceptable price,
        !           169:  * considering that there are usually only one or two windows.
        !           170:  */
        !           171: typedef struct LIST {
        !           172:        union {
        !           173:                struct WINDOW   *l_wp;
        !           174:                struct BUFFER   *x_bp;  /* l_bp is used by LINE */
        !           175:                struct LIST     *l_nxt;
        !           176:        } l_p;
        !           177:        char    *l_name;
        !           178: } LIST;
        !           179: /*
        !           180:  * Usual hack - to keep from uglifying the code with lotsa
        !           181:  * references through the union, we #define something for it.
        !           182:  */
        !           183: #define l_next l_p.l_nxt
        !           184:
        !           185: /*
        !           186:  * There is a window structure allocated for
        !           187:  * every active display window. The windows are kept in a
        !           188:  * big list, in top to bottom screen order, with the listhead at
        !           189:  * "wheadp". Each window contains its own values of dot and mark.
        !           190:  * The flag field contains some bits that are set by commands
        !           191:  * to guide redisplay; although this is a bit of a compromise in
        !           192:  * terms of decoupling, the full blown redisplay is just too
        !           193:  * expensive to run for every input character.
        !           194:  */
        !           195: typedef struct WINDOW {
        !           196:        LIST    w_list;                 /* List header                 */
        !           197:        struct  BUFFER *w_bufp;         /* Buffer displayed in window   */
        !           198:        struct  LINE *w_linep;          /* Top line in the window       */
        !           199:        struct  LINE *w_dotp;           /* Line containing "."          */
        !           200:        struct  LINE *w_markp;          /* Line containing "mark"       */
        !           201:        int     w_doto;                 /* Byte offset for "."          */
        !           202:        int     w_marko;                /* Byte offset for "mark"       */
        !           203:        char    w_toprow;               /* Origin 0 top row of window   */
        !           204:        char    w_ntrows;               /* # of rows of text in window  */
        !           205:        char    w_force;                /* If NZ, forcing row.          */
        !           206:        char    w_flag;                 /* Flags.                       */
        !           207: }      WINDOW;
        !           208: #define w_wndp w_list.l_p.l_wp
        !           209: #define w_name w_list.l_name
        !           210:
        !           211: /*
        !           212:  * Window flags are set by command processors to
        !           213:  * tell the display system what has happened to the buffer
        !           214:  * mapped by the window. Setting "WFHARD" is always a safe thing
        !           215:  * to do, but it may do more work than is necessary. Always try
        !           216:  * to set the simplest action that achieves the required update.
        !           217:  * Because commands set bits in the "w_flag", update will see
        !           218:  * all change flags, and do the most general one.
        !           219:  */
        !           220: #define WFFORCE 0x01                   /* Force reframe.               */
        !           221: #define WFMOVE 0x02                    /* Movement from line to line.  */
        !           222: #define WFEDIT 0x04                    /* Editing within a line.       */
        !           223: #define WFHARD 0x08                    /* Better to a full display.    */
        !           224: #define WFMODE 0x10                    /* Update mode line.            */
        !           225:
        !           226: /*
        !           227:  * Text is kept in buffers. A buffer header, described
        !           228:  * below, exists for every buffer in the system. The buffers are
        !           229:  * kept in a big list, so that commands that search for a buffer by
        !           230:  * name can find the buffer header. There is a safe store for the
        !           231:  * dot and mark in the header, but this is only valid if the buffer
        !           232:  * is not being displayed (that is, if "b_nwnd" is 0). The text for
        !           233:  * the buffer is kept in a circularly linked list of lines, with
        !           234:  * a pointer to the header line in "b_linep".
        !           235:  */
        !           236: typedef struct BUFFER {
        !           237:        LIST    b_list;                 /* buffer list pointer          */
        !           238:        struct  BUFFER *b_altb;         /* Link to alternate buffer     */
        !           239:        struct  LINE *b_dotp;           /* Link to "." LINE structure   */
        !           240:        struct  LINE *b_markp;          /* ditto for mark               */
        !           241:        struct  LINE *b_linep;          /* Link to the header LINE      */
        !           242:        struct  MAPS_S *b_modes[PBMODES]; /* buffer modes               */
        !           243:        int     b_doto;                 /* Offset of "." in above LINE  */
        !           244:        int     b_marko;                /* ditto for the "mark"         */
        !           245:        short   b_nmodes;               /* number of non-fundamental modes */
        !           246:        char    b_nwnd;                 /* Count of windows on buffer   */
        !           247:        char    b_flag;                 /* Flags                        */
        !           248:        char    b_fname[NFILEN];        /* File name                    */
        !           249:        struct  fileinfo b_fi;          /* File attributes              */
        !           250: }      BUFFER;
        !           251: #define b_bufp b_list.l_p.x_bp
        !           252: #define b_bname b_list.l_name
        !           253:
        !           254: #define BFCHG  0x01                    /* Changed.                     */
        !           255: #define BFBAK  0x02                    /* Need to make a backup.       */
        !           256: #ifdef NOTAB
        !           257: #define BFNOTAB 0x04                   /* no tab mode                  */
        !           258: #endif
        !           259: #define BFOVERWRITE 0x08               /* overwrite mode               */
        !           260:
        !           261: /*
        !           262:  * This structure holds the starting position
        !           263:  * (as a line/offset pair) and the number of characters in a
        !           264:  * region of a buffer. This makes passing the specification
        !           265:  * of a region around a little bit easier.
        !           266:  */
        !           267: typedef struct {
        !           268:        struct  LINE *r_linep;          /* Origin LINE address.         */
        !           269:        int     r_offset;               /* Origin LINE offset.          */
        !           270:        RSIZE   r_size;                 /* Length in characters.        */
        !           271: }      REGION;
        !           272:
        !           273: /*
        !           274:  * Externals.
        !           275:  */
        !           276: extern int     thisflag;
        !           277: extern int     lastflag;
        !           278: extern int     curgoal;
        !           279: extern int     epresf;
        !           280: extern int     sgarbf;
        !           281: extern int     mode;
        !           282: extern WINDOW  *curwp;
        !           283: extern BUFFER  *curbp;
        !           284: extern WINDOW  *wheadp;
        !           285: extern BUFFER  *bheadp;
        !           286: extern char    pat[];
        !           287: extern BUFFER  *bfind();
        !           288: extern WINDOW  *popbuf();
        !           289: extern WINDOW  *wpopup();
        !           290: extern LINE    *lalloc();
        !           291: extern LINE    *lallocx();
        !           292: extern VOID    ewprintf();
        !           293: extern int     nrow;
        !           294: extern int     ncol;
        !           295: extern int     ttrow;
        !           296: extern int     ttcol;
        !           297: extern int     tceeol;
        !           298: extern int     tcinsl;
        !           299: extern int     tcdell;
        !           300: extern char    cinfo[];
        !           301: extern char    *keystrings[];
        !           302: extern VOID    update();
        !           303: extern char    *keyname();
        !           304: extern char    *adjustname();
        !           305: extern VOID    kdelete();
        !           306: extern VOID    lchange();
        !           307: /*
        !           308:  * Standard I/O.
        !           309:  */
        !           310: extern char    *strcpy();
        !           311: extern char    *strcat();
        !           312: extern char    *malloc();