JNIEXPORT void JNICALL Java_org_gnu_readline_Readline_readInitFileImpl
                            (JNIEnv *env, jclass theClass, jstring jfilename) {
  const char *filename;
  jboolean is_copy;

  /* retrieve filename argument and convert to ucs -------------------------- */

  filename = (*env)->GetStringUTFChars(env,jfilename,&is_copy);
  if (!utf2ucs(filename)) {
    jclass newExcCls;
    if (is_copy == JNI_TRUE)
      (*env)->ReleaseStringUTFChars(env,jfilename,filename);
    newExcCls = (*env)->FindClass(env,"java/io/UnsupportedEncodingException");
    if (newExcCls != NULL)
      (*env)->ThrowNew(env,newExcCls,"");
    return;
  }
  if (is_copy == JNI_TRUE)
    (*env)->ReleaseStringUTFChars(env,jfilename,filename);

  /* pass to readline function ---------------------------------------------- */

  if (rl_read_init_file(buffer)) {
    jclass newExcCls;
    newExcCls = (*env)->FindClass(env,"java/io/IOException");
    if (newExcCls != NULL)
      (*env)->ThrowNew(env,newExcCls,strerror(errno));
    return;
  }
}
Ejemplo n.º 2
0
static PyObject *
read_init_file(PyObject *self, PyObject *args)
{
    PyObject *filename_obj = Py_None, *filename_bytes;
    if (!PyArg_ParseTuple(args, "|O:read_init_file", &filename_obj))
        return NULL;
    if (filename_obj != Py_None) {
        if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
            return NULL;
        errno = rl_read_init_file(PyBytes_AsString(filename_bytes));
        Py_DECREF(filename_bytes);
    } else
        errno = rl_read_init_file(NULL);
    if (errno)
        return PyErr_SetFromErrno(PyExc_IOError);
    Py_RETURN_NONE;
}
Ejemplo n.º 3
0
static void
setup_readline(void)
{
#ifdef SAVE_LOCALE
    char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
    if (!saved_locale)
        Py_FatalError("not enough memory to save locale");
#endif

#ifdef __APPLE__
    /* the libedit readline emulation resets key bindings etc
     * when calling rl_initialize.  So call it upfront
     */
    if (using_libedit_emulation)
        rl_initialize();
#endif /* __APPLE__ */

    using_history();

    rl_readline_name = "python";
#if defined(PYOS_OS2) && defined(PYCC_GCC)
    /* Allow $if term= in .inputrc to work */
    rl_terminal_name = getenv("TERM");
#endif
    /* Force rebind of TAB to insert-tab */
    rl_bind_key('\t', rl_insert);
    /* Bind both ESC-TAB and ESC-ESC to the completion function */
    rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
    rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
    /* Set our hook functions */
    rl_startup_hook = (Function *)on_startup_hook;
#ifdef HAVE_RL_PRE_INPUT_HOOK
    rl_pre_input_hook = (Function *)on_pre_input_hook;
#endif
    /* Set our completion function */
    rl_attempted_completion_function = (CPPFunction *)flex_complete;
    /* Set Python word break characters */
    completer_word_break_characters =
        rl_completer_word_break_characters =
        strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
        /* All nonalphanums except '.' */

    begidx = PyLong_FromLong(0L);
    endidx = PyLong_FromLong(0L);
    /* Initialize (allows .inputrc to override)
     *
     * XXX: A bug in the readline-2.2 library causes a memory leak
     * inside this function.  Nothing we can do about it.
     */
#ifdef __APPLE__
    if (using_libedit_emulation)
        rl_read_init_file(NULL);
    else
#endif /* __APPLE__ */
        rl_initialize();

    RESTORE_LOCALE(saved_locale)
}
Ejemplo n.º 4
0
static PyObject *
read_init_file(PyObject *self, PyObject *args)
{
	char *s = NULL;
	if (!PyArg_ParseTuple(args, "|z:read_init_file", &s))
		return NULL;
	errno = rl_read_init_file(s);
	if (errno)
		return PyErr_SetFromErrno(PyExc_IOError);
	Py_RETURN_NONE;
}
Ejemplo n.º 5
0
void
octave_rl_read_init_file (const char *f)
{
  rl_read_init_file (f);
}
Ejemplo n.º 6
0
static void
setup_readline(readlinestate *mod_state)
{
#ifdef SAVE_LOCALE
    char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
    if (!saved_locale)
        Py_FatalError("not enough memory to save locale");
#endif

#ifdef __APPLE__
    /* the libedit readline emulation resets key bindings etc
     * when calling rl_initialize.  So call it upfront
     */
    if (using_libedit_emulation)
        rl_initialize();

    /* Detect if libedit's readline emulation uses 0-based
     * indexing or 1-based indexing.
     */
    add_history("1");
    if (history_get(1) == NULL) {
        libedit_history_start = 0;
    } else {
        libedit_history_start = 1;
    }
    clear_history();
#endif /* __APPLE__ */

    using_history();

    rl_readline_name = "python";
    /* Force rebind of TAB to insert-tab */
    rl_bind_key('\t', rl_insert);
    /* Bind both ESC-TAB and ESC-ESC to the completion function */
    rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
    rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
#ifdef HAVE_RL_RESIZE_TERMINAL
    /* Set up signal handler for window resize */
    sigwinch_ohandler = PyOS_setsig(SIGWINCH, readline_sigwinch_handler);
#endif
    /* Set our hook functions */
    rl_startup_hook = on_startup_hook;
#ifdef HAVE_RL_PRE_INPUT_HOOK
    rl_pre_input_hook = on_pre_input_hook;
#endif
    /* Set our completion function */
    rl_attempted_completion_function = flex_complete;
    /* Set Python word break characters */
    completer_word_break_characters =
        rl_completer_word_break_characters =
        strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
        /* All nonalphanums except '.' */

    mod_state->begidx = PyLong_FromLong(0L);
    mod_state->endidx = PyLong_FromLong(0L);

#ifdef __APPLE__
    if (!using_libedit_emulation)
#endif
    {
        if (!isatty(STDOUT_FILENO)) {
            /* Issue #19884: stdout is not a terminal. Disable meta modifier
               keys to not write the ANSI sequence "\033[1034h" into stdout. On
               terminals supporting 8 bit characters like TERM=xterm-256color
               (which is now the default Fedora since Fedora 18), the meta key is
               used to enable support of 8 bit characters (ANSI sequence
               "\033[1034h").

               With libedit, this call makes readline() crash. */
            rl_variable_bind ("enable-meta-key", "off");
        }
    }

    /* Initialize (allows .inputrc to override)
     *
     * XXX: A bug in the readline-2.2 library causes a memory leak
     * inside this function.  Nothing we can do about it.
     */
#ifdef __APPLE__
    if (using_libedit_emulation)
        rl_read_init_file(NULL);
    else
#endif /* __APPLE__ */
        rl_initialize();

    RESTORE_LOCALE(saved_locale)
}
Ejemplo n.º 7
0
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()*/
Ejemplo n.º 8
0
static int
_inp_rl_startup_hook(void)
{
    rl_bind_keyseq("\\e1", _inp_rl_win_1_handler);
    rl_bind_keyseq("\\e2", _inp_rl_win_2_handler);
    rl_bind_keyseq("\\e3", _inp_rl_win_3_handler);
    rl_bind_keyseq("\\e4", _inp_rl_win_4_handler);
    rl_bind_keyseq("\\e5", _inp_rl_win_5_handler);
    rl_bind_keyseq("\\e6", _inp_rl_win_6_handler);
    rl_bind_keyseq("\\e7", _inp_rl_win_7_handler);
    rl_bind_keyseq("\\e8", _inp_rl_win_8_handler);
    rl_bind_keyseq("\\e9", _inp_rl_win_9_handler);
    rl_bind_keyseq("\\e0", _inp_rl_win_0_handler);

    rl_bind_keyseq("\\eOP", _inp_rl_win_1_handler);
    rl_bind_keyseq("\\eOQ", _inp_rl_win_2_handler);
    rl_bind_keyseq("\\eOR", _inp_rl_win_3_handler);
    rl_bind_keyseq("\\eOS", _inp_rl_win_4_handler);
    rl_bind_keyseq("\\e[15~", _inp_rl_win_5_handler);
    rl_bind_keyseq("\\e[17~", _inp_rl_win_6_handler);
    rl_bind_keyseq("\\e[18~", _inp_rl_win_7_handler);
    rl_bind_keyseq("\\e[19~", _inp_rl_win_8_handler);
    rl_bind_keyseq("\\e[20~", _inp_rl_win_9_handler);
    rl_bind_keyseq("\\e[21~", _inp_rl_win_0_handler);

    rl_bind_keyseq("\\e[1;9D", _inp_rl_win_prev_handler);
    rl_bind_keyseq("\\e[1;3D", _inp_rl_win_prev_handler);
    rl_bind_keyseq("\\e\\e[D", _inp_rl_win_prev_handler);

    rl_bind_keyseq("\\e[1;9C", _inp_rl_win_next_handler);
    rl_bind_keyseq("\\e[1;3C", _inp_rl_win_next_handler);
    rl_bind_keyseq("\\e\\e[C", _inp_rl_win_next_handler);

    rl_bind_keyseq("\\e\\e[5~", _inp_rl_subwin_pageup_handler);
    rl_bind_keyseq("\\e[5;3~", _inp_rl_subwin_pageup_handler);
    rl_bind_keyseq("\\e\\eOy", _inp_rl_subwin_pageup_handler);

    rl_bind_keyseq("\\e\\e[6~", _inp_rl_subwin_pagedown_handler);
    rl_bind_keyseq("\\e[6;3~", _inp_rl_subwin_pagedown_handler);
    rl_bind_keyseq("\\e\\eOs", _inp_rl_subwin_pagedown_handler);

    rl_bind_keyseq("\\e[5~", _inp_rl_win_pageup_handler);
    rl_bind_keyseq("\\eOy", _inp_rl_win_pageup_handler);
    rl_bind_keyseq("\\e[6~", _inp_rl_win_pagedown_handler);
    rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler);

    rl_bind_key('\t', _inp_rl_tab_handler);

    // unbind unwanted mappings
    rl_bind_keyseq("\\e=", NULL);

    // disable readline completion
    rl_variable_bind("disable-completion", "on");

    // check for and load ~/.config/profanity/inputrc
    char *inputrc = prefs_get_inputrc();
    if (inputrc) {
        rl_read_init_file(inputrc);
        free(inputrc);
    }

    return 0;
}
Ejemplo n.º 9
0
/*---------
 * readline
 *---------
 */
