some work
[svn/Cll1h/.git] / demos / idmap.c
... / ...
CommitLineData
1#include "cll1.h"
2
3struct Line
4{
5 int n;
6 list(Line);
7} *line;
8
9struct Id
10{
11 char *str;
12 int count;
13 struct Line *lines;
14 list(Id);
15} *id,*ids=NULL;
16
17program
18{
19 char *ptr;
20 char *fname;
21 char *c=NULL;
22 int l=0;
23
24 arguments
25 {
26 thisargument(fname);
27 nextargument(c);
28 }
29 else
30 {
31 puts("Usage: idmap file [c]");
32 return 1;
33 }
34
35 parse(fname)
36 {
37 l++;
38 while(*_)
39 {
40 goto_alpha(_);
41 ptr=_;
42 skip_alnum(_);
43 *_=0;
44 _++;
45
46 if(*ptr)
47 {
48 if_exists(id,ids,eq(id->str,ptr))
49 {
50 id->count++;
51 if_exists(line,id->lines,line->n==l);
52 else
53 {
54 create(line,Line);
55 line->n=l;
56 push(line,id->lines);
57 }
58 }
59 else
60 {
61 create(id,Id);
62 create(line,Line);
63 id->str=ptr;
64 id->count=1;
65 id->lines=line;
66 line->n=l;
67 insert(id,ids,sort_by,str);
68 }
69 }
70 if(*_=='"' || *_=='\'' )
71 {
72 char c=*_;
73 _++;
74 gotochr(_,c);
75 }
76 }
77 }
78 fail
79 {
80 perror(argv[1]);
81 exit(-1);
82 }
83 done;
84
85 if(c)
86 sort(id,ids,desc_order_by,count);
87
88 for_each(id,ids)
89 {
90 printf("%3dx %s",id->count,id->str);
91 for_each(line,id->lines) printf(" [%d]",line->n);
92 printf("\n");
93 }
94}
This page took 0.529999 seconds and 4 git commands to generate.