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