srchcfile.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdio.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <limits.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdlib.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <string.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <strings.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <ctype.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <sys/types.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <libintl.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkglib.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkgstrct.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkglocale.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkglibmsgs.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Forward declarations
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void findend(char **cp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int getend(char **cp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int getstr(char **cp, int n, char *str, int separator[]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* from gpkgmap.c */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint getnumvfp(char **cp, int base, long *d, long bad);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint getlnumvfp(char **cp, int base, fsblkcnt_t *d, long bad);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Module globals
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char lpath[PATH_MAX]; /* for ept->path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char mylocal[PATH_MAX]; /* for ept->ainfo.local */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int decisionTableInit = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * These arrays must be indexable by an unsigned char.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int ISPKGPATHSEP[UCHAR_MAX+1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int ISWORDSEP[UCHAR_MAX+1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int ISPKGNAMESEP[UCHAR_MAX+1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: WRITEDATA
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: write out data to VFP_T given start and end pointers
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: VFP - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Contents file VFP to narrow search on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * FIRSTPOS - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to first byte to write out
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * LASTPOS - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to last byte to write out
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define WRITEDATA(VFP, FIRSTPOS, LASTPOS) \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ssize_t XXlenXX; \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compute number of bytes skipped */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland XXlenXX = (ptrdiff_t)(LASTPOS) - (ptrdiff_t)(FIRSTPOS); \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write the bytes out */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutBytes((VFP), (FIRSTPOS), XXlenXX); \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: COPYPATH
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: copy path limiting size to destination capacity
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: DEST - (char []) - [RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * SRC - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to first byte of path to copy
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * LEN - (int) - [RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Number of bytes to copy
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define COPYPATH(DEST, SRC, LEN) \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* assure return path does not overflow */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((LEN) > sizeof ((DEST))) { \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (LEN) = sizeof ((DEST))-1; \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy return path to local storage */ \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) memcpy((DEST), (SRC), (LEN)); \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (DEST)[(LEN)] = '\0'; \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: narrowSearch
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: narrow the search location for a specified path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents and package map files are always sorted by path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function is given a target path to search for given the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * current location in a contents file. It is assured that the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * target path has not been searched for yet in the contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * so the current location in the contents file is guaranteed to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * be less than the location of the target path (if present).
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Given this employ a binary search to speed up the search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the path nearest to a specified target path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_vfp - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Contents file VFP to narrow search on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_path - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to path to search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_pathLen - (size_t) - [RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Length of string (a_path)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: char * - pointer to first byte of entry in contents file that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is guaranteed to be the closest match to the specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_path without being "greater than" the path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == (char *)NULL if no entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandnarrowSearch(VFP_T *a_vfp, char *a_path, size_t a_pathLen)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *phigh;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *plow;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *pmid;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t plen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if no path to compare, start at beginning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_path == (char *)NULL) || (*a_path == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ((char *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if the contents file is empty, resort to sequential search */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpGetBytesRemaining(a_vfp) <= 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ((char *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * test against first path - if the path specified is less than the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * first path in the contents file, then the path can be inserted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * before the first entry in the contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* locate start of first line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plow = vfpGetCurrCharPtr(a_vfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid = plow;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if first path not absolute, resort to sequential search */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*pmid != '/') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ((char *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find end of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*pmid] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine length of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plen = (ptrdiff_t)pmid - (ptrdiff_t)plow;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target path with current path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = strncmp(a_path, plow, plen);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if lengths same exact match return position found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_pathLen == plen) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (plow);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = a_pathLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return if target is less than or equal to first entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n <= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (plow);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * test against last path - if the path specified is greater than the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * last path in the contents file, then the path can be appended after
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the last entry in the contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* locate start of last line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plow = vfpGetCurrCharPtr(a_vfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid = vfpGetLastCharPtr(a_vfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((pmid > plow) && (!((pmid[0] == '/') && (pmid[-1] == '\n')))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if absolute path, do comparison */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((pmid > plow) && (*pmid == '/')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plow = pmid;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find end of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*pmid] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine length of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plen = (ptrdiff_t)pmid - (ptrdiff_t)plow;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target path with current path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = strncmp(a_path, plow, plen);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if lengths same exact match return position found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_pathLen == plen) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (plow);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = a_pathLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return if target is greater than or equal to entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n >= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (plow);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * firstPath < targetpath < lastPath:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * binary search looking for closest "less than" match
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plow = vfpGetCurrCharPtr(a_vfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland phigh = vfpGetLastCharPtr(a_vfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (;;) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *pm;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine number of bytes left in search area */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plen = (ptrdiff_t)phigh - (ptrdiff_t)plow;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* calculate mid point between current low and high points */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid = plow + (plen >> 1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* backup and find first "\n/" -or- start of buffer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((pmid > plow) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (!((pmid[0] == '/') && (pmid[-1] == '\n')))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return lowest line found if current line not past that */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (pmid <= plow) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (plow);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remember start of this line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pm = pmid;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find end of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*pmid] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pmid++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine length of path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plen = (ptrdiff_t)pmid - (ptrdiff_t)pm;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target path with current path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = strncmp(a_path, pm, plen);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if lengths same exact match return position found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_pathLen == plen) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (pm);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = a_pathLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not exact match - determine which watermark to split */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n > 0) { /* a_path > pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland plow = pm;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else { /* a_path < pm */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland phigh = pm;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*NOTREACHED*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: srchcfile
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: search contents file looking for closest match to entry,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * creating a new contents file if output contents file specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: ept - (struct cfent *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - contents file entry, describing last item found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path - (char *) - [RO, *RO]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - path to search for in contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If path is "*", then the next entry is returned;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the next entry always matches this path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If the path is (char *)NULL or "", then all remaining
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entries are processed and copied out to the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file specified by cfTmpVFp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * cfVfp - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - VFP_T open on contents file to search
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * cfTmpVfp - (VFP_T *) - [RO, *RW]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - VFP_T open on temporary contents file to populate
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * < 0 - error occurred
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - Use getErrstr to retrieve character-string describing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the reason for failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - no match found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - specified path not in the contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - all contents of cfVfp copied to cfTmpVfp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - current character of cfVfp is at end of file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 1 - exact match found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - specified path found in contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - contents of cfVfp up to entry found copied to cfTmpVfp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - current character of cfVfp is first character of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - this value is always returned if path is "*" and the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * next entry is returned - -1 is returned when no more
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entries are left to process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 2 - entry found which is GREATER than path specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - specified path would fit BEFORE entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - contents of cfVfp up to entry found copied to cfTmpVfp
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - current character of cfVfp is first character of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entry found
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Side Effects:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - The ept structure supplied is filled in with a description of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the item that caused the search to terminate, except in the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * case of '0' in which case the contents of 'ept' is undefined.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - NOTE: the ept->path item points to a path that is statically
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * allocated and will be overwritten on the next call.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - NOTE: the ept->ainfo.local item points to a path that is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * statically allocated and will be overwritten on the next call.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandsrchcfile(struct cfent *ept, char *path, VFP_T *cfVfp, VFP_T *cfTmpVfp)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *cpath_start = (char *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *firstPos = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *lastPos = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *pos;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char classname[CLSSIZ+1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char pkgname[PKGSIZ+1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int anypath = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int dataSkipped = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int rdpath;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t cpath_len = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t pathLength;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct pinfo *lastpinfo;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct pinfo *pinfo;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this code does not use nested subroutines because execution time
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of this routine is especially critical to installation and upgrade
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initialize local variables */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(NULL); /* no error message currently cached */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pathLength = (path == (char *)NULL ? 0 : strlen(path));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lpath[0] = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lpath[sizeof (lpath)-1] = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initialize ept structure values */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(ept->ainfo.group, BADGROUP, sizeof (ept->ainfo.group));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(ept->ainfo.owner, BADOWNER, sizeof (ept->ainfo.owner));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(ept->pkg_class, BADCLASS, sizeof (ept->pkg_class));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.local = (char *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.mode = BADMODE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->cinfo.cksum = BADCONT;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->cinfo.modtime = BADCONT;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->cinfo.size = (fsblkcnt_t)BADCONT;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ftype = BADFTYPE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->npkgs = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->path = (char *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->pinfo = (struct pinfo *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->pkg_class_idx = -1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->volno = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * populate decision tables that implement fast character checking;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is much faster than the equivalent strpbrk() call or a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * while() loop checking for the characters. It is only faster if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * there are at least 3 characters to scan for - when checking for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * one or two characters (such as '\n' or '\0') its faster to do
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a simple while() loop.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (decisionTableInit == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * any chars listed stop scan;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * scan stops on first byte found that is set to '1' below
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Separators for path names, normal space and =
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for linked filenames
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland bzero(ISPKGPATHSEP, sizeof (ISPKGPATHSEP));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP['='] = 1; /* = */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP[' '] = 1; /* space */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP['\t'] = 1; /* horizontal-tab */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP['\n'] = 1; /* new-line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGPATHSEP['\0'] = 1; /* NULL character */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Separators for normal words
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland bzero(ISWORDSEP, sizeof (ISWORDSEP));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISWORDSEP[' '] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISWORDSEP['\t'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISWORDSEP['\n'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISWORDSEP['\0'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Separators for list of packages, includes \\ for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * alternate ftype and : for classname
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland bzero(ISPKGNAMESEP, sizeof (ISPKGNAMESEP));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGNAMESEP[' '] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGNAMESEP['\t'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGNAMESEP['\n'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGNAMESEP[':'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGNAMESEP['\\'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ISPKGNAMESEP['\0'] = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland decisionTableInit = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if no bytes in contents file, return 0 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpGetBytesRemaining(cfVfp) <= 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if the path to scan for is empty, act like no path was specified */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((path != (char *)NULL) && (*path == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland path = (char *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if path to search for is "*", then we will return the first path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we encounter as a match, otherwise we return an error
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((path != (char *)NULL) && (path[0] != '/')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(path, "*") != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(pkg_gt(ERR_ILLEGAL_SEARCH_PATH));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland anypath = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* attempt to narrow down the search for the specified path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (anypath == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *np;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland np = narrowSearch(cfVfp, path, pathLength);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (np != (char *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland dataSkipped = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lastPos = np;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpSetCurrCharPtr(cfVfp, np);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the path to search for in the source contents file is NULL, then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is a request to scan to the end of the source contents file. If
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * there is a temporary contents file to copy entries to, all that needs
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to be done is to copy the data remaining from the current location in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the source contents file to the end of the temporary contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if there is no temporary contents file to copy to, then all that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * needs to be done is to seek to the end of the source contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((anypath == 0) && (path == (char *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (cfTmpVfp != (VFP_T *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpGetBytesRemaining(cfVfp) > 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland WRITEDATA(cfTmpVfp, firstPos,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpGetLastCharPtr(cfVfp)+1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *vfpGetLastCharPtr(cfTmpVfp) = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpSeekToEnd(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * main loop processing entries from the contents file looking for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the specified path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (;;) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not reading old style entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rdpath = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine first character of the next entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpGetBytesRemaining(cfVfp) <= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no bytes in contents file current char is NULL */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* grab path from first entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = vfpGetcNoInc(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save current position in file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pos = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * at the first character of the next entry in the contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if not absolute path check for exceptions and old style entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --> if end of contents file write out skipped data and return
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --> if comment character skip to end of line and restart loop
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --> else process "old style entry: ftype class path"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c != '/') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if NULL character then end of contents file found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland WRITEDATA(cfTmpVfp, firstPos, lastPos);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *vfpGetLastCharPtr(cfTmpVfp) = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* no more entries */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* ignore lines that begin with #, : or a "space" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((isspace(c) != 0) || (c == '#') || (c == ':')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* line is a comment */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * old style entry - format is:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * ftype class path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->ftype to the type
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->class to the class
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->path to point to lpath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set cpath_start/cpath_len to point to the file name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set rdpath to '1' to indicate old style entry parsed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (isspace((c = vfpGetc(cfVfp))))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?': case 'f': case 'v': case 'e': case 'l':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 's': case 'p': case 'c': case 'b': case 'd':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'x':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ftype = (char)c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save class */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getstr(&vfpGetCurrCharPtr(cfVfp), CLSSIZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->pkg_class, ISWORDSEP)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_CANNOT_READ_CLASS_TOKEN);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * locate file name up to "=", set cpath_start
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and cpath_len to point to the file name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cpath_start = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * skip past all bytes until first '= \t\n\0':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*p] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cpath_len = vfpGetCurrPtrDelta(cfVfp, p);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if the path is zero bytes, line is corrupted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (cpath_len < 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_CANNOT_READ_PATHNAME_FLD);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpIncCurrPtrBy(cfVfp, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set path to point to local path cache */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->path = lpath;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set flag indicating path already parsed */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rdpath = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* end of line before new-line seen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpDecCurrPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_INCOMPLETE_ENTRY);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '0': case '1': case '2': case '3': case '4':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '5': case '6': case '7': case '8': case '9':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* volume number seen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_VOLUMENO_UNEXPECTED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'i':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* type i files are not cataloged */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_FTYPE_I_UNEXPECTED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* unknown ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_UNKNOWN_FTYPE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * current entry DOES start with absolute path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set ept->path to point to lpath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set cpath_start/cpath_len to point to the file name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy first token into path element of passed structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cpath_start = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p = cpath_start;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * skip past all bytes until first from '= \t\n\0':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ISPKGPATHSEP[(int)*p] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cpath_len = vfpGetCurrPtrDelta(cfVfp, p);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpIncCurrPtrBy(cfVfp, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpGetcNoInc(cfVfp) == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_INCOMPLETE_ENTRY);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->path = lpath;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if absolute path then the path is collected and we are at the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * first byte following the absolute path name;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if not an absolute path then an old style entry, ept has been
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * filled with the type and class and path name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * determine if we have read the pathname which identifies
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the entry we are searching for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * =============================================================
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (anypath != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = 0; /* next entry is "equal to" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (path == (char *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = 1; /* next entry is "greater than" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = strncmp(path, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((n == 0) && (cpath_len != pathLength)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = cpath_len;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get first character following the end of the path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = vfpGetc(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if an exact match, always parse out the local path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we want to return information about this path in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the structure provided, so parse any local path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and jump to code which parses rest of the input line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == '=') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* parse local path specification */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getstr(&vfpGetCurrCharPtr(cfVfp), PATH_MAX,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland mylocal, ISWORDSEP)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_CANNOT_READ_LL_PATH);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.local = mylocal;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if an exact match and processing a new style entry, read the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remaining information from the new style entry - if this is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an old style entry (rdpath != 0) then the existing info has
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * already been processed as it exists before the pathname and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * not after like a new style entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0 && rdpath == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (isspace((c = vfpGetc(cfVfp))))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?': case 'f': case 'v': case 'e': case 'l':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 's': case 'p': case 'c': case 'b': case 'd':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'x':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ftype = (char)c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save class */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getstr(&vfpGetCurrCharPtr(cfVfp), CLSSIZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->pkg_class, ISWORDSEP)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_CANNOT_READ_CLASS_TOKEN);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break; /* we already read the pathname */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* end of line before new-line seen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpDecCurrPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_INCOMPLETE_ENTRY);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '0': case '1': case '2': case '3': case '4':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '5': case '6': case '7': case '8': case '9':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_VOLUMENO_UNEXPECTED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'i':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_FTYPE_I_UNEXPECTED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* unknown ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_UNKNOWN_FTYPE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if an exact match all processing is completed; break out of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the main processing loop and finish processing this entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * prior to returning to the caller.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this entry is not an exact match for the path being searched
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for - if this entry is GREATER THAN the path being searched
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for then finish processing and return GREATER THAN result
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to the caller so the entry for the path being searched for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * can be added to the contents file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the entry we want would fit BEFORE the one we just
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * read, so we need to unread what we've read by
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * seeking back to the start of this entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpSetCurrCharPtr(cfVfp, pos);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out any skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped && (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland WRITEDATA(cfTmpVfp, firstPos, lastPos);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (2); /* path would insert here */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This entry is "LESS THAN" the specified path to search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * need to process the next entry from the contents file. First,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if writing to new contents file, update new contents file if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * processing old style entry; otherwise, update skipped data
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information to remember current last byte of skipped data.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (cfTmpVfp != (VFP_T *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *px;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ssize_t len;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (rdpath != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* modify record: write out any skipped data */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland WRITEDATA(cfTmpVfp, firstPos, lastPos);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * copy what we've read and the rest of this
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * line onto the specified output stream
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutBytes(cfTmpVfp, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutc(cfTmpVfp, c);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutc(cfTmpVfp, ept->ftype);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutc(cfTmpVfp, ' ');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPuts(cfTmpVfp, ept->pkg_class);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland px = strchr(vfpGetCurrCharPtr(cfVfp), '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (px == (char *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland len = vfpGetBytesRemaining(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutBytes(cfTmpVfp,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpGetCurrCharPtr(cfVfp), len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutc(cfTmpVfp, '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpSeekToEnd(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland len = vfpGetCurrPtrDelta(cfVfp, px);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpPutBytes(cfTmpVfp,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpGetCurrCharPtr(cfVfp), len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpIncCurrPtrBy(cfVfp, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset skiped bytes if any data skipped */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland dataSkipped = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lastPos = (char *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland firstPos = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* skip data */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland dataSkipped = 1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland px = strchr(vfpGetCurrCharPtr(cfVfp), '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (px == (char *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpSeekToEnd(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland len = vfpGetCurrPtrDelta(cfVfp, px)+1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpIncCurrPtrBy(cfVfp, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lastPos = vfpGetCurrCharPtr(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * since this isn't the entry we want, just read the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * stream until we find the end of this entry and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * then start this search loop again
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *px;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland px = strchr(vfpGetCurrCharPtr(cfVfp), '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (px == (char *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpSeekToEnd(cfVfp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(pkg_gt(ERR_MISSING_NEWLINE));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ssize_t len;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland len = vfpGetCurrPtrDelta(cfVfp, px)+1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vfpIncCurrPtrBy(cfVfp, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * end of main loop processing entries from contents file
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the loop is broken out of when an exact match for the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path being searched for has been found and the type is one of:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - ?fvelspcbdx
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * at this point parsing is at the first character past the full path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * name on an exact match for the path being looked for - parse the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remainder of the entries information into the ept structure.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* link/symbolic link must have link destination */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (((ept->ftype == 's') || (ept->ftype == 'l')) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ainfo.local == NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_NO_LINK_SOURCE_SPECIFIED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* character/block devices have major/minor device numbers */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (((ept->ftype == 'c') || (ept->ftype == 'b'))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.major = BADMAJOR;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.minor = BADMINOR;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (long *)&ept->ainfo.major, BADMAJOR) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (long *)&ept->ainfo.minor, BADMINOR)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(pkg_gt(ERR_CANNOT_READ_MM_NUMS));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* most types have mode, owner, group identification components */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((ept->ftype == 'd') || (ept->ftype == 'x') || (ept->ftype == 'c') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'b') || (ept->ftype == 'p') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'f') || (ept->ftype == 'v') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'e')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* mode, owner, group should be here */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getnumvfp(&vfpGetCurrCharPtr(cfVfp), 8,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (long *)&ept->ainfo.mode, BADMODE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getstr(&vfpGetCurrCharPtr(cfVfp), sizeof (ept->ainfo.owner),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.owner, ISWORDSEP) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getstr(&vfpGetCurrCharPtr(cfVfp), sizeof (ept->ainfo.group),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->ainfo.group, ISWORDSEP)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_CANNOT_READ_MOG);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* i/f/v/e have size, checksum, modification time components */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((ept->ftype == 'i') || (ept->ftype == 'f') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (ept->ftype == 'v') || (ept->ftype == 'e')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* look for content description */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getlnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (fsblkcnt_t *)&ept->cinfo.size, BADCONT) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (long *)&ept->cinfo.cksum, BADCONT) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland getnumvfp(&vfpGetCurrCharPtr(cfVfp), 10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (long *)&ept->cinfo.modtime, BADCONT)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_CANNOT_READ_CONTENT_INFO);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* i files processing is completed - return 'exact match found' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ept->ftype == 'i') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getend(&vfpGetCurrCharPtr(cfVfp))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_EXTRA_TOKENS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out any skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped && (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland WRITEDATA(cfTmpVfp, firstPos, lastPos);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * determine list of packages which reference this entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lastpinfo = (struct pinfo *)NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getstr(&vfpGetCurrCharPtr(cfVfp), sizeof (pkgname),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pkgname, ISPKGNAMESEP)) <= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if c < 0 the string was too long to fix in the buffer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_PACKAGE_NAME_TOO_LONG);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* a package is present - create and populate pinfo structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pinfo = (struct pinfo *)calloc(1, sizeof (struct pinfo));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!pinfo) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_NO_MEMORY);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!lastpinfo) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->pinfo = pinfo; /* first one */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lastpinfo->next = pinfo; /* link list */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland lastpinfo = pinfo;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((pkgname[0] == '-') || (pkgname[0] == '+') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (pkgname[0] == '*') || (pkgname[0] == '~') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (pkgname[0] == '!') || (pkgname[0] == '%')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pinfo->status = pkgname[0];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(pinfo->pkg, pkgname+1,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (pinfo->pkg));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(pinfo->pkg, pkgname,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (pinfo->pkg));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* pkg/[:[ftype][:class] */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = (vfpGetc(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == '\\') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get alternate ftype */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pinfo->editflag++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = (vfpGetc(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == ':') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get special classname */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) getstr(&vfpGetCurrCharPtr(cfVfp),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (classname), classname, ISWORDSEP);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcpy(pinfo->aclass, classname,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (pinfo->aclass));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = (vfpGetc(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ept->npkgs++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* break out of while if at end of entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((c == '\n') || (c == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if package not separated by a space return an error */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!isspace(c)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_BAD_ENTRY_END);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland findend(&vfpGetCurrCharPtr(cfVfp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * parsing of the entry is complete
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* copy path found to 'lpath' */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland COPYPATH(lpath, cpath_start, cpath_len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out any skipped data before returning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dataSkipped && (cfTmpVfp != (VFP_T *)NULL)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland WRITEDATA(cfTmpVfp, firstPos, lastPos);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if not at the end of the entry, make it so */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((c != '\n') && (c != '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getend(&vfpGetCurrCharPtr(cfVfp)) && ept->pinfo) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setErrstr(ERR_EXTRA_TOKENS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandgetstr(char **cp, int n, char *str, int separator[])
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p = *cp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t len;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*p == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* leading white space ignored */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (((c = *p) != '\0') && (isspace(*p++)))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((c == '\0') || (c == '\n')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (1); /* nothing there */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compute length based on delimiter found or not */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p1 = p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (separator[(int)*p1] == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p1++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland len = (ptrdiff_t)p1 - (ptrdiff_t)p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if string will fit in result buffer copy string and return success */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (len < n) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) memcpy(str, p, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland str[len] = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p += len;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* result buffer too small; copy partial string, return error */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) memcpy(str, p, n-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland str[n-1] = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p += n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (-1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandgetend(char **cp)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p = *cp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if at end of buffer return no more characters left */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*p == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((*p != '\0') && (*p != '\n')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!isspace(*p)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = ++p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (n);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandfindend(char **cp)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p = *cp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if at end of buffer return no more characters left */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*p == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find the end of the line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p1 = strchr(p, '\n');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (p1 != (char *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = ++p1;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = strchr(p, '\0');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}