home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-02-03 | 58.7 KB | 2,446 lines |
- Path: xanth!mcnc!uvaarpa!umd5!ames!necntc!ncoast!allbery
- From: BLARSON@ECLA.USC.EDU (Bob Larson)
- Newsgroups: comp.sources.misc
- Subject: v03i028: mg 2a part 4 of 15
- Message-ID: <12401299447.47.BLARSON@ECLA.USC.EDU>
- Date: 26 May 88 04:52:27 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: BLARSON@ECLA.USC.EDU (Bob Larson)
- Lines: 2434
- Approved: allbery@ncoast.UUCP
-
- comp.sources.misc: Volume 3, Issue 28
- Submitted-By: "Bob Larson" <BLARSON@ECLA.USC.EDU>
- Archive-Name: mg2a/Part4
-
- # This is a shell archive.
- # Remove everything above and including the cut line.
- # Then run the rest of the file through sh.
- #----cut here-----cut here-----cut here-----cut here----#
- #!/bin/sh
- # shar: Shell Archiver
- # Run the following text with /bin/sh to create:
- # kbd.c
- # kbd.h
- # key.h
- # keymap.c
- # line.c
- # macro.h
- # main.c
- # This archive created: Tue May 17 18:06:01 1988
- # By: blarson
- cat << \SHAR_EOF > kbd.c
- /*
- * Terminal independent keyboard handling.
- */
- #include "def.h"
- #include "kbd.h"
-
- #define EXTERN
- #include "key.h"
-
- #ifndef NO_MACRO
- #include "macro.h"
- #endif
-
- #ifdef DO_METAKEY
- #ifndef METABIT
- #define METABIT 0x80
- #endif
-
- int use_metakey = TRUE;
-
- /*
- * Toggle the value of use_metakey
- */
- do_meta(f, n)
- {
- if(f & FFARG) use_metakey = n > 0;
- else use_metakey = !use_metakey;
- ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis");
- return TRUE;
- }
- #endif
-
- #ifdef BSMAP
- static int bs_map = BSMAP;
- /*
- * Toggle backspace mapping
- */
- bsmap(f, n)
- {
- if(f & FFARG) bs_map = n > 0;
- else bs_map = ! bs_map;
- ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis");
- return TRUE;
- }
- #endif
-
- #ifndef NO_DPROMPT
- #define PROMPTL 80
- char prompt[PROMPTL], *promptp;
- #endif
-
- static int pushed = FALSE;
- static int pushedc;
-
- VOID ungetkey(c)
- int c;
- {
- #ifdef DO_METAKEY
- if(use_metakey && pushed && c==CCHR('[')) pushedc |= METABIT;
- else
- #endif
- pushedc = c;
- pushed = TRUE;
- }
-
- int getkey(flag)
- int flag;
- {
- int c;
- char *keyname();
-
- #ifndef NO_DPROMPT
- if(flag && !pushed) {
- if(prompt[0]!='\0' && ttwait()) {
- ewprintf("%s", prompt); /* avoid problems with % */
- update(); /* put the cursor back */
- epresf = KPROMPT;
- }
- if(promptp > prompt) *(promptp-1) = ' ';
- }
- #endif
- if(pushed) {
- c = pushedc;
- pushed = FALSE;
- } else c = getkbd();
- #ifdef BSMAP
- if(bs_map)
- if(c==CCHR('H')) c=CCHR('?');
- else if(c==CCHR('?')) c=CCHR('H');
- #endif
- #ifdef DO_METAKEY
- if(use_metakey && (c&METABIT)) {
- pushedc = c & ~METABIT;
- pushed = TRUE;
- c = CCHR('[');
- }
- #endif
- #ifndef NO_DPROMPT
- if(flag && promptp < &prompt[PROMPTL - 5]) {
- promptp = keyname(promptp, c);
- *promptp++ = '-';
- *promptp = '\0';
- }
- #endif
- return c;
- }
-
- /*
- * doscan scans a keymap for a keyboard character and returns a pointer
- * to the function associated with that character. Sets ele to the
- * keymap element the keyboard was found in as a side effect.
- */
-
- MAP_ELEMENT *ele;
-
- PF doscan(map, c)
- register KEYMAP *map;
- register int c;
- {
- register MAP_ELEMENT *elec = &map->map_element[0]; /* local register copy for faster access */
- register MAP_ELEMENT *last = &map->map_element[map->map_num];
-
- while(elec < last && c > elec->k_num) elec++;
- ele = elec; /* used by prefix and binding code */
- if(elec >= last || c < elec->k_base)
- return map->map_default;
- return elec->k_funcp[c - elec->k_base];
- }
-
- doin()
- {
- KEYMAP *curmap;
- PF funct;
-
- #ifndef NO_DPROMPT
- *(promptp = prompt) = '\0';
- #endif
- curmap = curbp->b_modes[curbp->b_nmodes]->p_map;
- key.k_count = 0;
- while((funct=doscan(curmap,(key.k_chars[key.k_count++]=getkey(TRUE))))
- == prefix)
- curmap = ele->k_prefmap;
- #ifndef NO_MACRO
- if(macrodef && macrocount < MAXMACRO)
- macro[macrocount++].m_funct = funct;
- #endif
- return (*funct)(0, 1);
- }
-
- rescan(f, n)
- int f, n;
- {
- int c;
- register KEYMAP *curmap;
- int i;
- PF fp;
- int mode = curbp->b_nmodes;
-
- for(;;) {
- if(ISUPPER(key.k_chars[key.k_count-1])) {
- c = TOLOWER(key.k_chars[key.k_count-1]);
- curmap = curbp->b_modes[mode]->p_map;
- for(i=0; i < key.k_count-1; i++) {
- if((fp=doscan(curmap,(key.k_chars[i]))) != prefix) break;
- curmap = ele->k_prefmap;
- }
- if(fp==prefix) {
- if((fp = doscan(curmap, c)) == prefix)
- while((fp=doscan(curmap,key.k_chars[key.k_count++] =
- getkey(TRUE))) == prefix)
- curmap = ele->k_prefmap;
- if(fp!=rescan) {
- #ifndef NO_MACRO
- if(macrodef && macrocount <= MAXMACRO)
- macro[macrocount-1].m_funct = fp;
- #endif
- return (*fp)(f, n);
- }
- }
- }
- /* try previous mode */
- if(--mode < 0) return ABORT;
- curmap = curbp->b_modes[mode]->p_map;
- for(i=0; i < key.k_count; i++) {
- if((fp=doscan(curmap,(key.k_chars[i]))) != prefix) break;
- curmap = ele->k_prefmap;
- }
- if(fp==prefix) {
- while((fp=doscan(curmap,key.k_chars[i++]=getkey(TRUE)))
- == prefix)
- curmap = ele->k_prefmap;
- key.k_count = i;
- }
- if(fp!=rescan && i>=key.k_count-1) {
- #ifndef NO_MACRO
- if(macrodef && macrocount <= MAXMACRO)
- macro[macrocount-1].m_funct = fp;
- #endif
- return (*fp)(f, n);
- }
- }
- }
-
- universal_argument(f, n)
- int f, n;
- {
- int c, nn=4;
- KEYMAP *curmap;
- PF funct;
-
- if(f&FFUNIV) nn *= n;
- for(;;) {
- key.k_chars[0] = c = getkey(TRUE);
- key.k_count = 1;
- if(c == '-') return negative_argument(f, nn);
- if(c >= '0' && c <= '9') return digit_argument(f, nn);
- curmap = curbp->b_modes[curbp->b_nmodes]->p_map;
- while((funct=doscan(curmap,c)) == prefix) {
- curmap = ele->k_prefmap;
- key.k_chars[key.k_count++] = c = getkey(TRUE);
- }
- if(funct != universal_argument) {
- #ifndef NO_MACRO
- if(macrodef && macrocount < MAXMACRO-1) {
- if(f&FFARG) macrocount--;
- macro[macrocount++].m_count = nn;
- macro[macrocount++].m_funct = funct;
- }
- #endif
- return (*funct)(FFUNIV, nn);
- }
- nn <<= 2;
- }
- }
-
- /*ARGSUSED*/
- digit_argument(f, n)
- int f, n;
- {
- int nn, c;
- KEYMAP *curmap;
- PF funct;
-
- nn = key.k_chars[key.k_count-1] - '0';
- for(;;) {
- c = getkey(TRUE);
- if(c < '0' || c > '9') break;
- nn *= 10;
- nn += c - '0';
- }
- key.k_chars[0] = c;
- key.k_count = 1;
- curmap = curbp->b_modes[curbp->b_nmodes]->p_map;
- while((funct=doscan(curmap,c)) == prefix) {
- curmap = ele->k_prefmap;
- key.k_chars[key.k_count++] = c = getkey(TRUE);
- }
- #ifndef NO_MACRO
- if(macrodef && macrocount < MAXMACRO-1) {
- if(f&FFARG) macrocount--;
- else macro[macrocount-1].m_funct = universal_argument;
- macro[macrocount++].m_count = nn;
- macro[macrocount++].m_funct = funct;
- }
- #endif
- return (*funct)(FFOTHARG, nn);
- }
-
- negative_argument(f, n)
- int f, n;
- {
- int nn = 0, c;
- KEYMAP *curmap;
- PF funct;
-
- for(;;) {
- c = getkey(TRUE);
- if(c < '0' || c > '9') break;
- nn *= 10;
- nn += c - '0';
- }
- if(nn) nn = -nn;
- else nn = -n;
- key.k_chars[0] = c;
- key.k_count = 1;
- curmap = curbp->b_modes[curbp->b_nmodes]->p_map;
- while((funct=doscan(curmap,c)) == prefix) {
- curmap = ele->k_prefmap;
- key.k_chars[key.k_count++] = c = getkey(TRUE);
- }
- #ifndef NO_MACRO
- if(macrodef && macrocount < MAXMACRO-1) {
- if(f&FFARG) macrocount--;
- else macro[macrocount-1].m_funct = universal_argument;
- macro[macrocount++].m_count = nn;
- macro[macrocount++].m_funct = funct;
- }
- #endif
- return (*funct)(FFNEGARG, nn);
- }
-
- /*
- * Insert a character. While defining a macro, create a "LINE" containing
- * all inserted characters.
- */
-
- selfinsert(f, n)
- int f, n;
- {
- register int c;
- int count;
- VOID lchange();
- #ifndef NO_MACRO
- LINE *lp;
- int insert();
- #endif
-
- if (n < 0) return FALSE;
- if (n == 0) return TRUE;
- c = key.k_chars[key.k_count-1];
- #ifndef NO_MACRO
- if(macrodef && macrocount < MAXMACRO) {
- if(f & FFARG) macrocount -= 2;
- if(lastflag & CFINS) { /* last command was insert -- tack on end */
- macrocount--;
- if(maclcur->l_size < maclcur->l_used + n) {
- if((lp = lallocx(maclcur->l_used + n)) == NULL)
- return FALSE;
- lp->l_fp = maclcur->l_fp;
- lp->l_bp = maclcur->l_bp;
- lp->l_fp->l_bp = lp->l_bp->l_fp = lp;
- bcopy(maclcur->l_text, lp->l_text, maclcur->l_used);
- for(count = maclcur->l_used; count < lp->l_used; count++)
- lp->l_text[count] = c;
- free((char *)maclcur);
- maclcur = lp;
- } else {
- maclcur->l_used += n;
- for(count = maclcur->l_used-n; count < maclcur->l_used; count++)
- maclcur->l_text[count] = c;
- }
- } else {
- macro[macrocount-1].m_funct = insert;
- if((lp = lallocx(n)) == NULL) return FALSE;
- lp->l_bp = maclcur;
- lp->l_fp = maclcur->l_fp;
- maclcur->l_fp = lp;
- maclcur = lp;
- for(count = 0; count < n; count++)
- lp->l_text[count] = c;
- }
- thisflag |= CFINS;
- }
- #endif
- if(c == '\n') {
- do {
- count = lnewline();
- } while (--n && count==TRUE);
- return count;
- }
- if(curbp->b_flag & BFOVERWRITE) { /* Overwrite mode */
- lchange(WFEDIT);
- while(curwp->w_doto < llength(curwp->w_dotp) && n--)
- lputc(curwp->w_dotp, curwp->w_doto++, c);
- if(n<=0) return TRUE;
- }
- return linsert(n, c);
- }
-
- /*
- * this could be implemented as a keymap with everthing defined
- * as self-insert.
- */
- quote(f, n)
- {
- register int c;
-
- key.k_count = 1;
- if((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') {
- key.k_chars[0] -= '0';
- if((c = getkey(TRUE)) >= '0' && c <= '7') {
- key.k_chars[0] <<= 3;
- key.k_chars[0] += c - '0';
- if((c = getkey(TRUE)) >= '0' && c <= '7') {
- key.k_chars[0] <<= 3;
- key.k_chars[0] += c - '0';
- } else ungetkey(c);
- } else ungetkey(c);
- }
- return selfinsert(f, n);
- }
- SHAR_EOF
- cat << \SHAR_EOF > kbd.h
- /*
- * kbd.h: type definitions for symbol.c and kbd.c for mg experimental
- */
-
- typedef struct {
- KCHAR k_base; /* first key in element */
- KCHAR k_num; /* last key in element */
- PF *k_funcp; /* pointer to array of pointers to functions */
- struct keymap_s *k_prefmap; /* keymap of ONLY prefix key in element */
- } MAP_ELEMENT;
-
- /* predefined keymaps are NOT type KEYMAP because final array needs
- * dimension. If any changes are made to this struct, they must be
- * reflected in all keymap declarations.
- */
-
- #define KEYMAPE(NUM) {\
- short map_num;\
- short map_max;\
- PF map_default;\
- MAP_ELEMENT map_element[NUM];\
- }
- /* elements used */
- /* elements allocated */
- /* default function */
- /* realy [e_max] */
- typedef struct keymap_s KEYMAPE(1) KEYMAP;
-
- #define none ctrlg
- #define prefix (PF)NULL
-
- /* number of map_elements to grow an overflowed keymap by */
- #define IMAPEXT 0
- #define MAPGROW 3
- #define MAPINIT (MAPGROW+1)
-
- /* max number of default bindings added to avoid creating new element */
- #define MAPELEDEF 4
-
- typedef struct MAPS_S {
- KEYMAP *p_map;
- char *p_name;
- } MAPS;
-
- extern MAPS map_table[];
-
- typedef struct {
- PF n_funct;
- char *n_name;
- } FUNCTNAMES;
-
- extern FUNCTNAMES functnames[];
- extern int nfunct;
-
- extern PF doscan();
- extern PF name_function();
- extern char *function_name();
- extern int complete_function();
- extern KEYMAP *name_map();
- extern char *map_name();
- extern MAPS *name_mode();
-
- extern MAP_ELEMENT *ele;
- SHAR_EOF
- cat << \SHAR_EOF > key.h
- /* key.h: Insert file for mg 2 functions that need to reference key pressed */
-
- #ifndef EXTERN
- #define EXTERN extern
- #endif
-
- #define MAXKEY 8 /* maximum number of prefix chars */
-
- EXTERN struct { /* the chacter sequence in a key */
- int k_count; /* number of chars */
- KCHAR k_chars[MAXKEY]; /* chars */
- } key;
- #undef EXTERN
- SHAR_EOF
- cat << \SHAR_EOF > keymap.c
- /*
- * Keyboard maps. This is character set dependent.
- * The terminal specific parts of building the
- * keymap has been moved to a better place.
- */
- #include "def.h"
- #include "kbd.h"
-
- /*
- * Defined by "basic.c".
- */
- extern int gotobol(); /* Move to start of line */
- extern int backchar(); /* Move backward by characters */
- extern int gotoeol(); /* Move to end of line */
- extern int forwchar(); /* Move forward by characters */
- extern int gotobob(); /* Move to start of buffer */
- extern int gotoeob(); /* Move to end of buffer */
- extern int forwline(); /* Move forward by lines */
- extern int backline(); /* Move backward by lines */
- extern int forwpage(); /* Move forward by pages */
- extern int backpage(); /* Move backward by pages */
- extern int pagenext(); /* Page forward next window */
- extern int setmark(); /* Set mark */
- extern int swapmark(); /* Swap "." and mark */
- extern int gotoline(); /* Go to a specified line. */
- #ifdef GOSMACS
- extern int forw1page(); /* move forward by lines */
- extern int back1page(); /* move back by lines */
- #endif
-
- /*
- * Defined by "buffer.c".
- */
- extern int listbuffers(); /* Display list of buffers */
- extern int usebuffer(); /* Switch a window to a buffer */
- extern int poptobuffer(); /* Other window to a buffer */
- extern int killbuffer(); /* Make a buffer go away. */
- extern int savebuffers(); /* Save unmodified buffers */
- extern int bufferinsert(); /* Insert buffer into another */
- extern int notmodified(); /* Reset modification flag */
-
- #ifndef NO_DIR
- /*
- * Defined by "dir.c"
- */
- extern int changedir(); /* change current directory */
- extern int showcwdir(); /* show current directory */
-
- #ifndef NO_DIRED
- /*
- * defined by "dired.c"
- */
- extern int dired(); /* dired */
- extern int d_findfile(); /* dired find file */
- extern int d_del(); /* dired mark for deletion */
- extern int d_undel(); /* dired unmark */
- extern int d_undelbak(); /* dired unmark backwards */
- extern int d_expunge(); /* dired expunge */
- extern int d_copy(); /* dired copy */
- extern int d_rename(); /* dired rename */
- extern int d_otherwindow(); /* dired other window */
- extern int d_ffotherwindow(); /* dired find file other window */
- #endif
- #endif
-
- /*
- * Defined by "extend.c".
- */
- extern int extend(); /* Extended commands. */
- extern int bindtokey(); /* Modify global key bindings. */
- extern int localbind(); /* Modify mode key bindings. */
- extern int define_key(); /* modify any key map */
- extern int unbindtokey(); /* delete global binding */
- extern int localunbind(); /* delete local binding */
- extern int insert(); /* insert string */
- #ifndef NO_STARTUP
- extern int evalexpr(); /* Extended commands (again) */
- extern int evalbuffer(); /* Evaluate current buffer */
- extern int evalfile(); /* Evaluate a file */
- #endif
-
- /*
- * Defined by "file.c".
- */
- extern int filevisit(); /* Get a file, read write */
- extern int poptofile(); /* Get a file, other window */
- extern int filewrite(); /* Write a file */
- extern int filesave(); /* Save current file */
- extern int fileinsert(); /* Insert file into buffer */
- #ifndef NO_BACKUP
- extern int makebkfile(); /* Control backups on saves */
- #endif
-
- /*
- * defined by help.c
- */
- #ifndef NO_HELP
- extern int desckey(); /* describe key */
- extern int wallchart(); /* Make wall chart. */
- extern int help_help(); /* help help */
- extern int apropos_command(); /* apropos */
- #endif
-
- /*
- * defined by "kbd.c"
- */
- #ifdef DO_METAKEY
- extern int do_meta(); /* interpret meta keys */
- #endif
- #ifdef BSMAP
- extern int bsmap(); /* backspace mapping */
- #endif
- extern int universal_argument(); /* Ctrl-U */
- extern int digit_argument(); /* M-1, etc. */
- extern int negative_argument(); /* M-- */
- extern int selfinsert(); /* Insert character */
- extern int rescan(); /* internal try again function */
-
- /*
- * defined by "macro.c"
- */
- #ifndef NO_MACRO
- extern int definemacro(); /* Begin macro */
- extern int finishmacro(); /* End macro */
- extern int executemacro(); /* Execute macro */
- #endif
-
- /*
- * Defined by "main.c".
- */
- extern int ctrlg(); /* Abort out of things */
- extern int quit(); /* Quit */
-
- /*
- * Defined by "match.c"
- */
- extern int showmatch(); /* Hack to show matching paren */
-
- /* defined by "modes.c" */
-
- extern int indentmode(); /* set auto-indent mode */
- extern int fillmode(); /* set word-wrap mode */
- extern int blinkparen(); /* Fake blink-matching-paren var */
- #ifdef NOTAB
- extern int notabmode(); /* no tab mode */
- #endif
- extern int overwrite(); /* overwrite mode */
- extern int set_default_mode(); /* set default modes */
-
- /*
- * defined by "paragraph.c" - the paragraph justification code.
- */
- extern int gotobop(); /* Move to start of paragraph. */
- extern int gotoeop(); /* Move to end of paragraph. */
- extern int fillpara(); /* Justify a paragraph. */
- extern int killpara(); /* Delete a paragraph. */
- extern int setfillcol(); /* Set fill column for justify. */
- extern int fillword(); /* Insert char with word wrap. */
-
- /*
- * Defined by "random.c".
- */
- extern int showcpos(); /* Show the cursor position */
- extern int twiddle(); /* Twiddle characters */
- extern int quote(); /* Insert literal */
- extern int openline(); /* Open up a blank line */
- extern int newline(); /* Insert newline */
- extern int deblank(); /* Delete blank lines */
- extern int justone(); /* Delete extra whitespace */
- extern int delwhite(); /* Delete all whitespace */
- extern int indent(); /* Insert newline, then indent */
- extern int forwdel(); /* Forward delete */
- extern int backdel(); /* Backward delete in */
- extern int killline(); /* Kill forward */
- extern int yank(); /* Yank back from killbuffer. */
- #ifdef NOTAB
- extern int space_to_tabstop();
- #endif
-
- #ifdef REGEX
- /*
- * Defined by "re_search.c"
- */
- extern int re_forwsearch(); /* Regex search forward */
- extern int re_backsearch(); /* Regex search backwards */
- extern int re_searchagain(); /* Repeat regex search command */
- extern int re_queryrepl(); /* Regex query replace */
- extern int setcasefold(); /* Set case fold in searches */
- extern int delmatchlines(); /* Delete all lines matching */
- extern int delnonmatchlines(); /* Delete all lines not matching */
- extern int cntmatchlines(); /* Count matching lines */
- extern int cntnonmatchlines(); /* Count nonmatching lines */
- #endif
-
- /*
- * Defined by "region.c".
- */
- extern int killregion(); /* Kill region. */
- extern int copyregion(); /* Copy region to kill buffer. */
- extern int lowerregion(); /* Lower case region. */
- extern int upperregion(); /* Upper case region. */
- #ifdef PREFIXREGION
- extern int prefixregion(); /* Prefix all lines in region */
- extern int setprefix(); /* Set line prefix string */
- #endif
-
- /*
- * Defined by "search.c".
- */
- extern int forwsearch(); /* Search forward */
- extern int backsearch(); /* Search backwards */
- extern int searchagain(); /* Repeat last search command */
- extern int forwisearch(); /* Incremental search forward */
- extern int backisearch(); /* Incremental search backwards */
- extern int queryrepl(); /* Query replace */
-
- /*
- * Defined by "spawn.c".
- */
- extern int spawncli(); /* Run CLI in a subjob. */
- #ifdef VMS
- extern int attachtoparent(); /* Attach to parent process */
- #endif
-
- /* defined by "version.c" */
-
- extern int showversion(); /* Show version numbers, etc. */
-
- /*
- * Defined by "window.c".
- */
- extern int reposition(); /* Reposition window */
- extern int refresh(); /* Refresh the screen */
- extern int nextwind(); /* Move to the next window */
- #ifdef GOSMACS
- extern int prevwind(); /* Move to the previous window */
- #endif
- extern int onlywind(); /* Make current window only one */
- extern int splitwind(); /* Split current window */
- extern int delwind(); /* Delete current window */
- extern int enlargewind(); /* Enlarge display window. */
- extern int shrinkwind(); /* Shrink window. */
-
- /*
- * Defined by "word.c".
- */
- extern int backword(); /* Backup by words */
- extern int forwword(); /* Advance by words */
- extern int upperword(); /* Upper case word. */
- extern int lowerword(); /* Lower case word. */
- extern int capword(); /* Initial capitalize word. */
- extern int delfword(); /* Delete forward word. */
- extern int delbword(); /* Delete backward word. */
-
- #ifdef AMIGA
- #ifdef DO_ICONIFY
- extern int tticon();
- #endif
- #ifdef DO_MENU
- extern int amigamenu(); /* Menu function */
- #endif
- #ifdef MOUSE
- extern int amigamouse(); /* Amiga mouse functions */
- extern int mgotobob();
- extern int mforwdel();
- extern int mdelwhite();
- extern int mdelwind();
- extern int mgotoeob();
- extern int menlargewind();
- extern int mkillline();
- extern int mkillregion();
- extern int mdelfword();
- extern int mreposition();
- extern int mbackpage();
- extern int mforwpage();
- extern int mshrinkwind();
- extern int msplitwind();
- extern int myank();
- #endif MOUSE
-
- extern int togglewindow(); /* Defined by "ttyio.c" */
- extern int togglezooms(); /* "" "" */
-
- #ifdef CHANGE_FONT
- extern int setfont(); /* Defined by "ttyio.c" */
- #endif
-
- #ifdef CHANGE_COLOR
- /* functions to mess with the mode line rendition, window colors*/
- extern int ttmode(); /* Defined by "tty.c" */
- extern int tttext(); /* "" */
- extern int textforeground(); /* "" */
- extern int textbackground(); /* "" */
- extern int modeforeground(); /* "" */
- extern int modebackground(); /* "" */
- #endif
-
- /*
- * This file contains map segment definitions for adding function keys to
- * keymap declarations. Currently you can add things to the fundamental
- * mode keymap and the dired mode keymap. See the declaration of
- * diredmap and fundmap for details.
- */
- #include "amiga_maps.c"
-
- #endif /* AMIGA */
-
- /* initial keymap declarations, deepest first */
-
- #ifndef NO_HELP
- static PF cHcG[] = {
- ctrlg, /* ^G */
- help_help, /* ^H */
- };
- static PF cHa[] = {
- apropos_command,/* a */
- wallchart, /* b */
- desckey, /* c */
- };
- static struct KEYMAPE(2+IMAPEXT) helpmap = {
- 2,
- 2+IMAPEXT,
- rescan,
- {
- {CCHR('G'),CCHR('H'), cHcG, (KEYMAP *)NULL},
- {'a', 'c', cHa, (KEYMAP *)NULL},
- }
- };
- #endif
-
- static PF cX4cF[] = {
- poptofile, /* ^f */
- ctrlg, /* ^g */
- };
- static PF cX4b[] = {
- poptobuffer, /* b */
- rescan, /* c */
- rescan, /* d */
- rescan, /* e */
- poptofile, /* f */
- };
- static struct KEYMAPE(2+IMAPEXT) cX4map = {
- 2,
- 2+IMAPEXT,
- rescan,
- {
- {CCHR('F'),CCHR('G'), cX4cF, (KEYMAP *)NULL},
- {'b', 'f', cX4b, (KEYMAP *)NULL},
- }
- };
-
- static PF cXcB[] = {
- listbuffers, /* ^B */
- quit, /* ^C */
- rescan, /* ^D */
- rescan, /* ^E */
- filevisit, /* ^F */
- ctrlg, /* ^G */
- };
- static PF cXcL[] = {
- lowerregion, /* ^L */
- rescan, /* ^M */
- rescan, /* ^N */
- deblank, /* ^O */
- rescan, /* ^P */
- rescan, /* ^Q */
- rescan, /* ^R */
- filesave, /* ^S */
- rescan, /* ^T */
- upperregion, /* ^U */
- rescan, /* ^V */
- filewrite, /* ^W */
- swapmark, /* ^X */
- };
- #ifndef NO_MACRO
- static PF cXlp[] = {
- definemacro, /* ( */
- finishmacro, /* ) */
- };
- #endif
- static PF cX0[] = {
- delwind, /* 0 */
- onlywind, /* 1 */
- splitwind, /* 2 */
- rescan, /* 3 */
- prefix, /* 4 */
- };
- static PF cXeq[] = {
- showcpos, /* = */
- };
- static PF cXcar[] = {
- enlargewind, /* ^ */
- rescan, /* _ */
- rescan, /* ` */
- rescan, /* a */
- usebuffer, /* b */
- rescan, /* c */
- #ifndef NO_DIRED
- dired, /* d */
- #else
- rescan, /* d */
- #endif
- #ifndef NO_MACRO
- executemacro, /* e */
- #else
- rescan, /* e */
- #endif
- setfillcol, /* f */
- rescan, /* g */
- rescan, /* h */
- fileinsert, /* i */
- rescan, /* j */
- killbuffer, /* k */
- rescan, /* l */
- rescan, /* m */
- rescan, /* n */
- nextwind, /* o */
- rescan, /* p */
- rescan, /* q */
- rescan, /* r */
- savebuffers, /* s */
- };
- #ifndef NO_MACRO
- static struct KEYMAPE(6+IMAPEXT) cXmap = {
- 6,
- 6+IMAPEXT,
- #else
- static struct KEYMAPE(5+IMAPEXT) cXmap = {
- 5,
- 5+IMAPEXT,
- #endif
- rescan,
- {
- {CCHR('B'),CCHR('G'), cXcB, (KEYMAP *)NULL},
- {CCHR('L'),CCHR('X'), cXcL, (KEYMAP *)NULL},
- #ifndef NO_MACRO
- {'(', ')', cXlp, (KEYMAP *)NULL},
- #endif
- {'0', '4', cX0, (KEYMAP *)&cX4map},
- {'=', '=', cXeq, (KEYMAP *)NULL},
- {'^', 's', cXcar, (KEYMAP *)NULL},
- }
- };
-
- static PF metacG[] = {
- ctrlg, /* ^G */
- };
- static PF metacV[] = {
- pagenext, /* ^V */
- };
- static PF metasp[] = {
- justone, /* space */
- };
- static PF metapct[] = {
- queryrepl, /* % */
- };
- static PF metami[] = {
- negative_argument, /* - */
- rescan, /* . */
- rescan, /* / */
- digit_argument, /* 0 */
- digit_argument, /* 1 */
- digit_argument, /* 2 */
- digit_argument, /* 3 */
- digit_argument, /* 4 */
- digit_argument, /* 5 */
- digit_argument, /* 6 */
- digit_argument, /* 7 */
- digit_argument, /* 8 */
- digit_argument, /* 9 */
- rescan, /* : */
- rescan, /* ; */
- gotobob, /* < */
- rescan, /* = */
- gotoeob, /* > */
- };
- static PF metalb[] = {
- gotobop, /* [ */
- delwhite, /* \ */
- gotoeop, /* ] */
- rescan, /* ^ */
- rescan, /* _ */
- rescan, /* ` */
- rescan, /* a */
- backword, /* b */
- capword, /* c */
- delfword, /* d */
- rescan, /* e */
- forwword, /* f */
- };
- static PF metal[] = {
- lowerword, /* l */
- rescan, /* m */
- rescan, /* n */
- rescan, /* o */
- rescan, /* p */
- fillpara, /* q */
- backsearch, /* r */
- forwsearch, /* s */
- rescan, /* t */
- upperword, /* u */
- backpage, /* v */
- copyregion, /* w */
- extend, /* x */
- };
- static PF metatilde[] = {
- notmodified, /* ~ */
- delbword, /* DEL */
- };
- static struct KEYMAPE(8+IMAPEXT) metamap = {
- 8,
- 8+IMAPEXT,
- rescan,
- {
- {CCHR('G'),CCHR('G'), metacG, (KEYMAP *)NULL},
- {CCHR('V'),CCHR('V'), metacV, (KEYMAP *)NULL},
- {' ', ' ', metasp, (KEYMAP *)NULL},
- {'%', '%', metapct,(KEYMAP *)NULL},
- {'-', '>', metami, (KEYMAP *)NULL},
- {'[', 'f', metalb, (KEYMAP *)NULL},
- {'l', 'x', metal, (KEYMAP *)NULL},
- {'~', CCHR('?'), metatilde,(KEYMAP *)NULL},
- }
- };
-
- static PF fund_at[] = {
- setmark, /* ^@ */
- gotobol, /* ^A */
- backchar, /* ^B */
- rescan, /* ^C */
- forwdel, /* ^D */
- gotoeol, /* ^E */
- forwchar, /* ^F */
- ctrlg, /* ^G */
- #ifndef NO_HELP
- prefix, /* ^H */
- #else
- rescan, /* ^H */
- #endif
- };
- /* ^I is selfinsert */
- static PF fund_CJ[] = {
- indent, /* ^J */
- killline, /* ^K */
- reposition, /* ^L */
- newline, /* ^M */
- forwline, /* ^N */
- openline, /* ^O */
- backline, /* ^P */
- quote, /* ^Q */
- backisearch, /* ^R */
- forwisearch, /* ^S */
- twiddle, /* ^T */
- universal_argument, /* ^U */
- forwpage, /* ^V */
- killregion, /* ^W */
- prefix, /* ^X */
- yank, /* ^Y */
- #ifndef VMS
- spawncli, /* ^Z */
- #else
- attachtoparent, /* ^Z */
- #endif
- };
- static PF fund_esc[] = {
- prefix, /* esc */
- rescan, /* ^\ */ /* selfinsert is default on fundamental */
- rescan, /* ^] */
- rescan, /* ^^ */
- rescan, /* ^_ */
- };
- static PF fund_del[] = {
- backdel, /* DEL */
- };
-
- #ifndef FUND_XMAPS
- #define NFUND_XMAPS 0 /* extra map sections after normal ones */
- #endif
-
- static struct KEYMAPE(4+NFUND_XMAPS+IMAPEXT) fundmap = {
- 4 + NFUND_XMAPS,
- 4 + NFUND_XMAPS + IMAPEXT,
- selfinsert,
- {
- #ifndef NO_HELP
- {CCHR('@'),CCHR('H'), fund_at, (KEYMAP *)&helpmap},
- #else
- {CCHR('@'),CCHR('H'), fund_at, (KEYMAP *)NULL},
- #endif
- {CCHR('J'),CCHR('Z'), fund_CJ, (KEYMAP *)&cXmap},
- {CCHR('['),CCHR('_'), fund_esc,(KEYMAP *)&metamap},
- {CCHR('?'),CCHR('?'), fund_del,(KEYMAP *)NULL},
- #ifdef FUND_XMAPS
- FUND_XMAPS,
- #endif
- }
- };
-
- static PF fill_sp[] = {
- fillword, /* ' ' */
- };
- static struct KEYMAPE(1+IMAPEXT) fillmap = {
- 1,
- 1+IMAPEXT,
- rescan,
- {
- {' ', ' ', fill_sp, (KEYMAP *)NULL},
- }
- };
-
- static PF indent_lf[] = {
- newline, /* ^J */
- rescan, /* ^K */
- rescan, /* ^L */
- indent, /* ^M */
- };
- static struct KEYMAPE(1+IMAPEXT) indntmap = {
- 1,
- 1+IMAPEXT,
- rescan,
- {
- {CCHR('J'), CCHR('M'), indent_lf, (KEYMAP *)NULL},
- }
- };
- static PF blink_rp[] = {
- showmatch, /* ) */
- };
- static struct KEYMAPE(1+IMAPEXT) blinkmap = {
- 1,
- 1+IMAPEXT,
- rescan,
- {
- {')', ')', blink_rp, (KEYMAP *)NULL},
- }
- };
-
- #ifdef NOTAB
- static PF notab_tab[] = {
- space_to_tabstop, /* ^I */
- };
- static struct KEYMAPE(1+IMAPEXT) notabmap = {
- 1,
- 1+IMAPEXT,
- rescan,
- {
- {CCHR('I'),CCHR('I'), notab_tab, (KEYMAP *)NULL},
- }
- };
- #endif
-
- static struct KEYMAPE(1+IMAPEXT) overwmap = {
- 0,
- 1+IMAPEXT, /* 1 to avoid 0 sized array */
- rescan,
- {
- /* unused dummy entry for VMS C */
- {(KCHAR)0, (KCHAR)0, (PF *)NULL, (KEYMAP *)NULL},
- }
- };
-
- #ifndef NO_DIRED
- static PF dirednul[] = {
- setmark, /* ^@ */
- gotobol, /* ^A */
- backchar, /* ^B */
- rescan, /* ^C */
- d_del, /* ^D */
- gotoeol, /* ^E */
- forwchar, /* ^F */
- ctrlg, /* ^G */
- #ifndef NO_HELP
- prefix, /* ^H */
- #endif
- };
- static PF diredcl[] = {
- reposition, /* ^L */
- forwline, /* ^M */
- forwline, /* ^N */
- rescan, /* ^O */
- backline, /* ^P */
- rescan, /* ^Q */
- backisearch, /* ^R */
- forwisearch, /* ^S */
- rescan, /* ^T */
- universal_argument, /* ^U */
- forwpage, /* ^V */
- rescan, /* ^W */
- prefix, /* ^X */
- };
- static PF diredcz[] = {
- #ifndef VMS
- spawncli, /* ^Z */
- #else
- attachtoparent, /* ^Z */
- #endif
- prefix, /* esc */
- rescan, /* ^\ */
- rescan, /* ^] */
- rescan, /* ^^ */
- rescan, /* ^_ */
- forwline, /* SP */
- };
- static PF diredc[] = {
- d_copy, /* c */
- d_del, /* d */
- d_findfile, /* e */
- d_findfile, /* f */
- };
- static PF diredn[] = {
- forwline, /* n */
- d_ffotherwindow,/* o */
- backline, /* p */
- rescan, /* q */
- d_rename, /* r */
- rescan, /* s */
- rescan, /* t */
- d_undel, /* u */
- rescan, /* v */
- rescan, /* w */
- d_expunge, /* x */
- };
- static PF direddl[] = {
- d_undelbak, /* del */
- };
-
- #ifndef DIRED_XMAPS
- #define NDIRED_XMAPS 0 /* number of extra map sections */
- #endif
-
- static struct KEYMAPE(6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
- 6 + NDIRED_XMAPS,
- 6 + NDIRED_XMAPS + IMAPEXT,
- rescan,
- {
- #ifndef NO_HELP
- {CCHR('@'), CCHR('H'), dirednul, (KEYMAP *)&helpmap},
- #else
- {CCHR('@'), CCHR('G'), dirednul, (KEYMAP *)NULL},
- #endif
- {CCHR('L'), CCHR('X'), diredcl, (KEYMAP *)&cXmap},
- {CCHR('Z'), ' ', diredcz, (KEYMAP *)&metamap},
- {'c', 'f', diredc, (KEYMAP *)NULL},
- {'n', 'x', diredn, (KEYMAP *)NULL},
- {CCHR('?'), CCHR('?'), direddl, (KEYMAP *)NULL},
- #ifdef DIRED_XMAPS
- DIRED_XMAPS, /* map sections for dired mode keys */
- #endif
- }
- };
- #endif
-
- /* give names to the maps, for use by help etc.
- * If the map is to be bindable, it must also be listed in the
- * function name table below with the same name.
- * Maps created dynamicly currently don't get added here, thus are unnamed.
- * Modes are just named keymaps with functions to add/subtract them from
- * a buffer's list of modes. If you change a mode name, change it in
- * modes.c also.
- */
-
- MAPS map_table[] = {
- /* fundamental map MUST be first entry */
- {(KEYMAP *)&fundmap, "fundamental"},
- {(KEYMAP *)&fillmap, "fill"},
- {(KEYMAP *)&indntmap, "indent"},
- {(KEYMAP *)&blinkmap, "blink"},
- #ifdef NOTAB
- {(KEYMAP *)¬abmap, "notab"},
- #endif
- {(KEYMAP *)&overwmap, "overwrite"},
- {(KEYMAP *)&metamap, "esc prefix"},
- {(KEYMAP *)&cXmap, "c-x prefix"},
- {(KEYMAP *)&cX4map, "c-x 4 prefix"},
- #ifndef NO_HELP
- {(KEYMAP *)&helpmap, "help"},
- #endif
- #ifndef NO_DIRED
- {(KEYMAP *)&diredmap, "dired"},
- #endif
- };
-
- #define NMAPS (sizeof map_table/sizeof(MAPS))
- int nmaps = NMAPS; /* for use by rebind in extend.c */
-
- char *map_name(map)
- KEYMAP *map;
- {
- MAPS *mp = &map_table[0];
-
- do {
- if(mp->p_map == map) return mp->p_name;
- } while(++mp < &map_table[NMAPS]);
- return (char *)NULL;
- }
-
- MAPS *name_mode(name)
- char *name;
- {
- MAPS *mp = &map_table[0];
-
- do {
- if(strcmp(mp->p_name,name)==0) return mp;
- } while(++mp < &map_table[NMAPS]);
- return (MAPS *)NULL;
- }
-
- KEYMAP *name_map(name)
- char *name;
- {
- MAPS *mp;
- return (mp=name_mode(name))==NULL ? (KEYMAP *)NULL : mp->p_map;
- }
-
- /* Warning: functnames MUST be in alphabetical order! (due to binary
- * search in name_function.) If the function is prefix, it must be listed
- * with the same name in the map_table above.
- */
-
- FUNCTNAMES functnames[] = {
- #ifdef AMIGA
- #ifdef DO_ICONIFY
- {tticon, "amiga-iconify"},
- #endif
- #ifdef DO_MENU
- {amigamenu, "amiga-menu"},
- #endif
- #ifdef CHANGE_COLOR
- {modebackground,"amiga-mode-background"},
- {modeforeground,"amiga-mode-foreground"},
- {ttmode, "amiga-mode-rendition"},
- #endif
- #ifdef CHANGE_FONT
- {setfont, "amiga-set-font"},
- #endif
- #ifdef CHANGE_COLOR
- {textbackground,"amiga-text-background"},
- {textforeground,"amiga-text-foreground"},
- {tttext, "amiga-text-rendition"},
- #endif
- {togglewindow, "amiga-toggle-border"},
- {togglezooms, "amiga-zoom-mode"},
- #endif /* AMIGA */
- #ifndef NO_HELP
- {apropos_command, "apropos"},
- #endif
- {fillmode, "auto-fill-mode"},
- {indentmode, "auto-indent-mode"},
- {backchar, "backward-char"},
- {delbword, "backward-kill-word"},
- {gotobop, "backward-paragraph"},
- {backword, "backward-word"},
- {gotobob, "beginning-of-buffer"},
- {gotobol, "beginning-of-line"},
- {blinkparen, "blink-matching-paren"},
- {showmatch, "blink-matching-paren-hack"},
- #ifdef BSMAP
- {bsmap, "bsmap-mode"},
- #endif
- {prefix, "c-x 4 prefix"},
- {prefix, "c-x prefix"},
- #ifndef NO_MACRO
- {executemacro, "call-last-kbd-macro"},
- #endif
- {capword, "capitalize-word"},
- #ifndef NO_DIR
- {changedir, "cd"},
- #endif
- {copyregion, "copy-region-as-kill"},
- #ifdef REGEX
- {cntmatchlines, "count-matches"},
- {cntnonmatchlines,"count-non-matches"},
- #endif
- {define_key, "define-key"},
- {backdel, "delete-backward-char"},
- {deblank, "delete-blank-lines"},
- {forwdel, "delete-char"},
- {delwhite, "delete-horizontal-space"},
- #ifdef REGEX
- {delmatchlines, "delete-matching-lines"},
- {delnonmatchlines,"delete-non-matching-lines"},
- #endif
- {onlywind, "delete-other-windows"},
- {delwind, "delete-window"},
- #ifndef NO_HELP
- {wallchart, "describe-bindings"},
- {desckey, "describe-key-briefly"},
- #endif
- {digit_argument,"digit-argument"},
- #ifndef NO_DIRED
- {dired, "dired"},
- {d_undelbak, "dired-backup-unflag"},
- {d_copy, "dired-copy-file"},
- {d_expunge, "dired-do-deletions"},
- {d_findfile, "dired-find-file"},
- {d_ffotherwindow, "dired-find-file-other-window"},
- {d_del, "dired-flag-file-deleted"},
- {d_otherwindow, "dired-other-window"},
- {d_rename, "dired-rename-file"},
- {d_undel, "dired-unflag"},
- #endif
- {lowerregion, "downcase-region"},
- {lowerword, "downcase-word"},
- {showversion, "emacs-version"},
- #ifndef NO_MACRO
- {finishmacro, "end-kbd-macro"},
- #endif
- {gotoeob, "end-of-buffer"},
- {gotoeol, "end-of-line"},
- {enlargewind, "enlarge-window"},
- {prefix, "esc prefix"},
- #ifndef NO_STARTUP
- {evalbuffer, "eval-current-buffer"},
- {evalexpr, "eval-expression"},
- #endif
- {swapmark, "exchange-point-and-mark"},
- {extend, "execute-extended-command"},
- {fillpara, "fill-paragraph"},
- {filevisit, "find-file"},
- {poptofile, "find-file-other-window"},
- {forwchar, "forward-char"},
- {gotoeop, "forward-paragraph"},
- {forwword, "forward-word"},
- {bindtokey, "global-set-key"},
- {unbindtokey, "global-unset-key"},
- {gotoline, "goto-line"},
- #ifndef NO_HELP
- {prefix, "help"},
- {help_help, "help-help"},
- #endif
- {insert, "insert"},
- {bufferinsert, "insert-buffer"},
- {fileinsert, "insert-file"},
- {fillword, "insert-with-wrap"},
- {backisearch, "isearch-backward"},
- {forwisearch, "isearch-forward"},
- {justone, "just-one-space"},
- {ctrlg, "keyboard-quit"},
- {killbuffer, "kill-buffer"},
- {killline, "kill-line"},
- {killpara, "kill-paragraph"},
- {killregion, "kill-region"},
- {delfword, "kill-word"},
- {listbuffers, "list-buffers"},
- #ifndef NO_STARTUP
- {evalfile, "load"},
- #endif
- {localbind, "local-set-key"},
- {localunbind, "local-unset-key"},
- #ifndef NO_BACKUP
- {makebkfile, "make-backup-files"},
- #endif
- #ifdef DO_METAKEY
- {do_meta, "meta-key-mode"}, /* better name, anyone? */
- #endif
- #ifdef AMIGA
- #ifdef MOUSE
- {mgotobob, "mouse-beginning-of-buffer"},
- {mforwdel, "mouse-delete-char"},
- {mdelwhite, "mouse-delete-horizontal-space"},
- {mdelwind, "mouse-delete-window"},
- {mgotoeob, "mouse-end-of-buffer"},
- {menlargewind, "mouse-enlarge-window"},
- {mkillline, "mouse-kill-line"},
- {mkillregion, "mouse-kill-region"},
- {mdelfword, "mouse-kill-word"},
- {mreposition, "mouse-recenter"},
- {mbackpage, "mouse-scroll-down"},
- {mforwpage, "mouse-scroll-up"},
- {amigamouse, "mouse-set-point"},
- {mshrinkwind, "mouse-shrink-window"},
- {msplitwind, "mouse-split-window-vertically"},
- {myank, "mouse-yank"},
- #endif
- #endif
- {negative_argument, "negative-argument"},
- {newline, "newline"},
- {indent, "newline-and-indent"},
- {forwline, "next-line"},
- #ifdef NOTAB
- {notabmode, "no-tab-mode"},
- #endif
- {notmodified, "not-modified"},
- {openline, "open-line"},
- {nextwind, "other-window"},
- {overwrite, "overwrite-mode"},
- #ifdef PREFIXREGION
- {prefixregion, "prefix-region"},
- #endif
- {backline, "previous-line"},
- #ifdef GOSMACS
- {prevwind, "previous-window"},
- #endif
- #ifdef VMS
- {spawncli, "push-to-dcl"},
- #endif
- #ifndef NO_DIR
- {showcwdir, "pwd"},
- #endif
- {queryrepl, "query-replace"},
- #ifdef REGEX
- {re_queryrepl, "query-replace-regexp"},
- #endif
- {quote, "quoted-insert"},
- #ifdef REGEX
- {re_searchagain,"re-search-again"},
- {re_backsearch, "re-search-backward"},
- {re_forwsearch, "re-search-forward"},
- #endif
- {reposition, "recenter"},
- {refresh, "redraw-display"},
- {filesave, "save-buffer"},
- {quit, "save-buffers-kill-emacs"},
- {savebuffers, "save-some-buffers"},
- {backpage, "scroll-down"},
- #ifdef GOSMACS
- {back1page, "scroll-one-line-down"},
- {forw1page, "scroll-one-line-up"},
- #endif
- {pagenext, "scroll-other-window"},
- {forwpage, "scroll-up"},
- {searchagain, "search-again"},
- {backsearch, "search-backward"},
- {forwsearch, "search-forward"},
- {selfinsert, "self-insert-command"},
- #ifdef REGEX
- {setcasefold, "set-case-fold-search"},
- #endif
- {set_default_mode, "set-default-mode"},
- {setfillcol, "set-fill-column"},
- {setmark, "set-mark-command"},
- #ifdef PREFIXREGION
- {setprefix, "set-prefix-string"},
- #endif
- {shrinkwind, "shrink-window"},
- #ifdef NOTAB
- {space_to_tabstop, "space-to-tabstop"},
- #endif
- {splitwind, "split-window-vertically"},
- #ifndef NO_MACRO
- {definemacro, "start-kbd-macro"},
- #endif
- #ifdef VMS
- {attachtoparent,"suspend-emacs"},
- #else
- {spawncli, "suspend-emacs"},
- #endif
- {usebuffer, "switch-to-buffer"},
- {poptobuffer, "switch-to-buffer-other-window"},
- {twiddle, "transpose-chars"},
- {universal_argument, "universal-argument"},
- {upperregion, "upcase-region"},
- {upperword, "upcase-word"},
- {showcpos, "what-cursor-position"},
- {filewrite, "write-file"},
- {yank, "yank"},
- };
-
- #define NFUNCT (sizeof(functnames)/sizeof(FUNCTNAMES))
-
- int nfunct = NFUNCT; /* used by help.c */
-
- /*
- * The general-purpose version of ROUND2 blows osk C (2.0) out of the water.
- * (reboot required) If you need to build a version of mg with less than 32
- * or more than 511 functions, something better must be done.
- * The version that should work, but doesn't is:
- * #define ROUND2(x) (1+((x>>1)|(x>>2)|(x>>3)|(x>>4)|(x>>5)|(x>>6)|(x>>7)|\
- * (x>>8)|(x>>9)|(x>>10)|(x>>11)|(x>>12)|(x>>13)|(x>>14)|(x>>15)))
- */
- #define ROUND2(x) (x<128?(x<64?32:64):(x<256?128:256))
-
- static name_fent(fname, flag)
- register char *fname;
- int flag;
- {
- register int try;
- register int x = ROUND2(NFUNCT);
- register int base = 0;
- register int notit;
-
- do {
- /* + can be used instead of | here if more efficent. */
- if((try = base | x) < NFUNCT) {
- if((notit = strcmp(fname, functnames[try].n_name)) >= 0) {
- if(!notit) return try;
- base = try;
- }
- }
- } while((x>>=1) || (try==1 && base==0)); /* try 0 once if needed */
- return flag ? base : -1;
- }
-
- /*
- * Translate from function name to function pointer, using binary search.
- */
-
- PF name_function(fname)
- char *fname;
- {
- int i;
- if((i = name_fent(fname, FALSE)) >= 0) return functnames[i].n_funct;
- return (PF)NULL;
- }
-
- /* complete function name */
-
- complete_function(fname, c)
- register char *fname;
- {
- register int i, j, k, l;
- int oj;
-
- i = name_fent(fname, TRUE);
- for(j=0; (l=fname[j]) && functnames[i].n_name[j]==l; j++) {}
- if(fname[j]!='\0') {
- if(++i >= NFUNCT) return -2; /* no match */
- for(j=0; (l=fname[j]) && functnames[i].n_name[j]==l; j++) {}
- if(fname[j]!='\0') return -2; /* no match */
- }
- if(c==CCHR('M') && functnames[i].n_name[j]=='\0') return -1;
- for(k=i+1; k<NFUNCT; k++) { /* find last match */
- for(l=0; functnames[k].n_name[l]==fname[l]; l++) {}
- if(l<j) break;
- }
- k--;
- oj = j;
- if(k>i) { /* multiple matches */
- while((l = functnames[i].n_name[j]) == functnames[k].n_name[j]) {
- fname[j++] = l;
- if(l=='-' && c==' ') break;
- }
- if(j==oj) return -3; /* ambiguous */
- } else { /* single match */
- while(l = functnames[i].n_name[j]) {
- fname[j++] = l;
- if(l=='-' && c==' ') break;
- }
- }
- fname[j] = '\0';
- return j - oj;
- }
-
- /* translate from function pointer to function name. */
-
- char *function_name(fpoint)
- register PF fpoint;
- {
- register FUNCTNAMES *fnp = &functnames[0];
-
- if(fpoint == prefix) return (char *)NULL; /* ambiguous */
- do {
- if(fnp->n_funct == fpoint) return fnp->n_name;
- } while(++fnp < &functnames[NFUNCT]);
- return (char *)NULL;
- }
- SHAR_EOF
- cat << \SHAR_EOF > line.c
- /*
- * Text line handling.
- * The functions in this file
- * are a general set of line management
- * utilities. They are the only routines that
- * touch the text. They also touch the buffer
- * and window structures, to make sure that the
- * necessary updating gets done. There are routines
- * in this file that handle the kill buffer too.
- * It isn't here for any good reason.
- *
- * Note that this code only updates the dot and
- * mark values in the window list. Since all the code
- * acts on the current window, the buffer that we
- * are editing must be being displayed, which means
- * that "b_nwnd" is non zero, which means that the
- * dot and mark values in the buffer headers are
- * nonsense.
- */
- #include "def.h"
-
- /* number of bytes member is from start of structure type */
- /* should be computed at compile time */
-
- #ifndef OFFSET
- #define OFFSET(type,member) ((char *)&(((type *)0)->member)-(char *)((type *)0))
- #endif
-
- #ifndef NBLOCK
- #define NBLOCK 16 /* Line block chunk size */
- #endif
-
- #ifndef KBLOCK
- #define KBLOCK 256 /* Kill buffer block size. */
- #endif
-
- static char *kbufp = NULL; /* Kill buffer data. */
- static RSIZE kused = 0; /* # of bytes used in KB. */
- static RSIZE ksize = 0; /* # of bytes allocated in KB. */
- static RSIZE kstart = 0; /* # of first used byte in KB. */
-
- /*
- * This routine allocates a block of memory large enough to hold a LINE
- * containing "used" characters. The block is rounded up to whatever
- * needs to be allocated. (use lallocx for lines likely to grow.)
- * Return a pointer to the new block, or NULL if there isn't
- * any memory left. Print a message in the message line if no space.
- */
- LINE *
- lalloc(used) register int used; {
- register LINE *lp;
- register int size;
-
- /* any padding at the end of the structure is used */
- if((size = used + OFFSET(LINE, l_text[0])) < sizeof(LINE))
- size = sizeof(LINE);
- #ifdef MALLOCROUND
- MALLOCROUND(size); /* round up to a size optimal to malloc */
- #endif
- if((lp = (LINE *)malloc((unsigned)size)) == NULL) {
- ewprintf("Can't get %d bytes", size);
- return (LINE *)NULL;
- }
- lp->l_size = size - OFFSET(LINE, l_text[0]);
- lp->l_used = used;
- return lp;
- }
-
- /*
- * Like lalloc, only round amount desired up because this line will
- * probably grow. We always make room for at least one more char.
- * (thus making 0 not a special case anymore.)
- */
- LINE *
- lallocx(used)
- int used;
- {
- register int size;
- register LINE *lp;
-
- size = (NBLOCK+used) & ~(NBLOCK-1);
- if((lp = lalloc(size)) != NULL) lp->l_used = used;
- return lp;
- }
-
- /*
- * Delete line "lp". Fix all of the
- * links that might point at it (they are
- * moved to offset 0 of the next line.
- * Unlink the line from whatever buffer it
- * might be in. Release the memory. The
- * buffers are updated too; the magic conditions
- * described in the above comments don't hold
- * here.
- */
- VOID
- lfree(lp) register LINE *lp; {
- register BUFFER *bp;
- register WINDOW *wp;
-
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
- if (wp->w_linep == lp)
- wp->w_linep = lp->l_fp;
- if (wp->w_dotp == lp) {
- wp->w_dotp = lp->l_fp;
- wp->w_doto = 0;
- }
- if (wp->w_markp == lp) {
- wp->w_markp = lp->l_fp;
- wp->w_marko = 0;
- }
- }
- for(bp = bheadp; bp != NULL; bp = bp->b_bufp) {
- if (bp->b_nwnd == 0) {
- if (bp->b_dotp == lp) {
- bp->b_dotp = lp->l_fp;
- bp->b_doto = 0;
- }
- if (bp->b_markp == lp) {
- bp->b_markp = lp->l_fp;
- bp->b_marko = 0;
- }
- }
- }
- lp->l_bp->l_fp = lp->l_fp;
- lp->l_fp->l_bp = lp->l_bp;
- free((char *) lp);
- }
-
- /*
- * This routine gets called when
- * a character is changed in place in the
- * current buffer. It updates all of the required
- * flags in the buffer and window system. The flag
- * used is passed as an argument; if the buffer is being
- * displayed in more than 1 window we change EDIT to
- * HARD. Set MODE if the mode line needs to be
- * updated (the "*" has to be set).
- */
- VOID
- lchange(flag) register int flag; {
- register WINDOW *wp;
-
- if ((curbp->b_flag&BFCHG) == 0) { /* First change, so */
- flag |= WFMODE; /* update mode lines. */
- curbp->b_flag |= BFCHG;
- }
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
- if (wp->w_bufp == curbp) {
- wp->w_flag |= flag;
- if(wp != curwp) wp->w_flag |= WFHARD;
- }
- }
- }
-
- /*
- * Insert "n" copies of the character "c"
- * at the current location of dot. In the easy case
- * all that happens is the text is stored in the line.
- * In the hard case, the line has to be reallocated.
- * When the window list is updated, take special
- * care; I screwed it up once. You always update dot
- * in the current window. You update mark, and a
- * dot in another window, if it is greater than
- * the place where you did the insert. Return TRUE
- * if all is well, and FALSE on errors.
- */
- linsert(n, c)
- int n;
- {
- register char *cp1;
- register char *cp2;
- register LINE *lp1;
- LINE *lp2;
- LINE *lp3;
- register int doto;
- register RSIZE i;
- WINDOW *wp;
-
- lchange(WFEDIT);
- lp1 = curwp->w_dotp; /* Current line */
- if (lp1 == curbp->b_linep) { /* At the end: special */
- /* (now should only happen in empty buffer */
- if (curwp->w_doto != 0) {
- ewprintf("bug: linsert");
- return FALSE;
- }
- if ((lp2=lallocx(n)) == NULL) /* Allocate new line */
- return FALSE;
- lp3 = lp1->l_bp; /* Previous line */
- lp3->l_fp = lp2; /* Link in */
- lp2->l_fp = lp1;
- lp1->l_bp = lp2;
- lp2->l_bp = lp3;
- for (i=0; i<n; ++i)
- lp2->l_text[i] = c;
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
- if (wp->w_linep == lp1)
- wp->w_linep = lp2;
- if (wp->w_dotp == lp1)
- wp->w_dotp = lp2;
- if (wp->w_markp == lp1)
- wp->w_markp = lp2;
- }
- /*NOSTRICT*/
- curwp->w_doto = n;
- return TRUE;
- }
- doto = curwp->w_doto; /* Save for later. */
- /*NOSTRICT (2) */
- if (lp1->l_used+n > lp1->l_size) { /* Hard: reallocate */
- if ((lp2=lallocx(lp1->l_used+n)) == NULL)
- return FALSE;
- cp1 = &lp1->l_text[0];
- cp2 = &lp2->l_text[0];
- while (cp1 != &lp1->l_text[doto])
- *cp2++ = *cp1++;
- /*NOSTRICT*/
- cp2 += n;
- while (cp1 != &lp1->l_text[lp1->l_used])
- *cp2++ = *cp1++;
- lp1->l_bp->l_fp = lp2;
- lp2->l_fp = lp1->l_fp;
- lp1->l_fp->l_bp = lp2;
- lp2->l_bp = lp1->l_bp;
- free((char *) lp1);
- } else { /* Easy: in place */
- lp2 = lp1; /* Pretend new line */
- /*NOSTRICT*/
- lp2->l_used += n;
- cp2 = &lp1->l_text[lp1->l_used];
-
- cp1 = cp2-n;
- while (cp1 != &lp1->l_text[doto])
- *--cp2 = *--cp1;
- }
- for (i=0; i<n; ++i) /* Add the characters */
- lp2->l_text[doto+i] = c;
-
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
- if (wp->w_linep == lp1)
- wp->w_linep = lp2;
- if (wp->w_dotp == lp1) {
- wp->w_dotp = lp2;
- if (wp==curwp || wp->w_doto>doto)
- /*NOSTRICT*/
- wp->w_doto += n;
- }
- if (wp->w_markp == lp1) {
- wp->w_markp = lp2;
- if (wp->w_marko > doto)
- /*NOSTRICT*/
- wp->w_marko += n;
- }
- }
- return TRUE;
- }
-
- /*
- * Insert a newline into the buffer
- * at the current location of dot in the current
- * window. The funny ass-backwards way is no longer used.
- */
- lnewline()
- {
- register LINE *lp1;
- register LINE *lp2;
- register int doto;
- register int nlen;
- WINDOW *wp;
-
- lchange(WFHARD);
- lp1 = curwp->w_dotp; /* Get the address and */
- doto = curwp->w_doto; /* offset of "." */
- if(doto == 0) { /* avoid unnessisary copying */
- if((lp2 = lallocx(0)) == NULL) /* new first part */
- return FALSE;
- lp2->l_bp = lp1->l_bp;
- lp1->l_bp->l_fp = lp2;
- lp2->l_fp = lp1;
- lp1->l_bp = lp2;
- for(wp = wheadp; wp!=NULL; wp = wp->w_wndp)
- if(wp->w_linep == lp1) wp->w_linep = lp2;
- return TRUE;
- }
- nlen = llength(lp1) - doto; /* length of new part */
- if((lp2=lallocx(nlen)) == NULL) /* New second half line */
- return FALSE;
- if(nlen!=0) bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen);
- lp1->l_used = doto;
- lp2->l_bp = lp1;
- lp2->l_fp = lp1->l_fp;
- lp1->l_fp = lp2;
- lp2->l_fp->l_bp = lp2;
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { /* Windows */
- if (wp->w_dotp == lp1 && wp->w_doto >= doto) {
- wp->w_dotp = lp2;
- wp->w_doto -= doto;
- }
- if (wp->w_markp == lp1 && wp->w_marko >= doto) {
- wp->w_markp = lp2;
- wp->w_marko -= doto;
- }
- }
- return TRUE;
- }
-
- /*
- * This function deletes "n" bytes,
- * starting at dot. It understands how do deal
- * with end of lines, etc. It returns TRUE if all
- * of the characters were deleted, and FALSE if
- * they were not (because dot ran into the end of
- * the buffer. The "kflag" indicates either no insertion,
- * or direction of insertion into the kill buffer.
- */
- ldelete(n, kflag) RSIZE n; {
- register char *cp1;
- register char *cp2;
- register LINE *dotp;
- register int doto;
- register RSIZE chunk;
- WINDOW *wp;
-
- /*
- * HACK - doesn't matter, and fixes back-over-nl bug for empty
- * kill buffers.
- */
- if (kused == kstart) kflag = KFORW;
-
- while (n != 0) {
- dotp = curwp->w_dotp;
- doto = curwp->w_doto;
- if (dotp == curbp->b_linep) /* Hit end of buffer. */
- return FALSE;
- chunk = dotp->l_used-doto; /* Size of chunk. */
- if (chunk > n)
- chunk = n;
- if (chunk == 0) { /* End of line, merge. */
- if(dotp == lback(curbp->b_linep))
- return FALSE; /* End of buffer. */
- lchange(WFHARD);
- if (ldelnewline() == FALSE
- || (kflag!=KNONE && kinsert('\n', kflag)==FALSE))
- return FALSE;
- --n;
- continue;
- }
- lchange(WFEDIT);
- cp1 = &dotp->l_text[doto]; /* Scrunch text. */
- cp2 = cp1 + chunk;
- if (kflag == KFORW) {
- while (ksize - kused < chunk)
- if (kgrow(FALSE) == FALSE) return FALSE;
- bcopy(cp1, &(kbufp[kused]), (int) chunk);
- kused += chunk;
- } else if (kflag == KBACK) {
- while (kstart < chunk)
- if (kgrow(TRUE) == FALSE) return FALSE;
- bcopy(cp1, &(kbufp[kstart-chunk]), (int) chunk);
- kstart -= chunk;
- } else if (kflag != KNONE) panic("broken ldelete call");
- while (cp2 != &dotp->l_text[dotp->l_used])
- *cp1++ = *cp2++;
- dotp->l_used -= (int) chunk;
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp ) {
- if (wp->w_dotp==dotp && wp->w_doto>=doto) {
- /*NOSTRICT*/
- wp->w_doto -= chunk;
- if (wp->w_doto < doto)
- wp->w_doto = doto;
- }
- if (wp->w_markp==dotp && wp->w_marko>=doto) {
- /*NOSTRICT*/
- wp->w_marko -= chunk;
- if (wp->w_marko < doto)
- wp->w_marko = doto;
- }
- }
- n -= chunk;
- }
- return TRUE;
- }
-
- /*
- * Delete a newline. Join the current line
- * with the next line. If the next line is the magic
- * header line always return TRUE; merging the last line
- * with the header line can be thought of as always being a
- * successful operation, even if nothing is done, and this makes
- * the kill buffer work "right". Easy cases can be done by
- * shuffling data around. Hard cases require that lines be moved
- * about in memory. Return FALSE on error and TRUE if all
- * looks ok.
- */
- ldelnewline() {
- register LINE *lp1;
- register LINE *lp2;
- register WINDOW *wp;
- LINE *lp3;
-
- lp1 = curwp->w_dotp;
- lp2 = lp1->l_fp;
- if (lp2 == curbp->b_linep) /* At the buffer end. */
- return TRUE;
- if (lp2->l_used <= lp1->l_size - lp1->l_used) {
- bcopy(&lp2->l_text[0], &lp1->l_text[lp1->l_used], lp2->l_used);
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
- if (wp->w_linep == lp2)
- wp->w_linep = lp1;
- if (wp->w_dotp == lp2) {
- wp->w_dotp = lp1;
- wp->w_doto += lp1->l_used;
- }
- if (wp->w_markp == lp2) {
- wp->w_markp = lp1;
- wp->w_marko += lp1->l_used;
- }
- }
- lp1->l_used += lp2->l_used;
- lp1->l_fp = lp2->l_fp;
- lp2->l_fp->l_bp = lp1;
- free((char *) lp2);
- return TRUE;
- }
- if ((lp3=lalloc(lp1->l_used + lp2->l_used)) == NULL)
- return FALSE;
- bcopy(&lp1->l_text[0], &lp3->l_text[0], lp1->l_used);
- bcopy(&lp2->l_text[0], &lp3->l_text[lp1->l_used], lp2->l_used);
- lp1->l_bp->l_fp = lp3;
- lp3->l_fp = lp2->l_fp;
- lp2->l_fp->l_bp = lp3;
- lp3->l_bp = lp1->l_bp;
- for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
- if (wp->w_linep==lp1 || wp->w_linep==lp2)
- wp->w_linep = lp3;
- if (wp->w_dotp == lp1)
- wp->w_dotp = lp3;
- else if (wp->w_dotp == lp2) {
- wp->w_dotp = lp3;
- wp->w_doto += lp1->l_used;
- }
- if (wp->w_markp == lp1)
- wp->w_markp = lp3;
- else if (wp->w_markp == lp2) {
- wp->w_markp = lp3;
- wp->w_marko += lp1->l_used;
- }
- }
- free((char *) lp1);
- free((char *) lp2);
- return TRUE;
- }
-
- /*
- * Replace plen characters before dot with argument string.
- * Control-J characters in st are interpreted as newlines.
- * There is a casehack disable flag (normally it likes to match
- * case of replacement to what was there).
- */
- lreplace(plen, st, f)
- register RSIZE plen; /* length to remove */
- char *st; /* replacement string */
- int f; /* case hack disable */
- {
- register RSIZE rlen; /* replacement length */
- register int rtype; /* capitalization */
- register int c; /* used for random characters */
- register int doto; /* offset into line */
-
- /*
- * Find the capitalization of the word that was found.
- * f says use exact case of replacement string (same thing that
- * happens with lowercase found), so bypass check.
- */
- /*NOSTRICT*/
- (VOID) backchar(FFARG | FFRAND, (int) plen);
- rtype = _L;
- c = lgetc(curwp->w_dotp, curwp->w_doto);
- if (ISUPPER(c)!=FALSE && f==FALSE) {
- rtype = _U|_L;
- if (curwp->w_doto+1 < llength(curwp->w_dotp)) {
- c = lgetc(curwp->w_dotp, curwp->w_doto+1);
- if (ISUPPER(c) != FALSE) {
- rtype = _U;
- }
- }
- }
-
- /*
- * make the string lengths match (either pad the line
- * so that it will fit, or scrunch out the excess).
- * be careful with dot's offset.
- */
- rlen = strlen(st);
- doto = curwp->w_doto;
- if (plen > rlen)
- (VOID) ldelete((RSIZE) (plen-rlen), KNONE);
- else if (plen < rlen) {
- if (linsert((int)(rlen-plen), ' ') == FALSE)
- return FALSE;
- }
- curwp->w_doto = doto;
-
- /*
- * do the replacement: If was capital, then place first
- * char as if upper, and subsequent chars as if lower.
- * If inserting upper, check replacement for case.
- */
- while ((c = CHARMASK(*st++)) != '\0') {
- if ((rtype&_U)!=0 && ISLOWER(c)!=0)
- c = TOUPPER(c);
- if (rtype == (_U|_L))
- rtype = _L;
- if (c == CCHR('J')) {
- if (curwp->w_doto == llength(curwp->w_dotp))
- (VOID) forwchar(FFRAND, 1);
- else {
- if (ldelete((RSIZE) 1, KNONE) != FALSE)
- (VOID) lnewline();
- }
- } else if (curwp->w_dotp == curbp->b_linep) {
- (VOID) linsert(1, c);
- } else if (curwp->w_doto == llength(curwp->w_dotp)) {
- if (ldelete((RSIZE) 1, KNONE) != FALSE)
- (VOID) linsert(1, c);
- } else
- lputc(curwp->w_dotp, curwp->w_doto++, c);
- }
- lchange(WFHARD);
- return (TRUE);
- }
-
- /*
- * Delete all of the text
- * saved in the kill buffer. Called by commands
- * when a new kill context is being created. The kill
- * buffer array is released, just in case the buffer has
- * grown to immense size. No errors.
- */
- VOID
- kdelete() {
- if (kbufp != NULL) {
- free((char *) kbufp);
- kbufp = NULL;
- kstart = kused = ksize = 0;
- }
- }
-
- /*
- * Insert a character to the kill buffer,
- * enlarging the buffer if there isn't any room. Always
- * grow the buffer in chunks, on the assumption that if you
- * put something in the kill buffer you are going to put
- * more stuff there too later. Return TRUE if all is
- * well, and FALSE on errors. Print a message on
- * errors. Dir says whether to put it at back or front.
- */
- kinsert(c, dir) {
-
- if (kused == ksize && dir == KFORW && kgrow(FALSE) == FALSE)
- return FALSE;
- if (kstart == 0 && dir == KBACK && kgrow(TRUE) == FALSE)
- return FALSE;
- if (dir == KFORW) kbufp[kused++] = c;
- else if (dir == KBACK) kbufp[--kstart] = c;
- else panic("broken kinsert call"); /* Oh shit! */
- return (TRUE);
- }
-
- /*
- * kgrow - just get more kill buffer for the callee. back is true if
- * we are trying to get space at the beginning of the kill buffer.
- */
- kgrow(back) {
- register int nstart;
- register char *nbufp;
-
- if ((unsigned)(ksize+KBLOCK) <= (unsigned)ksize) {
- /* probably 16 bit unsigned */
- ewprintf("Kill buffer size at maximum");
- return FALSE;
- }
- if ((nbufp=malloc((unsigned)(ksize+KBLOCK))) == NULL) {
- ewprintf("Can't get %ld bytes", (long)(ksize+KBLOCK));
- return FALSE;
- }
- nstart = (back == TRUE) ? (kstart + KBLOCK) : (KBLOCK / 4) ;
- bcopy(&(kbufp[kstart]), &(nbufp[nstart]), (int) (kused-kstart));
- if (kbufp != NULL)
- free((char *) kbufp);
- kbufp = nbufp;
- ksize += KBLOCK;
- kused = kused - kstart + nstart;
- kstart = nstart;
- return TRUE;
- }
-
- /*
- * This function gets characters from
- * the kill buffer. If the character index "n" is
- * off the end, it returns "-1". This lets the caller
- * just scan along until it gets a "-1" back.
- */
- kremove(n) {
- if (n < 0 || n + kstart >= kused)
- return -1;
- return CHARMASK(kbufp[n + kstart]);
- }
- SHAR_EOF
- cat << \SHAR_EOF > macro.h
- /* definitions for keyboard macros */
-
- #ifndef EXTERN
- #define EXTERN extern
- #define INIT(i)
- #endif
-
- #define MAXMACRO 256 /* maximum functs in a macro */
-
- EXTERN int inmacro INIT(FALSE);
- EXTERN int macrodef INIT(FALSE);
- EXTERN int macrocount INIT(0);
-
- EXTERN union {
- PF m_funct;
- int m_count; /* for count-prefix */
- } macro[MAXMACRO];
-
- EXTERN LINE *maclhead INIT(NULL);
- EXTERN LINE *maclcur;
-
- #undef EXTERN
- #undef INIT
- SHAR_EOF
- cat << \SHAR_EOF > main.c
- /*
- * Mainline
- */
- #include "def.h"
- #ifndef NO_MACRO
- #include "macro.h"
- #endif
-
- int thisflag; /* Flags, this command */
- int lastflag; /* Flags, last command */
- int curgoal; /* Goal column */
- BUFFER *curbp; /* Current buffer */
- WINDOW *curwp; /* Current window */
- BUFFER *bheadp; /* BUFFER listhead */
- WINDOW *wheadp = (WINDOW *)NULL; /* WINDOW listhead */
- char pat[NPAT]; /* Pattern */
- #ifndef NO_DPROMPT
- extern char prompt[], *promptp; /* delayed prompting */
- #endif
-
- static VOID edinit();
-
- VOID
- main(argc, argv)
- int argc;
- char **argv;
- {
- #ifndef NO_STARTUP
- char *startupfile();
- #endif
- char *cp;
- VOID vtinit(), makename(), eerase();
- BUFFER *findbuffer();
-
- #ifdef SYSINIT
- SYSINIT; /* system dependent. */
- #endif
- vtinit(); /* Virtual terminal. */
- #ifndef NO_DIR
- dirinit(); /* Get current directory */
- #endif
- edinit(); /* Buffers, windows. */
- ttykeymapinit(); /* Symbols, bindings. */
- /* doing update() before reading files causes the error messages from
- * the file I/O show up on the screen. (and also an extra display
- * of the mode line if there are files specified on the command line.)
- */
- update();
- #ifndef NO_STARTUP /* User startup file. */
- if ((cp = startupfile((char *)NULL)) != NULL)
- (VOID) load(cp);
- #endif
- while (--argc > 0) {
- cp = adjustname(*++argv);
- curbp = findbuffer(cp);
- (VOID) showbuffer(curbp, curwp, 0);
- (VOID) readin(cp);
- }
- thisflag = 0; /* Fake last flags. */
- for(;;) {
- #ifndef NO_DPROMPT
- *(promptp = prompt) = '\0';
- if(epresf == KPROMPT) eerase();
- #endif
- update();
- lastflag = thisflag;
- thisflag = 0;
- switch(doin()) {
- case TRUE: break;
- case ABORT:
- ewprintf("Quit"); /* and fall through */
- case FALSE:
- default:
- ttbeep();
- #ifndef NO_MACRO
- macrodef = FALSE;
- #endif
- }
- }
- }
-
- /*
- * Initialize default buffer and window.
- */
- static VOID
- edinit() {
- register BUFFER *bp;
- register WINDOW *wp;
-
- bheadp = NULL;
- bp = bfind("*scratch*", TRUE); /* Text buffer. */
- wp = (WINDOW *)malloc(sizeof(WINDOW)); /* Initial window. */
- if (bp==NULL || wp==NULL) panic("edinit");
- curbp = bp; /* Current ones. */
- wheadp = wp;
- curwp = wp;
- wp->w_wndp = NULL; /* Initialize window. */
- wp->w_bufp = bp;
- bp->b_nwnd = 1; /* Displayed. */
- wp->w_linep = wp->w_dotp = bp->b_linep;
- wp->w_doto = 0;
- wp->w_markp = NULL;
- wp->w_marko = 0;
- wp->w_toprow = 0;
- wp->w_ntrows = nrow-2; /* 2 = mode, echo. */
- wp->w_force = 0;
- wp->w_flag = WFMODE|WFHARD; /* Full. */
- }
-
- /*
- * Quit command. If an argument, always
- * quit. Otherwise confirm if a buffer has been
- * changed and not written out. Normally bound
- * to "C-X C-C".
- */
- /*ARGSUSED*/
- quit(f, n)
- {
- register int s;
- VOID vttidy();
-
- if ((s = anycb(FALSE)) == ABORT) return ABORT;
- if (s == FALSE
- || eyesno("Some modified buffers exist, really exit") == TRUE) {
- vttidy();
- #ifdef SYSCLEANUP
- SYSCLEANUP;
- #endif
- exit(GOOD);
- }
- return TRUE;
- }
-
- /*
- * User abort. Should be called by any input routine that sees a C-g
- * to abort whatever C-g is aborting these days. Currently does
- * nothing.
- */
- /*ARGSUSED*/
- ctrlg(f, n)
- {
- return ABORT;
- }
- SHAR_EOF
- # End of shell archive
- exit 0
- -------
-