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 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
/* Panorama_Tools - Generate, Edit and Convert Panoramic Images
Copyright (C) 1998,1999 - Helmut Dersch der@fh-furtwangen.de
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, or (at your option)
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 software; see the file COPYING. If not, a copy
can be downloaded from http://www.gnu.org/licenses/gpl.html, or
obtained by writing to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/*------------------------------------------------------------*/
#include "sys_ansi.h"
#include "panotypes.h"
#include <signal.h>
//------------------ Public functions required by filter.h -------------------------------
// Required by filter.h but not used in the sys_ansi build of panotools.
// just return and do nothing
void SetWindowOwner(void * Owner) {return;}
void CenterDialog(void * hDlg) {return;}
void filter_main( TrformStr *TrPtr, struct size_Prefs *spref)
{
dispatch ( TrPtr, spref);
}
// Error reporting
void PrintErrorIntern(char* fmt, va_list ap)
{
char message[512];
char *toPrint;
if (strlen(fmt) < 512) {
vsprintf(message, fmt, ap);
toPrint = message;
} else {
// we don't have enough space, so just
// print original string
toPrint = fmt;
}
#ifdef HasJava
if( JavaUI ){
JPrintError( toPrint );
}else
#endif
{
printf("%s", toPrint);
// Add an end of line if none is provide
if (strlen(toPrint) > 0 &&
toPrint[strlen(toPrint)-1] != '\n') {
putchar('\n');
}
fflush(stdout);
}
}
// Progress report; return false if canceled
int ProgressIntern( int command, char* argument )
{
long percent;
switch( command ){
case _initProgress:
printf( "\n%s ", argument );
return TRUE;
case _setProgress:
sscanf(argument,"%ld", &percent);
printf("\b\b\b\b%3ld%%", (long) percent);
fflush (stdout);
return TRUE;
case _disposeProgress:
printf("\n");
return TRUE;
case _idleProgress:
return TRUE;
}
return TRUE;
}
volatile sig_atomic_t sigFlag;
void sigHandler(int sig PT_UNUSED){
signal( SIGINT, sigHandler );
sigFlag = 1;
}
int infoDlgIntern ( int command, char* argument ){
static char mainMessage[256];
// int reply;
*mainMessage = 0;
switch( command ){
case _initProgress:
signal( SIGINT, sigHandler );
sigFlag = 0;
printf( "%s\n", argument );
return TRUE;
case _setProgress:
if( *argument != 0 ){
if( *argument != '+' ){
strcpy( mainMessage, argument );
printf( "%s\n", argument );
}else{
printf( "%s%s", mainMessage, &(argument[1]) );
}
fflush (stdout);
}
//printf("\nContinue (c) or stop (s) ?\n");
//reply = getchar();
//if( reply == 's' )
// return FALSE;
//return TRUE;
if( sigFlag )
return FALSE;
return TRUE;
case _disposeProgress:
printf("\n");
return TRUE;
case _idleProgress:
return TRUE;
}
return TRUE;
}
int readPrefs( char* pref, int selector )
{
struct {
char v[sizeof(PREF_VERSION)];
struct correct_Prefs c;
struct remap_Prefs r;
struct perspective_Prefs p;
struct adjust_Prefs a;
struct size_Prefs s;
panControls pc;
} prf;
char* prefname = "pano13.prf";
long size;
FILE *prfile;
int result = 0;
if( (prfile = fopen( prefname, "rb" )) != NULL ){
size = fread( &prf, 1, sizeof(prf), prfile);
fclose( prfile );
if( size != sizeof(prf) ){
result = -1;
}else{
switch( selector){
case _version:
memcpy( pref, &prf.v, sizeof( PREF_VERSION ) );
break;
case _correct:
if( prf.c.magic != 20 )
result = -1;
else
memcpy( pref, &prf.c, sizeof(struct correct_Prefs));
break;
case _remap:
if( prf.r.magic != 30 )
result = -1;
else
memcpy( pref, &prf.r , sizeof(struct remap_Prefs));
break;
case _perspective:
if( prf.p.magic != 40 )
result = -1;
else
memcpy( pref, &prf.p , sizeof(struct perspective_Prefs));
break;
case _adjust:
if( prf.a.magic != 50 )
result = -1;
else
memcpy( pref, &prf.a , sizeof(struct adjust_Prefs));
break;
case _sizep:
if( prf.s.magic != 70 )
result = -1;
else
memcpy( pref, &prf.s , sizeof(struct size_Prefs));
break;
case _panright:
case _panleft:
case _panup:
case _pandown:
case _zoomin:
case _zoomout:
case _apply:
case _getPano:
case _increment:
memcpy( pref, &prf.pc , sizeof(panControls));
break;
}// switch
} // sizes match
}
else
result = -1;
return result;
}
void writePrefs( char* prefs, int selector ){
struct {
char v[sizeof(PREF_VERSION)];
struct correct_Prefs c;
struct remap_Prefs r;
struct perspective_Prefs p;
struct adjust_Prefs a;
struct size_Prefs s;
panControls pc;
} prf;
FILE *prfile;
char* prefname = "pano13.prf";
if( (prfile = fopen( prefname, "rb" )) != NULL ){
int i;
i = fread( &prf, sizeof(prf), 1 , prfile);
if (i != sizeof(prf)) {
PrintError("Unable to write to preference file [%s]\n", prefname);
}
fclose( prfile );
}
switch( selector){
case _version:
memcpy( &prf.v, prefs, sizeof( PREF_VERSION ) );
break;
case _correct:
memcpy( &prf.c , prefs, sizeof(struct correct_Prefs));
break;
case _remap:
memcpy( &prf.r , prefs, sizeof(struct remap_Prefs));
break;
case _perspective:
memcpy( &prf.p , prefs, sizeof(struct perspective_Prefs));
break;
case _adjust:
memcpy( &prf.a , prefs, sizeof(struct adjust_Prefs));
break;
case _sizep:
memcpy( &prf.s , prefs, sizeof(struct size_Prefs));
break;
case _panright:
case _panleft:
case _panup:
case _pandown:
case _zoomin:
case _zoomout:
case _apply:
case _getPano:
case _increment:
memcpy( &prf.pc , prefs, sizeof(panControls));
break;
}
if( (prfile = fopen( prefname, "wb" )) != NULL ){
fwrite( &prf, sizeof(prf), 1 , prfile);
fclose(prfile);
}
}
#define signatureSize 4
void** mymalloc( size_t numBytes ) // Memory allocation, use Handles
{
char **mem;
mem = (char**)malloc( sizeof(char*) ); // Allocate memory for pointer
if(mem == NULL)
return (void**)NULL;
else
{
(*mem) = (char*) malloc( numBytes ); // Allocate numBytes
if( *mem == NULL )
{
free( mem );
return (void**)NULL;
}
else
return (void**)mem;
}
}
void myfree( void** Hdl ) // free Memory, use Handles
{
free( (char*) *Hdl );
free( (char**) Hdl );
}
// Display Scriptfile using plain text editor
void showScript ( fullPath* scriptFile )
{
char cmd[sizeof(fullPath) + 16];
sprintf( cmd, "vi \"%s\"", scriptFile->name );
if (system( cmd ) == -1) {
PrintError("Unable to execute script editor");
}
}
int FindFile( fullPath *fname ){
printf("\n");
printf("Load File:\n");
if (scanf("%s", fname->name) != 1) {
return -1;
}
if(strlen(fname->name) > 0)
return 0;
else
return -1;
}
int SaveFileAs ( fullPath *fname, char *prompt PT_UNUSED, char *name PT_UNUSED){
printf("\n");
printf("Save File As:\n");
if (scanf("%s", fname->name) != 1) {
return -1;
}
if(strlen(fname->name) > 0)
return 0;
else
return -1;
}
void makePathForResult ( fullPath *path ){
strcpy( path->name, "//ptool_result" );
}
int makePathToHost ( fullPath *path ){
strcpy(path->name, "./");
return 0;
}
// Fname is appended to host-directory path
void MakeTempName( fullPath *destPath, char *fname ){
sprintf( destPath->name, "pano13.%s", fname );
}
void ConvFileName( fullPath *fspec,char *string){
strcpy( string, fspec->name );
}
int FullPathtoString (fullPath *path, char *filename){
if( strlen( path->name ) < 256 )
{
strcpy( filename, path->name );
return 0;
}
else
{
return -1;
}
}
int IsTextFile( char* fname )
{
if( strrchr( fname, '.' ) != NULL &&
(strcmp( strrchr( fname, '.' ), ".txt") == 0 ||
strcmp( strrchr( fname, '.' ), ".TXT") == 0) )
return TRUE;
return FALSE;
}
int LaunchAndSendScript(char *application, char *script){
char *cmd = (char*)malloc( strlen(application) + strlen(script) + 16);
if( cmd == NULL){
PrintError("Not enough memory");
return -1;
}
sprintf(cmd, "%s %s", application, script );
if (system( cmd ) == -1) {
PrintError("Unable to launch script");
}
free(cmd);
return 0;
}
int StringtoFullPath(fullPath *path, char *filename){
if(strlen( filename ) < 256 ){
strcpy( path->name, filename);
return 0;
}else{
return -1;
}
}
|