summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-07-08 17:13:47 (GMT)
committerjoye <joye>2014-07-08 17:13:47 (GMT)
commitce9561bee4d1cd04214541cce65c3a93fe605ad5 (patch)
treedd64cca971f11d68e2542fc17d108d4bd5e68393 /src
parentf6affbcfef4841070559bd95d40f5a2c26581f7e (diff)
downloadblt-ce9561bee4d1cd04214541cce65c3a93fe605ad5.zip
blt-ce9561bee4d1cd04214541cce65c3a93fe605ad5.tar.gz
blt-ce9561bee4d1cd04214541cce65c3a93fe605ad5.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltChain.C2
-rw-r--r--src/bltGrAxis.h2
-rw-r--r--src/bltGrElem.h2
-rw-r--r--src/bltGrElemOption.C2
-rw-r--r--src/bltGrMarker.h2
-rw-r--r--src/bltGraph.h2
-rw-r--r--src/bltInt.C2
-rw-r--r--src/bltOp.C2
-rw-r--r--src/bltParse.C2
-rw-r--r--src/bltSwitch.C4
-rw-r--r--src/bltSwitch.h78
-rw-r--r--src/bltVecCmd.C2906
-rw-r--r--src/bltVecInt.h128
-rw-r--r--src/bltVecMath.C2553
-rw-r--r--src/bltVector.C3099
-rw-r--r--src/bltVector.h48
16 files changed, 4388 insertions, 4446 deletions
diff --git a/src/bltChain.C b/src/bltChain.C
index 6443671..7fb076d 100644
--- a/src/bltChain.C
+++ b/src/bltChain.C
@@ -29,9 +29,7 @@
#include <stdlib.h>
-extern "C" {
#include "bltChain.h"
-};
#ifndef ALIGN
#define ALIGN(a) \
diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h
index 12ef74a..75b0b92 100644
--- a/src/bltGrAxis.h
+++ b/src/bltGrAxis.h
@@ -35,9 +35,7 @@
#include <tk.h>
-extern "C" {
#include "bltChain.h"
-};
#include "bltGrMisc.h"
#include "bltGrText.h"
diff --git a/src/bltGrElem.h b/src/bltGrElem.h
index 3263000..f909227 100644
--- a/src/bltGrElem.h
+++ b/src/bltGrElem.h
@@ -32,10 +32,8 @@
#include <tk.h>
-extern "C" {
#include "bltVector.h"
#include "bltChain.h"
-};
#include "bltGrMisc.h"
#include "bltGrPen.h"
diff --git a/src/bltGrElemOption.C b/src/bltGrElemOption.C
index f5bf8b1..781b1e1 100644
--- a/src/bltGrElemOption.C
+++ b/src/bltGrElemOption.C
@@ -32,9 +32,7 @@
#include <stdlib.h>
#include <string.h>
-extern "C" {
#include "bltChain.h"
-};
#include "bltGraph.h"
#include "bltGrElem.h"
diff --git a/src/bltGrMarker.h b/src/bltGrMarker.h
index 8aeae4f..0522cf8 100644
--- a/src/bltGrMarker.h
+++ b/src/bltGrMarker.h
@@ -32,9 +32,7 @@
#include <tk.h>
-extern "C" {
#include "bltChain.h"
-};
#include "bltGrMisc.h"
#include "bltGrPSOutput.h"
diff --git a/src/bltGraph.h b/src/bltGraph.h
index 036e96d..1861a25 100644
--- a/src/bltGraph.h
+++ b/src/bltGraph.h
@@ -32,9 +32,7 @@
#include <tk.h>
-extern "C" {
#include "bltChain.h"
-};
#include "bltGrMisc.h"
#include "bltGrText.h"
diff --git a/src/bltInt.C b/src/bltInt.C
index 2c69ed5..e1c0623 100644
--- a/src/bltInt.C
+++ b/src/bltInt.C
@@ -32,9 +32,9 @@
extern "C" {
Tcl_AppInitProc Tkblt_Init;
Tcl_AppInitProc Tkblt_SafeInit;
-Tcl_AppInitProc Blt_VectorCmdInitProc;
};
+Tcl_AppInitProc Blt_VectorCmdInitProc;
Tcl_AppInitProc Blt_GraphCmdInitProc;
int Tkblt_Init(Tcl_Interp* interp)
diff --git a/src/bltOp.C b/src/bltOp.C
index 429e8f9..c30aded 100644
--- a/src/bltOp.C
+++ b/src/bltOp.C
@@ -29,9 +29,7 @@
#include <string.h>
-extern "C" {
#include "bltOp.h"
-};
static int BinaryOpSearch(Blt_OpSpec *specs, int nSpecs,
const char *string, int length)
diff --git a/src/bltParse.C b/src/bltParse.C
index 2f0a03c..f968cf0 100644
--- a/src/bltParse.C
+++ b/src/bltParse.C
@@ -33,9 +33,7 @@ using namespace std;
#include <tcl.h>
-extern "C" {
#include "bltParse.h"
-};
/*
* A table used to classify input characters to assist in parsing
diff --git a/src/bltSwitch.C b/src/bltSwitch.C
index 489568f..bb4a62f 100644
--- a/src/bltSwitch.C
+++ b/src/bltSwitch.C
@@ -37,9 +37,7 @@ using namespace std;
#include <tcl.h>
-extern "C" {
#include "bltSwitch.h"
-};
#define COUNT_NNEG 0
#define COUNT_POS 1
@@ -56,7 +54,7 @@ static char* Blt_Strdup(const char *string)
}
static int Blt_GetCountFromObj(Tcl_Interp* interp, Tcl_Obj *objPtr, int check,
- long *valuePtr)
+ long *valuePtr)
{
long count;
if (Tcl_GetLongFromObj(interp, objPtr, &count) != TCL_OK)
diff --git a/src/bltSwitch.h b/src/bltSwitch.h
index 20c7f80..dab5e37 100644
--- a/src/bltSwitch.h
+++ b/src/bltSwitch.h
@@ -36,19 +36,19 @@
# include <stddef.h>
typedef int (Blt_SwitchParseProc)(ClientData clientData, Tcl_Interp* interp,
- const char *switchName, Tcl_Obj *valueObjPtr, char *record, int offset,
- int flags);
+ const char *switchName, Tcl_Obj *valueObjPtr, char *record, int offset,
+ int flags);
typedef void (Blt_SwitchFreeProc)(char *record, int offset, int flags);
typedef struct {
- Blt_SwitchParseProc *parseProc; /* Procedure to parse a switch
- * value and store it in its *
- * converted form in the data *
- * record. */
+ Blt_SwitchParseProc *parseProc; /* Procedure to parse a switch
+ * value and store it in its *
+ * converted form in the data *
+ * record. */
- Blt_SwitchFreeProc *freeProc; /* Procedure to free a switch. */
+ Blt_SwitchFreeProc *freeProc; /* Procedure to free a switch. */
- ClientData clientData; /* Arbitrary one-word value used by
+ ClientData clientData; /* Arbitrary one-word value used by
* switch parser, passed to
* parseProc. */
} Blt_SwitchCustom;
@@ -59,50 +59,50 @@ typedef struct {
* documentation for details.
*/
typedef enum {
- BLT_SWITCH_BOOLEAN,
- BLT_SWITCH_DOUBLE,
- BLT_SWITCH_BITMASK,
- BLT_SWITCH_BITMASK_INVERT,
- BLT_SWITCH_FLOAT,
- BLT_SWITCH_INT,
- BLT_SWITCH_INT_NNEG,
- BLT_SWITCH_INT_POS,
- BLT_SWITCH_LIST,
- BLT_SWITCH_LONG,
- BLT_SWITCH_LONG_NNEG,
- BLT_SWITCH_LONG_POS,
- BLT_SWITCH_OBJ,
- BLT_SWITCH_STRING,
- BLT_SWITCH_VALUE,
- BLT_SWITCH_CUSTOM,
- BLT_SWITCH_END
+ BLT_SWITCH_BOOLEAN,
+ BLT_SWITCH_DOUBLE,
+ BLT_SWITCH_BITMASK,
+ BLT_SWITCH_BITMASK_INVERT,
+ BLT_SWITCH_FLOAT,
+ BLT_SWITCH_INT,
+ BLT_SWITCH_INT_NNEG,
+ BLT_SWITCH_INT_POS,
+ BLT_SWITCH_LIST,
+ BLT_SWITCH_LONG,
+ BLT_SWITCH_LONG_NNEG,
+ BLT_SWITCH_LONG_POS,
+ BLT_SWITCH_OBJ,
+ BLT_SWITCH_STRING,
+ BLT_SWITCH_VALUE,
+ BLT_SWITCH_CUSTOM,
+ BLT_SWITCH_END
} Blt_SwitchTypes;
typedef struct {
- Blt_SwitchTypes type; /* Type of option, such as
- * BLT_SWITCH_COLOR; see definitions
- * below. Last option in table must
- * have type BLT_SWITCH_END. */
+ Blt_SwitchTypes type; /* Type of option, such as
+ * BLT_SWITCH_COLOR; see definitions
+ * below. Last option in table must
+ * have type BLT_SWITCH_END. */
- const char *switchName; /* Switch used to specify option in
+ const char *switchName; /* Switch used to specify option in
* argv. NULL means this spec is part
* of a group. */
- const char *help; /* Help string. */
- int offset; /* Where in widget record to store
+ const char *help; /* Help string. */
+ int offset; /* Where in widget record to store
* value; use Blt_Offset macro to
* generate values for this. */
- int flags; /* Any combination of the values
+ int flags; /* Any combination of the values
* defined below. */
- unsigned int mask;
+ unsigned int mask;
- Blt_SwitchCustom *customPtr; /* If type is BLT_SWITCH_CUSTOM then
- * this is a pointer to info about how
- * to parse and print the option.
- * Otherwise it is irrelevant. */
+ Blt_SwitchCustom *customPtr; /* If type is BLT_SWITCH_CUSTOM then
+ * this is a pointer to info about how
+ * to parse and print the option.
+ * Otherwise it is irrelevant. */
} Blt_SwitchSpec;
#define BLT_SWITCH_DEFAULTS (0)
@@ -120,7 +120,7 @@ typedef struct {
#define BLT_SWITCH_USER_BIT (1<<8)
extern int Blt_ParseSwitches(Tcl_Interp* interp, Blt_SwitchSpec *specPtr,
- int objc, Tcl_Obj *const *objv, void *rec, int flags);
+ int objc, Tcl_Obj *const *objv, void *rec, int flags);
extern void Blt_FreeSwitches(Blt_SwitchSpec *specs, void *rec, int flags);
diff --git a/src/bltVecCmd.C b/src/bltVecCmd.C
index e615ec2..dda383e 100644
--- a/src/bltVecCmd.C
+++ b/src/bltVecCmd.C
@@ -58,80 +58,80 @@
#include "bltSwitch.h"
extern int Blt_SimplifyLine (Point2d *origPts, int low, int high,
- double tolerance, int *indices);
+ double tolerance, int *indices);
typedef int (VectorCmdProc)(Vector *vPtr, Tcl_Interp* interp, int objc,
- Tcl_Obj* const objv[]);
+ Tcl_Obj* const objv[]);
typedef int (QSortCompareProc) (const void *, const void *);
static Blt_SwitchParseProc ObjToFFTVector;
static Blt_SwitchCustom fftVectorSwitch = {
- ObjToFFTVector, NULL, (ClientData)0,
+ ObjToFFTVector, NULL, (ClientData)0,
};
static Blt_SwitchParseProc ObjToIndex;
static Blt_SwitchCustom indexSwitch = {
- ObjToIndex, NULL, (ClientData)0,
+ ObjToIndex, NULL, (ClientData)0,
};
typedef struct {
- Tcl_Obj *formatObjPtr;
- int from, to;
+ Tcl_Obj *formatObjPtr;
+ int from, to;
} PrintSwitches;
static Blt_SwitchSpec printSwitches[] =
-{
+ {
{BLT_SWITCH_OBJ, "-format", "string",
- Tk_Offset(PrintSwitches, formatObjPtr), 0},
+ Tk_Offset(PrintSwitches, formatObjPtr), 0},
{BLT_SWITCH_CUSTOM, "-from", "index",
- Tk_Offset(PrintSwitches, from), 0, 0, &indexSwitch},
+ Tk_Offset(PrintSwitches, from), 0, 0, &indexSwitch},
{BLT_SWITCH_CUSTOM, "-to", "index",
- Tk_Offset(PrintSwitches, to), 0, 0, &indexSwitch},
+ Tk_Offset(PrintSwitches, to), 0, 0, &indexSwitch},
{BLT_SWITCH_END}
-};
+ };
typedef struct {
- int flags;
+ int flags;
} SortSwitches;
#define SORT_DECREASING (1<<0)
#define SORT_UNIQUE (1<<1)
static Blt_SwitchSpec sortSwitches[] =
-{
+ {
{BLT_SWITCH_BITMASK, "-decreasing", "",
Tk_Offset(SortSwitches, flags), 0, SORT_DECREASING},
- {BLT_SWITCH_BITMASK, "-reverse", "",
- Tk_Offset(SortSwitches, flags), 0, SORT_DECREASING},
- {BLT_SWITCH_BITMASK, "-uniq", "",
- Tk_Offset(SortSwitches, flags), 0, SORT_UNIQUE},
- {BLT_SWITCH_END}
-};
+ {BLT_SWITCH_BITMASK, "-reverse", "",
+ Tk_Offset(SortSwitches, flags), 0, SORT_DECREASING},
+ {BLT_SWITCH_BITMASK, "-uniq", "",
+ Tk_Offset(SortSwitches, flags), 0, SORT_UNIQUE},
+ {BLT_SWITCH_END}
+ };
typedef struct {
- double delta;
- Vector *imagPtr; /* Vector containing imaginary part. */
- Vector *freqPtr; /* Vector containing frequencies. */
- VectorInterpData *dataPtr;
- int mask; /* Flags controlling FFT. */
+ double delta;
+ Vector *imagPtr; /* Vector containing imaginary part. */
+ Vector *freqPtr; /* Vector containing frequencies. */
+ VectorInterpData *dataPtr;
+ int mask; /* Flags controlling FFT. */
} FFTData;
static Blt_SwitchSpec fftSwitches[] = {
- {BLT_SWITCH_CUSTOM, "-imagpart", "vector",
- Tk_Offset(FFTData, imagPtr), 0, 0, &fftVectorSwitch},
- {BLT_SWITCH_BITMASK, "-noconstant", "",
- Tk_Offset(FFTData, mask), 0, FFT_NO_CONSTANT},
- {BLT_SWITCH_BITMASK, "-spectrum", "",
- Tk_Offset(FFTData, mask), 0, FFT_SPECTRUM},
- {BLT_SWITCH_BITMASK, "-bartlett", "",
- Tk_Offset(FFTData, mask), 0, FFT_BARTLETT},
- {BLT_SWITCH_DOUBLE, "-delta", "float",
- Tk_Offset(FFTData, mask), 0, 0, },
- {BLT_SWITCH_CUSTOM, "-frequencies", "vector",
- Tk_Offset(FFTData, freqPtr), 0, 0, &fftVectorSwitch},
- {BLT_SWITCH_END}
+ {BLT_SWITCH_CUSTOM, "-imagpart", "vector",
+ Tk_Offset(FFTData, imagPtr), 0, 0, &fftVectorSwitch},
+ {BLT_SWITCH_BITMASK, "-noconstant", "",
+ Tk_Offset(FFTData, mask), 0, FFT_NO_CONSTANT},
+ {BLT_SWITCH_BITMASK, "-spectrum", "",
+ Tk_Offset(FFTData, mask), 0, FFT_SPECTRUM},
+ {BLT_SWITCH_BITMASK, "-bartlett", "",
+ Tk_Offset(FFTData, mask), 0, FFT_BARTLETT},
+ {BLT_SWITCH_DOUBLE, "-delta", "float",
+ Tk_Offset(FFTData, mask), 0, 0, },
+ {BLT_SWITCH_CUSTOM, "-frequencies", "vector",
+ Tk_Offset(FFTData, freqPtr), 0, 0, &fftVectorSwitch},
+ {BLT_SWITCH_END}
};
static int Blt_ExprIntFromObj(Tcl_Interp* interp, Tcl_Obj *objPtr, int *valuePtr)
@@ -177,27 +177,27 @@ static int Blt_ExprDoubleFromObj(Tcl_Interp* interp, Tcl_Obj *objPtr, double *va
/*ARGSUSED*/
static int
ObjToFFTVector(
- ClientData clientData, /* Not used. */
- Tcl_Interp* interp, /* Interpreter to send results back to */
- const char *switchName, /* Not used. */
- Tcl_Obj *objPtr, /* Name of vector. */
- char *record, /* Structure record */
- int offset, /* Offset to field in structure */
- int flags) /* Not used. */
+ ClientData clientData, /* Not used. */
+ Tcl_Interp* interp, /* Interpreter to send results back to */
+ const char *switchName, /* Not used. */
+ Tcl_Obj *objPtr, /* Name of vector. */
+ char *record, /* Structure record */
+ int offset, /* Offset to field in structure */
+ int flags) /* Not used. */
{
- FFTData *dataPtr = (FFTData *)record;
- Vector *vPtr;
- Vector **vPtrPtr = (Vector **)(record + offset);
- int isNew; /* Not used. */
- char *string;
-
- string = Tcl_GetString(objPtr);
- vPtr = Blt_Vec_Create(dataPtr->dataPtr, string, string, string, &isNew);
- if (vPtr == NULL) {
- return TCL_ERROR;
- }
- *vPtrPtr = vPtr;
- return TCL_OK;
+ FFTData *dataPtr = (FFTData *)record;
+ Vector *vPtr;
+ Vector **vPtrPtr = (Vector **)(record + offset);
+ int isNew; /* Not used. */
+ char *string;
+
+ string = Tcl_GetString(objPtr);
+ vPtr = Blt_Vec_Create(dataPtr->dataPtr, string, string, string, &isNew);
+ if (vPtr == NULL) {
+ return TCL_ERROR;
+ }
+ *vPtrPtr = vPtr;
+ return TCL_OK;
}
/*
@@ -215,116 +215,116 @@ ObjToFFTVector(
/*ARGSUSED*/
static int
ObjToIndex(
- ClientData clientData, /* Contains the vector in question to verify
- * its length. */
- Tcl_Interp* interp, /* Interpreter to send results back to */
- const char *switchName, /* Not used. */
- Tcl_Obj *objPtr, /* Name of vector. */
- char *record, /* Structure record */
- int offset, /* Offset to field in structure */
- int flags) /* Not used. */
+ ClientData clientData, /* Contains the vector in question to verify
+ * its length. */
+ Tcl_Interp* interp, /* Interpreter to send results back to */
+ const char *switchName, /* Not used. */
+ Tcl_Obj *objPtr, /* Name of vector. */
+ char *record, /* Structure record */
+ int offset, /* Offset to field in structure */
+ int flags) /* Not used. */
{
- Vector *vPtr = clientData;
- int *indexPtr = (int *)(record + offset);
- int index;
+ Vector *vPtr = (Vector*)clientData;
+ int *indexPtr = (int *)(record + offset);
+ int index;
- if (Blt_Vec_GetIndex(interp, vPtr, Tcl_GetString(objPtr), &index,
- INDEX_CHECK, (Blt_VectorIndexProc **)NULL) != TCL_OK) {
- return TCL_ERROR;
- }
- *indexPtr = index;
- return TCL_OK;
+ if (Blt_Vec_GetIndex(interp, vPtr, Tcl_GetString(objPtr), &index,
+ INDEX_CHECK, (Blt_VectorIndexProc **)NULL) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ *indexPtr = index;
+ return TCL_OK;
}
static Tcl_Obj *
GetValues(Vector *vPtr, int first, int last)
{
- Tcl_Obj *listObjPtr;
- double *vp, *vend;
-
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- for (vp = vPtr->valueArr + first, vend = vPtr->valueArr + last; vp <= vend;
- vp++) {
- Tcl_ListObjAppendElement(vPtr->interp, listObjPtr,
- Tcl_NewDoubleObj(*vp));
- }
- return listObjPtr;
+ Tcl_Obj *listObjPtr;
+ double *vp, *vend;
+
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ for (vp = vPtr->valueArr + first, vend = vPtr->valueArr + last; vp <= vend;
+ vp++) {
+ Tcl_ListObjAppendElement(vPtr->interp, listObjPtr,
+ Tcl_NewDoubleObj(*vp));
+ }
+ return listObjPtr;
}
static void
ReplicateValue(Vector *vPtr, int first, int last, double value)
{
- double *vp, *vend;
+ double *vp, *vend;
- for (vp = vPtr->valueArr + first, vend = vPtr->valueArr + last;
- vp <= vend; vp++) {
- *vp = value;
- }
- vPtr->notifyFlags |= UPDATE_RANGE;
+ for (vp = vPtr->valueArr + first, vend = vPtr->valueArr + last;
+ vp <= vend; vp++) {
+ *vp = value;
+ }
+ vPtr->notifyFlags |= UPDATE_RANGE;
}
static int
CopyList(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int i;
+ int i;
- if (Blt_Vec_SetLength(interp, vPtr, objc) != TCL_OK) {
- return TCL_ERROR;
- }
- for (i = 0; i < objc; i++) {
- double value;
+ if (Blt_Vec_SetLength(interp, vPtr, objc) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ for (i = 0; i < objc; i++) {
+ double value;
- if (Blt_ExprDoubleFromObj(interp, objv[i], &value) != TCL_OK) {
- Blt_Vec_SetLength(interp, vPtr, i);
- return TCL_ERROR;
- }
- vPtr->valueArr[i] = value;
+ if (Blt_ExprDoubleFromObj(interp, objv[i], &value) != TCL_OK) {
+ Blt_Vec_SetLength(interp, vPtr, i);
+ return TCL_ERROR;
}
- return TCL_OK;
+ vPtr->valueArr[i] = value;
+ }
+ return TCL_OK;
}
static int
AppendVector(Vector *destPtr, Vector *srcPtr)
{
- size_t nBytes;
- size_t oldSize, newSize;
+ size_t nBytes;
+ size_t oldSize, newSize;
- oldSize = destPtr->length;
- newSize = oldSize + srcPtr->last - srcPtr->first + 1;
- if (Blt_Vec_ChangeLength(destPtr->interp, destPtr, newSize) != TCL_OK) {
- return TCL_ERROR;
- }
- nBytes = (newSize - oldSize) * sizeof(double);
- memcpy((char *)(destPtr->valueArr + oldSize),
- (srcPtr->valueArr + srcPtr->first), nBytes);
- destPtr->notifyFlags |= UPDATE_RANGE;
- return TCL_OK;
+ oldSize = destPtr->length;
+ newSize = oldSize + srcPtr->last - srcPtr->first + 1;
+ if (Blt_Vec_ChangeLength(destPtr->interp, destPtr, newSize) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ nBytes = (newSize - oldSize) * sizeof(double);
+ memcpy((char *)(destPtr->valueArr + oldSize),
+ (srcPtr->valueArr + srcPtr->first), nBytes);
+ destPtr->notifyFlags |= UPDATE_RANGE;
+ return TCL_OK;
}
static int
AppendList(Vector *vPtr, int objc, Tcl_Obj* const objv[])
{
- Tcl_Interp* interp = vPtr->interp;
- int count;
- int i;
- double value;
- int oldSize;
-
- oldSize = vPtr->length;
- if (Blt_Vec_ChangeLength(interp, vPtr, vPtr->length + objc) != TCL_OK) {
- return TCL_ERROR;
- }
- count = oldSize;
- for (i = 0; i < objc; i++) {
- if (Blt_ExprDoubleFromObj(interp, objv[i], &value) != TCL_OK) {
- Blt_Vec_ChangeLength(interp, vPtr, count);
- return TCL_ERROR;
- }
- vPtr->valueArr[count++] = value;
+ Tcl_Interp* interp = vPtr->interp;
+ int count;
+ int i;
+ double value;
+ int oldSize;
+
+ oldSize = vPtr->length;
+ if (Blt_Vec_ChangeLength(interp, vPtr, vPtr->length + objc) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ count = oldSize;
+ for (i = 0; i < objc; i++) {
+ if (Blt_ExprDoubleFromObj(interp, objv[i], &value) != TCL_OK) {
+ Blt_Vec_ChangeLength(interp, vPtr, count);
+ return TCL_ERROR;
}
- vPtr->notifyFlags |= UPDATE_RANGE;
- return TCL_OK;
+ vPtr->valueArr[count++] = value;
+ }
+ vPtr->notifyFlags |= UPDATE_RANGE;
+ return TCL_OK;
}
/* Vector instance option commands */
@@ -350,36 +350,36 @@ AppendList(Vector *vPtr, int objc, Tcl_Obj* const objv[])
static int
AppendOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int i;
- int result;
- Vector *v2Ptr;
+ int i;
+ int result;
+ Vector *v2Ptr;
- for (i = 2; i < objc; i++) {
- v2Ptr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, vPtr->dataPtr,
- Tcl_GetString(objv[i]), (const char **)NULL, NS_SEARCH_BOTH);
- if (v2Ptr != NULL) {
- result = AppendVector(vPtr, v2Ptr);
- } else {
- int nElem;
- Tcl_Obj **elemObjArr;
-
- if (Tcl_ListObjGetElements(interp, objv[i], &nElem, &elemObjArr)
- != TCL_OK) {
- return TCL_ERROR;
- }
- result = AppendList(vPtr, nElem, elemObjArr);
- }
- if (result != TCL_OK) {
- return TCL_ERROR;
- }
- }
- if (objc > 2) {
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
+ for (i = 2; i < objc; i++) {
+ v2Ptr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, vPtr->dataPtr,
+ Tcl_GetString(objv[i]), (const char **)NULL, NS_SEARCH_BOTH);
+ if (v2Ptr != NULL) {
+ result = AppendVector(vPtr, v2Ptr);
+ } else {
+ int nElem;
+ Tcl_Obj **elemObjArr;
+
+ if (Tcl_ListObjGetElements(interp, objv[i], &nElem, &elemObjArr)
+ != TCL_OK) {
+ return TCL_ERROR;
+ }
+ result = AppendList(vPtr, nElem, elemObjArr);
}
- return TCL_OK;
+ if (result != TCL_OK) {
+ return TCL_ERROR;
+ }
+ }
+ if (objc > 2) {
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ return TCL_OK;
}
/*
@@ -403,8 +403,8 @@ AppendOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
ClearOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Blt_Vec_FlushCache(vPtr);
- return TCL_OK;
+ Blt_Vec_FlushCache(vPtr);
+ return TCL_OK;
}
/*
@@ -429,53 +429,53 @@ ClearOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
DeleteOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- unsigned char *unsetArr;
- int i, j;
- int count;
- char *string;
+ unsigned char *unsetArr;
+ int i, j;
+ int count;
+ char *string;
+
+ /* FIXME: Don't delete vector with no indices. */
+ if (objc == 2) {
+ Blt_Vec_Free(vPtr);
+ return TCL_OK;
+ }
- /* FIXME: Don't delete vector with no indices. */
- if (objc == 2) {
- Blt_Vec_Free(vPtr);
- return TCL_OK;
- }
-
- /* Allocate an "unset" bitmap the size of the vector. */
- unsetArr = calloc(sizeof(unsigned char), (vPtr->length + 7) / 8);
-#define SetBit(i) \
- unsetArr[(i) >> 3] |= (1 << ((i) & 0x07))
-#define GetBit(i) \
- (unsetArr[(i) >> 3] & (1 << ((i) & 0x07)))
-
- for (i = 2; i < objc; i++) {
- string = Tcl_GetString(objv[i]);
- if (Blt_Vec_GetIndexRange(interp, vPtr, string,
- (INDEX_COLON | INDEX_CHECK), (Blt_VectorIndexProc **) NULL)
- != TCL_OK) {
- free(unsetArr);
- return TCL_ERROR;
- }
- for (j = vPtr->first; j <= vPtr->last; j++) {
- SetBit(j); /* Mark the range of elements for deletion. */
- }
- }
- count = 0;
- for (i = 0; i < vPtr->length; i++) {
- if (GetBit(i)) {
- continue; /* Skip elements marked for deletion. */
- }
- if (count < i) {
- vPtr->valueArr[count] = vPtr->valueArr[i];
- }
- count++;
+ /* Allocate an "unset" bitmap the size of the vector. */
+ unsetArr = (unsigned char*)calloc(sizeof(unsigned char), (vPtr->length + 7) / 8);
+#define SetBit(i) \
+ unsetArr[(i) >> 3] |= (1 << ((i) & 0x07))
+#define GetBit(i) \
+ (unsetArr[(i) >> 3] & (1 << ((i) & 0x07)))
+
+ for (i = 2; i < objc; i++) {
+ string = Tcl_GetString(objv[i]);
+ if (Blt_Vec_GetIndexRange(interp, vPtr, string,
+ (INDEX_COLON | INDEX_CHECK), (Blt_VectorIndexProc **) NULL)
+ != TCL_OK) {
+ free(unsetArr);
+ return TCL_ERROR;
}
- free(unsetArr);
- vPtr->length = count;
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
+ for (j = vPtr->first; j <= vPtr->last; j++) {
+ SetBit(j); /* Mark the range of elements for deletion. */
}
- Blt_Vec_UpdateClients(vPtr);
- return TCL_OK;
+ }
+ count = 0;
+ for (i = 0; i < vPtr->length; i++) {
+ if (GetBit(i)) {
+ continue; /* Skip elements marked for deletion. */
+ }
+ if (count < i) {
+ vPtr->valueArr[count] = vPtr->valueArr[i];
+ }
+ count++;
+ }
+ free(unsetArr);
+ vPtr->length = count;
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ return TCL_OK;
}
/*
@@ -498,32 +498,32 @@ DeleteOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
DupOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int i;
+ int i;
+
+ for (i = 2; i < objc; i++) {
+ Vector *v2Ptr;
+ char *name;
+ int isNew;
- for (i = 2; i < objc; i++) {
- Vector *v2Ptr;
- char *name;
- int isNew;
-
- name = Tcl_GetString(objv[i]);
- v2Ptr = Blt_Vec_Create(vPtr->dataPtr, name, name, name, &isNew);
- if (v2Ptr == NULL) {
- return TCL_ERROR;
- }
- if (v2Ptr == vPtr) {
- continue;
- }
- if (Blt_Vec_Duplicate(v2Ptr, vPtr) != TCL_OK) {
- return TCL_ERROR;
- }
- if (!isNew) {
- if (v2Ptr->flush) {
- Blt_Vec_FlushCache(v2Ptr);
- }
- Blt_Vec_UpdateClients(v2Ptr);
- }
+ name = Tcl_GetString(objv[i]);
+ v2Ptr = Blt_Vec_Create(vPtr->dataPtr, name, name, name, &isNew);
+ if (v2Ptr == NULL) {
+ return TCL_ERROR;
}
- return TCL_OK;
+ if (v2Ptr == vPtr) {
+ continue;
+ }
+ if (Blt_Vec_Duplicate(v2Ptr, vPtr) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (!isNew) {
+ if (v2Ptr->flush) {
+ Blt_Vec_FlushCache(v2Ptr);
+ }
+ Blt_Vec_UpdateClients(v2Ptr);
+ }
+ }
+ return TCL_OK;
}
@@ -534,88 +534,88 @@ DupOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
FFTOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Vector *v2Ptr = NULL;
- int isNew;
- FFTData data;
- char *realVecName;
-
- memset(&data, 0, sizeof(data));
- data.delta = 1.0;
-
- realVecName = Tcl_GetString(objv[2]);
- v2Ptr = Blt_Vec_Create(vPtr->dataPtr, realVecName, realVecName,
- realVecName, &isNew);
- if (v2Ptr == NULL) {
- return TCL_ERROR;
- }
- if (v2Ptr == vPtr) {
- Tcl_AppendResult(interp, "real vector \"", realVecName, "\"",
- " can't be the same as the source", (char *)NULL);
- return TCL_ERROR;
- }
- if (Blt_ParseSwitches(interp, fftSwitches, objc - 3, objv + 3, &data,
- BLT_SWITCH_DEFAULTS) < 0) {
- return TCL_ERROR;
+ Vector *v2Ptr = NULL;
+ int isNew;
+ FFTData data;
+ char *realVecName;
+
+ memset(&data, 0, sizeof(data));
+ data.delta = 1.0;
+
+ realVecName = Tcl_GetString(objv[2]);
+ v2Ptr = Blt_Vec_Create(vPtr->dataPtr, realVecName, realVecName,
+ realVecName, &isNew);
+ if (v2Ptr == NULL) {
+ return TCL_ERROR;
+ }
+ if (v2Ptr == vPtr) {
+ Tcl_AppendResult(interp, "real vector \"", realVecName, "\"",
+ " can't be the same as the source", (char *)NULL);
+ return TCL_ERROR;
+ }
+ if (Blt_ParseSwitches(interp, fftSwitches, objc - 3, objv + 3, &data,
+ BLT_SWITCH_DEFAULTS) < 0) {
+ return TCL_ERROR;
+ }
+ if (Blt_Vec_FFT(interp, v2Ptr, data.imagPtr, data.freqPtr, data.delta,
+ data.mask, vPtr) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ /* Update bookkeeping. */
+ if (!isNew) {
+ if (v2Ptr->flush) {
+ Blt_Vec_FlushCache(v2Ptr);
}
- if (Blt_Vec_FFT(interp, v2Ptr, data.imagPtr, data.freqPtr, data.delta,
- data.mask, vPtr) != TCL_OK) {
- return TCL_ERROR;
+ Blt_Vec_UpdateClients(v2Ptr);
+ }
+ if (data.imagPtr != NULL) {
+ if (data.imagPtr->flush) {
+ Blt_Vec_FlushCache(data.imagPtr);
}
- /* Update bookkeeping. */
- if (!isNew) {
- if (v2Ptr->flush) {
- Blt_Vec_FlushCache(v2Ptr);
- }
- Blt_Vec_UpdateClients(v2Ptr);
- }
- if (data.imagPtr != NULL) {
- if (data.imagPtr->flush) {
- Blt_Vec_FlushCache(data.imagPtr);
- }
- Blt_Vec_UpdateClients(data.imagPtr);
- }
- if (data.freqPtr != NULL) {
- if (data.freqPtr->flush) {
- Blt_Vec_FlushCache(data.freqPtr);
- }
- Blt_Vec_UpdateClients(data.freqPtr);
+ Blt_Vec_UpdateClients(data.imagPtr);
+ }
+ if (data.freqPtr != NULL) {
+ if (data.freqPtr->flush) {
+ Blt_Vec_FlushCache(data.freqPtr);
}
- return TCL_OK;
+ Blt_Vec_UpdateClients(data.freqPtr);
+ }
+ return TCL_OK;
}
/*ARGSUSED*/
static int
InverseFFTOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int isNew;
- char *name;
- Vector *srcImagPtr;
- Vector *destRealPtr;
- Vector *destImagPtr;
-
- name = Tcl_GetString(objv[2]);
- if (Blt_Vec_LookupName(vPtr->dataPtr, name, &srcImagPtr) != TCL_OK ) {
- return TCL_ERROR;
- }
- name = Tcl_GetString(objv[3]);
- destRealPtr = Blt_Vec_Create(vPtr->dataPtr, name, name, name, &isNew);
- name = Tcl_GetString(objv[4]);
- destImagPtr = Blt_Vec_Create(vPtr->dataPtr, name, name, name, &isNew);
-
- if (Blt_Vec_InverseFFT(interp, srcImagPtr, destRealPtr, destImagPtr, vPtr)
- != TCL_OK ){
- return TCL_ERROR;
- }
- if (destRealPtr->flush) {
- Blt_Vec_FlushCache(destRealPtr);
- }
- Blt_Vec_UpdateClients(destRealPtr);
+ int isNew;
+ char *name;
+ Vector *srcImagPtr;
+ Vector *destRealPtr;
+ Vector *destImagPtr;
+
+ name = Tcl_GetString(objv[2]);
+ if (Blt_Vec_LookupName(vPtr->dataPtr, name, &srcImagPtr) != TCL_OK ) {
+ return TCL_ERROR;
+ }
+ name = Tcl_GetString(objv[3]);
+ destRealPtr = Blt_Vec_Create(vPtr->dataPtr, name, name, name, &isNew);
+ name = Tcl_GetString(objv[4]);
+ destImagPtr = Blt_Vec_Create(vPtr->dataPtr, name, name, name, &isNew);
+
+ if (Blt_Vec_InverseFFT(interp, srcImagPtr, destRealPtr, destImagPtr, vPtr)
+ != TCL_OK ){
+ return TCL_ERROR;
+ }
+ if (destRealPtr->flush) {
+ Blt_Vec_FlushCache(destRealPtr);
+ }
+ Blt_Vec_UpdateClients(destRealPtr);
- if (destImagPtr->flush) {
- Blt_Vec_FlushCache(destImagPtr);
- }
- Blt_Vec_UpdateClients(destImagPtr);
- return TCL_OK;
+ if (destImagPtr->flush) {
+ Blt_Vec_FlushCache(destImagPtr);
+ }
+ Blt_Vec_UpdateClients(destImagPtr);
+ return TCL_OK;
}
@@ -637,51 +637,51 @@ InverseFFTOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
IndexOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int first, last;
- char *string;
+ int first, last;
+ char *string;
- string = Tcl_GetString(objv[2]);
- if (Blt_Vec_GetIndexRange(interp, vPtr, string, INDEX_ALL_FLAGS,
- (Blt_VectorIndexProc **) NULL) != TCL_OK) {
+ string = Tcl_GetString(objv[2]);
+ if (Blt_Vec_GetIndexRange(interp, vPtr, string, INDEX_ALL_FLAGS,
+ (Blt_VectorIndexProc **) NULL) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ first = vPtr->first, last = vPtr->last;
+ if (objc == 3) {
+ Tcl_Obj *listObjPtr;
+
+ if (first == vPtr->length) {
+ Tcl_AppendResult(interp, "can't get index \"", string, "\"",
+ (char *)NULL);
+ return TCL_ERROR; /* Can't read from index "++end" */
+ }
+ listObjPtr = GetValues(vPtr, first, last);
+ Tcl_SetObjResult(interp, listObjPtr);
+ } else {
+ double value;
+
+ /* FIXME: huh? Why set values here?. */
+ if (first == SPECIAL_INDEX) {
+ Tcl_AppendResult(interp, "can't set index \"", string, "\"",
+ (char *)NULL);
+ return TCL_ERROR; /* Tried to set "min" or "max" */
+ }
+ if (Blt_ExprDoubleFromObj(interp, objv[3], &value) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (first == vPtr->length) {
+ if (Blt_Vec_ChangeLength(interp, vPtr, vPtr->length + 1)
+ != TCL_OK) {
return TCL_ERROR;
+ }
}
- first = vPtr->first, last = vPtr->last;
- if (objc == 3) {
- Tcl_Obj *listObjPtr;
-
- if (first == vPtr->length) {
- Tcl_AppendResult(interp, "can't get index \"", string, "\"",
- (char *)NULL);
- return TCL_ERROR; /* Can't read from index "++end" */
- }
- listObjPtr = GetValues(vPtr, first, last);
- Tcl_SetObjResult(interp, listObjPtr);
- } else {
- double value;
-
- /* FIXME: huh? Why set values here?. */
- if (first == SPECIAL_INDEX) {
- Tcl_AppendResult(interp, "can't set index \"", string, "\"",
- (char *)NULL);
- return TCL_ERROR; /* Tried to set "min" or "max" */
- }
- if (Blt_ExprDoubleFromObj(interp, objv[3], &value) != TCL_OK) {
- return TCL_ERROR;
- }
- if (first == vPtr->length) {
- if (Blt_Vec_ChangeLength(interp, vPtr, vPtr->length + 1)
- != TCL_OK) {
- return TCL_ERROR;
- }
- }
- ReplicateValue(vPtr, first, last, value);
- Tcl_SetObjResult(interp, objv[3]);
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
+ ReplicateValue(vPtr, first, last, value);
+ Tcl_SetObjResult(interp, objv[3]);
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
}
- return TCL_OK;
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ return TCL_OK;
}
/*
@@ -702,28 +702,28 @@ IndexOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
LengthOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- if (objc == 3) {
- int nElem;
-
- if (Tcl_GetIntFromObj(interp, objv[2], &nElem) != TCL_OK) {
- return TCL_ERROR;
- }
- if (nElem < 0) {
- Tcl_AppendResult(interp, "bad vector size \"",
- Tcl_GetString(objv[2]), "\"", (char *)NULL);
- return TCL_ERROR;
- }
- if ((Blt_Vec_SetSize(interp, vPtr, nElem) != TCL_OK) ||
- (Blt_Vec_SetLength(interp, vPtr, nElem) != TCL_OK)) {
- return TCL_ERROR;
- }
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
- }
- Tcl_SetIntObj(Tcl_GetObjResult(interp), vPtr->length);
- return TCL_OK;
+ if (objc == 3) {
+ int nElem;
+
+ if (Tcl_GetIntFromObj(interp, objv[2], &nElem) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (nElem < 0) {
+ Tcl_AppendResult(interp, "bad vector size \"",
+ Tcl_GetString(objv[2]), "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ if ((Blt_Vec_SetSize(interp, vPtr, nElem) != TCL_OK) ||
+ (Blt_Vec_SetLength(interp, vPtr, nElem) != TCL_OK)) {
+ return TCL_ERROR;
+ }
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ Tcl_SetIntObj(Tcl_GetObjResult(interp), vPtr->length);
+ return TCL_OK;
}
/*
@@ -745,16 +745,16 @@ LengthOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
MapOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- if (objc > 2) {
- if (Blt_Vec_MapVariable(interp, vPtr, Tcl_GetString(objv[2]))
- != TCL_OK) {
- return TCL_ERROR;
- }
- }
- if (vPtr->arrayName != NULL) {
- Tcl_SetStringObj(Tcl_GetObjResult(interp), vPtr->arrayName, -1);
+ if (objc > 2) {
+ if (Blt_Vec_MapVariable(interp, vPtr, Tcl_GetString(objv[2]))
+ != TCL_OK) {
+ return TCL_ERROR;
}
- return TCL_OK;
+ }
+ if (vPtr->arrayName != NULL) {
+ Tcl_SetStringObj(Tcl_GetObjResult(interp), vPtr->arrayName, -1);
+ }
+ return TCL_OK;
}
/*
@@ -773,8 +773,8 @@ MapOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
MaxOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Tcl_SetDoubleObj(Tcl_GetObjResult(interp), Blt_Vec_Max(vPtr));
- return TCL_OK;
+ Tcl_SetDoubleObj(Tcl_GetObjResult(interp), Blt_Vec_Max(vPtr));
+ return TCL_OK;
}
/*
@@ -795,63 +795,63 @@ MaxOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
MergeOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Vector **vecArr;
- int refSize, nElem;
- int i;
- double *valuePtr, *valueArr;
- Vector **vPtrPtr;
+ Vector **vecArr;
+ int refSize, nElem;
+ int i;
+ double *valuePtr, *valueArr;
+ Vector **vPtrPtr;
- /* Allocate an array of vector pointers of each vector to be
- * merged in the current vector. */
- vecArr = malloc(sizeof(Vector *) * objc);
- vPtrPtr = vecArr;
-
- refSize = -1;
- nElem = 0;
- for (i = 2; i < objc; i++) {
- Vector *v2Ptr;
- int length;
-
- if (Blt_Vec_LookupName(vPtr->dataPtr, Tcl_GetString(objv[i]), &v2Ptr)
- != TCL_OK) {
- free(vecArr);
- return TCL_ERROR;
- }
- /* Check that all the vectors are the same length */
- length = v2Ptr->last - v2Ptr->first + 1;
- if (refSize < 0) {
- refSize = length;
- } else if (length != refSize) {
- Tcl_AppendResult(vPtr->interp, "vectors \"", vPtr->name,
- "\" and \"", v2Ptr->name, "\" differ in length",
- (char *)NULL);
- free(vecArr);
- return TCL_ERROR;
- }
- *vPtrPtr++ = v2Ptr;
- nElem += refSize;
- }
- *vPtrPtr = NULL;
-
- valueArr = malloc(sizeof(double) * nElem);
- if (valueArr == NULL) {
- Tcl_AppendResult(vPtr->interp, "not enough memory to allocate ",
- Blt_Itoa(nElem), " vector elements", (char *)NULL);
- return TCL_ERROR;
- }
+ /* Allocate an array of vector pointers of each vector to be
+ * merged in the current vector. */
+ vecArr = (Vector**)malloc(sizeof(Vector *) * objc);
+ vPtrPtr = vecArr;
+
+ refSize = -1;
+ nElem = 0;
+ for (i = 2; i < objc; i++) {
+ Vector *v2Ptr;
+ int length;
- /* Merge the values from each of the vectors into the current vector */
- valuePtr = valueArr;
- for (i = 0; i < refSize; i++) {
- Vector **vpp;
+ if (Blt_Vec_LookupName(vPtr->dataPtr, Tcl_GetString(objv[i]), &v2Ptr)
+ != TCL_OK) {
+ free(vecArr);
+ return TCL_ERROR;
+ }
+ /* Check that all the vectors are the same length */
+ length = v2Ptr->last - v2Ptr->first + 1;
+ if (refSize < 0) {
+ refSize = length;
+ } else if (length != refSize) {
+ Tcl_AppendResult(vPtr->interp, "vectors \"", vPtr->name,
+ "\" and \"", v2Ptr->name, "\" differ in length",
+ (char *)NULL);
+ free(vecArr);
+ return TCL_ERROR;
+ }
+ *vPtrPtr++ = v2Ptr;
+ nElem += refSize;
+ }
+ *vPtrPtr = NULL;
+
+ valueArr = (double*)malloc(sizeof(double) * nElem);
+ if (valueArr == NULL) {
+ Tcl_AppendResult(vPtr->interp, "not enough memory to allocate ",
+ Blt_Itoa(nElem), " vector elements", (char *)NULL);
+ return TCL_ERROR;
+ }
- for (vpp = vecArr; *vpp != NULL; vpp++) {
- *valuePtr++ = (*vpp)->valueArr[i + (*vpp)->first];
- }
+ /* Merge the values from each of the vectors into the current vector */
+ valuePtr = valueArr;
+ for (i = 0; i < refSize; i++) {
+ Vector **vpp;
+
+ for (vpp = vecArr; *vpp != NULL; vpp++) {
+ *valuePtr++ = (*vpp)->valueArr[i + (*vpp)->first];
}
- free(vecArr);
- Blt_Vec_Reset(vPtr, valueArr, nElem, nElem, TCL_DYNAMIC);
- return TCL_OK;
+ }
+ free(vecArr);
+ Blt_Vec_Reset(vPtr, valueArr, nElem, nElem, TCL_DYNAMIC);
+ return TCL_OK;
}
/*
@@ -870,8 +870,8 @@ MergeOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
MinOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Tcl_SetDoubleObj(Tcl_GetObjResult(interp), Blt_Vec_Min(vPtr));
- return TCL_OK;
+ Tcl_SetDoubleObj(Tcl_GetObjResult(interp), Blt_Vec_Min(vPtr));
+ return TCL_OK;
}
/*
@@ -891,48 +891,48 @@ MinOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
NormalizeOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int i;
- double range;
-
- Blt_Vec_UpdateRange(vPtr);
- range = vPtr->max - vPtr->min;
- if (objc > 2) {
- Vector *v2Ptr;
- int isNew;
- char *string;
-
- string = Tcl_GetString(objv[2]);
- v2Ptr = Blt_Vec_Create(vPtr->dataPtr, string, string, string, &isNew);
- if (v2Ptr == NULL) {
- return TCL_ERROR;
- }
- if (Blt_Vec_SetLength(interp, v2Ptr, vPtr->length) != TCL_OK) {
- return TCL_ERROR;
- }
- for (i = 0; i < vPtr->length; i++) {
- v2Ptr->valueArr[i] = (vPtr->valueArr[i] - vPtr->min) / range;
- }
- Blt_Vec_UpdateRange(v2Ptr);
- if (!isNew) {
- if (v2Ptr->flush) {
- Blt_Vec_FlushCache(v2Ptr);
- }
- Blt_Vec_UpdateClients(v2Ptr);
- }
- } else {
- Tcl_Obj *listObjPtr;
+ int i;
+ double range;
+
+ Blt_Vec_UpdateRange(vPtr);
+ range = vPtr->max - vPtr->min;
+ if (objc > 2) {
+ Vector *v2Ptr;
+ int isNew;
+ char *string;
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- for (i = 0; i < vPtr->length; i++) {
- double norm;
+ string = Tcl_GetString(objv[2]);
+ v2Ptr = Blt_Vec_Create(vPtr->dataPtr, string, string, string, &isNew);
+ if (v2Ptr == NULL) {
+ return TCL_ERROR;
+ }
+ if (Blt_Vec_SetLength(interp, v2Ptr, vPtr->length) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ for (i = 0; i < vPtr->length; i++) {
+ v2Ptr->valueArr[i] = (vPtr->valueArr[i] - vPtr->min) / range;
+ }
+ Blt_Vec_UpdateRange(v2Ptr);
+ if (!isNew) {
+ if (v2Ptr->flush) {
+ Blt_Vec_FlushCache(v2Ptr);
+ }
+ Blt_Vec_UpdateClients(v2Ptr);
+ }
+ } else {
+ Tcl_Obj *listObjPtr;
- norm = (vPtr->valueArr[i] - vPtr->min) / range;
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(norm));
- }
- Tcl_SetObjResult(interp, listObjPtr);
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ for (i = 0; i < vPtr->length; i++) {
+ double norm;
+
+ norm = (vPtr->valueArr[i] - vPtr->min) / range;
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(norm));
}
- return TCL_OK;
+ Tcl_SetObjResult(interp, listObjPtr);
+ }
+ return TCL_OK;
}
/*
@@ -959,49 +959,49 @@ NormalizeOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
NotifyOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int option;
- int bool;
- enum optionIndices {
- OPTION_ALWAYS, OPTION_NEVER, OPTION_WHENIDLE,
- OPTION_NOW, OPTION_CANCEL, OPTION_PENDING
- };
- static const char *optionArr[] = {
- "always", "never", "whenidle", "now", "cancel", "pending", NULL
- };
-
- if (Tcl_GetIndexFromObj(interp, objv[2], optionArr, "qualifier", TCL_EXACT,
- &option) != TCL_OK) {
- return TCL_OK;
- }
- switch (option) {
- case OPTION_ALWAYS:
- vPtr->notifyFlags &= ~NOTIFY_WHEN_MASK;
- vPtr->notifyFlags |= NOTIFY_ALWAYS;
- break;
- case OPTION_NEVER:
- vPtr->notifyFlags &= ~NOTIFY_WHEN_MASK;
- vPtr->notifyFlags |= NOTIFY_NEVER;
- break;
- case OPTION_WHENIDLE:
- vPtr->notifyFlags &= ~NOTIFY_WHEN_MASK;
- vPtr->notifyFlags |= NOTIFY_WHENIDLE;
- break;
- case OPTION_NOW:
- /* FIXME: How does this play when an update is pending? */
- Blt_Vec_NotifyClients(vPtr);
- break;
- case OPTION_CANCEL:
- if (vPtr->notifyFlags & NOTIFY_PENDING) {
- vPtr->notifyFlags &= ~NOTIFY_PENDING;
- Tcl_CancelIdleCall(Blt_Vec_NotifyClients, (ClientData)vPtr);
- }
- break;
- case OPTION_PENDING:
- bool = (vPtr->notifyFlags & NOTIFY_PENDING);
- Tcl_SetBooleanObj(Tcl_GetObjResult(interp), bool);
- break;
- }
+ int option;
+ int boll;
+ enum optionIndices {
+ OPTION_ALWAYS, OPTION_NEVER, OPTION_WHENIDLE,
+ OPTION_NOW, OPTION_CANCEL, OPTION_PENDING
+ };
+ static const char *optionArr[] = {
+ "always", "never", "whenidle", "now", "cancel", "pending", NULL
+ };
+
+ if (Tcl_GetIndexFromObj(interp, objv[2], optionArr, "qualifier", TCL_EXACT,
+ &option) != TCL_OK) {
return TCL_OK;
+ }
+ switch (option) {
+ case OPTION_ALWAYS:
+ vPtr->notifyFlags &= ~NOTIFY_WHEN_MASK;
+ vPtr->notifyFlags |= NOTIFY_ALWAYS;
+ break;
+ case OPTION_NEVER:
+ vPtr->notifyFlags &= ~NOTIFY_WHEN_MASK;
+ vPtr->notifyFlags |= NOTIFY_NEVER;
+ break;
+ case OPTION_WHENIDLE:
+ vPtr->notifyFlags &= ~NOTIFY_WHEN_MASK;
+ vPtr->notifyFlags |= NOTIFY_WHENIDLE;
+ break;
+ case OPTION_NOW:
+ /* FIXME: How does this play when an update is pending? */
+ Blt_Vec_NotifyClients(vPtr);
+ break;
+ case OPTION_CANCEL:
+ if (vPtr->notifyFlags & NOTIFY_PENDING) {
+ vPtr->notifyFlags &= ~NOTIFY_PENDING;
+ Tcl_CancelIdleCall(Blt_Vec_NotifyClients, (ClientData)vPtr);
+ }
+ break;
+ case OPTION_PENDING:
+ boll = (vPtr->notifyFlags & NOTIFY_PENDING);
+ Tcl_SetBooleanObj(Tcl_GetObjResult(interp), boll);
+ break;
+ }
+ return TCL_OK;
}
/*
@@ -1021,56 +1021,56 @@ NotifyOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
PopulateOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Vector *v2Ptr;
- int size, density;
- int isNew;
- int i, j;
- double *valuePtr;
- int count;
- char *string;
-
- string = Tcl_GetString(objv[2]);
- v2Ptr = Blt_Vec_Create(vPtr->dataPtr, string, string, string, &isNew);
- if (v2Ptr == NULL) {
- return TCL_ERROR;
- }
- if (vPtr->length == 0) {
- return TCL_OK; /* Source vector is empty. */
- }
- if (Tcl_GetIntFromObj(interp, objv[3], &density) != TCL_OK) {
- return TCL_ERROR;
- }
- if (density < 1) {
- Tcl_AppendResult(interp, "bad density \"", Tcl_GetString(objv[3]),
- "\"", (char *)NULL);
- return TCL_ERROR;
- }
- size = (vPtr->length - 1) * (density + 1) + 1;
- if (Blt_Vec_SetLength(interp, v2Ptr, size) != TCL_OK) {
- return TCL_ERROR;
- }
- count = 0;
- valuePtr = v2Ptr->valueArr;
- for (i = 0; i < (vPtr->length - 1); i++) {
- double slice, range;
-
- range = vPtr->valueArr[i + 1] - vPtr->valueArr[i];
- slice = range / (double)(density + 1);
- for (j = 0; j <= density; j++) {
- *valuePtr = vPtr->valueArr[i] + (slice * (double)j);
- valuePtr++;
- count++;
- }
+ Vector *v2Ptr;
+ int size, density;
+ int isNew;
+ int i, j;
+ double *valuePtr;
+ int count;
+ char *string;
+
+ string = Tcl_GetString(objv[2]);
+ v2Ptr = Blt_Vec_Create(vPtr->dataPtr, string, string, string, &isNew);
+ if (v2Ptr == NULL) {
+ return TCL_ERROR;
+ }
+ if (vPtr->length == 0) {
+ return TCL_OK; /* Source vector is empty. */
+ }
+ if (Tcl_GetIntFromObj(interp, objv[3], &density) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (density < 1) {
+ Tcl_AppendResult(interp, "bad density \"", Tcl_GetString(objv[3]),
+ "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ size = (vPtr->length - 1) * (density + 1) + 1;
+ if (Blt_Vec_SetLength(interp, v2Ptr, size) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ count = 0;
+ valuePtr = v2Ptr->valueArr;
+ for (i = 0; i < (vPtr->length - 1); i++) {
+ double slice, range;
+
+ range = vPtr->valueArr[i + 1] - vPtr->valueArr[i];
+ slice = range / (double)(density + 1);
+ for (j = 0; j <= density; j++) {
+ *valuePtr = vPtr->valueArr[i] + (slice * (double)j);
+ valuePtr++;
+ count++;
}
- count++;
- *valuePtr = vPtr->valueArr[i];
- if (!isNew) {
- if (v2Ptr->flush) {
- Blt_Vec_FlushCache(v2Ptr);
- }
- Blt_Vec_UpdateClients(v2Ptr);
+ }
+ count++;
+ *valuePtr = vPtr->valueArr[i];
+ if (!isNew) {
+ if (v2Ptr->flush) {
+ Blt_Vec_FlushCache(v2Ptr);
}
- return TCL_OK;
+ Blt_Vec_UpdateClients(v2Ptr);
+ }
+ return TCL_OK;
}
/*
@@ -1089,49 +1089,49 @@ PopulateOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
ValuesOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- PrintSwitches switches;
-
- switches.formatObjPtr = NULL;
- switches.from = 0;
- switches.to = vPtr->length - 1;
- indexSwitch.clientData = vPtr;
- if (Blt_ParseSwitches(interp, printSwitches, objc - 2, objv + 2, &switches,
- BLT_SWITCH_DEFAULTS) < 0) {
- return TCL_ERROR;
+ PrintSwitches switches;
+
+ switches.formatObjPtr = NULL;
+ switches.from = 0;
+ switches.to = vPtr->length - 1;
+ indexSwitch.clientData = vPtr;
+ if (Blt_ParseSwitches(interp, printSwitches, objc - 2, objv + 2, &switches,
+ BLT_SWITCH_DEFAULTS) < 0) {
+ return TCL_ERROR;
+ }
+ if (switches.from > switches.to) {
+ int tmp;
+ /* swap positions. */
+ tmp = switches.to;
+ switches.to = switches.from;
+ switches.from = tmp;
+ }
+ if (switches.formatObjPtr == NULL) {
+ Tcl_Obj *listObjPtr;
+ int i;
+
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ for (i = switches.from; i <= switches.to; i++) {
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(vPtr->valueArr[i]));
}
- if (switches.from > switches.to) {
- int tmp;
- /* swap positions. */
- tmp = switches.to;
- switches.to = switches.from;
- switches.from = tmp;
- }
- if (switches.formatObjPtr == NULL) {
- Tcl_Obj *listObjPtr;
- int i;
-
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- for (i = switches.from; i <= switches.to; i++) {
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(vPtr->valueArr[i]));
- }
- Tcl_SetObjResult(interp, listObjPtr);
- } else {
- Tcl_DString ds;
- char buffer[200];
- const char *fmt;
- int i;
-
- Tcl_DStringInit(&ds);
- fmt = Tcl_GetString(switches.formatObjPtr);
- for (i = switches.from; i <= switches.to; i++) {
- sprintf(buffer, fmt, vPtr->valueArr[i]);
- Tcl_DStringAppend(&ds, buffer, -1);
- }
- Tcl_DStringResult(interp, &ds);
- Tcl_DStringFree(&ds);
+ Tcl_SetObjResult(interp, listObjPtr);
+ } else {
+ Tcl_DString ds;
+ char buffer[200];
+ const char *fmt;
+ int i;
+
+ Tcl_DStringInit(&ds);
+ fmt = Tcl_GetString(switches.formatObjPtr);
+ for (i = switches.from; i <= switches.to; i++) {
+ sprintf(buffer, fmt, vPtr->valueArr[i]);
+ Tcl_DStringAppend(&ds, buffer, -1);
}
- return TCL_OK;
+ Tcl_DStringResult(interp, &ds);
+ Tcl_DStringFree(&ds);
+ }
+ return TCL_OK;
}
/*
@@ -1152,40 +1152,40 @@ ValuesOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
RangeOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Tcl_Obj *listObjPtr;
- int first, last;
- int i;
-
- if (objc == 2) {
- first = 0;
- last = vPtr->length - 1;
- } else if (objc == 4) {
- if ((Blt_Vec_GetIndex(interp, vPtr, Tcl_GetString(objv[2]), &first,
- INDEX_CHECK, (Blt_VectorIndexProc **) NULL) != TCL_OK) ||
- (Blt_Vec_GetIndex(interp, vPtr, Tcl_GetString(objv[3]), &last,
- INDEX_CHECK, (Blt_VectorIndexProc **) NULL) != TCL_OK)) {
- return TCL_ERROR;
- }
- } else {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- Tcl_GetString(objv[0]), " range ?first last?", (char *)NULL);
- return TCL_ERROR;
- }
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- if (first > last) {
- /* Return the list reversed */
- for (i = last; i <= first; i++) {
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(vPtr->valueArr[i]));
- }
- } else {
- for (i = first; i <= last; i++) {
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(vPtr->valueArr[i]));
- }
+ Tcl_Obj *listObjPtr;
+ int first, last;
+ int i;
+
+ if (objc == 2) {
+ first = 0;
+ last = vPtr->length - 1;
+ } else if (objc == 4) {
+ if ((Blt_Vec_GetIndex(interp, vPtr, Tcl_GetString(objv[2]), &first,
+ INDEX_CHECK, (Blt_VectorIndexProc **) NULL) != TCL_OK) ||
+ (Blt_Vec_GetIndex(interp, vPtr, Tcl_GetString(objv[3]), &last,
+ INDEX_CHECK, (Blt_VectorIndexProc **) NULL) != TCL_OK)) {
+ return TCL_ERROR;
+ }
+ } else {
+ Tcl_AppendResult(interp, "wrong # args: should be \"",
+ Tcl_GetString(objv[0]), " range ?first last?", (char *)NULL);
+ return TCL_ERROR;
+ }
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ if (first > last) {
+ /* Return the list reversed */
+ for (i = last; i <= first; i++) {
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(vPtr->valueArr[i]));
+ }
+ } else {
+ for (i = first; i <= last; i++) {
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(vPtr->valueArr[i]));
}
- Tcl_SetObjResult(interp, listObjPtr);
- return TCL_OK;
+ }
+ Tcl_SetObjResult(interp, listObjPtr);
+ return TCL_OK;
}
/*
@@ -1211,26 +1211,26 @@ RangeOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
INLINE static int
InRange(double value, double min, double max)
{
- double range;
+ double range;
- range = max - min;
- if (range < DBL_EPSILON) {
- return (fabs(max - value) < DBL_EPSILON);
- } else {
- double norm;
+ range = max - min;
+ if (range < DBL_EPSILON) {
+ return (fabs(max - value) < DBL_EPSILON);
+ } else {
+ double norm;
- norm = (value - min) / range;
- return ((norm >= -DBL_EPSILON) && ((norm - 1.0) < DBL_EPSILON));
- }
+ norm = (value - min) / range;
+ return ((norm >= -DBL_EPSILON) && ((norm - 1.0) < DBL_EPSILON));
+ }
}
enum NativeFormats {
- FMT_UNKNOWN = -1,
- FMT_UCHAR, FMT_CHAR,
- FMT_USHORT, FMT_SHORT,
- FMT_UINT, FMT_INT,
- FMT_ULONG, FMT_LONG,
- FMT_FLOAT, FMT_DOUBLE
+ FMT_UNKNOWN = -1,
+ FMT_UCHAR, FMT_CHAR,
+ FMT_USHORT, FMT_SHORT,
+ FMT_UINT, FMT_INT,
+ FMT_ULONG, FMT_LONG,
+ FMT_FLOAT, FMT_DOUBLE
};
/*
@@ -1253,137 +1253,137 @@ enum NativeFormats {
static enum NativeFormats
GetBinaryFormat(Tcl_Interp* interp, char *string, int *sizePtr)
{
- char c;
-
- c = tolower(string[0]);
- if (Tcl_GetInt(interp, string + 1, sizePtr) != TCL_OK) {
- Tcl_AppendResult(interp, "unknown binary format \"", string,
- "\": incorrect byte size", (char *)NULL);
- return FMT_UNKNOWN;
- }
- switch (c) {
- case 'r':
- if (*sizePtr == sizeof(double)) {
- return FMT_DOUBLE;
- } else if (*sizePtr == sizeof(float)) {
- return FMT_FLOAT;
- }
- break;
-
- case 'i':
- if (*sizePtr == sizeof(char)) {
- return FMT_CHAR;
- } else if (*sizePtr == sizeof(int)) {
- return FMT_INT;
- } else if (*sizePtr == sizeof(long)) {
- return FMT_LONG;
- } else if (*sizePtr == sizeof(short)) {
- return FMT_SHORT;
- }
- break;
-
- case 'u':
- if (*sizePtr == sizeof(unsigned char)) {
- return FMT_UCHAR;
- } else if (*sizePtr == sizeof(unsigned int)) {
- return FMT_UINT;
- } else if (*sizePtr == sizeof(unsigned long)) {
- return FMT_ULONG;
- } else if (*sizePtr == sizeof(unsigned short)) {
- return FMT_USHORT;
- }
- break;
-
- default:
- Tcl_AppendResult(interp, "unknown binary format \"", string,
- "\": should be either i#, r#, u# (where # is size in bytes)",
- (char *)NULL);
- return FMT_UNKNOWN;
- }
- Tcl_AppendResult(interp, "can't handle format \"", string, "\"",
+ char c;
+
+ c = tolower(string[0]);
+ if (Tcl_GetInt(interp, string + 1, sizePtr) != TCL_OK) {
+ Tcl_AppendResult(interp, "unknown binary format \"", string,
+ "\": incorrect byte size", (char *)NULL);
+ return FMT_UNKNOWN;
+ }
+ switch (c) {
+ case 'r':
+ if (*sizePtr == sizeof(double)) {
+ return FMT_DOUBLE;
+ } else if (*sizePtr == sizeof(float)) {
+ return FMT_FLOAT;
+ }
+ break;
+
+ case 'i':
+ if (*sizePtr == sizeof(char)) {
+ return FMT_CHAR;
+ } else if (*sizePtr == sizeof(int)) {
+ return FMT_INT;
+ } else if (*sizePtr == sizeof(long)) {
+ return FMT_LONG;
+ } else if (*sizePtr == sizeof(short)) {
+ return FMT_SHORT;
+ }
+ break;
+
+ case 'u':
+ if (*sizePtr == sizeof(unsigned char)) {
+ return FMT_UCHAR;
+ } else if (*sizePtr == sizeof(unsigned int)) {
+ return FMT_UINT;
+ } else if (*sizePtr == sizeof(unsigned long)) {
+ return FMT_ULONG;
+ } else if (*sizePtr == sizeof(unsigned short)) {
+ return FMT_USHORT;
+ }
+ break;
+
+ default:
+ Tcl_AppendResult(interp, "unknown binary format \"", string,
+ "\": should be either i#, r#, u# (where # is size in bytes)",
(char *)NULL);
return FMT_UNKNOWN;
+ }
+ Tcl_AppendResult(interp, "can't handle format \"", string, "\"",
+ (char *)NULL);
+ return FMT_UNKNOWN;
}
static int
CopyValues(Vector *vPtr, char *byteArr, enum NativeFormats fmt, int size,
- int length, int swap, int *indexPtr)
+ int length, int swap, int *indexPtr)
{
- int i, n;
- int newSize;
+ int i, n;
+ int newSize;
- if ((swap) && (size > 1)) {
- int nBytes = size * length;
- unsigned char *p;
- int left, right;
+ if ((swap) && (size > 1)) {
+ int nBytes = size * length;
+ unsigned char *p;
+ int left, right;
- for (i = 0; i < nBytes; i += size) {
- p = (unsigned char *)(byteArr + i);
- for (left = 0, right = size - 1; left < right; left++, right--) {
- p[left] ^= p[right];
- p[right] ^= p[left];
- p[left] ^= p[right];
- }
+ for (i = 0; i < nBytes; i += size) {
+ p = (unsigned char *)(byteArr + i);
+ for (left = 0, right = size - 1; left < right; left++, right--) {
+ p[left] ^= p[right];
+ p[right] ^= p[left];
+ p[left] ^= p[right];
+ }
- }
- }
- newSize = *indexPtr + length;
- if (newSize > vPtr->length) {
- if (Blt_Vec_ChangeLength(vPtr->interp, vPtr, newSize) != TCL_OK) {
- return TCL_ERROR;
- }
}
-#define CopyArrayToVector(vPtr, arr) \
- for (i = 0, n = *indexPtr; i < length; i++, n++) { \
- (vPtr)->valueArr[n] = (double)(arr)[i]; \
+ }
+ newSize = *indexPtr + length;
+ if (newSize > vPtr->length) {
+ if (Blt_Vec_ChangeLength(vPtr->interp, vPtr, newSize) != TCL_OK) {
+ return TCL_ERROR;
}
+ }
+#define CopyArrayToVector(vPtr, arr) \
+ for (i = 0, n = *indexPtr; i < length; i++, n++) { \
+ (vPtr)->valueArr[n] = (double)(arr)[i]; \
+ }
- switch (fmt) {
- case FMT_CHAR:
- CopyArrayToVector(vPtr, (char *)byteArr);
- break;
+ switch (fmt) {
+ case FMT_CHAR:
+ CopyArrayToVector(vPtr, (char *)byteArr);
+ break;
- case FMT_UCHAR:
- CopyArrayToVector(vPtr, (unsigned char *)byteArr);
- break;
+ case FMT_UCHAR:
+ CopyArrayToVector(vPtr, (unsigned char *)byteArr);
+ break;
- case FMT_INT:
- CopyArrayToVector(vPtr, (int *)byteArr);
- break;
+ case FMT_INT:
+ CopyArrayToVector(vPtr, (int *)byteArr);
+ break;
- case FMT_UINT:
- CopyArrayToVector(vPtr, (unsigned int *)byteArr);
- break;
+ case FMT_UINT:
+ CopyArrayToVector(vPtr, (unsigned int *)byteArr);
+ break;
- case FMT_LONG:
- CopyArrayToVector(vPtr, (long *)byteArr);
- break;
+ case FMT_LONG:
+ CopyArrayToVector(vPtr, (long *)byteArr);
+ break;
- case FMT_ULONG:
- CopyArrayToVector(vPtr, (unsigned long *)byteArr);
- break;
+ case FMT_ULONG:
+ CopyArrayToVector(vPtr, (unsigned long *)byteArr);
+ break;
- case FMT_SHORT:
- CopyArrayToVector(vPtr, (short int *)byteArr);
- break;
+ case FMT_SHORT:
+ CopyArrayToVector(vPtr, (short int *)byteArr);
+ break;
- case FMT_USHORT:
- CopyArrayToVector(vPtr, (unsigned short int *)byteArr);
- break;
+ case FMT_USHORT:
+ CopyArrayToVector(vPtr, (unsigned short int *)byteArr);
+ break;
- case FMT_FLOAT:
- CopyArrayToVector(vPtr, (float *)byteArr);
- break;
+ case FMT_FLOAT:
+ CopyArrayToVector(vPtr, (float *)byteArr);
+ break;
- case FMT_DOUBLE:
- CopyArrayToVector(vPtr, (double *)byteArr);
- break;
+ case FMT_DOUBLE:
+ CopyArrayToVector(vPtr, (double *)byteArr);
+ break;
- case FMT_UNKNOWN:
- break;
- }
- *indexPtr += length;
- return TCL_OK;
+ case FMT_UNKNOWN:
+ break;
+ }
+ *indexPtr += length;
+ return TCL_OK;
}
/*
@@ -1419,133 +1419,133 @@ CopyValues(Vector *vPtr, char *byteArr, enum NativeFormats fmt, int size,
static int
BinreadOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Tcl_Channel channel;
- char *byteArr;
- char *string;
- enum NativeFormats fmt;
- int arraySize, bytesRead;
- int count, total;
- int first;
- int size, length, mode;
- int swap;
- int i;
-
- string = Tcl_GetString(objv[2]);
- channel = Tcl_GetChannel(interp, string, &mode);
- if (channel == NULL) {
+ Tcl_Channel channel;
+ char *byteArr;
+ char *string;
+ enum NativeFormats fmt;
+ int arraySize, bytesRead;
+ int count, total;
+ int first;
+ int size, length, mode;
+ int swap;
+ int i;
+
+ string = Tcl_GetString(objv[2]);
+ channel = Tcl_GetChannel(interp, string, &mode);
+ if (channel == NULL) {
+ return TCL_ERROR;
+ }
+ if ((mode & TCL_READABLE) == 0) {
+ Tcl_AppendResult(interp, "channel \"", string,
+ "\" wasn't opened for reading", (char *)NULL);
+ return TCL_ERROR;
+ }
+ first = vPtr->length;
+ fmt = FMT_DOUBLE;
+ size = sizeof(double);
+ swap = 0;
+ count = 0;
+
+ if (objc > 3) {
+ string = Tcl_GetString(objv[3]);
+ if (string[0] != '-') {
+ long int value;
+ /* Get the number of values to read. */
+ if (Tcl_GetLongFromObj(interp, objv[3], &value) != TCL_OK) {
return TCL_ERROR;
- }
- if ((mode & TCL_READABLE) == 0) {
- Tcl_AppendResult(interp, "channel \"", string,
- "\" wasn't opened for reading", (char *)NULL);
+ }
+ if (value < 0) {
+ Tcl_AppendResult(interp, "count can't be negative",
+ (char *)NULL);
return TCL_ERROR;
+ }
+ count = (size_t)value;
+ objc--, objv++;
}
- first = vPtr->length;
- fmt = FMT_DOUBLE;
- size = sizeof(double);
- swap = 0;
- count = 0;
-
- if (objc > 3) {
- string = Tcl_GetString(objv[3]);
- if (string[0] != '-') {
- long int value;
- /* Get the number of values to read. */
- if (Tcl_GetLongFromObj(interp, objv[3], &value) != TCL_OK) {
- return TCL_ERROR;
- }
- if (value < 0) {
- Tcl_AppendResult(interp, "count can't be negative",
- (char *)NULL);
- return TCL_ERROR;
- }
- count = (size_t)value;
- objc--, objv++;
- }
- }
- /* Process any option-value pairs that remain. */
- for (i = 3; i < objc; i++) {
- string = Tcl_GetString(objv[i]);
- if (strcmp(string, "-swap") == 0) {
- swap = 1;
- } else if (strcmp(string, "-format") == 0) {
- i++;
- if (i >= objc) {
- Tcl_AppendResult(interp, "missing arg after \"", string,
- "\"", (char *)NULL);
- return TCL_ERROR;
- }
- string = Tcl_GetString(objv[i]);
- fmt = GetBinaryFormat(interp, string, &size);
- if (fmt == FMT_UNKNOWN) {
- return TCL_ERROR;
- }
- } else if (strcmp(string, "-at") == 0) {
- i++;
- if (i >= objc) {
- Tcl_AppendResult(interp, "missing arg after \"", string,
- "\"", (char *)NULL);
- return TCL_ERROR;
- }
- string = Tcl_GetString(objv[i]);
- if (Blt_Vec_GetIndex(interp, vPtr, string, &first, 0,
- (Blt_VectorIndexProc **)NULL) != TCL_OK) {
- return TCL_ERROR;
- }
- if (first > vPtr->length) {
- Tcl_AppendResult(interp, "index \"", string,
- "\" is out of range", (char *)NULL);
- return TCL_ERROR;
- }
- }
+ }
+ /* Process any option-value pairs that remain. */
+ for (i = 3; i < objc; i++) {
+ string = Tcl_GetString(objv[i]);
+ if (strcmp(string, "-swap") == 0) {
+ swap = 1;
+ } else if (strcmp(string, "-format") == 0) {
+ i++;
+ if (i >= objc) {
+ Tcl_AppendResult(interp, "missing arg after \"", string,
+ "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ string = Tcl_GetString(objv[i]);
+ fmt = GetBinaryFormat(interp, string, &size);
+ if (fmt == FMT_UNKNOWN) {
+ return TCL_ERROR;
+ }
+ } else if (strcmp(string, "-at") == 0) {
+ i++;
+ if (i >= objc) {
+ Tcl_AppendResult(interp, "missing arg after \"", string,
+ "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ string = Tcl_GetString(objv[i]);
+ if (Blt_Vec_GetIndex(interp, vPtr, string, &first, 0,
+ (Blt_VectorIndexProc **)NULL) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (first > vPtr->length) {
+ Tcl_AppendResult(interp, "index \"", string,
+ "\" is out of range", (char *)NULL);
+ return TCL_ERROR;
+ }
}
+ }
#define BUFFER_SIZE 1024
- if (count == 0) {
- arraySize = BUFFER_SIZE * size;
- } else {
- arraySize = count * size;
- }
+ if (count == 0) {
+ arraySize = BUFFER_SIZE * size;
+ } else {
+ arraySize = count * size;
+ }
- byteArr = malloc(arraySize);
- /* FIXME: restore old channel translation later? */
- if (Tcl_SetChannelOption(interp, channel, "-translation",
- "binary") != TCL_OK) {
- return TCL_ERROR;
+ byteArr = (char*)malloc(arraySize);
+ /* FIXME: restore old channel translation later? */
+ if (Tcl_SetChannelOption(interp, channel, "-translation",
+ "binary") != TCL_OK) {
+ return TCL_ERROR;
+ }
+ total = 0;
+ while (!Tcl_Eof(channel)) {
+ bytesRead = Tcl_Read(channel, byteArr, arraySize);
+ if (bytesRead < 0) {
+ Tcl_AppendResult(interp, "error reading channel: ",
+ Tcl_PosixError(interp), (char *)NULL);
+ return TCL_ERROR;
+ }
+ if ((bytesRead % size) != 0) {
+ Tcl_AppendResult(interp, "error reading channel: short read",
+ (char *)NULL);
+ return TCL_ERROR;
+ }
+ length = bytesRead / size;
+ if (CopyValues(vPtr, byteArr, fmt, size, length, swap, &first)
+ != TCL_OK) {
+ return TCL_ERROR;
}
- total = 0;
- while (!Tcl_Eof(channel)) {
- bytesRead = Tcl_Read(channel, byteArr, arraySize);
- if (bytesRead < 0) {
- Tcl_AppendResult(interp, "error reading channel: ",
- Tcl_PosixError(interp), (char *)NULL);
- return TCL_ERROR;
- }
- if ((bytesRead % size) != 0) {
- Tcl_AppendResult(interp, "error reading channel: short read",
- (char *)NULL);
- return TCL_ERROR;
- }
- length = bytesRead / size;
- if (CopyValues(vPtr, byteArr, fmt, size, length, swap, &first)
- != TCL_OK) {
- return TCL_ERROR;
- }
- total += length;
- if (count > 0) {
- break;
- }
- }
- free(byteArr);
-
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
+ total += length;
+ if (count > 0) {
+ break;
}
- Blt_Vec_UpdateClients(vPtr);
+ }
+ free(byteArr);
- /* Set the result as the number of values read. */
- Tcl_SetIntObj(Tcl_GetObjResult(interp), total);
- return TCL_OK;
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+
+ /* Set the result as the number of values read. */
+ Tcl_SetIntObj(Tcl_GetObjResult(interp), total);
+ return TCL_OK;
}
/*
@@ -1567,53 +1567,53 @@ BinreadOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
SearchOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- double min, max;
- int i;
- int wantValue;
- char *string;
- Tcl_Obj *listObjPtr;
-
- wantValue = 0;
- string = Tcl_GetString(objv[2]);
- if ((string[0] == '-') && (strcmp(string, "-value") == 0)) {
- wantValue = 1;
- objv++, objc--;
- }
- if (Blt_ExprDoubleFromObj(interp, objv[2], &min) != TCL_OK) {
- return TCL_ERROR;
- }
- max = min;
- if (objc > 4) {
- Tcl_AppendResult(interp, "wrong # arguments: should be \"",
- Tcl_GetString(objv[0]), " search ?-value? min ?max?",
- (char *)NULL);
- return TCL_ERROR;
- }
- if ((objc > 3) &&
- (Blt_ExprDoubleFromObj(interp, objv[3], &max) != TCL_OK)) {
- return TCL_ERROR;
- }
- if ((min - max) >= DBL_EPSILON) {
- return TCL_OK; /* Bogus range. Don't bother looking. */
+ double min, max;
+ int i;
+ int wantValue;
+ char *string;
+ Tcl_Obj *listObjPtr;
+
+ wantValue = 0;
+ string = Tcl_GetString(objv[2]);
+ if ((string[0] == '-') && (strcmp(string, "-value") == 0)) {
+ wantValue = 1;
+ objv++, objc--;
+ }
+ if (Blt_ExprDoubleFromObj(interp, objv[2], &min) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ max = min;
+ if (objc > 4) {
+ Tcl_AppendResult(interp, "wrong # arguments: should be \"",
+ Tcl_GetString(objv[0]), " search ?-value? min ?max?",
+ (char *)NULL);
+ return TCL_ERROR;
+ }
+ if ((objc > 3) &&
+ (Blt_ExprDoubleFromObj(interp, objv[3], &max) != TCL_OK)) {
+ return TCL_ERROR;
+ }
+ if ((min - max) >= DBL_EPSILON) {
+ return TCL_OK; /* Bogus range. Don't bother looking. */
+ }
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ if (wantValue) {
+ for (i = 0; i < vPtr->length; i++) {
+ if (InRange(vPtr->valueArr[i], min, max)) {
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(vPtr->valueArr[i]));
+ }
}
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- if (wantValue) {
- for (i = 0; i < vPtr->length; i++) {
- if (InRange(vPtr->valueArr[i], min, max)) {
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(vPtr->valueArr[i]));
- }
- }
- } else {
- for (i = 0; i < vPtr->length; i++) {
- if (InRange(vPtr->valueArr[i], min, max)) {
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewIntObj(i + vPtr->offset));
- }
- }
+ } else {
+ for (i = 0; i < vPtr->length; i++) {
+ if (InRange(vPtr->valueArr[i], min, max)) {
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewIntObj(i + vPtr->offset));
+ }
}
- Tcl_SetObjResult(interp, listObjPtr);
- return TCL_OK;
+ }
+ Tcl_SetObjResult(interp, listObjPtr);
+ return TCL_OK;
}
/*
@@ -1635,16 +1635,16 @@ SearchOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
OffsetOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- if (objc == 3) {
- int newOffset;
+ if (objc == 3) {
+ int newOffset;
- if (Tcl_GetIntFromObj(interp, objv[2], &newOffset) != TCL_OK) {
- return TCL_ERROR;
- }
- vPtr->offset = newOffset;
+ if (Tcl_GetIntFromObj(interp, objv[2], &newOffset) != TCL_OK) {
+ return TCL_ERROR;
}
- Tcl_SetIntObj(Tcl_GetObjResult(interp), vPtr->offset);
- return TCL_OK;
+ vPtr->offset = newOffset;
+ }
+ Tcl_SetIntObj(Tcl_GetObjResult(interp), vPtr->offset);
+ return TCL_OK;
}
/*
@@ -1663,16 +1663,16 @@ OffsetOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
RandomOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int i;
+ int i;
- for (i = 0; i < vPtr->length; i++) {
- vPtr->valueArr[i] = drand48();
- }
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
- return TCL_OK;
+ for (i = 0; i < vPtr->length; i++) {
+ vPtr->valueArr[i] = drand48();
+ }
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ return TCL_OK;
}
/*
@@ -1691,36 +1691,36 @@ RandomOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
SeqOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int n;
- double start, stop;
+ int n;
+ double start, stop;
- if (Blt_ExprDoubleFromObj(interp, objv[2], &start) != TCL_OK) {
- return TCL_ERROR;
- }
- if (Blt_ExprDoubleFromObj(interp, objv[3], &stop) != TCL_OK) {
- return TCL_ERROR;
+ if (Blt_ExprDoubleFromObj(interp, objv[2], &start) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (Blt_ExprDoubleFromObj(interp, objv[3], &stop) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ n = vPtr->length;
+ if ((objc > 4) && (Blt_ExprIntFromObj(interp, objv[4], &n) != TCL_OK)) {
+ return TCL_ERROR;
+ }
+ if (n > 1) {
+ int i;
+ double step;
+
+ if (Blt_Vec_SetLength(interp, vPtr, n) != TCL_OK) {
+ return TCL_ERROR;
}
- n = vPtr->length;
- if ((objc > 4) && (Blt_ExprIntFromObj(interp, objv[4], &n) != TCL_OK)) {
- return TCL_ERROR;
+ step = (stop - start) / (double)(n - 1);
+ for (i = 0; i < n; i++) {
+ vPtr->valueArr[i] = start + (step * i);
}
- if (n > 1) {
- int i;
- double step;
-
- if (Blt_Vec_SetLength(interp, vPtr, n) != TCL_OK) {
- return TCL_ERROR;
- }
- step = (stop - start) / (double)(n - 1);
- for (i = 0; i < n; i++) {
- vPtr->valueArr[i] = start + (step * i);
- }
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
}
- return TCL_OK;
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ return TCL_OK;
}
/*
@@ -1745,50 +1745,50 @@ SeqOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
SetOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int result;
- Vector *v2Ptr;
- int nElem;
- Tcl_Obj **elemObjArr;
-
- /* The source can be either a list of numbers or another vector. */
-
- v2Ptr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, vPtr->dataPtr,
- Tcl_GetString(objv[2]), NULL, NS_SEARCH_BOTH);
- if (v2Ptr != NULL) {
- if (vPtr == v2Ptr) {
- Vector *tmpPtr;
- /*
- * Source and destination vectors are the same. Copy the source
- * first into a temporary vector to avoid memory overlaps.
- */
- tmpPtr = Blt_Vec_New(vPtr->dataPtr);
- result = Blt_Vec_Duplicate(tmpPtr, v2Ptr);
- if (result == TCL_OK) {
- result = Blt_Vec_Duplicate(vPtr, tmpPtr);
- }
- Blt_Vec_Free(tmpPtr);
- } else {
- result = Blt_Vec_Duplicate(vPtr, v2Ptr);
- }
- } else if (Tcl_ListObjGetElements(interp, objv[2], &nElem, &elemObjArr)
- == TCL_OK) {
- result = CopyList(vPtr, interp, nElem, elemObjArr);
+ int result;
+ Vector *v2Ptr;
+ int nElem;
+ Tcl_Obj **elemObjArr;
+
+ /* The source can be either a list of numbers or another vector. */
+
+ v2Ptr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, vPtr->dataPtr,
+ Tcl_GetString(objv[2]), NULL, NS_SEARCH_BOTH);
+ if (v2Ptr != NULL) {
+ if (vPtr == v2Ptr) {
+ Vector *tmpPtr;
+ /*
+ * Source and destination vectors are the same. Copy the source
+ * first into a temporary vector to avoid memory overlaps.
+ */
+ tmpPtr = Blt_Vec_New(vPtr->dataPtr);
+ result = Blt_Vec_Duplicate(tmpPtr, v2Ptr);
+ if (result == TCL_OK) {
+ result = Blt_Vec_Duplicate(vPtr, tmpPtr);
+ }
+ Blt_Vec_Free(tmpPtr);
} else {
- return TCL_ERROR;
+ result = Blt_Vec_Duplicate(vPtr, v2Ptr);
}
+ } else if (Tcl_ListObjGetElements(interp, objv[2], &nElem, &elemObjArr)
+ == TCL_OK) {
+ result = CopyList(vPtr, interp, nElem, elemObjArr);
+ } else {
+ return TCL_ERROR;
+ }
- if (result == TCL_OK) {
- /*
- * The vector has changed; so flush the array indices (they're wrong
- * now), find the new range of the data, and notify the vector's
- * clients that it's been modified.
- */
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
+ if (result == TCL_OK) {
+ /*
+ * The vector has changed; so flush the array indices (they're wrong
+ * now), find the new range of the data, and notify the vector's
+ * clients that it's been modified.
+ */
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
}
- return result;
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ return result;
}
/*
@@ -1813,33 +1813,33 @@ SetOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
SimplifyOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- size_t i, n;
- int length, nPoints;
- int *simple;
- double tolerance = 10.0;
- Point2d *orig, *reduced;
-
- length = vPtr->length;
- nPoints = vPtr->length / 2;
- simple = malloc(nPoints * sizeof(int));
- reduced = malloc(nPoints * sizeof(Point2d));
- orig = (Point2d *)vPtr->valueArr;
- n = Blt_SimplifyLine(orig, 0, nPoints - 1, tolerance, simple);
- for (i = 0; i < n; i++) {
- reduced[i] = orig[simple[i]];
- }
- free(simple);
- Blt_Vec_Reset(vPtr, (double *)reduced, n * 2, vPtr->length, TCL_DYNAMIC);
- /*
- * The vector has changed; so flush the array indices (they're wrong
- * now), find the new range of the data, and notify the vector's
- * clients that it's been modified.
- */
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
- return TCL_OK;
+ size_t i, n;
+ int length, nPoints;
+ int *simple;
+ double tolerance = 10.0;
+ Point2d *orig, *reduced;
+
+ length = vPtr->length;
+ nPoints = vPtr->length / 2;
+ simple = (int*)malloc(nPoints * sizeof(int));
+ reduced = (Point2d*)malloc(nPoints * sizeof(Point2d));
+ orig = (Point2d *)vPtr->valueArr;
+ n = Blt_SimplifyLine(orig, 0, nPoints - 1, tolerance, simple);
+ for (i = 0; i < n; i++) {
+ reduced[i] = orig[simple[i]];
+ }
+ free(simple);
+ Blt_Vec_Reset(vPtr, (double *)reduced, n * 2, vPtr->length, TCL_DYNAMIC);
+ /*
+ * The vector has changed; so flush the array indices (they're wrong
+ * now), find the new range of the data, and notify the vector's
+ * clients that it's been modified.
+ */
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ return TCL_OK;
}
/*
@@ -1858,40 +1858,40 @@ SimplifyOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
SplitOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- int nVectors;
+ int nVectors;
- nVectors = objc - 2;
- if ((vPtr->length % nVectors) != 0) {
- Tcl_AppendResult(interp, "can't split vector \"", vPtr->name,
- "\" into ", Blt_Itoa(nVectors), " even parts.", (char *)NULL);
+ nVectors = objc - 2;
+ if ((vPtr->length % nVectors) != 0) {
+ Tcl_AppendResult(interp, "can't split vector \"", vPtr->name,
+ "\" into ", Blt_Itoa(nVectors), " even parts.", (char *)NULL);
+ return TCL_ERROR;
+ }
+ if (nVectors > 0) {
+ Vector *v2Ptr;
+ char *string; /* Name of vector. */
+ int i, j, k;
+ int oldSize, newSize, extra, isNew;
+
+ extra = vPtr->length / nVectors;
+ for (i = 0; i < nVectors; i++) {
+ string = Tcl_GetString(objv[i+2]);
+ v2Ptr = Blt_Vec_Create(vPtr->dataPtr, string, string, string,
+ &isNew);
+ oldSize = v2Ptr->length;
+ newSize = oldSize + extra;
+ if (Blt_Vec_SetLength(interp, v2Ptr, newSize) != TCL_OK) {
return TCL_ERROR;
+ }
+ for (j = i, k = oldSize; j < vPtr->length; j += nVectors, k++) {
+ v2Ptr->valueArr[k] = vPtr->valueArr[j];
+ }
+ Blt_Vec_UpdateClients(v2Ptr);
+ if (v2Ptr->flush) {
+ Blt_Vec_FlushCache(v2Ptr);
+ }
}
- if (nVectors > 0) {
- Vector *v2Ptr;
- char *string; /* Name of vector. */
- int i, j, k;
- int oldSize, newSize, extra, isNew;
-
- extra = vPtr->length / nVectors;
- for (i = 0; i < nVectors; i++) {
- string = Tcl_GetString(objv[i+2]);
- v2Ptr = Blt_Vec_Create(vPtr->dataPtr, string, string, string,
- &isNew);
- oldSize = v2Ptr->length;
- newSize = oldSize + extra;
- if (Blt_Vec_SetLength(interp, v2Ptr, newSize) != TCL_OK) {
- return TCL_ERROR;
- }
- for (j = i, k = oldSize; j < vPtr->length; j += nVectors, k++) {
- v2Ptr->valueArr[k] = vPtr->valueArr[j];
- }
- Blt_Vec_UpdateClients(v2Ptr);
- if (v2Ptr->flush) {
- Blt_Vec_FlushCache(v2Ptr);
- }
- }
- }
- return TCL_OK;
+ }
+ return TCL_OK;
}
@@ -1905,22 +1905,22 @@ static int sortDecreasing; /* Indicates the ordering of the sort. If
static int
CompareVectors(void *a, void *b)
{
- double delta;
- int i;
- int sign;
- Vector *vPtr;
-
- sign = (sortDecreasing) ? -1 : 1;
- for (i = 0; i < nSortVectors; i++) {
- vPtr = sortVectors[i];
- delta = vPtr->valueArr[*(int *)a] - vPtr->valueArr[*(int *)b];
- if (delta < 0.0) {
- return (-1 * sign);
- } else if (delta > 0.0) {
- return (1 * sign);
- }
- }
- return 0;
+ double delta;
+ int i;
+ int sign;
+ Vector *vPtr;
+
+ sign = (sortDecreasing) ? -1 : 1;
+ for (i = 0; i < nSortVectors; i++) {
+ vPtr = sortVectors[i];
+ delta = vPtr->valueArr[*(int *)a] - vPtr->valueArr[*(int *)b];
+ if (delta < 0.0) {
+ return (-1 * sign);
+ } else if (delta > 0.0) {
+ return (1 * sign);
+ }
+ }
+ return 0;
}
/*
@@ -1945,51 +1945,51 @@ CompareVectors(void *a, void *b)
size_t *
Blt_Vec_SortMap(Vector **vectors, int nVectors)
{
- size_t *map;
- int i;
- Vector *vPtr = *vectors;
- int length;
-
- length = vPtr->last - vPtr->first + 1;
- map = malloc(sizeof(size_t) * length);
- for (i = vPtr->first; i <= vPtr->last; i++) {
- map[i] = i;
- }
- /* Set global variables for sorting routine. */
- sortVectors = vectors;
- nSortVectors = nVectors;
- qsort((char *)map, length, sizeof(size_t),
- (QSortCompareProc *)CompareVectors);
- return map;
+ size_t *map;
+ int i;
+ Vector *vPtr = *vectors;
+ int length;
+
+ length = vPtr->last - vPtr->first + 1;
+ map = (size_t*)malloc(sizeof(size_t) * length);
+ for (i = vPtr->first; i <= vPtr->last; i++) {
+ map[i] = i;
+ }
+ /* Set global variables for sorting routine. */
+ sortVectors = vectors;
+ nSortVectors = nVectors;
+ qsort((char *)map, length, sizeof(size_t),
+ (QSortCompareProc *)CompareVectors);
+ return map;
}
static size_t *
SortVectors(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Vector **vectors, *v2Ptr;
- size_t *map;
- int i;
-
- vectors = malloc(sizeof(Vector *) * (objc + 1));
- vectors[0] = vPtr;
- map = NULL;
- for (i = 0; i < objc; i++) {
- if (Blt_Vec_LookupName(vPtr->dataPtr, Tcl_GetString(objv[i]),
- &v2Ptr) != TCL_OK) {
- goto error;
- }
- if (v2Ptr->length != vPtr->length) {
- Tcl_AppendResult(interp, "vector \"", v2Ptr->name,
- "\" is not the same size as \"", vPtr->name, "\"",
- (char *)NULL);
- goto error;
- }
- vectors[i + 1] = v2Ptr;
- }
- map = Blt_Vec_SortMap(vectors, objc + 1);
- error:
- free(vectors);
- return map;
+ Vector **vectors, *v2Ptr;
+ size_t *map;
+ int i;
+
+ vectors = (Vector**)malloc(sizeof(Vector *) * (objc + 1));
+ vectors[0] = vPtr;
+ map = NULL;
+ for (i = 0; i < objc; i++) {
+ if (Blt_Vec_LookupName(vPtr->dataPtr, Tcl_GetString(objv[i]),
+ &v2Ptr) != TCL_OK) {
+ goto error;
+ }
+ if (v2Ptr->length != vPtr->length) {
+ Tcl_AppendResult(interp, "vector \"", v2Ptr->name,
+ "\" is not the same size as \"", vPtr->name, "\"",
+ (char *)NULL);
+ goto error;
+ }
+ vectors[i + 1] = v2Ptr;
+ }
+ map = Blt_Vec_SortMap(vectors, objc + 1);
+ error:
+ free(vectors);
+ return map;
}
@@ -2015,93 +2015,93 @@ SortVectors(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
SortOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- Vector *v2Ptr;
- double *copy;
- size_t *map;
- size_t sortLength, nBytes;
- int result;
- int i;
- unsigned int n;
- SortSwitches switches;
-
- sortDecreasing = 0;
- switches.flags = 0;
- i = Blt_ParseSwitches(interp, sortSwitches, objc - 2, objv + 2, &switches,
- BLT_SWITCH_OBJV_PARTIAL);
- if (i < 0) {
- return TCL_ERROR;
- }
- objc -= i, objv += i;
- sortDecreasing = (switches.flags & SORT_DECREASING);
- if (objc > 2) {
- map = SortVectors(vPtr, interp, objc - 2, objv + 2);
- } else {
- map = Blt_Vec_SortMap(&vPtr, 1);
+ Vector *v2Ptr;
+ double *copy;
+ size_t *map;
+ size_t sortLength, nBytes;
+ int result;
+ int i;
+ unsigned int n;
+ SortSwitches switches;
+
+ sortDecreasing = 0;
+ switches.flags = 0;
+ i = Blt_ParseSwitches(interp, sortSwitches, objc - 2, objv + 2, &switches,
+ BLT_SWITCH_OBJV_PARTIAL);
+ if (i < 0) {
+ return TCL_ERROR;
+ }
+ objc -= i, objv += i;
+ sortDecreasing = (switches.flags & SORT_DECREASING);
+ if (objc > 2) {
+ map = SortVectors(vPtr, interp, objc - 2, objv + 2);
+ } else {
+ map = Blt_Vec_SortMap(&vPtr, 1);
+ }
+ if (map == NULL) {
+ return TCL_ERROR;
+ }
+ sortLength = vPtr->length;
+ /*
+ * Create an array to store a copy of the current values of the
+ * vector. We'll merge the values back into the vector based upon the
+ * indices found in the index array.
+ */
+ nBytes = sizeof(double) * sortLength;
+ copy = (double*)malloc(nBytes);
+ memcpy((char *)copy, (char *)vPtr->valueArr, nBytes);
+ if (switches.flags & SORT_UNIQUE) {
+ int count;
+
+ for (count = n = 1; n < sortLength; n++) {
+ size_t next, prev;
+
+ next = map[n];
+ prev = map[n - 1];
+ if (copy[next] != copy[prev]) {
+ map[count] = next;
+ count++;
+ }
}
- if (map == NULL) {
- return TCL_ERROR;
+ sortLength = count;
+ nBytes = sortLength * sizeof(double);
+ }
+ if (sortLength != vPtr->length) {
+ Blt_Vec_SetLength(interp, vPtr, sortLength);
+ }
+ for (n = 0; n < sortLength; n++) {
+ vPtr->valueArr[n] = copy[map[n]];
+ }
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+
+ /* Now sort any other vectors in the same fashion. The vectors must be
+ * the same size as the map though. */
+ result = TCL_ERROR;
+ for (i = 2; i < objc; i++) {
+ if (Blt_Vec_LookupName(vPtr->dataPtr, Tcl_GetString(objv[i]),
+ &v2Ptr) != TCL_OK) {
+ goto error;
}
- sortLength = vPtr->length;
- /*
- * Create an array to store a copy of the current values of the
- * vector. We'll merge the values back into the vector based upon the
- * indices found in the index array.
- */
- nBytes = sizeof(double) * sortLength;
- copy = malloc(nBytes);
- memcpy((char *)copy, (char *)vPtr->valueArr, nBytes);
- if (switches.flags & SORT_UNIQUE) {
- int count;
-
- for (count = n = 1; n < sortLength; n++) {
- size_t next, prev;
-
- next = map[n];
- prev = map[n - 1];
- if (copy[next] != copy[prev]) {
- map[count] = next;
- count++;
- }
- }
- sortLength = count;
- nBytes = sortLength * sizeof(double);
- }
- if (sortLength != vPtr->length) {
- Blt_Vec_SetLength(interp, vPtr, sortLength);
+ if (sortLength != v2Ptr->length) {
+ Blt_Vec_SetLength(interp, v2Ptr, sortLength);
}
+ memcpy((char *)copy, (char *)v2Ptr->valueArr, nBytes);
for (n = 0; n < sortLength; n++) {
- vPtr->valueArr[n] = copy[map[n]];
+ v2Ptr->valueArr[n] = copy[map[n]];
}
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
+ Blt_Vec_UpdateClients(v2Ptr);
+ if (v2Ptr->flush) {
+ Blt_Vec_FlushCache(v2Ptr);
}
- Blt_Vec_UpdateClients(vPtr);
-
- /* Now sort any other vectors in the same fashion. The vectors must be
- * the same size as the map though. */
- result = TCL_ERROR;
- for (i = 2; i < objc; i++) {
- if (Blt_Vec_LookupName(vPtr->dataPtr, Tcl_GetString(objv[i]),
- &v2Ptr) != TCL_OK) {
- goto error;
- }
- if (sortLength != v2Ptr->length) {
- Blt_Vec_SetLength(interp, v2Ptr, sortLength);
- }
- memcpy((char *)copy, (char *)v2Ptr->valueArr, nBytes);
- for (n = 0; n < sortLength; n++) {
- v2Ptr->valueArr[n] = copy[map[n]];
- }
- Blt_Vec_UpdateClients(v2Ptr);
- if (v2Ptr->flush) {
- Blt_Vec_FlushCache(v2Ptr);
- }
- }
- result = TCL_OK;
- error:
- free(copy);
- free(map);
- return result;
+ }
+ result = TCL_OK;
+ error:
+ free(copy);
+ free(map);
+ return result;
}
/*
@@ -2122,15 +2122,15 @@ static int
InstExprOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- if (Blt_ExprVector(interp, Tcl_GetString(objv[2]), (Blt_Vector *)vPtr)
- != TCL_OK) {
- return TCL_ERROR;
- }
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
- return TCL_OK;
+ if (Blt_ExprVector(interp, Tcl_GetString(objv[2]), (Blt_Vector *)vPtr)
+ != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ return TCL_OK;
}
/*
@@ -2153,104 +2153,104 @@ InstExprOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
static int
ArithOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
{
- double value;
- int i;
- Vector *v2Ptr;
- double scalar;
- Tcl_Obj *listObjPtr;
- char *string;
+ double value;
+ int i;
+ Vector *v2Ptr;
+ double scalar;
+ Tcl_Obj *listObjPtr;
+ char *string;
+
+ v2Ptr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, vPtr->dataPtr,
+ Tcl_GetString(objv[2]), NULL, NS_SEARCH_BOTH);
+ if (v2Ptr != NULL) {
+ int j;
+ int length;
- v2Ptr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, vPtr->dataPtr,
- Tcl_GetString(objv[2]), NULL, NS_SEARCH_BOTH);
- if (v2Ptr != NULL) {
- int j;
- int length;
-
- length = v2Ptr->last - v2Ptr->first + 1;
- if (length != vPtr->length) {
- Tcl_AppendResult(interp, "vectors \"", Tcl_GetString(objv[0]),
- "\" and \"", Tcl_GetString(objv[2]),
- "\" are not the same length", (char *)NULL);
- return TCL_ERROR;
- }
- string = Tcl_GetString(objv[1]);
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- switch (string[0]) {
- case '*':
- for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
- value = vPtr->valueArr[i] * v2Ptr->valueArr[j];
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
-
- case '/':
- for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
- value = vPtr->valueArr[i] / v2Ptr->valueArr[j];
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
-
- case '-':
- for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
- value = vPtr->valueArr[i] - v2Ptr->valueArr[j];
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
-
- case '+':
- for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
- value = vPtr->valueArr[i] + v2Ptr->valueArr[j];
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
- }
- Tcl_SetObjResult(interp, listObjPtr);
-
- } else if (Blt_ExprDoubleFromObj(interp, objv[2], &scalar) == TCL_OK) {
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
- string = Tcl_GetString(objv[1]);
- switch (string[0]) {
- case '*':
- for (i = 0; i < vPtr->length; i++) {
- value = vPtr->valueArr[i] * scalar;
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
-
- case '/':
- for (i = 0; i < vPtr->length; i++) {
- value = vPtr->valueArr[i] / scalar;
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
-
- case '-':
- for (i = 0; i < vPtr->length; i++) {
- value = vPtr->valueArr[i] - scalar;
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
-
- case '+':
- for (i = 0; i < vPtr->length; i++) {
- value = vPtr->valueArr[i] + scalar;
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewDoubleObj(value));
- }
- break;
- }
- Tcl_SetObjResult(interp, listObjPtr);
- } else {
- return TCL_ERROR;
+ length = v2Ptr->last - v2Ptr->first + 1;
+ if (length != vPtr->length) {
+ Tcl_AppendResult(interp, "vectors \"", Tcl_GetString(objv[0]),
+ "\" and \"", Tcl_GetString(objv[2]),
+ "\" are not the same length", (char *)NULL);
+ return TCL_ERROR;
}
- return TCL_OK;
+ string = Tcl_GetString(objv[1]);
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ switch (string[0]) {
+ case '*':
+ for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
+ value = vPtr->valueArr[i] * v2Ptr->valueArr[j];
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+
+ case '/':
+ for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
+ value = vPtr->valueArr[i] / v2Ptr->valueArr[j];
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+
+ case '-':
+ for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
+ value = vPtr->valueArr[i] - v2Ptr->valueArr[j];
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+
+ case '+':
+ for (i = 0, j = v2Ptr->first; i < vPtr->length; i++, j++) {
+ value = vPtr->valueArr[i] + v2Ptr->valueArr[j];
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+ }
+ Tcl_SetObjResult(interp, listObjPtr);
+
+ } else if (Blt_ExprDoubleFromObj(interp, objv[2], &scalar) == TCL_OK) {
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
+ string = Tcl_GetString(objv[1]);
+ switch (string[0]) {
+ case '*':
+ for (i = 0; i < vPtr->length; i++) {
+ value = vPtr->valueArr[i] * scalar;
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+
+ case '/':
+ for (i = 0; i < vPtr->length; i++) {
+ value = vPtr->valueArr[i] / scalar;
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+
+ case '-':
+ for (i = 0; i < vPtr->length; i++) {
+ value = vPtr->valueArr[i] - scalar;
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+
+ case '+':
+ for (i = 0; i < vPtr->length; i++) {
+ value = vPtr->valueArr[i] + scalar;
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewDoubleObj(value));
+ }
+ break;
+ }
+ Tcl_SetObjResult(interp, listObjPtr);
+ } else {
+ return TCL_ERROR;
+ }
+ return TCL_OK;
}
/*
@@ -2266,39 +2266,39 @@ ArithOp(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[])
*---------------------------------------------------------------------------
*/
static Blt_OpSpec vectorInstOps[] =
-{
- {"*", 1, ArithOp, 3, 3, "item",}, /*Deprecated*/
- {"+", 1, ArithOp, 3, 3, "item",}, /*Deprecated*/
- {"-", 1, ArithOp, 3, 3, "item",}, /*Deprecated*/
- {"/", 1, ArithOp, 3, 3, "item",}, /*Deprecated*/
- {"append", 1, AppendOp, 3, 0, "item ?item...?",},
- {"binread", 1, BinreadOp, 3, 0, "channel ?numValues? ?flags?",},
- {"clear", 1, ClearOp, 2, 2, "",},
- {"delete", 2, DeleteOp, 2, 0, "index ?index...?",},
- {"dup", 2, DupOp, 3, 0, "vecName",},
- {"expr", 1, InstExprOp, 3, 3, "expression",},
- {"fft", 1, FFTOp, 3, 0, "vecName ?switches?",},
- {"index", 3, IndexOp, 3, 4, "index ?value?",},
- {"inversefft",3, InverseFFTOp,4, 4, "vecName vecName",},
- {"length", 1, LengthOp, 2, 3, "?newSize?",},
- {"max", 2, MaxOp, 2, 2, "",},
- {"merge", 2, MergeOp, 3, 0, "vecName ?vecName...?",},
- {"min", 2, MinOp, 2, 2, "",},
- {"normalize", 3, NormalizeOp, 2, 3, "?vecName?",}, /*Deprecated*/
- {"notify", 3, NotifyOp, 3, 3, "keyword",},
- {"offset", 1, OffsetOp, 2, 3, "?offset?",},
- {"populate", 1, PopulateOp, 4, 4, "vecName density",},
- {"random", 4, RandomOp, 2, 2, "",}, /*Deprecated*/
- {"range", 4, RangeOp, 2, 4, "first last",},
- {"search", 3, SearchOp, 3, 5, "?-value? value ?value?",},
- {"seq", 3, SeqOp, 4, 5, "begin end ?num?",},
- {"set", 3, SetOp, 3, 3, "list",},
- {"simplify", 2, SimplifyOp, 2, 2, },
- {"sort", 2, SortOp, 2, 0, "?switches? ?vecName...?",},
- {"split", 2, SplitOp, 2, 0, "?vecName...?",},
- {"values", 3, ValuesOp, 2, 0, "?switches?",},
- {"variable", 3, MapOp, 2, 3, "?varName?",},
-};
+ {
+ {"*", 1, (void*)ArithOp, 3, 3, "item",}, /*Deprecated*/
+ {"+", 1, (void*)ArithOp, 3, 3, "item",}, /*Deprecated*/
+ {"-", 1, (void*)ArithOp, 3, 3, "item",}, /*Deprecated*/
+ {"/", 1, (void*)ArithOp, 3, 3, "item",}, /*Deprecated*/
+ {"append", 1, (void*)AppendOp, 3, 0, "item ?item...?",},
+ {"binread", 1, (void*)BinreadOp, 3, 0, "channel ?numValues? ?flags?",},
+ {"clear", 1, (void*)ClearOp, 2, 2, "",},
+ {"delete", 2, (void*)DeleteOp, 2, 0, "index ?index...?",},
+ {"dup", 2, (void*)DupOp, 3, 0, "vecName",},
+ {"expr", 1, (void*)InstExprOp, 3, 3, "expression",},
+ {"fft", 1, (void*)FFTOp, 3, 0, "vecName ?switches?",},
+ {"index", 3, (void*)IndexOp, 3, 4, "index ?value?",},
+ {"inversefft",3, (void*)InverseFFTOp,4, 4, "vecName vecName",},
+ {"length", 1, (void*)LengthOp, 2, 3, "?newSize?",},
+ {"max", 2, (void*)MaxOp, 2, 2, "",},
+ {"merge", 2, (void*)MergeOp, 3, 0, "vecName ?vecName...?",},
+ {"min", 2, (void*)MinOp, 2, 2, "",},
+ {"normalize", 3, (void*)NormalizeOp, 2, 3, "?vecName?",}, /*Deprecated*/
+ {"notify", 3, (void*)NotifyOp, 3, 3, "keyword",},
+ {"offset", 1, (void*)OffsetOp, 2, 3, "?offset?",},
+ {"populate", 1, (void*)PopulateOp, 4, 4, "vecName density",},
+ {"random", 4, (void*)RandomOp, 2, 2, "",}, /*Deprecated*/
+ {"range", 4, (void*)RangeOp, 2, 4, "first last",},
+ {"search", 3, (void*)SearchOp, 3, 5, "?-value? value ?value?",},
+ {"seq", 3, (void*)SeqOp, 4, 5, "begin end ?num?",},
+ {"set", 3, (void*)SetOp, 3, 3, "list",},
+ {"simplify", 2, (void*)SimplifyOp, 2, 2, },
+ {"sort", 2, (void*)SortOp, 2, 0, "?switches? ?vecName...?",},
+ {"split", 2, (void*)SplitOp, 2, 0, "?vecName...?",},
+ {"values", 3, (void*)ValuesOp, 2, 0, "?switches?",},
+ {"variable", 3, (void*)MapOp, 2, 3, "?varName?",},
+ };
static int nInstOps = sizeof(vectorInstOps) / sizeof(Blt_OpSpec);
@@ -2306,17 +2306,17 @@ int
Blt_Vec_InstCmd(ClientData clientData, Tcl_Interp* interp, int objc,
Tcl_Obj* const objv[])
{
- VectorCmdProc *proc;
- Vector *vPtr = clientData;
-
- vPtr->first = 0;
- vPtr->last = vPtr->length - 1;
- proc = Blt_GetOpFromObj(interp, nInstOps, vectorInstOps, BLT_OP_ARG1, objc,
- objv, 0);
- if (proc == NULL) {
- return TCL_ERROR;
- }
- return (*proc) (vPtr, interp, objc, objv);
+ VectorCmdProc* proc;
+ Vector* vPtr = (Vector*)clientData;
+
+ vPtr->first = 0;
+ vPtr->last = vPtr->length - 1;
+ proc = (VectorCmdProc*)Blt_GetOpFromObj(interp, nInstOps, vectorInstOps, BLT_OP_ARG1, objc,
+ objv, 0);
+ if (proc == NULL) {
+ return TCL_ERROR;
+ }
+ return (*proc) (vPtr, interp, objc, objv);
}
@@ -2336,117 +2336,117 @@ char *
Blt_Vec_VarTrace(ClientData clientData, Tcl_Interp* interp, const char *part1,
const char *part2, int flags)
{
- Blt_VectorIndexProc *indexProc;
- Vector *vPtr = clientData;
- int first, last;
- int varFlags;
+ Blt_VectorIndexProc *indexProc;
+ Vector* vPtr = (Vector*)clientData;
+ int first, last;
+ int varFlags;
#define MAX_ERR_MSG 1023
- static char message[MAX_ERR_MSG + 1];
-
- if (part2 == NULL) {
- if (flags & TCL_TRACE_UNSETS) {
- free((void*)(vPtr->arrayName));
- vPtr->arrayName = NULL;
- if (vPtr->freeOnUnset) {
- Blt_Vec_Free(vPtr);
- }
- }
- return NULL;
- }
- if (Blt_Vec_GetIndexRange(interp, vPtr, part2, INDEX_ALL_FLAGS, &indexProc)
- != TCL_OK) {
- goto error;
+ static char message[MAX_ERR_MSG + 1];
+
+ if (part2 == NULL) {
+ if (flags & TCL_TRACE_UNSETS) {
+ free((void*)(vPtr->arrayName));
+ vPtr->arrayName = NULL;
+ if (vPtr->freeOnUnset) {
+ Blt_Vec_Free(vPtr);
+ }
}
- first = vPtr->first, last = vPtr->last;
- varFlags = TCL_LEAVE_ERR_MSG | (TCL_GLOBAL_ONLY & flags);
- if (flags & TCL_TRACE_WRITES) {
- double value;
- Tcl_Obj *objPtr;
-
- if (first == SPECIAL_INDEX) { /* Tried to set "min" or "max" */
- return (char *)"read-only index";
- }
- objPtr = Tcl_GetVar2Ex(interp, part1, part2, varFlags);
- if (objPtr == NULL) {
- goto error;
- }
- if (Blt_ExprDoubleFromObj(interp, objPtr, &value) != TCL_OK) {
- if ((last == first) && (first >= 0)) {
- /* Single numeric index. Reset the array element to
- * its old value on errors */
- Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags);
- }
- goto error;
- }
- if (first == vPtr->length) {
- if (Blt_Vec_ChangeLength((Tcl_Interp *)NULL, vPtr, vPtr->length + 1)
- != TCL_OK) {
- return (char *)"error resizing vector";
- }
- }
- /* Set possibly an entire range of values */
- ReplicateValue(vPtr, first, last, value);
- } else if (flags & TCL_TRACE_READS) {
- double value;
- Tcl_Obj *objPtr;
-
- if (vPtr->length == 0) {
- if (Tcl_SetVar2(interp, part1, part2, "", varFlags) == NULL) {
- goto error;
- }
- return NULL;
- }
- if (first == vPtr->length) {
- return (char *)"write-only index";
- }
- if (first == last) {
- if (first >= 0) {
- value = vPtr->valueArr[first];
- } else {
- vPtr->first = 0, vPtr->last = vPtr->length - 1;
- value = (*indexProc) ((Blt_Vector *) vPtr);
- }
- objPtr = Tcl_NewDoubleObj(value);
- if (Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags) == NULL) {
- Tcl_DecrRefCount(objPtr);
- goto error;
- }
- } else {
- objPtr = GetValues(vPtr, first, last);
- if (Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags) == NULL) {
- Tcl_DecrRefCount(objPtr);
- goto error;
- }
- }
- } else if (flags & TCL_TRACE_UNSETS) {
- int i, j;
-
- if ((first == vPtr->length) || (first == SPECIAL_INDEX)) {
- return (char *)"special vector index";
- }
- /*
- * Collapse the vector from the point of the first unset element.
- * Also flush any array variable entries so that the shift is
- * reflected when the array variable is read.
- */
- for (i = first, j = last + 1; j < vPtr->length; i++, j++) {
- vPtr->valueArr[i] = vPtr->valueArr[j];
- }
- vPtr->length -= ((last - first) + 1);
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
+ return NULL;
+ }
+ if (Blt_Vec_GetIndexRange(interp, vPtr, part2, INDEX_ALL_FLAGS, &indexProc)
+ != TCL_OK) {
+ goto error;
+ }
+ first = vPtr->first, last = vPtr->last;
+ varFlags = TCL_LEAVE_ERR_MSG | (TCL_GLOBAL_ONLY & flags);
+ if (flags & TCL_TRACE_WRITES) {
+ double value;
+ Tcl_Obj *objPtr;
+
+ if (first == SPECIAL_INDEX) { /* Tried to set "min" or "max" */
+ return (char *)"read-only index";
+ }
+ objPtr = Tcl_GetVar2Ex(interp, part1, part2, varFlags);
+ if (objPtr == NULL) {
+ goto error;
+ }
+ if (Blt_ExprDoubleFromObj(interp, objPtr, &value) != TCL_OK) {
+ if ((last == first) && (first >= 0)) {
+ /* Single numeric index. Reset the array element to
+ * its old value on errors */
+ Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags);
+ }
+ goto error;
+ }
+ if (first == vPtr->length) {
+ if (Blt_Vec_ChangeLength((Tcl_Interp *)NULL, vPtr, vPtr->length + 1)
+ != TCL_OK) {
+ return (char *)"error resizing vector";
+ }
+ }
+ /* Set possibly an entire range of values */
+ ReplicateValue(vPtr, first, last, value);
+ } else if (flags & TCL_TRACE_READS) {
+ double value;
+ Tcl_Obj *objPtr;
+
+ if (vPtr->length == 0) {
+ if (Tcl_SetVar2(interp, part1, part2, "", varFlags) == NULL) {
+ goto error;
+ }
+ return NULL;
+ }
+ if (first == vPtr->length) {
+ return (char *)"write-only index";
+ }
+ if (first == last) {
+ if (first >= 0) {
+ value = vPtr->valueArr[first];
+ } else {
+ vPtr->first = 0, vPtr->last = vPtr->length - 1;
+ value = (*indexProc) ((Blt_Vector *) vPtr);
+ }
+ objPtr = Tcl_NewDoubleObj(value);
+ if (Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags) == NULL) {
+ Tcl_DecrRefCount(objPtr);
+ goto error;
+ }
} else {
- return (char *)"unknown variable trace flag";
+ objPtr = GetValues(vPtr, first, last);
+ if (Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags) == NULL) {
+ Tcl_DecrRefCount(objPtr);
+ goto error;
+ }
}
- if (flags & (TCL_TRACE_UNSETS | TCL_TRACE_WRITES)) {
- Blt_Vec_UpdateClients(vPtr);
+ } else if (flags & TCL_TRACE_UNSETS) {
+ int i, j;
+
+ if ((first == vPtr->length) || (first == SPECIAL_INDEX)) {
+ return (char *)"special vector index";
}
- Tcl_ResetResult(interp);
- return NULL;
+ /*
+ * Collapse the vector from the point of the first unset element.
+ * Also flush any array variable entries so that the shift is
+ * reflected when the array variable is read.
+ */
+ for (i = first, j = last + 1; j < vPtr->length; i++, j++) {
+ vPtr->valueArr[i] = vPtr->valueArr[j];
+ }
+ vPtr->length -= ((last - first) + 1);
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ } else {
+ return (char *)"unknown variable trace flag";
+ }
+ if (flags & (TCL_TRACE_UNSETS | TCL_TRACE_WRITES)) {
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ Tcl_ResetResult(interp);
+ return NULL;
error:
- strncpy(message, Tcl_GetStringResult(interp), MAX_ERR_MSG);
- message[MAX_ERR_MSG] = '\0';
- return message;
+ strncpy(message, Tcl_GetStringResult(interp), MAX_ERR_MSG);
+ message[MAX_ERR_MSG] = '\0';
+ return message;
}
diff --git a/src/bltVecInt.h b/src/bltVecInt.h
index 6a5a353..da2e107 100644
--- a/src/bltVecInt.h
+++ b/src/bltVecInt.h
@@ -56,11 +56,11 @@ typedef struct {
} Point2d;
typedef struct {
- Tcl_HashTable vectorTable; /* Table of vectors */
- Tcl_HashTable mathProcTable; /* Table of vector math functions */
- Tcl_HashTable indexProcTable;
- Tcl_Interp* interp;
- unsigned int nextId;
+ Tcl_HashTable vectorTable; /* Table of vectors */
+ Tcl_HashTable mathProcTable; /* Table of vector math functions */
+ Tcl_HashTable indexProcTable;
+ Tcl_Interp* interp;
+ unsigned int nextId;
} VectorInterpData;
/*
@@ -82,68 +82,68 @@ typedef struct {
typedef struct {
- /*
- * If you change these fields, make sure you change the definition of
- * Blt_Vector in blt.h too.
- */
+ /*
+ * If you change these fields, make sure you change the definition of
+ * Blt_Vector in blt.h too.
+ */
- double *valueArr; /* Array of values (malloc-ed) */
+ double *valueArr; /* Array of values (malloc-ed) */
- int length; /* Current number of values in the array. */
+ int length; /* Current number of values in the array. */
- int size; /* Maximum number of values that can be stored
+ int size; /* Maximum number of values that can be stored
* in the value array. */
- double min, max; /* Minimum and maximum values in the vector */
+ double min, max; /* Minimum and maximum values in the vector */
- int dirty; /* Indicates if the vector has been updated */
+ int dirty; /* Indicates if the vector has been updated */
- int reserved;
+ int reserved;
- /* The following fields are local to this module */
+ /* The following fields are local to this module */
- const char *name; /* The namespace-qualified name of the vector.
+ const char *name; /* The namespace-qualified name of the vector.
* It points to the hash key allocated for the
* entry in the vector hash table. */
- VectorInterpData *dataPtr;
- Tcl_Interp* interp; /* Interpreter associated with the
+ VectorInterpData *dataPtr;
+ Tcl_Interp* interp; /* Interpreter associated with the
* vector */
- Tcl_HashEntry *hashPtr; /* If non-NULL, pointer in a hash table to
+ Tcl_HashEntry *hashPtr; /* If non-NULL, pointer in a hash table to
* track the vectors in use. */
- Tcl_FreeProc *freeProc; /* Address of procedure to call to release
+ Tcl_FreeProc *freeProc; /* Address of procedure to call to release
* storage for the value array, Optionally can
* be one of the following: TCL_STATIC,
* TCL_DYNAMIC, or TCL_VOLATILE. */
- const char *arrayName; /* The name of the TCL array variable mapped
+ const char *arrayName; /* The name of the TCL array variable mapped
* to the vector (malloc'ed). If NULL,
* indicates that the vector isn't mapped to
* any variable */
- Tcl_Namespace *nsPtr; /* Namespace context of the vector itself. */
+ Tcl_Namespace *nsPtr; /* Namespace context of the vector itself. */
- int offset; /* Offset from zero of the vector's starting
+ int offset; /* Offset from zero of the vector's starting
* index */
- Tcl_Command cmdToken; /* Token for vector's TCL command. */
+ Tcl_Command cmdToken; /* Token for vector's TCL command. */
- Blt_Chain chain; /* List of clients using this vector */
+ Blt_Chain chain; /* List of clients using this vector */
- int notifyFlags; /* Notification flags. See definitions
+ int notifyFlags; /* Notification flags. See definitions
* below */
- int varFlags; /* Indicate if the variable is global,
- * namespace, or local */
+ int varFlags; /* Indicate if the variable is global,
+ * namespace, or local */
- int freeOnUnset; /* For backward compatibility only: If
+ int freeOnUnset; /* For backward compatibility only: If
* non-zero, free the vector when its variable
* is unset. */
- int flush;
+ int flush;
- int first, last; /* Selected region of vector. This is used
+ int first, last; /* Selected region of vector. This is used
* mostly for the math routines */
} Vector;
@@ -169,22 +169,22 @@ typedef struct {
* they are needed */
#define FindRange(array, first, last, min, max) \
-{ \
- min = max = 0.0; \
- if (first <= last) { \
- register int i; \
- min = max = array[first]; \
- for (i = first + 1; i <= last; i++) { \
- if (min > array[i]) { \
- min = array[i]; \
- } else if (max < array[i]) { \
- max = array[i]; \
- } \
- } \
- } \
-}
-
-extern const char *Blt_Itoa(int value);
+ { \
+ min = max = 0.0; \
+ if (first <= last) { \
+ register int i; \
+ min = max = array[first]; \
+ for (i = first + 1; i <= last; i++) { \
+ if (min > array[i]) { \
+ min = array[i]; \
+ } else if (max < array[i]) { \
+ max = array[i]; \
+ } \
+ } \
+ } \
+ }
+
+ extern const char *Blt_Itoa(int value);
extern void Blt_Vec_InstallSpecialIndices(Tcl_HashTable *tablePtr);
@@ -202,28 +202,28 @@ extern Vector *Blt_Vec_New(VectorInterpData *dataPtr);
extern int Blt_Vec_Duplicate(Vector *destPtr, Vector *srcPtr);
extern int Blt_Vec_SetLength(Tcl_Interp* interp, Vector *vPtr,
- int length);
+ int length);
extern int Blt_Vec_SetSize(Tcl_Interp* interp, Vector *vPtr,
- int size);
+ int size);
extern int Blt_Vec_ChangeLength(Tcl_Interp* interp, Vector *vPtr,
- int length);
+ int length);
extern Vector *Blt_Vec_ParseElement(Tcl_Interp* interp,
- VectorInterpData *dataPtr, const char *start, const char **endPtr,
- int flags);
+ VectorInterpData *dataPtr, const char *start, const char **endPtr,
+ int flags);
extern void Blt_Vec_Free(Vector *vPtr);
extern size_t *Blt_Vec_SortMap(Vector **vectors, int nVectors);
extern int Blt_Vec_LookupName(VectorInterpData *dataPtr,
- const char *vecName, Vector **vPtrPtr);
+ const char *vecName, Vector **vPtrPtr);
extern Vector *Blt_Vec_Create(VectorInterpData *dataPtr,
- const char *name, const char *cmdName, const char *varName,
- int *newPtr);
+ const char *name, const char *cmdName, const char *varName,
+ int *newPtr);
extern void Blt_Vec_UpdateRange(Vector *vPtr);
@@ -232,24 +232,24 @@ extern void Blt_Vec_UpdateClients(Vector *vPtr);
extern void Blt_Vec_FlushCache(Vector *vPtr);
extern int Blt_Vec_Reset(Vector *vPtr, double *dataArr,
- int nValues, int arraySize, Tcl_FreeProc *freeProc);
+ int nValues, int arraySize, Tcl_FreeProc *freeProc);
extern int Blt_Vec_GetIndex(Tcl_Interp* interp, Vector *vPtr,
- const char *string, int *indexPtr, int flags,
- Blt_VectorIndexProc **procPtrPtr);
+ const char *string, int *indexPtr, int flags,
+ Blt_VectorIndexProc **procPtrPtr);
extern int Blt_Vec_GetIndexRange(Tcl_Interp* interp, Vector *vPtr,
- const char *string, int flags, Blt_VectorIndexProc **procPtrPtr);
+ const char *string, int flags, Blt_VectorIndexProc **procPtrPtr);
extern int Blt_Vec_MapVariable(Tcl_Interp* interp, Vector *vPtr,
- const char *name);
+ const char *name);
extern int Blt_Vec_FFT(Tcl_Interp* interp, Vector *realPtr,
- Vector *phasesPtr, Vector *freqPtr, double delta,
- int flags, Vector *srcPtr);
+ Vector *phasesPtr, Vector *freqPtr, double delta,
+ int flags, Vector *srcPtr);
extern int Blt_Vec_InverseFFT(Tcl_Interp* interp, Vector *iSrcPtr,
- Vector *rDestPtr, Vector *iDestPtr, Vector *srcPtr);
+ Vector *rDestPtr, Vector *iDestPtr, Vector *srcPtr);
extern Tcl_ObjCmdProc Blt_Vec_InstCmd;
diff --git a/src/bltVecMath.C b/src/bltVecMath.C
index efe6a27..cdcb5e8 100644
--- a/src/bltVecMath.C
+++ b/src/bltVecMath.C
@@ -58,7 +58,7 @@ typedef double (ScalarProc)(Vector *vPtr);
/*
* Built-in math functions:
*/
-typedef int (GenericMathProc) ();
+typedef int (GenericMathProc) (void*, Tcl_Interp*, Vector*);
/*
* MathFunction --
@@ -69,16 +69,16 @@ typedef int (GenericMathProc) ();
* functions.
*/
typedef struct {
- const char *name; /* Name of built-in math function. If
+ const char *name; /* Name of built-in math function. If
* NULL, indicates that the function
* was user-defined and dynamically
* allocated. Function names are
* global across all interpreters. */
- void *proc; /* Procedure that implements this math
+ void *proc; /* Procedure that implements this math
* function. */
- ClientData clientData; /* Argument to pass when invoking the
+ ClientData clientData; /* Argument to pass when invoking the
* function. */
} MathFunction;
@@ -97,18 +97,18 @@ typedef struct {
* of types is important. Consult the code before changing it.
*/
enum Tokens {
- VALUE, OPEN_PAREN, CLOSE_PAREN, COMMA, END, UNKNOWN,
- MULT = 8, DIVIDE, MOD, PLUS, MINUS,
- LEFT_SHIFT, RIGHT_SHIFT,
- LESS, GREATER, LEQ, GEQ, EQUAL, NEQ,
- OLD_BIT_AND, EXPONENT, OLD_BIT_OR, OLD_QUESTY, OLD_COLON,
- AND, OR, UNARY_MINUS, OLD_UNARY_PLUS, NOT, OLD_BIT_NOT
+ VALUE, OPEN_PAREN, CLOSE_PAREN, COMMA, END, UNKNOWN,
+ MULT = 8, DIVIDE, MOD, PLUS, MINUS,
+ LEFT_SHIFT, RIGHT_SHIFT,
+ LESS, GREATER, LEQ, GEQ, EQUAL, NEQ,
+ OLD_BIT_AND, EXPONENT, OLD_BIT_OR, OLD_QUESTY, OLD_COLON,
+ AND, OR, UNARY_MINUS, OLD_UNARY_PLUS, NOT, OLD_BIT_NOT
};
typedef struct {
- Vector *vPtr;
- char staticSpace[STATIC_STRING_SPACE];
- ParseValue pv; /* Used to hold a string value, if any. */
+ Vector *vPtr;
+ char staticSpace[STATIC_STRING_SPACE];
+ ParseValue pv; /* Used to hold a string value, if any. */
} Value;
/*
@@ -118,15 +118,15 @@ typedef struct {
* expression. It's passed among the routines in this module.
*/
typedef struct {
- const char *expr; /* The entire right-hand side of the
+ const char *expr; /* The entire right-hand side of the
* expression, as originally passed to
* Blt_ExprVector. */
- const char *nextPtr; /* Position of the next character to
- * be scanned from the expression
- * string. */
+ const char *nextPtr; /* Position of the next character to
+ * be scanned from the expression
+ * string. */
- enum Tokens token; /* Type of the last token to be parsed
+ enum Tokens token; /* Type of the last token to be parsed
* from nextPtr. See below for
* definitions. Corresponds to the
* characters just before nextPtr. */
@@ -137,7 +137,7 @@ typedef struct {
* Precedence table. The values for non-operator token types are ignored.
*/
static int precTable[] =
-{
+ {
0, 0, 0, 0, 0, 0, 0, 0,
12, 12, 12, /* MULT, DIVIDE, MOD */
11, 11, /* PLUS, MINUS */
@@ -153,7 +153,7 @@ static int precTable[] =
1, /* OLD_COLON */
14, 14, 14, 14 /* UNARY_MINUS, OLD_UNARY_PLUS, NOT,
* OLD_BIT_NOT */
-};
+ };
/*
@@ -161,7 +161,7 @@ static int precTable[] =
*/
static int NextValue(Tcl_Interp* interp, ParseInfo *piPtr, int prec,
- Value *valuePtr);
+ Value *valuePtr);
/*
*---------------------------------------------------------------------------
@@ -182,100 +182,100 @@ static int NextValue(Tcl_Interp* interp, ParseInfo *piPtr, int prec,
static int
Sort(Vector *vPtr)
{
- size_t *map;
- double *values;
- int i;
-
- map = Blt_Vec_SortMap(&vPtr, 1);
- values = malloc(sizeof(double) * vPtr->length);
- for(i = vPtr->first; i <= vPtr->last; i++) {
- values[i] = vPtr->valueArr[map[i]];
- }
- free(map);
- for (i = vPtr->first; i <= vPtr->last; i++) {
- vPtr->valueArr[i] = values[i];
- }
- free(values);
- return TCL_OK;
+ size_t *map;
+ double *values;
+ int i;
+
+ map = Blt_Vec_SortMap(&vPtr, 1);
+ values = (double*)malloc(sizeof(double) * vPtr->length);
+ for(i = vPtr->first; i <= vPtr->last; i++) {
+ values[i] = vPtr->valueArr[map[i]];
+ }
+ free(map);
+ for (i = vPtr->first; i <= vPtr->last; i++) {
+ vPtr->valueArr[i] = values[i];
+ }
+ free(values);
+ return TCL_OK;
}
static double
Length(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
+ Vector *vPtr = (Vector *)vectorPtr;
- return (double)(vPtr->last - vPtr->first + 1);
+ return (double)(vPtr->last - vPtr->first + 1);
}
double
Blt_VecMax(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
+ Vector *vPtr = (Vector *)vectorPtr;
- return Blt_Vec_Max(vPtr);
+ return Blt_Vec_Max(vPtr);
}
double
Blt_VecMin(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
+ Vector *vPtr = (Vector *)vectorPtr;
- return Blt_Vec_Min(vPtr);
+ return Blt_Vec_Min(vPtr);
}
static double
Product(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double prod;
- double *vp, *vend;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double prod;
+ double *vp, *vend;
- prod = 1.0;
- for(vp = vPtr->valueArr + vPtr->first,
- vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- prod *= *vp;
- }
- return prod;
+ prod = 1.0;
+ for(vp = vPtr->valueArr + vPtr->first,
+ vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ prod *= *vp;
+ }
+ return prod;
}
static double
Sum(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double sum, c;
- double *vp, *vend;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double sum, c;
+ double *vp, *vend;
- /* Kahan summation algorithm */
+ /* Kahan summation algorithm */
- vp = vPtr->valueArr + vPtr->first;
- sum = *vp++;
- c = 0.0; /* A running compensation for lost
+ vp = vPtr->valueArr + vPtr->first;
+ sum = *vp++;
+ c = 0.0; /* A running compensation for lost
* low-order bits.*/
- for (vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- double y, t;
+ for (vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ double y, t;
- y = *vp - c; /* So far, so good: c is zero.*/
- t = sum + y; /* Alas, sum is big, y small, so
+ y = *vp - c; /* So far, so good: c is zero.*/
+ t = sum + y; /* Alas, sum is big, y small, so
* low-order digits of y are lost.*/
- c = (t - sum) - y; /* (t - sum) recovers the high-order
- * part of y; subtracting y recovers
- * -(low part of y) */
- sum = t;
- }
- return sum;
+ c = (t - sum) - y; /* (t - sum) recovers the high-order
+ * part of y; subtracting y recovers
+ * -(low part of y) */
+ sum = t;
+ }
+ return sum;
}
static double
Mean(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double sum;
- int n;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double sum;
+ int n;
- sum = Sum(vectorPtr);
- n = vPtr->last - vPtr->first + 1;
- return sum / (double)n;
+ sum = Sum(vectorPtr);
+ n = vPtr->last - vPtr->first + 1;
+ return sum / (double)n;
}
/*
@@ -284,27 +284,27 @@ Mean(Blt_Vector *vectorPtr)
static double
Variance(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double var, mean;
- double *vp, *vend;
- int count;
-
- mean = Mean(vectorPtr);
- var = 0.0;
- count = 0;
- for(vp = vPtr->valueArr + vPtr->first,
+ Vector *vPtr = (Vector *)vectorPtr;
+ double var, mean;
+ double *vp, *vend;
+ int count;
+
+ mean = Mean(vectorPtr);
+ var = 0.0;
+ count = 0;
+ for(vp = vPtr->valueArr + vPtr->first,
vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- double dx;
+ double dx;
- dx = *vp - mean;
- var += dx * dx;
- count++;
- }
- if (count < 2) {
- return 0.0;
- }
- var /= (double)(count - 1);
- return var;
+ dx = *vp - mean;
+ var += dx * dx;
+ count++;
+ }
+ if (count < 2) {
+ return 0.0;
+ }
+ var /= (double)(count - 1);
+ return var;
}
/*
@@ -313,264 +313,264 @@ Variance(Blt_Vector *vectorPtr)
static double
Skew(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double diff, var, skew, mean, diffsq;
- double *vp, *vend;
- int count;
-
- mean = Mean(vectorPtr);
- var = skew = 0.0;
- count = 0;
- for(vp = vPtr->valueArr + vPtr->first,
- vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- diff = *vp - mean;
- diff = fabs(diff);
- diffsq = diff * diff;
- var += diffsq;
- skew += diffsq * diff;
- count++;
- }
- if (count < 2) {
- return 0.0;
- }
- var /= (double)(count - 1);
- skew /= count * var * sqrt(var);
- return skew;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double diff, var, skew, mean, diffsq;
+ double *vp, *vend;
+ int count;
+
+ mean = Mean(vectorPtr);
+ var = skew = 0.0;
+ count = 0;
+ for(vp = vPtr->valueArr + vPtr->first,
+ vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ diff = *vp - mean;
+ diff = fabs(diff);
+ diffsq = diff * diff;
+ var += diffsq;
+ skew += diffsq * diff;
+ count++;
+ }
+ if (count < 2) {
+ return 0.0;
+ }
+ var /= (double)(count - 1);
+ skew /= count * var * sqrt(var);
+ return skew;
}
static double
StdDeviation(Blt_Vector *vectorPtr)
{
- double var;
+ double var;
- var = Variance(vectorPtr);
- if (var > 0.0) {
- return sqrt(var);
- }
- return 0.0;
+ var = Variance(vectorPtr);
+ if (var > 0.0) {
+ return sqrt(var);
+ }
+ return 0.0;
}
static double
AvgDeviation(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double diff, avg, mean;
- double *vp, *vend;
- int count;
-
- mean = Mean(vectorPtr);
- avg = 0.0;
- count = 0;
- for(vp = vPtr->valueArr + vPtr->first,
- vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- diff = *vp - mean;
- avg += fabs(diff);
- count++;
- }
- if (count < 2) {
- return 0.0;
- }
- avg /= (double)count;
- return avg;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double diff, avg, mean;
+ double *vp, *vend;
+ int count;
+
+ mean = Mean(vectorPtr);
+ avg = 0.0;
+ count = 0;
+ for(vp = vPtr->valueArr + vPtr->first,
+ vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ diff = *vp - mean;
+ avg += fabs(diff);
+ count++;
+ }
+ if (count < 2) {
+ return 0.0;
+ }
+ avg /= (double)count;
+ return avg;
}
static double
Kurtosis(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double diff, diffsq, kurt, var, mean;
- double *vp, *vend;
- int count;
-
- mean = Mean(vectorPtr);
- var = kurt = 0.0;
- count = 0;
- for(vp = vPtr->valueArr + vPtr->first,
- vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- diff = *vp - mean;
- diffsq = diff * diff;
- var += diffsq;
- kurt += diffsq * diffsq;
- count++;
- }
- if (count < 2) {
- return 0.0;
- }
- var /= (double)(count - 1);
- if (var == 0.0) {
- return 0.0;
- }
- kurt /= (count * var * var);
- return kurt - 3.0; /* Fisher Kurtosis */
+ Vector *vPtr = (Vector *)vectorPtr;
+ double diff, diffsq, kurt, var, mean;
+ double *vp, *vend;
+ int count;
+
+ mean = Mean(vectorPtr);
+ var = kurt = 0.0;
+ count = 0;
+ for(vp = vPtr->valueArr + vPtr->first,
+ vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ diff = *vp - mean;
+ diffsq = diff * diff;
+ var += diffsq;
+ kurt += diffsq * diffsq;
+ count++;
+ }
+ if (count < 2) {
+ return 0.0;
+ }
+ var /= (double)(count - 1);
+ if (var == 0.0) {
+ return 0.0;
+ }
+ kurt /= (count * var * var);
+ return kurt - 3.0; /* Fisher Kurtosis */
}
static double
Median(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- size_t *map;
- double q2;
- int mid;
-
- if (vPtr->length == 0) {
- return -DBL_MAX;
- }
- map = Blt_Vec_SortMap(&vPtr, 1);
- mid = (vPtr->length - 1) / 2;
-
- /*
- * Determine Q2 by checking if the number of elements [0..n-1] is
- * odd or even. If even, we must take the average of the two
- * middle values.
- */
- if (vPtr->length & 1) { /* Odd */
- q2 = vPtr->valueArr[map[mid]];
- } else { /* Even */
- q2 = (vPtr->valueArr[map[mid]] +
- vPtr->valueArr[map[mid + 1]]) * 0.5;
- }
- free(map);
- return q2;
+ Vector *vPtr = (Vector *)vectorPtr;
+ size_t *map;
+ double q2;
+ int mid;
+
+ if (vPtr->length == 0) {
+ return -DBL_MAX;
+ }
+ map = Blt_Vec_SortMap(&vPtr, 1);
+ mid = (vPtr->length - 1) / 2;
+
+ /*
+ * Determine Q2 by checking if the number of elements [0..n-1] is
+ * odd or even. If even, we must take the average of the two
+ * middle values.
+ */
+ if (vPtr->length & 1) { /* Odd */
+ q2 = vPtr->valueArr[map[mid]];
+ } else { /* Even */
+ q2 = (vPtr->valueArr[map[mid]] +
+ vPtr->valueArr[map[mid + 1]]) * 0.5;
+ }
+ free(map);
+ return q2;
}
static double
Q1(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double q1;
- size_t *map;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double q1;
+ size_t *map;
- if (vPtr->length == 0) {
- return -DBL_MAX;
- }
- map = Blt_Vec_SortMap(&vPtr, 1);
+ if (vPtr->length == 0) {
+ return -DBL_MAX;
+ }
+ map = Blt_Vec_SortMap(&vPtr, 1);
- if (vPtr->length < 4) {
- q1 = vPtr->valueArr[map[0]];
- } else {
- int mid, q;
-
- mid = (vPtr->length - 1) / 2;
- q = mid / 2;
-
- /*
- * Determine Q1 by checking if the number of elements in the
- * bottom half [0..mid) is odd or even. If even, we must
- * take the average of the two middle values.
- */
- if (mid & 1) { /* Odd */
- q1 = vPtr->valueArr[map[q]];
- } else { /* Even */
- q1 = (vPtr->valueArr[map[q]] +
- vPtr->valueArr[map[q + 1]]) * 0.5;
- }
+ if (vPtr->length < 4) {
+ q1 = vPtr->valueArr[map[0]];
+ } else {
+ int mid, q;
+
+ mid = (vPtr->length - 1) / 2;
+ q = mid / 2;
+
+ /*
+ * Determine Q1 by checking if the number of elements in the
+ * bottom half [0..mid) is odd or even. If even, we must
+ * take the average of the two middle values.
+ */
+ if (mid & 1) { /* Odd */
+ q1 = vPtr->valueArr[map[q]];
+ } else { /* Even */
+ q1 = (vPtr->valueArr[map[q]] +
+ vPtr->valueArr[map[q + 1]]) * 0.5;
}
- free(map);
- return q1;
+ }
+ free(map);
+ return q1;
}
static double
Q3(Blt_Vector *vectorPtr)
{
- Vector *vPtr = (Vector *)vectorPtr;
- double q3;
- size_t *map;
+ Vector *vPtr = (Vector *)vectorPtr;
+ double q3;
+ size_t *map;
- if (vPtr->length == 0) {
- return -DBL_MAX;
- }
+ if (vPtr->length == 0) {
+ return -DBL_MAX;
+ }
- map = Blt_Vec_SortMap(&vPtr, 1);
+ map = Blt_Vec_SortMap(&vPtr, 1);
- if (vPtr->length < 4) {
- q3 = vPtr->valueArr[map[vPtr->length - 1]];
- } else {
- int mid, q;
-
- mid = (vPtr->length - 1) / 2;
- q = (vPtr->length + mid) / 2;
-
- /*
- * Determine Q3 by checking if the number of elements in the
- * upper half (mid..n-1] is odd or even. If even, we must
- * take the average of the two middle values.
- */
- if (mid & 1) { /* Odd */
- q3 = vPtr->valueArr[map[q]];
- } else { /* Even */
- q3 = (vPtr->valueArr[map[q]] +
- vPtr->valueArr[map[q + 1]]) * 0.5;
- }
+ if (vPtr->length < 4) {
+ q3 = vPtr->valueArr[map[vPtr->length - 1]];
+ } else {
+ int mid, q;
+
+ mid = (vPtr->length - 1) / 2;
+ q = (vPtr->length + mid) / 2;
+
+ /*
+ * Determine Q3 by checking if the number of elements in the
+ * upper half (mid..n-1] is odd or even. If even, we must
+ * take the average of the two middle values.
+ */
+ if (mid & 1) { /* Odd */
+ q3 = vPtr->valueArr[map[q]];
+ } else { /* Even */
+ q3 = (vPtr->valueArr[map[q]] +
+ vPtr->valueArr[map[q + 1]]) * 0.5;
}
- free(map);
- return q3;
+ }
+ free(map);
+ return q3;
}
static int
Norm(Blt_Vector *vector)
{
- Vector *vPtr = (Vector *)vector;
- double norm, range, min, max;
- int i;
-
- min = Blt_Vec_Min(vPtr);
- max = Blt_Vec_Max(vPtr);
- range = max - min;
- for (i = 0; i < vPtr->length; i++) {
- norm = (vPtr->valueArr[i] - min) / range;
- vPtr->valueArr[i] = norm;
- }
- return TCL_OK;
+ Vector *vPtr = (Vector *)vector;
+ double norm, range, min, max;
+ int i;
+
+ min = Blt_Vec_Min(vPtr);
+ max = Blt_Vec_Max(vPtr);
+ range = max - min;
+ for (i = 0; i < vPtr->length; i++) {
+ norm = (vPtr->valueArr[i] - min) / range;
+ vPtr->valueArr[i] = norm;
+ }
+ return TCL_OK;
}
static double
Nonzeros(Blt_Vector *vector)
{
- Vector *vPtr = (Vector *)vector;
- int count;
- double *vp, *vend;
+ Vector *vPtr = (Vector *)vector;
+ int count;
+ double *vp, *vend;
- count = 0;
- for(vp = vPtr->valueArr + vPtr->first,
- vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- if (*vp == 0.0) {
- count++;
- }
+ count = 0;
+ for(vp = vPtr->valueArr + vPtr->first,
+ vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ if (*vp == 0.0) {
+ count++;
}
- return (double) count;
+ }
+ return (double) count;
}
static double
Fabs(double value)
{
- if (value < 0.0) {
- return -value;
- }
- return value;
+ if (value < 0.0) {
+ return -value;
+ }
+ return value;
}
static double
Round(double value)
{
- if (value < 0.0) {
- return ceil(value - 0.5);
- } else {
- return floor(value + 0.5);
- }
+ if (value < 0.0) {
+ return ceil(value - 0.5);
+ } else {
+ return floor(value + 0.5);
+ }
}
static double
Fmod(double x, double y)
{
- if (y == 0.0) {
- return 0.0;
- }
- return x - (floor(x / y) * y);
+ if (y == 0.0) {
+ return 0.0;
+ }
+ return x - (floor(x / y) * y);
}
/*
@@ -592,36 +592,36 @@ Fmod(double x, double y)
*/
static void
MathError(
- Tcl_Interp* interp, /* Where to store error message. */
- double value) /* Value returned after error; used to
+ Tcl_Interp* interp, /* Where to store error message. */
+ double value) /* Value returned after error; used to
* distinguish underflows from
* overflows. */
{
- if ((errno == EDOM) || (value != value)) {
- Tcl_AppendResult(interp, "domain error: argument not in valid range",
- (char *)NULL);
- Tcl_SetErrorCode(interp, "ARITH", "DOMAIN",
- Tcl_GetStringResult(interp), (char *)NULL);
- } else if ((errno == ERANGE) || isinf(value)) {
- if (value == 0.0) {
- Tcl_AppendResult(interp,
- "floating-point value too small to represent",
- (char *)NULL);
- Tcl_SetErrorCode(interp, "ARITH", "UNDERFLOW",
- Tcl_GetStringResult(interp), (char *)NULL);
- } else {
- Tcl_AppendResult(interp,
- "floating-point value too large to represent",
- (char *)NULL);
- Tcl_SetErrorCode(interp, "ARITH", "OVERFLOW",
- Tcl_GetStringResult(interp), (char *)NULL);
- }
+ if ((errno == EDOM) || (value != value)) {
+ Tcl_AppendResult(interp, "domain error: argument not in valid range",
+ (char *)NULL);
+ Tcl_SetErrorCode(interp, "ARITH", "DOMAIN",
+ Tcl_GetStringResult(interp), (char *)NULL);
+ } else if ((errno == ERANGE) || isinf(value)) {
+ if (value == 0.0) {
+ Tcl_AppendResult(interp,
+ "floating-point value too small to represent",
+ (char *)NULL);
+ Tcl_SetErrorCode(interp, "ARITH", "UNDERFLOW",
+ Tcl_GetStringResult(interp), (char *)NULL);
} else {
- Tcl_AppendResult(interp, "unknown floating-point error, ",
- "errno = ", Blt_Itoa(errno), (char *)NULL);
- Tcl_SetErrorCode(interp, "ARITH", "UNKNOWN",
- Tcl_GetStringResult(interp), (char *)NULL);
+ Tcl_AppendResult(interp,
+ "floating-point value too large to represent",
+ (char *)NULL);
+ Tcl_SetErrorCode(interp, "ARITH", "OVERFLOW",
+ Tcl_GetStringResult(interp), (char *)NULL);
}
+ } else {
+ Tcl_AppendResult(interp, "unknown floating-point error, ",
+ "errno = ", Blt_Itoa(errno), (char *)NULL);
+ Tcl_SetErrorCode(interp, "ARITH", "UNKNOWN",
+ Tcl_GetStringResult(interp), (char *)NULL);
+ }
}
/*
@@ -648,55 +648,55 @@ MathError(
static int
ParseString(
- Tcl_Interp* interp, /* Where to store error message. */
- const char *string, /* String to turn into value. */
- Value *valuePtr) /* Where to store value information.
- * Caller must have initialized pv field. */
+ Tcl_Interp* interp, /* Where to store error message. */
+ const char *string, /* String to turn into value. */
+ Value *valuePtr) /* Where to store value information.
+ * Caller must have initialized pv field. */
{
- const char *endPtr;
- double value;
-
- errno = 0;
+ const char *endPtr;
+ double value;
- /*
- * The string can be either a number or a vector. First try to
- * convert the string to a number. If that fails then see if
- * we can find a vector by that name.
- */
+ errno = 0;
- value = strtod(string, (char **)&endPtr);
- if ((endPtr != string) && (*endPtr == '\0')) {
- if (errno != 0) {
- Tcl_ResetResult(interp);
- MathError(interp, value);
- return TCL_ERROR;
- }
- /* Numbers are stored as single element vectors. */
- if (Blt_Vec_ChangeLength(interp, valuePtr->vPtr, 1) != TCL_OK) {
- return TCL_ERROR;
- }
- valuePtr->vPtr->valueArr[0] = value;
- return TCL_OK;
- } else {
- Vector *vPtr;
+ /*
+ * The string can be either a number or a vector. First try to
+ * convert the string to a number. If that fails then see if
+ * we can find a vector by that name.
+ */
- while (isspace((unsigned char)(*string))) {
- string++; /* Skip spaces leading the vector name. */
- }
- vPtr = Blt_Vec_ParseElement(interp, valuePtr->vPtr->dataPtr,
- string, &endPtr, NS_SEARCH_BOTH);
- if (vPtr == NULL) {
- return TCL_ERROR;
- }
- if (*endPtr != '\0') {
- Tcl_AppendResult(interp, "extra characters after vector",
- (char *)NULL);
- return TCL_ERROR;
- }
- /* Copy the designated vector to our temporary. */
- Blt_Vec_Duplicate(valuePtr->vPtr, vPtr);
+ value = strtod(string, (char **)&endPtr);
+ if ((endPtr != string) && (*endPtr == '\0')) {
+ if (errno != 0) {
+ Tcl_ResetResult(interp);
+ MathError(interp, value);
+ return TCL_ERROR;
+ }
+ /* Numbers are stored as single element vectors. */
+ if (Blt_Vec_ChangeLength(interp, valuePtr->vPtr, 1) != TCL_OK) {
+ return TCL_ERROR;
}
+ valuePtr->vPtr->valueArr[0] = value;
return TCL_OK;
+ } else {
+ Vector *vPtr;
+
+ while (isspace((unsigned char)(*string))) {
+ string++; /* Skip spaces leading the vector name. */
+ }
+ vPtr = Blt_Vec_ParseElement(interp, valuePtr->vPtr->dataPtr,
+ string, &endPtr, NS_SEARCH_BOTH);
+ if (vPtr == NULL) {
+ return TCL_ERROR;
+ }
+ if (*endPtr != '\0') {
+ Tcl_AppendResult(interp, "extra characters after vector",
+ (char *)NULL);
+ return TCL_ERROR;
+ }
+ /* Copy the designated vector to our temporary. */
+ Blt_Vec_Duplicate(valuePtr->vPtr, vPtr);
+ }
+ return TCL_OK;
}
/*
@@ -726,64 +726,64 @@ ParseString(
*/
static int
ParseMathFunction(
- Tcl_Interp* interp, /* Interpreter to use for error reporting. */
- const char *start, /* Start of string to parse */
- ParseInfo *piPtr, /* Describes the state of the parse.
- * piPtr->nextPtr must point to the
- * first character of the function's
- * name. */
- Value *valuePtr) /* Where to store value, if that is
- * what's parsed from string. Caller
- * must have initialized pv field
- * correctly. */
+ Tcl_Interp* interp, /* Interpreter to use for error reporting. */
+ const char *start, /* Start of string to parse */
+ ParseInfo *piPtr, /* Describes the state of the parse.
+ * piPtr->nextPtr must point to the
+ * first character of the function's
+ * name. */
+ Value *valuePtr) /* Where to store value, if that is
+ * what's parsed from string. Caller
+ * must have initialized pv field
+ * correctly. */
{
- Tcl_HashEntry *hPtr;
- MathFunction *mathPtr; /* Info about math function. */
- char *p;
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- GenericMathProc *proc;
-
- /*
- * Find the end of the math function's name and lookup the
- * record for the function.
- */
- p = (char *)start;
- while (isspace((unsigned char)(*p))) {
- p++;
- }
- piPtr->nextPtr = p;
- while (isalnum((unsigned char)(*p)) || (*p == '_')) {
- p++;
- }
- if (*p != '(') {
- return TCL_RETURN; /* Must start with open parenthesis */
- }
- dataPtr = valuePtr->vPtr->dataPtr;
- *p = '\0';
- hPtr = Tcl_FindHashEntry(&dataPtr->mathProcTable, piPtr->nextPtr);
- *p = '(';
- if (hPtr == NULL) {
- return TCL_RETURN; /* Name doesn't match any known function */
- }
- /* Pick up the single value as the argument to the function */
- piPtr->token = OPEN_PAREN;
- piPtr->nextPtr = p + 1;
- valuePtr->pv.next = valuePtr->pv.buffer;
- if (NextValue(interp, piPtr, -1, valuePtr) != TCL_OK) {
- return TCL_ERROR; /* Parse error */
- }
- if (piPtr->token != CLOSE_PAREN) {
- Tcl_AppendResult(interp, "unmatched parentheses in expression \"",
- piPtr->expr, "\"", (char *)NULL);
- return TCL_ERROR; /* Missing right parenthesis */
- }
- mathPtr = Tcl_GetHashValue(hPtr);
- proc = mathPtr->proc;
- if ((*proc) (mathPtr->clientData, interp, valuePtr->vPtr) != TCL_OK) {
- return TCL_ERROR; /* Function invocation error */
- }
- piPtr->token = VALUE;
- return TCL_OK;
+ Tcl_HashEntry *hPtr;
+ MathFunction *mathPtr; /* Info about math function. */
+ char *p;
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ GenericMathProc *proc;
+
+ /*
+ * Find the end of the math function's name and lookup the
+ * record for the function.
+ */
+ p = (char *)start;
+ while (isspace((unsigned char)(*p))) {
+ p++;
+ }
+ piPtr->nextPtr = p;
+ while (isalnum((unsigned char)(*p)) || (*p == '_')) {
+ p++;
+ }
+ if (*p != '(') {
+ return TCL_RETURN; /* Must start with open parenthesis */
+ }
+ dataPtr = valuePtr->vPtr->dataPtr;
+ *p = '\0';
+ hPtr = Tcl_FindHashEntry(&dataPtr->mathProcTable, piPtr->nextPtr);
+ *p = '(';
+ if (hPtr == NULL) {
+ return TCL_RETURN; /* Name doesn't match any known function */
+ }
+ /* Pick up the single value as the argument to the function */
+ piPtr->token = OPEN_PAREN;
+ piPtr->nextPtr = p + 1;
+ valuePtr->pv.next = valuePtr->pv.buffer;
+ if (NextValue(interp, piPtr, -1, valuePtr) != TCL_OK) {
+ return TCL_ERROR; /* Parse error */
+ }
+ if (piPtr->token != CLOSE_PAREN) {
+ Tcl_AppendResult(interp, "unmatched parentheses in expression \"",
+ piPtr->expr, "\"", (char *)NULL);
+ return TCL_ERROR; /* Missing right parenthesis */
+ }
+ mathPtr = (MathFunction*)Tcl_GetHashValue(hPtr);
+ proc = (GenericMathProc*)mathPtr->proc;
+ if ((*proc) (mathPtr->clientData, interp, valuePtr->vPtr) != TCL_OK) {
+ return TCL_ERROR; /* Function invocation error */
+ }
+ piPtr->token = VALUE;
+ return TCL_OK;
}
/*
@@ -811,228 +811,228 @@ ParseMathFunction(
*/
static int
NextToken(
- Tcl_Interp* interp, /* Interpreter to use for error reporting. */
- ParseInfo *piPtr, /* Describes the state of the parse. */
- Value *valuePtr) /* Where to store value, if that is
- * what's parsed from string. Caller
- * must have initialized pv field
- * correctly. */
+ Tcl_Interp* interp, /* Interpreter to use for error reporting. */
+ ParseInfo *piPtr, /* Describes the state of the parse. */
+ Value *valuePtr) /* Where to store value, if that is
+ * what's parsed from string. Caller
+ * must have initialized pv field
+ * correctly. */
{
- const char *p;
- const char *endPtr;
- const char *var;
- int result;
-
- p = piPtr->nextPtr;
- while (isspace((unsigned char)(*p))) {
- p++;
+ const char *p;
+ const char *endPtr;
+ const char *var;
+ int result;
+
+ p = piPtr->nextPtr;
+ while (isspace((unsigned char)(*p))) {
+ p++;
+ }
+ if (*p == '\0') {
+ piPtr->token = END;
+ piPtr->nextPtr = p;
+ return TCL_OK;
+ }
+ /*
+ * Try to parse the token as a floating-point number. But check
+ * that the first character isn't a "-" or "+", which "strtod"
+ * will happily accept as an unary operator. Otherwise, we might
+ * accidently treat a binary operator as unary by mistake, which
+ * will eventually cause a syntax error.
+ */
+ if ((*p != '-') && (*p != '+')) {
+ double value;
+
+ errno = 0;
+ value = strtod(p, (char **)&endPtr);
+ if (endPtr != p) {
+ if (errno != 0) {
+ MathError(interp, value);
+ return TCL_ERROR;
+ }
+ piPtr->token = VALUE;
+ piPtr->nextPtr = endPtr;
+
+ /*
+ * Save the single floating-point value as an 1-component vector.
+ */
+ if (Blt_Vec_ChangeLength(interp, valuePtr->vPtr, 1) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ valuePtr->vPtr->valueArr[0] = value;
+ return TCL_OK;
}
- if (*p == '\0') {
- piPtr->token = END;
- piPtr->nextPtr = p;
- return TCL_OK;
+ }
+ piPtr->nextPtr = p + 1;
+ switch (*p) {
+ case '$':
+ piPtr->token = VALUE;
+ var = Tcl_ParseVar(interp, p, &endPtr);
+ if (var == NULL) {
+ return TCL_ERROR;
}
- /*
- * Try to parse the token as a floating-point number. But check
- * that the first character isn't a "-" or "+", which "strtod"
- * will happily accept as an unary operator. Otherwise, we might
- * accidently treat a binary operator as unary by mistake, which
- * will eventually cause a syntax error.
- */
- if ((*p != '-') && (*p != '+')) {
- double value;
-
- errno = 0;
- value = strtod(p, (char **)&endPtr);
- if (endPtr != p) {
- if (errno != 0) {
- MathError(interp, value);
- return TCL_ERROR;
- }
- piPtr->token = VALUE;
- piPtr->nextPtr = endPtr;
-
- /*
- * Save the single floating-point value as an 1-component vector.
- */
- if (Blt_Vec_ChangeLength(interp, valuePtr->vPtr, 1) != TCL_OK) {
- return TCL_ERROR;
- }
- valuePtr->vPtr->valueArr[0] = value;
- return TCL_OK;
- }
+ piPtr->nextPtr = endPtr;
+ Tcl_ResetResult(interp);
+ result = ParseString(interp, var, valuePtr);
+ return result;
+
+ case '[':
+ piPtr->token = VALUE;
+ result = Blt_ParseNestedCmd(interp, p + 1, 0, &endPtr, &valuePtr->pv);
+ if (result != TCL_OK) {
+ return result;
}
- piPtr->nextPtr = p + 1;
- switch (*p) {
- case '$':
- piPtr->token = VALUE;
- var = Tcl_ParseVar(interp, p, &endPtr);
- if (var == NULL) {
- return TCL_ERROR;
- }
- piPtr->nextPtr = endPtr;
- Tcl_ResetResult(interp);
- result = ParseString(interp, var, valuePtr);
- return result;
-
- case '[':
- piPtr->token = VALUE;
- result = Blt_ParseNestedCmd(interp, p + 1, 0, &endPtr, &valuePtr->pv);
- if (result != TCL_OK) {
- return result;
- }
- piPtr->nextPtr = endPtr;
- Tcl_ResetResult(interp);
- result = ParseString(interp, valuePtr->pv.buffer, valuePtr);
- return result;
-
- case '"':
- piPtr->token = VALUE;
- result = Blt_ParseQuotes(interp, p + 1, '"', 0, &endPtr, &valuePtr->pv);
- if (result != TCL_OK) {
- return result;
- }
- piPtr->nextPtr = endPtr;
- Tcl_ResetResult(interp);
- result = ParseString(interp, valuePtr->pv.buffer, valuePtr);
- return result;
-
- case '{':
- piPtr->token = VALUE;
- result = Blt_ParseBraces(interp, p + 1, &endPtr, &valuePtr->pv);
- if (result != TCL_OK) {
- return result;
- }
- piPtr->nextPtr = endPtr;
- Tcl_ResetResult(interp);
- result = ParseString(interp, valuePtr->pv.buffer, valuePtr);
- return result;
+ piPtr->nextPtr = endPtr;
+ Tcl_ResetResult(interp);
+ result = ParseString(interp, valuePtr->pv.buffer, valuePtr);
+ return result;
- case '(':
- piPtr->token = OPEN_PAREN;
- break;
+ case '"':
+ piPtr->token = VALUE;
+ result = Blt_ParseQuotes(interp, p + 1, '"', 0, &endPtr, &valuePtr->pv);
+ if (result != TCL_OK) {
+ return result;
+ }
+ piPtr->nextPtr = endPtr;
+ Tcl_ResetResult(interp);
+ result = ParseString(interp, valuePtr->pv.buffer, valuePtr);
+ return result;
- case ')':
- piPtr->token = CLOSE_PAREN;
- break;
+ case '{':
+ piPtr->token = VALUE;
+ result = Blt_ParseBraces(interp, p + 1, &endPtr, &valuePtr->pv);
+ if (result != TCL_OK) {
+ return result;
+ }
+ piPtr->nextPtr = endPtr;
+ Tcl_ResetResult(interp);
+ result = ParseString(interp, valuePtr->pv.buffer, valuePtr);
+ return result;
- case ',':
- piPtr->token = COMMA;
- break;
+ case '(':
+ piPtr->token = OPEN_PAREN;
+ break;
- case '*':
- piPtr->token = MULT;
- break;
+ case ')':
+ piPtr->token = CLOSE_PAREN;
+ break;
- case '/':
- piPtr->token = DIVIDE;
- break;
+ case ',':
+ piPtr->token = COMMA;
+ break;
- case '%':
- piPtr->token = MOD;
- break;
+ case '*':
+ piPtr->token = MULT;
+ break;
- case '+':
- piPtr->token = PLUS;
- break;
+ case '/':
+ piPtr->token = DIVIDE;
+ break;
- case '-':
- piPtr->token = MINUS;
- break;
+ case '%':
+ piPtr->token = MOD;
+ break;
- case '^':
- piPtr->token = EXPONENT;
- break;
+ case '+':
+ piPtr->token = PLUS;
+ break;
+
+ case '-':
+ piPtr->token = MINUS;
+ break;
+ case '^':
+ piPtr->token = EXPONENT;
+ break;
+
+ case '<':
+ switch (*(p + 1)) {
case '<':
- switch (*(p + 1)) {
- case '<':
- piPtr->nextPtr = p + 2;
- piPtr->token = LEFT_SHIFT;
- break;
- case '=':
- piPtr->nextPtr = p + 2;
- piPtr->token = LEQ;
- break;
- default:
- piPtr->token = LESS;
- break;
- }
- break;
+ piPtr->nextPtr = p + 2;
+ piPtr->token = LEFT_SHIFT;
+ break;
+ case '=':
+ piPtr->nextPtr = p + 2;
+ piPtr->token = LEQ;
+ break;
+ default:
+ piPtr->token = LESS;
+ break;
+ }
+ break;
+ case '>':
+ switch (*(p + 1)) {
case '>':
- switch (*(p + 1)) {
- case '>':
- piPtr->nextPtr = p + 2;
- piPtr->token = RIGHT_SHIFT;
- break;
- case '=':
- piPtr->nextPtr = p + 2;
- piPtr->token = GEQ;
- break;
- default:
- piPtr->token = GREATER;
- break;
- }
- break;
-
+ piPtr->nextPtr = p + 2;
+ piPtr->token = RIGHT_SHIFT;
+ break;
case '=':
- if (*(p + 1) == '=') {
- piPtr->nextPtr = p + 2;
- piPtr->token = EQUAL;
- } else {
- piPtr->token = UNKNOWN;
- }
- break;
+ piPtr->nextPtr = p + 2;
+ piPtr->token = GEQ;
+ break;
+ default:
+ piPtr->token = GREATER;
+ break;
+ }
+ break;
- case '&':
- if (*(p + 1) == '&') {
- piPtr->nextPtr = p + 2;
- piPtr->token = AND;
- } else {
- piPtr->token = UNKNOWN;
- }
- break;
+ case '=':
+ if (*(p + 1) == '=') {
+ piPtr->nextPtr = p + 2;
+ piPtr->token = EQUAL;
+ } else {
+ piPtr->token = UNKNOWN;
+ }
+ break;
- case '|':
- if (*(p + 1) == '|') {
- piPtr->nextPtr = p + 2;
- piPtr->token = OR;
- } else {
- piPtr->token = UNKNOWN;
- }
- break;
+ case '&':
+ if (*(p + 1) == '&') {
+ piPtr->nextPtr = p + 2;
+ piPtr->token = AND;
+ } else {
+ piPtr->token = UNKNOWN;
+ }
+ break;
- case '!':
- if (*(p + 1) == '=') {
- piPtr->nextPtr = p + 2;
- piPtr->token = NEQ;
- } else {
- piPtr->token = NOT;
- }
- break;
+ case '|':
+ if (*(p + 1) == '|') {
+ piPtr->nextPtr = p + 2;
+ piPtr->token = OR;
+ } else {
+ piPtr->token = UNKNOWN;
+ }
+ break;
- default:
- piPtr->token = VALUE;
- result = ParseMathFunction(interp, p, piPtr, valuePtr);
- if ((result == TCL_OK) || (result == TCL_ERROR)) {
- return result;
- } else {
- Vector *vPtr;
-
- while (isspace((unsigned char)(*p))) {
- p++; /* Skip spaces leading the vector name. */
- }
- vPtr = Blt_Vec_ParseElement(interp, valuePtr->vPtr->dataPtr,
- p, &endPtr, NS_SEARCH_BOTH);
- if (vPtr == NULL) {
- return TCL_ERROR;
- }
- Blt_Vec_Duplicate(valuePtr->vPtr, vPtr);
- piPtr->nextPtr = endPtr;
- }
+ case '!':
+ if (*(p + 1) == '=') {
+ piPtr->nextPtr = p + 2;
+ piPtr->token = NEQ;
+ } else {
+ piPtr->token = NOT;
}
- return TCL_OK;
+ break;
+
+ default:
+ piPtr->token = VALUE;
+ result = ParseMathFunction(interp, p, piPtr, valuePtr);
+ if ((result == TCL_OK) || (result == TCL_ERROR)) {
+ return result;
+ } else {
+ Vector *vPtr;
+
+ while (isspace((unsigned char)(*p))) {
+ p++; /* Skip spaces leading the vector name. */
+ }
+ vPtr = Blt_Vec_ParseElement(interp, valuePtr->vPtr->dataPtr,
+ p, &endPtr, NS_SEARCH_BOTH);
+ if (vPtr == NULL) {
+ return TCL_ERROR;
+ }
+ Blt_Vec_Duplicate(valuePtr->vPtr, vPtr);
+ piPtr->nextPtr = endPtr;
+ }
+ }
+ return TCL_OK;
}
/*
@@ -1057,526 +1057,526 @@ NextToken(
*/
static int
NextValue(
- Tcl_Interp* interp, /* Interpreter to use for error reporting. */
- ParseInfo *piPtr, /* Describes the state of the parse
+ Tcl_Interp* interp, /* Interpreter to use for error reporting. */
+ ParseInfo *piPtr, /* Describes the state of the parse
* just before the value (i.e. NextToken will
* be called to get first token of value). */
- int prec, /* Treat any un-parenthesized operator
- * with precedence <= this as the end
- * of the expression. */
- Value *valuePtr) /* Where to store the value of the expression.
- * Caller must have initialized pv field. */
+ int prec, /* Treat any un-parenthesized operator
+ * with precedence <= this as the end
+ * of the expression. */
+ Value *valuePtr) /* Where to store the value of the expression.
+ * Caller must have initialized pv field. */
{
- Value value2; /* Second operand for current operator. */
- int operator; /* Current operator (either unary or binary). */
- int gotOp; /* Non-zero means already lexed the operator
+ Value value2; /* Second operand for current operator. */
+ int oper; /* Current operator (either unary or binary). */
+ int gotOp; /* Non-zero means already lexed the operator
* (while picking up value for unary operator).
* Don't lex again. */
- int result;
- Vector *vPtr, *v2Ptr;
- int i;
+ int result;
+ Vector *vPtr, *v2Ptr;
+ int i;
+
+ /*
+ * There are two phases to this procedure. First, pick off an initial
+ * value. Then, parse (binary operator, value) pairs until done.
+ */
+
+ vPtr = valuePtr->vPtr;
+ v2Ptr = Blt_Vec_New(vPtr->dataPtr);
+ gotOp = 0;
+ value2.vPtr = v2Ptr;
+ value2.pv.buffer = value2.pv.next = value2.staticSpace;
+ value2.pv.end = value2.pv.buffer + STATIC_STRING_SPACE - 1;
+ value2.pv.expandProc = Blt_ExpandParseValue;
+ value2.pv.clientData = NULL;
+
+ result = NextToken(interp, piPtr, valuePtr);
+ if (result != TCL_OK) {
+ goto done;
+ }
+ if (piPtr->token == OPEN_PAREN) {
+
+ /* Parenthesized sub-expression. */
+
+ result = NextValue(interp, piPtr, -1, valuePtr);
+ if (result != TCL_OK) {
+ goto done;
+ }
+ if (piPtr->token != CLOSE_PAREN) {
+ Tcl_AppendResult(interp, "unmatched parentheses in expression \"",
+ piPtr->expr, "\"", (char *)NULL);
+ result = TCL_ERROR;
+ goto done;
+ }
+ } else {
+ if (piPtr->token == MINUS) {
+ piPtr->token = UNARY_MINUS;
+ }
+ if (piPtr->token >= UNARY_MINUS) {
+ oper = piPtr->token;
+ result = NextValue(interp, piPtr, precTable[oper], valuePtr);
+ if (result != TCL_OK) {
+ goto done;
+ }
+ gotOp = 1;
+ /* Process unary operators. */
+ switch (oper) {
+ case UNARY_MINUS:
+ for(i = 0; i < vPtr->length; i++) {
+ vPtr->valueArr[i] = -(vPtr->valueArr[i]);
+ }
+ break;
+ case NOT:
+ for(i = 0; i < vPtr->length; i++) {
+ vPtr->valueArr[i] = (double)(!vPtr->valueArr[i]);
+ }
+ break;
+ default:
+ Tcl_AppendResult(interp, "unknown operator", (char *)NULL);
+ goto error;
+ }
+ } else if (piPtr->token != VALUE) {
+ Tcl_AppendResult(interp, "missing operand", (char *)NULL);
+ goto error;
+ }
+ }
+ if (!gotOp) {
+ result = NextToken(interp, piPtr, &value2);
+ if (result != TCL_OK) {
+ goto done;
+ }
+ }
+ /*
+ * Got the first operand. Now fetch (operator, operand) pairs.
+ */
+ for (;;) {
+ oper = piPtr->token;
+
+ value2.pv.next = value2.pv.buffer;
+ if ((oper < MULT) || (oper >= UNARY_MINUS)) {
+ if ((oper == END) || (oper == CLOSE_PAREN) ||
+ (oper == COMMA)) {
+ result = TCL_OK;
+ goto done;
+ } else {
+ Tcl_AppendResult(interp, "bad operator", (char *)NULL);
+ goto error;
+ }
+ }
+ if (precTable[oper] <= prec) {
+ result = TCL_OK;
+ goto done;
+ }
+ result = NextValue(interp, piPtr, precTable[oper], &value2);
+ if (result != TCL_OK) {
+ goto done;
+ }
+ if ((piPtr->token < MULT) && (piPtr->token != VALUE) &&
+ (piPtr->token != END) && (piPtr->token != CLOSE_PAREN) &&
+ (piPtr->token != COMMA)) {
+ Tcl_AppendResult(interp, "unexpected token in expression",
+ (char *)NULL);
+ goto error;
+ }
/*
- * There are two phases to this procedure. First, pick off an initial
- * value. Then, parse (binary operator, value) pairs until done.
+ * At this point we have two vectors and an operator.
*/
- vPtr = valuePtr->vPtr;
- v2Ptr = Blt_Vec_New(vPtr->dataPtr);
- gotOp = 0;
- value2.vPtr = v2Ptr;
- value2.pv.buffer = value2.pv.next = value2.staticSpace;
- value2.pv.end = value2.pv.buffer + STATIC_STRING_SPACE - 1;
- value2.pv.expandProc = Blt_ExpandParseValue;
- value2.pv.clientData = NULL;
+ if (v2Ptr->length == 1) {
+ double *opnd;
+ double scalar;
+
+ /*
+ * 2nd operand is a scalar.
+ */
+ scalar = v2Ptr->valueArr[0];
+ opnd = vPtr->valueArr;
+ switch (oper) {
+ case MULT:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] *= scalar;
+ }
+ break;
- result = NextToken(interp, piPtr, valuePtr);
- if (result != TCL_OK) {
- goto done;
- }
- if (piPtr->token == OPEN_PAREN) {
+ case DIVIDE:
+ if (scalar == 0.0) {
+ Tcl_AppendResult(interp, "divide by zero", (char *)NULL);
+ goto error;
+ }
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] /= scalar;
+ }
+ break;
- /* Parenthesized sub-expression. */
+ case PLUS:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] += scalar;
+ }
+ break;
- result = NextValue(interp, piPtr, -1, valuePtr);
- if (result != TCL_OK) {
- goto done;
+ case MINUS:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] -= scalar;
}
- if (piPtr->token != CLOSE_PAREN) {
- Tcl_AppendResult(interp, "unmatched parentheses in expression \"",
- piPtr->expr, "\"", (char *)NULL);
- result = TCL_ERROR;
- goto done;
+ break;
+
+ case EXPONENT:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = pow(opnd[i], scalar);
}
- } else {
- if (piPtr->token == MINUS) {
- piPtr->token = UNARY_MINUS;
+ break;
+
+ case MOD:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = Fmod(opnd[i], scalar);
}
- if (piPtr->token >= UNARY_MINUS) {
- operator = piPtr->token;
- result = NextValue(interp, piPtr, precTable[operator], valuePtr);
- if (result != TCL_OK) {
- goto done;
- }
- gotOp = 1;
- /* Process unary operators. */
- switch (operator) {
- case UNARY_MINUS:
- for(i = 0; i < vPtr->length; i++) {
- vPtr->valueArr[i] = -(vPtr->valueArr[i]);
- }
- break;
-
- case NOT:
- for(i = 0; i < vPtr->length; i++) {
- vPtr->valueArr[i] = (double)(!vPtr->valueArr[i]);
- }
- break;
- default:
- Tcl_AppendResult(interp, "unknown operator", (char *)NULL);
- goto error;
- }
- } else if (piPtr->token != VALUE) {
- Tcl_AppendResult(interp, "missing operand", (char *)NULL);
- goto error;
+ break;
+
+ case LESS:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] < scalar);
}
- }
- if (!gotOp) {
- result = NextToken(interp, piPtr, &value2);
- if (result != TCL_OK) {
- goto done;
+ break;
+
+ case GREATER:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] > scalar);
}
- }
- /*
- * Got the first operand. Now fetch (operator, operand) pairs.
- */
- for (;;) {
- operator = piPtr->token;
-
- value2.pv.next = value2.pv.buffer;
- if ((operator < MULT) || (operator >= UNARY_MINUS)) {
- if ((operator == END) || (operator == CLOSE_PAREN) ||
- (operator == COMMA)) {
- result = TCL_OK;
- goto done;
- } else {
- Tcl_AppendResult(interp, "bad operator", (char *)NULL);
- goto error;
- }
+ break;
+
+ case LEQ:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] <= scalar);
}
- if (precTable[operator] <= prec) {
- result = TCL_OK;
- goto done;
+ break;
+
+ case GEQ:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] >= scalar);
}
- result = NextValue(interp, piPtr, precTable[operator], &value2);
- if (result != TCL_OK) {
- goto done;
+ break;
+
+ case EQUAL:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] == scalar);
}
- if ((piPtr->token < MULT) && (piPtr->token != VALUE) &&
- (piPtr->token != END) && (piPtr->token != CLOSE_PAREN) &&
- (piPtr->token != COMMA)) {
- Tcl_AppendResult(interp, "unexpected token in expression",
- (char *)NULL);
- goto error;
+ break;
+
+ case NEQ:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] != scalar);
}
- /*
- * At this point we have two vectors and an operator.
- */
-
- if (v2Ptr->length == 1) {
- double *opnd;
- double scalar;
-
- /*
- * 2nd operand is a scalar.
- */
- scalar = v2Ptr->valueArr[0];
- opnd = vPtr->valueArr;
- switch (operator) {
- case MULT:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] *= scalar;
- }
- break;
-
- case DIVIDE:
- if (scalar == 0.0) {
- Tcl_AppendResult(interp, "divide by zero", (char *)NULL);
- goto error;
- }
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] /= scalar;
- }
- break;
-
- case PLUS:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] += scalar;
- }
- break;
-
- case MINUS:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] -= scalar;
- }
- break;
-
- case EXPONENT:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = pow(opnd[i], scalar);
- }
- break;
-
- case MOD:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = Fmod(opnd[i], scalar);
- }
- break;
-
- case LESS:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] < scalar);
- }
- break;
-
- case GREATER:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] > scalar);
- }
- break;
-
- case LEQ:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] <= scalar);
- }
- break;
-
- case GEQ:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] >= scalar);
- }
- break;
-
- case EQUAL:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] == scalar);
- }
- break;
-
- case NEQ:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] != scalar);
- }
- break;
-
- case AND:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] && scalar);
- }
- break;
-
- case OR:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] || scalar);
- }
- break;
-
- case LEFT_SHIFT:
- {
- int offset;
-
- offset = (int)scalar % vPtr->length;
- if (offset > 0) {
- double *hold;
- int j;
-
- hold = malloc(sizeof(double) * offset);
- for (i = 0; i < offset; i++) {
- hold[i] = opnd[i];
- }
- for (i = offset, j = 0; i < vPtr->length; i++, j++) {
- opnd[j] = opnd[i];
- }
- for (i = 0, j = vPtr->length - offset;
- j < vPtr->length; i++, j++) {
- opnd[j] = hold[i];
- }
- free(hold);
- }
- }
- break;
-
- case RIGHT_SHIFT:
- {
- int offset;
-
- offset = (int)scalar % vPtr->length;
- if (offset > 0) {
- double *hold;
- int j;
-
- hold = malloc(sizeof(double) * offset);
- for (i = vPtr->length - offset, j = 0;
- i < vPtr->length; i++, j++) {
- hold[j] = opnd[i];
- }
- for (i = vPtr->length - offset - 1,
- j = vPtr->length - 1; i >= 0; i--, j--) {
- opnd[j] = opnd[i];
- }
- for (i = 0; i < offset; i++) {
- opnd[i] = hold[i];
- }
- free(hold);
- }
- }
- break;
-
- default:
- Tcl_AppendResult(interp, "unknown operator in expression",
- (char *)NULL);
- goto error;
+ break;
+
+ case AND:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] && scalar);
+ }
+ break;
+
+ case OR:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] || scalar);
+ }
+ break;
+
+ case LEFT_SHIFT:
+ {
+ int offset;
+
+ offset = (int)scalar % vPtr->length;
+ if (offset > 0) {
+ double *hold;
+ int j;
+
+ hold = (double*)malloc(sizeof(double) * offset);
+ for (i = 0; i < offset; i++) {
+ hold[i] = opnd[i];
}
+ for (i = offset, j = 0; i < vPtr->length; i++, j++) {
+ opnd[j] = opnd[i];
+ }
+ for (i = 0, j = vPtr->length - offset;
+ j < vPtr->length; i++, j++) {
+ opnd[j] = hold[i];
+ }
+ free(hold);
+ }
+ }
+ break;
+
+ case RIGHT_SHIFT:
+ {
+ int offset;
- } else if (vPtr->length == 1) {
- double *opnd;
- double scalar;
-
- /*
- * 1st operand is a scalar.
- */
- scalar = vPtr->valueArr[0];
- Blt_Vec_Duplicate(vPtr, v2Ptr);
- opnd = vPtr->valueArr;
- switch (operator) {
- case MULT:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] *= scalar;
- }
- break;
-
- case PLUS:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] += scalar;
- }
- break;
-
- case DIVIDE:
- for(i = 0; i < vPtr->length; i++) {
- if (opnd[i] == 0.0) {
- Tcl_AppendResult(interp, "divide by zero",
- (char *)NULL);
- goto error;
- }
- opnd[i] = (scalar / opnd[i]);
- }
- break;
-
- case MINUS:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = scalar - opnd[i];
- }
- break;
-
- case EXPONENT:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = pow(scalar, opnd[i]);
- }
- break;
-
- case MOD:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = Fmod(scalar, opnd[i]);
- }
- break;
-
- case LESS:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(scalar < opnd[i]);
- }
- break;
-
- case GREATER:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(scalar > opnd[i]);
- }
- break;
-
- case LEQ:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(scalar >= opnd[i]);
- }
- break;
-
- case GEQ:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(scalar <= opnd[i]);
- }
- break;
-
- case EQUAL:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] == scalar);
- }
- break;
-
- case NEQ:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] != scalar);
- }
- break;
-
- case AND:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] && scalar);
- }
- break;
-
- case OR:
- for(i = 0; i < vPtr->length; i++) {
- opnd[i] = (double)(opnd[i] || scalar);
- }
- break;
-
- case LEFT_SHIFT:
- case RIGHT_SHIFT:
- Tcl_AppendResult(interp, "second shift operand must be scalar",
- (char *)NULL);
- goto error;
-
- default:
- Tcl_AppendResult(interp, "unknown operator in expression",
- (char *)NULL);
- goto error;
+ offset = (int)scalar % vPtr->length;
+ if (offset > 0) {
+ double *hold;
+ int j;
+
+ hold = (double*)malloc(sizeof(double) * offset);
+ for (i = vPtr->length - offset, j = 0;
+ i < vPtr->length; i++, j++) {
+ hold[j] = opnd[i];
}
- } else {
- double *opnd1, *opnd2;
- /*
- * Carry out the function of the specified operator.
- */
- if (vPtr->length != v2Ptr->length) {
- Tcl_AppendResult(interp, "vectors are different lengths",
- (char *)NULL);
- goto error;
+ for (i = vPtr->length - offset - 1,
+ j = vPtr->length - 1; i >= 0; i--, j--) {
+ opnd[j] = opnd[i];
}
- opnd1 = vPtr->valueArr, opnd2 = v2Ptr->valueArr;
- switch (operator) {
- case MULT:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] *= opnd2[i];
- }
- break;
-
- case DIVIDE:
- for (i = 0; i < vPtr->length; i++) {
- if (opnd2[i] == 0.0) {
- Tcl_AppendResult(interp,
- "can't divide by 0.0 vector component",
- (char *)NULL);
- goto error;
- }
- opnd1[i] /= opnd2[i];
- }
- break;
-
- case PLUS:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] += opnd2[i];
- }
- break;
-
- case MINUS:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] -= opnd2[i];
- }
- break;
-
- case MOD:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = Fmod(opnd1[i], opnd2[i]);
- }
- break;
-
- case EXPONENT:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = pow(opnd1[i], opnd2[i]);
- }
- break;
-
- case LESS:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] < opnd2[i]);
- }
- break;
-
- case GREATER:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] > opnd2[i]);
- }
- break;
-
- case LEQ:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] <= opnd2[i]);
- }
- break;
-
- case GEQ:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] >= opnd2[i]);
- }
- break;
-
- case EQUAL:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] == opnd2[i]);
- }
- break;
-
- case NEQ:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] != opnd2[i]);
- }
- break;
-
- case AND:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] && opnd2[i]);
- }
- break;
-
- case OR:
- for (i = 0; i < vPtr->length; i++) {
- opnd1[i] = (double)(opnd1[i] || opnd2[i]);
- }
- break;
-
- case LEFT_SHIFT:
- case RIGHT_SHIFT:
- Tcl_AppendResult(interp, "second shift operand must be scalar",
- (char *)NULL);
- goto error;
-
- default:
- Tcl_AppendResult(interp, "unknown operator in expression",
- (char *)NULL);
- goto error;
+ for (i = 0; i < offset; i++) {
+ opnd[i] = hold[i];
}
+ free(hold);
+ }
}
- }
- done:
- if (value2.pv.buffer != value2.staticSpace) {
- free(value2.pv.buffer);
- }
- Blt_Vec_Free(v2Ptr);
- return result;
+ break;
+
+ default:
+ Tcl_AppendResult(interp, "unknown operator in expression",
+ (char *)NULL);
+ goto error;
+ }
+
+ } else if (vPtr->length == 1) {
+ double *opnd;
+ double scalar;
+
+ /*
+ * 1st operand is a scalar.
+ */
+ scalar = vPtr->valueArr[0];
+ Blt_Vec_Duplicate(vPtr, v2Ptr);
+ opnd = vPtr->valueArr;
+ switch (oper) {
+ case MULT:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] *= scalar;
+ }
+ break;
+
+ case PLUS:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] += scalar;
+ }
+ break;
+
+ case DIVIDE:
+ for(i = 0; i < vPtr->length; i++) {
+ if (opnd[i] == 0.0) {
+ Tcl_AppendResult(interp, "divide by zero",
+ (char *)NULL);
+ goto error;
+ }
+ opnd[i] = (scalar / opnd[i]);
+ }
+ break;
+
+ case MINUS:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = scalar - opnd[i];
+ }
+ break;
+
+ case EXPONENT:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = pow(scalar, opnd[i]);
+ }
+ break;
+
+ case MOD:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = Fmod(scalar, opnd[i]);
+ }
+ break;
+
+ case LESS:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(scalar < opnd[i]);
+ }
+ break;
+
+ case GREATER:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(scalar > opnd[i]);
+ }
+ break;
+
+ case LEQ:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(scalar >= opnd[i]);
+ }
+ break;
+
+ case GEQ:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(scalar <= opnd[i]);
+ }
+ break;
+
+ case EQUAL:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] == scalar);
+ }
+ break;
+
+ case NEQ:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] != scalar);
+ }
+ break;
+
+ case AND:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] && scalar);
+ }
+ break;
+
+ case OR:
+ for(i = 0; i < vPtr->length; i++) {
+ opnd[i] = (double)(opnd[i] || scalar);
+ }
+ break;
+
+ case LEFT_SHIFT:
+ case RIGHT_SHIFT:
+ Tcl_AppendResult(interp, "second shift operand must be scalar",
+ (char *)NULL);
+ goto error;
+
+ default:
+ Tcl_AppendResult(interp, "unknown operator in expression",
+ (char *)NULL);
+ goto error;
+ }
+ } else {
+ double *opnd1, *opnd2;
+ /*
+ * Carry out the function of the specified operator.
+ */
+ if (vPtr->length != v2Ptr->length) {
+ Tcl_AppendResult(interp, "vectors are different lengths",
+ (char *)NULL);
+ goto error;
+ }
+ opnd1 = vPtr->valueArr, opnd2 = v2Ptr->valueArr;
+ switch (oper) {
+ case MULT:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] *= opnd2[i];
+ }
+ break;
+
+ case DIVIDE:
+ for (i = 0; i < vPtr->length; i++) {
+ if (opnd2[i] == 0.0) {
+ Tcl_AppendResult(interp,
+ "can't divide by 0.0 vector component",
+ (char *)NULL);
+ goto error;
+ }
+ opnd1[i] /= opnd2[i];
+ }
+ break;
+
+ case PLUS:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] += opnd2[i];
+ }
+ break;
+
+ case MINUS:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] -= opnd2[i];
+ }
+ break;
+
+ case MOD:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = Fmod(opnd1[i], opnd2[i]);
+ }
+ break;
+
+ case EXPONENT:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = pow(opnd1[i], opnd2[i]);
+ }
+ break;
+
+ case LESS:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] < opnd2[i]);
+ }
+ break;
+
+ case GREATER:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] > opnd2[i]);
+ }
+ break;
+
+ case LEQ:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] <= opnd2[i]);
+ }
+ break;
+
+ case GEQ:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] >= opnd2[i]);
+ }
+ break;
+
+ case EQUAL:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] == opnd2[i]);
+ }
+ break;
+
+ case NEQ:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] != opnd2[i]);
+ }
+ break;
- error:
- if (value2.pv.buffer != value2.staticSpace) {
- free(value2.pv.buffer);
+ case AND:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] && opnd2[i]);
+ }
+ break;
+
+ case OR:
+ for (i = 0; i < vPtr->length; i++) {
+ opnd1[i] = (double)(opnd1[i] || opnd2[i]);
+ }
+ break;
+
+ case LEFT_SHIFT:
+ case RIGHT_SHIFT:
+ Tcl_AppendResult(interp, "second shift operand must be scalar",
+ (char *)NULL);
+ goto error;
+
+ default:
+ Tcl_AppendResult(interp, "unknown operator in expression",
+ (char *)NULL);
+ goto error;
+ }
}
- Blt_Vec_Free(v2Ptr);
- return TCL_ERROR;
+ }
+ done:
+ if (value2.pv.buffer != value2.staticSpace) {
+ free(value2.pv.buffer);
+ }
+ Blt_Vec_Free(v2Ptr);
+ return result;
+
+ error:
+ if (value2.pv.buffer != value2.staticSpace) {
+ free(value2.pv.buffer);
+ }
+ Blt_Vec_Free(v2Ptr);
+ return TCL_ERROR;
}
/*
@@ -1603,45 +1603,45 @@ NextValue(
*/
static int
EvaluateExpression(
- Tcl_Interp* interp, /* Context in which to evaluate the
- * expression. */
- char *string, /* Expression to evaluate. */
- Value *valuePtr) /* Where to store result. Should
- * not be initialized by caller. */
+ Tcl_Interp* interp, /* Context in which to evaluate the
+ * expression. */
+ char *string, /* Expression to evaluate. */
+ Value *valuePtr) /* Where to store result. Should
+ * not be initialized by caller. */
{
- ParseInfo info;
- int result;
- Vector *vPtr;
- double *vp, *vend;
-
- info.expr = info.nextPtr = string;
- valuePtr->pv.buffer = valuePtr->pv.next = valuePtr->staticSpace;
- valuePtr->pv.end = valuePtr->pv.buffer + STATIC_STRING_SPACE - 1;
- valuePtr->pv.expandProc = Blt_ExpandParseValue;
- valuePtr->pv.clientData = NULL;
-
- result = NextValue(interp, &info, -1, valuePtr);
- if (result != TCL_OK) {
- return result;
- }
- if (info.token != END) {
- Tcl_AppendResult(interp, ": syntax error in expression \"",
- string, "\"", (char *)NULL);
- return TCL_ERROR;
- }
- vPtr = valuePtr->vPtr;
-
- /* Check for NaN's and overflows. */
- for (vp = vPtr->valueArr, vend = vp + vPtr->length; vp < vend; vp++) {
- if (!isfinite(*vp)) {
- /*
- * IEEE floating-point error.
- */
- MathError(interp, *vp);
- return TCL_ERROR;
- }
+ ParseInfo info;
+ int result;
+ Vector *vPtr;
+ double *vp, *vend;
+
+ info.expr = info.nextPtr = string;
+ valuePtr->pv.buffer = valuePtr->pv.next = valuePtr->staticSpace;
+ valuePtr->pv.end = valuePtr->pv.buffer + STATIC_STRING_SPACE - 1;
+ valuePtr->pv.expandProc = Blt_ExpandParseValue;
+ valuePtr->pv.clientData = NULL;
+
+ result = NextValue(interp, &info, -1, valuePtr);
+ if (result != TCL_OK) {
+ return result;
+ }
+ if (info.token != END) {
+ Tcl_AppendResult(interp, ": syntax error in expression \"",
+ string, "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ vPtr = valuePtr->vPtr;
+
+ /* Check for NaN's and overflows. */
+ for (vp = vPtr->valueArr, vend = vp + vPtr->length; vp < vend; vp++) {
+ if (!isfinite(*vp)) {
+ /*
+ * IEEE floating-point error.
+ */
+ MathError(interp, *vp);
+ return TCL_ERROR;
}
- return TCL_OK;
+ }
+ return TCL_OK;
}
/*
@@ -1664,164 +1664,161 @@ EvaluateExpression(
*/
static int
ComponentFunc(
- ClientData clientData, /* Contains address of procedure that
- * takes one double argument and
- * returns a double result. */
- Tcl_Interp* interp,
- Vector *vPtr)
+ ClientData clientData, /* Contains address of procedure that
+ * takes one double argument and
+ * returns a double result. */
+ Tcl_Interp* interp,
+ Vector *vPtr)
{
- ComponentProc *procPtr = (ComponentProc *) clientData;
- double *vp, *vend;
+ ComponentProc *procPtr = (ComponentProc *) clientData;
+ double *vp, *vend;
- errno = 0;
- for(vp = vPtr->valueArr + vPtr->first,
- vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
- *vp = (*procPtr) (*vp);
- if (errno != 0) {
- MathError(interp, *vp);
- return TCL_ERROR;
- }
- if (!isfinite(*vp)) {
- /*
- * IEEE floating-point error.
- */
- MathError(interp, *vp);
- return TCL_ERROR;
- }
+ errno = 0;
+ for(vp = vPtr->valueArr + vPtr->first,
+ vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) {
+ *vp = (*procPtr) (*vp);
+ if (errno != 0) {
+ MathError(interp, *vp);
+ return TCL_ERROR;
}
- return TCL_OK;
+ if (!isfinite(*vp)) {
+ /*
+ * IEEE floating-point error.
+ */
+ MathError(interp, *vp);
+ return TCL_ERROR;
+ }
+ }
+ return TCL_OK;
}
static int
ScalarFunc(ClientData clientData, Tcl_Interp* interp, Vector *vPtr)
{
- double value;
- ScalarProc *procPtr = (ScalarProc *) clientData;
+ double value;
+ ScalarProc *procPtr = (ScalarProc *) clientData;
- errno = 0;
- value = (*procPtr) (vPtr);
- if (errno != 0) {
- MathError(interp, value);
- return TCL_ERROR;
- }
- if (Blt_Vec_ChangeLength(interp, vPtr, 1) != TCL_OK) {
- return TCL_ERROR;
- }
- vPtr->valueArr[0] = value;
- return TCL_OK;
+ errno = 0;
+ value = (*procPtr) (vPtr);
+ if (errno != 0) {
+ MathError(interp, value);
+ return TCL_ERROR;
+ }
+ if (Blt_Vec_ChangeLength(interp, vPtr, 1) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ vPtr->valueArr[0] = value;
+ return TCL_OK;
}
/*ARGSUSED*/
static int
VectorFunc(ClientData clientData, Tcl_Interp* interp, Vector *vPtr)
{
- VectorProc *procPtr = (VectorProc *) clientData;
+ VectorProc *procPtr = (VectorProc *) clientData;
- return (*procPtr) (vPtr);
+ return (*procPtr) (vPtr);
}
static MathFunction mathFunctions[] =
-{
- {"abs", ComponentFunc, Fabs},
- {"acos", ComponentFunc, acos},
- {"asin", ComponentFunc, asin},
- {"atan", ComponentFunc, atan},
- {"adev", ScalarFunc, AvgDeviation},
- {"ceil", ComponentFunc, ceil},
- {"cos", ComponentFunc, cos},
- {"cosh", ComponentFunc, cosh},
- {"exp", ComponentFunc, exp},
- {"floor", ComponentFunc, floor},
- {"kurtosis",ScalarFunc, Kurtosis},
- {"length", ScalarFunc, Length},
- {"log", ComponentFunc, log},
- {"log10", ComponentFunc, log10},
- {"max", ScalarFunc, Blt_VecMax},
- {"mean", ScalarFunc, Mean},
- {"median", ScalarFunc, Median},
- {"min", ScalarFunc, Blt_VecMin},
- {"norm", VectorFunc, Norm},
- {"nz", ScalarFunc, Nonzeros},
- {"q1", ScalarFunc, Q1},
- {"q3", ScalarFunc, Q3},
- {"prod", ScalarFunc, Product},
- {"random", ComponentFunc, drand48},
- {"round", ComponentFunc, Round},
- {"sdev", ScalarFunc, StdDeviation},
- {"sin", ComponentFunc, sin},
- {"sinh", ComponentFunc, sinh},
- {"skew", ScalarFunc, Skew},
- {"sort", VectorFunc, Sort},
- {"sqrt", ComponentFunc, sqrt},
- {"sum", ScalarFunc, Sum},
- {"tan", ComponentFunc, tan},
- {"tanh", ComponentFunc, tanh},
- {"var", ScalarFunc, Variance},
+ {
+ {"abs", (void*)ComponentFunc, (ClientData)Fabs},
+ {"acos", (void*)ComponentFunc, (ClientData)acos},
+ {"asin", (void*)ComponentFunc, (ClientData)asin},
+ {"atan", (void*)ComponentFunc, (ClientData)atan},
+ {"adev", (void*)ScalarFunc, (ClientData)AvgDeviation},
+ {"ceil", (void*)ComponentFunc, (ClientData)ceil},
+ {"cos", (void*)ComponentFunc, (ClientData)cos},
+ {"cosh", (void*)ComponentFunc, (ClientData)cosh},
+ {"exp", (void*)ComponentFunc, (ClientData)exp},
+ {"floor", (void*)ComponentFunc, (ClientData)floor},
+ {"kurtosis",(void*)ScalarFunc, (ClientData)Kurtosis},
+ {"length", (void*)ScalarFunc, (ClientData)Length},
+ {"log", (void*)ComponentFunc, (ClientData)log},
+ {"log10", (void*)ComponentFunc, (ClientData)log10},
+ {"max", (void*)ScalarFunc, (ClientData)Blt_VecMax},
+ {"mean", (void*)ScalarFunc, (ClientData)Mean},
+ {"median", (void*)ScalarFunc, (ClientData)Median},
+ {"min", (void*)ScalarFunc, (ClientData)Blt_VecMin},
+ {"norm", (void*)VectorFunc, (ClientData)Norm},
+ {"nz", (void*)ScalarFunc, (ClientData)Nonzeros},
+ {"q1", (void*)ScalarFunc, (ClientData)Q1},
+ {"q3", (void*)ScalarFunc, (ClientData)Q3},
+ {"prod", (void*)ScalarFunc, (ClientData)Product},
+ {"random", (void*)ComponentFunc, (ClientData)drand48},
+ {"round", (void*)ComponentFunc, (ClientData)Round},
+ {"sdev", (void*)ScalarFunc, (ClientData)StdDeviation},
+ {"sin", (void*)ComponentFunc, (ClientData)sin},
+ {"sinh", (void*)ComponentFunc, (ClientData)sinh},
+ {"skew", (void*)ScalarFunc, (ClientData)Skew},
+ {"sort", (void*)VectorFunc, (ClientData)Sort},
+ {"sqrt", (void*)ComponentFunc, (ClientData)sqrt},
+ {"sum", (void*)ScalarFunc, (ClientData)Sum},
+ {"tan", (void*)ComponentFunc, (ClientData)tan},
+ {"tanh", (void*)ComponentFunc, (ClientData)tanh},
+ {"var", (void*)ScalarFunc, (ClientData)Variance},
{(char *)NULL,},
-};
+ };
void
Blt_Vec_InstallMathFunctions(Tcl_HashTable *tablePtr)
{
- MathFunction *mathPtr;
+ MathFunction *mathPtr;
- for (mathPtr = mathFunctions; mathPtr->name != NULL; mathPtr++) {
- Tcl_HashEntry *hPtr;
- int isNew;
+ for (mathPtr = mathFunctions; mathPtr->name != NULL; mathPtr++) {
+ Tcl_HashEntry *hPtr;
+ int isNew;
- hPtr = Tcl_CreateHashEntry(tablePtr, mathPtr->name, &isNew);
- Tcl_SetHashValue(hPtr, (ClientData)mathPtr);
- }
+ hPtr = Tcl_CreateHashEntry(tablePtr, mathPtr->name, &isNew);
+ Tcl_SetHashValue(hPtr, (ClientData)mathPtr);
+ }
}
void
Blt_Vec_UninstallMathFunctions(Tcl_HashTable *tablePtr)
{
- Tcl_HashEntry *hPtr;
- Tcl_HashSearch cursor;
-
- for (hPtr = Tcl_FirstHashEntry(tablePtr, &cursor); hPtr != NULL;
- hPtr = Tcl_NextHashEntry(&cursor)) {
- MathFunction *mathPtr;
-
- mathPtr = Tcl_GetHashValue(hPtr);
- if (mathPtr->name == NULL) {
- free(mathPtr);
- }
- }
+ Tcl_HashEntry *hPtr;
+ Tcl_HashSearch cursor;
+
+ for (hPtr = Tcl_FirstHashEntry(tablePtr, &cursor); hPtr != NULL;
+ hPtr = Tcl_NextHashEntry(&cursor)) {
+ MathFunction *mathPtr = (MathFunction*)Tcl_GetHashValue(hPtr);
+ if (mathPtr->name == NULL)
+ free(mathPtr);
+ }
}
static void
InstallIndexProc(
- Tcl_HashTable *tablePtr,
- const char *string,
- Blt_VectorIndexProc *procPtr) /* Pointer to function to be called
- * when the vector finds the named index.
- * If NULL, this indicates to remove
- * the index from the table.
- */
+ Tcl_HashTable *tablePtr,
+ const char *string,
+ Blt_VectorIndexProc *procPtr) /* Pointer to function to be called
+ * when the vector finds the named index.
+ * If NULL, this indicates to remove
+ * the index from the table.
+ */
{
- Tcl_HashEntry *hPtr;
- int dummy;
-
- hPtr = Tcl_CreateHashEntry(tablePtr, string, &dummy);
- if (procPtr == NULL) {
- Tcl_DeleteHashEntry(hPtr);
- } else {
- Tcl_SetHashValue(hPtr, (ClientData)procPtr);
- }
+ Tcl_HashEntry *hPtr;
+ int dummy;
+
+ hPtr = Tcl_CreateHashEntry(tablePtr, string, &dummy);
+ if (procPtr == NULL) {
+ Tcl_DeleteHashEntry(hPtr);
+ } else {
+ Tcl_SetHashValue(hPtr, (ClientData)procPtr);
+ }
}
void
Blt_Vec_InstallSpecialIndices(Tcl_HashTable *tablePtr)
{
- InstallIndexProc(tablePtr, "min", Blt_VecMin);
- InstallIndexProc(tablePtr, "max", Blt_VecMax);
- InstallIndexProc(tablePtr, "mean", Mean);
- InstallIndexProc(tablePtr, "sum", Sum);
- InstallIndexProc(tablePtr, "prod", Product);
+ InstallIndexProc(tablePtr, "min", Blt_VecMin);
+ InstallIndexProc(tablePtr, "max", Blt_VecMax);
+ InstallIndexProc(tablePtr, "mean", Mean);
+ InstallIndexProc(tablePtr, "sum", Sum);
+ InstallIndexProc(tablePtr, "prod", Product);
}
@@ -1847,36 +1844,36 @@ Blt_Vec_InstallSpecialIndices(Tcl_HashTable *tablePtr)
*/
int
Blt_ExprVector(
- Tcl_Interp* interp, /* Context in which to evaluate the
- * expression. */
- char *string, /* Expression to evaluate. */
- Blt_Vector *vector) /* Where to store result. */
+ Tcl_Interp* interp, /* Context in which to evaluate the
+ * expression. */
+ char *string, /* Expression to evaluate. */
+ Blt_Vector *vector) /* Where to store result. */
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Vector *vPtr = (Vector *)vector;
- Value value;
-
- dataPtr = (vector != NULL)
- ? vPtr->dataPtr : Blt_Vec_GetInterpData(interp);
- value.vPtr = Blt_Vec_New(dataPtr);
- if (EvaluateExpression(interp, string, &value) != TCL_OK) {
- Blt_Vec_Free(value.vPtr);
- return TCL_ERROR;
- }
- if (vPtr != NULL) {
- Blt_Vec_Duplicate(vPtr, value.vPtr);
- } else {
- Tcl_Obj *listObjPtr;
- double *vp, *vend;
-
- /* No result vector. Put values in interp->result. */
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
- for (vp = value.vPtr->valueArr, vend = vp + value.vPtr->length;
- vp < vend; vp++) {
- Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewDoubleObj(*vp));
- }
- Tcl_SetObjResult(interp, listObjPtr);
- }
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Vector *vPtr = (Vector *)vector;
+ Value value;
+
+ dataPtr = (vector != NULL)
+ ? vPtr->dataPtr : Blt_Vec_GetInterpData(interp);
+ value.vPtr = Blt_Vec_New(dataPtr);
+ if (EvaluateExpression(interp, string, &value) != TCL_OK) {
Blt_Vec_Free(value.vPtr);
- return TCL_OK;
+ return TCL_ERROR;
+ }
+ if (vPtr != NULL) {
+ Blt_Vec_Duplicate(vPtr, value.vPtr);
+ } else {
+ Tcl_Obj *listObjPtr;
+ double *vp, *vend;
+
+ /* No result vector. Put values in interp->result. */
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
+ for (vp = value.vPtr->valueArr, vend = vp + value.vPtr->length;
+ vp < vend; vp++) {
+ Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewDoubleObj(*vp));
+ }
+ Tcl_SetObjResult(interp, listObjPtr);
+ }
+ Blt_Vec_Free(value.vPtr);
+ return TCL_OK;
}
diff --git a/src/bltVector.C b/src/bltVector.C
index bae2fcd..e5c7508 100644
--- a/src/bltVector.C
+++ b/src/bltVector.C
@@ -59,8 +59,8 @@
#define TRACE_ALL (TCL_TRACE_WRITES | TCL_TRACE_READS | TCL_TRACE_UNSETS)
-#define VECTOR_CHAR(c) ((isalnum((unsigned char)(c))) || \
- (c == '_') || (c == ':') || (c == '@') || (c == '.'))
+#define VECTOR_CHAR(c) ((isalnum((unsigned char)(c))) || \
+ (c == '_') || (c == ':') || (c == '@') || (c == '.'))
/*
* VectorClient --
@@ -72,21 +72,21 @@
*
*/
typedef struct {
- unsigned int magic; /* Magic value designating whether this really
+ unsigned int magic; /* Magic value designating whether this really
* is a vector token or not */
- Vector *serverPtr; /* Pointer to the master record of the vector.
+ Vector *serverPtr; /* Pointer to the master record of the vector.
* If NULL, indicates that the vector has been
* destroyed but as of yet, this client hasn't
* recognized it. */
- Blt_VectorChangedProc *proc;/* Routine to call when the contents of the
- * vector change or the vector is deleted. */
+ Blt_VectorChangedProc *proc;/* Routine to call when the contents of the
+ * vector change or the vector is deleted. */
- ClientData clientData; /* Data passed whenever the vector change
+ ClientData clientData; /* Data passed whenever the vector change
* procedure is called. */
- Blt_ChainLink link; /* Used to quickly remove this entry from its
+ Blt_ChainLink link; /* Used to quickly remove this entry from its
* server's client chain. */
} VectorClient;
@@ -95,27 +95,27 @@ static Tcl_ObjCmdProc VectorCmd;
static Tcl_InterpDeleteProc VectorInterpDeleteProc;
typedef struct {
- char *varName; /* Requested variable name. */
- char *cmdName; /* Requested command name. */
- int flush; /* Flush */
- int watchUnset; /* Watch when variable is unset. */
+ char *varName; /* Requested variable name. */
+ char *cmdName; /* Requested command name. */
+ int flush; /* Flush */
+ int watchUnset; /* Watch when variable is unset. */
} CreateSwitches;
static Blt_SwitchSpec createSwitches[] =
-{
+ {
{BLT_SWITCH_STRING, "-variable", "varName",
- Tk_Offset(CreateSwitches, varName), BLT_SWITCH_NULL_OK},
+ Tk_Offset(CreateSwitches, varName), BLT_SWITCH_NULL_OK},
{BLT_SWITCH_STRING, "-command", "command",
- Tk_Offset(CreateSwitches, cmdName), BLT_SWITCH_NULL_OK},
+ Tk_Offset(CreateSwitches, cmdName), BLT_SWITCH_NULL_OK},
{BLT_SWITCH_BOOLEAN, "-watchunset", "bool",
- Tk_Offset(CreateSwitches, watchUnset), 0},
+ Tk_Offset(CreateSwitches, watchUnset), 0},
{BLT_SWITCH_BOOLEAN, "-flush", "bool",
- Tk_Offset(CreateSwitches, flush), 0},
+ Tk_Offset(CreateSwitches, flush), 0},
{BLT_SWITCH_END}
-};
+ };
typedef int (VectorCmdProc)(Vector *vecObjPtr, Tcl_Interp* interp,
- int objc, Tcl_Obj* const objv[]);
+ int objc, Tcl_Obj* const objv[]);
static char* Blt_Strdup(const char *string)
{
@@ -129,20 +129,20 @@ static char* Blt_Strdup(const char *string)
static Vector *
FindVectorInNamespace(
- VectorInterpData *dataPtr, /* Interpreter-specific data. */
- Blt_ObjectName *objNamePtr)
+ VectorInterpData *dataPtr, /* Interpreter-specific data. */
+ Blt_ObjectName *objNamePtr)
{
- Tcl_DString dString;
- const char *name;
- Tcl_HashEntry *hPtr;
-
- name = Blt_MakeQualifiedName(objNamePtr, &dString);
- hPtr = Tcl_FindHashEntry(&dataPtr->vectorTable, name);
- Tcl_DStringFree(&dString);
- if (hPtr != NULL) {
- return Tcl_GetHashValue(hPtr);
- }
- return NULL;
+ Tcl_DString dString;
+ const char *name;
+ Tcl_HashEntry *hPtr;
+
+ name = Blt_MakeQualifiedName(objNamePtr, &dString);
+ hPtr = Tcl_FindHashEntry(&dataPtr->vectorTable, name);
+ Tcl_DStringFree(&dString);
+ if (hPtr != NULL) {
+ return (Vector*)Tcl_GetHashValue(hPtr);
+ }
+ return NULL;
}
/*
@@ -160,54 +160,54 @@ FindVectorInNamespace(
*/
static Vector *
GetVectorObject(
- VectorInterpData *dataPtr, /* Interpreter-specific data. */
- const char *name,
- int flags)
+ VectorInterpData *dataPtr, /* Interpreter-specific data. */
+ const char *name,
+ int flags)
{
- Blt_ObjectName objName;
- Vector *vPtr;
- Tcl_Interp* interp;
-
- interp = dataPtr->interp;
- if (!Blt_ParseObjectName(interp, name, &objName,
- BLT_NO_ERROR_MSG | BLT_NO_DEFAULT_NS)) {
- return NULL; /* Can't find namespace. */
- }
- vPtr = NULL;
- if (objName.nsPtr != NULL) {
- vPtr = FindVectorInNamespace(dataPtr, &objName);
- } else {
- if (flags & NS_SEARCH_CURRENT) {
- objName.nsPtr = Tcl_GetCurrentNamespace(interp);
- vPtr = FindVectorInNamespace(dataPtr, &objName);
- }
- if ((vPtr == NULL) && (flags & NS_SEARCH_GLOBAL)) {
- objName.nsPtr = Tcl_GetGlobalNamespace(interp);
- vPtr = FindVectorInNamespace(dataPtr, &objName);
- }
+ Blt_ObjectName objName;
+ Vector *vPtr;
+ Tcl_Interp* interp;
+
+ interp = dataPtr->interp;
+ if (!Blt_ParseObjectName(interp, name, &objName,
+ BLT_NO_ERROR_MSG | BLT_NO_DEFAULT_NS)) {
+ return NULL; /* Can't find namespace. */
+ }
+ vPtr = NULL;
+ if (objName.nsPtr != NULL) {
+ vPtr = FindVectorInNamespace(dataPtr, &objName);
+ } else {
+ if (flags & NS_SEARCH_CURRENT) {
+ objName.nsPtr = Tcl_GetCurrentNamespace(interp);
+ vPtr = FindVectorInNamespace(dataPtr, &objName);
+ }
+ if ((vPtr == NULL) && (flags & NS_SEARCH_GLOBAL)) {
+ objName.nsPtr = Tcl_GetGlobalNamespace(interp);
+ vPtr = FindVectorInNamespace(dataPtr, &objName);
}
- return vPtr;
+ }
+ return vPtr;
}
void
Blt_Vec_UpdateRange(Vector *vPtr)
{
- double min, max;
- double *vp, *vend;
-
- vp = vPtr->valueArr + vPtr->first;
- vend = vPtr->valueArr + vPtr->last;
- min = max = *vp++;
- for (/* empty */; vp <= vend; vp++) {
- if (min > *vp) {
- min = *vp;
- } else if (max < *vp) {
- max = *vp;
- }
+ double min, max;
+ double *vp, *vend;
+
+ vp = vPtr->valueArr + vPtr->first;
+ vend = vPtr->valueArr + vPtr->last;
+ min = max = *vp++;
+ for (/* empty */; vp <= vend; vp++) {
+ if (min > *vp) {
+ min = *vp;
+ } else if (max < *vp) {
+ max = *vp;
}
- vPtr->min = min;
- vPtr->max = max;
- vPtr->notifyFlags &= ~UPDATE_RANGE;
+ }
+ vPtr->min = min;
+ vPtr->max = max;
+ vPtr->notifyFlags &= ~UPDATE_RANGE;
}
/*
@@ -228,77 +228,77 @@ Blt_Vec_UpdateRange(Vector *vPtr)
*/
int
Blt_Vec_GetIndex(
- Tcl_Interp* interp,
- Vector *vPtr,
- const char *string,
- int *indexPtr,
- int flags,
- Blt_VectorIndexProc **procPtrPtr)
+ Tcl_Interp* interp,
+ Vector *vPtr,
+ const char *string,
+ int *indexPtr,
+ int flags,
+ Blt_VectorIndexProc **procPtrPtr)
{
- char c;
- int value;
+ char c;
+ int value;
- c = string[0];
+ c = string[0];
- /* Treat the index "end" like a numeric index. */
+ /* Treat the index "end" like a numeric index. */
- if ((c == 'e') && (strcmp(string, "end") == 0)) {
- if (vPtr->length < 1) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "bad index \"end\": vector is empty",
- (char *)NULL);
- }
- return TCL_ERROR;
- }
- *indexPtr = vPtr->length - 1;
- return TCL_OK;
- } else if ((c == '+') && (strcmp(string, "++end") == 0)) {
- *indexPtr = vPtr->length;
- return TCL_OK;
- }
- if (procPtrPtr != NULL) {
- Tcl_HashEntry *hPtr;
-
- hPtr = Tcl_FindHashEntry(&vPtr->dataPtr->indexProcTable, string);
- if (hPtr != NULL) {
- *indexPtr = SPECIAL_INDEX;
- *procPtrPtr = Tcl_GetHashValue(hPtr);
- return TCL_OK;
- }
+ if ((c == 'e') && (strcmp(string, "end") == 0)) {
+ if (vPtr->length < 1) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "bad index \"end\": vector is empty",
+ (char *)NULL);
+ }
+ return TCL_ERROR;
}
- if (Tcl_GetInt(interp, (char *)string, &value) != TCL_OK) {
- long int lvalue;
- /*
- * Unlike Tcl_GetInt, Tcl_ExprLong needs a valid interpreter, but the
- * interp passed in may be NULL. So we have to use vPtr->interp and
- * then reset the result.
- */
- if (Tcl_ExprLong(vPtr->interp, (char *)string, &lvalue) != TCL_OK) {
- Tcl_ResetResult(vPtr->interp);
- if (interp != NULL) {
- Tcl_AppendResult(interp, "bad index \"", string, "\"",
- (char *)NULL);
- }
- return TCL_ERROR;
- }
- value = (int)lvalue;
+ *indexPtr = vPtr->length - 1;
+ return TCL_OK;
+ } else if ((c == '+') && (strcmp(string, "++end") == 0)) {
+ *indexPtr = vPtr->length;
+ return TCL_OK;
+ }
+ if (procPtrPtr != NULL) {
+ Tcl_HashEntry *hPtr;
+
+ hPtr = Tcl_FindHashEntry(&vPtr->dataPtr->indexProcTable, string);
+ if (hPtr != NULL) {
+ *indexPtr = SPECIAL_INDEX;
+ *procPtrPtr = (Blt_VectorIndexProc*)Tcl_GetHashValue(hPtr);
+ return TCL_OK;
}
- /*
- * Correct the index by the current value of the offset. This makes all
- * the numeric indices non-negative, which is how we distinguish the
- * special non-numeric indices.
+ }
+ if (Tcl_GetInt(interp, (char *)string, &value) != TCL_OK) {
+ long int lvalue;
+ /*
+ * Unlike Tcl_GetInt, Tcl_ExprLong needs a valid interpreter, but the
+ * interp passed in may be NULL. So we have to use vPtr->interp and
+ * then reset the result.
*/
- value -= vPtr->offset;
-
- if ((value < 0) || ((flags & INDEX_CHECK) && (value >= vPtr->length))) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "index \"", string, "\" is out of range",
+ if (Tcl_ExprLong(vPtr->interp, (char *)string, &lvalue) != TCL_OK) {
+ Tcl_ResetResult(vPtr->interp);
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "bad index \"", string, "\"",
(char *)NULL);
- }
- return TCL_ERROR;
+ }
+ return TCL_ERROR;
}
- *indexPtr = (int)value;
- return TCL_OK;
+ value = (int)lvalue;
+ }
+ /*
+ * Correct the index by the current value of the offset. This makes all
+ * the numeric indices non-negative, which is how we distinguish the
+ * special non-numeric indices.
+ */
+ value -= vPtr->offset;
+
+ if ((value < 0) || ((flags & INDEX_CHECK) && (value >= vPtr->length))) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "index \"", string, "\" is out of range",
+ (char *)NULL);
+ }
+ return TCL_ERROR;
+ }
+ *indexPtr = (int)value;
+ return TCL_OK;
}
/*
@@ -319,132 +319,132 @@ Blt_Vec_GetIndex(
*/
int
Blt_Vec_GetIndexRange(
- Tcl_Interp* interp,
- Vector *vPtr,
- const char *string,
- int flags,
- Blt_VectorIndexProc **procPtrPtr)
+ Tcl_Interp* interp,
+ Vector *vPtr,
+ const char *string,
+ int flags,
+ Blt_VectorIndexProc **procPtrPtr)
{
- int ielem;
- char *colon;
-
- colon = NULL;
- if (flags & INDEX_COLON) {
- colon = strchr(string, ':');
- }
- if (colon != NULL) {
- if (string == colon) {
- vPtr->first = 0; /* Default to the first index */
- } else {
- int result;
-
- *colon = '\0';
- result = Blt_Vec_GetIndex(interp, vPtr, string, &ielem, flags,
- (Blt_VectorIndexProc **) NULL);
- *colon = ':';
- if (result != TCL_OK) {
- return TCL_ERROR;
- }
- vPtr->first = ielem;
- }
- if (*(colon + 1) == '\0') {
- /* Default to the last index */
- vPtr->last = (vPtr->length > 0) ? vPtr->length - 1 : 0;
- } else {
- if (Blt_Vec_GetIndex(interp, vPtr, colon + 1, &ielem, flags,
- (Blt_VectorIndexProc **) NULL) != TCL_OK) {
- return TCL_ERROR;
- }
- vPtr->last = ielem;
- }
- if (vPtr->first > vPtr->last) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "bad range \"", string,
- "\" (first > last)", (char *)NULL);
- }
- return TCL_ERROR;
- }
+ int ielem;
+ char *colon;
+
+ colon = NULL;
+ if (flags & INDEX_COLON) {
+ colon = strchr(string, ':');
+ }
+ if (colon != NULL) {
+ if (string == colon) {
+ vPtr->first = 0; /* Default to the first index */
} else {
- if (Blt_Vec_GetIndex(interp, vPtr, string, &ielem, flags,
- procPtrPtr) != TCL_OK) {
- return TCL_ERROR;
- }
- vPtr->last = vPtr->first = ielem;
+ int result;
+
+ *colon = '\0';
+ result = Blt_Vec_GetIndex(interp, vPtr, string, &ielem, flags,
+ (Blt_VectorIndexProc **) NULL);
+ *colon = ':';
+ if (result != TCL_OK) {
+ return TCL_ERROR;
+ }
+ vPtr->first = ielem;
}
- return TCL_OK;
+ if (*(colon + 1) == '\0') {
+ /* Default to the last index */
+ vPtr->last = (vPtr->length > 0) ? vPtr->length - 1 : 0;
+ } else {
+ if (Blt_Vec_GetIndex(interp, vPtr, colon + 1, &ielem, flags,
+ (Blt_VectorIndexProc **) NULL) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ vPtr->last = ielem;
+ }
+ if (vPtr->first > vPtr->last) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "bad range \"", string,
+ "\" (first > last)", (char *)NULL);
+ }
+ return TCL_ERROR;
+ }
+ } else {
+ if (Blt_Vec_GetIndex(interp, vPtr, string, &ielem, flags,
+ procPtrPtr) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ vPtr->last = vPtr->first = ielem;
+ }
+ return TCL_OK;
}
Vector *
Blt_Vec_ParseElement(
- Tcl_Interp* interp,
- VectorInterpData *dataPtr, /* Interpreter-specific data. */
- const char *start,
- const char **endPtr,
- int flags)
+ Tcl_Interp* interp,
+ VectorInterpData *dataPtr, /* Interpreter-specific data. */
+ const char *start,
+ const char **endPtr,
+ int flags)
{
- char *p;
- char saved;
- Vector *vPtr;
+ char *p;
+ char saved;
+ Vector *vPtr;
+
+ p = (char *)start;
+ /* Find the end of the vector name */
+ while (VECTOR_CHAR(*p)) {
+ p++;
+ }
+ saved = *p;
+ *p = '\0';
- p = (char *)start;
- /* Find the end of the vector name */
- while (VECTOR_CHAR(*p)) {
- p++;
- }
- saved = *p;
- *p = '\0';
-
- vPtr = GetVectorObject(dataPtr, start, flags);
- if (vPtr == NULL) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "can't find vector \"", start, "\"",
- (char *)NULL);
- }
- *p = saved;
- return NULL;
+ vPtr = GetVectorObject(dataPtr, start, flags);
+ if (vPtr == NULL) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "can't find vector \"", start, "\"",
+ (char *)NULL);
}
*p = saved;
- vPtr->first = 0;
- vPtr->last = vPtr->length - 1;
- if (*p == '(') {
- int count, result;
-
- start = p + 1;
- p++;
-
- /* Find the matching right parenthesis */
- count = 1;
- while (*p != '\0') {
- if (*p == ')') {
- count--;
- if (count == 0) {
- break;
- }
- } else if (*p == '(') {
- count++;
- }
- p++;
- }
- if (count > 0) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "unbalanced parentheses \"", start,
- "\"", (char *)NULL);
- }
- return NULL;
- }
- *p = '\0';
- result = Blt_Vec_GetIndexRange(interp, vPtr, start,
- (INDEX_COLON | INDEX_CHECK), (Blt_VectorIndexProc **) NULL);
- *p = ')';
- if (result != TCL_OK) {
- return NULL;
+ return NULL;
+ }
+ *p = saved;
+ vPtr->first = 0;
+ vPtr->last = vPtr->length - 1;
+ if (*p == '(') {
+ int count, result;
+
+ start = p + 1;
+ p++;
+
+ /* Find the matching right parenthesis */
+ count = 1;
+ while (*p != '\0') {
+ if (*p == ')') {
+ count--;
+ if (count == 0) {
+ break;
}
- p++;
+ } else if (*p == '(') {
+ count++;
+ }
+ p++;
}
- if (endPtr != NULL) {
- *endPtr = p;
+ if (count > 0) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "unbalanced parentheses \"", start,
+ "\"", (char *)NULL);
+ }
+ return NULL;
}
- return vPtr;
+ *p = '\0';
+ result = Blt_Vec_GetIndexRange(interp, vPtr, start,
+ (INDEX_COLON | INDEX_CHECK), (Blt_VectorIndexProc **) NULL);
+ *p = ')';
+ if (result != TCL_OK) {
+ return NULL;
+ }
+ p++;
+ }
+ if (endPtr != NULL) {
+ *endPtr = p;
+ }
+ return vPtr;
}
@@ -469,36 +469,32 @@ Blt_Vec_ParseElement(
void
Blt_Vec_NotifyClients(ClientData clientData)
{
- Vector *vPtr = clientData;
- Blt_ChainLink link, next;
- Blt_VectorNotify notify;
-
- notify = (vPtr->notifyFlags & NOTIFY_DESTROYED)
- ? BLT_VECTOR_NOTIFY_DESTROY : BLT_VECTOR_NOTIFY_UPDATE;
- vPtr->notifyFlags &= ~(NOTIFY_UPDATED | NOTIFY_DESTROYED | NOTIFY_PENDING);
- for (link = Blt_Chain_FirstLink(vPtr->chain); link != NULL; link = next) {
- VectorClient *clientPtr;
-
- next = Blt_Chain_NextLink(link);
- clientPtr = Blt_Chain_GetValue(link);
- if ((clientPtr->proc != NULL) && (clientPtr->serverPtr != NULL)) {
- (*clientPtr->proc) (vPtr->interp, clientPtr->clientData, notify);
- }
+ Vector* vPtr = (Vector*)clientData;
+ Blt_ChainLink link, next;
+ Blt_VectorNotify notify;
+
+ notify = (vPtr->notifyFlags & NOTIFY_DESTROYED)
+ ? BLT_VECTOR_NOTIFY_DESTROY : BLT_VECTOR_NOTIFY_UPDATE;
+ vPtr->notifyFlags &= ~(NOTIFY_UPDATED | NOTIFY_DESTROYED | NOTIFY_PENDING);
+ for (link = Blt_Chain_FirstLink(vPtr->chain); link != NULL; link = next) {
+ next = Blt_Chain_NextLink(link);
+ VectorClient *clientPtr = (VectorClient*)Blt_Chain_GetValue(link);
+ if ((clientPtr->proc != NULL) && (clientPtr->serverPtr != NULL)) {
+ (*clientPtr->proc) (vPtr->interp, clientPtr->clientData, notify);
}
- /*
- * Some clients may not handle the "destroy" callback properly (they
- * should call Blt_FreeVectorId to release the client identifier), so mark
- * any remaining clients to indicate that vector's server has gone away.
- */
- if (notify == BLT_VECTOR_NOTIFY_DESTROY) {
- for (link = Blt_Chain_FirstLink(vPtr->chain); link != NULL;
- link = Blt_Chain_NextLink(link)) {
- VectorClient *clientPtr;
-
- clientPtr = Blt_Chain_GetValue(link);
- clientPtr->serverPtr = NULL;
- }
+ }
+ /*
+ * Some clients may not handle the "destroy" callback properly (they
+ * should call Blt_FreeVectorId to release the client identifier), so mark
+ * any remaining clients to indicate that vector's server has gone away.
+ */
+ if (notify == BLT_VECTOR_NOTIFY_DESTROY) {
+ for (link = Blt_Chain_FirstLink(vPtr->chain); link != NULL;
+ link = Blt_Chain_NextLink(link)) {
+ VectorClient *clientPtr = (VectorClient*)Blt_Chain_GetValue(link);
+ clientPtr->serverPtr = NULL;
}
+ }
}
/*
@@ -520,20 +516,20 @@ Blt_Vec_NotifyClients(ClientData clientData)
void
Blt_Vec_UpdateClients(Vector *vPtr)
{
- vPtr->dirty++;
- vPtr->max = vPtr->min = NAN;
- if (vPtr->notifyFlags & NOTIFY_NEVER) {
- return;
- }
- vPtr->notifyFlags |= NOTIFY_UPDATED;
- if (vPtr->notifyFlags & NOTIFY_ALWAYS) {
- Blt_Vec_NotifyClients(vPtr);
- return;
- }
- if (!(vPtr->notifyFlags & NOTIFY_PENDING)) {
- vPtr->notifyFlags |= NOTIFY_PENDING;
- Tcl_DoWhenIdle(Blt_Vec_NotifyClients, vPtr);
- }
+ vPtr->dirty++;
+ vPtr->max = vPtr->min = NAN;
+ if (vPtr->notifyFlags & NOTIFY_NEVER) {
+ return;
+ }
+ vPtr->notifyFlags |= NOTIFY_UPDATED;
+ if (vPtr->notifyFlags & NOTIFY_ALWAYS) {
+ Blt_Vec_NotifyClients(vPtr);
+ return;
+ }
+ if (!(vPtr->notifyFlags & NOTIFY_PENDING)) {
+ vPtr->notifyFlags |= NOTIFY_PENDING;
+ Tcl_DoWhenIdle(Blt_Vec_NotifyClients, vPtr);
+ }
}
/*
@@ -563,24 +559,24 @@ Blt_Vec_UpdateClients(Vector *vPtr)
void
Blt_Vec_FlushCache(Vector *vPtr)
{
- Tcl_Interp* interp = vPtr->interp;
+ Tcl_Interp* interp = vPtr->interp;
- if (vPtr->arrayName == NULL) {
- return; /* Doesn't use the variable API */
- }
- /* Turn off the trace temporarily so that we can unset all the
- * elements in the array. */
+ if (vPtr->arrayName == NULL) {
+ return; /* Doesn't use the variable API */
+ }
+ /* Turn off the trace temporarily so that we can unset all the
+ * elements in the array. */
- Tcl_UntraceVar2(interp, vPtr->arrayName, (char *)NULL,
- TRACE_ALL | vPtr->varFlags, Blt_Vec_VarTrace, vPtr);
+ Tcl_UntraceVar2(interp, vPtr->arrayName, (char *)NULL,
+ TRACE_ALL | vPtr->varFlags, Blt_Vec_VarTrace, vPtr);
- /* Clear all the element entries from the entire array */
- Tcl_UnsetVar2(interp, vPtr->arrayName, (char *)NULL, vPtr->varFlags);
+ /* Clear all the element entries from the entire array */
+ Tcl_UnsetVar2(interp, vPtr->arrayName, (char *)NULL, vPtr->varFlags);
- /* Restore the "end" index by default and the trace on the entire array */
- Tcl_SetVar2(interp, vPtr->arrayName, "end", "", vPtr->varFlags);
- Tcl_TraceVar2(interp, vPtr->arrayName, (char *)NULL,
- TRACE_ALL | vPtr->varFlags, Blt_Vec_VarTrace, vPtr);
+ /* Restore the "end" index by default and the trace on the entire array */
+ Tcl_SetVar2(interp, vPtr->arrayName, "end", "", vPtr->varFlags);
+ Tcl_TraceVar2(interp, vPtr->arrayName, (char *)NULL,
+ TRACE_ALL | vPtr->varFlags, Blt_Vec_VarTrace, vPtr);
}
/*
@@ -600,62 +596,62 @@ Blt_Vec_FlushCache(Vector *vPtr)
*/
int
Blt_Vec_LookupName(
- VectorInterpData *dataPtr, /* Interpreter-specific data. */
- const char *vecName,
- Vector **vPtrPtr)
+ VectorInterpData *dataPtr, /* Interpreter-specific data. */
+ const char *vecName,
+ Vector **vPtrPtr)
{
- Vector *vPtr;
- const char *endPtr;
+ Vector *vPtr;
+ const char *endPtr;
- vPtr = Blt_Vec_ParseElement(dataPtr->interp, dataPtr, vecName, &endPtr,
- NS_SEARCH_BOTH);
- if (vPtr == NULL) {
- return TCL_ERROR;
- }
- if (*endPtr != '\0') {
- Tcl_AppendResult(dataPtr->interp,
- "extra characters after vector name", (char *)NULL);
- return TCL_ERROR;
- }
- *vPtrPtr = vPtr;
- return TCL_OK;
+ vPtr = Blt_Vec_ParseElement(dataPtr->interp, dataPtr, vecName, &endPtr,
+ NS_SEARCH_BOTH);
+ if (vPtr == NULL) {
+ return TCL_ERROR;
+ }
+ if (*endPtr != '\0') {
+ Tcl_AppendResult(dataPtr->interp,
+ "extra characters after vector name", (char *)NULL);
+ return TCL_ERROR;
+ }
+ *vPtrPtr = vPtr;
+ return TCL_OK;
}
double
Blt_Vec_Min(Vector *vecObjPtr)
{
- double *vp, *vend;
- double min;
-
- vp = vecObjPtr->valueArr + vecObjPtr->first;
- vend = vecObjPtr->valueArr + vecObjPtr->last;
- min = *vp++;
- for (/* empty */; vp <= vend; vp++) {
- if (min > *vp) {
- min = *vp;
- }
+ double *vp, *vend;
+ double min;
+
+ vp = vecObjPtr->valueArr + vecObjPtr->first;
+ vend = vecObjPtr->valueArr + vecObjPtr->last;
+ min = *vp++;
+ for (/* empty */; vp <= vend; vp++) {
+ if (min > *vp) {
+ min = *vp;
}
- vecObjPtr->min = min;
- return vecObjPtr->min;
+ }
+ vecObjPtr->min = min;
+ return vecObjPtr->min;
}
double
Blt_Vec_Max(Vector *vecObjPtr)
{
- double max;
- double *vp, *vend;
-
- max = NAN;
- vp = vecObjPtr->valueArr + vecObjPtr->first;
- vend = vecObjPtr->valueArr + vecObjPtr->last;
- max = *vp++;
- for (/* empty */; vp <= vend; vp++) {
- if (max < *vp) {
- max = *vp;
- }
+ double max;
+ double *vp, *vend;
+
+ max = NAN;
+ vp = vecObjPtr->valueArr + vecObjPtr->first;
+ vend = vecObjPtr->valueArr + vecObjPtr->last;
+ max = *vp++;
+ for (/* empty */; vp <= vend; vp++) {
+ if (max < *vp) {
+ max = *vp;
}
- vecObjPtr->max = max;
- return vecObjPtr->max;
+ }
+ vecObjPtr->max = max;
+ return vecObjPtr->max;
}
/*
@@ -674,24 +670,24 @@ Blt_Vec_Max(Vector *vecObjPtr)
static void
DeleteCommand(Vector *vPtr) /* Vector associated with the TCL command. */
{
- Tcl_Interp* interp = vPtr->interp;
- char *qualName; /* Name of TCL command. */
- Tcl_CmdInfo cmdInfo;
- Tcl_DString dString;
- Blt_ObjectName objName;
-
- Tcl_DStringInit(&dString);
- objName.name = Tcl_GetCommandName(interp, vPtr->cmdToken);
- objName.nsPtr = Blt_GetCommandNamespace(vPtr->cmdToken);
- qualName = Blt_MakeQualifiedName(&objName, &dString);
- if (Tcl_GetCommandInfo(interp, qualName, &cmdInfo)) {
- /* Disable the callback before deleting the TCL command.*/
- cmdInfo.deleteProc = NULL;
- Tcl_SetCommandInfo(interp, qualName, &cmdInfo);
- Tcl_DeleteCommandFromToken(interp, vPtr->cmdToken);
- }
- Tcl_DStringFree(&dString);
- vPtr->cmdToken = 0;
+ Tcl_Interp* interp = vPtr->interp;
+ char *qualName; /* Name of TCL command. */
+ Tcl_CmdInfo cmdInfo;
+ Tcl_DString dString;
+ Blt_ObjectName objName;
+
+ Tcl_DStringInit(&dString);
+ objName.name = Tcl_GetCommandName(interp, vPtr->cmdToken);
+ objName.nsPtr = Blt_GetCommandNamespace(vPtr->cmdToken);
+ qualName = Blt_MakeQualifiedName(&objName, &dString);
+ if (Tcl_GetCommandInfo(interp, qualName, &cmdInfo)) {
+ /* Disable the callback before deleting the TCL command.*/
+ cmdInfo.deleteProc = NULL;
+ Tcl_SetCommandInfo(interp, qualName, &cmdInfo);
+ Tcl_DeleteCommandFromToken(interp, vPtr->cmdToken);
+ }
+ Tcl_DStringFree(&dString);
+ vPtr->cmdToken = 0;
}
/*
@@ -710,17 +706,17 @@ DeleteCommand(Vector *vPtr) /* Vector associated with the TCL command. */
static void
UnmapVariable(Vector *vPtr)
{
- Tcl_Interp* interp = vPtr->interp;
+ Tcl_Interp* interp = vPtr->interp;
- /* Unset the entire array */
- Tcl_UntraceVar2(interp, vPtr->arrayName, (char *)NULL,
- (TRACE_ALL | vPtr->varFlags), Blt_Vec_VarTrace, vPtr);
- Tcl_UnsetVar2(interp, vPtr->arrayName, (char *)NULL, vPtr->varFlags);
+ /* Unset the entire array */
+ Tcl_UntraceVar2(interp, vPtr->arrayName, (char *)NULL,
+ (TRACE_ALL | vPtr->varFlags), Blt_Vec_VarTrace, vPtr);
+ Tcl_UnsetVar2(interp, vPtr->arrayName, (char *)NULL, vPtr->varFlags);
- if (vPtr->arrayName != NULL) {
- free((void*)(vPtr->arrayName));
- vPtr->arrayName = NULL;
- }
+ if (vPtr->arrayName != NULL) {
+ free((void*)(vPtr->arrayName));
+ vPtr->arrayName = NULL;
+ }
}
/*
@@ -747,65 +743,65 @@ UnmapVariable(Vector *vPtr)
*/
int
Blt_Vec_MapVariable(
- Tcl_Interp* interp,
- Vector *vPtr,
- const char *path)
+ Tcl_Interp* interp,
+ Vector *vPtr,
+ const char *path)
{
- Blt_ObjectName objName;
- char *newPath;
- const char *result;
- Tcl_DString dString;
+ Blt_ObjectName objName;
+ char *newPath;
+ const char *result;
+ Tcl_DString dString;
- if (vPtr->arrayName != NULL) {
- UnmapVariable(vPtr);
- }
- if ((path == NULL) || (path[0] == '\0')) {
- return TCL_OK; /* If the variable pathname is the empty
+ if (vPtr->arrayName != NULL) {
+ UnmapVariable(vPtr);
+ }
+ if ((path == NULL) || (path[0] == '\0')) {
+ return TCL_OK; /* If the variable pathname is the empty
* string, simply return after removing any
* existing variable. */
- }
- /* Get the variable name (without the namespace qualifier). */
- if (!Blt_ParseObjectName(interp, path, &objName, BLT_NO_DEFAULT_NS)) {
- return TCL_ERROR;
- }
- if (objName.nsPtr == NULL) {
- /*
- * If there was no namespace qualifier, try harder to see if the
- * variable is non-local.
- */
- objName.nsPtr = Blt_GetVariableNamespace(interp, objName.name);
- }
- Tcl_DStringInit(&dString);
- vPtr->varFlags = 0;
- if (objName.nsPtr != NULL) { /* Global or namespace variable. */
- newPath = Blt_MakeQualifiedName(&objName, &dString);
- vPtr->varFlags |= (TCL_GLOBAL_ONLY);
- } else { /* Local variable. */
- newPath = (char *)objName.name;
- }
-
- /*
- * To play it safe, delete the variable first. This has the benefical
- * side-effect of unmapping the variable from another vector that may be
- * currently associated with it.
- */
- Tcl_UnsetVar2(interp, newPath, (char *)NULL, 0);
-
+ }
+ /* Get the variable name (without the namespace qualifier). */
+ if (!Blt_ParseObjectName(interp, path, &objName, BLT_NO_DEFAULT_NS)) {
+ return TCL_ERROR;
+ }
+ if (objName.nsPtr == NULL) {
/*
- * Set the index "end" in the array. This will create the variable
- * immediately so that we can check its namespace context.
+ * If there was no namespace qualifier, try harder to see if the
+ * variable is non-local.
*/
- result = Tcl_SetVar2(interp, newPath, "end", "", TCL_LEAVE_ERR_MSG);
- if (result == NULL) {
- Tcl_DStringFree(&dString);
- return TCL_ERROR;
- }
- /* Create a full-array trace on reads, writes, and unsets. */
- Tcl_TraceVar2(interp, newPath, (char *)NULL, TRACE_ALL, Blt_Vec_VarTrace,
- vPtr);
- vPtr->arrayName = Blt_Strdup(newPath);
+ objName.nsPtr = Blt_GetVariableNamespace(interp, objName.name);
+ }
+ Tcl_DStringInit(&dString);
+ vPtr->varFlags = 0;
+ if (objName.nsPtr != NULL) { /* Global or namespace variable. */
+ newPath = Blt_MakeQualifiedName(&objName, &dString);
+ vPtr->varFlags |= (TCL_GLOBAL_ONLY);
+ } else { /* Local variable. */
+ newPath = (char *)objName.name;
+ }
+
+ /*
+ * To play it safe, delete the variable first. This has the benefical
+ * side-effect of unmapping the variable from another vector that may be
+ * currently associated with it.
+ */
+ Tcl_UnsetVar2(interp, newPath, (char *)NULL, 0);
+
+ /*
+ * Set the index "end" in the array. This will create the variable
+ * immediately so that we can check its namespace context.
+ */
+ result = Tcl_SetVar2(interp, newPath, "end", "", TCL_LEAVE_ERR_MSG);
+ if (result == NULL) {
Tcl_DStringFree(&dString);
- return TCL_OK;
+ return TCL_ERROR;
+ }
+ /* Create a full-array trace on reads, writes, and unsets. */
+ Tcl_TraceVar2(interp, newPath, (char *)NULL, TRACE_ALL, Blt_Vec_VarTrace,
+ vPtr);
+ vPtr->arrayName = Blt_Strdup(newPath);
+ Tcl_DStringFree(&dString);
+ return TCL_OK;
}
/*
@@ -832,84 +828,80 @@ Blt_Vec_MapVariable(
*/
int
Blt_Vec_SetSize(
- Tcl_Interp* interp,
- Vector *vPtr,
- int newSize) /* Size of array in elements */
+ Tcl_Interp* interp,
+ Vector *vPtr,
+ int newSize) /* Size of array in elements */
{
- if (newSize <= 0) {
- newSize = DEF_ARRAY_SIZE;
- }
- if (newSize == vPtr->size) {
- /* Same size, use the current array. */
- return TCL_OK;
- }
- if (vPtr->freeProc == TCL_DYNAMIC) {
- double *newArr;
-
- /* Old memory was dynamically allocated, so use realloc. */
- newArr = realloc(vPtr->valueArr, newSize * sizeof(double));
- if (newArr == NULL) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "can't reallocate ",
- Blt_Itoa(newSize), " elements for vector \"",
- vPtr->name, "\"", (char *)NULL);
- }
- return TCL_ERROR;
- }
- vPtr->size = newSize;
- vPtr->valueArr = newArr;
- return TCL_OK;
+ if (newSize <= 0) {
+ newSize = DEF_ARRAY_SIZE;
+ }
+ if (newSize == vPtr->size) {
+ /* Same size, use the current array. */
+ return TCL_OK;
+ }
+ if (vPtr->freeProc == TCL_DYNAMIC) {
+ /* Old memory was dynamically allocated, so use realloc. */
+ double* newArr = (double*)realloc(vPtr->valueArr, newSize * sizeof(double));
+ if (newArr == NULL) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "can't reallocate ",
+ Blt_Itoa(newSize), " elements for vector \"",
+ vPtr->name, "\"", (char *)NULL);
+ }
+ return TCL_ERROR;
}
+ vPtr->size = newSize;
+ vPtr->valueArr = newArr;
+ return TCL_OK;
+ }
+
+ {
+ /* Old memory was created specially (static or special allocator).
+ * Replace with dynamically allocated memory (malloc-ed). */
+ double* newArr = (double*)calloc(newSize, sizeof(double));
+ if (newArr == NULL) {
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "can't allocate ",
+ Blt_Itoa(newSize), " elements for vector \"",
+ vPtr->name, "\"", (char *)NULL);
+ }
+ return TCL_ERROR;
+ }
{
- double *newArr;
-
- /* Old memory was created specially (static or special allocator).
- * Replace with dynamically allocated memory (malloc-ed). */
-
- newArr = calloc(newSize, sizeof(double));
- if (newArr == NULL) {
- if (interp != NULL) {
- Tcl_AppendResult(interp, "can't allocate ",
- Blt_Itoa(newSize), " elements for vector \"",
- vPtr->name, "\"", (char *)NULL);
- }
- return TCL_ERROR;
- }
- {
- int used, wanted;
+ int used, wanted;
- /* Copy the contents of the old memory into the new. */
- used = vPtr->length;
- wanted = newSize;
+ /* Copy the contents of the old memory into the new. */
+ used = vPtr->length;
+ wanted = newSize;
- if (used > wanted) {
- used = wanted;
- }
- /* Copy any previous data */
- if (used > 0) {
- memcpy(newArr, vPtr->valueArr, used * sizeof(double));
- }
- }
+ if (used > wanted) {
+ used = wanted;
+ }
+ /* Copy any previous data */
+ if (used > 0) {
+ memcpy(newArr, vPtr->valueArr, used * sizeof(double));
+ }
+ }
- /*
- * We're not using the old storage anymore, so free it if it's not
- * TCL_STATIC. It's static because the user previously reset the
- * vector with a statically allocated array (setting freeProc to
- * TCL_STATIC).
- */
- if (vPtr->freeProc != TCL_STATIC) {
- if (vPtr->freeProc == TCL_DYNAMIC) {
- free(vPtr->valueArr);
- } else {
- (*vPtr->freeProc) ((char *)vPtr->valueArr);
- }
- }
- vPtr->freeProc = TCL_DYNAMIC; /* Set the type of the new storage */
- vPtr->valueArr = newArr;
- vPtr->size = newSize;
+ /*
+ * We're not using the old storage anymore, so free it if it's not
+ * TCL_STATIC. It's static because the user previously reset the
+ * vector with a statically allocated array (setting freeProc to
+ * TCL_STATIC).
+ */
+ if (vPtr->freeProc != TCL_STATIC) {
+ if (vPtr->freeProc == TCL_DYNAMIC) {
+ free(vPtr->valueArr);
+ } else {
+ (*vPtr->freeProc) ((char *)vPtr->valueArr);
+ }
}
- return TCL_OK;
+ vPtr->freeProc = TCL_DYNAMIC; /* Set the type of the new storage */
+ vPtr->valueArr = newArr;
+ vPtr->size = newSize;
+ }
+ return TCL_OK;
}
/*
@@ -932,19 +924,19 @@ Blt_Vec_SetSize(
*/
int
Blt_Vec_SetLength(
- Tcl_Interp* interp,
- Vector *vPtr,
- int newLength) /* Size of array in elements */
+ Tcl_Interp* interp,
+ Vector *vPtr,
+ int newLength) /* Size of array in elements */
{
- if (vPtr->size < newLength) {
- if (Blt_Vec_SetSize(interp, vPtr, newLength) != TCL_OK) {
- return TCL_ERROR;
- }
+ if (vPtr->size < newLength) {
+ if (Blt_Vec_SetSize(interp, vPtr, newLength) != TCL_OK) {
+ return TCL_ERROR;
}
- vPtr->length = newLength;
- vPtr->first = 0;
- vPtr->last = newLength - 1;
- return TCL_OK;
+ }
+ vPtr->length = newLength;
+ vPtr->first = 0;
+ vPtr->last = newLength - 1;
+ return TCL_OK;
}
/*
@@ -978,32 +970,32 @@ Blt_Vec_SetLength(
int
Blt_Vec_ChangeLength(
- Tcl_Interp* interp,
- Vector *vPtr,
- int newLength)
+ Tcl_Interp* interp,
+ Vector *vPtr,
+ int newLength)
{
- if (newLength < 0) {
- newLength = 0;
- }
- if (newLength > vPtr->size) {
- int newSize; /* Size of array in elements */
+ if (newLength < 0) {
+ newLength = 0;
+ }
+ if (newLength > vPtr->size) {
+ int newSize; /* Size of array in elements */
- /* Compute the new size of the array. It's a multiple of
- * DEF_ARRAY_SIZE. */
- newSize = DEF_ARRAY_SIZE;
- while (newSize < newLength) {
- newSize += newSize;
- }
- if (newSize != vPtr->size) {
- if (Blt_Vec_SetSize(interp, vPtr, newSize) != TCL_OK) {
- return TCL_ERROR;
- }
- }
+ /* Compute the new size of the array. It's a multiple of
+ * DEF_ARRAY_SIZE. */
+ newSize = DEF_ARRAY_SIZE;
+ while (newSize < newLength) {
+ newSize += newSize;
+ }
+ if (newSize != vPtr->size) {
+ if (Blt_Vec_SetSize(interp, vPtr, newSize) != TCL_OK) {
+ return TCL_ERROR;
+ }
}
- vPtr->length = newLength;
- vPtr->first = 0;
- vPtr->last = newLength - 1;
- return TCL_OK;
+ }
+ vPtr->length = newLength;
+ vPtr->first = 0;
+ vPtr->last = newLength - 1;
+ return TCL_OK;
}
@@ -1030,93 +1022,91 @@ Blt_Vec_ChangeLength(
*/
int
Blt_Vec_Reset(
- Vector *vPtr,
- double *valueArr, /* Array containing the elements of the
- * vector. If NULL, indicates to reset the
- * vector size to the default. */
- int length, /* The number of elements that the vector
- * currently holds. */
- int size, /* The maximum number of elements that the
- * array can hold. */
- Tcl_FreeProc *freeProc) /* Address of memory deallocation routine
- * for the array of values. Can also be
- * TCL_STATIC, TCL_DYNAMIC, or TCL_VOLATILE. */
+ Vector *vPtr,
+ double *valueArr, /* Array containing the elements of the
+ * vector. If NULL, indicates to reset the
+ * vector size to the default. */
+ int length, /* The number of elements that the vector
+ * currently holds. */
+ int size, /* The maximum number of elements that the
+ * array can hold. */
+ Tcl_FreeProc *freeProc) /* Address of memory deallocation routine
+ * for the array of values. Can also be
+ * TCL_STATIC, TCL_DYNAMIC, or TCL_VOLATILE. */
{
- if (vPtr->valueArr != valueArr) { /* New array of values resides
+ if (vPtr->valueArr != valueArr) { /* New array of values resides
* in different memory than
* the current vector. */
- if ((valueArr == NULL) || (size == 0)) {
- /* Empty array. Set up default values */
- valueArr = malloc(sizeof(double) * DEF_ARRAY_SIZE);
- size = DEF_ARRAY_SIZE;
- if (valueArr == NULL) {
- Tcl_AppendResult(vPtr->interp, "can't allocate ",
- Blt_Itoa(size), " elements for vector \"",
- vPtr->name, "\"", (char *)NULL);
- return TCL_ERROR;
- }
- freeProc = TCL_DYNAMIC;
- length = 0;
- } else if (freeProc == TCL_VOLATILE) {
- double *newArr;
- /* Data is volatile. Make a copy of the value array. */
- newArr = malloc(size * sizeof(double));
- if (newArr == NULL) {
- Tcl_AppendResult(vPtr->interp, "can't allocate ",
- Blt_Itoa(size), " elements for vector \"",
- vPtr->name, "\"", (char *)NULL);
- return TCL_ERROR;
- }
- memcpy((char *)newArr, (char *)valueArr,
- sizeof(double) * length);
- valueArr = newArr;
- freeProc = TCL_DYNAMIC;
- }
-
- if (vPtr->freeProc != TCL_STATIC) {
- /* Old data was dynamically allocated. Free it before attaching
- * new data. */
- if (vPtr->freeProc == TCL_DYNAMIC) {
- free(vPtr->valueArr);
- } else {
- (*freeProc) ((char *)vPtr->valueArr);
- }
- }
- vPtr->freeProc = freeProc;
- vPtr->valueArr = valueArr;
- vPtr->size = size;
- }
+ if ((valueArr == NULL) || (size == 0)) {
+ /* Empty array. Set up default values */
+ valueArr = (double*)malloc(sizeof(double) * DEF_ARRAY_SIZE);
+ size = DEF_ARRAY_SIZE;
+ if (valueArr == NULL) {
+ Tcl_AppendResult(vPtr->interp, "can't allocate ",
+ Blt_Itoa(size), " elements for vector \"",
+ vPtr->name, "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ freeProc = TCL_DYNAMIC;
+ length = 0;
+ }
+ else if (freeProc == TCL_VOLATILE) {
+ /* Data is volatile. Make a copy of the value array. */
+ double* newArr = (double*)malloc(size * sizeof(double));
+ if (newArr == NULL) {
+ Tcl_AppendResult(vPtr->interp, "can't allocate ",
+ Blt_Itoa(size), " elements for vector \"",
+ vPtr->name, "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ memcpy((char *)newArr, (char *)valueArr,
+ sizeof(double) * length);
+ valueArr = newArr;
+ freeProc = TCL_DYNAMIC;
+ }
- vPtr->length = length;
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
+ if (vPtr->freeProc != TCL_STATIC) {
+ /* Old data was dynamically allocated. Free it before attaching
+ * new data. */
+ if (vPtr->freeProc == TCL_DYNAMIC) {
+ free(vPtr->valueArr);
+ } else {
+ (*freeProc) ((char *)vPtr->valueArr);
+ }
}
- Blt_Vec_UpdateClients(vPtr);
- return TCL_OK;
+ vPtr->freeProc = freeProc;
+ vPtr->valueArr = valueArr;
+ vPtr->size = size;
+ }
+
+ vPtr->length = length;
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ return TCL_OK;
}
Vector *
Blt_Vec_New(VectorInterpData *dataPtr) /* Interpreter-specific data. */
{
- Vector *vPtr;
-
- vPtr = calloc(1, sizeof(Vector));
- vPtr->valueArr = malloc(sizeof(double) * DEF_ARRAY_SIZE);
- if (vPtr->valueArr == NULL) {
- free(vPtr);
- return NULL;
- }
- vPtr->size = DEF_ARRAY_SIZE;
- vPtr->freeProc = TCL_DYNAMIC;
- vPtr->length = 0;
- vPtr->interp = dataPtr->interp;
- vPtr->hashPtr = NULL;
- vPtr->chain = Blt_Chain_Create();
- vPtr->flush = 0;
- vPtr->min = vPtr->max = NAN;
- vPtr->notifyFlags = NOTIFY_WHENIDLE;
- vPtr->dataPtr = dataPtr;
- return vPtr;
+ Vector* vPtr = (Vector*)calloc(1, sizeof(Vector));
+ vPtr->valueArr = (double*)malloc(sizeof(double) * DEF_ARRAY_SIZE);
+ if (vPtr->valueArr == NULL) {
+ free(vPtr);
+ return NULL;
+ }
+ vPtr->size = DEF_ARRAY_SIZE;
+ vPtr->freeProc = TCL_DYNAMIC;
+ vPtr->length = 0;
+ vPtr->interp = dataPtr->interp;
+ vPtr->hashPtr = NULL;
+ vPtr->chain = Blt_Chain_Create();
+ vPtr->flush = 0;
+ vPtr->min = vPtr->max = NAN;
+ vPtr->notifyFlags = NOTIFY_WHENIDLE;
+ vPtr->dataPtr = dataPtr;
+ return vPtr;
}
/*
@@ -1145,48 +1135,46 @@ Blt_Vec_New(VectorInterpData *dataPtr) /* Interpreter-specific data. */
void
Blt_Vec_Free(Vector *vPtr)
{
- Blt_ChainLink link;
+ Blt_ChainLink link;
- if (vPtr->cmdToken != 0) {
- DeleteCommand(vPtr);
- }
- if (vPtr->arrayName != NULL) {
- UnmapVariable(vPtr);
- }
- vPtr->length = 0;
+ if (vPtr->cmdToken != 0) {
+ DeleteCommand(vPtr);
+ }
+ if (vPtr->arrayName != NULL) {
+ UnmapVariable(vPtr);
+ }
+ vPtr->length = 0;
- /* Immediately notify clients that vector is going away */
- if (vPtr->notifyFlags & NOTIFY_PENDING) {
- vPtr->notifyFlags &= ~NOTIFY_PENDING;
- Tcl_CancelIdleCall(Blt_Vec_NotifyClients, vPtr);
- }
- vPtr->notifyFlags |= NOTIFY_DESTROYED;
- Blt_Vec_NotifyClients(vPtr);
+ /* Immediately notify clients that vector is going away */
+ if (vPtr->notifyFlags & NOTIFY_PENDING) {
+ vPtr->notifyFlags &= ~NOTIFY_PENDING;
+ Tcl_CancelIdleCall(Blt_Vec_NotifyClients, vPtr);
+ }
+ vPtr->notifyFlags |= NOTIFY_DESTROYED;
+ Blt_Vec_NotifyClients(vPtr);
- for (link = Blt_Chain_FirstLink(vPtr->chain); link != NULL;
- link = Blt_Chain_NextLink(link)) {
- VectorClient *clientPtr;
-
- clientPtr = Blt_Chain_GetValue(link);
- free(clientPtr);
- }
- Blt_Chain_Destroy(vPtr->chain);
- if ((vPtr->valueArr != NULL) && (vPtr->freeProc != TCL_STATIC)) {
- if (vPtr->freeProc == TCL_DYNAMIC) {
- free(vPtr->valueArr);
- } else {
- (*vPtr->freeProc) ((char *)vPtr->valueArr);
- }
- }
- if (vPtr->hashPtr != NULL) {
- Tcl_DeleteHashEntry(vPtr->hashPtr);
+ for (link = Blt_Chain_FirstLink(vPtr->chain); link != NULL;
+ link = Blt_Chain_NextLink(link)) {
+ VectorClient *clientPtr = (VectorClient*)Blt_Chain_GetValue(link);
+ free(clientPtr);
+ }
+ Blt_Chain_Destroy(vPtr->chain);
+ if ((vPtr->valueArr != NULL) && (vPtr->freeProc != TCL_STATIC)) {
+ if (vPtr->freeProc == TCL_DYNAMIC) {
+ free(vPtr->valueArr);
+ } else {
+ (*vPtr->freeProc) ((char *)vPtr->valueArr);
}
+ }
+ if (vPtr->hashPtr != NULL) {
+ Tcl_DeleteHashEntry(vPtr->hashPtr);
+ }
#ifdef NAMESPACE_DELETE_NOTIFY
- if (vPtr->nsPtr != NULL) {
- Blt_DestroyNsDeleteNotify(vPtr->interp, vPtr->nsPtr, vPtr);
- }
+ if (vPtr->nsPtr != NULL) {
+ Blt_DestroyNsDeleteNotify(vPtr->interp, vPtr->nsPtr, vPtr);
+ }
#endif /* NAMESPACE_DELETE_NOTIFY */
- free(vPtr);
+ free(vPtr);
}
/*
@@ -1205,10 +1193,9 @@ Blt_Vec_Free(Vector *vPtr)
static void
VectorInstDeleteProc(ClientData clientData)
{
- Vector *vPtr = clientData;
-
- vPtr->cmdToken = 0;
- Blt_Vec_Free(vPtr);
+ Vector *vPtr = (Vector*)clientData;
+ vPtr->cmdToken = 0;
+ Blt_Vec_Free(vPtr);
}
/*
@@ -1233,141 +1220,141 @@ VectorInstDeleteProc(ClientData clientData)
*/
Vector *
Blt_Vec_Create(
- VectorInterpData *dataPtr, /* Interpreter-specific data. */
- const char *vecName, /* Namespace-qualified name of the vector */
- const char *cmdName, /* Name of the TCL command mapped to
- * the vector */
- const char *varName, /* Name of the TCL array mapped to the
- * vector */
- int *isNewPtr)
+ VectorInterpData *dataPtr, /* Interpreter-specific data. */
+ const char *vecName, /* Namespace-qualified name of the vector */
+ const char *cmdName, /* Name of the TCL command mapped to
+ * the vector */
+ const char *varName, /* Name of the TCL array mapped to the
+ * vector */
+ int *isNewPtr)
{
- Tcl_DString dString;
- Vector *vPtr;
- int isNew;
- Blt_ObjectName objName;
- char *qualName;
- Tcl_HashEntry *hPtr;
- Tcl_Interp* interp = dataPtr->interp;
-
- isNew = 0;
- vPtr = NULL;
-
- if (!Blt_ParseObjectName(interp, vecName, &objName, 0)) {
- return NULL;
- }
- Tcl_DStringInit(&dString);
- if ((objName.name[0] == '#') && (strcmp(objName.name, "#auto") == 0)) {
-
- do { /* Generate a unique vector name. */
- char string[200];
-
- snprintf(string, 200, "vector%d", dataPtr->nextId++);
- objName.name = string;
- qualName = Blt_MakeQualifiedName(&objName, &dString);
- hPtr = Tcl_FindHashEntry(&dataPtr->vectorTable, qualName);
- } while (hPtr != NULL);
- } else {
- const char *p;
-
- for (p = objName.name; *p != '\0'; p++) {
- if (!VECTOR_CHAR(*p)) {
- Tcl_AppendResult(interp, "bad vector name \"", objName.name,
- "\": must contain digits, letters, underscore, or period",
- (char *)NULL);
- goto error;
- }
- }
- qualName = Blt_MakeQualifiedName(&objName, &dString);
- vPtr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, dataPtr, qualName,
- NULL, NS_SEARCH_CURRENT);
+ Tcl_DString dString;
+ Vector *vPtr;
+ int isNew;
+ Blt_ObjectName objName;
+ char *qualName;
+ Tcl_HashEntry *hPtr;
+ Tcl_Interp* interp = dataPtr->interp;
+
+ isNew = 0;
+ vPtr = NULL;
+
+ if (!Blt_ParseObjectName(interp, vecName, &objName, 0)) {
+ return NULL;
+ }
+ Tcl_DStringInit(&dString);
+ if ((objName.name[0] == '#') && (strcmp(objName.name, "#auto") == 0)) {
+
+ do { /* Generate a unique vector name. */
+ char string[200];
+
+ snprintf(string, 200, "vector%d", dataPtr->nextId++);
+ objName.name = string;
+ qualName = Blt_MakeQualifiedName(&objName, &dString);
+ hPtr = Tcl_FindHashEntry(&dataPtr->vectorTable, qualName);
+ } while (hPtr != NULL);
+ } else {
+ const char *p;
+
+ for (p = objName.name; *p != '\0'; p++) {
+ if (!VECTOR_CHAR(*p)) {
+ Tcl_AppendResult(interp, "bad vector name \"", objName.name,
+ "\": must contain digits, letters, underscore, or period",
+ (char *)NULL);
+ goto error;
+ }
}
- if (vPtr == NULL) {
- hPtr = Tcl_CreateHashEntry(&dataPtr->vectorTable, qualName, &isNew);
- vPtr = Blt_Vec_New(dataPtr);
- vPtr->hashPtr = hPtr;
- vPtr->nsPtr = objName.nsPtr;
+ qualName = Blt_MakeQualifiedName(&objName, &dString);
+ vPtr = Blt_Vec_ParseElement((Tcl_Interp *)NULL, dataPtr, qualName,
+ NULL, NS_SEARCH_CURRENT);
+ }
+ if (vPtr == NULL) {
+ hPtr = Tcl_CreateHashEntry(&dataPtr->vectorTable, qualName, &isNew);
+ vPtr = Blt_Vec_New(dataPtr);
+ vPtr->hashPtr = hPtr;
+ vPtr->nsPtr = objName.nsPtr;
- vPtr->name = Tcl_GetHashKey(&dataPtr->vectorTable, hPtr);
+ vPtr->name = (const char*)Tcl_GetHashKey(&dataPtr->vectorTable, hPtr);
#ifdef NAMESPACE_DELETE_NOTIFY
- Blt_CreateNsDeleteNotify(interp, objName.nsPtr, vPtr,
- VectorInstDeleteProc);
+ Blt_CreateNsDeleteNotify(interp, objName.nsPtr, vPtr,
+ VectorInstDeleteProc);
#endif /* NAMESPACE_DELETE_NOTIFY */
- Tcl_SetHashValue(hPtr, vPtr);
- }
- if (cmdName != NULL) {
- Tcl_CmdInfo cmdInfo;
-
- if ((cmdName == vecName) ||
- ((cmdName[0] == '#') && (strcmp(cmdName, "#auto")==0))) {
- cmdName = qualName;
- }
- if (Tcl_GetCommandInfo(interp, (char *)cmdName, &cmdInfo)) {
- if (vPtr != cmdInfo.objClientData) {
- Tcl_AppendResult(interp, "command \"", cmdName,
+ Tcl_SetHashValue(hPtr, vPtr);
+ }
+ if (cmdName != NULL) {
+ Tcl_CmdInfo cmdInfo;
+
+ if ((cmdName == vecName) ||
+ ((cmdName[0] == '#') && (strcmp(cmdName, "#auto")==0))) {
+ cmdName = qualName;
+ }
+ if (Tcl_GetCommandInfo(interp, (char *)cmdName, &cmdInfo)) {
+ if (vPtr != cmdInfo.objClientData) {
+ Tcl_AppendResult(interp, "command \"", cmdName,
"\" already exists", (char *)NULL);
- goto error;
- }
- /* We get here only if the old name is the same as the new. */
- goto checkVariable;
- }
- }
- if (vPtr->cmdToken != 0) {
- DeleteCommand(vPtr); /* Command already exists, delete old first */
+ goto error;
+ }
+ /* We get here only if the old name is the same as the new. */
+ goto checkVariable;
}
- if (cmdName != NULL) {
- Tcl_DString dString2;
+ }
+ if (vPtr->cmdToken != 0) {
+ DeleteCommand(vPtr); /* Command already exists, delete old first */
+ }
+ if (cmdName != NULL) {
+ Tcl_DString dString2;
- Tcl_DStringInit(&dString2);
- if (cmdName != qualName) {
- if (!Blt_ParseObjectName(interp, cmdName, &objName, 0)) {
- goto error;
- }
- cmdName = Blt_MakeQualifiedName(&objName, &dString2);
- }
- vPtr->cmdToken = Tcl_CreateObjCommand(interp, (char *)cmdName,
- Blt_Vec_InstCmd, vPtr, VectorInstDeleteProc);
- Tcl_DStringFree(&dString2);
- }
- checkVariable:
- if (varName != NULL) {
- if ((varName[0] == '#') && (strcmp(varName, "#auto") == 0)) {
- varName = qualName;
- }
- if (Blt_Vec_MapVariable(interp, vPtr, varName) != TCL_OK) {
- goto error;
- }
+ Tcl_DStringInit(&dString2);
+ if (cmdName != qualName) {
+ if (!Blt_ParseObjectName(interp, cmdName, &objName, 0)) {
+ goto error;
+ }
+ cmdName = Blt_MakeQualifiedName(&objName, &dString2);
}
+ vPtr->cmdToken = Tcl_CreateObjCommand(interp, (char *)cmdName,
+ Blt_Vec_InstCmd, vPtr, VectorInstDeleteProc);
+ Tcl_DStringFree(&dString2);
+ }
+ checkVariable:
+ if (varName != NULL) {
+ if ((varName[0] == '#') && (strcmp(varName, "#auto") == 0)) {
+ varName = qualName;
+ }
+ if (Blt_Vec_MapVariable(interp, vPtr, varName) != TCL_OK) {
+ goto error;
+ }
+ }
- Tcl_DStringFree(&dString);
- *isNewPtr = isNew;
- return vPtr;
+ Tcl_DStringFree(&dString);
+ *isNewPtr = isNew;
+ return vPtr;
- error:
- Tcl_DStringFree(&dString);
- if (vPtr != NULL) {
- Blt_Vec_Free(vPtr);
- }
- return NULL;
+ error:
+ Tcl_DStringFree(&dString);
+ if (vPtr != NULL) {
+ Blt_Vec_Free(vPtr);
+ }
+ return NULL;
}
int
Blt_Vec_Duplicate(Vector *destPtr, Vector *srcPtr)
{
- size_t nBytes;
- size_t length;
+ size_t nBytes;
+ size_t length;
- if (destPtr == srcPtr) {
- /* Copying the same vector. */
- }
- length = srcPtr->last - srcPtr->first + 1;
- if (Blt_Vec_ChangeLength(destPtr->interp, destPtr, length) != TCL_OK) {
- return TCL_ERROR;
- }
- nBytes = length * sizeof(double);
- memcpy(destPtr->valueArr, srcPtr->valueArr + srcPtr->first, nBytes);
- destPtr->offset = srcPtr->offset;
- return TCL_OK;
+ if (destPtr == srcPtr) {
+ /* Copying the same vector. */
+ }
+ length = srcPtr->last - srcPtr->first + 1;
+ if (Blt_Vec_ChangeLength(destPtr->interp, destPtr, length) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ nBytes = length * sizeof(double);
+ memcpy(destPtr->valueArr, srcPtr->valueArr + srcPtr->first, nBytes);
+ destPtr->offset = srcPtr->offset;
+ return TCL_OK;
}
@@ -1387,51 +1374,47 @@ Blt_Vec_Duplicate(Vector *destPtr, Vector *srcPtr)
/*ARGSUSED*/
static int
VectorNamesOp(
- ClientData clientData, /* Interpreter-specific data. */
- Tcl_Interp* interp,
- int objc,
- Tcl_Obj* const objv[])
+ ClientData clientData, /* Interpreter-specific data. */
+ Tcl_Interp* interp,
+ int objc,
+ Tcl_Obj* const objv[])
{
- VectorInterpData *dataPtr = clientData;
- Tcl_Obj *listObjPtr;
+ VectorInterpData* dataPtr = (VectorInterpData*)clientData;
+ Tcl_Obj *listObjPtr;
- listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
- if (objc == 2) {
- Tcl_HashEntry *hPtr;
- Tcl_HashSearch cursor;
+ listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
+ if (objc == 2) {
+ Tcl_HashEntry *hPtr;
+ Tcl_HashSearch cursor;
- for (hPtr = Tcl_FirstHashEntry(&dataPtr->vectorTable, &cursor);
- hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
- char *name;
+ for (hPtr = Tcl_FirstHashEntry(&dataPtr->vectorTable, &cursor);
+ hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
+ char *name = (char*)Tcl_GetHashKey(&dataPtr->vectorTable, hPtr);
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewStringObj(name, -1));
+ }
+ } else {
+ Tcl_HashEntry *hPtr;
+ Tcl_HashSearch cursor;
- name = Tcl_GetHashKey(&dataPtr->vectorTable, hPtr);
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewStringObj(name, -1));
- }
- } else {
- Tcl_HashEntry *hPtr;
- Tcl_HashSearch cursor;
-
- for (hPtr = Tcl_FirstHashEntry(&dataPtr->vectorTable, &cursor);
- hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
- char *name;
- int i;
-
- name = Tcl_GetHashKey(&dataPtr->vectorTable, hPtr);
- for (i = 2; i < objc; i++) {
- char *pattern;
-
- pattern = Tcl_GetString(objv[i]);
- if (Tcl_StringMatch(name, pattern)) {
- Tcl_ListObjAppendElement(interp, listObjPtr,
- Tcl_NewStringObj(name, -1));
- break;
- }
- }
+ for (hPtr = Tcl_FirstHashEntry(&dataPtr->vectorTable, &cursor);
+ hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
+ char *name = (char*)Tcl_GetHashKey(&dataPtr->vectorTable, hPtr);
+ int i;
+ for (i = 2; i < objc; i++) {
+ char *pattern;
+
+ pattern = Tcl_GetString(objv[i]);
+ if (Tcl_StringMatch(name, pattern)) {
+ Tcl_ListObjAppendElement(interp, listObjPtr,
+ Tcl_NewStringObj(name, -1));
+ break;
}
+ }
}
- Tcl_SetObjResult(interp, listObjPtr);
- return TCL_OK;
+ }
+ Tcl_SetObjResult(interp, listObjPtr);
+ return TCL_OK;
}
/*
@@ -1458,146 +1441,146 @@ VectorNamesOp(
/*ARGSUSED*/
static int
VectorCreate2(
- ClientData clientData, /* Interpreter-specific data. */
- Tcl_Interp* interp,
- int argStart,
- int objc,
- Tcl_Obj* const objv[])
+ ClientData clientData, /* Interpreter-specific data. */
+ Tcl_Interp* interp,
+ int argStart,
+ int objc,
+ Tcl_Obj* const objv[])
{
- VectorInterpData *dataPtr = clientData;
- Vector *vPtr;
- int count, i;
- CreateSwitches switches;
-
- /*
- * Handle switches to the vector command and collect the vector name
- * arguments into an array.
- */
- count = 0;
- vPtr = NULL;
- for (i = argStart; i < objc; i++) {
- char *string;
-
- string = Tcl_GetString(objv[i]);
- if (string[0] == '-') {
- break;
- }
- }
- count = i - argStart;
- if (count == 0) {
- Tcl_AppendResult(interp, "no vector names supplied", (char *)NULL);
- return TCL_ERROR;
+ VectorInterpData *dataPtr = (VectorInterpData*)clientData;
+ Vector *vPtr;
+ int count, i;
+ CreateSwitches switches;
+
+ /*
+ * Handle switches to the vector command and collect the vector name
+ * arguments into an array.
+ */
+ count = 0;
+ vPtr = NULL;
+ for (i = argStart; i < objc; i++) {
+ char *string;
+
+ string = Tcl_GetString(objv[i]);
+ if (string[0] == '-') {
+ break;
}
- memset(&switches, 0, sizeof(switches));
- if (Blt_ParseSwitches(interp, createSwitches, objc - i, objv + i,
- &switches, BLT_SWITCH_DEFAULTS) < 0) {
- return TCL_ERROR;
+ }
+ count = i - argStart;
+ if (count == 0) {
+ Tcl_AppendResult(interp, "no vector names supplied", (char *)NULL);
+ return TCL_ERROR;
+ }
+ memset(&switches, 0, sizeof(switches));
+ if (Blt_ParseSwitches(interp, createSwitches, objc - i, objv + i,
+ &switches, BLT_SWITCH_DEFAULTS) < 0) {
+ return TCL_ERROR;
+ }
+ if (count > 1) {
+ if (switches.cmdName != NULL) {
+ Tcl_AppendResult(interp,
+ "can't specify more than one vector with \"-command\" switch",
+ (char *)NULL);
+ goto error;
+ }
+ if (switches.varName != NULL) {
+ Tcl_AppendResult(interp,
+ "can't specify more than one vector with \"-variable\" switch",
+ (char *)NULL);
+ goto error;
}
- if (count > 1) {
- if (switches.cmdName != NULL) {
- Tcl_AppendResult(interp,
- "can't specify more than one vector with \"-command\" switch",
- (char *)NULL);
- goto error;
- }
- if (switches.varName != NULL) {
- Tcl_AppendResult(interp,
- "can't specify more than one vector with \"-variable\" switch",
- (char *)NULL);
- goto error;
+ }
+ for (i = 0; i < count; i++) {
+ char *leftParen, *rightParen;
+ char *string;
+ int isNew;
+ int size, first, last;
+
+ size = first = last = 0;
+ string = Tcl_GetString(objv[i + argStart]);
+ leftParen = strchr(string, '(');
+ rightParen = strchr(string, ')');
+ if (((leftParen != NULL) && (rightParen == NULL)) ||
+ ((leftParen == NULL) && (rightParen != NULL)) ||
+ (leftParen > rightParen)) {
+ Tcl_AppendResult(interp, "bad vector specification \"", string,
+ "\"", (char *)NULL);
+ goto error;
+ }
+ if (leftParen != NULL) {
+ int result;
+ char *colon;
+
+ *rightParen = '\0';
+ colon = strchr(leftParen + 1, ':');
+ if (colon != NULL) {
+
+ /* Specification is in the form vecName(first:last) */
+ *colon = '\0';
+ result = Tcl_GetInt(interp, leftParen + 1, &first);
+ if ((*(colon + 1) != '\0') && (result == TCL_OK)) {
+ result = Tcl_GetInt(interp, colon + 1, &last);
+ if (first > last) {
+ Tcl_AppendResult(interp, "bad vector range \"",
+ string, "\"", (char *)NULL);
+ result = TCL_ERROR;
+ }
+ size = (last - first) + 1;
}
+ *colon = ':';
+ } else {
+ /* Specification is in the form vecName(size) */
+ result = Tcl_GetInt(interp, leftParen + 1, &size);
+ }
+ *rightParen = ')';
+ if (result != TCL_OK) {
+ goto error;
+ }
+ if (size < 0) {
+ Tcl_AppendResult(interp, "bad vector size \"", string, "\"",
+ (char *)NULL);
+ goto error;
+ }
}
- for (i = 0; i < count; i++) {
- char *leftParen, *rightParen;
- char *string;
- int isNew;
- int size, first, last;
-
- size = first = last = 0;
- string = Tcl_GetString(objv[i + argStart]);
- leftParen = strchr(string, '(');
- rightParen = strchr(string, ')');
- if (((leftParen != NULL) && (rightParen == NULL)) ||
- ((leftParen == NULL) && (rightParen != NULL)) ||
- (leftParen > rightParen)) {
- Tcl_AppendResult(interp, "bad vector specification \"", string,
- "\"", (char *)NULL);
- goto error;
- }
- if (leftParen != NULL) {
- int result;
- char *colon;
-
- *rightParen = '\0';
- colon = strchr(leftParen + 1, ':');
- if (colon != NULL) {
-
- /* Specification is in the form vecName(first:last) */
- *colon = '\0';
- result = Tcl_GetInt(interp, leftParen + 1, &first);
- if ((*(colon + 1) != '\0') && (result == TCL_OK)) {
- result = Tcl_GetInt(interp, colon + 1, &last);
- if (first > last) {
- Tcl_AppendResult(interp, "bad vector range \"",
- string, "\"", (char *)NULL);
- result = TCL_ERROR;
- }
- size = (last - first) + 1;
- }
- *colon = ':';
- } else {
- /* Specification is in the form vecName(size) */
- result = Tcl_GetInt(interp, leftParen + 1, &size);
- }
- *rightParen = ')';
- if (result != TCL_OK) {
- goto error;
- }
- if (size < 0) {
- Tcl_AppendResult(interp, "bad vector size \"", string, "\"",
- (char *)NULL);
- goto error;
- }
- }
- if (leftParen != NULL) {
- *leftParen = '\0';
- }
- /*
- * By default, we create a TCL command by the name of the vector.
- */
- vPtr = Blt_Vec_Create(dataPtr, string,
- (switches.cmdName == NULL) ? string : switches.cmdName,
- (switches.varName == NULL) ? string : switches.varName, &isNew);
- if (leftParen != NULL) {
- *leftParen = '(';
- }
- if (vPtr == NULL) {
- goto error;
- }
- vPtr->freeOnUnset = switches.watchUnset;
- vPtr->flush = switches.flush;
- vPtr->offset = first;
- if (size > 0) {
- if (Blt_Vec_ChangeLength(interp, vPtr, size) != TCL_OK) {
- goto error;
- }
- }
- if (!isNew) {
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
- }
+ if (leftParen != NULL) {
+ *leftParen = '\0';
}
- Blt_FreeSwitches(createSwitches, (char *)&switches, 0);
- if (vPtr != NULL) {
- /* Return the name of the last vector created */
- Tcl_SetStringObj(Tcl_GetObjResult(interp), vPtr->name, -1);
+ /*
+ * By default, we create a TCL command by the name of the vector.
+ */
+ vPtr = Blt_Vec_Create(dataPtr, string,
+ (switches.cmdName == NULL) ? string : switches.cmdName,
+ (switches.varName == NULL) ? string : switches.varName, &isNew);
+ if (leftParen != NULL) {
+ *leftParen = '(';
}
- return TCL_OK;
- error:
- Blt_FreeSwitches(createSwitches, (char *)&switches, 0);
- return TCL_ERROR;
+ if (vPtr == NULL) {
+ goto error;
+ }
+ vPtr->freeOnUnset = switches.watchUnset;
+ vPtr->flush = switches.flush;
+ vPtr->offset = first;
+ if (size > 0) {
+ if (Blt_Vec_ChangeLength(interp, vPtr, size) != TCL_OK) {
+ goto error;
+ }
+ }
+ if (!isNew) {
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ }
+ }
+ Blt_FreeSwitches(createSwitches, (char *)&switches, 0);
+ if (vPtr != NULL) {
+ /* Return the name of the last vector created */
+ Tcl_SetStringObj(Tcl_GetObjResult(interp), vPtr->name, -1);
+ }
+ return TCL_OK;
+ error:
+ Blt_FreeSwitches(createSwitches, (char *)&switches, 0);
+ return TCL_ERROR;
}
/*
@@ -1624,7 +1607,7 @@ VectorCreate2(
static int VectorCreateOp(ClientData clientData, Tcl_Interp* interp,
int objc, Tcl_Obj* const objv[])
{
- return VectorCreate2(clientData, interp, 2, objc, objv);
+ return VectorCreate2(clientData, interp, 2, objc, objv);
}
/*
@@ -1646,23 +1629,23 @@ static int VectorCreateOp(ClientData clientData, Tcl_Interp* interp,
/*ARGSUSED*/
static int
VectorDestroyOp(
- ClientData clientData, /* Interpreter-specific data. */
- Tcl_Interp* interp, /* Not used. */
- int objc,
- Tcl_Obj* const objv[])
+ ClientData clientData, /* Interpreter-specific data. */
+ Tcl_Interp* interp, /* Not used. */
+ int objc,
+ Tcl_Obj* const objv[])
{
- VectorInterpData *dataPtr = clientData;
- Vector *vPtr;
- int i;
+ VectorInterpData *dataPtr = (VectorInterpData*)clientData;
+ Vector *vPtr;
+ int i;
- for (i = 2; i < objc; i++) {
- if (Blt_Vec_LookupName(dataPtr, Tcl_GetString(objv[i]), &vPtr)
- != TCL_OK) {
- return TCL_ERROR;
- }
- Blt_Vec_Free(vPtr);
+ for (i = 2; i < objc; i++) {
+ if (Blt_Vec_LookupName(dataPtr, Tcl_GetString(objv[i]), &vPtr)
+ != TCL_OK) {
+ return TCL_ERROR;
}
- return TCL_OK;
+ Blt_Vec_Free(vPtr);
+ }
+ return TCL_OK;
}
/*
@@ -1681,66 +1664,66 @@ VectorDestroyOp(
/*ARGSUSED*/
static int
VectorExprOp(
- ClientData clientData, /* Not Used. */
- Tcl_Interp* interp,
- int objc, /* Not used. */
- Tcl_Obj* const objv[])
+ ClientData clientData, /* Not Used. */
+ Tcl_Interp* interp,
+ int objc, /* Not used. */
+ Tcl_Obj* const objv[])
{
- return Blt_ExprVector(interp, Tcl_GetString(objv[2]), (Blt_Vector *)NULL);
+ return Blt_ExprVector(interp, Tcl_GetString(objv[2]), (Blt_Vector *)NULL);
}
static Blt_OpSpec vectorCmdOps[] =
-{
- {"create", 1, VectorCreateOp, 3, 0,
- "vecName ?vecName...? ?switches...?",},
- {"destroy", 1, VectorDestroyOp, 3, 0,
- "vecName ?vecName...?",},
- {"expr", 1, VectorExprOp, 3, 3, "expression",},
- {"names", 1, VectorNamesOp, 2, 3, "?pattern?...",},
-};
+ {
+ {"create", 1, (void*)VectorCreateOp, 3, 0,
+ "vecName ?vecName...? ?switches...?",},
+ {"destroy", 1, (void*)VectorDestroyOp, 3, 0,
+ "vecName ?vecName...?",},
+ {"expr", 1, (void*)VectorExprOp, 3, 3, "expression",},
+ {"names", 1, (void*)VectorNamesOp, 2, 3, "?pattern?...",},
+ };
static int nCmdOps = sizeof(vectorCmdOps) / sizeof(Blt_OpSpec);
/*ARGSUSED*/
static int
VectorCmd(
- ClientData clientData, /* Interpreter-specific data. */
- Tcl_Interp* interp,
- int objc,
- Tcl_Obj* const objv[])
+ ClientData clientData, /* Interpreter-specific data. */
+ Tcl_Interp* interp,
+ int objc,
+ Tcl_Obj* const objv[])
{
- VectorCmdProc *proc;
+ VectorCmdProc *proc;
+ /*
+ * Try to replicate the old vector command's behavior:
+ */
+ if (objc > 1) {
+ char *string;
+ char c;
+ int i;
+ Blt_OpSpec *specPtr;
+
+ string = Tcl_GetString(objv[1]);
+ c = string[0];
+ for (specPtr = vectorCmdOps, i = 0; i < nCmdOps; i++, specPtr++) {
+ if ((c == specPtr->name[0]) &&
+ (strcmp(string, specPtr->name) == 0)) {
+ goto doOp;
+ }
+ }
/*
- * Try to replicate the old vector command's behavior:
+ * The first argument is not an operation, so assume that its
+ * actually the name of a vector to be created
*/
- if (objc > 1) {
- char *string;
- char c;
- int i;
- Blt_OpSpec *specPtr;
-
- string = Tcl_GetString(objv[1]);
- c = string[0];
- for (specPtr = vectorCmdOps, i = 0; i < nCmdOps; i++, specPtr++) {
- if ((c == specPtr->name[0]) &&
- (strcmp(string, specPtr->name) == 0)) {
- goto doOp;
- }
- }
- /*
- * The first argument is not an operation, so assume that its
- * actually the name of a vector to be created
- */
- return VectorCreate2(clientData, interp, 1, objc, objv);
- }
- doOp:
- /* Do the usual vector operation lookup now. */
- proc = Blt_GetOpFromObj(interp, nCmdOps, vectorCmdOps, BLT_OP_ARG1,
- objc, objv,0);
- if (proc == NULL) {
- return TCL_ERROR;
- }
- return (*proc) (clientData, interp, objc, objv);
+ return VectorCreate2(clientData, interp, 1, objc, objv);
+ }
+ doOp:
+ /* Do the usual vector operation lookup now. */
+ proc = (VectorCmdProc*)Blt_GetOpFromObj(interp, nCmdOps, vectorCmdOps, BLT_OP_ARG1,
+ objc, objv,0);
+ if (proc == NULL) {
+ return TCL_ERROR;
+ }
+ return (*proc) ((Vector*)clientData, interp, objc, objv);
}
/*
@@ -1763,75 +1746,55 @@ VectorCmd(
/* ARGSUSED */
static void
VectorInterpDeleteProc(
- ClientData clientData, /* Interpreter-specific data. */
- Tcl_Interp* interp)
+ ClientData clientData, /* Interpreter-specific data. */
+ Tcl_Interp* interp)
{
- VectorInterpData *dataPtr = clientData;
- Tcl_HashEntry *hPtr;
- Tcl_HashSearch cursor;
+ VectorInterpData *dataPtr = (VectorInterpData*)clientData;
+ Tcl_HashEntry *hPtr;
+ Tcl_HashSearch cursor;
- for (hPtr = Tcl_FirstHashEntry(&dataPtr->vectorTable, &cursor);
- hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
- Vector *vPtr;
-
- vPtr = Tcl_GetHashValue(hPtr);
- vPtr->hashPtr = NULL;
- Blt_Vec_Free(vPtr);
- }
- Tcl_DeleteHashTable(&dataPtr->vectorTable);
+ for (hPtr = Tcl_FirstHashEntry(&dataPtr->vectorTable, &cursor);
+ hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
+ Vector *vPtr = (Vector*)Tcl_GetHashValue(hPtr);
+ vPtr->hashPtr = NULL;
+ Blt_Vec_Free(vPtr);
+ }
+ Tcl_DeleteHashTable(&dataPtr->vectorTable);
- /* If any user-defined math functions were installed, remove them. */
- Blt_Vec_UninstallMathFunctions(&dataPtr->mathProcTable);
- Tcl_DeleteHashTable(&dataPtr->mathProcTable);
+ /* If any user-defined math functions were installed, remove them. */
+ Blt_Vec_UninstallMathFunctions(&dataPtr->mathProcTable);
+ Tcl_DeleteHashTable(&dataPtr->mathProcTable);
- Tcl_DeleteHashTable(&dataPtr->indexProcTable);
- Tcl_DeleteAssocData(interp, VECTOR_THREAD_KEY);
- free(dataPtr);
+ Tcl_DeleteHashTable(&dataPtr->indexProcTable);
+ Tcl_DeleteAssocData(interp, VECTOR_THREAD_KEY);
+ free(dataPtr);
}
VectorInterpData *
Blt_Vec_GetInterpData(Tcl_Interp* interp)
{
- VectorInterpData *dataPtr;
- Tcl_InterpDeleteProc *proc;
-
- dataPtr = (VectorInterpData *)
- Tcl_GetAssocData(interp, VECTOR_THREAD_KEY, &proc);
- if (dataPtr == NULL) {
- dataPtr = malloc(sizeof(VectorInterpData));
- dataPtr->interp = interp;
- dataPtr->nextId = 0;
- Tcl_SetAssocData(interp, VECTOR_THREAD_KEY, VectorInterpDeleteProc,
- dataPtr);
- Tcl_InitHashTable(&dataPtr->vectorTable, TCL_STRING_KEYS);
- Tcl_InitHashTable(&dataPtr->mathProcTable, TCL_STRING_KEYS);
- Tcl_InitHashTable(&dataPtr->indexProcTable, TCL_STRING_KEYS);
- Blt_Vec_InstallMathFunctions(&dataPtr->mathProcTable);
- Blt_Vec_InstallSpecialIndices(&dataPtr->indexProcTable);
- srand48(time((time_t *) NULL));
- }
- return dataPtr;
+ VectorInterpData *dataPtr;
+ Tcl_InterpDeleteProc *proc;
+
+ dataPtr = (VectorInterpData *)
+ Tcl_GetAssocData(interp, VECTOR_THREAD_KEY, &proc);
+ if (dataPtr == NULL) {
+ dataPtr = (VectorInterpData*)malloc(sizeof(VectorInterpData));
+ dataPtr->interp = interp;
+ dataPtr->nextId = 0;
+ Tcl_SetAssocData(interp, VECTOR_THREAD_KEY, VectorInterpDeleteProc,
+ dataPtr);
+ Tcl_InitHashTable(&dataPtr->vectorTable, TCL_STRING_KEYS);
+ Tcl_InitHashTable(&dataPtr->mathProcTable, TCL_STRING_KEYS);
+ Tcl_InitHashTable(&dataPtr->indexProcTable, TCL_STRING_KEYS);
+ Blt_Vec_InstallMathFunctions(&dataPtr->mathProcTable);
+ Blt_Vec_InstallSpecialIndices(&dataPtr->indexProcTable);
+ srand48(time((time_t *) NULL));
+ }
+ return dataPtr;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_VectorCmdInitProc --
- *
- * This procedure is invoked to initialize the "vector" command.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Creates the new command and adds a new entry into a global Tcl
- * associative array.
- *
- *---------------------------------------------------------------------------
- */
-
-int
-Blt_VectorCmdInitProc(Tcl_Interp* interp)
+int Blt_VectorCmdInitProc(Tcl_Interp* interp)
{
Tcl_Namespace* nsPtr;
Tcl_Command cmdToken;
@@ -1843,11 +1806,11 @@ Blt_VectorCmdInitProc(Tcl_Interp* interp)
cmdToken = Tcl_FindCommand(interp, cmdPath, NULL, 0);
if (cmdToken)
- return TCL_OK;
+ return TCL_OK;
cmdToken = Tcl_CreateObjCommand(interp, cmdPath, VectorCmd,
Blt_Vec_GetInterpData(interp), NULL);
if (Tcl_Export(interp, nsPtr, "vector", 0) != TCL_OK)
- return TCL_ERROR;
+ return TCL_ERROR;
return TCL_OK;
}
@@ -1876,49 +1839,49 @@ Blt_VectorCmdInitProc(Tcl_Interp* interp)
/*LINTLIBRARY*/
int
Blt_CreateVector2(
- Tcl_Interp* interp,
- const char *vecName, const char *cmdName, const char *varName,
- int initialSize,
- Blt_Vector **vecPtrPtr)
+ Tcl_Interp* interp,
+ const char *vecName, const char *cmdName, const char *varName,
+ int initialSize,
+ Blt_Vector **vecPtrPtr)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Vector *vPtr;
- int isNew;
- char *nameCopy;
-
- if (initialSize < 0) {
- Tcl_AppendResult(interp, "bad vector size \"", Blt_Itoa(initialSize),
- "\"", (char *)NULL);
- return TCL_ERROR;
- }
- dataPtr = Blt_Vec_GetInterpData(interp);
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Vector *vPtr;
+ int isNew;
+ char *nameCopy;
+
+ if (initialSize < 0) {
+ Tcl_AppendResult(interp, "bad vector size \"", Blt_Itoa(initialSize),
+ "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ dataPtr = Blt_Vec_GetInterpData(interp);
- nameCopy = Blt_Strdup(vecName);
- vPtr = Blt_Vec_Create(dataPtr, nameCopy, cmdName, varName, &isNew);
- free(nameCopy);
+ nameCopy = Blt_Strdup(vecName);
+ vPtr = Blt_Vec_Create(dataPtr, nameCopy, cmdName, varName, &isNew);
+ free(nameCopy);
- if (vPtr == NULL) {
- return TCL_ERROR;
- }
- if (initialSize > 0) {
- if (Blt_Vec_ChangeLength(interp, vPtr, initialSize) != TCL_OK) {
- return TCL_ERROR;
- }
- }
- if (vecPtrPtr != NULL) {
- *vecPtrPtr = (Blt_Vector *) vPtr;
+ if (vPtr == NULL) {
+ return TCL_ERROR;
+ }
+ if (initialSize > 0) {
+ if (Blt_Vec_ChangeLength(interp, vPtr, initialSize) != TCL_OK) {
+ return TCL_ERROR;
}
- return TCL_OK;
+ }
+ if (vecPtrPtr != NULL) {
+ *vecPtrPtr = (Blt_Vector *) vPtr;
+ }
+ return TCL_OK;
}
int
Blt_CreateVector(
- Tcl_Interp* interp,
- const char *name,
- int size,
- Blt_Vector **vecPtrPtr)
+ Tcl_Interp* interp,
+ const char *name,
+ int size,
+ Blt_Vector **vecPtrPtr)
{
- return Blt_CreateVector2(interp, name, name, name, size, vecPtrPtr);
+ return Blt_CreateVector2(interp, name, name, name, size, vecPtrPtr);
}
/*
@@ -1944,10 +1907,10 @@ Blt_CreateVector(
int
Blt_DeleteVector(Blt_Vector *vecPtr)
{
- Vector *vPtr = (Vector *)vecPtr;
+ Vector *vPtr = (Vector *)vecPtr;
- Blt_Vec_Free(vPtr);
- return TCL_OK;
+ Blt_Vec_Free(vPtr);
+ return TCL_OK;
}
/*
@@ -1973,27 +1936,27 @@ Blt_DeleteVector(Blt_Vector *vecPtr)
int
Blt_DeleteVectorByName(Tcl_Interp* interp, const char *name)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Vector *vPtr;
- char *nameCopy;
- int result;
-
- /*
- * If the vector name was passed via a read-only string (e.g. "x"), the
- * Blt_Vec_ParseElement routine will segfault when it tries to write into
- * the string. Therefore make a writable copy and free it when we're
- * done.
- */
- nameCopy = Blt_Strdup(name);
- dataPtr = Blt_Vec_GetInterpData(interp);
- result = Blt_Vec_LookupName(dataPtr, nameCopy, &vPtr);
- free(nameCopy);
-
- if (result != TCL_OK) {
- return TCL_ERROR;
- }
- Blt_Vec_Free(vPtr);
- return TCL_OK;
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Vector *vPtr;
+ char *nameCopy;
+ int result;
+
+ /*
+ * If the vector name was passed via a read-only string (e.g. "x"), the
+ * Blt_Vec_ParseElement routine will segfault when it tries to write into
+ * the string. Therefore make a writable copy and free it when we're
+ * done.
+ */
+ nameCopy = Blt_Strdup(name);
+ dataPtr = Blt_Vec_GetInterpData(interp);
+ result = Blt_Vec_LookupName(dataPtr, nameCopy, &vPtr);
+ free(nameCopy);
+
+ if (result != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Blt_Vec_Free(vPtr);
+ return TCL_OK;
}
/*
@@ -2012,13 +1975,13 @@ Blt_DeleteVectorByName(Tcl_Interp* interp, const char *name)
int
Blt_VectorExists2(Tcl_Interp* interp, const char *vecName)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
- dataPtr = Blt_Vec_GetInterpData(interp);
- if (GetVectorObject(dataPtr, vecName, NS_SEARCH_BOTH) != NULL) {
- return 1;
- }
- return 0;
+ dataPtr = Blt_Vec_GetInterpData(interp);
+ if (GetVectorObject(dataPtr, vecName, NS_SEARCH_BOTH) != NULL) {
+ return 1;
+ }
+ return 0;
}
/*
@@ -2037,19 +2000,19 @@ Blt_VectorExists2(Tcl_Interp* interp, const char *vecName)
int
Blt_VectorExists(Tcl_Interp* interp, const char *vecName)
{
- char *nameCopy;
- int result;
-
- /*
- * If the vector name was passed via a read-only string (e.g. "x"), the
- * Blt_VectorParseName routine will segfault when it tries to write into
- * the string. Therefore make a writable copy and free it when we're
- * done.
- */
- nameCopy = Blt_Strdup(vecName);
- result = Blt_VectorExists2(interp, nameCopy);
- free(nameCopy);
- return result;
+ char *nameCopy;
+ int result;
+
+ /*
+ * If the vector name was passed via a read-only string (e.g. "x"), the
+ * Blt_VectorParseName routine will segfault when it tries to write into
+ * the string. Therefore make a writable copy and free it when we're
+ * done.
+ */
+ nameCopy = Blt_Strdup(vecName);
+ result = Blt_VectorExists2(interp, nameCopy);
+ free(nameCopy);
+ return result;
}
/*
@@ -2069,27 +2032,27 @@ Blt_VectorExists(Tcl_Interp* interp, const char *vecName)
int
Blt_GetVector(Tcl_Interp* interp, const char *name, Blt_Vector **vecPtrPtr)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Vector *vPtr;
- char *nameCopy;
- int result;
-
- dataPtr = Blt_Vec_GetInterpData(interp);
- /*
- * If the vector name was passed via a read-only string (e.g. "x"), the
- * Blt_VectorParseName routine will segfault when it tries to write into
- * the string. Therefore make a writable copy and free it when we're
- * done.
- */
- nameCopy = Blt_Strdup(name);
- result = Blt_Vec_LookupName(dataPtr, nameCopy, &vPtr);
- free(nameCopy);
- if (result != TCL_OK) {
- return TCL_ERROR;
- }
- Blt_Vec_UpdateRange(vPtr);
- *vecPtrPtr = (Blt_Vector *) vPtr;
- return TCL_OK;
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Vector *vPtr;
+ char *nameCopy;
+ int result;
+
+ dataPtr = Blt_Vec_GetInterpData(interp);
+ /*
+ * If the vector name was passed via a read-only string (e.g. "x"), the
+ * Blt_VectorParseName routine will segfault when it tries to write into
+ * the string. Therefore make a writable copy and free it when we're
+ * done.
+ */
+ nameCopy = Blt_Strdup(name);
+ result = Blt_Vec_LookupName(dataPtr, nameCopy, &vPtr);
+ free(nameCopy);
+ if (result != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Blt_Vec_UpdateRange(vPtr);
+ *vecPtrPtr = (Blt_Vector *) vPtr;
+ return TCL_OK;
}
/*
@@ -2108,20 +2071,20 @@ Blt_GetVector(Tcl_Interp* interp, const char *name, Blt_Vector **vecPtrPtr)
*/
int
Blt_GetVectorFromObj(
- Tcl_Interp* interp,
- Tcl_Obj *objPtr,
- Blt_Vector **vecPtrPtr)
+ Tcl_Interp* interp,
+ Tcl_Obj *objPtr,
+ Blt_Vector **vecPtrPtr)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Vector *vPtr;
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Vector *vPtr;
- dataPtr = Blt_Vec_GetInterpData(interp);
- if (Blt_Vec_LookupName(dataPtr, Tcl_GetString(objPtr), &vPtr) != TCL_OK) {
- return TCL_ERROR;
- }
- Blt_Vec_UpdateRange(vPtr);
- *vecPtrPtr = (Blt_Vector *) vPtr;
- return TCL_OK;
+ dataPtr = Blt_Vec_GetInterpData(interp);
+ if (Blt_Vec_LookupName(dataPtr, Tcl_GetString(objPtr), &vPtr) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Blt_Vec_UpdateRange(vPtr);
+ *vecPtrPtr = (Blt_Vector *) vPtr;
+ return TCL_OK;
}
/*
@@ -2147,25 +2110,25 @@ Blt_GetVectorFromObj(
*/
int
Blt_ResetVector(
- Blt_Vector *vecPtr,
- double *valueArr, /* Array containing the elements of the
- * vector. If NULL, indicates to reset the
- * vector.*/
- int length, /* The number of elements that the vector
- * currently holds. */
- int size, /* The maximum number of elements that the
- * array can hold. */
- Tcl_FreeProc *freeProc) /* Address of memory deallocation routine
- * for the array of values. Can also be
- * TCL_STATIC, TCL_DYNAMIC, or TCL_VOLATILE. */
+ Blt_Vector *vecPtr,
+ double *valueArr, /* Array containing the elements of the
+ * vector. If NULL, indicates to reset the
+ * vector.*/
+ int length, /* The number of elements that the vector
+ * currently holds. */
+ int size, /* The maximum number of elements that the
+ * array can hold. */
+ Tcl_FreeProc *freeProc) /* Address of memory deallocation routine
+ * for the array of values. Can also be
+ * TCL_STATIC, TCL_DYNAMIC, or TCL_VOLATILE. */
{
- Vector *vPtr = (Vector *)vecPtr;
+ Vector *vPtr = (Vector *)vecPtr;
- if (size < 0) {
- Tcl_AppendResult(vPtr->interp, "bad array size", (char *)NULL);
- return TCL_ERROR;
- }
- return Blt_Vec_Reset(vPtr, valueArr, length, size, freeProc);
+ if (size < 0) {
+ Tcl_AppendResult(vPtr->interp, "bad array size", (char *)NULL);
+ return TCL_ERROR;
+ }
+ return Blt_Vec_Reset(vPtr, valueArr, length, size, freeProc);
}
/*
@@ -2189,18 +2152,18 @@ Blt_ResetVector(
int
Blt_ResizeVector(Blt_Vector *vecPtr, int length)
{
- Vector *vPtr = (Vector *)vecPtr;
+ Vector *vPtr = (Vector *)vecPtr;
- if (Blt_Vec_ChangeLength((Tcl_Interp *)NULL, vPtr, length) != TCL_OK) {
- Tcl_AppendResult(vPtr->interp, "can't resize vector \"", vPtr->name,
- "\"", (char *)NULL);
- return TCL_ERROR;
- }
- if (vPtr->flush) {
- Blt_Vec_FlushCache(vPtr);
- }
- Blt_Vec_UpdateClients(vPtr);
- return TCL_OK;
+ if (Blt_Vec_ChangeLength((Tcl_Interp *)NULL, vPtr, length) != TCL_OK) {
+ Tcl_AppendResult(vPtr->interp, "can't resize vector \"", vPtr->name,
+ "\"", (char *)NULL);
+ return TCL_ERROR;
+ }
+ if (vPtr->flush) {
+ Blt_Vec_FlushCache(vPtr);
+ }
+ Blt_Vec_UpdateClients(vPtr);
+ return TCL_OK;
}
/*
@@ -2222,36 +2185,36 @@ Blt_ResizeVector(Blt_Vector *vecPtr, int length)
Blt_VectorId
Blt_AllocVectorId(Tcl_Interp* interp, const char *name)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Vector *vPtr;
- VectorClient *clientPtr;
- Blt_VectorId clientId;
- int result;
- char *nameCopy;
-
- dataPtr = Blt_Vec_GetInterpData(interp);
- /*
- * If the vector name was passed via a read-only string (e.g. "x"), the
- * Blt_VectorParseName routine will segfault when it tries to write into
- * the string. Therefore make a writable copy and free it when we're
- * done.
- */
- nameCopy = Blt_Strdup(name);
- result = Blt_Vec_LookupName(dataPtr, nameCopy, &vPtr);
- free(nameCopy);
-
- if (result != TCL_OK) {
- return (Blt_VectorId) 0;
- }
- /* Allocate a new client structure */
- clientPtr = calloc(1, sizeof(VectorClient));
- clientPtr->magic = VECTOR_MAGIC;
-
- /* Add the new client to the server's list of clients */
- clientPtr->link = Blt_Chain_Append(vPtr->chain, clientPtr);
- clientPtr->serverPtr = vPtr;
- clientId = (Blt_VectorId) clientPtr;
- return clientId;
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Vector *vPtr;
+ VectorClient *clientPtr;
+ Blt_VectorId clientId;
+ int result;
+ char *nameCopy;
+
+ dataPtr = Blt_Vec_GetInterpData(interp);
+ /*
+ * If the vector name was passed via a read-only string (e.g. "x"), the
+ * Blt_VectorParseName routine will segfault when it tries to write into
+ * the string. Therefore make a writable copy and free it when we're
+ * done.
+ */
+ nameCopy = Blt_Strdup(name);
+ result = Blt_Vec_LookupName(dataPtr, nameCopy, &vPtr);
+ free(nameCopy);
+
+ if (result != TCL_OK) {
+ return (Blt_VectorId) 0;
+ }
+ /* Allocate a new client structure */
+ clientPtr = (VectorClient*)calloc(1, sizeof(VectorClient));
+ clientPtr->magic = VECTOR_MAGIC;
+
+ /* Add the new client to the server's list of clients */
+ clientPtr->link = Blt_Chain_Append(vPtr->chain, clientPtr);
+ clientPtr->serverPtr = vPtr;
+ clientId = (Blt_VectorId) clientPtr;
+ return clientId;
}
/*
@@ -2274,20 +2237,20 @@ Blt_AllocVectorId(Tcl_Interp* interp, const char *name)
*/
void
Blt_SetVectorChangedProc(
- Blt_VectorId clientId, /* Client token identifying the vector */
- Blt_VectorChangedProc *proc,/* Address of routine to call when the contents
- * of the vector change. If NULL, no routine
- * will be called */
- ClientData clientData) /* One word of information to pass along when
- * the above routine is called */
+ Blt_VectorId clientId, /* Client token identifying the vector */
+ Blt_VectorChangedProc *proc,/* Address of routine to call when the contents
+ * of the vector change. If NULL, no routine
+ * will be called */
+ ClientData clientData) /* One word of information to pass along when
+ * the above routine is called */
{
- VectorClient *clientPtr = (VectorClient *)clientId;
+ VectorClient *clientPtr = (VectorClient *)clientId;
- if (clientPtr->magic != VECTOR_MAGIC) {
- return; /* Not a valid token */
- }
- clientPtr->clientData = clientData;
- clientPtr->proc = proc;
+ if (clientPtr->magic != VECTOR_MAGIC) {
+ return; /* Not a valid token */
+ }
+ clientPtr->clientData = clientData;
+ clientPtr->proc = proc;
}
/*
@@ -2312,16 +2275,16 @@ Blt_SetVectorChangedProc(
void
Blt_FreeVectorId(Blt_VectorId clientId)
{
- VectorClient *clientPtr = (VectorClient *)clientId;
+ VectorClient *clientPtr = (VectorClient *)clientId;
- if (clientPtr->magic != VECTOR_MAGIC) {
- return; /* Not a valid token */
- }
- if (clientPtr->serverPtr != NULL) {
- /* Remove the client from the server's list */
- Blt_Chain_DeleteLink(clientPtr->serverPtr->chain, clientPtr->link);
- }
- free(clientPtr);
+ if (clientPtr->magic != VECTOR_MAGIC) {
+ return; /* Not a valid token */
+ }
+ if (clientPtr->serverPtr != NULL) {
+ /* Remove the client from the server's list */
+ Blt_Chain_DeleteLink(clientPtr->serverPtr->chain, clientPtr->link);
+ }
+ free(clientPtr);
}
/*
@@ -2339,19 +2302,19 @@ Blt_FreeVectorId(Blt_VectorId clientId)
const char *
Blt_NameOfVectorId(Blt_VectorId clientId)
{
- VectorClient *clientPtr = (VectorClient *)clientId;
+ VectorClient *clientPtr = (VectorClient *)clientId;
- if ((clientPtr->magic != VECTOR_MAGIC) || (clientPtr->serverPtr == NULL)) {
- return NULL;
- }
- return clientPtr->serverPtr->name;
+ if ((clientPtr->magic != VECTOR_MAGIC) || (clientPtr->serverPtr == NULL)) {
+ return NULL;
+ }
+ return clientPtr->serverPtr->name;
}
const char *
Blt_NameOfVector(Blt_Vector *vecPtr) /* Vector to query. */
{
- Vector *vPtr = (Vector *)vecPtr;
- return vPtr->name;
+ Vector *vPtr = (Vector *)vecPtr;
+ return vPtr->name;
}
/*
@@ -2369,13 +2332,13 @@ Blt_NameOfVector(Blt_Vector *vecPtr) /* Vector to query. */
int
Blt_VectorNotifyPending(Blt_VectorId clientId)
{
- VectorClient *clientPtr = (VectorClient *)clientId;
+ VectorClient *clientPtr = (VectorClient *)clientId;
- if ((clientPtr == NULL) || (clientPtr->magic != VECTOR_MAGIC) ||
- (clientPtr->serverPtr == NULL)) {
- return 0;
- }
- return (clientPtr->serverPtr->notifyFlags & NOTIFY_PENDING);
+ if ((clientPtr == NULL) || (clientPtr->magic != VECTOR_MAGIC) ||
+ (clientPtr->serverPtr == NULL)) {
+ return 0;
+ }
+ return (clientPtr->serverPtr->notifyFlags & NOTIFY_PENDING);
}
/*
@@ -2395,23 +2358,23 @@ Blt_VectorNotifyPending(Blt_VectorId clientId)
*/
int
Blt_GetVectorById(
- Tcl_Interp* interp,
- Blt_VectorId clientId, /* Client token identifying the vector */
- Blt_Vector **vecPtrPtr)
+ Tcl_Interp* interp,
+ Blt_VectorId clientId, /* Client token identifying the vector */
+ Blt_Vector **vecPtrPtr)
{
- VectorClient *clientPtr = (VectorClient *)clientId;
+ VectorClient *clientPtr = (VectorClient *)clientId;
- if (clientPtr->magic != VECTOR_MAGIC) {
- Tcl_AppendResult(interp, "bad vector token", (char *)NULL);
- return TCL_ERROR;
- }
- if (clientPtr->serverPtr == NULL) {
- Tcl_AppendResult(interp, "vector no longer exists", (char *)NULL);
- return TCL_ERROR;
- }
- Blt_Vec_UpdateRange(clientPtr->serverPtr);
- *vecPtrPtr = (Blt_Vector *) clientPtr->serverPtr;
- return TCL_OK;
+ if (clientPtr->magic != VECTOR_MAGIC) {
+ Tcl_AppendResult(interp, "bad vector token", (char *)NULL);
+ return TCL_ERROR;
+ }
+ if (clientPtr->serverPtr == NULL) {
+ Tcl_AppendResult(interp, "vector no longer exists", (char *)NULL);
+ return TCL_ERROR;
+ }
+ Blt_Vec_UpdateRange(clientPtr->serverPtr);
+ *vecPtrPtr = (Blt_Vector *) clientPtr->serverPtr;
+ return TCL_OK;
}
/*LINTLIBRARY*/
@@ -2419,17 +2382,17 @@ void
Blt_InstallIndexProc(Tcl_Interp* interp, const char *string,
Blt_VectorIndexProc *procPtr)
{
- VectorInterpData *dataPtr; /* Interpreter-specific data. */
- Tcl_HashEntry *hPtr;
- int isNew;
-
- dataPtr = Blt_Vec_GetInterpData(interp);
- hPtr = Tcl_CreateHashEntry(&dataPtr->indexProcTable, string, &isNew);
- if (procPtr == NULL) {
- Tcl_DeleteHashEntry(hPtr);
- } else {
- Tcl_SetHashValue(hPtr, procPtr);
- }
+ VectorInterpData *dataPtr; /* Interpreter-specific data. */
+ Tcl_HashEntry *hPtr;
+ int isNew;
+
+ dataPtr = Blt_Vec_GetInterpData(interp);
+ hPtr = Tcl_CreateHashEntry(&dataPtr->indexProcTable, string, &isNew);
+ if (procPtr == NULL) {
+ Tcl_DeleteHashEntry(hPtr);
+ } else {
+ Tcl_SetHashValue(hPtr, procPtr);
+ }
}
/* spinellia@acm.org START */
@@ -2446,290 +2409,290 @@ Blt_InstallIndexProc(Tcl_Interp* interp, const char *string,
static void
four1(double *data, unsigned long nn, int isign)
{
- unsigned long n,mmax,m,j,istep,i;
- double wtemp,wr,wpr,wpi,wi,theta;
- double tempr,tempi;
+ unsigned long n,mmax,m,j,istep,i;
+ double wtemp,wr,wpr,wpi,wi,theta;
+ double tempr,tempi;
- n=nn << 1;
- j=1;
- for (i = 1;i<n;i+=2) {
- if (j > i) {
- SWAP(data[j],data[i]);
- SWAP(data[j+1],data[i+1]);
- }
- m=n >> 1;
- while (m >= 2 && j > m) {
- j -= m;
- m >>= 1;
- }
- j += m;
- }
- mmax=2;
- while (n > mmax) {
- istep=mmax << 1;
- theta=isign*(6.28318530717959/mmax);
- wtemp=sin(0.5*theta);
- wpr = -2.0*wtemp*wtemp;
- wpi=sin(theta);
- wr=1.0;
- wi=0.0;
- for (m=1;m<mmax;m+=2) {
- for (i=m;i<=n;i+=istep) {
- j=i+mmax;
- tempr=wr*data[j]-wi*data[j+1];
- tempi=wr*data[j+1]+wi*data[j];
- data[j]=data[i]-tempr;
- data[j+1]=data[i+1]-tempi;
- data[i] += tempr;
- data[i+1] += tempi;
- }
- wr=(wtemp=wr)*wpr-wi*wpi+wr;
- wi=wi*wpr+wtemp*wpi+wi;
- }
- mmax=istep;
+ n=nn << 1;
+ j=1;
+ for (i = 1;i<n;i+=2) {
+ if (j > i) {
+ SWAP(data[j],data[i]);
+ SWAP(data[j+1],data[i+1]);
+ }
+ m=n >> 1;
+ while (m >= 2 && j > m) {
+ j -= m;
+ m >>= 1;
+ }
+ j += m;
+ }
+ mmax=2;
+ while (n > mmax) {
+ istep=mmax << 1;
+ theta=isign*(6.28318530717959/mmax);
+ wtemp=sin(0.5*theta);
+ wpr = -2.0*wtemp*wtemp;
+ wpi=sin(theta);
+ wr=1.0;
+ wi=0.0;
+ for (m=1;m<mmax;m+=2) {
+ for (i=m;i<=n;i+=istep) {
+ j=i+mmax;
+ tempr=wr*data[j]-wi*data[j+1];
+ tempi=wr*data[j+1]+wi*data[j];
+ data[j]=data[i]-tempr;
+ data[j+1]=data[i+1]-tempi;
+ data[i] += tempr;
+ data[i+1] += tempi;
+ }
+ wr=(wtemp=wr)*wpr-wi*wpi+wr;
+ wi=wi*wpr+wtemp*wpi+wi;
}
+ mmax=istep;
+ }
}
#undef SWAP
static int
smallest_power_of_2_not_less_than(int x)
{
- int pow2 = 1;
+ int pow2 = 1;
- while (pow2 < x){
- pow2 <<= 1;
- }
- return pow2;
+ while (pow2 < x){
+ pow2 <<= 1;
+ }
+ return pow2;
}
int
Blt_Vec_FFT(
- Tcl_Interp* interp, /* Interpreter to report errors to */
- Vector *realPtr, /* If non-NULL, indicates to compute and
+ Tcl_Interp* interp, /* Interpreter to report errors to */
+ Vector *realPtr, /* If non-NULL, indicates to compute and
store the real values in this vector. */
- Vector *phasesPtr, /* If non-NULL, indicates to compute
+ Vector *phasesPtr, /* If non-NULL, indicates to compute
* and store the imaginary values in
* this vector. */
- Vector *freqPtr, /* If non-NULL, indicates to compute
+ Vector *freqPtr, /* If non-NULL, indicates to compute
* and store the frequency values in
* this vector. */
- double delta, /* */
- int flags, /* Bit mask representing various
- * flags: FFT_NO_constANT,
- * FFT_SPECTRUM, and FFT_BARTLETT. */
- Vector *srcPtr)
+ double delta, /* */
+ int flags, /* Bit mask representing various
+ * flags: FFT_NO_constANT,
+ * FFT_SPECTRUM, and FFT_BARTLETT. */
+ Vector *srcPtr)
{
- int length;
- int pow2len;
- double *paddedData;
- int i;
- double Wss = 0.0;
- /* TENTATIVE */
- int middle = 1;
- int noconstant;
-
- noconstant = (flags & FFT_NO_CONSTANT) ? 1 : 0;
-
- /* Length of the original vector. */
- length = srcPtr->last - srcPtr->first + 1;
- /* new length */
- pow2len = smallest_power_of_2_not_less_than( length );
-
- /* We do not do in-place FFTs */
- if (realPtr == srcPtr) {
- Tcl_AppendResult(interp, "real vector \"", realPtr->name,
- "\" can't be the same as the source", (char *)NULL);
- return TCL_ERROR;
+ int length;
+ int pow2len;
+ double *paddedData;
+ int i;
+ double Wss = 0.0;
+ /* TENTATIVE */
+ int middle = 1;
+ int noconstant;
+
+ noconstant = (flags & FFT_NO_CONSTANT) ? 1 : 0;
+
+ /* Length of the original vector. */
+ length = srcPtr->last - srcPtr->first + 1;
+ /* new length */
+ pow2len = smallest_power_of_2_not_less_than( length );
+
+ /* We do not do in-place FFTs */
+ if (realPtr == srcPtr) {
+ Tcl_AppendResult(interp, "real vector \"", realPtr->name,
+ "\" can't be the same as the source", (char *)NULL);
+ return TCL_ERROR;
+ }
+ if (phasesPtr != NULL) {
+ if (phasesPtr == srcPtr) {
+ Tcl_AppendResult(interp, "imaginary vector \"", phasesPtr->name,
+ "\" can't be the same as the source", (char *)NULL);
+ return TCL_ERROR;
}
- if (phasesPtr != NULL) {
- if (phasesPtr == srcPtr) {
- Tcl_AppendResult(interp, "imaginary vector \"", phasesPtr->name,
- "\" can't be the same as the source", (char *)NULL);
- return TCL_ERROR;
- }
- if (Blt_Vec_ChangeLength(interp, phasesPtr,
- pow2len/2-noconstant+middle) != TCL_OK) {
- return TCL_ERROR;
- }
+ if (Blt_Vec_ChangeLength(interp, phasesPtr,
+ pow2len/2-noconstant+middle) != TCL_OK) {
+ return TCL_ERROR;
}
- if (freqPtr != NULL) {
- if (freqPtr == srcPtr) {
- Tcl_AppendResult(interp, "frequency vector \"", freqPtr->name,
- "\" can't be the same as the source", (char *)NULL);
- return TCL_ERROR;
- }
- if (Blt_Vec_ChangeLength(interp, freqPtr,
- pow2len/2-noconstant+middle) != TCL_OK) {
- return TCL_ERROR;
- }
+ }
+ if (freqPtr != NULL) {
+ if (freqPtr == srcPtr) {
+ Tcl_AppendResult(interp, "frequency vector \"", freqPtr->name,
+ "\" can't be the same as the source", (char *)NULL);
+ return TCL_ERROR;
}
-
- /* Allocate memory zero-filled array. */
- paddedData = calloc(pow2len * 2, sizeof(double));
- if (paddedData == NULL) {
- Tcl_AppendResult(interp, "can't allocate memory for padded data",
- (char *)NULL);
- return TCL_ERROR;
+ if (Blt_Vec_ChangeLength(interp, freqPtr,
+ pow2len/2-noconstant+middle) != TCL_OK) {
+ return TCL_ERROR;
}
+ }
+
+ /* Allocate memory zero-filled array. */
+ paddedData = (double*)calloc(pow2len * 2, sizeof(double));
+ if (paddedData == NULL) {
+ Tcl_AppendResult(interp, "can't allocate memory for padded data",
+ (char *)NULL);
+ return TCL_ERROR;
+ }
- /*
- * Since we just do real transforms, only even locations will be
- * filled with data.
- */
- if (flags & FFT_BARTLETT) { /* Bartlett window 1 - ( (x - N/2) / (N/2) ) */
- double Nhalf = pow2len*0.5;
- double Nhalf_1 = 1.0 / Nhalf;
- double w;
-
- for (i = 0; i < length; i++) {
- w = 1.0 - fabs( (i-Nhalf) * Nhalf_1 );
- Wss += w;
- paddedData[2*i] = w * srcPtr->valueArr[i];
- }
- for(/*empty*/; i < pow2len; i++) {
- w = 1.0 - fabs((i-Nhalf) * Nhalf_1);
- Wss += w;
- }
- } else { /* Squared window, i.e. no data windowing. */
- for (i = 0; i < length; i++) {
- paddedData[2*i] = srcPtr->valueArr[i];
- }
- Wss = pow2len;
- }
+ /*
+ * Since we just do real transforms, only even locations will be
+ * filled with data.
+ */
+ if (flags & FFT_BARTLETT) { /* Bartlett window 1 - ( (x - N/2) / (N/2) ) */
+ double Nhalf = pow2len*0.5;
+ double Nhalf_1 = 1.0 / Nhalf;
+ double w;
+
+ for (i = 0; i < length; i++) {
+ w = 1.0 - fabs( (i-Nhalf) * Nhalf_1 );
+ Wss += w;
+ paddedData[2*i] = w * srcPtr->valueArr[i];
+ }
+ for(/*empty*/; i < pow2len; i++) {
+ w = 1.0 - fabs((i-Nhalf) * Nhalf_1);
+ Wss += w;
+ }
+ } else { /* Squared window, i.e. no data windowing. */
+ for (i = 0; i < length; i++) {
+ paddedData[2*i] = srcPtr->valueArr[i];
+ }
+ Wss = pow2len;
+ }
- /* Fourier */
- four1(paddedData-1, pow2len, 1);
+ /* Fourier */
+ four1(paddedData-1, pow2len, 1);
- /*
- for(i=0;i<pow2len;i++){
- printf( "(%f %f) ", paddedData[2*i], paddedData[2*i+1] );
- }
- */
+ /*
+ for(i=0;i<pow2len;i++){
+ printf( "(%f %f) ", paddedData[2*i], paddedData[2*i+1] );
+ }
+ */
- /* the spectrum is the modulus of the transforms, scaled by 1/N^2 */
- /* or 1/(N * Wss) for windowed data */
- if (flags & FFT_SPECTRUM) {
- double re, im, reS, imS;
- double factor = 1.0 / (pow2len*Wss);
- double *v = realPtr->valueArr;
+ /* the spectrum is the modulus of the transforms, scaled by 1/N^2 */
+ /* or 1/(N * Wss) for windowed data */
+ if (flags & FFT_SPECTRUM) {
+ double re, im, reS, imS;
+ double factor = 1.0 / (pow2len*Wss);
+ double *v = realPtr->valueArr;
- for (i = 0 + noconstant; i < pow2len / 2; i++) {
- re = paddedData[2*i];
- im = paddedData[2*i+1];
- reS = paddedData[2*pow2len-2*i-2];
- imS = paddedData[2*pow2len-2*i-1];
- v[i - noconstant] = factor * (
+ for (i = 0 + noconstant; i < pow2len / 2; i++) {
+ re = paddedData[2*i];
+ im = paddedData[2*i+1];
+ reS = paddedData[2*pow2len-2*i-2];
+ imS = paddedData[2*pow2len-2*i-1];
+ v[i - noconstant] = factor * (
# if 0
- hypot( paddedData[2*i], paddedData[2*i+1] )
- + hypot(
- paddedData[pow2len*2-2*i-2],
- paddedData[pow2len*2-2*i-1]
- )
+ hypot( paddedData[2*i], paddedData[2*i+1] )
+ + hypot(
+ paddedData[pow2len*2-2*i-2],
+ paddedData[pow2len*2-2*i-1]
+ )
# else
- sqrt( re*re + im* im ) + sqrt( reS*reS + imS*imS )
+ sqrt( re*re + im* im ) + sqrt( reS*reS + imS*imS )
# endif
- );
- }
- } else {
- for(i = 0 + noconstant; i < pow2len / 2 + middle; i++) {
- realPtr->valueArr[i - noconstant] = paddedData[2*i];
- }
+ );
}
- if( phasesPtr != NULL ){
- for (i = 0 + noconstant; i < pow2len / 2 + middle; i++) {
- phasesPtr->valueArr[i-noconstant] = paddedData[2*i+1];
- }
+ } else {
+ for(i = 0 + noconstant; i < pow2len / 2 + middle; i++) {
+ realPtr->valueArr[i - noconstant] = paddedData[2*i];
}
+ }
+ if( phasesPtr != NULL ){
+ for (i = 0 + noconstant; i < pow2len / 2 + middle; i++) {
+ phasesPtr->valueArr[i-noconstant] = paddedData[2*i+1];
+ }
+ }
- /* Compute frequencies */
- if (freqPtr != NULL) {
- double N = pow2len;
- double denom = 1.0 / N / delta;
- for( i=0+noconstant; i<pow2len/2+middle; i++ ){
- freqPtr->valueArr[i-noconstant] = ((double) i) * denom;
- }
+ /* Compute frequencies */
+ if (freqPtr != NULL) {
+ double N = pow2len;
+ double denom = 1.0 / N / delta;
+ for( i=0+noconstant; i<pow2len/2+middle; i++ ){
+ freqPtr->valueArr[i-noconstant] = ((double) i) * denom;
}
+ }
- /* Memory is necessarily dynamic, because nobody touched it ! */
- free(paddedData);
+ /* Memory is necessarily dynamic, because nobody touched it ! */
+ free(paddedData);
- realPtr->offset = 0;
- return TCL_OK;
+ realPtr->offset = 0;
+ return TCL_OK;
}
int
Blt_Vec_InverseFFT(Tcl_Interp* interp, Vector *srcImagPtr, Vector *destRealPtr,
- Vector *destImagPtr, Vector *srcPtr)
+ Vector *destImagPtr, Vector *srcPtr)
{
- int length;
- int pow2len;
- double *paddedData;
- int i;
- double oneOverN;
+ int length;
+ int pow2len;
+ double *paddedData;
+ int i;
+ double oneOverN;
+
+ if ((destRealPtr == srcPtr) || (destImagPtr == srcPtr )){
+ /* we do not do in-place FFTs */
+ return TCL_ERROR;
+ }
+ length = srcPtr->last - srcPtr->first + 1;
- if ((destRealPtr == srcPtr) || (destImagPtr == srcPtr )){
-/* we do not do in-place FFTs */
- return TCL_ERROR;
- }
- length = srcPtr->last - srcPtr->first + 1;
+ /* minus one because of the magical middle element! */
+ pow2len = smallest_power_of_2_not_less_than( (length-1)*2 );
+ oneOverN = 1.0 / pow2len;
-/* minus one because of the magical middle element! */
- pow2len = smallest_power_of_2_not_less_than( (length-1)*2 );
- oneOverN = 1.0 / pow2len;
+ if (Blt_Vec_ChangeLength(interp, destRealPtr, pow2len) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (Blt_Vec_ChangeLength(interp, destImagPtr, pow2len) != TCL_OK) {
+ return TCL_ERROR;
+ }
- if (Blt_Vec_ChangeLength(interp, destRealPtr, pow2len) != TCL_OK) {
- return TCL_ERROR;
- }
- if (Blt_Vec_ChangeLength(interp, destImagPtr, pow2len) != TCL_OK) {
- return TCL_ERROR;
- }
+ if( length != (srcImagPtr->last - srcImagPtr->first + 1) ){
+ Tcl_AppendResult(srcPtr->interp,
+ "the length of the imagPart vector must ",
+ "be the same as the real one", (char *)NULL);
+ return TCL_ERROR;
+ }
- if( length != (srcImagPtr->last - srcImagPtr->first + 1) ){
- Tcl_AppendResult(srcPtr->interp,
- "the length of the imagPart vector must ",
- "be the same as the real one", (char *)NULL);
- return TCL_ERROR;
+ paddedData = (double*)malloc( pow2len*2*sizeof(double) );
+ if( paddedData == NULL ){
+ if (interp != NULL) {
+ Tcl_AppendResult(interp, "memory allocation failed", (char *)NULL);
}
+ return TCL_ERROR;
+ }
+ for(i=0;i<pow2len*2;i++) { paddedData[i] = 0.0; }
+ for(i=0;i<length-1;i++){
+ paddedData[2*i] = srcPtr->valueArr[i];
+ paddedData[2*i+1] = srcImagPtr->valueArr[i];
+ paddedData[pow2len*2 - 2*i - 2 ] = srcPtr->valueArr[i+1];
+ paddedData[pow2len*2 - 2*i - 1 ] = - srcImagPtr->valueArr[i+1];
+ }
+ /* mythical middle element */
+ paddedData[(length-1)*2] = srcPtr->valueArr[length-1];
+ paddedData[(length-1)*2+1] = srcImagPtr->valueArr[length-1];
- paddedData = malloc( pow2len*2*sizeof(double) );
- if( paddedData == NULL ){
- if (interp != NULL) {
- Tcl_AppendResult(interp, "memory allocation failed", (char *)NULL);
- }
- return TCL_ERROR;
- }
- for(i=0;i<pow2len*2;i++) { paddedData[i] = 0.0; }
- for(i=0;i<length-1;i++){
- paddedData[2*i] = srcPtr->valueArr[i];
- paddedData[2*i+1] = srcImagPtr->valueArr[i];
- paddedData[pow2len*2 - 2*i - 2 ] = srcPtr->valueArr[i+1];
- paddedData[pow2len*2 - 2*i - 1 ] = - srcImagPtr->valueArr[i+1];
+ /*
+ for(i=0;i<pow2len;i++){
+ printf( "(%f %f) ", paddedData[2*i], paddedData[2*i+1] );
}
-/* mythical middle element */
- paddedData[(length-1)*2] = srcPtr->valueArr[length-1];
- paddedData[(length-1)*2+1] = srcImagPtr->valueArr[length-1];
+ */
-/*
-for(i=0;i<pow2len;i++){
- printf( "(%f %f) ", paddedData[2*i], paddedData[2*i+1] );
-}
- */
-
-/* fourier */
- four1( paddedData-1, pow2len, -1 );
+ /* fourier */
+ four1( paddedData-1, pow2len, -1 );
-/* put values in their places, normalising by 1/N */
- for(i=0;i<pow2len;i++){
- destRealPtr->valueArr[i] = paddedData[2*i] * oneOverN;
- destImagPtr->valueArr[i] = paddedData[2*i+1] * oneOverN;
- }
+ /* put values in their places, normalising by 1/N */
+ for(i=0;i<pow2len;i++){
+ destRealPtr->valueArr[i] = paddedData[2*i] * oneOverN;
+ destImagPtr->valueArr[i] = paddedData[2*i+1] * oneOverN;
+ }
-/* memory is necessarily dynamic, because nobody touched it ! */
- free( paddedData );
+ /* memory is necessarily dynamic, because nobody touched it ! */
+ free( paddedData );
- return TCL_OK;
+ return TCL_OK;
}
@@ -2740,41 +2703,41 @@ for(i=0;i<pow2len;i++){
static double
FindSplit(Point2d *points, int i, int j, int *split)
{
- double maxDist2;
+ double maxDist2;
- maxDist2 = -1.0;
- if ((i + 1) < j) {
- int k;
- double a, b, c;
-
- /*
- *
- * dist2 P(k) = | 1 P(i).x P(i).y |
- * | 1 P(j).x P(j).y |
- * | 1 P(k).x P(k).y |
- * ------------------------------------------
- * (P(i).x - P(j).x)^2 + (P(i).y - P(j).y)^2
- */
-
- a = points[i].y - points[j].y;
- b = points[j].x - points[i].x;
- c = (points[i].x * points[j].y) - (points[i].y * points[j].x);
- for (k = (i + 1); k < j; k++) {
- double dist2;
-
- dist2 = (points[k].x * a) + (points[k].y * b) + c;
- if (dist2 < 0.0) {
- dist2 = -dist2;
- }
- if (dist2 > maxDist2) {
- maxDist2 = dist2; /* Track the maximum. */
- *split = k;
- }
- }
- /* Correction for segment length---should be redone if can == 0 */
- maxDist2 *= maxDist2 / (a * a + b * b);
- }
- return maxDist2;
+ maxDist2 = -1.0;
+ if ((i + 1) < j) {
+ int k;
+ double a, b, c;
+
+ /*
+ *
+ * dist2 P(k) = | 1 P(i).x P(i).y |
+ * | 1 P(j).x P(j).y |
+ * | 1 P(k).x P(k).y |
+ * ------------------------------------------
+ * (P(i).x - P(j).x)^2 + (P(i).y - P(j).y)^2
+ */
+
+ a = points[i].y - points[j].y;
+ b = points[j].x - points[i].x;
+ c = (points[i].x * points[j].y) - (points[i].y * points[j].x);
+ for (k = (i + 1); k < j; k++) {
+ double dist2;
+
+ dist2 = (points[k].x * a) + (points[k].y * b) + c;
+ if (dist2 < 0.0) {
+ dist2 = -dist2;
+ }
+ if (dist2 > maxDist2) {
+ maxDist2 = dist2; /* Track the maximum. */
+ *split = k;
+ }
+ }
+ /* Correction for segment length---should be redone if can == 0 */
+ maxDist2 *= maxDist2 / (a * a + b * b);
+ }
+ return maxDist2;
}
@@ -2787,26 +2750,26 @@ Blt_SimplifyLine(Point2d *inputPts, int low, int high, double tolerance,
#define StackPop(a) (a) = stack[s], s--
#define StackEmpty() (s < 0)
#define StackTop() stack[s]
- int *stack;
- int split = -1;
- double dist2, tolerance2;
- int s = -1; /* Points to top stack item. */
- int count;
-
- stack = malloc(sizeof(int) * (high - low + 1));
- StackPush(high);
- count = 0;
- indices[count++] = 0;
- tolerance2 = tolerance * tolerance;
- while (!StackEmpty()) {
- dist2 = FindSplit(inputPts, low, StackTop(), &split);
- if (dist2 > tolerance2) {
- StackPush(split);
- } else {
- indices[count++] = StackTop();
- StackPop(low);
- }
- }
- free(stack);
- return count;
+ int *stack;
+ int split = -1;
+ double dist2, tolerance2;
+ int s = -1; /* Points to top stack item. */
+ int count;
+
+ stack = (int*)malloc(sizeof(int) * (high - low + 1));
+ StackPush(high);
+ count = 0;
+ indices[count++] = 0;
+ tolerance2 = tolerance * tolerance;
+ while (!StackEmpty()) {
+ dist2 = FindSplit(inputPts, low, StackTop(), &split);
+ if (dist2 > tolerance2) {
+ StackPush(split);
+ } else {
+ indices[count++] = StackTop();
+ StackPop(low);
+ }
+ }
+ free(stack);
+ return count;
}
diff --git a/src/bltVector.h b/src/bltVector.h
index 6712a42..f1daa78 100644
--- a/src/bltVector.h
+++ b/src/bltVector.h
@@ -36,8 +36,8 @@
#include <tcl.h>
typedef enum {
- BLT_VECTOR_NOTIFY_UPDATE = 1, /* The vector's values has been updated */
- BLT_VECTOR_NOTIFY_DESTROY /* The vector has been destroyed and the client
+ BLT_VECTOR_NOTIFY_UPDATE = 1, /* The vector's values has been updated */
+ BLT_VECTOR_NOTIFY_DESTROY /* The vector has been destroyed and the client
* should no longer use its data (calling
* Blt_FreeVectorId) */
} Blt_VectorNotify;
@@ -45,24 +45,24 @@ typedef enum {
typedef struct _Blt_VectorId *Blt_VectorId;
typedef void (Blt_VectorChangedProc)(Tcl_Interp* interp, ClientData clientData,
- Blt_VectorNotify notify);
+ Blt_VectorNotify notify);
typedef struct {
- double *valueArr; /* Array of values (possibly malloc-ed) */
- int numValues; /* Number of values in the array */
- int arraySize; /* Size of the allocated space */
- double min, max; /* Minimum and maximum values in the vector */
- int dirty; /* Indicates if the vector has been updated */
- int reserved; /* Reserved for future use */
+ double *valueArr; /* Array of values (possibly malloc-ed) */
+ int numValues; /* Number of values in the array */
+ int arraySize; /* Size of the allocated space */
+ double min, max; /* Minimum and maximum values in the vector */
+ int dirty; /* Indicates if the vector has been updated */
+ int reserved; /* Reserved for future use */
} Blt_Vector;
typedef double (Blt_VectorIndexProc)(Blt_Vector * vecPtr);
typedef enum {
- BLT_MATH_FUNC_SCALAR = 1, /* The function returns a single double
+ BLT_MATH_FUNC_SCALAR = 1, /* The function returns a single double
* precision value. */
- BLT_MATH_FUNC_VECTOR /* The function processes the entire vector. */
+ BLT_MATH_FUNC_VECTOR /* The function processes the entire vector. */
} Blt_MathFuncType;
/*
@@ -91,15 +91,15 @@ extern double Blt_VecMin(Blt_Vector *vPtr);
extern double Blt_VecMax(Blt_Vector *vPtr);
extern Blt_VectorId Blt_AllocVectorId(Tcl_Interp* interp,
- const char *vecName);
+ const char *vecName);
extern void Blt_SetVectorChangedProc(Blt_VectorId clientId,
- Blt_VectorChangedProc *proc, ClientData clientData);
+ Blt_VectorChangedProc *proc, ClientData clientData);
extern void Blt_FreeVectorId(Blt_VectorId clientId);
extern int Blt_GetVectorById(Tcl_Interp* interp, Blt_VectorId clientId,
- Blt_Vector **vecPtrPtr);
+ Blt_Vector **vecPtrPtr);
extern const char *Blt_NameOfVectorId(Blt_VectorId clientId);
@@ -108,22 +108,22 @@ extern const char *Blt_NameOfVector(Blt_Vector *vecPtr);
extern int Blt_VectorNotifyPending(Blt_VectorId clientId);
extern int Blt_CreateVector(Tcl_Interp* interp, const char *vecName,
- int size, Blt_Vector ** vecPtrPtr);
+ int size, Blt_Vector ** vecPtrPtr);
extern int Blt_CreateVector2(Tcl_Interp* interp, const char *vecName,
- const char *cmdName, const char *varName, int initialSize,
- Blt_Vector **vecPtrPtr);
+ const char *cmdName, const char *varName, int initialSize,
+ Blt_Vector **vecPtrPtr);
-extern int Blt_GetVector(Tcl_Interp* interp, const char *vecName,
- Blt_Vector **vecPtrPtr);
+extern "C" {
+ int Blt_GetVector(Tcl_Interp* interp, const char *vecName, Blt_Vector **vecPtrPtr);
+ int Blt_ResetVector(Blt_Vector *vecPtr, double *dataArr, int n, int arraySize, Tcl_FreeProc *freeProc);
+}
extern int Blt_GetVectorFromObj(Tcl_Interp* interp, Tcl_Obj *objPtr,
- Blt_Vector **vecPtrPtr);
+ Blt_Vector **vecPtrPtr);
extern int Blt_VectorExists(Tcl_Interp* interp, const char *vecName);
-extern int Blt_ResetVector(Blt_Vector *vecPtr, double *dataArr, int n,
- int arraySize, Tcl_FreeProc *freeProc);
extern int Blt_ResizeVector(Blt_Vector *vecPtr, int n);
@@ -132,10 +132,10 @@ extern int Blt_DeleteVectorByName(Tcl_Interp* interp, const char *vecName);
extern int Blt_DeleteVector(Blt_Vector *vecPtr);
extern int Blt_ExprVector(Tcl_Interp* interp, char *expr,
- Blt_Vector *vecPtr);
+ Blt_Vector *vecPtr);
extern void Blt_InstallIndexProc(Tcl_Interp* interp, const char *indexName,
- Blt_VectorIndexProc * procPtr);
+ Blt_VectorIndexProc * procPtr);
extern int Blt_VectorExists2(Tcl_Interp* interp, const char *vecName);