Commit c9073da1 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(fparse_read_range_0): New static function that handles the new

	range-based representation of memberships.
(fparse_membership_2): Use it.
(fparse_membership_0): Use it.
(fparse_membership_list_0): Handle the new range-based
	representation of memberships.
(fparse_membership_list_2): Ditto.
parent 80e0f3fa
/*
* $Id: ram-parse.c,v 0.49 2002/09/06 22:42:58 ceder Exp $
* $Id: ram-parse.c,v 0.50 2002/11/06 18:41:15 ceder Exp $
* Copyright (C) 1991, 1993-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -460,61 +460,72 @@ fparse_membership_type(FILE *fp,
return OK;
}
static Success
fparse_membership_2(FILE *fp,
Membership *mship)
fparse_read_range_0(FILE *fp,
Membership *mship)
{
int i;
mship->last_time_read = fparse_time(fp);
Local_text_no last_text_read;
unsigned short no_of_read;
unsigned short i;
mship->conf_no = fparse_long(fp);
mship->priority = fparse_long(fp);
mship->last_text_read = fparse_long(fp);
mship->no_of_read = fparse_long(fp);
unsigned int n;
struct read_range *res;
struct read_range *tail;
Local_text_no tmp;
last_text_read = fparse_long(fp);
no_of_read = fparse_long(fp);
sfree(mship->read_ranges);
mship->read_ranges = NULL;
mship->no_of_read_ranges = 0;
if ( mship->no_of_read > 0)
if (no_of_read > 0)
{
fskipwhite(fp);
switch(getc(fp))
{
case '{':
mship->read_texts
= REALLOC(mship->read_texts, (mship->no_of_read
* sizeof(Local_text_no)));
if ( mship->read_texts == NULL )
n = 0;
tail = res = NULL;
for (i = 0; i < no_of_read; i++)
{
err_stat = 0;
kom_errno = KOM_OUT_OF_MEMORY;
return FAILURE;
tmp = fparse_long(fp);
if (tail != NULL && tmp == tail->last_read + 1)
tail->last_read = tmp;
else
{
res = REALLOC(res, ++n * sizeof(*res));
tail = &res[n-1];
tail->first_read = tail->last_read = tmp;
}
}
for ( i = 0; i < mship->no_of_read; i++)
mship->read_texts[ i ] = fparse_long(fp);
mship->no_of_read_ranges = n;
mship->read_ranges = res;
fskipwhite(fp);
if ( getc(fp) != '}' )
if (getc(fp) != '}')
{
err_stat = 1;
kom_errno = KOM_LDB_ERR;
kom_log("fparse_membership(): expected '}' at pos %lu.\n",
(unsigned long)ftell(fp));
(unsigned long)ftell(fp));
return FAILURE;
}
break;
case '*':
if ( mship->read_texts != NULL )
{
sfree(mship->read_texts);
mship->read_texts = NULL;
}
kom_log("fparse_membership(): %s with %lu elements (corrected)\n",
"empty read_texts", (unsigned long)mship->no_of_read);
mship->no_of_read = 0;
kom_log("fparse_read_range_0(): "
"empty read_ranges with %lu elements (corrected)\n",
(unsigned long)no_of_read);
mship->no_of_read_ranges = 0;
break;
default:
kom_log("fparse_membership(): expected '*' or '{' at pos %lu.\n",
kom_log("fparse_read_range_0(): expected '*' or '{' at pos %lu.\n",
(unsigned long)ftell(fp));
err_stat = 2;
kom_errno = KOM_LDB_ERR;
......@@ -526,20 +537,26 @@ fparse_membership_2(FILE *fp,
fskipwhite(fp);
if ( getc(fp) != '*' )
{
kom_log("fparse_membership(): expected '*' at pos %lu.\n",
kom_log("fparse_read_range_0(): expected '*' at pos %lu.\n",
(unsigned long)ftell(fp));
err_stat = 3;
kom_errno = KOM_LDB_ERR;
return FAILURE;
}
if ( mship->read_texts != NULL )
{
sfree(mship->read_texts);
mship->read_texts = NULL;
}
}
return OK;
}
static Success
fparse_membership_2(FILE *fp,
Membership *mship)
{
mship->last_time_read = fparse_time(fp);
mship->conf_no = fparse_long(fp);
mship->priority = fparse_long(fp);
if (fparse_read_range_0(fp, mship) != OK)
return FAILURE;
mship->added_by = fparse_long(fp);
mship->added_at = fparse_time(fp);
if (fparse_membership_type(fp, &mship->type) != OK)
......@@ -552,81 +569,12 @@ static Success
fparse_membership_0(FILE *fp,
Membership *mship)
{
int i;
mship->last_time_read = fparse_time(fp);
mship->conf_no = fparse_long(fp);
mship->priority = fparse_long(fp);
mship->last_text_read = fparse_long(fp);
mship->no_of_read = fparse_long(fp);
if ( mship->no_of_read > 0)
{
fskipwhite(fp);
switch(getc(fp))
{
case '{':
mship->read_texts
= REALLOC(mship->read_texts, (mship->no_of_read
* sizeof(Local_text_no)));
if ( mship->read_texts == NULL )
{
err_stat = 0;
kom_errno = KOM_OUT_OF_MEMORY;
return FAILURE;
}
for ( i = 0; i < mship->no_of_read; i++)
mship->read_texts[ i ] = fparse_long(fp);
fskipwhite(fp);
if ( getc(fp) != '}' )
{
err_stat = 1;
kom_errno = KOM_LDB_ERR;
kom_log("fparse_membership(): expected '}' at pos %lu.\n",
(unsigned long)ftell(fp));
return FAILURE;
}
break;
case '*':
if ( mship->read_texts != NULL )
{
sfree(mship->read_texts);
mship->read_texts = NULL;
}
kom_log("fparse_membership(): %s with %lu elements (corrected)\n",
"empty read_texts", (unsigned long)mship->no_of_read);
mship->no_of_read = 0;
break;
default:
kom_log("fparse_membership(): expected '*' or '{' at pos %lu.\n",
(unsigned long)ftell(fp));
err_stat = 2;
kom_errno = KOM_LDB_ERR;
return FAILURE;
}
}
else
{
fskipwhite(fp);
if ( getc(fp) != '*' )
{
kom_log("fparse_membership(): expected '*' at pos %lu.\n",
(unsigned long)ftell(fp));
err_stat = 3;
kom_errno = KOM_LDB_ERR;
return FAILURE;
}
if ( mship->read_texts != NULL )
{
sfree(mship->read_texts);
mship->read_texts = NULL;
}
}
if (fparse_read_range_0(fp, mship) != OK)
return FAILURE;
return OK;
}
......@@ -664,7 +612,7 @@ fparse_membership_list_0(FILE *fp,
if ( result->confs != NULL )
{
for ( i = 0; i < result->no_of_confs; i++)
sfree(result->confs[ i ].read_texts);
sfree(result->confs[ i ].read_ranges);
}
result->no_of_confs = fparse_long(fp);
......@@ -754,7 +702,7 @@ fparse_membership_list_2(FILE *fp,
if ( result->confs != NULL )
{
for ( i = 0; i < result->no_of_confs; i++)
sfree(result->confs[ i ].read_texts);
sfree(result->confs[ i ].read_ranges);
}
result->no_of_confs = fparse_long(fp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment