summaryrefslogtreecommitdiffstats
path: root/contrib/ee/ee.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-05-27 17:27:03 +0000
committered <ed@FreeBSD.org>2009-05-27 17:27:03 +0000
commit6c84dada4f81e47ab4a1684ec36e4260f937debd (patch)
tree69071259f3ad010993ed926d39c9428688e32b5a /contrib/ee/ee.c
parentf56e53b0d75e50ab9afcdd3e9ea538a6424d5ce7 (diff)
parentc43673ef75b7d102d622ebc468c6046f186c18b6 (diff)
downloadFreeBSD-src-6c84dada4f81e47ab4a1684ec36e4260f937debd.zip
FreeBSD-src-6c84dada4f81e47ab4a1684ec36e4260f937debd.tar.gz
Update ee(1) in the base system to version 1.5.0.
This version is now licensed under a 2-clause BSD license, instead of the Artistic license. I've reverted a lot of local modifications we made to ee, because they have been integrated upstream as well. Only local modifications include: - $FreeBSD$ ID. - Pathname to init.ee. - catopen() call, to honor LC_MESSAGES instead of LANG. To keep SVN happy, I'm putting an application/octet-stream mime type on the KOI8 translations. Reviewed by: current@
Diffstat (limited to 'contrib/ee/ee.c')
-rwxr-xr-xcontrib/ee/ee.c402
1 files changed, 220 insertions, 182 deletions
diff --git a/contrib/ee/ee.c b/contrib/ee/ee.c
index f727bec..4643e31 100755
--- a/contrib/ee/ee.c
+++ b/contrib/ee/ee.c
@@ -5,34 +5,35 @@
|
| written by Hugh Mahon
|
- | THIS MATERIAL IS PROVIDED "AS IS". THERE ARE
- | NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
- | MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
- | IMPLIED WARRANTIES OF MERCHANTABILITY AND
- | FITNESS FOR A PARTICULAR PURPOSE. Neither
- | Hewlett-Packard nor Hugh Mahon shall be liable
- | for errors contained herein, nor for
- | incidental or consequential damages in
- | connection with the furnishing, performance or
- | use of this material. Neither Hewlett-Packard
- | nor Hugh Mahon assumes any responsibility for
- | the use or reliability of this software or
- | documentation. This software and
- | documentation is totally UNSUPPORTED. There
- | is no support contract available. Hewlett-
- | Packard has done NO Quality Assurance on ANY
- | of the program or documentation. You may find
- | the quality of the materials inferior to
- | supported materials.
|
- | This software is not a product of Hewlett-Packard, Co., or any
- | other company. No support is implied or offered with this software.
- | You've got the source, and you're on your own.
+ | Copyright (c) 2009, Hugh Mahon
+ | All rights reserved.
+ |
+ | Redistribution and use in source and binary forms, with or without
+ | modification, are permitted provided that the following conditions
+ | are met:
+ |
+ | * Redistributions of source code must retain the above copyright
+ | notice, this list of conditions and the following disclaimer.
+ | * Redistributions in binary form must reproduce the above
+ | copyright notice, this list of conditions and the following
+ | disclaimer in the documentation and/or other materials provided
+ | with the distribution.
+ |
+ | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ | POSSIBILITY OF SUCH DAMAGE.
|
- | This software may be distributed under the terms of Larry Wall's
- | Artistic license, a copy of which is included in this distribution.
- |
- | This notice must be included with this software and any derivatives.
+ | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
| This editor was purposely developed to be simple, both in
| interface and implementation. This editor was developed to
@@ -49,7 +50,7 @@
| proprietary information which is protected by
| copyright. All rights are reserved.
|
- | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.96 1998/07/14 05:02:30 hugh Exp $
+ | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.102 2009/02/17 03:22:50 hugh Exp hugh $
|
*/
@@ -57,15 +58,11 @@
__FBSDID("$FreeBSD$");
char *ee_copyright_message =
-"Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996 Hugh Mahon ";
+"Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
-char *ee_long_notice[] = {
- "This software and documentation contains",
- "proprietary information which is protected by",
- "copyright. All rights are reserved."
- };
+#include "ee_version.h"
-char *version = "@(#) ee, version 1.4.1 $Revision: 1.96 $";
+char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.102 $";
#ifdef NCURSE
#include "new_curse.h"
@@ -78,28 +75,32 @@ char *version = "@(#) ee, version 1.4.1 $Revision: 1.96 $";
#ifdef HAS_CTYPE
#include <ctype.h>
#endif
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <pwd.h>
+
#include <signal.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <pwd.h>
+
#ifdef HAS_SYS_WAIT
#include <sys/wait.h>
#endif
-#ifdef HAS_STDARG
-#include <stdarg.h>
-#endif
+
#ifdef HAS_STDLIB
#include <stdlib.h>
#endif
-#include <string.h>
+
+#ifdef HAS_STDARG
+#include <stdarg.h>
+#endif
+
#ifdef HAS_UNISTD
#include <unistd.h>
#endif
+
#ifndef NO_CATGETS
#include <locale.h>
#include <nl_types.h>
@@ -151,6 +152,7 @@ int position; /* offset in bytes from begin of line */
int scr_pos; /* horizontal position */
int scr_vert; /* vertical position on screen */
int scr_horz; /* horizontal position on screen */
+int absolute_lin; /* number of lines from top */
int tmp_vert, tmp_horz;
int input_file; /* indicate to read input file */
int recv_file; /* indicate reading a file */
@@ -203,11 +205,8 @@ unsigned char *d_char; /* deleted character */
unsigned char *d_word; /* deleted word */
unsigned char *d_line; /* deleted line */
char in_string[513]; /* buffer for reading a file */
-unsigned char *print_command = "lpr"; /* string to use for the print command */
+unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
unsigned char *start_at_line = NULL; /* move to this line at start of session*/
-const char count_text_default[] = "===============================================================================";
-int count_text_len = sizeof(count_text_default); /* length of the line above */
-char count_text[sizeof(count_text_default)]; /* buffer for current position display */
int in; /* input character */
FILE *temp_fp; /* temporary file pointer */
@@ -223,7 +222,6 @@ WINDOW *com_win;
WINDOW *text_win;
WINDOW *help_win;
WINDOW *info_win;
-WINDOW *count_win;
#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
@@ -344,7 +342,6 @@ char *is_in_string P_((char *string, char *substring));
char *resolve_name P_((char *name));
int restrict_mode P_((void));
int unique_test P_((char *string, char *list[]));
-void renumber_lines P_((struct text *firstline, int startnumber));
void strings_init P_((void));
#undef P_
@@ -538,29 +535,35 @@ char *ree_no_file_msg;
char *cancel_string;
char *menu_too_lrg_msg;
char *more_above_str, *more_below_str;
+char *separator = "===============================================================================";
char *chinese_cmd, *nochinese_cmd;
+#ifndef __STDC__
+#ifndef HAS_STDLIB
+extern char *malloc();
+extern char *realloc();
+extern char *getenv();
+FILE *fopen(); /* declaration for open function */
+#endif /* HAS_STDLIB */
+#endif /* __STDC__ */
int
main(argc, argv) /* beginning of main program */
int argc;
char *argv[];
{
- /* Always read from (and write to) a terminal. */
- if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
- fprintf(stderr, "ee's standard input and output must be a terminal\n");
- exit(1);
- }
+ int counter;
+
+ for (counter = 1; counter < 24; counter++)
+ signal(counter, SIG_IGN);
signal(SIGCHLD, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGINT, edit_abort);
- signal(SIGHUP, edit_abort);
-
d_char = malloc(3); /* provide a buffer for multi-byte chars */
d_word = malloc(150);
- *d_word = (char) NULL;
+ *d_word = '\0';
d_line = NULL;
dlt_line = txtalloc();
dlt_line->line = d_line;
@@ -578,7 +581,8 @@ char *argv[];
scr_pos =0;
scr_vert = 0;
scr_horz = 0;
- bit_bucket = fopen(_PATH_DEVNULL, "w");
+ absolute_lin = 1;
+ bit_bucket = fopen("/dev/null", "w");
edit = TRUE;
gold = case_sen = FALSE;
shell_fork = TRUE;
@@ -607,25 +611,32 @@ char *argv[];
clear_com_win = TRUE;
+ counter = 0;
+
while(edit)
{
+ /*
+ | display line and column information
+ */
if (info_window)
{
- snprintf(count_text, count_text_len, "L: %d C: %d %s", \
- curr_line->line_number, scr_horz + 1, count_text_default);
- wmove(count_win, 0, 0);
if (!nohighlight)
- wstandout(count_win);
- wprintw(count_win, count_text);
- wstandend(count_win);
- wnoutrefresh(count_win);
+ wstandout(info_win);
+ wmove(info_win, 5, 0);
+ wprintw(info_win, separator);
+ wmove(info_win, 5, 5);
+ wprintw(info_win, "line %d col %d lines from top %d ",
+ curr_line->line_number, scr_horz, absolute_lin);
+ wstandend(info_win);
+ wrefresh(info_win);
}
- wnoutrefresh(text_win);
- doupdate();
+ wrefresh(text_win);
in = wgetch(text_win);
if (in == -1)
- continue;
+ exit(0); /* without this exit ee will go into an
+ infinite loop if the network
+ session detaches */
resize_check();
@@ -800,7 +811,7 @@ int disp;
d_char[0] = *point;
d_char[1] = *(point + 1);
}
- d_char[del_width] = (unsigned char) NULL;
+ d_char[del_width] = '\0';
}
while (temp_pos <= curr_line->line_length)
{
@@ -817,6 +828,7 @@ int disp;
}
else if (curr_line->prev_line != NULL)
{
+ absolute_lin--;
text_changes = TRUE;
left(disp); /* go to previous line */
temp_buff = curr_line->next_line;
@@ -824,12 +836,11 @@ int disp;
if (temp_buff->next_line != NULL)
temp_buff->next_line->prev_line = curr_line;
curr_line->next_line = temp_buff->next_line;
- renumber_lines(curr_line->next_line, curr_line->line_number + 1);
temp2 = temp_buff->line;
if (in == 8)
{
d_char[0] = '\n';
- d_char[1] = (unsigned char) NULL;
+ d_char[1] = '\0';
}
tp = point;
temp_pos = 1;
@@ -841,7 +852,7 @@ int disp;
tp++;
temp2++;
}
- *tp = (char) NULL;
+ *tp = '\0';
free(temp_buff->line);
free(temp_buff);
temp_buff = curr_line;
@@ -930,7 +941,7 @@ char character;
int column;
{
int i1, i2;
- unsigned char *string;
+ char *string;
char string2[8];
if (character == TAB)
@@ -958,16 +969,16 @@ int column;
}
else
{
- waddch(window, (unsigned char)character );
+ waddch(window, (char)character );
return(1);
}
}
else
{
- waddch(window, (unsigned char)character);
+ waddch(window, (char)character);
return(1);
}
- for (i2 = 0; (string[i2] != (char) NULL) && (((column+i2+1)-horiz_offset) < last_col); i2++)
+ for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
waddch(window, string[i2]);
return(strlen(string));
}
@@ -1069,8 +1080,8 @@ int disp;
temp_nod->line = extra= malloc(10);
temp_nod->line_length = 1;
temp_nod->max_length = 10;
+ temp_nod->line_number = curr_line->line_number + 1;
temp_nod->next_line = curr_line->next_line;
- renumber_lines(temp_nod, curr_line->line_number + 1);
if (temp_nod->next_line != NULL)
temp_nod->next_line->prev_line = temp_nod;
temp_nod->prev_line = curr_line;
@@ -1092,13 +1103,14 @@ int disp;
temp++;
}
temp=point;
- *temp = (char) NULL;
+ *temp = '\0';
temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
curr_line->line_length = 1 + temp - curr_line->line;
}
curr_line->line_length = position;
+ absolute_lin++;
curr_line = temp_nod;
- *extra = (char) NULL;
+ *extra = '\0';
position = 1;
point= curr_line->line;
if (disp)
@@ -1141,9 +1153,9 @@ struct files *name_alloc() /* allocate space for file name list node */
unsigned char *next_word(string) /* move to next word in string */
unsigned char *string;
{
- while ((*string != (char) NULL) && ((*string != 32) && (*string != 9)))
+ while ((*string != '\0') && ((*string != 32) && (*string != 9)))
string++;
- while ((*string != (char) NULL) && ((*string == 32) || (*string == 9)))
+ while ((*string != '\0') && ((*string == 32) || (*string == 9)))
string++;
return(string);
}
@@ -1177,7 +1189,7 @@ control() /* use control for commands */
if (in == 1) /* control a */
{
string = get_string(ascii_code_str, TRUE);
- if (*string != (char) NULL)
+ if (*string != '\0')
{
in = atoi(string);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
@@ -1285,7 +1297,7 @@ emacs_control()
else if (in == 15) /* control o */
{
string = get_string(ascii_code_str, TRUE);
- if (*string != (char) NULL)
+ if (*string != '\0')
{
in = atoi(string);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
@@ -1325,7 +1337,10 @@ void
bottom() /* go to bottom of file */
{
while (curr_line->next_line != NULL)
+ {
curr_line = curr_line->next_line;
+ absolute_lin++;
+ }
point = curr_line->line;
if (horiz_offset)
horiz_offset = 0;
@@ -1338,7 +1353,10 @@ void
top() /* go to top of file */
{
while (curr_line->prev_line != NULL)
+ {
curr_line = curr_line->prev_line;
+ absolute_lin--;
+ }
point = curr_line->line;
if (horiz_offset)
horiz_offset = 0;
@@ -1351,6 +1369,7 @@ void
nextline() /* move pointers to start of next line */
{
curr_line = curr_line->next_line;
+ absolute_lin++;
point = curr_line->line;
position = 1;
if (scr_vert == last_line)
@@ -1369,6 +1388,7 @@ void
prevline() /* move pointers to start of previous line*/
{
curr_line = curr_line->prev_line;
+ absolute_lin--;
point = curr_line->line;
position = 1;
if (scr_vert == 0)
@@ -1406,6 +1426,7 @@ int disp;
{
if (!disp)
{
+ absolute_lin--;
curr_line = curr_line->prev_line;
point = curr_line->line + curr_line->line_length;
position = curr_line->line_length;
@@ -1441,6 +1462,7 @@ int disp;
{
if (!disp)
{
+ absolute_lin++;
curr_line = curr_line->next_line;
point = curr_line->line;
position = 1;
@@ -1526,7 +1548,7 @@ function_key() /* process function key */
bol();
else if (in == KEY_END)
eol();
- else if ( in == KEY_UP)
+ else if (in == KEY_UP)
up();
else if (in == KEY_DOWN)
down();
@@ -1686,7 +1708,7 @@ char *cmd_str1;
return;
}
cmd_str = next_word(cmd_str);
- if (*cmd_str == (char) NULL)
+ if (*cmd_str == '\0')
{
cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
}
@@ -1702,7 +1724,7 @@ char *cmd_str1;
return;
}
cmd_str = next_word(cmd_str);
- if (*cmd_str == (char) NULL)
+ if (*cmd_str == '\0')
{
cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
}
@@ -1872,7 +1894,7 @@ int advance; /* if true, skip leading spaces and tabs */
esc_flag = FALSE;
in = wgetch(com_win);
if (in == -1)
- continue;
+ exit(0);
if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
{
tmp_int = g_horz;
@@ -1897,7 +1919,7 @@ int advance; /* if true, skip leading spaces and tabs */
esc_flag = TRUE;
in = wgetch(com_win);
if (in == -1)
- continue;
+ exit(0);
}
*nam_str = in;
g_pos++;
@@ -1913,9 +1935,9 @@ int advance; /* if true, skip leading spaces and tabs */
}
wrefresh(com_win);
if (esc_flag)
- in = (char) NULL;
+ in = '\0';
} while ((in != '\n') && (in != '\r'));
- *nam_str = (char) NULL;
+ *nam_str = '\0';
nam_str = tmp_string;
if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
nam_str = next_word(nam_str);
@@ -1940,7 +1962,7 @@ int sensitive;
strng1 = string1;
strng2 = string2;
tmp = 0;
- if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == (char) NULL) || (*strng2 == (char) NULL))
+ if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
return(FALSE);
equal = TRUE;
while (equal)
@@ -1957,7 +1979,7 @@ int sensitive;
}
strng1++;
strng2++;
- if ((*strng1 == (char) NULL) || (*strng2 == (char) NULL) || (*strng1 == ' ') || (*strng2 == ' '))
+ if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
break;
tmp++;
}
@@ -2002,6 +2024,14 @@ char *cmd_str;
}
else
{
+ if (!strcmp(direction, "d"))
+ {
+ absolute_lin += i;
+ }
+ else
+ {
+ absolute_lin -= i;
+ }
curr_line = t_line;
point = curr_line->line;
position = 1;
@@ -2062,7 +2092,7 @@ char *arguments[];
input_file = FALSE;
recv_file = FALSE;
count = 1;
- while ((count < numargs) && (!no_more_opts))
+ while ((count < numargs)&& (!no_more_opts))
{
buff = arguments[count];
if (!strcmp("-i", buff))
@@ -2086,7 +2116,7 @@ char *arguments[];
fprintf(stderr, usage4);
exit(1);
}
- else if (*buff == '+')
+ else if ((*buff == '+') && (start_at_line == NULL))
{
buff++;
start_at_line = buff;
@@ -2113,13 +2143,13 @@ char *arguments[];
temp_names = temp_names->next_name;
}
ptr = temp_names->name = malloc(strlen(buff) + 1);
- while (*buff != (char) NULL)
+ while (*buff != '\0')
{
*ptr = *buff;
buff++;
ptr++;
}
- *ptr = (char) NULL;
+ *ptr = '\0';
temp_names->next_name = NULL;
input_file = TRUE;
recv_file = TRUE;
@@ -2201,7 +2231,7 @@ check_fp() /* open or close files according to flags */
wmove(com_win, 0, 0);
wclrtoeol(com_win);
text_changes = TRUE;
- if ((tmp_file != NULL) && (*tmp_file != (char) NULL))
+ if ((tmp_file != NULL) && (*tmp_file != '\0'))
wprintw(com_win, file_read_fin_msg, tmp_file);
}
wrefresh(com_win);
@@ -2318,8 +2348,8 @@ int *append; /* TRUE if must append more text to end of current line */
if (!(*append)) /* if not append to current line, insert new one */
{
tline = txtalloc(); /* allocate data structure for next line */
+ tline->line_number = curr_line->line_number + 1;
tline->next_line = curr_line->next_line;
- renumber_lines(tline, curr_line->line_number + 1);
tline->prev_line = curr_line;
curr_line->next_line = tline;
if (tline->next_line != NULL)
@@ -2340,7 +2370,7 @@ int *append; /* TRUE if must append more text to end of current line */
point++;
str1++;
}
- *point = (char) NULL;
+ *point = '\0';
*append = FALSE;
if ((num == length) && (*str2 != '\n'))
*append = TRUE;
@@ -2378,10 +2408,10 @@ finish() /* prepare to exit edit session */
| portion of file_op()
*/
- if ((file_name == NULL) || (*file_name == (char) NULL))
+ if ((file_name == NULL) || (*file_name == '\0'))
file_name = get_string(save_file_name_prompt, TRUE);
- if ((file_name == NULL) || (*file_name == (char) NULL))
+ if ((file_name == NULL) || (*file_name == '\0'))
{
wmove(com_win, 0, 0);
wprintw(com_win, file_not_saved_msg);
@@ -2438,7 +2468,6 @@ int noverify;
recv_file = TRUE;
input_file = TRUE;
check_fp();
- text_changes = FALSE;
}
return(0);
}
@@ -2463,10 +2492,11 @@ delete_text()
{
free(curr_line->line);
curr_line = curr_line->prev_line;
+ absolute_lin--;
free(curr_line->next_line);
}
curr_line->next_line = NULL;
- *curr_line->line = (char) NULL;
+ *curr_line->line = '\0';
curr_line->line_length = 1;
curr_line->line_number = 1;
point = curr_line->line;
@@ -2558,7 +2588,7 @@ int display_message;
int iter;
int found;
- if ((srch_str == NULL) || (*srch_str == (char) NULL))
+ if ((srch_str == NULL) || (*srch_str == '\0'))
return(FALSE);
if (display_message)
{
@@ -2583,7 +2613,7 @@ int display_message;
if (case_sen) /* if case sensitive */
{
srch_3 = srch_str;
- while ((*srch_2 == *srch_3) && (*srch_3 != (char) NULL))
+ while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
{
found = TRUE;
srch_2++;
@@ -2593,14 +2623,14 @@ int display_message;
else /* if not case sensitive */
{
srch_3 = u_srch_str;
- while ((toupper(*srch_2) == *srch_3) && (*srch_3 != (char) NULL))
+ while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
{
found = TRUE;
srch_2++;
srch_3++;
}
} /* end else */
- if (!((*srch_3 == (char) NULL) && (found)))
+ if (!((*srch_3 == '\0') && (found)))
{
found = FALSE;
if (iter < srch_line->line_length)
@@ -2640,6 +2670,7 @@ int display_message;
}
else
{
+ absolute_lin += lines_moved;
curr_line = srch_line;
point = srch_1;
position = iter;
@@ -2668,19 +2699,19 @@ search_prompt() /* prompt and read search string (srch_str) */
{
if (srch_str != NULL)
free(srch_str);
- if ((u_srch_str != NULL) && (*u_srch_str != (char) NULL))
+ if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
free(u_srch_str);
srch_str = get_string(search_prompt_str, FALSE);
gold = FALSE;
srch_3 = srch_str;
srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
- while (*srch_3 != (char) NULL)
+ while (*srch_3 != '\0')
{
*srch_1 = toupper(*srch_3);
srch_1++;
srch_3++;
}
- *srch_1 = (char) NULL;
+ *srch_1 = '\0';
search(TRUE);
}
@@ -2717,7 +2748,7 @@ undel_char() /* undelete last deleted character */
{
in = d_char[0];
insert(in);
- if (d_char[1] != (unsigned char) NULL)
+ if (d_char[1] != '\0')
{
in = d_char[1];
insert(in);
@@ -2759,7 +2790,7 @@ del_word() /* delete word in front of cursor */
d_word2++;
d_word3++;
}
- *d_word2 = (char) NULL;
+ *d_word2 = '\0';
d_wrd_len = difference = d_word2 - d_word;
d_word2 = point;
while (tposit < curr_line->line_length)
@@ -2770,7 +2801,7 @@ del_word() /* delete word in front of cursor */
d_word3++;
}
curr_line->line_length -= difference;
- *d_word2 = (char) NULL;
+ *d_word2 = '\0';
draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
d_char[0] = tmp_char[0];
d_char[1] = tmp_char[1];
@@ -2823,7 +2854,7 @@ undel_word() /* undelete last deleted word */
}
curr_line->line_length += d_wrd_len;
tmp_old_ptr = point;
- *tmp_ptr = (char) NULL;
+ *tmp_ptr = '\0';
tmp_ptr = tmp_space;
tposit = 1;
/*
@@ -2836,7 +2867,7 @@ undel_word() /* undelete last deleted word */
tmp_ptr++;
tmp_old_ptr++;
}
- *tmp_old_ptr = (char) NULL;
+ *tmp_old_ptr = '\0';
free(tmp_space);
draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
}
@@ -2862,8 +2893,8 @@ del_line() /* delete from cursor to end of line */
tposit++;
}
dlt_line->line_length = 1 + tposit - position;
- *dl1 = (char) NULL;
- *point = (char) NULL;
+ *dl1 = '\0';
+ *point = '\0';
curr_line->line_length = position;
wclrtoeol(text_win);
if (curr_line->next_line != NULL)
@@ -2898,7 +2929,7 @@ undel_line() /* undelete last deleted line */
ud1++;
ud2++;
}
- *ud1 = (char) NULL;
+ *ud1 = '\0';
draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
}
@@ -2938,6 +2969,7 @@ int lines;
}
scr_vert = scr_vert + i;
curr_line = tmp_line;
+ absolute_lin += i;
point = tmp;
scanline(point);
}
@@ -2968,6 +3000,7 @@ int lines;
{
down();
}
+ absolute_lin -= i;
scr_vert = scr_vert - i;
curr_line = tmp_line;
point = tmp;
@@ -3025,6 +3058,20 @@ adv_line() /* advance to beginning of next line */
}
void
+from_top()
+{
+ struct text *tmpline = first_line;
+ int x = 1;
+
+ while ((tmpline != NULL) && (tmpline != curr_line))
+ {
+ x++;
+ tmpline = tmpline->next_line;
+ }
+ absolute_lin = x;
+}
+
+void
sh_command(string) /* execute shell command */
char *string; /* string containing user command */
{
@@ -3044,7 +3091,7 @@ char *string; /* string containing user command */
if (!(path = getenv("SHELL")))
path = "/bin/sh";
last_slash = temp_point = path;
- while (*temp_point != (char) NULL)
+ while (*temp_point != '\0')
{
if (*temp_point == '/')
last_slash = ++temp_point;
@@ -3116,6 +3163,7 @@ char *string; /* string containing user command */
scr_horz = scr_pos = 0;
position = 1;
curr_line = line_holder;
+ from_top();
point = curr_line->line;
out_pipe = FALSE;
signal(SIGCHLD, SIG_DFL);
@@ -3154,8 +3202,9 @@ char *string; /* string containing user command */
}
for (value = 1; value < 24; value++)
signal(value, SIG_DFL);
- execl(path, last_slash, "-c", string, (char *)NULL);
- errx(1, exec_err_msg, path);
+ execl(path, last_slash, "-c", string, NULL);
+ fprintf(stderr, exec_err_msg, path);
+ exit(-1);
}
else /* if the parent */
{
@@ -3198,7 +3247,7 @@ char *string; /* string containing user command */
}
if (shell_fork)
{
- printf("%s", continue_msg);
+ printf(continue_msg);
fflush(stdout);
while ((in = getchar()) != '\n')
;
@@ -3258,12 +3307,9 @@ set_up_term() /* set up the terminal for operating with ae */
if (info_window)
{
info_type = CONTROL_KEYS;
- info_win = newwin(5, COLS, 0, 0);
+ info_win = newwin(6, COLS, 0, 0);
werase(info_win);
paint_info_win();
- count_win = newwin(1, COLS, 5, 0);
- leaveok(count_win, TRUE);
- wrefresh(count_win);
}
last_col = COLS - 1;
@@ -3288,7 +3334,6 @@ resize_check()
delwin(text_win);
delwin(com_win);
delwin(help_win);
- delwin(count_win);
set_up_term();
redraw();
wrefresh(text_win);
@@ -3306,7 +3351,7 @@ struct menu_entries menu_list[];
int counter;
int length;
int input;
- int temp = 0;
+ int temp;
int list_size;
int top_offset; /* offset from top where menu items start */
int vert_pos; /* vertical position */
@@ -3388,7 +3433,10 @@ struct menu_entries menu_list[];
wmove(temp_win, (counter + top_offset - off_start), 3);
wrefresh(temp_win);
- input = wgetch(temp_win);
+ in = wgetch(temp_win);
+ input = in;
+ if (input == -1)
+ exit(0);
if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
((input >= '0') && (input <= '9')))
@@ -3631,6 +3679,8 @@ help()
wprintw(com_win, press_any_key_msg);
wrefresh(com_win);
counter = wgetch(com_win);
+ if (counter == -1)
+ exit(0);
werase(com_win);
wmove(com_win, 0, 0);
werase(help_win);
@@ -3658,6 +3708,11 @@ paint_info_win()
else if (info_type == COMMANDS)
waddstr(info_win, command_strings[counter]);
}
+ wmove(info_win, 5, 0);
+ if (!nohighlight)
+ wstandout(info_win);
+ waddstr(info_win, separator);
+ wstandend(info_win);
wrefresh(info_win);
}
@@ -3691,15 +3746,12 @@ create_info_window()
idlok(text_win, TRUE);
werase(text_win);
info_window = TRUE;
- info_win = newwin(5, COLS, 0, 0);
+ info_win = newwin(6, COLS, 0, 0);
werase(info_win);
info_type = CONTROL_KEYS;
midscreen(min(scr_vert, last_line), point);
clearok(info_win, TRUE);
paint_info_win();
- count_win = newwin(1, COLS, 5, 0);
- leaveok(count_win, TRUE);
- wrefresh(count_win);
wrefresh(text_win);
clear_com_win = TRUE;
}
@@ -3747,9 +3799,9 @@ int arg;
flag = FALSE;
string = in_file_name;
- if ((string == NULL) || (*string == (char) NULL))
+ if ((string == NULL) || (*string == '\0'))
string = get_string(save_file_name_prompt, TRUE);
- if ((string == NULL) || (*string == (char) NULL))
+ if ((string == NULL) || (*string == '\0'))
{
wmove(com_win, 0, 0);
wprintw(com_win, file_not_saved_msg);
@@ -3784,7 +3836,7 @@ shell_op()
char *string;
if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
- (*string != (char) NULL))
+ (*string != '\0'))
{
sh_command(string);
free(string);
@@ -3910,14 +3962,14 @@ Format() /* format the paragraph according to set margins */
offset -= position;
counter = position;
line = temp1 = point;
- while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
+ while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
{
*temp2 = *temp1;
temp2++;
temp1++;
counter++;
}
- *temp2 = (char) NULL;
+ *temp2 = '\0';
if (position != 1)
bol();
while (!Blank_Line(curr_line->prev_line))
@@ -4093,8 +4145,8 @@ ee_init() /* check for init file and read it if it exists */
int temp_int;
string = getenv("HOME");
- if (!string)
- string = "/root"; /* Set to reasonable default so we don't crash */
+ if (string == NULL)
+ string = "/tmp";
str1 = home = malloc(strlen(string)+10);
strcpy(home, string);
strcat(home, "/.init.ee");
@@ -4111,7 +4163,7 @@ ee_init() /* check for init file and read it if it exists */
str1 = str2 = string;
while (*str2 != '\n')
str2++;
- *str2 = (char) NULL;
+ *str2 = '\0';
if (unique_test(string, init_strings) != 1)
continue;
@@ -4142,7 +4194,7 @@ ee_init() /* check for init file and read it if it exists */
else if (compare(str1, Echo, FALSE))
{
str1 = next_word(str1);
- if (*str1 != (char) NULL)
+ if (*str1 != '\0')
echo_string(str1);
}
else if (compare(str1, PRINTCOMMAND, FALSE))
@@ -4266,7 +4318,7 @@ dump_ee_conf()
while ((string = fgets(buffer, 512, old_init_file)) != NULL)
{
length = strlen(string);
- string[length - 1] = (char) NULL;
+ string[length - 1] = '\0';
if (unique_test(string, init_strings) == 1)
{
@@ -4313,7 +4365,7 @@ char *string;
int Counter;
temp = string;
- while (*temp != (char) NULL)
+ while (*temp != '\0')
{
if (*temp == '\\')
{
@@ -4389,8 +4441,7 @@ ispell_op()
return;
}
(void)sprintf(template, "/tmp/ee.XXXXXXXX");
- name = mktemp(&template[0]);
- fd = open(name, O_CREAT | O_EXCL | O_RDWR, 0600);
+ fd = mkstemp(template);
if (fd < 0) {
wmove(com_win, 0, 0);
wprintw(com_win, create_file_fail_msg, name);
@@ -4421,7 +4472,7 @@ struct text *test_line;
return(0);
pnt = test_line->line;
- if ((pnt == NULL) || (*pnt == (char) NULL) ||
+ if ((pnt == NULL) || (*pnt == '\0') ||
(*pnt == '.') || (*pnt == '>'))
return(0);
@@ -4430,16 +4481,16 @@ struct text *test_line;
pnt = next_word(pnt);
}
- if (*pnt == (char) NULL)
+ if (*pnt == '\0')
return(0);
counter = 0;
- while ((*pnt != (char) NULL) && ((*pnt != ' ') && (*pnt != '\t')))
+ while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
{
pnt++;
counter++;
}
- while ((*pnt != (char) NULL) && ((*pnt == ' ') || (*pnt == '\t')))
+ while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
{
pnt++;
counter++;
@@ -4490,7 +4541,7 @@ Auto_Format() /* format the paragraph according to set margins */
d_line = NULL;
auto_format = FALSE;
offset = position;
- if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == (char) NULL)))
+ if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
prev_word();
temp_dword = d_word;
temp_dwl = d_wrd_len;
@@ -4505,14 +4556,14 @@ Auto_Format() /* format the paragraph according to set margins */
offset -= position;
counter = position;
line = temp1 = point;
- while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
+ while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
{
*temp2 = *temp1;
temp2++;
temp1++;
counter++;
}
- *temp2 = (char) NULL;
+ *temp2 = '\0';
if (position != 1)
bol();
while (!Blank_Line(curr_line->prev_line))
@@ -4814,9 +4865,9 @@ char * string, *substring;
{
char *full, *sub;
- for (sub = substring; (sub != NULL) && (*sub != (char)NULL); sub++)
+ for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
{
- for (full = string; (full != NULL) && (*full != (char)NULL);
+ for (full = string; (full != NULL) && (*full != '\0');
full++)
{
if (*sub == *full)
@@ -4859,7 +4910,7 @@ char *name;
slash = strchr(name, '/');
if (slash == NULL)
return(name);
- *slash = (char) NULL;
+ *slash = '\0';
user = (struct passwd *) getpwnam((name + 1));
*slash = '/';
}
@@ -4879,10 +4930,10 @@ char *name;
tmp = buffer;
index = 0;
- while ((*tmp != (char) NULL) && (index < 1024))
+ while ((*tmp != '\0') && (index < 1024))
{
- while ((*tmp != (char) NULL) && (*tmp != '$') &&
+ while ((*tmp != '\0') && (*tmp != '$') &&
(index < 1024))
{
long_buffer[index] = *tmp;
@@ -4898,7 +4949,7 @@ char *name;
if (*tmp == '{') /* } */ /* bracketed variable name */
{
tmp++; /* { */
- while ((*tmp != (char) NULL) &&
+ while ((*tmp != '\0') &&
(*tmp != '}') &&
(counter < 128))
{
@@ -4911,7 +4962,7 @@ char *name;
}
else
{
- while ((*tmp != (char) NULL) &&
+ while ((*tmp != '\0') &&
(*tmp != '/') &&
(*tmp != '$') &&
(counter < 128))
@@ -4921,7 +4972,7 @@ char *name;
tmp++;
}
}
- short_buffer[counter] = (char) NULL;
+ short_buffer[counter] = '\0';
if ((slash = getenv(short_buffer)) != NULL)
{
offset = strlen(slash);
@@ -4944,7 +4995,7 @@ char *name;
if (index == 1024)
return(buffer);
else
- long_buffer[index] = (char) NULL;
+ long_buffer[index] = '\0';
if (name != buffer)
free(buffer);
@@ -4996,19 +5047,6 @@ char *list[];
return(num_match);
}
-void
-renumber_lines(firstline, startnumber)
-struct text *firstline;
-int startnumber;
-{
- struct text *lineptr;
- int i;
-
- i = startnumber;
- for (lineptr = firstline; lineptr != NULL; lineptr = lineptr->next_line)
- lineptr->line_number = i++;
-}
-
#ifndef NO_CATGETS
/*
| Get the catalog entry, and if it got it from the catalog,
@@ -5154,7 +5192,7 @@ strings_init()
searching_msg = catgetlocal( 100, " ...searching");
str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
search_prompt_str = catgetlocal( 102, "search for: ");
- exec_err_msg = catgetlocal( 103, "could not exec %s");
+ exec_err_msg = catgetlocal( 103, "could not exec %s\n");
continue_msg = catgetlocal( 104, "press return to continue ");
menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
menu_size_err_msg = catgetlocal( 106, "menu too large for window");
@@ -5202,8 +5240,8 @@ strings_init()
mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
emacs_help_text[0] = help_text[0];
emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
- emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t begin of file ");
- emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u end of file ");
+ emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
+ emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
@@ -5222,10 +5260,10 @@ strings_init()
emacs_help_text[19] = help_text[19];
emacs_help_text[20] = help_text[20];
emacs_help_text[21] = help_text[21];
- emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev line ^g prev page");
- emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next line ^v next page");
- emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back char ^z next word");
- emacs_control_keys[3] = catgetlocal( 157, "^t begin of file ^e end of line ^r restore word ^f forward char ");
+ emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
+ emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
+ emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
+ emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
EMACS_string = catgetlocal( 159, "EMACS");
NOEMACS_string = catgetlocal( 160, "NOEMACS");
OpenPOWER on IntegriCloud