home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <stdio.h>
-
- #include <Xos.h>
- #include <Intrinsic.h>
- #include <StringDefs.h>
- #include <Shell.h>
- #include <Xaw/Command.h>
- #include <Xaw/Label.h>
- #include <Xaw/Form.h>
- #include <Composite.h>
- #include "defs.h"
- #include "externs.h"
-
- #include "icon.xbm"
-
- XFontStruct *largekfont;
- XFontStruct *smallkfont;
- XFontStruct *fixedfont;
-
- /* I should just get rid of this, but I might use it at some
- * later date
- */
- static XtActionsRec actionlist[] = {
- { "quit",quit },
- };
-
- /*
- * We must have these resources set!!
- *
- * ( Note the similarity between this stuff and optionDescList[].
- * coincidence? I think not :-)
- */
- static char *fallback[] = {
- "KDrill.noBell: 0",
- "KDrill*usefile: usefile",
- "KDrill*dictfile: kanjidic",
- "KDrill*kanjifont: kanji24",
- "KDrill*smallkanji: kanji16",
- "KDrill*font: fixed",
- "KDrill*gradelevel: 0",
- "KDrill*showkana: 0",
- NULL
- };
-
- /* command line arguments should set the appropriate resources.. so we can
- * pull them out when wanted
- */
- static XrmOptionDescRec optionDescList[] = {
- {"-usefile", ".usefile", XrmoptionSepArg,(caddr_t) NULL},
- {"-dictfile", ".dictfile", XrmoptionSepArg,(caddr_t) NULL},
- {"-font", ".font", XrmoptionSepArg,(caddr_t) NULL},
- {"-kanjifont", ".kanjifont", XrmoptionSepArg,(caddr_t) NULL},
- {"-smallkanji", ".smallkanji", XrmoptionSepArg,(caddr_t) NULL},
- {"-noBell", ".noBell", XrmoptionNoArg, "1"},
- {"-guessmeaning",".guessmeaning",XrmoptionNoArg,"1"},
- {"-gradelevel", ".gradelevel", XrmoptionSepArg,(caddr_t) NULL},
- {"-showkana", ".showkana", XrmoptionNoArg,"1"},
- };
-
-
-
- /* initgc:
- * Initialises global gc values.
- * We don't really need this any more. But
- * GC's are good to have, I suppose.
- */
- void initgc(){
-
- gc = XCreateGC(display,mainwindow,0,NULL);
- cleargc = XCreateGC(display,mainwindow,0,NULL);
-
- XSetForeground(display,gc,black);
- XSetBackground(display,gc,white);
- XSetForeground(display,cleargc,white);
- XSetBackground(display,cleargc,black);
-
- }
-
- /* getusefile:
- * Gets a "usefile", to abridge the full dictionary.
- * If possible, will get it from the user's home directory,
- * otherwise, tries current directory
- */
- FILE *getusefile(){
- FILE *f;
- char *homedir;
- char fullname[100];
-
- if(usefile == NULL) return NULL;
- fullname[0] = '\0';
- if(usefile[0] == '~'){
- homedir = (char *) getenv("HOME");
- if(homedir == NULL){
- perror("Cannot expand '~' char. no HOME env. varriable");
- exit(0);
- }
- sprintf(fullname,"%s%s",homedir,usefile);
- } else {
- strcpy(fullname,usefile);
- }
-
- if((f = fopen(fullname,"r")) == NULL){
- puts("no usefile. using entire dictionary...");
- usefile = NULL;
- } else {
- printf("using \"%s\" to abridge dictionary\n",fullname);
- }
- return f;
- }
-
- /* inituse:
- * clear out global array of 'translations' (really abridgements),
- * and set what kanji chars are appropriate to check on.
- *
- * we set "okay" chars to have a NULL pointer stored for them in the
- * translation table, since later, we will want to check if
- * malloc malloc'd them properly.
- *
- * unacceptable chars have a pointer stored of (void *) 1
- *
- * We should really redo this.. but either way, there would
- * seem to be a conflict as to whether we have actually
- * malloced memory that starts at 0x00000001, or whatever.
- * (on a sparc, that will never happen :-)
- *
- */
- void inituse(){
- FILE *f;
- int i;
- char inbuf[100];
-
- f = getusefile();
-
- /* set all translations flags == NULL.
- * NULL means it's okay to use this character
- *
- */
- if(usefile == NULL){
- i = 0x2000;
- while(i<0x8000){
- translations[i++] = (void *)NULL;
- }
- return;
- } else { /* set all to UNREADABLE, for now */
- i = 0x2000;
- while(i<0x8000){
- translations[i++] = (void *)1;
- }
- }
-
- while(fgets(inbuf,99,f) != NULL){
- int usechar;
- usechar = xtoi(inbuf);
- if( usechar<0x8000)
- translations[usechar] = NULL;
- }
-
- }
-
-
- /* initstuffs:
- * calls the various init routines to setup
- * GCs, fonts, dictionaries, and widgets
- * (But initializing the translations is done later)
- */
-
- static Pixmap iconpixmap;
-
- void initstuffs(argc,argv)
- int *argc;
- char *argv[];
- {
- char tempnumber[10];
- XWMHints wmhints;
-
- srandom (time(NULL));
-
- toplevel = XtVaAppInitialize(&Context,"KDrill",
- optionDescList,XtNumber(optionDescList),
- argc,argv,
- fallback,
- NULL,NULL);
-
- if(*argc >1){
- usage();
- }
-
- /* this don't work?!! */
- doBell = !GetXtBoolean("noBell","NoBell");
-
-
- if(GetXtBoolean("guessmeaning","Guessmeaning"))
- Kanji2English = GUESSMEANING;
- GetXtString("gradelevel","Gradelevel",tempnumber);
- gradelevel = atoi(tempnumber);
- if(gradelevel>6){
- fprintf(stderr,"Grade level >6: defaulting to All (0)\n");
- gradelevel = 0;
- }
-
- /* display set in here */
- MakeWidgets();
-
- XtAppAddActions(Context,actionlist,XtNumber(actionlist));
- XtRealizeWidget(toplevel);
- mainwindow = XtWindow(form);
-
- iconpixmap = XCreateBitmapFromData(display,mainwindow,
- icon_bits,icon_width,icon_height);
-
- XtVaSetValues(toplevel,XtNiconName,"kdrill",
- XtNiconPixmap,iconpixmap,
- NULL);
- #ifdef OLDWAY
- wmhints.icon_pixmap = iconpixmap;
- wmhints.flags = IconPixmapHint;
-
- XSetWMProperties(display,mainwindow,"kdrill","kdrill",
- NULL,NULL, /* argv,argc */
- NULL,&wmhints,NULL); /* size, wmhints, classhints */
- #endif /* OLDWAY */
-
-
- white = WhitePixel(display,0);
- black = BlackPixel(display,0);
- initgc();
- SetBackingStore(display,XtScreen(toplevel),XtWindow(toplevel));
-
- }
-