本文整理汇总了C++中Jim_SetResultString函数的典型用法代码示例。如果您正苦于以下问题:C++ Jim_SetResultString函数的具体用法?C++ Jim_SetResultString怎么用?C++ Jim_SetResultString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Jim_SetResultString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Jim_PosixSignalCommand
static int Jim_PosixSignalCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int sig;
int signum;
sighandler_t lastaction;
sighandler_t nextaction = SIG_DFL;
const char *op;
int strlen = 0;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "signame ?action ...?");
return JIM_ERR;
}
if (Jim_GetEnum(interp, argv[1], signames, &sig, "Signal Names",
JIM_ERRMSG) != JIM_OK)
return JIM_ERR;
signum = signums[sig];
switch (argc) {
case 3:
if (op = Jim_GetString(argv[2], &strlen),strlen == 0) {
return JIM_ERR;
}
if (strcmp("default",op) == 0) {
nextaction = SIG_DFL;
} else if (strcmp("ignore",op) == 0) {
nextaction = SIG_IGN;
} else if (strcmp("debug",op) == 0) {
nextaction = Jim_Posix_SigHandler;
} else {
// this is the place to insert a script! UK
}
// fall through to query case:
case 2:
lastaction = signal(signum, nextaction);
if (argc==2)
signal(signum, lastaction);
if (lastaction == SIG_ERR) {
return JIM_ERR;
}
if (lastaction == SIG_DFL) {
Jim_SetResultString(interp, "default", -1);
return JIM_OK;
}
if (lastaction == SIG_IGN) {
Jim_SetResultString(interp, "ignore", -1);
return JIM_OK;
}
Jim_SetResultString(interp, "function", -1);
return JIM_OK;
}
return JIM_OK;
}
示例2: JimInterpCommand
/**
* [interp] creates a new interpreter.
*/
static int JimInterpCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Interp *child;
char buf[32];
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}
/* Create the interpreter command */
child = Jim_CreateInterp();
Jim_RegisterCoreCommands(child);
Jim_InitStaticExtensions(child);
/* Copy some core variables to the new interpreter */
JimInterpCopyVariable(child, interp, "argv", NULL);
JimInterpCopyVariable(child, interp, "argc", NULL);
JimInterpCopyVariable(child, interp, "argv0", NULL);
JimInterpCopyVariable(child, interp, "jim::argv0", NULL);
JimInterpCopyVariable(child, interp, "jim::exe", NULL);
/* Allow the child interpreter to find the parent */
Jim_SetAssocData(child, "interp.parent", NULL, interp);
snprintf(buf, sizeof(buf), "interp.handle%ld", Jim_GetId(interp));
Jim_CreateCommand(interp, buf, JimInterpSubCmdProc, child, JimInterpDelProc);
Jim_SetResultString(interp, buf, -1);
return JIM_OK;
}
示例3: GetAnimateWindowFlagsFromObj
static int
GetAnimateWindowFlagsFromObj(Jim_Interp *interp, Jim_Obj *listObj, DWORD *flags)
{
int r = JIM_OK, n, nLength;
*flags = 0;
Jim_ListLength(interp, listObj, &nLength);
if (r == JIM_OK) {
for (n = 0; n < nLength; n++) {
ANIMATEWINDOWFLAGSMAP *p;
Jim_Obj *obj;
r = Jim_ListIndex(interp, listObj, n, &obj, 1);
for (p = AnimateWindowFlagsMap; r == JIM_OK && p->s != NULL; p++) {
size_t len;
const char *name = Jim_GetString(obj, &len);
if (strncmp(p->s, name, len) == 0) {
*flags |= p->f;
break;
}
}
if (p->s == NULL) {
Jim_SetResultString(interp, "invalid option", -1);
return JIM_ERR;
}
}
}
return r;
}
示例4: Win32_GetLastInputInfo
static BOOL
Win32_GetLastInputInfo(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
{
struct lastinputinfo_t {
UINT cbSize;
DWORD dwTime;
} lii;
typedef BOOL (__stdcall *LPFNGETLASTINPUTINFO)(struct lastinputinfo_t *);
LPFNGETLASTINPUTINFO lpfnGetLastInputInfo = NULL;
HMODULE hLib = (HMODULE)Jim_CmdPrivData(interp);
JIM_NOTUSED(objc);
JIM_NOTUSED(objv);
if (hLib != NULL)
lpfnGetLastInputInfo = (LPFNGETLASTINPUTINFO)GetProcAddress(hLib, "GetLastInputInfo");
if (lpfnGetLastInputInfo == NULL) {
Jim_SetResultString(interp, "command not available on this platform", -1);
return JIM_ERR;
}
lii.cbSize = sizeof(lii);
if (!lpfnGetLastInputInfo(&lii)) {
Jim_SetResult(interp,
Win32ErrorObj(interp, "GetLastInputInfo", GetLastError()));
return JIM_ERR;
}
Jim_SetResult(interp, Jim_NewIntObj(interp, lii.dwTime));
return JIM_OK;
}
示例5: Jim_MakeTempFile
int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
{
char name[MAX_PATH];
HANDLE handle;
if (!GetTempPath(MAX_PATH, name) || !GetTempFileName(name, filename_template ? filename_template : "JIM", 0, name)) {
return -1;
}
handle = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | (unlink_file ? FILE_FLAG_DELETE_ON_CLOSE : 0),
NULL);
if (handle == INVALID_HANDLE_VALUE) {
goto error;
}
Jim_SetResultString(interp, name, -1);
return _open_osfhandle((int)handle, _O_RDWR | _O_TEXT);
error:
Jim_SetResultErrno(interp, name);
DeleteFile(name);
return -1;
}
示例6: clock_cmd_format
static int clock_cmd_format(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
/* How big is big enough? */
char buf[100];
time_t t;
long seconds;
const char *format = "%a %b %d %H:%M:%S %Z %Y";
if (argc == 2 || (argc == 3 && !Jim_CompareStringImmediate(interp, argv[1], "-format"))) {
return -1;
}
if (argc == 3) {
format = Jim_String(argv[2]);
}
if (Jim_GetLong(interp, argv[0], &seconds) != JIM_OK) {
return JIM_ERR;
}
t = seconds;
/*@@if (strftime(buf, sizeof(buf), format, localtime(&t)) == 0) {
Jim_SetResultString(interp, "format string too long", -1);
return JIM_ERR;
}*/
Jim_SetResultString(interp, buf, -1);
return JIM_OK;
}
示例7: array_cmd_set
static int array_cmd_set(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i;
int len;
Jim_Obj *listObj = argv[1];
Jim_Obj *dictObj;
len = Jim_ListLength(interp, listObj);
if (len % 2) {
Jim_SetResultString(interp, "list must have an even number of elements", -1);
return JIM_ERR;
}
dictObj = Jim_GetVariable(interp, argv[0], JIM_UNSHARED);
if (!dictObj) {
/* Doesn't exist, so just set the list directly */
return Jim_SetVariable(interp, argv[0], listObj);
}
if (Jim_IsShared(dictObj)) {
dictObj = Jim_DuplicateObj(interp, dictObj);
}
for (i = 0; i < len; i += 2) {
Jim_Obj *nameObj;
Jim_Obj *valueObj;
Jim_ListIndex(interp, listObj, i, &nameObj, JIM_NONE);
Jim_ListIndex(interp, listObj, i + 1, &valueObj, JIM_NONE);
Jim_DictAddElement(interp, dictObj, nameObj, valueObj);
}
return Jim_SetVariable(interp, argv[0], dictObj);
}
示例8: signal_cmd_throw
static int signal_cmd_throw(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int sig = SIGINT;
if (argc == 1) {
if ((sig = find_signal_by_name(interp, Jim_String(argv[0]))) < 0) {
return JIM_ERR;
}
}
/* If the signal is ignored (blocked) ... */
if (siginfo[sig].status == SIGNAL_ACTION_IGNORE) {
sigsblocked |= sig_to_bit(sig);
return JIM_OK;
}
/* Just set the signal */
interp->sigmask |= sig_to_bit(sig);
/* Set the canonical name of the signal as the result */
Jim_SetResultString(interp, Jim_SignalId(sig), -1);
/* And simply say we caught the signal */
return JIM_SIGNAL;
}
示例9: find_signal_by_name
/**
* Given the name of a signal, returns the signal value if found,
* or returns -1 (and sets an error) if not found.
* We accept -SIGINT, SIGINT, INT or any lowercase version or a number,
* either positive or negative.
*/
static int find_signal_by_name(Jim_Interp *interp, const char *name)
{
int i;
const char *pt = name;
/* Remove optional - and SIG from the front of the name */
if (*pt == '-') {
pt++;
}
if (strncasecmp(name, "sig", 3) == 0) {
pt += 3;
}
if (isdigit(UCHAR(pt[0]))) {
i = atoi(pt);
if (i > 0 && i < MAX_SIGNALS) {
return i;
}
}
else {
for (i = 1; i < MAX_SIGNALS; i++) {
/* Jim_SignalId() returns names such as SIGINT, and
* returns "unknown signal id" if unknown, so this will work
*/
if (strcasecmp(Jim_SignalId(i) + 3, pt) == 0) {
return i;
}
}
}
Jim_SetResultString(interp, "unknown signal ", -1);
Jim_AppendString(interp, Jim_GetResult(interp), name, -1);
return -1;
}
示例10: JimMakeChannel
/**
* Creates a channel for fh/fd/filename.
*
* If fh is not NULL, uses that as the channel (and set AIO_KEEPOPEN).
* Otherwise, if fd is >= 0, uses that as the chanel.
* Otherwise opens 'filename' with mode 'mode'.
*
* hdlfmt is a sprintf format for the filehandle. Anything with %ld at the end will do.
* mode is used for open or fdopen.
*
* Creates the command and sets the name as the current result.
*/
static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode)
{
AioFile *af;
char buf[AIO_CMD_LEN];
int OpenFlags = 0;
if (filename == NULL) {
filename = Jim_NewStringObj(interp, hdlfmt, -1);
}
Jim_IncrRefCount(filename);
if (fh == NULL) {
if (fd < 0) {
fh = fopen(Jim_String(filename), mode);
}
else {
fh = fdopen(fd, mode);
}
}
else {
OpenFlags = AIO_KEEPOPEN;
}
if (fh == NULL) {
JimAioSetError(interp, filename);
#if !defined(JIM_ANSIC)
if (fd >= 0) {
close(fd);
}
#endif
Jim_DecrRefCount(interp, filename);
return JIM_ERR;
}
/* Create the file command */
af = Jim_Alloc(sizeof(*af));
memset(af, 0, sizeof(*af));
af->fp = fh;
af->fd = fileno(fh);
af->filename = filename;
#ifdef FD_CLOEXEC
if ((OpenFlags & AIO_KEEPOPEN) == 0) {
fcntl(af->fd, F_SETFD, FD_CLOEXEC);
}
#endif
af->OpenFlags = OpenFlags;
#ifdef O_NDELAY
af->flags = fcntl(af->fd, F_GETFL);
#endif
af->addr_family = family;
snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
Jim_SetResultString(interp, buf, -1);
return JIM_OK;
}
示例11: Jim_Alloc
/* Add this handle to the stack of handles to be freed */
if (!interp->loadHandles) {
interp->loadHandles = Jim_Alloc(sizeof(*interp->loadHandles));
Jim_InitStack(interp->loadHandles);
}
Jim_StackPush(interp->loadHandles, handle);
Jim_SetEmptyResult(interp);
return JIM_OK;
}
}
if (handle) {
dlclose(handle);
}
return JIM_ERR;
}
static void JimFreeOneLoadHandle(void *handle)
{
dlclose(handle);
}
void Jim_FreeLoadHandles(Jim_Interp *interp)
{
if (interp->loadHandles) {
Jim_FreeStackElements(interp->loadHandles, JimFreeOneLoadHandle);
Jim_Free(interp->loadHandles);
}
}
#else /* JIM_DYNLIB */
int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName)
{
JIM_NOTUSED(interp);
JIM_NOTUSED(pathName);
Jim_SetResultString(interp, "the Jim binary has no support for [load]", -1);
return JIM_ERR;
}
示例12: Jim_Decompress
static int Jim_Decompress(Jim_Interp *interp, const char *in, int len, long bufsiz, int wbits)
{
z_stream strm = {0};
void *buf;
Jim_Obj *out;
int ret;
if (JimZlibCheckBufSize(interp, bufsiz)) {
return JIM_ERR;
}
if (inflateInit2(&strm, wbits) != Z_OK) {
return JIM_ERR;
}
/* allocate a buffer - decompression is done in chunks, into this buffer;
* when the decompressed data size is given, decompression is faster because
* it's done in one pass, with less memcpy() overhead */
buf = Jim_Alloc((int)bufsiz);
out = Jim_NewEmptyStringObj(interp);
Jim_IncrRefCount(out);
strm.next_in = (Bytef*)in;
strm.avail_in = (uInt)len;
do {
do {
strm.next_out = buf;
strm.avail_out = (uInt)bufsiz;
ret = inflate(&strm, Z_NO_FLUSH);
switch (ret) {
case Z_OK:
case Z_STREAM_END:
/* append each chunk to the output object */
Jim_AppendString(interp, out, buf, (int)(bufsiz - (long)strm.avail_out));
break;
default:
Jim_DecrRefCount(interp, out);
Jim_Free(buf);
inflateEnd(&strm);
if (strm.msg != NULL)
Jim_SetResultString(interp, strm.msg, -1);
return JIM_ERR;
}
} while (strm.avail_out == 0);
} while (ret != Z_STREAM_END);
/* free memory used for decompression before we assign the return value */
Jim_Free(buf);
inflateEnd(&strm);
Jim_SetResult(interp, out);
Jim_DecrRefCount(interp, out);
return JIM_OK;
}
示例13: Jim_ReaddirCmd
/*
*-----------------------------------------------------------------------------
*
* Jim_ReaddirCmd --
* Implements the rename TCL command:
* readdir ?-nocomplain? dirPath
*
* Results:
* Standard TCL result.
*-----------------------------------------------------------------------------
*/
int
Jim_ReaddirCmd (Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *dirPath;
DIR *dirPtr;
struct dirent *entryPtr;
int nocomplain = 0;
if (argc == 3 && Jim_CompareStringImmediate(interp, argv[1], "-nocomplain")) {
nocomplain = 1;
}
if (argc != 2 && !nocomplain) {
Jim_WrongNumArgs(interp, 1, argv, "?-nocomplain? dirPath");
return JIM_ERR;
}
dirPath = Jim_GetString(argv[1 + nocomplain], NULL);
dirPtr = opendir (dirPath);
if (dirPtr == NULL) {
if (nocomplain) {
return JIM_OK;
}
Jim_SetResultString(interp, strerror(errno), -1);
return JIM_ERR;
}
Jim_SetResultString(interp, strerror(errno), -1);
Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0));
while ((entryPtr = readdir (dirPtr)) != NULL) {
if (entryPtr->d_name [0] == '.') {
if (entryPtr->d_name [1] == '\0') {
continue;
}
if ((entryPtr->d_name [1] == '.') &&
(entryPtr->d_name [2] == '\0'))
continue;
}
Jim_ListAppendElement(interp, Jim_GetResult(interp), Jim_NewStringObj(interp, entryPtr->d_name, -1));
}
closedir (dirPtr);
return JIM_OK;
}
示例14: JimTrimTrailingNewline
/*
* If the last character of the result is a newline, then remove
* the newline character (the newline would just confuse things).
*
* Note: Ideally we could do this by just reducing the length of stringrep
* by 1, but there is no API for this :-(
*/
static void JimTrimTrailingNewline(Jim_Interp *interp)
{
int len;
const char *p = Jim_GetString(Jim_GetResult(interp), &len);
if (len > 0 && p[len - 1] == '\n') {
Jim_SetResultString(interp, p, len - 1);
}
}
示例15: JimAioSetError
static void JimAioSetError(Jim_Interp *interp, Jim_Obj *name)
{
if (name) {
Jim_SetResultFormatted(interp, "%#s: %s", name, strerror(errno));
}
else {
Jim_SetResultString(interp, strerror(errno), -1);
}
}