示例#1
0
static int Jim_SleepCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int ret;

    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "seconds");
        return JIM_ERR;
    }
    else {
        double t;

        ret = Jim_GetDouble(interp, argv[1], &t);
        if (ret == JIM_OK) {

#ifdef HAVE_SELECT
            struct timeval s;
            s.tv_sec = (long)t;
            s.tv_usec = (long)((t - (int)t) * 1e6);
            select(0, NULL, NULL, NULL, &s);
#else
#ifdef HAVE_USLEEP
            usleep((int)((t - (int)t) * 1e6));
#endif
            sleep(t);
#endif
        }
    }

    return ret;
}
示例#2
0
文件: jim-signal.c 项目: dgsb/jimtcl
static int Jim_AlarmCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int ret;

    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "seconds");
        return JIM_ERR;
    }
    else {
#ifdef HAVE_UALARM
        double t;

        ret = Jim_GetDouble(interp, argv[1], &t);
        if (ret == JIM_OK) {
            if (t < 1) {
                ualarm(t * 1e6, 0);
            }
            else {
                alarm(t);
            }
        }
#else
        long t;

        ret = Jim_GetLong(interp, argv[1], &t);
        if (ret == JIM_OK) {
            alarm(t);
        }
#endif
    }

    return ret;
}
示例#3
0
/* 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;
}
示例#4
0
static int JimELUpdateCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    Jim_EventLoop *eventLoop = Jim_CmdPrivData(interp);
    static const char * const options[] = {
        "idletasks", NULL
    };
    enum { UPDATE_IDLE, UPDATE_NONE };
    int option = UPDATE_NONE;
    int flags = JIM_TIME_EVENTS;

    if (argc == 1) {
        flags = JIM_ALL_EVENTS;
    }
    else if (argc > 2 || Jim_GetEnum(interp, argv[1], options, &option, NULL, JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
        Jim_WrongNumArgs(interp, 1, argv, "?idletasks?");
        return JIM_ERR;
    }

    eventLoop->suppress_bgerror = 0;

    while (Jim_ProcessEvents(interp, flags | JIM_DONT_WAIT) > 0) {
    }

    return JIM_OK;
}
示例#5
0
static int JimVariableCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int retcode = JIM_OK;

    if (argc > 3) {
        Jim_WrongNumArgs(interp, 1, argv, "name ?value?");
        return JIM_ERR;
    }
    if (argc > 1) {
        Jim_Obj *targetNameObj;
        Jim_Obj *localNameObj;

        targetNameObj = JimCanonicalNamespace(interp, interp->framePtr->nsObj, argv[1]);

        localNameObj = Jim_NamespaceTail(interp, argv[1]);
        Jim_IncrRefCount(localNameObj);
        if (interp->framePtr->level != 0 || Jim_Length(interp->framePtr->nsObj) != 0) {
            retcode = Jim_CreateNamespaceVariable(interp, localNameObj, targetNameObj);
        }

        /* Set the variable via the local name */
        if (retcode == JIM_OK && argc > 2) {
            retcode = Jim_SetVariable(interp, localNameObj, argv[2]);
        }
        Jim_DecrRefCount(interp, localNameObj);
    }
    return retcode;
}
示例#6
0
/**
 * [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;
}
static int Jim_SleepCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int ret;

    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "seconds");
        return JIM_ERR;
    }
    else {
        double t;

        ret = Jim_GetDouble(interp, argv[1], &t);
        if (ret == JIM_OK) {
#ifdef HAVE_USLEEP
            if (t < 1) {
                usleep(t * 1e6);
            }
            else
#endif
                sleep(t);
        }
    }

    return ret;
}
示例#8
0
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
0
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 JimVariableCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int retcode = JIM_OK;

    if (argc > 3) {
        Jim_WrongNumArgs(interp, 1, argv, "name ?value?");
        return JIM_ERR;
    }
    if (argc > 1) {
        Jim_Obj *targetNameObj;
        Jim_Obj *localNameObj;

#if 0
        /* XXX should we give an error on dict sugar syntax? */
        if (JimValidName(interp, "variable", argv[1]) != JIM_OK) {
            return JIM_ERR;
        }
