| File: | libexec/got-read-gotconfig/obj/parse.c |
| Warning: | line 882, column 13 Attempt to free released memory |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | #include <stdlib.h> | |||
| 2 | #include <string.h> | |||
| 3 | #define YYBYACC1 1 | |||
| 4 | #define YYMAJOR1 1 | |||
| 5 | #define YYMINOR9 9 | |||
| 6 | #define YYLEXyylex() yylex() | |||
| 7 | #define YYEMPTY-1 -1 | |||
| 8 | #define yyclearin(yychar=(-1)) (yychar=(YYEMPTY-1)) | |||
| 9 | #define yyerrok(yyerrflag=0) (yyerrflag=0) | |||
| 10 | #define YYRECOVERING()(yyerrflag!=0) (yyerrflag!=0) | |||
| 11 | #define YYPREFIX"yy" "yy" | |||
| 12 | #line 25 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 13 | #include <sys/types.h> | |||
| 14 | #include <sys/queue.h> | |||
| 15 | ||||
| 16 | #include <netdb.h> | |||
| 17 | ||||
| 18 | #include <ctype.h> | |||
| 19 | #include <err.h> | |||
| 20 | #include <errno(*__errno()).h> | |||
| 21 | #include <limits.h> | |||
| 22 | #include <stdarg.h> | |||
| 23 | #include <stdio.h> | |||
| 24 | #include <stdlib.h> | |||
| 25 | #include <string.h> | |||
| 26 | ||||
| 27 | #include "got_error.h" | |||
| 28 | #include "gotconfig.h" | |||
| 29 | ||||
| 30 | static struct file { | |||
| 31 | FILE *stream; | |||
| 32 | const char *name; | |||
| 33 | size_t ungetpos; | |||
| 34 | size_t ungetsize; | |||
| 35 | u_char *ungetbuf; | |||
| 36 | int eof_reached; | |||
| 37 | int lineno; | |||
| 38 | } *file; | |||
| 39 | static const struct got_error* newfile(struct file**, const char *, int *); | |||
| 40 | static void closefile(struct file *); | |||
| 41 | int yyparse(void); | |||
| 42 | int yylex(void); | |||
| 43 | int yyerror(const char *, ...) | |||
| 44 | __attribute__((__format__ (printf, 1, 2))) | |||
| 45 | __attribute__((__nonnull__ (1))); | |||
| 46 | int kw_cmp(const void *, const void *); | |||
| 47 | int lookup(char *); | |||
| 48 | int igetc(void); | |||
| 49 | int lgetc(int); | |||
| 50 | void lungetc(int); | |||
| 51 | int findeol(void); | |||
| 52 | static int parseport(char *, long long *); | |||
| 53 | ||||
| 54 | TAILQ_HEAD(symhead, sym)struct symhead { struct sym *tqh_first; struct sym **tqh_last ; } symhead = TAILQ_HEAD_INITIALIZER(symhead){ ((void *)0), &(symhead).tqh_first }; | |||
| 55 | struct sym { | |||
| 56 | TAILQ_ENTRY(sym)struct { struct sym *tqe_next; struct sym **tqe_prev; } entry; | |||
| 57 | int used; | |||
| 58 | int persist; | |||
| 59 | char *nam; | |||
| 60 | char *val; | |||
| 61 | }; | |||
| 62 | ||||
| 63 | int symset(const char *, const char *, int); | |||
| 64 | char *symget(const char *); | |||
| 65 | ||||
| 66 | static int atoul(char *, u_long *); | |||
| 67 | ||||
| 68 | static const struct got_error* gerror; | |||
| 69 | static struct gotconfig_remote_repo *remote; | |||
| 70 | static struct gotconfig gotconfig; | |||
| 71 | static const struct got_error* new_remote(struct gotconfig_remote_repo **); | |||
| 72 | ||||
| 73 | typedef struct { | |||
| 74 | union { | |||
| 75 | long long number; | |||
| 76 | char *string; | |||
| 77 | struct node_branch *branch; | |||
| 78 | struct node_ref *ref; | |||
| 79 | } v; | |||
| 80 | int lineno; | |||
| 81 | } YYSTYPE; | |||
| 82 | ||||
| 83 | #line 84 "parse.c" | |||
| 84 | #define ERROR257 257 | |||
| 85 | #define REMOTE258 258 | |||
| 86 | #define REPOSITORY259 259 | |||
| 87 | #define SERVER260 260 | |||
| 88 | #define PORT261 261 | |||
| 89 | #define PROTOCOL262 262 | |||
| 90 | #define MIRROR_REFERENCES263 263 | |||
| 91 | #define BRANCH264 264 | |||
| 92 | #define AUTHOR265 265 | |||
| 93 | #define FETCH_ALL_BRANCHES266 266 | |||
| 94 | #define REFERENCE267 267 | |||
| 95 | #define STRING268 268 | |||
| 96 | #define NUMBER269 269 | |||
| 97 | #define YYERRCODE256 256 | |||
| 98 | const short yylhs[] = | |||
| 99 | { -1, | |||
| 100 | 0, 0, 0, 0, 1, 3, 3, 2, 4, 4, | |||
| 101 | 4, 5, 6, 6, 7, 7, 7, 8, 9, 9, | |||
| 102 | 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, | |||
| 103 | 17, 11, 10, 12, 12, 16, 13, 13, | |||
| 104 | }; | |||
| 105 | const short yylen[] = | |||
| 106 | { 2, | |||
| 107 | 0, 2, 3, 3, 1, 1, 1, 1, 0, 1, | |||
| 108 | 4, 1, 2, 4, 0, 1, 4, 1, 2, 4, | |||
| 109 | 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |||
| 110 | 0, 7, 2, 2, 0, 2, 1, 0, | |||
| 111 | }; | |||
| 112 | const short yydefred[] = | |||
| 113 | { 1, | |||
| 114 | 0, 0, 0, 2, 0, 0, 31, 33, 3, 4, | |||
| 115 | 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, | |||
| 116 | 0, 0, 0, 0, 0, 23, 24, 7, 6, 28, | |||
| 117 | 8, 25, 5, 26, 12, 0, 29, 10, 27, 18, | |||
| 118 | 0, 30, 16, 32, 0, 22, 0, 0, 0, 21, | |||
| 119 | 0, 0, 0, 0, 36, 13, 11, 37, 0, 19, | |||
| 120 | 17, 0, 0, 0, 14, 20, | |||
| 121 | }; | |||
| 122 | const short yydgoto[] = | |||
| 123 | { 1, | |||
| 124 | 34, 30, 31, 37, 38, 52, 42, 43, 54, 5, | |||
| 125 | 6, 14, 59, 24, 25, 50, 11, | |||
| 126 | }; | |||
| 127 | const short yysindex[] = | |||
| 128 | { 0, | |||
| 129 | 6, -258, -254, 0, 5, 8, 0, 0, 0, 0, | |||
| 130 | -103, 11, 11, -211, 0, -244, -243, -256, -241, -240, | |||
| 131 | -120, -240, -119, -108, 11, 0, 0, 0, 0, 0, | |||
| 132 | 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, | |||
| 133 | 11, 0, 0, 0, 19, 0, -237, -236, 11, 0, | |||
| 134 | 11, -39, 11, -38, 0, 0, 0, 0, -237, 0, | |||
| 135 | 0, -236, 11, 11, 0, 0,}; | |||
| 136 | const short yyrindex[] = | |||
| 137 | { 0, | |||
| 138 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 139 | 0, -200, -43, 0, 0, 0, 0, 0, 0, 0, | |||
| 140 | -10, 0, -1, 0, -99, 0, 0, 0, 0, 0, | |||
| 141 | 0, 0, 0, 0, 0, -237, 0, 0, 0, 0, | |||
| 142 | -237, 0, 0, 0, 0, 0, 0, 0, -99, 0, | |||
| 143 | -42, -235, -42, -235, 0, 0, 0, 0, 0, 0, | |||
| 144 | 0, 0, -42, -42, 0, 0,}; | |||
| 145 | const short yygindex[] = | |||
| 146 | { 0, | |||
| 147 | 12, 0, 0, 0, -36, 0, 0, -40, 0, 0, | |||
| 148 | 0, -6, -18, 0, 13, 0, 0, | |||
| 149 | }; | |||
| 150 | #define YYTABLESIZE271 271 | |||
| 151 | const short yytable[] = | |||
| 152 | { 9, | |||
| 153 | 35, 35, 36, 41, 58, 58, 15, 53, 15, 7, | |||
| 154 | 51, 28, 29, 8, 9, 4, 44, 10, 46, 12, | |||
| 155 | 13, 64, 63, 26, 27, 35, 32, 33, 49, 47, | |||
| 156 | 35, 40, 38, 39, 48, 62, 45, 0, 0, 0, | |||
| 157 | 0, 0, 55, 0, 56, 0, 60, 16, 17, 18, | |||
| 158 | 19, 20, 21, 0, 22, 23, 65, 66, 35, 35, | |||
| 159 | 35, 35, 35, 35, 0, 35, 35, 0, 0, 0, | |||
| 160 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 161 | 0, 35, 35, 0, 0, 57, 61, 0, 0, 0, | |||
| 162 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 163 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 164 | 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, | |||
| 165 | 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, | |||
| 166 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 167 | 0, 0, 0, 0, 0, 0, 0, 35, 40, 0, | |||
| 168 | 16, 17, 18, 19, 20, 21, 0, 22, 23, 35, | |||
| 169 | 35, 35, 35, 35, 35, 0, 35, 35, 0, 0, | |||
| 170 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 171 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 172 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 173 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 174 | 0, 0, 0, 0, 0, 35, 35, 35, 35, 35, | |||
| 175 | 35, 0, 35, 35, 35, 35, 0, 0, 0, 0, | |||
| 176 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
| 177 | 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, | |||
| 178 | 9, 9, 9, 9, 0, 9, 9, 15, 15, 15, | |||
| 179 | 15, 15, 15, 2, 15, 15, 0, 0, 0, 0, | |||
| 180 | 3, | |||
| 181 | }; | |||
| 182 | const short yycheck[] = | |||
| 183 | { 10, | |||
| 184 | 44, 44, 123, 123, 44, 44, 13, 48, 10, 268, | |||
| 185 | 47, 268, 269, 268, 10, 10, 125, 10, 25, 123, | |||
| 186 | 10, 62, 59, 268, 268, 125, 268, 268, 10, 36, | |||
| 187 | 268, 268, 268, 22, 41, 54, 24, -1, -1, -1, | |||
| 188 | -1, -1, 49, -1, 51, -1, 53, 259, 260, 261, | |||
| 189 | 262, 263, 264, -1, 266, 267, 63, 64, 259, 260, | |||
| 190 | 261, 262, 263, 264, -1, 266, 267, -1, -1, -1, | |||
| 191 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 192 | -1, 125, 125, -1, -1, 125, 125, -1, -1, -1, | |||
| 193 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 194 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 195 | -1, -1, -1, -1, 125, -1, -1, -1, -1, -1, | |||
| 196 | -1, -1, -1, 125, -1, -1, -1, -1, -1, -1, | |||
| 197 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 198 | -1, -1, -1, -1, -1, -1, -1, 268, 268, -1, | |||
| 199 | 259, 260, 261, 262, 263, 264, -1, 266, 267, 259, | |||
| 200 | 260, 261, 262, 263, 264, -1, 266, 267, -1, -1, | |||
| 201 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 202 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 203 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 204 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 205 | -1, -1, -1, -1, -1, 259, 260, 261, 262, 263, | |||
| 206 | 264, -1, 266, 267, 268, 268, -1, -1, -1, -1, | |||
| 207 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
| 208 | -1, -1, -1, -1, -1, -1, -1, -1, 259, 260, | |||
| 209 | 261, 262, 263, 264, -1, 266, 267, 259, 260, 261, | |||
| 210 | 262, 263, 264, 258, 266, 267, -1, -1, -1, -1, | |||
| 211 | 265, | |||
| 212 | }; | |||
| 213 | #define YYFINAL1 1 | |||
| 214 | #ifndef YYDEBUG0 | |||
| 215 | #define YYDEBUG0 0 | |||
| 216 | #endif | |||
| 217 | #define YYMAXTOKEN269 269 | |||
| 218 | #if YYDEBUG0 | |||
| 219 | const char * const yyname[] = | |||
| 220 | { | |||
| 221 | "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |||
| 222 | 0,0,0,0,0,0,0,0,0,0,0,0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |||
| 223 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |||
| 224 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'{'",0,"'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |||
| 225 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |||
| 226 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |||
| 227 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"ERROR", | |||
| 228 | "REMOTE","REPOSITORY","SERVER","PORT","PROTOCOL","MIRROR_REFERENCES","BRANCH", | |||
| 229 | "AUTHOR","FETCH_ALL_BRANCHES","REFERENCE","STRING","NUMBER", | |||
| 230 | }; | |||
| 231 | const char * const yyrule[] = | |||
| 232 | {"$accept : grammar", | |||
| 233 | "grammar :", | |||
| 234 | "grammar : grammar '\\n'", | |||
| 235 | "grammar : grammar author '\\n'", | |||
| 236 | "grammar : grammar remote '\\n'", | |||
| 237 | "boolean : STRING", | |||
| 238 | "numberstring : NUMBER", | |||
| 239 | "numberstring : STRING", | |||
| 240 | "portplain : numberstring", | |||
| 241 | "branch :", | |||
| 242 | "branch : xbranch", | |||
| 243 | "branch : '{' optnl branch_list '}'", | |||
| 244 | "xbranch : STRING", | |||
| 245 | "branch_list : xbranch optnl", | |||
| 246 | "branch_list : branch_list comma xbranch optnl", | |||
| 247 | "ref :", | |||
| 248 | "ref : xref", | |||
| 249 | "ref : '{' optnl ref_list '}'", | |||
| 250 | "xref : STRING", | |||
| 251 | "ref_list : xref optnl", | |||
| 252 | "ref_list : ref_list comma xref optnl", | |||
| 253 | "remoteopts2 : remoteopts2 remoteopts1 nl", | |||
| 254 | "remoteopts2 : remoteopts1 optnl", | |||
| 255 | "remoteopts1 : REPOSITORY STRING", | |||
| 256 | "remoteopts1 : SERVER STRING", | |||
| 257 | "remoteopts1 : PROTOCOL STRING", | |||
| 258 | "remoteopts1 : MIRROR_REFERENCES boolean", | |||
| 259 | "remoteopts1 : FETCH_ALL_BRANCHES boolean", | |||
| 260 | "remoteopts1 : PORT portplain", | |||
| 261 | "remoteopts1 : BRANCH branch", | |||
| 262 | "remoteopts1 : REFERENCE ref", | |||
| 263 | "$$1 :", | |||
| 264 | "remote : REMOTE STRING $$1 '{' optnl remoteopts2 '}'", | |||
| 265 | "author : AUTHOR STRING", | |||
| 266 | "optnl : '\\n' optnl", | |||
| 267 | "optnl :", | |||
| 268 | "nl : '\\n' optnl", | |||
| 269 | "comma : ','", | |||
| 270 | "comma :", | |||
| 271 | }; | |||
| 272 | #endif | |||
| 273 | #ifdef YYSTACKSIZE10000 | |||
| 274 | #undef YYMAXDEPTH10000 | |||
| 275 | #define YYMAXDEPTH10000 YYSTACKSIZE10000 | |||
| 276 | #else | |||
| 277 | #ifdef YYMAXDEPTH10000 | |||
| 278 | #define YYSTACKSIZE10000 YYMAXDEPTH10000 | |||
| 279 | #else | |||
| 280 | #define YYSTACKSIZE10000 10000 | |||
| 281 | #define YYMAXDEPTH10000 10000 | |||
| 282 | #endif | |||
| 283 | #endif | |||
| 284 | #define YYINITSTACKSIZE200 200 | |||
| 285 | /* LINTUSED */ | |||
| 286 | int yydebug; | |||
| 287 | int yynerrs; | |||
| 288 | int yyerrflag; | |||
| 289 | int yychar; | |||
| 290 | short *yyssp; | |||
| 291 | YYSTYPE *yyvsp; | |||
| 292 | YYSTYPE yyval; | |||
| 293 | YYSTYPE yylval; | |||
| 294 | short *yyss; | |||
| 295 | short *yysslim; | |||
| 296 | YYSTYPE *yyvs; | |||
| 297 | unsigned int yystacksize; | |||
| 298 | int yyparse(void); | |||
| 299 | #line 275 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 300 | ||||
| 301 | struct keywords { | |||
| 302 | const char *k_name; | |||
| 303 | int k_val; | |||
| 304 | }; | |||
| 305 | ||||
| 306 | int | |||
| 307 | yyerror(const char *fmt, ...) | |||
| 308 | { | |||
| 309 | va_list ap; | |||
| 310 | char *msg; | |||
| 311 | char *err = NULL((void *)0); | |||
| 312 | ||||
| 313 | va_start(ap, fmt)__builtin_va_start(ap, fmt); | |||
| 314 | if (vasprintf(&msg, fmt, ap) == -1) { | |||
| 315 | gerror = got_error_from_errno("vasprintf"); | |||
| 316 | return 0; | |||
| 317 | } | |||
| 318 | va_end(ap)__builtin_va_end(ap); | |||
| 319 | if (asprintf(&err, "%s: line %d: %s", file->name, yylval.lineno, | |||
| 320 | msg) == -1) { | |||
| 321 | gerror = got_error_from_errno("asprintf"); | |||
| 322 | return(0); | |||
| 323 | } | |||
| 324 | gerror = got_error_msg(GOT_ERR_PARSE_CONFIG127, strdup(err)); | |||
| 325 | free(msg); | |||
| 326 | free(err); | |||
| 327 | return(0); | |||
| 328 | } | |||
| 329 | int | |||
| 330 | kw_cmp(const void *k, const void *e) | |||
| 331 | { | |||
| 332 | return (strcmp(k, ((const struct keywords *)e)->k_name)); | |||
| 333 | } | |||
| 334 | ||||
| 335 | int | |||
| 336 | lookup(char *s) | |||
| 337 | { | |||
| 338 | /* This has to be sorted always. */ | |||
| 339 | static const struct keywords keywords[] = { | |||
| 340 | {"author", AUTHOR265}, | |||
| 341 | {"branch", BRANCH264}, | |||
| 342 | {"fetch-all-branches", FETCH_ALL_BRANCHES266}, | |||
| 343 | {"mirror-references", MIRROR_REFERENCES263}, | |||
| 344 | {"port", PORT261}, | |||
| 345 | {"protocol", PROTOCOL262}, | |||
| 346 | {"reference", REFERENCE267}, | |||
| 347 | {"remote", REMOTE258}, | |||
| 348 | {"repository", REPOSITORY259}, | |||
| 349 | {"server", SERVER260}, | |||
| 350 | }; | |||
| 351 | const struct keywords *p; | |||
| 352 | ||||
| 353 | p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]), | |||
| 354 | sizeof(keywords[0]), kw_cmp); | |||
| 355 | ||||
| 356 | if (p) | |||
| 357 | return (p->k_val); | |||
| 358 | else | |||
| 359 | return (STRING268); | |||
| 360 | } | |||
| 361 | ||||
| 362 | #define START_EXPAND1 1 | |||
| 363 | #define DONE_EXPAND2 2 | |||
| 364 | ||||
| 365 | static int expanding; | |||
| 366 | ||||
| 367 | int | |||
| 368 | igetc(void) | |||
| 369 | { | |||
| 370 | int c; | |||
| 371 | ||||
| 372 | while (1) { | |||
| 373 | if (file->ungetpos > 0) | |||
| 374 | c = file->ungetbuf[--file->ungetpos]; | |||
| 375 | else | |||
| 376 | c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget (file->stream) : (int)(*(file->stream)->_p++)) : (getc )(file->stream)); | |||
| 377 | ||||
| 378 | if (c == START_EXPAND1) | |||
| 379 | expanding = 1; | |||
| 380 | else if (c == DONE_EXPAND2) | |||
| 381 | expanding = 0; | |||
| 382 | else | |||
| 383 | break; | |||
| 384 | } | |||
| 385 | return (c); | |||
| 386 | } | |||
| 387 | ||||
| 388 | int | |||
| 389 | lgetc(int quotec) | |||
| 390 | { | |||
| 391 | int c, next; | |||
| 392 | ||||
| 393 | if (quotec) { | |||
| 394 | c = igetc(); | |||
| 395 | if (c == EOF(-1)) { | |||
| 396 | yyerror("reached end of file while parsing " | |||
| 397 | "quoted string"); | |||
| 398 | } | |||
| 399 | return (c); | |||
| 400 | } | |||
| 401 | ||||
| 402 | c = igetc(); | |||
| 403 | while (c == '\\') { | |||
| 404 | next = igetc(); | |||
| 405 | if (next != '\n') { | |||
| 406 | c = next; | |||
| 407 | break; | |||
| 408 | } | |||
| 409 | yylval.lineno = file->lineno; | |||
| 410 | file->lineno++; | |||
| 411 | } | |||
| 412 | ||||
| 413 | return (c); | |||
| 414 | } | |||
| 415 | ||||
| 416 | void | |||
| 417 | lungetc(int c) | |||
| 418 | { | |||
| 419 | if (c == EOF(-1)) | |||
| 420 | return; | |||
| 421 | ||||
| 422 | if (file->ungetpos >= file->ungetsize) { | |||
| 423 | void *p = reallocarray(file->ungetbuf, file->ungetsize, 2); | |||
| 424 | if (p == NULL((void *)0)) | |||
| 425 | err(1, "%s", __func__); | |||
| 426 | file->ungetbuf = p; | |||
| 427 | file->ungetsize *= 2; | |||
| 428 | } | |||
| 429 | file->ungetbuf[file->ungetpos++] = c; | |||
| 430 | } | |||
| 431 | ||||
| 432 | int | |||
| 433 | findeol(void) | |||
| 434 | { | |||
| 435 | int c; | |||
| 436 | ||||
| 437 | /* Skip to either EOF or the first real EOL. */ | |||
| 438 | while (1) { | |||
| 439 | c = lgetc(0); | |||
| 440 | if (c == '\n') { | |||
| 441 | file->lineno++; | |||
| 442 | break; | |||
| 443 | } | |||
| 444 | if (c == EOF(-1)) | |||
| 445 | break; | |||
| 446 | } | |||
| 447 | return (ERROR257); | |||
| 448 | } | |||
| 449 | ||||
| 450 | static long long | |||
| 451 | getservice(char *n) | |||
| 452 | { | |||
| 453 | struct servent *s; | |||
| 454 | u_long ulval; | |||
| 455 | ||||
| 456 | if (atoul(n, &ulval) == 0) { | |||
| 457 | if (ulval > 65535) { | |||
| 458 | yyerror("illegal port value %lu", ulval); | |||
| 459 | return (-1); | |||
| 460 | } | |||
| 461 | return ulval; | |||
| 462 | } else { | |||
| 463 | s = getservbyname(n, "tcp"); | |||
| 464 | if (s == NULL((void *)0)) | |||
| 465 | s = getservbyname(n, "udp"); | |||
| 466 | if (s == NULL((void *)0)) { | |||
| 467 | yyerror("unknown port %s", n); | |||
| 468 | return (-1); | |||
| 469 | } | |||
| 470 | return (s->s_port); | |||
| 471 | } | |||
| 472 | } | |||
| 473 | ||||
| 474 | static int | |||
| 475 | parseport(char *port, long long *pn) | |||
| 476 | { | |||
| 477 | if ((*pn = getservice(port)) == -1) { | |||
| 478 | *pn = 0LL; | |||
| 479 | return (-1); | |||
| 480 | } | |||
| 481 | return (0); | |||
| 482 | } | |||
| 483 | ||||
| 484 | ||||
| 485 | int | |||
| 486 | yylex(void) | |||
| 487 | { | |||
| 488 | unsigned char buf[8096]; | |||
| 489 | unsigned char *p, *val; | |||
| 490 | int quotec, next, c; | |||
| 491 | int token; | |||
| 492 | ||||
| 493 | top: | |||
| 494 | p = buf; | |||
| 495 | c = lgetc(0); | |||
| 496 | while (c == ' ' || c == '\t') | |||
| 497 | c = lgetc(0); /* nothing */ | |||
| 498 | ||||
| 499 | yylval.lineno = file->lineno; | |||
| 500 | if (c == '#') { | |||
| 501 | c = lgetc(0); | |||
| 502 | while (c != '\n' && c != EOF(-1)) | |||
| 503 | c = lgetc(0); /* nothing */ | |||
| 504 | } | |||
| 505 | if (c == '$' && !expanding) { | |||
| 506 | while (1) { | |||
| 507 | c = lgetc(0); | |||
| 508 | if (c == EOF(-1)) | |||
| 509 | return (0); | |||
| 510 | ||||
| 511 | if (p + 1 >= buf + sizeof(buf) - 1) { | |||
| 512 | yyerror("string too long"); | |||
| 513 | return (findeol()); | |||
| 514 | } | |||
| 515 | if (isalnum(c) || c == '_') { | |||
| 516 | *p++ = c; | |||
| 517 | continue; | |||
| 518 | } | |||
| 519 | *p = '\0'; | |||
| 520 | lungetc(c); | |||
| 521 | break; | |||
| 522 | } | |||
| 523 | val = symget(buf); | |||
| 524 | if (val == NULL((void *)0)) { | |||
| 525 | yyerror("macro '%s' not defined", buf); | |||
| 526 | return (findeol()); | |||
| 527 | } | |||
| 528 | p = val + strlen(val) - 1; | |||
| 529 | lungetc(DONE_EXPAND2); | |||
| 530 | while (p >= val) { | |||
| 531 | lungetc(*p); | |||
| 532 | p--; | |||
| 533 | } | |||
| 534 | lungetc(START_EXPAND1); | |||
| 535 | goto top; | |||
| 536 | } | |||
| 537 | ||||
| 538 | switch (c) { | |||
| 539 | case '\'': | |||
| 540 | case '"': | |||
| 541 | quotec = c; | |||
| 542 | while (1) { | |||
| 543 | c = lgetc(quotec); | |||
| 544 | if (c == EOF(-1)) | |||
| 545 | return (0); | |||
| 546 | if (c == '\n') { | |||
| 547 | file->lineno++; | |||
| 548 | continue; | |||
| 549 | } else if (c == '\\') { | |||
| 550 | next = lgetc(quotec); | |||
| 551 | if (next == EOF(-1)) | |||
| 552 | return (0); | |||
| 553 | if (next == quotec || c == ' ' || c == '\t') | |||
| 554 | c = next; | |||
| 555 | else if (next == '\n') { | |||
| 556 | file->lineno++; | |||
| 557 | continue; | |||
| 558 | } else | |||
| 559 | lungetc(next); | |||
| 560 | } else if (c == quotec) { | |||
| 561 | *p = '\0'; | |||
| 562 | break; | |||
| 563 | } else if (c == '\0') { | |||
| 564 | yyerror("syntax error"); | |||
| 565 | return (findeol()); | |||
| 566 | } | |||
| 567 | if (p + 1 >= buf + sizeof(buf) - 1) { | |||
| 568 | yyerror("string too long"); | |||
| 569 | return (findeol()); | |||
| 570 | } | |||
| 571 | *p++ = c; | |||
| 572 | } | |||
| 573 | yylval.v.string = strdup(buf); | |||
| 574 | if (yylval.v.string == NULL((void *)0)) | |||
| 575 | err(1, "%s", __func__); | |||
| 576 | return (STRING268); | |||
| 577 | } | |||
| 578 | ||||
| 579 | #define allowed_to_end_number(x)(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') \ | |||
| 580 | (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') | |||
| 581 | ||||
| 582 | if (c == '-' || isdigit(c)) { | |||
| 583 | do { | |||
| 584 | *p++ = c; | |||
| 585 | if ((unsigned)(p-buf) >= sizeof(buf)) { | |||
| 586 | yyerror("string too long"); | |||
| 587 | return (findeol()); | |||
| 588 | } | |||
| 589 | c = lgetc(0); | |||
| 590 | } while (c != EOF(-1) && isdigit(c)); | |||
| 591 | lungetc(c); | |||
| 592 | if (p == buf + 1 && buf[0] == '-') | |||
| 593 | goto nodigits; | |||
| 594 | if (c == EOF(-1) || allowed_to_end_number(c)(isspace(c) || c == ')' || c ==',' || c == '/' || c == '}' || c == '=')) { | |||
| 595 | const char *errstr = NULL((void *)0); | |||
| 596 | ||||
| 597 | *p = '\0'; | |||
| 598 | yylval.v.number = strtonum(buf, LLONG_MIN(-9223372036854775807LL -1LL), | |||
| 599 | LLONG_MAX9223372036854775807LL, &errstr); | |||
| 600 | if (errstr) { | |||
| 601 | yyerror("\"%s\" invalid number: %s", | |||
| 602 | buf, errstr); | |||
| 603 | return (findeol()); | |||
| 604 | } | |||
| 605 | return (NUMBER269); | |||
| 606 | } else { | |||
| 607 | nodigits: | |||
| 608 | while (p > buf + 1) | |||
| 609 | lungetc(*--p); | |||
| 610 | c = *--p; | |||
| 611 | if (c == '-') | |||
| 612 | return (c); | |||
| 613 | } | |||
| 614 | } | |||
| 615 | ||||
| 616 | #define allowed_in_string(x)(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && x != '{' && x != '}' && x != '!' && x != '=' && x != '#' && x != ',') ) \ | |||
| 617 | (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ | |||
| 618 | x != '{' && x != '}' && \ | |||
| 619 | x != '!' && x != '=' && x != '#' && \ | |||
| 620 | x != ',')) | |||
| 621 | ||||
| 622 | if (isalnum(c) || c == ':' || c == '_') { | |||
| 623 | do { | |||
| 624 | *p++ = c; | |||
| 625 | if ((unsigned)(p-buf) >= sizeof(buf)) { | |||
| 626 | yyerror("string too long"); | |||
| 627 | return (findeol()); | |||
| 628 | } | |||
| 629 | c = lgetc(0); | |||
| 630 | } while (c != EOF(-1) && (allowed_in_string(c)(isalnum(c) || (ispunct(c) && c != '(' && c != ')' && c != '{' && c != '}' && c != '!' && c != '=' && c != '#' && c != ',') ))); | |||
| 631 | lungetc(c); | |||
| 632 | *p = '\0'; | |||
| 633 | token = lookup(buf); | |||
| 634 | if (token == STRING268) { | |||
| 635 | yylval.v.string = strdup(buf); | |||
| 636 | if (yylval.v.string == NULL((void *)0)) | |||
| 637 | err(1, "%s", __func__); | |||
| 638 | } | |||
| 639 | return (token); | |||
| 640 | } | |||
| 641 | if (c == '\n') { | |||
| 642 | yylval.lineno = file->lineno; | |||
| 643 | file->lineno++; | |||
| 644 | } | |||
| 645 | if (c == EOF(-1)) | |||
| 646 | return (0); | |||
| 647 | return (c); | |||
| 648 | } | |||
| 649 | ||||
| 650 | static const struct got_error* | |||
| 651 | newfile(struct file **nfile, const char *filename, int *fd) | |||
| 652 | { | |||
| 653 | const struct got_error* error = NULL((void *)0); | |||
| 654 | ||||
| 655 | (*nfile) = calloc(1, sizeof(struct file)); | |||
| 656 | if ((*nfile) == NULL((void *)0)) | |||
| 657 | return got_error_from_errno("calloc"); | |||
| 658 | (*nfile)->stream = fdopen(*fd, "r"); | |||
| 659 | if ((*nfile)->stream == NULL((void *)0)) { | |||
| 660 | error = got_error_from_errno("fdopen"); | |||
| 661 | free((*nfile)); | |||
| 662 | return error; | |||
| 663 | } | |||
| 664 | *fd = -1; /* Stream owns the file descriptor now. */ | |||
| 665 | (*nfile)->name = filename; | |||
| 666 | (*nfile)->lineno = 1; | |||
| 667 | (*nfile)->ungetsize = 16; | |||
| 668 | (*nfile)->ungetbuf = malloc((*nfile)->ungetsize); | |||
| 669 | if ((*nfile)->ungetbuf == NULL((void *)0)) { | |||
| 670 | error = got_error_from_errno("malloc"); | |||
| 671 | fclose((*nfile)->stream); | |||
| 672 | free((*nfile)); | |||
| 673 | return error; | |||
| 674 | } | |||
| 675 | return NULL((void *)0); | |||
| 676 | } | |||
| 677 | ||||
| 678 | static const struct got_error* | |||
| 679 | new_remote(struct gotconfig_remote_repo **remote) | |||
| 680 | { | |||
| 681 | const struct got_error *error = NULL((void *)0); | |||
| 682 | ||||
| 683 | *remote = calloc(1, sizeof(**remote)); | |||
| 684 | if (*remote == NULL((void *)0)) | |||
| 685 | error = got_error_from_errno("calloc"); | |||
| 686 | return error; | |||
| 687 | } | |||
| 688 | ||||
| 689 | static void | |||
| 690 | closefile(struct file *file) | |||
| 691 | { | |||
| 692 | fclose(file->stream); | |||
| 693 | free(file->ungetbuf); | |||
| 694 | free(file); | |||
| 695 | } | |||
| 696 | ||||
| 697 | const struct got_error * | |||
| 698 | gotconfig_parse(struct gotconfig **conf, const char *filename, int *fd) | |||
| 699 | { | |||
| 700 | const struct got_error *err = NULL((void *)0); | |||
| 701 | struct sym *sym, *next; | |||
| 702 | ||||
| 703 | *conf = NULL((void *)0); | |||
| 704 | ||||
| 705 | err = newfile(&file, filename, fd); | |||
| 706 | if (err) | |||
| 707 | return err; | |||
| 708 | ||||
| 709 | TAILQ_INIT(&gotconfig.remotes)do { (&gotconfig.remotes)->tqh_first = ((void *)0); (& gotconfig.remotes)->tqh_last = &(&gotconfig.remotes )->tqh_first; } while (0); | |||
| 710 | ||||
| 711 | yyparse(); | |||
| 712 | closefile(file); | |||
| 713 | ||||
| 714 | /* Free macros and check which have not been used. */ | |||
| 715 | TAILQ_FOREACH_SAFE(sym, &symhead, entry, next)for ((sym) = ((&symhead)->tqh_first); (sym) != ((void * )0) && ((next) = ((sym)->entry.tqe_next), 1); (sym ) = (next)) { | |||
| 716 | if (!sym->persist) { | |||
| 717 | free(sym->nam); | |||
| 718 | free(sym->val); | |||
| 719 | TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void *)0)) (sym)-> entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev; else (&symhead)->tqh_last = (sym)->entry.tqe_prev; *(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while (0); | |||
| 720 | free(sym); | |||
| 721 | } | |||
| 722 | } | |||
| 723 | ||||
| 724 | if (gerror == NULL((void *)0)) | |||
| 725 | *conf = &gotconfig; | |||
| 726 | return gerror; | |||
| 727 | } | |||
| 728 | ||||
| 729 | void | |||
| 730 | gotconfig_free(struct gotconfig *conf) | |||
| 731 | { | |||
| 732 | struct gotconfig_remote_repo *remote; | |||
| 733 | ||||
| 734 | free(conf->author); | |||
| 735 | while (!TAILQ_EMPTY(&conf->remotes)(((&conf->remotes)->tqh_first) == ((void *)0))) { | |||
| 736 | remote = TAILQ_FIRST(&conf->remotes)((&conf->remotes)->tqh_first); | |||
| 737 | TAILQ_REMOVE(&conf->remotes, remote, entry)do { if (((remote)->entry.tqe_next) != ((void *)0)) (remote )->entry.tqe_next->entry.tqe_prev = (remote)->entry. tqe_prev; else (&conf->remotes)->tqh_last = (remote )->entry.tqe_prev; *(remote)->entry.tqe_prev = (remote) ->entry.tqe_next; ; ; } while (0); | |||
| 738 | free(remote->name); | |||
| 739 | free(remote->repository); | |||
| 740 | free(remote->server); | |||
| 741 | free(remote->protocol); | |||
| 742 | free(remote); | |||
| 743 | } | |||
| 744 | } | |||
| 745 | ||||
| 746 | int | |||
| 747 | symset(const char *nam, const char *val, int persist) | |||
| 748 | { | |||
| 749 | struct sym *sym; | |||
| 750 | ||||
| 751 | TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void * )0); (sym) = ((sym)->entry.tqe_next)) { | |||
| 752 | if (strcmp(nam, sym->nam) == 0) | |||
| 753 | break; | |||
| 754 | } | |||
| 755 | ||||
| 756 | if (sym != NULL((void *)0)) { | |||
| 757 | if (sym->persist == 1) | |||
| 758 | return (0); | |||
| 759 | else { | |||
| 760 | free(sym->nam); | |||
| 761 | free(sym->val); | |||
| 762 | TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void *)0)) (sym)-> entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev; else (&symhead)->tqh_last = (sym)->entry.tqe_prev; *(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while (0); | |||
| 763 | free(sym); | |||
| 764 | } | |||
| 765 | } | |||
| 766 | sym = calloc(1, sizeof(*sym)); | |||
| 767 | if (sym == NULL((void *)0)) | |||
| 768 | return (-1); | |||
| 769 | ||||
| 770 | sym->nam = strdup(nam); | |||
| 771 | if (sym->nam == NULL((void *)0)) { | |||
| 772 | free(sym); | |||
| 773 | return (-1); | |||
| 774 | } | |||
| 775 | sym->val = strdup(val); | |||
| 776 | if (sym->val == NULL((void *)0)) { | |||
| 777 | free(sym->nam); | |||
| 778 | free(sym); | |||
| 779 | return (-1); | |||
| 780 | } | |||
| 781 | sym->used = 0; | |||
| 782 | sym->persist = persist; | |||
| 783 | TAILQ_INSERT_TAIL(&symhead, sym, entry)do { (sym)->entry.tqe_next = ((void *)0); (sym)->entry. tqe_prev = (&symhead)->tqh_last; *(&symhead)->tqh_last = (sym); (&symhead)->tqh_last = &(sym)->entry. tqe_next; } while (0); | |||
| 784 | return (0); | |||
| 785 | } | |||
| 786 | ||||
| 787 | int | |||
| 788 | cmdline_symset(char *s) | |||
| 789 | { | |||
| 790 | char *sym, *val; | |||
| 791 | int ret; | |||
| 792 | size_t len; | |||
| 793 | ||||
| 794 | val = strrchr(s, '='); | |||
| 795 | if (val == NULL((void *)0)) | |||
| 796 | return (-1); | |||
| 797 | ||||
| 798 | len = strlen(s) - strlen(val) + 1; | |||
| 799 | sym = malloc(len); | |||
| 800 | if (sym == NULL((void *)0)) | |||
| 801 | errx(1, "cmdline_symset: malloc"); | |||
| 802 | ||||
| 803 | strlcpy(sym, s, len); | |||
| 804 | ||||
| 805 | ret = symset(sym, val + 1, 1); | |||
| 806 | free(sym); | |||
| 807 | ||||
| 808 | return (ret); | |||
| 809 | } | |||
| 810 | ||||
| 811 | char * | |||
| 812 | symget(const char *nam) | |||
| 813 | { | |||
| 814 | struct sym *sym; | |||
| 815 | ||||
| 816 | TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void * )0); (sym) = ((sym)->entry.tqe_next)) { | |||
| 817 | if (strcmp(nam, sym->nam) == 0) { | |||
| 818 | sym->used = 1; | |||
| 819 | return (sym->val); | |||
| 820 | } | |||
| 821 | } | |||
| 822 | return (NULL((void *)0)); | |||
| 823 | } | |||
| 824 | ||||
| 825 | static int | |||
| 826 | atoul(char *s, u_long *ulvalp) | |||
| 827 | { | |||
| 828 | u_long ulval; | |||
| 829 | char *ep; | |||
| 830 | ||||
| 831 | errno(*__errno()) = 0; | |||
| 832 | ulval = strtoul(s, &ep, 0); | |||
| 833 | if (s[0] == '\0' || *ep != '\0') | |||
| 834 | return (-1); | |||
| 835 | if (errno(*__errno()) == ERANGE34 && ulval == ULONG_MAX(9223372036854775807L *2UL+1UL)) | |||
| 836 | return (-1); | |||
| 837 | *ulvalp = ulval; | |||
| 838 | return (0); | |||
| 839 | } | |||
| 840 | #line 833 "parse.c" | |||
| 841 | /* allocate initial stack or double stack size, up to YYMAXDEPTH */ | |||
| 842 | static int yygrowstack(void) | |||
| 843 | { | |||
| 844 | unsigned int newsize; | |||
| 845 | long sslen; | |||
| 846 | short *newss; | |||
| 847 | YYSTYPE *newvs; | |||
| 848 | ||||
| 849 | if ((newsize = yystacksize) == 0) | |||
| 850 | newsize = YYINITSTACKSIZE200; | |||
| 851 | else if (newsize >= YYMAXDEPTH10000) | |||
| 852 | return -1; | |||
| 853 | else if ((newsize *= 2) > YYMAXDEPTH10000) | |||
| 854 | newsize = YYMAXDEPTH10000; | |||
| 855 | sslen = yyssp - yyss; | |||
| 856 | #ifdef SIZE_MAX | |||
| 857 | #define YY_SIZE_MAX0xffffffffU SIZE_MAX | |||
| 858 | #else | |||
| 859 | #define YY_SIZE_MAX0xffffffffU 0xffffffffU | |||
| 860 | #endif | |||
| 861 | if (newsize && YY_SIZE_MAX0xffffffffU / newsize < sizeof *newss) | |||
| 862 | goto bail; | |||
| 863 | newss = (short *)realloc(yyss, newsize * sizeof *newss); | |||
| 864 | if (newss == NULL((void *)0)) | |||
| 865 | goto bail; | |||
| 866 | yyss = newss; | |||
| 867 | yyssp = newss + sslen; | |||
| 868 | if (newsize
| |||
| 869 | goto bail; | |||
| 870 | newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs); | |||
| 871 | if (newvs == NULL((void *)0)) | |||
| 872 | goto bail; | |||
| 873 | yyvs = newvs; | |||
| 874 | yyvsp = newvs + sslen; | |||
| 875 | yystacksize = newsize; | |||
| 876 | yysslim = yyss + newsize - 1; | |||
| 877 | return 0; | |||
| 878 | bail: | |||
| 879 | if (yyss
| |||
| 880 | free(yyss); | |||
| 881 | if (yyvs) | |||
| 882 | free(yyvs); | |||
| ||||
| 883 | yyss = yyssp = NULL((void *)0); | |||
| 884 | yyvs = yyvsp = NULL((void *)0); | |||
| 885 | yystacksize = 0; | |||
| 886 | return -1; | |||
| 887 | } | |||
| 888 | ||||
| 889 | #define YYABORTgoto yyabort goto yyabort | |||
| 890 | #define YYREJECTgoto yyabort goto yyabort | |||
| 891 | #define YYACCEPTgoto yyaccept goto yyaccept | |||
| 892 | #define YYERRORgoto yyerrlab goto yyerrlab | |||
| 893 | int | |||
| 894 | yyparse(void) | |||
| 895 | { | |||
| 896 | int yym, yyn, yystate; | |||
| 897 | #if YYDEBUG0 | |||
| 898 | const char *yys; | |||
| 899 | ||||
| 900 | if ((yys = getenv("YYDEBUG"))) | |||
| 901 | { | |||
| 902 | yyn = *yys; | |||
| 903 | if (yyn >= '0' && yyn <= '9') | |||
| 904 | yydebug = yyn - '0'; | |||
| 905 | } | |||
| 906 | #endif /* YYDEBUG */ | |||
| 907 | ||||
| 908 | yynerrs = 0; | |||
| 909 | yyerrflag = 0; | |||
| 910 | yychar = (-1); | |||
| 911 | ||||
| 912 | if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow; | |||
| ||||
| 913 | yyssp = yyss; | |||
| 914 | yyvsp = yyvs; | |||
| 915 | *yyssp = yystate = 0; | |||
| 916 | ||||
| 917 | yyloop: | |||
| 918 | if ((yyn = yydefred[yystate]) != 0) goto yyreduce; | |||
| 919 | if (yychar < 0) | |||
| 920 | { | |||
| 921 | if ((yychar = yylex()) < 0) yychar = 0; | |||
| 922 | #if YYDEBUG0 | |||
| 923 | if (yydebug) | |||
| 924 | { | |||
| 925 | yys = 0; | |||
| 926 | if (yychar <= YYMAXTOKEN269) yys = yyname[yychar]; | |||
| 927 | if (!yys) yys = "illegal-symbol"; | |||
| 928 | printf("%sdebug: state %d, reading %d (%s)\n", | |||
| 929 | YYPREFIX"yy", yystate, yychar, yys); | |||
| 930 | } | |||
| 931 | #endif | |||
| 932 | } | |||
| 933 | if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && | |||
| 934 | yyn <= YYTABLESIZE271 && yycheck[yyn] == yychar) | |||
| 935 | { | |||
| 936 | #if YYDEBUG0 | |||
| 937 | if (yydebug) | |||
| 938 | printf("%sdebug: state %d, shifting to state %d\n", | |||
| 939 | YYPREFIX"yy", yystate, yytable[yyn]); | |||
| 940 | #endif | |||
| 941 | if (yyssp >= yysslim && yygrowstack()) | |||
| 942 | { | |||
| 943 | goto yyoverflow; | |||
| 944 | } | |||
| 945 | *++yyssp = yystate = yytable[yyn]; | |||
| 946 | *++yyvsp = yylval; | |||
| 947 | yychar = (-1); | |||
| 948 | if (yyerrflag > 0) --yyerrflag; | |||
| 949 | goto yyloop; | |||
| 950 | } | |||
| 951 | if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && | |||
| 952 | yyn <= YYTABLESIZE271 && yycheck[yyn] == yychar) | |||
| 953 | { | |||
| 954 | yyn = yytable[yyn]; | |||
| 955 | goto yyreduce; | |||
| 956 | } | |||
| 957 | if (yyerrflag) goto yyinrecovery; | |||
| 958 | #if defined(__GNUC__4) | |||
| 959 | goto yynewerror; | |||
| 960 | #endif | |||
| 961 | yynewerror: | |||
| 962 | yyerror("syntax error"); | |||
| 963 | #if defined(__GNUC__4) | |||
| 964 | goto yyerrlab; | |||
| 965 | #endif | |||
| 966 | yyerrlab: | |||
| 967 | ++yynerrs; | |||
| 968 | yyinrecovery: | |||
| 969 | if (yyerrflag < 3) | |||
| 970 | { | |||
| 971 | yyerrflag = 3; | |||
| 972 | for (;;) | |||
| 973 | { | |||
| 974 | if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 && | |||
| 975 | yyn <= YYTABLESIZE271 && yycheck[yyn] == YYERRCODE256) | |||
| 976 | { | |||
| 977 | #if YYDEBUG0 | |||
| 978 | if (yydebug) | |||
| 979 | printf("%sdebug: state %d, error recovery shifting\ | |||
| 980 | to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]); | |||
| 981 | #endif | |||
| 982 | if (yyssp >= yysslim && yygrowstack()) | |||
| 983 | { | |||
| 984 | goto yyoverflow; | |||
| 985 | } | |||
| 986 | *++yyssp = yystate = yytable[yyn]; | |||
| 987 | *++yyvsp = yylval; | |||
| 988 | goto yyloop; | |||
| 989 | } | |||
| 990 | else | |||
| 991 | { | |||
| 992 | #if YYDEBUG0 | |||
| 993 | if (yydebug) | |||
| 994 | printf("%sdebug: error recovery discarding state %d\n", | |||
| 995 | YYPREFIX"yy", *yyssp); | |||
| 996 | #endif | |||
| 997 | if (yyssp <= yyss) goto yyabort; | |||
| 998 | --yyssp; | |||
| 999 | --yyvsp; | |||
| 1000 | } | |||
| 1001 | } | |||
| 1002 | } | |||
| 1003 | else | |||
| 1004 | { | |||
| 1005 | if (yychar == 0) goto yyabort; | |||
| 1006 | #if YYDEBUG0 | |||
| 1007 | if (yydebug) | |||
| 1008 | { | |||
| 1009 | yys = 0; | |||
| 1010 | if (yychar <= YYMAXTOKEN269) yys = yyname[yychar]; | |||
| 1011 | if (!yys) yys = "illegal-symbol"; | |||
| 1012 | printf("%sdebug: state %d, error recovery discards token %d (%s)\n", | |||
| 1013 | YYPREFIX"yy", yystate, yychar, yys); | |||
| 1014 | } | |||
| 1015 | #endif | |||
| 1016 | yychar = (-1); | |||
| 1017 | goto yyloop; | |||
| 1018 | } | |||
| 1019 | yyreduce: | |||
| 1020 | #if YYDEBUG0 | |||
| 1021 | if (yydebug) | |||
| 1022 | printf("%sdebug: state %d, reducing by rule %d (%s)\n", | |||
| 1023 | YYPREFIX"yy", yystate, yyn, yyrule[yyn]); | |||
| 1024 | #endif | |||
| 1025 | yym = yylen[yyn]; | |||
| 1026 | if (yym) | |||
| 1027 | yyval = yyvsp[1-yym]; | |||
| 1028 | else | |||
| 1029 | memset(&yyval, 0, sizeof yyval); | |||
| 1030 | switch (yyn) | |||
| 1031 | { | |||
| 1032 | case 5: | |||
| 1033 | #line 114 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1034 | { | |||
| 1035 | if (strcasecmp(yyvsp[0].v.string, "true") == 0 || | |||
| 1036 | strcasecmp(yyvsp[0].v.string, "yes") == 0) | |||
| 1037 | yyval.v.number = 1; | |||
| 1038 | else if (strcasecmp(yyvsp[0].v.string, "false") == 0 || | |||
| 1039 | strcasecmp(yyvsp[0].v.string, "no") == 0) | |||
| 1040 | yyval.v.number = 0; | |||
| 1041 | else { | |||
| 1042 | yyerror("invalid boolean value '%s'", yyvsp[0].v.string); | |||
| 1043 | free(yyvsp[0].v.string); | |||
| 1044 | YYERRORgoto yyerrlab; | |||
| 1045 | } | |||
| 1046 | free(yyvsp[0].v.string); | |||
| 1047 | } | |||
| 1048 | break; | |||
| 1049 | case 6: | |||
| 1050 | #line 129 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1051 | { | |||
| 1052 | char *s; | |||
| 1053 | if (asprintf(&s, "%lld", yyvsp[0].v.number) == -1) { | |||
| 1054 | yyerror("string: asprintf"); | |||
| 1055 | YYERRORgoto yyerrlab; | |||
| 1056 | } | |||
| 1057 | yyval.v.string = s; | |||
| 1058 | } | |||
| 1059 | break; | |||
| 1060 | case 8: | |||
| 1061 | #line 139 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1062 | { | |||
| 1063 | if (parseport(yyvsp[0].v.string, &yyval.v.number) == -1) { | |||
| 1064 | free(yyvsp[0].v.string); | |||
| 1065 | YYERRORgoto yyerrlab; | |||
| 1066 | } | |||
| 1067 | free(yyvsp[0].v.string); | |||
| 1068 | } | |||
| 1069 | break; | |||
| 1070 | case 9: | |||
| 1071 | #line 147 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1072 | { yyval.v.branch = NULL((void *)0); } | |||
| 1073 | break; | |||
| 1074 | case 10: | |||
| 1075 | #line 148 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1076 | { yyval.v.branch = yyvsp[0].v.branch; } | |||
| 1077 | break; | |||
| 1078 | case 11: | |||
| 1079 | #line 149 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1080 | { yyval.v.branch = yyvsp[-1].v.branch; } | |||
| 1081 | break; | |||
| 1082 | case 12: | |||
| 1083 | #line 151 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1084 | { | |||
| 1085 | yyval.v.branch = calloc(1, sizeof(struct node_branch)); | |||
| 1086 | if (yyval.v.branch == NULL((void *)0)) { | |||
| 1087 | yyerror("calloc"); | |||
| 1088 | YYERRORgoto yyerrlab; | |||
| 1089 | } | |||
| 1090 | yyval.v.branch->branch_name = yyvsp[0].v.string; | |||
| 1091 | yyval.v.branch->tail = yyval.v.branch; | |||
| 1092 | } | |||
| 1093 | break; | |||
| 1094 | case 13: | |||
| 1095 | #line 161 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1096 | { yyval.v.branch = yyvsp[-1].v.branch; } | |||
| 1097 | break; | |||
| 1098 | case 14: | |||
| 1099 | #line 162 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1100 | { | |||
| 1101 | yyvsp[-3].v.branch->tail->next = yyvsp[-1].v.branch; | |||
| 1102 | yyvsp[-3].v.branch->tail = yyvsp[-1].v.branch; | |||
| 1103 | yyval.v.branch = yyvsp[-3].v.branch; | |||
| 1104 | } | |||
| 1105 | break; | |||
| 1106 | case 15: | |||
| 1107 | #line 168 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1108 | { yyval.v.ref = NULL((void *)0); } | |||
| 1109 | break; | |||
| 1110 | case 16: | |||
| 1111 | #line 169 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1112 | { yyval.v.ref = yyvsp[0].v.ref; } | |||
| 1113 | break; | |||
| 1114 | case 17: | |||
| 1115 | #line 170 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1116 | { yyval.v.ref = yyvsp[-1].v.ref; } | |||
| 1117 | break; | |||
| 1118 | case 18: | |||
| 1119 | #line 172 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1120 | { | |||
| 1121 | yyval.v.ref = calloc(1, sizeof(struct node_ref)); | |||
| 1122 | if (yyval.v.ref == NULL((void *)0)) { | |||
| 1123 | yyerror("calloc"); | |||
| 1124 | YYERRORgoto yyerrlab; | |||
| 1125 | } | |||
| 1126 | yyval.v.ref->ref_name = yyvsp[0].v.string; | |||
| 1127 | yyval.v.ref->tail = yyval.v.ref; | |||
| 1128 | } | |||
| 1129 | break; | |||
| 1130 | case 19: | |||
| 1131 | #line 182 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1132 | { yyval.v.ref = yyvsp[-1].v.ref; } | |||
| 1133 | break; | |||
| 1134 | case 20: | |||
| 1135 | #line 183 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1136 | { | |||
| 1137 | yyvsp[-3].v.ref->tail->next = yyvsp[-1].v.ref; | |||
| 1138 | yyvsp[-3].v.ref->tail = yyvsp[-1].v.ref; | |||
| 1139 | yyval.v.ref = yyvsp[-3].v.ref; | |||
| 1140 | } | |||
| 1141 | break; | |||
| 1142 | case 23: | |||
| 1143 | #line 192 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1144 | { | |||
| 1145 | remote->repository = strdup(yyvsp[0].v.string); | |||
| 1146 | if (remote->repository == NULL((void *)0)) { | |||
| 1147 | free(yyvsp[0].v.string); | |||
| 1148 | yyerror("strdup"); | |||
| 1149 | YYERRORgoto yyerrlab; | |||
| 1150 | } | |||
| 1151 | free(yyvsp[0].v.string); | |||
| 1152 | } | |||
| 1153 | break; | |||
| 1154 | case 24: | |||
| 1155 | #line 201 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1156 | { | |||
| 1157 | remote->server = strdup(yyvsp[0].v.string); | |||
| 1158 | if (remote->server == NULL((void *)0)) { | |||
| 1159 | free(yyvsp[0].v.string); | |||
| 1160 | yyerror("strdup"); | |||
| 1161 | YYERRORgoto yyerrlab; | |||
| 1162 | } | |||
| 1163 | free(yyvsp[0].v.string); | |||
| 1164 | } | |||
| 1165 | break; | |||
| 1166 | case 25: | |||
| 1167 | #line 210 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1168 | { | |||
| 1169 | remote->protocol = strdup(yyvsp[0].v.string); | |||
| 1170 | if (remote->protocol == NULL((void *)0)) { | |||
| 1171 | free(yyvsp[0].v.string); | |||
| 1172 | yyerror("strdup"); | |||
| 1173 | YYERRORgoto yyerrlab; | |||
| 1174 | } | |||
| 1175 | free(yyvsp[0].v.string); | |||
| 1176 | } | |||
| 1177 | break; | |||
| 1178 | case 26: | |||
| 1179 | #line 219 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1180 | { | |||
| 1181 | remote->mirror_references = yyvsp[0].v.number; | |||
| 1182 | } | |||
| 1183 | break; | |||
| 1184 | case 27: | |||
| 1185 | #line 222 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1186 | { | |||
| 1187 | remote->fetch_all_branches = yyvsp[0].v.number; | |||
| 1188 | } | |||
| 1189 | break; | |||
| 1190 | case 28: | |||
| 1191 | #line 225 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1192 | { | |||
| 1193 | remote->port = yyvsp[0].v.number; | |||
| 1194 | } | |||
| 1195 | break; | |||
| 1196 | case 29: | |||
| 1197 | #line 228 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1198 | { | |||
| 1199 | remote->branch = yyvsp[0].v.branch; | |||
| 1200 | } | |||
| 1201 | break; | |||
| 1202 | case 30: | |||
| 1203 | #line 231 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1204 | { | |||
| 1205 | remote->ref = yyvsp[0].v.ref; | |||
| 1206 | } | |||
| 1207 | break; | |||
| 1208 | case 31: | |||
| 1209 | #line 235 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1210 | { | |||
| 1211 | static const struct got_error* error; | |||
| 1212 | ||||
| 1213 | error = new_remote(&remote); | |||
| 1214 | if (error) { | |||
| 1215 | free(yyvsp[0].v.string); | |||
| 1216 | yyerror("%s", error->msg); | |||
| 1217 | YYERRORgoto yyerrlab; | |||
| 1218 | } | |||
| 1219 | remote->name = strdup(yyvsp[0].v.string); | |||
| 1220 | if (remote->name == NULL((void *)0)) { | |||
| 1221 | free(yyvsp[0].v.string); | |||
| 1222 | yyerror("strdup"); | |||
| 1223 | YYERRORgoto yyerrlab; | |||
| 1224 | } | |||
| 1225 | free(yyvsp[0].v.string); | |||
| 1226 | } | |||
| 1227 | break; | |||
| 1228 | case 32: | |||
| 1229 | #line 251 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1230 | { | |||
| 1231 | TAILQ_INSERT_TAIL(&gotconfig.remotes, remote, entry)do { (remote)->entry.tqe_next = ((void *)0); (remote)-> entry.tqe_prev = (&gotconfig.remotes)->tqh_last; *(& gotconfig.remotes)->tqh_last = (remote); (&gotconfig.remotes )->tqh_last = &(remote)->entry.tqe_next; } while (0 ); | |||
| 1232 | gotconfig.nremotes++; | |||
| 1233 | } | |||
| 1234 | break; | |||
| 1235 | case 33: | |||
| 1236 | #line 256 "/home/ben/Projects/got/libexec/got-read-gotconfig/parse.y" | |||
| 1237 | { | |||
| 1238 | gotconfig.author = strdup(yyvsp[0].v.string); | |||
| 1239 | if (gotconfig.author == NULL((void *)0)) { | |||
| 1240 | free(yyvsp[0].v.string); | |||
| 1241 | yyerror("strdup"); | |||
| 1242 | YYERRORgoto yyerrlab; | |||
| 1243 | } | |||
| 1244 | free(yyvsp[0].v.string); | |||
| 1245 | } | |||
| 1246 | break; | |||
| 1247 | #line 1240 "parse.c" | |||
| 1248 | } | |||
| 1249 | yyssp -= yym; | |||
| 1250 | yystate = *yyssp; | |||
| 1251 | yyvsp -= yym; | |||
| 1252 | yym = yylhs[yyn]; | |||
| 1253 | if (yystate == 0 && yym == 0) | |||
| 1254 | { | |||
| 1255 | #if YYDEBUG0 | |||
| 1256 | if (yydebug) | |||
| 1257 | printf("%sdebug: after reduction, shifting from state 0 to\ | |||
| 1258 | state %d\n", YYPREFIX"yy", YYFINAL1); | |||
| 1259 | #endif | |||
| 1260 | yystate = YYFINAL1; | |||
| 1261 | *++yyssp = YYFINAL1; | |||
| 1262 | *++yyvsp = yyval; | |||
| 1263 | if (yychar < 0) | |||
| 1264 | { | |||
| 1265 | if ((yychar = yylex()) < 0) yychar = 0; | |||
| 1266 | #if YYDEBUG0 | |||
| 1267 | if (yydebug) | |||
| 1268 | { | |||
| 1269 | yys = 0; | |||
| 1270 | if (yychar <= YYMAXTOKEN269) yys = yyname[yychar]; | |||
| 1271 | if (!yys) yys = "illegal-symbol"; | |||
| 1272 | printf("%sdebug: state %d, reading %d (%s)\n", | |||
| 1273 | YYPREFIX"yy", YYFINAL1, yychar, yys); | |||
| 1274 | } | |||
| 1275 | #endif | |||
| 1276 | } | |||
| 1277 | if (yychar == 0) goto yyaccept; | |||
| 1278 | goto yyloop; | |||
| 1279 | } | |||
| 1280 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && | |||
| 1281 | yyn <= YYTABLESIZE271 && yycheck[yyn] == yystate) | |||
| 1282 | yystate = yytable[yyn]; | |||
| 1283 | else | |||
| 1284 | yystate = yydgoto[yym]; | |||
| 1285 | #if YYDEBUG0 | |||
| 1286 | if (yydebug) | |||
| 1287 | printf("%sdebug: after reduction, shifting from state %d \ | |||
| 1288 | to state %d\n", YYPREFIX"yy", *yyssp, yystate); | |||
| 1289 | #endif | |||
| 1290 | if (yyssp >= yysslim && yygrowstack()) | |||
| 1291 | { | |||
| 1292 | goto yyoverflow; | |||
| 1293 | } | |||
| 1294 | *++yyssp = yystate; | |||
| 1295 | *++yyvsp = yyval; | |||
| 1296 | goto yyloop; | |||
| 1297 | yyoverflow: | |||
| 1298 | yyerror("yacc stack overflow"); | |||
| 1299 | yyabort: | |||
| 1300 | if (yyss) | |||
| 1301 | free(yyss); | |||
| 1302 | if (yyvs) | |||
| 1303 | free(yyvs); | |||
| 1304 | yyss = yyssp = NULL((void *)0); | |||
| 1305 | yyvs = yyvsp = NULL((void *)0); | |||
| 1306 | yystacksize = 0; | |||
| 1307 | return (1); | |||
| 1308 | yyaccept: | |||
| 1309 | if (yyss) | |||
| 1310 | free(yyss); | |||
| 1311 | if (yyvs) | |||
| 1312 | free(yyvs); | |||
| 1313 | yyss = yyssp = NULL((void *)0); | |||
| 1314 | yyvs = yyvsp = NULL((void *)0); | |||
| 1315 | yystacksize = 0; | |||
| 1316 | return (0); | |||
| 1317 | } |