home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
-
- #include <Xlib.h>
- #include <Xatom.h>
- #include <Xutil.h>
- #include <Intrinsic.h>
- #include <StringDefs.h>
- #include <Xaw/Command.h>
- #include <Xaw/Label.h>
- #include <Xaw/Form.h>
- #include <Composite.h>
-
- #include "defs.h"
- #include "externs.h"
- #include "patchlevel.h"
-
- static char *version = VERSION;
-
- Display *display;
- int screen;
- Window mainwindow,rootwindow;
- GC gc,cleargc;
- XtAppContext Context;
-
- char *dictname=NULL;
- char *usefile=NULL;
- char kanjifontname[100];
-
- XChar2b *kstring;
- XChar2b onecharstring;
-
- unsigned long white,black;
-
-
-
- /* quitbutton, of course */
- void quit(w,data,calldata)
- Widget w;
- XtPointer data,calldata;
- {
- #ifdef DEBUG
- puts("quitting?");
- #endif
- XtCloseDisplay(display);
- exit(0);
- }
-
-
- int usage(){
- printf(" kdrill -- Version %s\n",version);
- fflush(stdout);
- puts("A program to drill on kanji to english, or vica versa");
- puts("");
- puts("Options:");
- puts(" -usefile usefilename changes abridgement file of dictionary");
- puts(" -dictfile dictfilename changes dictionary file from");
- puts(" \"kanjidic\" to some other file");
- puts(" -font fontname changes english font");
- puts(" -kanjifont Kanjifontname changes LARGE kanji font");
- puts(" -smallkanji Kanjifontname changes small kanji font");
- puts(" -noBell turns off beep for incorrect answer");
- puts(" -guessmeaning starts off with four kanji to one meaning");
- puts(" -gradelevel define cut-off grade level:");
- puts(" 6 is highest limit, 0 means no restrictions");
- puts(" -showkana start showing kana meanings instead of english");
- puts("");
- puts(" The above options can also be set as resources,");
- puts(" with the same name as their optionflag");
- puts("");
- exit(0);
- }
-
- /* keypress:
- * return whether got strnage key (shift, etc), or normal key.
- * returns 0 on normal key, or exits program if 'q' hit
- */
- int keypress(key)
- int key;
- {
- if(key == 61)
- exit(0);
- else
-
- /* sun codes for shift, control, etc */
- switch(key){
- case 106:
- case 83:
- case 26:
- return 1;
- break;
- default:
- /* printf("Got keypress %d\n",key); */
- return 0;
- }
- }
-
- /* GetXtNumber(), GetXtBoolean(), GetXtString():
- * Not the "best way" to get resources...
- * supposed to read them all in at one go.
- * But I had reasons for reading things in at different times,
- * and I have stuck to that model
- */
-
- /* GetXtNumber:
- * Given resource name and and class, will attempt to look up
- * resource value in database.
- * Will return default of 0!!!
- */
- int GetXtNumber(name,class)
- char *name,*class;
- {
- Cardinal resourcevalue;
- char resourcename[100],resourceclass[100];
- XtResource resourceList= {
- NULL,NULL,
- XtRCardinal,sizeof(int),0,
- XtRCardinal,0
- };
-
- resourceList.resource_name = resourcename;
- resourceList.resource_class = resourceclass;
-
- strcpy(resourcename,name);
- strcpy(resourceclass,class);
-
- XtGetApplicationResources(toplevel,&resourcevalue,
- &resourceList,1,
- NULL,0);
- return resourcevalue;
- }
- /* GetXtBoolean()
- * see GetXtNumber
- */
- Boolean GetXtBoolean(name,class)
- char *name,*class;
- {
- Boolean resourcevalue;
- char resourcename[100],resourceclass[100];
-
- XtResource resourceList ={
- NULL,NULL,
- XtRBoolean,sizeof(Boolean),0,
- XtRBoolean,False,
- };
- resourceList.resource_name = resourcename;
- resourceList.resource_class = resourceclass;
-
- strcpy(resourcename,name);
- strcpy(resourceclass,class);
-
- XtGetApplicationResources(toplevel,&resourcevalue,
- &resourceList,1,
- NULL,0);
- return resourcevalue;
- }
-
-
- /* GetXtString:
- * Given the resource name and class, will
- * copy the resource string value to
- * destinationstring address.
- * Destination must be MALLOCED ARRAY!!!
- */
- void GetXtString(name,class,destinationstring)
- char *name,*class;
- char *destinationstring;
- {
- char resourcename[100],resourceclass[100];
- char buffer[100];
- char *returnstring = buffer;
-
-
- XtResource resourceList ={
- NULL,NULL,
- XtRString,sizeof(char *),0,
- XtRString,"NOT SET"
- };
- resourceList.resource_name = resourcename;
- resourceList.resource_class = resourceclass;
-
- strcpy(resourcename,name);
- strcpy(resourceclass,class);
-
- XtGetApplicationResources(toplevel,&returnstring,
- &resourceList,1,
- NULL,0);
- strcpy(destinationstring,returnstring);
- }
-
- int main(argc,argv)
- int argc;
- char *argv[];
- {
-
- char usefilename[100],dict[100];
-
- initstuffs(&argc,argv);
-
- puts("Reading in dictionary: please wait a few moments...");
-
- GetXtString("usefile","Usefile",usefilename);
- GetXtString("dictfile","Dictfile",dict);
- dictname = dict;
- usefile = usefilename;
- #ifdef DEBUG
- puts("");
- printf("usefile from resources is \"%s\"\n",usefilename);
- printf("dictfile from resources is\" %s\"\n",dictname);
- #endif
-
- /* check for abridgements of the dictionary... */
- inituse();
- /* and actually read in structs of dictionary */
- readstructs(&argc,argv);
-
- showEnglish = ! GetXtBoolean("showkana","Showkana");
- CountKanji();
- if(numberofkanji<8){
- fprintf(stderr,"There are two few kanji readable in the current configuration\n");
- fprintf(stderr,"Please either reconfigure your usefile, or raise the grade level\n");
- exit(0);
- }
-
-
- kanjitoenglish(Kanji2English);
- /* if pass 0, means want to guess english */
- XtAppMainLoop(Context);
- return 0;
- }
-