/* Qxw is a program to help construct and publish crosswords. Copyright 2011-2020 Mark Owen; Windows port by Peter Flippant http://www.quinapalus.com E-mail: qxw@quinapalus.com This file is part of Qxw. Qxw is free software: you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. Qxw is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Qxw. If not, see or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __COMMON_H__ #define __COMMON_H__ #include #include #include #include #include #include #include #include #include // OS-SPECIFIC #ifdef _WIN32 #include #include #include #define _USE_MATH_DEFINES #include #define DIR_SEP_STR "\\" #define DIR_SEP_CHAR '\\' #define STRCASECMP _stricmp #else #define DIR_SEP_STR "/" #define DIR_SEP_CHAR '/' #define STRCASECMP strcasecmp #endif #define RELEASE "20200708" // GENERAL #define NGTYPE 13 // number of different grid types #define MAXNDIR 3 // maximum number of directions #define MXSZ 63 // max grid size X and Y #define MXCL 250 // max number of cells in light; must be >=MXSZ*2; allow more for VL:s #define MXCT 31 // max contents in one cell per direction #define MXMUX MXCT // maximum degree of multiplexing #define NMSG 2 // number of messages passed to treatment code #define MXLE 250 // max entries in a light before tags added #define MXFL 255 // max entries in a word that filler can cope with: light plus tags, >=MXLE+NMSG; <256 to allow poscnt[] not to overflow #define MXLT (MAXNDIR*MXSZ*MXSZ+NVL) // max number of lights (conservative estimate) #define NVL (MXSZ*4) // max number of virtual lights #define MAXNMK (MAXNDIR*2) // max number of corner marks #define MXMK 30 // max length of mark string // note that a light (in a Mobius grid with all squares full) can contain up to MXSZ*2*MXCT entries, which is >MXLE; and that // if filler discretion is enabled, the number of treated lights must be <=MXFL, otherwise only limited by MXLT // MXFL<=255 to prevent unsigned char histograms overflowing #define NLEM 5 // number of light entry methods #define NATREAT 12 // number of treatments #define TREAT_PLUGIN 9 #define UNDOS 50 // MISC #define STRSTARTS(s,t) (!strncmp((s),(t),strlen(t))) #define MEMBLK 100000 // unit of memory allocation struct memblk { struct memblk*next; int ct; char s[MEMBLK]; }; #define PI (M_PI) #define ODD(x) ((x)&1) #define EVEN(x) (!((x)&1)) #define FREEX(p) if(p) {free(p);p=0;} #define SLEN 1000 // maximum length for filenames, strings etc.; Windows has MAX_PATH around 260; should be >>MXFL #define LEMDESCLEN 20 // maximum length of entry method description #define MX(a,b) ((a)>(b)?(a):(b)) extern int debug; #define DEB_F0 if(debug&0x00000001) // filler: start and stop #define DEB_F1 if(debug&0x00000002) // filler: basics #define DEB_F2 if(debug&0x00000004) // more detail #define DEB_F3 if(debug&0x00000008) // spreads and jumbles #define DEB_GU if(debug&0x00000010) // general GUI #define DEB_RF if(debug&0x00000020) // refresh, events #define DEB_DI if(debug&0x00000040) // dictionaries #define DEB_DV if(debug&0x00000080) // dictionaries, verbose #define DEB_AL if(debug&0x00000100) // alphabets #define DEB_FL if(debug&0x00000200) // feasible list building #define DEB_TR if(debug&0x00000400) // treatments and plug-ins #define DEB_GR if(debug&0x00000800) // grid operations, save, load #define DEB_BS if(debug&0x00001000) // buildstructs #define DEB_DE if(debug&0x00002000) // decks #define DEB_EX if(debug&0x00004000) // export // bit 31 is used to force printing of version information etc. without other output // ALPHABETS typedef unsigned int uchar; // to hold UTF-32 character; must be unsigned #define MAXUCHAR 0x30000 // maximum Unicode character accepted: first three planes only #define MAXEQUIV 100 // maximum equivalent unicode charaacters mapping to given internal code #define MAXICC 61 // internal character codes from 1..MAXICC-1 are allowed for normal characters; 0 reserved for 0-termination; code MAXICC used for "dash" in treatments (to mean "no treatment") #define ICC_DASH MAXICC // internal character code for dash #define TOUUPPER(c) g_unichar_toupper(c) #define TOULOWER(c) g_unichar_tolower(c) #define ISUUPPER(c) g_unichar_isupper(c) #define ISULOWER(c) g_unichar_islower(c) #define ISUDIGIT(c) g_unichar_isdigit(c) #define ISUALPHA(c) g_unichar_isalpha(c) #define ISUPRINT(c) g_unichar_isprint(c) #define ISUGRAPH(c) g_unichar_isgraph(c) struct alphaentry { char*rep; // representative as UTF-8 char*eqv; // UTF-8 string of equivalents (need not include rep) int vow; // is it a vowel? int con; // is it a consonant? int seq; // forms sequence with next? }; #define ICCTOABM(x) (1ULL<<((x)-1)) typedef unsigned long long int ABM; // alphabet bitmap type #define ABM_NRM ((1ULL<<(MAXICC-1))-1) // normal characters #define ABM_DASH (1ULL<<(ICC_DASH-1)) #define ABM_ALL (ABM_NRM|ABM_DASH) // normal characters plus dash // Terminology: // A `square' is the quantum of area in the grid; one or more squares (a `merge group') form // an `entry', which is a single enclosed white area in the grid where a letter (or group of letters) will appear. // A `word' is a sequence of entries to be filled. // bldstructs() constructs the words and entries from the square data produced // by the editor. struct sprop { // square properties unsigned int bgcol; // background colour unsigned int fgcol; // foreground colour unsigned int mkcol; // mark colour unsigned char ten; // treatment enable: flag to plug-in unsigned char spor; // global square property override (not used in dsp) unsigned char fstyle; // font style: b0=bold, b1=italic unsigned char dech; // dechecked: 0=normal, 1=contributions stacked atop one another, 2=contributions side-by-side char mk[MAXNMK][MXMK+1]; // square corner mark strings in each direction }; // entry methods #define EM_FWD 1 #define EM_REV 2 #define EM_CYC 4 #define EM_RCY 8 #define EM_JUM 16 #define EM_ALL 31 #define EM_SPR 32 // for internal use only struct lprop { // light properties unsigned int dmask; // mask of allowed dictionaries; special values 1<