udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
options.c
Go to the documentation of this file.
1 /*
2 * options.c
3 *
4 * Copyright (c) 2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu>
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23 #include "config.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28
29 #include "cdrwtool.h"
30 #include "libudffs.h"
31 #include "options.h"
32
33 struct option long_options[] = {
34 { "help", no_argument, NULL, OPT_HELP },
35 { "device", 1, NULL, 'd' },
36 { "set write parameters", no_argument, NULL, 's' },
37 { "get write parameters", no_argument, NULL, 'g' },
38 { "blank cdrw disc", 1, NULL, 'b' },
39 { "format cdrw disc", 1,NULL, 'm' },
40 { "run mkudffs on track", 1, NULL, 'u' },
41 { "set mkudffs version", 1, NULL, 'v' },
42 { "set cd writing speed", 1, NULL, 't' },
43 { "write fixed packets", 1, NULL, 'p' },
44 { "perform quick setup", optional_argument, NULL, 'q' },
45 { "reserve track", 1, NULL, 'r' },
46 { "close track", 1, NULL, 'c' },
47 { "fixed packet size", 1, NULL, 'z' },
48 { "border/session setting", 1, NULL, 'l' },
49 { "write type", 1, NULL, 'w' },
50 { "file to write", 1, NULL, 'f' },
51 { "start at this lba for file write", 1, NULL,'o' },
52 { "print detailed disc info", no_argument, NULL, 'i' },
53 { 0, 0, NULL, 0 },
54 };
55
56 void usage(void)
57 {
58 int i;
59
60 printf("cdrwtool from " PACKAGE_NAME " " PACKAGE_VERSION "\nUsage:\n\tcdrwtool [options]\nOptions:\n");
61 for (i = 0; long_options[i].name != NULL; i++)
62 if (long_options[i].val >= 0xFF)
63 printf("\t--%s\t%s\n", long_options[i].name, long_options[i].name);
64 else
65 printf("\t-%c\t%s\n", long_options[i].val, long_options[i].name);
66 exit(1);
67 }
68
69 void parse_args(int argc, char *argv[], struct cdrw_disc *disc, char *device)
70 {
71 int retval;
72
73 while ((retval = getopt_long(argc, argv, "r:t:im:u:v:d:sgq::c:C:b:p:z:l:w:f:o:h", long_options, NULL)) != EOF)
74 {
75 switch (retval)
76 {
77 case OPT_HELP:
78 case 'h':
79 usage();
80 break;
81 case 'c':
82 {
83 disc->close_track = strtol(optarg, NULL, 10);
84 break;
85 }
86 case 'C':
87 {
88 disc->close_session = strtol(optarg, NULL, 10);
89 break;
90 }
91 case 'q':
92 {
93 disc->quick_setup = 1;
94 if (optarg)
95 disc->offset = strtol(optarg, NULL, 10);
96 else
97 disc->offset = 0;
98 break;
99 }
100 case 'u':
101 {
102 disc->mkudf = 1;
103 disc->offset = strtol(optarg, NULL, 10);
104 printf("mkudffs %lu blocks\n", disc->offset);
105 break;
106 }
107 case 'v':
108 {
109 if (udf_set_version(&disc->udf_disc, strtol(optarg, NULL, 16)))
110 exit(1);
111 printf("udf version set to 0x%04x\n", disc->udf_disc.udf_rev);
112 break;
113 }
114 case 'r':
115 {
116 disc->reserve_track = strtol(optarg, NULL, 10);
117 printf("reserving track %u\n", disc->reserve_track);
118 break;
119 }
120 case 't':
121 {
122 disc->speed = strtol(optarg, NULL, 10);
123 printf("setting speed to %d\n", disc->speed);
124 break;
125 }
126 case 'm':
127 {
128 disc->format = 1;
129 disc->offset = strtol(optarg, NULL, 10);
130 printf("formatting %lu blocks\n", disc->offset);
131 break;
132 }
133 case 'i':
134 {
135 disc->disc_track_info = 1;
136 break;
137 }
138 case 'd':
139 {
140 strncpy(device, optarg, NAME_MAX-1);
141 device[NAME_MAX-1] = '\0';
142 printf("using device %s\n", device);
143 break;
144 }
145 case 'g':
146 {
147 printf("ok, want to get\n");
148 disc->get_settings = 1;
149 break;
150 }
151 case 's':
152 {
153 printf("ok, want to set\n");
154 disc->set_settings = 1;
155 break;
156 }
157 case 'b':
158 {
159 if (!strcmp("full", optarg))
160 {
161 printf("full blank\n");
162 disc->blank = BLANK_FULL;
163 }
164 else if (!strcmp("fast", optarg))
165 {
166 printf("fast blank\n");
167 disc->blank = BLANK_FAST;
168 }
169 else
170 {
171 printf("full or fast blanking only\n");
172 exit(1);
173 }
174 break;
175 }
176 case 'p':
177 {
178 disc->fpacket = !!strtol(optarg, NULL, 10);
179 printf("%s packets\n", disc->fpacket?"fixed":"variable");
180 break;
181 }
182 case 'z':
183 {
184 disc->packet_size = strtol(optarg, NULL, 10);
185 printf("packet size: %d\n", disc->packet_size);
186 break;
187 }
188 case 'l':
189 {
190 disc->border = strtol(optarg, NULL, 10);
191 printf("border type: %d\n", disc->border);
192 break;
193 }
194 case 'w':
195 {
196 if (!strcmp("mode1", optarg))
197 {
198 printf("mode1\n");
199 disc->write_type = 1;
200 }
201 else if (!strcmp("mode2", optarg))
202 {
203 printf("mode2\n");
204 disc->write_type = 2;
205 }
206 else
207 {
208 fprintf(stderr, "mode1 or mode2 writing only\n");
209 exit(1);
210 }
211 break;
212 }
213 case 'f':
214 {
215 strncpy(disc->filename, optarg, NAME_MAX-1);
216 disc->filename[NAME_MAX-1] = '\0';
217 printf("write file %s\n", disc->filename);
218 break;
219 }
220 case 'o':
221 {
222 disc->offset = strtoul(optarg, NULL, 10);
223 printf("write offset %lu\n", disc->offset);
224 break;
225 }
226 }
227 }
228
229 if (optind < argc)
230 usage();
231 }
device
int device
Definition: wrudf.c:18
cdrw_disc::border
unsigned char border
Definition: cdrwtool.h:87
cdrw_disc::get_settings
unsigned char get_settings
Definition: cdrwtool.h:78
cdrw_disc
Definition: cdrwtool.h:74
options.h
cdrw_disc::udf_disc
struct udf_disc udf_disc
Definition: cdrwtool.h:95
NAME_MAX
#define NAME_MAX
Definition: cdrwtool.h:57
cdrw_disc::quick_setup
unsigned char quick_setup
Definition: cdrwtool.h:91
cdrw_disc::reserve_track
unsigned int reserve_track
Definition: cdrwtool.h:90
cdrw_disc::close_session
unsigned int close_session
Definition: cdrwtool.h:94
cdrw_disc::offset
unsigned long offset
Definition: cdrwtool.h:77
cdrw_disc::close_track
unsigned int close_track
Definition: cdrwtool.h:93
cdrw_disc::blank
unsigned char blank
Definition: cdrwtool.h:80
cdrw_disc::packet_size
unsigned char packet_size
Definition: cdrwtool.h:82
cdrw_disc::speed
unsigned char speed
Definition: cdrwtool.h:88
cdrw_disc::filename
char filename[NAME_MAX]
Definition: cdrwtool.h:76
cdrw_disc::write_type
unsigned char write_type
Definition: cdrwtool.h:84
cdrw_disc::format
unsigned char format
Definition: cdrwtool.h:86
BLANK_FAST
#define BLANK_FAST
Definition: cdrwtool.h:47
udf_set_version
int udf_set_version(struct udf_disc *, int)
Definition: mkudffs.c:152
cdrw_disc::disc_track_info
unsigned char disc_track_info
Definition: cdrwtool.h:85
long_options
struct option long_options[]
Definition: options.c:33
cdrw_disc::fpacket
unsigned char fpacket
Definition: cdrwtool.h:81
parse_args
void parse_args(int argc, char *argv[], struct cdrw_disc *disc, char *device)
Definition: options.c:69
OPT_HELP
#define OPT_HELP
Definition: options.h:38
usage
void usage(void)
Definition: options.c:56
libudffs.h
udf_disc::udf_rev
uint16_t udf_rev
Definition: libudffs.h:97
BLANK_FULL
#define BLANK_FULL
Definition: cdrwtool.h:46
cdrwtool.h
cdrw_disc::mkudf
unsigned char mkudf
Definition: cdrwtool.h:92
cdrw_disc::set_settings
unsigned char set_settings
Definition: cdrwtool.h:79