[5f4d9c3] | 1 | |
---|
| 2 | /** |
---|
| 3 | * Package: UAM Text Tools |
---|
| 4 | * Component: dgp (dg parser) |
---|
| 5 | * Version: 1.0 |
---|
| 6 | * Author: Tomasz Obrebski |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "global.hh" |
---|
| 10 | #include "mgraph.hh" |
---|
| 11 | #include "sgraph.hh" |
---|
| 12 | #include "grammar.hh" |
---|
| 13 | #include "dgp0.hh" |
---|
| 14 | #include "../common/common.h" |
---|
| 15 | #include "cmdline.h" |
---|
| 16 | |
---|
| 17 | #define MAXSEGMENTS 500 |
---|
| 18 | |
---|
| 19 | char segment[MAXSEGMENTS][MAXLINE]; |
---|
| 20 | int segcount=0; |
---|
| 21 | char seg_mnode[MAXSEGMENTS]; |
---|
| 22 | char grammarfile[255]; |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | Grammar grammar; |
---|
| 26 | MGraph mgraph; |
---|
| 27 | SGraph sgraph; |
---|
| 28 | |
---|
| 29 | FILE* grammarf; |
---|
| 30 | FILE* debugf=stdout; |
---|
| 31 | unsigned int info=0U; |
---|
| 32 | |
---|
| 33 | void output(); |
---|
| 34 | |
---|
| 35 | main(int argc, char* argv[]) |
---|
| 36 | { |
---|
| 37 | gengetopt_args_info args; |
---|
| 38 | |
---|
| 39 | if(cmdline_parser(argc,argv,&args) != 0) |
---|
| 40 | exit(1); |
---|
| 41 | |
---|
| 42 | process_config_files(&args,argv[0]); |
---|
| 43 | process_common_options(&args,argv[0]); |
---|
| 44 | |
---|
| 45 | if(!args.grammar_given) |
---|
| 46 | fprintf(stderr,"dgp: no grammar given\n"); |
---|
| 47 | |
---|
| 48 | expand_path(args.grammar_arg,grammarfile); |
---|
| 49 | |
---|
| 50 | if(!(grammarf=fopen(grammarfile,"r"))) |
---|
| 51 | fprintf(stderr,"dgp: grammar file not found: %s.\n", grammarfile), exit(1); |
---|
| 52 | |
---|
| 53 | if(args.debug_given) debug=true; |
---|
| 54 | |
---|
| 55 | for(char* c=args.info_arg; *c!='\0' ; ++c) |
---|
| 56 | switch(*c) |
---|
| 57 | { |
---|
| 58 | case 'h': info|=SGraph::HEADS; break; |
---|
| 59 | case 'd': info|=SGraph::DEPS; break; |
---|
| 60 | case 's': info|=SGraph::SETS; break; |
---|
| 61 | case 'c': info|=SGraph::CONSTRAINTS; break; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | grammar.read(grammarf); |
---|
| 65 | fclose(grammarf); |
---|
| 66 | |
---|
| 67 | mgraph.clear(); |
---|
| 68 | sgraph.clear(); |
---|
| 69 | |
---|
| 70 | char line[1000]; |
---|
| 71 | while (fgets(line, MAXLINE+1, inputf)) |
---|
| 72 | { |
---|
| 73 | line[strlen(line)-1] = '\0'; |
---|
| 74 | strcpy(segment[segcount],line); |
---|
| 75 | |
---|
| 76 | char segtype[80]; |
---|
| 77 | |
---|
| 78 | seg_mnode[segcount] = process_seg(line, args) ? mgraph.add_node(line) : -1; |
---|
| 79 | |
---|
| 80 | segcount++; |
---|
| 81 | |
---|
| 82 | getfield(line,"3",segtype); |
---|
| 83 | if(strcmp(segtype,"EOS")==0) |
---|
| 84 | { |
---|
| 85 | dgp0(); // parametry!!! MGraph, SGraph, Grammar |
---|
| 86 | output(); |
---|
| 87 | |
---|
| 88 | mgraph.clear(); |
---|
| 89 | sgraph.clear(); |
---|
| 90 | segcount=0; |
---|
| 91 | } |
---|
| 92 | // if(args.interactive_flag) { fflush(outputf); fflush(failedf); } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | fclose(inputf); |
---|
| 96 | fclose(outputf); |
---|
| 97 | cmdline_parser_free(&args); |
---|
| 98 | exit(0); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void output() |
---|
| 102 | { |
---|
| 103 | for(int si=0; si<segcount; ++si) |
---|
| 104 | { |
---|
| 105 | if(seg_mnode[si]>=0) |
---|
| 106 | { |
---|
| 107 | MNode& m=mgraph.nodes[seg_mnode[si]]; |
---|
| 108 | for(vector<int>::iterator s=m.snodes.begin(); s!=m.snodes.end(); ++s) |
---|
| 109 | { |
---|
| 110 | fputs(segment[si],outputf); |
---|
| 111 | sgraph.print_node(outputf, *s, info); |
---|
| 112 | fputc('\n',outputf); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | fputs(segment[si],outputf); |
---|
| 118 | fputc('\n',outputf); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|