summaryrefslogtreecommitdiffstats
path: root/xlators/debug/error-gen/src/error-gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/debug/error-gen/src/error-gen.c')
0 files changed, 0 insertions, 0 deletions
complete_tree->name, yylineno, type); return -1; } gf_log ("parser", GF_LOG_DEBUG, "Type:%s:%s", tree->name, type); return 0; } static int section_option (char *key, char *value) { extern int yylineno; int ret = 0; if (!key || !value){ fprintf (stderr, "invalid argument\n"); gf_log ("parser", GF_LOG_ERROR, "invalid argument"); return -1; } ret = dict_set (tree->options, key, str_to_data (value)); if (ret == 1) { gf_log ("parser", GF_LOG_ERROR, "volume '%s', line %d: duplicate entry " "('option %s') present", tree->name, yylineno, key); return -1; } gf_log ("parser", GF_LOG_DEBUG, "Option:%s:%s:%s", tree->name, key, value); return 0; } static int section_sub (char *sub) { extern int yylineno; xlator_t *trav = complete_tree; xlator_list_t *xlchild, *tmp, *xlparent; if (!sub) { fprintf (stderr, "invalid subvolumes argument\n"); gf_log ("parser", GF_LOG_ERROR, "invalid subvolumes argument"); return -1; } while (trav) { if (!strcmp (sub, trav->name)) break; trav = trav->next; } if (!trav) { fprintf (stderr, "volume '%s', line %d: subvolume '%s' is not " "defined prior to usage\n", complete_tree->name, yylineno, sub); gf_log ("parser", GF_LOG_ERROR, "volume '%s', line %d: subvolume '%s' is not defined " "prior to usage", complete_tree->name, yylineno, sub); return -1; } if (trav == tree) { fprintf (stderr, "volume '%s', line %d: has '%s' itself as " "subvolume\n", complete_tree->name, yylineno, sub); gf_log ("parser", GF_LOG_ERROR, "volume '%s', line %d: has '%s' itself as subvolume", complete_tree->name, yylineno, sub); return -1; } xlparent = (void *) calloc (1, sizeof (*xlparent)); xlparent->xlator = tree; tmp = trav->parents; if (tmp == NULL) { trav->parents = xlparent; } else { while (tmp->next) tmp = tmp->next; tmp->next = xlparent; } xlchild = (void *) calloc (1, sizeof(*xlchild)); xlchild->xlator = trav; tmp = tree->children; if (tmp == NULL) { tree->children = xlchild; } else { while (tmp->next) tmp = tmp->next; tmp->next = xlchild; } gf_log ("parser", GF_LOG_DEBUG, "child:%s->%s", tree->name, sub); return 0; } static int section_end (void) { if (!tree->fops || !tree->mops) { fprintf (stderr, "\"type\" not specified for volume %s\n", tree->name); gf_log ("parser", GF_LOG_ERROR, "\"type\" not specified for volume %s", tree->name); return -1; } gf_log ("parser", GF_LOG_DEBUG, "end:%s", tree->name); tree = NULL; return 0; } int yywrap () { return 1; } int yyerror (const char *str) { extern char *yytext; extern int yylineno; if (complete_tree && complete_tree->name) { if (!strcmp (yytext, "volume")) { fprintf (stderr, "'end-volume' not defined for volume '%s'\n", complete_tree->name); gf_log ("parser", GF_LOG_ERROR, "'end-volume' not defined for volume '%s'", complete_tree->name); } else if (!strcmp (yytext, "type")) { fprintf (stderr, "line %d: duplicate 'type' defined " "for volume '%s'", yylineno, complete_tree->name); gf_log ("parser", GF_LOG_ERROR, "line %d: duplicate 'type' defined for " "volume '%s'", yylineno, complete_tree->name); } else if (!strcmp (yytext, "subvolumes")) { fprintf (stderr, "line %d: duplicate 'subvolumes' " "defined for volume '%s'", yylineno, complete_tree->name); gf_log ("parser", GF_LOG_ERROR, "line %d: duplicate 'subvolumes' defined for " "volume '%s'", yylineno, complete_tree->name); } else if (tree) { fprintf (stderr, "syntax error: line %d (volume '%s'): \"%s\"" "\nallowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume'", yylineno, complete_tree->name, yytext); gf_log ("parser", GF_LOG_ERROR, "syntax error: line %d (volume '%s'): \"%s\"" "\nallowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume'()", yylineno, complete_tree->name, yytext); } else { fprintf (stderr, "syntax error: line %d (just after volume " "'%s'): \"%s\"\n(%s)", yylineno, complete_tree->name, yytext, "allowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume'"); gf_log ("parser", GF_LOG_ERROR, "syntax error: line %d (just after volume " "'%s'): \"%s\"\n(%s)", yylineno, complete_tree->name, yytext, "allowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume'"); } } else { fprintf (stderr, "syntax error in line %d: \"%s\" \n" "(allowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume')\n", yylineno, yytext); gf_log ("parser", GF_LOG_ERROR, "syntax error in line %d: \"%s\" \n" "(allowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume')\n", yylineno, yytext); } cut_tree (tree); complete_tree = NULL; return 0; } static int execute_cmd (char *cmd, char **result, size_t size) { FILE *fpp = NULL; int i = 0, status = 0; char character = 0; char *buf = *result; fpp = popen (cmd, "r"); if (!fpp) { gf_log ("parser", GF_LOG_ERROR, "%s: failed to popen", cmd); return -1; } while ((character = fgetc (fpp)) != EOF) { if (i == size) { size *= 2; buf = *result = realloc (*result, size); } buf[i++] = character; } if (i > 0) { i--; buf[i] = '\0'; } status = pclose (fpp); if (status == -1 || !WIFEXITED (status) || ((WEXITSTATUS (status)) != 0)) { i = -1; buf[0] = '\0'; } return i; } static int parse_backtick (FILE *srcfp, FILE *dstfp) { int ret = 0, i = 0; char *cmd = NULL, *result = NULL; size_t cmd_buf_size = GF_CMD_BUFFER_LEN; char escaped = 0, in_backtick = 0, character = 0; int line = 1, column = 0, backtick_line = 0, backtick_column = 0; fseek (srcfp, 0L, SEEK_SET); fseek (dstfp, 0L, SEEK_SET); cmd = CALLOC (cmd_buf_size, 1); if (cmd == NULL) { return -1; } result = CALLOC (cmd_buf_size * 2, 1); if (result == NULL) { return -1; } while ((character = fgetc (srcfp)) != EOF) { if ((character == '`') && !escaped) { if (in_backtick) { cmd[i] = '\0'; result[0] = '\0'; ret = execute_cmd (cmd, &result, 2 * cmd_buf_size); if (ret < 0) { ret = -1; goto out; } fwrite (result, ret, 1, dstfp); } else { i = 0; cmd[i] = '\0'; backtick_column = column; backtick_line = line; } in_backtick = !in_backtick; } else { if (in_backtick) { if (i == cmd_buf_size) { cmd_buf_size *= 2; cmd = realloc (cmd, cmd_buf_size); if (cmd == NULL) { return -1; } result = realloc (result, 2 * cmd_buf_size); if (result == NULL) { return -1; } } cmd[i++] = character; } else { fputc (character, dstfp); } } if (character == '\\') { escaped = !escaped; } else { escaped = 0; } if