static void handle_comments (xmms_xform_t *xform, xmms_flac_data_t *data) { FLAC__StreamMetadata_VorbisComment *vc; gint i; g_return_if_fail (data->vorbiscomment); vc = &data->vorbiscomment->data.vorbis_comment; for (i = 0; i < vc->num_comments; i++) { FLAC__byte *ptr, *content = vc->comments[i].entry; gint j; /* check whether it's a valid comment */ if (!content || !*content || *content == '=') continue; for (ptr = content, j = 0; j < vc->comments[i].length; ptr++, j++) if (*ptr == '=') break; if (j == vc->comments[i].length) continue; handle_comment (xform, (gchar *) content, j, (gchar *) ptr + 1); } }
/* * Read a declaration up to a semicolon or an open curly brace and add it to <declaration>. */ static int handle_declaration(FILE *fp, Buffer *declaration) { int c; while ((c = fgetc(fp)) != EOF) { if (c == ';') { bufAddC(declaration, c); break; } else if (c == '{') { Buffer body = { 0 }; handle_compound(fp, &body); bufReset(&body); break; } else if (c == '/') { bufAddC(declaration, c); handle_comment(fp, declaration); } else if (c == '"' || c == '\'') { handle_string(fp, declaration, c); } else { bufAddC(declaration, c); } } return 0; }
/* Inspect the line */ static int parser_inspect(struct parser_obj *po) { int error = EOK; uint32_t action = PARSE_DONE; TRACE_FLOW_ENTRY(); TRACE_INFO_STRING("Buffer:", po->last_read); TRACE_INFO_NUMBER("In comment:", po->inside_comment); if (check_for_comment(po->last_read, po->last_read_len, !(po->parse_flags & INI_PARSE_NO_C_COMMENTS), &(po->inside_comment))) { error = handle_comment(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to process comment", error); return error; } } else if (isspace(*(po->last_read))) { error = handle_space(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to process line wrapping", error); return error; } } else if (*(po->last_read) == '[') { error = handle_section(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to save section", error); return error; } } else { error = handle_kvp(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to save kvp", error); return error; } } /* Move to the next action */ error = col_enqueue_unsigned_property(po->queue, PARSE_ACTION, action); if (error) { TRACE_ERROR_NUMBER("Failed to schedule an action", error); return error; } TRACE_FLOW_EXIT(); return error; }
static int parse_int (JDFits_Keyword_Type *kwt) { char *p, *pbeg, *pmax; int32 i; long ilong; if ((kwt->type & JDFITS_UNPARSED_TYPE) == 0) return 0; pbeg = kwt->v.sval; pmax = kwt->comment; /* for unparsed cards, this * points to the end of the * card */ /* Check for a hex value--- it is illegal but it happens :( */ p = pbeg; while (p < pmax) { if ((*p == '/') || (*p == ' ')) break; if ((unsigned int) (*p | 0x20) >= (unsigned int) 'a') return parse_int_as_hex (kwt); p++; } p = pbeg; if (*p == '+') p++; if (1 != sscanf ((char *) p, "%ld", &ilong)) { jdfits_error ("Error parsing integer value for %s.", kwt->name); return -1; } i = (int32) ilong; while (p < pmax) { if (!isdigit (*p) && (*p != ' ') && (*p != '-')) { if (*p == '/') break; jdfits_warning ("Excess junk at end of integer field for %s.", kwt->name); break; } p++; } kwt->type = JDFITS_INT_TYPE; kwt->v.ival = i; handle_comment (kwt, p, pmax); return 0; }
static int parse_bool (JDFits_Keyword_Type *kwt) { char *p, *pmax; if ((kwt->type & JDFITS_UNPARSED_TYPE) == 0) return 0; p = kwt->v.sval; pmax = kwt->comment; kwt->v.ival = (*p == 'T'); kwt->type = JDFITS_BOOL_TYPE; handle_comment (kwt, p + 1, pmax); return 0; }
static int parse_float64 (JDFits_Keyword_Type *kwt) { char *p, *pbeg, *pmax; float64 x; if ((kwt->type & JDFITS_UNPARSED_TYPE) == 0) return 0; pbeg = kwt->v.sval; pmax = kwt->comment; /* for unparsed cards, this * points to the end of the * card */ /* Change [+-]ddd.dddD to [+-]ddd.dddE */ p = pbeg; if ((p < pmax) && ((*p == '+') || (*p == '-'))) p++; while ((p < pmax) && isdigit(*p)) p++; if ((p < pmax) && (*p == '.')) p++; while ((p < pmax) && isdigit(*p)) p++; if (*p == 'D') *p = 'E'; p = pbeg; if (1 != sscanf (p, "%lf", &x)) { jdfits_error ("Error parsing floating value for %s.", kwt->name); return -1; } while (p < pmax) { if (*p == '/') break; p++; } kwt->type = JDFITS_FLOAT64_TYPE; kwt->v.dval = x; handle_comment (kwt, p, pmax); return 0; }
int readLine(FILE *fp, char *buf, int maxSize) { char *p; int n; while (1) { if (fgets(buf, maxSize, fp) == NULL) return 0; if (badline(buf)) continue; else if ((n = handle_comment(buf)) > 0) return (n); break; } p = strchr(buf, '\n'); *p = '\0'; return (p - buf); }
/* * Read a compound statement and add it to <buffer>. */ static int handle_compound(FILE *fp, Buffer *buffer) { int c; while ((c = fgetc(fp)) != EOF) { bufAddC(buffer, c); if (c == '}') break; else if (c == '"' || c == '\'') handle_string(fp, buffer, c); else if (c == '{') handle_compound(fp, buffer); else if (c == '/') { bufAddC(buffer, c); handle_comment(fp, buffer); } } return 0; }
/** * Load a file containing presetting information (a configuration file). */ static void file_preset(tOptions * opts, char const * fname, int dir) { tmap_info_t cfgfile; tOptState optst = OPTSTATE_INITIALIZER(PRESET); opt_state_mask_t st_flags = optst.flags; char * ftext = text_mmap(fname, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile); if (TEXT_MMAP_FAILED_ADDR(ftext)) return; if (dir == DIRECTION_CALLED) { st_flags = OPTST_DEFINED; dir = DIRECTION_PROCESS; } /* * IF this is called via "optionProcess", then we are presetting. * This is the default and the PRESETTING bit will be set. * If this is called via "optionFileLoad", then the bit is not set * and we consider stuff set herein to be "set" by the client program. */ if ((opts->fOptSet & OPTPROC_PRESETTING) == 0) st_flags = OPTST_SET; do { optst.flags = st_flags; ftext = SPN_WHITESPACE_CHARS(ftext); if (IS_VAR_FIRST_CHAR(*ftext)) { ftext = handle_cfg(opts, &optst, ftext, dir); } else switch (*ftext) { case '<': if (IS_VAR_FIRST_CHAR(ftext[1])) ftext = handle_struct(opts, &optst, ftext, dir); else switch (ftext[1]) { case '?': ftext = handle_directive(opts, ftext); break; case '!': ftext = handle_comment(ftext); break; case '/': ftext = strchr(ftext + 2, '>'); if (ftext++ != NULL) break; default: ftext = NULL; } if (ftext == NULL) goto all_done; break; case '[': ftext = handle_section(opts, ftext); break; case '#': ftext = strchr(ftext + 1, NL); break; default: goto all_done; /* invalid format */ } } while (ftext != NULL); all_done: text_munmap(&cfgfile); }
/* Process line starts with space */ static int handle_space(struct parser_obj *po, uint32_t *action) { int error = EOK; int space_err = 0; TRACE_FLOW_ENTRY(); if (po->parse_flags & INI_PARSE_NOWRAP) { /* In this case an empty line is a comment. */ if (is_just_spaces(po->last_read, po->last_read_len)) { error = handle_comment(po, action); TRACE_FLOW_EXIT(); return error; } /* Wrapping is not allowed */ if (!is_allowed_spaces(po->last_read, po->last_read_len, po->parse_flags, &space_err)) { *action = PARSE_ERROR; po->last_error = space_err; error = EOK; } else { /* Allowed spaces will be trimmed * inside KVP processing. */ error = handle_kvp(po, action); } TRACE_FLOW_EXIT(); return error; } /* Do we have current value object? */ if (po->key) { /* This is a new line in a folded value */ error = value_add_to_arrays(po->last_read, po->last_read_len, po->raw_lines, po->raw_lengths); if (error) { TRACE_ERROR_NUMBER("Failed to add line to value", error); return error; } /* Do not free the line, it is now an element of the array */ po->last_read = NULL; po->last_read_len = 0; *action = PARSE_READ; } else { /* Check if this is a completely empty line */ if (is_just_spaces(po->last_read, po->last_read_len)) { error = handle_comment(po, action); if (error) { TRACE_ERROR_NUMBER("Failed to process comment", error); return error; } } else { /* We do not have an active value * but have a line is starting with a space. * For now it is error. * We can change it in future if * people find it being too restrictive */ *action = PARSE_ERROR; po->last_error = ERR_SPACE; } } TRACE_FLOW_EXIT(); return EOK; }
static int parse_string (JDFits_Keyword_Type *kwt) { char *pend, *pmax, *pbeg, *p1, *p2; if ((kwt->type & JDFITS_UNPARSED_TYPE) == 0) return 0; pmax = kwt->comment; /* for unparsed cards, this * points to the end of the * card */ pbeg = kwt->v.sval; if (*pbeg != '\'') { /* This is an ugly hack to handle cards without values! * FIXME!!!! */ kwt->v.sval = pbeg = pmax - 1; *pbeg = 0; kwt->comment = NULL; return 0; } pbeg++; /* skip by opening ' */ p2 = p1 = pbeg; while (p1 < pmax) { unsigned char ch = *p1; if (ch == '\'') { p1++; if ((p1 == pmax) || (*p1 != '\'')) { p1--; break; } } *p2++ = ch; p1++; } if (p1 == pmax) { jdfits_warning ("Card %s lacks closing ' character.", kwt->name); p1--; if (p2 == pmax) p2--; } p2--; /* Trailing blanks not significant */ while (*p2 == ' ') p2--; *(p2 + 1) = 0; kwt->v.sval = pbeg; kwt->type = JDFITS_STRING_TYPE; pend = p1 + 1; handle_comment (kwt, pend, pmax); return 0; }
static int parse_int_as_hex (JDFits_Keyword_Type *kwt) { char *p, *pbeg, *pmax; int32 i; int sign = 1; if ((kwt->type & JDFITS_UNPARSED_TYPE) == 0) return 0; pbeg = kwt->v.sval; pmax = kwt->comment; /* for unparsed cards, this * points to the end of the * card */ jdfits_warning ("\ Keyword %s appeard to have an integer value expressed in HEX form.\n\ This file does NOT conform to the fits standard-- it is NOT a fits file.", kwt->name); p = pbeg; if (p < pmax) { if (*p == '+') { sign = 1; p++; } else if (*p == '-') { sign = -1; p++; } } else sign = 1; i = 0; while (p < pmax) { long ich = *p; if ((ich <= '9') && (ich >= '0')) ich = ich - '0'; else if (((ich = ich | 0x20) >= 'a') && (ich <= 'f')) ich = 10 + (ich - 'a'); else break; i = 16 * i + ich; p++; } i = i * sign; while (p < pmax) { if (*p != ' ') { if (*p == '/') break; jdfits_warning ("Excess junk at end of integer field for %s.", kwt->name); break; } p++; } kwt->type = JDFITS_INT_TYPE; kwt->v.ival = i; handle_comment (kwt, p, pmax); return 0; }
struct MINI_Section *mini_load(char *text) { char *it = text; struct MINI_Section *section_it = NULL; struct MINI_Section *section_start = NULL; struct MINI_KeyValue *value_it = NULL; while(*it != 0) { if(*it == '#') { it = handle_comment(it); if(*it == 0) { return section_start; } } else if(*it == '[') { it++; it = skip_wspace(it); if(*it == 0) { return NULL; } if(section_start == NULL) { section_start = calloc(1, sizeof(struct MINI_Section)); if(section_start == NULL) { return NULL; } section_it = section_start; section_it->next = NULL; } else { section_it->next = calloc(1, sizeof(struct MINI_Section)); if(section_it->next == NULL) { return NULL; } section_it = section_it->next; section_it->next = NULL; } section_it->values = NULL; section_it->name = get_name(&it); if(*section_it->name == 0) { return NULL; } it = skip_wspace(it); if(*it == 0) { return NULL; } if(*it != ']') { return NULL; } it++; while(1) { it = skip_wspace(it); if(*it == 0) { return section_start; } else if(*it == '#') { it = handle_comment(it); if(*it == 0) { return section_start; } } else if(*it == '[') { break; } else { if(section_it->values == NULL) { section_it->values = calloc(1, sizeof(struct MINI_KeyValue)); if(section_it->values == NULL) { return NULL; } value_it = section_it->values; value_it->next = NULL; } else { value_it->next = calloc(1, sizeof(struct MINI_KeyValue)); if(value_it->next == NULL) { return NULL; } value_it = value_it->next; value_it->next = NULL; } value_it->name = get_name(&it); if(*value_it->name == 0) { return NULL; } it = skip_wspace(it); if(*it == 0) { return NULL; } if(*it != '=') { return NULL; } /* first letter after = */ it++; if(*it == 0) { return NULL; } it = skip_wspace(it); if(*it == 0) { return NULL; } value_it->value = get_value(&it); if(*value_it->value == 0) { return NULL; } } } } if(*it == '[') { continue; } it++; } return 0; }
/* * Process input from <in> and write the result to <out>. The name of the original file from which * prototypes are to be extracted is in <input>. */ static int process(const char *input, FILE *in, FILE *out) { char *current_file = strdup(input); Buffer comment = { 0 }, declaration = { 0 }; int c; while ((c = fgetc(in)) != EOF) { if (c == '#') { handle_preprocessor_line(in, ¤t_file); } else if (c == '/') { bufSetC(&comment, c); handle_comment(in, &comment); } else if (!isspace(c) && c != ';') { bufSetC(&declaration, c); handle_declaration(in, &declaration); if (strchr(bufGet(&declaration), '(') != NULL && strcmp(current_file, input) == 0) { const char *str; int len; while (TRUE) { str = bufGet(&declaration); len = bufLen(&declaration); if (isspace(str[0])) bufTrim(&declaration, 1, 0); else break; } while (TRUE) { str = bufGet(&declaration); len = bufLen(&declaration); if (isspace(str[len - 1])) bufTrim(&declaration, 0, 1); else break; } if (include_static == TRUE || strncmp(str, "static", 6) != 0) { fputc('\n', out); if (include_comment && bufLen(&comment) > 0) { fputs(bufGet(&comment), out); fputc('\n', out); } fputs(str, out); if (str[len - 1] != ';') fputc(';', out); fputc('\n', out); } } bufClear(&comment); } } bufReset(&comment); bufReset(&declaration); free(current_file); return 0; }