static int my_init_readline(char *name)
{
    int  i = 0;
    int  fd = 0;
    int  tmplen = 0;
    char *buf   = NULL;
    FILE *tmpfp = (FILE *)NULL;

    char nametmp[] = ".inputrc.XXXXXX";
    char tmpcmd[] = "rm -rf ";
    char *rc[] = {
            "#$include /etc/inputrc\n",
            "set editing-mode emacs\n",
            "set bell-style none\n",
            "set input-meta on\n",
            "set convert-meta on\n",
            "set output-meta on\n",
            "TAB: complete\n ",
            "Meta-Rubout: backward-kill-word\n",
            "\"\\C-a\": beginning-of-line\n",
            "\"\\C-e\": end-of-line\n",
            "\"\\C-f\": forward-char\n",
            "\"\\C-b\": backward-char\n",
            "\"\\C-p\": previous-history\n",
            "\"\\C-n\": next-history  \n",
            "\"\\C-k\": kill-line  \n",
            "\"\\C-u\": unix-line-discard \n",
            "\"\\C-d\": delete-char  \n",
            "\"\\C-h\": backward-delete-char  \n",
//            "\"  \":   \n",
            "\"\x7F\": backward-delete-char  \n",
            NULL
        };


    /********
     inputrc
     ********/
    fd = mkstemp(nametmp);
    //dbg("tmpfile:%s\n", nametmp);
    if (fd == -1) {
        fprintf(stderr, "fopen tmpfile error.");
        return -1;
    }

    for(i=0; rc[i] != NULL; i++) {
        tmplen = strlen(rc[i]);
        if (write(fd, rc[i], tmplen) != tmplen) {
            fprintf(stderr, "WARN: write inputrc fail(line: %d, func: %s).\n",
                __LINE__, __FUNCTION__);
        }
    }
    close(fd);
    fd = 0;

    rl_read_init_file(nametmp); 

    myrm(nametmp);

    rl_redisplay_function = myrl_noredisplay;  //remove outputs of readline();
    //rl_bind_key_in_map();//

    /*tmp file for rl_outstream*/
    tmpfp = tmpfile();
    if (!tmpfp) {
        fprintf(stderr, "can't open tmp stream for rl_outstream!\n");
        return -1;
    }
    rl_outstream = tmpfp;

    if ((fd = mkstemp(name)) == -1) {
        fprintf(stderr, "tmpfile err.\n");
        close(fd);
        return -1;
    }
    close(fd);

    return 0;
}