本文整理汇总了C++中Jim_NewStringObj函数的典型用法代码示例。如果您正苦于以下问题:C++ Jim_NewStringObj函数的具体用法?C++ Jim_NewStringObj怎么用?C++ Jim_NewStringObj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Jim_NewStringObj函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JimAioOpenCommand
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *mode;
const char *filename;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
return JIM_ERR;
}
mode = (argc == 3) ? Jim_String(argv[2]) : "r";
filename = Jim_String(argv[1]);
#ifdef jim_ext_tclcompat
/* If the filename starts with '|', use popen instead */
if (*filename == '|') {
Jim_Obj *evalObj[3];
evalObj[0] = Jim_NewStringObj(interp, "popen", -1);
evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
evalObj[2] = Jim_NewStringObj(interp, mode, -1);
return Jim_EvalObjVector(interp, 3, evalObj);
}
#endif
return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode);
}
示例2: Jim_PosixWaitCommand
/*
* 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;
}
示例3: Win32_GetSystemInfo
static int
Win32_GetSystemInfo(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
Jim_Obj *a[20];
SYSTEM_INFO si;
int n = 0;
struct pa_map { int arch; const char *name; };
struct pa_map *p, map[] = {
{ PROCESSOR_ARCHITECTURE_INTEL, "intel" },
{ PROCESSOR_ARCHITECTURE_MIPS, "mips" },
{ PROCESSOR_ARCHITECTURE_ALPHA, "alpha" },
{ PROCESSOR_ARCHITECTURE_PPC, "ppc" },
{ PROCESSOR_ARCHITECTURE_SHX, "shx" },
{ PROCESSOR_ARCHITECTURE_ARM, "arm" },
{ PROCESSOR_ARCHITECTURE_IA64, "ia64" },
{ PROCESSOR_ARCHITECTURE_ALPHA64,"alpha64" },
{ PROCESSOR_ARCHITECTURE_MSIL, "msil" },
{ PROCESSOR_ARCHITECTURE_AMD64, "amd64"},
{ PROCESSOR_ARCHITECTURE_IA32_ON_WIN64, "ia32onwin64" },
{ PROCESSOR_ARCHITECTURE_UNKNOWN,"unknown" }
};
JIM_NOTUSED(objc);
JIM_NOTUSED(objv);
GetSystemInfo(&si);
a[n++] = Jim_NewStringObj(interp, "ProcessorArchitecture", -1);
for (p = map; p->arch != PROCESSOR_ARCHITECTURE_UNKNOWN; ++p) {
if (p->arch == si.wProcessorArchitecture) {
break;
}
}
a[n++] = Jim_NewStringObj(interp, p->name, -1);
#define JIMADD(name,element) \
a[n++] = Jim_NewStringObj(interp, #name, -1); \
a[n++] = Jim_NewIntObj(interp, (jim_wide)si. ## element )
JIMADD(PageSize, dwPageSize);
JIMADD(MinimumApplicationAddress, lpMinimumApplicationAddress);
JIMADD(MaximumApplicationAddress, lpMaximumApplicationAddress);
JIMADD(ActiveProcessorMask, dwActiveProcessorMask);
JIMADD(NumberOfProcessors, dwNumberOfProcessors);
JIMADD(ProcessorType, dwProcessorType);
JIMADD(AllocationGranularity, dwAllocationGranularity);
JIMADD(ProcessorLevel, wProcessorLevel);
JIMADD(ProcessorRevision, wProcessorRevision);
#undef JIMADD
Jim_SetResult(interp, Jim_NewListObj(interp, a, n));
return JIM_OK;
}
示例4: StoreStatData
static int StoreStatData(Jim_Interp *interp, Jim_Obj *varName, const struct stat *sb)
{
/* Just use a list to store the data */
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
AppendStatElement(interp, listObj, "dev", sb->st_dev);
AppendStatElement(interp, listObj, "ino", sb->st_ino);
AppendStatElement(interp, listObj, "mode", sb->st_mode);
AppendStatElement(interp, listObj, "nlink", sb->st_nlink);
AppendStatElement(interp, listObj, "uid", sb->st_uid);
AppendStatElement(interp, listObj, "gid", sb->st_gid);
AppendStatElement(interp, listObj, "size", sb->st_size);
AppendStatElement(interp, listObj, "atime", sb->st_atime);
AppendStatElement(interp, listObj, "mtime", sb->st_mtime);
AppendStatElement(interp, listObj, "ctime", sb->st_ctime);
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "type", -1));
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, JimGetFileType((int)sb->st_mode), -1));
/* Was a variable specified? */
if (varName) {
Jim_Obj *objPtr = Jim_GetVariable(interp, varName, JIM_NONE);
if (objPtr) {
if (Jim_DictSize(interp, objPtr) < 0) {
/* This message matches the one from Tcl */
Jim_SetResultFormatted(interp, "can't set \"%#s(dev)\": variable isn't array", varName);
Jim_FreeNewObj(interp, listObj);
return JIM_ERR;
}
if (Jim_IsShared(objPtr))
objPtr = Jim_DuplicateObj(interp, objPtr);
/* Just cheat here and append as a list and convert to a dict */
Jim_ListAppendList(interp, objPtr, listObj);
Jim_DictSize(interp, objPtr);
Jim_InvalidateStringRep(objPtr);
Jim_FreeNewObj(interp, listObj);
listObj = objPtr;
}
Jim_SetVariable(interp, varName, listObj);
}
/* And also return the value */
Jim_SetResult(interp, listObj);
return JIM_OK;
}
示例5: Win32ErrorObj
static Jim_Obj *
Win32ErrorObj(Jim_Interp *interp, const char * szPrefix, DWORD dwError)
{
Jim_Obj *msgObj = NULL;
char * lpBuffer = NULL;
DWORD dwLen = 0;
dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, LANG_NEUTRAL,
(char *)&lpBuffer, 0, NULL);
if (dwLen < 1) {
dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
"code 0x%1!08X!%n", 0, LANG_NEUTRAL,
(char *)&lpBuffer, 0, (va_list *)&dwError);
}
msgObj = Jim_NewStringObj(interp, szPrefix, -1);
if (dwLen > 0) {
char *p = lpBuffer + dwLen - 1; /* remove cr-lf at end */
for ( ; p && *p && isspace(UCHAR(*p)); p--)
;
*++p = 0;
Jim_AppendString(interp, msgObj, ": ", 2);
Jim_AppendString(interp, msgObj, lpBuffer, -1);
}
LocalFree((HLOCAL)lpBuffer);
return msgObj;
}
示例6: ioutil_Jim_Command_ls
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;
}
示例7: Win32_AnimateWindow
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;
}
示例8: Win32_GetModuleFileName
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;
}
示例9: 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;
}
示例10: Jim_MakeTempFile
int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
{
int fd;
mode_t mask;
Jim_Obj *filenameObj;
if (filename_template == NULL) {
const char *tmpdir = getenv("TMPDIR");
if (tmpdir == NULL || *tmpdir == '\0' || access(tmpdir, W_OK) != 0) {
tmpdir = "/tmp/";
}
filenameObj = Jim_NewStringObj(interp, tmpdir, -1);
if (tmpdir[0] && tmpdir[strlen(tmpdir) - 1] != '/') {
Jim_AppendString(interp, filenameObj, "/", 1);
}
Jim_AppendString(interp, filenameObj, "tcl.tmp.XXXXXX", -1);
}
else {
filenameObj = Jim_NewStringObj(interp, filename_template, -1);
}
/* Update the template name directly with the filename */
mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
#ifdef HAVE_MKSTEMP
fd = mkstemp(filenameObj->bytes);
#else
if (mktemp(filenameObj->bytes) == NULL) {
fd = -1;
}
else {
fd = open(filenameObj->bytes, O_RDWR | O_CREAT | O_TRUNC);
}
#endif
umask(mask);
if (fd < 0) {
Jim_SetResultErrno(interp, Jim_String(filenameObj));
Jim_FreeNewObj(interp, filenameObj);
return -1;
}
if (unlink_file) {
remove(Jim_String(filenameObj));
}
Jim_SetResult(interp, filenameObj);
return fd;
}
示例11: JimCheckWaitStatus
/*
* Create error messages for unusual process exits. An
* extra newline gets appended to each error message, but
* it gets removed below (in the same fashion that an
* extra newline in the command's output is removed).
*/
static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus)
{
Jim_Obj *errorCode = Jim_NewListObj(interp, NULL, 0);
int rc = JIM_ERR;
if (WIFEXITED(waitStatus)) {
if (WEXITSTATUS(waitStatus) == 0) {
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "NONE", -1));
rc = JIM_OK;
}
else {
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "CHILDSTATUS", -1));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WEXITSTATUS(waitStatus)));
}
}
else {
const char *type;
const char *action;
if (WIFSIGNALED(waitStatus)) {
type = "CHILDKILLED";
action = "killed";
}
else {
type = "CHILDSUSP";
action = "suspended";
}
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, type, -1));
#ifdef jim_ext_signal
Jim_SetResultFormatted(interp, "child %s by signal %s", action, Jim_SignalId(WTERMSIG(waitStatus)));
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, Jim_SignalId(WTERMSIG(waitStatus)), -1));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, Jim_SignalName(WTERMSIG(waitStatus)), -1));
#else
Jim_SetResultFormatted(interp, "child %s by signal %d", action, WTERMSIG(waitStatus));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WTERMSIG(waitStatus)));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WTERMSIG(waitStatus)));
#endif
}
Jim_SetGlobalVariableStr(interp, "errorCode", errorCode);
return rc;
}
示例12: Jim_GetString
/* Everything passing between interpreters must be converted to a string */
static Jim_Obj *JimInterpCopyObj(Jim_Interp *target, Jim_Obj *obj)
{
const char *rep;
int len;
rep = Jim_GetString(obj, &len);
return Jim_NewStringObj(target, rep, len);
}
示例13: zylinjtag_Jim_Command_ip
/* not so pretty code to fish out ip number*/
static int zylinjtag_Jim_Command_ip(Jim_Interp *interp, int argc,
Jim_Obj * const *argv)
{
#if !defined(__CYGWIN__)
Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
struct ifaddrs *ifa = NULL, *ifp = NULL;
if (getifaddrs(&ifp) < 0)
{
return JIM_ERR;
}
for (ifa = ifp; ifa; ifa = ifa->ifa_next)
{
char ip[200];
socklen_t salen;
if (ifa->ifa_addr->sa_family == AF_INET)
salen = sizeof(struct sockaddr_in);
else if (ifa->ifa_addr->sa_family == AF_INET6)
salen = sizeof(struct sockaddr_in6);
else
continue;
if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
NI_NUMERICHOST) < 0)
{
continue;
}
Jim_AppendString(interp, tclOutput, ip, strlen(ip));
break;
}
freeifaddrs(ifp);
#else
Jim_Obj *tclOutput = Jim_NewStringObj(interp, "fixme!!!", 0);
LOG_ERROR("NOT IMPLEMENTED!!!");
#endif
Jim_SetResult(interp, tclOutput);
return JIM_OK;
}
示例14: Jim_EvalEnsemble
/* XXX: Temporary */
static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv)
{
Jim_Obj *prefixObj = Jim_NewStringObj(interp, basecmd, -1);
Jim_AppendString(interp, prefixObj, " ", 1);
Jim_AppendString(interp, prefixObj, subcmd, -1);
return Jim_EvalObjPrefix(interp, prefixObj, argc, argv);
}
示例15: ioutil_Jim_Command_mac
/* 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;
}