vtkWrapTcl.c 39.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 <ctype.h>
17
#include <stdio.h>
18
#include <stdlib.h>
19
#include <string.h>
20
#include "vtkParse.h"
21
#include "vtkConfigure.h"
22
23
24

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

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* convert special characters in a string into their escape codes,
   so that the string can be quoted in a source file (the specified
   maxlen must be at least 32 chars)*/
static const char *quote_string(const char *comment, int maxlen)
{
  static char *result = 0;
  static int oldmaxlen = 0;
  int i, j, n;

  if (maxlen > oldmaxlen)
    {
    if (result)
      {
      free(result);
      }
Francois Bertel's avatar
Francois Bertel committed
42
    result = (char *)malloc((size_t)(maxlen+1));
43
44
45
46
47
48
49
50
51
52
53
    oldmaxlen = maxlen;
    }

  if (comment == NULL)
    {
    return "";
    }

  j = 0;

  n = (int)strlen(comment);
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
  for (i = 0; i < n; i++)
    {
    if (comment[i] == '\"')
      {
      strcpy(&result[j],"\\\"");
      j += 2;
      }
    else if (comment[i] == '\\')
      {
      strcpy(&result[j],"\\\\");
      j += 2;
      }
    else if (comment[i] == ']')
      {
      strcpy(&result[j],"\\\\]");
      j += 3;
      }
    else if (comment[i] == '[')
      {
      strcpy(&result[j],"\\\\[");
      j += 3;
      }
    else if (comment[i] == '\n')
      {
      strcpy(&result[j],"\\n");
      j += 2;
      }      
    else if (isprint(comment[i]))
      {
      result[j] = comment[i];
      j++;
      }
    else
      {
      sprintf(&result[j],"\\%3.3o",comment[i]);
      j += 4;
      }
92

93
    if (j >= maxlen - 21)
94
      {
95
96
97
98
99
      sprintf(&result[j]," ...\\n [Truncated]\\n");
      j += (int)strlen(" ...\\n [Truncated]\\n");
      break;
      }
    }
100

101
102
103
104
  result[j] = '\0';

  return result;
}
105

