1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/* Spruce
* Copyright (C) 1999 Susixware
*
* 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 the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "msgid.h"
GSList *msgids = NULL;
/* We have no foolproofing */
gint open_msgids_file(void)
{
gchar *home_dir, *msgids_file, *msgid, *hgc1;
FILE *fp;
home_dir = g_strdup(getenv("HOME"));
if (!home_dir)
{
g_warning("Can't determine home dir !");
gtk_exit(1);
}
if (msgids != NULL)
g_slist_free(msgids);
msgids = NULL;
msgids_file = g_malloc0(strlen(home_dir) + strlen(MSGIDS_FILE) + 1);
strcpy(msgids_file, home_dir);
strcat(msgids_file, MSGIDS_FILE);
fp = fopen(msgids_file, "r");
if (fp != NULL)
{
while (!feof(fp))
{
msgid = g_malloc0(128);
fgets(msgid, 127, fp);
if (*msgid != '<')
continue;
hgc1 = strchr(msgid, '>') + 1;
if (hgc1 != (gchar*) 1)
*hgc1 = '\0';
msgids = g_slist_append(msgids, g_strdup(msgid));
g_free(msgid);
}
fclose(fp);
}
g_free(home_dir);
g_free(msgids_file);
return 0;
}
gboolean find_msgid(gchar *msgid)
{
GSList *temp = msgids;
while (temp != NULL)
{
if (!strcmp(msgid, (gchar *)(temp->data)))
return TRUE;
temp = g_slist_next(temp);
}
return FALSE;
}
void add_msgid(gchar *msgid)
{
msgids = g_slist_append(msgids, g_strdup(msgid));
}
void close_msgids_file(void)
{
GSList *temp;
FILE *fp;
gchar *home_dir, *msgids_file;
home_dir = g_strdup(getenv("HOME"));
if (!home_dir)
{
g_warning("Can't determine home dir!");
gtk_exit(1);
}
temp = msgids;
msgids_file = g_malloc0(strlen(home_dir) + strlen(MSGIDS_FILE) + 1);
strcpy(msgids_file, home_dir);
strcat(msgids_file, MSGIDS_FILE);
fp = fopen(msgids_file, "w");
if (fp != NULL)
{
while (temp != NULL)
{
fprintf(fp, "%s\n", (gchar *)(temp->data));
temp = g_slist_next(temp);
}
fclose(fp);
}
g_free(home_dir);
g_free(msgids_file);
}
|