fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 177 lines 4.2 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/utils/pce-img/create.c * 7 * Created: 2013-01-14 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2013-2018 Hampa Hug <hampa@hampa.ch> * 9 *****************************************************************************/ 10 11/***************************************************************************** 12 * This program is free software. You can redistribute it and / or modify it * 13 * under the terms of the GNU General Public License version 2 as published * 14 * by the Free Software Foundation. * 15 * * 16 * This program is distributed in the hope that it will be useful, but * 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 * Public License for more details. * 20 *****************************************************************************/ 21 22 23#include "pce-img.h" 24 25#include <stdio.h> 26#include <stdlib.h> 27#include <string.h> 28#include <stdint.h> 29 30#include <drivers/block/block.h> 31 32#include <lib/getopt.h> 33 34 35static pce_option_t opts_create[] = { 36 { '?', 0, "help", NULL, "Print usage information" }, 37 { 'c', 1, "cylinders", "int", "Set the number of cylinders [0]" }, 38 { 'C', 1, "min-cluster-size", "int", "Set the minimum cluster size for QED [0]" }, 39 { 'f', 1, "offset", "int", "Set the data offset [0]" }, 40 { 'F', 0, "flat", NULL, "Create a flat pbi file [no]" }, 41 { 'g', 3, "geometry", "3*int", "Set the disk geometry (c h s)" }, 42 { 'h', 1, "heads", "int", "Set the number of heads [0]" }, 43 { 'n', 1, "size", "int", "Set the disk size in 512 byte blocks [0]" }, 44 { 'o', 1, "output", "string", "Set the output file name [stdout]" }, 45 { 'O', 1, "output-type", "string", "Set the output file type [auto]" }, 46 { 'q', 0, "quiet", NULL, "Be quiet [no]" }, 47 { 's', 1, "sectors", "int", "Set the number of sectors per track [0]" }, 48 { 'V', 0, "version", NULL, "Print version information" }, 49 { 'w', 1, "cow", "string", "Add a COW file" }, 50 { -1, 0, NULL, NULL, NULL } 51}; 52 53static 54void print_help (void) 55{ 56 pce_getopt_help ( 57 "pce-img create: Create disk images", 58 "usage: pce-img create [options] [output]", 59 opts_create 60 ); 61 62 fflush (stdout); 63} 64 65int main_create (int argc, char **argv) 66{ 67 int r; 68 char **optarg; 69 disk_t *out; 70 71 out = NULL; 72 73 while (1) { 74 r = pce_getopt (argc, argv, &optarg, opts_create); 75 76 if (r == GETOPT_DONE) { 77 break; 78 } 79 80 if (r < 0) { 81 return (1); 82 } 83 84 switch (r) { 85 case '?': 86 print_help(); 87 return (0); 88 89 case 'V': 90 print_version(); 91 return (0); 92 93 case 'c': 94 if (pce_set_c (optarg[0])) { 95 return (1); 96 } 97 break; 98 99 case 'C': 100 if (pce_set_min_cluster_size (optarg[0])) { 101 return (1); 102 } 103 break; 104 105 case 'f': 106 if (pce_set_ofs (optarg[0])) { 107 return (1); 108 } 109 break; 110 111 case 'F': 112 pce_set_flat (1); 113 break; 114 115 case 'g': 116 if (pce_set_geo (optarg[0], optarg[1], optarg[2])) { 117 return (1); 118 } 119 break; 120 121 case 'h': 122 if (pce_set_h (optarg[0])) { 123 return (1); 124 } 125 break; 126 127 case 'n': 128 if (pce_set_n (optarg[0])) { 129 return (1); 130 } 131 break; 132 133 case 'o': 134 if ((out = dsk_create_out (optarg[0], out)) == NULL) { 135 return (1); 136 } 137 break; 138 139 case 'O': 140 if (pce_set_type_out (optarg[0])) { 141 return (1); 142 } 143 break; 144 145 case 'q': 146 pce_set_quiet (1); 147 break; 148 149 case 's': 150 if (pce_set_s (optarg[0])) { 151 return (1); 152 } 153 break; 154 155 case 'w': 156 if ((out = pce_cow_create (out, optarg[0])) == NULL) { 157 return (1); 158 } 159 break; 160 161 case 0: 162 if ((out = dsk_create_out (optarg[0], out)) == NULL) { 163 return (1); 164 } 165 break; 166 167 default: 168 return (1); 169 } 170 } 171 172 if (out != NULL) { 173 dsk_del (out); 174 } 175 176 return (1); 177}