home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume23
/
tua
/
part04
< prev
next >
Wrap
Text File
|
1991-09-23
|
46KB
|
1,587 lines
Newsgroups: comp.sources.misc
From: piggy@idea.sublink.org (Lele Gaifas)
Subject: v23i010: tua - The Uucp Analyzer, Part04/05
Message-ID: <1991Sep22.203540.23061@sparky.imd.sterling.com>
X-Md4-Signature: 1cd1408d38e27a6eada787142c3de802
Date: Sun, 22 Sep 1991 20:35:40 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: piggy@idea.sublink.org (Lele Gaifas)
Posting-number: Volume 23, Issue 10
Archive-name: tua/part04
Environment: Xenix, SYSV
---- Cut Here and feed the following to sh ----
# This is part 04 of a multipart archive
# ============= getopt.c ==============
if test -f 'getopt.c' -a X"$1" != X"-c"; then
echo 'x - skipping getopt.c (File already exists)'
else
echo 'x - extracting getopt.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'getopt.c' &&
/* Getopt for GNU.
X Copyright (C) 1987, 1989 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 1, or (at your option)
X any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#ifdef __STDC__
#define CONST const
#else
#define CONST
#endif
X
/* This version of `getopt' appears to the caller like standard Unix `getopt'
X but it behaves differently for the user, since it allows the user
X to intersperse the options with the other arguments.
X
X As `getopt' works, it permutes the elements of `argv' so that,
X when it is done, all the options precede everything else. Thus
X all application programs are extended to handle flexible argument order.
X
X Setting the environment variable _POSIX_OPTION_ORDER disables permutation.
X Then the behavior is completely standard.
X
X GNU application programs can use a third alternative mode in which
X they can distinguish the relative order of options and other arguments. */
X
#include <stdio.h>
X
/* If compiled with GNU C, use the built-in alloca */
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not __GNUC__ */
#ifdef sparc
#include <alloca.h>
#else
char *alloca ();
#endif
#endif /* not __GNUC__ */
X
#ifdef USG
#define bcopy(s, d, l) memcpy((d), (s), (l))
#define index strchr
#endif
X
char *getenv ();
char *index ();
char *malloc ();
X
/* For communication from `getopt' to the caller.
X When `getopt' finds an option that takes an argument,
X the argument value is returned here.
X Also, when `ordering' is RETURN_IN_ORDER,
X each non-option ARGV-element is returned here. */
X
char *optarg = 0;
X
/* Index in ARGV of the next element to be scanned.
X This is used for communication to and from the caller
X and for communication between successive calls to `getopt'.
X
X On entry to `getopt', zero means this is the first call; initialize.
X
X When `getopt' returns EOF, this is the index of the first of the
X non-option elements that the caller should itself scan.
X
X Otherwise, `optind' communicates from one call to the next
X how much of ARGV has been scanned so far. */
X
int optind = 0;
X
/* The next char to be scanned in the option-element
X in which the last option character we returned was found.
X This allows us to pick up the scan where we left off.
X
X If this is zero, or a null string, it means resume the scan
X by advancing to the next ARGV-element. */
X
static char *nextchar;
X
/* Callers store zero here to inhibit the error message
X for unrecognized options. */
X
int opterr = 1;
X
/* Describe how to deal with options that follow non-option ARGV-elements.
X
X If the caller did not specify anything,
X the default is REQUIRE_ORDER if the environment variable
X _POSIX_OPTION_ORDER is defined, PERMUTE otherwise.
X
X REQUIRE_ORDER means don't recognize them as options.
X Stop option processing when the first non-option is seen.
X This is what Unix does.
X
X PERMUTE is the default. We permute the contents of ARGV as we scan,
X so that eventually all the options are at the end. This allows options
X to be given in any order, even with programs that were not written to
X expect this.
X
X RETURN_IN_ORDER is an option available to programs that were written
X to expect options and other ARGV-elements in any order and that care about
X the ordering of the two. We describe each non-option ARGV-element
X as if it were the argument of an option with character code one.
X Using `-' as the first character of the list of option characters
X requests this mode of operation.
X
X The special argument `--' forces an end of option-scanning regardless
X of the value of `ordering'. In the case of RETURN_IN_ORDER, only
X `--' can cause `getopt' to return EOF with `optind' != ARGC. */
X
static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering;
X
/* Describe the long-named options requested by the application.
X _GETOPT_LONG_OPTIONS is a vector of `struct option' terminated by an
X element containing a name which is zero.
X The field `has_arg' is 1 if the option takes an argument,
X 2 if it takes an optional argument. */
X
struct option
{
X char *name;
X int has_arg;
X int *flag;
X int val;
};
X
CONST struct option *_getopt_long_options;
X
int _getopt_long_only = 0;
X
/* Index in _GETOPT_LONG_OPTIONS of the long-named option actually found.
X Only valid when a long-named option was found. */
X
int option_index;
X
/* Handle permutation of arguments. */
X
/* Describe the part of ARGV that contains non-options that have
X been skipped. `first_nonopt' is the index in ARGV of the first of them;
X `last_nonopt' is the index after the last of them. */
X
static int first_nonopt;
static int last_nonopt;
X
/* Exchange two adjacent subsequences of ARGV.
X One subsequence is elements [first_nonopt,last_nonopt)
X which contains all the non-options that have been skipped so far.
X The other is elements [last_nonopt,optind), which contains all
X the options processed since those non-options were skipped.
X
X `first_nonopt' and `last_nonopt' are relocated so that they describe
X the new indices of the non-options in ARGV after they are moved. */
X
static void
exchange (argv)
X char **argv;
{
X int nonopts_size
X = (last_nonopt - first_nonopt) * sizeof (char *);
X char **temp = (char **) alloca (nonopts_size);
X
X /* Interchange the two blocks of data in argv. */
X
X bcopy (&argv[first_nonopt], temp, nonopts_size);
X bcopy (&argv[last_nonopt], &argv[first_nonopt],
X (optind - last_nonopt) * sizeof (char *));
X bcopy (temp, &argv[first_nonopt + optind - last_nonopt],
X nonopts_size);
X
X /* Update records for the slots the non-options now occupy. */
X
X first_nonopt += (optind - last_nonopt);
X last_nonopt = optind;
}
X
/* Scan elements of ARGV (whose length is ARGC) for option characters
X given in OPTSTRING.
X
X If an element of ARGV starts with '-', and is not exactly "-" or "--",
X then it is an option element. The characters of this element
X (aside from the initial '-') are option characters. If `getopt'
X is called repeatedly, it returns successively each of the option characters
X from each of the option elements.
X
X If `getopt' finds another option character, it returns that character,
X updating `optind' and `nextchar' so that the next call to `getopt' can
X resume the scan with the following option character or ARGV-element.
X
X If there are no more option characters, `getopt' returns `EOF'.
X Then `optind' is the index in ARGV of the first ARGV-element
X that is not an option. (The ARGV-elements have been permuted
X so that those that are not options now come last.)
X
X OPTSTRING is a string containing the legitimate option characters.
X If an option character is seen that is not listed in OPTSTRING,
X return '?' after printing an error message. If you set `opterr' to
X zero, the error message is suppressed but we still return '?'.
X
X If a char in OPTSTRING is followed by a colon, that means it wants an arg,
X so the following text in the same ARGV-element, or the text of the following
X ARGV-element, is returned in `optarg'. Two colons mean an option that
X wants an optional arg; if there is text in the current ARGV-element,
X it is returned in `optarg', otherwise `optarg' is set to zero.
X
X If OPTSTRING starts with `-', it requests a different method of handling the
X non-option ARGV-elements. See the comments about RETURN_IN_ORDER, above.
X
X Long-named options begin with `+' instead of `-'.
X Their names may be abbreviated as long as the abbreviation is unique
X or is an exact match for some defined option. If they have an
X argument, it follows the option name in the same ARGV-element, separated
X from the option name by a `=', or else the in next ARGV-element.
X `getopt' returns 0 when it finds a long-named option. */
X
int
getopt (argc, argv, optstring)
X int argc;
X char **argv;
X CONST char *optstring;
{
X optarg = 0;
X
X /* Initialize the internal data when the first call is made.
X Start processing options with ARGV-element 1 (since ARGV-element 0
X is the program name); the sequence of previously skipped
X non-option ARGV-elements is empty. */
X
X if (optind == 0)
X {
X first_nonopt = last_nonopt = optind = 1;
X
X nextchar = 0;
X
X /* Determine how to handle the ordering of options and nonoptions. */
X
X if (optstring[0] == '-')
X ordering = RETURN_IN_ORDER;
X else if (getenv ("_POSIX_OPTION_ORDER") != 0)
X ordering = REQUIRE_ORDER;
X else
X ordering = PERMUTE;
X }
X
X if (nextchar == 0 || *nextchar == 0)
X {
X if (ordering == PERMUTE)
X {
X /* If we have just processed some options following some non-options,
X exchange them so that the options come first. */
X
X if (first_nonopt != last_nonopt && last_nonopt != optind)
X exchange (argv);
X else if (last_nonopt != optind)
X first_nonopt = optind;
X
X /* Now skip any additional non-options
X and extend the range of non-options previously skipped. */
X
X while (optind < argc
X && (argv[optind][0] != '-'
X || argv[optind][1] == 0)
X && (_getopt_long_options == 0
X || argv[optind][0] != '+'
X || argv[optind][1] == 0))
X optind++;
X last_nonopt = optind;
X }
X
X /* Special ARGV-element `--' means premature end of options.
X Skip it like a null option,
X then exchange with previous non-options as if it were an option,
X then skip everything else like a non-option. */
X
X if (optind != argc && !strcmp (argv[optind], "--"))
X {
X optind++;
X
X if (first_nonopt != last_nonopt && last_nonopt != optind)
X exchange (argv);
X else if (first_nonopt == last_nonopt)
X first_nonopt = optind;
X last_nonopt = argc;
X
X optind = argc;
X }
X
X /* If we have done all the ARGV-elements, stop the scan
X and back over any non-options that we skipped and permuted. */
X
X if (optind == argc)
X {
X /* Set the next-arg-index to point at the non-options
X that we previously skipped, so the caller will digest them. */
X if (first_nonopt != last_nonopt)
X optind = first_nonopt;
X return EOF;
X }
X
X /* If we have come to a non-option and did not permute it,
X either stop the scan or describe it to the caller and pass it by. */
X
X if ((argv[optind][0] != '-' || argv[optind][1] == 0)
X && (_getopt_long_options == 0
X || argv[optind][0] != '+' || argv[optind][1] == 0))
X {
X if (ordering == REQUIRE_ORDER)
X return EOF;
X optarg = argv[optind++];
X return 1;
X }
X
X /* We have found another option-ARGV-element.
X Start decoding its characters. */
X
X nextchar = argv[optind] + 1;
X }
X
X if (_getopt_long_options != 0
X && (argv[optind][0] == '+'
X || (_getopt_long_only && argv[optind][0] == '-'))
X )
X {
X CONST struct option *p;
X char *s = nextchar;
X int exact = 0;
X int ambig = 0;
X CONST struct option *pfound = 0;
X int indfound;
X
X while (*s && *s != '=') s++;
X
X /* Test all options for either exact match or abbreviated matches. */
X for (p = _getopt_long_options, option_index = 0; p->name;
X p++, option_index++)
X if (!strncmp (p->name, nextchar, s - nextchar))
X {
X if (s - nextchar == strlen (p->name))
X {
X /* Exact match found. */
X pfound = p;
X indfound = option_index;
X exact = 1;
X break;
X }
X else if (pfound == 0)
X {
X /* First nonexact match found. */
X pfound = p;
X indfound = option_index;
X }
X else
X /* Second nonexact match found. */
X ambig = 1;
X }
X
X if (ambig && !exact)
X {
X fprintf (stderr, "%s: option `%s' is ambiguous\n",
X argv[0], argv[optind]);
X nextchar += strlen (nextchar);
X return '?';
X }
X
X if (pfound != 0)
X {
X option_index = indfound;
X optind++;
X if (*s)
X {
X if (pfound->has_arg > 0)
X optarg = s + 1;
X else
X {
X fprintf (stderr,
X "%s: option `%c%s' doesn't allow an argument\n",
X argv[0], argv[optind - 1][0], pfound->name);
X nextchar += strlen (nextchar);
X return '?';
X }
X }
X else if (pfound->has_arg == 1)
X {
X if (optind < argc)
X optarg = argv[optind++];
X else
X {
X fprintf (stderr, "%s: option `%s' requires an argument\n",
X argv[0], argv[optind - 1]);
X nextchar += strlen (nextchar);
X return '?';
X }
X }
X nextchar += strlen (nextchar);
X if (pfound->flag)
X *(pfound->flag) = pfound->val;
X return 0;
X }
X /* Can't find it as a long option. If this is getopt_long_only,
X and the option starts with '-' and is a valid short
X option, then interpret it as a short option. Otherwise it's
X an error. */
X if (_getopt_long_only == 0 || argv[optind][0] == '+' ||
X index (optstring, *nextchar) == 0)
X {
X if (opterr != 0)
X fprintf (stderr, "%s: unrecognized option `%c%s'\n",
X argv[0], argv[optind][0], nextchar);
X nextchar += strlen (nextchar);
X return '?';
X }
X }
X
X /* Look at and handle the next option-character. */
X
X {
X char c = *nextchar++;
X char *temp = index (optstring, c);
X
X /* Increment `optind' when we start to process its last character. */
X if (*nextchar == 0)
X optind++;
X
X if (temp == 0 || c == ':')
X {
X if (opterr != 0)
X {
X if (c < 040 || c >= 0177)
X fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
X argv[0], c);
X else
X fprintf (stderr, "%s: unrecognized option `-%c'\n",
X argv[0], c);
X }
X return '?';
X }
X if (temp[1] == ':')
X {
X if (temp[2] == ':')
X {
X /* This is an option that accepts an argument optionally. */
X if (*nextchar != 0)
X {
X optarg = nextchar;
X optind++;
X }
X else
X optarg = 0;
X nextchar = 0;
X }
X else
X {
X /* This is an option that requires an argument. */
X if (*nextchar != 0)
X {
X optarg = nextchar;
X /* If we end this ARGV-element by taking the rest as an arg,
X we must advance to the next element now. */
X optind++;
X }
X else if (optind == argc)
X {
X if (opterr != 0)
X fprintf (stderr, "%s: option `-%c' requires an argument\n",
X argv[0], c);
X c = '?';
X }
X else
X /* We already incremented `optind' once;
X increment it again when taking next ARGV-elt as argument. */
X optarg = argv[optind++];
X nextchar = 0;
X }
X }
X return c;
X }
}
X
#ifdef TEST
X
/* Compile with -DTEST to make an executable for use in testing
X the above definition of `getopt'. */
X
int
main (argc, argv)
X int argc;
X char **argv;
{
X char c;
X int digit_optind = 0;
X
X while (1)
X {
X int this_option_optind = optind;
X if ((c = getopt (argc, argv, "abc:d:0123456789")) == EOF)
X break;
X
X switch (c)
X {
X case '0':
X case '1':
X case '2':
X case '3':
X case '4':
X case '5':
X case '6':
X case '7':
X case '8':
X case '9':
X if (digit_optind != 0 && digit_optind != this_option_optind)
X printf ("digits occur in two different argv-elements.\n");
X digit_optind = this_option_optind;
X printf ("option %c\n", c);
X break;
X
X case 'a':
X printf ("option a\n");
X break;
X
X case 'b':
X printf ("option b\n");
X break;
X
X case 'c':
X printf ("option c with value `%s'\n", optarg);
X break;
X
X case '?':
X break;
X
X default:
X printf ("?? getopt returned character code 0%o ??\n", c);
X }
X }
X
X if (optind < argc)
X {
X printf ("non-option ARGV-elements: ");
X while (optind < argc)
X printf ("%s ", argv[optind++]);
X printf ("\n");
X }
X
X return 0;
}
X
#endif /* TEST */
SHAR_EOF
chmod 0444 getopt.c ||
echo 'restore of getopt.c failed'
Wc_c="`wc -c < 'getopt.c'`"
test 16005 -eq "$Wc_c" ||
echo 'getopt.c: original size 16005, current size' "$Wc_c"
fi
# ============= getopt1.c ==============
if test -f 'getopt1.c' -a X"$1" != X"-c"; then
echo 'x - skipping getopt1.c (File already exists)'
else
echo 'x - extracting getopt1.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'getopt1.c' &&
/* Getopt for GNU.
X Copyright (C) 1987, 1989 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 1, or (at your option)
X any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#include "getopt.h"
X
#ifdef __STDC__
#define CONST const
#else
#define CONST
#endif
X
int
getopt_long (argc, argv, options, long_options, opt_index)
X int argc;
X char **argv;
X CONST char *options;
X CONST struct option *long_options;
X int *opt_index;
{
X int val;
X
X _getopt_long_options = long_options;
X val = getopt (argc, argv, options);
X if (val == 0)
X *opt_index = option_index;
X return val;
}
X
/* Like getopt_long, but '-' as well as '+' can indicate a long option.
X If an option that starts with '-' doesn't match a long option,
X but does match a short option, it is parsed as a short option
X instead. */
X
int getopt_long_only (argc, argv, options, long_options, opt_index)
X int argc;
X char **argv;
X CONST char *options;
X CONST struct option *long_options;
X int *opt_index;
{
X int val;
X
X _getopt_long_options = long_options;
X _getopt_long_only = 1;
X val = getopt (argc, argv, options);
X if (val == 0)
X *opt_index = option_index;
X return val;
}
X
X
#ifdef TEST
X
#include <stdio.h>
X
int
main (argc, argv)
X int argc;
X char **argv;
{
X char c;
X int digit_optind = 0;
X
X while (1)
X {
X int this_option_optind = optind;
X char *name = '\0';
X int option_index = 0;
X static struct option long_options[]
X = {{ "add", 1, 0, 0 },
X { "append", 0, 0, 0 },
X { "delete", 1, 0, 0 },
X { "verbose", 0, 0, 0 },
X { "create", 0, 0, 0 },
X { "file", 1, 0, 0 },
X { 0, 0, 0, 0}};
X
X c = getopt_long (argc, argv, "abc:d:0123456789",
X long_options, &option_index);
X if (c == EOF)
X break;
X switch (c)
X {
X case 0:
X printf ("option %s", (long_options[option_index]).name);
X if (optarg)
X printf (" with arg %s", optarg);
X printf ("\n");
X break;
X
X case '0':
X case '1':
X case '2':
X case '3':
X case '4':
X case '5':
X case '6':
X case '7':
X case '8':
X case '9':
X if (digit_optind != 0 && digit_optind != this_option_optind)
X printf ("digits occur in two different argv-elements.\n");
X digit_optind = this_option_optind;
X printf ("option %c\n", c);
X break;
X
X case 'a':
X printf ("option a\n");
X break;
X
X case 'b':
X printf ("option b\n");
X break;
X
X case 'c':
X printf ("option c with value `%s'\n", optarg);
X break;
X
X case '?':
X break;
X
X default:
X printf ("?? getopt returned character code 0%o ??\n", c);
X }
X }
X
X if (optind < argc)
X {
X printf ("non-option ARGV-elements: ");
X while (optind < argc)
X printf ("%s ", argv[optind++]);
X printf ("\n");
X }
X
X return 0;
}
X
#endif /* TEST */
SHAR_EOF
chmod 0444 getopt1.c ||
echo 'restore of getopt1.c failed'
Wc_c="`wc -c < 'getopt1.c'`"
test 3378 -eq "$Wc_c" ||
echo 'getopt1.c: original size 3378, current size' "$Wc_c"
fi
# ============= getopt.h ==============
if test -f 'getopt.h' -a X"$1" != X"-c"; then
echo 'x - skipping getopt.h (File already exists)'
else
echo 'x - extracting getopt.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'getopt.h' &&
/* declarations for getopt
X Copyright (C) 1989 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 1, or (at your option)
X any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
X
/* For communication from `getopt' to the caller.
X When `getopt' finds an option that takes an argument,
X the argument value is returned here.
X Also, when `ordering' is RETURN_IN_ORDER,
X each non-option ARGV-element is returned here. */
X
extern char *optarg;
X
/* Index in ARGV of the next element to be scanned.
X This is used for communication to and from the caller
X and for communication between successive calls to `getopt'.
X
X On entry to `getopt', zero means this is the first call; initialize.
X
X When `getopt' returns EOF, this is the index of the first of the
X non-option elements that the caller should itself scan.
X
X Otherwise, `optind' communicates from one call to the next
X how much of ARGV has been scanned so far. */
X
extern int optind;
X
/* Callers store zero here to inhibit the error message `getopt' prints
X for unrecognized options. */
X
extern int opterr;
X
/* Describe the long-named options requested by the application.
X _GETOPT_LONG_OPTIONS is a vector of `struct option' terminated by an
X element containing a name which is zero.
X The field `has_arg' is:
X 0 if the option does not take an argument,
X 1 if the option requires an argument,
X 2 if the option takes an optional argument.
X If the field `flag' is nonzero, it points to a variable that is set to
X the value given in the field `val' when the option is found, but
X left unchanged if the option is not found. */
X
struct option
{
X char *name;
X int has_arg;
X int *flag;
X int val;
};
X
#ifdef __STDC__
extern const struct option *_getopt_long_options;
#else
extern struct option *_getopt_long_options;
#endif
X
/* If nonzero, tell getopt that '-' means a long option.
X Set by getopt_long_only. */
extern int _getopt_long_only;
X
/* The index in GETOPT_LONG_OPTIONS of the long-named option found.
X Only valid when a long-named option has been found by the most
X recent call to `getopt'. */
X
extern int option_index;
X
#ifdef __STDC__
int getopt (int argc, char **argv, const char *shortopts);
int getopt_long (int argc, char **argv, const char *shortopts,
X const struct option *longopts, int *longind);
int getopt_long_only (int argc, char **argv, const char *shortopts,
X const struct option *longopts, int *longind);
void envopt(int *pargc, char ***pargv, char *optstr);
#else
int getopt ();
int getopt_long ();
int getopt_long_only ();
void envopt();
#endif
SHAR_EOF
chmod 0444 getopt.h ||
echo 'restore of getopt.h failed'
Wc_c="`wc -c < 'getopt.h'`"
test 3161 -eq "$Wc_c" ||
echo 'getopt.h: original size 3161, current size' "$Wc_c"
fi
# ============= patchlevel.h ==============
if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
echo 'x - skipping patchlevel.h (File already exists)'
else
echo 'x - extracting patchlevel.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
/* $Id: patchlevel.h,v 3.3 1991/09/01 14:03:43 piggy Rel $
X * Release and patchlevel string.
X *
X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 1, or (at your option)
X * any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
#define RELEASE "3.3"
SHAR_EOF
chmod 0444 patchlevel.h ||
echo 'restore of patchlevel.h failed'
Wc_c="`wc -c < 'patchlevel.h'`"
test 892 -eq "$Wc_c" ||
echo 'patchlevel.h: original size 892, current size' "$Wc_c"
fi
# ============= tua.man ==============
if test -f 'tua.man' -a X"$1" != X"-c"; then
echo 'x - skipping tua.man (File already exists)'
else
echo 'x - extracting tua.man (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'tua.man' &&
''' $Header: /usr/src/piggy/tua/RCS/tua.man,v 3.3 1991/09/01 14:03:45 piggy Rel $
'''
''' Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
'''
''' 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
''' the Free Software Foundation; either version 1, or (at your option)
''' any later version.
'''
''' This program is distributed in the hope that it will be useful,
''' but WITHOUT ANY WARRANTY; without even the implied warranty of
''' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
''' GNU General Public License for more details.
'''
''' You should have received a copy of the GNU General Public License
''' along with this program; if not, write to the Free Software
''' Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
'''
''' The next definitions are from Larry Wall's perl manual pages.
.de Sh
.br
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp
.if t .sp .5v
.if n .sp
..
.de Ip
.br
.ie \\n.$>=3 .ne \\$3
.el .ne 3
.IP "\\$1" \\$2
..
'''
''' Set up \*(-- to give an unbreakable dash;
''' string Tr holds user defined translation string.
''' Bell System Logo is used as a dummy character.
'''
.tr \(*W-|\(bv\*(Tr
.ie n \{\
.ds -- \(*W-
.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
.ds L" ""
.ds R" ""
.ds L' '
.ds R' '
'br\}
.el\{\
.ds -- \(em\|
.tr \*(Tr
.ds L" ``
.ds R" ''
.ds L' `
.ds R' '
'br\}
.TH TUA 1L "1 September 1991" "Release 3.3" "LOCAL USER COMMANDS"
.SH NAME
TUA \- The Uucp Analyzer
.SH SYNOPSIS
.B tua
[ option ]
.SH DESCRIPTION
.LP
The purpose of the
.I TUA
utility is to produce a readable and complete analysis of the
.IR HoneyDanbeer
UUCP connections.
This manual page describes the
.I TUA
command line options and shortly explains its output.
.SH OPTIONS
To specify any of the options, you can use either the short form or the
more mnemonic long form. In the latter case, you can abbreviate the name
as long as it is unique. For more information on the long format, please
refer to the
.IR "GNU getopt"
package description.
.sp 1
.TP 0.5i
.B \-S, +no-sys-rep
Do not print the
.BR "per System report" .
The default is to print it out.
.TP 0.5i
.B \-U, +no-user-rep
Do not print the
.BR "per User report" .
The default is to print it out.
.TP 0.5i
.B \-D, +no-daily-rep
Do not print the
.BR "Daily report" .
The default is to print it out.
.TP 0.5i
.B \-C, +command-lists
Show also the command lists. It is off by default because it makes TUA very
hungry of memory.
.TP 0.5i
.BI "\-O, +only-system " SYSTEM
Consider just system
.I SYSTEM
in the reports. You can specify more than one of this option, so you can have
TUA consider just those systems.
.TP 0.5i
.B \-m, +no-monthly-act
Do not output the last 12 months activity summary.
.TP 0.5i
.B \-h, +no-history
Do not output the history at the end of the reports.
.TP 0.5i
.B \-c, +separate-com
Separate command lists from the other data. So there will be two tables
with the header
.I "By System" ,
the first containing only the amounts and the timing of each transfer,
the second with all the commands invoked by each System. You must specify
also the
.B \-C
option to make it works.
.TP 0.5i
.BI "\-k, +kill-system " SYSTEM
Eliminate each reference to
.I SYSTEM
from the reports. Neither the transfer table nor the
.I SYSTEM
command list will be printed.
.TP 0.5i
.BI "\-K, +kill-user " USER
Like
.B \-k
, but it applies to the user called
.I USER .
.TP 0.5i
.B \-H, +update-hist
Update the
.I history
database (see the FILES section below) with the new values. You must have
the
.B uucp
write permission.
.TP 0.5i
.B \-0, +reset-hist
Reset the
.I history
database, deleting any systems in it. Then put in the database the
analysis since the last
.I uuclean .
You have to specify also
.B \-H
to make this option do his job.
.TP 0.5i
.B \-y, +no-hourly-chart
Do not display the hourly activity chart.
.TP 0.5i
.BI "-z, +chart-size " SIZE
Set the size of the hourly activity chart to
.I SIZE
rows. The greater is this number, the smaller is the scale. By default it
is set to 10.
.TP 0.5i
.B \-o, +chart-only
Display only the hourly activity chart. Since with this options
.I TUA
reads only
.BR .Admin/xferstats ,
it is faster.
.TP 0.5i
.B \-v, +verbose
Print, on standard error, what is going on. While
.I TUA
reads the various logs, it displays a counter of the loaded lines.
.TP 0.5i
.BI "\-p, +prefix-path " PATH
By default,
.I TUA
looks for uucp data in
.BR "/usr/spool/uucp/"
and in the relative subdirectory. For debugging purpose, this option lets you
change this directory, so that
.I TUA
looks for the data in the specified
.I PATH.
Below this point
.I TUA
needs a hierarchy like the standard one (see FILES below).
.TP 0.5i
.B \-i, +help
Show a summary and a description of all the options.
.SH OUTPUT
All reports are printed on the standard output, so you can easily
redirect them wherever you want. Assuming, unless otherwise stated,
that you do not explicity request to disable some of the reports
(eg. when you do not specify
any command line option), here is a short description of what you get.
.Sh "By System"
With this report, you get all the information relative to all the
nodes that talk with your machine but those which didn't sent or received
something. The data are divided in
.I inbound
and
.I outbound.
For each system, displayed in alphabetical order, you have the total
count of the files transferred, with the relative
bytes and times, as well as an average transfer rate (ATP).
If
.B \+commands-lists
was specified, next there is
the list of the commands invoked by that node, or directed to it. If a
command is preceeded by a number between brackets, that number indicates how
many times that command was invoked.
.Sh "By User"
This report is similar to the previous one, but it shows, in
alphabetical order for each local user, all the commands the user invoked,
and the transfers he caused.
.Sh "By Day"
This report summarize the per day activity on the local machine. It doesn't
depend on the destinations and on the users.
.Sh "SUMMARY by System"
It shows a summary of the activity of each system, and the number of calls
(inbound and outbound) for it. Please note that sometimes
.I TUA
fails in calculating the exact number of calls, because of the misleading
log of uucico. Note also that the "total connection time" always differs from
the sum of the trasmissions times, because it takes care also of the various
uucp dead time. In fact, it is calculated from the difference between
the time in which the nodes are really connected (ie. at the end of dial
phase, when the modem answers) and the time in which the link is dropped,
due to the the end of the conversation as well as to any error.
Then comes the time of the last connection with that system.
There is also the subdivision of the connection time based on the phone
costs, ie "day", "evening", "night". This is completely configurable,
so if your telephone company uses a different hourly division you can
adjust it (see
.BR config.h
and
.BR phonesw.c .)
.Sh "SUMMARY by System (table format)"
Substancially, this report summarizes some of the previous informations in a
tabular form. Nothing new...
.Sh "and since ..."
This is the historical data maintained by
.I TUA.
It looks like the previous table, but it includes the history
of the system, incrementally.
.Sh "Last 12 Months Activity"
This table shows the activity of the local machine during the last 12 months.
Only the transferred amounts are computed.
.br
The months are displayed in a manner so that the last column contains the
current one, so it is very readable (of course, it is a matter of opinions!)
.Sh "Hourly Activity (per communication port)"
This chart shows the uucp hourly load for each used communication port.
Each hour is divided in 20 minutes slices.
.Sh "Global Hourly Activity"
The same as the previous chart, but it reports the sums of all the ports.
.SH HISTORY
.I TUA
maintains a database with the history of each system and of the activity
in each of the last 12 months
activities. It is usually located in
.BR /usr/spool/uucp/.Admin/tua.history
and it is actually an ASCII file. It is up to you to update it or not, because
probably you will like to run
.I TUA
simply to have a notion of what is going on. To make it working correctly,
you have to run
.I TUA
with the option
.BR +update-hist
just before you run uuclean. So probably you will have to modify that
script including in it a line like
.nf
X
X tua +update-hist {whatever options you like} | mail lele
X
.fi
before it cleans up the uucp logs.
.SH BUGS
Since HDB\-Uucp doesn't put a complete datestamp in its logs, but omits
the year, it may be possible that
.IR TUA
fails to compute the various times in the first analysis of the year.
This is in my opinion its major weakness. For this silliness,
.IR TUA
cannot correctly handle logs that cover several years. There is little
that I can do to correct the situation; I tried to adjust the year
when the to\-be\-parsed date refers obviously to the previous year,
but this is just a work\-around...
.PP
There is a limit: if your system spent more than 9999 hours
linked with someone (or the sum exceed that value), the reports will be
garbaged...
.SH DISCLAIMER
.I TUA
is
.BR free ,
and it is redistribuitable under the terms of the GNU
General Public License. You can find a copy of it in the file
.BR COPYING
in the distribution package.
I reject any responsability about it. It is simple and safe, but
I did not try it under all the possible conditions and environments, so if it
causes you some trouble, I'll be sad for a while, but that's it. However,
I will try to correct any bugs you will tell me.
.PP
And
.BR please,
forgive my poor english, but I put my soul in it...
.SH AUTHOR
Lele Gaifas, Idea Informatica, Rovereto (TN) - Italy
.br
( piggy@idea.sublink.org )
.SH FILES
X .../.Log/uucico/* uucico's logs
X .../.Log/uucp/* uucp's logs
X .../.Log/uux/* uux's logs
X .../.Log/uuxqt/* uuxqt's logs
X .../.Admin/xferstat Transfer stats
X .../.Admin/tua.history TUA's system history
.SH BUGS REPORT TO
Lele Gaifas, piggy@idea.sublink.org
.SH ACKNOLEDGMENT
I want to thank expecially Marco Lorenzini
(marlor@gear.sublink.org) for his help in debugging the previous
releases of
.I TUA
on the SCO Unix architecture, and for his suggestions on the layout of
the reports. And to the "omnipresent" Paolo Ventafridda
(venta@i2ack.sublink.org) for his support and interest, and several
other people that encouraged me to add more and more functionality, or
that let me scan their huge logs.
.br
Thanks also to all the people that, with their PD or GPL software, helped
me indirectly with ideas or examples.
SHAR_EOF
chmod 0444 tua.man ||
echo 'restore of tua.man failed'
Wc_c="`wc -c < 'tua.man'`"
test 10875 -eq "$Wc_c" ||
echo 'tua.man: original size 10875, current size' "$Wc_c"
fi
# ============= porttree.c ==============
if test -f 'porttree.c' -a X"$1" != X"-c"; then
echo 'x - skipping porttree.c (File already exists)'
else
echo 'x - extracting porttree.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'porttree.c' &&
/* $Id: porttree.c,v 3.3 1991/09/01 14:03:49 piggy Rel $
X * Port tree management
X *
X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 1, or (at your option)
X * any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *
X * SYNOPSIS:
X * int InsertPort(char * port)
X * Look for port in the tree. If it is already there, return a pointer
X * to its info. Otherwise make a new entry and initialize it.
X *
X * void EnquiryPort(void (*funct)(portact_t port))
X * For each node in the tree, process it through funct.
X *
X * void KillPort(char * port)
X * Do not show that port in any report.
X *
X */
X
#include <stdio.h>
#include "mem.h"
#include <string.h>
#include "hdbstat.h"
X
typedef struct porttree
{
X portact_t Node;
X struct porttree *L;
X struct porttree *R;
} porttree_t;
X
#define TNULL (porttree_t *) NULL
X
static FlistHead PortFlist =
{
X 0, 0, 0
};
X
static porttree_t *Root = TNULL;
X
static portact_t *
PortTree (tree, port)
X porttree_t **tree;
X char *port;
{
X int cmpres;
X
X if (*tree == TNULL)
X {
X register portact_t *sr;
X int idx;
X
X if (PortFlist.size == 0)
X MemInit (&PortFlist, sizeof (porttree_t), 5, 5);
X *tree = (porttree_t *) new (&PortFlist);
X (*tree)->L = (*tree)->R = TNULL;
X sr = &((*tree)->Node);
X sr->Port = strdup (port);
X sr->Killed = FALSE;
X for (idx = 0; idx < TIMESLICES; idx++)
X sr->Activity[idx] = 0.0;
X return (&(*tree)->Node);
X }
X else if ((cmpres = strcmp (port, (*tree)->Node.Port)) < 0)
X return PortTree (&(*tree)->L, port);
X else if (cmpres > 0)
X return PortTree (&(*tree)->R, port);
X else
X return (&(*tree)->Node);
}
X
portact_t *
InsertPort (port)
X char *port;
{
X return PortTree (&Root, port);
}
X
void
KillPort (port)
X char *port;
{
X PortTree (&Root, port)->Killed = TRUE;
}
X
static void
ProcPortTree (tree, funct)
X porttree_t *tree;
X void (*funct) ();
{
X if (tree != TNULL)
X {
X ProcPortTree (tree->L, funct);
X if (!(tree->Node.Killed))
X (*funct) (tree->Node);
X ProcPortTree (tree->R, funct);
X }
}
X
void
EnquiryPort (funct)
X void (*funct) ();
{
X ProcPortTree (Root, funct);
}
SHAR_EOF
chmod 0444 porttree.c ||
echo 'restore of porttree.c failed'
Wc_c="`wc -c < 'porttree.c'`"
test 2763 -eq "$Wc_c" ||
echo 'porttree.c: original size 2763, current size' "$Wc_c"
fi
# ============= phonesw.c ==============
if test -f 'phonesw.c' -a X"$1" != X"-c"; then
echo 'x - skipping phonesw.c (File already exists)'
else
echo 'x - extracting phonesw.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'phonesw.c' &&
/* $Id: phonesw.c,v 3.3 1991/09/01 14:03:52 piggy Rel $
X * Return an index based on the day, hour and minute we are working
X *
X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 1, or (at your option)
X * any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *
X * SYNOPSIS:
X * int GetPhonePrice(int day, int hour, int minute)
X * Return an index in PHONE_PRICING_TB_NAMES, calculated from day, hour,
X * minute.
X *
X * NOTE: Probably you'll need to customize this function for your country.
X * Please, include your code, if any, between ifdefs, as I did, and
X * send me the diffs, so I can keep this file up to date ;-)
X */
X
#include "hdbstat.h"
X
/*
X * ITALY
X */
#ifdef ITALY
X
#define PEAK_TIME 0
#define NORMAL_TIME 1
#define EVENING_TIME 2
#define NIGHT_TIME 3
X
char *PhoneCategoryNames[] =
{
X "Peak Time ", /* 8:30am to 1pm */
X "Normal Time ", /* 8am to 8:30am, 1pm to 6:30pm */
X "Evening Time", /* 6:30pm to 10pm */
X "Night Time " /* 10pm to 8 am */
};
X
/*
X * This function get the Day of the Week, the Hour, and the Minute, and
X * return an integer indicating in which timebelt we are.
X */
X
int
GetPhonePrice (day, hour, min)
X int day, hour, min;
X
{
X int retvalue;
X
X switch (day)
X {
X case 0: /* Sunday */
X retvalue = ((hour < 8 || hour >= 22) ? NIGHT_TIME : EVENING_TIME);
X break;
X
X case 1:
X case 2:
X case 3:
X case 4:
X case 5:
X if (hour < 8 || hour >= 22)
X retvalue = NIGHT_TIME;
X else if (hour > 18 || (hour == 18 && min >= 30))
X retvalue = EVENING_TIME;
X else if ((hour > 8 && hour < 13) || (hour == 8 && min >= 30))
X retvalue = PEAK_TIME;
X else retvalue = NORMAL_TIME;
X break;
X
X case 6: /* Saturday */
X if (hour < 8 || hour >= 22)
X retvalue = NIGHT_TIME;
X else if (hour >= 8 && hour < 13)
X retvalue = PEAK_TIME;
X else retvalue = EVENING_TIME;
X break;
X }
X return retvalue;
}
X
#undef PEAK_TIME
#undef NORMAL_TIME
#undef EVENING_TIME
#undef NIGHT_TIME
#endif /* ifdef ITALY */
X
/*
X * UNITED KINGDOM
X */
#ifdef UK
X
#define UK_PEAK 0
#define UK_NORMAL 1
#define UK_CHEAP 2
X
char *PhoneCategoryNames[] =
{
X "Peak Rate ", /* UK_PEAK 9:00am to 1pm */
X "Normal Rate ", /* UK_NORMAL 8am to 9.00am, 1pm to 6:00pm */
X "Cheap Rate " /* UK_CHEAP 6pm to 8 am */
};
X
/*
X * This function get the Day of the Week, the Hour, and the Minute, and
X * return an integer indicating in which timebelt we are.
X */
X
int
GetPhonePrice (day, hour, min)
X int day, hour, min;
X
{
X int retvalue;
X
X switch (day)
X {
X case 0: /* Sunday */
X case 6: /* Saturday */
X retvalue = UK_CHEAP;
X break;
X
X case 1:
X case 2:
X case 3:
X case 4:
X case 5:
X if (hour < 8 || hour >= 18)
X retvalue = UK_CHEAP;
X else if (hour >= 9 && hour < 13)
X retvalue = UK_PEAK;
X else
X retvalue = UK_NORMAL;
X break;
X }
X return retvalue;
}
X
#undef UK_PEAK
#undef UK_NORMAL
#undef UK_CHEAP
X
#endif /* ifdef UK */
X
SHAR_EOF
chmod 0444 phonesw.c ||
echo 'restore of phonesw.c failed'
Wc_c="`wc -c < 'phonesw.c'`"
test 3619 -eq "$Wc_c" ||
echo 'phonesw.c: original size 3619, current size' "$Wc_c"
fi
# ============= gethostn.c ==============
if test -f 'gethostn.c' -a X"$1" != X"-c"; then
echo 'x - skipping gethostn.c (File already exists)'
else
echo 'x - extracting gethostn.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'gethostn.c' &&
/*
X * From Cnews as of 1 Jan 91
X *
X * Uglix gethostname simulation
X */
X
#include <sys/types.h>
#include <sys/utsname.h>
X
#define min(a, b) ((a) < (b)? (a): (b))
X
int
gethostname (buf, size)
X char *buf;
X int size;
{
X struct utsname ugnm;
X char *strncpy ();
X
X if (uname (&ugnm) < 0)
X return -1;
X (void) strncpy (buf, ugnm.nodename, min (sizeof ugnm.nodename, size));
X return 0;
}
SHAR_EOF
chmod 0444 gethostn.c ||
echo 'restore of gethostn.c failed'
Wc_c="`wc -c < 'gethostn.c'`"
test 394 -eq "$Wc_c" ||
echo 'gethostn.c: original size 394, current size' "$Wc_c"
fi
true || echo 'restore of tua.1l failed'
echo End of part 4, continue with part 5
exit 0
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD UUCP: uunet!sparky!kent
Phone: (402) 291-8300 FAX: (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.