void interpretCmdLine(const char *textbuf, int textlen, char *methodname) { PyrString *string; if (compiledOK) { PyrSlot slot; string = newPyrStringN(gMainVMGlobals->gc, textlen, 0, false); memcpy(string->s, textbuf, textlen); SetObject(&slotRawInterpreter(&gMainVMGlobals->process->interpreter)->cmdLine, string); gMainVMGlobals->gc->GCWrite(slotRawObject(&gMainVMGlobals->process->interpreter), string); SetObject(&slot, gMainVMGlobals->process); //#if __profile__ // ProfilerInit(collectSummary, microsecondsTimeBase, 500, 100); //#endif slotCopy((++gMainVMGlobals->sp), &slot); runInterpreter(gMainVMGlobals, getsym(methodname), 1); //#if __profile__ // ProfilerDump("\pErase2.prof"); // ProfilerTerm(); //#endif } else { postfl("Library has not been compiled successfully.\n"); } }
int prAscTime(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; PyrSlot *slots = a->uo->slots; if (IsNil(slots + 0)) { SetNil(a); return errNone; } struct tm tm0; if (slotIntVal(slots+0, &tm0.tm_year)) return errWrongType; tm0.tm_year -= 1900; if (slotIntVal(slots+1, &tm0.tm_mon)) return errWrongType; tm0.tm_mon -- ; if (slotIntVal(slots+2, &tm0.tm_mday)) return errWrongType; if (slotIntVal(slots+3, &tm0.tm_hour)) return errWrongType; if (slotIntVal(slots+4, &tm0.tm_min)) return errWrongType; if (slotIntVal(slots+5, &tm0.tm_sec)) return errWrongType; if (slotIntVal(slots+6, &tm0.tm_wday)) return errWrongType; const char *text = asctime(&tm0); int size = strlen(text) - 1; // Discard trailing newline PyrString *strobj = newPyrStringN(g->gc, size, 0, true); memcpy(strobj->s, text, size); SetObject(a, strobj); return errNone; }
void SC_LanguageClient::setCmdLine(const char* buf, size_t size) { if (isLibraryCompiled()) { lock(); if (isLibraryCompiled()) { VMGlobals *g = gMainVMGlobals; PyrString* strobj = newPyrStringN(g->gc, size, 0, true); memcpy(strobj->s, buf, size); SetObject(&slotRawInterpreter(&g->process->interpreter)->cmdLine, strobj); g->gc->GCWriteNew(slotRawObject(&g->process->interpreter), strobj); // we know strobj is white so we can use GCWriteNew } unlock(); } }
int prString_Dirname(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; char path[PATH_MAX]; int err = slotStrVal(a, path, PATH_MAX); if (err) return err; char *dirname0 = dirname(path); int size = strlen(dirname0); PyrString *strobj = newPyrStringN(g->gc, size, 0, true); memcpy(strobj->s, dirname0, size); SetObject(a, strobj); return errNone; }
int prStrFTime(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 1; PyrSlot *b = g->sp; PyrSlot *slots = a->uo->slots; if (IsNil(slots + 0)) { SetNil(a); return errNone; } struct tm tm0; if (slotIntVal(slots+0, &tm0.tm_year)) return errWrongType; tm0.tm_year -= 1900; if (slotIntVal(slots+1, &tm0.tm_mon)) return errWrongType; tm0.tm_mon --; if (slotIntVal(slots+2, &tm0.tm_mday)) return errWrongType; if (slotIntVal(slots+3, &tm0.tm_hour)) return errWrongType; if (slotIntVal(slots+4, &tm0.tm_min)) return errWrongType; if (slotIntVal(slots+5, &tm0.tm_sec)) return errWrongType; if (slotIntVal(slots+6, &tm0.tm_wday)) return errWrongType; char format[1024]; if (slotStrVal(b, format, 1024)) return errWrongType; char buffer[1024]; if (strftime(buffer, 1024, format, &tm0) != 0) { int size = strlen(buffer); PyrString *strobj = newPyrStringN(g->gc, size, 0, true); memcpy(strobj->s, buffer, size); SetObject(a, strobj); } else { error("could not convert the date to string with the give format"); return errFailed; } return errNone; }