📄 table_string_list.c
字号:
/* Copyright (C) 2004,2005,2006 Bull S.A. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#if HAVE_CONFIG_H#include <config.h>#endif#include <stdlib.h>#include <string.h>#include "modules.h"#include "glib_hash.h"static GHashTable *hash_table[NB_OBJ] = { [0 ... (NB_OBJ-1)] = NULL };static int table_nb[NB_OBJ] = { [0 ... (NB_OBJ-1)] = 0 };static int ok = 1;static int init (int nb_elem) { int ind; for (ind = 0; ind < NB_OBJ; ind++) hash_table[ind] = g_hash_table_new (g_str_hash, g_str_equal); return 0;}static int insert (int index, char *name) { gpointer new_key; if (g_hash_table_lookup (hash_table[index], (gpointer)name) == NULL) { new_key = (gpointer)strdup(name); if (new_key == NULL) { fprintf(stderr, "Error with strdup\n"); return -1; } g_hash_table_insert (hash_table[index], new_key, (gpointer)(&ok)); table_nb[index]++; } return 0;}static void display_pair (gpointer key, gpointer value, gpointer user_data) { printf (" %s", (char *)key);}static void display (int index) { printf (" %d : (", table_nb[index]); g_hash_table_foreach (hash_table[index], display_pair, (gpointer)NULL); printf (" )\n");}static void free_key (gpointer key, gpointer value, gpointer user_data) { free (key);}static void close () { int ind; for (ind = 0; ind < NB_OBJ; ind++) { g_hash_table_foreach (hash_table[ind], free_key, (gpointer)NULL); g_hash_table_destroy (hash_table[ind]); }}struct table_string_list table_string_list = { .init = init, .insert = insert, .display = display, .close = close};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -