chiark / gitweb /
where-vessels: expand report area to fill space available
[ypp-sc-tools.main.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(keymap)                                   \
35    DF(rect)                                     \
36    DF(pixmap)                                   \
37    DF(struct)                                   \
38    DF(ocr)                                      \
39    DF(rsync)                                    \
40    DF(structcolon)                              \
41    DF(callout)
42
43
44 #include "common.h"
45 #include "ocr.h"
46
47 #include <fnmatch.h>
48 #include <pcre.h>
49 #include <pam.h>
50 #include <time.h>
51 #include <limits.h>
52
53 #include <sys/time.h>
54
55
56 /*----- from rgbimage.c -----*/
57
58 #define MAXIMGIDENT 100
59
60 typedef uint32_t Rgb; /* red<<0 | green<<8 | blue<<16 */
61
62 typedef struct RgbImage {
63   int w, h;
64   Rgb data[]; /* data[ y*w + x ] */
65 } RgbImage;
66
67 void identify_rgbimage(const RgbImage *base, Rect portion,
68                        char result[MAXIMGIDENT], const char *what);
69 RgbImage *alloc_rgb_image(int w, int h);
70 void fwrite_ppmraw(FILE *f, const RgbImage *ri);
71
72 #define RI_PIXEL32(ri,x,y) ((ri)->data + ((y)*(ri)->w + (x)))
73
74 static inline Rgb ri_rgb(const RgbImage *ri, int x, int y) {
75   return *RI_PIXEL32(ri,x,y);
76 }
77
78 /*----- from structure.c -----*/
79
80 typedef struct PageStruct PageStruct;
81
82 void find_structure(const CanonImage *im,
83                     PageStruct **pagestruct_r, /* caller must free() */
84                     int *max_relevant_y_r,
85                     Point *commod_focus_point_r,
86                     Point *commod_page_point_r,
87                     Point *commod_focuslast_point_r);
88 void store_current_page(CanonImage *ci /*pointer saved*/,
89                         PageStruct *pagestruct, /*freed*/
90                         RgbImage *rgb /*freed*/);
91 void adjust_colours(CanonImage *ci, const RgbImage *rgb);
92
93 void select_page(int page);
94 void check_pager_motion(int first, int stop);
95
96 Rect find_sunshine_widget(void);
97
98 void canon_colour_prepare(void);
99 void find_islandname(void);
100 void check_correct_commodities(void);
101 void read_screenshots(void);
102 void read_one_screenshot(void);
103 void analyse(FILE *tsv_output);
104
105 /*----- from convert.c -----*/
106
107 extern FILE *screenshot_file;
108 void fetch_with_rsync(const char *stem);
109 void fetch_with_rsync_gz(const char *stem);
110
111 enum flags {
112   ff_singlepage=          000002,
113   ff_testservers=         000004,
114
115   ff_charset_edit=        000010,
116   ff_charset_allowedit=   000020,
117   ff_charset_havelocal=   000040,
118   ffm_charset=            000070,
119   
120   ff_dict_fetch=          000100,
121   ff_dict_submit=         000200,
122   ff_dict_pirate=         000400,
123   ffs_dict=               000700,
124
125   ff_needisland=          001000,
126   ff_printisland=         002000,
127   ff_upload=              004000,
128   
129   ff_use_yarrg=           010000,
130   ff_use_pctb=            020000,
131   ffm_use=                070000,
132   
133   ffs_printisland=        003000,
134   ffs_upload=             005000,
135 };
136 extern enum flags o_flags;
137
138 enum mode {
139   mf_findwindow=        00001,
140   mf_screenshot=        00010,
141   mf_readscreenshot=    00020,
142   mf_analyse=           00100,
143   mf_printoceanpirate=  00200,
144   mfm_special=          07000,
145   
146   mode_findwindow=      00201,
147   mode_screenshot=      00011,
148   mode_analyse=         00120,
149   mode_showcharset=     01000,
150
151   mode_all=           00111,
152 };
153 extern enum mode o_mode;
154
155 extern const char *o_ocean, *o_pirate;
156 extern int o_quiet;
157
158
159 #define dbassert(x) ((x) ? (void)0 : dbfile_assertfail(__FILE__,__LINE__,#x))
160 void dbfile_assertfail(const char *file, int line, const char *m) NORET;
161
162 FILE *dbfile;
163 void dbfile_getsline(char *lbuf, size_t lbufsz, const char *file, int line);
164 int dbfile_open(const char *tpath);   /* 0: ENOENT; 1: worked */
165 int dbfile_gzopen(const char *tpath); /* 0: ENOENT; 1: worked */
166 void dbfile_close(void); /* idempotent */
167
168 int dbfile_scanf(const char *fmt, ...) SCANFMT(1,2);
169 int dbfile_vscanf(const char *fmt, va_list al) SCANFMT(1,0);
170
171 int gzopen(const char *zpath, int oflags, FILE **f_r, pid_t *pid_r,
172            const char *gziplevel /* 0 for read; may be 0, or "-1" etc. */);
173   /* returns errno value from open */
174 void gzclose(FILE **f, pid_t *p, const char *what);
175   /* also OK with f==0, or p==-1 */
176
177
178 const char *get_vardir(void);
179 const char *get_libdir(void);
180
181
182 #define EXECLP_HELPER(helper, ...) do{                          \
183     char *helper_path= masprintf("%s/%s",get_libdir(),helper);  \
184     execlp(helper_path,helper, __VA_ARGS__);                    \
185     sysassert(errno==ENOENT);                                   \
186     fatal("Failed to find helper program %s.\n"                 \
187           "(Are you in the correct directory?)", helper);       \
188   }while(0)
189
190
191 /*----- from pages.c -----*/
192
193 void screenshot_startup(void);
194 void set_yppclient_window(unsigned long wul);
195 void find_yppclient_window(void);
196 void take_screenshots(void);
197 void take_one_screenshot(void);
198
199 #define MAX_PAGES 1000
200
201 extern const CanonImage *page_images[MAX_PAGES];
202 extern const RgbImage *page0_rgbimage;
203 extern int npages;
204
205 extern const char *ocean, *pirate;
206 extern char *archipelago, *island;
207
208 #endif /*CONVERT_H*/