From d890880a520e9f904058951f27a6cab9703b4605 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Tue, 3 Aug 2021 13:37:06 +0800 Subject: [PATCH] Revise bindable functions usage of struct to named types. --- execute.c | 6 +- file.c | 130 +++++++++++---------------- file.h | 22 +++-- line.c | 169 +++++++++++++++++------------------ line.h | 18 ++-- names.c | 16 ---- random.c | 258 ++++++++++++++++++++---------------------------------- random.h | 67 +++++++------- region.c | 97 ++++++++------------ region.h | 27 +++--- search.c | 70 +++++++-------- search.h | 20 +++-- spawn.c | 6 +- spawn.h | 20 +++-- word.c | 32 ++----- word.h | 36 ++++---- 16 files changed, 427 insertions(+), 567 deletions(-) diff --git a/execute.c b/execute.c index d96bcf3..875f91d 100644 --- a/execute.c +++ b/execute.c @@ -78,7 +78,7 @@ static int insbrace( int n, int c) { count = 1 ; do { - if( boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) { + if( boundary( curwp->w_dotp, curwp->w_doto, REVERSE)) { /* at beginning of buffer, no match to be found */ curwp->w_dotp = oldlp ; curwp->w_doto = oldoff ; @@ -166,7 +166,7 @@ static void fmatch( int ch) { do { /* At beginning of window or buffer, no match to be found */ if( curwp->w_dotp == toplp - || boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) + || boundary( curwp->w_dotp, curwp->w_doto, REVERSE)) break ; backchar( FALSE, 1) ; @@ -261,7 +261,7 @@ BINDABLE( getfence) { /* scan until we find a match, or reach the end of file */ count = 1 ; do { - if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) { + if( boundary( curwp->w_dotp, curwp->w_doto, sdir)) { /* at buffer limit, no match to be found */ /* restore the current position */ curwp->w_dotp = oldlp ; diff --git a/file.c b/file.c index 68fe898..d372541 100644 --- a/file.c +++ b/file.c @@ -1,5 +1,4 @@ /* file.c -- implements file.h */ - #include "file.h" /* file.c @@ -65,21 +64,17 @@ boolean resterr( void) { return FALSE ; } -/* - * Read a file into the current - * buffer. This is really easy; all you do is - * find the name of the file, and call the standard - * "read a file into the current buffer" code. - * Bound to "C-X C-R". +/* Read a file into the current buffer. This is really easy; all you do is + * find the name of the file, and call the standard "read a file into the + * current buffer" code. Bound to C-X C-R read-file. */ -int fileread( int f, int n) { - int status ; +BINDABLE( fileread) { char *fname ; if( restflag) /* don't allow this command if restricted */ return resterr() ; - status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ; + int status = newmlarg( &fname, "read-file: ", sizeof( fname_t)) ; if( status == TRUE) { status = readin( fname, TRUE) ; free( fname) ; @@ -88,25 +83,19 @@ int fileread( int f, int n) { return status ; } -/* - * Insert a file into the current - * buffer. This is really easy; all you do is - * find the name of the file, and call the standard - * "insert a file into the current buffer" code. - * Bound to "C-X C-I". +/* Insert a file into the current buffer. This is really easy; all you do + * is find the name of the file, and call the standard "insert a file into + * the current buffer" code. Bound to C-X C-I insert-file. */ -int insfile( int f, int n) { - int status ; +BINDABLE( insfile) { char *fname ; if( restflag) /* don't allow this command if restricted */ return resterr() ; -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; - status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ; + int status = newmlarg( &fname, "insert-file: ", sizeof( fname_t)) ; if( status == TRUE) { status = ifile( fname) ; free( fname) ; @@ -118,23 +107,18 @@ int insfile( int f, int n) { return reposition( TRUE, -1) ; /* Redraw with dot at bottom of window */ } -/* - * 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. - * Bound to C-X C-F. +/* 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. Bound to C-X C-F find-file. */ -int filefind( int f, int n) { +BINDABLE( filefind) { char *fname ; /* file user wishes to find */ - int status ; /* status return */ if( restflag) /* don't allow this command if restricted */ return resterr() ; - status = newmlarg( &fname, "find-file: ", sizeof( fname_t)) ; + int status = newmlarg( &fname, "find-file: ", sizeof( fname_t)) ; if( status == TRUE) { status = getfile( fname, TRUE) ; free( fname) ; @@ -152,16 +136,15 @@ static void upd_mode( void) { wp->w_flag |= WFMODE ; } -int viewfile( int f, int n) { /* visit a file in VIEW mode */ +BINDABLE( viewfile) { /* visit a file in VIEW mode */ char *fname ; /* file user wishes to find */ - int status ; /* status return */ if( restflag) /* don't allow this command if restricted */ return resterr() ; - status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ; + int status = newmlarg( &fname, "view-file: ", sizeof( fname_t)) ; if( status == TRUE) { - status = getfile(fname, FALSE) ; + status = getfile( fname, FALSE) ; free( fname) ; if( status == TRUE) { /* if we succeed, put it in view mode */ @@ -180,7 +163,7 @@ int viewfile( int f, int n) { /* visit a file in VIEW mode */ * boolean lockfl; check the file for locks? */ int getfile( const char *fname, boolean lockfl) { - struct buffer *bp; + buffer_p bp; int s; bname_t bname ; /* buffer name to put file */ @@ -264,7 +247,7 @@ int getfile( const char *fname, boolean lockfl) { int readin(const char *fname, boolean lockfl) { struct window *wp; - struct buffer *bp; + buffer_p bp; int status ; fio_code s ; @@ -437,23 +420,17 @@ void unqname(char *name) } } -/* - * 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 compatible with Gosling EMACS than - * with ITS EMACS. Bound to "C-X C-W". +/* Ask for a file name, and write the content of the current buffer to that + * file. Update the remembered file name and clear the buffer changed + * flag. Bound to C-X C-W write-file. */ -int filewrite( int f, int n) { - int status ; +BINDABLE( filewrite) { char *fname ; if( restflag) /* don't allow this command if restricted */ return resterr() ; - status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ; + int status = newmlarg( &fname, "write-file: ", sizeof( fname_t)) ; if( status == TRUE) { if( strlen( fname) > sizeof( fname_t) - 1) status = FALSE ; @@ -469,32 +446,27 @@ int filewrite( int f, int n) { return status ; } -/* - * Save the contents of the current - * buffer in its associated file. Do nothing - * if nothing has changed (this may be a bug, not a - * feature). Error if there is no remembered file - * name for the buffer. Bound to "C-X C-S". May - * get called by "C-Z". +/* Save the content of the current buffer in its associated file. Do + * nothing if nothing has changed (this may be a bug, not a feature). + * Error if there is no remembered file name for the buffer. Bound to "C-X + * C-S save-file". May get called by "M-Z quick-exit". */ -int filesave( int f, int n) { -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ +BINDABLE( filesave) { assert( !(curbp->b_mode & MDVIEW)) ; - if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ - return TRUE; - if (curbp->b_fname[0] == 0) { /* Must have a name. */ - mloutstr( "No file name") ; - return FALSE; + if( (curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ + return TRUE ; + + if( curbp->b_fname[0] == 0) { /* Must have a name. */ + mloutfmt( "%BNo file name") ; + return FALSE ; } /* complain about truncated files */ - if ((curbp->b_flag & BFTRUNC) != 0) { - if (mlyesno("Truncated file ... write it out") == FALSE) { - mloutstr( "(Aborted)") ; - return FALSE; - } + if( (curbp->b_flag & BFTRUNC) != 0 + && mlyesno("Truncated file ... write it out") == FALSE) { + mloutfmt( "%B(Aborted)") ; + return FALSE ; } return writeout( curbp->b_fname) ; @@ -544,23 +516,19 @@ int writeout( const char *fn) { return FALSE ; } -/* - * The command allows the user - * to modify the file name associated with - * the current buffer. It is like the "f" command - * in UNIX "ed". The operation is simple; just zap - * the name in the buffer structure, and mark the windows - * as needing an update. You can type a blank line at the - * prompt if you wish. +/* The command allows the user to modify the file name associated with the + current buffer. It is like the "f" command in UNIX "ed". The operation + is simple; just zap the name in the buffer structure, and mark the + windows as needing an update. You can type a blank line at the prompt + if you wish. Bound to C-X N change-file-name. */ -int filename( int f, int n) { - int status ; +BINDABLE( filename) { char *fname ; if( restflag) /* don't allow this command if restricted */ return resterr() ; - status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ; + int status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ; if( status == ABORT) return status ; else if( status == FALSE) @@ -653,3 +621,5 @@ static int ifile( const char *fname) { return (s == FIOERR) ? FALSE : TRUE ; } + +/* end of file.c */ diff --git a/file.h b/file.h index 68d649e..b168a4a 100644 --- a/file.h +++ b/file.h @@ -1,23 +1,29 @@ +/* file.h -- file centric commands */ + #ifndef _FILE_H_ #define _FILE_H_ #include "buffer.h" -#include "retcode.h" +#include "names.h" extern boolean restflag ; /* restricted use? */ boolean resterr( void) ; /* restricted error message */ -int fileread( int f, int n) ; -int insfile( int f, int n) ; -int filefind( int f, int n) ; -int viewfile( int f, int n) ; +/* Bindable functions */ +BINDABLE( filefind) ; +BINDABLE( fileread) ; +BINDABLE( filename) ; +BINDABLE( filesave) ; +BINDABLE( filewrite) ; +BINDABLE( insfile) ; +BINDABLE( viewfile) ; + int getfile( const char *fname, boolean lockfl) ; int readin( const char *fname, boolean lockfl) ; void makename( bname_t bname, const char *fname) ; void unqname( char *name) ; -int filewrite( int f, int n) ; -int filesave( int f, int n) ; int writeout( const char *fn) ; -int filename( int f, int n) ; #endif + +/* end of file.h */ diff --git a/line.c b/line.c index 30bcb98..f093e1d 100644 --- a/line.c +++ b/line.c @@ -1,6 +1,7 @@ -/* line.c - * - * The functions in this file are a general set of line management utilities. +/* line.c -- implements line.h */ +#include "line.h" + +/* 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 @@ -13,12 +14,9 @@ * */ -#include "line.h" - #include -#include -#include -#include +#include /* NULL, offsetof() */ +#include /* malloc(), free() */ #include #include "buffer.h" @@ -41,13 +39,13 @@ static int ldelnewline( void) ; #define KBLOCK 250 /* sizeof kill buffer chunks */ -struct kill { +typedef struct kill { struct kill *d_next; /* Link to next chunk, NULL if last. */ char d_chunk[KBLOCK]; /* Deleted text. */ -}; +} *kill_p ; -static struct kill *kbufp = NULL ; /* current kill buffer chunk pointer */ -static struct kill *kbufh = NULL ; /* kill buffer header pointer */ +static kill_p kbufp = NULL ; /* current kill buffer chunk pointer */ +static kill_p kbufh = NULL ; /* kill buffer header pointer */ static int kused = KBLOCK ; /* # of bytes used in kill buffer */ static int klen ; /* length of kill buffer content */ static char *value = NULL ; /* temp buffer for value */ @@ -56,7 +54,7 @@ static char *value = NULL ; /* temp buffer for value */ * return some of the contents of the kill buffer */ char *getkill( void) { - struct kill *kp ; + kill_p kp ; char *cp ; if (kbufh == NULL) @@ -160,12 +158,14 @@ boolean forwchar( int f, int n) { */ line_p lalloc( int used) { #define BLOCK_SIZE 16 /* Line block chunk size. */ - line_p lp ; - int size ; -/* size = used + BLOCK_SIZE - used % BLOCK_SIZE ; */ - size = (used + BLOCK_SIZE) & ~(BLOCK_SIZE - 1) ; /* as BLOCK_SIZE is power of 2 */ - lp = (line_p) malloc( offsetof( struct line, l_text) + size) ; +/* rounding down use masking instead or modulo when BLOCK_SIZE is power of 2 */ +#if (BLOCK_SIZE & -BLOCK_SIZE) == BLOCK_SIZE + int size = (used + BLOCK_SIZE) & ~(BLOCK_SIZE - 1) ; +#else + int size = used + BLOCK_SIZE - used % BLOCK_SIZE ; +#endif + line_p lp = (line_p) malloc( offsetof( struct line, l_text) + size) ; if( lp == NULL) mloutstr( "(OUT OF MEMORY)") ; else { @@ -183,7 +183,7 @@ line_p lalloc( int used) { * conditions described in the above comments don't hold here. */ void lfree( line_p lp) { - struct buffer *bp; + buffer_p bp; struct window *wp; wp = wheadp; @@ -295,18 +295,13 @@ int linstr( char *instr) { boolean linsert_byte( int n, int c) { char *cp1; char *cp2; - struct line *lp1; - struct line *lp2; - struct line *lp3; + line_p lp1, lp2, lp3 ; int doto; int i; struct window *wp; assert( (curbp->b_mode & MDVIEW) == 0) ; -#if 0 - if (curbp->b_mode & MDVIEW) /* don't allow this command if */ - return rdonly(); /* we are in read only mode */ -#endif + lchange(WFEDIT); lp1 = curwp->w_dotp; /* Current line */ if (lp1 == curbp->b_linep) { /* At the end: special */ @@ -314,8 +309,11 @@ boolean linsert_byte( int n, int c) { mloutstr( "bug: linsert") ; return FALSE; } - if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */ - return FALSE; + + lp2 = lalloc( n) ; /* Allocate new line */ + if( lp2 == NULL) + return FALSE ; + lp3 = lp1->l_bp; /* Previous line */ lp3->l_fp = lp2; /* Link in */ lp2->l_fp = lp1; @@ -329,8 +327,10 @@ boolean linsert_byte( int n, int c) { } doto = curwp->w_doto; /* Save for later. */ if (lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */ - if ((lp2 = lalloc(lp1->l_used + n)) == NULL) - return FALSE; + lp2 = lalloc( lp1->l_used + n) ; + if( lp2 == NULL) + return FALSE ; + cp1 = &lp1->l_text[0]; cp2 = &lp2->l_text[0]; while (cp1 != &lp1->l_text[doto]) @@ -374,8 +374,6 @@ boolean linsert_byte( int n, int c) { int linsert( int n, unicode_t c) { assert( n >= 0) ; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; if( n > 0) { @@ -398,16 +396,14 @@ int linsert( int n, unicode_t c) { return TRUE; } -/* - * Overwrite a character into the current line at the current position +/* Overwrite a character into the current line at the current position * - * int c; character to overwrite on current position + * int c ; character to overwrite on current position */ static int lowrite( int c) { if( curwp->w_doto < curwp->w_dotp->l_used - && ( - lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || - ((curwp->w_doto) % tabwidth) == (tabwidth - 1) + && ( lgetc( curwp->w_dotp, curwp->w_doto) != '\t' + || (curwp->w_doto % tabwidth) == (tabwidth - 1) )) ldelchar( 1, FALSE) ; @@ -420,15 +416,12 @@ static int lowrite( int c) { int lover( char *ostr) { int status = TRUE ; - if (ostr != NULL) { + if( ostr != NULL) { char tmpc ; while( (tmpc = *ostr++)) { - status = - (tmpc == '\n' ? lnewline() : lowrite(tmpc)); - - /* Insertion error? */ - if( status != TRUE) { + status = (tmpc == '\n' ? lnewline() : lowrite( tmpc)) ; + if( status != TRUE) { /* Insertion error? */ mloutstr( "%Out of memory while overwriting") ; return status ; } @@ -446,17 +439,13 @@ int lover( char *ostr) { * update of dot and mark is a bit easier then in the above case, because the * split forces more updating. */ -int lnewline(void) -{ +int lnewline( void) { char *cp1; char *cp2; - struct line *lp1; - struct line *lp2; + line_p lp1, lp2 ; int doto; struct window *wp; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; #if SCROLLCODE @@ -466,8 +455,10 @@ int lnewline(void) #endif lp1 = curwp->w_dotp; /* Get the address and */ doto = curwp->w_doto; /* offset of "." */ - if ((lp2 = lalloc(doto)) == NULL) /* New first half line */ - return FALSE; + lp2 = lalloc( doto) ; /* New first half line */ + if( lp2 == NULL) + return FALSE ; + cp1 = &lp1->l_text[0]; /* Shuffle text around */ cp2 = &lp2->l_text[0]; while (cp1 != &lp1->l_text[doto]) @@ -519,12 +510,14 @@ int lgetchar( unicode_t *c) { */ boolean ldelchar( long n, boolean kflag) { /* testing for read only mode is done by ldelete() */ - while (n-- > 0) { + while( n-- > 0) { unicode_t c; - if (!ldelete(lgetchar(&c), kflag)) - return FALSE; + + if( !ldelete( lgetchar( &c), kflag)) + return FALSE ; } - return TRUE; + + return TRUE ; } /* @@ -539,13 +532,11 @@ boolean ldelchar( long n, boolean kflag) { boolean ldelete( long n, boolean kflag) { char *cp1; char *cp2; - struct line *dotp; + line_p dotp; int doto; int chunk; struct window *wp; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; while( n > 0) { @@ -641,20 +632,14 @@ char *getctext( void) { * about in memory. Return FALSE on error and TRUE if all looks ok. Called by * "ldelete" only. */ -static int ldelnewline(void) -{ +static int ldelnewline( void) { char *cp1; char *cp2; - struct line *lp1; - struct line *lp2; - struct line *lp3; + line_p lp1, lp2, lp3 ; struct window *wp; assert( (curbp->b_mode & MDVIEW) == 0) ; -#if 0 - if (curbp->b_mode & MDVIEW) /* don't allow this command if */ - return rdonly(); /* we are in read only mode */ -#endif + lp1 = curwp->w_dotp; lp2 = lp1->l_fp; if (lp2 == curbp->b_linep) { /* At the buffer end. */ @@ -687,8 +672,11 @@ static int ldelnewline(void) free((char *) lp2); return TRUE; } - if ((lp3 = lalloc(lp1->l_used + lp2->l_used)) == NULL) - return FALSE; + + lp3 = lalloc( lp1->l_used + lp2->l_used) ; + if( lp3 == NULL) + return FALSE ; + cp1 = &lp1->l_text[0]; cp2 = &lp3->l_text[0]; while (cp1 != &lp1->l_text[lp1->l_used]) @@ -730,7 +718,7 @@ static int ldelnewline(void) */ void kdelete(void) { - struct kill *kp; /* ptr to scan kill buffer chunk list */ + kill_p kp; /* ptr to scan kill buffer chunk list */ if (kbufh != NULL) { @@ -759,30 +747,30 @@ void kdelete(void) * * int c; character to insert in the kill buffer */ -int kinsert(int c) -{ - struct kill *nchunk; /* ptr to newly malloced chunk */ - +int kinsert( int c) { /* check to see if we need a new chunk */ - if (kused >= KBLOCK) { - if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL) - return FALSE; + if( kused >= KBLOCK) { + kill_p nchunk = malloc( sizeof *nchunk) ; + if( nchunk == NULL) + return FALSE ; + if( kbufh == NULL) { /* set head ptr if first time */ - kbufh = nchunk; + kbufh = nchunk ; klen = 0 ; } - if (kbufp != NULL) /* point the current to this new one */ - kbufp->d_next = nchunk; - kbufp = nchunk; - kbufp->d_next = NULL; - kused = 0; + if( kbufp != NULL) /* point the current to this new one */ + kbufp->d_next = nchunk ; + + kbufp = nchunk ; + kbufp->d_next = NULL ; + kused = 0 ; } /* and now insert the character */ - kbufp->d_chunk[kused++] = c; + kbufp->d_chunk[ kused++] = c ; klen += 1 ; - return TRUE; + return TRUE ; } /* @@ -790,15 +778,12 @@ int kinsert(int c) * is done by the standard insert routines. All you do is run the loop, and * check for errors. Bound to "C-Y". */ -int yank(int f, int n) -{ +BINDABLE( yank) { int c; int i; char *sp; /* pointer into string to insert */ - struct kill *kp; /* pointer into kill buffer */ + kill_p kp; /* pointer into kill buffer */ -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; if (n < 0) @@ -839,3 +824,5 @@ boolean rdonly( void) { mloutfmt( "%B(Key illegal in VIEW mode)") ; return FALSE ; } + +/* end of line.c */ diff --git a/line.h b/line.h index 18ed04f..656a83b 100644 --- a/line.h +++ b/line.h @@ -1,7 +1,9 @@ -#ifndef LINE_H_ -#define LINE_H_ +/* line.h -- line centric interface */ -#include "retcode.h" +#ifndef _LINE_H_ +#define _LINE_H_ + +#include "names.h" #include "utf8.h" /* @@ -34,8 +36,8 @@ char *getkill( void) ; /* Bindable functions */ boolean backchar( int f, int n) ; boolean forwchar( int f, int n) ; -int insspace( int f, int n) ; -int yank( int f, int n) ; +BINDABLE( insspace) ; +BINDABLE( yank) ; void lfree( line_p lp) ; void lchange( int flag) ; @@ -46,7 +48,7 @@ int lover( char *ostr) ; int lnewline( void) ; boolean ldelete( long n, boolean kflag) ; boolean ldelchar( long n, boolean kflag) ; -int lgetchar( unicode_t *) ; +int lgetchar( unicode_t *cref) ; char *getctext( void) ; void kdelete( void) ; int kinsert( int c) ; @@ -54,4 +56,6 @@ line_p lalloc( int minsize) ; /* Allocate a line of at least minsize chars. */ boolean rdonly( void) ; /* Read Only error message */ -#endif /* LINE_H_ */ +#endif /* _LINE_H_ */ + +/* end of line.h */ diff --git a/names.c b/names.c index a5c219d..f357a99 100644 --- a/names.c +++ b/names.c @@ -54,9 +54,7 @@ const name_bind names[] = { {" clear-and-redraw", redraw, CTRL | 'L'} , {" clear-message-line", clrmes, 0} , {" copy-region", copyregion, META | 'W'} , -#if WORDPRO {" count-words", wordcount, META | CTRL | 'C'} , -#endif {" ctlx-prefix", cex, CTRL | 'X'} , {"!delete-blank-lines", deblank, CTLX | CTRL | 'O'} , {" delete-buffer", killbuffer, CTLX | 'K'} , @@ -70,15 +68,11 @@ const name_bind names[] = { {" delete-window", delwind, CTLX | '0'} , {" describe-bindings", desbind, 0} , {" describe-key", deskey, CTLX | '?'} , -#if AEDIT {"!detab-line", detab, CTLX | CTRL | 'D'} , /* X^A */ -#endif {" end-macro", ctlxrp, CTLX | ')'} , {" end-of-file", (fnp_t) gotoeob, META | '>'} , {" end-of-line", (fnp_t) gotoeol, CTRL | 'E'} , -#if AEDIT {"!entab-line", entab, CTLX | CTRL | 'E'} , -#endif {" exchange-point-and-mark", (fnp_t) swapmark, CTLX | CTRL | 'X'} , {" execute-buffer", execbuf, 0} , {" execute-command-line", execcmd, 0} , @@ -130,9 +124,7 @@ const name_bind names[] = { #endif {" execute-program", execprg, CTLX | '$'} , {" exit-emacs", quit, CTLX | CTRL | 'C'} , -#if WORDPRO {"!fill-paragraph", fillpara, META | 'Q'} , -#endif {"!filter-buffer", filter_buffer, CTLX | '#'} , {" find-file", filefind, CTLX | CTRL | 'F'} , {" forward-character", (fnp_t) forwchar, CTRL | 'F'} , @@ -152,12 +144,10 @@ const name_bind names[] = { {"!insert-file", insfile, CTLX | CTRL | 'I'} , {"!insert-space", insspace, CTRL | 'C'} , {"!insert-string", istring, 0} , -#if WORDPRO #if PKCODE {"!justify-paragraph", justpara, META | 'J'} , #endif {"!kill-paragraph", killpara, META | CTRL | 'W'} , -#endif {"!kill-region", killregion, CTRL | 'W'} , {"!kill-to-end-of-line", killtext, CTRL | 'K'} , {" list-buffers", listbuffers, CTLX | CTRL | 'B'} , @@ -170,9 +160,7 @@ const name_bind names[] = { {" next-buffer", nextbuffer, CTLX | 'X'} , {" next-line", (fnp_t) forwline, CTRL | 'N'} , {" next-page", (fnp_t) forwpage, CTRL | 'V'} , -#if WORDPRO {" next-paragraph", gotoeop, META | 'N'} , -#endif {" next-window", nextwind, CTLX | 'O'} , {" next-word", forwword, META | 'F'} , {" nop", nullproc, SPEC | META | 'C'}, /* hook */ @@ -181,9 +169,7 @@ const name_bind names[] = { {" pipe-command", pipecmd, CTLX | '@'} , {" previous-line", (fnp_t) backline, CTRL | 'P'} , {" previous-page", (fnp_t) backpage, CTRL | 'Z'} , /* MV */ -#if WORDPRO {" previous-paragraph", gotobop, META | 'P'} , -#endif {" previous-window", prevwind, CTLX | 'P'} , {" previous-word", backword, META | 'B'} , {"!query-replace-string", qreplace, META | CTRL | 'R'} , @@ -221,9 +207,7 @@ const name_bind names[] = { {" suspend-emacs", bktoshell, CTLX | 'D'} , /* BSD MS */ #endif {"!transpose-characters", (fnp_t) twiddle, CTRL | 'T'} , -#if AEDIT {"!trim-line", trim, CTLX | CTRL | 'T'} , -#endif {" unbind-key", unbindkey, META | CTRL | 'K'} , {" universal-argument", unarg, CTRL | 'U'} , {" unmark-buffer", unmark, META | '~'} , diff --git a/random.c b/random.c index 841ffa9..98441d3 100644 --- a/random.c +++ b/random.c @@ -51,26 +51,22 @@ int lastflag ; /* Flags, last command */ static int adjustmode( int kind, int global) ; static int cinsert( void) ; -/* - * Set fill column to n. +/* Set fill column to n. Bound to C-X F set-fill-column. */ -int setfillcol(int f, int n) -{ - fillcol = n; - mlwrite("(Fill column is %d)", n); - return TRUE; +BINDABLE( setfillcol) { + fillcol = n ; + mlwrite( "(Fill column is %d)", n) ; + return TRUE ; } -/* - * Display the current position of the cursor, in origin 1 X-Y coordinates, - * the character that is under the cursor (in hex), and the fraction of the - * text that is before the cursor. The displayed column is not the current - * column, but the column that would be used on an infinite width display. - * Normally this is bound to "C-X =". +/* Display the current position of the cursor, in origin 1 X-Y coordinates, + the character that is under the cursor (in hex), and the fraction of the + text that is before the cursor. The displayed column is not the current + column, but the column that would be used on an infinite width display. + Normally this is bound to C-X = buffer-position. */ -int showcpos(int f, int n) -{ - struct line *lp; /* current line */ +BINDABLE( showcpos) { + line_p lp ; /* current line */ long numchars; /* # of chars in file */ int numlines; /* # of lines in file */ long predchars; /* # chars preceding point */ @@ -128,7 +124,7 @@ int showcpos(int f, int n) int getcline(void) { /* get the current line number */ - struct line *lp; /* current line */ + line_p lp ; /* current line */ int numlines; /* # of lines before point */ /* starting at the beginning of the buffer */ @@ -154,7 +150,7 @@ int getcline(void) int getccol(int bflg) { int i, col; - struct line *dlp = curwp->w_dotp; + line_p dlp = curwp->w_dotp ; int byte_offset = curwp->w_doto; int len = llength(dlp); @@ -224,14 +220,11 @@ boolean setccol( int pos) { */ boolean twiddle( int f, int n) { unicode_t c ; - int len ; boolean eof_f = FALSE ; -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; - len = llength( curwp->w_dotp) ; + int len = llength( curwp->w_dotp) ; if( len < 2 || curwp->w_doto == 0) /* at least 2 chars & not bol */ return FALSE ; @@ -255,44 +248,36 @@ boolean twiddle( int f, int n) { return TRUE ; } -/* - * Quote the next character, and insert it into the buffer. All the characters - * are taken literally, with the exception of the newline, which always has - * its line splitting meaning. The character is always read, even if it is - * inserted 0 times, for regularity. Bound to "C-Q" +/* Quote the next character, and insert it into the buffer. All the + characters are taken literally, with the exception of the newline, which + always has its line splitting meaning. The character is always read, + even if it is inserted 0 times, for regularity. Bound to C-Q + quote-character. */ -int quote(int f, int n) -{ -// int c; -// -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ +BINDABLE( quote) { + int ret ; + assert( !(curbp->b_mode & MDVIEW)) ; - int c = tgetc(); - if (n < 0) - return FALSE; - if (n == 0) - return TRUE; - if (c == '\n') { - int s ; + int c = ectoc( get1key()) ; + if( n < 0) + ret = FALSE ; + else if( n == 0) + ret = TRUE ; + else if( c == '\n') + do + ret = lnewline() ; + while( ret == TRUE && --n) ; + else + ret = linsert( n, c) ; - do { - s = lnewline(); - } while (s == TRUE && --n); - return s; - } - return linsert(n, c); + return ret ; } -/* - * Set tab size if given non-default argument (n <> 1). Otherwise, insert a - * tab into file. If given argument, n, of zero, change to true tabs. - * If n > 1, simulate tab stop every n-characters using spaces. This has to be - * done in this slightly funny way because the tab (in ASCII) has been turned - * into "C-I" (in 10 bit code) already. Bound to "C-I". +/* Insert tab/blank/space up to nth next tabulation according to hard/soft + tab current state and tab width. Bound to C-I handle-tab. */ -int insert_tab( int f, int n) { +BINDABLE( insert_tab) { int status ; if( n < 0) @@ -309,27 +294,20 @@ int insert_tab( int f, int n) { return status ; } -#if AEDIT /* * change tabs to spaces * * int f, n; default flag and numeric repeat count */ -int detab(int f, int n) -{ - int inc; /* increment to next line [sgn(n)] */ - -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ - +BINDABLE( detab) { assert( !(curbp->b_mode & MDVIEW)) ; - if (f == FALSE) - n = 1; + if( f == FALSE) + n = 1 ; /* loop thru detabbing n lines */ - inc = ((n > 0) ? 1 : -1); - while (n) { + int inc = (n > 0) ? 1 : -1 ; /* increment to next line [sgn(n)] */ + for( ; n ; n -= inc) { curwp->w_doto = 0; /* start at the beginning */ /* detab the entire current line */ @@ -349,9 +327,8 @@ int detab(int f, int n) /* advance/or back to the next line */ if( forwline( TRUE, inc) == FALSE) break ; - - n -= inc; } + curwp->w_doto = 0; /* to the begining of the line */ thisflag &= ~CFCPCN; /* flag that this resets the goal column */ lchange(WFEDIT); /* yes, we have made at least an edit */ @@ -359,27 +336,21 @@ int detab(int f, int n) } /* - * change spaces to tabs where posible + * change spaces to tabs where possible * * int f, n; default flag and numeric repeat count */ -int entab(int f, int n) -{ +BINDABLE( entab) { #define nextab(a) (a + tabwidth - a % tabwidth) - int inc; /* increment to next line [sgn(n)] */ - -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ - assert( !(curbp->b_mode & MDVIEW)) ; - if (f == FALSE) - n = 1; + if( f == FALSE) + n = 1 ; /* loop thru entabbing n lines */ - inc = ((n > 0) ? 1 : -1); - while (n) { + int inc = (n > 0) ? 1 : -1 ; /* increment to next line [sgn(n)] */ + for( ; n ; n -= inc) { int fspace ; /* pointer to first space if in a run */ int ccol ; /* current cursor column */ @@ -426,9 +397,8 @@ int entab(int f, int n) /* advance/or back to the next line */ if( forwline( TRUE, inc) == FALSE) break ; - - n -= inc; } + curwp->w_doto = 0; /* to the begining of the line */ thisflag &= ~CFCPCN; /* flag that this resets the goal column */ lchange(WFEDIT); /* yes, we have made at least an edit */ @@ -440,21 +410,15 @@ int entab(int f, int n) * * int f, n; default flag and numeric repeat count */ -int trim(int f, int n) -{ - int inc; /* increment to next line [sgn(n)] */ - -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ - +BINDABLE( trim) { assert( !(curbp->b_mode & MDVIEW)) ; - if (f == FALSE) - n = 1; + if( f == FALSE) + n = 1 ; /* loop thru trimming n lines */ - inc = ((n > 0) ? 1 : -1); - while (n) { + int inc = (n > 0) ? 1 : -1 ; /* increment to next line [sgn(n)] */ + for( ; n ; n -= inc) { line_p lp ; /* current line pointer */ int offset ; /* original line offset position */ int length ; /* current length */ @@ -468,60 +432,46 @@ int trim(int f, int n) if( c != ' ' && c != '\t') break ; } - + lp->l_used = length; /* advance/or back to the next line */ if( forwline( TRUE, inc) == FALSE) break ; - - n -= inc; } + lchange(WFEDIT); thisflag &= ~CFCPCN; /* flag that this resets the goal column */ return (n == 0) ? TRUE : FALSE ; } -#endif /* * 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". */ -int openline(int f, int n) -{ - int i; - int s; - -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ +BINDABLE( openline) { assert( !(curbp->b_mode & MDVIEW)) ; - if (n < 0) - return FALSE; - if (n == 0) - return TRUE; - i = n; /* Insert newlines. */ - do { - s = lnewline(); - } while (s == TRUE && --i); - if (s == TRUE) /* Then back up overtop */ - s = backchar(f, n); /* of them all. */ - return s; + int ret = (n < 0) ? FALSE : TRUE ; + for( int i = n ; ret == TRUE && i ; i--) /* Insert newlines. */ + ret = lnewline() ; + + if( ret == TRUE) /* Then back up overtop */ + ret = backchar( f, n) ; /* of them all. */ + + return ret ; } /* * Insert a newline. Bound to "C-M". If we are in CMODE, do automatic * indentation as specified. */ -int insert_newline(int f, int n) -{ -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ +BINDABLE( insert_newline) { assert( !(curbp->b_mode & MDVIEW)) ; - if (n < 0) - return FALSE; + if( n < 0) + return FALSE ; /* if we are in C mode and this is a default */ if (n == 1 && (curbp->b_mode & MDCMOD) && @@ -569,7 +519,7 @@ static int cinsert(void) nicol = 0 ; for( i = 0 ; i < tptr ; i += 1) { int ch ; - + ch = cptr[ i] ; if( ch == ' ') nicol += 1 ; @@ -610,22 +560,17 @@ static int cinsert(void) } -/* - * 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 + * delete-blank-lines. Any argument is ignored. */ -int deblank(int f, int n) -{ - struct line *lp1; - struct line *lp2; - long nld; +BINDABLE( deblank) { + line_p lp1, lp2 ; + long nld ; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; lp1 = curwp->w_dotp; @@ -642,28 +587,24 @@ int deblank(int f, int n) return ldelete(nld, FALSE); } -/* - * Insert a newline, then enough tabs and spaces to duplicate the indentation - * of the previous line. Assumes tabs are every tabwidth characters. - * 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 tabwidth + * characters. 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 + * newline-and-indent. */ -int indent( int f, int n) { - int nicol ; +BINDABLE( indent) { int i ; -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ - assert( !(curbp->b_mode & MDVIEW)) ; if( n < 0) return FALSE ; /* number of columns to indent */ - nicol = 0 ; + int nicol = 0 ; for( i = 0 ; i < llength( curwp->w_dotp) ; i += 1) { int c ; @@ -693,10 +634,7 @@ int indent( int f, int n) { * 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". */ -int forwdel( int f, int n) { -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ - +BINDABLE( forwdel) { assert( !(curbp->b_mode & MDVIEW)) ; if( n == 0) @@ -719,10 +657,7 @@ int forwdel( int f, int n) { * forward, this actually does a kill if presented with an argument. Bound to * both "RUBOUT" and "C-H". */ -int backdel( int f, int n) { -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ - +BINDABLE( backdel) { assert( !(curbp->b_mode & MDVIEW)) ; if( n == 0) @@ -747,13 +682,10 @@ int backdel( int f, int n) { * number of newlines. If called with a negative argument it kills backwards * that number of newlines. Normally bound to "C-K". */ -int killtext(int f, int n) -{ - struct line *nextp; +BINDABLE( killtext) { + line_p nextp ; long chunk; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; if ((lastflag & CFKILL) == 0) /* Clear kill buffer if */ @@ -953,7 +885,7 @@ static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) { * * int f, n; ignored arguments */ -int istring( int f, int n) { +BINDABLE( istring) { return iovstring( f, n, "insert-string: ", linstr) ; } @@ -963,7 +895,7 @@ int istring( int f, int n) { * * int f, n; ignored arguments */ -int ovstring( int f, int n) { +BINDABLE( ovstring) { return iovstring( f, n, "overwrite-string: ", lover) ; } diff --git a/random.h b/random.h index eb772d7..6f7e657 100644 --- a/random.h +++ b/random.h @@ -1,49 +1,48 @@ +/* random.h -- various commands */ + #ifndef _RANDOM_H_ #define _RANDOM_H_ +#include "names.h" -#include "retcode.h" +/* Command flags */ +#define CFCPCN 0x0001 /* Flag that last command was C-P, C-N */ +#define CFKILL 0x0002 /* Flag that last command was a kill */ +extern int thisflag ; /* Flags, this command */ +extern int lastflag ; /* Flags, last command */ -#define AEDIT 1 - -extern int fillcol ; /* Fill column */ +extern int fillcol ; /* Fill column */ extern boolean hardtab ; /* Use hard tab instead of soft tab */ -/* Uninitialized global external declarations. */ - -#define CFCPCN 0x0001 /* Last command was C-P, C-N */ -#define CFKILL 0x0002 /* Last command was a kill */ - -extern int thisflag ; /* Flags, this command */ -extern int lastflag ; /* Flags, last command */ - -int setfillcol( int f, int n) ; -int showcpos( int f, int n) ; int getcline( void) ; int getccol( int bflg) ; boolean setccol( int pos) ; + +/* Bindable functions */ +BINDABLE( setfillcol) ; +BINDABLE( showcpos) ; boolean twiddle( int f, int n) ; -int quote( int f, int n) ; -int insert_tab( int f, int n) ; -#if AEDIT -int detab( int f, int n) ; -int entab( int f, int n) ; -int trim( int f, int n) ; -#endif -int openline( int f, int n) ; -int insert_newline( int f, int n) ; -int deblank( int f, int n) ; -int indent( int f, int n) ; -int forwdel( int f, int n) ; -int backdel( int f, int n) ; -int killtext( int f, int n) ; -int setemode( int f, int n) ; -int delmode( int f, int n) ; -int setgmode( int f, int n) ; -int delgmode( int f, int n) ; -int istring( int f, int n) ; -int ovstring( int f, int n) ; +BINDABLE( quote) ; +BINDABLE( insert_tab) ; +BINDABLE( detab) ; +BINDABLE( entab) ; +BINDABLE( trim) ; +BINDABLE( openline) ; +BINDABLE( insert_newline) ; +BINDABLE( deblank) ; +BINDABLE( indent) ; +BINDABLE( forwdel) ; +BINDABLE( backdel) ; +BINDABLE( killtext) ; +BINDABLE( setemode) ; +BINDABLE( delmode) ; +BINDABLE( setgmode) ; +BINDABLE( delgmode) ; +BINDABLE( istring) ; +BINDABLE( ovstring) ; #endif + +/* end of random.h */ diff --git a/region.c b/region.c index fcf5d71..00944c5 100644 --- a/region.c +++ b/region.c @@ -20,19 +20,14 @@ #include "random.h" #include "window.h" -/* - * Kill the region. Ask "getregion" - * to figure out the bounds of the region. - * Move "." to the start, and kill the characters. - * Bound to "C-W". +/* Kill the region. Ask "getregion" to figure out the bounds of the + * region. Move "." to the start, and kill the characters. Bound to + * "C-W". */ -int killregion(int f, int n) -{ +BINDABLE( killregion) { int s; - struct region region; + region_t region; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; if ((s = getregion(®ion)) != TRUE) @@ -45,18 +40,15 @@ int killregion(int f, int n) return ldelete(region.r_size, TRUE); } -/* - * 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. Bound to "M-W". +/* 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. Bound + * to "M-W". */ -int copyregion(int f, int n) -{ - struct line *linep; +BINDABLE( copyregion) { + line_p linep; int loffs; int s; - struct region region; + region_t region; if ((s = getregion(®ion)) != TRUE) return s; @@ -81,24 +73,18 @@ int copyregion(int f, int n) return TRUE; } -/* - * 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. Bound to - * "C-X C-L". +/* 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. Bound to "C-X C-L". */ -int lowerregion(int f, int n) -{ - struct line *linep; +BINDABLE( lowerregion) { + line_p linep; int loffs; int c; int s; - struct region region; + region_t region; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; if ((s = getregion(®ion)) != TRUE) @@ -120,24 +106,18 @@ int lowerregion(int f, int n) return TRUE; } -/* - * 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. Bound to - * "C-X C-L". +/* 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. Bound to "C-X C-L". */ -int upperregion(int f, int n) -{ - struct line *linep; +BINDABLE( upperregion) { + line_p linep; int loffs; int c; int s; - struct region region; + region_t region; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; if ((s = getregion(®ion)) != TRUE) @@ -159,23 +139,16 @@ int upperregion(int f, int n) return TRUE; } -/* - * This routine figures out the - * bounds of the region in the current window, and - * fills in the fields of the "struct region" structure pointed - * to by "rp". Because the dot and mark are usually very - * close together, we scan outward from dot looking for - * mark. This should save time. Return a standard code. - * Callers of this routine should be prepared to get - * an "ABORT" status; we might make this have the - * conform thing later. +/* This routine figures out the bounds of the region in the current window, + * and fills in the fields of the "region_t" structure pointed to by "rp". + * Because the dot and mark are usually very close together, we scan + * outward from dot looking for mark. This should save time. Return a + * standard code. Callers of this routine should be prepared to get an + * "ABORT" status; we might make this have the conform thing later. */ -int getregion(struct region *rp) -{ - struct line *flp; - struct line *blp; - long fsize; - long bsize; +int getregion( region_p rp) { + line_p flp, blp ; + long fsize, bsize ; if (curwp->w_markp == NULL) { mloutstr( "No mark set in this window") ; @@ -223,3 +196,5 @@ int getregion(struct region *rp) mloutstr( "Bug: lost mark") ; return FALSE; } + +/* end of region.c */ diff --git a/region.h b/region.h index 1e46e7f..991d1a0 100644 --- a/region.h +++ b/region.h @@ -1,3 +1,4 @@ +/* region.h -- a region starts at the mark and end at the dot */ #ifndef _REGION_H_ #define _REGION_H_ @@ -7,16 +8,22 @@ * The starting position of a region, and the size of the region in * characters, is kept in a region structure. Used by the region commands. */ -struct region { - struct line *r_linep; /* Origin struct line address. */ - int r_offset; /* Origin struct line offset. */ - long r_size; /* Length in characters. */ -}; +typedef struct { + line_p r_linep ; /* Origin struct line address. */ + int r_offset ; /* Origin struct line offset. */ + long r_size ; /* Length in characters. */ +} region_t ; -int killregion( int f, int n) ; -int copyregion( int f, int n) ; -int lowerregion( int f, int n) ; -int upperregion( int f, int n) ; -int getregion( struct region *rp) ; +typedef region_t *region_p ; + +/* Bindable functions */ +BINDABLE( killregion) ; +BINDABLE( copyregion) ; +BINDABLE( lowerregion) ; +BINDABLE( upperregion) ; + +int getregion( region_p rp) ; #endif + +/* end of region.h */ diff --git a/search.c b/search.c index 029becf..6e0dace 100644 --- a/search.c +++ b/search.c @@ -87,7 +87,7 @@ unsigned int matchlen = 0 ; static unsigned int mlenold = 0 ; char *patmatch = NULL ; -static struct line *matchline = NULL; +static line_p matchline = NULL; static int matchoff = 0; spat_t pat ; /* Search pattern */ @@ -165,10 +165,10 @@ static struct magic_replacement rmcpat[NPAT]; /* The replacement magic array. */ static int mcscanner( struct magic *mcpatrn, int direct, int beg_or_end) ; #endif -static int amatch(struct magic *mcptr, int direct, struct line **pcwline, int *pcwoff); +static int amatch(struct magic *mcptr, int direct, line_p *pcwline, int *pcwoff); static int readpattern(char *prompt, char *apat, int srch); static int replaces(int kind, int f, int n); -static int nextch(struct line **pcurline, int *pcuroff, int dir); +static int nextch( line_p *pcurline, int *pcuroff, int dir); static int mcstr(void); static int rmcstr(void); static int mceq(int bc, struct magic *mt); @@ -390,7 +390,7 @@ int backhunt(int f, int n) */ static int mcscanner(struct magic *mcpatrn, int direct, int beg_or_end) { - struct line *curline; /* current line during scan */ + line_p curline; /* current line during scan */ int curoff; /* position within current line */ /* If we are going in reverse, then the 'end' is actually @@ -413,7 +413,7 @@ static int mcscanner(struct magic *mcpatrn, int direct, int beg_or_end) /* Scan each character until we hit the head link record. */ - while (!boundry(curline, curoff, direct)) { + while (!boundary(curline, curoff, direct)) { /* Save the current position in case we need to * restore it on a match, and initialize matchlen to * zero in case we are doing a search for replacement. @@ -454,13 +454,13 @@ static int mcscanner(struct magic *mcpatrn, int direct, int beg_or_end) * * struct magic *mcptr; string to scan for * int direct; which way to go. - * struct line **pcwline; current line during scan + * line_p *pcwline; current line during scan * int *pcwoff; position within current line */ -static int amatch(struct magic *mcptr, int direct, struct line **pcwline, int *pcwoff) +static int amatch(struct magic *mcptr, int direct, line_p *pcwline, int *pcwoff) { int c; /* character at current position */ - struct line *curline; /* current line during scan */ + line_p curline; /* current line during scan */ int curoff; /* position within current line */ int nchars; @@ -600,9 +600,9 @@ int scanner(const char *patrn, int direct, int beg_or_end) { int c; /* character at current position */ const char *patptr; /* pointer into pattern */ - struct line *curline; /* current line during scan */ + line_p curline; /* current line during scan */ int curoff; /* position within current line */ - struct line *scanline; /* current line during scanning */ + line_p scanline; /* current line during scanning */ int scanoff; /* position in scanned line */ /* If we are going in reverse, then the 'end' is actually @@ -617,7 +617,7 @@ int scanner(const char *patrn, int direct, int beg_or_end) /* Scan each character until we hit the head link record. */ - while (!boundry(curline, curoff, direct)) { + while (!boundary(curline, curoff, direct)) { /* Save the current position in case we match * the search string at this point. */ @@ -749,7 +749,7 @@ static int readpattern(char *prompt, char *apat, int srch) void savematch(void) { char *ptr; /* pointer to last match string */ - struct line *curline; /* line of last match */ + line_p curline; /* line of last match */ int curoff; /* offset " " */ /* Free any existing match string, then @@ -828,17 +828,15 @@ static int replaces(int kind, int f, int n) int nlrepl; /* was a replace done on the last line? */ char c; /* input char for query */ spat_t tpat ; /* temporary to hold search pattern */ - struct line *origline; /* original "." position */ + line_p origline; /* original "." position */ int origoff; /* and offset (for . query option) */ - struct line *lastline; /* position of last replace and */ + line_p lastline; /* position of last replace and */ int lastoff; /* offset (for 'u' query option) */ ///* rfi */ lastline = NULL ; lastoff = 0 ; -// if (curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly(); /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; /* Check for negative repetitions. @@ -1116,25 +1114,23 @@ int expandp(char *srcstr, char *deststr, int maxlength) return TRUE; } -/* - * boundry -- Return information depending on whether we may search no - * further. Beginning of file and end of file are the obvious - * cases, but we may want to add further optional boundry restrictions - * in future, a' la VMS EDT. At the moment, just return TRUE or - * FALSE depending on if a boundry is hit (ouch). - */ -int boundry(struct line *curline, int curoff, int dir) -{ - int border; - if (dir == FORWARD) { - border = (curoff == llength(curline)) && - (lforw(curline) == curbp->b_linep); - } else { - border = (curoff == 0) && - (lback(curline) == curbp->b_linep); - } - return border; +/* boundary -- Returns information depending on whether we may search no + further. Beginning of file and end of file are the obvious cases, but + we may want to add further optional boundary restrictions in future, a' + la VMS EDT. At the moment, just return TRUE or FALSE depending on if a + boundary is hit (ouch). + */ +int boundary( line_p curline, int curoff, int dir) { + int border ; + + if( dir == FORWARD) + border = (curoff == llength( curline)) && + (lforw( curline) == curbp->b_linep) ; + else + border = (curoff == 0) && (lback( curline) == curbp->b_linep) ; + + return border ; } /* @@ -1145,9 +1141,9 @@ int boundry(struct line *curline, int curoff, int dir) * the current character and move, reverse searches move and * look at the character. */ -static int nextch(struct line **pcurline, int *pcuroff, int dir) +static int nextch( line_p *pcurline, int *pcuroff, int dir) { - struct line *curline; + line_p curline; int curoff; int c; @@ -1606,3 +1602,5 @@ static void setbit(int bc, char *cclmap) *(cclmap + (bc >> 3)) |= BIT(bc & 7); } #endif + +/* end of search.c */ diff --git a/search.h b/search.h index 6f8c7a5..9b3d596 100644 --- a/search.h +++ b/search.h @@ -1,3 +1,5 @@ +/* search.h -- */ + #ifndef _SEARCH_H_ #define _SEARCH_H_ @@ -26,18 +28,20 @@ extern spat_t rpat ; /* replacement pattern */ int scanner( const char *patrn, int direct, int beg_or_end) ; -int forwsearch( int f, int n) ; -int forwhunt( int f, int n) ; -int backsearch( int f, int n) ; -int backhunt( int f, int n) ; +/* Bindable functions */ +BINDABLE( forwsearch) ; +BINDABLE( forwhunt) ; +BINDABLE( backsearch) ; +BINDABLE( backhunt) ; +BINDABLE( sreplace) ; +BINDABLE( qreplace) ; + int eq( unsigned char bc, unsigned char pc) ; void savematch( void) ; void rvstrcpy( char *rvstr, char *str) ; -int sreplace( int f, int n) ; -int qreplace( int f, int n) ; int delins( int dlength, char *instr, int use_meta) ; int expandp( char *srcstr, char *deststr, int maxlength) ; -int boundry( struct line *curline, int curoff, int dir) ; +int boundary( line_p curline, int curoff, int dir) ; void setprompt( char *tpat, unsigned tpat_size, char *prompt, char *apat) ; @@ -47,3 +51,5 @@ void rmcclear( void) ; #endif #endif + +/* end of search.h */ diff --git a/spawn.c b/spawn.c index a073159..ff6aa18 100644 --- a/spawn.c +++ b/spawn.c @@ -183,7 +183,7 @@ int execprg( int f, int n) { int pipecmd( int f, int n) { int s ; /* return status from CLI */ struct window *wp ; /* pointer to new window */ - struct buffer *bp ; /* pointer to buffer to zot */ + buffer_p bp ; /* pointer to buffer to zot */ char *mlarg ; char *line ; /* command line send to shell */ static char bname[] = "command" ; @@ -277,7 +277,7 @@ int pipecmd( int f, int n) { */ int filter_buffer( int f, int n) { int s ; /* return status from CLI */ - struct buffer *bp ; /* pointer to buffer to zot */ + buffer_p bp ; /* pointer to buffer to zot */ char *mlarg ; char *line ; /* command line send to shell */ fname_t tmpnam ; /* place to store real file name */ @@ -290,8 +290,6 @@ int filter_buffer( int f, int n) { if( restflag) return resterr() ; -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ assert( !(curbp->b_mode & MDVIEW)) ; /* get the filter name and its args */ diff --git a/spawn.h b/spawn.h index db8d7c2..cc219f9 100644 --- a/spawn.h +++ b/spawn.h @@ -1,7 +1,15 @@ -int spawncli( int f, int n) ; -int bktoshell( int f, int n) ; +/* spawn.h -- various operating system access commands */ + +#include "names.h" + +/* Bindable functions */ +BINDABLE( spawncli) ; +BINDABLE( bktoshell) ; +BINDABLE( spawn) ; +BINDABLE( execprg) ; +BINDABLE( pipecmd) ; +BINDABLE( filter_buffer) ; + void rtfrmshell( void) ; -int spawn( int f, int n) ; -int execprg( int f, int n) ; -int pipecmd( int f, int n) ; -int filter_buffer( int f, int n) ; + +/* end of spawn.h */ diff --git a/word.c b/word.c index 52f2e0e..cc7ce03 100644 --- a/word.c +++ b/word.c @@ -11,7 +11,6 @@ */ #include -#include #include /* malloc, free */ #include /* memcpy */ @@ -152,9 +151,6 @@ static boolean uniflip( boolean toupper_f) { /* flip unicode case and forward */ } static boolean capcapword( int n, boolean first_f, boolean rest_f) { -// if( curbp->b_mode & MDVIEW) /* don't allow this command if */ -// return rdonly() ; /* we are in read only mode */ - assert( !(curbp->b_mode & MDVIEW)) ; if( n < 0) @@ -210,14 +206,9 @@ int capword( int f, int n) { */ int delfword(int f, int n) { - struct line *dotp; /* original cursor line */ + line_p dotp; /* original cursor line */ int doto; /* and row */ int c; /* temp char */ - long size; /* # of chars to delete */ - -// /* don't allow this command if we are in read only mode */ -// if (curbp->b_mode & MDVIEW) -// return rdonly(); assert( !(curbp->b_mode & MDVIEW)) ; @@ -235,7 +226,7 @@ int delfword(int f, int n) doto = curwp->w_doto; /* figure out how many characters to give the axe */ - size = 0; + long size = 0 ; /* get us into a word.... */ while (inword() == FALSE) { @@ -301,12 +292,6 @@ int delfword(int f, int n) */ int delbword(int f, int n) { - long size; - -// /* don't allow this command if we are in read only mode */ -// if (curbp->b_mode & MDVIEW) -// return rdonly(); - assert( !(curbp->b_mode & MDVIEW)) ; /* ignore the command if there is a nonpositive argument */ @@ -320,7 +305,8 @@ int delbword(int f, int n) if (backchar(FALSE, 1) == FALSE) return FALSE; - size = 0; + + long size = 0 ; while (n--) { while (inword() == FALSE) { if (backchar(FALSE, 1) == FALSE) @@ -352,7 +338,6 @@ static int inword( void) { return isletter( c) || ( c >= '0' && c <= '9') ; } -#if WORDPRO static int parafillnjustify( int f, int n, int justify_f) { unicode_t c; /* current char during scan */ unicode_t *wbuf ; /* buffer for current word */ @@ -361,7 +346,7 @@ static int parafillnjustify( int f, int n, int justify_f) { int clength; /* position on line during fill */ int eopflag; /* Are we at the End-Of-Paragraph? */ int firstflag = TRUE ; /* first word? (needs no space) */ - struct line *eopline; /* pointer to line just past EOP */ + line_p eopline; /* pointer to line just past EOP */ int dotflag = 0 ; /* was the last char a period? */ int leftmarg = 0 ; /* left marginal */ @@ -549,7 +534,7 @@ int killpara(int f, int n) */ int wordcount(int f, int n) { - struct line *lp; /* current line to scan */ + line_p lp; /* current line to scan */ int offset; /* current char to scan */ long size; /* size of region left to count */ int ch; /* current character to scan */ @@ -560,10 +545,10 @@ int wordcount(int f, int n) int nlines; /* total number of lines in region */ int avgch; /* average number of chars/word */ int status; /* status return code */ - struct region region; /* region to look at */ + region_t region ; /* region to look at */ /* make sure we have a region to count */ - if ((status = getregion(®ion)) != TRUE) + if( (status = getregion( ®ion)) != TRUE) return status; lp = region.r_linep; offset = region.r_offset; @@ -684,6 +669,5 @@ int gotoeop(int f, int n) curwp->w_flag |= WFMOVE; /* force screen update */ return TRUE; } -#endif /* end of word.c */ diff --git a/word.h b/word.h index e89d095..abdb507 100644 --- a/word.h +++ b/word.h @@ -1,23 +1,25 @@ +/* word.h -- word processing functions */ #ifndef _WORD_H_ #define _WORD_H_ -#define WORDPRO 1 +#include "names.h" -int wrapword( int f, int n) ; -int backword( int f, int n) ; -int forwword( int f, int n) ; -int upperword( int f, int n) ; -int lowerword( int f, int n) ; -int capword( int f, int n) ; -int delfword( int f, int n) ; -int delbword( int f, int n) ; -#if WORDPRO -int gotobop( int f, int n) ; -int gotoeop( int f, int n) ; -int fillpara( int f, int n) ; -int justpara( int f, int n) ; -int killpara( int f, int n) ; -int wordcount( int f, int n) ; -#endif +/* Bindable functions */ +BINDABLE( wrapword) ; +BINDABLE( backword) ; +BINDABLE( forwword) ; +BINDABLE( upperword) ; +BINDABLE( lowerword) ; +BINDABLE( capword) ; +BINDABLE( delfword) ; +BINDABLE( delbword) ; +BINDABLE( gotobop) ; +BINDABLE( gotoeop) ; +BINDABLE( fillpara) ; +BINDABLE( justpara) ; +BINDABLE( killpara) ; +BINDABLE( wordcount) ; #endif + +/* end of word.h */