#endif

        targetNameObj = JimCanonicalNamespace(interp, interp->framePtr->nsObj, argv[1]);

        localNameObj = Jim_NamespaceTail(interp, argv[1]);
        Jim_IncrRefCount(localNameObj);
        if (interp->framePtr->level != 0 || Jim_Length(interp->framePtr->nsObj) != 0) {
            Jim_CreateNamespaceVariable(interp, localNameObj, targetNameObj);
        }

        /* Set the variable via the local name */
        if (argc > 2) {
            retcode = Jim_SetVariable(interp, localNameObj, argv[2]);
        }
        Jim_DecrRefCount(interp, localNameObj);
    }
    return retcode;
}
示例#11
0
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);
}
示例#12
0
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;
}
示例#13
0
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;
}
示例#14
0
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;
}
示例#15
0
static int JimELVwaitCommand(Jim_Interp *interp, int argc, 
        Jim_Obj *const *argv)
{
    Jim_Obj *oldValue;

    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "name");
        return JIM_ERR;
    }
    oldValue = Jim_GetGlobalVariable(interp, argv[1], JIM_NONE);
    if (oldValue) Jim_IncrRefCount(oldValue);
    while (1) {
        Jim_Obj *currValue;

        Jim_ProcessEvents(interp, JIM_ALL_EVENTS);
        currValue = Jim_GetGlobalVariable(interp, argv[1], JIM_NONE);
        /* Stop the loop if the vwait-ed variable changed value,
         * or if was unset and now is set (or the contrary). */
        if ((oldValue && !currValue) ||
            (!oldValue && currValue) ||
            (oldValue && currValue &&
             !Jim_StringEqObj(oldValue, currValue, JIM_CASESENS)))
            break;
    }
    if (oldValue) Jim_DecrRefCount(interp, oldValue);
    return JIM_OK;
}
示例#16
0
文件: jim-load.c 项目: AllardJ/Tomato
/* [load] */
static int Jim_LoadCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    if (argc < 2) {
        Jim_WrongNumArgs(interp, 1, argv, "libaryFile");
        return JIM_ERR;
    }
    return Jim_LoadLibrary(interp, Jim_String(argv[1]));
}
示例#17
0
static int JimRlAddHistoryCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "string");
        return JIM_ERR;
    }
    add_history(Jim_String(argv[1]));
    return JIM_OK;
}
示例#18
0
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;
}
示例#19
0
/*
 * 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);
}
示例#20
0
static int Jim_PosixPidCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    if (argc != 1) {
        Jim_WrongNumArgs(interp, 1, argv, "");
        return JIM_ERR;
    }

    Jim_SetResultInt(interp, getpid());
    return JIM_OK;
}
示例#21
0
/*
 * 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;
}
示例#22
0
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;
}
示例#23
0
static int Jim_LinuxUSleepCommand(Jim_Interp *interp, int argc,
        Jim_Obj *const *argv)
{
    int mult = NSNS ;
    double floatValue ;
    const char *units ;
    long long delay ;
    int len ;
    struct timespec tv;
	
    switch (argc) { 
    case 3: 
           units = Jim_GetString(argv[2], &len);
	   if (units == NULL)
               return JIM_ERR;
	   switch (*units) {
	   case 's': mult = S_NS; break;
	   case 'm': mult = MSNS; break;
	   case 'u': mult = USNS; break;
	   case 'n': mult = NSNS; break;
	   default:
               Jim_WrongNumArgs(interp, 1, argv, "arg3: ms us ns or empty");
	       return JIM_ERR;
	   }
	// fallthrough
    case 2: if (Jim_GetDouble(interp, argv[1], &floatValue) != JIM_OK)
               return JIM_ERR;
	   delay = (long long)(floatValue * mult);
           break;
    default:
           Jim_WrongNumArgs(interp, 1, argv, "?useconds?");
           return JIM_ERR;
    }
    tv.tv_sec = delay / S_NS;
    tv.tv_nsec = delay % S_NS;
    fprintf(stderr,"delay: %lld mult: %d  sec: %ld ns: %ld\n", delay, mult, tv.tv_sec,tv.tv_nsec );
    nanosleep(&tv,NULL);
    return JIM_OK;
}
示例#24
0
static int Jim_PosixSleepCommand(Jim_Interp *interp, int argc, 
        Jim_Obj *const *argv)
{
    long longValue;
    
    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "?seconds?");
        return JIM_ERR;
    }
    if (Jim_GetLong(interp, argv[1], &longValue) != JIM_OK)
        return JIM_ERR;
    sleep(longValue);
    return JIM_OK;
}
示例#25
0
static int JimRlReadlineCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    char *line;

    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "prompt");
        return JIM_ERR;
    }
    line = readline(Jim_String(argv[1]));
    if (!line) {
        return JIM_EXIT;
    }
    Jim_SetResult(interp, Jim_NewStringObj(interp, line, -1));
    return JIM_OK;
}
示例#26
0
/**
 * Implements the Tcl "transport select" command, choosing the
 * transport to be used in this debug session from among the
 * set supported by the debug adapter being used.  Return value
 * is scriptable (allowing "if swd then..." etc).
 */
