Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

main.c

Go to the documentation of this file.
00001 /*
00002  * finflect - Algorithms and tools for inflecting Finnish nouns
00003  * Copyright (C) 2004, 2005  The FinFlect Team
00004  * 
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  * 
00019  * 
00020  * For the complete legal text of the GNU Lesser General Public License,
00021  * see the file LICENSE. For a complete list of authors and copyright
00022  * holders, see the file AUTHORS.
00023  */
00024 
00025 /**
00026  * @file main.c The FinFlect demo program
00027  */
00028 
00029 #include "finflect.h"
00030 #include "ffconfig.h"
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 
00036 #define _GNU_SOURCE
00037 #include <getopt.h>
00038 
00039 #define MODE_NORMAL 400
00040 #define MODE_ALL 401
00041 
00042 #define OPT_VERSION 800
00043 #define OPT_HELP 801
00044 #define OPT_ALL 802
00045 #define OPT_SINGULAR 803
00046 #define OPT_PLURAL 804
00047 #define OPT_COUNT 805
00048 
00049 void print_version() {
00050   printf("FinFlect version %s\n", FF_VERSION);
00051   printf("Copyright (C) 2004, 2005  The FinFlect Team\n");
00052 }
00053 
00054 void print_help() {
00055   printf("usage: finflect [options] <word>\n\n");
00056 
00057   printf("general options:\n\n");
00058 
00059   printf("      --version        -V     Shows the version information and exits.\n");
00060   printf("      --help           -h     Shows this help text and exits.\n");
00061   printf("      --all            -a     Shows a table of all inflections and exits.\n\n");
00062 
00063   printf("cases:\n\n");
00064 
00065   printf("      --nominative            (implied unless another case is specified)\n");
00066   printf("      --partitive\n");
00067   printf("      --genitive\n");
00068   printf("      --essive\n");
00069   printf("      --translative\n");
00070   printf("      --inessive\n");
00071   printf("      --elative\n");
00072   printf("      --illative\n");
00073   printf("      --adessive\n");
00074   printf("      --ablative\n");
00075   printf("      --allative\n");
00076   printf("      --abessive\n");
00077   printf("      --comitative            NOTE: Comitative has no singular form\n\n");
00078   printf("      --instructive\n\n");
00079 
00080   printf("counts:\n\n");
00081 
00082   printf("      --singular              (implied unless --plural is specified)\n");
00083   printf("      --plural\n\n");
00084   printf("      --count=N               singular if N == 1, plural otherwise\n\n");
00085 }
00086 
00087 
00088 int main(int argc, char** argv) {
00089   int opt;
00090   ffcase thecase = FFCASE_NOMINATIVE;
00091   ffint32 count = FFCOUNT_SINGULAR;
00092   ffchar* word = NULL;
00093   ffint32 mode = MODE_NORMAL;
00094 
00095   /* Kids, don't try this at home... */
00096   struct option longopts[21];
00097   longopts[0] = (struct option) {"version", 0, NULL, OPT_VERSION
00098                 };
00099   longopts[1] = (struct option) {"help", 0, NULL, OPT_HELP
00100                 };
00101   longopts[2] = (struct option) {"all", 0, NULL, OPT_ALL
00102                 };
00103 
00104   longopts[3] = (struct option) {"nominative", 0, NULL, FFCASE_NOMINATIVE
00105                 };
00106   longopts[4] = (struct option) {"partitive", 0, NULL, FFCASE_PARTITIVE
00107                 };
00108   longopts[5] = (struct option) {"genitive", 0, NULL, FFCASE_GENITIVE
00109                 };
00110   longopts[6] = (struct option) {"essive", 0, NULL, FFCASE_ESSIVE
00111                 };
00112   longopts[7] = (struct option) {"translative", 0, NULL, FFCASE_TRANSLATIVE
00113                 };
00114   longopts[8] = (struct option) {"inessive", 0, NULL, FFCASE_INESSIVE
00115                 };
00116   longopts[9] = (struct option) {"elative", 0, NULL, FFCASE_ELATIVE
00117                 };
00118   longopts[10] = (struct option) {"illative", 0, NULL, FFCASE_ILLATIVE
00119                  };
00120   longopts[11] = (struct option) {"adessive", 0, NULL, FFCASE_ADESSIVE
00121                  };
00122   longopts[12] = (struct option) {"ablative", 0, NULL, FFCASE_ABLATIVE
00123                  };
00124   longopts[13] = (struct option) {"allative", 0, NULL, FFCASE_ALLATIVE
00125                  };
00126   longopts[14] = (struct option) {"abessive", 0, NULL, FFCASE_ABESSIVE
00127                  };
00128   longopts[15] = (struct option) {"comitative", 0, NULL, FFCASE_COMITATIVE
00129                  };
00130   longopts[16] = (struct option) {"instructive", 0, NULL, FFCASE_INSTRUCTIVE
00131                  };
00132 
00133   longopts[17] = (struct option) {"singular", 0, NULL, OPT_SINGULAR
00134                  };
00135   longopts[18] = (struct option) {"plural", 0, NULL, OPT_PLURAL
00136                  };
00137   longopts[19] = (struct option) {"count", 1, NULL, OPT_COUNT
00138                  };
00139   /* ...but if you do, DO remember the all-zero terminator */
00140   longopts[20] = (struct option) {
00141                    NULL, 0, NULL, 0
00142                  };
00143 
00144   while((opt = getopt_long(argc, argv, "Vha", longopts, NULL)) > 0) {
00145     switch(opt) {
00146     case 'h':
00147     case OPT_HELP:
00148       print_help();
00149       exit(0);
00150       break;
00151     case 'V':
00152     case OPT_VERSION:
00153       print_version();
00154       exit(0);
00155       break;
00156     case OPT_ALL:
00157     case 'a':
00158       mode = MODE_ALL;
00159       break;
00160     case FFCASE_NOMINATIVE:
00161     case FFCASE_PARTITIVE:
00162     case FFCASE_GENITIVE:
00163     case FFCASE_ESSIVE:
00164     case FFCASE_TRANSLATIVE:
00165     case FFCASE_INESSIVE:
00166     case FFCASE_ELATIVE:
00167     case FFCASE_ILLATIVE:
00168     case FFCASE_ADESSIVE:
00169     case FFCASE_ABLATIVE:
00170     case FFCASE_ALLATIVE:
00171     case FFCASE_ABESSIVE:
00172     case FFCASE_COMITATIVE:
00173     case FFCASE_INSTRUCTIVE:
00174       thecase = opt;
00175       break;
00176     case OPT_SINGULAR:
00177       count = FFCOUNT_SINGULAR;
00178       break;
00179     case OPT_PLURAL:
00180       count = FFCOUNT_PLURAL;
00181       break;
00182     default:
00183       break;
00184     }
00185   }
00186 
00187   if(thecase == FFCASE_COMITATIVE && count == FFCOUNT_SINGULAR) {
00188     printf("finflect: comitative has no singular form");
00189     print_help();
00190     return 1;
00191   } else if(optind < argc) {
00192     word = (ffchar*) malloc (strlen(argv[optind]) + 1);
00193     strcpy(word, argv[optind]);
00194     if(mode == MODE_NORMAL) {
00195       ffchar* inflected = ff_inflect(word, thecase, count);
00196       printf("%s\n", inflected);
00197       free(inflected);
00198     } else /* if(mode == MODE_ALL) */
00199     {
00200       ffchar *singular, *plural, *casename;
00201       ffint32 i;
00202       for(i = FFCASE_NOMINATIVE; i <= FFCASE_INSTRUCTIVE; ++i) {
00203         casename = ff_case_name((ffcase)i);
00204         singular = ff_inflect(word, (ffcase)i, FFCOUNT_SINGULAR);
00205         plural = ff_inflect(word, (ffcase)i, FFCOUNT_PLURAL);
00206         printf("%s: \t%s\t%s\n", casename, singular, plural);
00207         free(singular);
00208         free(plural);
00209       }
00210     }
00211     free(word);
00212     return 0;
00213   } else {
00214     print_help();
00215     return 1;
00216   }
00217 }
00218 

Generated on Thu Jun 2 23:16:59 2005 for FinFlect by  doxygen 1.4.2