Exemplo n.º 1
0
/*
**  Name: CFReadConf
**
**  Description:
**      Read the configuration file a line at a time and build a list.
**
**  Inputs:
**      path            path of file to read
**      filename        filename of file to read
**
**  Outputs:
**      loc             Location to update with path and filename
**      begin           Starting line of the confiuration
**      end             Last line of the configuration
**
**  Returns:
**      OK      success
**      FAIL    failure
**
** History:
**      11-Feb-2000 (fanra01)
**          Created.
*/
STATUS
CFReadConf( char* path, char* filename, LOCATION* loc, PRL* begin )
{
    STATUS  status;
    char*   locpath;
    FILE*   fptr;
    PRL     newline;
    PRL     end;

    /*
    ** Get the location path
    */
    LOtos( loc, &locpath );
    STRCOPY( path, locpath );
    if ((status = LOfroms( PATH, locpath, loc )) == OK)
    {
        LOfstfile( filename, loc );
        if ((status = SIfopen( loc, "r", SI_TXT, 0, &fptr )) == OK)
        {
            do
            {
                status = SIgetrec( readbuf, SI_MAX_TXT_REC, fptr );
                if (status != ENDFILE)
                {
                    HALLOC( newline, RL, 1, &status );
                    if (newline != NULL)
                    {
                        newline->text = STRALLOC( readbuf );
                        if (*begin == NULL)
                        {
                            *begin = newline;
                            newline->prev = newline;
                        }
                        else
                        {
                            end = (*begin)->prev;
                            end->next = newline;
                            newline->prev = end;
                            (*begin)->prev = newline;
                        }
                    }
                }
            }while (status == OK);
            status = ((status == ENDFILE) || (status == OK)) ? OK : status;
            SIclose( fptr );
        }
        else
        {
            PRINTF( "Error: %d - Unable to open file %s in %s.\n", status,
                filename, path );
        }
    }
    return (status);
}
Exemplo n.º 2
0
/*
** Name: CFBuildList
**
** Description:
**      Build a list from an array of character strings.
**
** Inputs:
**      section         pointer to array of character strings.
**
** Outputs:
**      begin           head of the list
**      end             tail of the list
**
** Returns:
**      OK              success
**      FAIL            failure
**
** History:
**      11-Feb-2000 (fanra01)
**          Created.
*/
STATUS
CFBuildList( char* section[], PRL* begin )
{
    STATUS  status = OK;
    PRL     newline;
    PRL     end;
    char**  sectline = section;
    i4      i;

    /*
    ** Assume the section is NULL terminated
    */
    for (i=0; (sectline && sectline[i]); i++)
    {
        /*
        ** Allocate a structure for the new line
        */
        HALLOC( newline, RL, 1, &status );
        if (newline != NULL)
        {
            /*
            ** Duplicate the line and add to end of list
            */
            newline->text = STRALLOC( sectline[i] );
            if (*begin == NULL)
            {
                *begin = newline;
                newline->prev = newline;
            }
            else
            {
                end = (*begin)->prev;
                end->next = newline;
                newline->prev = end;
                (*begin)->prev = newline;
            }
        }
    }
    return (status);
}
Exemplo n.º 3
0
int hAllocEntry(void ***list, int *max, int size)
#endif
{
	char_t	*cp;
	int		id;

	a_assert(list);
	a_assert(max);

#ifdef B_STATS
	if ((id = HALLOC(B_ARGS, (void***) list)) < 0) {
#else
	if ((id = hAlloc((void***) list)) < 0) {
#endif
		return -1;
	}

	if (size > 0) {
#ifdef B_STATS
		if ((cp = balloc(B_ARGS, size)) == NULL) {
#else
		if ((cp = balloc(B_L, size)) == NULL) {
#endif
			hFree(list, id);
			return -1;
		}
		a_assert(cp);
		memset(cp, 0, size);

		(*list)[id] = (void*) cp;
	}

	if (id >= *max) {
		*max = id + 1;
	}
	return id;
}