2 * Copyright 2006 Eduard Bloch
4 * This code emulates the interface of the original defaults.c file. However,
5 * it improves its behaviour and deals with corner cases: prepended and
6 * trailing spaces on variable and value, no requirement for using TABs
7 * anymore. No requirements to insert dummy values like -1 or "".
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along with
21 * this program; see the file COPYING. If not, write to the Free Software
22 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #define CFGPATH "/etc/wodim.conf"
33 /* The better way would be exporting the meta functions to getnum.h or so */
34 extern int getnum(char *arg, long *valp);
37 cdr_defaults(char **p_dev_name, int *p_speed, long *p_fifosize,
42 char loc[256], sSpeed[11], sFs[11], sOpts[81];
47 if(p_dev_name && *p_dev_name)
49 else if(NULL!=(t=getenv("CDR_DEVICE")))
51 else if(NULL!=(t=cfg_get("CDR_DEVICE")))
52 devcand=strdup(t); /* needs to use it as a key later, same stat. memory */
54 if(devcand && NULL != (t=cfg_get(devcand))) {
55 /* extract them now, may be used later */
56 wc=sscanf(t, "%255s %10s %10s %80s", loc, sSpeed, sFs, sOpts);
61 *p_dev_name = strdup(loc);
62 else if(devcand) /* small mem. leak possible, does not matter, checks for that would require more code size than we loose */
63 *p_dev_name=strdup(devcand);
65 if(p_speed) { /* sth. to write back */
69 /* that value may be used twice */
70 if(NULL!=(t=cfg_get("CDR_SPEED"))) {
71 cfg_speed=strtol(t,&bad,10);
72 if(*bad || cfg_speed<-1) {
73 fprintf(stderr, "Bad default CDR_SPEED setting (%s).\n", t);
79 /* ok, already set by the program arguments */
81 else if(NULL!=(t=getenv("CDR_SPEED"))) {
82 *p_speed=strtol(t,&bad,10);
83 if(*bad || *p_speed<-1) {
84 fprintf(stderr, "Bad CDR_SPEED environment (%s).\n", t);
88 else if(wc>1 && *sSpeed) {
89 *p_speed=strtol(sSpeed, &bad, 10);
90 if(*bad || *p_speed<-1) {
91 fprintf(stderr, "Bad speed (%s) in the config, drive description.\n", sSpeed);
95 /* that's autodetect, use the config default as last ressort */
101 if(p_fifosize) { /* sth. to write back */
103 /* ok, already set by the user */
105 else if(NULL!=(t=getenv("CDR_FIFOSIZE"))) {
106 if(getnum(t, p_fifosize)!=1 || *p_fifosize<-1) {
107 fprintf(stderr, "Bad CDR_FIFOSIZE environment (%s).\n", t);
111 else if(wc>2 && *sFs && strcmp("-1", sFs)) {
112 if(getnum(sFs, p_fifosize)!=1 || *p_fifosize<-1) {
113 fprintf(stderr, "Bad fifo size (%s) in the config, device description.\n", sFs);
117 else if(NULL!=(t=cfg_get("CDR_FIFOSIZE"))) {
118 if(getnum(t, p_fifosize)!=1 || *p_fifosize<-1) {
119 fprintf(stderr, "Bad speed default setting (%s).\n", t);
123 if(NULL!=(t=cfg_get("CDR_MAXFIFOSIZE"))) {
125 if(getnum(t, &max)!=1 || *p_fifosize<-1) {
126 fprintf(stderr, "Bad CDR_MAXFIFOSIZE setting (%s).\n", t);
134 if(p_drv_opts && !*p_drv_opts && wc>3 && strcmp(sOpts, "\"\""))
135 *p_drv_opts=strdup(sOpts);