16 changed files with 701 additions and 598 deletions
-
6ChangeLog
-
4doc/version.texi
-
33src/frontend/numparam/general.h
-
325src/frontend/numparam/mystring.c
-
16src/frontend/numparam/numparam.h
-
2src/frontend/numparam/readme.txt
-
154src/frontend/numparam/spicenum.c
-
191src/frontend/numparam/xpressn.c
-
1src/include/Makefile.am
-
33src/include/hash.h
-
1src/misc/Makefile.am
-
352src/misc/dstring.c
-
16src/misc/hash.c
-
67src/misc/string.c
-
4src/spicelib/analysis/cktop.c
-
94visualc/vngspice.sln
@ -1,4 +1,4 @@ |
|||
@set UPDATED 25 November 2008 |
|||
@set UPDATED-MONTH November 2008 |
|||
@set EDITION 18 |
|||
@set VERSION 18 |
|||
@set EDITION 20 |
|||
@set VERSION 20 |
|||
@ -0,0 +1,352 @@ |
|||
/* ----------------------------------------------------------------- |
|||
FILE: dstring.c |
|||
DESCRIPTION:This file contains the routines for manipulating dynamic strings. |
|||
CONTENTS: |
|||
DATE: Wed Mar 24 18:38:28 CDT 2010 |
|||
REVISIONS: $Log$ |
|||
REVISIONS: Revision 1.1 2010-03-25 22:44:38 dwarning |
|||
REVISIONS: Bill Swartz patch |
|||
REVISIONS: |
|||
----------------------------------------------------------------- */ |
|||
#include "ngspice.h" |
|||
#include <stdarg.h> |
|||
#include "dstring.h" |
|||
|
|||
/* definitions local to this file only */ |
|||
|
|||
/* ********************** TYPE DEFINITIONS ************************* */ |
|||
|
|||
/* ********************** STATIC DEFINITIONS ************************* */ |
|||
/* |
|||
*---------------------------------------------------------------------- |
|||
* |
|||
* spice_dstring_init -- |
|||
* |
|||
* Initializes a dynamic string, discarding any previous contents |
|||
* of the string (spice_dstring_free should have been called already |
|||
* if the dynamic string was previously in use). |
|||
* |
|||
* Results: |
|||
* None. |
|||
* |
|||
* Side effects: |
|||
* The dynamic string is initialized to be empty. |
|||
* |
|||
*---------------------------------------------------------------------- |
|||
*/ |
|||
|
|||
void spice_dstring_init(SPICE_DSTRINGPTR dsPtr) |
|||
{ |
|||
dsPtr->string = dsPtr->staticSpace ; |
|||
dsPtr->length = 0 ; |
|||
dsPtr->spaceAvl = SPICE_DSTRING_STATIC_SIZE ; |
|||
dsPtr->staticSpace[0] = EOS; |
|||
} /* end spice_dstring_init() */ |
|||
|
|||
/* |
|||
*---------------------------------------------------------------------- |
|||
* |
|||
* spice_dstring_append -- |
|||
* |
|||
* Append more characters to the current value of a dynamic string. |
|||
* |
|||
* Results: |
|||
* The return value is a pointer to the dynamic string's new value. |
|||
* |
|||
* Side effects: |
|||
* Length bytes from string (or all of string if length is less |
|||
* than zero) are added to the current value of the string. Memory |
|||
* gets reallocated if needed to accomodate the string's new size. |
|||
* |
|||
* Notes: char *string; String to append. If length is -1 then |
|||
* this must be null-terminated. |
|||
* INT length; Number of characters from string to append. |
|||
* If < 0, then append all of string, up to null at end. |
|||
* |
|||
*---------------------------------------------------------------------- |
|||
*/ |
|||
char *spice_dstring_append(SPICE_DSTRINGPTR dsPtr,char *string,int length) |
|||
{ |
|||
int newSize ; /* needed size */ |
|||
char *newString ; /* newly allocated string buffer */ |
|||
char *dst ; /* destination */ |
|||
char *end ; /* end of string */ |
|||
|
|||
if( length < 0){ |
|||
length = strlen(string) ; |
|||
} |
|||
newSize = length + dsPtr->length ; |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* Allocate a larger buffer for the string if the current one isn't |
|||
* large enough. Allocate extra space in the new buffer so that there |
|||
* will be room to grow before we have to allocate again. |
|||
----------------------------------------------------------------- */ |
|||
if (newSize >= dsPtr->spaceAvl) { |
|||
dsPtr->spaceAvl = 2 * newSize ; |
|||
newString = tmalloc( dsPtr->spaceAvl * sizeof(char) ) ; |
|||
memcpy((void *) newString, (void *) dsPtr->string, (size_t) dsPtr->length) ; |
|||
if (dsPtr->string != dsPtr->staticSpace) { |
|||
txfree(dsPtr->string) ; |
|||
} |
|||
dsPtr->string = newString; |
|||
} |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* Copy the new string into the buffer at the end of the old |
|||
* one. |
|||
----------------------------------------------------------------- */ |
|||
for( dst = dsPtr->string + dsPtr->length, end = string+length; |
|||
string < end; string++, dst++) { |
|||
*dst = *string ; |
|||
} |
|||
*dst = EOS ; |
|||
dsPtr->length += length ; |
|||
|
|||
return(dsPtr->string) ; |
|||
|
|||
} /* end spice_dstring_append() */ |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* Function: add character c to dynamic string dstr_p. |
|||
* ----------------------------------------------------------------- */ |
|||
char *spice_dstring_append_char( SPICE_DSTRINGPTR dstr_p, char c) |
|||
{ |
|||
char tmp_str[2] ; /* temporary string for append */ |
|||
char *val_p ; /* return value */ |
|||
|
|||
tmp_str[0] = c ; |
|||
tmp_str[1] = EOS ; |
|||
val_p = spice_dstring_append( dstr_p, tmp_str, -1 ) ; |
|||
return(val_p) ; |
|||
} /* end spice_dstring_append_char() */ |
|||
|
|||
static int spice_format_length( va_list args, char *fmt ) |
|||
{ |
|||
int i ; /* integer */ |
|||
int len ; /* length of format */ |
|||
int size_format ; /* width of field */ |
|||
int found_special ; /* look for special characters */ |
|||
char *s ; /* string */ |
|||
char c ; /* character */ |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* First find length of buffer. |
|||
----------------------------------------------------------------- */ |
|||
len = 0 ; |
|||
while(fmt && *fmt){ |
|||
if( *fmt == '%' ){ |
|||
fmt++ ; |
|||
if( *fmt == '%' ){ |
|||
len++ ; |
|||
} else { |
|||
/* ----------------------------------------------------------------- |
|||
* We have a real formatting character, loop until we get a special |
|||
* character. |
|||
----------------------------------------------------------------- */ |
|||
if( *fmt == '.' || *fmt == '-' ){ |
|||
fmt++ ; /* skip over these characters */ |
|||
} |
|||
size_format = atoi(fmt) ; |
|||
if( size_format > 0 ){ |
|||
len += size_format ; |
|||
} |
|||
found_special = FALSE ; |
|||
for( ; fmt && *fmt ; fmt++ ){ |
|||
switch( *fmt ){ |
|||
case 's': |
|||
s = va_arg(args, char *) ; |
|||
if( s ){ |
|||
len += strlen(s) ; |
|||
} |
|||
found_special = TRUE ; |
|||
break ; |
|||
case 'i': |
|||
case 'd': |
|||
case 'o': |
|||
case 'x': |
|||
case 'X': |
|||
case 'u': |
|||
i = va_arg(args, int) ; |
|||
len += 10 ; |
|||
found_special = TRUE ; |
|||
break ; |
|||
case 'c': |
|||
c = va_arg(args, int) ; |
|||
len++ ; |
|||
found_special = TRUE ; |
|||
break ; |
|||
case 'f': |
|||
case 'e': |
|||
case 'F': |
|||
case 'g': |
|||
case 'G': |
|||
c = va_arg(args, double) ; |
|||
len += 35 ; |
|||
found_special = TRUE ; |
|||
break ; |
|||
default: |
|||
; |
|||
} /* end switch() */ |
|||
|
|||
if( found_special ){ |
|||
break ; |
|||
} |
|||
} |
|||
} |
|||
} else { |
|||
len++ ; |
|||
} |
|||
fmt++ ; |
|||
} /* end while() */ |
|||
va_end(args) ; |
|||
|
|||
return(len) ; |
|||
|
|||
} /* end Ymessage_format_length() */ |
|||
|
|||
|
|||
char *spice_dstring_print( SPICE_DSTRINGPTR dsPtr,char *format, ... ) |
|||
{ |
|||
va_list args ; |
|||
int format_len ; /* length of format */ |
|||
int length ; /* new length */ |
|||
int orig_length ; /* original length of buffer */ |
|||
char *buffer ; /* proper length of buffer */ |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* First get the length of the buffer needed. |
|||
----------------------------------------------------------------- */ |
|||
va_start( args, format ) ; |
|||
format_len = spice_format_length(args,format) ; |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* Next allocate the proper buffer size. |
|||
----------------------------------------------------------------- */ |
|||
orig_length = dsPtr->length ; |
|||
length = orig_length + format_len + 1 ; |
|||
buffer = spice_dstring_setlength( dsPtr, length) ; |
|||
|
|||
/* ----------------------------------------------------------------- |
|||
* Convert the format. |
|||
----------------------------------------------------------------- */ |
|||
va_start( args, format ) ; |
|||
if( format ){ |
|||
vsprintf( buffer + orig_length, format, args ) ; |
|||
dsPtr->length = strlen( buffer ) ; |
|||
} else { |
|||
buffer = NULL ; |
|||
} |
|||
va_end(args) ; |
|||
return( buffer ) ; |
|||
|
|||
} /* end spice_dstring_print() */ |
|||
|
|||
/* |
|||
*---------------------------------------------------------------------- |
|||
* |
|||
* _spice_dstring_setlength -- |
|||
* |
|||
* Change the length of a dynamic string. This can cause the |
|||
* string to either grow or shrink, depending on the value of |
|||
* length. |
|||
* |
|||
* Results: |
|||
* Returns the current string buffer. |
|||
* |
|||
* Side effects: |
|||
* The length of dsPtr is changed to length but a null byte is not |
|||
* stored at that position in the string. Use spice_dstring_setlength |
|||
* for that function. If length is larger |
|||
* than the space allocated for dsPtr, then a panic occurs. |
|||
* |
|||
*---------------------------------------------------------------------- |
|||
*/ |
|||
|
|||
char *_spice_dstring_setlength(SPICE_DSTRINGPTR dsPtr,int length) |
|||
{ |
|||
char *newString ; |
|||
|
|||
if (length < 0) { |
|||
length = 0 ; |
|||
} |
|||
if (length >= dsPtr->spaceAvl) { |
|||
|
|||
dsPtr->spaceAvl = length+1; |
|||
newString = tmalloc( dsPtr->spaceAvl * sizeof(char) ) ; |
|||
/* ----------------------------------------------------------------- |
|||
* SPECIAL NOTE: must use memcpy, not strcpy, to copy the string |
|||
* to a larger buffer, since there may be embedded NULLs in the |
|||
* string in some cases. |
|||
----------------------------------------------------------------- */ |
|||
memcpy((void *) newString, (void *) dsPtr->string, (size_t) dsPtr->length) ; |
|||
if( dsPtr->string != dsPtr->staticSpace ) { |
|||
txfree(dsPtr->string) ; |
|||
} |
|||
dsPtr->string = newString ; |
|||
} |
|||
dsPtr->length = length ; |
|||
return(dsPtr->string) ; |
|||
|
|||
} /* end _spice_dstring_setlength() */ |
|||
|
|||
|
|||
/* |
|||
*---------------------------------------------------------------------- |
|||
* |
|||
* spice_dstring_setlength -- |
|||
* |
|||
* Change the length of a dynamic string. This can cause the |
|||
* string to either grow or shrink, depending on the value of |
|||
* length. |
|||
* |
|||
* Results: |
|||
* Returns the current string buffer. |
|||
* |
|||
* Side effects: |
|||
* The length of dsPtr is changed to length and a null byte is |
|||
* stored at that position in the string. If length is larger |
|||
* than the space allocated for dsPtr, then a panic occurs. |
|||
* |
|||
*---------------------------------------------------------------------- |
|||
*/ |
|||
|
|||
char *spice_dstring_setlength(SPICE_DSTRINGPTR dsPtr,int length) |
|||
{ |
|||
char *str_p ; /* newly create string */ |
|||
|
|||
str_p = _spice_dstring_setlength( dsPtr,length) ; |
|||
str_p[length] = EOS ; |
|||
return( str_p ) ; |
|||
|
|||
} /* end spice_dstring_setlength() */ |
|||
|
|||
/* |
|||
*---------------------------------------------------------------------- |
|||
* |
|||
* spice_dstring_free -- |
|||
* |
|||
* Frees up any memory allocated for the dynamic string and |
|||
* reinitializes the string to an empty state. |
|||
* |
|||
* Results: |
|||
* None. |
|||
* |
|||
* Side effects: |
|||
* The previous contents of the dynamic string are lost, and |
|||
* the new value is an empty string. |
|||
* |
|||
*---------------------------------------------------------------------- |
|||
*/ |
|||
|
|||
void spice_dstring_free(SPICE_DSTRINGPTR dsPtr) |
|||
{ |
|||
if (dsPtr->string != dsPtr->staticSpace) { |
|||
txfree(dsPtr->string) ; |
|||
} |
|||
dsPtr->string = dsPtr->staticSpace ; |
|||
dsPtr->length = 0 ; |
|||
dsPtr->spaceAvl = SPICE_DSTRING_STATIC_SIZE; |
|||
dsPtr->staticSpace[0] = EOS ; |
|||
|
|||
} /* end spice_dstring_free() */ |
|||
@ -1,47 +1,47 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 10.00 |
|||
# Visual Studio 2008 |
|||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vngspice", "vngspice.vcproj", "{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
console_debug|Win32 = console_debug|Win32 |
|||
console_debug|x64 = console_debug|x64 |
|||
console_release|Win32 = console_release|Win32 |
|||
console_release|x64 = console_release|x64 |
|||
Debug|Win32 = Debug|Win32 |
|||
Debug|x64 = Debug|x64 |
|||
Release|Win32 = Release|Win32 |
|||
Release|x64 = Release|x64 |
|||
release64|Win32 = release64|Win32 |
|||
release64|x64 = release64|x64 |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|Win32.ActiveCfg = console_debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|Win32.Build.0 = console_debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|x64.ActiveCfg = console_debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|x64.Build.0 = console_debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|Win32.ActiveCfg = console_release|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|Win32.Build.0 = console_release|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|x64.ActiveCfg = console_release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|x64.Build.0 = console_release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.ActiveCfg = Debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.Build.0 = Debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|x64.ActiveCfg = Debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|x64.Build.0 = Debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.ActiveCfg = Debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.Build.0 = Debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|x64.ActiveCfg = Release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|x64.Build.0 = Release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|Win32.ActiveCfg = release64|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|Win32.Build.0 = release64|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|x64.ActiveCfg = release64|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|x64.Build.0 = release64|x64 |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
GlobalSection(ExtensibilityGlobals) = postSolution |
|||
AMDCaProjectFile = D:\Spice_general\ng-spice-rework\visualc\CodeAnalyst\vngspice.caw |
|||
EndGlobalSection |
|||
EndGlobal |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 10.00 |
|||
# Visual C++ Express 2008 |
|||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vngspice", "vngspice.vcproj", "{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
console_debug|Win32 = console_debug|Win32 |
|||
console_debug|x64 = console_debug|x64 |
|||
console_release|Win32 = console_release|Win32 |
|||
console_release|x64 = console_release|x64 |
|||
Debug|Win32 = Debug|Win32 |
|||
Debug|x64 = Debug|x64 |
|||
Release|Win32 = Release|Win32 |
|||
Release|x64 = Release|x64 |
|||
release64|Win32 = release64|Win32 |
|||
release64|x64 = release64|x64 |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|Win32.ActiveCfg = console_debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|Win32.Build.0 = console_debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|x64.ActiveCfg = console_debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_debug|x64.Build.0 = console_debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|Win32.ActiveCfg = console_release|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|Win32.Build.0 = console_release|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|x64.ActiveCfg = console_release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|x64.Build.0 = console_release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.ActiveCfg = Debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.Build.0 = Debug|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|x64.ActiveCfg = Debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|x64.Build.0 = Debug|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.ActiveCfg = Release|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.Build.0 = Release|Win32 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|x64.ActiveCfg = Release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|x64.Build.0 = Release|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|Win32.ActiveCfg = release64|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|Win32.Build.0 = release64|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|x64.ActiveCfg = release64|x64 |
|||
{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|x64.Build.0 = release64|x64 |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
GlobalSection(ExtensibilityGlobals) = postSolution |
|||
AMDCaProjectFile = D:\Spice_general\ng-spice-rework\visualc\CodeAnalyst\vngspice.caw |
|||
EndGlobalSection |
|||
EndGlobal |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue