summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-09-01 14:59:10 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-09-01 14:59:10 +0000
commita045bd2fd0eec255d59e94ac735e3096da56bfc7 (patch)
tree5d2398a23f5bfa85d6ea967969f36b1e419a9568 /usr.bin
parent58c021b47d6326c960010c7261da73856d613f4b (diff)
More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/Makefile4
-rw-r--r--usr.bin/mg/buffer.c22
-rw-r--r--usr.bin/mg/def.h493
-rw-r--r--usr.bin/mg/echo.c340
-rw-r--r--usr.bin/mg/extend.c364
-rw-r--r--usr.bin/mg/file.c326
-rw-r--r--usr.bin/mg/help.c141
-rw-r--r--usr.bin/mg/kbd.c198
-rw-r--r--usr.bin/mg/kbd.h12
-rw-r--r--usr.bin/mg/keymap.c681
-rw-r--r--usr.bin/mg/line.c390
-rw-r--r--usr.bin/mg/macro.c41
-rw-r--r--usr.bin/mg/main.c119
-rw-r--r--usr.bin/mg/match.c149
-rw-r--r--usr.bin/mg/modes.c76
-rw-r--r--usr.bin/mg/paragraph.c174
-rw-r--r--usr.bin/mg/random.c345
-rw-r--r--usr.bin/mg/re_search.c355
-rw-r--r--usr.bin/mg/region.c199
-rw-r--r--usr.bin/mg/search.c299
-rw-r--r--usr.bin/mg/spawn.c36
-rw-r--r--usr.bin/mg/tty.c252
-rw-r--r--usr.bin/mg/ttykbd.c37
-rw-r--r--usr.bin/mg/version.c8
-rw-r--r--usr.bin/mg/window.c241
-rw-r--r--usr.bin/mg/word.c120
26 files changed, 2718 insertions, 2704 deletions
diff --git a/usr.bin/mg/Makefile b/usr.bin/mg/Makefile
index 82ce5d2118a..8c726d3a5cf 100644
--- a/usr.bin/mg/Makefile
+++ b/usr.bin/mg/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.5 2000/02/28 23:45:21 millert Exp $
+# $OpenBSD: Makefile,v 1.6 2000/09/01 14:59:08 millert Exp $
PROG= mg
@@ -16,7 +16,7 @@ DPADD+= ${LIBCURSES}
# PREFIXREGION -- enable function "prefix-region"
# REGEX -- create regular expression functions
#
-CFLAGS+=-DDO_METAKEY -DPREFIXREGION -DXKEYS -DFKEYS -DBACKUP -DREGEX
+CFLAGS+=-Wall -DDO_METAKEY -DPREFIXREGION -DXKEYS -DFKEYS -DBACKUP -DREGEX
SRCS= cinfo.c fileio.c spawn.c ttyio.c tty.c ttykbd.c \
basic.c dir.c dired.c file.c line.c match.c paragraph.c \
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index a795506369b..231ee574ed6 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,8 +1,9 @@
/*
* Buffer handling.
*/
-#include "def.h"
-#include "kbd.h" /* needed for modes */
+
+#include "def.h"
+#include "kbd.h" /* needed for modes */
static RSIZE itor __P((char *, int, RSIZE));
static BUFFER *makelist __P((void));
@@ -54,7 +55,6 @@ poptobuffer(f, n)
MGWIN *wp;
int s;
char bufn[NBUFN];
- MGWIN *popbuf();
/* Get buffer to use from user */
if ((curbp->b_altb == NULL)
@@ -168,7 +168,6 @@ int
savebuffers(f, n)
int f, n;
{
-
if (anycb(f) == ABORT)
return ABORT;
return TRUE;
@@ -184,7 +183,7 @@ savebuffers(f, n)
/* ARGSUSED */
int
listbuffers(f, n)
- int f, n;
+ int f, n;
{
BUFFER *bp;
MGWIN *wp;
@@ -380,15 +379,12 @@ anycb(f)
*/
BUFFER *
bfind(bname, cflag)
- char *bname;
- int cflag;
+ char *bname;
+ int cflag;
{
- BUFFER *bp;
- LINE *lp;
- int i;
- extern int defb_nmodes;
- extern MAPS *defb_modes[PBMODES];
- extern int defb_flag;
+ BUFFER *bp;
+ LINE *lp;
+ int i;
bp = bheadp;
while (bp != NULL) {
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 57ce809edb9..171253bdf88 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -36,7 +36,7 @@
#endif
#endif
-typedef int (*PF) (); /* generaly useful type */
+typedef int (*PF)(); /* generally useful type */
/*
* Table sizes, etc.
@@ -275,214 +275,335 @@ typedef struct {
* Prototypes.
*/
-/* tty.c */
-VOID ttinit __P((void));
-VOID ttreinit __P((void));
-VOID tttidy __P((void));
-VOID ttmove __P((int, int));
-VOID tteeol __P((void));
-VOID tteeop __P((void));
-VOID ttbeep __P((void));
-VOID ttinsl __P((int, int, int));
-VOID ttdell __P((int, int, int));
-VOID ttwindow __P((int, int));
-VOID ttnowindow __P((void));
-VOID ttcolor __P((int));
-VOID ttresize __P((void));
+/* tty.c X */
+VOID ttinit __P((void));
+VOID ttreinit __P((void));
+VOID tttidy __P((void));
+VOID ttmove __P((int, int));
+VOID tteeol __P((void));
+VOID tteeop __P((void));
+VOID ttbeep __P((void));
+VOID ttinsl __P((int, int, int));
+VOID ttdell __P((int, int, int));
+VOID ttwindow __P((int, int));
+VOID ttnowindow __P((void));
+VOID ttcolor __P((int));
+VOID ttresize __P((void));
/* ttyio.c */
-VOID ttopen __P((void));
-int ttraw __P((void));
-VOID ttclose __P((void));
-int ttcooked __P((void));
-int ttputc __P((int));
-VOID ttflush __P((void));
-int ttgetc __P((void));
-int ttwait __P((void));
-VOID setttysize __P((void));
-int typeahead __P((void));
+VOID ttopen __P((void));
+int ttraw __P((void));
+VOID ttclose __P((void));
+int ttcooked __P((void));
+int ttputc __P((int));
+VOID ttflush __P((void));
+int ttgetc __P((void));
+int ttwait __P((void));
+VOID setttysize __P((void));
+int typeahead __P((void));
/* dir.c */
-VOID dirinit __P((VOID));
-int changedir __P((int, int));
-int showcwdir __P((int, int));
+VOID dirinit __P((VOID));
+int changedir __P((int, int));
+int showcwdir __P((int, int));
/* dired.c */
-int dired __P((int, int));
-int d_otherwindow __P((int, int));
-int d_undel __P((int, int));
-int d_undelbak __P((int, int));
-int d_findfile __P((int, int));
-int d_ffotherwindow __P((int, int));
-int d_expunge __P((int, int));
-int d_copy __P((int, int));
-int d_del __P((int, int));
-int d_rename __P((int, int));
-
-/* file.c */
-int fileinsert __P((int, int));
-int filevisit __P((int, int));
-int poptofile __P((int, int));
-BUFFER *findbuffer __P((char *));
-int readin __P((char *));
-int insertfile __P((char *, char *, int));
-VOID makename __P((char *, char *));
-int filewrite __P((int, int));
-int filesave __P((int, int));
-int buffsave __P((BUFFER *));
-int makebkfile __P((int, int));
-int writeout __P((BUFFER *, char *));
-VOID upmodes __P((BUFFER *));
-
-/* line.c */
-LINE *lalloc __P((int));
-LINE *lallocx __P((int));
-int lnewline __P((void));
-VOID lfree __P((LINE *));
-VOID lchange __P((int));
-VOID kdelete __P((void));
-int ldelnewline __P((void));
-int linsert __P((int, int));
-
-/* window.c */
-MGWIN *wpopup __P((void));
-int nextwind __P((int, int));
+int dired __P((int, int));
+int d_otherwindow __P((int, int));
+int d_undel __P((int, int));
+int d_undelbak __P((int, int));
+int d_findfile __P((int, int));
+int d_ffotherwindow __P((int, int));
+int d_expunge __P((int, int));
+int d_copy __P((int, int));
+int d_del __P((int, int));
+int d_rename __P((int, int));
+
+/* file.c X */
+int fileinsert __P((int, int));
+int filevisit __P((int, int));
+int poptofile __P((int, int));
+BUFFER *findbuffer __P((char *));
+int readin __P((char *));
+int insertfile __P((char *, char *, int));
+VOID makename __P((char *, char *));
+int filewrite __P((int, int));
+int filesave __P((int, int));
+int buffsave __P((BUFFER *));
+int makebkfile __P((int, int));
+int writeout __P((BUFFER *, char *));
+VOID upmodes __P((BUFFER *));
+
+/* line.c X */
+LINE *lalloc __P((int));
+LINE *lallocx __P((int));
+VOID lfree __P((LINE *));
+VOID lchange __P((int));
+int linsert __P((int, int));
+int lnewline __P((void));
+int ldelete __P((RSIZE, int));
+int ldelnewline __P((void));
+int lreplace __P((RSIZE, char *, int));
+VOID kdelete __P((void));
+int kinsert __P((int, int));
+int kremove __P((int));
+
+/* window.c X */
+int reposition __P((int, int));
+int refresh __P((int, int));
+int nextwind __P((int, int));
+int prevwind __P((int, int));
+int onlywind __P((int, int));
+int splitwind __P((int, int));
+int enlargewind __P((int, int));
+int shrinkwind __P((int, int));
+int delwind __P((int, int));
+MGWIN *wpopup __P((void));
/* buffer.c */
-BUFFER *bfind __P((char *, int));
-int poptobuffer __P((int, int));
-int killbuffer __P((int, int));
-int savebuffers __P((int, int));
-int listbuffers __P((int, int));
-int addline __P((BUFFER *, char *));
-int anycb __P((int));
-int bclear __P((BUFFER *));
-int showbuffer __P((BUFFER *, MGWIN *, int));
-MGWIN *popbuf __P((BUFFER *));
-int bufferinsert __P((int, int));
-int usebuffer __P((int, int));
-int notmodified __P((int, int));
-int popbuftop __P((BUFFER *));
+BUFFER *bfind __P((char *, int));
+int poptobuffer __P((int, int));
+int killbuffer __P((int, int));
+int savebuffers __P((int, int));
+int listbuffers __P((int, int));
+int addline __P((BUFFER *, char *));
+int anycb __P((int));
+int bclear __P((BUFFER *));
+int showbuffer __P((BUFFER *, MGWIN *, int));
+MGWIN *popbuf __P((BUFFER *));
+int bufferinsert __P((int, int));
+int usebuffer __P((int, int));
+int notmodified __P((int, int));
+int popbuftop __P((BUFFER *));
/* display.c */
-VOID vtinit __P((void));
-VOID vttidy __P((void));
-VOID update __P((void));
-
-/* echo.c */
-int eyorn __P((char *));
-int eyesno __P((char *));
-VOID ewprintf __P((const char *fmt, ...));
-int ereply __P((const char *, char *, int, ...));
-int eread __P((const char *, char *, int, int, ...));
-int getxtra __P((LIST *, LIST *, int, int));
+VOID vtinit __P((void));
+VOID vttidy __P((void));
+VOID update __P((void));
+
+/* echo.c X */
+VOID eerase __P((void));
+int eyorn __P((char *));
+int eyesno __P((char *));
+VOID ewprintf __P((const char *fmt, ...));
+int ereply __P((const char *, char *, int, ...));
+int eread __P((const char *, char *, int, int, ...));
+int getxtra __P((LIST *, LIST *, int, int));
/* fileio.c */
-int ffropen __P((char *, BUFFER *));
-int ffwopen __P((char *, BUFFER *));
-int ffclose __P((BUFFER *));
-int ffputbuf __P((BUFFER *));
-int ffgetline __P((char *, int, int *));
-int fbackupfile __P((char *));
-char *adjustname __P((char *));
-char *startupfile __P((char *));
-int copy __P((char *, char *));
-BUFFER *dired_ __P((char *));
-int d_makename __P((LINE *, char *));
-LIST *make_file_list __P((char *, int));
-
-/* keymap.c */
-LIST *complete_function_list __P((char *, int));
+int ffropen __P((char *, BUFFER *));
+int ffwopen __P((char *, BUFFER *));
+int ffclose __P((BUFFER *));
+int ffputbuf __P((BUFFER *));
+int ffgetline __P((char *, int, int *));
+int fbackupfile __P((char *));
+char *adjustname __P((char *));
+char *startupfile __P((char *));
+int copy __P((char *, char *));
+BUFFER *dired_ __P((char *));
+int d_makename __P((LINE *, char *));
+LIST *make_file_list __P((char *, int));
+
+/* keymap.c X */
int complete_function __P((char *, int));
+LIST *complete_function_list __P((char *, int));
-/* kbd.c */
-int do_meta __P((int, int));
-int bsmap __P((int, int));
-VOID ungetkey __P((int));
-int getkey __P((int));
-int doin __P((void));
-int rescan __P((int, int));
-int universal_argument __P((int, int));
-int digit_argument __P((int, int));
-int negative_argument __P((int, int));
-int selfinsert __P((int, int));
-int quote __P((int, int));
+/* kbd.c X */
+int do_meta __P((int, int));
+int bsmap __P((int, int));
+VOID ungetkey __P((int));
+int getkey __P((int));
+int doin __P((void));
+int rescan __P((int, int));
+int universal_argument __P((int, int));
+int digit_argument __P((int, int));
+int negative_argument __P((int, int));
+int selfinsert __P((int, int));
+int quote __P((int, int));
/* main.c */
-int ctrlg __P((int, int));
+int ctrlg __P((int, int));
+int quit __P((int, int));
/* ttyio.c */
-VOID panic __P((char *));
+VOID panic __P((char *));
/* cinfo.c */
-char *keyname __P((char *, int));
+char *keyname __P((char *, int));
/* basic.c */
-int gotobol __P((int, int));
-int backchar __P((int, int));
-int gotoeol __P((int, int));
-int forwchar __P((int, int));
-int gotobob __P((int, int));
-int gotoeob __P((int, int));
-int forwline __P((int, int));
-int backline __P((int, int));
-VOID setgoal __P((void));
-int getgoal __P((LINE *));
-int forwpage __P((int, int));
-int backpage __P((int, int));
-int forw1page __P((int, int));
-int back1page __P((int, int));
-int pagenext __P((int, int));
-VOID isetmark __P((VOID));
-int setmark __P((int, int));
-int swapmark __P((int, int));
-int gotoline __P((int, int));
-
-/* random.c */
-int getcolpos __P((void));
-int newline __P((int, int));
-
-/* extend.c */
-int insert __P((int, int));
-int bindtokey __P((int, int));
-int localbind __P((int, int));
-int define_key __P((int, int));
-int unbindtokey __P((int, int));
-int localunbind __P((int, int));
-int extend __P((int, int));
-int evalexpr __P((int, int));
-int evalbuffer __P((int, int));
-int evalfile __P((int, int));
-int load __P((char *));
-int excline __P((char *));
-
-/* help.c */
-int desckey __P((int, int));
-int wallchart __P((int, int));
-int help_help __P((int, int));
-int apropos_command __P((int, int));
+int gotobol __P((int, int));
+int backchar __P((int, int));
+int gotoeol __P((int, int));
+int forwchar __P((int, int));
+int gotobob __P((int, int));
+int gotoeob __P((int, int));
+int forwline __P((int, int));
+int backline __P((int, int));
+VOID setgoal __P((void));
+int getgoal __P((LINE *));
+int forwpage __P((int, int));
+int backpage __P((int, int));
+int forw1page __P((int, int));
+int back1page __P((int, int));
+int pagenext __P((int, int));
+VOID isetmark __P((VOID));
+int setmark __P((int, int));
+int swapmark __P((int, int));
+int gotoline __P((int, int));
+
+/* random.c X */
+int showcpos __P((int, int));
+int getcolpos __P((void));
+int twiddle __P((int, int));
+int openline __P((int, int));
+int newline __P((int, int));
+int deblank __P((int, int));
+int justone __P((int, int));
+int delwhite __P((int, int));
+int indent __P((int, int));
+int forwdel __P((int, int));
+int backdel __P((int, int));
+int killline __P((int, int));
+int yank __P((int, int));
+int space_to_tabstop __P((int, int));
+
+/* extend.c X */
+int insert __P((int, int));
+int bindtokey __P((int, int));
+int localbind __P((int, int));
+int define_key __P((int, int));
+int unbindtokey __P((int, int));
+int localunbind __P((int, int));
+int extend __P((int, int));
+int evalexpr __P((int, int));
+int evalbuffer __P((int, int));
+int evalfile __P((int, int));
+int load __P((char *));
+int excline __P((char *));
+
+/* help.c X */
+int desckey __P((int, int));
+int wallchart __P((int, int));
+int help_help __P((int, int));
+int apropos_command __P((int, int));
+
+/* paragraph.c X */
+int gotobop __P((int, int));
+int gotoeop __P((int, int));
+int fillpara __P((int, int));
+int killpara __P((int, int));
+int fillword __P((int, int));
+int setfillcol __P((int, int));
+
+/* word.c X */
+int backword __P((int, int));
+int forwword __P((int, int));
+int upperword __P((int, int));
+int lowerword __P((int, int));
+int capword __P((int, int));
+int delfword __P((int, int));
+int delbword __P((int, int));
+int inword __P((void));
+
+/* region.c X */
+int killregion __P((int, int));
+int copyregion __P((int, int));
+int lowerregion __P((int, int));
+int upperregion __P((int, int));
+int prefixregion __P((int, int));
+int setprefix __P((int, int));
+
+/* search.c X */
+int forwsearch __P((int, int));
+int backsearch __P((int, int));
+int searchagain __P((int, int));
+int forwisearch __P((int, int));
+int backisearch __P((int, int));
+int queryrepl __P((int, int));
+int forwsrch __P((void));
+int backsrch __P((void));
+int readpattern __P((char *));
+
+/* spawn.c X */
+int spawncli __P((int, int));
+
+/* ttykbd.c X */
+void ttykeymapinit __P((void));
+void ttykeymaptidy __P((void));
+
+/* match.c X */
+int showmatch __P((int, int));
+
+/* version.c X */
+int showversion __P((int, int));
+
+#ifndef NO_MACRO
+/* macro.c X */
+int definemacro __P((int, int));
+int finishmacro __P((int, int));
+int executemacro __P((int, int));
+#endif /* !NO_MACRO */
+
+/* modes.c X */
+int indentmode __P((int, int));
+int fillmode __P((int, int));
+int blinkparen __P((int, int));
+#ifdef NOTAB
+int notabmode __P((int, int));
+#endif /* NOTAB */
+int overwrite __P((int, int));
+int set_default_mode __P((int,int));
+
+#ifdef REGEX
+/* re_search.c X */
+int re_forwsearch __P((int, int));
+int re_backsearch __P((int, int));
+int re_searchagain __P((int, int));
+int re_queryrepl __P((int, int));
+int setcasefold __P((int, int));
+int delmatchlines __P((int, int));
+int delnonmatchlines __P((int, int));
+int cntmatchlines __P((int, int));
+int cntnonmatchlines __P((int, int));
+#endif /* REGEX */
/*
* Externals.
*/
-extern int thisflag;
-extern int lastflag;
-extern int curgoal;
-extern int epresf;
-extern int sgarbf;
-extern int mode;
-extern MGWIN *curwp;
-extern BUFFER *curbp;
-extern MGWIN *wheadp;
-extern BUFFER *bheadp;
-extern char pat[];
-extern int nrow;
-extern int ncol;
-extern int ttrow;
-extern int ttcol;
-extern int tthue;
-extern int tceeol;
-extern int tcinsl;
-extern int tcdell;
-extern char cinfo[];
-extern char *keystrings[];
+extern BUFFER *bheadp;
+extern BUFFER *curbp;
+extern MGWIN *curwp;
+extern MGWIN *wheadp;
+extern int thisflag;
+extern int lastflag;
+extern int curgoal;
+extern int epresf;
+extern int sgarbf;
+extern int mode;
+extern int nrow;
+extern int ncol;
+extern int ttrow;
+extern int ttcol;
+extern int tttop;
+extern int ttbot;
+extern int tthue;
+extern int nmaps;
+extern int nfunct;
+extern int defb_nmodes;
+extern int defb_flag;
+extern char cinfo[];
+extern char *keystrings[];
+extern char pat[];
+#ifndef NO_DPROMPT
+extern char prompt[];
+extern char *promptp;
+#endif /* !NO_DPROMPT */
+
+/*
+ * Globals.
+ */
+int tceeol;
+int tcinsl;
+int tcdell;
+
diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c
index 775be72fa7e..3f85bbaf3ab 100644
--- a/usr.bin/mg/echo.c
+++ b/usr.bin/mg/echo.c
@@ -1,34 +1,34 @@
/*
- * Echo line reading and writing.
+ * Echo line reading and writing.
*
- * Common routines for reading
- * and writing characters in the echo line area
- * of the display screen. Used by the entire
- * known universe.
+ * Common routines for reading and writing characters in the echo line area
+ * of the display screen. Used by the entire known universe.
*/
-#include "def.h"
-#include "key.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+
+#include "def.h"
+#include "key.h"
#ifndef NO_MACRO
-#include "macro.h"
-#endif
+#include "macro.h"
+#endif /* !NO_MACRO */
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else /* __STDC__ */
+#include <varargs.h>
+#endif /* __STDC__ */
-static VOID eformat __P((const char *, va_list));
static int veread __P((const char *, char *buf, int, int, va_list));
+static int complt __P((int, int, char *, int));
+static int complt_list __P((int, int, char *, int));
+static VOID eformat __P((const char *, va_list));
static VOID eputi __P((int, int));
static VOID eputl __P((long, int));
static VOID eputs __P((char *));
static VOID eputc __P((char));
-static int complt __P((int, int, char *, int));
-static int complt_list __P((int, int, char *, int));
-static LIST *copy_list __P((LIST *));
static VOID free_file_list __P((LIST *));
+static LIST *copy_list __P((LIST *));
-int epresf = FALSE; /* Stuff in echo line flag. */
+int epresf = FALSE; /* stuff in echo line flag */
/*
* Erase the echo line.
@@ -36,7 +36,6 @@ int epresf = FALSE; /* Stuff in echo line flag. */
VOID
eerase()
{
-
ttcolor(CTEXT);
ttmove(nrow - 1, 0);
tteeol();
@@ -45,22 +44,21 @@ eerase()
}
/*
- * Ask "yes" or "no" question.
- * Return ABORT if the user answers the question
- * with the abort ("^G") character. Return FALSE
- * for "no" and TRUE for "yes". No formatting
- * services are available. No newline required.
+ * Ask a "yes" or "no" question. Return ABORT if the user answers the
+ * question with the abort ("^G") character. Return FALSE for "no" and
+ * TRUE for "yes". No formatting services are available. No newline
+ * required.
*/
int
eyorn(sp)
- char *sp;
+ char *sp;
{
- int s;
+ int s;
#ifndef NO_MACRO
if (inmacro)
return TRUE;
-#endif
+#endif /* !NO_MACRO */
ewprintf("%s? (y or n) ", sp);
for (;;) {
s = getkey(FALSE);
@@ -76,20 +74,20 @@ eyorn(sp)
}
/*
- * Like eyorn, but for more important question. User must type either all of
- * "yes" or "no", and the trainling newline.
+ * Like eyorn, but for more important questions. User must type all of
+ * "yes" or "no" and the trainling newline.
*/
int
eyesno(sp)
- char *sp;
+ char *sp;
{
- int s;
- char buf[64];
+ int s;
+ char buf[64];
#ifndef NO_MACRO
if (inmacro)
return TRUE;
-#endif
+#endif /* !NO_MACRO */
s = ereply("%s? (yes or no) ", buf, sizeof(buf), sp);
for (;;) {
if (s == ABORT)
@@ -97,13 +95,13 @@ eyesno(sp)
if (s != FALSE) {
#ifndef NO_MACRO
if (macrodef) {
- LINE *lp = maclcur;
+ LINE *lp = maclcur;
maclcur = lp->l_bp;
maclcur->l_fp = lp->l_fp;
- free((char *) lp);
+ free((char *)lp);
}
-#endif
+#endif /* !NO_MACRO */
if ((buf[0] == 'y' || buf[0] == 'Y')
&& (buf[1] == 'e' || buf[1] == 'E')
&& (buf[2] == 's' || buf[2] == 'S')
@@ -115,81 +113,76 @@ eyesno(sp)
return FALSE;
}
s = ereply("Please answer yes or no. %s? (yes or no) ",
- buf, sizeof(buf), sp);
+ buf, sizeof(buf), sp);
}
/* NOTREACHED */
}
/*
- * Write out a prompt, and read back a
- * reply. The prompt is now written out with full "ewprintf"
- * formatting, although the arguments are in a rather strange
- * place. This is always a new message, there is no auto
+ * Write out a prompt and read back a reply. The prompt is now written
+ * out with full "ewprintf" formatting, although the arguments are in a
+ * rather strange place. This is always a new message, there is no auto
* completion, and the return is echoed as such.
*/
/* VARARGS */
int
#ifdef __STDC__
ereply(const char *fmt, char *buf, int nbuf, ...)
-#else
+#else /* __STDC__ */
ereply(va_alist)
va_dcl
-#endif
+#endif /* __STDC__ */
{
- va_list ap;
- int i;
+ va_list ap;
+ int i;
#ifdef __STDC__
va_start(ap, nbuf);
-#else
- char *fmt, *buf;
- int nbuf;
+#else /* __STDC__ */
+ char *fmt, *buf;
+ int nbuf;
va_start(ap);
fmt = va_arg(ap, char *);
buf = va_arg(ap, char *);
nbuf = va_arg(ap, int);
-#endif
+#endif /* __STDC__ */
i = veread(fmt, buf, nbuf, EFNEW | EFCR, ap);
va_end(ap);
return i;
}
/*
- * This is the general "read input from the
- * echo line" routine. The basic idea is that the prompt
- * string "prompt" is written to the echo line, and a one
- * line reply is read back into the supplied "buf" (with
- * maximum length "len"). The "flag" contains EFNEW (a
- * new prompt), an EFFUNC (autocomplete), or EFCR (echo
- * the carriage return as CR).
+ * This is the general "read input from the echo line" routine. The basic
+ * idea is that the prompt string "prompt" is written to the echo line, and
+ * a one line reply is read back into the supplied "buf" (with maximum
+ * length "len"). The "flag" contains EFNEW (a new prompt), an EFFUNC
+ * (autocomplete), or EFCR (echo the carriage return as CR).
*/
/* VARARGS */
int
#ifdef __STDC__
eread(const char *fmt, char *buf, int nbuf, int flag, ...)
-#else
+#else /* __STDC__ */
eread(va_alist)
- char *fmt;
- char *buf;
- int nbuf;
- int flag;
+ char *fmt, *buf;
+ int buf, flag;
va_dcl
-#endif
+#endif /* __STDC__ */
{
- int i;
- va_list ap;
+ int i;
+ va_list ap;
#ifdef __STDC__
va_start(ap, flag);
-#else
- char *fmt, *buf;
- int nbuf;
+#else /* __STDC__ */
+ char *fmt, *buf;
+ int nbuf;
va_start(ap);
fmt = va_arg(ap, char *);
buf = va_arg(ap, char *);
nbuf = va_arg(ap, int);
flag = va_arg(ap, int);
-#endif
+#endif /* __STDC__ */
i = veread(fmt, buf, nbuf, flag, ap);
va_end(ap);
return i;
@@ -199,13 +192,12 @@ static int
veread(fp, buf, nbuf, flag, ap)
const char *fp;
char *buf;
- int nbuf;
- int flag;
+ int nbuf, flag;
va_list ap;
{
- int cpos;
- int i;
- int c;
+ int cpos;
+ int i;
+ int c;
#ifndef NO_MACRO
if (inmacro) {
@@ -214,7 +206,7 @@ veread(fp, buf, nbuf, flag, ap)
maclcur = maclcur->l_fp;
return TRUE;
}
-#endif
+#endif /* !NO_MACRO */
cpos = 0;
if ((flag & EFNEW) != 0 || ttrow != nrow - 1) {
ttcolor(CTEXT);
@@ -237,8 +229,9 @@ veread(fp, buf, nbuf, flag, ap)
}
switch (c) {
case CCHR('J'):
- c = CCHR('M'); /* and continue */
- case CCHR('M'):/* Return, done. */
+ c = CCHR('M');
+ /* and continue */
+ case CCHR('M'): /* return, done */
if ((flag & EFFUNC) != 0) {
if ((i = complt(flag, c, buf, cpos)) == 0)
continue;
@@ -252,7 +245,7 @@ veread(fp, buf, nbuf, flag, ap)
}
#ifndef NO_MACRO
if (macrodef) {
- LINE *lp;
+ LINE *lp;
if ((lp = lalloc(cpos)) == NULL)
return FALSE;
@@ -262,17 +255,15 @@ veread(fp, buf, nbuf, flag, ap)
maclcur = lp;
bcopy(buf, lp->l_text, cpos);
}
-#endif
+#endif /* !NO_MACRO */
goto done;
-
- case CCHR('G'): /* Bell, abort. */
+ case CCHR('G'): /* bell, abort */
eputc(CCHR('G'));
- (VOID) ctrlg(FFRAND, 0);
+ (VOID)ctrlg(FFRAND, 0);
ttflush();
return ABORT;
-
- case CCHR('H'):
- case CCHR('?'): /* Rubout, erase. */
+ case CCHR('H'): /* rubout, erase */
+ case CCHR('?'):
if (cpos != 0) {
ttputc('\b');
ttputc(' ');
@@ -287,9 +278,8 @@ veread(fp, buf, nbuf, flag, ap)
ttflush();
}
break;
-
- case CCHR('X'): /* C-X */
- case CCHR('U'): /* C-U, kill line. */
+ case CCHR('X'): /* kill line */
+ case CCHR('U'):
while (cpos != 0) {
ttputc('\b');
ttputc(' ');
@@ -304,10 +294,7 @@ veread(fp, buf, nbuf, flag, ap)
}
ttflush();
break;
-
- case CCHR('W'): /* C-W, kill to beginning of */
- /* previous word */
- /* back up to first word character or beginning */
+ case CCHR('W'): /* kill to beginning of word */
while ((cpos > 0) && !ISWORD(buf[cpos - 1])) {
ttputc('\b');
ttputc(' ');
@@ -334,14 +321,14 @@ veread(fp, buf, nbuf, flag, ap)
}
ttflush();
break;
-
case CCHR('\\'):
- case CCHR('Q'): /* C-Q, quote next */
- c = getkey(FALSE); /* and continue */
- default: /* All the rest. */
+ case CCHR('Q'): /* quote next */
+ c = getkey(FALSE);
+ /* and continue */
+ default: /* all the rest */
if (cpos < nbuf - 1) {
- buf[cpos++] = (char) c;
- eputc((char) c);
+ buf[cpos++] = (char)c;
+ eputc((char)c);
ttflush();
}
}
@@ -354,18 +341,16 @@ done: return buf[0] != '\0';
*/
static int
complt(flags, c, buf, cpos)
- int flags;
- int c;
- char *buf;
- int cpos;
+ int flags, c, cpos;
+ char *buf;
{
- LIST *lh, *lh2;
- LIST *wholelist = NULL;
- int i, nxtra;
- int nhits, bxtra;
- int wflag = FALSE;
- int msglen, nshown;
- char *msg;
+ LIST *lh, *lh2;
+ LIST *wholelist = NULL;
+ int i, nxtra, nhits, bxtra, msglen, nshown;
+ int wflag = FALSE;
+ char *msg;
+
+ lh = lh2 = NULL;
if ((flags & EFFUNC) != 0) {
buf[cpos] = '\0';
@@ -431,7 +416,7 @@ complt(flags, c, buf, cpos)
msg = " [No match]";
else if (nhits > 1 && nxtra == 0)
msg = " [Ambiguous]";
- else { /* Got a match, do it to it */
+ else {
/*
* Being lazy - ought to check length, but all things
* autocompleted have known types/lengths.
@@ -449,11 +434,13 @@ complt(flags, c, buf, cpos)
return nxtra;
}
}
+
/*
* wholelist is null if we are doing buffers. want to free lists
* that were created for us, but not the buffer list!
*/
free_file_list(wholelist);
+
/* Set up backspaces, etc., being mindful of echo line limit */
msglen = strlen(msg);
nshown = (ttcol + msglen + 2 > ncol) ?
@@ -464,7 +451,7 @@ complt(flags, c, buf, cpos)
ttputc('\b');
ttflush(); /* display to user */
i = nshown;
- while (i--) /* blank out on next flush */
+ while (i--) /* blank out on next flush */
eputc(' ');
ttcol -= (i = nshown); /* update ttcol on BS's */
while (i--)
@@ -477,21 +464,23 @@ complt(flags, c, buf, cpos)
*/
static int
complt_list(flags, c, buf, cpos)
- int flags;
- int c;
- char *buf;
- int cpos;
+ int flags;
+ int c;
+ char *buf;
+ int cpos;
{
- LIST *lh, *lh2, *lh3;
- LIST *wholelist = NULL;
- int i, maxwidth, width;
- int preflen = 0;
- BUFFER *bp;
- int oldrow = ttrow;
- int oldcol = ttcol;
- int oldhue = tthue;
- char linebuf[NCOL + 1];
- char *cp;
+ LIST *lh, *lh2, *lh3;
+ LIST *wholelist = NULL;
+ BUFFER *bp;
+ int i, maxwidth, width;
+ int preflen = 0;
+ int oldrow = ttrow;
+ int oldcol = ttcol;
+ int oldhue = tthue;
+ char linebuf[NCOL + 1];
+ char *cp;
+
+ lh = NULL;
ttflush();
@@ -621,19 +610,18 @@ complt_list(flags, c, buf, cpos)
}
/*
- * The "lp1" and "lp2" point to list structures. The
- * "cpos" is a horizontal position in the name.
- * Return the longest block of characters that can be
- * autocompleted at this point. Sometimes the two
- * symbols are the same, but this is normal.
+ * The "lp1" and "lp2" point to list structures. The "cpos" is a horizontal
+ * position in the name. Return the longest block of characters that can be
+ * autocompleted at this point. Sometimes the two symbols are the same, but
+ * this is normal.
*/
int
getxtra(lp1, lp2, cpos, wflag)
- LIST *lp1, *lp2;
- int cpos;
- int wflag;
+ LIST *lp1, *lp2;
+ int cpos;
+ int wflag;
{
- int i;
+ int i;
i = cpos;
for (;;) {
@@ -649,36 +637,35 @@ getxtra(lp1, lp2, cpos, wflag)
}
/*
- * Special "printf" for the echo line.
- * Each call to "ewprintf" starts a new line in the
- * echo area, and ends with an erase to end of the
- * echo line. The formatting is done by a call
- * to the standard formatting routine.
+ * Special "printf" for the echo line. Each call to "ewprintf" starts a
+ * new line in the echo area, and ends with an erase to end of the echo
+ * line. The formatting is done by a call to the standard formatting
+ * routine.
*/
/* VARARGS */
VOID
#ifdef __STDC__
ewprintf(const char *fmt, ...)
-#else
+#else /* __STDC__ */
ewprintf(va_alist)
va_dcl
-#endif
+#endif /* __STDC__ */
{
- va_list ap;
+ va_list ap;
#ifndef __STDC__
- char *fmt;
-#endif
+ char *fmt;
+#endif /* !__STDC__ */
#ifndef NO_MACRO
if (inmacro)
return;
-#endif
+#endif /* !NO_MACRO */
#ifdef __STDC__
va_start(ap, fmt);
-#else
+#else /* __STDC__ */
va_start(ap);
fmt = va_arg(ap, char *);
-#endif
+#endif /* __STDC__ */
ttcolor(CTEXT);
ttmove(nrow - 1, 0);
eformat(fmt, ap);
@@ -689,22 +676,21 @@ ewprintf(va_alist)
}
/*
- * Printf style formatting. This is
- * called by both "ewprintf" and "ereply" to provide
- * formatting services to their clients. The move to the
- * start of the echo line, and the erase to the end of
- * the echo line, is done by the caller.
+ * Printf style formatting. This is called by both "ewprintf" and "ereply"
+ * to provide formatting services to their clients. The move to the start
+ * of the echo line, and the erase to the end of the echo line, is done by
+ * the caller.
* Note: %c works, and prints the "name" of the character.
* %k prints the name of a key (and takes no arguments).
*/
static VOID
eformat(fp, ap)
- const char *fp;
- va_list ap;
+ const char *fp;
+ va_list ap;
{
- int c;
- char kname[NKNAME];
- char *cp;
+ int c;
+ char kname[NKNAME];
+ char *cp;
while ((c = *fp++) != '\0') {
if (c != '%')
@@ -713,7 +699,7 @@ eformat(fp, ap)
c = *fp++;
switch (c) {
case 'c':
- (VOID) keyname(kname, va_arg(ap, int));
+ (VOID)keyname(kname, va_arg(ap, int));
eputs(kname);
break;
@@ -739,11 +725,12 @@ eformat(fp, ap)
eputs(va_arg(ap, char *));
break;
- case 'l': /* explicit longword */
+ case 'l':
+ /* explicit longword */
c = *fp++;
switch (c) {
case 'd':
- eputl((long) va_arg(ap, long), 10);
+ eputl((long)va_arg(ap, long), 10);
break;
default:
eputc(c);
@@ -763,10 +750,9 @@ eformat(fp, ap)
*/
static VOID
eputi(i, r)
- int i;
- int r;
+ int i, r;
{
- int q;
+ int q;
if (i < 0) {
eputc('-');
@@ -782,10 +768,10 @@ eputi(i, r)
*/
static VOID
eputl(l, r)
- long l;
- int r;
+ long l;
+ int r;
{
- long q;
+ long q;
if (l < 0) {
eputc('-');
@@ -793,7 +779,7 @@ eputl(l, r)
}
if ((q = l / r) != 0)
eputl(q, r);
- eputc((int) (l % r) + '0');
+ eputc((int)(l % r) + '0');
}
/*
@@ -801,24 +787,22 @@ eputl(l, r)
*/
static VOID
eputs(s)
- char *s;
+ char *s;
{
- int c;
+ int c;
while ((c = *s++) != '\0')
eputc(c);
}
/*
- * Put character. Watch for
- * control characters, and for the line
- * getting too long.
+ * Put character. Watch for control characters, and for the line getting
+ * too long.
*/
static VOID
eputc(c)
- char c;
+ char c;
{
-
if (ttcol + 2 < ncol) {
if (ISCTRL(c)) {
eputc('^');
@@ -833,7 +817,7 @@ static VOID
free_file_list(lp)
LIST *lp;
{
- LIST *next;
+ LIST *next;
while (lp) {
next = lp->l_next;
@@ -846,14 +830,14 @@ static LIST *
copy_list(lp)
LIST *lp;
{
- LIST *current, *last;
+ LIST *current, *last;
last = NULL;
while (lp) {
- current = (LIST *) malloc(sizeof(LIST));
+ current = (LIST *)malloc(sizeof(LIST));
current->l_next = last;
current->l_name = lp->l_name;
- last = (LIST *) current;
+ last = (LIST *)current;
lp = lp->l_next;
}
return (last);
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c
index 774dbbfc06b..ed7959c2237 100644
--- a/usr.bin/mg/extend.c
+++ b/usr.bin/mg/extend.c
@@ -1,41 +1,43 @@
/*
- * Extended (M-X) commands, rebinding, and
- * startup file processing.
+ * Extended (M-X) commands, rebinding, and startup file processing.
*/
-#include "def.h"
-#include "kbd.h"
+
+#include "def.h"
+#include "kbd.h"
#ifndef NO_MACRO
-#include "macro.h"
-#endif
+#include "macro.h"
+#endif /* !NO_MACRO */
#ifdef FKEYS
-#include "key.h"
+#include "key.h"
#ifndef NO_STARTUP
#ifndef BINDKEY
#define BINDKEY /* bindkey is used by FKEYS startup code */
-#endif
-#endif
-#endif
-
-static KEYMAP *realocmap __P((KEYMAP *));
-static VOID fixmap __P((KEYMAP *, KEYMAP*, KEYMAP*));
-static char *skipwhite __P((char *));
-static char *parsetoken __P((char *));
-int load __P((char *));
-int excline __P((char *));
-
-/* insert a string, mainly for use from macros (created by selfinsert) */
+#endif /* !BINDKEY */
+#endif /* !NO_STARTUP */
+#endif /* FKEYS */
+
+static int remap __P((KEYMAP *, int, PF, KEYMAP *));
+static KEYMAP *realocmap __P((KEYMAP *));
+static VOID fixmap __P((KEYMAP *, KEYMAP *, KEYMAP *));
+static int dobind __P((KEYMAP *, char *, int));
+static char *skipwhite __P((char *));
+static char *parsetoken __P((char *));
+static int bindkey __P((KEYMAP **, char *, KCHAR *, int));
+
+/*
+ * Insert a string, mainly for use from macros (created by selfinsert)
+ */
/* ARGSUSED */
int
insert(f, n)
int f, n;
{
- char *cp;
- char buf[128];
+ char *cp;
+ char buf[128];
#ifndef NO_MACRO
- int count;
- int c;
+ int count, c;
if (inmacro) {
while (--n >= 0) {
@@ -49,9 +51,9 @@ insert(f, n)
return TRUE;
}
if (n == 1)
- thisflag |= CFINS; /* CFINS means selfinsert can tack on
- * end */
-#endif
+ /* CFINS means selfinsert can tack on the end */
+ thisflag |= CFINS;
+#endif /* !NO_MACRO */
if (eread("Insert: ", buf, sizeof(buf), EFNEW) == FALSE)
return FALSE;
while (--n >= 0) {
@@ -85,28 +87,26 @@ remap(curmap, c, funct, pref_map)
PF funct; /* function being changed to */
KEYMAP *pref_map; /* if funct==prefix, map to bind to or
NULL for new */
-/* extern MAP_ELEMENT *ele; must be set before calling */
{
- int i;
- int n1, n2, nold;
- KEYMAP *mp;
- PF *pfp;
- MAP_ELEMENT *mep;
+ int i, n1, n2, nold;
+ KEYMAP *mp;
+ PF *pfp;
+ MAP_ELEMENT *mep;
if (ele >= &curmap->map_element[curmap->map_num] || c < ele->k_base) {
if (ele > &curmap->map_element[0] && (funct != prefix ||
- (ele - 1)->k_prefmap == NULL)) {
+ (ele - 1)->k_prefmap == NULL))
n1 = c - (ele - 1)->k_num;
- } else
+ else
n1 = HUGE;
if (ele < &curmap->map_element[curmap->map_num] &&
- (funct != prefix || ele->k_prefmap == NULL)) {
+ (funct != prefix || ele->k_prefmap == NULL))
n2 = ele->k_base - c;
- } else
+ else
n2 = HUGE;
if (n1 <= MAPELEDEF && n1 <= n2) {
ele--;
- if ((pfp = (PF *) malloc((c - ele->k_base + 1) *
+ if ((pfp = (PF *)malloc((c - ele->k_base + 1) *
sizeof(PF))) == NULL) {
ewprintf("Out of memory");
return FALSE;
@@ -120,8 +120,8 @@ remap(curmap, c, funct, pref_map)
ele->k_num = c;
ele->k_funcp = pfp;
} else if (n2 <= MAPELEDEF) {
- if ((pfp = (PF *) malloc((ele->k_num - c + 1)
- * sizeof(PF))) == NULL) {
+ if ((pfp = (PF *)malloc((ele->k_num - c + 1) *
+ sizeof(PF))) == NULL) {
ewprintf("Out of memory");
return FALSE;
}
@@ -137,7 +137,7 @@ remap(curmap, c, funct, pref_map)
if (curmap->map_num >= curmap->map_max &&
(curmap = realocmap(curmap)) == NULL)
return FALSE;
- if ((pfp = (PF *) malloc(sizeof(PF))) == NULL) {
+ if ((pfp = (PF *)malloc(sizeof(PF))) == NULL) {
ewprintf("Out of memory");
return FALSE;
}
@@ -159,7 +159,7 @@ remap(curmap, c, funct, pref_map)
if (pref_map != NULL) {
ele->k_prefmap = pref_map;
} else {
- if (!(mp = (KEYMAP *) malloc(sizeof(KEYMAP) +
+ if (!(mp = (KEYMAP *)malloc(sizeof(KEYMAP) +
(MAPINIT - 1) * sizeof(MAP_ELEMENT)))) {
ewprintf("Out of memory");
ele->k_funcp[c - ele->k_base] =
@@ -176,17 +176,20 @@ remap(curmap, c, funct, pref_map)
n1 = c - ele->k_base;
if (ele->k_funcp[n1] == funct && (funct != prefix ||
pref_map == NULL || pref_map == ele->k_prefmap))
- return TRUE; /* no change */
+ /* no change */
+ return TRUE;
if (funct != prefix || ele->k_prefmap == NULL) {
if (ele->k_funcp[n1] == prefix)
ele->k_prefmap = (KEYMAP *) NULL;
- ele->k_funcp[n1] = funct; /* easy case */
+ /* easy case */
+ ele->k_funcp[n1] = funct;
if (funct == prefix) {
if (pref_map != NULL)
ele->k_prefmap = pref_map;
else {
if (!(mp = malloc(sizeof(KEYMAP) +
- (MAPINIT - 1) * sizeof(MAP_ELEMENT)))) {
+ (MAPINIT - 1) *
+ sizeof(MAP_ELEMENT)))) {
ewprintf("Out of memory");
ele->k_funcp[c - ele->k_base] =
curmap->map_default;
@@ -200,8 +203,8 @@ remap(curmap, c, funct, pref_map)
}
} else {
/*
- * This case is the splits
- * determine which side of the break c goes on
+ * This case is the splits.
+ * Determine which side of the break c goes on
* 0 = after break; 1 = before break
*/
n2 = 1;
@@ -210,7 +213,8 @@ remap(curmap, c, funct, pref_map)
if (curmap->map_num >= curmap->map_max &&
(curmap = realocmap(curmap)) == NULL)
return FALSE;
- if (!(pfp = malloc((ele->k_num - c + !n2) * sizeof(PF)))) {
+ if ((pfp = malloc((ele->k_num - c + !n2) *
+ sizeof(PF))) == NULL) {
ewprintf("Out of memory");
return FALSE;
}
@@ -254,14 +258,14 @@ remap(curmap, c, funct, pref_map)
*/
static KEYMAP *
realocmap(curmap)
- KEYMAP *curmap;
+ KEYMAP *curmap;
{
- KEYMAP *mp;
- int i;
- extern int nmaps;
+ KEYMAP *mp;
+ int i;
- if ((mp = (KEYMAP *) malloc((unsigned) (sizeof(KEYMAP) +
- (curmap->map_max + (MAPGROW - 1)) * sizeof(MAP_ELEMENT)))) == NULL) {
+ if ((mp = (KEYMAP *)malloc((unsigned)(sizeof(KEYMAP) +
+ (curmap->map_max + (MAPGROW - 1)) *
+ sizeof(MAP_ELEMENT)))) == NULL) {
ewprintf("Out of memory");
return NULL;
}
@@ -293,7 +297,7 @@ fixmap(curmap, mp, mt)
KEYMAP *curmap;
KEYMAP *mp;
{
- int i;
+ int i;
for (i = mt->map_num; i--;) {
if (mt->map_element[i].k_prefmap != NULL) {
@@ -315,12 +319,11 @@ dobind(curmap, p, unbind)
char *p;
int unbind;
{
- PF funct;
- char prompt[80];
- char *pep;
- int c;
- int s;
- KEYMAP *pref_map = NULL;
+ KEYMAP *pref_map = NULL;
+ PF funct;
+ char prompt[80];
+ char *pep;
+ int c, s;
#ifndef NO_MACRO
if (macrodef) {
@@ -336,18 +339,18 @@ dobind(curmap, p, unbind)
for (s = 0; s < maclcur->l_used - 1; s++) {
if (doscan(curmap, c = CHARMASK(maclcur->l_text[s]))
!= prefix) {
- if (remap(curmap, c, prefix, (KEYMAP *) NULL)
+ if (remap(curmap, c, prefix, (KEYMAP *)NULL)
!= TRUE)
return FALSE;
}
curmap = ele->k_prefmap;
}
- (VOID) doscan(curmap, c = maclcur->l_text[s]);
+ (VOID)doscan(curmap, c = maclcur->l_text[s]);
maclcur = maclcur->l_fp;
} else {
-#endif
-#endif
- (VOID) strcpy(prompt, p);
+#endif /* !NO_STARTUP */
+#endif /* !NO_MACRO */
+ (VOID)strcpy(prompt, p);
pep = prompt + strlen(prompt);
for (;;) {
ewprintf("%s", prompt);
@@ -361,7 +364,7 @@ dobind(curmap, p, unbind)
}
#ifndef NO_STARTUP
}
-#endif
+#endif /* !NO_STARTUP */
if (unbind)
funct = rescan;
else {
@@ -378,39 +381,39 @@ dobind(curmap, p, unbind)
}
/*
- * bindkey: bind key sequence to a function in
- * the specified map. Used by excline so it can bind function keys.
- * To close to release to change calling sequence, should just pass
- * KEYMAP *curmap rather than KEYMAP **mapp.
-*/
+ * bindkey: bind key sequence to a function in the specified map. Used by
+ * excline so it can bind function keys. To close to release to change
+ * calling sequence, should just pass KEYMAP *curmap rather than
+ * KEYMAP **mapp.
+ */
#ifdef BINDKEY
-int
+static int
bindkey(mapp, fname, keys, kcount)
KEYMAP **mapp;
- char *fname;
- KCHAR *keys;
- int kcount;
+ char *fname;
+ KCHAR *keys;
+ int kcount;
{
- KEYMAP *curmap = *mapp;
- PF funct;
- int c;
- KEYMAP *pref_map = NULL;
+ KEYMAP *curmap = *mapp;
+ KEYMAP *pref_map = NULL;
+ PF funct;
+ int c;
if (fname == NULL)
funct = rescan;
else if (((funct = name_function(fname)) == prefix) ?
- (pref_map = name_map(fname)) == NULL : funct == NULL) {
+ (pref_map = name_map(fname)) == NULL : funct == NULL) {
ewprintf("[No match: %s]", fname);
return FALSE;
}
while (--kcount) {
if (doscan(curmap, c = *keys++) != prefix) {
- if (remap(curmap, c, prefix, (KEYMAP *) NULL) != TRUE)
+ if (remap(curmap, c, prefix, (KEYMAP *)NULL) != TRUE)
return FALSE;
}
curmap = ele->k_prefmap;
}
- (VOID) doscan(curmap, c = *keys);
+ (VOID)doscan(curmap, c = *keys);
return remap(curmap, c, funct, pref_map);
}
@@ -424,7 +427,7 @@ dobindkey(map, func, str)
char *func;
char *str;
{
- int i;
+ int i;
for (i = 0; *str && i < MAXKEY; i++) {
/* XXX - convert numbers w/ strol()? */
@@ -455,8 +458,8 @@ dobindkey(map, func, str)
key.k_count = i;
return (bindkey(&map, func, key.k_chars, key.k_count));
}
-#endif
-#endif
+#endif /* FKEYS */
+#endif /* BINDKEY */
/*
* This function modifies the fundamental keyboard map.
@@ -477,9 +480,8 @@ int
localbind(f, n)
int f, n;
{
-
- return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, "Local set key: ",
- FALSE);
+ return dobind(curbp->b_modes[curbp->b_nmodes]->p_map,
+ "Local set key: ", FALSE);
}
/*
@@ -490,9 +492,8 @@ int
define_key(f, n)
int f, n;
{
- static char buf[48] = "Define key map: ";
- MAPS *mp;
- char *strncat();
+ static char buf[48] = "Define key map: ";
+ MAPS *mp;
buf[16] = '\0';
if (eread(buf, &buf[16], 48 - 16, EFNEW) != TRUE)
@@ -501,7 +502,7 @@ define_key(f, n)
ewprintf("Unknown map %s", &buf[16]);
return FALSE;
}
- (VOID) strncat(&buf[16], " key: ", 48 - 16 - 1);
+ (VOID)strncat(&buf[16], " key: ", 48 - 16 - 1);
return dobind(mp->p_map, buf, FALSE);
}
@@ -509,7 +510,6 @@ int
unbindtokey(f, n)
int f, n;
{
-
return dobind(map_table[0].p_map, "Global unset key: ", TRUE);
}
@@ -517,25 +517,23 @@ int
localunbind(f, n)
int f, n;
{
-
return dobind(curbp->b_modes[curbp->b_nmodes]->p_map,
"Local unset key: ", TRUE);
}
/*
- * Extended command. Call the message line
- * routine to read in the command name and apply autocompletion
- * to it. When it comes back, look the name up in the symbol table
- * and run the command if it is found.
- * Print an error if there is anything wrong.
+ * Extended command. Call the message line routine to read in the command
+ * name and apply autocompletion to it. When it comes back, look the name
+ * up in the symbol table and run the command if it is found. Print an
+ * error if there is anything wrong.
*/
int
extend(f, n)
- int f, n;
+ int f, n;
{
- PF funct;
- int s;
- char xname[NXNAME];
+ PF funct;
+ int s;
+ char xname[NXNAME];
if (!(f & FFARG))
s = eread("M-x ", xname, NXNAME, EFNEW | EFFUNC);
@@ -546,14 +544,14 @@ extend(f, n)
if ((funct = name_function(xname)) != NULL) {
#ifndef NO_MACRO
if (macrodef) {
- LINE *lp = maclcur;
+ LINE *lp = maclcur;
macro[macrocount - 1].m_funct = funct;
maclcur = lp->l_bp;
maclcur->l_fp = lp->l_fp;
- free((char *) lp);
+ free((char *)lp);
}
-#endif
- return (*funct) (f, n);
+#endif /* !NO_MACRO */
+ return (*funct)(f, n);
}
ewprintf("[No match]");
return FALSE;
@@ -581,10 +579,10 @@ extend(f, n)
/* ARGSUSED */
int
evalexpr(f, n)
- int f, n;
+ int f, n;
{
- int s;
- char exbuf[128];
+ int s;
+ char exbuf[128];
if ((s = ereply("Eval: ", exbuf, 128)) != TRUE)
return s;
@@ -592,24 +590,26 @@ evalexpr(f, n)
}
/*
- * evalbuffer - evaluate the current buffer as line commands. Useful
- * for testing startup files.
+ * evalbuffer - evaluate the current buffer as line commands. Useful for
+ * testing startup files.
*/
/* ARGSUSED */
int
evalbuffer(f, n)
- int f, n;
+ int f, n;
{
- LINE *lp;
- BUFFER *bp = curbp;
- int s;
- static char excbuf[128];
+ LINE *lp;
+ BUFFER *bp = curbp;
+ int s;
+ static char excbuf[128];
for (lp = lforw(bp->b_linep); lp != bp->b_linep; lp = lforw(lp)) {
if (llength(lp) >= 128)
return FALSE;
- (VOID) strncpy(excbuf, ltext(lp), llength(lp));
- excbuf[llength(lp)] = '\0'; /* make sure it's terminated */
+ (VOID)strncpy(excbuf, ltext(lp), llength(lp));
+
+ /* make sure it's terminated */
+ excbuf[llength(lp)] = '\0';
if ((s = excline(excbuf)) != TRUE)
return s;
}
@@ -623,10 +623,10 @@ evalbuffer(f, n)
/* ARGSUSED */
int
evalfile(f, n)
- int f, n;
+ int f, n;
{
- int s;
- char fname[NFILEN];
+ int s;
+ char fname[NFILEN];
if ((s = ereply("Load file: ", fname, NFILEN)) != TRUE)
return s;
@@ -638,17 +638,19 @@ evalfile(f, n)
*/
int
load(fname)
- char *fname;
+ char *fname;
{
- int s = TRUE;
- int nbytes;
- char excbuf[128];
+ int s = TRUE;
+ int nbytes;
+ char excbuf[128];
if ((fname = adjustname(fname)) == NULL)
- return FALSE; /* just to be careful */
+ /* just to be careful */
+ return FALSE;
- if (ffropen(fname, (BUFFER *) NULL) != FIOSUC)
+ if (ffropen(fname, (BUFFER *)NULL) != FIOSUC)
return FALSE;
+
while ((s = ffgetline(excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) {
excbuf[nbytes] = '\0';
if (excline(excbuf) != TRUE) {
@@ -657,7 +659,7 @@ load(fname)
break;
}
}
- (VOID) ffclose((BUFFER *) NULL);
+ (VOID)ffclose((BUFFER *)NULL);
excbuf[nbytes] = '\0';
if (s != FIOEOF || (nbytes && excline(excbuf) != TRUE))
return FALSE;
@@ -665,33 +667,33 @@ load(fname)
}
/*
- * excline - run a line from a load file or eval-expression.
- * if FKEYS is defined, duplicate functionallity of dobind so function
- * key values don't have to fit in type char.
+ * excline - run a line from a load file or eval-expression. if FKEYS is
+ * defined, duplicate functionallity of dobind so function key values don't
+ * have to fit in type char.
*/
int
excline(line)
- char *line;
+ char *line;
{
- char *funcp, *argp = NULL;
- int c;
- int status;
- int f, n;
- LINE *lp, *np;
- PF fp;
+ PF fp;
+ LINE *lp, *np;
+ int status, c, f, n;
+ char *funcp;
+ char *argp = NULL;
#ifdef FKEYS
- int bind;
- KEYMAP *curmap;
- MAPS *mp;
-#define BINDARG 0 /* this arg is key to bind (local/global set
- * key) */
-#define BINDNO 1 /* not binding or non-quoted BINDARG */
-#define BINDNEXT 2 /* next arg " (define-key) */
-#define BINDDO 3 /* already found key to bind */
-#define BINDEXT 1 /* space for trailing \0 */
-#else
-#define BINDEXT 0
-#endif
+ int bind;
+ KEYMAP *curmap;
+ MAPS *mp;
+#define BINDARG 0 /* this arg is key to bind (local/global set key) */
+#define BINDNO 1 /* not binding or non-quoted BINDARG */
+#define BINDNEXT 2 /* next arg " (define-key) */
+#define BINDDO 3 /* already found key to bind */
+#define BINDEXT 1 /* space for trailing \0 */
+#else /* FKEYS */
+#define BINDEXT 0
+#endif /* FKEYS */
+
+ lp = NULL;
if (macrodef || inmacro) {
ewprintf("Not now!");
@@ -730,8 +732,8 @@ excline(line)
bind = BINDNEXT;
else
bind = BINDNO;
-#endif
- /* Pack away all the args now... */
+#endif /* FKEYS */
+ /* Pack away all the args now... */
if ((np = lalloc(0)) == FALSE)
return FALSE;
np->l_fp = np->l_bp = maclcur = np;
@@ -747,18 +749,20 @@ excline(line)
status = FALSE;
goto cleanup;
}
- bcopy(argp, ltext(lp), (int) (line - argp));
+ bcopy(argp, ltext(lp), (int)(line - argp));
#ifdef FKEYS
- lp->l_used--; /* don't count BINDEXT! */
+ /* don't count BINDEXT */
+ lp->l_used--;
if (bind == BINDARG)
bind = BINDNO;
-#endif
- } else { /* Quoted strings special */
+#endif /* FKEYS */
+ } else {
+ /* quoted strings are special */
++argp;
#ifdef FKEYS
if (bind != BINDARG) {
-#endif
- lp = lalloc((int) (line - argp) + BINDEXT);
+#endif /* FKEYS */
+ lp = lalloc((int)(line - argp) + BINDEXT);
if (lp == NULL) {
status = FALSE;
goto cleanup;
@@ -768,7 +772,7 @@ excline(line)
} else {
key.k_count = 0;
}
-#endif
+#endif /* FKEYS */
while (*argp != '"' && *argp != '\0') {
if (*argp != '\\')
c = *argp++;
@@ -808,7 +812,8 @@ excline(line)
case '6':
case '7':
c = *argp - '0';
- if (argp[1] <= '7' && argp[1] >= '0') {
+ if (argp[1] <= '7' &&
+ argp[1] >= '0') {
c <<= 3;
c += *++argp - '0';
if (argp[1] <= '7' &&
@@ -829,7 +834,7 @@ excline(line)
}
c += KFIRST;
break;
-#endif
+#endif /* FKEYS */
default:
c = CHARMASK(*argp);
break;
@@ -840,7 +845,7 @@ excline(line)
if (bind == BINDARG)
key.k_chars[key.k_count++] = c;
else
-#endif
+#endif /* FKEYS */
lp->l_text[lp->l_used++] = c;
}
if (*line)
@@ -856,22 +861,22 @@ excline(line)
if ((mp = name_mode(lp->l_text)) == NULL) {
ewprintf("No such mode: %s", lp->l_text);
status = FALSE;
- free((char *) lp);
+ free((char *)lp);
goto cleanup;
}
curmap = mp->p_map;
- free((char *) lp);
+ free((char *)lp);
bind = BINDARG;
break;
default:
-#endif
+#endif /* FKEYS */
lp->l_fp = np->l_fp;
lp->l_bp = np;
np->l_fp = lp;
np = lp;
#ifdef FKEYS
}
-#endif
+#endif /* FKEYS */
}
#ifdef FKEYS
switch (bind) {
@@ -885,26 +890,26 @@ excline(line)
status = bindkey(&curmap, lp->l_text, key.k_chars,
key.k_count);
} else
- status = bindkey(&curmap, (char *) NULL, key.k_chars,
+ status = bindkey(&curmap, (char *)NULL, key.k_chars,
key.k_count);
break;
case BINDNO:
-#endif
+#endif /* FKEYS */
inmacro = TRUE;
maclcur = maclcur->l_fp;
- status = (*fp) (f, n);
+ status = (*fp)(f, n);
inmacro = FALSE;
#ifdef FKEYS
}
-#endif
+#endif /* FKEYS */
cleanup:
lp = maclcur->l_fp;
while (lp != maclcur) {
np = lp->l_fp;
- free((char *) lp);
+ free((char *)lp);
lp = np;
}
- free((char *) lp);
+ free((char *)lp);
return status;
}
@@ -913,9 +918,8 @@ cleanup:
*/
static char *
skipwhite(s)
- char *s;
+ char *s;
{
-
while (*s == ' ' || *s == '\t' || *s == ')' || *s == '(')
s++;
if (*s == ';')
@@ -927,18 +931,20 @@ static char *
parsetoken(s)
char *s;
{
-
if (*s != '"') {
while (*s && *s != ' ' && *s != '\t' && *s != ')' && *s != '(')
s++;
if (*s == ';')
*s = '\0';
} else
- do { /* Strings get special treatment */
- /* Beware: You can \ out the end of the string! */
+ do {
+ /*
+ * Strings get special treatment.
+ * Beware: You can \ out the end of the string!
+ */
if (*s == '\\')
++s;
} while (*++s != '"' && *s != '\0');
return s;
}
-#endif
+#endif /* !NO_STARTUP */
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 966982f295f..b1a023b5a68 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,46 +1,45 @@
/*
- * File commands.
+ * File commands.
*/
-#include "def.h"
-static char *itos __P((char *, unsigned int));
+#include "def.h"
+
+static char *itos __P((char *, unsigned int));
/*
- * insert a file into the current buffer. Real easy - just call the
+ * Insert a file into the current buffer. Real easy - just call the
* insertfile routine with the file name.
*/
/* ARGSUSED */
int
fileinsert(f, n)
- int f, n;
+ int f, n;
{
- int s;
- char fname[NFILEN];
+ int s;
+ char fname[NFILEN];
s = eread("Insert file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);
if (s != TRUE)
return (s);
- return insertfile(adjustname(fname), (char *) NULL, FALSE);
+ return insertfile(adjustname(fname), (char *)NULL, FALSE);
/* don't set buffer name */
}
/*
- * Select a file for editing.
- * Look around to see if you can find the
- * fine in another buffer; if you can find it
- * just switch to the buffer. If you cannot find
- * the file, create a new buffer, read in the
- * text, and switch to the new buffer.
+ * Select a file for editing. Look around to see if you can find the file
+ * in another buffer; if you can find it, just switch to the buffer. If
+ * you cannot find the file, create a new buffer, read in the text, and
+ * switch to the new buffer.
*/
/* ARGSUSED */
int
filevisit(f, n)
- int f, n;
+ int f, n;
{
- BUFFER *bp;
- int s;
- char fname[NFILEN];
- char *adjf;
+ BUFFER *bp;
+ int s;
+ char fname[NFILEN];
+ char *adjf;
s = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);
if (s != TRUE)
@@ -52,24 +51,24 @@ filevisit(f, n)
if (showbuffer(bp, curwp, WFHARD) != TRUE)
return FALSE;
if (bp->b_fname[0] == 0)
- return readin(adjf); /* Read it in. */
+ return readin(adjf);
return TRUE;
}
/*
- * Pop to a file in the other window. Same as last function, just
+ * Pop to a file in the other window. Same as the last function, but uses
* popbuf instead of showbuffer.
*/
/* ARGSUSED */
int
poptofile(f, n)
- int f, n;
+ int f, n;
{
- BUFFER *bp;
- MGWIN *wp;
- int s;
- char fname[NFILEN];
- char *adjf;
+ BUFFER *bp;
+ MGWIN *wp;
+ int s;
+ char fname[NFILEN];
+ char *adjf;
if ((s = eread("Find file in other window: ", fname, NFILEN,
EFNEW | EFCR | EFFILE)) != TRUE)
@@ -82,7 +81,7 @@ poptofile(f, n)
curbp = bp;
curwp = wp;
if (bp->b_fname[0] == 0)
- return readin(adjf); /* Read it in. */
+ return readin(adjf);
return TRUE;
}
@@ -92,21 +91,23 @@ poptofile(f, n)
*/
BUFFER *
findbuffer(fname)
- char *fname;
+ char *fname;
{
- BUFFER *bp;
- char bname[NBUFN], *cp;
- unsigned int count = 1;
+ BUFFER *bp;
+ char bname[NBUFN], *cp;
+ unsigned int count = 1;
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
if (fncmp(bp->b_fname, fname) == 0)
return bp;
}
- makename(bname, fname); /* New buffer name. */
+ /* new buffer name */
+ makename(bname, fname);
cp = bname + strlen(bname);
while (bfind(bname, FALSE) != NULL) {
- *cp = '<'; /* add "<count>" to then name */
- (VOID) strcpy(itos(cp, ++count) + 1, ">");
+ /* add "<count>" to the name */
+ *cp = '<';
+ (VOID)strcpy(itos(cp, ++count) + 1, ">");
}
return bfind(bname, TRUE);
}
@@ -117,10 +118,9 @@ findbuffer(fname)
*/
static char *
itos(bufp, num)
- char *bufp;
- unsigned int num;
+ char *bufp;
+ unsigned int num;
{
-
if (num >= 10) {
bufp = itos(bufp, num / 10);
num %= 10;
@@ -130,22 +130,25 @@ itos(bufp, num)
}
/*
- * Read the file "fname" into the current buffer.
- * Make all of the text in the buffer go away, after checking
- * for unsaved changes. This is called by the "read" command, the
- * "visit" command, and the mainline (for "uemacs file").
+ * Read the file "fname" into the current buffer. Make all of the text
+ * in the buffer go away, after checking for unsaved changes. This is
+ * called by the "read" command, the "visit" command, and the mainline
+ * (for "uemacs file").
*/
int
readin(fname)
- char *fname;
+ char *fname;
{
- int status;
- MGWIN *wp;
+ MGWIN *wp;
+ int status;
- if (bclear(curbp) != TRUE) /* Might be old. */
+ /* might be old */
+ if (bclear(curbp) != TRUE)
return TRUE;
status = insertfile(fname, fname, TRUE);
- curbp->b_flag &= ~BFCHG;/* No change. */
+
+ /* no change */
+ curbp->b_flag &= ~BFCHG;
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_bufp == curbp) {
wp->w_dotp = wp->w_linep = lforw(curbp->b_linep);
@@ -156,6 +159,7 @@ readin(fname)
}
return status;
}
+
/*
* NB, getting file attributes is done here under control of a flag
* rather than in readin, which would be cleaner. I was concerned
@@ -164,44 +168,46 @@ readin(fname)
*/
/*
- * insert a file in the current buffer, after dot. Set mark
- * at the end of the text inserted, point at the beginning.
- * Return a standard status. Print a summary (lines read,
- * error message) out as well. If the
- * BACKUP conditional is set, then this routine also does the read
- * end of backup processing. The BFBAK flag, if set in a buffer,
- * says that a backup should be taken. It is set when a file is
- * read in, but not on a new file (you don't need to make a backup
- * copy of nothing).
+ * Insert a file in the current buffer, after dot. Set mark at the end of
+ * the text inserted; point at the beginning. Return a standard status.
+ * Print a summary (lines read, error message) out as well. If the BACKUP
+ * conditional is set, then this routine also does the read end of backup
+ * processing. The BFBAK flag, if set in a buffer, says that a backup
+ * should be taken. It is set when a file is read in, but not on a new
+ * file. (You don't need to make a backup copy of nothing.)
*/
static char *line = NULL;
static int linesize = 0;
int
insertfile(fname, newname, needinfo)
- char *fname, *newname;
- int needinfo;
+ char *fname, *newname;
+ int needinfo;
{
- LINE *lp1;
- LINE *lp2;
- MGWIN *wp;
- int nbytes;
- LINE *olp; /* Line we started at */
- int opos; /* and offset into it */
- int s, nline;
- BUFFER *bp;
+ BUFFER *bp;
+ LINE *lp1, *lp2;
+ LINE *olp; /* line we started at */
+ MGWIN *wp;
+ int nbytes, s, nline;
+ int opos; /* and offset into it */
+
+ lp1 = NULL;
if (line == NULL) {
line = malloc(NLINE);
linesize = NLINE;
}
- bp = curbp; /* Cheap. */
- if (newname != (char *) NULL)
- (VOID) strcpy(bp->b_fname, newname);
- /* Hard file open. */
+
+ /* cheap */
+ bp = curbp;
+ if (newname != (char *)NULL)
+ (VOID)strcpy(bp->b_fname, newname);
+
+ /* hard file open */
if ((s = ffropen(fname, needinfo ? bp : (BUFFER *) NULL)) == FIOERR)
goto out;
- if (s == FIOFNF) { /* File not found. */
+ if (s == FIOFNF) {
+ /* file not found */
if (newname != NULL)
ewprintf("(New file)");
else
@@ -209,25 +215,30 @@ insertfile(fname, newname, needinfo)
goto out;
}
opos = curwp->w_doto;
- /* Open a new line, at point, and start inserting after it */
- (VOID) lnewline();
+
+ /* open a new line, at point, and start inserting after it */
+ (VOID)lnewline();
olp = lback(curwp->w_dotp);
if (olp == curbp->b_linep) {
/* if at end of buffer, create a line to insert before */
- (VOID) lnewline();
+ (VOID)lnewline();
curwp->w_dotp = lback(curwp->w_dotp);
}
- nline = 0; /* Don't count fake line at end */
+
+ /* don't count fake lines at the end */
+ nline = 0;
while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) {
doneread:
switch (s) {
case FIOSUC:
++nline;
/* and continue */
- case FIOEOF: /* the last line of the file */
+ case FIOEOF:
+ /* the last line of the file */
if ((lp1 = lalloc(nbytes)) == NULL) {
- s = FIOERR; /* Keep message on the */
- goto endoffile; /* display. */
+ /* keep message on the display */
+ s = FIOERR;
+ goto endoffile;
}
bcopy(line, &ltext(lp1)[0], nbytes);
lp2 = lback(curwp->w_dotp);
@@ -238,22 +249,24 @@ doneread:
if (s == FIOEOF)
goto endoffile;
break;
- case FIOLONG:{ /* a line too long to fit in our buffer */
+ case FIOLONG:{
+ /* a line too long to fit in our buffer */
char *cp;
int newsize;
newsize = linesize * 2;
if (newsize < 0 ||
- (cp = malloc((unsigned) newsize)) == NULL) {
+ (cp = malloc((unsigned)newsize)) == NULL) {
ewprintf("Could not allocate %d bytes",
- newsize);
- s = FIOERR;
- goto endoffile;
+ newsize);
+ s = FIOERR;
+ goto endoffile;
}
bcopy(line, cp, linesize);
free(line);
line = cp;
- s = ffgetline(line + linesize, linesize, &nbytes);
+ s = ffgetline(line + linesize, linesize,
+ &nbytes);
nbytes += linesize;
linesize = newsize;
if (s == FIOERR)
@@ -267,17 +280,19 @@ doneread:
}
}
endoffile:
- (VOID) ffclose((BUFFER *) NULL); /* Ignore errors. */
- if (s == FIOEOF) { /* Don't zap an error. */
+ /* ignore errors */
+ (VOID)ffclose((BUFFER *)NULL);
+ /* don't zap an error */
+ if (s == FIOEOF) {
if (nline == 1)
ewprintf("(Read 1 line)");
else
ewprintf("(Read %d lines)", nline);
}
- /* Set mark at the end of the text */
+ /* set mark at the end of the text */
curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp);
curwp->w_marko = llength(curwp->w_markp);
- (VOID) ldelnewline();
+ (VOID)ldelnewline();
curwp->w_dotp = olp;
curwp->w_doto = opos;
if (olp == curbp->b_linep)
@@ -287,9 +302,9 @@ endoffile:
bp->b_flag |= BFCHG | BFBAK; /* Need a backup. */
else
bp->b_flag |= BFCHG;
-#else
+#else /* !NO_BACKUP */
bp->b_flag |= BFCHG;
-#endif
+#endif /* !NO_BACKUP */
/*
* if the insert was at the end of buffer, set lp1 to the end of
* buffer line, and lp2 to the beginning of the newly inserted text.
@@ -301,7 +316,8 @@ endoffile:
if (curwp->w_markp == lp1) {
lp2 = curwp->w_dotp;
} else {
- (VOID) ldelnewline(); /* delete extranious newline */
+ /* delete extraneous newline */
+ (VOID)ldelnewline();
out: lp2 = NULL;
}
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
@@ -317,12 +333,12 @@ out: lp2 = NULL;
}
}
}
- return s != FIOERR; /* False if error. */
+ /* return false if error */
+ return s != FIOERR;
}
/*
- * Take a file name, and from it
- * fabricate a buffer name. This routine knows
+ * Fabriacte a buffer name from a given filename. This routing knows
* about the syntax of file names on the target system.
* BDC1 left scan delimiter.
* BDC2 optional second left scan delimiter.
@@ -330,51 +346,49 @@ out: lp2 = NULL;
*/
VOID
makename(bname, fname)
- char *bname;
- char *fname;
+ char *bname, *fname;
{
- char *cp1;
- char *cp2;
+ char *cp1, *cp2;
cp1 = &fname[0];
while (*cp1 != 0)
++cp1;
- --cp1; /* insure at least 1 character ! */
-#ifdef BDC2
+
+ /* insure at least 1 character */
+ --cp1;
+#ifdef BDC2
while (cp1 != &fname[0] && cp1[-1] != BDC1 && cp1[-1] != BDC2)
--cp1;
-#else
+#else /* BDC2 */
while (cp1 != &fname[0] && cp1[-1] != BDC1)
--cp1;
-#endif
+#endif /* BDC2 */
cp2 = &bname[0];
-#ifdef BDC3
+
+#ifdef BDC3
while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != BDC3)
*cp2++ = *cp1++;
-#else
+#else /* BDC3 */
while (cp2 != &bname[NBUFN - 1] && *cp1 != 0)
*cp2++ = *cp1++;
-#endif
+#endif /* BDC3 */
*cp2 = 0;
}
/*
- * Ask for a file name, and write the
- * contents of the current buffer to that file.
- * Update the remembered file name and clear the
- * buffer changed flag. This handling of file names
- * is different from the earlier versions, and
- * is more compatable with Gosling EMACS than
- * with ITS EMACS.
+ * Ask for a file name and write the contents of the current buffer to that
+ * file. Update the remembered file name and clear the buffer changed flag.
+ * This handling of file names is different from the earlier versions and
+ * is more compatable with Gosling EMACS than with ITS EMACS.
*/
/* ARGSUSED */
int
filewrite(f, n)
- int f, n;
+ int f, n;
{
- int s;
- char fname[NFILEN];
- char *adjfname;
+ int s;
+ char fname[NFILEN];
+ char *adjfname;
if ((s = eread("Write file: ", fname, NFILEN,
EFNEW | EFCR | EFFILE)) != TRUE)
@@ -383,74 +397,79 @@ filewrite(f, n)
/* old attributes are no longer current */
bzero(&curbp->b_fi, sizeof(curbp->b_fi));
if ((s = writeout(curbp, adjfname)) == TRUE) {
- (VOID) strcpy(curbp->b_fname, adjfname);
+ (VOID)strcpy(curbp->b_fname, adjfname);
#ifndef NO_BACKUP
curbp->b_flag &= ~(BFBAK | BFCHG);
-#else
+#else /* !NO_BACKUP */
curbp->b_flag &= ~BFCHG;
-#endif
+#endif /* !NO_BACKUP */
upmodes(curbp);
}
return s;
}
/*
- * Save the contents of the current buffer back into
- * its associated file.
+ * Save the contents of the current buffer back into its associated file.
*/
#ifndef NO_BACKUP
#ifndef MAKEBACKUP
#define MAKEBACKUP TRUE
-#endif
+#endif /* !MAKEBACKUP */
static int makebackup = MAKEBACKUP;
-#endif
+#endif /* !NO_BACKUP */
/* ARGSUSED */
int
filesave(f, n)
+ int f, n;
{
return buffsave(curbp);
}
/*
- * Save the contents of the buffer argument into its associated file.
- * Do nothing if there have been no changes
- * (is this a bug, or a feature). Error if there is no remembered
- * file name. If this is the first write since the read or visit,
- * then a backup copy of the file is made.
- * Allow user to select whether or not to make backup files
- * by looking at the value of makebackup.
+ * Save the contents of the buffer argument into its associated file. Do
+ * nothing if there have been no changes (is this a bug, or a feature?).
+ * Error if there is no remembered file name. If this is the first write
+ * since the read or visit, then a backup copy of the file is made.
+ * Allow user to select whether or not to make backup files by looking at
+ * the value of makebackup.
*/
int
buffsave(bp)
BUFFER *bp;
{
- int s;
+ int s;
- if ((bp->b_flag & BFCHG) == 0) { /* Return, no changes. */
+ /* return, no changes */
+ if ((bp->b_flag & BFCHG) == 0) {
ewprintf("(No changes need to be saved)");
return TRUE;
}
- if (bp->b_fname[0] == '\0') { /* Must have a name. */
+
+ /* must have a name */
+ if (bp->b_fname[0] == '\0') {
ewprintf("No file name");
return (FALSE);
}
+
#ifndef NO_BACKUP
if (makebackup && (bp->b_flag & BFBAK)) {
s = fbackupfile(bp->b_fname);
- if (s == ABORT) /* Hard error. */
+ /* hard error */
+ if (s == ABORT)
return FALSE;
- if (s == FALSE /* Softer error. */
- && (s = eyesno("Backup error, save anyway")) != TRUE)
+ /* softer error */
+ if (s == FALSE &&
+ (s = eyesno("Backup error, save anyway")) != TRUE)
return s;
}
-#endif
+#endif /* !NO_BACKUP */
if ((s = writeout(bp, bp->b_fname)) == TRUE) {
#ifndef NO_BACKUP
bp->b_flag &= ~(BFCHG | BFBAK);
-#else
+#else /* !NO_BACKUP */
bp->b_flag &= ~BFCHG;
-#endif
+#endif /* !NO_BACKUP */
upmodes(bp);
}
return s;
@@ -467,8 +486,8 @@ buffsave(bp)
/* ARGSUSED */
int
makebkfile(f, n)
+ int f, n;
{
-
if (f & FFARG)
makebackup = n > 0;
else
@@ -476,7 +495,7 @@ makebkfile(f, n)
ewprintf("Backup files %sabled", makebackup ? "en" : "dis");
return TRUE;
}
-#endif
+#endif /* !NO_BACKUP */
/*
* NB: bp is passed to both ffwopen and ffclose because some
@@ -488,40 +507,41 @@ makebkfile(f, n)
*/
/*
- * This function performs the details of file
- * writing; writing the file in buffer bp to
- * file fn. Uses the file management routines
- * in the "fileio.c" package. Most of the grief
- * is checking of some sort.
+ * This function performs the details of file writing; writing the file
+ * in buffer bp to file fn. Uses the file management routines in the
+ * "fileio.c" package. Most of the grief is checking of some sort.
*/
int
writeout(bp, fn)
BUFFER *bp;
char *fn;
{
- int s;
+ int s;
- if ((s = ffwopen(fn, bp)) != FIOSUC) /* Open writes message. */
+ /* open writes message */
+ if ((s = ffwopen(fn, bp)) != FIOSUC)
return (FALSE);
s = ffputbuf(bp);
- if (s == FIOSUC) { /* No write error. */
+ if (s == FIOSUC) {
+ /* no write error */
s = ffclose(bp);
if (s == FIOSUC)
ewprintf("Wrote %s", fn);
- } else /* Ignore close error */
- (VOID) ffclose(bp); /* if a write error. */
+ } else
+ /* ignore close error if it is a write error */
+ (VOID)ffclose(bp);
return s == FIOSUC;
}
/*
- * Tag all windows for bp (all windows if bp NULL) as needing their
+ * Tag all windows for bp (all windows if bp == NULL) as needing their
* mode line updated.
*/
VOID
upmodes(bp)
BUFFER *bp;
{
- MGWIN *wp;
+ MGWIN *wp;
for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
if (bp == NULL || curwp->w_bufp == bp)
diff --git a/usr.bin/mg/help.c b/usr.bin/mg/help.c
index 4f70c009d86..ae6dd3b3af1 100644
--- a/usr.bin/mg/help.c
+++ b/usr.bin/mg/help.c
@@ -1,4 +1,6 @@
-/* Help functions for Mg 2 */
+/*
+ * Help functions for Mg 2
+ */
#include "def.h"
@@ -7,11 +9,16 @@
#include "key.h"
#ifndef NO_MACRO
#include "macro.h"
-#endif
+#endif /* !NO_MACRO */
-static int showall __P((char *ind, KEYMAP *map));
-static VOID findbind __P((PF, char *, KEYMAP *));
-static VOID bindfound __P((void));
+static int showall __P((char *ind, KEYMAP *map));
+static VOID findbind __P((PF, char *, KEYMAP *));
+static VOID bindfound __P((void));
+
+static BUFFER *bp;
+static char buf[80]; /* used by showall and findbind */
+static char buf2[128];
+static char *buf2p;
/*
* Read a key from the keyboard, and look it up in the keymap.
@@ -20,21 +27,19 @@ static VOID bindfound __P((void));
/* ARGSUSED */
int
desckey(f, n)
- int f, n;
+ int f, n;
{
- KEYMAP *curmap;
- PF funct;
- char *pep;
- char prompt[80];
- int c;
- int m;
- int i;
+ KEYMAP *curmap;
+ PF funct;
+ int c, m, i;
+ char *pep;
+ char prompt[80];
#ifndef NO_MACRO
if (inmacro)
return TRUE; /* ignore inside keyboard macro */
-#endif
- (VOID) strcpy(prompt, "Describe key briefly: ");
+#endif /* !NO_MACRO */
+ (VOID)strcpy(prompt, "Describe key briefly: ");
pep = prompt + strlen(prompt);
key.k_count = 0;
m = curbp->b_nmodes;
@@ -97,22 +102,21 @@ found:
* keys and their current bindings, and stores the table in the
* *help* pop-up buffer. This lets Mg produce it's own wall chart.
*/
-static BUFFER *bp;
-static char buf[80]; /* used by showall and findbind */
-
/* ARGSUSED */
int
wallchart(f, n)
+ int f, n;
{
- int m;
- static char locbind[80] = "Local keybindings for mode ";
+ int m;
+ static char locbind[80] = "Local keybindings for mode ";
bp = bfind("*help*", TRUE);
if (bclear(bp) != TRUE)
- return FALSE; /* Clear it out. */
+ /* clear it out */
+ return FALSE;
for (m = curbp->b_nmodes; m > 0; m--) {
- (VOID) strcpy(&locbind[27], curbp->b_modes[m]->p_name);
- (VOID) strcat(&locbind[27], ":");
+ (VOID)strcpy(&locbind[27], curbp->b_modes[m]->p_name);
+ (VOID)strcat(&locbind[27], ":");
if ((addline(bp, locbind) == FALSE) ||
(showall(buf, curbp->b_modes[m]->p_map) == FALSE) ||
(addline(bp, "") == FALSE))
@@ -126,31 +130,29 @@ wallchart(f, n)
static int
showall(ind, map)
- char *ind;
- KEYMAP *map;
+ char *ind;
+ KEYMAP *map;
{
- MAP_ELEMENT *ele;
- int i;
- PF functp;
- char *cp;
- char *cp2;
- int last;
+ MAP_ELEMENT *ele;
+ PF functp;
+ int i, last;
+ char *cp, *cp2;
if (addline(bp, "") == FALSE)
return FALSE;
last = -1;
- for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];
- ele++) {
+ for (ele = &map->map_element[0];
+ ele < &map->map_element[map->map_num]; ele++) {
if (map->map_default != rescan && ++last < ele->k_base) {
cp = keyname(ind, last);
if (last < ele->k_base - 1) {
- (VOID) strcpy(cp, " .. ");
+ (VOID)strcpy(cp, " .. ");
cp = keyname(cp + 4, ele->k_base - 1);
}
do {
*cp++ = ' ';
} while (cp < &buf[16]);
- (VOID) strcpy(cp, function_name(map->map_default));
+ (VOID)strcpy(cp, function_name(map->map_default));
if (addline(bp, buf) == FALSE)
return FALSE;
}
@@ -167,19 +169,20 @@ showall(ind, map)
do {
*cp++ = ' ';
} while (cp < &buf[16]);
- (VOID) strcpy(cp, cp2);
+ (VOID)strcpy(cp, cp2);
if (addline(bp, buf) == FALSE)
return FALSE;
}
}
}
}
- for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];
- ele++) {
+ for (ele = &map->map_element[0];
+ ele < &map->map_element[map->map_num]; ele++) {
if (ele->k_prefmap != NULL) {
for (i = ele->k_base;
ele->k_funcp[i - ele->k_base] != prefix; i++) {
- if (i >= ele->k_num) /* damaged map */
+ if (i >= ele->k_num)
+ /* damaged map */
return FALSE;
}
cp = keyname(ind, i);
@@ -193,10 +196,10 @@ showall(ind, map)
int
help_help(f, n)
- int f, n;
+ int f, n;
{
- KEYMAP *kp;
- PF funct;
+ KEYMAP *kp;
+ PF funct;
if ((kp = name_map("help")) == NULL)
return FALSE;
@@ -207,22 +210,19 @@ help_help(f, n)
#ifndef NO_MACRO
if (macrodef && macrocount < MAXMACRO)
macro[macrocount - 1].m_funct = funct;
-#endif
- return (*funct) (f, n);
+#endif /* !NO_MACRO */
+ return (*funct)(f, n);
}
-static char buf2[128];
-static char *buf2p;
-
/* ARGSUSED */
int
apropos_command(f, n)
- int f, n;
+ int f, n;
{
- char *cp1, *cp2;
- char string[32];
- FUNCTNAMES *fnp;
- BUFFER *bp;
+ BUFFER *bp;
+ FUNCTNAMES *fnp;
+ char *cp1, *cp2;
+ char string[32];
if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT)
return ABORT;
@@ -236,7 +236,7 @@ apropos_command(f, n)
while (*cp2 && *cp1 == *cp2)
cp1++, cp2++;
if (!*cp2) {
- (VOID) strcpy(buf2, fnp->n_name);
+ (VOID)strcpy(buf2, fnp->n_name);
buf2p = &buf2[strlen(buf2)];
findbind(fnp->n_funct, buf, map_table[0].p_map);
if (addline(bp, buf2) == FALSE)
@@ -251,23 +251,22 @@ apropos_command(f, n)
static VOID
findbind(funct, ind, map)
- PF funct;
- char *ind;
- KEYMAP *map;
+ KEYMAP *map;
+ PF funct;
+ char *ind;
{
- MAP_ELEMENT *ele;
- int i;
- char *cp;
- int last;
+ MAP_ELEMENT *ele;
+ int i, last;
+ char *cp;
last = -1;
- for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];
- ele++) {
+ for (ele = &map->map_element[0];
+ ele < &map->map_element[map->map_num]; ele++) {
if (map->map_default == funct && ++last < ele->k_base) {
cp = keyname(ind, last);
if (last < ele->k_base - 1) {
- (VOID) strcpy(cp, " .. ");
- (VOID) keyname(cp + 4, ele->k_base - 1);
+ (VOID)strcpy(cp, " .. ");
+ (VOID)keyname(cp + 4, ele->k_base - 1);
}
bindfound();
}
@@ -280,18 +279,19 @@ findbind(funct, ind, map)
strncmp(cp, buf2, strlen(cp)) != 0)
continue;
}
- (VOID) keyname(ind, i);
+ (VOID)keyname(ind, i);
bindfound();
}
}
}
- for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];
- ele++) {
+ for (ele = &map->map_element[0];
+ ele < &map->map_element[map->map_num]; ele++) {
if (ele->k_prefmap != NULL) {
for (i = ele->k_base;
ele->k_funcp[i - ele->k_base] != prefix; i++) {
if (i >= ele->k_num)
- return; /* damaged */
+ /* damaged */
+ return;
}
cp = keyname(ind, i);
*cp++ = ' ';
@@ -303,7 +303,6 @@ findbind(funct, ind, map)
static VOID
bindfound()
{
-
if (buf2p < &buf2[32]) {
do {
*buf2p++ = ' ';
@@ -312,7 +311,7 @@ bindfound()
*buf2p++ = ',';
*buf2p++ = ' ';
}
- (VOID) strcpy(buf2p, buf);
+ (VOID)strcpy(buf2p, buf);
buf2p += strlen(buf);
}
-#endif
+#endif /* !NO_HELP */
diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c
index 72be336b622..c61e575742f 100644
--- a/usr.bin/mg/kbd.c
+++ b/usr.bin/mg/kbd.c
@@ -1,22 +1,32 @@
/*
- * Terminal independent keyboard handling.
+ * Terminal independent keyboard handling.
*/
-#include "def.h"
-#include "kbd.h"
#define EXTERN
-#include "key.h"
+
+#include "def.h"
+#include "kbd.h"
+#include "key.h"
#ifndef NO_MACRO
#include "macro.h"
-#endif
+#endif /* !NO_MACRO */
-#ifdef DO_METAKEY
+#ifdef DO_METAKEY
#ifndef METABIT
#define METABIT 0x80
-#endif
+#endif /* !METABIT */
+
+#ifndef NO_DPROMPT
+#define PROMPTL 80
+char prompt[PROMPTL], *promptp;
+#endif /* !NO_DPROMPT */
-int use_metakey = TRUE;
+static int use_metakey = TRUE;
+static int pushed = FALSE;
+static int pushedc;
+
+MAP_ELEMENT *ele;
/*
* Toggle the value of use_metakey
@@ -25,7 +35,6 @@ int
do_meta(f, n)
int f, n;
{
-
if (f & FFARG)
use_metakey = n > 0;
else
@@ -33,10 +42,10 @@ do_meta(f, n)
ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis");
return TRUE;
}
-#endif
+#endif /* DO_METAKEY */
-#ifdef BSMAP
-static int bs_map = BSMAP;
+#ifdef BSMAP
+static int bs_map = BSMAP;
/*
* Toggle backspace mapping
*/
@@ -44,7 +53,6 @@ int
bsmap(f, n)
int f, n;
{
-
if (f & FFARG)
bs_map = n > 0;
else
@@ -52,73 +60,66 @@ bsmap(f, n)
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;
+#endif /* BSMAP */
VOID
ungetkey(c)
int c;
{
-
-#ifdef DO_METAKEY
+#ifdef DO_METAKEY
if (use_metakey && pushed && c == CCHR('['))
pushedc |= METABIT;
else
-#endif
+#endif /* DO_METAKEY */
pushedc = c;
pushed = TRUE;
}
int
getkey(flag)
- int flag;
+ int flag;
{
- int c;
+ int c;
#ifndef NO_DPROMPT
if (flag && !pushed) {
if (prompt[0] != '\0' && ttwait()) {
- ewprintf("%s", prompt); /* avoid problems with % */
- update(); /* put the cursor back */
+ /* avoid problems with % */
+ ewprintf("%s", prompt);
+ /* put the cursor back */
+ update();
epresf = KPROMPT;
}
if (promptp > prompt)
*(promptp - 1) = ' ';
}
-#endif
+#endif /* !NO_DPROMPT */
if (pushed) {
c = pushedc;
pushed = FALSE;
} else
c = getkbd();
-#ifdef BSMAP
+#ifdef BSMAP
if (bs_map)
if (c == CCHR('H'))
c = CCHR('?');
else if (c == CCHR('?'))
c = CCHR('H');
-#endif
-#ifdef DO_METAKEY
+#endif /* BSMAP */
+#ifdef DO_METAKEY
if (use_metakey && (c & METABIT)) {
pushedc = c & ~METABIT;
pushed = TRUE;
c = CCHR('[');
}
-#endif
+#endif /* DO_METAKEY */
#ifndef NO_DPROMPT
if (flag && promptp < &prompt[PROMPTL - 5]) {
promptp = keyname(promptp, c);
*promptp++ = '-';
*promptp = '\0';
}
-#endif
+#endif /* !NO_DPROMPT */
return c;
}
@@ -127,20 +128,19 @@ getkey(flag)
* 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)
KEYMAP *map;
int c;
{
- MAP_ELEMENT *elec = &map->map_element[0];
- MAP_ELEMENT *last = &map->map_element[map->map_num];
+ MAP_ELEMENT *elec = &map->map_element[0];
+ 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 */
+
+ /* used by prefix and binding code */
+ ele = elec;
if (elec >= last || c < elec->k_base)
return map->map_default;
return elec->k_funcp[c - elec->k_base];
@@ -149,12 +149,12 @@ doscan(map, c)
int
doin()
{
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
#ifndef NO_DPROMPT
*(promptp = prompt) = '\0';
-#endif
+#endif /* !NO_DPROMPT */
curmap = curbp->b_modes[curbp->b_nmodes]->p_map;
key.k_count = 0;
while ((funct = doscan(curmap, (key.k_chars[key.k_count++] =
@@ -163,26 +163,27 @@ doin()
#ifndef NO_MACRO
if (macrodef && macrocount < MAXMACRO)
macro[macrocount++].m_funct = funct;
-#endif
- return (*funct) (0, 1);
+#endif /* !NO_MACRO */
+ return (*funct)(0, 1);
}
int
rescan(f, n)
- int f, n;
+ int f, n;
{
- int c;
- KEYMAP *curmap;
- int i;
- PF fp;
- int mode = curbp->b_nmodes;
+ int c;
+ KEYMAP *curmap;
+ int i;
+ PF fp = NULL;
+ 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)
+ if ((fp = doscan(curmap, (key.k_chars[i])))
+ != prefix)
break;
curmap = ele->k_prefmap;
}
@@ -190,14 +191,15 @@ rescan(f, n)
if ((fp = doscan(curmap, c)) == prefix)
while ((fp = doscan(curmap,
key.k_chars[key.k_count++] =
- getkey(TRUE))) == prefix)
+ 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);
+ macro[macrocount - 1].m_funct
+ = fp;
+#endif /* !NO_MACRO */
+ return (*fp)(f, n);
}
}
}
@@ -211,8 +213,8 @@ rescan(f, n)
curmap = ele->k_prefmap;
}
if (fp == prefix) {
- while ((fp = doscan(curmap, key.k_chars[i++] = getkey(TRUE)))
- == prefix)
+ while ((fp = doscan(curmap, key.k_chars[i++] =
+ getkey(TRUE))) == prefix)
curmap = ele->k_prefmap;
key.k_count = i;
}
@@ -220,19 +222,20 @@ rescan(f, n)
#ifndef NO_MACRO
if (macrodef && macrocount <= MAXMACRO)
macro[macrocount - 1].m_funct = fp;
-#endif
- return (*fp) (f, n);
+#endif /* !NO_MACRO */
+ return (*fp)(f, n);
}
}
}
int
universal_argument(f, n)
- int f, n;
+ int f, n;
{
- int c, nn = 4;
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
+ int c;
+ int nn = 4;
if (f & FFUNIV)
nn *= n;
@@ -256,8 +259,8 @@ universal_argument(f, n)
macro[macrocount++].m_count = nn;
macro[macrocount++].m_funct = funct;
}
-#endif
- return (*funct) (FFUNIV, nn);
+#endif /* !NO_MACRO */
+ return (*funct)(FFUNIV, nn);
}
nn <<= 2;
}
@@ -266,11 +269,11 @@ universal_argument(f, n)
/* ARGSUSED */
int
digit_argument(f, n)
- int f, n;
+ int f, n;
{
- int nn, c;
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
+ int nn, c;
nn = key.k_chars[key.k_count - 1] - '0';
for (;;) {
@@ -296,17 +299,18 @@ digit_argument(f, n)
macro[macrocount++].m_count = nn;
macro[macrocount++].m_funct = funct;
}
-#endif
- return (*funct) (FFOTHARG, nn);
+#endif /* !NO_MACRO */
+ return (*funct)(FFOTHARG, nn);
}
int
negative_argument(f, n)
- int f, n;
+ int f, n;
{
- int nn = 0, c;
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
+ int c;
+ int nn = 0;
for (;;) {
c = getkey(TRUE);
@@ -335,8 +339,8 @@ negative_argument(f, n)
macro[macrocount++].m_count = nn;
macro[macrocount++].m_funct = funct;
}
-#endif
- return (*funct) (FFNEGARG, nn);
+#endif /* !NO_MACRO */
+ return (*funct)(FFNEGARG, nn);
}
/*
@@ -345,13 +349,13 @@ negative_argument(f, n)
*/
int
selfinsert(f, n)
- int f, n;
+ int f, n;
{
- int c;
- int count;
#ifndef NO_MACRO
- LINE *lp;
-#endif
+ LINE *lp;
+#endif /* !NO_MACRO */
+ int c;
+ int count;
if (n < 0)
return FALSE;
@@ -362,8 +366,9 @@ selfinsert(f, n)
if (macrodef && macrocount < MAXMACRO) {
if (f & FFARG)
macrocount -= 2;
- if (lastflag & CFINS) { /* last command was insert -- tack on
- * end */
+
+ /* last command was insert -- tack on the end */
+ if (lastflag & CFINS) {
macrocount--;
if (maclcur->l_size < maclcur->l_used + n) {
if ((lp = lallocx(maclcur->l_used + n)) == NULL)
@@ -371,10 +376,12 @@ selfinsert(f, n)
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++)
+ 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);
+ free((char *)maclcur);
maclcur = lp;
} else {
maclcur->l_used += n;
@@ -395,14 +402,16 @@ selfinsert(f, n)
}
thisflag |= CFINS;
}
-#endif
+#endif /* !NO_MACRO */
if (c == '\n') {
do {
count = lnewline();
} while (--n && count == TRUE);
return count;
}
- if (curbp->b_flag & BFOVERWRITE) { /* Overwrite mode */
+
+ /* overwrite mode */
+ if (curbp->b_flag & BFOVERWRITE) {
lchange(WFEDIT);
while (curwp->w_doto < llength(curwp->w_dotp) && n--)
lputc(curwp->w_dotp, curwp->w_doto++, c);
@@ -413,14 +422,13 @@ selfinsert(f, n)
}
/*
- * This could be implemented as a keymap with everthing defined
- * as self-insert.
+ * This could be implemented as a keymap with everthing defined as self-insert.
*/
int
quote(f, n)
- int f, n;
+ int f, n;
{
- int c;
+ int c;
key.k_count = 1;
if ((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') {
diff --git a/usr.bin/mg/kbd.h b/usr.bin/mg/kbd.h
index b121f0e19a3..a0433661b81 100644
--- a/usr.bin/mg/kbd.h
+++ b/usr.bin/mg/kbd.h
@@ -48,13 +48,15 @@ typedef struct {
char *n_name;
} FUNCTNAMES;
+int dobindkey __P((KEYMAP *, char *, char *));
+KEYMAP *name_map __P((char *));
+MAPS *name_mode __P((char *));
PF doscan __P((KEYMAP *, int));
PF name_function __P((char *));
char *function_name __P((PF));
-KEYMAP *name_map __P((char *));
char *map_name __P((KEYMAP *));
-MAPS *name_mode __P((char *));
-extern FUNCTNAMES functnames[];
-extern int nfunct;
-extern MAP_ELEMENT *ele;
+extern int nfunct;
+extern FUNCTNAMES functnames[];
+extern MAP_ELEMENT *ele;
+extern MAPS *defb_modes[];
diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c
index da5a1ec2724..f5f94b30885 100644
--- a/usr.bin/mg/keymap.c
+++ b/usr.bin/mg/keymap.c
@@ -1,226 +1,43 @@
/*
- * Keyboard maps. This is character set dependent.
- * The terminal specific parts of building the
- * keymap has been moved to a better place.
+ * 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 "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. */
+static int name_fent __P((char *, int));
/*
- * Defined by "window.c".
+ * initial keymap declarations, deepest first
*/
-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[] = {
+static PF cHcG[] = {
ctrlg, /* ^G */
help_help, /* ^H */
};
-static PF cHa[] = {
+
+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
+ CCHR('G'), CCHR('H'), cHcG, (KEYMAP *)NULL
},
{
- 'a', 'c', cHa, (KEYMAP *) NULL
+ 'a', 'c', cHa, (KEYMAP *)NULL
},
}
};
-#endif
+#endif /* !NO_HELP */
static struct KEYMAPE (1 + IMAPEXT) extramap1 = {
0,
@@ -252,11 +69,11 @@ static struct KEYMAPE (1 + IMAPEXT) extramap5 = {
rescan
};
-static PF cX4cF[] = {
+static PF cX4cF[] = {
poptofile, /* ^f */
ctrlg, /* ^g */
};
-static PF cX4b[] = {
+static PF cX4b[] = {
poptobuffer, /* b */
rescan, /* c */
rescan, /* d */
@@ -269,15 +86,15 @@ static struct KEYMAPE (2 + IMAPEXT) cX4map = {
rescan,
{
{
- CCHR('F'), CCHR('G'), cX4cF, (KEYMAP *) NULL
+ CCHR('F'), CCHR('G'), cX4cF, (KEYMAP *)NULL
},
{
- 'b', 'f', cX4b, (KEYMAP *) NULL
+ 'b', 'f', cX4b, (KEYMAP *)NULL
},
}
};
-static PF cXcB[] = {
+static PF cXcB[] = {
listbuffers, /* ^B */
quit, /* ^C */
rescan, /* ^D */
@@ -285,7 +102,8 @@ static PF cXcB[] = {
filevisit, /* ^F */
ctrlg, /* ^G */
};
-static PF cXcL[] = {
+
+static PF cXcL[] = {
lowerregion, /* ^L */
rescan, /* ^M */
rescan, /* ^N */
@@ -300,23 +118,27 @@ static PF cXcL[] = {
filewrite, /* ^W */
swapmark, /* ^X */
};
+
#ifndef NO_MACRO
-static PF cXlp[] = {
+static PF cXlp[] = {
definemacro, /* ( */
finishmacro, /* ) */
};
-#endif
-static PF cX0[] = {
+#endif /* !NO_MACRO */
+
+static PF cX0[] = {
delwind, /* 0 */
onlywind, /* 1 */
splitwind, /* 2 */
rescan, /* 3 */
prefix, /* 4 */
};
-static PF cXeq[] = {
+
+static PF cXeq[] = {
showcpos, /* = */
};
-static PF cXcar[] = {
+
+static PF cXcar[] = {
enlargewind, /* ^ */
rescan, /* _ */
rescan, /* ` */
@@ -325,14 +147,14 @@ static PF cXcar[] = {
rescan, /* c */
#ifndef NO_DIRED
dired, /* d */
-#else
+#else /* !NO_DIRED */
rescan, /* d */
-#endif
+#endif /* !NO_DIRED */
#ifndef NO_MACRO
executemacro, /* e */
-#else
+#else /* !NO_MACRO */
rescan, /* e */
-#endif
+#endif /* !NO_MACRO */
setfillcol, /* f */
rescan, /* g */
rescan, /* h */
@@ -348,53 +170,58 @@ static PF cXcar[] = {
rescan, /* r */
savebuffers, /* s */
};
+
#ifndef NO_MACRO
static struct KEYMAPE (6 + IMAPEXT) cXmap = {
6,
6 + IMAPEXT,
-#else
+#else /* !NO_MACRO */
static struct KEYMAPE (5 + IMAPEXT) cXmap = {
5,
5 + IMAPEXT,
-#endif
+#endif /* !NO_MACRO */
rescan,
{
{
- CCHR('B'), CCHR('G'), cXcB, (KEYMAP *) NULL
+ CCHR('B'), CCHR('G'), cXcB, (KEYMAP *)NULL
},
{
- CCHR('L'), CCHR('X'), cXcL, (KEYMAP *) NULL
+ CCHR('L'), CCHR('X'), cXcL, (KEYMAP *)NULL
},
#ifndef NO_MACRO
{
- '(', ')', cXlp, (KEYMAP *) NULL
+ '(', ')', cXlp, (KEYMAP *)NULL
},
-#endif
+#endif /* !NO_MACRO */
{
'0', '4', cX0, (KEYMAP *) & cX4map
},
{
- '=', '=', cXeq, (KEYMAP *) NULL
+ '=', '=', cXeq, (KEYMAP *)NULL
},
{
- '^', 's', cXcar, (KEYMAP *) NULL
+ '^', 's', cXcar, (KEYMAP *)NULL
},
}
};
-static PF metacG[] = {
+static PF metacG[] = {
ctrlg, /* ^G */
};
-static PF metacV[] = {
+
+static PF metacV[] = {
pagenext, /* ^V */
};
-static PF metasp[] = {
+
+static PF metasp[] = {
justone, /* space */
};
-static PF metapct[] = {
+
+static PF metapct[] = {
queryrepl, /* % */
};
-static PF metami[] = {
+
+static PF metami[] = {
negative_argument, /* - */
rescan, /* . */
rescan, /* / */
@@ -414,7 +241,8 @@ static PF metami[] = {
rescan, /* = */
gotoeob, /* > */
};
-static PF metalb[] = {
+
+static PF metalb[] = {
gotobop, /* [ */
delwhite, /* \ */
gotoeop, /* ] */
@@ -428,7 +256,8 @@ static PF metalb[] = {
rescan, /* e */
forwword, /* f */
};
-static PF metal[] = {
+
+static PF metal[] = {
lowerword, /* l */
rescan, /* m */
rescan, /* n */
@@ -443,43 +272,45 @@ static PF metal[] = {
copyregion, /* w */
extend, /* x */
};
-static PF metatilde[] = {
+
+static PF metatilde[] = {
notmodified, /* ~ */
delbword, /* DEL */
};
+
static struct KEYMAPE (8 + IMAPEXT) metamap = {
8,
8 + IMAPEXT,
rescan,
{
{
- CCHR('G'), CCHR('G'), metacG, (KEYMAP *) NULL
+ CCHR('G'), CCHR('G'), metacG, (KEYMAP *)NULL
},
{
- CCHR('V'), CCHR('V'), metacV, (KEYMAP *) NULL
+ CCHR('V'), CCHR('V'), metacV, (KEYMAP *)NULL
},
{
- ' ', ' ', metasp, (KEYMAP *) NULL
+ ' ', ' ', metasp, (KEYMAP *)NULL
},
{
- '%', '%', metapct, (KEYMAP *) NULL
+ '%', '%', metapct, (KEYMAP *)NULL
},
{
- '-', '>', metami, (KEYMAP *) NULL
+ '-', '>', metami, (KEYMAP *)NULL
},
{
- '[', 'f', metalb, (KEYMAP *) NULL
+ '[', 'f', metalb, (KEYMAP *)NULL
},
{
'l', 'x', metal, (KEYMAP *) NULL
},
{
- '~', CCHR('?'), metatilde, (KEYMAP *) NULL
+ '~', CCHR('?'), metatilde, (KEYMAP *)NULL
},
}
};
-static PF fund_at[] = {
+static PF fund_at[] = {
setmark, /* ^@ */
gotobol, /* ^A */
backchar, /* ^B */
@@ -490,12 +321,13 @@ static PF fund_at[] = {
ctrlg, /* ^G */
#ifndef NO_HELP
prefix, /* ^H */
-#else
+#else /* !NO_HELP */
rescan, /* ^H */
-#endif
+#endif /* !NO_HELP */
};
+
/* ^I is selfinsert */
-static PF fund_CJ[] = {
+static PF fund_CJ[] = {
indent, /* ^J */
killline, /* ^K */
reposition, /* ^L */
@@ -512,21 +344,18 @@ static PF fund_CJ[] = {
killregion, /* ^W */
prefix, /* ^X */
yank, /* ^Y */
-#ifndef VMS
spawncli, /* ^Z */
-#else
- attachtoparent, /* ^Z */
-#endif
};
-static PF fund_esc[] = {
+
+static PF fund_esc[] = {
prefix, /* esc */
- rescan, /* ^\ *//* selfinsert is default on
- * fundamental */
+ rescan, /* ^\ selfinsert is default on fundamental */
rescan, /* ^] */
rescan, /* ^^ */
rescan, /* ^_ */
};
-static PF fund_del[] = {
+
+static PF fund_del[] = {
backdel, /* DEL */
};
@@ -543,11 +372,11 @@ static struct KEYMAPE (4 + NFUND_XMAPS + IMAPEXT) fundmap = {
{
CCHR('@'), CCHR('H'), fund_at, (KEYMAP *) & helpmap
},
-#else
+#else /* !NO_HELP */
{
- CCHR('@'), CCHR('H'), fund_at, (KEYMAP *) NULL
+ CCHR('@'), CCHR('H'), fund_at, (KEYMAP *)NULL
},
-#endif
+#endif /* !NO_HELP */
{
CCHR('J'), CCHR('Z'), fund_CJ, (KEYMAP *) & cXmap
},
@@ -555,73 +384,78 @@ static struct KEYMAPE (4 + NFUND_XMAPS + IMAPEXT) fundmap = {
CCHR('['), CCHR('_'), fund_esc, (KEYMAP *) & metamap
},
{
- CCHR('?'), CCHR('?'), fund_del, (KEYMAP *) NULL
+ CCHR('?'), CCHR('?'), fund_del, (KEYMAP *)NULL
},
-#ifdef FUND_XMAPS
+#ifdef FUND_XMAPS
FUND_XMAPS,
-#endif
+#endif /* FUND_XMAPS */
}
};
-static PF fill_sp[] = {
+static PF fill_sp[] = {
fillword, /* ' ' */
};
+
static struct KEYMAPE (1 + IMAPEXT) fillmap = {
1,
1 + IMAPEXT,
rescan,
{
{
- ' ', ' ', fill_sp, (KEYMAP *) NULL
+ ' ', ' ', fill_sp, (KEYMAP *)NULL
},
}
};
-static PF indent_lf[] = {
+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
+ CCHR('J'), CCHR('M'), indent_lf, (KEYMAP *)NULL
},
}
};
-static PF blink_rp[] = {
+
+static PF blink_rp[] = {
showmatch, /* ) */
};
+
static struct KEYMAPE (1 + IMAPEXT) blinkmap = {
1,
1 + IMAPEXT,
rescan,
{
{
- ')', ')', blink_rp, (KEYMAP *) NULL
+ ')', ')', blink_rp, (KEYMAP *)NULL
},
}
};
-#ifdef NOTAB
-static PF notab_tab[] = {
+#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
+ CCHR('I'), CCHR('I'), notab_tab, (KEYMAP *)NULL
},
}
};
-#endif
+#endif /* NOTAB */
static struct KEYMAPE (1 + IMAPEXT) overwmap = {
0,
@@ -630,13 +464,13 @@ static struct KEYMAPE (1 + IMAPEXT) overwmap = {
{
/* unused dummy entry for VMS C */
{
- (KCHAR) 0, (KCHAR) 0, (PF *) NULL, (KEYMAP *) NULL
+ (KCHAR)0, (KCHAR)0, (PF *)NULL, (KEYMAP *)NULL
},
}
};
#ifndef NO_DIRED
-static PF dirednul[] = {
+static PF dirednul[] = {
setmark, /* ^@ */
gotobol, /* ^A */
backchar, /* ^B */
@@ -647,9 +481,10 @@ static PF dirednul[] = {
ctrlg, /* ^G */
#ifndef NO_HELP
prefix, /* ^H */
-#endif
+#endif /* !NO_HELP */
};
-static PF diredcl[] = {
+
+static PF diredcl[] = {
reposition, /* ^L */
forwline, /* ^M */
forwline, /* ^N */
@@ -664,12 +499,9 @@ static PF diredcl[] = {
rescan, /* ^W */
prefix, /* ^X */
};
-static PF diredcz[] = {
-#ifndef VMS
+
+static PF diredcz[] = {
spawncli, /* ^Z */
-#else
- attachtoparent, /* ^Z */
-#endif
prefix, /* esc */
rescan, /* ^\ */
rescan, /* ^] */
@@ -677,13 +509,15 @@ static PF diredcz[] = {
rescan, /* ^_ */
forwline, /* SP */
};
-static PF diredc[] = {
+
+static PF diredc[] = {
d_copy, /* c */
d_del, /* d */
d_findfile, /* e */
d_findfile, /* f */
};
-static PF diredn[] = {
+
+static PF diredn[] = {
forwline, /* n */
d_ffotherwindow, /* o */
backline, /* p */
@@ -696,13 +530,14 @@ static PF diredn[] = {
rescan, /* w */
d_expunge, /* x */
};
-static PF direddl[] = {
+
+static PF direddl[] = {
d_undelbak, /* del */
};
#ifndef DIRED_XMAPS
#define NDIRED_XMAPS 0 /* number of extra map sections */
-#endif
+#endif /* DIRED_XMAPS */
static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
6 + NDIRED_XMAPS,
@@ -713,11 +548,11 @@ static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
{
CCHR('@'), CCHR('H'), dirednul, (KEYMAP *) & helpmap
},
-#else
+#else /* !NO_HELP */
{
- CCHR('@'), CCHR('G'), dirednul, (KEYMAP *) NULL
+ CCHR('@'), CCHR('G'), dirednul, (KEYMAP *)NULL
},
-#endif
+#endif /* !NO_HELP */
{
CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap
},
@@ -725,20 +560,20 @@ static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
CCHR('Z'), ' ', diredcz, (KEYMAP *) & metamap
},
{
- 'c', 'f', diredc, (KEYMAP *) NULL
+ 'c', 'f', diredc, (KEYMAP *)NULL
},
{
- 'n', 'x', diredn, (KEYMAP *) NULL
+ 'n', 'x', diredn, (KEYMAP *)NULL
},
{
- CCHR('?'), CCHR('?'), direddl, (KEYMAP *) NULL
+ CCHR('?'), CCHR('?'), direddl, (KEYMAP *)NULL
},
#ifdef DIRED_XMAPS
DIRED_XMAPS, /* map sections for dired mode keys */
-#endif
+#endif /* DIRED_XMAPS */
}
};
-#endif
+#endif /* !NO_DIRED */
/*
* give names to the maps, for use by help etc. If the map is to be bindable,
@@ -749,15 +584,15 @@ static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
* modes.c also.
*/
-MAPS map_table[] = {
+MAPS map_table[] = {
/* fundamental map MUST be first entry */
{(KEYMAP *) & fundmap, "fundamental"},
{(KEYMAP *) & fillmap, "fill"},
{(KEYMAP *) & indntmap, "indent"},
{(KEYMAP *) & blinkmap, "blink"},
-#ifdef NOTAB
+#ifdef NOTAB
{(KEYMAP *) & notabmap, "notab"},
-#endif
+#endif /* NOTAB */
{(KEYMAP *) & overwmap, "overwrite"},
{(KEYMAP *) & metamap, "esc prefix"},
{(KEYMAP *) & cXmap, "c-x prefix"},
@@ -776,40 +611,40 @@ MAPS map_table[] = {
};
#define NMAPS (sizeof map_table/sizeof(MAPS))
-int nmaps = NMAPS; /* for use by rebind in extend.c */
+int nmaps = NMAPS; /* for use by rebind in extend.c */
-char *
+char *
map_name(map)
- KEYMAP *map;
+ KEYMAP *map;
{
- MAPS *mp = &map_table[0];
+ MAPS *mp = &map_table[0];
do {
if (mp->p_map == map)
return mp->p_name;
} while (++mp < &map_table[NMAPS]);
- return (char *) NULL;
+ return (char *)NULL;
}
-MAPS *
+MAPS *
name_mode(name)
- char *name;
+ char *name;
{
- MAPS *mp = &map_table[0];
+ MAPS *mp = &map_table[0];
do {
if (strcmp(mp->p_name, name) == 0)
return mp;
} while (++mp < &map_table[NMAPS]);
- return (MAPS *) NULL;
+ return (MAPS *)NULL;
}
-KEYMAP *
+KEYMAP *
name_map(name)
- char *name;
+ char *name;
{
- MAPS *mp;
- return (mp = name_mode(name)) == NULL ? (KEYMAP *) NULL : mp->p_map;
+ MAPS *mp;
+ return (mp = name_mode(name)) == NULL ? (KEYMAP *)NULL : mp->p_map;
}
/*
@@ -817,34 +652,10 @@ name_map(name)
* 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 */
+FUNCTNAMES functnames[] = {
#ifndef NO_HELP
{apropos_command, "apropos"},
-#endif
+#endif /* !NO_HELP */
{fillmode, "auto-fill-mode"},
{indentmode, "auto-indent-mode"},
{backchar, "backward-char"},
@@ -855,23 +666,23 @@ FUNCTNAMES functnames[] = {
{gotobol, "beginning-of-line"},
{blinkparen, "blink-matching-paren"},
{showmatch, "blink-matching-paren-hack"},
-#ifdef BSMAP
+#ifdef BSMAP
{bsmap, "bsmap-mode"},
-#endif
+#endif /* BSMAP */
{prefix, "c-x 4 prefix"},
{prefix, "c-x prefix"},
#ifndef NO_MACRO
{executemacro, "call-last-kbd-macro"},
-#endif
+#endif /* !NO_MACRO */
{capword, "capitalize-word"},
#ifndef NO_DIR
{changedir, "cd"},
-#endif
+#endif /* !NO_DIR */
{copyregion, "copy-region-as-kill"},
#ifdef REGEX
{cntmatchlines, "count-matches"},
{cntnonmatchlines, "count-non-matches"},
-#endif
+#endif /* REGEX */
{define_key, "define-key"},
{backdel, "delete-backward-char"},
{deblank, "delete-blank-lines"},
@@ -880,13 +691,13 @@ FUNCTNAMES functnames[] = {
#ifdef REGEX
{delmatchlines, "delete-matching-lines"},
{delnonmatchlines, "delete-non-matching-lines"},
-#endif
+#endif /* REGEX */
{onlywind, "delete-other-windows"},
{delwind, "delete-window"},
#ifndef NO_HELP
{wallchart, "describe-bindings"},
{desckey, "describe-key-briefly"},
-#endif
+#endif /* !NO_HELP */
{digit_argument, "digit-argument"},
#ifndef NO_DIRED
{dired, "dired"},
@@ -899,13 +710,13 @@ FUNCTNAMES functnames[] = {
{d_otherwindow, "dired-other-window"},
{d_rename, "dired-rename-file"},
{d_undel, "dired-unflag"},
-#endif
+#endif /* !NO_DIRED */
{lowerregion, "downcase-region"},
{lowerword, "downcase-word"},
{showversion, "emacs-version"},
#ifndef NO_MACRO
{finishmacro, "end-kbd-macro"},
-#endif
+#endif /* !NO_MACRO */
{gotoeob, "end-of-buffer"},
{gotoeol, "end-of-line"},
{enlargewind, "enlarge-window"},
@@ -913,7 +724,7 @@ FUNCTNAMES functnames[] = {
#ifndef NO_STARTUP
{evalbuffer, "eval-current-buffer"},
{evalexpr, "eval-expression"},
-#endif
+#endif /* !NO_STARTUP */
{swapmark, "exchange-point-and-mark"},
{extend, "execute-extended-command"},
{prefix, "extra prefix 1"},
@@ -933,7 +744,7 @@ FUNCTNAMES functnames[] = {
#ifndef NO_HELP
{prefix, "help"},
{help_help, "help-help"},
-#endif
+#endif /* !NO_HELP */
{insert, "insert"},
{bufferinsert, "insert-buffer"},
{fileinsert, "insert-file"},
@@ -950,109 +761,81 @@ FUNCTNAMES functnames[] = {
{listbuffers, "list-buffers"},
#ifndef NO_STARTUP
{evalfile, "load"},
-#endif
+#endif /* !NO_STARTUP */
{localbind, "local-set-key"},
{localunbind, "local-unset-key"},
#ifndef NO_BACKUP
{makebkfile, "make-backup-files"},
-#endif
-#ifdef DO_METAKEY
+#endif /* !NO_BACKUP */
+#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
+#endif /* DO_METAKEY */
{negative_argument, "negative-argument"},
{newline, "newline"},
{indent, "newline-and-indent"},
{forwline, "next-line"},
-#ifdef NOTAB
+#ifdef NOTAB
{notabmode, "no-tab-mode"},
-#endif
+#endif /* NOTAB */
{notmodified, "not-modified"},
{openline, "open-line"},
{nextwind, "other-window"},
{overwrite, "overwrite-mode"},
-#ifdef PREFIXREGION
+#ifdef PREFIXREGION
{prefixregion, "prefix-region"},
-#endif
+#endif /* PREFIXREGION */
{backline, "previous-line"},
-#ifdef GOSMACS
+#ifdef GOSMACS
{prevwind, "previous-window"},
-#endif
-#ifdef VMS
- {spawncli, "push-to-dcl"},
-#else
+#endif /* GOSEMACS */
{spawncli, "push-shell"},
-#endif
#ifndef NO_DIR
{showcwdir, "pwd"},
-#endif
+#endif /* !NO_DIR */
{queryrepl, "query-replace"},
-#ifdef REGEX
+#ifdef REGEX
{re_queryrepl, "query-replace-regexp"},
-#endif
+#endif /* REGEX */
{quote, "quoted-insert"},
-#ifdef REGEX
+#ifdef REGEX
{re_searchagain, "re-search-again"},
{re_backsearch, "re-search-backward"},
{re_forwsearch, "re-search-forward"},
-#endif
+#endif /* REGEX */
{reposition, "recenter"},
{refresh, "redraw-display"},
{filesave, "save-buffer"},
{quit, "save-buffers-kill-emacs"},
{savebuffers, "save-some-buffers"},
{backpage, "scroll-down"},
-#ifdef GOSMACS
+#ifdef GOSMACS
{back1page, "scroll-one-line-down"},
{forw1page, "scroll-one-line-up"},
-#endif
+#endif /* GOSMACS */
{pagenext, "scroll-other-window"},
{forwpage, "scroll-up"},
{searchagain, "search-again"},
{backsearch, "search-backward"},
{forwsearch, "search-forward"},
{selfinsert, "self-insert-command"},
-#ifdef REGEX
+#ifdef REGEX
{setcasefold, "set-case-fold-search"},
-#endif
+#endif /* REGEX */
{set_default_mode, "set-default-mode"},
{setfillcol, "set-fill-column"},
{setmark, "set-mark-command"},
-#ifdef PREFIXREGION
+#ifdef PREFIXREGION
{setprefix, "set-prefix-string"},
-#endif
+#endif /* PREFIXREGION */
{shrinkwind, "shrink-window"},
-#ifdef NOTAB
+#ifdef NOTAB
{space_to_tabstop, "space-to-tabstop"},
-#endif
+#endif /* NOTAB */
{splitwind, "split-window-vertically"},
#ifndef NO_MACRO
{definemacro, "start-kbd-macro"},
-#endif
-#ifdef VMS
- {attachtoparent, "suspend-emacs"},
-#else
+#endif /* !NO_MACRO */
{spawncli, "suspend-emacs"},
-#endif
{usebuffer, "switch-to-buffer"},
{poptobuffer, "switch-to-buffer-other-window"},
{twiddle, "transpose-chars"},
@@ -1066,7 +849,7 @@ FUNCTNAMES functnames[] = {
#define NFUNCT (sizeof(functnames)/sizeof(FUNCTNAMES))
-int nfunct = NFUNCT;/* used by help.c */
+int nfunct = NFUNCT; /* used by help.c */
/*
* The general-purpose version of ROUND2 blows osk C (2.0) out of the water.
@@ -1078,26 +861,27 @@ int nfunct = NFUNCT;/* used by help.c */
*/
#define ROUND2(x) (x<128?(x<64?32:64):(x<256?128:256))
-static
+static int
name_fent(fname, flag)
- register char *fname;
- int flag;
+ char *fname;
+ int flag;
{
- register int try;
- register int x = ROUND2(NFUNCT);
- register int base = 0;
- register int notit;
+ int try, notit;
+ int x = ROUND2(NFUNCT);
+ int base = 0;
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 = 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 */
+ /* try 0 once if needed */
+ } while ((x >>= 1) || (try == 1 && base == 0));
return flag ? base : -1;
}
@@ -1107,55 +891,62 @@ name_fent(fname, flag)
PF
name_function(fname)
- char *fname;
+ char *fname;
{
- int i;
+ int i;
if ((i = name_fent(fname, FALSE)) >= 0)
return functnames[i].n_funct;
- return (PF) NULL;
+ return (PF)NULL;
}
-/* complete function name */
-
+/*
+ * complete function name
+ */
int
complete_function(fname, c)
- register char *fname;
- int c;
+ char *fname;
+ int c;
{
- register int i, j, k, l;
- int oj;
+ int i, j, k, l, 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++) {
- }
+ /* no match */
+ return -2;
+ for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l;
+ j++);
if (fname[j] != '\0')
- return -2; /* no match */
+ /* no match */
+ return -2;
}
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++) {
- }
+ /* find last match */
+ for (k = i + 1; k < NFUNCT; k++) {
+ 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]) {
+
+ 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]) {
+ /* ambiguous */
+ return -3;
+ } else {
+ /* single match */
+ while ((l = functnames[i].n_name[j])) {
fname[j++] = l;
if (l == '-' && c == ' ')
break;
@@ -1165,40 +956,42 @@ complete_function(fname, c)
return j - oj;
}
-/* list possible function name completions */
-
-LIST *
+/*
+ * list possible function name completions.
+ */
+LIST *
complete_function_list(fname, c)
- register char *fname;
+ char *fname;
+ int c;
{
- register int i, j, k, l;
- int oj;
- LIST *current, *last;
+ int i, j, k, l;
+ LIST *current, *last;
i = name_fent(fname, TRUE);
- for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) {
- }
+ for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++);
if (fname[j] != '\0') {
if (++i >= NFUNCT)
- return NULL; /* no match */
- for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) {
- }
+ /* no match */
+ return NULL;
+ for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l;
+ j++);
if (fname[j] != '\0')
- return NULL; /* no match */
+ /* no match */
+ return NULL;
}
/*
- * if(c==CCHR('M') && functnames[i].n_name[j]=='\0') return -1;
+ * 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++) {
- }
+ /* find last match */
+ for (k = i + 1; k < NFUNCT; k++) {
+ for (l = 0; functnames[k].n_name[l] == fname[l]; l++);
if (l < j)
break;
}
k--;
last = NULL;
for (; k >= i; k--) {
- current = (LIST *) malloc(sizeof(LIST));
+ current = (LIST *)malloc(sizeof(LIST));
current->l_next = last;
current->l_name = functnames[k].n_name;
last = current;
@@ -1206,19 +999,21 @@ complete_function_list(fname, c)
return (last);
}
-/* translate from function pointer to function name. */
-
-char *
+/*
+ * translate from function pointer to function name.
+ */
+char *
function_name(fpoint)
- register PF fpoint;
+ PF fpoint;
{
- register FUNCTNAMES *fnp = &functnames[0];
+ FUNCTNAMES *fnp = &functnames[0];
if (fpoint == prefix)
- return (char *) NULL; /* ambiguous */
+ /* ambiguous */
+ return (char *)NULL;
do {
if (fnp->n_funct == fpoint)
return fnp->n_name;
} while (++fnp < &functnames[NFUNCT]);
- return (char *) NULL;
+ return (char *)NULL;
}
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 0c653291fee..23266767fbc 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,26 +1,25 @@
/*
* 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.
+ *
+ * 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
+ * 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 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 */
+#include "def.h"
+
+/*
+ * The number of bytes member from the start of the structure type should be
+ * computed at compile time.
+ */
#ifndef OFFSET
#define OFFSET(type,member) ((char *)&(((type *)0)->member)-(char *)((type *)0))
@@ -34,34 +33,36 @@
#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. */
+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. */
+
+static int kgrow __P((int));
/*
* 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.
+ * 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)
- int used;
+ int used;
{
- LINE *lp;
- int size;
+ LINE *lp;
+ 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);
+ size = sizeof(LINE);
#ifdef MALLOCROUND
MALLOCROUND(size); /* round up to a size optimal to malloc */
#endif
- if ((lp = (LINE *) malloc((unsigned) size)) == NULL) {
+ if ((lp = (LINE *)malloc((unsigned)size)) == NULL) {
ewprintf("Can't get %d bytes", size);
- return (LINE *) NULL;
+ return (LINE *)NULL;
}
lp->l_size = size - OFFSET(LINE, l_text[0]);
lp->l_used = used;
@@ -75,10 +76,10 @@ lalloc(used)
*/
LINE *
lallocx(used)
- int used;
+ int used;
{
- int size;
- LINE *lp;
+ int size;
+ LINE *lp;
size = (NBLOCK + used) & ~(NBLOCK - 1);
if ((lp = lalloc(size)) != NULL)
@@ -87,21 +88,17 @@ lallocx(used)
}
/*
- * 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.
+ * Delete line "lp". Fix all of the links that might point to it (they are
+ * moved to offset 0 of the next line. Unlink the line from whatever buffer
+ * it might be in, and 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;
+ LINE *lp;
{
- register BUFFER *bp;
- register MGWIN *wp;
+ BUFFER *bp;
+ MGWIN *wp;
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_linep == lp)
@@ -129,27 +126,25 @@ lfree(lp)
}
lp->l_bp->l_fp = lp->l_fp;
lp->l_fp->l_bp = lp->l_bp;
- free((char *) lp);
+ 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).
+ * This routine is called when a character changes 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;
+ int flag;
{
- register MGWIN *wp;
+ MGWIN *wp;
- if ((curbp->b_flag & BFCHG) == 0) { /* First change, so */
- flag |= WFMODE; /* update mode lines. */
+ /* update mode lines if this is the first change. */
+ if ((curbp->b_flag & BFCHG) == 0) {
+ flag |= WFMODE;
curbp->b_flag |= BFCHG;
}
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
@@ -162,41 +157,43 @@ lchange(flag)
}
/*
- * 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
+ * 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.
*/
+int
linsert(n, c)
- int n;
+ int n, c;
{
- register char *cp1;
- register char *cp2;
- register LINE *lp1;
- LINE *lp2;
- LINE *lp3;
- register int doto;
- register RSIZE i;
- MGWIN *wp;
+ LINE *lp1, *lp2, *lp3;
+ MGWIN *wp;
+ RSIZE i;
+ int doto;
+ char *cp1, *cp2;
lchange(WFEDIT);
- lp1 = curwp->w_dotp; /* Current line */
- if (lp1 == curbp->b_linep) { /* At the end: special */
- /* (now should only happen in empty buffer */
+
+ /* current line */
+ lp1 = curwp->w_dotp;
+
+ /* special case for the end */
+ if (lp1 == curbp->b_linep) {
+ /* 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 */
+ /* allocate a new line */
+ if ((lp2 = lallocx(n)) == NULL)
return FALSE;
- lp3 = lp1->l_bp;/* Previous line */
- lp3->l_fp = lp2;/* Link in */
+ /* previous line */
+ lp3 = lp1->l_bp;
+ /* link in */
+ lp3->l_fp = lp2;
lp2->l_fp = lp1;
lp1->l_bp = lp2;
lp2->l_bp = lp3;
@@ -214,9 +211,11 @@ linsert(n, c)
curwp->w_doto = n;
return TRUE;
}
- doto = curwp->w_doto; /* Save for later. */
+ /* save for later */
+ doto = curwp->w_doto;
/* NOSTRICT (2) */
- if (lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */
+ /* Hard case: reallocate */
+ if (lp1->l_used + n > lp1->l_size) {
if ((lp2 = lallocx(lp1->l_used + n)) == NULL)
return FALSE;
cp1 = &lp1->l_text[0];
@@ -231,9 +230,11 @@ linsert(n, c)
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 */
+ free((char *)lp1);
+ /* Easy case: in place */
+ } else {
+ /* pretend there's a new line */
+ lp2 = lp1;
/* NOSTRICT */
lp2->l_used += n;
cp2 = &lp1->l_text[lp1->l_used];
@@ -242,7 +243,8 @@ linsert(n, c)
while (cp1 != &lp1->l_text[doto])
*--cp2 = *--cp1;
}
- for (i = 0; i < n; ++i) /* Add the characters */
+ /* Add the characters */
+ for (i = 0; i < n; ++i)
lp2->l_text[doto + i] = c;
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
@@ -265,23 +267,26 @@ linsert(n, c)
}
/*
- * 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.
+ * 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.
*/
+int
lnewline()
{
- register LINE *lp1;
- register LINE *lp2;
- register int doto;
- register int nlen;
- MGWIN *wp;
+ LINE *lp1, *lp2;
+ int doto, nlen;
+ MGWIN *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 */
+
+ /* Get the address and offset of "." */
+ lp1 = curwp->w_dotp;
+ doto = curwp->w_doto;
+
+ /* avoid unnecessary copying */
+ if (doto == 0) {
+ /* new first part */
+ if ((lp2 = lallocx(0)) == NULL)
return FALSE;
lp2->l_bp = lp1->l_bp;
lp1->l_bp->l_fp = lp2;
@@ -292,8 +297,12 @@ lnewline()
wp->w_linep = lp2;
return TRUE;
}
- nlen = llength(lp1) - doto; /* length of new part */
- if ((lp2 = lallocx(nlen)) == NULL) /* New second half line */
+
+ /* length of new part */
+ nlen = llength(lp1) - doto;
+
+ /* new second half line */
+ if ((lp2 = lallocx(nlen)) == NULL)
return FALSE;
if (nlen != 0)
bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen);
@@ -302,7 +311,8 @@ lnewline()
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 */
+ /* Windows */
+ for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_dotp == lp1 && wp->w_doto >= doto) {
wp->w_dotp = lp2;
wp->w_doto -= doto;
@@ -316,23 +326,22 @@ lnewline()
}
/*
- * 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.
+ * This function deletes "n" bytes, starting at dot. It understands how to
+ * 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.
*/
+int
ldelete(n, kflag)
- RSIZE n;
+ RSIZE n;
+ int kflag;
{
- register char *cp1;
- register char *cp2;
- register LINE *dotp;
- register int doto;
- register RSIZE chunk;
- MGWIN *wp;
+ LINE *dotp;
+ RSIZE chunk;
+ MGWIN *wp;
+ int doto;
+ char *cp1, *cp2;
/*
* HACK - doesn't matter, and fixes back-over-nl bug for empty
@@ -344,41 +353,46 @@ ldelete(n, kflag)
while (n != 0) {
dotp = curwp->w_dotp;
doto = curwp->w_doto;
- if (dotp == curbp->b_linep) /* Hit end of buffer. */
+ /* Hit the end of the buffer */
+ if (dotp == curbp->b_linep)
return FALSE;
- chunk = dotp->l_used - doto; /* Size of chunk. */
+ /* Size of the chunk */
+ chunk = dotp->l_used - doto;
if (chunk > n)
chunk = n;
- if (chunk == 0) { /* End of line, merge. */
+ /* End of line, merge */
+ if (chunk == 0) {
if (dotp == lback(curbp->b_linep))
- return FALSE; /* End of buffer. */
+ /* End of buffer */
+ return FALSE;
lchange(WFHARD);
- if (ldelnewline() == FALSE
- || (kflag != KNONE && kinsert('\n', kflag) == FALSE))
+ if (ldelnewline() == FALSE ||
+ (kflag != KNONE && kinsert('\n', kflag) == FALSE))
return FALSE;
--n;
continue;
}
lchange(WFEDIT);
- cp1 = &dotp->l_text[doto]; /* Scrunch text. */
+ /* Scrunch text */
+ cp1 = &dotp->l_text[doto];
cp2 = cp1 + chunk;
if (kflag == KFORW) {
while (ksize - kused < chunk)
if (kgrow(FALSE) == FALSE)
return FALSE;
- bcopy(cp1, &(kbufp[kused]), (int) chunk);
+ 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);
+ 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;
+ dotp->l_used -= (int)chunk;
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_dotp == dotp && wp->w_doto >= doto) {
/* NOSTRICT */
@@ -399,26 +413,24 @@ ldelete(n, kflag)
}
/*
- * 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.
+ * Delete a newline and 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, 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.
*/
+int
ldelnewline()
{
- register LINE *lp1;
- register LINE *lp2;
- register MGWIN *wp;
- LINE *lp3;
+ LINE *lp1, *lp2, *lp3;
+ MGWIN *wp;
lp1 = curwp->w_dotp;
lp2 = lp1->l_fp;
- if (lp2 == curbp->b_linep) /* At the buffer end. */
+ /* at the end of the buffer */
+ if (lp2 == curbp->b_linep)
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);
@@ -437,7 +449,7 @@ ldelnewline()
lp1->l_used += lp2->l_used;
lp1->l_fp = lp2->l_fp;
lp2->l_fp->l_bp = lp1;
- free((char *) lp2);
+ free((char *)lp2);
return TRUE;
}
if ((lp3 = lalloc(lp1->l_used + lp2->l_used)) == NULL)
@@ -464,34 +476,35 @@ ldelnewline()
wp->w_marko += lp1->l_used;
}
}
- free((char *) lp1);
- free((char *) lp2);
+ 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).
+ * 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).
*/
+int
lreplace(plen, st, f)
- register RSIZE plen; /* length to remove */
- char *st; /* replacement string */
- int f; /* case hack disable */
+ 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 */
+ RSIZE rlen; /* replacement length */
+ int rtype; /* capitalization */
+ int c; /* used for random characters */
+ 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.
+ * 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);
+ (VOID)backchar(FFARG | FFRAND, (int)plen);
rtype = _L;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (ISUPPER(c) != FALSE && f == FALSE) {
@@ -511,9 +524,9 @@ lreplace(plen, st, f)
rlen = strlen(st);
doto = curwp->w_doto;
if (plen > rlen)
- (VOID) ldelete((RSIZE) (plen - rlen), KNONE);
+ (VOID)ldelete((RSIZE) (plen - rlen), KNONE);
else if (plen < rlen) {
- if (linsert((int) (rlen - plen), ' ') == FALSE)
+ if (linsert((int)(rlen - plen), ' ') == FALSE)
return FALSE;
}
curwp->w_doto = doto;
@@ -530,16 +543,16 @@ lreplace(plen, st, f)
rtype = _L;
if (c == CCHR('J')) {
if (curwp->w_doto == llength(curwp->w_dotp))
- (VOID) forwchar(FFRAND, 1);
+ (VOID)forwchar(FFRAND, 1);
else {
if (ldelete((RSIZE) 1, KNONE) != FALSE)
- (VOID) lnewline();
+ (VOID)lnewline();
}
} else if (curwp->w_dotp == curbp->b_linep) {
- (VOID) linsert(1, c);
+ (VOID)linsert(1, c);
} else if (curwp->w_doto == llength(curwp->w_dotp)) {
if (ldelete((RSIZE) 1, KNONE) != FALSE)
- (VOID) linsert(1, c);
+ (VOID)linsert(1, c);
} else
lputc(curwp->w_dotp, curwp->w_doto++, c);
}
@@ -548,35 +561,31 @@ lreplace(plen, st, f)
}
/*
- * 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.
+ * Delete all of the text saved in the kill buffer. Called by commands when
+ * a new kill context is created. The kill buffer array is released, just in
+ * case the buffer has grown to an immense size. No errors.
*/
VOID
kdelete()
{
-
if (kbufp != NULL) {
- free((char *) kbufp);
+ 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.
+ * 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.
*/
+int
kinsert(c, dir)
+ int c, dir;
{
-
if (kused == ksize && dir == KFORW && kgrow(FALSE) == FALSE)
return FALSE;
if (kstart == 0 && dir == KBACK && kgrow(TRUE) == FALSE)
@@ -594,24 +603,26 @@ kinsert(c, dir)
* 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.
*/
+static int
kgrow(back)
+ int back;
{
- register int nstart;
- register char *nbufp;
+ int nstart;
+ char *nbufp;
- if ((unsigned) (ksize + KBLOCK) <= (unsigned) ksize) {
+ 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));
+ 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));
+ bcopy(&(kbufp[kstart]), &(nbufp[nstart]), (int)(kused - kstart));
if (kbufp != NULL)
- free((char *) kbufp);
+ free((char *)kbufp);
kbufp = nbufp;
ksize += KBLOCK;
kused = kused - kstart + nstart;
@@ -620,12 +631,13 @@ kgrow(back)
}
/*
- * 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.
+ * 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.
*/
+int
kremove(n)
+ int n;
{
if (n < 0 || n + kstart >= kused)
return -1;
diff --git a/usr.bin/mg/macro.c b/usr.bin/mg/macro.c
index 6b4396bf78a..dba7c255130 100644
--- a/usr.bin/mg/macro.c
+++ b/usr.bin/mg/macro.c
@@ -1,4 +1,6 @@
-/* keyboard macros for Mg 2 */
+/*
+ * Keyboard macros.
+ */
#ifndef NO_MACRO
#include "def.h"
@@ -8,35 +10,40 @@
#include "macro.h"
/* ARGSUSED */
+int
definemacro(f, n)
- int f, n;
+ int f, n;
{
- register LINE *lp1;
- LINE *lp2;
+ LINE *lp1, *lp2;
macrocount = 0;
+
if (macrodef) {
ewprintf("already defining macro");
return macrodef = FALSE;
}
+
/* free lines allocated for string arguments */
if (maclhead != NULL) {
for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) {
lp2 = lp1->l_fp;
- free((char *) lp1);
+ free((char *)lp1);
}
- free((char *) lp1);
+ free((char *)lp1);
}
+
if ((maclhead = lp1 = lalloc(0)) == NULL)
return FALSE;
+
ewprintf("Defining Keyboard Macro...");
maclcur = lp1->l_fp = lp1->l_bp = lp1;
return macrodef = TRUE;
}
/* ARGSUSED */
+int
finishmacro(f, n)
- int f, n;
+ int f, n;
{
macrodef = FALSE;
ewprintf("End Keyboard Macro Definition");
@@ -44,20 +51,22 @@ finishmacro(f, n)
}
/* ARGSUSED */
+int
executemacro(f, n)
- int f, n;
+ int f, n;
{
- int i, j;
- PF funct;
- int universal_argument();
- int flag, num;
+ int i, j, flag, num;
+ PF funct;
- if (macrodef ||
- (macrocount >= MAXMACRO && macro[MAXMACRO].m_funct != finishmacro))
+ if (macrodef ||
+ (macrocount >= MAXMACRO && macro[MAXMACRO].m_funct != finishmacro))
return FALSE;
+
if (macrocount == 0)
return TRUE;
+
inmacro = TRUE;
+
for (i = n; i > 0; i--) {
maclcur = maclhead->l_fp;
flag = 0;
@@ -69,7 +78,7 @@ executemacro(f, n)
num = macro[++j].m_count;
continue;
}
- if ((*funct) (flag, num) != TRUE) {
+ if ((*funct)(flag, num) != TRUE) {
inmacro = FALSE;
return FALSE;
}
@@ -82,4 +91,4 @@ executemacro(f, n)
inmacro = FALSE;
return TRUE;
}
-#endif
+#endif /* NO_MACRO */
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index cb84ca4ddbf..80047685af8 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,83 +1,84 @@
/*
- * Mainline
+ * Mainline.
*/
+
#include "def.h"
+
#ifndef NO_MACRO
#include "macro.h"
-#endif
+#endif /* NO_MACRO */
-int thisflag; /* Flags, this command */
-int lastflag; /* Flags, last command */
-int curgoal; /* Goal column */
-BUFFER *curbp; /* Current buffer */
-MGWIN *curwp; /* Current window */
-BUFFER *bheadp; /* BUFFER listhead */
-MGWIN *wheadp = (MGWIN *) NULL; /* MGWIN listhead */
-char pat[NPAT]; /* Pattern */
-#ifndef NO_DPROMPT
-extern char prompt[], *promptp; /* delayed prompting */
-#endif
+int thisflag; /* flags, this command */
+int lastflag; /* flags, last command */
+int curgoal; /* goal column */
+BUFFER *curbp; /* current buffer */
+BUFFER *bheadp; /* BUFFER listhead */
+MGWIN *curwp; /* current window */
+MGWIN *wheadp = (MGWIN *)NULL; /* MGWIN listhead */
+char pat[NPAT]; /* pattern */
-static VOID edinit();
+static VOID edinit __P((VOID));
int
main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char **argv;
{
-#ifndef NO_STARTUP
- char *startupfile();
-#endif
- char *cp;
- VOID vtinit(), makename(), eerase();
- BUFFER *findbuffer();
+ char *cp;
#ifdef SYSINIT
- SYSINIT; /* system dependent. */
-#endif
- vtinit(); /* Virtual terminal. */
+ SYSINIT; /* System dependent. */
+#endif /* SYSINIT */
+ vtinit(); /* Virtual terminal. */
#ifndef NO_DIR
- dirinit(); /* Get current directory */
-#endif
- edinit(); /* Buffers, windows. */
- ttykeymapinit(); /* Symbols, bindings. */
+ dirinit(); /* Get current directory. */
+#endif /* !NO_DIR */
+ 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
+
+#ifndef NO_STARTUP
+ /* user startup file */
+ if ((cp = startupfile((char *)NULL)) != NULL)
+ (VOID)load(cp);
+#endif /* !NO_STARTUP */
while (--argc > 0) {
cp = adjustname(*++argv);
curbp = findbuffer(cp);
- (VOID) showbuffer(curbp, curwp, 0);
- (VOID) readin(cp);
+ (VOID)showbuffer(curbp, curwp, 0);
+ (VOID)readin(cp);
}
- thisflag = 0; /* Fake last flags. */
+
+ /* fake last flags */
+ thisflag = 0;
for (;;) {
#ifndef NO_DPROMPT
*(promptp = prompt) = '\0';
if (epresf == KPROMPT)
eerase();
-#endif
+#endif /* !NO_DPROMPT */
update();
lastflag = thisflag;
thisflag = 0;
+
switch (doin()) {
case TRUE:
break;
case ABORT:
- ewprintf("Quit"); /* and fall through */
+ ewprintf("Quit");
+ /* and fall through */
case FALSE:
default:
ttbeep();
#ifndef NO_MACRO
macrodef = FALSE;
-#endif
+#endif /* !NO_MACRO */
}
}
}
@@ -85,62 +86,60 @@ main(argc, argv)
/*
* Initialize default buffer and window.
*/
-static VOID
+static VOID
edinit()
{
- register BUFFER *bp;
- register MGWIN *wp;
+ BUFFER *bp;
+ MGWIN *wp;
bheadp = NULL;
- bp = bfind("*scratch*", TRUE); /* Text buffer. */
- wp = (MGWIN *) malloc(sizeof(MGWIN)); /* Initial window. */
+ bp = bfind("*scratch*", TRUE); /* Text buffer. */
+ wp = (MGWIN *)malloc(sizeof(MGWIN)); /* Initial window. */
if (bp == NULL || wp == NULL)
panic("edinit");
- curbp = bp; /* Current ones. */
+ curbp = bp; /* Current ones. */
wheadp = wp;
curwp = wp;
- wp->w_wndp = NULL; /* Initialize window. */
+ wp->w_wndp = NULL; /* Initialize window. */
wp->w_bufp = bp;
- bp->b_nwnd = 1; /* Displayed. */
+ 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_ntrows = nrow - 2; /* 2 = mode, echo. */
wp->w_force = 0;
- wp->w_flag = WFMODE | WFHARD; /* Full. */
+ 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".
+ * 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 */
+int
quit(f, n)
+ int f, n;
{
- register int s;
- VOID vttidy();
+ int s;
if ((s = anycb(FALSE)) == ABORT)
return ABORT;
if (s == FALSE
|| eyesno("Some modified buffers exist, really exit") == TRUE) {
vttidy();
-#ifdef SYSCLEANUP
+#ifdef SYSCLEANUP
SYSCLEANUP;
-#endif
+#endif /* SYSCLEANUP */
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.
+ * 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 */
int
diff --git a/usr.bin/mg/match.c b/usr.bin/mg/match.c
index e5eacf2465f..fb7a2908750 100644
--- a/usr.bin/mg/match.c
+++ b/usr.bin/mg/match.c
@@ -1,32 +1,30 @@
/*
- * Name: MicroEMACS
- * Limited parenthesis matching routines
+ * Limited parenthesis matching routines
*
- * The hacks in this file implement automatic matching
- * of (), [], {}, and other characters. It would be
- * better to have a full-blown syntax table, but there's
- * enough overhead in the editor as it is.
+ * The hacks in this file implement automatic matching * of (), [], {}, and
+ * other characters. It would be better to have a full-blown syntax table,
+ * but there's enough overhead in the editor as it is.
*
- * Since I often edit Scribe code, I've made it possible to
- * blink arbitrary characters -- just bind delimiter characters
- * to "blink-matching-paren-hack"
+ * Since I often edit Scribe code, I've made it possible to blink arbitrary
+ * characters -- just bind delimiter characters to "blink-matching-paren-hack"
*/
-#include "def.h"
-#include "key.h"
-static int balance();
-static VOID displaymatch();
+#include "def.h"
+#include "key.h"
+
+static int balance __P((void));
+static VOID displaymatch __P((LINE *, int));
/*
* Balance table. When balance() encounters a character that is to be
* matched, it first searches this table for a balancing left-side character.
- * f the character is not in the table, the character is balanced by itself.
+ * If the character is not in the table, the character is balanced by itself.
* This is to allow delimiters in Scribe documents to be matched.
*/
static struct balance {
- char left, right;
-} bal[] = {
+ char left, right;
+} bal[] = {
{
'(', ')'
},
@@ -45,20 +43,22 @@ static struct balance {
};
/*
- * Self-insert character, then show matching character,
- * if any. Bound to "blink-matching-paren-command".
+ * Hack to show matching paren. Self-insert character, then show matching
+ * character, if any. Bound to "blink-matching-paren-command".
*/
-
+int
showmatch(f, n)
+ int f, n;
{
- register int i, s;
+ int i, s;
if (f & FFRAND)
return FALSE;
for (i = 0; i < n; i++) {
if ((s = selfinsert(FFRAND, 1)) != TRUE)
return s;
- if (balance() != TRUE) /* unbalanced -- warn user */
+ /* unbalanced -- warn user */
+ if (balance() != TRUE)
ttbeep();
}
return TRUE;
@@ -72,51 +72,56 @@ showmatch(f, n)
* is found, it uses displaymatch() to display the match.
*/
-static
+static int
balance()
{
- register LINE *clp;
- register int cbo;
- int c;
- int i;
- int rbal, lbal;
- int depth;
+ LINE *clp;
+ int cbo;
+ int c;
+ int i;
+ int rbal;
+ int lbal;
+ int depth;
rbal = key.k_chars[key.k_count - 1];
/* See if there is a matching character -- default to the same */
-
lbal = rbal;
for (i = 0; bal[i].right != '\0'; i++)
if (bal[i].right == rbal) {
lbal = bal[i].left;
break;
}
- /* Move behind the inserted character. We are always guaranteed */
- /* that there is at least one character on the line, since one was */
- /* just self-inserted by blinkparen. */
+ /*
+ * Move behind the inserted character. We are always guaranteed
+ * that there is at least one character on the line, since one was
+ * just self-inserted by blinkparen.
+ */
clp = curwp->w_dotp;
cbo = curwp->w_doto - 1;
- depth = 0; /* init nesting depth */
+ /* init nesting depth */
+ depth = 0;
for (;;) {
- if (cbo == 0) { /* beginning of line */
- clp = lback(clp);
+ if (cbo == 0) {
+ clp = lback(clp); /* beginning of line */
if (clp == curbp->b_linep)
return (FALSE);
cbo = llength(clp) + 1;
}
- if (--cbo == llength(clp)) /* end of line */
- c = '\n';
+ if (--cbo == llength(clp))
+ c = '\n'; /* end of line */
else
- c = lgetc(clp, cbo); /* somewhere in middle */
-
- /* Check for a matching character. If still in a nested */
- /* level, pop out of it and continue search. This check */
- /* is done before the nesting check so single-character */
- /* matches will work too. */
+ c = lgetc(clp, cbo); /* somewhere in middle */
+
+ /*
+ * Check for a matching character. If still in a nested
+ * level, pop out of it and continue search. This check
+ * is done before the nesting check so single-character
+ * matches will work too.
+ */
if (c == lbal) {
if (depth == 0) {
displaymatch(clp, cbo);
@@ -133,56 +138,56 @@ balance()
/*
- * Display matching character.
- * Matching characters that are not in the current window
- * are displayed in the echo line. If in the current
- * window, move dot to the matching character,
- * sit there a while, then move back.
+ * Display matching character. Matching characters that are not in the
+ * current window are displayed in the echo line. If in the current window,
+ * move dot to the matching character, sit there a while, then move back.
*/
-static VOID
+static VOID
displaymatch(clp, cbo)
- register LINE *clp;
- register int cbo;
+ LINE *clp;
+ int cbo;
{
- register LINE *tlp;
- register int tbo;
- register int cp;
- register int bufo;
- register int c;
- int inwindow;
- char buf[NLINE];
-
- /* Figure out if matching char is in current window by */
- /* searching from the top of the window to dot. */
-
+ LINE *tlp;
+ int tbo;
+ int cp;
+ int bufo;
+ int c;
+ int inwindow;
+ char buf[NLINE];
+
+ /*
+ * Figure out if matching char is in current window by
+ * searching from the top of the window to dot.
+ */
inwindow = FALSE;
- for (tlp = curwp->w_linep; tlp != lforw(curwp->w_dotp); tlp = lforw(tlp))
+ for (tlp = curwp->w_linep; tlp != lforw(curwp->w_dotp);
+ tlp = lforw(tlp))
if (tlp == clp)
inwindow = TRUE;
if (inwindow == TRUE) {
- tlp = curwp->w_dotp; /* save current position */
+ tlp = curwp->w_dotp; /* save current position */
tbo = curwp->w_doto;
- curwp->w_dotp = clp; /* move to new position */
+ curwp->w_dotp = clp; /* move to new position */
curwp->w_doto = cbo;
curwp->w_flag |= WFMOVE;
- update(); /* show match */
- sleep(1); /* wait a bit */
+ update(); /* show match */
+ sleep(1); /* wait a bit */
- curwp->w_dotp = tlp; /* return to old position */
+ curwp->w_dotp = tlp; /* return to old position */
curwp->w_doto = tbo;
curwp->w_flag |= WFMOVE;
update();
- } else { /* match not in this window so display line
- * in echo area */
+ } else {
+ /* match is not in this window, so display line in echo area */
bufo = 0;
- for (cp = 0; cp < llength(clp); cp++) { /* expand tabs */
+ for (cp = 0; cp < llength(clp); cp++) {
c = lgetc(clp, cp);
if (c != '\t'
-#ifdef NOTAB
+#ifdef NOTAB
|| (curbp->b_flag & BFNOTAB)
#endif
)
diff --git a/usr.bin/mg/modes.c b/usr.bin/mg/modes.c
index 856bcc9d517..e9223fc2f3f 100644
--- a/usr.bin/mg/modes.c
+++ b/usr.bin/mg/modes.c
@@ -1,22 +1,25 @@
/*
- * Commands to toggle modes. Without an argument, toggle mode.
- * Negitive or zero argument, mode off. Positive argument, mode on.
+ * Commands to toggle modes. Without an argument, these functions will
+ * toggle the given mode. A negative or zero argument will turn the mode
+ * off. A positive argument will turn the mode on.
*/
#include "def.h"
#include "kbd.h"
-int defb_nmodes = 0;
-MAPS *defb_modes[PBMODES] = {&map_table[0]};
-int defb_flag = 0;
+static int changemode __P((int, int, char *));
+
+int defb_nmodes = 0;
+MAPS *defb_modes[PBMODES] = { &map_table[0] };
+int defb_flag = 0;
static int
changemode(f, n, mode)
- int f, n;
- char *mode;
+ int f, n;
+ char *mode;
{
- register int i;
- MAPS *m;
+ int i;
+ MAPS *m;
if ((m = name_mode(mode)) == NULL) {
ewprintf("Can't find mode %s", mode);
@@ -25,14 +28,16 @@ changemode(f, n, mode)
if (!(f & FFARG)) {
for (i = 0; i <= curbp->b_nmodes; i++)
if (curbp->b_modes[i] == m) {
- n = 0; /* mode already set */
+ /* mode already set */
+ n = 0;
break;
}
}
if (n > 0) {
for (i = 0; i <= curbp->b_nmodes; i++)
if (curbp->b_modes[i] == m)
- return TRUE; /* mode already set */
+ /* mode already set */
+ return TRUE;
if (curbp->b_nmodes >= PBMODES - 1) {
ewprintf("Too many modes");
return FALSE;
@@ -40,8 +45,8 @@ changemode(f, n, mode)
curbp->b_modes[++(curbp->b_nmodes)] = m;
} else {
/* fundamental is b_modes[0] and can't be unset */
- for (i = 1; i <= curbp->b_nmodes && m != curbp->b_modes[i]; i++) {
- }
+ for (i = 1; i <= curbp->b_nmodes && m != curbp->b_modes[i];
+ i++);
if (i > curbp->b_nmodes)
return TRUE; /* mode wasn't set */
for (; i < curbp->b_nmodes; i++)
@@ -52,12 +57,16 @@ changemode(f, n, mode)
return TRUE;
}
+int
indentmode(f, n)
+ int f, n;
{
return changemode(f, n, "indent");
}
+int
fillmode(f, n)
+ int f, n;
{
return changemode(f, n, "fill");
}
@@ -65,13 +74,17 @@ fillmode(f, n)
/*
* Fake the GNU "blink-matching-paren" variable.
*/
+int
blinkparen(f, n)
+ int f, n;
{
return changemode(f, n, "blink");
}
-#ifdef NOTAB
+#ifdef NOTAB
+int
notabmode(f, n)
+ int f, n;
{
if (changemode(f, n, "notab") == FALSE)
return FALSE;
@@ -84,10 +97,11 @@ notabmode(f, n)
curbp->b_flag ^= BFNOTAB;
return TRUE;
}
-#endif
+#endif /* NOTAB */
+int
overwrite(f, n)
- int f, n;
+ int f, n;
{
if (changemode(f, n, "overwrite") == FALSE)
return FALSE;
@@ -101,12 +115,13 @@ overwrite(f, n)
return TRUE;
}
+int
set_default_mode(f, n)
- int f, n;
+ int f, n;
{
- register int i;
- register MAPS *m;
- char mode[32];
+ int i;
+ MAPS *m;
+ char mode[32];
if (eread("Set Default Mode: ", mode, 32, EFNEW) != TRUE)
return ABORT;
@@ -117,14 +132,16 @@ set_default_mode(f, n)
if (!(f & FFARG)) {
for (i = 0; i <= defb_nmodes; i++)
if (defb_modes[i] == m) {
- n = 0; /* mode already set */
+ /* mode already set */
+ n = 0;
break;
}
}
if (n > 0) {
for (i = 0; i <= defb_nmodes; i++)
if (defb_modes[i] == m)
- return TRUE; /* mode already set */
+ /* mode already set */
+ return TRUE;
if (defb_nmodes >= PBMODES - 1) {
ewprintf("Too many modes");
return FALSE;
@@ -132,25 +149,26 @@ set_default_mode(f, n)
defb_modes[++defb_nmodes] = m;
} else {
/* fundamental is defb_modes[0] and can't be unset */
- for (i = 1; i <= defb_nmodes && m != defb_modes[i]; i++) {
- }
+ for (i = 1; i <= defb_nmodes && m != defb_modes[i]; i++);
if (i > defb_nmodes)
- return TRUE; /* mode wasn't set */
+ /* mode was not set */
+ return TRUE;
for (; i < defb_nmodes; i++)
defb_modes[i] = defb_modes[i + 1];
defb_nmodes--;
}
- if (strcmp(mode, "overwrite") == 0)
- if (n <= 0)
+ if (strcmp(mode, "overwrite") == 0) {
+ if (n <= 0)
defb_flag &= ~BFOVERWRITE;
- else
+ else
defb_flag |= BFOVERWRITE;
+ }
#ifdef NOTAB
if (strcmp(mode, "notab") == 0)
if (n <= 0)
defb_flag &= ~BFNOTAB;
else
defb_flag |= BFNOTAB;
-#endif
+#endif /* NOTAB */
return TRUE;
}
diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c
index 8e1536dfe0d..f4e44042b91 100644
--- a/usr.bin/mg/paragraph.c
+++ b/usr.bin/mg/paragraph.c
@@ -2,29 +2,33 @@
* Code for dealing with paragraphs and filling. Adapted from MicroEMACS 3.6
* and GNU-ified by mwm@ucbvax. Several bug fixes by blarson@usc-oberon.
*/
+
#include "def.h"
-static int fillcol = 70;
+static int fillcol = 70;
+
#define MAXWORD 256
/*
- * go back to the begining of the current paragraph
- * here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
- * combination to delimit the begining of a paragraph
+ * Move to start of paragraph. Go back to the begining of the current
+ * paragraph here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
+ * combination to delimit the begining of a paragraph.
*/
/* ARGSUSED */
+int
gotobop(f, n)
+ int f, n;
{
- if (n < 0) /* the other way... */
+ /* the other way... */
+ if (n < 0)
return gotoeop(f, -n);
- while (n-- > 0) { /* for each one asked for */
-
+ while (n-- > 0) {
/* first scan back until we are in a word */
+ while (backchar(FFRAND, 1) && inword() == NULL);
- while (backchar(FFRAND, 1) && !inword()) {
- }
- curwp->w_doto = 0; /* and go to the B-O-Line */
+ /* and go to the B-O-Line */
+ curwp->w_doto = 0;
/*
* and scan back until we hit a <NL><SP> <NL><TAB> or
@@ -45,36 +49,43 @@ gotobop(f, n)
* beond end of buffer,
* cleanup time
*/
- curwp->w_dotp = lback(curwp->w_dotp);
- curwp->w_doto = llength(curwp->w_dotp);
+ curwp->w_dotp =
+ lback(curwp->w_dotp);
+ curwp->w_doto =
+ llength(curwp->w_dotp);
}
}
break;
}
}
- curwp->w_flag |= WFMOVE;/* force screen update */
+ /* force screen update */
+ curwp->w_flag |= WFMOVE;
return TRUE;
}
/*
- * go forword to the end of the current paragraph
- * here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
- * combination to delimit the begining of a paragraph
+ * Move to end of paragraph. Go forword to the end of the current paragraph
+ * here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE> combination to
+ * delimit the begining of a paragraph.
*/
/* ARGSUSED */
+int
gotoeop(f, n)
+ int f, n;
{
- if (n < 0) /* the other way... */
+ /* the other way... */
+ if (n < 0)
return gotobop(f, -n);
- while (n-- > 0) { /* for each one asked for */
-
+ /* for each one asked for */
+ while (n-- > 0) {
/* Find the first word on/after the current line */
curwp->w_doto = 0;
- while (forwchar(FFRAND, 1) && !inword()) {
- }
+ while (forwchar(FFRAND, 1) && inword() == NULL);
+
curwp->w_doto = 0;
curwp->w_dotp = lforw(curwp->w_dotp);
+
/* and scan forword until we hit a <NL><SP> or ... */
while (curwp->w_dotp != curbp->b_linep) {
if (llength(curwp->w_dotp)
@@ -92,43 +103,46 @@ gotoeop(f, n)
break;
}
}
- curwp->w_flag |= WFMOVE;/* force screen update */
+ /* force screen update */
+ curwp->w_flag |= WFMOVE;
return TRUE;
}
/*
- * Fill the current paragraph according to the current
- * fill column
+ * Justify a paragraph. Fill the current paragraph according to the current
+ * fill column.
*/
/* ARGSUSED */
+int
fillpara(f, n)
+ int f, n;
{
- register int c; /* current char durring scan */
- register int wordlen;/* length of current word */
- register int clength;/* position on line during fill */
- register int i; /* index during word copy */
- register int eopflag;/* Are we at the End-Of-Paragraph? */
- int firstflag; /* first word? (needs no space) */
- int newlength; /* tentative new line length */
- int eolflag;/* was at end of line */
- LINE *eopline;/* pointer to line just past EOP */
- char wbuf[MAXWORD]; /* buffer for current word */
+ int c; /* current char durring scan */
+ int wordlen; /* length of current word */
+ int clength; /* position on line during fill */
+ int i; /* index during word copy */
+ int eopflag; /* Are we at the End-Of-Paragraph? */
+ int firstflag; /* first word? (needs no space) */
+ int newlength; /* tentative new line length */
+ int eolflag; /* was at end of line */
+ LINE *eopline; /* pointer to line just past EOP */
+ char wbuf[MAXWORD]; /* buffer for current word */
/* record the pointer to the line just past the EOP */
- (VOID) gotoeop(FFRAND, 1);
+ (VOID)gotoeop(FFRAND, 1);
if (curwp->w_doto != 0) {
/* paragraph ends at end of buffer */
- (VOID) lnewline();
+ (VOID)lnewline();
eopline = lforw(curwp->w_dotp);
} else
eopline = curwp->w_dotp;
/* and back top the begining of the paragraph */
- (VOID) gotobop(FFRAND, 1);
+ (VOID)gotobop(FFRAND, 1);
/* initialize various info */
- while (!inword() && forwchar(FFRAND, 1)) {
- }
+ while (inword() == NULL && forwchar(FFRAND, 1));
+
clength = curwp->w_doto;
wordlen = 0;
@@ -136,8 +150,9 @@ fillpara(f, n)
firstflag = TRUE;
eopflag = FALSE;
while (!eopflag) {
+
/* get the next character in the paragraph */
- if (eolflag = (curwp->w_doto == llength(curwp->w_dotp))) {
+ if ((eolflag = (curwp->w_doto == llength(curwp->w_dotp)))) {
c = ' ';
if (lforw(curwp->w_dotp) == eopline)
eopflag = TRUE;
@@ -162,23 +177,26 @@ fillpara(f, n)
ewprintf("Word too long!");
}
} else if (wordlen) {
+
/* calculate tenatitive new length with word added */
newlength = clength + 1 + wordlen;
+
/*
* if at end of line or at doublespace and previous
* character was one of '.','?','!' doublespace here.
*/
- if ((eolflag || curwp->w_doto == llength(curwp->w_dotp)
- || (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
- || c == '\t')
- && ISEOSP(wbuf[wordlen - 1])
- && wordlen < MAXWORD - 1)
+ if ((eolflag ||
+ curwp->w_doto == llength(curwp->w_dotp) ||
+ (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
+ || c == '\t') && ISEOSP(wbuf[wordlen - 1]) &&
+ wordlen < MAXWORD - 1)
wbuf[wordlen++] = ' ';
+
/* at a word break with a word waiting */
if (newlength <= fillcol) {
/* add word to current line */
if (!firstflag) {
- (VOID) linsert(1, ' ');
+ (VOID)linsert(1, ' ');
++clength;
}
firstflag = FALSE;
@@ -186,77 +204,87 @@ fillpara(f, n)
if (curwp->w_doto > 0 &&
lgetc(curwp->w_dotp, curwp->w_doto - 1) == ' ') {
curwp->w_doto -= 1;
- (VOID) ldelete((RSIZE) 1, KNONE);
+ (VOID)ldelete((RSIZE) 1, KNONE);
}
/* start a new line */
- (VOID) lnewline();
+ (VOID)lnewline();
clength = 0;
}
/* and add the word in in either case */
for (i = 0; i < wordlen; i++) {
- (VOID) linsert(1, wbuf[i]);
+ (VOID)linsert(1, wbuf[i]);
++clength;
}
wordlen = 0;
}
}
/* and add a last newline for the end of our new paragraph */
- (VOID) lnewline();
+ (VOID)lnewline();
+
/*
* we realy should wind up where we started, (which is hard to keep
* track of) but I think the end of the last line is better than the
* begining of the blank line.
*/
- (VOID) backchar(FFRAND, 1);
+ (VOID)backchar(FFRAND, 1);
return TRUE;
}
-/* delete n paragraphs starting with the current one */
+/*
+ * Delete a paragraph. Delete n paragraphs starting with the current one.
+ */
/* ARGSUSED */
+int
killpara(f, n)
+ int f, n;
{
- register int status; /* returned status of functions */
+ int status; /* returned status of functions */
- while (n--) { /* for each paragraph to delete */
+ /* for each paragraph to delete */
+ while (n--) {
/* mark out the end and begining of the para to delete */
- (VOID) gotoeop(FFRAND, 1);
+ (VOID)gotoeop(FFRAND, 1);
/* set the mark here */
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto;
/* go to the begining of the paragraph */
- (VOID) gotobop(FFRAND, 1);
- curwp->w_doto = 0; /* force us to the begining of line */
+ (VOID)gotobop(FFRAND, 1);
+
+ /* force us to the beginning of line */
+ curwp->w_doto = 0;
/* and delete it */
if ((status = killregion(FFRAND, 1)) != TRUE)
return status;
/* and clean up the 2 extra lines */
- (VOID) ldelete((RSIZE) 1, KFORW);
+ (VOID)ldelete((RSIZE) 1, KFORW);
}
return TRUE;
}
/*
- * check to see if we're past fillcol, and if so,
- * justify this line. As a last step, justify the line.
+ * Insert char with work wrap. Check to see if we're past fillcol, and if so,
+ * justify this line. As a last step, justify the line.
*/
/* ARGSUSED */
+int
fillword(f, n)
+ int f, n;
{
- register char c;
- register int col, i, nce;
+ char c;
+ int col, i, nce;
for (i = col = 0; col <= fillcol; ++i, ++col) {
if (i == curwp->w_doto)
return selfinsert(f, n);
c = lgetc(curwp->w_dotp, i);
if (c == '\t'
-#ifdef NOTAB
+#ifdef NOTAB
&& !(curbp->b_flag & BFNOTAB)
#endif
)
@@ -265,7 +293,7 @@ fillword(f, n)
++col;
}
if (curwp->w_doto != llength(curwp->w_dotp)) {
- (VOID) selfinsert(f, n);
+ (VOID)selfinsert(f, n);
nce = llength(curwp->w_dotp) - curwp->w_doto;
} else
nce = 0;
@@ -273,18 +301,18 @@ fillword(f, n)
if ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' && c != '\t')
do {
- (VOID) backchar(FFRAND, 1);
+ (VOID)backchar(FFRAND, 1);
} while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' '
- && c != '\t' && curwp->w_doto > 0);
+ && c != '\t' && curwp->w_doto > 0);
if (curwp->w_doto == 0)
do {
- (VOID) forwchar(FFRAND, 1);
+ (VOID)forwchar(FFRAND, 1);
} while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' '
&& c != '\t' && curwp->w_doto < llength(curwp->w_dotp));
- (VOID) delwhite(FFRAND, 1);
- (VOID) lnewline();
+ (VOID)delwhite(FFRAND, 1);
+ (VOID)lnewline();
i = llength(curwp->w_dotp) - nce;
curwp->w_doto = i > 0 ? i : 0;
curwp->w_flag |= WFMOVE;
@@ -293,11 +321,13 @@ fillword(f, n)
return TRUE;
}
-/* Set fill column to n. */
+/*
+ * Set fill column to n for justify.
+ */
+int
setfillcol(f, n)
+ int f, n;
{
- extern int getcolpos();
-
fillcol = ((f & FFARG) ? n : getcolpos());
ewprintf("Fill column set to %d", fillcol);
return TRUE;
diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c
index c10aa2d5127..d3b49179946 100644
--- a/usr.bin/mg/random.c
+++ b/usr.bin/mg/random.c
@@ -1,51 +1,61 @@
/*
* Assorted commands.
- * The file contains the command
- * processors for a large assortment of unrelated
- * commands. The only thing they have in common is
- * that they are all command processors.
+ * This file contains the command processors for a large assortment of
+ * unrelated commands. The only thing they have in common is that they
+ * are all command processors.
*/
-#include "def.h"
+
+#include "def.h"
/*
- * Display a bunch of useful information about
- * the current location of dot. The character under the
- * cursor (in octal), the current line, row, and column, and
- * approximate position of the cursor in the file (as a percentage)
- * is displayed. The column position assumes an infinite position
- * display; it does not truncate just because the screen does.
+ * Display a bunch of useful information about the current location of dot.
+ * The character under the cursor (in octal), the current line, row, and
+ * column, and approximate position of the cursor in the file (as a
+ * percentage) is displayed. The column position assumes an infinite
+ * position display; it does not truncate just because the screen does.
* This is normally bound to "C-X =".
*/
/* ARGSUSED */
+int
showcpos(f, n)
+ int f, n;
{
- register LINE *clp;
- register long nchar;
- long cchar;
- register int nline, row;
- int cline, cbyte; /* Current line/char/byte */
- int ratio;
-
- clp = lforw(curbp->b_linep); /* Collect the data. */
+ LINE *clp;
+ long nchar;
+ long cchar;
+ int nline, row;
+ int cline, cbyte; /* Current line/char/byte */
+ int ratio;
+
+ /* collect the data */
+ clp = lforw(curbp->b_linep);
+ cchar = 0;
+ cline = 0;
+ cbyte = 0;
nchar = 0;
nline = 0;
- for (;;) {
- ++nline; /* Count this line */
+ for (;;) {
+ /* count this line */
+ ++nline;
if (clp == curwp->w_dotp) {
- cline = nline; /* Mark line */
+ /* mark line */
+ cline = nline;
cchar = nchar + curwp->w_doto;
if (curwp->w_doto == llength(clp))
cbyte = '\n';
else
cbyte = lgetc(clp, curwp->w_doto);
}
- nchar += llength(clp); /* Now count the chars */
+ /* now count the chars */
+ nchar += llength(clp);
clp = lforw(clp);
if (clp == curbp->b_linep)
break;
- nchar++; /* count the newline */
+ /* count the newline */
+ nchar++;
}
- row = curwp->w_toprow + 1; /* Determine row. */
+ /* determine row */
+ row = curwp->w_toprow + 1;
clp = curwp->w_linep;
while (clp != curbp->b_linep && clp != curwp->w_dotp) {
++row;
@@ -54,21 +64,24 @@ showcpos(f, n)
/* NOSTRICT */
ratio = nchar ? (100L * cchar) / nchar : 100;
ewprintf("Char: %c (0%o) point=%ld(%d%%) line=%d row=%d col=%d",
- cbyte, cbyte, cchar, ratio, cline, row, getcolpos());
+ cbyte, cbyte, cchar, ratio, cline, row, getcolpos());
return TRUE;
}
+int
getcolpos()
{
- register int col, i, c;
+ int col, i, c;
+
+ /* determine column */
+ col = 1;
- col = 1; /* Determine column. */
for (i = 0; i < curwp->w_doto; ++i) {
c = lgetc(curwp->w_dotp, i);
if (c == '\t'
-#ifdef NOTAB
+#ifdef NOTAB
&& !(curbp->b_flag & BFNOTAB)
-#endif
+#endif /* NOTAB */
) {
col |= 0x07;
++col;
@@ -78,23 +91,22 @@ getcolpos()
}
return col;
}
+
/*
- * Twiddle the two characters on either side of
- * dot. If dot is at the end of the line twiddle the
- * two characters before it. Return with an error if dot
- * is at the beginning of line; it seems to be a bit
- * pointless to make this work. This fixes up a very
- * common typo with a single stroke. Normally bound
- * to "C-T". This always works within a line, so
- * "WFEDIT" is good enough.
+ * Twiddle the two characters on either side of dot. If dot is at the end
+ * of the line twiddle the two characters before it. Return with an error
+ * if dot is at the beginning of line; it seems to be a bit pointless to
+ * make this work. This fixes up a very common typo with a single stroke.
+ * Normally bound to "C-T". This always works within a line, so "WFEDIT"
+ * is good enough.
*/
/* ARGSUSED */
+int
twiddle(f, n)
+ int f, n;
{
- register LINE *dotp;
- register int doto;
- register int cr;
- VOID lchange();
+ LINE *dotp;
+ int doto, cr;
dotp = curwp->w_dotp;
doto = curwp->w_doto;
@@ -114,51 +126,55 @@ twiddle(f, n)
}
/*
- * Open up some blank space. The basic plan
- * is to insert a bunch of newlines, and then back
- * up over them. Everything is done by the subcommand
- * procerssors. They even handle the looping. Normally
- * this is bound to "C-O".
+ * Open up some blank space. The basic plan is to insert a bunch of
+ * newlines, and then back up over them. Everything is done by the
+ * subcommand procerssors. They even handle the looping. Normally this
+ * is bound to "C-O".
*/
/* ARGSUSED */
+int
openline(f, n)
+ int f, n;
{
- register int i;
- register int s;
+ int i;
+ int s;
if (n < 0)
return FALSE;
if (n == 0)
return TRUE;
- i = n; /* Insert newlines. */
+
+ /* insert newlines */
+ i = n;
do {
s = lnewline();
} while (s == TRUE && --i);
- if (s == TRUE) /* Then back up overtop */
- s = backchar(f | FFRAND, n); /* of them all. */
+
+ /* then go back up overtop of them all */
+ if (s == TRUE)
+ s = backchar(f | FFRAND, n);
return s;
}
/*
- * Insert a newline.
- * [following "feature" not present in current version of
- * Gnu, and now disabled here too]
- * If you are at the end of the line and the
- * next line is a blank line, just move into the
- * blank line. This makes "C-O" and "C-X C-O" work
- * nicely, and reduces the ammount of screen
- * update that has to be done. This would not be
- * as critical if screen update were a lot
- * more efficient.
+ * Insert a newline. [following "feature" not present in current version of
+ * Gnu, and now disabled here too] If you are at the end of the line and the
+ * next line is a blank line, just move into the blank line. This makes
+ * "C-O" and "C-X C-O" work nicely, and reduces the ammount of screen update
+ * that has to be done. This would not be as critical if screen update were a
+ * lot more efficient.
*/
/* ARGSUSED */
+int
newline(f, n)
+ int f, n;
{
- register LINE *lp;
- register int s;
+ LINE *lp;
+ int s;
if (n < 0)
return FALSE;
+
while (n--) {
lp = curwp->w_dotp;
#ifdef undef
@@ -168,7 +184,7 @@ newline(f, n)
if ((s = forwchar(FFRAND, 1)) != TRUE)
return s;
} else
-#endif
+#endif /* undef */
if ((s = lnewline()) != TRUE)
return s;
}
@@ -176,53 +192,58 @@ newline(f, n)
}
/*
- * Delete blank lines around dot.
- * What this command does depends if dot is
- * sitting on a blank line. If dot is sitting on a
- * blank line, this command deletes all the blank lines
- * above and below the current line. If it is sitting
- * on a non blank line then it deletes all of the
- * blank lines after the line. Normally this command
- * is bound to "C-X C-O". Any argument is ignored.
+ * Delete blank lines around dot. What this command does depends if dot is
+ * sitting on a blank line. If dot is sitting on a blank line, this command
+ * deletes all the blank lines above and below the current line. If it is
+ * sitting on a non blank line then it deletes all of the blank lines after
+ * the line. Normally this command is bound to "C-X C-O". Any argument is
+ * ignored.
*/
/* ARGSUSED */
+int
deblank(f, n)
+ int f, n;
{
- register LINE *lp1;
- register LINE *lp2;
- register RSIZE nld;
+ LINE *lp1, *lp2;
+ RSIZE nld;
lp1 = curwp->w_dotp;
while (llength(lp1) == 0 && (lp2 = lback(lp1)) != curbp->b_linep)
lp1 = lp2;
lp2 = lp1;
- nld = (RSIZE) 0;
+ nld = (RSIZE)0;
while ((lp2 = lforw(lp2)) != curbp->b_linep && llength(lp2) == 0)
++nld;
if (nld == 0)
return (TRUE);
curwp->w_dotp = lforw(lp1);
curwp->w_doto = 0;
- return ldelete((RSIZE) nld, KNONE);
+ return ldelete((RSIZE)nld, KNONE);
}
/*
* Delete any whitespace around dot, then insert a space.
*/
+int
justone(f, n)
+ int f, n;
{
- (VOID) delwhite(f, n);
+ (VOID)delwhite(f, n);
return linsert(1, ' ');
}
+
/*
* Delete any whitespace around dot.
*/
/* ARGSUSED */
+int
delwhite(f, n)
+ int f, n;
{
- register int col, c, s;
+ int col, c, s;
col = curwp->w_doto;
+
while (((c = lgetc(curwp->w_dotp, col)) == ' ' || c == '\t')
&& col < llength(curwp->w_dotp))
++col;
@@ -236,31 +257,31 @@ delwhite(f, n)
} while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ' || c == '\t');
if (s == TRUE)
- (VOID) forwchar(FFRAND, 1);
- (VOID) ldelete((RSIZE) (col - curwp->w_doto), KNONE);
+ (VOID)forwchar(FFRAND, 1);
+ (VOID)ldelete((RSIZE)(col - curwp->w_doto), KNONE);
return TRUE;
}
+
/*
- * Insert a newline, then enough
- * tabs and spaces to duplicate the indentation
- * of the previous line. Assumes tabs are every eight
- * characters. Quite simple. Figure out the indentation
- * of the current line. Insert a newline by calling
- * the standard routine. Insert the indentation by
- * inserting the right number of tabs and spaces.
- * Return TRUE if all ok. Return FALSE if one
- * of the subcomands failed. Normally bound
- * to "C-J".
+ * Insert a newline, then enough tabs and spaces to duplicate the indentation
+ * of the previous line. Assumes tabs are every eight characters. Quite
+ * simple. Figure out the indentation of the current line. Insert a newline
+ * by calling the standard routine. Insert the indentation by inserting the
+ * right number of tabs and spaces. Return TRUE if all ok. Return FALSE if
+ * one of the subcomands failed. Normally bound to "C-J".
*/
/* ARGSUSED */
+int
indent(f, n)
+ int f, n;
{
- register int nicol;
- register int c;
- register int i;
+ int nicol;
+ int c;
+ int i;
if (n < 0)
return (FALSE);
+
while (n--) {
nicol = 0;
for (i = 0; i < llength(curwp->w_dotp); ++i) {
@@ -273,83 +294,87 @@ indent(f, n)
}
if (lnewline() == FALSE || ((
#ifdef NOTAB
- curbp->b_flag & BFNOTAB) ?
- linsert(nicol, ' ') == FALSE : (
-#endif
- ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) ||
- ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE))))
+ curbp->b_flag & BFNOTAB) ? linsert(nicol, ' ') == FALSE : (
+#endif /* NOTAB */
+ ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) ||
+ ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE))))
return FALSE;
}
return TRUE;
}
/*
- * Delete forward. This is real
- * easy, because the basic delete routine does
- * all of the work. Watches for negative arguments,
- * and does the right thing. If any argument is
- * present, it kills rather than deletes, to prevent
- * loss of text if typed with a big argument.
- * Normally bound to "C-D".
+ * Delete forward. This is real easy, because the basic delete routine does
+ * all of the work. Watches for negative arguments, and does the right thing.
+ * If any argument is present, it kills rather than deletes, to prevent loss
+ * of text if typed with a big argument. Normally bound to "C-D".
*/
/* ARGSUSED */
+int
forwdel(f, n)
+ int f, n;
{
if (n < 0)
return backdel(f | FFRAND, -n);
- if (f & FFARG) { /* Really a kill. */
+
+ /* really a kill */
+ if (f & FFARG) {
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
}
+
return ldelete((RSIZE) n, (f & FFARG) ? KFORW : KNONE);
}
/*
- * Delete backwards. This is quite easy too,
- * because it's all done with other functions. Just
- * move the cursor back, and delete forwards.
- * Like delete forward, this actually does a kill
- * if presented with an argument.
+ * Delete backwards. This is quite easy too, because it's all done with
+ * other functions. Just move the cursor back, and delete forwards. Like
+ * delete forward, this actually does a kill if presented with an argument.
*/
/* ARGSUSED */
+int
backdel(f, n)
+ int f, n;
{
- register int s;
+ int s;
if (n < 0)
return forwdel(f | FFRAND, -n);
- if (f & FFARG) { /* Really a kill. */
+
+ /* really a kill */
+ if (f & FFARG) {
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
}
if ((s = backchar(f | FFRAND, n)) == TRUE)
- s = ldelete((RSIZE) n, (f & FFARG) ? KFORW : KNONE);
+ s = ldelete((RSIZE)n, (f & FFARG) ? KFORW : KNONE);
+
return s;
}
/*
- * Kill line. If called without an argument,
- * it kills from dot to the end of the line, unless it
- * is at the end of the line, when it kills the newline.
- * If called with an argument of 0, it kills from the
- * start of the line to dot. If called with a positive
- * argument, it kills from dot forward over that number
- * of newlines. If called with a negative argument it
- * kills any text before dot on the current line,
- * then it kills back abs(arg) lines.
+ * Kill line. If called without an argument, it kills from dot to the end
+ * of the line, unless it is at the end of the line, when it kills the
+ * newline. If called with an argument of 0, it kills from the start of the
+ * line to dot. If called with a positive argument, it kills from dot
+ * forward over that number of newlines. If called with a negative argument
+ * it kills any text before dot on the current line, then it kills back
+ * abs(arg) lines.
*/
/* ARGSUSED */
+int
killline(f, n)
+ int f, n;
{
- register RSIZE chunk;
- register LINE *nextp;
- register int i, c;
- VOID kdelete();
+ LINE *nextp;
+ RSIZE chunk;
+ int i, c;
- if ((lastflag & CFKILL) == 0) /* Clear kill buffer if */
- kdelete(); /* last wasn't a kill. */
+ /* clear kill buffer if last wasn't a kill */
+ if ((lastflag & CFKILL) == 0)
+ kdelete();
thisflag |= CFKILL;
if (!(f & FFARG)) {
for (i = curwp->w_doto; i < llength(curwp->w_dotp); ++i)
@@ -372,7 +397,8 @@ killline(f, n)
chunk += llength(nextp) + 1;
nextp = lforw(nextp);
}
- } else { /* n <= 0 */
+ } else {
+ /* n <= 0 */
chunk = curwp->w_doto;
curwp->w_doto = 0;
i = n;
@@ -385,41 +411,39 @@ killline(f, n)
}
}
/*
- * KFORW here is a bug. Should be KBACK/KFORW, but we need to
+ * KFORW here is a bug. Should be KBACK/KFORW, but we need to
* rewrite the ldelete code (later)?
*/
return (ldelete(chunk, KFORW));
}
/*
- * Yank text back from the kill buffer. This
- * is really easy. All of the work is done by the
- * standard insert routines. All you do is run the loop,
- * and check for errors. The blank
- * lines are inserted with a call to "newline"
- * instead of a call to "lnewline" so that the magic
- * stuff that happens when you type a carriage
- * return also happens when a carriage return is
- * yanked back from the kill buffer.
- * An attempt has been made to fix the cosmetic bug
- * associated with a yank when dot is on the top line of
- * the window (nothing moves, because all of the new
- * text landed off screen).
+ * Yank text back from the kill buffer. This is really easy. All of the work
+ * is done by the standard insert routines. All you do is run the loop, and
+ * check for errors. The blank lines are inserted with a call to "newline"
+ * instead of a call to "lnewline" so that the magic stuff that happens when
+ * you type a carriage return also happens when a carriage return is yanked
+ * back from the kill buffer. An attempt has been made to fix the cosmetic
+ * bug associated with a yank when dot is on the top line of the window
+ * (nothing moves, because all of the new text landed off screen).
*/
/* ARGSUSED */
+int
yank(f, n)
+ int f, n;
{
- register int c;
- register int i;
- register LINE *lp;
- register int nline;
- VOID isetmark();
+ LINE *lp;
+ int c, i, nline;
if (n < 0)
return FALSE;
- nline = 0; /* Newline counting. */
+
+ /* newline counting */
+ nline = 0;
+
while (n--) {
- isetmark(); /* mark around last yank */
+ /* mark around last yank */
+ isetmark();
i = 0;
while ((c = kremove(i)) >= 0) {
if (c == '\n') {
@@ -433,11 +457,15 @@ yank(f, n)
++i;
}
}
- lp = curwp->w_linep; /* Cosmetic adjustment */
- if (curwp->w_dotp == lp) { /* if offscreen insert. */
+ /* cosmetic adjustment */
+ lp = curwp->w_linep;
+
+ /* if offscreen insert */
+ if (curwp->w_dotp == lp) {
while (nline-- && lback(lp) != curbp->b_linep)
lp = lback(lp);
- curwp->w_linep = lp; /* Adjust framing. */
+ /* adjust framing */
+ curwp->w_linep = lp;
curwp->w_flag |= WFHARD;
}
return TRUE;
@@ -445,8 +473,9 @@ yank(f, n)
#ifdef NOTAB
/* ARGSUSED */
+int
space_to_tabstop(f, n)
- int f, n;
+ int f, n;
{
if (n < 0)
return FALSE;
@@ -454,4 +483,4 @@ space_to_tabstop(f, n)
return TRUE;
return linsert((n << 3) - (curwp->w_doto & 7), ' ');
}
-#endif
+#endif /* NOTAB */
diff --git a/usr.bin/mg/re_search.c b/usr.bin/mg/re_search.c
index bfd1b8f1864..290d334209c 100644
--- a/usr.bin/mg/re_search.c
+++ b/usr.bin/mg/re_search.c
@@ -1,83 +1,54 @@
/*
- * regular expression search commands for Mg
+ * regular expression search commands for Mg
*
- * This file contains functions to implement several of gnuemacs'
- * regular expression functions for Mg. Several of the routines
- * below are just minor rearrangements of the Mg non-regular
- * expression search functions. Hence some of them date back in
- * essential structure to the original MicroEMACS; others are modifications
- * of Rich Ellison's code. I, Peter Newton, wrote about half from scratch.
+ * This file contains functions to implement several of gnuemacs's regular
+ * expression functions for Mg. Several of the routines below are just minor
+ * re-arrangements of Mg's non-regular expression search functions. Some of
+ * them are similar in structure to the original MicroEMACS, others are
+ * modifications of Rich Ellison's code. Peter Newton re-wrote about half of
+ * them from scratch.
*/
-
-#ifdef REGEX
+#ifdef REGEX
#include <sys/types.h>
#include <regex.h>
-#include "def.h"
-#include "macro.h"
+#include "def.h"
+#include "macro.h"
-#define SRCH_BEGIN (0) /* Search sub-codes. */
+#define SRCH_BEGIN (0) /* search sub-codes */
#define SRCH_FORW (-1)
#define SRCH_BACK (-2)
#define SRCH_NOPR (-3)
#define SRCH_ACCM (-4)
#define SRCH_MARK (-5)
-#define RE_NMATCH 10 /* max number of matches */
-
-char re_pat[NPAT]; /* Regex pattern */
-int re_srch_lastdir = SRCH_NOPR; /* Last search flags. */
-int casefoldsearch = TRUE; /* Does search ignore case ? */
-
-/* Indexed by a character, gives the upper case equivalent of the character */
-
-static char upcase[0400] =
-{000, 001, 002, 003, 004, 005, 006, 007,
- 010, 011, 012, 013, 014, 015, 016, 017,
- 020, 021, 022, 023, 024, 025, 026, 027,
- 030, 031, 032, 033, 034, 035, 036, 037,
- 040, 041, 042, 043, 044, 045, 046, 047,
- 050, 051, 052, 053, 054, 055, 056, 057,
- 060, 061, 062, 063, 064, 065, 066, 067,
- 070, 071, 072, 073, 074, 075, 076, 077,
- 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
- 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
- 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
- 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
- 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
- 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
- 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
- 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
- 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
- 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
- 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
- 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
- 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
- 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
- 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
- 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
- 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
- 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
- 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
- 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
- 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
- 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
- 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
- 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
-};
+#define RE_NMATCH 10 /* max number of matches */
+#define REPLEN 256 /* max length of replacement string */
+
+char re_pat[NPAT]; /* regex pattern */
+int re_srch_lastdir = SRCH_NOPR; /* last search flags */
+int casefoldsearch = TRUE; /* does search ignore case? */
+
+static int re_doreplace __P((RSIZE, char *, int));
+static int re_forwsrch __P((void));
+static int re_backsrch __P((void));
+static int re_readpattern __P((char *));
+static int killmatches __P((int));
+static int countmatches __P((int));
/*
* Search forward.
- * Get a search string from the user, and search for it,
- * starting at ".". If found, "." gets moved to just after the
- * matched characters, and display does all the hard stuff.
- * If not found, it just prints a message.
+ * Get a search string from the user and search for it starting at ".". If
+ * found, move "." to just after the matched characters. display does all
+ * the hard stuff. If not found, it just prints a message.
*/
/* ARGSUSED */
+int
re_forwsearch(f, n)
+ int f, n;
{
- register int s;
+ int s;
if ((s = re_readpattern("RE Search")) != TRUE)
return (s);
@@ -97,9 +68,11 @@ re_forwsearch(f, n)
* was matched].
*/
/* ARGSUSED */
+int
re_backsearch(f, n)
+ int f, n;
{
- register int s;
+ int s;
if ((s = re_readpattern("RE Search backward")) != TRUE)
return (s);
@@ -111,22 +84,19 @@ re_backsearch(f, n)
return (TRUE);
}
-
-
/*
- * Search again, using the same search string
- * and direction as the last search command. The direction
- * has been saved in "srch_lastdir", so you know which way
- * to go.
- */
-/* ARGSUSED */
-/*
- * This code has problems-- some incompatibility(?) with extend.c causes
+ * Search again, using the same search string and direction as the last search
+ * command. The direction has been saved in "srch_lastdir", so you know which
+ * way to go.
+ *
+ * XXX: This code has problems -- some incompatibility(?) with extend.c causes
* match to fail when it should not.
*/
+/* ARGSUSED */
+int
re_searchagain(f, n)
+ int f, n;
{
-
if (re_srch_lastdir == SRCH_NOPR) {
ewprintf("No last search");
return (FALSE);
@@ -138,31 +108,32 @@ re_searchagain(f, n)
}
return (TRUE);
}
- if (re_srch_lastdir == SRCH_BACK) {
+ if (re_srch_lastdir == SRCH_BACK)
if (re_backsrch() == FALSE) {
ewprintf("Search failed: \"%s\"", re_pat);
return (FALSE);
}
- return (TRUE);
- }
-}
+ return (TRUE);
+}
/* Compiled regex goes here-- changed only when new pattern read */
-static regex_t re_buff;
-static regmatch_t re_match[RE_NMATCH];
+static regex_t re_buff;
+static regmatch_t re_match[RE_NMATCH];
/*
* Re-Query Replace.
* Replace strings selectively. Does a search and replace operation.
*/
/* ARGSUSED */
+int
re_queryrepl(f, n)
+ int f, n;
{
- register int s;
- register int rcnt = 0; /* Replacements made so far */
- register int plen; /* length of found string */
- char news[NPAT]; /* replacement string */
+ int s;
+ int rcnt = 0; /* replacements made so far */
+ int plen; /* length of found string */
+ char news[NPAT]; /* replacement string */
/* Casefold check */
if (!casefoldsearch)
@@ -170,7 +141,8 @@ re_queryrepl(f, n)
if ((s = re_readpattern("RE Query replace")) != TRUE)
return (s);
- if ((s = ereply("Query replace %s with: ", news, NPAT, re_pat)) == ABORT)
+ if ((s =
+ ereply("Query replace %s with: ", news, NPAT, re_pat)) == ABORT)
return (s);
if (s == FALSE)
news[0] = '\0';
@@ -181,41 +153,39 @@ re_queryrepl(f, n)
* or not. The "!" case makes the check always true, so it gets put
* into a tighter loop for efficiency.
*/
-
while (re_forwsrch() == TRUE) {
retry:
update();
switch (getkey(FALSE)) {
case ' ':
plen = re_match[0].rm_eo - re_match[0].rm_so;
- if (re_doreplace((RSIZE) plen, news, f) == FALSE)
+ if (re_doreplace((RSIZE)plen, news, f) == FALSE)
return (FALSE);
rcnt++;
break;
case '.':
plen = re_match[0].rm_eo - re_match[0].rm_so;
- if (re_doreplace((RSIZE) plen, news, f) == FALSE)
+ if (re_doreplace((RSIZE)plen, news, f) == FALSE)
return (FALSE);
rcnt++;
goto stopsearch;
- case CCHR('G'):/* ^G */
- (VOID) ctrlg(FFRAND, 0);
- case CCHR('['):/* ESC */
+ case CCHR('G'): /* ^G */
+ (VOID)ctrlg(FFRAND, 0);
+ case CCHR('['): /* ESC */
case '`':
goto stopsearch;
-
case '!':
do {
plen = re_match[0].rm_eo - re_match[0].rm_so;
- if (re_doreplace((RSIZE) plen, news, f) == FALSE)
+ if (re_doreplace((RSIZE)plen, news, f) == FALSE)
return (FALSE);
rcnt++;
} while (re_forwsrch() == TRUE);
goto stopsearch;
- case CCHR('?'):/* To not replace */
+ case CCHR('?'): /* To not replace */
break;
default:
@@ -223,6 +193,7 @@ retry:
goto retry;
}
}
+
stopsearch:
curwp->w_flag |= WFHARD;
update();
@@ -237,37 +208,29 @@ stopsearch:
return TRUE;
}
-
-
/*
* Routine re_doreplace calls lreplace to make replacements needed by
* re_query replace. Its reason for existence is to deal with \1, \2. etc.
*/
-
-/* Maximum length of replacement string */
-#define REPLEN 256
-
+static int
re_doreplace(plen, st, f)
- register RSIZE plen; /* length to remove */
- char *st; /* replacement string */
- int f; /* case hack disable */
+ RSIZE plen; /* length to remove */
+ char *st; /* replacement string */
+ int f; /* case hack disable */
{
- int s;
- int num, k;
- register int j;
- int more, state;
- LINE *clp;
- char repstr[REPLEN];
+ int j, k, s, more, num, state;
+ LINE *clp;
+ char repstr[REPLEN];
clp = curwp->w_dotp;
more = TRUE;
j = 0;
state = 0;
+ num = 0;
/* The following FSA parses the replacement string */
while (more) {
switch (state) {
-
case 0:
if (*st == '\\') {
st++;
@@ -308,7 +271,8 @@ re_doreplace(plen, st, f)
k = re_match[num].rm_eo - re_match[num].rm_so;
if (j + k >= REPLEN)
return (FALSE);
- bcopy(&(clp->l_text[re_match[num].rm_so]), &repstr[j], k);
+ bcopy(&(clp->l_text[re_match[num].rm_so]),
+ &repstr[j], k);
j += k;
if (*st == '\0')
more = FALSE;
@@ -325,39 +289,35 @@ re_doreplace(plen, st, f)
}
}
break;
- } /* end case */
- } /* end while */
+ } /* switch (state) */
+ } /* while (more) */
repstr[j] = '\0';
-
s = lreplace(plen, repstr, f);
-
return (s);
}
/*
- * This routine does the real work of a
- * forward search. The pattern is sitting in the external
- * variable "pat". If found, dot is updated, the window system
- * is notified of the change, and TRUE is returned. If the
+ * This routine does the real work of a forward search. The pattern is
+ * sitting in the external variable "pat". If found, dot is updated, the
+ * window system is notified of the change, and TRUE is returned. If the
* string isn't found, FALSE is returned.
*/
+static int
re_forwsrch()
{
-
- register LINE *clp;
- register int tbo;
- int error, plen;
+ int tbo, error;
+ LINE *clp;
clp = curwp->w_dotp;
tbo = curwp->w_doto;
if (tbo == clp->l_used)
/*
- * Don't start matching off end of line-- must move to
- * beginning of next line, unless at end
+ * Don't start matching past end of line -- must move to
+ * beginning of next line, unless at end of file.
*/
if (clp != curbp->b_linep) {
clp = lforw(clp);
@@ -367,14 +327,12 @@ re_forwsrch()
* Note this loop does not process the last line, but this editor
* always makes the last line empty so this is good.
*/
-
while (clp != (curbp->b_linep)) {
-
re_match[0].rm_so = tbo;
re_match[0].rm_eo = llength(clp);
- error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND);
-
- if (error) {
+ error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match,
+ REG_STARTEND);
+ if (error != 0) {
clp = lforw(clp);
tbo = 0;
} else {
@@ -383,28 +341,23 @@ re_forwsrch()
curwp->w_flag |= WFMOVE;
return (TRUE);
}
-
}
-
return (FALSE);
-
}
/*
- * This routine does the real work of a
- * backward search. The pattern is sitting in the external
- * variable "re_pat". If found, dot is updated, the window system
- * is notified of the change, and TRUE is returned. If the
- * string isn't found, FALSE is returned.
+ * This routine does the real work of a backward search. The pattern is sitting
+ * in the external variable "re_pat". If found, dot is updated, the window
+ * system is notified of the change, and TRUE is returned. If the string isn't
+ * found, FALSE is returned.
*/
+static int
re_backsrch()
{
-
- register LINE *clp;
- register int tbo;
- regmatch_t lastmatch;
- char m[1];
+ LINE *clp;
+ int tbo;
+ regmatch_t lastmatch;
clp = curwp->w_dotp;
tbo = curwp->w_doto;
@@ -416,13 +369,12 @@ re_backsrch()
clp = lback(clp);
tbo = llength(clp);
}
+
/*
* Note this loop does not process the last line, but this editor
* always makes the last line empty so this is good.
*/
-
while (clp != (curbp->b_linep)) {
-
re_match[0].rm_so = 0;
re_match[0].rm_eo = llength(clp);
lastmatch.rm_so = -1;
@@ -438,7 +390,6 @@ re_backsrch()
re_match[0].rm_so++;
re_match[0].rm_eo = llength(clp);
}
-
if (lastmatch.rm_so == -1) {
clp = lback(clp);
tbo = llength(clp);
@@ -449,11 +400,8 @@ re_backsrch()
curwp->w_flag |= WFMOVE;
return (TRUE);
}
-
}
-
return (FALSE);
-
}
@@ -465,14 +413,13 @@ re_backsrch()
* Display the old pattern, in the style of Jeff Lomicka. There is
* some do-it-yourself control expansion.
*/
+static int
re_readpattern(prompt)
- char *prompt;
+ char *prompt;
{
- int s;
- int flags;
- int error;
- char tpat[NPAT];
- static int dofree = 0;
+ int s, flags, error;
+ char tpat[NPAT];
+ static int dofree = 0;
if (re_pat[0] == '\0')
s = ereply("%s: ", tpat, NPAT, prompt);
@@ -481,7 +428,7 @@ re_readpattern(prompt)
if (s == TRUE) {
/* New pattern given */
- (VOID) strcpy(re_pat, tpat);
+ (VOID)strcpy(re_pat, tpat);
if (casefoldsearch)
flags = REG_EXTENDED | REG_ICASE;
else
@@ -489,8 +436,8 @@ re_readpattern(prompt)
if (dofree)
regfree(&re_buff);
error = regcomp(&re_buff, re_pat, flags);
- if (error) {
- char message[256];
+ if (error != 0) {
+ char message[256];
regerror(error, &re_buff, message, sizeof(message));
ewprintf("Regex Error: %s", message);
re_pat[0] = '\0';
@@ -503,15 +450,14 @@ re_readpattern(prompt)
return (s);
}
-
-
/*
* Cause case to not matter in searches. This is the default. If called
* with argument cause case to matter.
*/
+int
setcasefold(f, n)
+ int f, n;
{
-
if (f & FFARG) {
casefoldsearch = FALSE;
ewprintf("Case-fold-search unset");
@@ -524,56 +470,55 @@ setcasefold(f, n)
* Invalidate the regular expression pattern since I'm too lazy to
* recompile it.
*/
-
re_pat[0] = '\0';
-
return (TRUE);
-
-} /* end setcasefold */
+}
/*
* Delete all lines after dot that contain a string matching regex
*/
+int
delmatchlines(f, n)
+ int f, n;
{
- int s;
+ int s;
- if ((s = re_readpattern("Flush lines (containing match for regexp)")) != TRUE)
+ if ((s = re_readpattern("Flush lines (containing match for regexp)"))
+ != TRUE)
return (s);
s = killmatches(TRUE);
-
return (s);
}
-
-
/*
* Delete all lines after dot that don't contain a string matching regex
*/
+int
delnonmatchlines(f, n)
+ int f, n;
{
- int s;
+ int s;
-
- if ((s = re_readpattern("Keep lines (containing match for regexp)")) != TRUE)
+ if ((s = re_readpattern("Keep lines (containing match for regexp)"))
+ != TRUE)
return (s);
s = killmatches(FALSE);
-
return (s);
}
-
-
-/* This function does the work of deleting matching lines */
+/*
+ * This function does the work of deleting matching lines
+ */
+static int
killmatches(cond)
- int cond;
+ int cond;
{
- int s, error;
- int count = 0;
- LINE *clp;
+ int s, error;
+ int count = 0;
+ LINE *clp;
clp = curwp->w_dotp;
if (curwp->w_doto == llength(clp))
@@ -581,11 +526,11 @@ killmatches(cond)
clp = lforw(clp);
while (clp != (curbp->b_linep)) {
-
/* see if line matches */
re_match[0].rm_so = 0;
re_match[0].rm_eo = llength(clp);
- error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND);
+ error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match,
+ REG_STARTEND);
/* Delete line when appropriate */
if ((cond == FALSE && error) || (cond == TRUE && !error)) {
@@ -608,46 +553,29 @@ killmatches(cond)
return (TRUE);
}
-
-petersfunc(f, n)
-{
-
- int s;
- LINE *clp;
- char c;
-
- curwp->w_doto = 0;
- s = ldelete(llength(curwp->w_dotp) + 1, KNONE);
- curwp->w_flag |= WFMOVE;
- return (s);
-
-}
-
-
/*
* Count lines matching regex
*/
+int
cntmatchlines(f, n)
+ int f, n;
{
- int s;
+ int s;
if ((s = re_readpattern("Count lines (matching regexp)")) != TRUE)
return (s);
-
s = countmatches(TRUE);
-
return (s);
}
-
-
/*
* Count lines that fail to match regex
*/
+int
cntnonmatchlines(f, n)
+ int f, n;
{
- int s;
-
+ int s;
if ((s = re_readpattern("Count lines (not matching regexp)")) != TRUE)
return (s);
@@ -657,15 +585,16 @@ cntnonmatchlines(f, n)
return (s);
}
-
-
-/* This function does the work of counting matching lines */
+/*
+ * This function does the work of counting matching lines.
+ */
+int
countmatches(cond)
- int cond;
+ int cond;
{
- int s, error;
- int count = 0;
- LINE *clp;
+ int error;
+ int count = 0;
+ LINE *clp;
clp = curwp->w_dotp;
if (curwp->w_doto == llength(clp))
@@ -673,11 +602,11 @@ countmatches(cond)
clp = lforw(clp);
while (clp != (curbp->b_linep)) {
-
/* see if line matches */
re_match[0].rm_so = 0;
re_match[0].rm_eo = llength(clp);
- error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND);
+ error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match,
+ REG_STARTEND);
/* Count line when appropriate */
if ((cond == FALSE && error) || (cond == TRUE && !error))
@@ -692,4 +621,4 @@ countmatches(cond)
return (TRUE);
}
-#endif
+#endif /* REGEX */
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c
index 0c3395150c0..94fff75b48a 100644
--- a/usr.bin/mg/region.c
+++ b/usr.bin/mg/region.c
@@ -1,63 +1,73 @@
/*
* Region based commands.
- * The routines in this file
- * deal with the region, that magic space
- * between "." and mark. Some functions are
- * commands. Some functions are just for
+ * The routines in this file deal with the region, that magic space between
+ * "." and mark. Some functions are commands. Some functions are just for
* internal use.
*/
-#include "def.h"
+
+#include "def.h"
+
+static int getregion __P((REGION *));
+static int setsize __P((REGION *, RSIZE));
/*
- * Kill the region. Ask "getregion"
- * to figure out the bounds of the region.
+ * Kill the region. Ask "getregion" to figure out the bounds of the region.
* Move "." to the start, and kill the characters.
*/
/* ARGSUSED */
+int
killregion(f, n)
+ int f, n;
{
- register int s;
- REGION region;
+ int s;
+ REGION region;
if ((s = getregion(&region)) != TRUE)
return (s);
- if ((lastflag & CFKILL) == 0) /* This is a kill type */
- kdelete(); /* command, so do magic */
- thisflag |= CFKILL; /* kill buffer stuff. */
+ /* This is a kill-type command, so do magic kill buffer stuff. */
+ if ((lastflag & CFKILL) == 0)
+ kdelete();
+ thisflag |= CFKILL;
curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset;
return (ldelete(region.r_size, KFORW));
}
/*
- * Copy all of the characters in the
- * region to the kill buffer. Don't move dot
- * at all. This is a bit like a kill region followed
- * by a yank.
+ * Copy all of the characters in the region to the kill buffer. Don't move
+ * dot at all. This is a bit like a kill region followed by a yank.
*/
/* ARGSUSED */
+int
copyregion(f, n)
+ int f, n;
{
- register LINE *linep;
- register int loffs;
- register int s;
- REGION region;
- VOID kdelete();
+ LINE *linep;
+ REGION region;
+ int loffs;
+ int s;
if ((s = getregion(&region)) != TRUE)
return s;
- if ((lastflag & CFKILL) == 0) /* Kill type command. */
+
+ /* kill type command */
+ if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
- linep = region.r_linep; /* Current line. */
- loffs = region.r_offset;/* Current offset. */
+
+ /* current line */
+ linep = region.r_linep;
+
+ /* current offset */
+ loffs = region.r_offset;
+
while (region.r_size--) {
if (loffs == llength(linep)) { /* End of line. */
if ((s = kinsert('\n', KFORW)) != TRUE)
return (s);
linep = lforw(linep);
loffs = 0;
- } else { /* Middle of line. */
+ } else { /* Middle of line. */
if ((s = kinsert(lgetc(linep, loffs), KFORW)) != TRUE)
return s;
++loffs;
@@ -67,20 +77,19 @@ copyregion(f, n)
}
/*
- * Lower case region. Zap all of the upper
- * case characters in the region to lower case. Use
- * the region code to set the limits. Scan the buffer,
- * doing the changes. Call "lchange" to ensure that
- * redisplay is done in all buffers.
+ * Lower case region. Zap all of the upper case characters in the region to
+ * lower case. Use the region code to set the limits. Scan the buffer, doing
+ * the changes. Call "lchange" to ensure that redisplay is done in all
+ * buffers.
*/
/* ARGSUSED */
+int
lowerregion(f, n)
+ int f, n;
{
- register LINE *linep;
- register int loffs;
- register int c;
- register int s;
- REGION region;
+ LINE *linep;
+ REGION region;
+ int loffs, c, s;
if ((s = getregion(&region)) != TRUE)
return s;
@@ -102,21 +111,19 @@ lowerregion(f, n)
}
/*
- * Upper case region. Zap all of the lower
- * case characters in the region to upper case. Use
- * the region code to set the limits. Scan the buffer,
- * doing the changes. Call "lchange" to ensure that
- * redisplay is done in all buffers.
+ * Upper case region. Zap all of the lower case characters in the region to
+ * upper case. Use the region code to set the limits. Scan the buffer,
+ * doing the changes. Call "lchange" to ensure that redisplay is done in all
+ * buffers.
*/
/* ARGSUSED */
+int
upperregion(f, n)
+ int f, n;
{
- register LINE *linep;
- register int loffs;
- register int c;
- register int s;
- REGION region;
- VOID lchange();
+ LINE *linep;
+ REGION region;
+ int loffs, c, s;
if ((s = getregion(&region)) != TRUE)
return s;
@@ -138,42 +145,42 @@ upperregion(f, n)
}
/*
- * This routine figures out the bound of the region
- * in the current window, and stores the results into the fields
- * of the REGION structure. Dot and mark are usually close together,
- * but I don't know the order, so I scan outward from dot, in both
- * directions, looking for mark. The size is kept in a long. At the
- * end, after the size is figured out, it is assigned to the size
- * field of the region structure. If this assignment loses any bits,
- * then we print an error. This is "type independent" overflow
- * checking. All of the callers of this routine should be ready to
- * get an ABORT status, because I might add a "if regions is big,
- * ask before clobberring" flag.
+ * This routine figures out the bound of the region in the current window,
+ * and stores the results into the fields of the REGION structure. Dot and
+ * mark are usually close together, but I don't know the order, so I scan
+ * outward from dot, in both directions, looking for mark. The size is kept
+ * in a long. At the end, after the size is figured out, it is assigned to
+ * the size field of the region structure. If this assignment loses any bits,
+ * then we print an error. This is "type independent" overflow checking. All
+ * of the callers of this routine should be ready to get an ABORT status,
+ * because I might add a "if regions is big, ask before clobberring" flag.
*/
+static int
getregion(rp)
- register REGION *rp;
+ REGION *rp;
{
- register LINE *flp;
- register LINE *blp;
- register long fsize; /* Long now. */
- register long bsize;
+ LINE *flp, *blp;
+ long fsize, bsize;
if (curwp->w_markp == NULL) {
ewprintf("No mark set in this window");
return (FALSE);
}
- if (curwp->w_dotp == curwp->w_markp) { /* "r_size" always ok. */
+
+ /* "r_size" always ok */
+ if (curwp->w_dotp == curwp->w_markp) {
rp->r_linep = curwp->w_dotp;
if (curwp->w_doto < curwp->w_marko) {
rp->r_offset = curwp->w_doto;
- rp->r_size = (RSIZE) (curwp->w_marko - curwp->w_doto);
+ rp->r_size = (RSIZE)(curwp->w_marko - curwp->w_doto);
} else {
rp->r_offset = curwp->w_marko;
- rp->r_size = (RSIZE) (curwp->w_doto - curwp->w_marko);
+ rp->r_size = (RSIZE)(curwp->w_doto - curwp->w_marko);
}
return TRUE;
}
- flp = blp = curwp->w_dotp; /* Get region size. */
+ /* get region size */
+ flp = blp = curwp->w_dotp;
bsize = curwp->w_doto;
fsize = llength(flp) - curwp->w_doto + 1;
while (lforw(flp) != curbp->b_linep || lback(blp) != curbp->b_linep) {
@@ -183,7 +190,7 @@ getregion(rp)
rp->r_linep = curwp->w_dotp;
rp->r_offset = curwp->w_doto;
return (setsize(rp,
- (RSIZE) (fsize + curwp->w_marko)));
+ (RSIZE)(fsize + curwp->w_marko)));
}
fsize += llength(flp) + 1;
}
@@ -194,22 +201,22 @@ getregion(rp)
rp->r_linep = blp;
rp->r_offset = curwp->w_marko;
return (setsize(rp,
- (RSIZE) (bsize - curwp->w_marko)));
+ (RSIZE)(bsize - curwp->w_marko)));
}
}
}
- ewprintf("Bug: lost mark"); /* Gak! */
+ ewprintf("Bug: lost mark");
return FALSE;
}
/*
* Set size, and check for overflow.
*/
+static int
setsize(rp, size)
- register REGION *rp;
- register RSIZE size;
+ REGION *rp;
+ RSIZE size;
{
-
rp->r_size = size;
if (rp->r_size != size) {
ewprintf("Region is too large");
@@ -218,7 +225,7 @@ setsize(rp, size)
return TRUE;
}
-#ifdef PREFIXREGION
+#ifdef PREFIXREGION
/*
* Implements one of my favorite keyboard macros; put a string at the
* beginning of a number of lines in a buffer. The quote string is
@@ -228,23 +235,23 @@ setsize(rp, size)
*/
#define PREFIXLENGTH 40
-static char prefix_string[PREFIXLENGTH] = {'>', '\0'};
+static char prefix_string[PREFIXLENGTH] = {'>', '\0'};
/*
- * Prefix the region with whatever is in prefix_string.
- * Leaves dot at the beginning of the line after the end
- * of the region. If an argument is given, prompts for the
- * line prefix string.
+ * Prefix the region with whatever is in prefix_string. Leaves dot at the
+ * beginning of the line after the end of the region. If an argument is
+ * given, prompts for the line prefix string.
*/
-
/* ARGSUSED */
+int
prefixregion(f, n)
+ int f, n;
{
- register int s;
- register LINE *first, *last;
- register int nline;
- REGION region;
- char *prefix = prefix_string;
+ LINE *first, *last;
+ REGION region;
+ char *prefix = prefix_string;
+ int nline;
+ int s;
if ((f == TRUE) && ((s = setprefix(FFRAND, 1)) != TRUE))
return s;
@@ -263,24 +270,25 @@ prefixregion(f, n)
/* for each line, go to beginning and insert the prefix string */
while (nline--) {
- (VOID) gotobol(FFRAND, 1);
+ (VOID)gotobol(FFRAND, 1);
for (prefix = prefix_string; *prefix; prefix++)
- (VOID) linsert(1, *prefix);
- (VOID) forwline(FFRAND, 1);
+ (VOID)linsert(1, *prefix);
+ (VOID)forwline(FFRAND, 1);
}
- (VOID) gotobol(FFRAND, 1);
+ (VOID)gotobol(FFRAND, 1);
return TRUE;
}
/*
- * Set prefix string.
+ * Set line prefix string.
*/
-
/* ARGSUSED */
+int
setprefix(f, n)
+ int f, n;
{
- char buf[PREFIXLENGTH];
- register int s;
+ char buf[PREFIXLENGTH];
+ int s;
if (prefix_string[0] == '\0')
s = ereply("Prefix string: ", buf, sizeof buf);
@@ -288,9 +296,10 @@ setprefix(f, n)
s = ereply("Prefix string (default %s): ",
buf, sizeof buf, prefix_string);
if (s == TRUE)
- (VOID) strcpy(prefix_string, buf);
- if ((s == FALSE) && (prefix_string[0] != '\0')) /* CR -- use old one */
+ (VOID)strcpy(prefix_string, buf);
+ /* CR -- use old one */
+ if ((s == FALSE) && (prefix_string[0] != '\0'))
s = TRUE;
return s;
}
-#endif
+#endif /* PREFIXREGION */
diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c
index ac384539222..4430be86eb8 100644
--- a/usr.bin/mg/search.c
+++ b/usr.bin/mg/search.c
@@ -1,17 +1,17 @@
/*
* Search commands.
- * The functions in this file implement the
- * search commands (both plain and incremental searches
- * are supported) and the query-replace command.
+ * The functions in this file implement the search commands (both plain and
+ * incremental searches are supported) and the query-replace command.
*
- * The plain old search code is part of the original
- * MicroEMACS "distribution". The incremental search code,
- * and the query-replace code, is by Rich Ellison.
+ * The plain old search code is part of the original MicroEMACS "distribution".
+ * The incremental search code and the query-replace code is by Rich Ellison.
*/
-#include "def.h"
+
+#include "def.h"
+
#ifndef NO_MACRO
-#include "macro.h"
-#endif
+#include "macro.h"
+#endif /* !NO_MACRO */
#define SRCH_BEGIN (0) /* Search sub-codes. */
#define SRCH_FORW (-1)
@@ -21,37 +21,39 @@
#define SRCH_MARK (-5)
typedef struct {
- int s_code;
- LINE *s_dotp;
- int s_doto;
-} SRCHCOM;
-
-static SRCHCOM cmds[NSRCH];
-static int cip;
-
-int srch_lastdir = SRCH_NOPR; /* Last search flags. */
-
-static VOID is_cpush();
-static VOID is_lpush();
-static VOID is_pop();
-static int is_peek();
-static VOID is_undo();
-static int is_find();
-static VOID is_prompt();
-static VOID is_dspl();
-static int eq();
+ int s_code;
+ LINE *s_dotp;
+ int s_doto;
+} SRCHCOM;
+
+static int isearch __P((int));
+static VOID is_cpush __P((int));
+static VOID is_lpush __P((void));
+static VOID is_pop __P((void));
+static int is_peek __P((void));
+static VOID is_undo __P((int *, int *));
+static int is_find __P((int));
+static VOID is_prompt __P((int, int, int));
+static VOID is_dspl __P((char *, int));
+static int eq __P((int, int));
+
+static SRCHCOM cmds[NSRCH];
+static int cip;
+
+int srch_lastdir = SRCH_NOPR; /* Last search flags. */
/*
- * Search forward.
- * Get a search string from the user, and search for it,
- * starting at ".". If found, "." gets moved to just after the
- * matched characters, and display does all the hard stuff.
- * If not found, it just prints a message.
+ * Search forward. Get a search string from the user, and search for it
+ * starting at ".". If found, "." gets moved to just after the matched
+ * characters, and display does all the hard stuff. If not found, it just
+ * prints a message.
*/
/* ARGSUSED */
+int
forwsearch(f, n)
+ int f, n;
{
- register int s;
+ int s;
if ((s = readpattern("Search")) != TRUE)
return s;
@@ -64,16 +66,17 @@ forwsearch(f, n)
}
/*
- * Reverse search.
- * Get a search string from the user, and search, starting at "."
- * and proceeding toward the front of the buffer. If found "." is left
- * pointing at the first character of the pattern [the last character that
- * was matched].
+ * Reverse search. Get a search string from the user, and search, starting
+ * at "." and proceeding toward the front of the buffer. If found "." is
+ * left pointing at the first character of the pattern [the last character
+ * that was matched].
*/
/* ARGSUSED */
+int
backsearch(f, n)
+ int f, n;
{
- register int s;
+ int s;
if ((s = readpattern("Search backward")) != TRUE)
return (s);
@@ -86,13 +89,14 @@ backsearch(f, n)
}
/*
- * Search again, using the same search string
- * and direction as the last search command. The direction
- * has been saved in "srch_lastdir", so you know which way
- * to go.
+ * Search again, using the same search string and direction as the last
+ * search command. The direction has been saved in "srch_lastdir", so you
+ * know which way to go.
*/
/* ARGSUSED */
+int
searchagain(f, n)
+ int f, n;
{
if (srch_lastdir == SRCH_FORW) {
if (forwsrch() == FALSE) {
@@ -113,11 +117,13 @@ searchagain(f, n)
}
/*
- * Use incremental searching, initially in the forward direction.
+ * Use incremental searching, initially in the forward direction.
* isearch ignores any explicit arguments.
*/
/* ARGSUSED */
+int
forwisearch(f, n)
+ int f, n;
{
return isearch(SRCH_FORW);
}
@@ -127,7 +133,9 @@ forwisearch(f, n)
* isearch ignores any explicit arguments.
*/
/* ARGSUSED */
+int
backisearch(f, n)
+ int f, n;
{
return isearch(SRCH_BACK);
}
@@ -143,25 +151,29 @@ backisearch(f, n)
* other ^ exit search, don't set mark
* else accumulate into search string
*/
+static int
isearch(dir)
+ int dir;
{
- register int c;
- register LINE *clp;
- register int cbo;
- register int success;
- int pptr;
- char opat[NPAT];
- VOID ungetkey();
+ LINE *clp;
+
+ int c;
+ int cbo;
+ int success;
+ int pptr;
+
+ char opat[NPAT];
#ifndef NO_MACRO
if (macrodef) {
ewprintf("Can't isearch in macro");
return FALSE;
}
-#endif
+#endif /* !NO_MACRO */
for (cip = 0; cip < NSRCH; cip++)
cmds[cip].s_code = SRCH_NOPR;
- (VOID) strcpy(opat, pat);
+
+ (VOID)strcpy(opat, pat);
cip = 0;
pptr = -1;
clp = curwp->w_dotp;
@@ -170,8 +182,10 @@ isearch(dir)
is_cpush(SRCH_BEGIN);
success = TRUE;
is_prompt(dir, TRUE, success);
+
for (;;) {
update();
+
switch (c = getkey(FALSE)) {
case CCHR('['):
srch_lastdir = dir;
@@ -179,7 +193,6 @@ isearch(dir)
curwp->w_marko = cbo;
ewprintf("Mark set");
return (TRUE);
-
case CCHR('G'):
if (success != TRUE) {
while (is_peek() == SRCH_ACCM)
@@ -192,10 +205,9 @@ isearch(dir)
curwp->w_doto = cbo;
curwp->w_flag |= WFMOVE;
srch_lastdir = dir;
- (VOID) ctrlg(FFRAND, 0);
- (VOID) strcpy(pat, opat);
+ (VOID)ctrlg(FFRAND, 0);
+ (VOID)strcpy(pat, opat);
return ABORT;
-
case CCHR(']'):
case CCHR('S'):
if (dir == SRCH_BACK) {
@@ -208,17 +220,16 @@ isearch(dir)
break;
is_lpush();
pptr = strlen(pat);
- (VOID) forwchar(FFRAND, 1);
+ (VOID)forwchar(FFRAND, 1);
if (is_find(SRCH_FORW) != FALSE)
is_cpush(SRCH_MARK);
else {
- (VOID) backchar(FFRAND, 1);
+ (VOID)backchar(FFRAND, 1);
ttbeep();
success = FALSE;
}
is_prompt(dir, pptr < 0, success);
break;
-
case CCHR('R'):
if (dir == SRCH_FORW) {
dir = SRCH_BACK;
@@ -230,17 +241,16 @@ isearch(dir)
break;
is_lpush();
pptr = strlen(pat);
- (VOID) backchar(FFRAND, 1);
+ (VOID)backchar(FFRAND, 1);
if (is_find(SRCH_BACK) != FALSE)
is_cpush(SRCH_MARK);
else {
- (VOID) forwchar(FFRAND, 1);
+ (VOID)forwchar(FFRAND, 1);
ttbeep();
success = FALSE;
}
is_prompt(dir, pptr < 0, success);
break;
-
case CCHR('H'):
case CCHR('?'):
is_undo(&pptr, &dir);
@@ -248,15 +258,13 @@ isearch(dir)
success = TRUE;
is_prompt(dir, pptr < 0, success);
break;
-
case CCHR('\\'):
case CCHR('Q'):
- c = (char) getkey(FALSE);
+ c = (char)getkey(FALSE);
goto addchar;
case CCHR('M'):
c = CCHR('J');
goto addchar;
-
default:
if (ISCTRL(c)) {
ungetkey(c);
@@ -296,19 +304,19 @@ isearch(dir)
/* NOTREACHED */
}
-static VOID
+static VOID
is_cpush(cmd)
- register int cmd;
+ int cmd;
{
if (++cip >= NSRCH)
cip = 0;
cmds[cip].s_code = cmd;
}
-static VOID
+static VOID
is_lpush()
{
- register int ctp;
+ int ctp;
ctp = cip + 1;
if (ctp >= NSRCH)
@@ -318,7 +326,7 @@ is_lpush()
cmds[ctp].s_dotp = curwp->w_dotp;
}
-static VOID
+static VOID
is_pop()
{
if (cmds[cip].s_code != SRCH_NOPR) {
@@ -338,29 +346,26 @@ is_peek()
}
/* this used to always return TRUE (the return value was checked) */
-static VOID
+static VOID
is_undo(pptr, dir)
- register int *pptr;
- register int *dir;
+ int *pptr, *dir;
{
- register int redo = FALSE;
+ int redo = FALSE;
+
switch (cmds[cip].s_code) {
case SRCH_BEGIN:
case SRCH_NOPR:
*pptr = -1;
case SRCH_MARK:
break;
-
case SRCH_FORW:
*dir = SRCH_BACK;
redo = TRUE;
break;
-
case SRCH_BACK:
*dir = SRCH_FORW;
redo = TRUE;
break;
-
case SRCH_ACCM:
default:
*pptr -= 1;
@@ -376,17 +381,17 @@ is_undo(pptr, dir)
static int
is_find(dir)
- register int dir;
+ int dir;
{
- register int plen, odoto;
- register LINE *odotp;
+ int plen, odoto;
+ LINE *odotp;
odoto = curwp->w_doto;
odotp = curwp->w_dotp;
plen = strlen(pat);
if (plen != 0) {
if (dir == SRCH_FORW) {
- (VOID) backchar(FFARG | FFRAND, plen);
+ (VOID)backchar(FFARG | FFRAND, plen);
if (forwsrch() == FALSE) {
curwp->w_doto = odoto;
curwp->w_dotp = odotp;
@@ -395,7 +400,7 @@ is_find(dir)
return TRUE;
}
if (dir == SRCH_BACK) {
- (VOID) forwchar(FFARG | FFRAND, plen);
+ (VOID)forwchar(FFARG | FFRAND, plen);
if (backsrch() == FALSE) {
curwp->w_doto = odoto;
curwp->w_dotp = odotp;
@@ -410,15 +415,14 @@ is_find(dir)
}
/*
- * If called with "dir" not one of SRCH_FORW
- * or SRCH_BACK, this routine used to print an error
- * message. It also used to return TRUE or FALSE,
- * depending on if it liked the "dir". However, none
- * of the callers looked at the status, so I just
- * made the checking vanish.
+ * If called with "dir" not one of SRCH_FORW or SRCH_BACK, this routine used
+ * to print an error message. It also used to return TRUE or FALSE, depending
+ * on if it liked the "dir". However, none of the callers looked at the
+ * status, so I just made the checking vanish.
*/
-static VOID
+static VOID
is_prompt(dir, flag, success)
+ int dir, flag, success;
{
if (dir == SRCH_FORW) {
if (success != FALSE)
@@ -435,15 +439,14 @@ is_prompt(dir, flag, success)
}
/*
- * Prompt writing routine for the incremental search.
- * The "prompt" is just a string. The "flag" determines
- * whether pat should be printed.
+ * Prompt writing routine for the incremental search. The "prompt" is just
+ * a string. The "flag" determines whether pat should be printed.
*/
-static VOID
+static VOID
is_dspl(prompt, flag)
- char *prompt;
+ char *prompt;
+ int flag;
{
-
if (flag != FALSE)
ewprintf("%s: ", prompt);
else
@@ -455,19 +458,22 @@ is_dspl(prompt, flag)
* Replace strings selectively. Does a search and replace operation.
*/
/* ARGSUSED */
+int
queryrepl(f, n)
+ int f, n;
{
- register int s;
- register int rcnt = 0; /* Replacements made so far */
- register int plen; /* length of found string */
- char news[NPAT]; /* replacement string */
+ int s;
+ int rcnt = 0; /* replacements made so far */
+ int plen; /* length of found string */
+ char news[NPAT]; /* replacement string */
#ifndef NO_MACRO
if (macrodef) {
ewprintf("Can't query replace in macro");
return FALSE;
}
-#endif
+#endif /* !NO_MACRO */
+
if ((s = readpattern("Query replace")) != TRUE)
return (s);
if ((s = ereply("Query replace %s with: ", news, NPAT, pat)) == ABORT)
@@ -482,40 +488,36 @@ queryrepl(f, n)
* or not. The "!" case makes the check always true, so it gets put
* into a tighter loop for efficiency.
*/
-
while (forwsrch() == TRUE) {
retry:
update();
switch (getkey(FALSE)) {
case ' ':
- if (lreplace((RSIZE) plen, news, f) == FALSE)
+ if (lreplace((RSIZE)plen, news, f) == FALSE)
return (FALSE);
rcnt++;
break;
-
case '.':
- if (lreplace((RSIZE) plen, news, f) == FALSE)
+ if (lreplace((RSIZE)plen, news, f) == FALSE)
return (FALSE);
rcnt++;
goto stopsearch;
-
- case CCHR('G'):/* ^G or ESC */
- (VOID) ctrlg(FFRAND, 0);
+ /* ^G or ESC */
+ case CCHR('G'):
+ (VOID)ctrlg(FFRAND, 0);
case CCHR('['):
goto stopsearch;
-
case '!':
do {
- if (lreplace((RSIZE) plen, news, f) == FALSE)
+ if (lreplace((RSIZE)plen, news, f) == FALSE)
return (FALSE);
rcnt++;
} while (forwsrch() == TRUE);
goto stopsearch;
-
case CCHR('H'):
- case CCHR('?'):/* To not replace */
+ /* To not replace */
+ case CCHR('?'):
break;
-
default:
ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit");
goto retry;
@@ -534,20 +536,17 @@ stopsearch:
}
/*
- * This routine does the real work of a
- * forward search. The pattern is sitting in the external
- * variable "pat". If found, dot is updated, the window system
- * is notified of the change, and TRUE is returned. If the
- * string isn't found, FALSE is returned.
+ * This routine does the real work of a forward search. The pattern is sitting
+ * in the external variable "pat". If found, dot is updated, the window system
+ * is notified of the change, and TRUE is returned. If the string isn't found,
+ * FALSE is returned.
*/
+int
forwsrch()
{
- register LINE *clp;
- register int cbo;
- register LINE *tlp;
- register int tbo;
- char *pp;
- register int c;
+ LINE *clp, *tlp;
+ int cbo, tbo, c;
+ char *pp;
clp = curwp->w_dotp;
cbo = curwp->w_doto;
@@ -586,21 +585,17 @@ fail: ;
}
/*
- * This routine does the real work of a
- * backward search. The pattern is sitting in the external
- * variable "pat". If found, dot is updated, the window system
- * is notified of the change, and TRUE is returned. If the
+ * This routine does the real work of a backward search. The pattern is
+ * sitting in the external variable "pat". If found, dot is updated, the
+ * window system is notified of the change, and TRUE is returned. If the
* string isn't found, FALSE is returned.
*/
+int
backsrch()
{
- register LINE *clp;
- register int cbo;
- register LINE *tlp;
- register int tbo;
- register int c;
- register char *epp;
- register char *pp;
+ LINE *clp, *tlp;
+ int cbo, tbo, c;
+ char *epp, *pp;
for (epp = &pat[0]; epp[1] != 0; ++epp);
clp = curwp->w_dotp;
@@ -645,14 +640,12 @@ fail: ;
}
/*
- * Compare two characters.
- * The "bc" comes from the buffer.
- * It has its case folded out. The
- * "pc" is from the pattern.
+ * Compare two characters. The "bc" comes from the buffer. It has its case
+ * folded out. The "pc" is from the pattern.
*/
static int
eq(bc, pc)
- register int bc, pc;
+ int bc, pc;
{
bc = CHARMASK(bc);
pc = CHARMASK(pc);
@@ -666,27 +659,29 @@ eq(bc, pc)
}
/*
- * Read a pattern.
- * Stash it in the external variable "pat". The "pat" is
- * not updated if the user types in an empty line. If the user typed
- * an empty line, and there is no old pattern, it is an error.
- * Display the old pattern, in the style of Jeff Lomicka. There is
- * some do-it-yourself control expansion.
+ * Read a pattern. Stash it in the external variable "pat". The "pat" is not
+ * updated if the user types in an empty line. If the user typed an empty
+ * line, and there is no old pattern, it is an error. Display the old pattern,
+ * in the style of Jeff Lomicka. There is some do-it-yourself control
+ * expansion.
*/
+int
readpattern(prompt)
- char *prompt;
+ char *prompt;
{
- register int s;
- char tpat[NPAT];
+ int s;
+ char tpat[NPAT];
if (tpat[0] == '\0')
s = ereply("%s: ", tpat, NPAT, prompt);
else
s = ereply("%s: (default %s) ", tpat, NPAT, prompt, pat);
- if (s == TRUE) /* Specified */
+ /* specified */
+ if (s == TRUE)
(VOID) strcpy(pat, tpat);
- else if (s == FALSE && pat[0] != 0) /* CR, but old one */
+ /* CR, but old one */
+ else if (s == FALSE && pat[0] != 0)
s = TRUE;
return s;
}
diff --git a/usr.bin/mg/spawn.c b/usr.bin/mg/spawn.c
index e8708064522..c8e2c99020c 100644
--- a/usr.bin/mg/spawn.c
+++ b/usr.bin/mg/spawn.c
@@ -2,22 +2,24 @@
* Spawn. Actually just suspends Mg.
* Assumes POSIX job control.
*/
-#include "def.h"
-#include <signal.h>
-#include <termios.h>
-#include <term.h>
+#include "def.h"
+
+#include <signal.h>
+#include <termios.h>
+#include <term.h>
/*
- * This causes mg to send itself a stop signal.
- * Assumes the parent shell supports POSIX job control.
- * If the terminal supports an alternate screen, we will sitch to it.
+ * This causes mg to send itself a stop signal. It assumes the parent
+ * shell supports POSIX job control. If the terminal supports an alternate
+ * screen, we will switch to it.
*/
/* ARGSUSED */
+int
spawncli(f, n)
+ int f, n;
{
- sigset_t oset;
- int ttputc __P((int)); /* XXX */
+ sigset_t oset;
/* Very similar to what vttidy() does. */
ttcolor(CTEXT);
@@ -28,13 +30,17 @@ spawncli(f, n)
epresf = FALSE;
}
if (ttcooked() == FALSE)
- return (FALSE);
- tttidy(); /* Exit application mode and tidy. */
+ return(FALSE);
+
+ /* Exit application mode and tidy. */
+ tttidy();
ttflush();
- (void) sigprocmask(SIG_SETMASK, NULL, &oset);
- (void) kill(0, SIGTSTP);
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
+ (void)sigprocmask(SIG_SETMASK, NULL, &oset);
+ (void)kill(0, SIGTSTP);
+ (void)sigprocmask(SIG_SETMASK, &oset, NULL);
ttreinit();
- sgarbf = TRUE; /* Force repaint. */
+
+ /* Force repaint. */
+ sgarbf = TRUE;
return ttraw();
}
diff --git a/usr.bin/mg/tty.c b/usr.bin/mg/tty.c
index e976f608ca7..470296c532b 100644
--- a/usr.bin/mg/tty.c
+++ b/usr.bin/mg/tty.c
@@ -22,28 +22,20 @@
* Using scrolling region vs insert/delete line should probably be based on cost
* rather than the assuption that scrolling region operations look better.
*/
-#include "def.h"
-#include <term.h>
+#include "def.h"
-extern int ttrow;
-extern int ttcol;
-extern int tttop;
-extern int ttbot;
-extern int tthue;
+#include <term.h>
-extern int ttputc();
-
-int tceeol; /* Costs are set later */
-int tcinsl;
-int tcdell;
+#ifdef NO_RESIZE
+static int setttysize __P((void));
+#endif /* NO_RESIZE */
-static int insdel; /* Do we have both insert & delete line? */
-static char *scroll_fwd; /* How to scroll forward. */
+static int charcost __P((char *));
-#ifdef NO_RESIZE
-static setttysize();
-#endif
+static int cci;
+static int insdel; /* Do we have both insert & delete line? */
+static char *scroll_fwd; /* How to scroll forward. */
/*
* Initialize the terminal when the editor
@@ -52,29 +44,34 @@ static setttysize();
VOID
ttinit()
{
- char *tv_stype;
- char *t, *p;
-#ifndef gettermtype /* (avoid declaration if #define) */
- char *gettermtype(); /* system dependent function to
- * determin terminal type */
-#endif
+ char *tv_stype, *p;
+
+/* system dependent function to determine terminal type, if necessary. */
+#ifndef gettermtype
+ char *gettermtype();
+#endif /* gettermtype */
if ((tv_stype = gettermtype()) == NULL)
- panic("Could not determine terminal type");
+ panic("Could not determine terminal type!");
+
if (setupterm(tv_stype, 1, NULL)) {
- (void) asprintf(&p, "Unknown terminal type: %s", tv_stype);
+ (void)asprintf(&p, "Unknown terminal type: %s", tv_stype);
panic(p);
}
+
scroll_fwd = scroll_forward;
- if (!scroll_fwd || !*scroll_fwd) {
+ if (scroll_fwd == NULL || *scroll_fwd == '\0') {
/* this is what GNU Emacs does */
scroll_fwd = parm_down_cursor;
- if (!scroll_fwd || !*scroll_fwd)
+ if (scroll_fwd == NULL || *scroll_fwd == '\0')
scroll_fwd = "\n";
}
- if (!cursor_address || !cursor_up)
- panic("This terminal is to stupid to run mg");
- ttresize(); /* set nrow & ncol */
+
+ if (cursor_address == NULL || cursor_up == NULL)
+ panic("This terminal is too stupid to run mg");
+
+ /* set nrow & ncol */
+ ttresize();
if (!clr_eol)
tceeol = ncol;
@@ -84,30 +81,34 @@ ttinit()
/* Estimate cost of inserting a line */
if (change_scroll_region && scroll_reverse)
tcinsl = charcost(change_scroll_region) * 2 +
- charcost(scroll_reverse);
+ charcost(scroll_reverse);
else if (parm_insert_line)
tcinsl = charcost(parm_insert_line);
else if (insert_line)
tcinsl = charcost(insert_line);
else
- tcinsl = NROW * NCOL; /* make this cost high enough */
+ /* make this cost high enough */
+ tcinsl = NROW * NCOL;
/* Estimate cost of deleting a line */
if (change_scroll_region)
tcdell = charcost(change_scroll_region) * 2 +
- charcost(scroll_fwd);
+ charcost(scroll_fwd);
else if (parm_delete_line)
tcdell = charcost(parm_delete_line);
else if (delete_line)
tcdell = charcost(delete_line);
else
- tcdell = NROW * NCOL; /* make this cost high enough */
+ /* make this cost high enough */
+ tcdell = NROW * NCOL;
/* Flag to indicate that we can both insert and delete lines */
- insdel = (insert_line || parm_insert_line) && (delete_line || parm_delete_line);
+ insdel = (insert_line || parm_insert_line) &&
+ (delete_line || parm_delete_line);
if (enter_ca_mode)
- putpad(enter_ca_mode, 1); /* enter application mode */
+ /* enter application mode */
+ putpad(enter_ca_mode, 1);
setttysize();
}
@@ -120,45 +121,42 @@ VOID
ttreinit()
{
if (enter_ca_mode)
- putpad(enter_ca_mode, 1); /* enter application mode */
+ /* enter application mode */
+ putpad(enter_ca_mode, 1);
if (keypad_xmit)
- putpad(keypad_xmit, 1); /* turn on keypad */
+ /* turn on keypad */
+ putpad(keypad_xmit, 1);
setttysize();
}
/*
- * Clean up the terminal, in anticipation of
- * a return to the command interpreter. This is a no-op
- * on the ANSI display. On the SCALD display, it sets the
- * window back to half screen scrolling. Perhaps it should
- * query the display for the increment, and put it
- * back to what it was.
+ * Clean up the terminal, in anticipation of a return to the command
+ * interpreter. This is a no-op on the ANSI display. On the SCALD display,
+ * it sets the window back to half screen scrolling. Perhaps it should
+ * query the display for the increment, and put it back to what it was.
*/
VOID
tttidy()
{
-
#ifdef XKEYS
ttykeymaptidy();
-#endif
+#endif /* XKEYS */
+
/* set the term back to normal mode */
if (exit_ca_mode)
putpad(exit_ca_mode, 1);
}
/*
- * Move the cursor to the specified
- * origin 0 row and column position. Try to
- * optimize out extra moves; redisplay may
- * have left the cursor in the right
+ * Move the cursor to the specified origin 0 row and column position. Try to
+ * optimize out extra moves; redisplay may have left the cursor in the right
* location last time!
*/
VOID
ttmove(row, col)
+ int row, col;
{
- char *tgoto();
-
if (ttrow != row || ttcol != col) {
putpad(tgoto(cursor_address, col, row), 1);
ttrow = row;
@@ -172,11 +170,12 @@ ttmove(row, col)
VOID
tteeol()
{
+ int i;
if (clr_eol)
putpad(clr_eol, 1);
else {
- int i = ncol - ttcol;
+ i = ncol - ttcol;
while (i--)
ttputc(' ');
ttrow = ttcol = HUGE;
@@ -189,7 +188,7 @@ tteeol()
VOID
tteeop()
{
- int line;
+ int line;
if (clr_eos)
putpad(clr_eos, nrow - ttrow);
@@ -197,7 +196,8 @@ tteeop()
putpad(clr_eol, 1);
if (insdel)
ttdell(ttrow + 1, lines, lines - ttrow - 1);
- else { /* do it by hand */
+ else {
+ /* do it by hand */
for (line = ttrow + 1; line <= lines; ++line) {
ttmove(line, 0);
tteeol();
@@ -218,20 +218,20 @@ ttbeep()
}
/*
- * Insert nchunk blank line(s) onto the
- * screen, scrolling the last line on the
- * screen off the bottom. Use the scrolling
- * region if possible for a smoother display.
- * If no scrolling region, use a set
- * of insert and delete line sequences
+ * Insert nchunk blank line(s) onto the screen, scrolling the last line on
+ * the screen off the bottom. Use the scrolling region if possible for a
+ * smoother display. If there is no scrolling region, use a set of insert
+ * and delete line sequences.
*/
VOID
ttinsl(row, bot, nchunk)
+ int row, bot, nchunk;
{
- int i, nl;
+ int i, nl;
- if (row == bot) { /* Case of one line insert is */
- ttmove(row, 0); /* special */
+ /* Case of one line insert is special. */
+ if (row == bot) {
+ ttmove(row, 0);
tteeol();
return;
}
@@ -250,11 +250,14 @@ ttinsl(row, bot, nchunk)
if (parm_delete_line)
putpad(tgoto(parm_delete_line, 0, nchunk), nl);
else
- /* For all lines in the chunk */
+ /* For all lines in the chunk... */
for (i = 0; i < nchunk; i++)
putpad(delete_line, nl);
ttmove(row, 0);
- nl = nrow - ttrow; /* ttmove() changes ttrow */
+
+ /* ttmove() changes ttrow */
+ nl = nrow - ttrow;
+
if (parm_insert_line)
putpad(tgoto(parm_insert_line, 0, nchunk), nl);
else
@@ -268,32 +271,34 @@ ttinsl(row, bot, nchunk)
}
/*
- * Delete nchunk line(s) from "row", replacing the
- * bottom line on the screen with a blank line.
- * Unless we're using the scrolling region, this is
- * done with a crafty sequences of insert and delete
- * lines. The presence of the echo area makes a
- * boundry condition go away.
+ * Delete nchunk line(s) from "row", replacing the bottom line on the
+ * screen with a blank line. Unless we're using the scrolling region,
+ * this is done with crafty sequences of insert and delete lines. The
+ * presence of the echo area makes a boundry condition go away.
*/
VOID
ttdell(row, bot, nchunk)
+ int row, bot, nchunk;
{
- int i, nl;
+ int i, nl;
- if (row == bot) { /* One line special case */
+ /* One line special cases */
+ if (row == bot) {
ttmove(row, 0);
tteeol();
return;
}
- if (change_scroll_region) { /* scrolling region */
+ /* scrolling region */
+ if (change_scroll_region) {
nl = bot - row;
ttwindow(row, bot);
ttmove(bot, 0);
while (nchunk--)
putpad(scroll_fwd, nl);
ttnowindow();
+ /* else use insert/delete line */
} else if (insdel) {
- ttmove(row, 0); /* Else use insert/delete line */
+ ttmove(row, 0);
nl = nrow - ttrow;
if (parm_delete_line)
putpad(tgoto(parm_delete_line, 0, nchunk), nl);
@@ -302,7 +307,9 @@ ttdell(row, bot, nchunk)
for (i = 0; i < nchunk; i++)
putpad(delete_line, nl);
ttmove(1 + bot - nchunk, 0);
- nl = nrow - ttrow; /* ttmove() changes ttrow */
+
+ /* ttmove() changes ttrow */
+ nl = nrow - ttrow;
if (parm_insert_line)
putpad(tgoto(parm_insert_line, 0, nchunk), nl);
else
@@ -316,19 +323,16 @@ ttdell(row, bot, nchunk)
}
/*
- * This routine sets the scrolling window
- * on the display to go from line "top" to line
- * "bot" (origin 0, inclusive). The caller checks
- * for the pathalogical 1 line scroll window that
- * doesn't work right, and avoids it. The "ttrow"
- * and "ttcol" variables are set to a crazy value
- * to ensure that the next call to "ttmove" does
- * not turn into a no-op (the window adjustment
- * moves the cursor).
- *
+ * This routine sets the scrolling window on the display to go from line
+ * "top" to line "bot" (origin 0, inclusive). The caller checks for the
+ * pathological 1-line scroll window which doesn't work right and avoids
+ * it. The "ttrow" and "ttcol" variables are set to a crazy value to
+ * ensure that the next call to "ttmove" does not turn into a no-op (the
+ * window adjustment moves the cursor).
*/
VOID
ttwindow(top, bot)
+ int top, bot;
{
if (change_scroll_region && (tttop != top || ttbot != bot)) {
putpad(tgoto(change_scroll_region, bot, top), nrow - ttrow);
@@ -340,14 +344,12 @@ ttwindow(top, bot)
}
/*
- * Switch to full screen scroll. This is
- * used by "spawn.c" just before is suspends the
- * editor, and by "display.c" when it is getting ready
- * to exit. This function gets to full screen scroll
- * by telling the terminal to set a scrolling regin
- * that is lines or nrow rows high, whichever is larger.
- * This behavior seems to work right on systems
- * where you can set your terminal size.
+ * Switch to full screen scroll. This is used by "spawn.c" just before it
+ * suspends the editor and by "display.c" when it is getting ready to
+ * exit. This function does a full screen scroll by telling the terminal
+ * to set a scrolling region that is lines or nrow rows high, whichever is
+ * larger. This behavior seems to work right on systems where you can set
+ * your terminal size.
*/
VOID
ttnowindow()
@@ -363,44 +365,43 @@ ttnowindow()
}
/*
- * Set the current writing color to the
- * specified color. Watch for color changes that are
- * not going to do anything (the color is already right)
- * and don't send anything to the display.
- * The rainbow version does this in putline.s on a
- * line by line basis, so don't bother sending
- * out the color shift.
+ * Set the current writing color to the specified color. Watch for color
+ * changes that are not going to do anything (the color is already right)
+ * and don't send anything to the display. The rainbow version does this
+ * in putline.s on a line by line basis, so don't bother sending out the
+ * color shift.
*/
VOID
ttcolor(color)
- int color;
+ int color;
{
-
if (color != tthue) {
- if (color == CTEXT) /* Normal video. */
+ if (color == CTEXT)
+ /* normal video */
putpad(exit_standout_mode, 1);
- else if (color == CMODE) /* Reverse video. */
+ else if (color == CMODE)
+ /* reverse video */
putpad(enter_standout_mode, 1);
- tthue = color; /* Save the color. */
+ /* save the color */
+ tthue = color;
}
}
/*
- * This routine is called by the
- * "refresh the screen" command to try and resize
- * the display. The new size, which must be deadstopped
- * to not exceed the NROW and NCOL limits, it stored
- * back into "nrow" and "ncol". Display can always deal
- * with a screen NROW by NCOL. Look in "window.c" to
- * see how the caller deals with a change.
+ * This routine is called by the "refresh the screen" command to try
+ * to resize the display. The new size, which must not exceed the NROW
+ * and NCOL limits, is stored back into "nrow" and * "ncol". Display can
+ * always deal with a screen NROW by NCOL. Look in "window.c" to see how
+ * the caller deals with a change.
*/
VOID
ttresize()
{
+ /* found in "ttyio.c" */
+ setttysize();
- setttysize(); /* found in "ttyio.c", */
- /* ask OS for tty size */
- if (nrow < 1) /* Check limits. */
+ /* ask OS for tty size and check limits */
+ if (nrow < 1)
nrow = 1;
else if (nrow > NROW)
nrow = NROW;
@@ -417,23 +418,26 @@ setttysize()
nrow = lines;
ncol = columns;
}
-#endif
-
-static int cci;
+#endif /* NO_RESIZE */
+/*
+ * fake char output for charcost()
+ */
/* ARGSUSED */
-static int /* fake char output for charcost() */
+static int
fakec(c)
- char c;
+ char c;
{
cci++;
+ return 0;
}
/* calculate the cost of doing string s */
+static int
charcost(s)
- char *s;
+ char *s;
{
- cci = 0;
+ int cci = 0;
tputs(s, nrow, fakec);
return (cci);
diff --git a/usr.bin/mg/ttykbd.c b/usr.bin/mg/ttykbd.c
index b10712f5c46..fac0b871ffd 100644
--- a/usr.bin/mg/ttykbd.c
+++ b/usr.bin/mg/ttykbd.c
@@ -4,10 +4,11 @@
* Created: 22-Nov-1987 Mic Kaczmarczik (mic@emx.cc.utexas.edu)
*/
-#include "def.h"
-#include "kbd.h"
+#include "def.h"
+#include "kbd.h"
+
#ifdef XKEYS
-#include <term.h>
+#include <term.h>
#ifdef FKEYS
/*
@@ -18,19 +19,18 @@
*/
char *keystrings[] = {NULL};
-#endif
+#endif /* FKEYS */
/*
* Turn on function keys using keypad_xmit, then load a keys file, if
* available. The keys file is located in the same manner as the startup
* file is, depending on what startupfile() does on your system.
*/
-extern int ttputc();
-
+void
ttykeymapinit()
{
- extern int dobindkey(); /* XXX */
- char *cp;
+ char *cp;
+
#ifdef FKEYS
/* Bind keypad function keys. */
if (key_left)
@@ -51,27 +51,28 @@ ttykeymapinit()
dobindkey(map_table[0].p_map, "scroll-up", key_npage);
if (key_ppage)
dobindkey(map_table[0].p_map, "scroll-down", key_ppage);
-#endif
+#endif /* FKEYS */
+
#ifndef NO_STARTUP
- if (cp = gettermtype()) {
- extern char *startupfile();
- if (((cp = startupfile(cp)) != NULL)
- && (load(cp) != TRUE))
+ if ((cp = gettermtype())) {
+ if (((cp = startupfile(cp)) != NULL) && (load(cp) != TRUE))
ewprintf("Error reading key initialization file");
}
-#endif
- if (keypad_xmit) /* turn on keypad */
+#endif /* !NO_STARTUP */
+ if (keypad_xmit)
+ /* turn on keypad */
putpad(keypad_xmit, 1);
}
/*
* Clean up the keyboard -- called by tttidy()
*/
+void
ttykeymaptidy()
{
-
if (keypad_local)
- putpad(keypad_local, 1); /* turn off keypad */
+ /* turn off keypad */
+ putpad(keypad_local, 1);
}
-#endif
+#endif /* XKEYS */
diff --git a/usr.bin/mg/version.c b/usr.bin/mg/version.c
index 846c873e87f..3b375f02b93 100644
--- a/usr.bin/mg/version.c
+++ b/usr.bin/mg/version.c
@@ -3,18 +3,18 @@
* out by the emacs-version command.
*/
-#define TRUE 1 /* include "def.h" when things get more
- * complicated */
+#include "def.h"
-char version[] = "Mg 2a";
+char version[] = "Mg 2a";
/*
* Display the version. All this does
* is copy the version string onto the echo line.
*/
/* ARGSUSED */
+int
showversion(f, n)
- int f, n;
+ int f, n;
{
ewprintf(version);
return TRUE;
diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c
index e9a9c17f1db..648896a5c05 100644
--- a/usr.bin/mg/window.c
+++ b/usr.bin/mg/window.c
@@ -1,61 +1,64 @@
/*
* Window handling.
*/
-#include "def.h"
+
+#include "def.h"
/*
- * Reposition dot in the current
- * window to line "n". If the argument is
- * positive, it is that line. If it is negative it
- * is that line from the bottom. If it is 0 the window
- * is centered (this is what the standard redisplay code
- * does). If GOSREC is undefined, default is 0, so it acts like GNU.
- * If GOSREC is defined, with no argument it defaults to 1
- * and works like in Gosling.
+ * Reposition dot in the current window to line "n". If the argument is
+ * positive, it is that line. If it is negative it is that line from the
+ * bottom. If it is 0 the window is centered (this is what the standard
+ * redisplay code does). If GOSREC is undefined, default is 0, so it acts
+ * like GNU. If GOSREC is defined, with no argument it defaults to 1 and
+ * works like in Gosling.
*/
/* ARGSUSED */
+int
reposition(f, n)
+ int f, n;
{
#ifndef GOSREC
curwp->w_force = (f & FFARG) ? (n >= 0 ? n + 1 : n) : 0;
-#else
+#else /* !GOSREC */
curwp->w_force = n;
-#endif
+#endif /* !GOSREC */
curwp->w_flag |= WFFORCE;
sgarbf = TRUE;
return TRUE;
}
/*
- * Refresh the display. A call is made to the
- * "ttresize" entry in the terminal handler, which tries
- * to reset "nrow" and "ncol". They will, however, never
- * be set outside of the NROW or NCOL range. If the display
- * changed size, arrange that everything is redone, then
- * call "update" to fix the display. We do this so the
- * new size can be displayed. In the normal case the
- * call to "update" in "main.c" refreshes the screen,
- * and all of the windows need not be recomputed.
- * Note that when you get to the "display unusable"
- * message, the screen will be messed up. If you make
- * the window bigger again, and send another command,
- * everything will get fixed!
+ * Refresh the display. A call is made to the "ttresize" entry in the
+ * terminal handler, which tries to reset "nrow" and "ncol". They will,
+ * however, never be set outside of the NROW or NCOL range. If the display
+ * changed size, arrange that everything is redone, then call "update" to
+ * fix the display. We do this so the new size can be displayed. In the
+ * normal case the call to "update" in "main.c" refreshes the screen, and
+ * all of the windows need not be recomputed. Note that when you get to the
+ * "display unusable" message, the screen will be messed up. If you make the
+ * window bigger again, and send another command, everything will get fixed!
*/
/* ARGSUSED */
+int
refresh(f, n)
+ int f, n;
{
- register MGWIN *wp;
- register int oldnrow;
- register int oldncol;
+ MGWIN *wp;
+ int oldnrow;
+ int oldncol;
oldnrow = nrow;
oldncol = ncol;
ttresize();
if (nrow != oldnrow || ncol != oldncol) {
- wp = wheadp; /* Find last. */
+
+ /* find last */
+ wp = wheadp;
while (wp->w_wndp != NULL)
wp = wp->w_wndp;
- if (nrow < wp->w_toprow + 3) { /* Check if too small. */
+
+ /* check if too small */
+ if (nrow < wp->w_toprow + 3) {
ewprintf("Display unusable");
return (FALSE);
}
@@ -69,17 +72,16 @@ refresh(f, n)
}
/*
- * The command to make the next
- * window (next => down the screen)
- * the current window. There are no real
- * errors, although the command does
- * nothing if there is only 1 window on
- * the screen.
+ * The command to make the next window (next => down the screen) the current
+ * window. There are no real errors, although the command does nothing if
+ * there is only 1 window on the screen.
*/
/* ARGSUSED */
+int
nextwind(f, n)
+ int f, n;
{
- register MGWIN *wp;
+ MGWIN *wp;
if ((wp = curwp->w_wndp) == NULL)
wp = wheadp;
@@ -89,19 +91,19 @@ nextwind(f, n)
}
#ifdef GOSMACS
+
/* not in Gnu Emacs */
/*
- * This command makes the previous
- * window (previous => up the screen) the
- * current window. There arn't any errors,
- * although the command does not do a lot
- * if there is 1 window.
+ * This command makes the previous window (previous => up the screen) the
+ * current window. There are no errors, although the command does not do
+ * a lot if there is only 1 window.
*/
/* ARGSUSED */
+int
prevwind(f, n)
+ int f, n;
{
- register MGWIN *wp1;
- register MGWIN *wp2;
+ MGWIN *wp1, *wp2;
wp1 = wheadp;
wp2 = curwp;
@@ -113,25 +115,23 @@ prevwind(f, n)
curbp = wp1->w_bufp;
return TRUE;
}
-#endif
+#endif /* GOSEMACS */
/*
- * This command makes the current
- * window the only window on the screen.
- * Try to set the framing
- * so that "." does not have to move on
- * the display. Some care has to be taken
- * to keep the values of dot and mark
- * in the buffer structures right if the
- * distruction of a window makes a buffer
- * become undisplayed.
+ * This command makes the current window the only window on the screen. Try
+ * to set the framing so that "." does not have to move on the display. Some
+ * care has to be taken to keep the values of dot and mark in the buffer
+ * structures right if the distruction of a window makes a buffer become
+ * undisplayed.
*/
/* ARGSUSED */
+int
onlywind(f, n)
+ int f, n;
{
- register MGWIN *wp;
- register LINE *lp;
- register int i;
+ MGWIN *wp;
+ LINE *lp;
+ int i;
while (wheadp != curwp) {
wp = wheadp;
@@ -142,7 +142,7 @@ onlywind(f, n)
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
- free((char *) wp);
+ free((char *)wp);
}
while (curwp->w_wndp != NULL) {
wp = curwp->w_wndp;
@@ -153,7 +153,7 @@ onlywind(f, n)
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
- free((char *) wp);
+ free((char *)wp);
}
lp = curwp->w_linep;
i = curwp->w_toprow;
@@ -162,38 +162,39 @@ onlywind(f, n)
lp = lback(lp);
}
curwp->w_toprow = 0;
- curwp->w_ntrows = nrow - 2; /* 2 = mode, echo. */
+
+ /* 2 = mode, echo */
+ curwp->w_ntrows = nrow - 2;
curwp->w_linep = lp;
curwp->w_flag |= WFMODE | WFHARD;
return TRUE;
}
/*
- * Split the current window. A window
- * smaller than 3 lines cannot be split.
- * The only other error that is possible is
- * a "malloc" failure allocating the structure
- * for the new window.
+ * Split the current window. A window smaller than 3 lines cannot be split.
+ * The only other error that is possible is a "malloc" failure allocating the
+ * structure for the new window.
*/
/* ARGSUSED */
+int
splitwind(f, n)
+ int f, n;
{
- register MGWIN *wp;
- register LINE *lp;
- register int ntru;
- register int ntrd;
- int ntrl;
- MGWIN *wp1, *wp2;
+ MGWIN *wp, *wp1, *wp2;
+ LINE *lp;
+ int ntru, ntrd, ntrl;
if (curwp->w_ntrows < 3) {
ewprintf("Cannot split a %d line window", curwp->w_ntrows);
return (FALSE);
}
- if ((wp = (MGWIN *) malloc(sizeof(MGWIN))) == NULL) {
+ if ((wp = (MGWIN *)malloc(sizeof(MGWIN))) == NULL) {
ewprintf("Can't get %d", sizeof(MGWIN));
return (FALSE);
}
- ++curbp->b_nwnd; /* Displayed twice. */
+
+ /* displayed twice */
+ ++curbp->b_nwnd;
wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp;
wp->w_doto = curwp->w_doto;
@@ -210,15 +211,19 @@ splitwind(f, n)
lp = lforw(lp);
}
lp = curwp->w_linep;
- if (ntrd <= ntru) { /* Old is upper window. */
- if (ntrd == ntru) /* Hit mode line. */
+
+ /* old is upper window */
+ if (ntrd <= ntru) {
+ /* hit mode line */
+ if (ntrd == ntru)
lp = lforw(lp);
curwp->w_ntrows = ntru;
wp->w_wndp = curwp->w_wndp;
curwp->w_wndp = wp;
wp->w_toprow = curwp->w_toprow + ntru + 1;
wp->w_ntrows = ntrl;
- } else { /* Old is lower window */
+ /* old is lower window */
+ } else {
wp1 = NULL;
wp2 = wheadp;
while (wp2 != curwp) {
@@ -232,33 +237,38 @@ splitwind(f, n)
wp->w_wndp = curwp;
wp->w_toprow = curwp->w_toprow;
wp->w_ntrows = ntru;
- ++ntru; /* Mode line. */
+
+ /* mode line */
+ ++ntru;
curwp->w_toprow += ntru;
curwp->w_ntrows = ntrl;
while (ntru--)
lp = lforw(lp);
}
- curwp->w_linep = lp; /* Adjust the top lines */
- wp->w_linep = lp; /* if necessary. */
+
+ /* adjust the top lines if necessary */
+ curwp->w_linep = lp;
+ wp->w_linep = lp;
+
curwp->w_flag |= WFMODE | WFHARD;
wp->w_flag |= WFMODE | WFHARD;
return TRUE;
}
/*
- * Enlarge the current window.
- * Find the window that loses space. Make
- * sure it is big enough. If so, hack the window
- * descriptions, and ask redisplay to do all the
- * hard work. You don't just set "force reframe"
- * because dot would move.
+ * Enlarge the current window. Find the window that loses space. Make sure
+ * it is big enough. If so, hack the window descriptions, and ask redisplay
+ * to do all the hard work. You don't just set "force reframe" because dot
+ * would move.
*/
/* ARGSUSED */
+int
enlargewind(f, n)
+ int f, n;
{
- register MGWIN *adjwp;
- register LINE *lp;
- register int i;
+ MGWIN *adjwp;
+ LINE *lp;
+ int i;
if (n < 0)
return shrinkwind(f, -n);
@@ -275,13 +285,16 @@ enlargewind(f, n)
ewprintf("Impossible change");
return FALSE;
}
- if (curwp->w_wndp == adjwp) { /* Shrink below. */
+
+ /* shrink below */
+ if (curwp->w_wndp == adjwp) {
lp = adjwp->w_linep;
for (i = 0; i < n && lp != adjwp->w_bufp->b_linep; ++i)
lp = lforw(lp);
adjwp->w_linep = lp;
adjwp->w_toprow += n;
- } else { /* Shrink above. */
+ /* shrink above */
+ } else {
lp = curwp->w_linep;
for (i = 0; i < n && lback(lp) != curbp->b_linep; ++i)
lp = lback(lp);
@@ -296,16 +309,16 @@ enlargewind(f, n)
}
/*
- * Shrink the current window.
- * Find the window that gains space. Hack at
- * the window descriptions. Ask the redisplay to
- * do all the hard work.
+ * Shrink the current window. Find the window that gains space. Hack at the
+ * window descriptions. Ask the redisplay to do all the hard work.
*/
+int
shrinkwind(f, n)
+ int f, n;
{
- register MGWIN *adjwp;
- register LINE *lp;
- register int i;
+ MGWIN *adjwp;
+ LINE *lp;
+ int i;
if (n < 0)
return enlargewind(f, -n);
@@ -326,13 +339,16 @@ shrinkwind(f, n)
while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp;
}
- if (curwp->w_wndp == adjwp) { /* Grow below. */
+
+ /* grow below */
+ if (curwp->w_wndp == adjwp) {
lp = adjwp->w_linep;
for (i = 0; i < n && lback(lp) != adjwp->w_bufp->b_linep; ++i)
lp = lback(lp);
adjwp->w_linep = lp;
adjwp->w_toprow -= n;
- } else { /* Grow above. */
+ /* grow above */
+ } else {
lp = curwp->w_linep;
for (i = 0; i < n && lp != curbp->b_linep; ++i)
lp = lforw(lp);
@@ -347,15 +363,18 @@ shrinkwind(f, n)
}
/*
- * Delete current window. Call shrink-window to do the screen
- * updating, then throw away the window.
+ * Delete current window. Call shrink-window to do the screen updating, then
+ * throw away the window.
*/
/* ARGSUSED */
+int
delwind(f, n)
+ int f, n;
{
- register MGWIN *wp, *nwp;
+ MGWIN *wp, *nwp;
wp = curwp; /* Cheap... */
+
/* shrinkwind returning false means only one window... */
if (shrinkwind(FFRAND, wp->w_ntrows + 1) == FALSE)
return FALSE;
@@ -365,6 +384,7 @@ delwind(f, n)
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
+
/* since shrinkwind did't crap out, we know we have a second window */
if (wp == wheadp)
wheadp = curwp = wp->w_wndp;
@@ -376,26 +396,27 @@ delwind(f, n)
nwp->w_wndp = wp->w_wndp;
break;
}
- free((char *) wp);
+ free((char *)wp);
return TRUE;
}
+
/*
- * Pick a window for a pop-up.
- * Split the screen if there is only
- * one window. Pick the uppermost window that
- * isn't the current window. An LRU algorithm
- * might be better. Return a pointer, or
- * NULL on error.
+ * Pick a window for a pop-up. Split the screen if there is only one window.
+ * Pick the uppermost window that isn't the current window. An LRU algorithm
+ * might be better. Return a pointer, or NULL on error.
*/
MGWIN *
wpopup()
{
- register MGWIN *wp;
+ MGWIN *wp;
if (wheadp->w_wndp == NULL
&& splitwind(FFRAND, 0) == FALSE)
return NULL;
- wp = wheadp; /* Find window to use */
+
+ /* find a window to use */
+ wp = wheadp;
+
while (wp != NULL && wp == curwp)
wp = wp->w_wndp;
return wp;
diff --git a/usr.bin/mg/word.c b/usr.bin/mg/word.c
index 859d904f331..b81cf45a92b 100644
--- a/usr.bin/mg/word.c
+++ b/usr.bin/mg/word.c
@@ -1,20 +1,19 @@
/*
* Word mode commands.
- * The routines in this file
- * implement commands that work word at
- * a time. There are all sorts of word mode
- * commands.
+ * The routines in this file implement commands that work word at a time.
+ * There are all sorts of word mode commands.
*/
-#include "def.h"
+
+#include "def.h"
/*
- * Move the cursor backward by
- * "n" words. All of the details of motion
- * are performed by the "backchar" and "forwchar"
- * routines.
+ * Move the cursor backward by "n" words. All of the details of motion are
+ * performed by the "backchar" and "forwchar" routines.
*/
/* ARGSUSED */
+int
backword(f, n)
+ int f, n;
{
if (n < 0)
return forwword(f | FFRAND, -n);
@@ -34,12 +33,13 @@ backword(f, n)
}
/*
- * Move the cursor forward by
- * the specified number of words. All of the
+ * Move the cursor forward by the specified number of words. All of the
* motion is done by "forwchar".
*/
/* ARGSUSED */
+int
forwword(f, n)
+ int f, n;
{
if (n < 0)
return backword(f | FFRAND, -n);
@@ -57,14 +57,15 @@ forwword(f, n)
}
/*
- * Move the cursor forward by
- * the specified number of words. As you move,
+ * Move the cursor forward by the specified number of words. As you move,
* convert any characters to upper case.
*/
/* ARGSUSED */
+int
upperword(f, n)
+ int f, n;
{
- register int c;
+ int c;
if (n < 0)
return FALSE;
@@ -88,14 +89,15 @@ upperword(f, n)
}
/*
- * Move the cursor forward by
- * the specified number of words. As you move
+ * Move the cursor forward by the specified number of words. As you move
* convert characters to lower case.
*/
/* ARGSUSED */
+int
lowerword(f, n)
+ int f, n;
{
- register int c;
+ int c;
if (n < 0)
return FALSE;
@@ -119,17 +121,17 @@ lowerword(f, n)
}
/*
- * Move the cursor forward by
- * the specified number of words. As you move
- * convert the first character of the word to upper
- * case, and subsequent characters to lower case. Error
- * if you try and move past the end of the buffer.
+ * Move the cursor forward by the specified number of words. As you move
+ * convert the first character of the word to upper case, and subsequent
+ * characters to lower case. Error if you try to move past the end of the
+ * buffer.
*/
/* ARGSUSED */
+int
capword(f, n)
+ int f, n;
{
- register int c;
- VOID lchange();
+ int c;
if (n < 0)
return FALSE;
@@ -166,29 +168,37 @@ capword(f, n)
* Kill forward by "n" words.
*/
/* ARGSUSED */
+int
delfword(f, n)
+ int f, n;
{
- register RSIZE size;
- register LINE *dotp;
- register int doto;
+ RSIZE size;
+ LINE *dotp;
+ int doto;
if (n < 0)
return FALSE;
- if ((lastflag & CFKILL) == 0) /* Purge kill buffer. */
+
+ /* purge kill buffer */
+ if ((lastflag & CFKILL) == 0)
kdelete();
+
thisflag |= CFKILL;
dotp = curwp->w_dotp;
doto = curwp->w_doto;
size = 0;
+
while (n--) {
while (inword() == FALSE) {
if (forwchar(FFRAND, 1) == FALSE)
- goto out; /* Hit end of buffer. */
+ /* hit the end of the buffer */
+ goto out;
++size;
}
while (inword() != FALSE) {
if (forwchar(FFRAND, 1) == FALSE)
- goto out; /* Hit end of buffer. */
+ /* hit the end of the buffer */
+ goto out;
++size;
}
}
@@ -199,56 +209,62 @@ out:
}
/*
- * Kill backwards by "n" words. The rules
- * for success and failure are now different, to prevent
- * strange behavior at the start of the buffer. The command
- * only fails if something goes wrong with the actual delete
- * of the characters. It is successful even if no characters
- * are deleted, or if you say delete 5 words, and there are
- * only 4 words left. I considered making the first call
- * to "backchar" special, but decided that that would just
- * be wierd. Normally this is bound to "M-Rubout" and
- * to "M-Backspace".
+ * Kill backwards by "n" words. The rules for success and failure are now
+ * different, to prevent strange behavior at the start of the buffer. The
+ * command only fails if something goes wrong with the actual delete of the
+ * characters. It is successful even if no characters are deleted, or if you
+ * say delete 5 words, and there are only 4 words left. I considered making
+ * the first call to "backchar" special, but decided that that would just be
+ * weird. Normally this is bound to "M-Rubout" and to "M-Backspace".
*/
/* ARGSUSED */
+int
delbword(f, n)
+ int f, n;
{
- register RSIZE size;
- VOID kdelete();
+ RSIZE size;
if (n < 0)
return FALSE;
- if ((lastflag & CFKILL) == 0) /* Purge kill buffer. */
+
+ /* purge kill buffer */
+ if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
if (backchar(FFRAND, 1) == FALSE)
- return (TRUE); /* Hit buffer start. */
- size = 1; /* One deleted. */
+ /* hit buffer start */
+ return (TRUE);
+
+ /* one deleted */
+ size = 1;
while (n--) {
while (inword() == FALSE) {
if (backchar(FFRAND, 1) == FALSE)
- goto out; /* Hit buffer start. */
+ /* hit buffer start */
+ goto out;
++size;
}
while (inword() != FALSE) {
if (backchar(FFRAND, 1) == FALSE)
- goto out; /* Hit buffer start. */
+ /* hit buffer start */
+ goto out;
++size;
}
}
if (forwchar(FFRAND, 1) == FALSE)
return FALSE;
- --size; /* Undo assumed delete. */
+
+ /* undo assumed delete */
+ --size;
out:
return ldelete(size, KBACK);
}
/*
- * Return TRUE if the character at dot
- * is a character that is considered to be
- * part of a word. The word character list is hard
- * coded. Should be setable.
+ * Return TRUE if the character at dot is a character that is considered to be
+ * part of a word. The word character list is hard coded. Should be setable.
*/
+int
inword()
{
/* can't use lgetc in ISWORD due to bug in OSK cpp */