1 /* -*- mode: C; c-file-style: "bsd"; tab-width: 4 -*- */
2 /* jstroke.h - System-independent functions/defines
3  * JStroke 1.x - Japanese Kanji handwriting recognition technology demo.
4  * Copyright (C) 1997  Robert E. Wells
5  * http://wellscs.com/pilot
6  * mailto:robert@wellscs.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program (gpl.html); if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * Derived from prior work by Todd David Rudick on JavaDict and StrokeDic.
23  * Makes use of KANJIDIC data from Jim Breen of Monash University.
24  * Further credit details available at http://wellscs.com/pilot
25  * See readme.txt, ChangeLog, and gpl.html for more information.
26  *
27  * CONDITIONAL COMPILATION FLAGS:
28  * -DFOR_PILOT_GCC -- Robert Wells uses this for code that is specific to the
29  *                US Robotics/3COM Pilot GCC development environment.
30  *                Contact robert@wellscs.com, http://wellscs.com/pilot.
31  *
32  * -DFOR_PILOT_COMPAT -- Owen Taylor uses this for his perl front-ended
33  *                application.  He puts this code in a subdirectory under the
34  *                rest of his code.  Contact owt1@cornell.edu for more
35  *                information, or visit his web site at
36  *                http://www.msc.cornell.edu/~otaylor/. 9/1997.
37  *
38  * -------------------------------------------------------------------------*/
39 #ifndef __JSTROKE_H__
40 #define __JSTROKE_H__
41 
42 #ifdef FOR_PILOT_COMPAT
43 #include "pilotcompat.h"
44 #endif /*FOR_PILOT_COMPAT*/
45 
46 #ifdef FOR_PILOT_GCC
47 #pragma pack(2)	// $$$ Probably not needed anymore... -rwells, 19970921.
48 #include <Common.h>
49 #include <System/SysAll.h>
50 #include <UI/UIAll.h>
51 #endif /*FOR_PILOT_GCC*/
52 
53 /* Limit list to what we can afford (5), or what will fit on screen at most.
54  * #define diMaxListCount     (diScreenHeight/diFontLineHeight)
55  */
56 #define diMaxListCount       5
57 #define diMaxXyPairs       256	/* Max pairs in stroke... */
58 
59 /* ----- List Memory ---------------------------------------------------------
60  * The idea here is to have a single nonmovable chunk of memory which contains
61  * all the structures and cross-pointers needed to support the item list for
62  * passing to LstSetListChoices, and related List control functions.  We
63  * allocate and free it as a single chunk of application memory.
64  */
65 
66 typedef struct {
67 	UInt   m_argc;
68 	char* m_argv[1];
69 } ListMem;
70 
71 /* ----- RawStroke ---------------------------------------------------------*/
72 
73 typedef struct {
74 	UInt   m_len;
75 	Byte   m_x[diMaxXyPairs];
76 	Byte   m_y[diMaxXyPairs];
77 } RawStroke;
78 
79 typedef struct
80 {
81     CharPtr      m_character;
82     CharPtr      m_strokes;
83     CharPtr      m_filters;
84 } StrokeDicEntry;
85 
86 typedef struct StrokeDicEntryListStruct
87 {
88 	StrokeDicEntry m_entry;
89 	struct StrokeDicEntryListStruct *m_next;
90 } StrokeDicEntryList;
91 
92 typedef StrokeDicEntryList* StrokeDic;
93 
94 typedef struct StrokeScorer *StrokeScorerPtr;
95 
96 /* ----- ScoreItem ---------------------------------------------------------*/
97 
98 typedef struct ScoreItemStruct *ScoreItemPtr;
99 
100 typedef struct ScoreItemStruct {
101 	ULong        m_iScore;
102     StrokeDicEntry      *m_cp;
103 } ScoreItem;
104 
105 /* ----- StrokeScorer------------------------------------------------------ */
106 
107 typedef struct StrokeScorerStruct {
108 	StrokeDic   m_cpStrokeDic;
109 	RawStroke*  m_pRawStrokes;
110 	UInt        m_iStrokeCnt;
111 	ScoreItem*  m_pScores;
112 	UInt        m_iScoreLen;
113 	CharPtr     m_cpPath;
114 } StrokeScorer;
115 
116 
117 ListMem*  AppEmptyList();
118 Long      Angle32(Long xdif, Long ydif);
119 void      ErrBox(CharPtr msg);
120 void      ErrBox2(CharPtr msg1, CharPtr msg2);
121 
122 /* Create a StrokeScorer object. (Returns NULL if can't get memory) */
123 StrokeScorer *StrokeScorerCreate  (StrokeDic cpStrokeDic, RawStroke *rsp,
124 			 					   UInt iStrokeCnt);
125 
126 /* Destroy a StrokeScorer object */
127 void          StrokeScorerDestroy  (StrokeScorer *pScorer);
128 
129 /* Process some database entries (maximum iMaxCnt, -1 for all).
130  * Returns 0 when none remaining (should eventually return count remaining
131  * to facilitate a progressbar.
132  */
133 Long          StrokeScorerProcess  (StrokeScorer *pScorer, Long iMaxCnt);
134 
135 /* Return best diMaxListCount candidates processed so far */
136 ListMem*      StrokeScorerTopPicks (StrokeScorer *pScorer);
137 
138 #endif /*__JSTROKE_H__*/
139 /* ----- End of jstroke.h ------------------------------------------------- */
140