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 
00031 #include <stdlib.h>
00032 #include <stdio.h>
00033 #include <string.h>
00034 
00035 #define _GNU_SOURCE
00036 #include <getopt.h>
00037 
00038 #define MODE_NORMAL 400
00039 #define MODE_ALL 401
00040 
00041 #define OPT_VERSION 800
00042 #define OPT_HELP 801
00043 #define OPT_ALL 802
00044 #define OPT_SINGULAR 803
00045 #define OPT_PLURAL 804
00046 #define OPT_COUNT 805
00047 
00048 void print_version()
00049 {
00050   printf("FinFlect version 0.1.0\n");
00051   printf("Copyright (C) 2004, 2005  The FinFlect Team\n");
00052 }
00053 
00054 void print_help()
00055 {
00056   printf("usage: finflect [options] <word>\n\n");
00057 
00058   printf("general options:\n\n");
00059 
00060   printf("      --version        -V     Shows the version information and exits.\n");
00061   printf("      --help           -h     Shows this help text and exits.\n");
00062   printf("      --all            -a     Shows a table of all inflections and exits.\n\n");
00063 
00064   printf("cases:\n\n");
00065 
00066   printf("      --nominative            (implied unless another case is specified)\n");
00067   printf("      --partitive\n");
00068   printf("      --genitive\n");
00069   printf("      --essive\n");
00070   printf("      --translative\n");
00071   printf("      --inessive\n");
00072   printf("      --elative\n");
00073   printf("      --illative\n");
00074   printf("      --adessive\n");
00075   printf("      --ablative\n");
00076   printf("      --allative\n");
00077   printf("      --abessive\n");
00078   printf("      --comitative            NOTE: Comitative has no singular form\n\n");
00079   printf("      --instructive\n");
00080   
00081   printf("counts:\n\n");
00082   
00083   printf("      --singular              (implied unless --plural is specified)\n");
00084   printf("      --plural\n\n");
00085   printf("      --count=N               singular if N == 1, plural otherwise\n");
00086 }
00087 
00088 
00089 int main(int argc, char** argv)
00090 {
00091   int opt;
00092   ffcase thecase = FFCASE_NOMINATIVE;
00093   ffint32 count = FFCOUNT_SINGULAR;
00094   ffchar* word = NULL;
00095   ffint32 mode = MODE_NORMAL;
00096 
00097   /* Kids, don't try this at home... */
00098   struct option longopts[21];
00099   longopts[0] = (struct option) {"version", 0, NULL, OPT_VERSION};
00100   longopts[1] = (struct option) {"help", 0, NULL, OPT_HELP};
00101   longopts[2] = (struct option) {"all", 0, NULL, OPT_ALL};
00102 
00103   longopts[3] = (struct option) {"nominative", 0, NULL, FFCASE_NOMINATIVE};
00104   longopts[4] = (struct option) {"partitive", 0, NULL, FFCASE_PARTITIVE};
00105   longopts[5] = (struct option) {"genitive", 0, NULL, FFCASE_GENITIVE};
00106   longopts[6] = (struct option) {"essive", 0, NULL, FFCASE_ESSIVE};
00107   longopts[7] = (struct option) {"translative", 0, NULL, FFCASE_TRANSLATIVE};
00108   longopts[8] = (struct option) {"inessive", 0, NULL, FFCASE_INESSIVE};
00109   longopts[9] = (struct option) {"elative", 0, NULL, FFCASE_ELATIVE};
00110   longopts[10] = (struct option) {"illative", 0, NULL, FFCASE_ILLATIVE};
00111   longopts[11] = (struct option) {"adessive", 0, NULL, FFCASE_ADESSIVE};
00112   longopts[12] = (struct option) {"ablative", 0, NULL, FFCASE_ABLATIVE};
00113   longopts[13] = (struct option) {"allative", 0, NULL, FFCASE_ALLATIVE};
00114   longopts[14] = (struct option) {"abessive", 0, NULL, FFCASE_ABESSIVE};
00115   longopts[15] = (struct option) {"comitative", 0, NULL, FFCASE_COMITATIVE};
00116   longopts[16] = (struct option) {"instructive", 0, NULL, FFCASE_INSTRUCTIVE};
00117   
00118   longopts[17] = (struct option) {"singular", 0, NULL, OPT_SINGULAR};
00119   longopts[18] = (struct option) {"plural", 0, NULL, OPT_PLURAL};
00120   longopts[19] = (struct option) {"count", 1, NULL, OPT_COUNT};
00121   /* ...but if you do, DO remember the all-zero terminator */
00122   longopts[20] = (struct option) {NULL, 0, NULL, 0};
00123 
00124   while((opt = getopt_long(argc, argv, "Vha", longopts, NULL)) > 0)
00125   {
00126     switch(opt)
00127     {
00128     case 'h':
00129     case OPT_HELP:
00130       print_help();
00131       exit(0);
00132       break;
00133     case 'V':
00134     case OPT_VERSION:
00135       print_version();
00136       exit(0);
00137       break;
00138     case OPT_ALL:
00139     case 'a':
00140       mode = MODE_ALL;
00141       break;
00142     case FFCASE_NOMINATIVE:
00143     case FFCASE_PARTITIVE:
00144     case FFCASE_GENITIVE:
00145     case FFCASE_ESSIVE:
00146     case FFCASE_TRANSLATIVE:
00147     case FFCASE_INESSIVE:
00148     case FFCASE_ELATIVE:
00149     case FFCASE_ILLATIVE:
00150     case FFCASE_ADESSIVE:
00151     case FFCASE_ABLATIVE:
00152     case FFCASE_ALLATIVE:
00153     case FFCASE_ABESSIVE:
00154     case FFCASE_COMITATIVE:
00155     case FFCASE_INSTRUCTIVE:
00156       thecase = opt;
00157       break;
00158     case OPT_SINGULAR:
00159       count = FFCOUNT_SINGULAR;
00160       break;
00161     case OPT_PLURAL:
00162       count = FFCOUNT_PLURAL;
00163       break;
00164     default:
00165       break;
00166     }
00167   }
00168   
00169   if(thecase == FFCASE_COMITATIVE && count == FFCOUNT_SINGULAR) {
00170     printf("finflect: comitative has no singular form");
00171     print_help();
00172     return 1;
00173   }
00174   else if(optind < argc) {
00175     word = (ffchar*) malloc (strlen(argv[optind]) + 1);
00176     strcpy(word, argv[optind]);
00177     if(mode == MODE_NORMAL) {  
00178       ffchar* inflected = ff_inflect(word, thecase, count);
00179       printf("%s\n", inflected);
00180       free(inflected);
00181     }
00182     else /* if(mode == MODE_ALL) */ {
00183       ffchar *singular, *plural, *casename;
00184       ffint32 i;
00185       for(i = FFCASE_NOMINATIVE; i <= FFCASE_INSTRUCTIVE; ++i) {
00186         casename = ff_case_name((ffcase)i);
00187         singular = ff_inflect(word, (ffcase)i, FFCOUNT_SINGULAR);
00188         plural = ff_inflect(word, (ffcase)i, FFCOUNT_PLURAL);
00189         printf("%s: \t%s\t%s\n", casename, singular, plural);
00190         free(singular);
00191         free(plural);
00192       }
00193     }
00194     free(word);
00195     return 0;
00196   }
00197   else {
00198     print_help();
00199     return 1;
00200   }
00201 }
00202 

Generated on Sun May 15 21:50:47 2005 for FinFlect by  doxygen 1.4.1