1 /* raw_engine.c -- not a real recognizer, just a way to store raw strokes
2 
3    Copyright (C) 2000 Carl Worth
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <errno.h>
19 #include <string.h>
20 
21 #include "raw_engine.h"
22 #include "sprintf_alloc.h"
23 
24 #ifdef DMALLOC
25 #include "dmalloc.h"
26 #endif
27 
28 /* raw_engine_funcs are defined statically in rec_engine.c
29 rec_engine_funcs_t engine_funcs =
30 {
31     raw_priv_alloc,
32     raw_priv_free,
33     raw_feature_data_alloc,
34     raw_feature_data_free,
35     raw_classify_stroke,
36     raw_classification_str_alloc,
37     raw_free_classification,
38     raw_recognize_feature
39 };
40 */
41 
raw_priv_alloc(rec_engine_t * engine)42 int raw_priv_alloc(rec_engine_t *engine)
43 {
44     return 0;
45 }
46 
raw_priv_free(rec_engine_t * engine)47 void raw_priv_free(rec_engine_t *engine)
48 {
49     /* that's all she wrote */
50 }
51 
raw_feature_data_alloc(rec_engine_t * engine,char * feature_data_str)52 void *raw_feature_data_alloc(rec_engine_t *engine, char *feature_data_str)
53 {
54     stroke_t *stroke;
55     char *nptr, *endptr;
56     long x, y, time;
57 
58     stroke = malloc(sizeof(stroke_t));
59     if (stroke == NULL) {
60 	fprintf(stderr, "%s: Out of memory\n", __FUNCTION__);
61 	return NULL;
62     }
63 
64     stroke_init(stroke);
65     nptr = feature_data_str;
66     while (1) {
67 	x = strtol(nptr, &endptr, 0);
68 	if (endptr == nptr && endptr[0] != '\0') {
69 	    fprintf(stderr, "%s: Error parsing X value in raw stroke data at: %s\n",
70 		    __FUNCTION__, nptr);
71 	    break;
72 	}
73 	nptr = endptr + 1;
74 	y = strtol(nptr, &endptr, 0);
75 	if (endptr == nptr && endptr[0] != '\0') {
76 	    fprintf(stderr, "%s: Error parsing Y value in raw stroke data at: %s\n",
77 		    __FUNCTION__, nptr);
78 	    break;
79 	}
80 	nptr = endptr + 1;
81 	time = strtol(nptr, &endptr, 0);
82 	if (endptr == nptr && endptr[0] != '\0') {
83 	    fprintf(stderr, "%s: Error parsing time value in raw stroke data at: %s\n",
84 		    __FUNCTION__, nptr);
85 	    break;
86 	}
87 	nptr = endptr + 1;
88 	stroke_add_pt(stroke, x, y, time);
89 	if (endptr[0] == '\0') {
90 	    break;
91 	}
92     }
93 
94     return stroke;
95 }
96 
raw_feature_data_free(rec_engine_t * engine,void * feature_data)97 void raw_feature_data_free(rec_engine_t *engine, void *feature_data)
98 {
99     stroke_deinit((stroke_t *) feature_data);
100 }
101 
raw_classify_stroke(rec_engine_t * engine,stroke_t * stroke)102 void raw_classify_stroke(rec_engine_t *engine, stroke_t *stroke)
103 {
104     stroke->classifications[engine->num] = NULL;
105 }
106 
raw_classification_str_alloc(rec_engine_t * engine,stroke_t * stroke)107 char *raw_classification_str_alloc(rec_engine_t *engine, stroke_t *stroke)
108 {
109     return stroke_str_alloc(stroke);
110 }
111 
raw_free_classification(rec_engine_t * engine,stroke_t * stroke)112 void raw_free_classification(rec_engine_t *engine, stroke_t *stroke)
113 {
114     /* Nothing to do here */
115 }
116 
raw_recognize_stroke(rec_engine_t * engine,stroke_t * stroke,void * feature_data)117 double raw_recognize_stroke(rec_engine_t *engine, stroke_t *stroke,
118 			     void *feature_data)
119 {
120     /* raw_engine recognizes anything, (else the veryify will never work) */
121     return 1;
122 }
123 
raw_set_option(rec_engine_t * engine,char * name,char * value)124 int raw_set_option(rec_engine_t *engine, char *name, char *value)
125 {
126     return EINVAL;
127 }
128