chiark / gitweb /
routetrade: put trades table below voyage plan; include toc
[ypp-sc-tools.db-test.git] / yarrg / convert.h
1 /*
2  * general header file for yarrg
3  */
4 /*
5  *  This is part of ypp-sc-tools, a set of third-party tools for assisting
6  *  players of Yohoho Puzzle Pirates.
7  * 
8  *  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
9  * 
10  *  This program is free software: you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation, either version 3 of the License, or
13  *  (at your option) any later version.
14  * 
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  * 
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  * 
23  *  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
24  *  are used without permission.  This program is not endorsed or
25  *  sponsored by Three Rings.
26  */
27
28 #ifndef CONVERT_H
29 #define CONVERT_H
30
31 #define DEBUG_FLAG_LIST                         \
32    DF(findypp)                                  \
33    DF(pages)                                    \
34    DF(rect)                                     \
35    DF(pixmap)                                   \
36    DF(struct)                                   \
37    DF(ocr)                                      \
38    DF(rsync)                                    \
39    DF(structcolon)                              \
40    DF(callout)
41
42
43 #include "common.h"
44 #include "ocr.h"
45
46 #include <fnmatch.h>
47 #include <pcre.h>
48 #include <pam.h>
49 #include <time.h>
50 #include <limits.h>
51
52 #include <sys/time.h>
53
54
55 /*----- from rgbimage.c -----*/
56
57 #define MAXIMGIDENT 100
58
59 typedef uint32_t Rgb; /* red<<0 | green<<8 | blue<<16 */
60
61 typedef struct RgbImage {
62   int w, h;
63   Rgb data[]; /* data[ y*w + x ] */
64 } RgbImage;
65
66 void identify_rgbimage(const RgbImage *base, Rect portion,
67                        char result[MAXIMGIDENT], const char *what);
68 RgbImage *alloc_rgb_image(int w, int h);
69 void fwrite_ppmraw(FILE *f, const RgbImage *ri);
70
71 #define RI_PIXEL32(ri,x,y) ((ri)->data + ((y)*(ri)->w + (x)))
72
73 static inline Rgb ri_rgb(const RgbImage *ri, int x, int y) {
74   return *RI_PIXEL32(ri,x,y);
75 }
76
77 /*----- from structure.c -----*/
78
79 typedef struct PageStruct PageStruct;
80
81 void find_structure(const CanonImage *im,
82                     PageStruct **pagestruct_r, /* caller must free() */
83                     int *max_relevant_y_r,
84                     Point *commod_focus_point_r,
85                     Point *commod_page_point_r,
86                     Point *commod_focuslast_point_r);
87 void store_current_page(CanonImage *ci /*pointer saved*/,
88                         PageStruct *pagestruct, /*freed*/
89                         RgbImage *rgb /*freed*/);
90 void adjust_colours(CanonImage *ci, const RgbImage *rgb);
91
92 void select_page(int page);
93 void check_pager_motion(int first, int stop);
94
95 Rect find_sunshine_widget(void);
96
97 void canon_colour_prepare(void);
98 void find_islandname(void);
99 void check_correct_commodities(void);
100 void read_screenshots(void);
101 void read_one_screenshot(void);
102 void analyse(FILE *tsv_output);
103
104 /*----- from convert.c -----*/
105
106 extern FILE *screenshot_file;
107 void fetch_with_rsync(const char *stem);
108 void fetch_with_rsync_gz(const char *stem);
109
110 enum flags {
111   ff_singlepage=          000002,
112   ff_testservers=         000004,
113
114   ff_charset_edit=        000010,
115   ff_charset_allowedit=   000020,
116   ff_charset_havelocal=   000040,
117   ffm_charset=            000070,
118   
119   ff_dict_fetch=          000100,
120   ff_dict_submit=         000200,
121   ff_dict_pirate=         000400,
122   ffs_dict=               000700,
123
124   ff_needisland=          001000,
125   ff_printisland=         002000,
126   ff_upload=              004000,
127   
128   ff_use_yarrg=           010000,
129   ff_use_pctb=            020000,
130   ffm_use=                070000,
131   
132   ffs_printisland=        003000,
133   ffs_upload=             005000,
134 };
135 extern enum flags o_flags;
136
137 enum mode {
138   mf_findwindow=      00001,
139   mf_screenshot=      00010,
140   mf_readscreenshot=  00020,
141   mf_analyse=         00100,
142   mfm_special=        07000,
143   
144   mode_findwindow=    00001,
145   mode_screenshot=    00011,
146   mode_analyse=       00120,
147   mode_showcharset=   01000,
148
149   mode_all=           00111,
150 };
151 extern enum mode o_mode;
152
153 extern const char *o_ocean, *o_pirate;
154 extern int o_quiet;
155
156
157 #define dbassert(x) ((x) ? (void)0 : dbfile_assertfail(__FILE__,__LINE__,#x))
158 void dbfile_assertfail(const char *file, int line, const char *m) NORET;
159
160 FILE *dbfile;
161 void dbfile_getsline(char *lbuf, size_t lbufsz, const char *file, int line);
162 int dbfile_open(const char *tpath);   /* 0: ENOENT; 1: worked */
163 int dbfile_gzopen(const char *tpath); /* 0: ENOENT; 1: worked */
164 void dbfile_close(void); /* idempotent */
165
166 int dbfile_scanf(const char *fmt, ...) SCANFMT(1,2);
167 int dbfile_vscanf(const char *fmt, va_list al) SCANFMT(1,0);
168
169 int gzopen(const char *zpath, int oflags, FILE **f_r, pid_t *pid_r,
170            const char *gziplevel /* 0 for read; may be 0, or "-1" etc. */);
171   /* returns errno value from open */
172 void gzclose(FILE **f, pid_t *p, const char *what);
173   /* also OK with f==0, or p==-1 */
174
175
176 const char *get_vardir(void);
177 const char *get_libdir(void);
178
179
180 #define EXECLP_HELPER(helper, ...) do{                          \
181     char *helper_path= masprintf("%s/%s",get_libdir(),helper);  \
182     execlp(helper_path,helper, __VA_ARGS__);                    \
183     sysassert(errno==ENOENT);                                   \
184     fatal("Failed to find helper program %s.\n"                 \
185           "(Are you in the correct directory?)", helper);       \
186   }while(0)
187
188
189 /*----- from pages.c -----*/
190
191 void screenshot_startup(void);
192 void set_yppclient_window(unsigned long wul);
193 void find_yppclient_window(void);
194 void take_screenshots(void);
195 void take_one_screenshot(void);
196
197 #define MAX_PAGES 1000
198
199 extern const CanonImage *page_images[MAX_PAGES];
200 extern const RgbImage *page0_rgbimage;
201 extern int npages;
202
203 extern const char *ocean, *pirate;
204 extern char *archipelago, *island;
205
206 #endif /*CONVERT_H*/