static int Win32_GetCursorInfo(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { Jim_Obj *a[8]; size_t n = 0; CURSORINFO ci; JIM_NOTUSED(objc); JIM_NOTUSED(objv); ci.cbSize = sizeof(ci); if (!GetCursorInfo(&ci)) { Jim_SetResult(interp, Win32ErrorObj(interp, "GetCursorInfo", GetLastError())); return JIM_ERR; } #define JIMADDN(name) a[n++] = Jim_NewStringObj(interp, #name, -1); #define JIMADDV(v) a[n++] = Jim_NewIntObj(interp, (v)); JIMADDN(flags); JIMADDV(ci.flags); JIMADDN(hCursor); JIMADDV((DWORD)ci.hCursor); JIMADDN(x); JIMADDV(ci.ptScreenPos.x); JIMADDN(y); JIMADDV(ci.ptScreenPos.y); #undef JIMADDN #undef JIMADDV Jim_SetResult(interp, Jim_NewListObj(interp, a, n)); return JIM_OK; }
static int Win32_LoadCursor(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { HCURSOR hCursor; int ndx; static const char *name[] = { "appstarting", "arrow", "cross", "hand", "help", "ibeam", "icon", "no", "size", "sizeall", "sizenesw", "sizens", "sizenwse", "sizewe", "uparrow", "wait", NULL }; static LPCTSTR id[] = { IDC_APPSTARTING, IDC_ARROW, IDC_CROSS, IDC_HAND, IDC_HELP, IDC_IBEAM, IDC_ICON, IDC_NO, IDC_SIZEALL, IDC_SIZEALL, IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_UPARROW, IDC_WAIT, NULL }; if (objc != 2) { Jim_WrongNumArgs(interp, 1, objv, "name"); return JIM_ERR; } if (Jim_GetEnum(interp, objv[1], name, &ndx, "cursor name", JIM_ERRMSG) != JIM_OK) return JIM_ERR; hCursor = LoadCursor((HINSTANCE)NULL, id[ndx]); if (hCursor == NULL) { Jim_SetResult(interp, Win32ErrorObj(interp, "LoadCursor", GetLastError())); return JIM_ERR; } Jim_SetResult(interp, Jim_NewIntObj(interp, (DWORD)hCursor)); return JIM_OK; }
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; }
/* win32.FindWindow title ?class? */ static int Win32_FindWindow(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { const char *title = NULL, *class = NULL; HWND hwnd = NULL; int r = JIM_OK; if (objc < 2 || objc > 3) { Jim_WrongNumArgs(interp, 1, objv, "title ?class?"); return JIM_ERR; } title = Jim_String(objv[1]); if (objc == 3) class = Jim_String(objv[2]); hwnd = FindWindowA(class, title); if (hwnd == NULL) { Jim_SetResult(interp, Win32ErrorObj(interp, "FindWindow", GetLastError())); r = JIM_ERR; } else { Jim_SetResult(interp, Jim_NewIntObj(interp, (long)hwnd)); } return r; }
// FIX ME: win2k+ so should do version checks really. static int Win32_GetPerformanceInfo(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { Jim_Obj *a[26]; size_t n = 0; PERFORMANCE_INFORMATION pi; if (!GetPerformanceInfo(&pi, sizeof(pi))) { Jim_SetResult(interp, Win32ErrorObj(interp, "GetPerformanceInfo", GetLastError())); return JIM_ERR; } #define JIMADD(name) \ a[n++] = Jim_NewStringObj(interp, #name, -1); \ a[n++] = Jim_NewIntObj(interp, pi. name ) JIMADD(CommitTotal); JIMADD(CommitLimit); JIMADD(CommitPeak); JIMADD(PhysicalTotal); JIMADD(PhysicalAvailable); JIMADD(SystemCache); JIMADD(KernelTotal); JIMADD(KernelPaged); JIMADD(KernelNonpaged); JIMADD(PageSize); JIMADD(HandleCount); JIMADD(ProcessCount); JIMADD(ThreadCount); #undef JIMADD Jim_SetResult(interp, Jim_NewListObj(interp, a, n)); return JIM_OK; }
static int Win32_GetModuleFileName(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { HMODULE hModule = NULL; char path[MAX_PATH]; DWORD len = 0; if (objc > 2) { Jim_WrongNumArgs(interp, 1, objv, "?moduleid?"); return JIM_ERR; } if (objc == 2) { if (Jim_GetLong(interp, objv[1], (long *)&hModule) != JIM_OK) { return JIM_ERR; } } len = GetModuleFileNameA(hModule, path, MAX_PATH); if (len != 0) { Jim_Obj *pathObj = Jim_NewStringObj(interp, path, len); Jim_SetResult(interp, pathObj); } else { Jim_SetResult(interp, Win32ErrorObj(interp, "GetModuleFileName", GetLastError())); return JIM_ERR; } return JIM_OK; }
static int JimELAfterCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { jim_wide ms, id; Jim_Obj *objPtr, *idObjPtr; const char *options[] = { "info", "cancel", "restart", "expire", NULL }; enum {INFO, CANCEL, RESTART, EXPIRE, CREATE }; int option = CREATE ; if (argc < 3) { Jim_WrongNumArgs(interp, 1, argv, "<after milliseconds> script"); return JIM_ERR; } if (Jim_GetWide(interp, argv[1], &ms) != JIM_OK) if (Jim_GetEnum(interp, argv[1], options, &option, "after options", JIM_ERRMSG) != JIM_OK) return JIM_ERR; switch (option) { case CREATE: Jim_IncrRefCount(argv[2]); id = Jim_CreateTimeHandler(interp, ms, JimAfterTimeHandler, argv[2], JimAfterTimeEventFinalizer); objPtr = Jim_NewStringObj(interp, NULL, 0); Jim_AppendString(interp, objPtr, "after#", -1); idObjPtr = Jim_NewIntObj(interp, id); Jim_IncrRefCount(idObjPtr); Jim_AppendObj(interp, objPtr, idObjPtr); Jim_DecrRefCount(interp, idObjPtr); Jim_SetResult(interp, objPtr); return JIM_OK; case CANCEL: { int tlen ; jim_wide remain = 0; const char *tok = Jim_GetString(argv[2], &tlen); if ( sscanf(tok,"after#%lld",&id) == 1) { remain = Jim_DeleteTimeHandler(interp, id); if (remain > -2) { Jim_SetResult(interp, Jim_NewIntObj(interp, remain)); return JIM_OK; } } Jim_SetResultString(interp, "invalid event" , -1); return JIM_ERR; } default: fprintf(stderr,"unserviced option to after %d\n",option); } return JIM_OK; }
static int Win32_GetPerformanceInfo(Jim_Interp *interp, int objc, Jim_Obj *const *objv) { Jim_Obj *a[26]; size_t n = 0; PERFORMANCE_INFORMATION pi; LPFNGETPERFORMANCEINFO lpfnGetPerformanceInfo = NULL; HMODULE hLib = (HMODULE)Jim_CmdPrivData(interp); JIM_NOTUSED(objc); JIM_NOTUSED(objv); if (hLib != NULL) lpfnGetPerformanceInfo = (LPFNGETPERFORMANCEINFO)GetProcAddress(hLib, "GetPerformanceInfo"); if (lpfnGetPerformanceInfo == NULL) { /* should never happen */ Jim_SetResultString(interp, "argh!", -1); return JIM_ERR; } pi.cb = sizeof(pi); if (!lpfnGetPerformanceInfo(&pi, sizeof(pi))) { Jim_SetResult(interp, Win32ErrorObj(interp, "GetPerformanceInfo", GetLastError())); return JIM_ERR; } #define JIMADD(name) \ a[n++] = Jim_NewStringObj(interp, #name, -1); \ a[n++] = Jim_NewIntObj(interp, pi.name ) JIMADD(CommitTotal); JIMADD(CommitLimit); JIMADD(CommitPeak); JIMADD(PhysicalTotal); JIMADD(PhysicalAvailable); JIMADD(SystemCache); JIMADD(KernelTotal); JIMADD(KernelPaged); JIMADD(KernelNonpaged); JIMADD(PageSize); JIMADD(HandleCount); JIMADD(ProcessCount); JIMADD(ThreadCount); #undef JIMADD Jim_SetResult(interp, Jim_NewListObj(interp, a, n)); return JIM_OK; }
static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask, Jim_Obj **scriptHandlerObj, int argc, Jim_Obj * const *argv) { int scriptlen = 0; if (argc == 0) { /* Return current script */ if (*scriptHandlerObj) { Jim_SetResult(interp, *scriptHandlerObj); } return JIM_OK; } if (*scriptHandlerObj) { /* Delete old handler */ Jim_DeleteFileHandler(interp, af->fp); *scriptHandlerObj = NULL; } /* Now possibly add the new script(s) */ Jim_GetString(argv[0], &scriptlen); if (scriptlen == 0) { /* Empty script, so done */ return JIM_OK; } /* A new script to add */ Jim_IncrRefCount(argv[0]); *scriptHandlerObj = argv[0]; Jim_CreateFileHandler(interp, af->fp, mask, JimAioFileEventHandler, *scriptHandlerObj, JimAioFileEventFinalizer); return JIM_OK; }
static int ioutil_Jim_Command_ls(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { if (argc != 2) { Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?"); return JIM_ERR; } const char *name = Jim_GetString(argv[1], NULL); DIR *dirp = NULL; dirp = opendir(name); if (dirp == NULL) return JIM_ERR; Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0); for (;; ) { struct dirent *entry = NULL; entry = readdir(dirp); if (entry == NULL) break; if ((strcmp(".", entry->d_name) == 0) || (strcmp("..", entry->d_name) == 0)) continue; Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, entry->d_name, strlen(entry->d_name))); } closedir(dirp); Jim_SetResult(interp, objPtr); return JIM_OK; }
static int array_cmd_get(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { Jim_Obj *objPtr = Jim_GetVariable(interp, argv[0], JIM_NONE); if (!objPtr) { return JIM_OK; } if (argc == 1 || Jim_CompareStringImmediate(interp, argv[1], "*")) { /* Optimise the "all" case */ if (Jim_IsList(objPtr)) { if (Jim_ListLength(interp, objPtr) % 2 != 0) { /* A list with an odd number of elements */ return JIM_ERR; } } else if (Jim_DictSize(interp, objPtr) < 0) { /* Can't be converted to a dictionary */ return JIM_ERR; } Jim_SetResult(interp, objPtr); return JIM_OK; } /* Return a list of keys and values where the keys match the pattern */ return Jim_DictValues(interp, objPtr, argv[1]); }
static int Win32_AnimateWindow(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { HWND hwnd; DWORD dwTime = 0, dwFlags = 0; struct map_t { const char* s; DWORD f; }; if (objc != 4) { Jim_WrongNumArgs(interp, 1, objv, "windowhandle time flags"); return JIM_ERR; } if (Jim_GetLong(interp, objv[1], (long *)&hwnd) != JIM_OK) return JIM_ERR; if (Jim_GetLong(interp, objv[2], &dwTime) != JIM_OK) return JIM_ERR; if (GetAnimateWindowFlagsFromObj(interp, objv[3], &dwFlags) != JIM_OK) return JIM_ERR; if (!AnimateWindow(hwnd, dwTime, dwFlags)) { DWORD err = GetLastError(); Jim_Obj *errObj; if (err == ERROR_SUCCESS) errObj = Jim_NewStringObj(interp, "error: " " calling thread does not own the window", -1); else errObj = Win32ErrorObj(interp, "AnimateWindow", err); Jim_SetResult(interp, errObj); return JIM_ERR; } return JIM_OK; }
static int Win32_ShowWindow(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { HWND hwnd; int cmd; const char *cmds[] = { "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_MAXIMIZE", "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE", "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE", NULL }; if (objc != 3) { Jim_WrongNumArgs(interp, 1, objv, "windowhandle option"); return JIM_ERR; } if (Jim_GetLong(interp, objv[1], (long *)&hwnd) != JIM_OK) return JIM_ERR; if (Jim_GetEnum(interp, objv[2], cmds, &cmd, "command", JIM_ERRMSG) != JIM_OK) return JIM_ERR; if (!ShowWindow(hwnd, cmd)) { Jim_SetResult(interp, Win32ErrorObj(interp, "ShowWindow", GetLastError())); return JIM_ERR; } return JIM_OK; }
static int Win32_GetSystemTime(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { Jim_Obj *a[16]; size_t n = 0; SYSTEMTIME t; GetSystemTime(&t); #define JIMADD(name) \ a[n++] = Jim_NewStringObj(interp, #name, -1); \ a[n++] = Jim_NewIntObj(interp, t.w ## name ) JIMADD(Year); JIMADD(Month); JIMADD(DayOfWeek); JIMADD(Day); JIMADD(Hour); JIMADD(Minute); JIMADD(Second); JIMADD(Milliseconds); #undef JIMADD Jim_SetResult(interp, Jim_NewListObj(interp, a, n)); return JIM_OK; }
static int aio_cmd_filename(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { AioFile *af = Jim_CmdPrivData(interp); Jim_SetResult(interp, af->filename); return JIM_OK; }
static int history_cmd_getline(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { Jim_Obj *objPtr; char *line = Jim_HistoryGetline(interp, Jim_String(argv[0])); /* On EOF returns -1 if varName was specified; otherwise the empty string. */ if (line == NULL) { if (argc == 2) { Jim_SetResultInt(interp, -1); } return JIM_OK; } objPtr = Jim_NewStringObjNoAlloc(interp, line, -1); /* Returns the length of the string if varName was specified */ if (argc == 2) { if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) { Jim_FreeNewObj(interp, objPtr); return JIM_ERR; } Jim_SetResultInt(interp, Jim_Length(objPtr)); } else { Jim_SetResult(interp, objPtr); } return JIM_OK; }
static int Win32_LoadLibrary(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { HMODULE hLib = NULL; if (objc != 2) { Jim_WrongNumArgs(interp, 1, objv, "path"); return JIM_ERR; } hLib = LoadLibraryA(Jim_String(objv[1])); if (hLib == NULL) { Jim_SetResult(interp, Win32ErrorObj(interp, "LoadLibrary", GetLastError())); return JIM_ERR; } Jim_SetResult(interp, Jim_NewIntObj(interp, (unsigned long)hLib)); return JIM_OK; }
static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args) { script_debug(interp, "flush_count", argc, args); Jim_SetResult(interp, Jim_NewIntObj(interp, jtag_get_flush_queue_count())); return JIM_OK; }
static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc, Jim_Obj *const *argv) { Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "Usage: \"", Jim_String(argv[0]), " command ... \", where command is one of: ", NULL); add_commands(interp, command_table, ", "); }
static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type, Jim_Obj *cmd, Jim_Obj *subcmd) { Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), Jim_String(cmd), ", ", type, " command \"", Jim_String(subcmd), "\": should be ", NULL); add_commands(interp, command_table, ", "); }
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; }
static int Win32_GetActiveWindow(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { JIM_NOTUSED(objc); JIM_NOTUSED(objv); Jim_SetResult(interp, Jim_NewIntObj(interp, (DWORD)GetActiveWindow())); return JIM_OK; }
static int Win32_GetTickCount(Jim_Interp *interp, int objc, Jim_Obj *const *objv) { JIM_NOTUSED(objc); JIM_NOTUSED(objv); Jim_SetResult(interp, Jim_NewIntObj(interp, GetTickCount())); return JIM_OK; }
static int Win32_GetCursorPos(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { Jim_Obj *a[2]; POINT pt; JIM_NOTUSED(objc); JIM_NOTUSED(objv); if (!GetCursorPos(&pt)) { Jim_SetResult(interp, Win32ErrorObj(interp, "GetCursorPos", GetLastError())); return JIM_ERR; } a[0] = Jim_NewIntObj(interp, pt.x); a[1] = Jim_NewIntObj(interp, pt.y); Jim_SetResult(interp, Jim_NewListObj(interp, a, 2)); return JIM_OK; }
/* not so pretty code to fish out eth0 mac address */ static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { struct ifreq *ifr, *ifend; struct ifreq ifreq; struct ifconf ifc; struct ifreq ifs[5]; int SockFD; SockFD = socket(AF_INET, SOCK_DGRAM, 0); if (SockFD < 0) return JIM_ERR; ifc.ifc_len = sizeof(ifs); ifc.ifc_req = ifs; if (ioctl(SockFD, SIOCGIFCONF, &ifc) < 0) { close(SockFD); return JIM_ERR; } ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq)); for (ifr = ifc.ifc_req; ifr < ifend; ifr++) { /* if (ifr->ifr_addr.sa_family == AF_INET) */ { if (strcmp("eth0", ifr->ifr_name) != 0) continue; strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0) { close(SockFD); return JIM_ERR; } close(SockFD); Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); char buffer[256]; sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x", ifreq.ifr_hwaddr.sa_data[0]&0xff, ifreq.ifr_hwaddr.sa_data[1]&0xff, ifreq.ifr_hwaddr.sa_data[2]&0xff, ifreq.ifr_hwaddr.sa_data[3]&0xff, ifreq.ifr_hwaddr.sa_data[4]&0xff, ifreq.ifr_hwaddr.sa_data[5]&0xff); Jim_AppendString(interp, tclOutput, buffer, strlen(buffer)); Jim_SetResult(interp, tclOutput); return JIM_OK; } } close(SockFD); return JIM_ERR; }
/* * Our function. */ static int CountCharsFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { if (argc != 2) { Jim_WrongNumArgs(interp, 1, argv, "string"); return (JIM_ERR); } Jim_SetResult(interp, Jim_NewIntObj(interp, Jim_Length(argv[1]))); return (JIM_OK); }
static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { AioFile *af = Jim_CmdPrivData(interp); char buf[AIO_BUF_LEN]; Jim_Obj *objPtr; int len; errno = 0; objPtr = Jim_NewStringObj(interp, NULL, 0); while (1) { buf[AIO_BUF_LEN - 1] = '_'; if (fgets(buf, AIO_BUF_LEN, af->fp) == NULL) break; if (buf[AIO_BUF_LEN - 1] == '\0' && buf[AIO_BUF_LEN - 2] != '\n') { Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN - 1); } else { len = strlen(buf); if (len && (buf[len - 1] == '\n')) { /* strip "\n" */ len--; } Jim_AppendString(interp, objPtr, buf, len); break; } } if (JimCheckStreamError(interp, af)) { /* I/O error */ Jim_FreeNewObj(interp, objPtr); return JIM_ERR; } if (argc) { if (Jim_SetVariable(interp, argv[0], objPtr) != JIM_OK) { Jim_FreeNewObj(interp, objPtr); return JIM_ERR; } len = Jim_Length(objPtr); if (len == 0 && feof(af->fp)) { /* On EOF returns -1 if varName was specified */ len = -1; } Jim_SetResultInt(interp, len); } else { Jim_SetResult(interp, objPtr); } return JIM_OK; }
/* * os.wait ?-nohang? pid * * An interface to waitpid(2) * * Returns a 3 element list. * * If -nohang is specified, and the process is still alive, returns * * {0 none 0} * * If the process does not exist or has already been waited for, returns: * * {-1 error <error-description>} * * If the process exited normally, returns: * * {<pid> exit <exit-status>} * * If the process terminated on a signal, returns: * * {<pid> signal <signal-number>} * * Otherwise (core dump, stopped, continued, ...), returns: * * {<pid> other 0} */ static int Jim_PosixWaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { int nohang = 0; long pid; int status; Jim_Obj *listObj; const char *type; int value; if (argc > 1 && Jim_CompareStringImmediate(interp, argv[1], "-nohang")) { nohang = 1; } if (argc != nohang + 2) { Jim_WrongNumArgs(interp, 1, argv, "?-nohang? pid"); return JIM_ERR; } if (Jim_GetLong(interp, argv[nohang + 1], &pid) != JIM_OK) { return JIM_ERR; } pid = waitpid(pid, &status, nohang ? WNOHANG : 0); listObj = Jim_NewListObj(interp, NULL, 0); Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, pid)); if (pid < 0) { type = "error"; value = errno; } else if (pid == 0) { type = "none"; value = 0; } else if (WIFEXITED(status)) { type = "exit"; value = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { type = "signal"; value = WTERMSIG(status); } else { type = "other"; value = 0; } Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, type, -1)); if (pid < 0) { Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, strerror(value), -1)); } else { Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, value)); } Jim_SetResult(interp, listObj); return JIM_OK; }
static int Win32_GetCursor(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { HCURSOR hCursor; JIM_NOTUSED(objc); JIM_NOTUSED(objv); hCursor = GetCursor(); Jim_SetResult(interp, Jim_NewIntObj(interp, (DWORD)hCursor)); return JIM_OK; }
static int Win32_CreateWindow(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { int r = JIM_ERR; HWND hwnd, hwndParent = HWND_DESKTOP; DWORD style = WS_VISIBLE | WS_OVERLAPPEDWINDOW; UINT id = 0; const char *class, *title; if (objc < 3 || objc > 5) { Jim_WrongNumArgs(interp, 1, objv, "class title ?parent? ?id?"); return JIM_ERR; } class = Jim_GetString(objv[1], NULL); title = Jim_GetString(objv[2], NULL); if (objc == 4) { if (Jim_GetLong(interp, objv[3], (long *)&hwndParent) != JIM_OK) return JIM_ERR; style = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; } if (objc == 5) { if (Jim_GetLong(interp, objv[4], (long *)&id) != JIM_OK) return JIM_ERR; } hwnd = CreateWindowA(class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndParent, (HMENU)id, g_hInstance, NULL); if (hwnd) { SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)interp); Jim_SetResult(interp, Jim_NewIntObj(interp, (DWORD)hwnd)); r = JIM_OK; } else { Jim_SetResult(interp, Win32ErrorObj(interp, "CreateWindow", GetLastError())); r = JIM_ERR; } return r; }