home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume21 / kdrill / part01 < prev    next >
Encoding:
Text File  |  1993-10-07  |  53.1 KB  |  2,044 lines

  1. Newsgroups: comp.sources.x
  2. From: philb@cats.ucsc.edu (Philip Brown)
  3. Subject: v21i002:  kdrill - A program to quiz folks on kanji, Part01/02
  4. Message-ID: <csx-v21i002=kdrill.115455@sparky.Sterling.COM>
  5. X-Md4-Signature: 9a8d11a44894044d57d8a5c62ca0c5e5
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Thu, 7 Oct 1993 16:55:29 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: philb@cats.ucsc.edu (Philip Brown)
  12. Posting-number: Volume 21, Issue 2
  13. Archive-name: kdrill/part01
  14. Environment: X11R5
  15. Supersedes: kdrill: Volume 20, Issue 134-135
  16.  
  17. [ I could not test this, other than by compiling it :-) ]
  18. [            -- chris            ]
  19.  
  20.   Here is a program to quiz folks on either english-to-kanji, or
  21. kanji-to-english. It will quiz you on either the whole dictionary [around
  22. 6000 kanji?]  OR specific kanji, if you give the JIS-number in the
  23. "usefile".
  24. It can actually quiz you on kanji<-> kana readings, now, as well as be
  25. selective about the "grade-level".
  26.  
  27. THIS REQUIRES X11 R5 !! This is because I do not think mit X11R4's Athena
  28. Widgets handled 16-bit fonts properly. If you happen to have a 16-bit
  29. capable libXaw, you should be okay anyway.
  30.  
  31. #! /bin/sh
  32. # This is a shell archive.  Remove anything before this line, then feed it
  33. # into a shell via "sh file" or similar.  To overwrite existing files,
  34. # type "sh file -c".
  35. # Contents:  README Makefile defs.h game.c init.c main.c readfile.c
  36. #   widgets.c
  37. # Wrapped by chris@sparky on Thu Oct  7 11:48:56 1993
  38. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  39. echo If this archive is complete, you will see the following message:
  40. echo '          "shar: End of archive 1 (of 2)."'
  41. if test -f 'README' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'README'\"
  43. else
  44.   echo shar: Extracting \"'README'\" \(3487 characters\)
  45.   sed "s/^X//" >'README' <<'END_OF_FILE'
  46. X  README file for kanjidrill  v2.1 July 20th, 1993
  47. X     (by Philip Brown)
  48. X
  49. X  Here is a program to quiz folks on either english-to-kanji, or
  50. Xkanji-to-english. It will quiz you on either the whole dictionary [around
  51. X6000 kanji?]  OR specific kanji, if you give the JIS-number in the
  52. X"usefile".
  53. XIt can actually quiz you on kanji<-> kana readings, now, as well as be
  54. Xselective about the "grade-level".
  55. X
  56. XTHIS REQUIRES X11 R5 !! This is because I do not think mit X11R4's Athena
  57. XWidgets handled 16-bit fonts properly. If you happen to have a 16-bit
  58. Xcapable libXaw, you should be okay anyway.
  59. X
  60. X  I use the PD kanjidic file from monu6.cc.monash.edu.au: I do not include
  61. Xit, as it is 400K. There is also a mirror at ftp.uwtc.washington.edu, but
  62. Xthey have not updated to the latest version as of this writing.
  63. X
  64. X  For the usefile, one number per entry, in hex, at the beginning of the
  65. Xline. NO TRAILING SPACE!! Anything after will be treated as a comment, so
  66. Xyou can notate the meaning of each kanji. A nifty useful usefile is
  67. Xincluded.
  68. X
  69. XThe approximate format of any kanjidic file used should be:
  70. X
  71. Xkk 3333 .... Fxxx Gxxx .... nnnn  nnnn  nn {english} {english}
  72. X
  73. XWhere kk is the 16-bit kanji value seen as two 8-bit vals.(MSB,LSB)
  74. X'....' is any char any number of times, except for things starting with
  75. X"F" or "G"
  76. XFxxx is a frequency of use rating.
  77. XGxxx is a grade level rating.
  78. Xnn is 16-bit kana interpretation with spaces between different ones.
  79. XThere may be any number of {english} segments, also.
  80. XNote that the braces {} MUST be included there.
  81. X
  82. XUnfortunately, "kanjidic" does not have english translations for some
  83. Xentries, and does not have kana for others. Depending on whether the
  84. Xprogram is in "showenglish" mode, or "showkana" mode, entries will be
  85. Xskiped if they do not have the required information to display.
  86. X(When you change modes, however, the entries will again become valid, as
  87. Xall entries in kanjidic have at LEAST one type)
  88. X
  89. XTO CHANGE FONTS, startup files, etc, you can either edit the 'fallback'
  90. Xresources in "init.c", or make up a resource file "KDrill", and stick it
  91. Xin your local app-defaults file. (Or load them with xrdb)
  92. XSample KDrill file included.
  93. X
  94. X
  95. X
  96. X
  97. X   The neat thing about programming this drill is that it uses the Kanji in
  98. Xthe kanji24 Xwindows font, so we don't have to store extra graphics.
  99. XAdding new entries to the usefile is fairly simple. grep through the
  100. Xdictionary for potential numbers, then use "xfd -fn kanji24" to check out
  101. Xwhat the characters actually look like. Note that you have to click "Next
  102. XPage" MANY times before getting to the actual kanji section.
  103. X
  104. X
  105. XCODING NOTES:
  106. X
  107. X   Coding this was.. "fun".  Fairly educational. I started this program
  108. Xalmost a year ago, because there was nothing out there like it. I made
  109. Xsome stupid design errors, and didn't have a clue what Xrm stuff was for.
  110. XThen there was a long hiatus, while I went through a few more quarters of
  111. Xschool :-)
  112. X
  113. XAfter finding some nice code ("tetris"), the junk I found in "xterm"
  114. Xstarted to make more sense.  Coupled with perusing certain other
  115. Xprograms, both bad and good, made me more aware of how a "good" X program
  116. Xshould be written.
  117. X  I hope this program can be used as an example of a well-written
  118. XXwindows program. I haven't got EVERYTHING in there.. but I do have a lot
  119. Xof the things a "proper" Xwindows program should have.
  120. X[ I even have an icon now! tee-hee..]
  121. X
  122. X Philip Brown philb@soda.berkeley.edu {preferred address}
  123. X [also for the next year or so, philb@cats.ucsc.edu]
  124. X
  125. X
  126. END_OF_FILE
  127.   if test 3487 -ne `wc -c <'README'`; then
  128.     echo shar: \"'README'\" unpacked with wrong size!
  129.   fi
  130.   # end of 'README'
  131. fi
  132. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  133.   echo shar: Will not clobber existing file \"'Makefile'\"
  134. else
  135.   echo shar: Extracting \"'Makefile'\" \(10277 characters\)
  136.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  137. X# Makefile generated by imake - do not edit!
  138. X# $XConsortium: imake.c,v 1.65 91/07/25 17:50:17 rws Exp $
  139. X#
  140. X# The cpp used on this machine replaces all newlines and multiple tabs and
  141. X# spaces in a macro expansion with a single space.  Imake tries to compensate
  142. X# for this, but is not always successful.
  143. X#
  144. X
  145. X# -------------------------------------------------------------------------
  146. X# Makefile generated from "Imake.tmpl" and <Imakefile>
  147. X# $XConsortium: Imake.tmpl,v 1.139 91/09/16 08:52:48 rws Exp $
  148. X#
  149. X# Platform-specific parameters may be set in the appropriate <vendor>.cf
  150. X# configuration files.  Site-specific parameters should be set in the file
  151. X# site.def.  Full rebuilds are recommended if any parameters are changed.
  152. X#
  153. X# If your C preprocessor does not define any unique symbols, you will need
  154. X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  155. X# "make World" the first time).
  156. X#
  157. X
  158. X# -------------------------------------------------------------------------
  159. X# site-specific configuration parameters that need to come before
  160. X# the platform-specific parameters - edit site.def to change
  161. X
  162. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  163. X
  164. X# -------------------------------------------------------------------------
  165. X# platform-specific configuration parameters - edit sun.cf to change
  166. X
  167. X# platform:  $XConsortium: sun.cf,v 1.72.1.1 92/03/18 13:13:37 rws Exp $
  168. X
  169. X# operating system:  SunOS 4.1.2
  170. X
  171. X# $XConsortium: sunLib.rules,v 1.7 91/12/20 11:19:47 rws Exp $
  172. X
  173. X.c.o:
  174. X    $(CC) -c $(CFLAGS) $*.c
  175. X
  176. X# -------------------------------------------------------------------------
  177. X# site-specific configuration parameters that go after
  178. X# the platform-specific parameters - edit site.def to change
  179. X
  180. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  181. X
  182. X            SHELL = /bin/sh
  183. X
  184. X              TOP = .
  185. X      CURRENT_DIR = .
  186. X
  187. X               AR = ar clq
  188. X  BOOTSTRAPCFLAGS =
  189. X               CC = gcc
  190. X               AS = as
  191. X
  192. X         COMPRESS = compress
  193. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  194. X    PREPROCESSCMD = gcc -E $(STD_CPP_DEFINES)
  195. X          INSTALL = install
  196. X               LD = ld
  197. X             LINT = lint
  198. X      LINTLIBFLAG = -C
  199. X         LINTOPTS = -axz
  200. X               LN = ln -s
  201. X             MAKE = make
  202. X               MV = mv
  203. X               CP = cp
  204. X
  205. X           RANLIB = ranlib
  206. X  RANLIBINSTFLAGS =
  207. X
  208. X               RM = rm -f
  209. X            TROFF = psroff
  210. X         MSMACROS = -ms
  211. X              TBL = tbl
  212. X              EQN = eqn
  213. X     STD_INCLUDES =
  214. X  STD_CPP_DEFINES =
  215. X      STD_DEFINES =
  216. X EXTRA_LOAD_FLAGS =
  217. X  EXTRA_LIBRARIES =
  218. X             TAGS = ctags
  219. X
  220. X    SHAREDCODEDEF = -DSHAREDCODE
  221. X         SHLIBDEF = -DSUNSHLIB
  222. X
  223. X    PROTO_DEFINES =
  224. X
  225. X     INSTPGMFLAGS =
  226. X
  227. X     INSTBINFLAGS = -m 0755
  228. X     INSTUIDFLAGS = -m 4755
  229. X     INSTLIBFLAGS = -m 0644
  230. X     INSTINCFLAGS = -m 0444
  231. X     INSTMANFLAGS = -m 0444
  232. X     INSTDATFLAGS = -m 0444
  233. X    INSTKMEMFLAGS = -g kmem -m 2755
  234. X
  235. X      CDEBUGFLAGS = -O2
  236. X        CCOPTIONS =
  237. X
  238. X      ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
  239. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(DEFINES)
  240. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  241. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  242. X
  243. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  244. X
  245. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(LOCAL_LDFLAGS)
  246. X
  247. X   LDCOMBINEFLAGS = -X -r
  248. X      DEPENDFLAGS =
  249. X
  250. X        MACROFILE = sun.cf
  251. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  252. X
  253. X    IMAKE_DEFINES =
  254. X
  255. X         IRULESRC = $(CONFIGDIR)
  256. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  257. X
  258. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  259. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  260. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  261. X
  262. X# -------------------------------------------------------------------------
  263. X# X Window System Build Parameters
  264. X# $XConsortium: Project.tmpl,v 1.138.1.1 92/11/11 09:49:19 rws Exp $
  265. X
  266. X# -------------------------------------------------------------------------
  267. X# X Window System make variables; this need to be coordinated with rules
  268. X
  269. X          PATHSEP = /
  270. X        USRLIBDIR = /usr/lib
  271. X           BINDIR = /usr/bin/X11
  272. X          INCROOT = /usr/include
  273. X     BUILDINCROOT = $(TOP)
  274. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  275. X      BUILDINCTOP = ..
  276. X           INCDIR = $(INCROOT)/X11
  277. X           ADMDIR = /usr/adm
  278. X           LIBDIR = $(USRLIBDIR)/X11
  279. X        CONFIGDIR = $(LIBDIR)/config
  280. X       LINTLIBDIR = $(USRLIBDIR)/lint
  281. X
  282. X          FONTDIR = $(LIBDIR)/fonts
  283. X         XINITDIR = $(LIBDIR)/xinit
  284. X           XDMDIR = $(LIBDIR)/xdm
  285. X           TWMDIR = $(LIBDIR)/twm
  286. X          MANPATH = /usr/man
  287. X    MANSOURCEPATH = $(MANPATH)/man
  288. X        MANSUFFIX = n
  289. X     LIBMANSUFFIX = 3
  290. X           MANDIR = $(MANSOURCEPATH)$(MANSUFFIX)
  291. X        LIBMANDIR = $(MANSOURCEPATH)$(LIBMANSUFFIX)
  292. X           NLSDIR = $(LIBDIR)/nls
  293. X        PEXAPIDIR = $(LIBDIR)/PEX
  294. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  295. X       FONTCFLAGS = -t
  296. X
  297. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  298. X
  299. X            IMAKE = imake
  300. X           DEPEND = makedepend
  301. X              RGB = rgb
  302. X
  303. X            FONTC = bdftopcf
  304. X
  305. X        MKFONTDIR = mkfontdir
  306. X        MKDIRHIER = mkdirhier
  307. X
  308. X        CONFIGSRC = $(TOP)/config
  309. X       DOCUTILSRC = $(TOP)/doc/util
  310. X        CLIENTSRC = $(TOP)/clients
  311. X          DEMOSRC = $(TOP)/demos
  312. X           LIBSRC = $(TOP)/lib
  313. X          FONTSRC = $(TOP)/fonts
  314. X       INCLUDESRC = $(TOP)/X11
  315. X        SERVERSRC = $(TOP)/server
  316. X          UTILSRC = $(TOP)/util
  317. X        SCRIPTSRC = $(UTILSRC)/scripts
  318. X       EXAMPLESRC = $(TOP)/examples
  319. X       CONTRIBSRC = $(TOP)/../contrib
  320. X           DOCSRC = $(TOP)/doc
  321. X           RGBSRC = $(TOP)/rgb
  322. X        DEPENDSRC = $(UTILSRC)/makedepend
  323. X         IMAKESRC = $(CONFIGSRC)
  324. X         XAUTHSRC = $(LIBSRC)/Xau
  325. X          XLIBSRC = $(LIBSRC)/X
  326. X           XMUSRC = $(LIBSRC)/Xmu
  327. X       TOOLKITSRC = $(LIBSRC)/Xt
  328. X       AWIDGETSRC = $(LIBSRC)/Xaw
  329. X       OLDXLIBSRC = $(LIBSRC)/oldX
  330. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  331. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  332. X      BDFTOSNFSRC = $(FONTSRC)/clients/bdftosnf
  333. X      BDFTOPCFSRC = $(FONTSRC)/clients/bdftopcf
  334. X     MKFONTDIRSRC = $(FONTSRC)/clients/mkfontdir
  335. X         FSLIBSRC = $(FONTSRC)/lib/fs
  336. X    FONTSERVERSRC = $(FONTSRC)/server
  337. X     EXTENSIONSRC = $(TOP)/extensions
  338. X         XILIBSRC = $(EXTENSIONSRC)/lib/xinput
  339. X        PEXLIBSRC = $(EXTENSIONSRC)/lib/PEXlib
  340. X      PHIGSLIBSRC = $(EXTENSIONSRC)/lib/PEX
  341. X
  342. X# $XConsortium: sunLib.tmpl,v 1.14.1.2 92/11/11 09:55:02 rws Exp $
  343. X
  344. XSHLIBLDFLAGS = -assert pure-text
  345. XPICFLAGS = -fpic
  346. X
  347. X  DEPEXTENSIONLIB =
  348. X     EXTENSIONLIB = -lXext
  349. X
  350. X          DEPXLIB = $(DEPEXTENSIONLIB)
  351. X             XLIB = $(EXTENSIONLIB) -lX11
  352. X
  353. X        DEPXMULIB = $(USRLIBDIR)/libXmu.sa.$(SOXMUREV)
  354. X       XMULIBONLY = -lXmu
  355. X           XMULIB = -lXmu
  356. X
  357. X       DEPOLDXLIB =
  358. X          OLDXLIB = -loldX
  359. X
  360. X      DEPXTOOLLIB = $(USRLIBDIR)/libXt.sa.$(SOXTREV)
  361. X         XTOOLLIB = -lXt
  362. X
  363. X        DEPXAWLIB = $(USRLIBDIR)/libXaw.sa.$(SOXAWREV)
  364. X           XAWLIB = -lXaw
  365. X
  366. X        DEPXILIB =
  367. X           XILIB = -lXi
  368. X
  369. X        DEPPEXLIB =
  370. X           PEXLIB = -lPEX5
  371. X
  372. X        SOXLIBREV = 4.10
  373. X          SOXTREV = 4.10
  374. X         SOXAWREV = 5.0
  375. X        SOOLDXREV = 4.10
  376. X         SOXMUREV = 4.10
  377. X        SOXEXTREV = 4.10
  378. X      SOXINPUTREV = 4.10
  379. X         SOPEXREV = 1.0
  380. X
  381. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  382. X         XAUTHLIB =  -lXau
  383. X      DEPXDMCPLIB = $(USRLIBDIR)/libXdmcp.a
  384. X         XDMCPLIB =  -lXdmcp
  385. X
  386. X        DEPPHIGSLIB = $(USRLIBDIR)/libphigs.a
  387. X           PHIGSLIB =  -lphigs
  388. X
  389. X       DEPXBSDLIB = $(USRLIBDIR)/libXbsd.a
  390. X          XBSDLIB =  -lXbsd
  391. X
  392. X LINTEXTENSIONLIB = $(LINTLIBDIR)/llib-lXext.ln
  393. X         LINTXLIB = $(LINTLIBDIR)/llib-lX11.ln
  394. X          LINTXMU = $(LINTLIBDIR)/llib-lXmu.ln
  395. X        LINTXTOOL = $(LINTLIBDIR)/llib-lXt.ln
  396. X          LINTXAW = $(LINTLIBDIR)/llib-lXaw.ln
  397. X           LINTXI = $(LINTLIBDIR)/llib-lXi.ln
  398. X          LINTPEX = $(LINTLIBDIR)/llib-lPEX5.ln
  399. X        LINTPHIGS = $(LINTLIBDIR)/llib-lphigs.ln
  400. X
  401. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  402. X
  403. X         DEPLIBS1 = $(DEPLIBS)
  404. X         DEPLIBS2 = $(DEPLIBS)
  405. X         DEPLIBS3 = $(DEPLIBS)
  406. X
  407. X# -------------------------------------------------------------------------
  408. X# Imake rules for building libraries, programs, scripts, and data files
  409. X# rules:  $XConsortium: Imake.rules,v 1.123 91/09/16 20:12:16 rws Exp $
  410. X
  411. X# -------------------------------------------------------------------------
  412. X# start of Imakefile
  413. X
  414. XDEPLIBS = $(DEPXLIB)
  415. X
  416. XLOCAL_LIBRARIES = $(XLIB) $(XTOOLLIB) $(XAWLIB) $(XMULIB)
  417. X
  418. XINCLUDES = -I/usr/include/X11
  419. X
  420. XSRCS = main.c readfile.c game.c init.c widgets.c attributes.c
  421. XOBJS = main.o readfile.o game.o init.o widgets.o attributes.o
  422. X
  423. X PROGRAM = kdrill
  424. X
  425. Xall:: kdrill
  426. X
  427. Xkdrill: $(OBJS) $(DEPLIBS)
  428. X    $(RM) $@
  429. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  430. X
  431. Xinstall:: kdrill
  432. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  433. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  434. X    $(INSTALL) -c $(INSTPGMFLAGS)  kdrill $(DESTDIR)$(BINDIR)
  435. X
  436. Xinstall.man:: kdrill.man
  437. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  438. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  439. X    $(INSTALL) -c $(INSTMANFLAGS) kdrill.man $(DESTDIR)$(MANDIR)/kdrill.$(MANSUFFIX)
  440. X
  441. Xdepend::
  442. X    $(DEPEND) $(DEPENDFLAGS) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  443. X
  444. Xlint:
  445. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  446. Xlint1:
  447. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  448. X
  449. Xclean::
  450. X    $(RM) $(PROGRAM)
  451. X
  452. X# -------------------------------------------------------------------------
  453. X# common rules for all Makefiles - do not edit
  454. X
  455. Xemptyrule::
  456. X
  457. Xclean::
  458. X    $(RM_CMD) "#"*
  459. X
  460. XMakefile::
  461. X    -@if [ -f Makefile ]; then set -x; \
  462. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  463. X    else exit 0; fi
  464. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  465. X
  466. Xtags::
  467. X    $(TAGS) -w *.[ch]
  468. X    $(TAGS) -xw *.[ch] > TAGS
  469. X
  470. X# -------------------------------------------------------------------------
  471. X# empty rules for directories that do not have SUBDIRS - do not edit
  472. X
  473. Xinstall::
  474. X    @echo "install in $(CURRENT_DIR) done"
  475. X
  476. Xinstall.man::
  477. X    @echo "install.man in $(CURRENT_DIR) done"
  478. X
  479. XMakefiles::
  480. X
  481. Xincludes::
  482. X
  483. X# -------------------------------------------------------------------------
  484. X# dependencies generated by makedepend
  485. X
  486. END_OF_FILE
  487.   if test 10277 -ne `wc -c <'Makefile'`; then
  488.     echo shar: \"'Makefile'\" unpacked with wrong size!
  489.   fi
  490.   # end of 'Makefile'
  491. fi
  492. if test -f 'defs.h' -a "${1}" != "-c" ; then 
  493.   echo shar: Will not clobber existing file \"'defs.h'\"
  494. else
  495.   echo shar: Extracting \"'defs.h'\" \(1146 characters\)
  496.   sed "s/^X//" >'defs.h' <<'END_OF_FILE'
  497. X/*
  498. X * defs.h for kdrill
  499. X *   Okay, I lied.. this file has struct definitions, as
  500. X *   well as the #defines
  501. X */
  502. Xextern int errno;
  503. X
  504. X/* enum for "changemode()" */
  505. Xenum { GUESSMEANING, GUESSKANJI,TOGGLEKANA};
  506. X
  507. X
  508. Xstruct translationstruct {
  509. X
  510. X    char *english;    /* english translation string.
  511. X             * null-terminated.
  512. X             * Can theoretically be any length, but
  513. X             * since it will all be on a single-line
  514. X             * text widget, that would be silly
  515. X             */
  516. X
  517. X    int frequency;        /* frequency that kanji is used */
  518. X    int grade_level;    /* akin to  school class level */
  519. X    XChar2b *pronunciation;
  520. X
  521. X};
  522. X
  523. X/********************************************************************
  524. X
  525. XSO here's the format for the translation/dictionary file I have decided
  526. Xon so far:
  527. X
  528. XI changed specs. it will have to be in "kanjidic" format...
  529. X
  530. XTwo char high-bit-set identifier, followed by JIS number in hex.
  531. XFollowed by stroke information? [HAS TO BE TERMINATED BY 'Gx', where
  532. X                  'x' is any number]
  533. XFollowed by pronunciation guide, in kana.
  534. XFollowed by various english translations, enclosed in {}
  535. X
  536. X"kanjidic" often has multiple {} phrases. which leads to another nasty
  537. Xhack  in readstructs()
  538. X
  539. X*/
  540. END_OF_FILE
  541.   if test 1146 -ne `wc -c <'defs.h'`; then
  542.     echo shar: \"'defs.h'\" unpacked with wrong size!
  543.   fi
  544.   # end of 'defs.h'
  545. fi
  546. if test -f 'game.c' -a "${1}" != "-c" ; then 
  547.   echo shar: Will not clobber existing file \"'game.c'\"
  548. else
  549.   echo shar: Extracting \"'game.c'\" \(7453 characters\)
  550.   sed "s/^X//" >'game.c' <<'END_OF_FILE'
  551. X#include <stdio.h>
  552. X#include <X11/Xlib.h>
  553. X#include <X11/Xatom.h>
  554. X#include <X11/Xutil.h>
  555. X#include <Intrinsic.h>
  556. X#include <StringDefs.h>
  557. X#include <Xaw/Command.h>
  558. X
  559. X#include "defs.h"
  560. X#include "externs.h"
  561. X
  562. Xint values[4];
  563. Xint truevalue;
  564. Xint Kanji2English=GUESSKANJI;
  565. Xint showEnglish = True;
  566. Xint doBell = True;
  567. X
  568. Xextern Display *display;
  569. Xextern Window mainwindow;
  570. X
  571. Xint englishwidth=7;
  572. Xint englishheight=11;
  573. X
  574. X/* setstatus:
  575. X *  sets label for main status bar widget.
  576. X *    ( the long one at the bottom)
  577. X */
  578. Xvoid setstatus(s)
  579. Xchar *s;
  580. X{
  581. X    XtVaSetValues(statusline,
  582. X              XtNlabel,s,
  583. X              NULL);
  584. X}
  585. X
  586. X/*
  587. X*UseThisKanji()
  588. X*    Returns Boolean value on whether this is a "valid" kanji for us,
  589. X*    based on usefile markings,
  590. X*    current grade set,
  591. X*    and whether it has english/kana translation
  592. X*/
  593. XBoolean UseThisKanji(kanji)
  594. Xstruct translationstruct *kanji;
  595. X{
  596. X    /* nonexistant? */
  597. X    if(kanji == NULL) return False;
  598. X
  599. X    /* "do not read", set by inituse ?*/
  600. X    if(kanji == (void *) 1) return False; 
  601. X
  602. X    if(showEnglish){
  603. X        if(kanji->english == NULL)
  604. X            return False;
  605. X        if(kanji->english[0] == '\0')
  606. X            return False;
  607. X    } else {
  608. X        /* we're supposed to be showing kana.. are there any? */
  609. X        if(kanji->pronunciation == NULL)
  610. X            return False;
  611. X    }
  612. X
  613. X    /* only thing left is to check grade level */
  614. X
  615. X    if(gradelevel == 0)
  616. X        return True;
  617. X    if(kanji->grade_level == 0)
  618. X            return False;
  619. X
  620. X    if(kanji->grade_level > gradelevel)
  621. X        return False;
  622. X
  623. X    return True;    
  624. X}
  625. X
  626. X
  627. X/* CountKanji
  628. X *This routine gets called a hell of a lot:
  629. X *    When we change grade level, and
  630. X *    when we change kana/english display.
  631. X *     (the secnd being because kanjidic does not always have
  632. X *     english and/or kana listings
  633. X */
  634. Xvoid CountKanji(){
  635. X    int counter;
  636. X    numberofkanji=0;
  637. X    for(counter=lowest;counter <=highest;counter++){
  638. X        if(UseThisKanji(translations[counter])){
  639. X            numberofkanji++;
  640. X        }
  641. X    }
  642. X}
  643. X
  644. X/* pickkanji:
  645. X *   picks an acceptably random kanji char
  646. X */
  647. X
  648. Xint pickkanji(){
  649. X    int rand_kanji,count;
  650. X    
  651. X
  652. X    rand_kanji = random()%numberofkanji;
  653. X
  654. X    for(count=lowest;count<=highest;count++){
  655. X        if(UseThisKanji(translations[count])){
  656. X              rand_kanji--;
  657. X              if(rand_kanji <0)
  658. X              return count;
  659. X        }
  660. X    }
  661. X    fprintf(stderr,"Internal error: picked kanji out of range");
  662. X    return 0;
  663. X
  664. X}
  665. X
  666. X/* printkanji:
  667. X *    updates all the kanji buttons.
  668. X */
  669. X
  670. Xvoid printkanji(){
  671. X    int i,knum;
  672. X    XChar2b onecharstring[2];
  673. X
  674. X    onecharstring[1].byte1 = onecharstring[1].byte2 = 0;
  675. X
  676. X    if(Kanji2English == GUESSKANJI){
  677. X        knum = values[truevalue];
  678. X        onecharstring[0].byte1 = (knum & 0xff00)>>8;
  679. X        onecharstring[0].byte2 = (knum & 0x00ff);
  680. X
  681. X        XtVaSetValues(kanjiWidget[0],XtNlabel,onecharstring,NULL);
  682. X        XtVaSetValues(kanjiWidget[1],XtNlabel,"  ",NULL);
  683. X        XtVaSetValues(kanjiWidget[2],XtNlabel,"  ",NULL);
  684. X        XtVaSetValues(kanjiWidget[3],XtNlabel,"  ",NULL);
  685. X        return;
  686. X    }
  687. X    /* else */
  688. X    for(i=0;i<4;i++) {
  689. X        knum = values[i];
  690. X
  691. X        onecharstring[0].byte1 = (knum & 0xff00)>>8;
  692. X        onecharstring[0].byte2 = (knum & 0x00ff);
  693. X
  694. X
  695. X        XtVaSetValues(kanjiWidget[i],
  696. X                  XtNlabel,onecharstring,
  697. X                  XtNsensitive,True,
  698. X                  NULL);
  699. X
  700. X    }
  701. X}
  702. X
  703. X/* SetWidgetLabel:
  704. X *    Convenience function to
  705. X *    set label of four lines of english/kana.
  706. X *    Will change fonts, dependant on "showEnglish"
  707. X */
  708. Xvoid SetWidgetLabel(widget,Tnum)
  709. XWidget widget;
  710. Xint Tnum;
  711. X{
  712. X
  713. X    if(showEnglish == True){
  714. X        XtVaSetValues(widget,
  715. X                 XtNencoding,XawTextEncoding8bit,
  716. X                 XtNfont,fixedfont,
  717. X                 XtNlabel,translations[Tnum]->english,
  718. X                 NULL);
  719. X    } else {
  720. X        XtVaSetValues(widget,
  721. X                 XtNencoding,XawTextEncodingChar2b,
  722. X                 XtNfont,smallkfont,
  723. X                 NULL);
  724. X        XtVaSetValues(widget,
  725. X                  XtNlabel,translations[Tnum]->pronunciation,
  726. X                  NULL);
  727. X    }
  728. X}
  729. X/* printenglish()
  730. X *  similar to printkanji()
  731. X *  updates all "english" labels...
  732. X *  EXCEPT: sometimes we want then to print kana! :-) so we use
  733. X *  SetWidgetLabel() to do the correct type
  734. X */
  735. Xvoid printenglish(){
  736. X    int i;
  737. X
  738. X    /* we must be guessing which character for one meaning */
  739. X    if(Kanji2English == GUESSMEANING){
  740. X        SetWidgetLabel(englishWidget[0],values[truevalue]);
  741. X        XtVaSetValues(englishWidget[1],XtNlabel,"  ",XtNsensitive,False,NULL);
  742. X        XtVaSetValues(englishWidget[2],XtNlabel,"  ",XtNsensitive,False,NULL);
  743. X        XtVaSetValues(englishWidget[3],XtNlabel,"  ",XtNsensitive,False,NULL);
  744. X        return;
  745. X    }
  746. X    /* ELSE */
  747. X    /* we have all FOUR  active for picking*/
  748. X    for(i=0;i<4;i++){
  749. X        XtVaSetValues(englishWidget[i],XtNsensitive,True,NULL);
  750. X        SetWidgetLabel(englishWidget[i],values[i]);
  751. X    }
  752. X}
  753. X
  754. X
  755. X/* kanjitoenglish
  756. X *    sets up question...
  757. X *    { "what does this symbol? choose one of the four choices"}
  758. X *    
  759. X *    then returns, presumably falling back to XtAppMainLoop()
  760. X *
  761. X *    guesskanji == GUESSKANJI : give kanji, and user guesses the meaning
  762. X *                    int English
  763. X *    guesskanji == GUESSENGLISH : give english, and user guesses which
  764. X *                    kanji fits best. 
  765. X */
  766. Xvoid kanjitoenglish(guesskanji)
  767. Xint guesskanji;
  768. X{
  769. X    int doloop;
  770. X    Kanji2English=guesskanji;
  771. X
  772. X    /* determine which value will be correct one.. */
  773. X    truevalue = random() %4;
  774. X
  775. X    /* hack for random numbers...
  776. X     * only picks values that are acceptable by our current
  777. X     *  "usefile"
  778. X     */
  779. X    values[0] = pickkanji();
  780. X    values[1] = pickkanji();
  781. X    values[2] = pickkanji();
  782. X    values[3] = pickkanji();
  783. X
  784. X    /* now weed out duplicates.. */
  785. X    doloop = 0;
  786. X    do{
  787. X        if((values[0] == values[1]) || (values[0] == values[2])
  788. X            || values[0] == values[3] ){
  789. X            values[0] = pickkanji();
  790. X            doloop=1;
  791. X        } else
  792. X        if(values[1] == values[2] || values[1] == values[3]){
  793. X            values[1] = pickkanji();
  794. X            doloop=1;
  795. X        } else 
  796. X        if(values[2] == values[3]){
  797. X            values[2] = pickkanji();
  798. X            doloop=1;
  799. X        } else
  800. X            doloop = 0;
  801. X    }while(doloop);
  802. X
  803. X    DescribeCurrent(values[truevalue]);
  804. X
  805. X    printkanji();    /* update labels */
  806. X    printenglish(); /* likewise      */
  807. X    switch(guesskanji){
  808. X        case GUESSKANJI:
  809. X            XtVaSetValues(kanjimode,XtNsensitive,False,NULL);
  810. X            XtVaSetValues(englishmode,XtNsensitive,True,NULL);
  811. X            break;
  812. X        case GUESSMEANING:
  813. X            XtVaSetValues(kanjimode,XtNsensitive,True,NULL);
  814. X            XtVaSetValues(englishmode,XtNsensitive,False,NULL);
  815. X            break;
  816. X    }
  817. X    
  818. X}
  819. X
  820. X
  821. X/* englishcallback:
  822. X *    Handles clicking on "english" widgets.
  823. X *    Only really neccessary if we are guessing the meaning of a
  824. X *    kanji character
  825. X */
  826. Xvoid englishcallback(w,data,calldata)
  827. XWidget w;
  828. XXtPointer data;XtPointer calldata;
  829. X{
  830. X    if(Kanji2English!= GUESSKANJI)
  831. X        return;
  832. X    if(data == (XtPointer) truevalue){
  833. X        setstatus("Correct!");
  834. X        kanjitoenglish(GUESSKANJI);
  835. X    } else {
  836. X        if(doBell)
  837. X            XBell(display,100);
  838. X        setstatus("Incorrect.");
  839. X    }
  840. X
  841. X}
  842. X
  843. X/*
  844. X *handles top four kanji buttons at top
  845. X */
  846. Xvoid kanjicallback(w,data,calldata)
  847. XWidget w;XtPointer data;XtPointer calldata;
  848. X{
  849. X    if(Kanji2English != GUESSMEANING)
  850. X        return;
  851. X    if(data == (XtPointer) truevalue){
  852. X        setstatus("Correct!");
  853. X        kanjitoenglish(GUESSMEANING);
  854. X    } else {
  855. X        if(doBell)
  856. X            XBell(display,100);
  857. X        setstatus("Incorrect.");
  858. X    }
  859. X}
  860. X
  861. X
  862. X/* changemode:
  863. X *   change from guessing kanji to guessing english, or vica verse,
  864. X *    by clicking on the appropriate button
  865. X *
  866. X *   Also handles changing from english <->kana display,
  867. X *   calling CountKanji(), because we have to .
  868. X */
  869. Xvoid ChangeMode(w,data,calldata)
  870. XWidget w;XtPointer data;XtPointer calldata;
  871. X{
  872. X    int whichbutton = (int) data;
  873. X#ifdef DEBUG
  874. X    printf("button mode change: %d\n",whichbutton);
  875. X#endif
  876. X    switch(whichbutton){
  877. X        case GUESSMEANING:
  878. X        case GUESSKANJI:
  879. X            kanjitoenglish(whichbutton);
  880. X            break;
  881. X        case TOGGLEKANA:
  882. X#ifdef DEBUG
  883. X            puts("We toggle kana/english now");
  884. X#endif
  885. X            showEnglish = !showEnglish;
  886. X            CountKanji();
  887. X            kanjitoenglish(Kanji2English);
  888. X            break;
  889. X    }
  890. X}
  891. X
  892. END_OF_FILE
  893.   if test 7453 -ne `wc -c <'game.c'`; then
  894.     echo shar: \"'game.c'\" unpacked with wrong size!
  895.   fi
  896.   # end of 'game.c'
  897. fi
  898. if test -f 'init.c' -a "${1}" != "-c" ; then 
  899.   echo shar: Will not clobber existing file \"'init.c'\"
  900. else
  901.   echo shar: Extracting \"'init.c'\" \(5423 characters\)
  902.   sed "s/^X//" >'init.c' <<'END_OF_FILE'
  903. X#include <stdlib.h>
  904. X#include <stdio.h>
  905. X
  906. X#include <Xos.h>
  907. X#include <Intrinsic.h>
  908. X#include <StringDefs.h>
  909. X#include <Shell.h>
  910. X#include <Xaw/Command.h>
  911. X#include <Xaw/Label.h>
  912. X#include <Xaw/Form.h>
  913. X#include <Composite.h>
  914. X#include "defs.h"
  915. X#include "externs.h"
  916. X
  917. X#include "icon.xbm"
  918. X
  919. XXFontStruct *largekfont;
  920. XXFontStruct *smallkfont;
  921. XXFontStruct *fixedfont;
  922. X
  923. X/* I should just get rid of this, but I might use it at some
  924. X * later date
  925. X */
  926. Xstatic XtActionsRec actionlist[] = {
  927. X    { "quit",quit },
  928. X};
  929. X
  930. X/*
  931. X * We  must have these resources set!!
  932. X *
  933. X * ( Note the similarity between this stuff and optionDescList[].
  934. X *   coincidence? I think not :-)
  935. X */
  936. Xstatic char *fallback[] = {
  937. X    "KDrill.noBell:     0",
  938. X    "KDrill*usefile:    usefile", 
  939. X    "KDrill*dictfile:   kanjidic",
  940. X    "KDrill*kanjifont:  kanji24",
  941. X    "KDrill*smallkanji: kanji16",
  942. X    "KDrill*font:       fixed",
  943. X    "KDrill*gradelevel: 0",
  944. X    "KDrill*showkana:   0",
  945. X    NULL
  946. X};
  947. X
  948. X/* command line arguments should set the appropriate resources.. so we can
  949. X * pull them out when wanted
  950. X */
  951. Xstatic XrmOptionDescRec optionDescList[] = {
  952. X    {"-usefile",    ".usefile",    XrmoptionSepArg,(caddr_t) NULL},
  953. X    {"-dictfile",    ".dictfile",    XrmoptionSepArg,(caddr_t) NULL},
  954. X    {"-font",    ".font",    XrmoptionSepArg,(caddr_t) NULL},
  955. X    {"-kanjifont",    ".kanjifont",    XrmoptionSepArg,(caddr_t) NULL},
  956. X    {"-smallkanji",    ".smallkanji",    XrmoptionSepArg,(caddr_t) NULL},
  957. X    {"-noBell",     ".noBell",    XrmoptionNoArg, "1"},
  958. X    {"-guessmeaning",".guessmeaning",XrmoptionNoArg,"1"},
  959. X    {"-gradelevel", ".gradelevel",  XrmoptionSepArg,(caddr_t) NULL},    
  960. X    {"-showkana",   ".showkana",    XrmoptionNoArg,"1"},
  961. X};
  962. X
  963. X
  964. X
  965. X/* initgc:
  966. X *    Initialises global gc values.
  967. X *      We don't really need this any more. But
  968. X *    GC's are good to have, I suppose.
  969. X */
  970. Xvoid initgc(){
  971. X
  972. X    gc =  XCreateGC(display,mainwindow,0,NULL);
  973. X    cleargc = XCreateGC(display,mainwindow,0,NULL);
  974. X
  975. X    XSetForeground(display,gc,black);
  976. X    XSetBackground(display,gc,white);
  977. X    XSetForeground(display,cleargc,white);
  978. X    XSetBackground(display,cleargc,black);
  979. X
  980. X}
  981. X
  982. X/* getusefile:
  983. X *    Gets a "usefile", to abridge the full dictionary.
  984. X *    If possible, will get it from the user's home directory,
  985. X *    otherwise, tries current directory
  986. X */
  987. XFILE *getusefile(){
  988. X    FILE *f;
  989. X    char *homedir;
  990. X    char fullname[100];
  991. X
  992. X    if(usefile == NULL) return NULL;
  993. X    fullname[0] = '\0';
  994. X    if(usefile[0] == '~'){
  995. X        homedir = (char *) getenv("HOME");
  996. X        if(homedir == NULL){
  997. X            perror("Cannot expand '~' char. no HOME env. varriable");
  998. X            exit(0);
  999. X        }
  1000. X        sprintf(fullname,"%s%s",homedir,usefile);
  1001. X    } else {
  1002. X        strcpy(fullname,usefile);
  1003. X    }
  1004. X
  1005. X    if((f = fopen(fullname,"r")) == NULL){
  1006. X        puts("no usefile. using entire dictionary...");
  1007. X        usefile = NULL;
  1008. X    } else {
  1009. X        printf("using \"%s\" to abridge dictionary\n",fullname);
  1010. X    }
  1011. X    return f;
  1012. X}
  1013. X
  1014. X/* inituse:
  1015. X *    clear out global array of 'translations' (really abridgements),
  1016. X *    and set what kanji chars are appropriate to check on.
  1017. X *
  1018. X *    we set "okay" chars to have a NULL pointer stored for them in the
  1019. X *    translation table, since later, we will want to check if
  1020. X *    malloc malloc'd them properly.
  1021. X *
  1022. X *     unacceptable chars have a pointer stored of (void *) 1
  1023. X *
  1024. X *    We should really redo this.. but either way, there would
  1025. X *    seem to be a conflict as to whether we have actually
  1026. X *    malloced memory that starts at 0x00000001, or whatever.
  1027. X *    (on a sparc, that will never happen :-) 
  1028. X *    
  1029. X */
  1030. Xvoid inituse(){
  1031. X    FILE *f;
  1032. X    int i;
  1033. X    char inbuf[100];
  1034. X
  1035. X    f = getusefile();
  1036. X
  1037. X    /* set all translations flags == NULL.
  1038. X     *    NULL means it's okay to use this character
  1039. X     *    
  1040. X     */
  1041. X    if(usefile == NULL){
  1042. X        i = 0x2000;
  1043. X        while(i<0x8000){
  1044. X            translations[i++] = (void *)NULL;
  1045. X        }
  1046. X        return;
  1047. X    } else {    /* set all to UNREADABLE, for now */
  1048. X        i = 0x2000;
  1049. X        while(i<0x8000){
  1050. X            translations[i++] = (void *)1;
  1051. X        }
  1052. X    }
  1053. X
  1054. X    while(fgets(inbuf,99,f) != NULL){
  1055. X        int usechar;
  1056. X        usechar = xtoi(inbuf);
  1057. X        if( usechar<0x8000)
  1058. X            translations[usechar] = NULL;
  1059. X    }
  1060. X
  1061. X}
  1062. X
  1063. X
  1064. X/* initstuffs:
  1065. X *    calls the various init routines to setup
  1066. X *    GCs, fonts, dictionaries, and widgets
  1067. X *    (But initializing the translations is done later)
  1068. X */
  1069. X
  1070. Xstatic Pixmap iconpixmap;
  1071. X
  1072. Xvoid initstuffs(argc,argv)
  1073. Xint *argc;
  1074. Xchar *argv[];
  1075. X{
  1076. X    char tempnumber[10];
  1077. X    XWMHints wmhints;
  1078. X
  1079. X    srandom (time(NULL));
  1080. X
  1081. X    toplevel = XtVaAppInitialize(&Context,"KDrill",
  1082. X                    optionDescList,XtNumber(optionDescList),
  1083. X                    argc,argv,
  1084. X                   fallback,
  1085. X                    NULL,NULL);
  1086. X
  1087. X    if(*argc >1){
  1088. X        usage();
  1089. X    }
  1090. X
  1091. X    /* this don't work?!! */
  1092. X    doBell = !GetXtBoolean("noBell","NoBell");
  1093. X
  1094. X
  1095. X    if(GetXtBoolean("guessmeaning","Guessmeaning"))
  1096. X        Kanji2English = GUESSMEANING;
  1097. X    GetXtString("gradelevel","Gradelevel",tempnumber);
  1098. X    gradelevel = atoi(tempnumber);
  1099. X    if(gradelevel>6){
  1100. X        fprintf(stderr,"Grade level >6: defaulting to All (0)\n");
  1101. X        gradelevel = 0;
  1102. X    }
  1103. X
  1104. X    /* display set in here */
  1105. X    MakeWidgets();
  1106. X
  1107. X    XtAppAddActions(Context,actionlist,XtNumber(actionlist));
  1108. X    XtRealizeWidget(toplevel);
  1109. X    mainwindow = XtWindow(form);
  1110. X
  1111. X    iconpixmap = XCreateBitmapFromData(display,mainwindow,
  1112. X                       icon_bits,icon_width,icon_height);
  1113. X
  1114. X    XtVaSetValues(toplevel,XtNiconName,"kdrill",
  1115. X                XtNiconPixmap,iconpixmap,
  1116. X                NULL);
  1117. X#ifdef OLDWAY
  1118. Xwmhints.icon_pixmap = iconpixmap;
  1119. X    wmhints.flags = IconPixmapHint;
  1120. X
  1121. X    XSetWMProperties(display,mainwindow,"kdrill","kdrill",
  1122. X            NULL,NULL, /* argv,argc */
  1123. X            NULL,&wmhints,NULL); /* size, wmhints, classhints */
  1124. X#endif /* OLDWAY */
  1125. X
  1126. X
  1127. X    white = WhitePixel(display,0);
  1128. X    black = BlackPixel(display,0);
  1129. X    initgc();
  1130. X    SetBackingStore(display,XtScreen(toplevel),XtWindow(toplevel));
  1131. X    
  1132. X}
  1133. END_OF_FILE
  1134.   if test 5423 -ne `wc -c <'init.c'`; then
  1135.     echo shar: \"'init.c'\" unpacked with wrong size!
  1136.   fi
  1137.   # end of 'init.c'
  1138. fi
  1139. if test -f 'main.c' -a "${1}" != "-c" ; then 
  1140.   echo shar: Will not clobber existing file \"'main.c'\"
  1141. else
  1142.   echo shar: Extracting \"'main.c'\" \(5363 characters\)
  1143.   sed "s/^X//" >'main.c' <<'END_OF_FILE'
  1144. X
  1145. X#include <stdio.h>
  1146. X
  1147. X#include <Xlib.h>
  1148. X#include <Xatom.h>
  1149. X#include <Xutil.h>
  1150. X#include <Intrinsic.h>
  1151. X#include <StringDefs.h>
  1152. X#include <Xaw/Command.h>
  1153. X#include <Xaw/Label.h>
  1154. X#include <Xaw/Form.h>
  1155. X#include <Composite.h>
  1156. X
  1157. X#include "defs.h"
  1158. X#include "externs.h"
  1159. X#include "patchlevel.h"
  1160. X
  1161. Xstatic char *version = VERSION;
  1162. X
  1163. XDisplay *display;
  1164. Xint screen;
  1165. XWindow mainwindow,rootwindow;
  1166. XGC gc,cleargc;
  1167. XXtAppContext Context;
  1168. X
  1169. Xchar *dictname=NULL;
  1170. Xchar *usefile=NULL;
  1171. Xchar kanjifontname[100];
  1172. X
  1173. XXChar2b *kstring;
  1174. XXChar2b onecharstring;
  1175. X
  1176. Xunsigned long white,black;
  1177. X
  1178. X
  1179. X
  1180. X/* quitbutton, of course */
  1181. Xvoid quit(w,data,calldata)
  1182. XWidget w;
  1183. XXtPointer data,calldata;
  1184. X{
  1185. X#ifdef DEBUG
  1186. X    puts("quitting?");
  1187. X#endif
  1188. X    XtCloseDisplay(display);
  1189. X    exit(0);
  1190. X}
  1191. X
  1192. X
  1193. Xint usage(){
  1194. X    printf(" kdrill    -- Version %s\n",version);
  1195. X    fflush(stdout);
  1196. X    puts("A program to drill on kanji to english, or vica versa");
  1197. X    puts("");
  1198. X    puts("Options:");
  1199. X    puts("  -usefile usefilename         changes abridgement file of dictionary");
  1200. X    puts("  -dictfile dictfilename       changes dictionary file from");
  1201. X    puts("                               \"kanjidic\" to some other file");
  1202. X    puts("  -font fontname               changes english font");
  1203. X    puts("  -kanjifont Kanjifontname     changes LARGE kanji font");
  1204. X    puts("  -smallkanji Kanjifontname    changes small kanji font");
  1205. X    puts("  -noBell                      turns off beep for incorrect answer");
  1206. X    puts("  -guessmeaning                starts off with four kanji to one meaning");
  1207. X    puts("  -gradelevel                  define cut-off grade level:");
  1208. X    puts("                                6 is highest limit, 0 means no restrictions");
  1209. X    puts("  -showkana                    start showing kana meanings instead of english");
  1210. X    puts("");
  1211. X    puts("       The above options can also be set as resources,");
  1212. X    puts("       with the same name as their optionflag");
  1213. X    puts("");
  1214. X    exit(0);
  1215. X}
  1216. X
  1217. X/* keypress:
  1218. X * return whether got strnage key (shift, etc), or normal key.
  1219. X * returns 0 on normal key, or exits program if 'q' hit
  1220. X */
  1221. Xint keypress(key)
  1222. Xint key;
  1223. X{
  1224. X    if(key == 61)
  1225. X        exit(0);
  1226. X    else
  1227. X
  1228. X        /* sun codes for shift, control, etc */
  1229. X    switch(key){
  1230. X        case 106:
  1231. X        case 83:
  1232. X        case 26:
  1233. X            return 1;
  1234. X            break;
  1235. X        default:
  1236. X            /* printf("Got keypress %d\n",key); */
  1237. X            return 0;
  1238. X    }
  1239. X}
  1240. X
  1241. X/* GetXtNumber(), GetXtBoolean(), GetXtString():
  1242. X *    Not the "best way" to get resources...
  1243. X *    supposed to read them all in at one go.
  1244. X *    But I had reasons for reading things in at different times,
  1245. X *    and I have stuck to that model
  1246. X */
  1247. X
  1248. X/* GetXtNumber:
  1249. X *    Given resource name and and class, will attempt to look up
  1250. X *    resource value in database.
  1251. X *    Will return default of 0!!!
  1252. X */
  1253. Xint GetXtNumber(name,class)
  1254. Xchar *name,*class;
  1255. X{
  1256. X    Cardinal resourcevalue;
  1257. X    char resourcename[100],resourceclass[100];
  1258. X    XtResource resourceList=    {
  1259. X        NULL,NULL,
  1260. X        XtRCardinal,sizeof(int),0,
  1261. X        XtRCardinal,0
  1262. X    };
  1263. X
  1264. X    resourceList.resource_name = resourcename;
  1265. X    resourceList.resource_class = resourceclass;
  1266. X
  1267. X    strcpy(resourcename,name);
  1268. X    strcpy(resourceclass,class);
  1269. X
  1270. X    XtGetApplicationResources(toplevel,&resourcevalue,
  1271. X                  &resourceList,1,
  1272. X                  NULL,0);
  1273. X    return resourcevalue;
  1274. X}
  1275. X/* GetXtBoolean()
  1276. X*    see GetXtNumber
  1277. X*/
  1278. XBoolean GetXtBoolean(name,class)
  1279. Xchar *name,*class;
  1280. X{
  1281. X    Boolean resourcevalue;
  1282. X    char resourcename[100],resourceclass[100];
  1283. X
  1284. X    XtResource resourceList ={
  1285. X        NULL,NULL,
  1286. X        XtRBoolean,sizeof(Boolean),0,
  1287. X        XtRBoolean,False,
  1288. X    };
  1289. X    resourceList.resource_name = resourcename;
  1290. X    resourceList.resource_class = resourceclass;
  1291. X
  1292. X    strcpy(resourcename,name);
  1293. X    strcpy(resourceclass,class);
  1294. X
  1295. X    XtGetApplicationResources(toplevel,&resourcevalue,
  1296. X                  &resourceList,1,
  1297. X                  NULL,0);
  1298. X    return resourcevalue;
  1299. X}
  1300. X
  1301. X
  1302. X/* GetXtString:
  1303. X *    Given the resource name and class, will
  1304. X *     copy the resource string value to
  1305. X *     destinationstring address.
  1306. X *    Destination must be MALLOCED ARRAY!!!
  1307. X */
  1308. Xvoid GetXtString(name,class,destinationstring)
  1309. Xchar *name,*class;
  1310. Xchar *destinationstring;
  1311. X{
  1312. X    char resourcename[100],resourceclass[100];
  1313. X    char buffer[100];
  1314. X    char *returnstring = buffer;
  1315. X    
  1316. X
  1317. X    XtResource resourceList ={
  1318. X        NULL,NULL,
  1319. X        XtRString,sizeof(char *),0,
  1320. X        XtRString,"NOT SET"
  1321. X    };
  1322. X    resourceList.resource_name = resourcename;
  1323. X    resourceList.resource_class = resourceclass;
  1324. X
  1325. X    strcpy(resourcename,name);
  1326. X    strcpy(resourceclass,class);
  1327. X
  1328. X    XtGetApplicationResources(toplevel,&returnstring,
  1329. X                  &resourceList,1,
  1330. X                  NULL,0);
  1331. X    strcpy(destinationstring,returnstring);
  1332. X}
  1333. X
  1334. Xint main(argc,argv)
  1335. Xint argc;
  1336. Xchar *argv[];
  1337. X{
  1338. X
  1339. X    char usefilename[100],dict[100];
  1340. X
  1341. X    initstuffs(&argc,argv);
  1342. X
  1343. X    puts("Reading in dictionary: please wait a few moments...");
  1344. X
  1345. X    GetXtString("usefile","Usefile",usefilename);
  1346. X    GetXtString("dictfile","Dictfile",dict);
  1347. X    dictname = dict;
  1348. X    usefile = usefilename;
  1349. X#ifdef DEBUG
  1350. X    puts("");
  1351. X    printf("usefile from resources is \"%s\"\n",usefilename);
  1352. X    printf("dictfile from resources is\" %s\"\n",dictname);
  1353. X#endif
  1354. X
  1355. X    /* check for abridgements of the dictionary... */
  1356. X    inituse();
  1357. X    /* and actually read in structs of dictionary */
  1358. X    readstructs(&argc,argv);
  1359. X
  1360. X    showEnglish = ! GetXtBoolean("showkana","Showkana");
  1361. X    CountKanji();
  1362. X    if(numberofkanji<8){
  1363. X        fprintf(stderr,"There are two few kanji readable in the current configuration\n");
  1364. X        fprintf(stderr,"Please either reconfigure your usefile, or raise the grade level\n");
  1365. X        exit(0);
  1366. X    }
  1367. X
  1368. X    
  1369. X    kanjitoenglish(Kanji2English);
  1370. X    /* if pass 0, means want to guess english */
  1371. X    XtAppMainLoop(Context);
  1372. X    return 0;
  1373. X}
  1374. END_OF_FILE
  1375.   if test 5363 -ne `wc -c <'main.c'`; then
  1376.     echo shar: \"'main.c'\" unpacked with wrong size!
  1377.   fi
  1378.   # end of 'main.c'
  1379. fi
  1380. if test -f 'readfile.c' -a "${1}" != "-c" ; then 
  1381.   echo shar: Will not clobber existing file \"'readfile.c'\"
  1382. else
  1383.   echo shar: Extracting \"'readfile.c'\" \(7193 characters\)
  1384.   sed "s/^X//" >'readfile.c' <<'END_OF_FILE'
  1385. X/*
  1386. X * This file is for just setting up the structs, etc
  1387. X */
  1388. X
  1389. X#include <stdlib.h>
  1390. X#include <stdio.h>
  1391. X#include <ctype.h>
  1392. X#include <Xfuncs.h>
  1393. X#include <Xlib.h>
  1394. X#include <Xatom.h>
  1395. X#include <Xutil.h>
  1396. X#include <Intrinsic.h>
  1397. X#include <StringDefs.h>
  1398. X#include <Xos.h>
  1399. X
  1400. X#include "defs.h"
  1401. X#include "externs.h"
  1402. X
  1403. X/* translations[] keeps track of which kanji it is okay to test the
  1404. X *    user on. Likewise with numberofkanji, highest, and lowest.
  1405. X *    YES, it is best to keep in a large array, otherwise
  1406. X *    it would be difficult to switch between grade levels.
  1407. X */
  1408. Xstruct translationstruct *translations[0x8000];
  1409. Xint numberofkanji,highest,lowest;
  1410. X
  1411. X
  1412. X/* random debugging util? */
  1413. Xvoid printline(s)
  1414. Xunsigned char *s;
  1415. X{
  1416. X    while(*s){
  1417. X        putchar(*s++);
  1418. X    }
  1419. X    putchar('\n');
  1420. X}
  1421. X
  1422. X/* Since there is no standard util to convert hex ascii to int,...
  1423. X *  have to supply our own..
  1424. X *  It isn't incredibly efficient.. let's hope the compiler is smart.
  1425. X *  arrg..
  1426. X */
  1427. Xint xtoi(s)
  1428. Xchar * s;
  1429. X{
  1430. X    int out=0;
  1431. X    sscanf(s,"%x",&out);
  1432. X    return out;
  1433. X}
  1434. X
  1435. X/* getline:
  1436. X *    reads a line (from dictionary).
  1437. X *    returns true (1) if read aline, otherwise,
  1438. X *    returns false (0);
  1439. X *
  1440. X *    used in "readstructs", below.
  1441. X */
  1442. X
  1443. Xunsigned char instring[2][512];
  1444. Xunsigned char *inptr=NULL;
  1445. Xint whichstring;
  1446. X
  1447. Xint getline(fp,s)
  1448. XFILE *fp;
  1449. Xunsigned char *s;
  1450. X{
  1451. X    if(inptr==NULL){
  1452. X        inptr= &instring[0][100];
  1453. X        whichstring=0;
  1454. X    }
  1455. X    for(;;){
  1456. X        int i;
  1457. X        if(inptr == &instring[whichstring][100]){
  1458. X            whichstring = 1-whichstring;
  1459. X            inptr=instring[whichstring];
  1460. X            i=fread(instring[whichstring],1,100,fp);
  1461. X            if(i<100){
  1462. X                instring[whichstring][i]='\0';
  1463. X                /* okay, we put the termination signal in.
  1464. X                 * But if there is a complete line in there,
  1465. X                 * it should be read with our buffering
  1466. X                 */
  1467. X            }
  1468. X        }
  1469. X        switch(*inptr){
  1470. X            case 0:
  1471. X                *s = '\0';
  1472. X                return 0;
  1473. X            case 10:
  1474. X            case 13:
  1475. X                *inptr='\0';
  1476. X                *s++ = *inptr++;
  1477. X                return 1;
  1478. X            default:
  1479. X                *s++ = *inptr++;
  1480. X        }
  1481. X    }
  1482. X}
  1483. X
  1484. X/* nextword:
  1485. X *    Goes to first whitespace, then sets pointer to
  1486. X *    beginning of non-white-space.
  1487. X *
  1488. X *    Returns 1 on success, 0 on fail
  1489. X */
  1490. Xint nextword(stringp)
  1491. Xchar ** stringp;
  1492. X{
  1493. X    while(!isspace(**stringp)){
  1494. X        if(stringp == '\0')
  1495. X            return 0;
  1496. X        *stringp +=1;
  1497. X    }
  1498. X    /* now on space */
  1499. X    while(isspace(**stringp)){
  1500. X        if(stringp == '\0')
  1501. X            return 0;
  1502. X        *stringp +=1;
  1503. X    }
  1504. X    return 1;
  1505. X    
  1506. X}
  1507. X
  1508. X/* nextchar:
  1509. X * returns pointer to next non-whitespace char
  1510. X*/
  1511. Xunsigned char *nextchar(c)
  1512. Xunsigned char *c;
  1513. X{
  1514. X    while(isspace(*c)){
  1515. X        if(*c == '\0') break;
  1516. X        c++;
  1517. X    }
  1518. X    return c;
  1519. X}
  1520. X
  1521. X/* StripBrackets:
  1522. X *    Gets rid of those annoying {enlish}{english2} brackets.
  1523. X *    PRESUMES first char of source is '{'!!
  1524. X *      Well, actually, it nicely sets a null string if otherwise.
  1525. X */
  1526. Xvoid StripBrackets(dest,source)
  1527. Xchar *dest,*source;
  1528. X{
  1529. X    char *parse = &source[1];
  1530. X
  1531. X    if(source[0] != '{'){
  1532. X        dest[0] = '\0';
  1533. X        return;
  1534. X    }
  1535. X    /* (*dest) is always assumed to be needing a write */
  1536. X
  1537. X    do {
  1538. X        switch(*parse){
  1539. X            case '{':
  1540. X                *dest++ = ':';
  1541. X                *dest++ = ' ';
  1542. X                break;
  1543. X            case '}':
  1544. X                break;
  1545. X            default:
  1546. X                *dest++ = *parse;                
  1547. X        }
  1548. X        parse++;
  1549. X    } while((*parse != '\n') && (*parse != '\0'));
  1550. X    *dest = '\0';
  1551. X    return;
  1552. X}
  1553. X
  1554. X
  1555. X/* Okay, it's not actually pronunciation we're reading.
  1556. X * We are reading the "no-yoni" and "kun-yoni" interpretation
  1557. X * in kanjidic
  1558. X */
  1559. Xvoid ReadPronunciation(Pstring,kanjinum)
  1560. Xint kanjinum;
  1561. Xchar **Pstring;
  1562. X{
  1563. X    XChar2b kanabuffer[256];
  1564. X    XChar2b *pronunciation;
  1565. X    int pronun_len;
  1566. X    unsigned char *parse = (unsigned char *) *Pstring;
  1567. X
  1568. X    pronunciation = kanabuffer;
  1569. X    /* "bad" job here.. this is just to get things working..
  1570. X     * this method will probably skip a few kana
  1571. X     */
  1572. X
  1573. X    if(*parse == '{'){
  1574. X        /* only english exists, so set to null */
  1575. X        translations[kanjinum] == NULL;
  1576. X        return;
  1577. X    }
  1578. X    
  1579. X    while((*parse > 127) && (*parse != '\0')){
  1580. X        /* kanjidic seems to have high bit set on
  1581. X         * Kana.. which we need to strip both of!!
  1582. X         */
  1583. X        pronunciation->byte1= (*parse++ & 0x7f);
  1584. X        pronunciation->byte2= (*parse++ & 0x7f);
  1585. X        pronunciation++;
  1586. X        /* skip space, and put in divider if
  1587. X         * second reading is there
  1588. X         */
  1589. X        while(*parse == ' ') {
  1590. X            parse++;
  1591. X            if(*parse == '\0')
  1592. X                break;
  1593. X            if(*parse >127){
  1594. X               pronunciation->byte1 = 0x21;
  1595. X               pronunciation->byte2 = 0x27;
  1596. X               pronunciation++;
  1597. X            }
  1598. X        }
  1599. X    }
  1600. X    pronunciation->byte1=pronunciation->byte2 = 0;
  1601. X    pronun_len = strlen((char *) kanabuffer);
  1602. X
  1603. X    translations[kanjinum]->pronunciation =
  1604. X        (XChar2b *) malloc(pronun_len+4);
  1605. X    if(translations[kanjinum]->pronunciation == NULL){
  1606. X        fprintf(stderr,"Not enough memory to read in dictionary\n");
  1607. X        exit(0);
  1608. X    }
  1609. X    strncpy(translations[kanjinum]->pronunciation, kanabuffer, pronun_len+1);
  1610. X
  1611. X    /* now position parse pointer for next step:
  1612. X     *  reading english
  1613. X     */
  1614. X    while(*parse != '{'){
  1615. X        if(*parse == '\0'){
  1616. X            return;
  1617. X        }
  1618. X        parse++;
  1619. X    }
  1620. X
  1621. X    *Pstring = (char *)parse;
  1622. X}
  1623. X
  1624. X/* readstructs:
  1625. X *    the main dictionary reading routine.
  1626. X *    Fills in the global translationstruct with
  1627. X *    all that is available for each selected kanji, in
  1628. X *    Grade, "pronunciation", english translation, and
  1629. X *    frequency of use (by native speakers)
  1630. X */
  1631. Xvoid readstructs(){
  1632. X    unsigned char instring[256];
  1633. X    FILE *fp;
  1634. X
  1635. X    lowest = highest = 0x3000;
  1636. X    fp = fopen(dictname,"r");
  1637. X    if(fp == NULL){
  1638. X        perror("cannot open kanji translation file");
  1639. X        fprintf(stderr,"Looking for %s\n",dictname);
  1640. X        exit(0);
  1641. X    }
  1642. X
  1643. X    while (getline(fp,instring) != 0) {
  1644. X        int Kanji;
  1645. X        int freq,grade;
  1646. X        unsigned char *parse;
  1647. X        int instrlen;    /* length of pronunciation */
  1648. X
  1649. X        if(strlen(instring) <10) continue;
  1650. X
  1651. X        /*try to get kanji Index right away */
  1652. X        Kanji = xtoi(&instring[2]);
  1653. X
  1654. X
  1655. X        /* skip comments, and kanji not specified in
  1656. X         * the usefile
  1657. X         */    
  1658. X        if( (Kanji < 0x3000) || (translations[Kanji] != NULL) ){
  1659. X            continue;
  1660. X        }
  1661. X
  1662. X        parse = &instring[2];
  1663. X        if(parse == NULL){
  1664. X            continue;
  1665. X        }
  1666. X        /* now parse for grade level, frequency, and english */
  1667. X        freq = grade = 0;
  1668. X
  1669. X        nextword(&parse);
  1670. X        /* check for high bit set, which means
  1671. X         * start of kana definition of kana
  1672. X         */
  1673. X        /* used to have (*parse != '{')  */
  1674. X        while ( (*parse < 127)  && (*parse != '{') ) {
  1675. X            
  1676. X            switch(*parse){
  1677. X                case 'G':
  1678. X                    grade = atoi(++parse);
  1679. X                    break;
  1680. X                case 'F':
  1681. X                    freq = atoi(++parse);
  1682. X                    break;
  1683. X                default:
  1684. X                    break;
  1685. X            }
  1686. X            nextword(&parse);
  1687. X        }
  1688. X        
  1689. X        
  1690. X        /**********************************************
  1691. X         *  Now we know that we have a useable/wanted *
  1692. X         *  dictionary definition                     *
  1693. X         *********************************************/
  1694. X
  1695. X        if(Kanji<lowest) lowest = Kanji;
  1696. X        if (Kanji >highest) highest = Kanji;
  1697. X        
  1698. X        translations[Kanji] = (struct translationstruct *)
  1699. X            malloc(sizeof(struct translationstruct));
  1700. X        if (translations[Kanji] == NULL){
  1701. X            perror("Cannot allocate memory for translation table\n");
  1702. X            exit(errno);
  1703. X        }
  1704. X        translations[Kanji]->frequency = freq;
  1705. X        translations[Kanji]->grade_level = grade;
  1706. X
  1707. X        ReadPronunciation(&parse,Kanji);
  1708. X        /*
  1709. X         * translations[Kanji]->pronunciation[0].byte1=0;
  1710. X         * translations[Kanji]->pronunciation[0].byte2=0;
  1711. X         */
  1712. X
  1713. X
  1714. X        instrlen = strlen(parse)+1;
  1715. X        translations[Kanji]->english = (char *) malloc(instrlen);
  1716. X        if(translations[Kanji]->english == NULL){
  1717. X            perror("Cannot allocate memory for translation table\n");
  1718. X            exit(errno);        
  1719. X        }
  1720. X
  1721. X        StripBrackets(translations[Kanji]->english,parse);
  1722. X
  1723. X    } /* and repeat until end of file */
  1724. X}
  1725. X
  1726. END_OF_FILE
  1727.   if test 7193 -ne `wc -c <'readfile.c'`; then
  1728.     echo shar: \"'readfile.c'\" unpacked with wrong size!
  1729.   fi
  1730.   # end of 'readfile.c'
  1731. fi
  1732. if test -f 'widgets.c' -a "${1}" != "-c" ; then 
  1733.   echo shar: Will not clobber existing file \"'widgets.c'\"
  1734. else
  1735.   echo shar: Extracting \"'widgets.c'\" \(7005 characters\)
  1736.   sed "s/^X//" >'widgets.c' <<'END_OF_FILE'
  1737. X#include <stdio.h>
  1738. X
  1739. X#include <Xos.h>
  1740. X#include <Intrinsic.h>
  1741. X#include <StringDefs.h>
  1742. X#include <Xaw/Command.h>
  1743. X#include <Xaw/Label.h>
  1744. X#include <Xaw/Form.h>
  1745. X#include <Composite.h>
  1746. X#include "defs.h"
  1747. X#include "externs.h"
  1748. X
  1749. XWidget toplevel,form,quitbutton,statusline;
  1750. XWidget gradedisplay;
  1751. XWidget currentkanjiForm,currentkanjiGrade,currentkanjiFreq,currentkanjiNum;
  1752. XWidget kanjimode,englishmode,togglekana;
  1753. XWidget englishWidget[4],kanjiWidget[4];
  1754. X
  1755. Xint gradelevel=0;
  1756. X
  1757. X char *gradelist[8] = {
  1758. X    "Grade: All  ",
  1759. X    "Grade: One  ",
  1760. X    "Grade: Two  ",
  1761. X    "Grade: Three",
  1762. X    "Grade: Four ",
  1763. X    "Grade: Five ",
  1764. X    "Grade: Six  ",
  1765. X    "Grade: ERROR!"
  1766. X};
  1767. Xvoid changegrade(widget,data,calldata)
  1768. XWidget widget;
  1769. XXtPointer data; XtPointer calldata;
  1770. X{
  1771. X    gradelevel = gradelevel +1;
  1772. X    if(gradelevel ==7) gradelevel = 0;
  1773. X    
  1774. X    XtVaSetValues(widget,
  1775. X              XtNlabel,gradelist[gradelevel],
  1776. X              NULL);
  1777. X
  1778. X    /* need to recount all kanji equal or below the current level */
  1779. X    CountKanji();
  1780. X    if(numberofkanji<9){
  1781. X        XtVaSetValues(statusline,XtNlabel,"Too Few Kanji",NULL);
  1782. X        fprintf(stderr,"Too Few Kanji\n");
  1783. X        if(gradelevel==0){
  1784. X            fprintf("You must have either a too-small usefile,or a corrupted kanjidic\n");
  1785. X            exit(0);
  1786. X        }
  1787. X        changegrade(0,0,0);
  1788. X        return;
  1789. X    }
  1790. X    /* and make another puzzle... */
  1791. X    kanjitoenglish(Kanji2English);
  1792. X    return;
  1793. X}
  1794. X
  1795. X/* DescribeCurrent()
  1796. X *    Sets labels to display difficulty of
  1797. X *    Current "true" kanji"
  1798. X */
  1799. Xvoid DescribeCurrent(kanjinum)
  1800. Xint kanjinum;
  1801. X{
  1802. X    char gradelabel[10],freqlabel[10],numlabel[10];
  1803. X
  1804. X
  1805. X
  1806. X    if(translations[kanjinum]->grade_level !=0){
  1807. X        sprintf(gradelabel,"G: %4d",translations[kanjinum]->grade_level);
  1808. X    } else {
  1809. X        sprintf(gradelabel,"G:     ");
  1810. X    }
  1811. X    if(translations[kanjinum]->frequency !=0){
  1812. X        sprintf(freqlabel,"F: %4d",translations[kanjinum]->frequency);
  1813. X#ifdef DEBUG
  1814. X    printf("Describing %x\n",kanjinum);
  1815. X    printf("Freqnum %d\n",translations[kanjinum]->frequency);
  1816. X#endif
  1817. X
  1818. X    } else {
  1819. X        sprintf(freqlabel,"F:     ");
  1820. X    }
  1821. X    sprintf(numlabel,"#: %4x",kanjinum);
  1822. X
  1823. X    XtVaSetValues(currentkanjiGrade,XtNlabel,gradelabel,NULL);
  1824. X    XtVaSetValues(currentkanjiFreq,XtNlabel,freqlabel,NULL);
  1825. X    XtVaSetValues(currentkanjiNum,XtNlabel,numlabel,NULL);
  1826. X}
  1827. X
  1828. X/* MakeKanjiButtons()
  1829. X *  set up kanji button widgets at initialization
  1830. X */
  1831. Xvoid MakeKanjiButtons(){
  1832. X    int i;
  1833. X    /* make KANJI buttons */
  1834. X    for(i=0;i<4;i++){
  1835. X        char labl[20];
  1836. X        sprintf(labl,"kanji%d",i);
  1837. X
  1838. X        kanjiWidget[i]=XtVaCreateManagedWidget(
  1839. X            labl,commandWidgetClass,
  1840. X            form,
  1841. X                  XtNlabel,"",
  1842. X                  XtNwidth,50, XtNheight,50,
  1843. X                  XtNshapeStyle,XawShapeOval,
  1844. X                  XtNencoding,XawTextEncodingChar2b,
  1845. X                  XtNfont,largekfont,
  1846. X                  NULL);
  1847. X        XtAddCallback(kanjiWidget[i],XtNcallback,kanjicallback,(XtPointer)i);
  1848. X        if(i>0){
  1849. X            XtVaSetValues(kanjiWidget[i],
  1850. X                      XtNfromHoriz,kanjiWidget[i-1],
  1851. X                      NULL);
  1852. X        }
  1853. X
  1854. X    }
  1855. X    currentkanjiForm = XtVaCreateManagedWidget(
  1856. X            "curkanjiForm",formWidgetClass,form,
  1857. X            XtNhorizDistance,40,
  1858. X            XtNright,XawChainRight,XtNleft,XawChainRight,
  1859. X            XtNfromHoriz,kanjiWidget[3],NULL);
  1860. X    currentkanjiGrade = XtVaCreateManagedWidget(
  1861. X            "curkanjiGrade",labelWidgetClass,currentkanjiForm,
  1862. X            XtNlabel,"G:     ",
  1863. X            NULL);
  1864. X    currentkanjiFreq = XtVaCreateManagedWidget(
  1865. X            "curkanjiFreq",labelWidgetClass,currentkanjiForm,
  1866. X            XtNlabel,"F:     ",
  1867. X            XtNfromVert,currentkanjiGrade,
  1868. X            NULL);
  1869. X    currentkanjiNum = XtVaCreateManagedWidget(
  1870. X            "curkanjiNum",labelWidgetClass,currentkanjiForm,
  1871. X            XtNlabel,"#:     ",
  1872. X            XtNfromVert,currentkanjiFreq,
  1873. X            NULL);
  1874. X}
  1875. X/* MakeEnglishButtons:
  1876. X * Just that. initialize the english buttons that display the possible
  1877. X * guesses.
  1878. X */
  1879. Xvoid MakeEnglishButtons(){
  1880. X    int i;
  1881. X    for(i=0;i<4;i++){
  1882. X        char labl[20];
  1883. X        sprintf(labl,"english%d",i);
  1884. X
  1885. X        englishWidget[i]=XtVaCreateManagedWidget(
  1886. X            labl,commandWidgetClass,form,
  1887. X            XtNwidth,320,
  1888. X            XtNright,XawChainRight,
  1889. X            XtNleft,XawChainLeft,
  1890. X            XtNfont,fixedfont,
  1891. X            NULL);
  1892. X        
  1893. X        XtAddCallback(englishWidget[i],XtNcallback,englishcallback,(XtPointer) i);
  1894. X
  1895. X        if(i==0){
  1896. X            XtVaSetValues(englishWidget[0],
  1897. X                      XtNfromVert,currentkanjiForm,
  1898. X                      XtNvertDistance,10,
  1899. X                      NULL);
  1900. X        } else {
  1901. X            XtVaSetValues(englishWidget[i],
  1902. X                      XtNfromVert,englishWidget[i-1],
  1903. X                      NULL);
  1904. X        }
  1905. X        
  1906. X
  1907. X    }
  1908. X}
  1909. X
  1910. Xvoid initfonts(){
  1911. X    char LargeKname[100],SmallKname[100],Fixedname[100];
  1912. X
  1913. X    GetXtString("kanjifont","Kanjifont",LargeKname);
  1914. X    GetXtString("smallkanji","Smallkanji",SmallKname);
  1915. X    GetXtString("font","Font",Fixedname);
  1916. X
  1917. X#ifdef DEBUG
  1918. X    printf("kanjifont from resources is \"%s\"\n",LargeKname);
  1919. X    printf("smallkanjifont from resources is \"%s\"\n",SmallKname);
  1920. X    printf("regular font from resources is \"%s\"\n",Fixedname);
  1921. X#endif
  1922. X    largekfont = XLoadQueryFont(display,LargeKname);
  1923. X    smallkfont = XLoadQueryFont(display,SmallKname);
  1924. X    fixedfont  = XLoadQueryFont(display,Fixedname);
  1925. X    if(largekfont == NULL){
  1926. X        fprintf(stderr,"could not load large kanji font\n");
  1927. X        exit(0);
  1928. X    }
  1929. X    if(smallkfont == NULL){
  1930. X        fprintf(stderr,"could not load small kanji font\n");
  1931. X        exit(0);
  1932. X    }
  1933. X    if(fixedfont == NULL){
  1934. X        fprintf(stderr,"could not load english font??\n");
  1935. X        exit(0);
  1936. X    }
  1937. X    
  1938. X
  1939. X}
  1940. X
  1941. Xint MakeWidgets(){
  1942. X    /* I suppose I shouldn't hard-code window-width and height..
  1943. X        but it makes things easier for now.
  1944. X    */
  1945. X    form = XtVaCreateManagedWidget("kdrill",formWidgetClass,
  1946. X                       toplevel,
  1947. X              XtNx,200, XtNy,100,
  1948. X              NULL);
  1949. X
  1950. X    
  1951. X    display = XtDisplay(toplevel);
  1952. X
  1953. X    initfonts();
  1954. X
  1955. X    MakeKanjiButtons();
  1956. X    MakeEnglishButtons();
  1957. X
  1958. X    kanjimode = XtVaCreateManagedWidget(
  1959. X            "kanjimode",commandWidgetClass, form,
  1960. X            XtNlabel,"Guess kanji",
  1961. X            XtNvertDistance,20,
  1962. X            XtNfromVert,englishWidget[3],
  1963. X            XtNshapeStyle,XawShapeOval,
  1964. X            NULL);
  1965. X    XtAddCallback(kanjimode,XtNcallback,ChangeMode,(XtPointer) GUESSKANJI);
  1966. X
  1967. X    englishmode = XtVaCreateManagedWidget(
  1968. X            "englishmode",commandWidgetClass, form,
  1969. X            XtNlabel,"Guess Meaning",
  1970. X            XtNvertDistance,20,
  1971. X            XtNfromVert,englishWidget[3],
  1972. X            XtNshapeStyle,XawShapeOval,
  1973. X            XtNfromHoriz,kanjimode,
  1974. X            NULL);
  1975. X    XtAddCallback(englishmode,XtNcallback,ChangeMode,(XtPointer) GUESSMEANING);
  1976. X
  1977. X    togglekana = XtVaCreateManagedWidget("togglekana",commandWidgetClass,
  1978. X                          form,
  1979. X            XtNlabel,"English/Kana",
  1980. X            XtNvertDistance,20,
  1981. X            XtNfromVert,englishWidget[3],
  1982. X            XtNshapeStyle,XawShapeOval,
  1983. X            XtNfromHoriz,englishmode,
  1984. X            NULL);
  1985. X    XtAddCallback(togglekana,XtNcallback,ChangeMode,(XtPointer) TOGGLEKANA);
  1986. X
  1987. X
  1988. X    quitbutton = XtVaCreateManagedWidget("quit",commandWidgetClass,
  1989. X                         form,
  1990. X              XtNlabel,"quit",
  1991. X              XtNfromVert,kanjimode,
  1992. X              XtNshapeStyle,XawShapeEllipse,
  1993. X              NULL);
  1994. X
  1995. X    XtAddCallback(quitbutton,XtNcallback,quit,NULL);
  1996. X
  1997. X    statusline = XtVaCreateManagedWidget("status",labelWidgetClass,
  1998. X                         form,
  1999. X              XtNlabel,"Welcome to kanjidrill",
  2000. X              XtNfromHoriz,quitbutton,
  2001. X              XtNfromVert,kanjimode,
  2002. X              XtNresize,True,
  2003. X              NULL);
  2004. X
  2005. X    gradedisplay = XtVaCreateManagedWidget(
  2006. X            "gradedisplay",commandWidgetClass,form,
  2007. X            XtNlabel,gradelist[gradelevel],
  2008. X            XtNresize,False,
  2009. X            XtNfromVert,kanjimode,
  2010. X            XtNfromHoriz,statusline,
  2011. X            NULL);
  2012. X    XtAddCallback(gradedisplay,XtNcallback,changegrade,NULL);
  2013. X
  2014. X    return 0;
  2015. X}
  2016. END_OF_FILE
  2017.   if test 7005 -ne `wc -c <'widgets.c'`; then
  2018.     echo shar: \"'widgets.c'\" unpacked with wrong size!
  2019.   fi
  2020.   # end of 'widgets.c'
  2021. fi
  2022. echo shar: End of archive 1 \(of 2\).
  2023. cp /dev/null ark1isdone
  2024. MISSING=""
  2025. for I in 1 2 ; do
  2026.     if test ! -f ark${I}isdone ; then
  2027.     MISSING="${MISSING} ${I}"
  2028.     fi
  2029. done
  2030. if test "${MISSING}" = "" ; then
  2031.     echo You have unpacked both archives.
  2032.     rm -f ark[1-9]isdone
  2033. else
  2034.     echo You still must unpack the following archives:
  2035.     echo "        " ${MISSING}
  2036. fi
  2037. exit 0
  2038. exit 0 # Just in case...
  2039. -- 
  2040.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  2041. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  2042.  "It's intuitively obvious to the |
  2043.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  2044.