summaryrefslogtreecommitdiffabout
path: root/src/lex.l
Side-by-side diff
Diffstat (limited to 'src/lex.l') (more/less context) (ignore whitespace changes)
-rw-r--r--src/lex.l134
1 files changed, 80 insertions, 54 deletions
diff --git a/src/lex.l b/src/lex.l
index 9c2c5f8..236474d 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -48,3 +48,3 @@ advance_line ()
{ \
- result = read_input (buf, max_size); \
+ result = input_read (yyin, buf, max_size); \
} \
@@ -58,4 +58,2 @@ int unescape (int c);
-static ssize_t read_input (char *buf, size_t size);
-
struct context /* Input context */
@@ -317,14 +315,12 @@ end_def (void)
-static ssize_t
-read_input (char *buf, size_t size)
+void
+print_prompt_at_bol (void)
{
- if (interactive)
+ if (YY_AT_BOL ())
{
- if (YY_AT_BOL ())
- print_prompt ();
- if (fgets (buf, size, yyin) == NULL)
- return 0;
- return strlen (buf);
+ char *s = make_prompt ();
+ fputs (s, stdout);
+ fflush (stdout);
+ free (s);
}
- return fread (buf, 1, size, yyin);
}
@@ -455,33 +451,30 @@ lerror (struct locus *loc, const char *fmt, ...)
-struct prompt_exp;
-
-void
-pe_file_name (struct prompt_exp *p)
+static struct slist *
+pe_file_name (void)
{
- if (file_name)
- fwrite (file_name, strlen (file_name), 1, stdout);
+ return file_name ? slist_new (file_name) : NULL;
}
-void
-pe_program_name (struct prompt_exp *p)
+static struct slist *
+pe_program_name (void)
{
- fwrite (progname, strlen (progname), 1, stdout);
+ return slist_new (progname);
}
-void
-pe_package_name (struct prompt_exp *p)
+static struct slist *
+pe_package_name (void)
{
- fwrite (PACKAGE_NAME, sizeof (PACKAGE_NAME) - 1, 1, stdout);
+ return slist_new (PACKAGE_NAME);
}
-void
-pe_program_version (struct prompt_exp *p)
+static struct slist *
+pe_program_version (void)
{
- fwrite (PACKAGE_VERSION, sizeof (PACKAGE_VERSION) - 1, 1, stdout);
+ return slist_new (PACKAGE_VERSION);
}
-void
-pe_space (struct prompt_exp *p)
+static struct slist *
+pe_space (void)
{
- fwrite (" ", 1, 1, stdout);
+ return slist_new (" ");
}
@@ -491,4 +484,3 @@ struct prompt_exp
int ch;
- void (*fun) (struct prompt_exp *);
- char *cache;
+ struct slist *(*fun) (void);
};
@@ -504,4 +496,4 @@ struct prompt_exp prompt_exp[] = {
-static void
-expand_char (int c)
+static int
+expand_char (int c, struct slist **tailp)
{
@@ -515,6 +507,6 @@ expand_char (int c)
{
- if (p->cache)
- free (p->cache);
- p->fun (p);
- return;
+ struct slist *s = p->fun ();
+ if (s)
+ slist_insert (tailp, s);
+ return 0;
}
@@ -522,4 +514,3 @@ expand_char (int c)
}
- putchar ('%');
- putchar (c);
+ return 1;
}
@@ -527,3 +518,3 @@ expand_char (int c)
char const *
-psname ()
+psname (void)
{
@@ -534,4 +525,4 @@ psname ()
-void
-print_prompt ()
+char *
+make_prompt (void)
{
@@ -539,3 +530,6 @@ print_prompt ()
const char *prompt;
-
+ struct slist *head = NULL, *tail = NULL, *p;
+ char *ret, *end;
+ size_t len;
+
switch (variable_get (psname (), VART_STRING, (void *) &prompt))
@@ -546,3 +540,3 @@ print_prompt ()
case VAR_ERR_NOTSET:
- return;
+ return NULL;
@@ -551,19 +545,51 @@ print_prompt ()
}
-
- for (s = prompt; *s; s++)
+
+ for (s = prompt; *s; )
{
- if (*s == '%')
+ if (*s == '%' && s[1])
{
- if (!*++s)
+ if (s > prompt)
+ {
+ slist_insert (&tail, slist_new_l (prompt, s - prompt));
+ if (!head)
+ head = tail;
+ }
+ if (expand_char (s[1], &tail) == 0)
{
- putchar ('%');
- break;
+ if (!head)
+ head = tail;
+ prompt = s + 2;
}
- expand_char (*s);
+ else
+ prompt = s;
+ s += 2;
}
else
- putchar (*s);
+ ++s;
+ }
+
+ if (s > prompt)
+ {
+ slist_insert (&tail, slist_new_l (prompt, s - prompt));
+ if (!head)
+ head = tail;
}
- fflush (stdout);
+ len = 0;
+ for (p = head; p; p = p->next)
+ len += strlen (p->str);
+
+ ret = emalloc (len + 1);
+ end = ret;
+ for (p = head; p; p = p->next)
+ {
+ s = p->str;
+ while (*s)
+ *end++ = *s++;
+ }
+ *end = 0;
+
+ slist_free (head);
+
+ return ret;
}

Return to:

Send suggestions and report system problems to the System administrator.