fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/utils/pce-img/commit.c *
7 * Created: 2013-01-13 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 <config.h>
24
25#include "pce-img.h"
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <stdint.h>
31
32#include <drivers/block/block.h>
33
34#include <lib/getopt.h>
35
36
37static pce_option_t opts_commit[] = {
38 { '?', 0, "help", NULL, "Print usage information" },
39 { 'i', 1, "input", "string", "Set the input file name [none]" },
40 { 'I', 1, "input-type", "string", "Set the input file type [auto]" },
41 { 'q', 0, "quiet", NULL, "Be quiet [no]" },
42 { 'V', 0, "version", NULL, "Print version information" },
43 { 'w', 1, "cow", "string", "Add a COW file [none]" },
44 { -1, 0, NULL, NULL, NULL }
45};
46
47
48static
49void print_help (void)
50{
51 pce_getopt_help (
52 "pce-img commit: commit changes",
53 "usage: pce-img commit [options] [image] [cow...]",
54 opts_commit
55 );
56
57 fflush (stdout);
58}
59
60int main_commit (int argc, char **argv)
61{
62 int r;
63 char **optarg;
64 disk_t *inp;
65
66 inp = NULL;
67
68 while (1) {
69 r = pce_getopt (argc, argv, &optarg, opts_commit);
70
71 if (r == GETOPT_DONE) {
72 break;
73 }
74
75 if (r < 0) {
76 return (1);
77 }
78
79 switch (r) {
80 case '?':
81 print_help();
82 return (0);
83
84 case 'V':
85 print_version();
86 return (0);
87
88 case 'i':
89 if ((inp = dsk_open_inp (optarg[0], inp, 0)) == NULL) {
90 return (1);
91 }
92 break;
93
94 case 'I':
95 if (pce_set_type_inp (optarg[0])) {
96 return (1);
97 }
98 break;
99
100 case 'q':
101 pce_set_quiet (1);
102 break;
103
104 case 'w':
105 if ((inp = pce_cow_open (inp, optarg[0])) == NULL) {
106 return (1);
107 }
108 break;
109
110 case 0:
111 if (inp == NULL) {
112 if ((inp = dsk_open_inp (optarg[0], inp, 0)) == NULL) {
113 return (1);
114 }
115 }
116 else {
117 if ((inp = pce_cow_open (inp, optarg[0])) == NULL) {
118 return (1);
119 }
120 }
121 break;
122
123 default:
124 return (1);
125 }
126 }
127
128 if (inp == NULL) {
129 return (0);
130 }
131
132 if (dsk_commit (inp)) {
133 fprintf (stderr, "%s: commit failed\n", arg0);
134 return (1);
135 }
136
137 dsk_del (inp);
138
139 return (0);
140}