int main(int argc, char *argv[]) { log_t *log; log = open_log(_T("-"), _T("json")); if(log == NULL) { puts("Failed."); } open_section(log, _T("compile")); open_item(log); add_value(log, _T("date"), _T(__DATE__)); add_value(log, _T("time"), _T(__TIME__)); close_item(log); open_item(log); add_value(log, _T("file"), _T(__FILE__)); add_value(log, _T("timestamp"), _T(__TIMESTAMP__)); close_item(log); close_section(log); open_section(log, _T("test")); open_item(log); add_value(log, _T("test"), _T("field")); close_item(log); close_section(log); close_log(log); return 0; }
/** * anjuta_plugin_description_new_from_string: * @data: The data to parse. The format of the data is .ini style. * * Parses the given plugin description data (usally read from the plugin * description file and creates an instance of #AnjutaPluginDescription. * The format of the content string is similar to .ini format. * * Return value: a new #AnjutaPluginDescription object */ AnjutaPluginDescription * anjuta_plugin_description_new_from_string (char *data, GError **error) { AnjutaPluginDescriptionParser parser; parser.df = g_new0 (AnjutaPluginDescription, 1); parser.current_section = -1; parser.n_allocated_lines = 0; parser.n_allocated_sections = 0; parser.line_nr = 1; parser.line = data; /* Put any initial comments in a NULL segment */ open_section (&parser, NULL); while (parser.line != NULL && strlen(parser.line)) { if (*parser.line == '[') { if (!parse_section_start (&parser, error)) return NULL; } else if (is_blank_line (&parser) || *parser.line == '#') parse_comment_or_blank (&parser); else { if (!parse_key_value (&parser, error)) return NULL; } } return parser.df; }
/** * gnome_theme_file_new_from_string: * @data: the string used to create a #GnomeThemeFile. * @error: location to store the error occuring, or NULL to ignore errors * * Creates a #GnomeThemeFile from the data string passed. * * Returns: a #GnomeThemeFile. * * Since: 2.2 **/ GnomeThemeFile * gnome_theme_file_new_from_string (char *data, GError **error) { GnomeThemeFileParser parser; parser.df = g_new0 (GnomeThemeFile, 1); parser.current_section = -1; parser.n_allocated_lines = 0; parser.n_allocated_sections = 0; parser.line_nr = 1; parser.line = data; /* Put any initial comments in a NULL segment */ open_section (&parser, NULL); while (parser.line && *parser.line) { if (*parser.line == '[') { if (!parse_section_start (&parser, error)) return NULL; } else if (is_blank_line (&parser) || *parser.line == '#') parse_comment_or_blank (&parser); else { if (!parse_key_value (&parser, error)) return NULL; } } return parser.df; }
static dbus_bool_t parse_section_start (BusDesktopFileParser *parser, DBusError *error) { int line_end, eol_len; char *section_name; _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len)) line_end = parser->len; if (line_end - parser->pos <= 2 || _dbus_string_get_byte (&parser->data, line_end - 1) != ']') { report_error (parser, "Invalid syntax for section header", BUS_DESKTOP_PARSE_ERROR_INVALID_SYNTAX, error); parser_free (parser); return FALSE; } section_name = unescape_string (parser, &parser->data, parser->pos + 1, line_end - 1, error); if (section_name == NULL) { parser_free (parser); return FALSE; } if (!is_valid_section_name (section_name)) { report_error (parser, "Invalid characters in section name", BUS_DESKTOP_PARSE_ERROR_INVALID_CHARS, error); parser_free (parser); dbus_free (section_name); return FALSE; } if (open_section (parser, section_name) == NULL) { dbus_free (section_name); parser_free (parser); BUS_SET_OOM (error); return FALSE; } if (line_end == parser->len) parser->pos = parser->len; else parser->pos = line_end + eol_len; parser->line_num += 1; dbus_free (section_name); return TRUE; }
//============================================================================= void CubitInstrumentation::write_context_token(int token) { if (check_token_log()) { if (outputState != GUI) { outputState = open_section(GUI); } else { *tokenUsageStream << ","; } *tokenUsageStream << token; tokenUsageStream->flush(); } }
//============================================================================= void CubitInstrumentation::write_all_words() { if (tokenUsageStream && !keywordMap.empty()) { if (outputState != Keyword) { outputState = open_section(Keyword); } std::map<std::string, int>::iterator it = keywordMap.begin(); std::map<std::string, int>::iterator end = keywordMap.end(); *tokenUsageStream << keywordMap.size() << std::endl; *tokenUsageStream << (*it).first; ++it; for ( ; it != end; it++) { *tokenUsageStream << "," << (*it).first; } close_section(); tokenUsageStream->flush(); } }
//============================================================================= void CubitInstrumentation::write_keywords(std::vector<CubitString> keywords) { if (check_token_log() && !keywords.empty()) { if (outputState != Command) { outputState = open_section(Command); } else { *tokenUsageStream << ","; } *tokenUsageStream << lookup_keyword(keywords[0].c_str()); for (size_t i = 1; i < keywords.size(); i++) { int debug = lookup_keyword(keywords[i].c_str()); *tokenUsageStream << ":" << debug; } tokenUsageStream->flush(); } }
static gboolean parse_section_start (AnjutaPluginDescriptionParser *parser, GError **error) { gchar *line_end; gchar *section_name; line_end = strchr (parser->line, '\n'); if (line_end == NULL) line_end = parser->line + strlen (parser->line); if (line_end - parser->line <= 2 || line_end[-1] != ']') { report_error (parser, "Invalid syntax for section header", ANJUTA_PLUGIN_DESCRIPTION_PARSE_ERROR_INVALID_SYNTAX, error); parser_free (parser); return FALSE; } section_name = unescape_string (parser->line + 1, line_end - parser->line - 2); if (section_name == NULL) { report_error (parser, "Invalid escaping in section name", ANJUTA_PLUGIN_DESCRIPTION_PARSE_ERROR_INVALID_ESCAPES, error); parser_free (parser); return FALSE; } open_section (parser, section_name); parser->line = (line_end) ? line_end + 1 : NULL; parser->line_nr++; g_free (section_name); return TRUE; }
static gboolean parse_section_start (GnomeThemeFileParser *parser, GError **error) { gchar *line_end; gchar *section_name; line_end = strchr (parser->line, '\n'); if (line_end == NULL) line_end = parser->line + strlen (parser->line); if (line_end - parser->line <= 2 || line_end[-1] != ']') { report_error (parser, "Invalid syntax for section header", GNOME_THEME_FILE_PARSE_ERROR_INVALID_SYNTAX, error); parser_free (parser); return FALSE; } section_name = unescape_string (parser->line + 1, line_end - parser->line - 2); if (section_name == NULL) { report_error (parser, "Invalid escaping in section name", GNOME_THEME_FILE_PARSE_ERROR_INVALID_ESCAPES, error); parser_free (parser); return FALSE; } open_section (parser, section_name); parser->line = (line_end) ? line_end + 1 : NULL; parser->line_nr++; g_free (section_name); return TRUE; }
/* Load a font and add it to the beginning of the global font list. Returns 0 upon success, nonzero upon failure. */ grub_font_t grub_font_load (const char *filename) { grub_file_t file = 0; struct font_file_section section; char magic[4]; grub_font_t font = 0; #if FONT_DEBUG >= 1 grub_dprintf ("font", "add_font(%s)\n", filename); #endif if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+') file = grub_buffile_open (filename, 1024); else { const char *prefix = grub_env_get ("prefix"); char *fullname, *ptr; if (!prefix) { grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix"); goto fail; } fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1 + sizeof ("/fonts/") + sizeof (".pf2")); if (!fullname) goto fail; ptr = grub_stpcpy (fullname, prefix); ptr = grub_stpcpy (ptr, "/fonts/"); ptr = grub_stpcpy (ptr, filename); ptr = grub_stpcpy (ptr, ".pf2"); *ptr = 0; file = grub_buffile_open (fullname, 1024); grub_free (fullname); } if (!file) goto fail; #if FONT_DEBUG >= 3 grub_dprintf ("font", "file opened\n"); #endif /* Read the FILE section. It indicates the file format. */ if (open_section (file, §ion) != 0) goto fail; #if FONT_DEBUG >= 3 grub_dprintf ("font", "opened FILE section\n"); #endif if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FILE, sizeof (FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0) { grub_error (GRUB_ERR_BAD_FONT, "font file format error: 1st section must be FILE"); goto fail; } #if FONT_DEBUG >= 3 grub_dprintf ("font", "section name ok\n"); #endif if (section.length != 4) { grub_error (GRUB_ERR_BAD_FONT, "font file format error (file type ID length is %d " "but should be 4)", section.length); goto fail; } #if FONT_DEBUG >= 3 grub_dprintf ("font", "section length ok\n"); #endif /* Check the file format type code. */ if (grub_file_read (file, magic, 4) != 4) goto fail; #if FONT_DEBUG >= 3 grub_dprintf ("font", "read magic ok\n"); #endif if (grub_memcmp (magic, FONT_FORMAT_PFF2_MAGIC, 4) != 0) { grub_error (GRUB_ERR_BAD_FONT, "invalid font magic %x %x %x %x", magic[0], magic[1], magic[2], magic[3]); goto fail; } #if FONT_DEBUG >= 3 grub_dprintf ("font", "compare magic ok\n"); #endif /* Allocate the font object. */ font = (grub_font_t) grub_zalloc (sizeof (struct grub_font)); if (!font) goto fail; font_init (font); font->file = file; #if FONT_DEBUG >= 3 grub_dprintf ("font", "allocate font ok; loading font info\n"); #endif /* Load the font information. */ while (1) { if (open_section (file, §ion) != 0) { if (section.eof) break; /* Done reading the font file. */ else goto fail; } #if FONT_DEBUG >= 2 grub_dprintf ("font", "opened section %c%c%c%c ok\n", section.name[0], section.name[1], section.name[2], section.name[3]); #endif if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME, sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0) { font->name = read_section_as_string (§ion); if (!font->name) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_POINT_SIZE, sizeof (FONT_FORMAT_SECTION_NAMES_POINT_SIZE) - 1) == 0) { if (read_section_as_short (§ion, &font->point_size) != 0) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_WEIGHT, sizeof (FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1) == 0) { char *wt; wt = read_section_as_string (§ion); if (!wt) continue; /* Convert the weight string 'normal' or 'bold' into a number. */ if (grub_strcmp (wt, "normal") == 0) font->weight = FONT_WEIGHT_NORMAL; else if (grub_strcmp (wt, "bold") == 0) font->weight = FONT_WEIGHT_BOLD; grub_free (wt); } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH, sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH) - 1) == 0) { if (read_section_as_short (§ion, &font->max_char_width) != 0) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT, sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT) - 1) == 0) { if (read_section_as_short (§ion, &font->max_char_height) != 0) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_ASCENT, sizeof (FONT_FORMAT_SECTION_NAMES_ASCENT) - 1) == 0) { if (read_section_as_short (§ion, &font->ascent) != 0) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DESCENT, sizeof (FONT_FORMAT_SECTION_NAMES_DESCENT) - 1) == 0) { if (read_section_as_short (§ion, &font->descent) != 0) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_CHAR_INDEX, sizeof (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1) == 0) { if (load_font_index (file, section.length, font) != 0) goto fail; } else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DATA, sizeof (FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0) { /* When the DATA section marker is reached, we stop reading. */ break; } else { /* Unhandled section type, simply skip past it. */ #if FONT_DEBUG >= 3 grub_dprintf ("font", "Unhandled section type, skipping.\n"); #endif grub_off_t section_end = grub_file_tell (file) + section.length; if ((int) grub_file_seek (file, section_end) == -1) goto fail; } } if (!font->name) { grub_dprintf ("font", "Font has no name.\n"); font->name = grub_strdup ("Unknown"); } #if FONT_DEBUG >= 1 grub_dprintf ("font", "Loaded font `%s'.\n" "Ascent=%d Descent=%d MaxW=%d MaxH=%d Number of characters=%d.\n", font->name, font->ascent, font->descent, font->max_char_width, font->max_char_height, font->num_chars); #endif if (font->max_char_width == 0 || font->max_char_height == 0 || font->num_chars == 0 || font->char_index == 0 || font->ascent == 0 || font->descent == 0) { grub_error (GRUB_ERR_BAD_FONT, "invalid font file: missing some required data"); goto fail; } /* Add the font to the global font registry. */ if (register_font (font) != 0) goto fail; return font; fail: if (file) grub_file_close (file); if (font) font->file = 0; free_font (font); return 0; }
int main(int argc, char **argv) { char *basename = NULL; char *tname = NULL; char *dname = NULL; char *pname = NULL; char *layers_str; FILE *part_f; uint iblock = 0; dub_init(); PPARM_INT_D(iblock, IBLOCK); PPARM_STR(layers_str, LAYERS); glist *layers = str2glist_len(&layers_str, NUM_FW_LAYERS - 1); open_section(FW, iblock); open_section(INVA, iblock); basename = pparm_common_name("fwlayers"); asprintf(&dname, "%s.%u.sect", basename, iblock); asprintf(&tname, "%s.%u.toc.sect", basename, iblock); asprintf(&pname, "%s.%u.nfo", basename, iblock); free(basename); if (!(data_f = fopen64(dname, "w+"))) dub_sysdie("Couldn't open section %s", dname); if (!(toc_f = fopen64(tname, "w+"))) dub_sysdie("Couldn't open section %s", tname); if (!(part_f = fopen64(pname, "w+"))) dub_sysdie("Couldn't open section %s", tname); if (setvbuf(data_f, NULL, _IOFBF, IO_BUF_SIZE)) dub_sysdie("Couldn't open input buffer"); if (setvbuf(toc_f, NULL, _IOFBF, IO_BUF_SIZE)) dub_sysdie("Couldn't open input buffer"); u32 num_entries = 0; fw_layers[0].idx = num_entries; int p, no, prev_p = 0, prev_offs = 0; for (p = 0; p < NUM_FW_LAYERS - 1; p++){ dub_msg("Layer %u", p); Pvoid_t ix = ixemes_freq_range(p, prev_p, layers->lst[p]); prev_p = layers->lst[p]; num_entries += encode_layer(ix); dub_msg("LAYER %u NUM %u", p, num_entries); fw_layers[p + 1].idx = num_entries; fw_layers[p + 1].max_freq = layers->lst[p]; u32 offs = (u32)ftello64(data_f); dub_msg("Layer takes %u bytes", offs - prev_offs); prev_offs = offs; J1FA(no, ix); } Pvoid_t ix = ixemes_freq_range(p, prev_p, 1 << 31); num_entries += encode_layer(ix); fw_layers[p + 1].idx = num_entries; fw_layers[p + 1].max_freq = 1 << 31; u32 offs = (u32)ftello64(data_f); dub_msg("Layer takes %u bytes", offs - prev_offs); fwrite(fw_layers, sizeof(fw_layers), 1, part_f); return 0; }