dir.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* cscope - interactive C symbol cross-reference
*
* directory searching functions
*/
#include "global.h"
#include "dirent.h"
#include "vp.h" /* vpdirs and vpndirs */
/* largest known database had 22049 files */
char **incdirs; /* #include directories */
char **srcdirs; /* source directories */
char **srcfiles; /* source files */
int nincdirs; /* number of #include directories */
int nsrcdirs; /* number of source directories */
int nsrcfiles; /* number of source files */
static struct listitem { /* source file table entry */
char *file;
} *srcfiletable[HASHMOD];
/* add a source directory to the list for each view path source directory */
void
{
struct stat statstruct;
char *dir;
/* don't change environment variable text */
/* parse the directory list */
/*
* make sure it is a directory (must exist in current
* view path node)
*/
msrcdirs * sizeof (char *));
}
}
}
}
/* add a #include directory to the list for each view path source directory */
void
includedir(char *dirlist)
{
struct stat statstruct;
char *dir;
/* don't change environment variable text */
/* parse the directory list */
/*
* make sure it is a directory (must exist in current
* view path node)
*/
mincdirs * sizeof (char *));
}
}
}
}
/* make the source file list */
void
makefilelist(void)
{
struct stat statstruct;
char *file;
char *s;
int i, j;
/* if there are source file arguments */
if (fileargc > 0) {
/* put them in a list that can be expanded */
for (i = 0; i < fileargc; ++i) {
} else {
"cscope: cannot find file %s\n",
file);
errorsfound = YES;
}
}
}
return;
}
/* see if a file name file exists */
}
/* if there is a file of source file names */
myexit(1);
}
/* get the names in the file */
i = path[1];
switch (i) {
case 'q': /* quick search */
invertedindex = YES;
break;
case 'T':
/* truncate symbols to 8 characters */
truncatesyms = YES;
break;
case 'I': /* #include file directory */
case 'p': /* file path components to */
/* display */
if (*s == '\0') { /* if "-I path" */
"%s", path);
s = path;
}
switch (i) {
case 'I': /* #include file directory */
if (firstbuild == YES) {
/* expand $ and ~ */
sizeof (dir), s);
}
break;
case 'p':
/* file path components */
/* to display */
if (*s < '0' || *s > '9') {
"cscope: -p option "
"in file %s: "
"missing or "
"invalid numeric "
"value\n",
namefile);
}
dispcomponents = atoi(s);
break;
}
break;
default:
"cscope: only -I, -p, and -T "
"options can be in file %s\n",
namefile);
}
} else {
"cscope: cannot find file %s\n",
path);
errorsfound = YES;
}
}
firstbuild = NO;
return;
}
/* make a list of all the source files in the directories */
for (i = 0; i < nsrcdirs; ++i) {
s = srcdirs[i];
getsrcfiles(s, s);
if (*s != '/') { /* if it isn't a full path name */
/* compute its path from any higher view path nodes */
for (j = 1; j < vpndirs; ++j) {
/* make sure it is a directory */
getsrcfiles(dir, s);
}
}
}
}
}
/* get the source file names in this directory */
static void
{
/* attempt to open the directory */
/* read each entry in the directory */
/* if it is a source file not already found */
}
}
}
}
/* see if this is a source file */
static BOOL
{
struct stat statstruct;
char *s;
/* if there is a file suffix */
/* if an SCCS or versioned file */
switch (*file) {
case 's':
case 'S':
return (NO);
}
}
if (s[1] == '\0') { /* 1 character suffix */
switch (*s) {
case 'c':
case 'h':
case 'l':
case 'y':
case 'C':
case 'G':
case 'H':
case 'L':
return (YES);
}
} else if (s[2] == '\0') { /* 2 character suffix */
if (*s == 'b' && s[1] == 'p' || /* breakpoint listing */
*s == 'q' &&
(s[1] == 'c' || s[1] == 'h') || /* Ingres */
*s == 'p' && s[1] == 'r' || /* SDL */
*s == 's' && s[1] == 'd') { /* SDL */
/*
* some directories have 2 character
* suffixes so make sure it is a file
*/
return (YES);
}
}
}
}
return (NO);
}
/* add an include file to the source file list */
void
{
int i;
/* see if the file is already in the source file list */
return;
}
/* look in current directory if it was #include "file" */
} else {
/* search for the file in the #include directory list */
for (i = 0; i < nincdirs; ++i) {
/* don't include the file from two directories */
break;
}
/* make sure it exists and is readable */
break;
}
}
}
}
/* see if the file is already in the list */
infilelist(char *file)
{
struct listitem *p;
return (YES);
}
}
return (NO);
}
/* add a source file to the list */
void
addsrcfile(char *path)
{
struct listitem *p;
int i;
/* make sure there is room for the file */
}
/* add the file to the list */
p->next = srcfiletable[i];
srcfiletable[i] = p;
}
/* free the memory allocated for the source file list */
void
freefilelist(void)
{
int i;
while (nsrcfiles > 0) {
}
for (i = 0; i < HASHMOD; ++i) {
free(p);
}
srcfiletable[i] = NULL;
}
}