From 3be6a075a33c006118f7d5b15a7a6d0d213cf3a7 Mon Sep 17 00:00:00 2001 From: gyboth Date: Sat, 29 Nov 2008 11:30:10 +0000 Subject: [PATCH] Newspaper progressing. --- src/xml_loadsave_newspaper.c | 231 +++++++++++++++++++++++++++++++++++ src/xml_loadsave_newspaper.h | 59 +++++++++ 2 files changed, 290 insertions(+) create mode 100644 src/xml_loadsave_newspaper.c create mode 100644 src/xml_loadsave_newspaper.h diff --git a/src/xml_loadsave_newspaper.c b/src/xml_loadsave_newspaper.c new file mode 100644 index 00000000..edc00371 --- /dev/null +++ b/src/xml_loadsave_newspaper.c @@ -0,0 +1,231 @@ +/* + xml_loadsave_newspaper.c + + Bygfoot Football Manager -- a small and simple GTK2-based + football management game. + + http://bygfoot.sourceforge.net + + Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com) + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "file.h" +#include "free.h" +#include "misc.h" +#include "xml.h" +#include "xml_loadsave_newspaper.h" +#include "variables.h" + +enum +{ + TAG_NEWS_PAPER = TAG_START_NEWS_PAPER, + TAG_NEWS_PAPER_NAME, + TAG_NEWS_PAPER_ARTICLE, + TAG_NEWS_PAPER_ARTICLE_WEEK, + TAG_NEWS_PAPER_ARTICLE_WEEK_ROUND, + TAG_NEWS_PAPER_ARTICLE_TITLE_ID, + TAG_NEWS_PAPER_ARTICLE_SUBTITLE_ID, + TAG_NEWS_PAPER_ARTICLE_TITLE, + TAG_NEWS_PAPER_ARTICLE_SUBTITLE, + TAG_END +}; + +gint state; +NewsPaperArticle new_article; + +void +xml_loadsave_newspaper_start_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ +#ifdef DEBUG + printf("xml_loadsave_newspaper_start_element\n"); +#endif + + gint i; + gint tag = xml_get_tag_from_name(element_name); + gboolean valid_tag = FALSE; + + for(i=TAG_NEWS_PAPER;i\n", TAG_NEWS_PAPER); + + for(i = 0; i < newspaper.names->len; i++) + xml_write_string(fil, (gchar*)g_ptr_array_index(newspaper.names, i), TAG_NEWS_PAPER_NAME, I1); + + for(i=0;ilen;i++) + { + fprintf(fil, "%s<_%d>\n", I0, TAG_NEWS_PAPER_ARTICLE); + + xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).week_number, + TAG_NEWS_PAPER_ARTICLE_WEEK, I1); + xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).week_round_number, + TAG_NEWS_PAPER_ARTICLE_WEEK_ROUND, I1); + xml_write_string(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).title, + TAG_NEWS_PAPER_ARTICLE_TITLE, I1); + xml_write_string(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).subtitle, + TAG_NEWS_PAPER_ARTICLE_SUBTITLE, I1); + xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).title_id, + TAG_NEWS_PAPER_ARTICLE_TITLE_ID, I1); + xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).subtitle_id, + TAG_NEWS_PAPER_ARTICLE_SUBTITLE_ID, I1); + + fprintf(fil, "%s\n", I0, TAG_NEWS_PAPER_ARTICLE); + } + + fprintf(fil, "\n", TAG_NEWS_PAPER); + + fclose(fil); +} diff --git a/src/xml_loadsave_newspaper.h b/src/xml_loadsave_newspaper.h new file mode 100644 index 00000000..c105cea6 --- /dev/null +++ b/src/xml_loadsave_newspaper.h @@ -0,0 +1,59 @@ +/* + xml_loadsave_newspaper.h + + Bygfoot Football Manager -- a small and simple GTK2-based + football management game. + + http://bygfoot.sourceforge.net + + Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com) + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef XML_LOADSAVE_NEWSPAPER_H +#define XML_LOADSAVE_NEWSPAPER_H + +#include "bygfoot.h" +#include "news_struct.h" + +void +xml_loadsave_newspaper_start_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error); + +void +xml_loadsave_newspaper_end_element (GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error); + +void +xml_loadsave_newspaper_text (GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error); + +void +xml_loadsave_newspaper_read(const gchar *dirname, const gchar *prefix); + +void +xml_loadsave_newspaper_write(const gchar *prefix); + +#endif