vtkWrapTcl.c 33.3 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkWrapTcl.c

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13
14
15
16

=========================================================================*/

#include <stdio.h>
17
#include <string.h>
18
#include "vtkParse.h"
19
#include "vtkConfigure.h"
20
21
22

int numberOfWrappedFunctions = 0;
FunctionInfo *wrappedFunctions[1000];
23
extern FunctionInfo *currentFunction;
24
25


Ken Martin's avatar
Ken Martin committed
26
void output_temp(FILE *fp, int i, int aType, char *Id, int count)
27
28
{
  /* handle VAR FUNCTIONS */
29
  if (aType == 0x5000)
30
31
32
33
34
35
    {
    fprintf(fp,"    vtkTclVoidFuncArg *temp%i = new vtkTclVoidFuncArg;\n",i);
    return;
    }
  
  /* ignore void */
36
  if (((aType % 0x10) == 0x2)&&(!((aType % 0x1000)/0x100)))
37
38
39
40
41
    {
    return;
    }

  /* for const * return types prototype with const */
42
  if ((i == MAX_ARGS) && (aType % 0x2000 >= 0x1000))
43
44
45
46
47
48
49
50
    {
    fprintf(fp,"    const ");
    }
  else
    {
    fprintf(fp,"    ");
    }

51
  if ((aType % 0x100)/0x10 == 0x1)
52
53
54
55
    {
    fprintf(fp,"unsigned ");
    }

56
  switch (aType % 0x10)
57
    {
58
59
60
61
62
63
64
65
66
    case 0x1:   fprintf(fp,"float  "); break;
    case 0x7:   fprintf(fp,"double "); break;
    case 0x4:   fprintf(fp,"int    "); break;
    case 0x5:   fprintf(fp,"short  "); break;
    case 0x6:   fprintf(fp,"long   "); break;
    case 0x2:     fprintf(fp,"void   "); break;
    case 0x3:     fprintf(fp,"char   "); break;
    case 0x9:     fprintf(fp,"%s ",Id); break;
    case 0xA:   fprintf(fp,"vtkIdType "); break;
67
68
    case 0xB:   fprintf(fp,"long long "); break;
    case 0xC:   fprintf(fp,"__int64 "); break;
69
    case 0xD:   fprintf(fp,"signed char "); break;
70
    case 0xE:   fprintf(fp,"bool "); break;
71
    case 0x8: return;
72
73
    }

Ken Martin's avatar
Ken Martin committed
74
  /* handle array arguements */
75
  if (count > 0x1)
Ken Martin's avatar
Ken Martin committed
76
77
78
79
80
    {
    fprintf(fp,"temp%i[%i];\n",i,count);
    return;
    }
  
81
  switch ((aType % 0x1000)/0x100)
82
    {
83
84
85
86
87
88
    case 0x1: fprintf(fp, " *"); break; /* act " &" */
    case 0x2: fprintf(fp, "&&"); break;
    case 0x3: fprintf(fp, " *"); break;
    case 0x4: fprintf(fp, "&*"); break;
    case 0x5: fprintf(fp, "*&"); break;
    case 0x7: fprintf(fp, "**"); break;
89
90
91
92
93
94
95
96
97
98
99
100
101
    default: fprintf(fp,"  "); break;
    }
  
  fprintf(fp,"temp%i",i);
  fprintf(fp,";\n");
}

