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
|
/*
GPSBabel session (format session) management
Copyright (C) 2008 Olaf Klein, o.b.klein@gpsbabel.org
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 USA
*/
#include "defs.h"
#include "session.h"
static queue session_list;
static int session_ct;
static void session_free(session_t *s);
void
session_init(void)
{
QUEUE_INIT(&session_list);
session_ct = 0;
}
void
session_exit(void)
{
queue *elem, *tmp;
QUEUE_FOR_EACH(&session_list, elem, tmp) {
session_t *s = (session_t *)elem;
dequeue(&s->Q);
session_free(s);
}
}
void
start_session(const char *name, const char *filename)
{
session_t *s;
if (session_ct == 0) {
QUEUE_INIT(&session_list);
}
session_ct++;
s = (session_t*) xcalloc(1, sizeof(*s));
ENQUEUE_TAIL(&session_list, &s->Q);
QUEUE_INIT(&s->category_list);
s->nr = session_ct;
s->name = name;
s->filename = xstrdup(filename);
}
session_t *
curr_session(void)
{
return (session_t *) session_list.prev;
}
/* in work
int
session_add_category(const char *name, const int id)
{
queue *elem, *tmp;
session_t *s;
category_t *c;
s = curr_session();
QUEUE_FOR_EACH(&s->category_list, elem, tmp) {
c = (category_t *) elem;
if (case_ignore_strcmp(c->name, name) == 0) {
if (id >= 0) c->id = id;
return c->id;
}
}
c = xmalloc(sizeof(*c));
c->name = xstrdup(name);
if (id < 0) c->id = -(++s->unknown_category_ct);
else c->id = id;
s->category_ct++;
ENQUEUE_TAIL(&s->category_list, &c->Q);
return c->id;
}
*/
/* non public functions */
static void
session_free(session_t *s)
{
queue *elem, *tmp;
QUEUE_FOR_EACH(&s->category_list, elem, tmp) {
category_t *c = (category_t *) elem;
dequeue(&c->Q);
xfree(c);
}
xfree(s->filename);
xfree(s);
}
|