|
|
|
@ -15,26 +15,35 @@ Author: 1992 David A. Gates, U. C. Berkeley CAD Group |
|
|
|
|
|
|
|
/* |
|
|
|
* Create a string of the form "12,1,10". |
|
|
|
* |
|
|
|
* Parameters |
|
|
|
* dim_data: Array of sizes of dimensions, [12, 1, 10] for the example |
|
|
|
* n_dim: Number of elements in the array, 3 in the example |
|
|
|
* retstring: Address of buffer where the string is returned. |
|
|
|
|
|
|
|
* Remarks |
|
|
|
* It is assumed that the buffer in retstring is large enough, which for |
|
|
|
* MAXDIMS, would require MAXDIMS * 11 bytes in the worst case assuming |
|
|
|
* 32-bit ints. A looser but more general bound only assuming 8-bit bytes |
|
|
|
* would be MAXDIMS * (3 * sizeof(int) + 1). |
|
|
|
*/ |
|
|
|
void |
|
|
|
dimstring(int *data, int length, char *retstring) |
|
|
|
dimstring(const int *dim_data, int n_dim, char *retstring) |
|
|
|
{ |
|
|
|
int i; |
|
|
|
char buf[BSIZE_SP]; |
|
|
|
|
|
|
|
|
|
|
|
if (!data || length < 1) |
|
|
|
retstring = ""; |
|
|
|
|
|
|
|
buf[0] = '\0'; |
|
|
|
/* Handle case of no dimensions */ |
|
|
|
if (dim_data == (int *) NULL || n_dim < 1) { |
|
|
|
*retstring = '\0'; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i < length; i++) |
|
|
|
sprintf(buf + strlen(buf), "%d%s", data[i], (i < length - 1) ? "," : ""); |
|
|
|
/* Append each dimension */ |
|
|
|
retstring += sprintf(retstring, "%d", dim_data[0]); /* first */ |
|
|
|
int i; |
|
|
|
for (i = 1; i < n_dim; i++) { /* rest are prefixed by a comma */ |
|
|
|
retstring += sprintf(retstring, ",%d", dim_data[i]); |
|
|
|
} |
|
|
|
} /* end of function dimstring */ |
|
|
|
|
|
|
|
/* XXX Should I return a copy instead? */ |
|
|
|
/* qui ci devo fare una copia */ |
|
|
|
strcpy(retstring, buf); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
@ -49,7 +58,7 @@ dimstring(int *data, int length, char *retstring) |
|
|
|
* It is assumed that the buffer in retstring is large enough, which for |
|
|
|
* MAXDIMS, would require MAXDIMS * 12 + 1 bytes in the worst case assuming |
|
|
|
* 32-bit ints. A looser but more general bound only assuming 8-bit bytes |
|
|
|
* would be MAXDIMS * 3 * sizeof(int) + 1. |
|
|
|
* would be MAXDIMS * (3 * sizeof(int) + 2) + 1. |
|
|
|
*/ |
|
|
|
void |
|
|
|
indexstring(const int *dim_data, int n_dim, char *retstring) |
|
|
|
@ -74,7 +83,7 @@ indexstring(const int *dim_data, int n_dim, char *retstring) |
|
|
|
* Return 1 when all counters overflow at once. |
|
|
|
*/ |
|
|
|
int |
|
|
|
incindex(int *counts, int numcounts, int *dims, int numdims) |
|
|
|
incindex(int *counts, int numcounts, const int *dims, int numdims) |
|
|
|
{ |
|
|
|
int i, start; |
|
|
|
|
|
|
|
@ -96,22 +105,6 @@ incindex(int *counts, int numcounts, int *dims, int numdims) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* Count number of empty dimensions in an array. |
|
|
|
*/ |
|
|
|
int |
|
|
|
emptydims(int *data, int length) |
|
|
|
{ |
|
|
|
int i, numempty = 0; |
|
|
|
|
|
|
|
for (i = 0; i < length; i++) |
|
|
|
if (data[i] == 0) |
|
|
|
numempty++; |
|
|
|
|
|
|
|
return (numempty); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* Read a string of one of the following forms into a dimensions array: |
|
|
|
* [12][1][10] |
|
|
|
@ -217,6 +210,26 @@ atodims(char *p, int *data, int *outlength) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef COMPILE_UNUSED_FUNCTIONS |
|
|
|
/* #ifdef COMPILE_UNUSED_FUNCTIONS added 2019-03-31 */ |
|
|
|
/* |
|
|
|
* Count number of empty dimensions in an array. |
|
|
|
*/ |
|
|
|
int |
|
|
|
emptydims(int *data, int length) |
|
|
|
{ |
|
|
|
int i, numempty = 0; |
|
|
|
|
|
|
|
for (i = 0; i < length; i++) |
|
|
|
if (data[i] == 0) |
|
|
|
numempty++; |
|
|
|
|
|
|
|
return (numempty); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* Skip to the first character that cannot be part of a dimension string. |
|
|
|
*/ |
|
|
|
@ -226,8 +239,10 @@ skipdims(char *p) |
|
|
|
if (!p) |
|
|
|
return NULL; |
|
|
|
|
|
|
|
while (*p && (*p == '[' || *p == ']' || *p == ',' || isspace_c(*p) || isdigit_c(*p))) |
|
|
|
while (*p && (*p == '[' || *p == ']' || *p == ',' || |
|
|
|
isspace_c(*p) || isdigit_c(*p))) |
|
|
|
p++; |
|
|
|
|
|
|
|
return (p); |
|
|
|
} |
|
|
|
#endif /* COMPILE_UNUSED_FUNCTIONS */ |