/* when the cpp file doesn't have enough info use the hint file */
void use_hints(FILE *fp)
{
  int  i;

  /* use the hint */
102
  switch (currentFunction->ReturnType % 0x1000)
103
    {
104
    case 0x301: case 0x307:  
105
106
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
107
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
108
109
110
        {
        fprintf(fp,"%%g ");
        }
111
112
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
113
114
115
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
116
      fprintf(fp,");\n");
117
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
118
      break;
119
    case 0x304: case 0x305: case 0x30D:
120
121
122
#ifndef VTK_USE_64BIT_IDS
    case 0x30A:
#endif
123
124
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
125
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
126
127
128
        {
        fprintf(fp,"%%i ");
        }
129
130
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
131
132
133
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
134
      fprintf(fp,");\n");
135
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
136
      break;
137
138
139
140
141
142
143
144
145
146
    case 0x30E:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%i ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
147
        fprintf(fp,",static_cast<int>(temp%i[%i])",MAX_ARGS,i);
148
149
150
151
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
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
    case 0x306:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%li ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
#ifdef VTK_USE_64BIT_IDS
    case 0x30A:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
#  if defined(_MSC_VER)
        fprintf(fp,"%%I64i ");
#  else
        fprintf(fp,"%%lli ");
#  endif
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
#endif
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
    case 0x30B:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%lli ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
    case 0x30C:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%I64i ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
218
219
220
221
    case 0x313: case 0x314: case 0x315:
#ifndef VTK_USE_64BIT_IDS
    case 0x31A:
#endif
222
223
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
Ken Martin's avatar
Ken Martin committed
224
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
225
226
227
        {
        fprintf(fp,"%%u ");
        }
Ken Martin's avatar
Ken Martin committed
228
229
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
230
231
232
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
Ken Martin's avatar
Ken Martin committed
233
      fprintf(fp,");\n");
234
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
Ken Martin's avatar
Ken Martin committed
235
      break;
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
    case 0x316:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%lu ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
#ifdef VTK_USE_64BIT_IDS
    case 0x31A:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
#  if defined(_MSC_VER)
        fprintf(fp,"%%I64u ");
#  else
        fprintf(fp,"%%llu ");
#  endif
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
#endif
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
    case 0x31B:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%llu ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
    case 0x31C:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%I64u ");
        }
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
      fprintf(fp,");\n");
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
302
303
304
305
306
    }
}

void return_result(FILE *fp)
{
307
  switch (currentFunction->ReturnType % 0x1000)
308
    {
309
    case 0x2:
310
      fprintf(fp,"    Tcl_ResetResult(interp);\n"); 
311
      break;
312
    case 0x1: case 0x7: 
313
314
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%g\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
315
              MAX_ARGS); 
316
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
317
      break;
318
319
320
321
    case 0x4:  
#ifndef VTK_USE_64BIT_IDS
    case 0xA:
#endif
322
    case 0xD:
323
324
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%i\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
325
              MAX_ARGS); 
326
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
327
      break;
328
329
330
331
332
333
    case 0xE:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%i\",(int)temp%i);\n",
              MAX_ARGS); 
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
334
    case 0x5:
335
336
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hi\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
337
              MAX_ARGS); 
338
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
339
      break;
340
    case 0x6:
341
342
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%li\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
343
              MAX_ARGS);
344
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
345
      break;
346
347
348
349
350
351
352
353
354
355
356
357
358
#ifdef VTK_USE_64BIT_IDS
    case 0xA:
      fprintf(fp,"    char tempResult[1024];\n");
#  if defined(_MSC_VER)
      fprintf(fp,"    sprintf(tempResult,\"%%I64i\",temp%i);\n",
              MAX_ARGS); 
#  else
      fprintf(fp,"    sprintf(tempResult,\"%%lli\",temp%i);\n",
              MAX_ARGS); 
#  endif
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
#endif
359
360
361
362
363
364
365
366
367
368
369
370
    case 0xB:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%lli\",temp%i);\n",
              MAX_ARGS);
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
    case 0xC:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%I64i\",temp%i);\n",
              MAX_ARGS);
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
371
372
373
374
    case 0x14:
#ifndef VTK_USE_64BIT_IDS
    case 0x1A:
#endif
375
376
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%u\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
377
              MAX_ARGS); 
378
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
379
      break;
380
    case 0x15: 
381
382
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
383
              MAX_ARGS);  
384
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
385
      break;
386
    case 0x16:  
387
388
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%lu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
389
              MAX_ARGS);
390
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
391
      break;
392
    case 0x13:
393
394
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
395
              MAX_ARGS); 
396
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
397
      break;
398
399
400
401
402
403
404
405
406
407
408
409
410
#ifdef VTK_USE_64BIT_IDS
    case 0x1A:  
      fprintf(fp,"    char tempResult[1024];\n");
#  if defined(_MSC_VER)
      fprintf(fp,"    sprintf(tempResult,\"%%I64u\",temp%i);\n",
              MAX_ARGS); 
#  else
      fprintf(fp,"    sprintf(tempResult,\"%%llu\",temp%i);\n",
              MAX_ARGS); 
#  endif
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
#endif
411
412
413
414
415
416
417
418
419
420
421
422
    case 0x1B:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%llu\",temp%i);\n",
              MAX_ARGS);
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
    case 0x1C:
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%I64u\",temp%i);\n",
              MAX_ARGS);
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
      break;
423
    case 0x303:
424
      fprintf(fp,"    if (temp%i)\n      {\n      Tcl_SetResult(interp, const_cast<char *>(temp%i), TCL_VOLATILE);\n",MAX_ARGS,MAX_ARGS); 
