int do_curses_photorec(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk) { static alloc_data_t list_search_space={ .list = TD_LIST_HEAD_INIT(list_search_space.list) }; if(params->cmd_device==NULL) { char *saved_device=NULL; char *saved_cmd=NULL; session_load(&saved_device, &saved_cmd,&list_search_space); if(saved_device!=NULL && saved_cmd!=NULL && !td_list_empty(&list_search_space.list) #ifdef HAVE_NCURSES && ask_confirmation("Continue previous session ? (Y/N)")!=0 #endif ) { /* yes */ params->cmd_run=saved_cmd; params->cmd_device=saved_device; } else { free(saved_device); free(saved_cmd); free_list_search_space(&list_search_space); } } if(params->cmd_device!=NULL && params->cmd_run!=NULL) { params->disk=photorec_disk_selection_cli(params->cmd_device, list_disk, &list_search_space); #ifdef HAVE_NCURSES if(params->disk==NULL) { log_critical("No disk found\n"); return intrf_no_disk_ncurses("PhotoRec"); } if(change_arch_type_cli(params->disk, options->verbose, ¶ms->cmd_run)==0 || change_arch_type_ncurses(params->disk, options->verbose)==0) { menu_photorec(params, options, &list_search_space); } return 0; #else if(params->disk==NULL) { log_critical("No disk found\n"); return 0; } change_arch_type_cli(params->disk, options->verbose, ¶ms->cmd_run); menu_photorec(params, options, &list_search_space); return 0; #endif } #ifdef HAVE_NCURSES return photorec_disk_selection_ncurses(params, options, list_disk, &list_search_space); #else return 0; #endif }
/*************************** *** Playback management *** ***************************/ void queue_play(gboolean notif) { sp_track* track; int len; len = g_queue_get_length(&g_queue); switch(g_status) { case STOPPED: if (len > 0) { if (g_shuffle && (g_shuffle_first == -1)) g_shuffle_first = g_current_track = g_random_int_range(0, len); else if (g_current_track < 0) g_current_track = 0; else if (g_current_track >= len) g_current_track = len-1; g_debug("Playing track %d.", g_current_track); track = g_queue_peek_nth(&g_queue, g_current_track); if (!track) g_error("Can't peek track."); session_load(track); session_play(TRUE); g_status = PLAYING; if (notif) queue_notify(); } else g_debug("Nothing to play (empty queue)."); break; case PAUSED: g_debug("Resuming playback."); session_play(TRUE); g_status = PLAYING; if (notif) queue_notify(); break; case PLAYING: g_debug("Already playing: nothing to do."); break; } }
void queue_goto(gboolean notif, int idx, gboolean reset_shuffle_first) { int len = g_queue_get_length(&g_queue); queue_status s = g_status; if (idx == g_current_track) { g_debug("New track == current_track == %d: doing nothing.", g_current_track); return; } queue_stop(FALSE); if (idx < 0) { g_debug("Reached beginning of queue, stopping playback."); g_current_track = -1; } else if (idx >= len) { g_debug("Reached end of queue, stopping playback."); g_current_track = -1; } else { g_debug("Switching to track %d.", idx); g_current_track = idx; if (reset_shuffle_first) g_shuffle_first = idx; if (s == PAUSED) { sp_track* track; track = g_queue_peek_nth(&g_queue, g_current_track); if (!track) g_error("Can't peek track."); session_load(track); g_status = PAUSED; } else queue_play(FALSE); } if (notif) queue_notify(); }
int main(int argc, char **argv) { char *session_file, c; int i; struct option arguments[] = { {"help", no_argument, 0, 'u'}, /* for "usage", get it? hah, hah... */ {"monome-columns", required_argument, 0, 'c'}, {"monome-rows", required_argument, 0, 'r'}, {"osc-prefix", required_argument, 0, 'p'}, {"osc-host-port", required_argument, 0, 'h'}, {"osc-listen-port", required_argument, 0, 'l'}, {0, 0, 0, 0} }; memset(&state, 0, sizeof(rove_state_t)); session_file = NULL; opterr = 0; while( (c = getopt_long(argc, argv, "uc:r:p:h:l:", arguments, &i)) > 0 ) { switch( c ) { case 'u': usage(); exit(EXIT_FAILURE); /* should we exit after displaying usage? (i think so) */ case 'c': state.config.cols = ((atoi(optarg) - 1) & 0xF) + 1; break; case 'r': state.config.rows = ((atoi(optarg) - 1) & 0xF) + 1; break; case 'p': if( *optarg == '/' ) /* remove the leading slash if there is one */ optarg++; state.config.osc_prefix = strdup(optarg); break; case 'h': if( !is_numstr(optarg) ) usage_printf_exit("error: \"%s\" is not a valid host port.\n\n", optarg); state.config.osc_host_port = strdup(optarg); break; case 'l': if( !is_numstr(optarg) ) usage_printf_exit("error: \"%s\" is not a valid listen port.\n\n", optarg); state.config.osc_listen_port = strdup(optarg); break; } } if( optind == argc ) usage_printf_exit("error: you did not specify a session file!\n\n"); if( rove_settings_load(user_config_path()) ) exit(EXIT_FAILURE); session_file = argv[optind]; state.files = rove_list_new(); state.patterns = rove_list_new(); state.active = rove_list_new(); state.staging = rove_list_new(); printf("\nhey, welcome to rove!\n\n" "you've got the following loops loaded:\n" "\t[rows]\t[file]\n"); if( session_load(session_file) ) { printf("error parsing session file :(\n"); exit(EXIT_FAILURE); } if( rove_list_is_empty(state.files) ) { fprintf(stderr, "\t(none, evidently. get some and come play!)\n\n"); exit(EXIT_FAILURE); } if( rove_jack_init() ) { fprintf(stderr, "error initializing JACK :(\n"); exit(EXIT_FAILURE); } rove_recalculate_bpm_variables(); #define ASSIGN_IF_UNSET(k, v) do { \ if( !k ) \ k = v; \ } while( 0 ); ASSIGN_IF_UNSET(state.config.osc_prefix, DEFAULT_OSC_PREFIX); ASSIGN_IF_UNSET(state.config.osc_host_port, DEFAULT_OSC_HOST_PORT); ASSIGN_IF_UNSET(state.config.osc_listen_port, DEFAULT_OSC_LISTEN_PORT); ASSIGN_IF_UNSET(state.config.cols, DEFAULT_MONOME_COLUMNS); ASSIGN_IF_UNSET(state.config.rows, DEFAULT_MONOME_ROWS); #undef ASSIGN_IF_UNSET if( rove_monome_init() ) exit(EXIT_FAILURE); if( rove_jack_activate() ) exit(EXIT_FAILURE); signal(SIGINT, exit_on_signal); atexit(cleanup); rove_monome_run_thread(state.monome); monome_display_loop(); return 0; }
int main(int argc, char **argv) { int i, retval = SUCCESS; #if defined (HAVE_WORKING_FORK) pid_t cpid; FILE *fscore; #endif #if defined (HAVE_ASSERT_H) && defined (SHORT_PASSWORDS) assert(MAX_PLAIN_SIZE < 16); #endif /* set the default values for `usr_opt' */ memset(&usr_opt, 0, sizeof(usr_opt)); usr_opt.verbose = 1; #if defined (DEV_RANDOM_SUPPORT) usr_opt.cryptopt.get_entropy = get_dev_entropy; #elif defined (EGD_SUPPORT) usr_opt.cryptopt.get_entropy = get_egd_entropy; #else usr_opt.cryptopt.get_entropy = get_sys_entropy; #endif opt_parse(argc, argv, &usr_opt); #if defined (HAVE_UMASK) /* set umask for security reasons */ umask(0077); #endif switch (usr_opt.action) { case crypt_ios: case crypt_pix: if (argc != optind + 1) tty_error(ERR_USAGE, "no string to crypt"); usr_opt.cryptopt.plain = (u_char *) str_alloc_copy(argv[optind]); retval = (usr_opt.action == crypt_ios) ? crypt_ios_fe(usr_opt.cryptopt.plain, usr_opt.cryptopt.salt) : crypt_pix_fe(usr_opt.cryptopt.plain); break; case decrypt_bf: case decrypt_wl: if (argc != optind + 1) tty_error(ERR_USAGE, "no password to decrypt"); usr_opt.decryptopt.cipher = (u_char *) str_alloc_copy(argv[optind]); /* no break here! */ case resume: /* if `decrypt_bf', `decrypt_wl', `resume_bf', `resume_wl', * create the restore file in case of an abort event */ save_session_if_signal_abort = true; if (usr_opt.action == resume) { if (argc != optind) tty_error(ERR_USAGE, "bad argument found `%s'", argv[optind]); session_load(usr_opt.decryptopt.restore_file); /* `usr_opt.decryptopt.regexpr' can be NULL, * so we must check `usr_opt.decryptopt.wordlist' */ usr_opt.action = usr_opt.decryptopt.wordlist ? resume_wl: resume_bf; } #if defined (HAVE_WORKING_FORK) if (usr_opt.daemonize) { cpid = fork(); if (cpid == (pid_t) 0) { /* child process */ /* checks the SCORE_FILE format */ fcheck(SCORE_FILE, HEAD_SCORE_TEXT); /* add the line `HEAD_SCORE_TEXT"\n"' at the begin, * if the file do not exists */ if (!(fscore = fopen(SCORE_FILE, "r"))) { fscore = fopen(SCORE_FILE, "w"); fprintf(fscore, HEAD_SCORE_TEXT"\n"); } fclose(fscore); tty_message ("%s -- running in daemon mode" #if defined (HAVE_GETPID) " [pid: %d]" #endif "...\n** WARNING: " "sensible data could be written in the file `%s'!\n", *argv, #if defined (HAVE_GETPID) (int) getpid(), #endif SCORE_FILE); /* point stdin/stdout/stderr to /dev/null */ for (i = 0; i < 3; i++) close(i); i = open(NULL_DEV, O_RDWR); if (i >= 0) { dup2(i, 0); dup2(i, 1); dup2(i, 2); if (i > 2) close(i); } retval = cisco_decrypt(); return retval; } else if (cpid < (pid_t) 0) tty_error(ERR_FORKING, "cannot run in daemon mode : %s", strerror(errno)); else return SUCCESS; /* parent process */ } else #endif retval = cisco_decrypt(); break; default: /* not enought paramethers entered */ tty_error(ERR_USAGE, "nothing to do (?)"); } mem_free_all(); return retval; }