=================================================================== RCS file: /home/cvs/OpenXM_contrib2/fep/fep_edit.c,v retrieving revision 1.1 retrieving revision 1.8 diff -u -p -r1.1 -r1.8 --- OpenXM_contrib2/fep/fep_edit.c 2002/09/03 00:41:44 1.1 +++ OpenXM_contrib2/fep/fep_edit.c 2020/11/01 10:28:22 1.8 @@ -1,11 +1,20 @@ /* Copyright (c) 1987, 1988 by Software Research Associates, Inc. */ +#if defined(ANDROID) +#include +#define index(s,c) strchr(s,c) +#define rindex(s,c) strrchr(s,c) +#endif + #ifndef lint static char rcsid[]= -"$Id: fep_edit.c,v 1.1 2002/09/03 00:41:44 noro Exp $ (SRA)"; +"$Id: fep_edit.c,v 1.8 2020/11/01 10:28:22 noro Exp $ (SRA)"; #endif /* lint */ #include +#include +#include +#include #include #include #include @@ -24,6 +33,10 @@ static char rcsid[]= #if defined(__CYGWIN__) #include #define direct dirent +#elif defined(sun) || defined(__FreeBSD__) || defined(ANDROID) +#include +#define direct dirent +#include #else #include #endif @@ -51,6 +64,8 @@ jmp_buf jbuf; /* jump buffer */ FUNC *curFuncTab; /* current function table */ FUNC *altFuncTab; /* alternative function table */ +void ls (DIR *dirp, char *prefixstring); + /* * Default binding table */ @@ -111,7 +126,7 @@ BINDENT emacsBindings[] = { /* * Initialize function table buffer */ -init_bind_table () +void init_bind_table () { curFuncTab = (FUNC *) calloc (sizeof (FUNC), 256); @@ -127,7 +142,7 @@ init_bind_table () */ char strspace [256], *strspace_addr = strspace; -init_edit_params () +void init_edit_params () { struct indirect *idp; char *cp, *getenv(); @@ -158,7 +173,8 @@ init_edit_params () set_var ("editmode", "emacs"); } - set_var ("showhist", itoa (lines - 1)); + sprintf (sbuf, "%d", lines); + set_var ("showhist", sbuf); /* * Read startup file @@ -196,8 +212,7 @@ init_edit_params () /* * Initialize emacs bindings */ -initEmacsBindings (cft, aft) - FUNC cft[], aft[]; +void initEmacsBindings (FUNC cft[], FUNC aft[]) { register int i; BINDENT *ftp; @@ -232,7 +247,9 @@ initEmacsBindings (cft, aft) import (cft, initial_ttymode.c_cc[VDSUSP], self_insert); */ import (cft, initial_ttymode.c_cc[VREPRINT], reprint); +#ifdef VDISCARD import (cft, initial_ttymode.c_cc[VDISCARD], self_insert); +#endif import (cft, initial_ttymode.c_cc[VWERASE], delete_previous_word); import (cft, initial_ttymode.c_cc[VLNEXT], literal_next); import (cft, initial_ttymode.c_cc[VERASE], delete_previous_character); @@ -278,8 +295,7 @@ initEmacsBindings (cft, aft) /* * Main function of front end program */ -CHAR * -getline() +CHAR * mygetline() { int c; CHAR *execute_command, *check_alias(); @@ -444,9 +460,7 @@ RETURN: * Invoke appropliate function according to fucntion table * Return value 1 means exit from line editing */ -callfunc (ft, c) - FUNC ft[]; - int c; +int callfunc (FUNC ft[], int c) { if (isIndirect(ft[(int) c])) { @@ -463,7 +477,7 @@ callfunc (ft, c) /* * Beep and do nothing */ -fep_abort() +int fep_abort() { (void) errorBell (); return (0); @@ -472,8 +486,7 @@ fep_abort() /* * Insert the character self */ -self_insert(c) - CHAR c; +int self_insert(CHAR c) { register int i, nbyte = 1, currentNull; #ifdef KANJI @@ -522,8 +535,7 @@ self_insert(c) /* * Insert string in current position */ -insert_string (s) - CHAR *s; +int insert_string (CHAR *s) { register int i, nbyte = strlen (s), currentNull; @@ -554,7 +566,7 @@ insert_string (s) /* * Yank string from kill buffer. */ -yank_from_kill_buffer () +void yank_from_kill_buffer () { insert_string (KillBuffer); } @@ -562,7 +574,7 @@ yank_from_kill_buffer () /* * Set mark to current position */ -mark () +int mark () { set_mark (CurrentPosition); return (0); @@ -571,8 +583,7 @@ mark () /* * Set mark to specified position */ -set_mark (pos) - int pos; +int set_mark (int pos) { MarkPosition = pos; return (0); @@ -581,7 +592,7 @@ set_mark (pos) /* * Delete area from mark to current position to kill buffer */ -delete_to_kill_buffer () +int delete_to_kill_buffer () { int n = abs (CurrentPosition - MarkPosition); @@ -603,7 +614,7 @@ delete_to_kill_buffer () /* * Move to specified position. */ -moveto (position) +void moveto (int position) { if (position < CurrentPosition) while (position < CurrentPosition) @@ -621,7 +632,7 @@ moveto (position) /* * Move cursor to top of line */ -beginning_of_line() +int beginning_of_line() { register int i; @@ -645,7 +656,7 @@ beginning_of_line() /* * Move cursor to end of line */ -end_of_line() +int end_of_line() { register int i; @@ -664,7 +675,7 @@ end_of_line() /* * Move cursor left one space */ -backward_character() +int backward_character() { return (backward_n_character (1)); @@ -673,8 +684,7 @@ backward_character() /* * Move cursor left "n" space */ -backward_n_character(n) - int n; +int backward_n_character(int n) { int space; int i = CurrentPosition; @@ -709,7 +719,7 @@ backward_n_character(n) /* * Move cursor backward one word */ -backward_word () +int backward_word () { return (backward_n_word (1)); @@ -718,8 +728,7 @@ backward_word () /* * Move cursor backward n word */ -backward_n_word (n) - int n; +int backward_n_word (int n) { register int i = CurrentPosition, nchars = 0; @@ -770,7 +779,7 @@ backward_n_word (n) /* * Move cursor backward one Word */ -backward_Word () +int backward_Word () { return (backward_n_Word (1)); @@ -779,8 +788,7 @@ backward_Word () /* * Move cursor backward n Word */ -backward_n_Word (n) - int n; +int backward_n_Word (int n) { register int i = CurrentPosition, nchars = 0; @@ -829,7 +837,7 @@ backward_n_Word (n) /* * Move cursor forward one character */ -forward_character() +int forward_character() { return (forward_n_character (1)); @@ -838,8 +846,7 @@ forward_character() /* * Move cursor forward n character */ -forward_n_character(n) - int n; +int forward_n_character(int n) { int space; register int i = CurrentPosition; @@ -890,7 +897,7 @@ forward_n_character(n) /* * Move cursor forward one word */ -forward_word () +int forward_word () { return (forward_n_word (1)); } @@ -898,8 +905,7 @@ forward_word () /* * Move cursor forward n word */ -forward_n_word (n) - int n; +int forward_n_word (int n) { register int i = CurrentPosition, nchars = 0; @@ -924,7 +930,7 @@ forward_n_word (n) /* * Move cursor forward one word */ -forward_Word () +int forward_Word () { return (forward_n_Word (1)); } @@ -932,8 +938,7 @@ forward_Word () /* * Move cursor forward n word */ -forward_n_Word (n) - int n; +int forward_n_Word (int n) { register int i = CurrentPosition, nchars = 0; @@ -958,7 +963,7 @@ forward_n_Word (n) /* * Forward to end of word */ -forward_to_end_of_word () +int forward_to_end_of_word () { return (forward_to_end_of_n_word (1)); @@ -967,7 +972,7 @@ forward_to_end_of_word () /* * Forward to end of n word */ -forward_to_end_of_n_word (n) +int forward_to_end_of_n_word (int n) { register int i = CurrentPosition, nchars = 0; @@ -994,7 +999,7 @@ forward_to_end_of_n_word (n) /* * Forward to end of word */ -forward_to_end_of_Word () +int forward_to_end_of_Word () { return (forward_to_end_of_n_Word (1)); @@ -1003,7 +1008,7 @@ forward_to_end_of_Word () /* * Forward to end of n word */ -forward_to_end_of_n_Word (n) +int forward_to_end_of_n_Word (int n) { register int i = CurrentPosition, nchars = 0; @@ -1030,7 +1035,7 @@ forward_to_end_of_n_Word (n) /* * Delete previous one character */ -delete_previous_character() +int delete_previous_character() { return (delete_previous_n_character (1)); @@ -1039,8 +1044,7 @@ delete_previous_character() /* * Delete previous n characters */ -delete_previous_n_character(n) - int n; +int delete_previous_n_character(int n) { register int i, nbyte; int deleteArea, restArea; @@ -1086,7 +1090,7 @@ delete_previous_n_character(n) /* * Delete previous one word */ -delete_previous_word() +int delete_previous_word() { return (delete_previous_n_word (1)); @@ -1095,8 +1099,7 @@ delete_previous_word() /* * Delete previous n word */ -delete_previous_n_word(n) - int n; +int delete_previous_n_word(int n) { register int i = CurrentPosition, nchars = 0; @@ -1147,7 +1150,7 @@ delete_previous_n_word(n) /* * Delete previous one word */ -delete_previous_Word() +int delete_previous_Word() { return (delete_previous_n_Word (1)); @@ -1156,8 +1159,7 @@ delete_previous_Word() /* * Delete previous n word */ -delete_previous_n_Word(n) - int n; +int delete_previous_n_Word(int n) { register int i = CurrentPosition, nchars = 0; @@ -1208,7 +1210,7 @@ delete_previous_n_Word(n) /* * Delete next one character */ -delete_next_character () +int delete_next_character () { return (delete_next_n_character (1)); @@ -1217,8 +1219,7 @@ delete_next_character () /* * Delete next n character */ -delete_next_n_character (n) - int n; +int delete_next_n_character (int n) { register int i, nbyte; int deleteArea, restArea; @@ -1267,7 +1268,7 @@ delete_next_n_character (n) /* * Delete next one word */ -delete_next_word () +int delete_next_word () { return (delete_next_n_word (1)); } @@ -1275,8 +1276,7 @@ delete_next_word () /* * Delete next n word */ -delete_next_n_word (n) - int n; +int delete_next_n_word (int n) { register int i = CurrentPosition, nchars = 0; @@ -1301,7 +1301,7 @@ delete_next_n_word (n) /* * Delete next one word */ -delete_next_Word () +int delete_next_Word () { return (delete_next_n_Word (1)); } @@ -1309,8 +1309,7 @@ delete_next_Word () /* * Delete next n word */ -delete_next_n_Word (n) - int n; +int delete_next_n_Word (int n) { register int i = CurrentPosition, nchars = 0; @@ -1335,7 +1334,7 @@ delete_next_n_Word (n) /* * Erase whole line */ -delete_line() +int delete_line() { register int i = CurrentPosition; register int len; @@ -1370,7 +1369,7 @@ delete_line() /* * Delete characters from current position to top of line */ -kill_to_top_of_line() +int kill_to_top_of_line() { int i = CurrentPosition; @@ -1381,7 +1380,7 @@ kill_to_top_of_line() /* * Delete characters from current position to end of line */ -kill_to_end_of_line() +int kill_to_end_of_line() { register int i, backCnt = 0; @@ -1407,7 +1406,7 @@ kill_to_end_of_line() /* * Insert tab to current cursor position */ -insert_tab() +int insert_tab() { /* sorry, not implemented */ @@ -1417,7 +1416,7 @@ insert_tab() /* * Process new line */ -new_line() +int new_line() { (void) end_of_line; @@ -1431,7 +1430,7 @@ new_line() /* * Check current position is top-of-line */ -is_tol() +int is_tol() { return (CurrentPosition == 0); } @@ -1439,7 +1438,7 @@ is_tol() /* * Check current position is end-of-line */ -is_eol() +int is_eol() { return (CommandLine [CurrentPosition] == '\0'); } @@ -1447,7 +1446,7 @@ is_eol() /* * Check command line if it refer history or not */ -refer_history() +int refer_history() { char *historyExtract (); char *his; @@ -1473,18 +1472,17 @@ refer_history() #define FORWARD 1 #define REVERSE 2 -search_reverse () +int search_reverse () { return (search_history (REVERSE)); } -search_forward () +int search_forward () { return (search_history (FORWARD)); } -search_history (direct) - int direct; +int search_history (int direct) { char *his, *search_reverse_history(), *search_forward_history(); char *(*func)(); @@ -1524,8 +1522,7 @@ AGAIN: /* * Insert the character and flush buffer */ -insert_and_flush(c) - char c; +int insert_and_flush(char c) { (void) self_insert (c); return (1); @@ -1535,7 +1532,7 @@ insert_and_flush(c) * Insert the character, but it means EOL. Therefore move cursor backward and * flush buffer */ -send_eof() +int send_eof() { #ifdef TERMIOS char c = initial_ttymode.c_cc[VEOF]; @@ -1554,7 +1551,7 @@ send_eof() /* * Alarm for EOF on only the first time finding eof character */ -alarm_on_eof () +int alarm_on_eof () { errorBell (); @@ -1566,7 +1563,7 @@ alarm_on_eof () /* * Clear screen */ -clear_screen() +int clear_screen() { if (term_clear) { @@ -1583,10 +1580,12 @@ clear_screen() typedef enum {HOP_INSERT, HOP_REPLACE} HISTOP; typedef enum {HDIR_PREV, HDIR_CURRENT, HDIR_NEXT} HISTDIR; +int serv_history(HISTOP op, HISTDIR dir); + /* * Get next history entry */ -next_history() +int next_history() { return (serv_history (HOP_REPLACE, HDIR_NEXT)); } @@ -1594,7 +1593,7 @@ next_history() /* * Get next history entry */ -previous_history() +int previous_history() { return (serv_history (HOP_REPLACE, HDIR_PREV)); } @@ -1602,7 +1601,7 @@ previous_history() /* * Insert next history entry */ -insert_current_history() +int insert_current_history() { return (serv_history (HOP_INSERT, HDIR_CURRENT)); } @@ -1610,7 +1609,7 @@ insert_current_history() /* * Insert next history entry */ -insert_next_history() +int insert_next_history() { return (serv_history (HOP_INSERT, HDIR_NEXT)); } @@ -1618,7 +1617,7 @@ insert_next_history() /* * Insert next history entry */ -insert_previous_history() +int insert_previous_history() { return (serv_history (HOP_INSERT, HDIR_PREV)); } @@ -1626,9 +1625,7 @@ insert_previous_history() /* * Get previous history */ -serv_history(op, dir) - HISTOP op; - HISTDIR dir; +int serv_history(HISTOP op, HISTDIR dir) { register char *cp; char *getPreviousHistory (), *getNextHistory (), *getCurrentHistory (); @@ -1655,7 +1652,7 @@ serv_history(op, dir) /* * Show history */ -show_history() +void show_history() { (void) clear_edit_line (); @@ -1666,7 +1663,7 @@ show_history() /* * Do nothing */ -ignore() +int ignore() { return(0); } @@ -1674,7 +1671,7 @@ ignore() /* * Next character is literal */ -literal_next() +int literal_next() { return (self_insert (getcharacter ())); @@ -1683,7 +1680,7 @@ literal_next() /* * Reprint command line */ -reprint() +int reprint() { (void) clear_edit_line (); @@ -1694,7 +1691,7 @@ reprint() /* * Print whole command line and move cursor to the current position */ -print_com_line() +void print_com_line() { printS (CommandLine); @@ -1707,9 +1704,7 @@ print_com_line() /* * Calcurate space of string using "^" for control character */ -howlong(s, n) - char *s; - int n; +int howlong(char *s, int n) { register char *sp; register int area = 0; @@ -1728,9 +1723,7 @@ howlong(s, n) /* * Repeat puting character n times */ -repeat(c, n) - char c; - register int n; +void repeat(char c, int n) { for (n = n; n; n--) (void) putchar(c); @@ -1739,9 +1732,7 @@ repeat(c, n) /* * Repeat putting string n times */ -repeat_string(s, n) - char *s; - register int n; +void repeat_string(char *s, int n) { for (n = n; n; n--) fputs(s, stdout); @@ -1750,7 +1741,7 @@ repeat_string(s, n) /* * Expand file name */ -expand_file_name () +int expand_file_name () { CHAR *cp, *start_expand; char *x_dirname(); @@ -1762,7 +1753,9 @@ expand_file_name () int found = 0; int i; int tilde_expanded = 0; +#if !defined(ANDROID) CHAR *index(), *rindex(); +#endif if (delimiters == NULL) delimiters = DEFAULT_DELIMITERS; @@ -1870,12 +1863,14 @@ expand_file_name () /* * List file name */ -list_file_name () +int list_file_name () { CHAR *cp; char dir[256]; DIR *dirp, *x_opendir(); +#if !defined(ANDROID) CHAR *index(), *rindex(); +#endif if (delimiters == NULL) delimiters = DEFAULT_DELIMITERS; @@ -1927,7 +1922,7 @@ list_file_name () int rememberPosition; -clear_edit_line () +void clear_edit_line () { if (editstatus == NOTEDITING) @@ -1938,8 +1933,7 @@ clear_edit_line () (void) fputs ("\r\n", stdout); } -recover_edit_line (put_prompt) - int put_prompt; +void recover_edit_line (int put_prompt) { if (editstatus == NOTEDITING) @@ -1959,9 +1953,7 @@ recover_edit_line (put_prompt) /* * Do ls */ -ls (dirp, prefixstring) - DIR *dirp; - char *prefixstring; +void ls (DIR *dirp, char *prefixstring) { struct direct *dp; char *fileList[MAXFILES + 1]; @@ -2043,8 +2035,7 @@ BACK: #include "../rinfo/rinfo.h" -list_remote_file (host, pattern) - char *host, *pattern; +void list_remote_file (char *host, char *pattern) { struct slist *slp, *getfilelist(); int i, j; @@ -2084,11 +2075,14 @@ list_remote_file (host, pattern) } #endif /* RINFO */ -bind_key (ft, func, s, dfunc) - FUNC ft[]; /* Function table */ - FUNC func; /* Function to be binded */ - char *s; /* String to bind */ - FUNC dfunc; /* Default function for table allocating */ +/* + FUNC ft[]; Function table + FUNC func; Function to be binded + char *s; String to bind + FUNC dfunc; Default function for table allocating +*/ + +int bind_key (FUNC ft[], FUNC func, char *s, FUNC dfunc) { char tmps[16];