static void filelist_parser_package_start (FilelistSAXContext *ctx, const char *name, const char **attrs) { SAXContext *sctx = &ctx->sctx; Package *p = sctx->current_package; int i; const char *attr; const char *value; g_assert (p != NULL); sctx->want_text = TRUE; if (!strcmp (name, "version")) { parse_version_info(attrs, p); } else if (!strcmp (name, "file")) { ctx->current_file = package_file_new (); for (i = 0; attrs && attrs[i]; i++) { attr = attrs[i]; value = attrs[++i]; if (!strcmp (attr, "type")) ctx->current_file->type = g_string_chunk_insert_const (p->chunk, value); } } }
static void other_parser_package_start (OtherSAXContext *ctx, const char *name, const char **attrs) { SAXContext *sctx = &ctx->sctx; Package *p = sctx->current_package; int i; const char *attr; const char *value; g_assert (p != NULL); sctx->want_text = TRUE; if (!strcmp (name, "version")) { parse_version_info(attrs, p); } else if (!strcmp (name, "changelog")) { ctx->current_entry = changelog_entry_new (); for (i = 0; attrs && attrs[i]; i++) { attr = attrs[i]; value = attrs[++i]; if (!strcmp (attr, "author")) ctx->current_entry->author = g_string_chunk_insert_const (p->chunk, value); else if (!strcmp (attr, "date")) ctx->current_entry->date = strtol(value, NULL, 10); } } }
int ckpmon_run(char *arg) { extern lua_State *L; gchar *pmon_input = NULL; char *pmon_buf = NULL; gsize length = 0; GRegex *regex; GMatchInfo *match_info; GError *err = NULL; printPrompt("PMON版本输入格式如下例:\"1.3.6\"\n请输入\n"); // get pmon spec version: pmon_input int len = getTableNumElement(L, "con", "PMONVER_LEN"); pmon_input = getNCharsPrompt("PMON版本条码", len, TRUE); if (pmon_input == NULL) { printPrompt("未输入\n"); return 1; } printPrompt("输入版本号为:"); printMsg(pmon_input); printMsg("\n"); // get pmon env version: pmon_env g_file_get_contents ("/proc/cmdline", &pmon_buf, &length, NULL); regex = g_regex_new (PMON_STR, G_REGEX_NO_AUTO_CAPTURE | G_REGEX_OPTIMIZE | G_REGEX_DUPNAMES, 0, &err); g_regex_match (regex, pmon_buf, 0, &match_info); gchar *pmon_named = g_match_info_fetch_named(match_info, "pmonver"); g_print ("%s\n", pmon_named); // cmp gchar *text_pmon_env = g_strdup_printf("本机的版本号[cmdline]为:%s\n", pmon_named); printPrompt(g_string_chunk_insert_const(text_chunk, text_pmon_env)); g_free(text_pmon_env); if (strcasecmp(pmon_input, (const char *)pmon_named)) { printNG("机器当前PMON版本号与标准不相符!\n"); return 1; } else { printOK("PMON版本号相符。\n"); } g_free(pmon_input); // TODO: here free g_strdup, but have not test g_free (pmon_named); g_match_info_free (match_info); g_regex_unref (regex); return 0; }
static void store_iline(gpointer key, gpointer value, gpointer user_data) { guint idx = GPOINTER_TO_UINT(value); pip_db_t *db = user_data; pip_ref_t *ref = &db->pip_array[idx]; gchar **endpoints = g_strsplit (key, " ", 2); ref->name = key; if (endpoints) { ref->start = g_string_chunk_insert_const (db->chunk, endpoints[0]); ref->end = g_string_chunk_insert_const (db->chunk, endpoints[1]); } else { ref->start = NULL; ref->end = NULL; } g_strfreev(endpoints); }
static void primary_parser_format_start (PrimarySAXContext *ctx, const char *name, const char **attrs) { SAXContext *sctx = &ctx->sctx; Package *p = sctx->current_package; int i; const char *attr; const char *value; g_assert (p != NULL); if (!strcmp (name, "rpm:header-range")) { for (i = 0; attrs && attrs[i]; i++) { attr = attrs[i]; value = attrs[++i]; if (!strcmp (attr, "start")) p->rpm_header_start = strtol(value, NULL, 10); else if (!strcmp (attr, "end")) p->rpm_header_end = strtol(value, NULL, 10); } } else if (!strcmp (name, "rpm:provides")) { ctx->state = PRIMARY_PARSER_DEP; ctx->current_dep_list = &sctx->current_package->provides; } else if (!strcmp (name, "rpm:requires")) { ctx->state = PRIMARY_PARSER_DEP; ctx->current_dep_list = &sctx->current_package->requires; } else if (!strcmp (name, "rpm:obsoletes")) { ctx->state = PRIMARY_PARSER_DEP; ctx->current_dep_list = &sctx->current_package->obsoletes; } else if (!strcmp (name, "rpm:conflicts")) { ctx->state = PRIMARY_PARSER_DEP; ctx->current_dep_list = &sctx->current_package->conflicts; } else if (!strcmp (name, "file")) { for (i = 0; attrs && attrs[i]; i++) { attr = attrs[i]; value = attrs[++i]; if (!strcmp (attr, "type")) { ctx->current_file = package_file_new (); ctx->current_file->type = g_string_chunk_insert_const (p->chunk, value); } } } }
static const char * get_static_string (const char *s) { static GStringChunk * static_strings = NULL; if (s == NULL) return NULL; if (static_strings == NULL) static_strings = g_string_chunk_new (1024); return g_string_chunk_insert_const (static_strings, s); }
static inline int load_wire_atom(const wire_db_t *db, GKeyFile *keyfile, const gchar *wirename) { GError *err = NULL; int retval = 0; gint id = g_key_file_get_integer(keyfile, wirename, "ID", &err); wire_simple_t *wire = (void *) &db->wires[id]; wire_t *detail = (void *) &db->details[id]; if (err) goto out_err; /* Insert the wirename */ debit_log(L_WIRES, "Inserting wire %s, id %i", wirename, id); db->names[id] = g_string_chunk_insert_const(db->wirenames, wirename); #define GET_STRUCT_MEMBER(structname, structmem, strname) \ do { structname->structmem = g_key_file_get_integer(keyfile, wirename, #strname, &err);\ if (err)\ goto out_err;\ } while (0) #define GET_STRUCT_MEMBER_LIST(structname, structmem, structmemlen, strname) \ do { \ gsize listsize = 0; \ structname->structmem = g_key_file_get_integer_list(keyfile, wirename, #strname, \ &listsize, &err);\ structname->structmemlen = (typeof(structname->structmemlen)) listsize; \ if (err)\ goto out_err;\ } while (0) GET_STRUCT_MEMBER(wire, dx, DX); GET_STRUCT_MEMBER(wire, dy, DY); GET_STRUCT_MEMBER(wire, ep, EP); GET_STRUCT_MEMBER_LIST(wire, fut, fut_len, FUT); GET_STRUCT_MEMBER(detail, type, TYPE); GET_STRUCT_MEMBER(detail, direction, DIR); GET_STRUCT_MEMBER(detail, situation, SIT); return retval; out_err: g_warning("%s", err->message); retval = err->code; g_error_free (err); return retval; }
static void primary_parser_format_end (PrimarySAXContext *ctx, const char *name) { SAXContext *sctx = &ctx->sctx; Package *p = sctx->current_package; g_assert (p != NULL); if (!strcmp (name, "rpm:license")) p->rpm_license = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); if (!strcmp (name, "rpm:vendor")) p->rpm_vendor = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); if (!strcmp (name, "rpm:group")) p->rpm_group = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); if (!strcmp (name, "rpm:buildhost")) p->rpm_buildhost = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); if (!strcmp (name, "rpm:sourcerpm")) p->rpm_sourcerpm = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); else if (!strcmp (name, "file")) { PackageFile *file = ctx->current_file != NULL ? ctx->current_file : package_file_new (); file->name = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); if (!file->type) file->type = g_string_chunk_insert_const (p->chunk, "file"); p->files = g_slist_prepend (p->files, file); ctx->current_file = NULL; } else if (!strcmp (name, "format")) ctx->state = PRIMARY_PARSER_PACKAGE; }
static void add_pip_line(const gchar *line, void *data) { pip_db_t *db = data; const gchar *chunk; GHashTable *hash = db->hash; guint value_int; gpointer orig_key, value_ptr; chunk = g_string_chunk_insert_const (db->chunk, line); /* query & insert it in the LUT */ if (g_hash_table_lookup_extended (hash, chunk, &orig_key, &value_ptr)) return; value_int = g_hash_table_size(hash); value_ptr = GUINT_TO_POINTER(value_int); debit_log(L_CORRELATE, "Adding pip %s with value %u to the hashtable", chunk, value_int); g_hash_table_insert (hash, (gpointer)chunk, value_ptr); }
/** * ide_debugger_address_map_insert: * @self: a #IdeDebuggerAddressMap * @map: the map entry to insert * * Inserts a new map entry as specified by @entry. * * The contents of @entry are copied and therefore do not need to be kept * around after calling this function. * * See also: ide_debugger_address_map_remove() * * Since: 3.32 */ void ide_debugger_address_map_insert (IdeDebuggerAddressMap *self, const IdeDebuggerAddressMapEntry *entry) { IdeDebuggerAddressMapEntry real = { 0 }; g_return_if_fail (self != NULL); g_return_if_fail (entry != NULL); real.filename = g_string_chunk_insert_const (self->chunk, entry->filename); real.start = entry->start; real.end = entry->end; real.offset = entry->offset; g_sequence_insert_sorted (self->seq, g_slice_dup (IdeDebuggerAddressMapEntry, &real), ide_debugger_address_map_entry_compare, NULL); }
static void filelist_parser_package_end (FilelistSAXContext *ctx, const char *name) { SAXContext *sctx = &ctx->sctx; Package *p = sctx->current_package; g_assert (p != NULL); sctx->want_text = FALSE; if (!strcmp (name, "package")) { if (sctx->package_fn && !*sctx->error) sctx->package_fn (p, sctx->user_data); package_free (p); sctx->current_package = NULL; if (ctx->current_file) { g_free (ctx->current_file); ctx->current_file = NULL; } ctx->state = FILELIST_PARSER_TOPLEVEL; } else if (!strcmp (name, "file")) { PackageFile *file = ctx->current_file; file->name = g_string_chunk_insert_len (p->chunk, sctx->text_buffer->str, sctx->text_buffer->len); if (!file->type) file->type = g_string_chunk_insert_const (p->chunk, "file"); p->files = g_slist_prepend (p->files, file); ctx->current_file = NULL; } }
unsigned get_pip_index(const pip_db_t *pipdb, const gchar *pip) { const gchar *chunk = g_string_chunk_insert_const (pipdb->chunk, pip); return GPOINTER_TO_UINT(g_hash_table_lookup (pipdb->hash, chunk)); }
static gboolean category_filter_model_update( GtkTreeStore * store ) { int i, n; int low = 0; int all = 0; int high = 0; int public = 0; int normal = 0; int private = 0; int store_pos; GtkTreeIter top; GtkTreeIter iter; GtkTreeModel * model = GTK_TREE_MODEL( store ); GPtrArray * hosts = g_ptr_array_new( ); GStringChunk * strings = g_string_chunk_new( 4096 ); GHashTable * hosts_hash = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, g_free ); GObject * o = G_OBJECT( store ); GtkTreeModel * tmodel = GTK_TREE_MODEL( g_object_get_qdata( o, TORRENT_MODEL_KEY ) ); g_object_steal_qdata( o, DIRTY_KEY ); /* Walk through all the torrents, tallying how many matches there are * for the various categories. Also make a sorted list of all tracker * hosts s.t. we can merge it with the existing list */ if( gtk_tree_model_iter_nth_child( tmodel, &iter, NULL, 0 ) ) do { tr_torrent * tor; const tr_info * inf; int keyCount; char ** keys; gtk_tree_model_get( tmodel, &iter, MC_TORRENT, &tor, -1 ); inf = tr_torrentInfo( tor ); keyCount = 0; keys = g_new( char*, inf->trackerCount ); for( i=0, n=inf->trackerCount; i<n; ++i ) { int k; int * count; char buf[1024]; char * key; gtr_get_host_from_url( buf, sizeof( buf ), inf->trackers[i].announce ); key = g_string_chunk_insert_const( strings, buf ); count = g_hash_table_lookup( hosts_hash, key ); if( count == NULL ) { count = tr_new0( int, 1 ); g_hash_table_insert( hosts_hash, key, count ); g_ptr_array_add( hosts, key ); } for( k=0; k<keyCount; ++k ) if( !strcmp( keys[k], key ) ) break; if( k==keyCount ) keys[keyCount++] = key; } for( i=0; i<keyCount; ++i ) { int * incrementme = g_hash_table_lookup( hosts_hash, keys[i] ); ++*incrementme; } g_free( keys ); ++all; if( inf->isPrivate ) ++private; else ++public;
static void dspy_introspection_model_init_parse_cb (GObject *object, GAsyncResult *result, gpointer user_data) { DspyIntrospectionModel *self = (DspyIntrospectionModel *)object; g_autoptr(Introspect) state = user_data; g_autoptr(GError) error = NULL; DspyNodeInfo *info = NULL; GCancellable *cancellable; gint *n_active; g_assert (DSPY_IS_INTROSPECTION_MODEL (self)); g_assert (G_IS_ASYNC_RESULT (result)); g_assert (state != NULL); g_assert (G_IS_TASK (state->task)); g_assert (state->path != NULL); self = g_task_get_source_object (state->task); n_active = g_task_get_task_data (state->task); cancellable = g_task_get_cancellable (state->task); g_assert (self != NULL); g_assert (DSPY_IS_INTROSPECTION_MODEL (self)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); g_assert (n_active != NULL); g_assert (*n_active > 0); if ((info = parse_xml_finish (self, result, &error))) { g_assert (DSPY_IS_NODE (info)); g_assert (info->kind == DSPY_NODE_KIND_NODE); /* First, queue a bunch of sub-path reads based on any discovered * nodes from querying this specific node. */ for (const GList *iter = info->nodes.head; iter; iter = iter->next) { DspyNodeInfo *child = iter->data; g_autofree gchar *child_path = NULL; g_assert (child != NULL); g_assert (DSPY_IS_NODE (child)); g_assert (child->kind == DSPY_NODE_KIND_NODE); child_path = g_build_path ("/", state->path, child->path, NULL); dspy_introspection_model_introspect (state->task, state->connection, child_path); } /* Now add this node to our root if it contains any intefaces. */ if (info->interfaces->interfaces.length > 0) { g_autofree gchar *abs_path = g_build_path ("/", state->path, info->path, NULL); g_mutex_lock (&self->chunks_mutex); info->path = g_string_chunk_insert_const (self->chunks, abs_path); g_mutex_unlock (&self->chunks_mutex); g_queue_push_tail_link (&self->root->nodes, &info->link); info->parent = (DspyNode *)self->root; emit_row_inserted_for_tree (self, (DspyNode *)info); /* Stolen */ info = NULL; } g_clear_pointer (&info, _dspy_node_free); } if (--(*n_active) == 0) g_task_return_boolean (state->task, TRUE); }
//#define MINIMIZE_STRING_COPYING 1 void PacketListRecord::cacheColumnStrings(column_info *cinfo) { // packet_list_store.c:packet_list_change_record(PacketList *packet_list, PacketListRecord *record, gint col, column_info *cinfo) if (!cinfo) { return; } col_text_.clear(); lines_ = 1; line_count_changed_ = false; for (int column = 0; column < cinfo->num_cols; ++column) { int col_lines = 1; #ifdef MINIMIZE_STRING_COPYING int text_col = cinfo_column_.value(column, -1); /* Column based on frame_data or it already contains a value */ if (text_col < 0) { col_fill_in_frame_data(fdata_, cinfo, column, FALSE); col_text_.append(cinfo->columns[column].col_data); continue; } switch (cinfo->col_fmt[column]) { case COL_PROTOCOL: case COL_INFO: case COL_IF_DIR: case COL_DCE_CALL: case COL_8021Q_VLAN_ID: case COL_EXPERT: case COL_FREQ_CHAN: if (cinfo->columns[column].col_data && cinfo->columns[column].col_data != cinfo->columns[column].col_buf) { /* This is a constant string, so we don't have to copy it */ // XXX - ui/gtk/packet_list_store.c uses G_MAXUSHORT. We don't do proper UTF8 // truncation in either case. int col_text_len = MIN(qstrlen(cinfo->col_data[column]) + 1, COL_MAX_INFO_LEN); col_text_.append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len)); break; } /* !! FALL-THROUGH!! */ case COL_DEF_SRC: case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */ case COL_UNRES_SRC: case COL_DEF_DL_SRC: case COL_RES_DL_SRC: case COL_UNRES_DL_SRC: case COL_DEF_NET_SRC: case COL_RES_NET_SRC: case COL_UNRES_NET_SRC: case COL_DEF_DST: case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */ case COL_UNRES_DST: case COL_DEF_DL_DST: case COL_RES_DL_DST: case COL_UNRES_DL_DST: case COL_DEF_NET_DST: case COL_RES_NET_DST: case COL_UNRES_NET_DST: default: if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) { /* Use the unresolved value in col_expr_val */ // XXX Use QContiguousCache? col_text_.append(cinfo->col_expr.col_expr_val[column]); } else { col_text_.append(cinfo->columns[column].col_data); } break; } #else // MINIMIZE_STRING_COPYING const char *col_str; if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) { /* Use the unresolved value in col_expr_val */ col_str = cinfo->col_expr.col_expr_val[column]; } else { int text_col = cinfo_column_.value(column, -1); if (text_col < 0) { col_fill_in_frame_data(fdata_, cinfo, column, FALSE); } col_str = cinfo->columns[column].col_data; } // g_string_chunk_insert_const manages a hash table of pointers to // strings: // https://git.gnome.org/browse/glib/tree/glib/gstringchunk.c // We might be better off adding the equivalent functionality to // wmem_tree. col_text_.append(g_string_chunk_insert_const(string_pool_, col_str)); for (int i = 0; col_str[i]; i++) { if (col_str[i] == '\n') col_lines++; } if (col_lines > lines_) { lines_ = col_lines; line_count_changed_ = true; } #endif // MINIMIZE_STRING_COPYING } }
int main (int argc, char *argv[]) { GStringChunk *string_chunk; gchar *tmp_string = NULL, *tmp_string_2; gint i; GString *string1, *string2; string_chunk = g_string_chunk_new (1024); for (i = 0; i < 100000; i ++) { tmp_string = g_string_chunk_insert (string_chunk, "hi pete"); if (strcmp ("hi pete", tmp_string) != 0) g_error ("string chunks are broken.\n"); } tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 != tmp_string && strcmp(tmp_string_2, tmp_string) == 0); tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 == tmp_string); g_string_chunk_free (string_chunk); string1 = g_string_new ("hi pete!"); string2 = g_string_new (""); g_assert (string1 != NULL); g_assert (string2 != NULL); g_assert (strlen (string1->str) == string1->len); g_assert (strlen (string2->str) == string2->len); g_assert (string2->len == 0); g_assert (strcmp ("hi pete!", string1->str) == 0); g_assert (strcmp ("", string2->str) == 0); for (i = 0; i < 10000; i++) g_string_append_c (string1, 'a'+(i%26)); g_assert((strlen("hi pete!") + 10000) == string1->len); g_assert((strlen("hi pete!") + 10000) == strlen(string1->str)); #ifndef G_OS_WIN32 /* MSVC and mingw32 use the same run-time C library, which doesn't like the %10000.10000f format... */ g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #else g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #endif g_string_free (string1, TRUE); g_string_free (string2, TRUE); /* append */ string1 = g_string_new ("firsthalf"); g_string_append (string1, "lasthalf"); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* append_len */ string1 = g_string_new ("firsthalf"); g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf")); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* prepend */ string1 = g_string_new ("lasthalf"); g_string_prepend (string1, "firsthalf"); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* prepend_len */ string1 = g_string_new ("lasthalf"); g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf")); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* insert */ string1 = g_string_new ("firstlast"); g_string_insert (string1, 5, "middle"); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert with pos == end of the string */ string1 = g_string_new ("firstmiddle"); g_string_insert (string1, strlen ("firstmiddle"), "last"); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert_len */ string1 = g_string_new ("firstlast"); g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle")); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert_len with magic -1 pos for append */ string1 = g_string_new ("first"); g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last")); g_assert (strcmp (string1->str, "firstlast") == 0); g_string_free (string1, TRUE); /* insert_len with magic -1 len for strlen-the-string */ string1 = g_string_new ("first"); g_string_insert_len (string1, 5, "last", -1); g_assert (strcmp (string1->str, "firstlast") == 0); g_string_free (string1, TRUE); /* g_string_equal */ string1 = g_string_new ("test"); string2 = g_string_new ("te"); g_assert (! g_string_equal(string1, string2)); g_string_append (string2, "st"); g_assert (g_string_equal(string1, string2)); g_string_free (string1, TRUE); g_string_free (string2, TRUE); /* Check handling of embedded ASCII 0 (NUL) characters in GString. */ string1 = g_string_new ("fiddle"); string2 = g_string_new ("fiddle"); g_assert (g_string_equal(string1, string2)); g_string_append_c(string1, '\0'); g_assert (! g_string_equal(string1, string2)); g_string_append_c(string2, '\0'); g_assert (g_string_equal(string1, string2)); g_string_append_c(string1, 'x'); g_string_append_c(string2, 'y'); g_assert (! g_string_equal(string1, string2)); g_assert (string1->len == 8); g_string_append(string1, "yzzy"); g_assert (string1->len == 12); g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0); g_string_insert(string1, 1, "QED"); g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0); g_string_free (string1, TRUE); g_string_free (string2, TRUE); return 0; }
int main (int argc, char *argv[]) { GList *list, *t; GSList *slist, *st; GHashTable *hash_table; GMemChunk *mem_chunk; GStringChunk *string_chunk; GTimer *timer; gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6}; gchar *string; gchar *mem[10000], *tmp_string = NULL, *tmp_string_2; gint i, j; GArray *garray; GPtrArray *gparray; GByteArray *gbarray; GString *string1, *string2; GTree *tree; char chars[62]; GRelation *relation; GTuples *tuples; gint data [1024]; struct { gchar *filename; gchar *dirname; } dirname_checks[] = { #ifndef NATIVE_WIN32 { "/", "/" }, { "////", "/" }, { ".////", "." }, { ".", "." }, { "..", "." }, { "../", ".." }, { "..////", ".." }, { "", "." }, { "a/b", "a" }, { "a/b/", "a/b" }, { "c///", "c" }, #else { "\\", "\\" }, { ".\\\\\\\\", "." }, { ".", "." }, { "..", "." }, { "..\\", ".." }, { "..\\\\\\\\", ".." }, { "", "." }, { "a\\b", "a" }, { "a\\b\\", "a\\b" }, { "c\\\\\\", "c" }, #endif }; guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]); guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U; guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U; #ifdef G_HAVE_GINT64 guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U), gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU); #endif g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n", glib_major_version, glib_minor_version, glib_micro_version, glib_interface_age, glib_binary_age); string = g_get_current_dir (); g_print ("cwd: %s\n", string); g_free (string); g_print ("user: %s\n", g_get_user_name ()); g_print ("real: %s\n", g_get_real_name ()); g_print ("home: %s\n", g_get_home_dir ()); g_print ("tmp-dir: %s\n", g_get_tmp_dir ()); /* type sizes */ g_print ("checking size of gint8: %d", (int)sizeof (gint8)); TEST (NULL, sizeof (gint8) == 1); g_print ("\nchecking size of gint16: %d", (int)sizeof (gint16)); TEST (NULL, sizeof (gint16) == 2); g_print ("\nchecking size of gint32: %d", (int)sizeof (gint32)); TEST (NULL, sizeof (gint32) == 4); #ifdef G_HAVE_GINT64 g_print ("\nchecking size of gint64: %d", (int)sizeof (gint64)); TEST (NULL, sizeof (gint64) == 8); #endif /* G_HAVE_GINT64 */ g_print ("\n"); g_print ("checking g_dirname()..."); for (i = 0; i < n_dirname_checks; i++) { gchar *dirname; dirname = g_dirname (dirname_checks[i].filename); if (strcmp (dirname, dirname_checks[i].dirname) != 0) { g_print ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n", dirname_checks[i].filename, dirname_checks[i].dirname, dirname); n_dirname_checks = 0; } g_free (dirname); } if (n_dirname_checks) g_print ("ok\n"); g_print ("checking doubly linked lists..."); list = NULL; for (i = 0; i < 10; i++) list = g_list_append (list, &nums[i]); list = g_list_reverse (list); for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != (9 - i)) g_error ("Regular insert failed"); } for (i = 0; i < 10; i++) if(g_list_position(list, g_list_nth (list, i)) != i) g_error("g_list_position does not seem to be the inverse of g_list_nth\n"); g_list_free (list); list = NULL; for (i = 0; i < 10; i++) list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one); /* g_print("\n"); g_list_foreach (list, my_list_print, NULL); */ for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != i) g_error ("Sorted insert failed"); } g_list_free (list); list = NULL; for (i = 0; i < 10; i++) list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two); /* g_print("\n"); g_list_foreach (list, my_list_print, NULL); */ for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != (9 - i)) g_error ("Sorted insert failed"); } g_list_free (list); list = NULL; for (i = 0; i < 10; i++) list = g_list_prepend (list, &morenums[i]); list = g_list_sort (list, my_list_compare_two); /* g_print("\n"); g_list_foreach (list, my_list_print, NULL); */ for (i = 0; i < 10; i++) { t = g_list_nth (list, i); if (*((gint*) t->data) != (9 - i)) g_error ("Merge sort failed"); } g_list_free (list); g_print ("ok\n"); g_print ("checking singly linked lists..."); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_append (slist, &nums[i]); slist = g_slist_reverse (slist); for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != (9 - i)) g_error ("failed"); } g_slist_free (slist); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_one); /* g_print("\n"); g_slist_foreach (slist, my_list_print, NULL); */ for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != i) g_error ("Sorted insert failed"); } g_slist_free(slist); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_two); /* g_print("\n"); g_slist_foreach (slist, my_list_print, NULL); */ for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != (9 - i)) g_error("Sorted insert failed"); } g_slist_free(slist); slist = NULL; for (i = 0; i < 10; i++) slist = g_slist_prepend (slist, &morenums[i]); slist = g_slist_sort (slist, my_list_compare_two); /* g_print("\n"); g_slist_foreach (slist, my_list_print, NULL); */ for (i = 0; i < 10; i++) { st = g_slist_nth (slist, i); if (*((gint*) st->data) != (9 - i)) g_error("Sorted insert failed"); } g_slist_free(slist); g_print ("ok\n"); g_print ("checking binary trees...\n"); tree = g_tree_new (my_compare); i = 0; for (j = 0; j < 10; j++, i++) { chars[i] = '0' + j; g_tree_insert (tree, &chars[i], &chars[i]); } for (j = 0; j < 26; j++, i++) { chars[i] = 'A' + j; g_tree_insert (tree, &chars[i], &chars[i]); } for (j = 0; j < 26; j++, i++) { chars[i] = 'a' + j; g_tree_insert (tree, &chars[i], &chars[i]); } g_print ("tree height: %d\n", g_tree_height (tree)); g_print ("tree nnodes: %d\n", g_tree_nnodes (tree)); g_print ("tree: "); g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL); g_print ("\n"); for (i = 0; i < 10; i++) g_tree_remove (tree, &chars[i]); g_print ("tree height: %d\n", g_tree_height (tree)); g_print ("tree nnodes: %d\n", g_tree_nnodes (tree)); g_print ("tree: "); g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL); g_print ("\n"); g_print ("ok\n"); /* check n-way trees */ g_node_test (); g_print ("checking mem chunks..."); mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE); for (i = 0; i < 10000; i++) { mem[i] = g_chunk_new (gchar, mem_chunk); for (j = 0; j < 50; j++) mem[i][j] = i * j; } for (i = 0; i < 10000; i++) { g_mem_chunk_free (mem_chunk, mem[i]); } g_print ("ok\n"); g_print ("checking hash tables..."); hash_table = g_hash_table_new (my_hash, my_hash_compare); for (i = 0; i < 10000; i++) { array[i] = i; g_hash_table_insert (hash_table, &array[i], &array[i]); } g_hash_table_foreach (hash_table, my_hash_callback, NULL); for (i = 0; i < 10000; i++) if (array[i] == 0) g_print ("%d\n", i); for (i = 0; i < 10000; i++) g_hash_table_remove (hash_table, &array[i]); for (i = 0; i < 10000; i++) { array[i] = i; g_hash_table_insert (hash_table, &array[i], &array[i]); } if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 || g_hash_table_size (hash_table) != 5000) g_print ("bad!\n"); g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL); g_hash_table_destroy (hash_table); g_print ("ok\n"); g_print ("checking string chunks..."); string_chunk = g_string_chunk_new (1024); for (i = 0; i < 100000; i ++) { tmp_string = g_string_chunk_insert (string_chunk, "hi pete"); if (strcmp ("hi pete", tmp_string) != 0) g_error ("string chunks are broken.\n"); } tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 != tmp_string && strcmp(tmp_string_2, tmp_string) == 0); tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 == tmp_string); g_string_chunk_free (string_chunk); g_print ("ok\n"); g_print ("checking arrays..."); garray = g_array_new (FALSE, FALSE, sizeof (gint)); for (i = 0; i < 10000; i++) g_array_append_val (garray, i); for (i = 0; i < 10000; i++) if (g_array_index (garray, gint, i) != i) g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), i); g_array_free (garray, TRUE); garray = g_array_new (FALSE, FALSE, sizeof (gint)); for (i = 0; i < 100; i++) g_array_prepend_val (garray, i); for (i = 0; i < 100; i++) if (g_array_index (garray, gint, i) != (100 - i - 1)) g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1); g_array_free (garray, TRUE); g_print ("ok\n"); g_print ("checking strings..."); string1 = g_string_new ("hi pete!"); string2 = g_string_new (""); g_assert (strcmp ("hi pete!", string1->str) == 0); for (i = 0; i < 10000; i++) g_string_append_c (string1, 'a'+(i%26)); #if !(defined (_MSC_VER) || defined (__LCC__)) /* MSVC and LCC use the same run-time C library, which doesn't like the %10000.10000f format... */ g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #else g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #endif g_print ("string2 length = %d...\n", string2->len); string2->str[70] = '\0'; g_print ("first 70 chars:\n%s\n", string2->str); string2->str[141] = '\0'; g_print ("next 70 chars:\n%s\n", string2->str+71); string2->str[212] = '\0'; g_print ("and next 70:\n%s\n", string2->str+142); g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70); g_print ("ok\n"); g_print ("checking timers...\n"); timer = g_timer_new (); g_print (" spinning for 3 seconds...\n"); g_timer_start (timer); while (g_timer_elapsed (timer, NULL) < 3) ; g_timer_stop (timer); g_timer_destroy (timer); g_print ("ok\n"); g_print ("checking g_strcasecmp..."); g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0); g_assert (g_strcasecmp ("frobozz", "frobozz") == 0); g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0); g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0); g_assert (g_strcasecmp ("", "") == 0); g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0); g_assert (g_strcasecmp ("a", "b") < 0); g_assert (g_strcasecmp ("a", "B") < 0); g_assert (g_strcasecmp ("A", "b") < 0); g_assert (g_strcasecmp ("A", "B") < 0); g_assert (g_strcasecmp ("b", "a") > 0); g_assert (g_strcasecmp ("b", "A") > 0); g_assert (g_strcasecmp ("B", "a") > 0); g_assert (g_strcasecmp ("B", "A") > 0); g_print ("ok\n"); g_print ("checking g_strdup..."); g_assert(g_strdup(NULL) == NULL); string = g_strdup(GLIB_TEST_STRING); g_assert(string != NULL); g_assert(strcmp(string, GLIB_TEST_STRING) == 0); g_free(string); g_print ("ok\n"); g_print ("checking g_strconcat..."); string = g_strconcat(GLIB_TEST_STRING, NULL); g_assert(string != NULL); g_assert(strcmp(string, GLIB_TEST_STRING) == 0); g_free(string); string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING, NULL); g_assert(string != NULL); g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING) == 0); g_free(string); g_print ("ok\n"); g_print ("checking g_strdup_printf..."); string = g_strdup_printf ("%05d %-5s", 21, "test"); g_assert (string != NULL); g_assert (strcmp(string, "00021 test ") == 0); g_free (string); g_print ("ok\n"); /* g_debug (argv[0]); */ /* Relation tests */ g_print ("checking relations..."); relation = g_relation_new (2); g_relation_index (relation, 0, g_int_hash, g_int_equal); g_relation_index (relation, 1, g_int_hash, g_int_equal); for (i = 0; i < 1024; i += 1) data[i] = i; for (i = 1; i < 1023; i += 1) { g_relation_insert (relation, data + i, data + i + 1); g_relation_insert (relation, data + i, data + i - 1); } for (i = 2; i < 1022; i += 1) { g_assert (! g_relation_exists (relation, data + i, data + i)); g_assert (! g_relation_exists (relation, data + i, data + i + 2)); g_assert (! g_relation_exists (relation, data + i, data + i - 2)); } for (i = 1; i < 1023; i += 1) { g_assert (g_relation_exists (relation, data + i, data + i + 1)); g_assert (g_relation_exists (relation, data + i, data + i - 1)); } for (i = 2; i < 1022; i += 1) { g_assert (g_relation_count (relation, data + i, 0) == 2); g_assert (g_relation_count (relation, data + i, 1) == 2); } g_assert (g_relation_count (relation, data, 0) == 0); g_assert (g_relation_count (relation, data + 42, 0) == 2); g_assert (g_relation_count (relation, data + 43, 1) == 2); g_assert (g_relation_count (relation, data + 41, 1) == 2); g_relation_delete (relation, data + 42, 0); g_assert (g_relation_count (relation, data + 42, 0) == 0); g_assert (g_relation_count (relation, data + 43, 1) == 1); g_assert (g_relation_count (relation, data + 41, 1) == 1); tuples = g_relation_select (relation, data + 200, 0); g_assert (tuples->len == 2); #if 0 for (i = 0; i < tuples->len; i += 1) { printf ("%d %d\n", *(gint*) g_tuples_index (tuples, i, 0), *(gint*) g_tuples_index (tuples, i, 1)); } #endif g_assert (g_relation_exists (relation, data + 300, data + 301)); g_relation_delete (relation, data + 300, 0); g_assert (!g_relation_exists (relation, data + 300, data + 301)); g_tuples_destroy (tuples); g_relation_destroy (relation); relation = NULL; g_print ("ok\n"); g_print ("checking pointer arrays..."); gparray = g_ptr_array_new (); for (i = 0; i < 10000; i++) g_ptr_array_add (gparray, GINT_TO_POINTER (i)); for (i = 0; i < 10000; i++) if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i)) g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i)); g_ptr_array_free (gparray, TRUE); g_print ("ok\n"); g_print ("checking byte arrays..."); gbarray = g_byte_array_new (); for (i = 0; i < 10000; i++) g_byte_array_append (gbarray, (guint8*) "abcd", 4); for (i = 0; i < 10000; i++) { g_assert (gbarray->data[4*i] == 'a'); g_assert (gbarray->data[4*i+1] == 'b'); g_assert (gbarray->data[4*i+2] == 'c'); g_assert (gbarray->data[4*i+3] == 'd'); } g_byte_array_free (gbarray, TRUE); g_print ("ok\n"); g_printerr ("g_log tests:"); g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345); g_message ("the next warning is a test:"); string = NULL; g_print (string); g_print ("checking endian macros (host is "); #if G_BYTE_ORDER == G_BIG_ENDIAN g_print ("big endian)..."); #else g_print ("little endian)..."); #endif g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2); g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2); #ifdef G_HAVE_GINT64 g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2); #endif g_print ("ok\n"); return 0; }
/* WARNING: Function accesses globals find_diskqp, curlog, curlog, curstr, * dynamic_disklist */ gboolean search_logfile( find_result_t **output_find, const char *label, const char *passed_datestamp, const char *logfile, disklist_t * dynamic_disklist) { FILE *logf; char *host, *host_undo; char *disk = NULL, *qdisk, *disk_undo; char *date, *date_undo; int partnum; int totalparts; int maxparts = -1; char *number; int fileno; char *current_label; char *rest, *rest_undo; char *ck_label=NULL; int level = 0; off_t filenum; char *ck_datestamp=NULL; char *datestamp; char *s; int ch; disk_t *dp; GHashTable* valid_label; GHashTable* part_by_dle; find_result_t *part_find; find_result_t *a_part_find; gboolean right_label = FALSE; gboolean found_something = FALSE; double sec; off_t kb; off_t bytes; off_t orig_kb; int taper_part = 0; g_return_val_if_fail(output_find != NULL, 0); g_return_val_if_fail(logfile != NULL, 0); current_label = g_strdup(""); if (string_chunk == NULL) { string_chunk = g_string_chunk_new(32768); } valid_label = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); part_by_dle = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); datestamp = g_strdup(passed_datestamp); if((logf = fopen(logfile, "r")) == NULL) { error(_("could not open logfile %s: %s"), logfile, strerror(errno)); /*NOTREACHED*/ } filenum = (off_t)0; while(get_logline(logf)) { if (curlog == L_START && curprog == P_TAPER) { amfree(ck_label); ck_datestamp = NULL; if(parse_taper_datestamp_log(curstr, &ck_datestamp, &ck_label) == 0) { g_printf(_("strange log line in %s \"start taper %s\"\n"), logfile, curstr); continue; } if (datestamp != NULL) { if (!g_str_equal(datestamp, ck_datestamp)) { g_printf(_("Log file %s stamped %s, expecting %s!\n"), logfile, ck_datestamp, datestamp); amfree(ck_label); break; } } right_label = volume_matches(label, ck_label, ck_datestamp); if (right_label && ck_label) { g_hash_table_insert(valid_label, g_strdup(ck_label), GINT_TO_POINTER(1)); } if (label && datestamp && right_label) { found_something = TRUE; } amfree(current_label); current_label = ck_label; ck_label = NULL; if (datestamp == NULL) { datestamp = g_strdup(ck_datestamp); } filenum = (off_t)0; } if (!datestamp) continue; if (right_label && (curlog == L_SUCCESS || curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTPARTIAL) && curprog == P_TAPER) { filenum++; } else if (right_label && curlog == L_PARTIAL && curprog == P_TAPER && taper_part == 0) { filenum++; } partnum = -1; totalparts = -1; if (curlog == L_SUCCESS || curlog == L_CHUNKSUCCESS || curlog == L_DONE || curlog == L_FAIL || curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTIAL || curlog == L_PARTPARTIAL ) { s = curstr; ch = *s++; skip_whitespace(s, ch); if(ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); continue; } if (curlog == L_PART || curlog == L_PARTPARTIAL) { char *part_label; char *qpart_label = s - 1; taper_part++; skip_quoted_string(s, ch); s[-1] = '\0'; part_label = unquote_string(qpart_label); if (!g_hash_table_lookup(valid_label, part_label)) { amfree(part_label); continue; } amfree(current_label); current_label = part_label; skip_whitespace(s, ch); if(ch == '\0') { g_printf("strange log line in %s \"%s\"\n", logfile, curstr); continue; } number = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; fileno = atoi(number); filenum = fileno; if (filenum == 0) continue; skip_whitespace(s, ch); if(ch == '\0') { g_printf("strange log line in %s \"%s\"\n", logfile, curstr); continue; } } else { taper_part = 0; } host = s - 1; skip_non_whitespace(s, ch); host_undo = s - 1; *host_undo = '\0'; skip_whitespace(s, ch); if(ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); continue; } qdisk = s - 1; skip_quoted_string(s, ch); disk_undo = s - 1; *disk_undo = '\0'; disk = unquote_string(qdisk); skip_whitespace(s, ch); if(ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } date = s - 1; skip_non_whitespace(s, ch); date_undo = s - 1; *date_undo = '\0'; if(strlen(date) < 3) { /* old log didn't have datestamp */ level = atoi(date); date = datestamp; partnum = 1; totalparts = 1; } else { if (curprog == P_TAPER && (curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTPARTIAL || curlog == L_PARTIAL || curlog == L_DONE)) { char *s1, ch1; skip_whitespace(s, ch); number = s - 1; skip_non_whitespace(s, ch); s1 = &s[-1]; ch1 = *s1; skip_whitespace(s, ch); if (*(s-1) != '[') { *s1 = ch1; sscanf(number, "%d/%d", &partnum, &totalparts); if (partnum > maxparts) maxparts = partnum; if (totalparts > maxparts) maxparts = totalparts; } else { /* nparts is not in all PARTIAL lines */ partnum = 1; totalparts = 1; s = number + 1; } } else { skip_whitespace(s, ch); } if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { g_printf(_("Fstrange log line in %s \"%s\"\n"), logfile, s-1); amfree(disk); continue; } skip_integer(s, ch); } skip_whitespace(s, ch); if(ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } rest = s - 1; skip_non_whitespace(s, ch); rest_undo = s - 1; *rest_undo = '\0'; if (g_str_equal(rest, "[sec")) { skip_whitespace(s, ch); if(ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } sec = atof(s - 1); skip_non_whitespace(s, ch); skip_whitespace(s, ch); rest = s - 1; skip_non_whitespace(s, ch); rest_undo = s - 1; *rest_undo = '\0'; if (!g_str_equal(rest, "kb") && !g_str_equal(rest, "bytes")) { g_printf(_("Bstrange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } skip_whitespace(s, ch); if (ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } if (g_str_equal(rest, "kb")) { kb = atof(s - 1); bytes = 0; } else { bytes = atof(s - 1); kb = bytes / 1024; } skip_non_whitespace(s, ch); skip_whitespace(s, ch); rest = s - 1; skip_non_whitespace(s, ch); rest_undo = s - 1; *rest_undo = '\0'; if (!g_str_equal(rest, "kps")) { g_printf(_("Cstrange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } skip_whitespace(s, ch); if (ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } /* kps = atof(s - 1); */ skip_non_whitespace(s, ch); skip_whitespace(s, ch); rest = s - 1; skip_non_whitespace(s, ch); rest_undo = s - 1; *rest_undo = '\0'; if (!g_str_equal(rest, "orig-kb")) { orig_kb = 0; } else { skip_whitespace(s, ch); if(ch == '\0') { g_printf(_("strange log line in %s \"%s\"\n"), logfile, curstr); amfree(disk); continue; } orig_kb = atof(s - 1); } } else { sec = 0; kb = 0; bytes = 0; orig_kb = 0; *rest_undo = ' '; } if (g_str_has_prefix(rest, "error")) rest += 6; if (g_str_has_prefix(rest, "config")) rest += 7; dp = lookup_disk(host,disk); if ( dp == NULL ) { if (dynamic_disklist == NULL) { amfree(disk); continue; } dp = add_disk(dynamic_disklist, host, disk); enqueue_disk(dynamic_disklist, dp); } if (find_match(host, disk)) { if(curprog == P_TAPER) { char *key = g_strdup_printf( "HOST:%s DISK:%s: DATE:%s LEVEL:%d", host, disk, date, level); find_result_t *new_output_find = g_new0(find_result_t, 1); part_find = g_hash_table_lookup(part_by_dle, key); maxparts = partnum; if (maxparts < totalparts) maxparts = totalparts; for (a_part_find = part_find; a_part_find; a_part_find = a_part_find->next) { if (maxparts < a_part_find->partnum) maxparts = a_part_find->partnum; if (maxparts < a_part_find->totalparts) maxparts = a_part_find->totalparts; } new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, date); new_output_find->write_timestamp = g_string_chunk_insert_const(string_chunk, datestamp); new_output_find->hostname=g_string_chunk_insert_const(string_chunk, host); new_output_find->diskname=g_string_chunk_insert_const(string_chunk, disk); new_output_find->level=level; new_output_find->partnum = partnum; new_output_find->totalparts = totalparts; new_output_find->label=g_string_chunk_insert_const(string_chunk, current_label); new_output_find->status=NULL; new_output_find->dump_status=NULL; new_output_find->message=""; new_output_find->filenum=filenum; new_output_find->sec=sec; new_output_find->kb=kb; new_output_find->bytes=bytes; new_output_find->orig_kb=orig_kb; new_output_find->next=NULL; if (curlog == L_SUCCESS) { new_output_find->status = "OK"; new_output_find->dump_status = "OK"; new_output_find->next = *output_find; new_output_find->partnum = 1; /* L_SUCCESS is pre-splitting */ *output_find = new_output_find; found_something = TRUE; } else if (curlog == L_CHUNKSUCCESS || curlog == L_DONE || curlog == L_PARTIAL || curlog == L_FAIL) { /* result line */ if (curlog == L_PARTIAL || curlog == L_FAIL) { /* set dump_status of each part */ for (a_part_find = part_find; a_part_find; a_part_find = a_part_find->next) { if (curlog == L_PARTIAL) a_part_find->dump_status = "PARTIAL"; else { a_part_find->dump_status = "FAIL"; a_part_find->message = g_string_chunk_insert_const(string_chunk, rest); } } } else { if (maxparts > -1) { /* format with part */ /* must check if all part are there */ int num_part = maxparts; for (a_part_find = part_find; a_part_find; a_part_find = a_part_find->next) { if (a_part_find->partnum == num_part && g_str_equal(a_part_find->status, "OK")) num_part--; } /* set dump_status of each part */ for (a_part_find = part_find; a_part_find; a_part_find = a_part_find->next) { if (num_part == 0) { a_part_find->dump_status = "OK"; } else { a_part_find->dump_status = "FAIL"; a_part_find->message = g_string_chunk_insert_const(string_chunk, "Missing part"); } } } } if (curlog == L_DONE) { for (a_part_find = part_find; a_part_find; a_part_find = a_part_find->next) { if (a_part_find->totalparts == -1) { a_part_find->totalparts = maxparts; } if (a_part_find->orig_kb == 0) { a_part_find->orig_kb = orig_kb; } } } if (part_find) { /* find last element */ for (a_part_find = part_find; a_part_find->next != NULL; a_part_find=a_part_find->next) { } /* merge part_find to *output_find */ a_part_find->next = *output_find; *output_find = part_find; part_find = NULL; maxparts = -1; found_something = TRUE; g_hash_table_remove(part_by_dle, key); } free_find_result(&new_output_find); } else { /* part line */ if (curlog == L_PART || curlog == L_CHUNK) { new_output_find->status = "OK"; new_output_find->dump_status = "OK"; } else { /* PARTPARTIAL */ new_output_find->status = "PARTIAL"; new_output_find->dump_status = "PARTIAL"; } /* Add to part_find list */ if (part_find) { new_output_find->next = part_find; part_find = new_output_find; } else { new_output_find->next = NULL; part_find = new_output_find; } g_hash_table_insert(part_by_dle, g_strdup(key), part_find); found_something = TRUE; } amfree(key); } else if(curlog == L_FAIL) { char *status_failed; /* print other failures too -- this is a hack to ensure that failures which * did not make it to tape are also listed in the output of 'amadmin x find'; * users that do not want this information (e.g., Amanda::DB::Catalog) should * filter dumps with a NULL label. */ find_result_t *new_output_find = g_new0(find_result_t, 1); new_output_find->next = *output_find; new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, date); new_output_find->write_timestamp = g_strdup("00000000000000"); /* dump was not written.. */ new_output_find->hostname=g_string_chunk_insert_const(string_chunk, host); new_output_find->diskname=g_string_chunk_insert_const(string_chunk, disk); new_output_find->level=level; new_output_find->label=NULL; new_output_find->partnum=partnum; new_output_find->totalparts=totalparts; new_output_find->filenum=0; new_output_find->sec=sec; new_output_find->kb=kb; new_output_find->bytes=bytes; new_output_find->orig_kb=orig_kb; status_failed = g_strjoin(NULL, "FAILED (", program_str[(int)curprog], ") ", rest, NULL); new_output_find->status = g_string_chunk_insert_const(string_chunk, status_failed); amfree(status_failed); new_output_find->dump_status=""; new_output_find->message=""; *output_find=new_output_find; found_something = TRUE; maxparts = -1; } } amfree(disk); } } g_hash_table_destroy(valid_label); afclose(logf); amfree(datestamp); amfree(current_label); amfree(disk); return found_something; }
void search_holding_disk( find_result_t **output_find, disklist_t * dynamic_disklist) { GSList *holding_file_list; GSList *e; char *holding_file; disk_t *dp; char *orig_name; holding_file_list = holding_get_files(NULL, 1); if (string_chunk == NULL) { string_chunk = g_string_chunk_new(32768); } for(e = holding_file_list; e != NULL; e = e->next) { dumpfile_t file; holding_file = (char *)e->data; if (!holding_file_get_dumpfile(holding_file, &file)) continue; if (file.dumplevel < 0 || file.dumplevel >= DUMP_LEVELS) { dumpfile_free_data(&file); continue; } dp = NULL; orig_name = g_strdup(file.name); for(;;) { char *s; if((dp = lookup_disk(file.name, file.disk))) break; if((s = strrchr(file.name,'.')) == NULL) break; *s = '\0'; } strcpy(file.name, orig_name); /* restore munged string */ g_free(orig_name); if ( dp == NULL ) { if (dynamic_disklist == NULL) { dumpfile_free_data(&file); continue; } dp = add_disk(dynamic_disklist, file.name, file.disk); enqueue_disk(dynamic_disklist, dp); } if(find_match(file.name,file.disk)) { find_result_t *new_output_find = g_new0(find_result_t, 1); new_output_find->next=*output_find; new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, file.datestamp); new_output_find->write_timestamp = g_string_chunk_insert_const(string_chunk, "00000000000000"); new_output_find->hostname = g_string_chunk_insert_const(string_chunk, file.name); new_output_find->diskname = g_string_chunk_insert_const(string_chunk, file.disk); new_output_find->level=file.dumplevel; new_output_find->label=g_string_chunk_insert_const(string_chunk, holding_file); new_output_find->partnum = -1; new_output_find->totalparts = -1; new_output_find->filenum=0; if (file.is_partial) { new_output_find->status="PARTIAL"; new_output_find->dump_status="PARTIAL"; } else { new_output_find->status="OK"; new_output_find->dump_status="OK"; } new_output_find->message=""; new_output_find->kb = holding_file_size(holding_file, 1); new_output_find->bytes = 0; new_output_find->orig_kb = file.orig_size; *output_find=new_output_find; } dumpfile_free_data(&file); } slist_free_full(holding_file_list, g_free); }
g_string_chunk_free(etd->text); etd->text = g_string_chunk_new(100); g_array_set_size(etd->ei_array, 0); expert_dlg_display_reset(etd); } int expert_dlg_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pointer) { expert_info_t *ei; expert_tapdata_t *etd = tapdata; g_array_append_val(etd->ei_array, *(expert_info_t *)pointer); etd->last = etd->ei_array->len; ei = &g_array_index(etd->ei_array, expert_info_t, etd->last -1); /* ugly */ ei->protocol = g_string_chunk_insert_const(etd->text, ei->protocol); ei->summary = g_string_chunk_insert_const(etd->text, ei->summary); switch(ei->severity) { case(PI_CHAT): etd->chat_events++; break; case(PI_NOTE): etd->note_events++; break; case(PI_WARN): etd->warn_events++; break; case(PI_ERROR): etd->error_events++; break;