vtkWrapTcl.c 24.9 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
19
20
21
#include "vtkParse.h"

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


Ken Martin's avatar
Ken Martin committed
25
void output_temp(FILE *fp, int i, int aType, char *Id, int count)
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
{
  /* handle VAR FUNCTIONS */
  if (aType == 5000)
    {
    fprintf(fp,"    vtkTclVoidFuncArg *temp%i = new vtkTclVoidFuncArg;\n",i);
    return;
    }
  
  /* ignore void */
  if (((aType % 10) == 2)&&(!((aType%1000)/100)))
    {
    return;
    }

  /* for const * return types prototype with const */
  if ((i == MAX_ARGS) && (aType%2000 >= 1000))
    {
    fprintf(fp,"    const ");
    }
  else
    {
    fprintf(fp,"    ");
    }

  if ((aType%100)/10 == 1)
    {
    fprintf(fp,"unsigned ");
    }

  switch (aType%10)
    {
    case 1:   fprintf(fp,"float  "); break;
    case 7:   fprintf(fp,"double "); break;
    case 4:   fprintf(fp,"int    "); break;
    case 5:   fprintf(fp,"short  "); break;
    case 6:   fprintf(fp,"long   "); break;
    case 2:     fprintf(fp,"void   "); break;
    case 3:     fprintf(fp,"char   "); break;
    case 9:     fprintf(fp,"%s ",Id); break;
    case 8: return;
    }

Ken Martin's avatar
Ken Martin committed
68
69
70
71
72
73
74
  /* handle array arguements */
  if (count > 1)
    {
    fprintf(fp,"temp%i[%i];\n",i,count);
    return;
    }
  
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  switch ((aType%1000)/100)
    {
    case 1: fprintf(fp, " *"); break; /* act " &" */
    case 2: fprintf(fp, "&&"); break;
    case 3: fprintf(fp, " *"); break;
    case 4: fprintf(fp, "&*"); break;
    case 5: fprintf(fp, "*&"); break;
    case 7: fprintf(fp, "**"); break;
    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 */
  switch (currentFunction->ReturnType%1000)
    {
    case 301: case 307:  
99
100
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
101
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
102
103
104
        {
        fprintf(fp,"%%g ");
        }
105
106
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
107
108
109
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
110
      fprintf(fp,");\n");
111
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
112
      break;
Ken Martin's avatar
Ken Martin committed
113
    case 304: case 305: case 306: 
114
115
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
116
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
117
118
119
        {
        fprintf(fp,"%%i ");
        }
120
121
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
122
123
124
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
125
      fprintf(fp,");\n");
126
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
127
      break;
Ken Martin's avatar
Ken Martin committed
128
    case 313: case 314: case 315: case 316:
129
130
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
Ken Martin's avatar
Ken Martin committed
131
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
132
133
134
        {
        fprintf(fp,"%%u ");
        }
Ken Martin's avatar
Ken Martin committed
135
136
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
137
138
139
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
Ken Martin's avatar
Ken Martin committed
140
      fprintf(fp,");\n");
141
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
Ken Martin's avatar
Ken Martin committed
142
      break;
143
144
145
146
147
148
149
150
    }
}

void return_result(FILE *fp)
{
  switch (currentFunction->ReturnType%1000)
    {
    case 2:
151
      fprintf(fp,"    Tcl_ResetResult(interp);\n"); 
152
      break;
153
    case 1: case 7: 
154
155
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%g\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
156
              MAX_ARGS); 
157
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
158
      break;
159
    case 4:  
160
161
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%i\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
162
              MAX_ARGS); 
163
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
164
165
      break;
    case 5:
166
167
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hi\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
168
              MAX_ARGS); 
169
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
170
171
      break;
    case 6:
172
173
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%li\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
174
              MAX_ARGS);
175
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
176
      break;
177
    case 14:
178
179
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%u\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
180
              MAX_ARGS); 
