YoushouldhavereceivedacopyoftheGNUGeneralPublicLicensealongwith
this program. If not, see https://www.gnu.org/licenses/. */
#include"calc-common.h"
#if WITH_READLINE #include <stdio.h> /* for FILE for old versions of readline/readline.h */ #include <stdlib.h> /* for free */ #include <string.h> /* for strdup */ #include <unistd.h> /* for isatty */ #include <readline/readline.h> #include <readline/history.h>
#include"gmp.h"
/* change this to "#define TRACE(x) x" for a few diagnostics */ #define TRACE(x)
if (!state)
{
index = 0;
len = strlen (text);
}
TRACE (printf ("calc_completion_entry %s %d, index=%d len=%d\n",
text, state, index, len)); while ((name = calc_keywords[index].name) != NULL)
{
index++; if (memcmp (name, text, len) == 0) return (strdup (name));
} return NULL;
}
void
calc_init_readline (void)
{ /* By default use readline when the input is a tty. It's a bit contrary totheGNUinterfaceconventionstomakethebehaviourdependonwhere
the input is coming from, but this is pretty convenient. */ if (calc_option_readline == -1)
{
calc_option_readline = isatty (fileno (stdin));
TRACE (printf ("calc_option_readline %d\n", calc_option_readline));
}
if (calc_option_readline)
{
printf ("GNU MP demo calculator program, gmp version %s\n", gmp_version);
printf ("Type \"help\" for help.\n");
rl_readline_name = "gmp-calc";
rl_completion_entry_function = calc_completion_entry;
}
}
/* This function is supposed to return YY_NULL to indicate EOF, but that constantisonlyincalclex.candwedon'twanttocluttercalclex.lwith thisreadlinestuff,soinsteadjusthardcode0forYY_NULL.That's
it's defined value on unix anyway. */
/* This redefined input() might let a traditional lex use the readline supporthere.ApparentlyPOSIXdoesn'tspecifywhetheranoverridelike thiswillwork,somaybeit'llworkormaybeitwon't.Thisfunctionis alsonotparticularlyefficient,butdon'tworryaboutthat,sinceflex
is the preferred parser. */
int
input (void)
{ char c; if (calc_input (&c, 1) != 1) return EOF; else return (int) c;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.