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