Print several types of alphabets
#include <>
#include <>
#include <>
#define PACKAGE "alphabet"
#define VERSION "0.0.5"
/*
// `0' westeren, `1' phonetic, `2' greek `3' hebrew
// `4' phoenician `5' arab
*/
static int type = 0;
/* all output upper case */
static int upper = 0;
/* recursive, output until killed */
static int recur = 0;
/* phonetic alphabet */
const char *palpha[]= { "alpha", "bravo", "charlie", "delta",
"echo", "foxtrot", "golf", "hotel",
"india", "juliet", "kilo", "lima",
"mike", "november", "oscar", "papa",
"quebec", "romeo", "sierra", "tango",
"uniform", "victor", "whisky", "x-ray",
"yankee", "zulu" };
/* lower case greek alphabet */
const char *galpha[]= { "alpha", "beta", "gamma", "delta",
"epsilon", "zeta", "eta", "theta",
"iota", "kappa", "lambda", "mu",
"nu", "xi", "omicron", "pi",
"rho", "sigma", "tau", "upsilon",
"phi", "chi", "psi", "omega" };
/* lower case hebrew alphabet */
const char *halpha[]= { "tet", "chet", "zayin", "vav",
"he", "dalet", "gimel", "bet",
"alef", "samech", "nun", "nun",
"mem", "mem", "lamed", "khaf",
"kaf", "yod", "tav", "shin",
"resh", "qof", "tzade", "tzade",
"fe", "pe", "ayin" };
/* lower case phoenician alphabet */
const char *nalpha[]= { "aleph", "beth", "gimel", "daleth",
"he", "waw", "heth", "yodh",
"kaph", "lamedh", "mem", "nun",
"ayin", "pe", "qoph", "resh",
"sin", "taw", "waw", "samekh",
"zayin" };
/* lower case arab alphabet */
const char *aalpha[]= { "xaa", "haa", "jiim", "th!aa",
"taa", "baa", "alif", "saad",
"shiin", "siin", "zaay", "raa",
"thaal", "daal", "qaaf", "faa",
"ghayn", "ayn", "th:aa", "taa",
"daad", "yaa", "waaw", "haa",
"nuun", "miim", "laam", "kaaf" };
/* status epilepticus, and die with `exval' */
void print_help(int exval);
/* print the specified alphabet */
void print_alphabet(void);
int main(int argc, char *argv[]) {
int opt = 0;
/* option parser */
while((opt = getopt(argc, argv, "hvpgwiaru")) != -1) {
switch(opt) {
case 'h': /* print help and exit */
print_help(0);
case 'v': /* print version and exit */
exit(0);
case 'p': /* print the phonetic alphabet */
type = 1;
break;
case 'g': /* print the lower case greek alphabet */
type = 2;
break;
case 'w': /* print the lower case hebrew alphabet */
type = 3;
break;
case 'i': /* print the lower case phoenician alphabet */
type = 4;
break;
case 'a': /* print the lower case arab alphabet */
type = 5;
break;
case 'r': /* print the alphabet repeatedly until killed */
recur = 1;
break;
case 'u': /* print all output upper case */
upper = 1;
break;
case '?': /* unkown option */
fprintf(stderr, "%s: Error - no such option `%c'\n\n", PACKAGE, optopt);
print_help(1);
break;
} /* switch */
} /* while */
/* prints the selected alphabet */
print_alphabet();
return 0;
}
/* prints the selected alphabet */
void print_alphabet(void) {
const char *ptr = NULL;
int i = 0;
/* western alphabet */
if(type == 0) {
if(upper == 0)
for(i = 97; i <= 122; i++)
printf("%c\n", i);
else
for(i = 65; i <= 90; i++)
printf("%c\n", i);
/* phonetic alphabet */
} else if(type == 1) {
if(upper == 0) {
for(i = 0; i < 26; i++)
printf("%s\n", palpha[i]);
} else {
for(i = 0; i < 26; i++) {
ptr = palpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
/* greek alphabet */
} else if(type == 2) {
if(upper == 0) {
for(i = 0; i < 24; i++)
printf("%s\n", galpha[i]);
} else {
for(i = 0; i < 24; i++) {
ptr = galpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} else if(type == 3) {
if(upper == 0) {
for(i = 0; i < 27; i++)
printf("%s\n", halpha[i]);
} else {
for(i = 0; i < 27; i++) {
ptr = halpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} else if(type == 4) {
if(upper == 0) {
for(i = 0; i < 21; i++)
printf("%s\n", nalpha[i]);
} else {
for(i = 0; i < 21; i++) {
ptr = nalpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} else if(type == 5) {
if(upper == 0) {
for(i = 0; i < 28; i++)
printf("%s\n", aalpha[i]);
} else {
for(i = 0; i < 28; i++) {
ptr = aalpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} /* else if */
if(recur == 1)
print_alphabet();
else
return;
}
/* status epilepticus, and die with `exval' */
void print_help(int exval) {
printf("%s,%s prints different alphabets\n", PACKAGE, VERSION);
printf("Usage: %s [-h] [-v] [-p] [-g] [-w] [-i] [-a] [-r] [-u]\n\n", PACKAGE);
printf(" Startup:\n");
printf(" -h print this help and exit\n");
printf(" -v print version and exit\n\n");
printf(" Alphabet:\n");
printf(" -p print the phonetic alphabet\n");
printf(" -g print the greek alphabet\n");
printf(" -w print the hebrew alphabet\n");
printf(" -i print the phoenician alphabet\n");
printf(" -a print the arab alphabet\n\n");
printf(" Output:\n");
printf(" -r print the alphabet repeatedly until killed\n");
printf(" -u print all output in upper case\n\n");
printf(" Per default the Westeren alphabet is printed\n");
exit(exval);
}
Read more: http://cmagical.blogspot.com/2010_02_14_archive.html#ixzz0xgY8R8cE
Under Creative Commons License: Attribution Non-Commercial No Derivatives
Wednesday, 25 August 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment