Commit 88a02a16 authored by Ziirish's avatar Ziirish
Browse files

splitting source code relative to strings utilities and datatables into specific source files

parent 9c532254
......@@ -63,10 +63,6 @@ cid_SOURCES = \
cid-asynchrone.h \
cid-callbacks.c \
cid-callbacks.h \
cid-file-utilities.c \
cid-file-utilities.h \
cid-gui-factory.c \
cid-gui-factory.h \
cid-config.c \
cid-config.h \
cid-console-call.c \
......@@ -74,12 +70,20 @@ cid_SOURCES = \
cid-constantes.h \
cid-cover.c \
cid-cover.h \
cid-datatables.c \
cid-datatables.h \
cid-dbus.c \
cid-dbus.h \
cid-draw.c \
cid-draw.h \
cid-exaile.c \
cid-exaile.h \
cid-file-utilities.c \
cid-file-utilities.h \
cid-gui-callback.c \
cid-gui-callback.h \
cid-gui-factory.c \
cid-gui-factory.h \
cid-md5.c \
cid-md5.h \
cid-menu-factory.c \
......@@ -89,10 +93,10 @@ cid_SOURCES = \
cid-modules.c \
cid-modules.h \
cid-mpd.c \
cid-gui-callback.c \
cid-gui-callback.h \
cid-rhythmbox.c \
cid-rhythmbox.h \
cid-string-utilities.c \
cid-string-utilities.h \
cid-utilities.c \
cid-utilities.h \
cid-X-utilities.c \
......@@ -125,20 +129,22 @@ cidsubinclude_HEADERS = \
cid-applet-canvas.h \
cid-asynchrone.h \
cid-callbacks.h \
cid-gui-factory.h \
cid-config.h \
cid-console-call.h \
cid-constantes.h \
cid-datatables.h \
cid-dbus.h \
cid-draw.h \
cid-exaile.h \
cid-gui-callback.h \
cid-gui-factory.h \
cid-md5.h \
cid-menu-factory.h \
cid-messages.h \
cid-modules.h \
cid-mpd.h \
cid-gui-callback.h \
cid-rhythmbox.h \
cid-string-utilities.h \
cid-struct.h \
cid-utilities.h \
cid-X-utilities.h \
......
......@@ -21,130 +21,12 @@
static gint iNbRead = 0;
static gboolean bChangedDesktop;
static gboolean bUnvalidKey;
//static gboolean bUnvalidKey;
static gboolean bReloaded = FALSE;
static PlayerIndice iPlayerChanged;
static SymbolColor iSymbolChanged;
static gint iOldWidth, iOldHeight;
void
cid_check_file (const gchar *f)
{
gchar *cFileTest;
if (!g_file_test (f, G_FILE_TEST_EXISTS))
{
/*
gchar *cCompareWith = g_strdup_printf("%s/.config/cid/%s",g_getenv("HOME"),CID_CONFIG_FILE);
if (g_strcmp(f,cCompareWith)) // f correspond a un chemin entre par l'utilisateur
{
g_free (cCompareWith);
gchar *cSrc = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_debug ("Copying file from %s to %s",cSrc,f);
cid_file_copy (cSrc,f);
g_free (cSrc);
return;
}
*/
/*
CidDataTable *p_folders = cid_create_datatable(G_TYPE_STRING,"%s/.config","%s/.config/cid",G_TYPE_INVALID);
BEGIN_FOREACH_DT(p_folders)
gchar *cDirName = g_strdup_printf(p_temp->content->string,g_getenv("HOME"));
if (!g_file_test (cDirName,G_FILE_TEST_IS_DIR))
{
cid_debug ("Creating directory: %s",cDirName);
mkdir(cDirName,S_IRWXU);
}
g_free (cDirName);
END_FOREACH_DT
*/
gchar *cDirectory = g_path_get_dirname (f);
if (! g_file_test (cDirectory, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE))
{
cid_info ("Creating path '%s'", cDirectory);
g_mkdir_with_parents (cDirectory, 7*8*8+7*8+5);
}
g_free (cDirectory);
cFileTest = g_strdup_printf("%s/%s",g_getenv("HOME"),OLD_CONFIG_FILE) ;
if (g_file_test (cFileTest, G_FILE_TEST_EXISTS))
{
gchar *cSrc = g_strdup_printf("%s/%s",g_getenv("HOME"),OLD_CONFIG_FILE);
gchar *cDst = g_strdup_printf("%s/.config/cid/%s",g_getenv("HOME"),CID_CONFIG_FILE);
cid_debug ("Moving file from %s to %s",cSrc,cDst);
rename(cSrc,cDst);
g_free (cSrc);
g_free (cDst);
g_free (cFileTest);
return;
}
g_free (cFileTest);
cFileTest = g_strdup_printf("%s/.config/%s",g_getenv("HOME"),OLD_CONFIG_FILE);
if (g_file_test (cFileTest, G_FILE_TEST_EXISTS))
{
gchar *cSrc = g_strdup_printf("%s/.config/%s",g_getenv("HOME"),OLD_CONFIG_FILE);
gchar *cDst = g_strdup_printf("%s/.config/cid/%s",g_getenv("HOME"),CID_CONFIG_FILE);
cid_debug ("Moving file from %s to %s",cSrc,cDst);
rename(cSrc,cDst);
g_free (cSrc);
g_free (cDst);
g_free (cFileTest);
return;
}
g_free (cFileTest);
cFileTest = g_strdup_printf("%s/.config/%s",g_getenv("HOME"),CID_CONFIG_FILE);
if (g_file_test (cFileTest, G_FILE_TEST_EXISTS))
{
gchar *cSrc = g_strdup_printf("%s/.config/%s",g_getenv("HOME"),CID_CONFIG_FILE);
gchar *cDst = g_strdup_printf("%s/.config/cid/%s",g_getenv("HOME"),CID_CONFIG_FILE);
cid_debug ("Moving file from %s to %s",cSrc,cDst);
rename(cSrc,cDst);
g_free (cSrc);
g_free (cDst);
g_free (cFileTest);
return;
}
g_free (cFileTest);
gchar *cSrc = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_debug ("Copying file from %s to %s",cSrc,f);
cid_file_copy (cSrc,f);
g_free (cSrc);
}
}
gboolean
cid_check_conf_file_version (CidMainContainer **pCid, const gchar *f)
{
gchar *cCommand=NULL;
gchar line_f1[80], line_f2[80];
FILE *f1, *f2;
gchar *cOrigFile = g_strdup_printf("%s/%s",CID_DATA_DIR, CID_CONFIG_FILE);
f1 = fopen ((const char *)cOrigFile,"r");
f2 = fopen ((const char *)f,"r");
g_free (cOrigFile);
if (!fgets(line_f1,80,f1) || !fgets(line_f2,80,f2))
cid_exit (pCid, 3,"couldn't read conf file, try to delete it");
fclose (f1);
fclose (f2);
cid_info ("line_f1 %s\nline_f2 %s",line_f1,line_f2);
if (strcmp(line_f1,line_f2)!=0 || bUnvalidKey)
{
cid_warning ("bad file version, building a new one\n");
cid_file_remove (f);
gchar *cTmpPath = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_file_copy(cTmpPath,f);
g_free (cTmpPath);
cid_save_data (pCid);
cid_read_key_file (pCid, f);
return FALSE;
}
return TRUE;
}
void
cid_read_config_after_update (CidMainContainer **pCid, const char *f)
{
......@@ -180,7 +62,7 @@ cid_read_config_after_update (CidMainContainer **pCid, const char *f)
if (iSymbolChanged != cid->config->iSymbolColor || iPlayerChanged != cid->config->iPlayer)
cid_load_symbols();
cid_check_position();
cid_check_position(pCid);
gtk_window_move (GTK_WINDOW(cid->pWindow), cid->config->iPosX, cid->config->iPosY);
gtk_window_resize (GTK_WINDOW (cid->pWindow), cid->config->iWidth, cid->config->iHeight);
......@@ -233,13 +115,13 @@ cid_key_file_free(CidMainContainer **pCid)
}
gboolean
cid_get_boolean_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault)
cid_get_boolean_value_full (CidMainContainer **pCid, GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault)
{
GError *error = NULL;
gboolean bGet = g_key_file_get_boolean (pKeyFile, cGroup, cKey, &error);
if (error != NULL)
{
bUnvalidKey = TRUE;
(*pCid)->config->bUnvalidKey = TRUE;
cid_warning("key '%s' in group '%s'\n=> %s",cKey,cGroup,error->message);
g_error_free(error);
error = NULL;
......@@ -250,13 +132,13 @@ cid_get_boolean_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboo
}
gchar *
cid_get_string_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gchar *cDefault, gboolean bFile, gboolean bDir, gboolean bForce)
cid_get_string_value_full (CidMainContainer **pCid, GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gchar *cDefault, gboolean bFile, gboolean bDir, gboolean bForce)
{
GError *error = NULL;
gchar *cGet = g_key_file_get_string (pKeyFile, cGroup, cKey, &error);
if (error != NULL && bDefault)
{
bUnvalidKey = TRUE;
(*pCid)->config->bUnvalidKey = TRUE;
cid_warning("key '%s' in group '%s'\n=> %s",cKey,cGroup,error->message);
g_error_free(error);
error = NULL;
......@@ -282,13 +164,13 @@ cid_get_string_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gbool
}
gint
cid_get_int_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gint iDefault, gboolean bMax, gint iMax)
cid_get_int_value_full (CidMainContainer **pCid, GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gint iDefault, gboolean bMax, gint iMax)
{
GError *error = NULL;
gint iGet = g_key_file_get_integer (pKeyFile, cGroup, cKey, &error);
if (error != NULL && bDefault)
{
bUnvalidKey = TRUE;
(*pCid)->config->bUnvalidKey = TRUE;
cid_warning("key '%s' in group '%s'\n=> %s",cKey,cGroup,error->message);
g_error_free(error);
error = NULL;
......@@ -300,12 +182,12 @@ cid_get_int_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean
return iGet;
}
gboolean
cid_free_and_debug_error (GError **error)
static gboolean
cid_free_and_debug_error (CidMainContainer **pCid, GError **error)
{
if (*error != NULL)
{
bUnvalidKey = TRUE;
(*pCid)->config->bUnvalidKey = TRUE;
cid_warning("\n=> %s",(*error)->message);
g_error_free(*error);
*error = NULL;
......@@ -331,7 +213,7 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
gsize iReadSize;
GError *error = NULL;
bUnvalidKey = FALSE;
cid->config->bUnvalidKey = FALSE;
// [System] configuration
cid->config->iPlayer = CID_CONFIG_GET_INTEGER ("System", "PLAYER");
......@@ -342,13 +224,13 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
cid->config->iSymbolColor = CID_CONFIG_GET_INTEGER ("System", "SYMBOL_COLOR");
cid->config->bDisplayControl = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("System", "CONTROLS", TRUE);
cid->config->dPoliceSize = g_key_file_get_double (cid->pKeyFile, "System", "POLICE_SIZE", &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->config->dPoliceColor = g_key_file_get_double_list (cid->pKeyFile, "System", "POLICE_COLOR", &cid->config->iPlainTextSize, &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->config->dOutlineTextColor = g_key_file_get_double_list (cid->pKeyFile, "System", "OUTLINE_COLOR", &cid->config->iOutlineTextSize, &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->config->t_cCoverPatternList = g_key_file_get_string_list (cid->pKeyFile, "System", "FILES_LIST", &cid->config->iNbPatterns, &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->runtime->pCoversList = cid_char_table_to_datatable (cid->config->t_cCoverPatternList, cid->config->iNbPatterns);
// [Options] configuration
......@@ -372,7 +254,7 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
cid->config->iPosX = CID_CONFIG_GET_INTEGER ("Behaviour", "GAP_X");
cid->config->iPosY = CID_CONFIG_GET_INTEGER ("Behaviour", "GAP_Y");
pSize = g_key_file_get_integer_list (cid->pKeyFile, "Behaviour", "SIZE", &iReadSize, &error);
if (cid_free_and_debug_error(&error) || iReadSize != 2)
if (cid_free_and_debug_error(pCid, &error) || iReadSize != 2)
{
pSize = g_realloc (pSize, 2 * sizeof(int));
if (pSize != NULL)
......@@ -386,11 +268,11 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
}
}
cid->config->dRotate = g_key_file_get_double (cid->pKeyFile, "Behaviour", "ROTATION", &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->config->dColor = g_key_file_get_double_list (cid->pKeyFile, "Behaviour", "COLOR", &cid->config->iColorSize, &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->config->dFlyingColor = g_key_file_get_double_list (cid->pKeyFile, "Behaviour", "FLYING_COLOR", &cid->config->iFlyiniColorSize, &error);
cid_free_and_debug_error(&error);
cid_free_and_debug_error(pCid, &error);
cid->config->bKeepCorners = CID_CONFIG_GET_BOOLEAN ("Behaviour", "KEEP_CORNERS");
cid->config->bAllDesktop = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Behaviour", "ALL_DESKTOP", TRUE);
cid->config->bLockPosition = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Behaviour", "LOCK", TRUE);
......@@ -415,7 +297,7 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
cid->config->iWidth = pSize[0] <= MAX_SIZE ? pSize[0] : MAX_SIZE;
cid->config->iHeight = pSize[1] <= MAX_SIZE ? pSize[1] : MAX_SIZE;
if (!bUnvalidKey)
if (!cid->config->bUnvalidKey)
{
cid->config->dRed = cid->config->dColor[0];
cid->config->dGreen = cid->config->dColor[1];
......@@ -429,7 +311,7 @@ cid_read_key_file (CidMainContainer **pCid, const gchar *f)
cid_key_file_free(pCid);
if (bUnvalidKey && !bReloaded)
if (cid->config->bUnvalidKey && !bReloaded)
{
cid_save_data (pCid);
cid_read_key_file (pCid, f);
......@@ -445,12 +327,18 @@ cid_read_config (CidMainContainer **pCid, const char *f)
cid_info ("Reading file : %s",f);
if (!cid->config->bDevMode)
cid_check_file (f);
{
if (!cid_file_check (f))
cid_exit (pCid, CID_ERROR_READING_FILE, "Unable to find configuration file");
}
cid_read_key_file (pCid, f);
if (!cid->config->bDevMode)
cid_check_conf_file_version (pCid, f);
{
if (!cid_file_check_config_version (pCid, f))
cid_exit (pCid, CID_ERROR_READING_FILE, "Unable to replace configuration file");
}
iNbRead++;
......
......@@ -15,18 +15,20 @@ G_BEGIN_DECLS
/**
* Fonction permettant de recuperer un boolean dans un fichier de configuration.
* @param pCid Structure de configuration.
* @param pKeyFile Fichier de configuration.
* @param cGroup Groupe auquel appartient la cle recherchee.
* @param cKey Cle recherchee.
* @param bDefault Valeur par defaut.
* @return Le booleen correspondant aux criteres.
*/
gboolean cid_get_boolean_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault);
#define CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT(cGroup,cKey,bDefault) cid_get_boolean_value_full (cid->pKeyFile,cGroup,cKey,bDefault)
#define CID_CONFIG_GET_BOOLEAN(cGroup,cKey) cid_get_boolean_value_full (cid->pKeyFile,cGroup,cKey,FALSE)
gboolean cid_get_boolean_value_full (CidMainContainer **pCid, GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault);
#define CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT(cGroup,cKey,bDefault) cid_get_boolean_value_full (pCid,cid->pKeyFile,cGroup,cKey,bDefault)
#define CID_CONFIG_GET_BOOLEAN(cGroup,cKey) cid_get_boolean_value_full (pCid,cid->pKeyFile,cGroup,cKey,FALSE)
/**
* Fonction permettant de recuperer une chaine dans un fichier de configuration.
* @param pCid Structure de configuration.
* @param pKeyFile Fichier de configuration.
* @param cGroup Groupe auquel appartient la cle recherchee.
* @param cKey Cle recherchee.
......@@ -36,15 +38,16 @@ gboolean cid_get_boolean_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *c
* @param bDir Si on veut tester l'existance d'un dossier.
* @return La chaine correspondante aux criteres.
*/
gchar *cid_get_string_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gchar *cDefault, gboolean bFile, gboolean bDir, gboolean bForce);
#define CID_CONFIG_GET_STRING(cGroup,cKey) cid_get_string_value_full (cid->pKeyFile,cGroup,cKey,FALSE,NULL,FALSE,FALSE,FALSE)
#define CID_CONFIG_GET_STRING_WITH_DEFAULT(cGroup,cKey,cDefault) cid_get_string_value_full (cid->pKeyFile,cGroup,cKey,FALSE,cDefault,FALSE,FALSE,FALSE)
#define CID_CONFIG_GET_FILE_PATH(cGroup,cKey,cDefault) cid_get_string_value_full (cid->pKeyFile,cGroup,cKey,TRUE,cDefault,TRUE,FALSE,FALSE)
#define CID_CONFIG_GET_DIR_PATH(cGroup,cKey,cDefault) cid_get_string_value_full (cid->pKeyFile,cGroup,cKey,FALSE,cDefault,FALSE,TRUE,FALSE)
#define CID_CONFIG_GET_DIR_PATH_FORCE(cGroup,cKey,cDefault) cid_get_string_value_full (cid->pKeyFile,cGroup,cKey,FALSE,cDefault,FALSE,TRUE,TRUE)
gchar *cid_get_string_value_full (CidMainContainer **pCid, GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gchar *cDefault, gboolean bFile, gboolean bDir, gboolean bForce);
#define CID_CONFIG_GET_STRING(cGroup,cKey) cid_get_string_value_full (pCid,cid->pKeyFile,cGroup,cKey,FALSE,NULL,FALSE,FALSE,FALSE)
#define CID_CONFIG_GET_STRING_WITH_DEFAULT(cGroup,cKey,cDefault) cid_get_string_value_full (pCid,cid->pKeyFile,cGroup,cKey,FALSE,cDefault,FALSE,FALSE,FALSE)
#define CID_CONFIG_GET_FILE_PATH(cGroup,cKey,cDefault) cid_get_string_value_full (pCid,cid->pKeyFile,cGroup,cKey,TRUE,cDefault,TRUE,FALSE,FALSE)
#define CID_CONFIG_GET_DIR_PATH(cGroup,cKey,cDefault) cid_get_string_value_full (pCid,cid->pKeyFile,cGroup,cKey,FALSE,cDefault,FALSE,TRUE,FALSE)
#define CID_CONFIG_GET_DIR_PATH_FORCE(cGroup,cKey,cDefault) cid_get_string_value_full (pCid,cid->pKeyFile,cGroup,cKey,FALSE,cDefault,FALSE,TRUE,TRUE)
/**
* Fonction permettant de recuperer un int dans un fichier de configuration.
* @param pCid Structure de configuration.
* @param pKeyFile Fichier de configuration.
* @param cGroup Groupe auquel appartient la cle recherchee.
* @param cKey Cle recherchee.
......@@ -54,10 +57,10 @@ gchar *cid_get_string_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey
* @param iMax Valeur maximale.
* @return L'entier correspondant aux criteres.
*/
gint cid_get_int_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gint iDefault, gboolean bMax, gint iMax);
#define CID_CONFIG_GET_INTEGER(cGroup,cKey) cid_get_int_value_full (cid->pKeyFile,cGroup,cKey,FALSE,0,FALSE,0)
#define CID_CONFIG_GET_INTEGER_WITH_DEFAULT(cGroup,cKey,iDefault) cid_get_int_value_full (cid->pKeyFile,cGroup,cKey,TRUE,iDefault,FALSE,0)
#define CID_CONFIG_GET_INTEGER_WITH_DEFAULT_AND_MAX(cGroup,cKey,iDefault,iMax) cid_get_int_value_full (cid->pKeyFile,cGroup,cKey,TRUE,iDefault,TRUE,iMax)
gint cid_get_int_value_full (CidMainContainer **pCid, GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gint iDefault, gboolean bMax, gint iMax);
#define CID_CONFIG_GET_INTEGER(cGroup,cKey) cid_get_int_value_full (pCid,cid->pKeyFile,cGroup,cKey,FALSE,0,FALSE,0)
#define CID_CONFIG_GET_INTEGER_WITH_DEFAULT(cGroup,cKey,iDefault) cid_get_int_value_full (pCid,cid->pKeyFile,cGroup,cKey,TRUE,iDefault,FALSE,0)
#define CID_CONFIG_GET_INTEGER_WITH_DEFAULT_AND_MAX(cGroup,cKey,iDefault,iMax) cid_get_int_value_full (pCid,cid->pKeyFile,cGroup,cKey,TRUE,iDefault,TRUE,iMax)
/**
* Fonction qui charge la configuration .
......@@ -65,12 +68,6 @@ gint cid_get_int_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gbo
*/
int cid_read_config (CidMainContainer **pCid, const char *f);
/**
* vérifie que le fichier de configuration existe.
* @param f fichier de configuration à lire.
*/
void cid_check_file (const char *f);
/**
* sauvegarde les données de cid
*/
......@@ -83,12 +80,6 @@ void cid_save_data (CidMainContainer **pCid);
*/
void cid_write_keys_to_file (GKeyFile *pKeyFile, const gchar *cConfFilePath);
/**
* vérifie la version du fichier de configuration.
* @param f path du fichier à vérifier.
*/
gboolean cid_check_conf_file_version (CidMainContainer **pCid, const gchar *f);
/**
* Permet de recharger la configuration lorsqu'on applique des changement via le GUI.
*/
......
/*
*
* cid-datatables.c
* -------
* Conky Images Display
* --------------------------
*
*/
#include "cid-datatables.h"
CidDataTable *
cid_datatable_new (void)
{
CidDataTable *res = g_new0(CidDataTable,1);
if (res != NULL)
{
res->length = 0;
res->head = NULL;
res->tail = NULL;
}
return res;
}
CidDataCase *
cid_datacase_new (void)
{
CidDataCase *ret = g_new0(CidDataCase,1);
if (ret != NULL)
{
ret->content = NULL;
ret->next = NULL;
ret->prev = NULL;
}
return ret;
}
CidDataContent *
cid_datacontent_new (GType iType, gpointer value)
{
CidDataContent *ret = g_new0(CidDataContent,1);
if (ret != NULL)
{
ret->type = iType;
switch (iType)
{
case G_TYPE_STRING:
ret->string = NULL;
int iLength = (strlen((gchar *) value)+1)*sizeof(gchar);
ret->string = g_malloc0(iLength);
strncpy(ret->string, (gchar *) value, iLength);
break;
case G_TYPE_INT:
ret->iNumber = (gint)(long) value;
break;
case G_TYPE_BOOLEAN:
ret->booleen = (gboolean)(long) value;
break;
case CID_TYPE_SUBSTITUTE:
ret->sub = (CidSubstitute *) value;
break;
default:
g_free(ret);
return NULL;
}
}
return ret;
}
gboolean
cid_datacontent_equals (CidDataContent *d1, CidDataContent *d2)
{
if (d1 == NULL || d2 == NULL)
return FALSE;
if (d1->type != d2->type)
return FALSE;
switch (d1->type)
{
case G_TYPE_STRING:
return g_strcmp0(d1->string,d2->string) == 0;
case G_TYPE_INT:
return d1->iNumber == d2->iNumber;
case G_TYPE_BOOLEAN:
return d1->booleen == d2->booleen;
case CID_TYPE_SUBSTITUTE:
return g_strcmp0(d1->sub->regex,d2->sub->regex) == 0
&& g_strcmp0(d1->sub->replacement,d2->sub->replacement) == 0;
}
}
void
cid_datatable_append(CidDataTable **p_list, CidDataContent *data)
{
if (*p_list != NULL)
{
CidDataCase *p_new = cid_datacase_new();
if (p_new != NULL)
{
p_new->content = data;
p_new->next = NULL;
if ((*p_list)->tail == NULL)
{
p_new->prev = NULL;
(*p_list)->head = p_new;
(*p_list)->tail = p_new;
}
else
{
(*p_list)->tail->next = p_new;
p_new->prev = (*p_list)->tail;
(*p_list)->tail = p_new;
}
(*p_list)->length++;
}
}
}
void
cid_datatable_prepend(CidDataTable **p_list, CidDataContent *data)
{
if (*p_list != NULL)
{
CidDataCase *p_new = cid_datacase_new();
if (p_new != NULL)
{
p_new->content = data;
p_new->prev = NULL;
if ((*p_list)->tail == NULL)
{
p_new->next = NULL;
(*p_list)->head = p_new;
(*p_list)->tail = p_new;
}
else
{
(*p_list)->head->prev = p_new;
p_new->next = (*p_list)->head;
(*p_list)->head = p_new;
}
(*p_list)->length++;
}
}
}
void
cid_datatable_insert(CidDataTable **p_list, CidDataContent *data, gint position)
{
if (*p_list != NULL)
{
if (position < 0)
{
cid_datatable_prepend(p_list,data);
return;
}
else
if (position > (gint) cid_datatable_length(*p_list))
{
cid_datatable_append(p_list,data);
return;
}
CidDataCase *p_temp = (*p_list)->head;
int i = 1;
while (p_temp != NULL && i <= position)
{
if (position == i)
{
if (p_temp->next == NULL)
{
cid_datatable_append(p_list, data);
}
else if (p_temp->prev == NULL)