/* Macro definitions : */ #include #include #include #include #define ERROR 1 #define OK 0 #define BLOCKSIZE 82 /* Max. line length */ /* Global variables : */ FILE *inputFile; FILE *out1File; unsigned char inLine[BLOCKSIZE]; unsigned char out1Line[BLOCKSIZE]; main() { /* Functions called */ void OpenFiles(); void ConvertLine(); /* Local arrays, structures and variables : */ unsigned int processedLines, i; OpenFiles( ); printf( "\n" ); for ( processedLines = 0; fgets( inLine, BLOCKSIZE, inputFile); processedLines++) { if( inLine[0] == '\n' ) fprintf( out1File, "\n" ); else { ConvertLine( inLine, out1Line ); fprintf( out1File, "%s", out1Line ); } /* else */ } /* for */ printf( "\n-S- Total of %d lines processed", processedLines ); } void ConvertLine( unsigned char *inL, unsigned char *outL ) { /* convert chars from Cyrillic to Latin */ /* Local arrays, structures and variables : */ static char alphabet[83] = { "ABVGDEZhZIJKLMNOPRSTUFHCChShSht`Y'EJuYaabvgdezhzijklmnoprstufhcchshsht`y'ejujaEe"}; static int alphaI[67] = { /* A B V G D E Zh Z I J K L M N O P R S T U F */ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, /* H C CH SH SHT ` Y ' E Ju Ja */ 22, 23, 24, 26, 28, 31, 32, 33, 34, 35, 37, /* a b v g d e zh z i j k l m n o p r s */ 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, /* t u f h c ch sh sht ` y ' e ju ja E e */ 58, 59, 60, 61, 62, 63, 65, 67, 70, 71, 72, 73, 74, 76, 78, 79, 80 }; int i, j, k, ind; for( i = j = 0; inL[i]; i++ ) { if( inL[i] < 128 || inL[i] > 193 ) outL[j++] = inL[i]; else { ind = inL[i] - 128; for( k = alphaI[ ind ]; k < alphaI[ ind+1 ]; k++ ) { outL[j++] = alphabet[k]; } /* for */ } /* else */ } /* for */ outL[j] = '\0'; } /* ConvertLine */ void OpenFiles( ) /* opens input and output files */ { /* Local variables and arrays */ unsigned int i; char token[21]; printf(" \n-I- Enter INPUT file name > "); scanf("%s", token); inputFile = fopen( token, "r" ); while(!inputFile) { printf("\n\007-W- Incorrect input file name '%s', re-enter >" ,token ); scanf("%s", token); inputFile = fopen( token, "r" ); } /* while */ printf("\n-S- File '%s' successfully opened", token ); printf(" \n-I- Enter OUTPUT file name > "); scanf("%s", token); out1File = fopen( token, "w" ); while( !out1File ) { printf("\n\007-W- Incorrect output file name '%s', re-enter >" ,token ); scanf("%s", token); out1File = fopen( token, "w" ); } /* while */ printf("\n-S- File '%s' successfully opened", token ); }