425
426
      fprintf(fp,"      }\n    else\n      {\n");
      fprintf(fp,"      Tcl_ResetResult(interp);\n      }\n"); 
427
      break;
428
    case 0x3:
429
430
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%c\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
431
              MAX_ARGS); 
432
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
433
      break;
434
435
    case 0x109:
    case 0x309:  
436
      fprintf(fp,"      vtkTclGetObjectFromPointer(interp,static_cast<void *>(temp%i),\"%s\");\n",MAX_ARGS,currentFunction->ReturnClass);
437
438
439
440
      break;

    /* handle functions returning vectors */
    /* this is done by looking them up in a hint file */
441
    case 0x301: case 0x307:
442
    case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E:
443
    case 0x313: case 0x314: case 0x315: case 0x316: case 0x31A: case 0x31B: case 0x31C:
444
445
446
      use_hints(fp);
      break;
    default:
447
      fprintf(fp,"    Tcl_SetResult(interp, static_cast<char *>(\"unable to return result.\"), TCL_VOLATILE);\n");
448
449
450
451
452
453
      break;
    }
}

void get_args(FILE *fp, int i)
{
Ken Martin's avatar
Ken Martin committed
454
455
456
457
458
459
460
461
462
463
  int j;
  int start_arg = 2;
  
  /* what arg do we start with */
  for (j = 0; j < i; j++)
    {
    start_arg = start_arg + 
      (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
    }
  
464
  /* handle VAR FUNCTIONS */
465
  if (currentFunction->ArgTypes[i] == 0x5000)
466
467
468
469
470
471
472
    {
    fprintf(fp,"    temp%i->interp = interp;\n",i);
    fprintf(fp,"    temp%i->command = strcpy(new char [strlen(argv[2])+1],argv[2]);\n",i);
    return;
    }

  /* ignore void */
473
474
  if (((currentFunction->ArgTypes[i] % 0x10) == 0x2)&&
      (!((currentFunction->ArgTypes[i] % 0x1000)/0x100)))
475
476
477
478
    {
    return;
    }
  
479
  switch (currentFunction->ArgTypes[i] % 0x1000)
480
    {
481
    case 0x1: case 0x7:  
482
      fprintf(fp,
Ken Martin's avatar
Ken Martin committed
483
484
              "    if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
              start_arg); 
485
486
      fprintf(fp,"    temp%i = tempd;\n",i);
      break;
487
    case 0x4: case 0x5: case 0x6: case 0xA: case 0xB: case 0xC: case 0xD:
488
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
489
              start_arg); 
490
491
      fprintf(fp,"    temp%i = tempi;\n",i);
      break;
492
493
494
    case 0xE:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
              start_arg); 
495
      fprintf(fp,"    temp%i = tempi ? true : false;\n",i);
496
      break;
497
    case 0x3:
Ken Martin's avatar
Ken Martin committed
498
      fprintf(fp,"    temp%i = *(argv[%i]);\n",i,start_arg);
499
      break;
500
    case 0x13:
501
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
502
              start_arg); 
503
      fprintf(fp,"    temp%i = static_cast<unsigned char>(tempi);\n",i);
504
      break;
505
    case 0x14: case 0x1A: case 0x1B: case 0x1C:
506
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
507
              start_arg); 
508
      fprintf(fp,"    temp%i = static_cast<unsigned int>(tempi);\n",i);
509
      break;
510
    case 0x15:
511
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
512
              start_arg); 
513
      fprintf(fp,"    temp%i = static_cast<unsigned short>(tempi);\n",i);
514
      break;
515
    case 0x16:
Ken Martin's avatar
Ken Martin committed
516
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
517
              start_arg); 
518
      fprintf(fp,"    temp%i = static_cast<unsigned long>(tempi);\n",i);
Ken Martin's avatar
Ken Martin committed
519
      break;
520
    case 0x303:
Ken Martin's avatar
Ken Martin committed
521
      fprintf(fp,"    temp%i = argv[%i];\n",i,start_arg);
522
      break;
523
524
    case 0x109:
    case 0x309:
525
      fprintf(fp,"    temp%i = (%s *)(vtkTclGetPointerFromObject(argv[%i],static_cast<char *>(\"%s\"),interp,error));\n",i,currentFunction->ArgClasses[i],start_arg,
Ken Martin's avatar
Ken Martin committed
526
              currentFunction->ArgClasses[i]);
