Diff of /sys_ansi.c [000000] .. [2a97a8] Maximize Restore

  Switch to unified view

a b/sys_ansi.c
1
/* Panorama_Tools -   Generate, Edit and Convert Panoramic Images
2
   Copyright (C) 1998,1999 - Helmut Dersch  der@fh-furtwangen.de
3
   
4
   This program is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
6
   the Free Software Foundation; either version 2, or (at your option)
7
   any later version.
8
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with this program; if not, write to the Free Software
16
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17
18
/*------------------------------------------------------------*/
19
20
#include "sys_ansi.h"
21
#include <signal.h>
22
23
24
//------------------ Public functions required by filter.h -------------------------------
25
26
27
28
void filter_main( TrformStr *TrPtr, struct size_Prefs *spref)
29
{
30
  dispatch    ( TrPtr, spref);
31
  
32
}
33
34
  
35
36
// Error reporting
37
38
void  PrintError( char* fmt, ...)
39
{
40
  va_list ap;
41
  char message[257];
42
  
43
  va_start(ap, fmt);
44
  vsprintf(message, fmt, ap);
45
  va_end(ap);
46
  
47
  if( JavaUI ){
48
      JPrintError( message );
49
  }else{
50
      printf("%s\n", message);
51
      fflush(stdout);
52
  }
53
}
54
55
56
// Progress report; return false if canceled
57
58
59
int Progress( int command, char* argument )
60
{
61
  long percent;   
62
63
  switch( command ){
64
      case _initProgress:
65
          printf( "\n%s          ", argument );
66
          return TRUE;
67
      
68
      case _setProgress:
69
          sscanf(argument,"%ld", &percent);
70
          printf("\b\b\b\b%3ld%%", (long) percent);
71
          fflush (stdout);
72
          return TRUE;
73
          
74
      case _disposeProgress:
75
          printf("\n");
76
          return TRUE;
77
      case _idleProgress:
78
          return TRUE;
79
  }
80
  return TRUE;
81
}
82
83
volatile sig_atomic_t sigFlag;
84
85
void sigHandler(int sig){
86
  signal( SIGINT, sigHandler );
87
  sigFlag = 1;
88
}
89
90
int infoDlg ( int command, char* argument ){
91
  static char mainMessage[256];   
92
  int reply;
93
  
94
  *mainMessage = 0;
95
96
  switch( command ){
97
      case _initProgress:
98
          signal( SIGINT, sigHandler );
99
          sigFlag = 0;
100
          printf( "%s\n", argument );
101
          return TRUE;
102
      case _setProgress:
103
          if( *argument != 0 ){
104
              if( *argument != '+' ){
105
                  strcpy( mainMessage, argument );
106
                  printf( "%s\n", argument );
107
              }else{
108
                  printf( "%s%s", mainMessage, &(argument[1]) );
109
              }
110
              fflush (stdout);
111
          }
112
          //printf("\nContinue (c) or stop (s) ?\n");
113
          //reply = getchar();
114
          //if( reply == 's' )
115
          //  return FALSE;
116
          //return TRUE;
117
          if( sigFlag )
118
              return FALSE;
119
          return TRUE;
120
      case _disposeProgress:
121
          printf("\n");
122
          return TRUE;
123
      case _idleProgress:
124
          return TRUE;
125
  }
126
  return TRUE;
127
}
128
129
130
int readPrefs( char* pref, int selector )
131
{
132
133
  struct {
134
      char                        v[sizeof(VERSION)];
135
      struct correct_Prefs        c;
136
      struct remap_Prefs          r;
137
      struct perspective_Prefs    p;
138
      struct adjust_Prefs         a;
139
      struct size_Prefs           s;
140
      panControls                 pc;
141
  } prf;
142
  char* prefname = "pano12.prf";
143
  long size;
144
145
  FILE    *prfile;
146
  int result = 0;
147
148
149
  if( (prfile = fopen( prefname, "rb" )) != NULL ){
150
      size = fread( &prf, 1, sizeof(prf),  prfile);
151
      fclose( prfile );
152
      
153
      if( size != sizeof(prf) ){
154
          result = -1;
155
      }else{
156
          switch( selector){
157
              case _version:
158
                  memcpy( pref, &prf.v, sizeof( VERSION ) );
159
                  break;
160
              case _correct:
161
                  if( prf.c.magic != 20 ) 
162
                      result = -1;
163
                  else
164
                      memcpy( pref, &prf.c, sizeof(struct correct_Prefs)); 
165
                  break;
166
              case _remap:
167
                  if( prf.r.magic != 30 ) 
168
                      result = -1;
169
                  else
170
                      memcpy( pref, &prf.r , sizeof(struct remap_Prefs)); 
171
                  break;
172
              case _perspective:
173
                  if( prf.p.magic != 40 ) 
174
                      result = -1;
175
                  else
176
                      memcpy( pref, &prf.p , sizeof(struct perspective_Prefs)); 
177
                  break;
178
              case _adjust:
179
                  if( prf.a.magic != 50 ) 
180
                      result = -1;
181
                  else
182
                      memcpy( pref, &prf.a , sizeof(struct adjust_Prefs)); 
183
                  break;
184
              case _sizep:
185
                  if( prf.s.magic != 70 ) 
186
                      result = -1;
187
                  else
188
                      memcpy( pref, &prf.s , sizeof(struct size_Prefs)); 
189
                  break;
190
              case _panright:
191
              case _panleft:
192
              case _panup:
193
              case _pandown:
194
              case _zoomin:
195
              case _zoomout:
196
              case _apply:
197
              case _getPano:
198
              case _increment:
199
                  memcpy( pref, &prf.pc , sizeof(panControls)); 
200
                  break;
201
          }// switch
202
      } // sizes match
203
  }
204
  else
205
      result = -1;
206
207
  return result;
208
}
209
210
211
212
213
214
void writePrefs( char* prefs, int selector ){
215
216
  struct {
217
      char                        v[sizeof(VERSION)];
218
      struct correct_Prefs        c;
219
      struct remap_Prefs          r;
220
      struct perspective_Prefs    p;
221
      struct adjust_Prefs         a;
222
      struct size_Prefs           s;
223
      panControls                 pc;
224
  } prf;
225
226
  FILE    *prfile;
227
  char* prefname = "pano12.prf";
228
229
230
231
  if( (prfile = fopen( prefname, "rb" )) != NULL ){
232
      fread( &prf, sizeof(prf), 1 , prfile);
233
      fclose( prfile );
234
  }
235
236
  switch( selector){
237
      case _version:
238
          memcpy( &prf.v,  prefs, sizeof( VERSION ) );
239
          break;
240
      case _correct:
241
          memcpy( &prf.c , prefs, sizeof(struct correct_Prefs)); 
242
          break;
243
      case _remap:
244
          memcpy( &prf.r , prefs, sizeof(struct remap_Prefs)); 
245
          break;
246
      case _perspective:
247
          memcpy( &prf.p , prefs, sizeof(struct perspective_Prefs)); 
248
          break;
249
      case _adjust:
250
          memcpy( &prf.a , prefs, sizeof(struct adjust_Prefs)); 
251
          break;
252
      case _sizep:
253
          memcpy( &prf.s , prefs, sizeof(struct size_Prefs)); 
254
          break;
255
      case _panright:
256
      case _panleft:
257
      case _panup:
258
      case _pandown:
259
      case _zoomin:
260
      case _zoomout:
261
      case _apply:
262
      case _getPano:
263
      case _increment:
264
          memcpy( &prf.pc , prefs, sizeof(panControls)); 
265
          break;
266
  }
267
  
268
  if( (prfile = fopen( prefname, "wb" )) != NULL ){
269
      fwrite( &prf, sizeof(prf), 1 , prfile);
270
      fclose(prfile);
271
  }
272
}
273
274
275
#define signatureSize 4
276
277
void**  mymalloc( long numBytes )                 // Memory allocation, use Handles
278
{
279
  char **mem;
280
  
281
  mem = (char**)malloc( sizeof(char*) );          // Allocate memory for pointer
282
  if(mem == NULL)
283
      return (void**)NULL;
284
  else
285
  {
286
      (*mem) = (char*) malloc( numBytes );        // Allocate numBytes
287
      if( *mem == NULL )
288
      {
289
          free( mem );
290
          return (void**)NULL;
291
      }
292
      else
293
          return (void**)mem;
294
  }
295
}
296
297
void  myfree( void** Hdl )                        // free Memory, use Handles
298
{
299
  free( (char*) *Hdl );
300
  free( (char**) Hdl );
301
}     
302
303
// Display Scriptfile using plain text editor
304
305
void  showScript          ( fullPath* scriptFile )
306
{
307
  char cmd[sizeof(fullPath) + 16];
308
  
309
  sprintf( cmd, "vi \"%s\"", scriptFile->name );
310
  system( cmd );
311
}
312
  
313
314
  
315
316
int   FindFile( fullPath *fname ){
317
  printf("\n");
318
  printf("Load File:\n");
319
  scanf("%s", fname->name); 
320
  
321
  if(strlen(fname->name) > 0)
322
      return 0;
323
  else
324
      return -1;
325
}
326
327
int   SaveFileAs          ( fullPath *fname, char *prompt, char *name ){
328
  printf("\n");
329
  printf("Save File As:\n");
330
  scanf("%s", fname->name); 
331
  
332
  if(strlen(fname->name) > 0)
333
      return 0;
334
  else
335
      return -1;
336
}
337
338
339
void makePathForResult    ( fullPath *path ){
340
  strcpy( path->name, "//ptool_result" );
341
}
342
343
int makePathToHost ( fullPath *path ){
344
  strcpy(path->name, "./");
345
  return 0;
346
}
347
348
349
350
351
// Fname is appended to host-directory path
352
353
void MakeTempName( fullPath *destPath, char *fname ){
354
  sprintf( destPath->name, "pano12.%s", fname );
355
}
356
357
void ConvFileName( fullPath *fspec,char *string){
358
  strcpy( string, fspec->name );
359
}
360
361
int FullPathtoString (fullPath *path, char *filename){
362
  if( strlen( path->name ) < 256 )
363
  {
364
      strcpy( filename, path->name );
365
      return 0;
366
  }
367
  else
368
  {
369
      return -1;
370
  }
371
}
372
373
int IsTextFile( char* fname )
374
{
375
376
  if( strrchr( fname, '.' ) != NULL && 
377
          (strcmp( strrchr( fname, '.' ), ".txt") == 0 ||
378
           strcmp( strrchr( fname, '.' ), ".TXT") == 0)   )
379
  return TRUE;
380
  
381
382
  return FALSE;
383
}
384
385
int LaunchAndSendScript(char *application, char *script){
386
  char *cmd = (char*)malloc( strlen(application) + strlen(script) + 16);
387
  if( cmd == NULL){
388
      PrintError("Not enough memory");
389
      return -1;
390
  }
391
  sprintf(cmd, "%s %s", application, script );
392
  system( cmd );
393
  free(cmd);
394
  return 0;
395
}
396
397
int StringtoFullPath(fullPath *path, char *filename){
398
  if(strlen( filename ) < 256 ){
399
      strcpy( path->name, filename);
400
      return 0;
401
  }else{
402
      return -1;
403
  }
404
}
405