181
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
182
      break;
183
    case 15: 
184
185
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
186
              MAX_ARGS);  
187
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
188
      break;
189
    case 16:  
190
191
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%lu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
192
              MAX_ARGS);
193
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
194
195
      break;
    case 13:
196
197
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
198
              MAX_ARGS); 
199
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
200
201
      break;
    case 303:
202
203
204
      fprintf(fp,"    if (temp%i)\n      {\n      Tcl_SetResult(interp, (char*)temp%i, TCL_VOLATILE);\n",MAX_ARGS,MAX_ARGS); 
      fprintf(fp,"      }\n    else\n      {\n");
      fprintf(fp,"      Tcl_ResetResult(interp);\n      }\n"); 
205
206
      break;
    case 3:
207
208
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%c\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
209
              MAX_ARGS); 
210
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
211
212
213
      break;
    case 109:
    case 309:  
214
      fprintf(fp,"    vtkTclGetObjectFromPointer(interp,(void *)temp%i,%sCommand);\n",MAX_ARGS,currentFunction->ReturnClass);
215
216
217
218
219
220
      break;

    /* handle functions returning vectors */
    /* this is done by looking them up in a hint file */
    case 301: case 307:
    case 304: case 305: case 306:
221
    case 313: case 314: case 315: case 316:      
222
223
224
      use_hints(fp);
      break;
    default:
Bill Lorensen's avatar
Bill Lorensen committed
225
      fprintf(fp,"    Tcl_SetResult(interp, (char *) \"unable to return result.\", TCL_VOLATILE);\n");
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
      break;
    }
}

void handle_return_prototype(FILE *fp)
{
  switch (currentFunction->ReturnType%1000)
    {
    case 109:
    case 309:  
      fprintf(fp,"    int %sCommand(ClientData, Tcl_Interp *, int, char *[]);\n",currentFunction->ReturnClass);
      break;
    }
}

void get_args(FILE *fp, int i)
{
Ken Martin's avatar
Ken Martin committed
243
244
245
246
247
248
249
250
251
252
  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);
    }
  
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  /* handle VAR FUNCTIONS */
  if (currentFunction->ArgTypes[i] == 5000)
    {
    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 */
  if (((currentFunction->ArgTypes[i] % 10) == 2)&&
      (!((currentFunction->ArgTypes[i]%1000)/100)))
    {
    return;
    }
  
  switch (currentFunction->ArgTypes[i]%1000)
    {
    case 1: case 7:  
      fprintf(fp,
Ken Martin's avatar
Ken Martin committed
272
273
              "    if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
              start_arg); 
274
275
276
277
      fprintf(fp,"    temp%i = tempd;\n",i);
      break;
    case 4: case 5: case 6: 
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
278
              start_arg); 
279
280
281
      fprintf(fp,"    temp%i = tempi;\n",i);
      break;
    case 3:
Ken Martin's avatar
Ken Martin committed
282
      fprintf(fp,"    temp%i = *(argv[%i]);\n",i,start_arg);
283
284
285
      break;
    case 13:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
286
              start_arg); 
287
288
289
290
      fprintf(fp,"    temp%i = (unsigned char)tempi;\n",i);
      break;
    case 14:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
291
              start_arg); 
292
293
294
295
      fprintf(fp,"    temp%i = (unsigned int)tempi;\n",i);
      break;
    case 15:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
296
              start_arg); 
297
298
      fprintf(fp,"    temp%i = (unsigned short)tempi;\n",i);
      break;
Ken Martin's avatar
Ken Martin committed
299
300
    case 16:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
301
              start_arg); 
Ken Martin's avatar
Ken Martin committed
302
303
      fprintf(fp,"    temp%i = (unsigned long)tempi;\n",i);
      break;
304
    case 303:
Ken Martin's avatar
Ken Martin committed
305
      fprintf(fp,"    temp%i = argv[%i];\n",i,start_arg);
