8 printf("Clear text from lib.ru for Pocket PC, Version 0.2.\n");
9 printf("Author: Teodor Sigaev <teodor@sigaev.ru>\n");
10 printf("Usage:\n clrlibru [-i INPUTFILE] [-o OUTPUT] [-l NUMSPACE]\n");
24 is_rtag(char *tag, int len) {
29 if ( strcmp(tag, *ptr) == 0 )
37 static char *optarg = NULL;
41 mgetopt(int argn, char* argv[], char *option) {
44 if ( current >= argn ) return -1;
46 key = *(argv[current]+1);
47 if ( *(argv[current]) == '-' || *(argv[current]) == '/' ) {
48 char *ptr = strchr( option, key );
50 printf( "Unknown option: %s\n", argv[current]);
54 if ( *(ptr+1) == ':' ) {
59 printf("No value for -%c\n" ,key);
65 printf("Unknown option: %s\n", argv[current]);
77 #define INDROPINCLSTAG 6
81 main(int argn, char *argv[]) {
83 FILE *in=stdin, *out=stdout;
86 int lenbuf=0,closelen=0;
89 while((ch = mgetopt(argn, argv, "l:i:o:h?"))!=-1) {
92 if ( (in=fopen(optarg, "r"))==NULL) {
93 printf("Can't open file %s\n", optarg);
98 if ( (out=fopen(optarg, "w"))==NULL) {
99 printf("Can't open file %s\n",optarg);
104 spacelen = atoi(optarg);
105 if ( spacelen < 0 ) {
106 printf("-l should be >= 0\n");
117 while( (ch=getc(in)) != EOF ) {
118 if ( state==INTXT ) {
122 } else if ( ch == '\n' ) {
126 } else if ( ch != '\r' )
128 } else if ( state==INHEADTAG ) {
130 buf[ lenbuf ] = tolower(ch);
132 } else if ( ch == '>' ) {
133 if ( is_rtag(buf,lenbuf) ) {
140 } else if ( lenbuf == 0 && ch != '/' ) {
141 fputc('<',out); fputc(ch,out);
144 if ( is_rtag(buf,lenbuf) ) {
152 } else if ( state==INTAG ) {
157 } else if ( state == INDROPTAG ) {
162 } else if ( state == INDROPINTAG ) {
164 state=INDROPINCLSTAG;
167 } else if ( state == INDROPINCLSTAG ) {
169 if ( closelen < lenbuf && tolower(ch) == buf[closelen] ) {
171 if ( closelen==lenbuf )
177 } else if ( state==FINDEND ) {
181 if ( lenbuf > spacelen ) {
182 fwrite(buf, sizeof(char), lenbuf, out);
185 } else if ( ch=='\n' ) {
188 fwrite(buf, sizeof(char), lenbuf, out);
190 } else if ( ch !='\r' ) {
196 printf("Unknown state: %d\n", state);