[Debburn-changes] r316 - in nonameyet/branches/cleanup: . cdrecord
include libdeflt libedc rscsi
Eduard Bloch
blade at costa.debian.org
Fri Sep 15 18:40:45 UTC 2006
Author: blade
Date: 2006-09-15 18:40:45 +0000 (Fri, 15 Sep 2006)
New Revision: 316
Modified:
nonameyet/branches/cleanup/Changelog
nonameyet/branches/cleanup/TODO
nonameyet/branches/cleanup/cdrecord/CMakeLists.txt
nonameyet/branches/cleanup/cdrecord/auinfo.c
nonameyet/branches/cleanup/cdrecord/defaults.c
nonameyet/branches/cleanup/include/deflts.h
nonameyet/branches/cleanup/libdeflt/default.c
nonameyet/branches/cleanup/libedc/CMakeLists.txt
nonameyet/branches/cleanup/rscsi/rscsi.c
Log:
Replaced libdeflt internals with my code, moved the relevant part out of cdrecord/defaults.c and refactored a bit. Changed the interface a bit, replaced the old functions with wrappers
Modified: nonameyet/branches/cleanup/Changelog
===================================================================
--- nonameyet/branches/cleanup/Changelog 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/Changelog 2006-09-15 18:40:45 UTC (rev 316)
@@ -1,3 +1,28 @@
+cdrkit (1.0pre5+cleanup) UNRELEASED; urgency=low
+
+ [ Eduard Bloch ]
+ * replacement of libdeflt and config parser rewrite; more user-friendly,
+ flexibel, tolerant now
+
+ [ Christian Fromme ]
+ * big cleanup, phase I, getting rid from Cstyle function definitions in
+ applications
+
+ -- Eduard Bloch <blade at debian.org> Wed, 6 Sep 2006 22:05:30 +0200
+
+
+
+
+
+
+
+
+
+
+
+
+
+
cdrkit (1.0pre5) UNRELEASED; urgency=low
[ Eduard Bloch ]
@@ -3,6 +28,5 @@
* added better check for capability.h and FATAL_ERROR if it's missing on Linux
* wodim.1 updates, ie. moved suid howto to README.suidroot, Linux bashing to
- README.linux, more notes about non-root usage (corrections by Peter)
- * config parser rewrite; more user-friendly, flexibel, tolerant now
+ README.linux, more notes about non-root usage
* more carefull description of the role of previous developer and his own
project
@@ -17,8 +41,6 @@
headers
[ Christian Fromme ]
- * big cleanup, phase I, getting rid from Cstyle function definitions in
- applications
* detailed review and correction of author related data in manpages and
README files
@@ -27,6 +49,8 @@
-- Eduard Bloch <blade at debian.org> Wed, 6 Sep 2006 22:05:30 +0200
+cdrkit (1.0pre4) RELEASED; urgency=low
+
[ Eduard Bloch ]
* Added checks for libcam to make (k)FreeBSD compilation work (untested)
* added clarifications about changes to all source files
Modified: nonameyet/branches/cleanup/TODO
===================================================================
--- nonameyet/branches/cleanup/TODO 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/TODO 2006-09-15 18:40:45 UTC (rev 316)
@@ -12,6 +12,8 @@
- add better detection for various functions. Eg. correct checks for have_soundcard, have_mlockall for cygwin. (volunteers?)
- see http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=cdrkit and try to solve upstream related problems
- find and eliminate remaining ".mk" ".mk*" files (where? cleanup branch)
+ - make some deflt.h functions inline, use a define wrapper INLINE which is set
+ if the compiler does not support it
- Can we rename the 'cdrecord' directory into 'wodim'?
That may be hard on the build system, this could be the best time to change
it. (No, it isn't hard. Just needs a good moment to settle down everything and
Modified: nonameyet/branches/cleanup/cdrecord/CMakeLists.txt
===================================================================
--- nonameyet/branches/cleanup/cdrecord/CMakeLists.txt 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/cdrecord/CMakeLists.txt 2006-09-15 18:40:45 UTC (rev 316)
@@ -18,7 +18,7 @@
ADD_DEFINITIONS(-DHAVE_LIB_EDC_ECC)
ADD_EXECUTABLE (wodim ${CDRECORD_SRCS})
-TARGET_LINK_LIBRARIES(wodim ${SCG_LIBS} schily deflt libedc ${CAPLINK})
+TARGET_LINK_LIBRARIES(wodim ${SCG_LIBS} schily deflt edc ${CAPLINK})
SET_TARGET_PROPERTIES(wodim PROPERTIES SKIP_BUILD_RPATH TRUE)
INSTALL(TARGETS wodim DESTINATION bin)
Modified: nonameyet/branches/cleanup/cdrecord/auinfo.c
===================================================================
--- nonameyet/branches/cleanup/cdrecord/auinfo.c 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/cdrecord/auinfo.c 2006-09-15 18:40:45 UTC (rev 316)
@@ -107,15 +107,15 @@
if (sb.st_size > 10000) /* Too large for a *.inf file */
return (FALSE);
- if (defltopen(name) < 0) /* Cannot open *.inf file */
+ if (cfg_open(name) < 0) /* Cannot open *.inf file */
return (FALSE);
- tlp = p = readtag("Tracklength=");
+ tlp = p = readtag("Tracklength");
if (p == NULL) { /* Tracklength= Tag not found */
errmsgno(EX_BAD,
"WARNING: %s does not contain a 'Tracklength=' tag.\n",
name);
- defltclose();
+ cfg_close();
return (FALSE);
}
@@ -124,7 +124,7 @@
errmsgno(EX_BAD,
"WARNING: %s: 'Tracklength=' contains illegal parameter '%s'.\n",
name, tlp);
- defltclose();
+ cfg_close();
return (FALSE);
}
if (*p == ',')
@@ -134,7 +134,7 @@
errmsgno(EX_BAD,
"WARNING: %s: 'Tracklength=' contains illegal parameter '%s'.\n",
name, tlp);
- defltclose();
+ cfg_close();
return (FALSE);
}
tracksize = (secs * 2352) + (nsamples * 4);
@@ -143,7 +143,7 @@
name, tracksize, secs, nsamples);
}
trackp->itracksize = tracksize;
- defltclose();
+ cfg_close();
return (TRUE);
}
@@ -165,81 +165,81 @@
strcpy(&p[1], "inf");
}
- if (defltopen(infname) == 0) {
+ if (cfg_open(infname) == 0) {
- p = readtstr("CDINDEX_DISCID=");
- p = readtag("CDDB_DISKID=");
+ p = readtstr("CDINDEX_DISCID");
+ p = readtag("CDDB_DISKID");
- p = readtag("MCN=");
+ p = readtag("MCN");
if (p && *p) {
setmcn(p, &trackp[0]);
txp = gettextptr(0, trackp); /* MCN is isrc for trk 0*/
txp->tc_isrc = savestr(p);
}
- p = readtag("ISRC=");
+ p = readtag("ISRC");
if (p && *p) {
setisrc(p, &trackp[track]);
txp = gettextptr(track, trackp);
txp->tc_isrc = savestr(p);
}
- p = readtstr("Albumperformer=");
+ p = readtstr("Albumperformer");
if (p && *p) {
txp = gettextptr(0, trackp); /* Album perf. in trk 0*/
txp->tc_performer = savestr(p);
}
- p = readtstr("Performer=");
+ p = readtstr("Performer");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_performer = savestr(p);
}
- p = readtstr("Albumtitle=");
+ p = readtstr("Albumtitle");
if (p && *p) {
txp = gettextptr(0, trackp); /* Album title in trk 0*/
txp->tc_title = savestr(p);
}
- p = readtstr("Tracktitle=");
+ p = readtstr("Tracktitle");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_title = savestr(p);
}
- p = readtstr("Songwriter=");
+ p = readtstr("Songwriter");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_songwriter = savestr(p);
}
- p = readtstr("Composer=");
+ p = readtstr("Composer");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_composer = savestr(p);
}
- p = readtstr("Arranger=");
+ p = readtstr("Arranger");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_arranger = savestr(p);
}
- p = readtstr("Message=");
+ p = readtstr("Message");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_message = savestr(p);
}
- p = readtstr("Diskid=");
+ p = readtstr("Diskid");
if (p && *p) {
txp = gettextptr(0, trackp); /* Disk id is in trk 0*/
txp->tc_title = savestr(p);
}
- p = readtstr("Closed_info=");
+ p = readtstr("Closed_info");
if (p && *p) {
txp = gettextptr(track, trackp);
txp->tc_closed_info = savestr(p);
}
- p = readtag("Tracknumber=");
+ p = readtag("Tracknumber");
if (p && isdao)
astol(p, &tno);
- p = readtag("Trackstart=");
+ p = readtag("Trackstart");
if (p && isdao) {
l = -1L;
astol(p, &l);
@@ -249,9 +249,9 @@
}
}
- p = readtag("Tracklength=");
+ p = readtag("Tracklength");
- p = readtag("Pre-emphasis=");
+ p = readtag("Pre-emphasis");
if (p && *p) {
if (strncmp(p, "yes", 3) == 0) {
tp->flags |= TI_PREEMP;
@@ -265,8 +265,8 @@
}
}
- p = readtag("Channels=");
- p = readtag("Copy_permitted=");
+ p = readtag("Channels");
+ p = readtag("Copy_permitted");
if (p && *p) {
/*
* -useinfo always wins
@@ -280,12 +280,12 @@
else if (strncmp(p, "once", 2) == 0)
tp->flags &= ~(TI_COPY|TI_SCMS);
}
- p = readtag("Endianess=");
- p = readtag("Index=");
+ p = readtag("Endianess");
+ p = readtag("Index");
if (p && *p && isdao)
setindex(p, &trackp[track]);
- p = readtag("Index0=");
+ p = readtag("Index0");
if (p && isdao) {
Llong ts;
Llong ps;
@@ -339,14 +339,10 @@
{
register char *p;
- p = defltread(name);
- if (p) {
- while (*p == ' ' || *p == '\t')
- p++;
- if (debug)
- printf("%s '%s'\n", name, p);
- }
- return (p);
+ p = cfg_get(name);
+ if (debug)
+ printf("%s '%s'\n", name, p);
+ return (p);
}
static char *
Modified: nonameyet/branches/cleanup/cdrecord/defaults.c
===================================================================
--- nonameyet/branches/cleanup/cdrecord/defaults.c 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/cdrecord/defaults.c 2006-09-15 18:40:45 UTC (rev 316)
@@ -25,7 +25,7 @@
#include <mconfig.h>
#include <stdlib.h>
#include <stdio.h>
-#include "defaults.h"
+#include <deflts.h>
#include <ctype.h>
#include <string.h>
@@ -33,130 +33,23 @@
/* The better way would be exporting the meta functions to getnum.h or so */
extern int getnum (char *arg, long *valp);
-enum parstate {
- KEYBEGINSEARCH,
- KEYCOMPARE,
- EQSIGNSEARCH,
- VALBEGINSEARCH,
- LASTCHARSEARCH
-};
-#define GETVAL_BUF_LEN 256
-#define isUspace(x) isspace( (int) (unsigned char) x)
-
-/*
- * Warning, uses static line buffer, not reentrant. NULL returned if the key isn't found.
- */
-static char *get_value(FILE *srcfile, char *key) {
- static char linebuf[GETVAL_BUF_LEN];
-
- if(!srcfile)
- return NULL;
-
- rewind(srcfile);
-next_line:
- while(fgets(linebuf, sizeof(linebuf)-1, srcfile)) {
- int i;
- int keybeg;
- int s=KEYBEGINSEARCH;
- char *ret=NULL;
- int lastchar=0;
-
- /* simple state machine, char position moved by the states (or not),
- * state change is done by the state (or not) */
- for( i=0 ; i<sizeof(linebuf) ; ) {
- /* printf("key: %s, %s, s: %d\n", key, linebuf, s); */
- switch(s) {
- case(KEYBEGINSEARCH):
- {
- if(isUspace(linebuf[i]))
- i++;
- else if(linebuf[i] == '#' || linebuf[i]=='\0')
- goto next_line;
- else {
- s=KEYCOMPARE;
- keybeg=i;
- }
- }
- break;
- case(KEYCOMPARE): /* compare the key */
- {
- if(key[i-keybeg]=='\0')
- /* end of key, next state decides what to do on this position */
- s=EQSIGNSEARCH;
- else {
- if(linebuf[i-keybeg]!=key[i-keybeg])
- goto next_line;
- else
- i++;
- }
- }
- break;
- case(EQSIGNSEARCH): /* skip whitespace, stop on =, break on anything else */
- {
- if(isUspace(linebuf[i]))
- i++;
- else if(linebuf[i]=='=') {
- s=VALBEGINSEARCH;
- i++;
- }
- else
- goto next_line;
- }
- break;
- case(VALBEGINSEARCH):
- {
- if(isUspace(linebuf[i]))
- i++;
- else {
- /* possible at EOF */
- if(linebuf[i] == '\0')
- return NULL;
-
- lastchar=i-1; /* lastchar can be a space, see below */
- ret= & linebuf[i];
- s=LASTCHARSEARCH;
- }
- }
- break;
- case(LASTCHARSEARCH):
- {
- if(linebuf[i]) {
- if(!isUspace(linebuf[i]))
- lastchar=i;
- }
- else { /* got string end, terminate after the last seen char */
- if(linebuf+lastchar < ret) /* no non-space found */
- return NULL;
- linebuf[lastchar+1]='\0';
- return ret;
- }
- i++;
- }
- break;
- }
- }
- }
- return NULL;
-}
-
-void
-cdr_defaults(char **p_dev_name, int *p_speed, long *p_fifosize, char **p_drv_opts) {
+void cdr_defaults(char **p_dev_name, int *p_speed, long *p_fifosize, char **p_drv_opts) {
FILE *stream;
char *t; /* tmp */
int wc=0;
char loc[256], sSpeed[11], sFs[11], sOpts[81];
char *devcand=NULL;
- stream=fopen(CFGPATH, "r");
+ cfg_open(CFGPATH);
if(p_dev_name && *p_dev_name)
devcand=*p_dev_name;
else if(NULL!=(t=getenv("CDR_DEVICE")))
devcand=t;
- else if(NULL!=(t=get_value(stream, "CDR_DEVICE")))
+ else if(NULL!=(t=cfg_get("CDR_DEVICE")))
devcand=strdup(t); // needs to use it as a key later, same stat. memory
- if(devcand && NULL != (t=get_value(stream,devcand))) {
+ if(devcand && NULL != (t=cfg_get(devcand))) {
/* extract them now, may be used later */
wc=sscanf(t, "%255s %10s %10s %80s", loc, sSpeed, sFs, sOpts);
}
@@ -172,7 +65,7 @@
int cfg_speed=-1;
/* that value may be used twice */
- if(NULL!=(t=get_value(stream, "CDR_SPEED"))) {
+ if(NULL!=(t=cfg_get("CDR_SPEED"))) {
cfg_speed=strtol(t,&bad,10);
if(*bad || cfg_speed<-1) {
fprintf(stderr, "Bad default CDR_SPEED setting (%s).\n", t);
@@ -219,7 +112,7 @@
exit(EXIT_FAILURE);
}
}
- else if(NULL!=(t=get_value(stream, "CDR_FIFOSIZE"))) {
+ else if(NULL!=(t=cfg_get("CDR_FIFOSIZE"))) {
if(getnum(t, p_fifosize)!=1 || *p_fifosize<-1) {
fprintf(stderr, "Bad speed default setting (%s).\n", t);
exit(EXIT_FAILURE);
@@ -228,7 +121,7 @@
/* undocumented option. Most likely to prevent killing Schily's
* underpowered machines (see docs) by allocating too much memory after
* doing a mistake in the config. */
- if(NULL!=(t=get_value(stream, "CDR_MAXFIFOSIZE"))) {
+ if(NULL!=(t=cfg_get("CDR_MAXFIFOSIZE"))) {
long max;
if(getnum(t, &max)!=1 || *p_fifosize<-1) {
fprintf(stderr, "Bad CDR_MAXFIFOSIZE setting (%s).\n", t);
@@ -242,7 +135,6 @@
if(p_drv_opts && !*p_drv_opts && wc>3 && strcmp(sOpts, "\"\""))
*p_drv_opts=strdup(sOpts);
- if(stream != (FILE*)NULL)
- fclose(stream);
+ cfg_close();
}
Modified: nonameyet/branches/cleanup/include/deflts.h
===================================================================
--- nonameyet/branches/cleanup/include/deflts.h 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/include/deflts.h 2006-09-15 18:40:45 UTC (rev 316)
@@ -1,22 +1,14 @@
/*
- * This file has been modified for the cdrkit suite.
+ * Copyright (c) 2006 Eduard Bloch
*
- * The behaviour and appearence of the program code below can differ to a major
- * extent from the version distributed by the original author(s).
+ * Config parsing code, with interface similar to basic libdeflt interface
+ * from J. Schilling but with different semantics
*
- * For details, see Changelog file distributed with the cdrkit package. If you
- * received this file from another source then ask the distributing person for
- * a log of modifications.
+ * get_value uses a static buffer (warning, non-reentrant)
+ * cfg_open and cfg_close maintain a static FILE pointer (warning, non-reentrant)
*
*/
-
-/* @(#)deflts.h 1.6 02/08/26 Copyright 1997 J. Schilling */
/*
- * Definitions for reading program defaults.
- *
- * Copyright (c) 1997 J. Schilling
- */
-/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
@@ -34,54 +26,25 @@
#ifndef _DEFLTS_H
#define _DEFLTS_H
-#ifndef _MCONFIG_H
-#include <mconfig.h>
-#endif
-#ifndef _PROTOTYP_H
-#include <prototyp.h>
-#endif
-
#ifdef __cplusplus
extern "C" {
#endif
-#define DEFLT "/etc/default"
+/* FIXME: use inline trough an INLINE macro wrapper */
+extern int cfg_open (const char *name);
+extern int cfg_close (void);
-/*
- * cmd's to defltcntl()
- */
-#define DC_GETFLAGS 0 /* Get actual flags */
-#define DC_SETFLAGS 1 /* Set new flags */
+/* reset the position in FILE */
+extern void cfg_restart (void);
+/* returns the next value found after the current position */
+extern char *cfg_get_next (const char *name);
+/* equivalent to cfg_restart(); cfg_get_next(...) */
+extern char *cfg_get(const char *key);
+/* function wrapped by those above */
+extern char *get_value(FILE *srcfile, const char *key, int dorewind);
-/*
- * flags to defltcntl()
- *
- * Make sure that when adding features, the default behaviour
- * is the same as old behaviour.
- */
-#define DC_CASE 0x0001 /* Don't ignore case */
-
-#define DC_STD DC_CASE /* Default flags */
-
-/*
- * Macros to handle flags
- */
-#ifndef TURNON
-#define TURNON(flags, mask) flags |= mask
-#define TURNOFF(flags, mask) flags &= ~(mask)
-#define ISON(flags, mask) (((flags) & (mask)) == (mask))
-#define ISOFF(flags, mask) (((flags) & (mask)) != (mask))
-#endif
-
-extern int defltopen __PR((const char *name));
-extern int defltclose __PR((void));
-extern void defltfirst __PR((void));
-extern char *defltread __PR((const char *name));
-extern char *defltnext __PR((const char *name));
-extern int defltcntl __PR((int cmd, int flags));
-
#ifdef __cplusplus
}
#endif
-#endif /* _DEFLTS_H */
+#endif
Modified: nonameyet/branches/cleanup/libdeflt/default.c
===================================================================
--- nonameyet/branches/cleanup/libdeflt/default.c 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/libdeflt/default.c 2006-09-15 18:40:45 UTC (rev 316)
@@ -1,24 +1,10 @@
-/*
- * This file has been modified for the cdrkit suite.
+/*
+ * Copyright 2006 Eduard Bloch
*
- * The behaviour and appearence of the program code below can differ to a major
- * extent from the version distributed by the original author(s).
+ * Uses my config parser code and small wrappers to provide the old interface.
*
- * For details, see Changelog file distributed with the cdrkit package. If you
- * received this file from another source then ask the distributing person for
- * a log of modifications.
- *
*/
-
-/* @(#)default.c 1.5 04/09/04 Copyright 1997 J. Schilling */
-#ifndef lint
-static char sccsid[] =
- "@(#)default.c 1.5 04/09/04 Copyright 1997 J. Schilling";
-#endif
/*
- * Copyright (c) 1997 J. Schilling
- */
-/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
@@ -34,96 +20,160 @@
*/
#include <mconfig.h>
-#include <standard.h>
+#include <stdlib.h>
#include <stdio.h>
-#include <strdefs.h>
-#include <deflts.h>
+#include <ctype.h>
+#include <string.h>
-#define MAXLINE 512
+enum parstate {
+ KEYBEGINSEARCH,
+ KEYCOMPARE,
+ EQSIGNSEARCH,
+ VALBEGINSEARCH,
+ LASTCHARSEARCH
+};
-static FILE *dfltfile = (FILE *)NULL;
+#define GETVAL_BUF_LEN 512
+#define isUspace(x) isspace( (int) (unsigned char) x)
-int defltopen __PR((const char *name));
-int defltclose __PR((void));
-void defltfirst __PR((void));
-char *defltread __PR((const char *name));
-char *defltnext __PR((const char *name));
-int defltcntl __PR((int cmd, int flags));
+static FILE *glob_cfg_ptr = NULL;
-int defltopen(const char *name)
-{
- if (dfltfile != (FILE *)NULL)
- fclose(dfltfile);
+/*
+ * Warning, uses static line buffer, not reentrant. NULL returned if the key isn't found.
+ */
+static char *get_value(FILE *srcfile, const char *key, int dorewind) {
+ static char linebuf[GETVAL_BUF_LEN];
- if (name == (char *)NULL) {
- fclose(dfltfile);
- dfltfile = NULL;
- return (0);
- }
+ if(!srcfile)
+ return ((char *) NULL);
- if ((dfltfile = fopen(name, "r")) == (FILE *)NULL) {
- return (-1);
+ if(dorewind)
+ rewind(srcfile);
+
+ if(!key)
+ return NULL;
+
+next_line:
+ while(fgets(linebuf, sizeof(linebuf)-1, srcfile)) {
+ int i;
+ int keybeg;
+ int s=KEYBEGINSEARCH;
+ char *ret=NULL;
+ int lastchar=0;
+
+ /* simple state machine, char position moved by the states (or not),
+ * state change is done by the state (or not) */
+ for( i=0 ; i<sizeof(linebuf) ; ) {
+ /* printf("key: %s, %s, s: %d\n", key, linebuf, s); */
+ switch(s) {
+ case(KEYBEGINSEARCH):
+ {
+ if(isUspace(linebuf[i]))
+ i++;
+ else if(linebuf[i] == '#' || linebuf[i]=='\0')
+ goto next_line;
+ else {
+ s=KEYCOMPARE;
+ keybeg=i;
+ }
+ }
+ break;
+ case(KEYCOMPARE): /* compare the key */
+ {
+ if(key[i-keybeg]=='\0')
+ /* end of key, next state decides what to do on this position */
+ s=EQSIGNSEARCH;
+ else {
+ if(linebuf[i-keybeg]!=key[i-keybeg])
+ goto next_line;
+ else
+ i++;
+ }
+ }
+ break;
+ case(EQSIGNSEARCH): /* skip whitespace, stop on =, break on anything else */
+ {
+ if(isUspace(linebuf[i]))
+ i++;
+ else if(linebuf[i]=='=') {
+ s=VALBEGINSEARCH;
+ i++;
+ }
+ else
+ goto next_line;
+ }
+ break;
+ case(VALBEGINSEARCH):
+ {
+ if(isUspace(linebuf[i]))
+ i++;
+ else {
+ /* possible at EOF */
+ if(linebuf[i] == '\0')
+ return NULL;
+
+ lastchar=i-1; /* lastchar can be a space, see below */
+ ret= & linebuf[i];
+ s=LASTCHARSEARCH;
+ }
+ }
+ break;
+ case(LASTCHARSEARCH):
+ {
+ if(linebuf[i]) {
+ if(!isUspace(linebuf[i]))
+ lastchar=i;
+ }
+ else { /* got string end, terminate after the last seen char */
+ if(linebuf+lastchar < ret) /* no non-space found */
+ return NULL;
+ linebuf[lastchar+1]='\0';
+ return ret;
+ }
+ i++;
+ }
+ break;
+ }
+ }
}
- return (0);
+ return NULL;
}
-int defltclose()
+int cfg_open(const char *name)
{
- int ret;
-
- if (dfltfile != (FILE *)NULL) {
- ret = fclose(dfltfile);
- dfltfile = NULL;
- return (ret);
+ if(glob_cfg_ptr) {
+ fclose(glob_cfg_ptr);
+ glob_cfg_ptr=NULL;
}
- return (0);
+ if(!name) {
+ glob_cfg_ptr=NULL;
+ return 0;
+ }
+ glob_cfg_ptr = fopen(name, "r");
+ return (glob_cfg_ptr ? 0 : -1);
}
-void defltfirst()
+int cfg_close()
{
- if (dfltfile == (FILE *)NULL) {
- return;
- }
- rewind(dfltfile);
+ int r;
+ if(!glob_cfg_ptr)
+ return 0;
+ r=fclose(glob_cfg_ptr);
+ glob_cfg_ptr=NULL;
+ return r;
}
-char *defltread(const char *name)
+void cfg_restart()
{
- if (dfltfile == (FILE *)NULL) {
- return ((char *)NULL);
- }
- rewind(dfltfile);
- return (defltnext(name));
+ get_value(glob_cfg_ptr, NULL, 1);
}
-char *defltnext(const char *name)
+char *cfg_get(const char *key)
{
- register int len;
- register int namelen;
- static char buf[MAXLINE];
-
- if (dfltfile == (FILE *)NULL) {
- return ((char *)NULL);
- }
- namelen = strlen(name);
-
- while (fgets(buf, sizeof (buf), dfltfile)) {
- len = strlen(buf);
- if (buf[len-1] == '\n') {
- buf[len-1] = 0;
- } else {
- return ((char *)NULL);
- }
- if (strncmp(name, buf, namelen) == 0) {
- return (&buf[namelen]);
- }
- }
- return ((char *)NULL);
+ return get_value(glob_cfg_ptr, key, 1);
}
-int defltcntl(int cmd, int flags)
+char *cfg_get_next(const char *key)
{
- int oldflags = 0;
-
- return (oldflags);
+ return get_value(glob_cfg_ptr, key, 0);
}
Modified: nonameyet/branches/cleanup/libedc/CMakeLists.txt
===================================================================
--- nonameyet/branches/cleanup/libedc/CMakeLists.txt 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/libedc/CMakeLists.txt 2006-09-15 18:40:45 UTC (rev 316)
@@ -3,4 +3,4 @@
AUX_SOURCE_DIRECTORY(. LIBEDC_SRCS)
-ADD_LIBRARY (libedc STATIC ${LIBEDC_SRCS})
+ADD_LIBRARY (edc STATIC ${LIBEDC_SRCS})
Modified: nonameyet/branches/cleanup/rscsi/rscsi.c
===================================================================
--- nonameyet/branches/cleanup/rscsi/rscsi.c 2006-09-15 14:38:36 UTC (rev 315)
+++ nonameyet/branches/cleanup/rscsi/rscsi.c 2006-09-15 18:40:45 UTC (rev 316)
@@ -154,13 +154,13 @@
* don't contribute work and don't give support, they are causing extra
* work for me and this way slow down the development.
*/
- if (defltopen("/etc/default/rscsi") < 0) {
+ if (cfg_open("/etc/default/rscsi") < 0) {
rscsierror(geterrno(), errmsgstr(geterrno()),
"Remote configuration error: Cannot open /etc/default/rscsi");
/* rscsirespond(-1, geterrno());*/
exit(EX_BAD);
}
- debug_name=defltread("DEBUG=");
+ debug_name=cfg_get("DEBUG");
#ifdef FORCE_DEBUG
if (debug_name == NULL && argc <= 0)
debug_name = "/tmp/RSCSI";
@@ -228,8 +228,8 @@
username = pw->pw_name;
DEBUG2("rscsid: user id %ld, name %s\n", (long)uid, username);
- defltfirst();
- while ((uname = defltnext("USER=")) != NULL) {
+ cfg_restart();
+ while ((uname = cfg_get_next("USER")) != NULL) {
if (strmatch(username, uname))
return;
}
@@ -346,8 +346,8 @@
if (peername == NULL)
return (FALSE);
- defltfirst();
- while ((target = defltnext("ACCESS=")) != NULL) {
+ cfg_restart();
+ while ((target = cfg_get_next("ACCESS")) != NULL) {
p = target;
while (*p == '\t')
p++;
More information about the Debburn-changes
mailing list