mined: clean-up trailing whitespace.

Change-Id: Ic27293d7e1d0f830d635b78e7e620dcf0ef3e03f
This commit is contained in:
Thomas Cort 2015-03-22 16:29:04 -04:00 committed by Lionel Sambuc
parent d131b58784
commit d1a87c1f64
2 changed files with 87 additions and 87 deletions

View file

@ -4,15 +4,15 @@
/* /*
* Author: Michiel Huisjes. * Author: Michiel Huisjes.
* *
* 1. General remarks. * 1. General remarks.
* *
* Mined is a screen editor designed for the MINIX operating system. * Mined is a screen editor designed for the MINIX operating system.
* It is meant to be used on files not larger than 50K and to be fast. * It is meant to be used on files not larger than 50K and to be fast.
* When mined starts up, it reads the file into its memory to minimize * When mined starts up, it reads the file into its memory to minimize
* disk access. The only time that disk access is needed is when certain * disk access. The only time that disk access is needed is when certain
* save, write or copy commands are given. * save, write or copy commands are given.
* *
* Mined has the style of Emacs or Jove, that means that there are no modes. * Mined has the style of Emacs or Jove, that means that there are no modes.
* Each character has its own entry in an 256 pointer to function array, * Each character has its own entry in an 256 pointer to function array,
* which is called when that character is typed. Only ASCII characters are * which is called when that character is typed. Only ASCII characters are
@ -21,7 +21,7 @@
* inserted as well. Note that the mapping between commands and functions * inserted as well. Note that the mapping between commands and functions
* called is implicit in the table. Changing the mapping just implies * called is implicit in the table. Changing the mapping just implies
* changing the pointers in this table. * changing the pointers in this table.
* *
* The display consists of SCREENMAX + 1 lines and XMAX + 1 characters. When * The display consists of SCREENMAX + 1 lines and XMAX + 1 characters. When
* a line is larger (or gets larger during editing) than XBREAK characters, * a line is larger (or gets larger during editing) than XBREAK characters,
* the line is either shifted SHIFT_SIZE characters to the left (which means * the line is either shifted SHIFT_SIZE characters to the left (which means
@ -40,7 +40,7 @@
* editing. This line is usually blank or contains information mined needs * editing. This line is usually blank or contains information mined needs
* during editing. This information (or rather questions) is displayed in * during editing. This information (or rather questions) is displayed in
* reverse video. * reverse video.
* *
* The terminal modes are changed completely. All signals like start/stop, * The terminal modes are changed completely. All signals like start/stop,
* interrupt etc. are unset. The only signal that remains is the quit signal. * interrupt etc. are unset. The only signal that remains is the quit signal.
* The quit signal (^\) is the general abort signal for mined. Typing a ^\ * The quit signal (^\) is the general abort signal for mined. Typing a ^\
@ -51,19 +51,19 @@
* The session will also be aborted when an unrecoverable error occurs. E.g * The session will also be aborted when an unrecoverable error occurs. E.g
* when there is no more memory available. If the file has been modified, * when there is no more memory available. If the file has been modified,
* mined will ask if the file has to be saved or not. * mined will ask if the file has to be saved or not.
* If there is no more space left on the disk, mined will just give an error * If there is no more space left on the disk, mined will just give an error
* message and continue. * message and continue.
* *
* The number of system calls are minized. This is done to keep the editor * The number of system calls are minized. This is done to keep the editor
* as fast as possible. I/O is done in SCREEN_SIZE reads/writes. Accumulated * as fast as possible. I/O is done in SCREEN_SIZE reads/writes. Accumulated
* output is also flushed at the end of each character typed. * output is also flushed at the end of each character typed.
* *
* 2. Regular expressions * 2. Regular expressions
* *
* Mined has a build in regular expression matcher, which is used for * Mined has a build in regular expression matcher, which is used for
* searching and replace routines. A regular expression consists of a * searching and replace routines. A regular expression consists of a
* sequence of: * sequence of:
* *
* 1. A normal character matching that character. * 1. A normal character matching that character.
* 2. A . matching any character. * 2. A . matching any character.
* 3. A ^ matching the begin of a line. * 3. A ^ matching the begin of a line.
@ -73,32 +73,32 @@
* characters. A list of characters can be indicated by a '-'. So * characters. A list of characters can be indicated by a '-'. So
* [a-z] matches any letter of the alphabet. If the first character * [a-z] matches any letter of the alphabet. If the first character
* after the '[' is a '^' then the set is negated (matching none of * after the '[' is a '^' then the set is negated (matching none of
* the characters). * the characters).
* A ']', '^' or '-' can be escaped by putting a '\' in front of it. * A ']', '^' or '-' can be escaped by putting a '\' in front of it.
* Of course this means that a \ must be represented by \\. * Of course this means that a \ must be represented by \\.
* 7. If one of the expressions as described in 1-6 is followed by a * 7. If one of the expressions as described in 1-6 is followed by a
* '*' than that expressions matches a sequence of 0 or more of * '*' than that expressions matches a sequence of 0 or more of
* that expression. * that expression.
* *
* Parsing of regular expression is done in two phases. In the first phase * Parsing of regular expression is done in two phases. In the first phase
* the expression is compiled into a more comprehensible form. In the second * the expression is compiled into a more comprehensible form. In the second
* phase the actual matching is done. For more details see 3.6. * phase the actual matching is done. For more details see 3.6.
* *
* *
* 3. Implementation of mined. * 3. Implementation of mined.
* *
* 3.1 Data structures. * 3.1 Data structures.
* *
* The main data structures are as follows. The whole file is kept in a * The main data structures are as follows. The whole file is kept in a
* double linked list of lines. The LINE structure looks like this: * double linked list of lines. The LINE structure looks like this:
* *
* typedef struct Line { * typedef struct Line {
* struct Line *next; * struct Line *next;
* struct Line *prev; * struct Line *prev;
* char *text; * char *text;
* unsigned char shift_count; * unsigned char shift_count;
* } LINE; * } LINE;
* *
* Each line entry contains a pointer to the next line, a pointer to the * Each line entry contains a pointer to the next line, a pointer to the
* previous line and a pointer to the text of that line. A special field * previous line and a pointer to the text of that line. A special field
* shift_count contains the number of shifts (in units of SHIFT_SIZE) * shift_count contains the number of shifts (in units of SHIFT_SIZE)
@ -108,7 +108,7 @@
* that the number of characters of the line is counted and sufficient * that the number of characters of the line is counted and sufficient
* space is allocated to store them (including a linefeed and a '\0'). * space is allocated to store them (including a linefeed and a '\0').
* The resulting address is assigned to the text field in the structure. * The resulting address is assigned to the text field in the structure.
* *
* A special structure is allocated and its address is assigned to the * A special structure is allocated and its address is assigned to the
* variable header as well as the variable tail. The text field of this * variable header as well as the variable tail. The text field of this
* structure is set to NULL. The tail->prev of this structure points * structure is set to NULL. The tail->prev of this structure points
@ -122,12 +122,12 @@
* character inserted. Then the old data space (pointed to by * character inserted. Then the old data space (pointed to by
* cur_line->text) is freed, data space for the new line is allocated and * cur_line->text) is freed, data space for the new line is allocated and
* assigned to cur_line->text. * assigned to cur_line->text.
* *
* Two global variables called x and y represent the x and y coordinates * Two global variables called x and y represent the x and y coordinates
* from the cursor. The global variable nlines contains the number of * from the cursor. The global variable nlines contains the number of
* lines in the file. Last_y indicates the maximum y coordinate of the * lines in the file. Last_y indicates the maximum y coordinate of the
* screen (which is usually SCREENMAX). * screen (which is usually SCREENMAX).
* *
* A few strings must be initialized by hand before compiling mined. * A few strings must be initialized by hand before compiling mined.
* These string are enter_string, which is printed upon entering mined, * These string are enter_string, which is printed upon entering mined,
* rev_video (turn on reverse video), normal_video, rev_scroll (perform a * rev_video (turn on reverse video), normal_video, rev_scroll (perform a
@ -135,13 +135,13 @@
* absolute position string to be printed for cursor motion. The #define * absolute position string to be printed for cursor motion. The #define
* X_PLUS and Y_PLUS should contain the characters to be added to the * X_PLUS and Y_PLUS should contain the characters to be added to the
* coordinates x and y (both starting at 0) to finish cursor positioning. * coordinates x and y (both starting at 0) to finish cursor positioning.
* *
* 3.2 Starting up. * 3.2 Starting up.
* *
* Mined can be called with or without argument and the function * Mined can be called with or without argument and the function
* load_file () is called with these arguments. load_file () checks * load_file () is called with these arguments. load_file () checks
* if the file exists if it can be read and if it is writable and * if the file exists if it can be read and if it is writable and
* sets the writable flag accordingly. If the file can be read, * sets the writable flag accordingly. If the file can be read,
* load_file () reads a line from the file and stores this line into * load_file () reads a line from the file and stores this line into
* a structure by calling install_line () and line_insert () which * a structure by calling install_line () and line_insert () which
* installs the line into the double linked list, until the end of the * installs the line into the double linked list, until the end of the
@ -149,9 +149,9 @@
* Lines are read by the function get_line (), which buffers the * Lines are read by the function get_line (), which buffers the
* reading in blocks of SCREEN_SIZE. Load_file () also initializes the * reading in blocks of SCREEN_SIZE. Load_file () also initializes the
* LINE *variables described above. * LINE *variables described above.
* *
* 3.3 Moving around. * 3.3 Moving around.
* *
* Several commands are implemented for moving through the file. * Several commands are implemented for moving through the file.
* Moving up (UP), down (DN) left (LF) and right (RT) are done by the * Moving up (UP), down (DN) left (LF) and right (RT) are done by the
* arrow keys. Moving one line below the screen scrolls the screen one * arrow keys. Moving one line below the screen scrolls the screen one
@ -163,12 +163,12 @@
* (HO), end of file (EF), scroll one page down (PD), scroll one page up * (HO), end of file (EF), scroll one page down (PD), scroll one page up
* (PU), scroll one line down (SD), scroll one line up (SU) and move to a * (PU), scroll one line down (SD), scroll one line up (SU) and move to a
* certain line number (GOTO). * certain line number (GOTO).
* Two functions called MN () and MP () each move one word further or * Two functions called MN () and MP () each move one word further or
* backwards. A word is a number of non-blanks seperated by a space, a * backwards. A word is a number of non-blanks seperated by a space, a
* tab or a linefeed. * tab or a linefeed.
* *
* 3.4 Modifying text. * 3.4 Modifying text.
* *
* The modifying commands can be separated into two modes. The first * The modifying commands can be separated into two modes. The first
* being inserting text, and the other deleting text. Two functions are * being inserting text, and the other deleting text. Two functions are
* created for these purposes: insert () and delete (). Both are capable * created for these purposes: insert () and delete (). Both are capable
@ -186,11 +186,11 @@
* before cursor (even linefeed) (DPC), delete next word (DNW), delete * before cursor (even linefeed) (DPC), delete next word (DNW), delete
* previous word (DPC) and delete to end of line (if the cursor is at * previous word (DPC) and delete to end of line (if the cursor is at
* a linefeed delete line) (DLN). * a linefeed delete line) (DLN).
* *
* 3.5 Yanking. * 3.5 Yanking.
* *
* A few utilities are provided for yanking pieces of text. The function * A few utilities are provided for yanking pieces of text. The function
* MA () marks the current position in the file. This is done by setting * MA () marks the current position in the file. This is done by setting
* LINE *mark_line and char *mark_text to the current position. Yanking * LINE *mark_line and char *mark_text to the current position. Yanking
* of text can be done in two modes. The first mode just copies the text * of text can be done in two modes. The first mode just copies the text
* from the mark to the current position (or visa versa) into a buffer * from the mark to the current position (or visa versa) into a buffer
@ -207,14 +207,14 @@
* yank ()). Several things can be done with the buffer. It can be * yank ()). Several things can be done with the buffer. It can be
* inserted somewhere else in the file (PT) or it can be copied into * inserted somewhere else in the file (PT) or it can be copied into
* another file (WB), which will be prompted for. * another file (WB), which will be prompted for.
* *
* 3.6 Search and replace routines. * 3.6 Search and replace routines.
* *
* Searching for strings and replacing strings are done by regular * Searching for strings and replacing strings are done by regular
* expressions. For any expression the function compile () is called * expressions. For any expression the function compile () is called
* with as argument the expression to compile. Compile () returns a * with as argument the expression to compile. Compile () returns a
* pointer to a structure which looks like this: * pointer to a structure which looks like this:
* *
* typedef struct regex { * typedef struct regex {
* union { * union {
* char *err_mess; * char *err_mess;
@ -224,7 +224,7 @@
* char *start_ptr; * char *start_ptr;
* char *end_ptr; * char *end_ptr;
* } REGEX; * } REGEX;
* *
* If something went wrong during compiling (e.g. an illegal expression * If something went wrong during compiling (e.g. an illegal expression
* was given), the function reg_error () is called, which sets the status * was given), the function reg_error () is called, which sets the status
* field to REG_ERROR and the err_mess field to the error message. If the * field to REG_ERROR and the err_mess field to the error message. If the
@ -241,7 +241,7 @@
* match was found else it returns a NULL. Line_check () takes the * match was found else it returns a NULL. Line_check () takes the
* same arguments, but return either MATCH or NO_MATCH. * same arguments, but return either MATCH or NO_MATCH.
* During checking, the start_ptr and end_ptr fields of the REGEX * During checking, the start_ptr and end_ptr fields of the REGEX
* structure are assigned to the start and end of the match. * structure are assigned to the start and end of the match.
* Both functions try to find a match by walking through the line * Both functions try to find a match by walking through the line
* character by character. For each possibility, the function * character by character. For each possibility, the function
* check_string () is called with as arguments the REGEX *program and the * check_string () is called with as arguments the REGEX *program and the
@ -271,9 +271,9 @@
* means substitute the match instead. An & can be escaped by a \. When * means substitute the match instead. An & can be escaped by a \. When
* a match is found, the function substitute () will perform the * a match is found, the function substitute () will perform the
* substitution. * substitution.
* *
* 3.6 Miscellaneous commands. * 3.6 Miscellaneous commands.
* *
* A few commands haven't be discussed yet. These are redraw the screen * A few commands haven't be discussed yet. These are redraw the screen
* (RD) fork a shell (SH), print file status (FS), write file to disc * (RD) fork a shell (SH), print file status (FS), write file to disc
* (WT), insert a file at current position (IF), leave editor (XT) and * (WT), insert a file at current position (IF), leave editor (XT) and
@ -282,16 +282,16 @@
* file by calling ask_save (). * file by calling ask_save ().
* The function ESC () will repeat a command n times. It will prompt for * The function ESC () will repeat a command n times. It will prompt for
* the number. Aborting the loop can be done by sending the ^\ signal. * the number. Aborting the loop can be done by sending the ^\ signal.
* *
* 3.7 Utility functions. * 3.7 Utility functions.
* *
* Several functions exists for internal use. First allocation routines: * Several functions exists for internal use. First allocation routines:
* alloc (bytes) and newline () will return a pointer to free data space * alloc (bytes) and newline () will return a pointer to free data space
* if the given size. If there is no more memory available, the function * if the given size. If there is no more memory available, the function
* panic () is called. * panic () is called.
* Signal handling: The only signal that can be send to mined is the * Signal handling: The only signal that can be send to mined is the
* SIGQUIT signal. This signal, functions as a general abort command. * SIGQUIT signal. This signal, functions as a general abort command.
* Mined will abort if the signal is given during the main loop. The * Mined will abort if the signal is given during the main loop. The
* function abort_mined () takes care of that. * function abort_mined () takes care of that.
* Panic () is a function with as argument a error message. It will print * Panic () is a function with as argument a error message. It will print
* the message and the error number set by the kernel (errno) and will * the message and the error number set by the kernel (errno) and will
@ -345,9 +345,9 @@
* of cur_line to an apropiate number according to new_x. The only thing * of cur_line to an apropiate number according to new_x. The only thing
* left to do now is to assign the new values to cur_line, cur_text, x * left to do now is to assign the new values to cur_line, cur_text, x
* and y. * and y.
* *
* 4. Summary of commands. * 4. Summary of commands.
* *
* CURSOR MOTION * CURSOR MOTION
* up-arrow Move cursor 1 line up. At top of screen, reverse scroll * up-arrow Move cursor 1 line up. At top of screen, reverse scroll
* down-arrow Move cursor 1 line down. At bottom, scroll forward. * down-arrow Move cursor 1 line down. At bottom, scroll forward.
@ -359,7 +359,7 @@
* CTRL-_ Move cursor to bottom of screen * CTRL-_ Move cursor to bottom of screen
* CTRL-F Forward to start of next word (even to next line) * CTRL-F Forward to start of next word (even to next line)
* CTRL-B Backward to first character of previous word * CTRL-B Backward to first character of previous word
* *
* SCREEN MOTION * SCREEN MOTION
* Home key Move cursor to first character of file * Home key Move cursor to first character of file
* End key Move cursor to last character of file * End key Move cursor to last character of file
@ -367,7 +367,7 @@
* PgD Scroll backward 1 page. Top line becomes bottom line * PgD Scroll backward 1 page. Top line becomes bottom line
* CTRL-D Scroll screen down one line (reverse scroll) * CTRL-D Scroll screen down one line (reverse scroll)
* CTRL-U Scroll screen up one line (forward scroll) * CTRL-U Scroll screen up one line (forward scroll)
* *
* MODIFYING TEXT * MODIFYING TEXT
* ASCII char Self insert character at cursor * ASCII char Self insert character at cursor
* tab Insert tab at cursor * tab Insert tab at cursor
@ -383,7 +383,7 @@
* CTRL-Y Insert the contents of the save file at current position * CTRL-Y Insert the contents of the save file at current position
* CTRL-Q Insert the contents of the save file into a new file * CTRL-Q Insert the contents of the save file into a new file
* CTRL-G Insert a file at the current position * CTRL-G Insert a file at the current position
* *
* MISCELLANEOUS * MISCELLANEOUS
* CTRL-E Erase and redraw the screen * CTRL-E Erase and redraw the screen
* CTRL-V Visit file (read a new file); complain if old one changed * CTRL-V Visit file (read a new file); complain if old one changed
@ -401,7 +401,7 @@
*/ */
/* ======================================================================== * /* ======================================================================== *
* Utilities * * Utilities *
* ======================================================================== */ * ======================================================================== */
#include "mined.h" #include "mined.h"
@ -440,7 +440,7 @@ void VI(void)
if (modified == TRUE && ask_save() == ERRORS) if (modified == TRUE && ask_save() == ERRORS)
return; return;
/* Get new file name */ /* Get new file name */
if (get_file("Visit file:", new_file) == ERRORS) if (get_file("Visit file:", new_file) == ERRORS)
return; return;
@ -619,7 +619,7 @@ int bottom_line(FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl)
stat_visible = FALSE; stat_visible = FALSE;
string_print(buf); string_print(buf);
if (inbuf != NULL) if (inbuf != NULL)
ret = input(inbuf, statfl); ret = input(inbuf, statfl);
@ -776,7 +776,7 @@ char *find_address(LINE *line, int x_coord, int *old_x)
tx++; tx++;
textp++; textp++;
} }
*old_x = tx; *old_x = tx;
return textp; return textp;
} }
@ -909,7 +909,7 @@ void display(int x_coord, int y_coord, register LINE *line, register int count)
} }
/* /*
* Write_char does a buffered output. * Write_char does a buffered output.
*/ */
int write_char(int fd, int c) int write_char(int fd, int c)
{ {
@ -1023,7 +1023,7 @@ void bad_write(int fd)
{ {
if (fd == STD_OUT) /* Cannot write to terminal? */ if (fd == STD_OUT) /* Cannot write to terminal? */
exit(1); exit(1);
clear_buffer(); clear_buffer();
build_string(text_buffer, "Command aborted: %s (File incomplete)", build_string(text_buffer, "Command aborted: %s (File incomplete)",
(errno == ENOSPC || errno == -ENOSPC) ? (errno == ENOSPC || errno == -ENOSPC) ?
@ -1208,7 +1208,7 @@ char *normal_video = "\033[m"; /* String for leaving reverse video */
char *blank_line = "\033[K"; /* Clear line to end */ char *blank_line = "\033[K"; /* Clear line to end */
#endif /* UNIX */ #endif /* UNIX */
/* /*
* Yank variables. * Yank variables.
*/ */
FLAG yank_status = NOT_VALID; /* Status of yank_file */ FLAG yank_status = NOT_VALID; /* Status of yank_file */
@ -1516,7 +1516,7 @@ void (*escfunc(int c))(void)
} }
/* /*
* ESC() wants a count and a command after that. It repeats the * ESC() wants a count and a command after that. It repeats the
* command count times. If a ^\ is given during repeating, stop looping and * command count times. If a ^\ is given during repeating, stop looping and
* return to main loop. * return to main loop.
*/ */
@ -1596,10 +1596,10 @@ int line_number(void)
count++; count++;
line = line->next; line = line->next;
} }
return count; return count;
} }
/* /*
* Display a line telling how many chars and lines the file contains. Also tell * Display a line telling how many chars and lines the file contains. Also tell
* whether the file is readonly and/or modified. * whether the file is readonly and/or modified.

View file

@ -3,7 +3,7 @@
*/ */
/* ======================================================================== * /* ======================================================================== *
* Move Commands * * Move Commands *
* ======================================================================== */ * ======================================================================== */
#include "mined.h" #include "mined.h"
@ -122,7 +122,7 @@ void GOTO(void)
} }
/* /*
* Scroll forward one page or to eof, whatever comes first. (Bot_line becomes * Scroll forward one page or to eof, whatever comes first. (Bot_line becomes
* top_line of display.) Try to leave the cursor on the same line. If this is * top_line of display.) Try to leave the cursor on the same line. If this is
* not possible, leave cursor on the line halfway the page. * not possible, leave cursor on the line halfway the page.
*/ */
@ -218,7 +218,7 @@ void SU(void)
*/ */
void SD(void) void SD(void)
{ {
if (forward_scroll() != ERRORS) if (forward_scroll() != ERRORS)
move_to(x, (y == 0) ? 0 : y - 1); move_to(x, (y == 0) ? 0 : y - 1);
else else
set_cursor(x, y); set_cursor(x, y);
@ -382,13 +382,13 @@ void DCC(void)
/* /*
* DPC deletes the character on the left side of the cursor. If the cursor is * DPC deletes the character on the left side of the cursor. If the cursor is
* at the beginning of the line, the last character if the previous line is * at the beginning of the line, the last character if the previous line is
* deleted. * deleted.
*/ */
void DPC(void) void DPC(void)
{ {
if (x == 0 && cur_line->prev == header) if (x == 0 && cur_line->prev == header)
return; /* Top of file */ return; /* Top of file */
LF(); /* Move one left */ LF(); /* Move one left */
DCC(); /* Delete character under cursor */ DCC(); /* Delete character under cursor */
} }
@ -529,12 +529,12 @@ int insert(register LINE *line, char *location, char *string)
/* Copy part of line until `location' has been reached */ /* Copy part of line until `location' has been reached */
while (textp != location) while (textp != location)
*bufp++ = *textp++; *bufp++ = *textp++;
/* Insert string at this location */ /* Insert string at this location */
while (*string != '\0') while (*string != '\0')
*bufp++ = *string++; *bufp++ = *string++;
*bufp = '\0'; *bufp = '\0';
if (*(string - 1) == '\n') /* Insert a new line */ if (*(string - 1) == '\n') /* Insert a new line */
(void) line_insert(line, location, length_of(location)); (void) line_insert(line, location, length_of(location));
else /* Append last part of line */ else /* Append last part of line */
@ -655,7 +655,7 @@ void delete(register LINE *start_line, char *start_textp, LINE *end_line,
} }
/* ======================================================================== * /* ======================================================================== *
* Yank Commands * * Yank Commands *
* ======================================================================== */ * ======================================================================== */
LINE *mark_line; /* For marking position. */ LINE *mark_line; /* For marking position. */
@ -678,7 +678,7 @@ void PT(void)
} }
/* /*
* IF() prompt for a filename and inserts the file at the current location * IF() prompt for a filename and inserts the file at the current location
* in the file. * in the file.
*/ */
void IF(void) void IF(void)
@ -689,7 +689,7 @@ void IF(void)
/* Get the file name */ /* Get the file name */
if (get_file("Get and insert file:", name) != FINE) if (get_file("Get and insert file:", name) != FINE)
return; return;
if ((fd = open(name, 0)) < 0) if ((fd = open(name, 0)) < 0)
error("Cannot open ", name); error("Cannot open ", name);
else { else {
@ -709,7 +709,7 @@ void file_insert(int fd, FLAG old_pos)
register int line_count = nlines; /* Nr of lines inserted */ register int line_count = nlines; /* Nr of lines inserted */
LINE *page = cur_line; LINE *page = cur_line;
int ret = ERRORS; int ret = ERRORS;
/* Get the first piece of text (might be ended with a '\n') from fd */ /* Get the first piece of text (might be ended with a '\n') from fd */
if (get_line(fd, line_buffer) == ERRORS) if (get_line(fd, line_buffer) == ERRORS)
return; /* Empty file */ return; /* Empty file */
@ -721,7 +721,7 @@ void file_insert(int fd, FLAG old_pos)
/* Repeat getting lines (and inserting lines) until EOF is reached */ /* Repeat getting lines (and inserting lines) until EOF is reached */
while ((ret = get_line(fd, line_buffer)) != ERRORS && ret != NO_LINE) while ((ret = get_line(fd, line_buffer)) != ERRORS && ret != NO_LINE)
line = line_insert(line, line_buffer, ret); line = line_insert(line, line_buffer, ret);
if (ret == NO_LINE) { /* Last line read not ended by a '\n' */ if (ret == NO_LINE) { /* Last line read not ended by a '\n' */
line = line->next; line = line->next;
(void) insert(line, line->text, line_buffer); (void) insert(line, line->text, line_buffer);
@ -766,7 +766,7 @@ void WB(void)
register int cnt; /* Count check for read/write */ register int cnt; /* Count check for read/write */
int ret = 0; /* Error check for write */ int ret = 0; /* Error check for write */
char file[LINE_LEN]; /* Output file */ char file[LINE_LEN]; /* Output file */
/* Checkout the buffer */ /* Checkout the buffer */
if ((yank_fd = scratch_file(READ)) == ERRORS) { if ((yank_fd = scratch_file(READ)) == ERRORS) {
error("Buffer is empty.", NULL); error("Buffer is empty.", NULL);
@ -776,7 +776,7 @@ void WB(void)
/* Get file name */ /* Get file name */
if (get_file("Write buffer to file:", file) != FINE) if (get_file("Write buffer to file:", file) != FINE)
return; return;
/* Creat the new file */ /* Creat the new file */
if ((new_fd = creat(file, 0644)) < 0) { if ((new_fd = creat(file, 0644)) < 0) {
error("Cannot create ", file); error("Cannot create ", file);
@ -784,7 +784,7 @@ void WB(void)
} }
status_line("Writing ", file); status_line("Writing ", file);
/* Copy buffer into file */ /* Copy buffer into file */
while ((cnt = read(yank_fd, text_buffer, sizeof(text_buffer))) > 0) while ((cnt = read(yank_fd, text_buffer, sizeof(text_buffer))) > 0)
if (write(new_fd, text_buffer, cnt) != cnt) { if (write(new_fd, text_buffer, cnt) != cnt) {
@ -802,7 +802,7 @@ void WB(void)
} }
/* /*
* MA sets mark_line (mark_text) to the current line (text pointer). * MA sets mark_line (mark_text) to the current line (text pointer).
*/ */
void MA(void) void MA(void)
{ {
@ -919,7 +919,7 @@ void yank(LINE *start_line, char *start_textp, LINE *end_line, char *end_textp,
/* Creat file to hold buffer */ /* Creat file to hold buffer */
if ((fd = scratch_file(WRITE)) == ERRORS) if ((fd = scratch_file(WRITE)) == ERRORS)
return; return;
chars_saved = 0L; chars_saved = 0L;
lines_saved = 0; lines_saved = 0;
status_line("Saving text.", NULL); status_line("Saving text.", NULL);
@ -1006,7 +1006,7 @@ int scratch_file(FLAG mode)
} }
/* ======================================================================== * /* ======================================================================== *
* Search Routines * * Search Routines *
* ======================================================================== */ * ======================================================================== */
/* /*
@ -1020,7 +1020,7 @@ int scratch_file(FLAG mode)
* characters. A list of characters can be indicated by a '-'. So * characters. A list of characters can be indicated by a '-'. So
* [a-z] matches any letter of the alphabet. If the first character * [a-z] matches any letter of the alphabet. If the first character
* after the '[' is a '^' then the set is negated (matching none of * after the '[' is a '^' then the set is negated (matching none of
* the characters). * the characters).
* A ']', '^' or '-' can be escaped by putting a '\' in front of it. * A ']', '^' or '-' can be escaped by putting a '\' in front of it.
* 7. If one of the expressions as described in 1-6 is followed by a * 7. If one of the expressions as described in 1-6 is followed by a
* '*' than that expressions matches a sequence of 0 or more of * '*' than that expressions matches a sequence of 0 or more of
@ -1059,7 +1059,7 @@ REGEX *get_expression(char *message)
if (get_string(message, exp_buf, FALSE) == ERRORS) if (get_string(message, exp_buf, FALSE) == ERRORS)
return NULL; return NULL;
if (exp_buf[0] == '\0' && typed_expression[0] == '\0') { if (exp_buf[0] == '\0' && typed_expression[0] == '\0') {
error("No previous expression.", NULL); error("No previous expression.", NULL);
return NULL; return NULL;
@ -1115,12 +1115,12 @@ void change(char *message, FLAG file)
copy_string(mess_buf, message); copy_string(mess_buf, message);
if ((program = get_expression(mess_buf)) == NULL) if ((program = get_expression(mess_buf)) == NULL)
return; return;
/* Get substitution pattern */ /* Get substitution pattern */
build_string(mess_buf, "%s %s by:", mess_buf, typed_expression); build_string(mess_buf, "%s %s by:", mess_buf, typed_expression);
if (get_string(mess_buf, replacement, FALSE) == ERRORS) if (get_string(mess_buf, replacement, FALSE) == ERRORS)
return; return;
set_cursor(0, ymax); set_cursor(0, ymax);
flush(); flush();
/* Substitute until end of file */ /* Substitute until end of file */
@ -1165,7 +1165,7 @@ void change(char *message, FLAG file)
/* /*
* Substitute() replaces the match on this line by the substitute pattern * Substitute() replaces the match on this line by the substitute pattern
* as indicated by the program. Every '&' in the replacement is replaced by * as indicated by the program. Every '&' in the replacement is replaced by
* the original match. A \ in the replacement escapes the next character. * the original match. A \ in the replacement escapes the next character.
*/ */
char *substitute(LINE *line, REGEX *program, char *replacement) char *substitute(LINE *line, REGEX *program, char *replacement)
@ -1180,7 +1180,7 @@ char *substitute(LINE *line, REGEX *program, char *replacement)
/* Copy part of line until the beginning of the match */ /* Copy part of line until the beginning of the match */
while (linep != program->start_ptr) while (linep != program->start_ptr)
*textp++ = *linep++; *textp++ = *linep++;
/* /*
* Replace the match by the substitution pattern. Each occurrence of '&' is * Replace the match by the substitution pattern. Each occurrence of '&' is
* replaced by the original match. A \ escapes the next character. * replaced by the original match. A \ escapes the next character.
@ -1326,7 +1326,7 @@ void finished(register REGEX *program, int *last_exp)
} }
/* /*
* Compile compiles the pattern into a more comprehensible form and returns a * Compile compiles the pattern into a more comprehensible form and returns a
* REGEX structure. If something went wrong, the status field of the structure * REGEX structure. If something went wrong, the status field of the structure
* is set to REG_ERROR and an error message is set into the err_mess field of * is set to REG_ERROR and an error message is set into the err_mess field of
* the union. If all went well the expression is saved and the expression * the union. If all went well the expression is saved and the expression
@ -1401,7 +1401,7 @@ void compile(register char *pattern, REGEX *program)
* the list. * the list.
* The opcode consists of BRACKET and if necessary * The opcode consists of BRACKET and if necessary
* NEGATE to indicate that the list should be negated * NEGATE to indicate that the list should be negated
* and/or STAR to indicate a number of sequence of this * and/or STAR to indicate a number of sequence of this
* list. * list.
* The lower byte contains the length of the list. * The lower byte contains the length of the list.
*/ */
@ -1466,7 +1466,7 @@ void compile(register char *pattern, REGEX *program)
} }
/* /*
* Match gets as argument the program, pointer to place in current line to * Match gets as argument the program, pointer to place in current line to
* start from and the method to search for (either FORWARD or REVERSE). * start from and the method to search for (either FORWARD or REVERSE).
* Match() will look through the whole file until a match is found. * Match() will look through the whole file until a match is found.
* NULL is returned if no match could be found. * NULL is returned if no match could be found.
@ -1557,7 +1557,7 @@ int line_check(register REGEX *program, char *string, FLAG method)
* is found during matching, then the begin position of the string is marked * is found during matching, then the begin position of the string is marked
* and the maximum number of matches is performed. Then the function star() * and the maximum number of matches is performed. Then the function star()
* is called which starts to finish the match from this position of the string * is called which starts to finish the match from this position of the string
* (and expression). Check() return MATCH for a match, NO_MATCH is the string * (and expression). Check() return MATCH for a match, NO_MATCH is the string
* couldn't be matched or REG_ERROR for an illegal opcode in expression. * couldn't be matched or REG_ERROR for an illegal opcode in expression.
*/ */
int check_string(REGEX *program, register char *string, int *expression) int check_string(REGEX *program, register char *string, int *expression)
@ -1607,7 +1607,7 @@ int check_string(REGEX *program, register char *string, int *expression)
default : default :
panic("Corrupted program in check_string()"); panic("Corrupted program in check_string()");
} }
if (star_fl) if (star_fl)
return star(program, mark, string, expression); return star(program, mark, string, expression);
} }
if (*expression & DONE) { if (*expression & DONE) {