ee.c revision 192856
1192830Sed/* 2192830Sed | ee (easy editor) 3192830Sed | 4192830Sed | An easy to use, simple screen oriented editor. 5192830Sed | 6192830Sed | written by Hugh Mahon 7192830Sed | 8192830Sed | THIS MATERIAL IS PROVIDED "AS IS". THERE ARE 9192830Sed | NO WARRANTIES OF ANY KIND WITH REGARD TO THIS 10192830Sed | MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE 11192830Sed | IMPLIED WARRANTIES OF MERCHANTABILITY AND 12192830Sed | FITNESS FOR A PARTICULAR PURPOSE. Neither 13192830Sed | Hewlett-Packard nor Hugh Mahon shall be liable 14192830Sed | for errors contained herein, nor for 15192830Sed | incidental or consequential damages in 16192830Sed | connection with the furnishing, performance or 17192830Sed | use of this material. Neither Hewlett-Packard 18192830Sed | nor Hugh Mahon assumes any responsibility for 19192830Sed | the use or reliability of this software or 20192830Sed | documentation. This software and 21192830Sed | documentation is totally UNSUPPORTED. There 22192830Sed | is no support contract available. Hewlett- 23192830Sed | Packard has done NO Quality Assurance on ANY 24192830Sed | of the program or documentation. You may find 25192830Sed | the quality of the materials inferior to 26192830Sed | supported materials. 27192830Sed | 28192830Sed | This software is not a product of Hewlett-Packard, Co., or any 29192830Sed | other company. No support is implied or offered with this software. 30192830Sed | You've got the source, and you're on your own. 31192830Sed | 32192830Sed | This software may be distributed under the terms of Larry Wall's 33192830Sed | Artistic license, a copy of which is included in this distribution. 34192830Sed | 35192830Sed | This notice must be included with this software and any derivatives. 36192830Sed | 37192830Sed | This editor was purposely developed to be simple, both in 38192830Sed | interface and implementation. This editor was developed to 39192830Sed | address a specific audience: the user who is new to computers 40192830Sed | (especially UNIX). 41192830Sed | 42192830Sed | ee is not aimed at technical users; for that reason more 43192830Sed | complex features were intentionally left out. In addition, 44192830Sed | ee is intended to be compiled by people with little computer 45192830Sed | experience, which means that it needs to be small, relatively 46192830Sed | simple in implementation, and portable. 47192830Sed | 48192830Sed | This software and documentation contains 49192830Sed | proprietary information which is protected by 50192830Sed | copyright. All rights are reserved. 51192830Sed | 52192830Sed | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.96 1998/07/14 05:02:30 hugh Exp $ 53192830Sed | 54192830Sed */ 55192830Sed 56192856Sed#include <sys/cdefs.h> 57192856Sed__FBSDID("$FreeBSD: head/contrib/ee/ee.c 192856 2009-05-26 21:06:51Z ed $"); 58192856Sed 59192830Sedchar *ee_copyright_message = 60192830Sed"Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996 Hugh Mahon "; 61192830Sed 62192830Sedchar *ee_long_notice[] = { 63192830Sed "This software and documentation contains", 64192830Sed "proprietary information which is protected by", 65192830Sed "copyright. All rights are reserved." 66192830Sed }; 67192830Sed 68192830Sedchar *version = "@(#) ee, version 1.4.1 $Revision: 1.96 $"; 69192830Sed 70192830Sed#ifdef NCURSE 71192830Sed#include "new_curse.h" 72192856Sed#elif HAS_NCURSES 73192856Sed#include <ncurses.h> 74192830Sed#else 75192830Sed#include <curses.h> 76192830Sed#endif 77192830Sed 78192856Sed#ifdef HAS_CTYPE 79192856Sed#include <ctype.h> 80192856Sed#endif 81192856Sed#include <err.h> 82192856Sed#include <errno.h> 83192856Sed#include <fcntl.h> 84192856Sed#include <paths.h> 85192856Sed#include <pwd.h> 86192830Sed#include <signal.h> 87192830Sed#include <sys/types.h> 88192830Sed#include <sys/stat.h> 89192830Sed#ifdef HAS_SYS_WAIT 90192830Sed#include <sys/wait.h> 91192830Sed#endif 92192856Sed#ifdef HAS_STDARG 93192856Sed#include <stdarg.h> 94192856Sed#endif 95192830Sed#ifdef HAS_STDLIB 96192830Sed#include <stdlib.h> 97192830Sed#endif 98192856Sed#include <string.h> 99192830Sed#ifdef HAS_UNISTD 100192830Sed#include <unistd.h> 101192830Sed#endif 102192830Sed 103192830Sed#ifndef NO_CATGETS 104192830Sed#include <locale.h> 105192830Sed#include <nl_types.h> 106192830Sed 107192830Sednl_catd catalog; 108192830Sed#else 109192830Sed#define catgetlocal(a, b) (b) 110192830Sed#endif /* NO_CATGETS */ 111192830Sed 112192830Sed#ifndef SIGCHLD 113192830Sed#define SIGCHLD SIGCLD 114192830Sed#endif 115192830Sed 116192830Sed#define TAB 9 117192830Sed#define max(a, b) (a > b ? a : b) 118192830Sed#define min(a, b) (a < b ? a : b) 119192830Sed 120192830Sed/* 121192830Sed | defines for type of data to show in info window 122192830Sed */ 123192830Sed 124192830Sed#define CONTROL_KEYS 1 125192830Sed#define COMMANDS 2 126192830Sed 127192830Sedstruct text { 128192830Sed unsigned char *line; /* line of characters */ 129192830Sed int line_number; /* line number */ 130192830Sed int line_length; /* actual number of characters in the line */ 131192830Sed int max_length; /* maximum number of characters the line handles */ 132192830Sed struct text *next_line; /* next line of text */ 133192830Sed struct text *prev_line; /* previous line of text */ 134192830Sed }; 135192830Sed 136192830Sedstruct text *first_line; /* first line of current buffer */ 137192830Sedstruct text *dlt_line; /* structure for info on deleted line */ 138192830Sedstruct text *curr_line; /* current line cursor is on */ 139192830Sedstruct text *tmp_line; /* temporary line pointer */ 140192830Sedstruct text *srch_line; /* temporary pointer for search routine */ 141192830Sed 142192830Sedstruct files { /* structure to store names of files to be edited*/ 143192830Sed unsigned char *name; /* name of file */ 144192830Sed struct files *next_name; 145192830Sed }; 146192830Sed 147192830Sedstruct files *top_of_stack = NULL; 148192830Sed 149192830Sedint d_wrd_len; /* length of deleted word */ 150192830Sedint position; /* offset in bytes from begin of line */ 151192830Sedint scr_pos; /* horizontal position */ 152192830Sedint scr_vert; /* vertical position on screen */ 153192830Sedint scr_horz; /* horizontal position on screen */ 154192830Sedint tmp_vert, tmp_horz; 155192830Sedint input_file; /* indicate to read input file */ 156192830Sedint recv_file; /* indicate reading a file */ 157192830Sedint edit; /* continue executing while true */ 158192830Sedint gold; /* 'gold' function key pressed */ 159192830Sedint fildes; /* file descriptor */ 160192830Sedint case_sen; /* case sensitive search flag */ 161192830Sedint last_line; /* last line for text display */ 162192830Sedint last_col; /* last column for text display */ 163192830Sedint horiz_offset = 0; /* offset from left edge of text */ 164192830Sedint clear_com_win; /* flag to indicate com_win needs clearing */ 165192830Sedint text_changes = FALSE; /* indicate changes have been made to text */ 166192830Sedint get_fd; /* file descriptor for reading a file */ 167192830Sedint info_window = TRUE; /* flag to indicate if help window visible */ 168192830Sedint info_type = CONTROL_KEYS; /* flag to indicate type of info to display */ 169192830Sedint expand_tabs = TRUE; /* flag for expanding tabs */ 170192830Sedint right_margin = 0; /* the right margin */ 171192830Sedint observ_margins = TRUE; /* flag for whether margins are observed */ 172192830Sedint shell_fork; 173192830Sedint temp_stdin; /* temporary storage for stdin */ 174192830Sedint temp_stdout; /* temp storage for stdout descriptor */ 175192830Sedint temp_stderr; /* temp storage for stderr descriptor */ 176192830Sedint pipe_out[2]; /* pipe file desc for output */ 177192830Sedint pipe_in[2]; /* pipe file descriptors for input */ 178192830Sedint out_pipe; /* flag that info is piped out */ 179192830Sedint in_pipe; /* flag that info is piped in */ 180192830Sedint formatted = FALSE; /* flag indicating paragraph formatted */ 181192830Sedint auto_format = FALSE; /* flag for auto_format mode */ 182192830Sedint restricted = FALSE; /* flag to indicate restricted mode */ 183192830Sedint nohighlight = FALSE; /* turns off highlighting */ 184192830Sedint eightbit = TRUE; /* eight bit character flag */ 185192830Sedint local_LINES = 0; /* copy of LINES, to detect when win resizes */ 186192830Sedint local_COLS = 0; /* copy of COLS, to detect when win resizes */ 187192830Sedint curses_initialized = FALSE; /* flag indicating if curses has been started*/ 188192830Sedint emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */ 189192830Sedint ee_chinese = FALSE; /* allows handling of multi-byte characters */ 190192830Sed /* by checking for high bit in a byte the */ 191192830Sed /* code recognizes a two-byte character */ 192192830Sed /* sequence */ 193192830Sed 194192830Sedunsigned char *point; /* points to current position in line */ 195192830Sedunsigned char *srch_str; /* pointer for search string */ 196192830Sedunsigned char *u_srch_str; /* pointer to non-case sensitive search */ 197192830Sedunsigned char *srch_1; /* pointer to start of suspect string */ 198192830Sedunsigned char *srch_2; /* pointer to next character of string */ 199192830Sedunsigned char *srch_3; 200192830Sedunsigned char *in_file_name = NULL; /* name of input file */ 201192830Sedchar *tmp_file; /* temporary file name */ 202192830Sedunsigned char *d_char; /* deleted character */ 203192830Sedunsigned char *d_word; /* deleted word */ 204192830Sedunsigned char *d_line; /* deleted line */ 205192830Sedchar in_string[513]; /* buffer for reading a file */ 206192856Sedunsigned char *print_command = "lpr"; /* string to use for the print command */ 207192830Sedunsigned char *start_at_line = NULL; /* move to this line at start of session*/ 208192856Sedconst char count_text_default[] = "==============================================================================="; 209192856Sedint count_text_len = sizeof(count_text_default); /* length of the line above */ 210192856Sedchar count_text[sizeof(count_text_default)]; /* buffer for current position display */ 211192830Sedint in; /* input character */ 212192830Sed 213192830SedFILE *temp_fp; /* temporary file pointer */ 214192830SedFILE *bit_bucket; /* file pointer to /dev/null */ 215192830Sed 216192830Sedchar *table[] = { 217192830Sed "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J", 218192830Sed "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", 219192830Sed "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_" 220192830Sed }; 221192830Sed 222192830SedWINDOW *com_win; 223192830SedWINDOW *text_win; 224192830SedWINDOW *help_win; 225192830SedWINDOW *info_win; 226192856SedWINDOW *count_win; 227192830Sed 228192830Sed#if defined(__STDC__) || defined(__cplusplus) 229192830Sed#define P_(s) s 230192830Sed#else 231192830Sed#define P_(s) () 232192830Sed#endif 233192830Sed 234192830Sed 235192830Sed/* 236192830Sed | The following structure allows menu items to be flexibly declared. 237192830Sed | The first item is the string describing the selection, the second 238192830Sed | is the address of the procedure to call when the item is selected, 239192830Sed | and the third is the argument for the procedure. 240192830Sed | 241192830Sed | For those systems with i18n, the string should be accompanied by a 242192830Sed | catalog number. The 'int *' should be replaced with 'void *' on 243192830Sed | systems with that type. 244192830Sed | 245192830Sed | The first menu item will be the title of the menu, with NULL 246192830Sed | parameters for the procedure and argument, followed by the menu items. 247192830Sed | 248192830Sed | If the procedure value is NULL, the menu item is displayed, but no 249192830Sed | procedure is called when the item is selected. The number of the 250192830Sed | item will be returned. If the third (argument) parameter is -1, no 251192830Sed | argument is given to the procedure when it is called. 252192830Sed */ 253192830Sed 254192830Sedstruct menu_entries { 255192830Sed char *item_string; 256192830Sed int (*procedure)P_((struct menu_entries *)); 257192830Sed struct menu_entries *ptr_argument; 258192830Sed int (*iprocedure)P_((int)); 259192830Sed void (*nprocedure)P_((void)); 260192830Sed int argument; 261192830Sed }; 262192830Sed 263192830Sedint main P_((int argc, char *argv[])); 264192830Sedunsigned char *resiz_line P_((int factor, struct text *rline, int rpos)); 265192830Sedvoid insert P_((int character)); 266192830Sedvoid delete P_((int disp)); 267192830Sedvoid scanline P_((unsigned char *pos)); 268192830Sedint tabshift P_((int temp_int)); 269192830Sedint out_char P_((WINDOW *window, int character, int column)); 270192830Sedint len_char P_((int character, int column)); 271192830Sedvoid draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length)); 272192830Sedvoid insert_line P_((int disp)); 273192830Sedstruct text *txtalloc P_((void)); 274192830Sedstruct files *name_alloc P_((void)); 275192830Sedunsigned char *next_word P_((unsigned char *string)); 276192830Sedvoid prev_word P_((void)); 277192830Sedvoid control P_((void)); 278192830Sedvoid emacs_control P_((void)); 279192830Sedvoid bottom P_((void)); 280192830Sedvoid top P_((void)); 281192830Sedvoid nextline P_((void)); 282192830Sedvoid prevline P_((void)); 283192830Sedvoid left P_((int disp)); 284192830Sedvoid right P_((int disp)); 285192830Sedvoid find_pos P_((void)); 286192830Sedvoid up P_((void)); 287192830Sedvoid down P_((void)); 288192830Sedvoid function_key P_((void)); 289192830Sedvoid print_buffer P_((void)); 290192830Sedvoid command_prompt P_((void)); 291192830Sedvoid command P_((char *cmd_str1)); 292192830Sedint scan P_((char *line, int offset, int column)); 293192830Sedchar *get_string P_((char *prompt, int advance)); 294192830Sedint compare P_((char *string1, char *string2, int sensitive)); 295192830Sedvoid goto_line P_((char *cmd_str)); 296192830Sedvoid midscreen P_((int line, unsigned char *pnt)); 297192830Sedvoid get_options P_((int numargs, char *arguments[])); 298192830Sedvoid check_fp P_((void)); 299192830Sedvoid get_file P_((char *file_name)); 300192830Sedvoid get_line P_((int length, unsigned char *in_string, int *append)); 301192830Sedvoid draw_screen P_((void)); 302192830Sedvoid finish P_((void)); 303192830Sedint quit P_((int noverify)); 304192830Sedvoid edit_abort P_((int arg)); 305192830Sedvoid delete_text P_((void)); 306192856Sedint write_file P_((char *file_name, int warn_if_exists)); 307192830Sedint search P_((int display_message)); 308192830Sedvoid search_prompt P_((void)); 309192830Sedvoid del_char P_((void)); 310192830Sedvoid undel_char P_((void)); 311192830Sedvoid del_word P_((void)); 312192830Sedvoid undel_word P_((void)); 313192830Sedvoid del_line P_((void)); 314192830Sedvoid undel_line P_((void)); 315192830Sedvoid adv_word P_((void)); 316192830Sedvoid move_rel P_((char *direction, int lines)); 317192830Sedvoid eol P_((void)); 318192830Sedvoid bol P_((void)); 319192830Sedvoid adv_line P_((void)); 320192830Sedvoid sh_command P_((char *string)); 321192830Sedvoid set_up_term P_((void)); 322192830Sedvoid resize_check P_((void)); 323192830Sedint menu_op P_((struct menu_entries *)); 324192830Sedvoid paint_menu P_((struct menu_entries menu_list[], int max_width, int max_height, int list_size, int top_offset, WINDOW *menu_win, int off_start, int vert_size)); 325192830Sedvoid help P_((void)); 326192830Sedvoid paint_info_win P_((void)); 327192830Sedvoid no_info_window P_((void)); 328192830Sedvoid create_info_window P_((void)); 329192830Sedint file_op P_((int arg)); 330192830Sedvoid shell_op P_((void)); 331192830Sedvoid leave_op P_((void)); 332192830Sedvoid redraw P_((void)); 333192830Sedint Blank_Line P_((struct text *test_line)); 334192830Sedvoid Format P_((void)); 335192830Sedvoid ee_init P_((void)); 336192830Sedvoid dump_ee_conf P_((void)); 337192830Sedvoid echo_string P_((char *string)); 338192830Sedvoid spell_op P_((void)); 339192830Sedvoid ispell_op P_((void)); 340192830Sedint first_word_len P_((struct text *test_line)); 341192830Sedvoid Auto_Format P_((void)); 342192830Sedvoid modes_op P_((void)); 343192830Sedchar *is_in_string P_((char *string, char *substring)); 344192830Sedchar *resolve_name P_((char *name)); 345192830Sedint restrict_mode P_((void)); 346192830Sedint unique_test P_((char *string, char *list[])); 347192856Sedvoid renumber_lines P_((struct text *firstline, int startnumber)); 348192830Sedvoid strings_init P_((void)); 349192830Sed 350192830Sed#undef P_ 351192830Sed/* 352192830Sed | allocate space here for the strings that will be in the menu 353192830Sed */ 354192830Sed 355192830Sedstruct menu_entries modes_menu[] = { 356192830Sed {"", NULL, NULL, NULL, NULL, 0}, /* title */ 357192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */ 358192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/ 359192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */ 360192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */ 361192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/ 362192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */ 363192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/ 364192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */ 365192830Sed {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */ 366192830Sed {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */ 367192830Sed {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */ 368192830Sed }; 369192830Sed 370192830Sedchar *mode_strings[11]; 371192830Sed 372192830Sed#define NUM_MODES_ITEMS 10 373192830Sed 374192830Sedstruct menu_entries config_dump_menu[] = { 375192830Sed {"", NULL, NULL, NULL, NULL, 0}, 376192830Sed {"", NULL, NULL, NULL, NULL, -1}, 377192830Sed {"", NULL, NULL, NULL, NULL, -1}, 378192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 379192830Sed }; 380192830Sed 381192830Sedstruct menu_entries leave_menu[] = { 382192830Sed {"", NULL, NULL, NULL, NULL, -1}, 383192830Sed {"", NULL, NULL, NULL, finish, -1}, 384192830Sed {"", NULL, NULL, quit, NULL, TRUE}, 385192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 386192830Sed }; 387192830Sed 388192830Sed#define READ_FILE 1 389192830Sed#define WRITE_FILE 2 390192830Sed#define SAVE_FILE 3 391192830Sed 392192830Sedstruct menu_entries file_menu[] = { 393192830Sed {"", NULL, NULL, NULL, NULL, -1}, 394192830Sed {"", NULL, NULL, file_op, NULL, READ_FILE}, 395192830Sed {"", NULL, NULL, file_op, NULL, WRITE_FILE}, 396192830Sed {"", NULL, NULL, file_op, NULL, SAVE_FILE}, 397192830Sed {"", NULL, NULL, NULL, print_buffer, -1}, 398192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 399192830Sed }; 400192830Sed 401192830Sedstruct menu_entries search_menu[] = { 402192830Sed {"", NULL, NULL, NULL, NULL, 0}, 403192830Sed {"", NULL, NULL, NULL, search_prompt, -1}, 404192830Sed {"", NULL, NULL, search, NULL, TRUE}, 405192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 406192830Sed }; 407192830Sed 408192830Sedstruct menu_entries spell_menu[] = { 409192830Sed {"", NULL, NULL, NULL, NULL, -1}, 410192830Sed {"", NULL, NULL, NULL, spell_op, -1}, 411192830Sed {"", NULL, NULL, NULL, ispell_op, -1}, 412192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 413192830Sed }; 414192830Sed 415192830Sedstruct menu_entries misc_menu[] = { 416192830Sed {"", NULL, NULL, NULL, NULL, -1}, 417192830Sed {"", NULL, NULL, NULL, Format, -1}, 418192830Sed {"", NULL, NULL, NULL, shell_op, -1}, 419192830Sed {"", menu_op, spell_menu, NULL, NULL, -1}, 420192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 421192830Sed }; 422192830Sed 423192830Sedstruct menu_entries main_menu[] = { 424192830Sed {"", NULL, NULL, NULL, NULL, -1}, 425192830Sed {"", NULL, NULL, NULL, leave_op, -1}, 426192830Sed {"", NULL, NULL, NULL, help, -1}, 427192830Sed {"", menu_op, file_menu, NULL, NULL, -1}, 428192830Sed {"", NULL, NULL, NULL, redraw, -1}, 429192830Sed {"", NULL, NULL, NULL, modes_op, -1}, 430192830Sed {"", menu_op, search_menu, NULL, NULL, -1}, 431192830Sed {"", menu_op, misc_menu, NULL, NULL, -1}, 432192830Sed {NULL, NULL, NULL, NULL, NULL, -1} 433192830Sed }; 434192830Sed 435192830Sedchar *help_text[23]; 436192830Sedchar *control_keys[5]; 437192830Sed 438192830Sedchar *emacs_help_text[22]; 439192830Sedchar *emacs_control_keys[5]; 440192830Sed 441192830Sedchar *command_strings[5]; 442192830Sedchar *commands[32]; 443192830Sedchar *init_strings[22]; 444192830Sed 445192830Sed#define MENU_WARN 1 446192830Sed 447192830Sed#define max_alpha_char 36 448192830Sed 449192830Sed/* 450192830Sed | Declarations for strings for localization 451192830Sed */ 452192830Sed 453192830Sedchar *com_win_message; /* to be shown in com_win if no info window */ 454192830Sedchar *no_file_string; 455192830Sedchar *ascii_code_str; 456192830Sedchar *printer_msg_str; 457192830Sedchar *command_str; 458192830Sedchar *file_write_prompt_str; 459192830Sedchar *file_read_prompt_str; 460192830Sedchar *char_str; 461192830Sedchar *unkn_cmd_str; 462192830Sedchar *non_unique_cmd_msg; 463192830Sedchar *line_num_str; 464192830Sedchar *line_len_str; 465192830Sedchar *current_file_str; 466192830Sedchar *usage0; 467192830Sedchar *usage1; 468192830Sedchar *usage2; 469192830Sedchar *usage3; 470192830Sedchar *usage4; 471192830Sedchar *file_is_dir_msg; 472192830Sedchar *new_file_msg; 473192830Sedchar *cant_open_msg; 474192830Sedchar *open_file_msg; 475192830Sedchar *file_read_fin_msg; 476192830Sedchar *reading_file_msg; 477192830Sedchar *read_only_msg; 478192830Sedchar *file_read_lines_msg; 479192830Sedchar *save_file_name_prompt; 480192830Sedchar *file_not_saved_msg; 481192830Sedchar *changes_made_prompt; 482192830Sedchar *yes_char; 483192830Sedchar *file_exists_prompt; 484192830Sedchar *create_file_fail_msg; 485192830Sedchar *writing_file_msg; 486192830Sedchar *file_written_msg; 487192830Sedchar *searching_msg; 488192830Sedchar *str_not_found_msg; 489192830Sedchar *search_prompt_str; 490192830Sedchar *exec_err_msg; 491192830Sedchar *continue_msg; 492192830Sedchar *menu_cancel_msg; 493192830Sedchar *menu_size_err_msg; 494192830Sedchar *press_any_key_msg; 495192830Sedchar *shell_prompt; 496192830Sedchar *formatting_msg; 497192830Sedchar *shell_echo_msg; 498192830Sedchar *spell_in_prog_msg; 499192830Sedchar *margin_prompt; 500192830Sedchar *restricted_msg; 501192830Sedchar *ON; 502192830Sedchar *OFF; 503192830Sedchar *HELP; 504192830Sedchar *WRITE; 505192830Sedchar *READ; 506192830Sedchar *LINE; 507192830Sedchar *FILE_str; 508192830Sedchar *CHARACTER; 509192830Sedchar *REDRAW; 510192830Sedchar *RESEQUENCE; 511192830Sedchar *AUTHOR; 512192830Sedchar *VERSION; 513192830Sedchar *CASE; 514192830Sedchar *NOCASE; 515192830Sedchar *EXPAND; 516192830Sedchar *NOEXPAND; 517192830Sedchar *Exit_string; 518192830Sedchar *QUIT_string; 519192830Sedchar *INFO; 520192830Sedchar *NOINFO; 521192830Sedchar *MARGINS; 522192830Sedchar *NOMARGINS; 523192830Sedchar *AUTOFORMAT; 524192830Sedchar *NOAUTOFORMAT; 525192830Sedchar *Echo; 526192830Sedchar *PRINTCOMMAND; 527192830Sedchar *RIGHTMARGIN; 528192830Sedchar *HIGHLIGHT; 529192830Sedchar *NOHIGHLIGHT; 530192830Sedchar *EIGHTBIT; 531192830Sedchar *NOEIGHTBIT; 532192830Sedchar *EMACS_string; 533192830Sedchar *NOEMACS_string; 534192830Sedchar *conf_dump_err_msg; 535192830Sedchar *conf_dump_success_msg; 536192830Sedchar *conf_not_saved_msg; 537192830Sedchar *ree_no_file_msg; 538192830Sedchar *cancel_string; 539192830Sedchar *menu_too_lrg_msg; 540192830Sedchar *more_above_str, *more_below_str; 541192830Sed 542192830Sedchar *chinese_cmd, *nochinese_cmd; 543192830Sed 544192830Sed 545192830Sedint 546192830Sedmain(argc, argv) /* beginning of main program */ 547192830Sedint argc; 548192830Sedchar *argv[]; 549192830Sed{ 550192856Sed /* Always read from (and write to) a terminal. */ 551192856Sed if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) { 552192856Sed fprintf(stderr, "ee's standard input and output must be a terminal\n"); 553192856Sed exit(1); 554192856Sed } 555192830Sed 556192830Sed signal(SIGCHLD, SIG_DFL); 557192830Sed signal(SIGSEGV, SIG_DFL); 558192830Sed signal(SIGINT, edit_abort); 559192856Sed signal(SIGHUP, edit_abort); 560192856Sed 561192830Sed d_char = malloc(3); /* provide a buffer for multi-byte chars */ 562192830Sed d_word = malloc(150); 563192830Sed *d_word = (char) NULL; 564192830Sed d_line = NULL; 565192830Sed dlt_line = txtalloc(); 566192830Sed dlt_line->line = d_line; 567192830Sed dlt_line->line_length = 0; 568192830Sed curr_line = first_line = txtalloc(); 569192830Sed curr_line->line = point = malloc(10); 570192830Sed curr_line->line_length = 1; 571192830Sed curr_line->max_length = 10; 572192830Sed curr_line->prev_line = NULL; 573192830Sed curr_line->next_line = NULL; 574192830Sed curr_line->line_number = 1; 575192830Sed srch_str = NULL; 576192830Sed u_srch_str = NULL; 577192830Sed position = 1; 578192830Sed scr_pos =0; 579192830Sed scr_vert = 0; 580192830Sed scr_horz = 0; 581192856Sed bit_bucket = fopen(_PATH_DEVNULL, "w"); 582192830Sed edit = TRUE; 583192830Sed gold = case_sen = FALSE; 584192830Sed shell_fork = TRUE; 585192830Sed strings_init(); 586192830Sed ee_init(); 587192830Sed if (argc > 0 ) 588192830Sed get_options(argc, argv); 589192830Sed set_up_term(); 590192830Sed if (right_margin == 0) 591192830Sed right_margin = COLS - 1; 592192830Sed if (top_of_stack == NULL) 593192830Sed { 594192830Sed if (restrict_mode()) 595192830Sed { 596192830Sed wmove(com_win, 0, 0); 597192830Sed werase(com_win); 598192830Sed wprintw(com_win, ree_no_file_msg); 599192830Sed wrefresh(com_win); 600192830Sed edit_abort(0); 601192830Sed } 602192830Sed wprintw(com_win, no_file_string); 603192830Sed wrefresh(com_win); 604192830Sed } 605192830Sed else 606192830Sed check_fp(); 607192830Sed 608192830Sed clear_com_win = TRUE; 609192830Sed 610192830Sed while(edit) 611192830Sed { 612192856Sed if (info_window) 613192856Sed { 614192856Sed snprintf(count_text, count_text_len, "L: %d C: %d %s", \ 615192856Sed curr_line->line_number, scr_horz + 1, count_text_default); 616192856Sed wmove(count_win, 0, 0); 617192856Sed if (!nohighlight) 618192856Sed wstandout(count_win); 619192856Sed wprintw(count_win, count_text); 620192856Sed wstandend(count_win); 621192856Sed wnoutrefresh(count_win); 622192856Sed } 623192856Sed 624192856Sed wnoutrefresh(text_win); 625192856Sed doupdate(); 626192830Sed in = wgetch(text_win); 627192830Sed if (in == -1) 628192856Sed continue; 629192830Sed 630192830Sed resize_check(); 631192830Sed 632192830Sed if (clear_com_win) 633192830Sed { 634192830Sed clear_com_win = FALSE; 635192830Sed wmove(com_win, 0, 0); 636192830Sed werase(com_win); 637192830Sed if (!info_window) 638192830Sed { 639192830Sed wprintw(com_win, "%s", com_win_message); 640192830Sed } 641192830Sed wrefresh(com_win); 642192830Sed } 643192830Sed 644192830Sed if (in > 255) 645192830Sed function_key(); 646192830Sed else if ((in == '\10') || (in == 127)) 647192830Sed { 648192830Sed in = 8; /* make sure key is set to backspace */ 649192830Sed delete(TRUE); 650192830Sed } 651192830Sed else if ((in > 31) || (in == 9)) 652192830Sed insert(in); 653192830Sed else if ((in >= 0) && (in <= 31)) 654192830Sed { 655192830Sed if (emacs_keys_mode) 656192830Sed emacs_control(); 657192830Sed else 658192830Sed control(); 659192830Sed } 660192830Sed } 661192830Sed return(0); 662192830Sed} 663192830Sed 664192830Sedunsigned char * 665192830Sedresiz_line(factor, rline, rpos) /* resize the line to length + factor*/ 666192830Sedint factor; /* resize factor */ 667192830Sedstruct text *rline; /* position in line */ 668192830Sedint rpos; 669192830Sed{ 670192830Sed unsigned char *rpoint; 671192830Sed int resiz_var; 672192830Sed 673192830Sed rline->max_length += factor; 674192830Sed rpoint = rline->line = realloc(rline->line, rline->max_length ); 675192830Sed for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++) 676192830Sed rpoint++; 677192830Sed return(rpoint); 678192830Sed} 679192830Sed 680192830Sedvoid 681192830Sedinsert(character) /* insert character into line */ 682192830Sedint character; /* new character */ 683192830Sed{ 684192830Sed int counter; 685192830Sed int value; 686192830Sed unsigned char *temp; /* temporary pointer */ 687192830Sed unsigned char *temp2; /* temporary pointer */ 688192830Sed 689192830Sed if ((character == '\011') && (expand_tabs)) 690192830Sed { 691192830Sed counter = len_char('\011', scr_horz); 692192830Sed for (; counter > 0; counter--) 693192830Sed insert(' '); 694192830Sed if (auto_format) 695192830Sed Auto_Format(); 696192830Sed return; 697192830Sed } 698192830Sed text_changes = TRUE; 699192830Sed if ((curr_line->max_length - curr_line->line_length) < 5) 700192830Sed point = resiz_line(10, curr_line, position); 701192830Sed curr_line->line_length++; 702192830Sed temp = point; 703192830Sed counter = position; 704192830Sed while (counter < curr_line->line_length) /* find end of line */ 705192830Sed { 706192830Sed counter++; 707192830Sed temp++; 708192830Sed } 709192830Sed temp++; /* increase length of line by one */ 710192830Sed while (point < temp) 711192830Sed { 712192830Sed temp2=temp - 1; 713192830Sed *temp= *temp2; /* shift characters over by one */ 714192830Sed temp--; 715192830Sed } 716192830Sed *point = character; /* insert new character */ 717192830Sed wclrtoeol(text_win); 718192830Sed if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/ 719192830Sed { 720192830Sed scr_pos = scr_horz += out_char(text_win, character, scr_horz); 721192830Sed point++; 722192830Sed position++; 723192830Sed } 724192830Sed else 725192830Sed { 726192830Sed waddch(text_win, character); 727192830Sed scr_pos = ++scr_horz; 728192830Sed point++; 729192830Sed position ++; 730192830Sed } 731192830Sed 732192830Sed if ((observ_margins) && (right_margin < scr_pos)) 733192830Sed { 734192830Sed counter = position; 735192830Sed while (scr_pos > right_margin) 736192830Sed prev_word(); 737192830Sed if (scr_pos == 0) 738192830Sed { 739192830Sed while (position < counter) 740192830Sed right(TRUE); 741192830Sed } 742192830Sed else 743192830Sed { 744192830Sed counter -= position; 745192830Sed insert_line(TRUE); 746192830Sed for (value = 0; value < counter; value++) 747192830Sed right(TRUE); 748192830Sed } 749192830Sed } 750192830Sed 751192830Sed if ((scr_horz - horiz_offset) > last_col) 752192830Sed { 753192830Sed horiz_offset += 8; 754192830Sed midscreen(scr_vert, point); 755192830Sed } 756192830Sed 757192830Sed if ((auto_format) && (character == ' ') && (!formatted)) 758192830Sed Auto_Format(); 759192830Sed else if ((character != ' ') && (character != '\t')) 760192830Sed formatted = FALSE; 761192830Sed 762192830Sed draw_line(scr_vert, scr_horz, point, position, curr_line->line_length); 763192830Sed} 764192830Sed 765192830Sedvoid 766192830Seddelete(disp) /* delete character */ 767192830Sedint disp; 768192830Sed{ 769192830Sed unsigned char *tp; 770192830Sed unsigned char *temp2; 771192830Sed struct text *temp_buff; 772192830Sed int temp_vert; 773192830Sed int temp_pos; 774192830Sed int del_width = 1; 775192830Sed 776192830Sed if (point != curr_line->line) /* if not at beginning of line */ 777192830Sed { 778192830Sed text_changes = TRUE; 779192830Sed temp2 = tp = point; 780192830Sed if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127)) 781192830Sed { 782192830Sed del_width = 2; 783192830Sed } 784192830Sed tp -= del_width; 785192830Sed point -= del_width; 786192830Sed position -= del_width; 787192830Sed temp_pos = position; 788192830Sed curr_line->line_length -= del_width; 789192830Sed if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */ 790192830Sed scanline(tp); 791192830Sed else 792192830Sed scr_horz -= del_width; 793192830Sed scr_pos = scr_horz; 794192830Sed if (in == 8) 795192830Sed { 796192830Sed if (del_width == 1) 797192830Sed *d_char = *point; /* save deleted character */ 798192830Sed else 799192830Sed { 800192830Sed d_char[0] = *point; 801192830Sed d_char[1] = *(point + 1); 802192830Sed } 803192830Sed d_char[del_width] = (unsigned char) NULL; 804192830Sed } 805192830Sed while (temp_pos <= curr_line->line_length) 806192830Sed { 807192830Sed temp_pos++; 808192830Sed *tp = *temp2; 809192830Sed tp++; 810192830Sed temp2++; 811192830Sed } 812192830Sed if (scr_horz < horiz_offset) 813192830Sed { 814192830Sed horiz_offset -= 8; 815192830Sed midscreen(scr_vert, point); 816192830Sed } 817192830Sed } 818192830Sed else if (curr_line->prev_line != NULL) 819192830Sed { 820192830Sed text_changes = TRUE; 821192830Sed left(disp); /* go to previous line */ 822192830Sed temp_buff = curr_line->next_line; 823192830Sed point = resiz_line(temp_buff->line_length, curr_line, position); 824192830Sed if (temp_buff->next_line != NULL) 825192830Sed temp_buff->next_line->prev_line = curr_line; 826192830Sed curr_line->next_line = temp_buff->next_line; 827192856Sed renumber_lines(curr_line->next_line, curr_line->line_number + 1); 828192830Sed temp2 = temp_buff->line; 829192830Sed if (in == 8) 830192830Sed { 831192830Sed d_char[0] = '\n'; 832192830Sed d_char[1] = (unsigned char) NULL; 833192830Sed } 834192830Sed tp = point; 835192830Sed temp_pos = 1; 836192830Sed while (temp_pos < temp_buff->line_length) 837192830Sed { 838192830Sed curr_line->line_length++; 839192830Sed temp_pos++; 840192830Sed *tp = *temp2; 841192830Sed tp++; 842192830Sed temp2++; 843192830Sed } 844192830Sed *tp = (char) NULL; 845192830Sed free(temp_buff->line); 846192830Sed free(temp_buff); 847192830Sed temp_buff = curr_line; 848192830Sed temp_vert = scr_vert; 849192830Sed scr_pos = scr_horz; 850192830Sed if (scr_vert < last_line) 851192830Sed { 852192830Sed wmove(text_win, scr_vert + 1, 0); 853192830Sed wdeleteln(text_win); 854192830Sed } 855192830Sed while ((temp_buff != NULL) && (temp_vert < last_line)) 856192830Sed { 857192830Sed temp_buff = temp_buff->next_line; 858192830Sed temp_vert++; 859192830Sed } 860192830Sed if ((temp_vert == last_line) && (temp_buff != NULL)) 861192830Sed { 862192830Sed tp = temp_buff->line; 863192830Sed wmove(text_win, last_line,0); 864192830Sed wclrtobot(text_win); 865192830Sed draw_line(last_line, 0, tp, 1, temp_buff->line_length); 866192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 867192830Sed } 868192830Sed } 869192830Sed draw_line(scr_vert, scr_horz, point, position, curr_line->line_length); 870192830Sed formatted = FALSE; 871192830Sed} 872192830Sed 873192830Sedvoid 874192830Sedscanline(pos) /* find the proper horizontal position for the pointer */ 875192830Sedunsigned char *pos; 876192830Sed{ 877192830Sed int temp; 878192830Sed unsigned char *ptr; 879192830Sed 880192830Sed ptr = curr_line->line; 881192830Sed temp = 0; 882192830Sed while (ptr < pos) 883192830Sed { 884192830Sed if (*ptr <= 8) 885192830Sed temp += 2; 886192830Sed else if (*ptr == 9) 887192830Sed temp += tabshift(temp); 888192830Sed else if ((*ptr >= 10) && (*ptr <= 31)) 889192830Sed temp += 2; 890192830Sed else if ((*ptr >= 32) && (*ptr < 127)) 891192830Sed temp++; 892192830Sed else if (*ptr == 127) 893192830Sed temp += 2; 894192830Sed else if (!eightbit) 895192830Sed temp += 5; 896192830Sed else 897192830Sed temp++; 898192830Sed ptr++; 899192830Sed } 900192830Sed scr_horz = temp; 901192830Sed if ((scr_horz - horiz_offset) > last_col) 902192830Sed { 903192830Sed horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8); 904192830Sed midscreen(scr_vert, point); 905192830Sed } 906192830Sed else if (scr_horz < horiz_offset) 907192830Sed { 908192830Sed horiz_offset = max(0, (scr_horz - (scr_horz % 8))); 909192830Sed midscreen(scr_vert, point); 910192830Sed } 911192830Sed} 912192830Sed 913192830Sedint 914192830Sedtabshift(temp_int) /* give the number of spaces to shift */ 915192830Sedint temp_int; 916192830Sed{ 917192830Sed int leftover; 918192830Sed 919192830Sed leftover = ((temp_int + 1) % 8); 920192830Sed if (leftover == 0) 921192830Sed return (1); 922192830Sed else 923192830Sed return (9 - leftover); 924192830Sed} 925192830Sed 926192830Sedint 927192830Sedout_char(window, character, column) /* output non-printing character */ 928192830SedWINDOW *window; 929192830Sedchar character; 930192830Sedint column; 931192830Sed{ 932192830Sed int i1, i2; 933192830Sed unsigned char *string; 934192830Sed char string2[8]; 935192830Sed 936192830Sed if (character == TAB) 937192830Sed { 938192830Sed i1 = tabshift(column); 939192830Sed for (i2 = 0; 940192830Sed (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++) 941192830Sed { 942192830Sed waddch(window, ' '); 943192830Sed } 944192830Sed return(i1); 945192830Sed } 946192830Sed else if ((character >= '\0') && (character < ' ')) 947192830Sed { 948192830Sed string = table[(int) character]; 949192830Sed } 950192830Sed else if ((character < 0) || (character >= 127)) 951192830Sed { 952192830Sed if (character == 127) 953192830Sed string = "^?"; 954192830Sed else if (!eightbit) 955192830Sed { 956192830Sed sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character); 957192830Sed string = string2; 958192830Sed } 959192830Sed else 960192830Sed { 961192856Sed waddch(window, (unsigned char)character ); 962192830Sed return(1); 963192830Sed } 964192830Sed } 965192830Sed else 966192830Sed { 967192856Sed waddch(window, (unsigned char)character); 968192830Sed return(1); 969192830Sed } 970192830Sed for (i2 = 0; (string[i2] != (char) NULL) && (((column+i2+1)-horiz_offset) < last_col); i2++) 971192830Sed waddch(window, string[i2]); 972192830Sed return(strlen(string)); 973192830Sed} 974192830Sed 975192830Sedint 976192830Sedlen_char(character, column) /* return the length of the character */ 977192830Sedchar character; 978192830Sedint column; /* the column must be known to provide spacing for tabs */ 979192830Sed{ 980192830Sed int length; 981192830Sed 982192830Sed if (character == '\t') 983192830Sed length = tabshift(column); 984192830Sed else if ((character >= 0) && (character < 32)) 985192830Sed length = 2; 986192830Sed else if ((character >= 32) && (character <= 126)) 987192830Sed length = 1; 988192830Sed else if (character == 127) 989192830Sed length = 2; 990192830Sed else if (((character > 126) || (character < 0)) && (!eightbit)) 991192830Sed length = 5; 992192830Sed else 993192830Sed length = 1; 994192830Sed 995192830Sed return(length); 996192830Sed} 997192830Sed 998192830Sedvoid 999192830Seddraw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */ 1000192830Sedint vertical; /* current vertical position on screen */ 1001192830Sedint horiz; /* current horizontal position on screen */ 1002192830Sedunsigned char *ptr; /* pointer to line */ 1003192830Sedint t_pos; /* current position (offset in bytes) from bol */ 1004192830Sedint length; /* length (in bytes) of line */ 1005192830Sed{ 1006192830Sed int d; /* partial length of special or tab char to display */ 1007192830Sed unsigned char *temp; /* temporary pointer to position in line */ 1008192830Sed int abs_column; /* offset in screen units from begin of line */ 1009192830Sed int column; /* horizontal position on screen */ 1010192830Sed int row; /* vertical position on screen */ 1011192830Sed int posit; /* temporary position indicator within line */ 1012192830Sed 1013192830Sed abs_column = horiz; 1014192830Sed column = horiz - horiz_offset; 1015192830Sed row = vertical; 1016192830Sed temp = ptr; 1017192830Sed d = 0; 1018192830Sed posit = t_pos; 1019192830Sed if (column < 0) 1020192830Sed { 1021192830Sed wmove(text_win, row, 0); 1022192830Sed wclrtoeol(text_win); 1023192830Sed } 1024192830Sed while (column < 0) 1025192830Sed { 1026192830Sed d = len_char(*temp, abs_column); 1027192830Sed abs_column += d; 1028192830Sed column += d; 1029192830Sed posit++; 1030192830Sed temp++; 1031192830Sed } 1032192830Sed wmove(text_win, row, column); 1033192830Sed wclrtoeol(text_win); 1034192830Sed while ((posit < length) && (column <= last_col)) 1035192830Sed { 1036192830Sed if ((*temp < 32) || (*temp >= 127)) 1037192830Sed { 1038192830Sed column += len_char(*temp, abs_column); 1039192830Sed abs_column += out_char(text_win, *temp, abs_column); 1040192830Sed } 1041192830Sed else 1042192830Sed { 1043192830Sed abs_column++; 1044192830Sed column++; 1045192830Sed waddch(text_win, *temp); 1046192830Sed } 1047192830Sed posit++; 1048192830Sed temp++; 1049192830Sed } 1050192830Sed if (column < last_col) 1051192830Sed wclrtoeol(text_win); 1052192830Sed wmove(text_win, vertical, (horiz - horiz_offset)); 1053192830Sed} 1054192830Sed 1055192830Sedvoid 1056192830Sedinsert_line(disp) /* insert new line */ 1057192830Sedint disp; 1058192830Sed{ 1059192830Sed int temp_pos; 1060192830Sed int temp_pos2; 1061192830Sed unsigned char *temp; 1062192830Sed unsigned char *extra; 1063192830Sed struct text *temp_nod; 1064192830Sed 1065192830Sed text_changes = TRUE; 1066192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1067192830Sed wclrtoeol(text_win); 1068192830Sed temp_nod= txtalloc(); 1069192830Sed temp_nod->line = extra= malloc(10); 1070192830Sed temp_nod->line_length = 1; 1071192830Sed temp_nod->max_length = 10; 1072192830Sed temp_nod->next_line = curr_line->next_line; 1073192856Sed renumber_lines(temp_nod, curr_line->line_number + 1); 1074192830Sed if (temp_nod->next_line != NULL) 1075192830Sed temp_nod->next_line->prev_line = temp_nod; 1076192830Sed temp_nod->prev_line = curr_line; 1077192830Sed curr_line->next_line = temp_nod; 1078192830Sed temp_pos2 = position; 1079192830Sed temp = point; 1080192830Sed if (temp_pos2 < curr_line->line_length) 1081192830Sed { 1082192830Sed temp_pos = 1; 1083192830Sed while (temp_pos2 < curr_line->line_length) 1084192830Sed { 1085192830Sed if ((temp_nod->max_length - temp_nod->line_length)< 5) 1086192830Sed extra = resiz_line(10, temp_nod, temp_pos); 1087192830Sed temp_nod->line_length++; 1088192830Sed temp_pos++; 1089192830Sed temp_pos2++; 1090192830Sed *extra= *temp; 1091192830Sed extra++; 1092192830Sed temp++; 1093192830Sed } 1094192830Sed temp=point; 1095192830Sed *temp = (char) NULL; 1096192830Sed temp = resiz_line((1 - temp_nod->line_length), curr_line, position); 1097192830Sed curr_line->line_length = 1 + temp - curr_line->line; 1098192830Sed } 1099192830Sed curr_line->line_length = position; 1100192830Sed curr_line = temp_nod; 1101192830Sed *extra = (char) NULL; 1102192830Sed position = 1; 1103192830Sed point= curr_line->line; 1104192830Sed if (disp) 1105192830Sed { 1106192830Sed if (scr_vert < last_line) 1107192830Sed { 1108192830Sed scr_vert++; 1109192830Sed wclrtoeol(text_win); 1110192830Sed wmove(text_win, scr_vert, 0); 1111192830Sed winsertln(text_win); 1112192830Sed } 1113192830Sed else 1114192830Sed { 1115192830Sed wmove(text_win, 0,0); 1116192830Sed wdeleteln(text_win); 1117192830Sed wmove(text_win, last_line,0); 1118192830Sed wclrtobot(text_win); 1119192830Sed } 1120192830Sed scr_pos = scr_horz = 0; 1121192830Sed if (horiz_offset) 1122192830Sed { 1123192830Sed horiz_offset = 0; 1124192830Sed midscreen(scr_vert, point); 1125192830Sed } 1126192830Sed draw_line(scr_vert, scr_horz, point, position, 1127192830Sed curr_line->line_length); 1128192830Sed } 1129192830Sed} 1130192830Sed 1131192830Sedstruct text *txtalloc() /* allocate space for line structure */ 1132192830Sed{ 1133192830Sed return((struct text *) malloc(sizeof( struct text))); 1134192830Sed} 1135192830Sed 1136192830Sedstruct files *name_alloc() /* allocate space for file name list node */ 1137192830Sed{ 1138192830Sed return((struct files *) malloc(sizeof( struct files))); 1139192830Sed} 1140192830Sed 1141192830Sedunsigned char *next_word(string) /* move to next word in string */ 1142192830Sedunsigned char *string; 1143192830Sed{ 1144192830Sed while ((*string != (char) NULL) && ((*string != 32) && (*string != 9))) 1145192830Sed string++; 1146192830Sed while ((*string != (char) NULL) && ((*string == 32) || (*string == 9))) 1147192830Sed string++; 1148192830Sed return(string); 1149192830Sed} 1150192830Sed 1151192830Sedvoid 1152192830Sedprev_word() /* move to start of previous word in text */ 1153192830Sed{ 1154192830Sed if (position != 1) 1155192830Sed { 1156192830Sed if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t'))) 1157192830Sed { /* if at the start of a word */ 1158192830Sed while ((position != 1) && ((*point != ' ') && (*point != '\t'))) 1159192830Sed left(TRUE); 1160192830Sed } 1161192830Sed while ((position != 1) && ((*point == ' ') || (*point == '\t'))) 1162192830Sed left(TRUE); 1163192830Sed while ((position != 1) && ((*point != ' ') && (*point != '\t'))) 1164192830Sed left(TRUE); 1165192830Sed if ((position != 1) && ((*point == ' ') || (*point == '\t'))) 1166192830Sed right(TRUE); 1167192830Sed } 1168192830Sed else 1169192830Sed left(TRUE); 1170192830Sed} 1171192830Sed 1172192830Sedvoid 1173192830Sedcontrol() /* use control for commands */ 1174192830Sed{ 1175192830Sed char *string; 1176192830Sed 1177192830Sed if (in == 1) /* control a */ 1178192830Sed { 1179192830Sed string = get_string(ascii_code_str, TRUE); 1180192830Sed if (*string != (char) NULL) 1181192830Sed { 1182192830Sed in = atoi(string); 1183192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1184192830Sed insert(in); 1185192830Sed } 1186192830Sed free(string); 1187192830Sed } 1188192830Sed else if (in == 2) /* control b */ 1189192830Sed bottom(); 1190192830Sed else if (in == 3) /* control c */ 1191192830Sed { 1192192830Sed command_prompt(); 1193192830Sed } 1194192830Sed else if (in == 4) /* control d */ 1195192830Sed down(); 1196192830Sed else if (in == 5) /* control e */ 1197192830Sed search_prompt(); 1198192830Sed else if (in == 6) /* control f */ 1199192830Sed undel_char(); 1200192830Sed else if (in == 7) /* control g */ 1201192830Sed bol(); 1202192830Sed else if (in == 8) /* control h */ 1203192830Sed delete(TRUE); 1204192830Sed else if (in == 9) /* control i */ 1205192830Sed ; 1206192830Sed else if (in == 10) /* control j */ 1207192830Sed insert_line(TRUE); 1208192830Sed else if (in == 11) /* control k */ 1209192830Sed del_char(); 1210192830Sed else if (in == 12) /* control l */ 1211192830Sed left(TRUE); 1212192830Sed else if (in == 13) /* control m */ 1213192830Sed insert_line(TRUE); 1214192830Sed else if (in == 14) /* control n */ 1215192830Sed move_rel("d", max(5, (last_line - 5))); 1216192830Sed else if (in == 15) /* control o */ 1217192830Sed eol(); 1218192830Sed else if (in == 16) /* control p */ 1219192830Sed move_rel("u", max(5, (last_line - 5))); 1220192830Sed else if (in == 17) /* control q */ 1221192830Sed ; 1222192830Sed else if (in == 18) /* control r */ 1223192830Sed right(TRUE); 1224192830Sed else if (in == 19) /* control s */ 1225192830Sed ; 1226192830Sed else if (in == 20) /* control t */ 1227192830Sed top(); 1228192830Sed else if (in == 21) /* control u */ 1229192830Sed up(); 1230192830Sed else if (in == 22) /* control v */ 1231192830Sed undel_word(); 1232192830Sed else if (in == 23) /* control w */ 1233192830Sed del_word(); 1234192830Sed else if (in == 24) /* control x */ 1235192830Sed search(TRUE); 1236192830Sed else if (in == 25) /* control y */ 1237192830Sed del_line(); 1238192830Sed else if (in == 26) /* control z */ 1239192830Sed undel_line(); 1240192830Sed else if (in == 27) /* control [ (escape) */ 1241192830Sed { 1242192830Sed menu_op(main_menu); 1243192830Sed } 1244192830Sed} 1245192830Sed 1246192830Sed/* 1247192830Sed | Emacs control-key bindings 1248192830Sed */ 1249192830Sed 1250192830Sedvoid 1251192830Sedemacs_control() 1252192830Sed{ 1253192830Sed char *string; 1254192830Sed 1255192830Sed if (in == 1) /* control a */ 1256192830Sed bol(); 1257192830Sed else if (in == 2) /* control b */ 1258192830Sed left(TRUE); 1259192830Sed else if (in == 3) /* control c */ 1260192830Sed { 1261192830Sed command_prompt(); 1262192830Sed } 1263192830Sed else if (in == 4) /* control d */ 1264192830Sed del_char(); 1265192830Sed else if (in == 5) /* control e */ 1266192830Sed eol(); 1267192830Sed else if (in == 6) /* control f */ 1268192830Sed right(TRUE); 1269192830Sed else if (in == 7) /* control g */ 1270192830Sed move_rel("u", max(5, (last_line - 5))); 1271192830Sed else if (in == 8) /* control h */ 1272192830Sed delete(TRUE); 1273192830Sed else if (in == 9) /* control i */ 1274192830Sed ; 1275192830Sed else if (in == 10) /* control j */ 1276192830Sed undel_char(); 1277192830Sed else if (in == 11) /* control k */ 1278192830Sed del_line(); 1279192830Sed else if (in == 12) /* control l */ 1280192830Sed undel_line(); 1281192830Sed else if (in == 13) /* control m */ 1282192830Sed insert_line(TRUE); 1283192830Sed else if (in == 14) /* control n */ 1284192830Sed down(); 1285192830Sed else if (in == 15) /* control o */ 1286192830Sed { 1287192830Sed string = get_string(ascii_code_str, TRUE); 1288192830Sed if (*string != (char) NULL) 1289192830Sed { 1290192830Sed in = atoi(string); 1291192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1292192830Sed insert(in); 1293192830Sed } 1294192830Sed free(string); 1295192830Sed } 1296192830Sed else if (in == 16) /* control p */ 1297192830Sed up(); 1298192830Sed else if (in == 17) /* control q */ 1299192830Sed ; 1300192830Sed else if (in == 18) /* control r */ 1301192830Sed undel_word(); 1302192830Sed else if (in == 19) /* control s */ 1303192830Sed ; 1304192830Sed else if (in == 20) /* control t */ 1305192830Sed top(); 1306192830Sed else if (in == 21) /* control u */ 1307192830Sed bottom(); 1308192830Sed else if (in == 22) /* control v */ 1309192830Sed move_rel("d", max(5, (last_line - 5))); 1310192830Sed else if (in == 23) /* control w */ 1311192830Sed del_word(); 1312192830Sed else if (in == 24) /* control x */ 1313192830Sed search(TRUE); 1314192830Sed else if (in == 25) /* control y */ 1315192830Sed search_prompt(); 1316192830Sed else if (in == 26) /* control z */ 1317192830Sed adv_word(); 1318192830Sed else if (in == 27) /* control [ (escape) */ 1319192830Sed { 1320192830Sed menu_op(main_menu); 1321192830Sed } 1322192830Sed} 1323192830Sed 1324192830Sedvoid 1325192830Sedbottom() /* go to bottom of file */ 1326192830Sed{ 1327192830Sed while (curr_line->next_line != NULL) 1328192830Sed curr_line = curr_line->next_line; 1329192830Sed point = curr_line->line; 1330192830Sed if (horiz_offset) 1331192830Sed horiz_offset = 0; 1332192830Sed position = 1; 1333192830Sed midscreen(last_line, point); 1334192830Sed scr_pos = scr_horz; 1335192830Sed} 1336192830Sed 1337192830Sedvoid 1338192830Sedtop() /* go to top of file */ 1339192830Sed{ 1340192830Sed while (curr_line->prev_line != NULL) 1341192830Sed curr_line = curr_line->prev_line; 1342192830Sed point = curr_line->line; 1343192830Sed if (horiz_offset) 1344192830Sed horiz_offset = 0; 1345192830Sed position = 1; 1346192830Sed midscreen(0, point); 1347192830Sed scr_pos = scr_horz; 1348192830Sed} 1349192830Sed 1350192830Sedvoid 1351192830Sednextline() /* move pointers to start of next line */ 1352192830Sed{ 1353192830Sed curr_line = curr_line->next_line; 1354192830Sed point = curr_line->line; 1355192830Sed position = 1; 1356192830Sed if (scr_vert == last_line) 1357192830Sed { 1358192830Sed wmove(text_win, 0,0); 1359192830Sed wdeleteln(text_win); 1360192830Sed wmove(text_win, last_line,0); 1361192830Sed wclrtobot(text_win); 1362192830Sed draw_line(last_line,0,point,1,curr_line->line_length); 1363192830Sed } 1364192830Sed else 1365192830Sed scr_vert++; 1366192830Sed} 1367192830Sed 1368192830Sedvoid 1369192830Sedprevline() /* move pointers to start of previous line*/ 1370192830Sed{ 1371192830Sed curr_line = curr_line->prev_line; 1372192830Sed point = curr_line->line; 1373192830Sed position = 1; 1374192830Sed if (scr_vert == 0) 1375192830Sed { 1376192830Sed winsertln(text_win); 1377192830Sed draw_line(0,0,point,1,curr_line->line_length); 1378192830Sed } 1379192830Sed else 1380192830Sed scr_vert--; 1381192830Sed while (position < curr_line->line_length) 1382192830Sed { 1383192830Sed position++; 1384192830Sed point++; 1385192830Sed } 1386192830Sed} 1387192830Sed 1388192830Sedvoid 1389192830Sedleft(disp) /* move left one character */ 1390192830Sedint disp; 1391192830Sed{ 1392192830Sed if (point != curr_line->line) /* if not at begin of line */ 1393192830Sed { 1394192830Sed if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127)) 1395192830Sed { 1396192830Sed point--; 1397192830Sed position--; 1398192830Sed } 1399192830Sed point--; 1400192830Sed position--; 1401192830Sed scanline(point); 1402192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1403192830Sed scr_pos = scr_horz; 1404192830Sed } 1405192830Sed else if (curr_line->prev_line != NULL) 1406192830Sed { 1407192830Sed if (!disp) 1408192830Sed { 1409192830Sed curr_line = curr_line->prev_line; 1410192830Sed point = curr_line->line + curr_line->line_length; 1411192830Sed position = curr_line->line_length; 1412192830Sed return; 1413192830Sed } 1414192830Sed position = 1; 1415192830Sed prevline(); 1416192830Sed scanline(point); 1417192830Sed scr_pos = scr_horz; 1418192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1419192830Sed } 1420192830Sed} 1421192830Sed 1422192830Sedvoid 1423192830Sedright(disp) /* move right one character */ 1424192830Sedint disp; 1425192830Sed{ 1426192830Sed if (position < curr_line->line_length) 1427192830Sed { 1428192830Sed if ((ee_chinese) && (*point > 127) && 1429192830Sed ((curr_line->line_length - position) >= 2)) 1430192830Sed { 1431192830Sed point++; 1432192830Sed position++; 1433192830Sed } 1434192830Sed point++; 1435192830Sed position++; 1436192830Sed scanline(point); 1437192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1438192830Sed scr_pos = scr_horz; 1439192830Sed } 1440192830Sed else if (curr_line->next_line != NULL) 1441192830Sed { 1442192830Sed if (!disp) 1443192830Sed { 1444192830Sed curr_line = curr_line->next_line; 1445192830Sed point = curr_line->line; 1446192830Sed position = 1; 1447192830Sed return; 1448192830Sed } 1449192830Sed nextline(); 1450192830Sed scr_pos = scr_horz = 0; 1451192830Sed if (horiz_offset) 1452192830Sed { 1453192830Sed horiz_offset = 0; 1454192830Sed midscreen(scr_vert, point); 1455192830Sed } 1456192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1457192830Sed position = 1; 1458192830Sed } 1459192830Sed} 1460192830Sed 1461192830Sedvoid 1462192830Sedfind_pos() /* move to the same column as on other line */ 1463192830Sed{ 1464192830Sed scr_horz = 0; 1465192830Sed position = 1; 1466192830Sed while ((scr_horz < scr_pos) && (position < curr_line->line_length)) 1467192830Sed { 1468192830Sed if (*point == 9) 1469192830Sed scr_horz += tabshift(scr_horz); 1470192830Sed else if (*point < ' ') 1471192830Sed scr_horz += 2; 1472192830Sed else if ((ee_chinese) && (*point > 127) && 1473192830Sed ((curr_line->line_length - position) >= 2)) 1474192830Sed { 1475192830Sed scr_horz += 2; 1476192830Sed point++; 1477192830Sed position++; 1478192830Sed } 1479192830Sed else 1480192830Sed scr_horz++; 1481192830Sed position++; 1482192830Sed point++; 1483192830Sed } 1484192830Sed if ((scr_horz - horiz_offset) > last_col) 1485192830Sed { 1486192830Sed horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8); 1487192830Sed midscreen(scr_vert, point); 1488192830Sed } 1489192830Sed else if (scr_horz < horiz_offset) 1490192830Sed { 1491192830Sed horiz_offset = max(0, (scr_horz - (scr_horz % 8))); 1492192830Sed midscreen(scr_vert, point); 1493192830Sed } 1494192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1495192830Sed} 1496192830Sed 1497192830Sedvoid 1498192830Sedup() /* move up one line */ 1499192830Sed{ 1500192830Sed if (curr_line->prev_line != NULL) 1501192830Sed { 1502192830Sed prevline(); 1503192830Sed point = curr_line->line; 1504192830Sed find_pos(); 1505192830Sed } 1506192830Sed} 1507192830Sed 1508192830Sedvoid 1509192830Seddown() /* move down one line */ 1510192830Sed{ 1511192830Sed if (curr_line->next_line != NULL) 1512192830Sed { 1513192830Sed nextline(); 1514192830Sed find_pos(); 1515192830Sed } 1516192830Sed} 1517192830Sed 1518192830Sedvoid 1519192830Sedfunction_key() /* process function key */ 1520192830Sed{ 1521192830Sed if (in == KEY_LEFT) 1522192830Sed left(TRUE); 1523192830Sed else if (in == KEY_RIGHT) 1524192830Sed right(TRUE); 1525192856Sed else if (in == KEY_HOME) 1526192856Sed bol(); 1527192856Sed else if (in == KEY_END) 1528192856Sed eol(); 1529192830Sed else if ( in == KEY_UP) 1530192830Sed up(); 1531192830Sed else if (in == KEY_DOWN) 1532192830Sed down(); 1533192830Sed else if (in == KEY_NPAGE) 1534192830Sed move_rel("d", max( 5, (last_line - 5))); 1535192830Sed else if (in == KEY_PPAGE) 1536192830Sed move_rel("u", max(5, (last_line - 5))); 1537192830Sed else if (in == KEY_DL) 1538192830Sed del_line(); 1539192830Sed else if (in == KEY_DC) 1540192830Sed del_char(); 1541192830Sed else if (in == KEY_BACKSPACE) 1542192830Sed delete(TRUE); 1543192830Sed else if (in == KEY_IL) 1544192830Sed { /* insert a line before current line */ 1545192830Sed insert_line(TRUE); 1546192830Sed left(TRUE); 1547192830Sed } 1548192830Sed else if (in == KEY_F(1)) 1549192830Sed gold = !gold; 1550192830Sed else if (in == KEY_F(2)) 1551192830Sed { 1552192830Sed if (gold) 1553192830Sed { 1554192830Sed gold = FALSE; 1555192830Sed undel_line(); 1556192830Sed } 1557192830Sed else 1558192830Sed undel_char(); 1559192830Sed } 1560192830Sed else if (in == KEY_F(3)) 1561192830Sed { 1562192830Sed if (gold) 1563192830Sed { 1564192830Sed gold = FALSE; 1565192830Sed undel_word(); 1566192830Sed } 1567192830Sed else 1568192830Sed del_word(); 1569192830Sed } 1570192830Sed else if (in == KEY_F(4)) 1571192830Sed { 1572192830Sed if (gold) 1573192830Sed { 1574192830Sed gold = FALSE; 1575192830Sed paint_info_win(); 1576192830Sed midscreen(scr_vert, point); 1577192830Sed } 1578192830Sed else 1579192830Sed adv_word(); 1580192830Sed } 1581192830Sed else if (in == KEY_F(5)) 1582192830Sed { 1583192830Sed if (gold) 1584192830Sed { 1585192830Sed gold = FALSE; 1586192830Sed search_prompt(); 1587192830Sed } 1588192830Sed else 1589192830Sed search(TRUE); 1590192830Sed } 1591192830Sed else if (in == KEY_F(6)) 1592192830Sed { 1593192830Sed if (gold) 1594192830Sed { 1595192830Sed gold = FALSE; 1596192830Sed bottom(); 1597192830Sed } 1598192830Sed else 1599192830Sed top(); 1600192830Sed } 1601192830Sed else if (in == KEY_F(7)) 1602192830Sed { 1603192830Sed if (gold) 1604192830Sed { 1605192830Sed gold = FALSE; 1606192830Sed eol(); 1607192830Sed } 1608192830Sed else 1609192830Sed bol(); 1610192830Sed } 1611192830Sed else if (in == KEY_F(8)) 1612192830Sed { 1613192830Sed if (gold) 1614192830Sed { 1615192830Sed gold = FALSE; 1616192830Sed command_prompt(); 1617192830Sed } 1618192830Sed else 1619192830Sed adv_line(); 1620192830Sed } 1621192830Sed} 1622192830Sed 1623192830Sedvoid 1624192830Sedprint_buffer() 1625192830Sed{ 1626192830Sed char buffer[256]; 1627192830Sed 1628192830Sed sprintf(buffer, ">!%s", print_command); 1629192830Sed wmove(com_win, 0, 0); 1630192830Sed wclrtoeol(com_win); 1631192830Sed wprintw(com_win, printer_msg_str, print_command); 1632192830Sed wrefresh(com_win); 1633192830Sed command(buffer); 1634192830Sed} 1635192830Sed 1636192830Sedvoid 1637192830Sedcommand_prompt() 1638192830Sed{ 1639192830Sed char *cmd_str; 1640192830Sed int result; 1641192830Sed 1642192830Sed info_type = COMMANDS; 1643192830Sed paint_info_win(); 1644192830Sed cmd_str = get_string(command_str, TRUE); 1645192830Sed if ((result = unique_test(cmd_str, commands)) != 1) 1646192830Sed { 1647192830Sed werase(com_win); 1648192830Sed wmove(com_win, 0, 0); 1649192830Sed if (result == 0) 1650192830Sed wprintw(com_win, unkn_cmd_str, cmd_str); 1651192830Sed else 1652192830Sed wprintw(com_win, non_unique_cmd_msg); 1653192830Sed 1654192830Sed wrefresh(com_win); 1655192830Sed 1656192830Sed info_type = CONTROL_KEYS; 1657192830Sed paint_info_win(); 1658192830Sed 1659192830Sed if (cmd_str != NULL) 1660192830Sed free(cmd_str); 1661192830Sed return; 1662192830Sed } 1663192830Sed command(cmd_str); 1664192830Sed wrefresh(com_win); 1665192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 1666192830Sed info_type = CONTROL_KEYS; 1667192830Sed paint_info_win(); 1668192830Sed if (cmd_str != NULL) 1669192830Sed free(cmd_str); 1670192830Sed} 1671192830Sed 1672192830Sedvoid 1673192830Sedcommand(cmd_str1) /* process commands from keyboard */ 1674192830Sedchar *cmd_str1; 1675192830Sed{ 1676192830Sed char *cmd_str2 = NULL; 1677192830Sed char *cmd_str = cmd_str1; 1678192830Sed 1679192830Sed clear_com_win = TRUE; 1680192830Sed if (compare(cmd_str, HELP, FALSE)) 1681192830Sed help(); 1682192830Sed else if (compare(cmd_str, WRITE, FALSE)) 1683192830Sed { 1684192830Sed if (restrict_mode()) 1685192830Sed { 1686192830Sed return; 1687192830Sed } 1688192830Sed cmd_str = next_word(cmd_str); 1689192830Sed if (*cmd_str == (char) NULL) 1690192830Sed { 1691192830Sed cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE); 1692192830Sed } 1693192830Sed tmp_file = resolve_name(cmd_str); 1694192856Sed write_file(tmp_file, 1); 1695192830Sed if (tmp_file != cmd_str) 1696192830Sed free(tmp_file); 1697192830Sed } 1698192830Sed else if (compare(cmd_str, READ, FALSE)) 1699192830Sed { 1700192830Sed if (restrict_mode()) 1701192830Sed { 1702192830Sed return; 1703192830Sed } 1704192830Sed cmd_str = next_word(cmd_str); 1705192830Sed if (*cmd_str == (char) NULL) 1706192830Sed { 1707192830Sed cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE); 1708192830Sed } 1709192830Sed tmp_file = cmd_str; 1710192830Sed recv_file = TRUE; 1711192830Sed tmp_file = resolve_name(cmd_str); 1712192830Sed check_fp(); 1713192830Sed if (tmp_file != cmd_str) 1714192830Sed free(tmp_file); 1715192830Sed } 1716192830Sed else if (compare(cmd_str, LINE, FALSE)) 1717192830Sed { 1718192830Sed wmove(com_win, 0, 0); 1719192830Sed wclrtoeol(com_win); 1720192830Sed wprintw(com_win, line_num_str, curr_line->line_number); 1721192830Sed wprintw(com_win, line_len_str, curr_line->line_length); 1722192830Sed } 1723192830Sed else if (compare(cmd_str, FILE_str, FALSE)) 1724192830Sed { 1725192830Sed wmove(com_win, 0, 0); 1726192830Sed wclrtoeol(com_win); 1727192830Sed if (in_file_name == NULL) 1728192830Sed wprintw(com_win, no_file_string); 1729192830Sed else 1730192830Sed wprintw(com_win, current_file_str, in_file_name); 1731192830Sed } 1732192830Sed else if ((*cmd_str >= '0') && (*cmd_str <= '9')) 1733192830Sed goto_line(cmd_str); 1734192830Sed else if (compare(cmd_str, CHARACTER, FALSE)) 1735192830Sed { 1736192830Sed wmove(com_win, 0, 0); 1737192830Sed wclrtoeol(com_win); 1738192830Sed wprintw(com_win, char_str, *point); 1739192830Sed } 1740192830Sed else if (compare(cmd_str, REDRAW, FALSE)) 1741192830Sed redraw(); 1742192830Sed else if (compare(cmd_str, RESEQUENCE, FALSE)) 1743192830Sed { 1744192830Sed tmp_line = first_line->next_line; 1745192830Sed while (tmp_line != NULL) 1746192830Sed { 1747192830Sed tmp_line->line_number = tmp_line->prev_line->line_number + 1; 1748192830Sed tmp_line = tmp_line->next_line; 1749192830Sed } 1750192830Sed } 1751192830Sed else if (compare(cmd_str, AUTHOR, FALSE)) 1752192830Sed { 1753192830Sed wmove(com_win, 0, 0); 1754192830Sed wclrtoeol(com_win); 1755192830Sed wprintw(com_win, "written by Hugh Mahon"); 1756192830Sed } 1757192830Sed else if (compare(cmd_str, VERSION, FALSE)) 1758192830Sed { 1759192830Sed wmove(com_win, 0, 0); 1760192830Sed wclrtoeol(com_win); 1761192830Sed wprintw(com_win, "%s", version); 1762192830Sed } 1763192830Sed else if (compare(cmd_str, CASE, FALSE)) 1764192830Sed case_sen = TRUE; 1765192830Sed else if (compare(cmd_str, NOCASE, FALSE)) 1766192830Sed case_sen = FALSE; 1767192830Sed else if (compare(cmd_str, EXPAND, FALSE)) 1768192830Sed expand_tabs = TRUE; 1769192830Sed else if (compare(cmd_str, NOEXPAND, FALSE)) 1770192830Sed expand_tabs = FALSE; 1771192830Sed else if (compare(cmd_str, Exit_string, FALSE)) 1772192830Sed finish(); 1773192830Sed else if (compare(cmd_str, chinese_cmd, FALSE)) 1774192830Sed { 1775192830Sed ee_chinese = TRUE; 1776192830Sed#ifdef NCURSE 1777192830Sed nc_setattrib(A_NC_BIG5); 1778192830Sed#endif /* NCURSE */ 1779192830Sed } 1780192830Sed else if (compare(cmd_str, nochinese_cmd, FALSE)) 1781192830Sed { 1782192830Sed ee_chinese = FALSE; 1783192830Sed#ifdef NCURSE 1784192830Sed nc_clearattrib(A_NC_BIG5); 1785192830Sed#endif /* NCURSE */ 1786192830Sed } 1787192830Sed else if (compare(cmd_str, QUIT_string, FALSE)) 1788192830Sed quit(0); 1789192830Sed else if (*cmd_str == '!') 1790192830Sed { 1791192830Sed cmd_str++; 1792192830Sed if ((*cmd_str == ' ') || (*cmd_str == 9)) 1793192830Sed cmd_str = next_word(cmd_str); 1794192830Sed sh_command(cmd_str); 1795192830Sed } 1796192830Sed else if ((*cmd_str == '<') && (!in_pipe)) 1797192830Sed { 1798192830Sed in_pipe = TRUE; 1799192830Sed shell_fork = FALSE; 1800192830Sed cmd_str++; 1801192830Sed if ((*cmd_str == ' ') || (*cmd_str == '\t')) 1802192830Sed cmd_str = next_word(cmd_str); 1803192830Sed command(cmd_str); 1804192830Sed in_pipe = FALSE; 1805192830Sed shell_fork = TRUE; 1806192830Sed } 1807192830Sed else if ((*cmd_str == '>') && (!out_pipe)) 1808192830Sed { 1809192830Sed out_pipe = TRUE; 1810192830Sed cmd_str++; 1811192830Sed if ((*cmd_str == ' ') || (*cmd_str == '\t')) 1812192830Sed cmd_str = next_word(cmd_str); 1813192830Sed command(cmd_str); 1814192830Sed out_pipe = FALSE; 1815192830Sed } 1816192830Sed else 1817192830Sed { 1818192830Sed wmove(com_win, 0, 0); 1819192830Sed wclrtoeol(com_win); 1820192830Sed wprintw(com_win, unkn_cmd_str, cmd_str); 1821192830Sed } 1822192830Sed if (cmd_str2 != NULL) 1823192830Sed free(cmd_str2); 1824192830Sed} 1825192830Sed 1826192830Sedint 1827192830Sedscan(line, offset, column) /* determine horizontal position for get_string */ 1828192830Sedchar *line; 1829192830Sedint offset; 1830192830Sedint column; 1831192830Sed{ 1832192830Sed char *stemp; 1833192830Sed int i; 1834192830Sed int j; 1835192830Sed 1836192830Sed stemp = line; 1837192830Sed i = 0; 1838192830Sed j = column; 1839192830Sed while (i < offset) 1840192830Sed { 1841192830Sed i++; 1842192830Sed j += len_char(*stemp, j); 1843192830Sed stemp++; 1844192830Sed } 1845192830Sed return(j); 1846192830Sed} 1847192830Sed 1848192830Sedchar * 1849192830Sedget_string(prompt, advance) /* read string from input on command line */ 1850192830Sedchar *prompt; /* string containing user prompt message */ 1851192830Sedint advance; /* if true, skip leading spaces and tabs */ 1852192830Sed{ 1853192830Sed char *string; 1854192830Sed char *tmp_string; 1855192830Sed char *nam_str; 1856192830Sed char *g_point; 1857192830Sed int tmp_int; 1858192830Sed int g_horz, g_position, g_pos; 1859192830Sed int esc_flag; 1860192830Sed 1861192830Sed g_point = tmp_string = malloc(512); 1862192830Sed wmove(com_win,0,0); 1863192830Sed wclrtoeol(com_win); 1864192830Sed waddstr(com_win, prompt); 1865192830Sed wrefresh(com_win); 1866192830Sed nam_str = tmp_string; 1867192830Sed clear_com_win = TRUE; 1868192830Sed g_horz = g_position = scan(prompt, strlen(prompt), 0); 1869192830Sed g_pos = 0; 1870192830Sed do 1871192830Sed { 1872192830Sed esc_flag = FALSE; 1873192830Sed in = wgetch(com_win); 1874192830Sed if (in == -1) 1875192856Sed continue; 1876192830Sed if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0)) 1877192830Sed { 1878192830Sed tmp_int = g_horz; 1879192830Sed g_pos--; 1880192830Sed g_horz = scan(g_point, g_pos, g_position); 1881192830Sed tmp_int = tmp_int - g_horz; 1882192830Sed for (; 0 < tmp_int; tmp_int--) 1883192830Sed { 1884192830Sed if ((g_horz+tmp_int) < (last_col - 1)) 1885192830Sed { 1886192830Sed waddch(com_win, '\010'); 1887192830Sed waddch(com_win, ' '); 1888192830Sed waddch(com_win, '\010'); 1889192830Sed } 1890192830Sed } 1891192830Sed nam_str--; 1892192830Sed } 1893192830Sed else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256)) 1894192830Sed { 1895192830Sed if (in == '\026') /* control-v, accept next character verbatim */ 1896192830Sed { /* allows entry of ^m, ^j, and ^h */ 1897192830Sed esc_flag = TRUE; 1898192830Sed in = wgetch(com_win); 1899192830Sed if (in == -1) 1900192856Sed continue; 1901192830Sed } 1902192830Sed *nam_str = in; 1903192830Sed g_pos++; 1904192830Sed if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1))) 1905192830Sed g_horz += out_char(com_win, in, g_horz); 1906192830Sed else 1907192830Sed { 1908192830Sed g_horz++; 1909192830Sed if (g_horz < (last_col - 1)) 1910192830Sed waddch(com_win, in); 1911192830Sed } 1912192830Sed nam_str++; 1913192830Sed } 1914192830Sed wrefresh(com_win); 1915192830Sed if (esc_flag) 1916192830Sed in = (char) NULL; 1917192830Sed } while ((in != '\n') && (in != '\r')); 1918192830Sed *nam_str = (char) NULL; 1919192830Sed nam_str = tmp_string; 1920192830Sed if (((*nam_str == ' ') || (*nam_str == 9)) && (advance)) 1921192830Sed nam_str = next_word(nam_str); 1922192830Sed string = malloc(strlen(nam_str) + 1); 1923192830Sed strcpy(string, nam_str); 1924192830Sed free(tmp_string); 1925192830Sed wrefresh(com_win); 1926192830Sed return(string); 1927192830Sed} 1928192830Sed 1929192830Sedint 1930192830Sedcompare(string1, string2, sensitive) /* compare two strings */ 1931192830Sedchar *string1; 1932192830Sedchar *string2; 1933192830Sedint sensitive; 1934192830Sed{ 1935192830Sed char *strng1; 1936192830Sed char *strng2; 1937192830Sed int tmp; 1938192830Sed int equal; 1939192830Sed 1940192830Sed strng1 = string1; 1941192830Sed strng2 = string2; 1942192830Sed tmp = 0; 1943192830Sed if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == (char) NULL) || (*strng2 == (char) NULL)) 1944192830Sed return(FALSE); 1945192830Sed equal = TRUE; 1946192830Sed while (equal) 1947192830Sed { 1948192830Sed if (sensitive) 1949192830Sed { 1950192830Sed if (*strng1 != *strng2) 1951192830Sed equal = FALSE; 1952192830Sed } 1953192830Sed else 1954192830Sed { 1955192830Sed if (toupper(*strng1) != toupper(*strng2)) 1956192830Sed equal = FALSE; 1957192830Sed } 1958192830Sed strng1++; 1959192830Sed strng2++; 1960192830Sed if ((*strng1 == (char) NULL) || (*strng2 == (char) NULL) || (*strng1 == ' ') || (*strng2 == ' ')) 1961192830Sed break; 1962192830Sed tmp++; 1963192830Sed } 1964192830Sed return(equal); 1965192830Sed} 1966192830Sed 1967192830Sedvoid 1968192830Sedgoto_line(cmd_str) 1969192830Sedchar *cmd_str; 1970192830Sed{ 1971192830Sed int number; 1972192830Sed int i; 1973192830Sed char *ptr; 1974192856Sed char *direction = NULL; 1975192830Sed struct text *t_line; 1976192830Sed 1977192830Sed ptr = cmd_str; 1978192830Sed i= 0; 1979192830Sed while ((*ptr >='0') && (*ptr <= '9')) 1980192830Sed { 1981192830Sed i= i * 10 + (*ptr - '0'); 1982192830Sed ptr++; 1983192830Sed } 1984192830Sed number = i; 1985192830Sed i = 0; 1986192830Sed t_line = curr_line; 1987192830Sed while ((t_line->line_number > number) && (t_line->prev_line != NULL)) 1988192830Sed { 1989192830Sed i++; 1990192830Sed t_line = t_line->prev_line; 1991192830Sed direction = "u"; 1992192830Sed } 1993192830Sed while ((t_line->line_number < number) && (t_line->next_line != NULL)) 1994192830Sed { 1995192830Sed i++; 1996192830Sed direction = "d"; 1997192830Sed t_line = t_line->next_line; 1998192830Sed } 1999192830Sed if ((i < 30) && (i > 0)) 2000192830Sed { 2001192830Sed move_rel(direction, i); 2002192830Sed } 2003192830Sed else 2004192830Sed { 2005192830Sed curr_line = t_line; 2006192830Sed point = curr_line->line; 2007192830Sed position = 1; 2008192830Sed midscreen((last_line / 2), point); 2009192830Sed scr_pos = scr_horz; 2010192830Sed } 2011192830Sed wmove(com_win, 0, 0); 2012192830Sed wclrtoeol(com_win); 2013192830Sed wprintw(com_win, line_num_str, curr_line->line_number); 2014192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 2015192830Sed} 2016192830Sed 2017192830Sedvoid 2018192830Sedmidscreen(line, pnt) /* put current line in middle of screen */ 2019192830Sedint line; 2020192830Sedunsigned char *pnt; 2021192830Sed{ 2022192830Sed struct text *mid_line; 2023192830Sed int i; 2024192830Sed 2025192830Sed line = min(line, last_line); 2026192830Sed mid_line = curr_line; 2027192830Sed for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++) 2028192830Sed curr_line = curr_line->prev_line; 2029192830Sed scr_vert = scr_horz = 0; 2030192830Sed wmove(text_win, 0, 0); 2031192830Sed draw_screen(); 2032192830Sed scr_vert = i; 2033192830Sed curr_line = mid_line; 2034192830Sed scanline(pnt); 2035192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 2036192830Sed} 2037192830Sed 2038192830Sedvoid 2039192830Sedget_options(numargs, arguments) /* get arguments from command line */ 2040192830Sedint numargs; 2041192830Sedchar *arguments[]; 2042192830Sed{ 2043192830Sed char *buff; 2044192830Sed int count; 2045192856Sed struct files *temp_names = NULL; 2046192830Sed char *name; 2047192830Sed char *ptr; 2048192856Sed int no_more_opts = FALSE; 2049192830Sed 2050192830Sed /* 2051192830Sed | see if editor was invoked as 'ree' (restricted mode) 2052192830Sed */ 2053192830Sed 2054192830Sed if (!(name = strrchr(arguments[0], '/'))) 2055192830Sed name = arguments[0]; 2056192830Sed else 2057192830Sed name++; 2058192830Sed if (!strcmp(name, "ree")) 2059192830Sed restricted = TRUE; 2060192830Sed 2061192830Sed top_of_stack = NULL; 2062192830Sed input_file = FALSE; 2063192830Sed recv_file = FALSE; 2064192830Sed count = 1; 2065192856Sed while ((count < numargs) && (!no_more_opts)) 2066192830Sed { 2067192830Sed buff = arguments[count]; 2068192830Sed if (!strcmp("-i", buff)) 2069192830Sed { 2070192830Sed info_window = FALSE; 2071192830Sed } 2072192830Sed else if (!strcmp("-e", buff)) 2073192830Sed { 2074192830Sed expand_tabs = FALSE; 2075192830Sed } 2076192830Sed else if (!strcmp("-h", buff)) 2077192830Sed { 2078192830Sed nohighlight = TRUE; 2079192830Sed } 2080192830Sed else if (!strcmp("-?", buff)) 2081192830Sed { 2082192830Sed fprintf(stderr, usage0, arguments[0]); 2083192830Sed fprintf(stderr, usage1); 2084192830Sed fprintf(stderr, usage2); 2085192830Sed fprintf(stderr, usage3); 2086192830Sed fprintf(stderr, usage4); 2087192830Sed exit(1); 2088192830Sed } 2089192830Sed else if (*buff == '+') 2090192830Sed { 2091192830Sed buff++; 2092192830Sed start_at_line = buff; 2093192830Sed } 2094192856Sed else if (!(strcmp("--", buff))) 2095192856Sed no_more_opts = TRUE; 2096192830Sed else 2097192830Sed { 2098192856Sed count--; 2099192856Sed no_more_opts = TRUE; 2100192830Sed } 2101192830Sed count++; 2102192830Sed } 2103192856Sed while (count < numargs) 2104192856Sed { 2105192856Sed buff = arguments[count]; 2106192856Sed if (top_of_stack == NULL) 2107192856Sed { 2108192856Sed temp_names = top_of_stack = name_alloc(); 2109192856Sed } 2110192856Sed else 2111192856Sed { 2112192856Sed temp_names->next_name = name_alloc(); 2113192856Sed temp_names = temp_names->next_name; 2114192856Sed } 2115192856Sed ptr = temp_names->name = malloc(strlen(buff) + 1); 2116192856Sed while (*buff != (char) NULL) 2117192856Sed { 2118192856Sed *ptr = *buff; 2119192856Sed buff++; 2120192856Sed ptr++; 2121192856Sed } 2122192856Sed *ptr = (char) NULL; 2123192856Sed temp_names->next_name = NULL; 2124192856Sed input_file = TRUE; 2125192856Sed recv_file = TRUE; 2126192856Sed count++; 2127192856Sed } 2128192830Sed} 2129192830Sed 2130192830Sedvoid 2131192830Sedcheck_fp() /* open or close files according to flags */ 2132192830Sed{ 2133192830Sed int line_num; 2134192830Sed int temp; 2135192830Sed struct stat buf; 2136192830Sed 2137192830Sed clear_com_win = TRUE; 2138192830Sed tmp_vert = scr_vert; 2139192830Sed tmp_horz = scr_horz; 2140192830Sed tmp_line = curr_line; 2141192830Sed if (input_file) 2142192830Sed { 2143192830Sed in_file_name = tmp_file = top_of_stack->name; 2144192830Sed top_of_stack = top_of_stack->next_name; 2145192830Sed } 2146192830Sed temp = stat(tmp_file, &buf); 2147192830Sed buf.st_mode &= ~07777; 2148192830Sed if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0)) 2149192830Sed { 2150192830Sed wprintw(com_win, file_is_dir_msg, tmp_file); 2151192830Sed wrefresh(com_win); 2152192830Sed if (input_file) 2153192830Sed { 2154192830Sed quit(0); 2155192830Sed return; 2156192830Sed } 2157192830Sed else 2158192830Sed return; 2159192830Sed } 2160192830Sed if ((get_fd = open(tmp_file, O_RDONLY)) == -1) 2161192830Sed { 2162192830Sed wmove(com_win, 0, 0); 2163192830Sed wclrtoeol(com_win); 2164192830Sed if (input_file) 2165192830Sed wprintw(com_win, new_file_msg, tmp_file); 2166192830Sed else 2167192830Sed wprintw(com_win, cant_open_msg, tmp_file); 2168192830Sed wrefresh(com_win); 2169192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 2170192830Sed wrefresh(text_win); 2171192830Sed recv_file = FALSE; 2172192830Sed input_file = FALSE; 2173192830Sed return; 2174192830Sed } 2175192830Sed else 2176192830Sed get_file(tmp_file); 2177192830Sed 2178192830Sed recv_file = FALSE; 2179192830Sed line_num = curr_line->line_number; 2180192830Sed scr_vert = tmp_vert; 2181192830Sed scr_horz = tmp_horz; 2182192830Sed if (input_file) 2183192830Sed curr_line= first_line; 2184192830Sed else 2185192830Sed curr_line = tmp_line; 2186192830Sed point = curr_line->line; 2187192830Sed draw_screen(); 2188192830Sed if (input_file) 2189192830Sed { 2190192830Sed input_file = FALSE; 2191192830Sed if (start_at_line != NULL) 2192192830Sed { 2193192830Sed line_num = atoi(start_at_line) - 1; 2194192830Sed move_rel("d", line_num); 2195192830Sed line_num = 0; 2196192830Sed start_at_line = NULL; 2197192830Sed } 2198192830Sed } 2199192830Sed else 2200192830Sed { 2201192830Sed wmove(com_win, 0, 0); 2202192830Sed wclrtoeol(com_win); 2203192830Sed text_changes = TRUE; 2204192830Sed if ((tmp_file != NULL) && (*tmp_file != (char) NULL)) 2205192830Sed wprintw(com_win, file_read_fin_msg, tmp_file); 2206192830Sed } 2207192830Sed wrefresh(com_win); 2208192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 2209192830Sed wrefresh(text_win); 2210192830Sed} 2211192830Sed 2212192830Sedvoid 2213192830Sedget_file(file_name) /* read specified file into current buffer */ 2214192830Sedchar *file_name; 2215192830Sed{ 2216192830Sed int can_read; /* file has at least one character */ 2217192830Sed int length; /* length of line read by read */ 2218192830Sed int append; /* should text be appended to current line */ 2219192830Sed struct text *temp_line; 2220192830Sed char ro_flag = FALSE; 2221192830Sed 2222192830Sed if (recv_file) /* if reading a file */ 2223192830Sed { 2224192830Sed wmove(com_win, 0, 0); 2225192830Sed wclrtoeol(com_win); 2226192830Sed wprintw(com_win, reading_file_msg, file_name); 2227192830Sed if (access(file_name, 2)) /* check permission to write */ 2228192830Sed { 2229192830Sed if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT)) 2230192830Sed { 2231192830Sed wprintw(com_win, read_only_msg); 2232192830Sed ro_flag = TRUE; 2233192830Sed } 2234192830Sed } 2235192830Sed wrefresh(com_win); 2236192830Sed } 2237192830Sed if (curr_line->line_length > 1) /* if current line is not blank */ 2238192830Sed { 2239192830Sed insert_line(FALSE); 2240192830Sed left(FALSE); 2241192830Sed append = FALSE; 2242192830Sed } 2243192830Sed else 2244192830Sed append = TRUE; 2245192830Sed can_read = FALSE; /* test if file has any characters */ 2246192830Sed while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1)) 2247192830Sed { 2248192830Sed can_read = TRUE; /* if set file has at least 1 character */ 2249192830Sed get_line(length, in_string, &append); 2250192830Sed } 2251192830Sed if ((can_read) && (curr_line->line_length == 1)) 2252192830Sed { 2253192830Sed temp_line = curr_line->prev_line; 2254192830Sed temp_line->next_line = curr_line->next_line; 2255192830Sed if (temp_line->next_line != NULL) 2256192830Sed temp_line->next_line->prev_line = temp_line; 2257192830Sed if (curr_line->line != NULL) 2258192830Sed free(curr_line->line); 2259192830Sed free(curr_line); 2260192830Sed curr_line = temp_line; 2261192830Sed } 2262192830Sed if (input_file) /* if this is the file to be edited display number of lines */ 2263192830Sed { 2264192830Sed wmove(com_win, 0, 0); 2265192830Sed wclrtoeol(com_win); 2266192830Sed wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number); 2267192830Sed if (ro_flag) 2268192830Sed wprintw(com_win, read_only_msg); 2269192830Sed wrefresh(com_win); 2270192830Sed } 2271192830Sed else if (can_read) /* not input_file and file is non-zero size */ 2272192830Sed text_changes = TRUE; 2273192830Sed 2274192830Sed if (recv_file) /* if reading a file */ 2275192830Sed { 2276192830Sed in = EOF; 2277192830Sed } 2278192830Sed} 2279192830Sed 2280192830Sedvoid 2281192830Sedget_line(length, in_string, append) /* read string and split into lines */ 2282192830Sedint length; /* length of string read by read */ 2283192830Sedunsigned char *in_string; /* string read by read */ 2284192830Sedint *append; /* TRUE if must append more text to end of current line */ 2285192830Sed{ 2286192830Sed unsigned char *str1; 2287192830Sed unsigned char *str2; 2288192830Sed int num; /* offset from start of string */ 2289192830Sed int char_count; /* length of new line (or added portion */ 2290192830Sed int temp_counter; /* temporary counter value */ 2291192830Sed struct text *tline; /* temporary pointer to new line */ 2292192830Sed int first_time; /* if TRUE, the first time through the loop */ 2293192830Sed 2294192830Sed str2 = in_string; 2295192830Sed num = 0; 2296192830Sed first_time = TRUE; 2297192830Sed while (num < length) 2298192830Sed { 2299192830Sed if (!first_time) 2300192830Sed { 2301192830Sed if (num < length) 2302192830Sed { 2303192830Sed str2++; 2304192830Sed num++; 2305192830Sed } 2306192830Sed } 2307192830Sed else 2308192830Sed first_time = FALSE; 2309192830Sed str1 = str2; 2310192830Sed char_count = 1; 2311192830Sed /* find end of line */ 2312192830Sed while ((*str2 != '\n') && (num < length)) 2313192830Sed { 2314192830Sed str2++; 2315192830Sed num++; 2316192830Sed char_count++; 2317192830Sed } 2318192830Sed if (!(*append)) /* if not append to current line, insert new one */ 2319192830Sed { 2320192830Sed tline = txtalloc(); /* allocate data structure for next line */ 2321192830Sed tline->next_line = curr_line->next_line; 2322192856Sed renumber_lines(tline, curr_line->line_number + 1); 2323192830Sed tline->prev_line = curr_line; 2324192830Sed curr_line->next_line = tline; 2325192830Sed if (tline->next_line != NULL) 2326192830Sed tline->next_line->prev_line = tline; 2327192830Sed curr_line = tline; 2328192830Sed curr_line->line = point = (unsigned char *) malloc(char_count); 2329192830Sed curr_line->line_length = char_count; 2330192830Sed curr_line->max_length = char_count; 2331192830Sed } 2332192830Sed else 2333192830Sed { 2334192830Sed point = resiz_line(char_count, curr_line, curr_line->line_length); 2335192830Sed curr_line->line_length += (char_count - 1); 2336192830Sed } 2337192830Sed for (temp_counter = 1; temp_counter < char_count; temp_counter++) 2338192830Sed { 2339192830Sed *point = *str1; 2340192830Sed point++; 2341192830Sed str1++; 2342192830Sed } 2343192830Sed *point = (char) NULL; 2344192830Sed *append = FALSE; 2345192830Sed if ((num == length) && (*str2 != '\n')) 2346192830Sed *append = TRUE; 2347192830Sed } 2348192830Sed} 2349192830Sed 2350192830Sedvoid 2351192830Seddraw_screen() /* redraw the screen from current postion */ 2352192830Sed{ 2353192830Sed struct text *temp_line; 2354192830Sed unsigned char *line_out; 2355192830Sed int temp_vert; 2356192830Sed 2357192830Sed temp_line = curr_line; 2358192830Sed temp_vert = scr_vert; 2359192830Sed wclrtobot(text_win); 2360192830Sed while ((temp_line != NULL) && (temp_vert <= last_line)) 2361192830Sed { 2362192830Sed line_out = temp_line->line; 2363192830Sed draw_line(temp_vert, 0, line_out, 1, temp_line->line_length); 2364192830Sed temp_vert++; 2365192830Sed temp_line = temp_line->next_line; 2366192830Sed } 2367192830Sed wmove(text_win, temp_vert, 0); 2368192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 2369192830Sed} 2370192830Sed 2371192830Sedvoid 2372192830Sedfinish() /* prepare to exit edit session */ 2373192830Sed{ 2374192830Sed char *file_name = in_file_name; 2375192830Sed 2376192830Sed /* 2377192830Sed | changes made here should be reflected in the 'save' 2378192830Sed | portion of file_op() 2379192830Sed */ 2380192830Sed 2381192830Sed if ((file_name == NULL) || (*file_name == (char) NULL)) 2382192830Sed file_name = get_string(save_file_name_prompt, TRUE); 2383192830Sed 2384192830Sed if ((file_name == NULL) || (*file_name == (char) NULL)) 2385192830Sed { 2386192830Sed wmove(com_win, 0, 0); 2387192830Sed wprintw(com_win, file_not_saved_msg); 2388192830Sed wclrtoeol(com_win); 2389192830Sed wrefresh(com_win); 2390192830Sed clear_com_win = TRUE; 2391192830Sed return; 2392192830Sed } 2393192830Sed 2394192830Sed tmp_file = resolve_name(file_name); 2395192830Sed if (tmp_file != file_name) 2396192830Sed { 2397192830Sed free(file_name); 2398192830Sed file_name = tmp_file; 2399192830Sed } 2400192830Sed 2401192856Sed if (write_file(file_name, 1)) 2402192830Sed { 2403192830Sed text_changes = FALSE; 2404192830Sed quit(0); 2405192830Sed } 2406192830Sed} 2407192830Sed 2408192830Sedint 2409192830Sedquit(noverify) /* exit editor */ 2410192830Sedint noverify; 2411192830Sed{ 2412192830Sed char *ans; 2413192830Sed 2414192830Sed touchwin(text_win); 2415192830Sed wrefresh(text_win); 2416192830Sed if ((text_changes) && (!noverify)) 2417192830Sed { 2418192830Sed ans = get_string(changes_made_prompt, TRUE); 2419192830Sed if (toupper(*ans) == toupper(*yes_char)) 2420192830Sed text_changes = FALSE; 2421192830Sed else 2422192830Sed return(0); 2423192830Sed free(ans); 2424192830Sed } 2425192830Sed if (top_of_stack == NULL) 2426192830Sed { 2427192830Sed if (info_window) 2428192830Sed wrefresh(info_win); 2429192830Sed wrefresh(com_win); 2430192830Sed resetty(); 2431192830Sed endwin(); 2432192830Sed putchar('\n'); 2433192830Sed exit(0); 2434192830Sed } 2435192830Sed else 2436192830Sed { 2437192830Sed delete_text(); 2438192830Sed recv_file = TRUE; 2439192830Sed input_file = TRUE; 2440192830Sed check_fp(); 2441192856Sed text_changes = FALSE; 2442192830Sed } 2443192830Sed return(0); 2444192830Sed} 2445192830Sed 2446192830Sedvoid 2447192830Sededit_abort(arg) 2448192830Sedint arg; 2449192830Sed{ 2450192830Sed wrefresh(com_win); 2451192830Sed resetty(); 2452192830Sed endwin(); 2453192830Sed putchar('\n'); 2454192830Sed exit(1); 2455192830Sed} 2456192830Sed 2457192830Sedvoid 2458192830Seddelete_text() 2459192830Sed{ 2460192830Sed while (curr_line->next_line != NULL) 2461192830Sed curr_line = curr_line->next_line; 2462192830Sed while (curr_line != first_line) 2463192830Sed { 2464192830Sed free(curr_line->line); 2465192830Sed curr_line = curr_line->prev_line; 2466192830Sed free(curr_line->next_line); 2467192830Sed } 2468192830Sed curr_line->next_line = NULL; 2469192830Sed *curr_line->line = (char) NULL; 2470192830Sed curr_line->line_length = 1; 2471192830Sed curr_line->line_number = 1; 2472192830Sed point = curr_line->line; 2473192830Sed scr_pos = scr_vert = scr_horz = 0; 2474192830Sed position = 1; 2475192830Sed} 2476192830Sed 2477192830Sedint 2478192856Sedwrite_file(file_name, warn_if_exists) 2479192830Sedchar *file_name; 2480192856Sedint warn_if_exists; 2481192830Sed{ 2482192830Sed char cr; 2483192830Sed char *tmp_point; 2484192830Sed struct text *out_line; 2485192830Sed int lines, charac; 2486192830Sed int temp_pos; 2487192830Sed int write_flag = TRUE; 2488192830Sed 2489192830Sed charac = lines = 0; 2490192856Sed if (warn_if_exists && 2491192856Sed ((in_file_name == NULL) || strcmp(in_file_name, file_name))) 2492192830Sed { 2493192830Sed if ((temp_fp = fopen(file_name, "r"))) 2494192830Sed { 2495192830Sed tmp_point = get_string(file_exists_prompt, TRUE); 2496192830Sed if (toupper(*tmp_point) == toupper(*yes_char)) 2497192830Sed write_flag = TRUE; 2498192830Sed else 2499192830Sed write_flag = FALSE; 2500192830Sed fclose(temp_fp); 2501192830Sed free(tmp_point); 2502192830Sed } 2503192830Sed } 2504192830Sed 2505192830Sed clear_com_win = TRUE; 2506192830Sed 2507192830Sed if (write_flag) 2508192830Sed { 2509192830Sed if ((temp_fp = fopen(file_name, "w")) == NULL) 2510192830Sed { 2511192830Sed clear_com_win = TRUE; 2512192830Sed wmove(com_win,0,0); 2513192830Sed wclrtoeol(com_win); 2514192830Sed wprintw(com_win, create_file_fail_msg, file_name); 2515192830Sed wrefresh(com_win); 2516192830Sed return(FALSE); 2517192830Sed } 2518192830Sed else 2519192830Sed { 2520192830Sed wmove(com_win,0,0); 2521192830Sed wclrtoeol(com_win); 2522192830Sed wprintw(com_win, writing_file_msg, file_name); 2523192830Sed wrefresh(com_win); 2524192830Sed cr = '\n'; 2525192830Sed out_line = first_line; 2526192830Sed while (out_line != NULL) 2527192830Sed { 2528192830Sed temp_pos = 1; 2529192830Sed tmp_point= out_line->line; 2530192830Sed while (temp_pos < out_line->line_length) 2531192830Sed { 2532192830Sed putc(*tmp_point, temp_fp); 2533192830Sed tmp_point++; 2534192830Sed temp_pos++; 2535192830Sed } 2536192830Sed charac += out_line->line_length; 2537192830Sed out_line = out_line->next_line; 2538192830Sed putc(cr, temp_fp); 2539192830Sed lines++; 2540192830Sed } 2541192830Sed fclose(temp_fp); 2542192830Sed wmove(com_win,0,0); 2543192830Sed wclrtoeol(com_win); 2544192830Sed wprintw(com_win, file_written_msg, file_name, lines, charac); 2545192830Sed wrefresh(com_win); 2546192830Sed return(TRUE); 2547192830Sed } 2548192830Sed } 2549192830Sed else 2550192830Sed return(FALSE); 2551192830Sed} 2552192830Sed 2553192830Sedint 2554192830Sedsearch(display_message) /* search for string in srch_str */ 2555192830Sedint display_message; 2556192830Sed{ 2557192830Sed int lines_moved; 2558192830Sed int iter; 2559192830Sed int found; 2560192830Sed 2561192830Sed if ((srch_str == NULL) || (*srch_str == (char) NULL)) 2562192830Sed return(FALSE); 2563192830Sed if (display_message) 2564192830Sed { 2565192830Sed wmove(com_win, 0, 0); 2566192830Sed wclrtoeol(com_win); 2567192830Sed wprintw(com_win, searching_msg); 2568192830Sed wrefresh(com_win); 2569192830Sed clear_com_win = TRUE; 2570192830Sed } 2571192830Sed lines_moved = 0; 2572192830Sed found = FALSE; 2573192830Sed srch_line = curr_line; 2574192830Sed srch_1 = point; 2575192830Sed if (position < curr_line->line_length) 2576192830Sed srch_1++; 2577192830Sed iter = position + 1; 2578192830Sed while ((!found) && (srch_line != NULL)) 2579192830Sed { 2580192830Sed while ((iter < srch_line->line_length) && (!found)) 2581192830Sed { 2582192830Sed srch_2 = srch_1; 2583192830Sed if (case_sen) /* if case sensitive */ 2584192830Sed { 2585192830Sed srch_3 = srch_str; 2586192830Sed while ((*srch_2 == *srch_3) && (*srch_3 != (char) NULL)) 2587192830Sed { 2588192830Sed found = TRUE; 2589192830Sed srch_2++; 2590192830Sed srch_3++; 2591192830Sed } /* end while */ 2592192830Sed } 2593192830Sed else /* if not case sensitive */ 2594192830Sed { 2595192830Sed srch_3 = u_srch_str; 2596192830Sed while ((toupper(*srch_2) == *srch_3) && (*srch_3 != (char) NULL)) 2597192830Sed { 2598192830Sed found = TRUE; 2599192830Sed srch_2++; 2600192830Sed srch_3++; 2601192830Sed } 2602192830Sed } /* end else */ 2603192830Sed if (!((*srch_3 == (char) NULL) && (found))) 2604192830Sed { 2605192830Sed found = FALSE; 2606192830Sed if (iter < srch_line->line_length) 2607192830Sed srch_1++; 2608192830Sed iter++; 2609192830Sed } 2610192830Sed } 2611192830Sed if (!found) 2612192830Sed { 2613192830Sed srch_line = srch_line->next_line; 2614192830Sed if (srch_line != NULL) 2615192830Sed srch_1 = srch_line->line; 2616192830Sed iter = 1; 2617192830Sed lines_moved++; 2618192830Sed } 2619192830Sed } 2620192830Sed if (found) 2621192830Sed { 2622192830Sed if (display_message) 2623192830Sed { 2624192830Sed wmove(com_win, 0, 0); 2625192830Sed wclrtoeol(com_win); 2626192830Sed wrefresh(com_win); 2627192830Sed } 2628192830Sed if (lines_moved == 0) 2629192830Sed { 2630192830Sed while (position < iter) 2631192830Sed right(TRUE); 2632192830Sed } 2633192830Sed else 2634192830Sed { 2635192830Sed if (lines_moved < 30) 2636192830Sed { 2637192830Sed move_rel("d", lines_moved); 2638192830Sed while (position < iter) 2639192830Sed right(TRUE); 2640192830Sed } 2641192830Sed else 2642192830Sed { 2643192830Sed curr_line = srch_line; 2644192830Sed point = srch_1; 2645192830Sed position = iter; 2646192830Sed scanline(point); 2647192830Sed scr_pos = scr_horz; 2648192830Sed midscreen((last_line / 2), point); 2649192830Sed } 2650192830Sed } 2651192830Sed } 2652192830Sed else 2653192830Sed { 2654192830Sed if (display_message) 2655192830Sed { 2656192830Sed wmove(com_win, 0, 0); 2657192830Sed wclrtoeol(com_win); 2658192830Sed wprintw(com_win, str_not_found_msg, srch_str); 2659192830Sed wrefresh(com_win); 2660192830Sed } 2661192830Sed wmove(text_win, scr_vert,(scr_horz - horiz_offset)); 2662192830Sed } 2663192830Sed return(found); 2664192830Sed} 2665192830Sed 2666192830Sedvoid 2667192830Sedsearch_prompt() /* prompt and read search string (srch_str) */ 2668192830Sed{ 2669192830Sed if (srch_str != NULL) 2670192830Sed free(srch_str); 2671192830Sed if ((u_srch_str != NULL) && (*u_srch_str != (char) NULL)) 2672192830Sed free(u_srch_str); 2673192830Sed srch_str = get_string(search_prompt_str, FALSE); 2674192830Sed gold = FALSE; 2675192830Sed srch_3 = srch_str; 2676192830Sed srch_1 = u_srch_str = malloc(strlen(srch_str) + 1); 2677192830Sed while (*srch_3 != (char) NULL) 2678192830Sed { 2679192830Sed *srch_1 = toupper(*srch_3); 2680192830Sed srch_1++; 2681192830Sed srch_3++; 2682192830Sed } 2683192830Sed *srch_1 = (char) NULL; 2684192830Sed search(TRUE); 2685192830Sed} 2686192830Sed 2687192830Sedvoid 2688192830Seddel_char() /* delete current character */ 2689192830Sed{ 2690192830Sed in = 8; /* backspace */ 2691192830Sed if (position < curr_line->line_length) /* if not end of line */ 2692192830Sed { 2693192830Sed if ((ee_chinese) && (*point > 127) && 2694192830Sed ((curr_line->line_length - position) >= 2)) 2695192830Sed { 2696192830Sed point++; 2697192830Sed position++; 2698192830Sed } 2699192830Sed position++; 2700192830Sed point++; 2701192830Sed scanline(point); 2702192830Sed delete(TRUE); 2703192830Sed } 2704192830Sed else 2705192830Sed { 2706192830Sed right(FALSE); 2707192830Sed delete(FALSE); 2708192830Sed } 2709192830Sed} 2710192830Sed 2711192830Sedvoid 2712192830Sedundel_char() /* undelete last deleted character */ 2713192830Sed{ 2714192830Sed if (d_char[0] == '\n') /* insert line if last del_char deleted eol */ 2715192830Sed insert_line(TRUE); 2716192830Sed else 2717192830Sed { 2718192830Sed in = d_char[0]; 2719192830Sed insert(in); 2720192830Sed if (d_char[1] != (unsigned char) NULL) 2721192830Sed { 2722192830Sed in = d_char[1]; 2723192830Sed insert(in); 2724192830Sed } 2725192830Sed } 2726192830Sed} 2727192830Sed 2728192830Sedvoid 2729192830Seddel_word() /* delete word in front of cursor */ 2730192830Sed{ 2731192830Sed int tposit; 2732192830Sed int difference; 2733192830Sed unsigned char *d_word2; 2734192830Sed unsigned char *d_word3; 2735192830Sed unsigned char tmp_char[3]; 2736192830Sed 2737192830Sed if (d_word != NULL) 2738192830Sed free(d_word); 2739192830Sed d_word = malloc(curr_line->line_length); 2740192830Sed tmp_char[0] = d_char[0]; 2741192830Sed tmp_char[1] = d_char[1]; 2742192830Sed tmp_char[2] = d_char[2]; 2743192830Sed d_word3 = point; 2744192830Sed d_word2 = d_word; 2745192830Sed tposit = position; 2746192830Sed while ((tposit < curr_line->line_length) && 2747192830Sed ((*d_word3 != ' ') && (*d_word3 != '\t'))) 2748192830Sed { 2749192830Sed tposit++; 2750192830Sed *d_word2 = *d_word3; 2751192830Sed d_word2++; 2752192830Sed d_word3++; 2753192830Sed } 2754192830Sed while ((tposit < curr_line->line_length) && 2755192830Sed ((*d_word3 == ' ') || (*d_word3 == '\t'))) 2756192830Sed { 2757192830Sed tposit++; 2758192830Sed *d_word2 = *d_word3; 2759192830Sed d_word2++; 2760192830Sed d_word3++; 2761192830Sed } 2762192830Sed *d_word2 = (char) NULL; 2763192830Sed d_wrd_len = difference = d_word2 - d_word; 2764192830Sed d_word2 = point; 2765192830Sed while (tposit < curr_line->line_length) 2766192830Sed { 2767192830Sed tposit++; 2768192830Sed *d_word2 = *d_word3; 2769192830Sed d_word2++; 2770192830Sed d_word3++; 2771192830Sed } 2772192830Sed curr_line->line_length -= difference; 2773192830Sed *d_word2 = (char) NULL; 2774192830Sed draw_line(scr_vert, scr_horz,point,position,curr_line->line_length); 2775192830Sed d_char[0] = tmp_char[0]; 2776192830Sed d_char[1] = tmp_char[1]; 2777192830Sed d_char[2] = tmp_char[2]; 2778192830Sed text_changes = TRUE; 2779192830Sed formatted = FALSE; 2780192830Sed} 2781192830Sed 2782192830Sedvoid 2783192830Sedundel_word() /* undelete last deleted word */ 2784192830Sed{ 2785192830Sed int temp; 2786192830Sed int tposit; 2787192830Sed unsigned char *tmp_old_ptr; 2788192830Sed unsigned char *tmp_space; 2789192830Sed unsigned char *tmp_ptr; 2790192830Sed unsigned char *d_word_ptr; 2791192830Sed 2792192830Sed /* 2793192830Sed | resize line to handle undeleted word 2794192830Sed */ 2795192830Sed if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5) 2796192830Sed point = resiz_line(d_wrd_len, curr_line, position); 2797192830Sed tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len); 2798192830Sed d_word_ptr = d_word; 2799192830Sed temp = 1; 2800192830Sed /* 2801192830Sed | copy d_word contents into temp space 2802192830Sed */ 2803192830Sed while (temp <= d_wrd_len) 2804192830Sed { 2805192830Sed temp++; 2806192830Sed *tmp_ptr = *d_word_ptr; 2807192830Sed tmp_ptr++; 2808192830Sed d_word_ptr++; 2809192830Sed } 2810192830Sed tmp_old_ptr = point; 2811192830Sed tposit = position; 2812192830Sed /* 2813192830Sed | copy contents of line from curent position to eol into 2814192830Sed | temp space 2815192830Sed */ 2816192830Sed while (tposit < curr_line->line_length) 2817192830Sed { 2818192830Sed temp++; 2819192830Sed tposit++; 2820192830Sed *tmp_ptr = *tmp_old_ptr; 2821192830Sed tmp_ptr++; 2822192830Sed tmp_old_ptr++; 2823192830Sed } 2824192830Sed curr_line->line_length += d_wrd_len; 2825192830Sed tmp_old_ptr = point; 2826192830Sed *tmp_ptr = (char) NULL; 2827192830Sed tmp_ptr = tmp_space; 2828192830Sed tposit = 1; 2829192830Sed /* 2830192830Sed | now copy contents from temp space back to original line 2831192830Sed */ 2832192830Sed while (tposit < temp) 2833192830Sed { 2834192830Sed tposit++; 2835192830Sed *tmp_old_ptr = *tmp_ptr; 2836192830Sed tmp_ptr++; 2837192830Sed tmp_old_ptr++; 2838192830Sed } 2839192830Sed *tmp_old_ptr = (char) NULL; 2840192830Sed free(tmp_space); 2841192830Sed draw_line(scr_vert, scr_horz, point, position, curr_line->line_length); 2842192830Sed} 2843192830Sed 2844192830Sedvoid 2845192830Seddel_line() /* delete from cursor to end of line */ 2846192830Sed{ 2847192830Sed unsigned char *dl1; 2848192830Sed unsigned char *dl2; 2849192830Sed int tposit; 2850192830Sed 2851192830Sed if (d_line != NULL) 2852192830Sed free(d_line); 2853192830Sed d_line = malloc(curr_line->line_length); 2854192830Sed dl1 = d_line; 2855192830Sed dl2 = point; 2856192830Sed tposit = position; 2857192830Sed while (tposit < curr_line->line_length) 2858192830Sed { 2859192830Sed *dl1 = *dl2; 2860192830Sed dl1++; 2861192830Sed dl2++; 2862192830Sed tposit++; 2863192830Sed } 2864192830Sed dlt_line->line_length = 1 + tposit - position; 2865192830Sed *dl1 = (char) NULL; 2866192830Sed *point = (char) NULL; 2867192830Sed curr_line->line_length = position; 2868192830Sed wclrtoeol(text_win); 2869192830Sed if (curr_line->next_line != NULL) 2870192830Sed { 2871192830Sed right(FALSE); 2872192830Sed delete(FALSE); 2873192830Sed } 2874192830Sed text_changes = TRUE; 2875192830Sed} 2876192830Sed 2877192830Sedvoid 2878192830Sedundel_line() /* undelete last deleted line */ 2879192830Sed{ 2880192830Sed unsigned char *ud1; 2881192830Sed unsigned char *ud2; 2882192830Sed int tposit; 2883192830Sed 2884192830Sed if (dlt_line->line_length == 0) 2885192830Sed return; 2886192830Sed 2887192830Sed insert_line(TRUE); 2888192830Sed left(TRUE); 2889192830Sed point = resiz_line(dlt_line->line_length, curr_line, position); 2890192830Sed curr_line->line_length += dlt_line->line_length - 1; 2891192830Sed ud1 = point; 2892192830Sed ud2 = d_line; 2893192830Sed tposit = 1; 2894192830Sed while (tposit < dlt_line->line_length) 2895192830Sed { 2896192830Sed tposit++; 2897192830Sed *ud1 = *ud2; 2898192830Sed ud1++; 2899192830Sed ud2++; 2900192830Sed } 2901192830Sed *ud1 = (char) NULL; 2902192830Sed draw_line(scr_vert, scr_horz,point,position,curr_line->line_length); 2903192830Sed} 2904192830Sed 2905192830Sedvoid 2906192830Sedadv_word() /* advance to next word */ 2907192830Sed{ 2908192830Sedwhile ((position < curr_line->line_length) && ((*point != 32) && (*point != 9))) 2909192830Sed right(TRUE); 2910192830Sedwhile ((position < curr_line->line_length) && ((*point == 32) || (*point == 9))) 2911192830Sed right(TRUE); 2912192830Sed} 2913192830Sed 2914192830Sedvoid 2915192830Sedmove_rel(direction, lines) /* move relative to current line */ 2916192830Sedchar *direction; 2917192830Sedint lines; 2918192830Sed{ 2919192830Sed int i; 2920192830Sed char *tmp; 2921192830Sed 2922192830Sed if (*direction == 'u') 2923192830Sed { 2924192830Sed scr_pos = 0; 2925192830Sed while (position > 1) 2926192830Sed left(TRUE); 2927192830Sed for (i = 0; i < lines; i++) 2928192830Sed { 2929192830Sed up(); 2930192830Sed } 2931192830Sed if ((last_line > 5) && ( scr_vert < 4)) 2932192830Sed { 2933192830Sed tmp = point; 2934192830Sed tmp_line = curr_line; 2935192830Sed for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++) 2936192830Sed { 2937192830Sed up(); 2938192830Sed } 2939192830Sed scr_vert = scr_vert + i; 2940192830Sed curr_line = tmp_line; 2941192830Sed point = tmp; 2942192830Sed scanline(point); 2943192830Sed } 2944192830Sed } 2945192830Sed else 2946192830Sed { 2947192830Sed if ((position != 1) && (curr_line->next_line != NULL)) 2948192830Sed { 2949192830Sed nextline(); 2950192830Sed scr_pos = scr_horz = 0; 2951192830Sed if (horiz_offset) 2952192830Sed { 2953192830Sed horiz_offset = 0; 2954192830Sed midscreen(scr_vert, point); 2955192830Sed } 2956192830Sed } 2957192830Sed else 2958192830Sed adv_line(); 2959192830Sed for (i = 1; i < lines; i++) 2960192830Sed { 2961192830Sed down(); 2962192830Sed } 2963192830Sed if ((last_line > 10) && (scr_vert > (last_line - 5))) 2964192830Sed { 2965192830Sed tmp = point; 2966192830Sed tmp_line = curr_line; 2967192830Sed for (i=0; (i<5) && (curr_line->next_line != NULL); i++) 2968192830Sed { 2969192830Sed down(); 2970192830Sed } 2971192830Sed scr_vert = scr_vert - i; 2972192830Sed curr_line = tmp_line; 2973192830Sed point = tmp; 2974192830Sed scanline(point); 2975192830Sed } 2976192830Sed } 2977192830Sed wmove(text_win, scr_vert, (scr_horz - horiz_offset)); 2978192830Sed} 2979192830Sed 2980192830Sedvoid 2981192830Sedeol() /* go to end of line */ 2982192830Sed{ 2983192830Sed if (position < curr_line->line_length) 2984192830Sed { 2985192830Sed while (position < curr_line->line_length) 2986192830Sed right(TRUE); 2987192830Sed } 2988192830Sed else if (curr_line->next_line != NULL) 2989192830Sed { 2990192830Sed right(TRUE); 2991192830Sed while (position < curr_line->line_length) 2992192830Sed right(TRUE); 2993192830Sed } 2994192830Sed} 2995192830Sed 2996192830Sedvoid 2997192830Sedbol() /* move to beginning of line */ 2998192830Sed{ 2999192830Sed if (point != curr_line->line) 3000192830Sed { 3001192830Sed while (point != curr_line->line) 3002192830Sed left(TRUE); 3003192830Sed } 3004192830Sed else if (curr_line->prev_line != NULL) 3005192830Sed { 3006192830Sed scr_pos = 0; 3007192830Sed up(); 3008192830Sed } 3009192830Sed} 3010192830Sed 3011192830Sedvoid 3012192830Sedadv_line() /* advance to beginning of next line */ 3013192830Sed{ 3014192830Sed if ((point != curr_line->line) || (scr_pos > 0)) 3015192830Sed { 3016192830Sed while (position < curr_line->line_length) 3017192830Sed right(TRUE); 3018192830Sed right(TRUE); 3019192830Sed } 3020192830Sed else if (curr_line->next_line != NULL) 3021192830Sed { 3022192830Sed scr_pos = 0; 3023192830Sed down(); 3024192830Sed } 3025192830Sed} 3026192830Sed 3027192830Sedvoid 3028192830Sedsh_command(string) /* execute shell command */ 3029192830Sedchar *string; /* string containing user command */ 3030192830Sed{ 3031192830Sed char *temp_point; 3032192830Sed char *last_slash; 3033192830Sed char *path; /* directory path to executable */ 3034192830Sed int parent; /* zero if child, child's pid if parent */ 3035192830Sed int value; 3036192830Sed int return_val; 3037192830Sed struct text *line_holder; 3038192830Sed 3039192830Sed if (restrict_mode()) 3040192830Sed { 3041192830Sed return; 3042192830Sed } 3043192830Sed 3044192830Sed if (!(path = getenv("SHELL"))) 3045192830Sed path = "/bin/sh"; 3046192830Sed last_slash = temp_point = path; 3047192830Sed while (*temp_point != (char) NULL) 3048192830Sed { 3049192830Sed if (*temp_point == '/') 3050192830Sed last_slash = ++temp_point; 3051192830Sed else 3052192830Sed temp_point++; 3053192830Sed } 3054192830Sed 3055192830Sed /* 3056192830Sed | if in_pipe is true, then output of the shell operation will be 3057192830Sed | read by the editor, and curses doesn't need to be turned off 3058192830Sed */ 3059192830Sed 3060192830Sed if (!in_pipe) 3061192830Sed { 3062192830Sed keypad(com_win, FALSE); 3063192830Sed keypad(text_win, FALSE); 3064192830Sed echo(); 3065192830Sed nl(); 3066192830Sed noraw(); 3067192830Sed resetty(); 3068192830Sed 3069192830Sed#ifndef NCURSE 3070192830Sed endwin(); 3071192830Sed#endif 3072192830Sed } 3073192830Sed 3074192830Sed if (in_pipe) 3075192830Sed { 3076192830Sed pipe(pipe_in); /* create a pipe */ 3077192830Sed parent = fork(); 3078192830Sed if (!parent) /* if the child */ 3079192830Sed { 3080192830Sed/* 3081192830Sed | child process which will fork and exec shell command (if shell output is 3082192830Sed | to be read by editor) 3083192830Sed */ 3084192830Sed in_pipe = FALSE; 3085192830Sed/* 3086192830Sed | redirect stdout to pipe 3087192830Sed */ 3088192830Sed temp_stdout = dup(1); 3089192830Sed close(1); 3090192830Sed dup(pipe_in[1]); 3091192830Sed/* 3092192830Sed | redirect stderr to pipe 3093192830Sed */ 3094192830Sed temp_stderr = dup(2); 3095192830Sed close(2); 3096192830Sed dup(pipe_in[1]); 3097192830Sed close(pipe_in[1]); 3098192830Sed /* 3099192830Sed | child will now continue down 'if (!in_pipe)' 3100192830Sed | path below 3101192830Sed */ 3102192830Sed } 3103192830Sed else /* if the parent */ 3104192830Sed { 3105192830Sed/* 3106192830Sed | prepare editor to read from the pipe 3107192830Sed */ 3108192830Sed signal(SIGCHLD, SIG_IGN); 3109192830Sed line_holder = curr_line; 3110192830Sed tmp_vert = scr_vert; 3111192830Sed close(pipe_in[1]); 3112192830Sed get_fd = pipe_in[0]; 3113192830Sed get_file(""); 3114192830Sed close(pipe_in[0]); 3115192830Sed scr_vert = tmp_vert; 3116192830Sed scr_horz = scr_pos = 0; 3117192830Sed position = 1; 3118192830Sed curr_line = line_holder; 3119192830Sed point = curr_line->line; 3120192830Sed out_pipe = FALSE; 3121192830Sed signal(SIGCHLD, SIG_DFL); 3122192830Sed/* 3123192830Sed | since flag "in_pipe" is still TRUE, the path which waits for the child 3124192830Sed | process to die will be avoided. 3125192830Sed | (the pipe is closed, no more output can be expected) 3126192830Sed */ 3127192830Sed } 3128192830Sed } 3129192830Sed if (!in_pipe) 3130192830Sed { 3131192830Sed signal(SIGINT, SIG_IGN); 3132192830Sed if (out_pipe) 3133192830Sed { 3134192830Sed pipe(pipe_out); 3135192830Sed } 3136192830Sed/* 3137192830Sed | fork process which will exec command 3138192830Sed */ 3139192830Sed parent = fork(); 3140192830Sed if (!parent) /* if the child */ 3141192830Sed { 3142192830Sed if (shell_fork) 3143192830Sed putchar('\n'); 3144192830Sed if (out_pipe) 3145192830Sed { 3146192830Sed/* 3147192830Sed | prepare the child process (soon to exec a shell command) to read from the 3148192830Sed | pipe (which will be output from the editor's buffer) 3149192830Sed */ 3150192830Sed close(0); 3151192830Sed dup(pipe_out[0]); 3152192830Sed close(pipe_out[0]); 3153192830Sed close(pipe_out[1]); 3154192830Sed } 3155192830Sed for (value = 1; value < 24; value++) 3156192830Sed signal(value, SIG_DFL); 3157192856Sed execl(path, last_slash, "-c", string, (char *)NULL); 3158192856Sed errx(1, exec_err_msg, path); 3159192830Sed } 3160192830Sed else /* if the parent */ 3161192830Sed { 3162192830Sed if (out_pipe) 3163192830Sed { 3164192830Sed/* 3165192830Sed | output the contents of the buffer to the pipe (to be read by the 3166192830Sed | process forked and exec'd above as stdin) 3167192830Sed */ 3168192830Sed close(pipe_out[0]); 3169192830Sed line_holder = first_line; 3170192830Sed while (line_holder != NULL) 3171192830Sed { 3172192830Sed write(pipe_out[1], line_holder->line, (line_holder->line_length-1)); 3173192830Sed write(pipe_out[1], "\n", 1); 3174192830Sed line_holder = line_holder->next_line; 3175192830Sed } 3176192830Sed close(pipe_out[1]); 3177192830Sed out_pipe = FALSE; 3178192830Sed } 3179192830Sed do 3180192830Sed { 3181192830Sed return_val = wait((int *) 0); 3182192830Sed } 3183192830Sed while ((return_val != parent) && (return_val != -1)); 3184192830Sed/* 3185192830Sed | if this process is actually the child of the editor, exit. Here's how it 3186192830Sed | works: 3187192830Sed | The editor forks a process. If output must be sent to the command to be 3188192830Sed | exec'd another process is forked, and that process (the child's child) 3189192830Sed | will exec the command. In this case, "shell_fork" will be FALSE. If no 3190192830Sed | output is to be performed to the shell command, "shell_fork" will be TRUE. 3191192830Sed | If this is the editor process, shell_fork will be true, otherwise this is 3192192830Sed | the child of the edit process. 3193192830Sed */ 3194192830Sed if (!shell_fork) 3195192830Sed exit(0); 3196192830Sed } 3197192830Sed signal(SIGINT, edit_abort); 3198192830Sed } 3199192830Sed if (shell_fork) 3200192830Sed { 3201192856Sed printf("%s", continue_msg); 3202192830Sed fflush(stdout); 3203192830Sed while ((in = getchar()) != '\n') 3204192830Sed ; 3205192830Sed } 3206192830Sed 3207192830Sed if (!in_pipe) 3208192830Sed { 3209192830Sed fixterm(); 3210192830Sed noecho(); 3211192830Sed nonl(); 3212192830Sed raw(); 3213192830Sed keypad(text_win, TRUE); 3214192830Sed keypad(com_win, TRUE); 3215192830Sed if (info_window) 3216192830Sed clearok(info_win, TRUE); 3217192830Sed } 3218192830Sed 3219192830Sed redraw(); 3220192830Sed} 3221192830Sed 3222192830Sedvoid 3223192830Sedset_up_term() /* set up the terminal for operating with ae */ 3224192830Sed{ 3225192830Sed if (!curses_initialized) 3226192830Sed { 3227192830Sed initscr(); 3228192830Sed savetty(); 3229192830Sed noecho(); 3230192830Sed raw(); 3231192830Sed nonl(); 3232192830Sed curses_initialized = TRUE; 3233192830Sed } 3234192830Sed 3235192830Sed if (((LINES > 15) && (COLS >= 80)) && info_window) 3236192830Sed last_line = LINES - 8; 3237192830Sed else 3238192830Sed { 3239192830Sed info_window = FALSE; 3240192830Sed last_line = LINES - 2; 3241192830Sed } 3242192830Sed 3243192830Sed idlok(stdscr, TRUE); 3244192830Sed com_win = newwin(1, COLS, (LINES - 1), 0); 3245192830Sed keypad(com_win, TRUE); 3246192830Sed idlok(com_win, TRUE); 3247192830Sed wrefresh(com_win); 3248192830Sed if (!info_window) 3249192830Sed text_win = newwin((LINES - 1), COLS, 0, 0); 3250192830Sed else 3251192830Sed text_win = newwin((LINES - 7), COLS, 6, 0); 3252192830Sed keypad(text_win, TRUE); 3253192830Sed idlok(text_win, TRUE); 3254192830Sed wrefresh(text_win); 3255192830Sed help_win = newwin((LINES - 1), COLS, 0, 0); 3256192830Sed keypad(help_win, TRUE); 3257192830Sed idlok(help_win, TRUE); 3258192830Sed if (info_window) 3259192830Sed { 3260192830Sed info_type = CONTROL_KEYS; 3261192856Sed info_win = newwin(5, COLS, 0, 0); 3262192830Sed werase(info_win); 3263192830Sed paint_info_win(); 3264192856Sed count_win = newwin(1, COLS, 5, 0); 3265192856Sed leaveok(count_win, TRUE); 3266192856Sed wrefresh(count_win); 3267192830Sed } 3268192830Sed 3269192830Sed last_col = COLS - 1; 3270192830Sed local_LINES = LINES; 3271192830Sed local_COLS = COLS; 3272192830Sed 3273192830Sed#ifdef NCURSE 3274192830Sed if (ee_chinese) 3275192830Sed nc_setattrib(A_NC_BIG5); 3276192830Sed#endif /* NCURSE */ 3277192830Sed 3278192830Sed} 3279192830Sed 3280192830Sedvoid 3281192830Sedresize_check() 3282192830Sed{ 3283192830Sed if ((LINES == local_LINES) && (COLS == local_COLS)) 3284192830Sed return; 3285192830Sed 3286192830Sed if (info_window) 3287192830Sed delwin(info_win); 3288192830Sed delwin(text_win); 3289192830Sed delwin(com_win); 3290192830Sed delwin(help_win); 3291192856Sed delwin(count_win); 3292192830Sed set_up_term(); 3293192830Sed redraw(); 3294192830Sed wrefresh(text_win); 3295192830Sed} 3296192830Sed 3297192830Sedstatic char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 "; 3298192830Sed 3299192830Sedint 3300192830Sedmenu_op(menu_list) 3301192830Sedstruct menu_entries menu_list[]; 3302192830Sed{ 3303192830Sed WINDOW *temp_win; 3304192830Sed int max_width, max_height; 3305192830Sed int x_off, y_off; 3306192830Sed int counter; 3307192830Sed int length; 3308192830Sed int input; 3309192856Sed int temp = 0; 3310192830Sed int list_size; 3311192830Sed int top_offset; /* offset from top where menu items start */ 3312192830Sed int vert_pos; /* vertical position */ 3313192830Sed int vert_size; /* vertical size for menu list item display */ 3314192830Sed int off_start = 1; /* offset from start of menu items to start display */ 3315192830Sed 3316192830Sed 3317192830Sed /* 3318192830Sed | determine number and width of menu items 3319192830Sed */ 3320192830Sed 3321192830Sed list_size = 1; 3322192830Sed while (menu_list[list_size + 1].item_string != NULL) 3323192830Sed list_size++; 3324192830Sed max_width = 0; 3325192830Sed for (counter = 0; counter <= list_size; counter++) 3326192830Sed { 3327192830Sed if ((length = strlen(menu_list[counter].item_string)) > max_width) 3328192830Sed max_width = length; 3329192830Sed } 3330192830Sed max_width += 3; 3331192830Sed max_width = max(max_width, strlen(menu_cancel_msg)); 3332192830Sed max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str))); 3333192830Sed max_width += 6; 3334192830Sed 3335192830Sed /* 3336192830Sed | make sure that window is large enough to handle menu 3337192830Sed | if not, print error message and return to calling function 3338192830Sed */ 3339192830Sed 3340192830Sed if (max_width > COLS) 3341192830Sed { 3342192830Sed wmove(com_win, 0, 0); 3343192830Sed werase(com_win); 3344192830Sed wprintw(com_win, menu_too_lrg_msg); 3345192830Sed wrefresh(com_win); 3346192830Sed clear_com_win = TRUE; 3347192830Sed return(0); 3348192830Sed } 3349192830Sed 3350192830Sed top_offset = 0; 3351192830Sed 3352192830Sed if (list_size > LINES) 3353192830Sed { 3354192830Sed max_height = LINES; 3355192830Sed if (max_height > 11) 3356192830Sed vert_size = max_height - 8; 3357192830Sed else 3358192830Sed vert_size = max_height; 3359192830Sed } 3360192830Sed else 3361192830Sed { 3362192830Sed vert_size = list_size; 3363192830Sed max_height = list_size; 3364192830Sed } 3365192830Sed 3366192830Sed if (LINES >= (vert_size + 8)) 3367192830Sed { 3368192830Sed if (menu_list[0].argument != MENU_WARN) 3369192830Sed max_height = vert_size + 8; 3370192830Sed else 3371192830Sed max_height = vert_size + 7; 3372192830Sed top_offset = 4; 3373192830Sed } 3374192830Sed x_off = (COLS - max_width) / 2; 3375192830Sed y_off = (LINES - max_height - 1) / 2; 3376192830Sed temp_win = newwin(max_height, max_width, y_off, x_off); 3377192830Sed keypad(temp_win, TRUE); 3378192830Sed 3379192830Sed paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size); 3380192830Sed 3381192830Sed counter = 1; 3382192830Sed vert_pos = 0; 3383192830Sed do 3384192830Sed { 3385192830Sed if (off_start > 2) 3386192830Sed wmove(temp_win, (1 + counter + top_offset - off_start), 3); 3387192830Sed else 3388192830Sed wmove(temp_win, (counter + top_offset - off_start), 3); 3389192830Sed 3390192830Sed wrefresh(temp_win); 3391192856Sed input = wgetch(temp_win); 3392192830Sed 3393192830Sed if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) || 3394192830Sed ((input >= '0') && (input <= '9'))) 3395192830Sed { 3396192830Sed if ((tolower(input) >= 'a') && (tolower(input) <= 'z')) 3397192830Sed { 3398192830Sed temp = 1 + tolower(input) - 'a'; 3399192830Sed } 3400192830Sed else if ((input >= '0') && (input <= '9')) 3401192830Sed { 3402192830Sed temp = (2 + 'z' - 'a') + (input - '0'); 3403192830Sed } 3404192830Sed 3405192830Sed if (temp <= list_size) 3406192830Sed { 3407192830Sed input = '\n'; 3408192830Sed counter = temp; 3409192830Sed } 3410192830Sed } 3411192830Sed else 3412192830Sed { 3413192830Sed switch (input) 3414192830Sed { 3415192830Sed case ' ': /* space */ 3416192830Sed case '\004': /* ^d, down */ 3417192830Sed case KEY_RIGHT: 3418192830Sed case KEY_DOWN: 3419192830Sed counter++; 3420192830Sed if (counter > list_size) 3421192830Sed counter = 1; 3422192830Sed break; 3423192830Sed case '\010': /* ^h, backspace*/ 3424192830Sed case '\025': /* ^u, up */ 3425192830Sed case 127: /* ^?, delete */ 3426192830Sed case KEY_BACKSPACE: 3427192830Sed case KEY_LEFT: 3428192830Sed case KEY_UP: 3429192830Sed counter--; 3430192830Sed if (counter == 0) 3431192830Sed counter = list_size; 3432192830Sed break; 3433192830Sed case '\033': /* escape key */ 3434192830Sed if (menu_list[0].argument != MENU_WARN) 3435192830Sed counter = 0; 3436192830Sed break; 3437192830Sed case '\014': /* ^l */ 3438192830Sed case '\022': /* ^r, redraw */ 3439192830Sed paint_menu(menu_list, max_width, max_height, 3440192830Sed list_size, top_offset, temp_win, 3441192830Sed off_start, vert_size); 3442192830Sed break; 3443192830Sed default: 3444192830Sed break; 3445192830Sed } 3446192830Sed } 3447192830Sed 3448192830Sed if (((list_size - off_start) >= (vert_size - 1)) && 3449192830Sed (counter > (off_start + vert_size - 3)) && 3450192830Sed (off_start > 1)) 3451192830Sed { 3452192830Sed if (counter == list_size) 3453192830Sed off_start = (list_size - vert_size) + 2; 3454192830Sed else 3455192830Sed off_start++; 3456192830Sed 3457192830Sed paint_menu(menu_list, max_width, max_height, 3458192830Sed list_size, top_offset, temp_win, off_start, 3459192830Sed vert_size); 3460192830Sed } 3461192830Sed else if ((list_size != vert_size) && 3462192830Sed (counter > (off_start + vert_size - 2))) 3463192830Sed { 3464192830Sed if (counter == list_size) 3465192830Sed off_start = 2 + (list_size - vert_size); 3466192830Sed else if (off_start == 1) 3467192830Sed off_start = 3; 3468192830Sed else 3469192830Sed off_start++; 3470192830Sed 3471192830Sed paint_menu(menu_list, max_width, max_height, 3472192830Sed list_size, top_offset, temp_win, off_start, 3473192830Sed vert_size); 3474192830Sed } 3475192830Sed else if (counter < off_start) 3476192830Sed { 3477192830Sed if (counter <= 2) 3478192830Sed off_start = 1; 3479192830Sed else 3480192830Sed off_start = counter; 3481192830Sed 3482192830Sed paint_menu(menu_list, max_width, max_height, 3483192830Sed list_size, top_offset, temp_win, off_start, 3484192830Sed vert_size); 3485192830Sed } 3486192830Sed } 3487192830Sed while ((input != '\r') && (input != '\n') && (counter != 0)); 3488192830Sed 3489192830Sed werase(temp_win); 3490192830Sed wrefresh(temp_win); 3491192830Sed delwin(temp_win); 3492192830Sed 3493192830Sed if ((menu_list[counter].procedure != NULL) || 3494192830Sed (menu_list[counter].iprocedure != NULL) || 3495192830Sed (menu_list[counter].nprocedure != NULL)) 3496192830Sed { 3497192830Sed if (menu_list[counter].argument != -1) 3498192830Sed (*menu_list[counter].iprocedure)(menu_list[counter].argument); 3499192830Sed else if (menu_list[counter].ptr_argument != NULL) 3500192830Sed (*menu_list[counter].procedure)(menu_list[counter].ptr_argument); 3501192830Sed else 3502192830Sed (*menu_list[counter].nprocedure)(); 3503192830Sed } 3504192830Sed 3505192830Sed if (info_window) 3506192830Sed paint_info_win(); 3507192830Sed redraw(); 3508192830Sed 3509192830Sed return(counter); 3510192830Sed} 3511192830Sed 3512192830Sedvoid 3513192830Sedpaint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win, 3514192830Sed off_start, vert_size) 3515192830Sedstruct menu_entries menu_list[]; 3516192830Sedint max_width, max_height, list_size, top_offset; 3517192830SedWINDOW *menu_win; 3518192830Sedint off_start, vert_size; 3519192830Sed{ 3520192830Sed int counter, temp_int; 3521192830Sed 3522192830Sed werase(menu_win); 3523192830Sed 3524192830Sed /* 3525192830Sed | output top and bottom portions of menu box only if window 3526192830Sed | large enough 3527192830Sed */ 3528192830Sed 3529192830Sed if (max_height > vert_size) 3530192830Sed { 3531192830Sed wmove(menu_win, 1, 1); 3532192830Sed if (!nohighlight) 3533192830Sed wstandout(menu_win); 3534192830Sed waddch(menu_win, '+'); 3535192830Sed for (counter = 0; counter < (max_width - 4); counter++) 3536192830Sed waddch(menu_win, '-'); 3537192830Sed waddch(menu_win, '+'); 3538192830Sed 3539192830Sed wmove(menu_win, (max_height - 2), 1); 3540192830Sed waddch(menu_win, '+'); 3541192830Sed for (counter = 0; counter < (max_width - 4); counter++) 3542192830Sed waddch(menu_win, '-'); 3543192830Sed waddch(menu_win, '+'); 3544192830Sed wstandend(menu_win); 3545192830Sed wmove(menu_win, 2, 3); 3546192830Sed waddstr(menu_win, menu_list[0].item_string); 3547192830Sed wmove(menu_win, (max_height - 3), 3); 3548192830Sed if (menu_list[0].argument != MENU_WARN) 3549192830Sed waddstr(menu_win, menu_cancel_msg); 3550192830Sed } 3551192830Sed if (!nohighlight) 3552192830Sed wstandout(menu_win); 3553192830Sed 3554192830Sed for (counter = 0; counter < (vert_size + top_offset); counter++) 3555192830Sed { 3556192830Sed if (top_offset == 4) 3557192830Sed { 3558192830Sed temp_int = counter + 2; 3559192830Sed } 3560192830Sed else 3561192830Sed temp_int = counter; 3562192830Sed 3563192830Sed wmove(menu_win, temp_int, 1); 3564192830Sed waddch(menu_win, '|'); 3565192830Sed wmove(menu_win, temp_int, (max_width - 2)); 3566192830Sed waddch(menu_win, '|'); 3567192830Sed } 3568192830Sed wstandend(menu_win); 3569192830Sed 3570192830Sed if (list_size > vert_size) 3571192830Sed { 3572192830Sed if (off_start >= 3) 3573192830Sed { 3574192830Sed temp_int = 1; 3575192830Sed wmove(menu_win, top_offset, 3); 3576192830Sed waddstr(menu_win, more_above_str); 3577192830Sed } 3578192830Sed else 3579192830Sed temp_int = 0; 3580192830Sed 3581192830Sed for (counter = off_start; 3582192830Sed ((temp_int + counter - off_start) < (vert_size - 1)); 3583192830Sed counter++) 3584192830Sed { 3585192830Sed wmove(menu_win, (top_offset + temp_int + 3586192830Sed (counter - off_start)), 3); 3587192830Sed if (list_size > 1) 3588192830Sed wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]); 3589192830Sed waddstr(menu_win, menu_list[counter].item_string); 3590192830Sed } 3591192830Sed 3592192830Sed wmove(menu_win, (top_offset + (vert_size - 1)), 3); 3593192830Sed 3594192830Sed if (counter == list_size) 3595192830Sed { 3596192830Sed if (list_size > 1) 3597192830Sed wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]); 3598192830Sed wprintw(menu_win, menu_list[counter].item_string); 3599192830Sed } 3600192830Sed else 3601192830Sed wprintw(menu_win, more_below_str); 3602192830Sed } 3603192830Sed else 3604192830Sed { 3605192830Sed for (counter = 1; counter <= list_size; counter++) 3606192830Sed { 3607192830Sed wmove(menu_win, (top_offset + counter - 1), 3); 3608192830Sed if (list_size > 1) 3609192830Sed wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]); 3610192830Sed waddstr(menu_win, menu_list[counter].item_string); 3611192830Sed } 3612192830Sed } 3613192830Sed} 3614192830Sed 3615192830Sedvoid 3616192830Sedhelp() 3617192830Sed{ 3618192830Sed int counter; 3619192830Sed 3620192830Sed werase(help_win); 3621192830Sed clearok(help_win, TRUE); 3622192830Sed for (counter = 0; counter < 22; counter++) 3623192830Sed { 3624192830Sed wmove(help_win, counter, 0); 3625192830Sed waddstr(help_win, (emacs_keys_mode) ? 3626192830Sed emacs_help_text[counter] : help_text[counter]); 3627192830Sed } 3628192830Sed wrefresh(help_win); 3629192830Sed werase(com_win); 3630192830Sed wmove(com_win, 0, 0); 3631192830Sed wprintw(com_win, press_any_key_msg); 3632192830Sed wrefresh(com_win); 3633192830Sed counter = wgetch(com_win); 3634192830Sed werase(com_win); 3635192830Sed wmove(com_win, 0, 0); 3636192830Sed werase(help_win); 3637192830Sed wrefresh(help_win); 3638192830Sed wrefresh(com_win); 3639192830Sed redraw(); 3640192830Sed} 3641192830Sed 3642192830Sedvoid 3643192830Sedpaint_info_win() 3644192830Sed{ 3645192830Sed int counter; 3646192830Sed 3647192830Sed if (!info_window) 3648192830Sed return; 3649192830Sed 3650192830Sed werase(info_win); 3651192830Sed for (counter = 0; counter < 5; counter++) 3652192830Sed { 3653192830Sed wmove(info_win, counter, 0); 3654192830Sed wclrtoeol(info_win); 3655192830Sed if (info_type == CONTROL_KEYS) 3656192830Sed waddstr(info_win, (emacs_keys_mode) ? 3657192830Sed emacs_control_keys[counter] : control_keys[counter]); 3658192830Sed else if (info_type == COMMANDS) 3659192830Sed waddstr(info_win, command_strings[counter]); 3660192830Sed } 3661192830Sed wrefresh(info_win); 3662192830Sed} 3663192830Sed 3664192830Sedvoid 3665192830Sedno_info_window() 3666192830Sed{ 3667192830Sed if (!info_window) 3668192830Sed return; 3669192830Sed delwin(info_win); 3670192830Sed delwin(text_win); 3671192830Sed info_window = FALSE; 3672192830Sed last_line = LINES - 2; 3673192830Sed text_win = newwin((LINES - 1), COLS, 0, 0); 3674192830Sed keypad(text_win, TRUE); 3675192830Sed idlok(text_win, TRUE); 3676192830Sed clearok(text_win, TRUE); 3677192830Sed midscreen(scr_vert, point); 3678192830Sed wrefresh(text_win); 3679192830Sed clear_com_win = TRUE; 3680192830Sed} 3681192830Sed 3682192830Sedvoid 3683192830Sedcreate_info_window() 3684192830Sed{ 3685192830Sed if (info_window) 3686192830Sed return; 3687192830Sed last_line = LINES - 8; 3688192830Sed delwin(text_win); 3689192830Sed text_win = newwin((LINES - 7), COLS, 6, 0); 3690192830Sed keypad(text_win, TRUE); 3691192830Sed idlok(text_win, TRUE); 3692192830Sed werase(text_win); 3693192830Sed info_window = TRUE; 3694192856Sed info_win = newwin(5, COLS, 0, 0); 3695192830Sed werase(info_win); 3696192830Sed info_type = CONTROL_KEYS; 3697192830Sed midscreen(min(scr_vert, last_line), point); 3698192830Sed clearok(info_win, TRUE); 3699192830Sed paint_info_win(); 3700192856Sed count_win = newwin(1, COLS, 5, 0); 3701192856Sed leaveok(count_win, TRUE); 3702192856Sed wrefresh(count_win); 3703192830Sed wrefresh(text_win); 3704192830Sed clear_com_win = TRUE; 3705192830Sed} 3706192830Sed 3707192830Sedint 3708192830Sedfile_op(arg) 3709192830Sedint arg; 3710192830Sed{ 3711192830Sed char *string; 3712192830Sed int flag; 3713192830Sed 3714192830Sed if (restrict_mode()) 3715192830Sed { 3716192830Sed return(0); 3717192830Sed } 3718192830Sed 3719192830Sed if (arg == READ_FILE) 3720192830Sed { 3721192830Sed string = get_string(file_read_prompt_str, TRUE); 3722192830Sed recv_file = TRUE; 3723192830Sed tmp_file = resolve_name(string); 3724192830Sed check_fp(); 3725192830Sed if (tmp_file != string) 3726192830Sed free(tmp_file); 3727192830Sed free(string); 3728192830Sed } 3729192830Sed else if (arg == WRITE_FILE) 3730192830Sed { 3731192830Sed string = get_string(file_write_prompt_str, TRUE); 3732192830Sed tmp_file = resolve_name(string); 3733192856Sed write_file(tmp_file, 1); 3734192830Sed if (tmp_file != string) 3735192830Sed free(tmp_file); 3736192830Sed free(string); 3737192830Sed } 3738192830Sed else if (arg == SAVE_FILE) 3739192830Sed { 3740192830Sed /* 3741192830Sed | changes made here should be reflected in finish() 3742192830Sed */ 3743192830Sed 3744192830Sed if (in_file_name) 3745192830Sed flag = TRUE; 3746192830Sed else 3747192830Sed flag = FALSE; 3748192830Sed 3749192830Sed string = in_file_name; 3750192830Sed if ((string == NULL) || (*string == (char) NULL)) 3751192830Sed string = get_string(save_file_name_prompt, TRUE); 3752192830Sed if ((string == NULL) || (*string == (char) NULL)) 3753192830Sed { 3754192830Sed wmove(com_win, 0, 0); 3755192830Sed wprintw(com_win, file_not_saved_msg); 3756192830Sed wclrtoeol(com_win); 3757192830Sed wrefresh(com_win); 3758192830Sed clear_com_win = TRUE; 3759192830Sed return(0); 3760192830Sed } 3761192830Sed if (!flag) 3762192830Sed { 3763192830Sed tmp_file = resolve_name(string); 3764192830Sed if (tmp_file != string) 3765192830Sed { 3766192830Sed free(string); 3767192830Sed string = tmp_file; 3768192830Sed } 3769192830Sed } 3770192856Sed if (write_file(string, 1)) 3771192830Sed { 3772192830Sed in_file_name = string; 3773192830Sed text_changes = FALSE; 3774192830Sed } 3775192830Sed else if (!flag) 3776192830Sed free(string); 3777192830Sed } 3778192830Sed return(0); 3779192830Sed} 3780192830Sed 3781192830Sedvoid 3782192830Sedshell_op() 3783192830Sed{ 3784192830Sed char *string; 3785192830Sed 3786192830Sed if (((string = get_string(shell_prompt, TRUE)) != NULL) && 3787192830Sed (*string != (char) NULL)) 3788192830Sed { 3789192830Sed sh_command(string); 3790192830Sed free(string); 3791192830Sed } 3792192830Sed} 3793192830Sed 3794192830Sedvoid 3795192830Sedleave_op() 3796192830Sed{ 3797192830Sed if (text_changes) 3798192830Sed { 3799192830Sed menu_op(leave_menu); 3800192830Sed } 3801192830Sed else 3802192830Sed quit(TRUE); 3803192830Sed} 3804192830Sed 3805192830Sedvoid 3806192830Sedredraw() 3807192830Sed{ 3808192830Sed if (info_window) 3809192830Sed { 3810192830Sed clearok(info_win, TRUE); 3811192830Sed paint_info_win(); 3812192830Sed } 3813192830Sed else 3814192830Sed clearok(text_win, TRUE); 3815192830Sed midscreen(scr_vert, point); 3816192830Sed} 3817192830Sed 3818192830Sed/* 3819192830Sed | The following routines will "format" a paragraph (as defined by a 3820192830Sed | block of text with blank lines before and after the block). 3821192830Sed */ 3822192830Sed 3823192830Sedint 3824192830SedBlank_Line(test_line) /* test if line has any non-space characters */ 3825192830Sedstruct text *test_line; 3826192830Sed{ 3827192830Sed unsigned char *line; 3828192830Sed int length; 3829192830Sed 3830192830Sed if (test_line == NULL) 3831192830Sed return(TRUE); 3832192830Sed 3833192830Sed length = 1; 3834192830Sed line = test_line->line; 3835192830Sed 3836192830Sed /* 3837192830Sed | To handle troff/nroff documents, consider a line with a 3838192830Sed | period ('.') in the first column to be blank. To handle mail 3839192830Sed | messages with included text, consider a line with a '>' blank. 3840192830Sed */ 3841192830Sed 3842192830Sed if ((*line == '.') || (*line == '>')) 3843192830Sed return(TRUE); 3844192830Sed 3845192830Sed while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length)) 3846192830Sed { 3847192830Sed length++; 3848192830Sed line++; 3849192830Sed } 3850192830Sed if (length != test_line->line_length) 3851192830Sed return(FALSE); 3852192830Sed else 3853192830Sed return(TRUE); 3854192830Sed} 3855192830Sed 3856192830Sedvoid 3857192830SedFormat() /* format the paragraph according to set margins */ 3858192830Sed{ 3859192830Sed int string_count; 3860192830Sed int offset; 3861192830Sed int temp_case; 3862192830Sed int status; 3863192830Sed int tmp_af; 3864192830Sed int counter; 3865192830Sed unsigned char *line; 3866192830Sed unsigned char *tmp_srchstr; 3867192830Sed unsigned char *temp1, *temp2; 3868192830Sed unsigned char *temp_dword; 3869192830Sed unsigned char temp_d_char[3]; 3870192830Sed 3871192830Sed temp_d_char[0] = d_char[0]; 3872192830Sed temp_d_char[1] = d_char[1]; 3873192830Sed temp_d_char[2] = d_char[2]; 3874192830Sed 3875192830Sed/* 3876192830Sed | if observ_margins is not set, or the current line is blank, 3877192830Sed | do not format the current paragraph 3878192830Sed */ 3879192830Sed 3880192830Sed if ((!observ_margins) || (Blank_Line(curr_line))) 3881192830Sed return; 3882192830Sed 3883192830Sed/* 3884192830Sed | save the currently set flags, and clear them 3885192830Sed */ 3886192830Sed 3887192830Sed wmove(com_win, 0, 0); 3888192830Sed wclrtoeol(com_win); 3889192830Sed wprintw(com_win, formatting_msg); 3890192830Sed wrefresh(com_win); 3891192830Sed 3892192830Sed/* 3893192830Sed | get current position in paragraph, so after formatting, the cursor 3894192830Sed | will be in the same relative position 3895192830Sed */ 3896192830Sed 3897192830Sed tmp_af = auto_format; 3898192830Sed auto_format = FALSE; 3899192830Sed offset = position; 3900192830Sed if (position != 1) 3901192830Sed prev_word(); 3902192830Sed temp_dword = d_word; 3903192830Sed d_word = NULL; 3904192830Sed temp_case = case_sen; 3905192830Sed case_sen = TRUE; 3906192830Sed tmp_srchstr = srch_str; 3907192830Sed temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position); 3908192830Sed if ((*point == ' ') || (*point == '\t')) 3909192830Sed adv_word(); 3910192830Sed offset -= position; 3911192830Sed counter = position; 3912192830Sed line = temp1 = point; 3913192830Sed while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length)) 3914192830Sed { 3915192830Sed *temp2 = *temp1; 3916192830Sed temp2++; 3917192830Sed temp1++; 3918192830Sed counter++; 3919192830Sed } 3920192830Sed *temp2 = (char) NULL; 3921192830Sed if (position != 1) 3922192830Sed bol(); 3923192830Sed while (!Blank_Line(curr_line->prev_line)) 3924192830Sed bol(); 3925192830Sed string_count = 0; 3926192830Sed status = TRUE; 3927192830Sed while ((line != point) && (status)) 3928192830Sed { 3929192830Sed status = search(FALSE); 3930192830Sed string_count++; 3931192830Sed } 3932192830Sed 3933192830Sed wmove(com_win, 0, 0); 3934192830Sed wclrtoeol(com_win); 3935192830Sed wprintw(com_win, formatting_msg); 3936192830Sed wrefresh(com_win); 3937192830Sed 3938192830Sed/* 3939192830Sed | now get back to the start of the paragraph to start formatting 3940192830Sed */ 3941192830Sed 3942192830Sed if (position != 1) 3943192830Sed bol(); 3944192830Sed while (!Blank_Line(curr_line->prev_line)) 3945192830Sed bol(); 3946192830Sed 3947192830Sed observ_margins = FALSE; 3948192830Sed 3949192830Sed/* 3950192830Sed | Start going through lines, putting spaces at end of lines if they do 3951192830Sed | not already exist. Append lines together to get one long line, and 3952192830Sed | eliminate spacing at begin of lines. 3953192830Sed */ 3954192830Sed 3955192830Sed while (!Blank_Line(curr_line->next_line)) 3956192830Sed { 3957192830Sed eol(); 3958192830Sed left(TRUE); 3959192830Sed if (*point != ' ') 3960192830Sed { 3961192830Sed right(TRUE); 3962192830Sed insert(' '); 3963192830Sed } 3964192830Sed else 3965192830Sed right(TRUE); 3966192830Sed del_char(); 3967192830Sed if ((*point == ' ') || (*point == '\t')) 3968192830Sed del_word(); 3969192830Sed } 3970192830Sed 3971192830Sed/* 3972192830Sed | Now there is one long line. Eliminate extra spaces within the line 3973192830Sed | after the first word (so as not to blow away any indenting the user 3974192830Sed | may have put in). 3975192830Sed */ 3976192830Sed 3977192830Sed bol(); 3978192830Sed adv_word(); 3979192830Sed while (position < curr_line->line_length) 3980192830Sed { 3981192830Sed if ((*point == ' ') && (*(point + 1) == ' ')) 3982192830Sed del_char(); 3983192830Sed else 3984192830Sed right(TRUE); 3985192830Sed } 3986192830Sed 3987192830Sed/* 3988192830Sed | Now make sure there are two spaces after a '.'. 3989192830Sed */ 3990192830Sed 3991192830Sed bol(); 3992192830Sed while (position < curr_line->line_length) 3993192830Sed { 3994192830Sed if ((*point == '.') && (*(point + 1) == ' ')) 3995192830Sed { 3996192830Sed right(TRUE); 3997192830Sed insert(' '); 3998192830Sed insert(' '); 3999192830Sed while (*point == ' ') 4000192830Sed del_char(); 4001192830Sed } 4002192830Sed right(TRUE); 4003192830Sed } 4004192830Sed 4005192830Sed observ_margins = TRUE; 4006192830Sed bol(); 4007192830Sed 4008192830Sed wmove(com_win, 0, 0); 4009192830Sed wclrtoeol(com_win); 4010192830Sed wprintw(com_win, formatting_msg); 4011192830Sed wrefresh(com_win); 4012192830Sed 4013192830Sed/* 4014192830Sed | create lines between margins 4015192830Sed */ 4016192830Sed 4017192830Sed while (position < curr_line->line_length) 4018192830Sed { 4019192830Sed while ((scr_pos < right_margin) && (position < curr_line->line_length)) 4020192830Sed right(TRUE); 4021192830Sed if (position < curr_line->line_length) 4022192830Sed { 4023192830Sed prev_word(); 4024192830Sed if (position == 1) 4025192830Sed adv_word(); 4026192830Sed insert_line(TRUE); 4027192830Sed } 4028192830Sed } 4029192830Sed 4030192830Sed/* 4031192830Sed | go back to begin of paragraph, put cursor back to original position 4032192830Sed */ 4033192830Sed 4034192830Sed bol(); 4035192830Sed while (!Blank_Line(curr_line->prev_line)) 4036192830Sed bol(); 4037192830Sed 4038192830Sed/* 4039192830Sed | find word cursor was in 4040192830Sed */ 4041192830Sed 4042192830Sed while ((status) && (string_count > 0)) 4043192830Sed { 4044192830Sed search(FALSE); 4045192830Sed string_count--; 4046192830Sed } 4047192830Sed 4048192830Sed/* 4049192830Sed | offset the cursor to where it was before from the start of the word 4050192830Sed */ 4051192830Sed 4052192830Sed while (offset > 0) 4053192830Sed { 4054192830Sed offset--; 4055192830Sed right(TRUE); 4056192830Sed } 4057192830Sed 4058192830Sed/* 4059192830Sed | reset flags and strings to what they were before formatting 4060192830Sed */ 4061192830Sed 4062192830Sed if (d_word != NULL) 4063192830Sed free(d_word); 4064192830Sed d_word = temp_dword; 4065192830Sed case_sen = temp_case; 4066192830Sed free(srch_str); 4067192830Sed srch_str = tmp_srchstr; 4068192830Sed d_char[0] = temp_d_char[0]; 4069192830Sed d_char[1] = temp_d_char[1]; 4070192830Sed d_char[2] = temp_d_char[2]; 4071192830Sed auto_format = tmp_af; 4072192830Sed 4073192830Sed midscreen(scr_vert, point); 4074192830Sed werase(com_win); 4075192830Sed wrefresh(com_win); 4076192830Sed} 4077192830Sed 4078192830Sedunsigned char *init_name[3] = { 4079192856Sed "/usr/share/misc/init.ee", 4080192830Sed NULL, 4081192830Sed ".init.ee" 4082192830Sed }; 4083192830Sed 4084192830Sedvoid 4085192830Sedee_init() /* check for init file and read it if it exists */ 4086192830Sed{ 4087192830Sed FILE *init_file; 4088192830Sed unsigned char *string; 4089192830Sed unsigned char *str1; 4090192830Sed unsigned char *str2; 4091192830Sed char *home; 4092192830Sed int counter; 4093192830Sed int temp_int; 4094192830Sed 4095192830Sed string = getenv("HOME"); 4096192856Sed if (!string) 4097192856Sed string = "/root"; /* Set to reasonable default so we don't crash */ 4098192830Sed str1 = home = malloc(strlen(string)+10); 4099192830Sed strcpy(home, string); 4100192830Sed strcat(home, "/.init.ee"); 4101192830Sed init_name[1] = home; 4102192830Sed string = malloc(512); 4103192830Sed 4104192830Sed for (counter = 0; counter < 3; counter++) 4105192830Sed { 4106192830Sed if (!(access(init_name[counter], 4))) 4107192830Sed { 4108192830Sed init_file = fopen(init_name[counter], "r"); 4109192830Sed while ((str2 = fgets(string, 512, init_file)) != NULL) 4110192830Sed { 4111192830Sed str1 = str2 = string; 4112192830Sed while (*str2 != '\n') 4113192830Sed str2++; 4114192830Sed *str2 = (char) NULL; 4115192830Sed 4116192830Sed if (unique_test(string, init_strings) != 1) 4117192830Sed continue; 4118192830Sed 4119192830Sed if (compare(str1, CASE, FALSE)) 4120192830Sed case_sen = TRUE; 4121192830Sed else if (compare(str1, NOCASE, FALSE)) 4122192830Sed case_sen = FALSE; 4123192830Sed else if (compare(str1, EXPAND, FALSE)) 4124192830Sed expand_tabs = TRUE; 4125192830Sed else if (compare(str1, NOEXPAND, FALSE)) 4126192830Sed expand_tabs = FALSE; 4127192830Sed else if (compare(str1, INFO, FALSE)) 4128192830Sed info_window = TRUE; 4129192830Sed else if (compare(str1, NOINFO, FALSE)) 4130192830Sed info_window = FALSE; 4131192830Sed else if (compare(str1, MARGINS, FALSE)) 4132192830Sed observ_margins = TRUE; 4133192830Sed else if (compare(str1, NOMARGINS, FALSE)) 4134192830Sed observ_margins = FALSE; 4135192830Sed else if (compare(str1, AUTOFORMAT, FALSE)) 4136192830Sed { 4137192830Sed auto_format = TRUE; 4138192830Sed observ_margins = TRUE; 4139192830Sed } 4140192830Sed else if (compare(str1, NOAUTOFORMAT, FALSE)) 4141192830Sed auto_format = FALSE; 4142192830Sed else if (compare(str1, Echo, FALSE)) 4143192830Sed { 4144192830Sed str1 = next_word(str1); 4145192830Sed if (*str1 != (char) NULL) 4146192830Sed echo_string(str1); 4147192830Sed } 4148192830Sed else if (compare(str1, PRINTCOMMAND, FALSE)) 4149192830Sed { 4150192830Sed str1 = next_word(str1); 4151192830Sed print_command = malloc(strlen(str1)+1); 4152192830Sed strcpy(print_command, str1); 4153192830Sed } 4154192830Sed else if (compare(str1, RIGHTMARGIN, FALSE)) 4155192830Sed { 4156192830Sed str1 = next_word(str1); 4157192830Sed if ((*str1 >= '0') && (*str1 <= '9')) 4158192830Sed { 4159192830Sed temp_int = atoi(str1); 4160192830Sed if (temp_int > 0) 4161192830Sed right_margin = temp_int; 4162192830Sed } 4163192830Sed } 4164192830Sed else if (compare(str1, HIGHLIGHT, FALSE)) 4165192830Sed nohighlight = FALSE; 4166192830Sed else if (compare(str1, NOHIGHLIGHT, FALSE)) 4167192830Sed nohighlight = TRUE; 4168192830Sed else if (compare(str1, EIGHTBIT, FALSE)) 4169192830Sed eightbit = TRUE; 4170192830Sed else if (compare(str1, NOEIGHTBIT, FALSE)) 4171192830Sed { 4172192830Sed eightbit = FALSE; 4173192830Sed ee_chinese = FALSE; 4174192830Sed } 4175192830Sed else if (compare(str1, EMACS_string, FALSE)) 4176192830Sed emacs_keys_mode = TRUE; 4177192830Sed else if (compare(str1, NOEMACS_string, FALSE)) 4178192830Sed emacs_keys_mode = FALSE; 4179192830Sed else if (compare(str1, chinese_cmd, FALSE)) 4180192830Sed { 4181192830Sed ee_chinese = TRUE; 4182192830Sed eightbit = TRUE; 4183192830Sed } 4184192830Sed else if (compare(str1, nochinese_cmd, FALSE)) 4185192830Sed ee_chinese = FALSE; 4186192830Sed } 4187192830Sed fclose(init_file); 4188192830Sed } 4189192830Sed } 4190192830Sed free(string); 4191192830Sed free(home); 4192192830Sed 4193192830Sed string = getenv("LANG"); 4194192830Sed if (string != NULL) 4195192830Sed { 4196192830Sed if (strcmp(string, "zh_TW.big5") == 0) 4197192830Sed { 4198192830Sed ee_chinese = TRUE; 4199192830Sed eightbit = TRUE; 4200192830Sed } 4201192830Sed } 4202192830Sed} 4203192830Sed 4204192830Sed/* 4205192830Sed | Save current configuration to .init.ee file in the current directory. 4206192830Sed */ 4207192830Sed 4208192830Sedvoid 4209192830Seddump_ee_conf() 4210192830Sed{ 4211192830Sed FILE *init_file; 4212192830Sed FILE *old_init_file = NULL; 4213192830Sed char *file_name = ".init.ee"; 4214192830Sed char *home_dir = "~/.init.ee"; 4215192830Sed char buffer[512]; 4216192830Sed struct stat buf; 4217192830Sed char *string; 4218192830Sed int length; 4219192830Sed int option = 0; 4220192830Sed 4221192830Sed if (restrict_mode()) 4222192830Sed { 4223192830Sed return; 4224192830Sed } 4225192830Sed 4226192830Sed option = menu_op(config_dump_menu); 4227192830Sed 4228192830Sed werase(com_win); 4229192830Sed wmove(com_win, 0, 0); 4230192830Sed 4231192830Sed if (option == 0) 4232192830Sed { 4233192830Sed wprintw(com_win, conf_not_saved_msg); 4234192830Sed wrefresh(com_win); 4235192830Sed return; 4236192830Sed } 4237192830Sed else if (option == 2) 4238192830Sed file_name = resolve_name(home_dir); 4239192830Sed 4240192830Sed /* 4241192830Sed | If a .init.ee file exists, move it to .init.ee.old. 4242192830Sed */ 4243192830Sed 4244192830Sed if (stat(file_name, &buf) != -1) 4245192830Sed { 4246192830Sed sprintf(buffer, "%s.old", file_name); 4247192830Sed unlink(buffer); 4248192830Sed link(file_name, buffer); 4249192830Sed unlink(file_name); 4250192830Sed old_init_file = fopen(buffer, "r"); 4251192830Sed } 4252192830Sed 4253192830Sed init_file = fopen(file_name, "w"); 4254192830Sed if (init_file == NULL) 4255192830Sed { 4256192830Sed wprintw(com_win, conf_dump_err_msg); 4257192830Sed wrefresh(com_win); 4258192830Sed return; 4259192830Sed } 4260192830Sed 4261192830Sed if (old_init_file != NULL) 4262192830Sed { 4263192830Sed /* 4264192830Sed | Copy non-configuration info into new .init.ee file. 4265192830Sed */ 4266192830Sed while ((string = fgets(buffer, 512, old_init_file)) != NULL) 4267192830Sed { 4268192830Sed length = strlen(string); 4269192830Sed string[length - 1] = (char) NULL; 4270192830Sed 4271192830Sed if (unique_test(string, init_strings) == 1) 4272192830Sed { 4273192830Sed if (compare(string, Echo, FALSE)) 4274192830Sed { 4275192830Sed fprintf(init_file, "%s\n", string); 4276192830Sed } 4277192830Sed } 4278192830Sed else 4279192830Sed fprintf(init_file, "%s\n", string); 4280192830Sed } 4281192830Sed 4282192830Sed fclose(old_init_file); 4283192830Sed } 4284192830Sed 4285192830Sed fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE); 4286192830Sed fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND); 4287192830Sed fprintf(init_file, "%s\n", info_window ? INFO : NOINFO ); 4288192830Sed fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS ); 4289192830Sed fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT ); 4290192830Sed fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command); 4291192830Sed fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin); 4292192830Sed fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT ); 4293192830Sed fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT ); 4294192830Sed fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string ); 4295192830Sed fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd ); 4296192830Sed 4297192830Sed fclose(init_file); 4298192830Sed 4299192830Sed wprintw(com_win, conf_dump_success_msg, file_name); 4300192830Sed wrefresh(com_win); 4301192830Sed 4302192830Sed if ((option == 2) && (file_name != home_dir)) 4303192830Sed { 4304192830Sed free(file_name); 4305192830Sed } 4306192830Sed} 4307192830Sed 4308192830Sedvoid 4309192830Sedecho_string(string) /* echo the given string */ 4310192830Sedchar *string; 4311192830Sed{ 4312192830Sed char *temp; 4313192830Sed int Counter; 4314192830Sed 4315192830Sed temp = string; 4316192830Sed while (*temp != (char) NULL) 4317192830Sed { 4318192830Sed if (*temp == '\\') 4319192830Sed { 4320192830Sed temp++; 4321192830Sed if (*temp == 'n') 4322192830Sed putchar('\n'); 4323192830Sed else if (*temp == 't') 4324192830Sed putchar('\t'); 4325192830Sed else if (*temp == 'b') 4326192830Sed putchar('\b'); 4327192830Sed else if (*temp == 'r') 4328192830Sed putchar('\r'); 4329192830Sed else if (*temp == 'f') 4330192830Sed putchar('\f'); 4331192830Sed else if ((*temp == 'e') || (*temp == 'E')) 4332192830Sed putchar('\033'); /* escape */ 4333192830Sed else if (*temp == '\\') 4334192830Sed putchar('\\'); 4335192830Sed else if (*temp == '\'') 4336192830Sed putchar('\''); 4337192830Sed else if ((*temp >= '0') && (*temp <= '9')) 4338192830Sed { 4339192830Sed Counter = 0; 4340192830Sed while ((*temp >= '0') && (*temp <= '9')) 4341192830Sed { 4342192830Sed Counter = (8 * Counter) + (*temp - '0'); 4343192830Sed temp++; 4344192830Sed } 4345192830Sed putchar(Counter); 4346192830Sed temp--; 4347192830Sed } 4348192830Sed temp++; 4349192830Sed } 4350192830Sed else 4351192830Sed { 4352192830Sed putchar(*temp); 4353192830Sed temp++; 4354192830Sed } 4355192830Sed } 4356192830Sed 4357192830Sed fflush(stdout); 4358192830Sed} 4359192830Sed 4360192830Sedvoid 4361192830Sedspell_op() /* check spelling of words in the editor */ 4362192830Sed{ 4363192830Sed if (restrict_mode()) 4364192830Sed { 4365192830Sed return; 4366192830Sed } 4367192830Sed top(); /* go to top of file */ 4368192830Sed insert_line(FALSE); /* create two blank lines */ 4369192830Sed insert_line(FALSE); 4370192830Sed top(); 4371192830Sed command(shell_echo_msg); 4372192830Sed adv_line(); 4373192830Sed wmove(com_win, 0, 0); 4374192830Sed wprintw(com_win, spell_in_prog_msg); 4375192830Sed wrefresh(com_win); 4376192830Sed command("<>!spell"); /* send contents of buffer to command 'spell' 4377192830Sed and read the results back into the editor */ 4378192830Sed} 4379192830Sed 4380192830Sedvoid 4381192830Sedispell_op() 4382192830Sed{ 4383192856Sed char template[128], *name; 4384192830Sed char string[256]; 4385192856Sed int fd; 4386192830Sed 4387192830Sed if (restrict_mode()) 4388192830Sed { 4389192830Sed return; 4390192830Sed } 4391192856Sed (void)sprintf(template, "/tmp/ee.XXXXXXXX"); 4392192856Sed name = mktemp(&template[0]); 4393192856Sed fd = open(name, O_CREAT | O_EXCL | O_RDWR, 0600); 4394192856Sed if (fd < 0) { 4395192856Sed wmove(com_win, 0, 0); 4396192856Sed wprintw(com_win, create_file_fail_msg, name); 4397192856Sed wrefresh(com_win); 4398192856Sed return; 4399192856Sed } 4400192856Sed close(fd); 4401192856Sed if (write_file(name, 0)) 4402192830Sed { 4403192830Sed sprintf(string, "ispell %s", name); 4404192830Sed sh_command(string); 4405192830Sed delete_text(); 4406192830Sed tmp_file = name; 4407192830Sed recv_file = TRUE; 4408192830Sed check_fp(); 4409192830Sed unlink(name); 4410192830Sed } 4411192830Sed} 4412192830Sed 4413192830Sedint 4414192830Sedfirst_word_len(test_line) 4415192830Sedstruct text *test_line; 4416192830Sed{ 4417192830Sed int counter; 4418192830Sed unsigned char *pnt; 4419192830Sed 4420192830Sed if (test_line == NULL) 4421192830Sed return(0); 4422192830Sed 4423192830Sed pnt = test_line->line; 4424192830Sed if ((pnt == NULL) || (*pnt == (char) NULL) || 4425192830Sed (*pnt == '.') || (*pnt == '>')) 4426192830Sed return(0); 4427192830Sed 4428192830Sed if ((*pnt == ' ') || (*pnt == '\t')) 4429192830Sed { 4430192830Sed pnt = next_word(pnt); 4431192830Sed } 4432192830Sed 4433192830Sed if (*pnt == (char) NULL) 4434192830Sed return(0); 4435192830Sed 4436192830Sed counter = 0; 4437192830Sed while ((*pnt != (char) NULL) && ((*pnt != ' ') && (*pnt != '\t'))) 4438192830Sed { 4439192830Sed pnt++; 4440192830Sed counter++; 4441192830Sed } 4442192830Sed while ((*pnt != (char) NULL) && ((*pnt == ' ') || (*pnt == '\t'))) 4443192830Sed { 4444192830Sed pnt++; 4445192830Sed counter++; 4446192830Sed } 4447192830Sed return(counter); 4448192830Sed} 4449192830Sed 4450192830Sedvoid 4451192830SedAuto_Format() /* format the paragraph according to set margins */ 4452192830Sed{ 4453192830Sed int string_count; 4454192830Sed int offset; 4455192830Sed int temp_case; 4456192830Sed int word_len; 4457192830Sed int temp_dwl; 4458192830Sed int tmp_d_line_length; 4459192830Sed int leave_loop = FALSE; 4460192830Sed int status; 4461192830Sed int counter; 4462192830Sed char not_blank; 4463192830Sed unsigned char *line; 4464192830Sed unsigned char *tmp_srchstr; 4465192830Sed unsigned char *temp1, *temp2; 4466192830Sed unsigned char *temp_dword; 4467192830Sed unsigned char temp_d_char[3]; 4468192830Sed unsigned char *tmp_d_line; 4469192830Sed 4470192830Sed 4471192830Sed temp_d_char[0] = d_char[0]; 4472192830Sed temp_d_char[1] = d_char[1]; 4473192830Sed temp_d_char[2] = d_char[2]; 4474192830Sed 4475192830Sed/* 4476192830Sed | if observ_margins is not set, or the current line is blank, 4477192830Sed | do not format the current paragraph 4478192830Sed */ 4479192830Sed 4480192830Sed if ((!observ_margins) || (Blank_Line(curr_line))) 4481192830Sed return; 4482192830Sed 4483192830Sed/* 4484192830Sed | get current position in paragraph, so after formatting, the cursor 4485192830Sed | will be in the same relative position 4486192830Sed */ 4487192830Sed 4488192830Sed tmp_d_line = d_line; 4489192830Sed tmp_d_line_length = dlt_line->line_length; 4490192830Sed d_line = NULL; 4491192830Sed auto_format = FALSE; 4492192830Sed offset = position; 4493192830Sed if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == (char) NULL))) 4494192830Sed prev_word(); 4495192830Sed temp_dword = d_word; 4496192830Sed temp_dwl = d_wrd_len; 4497192830Sed d_wrd_len = 0; 4498192830Sed d_word = NULL; 4499192830Sed temp_case = case_sen; 4500192830Sed case_sen = TRUE; 4501192830Sed tmp_srchstr = srch_str; 4502192830Sed temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position); 4503192830Sed if ((*point == ' ') || (*point == '\t')) 4504192830Sed adv_word(); 4505192830Sed offset -= position; 4506192830Sed counter = position; 4507192830Sed line = temp1 = point; 4508192830Sed while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length)) 4509192830Sed { 4510192830Sed *temp2 = *temp1; 4511192830Sed temp2++; 4512192830Sed temp1++; 4513192830Sed counter++; 4514192830Sed } 4515192830Sed *temp2 = (char) NULL; 4516192830Sed if (position != 1) 4517192830Sed bol(); 4518192830Sed while (!Blank_Line(curr_line->prev_line)) 4519192830Sed bol(); 4520192830Sed string_count = 0; 4521192830Sed status = TRUE; 4522192830Sed while ((line != point) && (status)) 4523192830Sed { 4524192830Sed status = search(FALSE); 4525192830Sed string_count++; 4526192830Sed } 4527192830Sed 4528192830Sed/* 4529192830Sed | now get back to the start of the paragraph to start checking 4530192830Sed */ 4531192830Sed 4532192830Sed if (position != 1) 4533192830Sed bol(); 4534192830Sed while (!Blank_Line(curr_line->prev_line)) 4535192830Sed bol(); 4536192830Sed 4537192830Sed/* 4538192830Sed | Start going through lines, putting spaces at end of lines if they do 4539192830Sed | not already exist. Check line length, and move words to the next line 4540192830Sed | if they cross the margin. Then get words from the next line if they 4541192830Sed | will fit in before the margin. 4542192830Sed */ 4543192830Sed 4544192830Sed counter = 0; 4545192830Sed 4546192830Sed while (!leave_loop) 4547192830Sed { 4548192830Sed if (position != curr_line->line_length) 4549192830Sed eol(); 4550192830Sed left(TRUE); 4551192830Sed if (*point != ' ') 4552192830Sed { 4553192830Sed right(TRUE); 4554192830Sed insert(' '); 4555192830Sed } 4556192830Sed else 4557192830Sed right(TRUE); 4558192830Sed 4559192830Sed not_blank = FALSE; 4560192830Sed 4561192830Sed /* 4562192830Sed | fill line if first word on next line will fit 4563192830Sed | in the line without crossing the margin 4564192830Sed */ 4565192830Sed 4566192830Sed while ((curr_line->next_line != NULL) && 4567192830Sed ((word_len = first_word_len(curr_line->next_line)) > 0) 4568192830Sed && ((scr_pos + word_len) < right_margin)) 4569192830Sed { 4570192830Sed adv_line(); 4571192830Sed if ((*point == ' ') || (*point == '\t')) 4572192830Sed adv_word(); 4573192830Sed del_word(); 4574192830Sed if (position != 1) 4575192830Sed bol(); 4576192830Sed 4577192830Sed /* 4578192830Sed | We know this line was not blank before, so 4579192830Sed | make sure that it doesn't have one of the 4580192830Sed | leading characters that indicate the line 4581192830Sed | should not be modified. 4582192830Sed | 4583192830Sed | We also know that this character should not 4584192830Sed | be left as the first character of this line. 4585192830Sed */ 4586192830Sed 4587192830Sed if ((Blank_Line(curr_line)) && 4588192830Sed (curr_line->line[0] != '.') && 4589192830Sed (curr_line->line[0] != '>')) 4590192830Sed { 4591192830Sed del_line(); 4592192830Sed not_blank = FALSE; 4593192830Sed } 4594192830Sed else 4595192830Sed not_blank = TRUE; 4596192830Sed 4597192830Sed /* 4598192830Sed | go to end of previous line 4599192830Sed */ 4600192830Sed left(TRUE); 4601192830Sed undel_word(); 4602192830Sed eol(); 4603192830Sed /* 4604192830Sed | make sure there's a space at the end of the line 4605192830Sed */ 4606192830Sed left(TRUE); 4607192830Sed if (*point != ' ') 4608192830Sed { 4609192830Sed right(TRUE); 4610192830Sed insert(' '); 4611192830Sed } 4612192830Sed else 4613192830Sed right(TRUE); 4614192830Sed } 4615192830Sed 4616192830Sed /* 4617192830Sed | make sure line does not cross right margin 4618192830Sed */ 4619192830Sed 4620192830Sed while (right_margin <= scr_pos) 4621192830Sed { 4622192830Sed prev_word(); 4623192830Sed if (position != 1) 4624192830Sed { 4625192830Sed del_word(); 4626192830Sed if (Blank_Line(curr_line->next_line)) 4627192830Sed insert_line(TRUE); 4628192830Sed else 4629192830Sed adv_line(); 4630192830Sed if ((*point == ' ') || (*point == '\t')) 4631192830Sed adv_word(); 4632192830Sed undel_word(); 4633192830Sed not_blank = TRUE; 4634192830Sed if (position != 1) 4635192830Sed bol(); 4636192830Sed left(TRUE); 4637192830Sed } 4638192830Sed } 4639192830Sed 4640192830Sed if ((!Blank_Line(curr_line->next_line)) || (not_blank)) 4641192830Sed { 4642192830Sed adv_line(); 4643192830Sed counter++; 4644192830Sed } 4645192830Sed else 4646192830Sed leave_loop = TRUE; 4647192830Sed } 4648192830Sed 4649192830Sed/* 4650192830Sed | go back to begin of paragraph, put cursor back to original position 4651192830Sed */ 4652192830Sed 4653192830Sed if (position != 1) 4654192830Sed bol(); 4655192830Sed while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line))) 4656192830Sed bol(); 4657192830Sed 4658192830Sed/* 4659192830Sed | find word cursor was in 4660192830Sed */ 4661192830Sed 4662192830Sed status = TRUE; 4663192830Sed while ((status) && (string_count > 0)) 4664192830Sed { 4665192830Sed status = search(FALSE); 4666192830Sed string_count--; 4667192830Sed } 4668192830Sed 4669192830Sed/* 4670192830Sed | offset the cursor to where it was before from the start of the word 4671192830Sed */ 4672192830Sed 4673192830Sed while (offset > 0) 4674192830Sed { 4675192830Sed offset--; 4676192830Sed right(TRUE); 4677192830Sed } 4678192830Sed 4679192830Sed if ((string_count > 0) && (offset < 0)) 4680192830Sed { 4681192830Sed while (offset < 0) 4682192830Sed { 4683192830Sed offset++; 4684192830Sed left(TRUE); 4685192830Sed } 4686192830Sed } 4687192830Sed 4688192830Sed/* 4689192830Sed | reset flags and strings to what they were before formatting 4690192830Sed */ 4691192830Sed 4692192830Sed if (d_word != NULL) 4693192830Sed free(d_word); 4694192830Sed d_word = temp_dword; 4695192830Sed d_wrd_len = temp_dwl; 4696192830Sed case_sen = temp_case; 4697192830Sed free(srch_str); 4698192830Sed srch_str = tmp_srchstr; 4699192830Sed d_char[0] = temp_d_char[0]; 4700192830Sed d_char[1] = temp_d_char[1]; 4701192830Sed d_char[2] = temp_d_char[2]; 4702192830Sed auto_format = TRUE; 4703192830Sed dlt_line->line_length = tmp_d_line_length; 4704192830Sed d_line = tmp_d_line; 4705192830Sed 4706192830Sed formatted = TRUE; 4707192830Sed midscreen(scr_vert, point); 4708192830Sed} 4709192830Sed 4710192830Sedvoid 4711192830Sedmodes_op() 4712192830Sed{ 4713192830Sed int ret_value; 4714192830Sed int counter; 4715192830Sed char *string; 4716192830Sed 4717192830Sed do 4718192830Sed { 4719192830Sed sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1], 4720192830Sed (expand_tabs ? ON : OFF)); 4721192830Sed sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2], 4722192830Sed (case_sen ? ON : OFF)); 4723192830Sed sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3], 4724192830Sed (observ_margins ? ON : OFF)); 4725192830Sed sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4], 4726192830Sed (auto_format ? ON : OFF)); 4727192830Sed sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5], 4728192830Sed (eightbit ? ON : OFF)); 4729192830Sed sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6], 4730192830Sed (info_window ? ON : OFF)); 4731192830Sed sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7], 4732192830Sed (emacs_keys_mode ? ON : OFF)); 4733192830Sed sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8], 4734192830Sed right_margin); 4735192830Sed sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9], 4736192830Sed (ee_chinese ? ON : OFF)); 4737192830Sed 4738192830Sed ret_value = menu_op(modes_menu); 4739192830Sed 4740192830Sed switch (ret_value) 4741192830Sed { 4742192830Sed case 1: 4743192830Sed expand_tabs = !expand_tabs; 4744192830Sed break; 4745192830Sed case 2: 4746192830Sed case_sen = !case_sen; 4747192830Sed break; 4748192830Sed case 3: 4749192830Sed observ_margins = !observ_margins; 4750192830Sed break; 4751192830Sed case 4: 4752192830Sed auto_format = !auto_format; 4753192830Sed if (auto_format) 4754192830Sed observ_margins = TRUE; 4755192830Sed break; 4756192830Sed case 5: 4757192830Sed eightbit = !eightbit; 4758192830Sed if (!eightbit) 4759192830Sed ee_chinese = FALSE; 4760192830Sed#ifdef NCURSE 4761192830Sed if (ee_chinese) 4762192830Sed nc_setattrib(A_NC_BIG5); 4763192830Sed else 4764192830Sed nc_clearattrib(A_NC_BIG5); 4765192830Sed#endif /* NCURSE */ 4766192830Sed 4767192830Sed redraw(); 4768192830Sed wnoutrefresh(text_win); 4769192830Sed break; 4770192830Sed case 6: 4771192830Sed if (info_window) 4772192830Sed no_info_window(); 4773192830Sed else 4774192830Sed create_info_window(); 4775192830Sed break; 4776192830Sed case 7: 4777192830Sed emacs_keys_mode = !emacs_keys_mode; 4778192830Sed if (info_window) 4779192830Sed paint_info_win(); 4780192830Sed break; 4781192830Sed case 8: 4782192830Sed string = get_string(margin_prompt, TRUE); 4783192830Sed if (string != NULL) 4784192830Sed { 4785192830Sed counter = atoi(string); 4786192830Sed if (counter > 0) 4787192830Sed right_margin = counter; 4788192830Sed free(string); 4789192830Sed } 4790192830Sed break; 4791192830Sed case 9: 4792192830Sed ee_chinese = !ee_chinese; 4793192830Sed if (ee_chinese != FALSE) 4794192830Sed eightbit = TRUE; 4795192830Sed#ifdef NCURSE 4796192830Sed if (ee_chinese) 4797192830Sed nc_setattrib(A_NC_BIG5); 4798192830Sed else 4799192830Sed nc_clearattrib(A_NC_BIG5); 4800192830Sed#endif /* NCURSE */ 4801192830Sed redraw(); 4802192830Sed break; 4803192830Sed default: 4804192830Sed break; 4805192830Sed } 4806192830Sed } 4807192830Sed while (ret_value != 0); 4808192830Sed} 4809192830Sed 4810192830Sedchar * 4811192830Sedis_in_string(string, substring) /* a strchr() look-alike for systems without 4812192830Sed strchr() */ 4813192830Sedchar * string, *substring; 4814192830Sed{ 4815192830Sed char *full, *sub; 4816192830Sed 4817192830Sed for (sub = substring; (sub != NULL) && (*sub != (char)NULL); sub++) 4818192830Sed { 4819192830Sed for (full = string; (full != NULL) && (*full != (char)NULL); 4820192830Sed full++) 4821192830Sed { 4822192830Sed if (*sub == *full) 4823192830Sed return(full); 4824192830Sed } 4825192830Sed } 4826192830Sed return(NULL); 4827192830Sed} 4828192830Sed 4829192830Sed/* 4830192830Sed | handle names of the form "~/file", "~user/file", 4831192830Sed | "$HOME/foo", "~/$FOO", etc. 4832192830Sed */ 4833192830Sed 4834192830Sedchar * 4835192830Sedresolve_name(name) 4836192830Sedchar *name; 4837192830Sed{ 4838192830Sed char long_buffer[1024]; 4839192830Sed char short_buffer[128]; 4840192830Sed char *buffer; 4841192830Sed char *slash; 4842192830Sed char *tmp; 4843192830Sed char *start_of_var; 4844192830Sed int offset; 4845192830Sed int index; 4846192830Sed int counter; 4847192830Sed struct passwd *user; 4848192830Sed 4849192830Sed if (name[0] == '~') 4850192830Sed { 4851192830Sed if (name[1] == '/') 4852192830Sed { 4853192830Sed index = getuid(); 4854192830Sed user = (struct passwd *) getpwuid(index); 4855192830Sed slash = name + 1; 4856192830Sed } 4857192830Sed else 4858192830Sed { 4859192830Sed slash = strchr(name, '/'); 4860192830Sed if (slash == NULL) 4861192830Sed return(name); 4862192830Sed *slash = (char) NULL; 4863192830Sed user = (struct passwd *) getpwnam((name + 1)); 4864192830Sed *slash = '/'; 4865192830Sed } 4866192830Sed if (user == NULL) 4867192830Sed { 4868192830Sed return(name); 4869192830Sed } 4870192830Sed buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1); 4871192830Sed strcpy(buffer, user->pw_dir); 4872192830Sed strcat(buffer, slash); 4873192830Sed } 4874192830Sed else 4875192830Sed buffer = name; 4876192830Sed 4877192830Sed if (is_in_string(buffer, "$")) 4878192830Sed { 4879192830Sed tmp = buffer; 4880192830Sed index = 0; 4881192830Sed 4882192830Sed while ((*tmp != (char) NULL) && (index < 1024)) 4883192830Sed { 4884192830Sed 4885192830Sed while ((*tmp != (char) NULL) && (*tmp != '$') && 4886192830Sed (index < 1024)) 4887192830Sed { 4888192830Sed long_buffer[index] = *tmp; 4889192830Sed tmp++; 4890192830Sed index++; 4891192830Sed } 4892192830Sed 4893192830Sed if ((*tmp == '$') && (index < 1024)) 4894192830Sed { 4895192830Sed counter = 0; 4896192830Sed start_of_var = tmp; 4897192830Sed tmp++; 4898192830Sed if (*tmp == '{') /* } */ /* bracketed variable name */ 4899192830Sed { 4900192830Sed tmp++; /* { */ 4901192830Sed while ((*tmp != (char) NULL) && 4902192830Sed (*tmp != '}') && 4903192830Sed (counter < 128)) 4904192830Sed { 4905192830Sed short_buffer[counter] = *tmp; 4906192830Sed counter++; 4907192830Sed tmp++; 4908192830Sed } /* { */ 4909192830Sed if (*tmp == '}') 4910192830Sed tmp++; 4911192830Sed } 4912192830Sed else 4913192830Sed { 4914192830Sed while ((*tmp != (char) NULL) && 4915192830Sed (*tmp != '/') && 4916192830Sed (*tmp != '$') && 4917192830Sed (counter < 128)) 4918192830Sed { 4919192830Sed short_buffer[counter] = *tmp; 4920192830Sed counter++; 4921192830Sed tmp++; 4922192830Sed } 4923192830Sed } 4924192830Sed short_buffer[counter] = (char) NULL; 4925192830Sed if ((slash = getenv(short_buffer)) != NULL) 4926192830Sed { 4927192830Sed offset = strlen(slash); 4928192830Sed if ((offset + index) < 1024) 4929192830Sed strcpy(&long_buffer[index], slash); 4930192830Sed index += offset; 4931192830Sed } 4932192830Sed else 4933192830Sed { 4934192830Sed while ((start_of_var != tmp) && (index < 1024)) 4935192830Sed { 4936192830Sed long_buffer[index] = *start_of_var; 4937192830Sed start_of_var++; 4938192830Sed index++; 4939192830Sed } 4940192830Sed } 4941192830Sed } 4942192830Sed } 4943192830Sed 4944192830Sed if (index == 1024) 4945192830Sed return(buffer); 4946192830Sed else 4947192830Sed long_buffer[index] = (char) NULL; 4948192830Sed 4949192830Sed if (name != buffer) 4950192830Sed free(buffer); 4951192830Sed buffer = malloc(index + 1); 4952192830Sed strcpy(buffer, long_buffer); 4953192830Sed } 4954192830Sed 4955192830Sed return(buffer); 4956192830Sed} 4957192830Sed 4958192830Sedint 4959192830Sedrestrict_mode() 4960192830Sed{ 4961192830Sed if (!restricted) 4962192830Sed return(FALSE); 4963192830Sed 4964192830Sed wmove(com_win, 0, 0); 4965192830Sed wprintw(com_win, restricted_msg); 4966192830Sed wclrtoeol(com_win); 4967192830Sed wrefresh(com_win); 4968192830Sed clear_com_win = TRUE; 4969192830Sed return(TRUE); 4970192830Sed} 4971192830Sed 4972192830Sed/* 4973192830Sed | The following routine tests the input string against the list of 4974192830Sed | strings, to determine if the string is a unique match with one of the 4975192830Sed | valid values. 4976192830Sed */ 4977192830Sed 4978192830Sedint 4979192830Sedunique_test(string, list) 4980192830Sedchar *string; 4981192830Sedchar *list[]; 4982192830Sed{ 4983192830Sed int counter; 4984192830Sed int num_match; 4985192830Sed int result; 4986192830Sed 4987192830Sed num_match = 0; 4988192830Sed counter = 0; 4989192830Sed while (list[counter] != NULL) 4990192830Sed { 4991192830Sed result = compare(string, list[counter], FALSE); 4992192830Sed if (result) 4993192830Sed num_match++; 4994192830Sed counter++; 4995192830Sed } 4996192830Sed return(num_match); 4997192830Sed} 4998192830Sed 4999192856Sedvoid 5000192856Sedrenumber_lines(firstline, startnumber) 5001192856Sedstruct text *firstline; 5002192856Sedint startnumber; 5003192856Sed{ 5004192856Sed struct text *lineptr; 5005192856Sed int i; 5006192856Sed 5007192856Sed i = startnumber; 5008192856Sed for (lineptr = firstline; lineptr != NULL; lineptr = lineptr->next_line) 5009192856Sed lineptr->line_number = i++; 5010192856Sed} 5011192856Sed 5012192830Sed#ifndef NO_CATGETS 5013192830Sed/* 5014192830Sed | Get the catalog entry, and if it got it from the catalog, 5015192830Sed | make a copy, since the buffer will be overwritten by the 5016192830Sed | next call to catgets(). 5017192830Sed */ 5018192830Sed 5019192830Sedchar * 5020192830Sedcatgetlocal(number, string) 5021192830Sedint number; 5022192830Sedchar *string; 5023192830Sed{ 5024192830Sed char *temp1; 5025192830Sed char *temp2; 5026192830Sed 5027192830Sed temp1 = catgets(catalog, 1, number, string); 5028192830Sed if (temp1 != string) 5029192830Sed { 5030192830Sed temp2 = malloc(strlen(temp1) + 1); 5031192830Sed strcpy(temp2, temp1); 5032192830Sed temp1 = temp2; 5033192830Sed } 5034192830Sed return(temp1); 5035192830Sed} 5036192830Sed#endif /* NO_CATGETS */ 5037192830Sed 5038192830Sed/* 5039192830Sed | The following is to allow for using message catalogs which allow 5040192830Sed | the software to be 'localized', that is, to use different languages 5041192830Sed | all with the same binary. For more information, see your system 5042192830Sed | documentation, or the X/Open Internationalization Guide. 5043192830Sed */ 5044192830Sed 5045192830Sedvoid 5046192830Sedstrings_init() 5047192830Sed{ 5048192830Sed int counter; 5049192830Sed 5050192830Sed#ifndef NO_CATGETS 5051192830Sed setlocale(LC_ALL, ""); 5052192856Sed catalog = catopen("ee", NL_CAT_LOCALE); 5053192830Sed#endif /* NO_CATGETS */ 5054192830Sed 5055192830Sed modes_menu[0].item_string = catgetlocal( 1, "modes menu"); 5056192830Sed mode_strings[1] = catgetlocal( 2, "tabs to spaces "); 5057192830Sed mode_strings[2] = catgetlocal( 3, "case sensitive search"); 5058192830Sed mode_strings[3] = catgetlocal( 4, "margins observed "); 5059192830Sed mode_strings[4] = catgetlocal( 5, "auto-paragraph format"); 5060192830Sed mode_strings[5] = catgetlocal( 6, "eightbit characters "); 5061192830Sed mode_strings[6] = catgetlocal( 7, "info window "); 5062192830Sed mode_strings[8] = catgetlocal( 8, "right margin "); 5063192830Sed leave_menu[0].item_string = catgetlocal( 9, "leave menu"); 5064192830Sed leave_menu[1].item_string = catgetlocal( 10, "save changes"); 5065192830Sed leave_menu[2].item_string = catgetlocal( 11, "no save"); 5066192830Sed file_menu[0].item_string = catgetlocal( 12, "file menu"); 5067192830Sed file_menu[1].item_string = catgetlocal( 13, "read a file"); 5068192830Sed file_menu[2].item_string = catgetlocal( 14, "write a file"); 5069192830Sed file_menu[3].item_string = catgetlocal( 15, "save file"); 5070192830Sed file_menu[4].item_string = catgetlocal( 16, "print editor contents"); 5071192830Sed search_menu[0].item_string = catgetlocal( 17, "search menu"); 5072192830Sed search_menu[1].item_string = catgetlocal( 18, "search for ..."); 5073192830Sed search_menu[2].item_string = catgetlocal( 19, "search"); 5074192830Sed spell_menu[0].item_string = catgetlocal( 20, "spell menu"); 5075192830Sed spell_menu[1].item_string = catgetlocal( 21, "use 'spell'"); 5076192830Sed spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'"); 5077192830Sed misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu"); 5078192830Sed misc_menu[1].item_string = catgetlocal( 24, "format paragraph"); 5079192830Sed misc_menu[2].item_string = catgetlocal( 25, "shell command"); 5080192830Sed misc_menu[3].item_string = catgetlocal( 26, "check spelling"); 5081192830Sed main_menu[0].item_string = catgetlocal( 27, "main menu"); 5082192830Sed main_menu[1].item_string = catgetlocal( 28, "leave editor"); 5083192830Sed main_menu[2].item_string = catgetlocal( 29, "help"); 5084192830Sed main_menu[3].item_string = catgetlocal( 30, "file operations"); 5085192830Sed main_menu[4].item_string = catgetlocal( 31, "redraw screen"); 5086192830Sed main_menu[5].item_string = catgetlocal( 32, "settings"); 5087192830Sed main_menu[6].item_string = catgetlocal( 33, "search"); 5088192830Sed main_menu[7].item_string = catgetlocal( 34, "miscellaneous"); 5089192830Sed help_text[0] = catgetlocal( 35, "Control keys: "); 5090192830Sed help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right "); 5091192830Sed help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text "); 5092192830Sed help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up "); 5093192830Sed help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word "); 5094192830Sed help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word "); 5095192830Sed help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search "); 5096192830Sed help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line "); 5097192830Sed help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line "); 5098192856Sed help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee "); 5099192830Sed help_text[10] = catgetlocal( 45, " "); 5100192830Sed help_text[11] = catgetlocal( 46, "Commands: "); 5101192830Sed help_text[12] = catgetlocal( 47, "help : get this info file : print file name "); 5102192830Sed help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char "); 5103192830Sed help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search "); 5104192830Sed help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search "); 5105192830Sed help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell "); 5106192830Sed help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" "); 5107192830Sed help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs "); 5108192830Sed help_text[19] = catgetlocal( 54, " "); 5109192830Sed help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] "); 5110192830Sed help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight"); 5111192830Sed control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page "); 5112192830Sed control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page "); 5113192830Sed control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left "); 5114192830Sed control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right "); 5115192856Sed control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee "); 5116192830Sed command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # "); 5117192830Sed command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\""); 5118192830Sed command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save "); 5119192830Sed command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save"); 5120192830Sed command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs "); 5121192830Sed com_win_message = catgetlocal( 67, " press Escape (^[) for menu"); 5122192830Sed no_file_string = catgetlocal( 68, "no file"); 5123192830Sed ascii_code_str = catgetlocal( 69, "ascii code: "); 5124192830Sed printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" "); 5125192830Sed command_str = catgetlocal( 71, "command: "); 5126192830Sed file_write_prompt_str = catgetlocal( 72, "name of file to write: "); 5127192830Sed file_read_prompt_str = catgetlocal( 73, "name of file to read: "); 5128192830Sed char_str = catgetlocal( 74, "character = %d"); 5129192830Sed unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\""); 5130192830Sed non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique"); 5131192830Sed line_num_str = catgetlocal( 77, "line %d "); 5132192830Sed line_len_str = catgetlocal( 78, "length = %d"); 5133192830Sed current_file_str = catgetlocal( 79, "current file is \"%s\" "); 5134192830Sed usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n"); 5135192830Sed usage1 = catgetlocal( 81, " -i turn off info window\n"); 5136192830Sed usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n"); 5137192830Sed usage3 = catgetlocal( 83, " -h do not use highlighting\n"); 5138192830Sed file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory"); 5139192830Sed new_file_msg = catgetlocal( 85, "new file \"%s\""); 5140192830Sed cant_open_msg = catgetlocal( 86, "can't open \"%s\""); 5141192830Sed open_file_msg = catgetlocal( 87, "file \"%s\", %d lines"); 5142192830Sed file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\""); 5143192830Sed reading_file_msg = catgetlocal( 89, "reading file \"%s\""); 5144192830Sed read_only_msg = catgetlocal( 90, ", read only"); 5145192830Sed file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines"); 5146192830Sed save_file_name_prompt = catgetlocal( 92, "enter name of file: "); 5147192830Sed file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved"); 5148192830Sed changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) "); 5149192830Sed yes_char = catgetlocal( 95, "y"); 5150192830Sed file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] "); 5151192830Sed create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\""); 5152192830Sed writing_file_msg = catgetlocal( 98, "writing file \"%s\""); 5153192830Sed file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters"); 5154192830Sed searching_msg = catgetlocal( 100, " ...searching"); 5155192830Sed str_not_found_msg = catgetlocal( 101, "string \"%s\" not found"); 5156192830Sed search_prompt_str = catgetlocal( 102, "search for: "); 5157192856Sed exec_err_msg = catgetlocal( 103, "could not exec %s"); 5158192830Sed continue_msg = catgetlocal( 104, "press return to continue "); 5159192830Sed menu_cancel_msg = catgetlocal( 105, "press Esc to cancel"); 5160192830Sed menu_size_err_msg = catgetlocal( 106, "menu too large for window"); 5161192830Sed press_any_key_msg = catgetlocal( 107, "press any key to continue "); 5162192830Sed shell_prompt = catgetlocal( 108, "shell command: "); 5163192830Sed formatting_msg = catgetlocal( 109, "...formatting paragraph..."); 5164192830Sed shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-"); 5165192830Sed spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'"); 5166192830Sed margin_prompt = catgetlocal( 112, "right margin is: "); 5167192830Sed restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation"); 5168192830Sed ON = catgetlocal( 114, "ON"); 5169192830Sed OFF = catgetlocal( 115, "OFF"); 5170192830Sed HELP = catgetlocal( 116, "HELP"); 5171192830Sed WRITE = catgetlocal( 117, "WRITE"); 5172192830Sed READ = catgetlocal( 118, "READ"); 5173192830Sed LINE = catgetlocal( 119, "LINE"); 5174192830Sed FILE_str = catgetlocal( 120, "FILE"); 5175192830Sed CHARACTER = catgetlocal( 121, "CHARACTER"); 5176192830Sed REDRAW = catgetlocal( 122, "REDRAW"); 5177192830Sed RESEQUENCE = catgetlocal( 123, "RESEQUENCE"); 5178192830Sed AUTHOR = catgetlocal( 124, "AUTHOR"); 5179192830Sed VERSION = catgetlocal( 125, "VERSION"); 5180192830Sed CASE = catgetlocal( 126, "CASE"); 5181192830Sed NOCASE = catgetlocal( 127, "NOCASE"); 5182192830Sed EXPAND = catgetlocal( 128, "EXPAND"); 5183192830Sed NOEXPAND = catgetlocal( 129, "NOEXPAND"); 5184192830Sed Exit_string = catgetlocal( 130, "EXIT"); 5185192830Sed QUIT_string = catgetlocal( 131, "QUIT"); 5186192830Sed INFO = catgetlocal( 132, "INFO"); 5187192830Sed NOINFO = catgetlocal( 133, "NOINFO"); 5188192830Sed MARGINS = catgetlocal( 134, "MARGINS"); 5189192830Sed NOMARGINS = catgetlocal( 135, "NOMARGINS"); 5190192830Sed AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT"); 5191192830Sed NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT"); 5192192830Sed Echo = catgetlocal( 138, "ECHO"); 5193192830Sed PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND"); 5194192830Sed RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN"); 5195192830Sed HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT"); 5196192830Sed NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT"); 5197192830Sed EIGHTBIT = catgetlocal( 143, "EIGHTBIT"); 5198192830Sed NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT"); 5199192830Sed /* 5200192830Sed | additions 5201192830Sed */ 5202192830Sed mode_strings[7] = catgetlocal( 145, "emacs key bindings "); 5203192830Sed emacs_help_text[0] = help_text[0]; 5204192830Sed emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word "); 5205192856Sed emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t begin of file "); 5206192856Sed emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u end of file "); 5207192830Sed emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page "); 5208192830Sed emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word "); 5209192830Sed emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search "); 5210192830Sed emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt "); 5211192830Sed emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word "); 5212192830Sed emacs_help_text[9] = help_text[9]; 5213192830Sed emacs_help_text[10] = help_text[10]; 5214192830Sed emacs_help_text[11] = help_text[11]; 5215192830Sed emacs_help_text[12] = help_text[12]; 5216192830Sed emacs_help_text[13] = help_text[13]; 5217192830Sed emacs_help_text[14] = help_text[14]; 5218192830Sed emacs_help_text[15] = help_text[15]; 5219192830Sed emacs_help_text[16] = help_text[16]; 5220192830Sed emacs_help_text[17] = help_text[17]; 5221192830Sed emacs_help_text[18] = help_text[18]; 5222192830Sed emacs_help_text[19] = help_text[19]; 5223192830Sed emacs_help_text[20] = help_text[20]; 5224192830Sed emacs_help_text[21] = help_text[21]; 5225192856Sed emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev line ^g prev page"); 5226192856Sed emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next line ^v next page"); 5227192856Sed emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back char ^z next word"); 5228192856Sed emacs_control_keys[3] = catgetlocal( 157, "^t begin of file ^e end of line ^r restore word ^f forward char "); 5229192856Sed emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit"); 5230192830Sed EMACS_string = catgetlocal( 159, "EMACS"); 5231192830Sed NOEMACS_string = catgetlocal( 160, "NOEMACS"); 5232192830Sed usage4 = catgetlocal( 161, " +# put cursor at line #\n"); 5233192830Sed conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!"); 5234192830Sed conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s"); 5235192830Sed modes_menu[10].item_string = catgetlocal( 164, "save editor configuration"); 5236192830Sed config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration"); 5237192830Sed config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory"); 5238192830Sed config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory"); 5239192830Sed conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved"); 5240192830Sed ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree"); 5241192830Sed menu_too_lrg_msg = catgetlocal( 180, "menu too large for window"); 5242192830Sed more_above_str = catgetlocal( 181, "^^more^^"); 5243192830Sed more_below_str = catgetlocal( 182, "VVmoreVV"); 5244192830Sed mode_strings[9] = catgetlocal( 183, "16 bit characters "); 5245192830Sed chinese_cmd = catgetlocal( 184, "16BIT"); 5246192830Sed nochinese_cmd = catgetlocal( 185, "NO16BIT"); 5247192830Sed 5248192830Sed commands[0] = HELP; 5249192830Sed commands[1] = WRITE; 5250192830Sed commands[2] = READ; 5251192830Sed commands[3] = LINE; 5252192830Sed commands[4] = FILE_str; 5253192830Sed commands[5] = REDRAW; 5254192830Sed commands[6] = RESEQUENCE; 5255192830Sed commands[7] = AUTHOR; 5256192830Sed commands[8] = VERSION; 5257192830Sed commands[9] = CASE; 5258192830Sed commands[10] = NOCASE; 5259192830Sed commands[11] = EXPAND; 5260192830Sed commands[12] = NOEXPAND; 5261192830Sed commands[13] = Exit_string; 5262192830Sed commands[14] = QUIT_string; 5263192830Sed commands[15] = "<"; 5264192830Sed commands[16] = ">"; 5265192830Sed commands[17] = "!"; 5266192830Sed commands[18] = "0"; 5267192830Sed commands[19] = "1"; 5268192830Sed commands[20] = "2"; 5269192830Sed commands[21] = "3"; 5270192830Sed commands[22] = "4"; 5271192830Sed commands[23] = "5"; 5272192830Sed commands[24] = "6"; 5273192830Sed commands[25] = "7"; 5274192830Sed commands[26] = "8"; 5275192830Sed commands[27] = "9"; 5276192830Sed commands[28] = CHARACTER; 5277192830Sed commands[29] = chinese_cmd; 5278192830Sed commands[30] = nochinese_cmd; 5279192830Sed commands[31] = NULL; 5280192830Sed init_strings[0] = CASE; 5281192830Sed init_strings[1] = NOCASE; 5282192830Sed init_strings[2] = EXPAND; 5283192830Sed init_strings[3] = NOEXPAND; 5284192830Sed init_strings[4] = INFO; 5285192830Sed init_strings[5] = NOINFO; 5286192830Sed init_strings[6] = MARGINS; 5287192830Sed init_strings[7] = NOMARGINS; 5288192830Sed init_strings[8] = AUTOFORMAT; 5289192830Sed init_strings[9] = NOAUTOFORMAT; 5290192830Sed init_strings[10] = Echo; 5291192830Sed init_strings[11] = PRINTCOMMAND; 5292192830Sed init_strings[12] = RIGHTMARGIN; 5293192830Sed init_strings[13] = HIGHLIGHT; 5294192830Sed init_strings[14] = NOHIGHLIGHT; 5295192830Sed init_strings[15] = EIGHTBIT; 5296192830Sed init_strings[16] = NOEIGHTBIT; 5297192830Sed init_strings[17] = EMACS_string; 5298192830Sed init_strings[18] = NOEMACS_string; 5299192830Sed init_strings[19] = chinese_cmd; 5300192830Sed init_strings[20] = nochinese_cmd; 5301192830Sed init_strings[21] = NULL; 5302192830Sed 5303192830Sed /* 5304192830Sed | allocate space for strings here for settings menu 5305192830Sed */ 5306192830Sed 5307192830Sed for (counter = 1; counter < NUM_MODES_ITEMS; counter++) 5308192830Sed { 5309192830Sed modes_menu[counter].item_string = malloc(80); 5310192830Sed } 5311192830Sed 5312192830Sed#ifndef NO_CATGETS 5313192830Sed catclose(catalog); 5314192830Sed#endif /* NO_CATGETS */ 5315192830Sed} 5316192830Sed 5317