X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=recover-src%2Fuscan.l;h=e62575d1b03e8200cbcaffcfe298d38185388f56;hb=fd48f3e498442f0cbff5f3606c7c403d0566150e;hp=8c86297cb631fd75c0116866d493620083cec884;hpb=96f35b20267e8b1a1c846d476f27fcd330e0b018;p=debian%2Famanda diff --git a/recover-src/uscan.l b/recover-src/uscan.l index 8c86297..e62575d 100644 --- a/recover-src/uscan.l +++ b/recover-src/uscan.l @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: uscan.l,v 1.27 2006/07/05 11:15:56 martinea Exp $ + * $Id$ * * lexer for amrecover interactive language */ @@ -45,19 +45,23 @@ #define YY_NO_UNPUT -#define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD-HH-MM-SS") /* includes null */ - #define YY_DECL int yylex(void) extern int yylex(void); extern void yyerror(char *s); extern int yyparse(void); -static int ll_parse_date(int type, char *text); int process_line(char *line); %} -%x quotedpath +%x quotedstring +%x needdevice +%x needstring +%x needmode +%x astring +%x propertyappend +%x propertypriority +LINEFEED [[:space:]]*("\n"|"\r"|"\r\n") %{ static char *string_buf = NULL; %} @@ -68,90 +72,101 @@ static char *string_buf = NULL; /* literal keyword tokens */ %} -listhost { return LISTHOST; } -listdisk { return LISTDISK; } -sethost { return SETHOST; } -setdisk { return SETDISK; } -setdate { return SETDATE; } -setmode { return SETMODE; } -settape { return SETTAPE; } -setdevice { return SETDEVICE; } --h { return DASH_H; } -cd { return CD; } -cdx { return CDX; } -quit { return QUIT; } -exit { return QUIT; } -history { return DHIST; } -ls { return LS; } -add { return ADD; } -addx { return ADDX; } -list { return LIST; } -delete { return DELETE; } -deletex { return DELETEX; } -pwd { return PWD; } -clear { return CLEAR; } -help { return HELP; } -\? { return HELP; } -lcd { return LCD; } -lpwd { return LPWD; } -extract { return EXTRACT; } -smb { return SMB; } -tar { return TAR; } -mode { return MODE; } +listhost { BEGIN(needstring); return LISTHOST; } +listdisk { BEGIN(needstring); return LISTDISK; } +listproperty { BEGIN(needstring); return LISTPROPERTY; } +sethost { BEGIN(needstring); return SETHOST; } +setdisk { BEGIN(needstring); return SETDISK; } +setdate { BEGIN(needstring); return SETDATE; } +setmode { BEGIN(needmode); return SETMODE; } +settape { BEGIN(needstring); return SETTAPE; } +setdevice { BEGIN(needdevice); return SETDEVICE; } +setproperty { BEGIN(propertyappend); return SETPROPERTY; } +-h { BEGIN(needstring); return DASH_H; } +cd { BEGIN(needstring); return CD; } +cdx { BEGIN(needstring); return CDX; } +quit { BEGIN(needstring); return QUIT; } +exit { BEGIN(needstring); return QUIT; } +history { BEGIN(needstring); return DHIST; } +ls { BEGIN(needstring); return LS; } +add { BEGIN(needstring); return ADD; } +addx { BEGIN(needstring); return ADDX; } +list { BEGIN(needstring); return LIST; } +delete { BEGIN(needstring); return DELETE; } +deletex { BEGIN(needstring); return DELETEX; } +pwd { BEGIN(needstring); return PWD; } +clear { BEGIN(needstring); return CLEAR; } +help { BEGIN(INITIAL); return HELP; } +\? { BEGIN(needstring); return HELP; } +lcd { BEGIN(needstring); return LCD; } +lpwd { BEGIN(needstring); return LPWD; } +extract { BEGIN(needstring); return EXTRACT; } +mode { BEGIN(needstring); return MODE; } +tar { BEGIN(needstring); return TAR; } +smb { BEGIN(needstring); return SMB; } +{LINEFEED} { BEGIN(INITIAL); return NL; } %{ - /* dates */ + /* quoted file names */ %} ----[0-9]+ { return ll_parse_date(1, yytext); } ---[0-9]+-[0-9]+ { return ll_parse_date(2, yytext); } -[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(3, yytext); } -[0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(4, yytext); } -[0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(5, yytext); } +append { + BEGIN(propertypriority); + return APPEND; +} -%{ - /* quoted file names */ -%} +priority { + BEGIN(needstring); + return PRIORITY; +} -\" { +\" { if(string_buf != NULL) { g_printf("ERROR:string_buf != NULL: %s\n",string_buf); } - BEGIN(quotedpath); + BEGIN(quotedstring); strappend(string_buf, yytext); } -[^\\\"]+ { +[^\\\"\n\r]+ { strappend(string_buf, yytext); } -\\. { +\\. { /* escaped character (including quote) */ strappend(string_buf, yytext); } -\" { /* saw closing quote - all done */ +\" { /* saw closing quote - all done */ strappend(string_buf, yytext); yylval.strval = string_buf; string_buf = NULL; + BEGIN(needstring); + return STRING; +} + +{LINEFEED} { + fprintf(stderr,"Unterminated quoted string\n"); + string_buf = NULL; BEGIN(INITIAL); - return PATH; + return NL; } %{ /* file names */ %} -[^[:space:][:cntrl:]"]+ { +[^[:space:][:cntrl:]"]+ { yylval.strval = stralloc(yytext); - return PATH; + BEGIN(needstring); + return STRING; } %{ /* whitespace */ %} -[[:space:]]+ ; /* whitespace */ +[[:space:]]+ ; /* whitespace */ %{ /* anything else */ @@ -173,86 +188,14 @@ process_line( YY_BUFFER_STATE b; int result; - b = yy_scan_string(line); /* tell lex to scan lineread */ + char *line1 = stralloc2(line, "\n"); + b = yy_scan_string(line1); /* tell lex to scan lineread */ result = yyparse(); /* parse lineread and act */ yy_delete_buffer(b); + amfree(line1); return result; } -static int -ll_parse_date( - int type, - char * text) -{ - time_t now; - struct tm *t; - int y=2000, m=0, d=1, h=0, mi=0, s=0; - int ret; - - now = time((time_t *)NULL); - t = localtime(&now); - if (t) { - y = 1900+t->tm_year; - m = t->tm_mon+1; - d = t->tm_mday; - } - switch(type) { - case 1: - if (sscanf(text, "---%d", &d) != 1) { - yyerror("invalid date"); - } - break; - case 2: - if (sscanf(text, "--%d-%d", &m, &d) != 2) { - yyerror("invalid date"); - } - break; - case 3: - if (sscanf(text, "%d-%d-%d", &y, &m, &d) != 3) { - yyerror("invalid date"); - } - break; - case 4: - if (sscanf(text, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) != 6) { - yyerror("invalid date"); - } - break; - case 5: - if (sscanf(text, "%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi) != 5) { - yyerror("invalid date"); - } - break; - } - - ret = PATH; /* cause a parse error */ - if(y < 70) { - y += 2000; - } else if(y < 100) { - y += 1900; - } - if(y < 1000 || y > 9999) { - yyerror("invalid year"); - } else if(m < 1 || m > 12) { - yyerror("invalid month"); - } else if(d < 1 || d > 31) { - yyerror("invalid day"); - } else if(h < 0 || h > 24) { - yyerror("invalid hour"); - } else if(mi < 0 || mi > 59) { - yyerror("invalid minute"); - } else if(s < 0 || s > 59) { - yyerror("invalid second"); - } else if(type < 4) { - yylval.strval = alloc(DATE_ALLOC_SIZE); - g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d); - ret = DATE; - } else { - yylval.strval = alloc(DATE_ALLOC_SIZE); - g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s); - ret = DATE; - } - return ret; -} int yywrap(void)