1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
/**
* @file thinit.cxx
*/
/* Copyright (C) 2000 Stacho Mudrak
*
* $Date: $
* $RCSfile: $
* $Revision: $
*
* --------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* --------------------------------------------------------------------
*/
#include "thinit.h"
#include "thparse.h"
#include "thchenc.h"
#include "therion.h"
#include "thconfig.h"
#include "thexception.h"
#include "thtexfonts.h"
#include "thlang.h"
#include "thlocale.h"
#ifdef THWIN32
#include <windows.h>
#endif
const char * THCCC_INIT_FILE = "### Output character encodings ###\n"
"# encoding-default ASCII\n"
"# encoding-sql ASCII\n\n"
"### Default regional settings ###\n"
"# language en_UK\n"
"# units metric\n\n"
"### Prefered loop closure method\n"
"# loop-closure survex\n\n"
"### Paths to called executable files ###\n"
"# mpost-path \"mpost\"\n"
"# pdftex-path \"pdfetex\"\n"
"# cavern-path \"cavern\"\n\n"
"### Search paths for source and configuration files ###\n"
"# source-path \"\"\n\n"
"### Tex initialization ###\n"
"# tex-env off\n"
"# tex-fonts <encoding> <roman> <italic> <bold> <sansserif> <sansserifoblique>\n"
"# tex-fonts raw cmr10 cmti10 cmbx10 cmss10 cmssi10\n"
"# tex-fonts xl2 csr10 csti10 csbx10 csss10 csssi10\n\n"
"### Path to temporary directory ###\n"
"# tmp-path \"\"\n\n"
"### Command to remove temporary directory ###\n"
"# tmp-remove \"\"\n\n";
thinit::thinit()
{
this->tex_env = false;
this->loopc = THINIT_LOOPC_UNKNOWN;
}
thinit::~thinit()
{
}
enum {
TTIC_ENCODING_DEFAULT,
TTIC_ENCODING_SQL,
TTIC_PATH_CAVERN,
// TTIC_PATH_3DTOPOS,
TTIC_PATH_MPOST,
TTIC_PATH_PDFTEX,
TTIC_PATH_SOURCE,
TTIC_TMP_PATH,
TTIC_TMP_REMOVE_SCRIPT,
TTIC_LANG,
TTIC_TEX_FONTS,
TTIC_TEX_ENV,
TTIC_UNITS,
TTIC_LOOPC,
TTIC_UNKNOWN,
};
/**
* Data types parsing table.
*/
static const thstok thtt_initcmd[] = {
{"cavern-path", TTIC_PATH_CAVERN},
{"encoding-default", TTIC_ENCODING_DEFAULT},
{"encoding-sql", TTIC_ENCODING_SQL},
// {"encoding_default", TTIC_ENCODING_DEFAULT},
// {"path_3dtopos", TTIC_PATH_3DTOPOS},
{"language", TTIC_LANG},
{"loop-closure", TTIC_LOOPC},
{"mpost-path", TTIC_PATH_MPOST},
{"pdftex-path", TTIC_PATH_PDFTEX},
{"source-path", TTIC_PATH_SOURCE},
{"tex-env",TTIC_TEX_ENV},
{"tex-fonts",TTIC_TEX_FONTS},
{"tmp-path",TTIC_TMP_PATH},
{"tmp-remove",TTIC_TMP_REMOVE_SCRIPT},
{"units",TTIC_UNITS},
{NULL, TTIC_UNKNOWN},
};
void thinit__print_open(char * s) {
#ifdef THDEBUG
thprintf("\ninitialization file: %s\nreading\n", s);
#else
thprintf("initialization file: %s\n", s);
thprintf("reading ...");
thtext_inline = true;
#endif
}
static const thstok thtt_loopc[] = {
{"survex", THINIT_LOOPC_SURVEX},
{"therion", THINIT_LOOPC_THERION},
{NULL, THINIT_LOOPC_UNKNOWN},
};
void thinit::load()
{
// set encodings
this->encoding_default = TT_ASCII;
this->encoding_sql = TT_UNKNOWN_ENCODING;
// set programs paths
this->path_cavern = "cavern";
#ifdef THWIN32
// set cavern path according to Windows registers
this->path_cavern.guarantee(1024);
thmbuffer mbf;
DWORD type, length = 1024;
HKEY key;
bool loaded_ok = true;
if (RegOpenKey(HKEY_CLASSES_ROOT,"survex.source\\shell\\Process\\command",&key) != ERROR_SUCCESS)
loaded_ok = false;
if (!loaded_ok || (RegQueryValueEx(key,NULL,NULL,&type,(BYTE *)this->path_cavern.get_buffer(),&length) != ERROR_SUCCESS)) {
loaded_ok = false;
RegCloseKey(key);
}
if (loaded_ok)
RegCloseKey(key);
if (type != REG_SZ)
loaded_ok = false;
if (loaded_ok) {
thsplit_args(&mbf,this->path_cavern.get_buffer());
this->path_cavern = "\"";
this->path_cavern += *(mbf.get_buffer());
this->path_cavern += "\"";
} else {
this->path_cavern = "cavern";
}
#endif
// try running survex
if (this->loopc == THINIT_LOOPC_UNKNOWN) {
thbuffer svxcom;
svxcom = "\"";
svxcom += thini.get_path_cavern();
svxcom += "\" --version";
#ifdef THDEBUG
thprintf("testing cavern\n");
#endif
if (system(svxcom.get_buffer()) == EXIT_SUCCESS) {
this->loopc = THINIT_LOOPC_SURVEX;
} else {
this->loopc = THINIT_LOOPC_THERION;
}
}
// this->path_3dtopos = "3dtopos";
#ifdef THWIN32
if (thcfg.install_tex) {
this->path_mpost = thcfg.install_path.get_buffer();
this->path_pdftex = thcfg.install_path.get_buffer();
this->path_mpost += "\\bin\\win32\\mpost.exe";
this->path_pdftex += "\\bin\\win32\\pdfetex.exe";
} else {
#endif
this->path_mpost = "mpost";
this->path_pdftex = "pdfetex";
#ifdef THWIN32
}
#endif
this->tmp_path = "";
this->tmp_remove_script = "";
this->lang = THLANG_UNKNOWN;
char * cmdln;
char ** args;
int nargs, argid, sv; //, argid2;
fontrecord frec;
bool some_tex_fonts = false, started = false;
this->ini_file.set_search_path(thcfg.get_initialization_path());
this->ini_file.set_file_name("therion.ini");
this->ini_file.sp_scan_on();
this->ini_file.cmd_sensitivity_off();
this->ini_file.print_if_opened(thinit__print_open, &started);
this->ini_file.reset();
try {
while((cmdln = this->ini_file.read_line()) != NULL) {
thsplit_args(& this->cmb, cmdln);
args = this->cmb.get_buffer();
nargs = this->cmb.get_size();
argid = thmatch_token(args[0], thtt_initcmd);
// check number of arguments:
switch (argid) {
case TTIC_ENCODING_DEFAULT:
case TTIC_PATH_CAVERN:
case TTIC_LOOPC:
case TTIC_TMP_PATH:
case TTIC_LANG:
case TTIC_UNITS:
case TTIC_TMP_REMOVE_SCRIPT:
case TTIC_PATH_MPOST:
case TTIC_PATH_PDFTEX:
case TTIC_PATH_SOURCE:
case TTIC_TEX_ENV:
if (nargs != 2)
ththrow(("invalid number of command arguments"));
break;
case TTIC_TEX_FONTS:
if (nargs != 7)
ththrow(("invalid number of command arguments"));
break;
default:
ththrow(("invalid initialization command -- %s", args[0]))
}
switch(argid) {
case TTIC_ENCODING_DEFAULT:
this->encoding_default = thparse_encoding(args[1]);
break;
case TTIC_ENCODING_SQL:
this->encoding_sql = thparse_encoding(args[1]);
break;
case TTIC_PATH_CAVERN:
if (strlen(args[1]) < 1)
ththrow(("invalid path"))
this->path_cavern.strcpy(args[1]);
break;
case TTIC_TMP_PATH:
this->tmp_path.strcpy(args[1]);
break;
case TTIC_LANG:
this->lang = thlang_parse(args[1]);
if (this->lang == THLANG_UNKNOWN)
ththrow(("language not supported -- %s",args[1]))
break;
case TTIC_UNITS:
thdeflocale.parse_units(args[1]);
break;
case TTIC_TMP_REMOVE_SCRIPT:
this->tmp_remove_script.strcpy(args[1]);
break;
case TTIC_PATH_MPOST:
if (strlen(args[1]) < 1)
ththrow(("invalid path"))
this->path_mpost.strcpy(args[1]);
break;
case TTIC_PATH_PDFTEX:
if (strlen(args[1]) < 1)
ththrow(("invalid path"))
this->path_pdftex.strcpy(args[1]);
break;
case TTIC_PATH_SOURCE:
thcfg.set_search_path(args[1]);
break;
case TTIC_TEX_FONTS:
frec.id = get_enc_id(args[1]);
if (frec.id < 0)
ththrow(("tex encoding not supported -- %s", args[1]))
frec.rm = args[2];
frec.it = args[3];
frec.bf = args[4];
frec.ss = args[5];
frec.si = args[6];
FONTS.push_back(frec);
some_tex_fonts = true;
break;
case TTIC_TEX_ENV:
sv = thmatch_token(args[1], thtt_bool);
if (sv == TT_UNKNOWN_BOOL)
ththrow(("invalid tex-env switch -- %s", args[1]))
this->tex_env = (sv == TT_TRUE);
break;
case TTIC_LOOPC:
sv = thmatch_token(args[1], thtt_loopc);
if (sv == THINIT_LOOPC_UNKNOWN)
ththrow(("invalid loop-closure switch -- %s", args[1]))
this->loopc = sv;
break;
default:
ththrow(("invalid initialization command -- %s", args[0]))
}
}
}
catch (...)
threthrow(("%s [%d]", this->ini_file.get_cif_name(), this->ini_file.get_cif_line_number()))
if (started) {
#ifdef THDEBUG
thprintf("\n");
#else
thprintf(" done\n");
thtext_inline = false;
#endif
}
if (!some_tex_fonts)
init_encodings();
}
char * thinit::get_path_cavern()
{
return this->path_cavern.get_buffer();
}
//char * thinit::get_path_3dtopos()
//{
// return this->path_3dtopos.get_buffer();
//}
char * thinit::get_path_mpost()
{
return this->path_mpost.get_buffer();
}
char * thinit::get_path_pdftex()
{
return this->path_pdftex.get_buffer();
}
void thprint_init_file()
{
thprintf(THCCC_INIT_FILE);
}
int thinit::get_encoding(int type) {
int res;
switch (type) {
case THINIT_ENCODING_SQL:
res = this->encoding_sql;
break;
default:
res = this->encoding_default;
break;
}
if (res == TT_UNKNOWN_ENCODING)
res = this->encoding_default;
return res;
}
thinit thini;
|