#ifndef __UTIL_H #define __UTIL_H /*------------------------------------------------------------------------- * Copyright (c) 1999-2004 Kenneth W. Sodemann (stuffle@mac.com) *------------------------------------------------------------------------- * util * * Synopsis: * Various utility functions that could come in handy in more than * one module in this system. * * $Id: util.h,v 1.20 2004/09/07 01:24:58 stuffle Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * *------------------------------------------------------------------------- */ #include #include #include #define INVALID_PK -1 #define INVALID_ID "!!Not a valid ID!!" #define INVALID_ID_LEN 18 /* * For using pipes, define which is read and which is write. */ #define READ_PIPE 0 #define WRITE_PIPE 1 /* * This structure is used to couple a name display string with a * numeric key. * * Use the 'find_name_from_pk' and 'find_pk_from_name' functions to * find one item when given the other. */ typedef struct name_pk_struct { gchar *name; gint pk; } name_pk_struct; /* * This structure is used to couple a name display string with a * user ID (character string) key. * * Use the 'fine_name_from_id' and 'find_id_from_name' functions to * find one item when given the other. */ typedef struct name_id_struct { gchar *name; gchar *id; } name_id_struct; /*------------------------------------------------------------------------- * Function: destroy_name_pk_list * * Synopsis: * Free the memory used by a list of name_pk_struct elements. * * Inputs: * list : GList of name_pk_struct's to destroy * * Outputs: * None. * * Return Value: * None. *------------------------------------------------------------------------- */ void destroy_name_pk_list (GList *list); /*------------------------------------------------------------------------- * Function: destroy_name_id_list * * Synopsis: * Free the memory used by a list of name_id_struct elements. * * Inputs: * list : GList of name_id_struct's to destroy * * Outputs: * None. * * Return Value: * None. *------------------------------------------------------------------------- */ void destroy_name_id_list (GList *list); /*------------------------------------------------------------------------- * Function: find_name_pk_from_pk * * Synopsis: * Given the PK number and a list, find the first name/pk struct * in the list with that PK. * * Inputs: * list : GList of name_pk_structs to search * pk : the numeric key to look for * * Outputs: * None. * * Return Value: * Pointer to the struct, or NULL if not found. *------------------------------------------------------------------------- */ name_pk_struct *find_name_pk_from_pk (GList *list, gint pk); /*------------------------------------------------------------------------- * Function: find_name_pk_from_name * * Synopsis: * Given the list and a name, find the first name/pk struct in the * list that has a matching name. * * Inputs: * list : GList of name_pk_struct's to search * name : the name to search for * * Outputs: * None. * * Return Value: * Pointer to the struct, or NULL if not found. *------------------------------------------------------------------------- */ name_pk_struct *find_name_pk_from_name (GList *list, const gchar *name); /*------------------------------------------------------------------------- * Function: find_name_from_pk * * Synopsis: * Given the PK number and a list, find the first name in the * list with that PK. * * Inputs: * list : GList of name_pk_struct's to search * pk : the numeric key to look for * * Outputs: * None. * * Return Value: * Pointer to the name, or NULL if not found. *------------------------------------------------------------------------- */ gchar *find_name_from_pk (GList *list, gint pk); /*------------------------------------------------------------------------- * Function: find_pk_from_name * * Synopsis: * Given the list and a name, find the first PK that has a matching * name. * * Inputs: * list : GList of name_pk_struct's to search * name : the name to search for * * Outputs: * None. * * Return Value: * The first PK with a matching name, or INVALID_PK if none found. *------------------------------------------------------------------------- */ gint find_pk_from_name (GList *list, const gchar *name); /*------------------------------------------------------------------------- * Function: find_name_id_from_id * * Synopsis: * Find the name/id struct associated with the given ID. * * Inputs: * list : GList of name_id_struct's to search * id : the ID to search for * * Outputs: * None. * * Return Value: * Pointer to the struct, or NULL if not found. *------------------------------------------------------------------------- */ name_id_struct *find_name_id_from_id (GList *list, const gchar *id); /*------------------------------------------------------------------------- * Function: find_name_id_from_name * * Synopsis: * Given the name, find the first name/ID struct that is associated * with that name. * * Inputs: * list : a GList of name_id_struct's to search * name : the name to look for * * Outputs: * None. * * Return Value: * Pointer to the struct, or NULL if not found. *------------------------------------------------------------------------- */ name_id_struct *find_name_id_from_name (GList *list, const gchar *name); /*------------------------------------------------------------------------- * Function: find_name_from_id * * Synopsis: * Find the name associated with the given ID. * * Inputs: * list : GList of name_id_struct's to search * id : the ID to search for * * Outputs: * None. * * Return Value: * Pointer to the associated name string, or NULL if not found. * *------------------------------------------------------------------------- */ gchar *find_name_from_id (GList *list, const gchar *id); /*------------------------------------------------------------------------- * Function: find_id_from_name * * Synopsis: * Given the name, find the first ID that is associated with that * name. * * Inputs: * list : a GList of name_id_struct's to search * name : the name to look for * * Outputs: * None. * * Return Value: * The first ID associated with the given name, NULL if not found. * *------------------------------------------------------------------------- */ gchar *find_id_from_name (GList *list, const gchar *name); /*------------------------------------------------------------------------- * Function: spawn_viewer * * Synopsis: * Spawn the given viewer to display the given file. * * Inputs: * viewer : command to launch viewer * file_name : the file name to load * * Outputs: * None. * * Return Value: * 0 : Success * < 0 : Failure *------------------------------------------------------------------------- */ gint spawn_viewer (const gchar *viewer, const gchar *file_name); /*------------------------------------------------------------------------- * Function: save_dlg_size * * Synopsis: * Save the size of the dialog in the config file. Sync the config * file. * * Inputs: * client : GConf client to use when setting the configuration * dlg : pointer to the dialog * name : the config section name for the dialog * * Outputs: * None. * * Return Value: * None. *------------------------------------------------------------------------- */ void save_dlg_size (GConfClient *client, GtkWidget *dlg, const gchar *name); /*------------------------------------------------------------------------- * Function: set_dlg_size * * Synopsis: * Set the size of the dialog based on values in the config file. * * Inputs: * client : GConf client to use when getting the configuration * dlg : pointer to the dialog * name : the config section name for the dialog * x_def : default x value (width) if not defined in config file * y_def : default y value (height) if not defined in config file * * Outputs: * None. * * Return Value: * None. *------------------------------------------------------------------------- */ void set_dlg_size (GConfClient *client, GtkWidget *dlg, const gchar *name, gint x_def, gint y_def); #endif