filter.c

#ifndef STDIO #include #define STDIO #endif #ifndef CONSTANTEN #include "constanten.c" #endif #ifndef BEZEICHNER #include "bezeichner.c" #endif #ifndef WERT #include "wert.c" #endif int umlaute(char c, int *f) { switch(c) { case '{' : if(*f==0) { *f=1;} else *f=0; return(0); break; case '\\': if(*f==1) { *f=2;} else *f=0; return(0); break; case '}' : if(*f>3) { *f=0; return(1); } else { *f=0; return(0); } break; case '"' : if(*f==2) { *f=3;} else *f=0; return(0); break; case 'a' : if(*f==3) { *f=4;} else *f=0; return(0); break; case 'A' : if(*f==3) { *f=5;} else *f=0; return(0); break; case 'o' : if(*f==3) { *f=6;} else *f=0; return(0); break; case 'O' : if(*f==3) { *f=7;} else *f=0; return(0); break; case 'u' : if(*f==3) { *f=8;} else *f=0; return(0); break; case 'U' : if(*f==3) { *f=9;} else *f=0; return(0); break; case 's' : if(*f==3) {*f=10;} else *f=0; return(0); break; default : *f=0; return(0); break; } } void new_format ( int art, int flag, int format, char *line) { int i = 0; int j = 0; int f = 0; char w[max_len]; /* Vorsetze eines Leer-Zeichens innerhalb eines Attributwertes */ if((flag == 7) || ((flag == 9) && (format == 9))) { w[i]=' '; ++i; ++j; } /* bei Format "...," im Zustand 9 und 8 muss '"' vor das Wort gestellt werden */ w[i]='"'; if((flag == 8) || ((flag == 9) && (format == 11))) { ++i; ++j; } /* Zeile copieren */ for( ; ( i < max_len ) && ( *(line+(i-j)) != '\0'); ++i) { if((umlaute( *(line+(i-j)), &f)) && (art == 3)) { i=i-4; j=j+4; switch(f) { case 4: w[i]=ae; break; case 5: w[i]=AE; break; case 6: w[i]=oe; break; case 7: w[i]=OE; break; case 8: w[i]=ue; break; case 9: w[i]=UE; break; default: w[i]=Ss; break; } } else w[i]=*(line+(i-j)); } /* Ausblenden von ',' am Ende bei "...," */ w[((((( flag == 9 ) || (flag == 8)) && (i>0) && (w[i-1] == ','))) || ((flag == 2) && ( format == 5)) ? (i-1) : (i))]='\0'; /* Anhaengen von '"' am Ende bei "...," */ if((flag == 8) || ((flag == 9) && (format == 11))) strcat(w, "\""); /* Anhaengen des des PIPE bei Ende des aktuellen Attributes */ if(((flag == 8) || (flag == 9)) && (format !=2)) strcat( w, PIPE); /* Ausgabe */ switch(flag) { case 0 : if(art > 1) fprintf( stdout, "\n", flag, format, w ); break; case 1 : /* fprintf( ofp, "", flag, format, w ); */ break; case 3 : /* fprintf( ofp, "", flag, format, w ); */ break; case 2 : set_attribut(incert_bez(w)); break; case 4 : if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s", w); */ incert_wert(w); } break; case 5 : if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s", w); */ incert_wert(w); break; } break; case 6 : if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s", w); */ incert_wert(w); break; } break; case 7 : if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s" , w); */ incert_wert(w); break; } break; case 8 : if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s", w); */ incert_wert(w); break; } break; case 9 : if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s", w); */ incert_wert(w); break; } break; case 10: if(( art == 2 ) || ( art == 3 )) { /* fprintf( ofp, "%s", w); */ incert_wert(w); break; } break; } } int line_format( char *l) { int last; last=(((last=strlen(l))>0) ? last-1 : 0); /* "@...{" --> 1 */ if(( l[first] == '@') && ( l[last] == '{')) { return(1);} else { /* "}" --> 2 */ if(( l[first] == '}') && ( l[last] == '}')) { return(2);} else { /* "," --> 3 */ if(( l[first] == ',') && ( l[last] == ',')) { return(3);} else { /* "=" --> 4 */ if(( l[first] == '=') && ( l[last] == '=')) { return(4);} else { /* "...=..." --> 5 */ if((last >= 15) && ( l[15] == '=')) { /* strcat( k, l); */ return(5); } else { /* ""..."," --> 6 */ if(( last > 0 ) && ( l[first] == '"') && ( l[last] == ',') && ( l[last-1] == '"')) { return(6);} else { /* ""..."" --> 7 */ if(( last > 0) && ( l[first] == '"') && ( l[last] == '"')) { return(7);} else { /* ""..." --> 8 */ if( l[first] == '"') { return(8);} else { /* "..."," --> 9 */ if(( last > 0 ) && ( l[last] == ',') && ( l[last-1] == '"')) { return(9);} else { /* "..."" --> 10 */ if( l[last] == '"') { return(10);} else { /* "...," --> 11 */ if( l[last] == ',') { return(11);} else { /* "..." --> 0 */ return(0); } /* endif 11 */ } /* endif 10 */ } /* endif 9 */ } /* endif 8 */ } /* endif 7 */ } /* endif 6 */ } /* endif 5 */ } /* endif 4 */ } /* endif 3 */ } /* endif 2 */ } /* endif 1 */ } int next_state( int flag, int format) { /* Filter mit Zustandskodierung */ switch( flag ) { case 0: switch(format) { case 1: return(1); break; /* "@...{" */ default: return(flag); break; } case 1: switch(format) { case 2: return(0); break; /* "}" */ case 11: return(8); break; /* "...," */ default: return(9); break; } case 2: switch(format) { case 2: return(0); break; /* "}" */ case 4: return(3); break; /* "=" */ case 5: return(10); break; /* "...=..." */ case 8: return(5); break; /* ""..." */ default: return(3); break; } case 3: switch(format) { case 2: return(0); break; /* "}" */ case 6: return(9); break; /* ""..."," */ case 11: return(9); break; /* "...," */ case 7: return(4); break; /* ""..."" */ case 8: return(5); break; /* ""..." */ case 0: return(6); break; /* "..." */ } case 4: switch(format) { case 2: return(0); break; /* "}" */ case 3: return(9); break; /* "," */ default: return(7); break; } case 5: switch(format) { case 2: return(0); break; /* "}" */ case 6: return(9); break; /* ""..."," */ case 9: return(9); break; /* "..."," */ case 10: return(4); break; /* "..."" */ default: return(7); break; } case 6: switch(format) { case 2: return(0); break; /* "}" */ default: return(flag); break; } case 7: switch(format) { case 2: return(0); break; /* "}" */ case 9: return(9); break; /* "..."," */ case 10: return(4); break; /* "..."" */ case 6: return(9); break; /* ""..."," */ default: return(flag); break; } case 8: switch(format) { case 2: return(0); break; /* "}" */ default: return(2); break; } case 9: switch(format) { case 2: return(0); break; /* "}" */ case 4: return(2); break; /* "..." */ case 5: return(2); break; /* "...=..." */ default: return(2); break; } case 10: switch(format) { case 2: return(0); break; /* "}" */ case 6: return(9); break; /* ""..."," */ case 7: return(9); break; /* ""..."" */ case 8: return(5); break; /* ""..." */ case 11: return(6); break; /* "...," */ case 3: return(9); break; /* "," */ default: return(6); break; /* "..." */ } default: return(flag); break; } } void filter( FILE *ifp, int out) { int flag = 0; int attr_wert = 0; int l_format = 0; char line[max_len]; char buffer[max_len]; extern char *attr_bez[max_attr]; line[first]='\0'; buffer[first]='\0'; while ((fscanf( ifp, "%s\n",line )) != EOF ) { strcat( buffer, line); strcpy( line, buffer); buffer[first]='\0'; /* Erkennen eines bestimmten Wortformats */ l_format = line_format( line ); if(l_format == 5) { strcpy( buffer, line+16); line[16]='\0'; } /* Zustandsaenderung durch erkanntes Wortformaten */ flag = next_state( flag, l_format); new_format( out, flag, l_format, line ); if(((out == 2) || (out == 3)) && (flag == 0) && (l_format == 2)) { print_ds(); delete_ds(); } line[first]='\0'; } fprintf( stdout, "\n", datensatz[0]); } #define FILTER

CSLIB 2000


Zurück: Persönliche Hypertexte