306
307
308
      break;
    case 109:
    case 309:
309
      fprintf(fp,"    temp%i = (%s *)(vtkTclGetPointerFromObject(argv[%i],(char *) \"%s\",interp,error));\n",i,currentFunction->ArgClasses[i],start_arg,
Ken Martin's avatar
Ken Martin committed
310
              currentFunction->ArgClasses[i]);
311
312
313
314
      break;
    case 2:    
    case 9:
      break;
Ken Martin's avatar
Ken Martin committed
315
316
    default:
      if (currentFunction->ArgCounts[i] > 1)
Ken Martin's avatar
Ken Martin committed
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
        {
        for (j = 0; j < currentFunction->ArgCounts[i]; j++)
          {
          switch (currentFunction->ArgTypes[i]%100)
            {
            case 1: case 7:  
              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;
            case 4: case 5: case 6: 
              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;
            case 3:
              fprintf(fp,"    temp%i[%i] = *(argv[%i]);\n",i,j,start_arg);
              break;
            case 13:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned char)tempi;\n",i,j);
              break;
            case 14:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned int)tempi;\n",i,j);
              break;
            case 15:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned short)tempi;\n",i,j);
              break;
            case 16:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned long)tempi;\n",i,j);
              break;
            }
          start_arg++;
          }
        }
Ken Martin's avatar
Ken Martin committed
360
      
361
362
363
364
365
366
367
368
369
    }
}

void outputFunction(FILE *fp, FileInfo *data)
{
  int i;
  int args_ok = 1;
 
  /* some functions will not get wrapped no matter what else */
370
  if (currentFunction->IsOperator || 
371
      currentFunction->ArrayFailure ||
Ken Martin's avatar
Ken Martin committed
372
373
      !currentFunction->IsPublic ||
      !currentFunction->Name) 
374
375
376
377
378
379
380
381
    {
    return;
    }
  
  /* check to see if we can handle the args */
  for (i = 0; i < currentFunction->NumberOfArguments; i++)
    {
    if ((currentFunction->ArgTypes[i]%10) == 8) args_ok = 0;
Ken Martin's avatar
Ken Martin committed
382
    /* if its a pointer arg make sure we have the ArgCount */
383
    if ((currentFunction->ArgTypes[i]%1000 >= 100) &&
Ken Martin's avatar
Ken Martin committed
384
385
386
        (currentFunction->ArgTypes[i]%1000 != 303)&&
        (currentFunction->ArgTypes[i]%1000 != 309)&&
        (currentFunction->ArgTypes[i]%1000 != 109)) 
Ken Martin's avatar
Ken Martin committed
387
388
      {
      if (currentFunction->NumberOfArguments > 1 ||
Ken Martin's avatar
Ken Martin committed
389
390
391
392
          !currentFunction->ArgCounts[i])
        {
        args_ok = 0;
        }
Ken Martin's avatar
Ken Martin committed
393
      }
394
    if ((currentFunction->ArgTypes[i]%100 >= 10)&&
Ken Martin's avatar
Ken Martin committed
395
396
397
398
        (currentFunction->ArgTypes[i] != 13)&&
        (currentFunction->ArgTypes[i] != 14)&&
        (currentFunction->ArgTypes[i] != 15)&&
        (currentFunction->ArgTypes[i] != 16)) args_ok = 0;
399
400
401
402
403
404
405
406
407
    }
  if ((currentFunction->ReturnType%10) == 8) args_ok = 0;
  if (((currentFunction->ReturnType%1000)/100 != 3)&&
      ((currentFunction->ReturnType%1000)/100 != 1)&&
      ((currentFunction->ReturnType%1000)/100)) args_ok = 0;
  if (currentFunction->NumberOfArguments && 
      (currentFunction->ArgTypes[0] == 5000)
      &&(currentFunction->NumberOfArguments != 1)) args_ok = 0;

Ken Martin's avatar
Ken Martin committed
408
409
410
411
412
413
  /* we can't handle void * return types */
  if ((currentFunction->ReturnType%1000) == 302) 
    {
    args_ok = 0;
    }
  
414
415
416
417
418
  /* watch out for functions that dont have enough info */
  switch (currentFunction->ReturnType%1000)
    {
    case 301: case 307:
    case 304: case 305: case 306:
419
    case 313: case 314: case 315: case 316:
420
421
422
423
424
425
426
427
428
      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
429
430
431
432
433
434
    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
435
        (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1);
Ken Martin's avatar
Ken Martin committed
436
437
      }
    
438
439
440
441
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
442
    fprintf(fp,"  if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n    {\n",
Ken Martin's avatar
Ken Martin committed
443
            currentFunction->Name, required_args + 2);
444
445
446
447
448
    
    /* process the args */
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      output_temp(fp, i, currentFunction->ArgTypes[i],
Ken Martin's avatar
Ken Martin committed
449
450
                  currentFunction->ArgClasses[i], 
                  currentFunction->ArgCounts[i]);
451
452
      }
    output_temp(fp, MAX_ARGS,currentFunction->ReturnType,
Ken Martin's avatar
Ken Martin committed
453
                currentFunction->ReturnClass, 0);
