Use properties code.

This commit is contained in:
jkh 1998-10-14 11:23:48 +00:00
parent 58669a215c
commit 8104dd7dfb
11 changed files with 70 additions and 305 deletions

View File

@ -9,7 +9,7 @@ CLEANFILES+= keymap.tmp keymap.h
.PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum
SRCS= anonFTP.c attr.c cdrom.c command.c config.c devices.c \
SRCS= anonFTP.c cdrom.c command.c config.c devices.c \
disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c \
ftp.c globals.c index.c install.c installUpgrade.c keymap.c \
label.c lndir.c main.c makedevs.c media.c menus.c misc.c mouse.c \

View File

@ -1,218 +0,0 @@
/*
* The new sysinstall program.
*
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: attr.c,v 1.17 1997/04/02 12:07:21 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
* Copyright (c) 1995
* Gary J Palmer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* verbatim and that no modifications are made prior to this
* point in the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR THEIR PETS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "sysinstall.h"
#include <ctype.h>
#include <sys/errno.h>
int
attr_parse_file(Attribs *attr, char *file)
{
int status;
FILE *fp;
if ((fp = fopen(file, "r")) == NULL) {
msgConfirm("Cannot open the information file `%s': %s (%d)", file, strerror(errno), errno);
return DITEM_FAILURE;
}
status = attr_parse(attr, fp);
fclose(fp);
return status;
}
int
attr_parse(Attribs *attr, FILE *fp)
{
char hold_n[MAX_NAME+1];
char hold_v[MAX_VALUE+1];
char buf[BUFSIZ * 4];
int bp, n, v, max;
enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state;
int num_attribs;
int ch = 0;
n = v = num_attribs = bp = max = 0;
state = LOOK;
while (state != STOP) {
if (state != COMMIT) {
if (bp == max)
state = FILL;
else
ch = buf[bp++];
}
switch(state) {
case FILL:
if ((max = fread(buf, 1, sizeof buf, fp)) <= 0) {
state = STOP;
break;
}
else {
state = LOOK;
if (isDebug())
msgDebug("Read %d characters from attributes file on state FILL\n", max);
ch = buf[0];
bp = 1;
}
/* Fall through deliberately since we already have a character and state == LOOK */
case LOOK:
if (isspace(ch))
continue;
/* Allow shell or lisp style comments */
else if (ch == '#' || ch == ';') {
state = COMMENT;
continue;
}
else if (isalnum(ch) || ch == '_') {
if (n >= MAX_NAME) {
msgDebug("Attribute name overflow at character %d, ignoring entry..\n", n);
n = 0;
state = COMMENT;
}
else {
hold_n[n++] = ch;
state = NAME;
}
}
else {
msgDebug("Parse config: Invalid character '%c (%0x)'\n", ch, ch);
state = COMMENT; /* Ignore the rest of the line */
}
break;
case COMMENT:
if (ch == '\n')
state = LOOK;
break;
case NAME:
if (ch == '\n' || !ch) {
hold_n[n] = '\0';
hold_v[0] = '\0';
v = n = 0;
state = COMMIT;
}
else if (isspace(ch))
continue;
else if (ch == '=') {
hold_n[n] = '\0';
v = n = 0;
state = VALUE;
}
else
hold_n[n++] = ch;
break;
case VALUE:
if (v == 0 && isspace(ch))
continue;
else if (ch == '{')
state = MVALUE;
else if (ch == '\n' || !ch) {
hold_v[v] = '\0';
v = n = 0;
state = COMMIT;
}
else {
if (v >= MAX_VALUE) {
msgDebug("Value length overflow at character %d\n", v);
state = COMMENT;
v = n = 0;
break;
}
else
hold_v[v++] = ch;
}
break;
case MVALUE:
/* multiline value */
if (v >= MAX_VALUE) {
msgDebug("Value length overflow at character %d\n", v);
state = COMMENT;
n = v = 0;
}
else if (ch == '}') {
hold_v[v] = '\0';
v = n = 0;
state = COMMIT;
}
else
hold_v[v++] = ch;
break;
case COMMIT:
SAFE_STRCPY(attr[num_attribs].name, hold_n);
SAFE_STRCPY(attr[num_attribs].value, hold_v);
state = LOOK;
v = n = 0;
if (++num_attribs >= MAX_ATTRIBS) {
msgDebug("Attribute limit overflow at %d; encountered a bad attributes file!\n", num_attribs);
return DITEM_FAILURE;
}
break;
default:
msgFatal("Unknown state in attr_parse??");
}
}
attr[num_attribs].name[0] = NULL; /* end marker */
attr[num_attribs].value[0] = NULL; /* end marker */
if (isDebug())
msgDebug("Finished parsing %d attributes.\n", num_attribs);
return DITEM_SUCCESS;
}
char *
attr_match(Attribs *attr, char *name)
{
int n;
if (isDebug())
msgDebug("Trying to match attribute `%s'\n", name);
for (n = 0; attr[n].name[0] && strcasecmp(attr[n].name, name); n++);
if (attr[n].name[0]) {
if (isDebug())
msgDebug("Returning `%s'\n", attr[n].value);
return(attr[n].value);
}
return NULL;
}