Ken Martin's avatar
Ken Martin committed
106
void output_temp(FILE *fp, int i, int aType, char *Id, int count)
107
108
{
  /* handle VAR FUNCTIONS */
109
  if (aType == 0x5000)
110
111
112
113
    {
    fprintf(fp,"    vtkTclVoidFuncArg *temp%i = new vtkTclVoidFuncArg;\n",i);
    return;
    }
114

115
  /* ignore void */
116
  if (((aType % 0x10) == 0x2)&&(!((aType % 0x1000)/0x100)))
117
118
119
120
121
    {
    return;
    }

  /* for const * return types prototype with const */
122
  if ((i == MAX_ARGS) && (aType % 0x2000 >= 0x1000))
123
124
125
126
127
128
129
130
    {
    fprintf(fp,"    const ");
    }
  else
    {
    fprintf(fp,"    ");
    }

131
  if ((aType % 0x100)/0x10 == 0x1)
132
133
134
135
    {
    fprintf(fp,"unsigned ");
    }

136
  switch (aType % 0x10)
137
    {
138
139
140
141
142
143
144
145
146
    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;
147
148
    case 0xB:   fprintf(fp,"long long "); break;
    case 0xC:   fprintf(fp,"__int64 "); break;
149
    case 0xD:   fprintf(fp,"signed char "); break;
150
    case 0xE:   fprintf(fp,"bool "); break;
151
    case 0x8: return;
152
153
    }

Ken Martin's avatar
Ken Martin committed
154
  /* handle array arguements */
155
  if (count > 0x1)
Ken Martin's avatar
Ken Martin committed
156
157
158
159
160
    {
    fprintf(fp,"temp%i[%i];\n",i,count);
    return;
    }
  
161
  switch ((aType % 0x1000)/0x100)
162
    {
163
164
165
166
167
168
    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;
169
170
171
172
173
174
175
176
177
178
179
180
    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;

181
182
183
184
185
#define INDENT "    "

  fprintf(fp,INDENT "if(temp%i)\n",MAX_ARGS);
  fprintf(fp,INDENT "  {\n");
  fprintf(fp,INDENT "  char tempResult[1024];\n");
186
  fprintf(fp,INDENT "  *tempResult = '\\0';\n");
187

188
189
190
191
192
193
  /* special case for double: use Tcl_PrintDouble to control precision */
  if (currentFunction->ReturnType % 0x1000 != 0x301
       && currentFunction->ReturnType % 0x1000 != 0x307 )
    {
    fprintf(fp,INDENT "  sprintf(tempResult,\"");
    }
194

195
  /* use the hint */
196
  switch (currentFunction->ReturnType % 0x1000)
197
    {
198
    case 0x301: case 0x307:  
199
200
      fprintf(fp,INDENT "  char converted[1024];\n");
      fprintf(fp,INDENT "  *converted = '\\0';\n");
201
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
202
        {
203
204
205
        fprintf(fp,INDENT "  Tcl_PrintDouble(interp,temp%i[%i], converted);\n",MAX_ARGS,i);
        fprintf(fp,INDENT "  strcat(tempResult, \" \");\n");
        fprintf(fp,INDENT "  strcat(tempResult, converted);\n");
Ken Martin's avatar
Ken Martin committed
206
        }
207
      break;
208

209
    case 0x304: case 0x305: case 0x30D:
210
211
212
#ifndef VTK_USE_64BIT_IDS
    case 0x30A:
#endif
213
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
214
215
216
        {
        fprintf(fp,"%%i ");
        }
217
      break;
218

219
220
221
222
223
224
    case 0x30E:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%i ");
        }
      break;
225

226
227
228
229
230
231
    case 0x306:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%li ");
        }
      break;
232

233
234
235
236
237
238
239
240
241
242
243
244
#ifdef VTK_USE_64BIT_IDS
    case 0x30A:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
#  if defined(_MSC_VER)
        fprintf(fp,"%%I64i ");
#  else
        fprintf(fp,"%%lli ");
#  endif
        }
      break;
#endif
245

246
247
248
249
250
251
    case 0x30B:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%lli ");
        }
      break;
252

253
254
255
256
257
258
    case 0x30C:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%I64i ");
        }
      break;
259

260
261
262
263
    case 0x313: case 0x314: case 0x315:
#ifndef VTK_USE_64BIT_IDS
    case 0x31A:
#endif
Ken Martin's avatar
Ken Martin committed
264
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
265
266
267
        {
        fprintf(fp,"%%u ");
        }
Ken Martin's avatar
Ken Martin committed
268
      break;
269

270
271
272
273
274
275
    case 0x316:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%lu ");
        }
      break;
276

277
278
279
280
281
282
283
284
285
286
287
288
#ifdef VTK_USE_64BIT_IDS
    case 0x31A:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
#  if defined(_MSC_VER)
        fprintf(fp,"%%I64u ");
#  else
        fprintf(fp,"%%llu ");
#  endif
        }
      break;
#endif
289

290
291
292
293
294
295
    case 0x31B:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%llu ");
        }
      break;
296

297
298
299
300
301
302
    case 0x31C:
      for (i = 0; i < currentFunction->HintSize; i++)
        {
        fprintf(fp,"%%I64u ");
        }
      break;
303
    }
304

305
306
  if (currentFunction->ReturnType % 0x1000 != 0x301
       && currentFunction->ReturnType % 0x1000 != 0x307 )
307
    {
308
309
310
311
312
313
    fprintf(fp,"\"");
    for (i = 0; i < currentFunction->HintSize; i++)
      {
      fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
      }
    fprintf(fp,");\n");
314
315
316
317
318
319
    }

  fprintf(fp,INDENT "  Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
  fprintf(fp,INDENT "  }\n");
  fprintf(fp,INDENT "else\n");
  fprintf(fp,INDENT "  {\n");
320
  fprintf(fp,INDENT "  Tcl_SetResult(interp, const_cast<char *>(\"\"), TCL_VOLATILE);\n");
321
322
323
  fprintf(fp,INDENT "  }\n");

#undef INDENT
324
325
326
327
}

