home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume21 / kdrill / part01 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-07  |  5.2 KB  |  231 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #include <Xlib.h>
  5. #include <Xatom.h>
  6. #include <Xutil.h>
  7. #include <Intrinsic.h>
  8. #include <StringDefs.h>
  9. #include <Xaw/Command.h>
  10. #include <Xaw/Label.h>
  11. #include <Xaw/Form.h>
  12. #include <Composite.h>
  13.  
  14. #include "defs.h"
  15. #include "externs.h"
  16. #include "patchlevel.h"
  17.  
  18. static char *version = VERSION;
  19.  
  20. Display *display;
  21. int screen;
  22. Window mainwindow,rootwindow;
  23. GC gc,cleargc;
  24. XtAppContext Context;
  25.  
  26. char *dictname=NULL;
  27. char *usefile=NULL;
  28. char kanjifontname[100];
  29.  
  30. XChar2b *kstring;
  31. XChar2b onecharstring;
  32.  
  33. unsigned long white,black;
  34.  
  35.  
  36.  
  37. /* quitbutton, of course */
  38. void quit(w,data,calldata)
  39. Widget w;
  40. XtPointer data,calldata;
  41. {
  42. #ifdef DEBUG
  43.     puts("quitting?");
  44. #endif
  45.     XtCloseDisplay(display);
  46.     exit(0);
  47. }
  48.  
  49.  
  50. int usage(){
  51.     printf(" kdrill    -- Version %s\n",version);
  52.     fflush(stdout);
  53.     puts("A program to drill on kanji to english, or vica versa");
  54.     puts("");
  55.     puts("Options:");
  56.     puts("  -usefile usefilename         changes abridgement file of dictionary");
  57.     puts("  -dictfile dictfilename       changes dictionary file from");
  58.     puts("                               \"kanjidic\" to some other file");
  59.     puts("  -font fontname               changes english font");
  60.     puts("  -kanjifont Kanjifontname     changes LARGE kanji font");
  61.     puts("  -smallkanji Kanjifontname    changes small kanji font");
  62.     puts("  -noBell                      turns off beep for incorrect answer");
  63.     puts("  -guessmeaning                starts off with four kanji to one meaning");
  64.     puts("  -gradelevel                  define cut-off grade level:");
  65.     puts("                                6 is highest limit, 0 means no restrictions");
  66.     puts("  -showkana                    start showing kana meanings instead of english");
  67.     puts("");
  68.     puts("       The above options can also be set as resources,");
  69.     puts("       with the same name as their optionflag");
  70.     puts("");
  71.     exit(0);
  72. }
  73.  
  74. /* keypress:
  75.  * return whether got strnage key (shift, etc), or normal key.
  76.  * returns 0 on normal key, or exits program if 'q' hit
  77.  */
  78. int keypress(key)
  79. int key;
  80. {
  81.     if(key == 61)
  82.         exit(0);
  83.     else
  84.  
  85.         /* sun codes for shift, control, etc */
  86.     switch(key){
  87.         case 106:
  88.         case 83:
  89.         case 26:
  90.             return 1;
  91.             break;
  92.         default:
  93.             /* printf("Got keypress %d\n",key); */
  94.             return 0;
  95.     }
  96. }
  97.  
  98. /* GetXtNumber(), GetXtBoolean(), GetXtString():
  99.  *    Not the "best way" to get resources...
  100.  *    supposed to read them all in at one go.
  101.  *    But I had reasons for reading things in at different times,
  102.  *    and I have stuck to that model
  103.  */
  104.  
  105. /* GetXtNumber:
  106.  *    Given resource name and and class, will attempt to look up
  107.  *    resource value in database.
  108.  *    Will return default of 0!!!
  109.  */
  110. int GetXtNumber(name,class)
  111. char *name,*class;
  112. {
  113.     Cardinal resourcevalue;
  114.     char resourcename[100],resourceclass[100];
  115.     XtResource resourceList=    {
  116.         NULL,NULL,
  117.         XtRCardinal,sizeof(int),0,
  118.         XtRCardinal,0
  119.     };
  120.  
  121.     resourceList.resource_name = resourcename;
  122.     resourceList.resource_class = resourceclass;
  123.  
  124.     strcpy(resourcename,name);
  125.     strcpy(resourceclass,class);
  126.  
  127.     XtGetApplicationResources(toplevel,&resourcevalue,
  128.                   &resourceList,1,
  129.                   NULL,0);
  130.     return resourcevalue;
  131. }
  132. /* GetXtBoolean()
  133. *    see GetXtNumber
  134. */
  135. Boolean GetXtBoolean(name,class)
  136. char *name,*class;
  137. {
  138.     Boolean resourcevalue;
  139.     char resourcename[100],resourceclass[100];
  140.  
  141.     XtResource resourceList ={
  142.         NULL,NULL,
  143.         XtRBoolean,sizeof(Boolean),0,
  144.         XtRBoolean,False,
  145.     };
  146.     resourceList.resource_name = resourcename;
  147.     resourceList.resource_class = resourceclass;
  148.  
  149.     strcpy(resourcename,name);
  150.     strcpy(resourceclass,class);
  151.  
  152.     XtGetApplicationResources(toplevel,&resourcevalue,
  153.                   &resourceList,1,
  154.                   NULL,0);
  155.     return resourcevalue;
  156. }
  157.  
  158.  
  159. /* GetXtString:
  160.  *    Given the resource name and class, will
  161.  *     copy the resource string value to
  162.  *     destinationstring address.
  163.  *    Destination must be MALLOCED ARRAY!!!
  164.  */
  165. void GetXtString(name,class,destinationstring)
  166. char *name,*class;
  167. char *destinationstring;
  168. {
  169.     char resourcename[100],resourceclass[100];
  170.     char buffer[100];
  171.     char *returnstring = buffer;
  172.     
  173.  
  174.     XtResource resourceList ={
  175.         NULL,NULL,
  176.         XtRString,sizeof(char *),0,
  177.         XtRString,"NOT SET"
  178.     };
  179.     resourceList.resource_name = resourcename;
  180.     resourceList.resource_class = resourceclass;
  181.  
  182.     strcpy(resourcename,name);
  183.     strcpy(resourceclass,class);
  184.  
  185.     XtGetApplicationResources(toplevel,&returnstring,
  186.                   &resourceList,1,
  187.                   NULL,0);
  188.     strcpy(destinationstring,returnstring);
  189. }
  190.  
  191. int main(argc,argv)
  192. int argc;
  193. char *argv[];
  194. {
  195.  
  196.     char usefilename[100],dict[100];
  197.  
  198.     initstuffs(&argc,argv);
  199.  
  200.     puts("Reading in dictionary: please wait a few moments...");
  201.  
  202.     GetXtString("usefile","Usefile",usefilename);
  203.     GetXtString("dictfile","Dictfile",dict);
  204.     dictname = dict;
  205.     usefile = usefilename;
  206. #ifdef DEBUG
  207.     puts("");
  208.     printf("usefile from resources is \"%s\"\n",usefilename);
  209.     printf("dictfile from resources is\" %s\"\n",dictname);
  210. #endif
  211.  
  212.     /* check for abridgements of the dictionary... */
  213.     inituse();
  214.     /* and actually read in structs of dictionary */
  215.     readstructs(&argc,argv);
  216.  
  217.     showEnglish = ! GetXtBoolean("showkana","Showkana");
  218.     CountKanji();
  219.     if(numberofkanji<8){
  220.         fprintf(stderr,"There are two few kanji readable in the current configuration\n");
  221.         fprintf(stderr,"Please either reconfigure your usefile, or raise the grade level\n");
  222.         exit(0);
  223.     }
  224.  
  225.     
  226.     kanjitoenglish(Kanji2English);
  227.     /* if pass 0, means want to guess english */
  228.     XtAppMainLoop(Context);
  229.     return 0;
  230. }
  231.