View File

@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: cdrom.c,v 1.41 1998/07/21 06:44:38 jkh Exp $
* $Id: cdrom.c,v 1.42 1998/08/27 00:50:14 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -46,6 +46,7 @@
#include <unistd.h>
#include <grp.h>
#include <fcntl.h>
#include <libutil.h>
#define CD9660
#include <sys/mount.h>
@ -54,27 +55,37 @@
static Boolean cdromMounted;
static properties
read_props(char *name)
{
int fd;
properties n;
fd = open(name, O_RDONLY);
if (fd == -1)
return NULL;
n = properties_read(fd);
close(fd);
return n;
}
Boolean
mediaInitCDROM(Device *dev)
{
struct iso_args args;
Attribs *cd_attr;
char *cp, *mountpoint = "/dist";
properties cd_attr = NULL;
char *cp = NULL, *mountpoint = "/dist";
Boolean readInfo = TRUE;
static Boolean bogusCDOK = FALSE;
if (cdromMounted)
return TRUE;
Mkdir(mountpoint);
bzero(&args, sizeof(args));
args.fspec = dev->devname;
args.flags = 0;
cd_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
cp = NULL;
Mkdir(mountpoint);
if (mount("cd9660", mountpoint, MNT_RDONLY, (caddr_t) &args) == -1) {
if (errno == EINVAL) {
msgConfirm("The CD in your drive looks more like an Audio CD than a FreeBSD release.");
@ -104,8 +115,8 @@ mediaInitCDROM(Device *dev)
}
if (readInfo &&
(DITEM_STATUS(attr_parse_file(cd_attr, string_concat(mountpoint, "/cdrom.inf"))) == DITEM_FAILURE ||
!(cp = attr_match(cd_attr, "CD_VERSION")) || (strcmp(cp, variable_get(VAR_RELNAME)) && strcmp("none", variable_get(VAR_RELNAME))))) {
(!(cd_attr = read_props(string_concat(mountpoint, "/cdrom.inf"))) ||
!(cp = property_find(cd_attr, "CD_VERSION")) || (strcmp(cp, variable_get(VAR_RELNAME)) && strcmp("none", variable_get(VAR_RELNAME))))) {
if (!cp) {
msgConfirm("Unable to find a %s/cdrom.inf file.\n"
"Either this is not a FreeBSD CDROM, there is a problem with\n"
@ -125,6 +136,7 @@ mediaInitCDROM(Device *dev)
if (msgYesNo("Would you like to try and use this CDROM anyway?") != 0) {
unmount(mountpoint, MNT_FORCE);
cdromMounted = FALSE;
properties_free(cd_attr);
return FALSE;
}
else
@ -132,6 +144,7 @@ mediaInitCDROM(Device *dev)
}
}
msgDebug("Mounted FreeBSD CDROM from device %s\n", dev->devname);
properties_free(cd_attr);
return TRUE;
}

View File

@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
* $Id: dist.c,v 1.126 1998/09/23 12:13:47 jkh Exp $
* $Id: dist.c,v 1.127 1998/09/29 07:27:33 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -37,6 +37,7 @@
#include "sysinstall.h"
#include <sys/time.h>
#include <signal.h>
#include <libutil.h>
unsigned int Dists;
unsigned int DESDists;
@ -558,25 +559,25 @@ distExtract(char *parent, Distribution *me)
}
}
else if (fp > 0) {
int status;
Attribs *dist_attr;
properties dist_attr;
if (isDebug())
msgDebug("Parsing attributes file for distribution %s\n", dist);
dist_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
status = attr_parse(dist_attr, fp);
dist_attr = properties_read(fileno(fp));
intr = check_for_interrupt();
if (intr || DITEM_STATUS(status) == DITEM_FAILURE)
if (intr || !dist_attr) {
msgConfirm("Cannot parse information file for the %s distribution: %s\n"
"Please verify that your media is valid and try again.",
dist, !intr ? "I/O error" : "User interrupt");
}
else {
tmp = attr_match(dist_attr, "pieces");
tmp = property_find(dist_attr, "pieces");
if (tmp)
numchunks = strtol(tmp, 0, 0);
}
fclose(fp);
properties_free(dist_attr);
if (!numchunks)
continue;
}

