| 1 | /* |
| 2 | * JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors. |
| 3 | * Copyright (C) 2010 Sergey Gridassov <grindars@gmail.com> |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | %{ |
| 20 | #include "shell_internal.h" |
| 21 | #include <string.h> |
| 22 | #include <stdlib.h> |
| 23 | |
| 24 | static char *str_append(char *str, const char *src) { |
| 25 | if(str) { |
| 26 | size_t newlen = strlen(str) + strlen(src) + 1; |
| 27 | |
| 28 | char *newstr = malloc(newlen); |
| 29 | |
| 30 | strcpy(newstr, str); |
| 31 | strcat(newstr, src); |
| 32 | |
| 33 | free(str); |
| 34 | |
| 35 | return newstr; |
| 36 | } else |
| 37 | return strdup(src); |
| 38 | } |
| 39 | %} |
| 40 | %option noyywrap nounput noinput batch reentrant |
| 41 | |
| 42 | %x STR |
| 43 | %% |
| 44 | ["] { yyextra->strval = NULL; BEGIN(STR); } |
| 45 | ; return TOK_SEPARATOR; |
| 46 | [[:space:]]+ return TOK_SPACE; |
| 47 | [#] return TOK_COMMENT; |
| 48 | [^[:space:];"#]+ { yyextra->strval = strdup(yytext); return TOK_STRING; } |
| 49 | <STR>[^\\"]+ yyextra->strval = str_append(yyextra->strval, yytext); |
| 50 | <STR>\\["] yyextra->strval = str_append(yyextra->strval, "\""); |
| 51 | <STR>\\ yyextra->strval = str_append(yyextra->strval, "\\"); |
| 52 | <STR>["] { BEGIN(INITIAL); return TOK_STRING; } |
| 53 | |