527
      break;
528
529
    case 0x2:    
    case 0x9:
530
      break;
Ken Martin's avatar
Ken Martin committed
531
532
    default:
      if (currentFunction->ArgCounts[i] > 1)
Ken Martin's avatar
Ken Martin committed
533
534
535
        {
        for (j = 0; j < currentFunction->ArgCounts[i]; j++)
          {
536
          switch (currentFunction->ArgTypes[i] % 0x100)
Ken Martin's avatar
Ken Martin committed
537
            {
538
            case 0x1: case 0x7:  
Ken Martin's avatar
Ken Martin committed
539
540
541
542
543
              fprintf(fp,
                      "    if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = tempd;\n",i,j);
              break;
544
            case 0x4: case 0x5: case 0x6: case 0xA: case 0xB: case 0xC: case 0xD:
Ken Martin's avatar
Ken Martin committed
545
546
547
548
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = tempi;\n",i,j);
              break;
549
550
551
            case 0xE:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
552
              fprintf(fp,"    temp%i[%i] = tempi ? true : false;\n",i,j);
553
              break;
554
            case 0x3:
Ken Martin's avatar
Ken Martin committed
555
556
              fprintf(fp,"    temp%i[%i] = *(argv[%i]);\n",i,j,start_arg);
              break;
557
            case 0x13:
Ken Martin's avatar
Ken Martin committed
558
559
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
560
              fprintf(fp,"    temp%i[%i] = static_cast<unsigned char>(tempi);\n",i,j);
Ken Martin's avatar
Ken Martin committed
561
              break;
562
            case 0x14: case 0x1A:
Ken Martin's avatar
Ken Martin committed
563
564
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
565
              fprintf(fp,"    temp%i[%i] = static_cast<unsigned int>(tempi);\n",i,j);
Ken Martin's avatar
Ken Martin committed
566
              break;
567
            case 0x15:
Ken Martin's avatar
Ken Martin committed
568
569
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
570
              fprintf(fp,"    temp%i[%i] = static_cast<unsigned short>(tempi);\n",i,j);
Ken Martin's avatar
Ken Martin committed
571
              break;
572
            case 0x16:
Ken Martin's avatar
Ken Martin committed
573
574
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
575
              fprintf(fp,"    temp%i[%i] = static_cast<unsigned long>(tempi);\n",i,j);
Ken Martin's avatar
Ken Martin committed
576
577
578
579
580
              break;
            }
          start_arg++;
          }
        }
Ken Martin's avatar
Ken Martin committed
581
      
582
583
584
585
586
587
588
589
590
    }
}