View File

@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: sysinstall.h,v 1.147 1998/07/18 09:42:01 jkh Exp $
* $Id: sysinstall.h,v 1.148 1998/09/30 11:49:37 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -223,16 +223,6 @@ typedef struct _layout {
void *obj; /* The obj pointer returned by libdialog */
} Layout;
/* For attribs */
#define MAX_ATTRIBS 200
#define MAX_NAME 64
#define MAX_VALUE 256
typedef struct _attribs {
char name[MAX_NAME];
char value[MAX_VALUE];
} Attribs;
typedef enum {
DEVICE_TYPE_NONE,
DEVICE_TYPE_DISK,
@ -404,11 +394,6 @@ extern void display_helpline(WINDOW *w, int y, int width);
/* anonFTP.c */
extern int configAnonFTP(dialogMenuItem *self);
/* attrs.c */
extern char *attr_match(Attribs *attr, char *name);
extern int attr_parse_file(Attribs *attr, char *file);
extern int attr_parse(Attribs *attr, FILE *fp);
/* cdrom.c */
extern Boolean mediaInitCDROM(Device *dev);
extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe);

View File

@ -9,7 +9,7 @@ CLEANFILES+= keymap.tmp keymap.h
.PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum
SRCS= anonFTP.c attr.c cdrom.c command.c config.c devices.c \
SRCS= anonFTP.c cdrom.c command.c config.c devices.c \
disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c \
ftp.c globals.c index.c install.c installUpgrade.c keymap.c \
label.c lndir.c main.c makedevs.c media.c menus.c misc.c mouse.c \

View File

@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: sysinstall.h,v 1.147 1998/07/18 09:42:01 jkh Exp $
* $Id: sysinstall.h,v 1.148 1998/09/30 11:49:37 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -223,16 +223,6 @@ typedef struct _layout {
void *obj; /* The obj pointer returned by libdialog */
} Layout;
/* For attribs */
#define MAX_ATTRIBS 200
#define MAX_NAME 64
#define MAX_VALUE 256
typedef struct _attribs {
char name[MAX_NAME];
char value[MAX_VALUE];
} Attribs;
typedef enum {
DEVICE_TYPE_NONE,
DEVICE_TYPE_DISK,
@ -404,11 +394,6 @@ extern void display_helpline(WINDOW *w, int y, int width);
/* anonFTP.c */
extern int configAnonFTP(dialogMenuItem *self);
/* attrs.c */
extern char *attr_match(Attribs *attr, char *name);
extern int attr_parse_file(Attribs *attr, char *file);
extern int attr_parse(Attribs *attr, FILE *fp);
/* cdrom.c */
extern Boolean mediaInitCDROM(Device *dev);
extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe);

View File

@ -9,7 +9,7 @@ CLEANFILES+= keymap.tmp keymap.h
.PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum
SRCS= anonFTP.c attr.c cdrom.c command.c config.c devices.c \
SRCS= anonFTP.c cdrom.c command.c config.c devices.c \
disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c \
ftp.c globals.c index.c install.c installUpgrade.c keymap.c \
label.c lndir.c main.c makedevs.c media.c menus.c misc.c mouse.c \

View File

