/**************************************/ /* */ /* Greeklish Converter ver 1.0 */ /* Implemented by Thunder */ /* thunder@isee.gr */ /* */ /* Usage: grklsh inputflnm outputflnm */ /* */ /**************************************/ #include < stdio.h & gt; #include < string.h & gt; #define LOGO "\n\n[ Greeklish Converter ~ Thunder (C) 2002 ]\n" const int FLNM_SIZE = 12; int greeklish(char input[], char output[]) { FILE *ifile; /* the file which will be created */ FILE *ofile; /* the file to use as source */ unsigned char cur_ch; /* represents each character of the input file */ char new_ch[3]; /* the string which will replace the character */ if ((ifile = fopen(input, "r")) == NULL || (ofile = fopen(output, "w")) == NULL) { /* checks if the input can be read and if the output can be written */ printf("\nError opening files! Exiting..."); return (1); } else { /* then we proceed */ while ((fread(& cur_ch, sizeof(cur_ch), 1, ifile)) != 0) { /* while it hasn't reached an end of file */ if (cur_ch < = 143 || cur_ch > = 255) { /* english letters and other symbols */ new_ch[0] = cur_ch; new_ch[1] = '\0'; } else { switch (cur_ch) { /* Greek to Greeklish correspondence */ case 193: case 162: { strcpy(new_ch, "A"); break; } case 194: { strcpy(new_ch, "B"); break; } case 195: { strcpy(new_ch, "G"); break; } case 196: { strcpy(new_ch, "D"); break; } case 197: case 184: { strcpy(new_ch, "E"); break; } case 198: { strcpy(new_ch, "Z"); break; } case 199: case 185: { strcpy(new_ch, "H"); break; } case 200: { strcpy(new_ch, "Th"); break; } case 201: case 186: { strcpy(new_ch, "I"); break; } case 218: { strcpy(new_ch, "'I'"); break; } case 202: { strcpy(new_ch, "K"); break; } case 203: { strcpy(new_ch, "L"); break; } case 204: { strcpy(new_ch, "M"); break; } case 205: { strcpy(new_ch, "N"); break; } case 206: { strcpy(new_ch, "Ks"); break; } case 207: case 188: { strcpy(new_ch, "O"); break; } case 208: { strcpy(new_ch, "P"); break; } case 209: { strcpy(new_ch, "R"); break; } case 211: { strcpy(new_ch, "S"); break; } case 212: { strcpy(new_ch, "T"); break; } case 213: case 190: { strcpy(new_ch, "Y"); break; } case 219: { strcpy(new_ch, "'Y'"); break; } case 214: { strcpy(new_ch, "F"); break; } case 215: { strcpy(new_ch, "X"); break; } case 216: { strcpy(new_ch, "Ps"); break; } case 217: case 191: { strcpy(new_ch, "W"); break; } case 225: case 220: { strcpy(new_ch, "a"); break; } case 226: { strcpy(new_ch, "b"); break; } case 227: { strcpy(new_ch, "g"); break; } case 228: { strcpy(new_ch, "d"); break; } case 229: case 221: { strcpy(new_ch, "e"); break; } case 230: { strcpy(new_ch, "z"); break; } case 231: case 222: { strcpy(new_ch, "h"); break; } case 232: { strcpy(new_ch, "th"); break; } case 233: case 223: { strcpy(new_ch, "i"); break; } case 192: case 250: { strcpy(new_ch, "'i'"); break; } case 234: { strcpy(new_ch, "k"); break; } case 235: { strcpy(new_ch, "l"); break; } case 236: { strcpy(new_ch, "m"); break; } case 237: { strcpy(new_ch, "n"); break; } case 238: { strcpy(new_ch, "ks"); break; } case 239: case 252: { strcpy(new_ch, "o"); break; } case 240: { strcpy(new_ch, "p"); break; } case 241: { strcpy(new_ch, "r"); break; } case 242: case 243: { strcpy(new_ch, "s"); break; } case 244: { strcpy(new_ch, "t"); break; } case 245: case 253: { strcpy(new_ch, "y"); break; } case 224: case 251: { strcpy(new_ch, "'y'"); break; } case 246: { strcpy(new_ch, "f"); break; } case 247: { strcpy(new_ch, "x"); break; } case 248: { strcpy(new_ch, "ps"); break; } case 249: case 254: { strcpy(new_ch, "w"); break; } default: { new_ch[0] = cur_ch; new_ch[1] = '\0'; break; } } } fwrite(new_ch, strlen(new_ch), 1, ofile); /* writes the character */ } } fwrite(LOGO, strlen(LOGO), 1, ofile); /* writes the logo */ fclose(ofile); /* closes the output */ fclose(ifile); /* closes the input */ printf(LOGO); /* prints the logo on the screen */ return (0); /* returns all clear to main */ } int main(int argc, char *argv[]) { char input[FLNM_SIZE + 1]; char output[FLNM_SIZE + 1]; if (argc == 1) { /* if no parameters are given, it exits */ printf("\n** An input file must be defined!"); return (1); } else { /* if at least on parameter is given, we proceed */ if (strlen(argv[1]) & gt; FLNM_SIZE) { /* makes sure the filenames are not over the allowed size */ printf("\n** Filename too big. %d characters max.", FLNM_SIZE); return (1); } else { strcpy(input, argv[1]); /* stores the input file name */ printf("\n** Input file name : %s", input); } if (argc == 2) { /* if no output filename has been given, we store a default one */ strcpy(output, "default.txt"); printf("\n** Setting output file name to default : %s", output); } else { if (argc == 3) { strncpy(output, argv[2], 12); /* stores the output file name */ printf("\n** Output file name : %s", output); } else { /* if more than two parameters are present, it exits */ printf("\n** Too many parameters"); return (1); } } } return (greeklish(input, output)); /* returns the int from greeklish */ }