void outputFunction(FILE *fp, FileInfo *data)
{
  int i;
  int args_ok = 1;
 
  /* some functions will not get wrapped no matter what else */
591
  if (currentFunction->IsOperator || 
592
      currentFunction->ArrayFailure ||
Ken Martin's avatar
Ken Martin committed
593
594
      !currentFunction->IsPublic ||
      !currentFunction->Name) 
595
596
597
598
599
600
601
    {
    return;
    }
  
  /* check to see if we can handle the args */
  for (i = 0; i < currentFunction->NumberOfArguments; i++)
    {
602
    if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0;
Ken Martin's avatar
Ken Martin committed
603
    /* if its a pointer arg make sure we have the ArgCount */
604
605
606
607
    if ((currentFunction->ArgTypes[i] % 0x1000 >= 0x100) &&
        (currentFunction->ArgTypes[i] % 0x1000 != 0x303)&&
        (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&&
        (currentFunction->ArgTypes[i] % 0x1000 != 0x109)) 
Ken Martin's avatar
Ken Martin committed
608
609
      {
      if (currentFunction->NumberOfArguments > 1 ||
Ken Martin's avatar
Ken Martin committed
610
611
612
613
          !currentFunction->ArgCounts[i])
        {
        args_ok = 0;
        }
Ken Martin's avatar
Ken Martin committed
614
      }
615
616
617
618
619
620
    if ((currentFunction->ArgTypes[i] % 0x100 >= 0x10)&&
        (currentFunction->ArgTypes[i] != 0x13)&&
        (currentFunction->ArgTypes[i] != 0x14)&&
        (currentFunction->ArgTypes[i] != 0x15)&&
        (currentFunction->ArgTypes[i] != 0x16)&&
        (currentFunction->ArgTypes[i] != 0x1A)) args_ok = 0;
621
    }
622
623
624
625
  if ((currentFunction->ReturnType % 0x10) == 0x8) args_ok = 0;
  if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&&
      ((currentFunction->ReturnType % 0x1000)/0x100 != 0x1)&&
      ((currentFunction->ReturnType % 0x1000)/0x100)) args_ok = 0;
626
  if (currentFunction->NumberOfArguments && 
627
      (currentFunction->ArgTypes[0] == 0x5000)
628
629
      &&(currentFunction->NumberOfArguments != 1)) args_ok = 0;

Ken Martin's avatar
Ken Martin committed
630
  /* we can't handle void * return types */
631
  if ((currentFunction->ReturnType % 0x1000) == 0x302) 
Ken Martin's avatar
Ken Martin committed
632
633
634
635
    {
    args_ok = 0;
    }
  
636
  /* watch out for functions that dont have enough info */
637
  switch (currentFunction->ReturnType % 0x1000)
638
    {
639
    case 0x301: case 0x307:
640
    case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E:
641
    case 0x313: case 0x314: case 0x315: case 0x316: case 0x31A: case 0x31B: case 0x31C:
642
643
644
645
646
647
648
649
650
      args_ok = currentFunction->HaveHint;
      break;
    }
  
  /* if the args are OK and it is not a constructor or destructor */
  if (args_ok && 
      strcmp(data->ClassName,currentFunction->Name) &&
      strcmp(data->ClassName,currentFunction->Name + 1))
    {
Ken Martin's avatar
Ken Martin committed
651
652
653
654
655
656
    int required_args = 0;
    
    /* calc the total required args */
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      required_args = required_args + 
Ken Martin's avatar
Ken Martin committed
657
        (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1);
Ken Martin's avatar
Ken Martin committed
658
659
      }
    
660
661
662
663
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
664
    fprintf(fp,"  if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n    {\n",
Ken Martin's avatar
Ken Martin committed
665
            currentFunction->Name, required_args + 2);
666
667
668
669
670
    
    /* process the args */
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      output_temp(fp, i, currentFunction->ArgTypes[i],
Ken Martin's avatar
Ken Martin committed
671
672
                  currentFunction->ArgClasses[i], 
                  currentFunction->ArgCounts[i]);
673
674
      }
    output_temp(fp, MAX_ARGS,currentFunction->ReturnType,
Ken Martin's avatar
Ken Martin committed
675
                currentFunction->ReturnClass, 0);
676

677
    /* only use the error variable if we have arguments to parse */
678
    if (currentFunction->NumberOfArguments)
679
      {
680
681
682
683
684
685
686
      fprintf(fp,"    error = 0;\n\n");
      /* now get the required args from the stack */
      for (i = 0; i < currentFunction->NumberOfArguments; i++)
        {
        get_args(fp,i);
        }
      fprintf(fp,"    if (!error)\n    {\n");
687
688
      }
    
689
    switch (currentFunction->ReturnType % 0x1000)
690
      {
691
      case 0x2:
692
        fprintf(fp,"    op->%s(",currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
693
        break;
694
      case 0x109:
695
        fprintf(fp,"    temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
696
        break;
697
      default:
698
        fprintf(fp,"    temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name);
699
700
701
702
      }
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      if (i)
Ken Martin's avatar
Ken Martin committed
703
704
705
        {
        fprintf(fp,",");
        }
706
      if (currentFunction->ArgTypes[i] == 0x109)
Ken Martin's avatar
Ken Martin committed
707
708
709
        {
        fprintf(fp,"*(temp%i)",i);
        }
710
      else if (currentFunction->ArgTypes[i] == 0x5000)
Ken Martin's avatar
Ken Martin committed
711
        {
712
        fprintf(fp,"vtkTclVoidFunc,static_cast<void *>(temp%i)",i);
Ken Martin's avatar
Ken Martin committed
713
        }
714
      else
Ken Martin's avatar
Ken Martin committed
715
716
717
        {
        fprintf(fp,"temp%i",i);
        }
718
719
720
      }
    fprintf(fp,");\n");
    if (currentFunction->NumberOfArguments && 
721
        (currentFunction->ArgTypes[0] == 0x5000))
722
      {
723
      fprintf(fp,"    op->%sArgDelete(vtkTclVoidFuncArgDelete);\n",
Ken Martin's avatar
Ken Martin committed
724
              currentFunction->Name);
725
726
      }
    return_result(fp);
727
728
    fprintf(fp,"    return TCL_OK;\n");
    
729
    /* close the if error */
730
731
732
733
734
    if (currentFunction->NumberOfArguments)
      {
      fprintf(fp,"    }\n");
      }
    
735
    fprintf(fp,"    }\n");
736
737
738
739
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
Ken Martin's avatar
Ken Martin committed
740
    
741
742
743
744
745
746
747
748
    wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
    numberOfWrappedFunctions++;
    }
}

