revert between 56095 -> 55830 in arch
[AROS.git] / tools / cxref / query / query.c
blobebff2ea49a3e18669b59502aee5c111b409221af
1 /***************************************
2 $Header$
4 C Cross Referencing & Documentation tool. Version 1.4.
5 ******************/ /******************
6 Written by Andrew M. Bishop
8 This file Copyright 1995,96 Andrew M. Bishop
9 It may be distributed under the GNU Public License, version 2, or
10 any higher version. See section COPYING of the GNU Public license
11 for conditions under which this file may be redistributed.
12 ***************************************/
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "../memory.h"
19 #include "../datatype.h"
20 #include "../cxref.h"
21 #include "query.h"
23 /*+ The command line switch that sets the amount of cross referencing to do. +*/
24 int option_xref=0;
26 /*+ The command line switch for the output name, +*/
27 char *option_odir=".", /*+ The directory to use. +*/
28 *option_name="cxref"; /*+ The base part of the name. +*/
30 File *files=NULL; /*+ The files that are queried. +*/
31 int n_files=0; /*+ The number of files referenced. +*/
33 Function *functions=NULL; /*+ The functions that are queried. +*/
34 int n_functions=0; /*+ The number of functions referenced. +*/
36 Variable *variables=NULL; /*+ The variables that are queried. +*/
37 int n_variables=0; /*+ The number of variables referenced. +*/
39 Typedef *typedefs=NULL; /*+ The type definitions that are queried. +*/
40 int n_typedefs=0; /*+ The number of typedefs referenced. +*/
43 /*++++++++++++++++++++++++++++++++++++++
44 The main function that does it all.
46 int main Returns the status, zero for normal termination, else an error.
48 int argc The command line number of arguments.
50 char** argv The actual command line arguments
51 ++++++++++++++++++++++++++++++++++++++*/
53 int main(int argc,char** argv)
55 int i,args=0;
57 if(argc==1)
59 fputs("Usage: cxref-query [name [ ... name]] ; Names of objects to query.\n"
60 " [-Odirname] ; Use dirname as the input directory\n"
61 " [-Nbasename] ; Use basename.* as the input filenames\n"
62 " [-xref[-all][-file][-func][-var][-type]] ; Use cross reference files (default -xref-all).\n"
63 ,stderr);
64 exit(1);
67 for(i=1;i<argc;i++)
69 if(!strncmp(argv[i],"-O",2))
71 if(argv[i][2]==0)
73 argv[i++]=NULL;
74 if(i==argc)
75 {fprintf(stderr,"cxref-query: The -O option requires a following argument.\n");return(1);}
76 option_odir=argv[i];
78 else
79 option_odir=&argv[i][2];
80 argv[i]=NULL;
81 continue;
84 if(!strncmp(argv[i],"-N",2))
86 if(argv[i][2]==0)
88 argv[i++]=NULL;
89 if(i==argc)
90 {fprintf(stderr,"cxref-query: The -N option requires a following argument.\n");return(1);}
91 option_name=argv[i];
93 else
94 option_name=&argv[i][2];
95 argv[i]=NULL;
96 continue;
99 if(!strncmp(argv[i],"-xref",5))
101 char* p=&argv[i][5];
103 if(!*p)
104 option_xref=XREF_ALL;
105 else
106 while(*p)
108 if(!strncmp(p,"-all" ,4)) {option_xref|=XREF_ALL ; p=&p[4]; continue;}
109 if(!strncmp(p,"-file",5)) {option_xref|=XREF_FILE; p=&p[5]; continue;}
110 if(!strncmp(p,"-func",5)) {option_xref|=XREF_FUNC; p=&p[5]; continue;}
111 if(!strncmp(p,"-var" ,4)) {option_xref|=XREF_VAR ; p=&p[4]; continue;}
112 if(!strncmp(p,"-type",5)) {option_xref|=XREF_TYPE; p=&p[5]; continue;}
113 break;
115 argv[i]=NULL;continue;
118 args++;
119 if(!strncmp(argv[i],"./",2))
120 argv[i]+=2;
123 LoadInCrossRefs();
125 if(args)
127 for(i=1;i<argc;i++)
128 if(argv[i])
130 printf("cxref-query> %s\n\n",argv[i]);
131 OutputCrossRef(argv[i]);
134 else
136 while(1)
138 char input[128];
139 printf("cxref-query> ");
140 if(!fgets(input,128,stdin))
141 {printf("\n\n");break;}
143 printf("\n");
144 input[strlen(input)-1]=0;
145 OutputCrossRef(input);
149 PrintMemoryStatistics();
151 return(0);