Ensure all utilities support `--help', `--version' and `--licence',
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 20 Nov 2004 11:43:53 +0000 (11:43 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 20 Nov 2004 11:43:53 +0000 (11:43 +0000)
that `--help' mentions the other two, and that the man page mentions
how to find the licence text.

git-svn-id: svn://svn.tartarus.org/sgt/utils@4844 cda61777-01e9-0310-a592-d414129be87e

base64/base64.but
base64/base64.c
cvt-utf8/cvt-utf8
cvt-utf8/cvt-utf8.but
multi/multi
multi/multi.but
xcopy/xcopy.but
xcopy/xcopy.c

index ce12b0e..0e09007 100644 (file)
@@ -66,7 +66,13 @@ line break in the middle of the data at all.
 
 The base64 encoding converts between a group of three plaintext
 bytes and a group of four encoded bytes. \cw{base64} does not
-support breaking an encoded group across a line. Therefore, the
-\e{width} parameter passed to \cw{-c} must be a multiple of 4.
+support breaking an encoded group across a line (although it can
+handle it as input if it receives it). Therefore, the \e{width}
+parameter passed to \cw{-c} must be a multiple of 4.
 
 }
+
+\H{base64-manpage-licence} LICENCE
+
+\cw{base64} is free software, distributed under the MIT licence.
+Type \cw{base64 --licence} to see the full licence text.
index 178c51b..512f793 100644 (file)
@@ -84,7 +84,8 @@ const char usagemsg[] =
     "usage: base64 [-d] [filename]        decode from a file or from stdin\n"
     "   or: base64 -e [-cNNN] [filename]  encode from a file or from stdin\n"
     " also: base64 --version              report version number\n"
-    "  and: base64 --help                 display this help text\n"
+    "       base64 --help                 display this help text\n"
+    "       base64 --licence              display the (MIT) licence text\n"
     "where: -d     decode mode (default)\n"
     "       -e     encode mode\n"
     "       -cNNN  set number of chars per line for encoded output\n"
@@ -94,6 +95,34 @@ void usage(void) {
     fputs(usagemsg, stdout);
 }
 
+const char licencemsg[] =
+    "base64 is copyright 2001,2004 Simon Tatham.\n"
+    "\n"
+    "Permission is hereby granted, free of charge, to any person\n"
+    "obtaining a copy of this software and associated documentation files\n"
+    "(the \"Software\"), to deal in the Software without restriction,\n"
+    "including without limitation the rights to use, copy, modify, merge,\n"
+    "publish, distribute, sublicense, and/or sell copies of the Software,\n"
+    "and to permit persons to whom the Software is furnished to do so,\n"
+    "subject to the following conditions:\n"
+    "\n"
+    "The above copyright notice and this permission notice shall be\n"
+    "included in all copies or substantial portions of the Software.\n"
+    "\n"
+    "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n"
+    "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n"
+    "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n"
+    "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\n"
+    "BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\n"
+    "ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n"
+    "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
+    "SOFTWARE.\n"
+    ;
+
+void licence(void) {
+    fputs(licencemsg, stdout);
+}
+
 void version(void) {
 #define SVN_REV "$Revision$"
     char rev[sizeof(SVN_REV)];
@@ -129,14 +158,22 @@ int main(int ac, char **av) {
                 char c = *++p;
                 switch (c) {
                   case '-':
+                   p++;
                     if (!strcmp(p, "version")) {
                         version();
                         exit(0);
-                    }
-                    if (!strcmp(p, "help")) {
+                    } else if (!strcmp(p, "help")) {
                         usage();
                         exit(0);
-                    }
+                    } else if (!strcmp(p, "licence") ||
+                       !strcmp(p, "license")) {
+                        licence();
+                        exit(0);
+                    } else {
+                        fprintf(stderr, "base64: unknown long option '--%s'\n",
+                               p);
+                       exit(1);
+                   }
                     break;
                   case 'v':
                   case 'V':
index 06a17fd..a3fff92 100755 (executable)
@@ -215,11 +215,7 @@ def do(args):
     if len(list) > 0:
        process_utf8(liststepper(list))
 
-args = sys.argv[1:]
-output_analysis = 1
-han_translations = 0
-
-if args == [] or args == ["--help"] or args == ["--help-admin"]:
+def usage(arg):
     print "Usage: cvt-utf8 [flags] <hex UTF-8 bytes and/or U+codepoints>"
     print "  e.g. cvt-utf8 e2 82 ac"
     print "    or cvt-utf8 U+20ac"
@@ -232,7 +228,7 @@ if args == [] or args == ["--help"] or args == ["--help-admin"]:
     print "Also:  cvt-utf8 --test       run Markus Kuhn's decoder stress tests" #'
     print "       cvt-utf8 --input (or -i)"
     print "                             read, analyse and decode UTF-8 from stdin"
-    if args == ["--help-admin"]:
+    if arg == "--help-admin":
         print "       cvt-utf8 --help       display user help text"
         print "       cvt-utf8 --help-admin display admin help text (this one)"
         print "       cvt-utf8 --build <infile> <outfile>"
@@ -248,82 +244,150 @@ if args == [] or args == ["--help"] or args == ["--help-admin"]:
     else:
         print "       cvt-utf8 --help       display this help text"
         print "       cvt-utf8 --help-admin display admin help text"
-    sys.exit(0)
+    print "       cvt-utf8 --version    report version number"
+    print "       cvt-utf8 --licence    display (MIT) licence text"
+
+def licence():
+    print "cvt-utf8 is copyright 2002-2004 Simon Tatham."
+    print ""
+    print "Permission is hereby granted, free of charge, to any person"
+    print "obtaining a copy of this software and associated documentation files"
+    print "(the \"Software\"), to deal in the Software without restriction,"
+    print "including without limitation the rights to use, copy, modify, merge,"
+    print "publish, distribute, sublicense, and/or sell copies of the Software,"
+    print "and to permit persons to whom the Software is furnished to do so,"
+    print "subject to the following conditions:"
+    print ""
+    print "The above copyright notice and this permission notice shall be"
+    print "included in all copies or substantial portions of the Software."
+    print ""
+    print "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,"
+    print "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF"
+    print "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND"
+    print "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS"
+    print "BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN"
+    print "ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN"
+    print "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE"
+    print "SOFTWARE."
 
-if args[0] == "-o" or args[0] == "--output":
-    output_analysis = 0
-    args = args[1:]
-
-if args[0] == "-h" or args[0] == "--han":
-    han_translations = 1
-    args = args[1:]
-
-if args[0] == "--build" or args[0] == "--fetch-build":
-    if args[0] == "--build":
-       if len(args) != 3:
-           print "cvt-utf8: --build expects two filename arguments"
-           sys.exit(1)
-       infile = open(args[1], "r")
-       outfile = args[2]
+def version():
+    rev = "$Revision$"
+    rev = string.replace(rev, " ", "")
+    rev = string.replace(rev, "$", "")
+    revs = string.split(rev, ":")
+    if len(revs) > 1:
+       print "cvt-utf8 revision %s" % revs[1]
     else:
-       if len(args) != 2:
-           print "cvt-utf8: --fetch-build expects one filename argument"
-           sys.exit(1)
-       import urllib
-       infile = urllib.urlopen("http://www.unicode.org/Public/UNIDATA/UnicodeData.txt")
-       outfile = args[1]
-    # Now build the database.
-    if outfile[-3:] == ".db":
-       print "cvt-utf8: warning: you should not append .db to db name"
-
-    db = anydbm.open(outfile, "n")
-    while 1:
-       s = infile.readline()
-       if s == "": break
-       ss = string.split(s, ";")[0]
-       db[ss] = s
-    db.close()
+       print "cvt-utf8: unknown version"
+
+args = sys.argv[1:]
+output_analysis = 1
+han_translations = 0
+mode = "cmdline"
+
+if args == []:
+    usage("")
     sys.exit(0)
 
-if args[0] == "--build-unihan" or args[0] == "--fetch-build-unihan":
-    if args[0] == "--build-unihan":
-        if len(args) != 3:
-            print "cvt-utf8: --build expects two filename arguments"
-            sys.exit(1)
-        infile = open(args[1], "r")
-        s = infile.read(1)
-        # Unihan.txt starts with a hash. If this file starts with a
-        # P, we assume it's a zip file ("PK").
-        if s == "P":
-            infile = zip_untangler(infile, s)
-            s = ""
-        outfile = args[2]
+while len(args) > 0 and args[0][:1] == "-":
+    if args[0] == "--help" or args[0] == "--help-admin":
+       usage(args[0])
+       sys.exit(0)
+
+    elif args[0] == "--licence" or args[0] == "--license":
+       licence()
+       sys.exit(0)
+
+    elif args[0] == "--version":
+       version()
+       sys.exit(0)
+
+    elif args[0] == "-o" or args[0] == "--output":
+       output_analysis = 0
+       args = args[1:]
+
+    elif args[0] == "-h" or args[0] == "--han":
+       han_translations = 1
+       args = args[1:]
+
+    elif args[0] == "--build" or args[0] == "--fetch-build":
+       if args[0] == "--build":
+           if len(args) != 3:
+               print "cvt-utf8: --build expects two filename arguments"
+               sys.exit(1)
+           infile = open(args[1], "r")
+           outfile = args[2]
+       else:
+           if len(args) != 2:
+               print "cvt-utf8: --fetch-build expects one filename argument"
+               sys.exit(1)
+           import urllib
+           infile = urllib.urlopen("http://www.unicode.org/Public/UNIDATA/UnicodeData.txt")
+           outfile = args[1]
+       # Now build the database.
+       if outfile[-3:] == ".db":
+           print "cvt-utf8: warning: you should not append .db to db name"
+
+       db = anydbm.open(outfile, "n")
+       while 1:
+           s = infile.readline()
+           if s == "": break
+           ss = string.split(s, ";")[0]
+           db[ss] = s
+       db.close()
+       sys.exit(0)
+
+    elif args[0] == "--build-unihan" or args[0] == "--fetch-build-unihan":
+       if args[0] == "--build-unihan":
+           if len(args) != 3:
+               print "cvt-utf8: --build expects two filename arguments"
+               sys.exit(1)
+           infile = open(args[1], "r")
+           s = infile.read(1)
+           # Unihan.txt starts with a hash. If this file starts with a
+           # P, we assume it's a zip file ("PK").
+           if s == "P":
+               infile = zip_untangler(infile, s)
+               s = ""
+           outfile = args[2]
+       else:
+           if len(args) != 2:
+               print "cvt-utf8: --fetch-build-unihan expects one filename argument"
+               sys.exit(1)
+           import urllib
+           infile = urllib.urlopen("ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip")
+           # We know this one is zipped.
+           infile = zip_untangler(infile, "")
+           outfile = args[1]
+           s = ""
+       # Now build the database.
+       if outfile[-3:] == ".db":
+           print "cvt-utf8: warning: you should not append .db to db name"
+
+       db = anydbm.open(outfile, "n")
+       while 1:
+           s = s + infile.readline()
+           if s == "": break
+           while s[-1:] == "\r" or s[-1:] == "\n":
+               s = s[:-1]
+           sa = string.split(s, "\t")
+           if len(sa) == 3 and sa[1] == "kDefinition" and sa[0][:2] == "U+":
+               db[sa[0][2:]] = sa[2]
+           s = ""
+       db.close()
+       sys.exit(0)
+
+    elif args[0] == "--test":
+       mode = "test"
+       args = args[1:]
+
+    elif args[0] == "--input" or args[0] == "-i":
+       mode = "input"
+       args = args[1:]
+
     else:
-       if len(args) != 2:
-           print "cvt-utf8: --fetch-build-unihan expects one filename argument"
-           sys.exit(1)
-       import urllib
-       infile = urllib.urlopen("ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip")
-        # We know this one is zipped.
-        infile = zip_untangler(infile, "")
-       outfile = args[1]
-        s = ""
-    # Now build the database.
-    if outfile[-3:] == ".db":
-       print "cvt-utf8: warning: you should not append .db to db name"
-
-    db = anydbm.open(outfile, "n")
-    while 1:
-       s = s + infile.readline()
-       if s == "": break
-       while s[-1:] == "\r" or s[-1:] == "\n":
-           s = s[:-1]
-       sa = string.split(s, "\t")
-       if len(sa) == 3 and sa[1] == "kDefinition" and sa[0][:2] == "U+":
-           db[sa[0][2:]] = sa[2]
-        s = ""
-    db.close()
-    sys.exit(0)
+       sys.stderr.write("cvt-utf8: unknown argument '%s'" % args[0])
+       sys.exit(1)
 
 locations = []
 locations.append("/usr/share/unicode/unicode")
@@ -349,7 +413,7 @@ if han_translations:
     handb = anydbm.open(hanloc, "r")
     # this has been explicitly required, so we don't squelch exceptions
 
-if args[0] == "--test":
+if mode == "test":
     do(["CE","BA","E1","BD","B9","CF","83","CE","BC","CE","B5"])
     do(["00"])
     do(["C2","80"])
@@ -449,7 +513,7 @@ if args[0] == "--test":
     do(["ED","AF","BF","ED","BF","8F"])
     do(["EF","BF","BE"])
     do(["EF","BF","BF"])
-elif args[0] == "--input" or args[0] == "-i":
+elif mode == "input":
     def getchar():
        s = sys.stdin.read(1)
        if s == "":
index 427c097..1bab0ae 100644 (file)
@@ -127,7 +127,65 @@ Chinese text meaning \q{Traditional Chinese}:
 \c                               midst of; hit (target); attain
 \c U-00006587  E6 96 87          <han> literature, culture, writing
 
-\H{cvt-utf8-manpage-bugs} BUGS
+\H{cvt-utf8-manpage-admin} ADMINISTRATION
 
-Command-line option processing is very basic. In particular, \cw{-h}
-must come before \cw{-i} or it will not be recognised.
+In order to print the \cw{unicode.org} official name of each
+character, \cw{cvt-utf8} requires file mapping code points to names.
+This file is in DBM database format, for rapid lookup.
+
+This database file is accessed using the Python \cw{anydbm} module,
+so its precise file name will vary depending on what flavours of DBM
+you have installed. The name Python knows it by is \cq{unicode}; it
+may actually be called \cq{unicode.db} or something similar.
+
+\cw{cvt-utf8} generates this DBM file itself starting from the
+Unicode Character Database, in the form of the file
+\cw{UnicodeData.txt} supplied by \cw{unicode.org}. It supports two
+administrative options for this purpose:
+
+\c cvt-utf8 --build /path/to/UnicodeData.txt /path/to/unicode
+
+Given a copy of \cw{UnicodeData.txt} on disk, this mode will create
+the DBM file and store it in a place of your choice.
+
+\c cvt-utf8 --fetch-build /path/to/unicode
+
+If you have a direct Internet connection, this will automatically
+download the text file from \cw{unicode.org} and process it straight
+into the DBM file.
+
+There is a second DBM file, known to Python as \cw{unihan}, which is
+required to support the \cw{-h} option. This one is built from the
+Unihan Database, distributed by \cw{unicode.org} as a zip file
+containing a text file \cw{Unihan.txt}.
+
+If you already have \cw{Unihan.txt} on your system, you can build
+\cw{cvt-utf8}'s \cw{unihan} DBM file like this:
+
+\c cvt-utf8 --build-unihan /path/to/Unihan.txt /path/to/unihan
+
+Or, again, \cw{cvt-utf8} can automatically download it from
+\cw{unicode.org}, unpack the zip file on the fly, and write the DBM
+straight out:
+
+\c cvt-utf8 --fetch-build-unihan /path/to/unihan
+
+\cw{cvt-utf8} expects to find these database files in one of the
+following locations:
+
+\c /usr/share/unicode
+\c /usr/lib/unicode
+\c /usr/local/share/unicode
+\c /usr/local/lib/unicode
+\c $HOME/share/unicode
+\e iiiii
+\c $HOME/lib/unicode
+\e iiiii
+
+If either of these files is not found, \cw{cvt-utf8} will still
+perform the rest of its functions.
+
+\H{cvt-utf8-manpage-licence} LICENCE
+
+\cw{cvt-utf8} is free software, distributed under the MIT licence.
+Type \cw{cvt-utf8 --licence} to see the full licence text.
index 7cdbe6c..a69c682 100755 (executable)
 # transformation on file names. Thus, I arrange that all _my_
 # variables stay as far out of its likely namespace as they can.
 
+$usage =
+  "usage: multi <cmd> <action> <files>\n" .
+  "  e.g. multi mv 'tr/A-Z/a-z/' *\n" .
+  "   or: multi - <multiple-word-cmd> - <action> <files>\n" .
+  "  e.g. multi - svn mv - 'tr/A-Z/a-z/' *\n" .
+  " also: multi --version    report version number\n" .
+  "       multi --help       display this help text\n" .
+  "       multi --licence    display (MIT) licence text\n";
+
+$licence =
+  "multi is copyright 1999-2004 Simon Tatham.\n" .
+  "\n" .
+  "Permission is hereby granted, free of charge, to any person\n" .
+  "obtaining a copy of this software and associated documentation files\n" .
+  "(the \"Software\"), to deal in the Software without restriction,\n" .
+  "including without limitation the rights to use, copy, modify, merge,\n" .
+  "publish, distribute, sublicense, and/or sell copies of the Software,\n" .
+  "and to permit persons to whom the Software is furnished to do so,\n" .
+  "subject to the following conditions:\n" .
+  "\n" .
+  "The above copyright notice and this permission notice shall be\n" .
+  "included in all copies or substantial portions of the Software.\n" .
+  "\n" .
+  "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n" .
+  "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n" .
+  "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n" .
+  "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\n" .
+  "BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\n" .
+  "ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n" .
+  "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" .
+  "SOFTWARE.\n";
+
 $__quiet = $__donothing = $__reverse = 0;
 
 while ($ARGV[0] =~ /^-(.+)$/) {
@@ -24,12 +56,23 @@ while ($ARGV[0] =~ /^-(.+)$/) {
   $__quiet = 1, next if $1 eq "q";
   $__quiet = 0, $__donothing = 1, next if $1 eq "n";
   $__reverse = 1, next if $1 eq "r";
+  if ($1 eq "-help") {
+    print STDERR $usage;
+    exit 0;
+  } elsif ($1 eq "-version") {
+    if ('$Revision$' =~ /Revision:\s+(\d+)/) {
+       print "multi revision $1\n";
+    } else {
+       print "multi: unknown revision\n";
+    }
+    exit 0;
+  } elsif ($1 eq "-licence" or $1 eq "-license") {
+    print $licence;
+    exit 0;
+  }
 }
 
-die "usage: multi <cmd> <action> <files>\n" .
-    "  e.g. multi mv 'tr/A-Z/a-z/' *\n" if $#ARGV < 2;
-    " also: multi - <multiple-word-cmd> - <action> <files>\n" .
-    "    or multi - svn mv - 'tr/A-Z/a-z/' *\n" if $#ARGV < 2;
+die $usage if $#ARGV < 2;
 
 @__cmd = ();
 if ($ARGV[0] eq "-") {
index df70186..9bff4c5 100644 (file)
@@ -204,3 +204,8 @@ script which contains the core idea of this program. It takes a
 single Perl argument followed by filenames, and invokes Perl's
 internal \cw{rename} function. \cw{multi} is a complete rewrite of
 this basic idea, supplying more options and configurability.
+
+\H{multi-manpage-licence} LICENCE
+
+\cw{multi} is free software, distributed under the MIT licence. Type
+\cw{multi --licence} to see the full licence text.
index ba5bcac..a318954 100644 (file)
@@ -102,3 +102,8 @@ Automatic conversion between compound text and UTF-8 is not
 currently supported. There are Xlib functions to do it, although
 they don't appear to work very well (missing out many characters
 which they could have converted).
+
+\H{xcopy-manpage-licence} LICENCE
+
+\cw{xcopy} is free software, distributed under the MIT licence. Type
+\cw{xcopy --licence} to see the full licence text.
index c936cd7..338b48c 100644 (file)
@@ -40,6 +40,69 @@ int sellen, selsize;
 int reading;                           /* read instead of writing? */
 int convert_to_ctext = True;          /* Xmb convert to compound text? */
 
+const char usagemsg[] =
+    "usage: xcopy [ -r ] [ -u | -c ] [ -C ]\n"
+    " also: xcopy --version              report version number\n"
+    "       xcopy --help                 display this help text\n"
+    "       xcopy --licence              display the (MIT) licence text\n"
+    "where: -r     read X selection and print on stdout\n"
+    "       no -r  read stdin and store in X selection\n"
+    "       -u     work with UTF8_STRING type selections\n"
+    "       -c     work with COMPOUND_TEXT type selections\n"
+    "       -C     suppress automatic conversion to COMPOUND_TEXT\n"
+    ;
+
+void usage(void) {
+    fputs(usagemsg, stdout);
+}
+
+const char licencemsg[] =
+    "xcopy is copyright 2001-2004 Simon Tatham.\n"
+    "\n"
+    "Permission is hereby granted, free of charge, to any person\n"
+    "obtaining a copy of this software and associated documentation files\n"
+    "(the \"Software\"), to deal in the Software without restriction,\n"
+    "including without limitation the rights to use, copy, modify, merge,\n"
+    "publish, distribute, sublicense, and/or sell copies of the Software,\n"
+    "and to permit persons to whom the Software is furnished to do so,\n"
+    "subject to the following conditions:\n"
+    "\n"
+    "The above copyright notice and this permission notice shall be\n"
+    "included in all copies or substantial portions of the Software.\n"
+    "\n"
+    "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n"
+    "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n"
+    "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n"
+    "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\n"
+    "BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\n"
+    "ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n"
+    "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
+    "SOFTWARE.\n"
+    ;
+
+void licence(void) {
+    fputs(licencemsg, stdout);
+}
+
+void version(void) {
+#define SVN_REV "$Revision$"
+    char rev[sizeof(SVN_REV)];
+    char *p, *q;
+
+    strcpy(rev, SVN_REV);
+
+    for (p = rev; *p && *p != ':'; p++);
+    if (*p) {
+        p++;
+        while (*p && isspace(*p)) p++;
+        for (q = p; *q && *q != '$'; q++);
+        if (*q) *q = '\0';
+        printf("xcopy revision %s\n", p);
+    } else {
+        printf("xcopy: unknown version\n");
+    }
+}
+
 int main(int ac, char **av) {
     int n;
     int eventloop;
@@ -62,6 +125,15 @@ int main(int ac, char **av) {
             mode = CTEXT;
         } else if (!strcmp(p, "-C")) {
             convert_to_ctext = False;
+        } else if (!strcmp(p, "--help")) {
+           usage();
+           return 0;
+        } else if (!strcmp(p, "--version")) {
+            version();
+           return 0;
+        } else if (!strcmp(p, "--licence") || !strcmp(p, "--license")) {
+            licence();
+           return 0;
        } else if (*p=='-') {
            error ("unrecognised option `%s'", p);
        } else {