static void abook_rl_init(bool use_completion) { rl_readline_name = RL_READLINE_NAME; #if RL_VERSION_MAJOR >= 4 rl_already_prompted = 1; #endif rl_catch_sigwinch = 0; rl_erase_empty_line = 0; rl_redisplay_function = rline_update; rl_completion_display_matches_hook = rline_compdisp; rl_prep_term_function = rline_prep_terminal; rl_deprep_term_function = rline_deprep_terminal; rl_unbind_function_in_map(rl_clear_screen, rl_get_keymap()); rl_unbind_function_in_map(rl_reverse_search_history, rl_get_keymap()); rl_unbind_function_in_map(rl_re_read_init_file, rl_get_keymap()); if(use_completion) { rl_bind_key('\t', rl_menu_complete); } else { rl_unbind_function_in_map(rl_complete, rl_get_keymap()); rl_unbind_function_in_map(rl_menu_complete, rl_get_keymap()); } rl_bind_key('g' & 31, rl_cancel); /* C-g */ clear_history(); rl_cancelled = FALSE; }
void readline_status_mode (cli_context_t *ctx, const keymap_entry_t map[]) { int i; Keymap stkmap; readline_cli_ctx = ctx; rl_callback_handler_install (NULL, &readline_status_callback); /* Backup current keymap-name */ readline_keymap = g_strdup (rl_get_keymap_name (rl_get_keymap ())); /* New keymap for status mode */ stkmap = rl_make_bare_keymap (); /* Fill out the keymap and display it. */ g_printf ("\n"); for (i = 0; map[i].keyseq; i++) { rl_set_key (map[i].keyseq, rl_named_function (map[i].named_function), stkmap); if (map[i].readable_keyseq) { g_printf (" (%s) %s\n", map[i].readable_keyseq, map[i].readable_function ? map[i].readable_function : map[i].named_function); } } g_printf ("\n"); rl_set_keymap (stkmap); }
static void init_bouncing_parens() { if(strncmp(rl_get_keymap_name(rl_get_keymap()), "vi", 2)) { rl_bind_key(')', match_paren); rl_bind_key(']', match_paren); rl_bind_key('}', match_paren); } }
/* Initialize readline and configure the keymap for the switching key shortcut. */ void tui_initialize_readline (void) { int i; Keymap tui_ctlx_keymap; rl_initialize (); rl_add_defun ("tui-switch-mode", tui_rl_switch_mode, -1); rl_add_defun ("gdb-command", tui_rl_command_key, -1); rl_add_defun ("next-keymap", tui_rl_next_keymap, -1); tui_keymap = rl_make_bare_keymap (); tui_ctlx_keymap = rl_make_bare_keymap (); tui_readline_standard_keymap = rl_get_keymap (); for (i = 0; tui_commands[i].cmd; i++) rl_bind_key_in_map (tui_commands[i].key, tui_rl_command_key, tui_keymap); rl_generic_bind (ISKMAP, "\\C-x", (char*) tui_ctlx_keymap, tui_keymap); /* Bind all other keys to tui_rl_command_mode so that we switch temporarily from SingleKey mode and can enter a gdb command. */ for (i = ' '; i < 0x7f; i++) { int j; for (j = 0; tui_commands[j].cmd; j++) if (tui_commands[j].key == i) break; if (tui_commands[j].cmd) continue; rl_bind_key_in_map (i, tui_rl_command_mode, tui_keymap); } rl_bind_key_in_map ('a', tui_rl_switch_mode, emacs_ctlx_keymap); rl_bind_key_in_map ('a', tui_rl_switch_mode, tui_ctlx_keymap); rl_bind_key_in_map ('A', tui_rl_switch_mode, emacs_ctlx_keymap); rl_bind_key_in_map ('A', tui_rl_switch_mode, tui_ctlx_keymap); rl_bind_key_in_map (CTRL ('A'), tui_rl_switch_mode, emacs_ctlx_keymap); rl_bind_key_in_map (CTRL ('A'), tui_rl_switch_mode, tui_ctlx_keymap); rl_bind_key_in_map ('1', tui_rl_delete_other_windows, emacs_ctlx_keymap); rl_bind_key_in_map ('1', tui_rl_delete_other_windows, tui_ctlx_keymap); rl_bind_key_in_map ('2', tui_rl_change_windows, emacs_ctlx_keymap); rl_bind_key_in_map ('2', tui_rl_change_windows, tui_ctlx_keymap); rl_bind_key_in_map ('o', tui_rl_other_window, emacs_ctlx_keymap); rl_bind_key_in_map ('o', tui_rl_other_window, tui_ctlx_keymap); rl_bind_key_in_map ('q', tui_rl_next_keymap, tui_keymap); rl_bind_key_in_map ('s', tui_rl_next_keymap, emacs_ctlx_keymap); rl_bind_key_in_map ('s', tui_rl_next_keymap, tui_ctlx_keymap); }
void readline_status_mode_exit (void) { Keymap active; g_assert (cli_context_in_status (readline_cli_ctx, CLI_ACTION_STATUS_REFRESH)); active = rl_get_keymap (); rl_set_keymap (rl_get_keymap_by_name (readline_keymap)); rl_discard_keymap (active); rl_callback_handler_remove (); g_free (readline_keymap); status_free (cli_context_status_entry (readline_cli_ctx)); // TODO: handle via cli_context_free or somesuch? cli_context_status_mode_exit (readline_cli_ctx); }
void initialize(char * helpFileName, char * dataFileName, char * macroFileName, char * dataPath, char * macroPath, char * homePath, promptType prompt) { long i; Symbolhandle symh, symh1; long length, nMacroFiles = 0, nPaths = 0; long nBuiltins = 0; char *dataPathName = (char *) 0, *macroPathName = (char *) 0; char *macroFileNames[NMACROFILES+1]; char *place; char completePath[PATHSIZE+1]; char *pathName; double value; #ifdef READLINE #if defined(INPUTRCFILE) || defined(DEFAULTINPUTRC) Keymap keymap; /* current keymap */ char *backwardkillword = "\033\010"; /*Esc-Backspace*/ FILE *readlineBindings = (FILE *) 0; Symbolhandle symhPath = (Symbolhandle) 0; #endif /*defined(INPUTRCFILE) || defined(DEFAULTINPUTRC)*/ #endif /*READLINE*/ WHERE("initialize"); getElapsedTime((double *) 0); /* save current time */ getElapsedTime((double *) 0); /* do it twice for good measure */ #if defined(MSDOS) pathName = get_dataPath(); for (i = 0; pathName[i] != '\0'; i++) { /* make sure all path separators are '\\' */ if (pathName[i] == '/') { pathName[i] = DIRSEPARATOR[0]; } } /*for (i == 0; pathName[i] != '\0'; i++)*/ #elif defined(MACINTOSH) /* macGetPath() returns address of completePath */ pathName = macGetPath(completePath, HomeVolume, HomeDirectory); #elif defined(UNIX) pathName = getenv("HOME"); #elif defined(VMS) pathName = getenv("ANOVA$HOME"); dataPathName = macroPathName = pathName; #endif if (pathName == (char *) 0) { completePath[0] = '\0'; } /*if (pathName == (char *) 0)*/ else { if (pathName != completePath) { strncpy(completePath, pathName, PATHSIZE); completePath[PATHSIZE] = '\0'; } length = strlen(completePath); #ifndef NOSEPARATOR if (completePath[length-1] != DIRSEPARATOR[0] && length < PATHSIZE) { strcat(completePath, DIRSEPARATOR); } #endif /*NOSEPARATOR*/ } /*if (pathName == (char *) 0){}else{}*/ homePath = (homePath != (char *) 0) ? homePath : completePath ; #if !defined(UNIX) && !defined(VMS) if (completePath[0] != '\0') { dataPathName = (dataPath != (char *) 0) ? dataPath : completePath; macroPathName = (macroPath != (char *) 0) ? macroPath : completePath; } else #endif /*UNIX*/ /* use defined values on Unix which should have trailing '/' */ { dataPathName = (dataPath != (char *) 0) ? dataPath : DATAPATHNAME; macroPathName = (macroPath != (char *) 0) ? macroPath : MACROPATHNAME; } /* initialized math constants */ MV_E = exp(1); MV_PI_4 = atan(1.0); MV_PI_2 = 2.0*MV_PI_4; MV_PI = 4.0*MV_PI_4; #ifdef M_E MV_LOG2E = M_LOG2E; MV_LOG10E = M_LOG10E; MV_LN2 = M_LN2; MV_LN10 = M_LN10; MV_1_PI = M_1_PI; MV_2_PI = M_2_PI; MV_2_SQRTPI = M_2_SQRTPI; MV_SQRT2 = M_SQRT2; #ifdef M_SQRT1_2 MV_SQRT1_2 = M_SQRT1_2; #else /*M_SQRT1_2*/ MV_SQRT1_2 = M_SQRT_2; /*Borland math.h name of constant */ #endif /*M_SQRT1_2*/ #else /*M_E*/ MV_LOG2E = 1.4426950408889634074; MV_LOG10E = 0.43429448190325182765; MV_LN2 = 0.69314718055994530942; MV_LN10 = 2.30258509299404568402; MV_1_PI = 0.31830988618379067154; MV_2_PI = 0.63661977236758134308; MV_2_SQRTPI = 1.12837916709551257390; MV_SQRT2 = 1.41421356237309504880; MV_SQRT1_2 = 0.70710678118654752440; #endif /*M_E*/ if (!inputInit()) { /* allocate space for INPUTSTRINGS and ISTRCHARS*/ goto fatalError; } /* Allocate space for globals, BATCHECHO, INPUTFILE, INPUTFILENAMES, LASTINPUTWASCR, PROMPTS */ if (!batchInit()) { goto fatalError; } if(!Symbolinit()) { /* create size TABLESIZE symbol table and zero it out*/ goto fatalError; } if(!glmInit()) { /* allocate glm related globals */ goto fatalError; } /* create fake handles for function symbols */ for (nBuiltins = 0; builtins[nBuiltins].name; nBuiltins++) { /* count builtins */ ; } FunctionPointers = (Symbol **) mygetpointer(nBuiltins * sizeof(Symbol *)); FunctionSymbols = (FunctionSymbol *) mygetpointer(nBuiltins* sizeof(FunctionSymbol)); if(FunctionPointers == (Symbol **) 0 || FunctionSymbols == (FunctionSymbol *) 0) { goto fatalError; } for (i = 0;i<nBuiltins; i++) { /* make fake Symbolhandle for each builtin function */ symh = FunctionPointers + i; *symh = (Symbol *) (FunctionSymbols+i); setTYPE(symh, BLTIN); markFakeSymbol(symh); /* indicates it's fake if we ever need to know */ setNDIMS(symh, 1); setDIM(symh, 1, 1); setPREV(symh, (Symbolhandle) 0); setNEXT(symh, (Symbolhandle) 0); setFPTR(symh, builtins[i].function); setNAME(symh, builtins[i].name); Addsymbol(symh); } /*for (i = 0;i<nBuiltins; i++)*/ /* now install pre-defined constants */ for (i = 0; constants[i].name; i++) { symh = RInstall(constants[i].name, 1L); if(symh == (Symbolhandle) 0) { goto fatalError; } if(strcmp(NAME(symh),"PI") == 0) { value = MV_PI; } else if(strcmp(NAME(symh),"E") == 0) { value = MV_E; } else if(strcmp(NAME(symh),"DEGPERRAD") == 0) { value = 45.0/MV_PI_4; } else { value = constants[i].value; } DATAVALUE(symh,0) = value; } /*for (i = 0; constants[i].name; i++)*/ /* Create NULLSYMBOL (value returned by print(), etc. Note that it is *not* installed in the symbol table */ NULLSYMBOL = Makesymbol(NULLSYM); if(NULLSYMBOL == (Symbolhandle) 0) { goto fatalError; } setNAME(NULLSYMBOL, "NULLSYMBOL"); /* initialize special symbol CLIPBOARD */ if (!iniClipboard(CLIPBOARDNAME)) { goto fatalError; } #ifdef HASSELECTION /* initialize special symbol SELECTION */ if (!iniClipboard(SELECTIONNAME)) { goto fatalError; } #endif /*HASSELECTION*/ /* install pre-defined macros */ if (!iniMacros()) { goto fatalError; } /* install pre-defined string variables (they must all be scalar) */ for (i = 0; stringvars[i].name; i++) { symh = CInstall(stringvars[i].name, strlen(stringvars[i].string) + 1); if(symh == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh), stringvars[i].string); cleanString(STRINGPTR(symh)); } /*for (i = 0; stringvars[i].name; i++)*/ /* set value for MISSING and infinities */ #if LONGSPERDOUBLE == 2 setBdouble(Missing, HIMISSING, LOWMISSING); #ifdef HASINFINITY setBdouble(PlusInfinity, HIPLUSINFINITY, LOWPLUSINFINITY); setBdouble(MinusInfinity, HIMINUSINFINITY, LOWMINUSINFINITY); #endif /*HASINFINITY*/ #else /*LONGSPERDOUBLE == 2*/ MISSING = MISSINGVALUE; /* may have to do something fancier than this */ #ifdef HASINFINITY PLUSINFINITY = 1.0/0.0; MINUSINFINITY = -1.0/0.0; #endif /*HASINFINITY*/ #endif /*LONGSPERDOUBLE == 2*/ /* TOOBIGVALUE should be HUGE_VAL which may be infinite */ #ifndef NOSTRTOD TOOBIGVALUE = mystrtod(TOOBIGVALUESTRING,(char **) 0); #else /*NOSTRTOD*/ #ifdef HUGE_VAL TOOBIGVALUE = HUGE_VAL; #else /*HUGE_VAL*/ TOOBIGVALUE = exp(1e200); #endif /*HUGE_VAL*/ #endif /*NOSTRTOD*/ OLDMISSING = OLDMISSINGVALUE; /* -99999.9999 */ setDefaultOptions(); /* set default options */ if (prompt[0] != '\0') { strcpy((char *) DEFAULTPROMPTS[0], (char *) prompt); } strcpy((char *) PROMPTS[0], (char *) DEFAULTPROMPTS[0]); #ifdef VERSION sprintf(OUTSTR,"MacAnova %s ",VERSION); #ifdef TODAY strcat(OUTSTR,TODAY); #endif /*TODAY*/ symh = CInstall("VERSION", strlen(OUTSTR) + 1); if(symh == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh),OUTSTR); *OUTSTR = '\0'; VERSION_ID = myduphandle(STRING(symh)); if(VERSION_ID == (char **) 0) { goto fatalError; } #endif /*VERSION*/ /* Create global HELPFILENAME*/ if(helpFileName == (char *) 0) { helpFileName = HELPNAME; #ifdef UNIX pathName = HELPPATHNAME; #elif defined(VMS) pathName = getenv("ANOVA$HOME"); #else /*UNIX*/ pathName = completePath; #endif /*UNIX*/ } else { pathName = NullString; } length = strlen(pathName) + strlen(helpFileName); HELPFILENAME = mygethandle(length + 1); if(HELPFILENAME == (char **) 0) { goto fatalError; } strcpy(*HELPFILENAME,pathName); strcat(*HELPFILENAME,helpFileName); /* Install CHARACTER scalar DATAPATH containing dataPathName */ length = strlen(dataPathName); #ifndef NOSEPARATOR if (dataPathName[length-1] != DIRSEPARATOR[0]) { length++; } #endif /*NOSEPARATOR*/ symh = CInstall("DATAPATH",length + 1); if (symh == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh),dataPathName); #ifndef NOSEPARATOR STRINGVALUE(symh, length-1) = DIRSEPARATOR[0]; STRINGVALUE(symh, length) = '\0'; #endif /*NOSEPARATOR*/ /* Install CHARACTER vector DATAPATHS containing dataPathName and macroPathName. If they are the same, they are not duplicated */ nPaths = 1; if (strcmp(macroPathName, dataPathName) != 0 && strcmp(macroPathName, STRINGPTR(symh)) != 0) { long length2 = strlen(macroPathName); length++; /* account for trailing null of dataPathName */ nPaths = 2; #ifndef NOSEPARATOR if (macroPathName[length2-1] != DIRSEPARATOR[0]) { length2++; } #endif /*NOSEPARATOR*/ length += length2; } symh1 = CInstall("DATAPATHS",length + 1); if (symh1 == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh1),STRINGPTR(symh)); if (nPaths > 1) { strcpy(skipStrings(STRINGPTR(symh1), 1), macroPathName); #ifndef NOSEPARATOR STRINGVALUE(symh1,length-1) = DIRSEPARATOR[0]; STRINGVALUE(symh1,length) = '\0'; #endif /*NOSEPARATOR*/ } setDIM(symh1, 1, nPaths); /* pre-install CHARACTER scalar HOME */ length = strlen(homePath); if(length > 0) { #ifndef NOSEPARATOR if (homePath[length-1] != DIRSEPARATOR[0]) { /* make room for terminating separator */ length++; } #endif /*NOSEPARATOR*/ symh = CInstall("HOME",length + 1); if (symh == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh),homePath); #ifndef NOSEPARATOR /* make sure HOME terminates with DIRSEPARATOR[0]*/ STRINGVALUE(symh, length-1) = DIRSEPARATOR[0]; STRINGVALUE(symh, length) = '\0'; #endif /*NOSEPARATOR*/ #ifdef MSDOS { char *pc; for (pc = STRINGPTR(symh); *pc != '\0'; pc++) { /* ensure all separators are standard backslashes*/ if (*pc == '/') { *pc = DIRSEPARATOR[0]; } } /*for (pc = STRINGPTR(symh); *pc != '\0'; pc++)*/ } #endif /*MSDOS*/ } /*if(length > 0)*/ /* install CHARACTER scalar DATAFILE */ if(dataFileName == (char *) 0) { dataFileName = DATAFILENAME; } length = strlen(dataFileName); symh = CInstall("DATAFILE", length + 1); if (symh == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh), dataFileName); /* Install CHARACTER scalar MACROFILE and CHARACTER vector MACROFILES*/ for (i = 0; i < NMACROFILES + 1; i++) { macroFileNames[i] = NullString; } if (macroFileName != (char *) 0) { macroFileNames[nMacroFiles++] = macroFileName; } macroFileNames[nMacroFiles++] = MACROFILENAME; macroFileNames[nMacroFiles++] = TSMACROFILENAME; macroFileNames[nMacroFiles++] = DESIGNMACROFILENAME; macroFileNames[nMacroFiles++] = ARIMAMACROFILENAME; length = strlen(macroFileNames[0]) + 1; symh = CInstall("MACROFILE",length); if(symh == (Symbolhandle) 0) { goto fatalError; } strcpy(STRINGPTR(symh), macroFileNames[0]); length = 0; for (i = 0; i < nMacroFiles; i++) { length += strlen(macroFileNames[i]) + 1; } symh = CInstall("MACROFILES", length); if (symh == (Symbolhandle) 0) { goto fatalError; } setDIM(symh, 1, nMacroFiles); place = STRINGPTR(symh); for (i = 0; i < nMacroFiles; i++) { place = copyStrings(macroFileNames[i], place, 1); } #ifdef READLINE /* Initialize line editing and history */ #if defined(INPUTRCFILE) || defined(DEFAULTINPUTRC) using_history(); /*added 980108*/ rl_initialize(); /*added 980106 */ rl_initialize_funmap(); keymap = rl_get_keymap(); if (keymap != (Keymap) 0) { /* this binding is standard but not the default in readline 1.1 */ rl_set_key (backwardkillword, rl_backward_kill_word, keymap); } /*if (keymap != (Keymap) 0)*/ #ifndef INPUTRCFILE pathName = OUTSTR; strcpy(pathName, dataPathName); strcat(pathName, DEFAULTINPUTRC); #else /*INPUTRCFILE*/ pathName = INPUTRCFILE; #endif /*INPUTRCFILE*/ if (pathName[0] != '\0') { readlineBindings = fmyopen(pathName, TEXTREADMODE); if (readlineBindings != (FILE *) 0) { fclose(readlineBindings); rl_read_init_file(pathName); } /*if (readlineBindings != (FILE *) 0)*/ } /*if (pathName[0] != '\0')*/ #endif /*defined(INPUTRCFILE) || defined(DEFAULTINPUTRC)*/ #endif /*READLINE*/ /* initialize or clear virtually everything in sight */ *OUTSTR = '\0'; for (i = 0;i < MAXWDEPTH;i++) { WHILELIMITS[i] = MAXWHILE; FORVECTORS[i] = (double **) 0; } clearGlobals(); INPUTFILE[0] = STDIN; INPUTFILENAMES[0] = &StdinName; for (i=1;i<MAXBDEPTH;i++) { INPUTFILE[i] = (FILE *) 0; INPUTFILENAMES[i] = (char **) 0; } TMPHANDLE = mygethandle(sizeof(double)); /*warehouseable length*/ if(TMPHANDLE == (char **) 0) { goto fatalError; } INPUTSTRING = ThisInputstring = (unsigned char **) TMPHANDLE; (*INPUTSTRING)[0] = '\0'; GUBED = 0; /* this is here to make it easy to change for debugging */ #ifdef DJGPP INTERRUPT = INTSET; (void) interrupted(0); /* to get DJGPP started */ INTERRUPT = INTNOTSET; #endif /*DJGPP*/ #if defined(BCPP) || defined (wx_msw) (void) _control87(EM_OVERFLOW,EM_OVERFLOW); #endif /*BCPP||wxmsw*/ #ifdef wx_motif #if (0) /* inititalization now done in base frame initializer */ initializePSPrinter(); #endif #endif /*wx_motif*/ return ; fatalError: FatalError = 1; } /*initialize()*/