X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=recover-src%2Fuscan.l;h=0e583b8f9936680859fae9d2c9c038fb48975818;hb=c6f0a88c567f8536c498f554285aed1f8150da18;hp=510d4965e00004a75dd0e7cbca57d816f16ca6c0;hpb=0de2ad0a86685398621fb8ffa6990c029681bb3a;p=debian%2Famanda diff --git a/recover-src/uscan.l b/recover-src/uscan.l index 510d496..0e583b8 100644 --- a/recover-src/uscan.l +++ b/recover-src/uscan.l @@ -1,5 +1,5 @@ /* - * Amanda, The Advanced Maryland Automatic Network Disk Archiver + * amanda, the advanced maryland automatic network disk archiver * Copyright (c) 1991-2000 University of Maryland at College Park * All Rights Reserved. * @@ -24,26 +24,44 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: uscan.l,v 1.14.2.3.4.1.2.2.2.1 2004/02/11 13:03:38 martinea Exp $ + * $Id$ * * lexer for amrecover interactive language */ %{ #include "amanda.h" -#undef ECHO #include "uparse.h" +/* + * We redefine this here to prevent compiler warning about ignoring fwrite + * return value... + */ +#undef ECHO +#define ECHO do { \ + if (fwrite(yytext, (size_t)yyleng, 1, yyout) <= 0) { \ + yyerror("ECHO failure"); \ + } \ +} while (0) + #define YY_NO_UNPUT -#define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD") /* includes null */ +#define YY_DECL int yylex(void) +extern int yylex(void); -extern void yyerror P((char *s)); -extern int yyparse P((void)); -static int ll_parse_date P((int type, char *text)); +extern void yyerror(char *s); +extern int yyparse(void); +int process_line(char *line); %} %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; %} @@ -54,85 +72,102 @@ static char *string_buf = NULL; /* literal keyword tokens */ %} -listdisk { return LISTDISK; } -sethost { return SETHOST; } -setdisk { return SETDISK; } -setdate { return SETDATE; } -setmode { return SETMODE; } -settape { return SETTAPE; } -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; } +settranslate { BEGIN(needstring); return SETTRANSLATE; } +-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); } +append { + BEGIN(propertypriority); + return APPEND; +} -%{ - /* file names */ -%} +priority { + BEGIN(needstring); + return PRIORITY; +} -[^ \t\r"]+ { - yylval.strval = stralloc(yytext); return PATH; +\" { + if(string_buf != NULL) { + g_printf("ERROR:string_buf != NULL: %s\n",string_buf); + } + BEGIN(quotedstring); + strappend(string_buf, yytext); } -%{ - /* quoted file names */ -%} +[^\\\"\n\r]+ { + strappend(string_buf, yytext); +} -\" { if(string_buf != NULL) {printf("ERROR:string_buf != NULL: %s\n",string_buf);}; BEGIN(quotedstring); } +\\. { + /* escaped character (including quote) */ + strappend(string_buf, yytext); +} -\" { /* saw closing quote - all done */ - BEGIN(INITIAL); - if(string_buf) { +\" { /* saw closing quote - all done */ + strappend(string_buf, yytext); yylval.strval = string_buf; string_buf = NULL; - } else { - yylval.strval = ""; - } - return PATH; + BEGIN(needstring); + return STRING; } -\\\" { - /* escaped quote */ - strappend(string_buf, "\\\""); +{LINEFEED} { + fprintf(stderr,"Unterminated quoted string\n"); + string_buf = NULL; + BEGIN(INITIAL); + return NL; } -\n { - /* error - unterminated string constant */ - yyerror("unterminated string"); - amfree(string_buf); -} +%{ + /* file names */ +%} -[^\\\n\"]+ { strappend(string_buf, yytext); } +[^[:space:][:cntrl:]"]+ { + yylval.strval = stralloc(yytext); + BEGIN(needstring); + return STRING; +} %{ /* whitespace */ %} -[ \t\r]+ ; /* whitespace */ +[[:space:]]+ ; /* whitespace */ %{ /* anything else */ @@ -147,59 +182,25 @@ mode { return MODE; } %% -int process_line(line) -char *line; +int +process_line( + char * 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(type, text) -int type; -char *text; -{ - time_t now; - struct tm *t; - int y, m, d; - int ret; - - now = time((time_t *)NULL); - t = localtime(&now); - y = 1900+t->tm_year; - m = t->tm_mon+1; - d = t->tm_mday; - if(type == 1) { - sscanf(text, "---%d", &d); - } else if(type == 2) { - sscanf(text, "--%d-%d", &m, &d); - } else { - sscanf(text, "%d-%d-%d", &y, &m, &d); - if(y < 70) { - y += 2000; - } else if(y < 100) { - y += 1900; - } - } - ret = PATH; /* cause a parse error */ - 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 { - yylval.strval = alloc(DATE_ALLOC_SIZE); - ap_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d); - ret = DATE; - } - return ret; -} -int yywrap() { +int +yywrap(void) +{ return 1; } +