aboutsummaryrefslogtreecommitdiff
path: root/src/lex.l
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-08-02 17:33:02 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-08-02 17:44:31 +0300
commit9016182fe92dcdfa9103acd144ab01f30463ac72 (patch)
treea96152de7f3af6c7b59dbf03f04d07a64dea34cb /src/lex.l
parent5557f48506e533cdf58fda35a38eb471d4736cb9 (diff)
downloadgdbm-9016182fe92dcdfa9103acd144ab01f30463ac72.tar.gz
gdbm-9016182fe92dcdfa9103acd144ab01f30463ac72.tar.bz2
Various fixes
* doc/gdbm.texi: Document manual crash recovery procedure. Document the gdbmtool "shell" command. Fix chapter headings (remove final point). Replace headings with sections. * src/gdbmopen.c (gdbm_header_avail): Remove const qualifier from 1st argument * src/proto.h (gdbm_file_sync): New proto. * src/gdbmsync.c (gdbm_file_sync): Moved from proto.h. (gdbm_sync): Call _gdbm_end_update to be sure all changes are written to disk. * src/gdbmtool.c: Implement the shell command. (command_lookup): Fix name prefix comparison. * src/gram.y: New token T_SHELL. * src/lex.l: Sub-lexers for shell arguments.
Diffstat (limited to 'src/lex.l')
-rw-r--r--src/lex.l85
1 files changed, 76 insertions, 9 deletions
diff --git a/src/lex.l b/src/lex.l
index 7faf046..1a57a3a 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -172,7 +172,7 @@ t_num (int base)
%option nounput
%option nodefault
-%x CMD STR MLSTR DEF
+%x CMD STR MLSTR DEF SHELLWS SHELL SHSTR SHQ
WS [ \t][ \t]*
IDENT [a-zA-Z_][a-zA-Z_0-9-]*
@@ -225,8 +225,20 @@ O [0-7]
<INITIAL>{
\? { BEGIN (CMD);
return command_lookup ("help", &yylloc, &yylval.cmd); }
-{IDENT} { BEGIN (CMD);
- return command_lookup (yytext, &yylloc, &yylval.cmd); }
+\! {
+ BEGIN (SHELLWS);
+ string_begin ();
+ return command_lookup ("shell", &yylloc, &yylval.cmd);
+ }
+{IDENT} {
+ int t;
+ t = command_lookup (yytext, &yylloc, &yylval.cmd);
+ if (t == T_SHELL)
+ BEGIN (SHELLWS);
+ else
+ BEGIN (CMD);
+ return t;
+ }
{WS} ;
}
@@ -258,7 +270,8 @@ pad { return T_PAD; }
memcpy (yylval.string, yytext+1, yyleng-2);
yylval.string[yyleng-2] = 0;
return T_WORD; }
-\"[^\\\"\n]*\\$ {
+\"[^\\\"\n]*\\\n {
+ advance_line ();
string_begin ();
string_add (yytext + 1, yyleng - 2);
BEGIN (MLSTR); }
@@ -277,11 +290,57 @@ pad { return T_PAD; }
yylval.string = string_end ();
BEGIN (CMD);
return T_WORD; }
-[^\\\"\n]*\\$ { string_add (yytext, yyleng - 1); }
+[^\\\"\n]*\\\n { advance_line ();
+ string_add (yytext, yyleng - 1); }
[^\\\"\n]*\\. { string_add (yytext, yyleng - 2);
string_addc (unescape (yytext[yyleng-1])); }
}
-
+
+<SHELLWS>{
+{WS} { BEGIN(SHELL); }
+"\n" {
+ BEGIN (INITIAL);
+ advance_line ();
+ return '\n';
+ }
+}
+
+<SHELL>{
+\\\n { advance_line (); string_add (yytext, yyleng); }
+\\. { string_add (yytext, yyleng); }
+\'[^\'\n]*\' { string_add (yytext, yyleng); }
+\'[^\'\n]*\n { advance_line ();
+ string_add (yytext, yyleng);
+ BEGIN (SHQ); }
+\"[^\\\"\n]*\" { string_add (yytext, yyleng); }
+\"[^\\\"\n]*\n { advance_line ();
+ string_add (yytext, yyleng);
+ BEGIN (SHSTR); }
+\"[^\\\"\n]*\\. { string_add (yytext, yyleng);
+ BEGIN (SHSTR); }
+"\n" {
+ BEGIN (INITIAL);
+ advance_line ();
+ yyless (0);
+ yylval.string = string_end ();
+ return T_WORD;
+ }
+. string_addc (yytext[0]);
+}
+
+<SHSTR>{
+[^\\\"]*\\. { string_add (yytext, yyleng); }
+[^\\\"]*\" { string_add (yytext, yyleng);
+ BEGIN (SHELL); }
+}
+
+<SHQ>{
+[^\'\n]*\n { advance_line ();
+ string_add (yytext, yyleng); }
+[^\'\n]*\' { string_add (yytext, yyleng);
+ BEGIN (SHELL); }
+}
+
<*>\n { BEGIN (INITIAL); advance_line (); return '\n'; }
<INITIAL,CMD,DEF>. return yytext[0];
@@ -510,9 +569,17 @@ expand_char (int c, struct slist **tailp)
char const *
psname (void)
{
- if (YYSTATE == DEF || YYSTATE == MLSTR)
- return "ps2";
- return "ps1";
+ switch (YYSTATE)
+ {
+ case DEF:
+ case MLSTR:
+ case SHSTR:
+ case SHQ:
+ return "ps2";
+
+ default:
+ return "ps1";
+ }
}
char *

Return to:

Send suggestions and report system problems to the System administrator.