of the list of options for each entry. The previous way was not
working properly so now we just look for the 'fstype' keyword in
each option. If it exists we copy its key value.
+ Added some comments to sun_map_parse_read().
+
+ * amd/amd.h: Added an extern from info_file.c called
+ file_read_line(). Previously this function was static but is now
+ used in sun2amd.c.
+
+ * amd/info_file.c: Changed the static function read_line() to a
+ public function called file_read_line(). This function is now
+ used in sun2amd.c
+
+ * amd/sun2amd.8: Filled in the contents of this man page. This is
+ a conversion utility that converts Sun maps to Amd maps.
+
+ * amd/sun2amd.c: Implemented a working version of this utility.
2005-08-11 Erez Zadok <ezk@cs.sunysb.edu>
.\"
.\" Copyright (c) 1997-2005 Erez Zadok
+.\" Copyright (c) 2005 Daniel P. Ottavio
.\" Copyright (c) 1990 Jan-Simon Pendry
.\" Copyright (c) 1990 Imperial College of Science, Technology & Medicine
.\" Copyright (c) 1990 The Regents of the University of California.
.\"
.\" File: am-utils/amd/sun2amd.8
.\"
-.TH SUN2AMD 8L "8 August 2005"
+.TH SUN2AMD 8L "14 August 2005"
+
.SH NAME
sun2amd \- converts Sun automount maps to Amd maps
+
+.SH SYNOPSIS
+.B sun2amd
+[-hH] [-i infile] [-o outfile]
+
+.SH DESCRIPTION
+.B sun2amd
+is used to convert Sun style automount maps to Amd style automount
+maps. By default
+.B sun2amd
+reads from stdin and writes to stdout.
+
+.SH OPTIONS
+.TP
+.B -h
+Help
+.TP
+.B -i
+Read Sun map information from specified file.
+.TP
+.B -o
+Write Amd map information to specified file.
+
+.SH EXAMPLE
+To convert a Sun automount file called auto_foo to an Amd file called
+auto.amd type:
+
+.B sun2amd
+-i auto_foo -o auto.amd
+
+.SH BUGS
+* Can not convert master maps yet.
+
+* NFS is the only automount type currently supported.
+
+total_bug_count = number_found + 1;
+
+.SH "SEE ALSO"
+.BR automount(8),
+.BR amd(8)
+
+.I "Linux NFS and Automounter Administration"
+by Erez Zadok, ISBN 0-7821-2739-8, (Sybex, 2001).
+.LP
+.I http://www.am-utils.org
+.LP
+
+.SH AUTHOR
+Daniel P. Ottavio
+.I <dottavio@ic.sunysb.edu>
/*
* Copyright (c) 1997-2005 Erez Zadok
+ * Copyright (c) 2005 Daniel P. Ottavio
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
#endif /* HAVE_CONFIG_H */
#include <am_defs.h>
#include <amd.h>
-
-/* XXX: empty placeholder. Fill in */
+#include <sun_map.h>
/* dummies to make the program compile and link */
-struct amu_global_options gopt; /* may not be needed for sun2amd */
+struct amu_global_options gopt;
+
+
+/*
+ * Parse the stream sun_in, convert the map information to amd, write
+ * the results to amd_out.
+ */
+static int
+sun2amd_convert(FILE *sun_in, FILE *amd_out)
+{
+ char line_buff[INFO_MAX_LINE_LEN], *tmp, *key, *entry;
+ int pos, line = 0, retval = 1;
+
+ /* just to be safe */
+ memset(line_buff, 0, sizeof(line_buff));
+
+ /* Read the input line by line and do the conversion. */
+ while ((pos = file_read_line(line_buff, sizeof(line_buff), sun_in))) {
+ line++;
+
+ /* Make sure we have the whole line. */
+ if (line_buff[pos - 1] != '\n') {
+ plog(XLOG_ERROR, "map line %d is too long", line);
+ goto err;
+ }
+
+ line_buff[pos - 1] = '\0';
+
+ /* remove comments */
+ if ((tmp = strchr(line_buff, '#')) != NULL) {
+ *tmp = '\0';
+ }
+
+ /* find start of key */
+ key = line_buff;
+ while (*key != '\0' && isspace((int)*key)) {
+ key++;
+ }
+
+ /* ignore blank lines */
+ if (*key == '\0') {
+ continue;
+ }
+
+ /* find the end of the key and NULL terminate */
+ tmp = key;
+ while (*tmp != '\0' && isspace((int)*tmp) == 0) {
+ tmp++;
+ }
+ if (*tmp == '\0') {
+ plog(XLOG_ERROR, "map line %d has no entry", line);
+ goto err;
+ }
+ *tmp++ = '\0';
+ if(*tmp == '\0') {
+ plog(XLOG_ERROR, "map line %d has no entry", line);
+ goto err;
+ }
+ entry = tmp;
+
+ /* convert the sun entry to an amd entry */
+ if ((tmp = sun_entry2amd(key, entry)) == NULL) {
+ goto err;
+ }
+
+ if (fputs(tmp, amd_out) == EOF) {
+ plog(XLOG_ERROR, "can't write amd entry on line %d: fputs: %s", line, strerror(errno));
+ goto err;
+ }
+
+ /* just to be safe */
+ memset(line_buff, 0, sizeof(line_buff));
+ }
+
+ /* success */
+ retval = 0;
+
+ err:
+ return retval;
+}
+
+
+/*
+ * wrapper open function
+ */
+static FILE *
+sun2amd_open(const char *path, const char *mode)
+{
+ FILE *retval = NULL;
+
+ if ((retval = fopen(path,mode)) == NULL) {
+ plog(XLOG_ERROR,"could not open file %s",path);
+ }
+
+ return retval;
+}
+
+
+/*
+ * echo the usage and exit
+ */
+static void
+sun2amd_usage(void)
+{
+ fprintf(stderr,
+ "usage : sun2amd [-hH] [-i infile] [-o outfile]\n"
+ "-h\thelp\n"
+ "-i\tspecify an infile (defaults to stdin)\n"
+ "-o\tspecify an outfile (defaults to stdout)\n");
+}
int
-main()
+main(int argc, char **argv)
{
- exit(1);
+ /* default in/out to stdin/stdout */
+ FILE *sun_in = stdin, *amd_out = stdout;
+ int opt, retval = 1;
+
+ while ((opt = getopt(argc, argv , "i:o:hH")) != -1) {
+ switch (opt) {
+
+ case 'i':
+ if ((sun_in = sun2amd_open(optarg,"r")) == NULL) {
+ goto err;
+ }
+ break;
+
+ case 'o':
+ if ((amd_out = sun2amd_open(optarg,"w")) == NULL) {
+ goto err;
+ }
+ break;
+
+ case 'h':
+ case 'H':
+ sun2amd_usage();
+ goto err;
+ }
+ }
+
+ retval = sun2amd_convert(sun_in,amd_out);
+
+ err:
+ exit(retval);
}