/* * On entry, current should point to the opening array character * On exit end will point to the closing character. */ static size_t copy_array(struct cfg_field *self, const struct cfg_string *str, size_t current, enum cfg_status *status) { // skip past the opening brace current++; CFG_FIELD_ELTYPE(self) = CFG_ELTYPE_UNKNOWN; while (1) { current = find_nonwhite(str, current, status); if (*status) { // EOF goto _copy_array_bail; } if (str->data[current] == CFG_ARRAY_SEP) { // this is the separator between elements of array, skip current++; continue; } if (str->data[current] == CFG_ARRAY_END) { break; } if (str->data[current] == '#') { // found a comment, skip to next EOL current = find_char(str, current, '\n', status); if (*status) { // EOF goto _copy_array_bail; } continue; } if (str->data[current] == CFG_QUOTE) { current = copy_quoted_string(self, str, current, status); if (*status) { goto _copy_array_bail; } CFG_FIELD_ELTYPE(self) = CFG_ELTYPE_QUOTED_STRING; // skip ending quote current ++; } else { current = copy_bare_array_token(self, str, current, status); } } _copy_array_bail: if (CFG_ELTYPE_QUOTED_STRING != CFG_FIELD_ELTYPE(self)) { // no quoted strings were found, use bare CFG_FIELD_ELTYPE(self)=CFG_ELTYPE_BARE; } return current; }
/* Assuming p points to some character beyond an opening parenthesis, copy everything to outfile up to but not including the closing parenthesis. */ char *copy_up_to_paren(register char *p) { for (;;) { SKIP_BLANKS(p); /* We don't call skip_blanks() in order to */ CHECK_EOL(p); /* preserve blanks at the beginning of the line */ if (*p == ')') break; if (*p == '\"') p = copy_quoted_string(p); else fputc(*p++, outfile); } return p; }
void process_C_file(void) { register char *p; char *gettext, *defun; while (p = GET_LINE) { gettext = strstr(p, "GETTEXT"); defun = strstr(p, "DEFUN"); if (gettext || defun) { if (gettext) { p = gettext; p += 7; /* Skip over "GETTEXT" */ } else if (defun) { p = defun; p += 5; /* Skip over "DEFUN" */ } p = skip_blanks(p); if (*p++ != '(') continue; if (defun) { register int i; for (i = 0; i < 5; i++) /* Skip over commas to doc string */ while (*p++ != ',') CHECK_EOL(p); if (*p == '\n') p = GET_LINE; } p = skip_blanks(p); if (*p != '\"') /* Make sure there is a quoted string */ continue; if (defun && no_interactive_prompt(p)) continue; fprintf(outfile, "gettext("); if (gettext) p = copy_up_to_paren(p); else p = copy_quoted_string(p); fprintf(outfile, ")\n"); } } }
static struct cfg_field *cfg_get_field(const struct cfg_string *str, size_t current, size_t *end, enum cfg_status *status) { char *name=NULL; struct cfg_field *field=NULL; // end will be on assignment character name=copy_next_identifier(str, current, end, status); if (*status) { if (CFG_EOF == *status) { // no field found at all. This is OK so we // will set status back to success *status=CFG_SUCCESS; goto _cfg_get_field_bail; } } field=cfg_field_new(); field->name=name; current = *end+1; current = find_nonwhite(str, current, status); if (*status) { // EOF return 0; } if (str->data[current] == CFG_ARRAY_BEG) { // leaves end at array end char CFG_FIELD_TYPE(field)=CFG_TYPE_ARRAY; *end = copy_array(field, str, current, status); } else if (CFG_CFG_BEG == str->data[current]) { //fprintf(stderr,"Found begin of sub config: '%s'\n", name); CFG_FIELD_TYPE(field)=CFG_TYPE_CFG; field->sub = cfg_parse(str, ¤t, status); //*end=current; // +1 cause we need to skip the ending brace *end=current+1; } else if (CFG_CFG_END == str->data[current]) { // this never happens *status = CFG_FOUND_END; *end=current; } else if (str->data[current] == CFG_QUOTE) { CFG_FIELD_TYPE(field)=CFG_TYPE_SCALAR; CFG_FIELD_ELTYPE(field)=CFG_ELTYPE_QUOTED_STRING; *end = copy_quoted_string(field, str, current, status); } else { CFG_FIELD_TYPE(field)=CFG_TYPE_SCALAR; CFG_FIELD_ELTYPE(field)=CFG_ELTYPE_BARE; //*end = copy_bare_token(field, str, current, status); *end = copy_bare_array_token(field, str, current, status); } _cfg_get_field_bail: if (*status) { field=cfg_field_free(field); } return field; }