@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: cdrom.c,v 1.41 1998/07/21 06:44:38 jkh Exp $
* $Id: cdrom.c,v 1.42 1998/08/27 00:50:14 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -46,6 +46,7 @@
#include <unistd.h>
#include <grp.h>
#include <fcntl.h>
#include <libutil.h>
#define CD9660
#include <sys/mount.h>
@ -54,27 +55,37 @@
static Boolean cdromMounted;
static properties
read_props(char *name)
{
int fd;
properties n;
fd = open(name, O_RDONLY);
if (fd == -1)
return NULL;
n = properties_read(fd);
close(fd);
return n;
}
Boolean
mediaInitCDROM(Device *dev)
{
struct iso_args args;
Attribs *cd_attr;
char *cp, *mountpoint = "/dist";
properties cd_attr = NULL;
char *cp = NULL, *mountpoint = "/dist";
Boolean readInfo = TRUE;
static Boolean bogusCDOK = FALSE;
if (cdromMounted)
return TRUE;
Mkdir(mountpoint);
bzero(&args, sizeof(args));
args.fspec = dev->devname;
args.flags = 0;
cd_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
cp = NULL;
Mkdir(mountpoint);
if (mount("cd9660", mountpoint, MNT_RDONLY, (caddr_t) &args) == -1) {
if (errno == EINVAL) {
msgConfirm("The CD in your drive looks more like an Audio CD than a FreeBSD release.");
@ -104,8 +115,8 @@ mediaInitCDROM(Device *dev)
}
if (readInfo &&
(DITEM_STATUS(attr_parse_file(cd_attr, string_concat(mountpoint, "/cdrom.inf"))) == DITEM_FAILURE ||
!(cp = attr_match(cd_attr, "CD_VERSION")) || (strcmp(cp, variable_get(VAR_RELNAME)) && strcmp("none", variable_get(VAR_RELNAME))))) {
(!(cd_attr = read_props(string_concat(mountpoint, "/cdrom.inf"))) ||
!(cp = property_find(cd_attr, "CD_VERSION")) || (strcmp(cp, variable_get(VAR_RELNAME)) && strcmp("none", variable_get(VAR_RELNAME))))) {
if (!cp) {
msgConfirm("Unable to find a %s/cdrom.inf file.\n"
"Either this is not a FreeBSD CDROM, there is a problem with\n"
@ -125,6 +136,7 @@ mediaInitCDROM(Device *dev)
if (msgYesNo("Would you like to try and use this CDROM anyway?") != 0) {
unmount(mountpoint, MNT_FORCE);
cdromMounted = FALSE;
properties_free(cd_attr);
return FALSE;
}
else
@ -132,6 +144,7 @@ mediaInitCDROM(Device *dev)
}
}
msgDebug("Mounted FreeBSD CDROM from device %s\n", dev->devname);
properties_free(cd_attr);
return TRUE;
}

View File

@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
* $Id: dist.c,v 1.126 1998/09/23 12:13:47 jkh Exp $
* $Id: dist.c,v 1.127 1998/09/29 07:27:33 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -37,6 +37,7 @@
#include "sysinstall.h"
#include <sys/time.h>
#include <signal.h>
#include <libutil.h>
unsigned int Dists;
unsigned int DESDists;
@ -558,25 +559,25 @@ distExtract(char *parent, Distribution *me)
}
}
else if (fp > 0) {
int status;
Attribs *dist_attr;
properties dist_attr;
if (isDebug())
msgDebug("Parsing attributes file for distribution %s\n", dist);
dist_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
status = attr_parse(dist_attr, fp);
dist_attr = properties_read(fileno(fp));
intr = check_for_interrupt();
if (intr || DITEM_STATUS(status) == DITEM_FAILURE)
if (intr || !dist_attr) {
msgConfirm("Cannot parse information file for the %s distribution: %s\n"
"Please verify that your media is valid and try again.",
dist, !intr ? "I/O error" : "User interrupt");
}
else {
tmp = attr_match(dist_attr, "pieces");
tmp = property_find(dist_attr, "pieces");
if (tmp)
numchunks = strtol(tmp, 0, 0);
}
fclose(fp);
properties_free(dist_attr);
if (!numchunks)
continue;
}

View File

@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: sysinstall.h,v 1.147 1998/07/18 09:42:01 jkh Exp $
* $Id: sysinstall.h,v 1.148 1998/09/30 11:49:37 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -223,16 +223,6 @@ typedef struct _layout {
void *obj; /* The obj pointer returned by libdialog */
} Layout;
/* For attribs */
#define MAX_ATTRIBS 200
#define MAX_NAME 64
#define MAX_VALUE 256
typedef struct _attribs {
char name[MAX_NAME];
char value[MAX_VALUE];
} Attribs;
typedef enum {
DEVICE_TYPE_NONE,
DEVICE_TYPE_DISK,
@ -404,11 +394,6 @@ extern void display_helpline(WINDOW *w, int y, int width);
/* anonFTP.c */
extern int configAnonFTP(dialogMenuItem *self);
/* attrs.c */
extern char *attr_match(Attribs *attr, char *name);
extern int attr_parse_file(Attribs *attr, char *file);
extern int attr_parse(Attribs *attr, FILE *fp);
/* cdrom.c */
extern Boolean mediaInitCDROM(Device *dev);
extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe);