2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2000 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <pthread.h>
2N/A#include <string.h>
2N/A#include <stdlib.h>
2N/A
2N/A#include "Parser.h"
2N/A
2N/A// yacc symbols
2N/Aint fruparse(void);
2N/Aextern int frudebug;
2N/A
2N/A// global data to/from the lexer
2N/Apthread_mutex_t gParserLock;
2N/Afru_errno_t gParserErrno = FRU_SUCCESS;
2N/Achar *gParserString = NULL;
2N/AAncestor *gParserAnts = NULL;
2N/APathDef *gParserHead = NULL;
2N/Aint *gParserAbs = NULL;
2N/A
2N/A// returns a NULL terminated list of PathDef objects.
2N/A// and a NULL terminated list of ancestor objects this path exists in
2N/A// NOTE: ancestors may be NULL if no tags contain a valid path.
2N/Afru_errno_t
2N/Afru_field_parser(const char *path, Ancestor **ancestors,
2N/A int *absolute, PathDef **pathDef)
2N/A{
2N/A // lock up the globals for the parser...
2N/A pthread_mutex_lock(&gParserLock);
2N/A
2N/A // get out a string for the parser to play with.
2N/A gParserString = strdup(path);
2N/A if (gParserString == NULL) {
2N/A pthread_mutex_unlock(&gParserLock);
2N/A return (FRU_FAILURE);
2N/A }
2N/A // save the head pointer for delete.
2N/A char *delPtr = gParserString;
2N/A
2N/A // frudebug = 1;
2N/A
2N/A // set up for return data from lexer.
2N/A gParserHead = NULL;
2N/A gParserAnts = NULL;
2N/A gParserErrno = FRU_SUCCESS;
2N/A gParserAbs = absolute;
2N/A *gParserAbs = 0;
2N/A
2N/A int rc = fruparse();
2N/A
2N/A // clean up the string we used for yacc.
2N/A free(delPtr);
2N/A gParserString = NULL;
2N/A
2N/A // frudebug = 0;
2N/A if (rc != 0) {
2N/A delete gParserHead;
2N/A delete gParserAnts;
2N/A fru_errno_t err = gParserErrno;
2N/A pthread_mutex_unlock(&gParserLock);
2N/A return (err);
2N/A }
2N/A
2N/A /* if ((gParserHead == NULL) || (gParserAnts == NULL)) { */
2N/A /* allow ancestors to be NULL */
2N/A /* some elements don't have tagged ancestors */
2N/A if (gParserHead == NULL) {
2N/A delete gParserAnts;
2N/A pthread_mutex_unlock(&gParserLock);
2N/A return (FRU_FAILURE);
2N/A }
2N/A
2N/A *pathDef = gParserHead;
2N/A *ancestors = gParserAnts;
2N/A
2N/A pthread_mutex_unlock(&gParserLock);
2N/A return (FRU_SUCCESS);
2N/A}