static void error(char *x) { arch_error(x); printf("\n\n%s\n\n -- System halted", x); while (1) ; /* Halt */ }
int ARCH_MAINDECL main(int argc, char *argv[]) { d64copy_settings *settings = d64copy_get_default_settings(); char *tm = NULL; char *src_arg; char *dst_arg; int c; int rv = 1; int l; int src_is_cbm; int dst_is_cbm; struct option longopts[] = { { "help" , no_argument , NULL, 'h' }, { "version" , no_argument , NULL, 'V' }, { "warp" , no_argument , NULL, 'w' }, { "no-warp" , no_argument , &settings->warp, 0 }, { "quiet" , no_argument , NULL, 'q' }, { "verbose" , no_argument , NULL, 'v' }, { "no-progress", no_argument , NULL, 'n' }, { "interleave" , required_argument, NULL, 'i' }, { "start-track", required_argument, NULL, 's' }, { "end-track" , required_argument, NULL, 'e' }, { "transfer" , required_argument, NULL, 't' }, { "bam-only" , no_argument , NULL, 'b' }, { "bam-save" , no_argument , NULL, 'B' }, { "drive-type" , required_argument, NULL, 'd' }, { "retry-count", required_argument, NULL, 'r' }, { "two-sided" , no_argument , NULL, '2' }, { "error-map" , required_argument, NULL, 'E' }, { NULL , 0 , NULL, 0 } }; const char shortopts[] ="hVwqbBt:i:s:e:d:r:2vnE:"; while((c=getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': help(); return 0; case 'V': printf("d64copy %s\n", OPENCBM_VERSION); return 0; case 'w': settings->warp = 1; break; case 'q': if(verbosity > 0) verbosity--; break; case 'v': verbosity++; break; case 'n': no_progress = 1; break; case 'i': settings->interleave = arch_atoc(optarg); break; case 's': settings->start_track = atoi(optarg); break; case 'e': settings->end_track = atoi(optarg); break; case 't': tm = optarg; break; case 'b': settings->bam_mode = bm_allocated; break; case 'B': settings->bam_mode = bm_save; break; case 'd': if(strcmp(optarg, "1541") == 0) { settings->drive_type = cbm_dt_cbm1541; } else if(strcmp(optarg, "1571") == 0) { settings->drive_type = cbm_dt_cbm1571; } else if(strcmp(optarg, "1570") == 0) { settings->drive_type = cbm_dt_cbm1570; } else { settings->drive_type = atoi(optarg) != 0 ? cbm_dt_cbm1571 : cbm_dt_cbm1541; } break; case 'r': settings->retries = atoi(optarg); break; case '2': settings->two_sided = 1; break; case 'E': l = strlen(optarg); if(strncmp(optarg, "always", l) == 0) { settings->error_mode = em_always; } else if(strncmp(optarg, "on_errors", l) == 0) { settings->error_mode = em_on_error; } else if(strncmp(optarg, "never", l) == 0) { settings->error_mode = em_never; } else { hint(argv[0]); return 1; } break; case 0: break; // needed for --no-warp default : hint(argv[0]); return 1; } } settings->transfer_mode = d64copy_get_transfer_mode_index(tm); if(settings->transfer_mode < 0) { char *modes = d64copy_get_transfer_modes(); char *m; fprintf(stderr, "Unknown transfer mode: %s\nAvailable modes:\n", tm); for(m = modes; *m; m+=(strlen(m)+1)) { fprintf(stderr, " %s\n", m); } free(modes); return 1; } my_message_cb(3, "transfer mode is %d", settings->transfer_mode ); if(optind + 2 != argc) { fprintf(stderr, "Usage: %s [OPTION]... [SOURCE] [TARGET]\n", argv[0]); hint(argv[0]); return 1; } src_arg = argv[optind]; dst_arg = argv[optind+1]; src_is_cbm = is_cbm(src_arg); dst_is_cbm = is_cbm(dst_arg); if(src_is_cbm == dst_is_cbm) { my_message_cb(0, "either source or target must be a CBM drive"); return 1; } if(cbm_driver_open(&fd_cbm, 0) == 0) { /* * If the user specified auto transfer mode, find out * which transfer mode to use. */ settings->transfer_mode = d64copy_check_auto_transfer_mode(fd_cbm, settings->transfer_mode, atoi(src_is_cbm ? src_arg : dst_arg)); my_message_cb(3, "decided to use transfer mode %d", settings->transfer_mode ); signal(SIGINT, reset); if(src_is_cbm) { rv = d64copy_read_image(fd_cbm, settings, atoi(src_arg), dst_arg, my_message_cb, my_status_cb); } else { rv = d64copy_write_image(fd_cbm, settings, src_arg, atoi(dst_arg), my_message_cb, my_status_cb); } if(!no_progress && rv >= 0) { printf("\n%d blocks copied.\n", rv); } cbm_driver_close(fd_cbm); rv = 0; } else { arch_error(0, arch_get_errno(), "%s", cbm_get_driver_name(0)); } free(settings); return rv; }