minix/endpoint.h minix/fslib.h minix/gcov.h minix/hash.h \
minix/ioctl.h minix/input.h minix/ipc.h minix/ipcconst.h \
minix/keymap.h minix/limits.h minix/mthread.h minix/minlib.h \
- minix/netdriver.h minix/partition.h minix/portio.h \
+ minix/netdriver.h minix/optset.h minix/partition.h minix/portio.h \
minix/priv.h minix/procfs.h minix/profile.h minix/queryparam.h \
minix/rs.h minix/safecopies.h minix/sched.h minix/sef.h \
minix/sound.h minix/spin.h minix/sys_config.h minix/sysinfo.h \
-#ifndef _OPTSET_H
-#define _OPTSET_H
+#ifndef _MINIX_OPTSET_H
+#define _MINIX_OPTSET_H
typedef enum {
OPT_BOOL,
OPT_STRING,
OPT_INT
-} opt_type;
+} optset_type;
/* An entry for the parser of an options set. The 'os_name' field must point
* to a string, which is treated case-insensitively; the last entry of a table
*/
struct optset {
char *os_name;
- opt_type os_type;
+ optset_type os_type;
void *os_ptr;
int os_val;
};
_PROTOTYPE( void optset_parse, (struct optset *table, char *string) );
-#endif /* _OPTSET_H */
+#endif /* _MINIX_OPTSET_H */
# Makefile for filter driver
PROG= filter
-SRCS= main.c sum.c driver.c util.c optset.c crc.c md5.c
+SRCS= main.c sum.c driver.c util.c crc.c md5.c
DPADD+= ${LIBDRIVER} ${LIBSYS}
LDADD+= -ldriver -lsys
#include <minix/ds.h>
#include <minix/callnr.h>
#include <minix/driver.h>
+#include <minix/optset.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
*/
#include "inc.h"
-#include "optset.h"
#define _POSIX_SOURCE 1
#include <signal.h>
+++ /dev/null
-/* This file provides functionality to parse strings of comma-separated
- * options, each being either a single key name or a key=value pair, where the
- * value may be enclosed in quotes. A table of optset entries is provided to
- * determine which options are recognized, how to parse their values, and where
- * to store those. Unrecognized options are silently ignored; improperly
- * formatted options are silently set to reasonably acceptable values.
- *
- * The entry points into this file are:
- * optset_parse parse the given options string using the given table
- *
- * Created:
- * May 2009 (D.C. van Moolenbroek)
- */
-
-#define _MINIX 1
-#include <stdlib.h>
-#include <string.h>
-#include <minix/config.h>
-#include <minix/const.h>
-
-#include "optset.h"
-
-FORWARD _PROTOTYPE( void optset_parse_entry, (struct optset *entry,
- char *ptr, int len) );
-
-/*===========================================================================*
- * optset_parse_entry *
- *===========================================================================*/
-PRIVATE void optset_parse_entry(entry, ptr, len)
-struct optset *entry;
-char *ptr;
-int len;
-{
-/* Parse and store the value of a single option.
- */
- char *dst;
- int val;
-
- switch (entry->os_type) {
- case OPT_BOOL:
- *((int *) entry->os_ptr) = entry->os_val;
-
- break;
-
- case OPT_STRING:
- if (len >= entry->os_val)
- len = entry->os_val - 1;
-
- dst = (char *) entry->os_ptr;
-
- if (len > 0)
- memcpy(dst, ptr, len);
- dst[len] = 0;
-
- break;
-
- case OPT_INT:
- if (len > 0)
- val = strtol(ptr, NULL, entry->os_val);
- else
- val = 0;
-
- *((int *) entry->os_ptr) = val;
-
- break;
- }
-}
-
-/*===========================================================================*
- * optset_parse *
- *===========================================================================*/
-PUBLIC void optset_parse(table, string)
-struct optset *table;
-char *string;
-{
-/* Parse a string of options, using the provided table of optset entries.
- */
- char *p, *kptr, *vptr;
- int i, klen, vlen;
-
- for (p = string; *p; ) {
- /* Get the key name for the field. */
- for (kptr = p, klen = 0; *p && *p != '=' && *p != ','; p++, klen++);
-
- if (*p == '=') {
- /* The field has an associated value. */
- vptr = ++p;
-
- /* If the first character after the '=' is a quote character,
- * find a matching quote character followed by either a comma
- * or the terminating null character, and use the string in
- * between. Otherwise, use the string up to the next comma or
- * the terminating null character.
- */
- if (*p == '\'' || *p == '"') {
- p++;
-
- for (vlen = 0; *p && (*p != *vptr ||
- (p[1] && p[1] != ',')); p++, vlen++);
-
- if (*p) p++;
- vptr++;
- }
- else
- for (vlen = 0; *p && *p != ','; p++, vlen++);
- }
- else {
- vptr = NULL;
- vlen = 0;
- }
-
- if (*p == ',') p++;
-
- /* Find a matching entry for this key in the given table. If found,
- * call optset_parse_entry() on it. Silently ignore the option
- * otherwise.
- */
- for (i = 0; table[i].os_name != NULL; i++) {
- if (strlen(table[i].os_name) == klen &&
- !strncasecmp(table[i].os_name, kptr, klen)) {
-
- optset_parse_entry(&table[i], vptr, vlen);
-
- break;
- }
- }
- }
-}
kprintf.c \
kputc.c \
kputs.c \
+ optset.c \
panic.c \
pci_attr_r16.c \
pci_attr_r32.c \
#include <string.h>
#include <minix/config.h>
#include <minix/const.h>
-
-#include "optset.h"
+#include <minix/optset.h>
FORWARD _PROTOTYPE( void optset_parse_entry, (struct optset *entry,
char *ptr, int len) );
mount.c misc.c open.c protect.c read.c \
stadir.c table.c time.c utility.c \
write.c ialloc.c inode.c main.c path.c \
- super.c optset.c
+ super.c
DPADD+= ${LIBSYS}
LDADD+= -lminixfs -lsys
#include <minix/dmap.h>
#include <minix/endpoint.h>
#include <minix/vfsif.h>
+#include <minix/optset.h>
#include "buf.h"
#include "inode.h"
#include "drivers.h"
-#include "optset.h"
-
/* Declare some local functions. */
FORWARD _PROTOTYPE(void get_work, (message *m_in) );
+++ /dev/null
-/* This file provides functionality to parse strings of comma-separated
- * options, each being either a single key name or a key=value pair, where the
- * value may be enclosed in quotes. A table of optset entries is provided to
- * determine which options are recognized, how to parse their values, and where
- * to store those. Unrecognized options are silently ignored; improperly
- * formatted options are silently set to reasonably acceptable values.
- *
- * The entry points into this file are:
- * optset_parse parse the given options string using the given table
- *
- * Created:
- * May 2009 (D.C. van Moolenbroek)
- */
-
-#define _MINIX 1
-#include <stdlib.h>
-#include <string.h>
-#include <minix/config.h>
-#include <minix/const.h>
-
-#include "optset.h"
-
-FORWARD _PROTOTYPE( void optset_parse_entry, (struct optset *entry,
- char *ptr, int len) );
-
-/*===========================================================================*
- * optset_parse_entry *
- *===========================================================================*/
-PRIVATE void optset_parse_entry(entry, ptr, len)
-struct optset *entry;
-char *ptr;
-int len;
-{
-/* Parse and store the value of a single option.
- */
- char *dst;
- int val;
-
- switch (entry->os_type) {
- case OPT_BOOL:
- *((int *) entry->os_ptr) = entry->os_val;
-
- break;
-
- case OPT_STRING:
- if (len >= entry->os_val)
- len = entry->os_val - 1;
-
- dst = (char *) entry->os_ptr;
-
- if (len > 0)
- memcpy(dst, ptr, len);
- dst[len] = 0;
-
- break;
-
- case OPT_INT:
- if (len > 0)
- val = strtol(ptr, NULL, entry->os_val);
- else
- val = 0;
-
- *((int *) entry->os_ptr) = val;
-
- break;
- }
-}
-
-/*===========================================================================*
- * optset_parse *
- *===========================================================================*/
-PUBLIC void optset_parse(table, string)
-struct optset *table;
-char *string;
-{
-/* Parse a string of options, using the provided table of optset entries.
- */
- char *p, *kptr, *vptr;
- int i, klen, vlen;
-
- for (p = string; *p; ) {
- /* Get the key name for the field. */
- for (kptr = p, klen = 0; *p && *p != '=' && *p != ','; p++, klen++);
-
- if (*p == '=') {
- /* The field has an associated value. */
- vptr = ++p;
-
- /* If the first character after the '=' is a quote character,
- * find a matching quote character followed by either a comma
- * or the terminating null character, and use the string in
- * between. Otherwise, use the string up to the next comma or
- * the terminating null character.
- */
- if (*p == '\'' || *p == '"') {
- p++;
-
- for (vlen = 0; *p && (*p != *vptr ||
- (p[1] && p[1] != ',')); p++, vlen++);
-
- if (*p) p++;
- vptr++;
- }
- else
- for (vlen = 0; *p && *p != ','; p++, vlen++);
- }
- else {
- vptr = NULL;
- vlen = 0;
- }
-
- if (*p == ',') p++;
-
- /* Find a matching entry for this key in the given table. If found,
- * call optset_parse_entry() on it. Silently ignore the option
- * otherwise.
- */
- for (i = 0; table[i].os_name != NULL; i++) {
- if (strlen(table[i].os_name) == klen &&
- !strncasecmp(table[i].os_name, kptr, klen)) {
-
- optset_parse_entry(&table[i], vptr, vlen);
-
- break;
- }
- }
- }
-}
+++ /dev/null
-#ifndef _OPTSET_H
-#define _OPTSET_H
-
-enum {
- OPT_BOOL,
- OPT_STRING,
- OPT_INT
-};
-
-/* An entry for the parser of an options set. The 'os_name' field must point
- * to a string, which is treated case-insensitively; the last entry of a table
- * must have NULL name. The 'os_type' field must be set to one of the OPT_
- * values defined above. The 'os_ptr' field must point to the field that is to
- * receive the value of a recognized option. For OPT_STRING, it must point to a
- * string of a size set in 'os_val'; the resulting string may be truncated, but
- * will always be null-terminated. For OPT_BOOL, it must point to an int which
- * will be set to the value in 'os_val' if the option is present. For OPT_INT,
- * it must point to an int which will be set to the provided option value;
- * 'os_val' is then a base passed to strtol().
- */
-struct optset {
- char *os_name;
- int os_type;
- void *os_ptr;
- int os_val;
-};
-
-_PROTOTYPE( void optset_parse, (struct optset *table, char *string) );
-
-#endif /* _OPTSET_H */
# Makefile for VMware Host/Guest File System (HGFS) server
PROG= hgfs
SRCS= dentry.c handle.c inode.c link.c lookup.c main.c \
- misc.c mount.c name.c optset.c path.c read.c \
- stat.c table.c util.c verify.c write.c
+ misc.c mount.c name.c path.c read.c stat.c table.c \
+ util.c verify.c write.c
DPADD+= ${LIBHGFS} ${LIBSYS}
LDADD+= -lhgfs -lsys
#include <minix/vfsif.h>
#include <minix/syslib.h>
#include <minix/sysutil.h>
+#include <minix/optset.h>
#include <sys/param.h>
#if DEBUG
#include "inc.h"
-#include "optset.h"
-
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
+++ /dev/null
-/* This file provides functionality to parse strings of comma-separated
- * options, each being either a single key name or a key=value pair, where the
- * value may be enclosed in quotes. A table of optset entries is provided to
- * determine which options are recognized, how to parse their values, and where
- * to store those. Unrecognized options are silently ignored; improperly
- * formatted options are silently set to reasonably acceptable values.
- *
- * The entry points into this file are:
- * optset_parse parse the given options string using the given table
- *
- * Created:
- * May 2009 (D.C. van Moolenbroek)
- */
-
-#define _MINIX 1
-#include <stdlib.h>
-#include <string.h>
-#include <minix/config.h>
-#include <minix/const.h>
-
-#include "optset.h"
-
-FORWARD _PROTOTYPE( void optset_parse_entry, (struct optset *entry,
- char *ptr, int len) );
-
-/*===========================================================================*
- * optset_parse_entry *
- *===========================================================================*/
-PRIVATE void optset_parse_entry(entry, ptr, len)
-struct optset *entry;
-char *ptr;
-int len;
-{
-/* Parse and store the value of a single option.
- */
- char *dst;
- int val;
-
- switch (entry->os_type) {
- case OPT_BOOL:
- *((int *) entry->os_ptr) = entry->os_val;
-
- break;
-
- case OPT_STRING:
- if (len >= entry->os_val)
- len = entry->os_val - 1;
-
- dst = (char *) entry->os_ptr;
-
- if (len > 0)
- memcpy(dst, ptr, len);
- dst[len] = 0;
-
- break;
-
- case OPT_INT:
- if (len > 0)
- val = strtol(ptr, NULL, entry->os_val);
- else
- val = 0;
-
- *((int *) entry->os_ptr) = val;
-
- break;
- }
-}
-
-/*===========================================================================*
- * optset_parse *
- *===========================================================================*/
-PUBLIC void optset_parse(table, string)
-struct optset *table;
-char *string;
-{
-/* Parse a string of options, using the provided table of optset entries.
- */
- char *p, *kptr, *vptr;
- int i, klen, vlen;
-
- for (p = string; *p; ) {
- /* Get the key name for the field. */
- for (kptr = p, klen = 0; *p && *p != '=' && *p != ','; p++, klen++);
-
- if (*p == '=') {
- /* The field has an associated value. */
- vptr = ++p;
-
- /* If the first character after the '=' is a quote character,
- * find a matching quote character followed by either a comma
- * or the terminating null character, and use the string in
- * between. Otherwise, use the string up to the next comma or
- * the terminating null character.
- */
- if (*p == '\'' || *p == '"') {
- p++;
-
- for (vlen = 0; *p && (*p != *vptr ||
- (p[1] && p[1] != ',')); p++, vlen++);
-
- if (*p) p++;
- vptr++;
- }
- else
- for (vlen = 0; *p && *p != ','; p++, vlen++);
- }
- else {
- vptr = NULL;
- vlen = 0;
- }
-
- if (*p == ',') p++;
-
- /* Find a matching entry for this key in the given table. If found,
- * call optset_parse_entry() on it. Silently ignore the option
- * otherwise.
- */
- for (i = 0; table[i].os_name != NULL; i++) {
- if (strlen(table[i].os_name) == klen &&
- !strncasecmp(table[i].os_name, kptr, klen)) {
-
- optset_parse_entry(&table[i], vptr, vlen);
-
- break;
- }
- }
- }
-}
+++ /dev/null
-#ifndef _OPTSET_H
-#define _OPTSET_H
-
-enum {
- OPT_BOOL,
- OPT_STRING,
- OPT_INT
-};
-
-/* An entry for the parser of an options set. The 'os_name' field must point
- * to a string, which is treated case-insensitively; the last entry of a table
- * must have NULL name. The 'os_type' field must be set to one of the OPT_
- * values defined above. The 'os_ptr' field must point to the field that is to
- * receive the value of a recognized option. For OPT_STRING, it must point to a
- * string of a size set in 'os_val'; the resulting string may be truncated, but
- * will always be null-terminated. For OPT_BOOL, it must point to an int which
- * will be set to the value in 'os_val' if the option is present. For OPT_INT,
- * it must point to an int which will be set to the provided option value;
- * 'os_val' is then a base passed to strtol().
- */
-struct optset {
- char *os_name;
- int os_type;
- void *os_ptr;
- int os_val;
-};
-
-_PROTOTYPE( void optset_parse, (struct optset *table, char *string) );
-
-#endif /* _OPTSET_H */
# Makefile for the Block Device Driver Test driver (blocktest)
PROG= blocktest
-SRCS= blocktest.c optset.c
+SRCS= blocktest.c
DPADD+= ${LIBSYS}
LDADD+= -lsys
#include <minix/dmap.h>
#include <minix/sysinfo.h>
#include <minix/ds.h>
+#include <minix/optset.h>
#include <sys/ioc_disk.h>
#include <assert.h>
#include "servers/avfs/const.h"
#include "servers/avfs/dmap.h"
-#include "optset.h"
-
enum {
RESULT_OK, /* exactly as expected */
RESULT_COMMFAIL, /* communication failed */
+++ /dev/null
-#ifndef _OPTSET_H
-#define _OPTSET_H
-
-typedef enum {
- OPT_BOOL,
- OPT_STRING,
- OPT_INT
-} opt_type;
-
-/* An entry for the parser of an options set. The 'os_name' field must point
- * to a string, which is treated case-insensitively; the last entry of a table
- * must have NULL name. The 'os_type' field must be set to one of the OPT_
- * values defined above. The 'os_ptr' field must point to the field that is to
- * receive the value of a recognized option. For OPT_STRING, it must point to a
- * string of a size set in 'os_val'; the resulting string may be truncated, but
- * will always be null-terminated. For OPT_BOOL, it must point to an int which
- * will be set to the value in 'os_val' if the option is present. For OPT_INT,
- * it must point to an int which will be set to the provided option value;
- * 'os_val' is then a base passed to strtol().
- */
-struct optset {
- char *os_name;
- opt_type os_type;
- void *os_ptr;
- int os_val;
-};
-
-_PROTOTYPE( void optset_parse, (struct optset *table, char *string) );
-
-#endif /* _OPTSET_H */