/* print the parsed structures */
void vtkParseOutput(FILE *fp, FileInfo *data)
{
749
  int i,j;
750
751
  
  fprintf(fp,"// tcl wrapper for %s object\n//\n",data->ClassName);
752
  fprintf(fp,"#define VTK_WRAPPING_CXX\n");
753
754
  if (strcmp("vtkObjectBase",data->ClassName) != 0)
    {
755
      /* Block inclusion of full streams. */
756
757
    fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n");
    }
Will Schroeder's avatar
Will Schroeder committed
758
  fprintf(fp,"#include \"vtkSystemIncludes.h\"\n");
759
760
  fprintf(fp,"#include \"%s.h\"\n\n",data->ClassName);
  fprintf(fp,"#include \"vtkTclUtil.h\"\n");
761
  fprintf(fp,"#include <vtkstd/stdexcept>\n");
762
  fprintf(fp,"#include <vtksys/ios/sstream>\n");
763
764
  if (data->IsConcrete)
    {
765
766
    if (strcmp(data->ClassName, "vtkRenderWindowInteractor") == 0)
      {
767
      fprintf(fp,"#include \"vtkToolkits.h\"\n");
Andy Cedilnik's avatar
Andy Cedilnik committed
768
      fprintf(fp,"#if defined( VTK_USE_X ) && defined( VTK_USE_TK )\n");
769
      fprintf(fp,"# include \"vtkXRenderWindowTclInteractor.h\"\n");
Yves Starreveld's avatar
   
Yves Starreveld committed
770
      fprintf(fp,"#endif\n");
771
772
773

      fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);

Andy Cedilnik's avatar
Andy Cedilnik committed
774
      fprintf(fp,"#if defined( VTK_USE_X ) && defined( VTK_USE_TK )\n");
775
      fprintf(fp,"  %s *temp = vtkXRenderWindowTclInteractor::New();\n",
Ken Martin's avatar
Ken Martin committed
776
              data->ClassName);
777
778
779
      fprintf(fp,"#else\n");
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
      fprintf(fp,"#endif\n");
780
      fprintf(fp,"  return static_cast<ClientData>(temp);\n}\n\n");
781
782
783
784
785
      }
    else
      {
      fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
786
      fprintf(fp,"  return static_cast<ClientData>(temp);\n}\n\n");
787
      }
788
789
790
791
792
793
794
795
    }
  
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"int %sCppCommand(%s *op, Tcl_Interp *interp,\n             int argc, char *argv[]);\n",data->SuperClasses[i],data->SuperClasses[i]);
    }
  fprintf(fp,"int VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n             int argc, char *argv[]);\n",data->ClassName,data->ClassName);
  fprintf(fp,"\nint VTKTCL_EXPORT %sCommand(ClientData cd, Tcl_Interp *interp,\n             int argc, char *argv[])\n{\n",data->ClassName);
796
  fprintf(fp,"  if ((argc == 2)&&(!strcmp(\"Delete\",argv[1]))&& !vtkTclInDelete(interp))\n    {\n");
797
798
  fprintf(fp,"    Tcl_DeleteCommand(interp,argv[0]);\n");
  fprintf(fp,"    return TCL_OK;\n    }\n");
799
  fprintf(fp,"   return %sCppCommand(static_cast<%s *>(static_cast<vtkTclCommandArgStruct *>(cd)->Pointer),interp, argc, argv);\n}\n",data->ClassName,data->ClassName);
800
801
802
803
804
805
  
  fprintf(fp,"\nint VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n             int argc, char *argv[])\n{\n",data->ClassName,data->ClassName);
  fprintf(fp,"  int    tempi;\n");
  fprintf(fp,"  double tempd;\n");
  fprintf(fp,"  static char temps[80];\n");
  fprintf(fp,"  int    error;\n\n");
806
807
808
809
  fprintf(fp,"  error = 0; error = error;\n");
  fprintf(fp,"  tempi = 0; tempi = tempi;\n");
  fprintf(fp,"  tempd = 0; tempd = tempd;\n");
  fprintf(fp,"  temps[0] = 0; temps[0] = temps[0];\n\n");
