Esempio n. 1
0
/*
 * Parse "interface" keyword.
 */
static int
InterfaceFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
	struct mystate *softc;
	struct iface *iface;
	Jim_Obj *ipobj;
	const char *ip;
	const char *name;
	int error;

	iface = NULL;
	ipobj = NULL;
	ip = name = NULL;
	error = 0;

	if (argc != 3)
		return (JIM_ERR);

	softc = Jim_CmdPrivData(interp);

	/* Name of the interface. */
	name = Jim_GetString(argv[1], NULL);

	softc->block_parsing = 1;
	/* Body of the block */
	error = Jim_EvalObj(interp, argv[2]);
	if (error) {
		printf("couldn't evaluate\n");
		return (JIM_ERR);
	}
	softc->block_parsing = 0;

	/* Take our hidden variable */
	ipobj = Jim_GetVariableStr(interp, JCONF_VAR_IP, JIM_NONE);
	assert(ipobj != NULL);

	ip = Jim_GetString(ipobj, NULL);
	if (ip == NULL) {
		Jim_fprintf(interp, interp->cookie_stdout, "NULL!\n");
		return (JIM_ERR);
	}
	iface = iface_alloc(ip, name);
	assert(iface != NULL);
	INSERT(softc->head, iface);
	return (JIM_OK);
}
Esempio n. 2
0
static int JimSdlSurfaceCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    JimSdlSurface *jss;
    char buf[AIO_CMD_LEN];
    Jim_Obj *objPtr;
    long screenId, xres, yres;
    SDL_Surface *screen;

    if (argc != 3) {
        Jim_WrongNumArgs(interp, 1, argv, "xres yres");
        return JIM_ERR;
    }
    if (Jim_GetLong(interp, argv[1], &xres) != JIM_OK ||
        Jim_GetLong(interp, argv[2], &yres) != JIM_OK)
        return JIM_ERR;

    /* Try to create the surface */
    screen = SDL_SetVideoMode(xres, yres, 32, SDL_SWSURFACE | SDL_ANYFORMAT);
    if (screen == NULL) {
        JimSdlSetError(interp);
        return JIM_ERR;
    }
    /* Get the next file id */
    if (Jim_EvalGlobal(interp, "if {[catch {incr sdl.surfaceId}]} {set sdl.surfaceId 0}") != JIM_OK)
        return JIM_ERR;
    objPtr = Jim_GetVariableStr(interp, "sdl.surfaceId", JIM_ERRMSG);
    if (objPtr == NULL)
        return JIM_ERR;
    if (Jim_GetLong(interp, objPtr, &screenId) != JIM_OK)
        return JIM_ERR;

    /* Create the SDL screen command */
    jss = Jim_Alloc(sizeof(*jss));
    jss->screen = screen;
    sprintf(buf, "sdl.surface%ld", screenId);
    Jim_CreateCommand(interp, buf, JimSdlHandlerCommand, jss, JimSdlDelProc);
    Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, Jim_NewStringObj(interp, buf, -1)));
    return JIM_OK;
}