1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/***************************************
$Header: /home/amb/CVS/cxref/query/query.c,v 1.5 2004-06-22 17:31:30 amb Exp $
C Cross Referencing & Documentation tool. Version 1.6.
******************/ /******************
Written by Andrew M. Bishop
This file Copyright 1995,96,2004 Andrew M. Bishop
It may be distributed under the GNU Public License, version 2, or
any higher version. See section COPYING of the GNU Public license
for conditions under which this file may be redistributed.
***************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "memory.h"
#include "datatype.h"
#include "cxref.h"
#include "query.h"
/*+ The command line switch that sets the amount of cross referencing to do. +*/
int option_xref=0;
/*+ The command line switch for the output name, +*/
char *option_odir=".", /*+ The directory to use. +*/
*option_name="cxref"; /*+ The base part of the name. +*/
File *files=NULL; /*+ The files that are queried. +*/
int n_files=0; /*+ The number of files referenced. +*/
Function *functions=NULL; /*+ The functions that are queried. +*/
int n_functions=0; /*+ The number of functions referenced. +*/
Variable *variables=NULL; /*+ The variables that are queried. +*/
int n_variables=0; /*+ The number of variables referenced. +*/
Typedef *typedefs=NULL; /*+ The type definitions that are queried. +*/
int n_typedefs=0; /*+ The number of typedefs referenced. +*/
/*++++++++++++++++++++++++++++++++++++++
The main function that does it all.
int main Returns the status, zero for normal termination, else an error.
int argc The command line number of arguments.
char** argv The actual command line arguments
++++++++++++++++++++++++++++++++++++++*/
int main(int argc,char** argv)
{
int i,args=0;
if(argc==1)
{
fputs("Usage: cxref-query [name [ ... name]] ; Names of objects to query.\n"
" [-Odirname] ; Use dirname as the input directory\n"
" [-Nbasename] ; Use basename.* as the input filenames\n"
" [-xref[-all][-file][-func][-var][-type]] ; Use cross reference files (default -xref-all).\n"
,stderr);
exit(1);
}
for(i=1;i<argc;i++)
{
if(!strncmp(argv[i],"-O",2))
{
if(argv[i][2]==0)
{
argv[i++]=NULL;
if(i==argc)
{fprintf(stderr,"cxref-query: The -O option requires a following argument.\n");return(1);}
option_odir=argv[i];
}
else
option_odir=&argv[i][2];
argv[i]=NULL;
continue;
}
if(!strncmp(argv[i],"-N",2))
{
if(argv[i][2]==0)
{
argv[i++]=NULL;
if(i==argc)
{fprintf(stderr,"cxref-query: The -N option requires a following argument.\n");return(1);}
option_name=argv[i];
}
else
option_name=&argv[i][2];
argv[i]=NULL;
continue;
}
if(!strncmp(argv[i],"-xref",5))
{
char* p=&argv[i][5];
if(!*p)
option_xref=XREF_ALL;
else
while(*p)
{
if(!strncmp(p,"-all" ,4)) {option_xref|=XREF_ALL ; p=&p[4]; continue;}
if(!strncmp(p,"-file",5)) {option_xref|=XREF_FILE; p=&p[5]; continue;}
if(!strncmp(p,"-func",5)) {option_xref|=XREF_FUNC; p=&p[5]; continue;}
if(!strncmp(p,"-var" ,4)) {option_xref|=XREF_VAR ; p=&p[4]; continue;}
if(!strncmp(p,"-type",5)) {option_xref|=XREF_TYPE; p=&p[5]; continue;}
break;
}
argv[i]=NULL;continue;
}
args++;
if(!strncmp(argv[i],"./",2))
argv[i]+=2;
}
LoadInCrossRefs();
if(args)
{
for(i=1;i<argc;i++)
if(argv[i])
{
printf("cxref-query> %s\n\n",argv[i]);
OutputCrossRef(argv[i]);
}
}
else
{
while(1)
{
char input[128];
printf("cxref-query> ");
if(!fgets(input,128,stdin))
{printf("\n\n");break;}
printf("\n");
input[strlen(input)-1]=0;
OutputCrossRef(input);
}
}
PrintMemoryStatistics();
return(0);
}
|