void return_result(FILE *fp)
{
328
  switch (currentFunction->ReturnType % 0x1000)
329
    {
330
    case 0x2:
331
      fprintf(fp,"    Tcl_ResetResult(interp);\n"); 
332
      break;
333
    case 0x1: case 0x7: 
334
      fprintf(fp,"    char tempResult[1024];\n");
335
336
337
338
339
       /*
        * use tcl's print double function to support variable
        * precision at runtime
        */
      fprintf(fp,"    Tcl_PrintDouble(interp,temp%i,tempResult);\n",
Ken Martin's avatar
Ken Martin committed
340
              MAX_ARGS); 
341
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
342
      break;
343
344
345
346
    case 0x4:  
#ifndef VTK_USE_64BIT_IDS
    case 0xA:
#endif
347
    case 0xD:
348
349
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%i\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
350
              MAX_ARGS); 
351
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
352
      break;
353
354
355
356
357
358
    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;
359
    case 0x5:
360
361
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hi\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
362
              MAX_ARGS); 
363
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
364
      break;
365
    case 0x6:
366
367
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%li\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
368
              MAX_ARGS);
369
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
370
      break;
371
372
373
374
375
376
377
378
379
380
381
382
383
#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
384
385
386
387
388
389
390
391
392
393
394
395
    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;
396
397
398
399
    case 0x14:
#ifndef VTK_USE_64BIT_IDS
    case 0x1A:
#endif
400
401
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%u\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
402
              MAX_ARGS); 
403
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
404
      break;
405
    case 0x15: 
406
407
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
408
              MAX_ARGS);  
409
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
410
      break;
411
    case 0x16:  
412
413
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%lu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
414
              MAX_ARGS);
415
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
416
      break;
417
    case 0x13:
418
419
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
420
              MAX_ARGS); 
421
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
422
      break;
423
424
425
426
427
428
429
430
431
432
433
434
435
#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
436
437
438
439
440
441
442
443
444
445
446
447
    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;
448
    case 0x303:
449
      fprintf(fp,"    if (temp%i)\n      {\n      Tcl_SetResult(interp, const_cast<char *>(temp%i), TCL_VOLATILE);\n",MAX_ARGS,MAX_ARGS); 
450
451
      fprintf(fp,"      }\n    else\n      {\n");
      fprintf(fp,"      Tcl_ResetResult(interp);\n      }\n"); 
452
      break;
453
    case 0x3:
454
455
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%c\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
456
              MAX_ARGS); 
457
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
458
      break;
459
460
    case 0x109:
    case 0x309:  
461
      fprintf(fp,"      vtkTclGetObjectFromPointer(interp,(void *)(temp%i),\"%s\");\n",MAX_ARGS,currentFunction->ReturnClass);
462
463
464
465
      break;

    /* handle functions returning vectors */
    /* this is done by looking them up in a hint file */
466
    case 0x301: case 0x307:
467
    case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E:
468
    case 0x313: case 0x314: case 0x315: case 0x316: case 0x31A: case 0x31B: case 0x31C:
469
470
471
      use_hints(fp);
      break;
    default:
472
      fprintf(fp,"    Tcl_SetResult(interp, const_cast<char *>(\"unable to return result.\"), TCL_VOLATILE);\n");
473
474
475
476
477
478
      break;
    }
}

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

