--- deliantra/server/common/readable.C 2010/03/26 00:59:20 1.55 +++ deliantra/server/common/readable.C 2010/04/15 21:49:15 1.58 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * @@ -536,6 +536,9 @@ static titlelist * get_titlelist (int i) { + if (!booklist) + booklist = get_empty_booklist (); + titlelist *tl = booklist; int number = i; @@ -548,7 +551,7 @@ tl->next = get_empty_booklist (); tl = tl->next; - number--; + --number; } return tl; @@ -623,89 +626,70 @@ static void init_book_archive () { - FILE *fp; - int comp, nroftitle = 0; - char buf[MAX_BUF], fname[MAX_BUF], *cp; - title *book = NULL; + int nroftitle = 0; + char fname[MAX_BUF]; titlelist *bl = get_empty_booklist (); - static int did_init_barch; - - if (did_init_barch) - return; - - did_init_barch = 1; - - if (!booklist) - booklist = bl; sprintf (fname, "%s/bookarch", settings.localdir); LOG (llevDebug, " Reading bookarch from %s...\n", fname); - if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) + object_thawer thawer (fname); + + if (!thawer) { - int value, type = 0; - size_t i; + LOG (llevDebug, "could not read bookarch file\n"); + return; + } + + while (thawer.kw) + { + if (thawer.kw != KW_title) + if (!thawer.parse_error ("bookarch file")) + break; - while (fgets (buf, MAX_BUF, fp) != NULL) + title *book = get_empty_book (); /* init new book entry */ + thawer.get (book->name); + + int type = -1; + + for (;;) { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; - if (!strncmp (cp, "title", 4)) - { - book = get_empty_book (); /* init new book entry */ - book->name = strchr (cp, ' ') + 1; - type = -1; - nroftitle++; - continue; - } - if (!strncmp (cp, "authour", 4)) - { - book->authour = strchr (cp, ' ') + 1; - } - if (!strncmp (cp, "arch", 4)) - { - book->archname = strchr (cp, ' ') + 1; - } - else if (sscanf (cp, "level %d", &value)) - { - book->level = (uint16) value; - } - else if (sscanf (cp, "type %d", &value)) - { - type = (uint16) value; - } - else if (sscanf (cp, "size %d", &value)) - { - book->size = (uint16) value; - } - else if (sscanf (cp, "index %d", &value)) + thawer.next (); + + switch (thawer.kw) { - book->msg_index = (uint16) value; + case KW_type: thawer.get (type ); break; + case KW_authour: thawer.get (book->authour ); break; + case KW_arch: thawer.get (book->archname ); break; + case KW_level: thawer.get (book->level ); break; + case KW_size: thawer.get (book->size ); break; + case KW_index: thawer.get (book->msg_index); break; + + case KW_end: + /* link it */ + bl = get_titlelist (type); + book->next = bl->first_book; + bl->first_book = book; + bl->number++; + ++nroftitle; + goto book_done; + + default: + delete book; + goto book_done; } - else if (!strncmp (cp, "end", 3)) - { /* link it */ - bl = get_titlelist (type); - book->next = bl->first_book; - bl->first_book = book; - bl->number++; - } - } - LOG (llevDebug, "book archives(used/avail): \n"); - for (bl = booklist, i = 0; bl != NULL && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) - { - LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); } - close_and_delete (fp, comp); + +book_done: + thawer.next (); } -#ifdef BOOK_MSG_DEBUG + LOG (llevDebug, "book archives(used/avail): \n"); + int i; + for (bl = booklist, i = 0; bl && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) + LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); + LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); -#endif LOG (llevDebug, " done.\n"); } @@ -1350,7 +1334,7 @@ tmp = object::create (); add_abilities (tmp, art->item); tmp->type = type; - SET_FLAG (tmp, FLAG_IDENTIFIED); + tmp->set_flag (FLAG_IDENTIFIED); if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) buf << "\rProperties of this artifact include:\r" << ch << "\n";