コード例 #1
0
ファイル: fileio.c プロジェクト: dschwen/jszip
void script_char( int c )
{

   /* Check the state of the scripting flag in the game flags. If it is on
    * then check to see if the scripting file is open as well */

   if ( ( get_word( H_FLAGS ) & SCRIPTING_FLAG ) != 0 && scripting == OFF )
   {
      open_script(  );
   }

   /* Check the state of the scripting flag in the game flags. If it is off
    * then check to see if the scripting file is closed as well */

   if ( ( get_word( H_FLAGS ) & SCRIPTING_FLAG ) == 0 && scripting == ON )
   {
      close_script(  );
   }

   /* If scripting file is open, we are in the text window and the character is
    * printable then write the character */

   if ( scripting == ON && scripting_disable == OFF && ( c == '\n' || ( isprint( c ) ) ) )
   {
      putc( c, sfp );
   }

}                               /* script_char */
コード例 #2
0
ファイル: pspsh.C プロジェクト: FTPiano/psplinkusb
int execute_script(const char *cmd)
{
	char args[4096];
	char *argv[16];
	int  argc;
	int len;

	len = strlen(cmd);

	if(len > 0)
	{
		char redir[PATH_MAX];
		int  type;
		int binlen = parse_cli(cmd, args, &argc, argv, 16, 0, NULL, &type, redir);
		if(binlen > 0)
		{
			if(open_script(argv[0], argc, argv))
			{
				if(execute_script_line() > 0)
				{
					return 1;
				}
			}
		}
	}

	return 0;
}
コード例 #3
0
ファイル: freej.cpp プロジェクト: K0F/FreeJ
// load all default scripts in $DATADIR/freej and ~/.freej
int scripts(char *path) {
    char *dir;
    struct dirent **filelist;
    int found;

    dir = strtok(path, ":");
    do {
        found = scandir(dir, &filelist, script_selector, alphasort);
        if(found < 0) {
            error("loading default scripts: scandir error: %s", strerror(errno));
            return(-1);
        }
        /* .so files found, check if they are plugins */
        while(found--) {
            char temp[256];
            snprintf(temp, 255, "%s/%s", dir, filelist[found]->d_name);
            // if it exist is a default one: source it
            open_script(temp);
        }
    } while((dir = strtok(NULL, ":")));

    return 1;
}
コード例 #4
0
ファイル: main.c プロジェクト: chenjiefeng/bladeRF
int main(int argc, char *argv[])
{
    int status = 0;
    struct rc_config rc;
    struct cli_state *state;
    bool exit_immediately = false;

    /* If no actions are specified, just show the usage text and exit */
    if (argc == 1) {
        usage(argv[0]);
        return 0;
    }

    init_rc_config(&rc);

    if (get_rc_config(argc, argv, &rc)) {
        return 1;
    }

    state = cli_state_create();

    if (!state) {
        fprintf(stderr, "Failed to create state object\n");
        return 1;
    }

    bladerf_log_set_verbosity(rc.verbosity);

    if (rc.show_help) {
        usage(argv[0]);
        exit_immediately = true;
    } else if (rc.show_version) {
        printf(BLADERF_CLI_VERSION "\n");
        exit_immediately = true;
    } else if (rc.show_lib_version) {
        struct bladerf_version version;
        bladerf_version(&version);
        printf("%s\n", version.describe);
        exit_immediately = true;
    } else if (rc.probe) {
        status = cmd_handle(state, "probe");
        exit_immediately = true;
    }

    if (!exit_immediately) {
        /* Conditionally performed items, depending on runtime config */
        status = open_device(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not open device\n");
            goto main__issues ;
        }

        status = flash_fw(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not flash firmware\n");
            goto main__issues ;
        }

        status = flash_fpga(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not flash fpga\n");
            goto main__issues ;
        }

        status = load_fpga(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not load fpga\n");
            goto main__issues ;
        }

        status = open_script(&rc, state, status);
        if (status) {
            fprintf(stderr, "Could not load scripts\n");
            goto main__issues ;
        }

main__issues:
        /* These items are no longer needed */
        free(rc.device);
        rc.device = NULL;

        free(rc.fw_file);
        rc.fw_file = NULL;

        free(rc.fpga_file);
        rc.fpga_file = NULL;

        free(rc.script_file);
        rc.script_file = NULL;

        /* Drop into interactive mode or begin executing commands
         * from a script. If we're not requested to do either, exit cleanly */
        if (rc.interactive_mode || state->script != NULL) {
            status = interactive(state, !rc.interactive_mode);
        }
    }

    cli_state_destroy(state);
    return status;
}
コード例 #5
0
ファイル: prompt.c プロジェクト: gonzus/tig
enum request
run_prompt_command(struct view *view, const char *argv[])
{
	enum request request;
	const char *cmd = argv[0];
	size_t cmdlen = cmd ? strlen(cmd) : 0;

	if (!cmd)
		return REQ_NONE;

	if (string_isnumber(cmd)) {
		int lineno = view->pos.lineno + 1;

		if (parse_int(&lineno, cmd, 0, view->lines + 1) == SUCCESS) {
			if (!lineno)
				lineno = 1;
			select_view_line(view, lineno - 1);
			report_clear();
		} else {
			report("Unable to parse '%s' as a line number", cmd);
		}
	} else if (iscommit(cmd)) {
		int lineno;

		if (!(view->ops->column_bits & view_column_bit(ID))) {
			report("Jumping to commits is not supported by the %s view", view->name);
			return REQ_NONE;
		}

		for (lineno = 0; lineno < view->lines; lineno++) {
			struct view_column_data column_data = {};
			struct line *line = &view->line[lineno];

			if (view->ops->get_column_data(view, line, &column_data) &&
			    column_data.id &&
			    !strncasecmp(column_data.id, cmd, cmdlen)) {
				string_ncopy(view->env->search, cmd, cmdlen);
				select_view_line(view, lineno);
				report_clear();
				return REQ_NONE;
			}
		}

		report("Unable to find commit '%s'", view->env->search);
		return REQ_NONE;

	} else if (cmdlen > 1 && (cmd[0] == '/' || cmd[0] == '?')) {
		char search[SIZEOF_STR];

		if (!argv_to_string(argv, search, sizeof(search), " ")) {
			report("Failed to copy search string");
			return REQ_NONE;
		}

		if (!strcmp(search + 1, view->env->search))
			return cmd[0] == '/' ? REQ_FIND_NEXT : REQ_FIND_PREV;

		string_ncopy(view->env->search, search + 1, strlen(search + 1));
		return cmd[0] == '/' ? REQ_SEARCH : REQ_SEARCH_BACK;

	} else if (cmdlen > 1 && cmd[0] == '!') {
		struct view *next = &pager_view;
		bool copied;

		/* Trim the leading '!'. */
		argv[0] = cmd + 1;
		copied = argv_format(view->env, &next->argv, argv, FALSE, TRUE);
		argv[0] = cmd;

		if (!copied) {
			report("Argument formatting failed");
		} else {
			/* When running random commands, initially show the
			 * command in the title. However, it maybe later be
			 * overwritten if a commit line is selected. */
			argv_to_string(next->argv, next->ref, sizeof(next->ref), " ");

			next->dir = NULL;
			open_pager_view(view, OPEN_PREPARED | OPEN_WITH_STDERR);
		}

	} else if (!strcmp(cmd, "save-display")) {
		const char *path = argv[1] ? argv[1] : "tig-display.txt";

		if (!save_display(path))
			report("Failed to save screen to %s", path);
		else
			report("Saved screen to %s", path);

	} else if (!strcmp(cmd, "exec")) {
		struct run_request req = { view->keymap, {}, argv + 1 };
		enum status_code code = parse_run_request_flags(&req.flags, argv + 1);

		if (code != SUCCESS) {
			report("Failed to execute command: %s", get_status_message(code));
		} else {
			return exec_run_request(view, &req);
		}

	} else if (!strcmp(cmd, "toggle")) {
		enum view_flag flags = VIEW_NO_FLAGS;
		enum status_code code = prompt_toggle(view, argv, &flags);
		const char *action = get_status_message(code);

		if (code != SUCCESS) {
			report("%s", action);
			return REQ_NONE;
		}

		prompt_update_display(flags);

		if (*action)
			report("%s", action);

	} else if (!strcmp(cmd, "script")) {
		if (is_script_executing()) {
			report("Scripts cannot be run from scripts");
		} else if (!open_script(argv[1])) {
			report("Failed to open %s", argv[1]);
		}

	} else {
		struct key key = {};
		enum status_code code;
		enum view_flag flags = VIEW_NO_FLAGS;

		/* Try :<key> */
		key.modifiers.multibytes = 1;
		string_ncopy(key.data.bytes, cmd, cmdlen);
		request = get_keybinding(view->keymap, &key, 1);
		if (request != REQ_NONE)
			return request;

		/* Try :<command> */
		request = get_request(cmd);
		if (request != REQ_UNKNOWN)
			return request;

		code = set_option(argv[0], argv_size(argv + 1), &argv[1]);
		if (code != SUCCESS) {
			report("%s", get_status_message(code));
			return REQ_NONE;
		}

		if (!strcmp(cmd, "set")) {
			struct prompt_toggle *toggle;

			toggle = find_prompt_toggle(option_toggles, ARRAY_SIZE(option_toggles),
						    "", argv[1], strlen(argv[1]));

			if (toggle)
				flags = toggle->flags;
		}

		if (flags) {
			prompt_update_display(flags);

		} else {
			request = view_can_refresh(view) ? REQ_REFRESH : REQ_SCREEN_REDRAW;
			if (!strcmp(cmd, "color"))
				init_colors();
			resize_display();
			redraw_display(TRUE);
		}

	}
	return REQ_NONE;
}
コード例 #6
0
ファイル: pspsh.C プロジェクト: FTPiano/psplinkusb
int parse_args(int argc, char **argv, struct Args *args)
{
	const char *name;
	memset(args, 0, sizeof(*args));
	args->port = DEFAULT_PORT;
	args->ip = DEFAULT_IP;

	if(argc == 0)
	{
		return 0;
	}

	name = argv[0];

	while(1)
	{
		int ch;
		int error = 0;

		ch = getopt(argc, argv, "nsrp:h:i:e:");
		if(ch < 0)
		{
			break;
		}

		switch(ch)
		{
			case 'p': args->port = atoi(optarg);
					  break;
			case 'h': args->hist = optarg;
					  break;
			case 'n': args->notty = 1;
					  break;
			case 'i': args->ip = optarg;
					  break;
			case 'e': snprintf(args->exec, sizeof(args->exec), "%s", optarg);
					  args->script = 1;
					  args->notty = 1;
					  break;
			case 's': dump_symlinks(0);
					  exit(0);
					  break;
			case 'r': dump_symlinks(1);
					  exit(0);
					  break;
			case 'v': g_verbose = 1;
					  break;
			default : error = 1;
					  break;
		};

		if(error)
		{
			return 0;
		}
	}

	argc -= optind;
	argv += optind;

	if(!check_symlink(name, argc, argv, args))
	{
		if(argc > 0)
		{
			if(!open_script(argv[0], argc, argv))
			{
				return 0;
			}
			args->script = 1;
			args->notty = 1;
		}
	}

	return 1;
}
コード例 #7
0
ファイル: freej.cpp プロジェクト: K0F/FreeJ
int main(int argc, char **argv) {
    LayerPtr lay;
    ConsoleControllerPtr con;
#ifdef WITH_JAVASCRIPT
    bool interactive = true;
#endif //WITH_JAVASCRIPT

    freej = MakeShared<Context>();

    notice("%s version %s   free the veejay", PACKAGE, VERSION);
    act("2001-2009 RASTASOFT :: %s", PACKAGE_URL);
    act("----------------------------------------------");

    cmdline(argc, argv);
    set_debug(debug_level);

    // create SDL screen by default at selected size
    screen = Factory<ViewPort>::get_instance("Screen", screen_name);
    //  screen = new SdlScreen();
    if(!screen) {
        error("no screen can be opened");
        exit(1);
    }

    screen->init(width, height, 32);
    setSelectedScreen(screen);

    // add the screen to the context
    freej->add_screen(screen);

    if(fullscreen) screen->fullscreen();

    /* sets realtime priority to maximum allowed for SCHED_RR (POSIX.1b)
       this hangs on some linux kernels - darwin doesn't even bothers with it
       anybody knows what's wrong when you turn it on? ouch! it hurts :|
       set_rtpriority is inside jutils.cpp
       if(set_rtpriority(true))
       notice("running as root: high priority realtime scheduling allowed.");
     */



    /* initialize the S-Lang text Console */
    if(!noconsole) {
        if(getenv("TERM")) {
            con = MakeShared<SlwConsole>(freej);
            freej->register_controller(con);
            GlobalLogger::register_logger(con);
            con->console_init();
        }
    }

#ifdef WITH_JAVASCRIPT
    // load default settings
    config_check("keyboard.js");

    /* execute javascript */
    if(javascript[0]) {
        interactive = false;
        open_script(javascript); // TODO: quit here when script failed??
        if(freej->isQuitting()) {
            //      freej.close();
            // here calling close directly we double the destructor
            // fixed omitting the explicit close() call
            // but would be better to make the destructor reentrant
            exit(1);
        } else {
            interactive = true;
        }
    }

    /* execute processing */
    if(processing[0]) {
        interactive = false;
        char tmp[1024];

        // parse includes our extra processing.js library
        snprintf(tmp, 1023, "include(\"processing.js\");script = read_file(\"%s\");Processing(script);", processing);
        freej->js->parse(tmp);
        if(freej->isQuitting()) {
            exit(1);
        } else {
            interactive = true;
        }
    }
#endif //WITH_JAVASCRIPT

    // Set fps
    freej->setFps(fps);

    // TODO freej->setStartRunning(startstate);

    /* create layers requested on commandline */
    {
        char *l, *p, *pp = layer_files;
        while(cli_chars > 0) {

            p = pp;

            while(*p != '#' && cli_chars > 0) {
                p++;
                cli_chars--;
            }
            l = p + 1;
            if(cli_chars <= 0) break;
            *p = '\0';

            func("creating layer for file %s", pp);

            lay = freej->open(pp); // hey, this already init and open the layer !!
            if(lay)  {
                screen->add_layer(lay);
            }

            pp = l;
        }
    }

    freej->start();

    /* initialize the S-Lang text Console */
    if(!noconsole) {
        if(getenv("TERM")) {
            freej->rem_controller(con);
            GlobalLogger::unregister_logger(con);
        }
    }

    return 0;
}