void outputFunction(FILE *fp, FileInfo *data)
{
  int i;
  int args_ok = 1;
 
  /* some functions will not get wrapped no matter what else */
616
  if (currentFunction->IsOperator || 
617
      currentFunction->ArrayFailure ||
Ken Martin's avatar
Ken Martin committed
618
619
      !currentFunction->IsPublic ||
      !currentFunction->Name) 
620
621
622
623
624
625
626
    {
    return;
    }
  
  /* check to see if we can handle the args */
  for (i = 0; i < currentFunction->NumberOfArguments; i++)
    {
627
    if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0;
Ken Martin's avatar
Ken Martin committed
628
    /* if its a pointer arg make sure we have the ArgCount */
629
630
631
632
    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
633
634
      {
      if (currentFunction->NumberOfArguments > 1 ||
Ken Martin's avatar
Ken Martin committed
635
636
637
638
          !currentFunction->ArgCounts[i])
        {
        args_ok = 0;
        }
Ken Martin's avatar
Ken Martin committed
639
      }
640
641
642
643
644
645
    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;
646
    }
647
648
649
650
  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;
651
  if (currentFunction->NumberOfArguments && 
652
      (currentFunction->ArgTypes[0] == 0x5000)
653
654
      &&(currentFunction->NumberOfArguments != 1)) args_ok = 0;

Ken Martin's avatar
Ken Martin committed
655
  /* we can't handle void * return types */
656
  if ((currentFunction->ReturnType % 0x1000) == 0x302) 
Ken Martin's avatar
Ken Martin committed
657
658
659
660
    {
    args_ok = 0;
    }
  
661
  /* watch out for functions that dont have enough info */
662
  switch (currentFunction->ReturnType % 0x1000)
663
    {
664
    case 0x301: case 0x307:
665
    case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E:
666
    case 0x313: case 0x314: case 0x315: case 0x316: case 0x31A: case 0x31B: case 0x31C:
667
668
669
670
671
672
673
674
675
      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
676
677
678
679
680
681
    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
682
        (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1);
Ken Martin's avatar
Ken Martin committed
683
684
      }
    
685
686
687
688
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
689
    fprintf(fp,"  if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n    {\n",
Ken Martin's avatar
Ken Martin committed
690
            currentFunction->Name, required_args + 2);
691
692
693
694
695
    
    /* process the args */
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      output_temp(fp, i, currentFunction->ArgTypes[i],
Ken Martin's avatar
Ken Martin committed
696
697
                  currentFunction->ArgClasses[i], 
                  currentFunction->ArgCounts[i]);
698
699
      }
    output_temp(fp, MAX_ARGS,currentFunction->ReturnType,
Ken Martin's avatar
Ken Martin committed
700
                currentFunction->ReturnClass, 0);
701

702
    /* only use the error variable if we have arguments to parse */
703
    if (currentFunction->NumberOfArguments)
704
      {
705
706
707
708
709
710
711
      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");
712
713
      }
    
714
    switch (currentFunction->ReturnType % 0x1000)
715
      {
716
      case 0x2:
717
        fprintf(fp,"    op->%s(",currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
718
        break;
719
      case 0x109:
720
        fprintf(fp,"    temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
721
        break;
722
      default:
723
        fprintf(fp,"    temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name);
724
725
726
727
      }
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      if (i)
Ken Martin's avatar
Ken Martin committed
728
729
730
        {
        fprintf(fp,",");
        }
731
      if (currentFunction->ArgTypes[i] == 0x109)
Ken Martin's avatar
Ken Martin committed
732
733
734
        {
        fprintf(fp,"*(temp%i)",i);
        }
735
      else if (currentFunction->ArgTypes[i] == 0x5000)
Ken Martin's avatar
Ken Martin committed
736
        {
737
        fprintf(fp,"vtkTclVoidFunc,static_cast<void *>(temp%i)",i);
Ken Martin's avatar
Ken Martin committed
738
        }
739
      else
Ken Martin's avatar
Ken Martin committed
740
741
742
        {
        fprintf(fp,"temp%i",i);
        }
743
744
745
      }
    fprintf(fp,");\n");
    if (currentFunction->NumberOfArguments && 
746
        (currentFunction->ArgTypes[0] == 0x5000))
747
      {
748
      fprintf(fp,"    op->%sArgDelete(vtkTclVoidFuncArgDelete);\n",
Ken Martin's avatar
Ken Martin committed
749
              currentFunction->Name);
750
751
      }
    return_result(fp);
752
753
    fprintf(fp,"    return TCL_OK;\n");
    
754
    /* close the if error */
755
756
757
758
759
    if (currentFunction->NumberOfArguments)
      {
      fprintf(fp,"    }\n");
      }
    
760
    fprintf(fp,"    }\n");
761
762
763
764
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
Ken Martin's avatar
Ken Martin committed
765
    
766
767
768
769
770
771
772
773
    wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
    numberOfWrappedFunctions++;
    }
}