static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
	switch (argc) {
		case 1:		/* return/display */
			if (!session) {
				LOG_ERROR("session's transport is not selected.");
				return JIM_ERR;
			} else {
				Jim_SetResultString(interp, session->name, -1);
				return JIM_OK;
			}
			break;
		case 2:		/* assign */
			if (session) {
				if (!strcmp(session->name, argv[1]->bytes)) {
					LOG_WARNING("Transport \"%s\" was already selected", session->name);
					return JIM_OK;
				} else {
					LOG_ERROR("Can't change session's transport after the initial selection was made");
					return JIM_ERR;
				}
			}

			/* Is this transport supported by our debug adapter?
			 * Example, "JTAG-only" means SWD is not supported.
			 *
			 * NOTE:  requires adapter to have been set up, with
			 * transports declared via C.
			 */
			if (!allowed_transports) {
				LOG_ERROR("Debug adapter doesn't support any transports?");
				return JIM_ERR;
			}

			for (unsigned i = 0; allowed_transports[i]; i++) {

				if (strcmp(allowed_transports[i], argv[1]->bytes) == 0)
					return transport_select(global_cmd_ctx, argv[1]->bytes);
			}

			LOG_ERROR("Debug adapter doesn't support '%s' transport", argv[1]->bytes);
			return JIM_ERR;
			break;
		default:
			Jim_WrongNumArgs(interp, 1, argv, "[too many parameters]");
			return JIM_ERR;
	}
}
示例#27
0
static int JimELVwaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    Jim_EventLoop *eventLoop = Jim_CmdPrivData(interp);
    Jim_Obj *oldValue;
    int rc;

    if (argc != 2) {
        Jim_WrongNumArgs(interp, 1, argv, "name");
        return JIM_ERR;
    }

    oldValue = Jim_GetGlobalVariable(interp, argv[1], JIM_NONE);
    if (oldValue) {
        Jim_IncrRefCount(oldValue);
    }
    else {
        /* If a result was left, it is an error */
        if (Jim_Length(Jim_GetResult(interp))) {
            return JIM_ERR;
        }
    }

    eventLoop->suppress_bgerror = 0;

    while ((rc = Jim_ProcessEvents(interp, JIM_ALL_EVENTS)) >= 0) {
        Jim_Obj *currValue;
        currValue = Jim_GetGlobalVariable(interp, argv[1], JIM_NONE);
        /* Stop the loop if the vwait-ed variable changed value,
         * or if was unset and now is set (or the contrary)
         * or if a signal was caught
         */
        if ((oldValue && !currValue) ||
            (!oldValue && currValue) ||
            (oldValue && currValue && !Jim_StringEqObj(oldValue, currValue)) ||
            Jim_CheckSignal(interp)) {
            break;
        }
    }
    if (oldValue)
        Jim_DecrRefCount(interp, oldValue);

    if (rc == -2) {
        return JIM_ERR;
    }

    Jim_SetEmptyResult(interp);
    return JIM_OK;
}
示例#28
0
static int Jim_PosixGethostnameCommand(Jim_Interp *interp, int argc,
        Jim_Obj *const *argv)
{
    char buf[JIM_HOST_NAME_MAX];

    if (argc != 1) {
        Jim_WrongNumArgs(interp, 1, argv, "");
        return JIM_ERR;
    }
    if (gethostname(buf, JIM_HOST_NAME_MAX) == -1) {
        Jim_PosixSetError(interp);
        return JIM_ERR;
    }
    Jim_SetResultString(interp, buf, -1);
    return JIM_OK;
}
示例#29
0
static int
MySampleCommandFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
	const char *str;
	int len;

	if (argc != 2) {
		Jim_WrongNumArgs(interp, 1, argv, "string");
		return (JIM_ERR);
	}

	str = Jim_GetString(argv[1], &len);
	assert(str != NULL);
	printf("%s\n", str);

	return (JIM_OK);
}
示例#30
0
static int Jim_PosixForkCommand(Jim_Interp *interp, int argc, 
        Jim_Obj *const *argv)
{
    pid_t pid;
    JIM_NOTUSED(argv);
    
    if (argc != 1) {
        Jim_WrongNumArgs(interp, 1, argv, "");
        return JIM_ERR;
    }
    if ((pid = fork()) == -1) {
        Jim_SetResultString(interp, strerror(errno), -1);
        return JIM_ERR;
    }
    Jim_SetResult(interp, Jim_NewIntObj(interp, (jim_wide)pid));
    return JIM_OK;
}