2
* This file is part of the apvlv package
3
* Copyright (C) <2008> <Alf>
5
* Contact: Alf <naihe2010@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program; if not, write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
/* @CFILE ApvlvInfo.cpp
24
* Author: Alf <naihe2010@gmail.com>
26
/* @date Created: 2010/02/23 15:00:42 Alf*/
28
#include "ApvlvInfo.hpp"
38
ApvlvInfo *gInfo = NULL;
40
ApvlvInfo::ApvlvInfo (const char *filename)
47
ifstream is (mFileName.c_str (), ios::in);
53
while (getline (is, line))
57
if (*p != '\'' /* the ' */
58
|| !isdigit (*(p + 1))) /* the digit */
66
mFileHead = g_slist_reverse (mFileHead);
72
ApvlvInfo::~ApvlvInfo ()
74
while (mFileHead != NULL)
76
infofile *fp = (infofile *) (mFileHead->data);
78
mFileHead = g_slist_next (mFileHead);
80
g_slist_free (mFileHead);
83
bool ApvlvInfo::update ()
85
ofstream os (mFileName.c_str (), ios::out);
94
for (i = 0, lfp = mFileHead;
95
i < mFileMax && lfp != NULL; ++i, lfp = g_slist_next (lfp))
97
fp = (infofile *) (lfp->data);
100
os << "'" << i << "\t";
101
os << fp->page << "\t";
102
os << fp->rate << "\t";
103
os << fp->file << endl;
111
infofile *ApvlvInfo::file (int id)
113
infofile *fp = (infofile *) g_slist_nth_data (mFileHead, id);
117
infofile *ApvlvInfo::file (const char *filename)
122
for (lfp = mFileHead; lfp != NULL; lfp = g_slist_next (lfp))
124
fp = (infofile *) (lfp->data);
125
if (fp->file == filename)
137
mFileHead = g_slist_insert_before (mFileHead, mFileHead, fp);
141
mFileHead = g_slist_remove (mFileHead, fp);
142
mFileHead = g_slist_insert_before (mFileHead, mFileHead, fp);
148
bool ApvlvInfo::file (int page, double rate, const char *filename)
152
fp = file (filename);
165
bool ApvlvInfo::ini_add_position (const char *str)
169
p = strchr (str + 2, '\t'); /* Skip the ' and the digit */
175
while (*p != '\0' && !isdigit (*p))
181
p = strchr (p, '\t');
187
while (*p != '\0' && !isdigit (*p))
191
double rate = atof (p);
193
p = strchr (p, '\t');
199
while (*p != '\0' && isspace (*p))
208
infofile *fp = new infofile;
212
mFileHead = g_slist_insert_before (mFileHead, mFileHead, fp);