810

811
  fprintf(fp,"  if (argc < 2)\n    {\n    Tcl_SetResult(interp, static_cast<char *>(\"Could not find requested method.\"), TCL_VOLATILE);\n    return TCL_ERROR;\n    }\n");
812
813
814
815
816

  /* stick in the typecasting and delete functionality here */
  fprintf(fp,"  if (!interp)\n    {\n");
  fprintf(fp,"    if (!strcmp(\"DoTypecasting\",argv[0]))\n      {\n");
  fprintf(fp,"      if (!strcmp(\"%s\",argv[1]))\n        {\n",
Ken Martin's avatar
Ken Martin committed
817
          data->ClassName);
818
  fprintf(fp,"        argv[2] = static_cast<char *>(static_cast<void *>(op));\n");
819
820
821
822
823
  fprintf(fp,"        return TCL_OK;\n        }\n");

  /* check our superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
824
    fprintf(fp,"      if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n        {\n",
Ken Martin's avatar
Ken Martin committed
825
            data->SuperClasses[i],data->SuperClasses[i]);
826
827
828
829
    fprintf(fp,"        return TCL_OK;\n        }\n");      
    }
  fprintf(fp,"      }\n    return TCL_ERROR;\n    }\n\n");
  
Ken Martin's avatar
Ken Martin committed
830
831
832
833
834
  /* add the GetSuperClassName */
  if (data->NumberOfSuperClasses)
    {
    fprintf(fp,"  if (!strcmp(\"GetSuperClassName\",argv[1]))\n");
    fprintf(fp,"    {\n");
835
    fprintf(fp,"    Tcl_SetResult(interp,static_cast<char *>(\"%s\"), TCL_VOLATILE);\n",data->SuperClasses[0]);
Ken Martin's avatar
Ken Martin committed
836
837
838
    fprintf(fp,"    return TCL_OK;\n");
    fprintf(fp,"    }\n\n");      
    }
839
  
840
841
  fprintf(fp,"  try\n    {\n");

842
843
844
845
846
847
848
849
850
  /* insert function handling code here */
  for (i = 0; i < data->NumberOfFunctions; i++)
    {
    currentFunction = data->Functions + i;
    outputFunction(fp, data);
    }
  
  /* add the ListInstances method */
  fprintf(fp,"\n  if (!strcmp(\"ListInstances\",argv[1]))\n    {\n");
851
  fprintf(fp,"    vtkTclListInstances(interp,(ClientData)(%sCommand));\n",data->ClassName);
852
853
854
855
856
857
858
859
  fprintf(fp,"    return TCL_OK;\n    }\n");
  
  /* add the ListMethods method */
  fprintf(fp,"\n  if (!strcmp(\"ListMethods\",argv[1]))\n    {\n");
  /* recurse up the tree */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"    %sCppCommand(op,interp,argc,argv);\n",
Ken Martin's avatar
Ken Martin committed
860
            data->SuperClasses[i]);
861
862
863
    }
  /* now list our methods */
  fprintf(fp,"    Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->ClassName);
Ken Martin's avatar
Ken Martin committed
864
  fprintf(fp,"    Tcl_AppendResult(interp,\"  GetSuperClassName\\n\",NULL);\n");
865
866
  for (i = 0; i < numberOfWrappedFunctions; i++)
    {
867
868
    int numArgs = 0;

869
    currentFunction = wrappedFunctions[i];
870
871
872
873
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
Ken Martin's avatar
Ken Martin committed
874
            
875
876
877
878
    /* calc the total required args */
    for (j = 0; j < currentFunction->NumberOfArguments; j++)
      {
      numArgs = numArgs + 
Ken Martin's avatar
Ken Martin committed
879
        (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
880
881
882
      }

    if (numArgs > 1)
883
884
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with %i args\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
885
              currentFunction->Name, numArgs);
886
      }
887
    if (numArgs == 1)
888
      {
Ken Martin's avatar
Ken Martin committed
889
890
          fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with 1 arg\\n\",NULL);\n",
                  currentFunction->Name);
891
      }
892
    if (numArgs == 0)
893
894
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
895
              currentFunction->Name);
896
      }
897
898
899
900
901

    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
