File: gap_array.c

package info (click to toggle)
staden 2.0.0%2Bb11-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 21,556 kB
  • sloc: ansic: 240,603; tcl: 65,360; cpp: 12,854; makefile: 11,201; sh: 2,952; fortran: 2,033; perl: 63; awk: 46
file content (56 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "gap_array.h"
#include "active_tags.h"
#include "tcl_utils.h"

/*****************************************************************************/
/*                            C2TclArray                                     */
/*****************************************************************************/
/* convert C array into tcl array */
/* elment_array: C array */
/* num_elements: number of elements in C array */
/* tcl_array: tcl array name */
/* tcl_num_ele: tcl variable to contain number of elements in array */

int
C2TclArray(Tcl_Interp *interp,                                    /* in, out */
	   char *element_array[],                                      /* in */
	   int num_elements,                                           /* in */
	   char *tcl_array,                                            /* in */
	   char *tcl_num_ele)                                          /* in */
{
  int item;
  char item_str[1024];
  char num_ele_str[1024];
  
  /* convert num_elements into a string */
  sprintf(num_ele_str, "%d", num_elements);

  /* create tcl variable passed as tcl_num_ele to hold num_elements */
  if (Tcl_SetVar(interp, tcl_num_ele, num_ele_str, 0) == NULL) {

      return TCL_ERROR; 
      
  } /* end if */

  for (item = 0; item < num_elements; item++) {

      /* convert each element of the array into a string for Tcl_SetVar */
      sprintf(item_str, "%d", item);

      /* create tcl array and set the corresponding C item of each element of
       * the array 
       */
      if (Tcl_SetVar2(interp, tcl_array, item_str, element_array[item], 0) 
	  ==  NULL) {  
	  Tcl_SetResult(interp, "Tcl_SetVar2 failed", TCL_STATIC);
	  return TCL_ERROR; 

      } /* end if */

  } /* end for */

  return TCL_OK;

} /* end C2TclArray */