454
    handle_return_prototype(fp);
455
456
    // only use the error variable if we have arguments to parse
    if (currentFunction->NumberOfArguments)
457
      {
458
459
460
461
462
463
464
      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");
465
466
467
468
469
      }
    
    switch (currentFunction->ReturnType%1000)
      {
      case 2:
470
        fprintf(fp,"    op->%s(",currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
471
        break;
472
      case 109:
473
        fprintf(fp,"    temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
474
        break;
475
      default:
476
        fprintf(fp,"    temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name);
477
478
479
480
      }
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      if (i)
Ken Martin's avatar
Ken Martin committed
481
482
483
        {
        fprintf(fp,",");
        }
484
      if (currentFunction->ArgTypes[i] == 109)
Ken Martin's avatar
Ken Martin committed
485
486
487
        {
        fprintf(fp,"*(temp%i)",i);
        }
488
      else if (currentFunction->ArgTypes[i] == 5000)
Ken Martin's avatar
Ken Martin committed
489
490
491
        {
        fprintf(fp,"vtkTclVoidFunc,(void *)temp%i",i);
        }
492
      else
Ken Martin's avatar
Ken Martin committed
493
494
495
        {
        fprintf(fp,"temp%i",i);
        }
496
497
498
      }
    fprintf(fp,");\n");
    if (currentFunction->NumberOfArguments && 
Ken Martin's avatar
Ken Martin committed
499
        (currentFunction->ArgTypes[0] == 5000))
500
      {
501
      fprintf(fp,"    op->%sArgDelete(vtkTclVoidFuncArgDelete);\n",
Ken Martin's avatar
Ken Martin committed
502
              currentFunction->Name);
503
504
      }
    return_result(fp);
505
506
507
508
509
510
511
512
    fprintf(fp,"    return TCL_OK;\n");
    
    // close the if error
    if (currentFunction->NumberOfArguments)
      {
      fprintf(fp,"    }\n");
      }
    
513
    fprintf(fp,"    }\n");
514
515
516
517
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
Ken Martin's avatar
Ken Martin committed
518
    
519
520
521
522
523
524
525
526
    wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
    numberOfWrappedFunctions++;
    }
}

