wchar_t *wcscat(wchar_t *dest, const wchar_t *src) { static wcscat_t real_wcscat = NULL; size_t max_bytes; uint dest_len, src_len; if (!real_memcpy) real_memcpy = (memcpy_t) getLibraryFunction("memcpy"); if (!real_wcscat) real_wcscat = (wcscat_t) getLibraryFunction("wcscat"); if (_libsafe_exclude) return real_wcscat(dest, src); if ((max_bytes = _libsafe_stackVariableP(dest)) == 0) { LOG(5, "wcscat(<heap var> , <src>)\n"); return real_wcscat(dest, src); } LOG(4, "wcscat(<stack var> , <src>) stack limit=%d\n", max_bytes); dest_len = wcsnlen(dest, max_bytes/sizeof(wchar_t)); src_len = wcsnlen(src, max_bytes/sizeof(wchar_t)); if (dest_len + src_len + 1 >= max_bytes/sizeof(wchar_t)) _libsafe_die("Overflow caused by wcscat()"); real_memcpy(dest + dest_len, src, src_len + 1); return dest; }
char *realpath(char *path, char resolved_path[]) { static realpath_t real_realpath = NULL; size_t max_size, len; char *res; char buf[MAXPATHLEN + 1]; if (!real_memcpy) real_memcpy = (memcpy_t) getLibraryFunction("memcpy"); if (!real_realpath) real_realpath = (realpath_t) getLibraryFunction("realpath"); if (_libsafe_exclude) return real_realpath(path, resolved_path); if ((max_size = _libsafe_stackVariableP(resolved_path)) == 0) { LOG(5, "realpath(<src>, <heap var>)\n"); return real_realpath(path, resolved_path); } LOG(4, "realpath(<src>, <stack var>) stack limit=%d\n", max_size); /* * realpath(3) copies at most MAXNAMLEN characters */ res = real_realpath(path, buf); if ((len = strnlen(buf, max_size)) == max_size) _libsafe_die("Overflow caused by realpath()"); real_memcpy(resolved_path, buf, len + 1); return (res == NULL) ? NULL : resolved_path; }
char *stpcpy(char *dest, const char *src) { static stpcpy_t real_stpcpy = NULL; size_t max_size, len; if (!real_memcpy) real_memcpy = (memcpy_t) getLibraryFunction("memcpy"); if (!real_stpcpy) real_stpcpy = (stpcpy_t) getLibraryFunction("stpcpy"); if (_libsafe_exclude) return real_stpcpy(dest, src); if ((max_size = _libsafe_stackVariableP(dest)) == 0) { LOG(5, "stpcpy(<heap var> , <src>)\n"); return real_stpcpy(dest, src); } LOG(4, "stpcpy(<stack var> , <src>) stack limit=%d)\n", max_size); /* * Note: we can't use the standard strncpy()! From the strncpy(3) manual * pages: In the case where the length of 'src' is less than that of * 'max_size', the remainder of 'dest' will be padded with nulls. We do * not want null written all over the 'dest', hence, our own * implementation. */ if ((len = strnlen(src, max_size)) == max_size) _libsafe_die("Overflow caused by stpcpy()"); real_memcpy(dest, src, len + 1); return dest + len; }
char *strcat(char *dest, const char *src) { static strcat_t real_strcat = NULL; size_t max_size; uint dest_len, src_len; if (!real_memcpy) real_memcpy = (memcpy_t) getLibraryFunction("memcpy"); if (!real_strcat) real_strcat = (strcat_t) getLibraryFunction("strcat"); if (_libsafe_exclude) return real_strcat(dest, src); if ((max_size = _libsafe_stackVariableP(dest)) == 0) { LOG(5, "strcat(<heap var> , <src>)\n"); return real_strcat(dest, src); } LOG(4, "strcat(<stack var> , <src>) stack limit=%d\n", max_size); dest_len = strnlen(dest, max_size); src_len = strnlen(src, max_size); if (dest_len + src_len >= max_size) _libsafe_die("Overflow caused by strcat()"); real_memcpy(dest + dest_len, src, src_len + 1); return dest; }
int sprintf(char *str, const char *format, ...) { static vsprintf_t real_vsprintf = NULL; static vsnprintf_t real_vsnprintf = NULL; size_t max_size; va_list ap; int res; if (!real_vsprintf) real_vsprintf = (vsprintf_t) getLibraryFunction("vsprintf"); if (!real_vsnprintf) real_vsnprintf = (vsnprintf_t) getLibraryFunction("vsnprintf"); if (_libsafe_exclude) { va_start(ap, format); res = real_vsprintf(str, format, ap); va_end(ap); return res; } if ((max_size = _libsafe_stackVariableP(str)) == 0) { LOG(5, "sprintf(<heap var>, <format>)\n"); va_start(ap, format); res = real_vsprintf(str, format, ap); va_end(ap); return res; } LOG(4, "sprintf(<stack var>, <format>) stack limit=%d\n", max_size); va_start(ap, format); /* * Some man pages say that -1 is returned if vsnprintf truncates the * output. However, some implementations actually return the number of * chars that would have been output with a sufficiently large output * buffer. Hence, we check for both res==-1 and res>max_size-1. The * max_size-1 is to make sure that there is room for the string-terminating * NULL. */ res = real_vsnprintf(str, max_size, format, ap); if (res == -1 || res > max_size-1) { _libsafe_die("overflow caused by sprintf()"); } va_end(ap); return res; }
int _IO_vfscanf (_IO_FILE *s, const char *format, _IO_va_list argptr, int *errp) { static _IO_vfscanf_t real_IO_vfscanf = NULL; int res, save_count; caddr_t ra_array[MAXLEVELS], fp_array[MAXLEVELS]; if (!real_IO_vfscanf) real_IO_vfscanf = (_IO_vfscanf_t) getLibraryFunction("_IO_vfscanf"); if (_libsafe_exclude) return real_IO_vfscanf(s, format, argptr, errp); save_count = _libsafe_save_ra_fp(sizeof(ra_array)/sizeof(caddr_t), ra_array, fp_array); res = real_IO_vfscanf(s, format, argptr, errp); if (save_count >= 0 && _libsafe_verify_ra_fp(save_count, ra_array, fp_array) == -1) { _libsafe_die("Overflow caused by *scanf()"); } return res; }
matObj *OPS_GetMaterialType(char *type, int sizeType) { // try existing loaded routines MaterialFunction *matFunction = theMaterialFunctions; bool found = false; while (matFunction != NULL && found == false) { if (strcmp(type, matFunction->funcName) == 0) { // create a new eleObject, set the function ptr & return it matObj *theMatObject = new matObj; theMatObject->matFunctPtr = matFunction->theFunct; /* opserr << "matObj *OPS_GetMaterialType() - FOUND " << endln; */ return theMatObject; } else matFunction = matFunction->next; } // ty to load new routine from dynamic library in load path matFunct matFunctPtr; void *libHandle; int res = getLibraryFunction(type, type, &libHandle, (void **)&matFunctPtr); if (res == 0) { // add the routine to the list of possible elements char *funcName = new char[strlen(type)+1]; strcpy(funcName, type); matFunction = new MaterialFunction; matFunction->theFunct = matFunctPtr; matFunction->funcName = funcName; matFunction->next = theMaterialFunctions; theMaterialFunctions = matFunction; // create a new eleObject, set the function ptr & return it matObj *theMatObject = new matObj; //eleObj *theEleObject = (eleObj *)malloc(sizeof( eleObj));; theMatObject->matFunctPtr = matFunction->theFunct; // fprintf(stderr,"getMaterial Address %p\n",theMatObject); return theMatObject; } return 0; }
eleObj *OPS_GetElementType(char *type, int sizeType) { // try existing loaded routines ElementFunction *eleFunction = theElementFunctions; bool found = false; while (eleFunction != NULL && found == false) { if (strcmp(type, eleFunction->funcName) == 0) { // create a new eleObject, set the function ptr & return it eleObj *theEleObject = new eleObj; theEleObject->eleFunctPtr = eleFunction->theFunct; return theEleObject; } else eleFunction = eleFunction->next; } // ty to load new routine from dynamic library in load path eleFunct eleFunctPtr; void *libHandle; int res = getLibraryFunction(type, type, &libHandle, (void **)&eleFunctPtr); if (res == 0) { // add the routine to the list of possible elements char *funcName = new char[strlen(type)+1]; strcpy(funcName, type); eleFunction = new ElementFunction; eleFunction->theFunct = eleFunctPtr; eleFunction->funcName = funcName; eleFunction->next = theElementFunctions; theElementFunctions = eleFunction; // create a new eleObject, set the function ptr & return it eleObj *theEleObject = new eleObj; //eleObj *theEleObject = (eleObj *)malloc(sizeof( eleObj));; theEleObject->eleFunctPtr = eleFunction->theFunct; return theEleObject; } return 0; }
extern "C" limCrvObj *OPS_GetLimitCurveType(char *type, int sizeType) { // try existing loaded routines LimitCurveFunction *limCrvFunction = theLimitCurveFunctions; bool found = false; while (limCrvFunction != NULL && found == false) { if (strcmp(type, limCrvFunction->funcName) == 0) { // create a new eleObject, set the function ptr & return it limCrvObj *theLimCrvObject = new limCrvObj; theLimCrvObject->limCrvFunctPtr = limCrvFunction->theFunct; /* opserr << "limCrvObj *OPS_GetLimitCurveType() - FOUND " << endln; */ return theLimCrvObject; } else limCrvFunction = limCrvFunction->next; } // try to load new routine from dynamic library in load path limCrvFunct limCrvFunctPtr; void *libHandle; int res = getLibraryFunction(type, type, &libHandle, (void **)&limCrvFunctPtr); if (res == 0) { // add the routine to the list of possible elements char *funcName = new char[strlen(type)+1]; strcpy(funcName, type); limCrvFunction = new LimitCurveFunction; limCrvFunction->theFunct = limCrvFunctPtr; limCrvFunction->funcName = funcName; limCrvFunction->next = theLimitCurveFunctions; theLimitCurveFunctions = limCrvFunction; // create a new eleObject, set the function ptr & return it limCrvObj *theLimCrvObject = new limCrvObj; theLimCrvObject->limCrvFunctPtr = limCrvFunction->theFunct; return theLimCrvObject; } return 0; }
/* * This is needed! See the strcpy() for the reason. -ab. */ void *memcpy(void *dest, const void *src, size_t n) { size_t max_size; if (!real_memcpy) real_memcpy = (memcpy_t) getLibraryFunction("memcpy"); if (_libsafe_exclude) return real_memcpy(dest, src, n); if ((max_size = _libsafe_stackVariableP(dest)) == 0) { LOG(5, "memcpy(<heap var> , <src>, %d)\n", n); return real_memcpy(dest, src, n); } LOG(4, "memcpy(<stack var> , <src>, %d) stack limit=%d)\n", n, max_size); if (n > max_size) _libsafe_die("Overflow caused by memcpy()"); return real_memcpy(dest, src, n); }
wchar_t *wcpcpy(wchar_t *dest, const wchar_t *src) { static wcpcpy_t real_wcpcpy = NULL; size_t max_bytes, max_wchars, len; if (!real_wcpcpy) real_wcpcpy = (wcpcpy_t) getLibraryFunction("wcpcpy"); if (_libsafe_exclude) return real_wcpcpy(dest, src); if ((max_bytes = _libsafe_stackVariableP(dest)) == 0) { LOG(5, "strcpy(<heap var> , <src>)\n"); return real_wcpcpy(dest, src); } LOG(4, "wcpcpy(<stack var> , <src>) stack limit=%d)\n", max_bytes); /* * Note: we can't use the standard wcsncpy()! From the wcsncpy(3) manual * pages: "If the length wcslen(src) is smaller than n, the remaining wide * characters in the array pointed to by dest are filled with L'\0' * characters." We do not want null written all over the 'dest', hence, * our own implementation. */ max_wchars = max_bytes / sizeof(wchar_t); if ((len = wcsnlen(src, max_wchars)) == max_wchars) { /* * If wcsnlen() returns max_wchars, it means that no L'\0' character was * found in the first max_wchars wide characters. So, this * wide-character string won't fit in the stack frame. */ _libsafe_die("Overflow caused by wcpcpy()"); } /* * Note that we can use wcpcpy() directly since there is no memcpy() * optimization as in the case of strcpy(). */ return real_wcpcpy(dest, src); }
char *strncpy(char *dest, const char *src, size_t n) { static strncpy_t real_strncpy = NULL; size_t max_size, len; if (!real_strncpy) real_strncpy = (strncpy_t) getLibraryFunction("strncpy"); if (_libsafe_exclude) return real_strncpy(dest, src, n); if ((max_size = _libsafe_stackVariableP(dest)) == 0) { LOG(5, "strncpy(<heap var> , <src>)\n"); return real_strncpy(dest, src, n); } LOG(4, "strncpy(<stack var> , <src>) stack limit=%d)\n", max_size); if (n > max_size && (len = strnlen(src, max_size)) == max_size) _libsafe_die("Overflow caused by strncpy()"); return real_strncpy(dest, src, n); }
char *getwd(char *buf) { static getwd_t real_getwd = NULL; size_t max_size; char *res; if (!real_getwd) real_getwd = (getwd_t) getLibraryFunction("getwd"); if (_libsafe_exclude) return real_getwd(buf); if ((max_size = _libsafe_stackVariableP(buf)) == 0) { LOG(5, "getwd(<heap var>)\n"); return real_getwd(buf); } LOG(4, "getwd(<stack var>) stack limit=%d\n", max_size); res = getcwd(buf, PATH_MAX); if ((strlen(buf) + 1) > max_size) _libsafe_die("Overflow caused by getwd()"); return res; }
char *gets(char *s) { static gets_t real_gets = NULL; size_t max_size, len; if (!real_gets) real_gets = (gets_t) getLibraryFunction("gets"); if (_libsafe_exclude) return real_gets(s); if ((max_size = _libsafe_stackVariableP(s)) == 0) { LOG(5, "gets(<heap var>)\n"); return real_gets(s); } LOG(4, "gets(<stack var>) stack limit=%d\n", max_size); fgets(s, max_size, stdin); len = strlen(s); if(s[len - 1] == '\n') s[len - 1] = '\0'; return s; }
int TclAddDatabase(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv, Domain &theDomain, FEM_ObjectBroker &theBroker) { if (createdDatabaseCommands == false) { // create the commands to commit and reset Tcl_CreateCommand(interp, "save", save, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateCommand(interp, "restore", restore, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); createdDatabaseCommands = true; } // make sure at least one other argument to contain integrator if (argc < 2) { opserr << "WARNING need to specify a Database type; valid type File, MySQL, BerkeleyDB \n"; return TCL_ERROR; } // // check argv[1] for type of Database, parse in rest of arguments // needed for the type of Database, create the object and add to Domain // // a File Database if (strcmp(argv[1],"File") == 0) { if (argc < 3) { opserr << "WARNING database File fileName? "; return TCL_ERROR; } // delete the old database if (theDatabase != 0) delete theDatabase; theDatabase = new FileDatastore(argv[2], theDomain, theBroker); // check we instantiated a database .. if not ran out of memory if (theDatabase == 0) { opserr << "WARNING ran out of memory - database File " << argv[2] << endln; return TCL_ERROR; } return TCL_OK; } else { // // maybe a database package // // try existing loaded packages DatabasePackageCommand *dataCommands = theDatabasePackageCommands; bool found = false; while (dataCommands != NULL && found == false) { if (strcmp(argv[1], dataCommands->funcName) == 0) { int result = (*(dataCommands->funcPtr))(clientData, interp, argc, argv, &theDomain, &theBroker, &theDatabase); return result; } else dataCommands = dataCommands->next; } // load new package void *libHandle; int (*funcPtr)(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv, Domain*, FEM_ObjectBroker *, FE_Datastore **); int databaseNameLength = strlen(argv[1]); char *tclFuncName = new char[databaseNameLength+12]; strcpy(tclFuncName, "TclCommand_"); strcpy(&tclFuncName[11], argv[1]); int res = getLibraryFunction(argv[1], tclFuncName, &libHandle, (void **)&funcPtr); if (res == 0) { char *databaseName = new char[databaseNameLength+1]; strcpy(databaseName, argv[1]); DatabasePackageCommand *theDataCommand = new DatabasePackageCommand; theDataCommand->funcPtr = funcPtr; theDataCommand->funcName = databaseName; theDataCommand->next = theDatabasePackageCommands; theDatabasePackageCommands = theDataCommand; int result = (*funcPtr)(clientData, interp, argc, argv, &theDomain, &theBroker, &theDatabase); return result; } } opserr << "WARNING No database type exists "; opserr << "for database of type:" << argv[1] << "valid database type File\n"; return TCL_ERROR; }
////////////////////////////////////////////////////////////////////// // the proceure invoked by the interpreter when limitCurve is invoked ////////////////////////////////////////////////////////////////////// int Tcl_AddLimitCurveCommand (ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv, Domain *theDomain) { OPS_ResetInputNoBuilder(clientData, interp, 2, argc, argv, theDomain); // Make sure there is a minimum number of arguments if (argc < 8) { opserr << "WARNING insufficient number of limit curve arguments\n"; opserr << "Want: limitCurve type? tag? <specific curve args>" << endln; return TCL_ERROR; } // Pointer to a limit curve that will be added to the model builder LimitCurve *theCurve = 0; /////////////////////// // Axial Limit Curve /////////////////////// if (strcmp(argv[1],"Axial") == 0) { if (argc != 9 && argc != 12 && argc != 14 && argc != 15) { opserr << "WARNING invalid number of arguments\n"; opserr << "Want: limitCurve Axial tag? eleTag? Fsw? Kdeg? Fres? defType? forType?" << endln; //SDK opserr << "<ndI? ndJ? dof? perpDirn? delta? eleRemove?>" << endln; return TCL_ERROR; } int tag; int eleTag; double Fsw;//SDK double Kdeg; double Fres; int defType, forType; int ndI = 0; int ndJ = 0; int dof = 0; int perpDirn = 0; int eleRemove = 0; double delta = 0.0; if (Tcl_GetInt(interp, argv[2], &tag) != TCL_OK) { opserr << "WARNING invalid Axial LimitCurve tag" << endln; return TCL_ERROR; } if (Tcl_GetInt(interp, argv[3], &eleTag) != TCL_OK) { opserr << "WARNING invalid element tag for associated beam-column element (eleTag)\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[4], &Fsw) != TCL_OK) { opserr << "WARNING invalid Fsw\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[5], &Kdeg) != TCL_OK) { opserr << "WARNING invalid degrading slope Kdeg\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[6], &Fres) != TCL_OK) { opserr << "WARNING invalid residual capacity Fres\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[7], &defType) != TCL_OK) { opserr << "WARNING invalid deformation type defType\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[8], &forType) != TCL_OK) { opserr << "WARNING invalid force type forType\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (defType == 2) { if (Tcl_GetInt(interp,argv[9], &ndI) != TCL_OK) { opserr << "WARNING invalid node I\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[10], &ndJ) != TCL_OK) { opserr << "WARNING invalid node J\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[11], &dof) != TCL_OK) { opserr << "WARNING invalid degree of freedom for drift\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[12], &perpDirn) != TCL_OK) { opserr << "WARNING invalid direction for column length\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } } if (argc >= 14) { if (Tcl_GetDouble(interp,argv[13], &delta) != TCL_OK) { opserr << "WARNING invalid shift in drift surface (delta)\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } } if (argc >= 15) { if (Tcl_GetInt(interp,argv[14], &eleRemove) != TCL_OK) { opserr << "WARNING invalid element removal option\n"; opserr << "LimitCurve Axial: " << tag << endln; return TCL_ERROR; } } // Parsing was successful, allocate the limit curve // Subtract one from dof and perpDirn for C indexing theCurve = new AxialCurve(interp, tag, eleTag, theDomain, Fsw, //SDK Kdeg, Fres, defType, forType, ndI, ndJ, dof-1, perpDirn-1, delta, eleRemove); } ////////////////////////// // Three Point LimitCurve ////////////////////////// else if (strcmp(argv[1],"RotationShearCurve") == 0) { void *theRSC = OPS_RotationShearCurve(); if (theRSC != 0) { theCurve = (LimitCurve *)theRSC; } else return TCL_ERROR; } else if (strcmp(argv[1],"ThreePoint") == 0) { if (argc < 14 || argc > 18) { opserr << "WARNING insufficient arguments\n"; opserr << "Want: limitCurve ThreePoint tag? eleTag? x1? y1? x2? y2? x3? y3?"; opserr << "Kdeg? Fres? defType? forType?" << endln; opserr << "<ndI? ndJ? dof? perpDirn?>" << endln; return TCL_ERROR; } int tag; int eleTag; double Kdeg; double Fres; int defType, forType; double x1, y1; double x2, y2; double x3, y3; int ndI = 0; int ndJ = 0; int dof = 0; int perpDirn = 0; if (Tcl_GetInt(interp, argv[2], &tag) != TCL_OK) { opserr << "WARNING invalid limitCurve ThreePoint tag" << endln; return TCL_ERROR; } if (Tcl_GetInt(interp, argv[3], &eleTag) != TCL_OK) { opserr << "WARNING invalid element tag for associated beam-column element (eleTag)\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[4], &x1) != TCL_OK) { opserr << "WARNING invalid x1\n"; opserr << "limitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[5], &y1) != TCL_OK) { opserr << "WARNING invalid y1\n"; opserr << "limitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[6], &x2) != TCL_OK) { opserr << "WARNING invalid x2\n"; opserr << "limitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[7], &y2) != TCL_OK) { opserr << "WARNING invalid y2\n"; opserr << "limitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[8], &x3) != TCL_OK) { opserr << "WARNING invalid x3\n"; opserr << "limitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[9], &y3) != TCL_OK) { opserr << "WARNING invalid y3\n"; opserr << "limitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[10], &Kdeg) != TCL_OK) { opserr << "WARNING invalid degrading slope Kdeg\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[11], &Fres) != TCL_OK) { opserr << "WARNING invalid residual capacity Fres\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[12], &defType) != TCL_OK) { opserr << "WARNING invalid deformation type defType\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[13], &forType) != TCL_OK) { opserr << "WARNING invalid force type forType\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (defType == 2) { if (Tcl_GetInt(interp,argv[14], &ndI) != TCL_OK) { opserr << "WARNING invalid node I\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[15], &ndJ) != TCL_OK) { opserr << "WARNING invalid node J\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[16], &dof) != TCL_OK) { opserr << "WARNING invalid degree of freedom for drift\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[17], &perpDirn) != TCL_OK) { opserr << "WARNING invalid direction for column length\n"; opserr << "LimitCurve ThreePoint: " << tag << endln; return TCL_ERROR; } } // Parsing was successful, allocate the material // Subtract one from dof and perpDirn for C indexing theCurve = new ThreePointCurve(tag, eleTag, theDomain, x1, y1, x2, y2, x3, y3, Kdeg, Fres, defType, forType, ndI, ndJ, dof-1, perpDirn-1); } ///////////////////////////// // Shear Limit Curve ///////////////////////////// else if (strcmp(argv[1],"Shear") == 0) { if (argc < 14 || argc > 19) { //SDK opserr << "WARNING insufficient arguments\n"; // printCommand(argc,argv); // Commented out by Terje opserr << "Want: limitCurve Shear tag? eleTag? rho? fc? b? h? d? Fsw? "; //SDK opserr << "Kdeg? Fres? defType? forType?" << endln; opserr << "<ndI? ndJ? dof? perpDirn? delta?>" << endln; return TCL_ERROR; } int tag; int eleTag; double Kdeg; double Fres; int defType, forType; double rho; double fc; double b, h, d; int ndI = 0; int ndJ = 0; int dof = 0; int perpDirn = 0; double Fsw = 0.0; //SDK double delta =0.0; if (Tcl_GetInt(interp, argv[2], &tag) != TCL_OK) { opserr << "WARNING invalid limitCurve Shear tag" << endln; return TCL_ERROR; } if (Tcl_GetInt(interp, argv[3], &eleTag) != TCL_OK) { opserr << "WARNING invalid element tag for associated beam-column element (eleTag)\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[4], &rho) != TCL_OK) { opserr << "WARNING invalid trans reinf ratio\n"; opserr << "limitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[5], &fc) != TCL_OK) { opserr << "WARNING invalid concrete strength\n"; opserr << "limitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[6], &b) != TCL_OK) { opserr << "WARNING invalid b\n"; opserr << "limitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[7], &h) != TCL_OK) { opserr << "WARNING invalid h\n"; opserr << "limitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[8], &d) != TCL_OK) { opserr << "WARNING invalid d\n"; opserr << "limitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[9], &Fsw) != TCL_OK) { //SDK opserr << "WARNING invalid Fsw\n"; opserr << "limitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[10], &Kdeg) != TCL_OK) { opserr << "WARNING invalid degrading slope Kdeg\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetDouble(interp,argv[11], &Fres) != TCL_OK) { opserr << "WARNING invalid residual capacity Fres\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[12], &defType) != TCL_OK) { opserr << "WARNING invalid deformation type defType\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[13], &forType) != TCL_OK) { opserr << "WARNING invalid force type forType\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (defType == 2) { if (Tcl_GetInt(interp,argv[14], &ndI) != TCL_OK) { opserr << "WARNING invalid node I\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[15], &ndJ) != TCL_OK) { opserr << "WARNING invalid node J\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[16], &dof) != TCL_OK) { opserr << "WARNING invalid degree of freedom for drift\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } if (Tcl_GetInt(interp,argv[17], &perpDirn) != TCL_OK) { opserr << "WARNING invalid direction for column length\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } } if (argc == 19) { if (Tcl_GetDouble(interp,argv[18], &delta) != TCL_OK) { opserr << "WARNING invalid shift in drift surface (delta)\n"; opserr << "LimitCurve Shear: " << tag << endln; return TCL_ERROR; } } // Parsing was successful, allocate the material // Subtract one from dof and perpDirn for C indexing theCurve = new ShearCurve(tag, eleTag, theDomain, rho, fc, b, h, d, Fsw, Kdeg, Fres, defType, forType, //SDK ndI, ndJ, dof-1, perpDirn-1, delta); } //***********************************************************************************************************************start package commands //**MRL else { //MRL Start Comment to allow OpenSees to look in package /*opserr << "WARNING unknown type of limitCurve: " << argv[1]; opserr << "\nValid types: Axial, ThreePoint, Shear" << endln; return TCL_ERROR; }*/ //MRL End Comment ////////////////////////////////////// // Curve could be defined in a package ////////////////////////////////////// if (theCurve == 0) { // maybe element in a class package already loaded // loop through linked list of loaded functions comparing names & if find call it LimitCurvePackageCommand *limCrvCommands = theLimitCurvePackageCommands; bool found = false; while (limCrvCommands != NULL && found == false) { if (strcmp(argv[1], limCrvCommands->funcName) == 0) { OPS_ResetInputNoBuilder(clientData, interp, 2, argc, argv, theDomain); theCurve = (LimitCurve *)(*(limCrvCommands->funcPtr))(argc, argv); found = true;; } else limCrvCommands = limCrvCommands->next; } } if (theCurve == 0) { // check to see if element is a procedure // maybe curve in a routine char *limCrvType = new char[strlen(argv[1])+1]; strcpy(limCrvType, argv[1]); limCrvObj *limCrvObject = OPS_GetLimitCurveType(limCrvType, strlen(limCrvType)); delete [] limCrvType; if (limCrvObject != 0) { theCurve = Tcl_addWrapperLimitCurve(limCrvObject, clientData, interp, argc, argv); if (theCurve == 0) delete limCrvObject; } } // maybe limit curve class exists in a package yet to be loaded if (theCurve == 0) { void *libHandle; void * (*funcPtr)(int argc, TCL_Char **argv); int limCrvNameLength = strlen(argv[1]); char *tclFuncName = new char[limCrvNameLength+12]; strcpy(tclFuncName, "OPS_"); strcpy(&tclFuncName[4], argv[1]); int res = getLibraryFunction(argv[1], tclFuncName, &libHandle, (void **)&funcPtr); delete [] tclFuncName; if (res == 0) { // add loaded function to list of functions char *limCrvName = new char[limCrvNameLength+1]; strcpy(limCrvName, argv[1]); LimitCurvePackageCommand *theLimCrvCommand = new LimitCurvePackageCommand; theLimCrvCommand->funcPtr = funcPtr; theLimCrvCommand->funcName = limCrvName; theLimCrvCommand->next = theLimitCurvePackageCommands; theLimitCurvePackageCommands = theLimCrvCommand; OPS_ResetInputNoBuilder(clientData, interp, 2, argc, argv, theDomain); theCurve = (LimitCurve *)(*funcPtr)(argc, argv); } } // if still here the element command does not exist if (theCurve == 0) { opserr << "WARNING could not create LimitCurve " << argv[1] << endln; return TCL_ERROR; } // Now add the limit curve to the modelBuilder if (OPS_addLimitCurve(theCurve) < 0) { opserr << "WARNING could not add LimitCurve to the domain\n"; opserr << *theCurve << endln; delete theCurve; // invoke the limit curve objects destructor, otherwise mem leak return TCL_ERROR; } //MRL end else for package } // Ensure we have created the Material, out of memory if got here and no material if (theCurve == 0) { opserr << "WARNING ran out of memory creating limitCurve\n"; opserr << argv[1] << endln; return TCL_ERROR; } // Now add the curve to the modelBuilder if (OPS_addLimitCurve(theCurve) < 0) { opserr << "WARNING could not add limitCurve to the domain\n"; opserr << *theCurve << endln; delete theCurve; // invoke the curve objects destructor, otherwise mem leak return TCL_ERROR; } return TCL_OK; }
/* * No variant of printf() can be called here!!! */ int vfprintf(FILE *fp, const char *format, va_list ap) { static vfprintf_t real_vfprintf = NULL; int res; char *p, *pnum; int c = -1; /* Next var arg to be used */ int in_mth; /* Are we currently looking for an m-th argument? */ int atoi(const char *nptr); if (!real_vfprintf) real_vfprintf = (vfprintf_t) getLibraryFunction("vfprintf"); if (_libsafe_exclude) { res = real_vfprintf(fp, format, ap); return res; } /* * Now check to see if there are any %n specifiers. If %n specifiers * exist, then check the destination pointer to make sure it isn't a return * address or frame pointer. */ /* * %[<value>][<flags>][<fieldwidth>][.<precision>][<lengthmod>]<convspec> * * <value> = <pnum>$ * <flags> = # | 0 | - | <space> | + | ' | I * NOTE: <flags> can be in any order and can be repeated * <fieldwidth> = <num> | *[<pnum>$] * <precision> = <num> | *[<pnum>$] * <lengthmod> = hh | h | l | ll | L | q | j | z | t * <convspec> = d | i | o | u | x | X | e | E | f | F | g | G | a | A | c | * s | C | S | p | n | % * * <num> = any integer, including negative and zero integers; can have any * number of leading '0' * <pnum> = positive integer; can have any number of leading '0' */ for (p=(char*)format; *p; p++) { if (*p == '%') { /* * Check for [<value>]. */ pnum = NULL; for (p++,in_mth=0; *p && isdigit((int)*p); p++) { if (in_mth == 0) pnum = p; in_mth = 1; } if (*p == (char)NULL) break; if (in_mth) { if (*p == '$') { p++; } else { c++; p--; continue; } } /* * Check for [<flags>]. */ for (; *p && is_printf_flag[(int)*p]; p++); if (*p == (char)NULL) break; /* * Check for [<fieldwidth>]. Note that '-' is consumed previously. */ if (*p == '*') { for (p++,in_mth=0; *p && isdigit((int)*p); p++) in_mth = 1; if (*p == (char)NULL) break; if (in_mth) { if (*p == '$') { p++; } else { c++; p--; continue; } } else { c++; } } else { for (; *p && isdigit((int)*p); p++); if (*p == (char)NULL) break; } /* * Check for [<precision>]. */ if (*p == '.') { p++; if (*p == '*') { for (p++,in_mth=0; *p && isdigit((int)*p); p++) in_mth = 1; if (*p == (char)NULL) break; if (in_mth) { if (*p == '$') { p++; } else { c++; p--; continue; } } else { c++; } } else { for (; *p && isdigit((int)*p); p++); if (*p == (char)NULL) break; } } /* * Check for [<lengthmod>]. */ if (is_printf_lengthmod[(int)*p]) { p++; if (*p == (char)NULL) break; if ((*p == 'h' && *(p-1) == 'h') || (*p == 'l' && *(p-1) == 'l')) { p++; } if (*p == (char)NULL) break; } /* * Check for <convspec>. */ if (is_printf_convspec[(int)*p]) { caddr_t addr; c++; if (pnum) { addr = *((caddr_t*)(ap + (atoi(pnum)-1)*sizeof(char*))); } else { addr = *((caddr_t*)(ap + c*sizeof(char*))); } if (*p == 'n') { if (_libsafe_raVariableP((void *)(addr))) { _libsafe_die("printf(\"%%n\")"); } } } } } res = real_vfprintf(fp, format, ap); return res; }