902
903
904
905
906
907
    }
  fprintf(fp,"    return TCL_OK;\n    }\n");
  
  /* try superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
908
    fprintf(fp,"\n  if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n",
Ken Martin's avatar
Ken Martin committed
909
            data->SuperClasses[i], data->SuperClasses[i]);
910
911
912
    fprintf(fp,"    {\n    return TCL_OK;\n    }\n");
    }
  
913
  /* Add the Print method to vtkObjectBase. */
914
  if (!strcmp("vtkObjectBase",data->ClassName))
915
916
    {
    fprintf(fp,"  if ((!strcmp(\"Print\",argv[1]))&&(argc == 2))\n    {\n");
917
    fprintf(fp,"    vtksys_ios::ostringstream buf_with_warning_C4701;\n");
918
919
    fprintf(fp,"    op->Print(buf_with_warning_C4701);\n");
    fprintf(fp,"    buf_with_warning_C4701.put('\\0');\n");
920
    fprintf(fp,"    Tcl_SetResult(interp,const_cast<char *>(buf_with_warning_C4701.str().c_str()),\n");
921
    fprintf(fp,"      TCL_VOLATILE);\n");
922
    fprintf(fp,"    return TCL_OK;\n    }\n");
923
924
    /* Add the PrintRevisions method to vtkObjectBase. */
    fprintf(fp,"  if ((!strcmp(\"PrintRevisions\",argv[1]))&&(argc == 2))\n    {\n");
925
    fprintf(fp,"    vtksys_ios::ostringstream buf_with_warning_C4701;\n");
926
927
    fprintf(fp,"    op->PrintRevisions(buf_with_warning_C4701);\n");
    fprintf(fp,"    buf_with_warning_C4701.put('\\0');\n");
928
    fprintf(fp,"    Tcl_SetResult(interp,const_cast<char *>(buf_with_warning_C4701.str().c_str()),\n");
929
    fprintf(fp,"      TCL_VOLATILE);\n");
930
    fprintf(fp,"    return TCL_OK;\n    }\n");    
931
    }
932
  /* Add the AddObserver method to vtkObject. */
933
934
  if (!strcmp("vtkObject",data->ClassName))
    {
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
    fprintf(fp,"  if ((!strcmp(\"AddObserver\",argv[1]))&&(argc >= 4))\n    {\n");
    fprintf(fp,"    error = 0;\n");
    fprintf(fp,"    if (argc > 4 && Tcl_GetDouble(interp,argv[4],&tempd) != TCL_OK) error = 1;\n");
    fprintf(fp,"    if (!error)\n      {\n");
    fprintf(fp,"      vtkTclCommand *cbc = vtkTclCommand::New();\n");
    fprintf(fp,"      cbc->SetInterp(interp);\n");
    fprintf(fp,"      cbc->SetStringCommand(argv[3]);\n");
    fprintf(fp,"      unsigned long      temp20;\n");
    fprintf(fp,"      if (argc > 4)\n        {\n");
    fprintf(fp,"        temp20 = op->AddObserver(argv[2],cbc,tempd);\n");
    fprintf(fp,"        }\n      else\n        {\n");
    fprintf(fp,"        temp20 = op->AddObserver(argv[2],cbc);\n");
    fprintf(fp,"        }\n");
    fprintf(fp,"      cbc->Delete();\n");
    fprintf(fp,"      char tempResult[1024];\n");
    fprintf(fp,"      sprintf(tempResult,\"%%li\",temp20);\n");
    fprintf(fp,"      Tcl_SetResult(interp,tempResult,TCL_VOLATILE);\n");
    fprintf(fp,"      return TCL_OK;\n      }\n");
    fprintf(fp,"    }\n");
954
955
956
    }
  fprintf(fp,"\n  if ((argc >= 2)&&(!strstr(interp->result,\"Object named:\")))\n    {\n");
  fprintf(fp,"    char temps2[256];\n    sprintf(temps2,\"Object named: %%s, could not find requested method: %%s\\nor the method was called with incorrect arguments.\\n\",argv[0],argv[1]);\n    Tcl_AppendResult(interp,temps2,NULL);\n    }\n");
957
958
959
960
961
962
  fprintf(fp,"    }\n");
  fprintf(fp,"  catch (vtkstd::exception &e)\n");
  fprintf(fp,"    {\n");
  fprintf(fp,"    Tcl_AppendResult(interp, \"Uncaught exception: \",  e.what(), \"\\n\", NULL);\n");
  fprintf(fp,"    return TCL_ERROR;\n");
  fprintf(fp,"    }\n");
963
964
965
  fprintf(fp,"  return TCL_ERROR;\n}\n");

}