/* print the parsed structures */
void vtkParseOutput(FILE *fp, FileInfo *data)
{
527
  int i,j;
528
529
  
  fprintf(fp,"// tcl wrapper for %s object\n//\n",data->ClassName);
530
531
  if (strcmp("vtkObjectBase",data->ClassName) != 0)
    {
532
      /* Block inclusion of full streams. */
533
534
    fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n");
    }
Will Schroeder's avatar
Will Schroeder committed
535
  fprintf(fp,"#include \"vtkSystemIncludes.h\"\n");
536
537
538
539
  fprintf(fp,"#include \"%s.h\"\n\n",data->ClassName);
  fprintf(fp,"#include \"vtkTclUtil.h\"\n");
  if (data->IsConcrete)
    {
540
541
    if (strcmp(data->ClassName, "vtkRenderWindowInteractor") == 0)
      {
542
543
544
      fprintf(fp,"#include \"vtkToolkits.h\"\n");
      fprintf(fp,"#ifdef VTK_USE_X\n");
      fprintf(fp,"# include \"vtkXRenderWindowTclInteractor.h\"\n");
Yves Starreveld's avatar
   
Yves Starreveld committed
545
      fprintf(fp,"#endif\n");
546
547
548

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

549
      fprintf(fp,"#ifdef VTK_USE_X\n");
550
      fprintf(fp,"  %s *temp = vtkXRenderWindowTclInteractor::New();\n",
Ken Martin's avatar
Ken Martin committed
551
              data->ClassName);
552
553
554
555
556
557
558
559
560
561
562
      fprintf(fp,"#else\n");
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
      fprintf(fp,"#endif\n");
      fprintf(fp,"  return ((ClientData)temp);\n}\n\n");
      }
    else
      {
      fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
      fprintf(fp,"  return ((ClientData)temp);\n}\n\n");
      }
563
564
565
566
567
568
569
570
    }
  
  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);
571
  fprintf(fp,"  if ((argc == 2)&&(!strcmp(\"Delete\",argv[1]))&& !vtkTclInDelete(interp))\n    {\n");
572
573
  fprintf(fp,"    Tcl_DeleteCommand(interp,argv[0]);\n");
  fprintf(fp,"    return TCL_OK;\n    }\n");
574
  fprintf(fp,"   return %sCppCommand((%s *)(((vtkTclCommandArgStruct *)cd)->Pointer),interp, argc, argv);\n}\n",data->ClassName,data->ClassName);
575
576
577
578
579
580
  
  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");
581
582
583
584
  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");
585

586
  fprintf(fp,"  if (argc < 2)\n    {\n    Tcl_SetResult(interp, (char *) \"Could not find requested method.\", TCL_VOLATILE);\n    return TCL_ERROR;\n    }\n");
587
588
589
590
591

  /* 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
592
          data->ClassName);
593
594
595
596
597
598
599
  fprintf(fp,"        argv[2] = (char *)((void *)op);\n");
  fprintf(fp,"        return TCL_OK;\n        }\n");

  /* check our superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"      if (%sCppCommand((%s *)op,interp,argc,argv) == TCL_OK)\n        {\n",
Ken Martin's avatar
Ken Martin committed
600
            data->SuperClasses[i],data->SuperClasses[i]);
601
602
603
604
    fprintf(fp,"        return TCL_OK;\n        }\n");      
    }
  fprintf(fp,"      }\n    return TCL_ERROR;\n    }\n\n");
  
Ken Martin's avatar
Ken Martin committed
605
606
607
608
609
  /* add the GetSuperClassName */
  if (data->NumberOfSuperClasses)
    {
    fprintf(fp,"  if (!strcmp(\"GetSuperClassName\",argv[1]))\n");
    fprintf(fp,"    {\n");
610
    fprintf(fp,"    Tcl_SetResult(interp,(char *) \"%s\", TCL_VOLATILE);\n",data->SuperClasses[0]);
Ken Martin's avatar
Ken Martin committed
611
612
613
    fprintf(fp,"    return TCL_OK;\n");
    fprintf(fp,"    }\n\n");      
    }
