int myfunc(jual_xapi *JXAPI) { void *L = JXAPI->LS; // Map functions as required defGetNumber *GetNumber = (defGetNumber *)JXAPI->fnGetNumber; defGetString *GetString = (defGetString *)JXAPI->fnGetString; defGetObject *GetObject = (defGetObject *)JXAPI->fnGetObject; defNumberPush *NumberPush = (defNumberPush *)JXAPI->fnNumberPush; defStrInit *StrInit = (defStrInit *)JXAPI->fnStrInit; defStrAppend *StrAppend = (defStrAppend *)JXAPI->fnStrAppend; defStrPush *StrPush = (defStrPush *)JXAPI->fnStrPush; int iNum = GetNumber(L, 1); size_t tSize; const char *szParm2 = GetString(L, 2, &tSize); printf("you entered %d %s %d\n", iNum, szParm2, tSize); char strBuffer[JXAPI->STRBUFFER_SIZE]; char *cResult = StrInit(L, strBuffer, 16); const char text[]="Hello from the C language"; StrAppend(strBuffer, text, sizeof(text)-1); const char text2[]="More greeting from the C language"; StrAppend(strBuffer, text2, sizeof(text2)-1); StrPush(strBuffer); return 1; }
/** Update all Test data Throws: SCXInternalErrorException - If any instance is not a TestInstance */ void WkEnumeration::Update(bool updateInstances) { size_t count = 5; SCX_LOGTRACE(m_log, StrAppend(StrAppend(L"WkEnumeration Update() - ", updateInstances).append(L" - "), count)); // add items if needed (i.e. currently empty) if (0 == Size()) { for (size_t i=Size(); i<count; i++) { SCX_LOGTRACE(m_log, StrAppend(L"WkEnumeration Update() - Adding Test ", i)); AddInstance(SCXHandle<TestInstance>(new TestInstance(i))); } } if (updateInstances) { for (size_t i=0; i<Size(); i++) { SCXHandle<TestInstance> inst = GetInstance(i); unsigned int valA = 0; unsigned int valB = 0; inst->GetAValue(valA); inst->GetBValue(valB); inst->UpdateValueA(valA + 1); inst->UpdateValueB(valB + 2); inst->UpdateValueD(); inst->UpdateValueE(); inst->UpdateValueF(); } } }
void DqsOrderBy(char** query, const char* field) { StrAppend(query, " ORDER BY "); StrAppend(query, field); return; }
std::string StrConcat(const T1 &a, const T2 &b) { std::string result; StrAppend(result, a); StrAppend(result, b); return result; }
XTDBError XTDBInitHandle(const char* dbName,const char* dir,XTDBHandle** out) { XTDBError rv; XTDBHandle* h = malloc(sizeof(XTDBHandle)); int rc; //InitQueryModule(); if (!h) { return XTDB_NO_MEM; } memset(h,0,sizeof(*h)); StrInit(&h->dbName); if (StrAppend(&h->dbName,dbName)) { rv = XTDB_NO_MEM; goto error; } StrInit(&h->dataDir); if (StrAppend(&h->dataDir,dir)) { rv = XTDB_NO_MEM; goto error; } StrInit(&h->descName); if (StrAppendFmt(&h->descName,"%s/%s.desc",dir,dbName)) { rv = XTDB_NO_MEM; goto error; } StrInit(&h->mainDbFileName); if (StrAppendFmt(&h->mainDbFileName,"%s/%s.main.data",dir,dbName)) { rv = XTDB_NO_MEM; goto error; } h->indexes = tcmapnew2(23); if (!h->indexes) { rv = XTDB_NO_MEM; goto error; } //h->indexes = hash_table_new(stringhash,string_equal); //hash_table_register_free_functions(h->indexes,free,NULL); if (!(h->mainDB = DBInit(h->mainDbFileName.ptr,BDBOCREAT|BDBOWRITER))) { rv = XTDB_NO_MEM; goto error; } if (!(rc=DBOpen(h->mainDB,BDBOCREAT|BDBOWRITER))) { rv = DBGetLastError(h->mainDB); goto error; } if (!XTDBLoadIndexes(h)) { rv = h->error; goto error; } *out = h; return XTDB_OK; error: XTDBFreeHandle(h); *out = NULL; return rv; }
static int WriteStassocRecord(struct stassocList *sa, FILE* ptr) { char buffer[200]; *buffer = '\0'; LngAppend(buffer, "%8d", 8, sa->element->stassid); StrAppend(buffer, "%-6s", 6, sa->element->sta); StrAppend(buffer, "%-7s", 7, sa->element->etype); StrAppend(buffer, "%-32s", 32, sa->element->location); DblAppend(buffer, "%7.2f", 7, sa->element->dist); DblAppend(buffer, "%7.2f", 7, sa->element->azimuth); DblAppend(buffer, "%9.4f", 9, sa->element->lat); DblAppend(buffer, "%9.4f", 9, sa->element->lon); DblAppend(buffer, "%9.4f", 9, sa->element->depth); DblAppend(buffer, "17.5f", 17, sa->element->time); DblAppend(buffer, "%7.2f", 7, sa->element->imb); DblAppend(buffer, "%7.2f", 7, sa->element->ims); DblAppend(buffer, "%7.2f", 7, sa->element->iml); StrAppend(buffer, "%-15s", 15, sa->element->auth); LngAppend(buffer, "%8d", 8, sa->element->commid); StrAppend(buffer, "%-17s", 17, sa->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
/** Parses a stream of the form # Comment key1 = value1 key2 = value2 \param[in] configuration Stream with configuration data. Typically as read from a configuration file. */ void ConfigurationParser::ParseStream(std::wistream& configuration) { SCXCoreLib::SCXLogHandle log = SCXLogHandleFactory::GetLogHandle(L"scx.core.providers.runasprovider.configparser"); std::vector<std::wstring> lines; SCXStream::NLFs nlfs; SCXStream::ReadAllLines(configuration, lines, nlfs); SCX_LOGTRACE(log, StrAppend(L"Number of lines in configuration: ", lines.size())); for (std::vector<std::wstring>::const_iterator it = lines.begin(); it != lines.end(); it++) { std::wstring line = StrTrim(*it); SCX_LOGTRACE(log, StrAppend(L"Parsing line: ", line)); if (line.length() == 0 || line.substr(0,1) == L"#") //comment { continue; } std::vector<std::wstring> parts; StrTokenize(line, parts, L"="); if (parts.size() == 2) { iterator iter = lower_bound(parts[0]); if ((end() != iter) && !(key_comp()(parts[0], iter->first))) { iter->second = parts[1]; } else { insert(iter, std::pair<const std::wstring, std::wstring>(parts[0], parts[1])); } } } }
static int WriteSitechanRecord(struct sitechanList *sc, FILE* ptr) { char buffer[150]; if(!CSSchrDefined(sc->element->sta) || !CSSchrDefined(sc->element->chan) || !CSSlngDefined(sc->element->ondate) ){ css_warning("Skipping sitechan record because of missing key...\n"); return 1; } *buffer = '\0'; StrAppend(buffer, "%-6s", 6, sc->element->sta); StrAppend(buffer, "%-8s", 8, sc->element->chan); LngAppend(buffer, "%8d", 8, sc->element->ondate); LngAppend(buffer, "%8d", 8, sc->element->chanid); LngAppend(buffer, "%8d", 8, sc->element->offdate); StrAppend(buffer, "%-4s", 4, sc->element->ctype); DblAppend(buffer, "%9.4f", 9, sc->element->edepth); DblAppend(buffer, "%6.1f", 6, sc->element->hang); DblAppend(buffer, "%6.1f", 6, sc->element->vang); StrAppend(buffer, "%-50s", 50, sc->element->descrip); StrAppend(buffer, "%-17s", 17, sc->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
static int WriteSiteRecord(struct siteList *si, FILE* ptr) { char buffer[160]; if(!CSSchrDefined(si->element->sta) || !CSSlngDefined(si->element->ondate) ){ css_warning("Skipping site record because of missing key...\n"); return 1; } *buffer = '\0'; StrAppend(buffer, "%-6s", 6, si->element->sta); LngAppend(buffer, "%8d", 8, si->element->ondate); LngAppend(buffer, "%8d", 8, si->element->offdate); DblAppend(buffer, "%9.4f", 9, si->element->lat); DblAppend(buffer, "%9.4f", 9, si->element->lon); DblAppend(buffer, "%9.4f", 9, si->element->elev); StrAppend(buffer, "%-50s", 50, si->element->staname); StrAppend(buffer, "%-4s", 4, si->element->statype); StrAppend(buffer, "%-6s", 6, si->element->refsta); DblAppend(buffer, "%9.4f", 9, si->element->dnorth); DblAppend(buffer, "%9.4f", 9, si->element->deast); StrAppend(buffer, "%-17s", 17, si->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
static int WriteSensorRecord(struct sensorList *se, FILE* ptr) { char buffer[160]; if(!CSSdblDefined(se->element->time) || !CSSchrDefined(se->element->sta) || !CSSchrDefined(se->element->chan) ){ css_warning("Skipping sensor record because of missing key...\n"); return 1; } *buffer = '\0'; StrAppend(buffer, "%-6s", 6, se->element->sta); StrAppend(buffer, "%-8s", 8, se->element->chan); DblAppend(buffer, "%17.5f", 17, se->element->time); DblAppend(buffer, "%17.5f", 17, se->element->endtime); LngAppend(buffer, "%8d", 8, se->element->inid); LngAppend(buffer, "%8d", 8, se->element->chanid); LngAppend(buffer, "%8d", 8, se->element->jdate); DblAppend(buffer, "%16.6f", 16, se->element->calratio); DblAppend(buffer, "%16.6f", 16, se->element->calper); DblAppend(buffer, "%6.2f", 6, se->element->tshift); StrAppend(buffer, "%-1s", 1, se->element->instant); StrAppend(buffer, "%-17s", 17, se->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
char_t* GetStorePath(const char_t* name) { char_t* path = GetAppDataPath(); if (NULL == path) return NULL; path = StrAppend(path, -1, TEXT("\\InfoMan"), -1); if (NULL == path) return NULL; BOOL res = CreateDirectory(path, NULL); if (!res && ERROR_ALREADY_EXISTS != GetLastError()) { free(path); return NULL; } path = StrAppend(path, -1, TEXT("\\"), 1); if (NULL == path) return NULL; path = StrAppend(path, -1, name, -1); if (NULL == path) return NULL; path = StrAppend(path, -1, TEXT(".dat"), -1); if (NULL == path) return NULL; return path; }
void DqsConditionKeyword(char** query, const char* field, DQS_COMPARISON compare, const char* value, int index) { StrAppend(query, (index == 0) ? " WHERE " : " AND "); StrAppend(query, field); DqsAppendComparison(query, compare); StrAppend(query, value); return; }
char* DisInit(const char* table) { char* sql; sql = StrStrdup("INSERT INTO "); StrAppend(&sql, table); StrAppend(&sql, " VALUES (NULL"); return sql; }
void DisAppendInt(char** sql, int what) { char buffer[KSM_INT_STR_SIZE]; /* Enough to hold any integer */ StrAppend(sql, ", "); snprintf(buffer, KSM_INT_STR_SIZE, "%d", what); StrAppend(sql, buffer); return; }
static int WriteGregionRecord(struct gregionList *gr, FILE* ptr) { char buffer[80]; *buffer = '\0'; LngAppend(buffer, "%8d", 8, gr->element->grn); StrAppend(buffer, "%-40s", 40, gr->element->grname); StrAppend(buffer, "%-17s", 17, gr->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
void DisAppendString(char** sql, const char* what) { if (what) { StrAppend(sql, ", '"); StrAppend(sql, what); /* TODO make sure 'what' is safe to insert (quote quotes?) */ StrAppend(sql, "'"); } else { StrAppend(sql, ", NULL"); } return; }
char* DqsSpecifyInit(const char* table, const char* fields) { char* query; char* query1; query = StrStrdup("SELECT "); StrAppend(&query, fields); query1 = StrStrdup(" FROM "); StrAppend(&query, query1); StrAppend(&query, table); StrFree(query1); return query; }
void DqsConditionInt(char** query, const char* field, DQS_COMPARISON compare, int value, int index) { char stringval[KSM_INT_STR_SIZE]; /* For Integer to String conversion */ StrAppend(query, (index == 0) ? " WHERE " : " AND "); StrAppend(query, field); DqsAppendComparison(query, compare); snprintf(stringval, KSM_INT_STR_SIZE, "%d", value); StrAppend(query, stringval); return; }
char* DisSpecifyInit(const char* table, const char* cols) { char* sql; sql = StrStrdup("INSERT INTO "); StrAppend(&sql, table); StrAppend(&sql, " (id, "); StrAppend(&sql, cols); StrAppend(&sql, ")"); StrAppend(&sql, " VALUES (NULL"); return sql; }
static int WriteInstrumentRecord(struct instrumentList *in, FILE* ptr) { char buffer[250]; if(!CSSlngDefined(in->element->inid) ){ css_warning("Skipping instrument record because of missing key...\n"); return 1; } *buffer = '\0'; LngAppend(buffer, "%8d", 8, in->element->inid); StrAppend(buffer, "%-50s", 50, in->element->insname); StrAppend(buffer, "%-6s", 6, in->element->instype); StrAppend(buffer, "%-1s", 1, in->element->band); StrAppend(buffer, "%-1s", 1, in->element->digital); DblAppend(buffer, "%11.7f", 11, in->element->samprate); DblAppend(buffer, "%16.6f", 16, in->element->ncalib); DblAppend(buffer, "%16.6f", 16, in->element->ncalper); StrAppend(buffer, "%-64s", 64, in->element->dir); StrAppend(buffer, "%-32s", 32, in->element->dfile); StrAppend(buffer, "%-6s", 6, in->element->rsptype); StrAppend(buffer, "%-17s", 17, in->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
static int WriteRemarkRecord(struct remarkList *re, FILE* ptr) { char buffer[120]; *buffer = '\0'; LngAppend(buffer, "%8d", 8, re->element->commid); LngAppend(buffer, "%8d", 8, re->element->lineno); StrAppend(buffer, "%-80s", 80, re->element->remark); StrAppend(buffer, "%-17s", 17, re->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
/** Parses the configuration file. If the file does not exist this is ignored. */ void ConfigurationFileParser::Parse() { SCXCoreLib::SCXLogHandle log = SCXLogHandleFactory::GetLogHandle(L"scx.core.providers.runasprovider.configparser"); try { ParseStream(*SCXFile::OpenWFstream(m_file, std::ios_base::in)); } catch (SCXException& e) { SCX_LOGWARNING(log, StrAppend(L"Failed to read file: ", m_file.Get())); SCX_LOGWARNING(log, StrAppend(L"Reason for failure: ", e.What())); } }
static int WriteAffiliationRecord(struct affiliationList *af, FILE* ptr) { char buffer[50]; if(!CSSchrDefined(af->element->sta) || !CSSchrDefined(af->element->net) ){ css_warning("Skipping affiliation record because of null keys...\n"); return 1; } *buffer = '\0'; StrAppend(buffer, "%-8s", 8, af->element->net); StrAppend(buffer, "%-6s", 6, af->element->sta); StrAppend(buffer, "%-17s", 17, af->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
static int WriteWftagRecord(struct wftagList *wt, FILE* ptr) { char buffer[50]; *buffer = '\0'; StrAppend(buffer, "%-8s", 8, wt->element->tagname); LngAppend(buffer, "%8d", 8, wt->element->tagid); LngAppend(buffer, "%8d", 8, wt->element->wfid); StrAppend(buffer, "%-17s", 17, wt->element->lddate); if( fprintf(ptr, "%s\n", buffer) == EOF )return 0; return 1; }
/** Constructor */ OSInstance::OSInstance() : EntityInstance(true) { m_log = SCXLogHandleFactory::GetLogHandle(moduleIdentifier); SCX_LOGTRACE(m_log, L"OSInstance constructor"); // Do various initiation that can be done once and for all #if defined(linux) PrecomputeMaxProcesses(); #elif defined(sun) /* Nothing yet */ #elif defined(hpux) /* Get information the system static variables (guaranteed constant until reboot) */ m_psts_isValid = true; if (pstat_getstatic(&m_psts, sizeof(m_psts), 1, 0) < 0) { SCX_LOGERROR(m_log, StrAppend(L"Could not do pstat_getstatic(). errno = ", errno)); m_psts_isValid = false; } // Compute the boot time once and for all SetBootTime(); #elif defined(aix) /* Nothing yet */ #else #error "Not implemented for this platform." #endif }
STATIC_ROUTINE int Indent( int step, struct descriptor_d *pout) { newline.length = (unsigned short)(((TdiIndent += step) < 8 ? TdiIndent : 8) + 1); return StrAppend(pout, &newline); }
/** Gather the Major and Minor version from Product version Parameters: version - Product version, its format like 11.23.32, REV- or 0.4b41 */ void InstalledSoftwareInstance::SetDetailedVersion(const wstring& version) { size_t pos = version.find_first_of('.'); if( pos != wstring::npos ) { wstring left = version.substr(0, pos); wstring right = version.substr(pos+1); try { m_versionMajor = StrToUInt(left); // Exclude characters for(pos = 0; pos< right.size(); pos++) { if( right[pos] < '0' || right[pos] > '9' ) { break; } } if(pos > 0) { left = right.substr(0, pos); m_versionMinor = StrToUInt(left); } } catch (const SCXException& e) { SCX_LOGWARNING(m_log, StrAppend(L"parse InstalledSoftwareInstance version fails:", version).append(L" - ").append(e.What())); } } }
static void DqsAppendComparison(char** query, DQS_COMPARISON compare) { switch (compare) { case DQS_COMPARE_LT: StrAppend(query, " < "); break; case DQS_COMPARE_LE: StrAppend(query, " <= "); break; case DQS_COMPARE_EQ: StrAppend(query, " = "); break; case DQS_COMPARE_NE: StrAppend(query, " != "); break; case DQS_COMPARE_GE: StrAppend(query, " >= "); break; case DQS_COMPARE_GT: StrAppend(query, " > "); break; case DQS_COMPARE_IN: StrAppend(query, " IN "); break; case DQS_COMPARE_NOT_IN: StrAppend(query, " NOT IN "); break; case DQS_COMPARE_IS: StrAppend(query, " IS "); break; default: StrAppend(query, " ?? "); } return; }
char* DqsCountInit(const char* table) { char* query; query = StrStrdup("SELECT COUNT(*) FROM "); StrAppend(&query, table); return query; }
STATIC_ROUTINE int Append( char *pstr, struct descriptor_d *pd) { struct descriptor dstr = {0,DTYPE_T,CLASS_S,0}; dstr.length = (unsigned short)strlen(pstr); dstr.pointer = pstr; return StrAppend(pd, &dstr); }