/* print the parsed structures */
void vtkParseOutput(FILE *fp, FileInfo *data)
{
774
  int i,j,k;
775
776
  
  fprintf(fp,"// tcl wrapper for %s object\n//\n",data->ClassName);
777
  fprintf(fp,"#define VTK_WRAPPING_CXX\n");
778
779
  if (strcmp("vtkObjectBase",data->ClassName) != 0)
    {
780
      /* Block inclusion of full streams. */
781
782
    fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n");
    }
Will Schroeder's avatar
Will Schroeder committed
783
  fprintf(fp,"#include \"vtkSystemIncludes.h\"\n");
784
785
  fprintf(fp,"#include \"%s.h\"\n\n",data->ClassName);
  fprintf(fp,"#include \"vtkTclUtil.h\"\n");
786
  fprintf(fp,"#include <vtkstd/stdexcept>\n");
787
  fprintf(fp,"#include <vtksys/ios/sstream>\n");
788
789
  if (data->IsConcrete)
    {
790
791
    if (strcmp(data->ClassName, "vtkRenderWindowInteractor") == 0)
      {
792
      fprintf(fp,"#include \"vtkToolkits.h\"\n");
Andy Cedilnik's avatar
Andy Cedilnik committed
793
      fprintf(fp,"#if defined( VTK_USE_X ) && defined( VTK_USE_TK )\n");
794
      fprintf(fp,"# include \"vtkXRenderWindowTclInteractor.h\"\n");
Yves Starreveld's avatar
   
Yves Starreveld committed
795
      fprintf(fp,"#endif\n");
796
797
798

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

Andy Cedilnik's avatar
Andy Cedilnik committed
799
      fprintf(fp,"#if defined( VTK_USE_X ) && defined( VTK_USE_TK )\n");
800
      fprintf(fp,"  %s *temp = vtkXRenderWindowTclInteractor::New();\n",
Ken Martin's avatar
Ken Martin committed
801
              data->ClassName);
802
803
804
      fprintf(fp,"#else\n");
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
      fprintf(fp,"#endif\n");
805
      fprintf(fp,"  return static_cast<ClientData>(temp);\n}\n\n");
806
807
808
809
810
      }
    else
      {
      fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
811
      fprintf(fp,"  return static_cast<ClientData>(temp);\n}\n\n");
812
      }
813
814
815
816
817
818
819
820
    }
  
  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);
821
  fprintf(fp,"  if ((argc == 2)&&(!strcmp(\"Delete\",argv[1]))&& !vtkTclInDelete(interp))\n    {\n");
822
823
  fprintf(fp,"    Tcl_DeleteCommand(interp,argv[0]);\n");
  fprintf(fp,"    return TCL_OK;\n    }\n");
824
  fprintf(fp,"   return %sCppCommand(static_cast<%s *>(static_cast<vtkTclCommandArgStruct *>(cd)->Pointer),interp, argc, argv);\n}\n",data->ClassName,data->ClassName);
825
826
827
828
829
830
  
  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");
831
832
833
834
  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");
835

836
  fprintf(fp,"  if (argc < 2)\n    {\n    Tcl_SetResult(interp,const_cast<char *>(\"Could not find requested method.\"), TCL_VOLATILE);\n    return TCL_ERROR;\n    }\n");
837
838
839
840
841

  /* 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
842
          data->ClassName);
843
  fprintf(fp,"        argv[2] = static_cast<char *>(static_cast<void *>(op));\n");
844
845
846
847
848
  fprintf(fp,"        return TCL_OK;\n        }\n");

  /* check our superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
849
    fprintf(fp,"      if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n        {\n",
Ken Martin's avatar
Ken Martin committed
850
            data->SuperClasses[i],data->SuperClasses[i]);
851
852
853
854
    fprintf(fp,"        return TCL_OK;\n        }\n");      
    }
  fprintf(fp,"      }\n    return TCL_ERROR;\n    }\n\n");
  
Ken Martin's avatar
Ken Martin committed
855
856
857
858
859
  /* add the GetSuperClassName */
  if (data->NumberOfSuperClasses)
    {
    fprintf(fp,"  if (!strcmp(\"GetSuperClassName\",argv[1]))\n");
    fprintf(fp,"    {\n");
860
    fprintf(fp,"    Tcl_SetResult(interp,const_cast<char *>(\"%s\"), TCL_VOLATILE);\n",data->SuperClasses[0]);
Ken Martin's avatar
Ken Martin committed
861
862
863
    fprintf(fp,"    return TCL_OK;\n");
    fprintf(fp,"    }\n\n");      
    }
864
  
865
866
  fprintf(fp,"  try\n    {\n");

867
868
869
870
871
872
873
874
875
  /* 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");
876
  fprintf(fp,"    vtkTclListInstances(interp,(ClientData)(%sCommand));\n",data->ClassName);
877
878
879
880
881
882
883
884
  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
885
            data->SuperClasses[i]);
886
887
888
    }
  /* now list our methods */
  fprintf(fp,"    Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->ClassName);
Ken Martin's avatar
Ken Martin committed
889
  fprintf(fp,"    Tcl_AppendResult(interp,\"  GetSuperClassName\\n\",NULL);\n");
890
891
  for (i = 0; i < numberOfWrappedFunctions; i++)
    {
892
893
    int numArgs = 0;

894
    currentFunction = wrappedFunctions[i];
895
896
897
898
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
Ken Martin's avatar
Ken Martin committed
899
            
900
901
902
903
    /* calc the total required args */
    for (j = 0; j < currentFunction->NumberOfArguments; j++)
      {
      numArgs = numArgs + 
Ken Martin's avatar
Ken Martin committed
904
        (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
905
906
907
      }

    if (numArgs > 1)
908
909
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with %i args\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
910
              currentFunction->Name, numArgs);
911
      }
912
    if (numArgs == 1)
913
      {
Ken Martin's avatar
Ken Martin committed
914
915
          fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with 1 arg\\n\",NULL);\n",
                  currentFunction->Name);
916
      }
917
    if (numArgs == 0)
918
919
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
920
              currentFunction->Name);
921
      }
922
923
924
925
926

    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
927
928
    }
  fprintf(fp,"    return TCL_OK;\n    }\n");
929

930
  
931
932
933
  /* add the DescribeMethods method */
  fprintf(fp,"\n  if (!strcmp(\"DescribeMethods\",argv[1]))\n    {\n");
  fprintf(fp,"    if(argc>3) {\n" );
934
  fprintf(fp,"      Tcl_SetResult ( interp, const_cast<char*>(\"Wrong number of arguments: object DescribeMethods <MethodName>\"), TCL_VOLATILE ); \n" );
935
936
937
  fprintf(fp,"      return TCL_ERROR;\n }\n" );
  
  fprintf(fp,"    if(argc==2) {\n" );
938
  /* Return a list of methods */
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
  fprintf(fp,"\n  Tcl_DString dString, dStringParent;\n");
  fprintf(fp,"\n  Tcl_DStringInit ( &dString );\n" );
  fprintf(fp,"\n  Tcl_DStringInit ( &dStringParent );\n" );
  /* recurse up the tree */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"    %sCppCommand(op,interp,argc,argv);\n",
            data->SuperClasses[i]);
    /* append the result to our string */
    fprintf(fp,"    Tcl_DStringGetResult ( interp, &dStringParent );\n" );
    fprintf(fp,"    Tcl_DStringAppend ( &dString, Tcl_DStringValue ( &dStringParent ), -1 );\n" );
    }
  for (k = 0; k < numberOfWrappedFunctions; k++)
    {
      currentFunction = wrappedFunctions[k];
      if(currentFunction->IsLegacy)
        {
          fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
        }
      fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"%s\" );\n", currentFunction->Name );
     if(currentFunction->IsLegacy)
        {
          fprintf(fp,"#endif\n");
        }
    }
  fprintf(fp,"  Tcl_DStringResult ( interp, &dString );\n" );
  fprintf(fp,"  Tcl_DStringFree ( &dString );\n" );
  fprintf(fp,"  Tcl_DStringFree ( &dStringParent );\n" );
  fprintf(fp,"    return TCL_OK;\n    }\n");

  /* Now handle if we are asked for a specific function */
  fprintf(fp,"    if(argc==3) {\n" );
  fprintf(fp,"      Tcl_DString dString;\n");
  if (data->NumberOfSuperClasses > 0)
  {
    fprintf(fp,"      int SuperClassStatus;\n" );
  }
  /* recurse up the tree */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"    SuperClassStatus = %sCppCommand(op,interp,argc,argv);\n",
            data->SuperClasses[i]);
    fprintf(fp,"    if ( SuperClassStatus == TCL_OK ) { return TCL_OK; }\n" );
    }
