11f5207b7SJohn Levon /*
21f5207b7SJohn Levon  * Example trivial client program that uses the sparse library
31f5207b7SJohn Levon  * to tokenize, preprocess and parse a C file, and prints out
41f5207b7SJohn Levon  * the results.
51f5207b7SJohn Levon  *
61f5207b7SJohn Levon  * Copyright (C) 2003 Transmeta Corp.
71f5207b7SJohn Levon  *               2003-2004 Linus Torvalds
81f5207b7SJohn Levon  *
91f5207b7SJohn Levon  * Permission is hereby granted, free of charge, to any person obtaining a copy
101f5207b7SJohn Levon  * of this software and associated documentation files (the "Software"), to deal
111f5207b7SJohn Levon  * in the Software without restriction, including without limitation the rights
121f5207b7SJohn Levon  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
131f5207b7SJohn Levon  * copies of the Software, and to permit persons to whom the Software is
141f5207b7SJohn Levon  * furnished to do so, subject to the following conditions:
151f5207b7SJohn Levon  *
161f5207b7SJohn Levon  * The above copyright notice and this permission notice shall be included in
171f5207b7SJohn Levon  * all copies or substantial portions of the Software.
181f5207b7SJohn Levon  *
191f5207b7SJohn Levon  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
201f5207b7SJohn Levon  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
211f5207b7SJohn Levon  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
221f5207b7SJohn Levon  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
231f5207b7SJohn Levon  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
241f5207b7SJohn Levon  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
251f5207b7SJohn Levon  * THE SOFTWARE.
261f5207b7SJohn Levon  */
271f5207b7SJohn Levon #include <stdarg.h>
281f5207b7SJohn Levon #include <stdlib.h>
291f5207b7SJohn Levon #include <stdio.h>
301f5207b7SJohn Levon #include <string.h>
311f5207b7SJohn Levon #include <ctype.h>
321f5207b7SJohn Levon #include <unistd.h>
331f5207b7SJohn Levon #include <fcntl.h>
341f5207b7SJohn Levon 
351f5207b7SJohn Levon #include "lib.h"
361f5207b7SJohn Levon #include "allocate.h"
371f5207b7SJohn Levon #include "token.h"
381f5207b7SJohn Levon #include "parse.h"
391f5207b7SJohn Levon #include "symbol.h"
401f5207b7SJohn Levon #include "expression.h"
411f5207b7SJohn Levon #include "linearize.h"
421f5207b7SJohn Levon 
emit_entrypoint(struct entrypoint * ep)431f5207b7SJohn Levon static void emit_entrypoint(struct entrypoint *ep)
441f5207b7SJohn Levon {
451f5207b7SJohn Levon 
461f5207b7SJohn Levon }
471f5207b7SJohn Levon 
emit_symbol(struct symbol * sym)481f5207b7SJohn Levon static void emit_symbol(struct symbol *sym)
491f5207b7SJohn Levon {
501f5207b7SJohn Levon 	struct entrypoint *ep;
511f5207b7SJohn Levon 	ep = linearize_symbol(sym);
521f5207b7SJohn Levon 	if (ep)
531f5207b7SJohn Levon 		emit_entrypoint(ep);
541f5207b7SJohn Levon }
551f5207b7SJohn Levon 
emit_symbol_list(struct symbol_list * list)561f5207b7SJohn Levon static void emit_symbol_list(struct symbol_list *list)
571f5207b7SJohn Levon {
581f5207b7SJohn Levon 	struct symbol *sym;
591f5207b7SJohn Levon 
601f5207b7SJohn Levon 	FOR_EACH_PTR(list, sym) {
611f5207b7SJohn Levon 		expand_symbol(sym);
621f5207b7SJohn Levon 		emit_symbol(sym);
631f5207b7SJohn Levon 	} END_FOR_EACH_PTR(sym);
641f5207b7SJohn Levon }
651f5207b7SJohn Levon 
main(int argc,char ** argv)661f5207b7SJohn Levon int main(int argc, char **argv)
671f5207b7SJohn Levon {
681f5207b7SJohn Levon 	struct string_list *filelist = NULL;
691f5207b7SJohn Levon 	char *file;
701f5207b7SJohn Levon 
711f5207b7SJohn Levon 	emit_symbol_list(sparse_initialize(argc, argv, &filelist));
72*c85f09ccSJohn Levon 	FOR_EACH_PTR(filelist, file) {
731f5207b7SJohn Levon 		emit_symbol_list(sparse(file));
74*c85f09ccSJohn Levon 	} END_FOR_EACH_PTR(file);
751f5207b7SJohn Levon 	return 0;
761f5207b7SJohn Levon }
77