int run_command(char* cmdline) { char* argv[BUFFER_SIZE]; int argc = tokenize(cmdline, argv); if (argc == 0) { return 0; } if (strcmp(argv[0], "wait") == 0) { return cmd_wait(argc, argv); } else if (strcmp(argv[0], "ls") == 0) { return cmd_ls(argc, argv); } else if (strcmp(argv[0], "cp") == 0) { return cmd_cp(argc, argv); } else if (strcmp(argv[0], "show") == 0) { return cmd_show(argc, argv); } else if (strcmp(argv[0], "rm") == 0) { return cmd_rm(argc, argv); } else if (strcmp(argv[0], "pwd") == 0) { return cmd_pwd(argc, argv); } else if (strcmp(argv[0], "cd") == 0) { return cmd_cd(argc, argv); } else if (strcmp(argv[0], "cmp") == 0) { return cmd_cmp(argc, argv); } else if (strcmp(argv[0], "echo") == 0) { return cmd_echo(argc, argv); } else if (strcmp(argv[0], "mkdir") == 0) { return cmd_mkdir(argc, argv); } else if (strcmp(argv[0], "rmdir") == 0) { return cmd_rmdir(argc, argv); } else { int k = strlen(argv[argc-1]); if (argv[argc-1][k-1] == '&') { argv[argc-1][k-1] = '\0'; return background_run(cmdline); } else { return cmd_run(cmdline); } } }
// runs a script // returns -1 is esc was pressed, 0 o/w int run_script(char *script, DATAFILE *d) { char buf[512]; Ttoken *token; int i; // set datafile data = d; clear_keybuf(); // init sound memory for(i = 0; i < MAX_SCRIPT_SOUNDS; i ++) active_sounds[i] = -1; // create gfx buffers swap_buffer = create_bitmap(160, 120); buffer = create_bitmap(160, 120); script_done = FALSE; while(!script_done) { // get commands from script string script = get_line(buf, script); if (buf[0] != '#' && buf[0] != '\n' && buf[0] != '\r' && buf[0] != '-') { token = tokenize(buf); if (token != NULL) { if (!stricmp(token->word, "load_map")) cmd_loadmap(get_next_word(token)); else if (!stricmp(token->word, "draw_map")) cmd_drawmap(); else if (!stricmp(token->word, "set")) cmd_set((Ttoken *)token->next); else if (!stricmp(token->word, "move")) cmd_move((Ttoken *)token->next); else if (!stricmp(token->word, "delete")) cmd_del((Ttoken *)token->next); else if (!stricmp(token->word, "run")) cmd_run((Ttoken *)token->next); else if (!stricmp(token->word, "speak")) cmd_speak((Ttoken *)token->next, 1); else if (!stricmp(token->word, "text")) cmd_speak((Ttoken *)token->next, 0); else if (!stricmp(token->word, "save_buffer")) cmd_savebmp(); else if (!stricmp(token->word, "show_bmp")) cmd_showbmp(get_next_word(token)); else if (!stricmp(token->word, "blit")) cmd_blit(); else if (!stricmp(token->word, "fade_in")) cmd_fadein(); else if (!stricmp(token->word, "fade_out")) cmd_fadeout(); else if (!stricmp(token->word, "wait")) cmd_wait(atoi(get_next_word(token))); else if (!stricmp(token->word, "play_sample")) cmd_play_sample((Ttoken *)token->next); else if (!stricmp(token->word, "stop_sample")) cmd_stop_sample((Ttoken *)token->next); else if (!stricmp(token->word, "end_script")) cmd_end(); else { char msg[256]; sprintf(msg, "unknown: %s", token->word); msg_box(msg); } flush_tokens(token); } } } // destroy buffers delete_all_objects(); destroy_bitmap(buffer); destroy_bitmap(swap_buffer); // stop old sounds for(i = 0; i < MAX_SCRIPT_SOUNDS; i ++) { if (active_sounds[i] != -1) { stop_sound_id(active_sounds[i]); forget_sound(active_sounds[i]); } } return (script_done == -1 ? -1 : 0); }
int main (int argc, char *argv[]) { flux_t h; int ch; char *cmd; log_init ("flux-kvs"); while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case 'h': /* --help */ usage (); break; default: usage (); break; } } if (optind == argc) usage (); cmd = argv[optind++]; if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (!strcmp (cmd, "get")) cmd_get (h, argc - optind, argv + optind); else if (!strcmp (cmd, "type")) cmd_type (h, argc - optind, argv + optind); else if (!strcmp (cmd, "put")) cmd_put (h, argc - optind, argv + optind); else if (!strcmp (cmd, "unlink")) cmd_unlink (h, argc - optind, argv + optind); else if (!strcmp (cmd, "link")) cmd_link (h, argc - optind, argv + optind); else if (!strcmp (cmd, "readlink")) cmd_readlink (h, argc - optind, argv + optind); else if (!strcmp (cmd, "mkdir")) cmd_mkdir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "exists")) cmd_exists (h, argc - optind, argv + optind); else if (!strcmp (cmd, "version")) cmd_version (h, argc - optind, argv + optind); else if (!strcmp (cmd, "wait")) cmd_wait (h, argc - optind, argv + optind); else if (!strcmp (cmd, "watch")) cmd_watch (h, argc - optind, argv + optind); else if (!strcmp (cmd, "watch-dir")) cmd_watch_dir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dropcache")) cmd_dropcache (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dropcache-all")) cmd_dropcache_all (h, argc - optind, argv + optind); else if (!strcmp (cmd, "copy-tokvs")) cmd_copy_tokvs (h, argc - optind, argv + optind); else if (!strcmp (cmd, "copy-fromkvs")) cmd_copy_fromkvs (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dir")) cmd_dir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dirsize")) cmd_dirsize (h, argc - optind, argv + optind); else usage (); flux_close (h); log_fini (); return 0; }