614
615
616
617
618
619
620
621
622
623
  
  /* 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");
Jim Miller's avatar
Jim Miller committed
624
  fprintf(fp,"    vtkTclListInstances(interp,(ClientData)%sCommand);\n",data->ClassName);
625
626
627
628
629
630
631
632
  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
633
            data->SuperClasses[i]);
634
635
636
    }
  /* now list our methods */
  fprintf(fp,"    Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->ClassName);
Ken Martin's avatar
Ken Martin committed
637
  fprintf(fp,"    Tcl_AppendResult(interp,\"  GetSuperClassName\\n\",NULL);\n");
638
639
  for (i = 0; i < numberOfWrappedFunctions; i++)
    {
640
641
    int numArgs = 0;

642
    currentFunction = wrappedFunctions[i];
643
644
645
646
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
Ken Martin's avatar
Ken Martin committed
647
            
648
649
650
651
    /* calc the total required args */
    for (j = 0; j < currentFunction->NumberOfArguments; j++)
      {
      numArgs = numArgs + 
Ken Martin's avatar
Ken Martin committed
652
        (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
653
654
655
      }

    if (numArgs > 1)
656
657
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with %i args\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
658
              currentFunction->Name, numArgs);
659
      }
660
    if (numArgs == 1)
661
      {
Ken Martin's avatar
Ken Martin committed
662
663
          fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with 1 arg\\n\",NULL);\n",
                  currentFunction->Name);
664
      }
665
    if (numArgs == 0)
666
667
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
668
              currentFunction->Name);
669
      }
670
671
672
673
674

    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
675
676
677
678
679
680
681
    }
  fprintf(fp,"    return TCL_OK;\n    }\n");
  
  /* try superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"\n  if (%sCppCommand((%s *)op,interp,argc,argv) == TCL_OK)\n",
Ken Martin's avatar
Ken Martin committed
682
            data->SuperClasses[i], data->SuperClasses[i]);
683
684
685
    fprintf(fp,"    {\n    return TCL_OK;\n    }\n");
    }
  
686
  /* Add the Print method to vtkObjectBase. */
687
  if (!strcmp("vtkObjectBase",data->ClassName))
688
689
    {
    fprintf(fp,"  if ((!strcmp(\"Print\",argv[1]))&&(argc == 2))\n    {\n");
690
691
692
693
694
695
    fprintf(fp,"    ostrstream buf_with_warning_C4701;\n");
    fprintf(fp,"    op->Print(buf_with_warning_C4701);\n");
    fprintf(fp,"    buf_with_warning_C4701.put('\\0');\n");
    fprintf(fp,"    Tcl_SetResult(interp,buf_with_warning_C4701.str(),\n");
    fprintf(fp,"      TCL_VOLATILE);\n");
    fprintf(fp,"    buf_with_warning_C4701.rdbuf()->freeze(0);\n");
696
    fprintf(fp,"    return TCL_OK;\n    }\n");
697
698
    /* Add the PrintRevisions method to vtkObjectBase. */
    fprintf(fp,"  if ((!strcmp(\"PrintRevisions\",argv[1]))&&(argc == 2))\n    {\n");
699
700
701
702
703
704
    fprintf(fp,"    ostrstream buf_with_warning_C4701;\n");
    fprintf(fp,"    op->PrintRevisions(buf_with_warning_C4701);\n");
    fprintf(fp,"    buf_with_warning_C4701.put('\\0');\n");
    fprintf(fp,"    Tcl_SetResult(interp,buf_with_warning_C4701.str(),\n");
    fprintf(fp,"      TCL_VOLATILE);\n");
    fprintf(fp,"    delete [] buf_with_warning_C4701.str();\n");
705
    fprintf(fp,"    return TCL_OK;\n    }\n");    
706
    }
707
  /* Add the AddObserver method to vtkObject. */
708
709
  if (!strcmp("vtkObject",data->ClassName))
    {
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
    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");
729
730
731
732
733
734
    }
  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");
  fprintf(fp,"  return TCL_ERROR;\n}\n");

}