diff options
author | Fritz Elfert <felfert@to.com> | 2002-03-06 02:03:01 +0000 |
---|---|---|
committer | Fritz Elfert <felfert@to.com> | 2002-03-06 02:03:01 +0000 |
commit | df8cd95398541462cdf94f55692b75976360ce01 (patch) | |
tree | 57d3a2f2cec6e7466b970f80715fa6b16b06bf3c | |
parent | fed9637559c4b2722ef7d70b8420cbee2f002174 (diff) | |
download | plptools-df8cd95398541462cdf94f55692b75976360ce01.tar.gz plptools-df8cd95398541462cdf94f55692b75976360ce01.tar.bz2 plptools-df8cd95398541462cdf94f55692b75976360ce01.zip |
- i18n: Changed macros into inline functions to make string constant
concatenation of gcc possible.
- Unified commandline arguments.
-rw-r--r-- | lib/plpintl.h | 24 | ||||
-rw-r--r-- | ncpd/main.cc | 201 | ||||
-rw-r--r-- | plpftp/ftp.cc | 44 | ||||
-rw-r--r-- | plpftp/main.cc | 105 | ||||
-rw-r--r-- | plpnfsd/main.cc | 127 |
5 files changed, 379 insertions, 122 deletions
diff --git a/lib/plpintl.h b/lib/plpintl.h index 382fd6d..79f3359 100644 --- a/lib/plpintl.h +++ b/lib/plpintl.h @@ -3,8 +3,7 @@ * * This file is part of plptools. * - * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com> - * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com> + * Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,25 +31,24 @@ #include <string.h> extern inline char * stpcpy(char *dest, const char *src) { - char c; - do { - c = *dest++ = *src++; - } while (c); - return dest; + char c; + do { + c = *dest++ = *src++; + } while (c); + return dest; } #endif #if defined(ENABLE_NLS) && defined(HAVE_GETTEXT) # include <libintl.h> -# define X_(x) gettext(x) -# define N_(x) (x) -# define _(x) gettext(x) +static inline const char *X_(const char *t) { return gettext(t); } +static inline const char *_(const char *t) { return gettext(t); } #else -# define X_(x) (x) -# define N_(x) (x) -# define _(x) (x) +static inline const char *X_(const char *t) { return t; } +static inline const char *_(const char *t) { return t; } # define textdomain(x) #endif +static inline const char *N_(const char *t) { return t; } /* Define this, if you have gettext */ #define HAVE_GETTEXT 1 diff --git a/ncpd/main.cc b/ncpd/main.cc index 279f0f5..f1f7f14 100644 --- a/ncpd/main.cc +++ b/ncpd/main.cc @@ -35,6 +35,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <pthread.h> +#include <plpintl.h> #include "ncp.h" #include "bufferstore.h" @@ -46,6 +47,9 @@ #include "packet.h" #include "log.h" +#define _GNU_SOURCE +#include <getopt.h> + static bool verbose = false; static bool active = true; static bool autoexit = false; @@ -125,11 +129,81 @@ pollSocketConnections(void *) return NULL; } -void -usage() +static void +help() +{ + cout << _( + "Usage: plpnfsd [OPTIONS]...\n" + "\n" + "Supported options:\n" + "\n" + " -d, --dontfork Run in foreground don't fork\n" + " -h, --help Display this text.\n" + " -V, --version Print version and exit.\n" + " -e, --autoexit Exit after device is disconnected.\n" + " -v, --verbose=LOGCLASS Enable logging of LOGCLASS events\n" + " Valid log classes are:\n" + " m - main program\n" + " nl - NCP protocol log\n" + " nd - NCP protocol data dump\n" + " ll - PLP protocol log\n" + " ld - PLP protocol data dump\n" + " pl - physical I/O log\n" + " ph - physical I/O handshake\n" + " pd - physical I/O data dump\n" + " all - All of the above\n" + " -s, --serial=DEV Use serial device DEV.\n" + " -b, --baudrate=RATE Set serial speed to BAUD.\n" + " -p, --port=[HOST:]PORT Listen on host HOST, port PORT.\n" + " Default for HOST is 127.0.0.1\n" + " Default for PORT is " + ) << DPORT << "\n\n"; +} + +static void +usage() { + cerr << _("Try `ncpd --help' for more information") << endl; +} + +static struct option opts[] = { + {"dontfork", no_argument, 0, 'd'}, + {"autoexit", no_argument, 0, 'e'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"verbose", required_argument, 0, 'v'}, + {"port", required_argument, 0, 'p'}, + {"serial", required_argument, 0, 's'}, + {"baudrate", required_argument, 0, 'b'}, + {NULL, 0, 0, 0 } +}; + +static void +parse_destination(const char *arg, const char **host, int *port) { - cerr << "Usage : ncpd [-V] [-v logclass] [-d] [-e] [-p [<host>:]<port>] [-s <device>] [-b <baudrate>]\n"; - exit(1); + if (!arg) + return; + // We don't want to modify argv, therefore copy it first ... + char *argcpy = strdup(arg); + char *pp = strchr(argcpy, ':'); + + if (pp) { + // host.domain:400 + // 10.0.0.1:400 + *pp ++= '\0'; + *host = argcpy; + } else { + // 400 + // host.domain + // host + // 10.0.0.1 + if (strchr(argcpy, '.') || !isdigit(argcpy[0])) { + *host = argcpy; + pp = 0L; + } else + pp = argcpy; + } + if (pp) + *port = atoi(pp); } static void * @@ -169,67 +243,64 @@ main(int argc, char **argv) if (se != 0L) sockNum = ntohs(se->s_port); - // Command line parameter processing - for (int i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-p") && i + 1 < argc) { - // parse port argument - i++; - char *pp = strchr(argv[i], ':'); - if (pp != NULL) { - // host.domain:400 - // 10.0.0.1:400 - *pp ++= '\0'; - host = argv[i]; - } else { - // 400 - // host.domain - // host - // 10.0.0.1 - if (strchr(argv[i], '.') || !isdigit(argv[i][0])) { - host = argv[i]; - pp = NULL; - } else - pp = argv[i]; - } - if (pp != NULL) - sockNum = atoi(pp); - } else if (!strcmp(argv[i], "-s") && i + 1 < argc) { - serialDevice = argv[++i]; - } else if (!strcmp(argv[i], "-v") && i + 1 < argc) { - i++; - if (!strcmp(argv[i], "nl")) - nverbose |= NCP_DEBUG_LOG; - if (!strcmp(argv[i], "nd")) - nverbose |= NCP_DEBUG_DUMP; - if (!strcmp(argv[i], "ll")) - nverbose |= LNK_DEBUG_LOG; - if (!strcmp(argv[i], "ld")) - nverbose |= LNK_DEBUG_DUMP; - if (!strcmp(argv[i], "pl")) - nverbose |= PKT_DEBUG_LOG; - if (!strcmp(argv[i], "pd")) - nverbose |= PKT_DEBUG_DUMP; - if (!strcmp(argv[i], "ph")) - nverbose |= PKT_DEBUG_HANDSHAKE; - if (!strcmp(argv[i], "m")) - verbose = true; - if (!strcmp(argv[i], "all")) { - nverbose = NCP_DEBUG_LOG | NCP_DEBUG_DUMP | - LNK_DEBUG_LOG | LNK_DEBUG_DUMP | - PKT_DEBUG_LOG | PKT_DEBUG_DUMP | PKT_DEBUG_HANDSHAKE; - verbose = true; - } - } else if (!strcmp(argv[i], "-b") && i + 1 < argc) { - baudRate = atoi(argv[++i]); - } else if (!strcmp(argv[i], "-d")) { - dofork = 0; - } else if (!strcmp(argv[i], "-e")) { - autoexit = true; - } else if (!strcmp(argv[i], "-V")) { - cout << "ncpd version " << VERSION << endl; - exit(0); - } else - usage(); + while (1) { + int c = getopt_long(argc, argv, "hdeVb:s:p:v:", opts, NULL); + if (c == -1) + break; + switch (c) { + case '?': + usage(); + return -1; + case 'V': + cout << _("plpnfsd Version ") << VERSION << endl; + return 0; + case 'h': + help(); + return 0; + case 'v': + if (!strcmp(optarg, "nl")) + nverbose |= NCP_DEBUG_LOG; + if (!strcmp(optarg, "nd")) + nverbose |= NCP_DEBUG_DUMP; + if (!strcmp(optarg, "ll")) + nverbose |= LNK_DEBUG_LOG; + if (!strcmp(optarg, "ld")) + nverbose |= LNK_DEBUG_DUMP; + if (!strcmp(optarg, "pl")) + nverbose |= PKT_DEBUG_LOG; + if (!strcmp(optarg, "pd")) + nverbose |= PKT_DEBUG_DUMP; + if (!strcmp(optarg, "ph")) + nverbose |= PKT_DEBUG_HANDSHAKE; + if (!strcmp(optarg, "m")) + verbose = true; + if (!strcmp(optarg, "all")) { + nverbose = NCP_DEBUG_LOG | NCP_DEBUG_DUMP | + LNK_DEBUG_LOG | LNK_DEBUG_DUMP | + PKT_DEBUG_LOG | PKT_DEBUG_DUMP | PKT_DEBUG_HANDSHAKE; + verbose = true; + } + break; + case 'd': + dofork = 0; + break; + case 'e': + autoexit = true; + break; + case 'b': + baudRate = atoi(optarg); + break; + case 's': + serialDevice = optarg; + break; + case 'p': + parse_destination(optarg, &host, &sockNum); + break; + } + } + if (optind < argc) { + usage(); + return -1; } if (serialDevice == NULL) { diff --git a/plpftp/ftp.cc b/plpftp/ftp.cc index 44ac4b6..4c6da16 100644 --- a/plpftp/ftp.cc +++ b/plpftp/ftp.cc @@ -212,11 +212,11 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) cpCallback_t cab = checkAbortNoHash; bool once = false; - if (xargc > 1) { + if (xargc) { once = true; - argc = (xargc<11)?xargc-1:10; + argc = (xargc<10)?xargc:10; for (int i = 0; i < argc; i++) - argv[i] = xargv[i+1]; + argv[i] = xargv[i]; } { Enum<rpcs::machs> machType; @@ -439,7 +439,43 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) } if (!strcmp(argv[0], "ls") || !strcmp(argv[0], "dir")) { PlpDir files; - if ((res = a.dir(psionDir, files)) != rfsv::E_PSI_GEN_NONE) + char dtmp[1024]; + char *dname = psionDir; + + if (argc > 1) { + u_int32_t tmp; + strcpy(dtmp, psionDir); + if (!strcmp(argv[1], "..")) { + strcpy(f1, psionDir); + char *p = f1 + strlen(f1); + if (p > f1) + p--; + *p = '\0'; + while ((p > f1) && (*p != '/') && (*p != '\\')) + p--; + *(++p) = '\0'; + if (strlen(f1) < 3) { + strcpy(f1, psionDir); + f1[3] = '\0'; + } + } else { + if ((argv[1][0] != '/') && (argv[1][0] != '\\') && + (argv[1][1] != ':')) { + strcpy(f1, psionDir); + strcat(f1, argv[1]); + } else + strcpy(f1, argv[1]); + } + if ((f1[strlen(f1) -1] != '/') && (f1[strlen(f1) -1] != '\\')) + strcat(f1,"\\"); + for (char *p = f1; *p; p++) + if (*p == '/') + *p = '\\'; + strcpy(dtmp, f1); + dname = dtmp; + } + + if ((res = a.dir(dname, files)) != rfsv::E_PSI_GEN_NONE) cerr << _("Error: ") << res << endl; else while (!files.empty()) { diff --git a/plpftp/main.cc b/plpftp/main.cc index a60a2fb..2bbc7d7 100644 --- a/plpftp/main.cc +++ b/plpftp/main.cc @@ -4,7 +4,7 @@ * This file is part of plptools. * * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com> - * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com> + * Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,19 +40,48 @@ #include "ftp.h" -void -usage() +#define _GNU_SOURCE +#include <getopt.h> + +static void +help() { - cout << _("Version ") << VERSION << endl; - cout << _("Usage : plpftp -p <port> [ftpcommand parameters]") << endl; + cout << _( + "Usage: plpftp [OPTIONS]... [FTPCOMMAND]\n" + "\n" + "If FTPCOMMAND is given, connect; run FTPCOMMAND and\n" + "terminate afterwards. If no FTPCOMMAND is given, start up\n" + "in interactive mode. For help on supported FTPCOMMANDs,\n" + "use `?' or `help' as FTPCOMMAND.\n" + "\n" + "Supported options:\n" + "\n" + " -h, --help Display this text.\n" + " -V, --version Print version and exit.\n" + " -p, --port=[HOST:]PORT Connect to port PORT on host HOST.\n" + " Default for HOST is 127.0.0.1\n" + " Default for PORT is " + ) << DPORT << "\n\n"; +} + +static void +usage() { + cerr << _("Try `plpftp --help' for more information") << endl; } +static struct option opts[] = { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"port", required_argument, 0, 'p'}, + {NULL, 0, 0, 0 } +}; + void ftpHeader() { cout << _("PLPFTP Version ") << VERSION; cout << _(" Copyright (C) 1999 Philip Proudman") << endl; - cout << _(" Additions Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>") << endl; + cout << _(" Additions Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com>") << endl; cout << _(" & (C) 1999 Matt Gumbley <matt@gumbley.demon.co.uk>") << endl; cout << _("PLPFTP comes with ABSOLUTELY NO WARRANTY.") << endl; cout << _("This is free software, and you are welcome to redistribute it") << endl; @@ -61,6 +90,35 @@ ftpHeader() cout << _("FTP like interface started. Type \"?\" for help.") << endl; } +static void +parse_destination(const char *arg, const char **host, int *port) +{ + if (!arg) + return; + // We don't want to modify argv, therefore copy it first ... + char *argcpy = strdup(arg); + char *pp = strchr(argcpy, ':'); + + if (pp) { + // host.domain:400 + // 10.0.0.1:400 + *pp ++= '\0'; + *host = argcpy; + } else { + // 400 + // host.domain + // host + // 10.0.0.1 + if (strchr(argcpy, '.') || !isdigit(argcpy[0])) { + *host = argcpy; + pp = 0L; + } else + pp = argcpy; + } + if (pp) + *port = atoi(pp); +} + int main(int argc, char **argv) { @@ -69,6 +127,7 @@ main(int argc, char **argv) rfsv *a; rpcs *r; ftp f; + const char *host = "127.0.0.1"; int status = 0; int sockNum = DPORT; @@ -82,23 +141,35 @@ main(int argc, char **argv) if (se != 0L) sockNum = ntohs(se->s_port); - // Command line parameter processing - if ((argc > 2) && !strcmp(argv[1], "-p")) { - sockNum = atoi(argv[2]); - argc -= 2; - for (int i = 1; i < argc; i++) - argv[i] = argv[i + 2]; + while (1) { + int c = getopt_long(argc, argv, "hVp:", opts, NULL); + if (c == -1) + break; + switch (c) { + case '?': + usage(); + return -1; + case 'V': + cout << _("plpftp Version ") << VERSION << endl; + return 0; + case 'h': + help(); + return 0; + case 'p': + parse_destination(optarg, &host, &sockNum); + break; + } } - - if (argc < 2) + if (optind == argc) ftpHeader(); + skt = new ppsocket(); - if (!skt->connect(NULL, sockNum)) { + if (!skt->connect(host, sockNum)) { cout << _("plpftp: could not connect to ncpd") << endl; return 1; } skt2 = new ppsocket(); - if (!skt2->connect(NULL, sockNum)) { + if (!skt2->connect(host, sockNum)) { cout << _("plpftp: could not connect to ncpd") << endl; return 1; } @@ -107,7 +178,7 @@ main(int argc, char **argv) a = rf->create(false); r = rp->create(false); if ((a != NULL) && (r != NULL)) { - status = f.session(*a, *r, argc, argv); + status = f.session(*a, *r, argc - optind, &argv[optind]); delete r; delete a; delete skt; diff --git a/plpnfsd/main.cc b/plpnfsd/main.cc index ecc9a14..b7f6740 100644 --- a/plpnfsd/main.cc +++ b/plpnfsd/main.cc @@ -42,6 +42,9 @@ extern "C" { #include "rfsv_api.h" } +#define _GNU_SOURCE +#include <getopt.h> + static rfsv *a; static rfsvfactory *rf; static char *a_filename = 0; @@ -447,10 +450,10 @@ long rfsv_drivelist(int *cnt, device **dlist) { if (ret == 0) for (i = 0; i<26; i++) { PlpDrive drive; - + if ((devbits & 1) && ((a->devinfo(i + 'A', drive) == rfsv::E_PSI_GEN_NONE))) { - + device *next = *dlist; *dlist = (device *)malloc(sizeof(device)); (*dlist)->next = next; @@ -466,10 +469,69 @@ long rfsv_drivelist(int *cnt, device **dlist) { return ret; } -void usage() +static void +help() +{ + cout << _( + "Usage: plpnfsd [OPTIONS]...\n" + "\n" + "Supported options:\n" + "\n" + " -d, --mountpoint=DIR Specify DIR as mountpoint\n" + " -u, --user=USER Specify USER who owns mounted dir.\n" + " -v, --verbose Increase verbosity\n" + " -D, --debug Increase debug level\n" + " -h, --help Display this text.\n" + " -V, --version Print version and exit.\n" + " -p, --port=[HOST:]PORT Connect to port PORT on host HOST.\n" + " Default for HOST is 127.0.0.1\n" + " Default for PORT is " + ) << DPORT << "\n\n"; +} + +static void +usage() { + cerr << _("Try `plpnfsd --help' for more information") << endl; +} + +static struct option opts[] = { + {"help", no_argument, 0, 'h'}, + {"verbose", no_argument, 0, 'v'}, + {"debug", no_argument, 0, 'D'}, + {"version", no_argument, 0, 'V'}, + {"port", required_argument, 0, 'p'}, + {"user", required_argument, 0, 'u'}, + {"mountpoint", required_argument, 0, 'd'}, + {NULL, 0, 0, 0 } +}; + +static void +parse_destination(const char *arg, const char **host, int *port) { - cerr << "usage: plpnfsd [-v] [-V] [-p port] [-d mountdir] [-u user]\n"; - exit(1); + if (!arg) + return; + // We don't want to modify argv, therefore copy it first ... + char *argcpy = strdup(arg); + char *pp = strchr(argcpy, ':'); + + if (pp) { + // host.domain:400 + // 10.0.0.1:400 + *pp ++= '\0'; + *host = argcpy; + } else { + // 400 + // host.domain + // host + // 10.0.0.1 + if (strchr(argcpy, '.') || !isdigit(argcpy[0])) { + *host = argcpy; + pp = 0L; + } else + pp = argcpy; + } + if (pp) + *port = atoi(pp); } int main(int argc, char**argv) { @@ -477,6 +539,7 @@ int main(int argc, char**argv) { ppsocket *skt2; char *user = 0L; char *mdir = DMOUNTPOINT; + const char *host = "127.0.0.1"; int sockNum = DPORT; int verbose = 0; int status = 0; @@ -486,31 +549,49 @@ int main(int argc, char**argv) { if (se != 0L) sockNum = ntohs(se->s_port); - for (int i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-p") && i + 1 < argc) { - sockNum = atoi(argv[++i]); - } else if (!strcmp(argv[i], "-d") && i + 1 < argc) { - mdir = argv[++i]; - } else if (!strcmp(argv[i], "-u") && i + 1 < argc) { - user = argv[++i]; - } else if (!strcmp(argv[i], "-v")) { - verbose++; - } else if (!strcmp(argv[i], "-D")) { - debug++; - } else if (!strcmp(argv[i], "-V")) { - cout << "plpnfsd version " << VERSION << endl; - exit(0); - } else - usage(); + while (1) { + int c = getopt_long(argc, argv, "hvDVp:u:d:", opts, NULL); + if (c == -1) + break; + switch (c) { + case '?': + usage(); + return -1; + case 'V': + cout << _("plpnfsd Version ") << VERSION << endl; + return 0; + case 'h': + help(); + return 0; + case 'v': + verbose++; + break; + case 'D': + debug++; + break; + case 'd': + mdir = optarg; + break; + case 'u': + user = optarg; + break; + case 'p': + parse_destination(optarg, &host, &sockNum); + break; + } + } + if (optind < argc) { + usage(); + return -1; } skt = new ppsocket(); - if (!skt->connect(NULL, sockNum)) { + if (!skt->connect(host, sockNum)) { cerr << "plpnfsd: could not connect to ncpd" << endl; status = 1; } skt2 = new ppsocket(); - if (!skt2->connect(NULL, sockNum)) { + if (!skt2->connect(host, sockNum)) { cerr << "plpnfsd: could not connect to ncpd" << endl; status = 1; } |