983
  /* Now we handle it ourselves */
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
  for (k = 0; k < numberOfWrappedFunctions; k++)
    {
      currentFunction = wrappedFunctions[k];
      if(currentFunction->IsLegacy)
        {
          fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
        }
      fprintf(fp,"    /* Starting function: %s */\n", currentFunction->Name );
      fprintf(fp,"    if ( strcmp ( argv[2], \"%s\" ) == 0 ) {\n", currentFunction->Name );
      fprintf(fp,"    Tcl_DStringInit ( &dString );\n" );
      
      fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"%s\" );\n", currentFunction->Name );
      
      /* calc the total required args */
      fprintf(fp,"    /* Arguments */\n" );
      fprintf(fp,"    Tcl_DStringStartSublist ( &dString );\n" );
      for (i = 0; i < currentFunction->NumberOfArguments; i++)
        {
          int argtype;
          if (currentFunction->ArgTypes[i] == 0x5000)
            {
              fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"function\" );\n" );
              continue;
            }
          
          argtype = currentFunction->ArgTypes[i] % 0x1000;
          switch (argtype)
            {
            case 0x301:
            case 0x307:
              /* Vector */
              fprintf(fp,"    Tcl_DStringStartSublist ( &dString );\n" );
              for (j = 0; j < currentFunction->ArgCounts[i]; j++) 
                {
                  fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"float\" );\n" );
                }
              fprintf(fp,"    Tcl_DStringEndSublist ( &dString );\n" );
              break;
            case 0x304:
              /* Vector */
              fprintf(fp,"    Tcl_DStringStartSublist ( &dString );\n" );
              for (j = 0; j < currentFunction->ArgCounts[i]; j++) 
                {
                  fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"int\" );\n" );
                }
              fprintf(fp,"    Tcl_DStringEndSublist ( &dString );\n" );
              break;
            case 0x30A:
              /* Vector */
              fprintf(fp,"    Tcl_DStringStartSublist ( &dString );\n" );
              for (j = 0; j < currentFunction->ArgCounts[i]; j++) 
                {
                  fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"int\" );\n" );
                }
              fprintf(fp,"    Tcl_DStringEndSublist ( &dString );\n" );
              break;
            case 0x30B: case 0x30C:
              /* Vector */
              fprintf(fp,"    Tcl_DStringStartSublist ( &dString );\n" );
              for (j = 0; j < currentFunction->ArgCounts[i]; j++) 
                {
                  fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"int\" );\n" );
                }
              fprintf(fp,"    Tcl_DStringEndSublist ( &dString );\n" );
              break;
            case 0x109:
            case 0x309: fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"%s\" );\n", currentFunction->ArgClasses[i] ); break;
            case 0x302:
            case 0x303: fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"string\" );\n" ); break;
            case 0x1:
            case 0x7:   fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"float\" );\n" ); break;
            case 0xD:
            case 0xA:
            case 0x1B:
            case 0xB:
            case 0x1C:
            case 0xC:
            case 0x14:
            case 0x4:
            case 0x15:
            case 0x5:
            case 0x16:
            case 0x6:   fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); break;
            case 0x3:   fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"char\" );\n" ); break;
            case 0x13:  fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"int\" );\n" ); break;
            case 0xE:   fprintf(fp,"    Tcl_DStringAppendElement ( &dString, \"bool\" );\n" ); break;
            }
        }
      fprintf(fp,"    Tcl_DStringEndSublist ( &dString );