|
v1_2_9
|
-v1_2_10
+v1_2_10 BRANCH_1_2_x
+BRANCHPT_1_2_x -------------+
+ | |
+v1_3_0 any future 1.2.x releases
+
+2006-03-20 Charles Wilson <cwilson@...>
+
+ bump version number to 1.3.0
+
+ * Makefile.am: remove programs, code, and documentation for
+ cal, col, colcrt, colrm, column, ddate, getopt, mcookie,
+ namei, rename, and rev. These programs now provided by
+ util-linux package.
+ * configure.ac: bump version number
+ * BRANCHES: update documentation
+ * NEWS: update documentation
+ * PROGLIST: update documentation
+ * README: update documentation
+ * src/cal/README.cal: removed
+ * src/cal/cal.1: removed
+ * src/cal/cal.c: removed
+ * src/cal/err.c: removed
+ * src/cal/errs.h: removed
+ * src/cal/widechar.h: removed
+ * src/col/README.col: removed
+ * src/col/col.1: removed
+ * src/col/col.c: removed
+ * src/col/err.c: removed
+ * src/col/err.h: removed
+ * src/colcrt/colcrt.1: removed
+ * src/colcrt/colcrt.c: removed
+ * src/colcrt/widechar.h: removed
+ * src/colrm/colrm.1: removed
+ * src/colrm/colrm.c: removed
+ * src/colrm/widechar.h: removed
+ * src/column/column.1: removed
+ * src/column/column.c: removed
+ * src/column/err.c: removed
+ * src/column/errs.h: removed
+ * src/column/widechar.h: removed
+ * src/ddate/ddate.1: removed
+ * src/ddate/ddate.c: removed
+ * src/ddate/ddate.doc: removed
+ * src/getopt/getopt.1: removed
+ * src/getopt/getopt.c: removed
+ * src/getopt/parse.bash: removed
+ * src/getopt/parse.tcsh: removed
+ * src/getopt/test.bash: removed
+ * src/getopt/test.tcsh: removed
+ * src/mcookie/mcookie.1: removed
+ * src/mcookie/mcookie.c: removed
+ * src/mcookie/md5.c: removed
+ * src/mcookie/md5.h: removed
+ * src/namei/README.namei: removed
+ * src/namei/README1.namei: removed
+ * src/namei/namei.1: removed
+ * src/namei/namei.c: removed
+ * src/rename/nls.h: removed
+ * src/rename/rename.1: removed
+ * src/rename/rename.c: removed
+ * src/rev/rev.1: removed
+ * src/rev/rev.c: removed
+ * src/rev/widechar.h: removed
+
2006-02-10 Charles Wilson <cwilson@...>
bump version number - 1.2.10
ipc_scripts = src/ipc/ipck
endif
-bin_PROGRAMS = src/ascii/ascii $(windows_progs) src/cal/cal src/conv/conv \
- src/ddate/ddate src/dump/dump $(ipc_progs) \
- src/namei/namei src/realpath/realpath src/col/col \
- src/getopt/getopt src/rev/rev src/column/column \
- src/colcrt/colcrt src/colrm/colrm src/mcookie/mcookie \
- src/rename/rename
+bin_PROGRAMS = src/ascii/ascii $(windows_progs) src/conv/conv \
+ src/dump/dump $(ipc_progs) \
+ src/realpath/realpath
bin_SCRIPTS = $(ipc_scripts)
-noinst_HEADERS = src/cal/errs.h src/cal/widechar.h \
- src/col/err.h src/rev/widechar.h \
- src/column/widechar.h src/column/errs.h \
- src/colcrt/widechar.h src/colrm/widechar.h src/mcookie/md5.h \
- src/lpr/Printer.hh src/lpr/PrinterException.hh src/lpr/Win32Utils.hh \
- src/rename/nls.h
+noinst_HEADERS = \
+ src/lpr/Printer.hh src/lpr/PrinterException.hh src/lpr/Win32Utils.hh
-man_MANS = src/cal/cal.1 src/cygstart/cygstart.1 src/ddate/ddate.1 \
+man_MANS = src/cygstart/cygstart.1 \
src/mkshortcut/mkshortcut.1 \
src/readshortcut/readshortcut.1 \
- src/namei/namei.1 src/col/col.1 src/getopt/getopt.1 \
- src/rev/rev.1 src/column/column.1 \
- src/colcrt/colcrt.1 src/colrm/colrm.1 src/mcookie/mcookie.1 \
- src/lpr/lpr.1 src/rename/rename.1
+ src/lpr/lpr.1
EXTRA_PROGRAMS = src/banner/banner src/clip/getclip src/clip/putclip \
src/cygstart/cygstart \
po/insert-header.sin po/quot.sed po/remove-potcdate.sin
extra_docs = \
- src/cal/README.cal src/ddate/ddate.doc src/namei/README.namei \
- src/namei/README1.namei src/col/README.col \
- src/getopt/parse.bash src/getopt/parse.tcsh \
- src/getopt/test.bash src/getopt/test.tcsh \
src/lpr/README
licenses = licenses/COPYING.BSD-no-advert licenses/COPYING.GPL
src_lpr_lpr_LDADD = -lwinspool
src_mkshortcut_mkshortcut_LDADD = -lole32 -luuid
src_readshortcut_readshortcut_LDADD = -lole32 -luuid
-src_cal_cal_LDADD = @LIBINTL@
-src_ddate_ddate_LDADD = @LIBINTL@
-src_namei_namei_LDADD = @LIBINTL@
-src_rev_rev_LDADD = @LIBINTL@
-src_column_column_LDADD = @LIBINTL@
-src_colcrt_colcrt_LDADD = @LIBINTL@
-src_mcookie_mcookie_LDADD = @LIBINTL@
-
-src_cal_cal_SOURCES = src/cal/cal.c src/cal/err.c src/cal/errs.h
-src_col_col_SOURCES = src/col/col.c src/col/err.c src/col/err.h
-src_rev_rev_SOURCES = src/rev/rev.c src/rev/widechar.h
-src_column_column_SOURCES = src/column/column.c src/column/err.c src/column/errs.h src/column/widechar.h
-src_colcrt_colcrt_SOURCES = src/colcrt/colcrt.c src/colcrt/widechar.h
-src_colrm_colrm_SOURCES = src/colrm/colrm.c src/colrm/widechar.h
-src_mcookie_mcookie_SOURCES = src/mcookie/mcookie.c src/mcookie/md5.c src/mcookie/md5.h
+
src_lpr_lpr_SOURCES = src/lpr/Printer.cc src/lpr/Win32Utils.cc src/lpr/lpr.cc src/lpr/Printer.hh src/lpr/PrinterException.hh src/lpr/Win32Utils.hh
install-exec-hook: $(bin_PROGRAMS)
+1.3.0
+ cal - remove
+ col - remove
+ colcrt - remove
+ colrm - remove
+ column - remove
+ ddate - remove
+ getopt - remove
+ mcookie - remove
+ namei - remove
+ rename - remove
+ rev - remove
+
1.2.10
cygstart: properly convert environment variables to Win32 (Michael Schaap)
cygstart: don't parse options listed after the command (Eric Blake)
prints a large banner to stdout. From Joerg Schaible.
(GPL)
-namei.exe
- follow a pathname until a terminal point is found
- (GPL - originally public domain)
-
-cal.exe
- displays a calendar
- (BSD-no-advert [*])
-
realpath.exe
Convert pathname argumen to absolute path, with all
references to `.', `..', and symlinks resolved.
(GPL)
-ddate.exe
- converts boring normal dates to fun Discordian Date
- (GPL - originally public domain)
-
lpr.exe
can be used to spool to a windows printer
(GPL)
command-line start command.
(GPL)
-col.exe
- Filters out reverse (and half reverse) line feeds so that the output is in
- the correct order with only forward and half forward line feeds, and replaces
- white-space characters with tabs where possible.
- (BSD-no-advert [*])
-
-getopt.exe
- an enhanced command option parser for use in shell scripts. Taken from
- util-linux.
- (GPL)
-
-rev.exe
- reverse lines of a file.
- The rev utility copies the specified files to the standard output,
- reversing the order of characters in every line. If no files are speci-
- fied, the standard input is read.
- (BSD-no-advert [*])
-
-column.exe
- columnate lists
- The column utility formats its input into multiple columns. Rows are
- filled before columns. Input is taken from file operands, or, by
- default, from the standard input. Empty lines are ignored.
- (BSD-no-advert [*])
-
-colcrt.exe
- filter nroff output for CRT previewing
- Colcrt provides virtual half-line and reverse line feed sequences for
- terminals without such capability, and on which overstriking is destruc-
- tive. Half-line characters and underlining (changed to dashing `-') are
- placed on new lines in between the normal output lines.
- (BSD-no-advert [*])
-
-colrm.exe
- remove columns from a file
- Colrm removes selected columns from a file. Input is taken from standard
- input. Output is sent to standard output.
- (BSD-no-advert [*])
-
-mcookie.exe
- generate magic cookies for xauth
- mcookie generates a 128-bit random hexadecimal number for
- use with the X authority system. Typical usage:
- xauth add :0 . `mcookie`
- (GPL - originally public domain)
-
ipck:
IPC utility brought over from cygipc.
(GPL)
-rename:
- flexible file rename utility from util-linux package
- (BSD-no-advert[*])
-
(*) originally BSD+advert, but falls under the blanket
conversion to BSD-no-advert, because it was originally
part of the UCB BSD distro.
University of California on July 22 1999. He states
that clause 3 is "hereby deleted in its entirety."
-Note: "last.exe" and "utmpdump.exe" were previously provided by
+Note1: "last.exe" and "utmpdump.exe" were previously provided by
cygutils. However, once the `sysvinit' package was added to
the cygwin distribution, they were removed. They are now
provided by `sysvinit' -- which is where we took them from
in the first place.
+
+Note2: "cal.exe" "col.exe" "colcrt.exe" "colrm.exe" "column.exe"
+ "ddate.exe" "getopt.exe" "mcookie.exe" "namei.exe" "rename.exe"
+ "rev.exe"
+were previously provided by cygutils. However, they were removed in
+version 1.3.10 because the `util-linux' package was added to the
+cygwin distribution, and it provides those utilities. In fact,
+it was from util-linux that the versions in cygutils were originally
+derived.
+
This collection started life called the "misc" package,
but was renamed to "cygutils" at version 0.9.5.
-Many of these utilities require the popt
-library, available here:
- ftp://ftp.rpm.org/pub/rpm/test-4.0.1/popt-1.6.1.tar.gz
+Many of these utilities require the popt library. Others
+may require the gettext and iconv libraries (libintl, libiconv).
+
+Actually, all of the programs that required gettext have been
+removed from this package, as they are now provided by other
+packages (usually, the original source package from which they
+were once copied into THIS package!). Thus, "last" is now
+in the `sysvinit' package, and `cal' (+ many more) are now in
+the `util-linux' package.
+
+However, I've kept the infrastructure for gettext-enabled
+programs just because I don't want to have to regenerate it
+if ever we add a new utility to this package which requires
+gettext functionality.
+
A Note on Licensing:
--------------------------------------
What's in this package:
-------------------------------
GPL:
- ascii banner conv cygstart dump
- getclip getopt ipck lpr mkshortcut
- msgtool putclip readshortcut realpath semstat
- semtool shmtool d2u dos2unix u2d
- unix2dos
+ ascii banner cygstart dump getclip
+ lpr mkshortcut putclip readshortcut realpath
+
+ ipck msgtool semstat semtool shmtool
+ conv unix2dos dos2unix d2u u2d
PublicDomain-now-GPL:
- namei ddate mcookie
+ <none>
BSD-no-advert:
- cal col colcrt colrm column rev
+ <none>
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT(cygutils, 1.2.10, cygwin@cygwin.com)
+AC_INIT(cygutils, 1.3.0, cygwin@cygwin.com)
AC_CONFIG_SRCDIR([config.h.in])
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER([config.h])
+++ /dev/null
-The cal(1) date routines were written from scratch, basically from first
-principles. The algorithm for calculating the day of week from any
-Gregorian date was "reverse engineered". This was necessary as most of
-the documented algorithms have to do with date calculations for other
-calendars (e.g. julian) and are only accurate when converted to gregorian
-within a narrow range of dates.
-
-1 Jan 1 is a Saturday because that's what cal says and I couldn't change
-that even if I was dumb enough to try. From this we can easily calculate
-the day of week for any date. The algorithm for a zero based day of week:
-
- calculate the number of days in all prior years (year-1)*365
- add the number of leap years (days?) since year 1
- (not including this year as that is covered later)
- add the day number within the year
- this compensates for the non-inclusive leap year
- calculation
- if the day in question occurs before the gregorian reformation
- (3 sep 1752 for our purposes), then simply return
- (value so far - 1 + SATURDAY's value of 6) modulo 7.
- if the day in question occurs during the reformation (3 sep 1752
- to 13 sep 1752 inclusive) return THURSDAY. This is my
- idea of what happened then. It does not matter much as
- this program never tries to find day of week for any day
- that is not the first of a month.
- otherwise, after the reformation, use the same formula as the
- days before with the additional step of subtracting the
- number of days (11) that were adjusted out of the calendar
- just before taking the modulo.
-
-It must be noted that the number of leap years calculation is sensitive
-to the date for which the leap year is being calculated. A year that occurs
-before the reformation is determined to be a leap year if its modulo of
-4 equals zero. But after the reformation, a year is only a leap year if
-its modulo of 4 equals zero and its modulo of 100 does not. Of course,
-there is an exception for these century years. If the modulo of 400 equals
-zero, then the year is a leap year anyway. This is, in fact, what the
-gregorian reformation was all about (a bit of error in the old algorithm
-that caused the calendar to be inaccurate.)
-
-Once we have the day in year for the first of the month in question, the
-rest is trivial.
+++ /dev/null
-.\" Copyright (c) 1989, 1990, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Kim Letkeman.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)cal.1 8.1 (Berkeley) 6/6/93
-.\"
-.Dd June 6, 1993
-.Dt CAL 1
-.Os
-.Sh NAME
-.Nm cal
-.Nd displays a calendar
-.Sh SYNOPSIS
-.Nm cal
-.Op Fl mjy13
-.Op [ Ar month ] Ar year
-.Sh DESCRIPTION
-.Nm Cal
-displays a simple calendar.
-If arguments are not specified,
-the current month is displayed.
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl 1
-Display single month output (use if cal was built with -3 as default to get
-older traditional output)
-.It Fl 3
-Display prev/current/next month output (use if cal was built with traditional
--1 as default to get newer improved output)
-.It Fl m
-Display Monday as the first day of the week.
-(The default is Sunday.)
-.It Fl j
-Display Julian dates (days one-based, numbered from January 1).
-.It Fl y
-Display a calendar for the current year.
-.El
-.Pp
-A single parameter specifies the year (1 - 9999) to be displayed;
-note the year must be fully specified:
-.Dq Li cal 89
-will
-.Em not
-display a calendar for 1989.
-Two parameters denote the month (1 - 12) and year.
-If no parameters are specified, the current month's calendar is
-displayed.
-.Pp
-A year starts on Jan 1.
-.Pp
-The Gregorian Reformation is assumed to have occurred in 1752 on the 3rd
-of September.
-By this time, most countries had recognized the reformation (although a
-few did not recognize it until the early 1900's.)
-Ten days following that date were eliminated by the reformation, so the
-calendar for that month is a bit unusual.
-.Sh HISTORY
-A
-.Nm
-command appeared in Version 6 AT&T UNIX.
+++ /dev/null
-/* && HAVE_NL_LANGINFO
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kim Letkeman.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* 2001-12-04 Charles Wilson: modified license to the 'BSD no advert'
- * license, as required by the Director of the Office of
- * Technology Licensing of the University of California on
- * July 22, 1999.
- * See http://www.opensource.org/licenses/bsd-license.html
- * 1999-02-01 Jean-Francois Bignolles: added option '-m' to display
- * monday as the first day of the week.
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- * - added Native Language Support
- *
- * 2000-09-01 Michael Charles Pruznick <dummy@netwiz.net>
- * Added "-3" option to print prev/next month with current.
- * Added over-ridable default NUM_MONTHS and "-1" option to
- * get traditional output when -3 is the default. I hope that
- * enough people will like -3 as the default that one day the
- * product can be shipped that way.
- *
- * 2001-05-07 Pablo Saratxaga <pablo@mandrakesoft.com>
- * Fixed the bugs with multi-byte charset (zg: cjk, utf-8)
- * displaying. made the 'month year' ("%s %d") header translatable
- * so it can be adapted to conventions used by different languages
- * added support to read "first_weekday" locale information
- * still to do: support for 'cal_direction' (will require a major
- * rewrite of the displaying) and proper handling of RTL scripts
- */
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "common.h"
-#include "errs.h"
-
-/* Determine if the C(++) compiler requires complete function prototype */
-#ifndef __P
-#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
-#define __P(x) x
-#else
-#define __P(x) ()
-#endif
-#endif
-
-int main __P((int argc, char *argv[]));
-
-#ifndef PACKAGE
-#define PACKAGE "cygutils"
-#endif
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#if defined HAVE_LANGINFO_H && HAVE_NL_LANGINFO
-# include <langinfo.h>
-#else
-struct time_info_struct {
- char *abbrev_wkday[7];
- char *full_month[12];
-};
-struct time_info_struct time_info = {
- {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},
- {"January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December"}
-};
-struct time_info_struct * _time_info = &time_info;
-#endif
-
-#include "widechar.h"
-
-/* allow compile-time define to over-ride default */
-#ifndef NUM_MONTHS
-#define NUM_MONTHS 1
-#endif
-
-#if ( NUM_MONTHS != 1 && NUM_MONTHS !=3 )
-#error NUM_MONTHS must be 1 or 3
-#endif
-
-#define THURSDAY 4 /* for reformation */
-#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
-
-#define FIRST_MISSING_DAY 639799 /* 3 Sep 1752 */
-#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
-
-#define MAXDAYS 43 /* max slots in a month array */
-#define SPACE -1 /* used in day array */
-
-static int days_in_month[2][13] = {
- {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
-};
-
-int sep1752[MAXDAYS] = {
- SPACE, SPACE, 1, 2, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE
-}, j_sep1752[MAXDAYS] = {
- SPACE, SPACE, 245, 246, 258, 259, 260,
- 261, 262, 263, 264, 265, 266, 267,
- 268, 269, 270, 271, 272, 273, 274,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE
-}, empty[MAXDAYS] = {
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE
-};
-
-#define DAY_LEN 3 /* 3 spaces per day */
-#define J_DAY_LEN 4 /* 4 spaces per day */
-#define WEEK_LEN 21 /* 7 days * 3 characters */
-#define J_WEEK_LEN 28 /* 7 days * 4 characters */
-#define HEAD_SEP 2 /* spaces between day headings */
-#define J_HEAD_SEP 2
-
-/* utf-8 can have up to 6 bytes per char; and an extra byte for ending \0 */
-char day_headings[WEEK_LEN*6+1];
-/* week1stday = 1 => " M Tu W Th F S S " */
-char j_day_headings[J_WEEK_LEN*6+1];
-/* week1stday = 1 => " M Tu W Th F S S " */
-const char *full_month[12];
-
-/* leap year -- account for gregorian reformation in 1752 */
-#define leap_year(yr) \
- ((yr) <= 1752 ? !((yr) % 4) : \
- (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400))
-
-/* number of centuries since 1700, not inclusive */
-#define centuries_since_1700(yr) \
- ((yr) > 1700 ? (yr) / 100 - 17 : 0)
-
-/* number of centuries since 1700 whose modulo of 400 is 0 */
-#define quad_centuries_since_1700(yr) \
- ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
-
-/* number of leap years between year 1 and this year, not inclusive */
-#define leap_years_since_year_1(yr) \
- ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
-
-/* 0 => sunday (default), 1 => monday */
-int week1stday=0;
-int julian;
-
-#define FMT_ST_LINES 8
-#define FMT_ST_CHARS 300 /* 90 suffices in most locales */
-struct fmt_st
-{
- char s[FMT_ST_LINES][FMT_ST_CHARS];
-};
-
-void ascii_day __P((char *, int));
-void center __P((const char *, int, int));
-void day_array __P((int, int, int *));
-int day_in_week __P((int, int, int));
-int day_in_year __P((int, int, int));
-void j_yearly __P((int));
-void do_monthly __P((int, int, struct fmt_st*));
-void monthly __P((int, int));
-void monthly3 __P((int, int));
-void trim_trailing_spaces __P((char *));
-void usage __P((void));
-void yearly __P((int));
-void headers_init(void);
-extern char *__progname;
-
-int
-main(int argc, char **argv) {
- struct tm *local_time;
- time_t now;
- int ch, month, year, yflag;
- char *progname, *p;
- int num_months = NUM_MONTHS;
-
- progname = argv[0];
- if ((p = strrchr(progname, '/')) != NULL)
- progname = p+1;
- __progname = progname;
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
-#if 0 /* setting week1stday is against man page */
-#if defined HAVE_LANGINFO_H && HAVE_NL_LANGINFO
- week1stday = (int)(nl_langinfo(_NL_TIME_FIRST_WEEKDAY))[0];
-#endif
-#endif
-
- yflag = 0;
- while ((ch = getopt(argc, argv, "13mjyV")) != EOF)
- switch(ch) {
- case '1':
- num_months = 1;
- break;
- case '3':
- num_months = 3;
- break;
- case 'm':
- week1stday = 1;
- break;
- case 'j':
- julian = 1;
- break;
- case 'y':
- yflag = 1;
- break;
- case 'V':
- printf(_("%s from %s version %s\n"),
- progname, PACKAGE, VERSION);
- return 0;
- case '?':
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- month = year = 0;
- switch(argc) {
- case 2:
- if ((month = atoi(*argv++)) < 1 || month > 12)
- errx(1, _("illegal month value: use 1-12"));
- /* FALLTHROUGH */
- case 1:
- if ((year = atoi(*argv)) < 1 || year > 9999)
- errx(1, _("illegal year value: use 1-9999"));
- break;
- case 0:
- (void)time(&now);
- local_time = localtime(&now);
- year = local_time->tm_year + 1900;
- if (!yflag)
- month = local_time->tm_mon + 1;
- break;
- default:
- usage();
- }
- headers_init();
-
- if (month && num_months == 1)
- monthly(month, year);
- else if (month && num_months == 3)
- monthly3(month, year);
- else if (julian)
- j_yearly(year);
- else
- yearly(year);
- exit(0);
-}
-
-#ifndef ENABLE_WIDECHAR
-static char *eos(char *s) {
- while (s && *s)
- s++;
- return s;
-}
-#endif
-
-void headers_init(void)
-{
- int i, wd;
-#ifdef ENABLE_WIDECHAR
- wchar_t day_headings_wc[22],j_day_headings_wc[29];
- wchar_t wd_wc[10];
-#endif
-
- strcpy(day_headings,"");
- strcpy(j_day_headings,"");
-#ifdef ENABLE_WIDECHAR
- wcscpy(day_headings_wc,L"");
- wcscpy(j_day_headings_wc,L"");
-#endif
-
-#if defined HAVE_LANGINFO_H && HAVE_NL_LANGINFO
-# define weekday(wd) nl_langinfo(ABDAY_1+wd)
-#else
-# define weekday(wd) _time_info->abbrev_wkday[wd]
-#endif
-
- for(i = 0 ; i < 7 ; i++ ) {
- wd = (i + week1stday) % 7;
-#ifdef ENABLE_WIDECHAR
- mbstowcs(wd_wc,weekday(wd),10);
- if (wcslen(wd_wc) < 3)
- wcscat(j_day_headings_wc,L" ");
- if (wcslen(wd_wc) < 2) {
- wcscat(day_headings_wc, L" ");
- wcscat(j_day_headings_wc, L" ");
- }
- wcsncat(day_headings_wc,wd_wc,2);
- wcsncat(j_day_headings_wc,wd_wc,3);
- wcscat(day_headings_wc, L" ");
- wcscat(j_day_headings_wc, L" ");
-#else
- sprintf(eos(day_headings), "%2.2s ", weekday(wd));
- sprintf(eos(j_day_headings), "%3.3s ", weekday(wd));
-#endif
- }
-
-#ifdef ENABLE_WIDECHAR
- wcstombs(day_headings,day_headings_wc,sizeof(day_headings));
- wcstombs(j_day_headings,j_day_headings_wc,sizeof(j_day_headings));
-#endif
-
-#undef weekday
-
- for (i = 0; i < 12; i++) {
-#if defined HAVE_LANGINFO_H && HAVE_NL_LANGINFO
- full_month[i] = nl_langinfo(MON_1+i);
-#else
- full_month[i] = _time_info->full_month[i];
-#endif
- }
-}
-
-void
-do_monthly(month, year, out)
- int month, year;
- struct fmt_st* out;
-{
- int col, row, len, days[MAXDAYS];
- char *p, lineout[300];
-#ifdef ENABLE_WIDECHAR
- wchar_t lineout_wc[300];
-#endif
-
- day_array(month, year, days);
- /* %s is the month name, %d the year number.
- * you can change the order and/or add something her; eg for
- * Basque the translation should be: "%2$dko %1$s", and
- * the Vietnamese should be "%s na(m %d", etc.
- */
- len = sprintf(lineout, _("%s %d"), full_month[month - 1], year);
-#ifdef ENABLE_WIDECHAR
- len = mbstowcs(lineout_wc,lineout,len);
-#endif
- (void)sprintf(out->s[0],"%*s%s",
- ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "", lineout );
- (void)sprintf(out->s[1],"%s",
- julian ? j_day_headings : day_headings);
- for (row = 0; row < 6; row++) {
- for (col = 0, p = lineout; col < 7; col++,
- p += julian ? J_DAY_LEN : DAY_LEN)
- ascii_day(p, days[row * 7 + col]);
- *p = '\0';
- trim_trailing_spaces(lineout);
- (void)sprintf(out->s[row+2],"%s", lineout);
- }
-}
-
-void
-monthly(month, year)
- int month, year;
-{
- int i;
- struct fmt_st out;
-
- do_monthly(month, year, &out);
- for ( i = 0; i < FMT_ST_LINES; i++ )
- {
- printf("%s\n", out.s[i]);
- }
-}
-
-void
-monthly3(month, year)
- int month, year;
-{
- int i;
- int width;
- struct fmt_st out_prev;
- struct fmt_st out_curm;
- struct fmt_st out_next;
- int prev_month, prev_year;
- int next_month, next_year;
-
- if ( month == 1 )
- {
- prev_month = 12;
- prev_year = year - 1;
- }
- else
- {
- prev_month = month - 1;
- prev_year = year;
- }
- if ( month == 12 )
- {
- next_month = 1;
- next_year = year + 1;
- }
- else
- {
- next_month = month + 1;
- next_year = year;
- }
-
- do_monthly(prev_month, prev_year, &out_prev);
- do_monthly(month, year, &out_curm);
- do_monthly(next_month, next_year, &out_next);
- width = (julian ? J_WEEK_LEN : WEEK_LEN);
- for ( i = 0; i < FMT_ST_LINES; i++ )
- {
- printf("%-*.*s %-*.*s %-*.*s\n",
- width, width, out_prev.s[i],
- width, width, out_curm.s[i],
- width, width, out_next.s[i] );
- }
-}
-
-void
-j_yearly(year)
- int year;
-{
- int col, *dp, i, month, row, which_cal;
- int days[12][MAXDAYS];
- char *p, lineout[80];
-
- (void)sprintf(lineout, "%d", year);
- center(lineout, J_WEEK_LEN * 2 + J_HEAD_SEP, 0);
- (void)printf("\n\n");
- for (i = 0; i < 12; i++)
- day_array(i + 1, year, days[i]);
- (void)memset(lineout, ' ', sizeof(lineout) - 1);
- lineout[sizeof(lineout) - 1] = '\0';
- for (month = 0; month < 12; month += 2) {
- center(full_month[month], J_WEEK_LEN, J_HEAD_SEP);
- center(full_month[month + 1], J_WEEK_LEN, 0);
- (void)printf("\n%s%*s%s\n", j_day_headings, J_HEAD_SEP, "",
- j_day_headings);
- for (row = 0; row < 6; row++) {
- for (which_cal = 0; which_cal < 2; which_cal++) {
- p = lineout + which_cal * (J_WEEK_LEN + 2);
- dp = &days[month + which_cal][row * 7];
- for (col = 0; col < 7; col++, p += J_DAY_LEN)
- ascii_day(p, *dp++);
- }
- *p = '\0';
- trim_trailing_spaces(lineout);
- (void)printf("%s\n", lineout);
- }
- }
- (void)printf("\n");
-}
-
-void
-yearly(year)
- int year;
-{
- int col, *dp, i, month, row, which_cal;
- int days[12][MAXDAYS];
- char *p, lineout[80];
-
- (void)sprintf(lineout, "%d", year);
- center(lineout, WEEK_LEN * 3 + HEAD_SEP * 2, 0);
- (void)printf("\n\n");
- for (i = 0; i < 12; i++)
- day_array(i + 1, year, days[i]);
- (void)memset(lineout, ' ', sizeof(lineout) - 1);
- lineout[sizeof(lineout) - 1] = '\0';
- for (month = 0; month < 12; month += 3) {
- center(full_month[month], WEEK_LEN, HEAD_SEP);
- center(full_month[month + 1], WEEK_LEN, HEAD_SEP);
- center(full_month[month + 2], WEEK_LEN, 0);
- (void)printf("\n%s%*s%s%*s%s\n", day_headings, HEAD_SEP,
- "", day_headings, HEAD_SEP, "", day_headings);
- for (row = 0; row < 6; row++) {
- for (which_cal = 0; which_cal < 3; which_cal++) {
- p = lineout + which_cal * (WEEK_LEN + 2);
- dp = &days[month + which_cal][row * 7];
- for (col = 0; col < 7; col++, p += DAY_LEN)
- ascii_day(p, *dp++);
- }
- *p = '\0';
- trim_trailing_spaces(lineout);
- (void)printf("%s\n", lineout);
- }
- }
- (void)printf("\n");
-}
-
-/*
- * day_array --
- * Fill in an array of 42 integers with a calendar. Assume for a moment
- * that you took the (maximum) 6 rows in a calendar and stretched them
- * out end to end. You would have 42 numbers or spaces. This routine
- * builds that array for any month from Jan. 1 through Dec. 9999.
- */
-void
-day_array(month, year, days)
- int month, year;
- int *days;
-{
- int day, dw, dm;
- int *d_sep1752;
-
- if (month == 9 && year == 1752) {
- d_sep1752 = julian ? j_sep1752 : sep1752;
- memcpy(days, d_sep1752 + week1stday, MAXDAYS * sizeof(int));
- return;
- }
- memcpy(days, empty, MAXDAYS * sizeof(int));
- dm = days_in_month[leap_year(year)][month];
- dw = (day_in_week(1, month, year) - week1stday + 7) % 7;
- day = julian ? day_in_year(1, month, year) : 1;
- while (dm--)
- days[dw++] = day++;
-}
-
-/*
- * day_in_year --
- * return the 1 based day number within the year
- */
-int
-day_in_year(day, month, year)
- int day, month, year;
-{
- int i, leap;
-
- leap = leap_year(year);
- for (i = 1; i < month; i++)
- day += days_in_month[leap][i];
- return (day);
-}
-
-/*
- * day_in_week
- * return the 0 based day number for any date from 1 Jan. 1 to
- * 31 Dec. 9999. Assumes the Gregorian reformation eliminates
- * 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
- * missing days.
- */
-int
-day_in_week(day, month, year)
- int day, month, year;
-{
- long temp;
-
- temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
- + day_in_year(day, month, year);
- if (temp < FIRST_MISSING_DAY)
- return ((temp - 1 + SATURDAY) % 7);
- if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
- return (((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
- return (THURSDAY);
-}
-
-void
-ascii_day(p, day)
- char *p;
- int day;
-{
- int display, val;
- static char *aday[] = {
- "",
- " 1", " 2", " 3", " 4", " 5", " 6", " 7",
- " 8", " 9", "10", "11", "12", "13", "14",
- "15", "16", "17", "18", "19", "20", "21",
- "22", "23", "24", "25", "26", "27", "28",
- "29", "30", "31",
- };
-
- if (day == SPACE) {
- memset(p, ' ', julian ? J_DAY_LEN : DAY_LEN);
- return;
- }
- if (julian) {
- if ((val = day / 100)) {
- day %= 100;
- *p++ = val + '0';
- display = 1;
- } else {
- *p++ = ' ';
- display = 0;
- }
- val = day / 10;
- if (val || display)
- *p++ = val + '0';
- else
- *p++ = ' ';
- *p++ = day % 10 + '0';
- } else {
- *p++ = aday[day][0];
- *p++ = aday[day][1];
- }
- *p = ' ';
-}
-
-void
-trim_trailing_spaces(s)
- char *s;
-{
- char *p;
-
- for (p = s; *p; ++p)
- continue;
- while (p > s && isspace(*--p))
- continue;
- if (p > s)
- ++p;
- *p = '\0';
-}
-
-void
-center(str, len, separate)
- const char *str;
- int len;
- int separate;
-{
-#ifdef ENABLE_WIDECHAR
- wchar_t str_wc[300];
- int str_len;
-
- str_len = mbstowcs(str_wc,str,300);
- len -= str_len;
-#else
- len -= strlen(str);
-#endif
- (void)printf("%*s%s%*s", len / 2, "", str, len / 2 + len % 2, "");
- if (separate)
- (void)printf("%*s", separate, "");
-}
-
-void
-usage()
-{
-
- (void)fprintf(stderr, _("usage: cal [-mjyV] [[month] year]\n"));
- exit(1);
-}
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* 2001-12-04 Charles Wilson: modified license to the 'BSD no advert'
- * license, as required by the Director of the Office of
- * Technology Licensing of the University of California on
- * July 22, 1999.
- * See http://www.opensource.org/licenses/bsd-license.html
- */
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "common.h"
-#include "errs.h"
-
-
-#ifdef HAVE_PROGNAME
-extern char *__progname; /* Program name, from crt0. */
-#else
-char *__progname = "foo"; /* probably libc4 */
-#endif
-
-/* Some compilers complain "null format string" upon err(1,NULL) */
-/* Make them happy with a separate routine. */
-void
-err_nomsg(int exitval) {
- (void)fprintf(stderr, "%s: %s\n", __progname, strerror(errno));
- exit(exitval);
-}
-
-void
-err(int exitval, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- verr(exitval, fmt, ap);
- va_end(ap);
-}
-
-void
-verr(int exitval, const char *fmt, va_list ap) {
- int sverrno;
-
- sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL && *fmt != 0) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
- exit(exitval);
-}
-
-void
-errx(int exitval, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- verrx(exitval, fmt, ap);
- va_end(ap);
-}
-
-void
-verrx(int exitval, const char *fmt, va_list ap) {
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
- exit(exitval);
-}
-
-void
-warn(const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- vwarn(fmt, ap);
- va_end(ap);
-}
-
-void
-vwarn(const char *fmt, va_list ap) {
- int sverrno;
-
- sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
-}
-
-void
-warnx(const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- vwarnx(fmt, ap);
- va_end(ap);
-}
-
-void
-vwarnx(const char *fmt, va_list ap) {
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
-}
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef _ERR_H_
-#define _ERR_H_
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "common.h"
-
-void err_nomsg (int);
-void err (int, const char *, ...);
-void verr (int, const char *, va_list);
-void errx (int, const char *, ...);
-void verrx (int, const char *, va_list);
-void warn (const char *, ...);
-void vwarn (const char *, va_list);
-void warnx (const char *, ...);
-void vwarnx (const char *, va_list);
-
-#endif /* !_ERR_H_ */
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef WIDECHAR_H
-#define WIDECHAR_H
-/* Declarations for wide characters */
-/* This file must be included last because the redefinition of wchar_t may
- cause conflicts when system include files were included after it. */
-#if HAVE_CONFIG_H
-# include "config.h" /* for ENABLE_WIDECHAR */
-#endif
-/* don't include "common.h" here */
-
-#ifdef ENABLE_WIDECHAR
-
-# include <wchar.h>
-# include <wctype.h>
-#if 0 /* for testing on platforms without built-in wide character support */
-# include <libutf8.h>
-#endif
-
-#if 1
-/* explicit prototypes, since sometimes <wchar.h> does not give them */
-extern int wcwidth (wint_t c);
-extern int wcswidth (const wchar_t *s, size_t n);
-extern size_t wcslen (const wchar_t *s);
-extern wchar_t *wcsdup (const wchar_t *s);
-#endif
-
-#else
-
-# include <ctype.h>
- /* Fallback for types */
-# define wchar_t char
-# define wint_t int
-# define WEOF EOF
- /* Fallback for input operations */
-# define fgetwc fgetc
-# define getwc getc
-# define getwchar getchar
-# define fgetws fgets
- /* Fallback for output operations */
-# define fputwc fputc
-# define putwc putc
-# define putwchar putchar
-# define fputws fputs
- /* Fallback for character classification */
-# define iswgraph isgraph
-# define iswprint isprint
-# define iswspace isspace
- /* Fallback for string functions */
-# define wcschr strchr
-# define wcsdup strdup
-# define wcslen strlen
-
-# define wcwidth(c) 1
-
-#endif
-#endif
+++ /dev/null
-# @(#)README 8.1 (Berkeley) 6/6/93
-
-col - filter out reverse line feeds.
-
-Options are:
- -b do not print any backspaces (last character written is printed)
- -f allow half line feeds in output, by default characters between
- lines are pushed to the line below
- -x do not compress spaces into tabs.
- -l num keep (at least) num lines in memory, 128 are kept by default
-
-In the 32V source code to col(1) the default behavior was to NOT compress
-spaces into tabs. There was a -h option which caused it to compress spaces
-into tabs. There was no -x flag.
-
-The 32V documentation, however, was consistent with the SVID (actually, V7
-at the time) and documented a -x flag (as defined above) while making no
-mention of a -h flag. Just before 4.3BSD went out, CSRG updated the manual
-page to reflect the way the code worked. Suspecting that this was probably
-the wrong way to go, this version adopts the SVID defaults, and no longer
-documents the -h option.
-
-The S5 -p flag is not supported because it isn't clear what it does (looks
-like a kludge introduced for a particular printer).
-
-Known differences between AT&T's col and this one (# is delimiter):
- Input AT&T col this col
- #\nabc\E7def\n# # def\nabc\r# # def\nabc\n#
- #a# ## #a\n#
- - last line always ends with at least one \n (or \E9)
- #1234567 8\n# #1234567\t8\n# #1234567 8\n#
- - single space not expanded to tab
- -f #a\E8b\n# #ab\n# # b\E9\ra\n#
- - can back up past first line (as far as you want) so you
- *can* have a super script on the first line
- #\E9_\ba\E8\nb\n# #\n_\bb\ba\n# #\n_\ba\bb\n#
- - always print last character written to a position,
- AT&T col claims to do this but doesn't.
-
-If a character is to be placed on a line that has been flushed, a warning
-is produced (the AT&T col is silent). The -l flag (not in AT&T col) can
-be used to increase the number of lines buffered to avoid the problem.
-
-General algorithm: a limited number of lines are buffered in a linked
-list. When a printable character is read, it is put in the buffer of
-the current line along with the column it's supposed to be in. When
-a line is flushed, the characters in the line are sorted according to
-column and then printed.
+++ /dev/null
-.\" Copyright (c) 1990, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Michael Rendell.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)col.1 8.1 (Berkeley) 6/29/93
-.\"
-.Dd June 29, 1993
-.Dt COL 1
-.Os
-.Sh NAME
-.Nm col
-.Nd filter reverse line feeds from input
-.Sh SYNOPSIS
-.Nm col
-.Op Fl bfx
-.Op Fl l Ar num
-.Sh DESCRIPTION
-.Nm Col
-filters out reverse (and half reverse) line feeds so that the output is
-in the correct order with only forward and half forward line
-feeds, and replaces white-space characters with tabs where possible.
-This can be useful in processing the output of
-.Xr nroff 1
-and
-.Xr tbl 1 .
-.Pp
-.Nm Col
-reads from the standard input and writes to the standard output.
-.Pp
-The options are as follows:
-.Bl -tag -width "-l num "
-.It Fl b
-Do not output any backspaces, printing only the last character
-written to each column position.
-.It Fl f
-Forward half line feeds are permitted (``fine'' mode).
-Normally characters printed on a half line boundary are printed
-on the following line.
-.It Fl x
-Output multiple spaces instead of tabs.
-.It Fl l Ar num
-Buffer at least
-.Ar num
-lines in memory.
-By default, 128 lines are buffered.
-.El
-.Pp
-The control sequences for carriage motion that
-.Nm col
-understands and their decimal values are listed in the following
-table:
-.Pp
-.Bl -tag -width "carriage return" -compact
-.It ESC\-7
-reverse line feed (escape then 7)
-.It ESC\-8
-half reverse line feed (escape then 8)
-.It ESC\-9
-half forward line feed (escape then 9)
-.It backspace
-moves back one column (8); ignored in the first column
-.It carriage return
-(13)
-.It newline
-forward line feed (10); also does carriage return
-.It shift in
-shift to normal character set (15)
-.It shift out
-shift to alternate character set (14)
-.It space
-moves forward one column (32)
-.It tab
-moves forward to next tab stop (9)
-.It vertical tab
-reverse line feed (11)
-.El
-.Pp
-All unrecognized control characters and escape sequences are
-discarded.
-.Pp
-.Nm Col
-keeps track of the character set as characters are read and makes
-sure the character set is correct when they are output.
-.Pp
-If the input attempts to back up to the last flushed line,
-.Nm col
-will display a warning message.
-.Sh SEE ALSO
-.Xr expand 1 ,
-.Xr nroff 1 ,
-.Xr tbl 1
-.Sh HISTORY
-A
-.Nm col
-command
-appeared in Version 6 AT&T UNIX.
+++ /dev/null
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Rendell of the Memorial University of Newfoundland.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* 2002-05-22 David A. Willis: modified license to the 'BSD no advert'
- * license, as required by the Director of the Office of
- * Technology Licensing of the University of California on
- * July 22, 1999.
- * See http://www.opensource.org/licenses/bsd-license.html
- * 2002-05-22 David A. Willis: "Ported" code for compilation under
- * ix86-pc-cygwin (just added the #if HAVE_CONFIG_H block,
- * really.)
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1990, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)col.c 8.3 (Berkeley) 4/2/94";
-#endif /* not lint */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-#include "err.h"
-#include <locale.h>
-
-/* These headers are included via common.h, except for <err.h> */
-/* err.h is located in CWD, so include using " " instead of < > */
-#if 0
-#include <ctype.h>
-#include <err.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <locale.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#endif
-
-#define BS '\b' /* backspace */
-#define TAB '\t' /* tab */
-#define SPACE ' ' /* space */
-#define NL '\n' /* newline */
-#define CR '\r' /* carriage return */
-#define ESC '\033' /* escape */
-#define SI '\017' /* shift in to normal character set */
-#define SO '\016' /* shift out to alternate character set */
-#define VT '\013' /* vertical tab (aka reverse line feed) */
-#define RLF '7' /* ESC-7 reverse line feed */
-#define RHLF '8' /* ESC-8 reverse half-line feed */
-#define FHLF '9' /* ESC-9 forward half-line feed */
-
-/* build up at least this many lines before flushing them out */
-#define BUFFER_MARGIN 32
-
-typedef char CSET;
-
-typedef struct char_str {
-#define CS_NORMAL 1
-#define CS_ALTERNATE 2
- short c_column; /* column character is in */
- CSET c_set; /* character set (currently only 2) */
- char c_char; /* character in question */
-} CHARACTER;
-
-typedef struct line_str LINE;
-struct line_str {
- CHARACTER *l_line; /* characters on the line */
- LINE *l_prev; /* previous line */
- LINE *l_next; /* next line */
- int l_lsize; /* allocated sizeof l_line */
- int l_line_len; /* strlen(l_line) */
- int l_needs_sort; /* set if chars went in out of order */
- int l_max_col; /* max column in the line */
-};
-
-LINE *alloc_line __P((void));
-void dowarn __P((int));
-void flush_line __P((LINE *));
-void flush_lines __P((int));
-void flush_blanks __P((void));
-void free_line __P((LINE *));
-void usage __P((void));
-void wrerr __P((void));
-void *xmalloc __P((void *, size_t));
-
-CSET last_set; /* char_set of last char printed */
-LINE *lines;
-int compress_spaces; /* if doing space -> tab conversion */
-int fine; /* if `fine' resolution (half lines) */
-int max_bufd_lines; /* max # lines to keep in memory */
-int nblank_lines; /* # blanks after last flushed line */
-int no_backspaces; /* if not to output any backspaces */
-
-#define PUTC(ch) \
- if (putchar(ch) == EOF) \
- wrerr();
-
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
- int ch;
- CHARACTER *c;
- CSET cur_set; /* current character set */
- LINE *l; /* current line */
- int extra_lines; /* # of lines above first line */
- int cur_col; /* current column */
- int cur_line; /* line number of current position */
- int max_line; /* max value of cur_line */
- int this_line; /* line l points to */
- int nflushd_lines; /* number of lines that were flushed */
- int adjust, opt, warned;
-
- err_setprogname(argv[0]);
- setlocale(LC_ALL, "");
-
- max_bufd_lines = 128;
- compress_spaces = 1; /* compress spaces into tabs */
- while ((opt = getopt(argc, argv, "bfhl:x")) != EOF)
- switch (opt) {
- case 'b': /* do not output backspaces */
- no_backspaces = 1;
- break;
- case 'f': /* allow half forward line feeds */
- fine = 1;
- break;
- case 'h': /* compress spaces into tabs */
- compress_spaces = 1;
- break;
- case 'l': /* buffered line count */
- if ((max_bufd_lines = atoi(optarg)) <= 0) {
- (void)fprintf(stderr,
- "col: bad -l argument %s.\n", optarg);
- exit(1);
- }
- break;
- case 'x': /* do not compress spaces into tabs */
- compress_spaces = 0;
- break;
- case '?':
- default:
- usage();
- }
-
- if (optind != argc)
- usage();
-
- /* this value is in half lines */
- max_bufd_lines *= 2;
-
- adjust = cur_col = extra_lines = warned = 0;
- cur_line = max_line = nflushd_lines = this_line = 0;
- cur_set = last_set = CS_NORMAL;
- lines = l = alloc_line();
-
- while ((ch = getchar()) != EOF) {
- if (!isgraph(ch)) {
- switch (ch) {
- case BS: /* can't go back further */
- if (cur_col == 0)
- continue;
- --cur_col;
- continue;
- case CR:
- cur_col = 0;
- continue;
- case ESC: /* just ignore EOF */
- switch(getchar()) {
- case RLF:
- cur_line -= 2;
- break;
- case RHLF:
- cur_line--;
- break;
- case FHLF:
- cur_line++;
- if (cur_line > max_line)
- max_line = cur_line;
- }
- continue;
- case NL:
- cur_line += 2;
- if (cur_line > max_line)
- max_line = cur_line;
- cur_col = 0;
- continue;
- case SPACE:
- ++cur_col;
- continue;
- case SI:
- cur_set = CS_NORMAL;
- continue;
- case SO:
- cur_set = CS_ALTERNATE;
- continue;
- case TAB: /* adjust column */
- cur_col |= 7;
- ++cur_col;
- continue;
- case VT:
- cur_line -= 2;
- continue;
- }
- continue;
- }
-
- /* Must stuff ch in a line - are we at the right one? */
- if (cur_line != this_line - adjust) {
- LINE *lnew;
- int nmove;
-
- adjust = 0;
- nmove = cur_line - this_line;
- if (!fine) {
- /* round up to next line */
- if (cur_line & 1) {
- adjust = 1;
- nmove++;
- }
- }
- if (nmove < 0) {
- for (; nmove < 0 && l->l_prev; nmove++)
- l = l->l_prev;
- if (nmove) {
- if (nflushd_lines == 0) {
- /*
- * Allow backup past first
- * line if nothing has been
- * flushed yet.
- */
- for (; nmove < 0; nmove++) {
- lnew = alloc_line();
- l->l_prev = lnew;
- lnew->l_next = l;
- l = lines = lnew;
- extra_lines++;
- }
- } else {
- if (!warned++)
- dowarn(cur_line);
- cur_line -= nmove;
- }
- }
- } else {
- /* may need to allocate here */
- for (; nmove > 0 && l->l_next; nmove--)
- l = l->l_next;
- for (; nmove > 0; nmove--) {
- lnew = alloc_line();
- lnew->l_prev = l;
- l->l_next = lnew;
- l = lnew;
- }
- }
- this_line = cur_line + adjust;
- nmove = this_line - nflushd_lines;
- if (nmove >= max_bufd_lines + BUFFER_MARGIN) {
- nflushd_lines += nmove - max_bufd_lines;
- flush_lines(nmove - max_bufd_lines);
- }
- }
- /* grow line's buffer? */
- if (l->l_line_len + 1 >= l->l_lsize) {
- int need;
-
- need = l->l_lsize ? l->l_lsize * 2 : 90;
- l->l_line = (CHARACTER *)xmalloc((void *) l->l_line,
- (unsigned) need * sizeof(CHARACTER));
- l->l_lsize = need;
- }
- c = &l->l_line[l->l_line_len++];
- c->c_char = ch;
- c->c_set = cur_set;
- c->c_column = cur_col;
- /*
- * If things are put in out of order, they will need sorting
- * when it is flushed.
- */
- if (cur_col < l->l_max_col)
- l->l_needs_sort = 1;
- else
- l->l_max_col = cur_col;
- cur_col++;
- }
- /* goto the last line that had a character on it */
- for (; l->l_next; l = l->l_next)
- this_line++;
- flush_lines(this_line - nflushd_lines + extra_lines + 1);
-
- /* make sure we leave things in a sane state */
- if (last_set != CS_NORMAL)
- PUTC('\017');
-
- /* flush out the last few blank lines */
- nblank_lines = max_line - this_line;
- if (max_line & 1)
- nblank_lines++;
- else if (!nblank_lines)
- /* missing a \n on the last line? */
- nblank_lines = 2;
- flush_blanks();
- exit(0);
-}
-
-void
-flush_lines(nflush)
- int nflush;
-{
- LINE *l;
-
- while (--nflush >= 0) {
- l = lines;
- lines = l->l_next;
- if (l->l_line) {
- flush_blanks();
- flush_line(l);
- }
- nblank_lines++;
- if (l->l_line)
- (void)free((void *)l->l_line);
- free_line(l);
- }
- if (lines)
- lines->l_prev = NULL;
-}
-
-/*
- * Print a number of newline/half newlines. If fine flag is set, nblank_lines
- * is the number of half line feeds, otherwise it is the number of whole line
- * feeds.
- */
-void
-flush_blanks()
-{
- int half, i, nb;
-
- half = 0;
- nb = nblank_lines;
- if (nb & 1) {
- if (fine)
- half = 1;
- else
- nb++;
- }
- nb /= 2;
- for (i = nb; --i >= 0;)
- PUTC('\n');
- if (half) {
- PUTC('\033');
- PUTC('9');
- if (!nb)
- PUTC('\r');
- }
- nblank_lines = 0;
-}
-
-/*
- * Write a line to stdout taking care of space to tab conversion (-h flag)
- * and character set shifts.
- */
-void
-flush_line(l)
- LINE *l;
-{
- CHARACTER *c, *endc;
- int nchars, last_col, this_col;
-
- last_col = 0;
- nchars = l->l_line_len;
-
- if (l->l_needs_sort) {
- static CHARACTER *sorted;
- static int count_size, *count, i, save, sorted_size, tot;
-
- /*
- * Do an O(n) sort on l->l_line by column being careful to
- * preserve the order of characters in the same column.
- */
- if (l->l_lsize > sorted_size) {
- sorted_size = l->l_lsize;
- sorted = (CHARACTER *)xmalloc((void *)sorted,
- (unsigned)sizeof(CHARACTER) * sorted_size);
- }
- if (l->l_max_col >= count_size) {
- count_size = l->l_max_col + 1;
- count = (int *)xmalloc((void *)count,
- (unsigned)sizeof(int) * count_size);
- }
- memset((char *)count, 0, sizeof(int) * l->l_max_col + 1);
- for (i = nchars, c = l->l_line; --i >= 0; c++)
- count[c->c_column]++;
-
- /*
- * calculate running total (shifted down by 1) to use as
- * indices into new line.
- */
- for (tot = 0, i = 0; i <= l->l_max_col; i++) {
- save = count[i];
- count[i] = tot;
- tot += save;
- }
-
- for (i = nchars, c = l->l_line; --i >= 0; c++)
- sorted[count[c->c_column]++] = *c;
- c = sorted;
- } else
- c = l->l_line;
- while (nchars > 0) {
- this_col = c->c_column;
- endc = c;
- do {
- ++endc;
- } while (--nchars > 0 && this_col == endc->c_column);
-
- /* if -b only print last character */
- if (no_backspaces)
- c = endc - 1;
-
- if (this_col > last_col) {
- int nspace = this_col - last_col;
-
- if (compress_spaces && nspace > 1) {
- int ntabs;
-
- ntabs = this_col / 8 - last_col / 8;
- nspace -= ntabs * 8;
- while (--ntabs >= 0)
- PUTC('\t');
- }
- while (--nspace >= 0)
- PUTC(' ');
- last_col = this_col;
- }
- last_col++;
-
- for (;;) {
- if (c->c_set != last_set) {
- switch (c->c_set) {
- case CS_NORMAL:
- PUTC('\017');
- break;
- case CS_ALTERNATE:
- PUTC('\016');
- }
- last_set = c->c_set;
- }
- PUTC(c->c_char);
- if (++c >= endc)
- break;
- PUTC('\b');
- }
- }
-}
-
-#define NALLOC 64
-
-static LINE *line_freelist;
-
-LINE *
-alloc_line()
-{
- LINE *l;
- int i;
-
- if (!line_freelist) {
- l = (LINE *)xmalloc((void *)NULL, sizeof(LINE) * NALLOC);
- line_freelist = l;
- for (i = 1; i < NALLOC; i++, l++)
- l->l_next = l + 1;
- l->l_next = NULL;
- }
- l = line_freelist;
- line_freelist = l->l_next;
-
- memset(l, 0, sizeof(LINE));
- return (l);
-}
-
-void
-free_line(l)
- LINE *l;
-{
-
- l->l_next = line_freelist;
- line_freelist = l;
-}
-
-void *
-xmalloc(p, size)
- void *p;
- size_t size;
-{
-
- if (!(p = (void *)realloc(p, size)))
- err(1, NULL);
- return (p);
-}
-
-void
-usage()
-{
-
- (void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n");
- exit(1);
-}
-
-void
-wrerr()
-{
-
- (void)fprintf(stderr, "col: write error.\n");
- exit(1);
-}
-
-void
-dowarn(line)
- int line;
-{
-
- warnx("warning: can't back up %s",
- line < 0 ? "past first line" : "-- line already flushed");
-}
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* 2002-05-22 David A. Willis: modified license to the 'BSD no advert'
- * license, as required by the Director of the Office of
- * Technology Licensing of the University of California on
- * July 22, 1999.
- * See http://www.opensource.org/licenses/bsd-license.html
- * 2002-05-22 David A. Willis: "Ported" code for compilation under
- * ix86-pc-cygwin (just added the #if HAVE_CONFIG_H block,
- * really.)
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-#include "err.h"
-
-/* These headers are included via common.h, except for <err.h> */
-/* err.h is located in CWD, so include using " " instead of < > */
-#if 0
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-#endif
-
-#ifdef HAVE___PROGNAME
-extern char *__progname; /* Program name, from crt0. */
-#else /* ! HAVE___PROGNAME */
-/* Eugh! People shouldn't rely on crt0 defining things like this. For
- example, linux doesn't define __progname. So each program has to call
- err_setprogname() to register its name. */
-/* don't define __progname, we're not allowed to use that namespace */
-static const char *progname;
-#define __progname progname
-#endif /* ! HAVE___PROGNAME */
-
-
-#ifndef HAVE___PROGNAME
-/* sane C compiler, so none of this messy __STDC__ guff */
-
-/* sets __progname to point into argv[0] at the right place. Takes
- argv[0], and finds where 'the right place' is. */
-void err_setprogname(const char *argv0)
-{
- __progname = strrchr(argv0, '/');
- if (__progname==NULL || *__progname==0)
- __progname = argv0;
- else
- __progname++;
-}
-#else /* HAVE___PROGNAME */
-#define err_setprogname(x) (void *)0
-#endif /* HAVE___PROGNAME */
-
-
-__dead void
-#ifdef __STDC__
-err(int eval, const char *fmt, ...)
-#else
-err(eval, fmt, va_alist)
- int eval;
- const char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- verr(eval, fmt, ap);
- va_end(ap);
-}
-
-__dead void
-verr(eval, fmt, ap)
- int eval;
- const char *fmt;
- va_list ap;
-{
- int sverrno;
-
- sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
- exit(eval);
-}
-
-__dead void
-#if __STDC__
-errx(int eval, const char *fmt, ...)
-#else
-errx(eval, fmt, va_alist)
- int eval;
- const char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- verrx(eval, fmt, ap);
- va_end(ap);
-}
-
-__dead void
-verrx(eval, fmt, ap)
- int eval;
- const char *fmt;
- va_list ap;
-{
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
- exit(eval);
-}
-
-void
-#if __STDC__
-warn(const char *fmt, ...)
-#else
-warn(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vwarn(fmt, ap);
- va_end(ap);
-}
-
-void
-vwarn(fmt, ap)
- const char *fmt;
- va_list ap;
-{
- int sverrno;
-
- sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
-}
-
-void
-#ifdef __STDC__
-warnx(const char *fmt, ...)
-#else
-warnx(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vwarnx(fmt, ap);
- va_end(ap);
-}
-
-void
-vwarnx(fmt, ap)
- const char *fmt;
- va_list ap;
-{
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
-}
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)err.h 8.1 (Berkeley) 6/2/93
- */
-
-/* 2002-05-22 David A. Willis: modified license to the 'BSD no advert'
- * license, as required by the Director of the Office of
- * Technology Licensing of the University of California on
- * July 22, 1999.
- * See http://www.opensource.org/licenses/bsd-license.html
- */
-
-#ifndef _ERR_H_
-#define _ERR_H_
-
-#ifdef HAVE_STDARG_H
- #include <stdarg.h>
- #define _BSD_VA_LIST_ va_list
- #define __dead
-#else /* not HAVE_STDARG_H */
-/*
- * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two
- * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
- * of them here we may collide with the utility's includes. It's unreasonable
- * for utilities to have to include one of them to include err.h, so we get
- * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
- */
- #include <machine/ansi.h>
-#endif /* not HAVE_STDARG_H */
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-#ifdef HAVE_STDARG_H
-void err_setprogname __P((const char *));
-#endif /* HAVE_STDARG_H */
-__dead void err __P((int, const char *, ...));
-__dead void verr __P((int, const char *, _BSD_VA_LIST_));
-__dead void errx __P((int, const char *, ...));
-__dead void verrx __P((int, const char *, _BSD_VA_LIST_));
-void warn __P((const char *, ...));
-void vwarn __P((const char *, _BSD_VA_LIST_));
-void warnx __P((const char *, ...));
-void vwarnx __P((const char *, _BSD_VA_LIST_));
-__END_DECLS
-
-#ifdef HAVE_STDARG_H
- #undef _BSD_VA_LIST
-#endif /* HAVE_STDARG_H */
-
-#endif /* !_ERR_H_ */
+++ /dev/null
-.\" Copyright (c) 1980, 1990, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)colcrt.1 8.1 (Berkeley) 6/30/93
-.\"
-.Dd June 30, 1993
-.Dt COLCRT 1
-.Os BSD 3
-.Sh NAME
-.Nm colcrt
-.Nd filter nroff output for CRT previewing
-.Sh SYNOPSIS
-.Nm colcrt
-.Op Fl
-.Op Fl \&2
-.Op Ar
-.Sh DESCRIPTION
-.Nm Colcrt
-provides virtual half-line and reverse line feed sequences
-for terminals without such capability, and on which overstriking
-is destructive.
-Half-line characters and underlining (changed to dashing `\-')
-are placed on new lines in between the normal output lines.
-.Pp
-Available options:
-.Bl -tag -width Ds
-.It Fl
-Suppress all underlining.
-This option is especially useful for previewing
-.Em allboxed
-tables from
-.Xr tbl 1 .
-.It Fl 2
-Causes all half-lines to be printed, effectively double spacing the output.
-Normally, a minimal space output format is used which will suppress empty
-lines.
-The program never suppresses two consecutive empty lines, however.
-The
-.Fl 2
-option is useful for sending output to the line printer when the output
-contains superscripts and subscripts which would otherwise be invisible.
-.El
-.Sh EXAMPLES
-A typical use of
-.Nm colcrt
-would be
-.Bd -literal
-tbl exum2.n \&| nroff \-ms \&| colcrt \- \&| more
-.Ed
-.Sh SEE ALSO
-.Xr nroff 1 ,
-.Xr troff 1 ,
-.Xr col 1 ,
-.Xr more 1 ,
-.Xr ul 1
-.Sh BUGS
-Should fold underlines onto blanks even with the
-.Ql Fl
-option so that
-a true underline character would show.
-.Pp
-Can't back up more than 102 lines.
-.Pp
-General overstriking is lost;
-as a special case
-.Ql \&|
-overstruck with
-.Ql \-
-or underline becomes
-.Ql \&+ .
-.Pp
-Lines are trimmed to 132 characters.
-.Pp
-Some provision should be made for processing superscripts and subscripts
-in documents which are already double-spaced.
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 3.0 .
+++ /dev/null
-/*
- * Copyright (c) 1980, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- * added Native Language Support
- * 1999-09-19 Bruno Haible <haible@clisp.cons.org>
- * modified to work correctly in multi-byte locales
- * 2002-07-12 Charles Wilson <cwilson@ece.gatech.edu>
- * modified to work on cygwin; integrated into cygutils package
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* included by common.h *//*
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-*/
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#include "widechar.h"
-
-int plus(wchar_t c, wchar_t d);
-void move(int l, int m);
-void pflush(int ol);
-
-/*
- * colcrt - replaces col for crts with new nroff esp. when using tbl.
- * Bill Joy UCB July 14, 1977
- *
- * This filter uses a screen buffer, 267 half-lines by 132 columns.
- * It interprets the up and down sequences generated by the new
- * nroff when used with tbl and by \u \d and \r.
- * General overstriking doesn't work correctly.
- * Underlining is split onto multiple lines, etc.
- *
- * Option - suppresses all underlining.
- * Option -2 forces printing of all half lines.
- */
-
-wchar_t page[267][132];
-
-int outline = 1;
-int outcol;
-
-char suppresul;
-char printall;
-
-char *progname;
-void colcrt(FILE *f);
-
-int
-main(int argc, char **argv) {
- FILE *f;
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- argc--;
- progname = *argv++;
- while (argc > 0 && argv[0][0] == '-') {
- switch (argv[0][1]) {
- case 0:
- suppresul = 1;
- break;
- case '2':
- printall = 1;
- break;
- default:
- printf(_("usage: %s [ - ] [ -2 ] [ file ... ]\n"), progname);
- fflush(stdout);
- exit(1);
- }
- argc--;
- argv++;
- }
- f = stdin;
- do {
- if (argc > 0) {
- if (!(f = fopen(argv[0], "r"))) {
- fflush(stdout);
- perror(argv[0]);
- exit (1);
- }
- argc--;
- argv++;
- }
- colcrt(f);
- if (f != stdin)
- fclose(f);
- } while (argc > 0);
- fflush(stdout);
- if (ferror(stdout) || fclose(stdout))
- return 1;
- return 0;
-}
-
-void
-colcrt(FILE *f) {
- wint_t c;
- wchar_t *cp, *dp;
- int i, w;
-
- for (;;) {
- c = getwc(f);
- if (c == WEOF) {
- pflush(outline);
- fflush(stdout);
- break;
- }
- switch (c) {
- case '\n':
- if (outline >= 265)
- pflush(62);
- outline += 2;
- outcol = 0;
- continue;
- case '\016':
- case '\017':
- continue;
- case 033:
- c = getwc(f);
- switch (c) {
- case '9':
- if (outline >= 266)
- pflush(62);
- outline++;
- continue;
- case '8':
- if (outline >= 1)
- outline--;
- continue;
- case '7':
- outline -= 2;
- if (outline < 0)
- outline = 0;
- continue;
- default:
- continue;
- }
- case '\b':
- if (outcol)
- outcol--;
- continue;
- case '\t':
- outcol += 8;
- outcol &= ~7;
- outcol--;
- c = ' ';
- default:
- w = wcwidth(c);
- if (outcol + w > 132) {
- outcol++;
- continue;
- }
- cp = &page[outline][outcol];
- outcol += w;
- if (c == '_') {
- if (suppresul)
- continue;
- cp += 132;
- c = '-';
- }
- if (*cp == 0) {
- /* trick! */
- for (i=0; i<w; i++)
- cp[i] = c;
- dp = cp - (outcol-w);
- for (cp--; cp >= dp && *cp == 0; cp--)
- *cp = ' ';
- } else {
- if (plus(c, *cp) || plus(*cp, c))
- *cp = '+';
- else if (*cp == ' ' || *cp == 0) {
- for (i=1; i<w; i++)
- if (cp[i] != ' ' && cp[i] != 0)
- continue;
- for (i=0; i<w; i++)
- cp[i] = c;
- }
- }
- continue;
- }
- }
-}
-
-int plus(wchar_t c, wchar_t d)
-{
-
- return (c == '|' && (d == '-' || d == '_'));
-}
-
-int first;
-
-void pflush(int ol)
-{
- register int i;
- register wchar_t *cp;
- char lastomit;
- int l, w;
-
- l = ol;
- lastomit = 0;
- if (l > 266)
- l = 266;
- else
- l |= 1;
- for (i = first | 1; i < l; i++) {
- move(i, i - 1);
- move(i, i + 1);
- }
- for (i = first; i < l; i++) {
- cp = page[i];
- if (printall == 0 && lastomit == 0 && *cp == 0) {
- lastomit = 1;
- continue;
- }
- lastomit = 0;
- while (*cp) {
- if ((w = wcwidth(*cp)) > 0) {
- putwchar(*cp);
- cp += w;
- } else
- cp++;
- }
- putwchar('\n');
- }
- bcopy(page[ol], page, (267 - ol) * 132 * sizeof(wchar_t));
- bzero(page[267- ol], ol * 132 * sizeof(wchar_t));
- outline -= ol;
- outcol = 0;
- first = 1;
-}
-
-void move(int l, int m)
-{
- register wchar_t *cp, *dp;
-
- for (cp = page[l], dp = page[m]; *cp; cp++, dp++) {
- switch (*cp) {
- case '|':
- if (*dp != ' ' && *dp != '|' && *dp != 0)
- return;
- break;
- case ' ':
- break;
- default:
- return;
- }
- }
- if (*cp == 0) {
- for (cp = page[l], dp = page[m]; *cp; cp++, dp++)
- if (*cp == '|')
- *dp = '|';
- else if (*dp == 0)
- *dp = ' ';
- page[l][0] = 0;
- }
-}
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef WIDECHAR_H
-#define WIDECHAR_H
-/* Declarations for wide characters */
-/* This file must be included last because the redefinition of wchar_t may
- cause conflicts when system include files were included after it. */
-#if HAVE_CONFIG_H
-# include "config.h" /* for ENABLE_WIDECHAR */
-#endif
-/* don't include "common.h" here */
-
-#ifdef ENABLE_WIDECHAR
-
-# include <wchar.h>
-# include <wctype.h>
-#if 0 /* for testing on platforms without built-in wide character support */
-# include <libutf8.h>
-#endif
-
-#if 1
-/* explicit prototypes, since sometimes <wchar.h> does not give them */
-extern int wcwidth (wint_t c);
-extern int wcswidth (const wchar_t *s, size_t n);
-extern size_t wcslen (const wchar_t *s);
-extern wchar_t *wcsdup (const wchar_t *s);
-#endif
-
-#else
-
-# include <ctype.h>
- /* Fallback for types */
-# define wchar_t char
-# define wint_t int
-# define WEOF EOF
- /* Fallback for input operations */
-# define fgetwc fgetc
-# define getwc getc
-# define getwchar getchar
-# define fgetws fgets
- /* Fallback for output operations */
-# define fputwc fputc
-# define putwc putc
-# define putwchar putchar
-# define fputws fputs
- /* Fallback for character classification */
-# define iswgraph isgraph
-# define iswprint isprint
-# define iswspace isspace
- /* Fallback for string functions */
-# define wcschr strchr
-# define wcsdup strdup
-# define wcslen strlen
-
-# define wcwidth(c) 1
-
-#endif
-#endif
+++ /dev/null
-.\" Copyright (c) 1980, 1990 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)colrm.1 6.6 (Berkeley) 3/14/91
-.\"
-.Dd March 14, 1991
-.Dt COLRM 1
-.Os BSD 3
-.Sh NAME
-.Nm colrm
-.Nd remove columns from a file
-.Sh SYNOPSIS
-.Nm colrm
-.Op Ar startcol Op Ar endcol
-.Sh DESCRIPTION
-.Nm Colrm
-removes selected columns from a file. Input is taken from standard input.
-Output is sent to standard output.
-.Pp
-If called with one parameter the columns
-of each line will be removed starting with the specified column.
-If called with two parameters the columns from the first column
-to the last column will be removed.
-.Pp
-Column numbering starts with column 1.
-.Sh SEE ALSO
-.Xr awk 1 ,
-.Xr column 1 ,
-.Xr expand 1 ,
-.Xr paste 1
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 3.0 .
+++ /dev/null
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- * added Native Language Support
- * 1999-09-19 Bruno Haible <haible@clisp.cons.org>
- * modified to work correctly in multi-byte locales
- * 2002-07-12 Charles Wilson <cwilson@ece.gatech.edu>
- * modified to work on cygwin; integrated into cygutils package
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* included by common.h *//*
-#include <stdio.h>
-#include <stdlib.h>
-#include <locale.h>
-*/
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#include "widechar.h"
-
-/*
-COLRM removes unwanted columns from a file
- Jeff Schriebman UC Berkeley 11-74
-*/
-
-int
-main(int argc, char **argv)
-{
- register int ct, first, last;
- register wint_t c;
- int i, w;
- int padding;
-
- setlocale(LC_ALL, "");
-
- first = 0;
- last = 0;
- if (argc > 1)
- first = atoi(*++argv);
- if (argc > 2)
- last = atoi(*++argv);
-
-start:
- ct = 0;
-loop1:
- c = getwc(stdin);
- if (feof(stdin))
- goto fin;
- if (c == '\t')
- w = ((ct + 8) & ~7) - ct;
- else if (c == '\b')
- w = (ct ? ct - 1 : 0) - ct;
- else {
- w = wcwidth(c);
- if (w < 0)
- w = 0;
- }
- ct += w;
- if (c == '\n') {
- putwc(c, stdout);
- goto start;
- }
- if (!first || ct < first) {
- putwc(c, stdout);
- goto loop1;
- }
- for (i = ct-w+1; i < first; i++)
- putwc(' ', stdout);
-
-/* Loop getting rid of characters */
- while (!last || ct < last) {
- c = getwc(stdin);
- if (feof(stdin))
- goto fin;
- if (c == '\n') {
- putwc(c, stdout);
- goto start;
- }
- if (c == '\t')
- ct = (ct + 8) & ~7;
- else if (c == '\b')
- ct = ct ? ct - 1 : 0;
- else {
- w = wcwidth(c);
- if (w < 0)
- w = 0;
- ct += w;
- }
- }
-
- padding = 0;
-
-/* Output last of the line */
- for (;;) {
- c = getwc(stdin);
- if (feof(stdin))
- break;
- if (c == '\n') {
- putwc(c, stdout);
- goto start;
- }
- if (padding == 0 && last < ct) {
- for (i = last; i <ct; i++)
- putwc(' ', stdout);
- padding = 1;
- }
- putwc(c, stdout);
- }
-fin:
- fflush(stdout);
- if (ferror(stdout) || fclose(stdout))
- return 1;
- return 0;
-}
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef WIDECHAR_H
-#define WIDECHAR_H
-/* Declarations for wide characters */
-/* This file must be included last because the redefinition of wchar_t may
- cause conflicts when system include files were included after it. */
-#if HAVE_CONFIG_H
-# include "config.h" /* for ENABLE_WIDECHAR */
-#endif
-/* don't include "common.h" here */
-
-#ifdef ENABLE_WIDECHAR
-
-# include <wchar.h>
-# include <wctype.h>
-#if 0 /* for testing on platforms without built-in wide character support */
-# include <libutf8.h>
-#endif
-
-#if 1
-/* explicit prototypes, since sometimes <wchar.h> does not give them */
-extern int wcwidth (wint_t c);
-extern int wcswidth (const wchar_t *s, size_t n);
-extern size_t wcslen (const wchar_t *s);
-extern wchar_t *wcsdup (const wchar_t *s);
-#endif
-
-#else
-
-# include <ctype.h>
- /* Fallback for types */
-# define wchar_t char
-# define wint_t int
-# define WEOF EOF
- /* Fallback for input operations */
-# define fgetwc fgetc
-# define getwc getc
-# define getwchar getchar
-# define fgetws fgets
- /* Fallback for output operations */
-# define fputwc fputc
-# define putwc putc
-# define putwchar putchar
-# define fputws fputs
- /* Fallback for character classification */
-# define iswgraph isgraph
-# define iswprint isprint
-# define iswspace isspace
- /* Fallback for string functions */
-# define wcschr strchr
-# define wcsdup strdup
-# define wcslen strlen
-
-# define wcwidth(c) 1
-
-#endif
-#endif
+++ /dev/null
-.\" Copyright (c) 1989, 1990, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)column.1 8.1 (Berkeley) 6/6/93
-.\"
-.Dd June 6, 1993
-.Os
-.Dt COLUMN 1
-.Sh NAME
-.Nm column
-.Nd columnate lists
-.Sh SYNOPSIS
-.Nm column
-.Op Fl tx
-.Op Fl c Ar columns
-.Op Fl s Ar sep
-.Op Ar
-.Sh DESCRIPTION
-The
-.Nm column
-utility formats its input into multiple columns.
-Rows are filled before columns.
-Input is taken from
-.Ar file
-operands, or, by default, from the standard input.
-Empty lines are ignored.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl c
-Output is formatted for a display
-.Ar columns
-wide.
-.It Fl s
-Specify a set of characters to be used to delimit columns for the
-.Fl t
-option.
-.It Fl t
-Determine the number of columns the input contains and create a table.
-Columns are delimited with whitespace, by default, or with the characters
-supplied using the
-.Fl s
-option.
-Useful for pretty-printing displays.
-.It Fl x
-Fill columns before filling rows.
-.El
-.Pp
-.Nm Column
-exits 0 on success, >0 if an error occurred.
-.Sh ENVIRONMENT
-.Bl -tag -width COLUMNS
-.It Ev COLUMNS
-The environment variable
-.Ev COLUMNS
-is used to determine the size of
-the screen if no other information is available.
-.El
-.Sh EXAMPLES
-.Dl (printf \&"PERM LINKS OWNER GROUP SIZE MONTH DAY HH:MM/YEAR\ NAME\en\&"\ \&\e
-.Dl \&; ls -l \&| sed 1d) \&| column -t
-.Sh SEE ALSO
-.Xr colrm 1 ,
-.Xr ls 1 ,
-.Xr paste 1 ,
-.Xr sort 1
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.3 Reno .
+++ /dev/null
-/*
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- * added Native Language Support
- * 1999-09-19 Bruno Haible <haible@clisp.cons.org>
- * modified to work correctly in multi-byte locales
- * 2002-07-12 Charles Wilson <cwilson@ece.gatech.edu>
- * modified to work on cygwin; integrated into cygutils package
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* included by common.h *//*
-#include <sys/types.h>
-#include <sys/ioctl.h>
-
-#include <ctype.h>
-#include <limits.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-*/
-#include "errs.h"
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#include "widechar.h"
-
-#ifdef ENABLE_WIDECHAR
-#define wcs_width(s) wcswidth(s,wcslen(s))
-static wchar_t *mbs_to_wcs(const char *);
-#else
-#define wcs_width(s) strlen(s)
-#define mbs_to_wcs(s) strdup(s)
-static char *mtsafe_strtok(char *, const char *, char **);
-#define wcstok mtsafe_strtok
-#endif
-
-void c_columnate __P((void));
-void *emalloc __P((int));
-void input __P((FILE *));
-void maketbl __P((void));
-void print __P((void));
-void r_columnate __P((void));
-void usage __P((void));
-
-int termwidth = 80; /* default terminal width */
-
-int entries; /* number of records */
-int eval; /* exit value */
-int maxlength; /* longest record */
-wchar_t **list; /* array of pointers to records */
-wchar_t default_separator[] = { '\t', ' ', 0 };
-wchar_t *separator = default_separator; /* field separator for table option */
-
-int
-main(int argc, char **argv)
-{
- struct winsize win;
- FILE *fp;
- int ch, tflag, xflag;
- char *p;
-
-#ifdef __linux__
- extern int optind;
- extern char *optarg;
- extern char *__progname;
- __progname = argv[0];
-#endif
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
- if ((p = getenv("COLUMNS")) != NULL)
- termwidth = atoi(p);
- } else
- termwidth = win.ws_col;
-
- tflag = xflag = 0;
- while ((ch = getopt(argc, argv, "c:s:tx")) != EOF)
- switch(ch) {
- case 'c':
- termwidth = atoi(optarg);
- break;
- case 's':
- separator = mbs_to_wcs(optarg);
- break;
- case 't':
- tflag = 1;
- break;
- case 'x':
- xflag = 1;
- break;
- case '?':
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (!*argv)
- input(stdin);
- else for (; *argv; ++argv)
- if ((fp = fopen(*argv, "r")) != NULL) {
- input(fp);
- (void)fclose(fp);
- } else {
- warn("%s", *argv);
- eval = 1;
- }
-
- if (!entries)
- exit(eval);
-
- if (tflag)
- maketbl();
- else if (maxlength >= termwidth)
- print();
- else if (xflag)
- c_columnate();
- else
- r_columnate();
- if (ferror(stdout) || fclose(stdout))
- eval = 1;
- exit(eval);
-}
-
-#define TAB 8
-void
-c_columnate()
-{
- int chcnt, col, cnt, endcol, numcols;
- wchar_t **lp;
-
- maxlength = (maxlength + TAB) & ~(TAB - 1);
- numcols = termwidth / maxlength;
- endcol = maxlength;
- for (chcnt = col = 0, lp = list;; ++lp) {
- fputws(*lp, stdout);
- chcnt += wcs_width(*lp);
- if (!--entries)
- break;
- if (++col == numcols) {
- chcnt = col = 0;
- endcol = maxlength;
- putwchar('\n');
- } else {
- while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol) {
- putwchar('\t');
- chcnt = cnt;
- }
- endcol += maxlength;
- }
- }
- if (chcnt)
- putwchar('\n');
-}
-
-void
-r_columnate()
-{
- int base, chcnt, cnt, col, endcol, numcols, numrows, row;
-
- maxlength = (maxlength + TAB) & ~(TAB - 1);
- numcols = termwidth / maxlength;
- if (!numcols)
- numcols = 1;
- numrows = entries / numcols;
- if (entries % numcols)
- ++numrows;
-
- for (row = 0; row < numrows; ++row) {
- endcol = maxlength;
- for (base = row, chcnt = col = 0; col < numcols; ++col) {
- fputws(list[base], stdout);
- chcnt += wcs_width(list[base]);
- if ((base += numrows) >= entries)
- break;
- while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol) {
- putwchar('\t');
- chcnt = cnt;
- }
- endcol += maxlength;
- }
- putwchar('\n');
- }
-}
-
-void
-print()
-{
- int cnt;
- wchar_t **lp;
-
- for (cnt = entries, lp = list; cnt--; ++lp) {
- fputws(*lp, stdout);
- putwchar('\n');
- }
-}
-
-typedef struct _tbl {
- wchar_t **list;
- int cols, *len;
-} TBL;
-#define DEFCOLS 25
-
-void
-maketbl()
-{
- TBL *t;
- int coloff, cnt, i;
- wchar_t *p, **lp;
- int *lens, maxcols;
- TBL *tbl;
- wchar_t **cols;
- wchar_t *wcstok_state;
-
- t = tbl = emalloc(entries * sizeof(TBL));
- cols = emalloc((maxcols = DEFCOLS) * sizeof(wchar_t *));
- lens = emalloc(maxcols * sizeof(int));
- for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
- for (coloff = 0, p = *lp;
- (cols[coloff] = wcstok(p, separator, &wcstok_state)) != NULL;
- p = NULL)
- if (++coloff == maxcols) {
- if (!(cols = realloc(cols, ((u_int)maxcols + DEFCOLS)
- * sizeof(wchar_t *))) ||
- !(lens = realloc(lens, ((u_int)maxcols + DEFCOLS)
- * sizeof(int))))
- err_nomsg(1);
- memset((char *)lens + maxcols * sizeof(int),
- 0, DEFCOLS * sizeof(int));
- maxcols += DEFCOLS;
- }
- t->list = emalloc(coloff * sizeof(wchar_t *));
- t->len = emalloc(coloff * sizeof(int));
- for (t->cols = coloff; --coloff >= 0;) {
- t->list[coloff] = cols[coloff];
- t->len[coloff] = wcs_width(cols[coloff]);
- if (t->len[coloff] > lens[coloff])
- lens[coloff] = t->len[coloff];
- }
- }
- for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) {
- for (coloff = 0; coloff < t->cols - 1; ++coloff) {
- fputws(t->list[coloff], stdout);
- for (i = lens[coloff] - t->len[coloff] + 2; i > 0; i--)
- putwchar(' ');
- }
- fputws(t->list[coloff], stdout);
- putwchar('\n');
- }
-}
-
-#define DEFNUM 1000
-#ifdef LINE_MAX
-# define MAXLINELEN (LINE_MAX + 1)
-#else
-# define MAXLINELEN (2049)
-#endif
-
-void
-input(fp)
- FILE *fp;
-{
- static int maxentry;
- int len;
- wchar_t *p, buf[MAXLINELEN];
-
- if (!list)
- list = emalloc((maxentry = DEFNUM) * sizeof(wchar_t *));
- while (fgetws(buf, MAXLINELEN, fp)) {
- for (p = buf; *p && iswspace(*p); ++p);
- if (!*p)
- continue;
- if (!(p = wcschr(p, '\n'))) {
- warnx(_("line too long"));
- eval = 1;
- continue;
- }
- *p = '\0';
- len = wcs_width(buf); /* len = p - buf; */
- if (maxlength < len)
- maxlength = len;
- if (entries == maxentry) {
- maxentry += DEFNUM;
- if (!(list = realloc(list,
- (u_int)maxentry * sizeof(wchar_t *))))
- err_nomsg(1);
- }
- list[entries++] = wcsdup(buf);
- }
-}
-
-#ifdef ENABLE_WIDECHAR
-static wchar_t *mbs_to_wcs(const char *s)
-{
- size_t n;
- wchar_t *wcs;
-
- n = mbstowcs((wchar_t *)0, s, 0);
- if (n < 0)
- return NULL;
- wcs = malloc((n + 1) * sizeof(wchar_t));
- if (!wcs)
- return NULL;
- if (mbstowcs(wcs, s, n + 1) < 0)
- return NULL;
- return wcs;
-}
-#endif
-
-#ifndef ENABLE_WIDECHAR
-static char *mtsafe_strtok(char *str, const char *delim, char **ptr)
-{
- if (str == NULL) {
- str = *ptr;
- if (str == NULL)
- return NULL;
- }
- str += strspn(str, delim);
- if (*str == '\0') {
- *ptr = NULL;
- return NULL;
- } else {
- char *token_end = strpbrk(str, delim);
- if (token_end) {
- *token_end = '\0';
- *ptr = token_end + 1;
- } else
- *ptr = NULL;
- return str;
- }
-}
-#endif
-
-void *
-emalloc(size)
- int size;
-{
- char *p;
-
- if (!(p = malloc(size)))
- err_nomsg(1);
- memset(p, 0, size);
- return (p);
-}
-
-void
-usage()
-{
-
- (void)fprintf(stderr,
- _("usage: column [-tx] [-c columns] [file ...]\n"));
- exit(1);
-}
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* 2001-12-04 Charles Wilson: modified license to the 'BSD no advert'
- * license, as required by the Director of the Office of
- * Technology Licensing of the University of California on
- * July 22, 1999.
- * See http://www.opensource.org/licenses/bsd-license.html
- */
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "common.h"
-#include "errs.h"
-
-
-#ifdef HAVE_PROGNAME
-extern char *__progname; /* Program name, from crt0. */
-#else
-char *__progname = "foo"; /* probably libc4 */
-#endif
-
-/* Some compilers complain "null format string" upon err(1,NULL) */
-/* Make them happy with a separate routine. */
-void
-err_nomsg(int exitval) {
- (void)fprintf(stderr, "%s: %s\n", __progname, strerror(errno));
- exit(exitval);
-}
-
-void
-err(int exitval, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- verr(exitval, fmt, ap);
- va_end(ap);
-}
-
-void
-verr(int exitval, const char *fmt, va_list ap) {
- int sverrno;
-
- sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL && *fmt != 0) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
- exit(exitval);
-}
-
-void
-errx(int exitval, const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- verrx(exitval, fmt, ap);
- va_end(ap);
-}
-
-void
-verrx(int exitval, const char *fmt, va_list ap) {
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
- exit(exitval);
-}
-
-void
-warn(const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- vwarn(fmt, ap);
- va_end(ap);
-}
-
-void
-vwarn(const char *fmt, va_list ap) {
- int sverrno;
-
- sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
- }
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
-}
-
-void
-warnx(const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- vwarnx(fmt, ap);
- va_end(ap);
-}
-
-void
-vwarnx(const char *fmt, va_list ap) {
- (void)fprintf(stderr, "%s: ", __progname);
- if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
-}
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef _ERR_H_
-#define _ERR_H_
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "common.h"
-
-void err_nomsg (int);
-void err (int, const char *, ...);
-void verr (int, const char *, va_list);
-void errx (int, const char *, ...);
-void verrx (int, const char *, va_list);
-void warn (const char *, ...);
-void vwarn (const char *, va_list);
-void warnx (const char *, ...);
-void vwarnx (const char *, va_list);
-
-#endif /* !_ERR_H_ */
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef WIDECHAR_H
-#define WIDECHAR_H
-/* Declarations for wide characters */
-/* This file must be included last because the redefinition of wchar_t may
- cause conflicts when system include files were included after it. */
-#if HAVE_CONFIG_H
-# include "config.h" /* for ENABLE_WIDECHAR */
-#endif
-/* don't include "common.h" here */
-
-#ifdef ENABLE_WIDECHAR
-
-# include <wchar.h>
-# include <wctype.h>
-#if 0 /* for testing on platforms without built-in wide character support */
-# include <libutf8.h>
-#endif
-
-#if 1
-/* explicit prototypes, since sometimes <wchar.h> does not give them */
-extern int wcwidth (wint_t c);
-extern int wcswidth (const wchar_t *s, size_t n);
-extern size_t wcslen (const wchar_t *s);
-extern wchar_t *wcsdup (const wchar_t *s);
-#endif
-
-#else
-
-# include <ctype.h>
- /* Fallback for types */
-# define wchar_t char
-# define wint_t int
-# define WEOF EOF
- /* Fallback for input operations */
-# define fgetwc fgetc
-# define getwc getc
-# define getwchar getchar
-# define fgetws fgets
- /* Fallback for output operations */
-# define fputwc fputc
-# define putwc putc
-# define putwchar putchar
-# define fputws fputs
- /* Fallback for character classification */
-# define iswgraph isgraph
-# define iswprint isprint
-# define iswspace isspace
- /* Fallback for string functions */
-# define wcschr strchr
-# define wcsdup strdup
-# define wcslen strlen
-
-# define wcwidth(c) 1
-
-#endif
-#endif
+++ /dev/null
-.\" All Rites Reversed. This file is in the PUBLIC DOMAIN.
-.\" Kallisti.
-.TH DDATE 1 "59 Bureaucracy 3161" "" "Emperor Norton Utilities"
-.SH NAME
-ddate \- converts Gregorian dates to Discordian dates
-.SH SYNOPSIS
-.B ddate [+format] [date]
-.SH DESCRIPTION
-.B ddate
-prints the date in Discordian date format.
-.PP
-If called with no arguments,
-.B ddate
-will get the current system date, convert this to the Discordian
-date format and print this on the standard output. Alternatively, a
-Gregorian date may be specified on the command line, in the form of a numerical
-day, month and year.
-.PP
-If a format string is specified, the Discordian date will be printed in
-a format specified by the string. This mechanism works similarly to the
-format string mechanism of
-.B date(1),
-only almost completely differently. The fields are:
-.IP %A
-Full name of the day of the week (i.e., Sweetmorn)
-.IP %a
-Abbreviated name of the day of the week (i.e., SM)
-.IP %B
-Full name of the season (i.e., Chaos)
-.IP %b
-Abbreviated name of the season (i.e., Chs)
-.IP %d
-Ordinal number of day in season (i.e., 23)
-.IP %e
-Cardinal number of day in season (i.e., 23rd)
-.IP %H
-Name of current Holyday, if any
-.IP %N
-Magic code to prevent rest of format from being printed unless today is
-a Holyday.
-.IP %n
-Newline
-.IP %t
-Tab
-.IP %X
-Number of days remaining until X-Day. (Not valid if the SubGenius options
-are not compiled in.)
-.IP %{
-.IP %}
-Used to enclose the part of the string which is to be replaced with the
-words "St. Tib's Day" if the current day is St. Tib's Day.
-.IP %\.
-Try it and see.
-.bp
-.SH EXAMPLES
-.nf
-% ddate
-.br
-Sweetmorn, Bureaucracy 42, 3161 YOLD
-.PP
-% ddate +'Today is %{%A, the %e of %B%}, %Y. %N%nCelebrate %H'
-.br
-Today is Sweetmorn, the 42nd of Bureaucracy, 3161.
-.PP
-% ddate +"It's %{%A, the %e of %B%}, %Y. %N%nCelebrate %H" 26 9 1995
-.br
-It's Prickle-Prickle, the 50th of Bureaucracy, 3161.
-.br
-Celebrate Bureflux
-.PP
-% ddate +'Today's %{%A, the %e of %B%}, %Y. %N%nCelebrate %H' 29 2 1996
-.br
-Today's St. Tib's Day, 3162.
-.br
-
-.SH BUGS
-
-.B ddate(1)
-will produce undefined behaviour if asked to produce the date for St. Tib's
-day and its format string does not contain the St. Tib's Day delimiters
-%{ and %}.
-
-.SH NOTE
-
-After `X-Day' passed without incident, the Church of the SubGenius
-declared that it had got the year upside down - X-Day is actually in 8661 AD
-rather than 1998 AD. Thus, the True X-Day is Cfn 40, 9827.
-
-.SH AUTHOR
-.nh
-Original program by Druel the Chaotic aka Jeremy Johnson (mpython@gnu.ai.mit.edu)
-.br
-Major rewrite by Lee H:. O:. Smith, KYTP, aka Andrew Bulhak (acb@dev.null.org)
-.br
-Five tons of flax.
-
-.SH DISTRIBUTION POLICY
-
-Public domain. All rites reversed.
-
-.SH SEE ALSO
-
-date(1),
-.br
-http://www.subgenius.com/
-.br
-Malaclypse the Younger,
-.I "Principia Discordia, Or How I Found Goddess And What I Did To Her When I Found Her"
-
+++ /dev/null
-/* $ DVCS ID: $jer|,523/lhos,KYTP!41023161\b"?" <<= DO NOT DELETE! */
-
-/* ddate.c .. converts boring normal dates to fun Discordian Date -><-
- written the 65th day of The Aftermath in the Year of Our Lady of
- Discord 3157 by Druel the Chaotic aka Jeremy Johnson aka
- mpython@gnu.ai.mit.edu
- 28 Sever St Apt #3
- Worcester MA 01609
-*/
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-
-/*
- and I'm not responsible if this program messes anything up (except your
- mind, I'm responsible for that)
-
- (k) YOLD 3161 and all time before and after.
- Reprint, reuse, and recycle what you wish.
- This program is in the public domain. Distribute freely. Or not.
- (*) Charles Wilson changes under GPL
-
- Majorly hacked, extended and bogotified/debogotified on
- Sweetmorn, Bureaucracy 42, 3161 YOLD, by Lee H:. O:. Smith, KYTP,
- aka Andrew Bulhak, aka acb@dev.null.org
-
- and I'm not responsible if this program messes anything up (except your
- mind, I'm responsible for that) (and that goes for me as well --lhos)
-
- Version history:
- Bureflux 3161: First release of enhanced ddate with format strings
- 59 Bcy, 3161: PRAISE_BOB and KILL_BOB options split, other minor
- changes.
-
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- - added Native Language Support
-
- 2000-03-17 Burt Holzman <bnh@iname.com>
- - added range checks for dates
-
- 2002-01-26 Charles Wilson
- - minor changes so that it compiles on cygwin
- - removed nls.h dependency (but retain NLS capabiltiy)
- - changes (c) 2002 Charles Wilson. Licensed under the GPL.
-*/
-
-/* configuration options VVVVV READ THIS!!! */
-
-/* If you wish ddate(1) to print the date in the same format as Druel's
- * original ddate when called in immediate mode, define OLD_IMMEDIATE_FMT
- */
-
-#define OLD_IMMEDIATE_FMT
-
-/* If you wish to use the US format for aneristic dates (m-d-y), as opposed to
- * the Commonwealth format, define US_FORMAT.
- */
-
-/* #define US_FORMAT */
-
-/* If you are ideologically, theologically or otherwise opposed to the
- * Church of the SubGenius and do not wish your copy of ddate(1) to contain
- * code for counting down to X-Day, undefine KILL_BOB */
-
-#define KILL_BOB 13013
-
-/* If you wish ddate(1) to contain SubGenius slogans, define PRAISE_BOB */
-
-/*#define PRAISE_BOB 13013*/
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "common.h"
-
-#ifndef PACKAGE
-#define PACKAGE "cygutils"
-#endif
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#ifndef __GNUC__
-#define inline /* foo */
-#endif
-
-#ifdef KILL_BOB
-int xday_countdown(int yday, int year);
-#endif
-
-
-/* string constants */
-
-char *day_long[5] = {
- "Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"
-};
-
-char *day_short[5] = {"SM","BT","PD","PP","SO"};
-
-char *season_long[5] = {
- "Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"
-};
-
-char *season_short[5] = {"Chs", "Dsc", "Cfn", "Bcy", "Afm"};
-
-char *holyday[5][2] = {
- { "Mungday", "Chaoflux" },
- { "Mojoday", "Discoflux" },
- { "Syaday", "Confuflux" },
- { "Zaraday", "Bureflux" },
- { "Maladay", "Afflux" }
-};
-
-struct disc_time {
- int season; /* 0-4 */
- int day; /* 0-72 */
- int yday; /* 0-365 */
- int year; /* 3066- */
-};
-
-char *excl[] = {
- "Hail Eris!", "All Hail Discordia!", "Kallisti!", "Fnord.", "Or not.",
- "Wibble.", "Pzat!", "P'tang!", "Frink!",
-#ifdef PRAISE_BOB
- "Slack!", "Praise \"Bob\"!", "Or kill me.",
-#endif /* PRAISE_BOB */
- /* randomness, from the Net and other places. Feel free to add (after
- checking with the relevant authorities, of course). */
- "Grudnuk demand sustenance!", "Keep the Lasagna flying!",
- "Umlaut Zebra über alles!", "You are what you see.",
- "Or is it?", "This statement is false.",
-#if defined(linux) || defined (__linux__) || defined (__linux)
- "Hail Eris, Hack Linux!",
-#endif
- ""
-};
-
-char default_fmt[] = "%{%A, %B %d%}, %Y YOLD";
-char *default_immediate_fmt=
-#ifdef OLD_IMMEDIATE_FMT
-"Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H"
-#else
-default_fmt
-#endif
-;
-
-#define DY(y) (y+1166)
-
-static inline char *ending(int i) {
- return (i%10==1)?"st":(i%10==2?"nd":(i%10==3?"rd":"th"));
-}
-
-static inline int leapp(int i) {
- return (!(DY(i)%4))&&((DY(i)%100)||(!(DY(i)%400)));
-}
-
-/* select a random string */
-static inline char *sel(char **strings, int num) {
- return(strings[random()%num]);
-}
-
-void print(struct disc_time,char **); /* old */
-void format(char *buf, const char* fmt, struct disc_time dt);
-/* read a fortune file */
-int load_fortunes(char *fn, char *delim, char** result);
-
-struct disc_time convert(int,int);
-struct disc_time makeday(int,int,int);
-
-int
-main (int argc, char *argv[]) {
- long t;
- struct tm *eris;
- int bob,raw;
- struct disc_time hastur;
- char schwa[23*17], *fnord=0;
- int pi;
- char *progname, *p;
-
- progname = argv[0];
- if ((p = strrchr(progname, '/')) != NULL)
- progname = p+1;
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- srandom(time(NULL));
- /* do args here */
- for(pi=1; pi<argc; pi++) {
- switch(argv[pi][0]) {
- case '+': fnord=argv[pi]+1; break;
- case '-':
- switch(argv[pi][1]) {
- case 'V':
- printf(_("%s from %s version %s\n"), progname, PACKAGE, VERSION);
- default: goto usage;
- }
- default: goto thud;
- }
- }
-
- thud:
- if (argc-pi==3){
- int moe=atoi(argv[pi]), larry=atoi(argv[pi+1]), curly=atoi(argv[pi+2]);
- hastur=makeday(
-#ifdef US_FORMAT
- moe,larry,
-#else
- larry,moe,
-#endif
- curly);
- if (hastur.season == -1) {
- printf("Invalid date -- out of range\n");
- return -1;
- }
- fnord=fnord?fnord:default_fmt;
- } else if (argc!=pi) {
- usage:
- fprintf(stderr,_("usage: %s [+format] [day month year]\n"), argv[0]);
- exit(1);
- } else {
- t= time(NULL);
- eris=localtime(&t);
- bob=eris->tm_yday; /* days since Jan 1. */
- raw=eris->tm_year; /* years since 1980 */
- hastur=convert(bob,raw);
- fnord=fnord?fnord:default_immediate_fmt;
- }
- format(schwa, fnord, hastur);
- printf("%s\n", schwa);
-
- return 0;
-}
-
-void format(char *buf, const char* fmt, struct disc_time dt)
-{
- int tib_start=-1, tib_end=0;
- int i, fmtlen=strlen(fmt);
- char *bufptr=buf;
-
-/* fprintf(stderr, "format(%p, \"%s\", dt)\n", buf, fmt);*/
-
- /* first, find extents of St. Tib's Day area, if defined */
- for(i=0; i<fmtlen; i++) {
- if(fmt[i]=='%') {
- switch(fmt[i+1]) {
- case 'A':
- case 'a':
- case 'd':
- case 'e':
- if(tib_start>0) tib_end=i+1;
- else tib_start=i;
- break;
- case '{': tib_start=i; break;
- case '}': tib_end=i+1; break;
- }
- }
- }
-
- /* now do the formatting */
- buf[0]=0;
-
- for(i=0; i<fmtlen; i++) {
- if((i==tib_start) && (dt.day==-1)) {
- /* handle St. Tib's Day */
- strcpy(bufptr, _("St. Tib's Day")); bufptr += 13;
- i=tib_end;
- } else {
- if(fmt[i]=='%') {
- char *wibble=0, snarf[23];
- switch(fmt[++i]) {
- case 'A': wibble=day_long[dt.yday%5]; break;
- case 'a': wibble=day_short[dt.yday%5]; break;
- case 'B': wibble=season_long[dt.season]; break;
- case 'b': wibble=season_short[dt.season]; break;
- case 'd': sprintf(snarf, "%d", dt.day+1); wibble=snarf; break;
- case 'e': sprintf(snarf, "%d%s", dt.day+1, ending(dt.day+1));
- wibble=snarf; break;
- case 'H': if(dt.day==4||dt.day==49)
- wibble=holyday[dt.season][dt.day==49]; break;
- case 'N': if(dt.day!=4&&dt.day!=49) goto eschaton; break;
- case 'n': *(bufptr++)='\n'; break;
- case 't': *(bufptr++)='\t'; break;
-
- case 'Y': sprintf(snarf, "%d", dt.year); wibble=snarf; break;
- case '.': wibble=sel(excl, sizeof(excl)/sizeof(excl[0]));
- break;
-#ifdef KILL_BOB
- case 'X': sprintf(snarf, "%d",
- xday_countdown(dt.yday, dt.year));
- wibble = snarf; break;
-#endif /* KILL_BOB */
- }
- if(wibble) {
-/* fprintf(stderr, "wibble = (%s)\n", wibble);*/
- strcpy(bufptr, wibble); bufptr+=strlen(wibble);
- }
- } else {
- *(bufptr++) = fmt[i];
- }
- }
- }
- eschaton:
- *(bufptr)=0;
-}
-
-struct disc_time makeday(int imonth,int iday,int iyear) /*i for input */
-{
- struct disc_time funkychickens;
-
- int cal[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
- int dayspast=0;
-
- /* basic range checks */
- if (imonth < 1 || imonth > 12) {
- funkychickens.season = -1;
- return funkychickens;
- }
- if (iday < 1 || iday > cal[imonth-1]) {
- if (!(imonth == 2 && iday == 29 && iyear%4 == 0 &&
- (iyear%100 != 0 || iyear%400 == 0))) {
- funkychickens.season = -1;
- return funkychickens;
- }
- }
-
- imonth--;
- funkychickens.year= iyear+1166;
- while(imonth>0) { dayspast+=cal[--imonth]; }
- funkychickens.day=dayspast+iday-1;
- funkychickens.season=0;
- if((funkychickens.year%4)==2) {
- if (funkychickens.day==59 && iday==29) funkychickens.day=-1;
- }
- funkychickens.yday=funkychickens.day;
-/* note: EQUAL SIGN...hopefully that fixes it */
- while(funkychickens.day>=73) {
- funkychickens.season++;
- funkychickens.day-=73;
- }
- return funkychickens;
-}
-
-struct disc_time convert(int nday, int nyear)
-{ struct disc_time funkychickens;
-
- funkychickens.year = nyear+3066;
- funkychickens.day=nday;
- funkychickens.season=0;
- if ((funkychickens.year%4)==2)
- {if (funkychickens.day==59)
- funkychickens.day=-1;
- else if (funkychickens.day >59)
- funkychickens.day-=1;
- }
- funkychickens.yday=funkychickens.day;
- while (funkychickens.day>=73)
- { funkychickens.season++;
- funkychickens.day-=73;
- }
- return funkychickens;
-
- }
-
-#ifdef KILL_BOB
-
-/* Code for counting down to X-Day, X-Day being Cfn 40, 3164
- *
- * After `X-Day' passed without incident, the CoSG declared that it had
- * got the year upside down --- X-Day is actually in 8661 AD rather than
- * 1998 AD.
- *
- * Thus, the True X-Day is Cfn 40, 9827.
- *
- */
-
-int xday_countdown(int yday, int year) {
- int r=(185-yday)+(((yday<59)&&(leapp(year)))?1:0);
- while(year<9827) r+=(leapp(++year)?366:365);
- while(year>9827) r-=(leapp(year--)?366:365);
- return r;
-}
-
-#endif
+++ /dev/null
-
-PERPETUAL DATE CONVERTER FROM GREGORIAN TO POEE CALENDAR
-
-SEASONS
- 1. Chaos -- Patron Apostle Hung Mung
- 2. Discord -- Patron Apostle Dr. Van Van Mojo
- 3. Confusion -- Patron Apostle Sri Syadasti
- 4. Bureaucracy -- Patron Apostle Zarathud
- 5. The Aftermath -- Patron Apostle the Elder Malaclypse
-
-DAYS OF THE WEEK*
- 1. Sweetmorn *The DAYS OF THE WEEK
- 2. Boomtime are named from the five
- 3. Pungenday basic elements: SWEET,
- 4. Prickle-Prickle BOOM, PUNGENT, PRICKLE,
- 5. Setting Orange and ORANGE.
-
-HOLYDAYS
-A. Apostle Holydays B. Seasons Holydays
- 1. Mungday 1. Chaoflux
- 2. Mojoday 2. Discoflux
- 3. Syaday 3. Confuflux
- 4. Zaraday 4. Bureflux
- 5. Maladay 5. Afflux
-Each occurs on the 5th Each occurs on the 50th
-day of the Season day of the Season
-
-C. Saint Tib's Day -- occurs once every four years (1 + 4 = 5) and is
- inserted between the 59th and 60th days of the Season of Chaos
-
- ST BT PD PP SO SM BT PD PP SO
-Jan 1 2 3 4 5 1 2 3 4 5 Chs Jul 5 6 7 8 9 40 41 42 43 44 Cfn
- 6 7 8 9 10 6 7 8 9 10 10 11 12 13 14 45 46 47 48 49
- 11 12 13 14 15 11 12 13 14 15 15 16 17 18 19 50 51 52 53 54
- 16 17 18 19 20 16 17 18 19 20 20 21 22 23 24 55 56 57 58 59
- 21 22 23 24 25 21 22 23 24 25 25 26 27 28 29 60 61 62 63 64
- 26 27 28 29 30 26 27 28 29 30 30 31 1 2 3 65 66 67 68 69
- 31 1 2 3 4 31 32 33 34 35 Aug 4 5 6 7 8 70 71 72 73 1 Bcy
-Feb 5 6 7 8 9 36 37 38 39 40 9 10 11 12 13 2 3 4 5 6
- 10 11 12 13 14 41 42 43 44 45 14 15 16 17 18 7 8 9 10 11
- 15 16 17 18 19 46 47 48 49 50 19 20 21 22 23 12 13 14 15 16
- 20 21 22 23 24 51 52 53 54 55 24 25 26 27 28 17 18 19 20 21
- 25 26 27 28* 1 56 57 58 59 60 29 30 31 1 2 22 23 24 25 26
-Mar 2 3 4 5 6 61 62 63 64 65 Sep 3 4 5 6 7 27 28 29 30 31
- 7 8 9 10 11 66 67 68 69 70 8 9 10 11 12 32 33 34 35 36
- 12 13 14 15 16 71 72 73 1 2 Dsc 13 14 15 16 17 37 38 39 40 41
- 17 18 19 20 21 3 4 5 6 7 18 19 20 21 22 42 43 44 45 46
- 22 23 24 25 26 8 9 10 11 12 23 24 25 26 27 47 48 49 50 51
- 27 28 29 30 31 13 14 15 16 17 28 29 30 1 2 52 53 54 55 56
-Apr 1 2 3 4 5 18 19 20 21 22 Oct 3 4 5 6 7 57 58 59 60 61
- 6 7 8 9 10 23 24 25 26 27 8 9 10 11 12 62 63 64 65 66
- 11 12 13 14 15 28 29 30 31 32 13 14 15 16 17 67 68 69 70 71
- 16 17 18 19 20 33 34 35 36 37 18 19 20 21 22 72 73 1 2 3 Afm
- 21 22 23 24 25 38 39 40 41 42 23 24 25 26 27 4 5 6 7 8
- 26 27 28 29 30 43 44 45 46 47 28 29 30 31 1 9 10 11 12 13
-May 1 2 3 4 5 48 49 50 51 52 Nov 2 3 4 5 6 14 15 16 17 18
- 6 7 8 9 10 53 54 55 56 57 7 8 9 10 11 19 20 21 22 23
- 11 12 13 14 15 58 59 60 61 62 12 13 14 15 16 24 25 26 27 28
- 16 17 18 19 20 63 64 65 66 67 17 18 19 20 21 29 30 31 32 33
- 21 22 23 24 25 68 69 70 71 72 22 23 24 25 26 34 35 36 37 38
- 26 27 28 29 30 73 1 2 3 4 Cfn 27 28 29 30 1 39 40 41 42 43
- 31 1 2 3 4 5 6 7 8 9 Dec 2 3 4 5 6 44 45 46 47 48
-Jun 5 6 7 8 9 10 11 12 13 14 7 8 9 10 11 49 50 51 52 53
- 10 11 12 13 14 15 16 17 18 19 12 13 14 15 16 54 55 56 57 58
- 15 16 17 18 19 20 21 22 23 24 17 18 19 20 21 59 60 61 62 63
- 20 21 22 23 24 25 26 27 28 29 22 23 24 25 26 64 65 66 67 68
- 25 26 27 28 29 30 31 32 33 34 27 28 29 30 31 69 70 71 72 73
- 30 1 2 3 4 35 36 37 38 39 [1970 = 3136] [Next St. Tib's Day in 3138]
-
- SACRED DOCUMENT OF THE FROGS (old Erisian poem):
- 73 Days hath
- Chaos, Discord, Confusion, Bureaucracy, and Aftermath
-
+++ /dev/null
-.TH GETOPT 1 "May 31, 1997" Linux ""
-.SH NAME
-getopt \- parse command options (enhanced)
-.SH SYNOPSIS
-.BR getopt " optstring parameters"
-
-.BR getopt " [options] [" -- "] optstring parameters"
-
-.BR getopt " [options] " -o | --options " optstring [options] [" -- "] parameters"
-.SH DESCRIPTION
-.B getopt
-is used to break up
-.RI ( parse )
-options in command lines for easy parsing by
-shell procedures, and to check for legal options.
-It uses the
-.SM GNU
-.BR getopt (3)
-routines to do this.
-
-The parameters
-.B getopt
-is called with can be divided into two parts: options
-which modify the way getopt will parse
-.RI ( options
-and
-.I -o|--options optstring
-in the
-.BR SYNOPSIS),
-and the parameters which are to be
-parsed
-.RI ( parameters
-in the
-.BR SYNOPSIS).
-The second part will start at the first non-option parameter
-that is not an option argument, or after the first occurence of
-.RB ` -- '.
-If no
-.RB ` -o '
-or
-.RB ` --options '
-option is found in the first part, the first
-parameter of the second part is used as the short options string.
-
-If the environment variable
-.B GETOPT_COMPATIBLE
-is set, or if its first parameter
-is not an option (does not start with a
-.RB ` - ',
-this is the first format in the
-.BR SYNOPSIS),
-.B getopt
-will generate output that is compatible with that of other versions of
-.BR getopt (1).
-It will still do parameter shuffling and recognize optional
-arguments (see section
-.B COMPATIBILITY
-for more information).
-
-Traditional implementations of
-.BR getopt (1)
-are unable to cope with whitespace and other (shell-specific) special characters
-in arguments and non-option parameters. To solve this problem, this
-implementation can generate
-quoted output which must once again be interpreted by the shell (usually
-by using the
-.B eval
-command). This has the effect of preserving those characters, but
-you must call
-.B getopt
-in a way that is no longer compatible with other versions (the second
-or third format in the
-.BR SYNOPSIS).
-To determine whether this enhanced version of
-.BR getopt (1)
-is installed, a special test option
-.RB ( -T )
-can be used.
-.SH OPTIONS
-.IP "-a, --alternative"
-Allow long options to start with a single
-.RB ` - '.
-.IP "-h, --help"
-Output a small usage guide and exit succesfully. No other output is generated.
-.IP "-l, --longoptions longopts"
-The long (multi-character) options to be recognized.
-More than one option name
-may be specified at once, by separating the names with commas. This option
-may be given more than once, the
-.I longopts
-are cummulative.
-Each long option name
-in
-.I longopts
-may be followed by one colon to indicate it has a required argument,and by two colons to indicate it has an optional argument.
-.IP "-n, --name progname"
-The name that will be used by the
-.BR getopt (3)
-routines when it reports errors. Note that errors of
-.BR getopt (1)
-are still reported as coming from getopt.
-.IP "-o, --options shortopts"
-The short (one-character) options to be recognized. If this options is not
-found, the first parameter of
-.B getopt
-that does not start with
-a
-.RB ` - '
-(and is not an option argument) is used as the short options string.
-Each short option character
-in
-.I shortopts
-may be followed by one colon to indicate it has a required argument,
-and by two colons to indicate it has an optional argument.
-The first character of shortopts may be
-.RB ` + '
-or
-.RB ` - '
-to influence the way
-options are parsed and output is generated (see section
-.B SCANNING MODES
-for details).
-.IP "-q, --quiet"
-Disable error reporting by getopt(3).
-.IP "-Q, --quiet-output"
-Do not generate normal output. Errors are still reported by
-.BR getopt (3),
-unless you also use
-.IR -q .
-.IP "-s, --shell shell"
-Set quoting conventions to those of shell. If no -s argument is found,
-the
-.SM BASH
-conventions are used. Valid arguments are currently
-.RB ` sh '
-.RB ` bash ',
-.RB ` csh ',
-and
-.RB ` tcsh '.
-.IP "-u, --unquoted"
-Do not quote the output. Note that whitespace and special (shell-dependent)
-characters can cause havoc in this mode (like they do with other
-.BR getopt (1)
-implementations).
-.IP "-T --test"
-Test if your
-.BR getopt (1)
-is this enhanced version or an old version. This generates no output,
-and sets the error status to 4. Other implementations of
-.BR getopt (1),
-and this version if the environment variable
-.B GETOPT_COMPATIBLE
-is set,
-will return
-.RB ` -- '
-and error status 0.
-.IP "-V, --version"
-Output version information and exit succesfully. No other output is generated.
-.SH PARSING
-This section specifies the format of the second part of the parameters of
-.B getopt
-(the
-.I parameters
-in the
-.BR SYNOPSIS ).
-The next section
-.RB ( OUTPUT )
-describes the output that is
-generated. These parameters were typically the parameters a shell function
-was called with.
-Care must be taken that each parameter the shell function was
-called with corresponds to exactly one parameter in the parameter list of
-.B getopt
-(see the
-.BR EXAMPLES ).
-All parsing is done by the GNU
-.BR getopt (3)
-routines.
-
-The parameters are parsed from left to right. Each parameter is classified as a
-short option, a long option, an argument to an option,
-or a non-option parameter.
-
-A simple short option is a
-.RB ` - '
-followed by a short option character. If
-the option has a required argument, it may be written directly after the option
-character or as the next parameter (ie. separated by whitespace on the
-command line). If the
-option has an optional argument, it must be written directly after the
-option character if present.
-
-It is possible to specify several short options after one
-.RB ` - ',
-as long as all (except possibly the last) do not have required or optional
-arguments.
-
-A long option normally begins with
-.RB ` -- '
-followed by the long option name.
-If the option has a required argument, it may be written directly after
-the long option name, separated by
-.RB ` = ',
-or as the next argument (ie. separated by whitespace on the command line).
-If the option has an optional argument, it must
-be written directly after the long option name, separated by
-.RB ` = ',
-if present (if you add the
-.RB ` = '
-but nothing behind it, it is interpreted
-as if no argument was present; this is a slight bug, see the
-.BR BUGS ).
-Long options may be abbreviated, as long as the abbreviation is not
-ambiguous.
-
-Each parameter not starting with a
-.RB ` - ',
-and not a required argument of
-a previous option, is a non-option parameter. Each parameter after
-a
-.RB ` -- '
-parameter is always interpreted as a non-option parameter.
-If the environment variable
-.B POSIXLY_CORRECT
-is set, or if the short
-option string started with a
-.RB ` + ',
-all remaining parameters are interpreted
-as non-option parameters as soon as the first non-option parameter is
-found.
-.SH OUTPUT
-Output is generated for each element described in the previous section.
-Output is done
-in the same order as the elements are specified in the input, except
-for non-option parameters. Output can be done in
-.I compatible
-.RI ( unquoted )
-mode, or in such way that whitespace and other special characters within
-arguments and non-option parameters are preserved (see
-.BR QUOTING ).
-When the output is processed in the shell script, it will seem to be
-composed of distinct elements that can be processed one by one (by using the
-shift command in most shell languages). This is imperfect in unquoted mode,
-as elements can be split at unexpected places if they contain whitespace
-or special characters.
-
-If there are problems parsing the parameters, for example because a
-required argument is not found or an option is not recognized, an error
-will be reported on stderr, there will be no output for the offending
-element, and a non-zero error status is returned.
-
-For a short option, a single
-.RB ` - '
-and the option character are generated
-as one parameter. If the option has an argument, the next
-parameter will be the argument. If the option takes an optional argument,
-but none was found, the next parameter will be generated but be empty in
-quoting mode,
-but no second parameter will be generated in unquoted (compatible) mode.
-Note that many other
-.BR getopt (1)
-implemetations do not support optional arguments.
-
-If several short options were specified after a single
-.RB ` - ',
-each will be present in the output as a separate parameter.
-
-For a long option,
-.RB ` -- '
-and the full option name are generated as one
-parameter. This is done regardless whether the option was abbreviated or
-specified with a single
-.RB ` - '
-in the input. Arguments are handled as with short options.
-
-Normally, no non-option parameters output is generated until all options
-and their arguments have been generated. Then
-.RB ` -- '
-is generated as a
-single parameter, and after it the non-option parameters in the order
-they were found, each as a separate parameter.
-Only if the first character of the short options string was a
-.RB ` - ',
-non-option parameter output is generated at the place they are found in the
-input (this is not supported if the first format of the
-.B SYNOPSIS
-is used; in that case all preceding occurences of
-.RB ` - '
-and
-.RB ` + '
-are ignored).
-.SH QUOTING
-In compatible mode, whitespace or 'special' characters in arguments or
-non-option parameters are not handled correctly. As the output is
-fed to the shell script, the script does not know how it is supposed to break
-the output into separate parameters. To circumvent this
-problem, this implementation offers quoting. The idea is that output
-is generated with quotes around each parameter. When this output is once
-again fed to the shell (usually by a shell
-.B eval
-command), it is split correctly into separate parameters.
-
-Quoting is not enabled if the environment variable
-.B GETOPT_COMPATIBLE
-is set, if the first form of the
-.B SYNOPSIS
-is used, or if the option
-.RB ` -u '
-is found.
-
-Different shells use different quoting conventions. You can use the
-.RB ` -s '
-option to select the shell you are using. The following shells are
-currently supported:
-.RB ` sh ',
-.RB ` bash ',
-.RB ` csh '
-and
-.RB ` tcsh '.
-Actually, only two `flavors' are distinguished: sh-like quoting conventions
-and csh-like quoting conventions. Chances are that if you use another shell
-script language, one of these flavors can still be used.
-
-.SH "SCANNING MODES"
-The first character of the short options string may be a
-.RB ` - '
-or a
-.RB ` + '
-to indicate a special scanning mode. If the first calling form
-in the
-.B SYNOPSIS
-is used they are ignored; the environment variable
-.B POSIXLY_CORRECT
-is still examined, though.
-
-If the first character is
-.RB ` + ',
-or if the environment variable
-.B POSIXLY_CORRECT
-is set, parsing stops as soon as the first non-option parameter
-(ie. a parameter that does not start with a
-.RB ` - ')
-is found that
-is not an option argument. The remaining parameters are all interpreted as
-non-option parameters.
-
-If the first character is a
-.RB ` - ',
-non-option parameters are outputed at the place where they are found; in normal
-operation, they are all collected at the end of output after a
-.RB ` -- '
-parameter has been generated. Note that this
-.RB ` -- '
-parameter is still generated, but it will always be the last parameter in
-this mode.
-.SH COMPATIBILITY
-This version of
-.BR getopt (1)
-is written to be as compatible as possible to
-other versions. Usually you can just replace them with this version
-without any modifications, and with some advantages.
-
-If the first character of the first parameter of getopt is not a
-.RB ` - ',
-getopt goes into compatibility mode. It will interpret its first parameter as
-the string of short options, and all other arguments will be parsed. It
-will still do parameter shuffling (ie. all non-option parameters are outputed
-at the end), unless the environment variable
-.B POSIXLY_CORRECT
-is set.
-
-The environment variable
-.B GETOPT_COMPATIBLE
-forces
-.B getopt
-into compatibility mode. Setting both this environment variable and
-.B POSIXLY_CORRECT
-offers 100% compatibility for `difficult' programs. Usually, though,
-neither is needed.
-
-In compatibility mode, leading
-.RB ` - '
-and
-.RB ` + '
-characters in the short options string are ignored.
-.SH RETURN CODES
-.B getopt
-returns error code
-.B 0
-for succesful parsing,
-.B 1
-if
-.BR getopt (3)
-returns errors,
-.B 2
-if it does not understand its own parameters,
-.B 3
-if an internal error occurs like out-of-memory, and
-.B 4
-if it is called with
-.BR -T .
-.SH EXAMPLES
-Example scripts for (ba)sh and (t)csh are provided with the
-.BR getopt (1)
-distribution, and are optionally installed in
-.B /usr/local/lib/getopt
-or
-.BR /usr/lib/getopt .
-.SH ENVIRONMENT
-.IP POSIXLY_CORRECT
-This environment variable is examined by the
-.BR getopt (3)
-routines.
-If it is set, parsing stops as soon as a parameter
-is found that is not an option or an option argument. All remaining
-parameters are also interpreted as non-option parameters, regardless
-whether they start with a
-.RB ` - '.
-.IP GETOPT_COMPATIBLE
-Forces
-.B getopt
-to use the first calling format as specified in the
-.BR SYNOPSIS .
-.SH BUGS
-.BR getopt (3)
-can parse long options with optional arguments that are given an empty optional
-argument (but can not do this for short options). This
-.BR getopt (1)
-treats optional arguments that are empty as if they were not present.
-
-The syntax if you do not want any short option variables at all is
-not very intuitive (you have to set them explicitely to the empty
-string).
-
-.SH AUTHOR
-Frodo Looijaard <frodol@dds.nl>
-.SH "SEE ALSO"
-.BR getopt (3),
-.BR bash (1),
-.BR tcsh (1).
-
+++ /dev/null
-/*
- getopt.c - Enhanced implementation of BSD getopt(1)
- Copyright (c) 1997, 1998, 1999, 2000 Frodo Looijaard <frodol@dds.nl>
-
- 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 2 of the License, 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.
-*/
-
-/*
- * Version 1.0-b4: Tue Sep 23 1997. First public release.
- * Version 1.0: Wed Nov 19 1997.
- * Bumped up the version number to 1.0
- * Fixed minor typo (CSH instead of TCSH)
- * Version 1.0.1: Tue Jun 3 1998
- * Fixed sizeof instead of strlen bug
- * Bumped up the version number to 1.0.1
- * Version 1.0.2: Thu Jun 11 1998 (not present)
- * Fixed gcc-2.8.1 warnings
- * Fixed --version/-V option (not present)
- * Version 1.0.5: Tue Jun 22 1999
- * Make -u option work (not present)
- * Version 1.0.6: Tue Jun 27 2000
- * No important changes
- */
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* common.h does this */
-/*
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#if LIBCGETOPT
-#include <getopt.h>
-#else
-#include "getopt.h"
-#endif
-*/
-
-#define _(x) x
-
-/* NON_OPT is the code that is returned when a non-option is found in '+'
- mode */
-#define NON_OPT 1
-/* LONG_OPT is the code that is returned when a long option is found. */
-#define LONG_OPT 2
-
-/* The shells recognized. */
-typedef enum {BASH,TCSH} shell_t;
-
-
-/* Some global variables that tells us how to parse. */
-shell_t shell=BASH; /* The shell we generate output for. */
-int quiet_errors=0; /* 0 is not quiet. */
-int quiet_output=0; /* 0 is not quiet. */
-int quote=1; /* 1 is do quote. */
-#ifdef HAVE_GETOPT_LONG_ONLY
-int alternative=0; /* 0 is getopt_long, 1 is getopt_long_only */
-#endif
-
-/* Function prototypes */
-void *our_malloc(size_t size);
-void *our_realloc(void *ptr, size_t size);
-const char *normalize(const char *arg);
-int generate_output(char * argv[],int argc,const char *optstr,
- const struct option *longopts);
-int main(int argc, char *argv[]);
-void parse_error(const char *message);
-void add_long_options(char *options);
-void add_longopt(const char *name,int has_arg);
-void print_help(void);
-void set_shell(const char *new_shell);
-void set_initial_shell(void);
-
-void *our_malloc(size_t size)
-{
- void *ret=malloc(size);
- if (! ret) {
- fprintf(stderr,_("%s: Out of memory!\n"),"getopt");
- exit(3);
- }
- return(ret);
-}
-
-void *our_realloc(void *ptr, size_t size)
-{
- void *ret=realloc(ptr,size);
- if (! ret && size) {
- fprintf(stderr,_("%s: Out of memory!\n"),"getopt");
- exit(3);
- }
- return(ret);
-}
-
-/*
- * This function 'normalizes' a single argument: it puts single quotes around
- * it and escapes other special characters. If quote is false, it just
- * returns its argument.
- * Bash only needs special treatment for single quotes; tcsh also recognizes
- * exclamation marks within single quotes, and nukes whitespace.
- * This function returns a pointer to a buffer that is overwritten by
- * each call.
- */
-const char *normalize(const char *arg)
-{
- static char *BUFFER=NULL;
- const char *argptr=arg;
- char *bufptr;
-
- if (BUFFER != NULL)
- free(BUFFER);
-
- if (!quote) { /* Just copy arg */
- BUFFER=our_malloc(strlen(arg)+1);
-
- strcpy(BUFFER,arg);
- return BUFFER;
- }
-
- /* Each character in arg may take upto four characters in the result:
- For a quote we need a closing quote, a backslash, a quote and an
- opening quote! We need also the global opening and closing quote,
- and one extra character for '\0'. */
- BUFFER=our_malloc(strlen(arg)*4+3);
-
- bufptr=BUFFER;
- *bufptr++='\'';
-
- while (*argptr) {
- if (*argptr == '\'') {
- /* Quote: replace it with: '\'' */
- *bufptr++='\'';
- *bufptr++='\\';
- *bufptr++='\'';
- *bufptr++='\'';
- } else if (shell==TCSH && *argptr=='!') {
- /* Exclamation mark: replace it with: \! */
- *bufptr++='\'';
- *bufptr++='\\';
- *bufptr++='!';
- *bufptr++='\'';
- } else if (shell==TCSH && *argptr=='\n') {
- /* Newline: replace it with: \n */
- *bufptr++='\\';
- *bufptr++='n';
- } else if (shell==TCSH && isspace(*argptr)) {
- /* Non-newline whitespace: replace it with \<ws> */
- *bufptr++='\'';
- *bufptr++='\\';
- *bufptr++=*argptr;
- *bufptr++='\'';
- } else
- /* Just copy */
- *bufptr++=*argptr;
- argptr++;
- }
- *bufptr++='\'';
- *bufptr++='\0';
- return BUFFER;
-}
-
-/*
- * Generate the output. argv[0] is the program name (used for reporting errors).
- * argv[1..] contains the options to be parsed. argc must be the number of
- * elements in argv (ie. 1 if there are no options, only the program name),
- * optstr must contain the short options, and longopts the long options.
- * Other settings are found in global variables.
- */
-int generate_output(char * argv[],int argc,const char *optstr,
- const struct option *longopts)
-{
- int exit_code = 0; /* We assume everything will be OK */
- int opt;
- int longindex;
- const char *charptr;
-
- if (quiet_errors) /* No error reporting from getopt(3) */
- opterr=0;
- optind=0; /* Reset getopt(3) */
-
-#ifdef HAVE_GETOPT_LONG_ONLY
- while ((opt = (alternative?
- getopt_long_only(argc,argv,optstr,longopts,&longindex):
-#else
- while ((opt = (
-#endif
- getopt_long(argc,argv,optstr,longopts,&longindex)))
- != EOF)
- if (opt == '?' || opt == ':' )
- exit_code = 1;
- else if (!quiet_output)
- {
- if (opt == LONG_OPT) {
- printf(" --%s",longopts[longindex].name);
- if (longopts[longindex].has_arg)
- printf(" %s",
- normalize(optarg?optarg:""));
- } else if (opt == NON_OPT)
- printf(" %s",normalize(optarg));
- else {
- printf(" -%c",opt);
- charptr = strchr(optstr,opt);
- if (charptr != NULL && *++charptr == ':')
- printf(" %s",
- normalize(optarg?optarg:""));
- }
- }
-
- if (! quiet_output) {
- printf(" --");
- while (optind < argc)
- printf(" %s",normalize(argv[optind++]));
- printf("\n");
- }
- return exit_code;
-}
-
-/*
- * Report an error when parsing getopt's own arguments.
- * If message is NULL, we already sent a message, we just exit with a helpful
- * hint.
- */
-void parse_error(const char *message)
-{
- if (message)
- fprintf(stderr,"getopt: %s\n",message);
- fputs(_("Try `getopt --help' for more information.\n"),stderr);
- exit(2);
-}
-
-static struct option *long_options=NULL;
-static int long_options_length=0; /* Length of array */
-static int long_options_nr=0; /* Nr of used elements in array */
-#define LONG_OPTIONS_INCR 10
-#define init_longopt() add_longopt(NULL,0)
-
-/* Register a long option. The contents of name is copied. */
-void add_longopt(const char *name,int has_arg)
-{
- char *tmp;
- if (!name) { /* init */
- free(long_options);
- long_options=NULL;
- long_options_length=0;
- long_options_nr=0;
- }
-
- if (long_options_nr == long_options_length) {
- long_options_length += LONG_OPTIONS_INCR;
- long_options=our_realloc(long_options,
- sizeof(struct option) *
- long_options_length);
- }
-
- long_options[long_options_nr].name=NULL;
- long_options[long_options_nr].has_arg=0;
- long_options[long_options_nr].flag=NULL;
- long_options[long_options_nr].val=0;
-
- if (long_options_nr) { /* Not for init! */
- long_options[long_options_nr-1].has_arg=has_arg;
- long_options[long_options_nr-1].flag=NULL;
- long_options[long_options_nr-1].val=LONG_OPT;
- tmp = our_malloc(strlen(name)+1);
- strcpy(tmp,name);
- long_options[long_options_nr-1].name=tmp;
- }
- long_options_nr++;
-}
-
-
-/*
- * Register several long options. options is a string of long options,
- * separated by commas or whitespace.
- * This nukes options!
- */
-void add_long_options(char *options)
-{
- int arg_opt;
- char *tokptr=strtok(options,", \t\n");
- while (tokptr) {
- arg_opt=no_argument;
- if (strlen(tokptr) > 0) {
- if (tokptr[strlen(tokptr)-1] == ':') {
- if (tokptr[strlen(tokptr)-2] == ':') {
- tokptr[strlen(tokptr)-2]='\0';
- arg_opt=optional_argument;
- } else {
- tokptr[strlen(tokptr)-1]='\0';
- arg_opt=required_argument;
- }
- if (strlen(tokptr) == 0)
- parse_error(_("empty long option after "
- "-l or --long argument"));
- }
- add_longopt(tokptr,arg_opt);
- }
- tokptr=strtok(NULL,", \t\n");
- }
-}
-
-void set_shell(const char *new_shell)
-{
- if (!strcmp(new_shell,"bash"))
- shell=BASH;
- else if (!strcmp(new_shell,"tcsh"))
- shell=TCSH;
- else if (!strcmp(new_shell,"sh"))
- shell=BASH;
- else if (!strcmp(new_shell,"csh"))
- shell=TCSH;
- else
- parse_error(_("unknown shell after -s or --shell argument"));
-}
-
-void print_help(void)
-{
- fputs(_("Usage: getopt optstring parameters\n"),stderr);
- fputs(_(" getopt [options] [--] optstring parameters\n"),stderr);
- fputs(_(" getopt [options] -o|--options optstring [options] [--]\n"),stderr);
- fputs(_(" parameters\n"),stderr);
-#ifdef HAVE_GETOPT_LONG_ONLY
- fputs(_(" -a, --alternative Allow long options starting with single -\n"),stderr);
-#endif
- fputs(_(" -h, --help This small usage guide\n"),stderr);
- fputs(_(" -l, --longoptions=longopts Long options to be recognized\n"),stderr);
- fputs(_(" -n, --name=progname The name under which errors are reported\n"),stderr);
- fputs(_(" -o, --options=optstring Short options to be recognized\n"),stderr);
- fputs(_(" -q, --quiet Disable error reporting by getopt(3)\n"),stderr);
- fputs(_(" -Q, --quiet-output No normal output\n"),stderr);
- fputs(_(" -s, --shell=shell Set shell quoting conventions\n"),stderr);
- fputs(_(" -T, --test Test for getopt(1) version\n"),stderr);
- fputs(_(" -u, --unqote Do not quote the output\n"),stderr);
- fputs(_(" -V, --version Output version information\n"),stderr);
- exit(2);
-}
-
-/* Exit codes:
- * 0) No errors, succesful operation.
- * 1) getopt(3) returned an error.
- * 2) A problem with parameter parsing for getopt(1).
- * 3) Internal error, out of memory
- * 4) Returned for -T
- */
-
-static struct option longopts[]={ {"options",required_argument,NULL,'o'},
- {"longoptions",required_argument,NULL,'l'},
- {"quiet",no_argument,NULL,'q'},
- {"quiet-output",no_argument,NULL,'Q'},
- {"shell",required_argument,NULL,'s'},
- {"test",no_argument,NULL,'T'},
- {"unquoted",no_argument,NULL,'u'},
- {"help",no_argument,NULL,'h'},
-#ifdef HAVE_GETOPT_LONG_ONLY
- {"alternative",no_argument,NULL,'a'},
-#endif
- {"name",required_argument,NULL,'n'},
- {"version",no_argument,NULL,'V'},
- {NULL,0,NULL,0}
- };
-
-/* Stop scanning as soon as a non-option argument is found! */
-static const char *shortopts="+ao:l:n:qQs:TuhV";
-
-int main(int argc, char *argv[])
-{
- char *optstr=NULL;
- char *name=NULL;
- int opt;
- int compatible=0;
-
- init_longopt();
-
- if (getenv("GETOPT_COMPATIBLE"))
- compatible=1;
-
- if (argc == 1)
- {
- if (compatible) {
- /* For some reason, the original getopt gave no error
- when there were no arguments. */
- printf(" --\n");
- exit(0);
- }
- else
- parse_error(_("missing optstring argument"));
- }
-
- if (argv[1][0] != '-' || compatible) {
- quote=0;
- optstr=our_malloc(strlen(argv[1])+1);
- strcpy(optstr,argv[1]+strspn(argv[1],"-+"));
- argv[1]=argv[0];
- exit(generate_output(argv+1,argc-1,optstr,long_options));
- }
-
- while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
- switch (opt) {
-#ifdef HAVE_GETOPT_LONG_ONLY
- case 'a':
- alternative=1;
- break;
-#endif
- case 'h':
- print_help();
- exit(0);
- case 'o':
- if (optstr)
- free(optstr);
- optstr=our_malloc(strlen(optarg)+1);
- strcpy(optstr,optarg);
- break;
- case 'l':
- add_long_options(optarg);
- break;
- case 'n':
- if (name)
- free(name);
- name=our_malloc(strlen(optarg)+1);
- strcpy(name,optarg);
- break;
- case 'q':
- quiet_errors=1;
- break;
- case 'Q':
- quiet_output=1;
- break;
- case 's':
- set_shell(optarg);
- break;
- case 'T':
- exit(4);
- case 'u':
- quote=0;
- break;
- case 'V':
- printf(_("getopt (enhanced) 1.1.2\n"));
- exit(0);
- case '?':
- case ':':
- parse_error(NULL);
- default:
- parse_error(_("internal error, contact the author."));
- }
-
- if (!optstr)
- {
- if (optind >= argc)
- parse_error(_("missing optstring argument"));
- else {
- optstr=our_malloc(strlen(argv[optind])+1);
- strcpy(optstr,argv[optind]);
- optind++;
- }
- }
- if (name)
- argv[optind-1]=name;
- else
- argv[optind-1]=argv[0];
- exit(generate_output(argv+optind-1,argc-optind+1,optstr,long_options));
-}
+++ /dev/null
-#!/bin/bash
-
-# A small example program for using the new getopt(1) program.
-# This program will only work with bash(1)
-# An similar program using the tcsh(1) script language can be found
-# as parse.tcsh
-
-# Example input and output (from the bash prompt):
-# ./parse.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long "
-# Option a
-# Option c, no argument
-# Option c, argument `more'
-# Option b, argument ` very long '
-# Remaining arguments:
-# --> `par1'
-# --> `another arg'
-# --> `wow!*\?'
-
-# Note that we use `"$@"' to let each command-line parameter expand to a
-# separate word. The quotes around `$@' are essential!
-# We need TEMP as the `eval set --' would nuke the return value of getopt.
-TEMP=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
- -n 'example.bash' -- "$@"`
-
-if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
-
-# Note the quotes around `$TEMP': they are essential!
-eval set -- "$TEMP"
-
-while true ; do
- case "$1" in
- -a|--a-long) echo "Option a" ; shift ;;
- -b|--b-long) echo "Option b, argument \`$2'" ; shift 2 ;;
- -c|--c-long)
- # c has an optional argument. As we are in quoted mode,
- # an empty parameter will be generated if its optional
- # argument is not found.
- case "$2" in
- "") echo "Option c, no argument"; shift 2 ;;
- *) echo "Option c, argument \`$2'" ; shift 2 ;;
- esac ;;
- --) shift ; break ;;
- *) echo "Internal error!" ; exit 1 ;;
- esac
-done
-echo "Remaining arguments:"
-for arg do echo '--> '"\`$arg'" ; done
+++ /dev/null
-#!/bin/tcsh
-
-# A small example program for using the new getopt(1) program.
-# This program will only work with tcsh(1)
-# An similar program using the bash(1) script language can be found
-# as parse.bash
-
-# Example input and output (from the tcsh prompt):
-# ./parse.tcsh -a par1 'another arg' --c-long 'wow\!*\?' -cmore -b " very long "
-# Option a
-# Option c, no argument
-# Option c, argument `more'
-# Option b, argument ` very long '
-# Remaining arguments:
-# --> `par1'
-# --> `another arg'
-# --> `wow!*\?'
-
-# Note that we had to escape the exclamation mark in the wow-argument. This
-# is _not_ a problem with getopt, but with the tcsh command parsing. If you
-# would give the same line from the bash prompt (ie. call ./parse.tcsh),
-# you could remove the exclamation mark.
-
-# This is a bit tricky. We use a temp variable, to be able to check the
-# return value of getopt (eval nukes it). argv contains the command arguments
-# as a list. The ':q` copies that list without doing any substitutions:
-# each element of argv becomes a separate argument for getopt. The braces
-# are needed because the result is also a list.
-set temp=(`getopt -s tcsh -o ab:c:: --long a-long,b-long:,c-long:: -- $argv:q`)
-if ($? != 0) then
- echo "Terminating..." >/dev/stderr
- exit 1
-endif
-
-# Now we do the eval part. As the result is a list, we need braces. But they
-# must be quoted, because they must be evaluated when the eval is called.
-# The 'q` stops doing any silly substitutions.
-eval set argv=\($temp:q\)
-
-while (1)
- switch($1:q)
- case -a:
- case --a-long:
- echo "Option a" ; shift
- breaksw;
- case -b:
- case --b-long:
- echo "Option b, argument "\`$2:q\' ; shift ; shift
- breaksw
- case -c:
- case --c-long:
- # c has an optional argument. As we are in quoted mode,
- # an empty parameter will be generated if its optional
- # argument is not found.
-
- if ($2:q == "") then
- echo "Option c, no argument"
- else
- echo "Option c, argument "\`$2:q\'
- endif
- shift; shift
- breaksw
- case --:
- shift
- break
- default:
- echo "Internal error!" ; exit 1
- endsw
-end
-
-echo "Remaining arguments:"
-# foreach el ($argv:q) created problems for some tcsh-versions (at least
-# 6.02). So we use another shift-loop here:
-while ($#argv > 0)
- echo '--> '\`$1:q\'
- shift
-end
+++ /dev/null
-#!/bin/bash
-if `getopt -T >/dev/null 2>&1` ; [ $? = 4 ] ; then
- echo "Enhanced getopt(1)"
-else
- echo "Old getopt(1)"
-fi
+++ /dev/null
-#!/bin/tcsh
-getopt -T >&/dev/null
-if ( $status == 4) then
- echo "Enhanced getopt(1)"
-else
- echo "Old getopt(1)"
-endif
+++ /dev/null
-.\" mcookie.1 --
-.\" Public Domain 1995 Rickard E. Faith (faith@cs.unc.edu)
-.TH MCOOKIE 1 "25 September 1995" "" "Linux Programmer's Manual"
-.SH NAME
-mcookie \- generate magic cookies for xauth
-.SH SYNOPSIS
-.BI "mcookie [\-v] [\-f " filename " ]"
-.SH DESCRIPTION
-.B mcookie
-generates a 128-bit random hexadecimal number for use with the X authority
-system. Typical usage:
-.RS
-xauth add :0 . `mcookie`
-.RE
-.PP
-The "random" number generated is actually the output of the MD5 message
-digest fed with various piece of random information: the current time, the
-process id, the parent process id, the contents of an input file (if
-.B \-f
-is specified), and several bytes of information from the first of the
-following devices which is present:
-.IR /dev/random ,
-.IR /dev/urandom ,
-files in
-.IR /proc ,
-.IR /dev/audio .
-.SH BUGS
-The entropy in the generated 128-bit is probably quite small (and,
-therefore, vulnerable to attack) unless a non-pseudorandom number generator
-is used (e.g.,
-.I /dev/random
-under Linux).
-.PP
-It is assumed that none of the devices opened will block.
-.SH FILES
-.I /dev/random
-.br
-.I /dev/urandom
-.br
-.I /dev/audio
-.br
-.I /proc/stat
-.br
-.I /proc/loadavg
-.SH "SEE ALSO"
-.BR X (1),
-.BR xauth (1),
-.BR md5sum (1)
+++ /dev/null
-/* mcookie.c -- Generates random numbers for xauth
- * Created: Fri Feb 3 10:42:48 1995 by faith@cs.unc.edu
- * Revised: Fri Mar 19 07:48:01 1999 by faith@acm.org
- * ORIGINAL LICENSE:
- * Public Domain 1995, 1999 Rickard E. Faith (faith@acm.org)
- * This program comes with ABSOLUTELY NO WARRANTY.
- * Revised 2002-07-12: Charles Wilson
- * modified to work on cygwin; integrated into cygutils package
- * Changes licensed under the GPL
- *
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-
-/* $Id$
- *
- * This program gathers some random bits of data and used the MD5
- * message-digest algorithm to generate a 128-bit hexadecimal number for
- * use with xauth(1).
- *
- * NOTE: Unless /dev/random is available, this program does not actually
- * gather 128 bits of random information, so the magic cookie generated
- * will be considerably easier to guess than one might expect.
- *
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- * - added Native Language Support
- * 1999-03-21 aeb: Added some fragments of code from Colin Plumb.
- * 2002-07-12 Charles Wilson <cwilson@ece.gatech.edu>
- * modified to work on cygwin; integrated into cygutils package
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* included by common.h *//*
-#ifdef __linux__
-#define HAVE_GETTIMEOFDAY 1
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-
-#include "md5.h"
-#if HAVE_GETTIMEOFDAY
-#include <sys/time.h>
-#include <unistd.h>
-#endif
-#endif
-*/
-
-#include "md5.h"
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#define BUFFERSIZE 4096
-
-struct rngs {
- const char *path;
- int minlength, maxlength;
-} rngs[] = {
- { "/dev/random", 16, 16 }, /* 16 bytes = 128 bits suffice */
- { "/proc/interrupts", 0, 0 },
- { "/proc/slabinfo", 0, 0 },
- { "/proc/stat", 0, 0 },
- { "/dev/urandom", 32, 64 },
-};
-#define RNGS (sizeof(rngs)/sizeof(struct rngs))
-
-int Verbose = 0;
-
-/* The basic function to hash a file */
-static off_t
-hash_file(struct MD5Context *ctx, int fd)
-{
- off_t count = 0;
- ssize_t r;
- unsigned char buf[BUFFERSIZE];
-
- while ((r = read(fd, buf, sizeof(buf))) > 0) {
- MD5Update(ctx, buf, r);
- count += r;
- }
- /* Separate files with a null byte */
- buf[0] = 0;
- MD5Update(ctx, buf, 1);
- return count;
-}
-
-int main( int argc, char **argv )
-{
- int i;
- struct MD5Context ctx;
- unsigned char digest[16];
- unsigned char buf[BUFFERSIZE];
- int fd;
- int c;
- pid_t pid;
- char *file = NULL;
- int r;
-#if HAVE_GETTIMEOFDAY
- struct timeval tv;
- struct timezone tz;
-#else
- long int t;
-#endif
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- while ((c = getopt( argc, argv, "vf:" )) != EOF)
- switch (c) {
- case 'v': ++Verbose; break;
- case 'f': file = optarg; break;
- }
-
- MD5Init( &ctx );
-
-#if HAVE_GETTIMEOFDAY
- gettimeofday( &tv, &tz );
- MD5Update( &ctx, (unsigned char *)&tv, sizeof( tv ) );
-#else
- time( &t );
- MD5Update( &ctx, (unsigned char *)&t, sizeof( t ) );
-#endif
- pid = getppid();
- MD5Update( &ctx, (unsigned char *)&pid, sizeof( pid ));
- pid = getpid();
- MD5Update( &ctx, (unsigned char *)&pid, sizeof( pid ));
-
- if (file) {
- int count = 0;
-
- if (file[0] == '-' && !file[1])
- fd = fileno(stdin);
- else
- fd = open( file, O_RDONLY );
-
- if (fd < 0) {
- fprintf( stderr, _("Could not open %s\n"), file );
- } else {
- count = hash_file( &ctx, fd );
- if (Verbose)
- fprintf( stderr, _("Got %d bytes from %s\n"), count, file );
-
- if (file[0] != '-' || file[1]) close( fd );
- }
- }
-
- for (i = 0; i < RNGS; i++) {
- if ((fd = open( rngs[i].path, O_RDONLY|O_NONBLOCK )) >= 0) {
- int count = sizeof(buf);
-
- if (rngs[i].maxlength && count > rngs[i].maxlength)
- count = rngs[i].maxlength;
- r = read( fd, buf, count );
- if (r > 0)
- MD5Update( &ctx, buf, r );
- else
- r = 0;
- close( fd );
- if (Verbose)
- fprintf( stderr, _("Got %d bytes from %s\n"), r, rngs[i].path );
- if (rngs[i].minlength && r >= rngs[i].minlength)
- break;
- } else if (Verbose)
- fprintf( stderr, _("Could not open %s\n"), rngs[i].path );
- }
-
- MD5Final( digest, &ctx );
- for (i = 0; i < 16; i++) printf( "%02x", digest[i] );
- putchar ( '\n' );
-
- /*
- * The following is important for cases like disk full, so shell scripts
- * can bomb out properly rather than think they succeeded.
- */
- if (fflush(stdout) < 0 || fclose(stdout) < 0)
- return 1;
-
- return 0;
-}
+++ /dev/null
-/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * ORIGINAL LICENSE:
- * This code is in the public domain; do with it what you wish.
- * Revised 2002-07-12: Charles Wilson
- * modified to work on cygwin; integrated into cygutils package
- * Changes licensed under the GPL
- *
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-
-/* Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
- * will fill a supplied 16-byte array with the digest.
- */
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* included by common.h *//*
-#include <string.h>
-*/
-#include "md5.h"
-
-#ifndef HIGHFIRST
-#define byteReverse(buf, len) /* Nothing */
-#else
-void byteReverse(unsigned char *buf, unsigned longs);
-
-#ifndef ASM_MD5
-/*
- * Note: this code is harmless on little-endian machines.
- */
-void byteReverse(unsigned char *buf, unsigned longs)
-{
- uint32 t;
- do {
- t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
- ((unsigned) buf[1] << 8 | buf[0]);
- *(uint32 *) buf = t;
- buf += 4;
- } while (--longs);
-}
-#endif
-#endif
-
-/*
- * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-void MD5Init(struct MD5Context *ctx)
-{
- ctx->buf[0] = 0x67452301;
- ctx->buf[1] = 0xefcdab89;
- ctx->buf[2] = 0x98badcfe;
- ctx->buf[3] = 0x10325476;
-
- ctx->bits[0] = 0;
- ctx->bits[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
-{
- uint32 t;
-
- /* Update bitcount */
-
- t = ctx->bits[0];
- if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
- ctx->bits[1]++; /* Carry from low to high */
- ctx->bits[1] += len >> 29;
-
- t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
-
- /* Handle any leading odd-sized chunks */
-
- if (t) {
- unsigned char *p = (unsigned char *) ctx->in + t;
-
- t = 64 - t;
- if (len < t) {
- memcpy(p, buf, len);
- return;
- }
- memcpy(p, buf, t);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
- buf += t;
- len -= t;
- }
- /* Process data in 64-byte chunks */
-
- while (len >= 64) {
- memcpy(ctx->in, buf, 64);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
- buf += 64;
- len -= 64;
- }
-
- /* Handle any remaining bytes of data. */
-
- memcpy(ctx->in, buf, len);
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
-{
- unsigned count;
- unsigned char *p;
-
- /* Compute number of bytes mod 64 */
- count = (ctx->bits[0] >> 3) & 0x3F;
-
- /* Set the first char of padding to 0x80. This is safe since there is
- always at least one byte free */
- p = ctx->in + count;
- *p++ = 0x80;
-
- /* Bytes of padding needed to make 64 bytes */
- count = 64 - 1 - count;
-
- /* Pad out to 56 mod 64 */
- if (count < 8) {
- /* Two lots of padding: Pad the first block to 64 bytes */
- memset(p, 0, count);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
-
- /* Now fill the next block with 56 bytes */
- memset(ctx->in, 0, 56);
- } else {
- /* Pad block to 56 bytes */
- memset(p, 0, count - 8);
- }
- byteReverse(ctx->in, 14);
-
- /* Append length in bits and transform */
- ((uint32 *) ctx->in)[14] = ctx->bits[0];
- ((uint32 *) ctx->in)[15] = ctx->bits[1];
-
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
- byteReverse((unsigned char *) ctx->buf, 4);
- memcpy(digest, ctx->buf, 16);
- memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
-}
-
-#ifndef ASM_MD5
-
-/* The four core functions - F1 is optimized somewhat */
-
-/* #define F1(x, y, z) (x & y | ~x & z) */
-#define F1(x, y, z) (z ^ (x & (y ^ z)))
-#define F2(x, y, z) F1(z, x, y)
-#define F3(x, y, z) (x ^ y ^ z)
-#define F4(x, y, z) (y ^ (x | ~z))
-
-/* This is the central step in the MD5 algorithm. */
-#define MD5STEP(f, w, x, y, z, data, s) \
- ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
-
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5Update blocks
- * the data and converts bytes into longwords for this routine.
- */
-void MD5Transform(uint32 buf[4], uint32 const in[16])
-{
- register uint32 a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
- MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
- MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
- MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
- MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
- MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
- MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
- MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
- MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
- MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
- MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
- MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
- MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
- MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
- MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
- MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
- MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
- MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
- MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
- MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
- MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
- MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
- MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
- MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
- MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
- MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
- MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
- MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
- MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
- MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
- MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
- MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
-
- MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
- MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
- MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
- MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
- MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
- MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
- MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
- MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
- MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
- MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
- MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
- MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
- MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
- MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
- MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
- MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
-
- MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
- MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
- MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
- MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
- MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
- MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
- MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
- MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
- MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
- MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
- MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
- MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
- MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
- MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
- MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
- MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
-
-#endif
-
+++ /dev/null
-/* ORIGINAL LICENSE:
- * This code is in the public domain; do with it what you wish.
- * Revised 2002-07-12: Charles Wilson
- * modified to work on cygwin; integrated into cygutils package
- * Changes licensed under the GPL
- *
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef MD5_H
-#define MD5_H
-
-#if defined (__alpha__) || defined (__ia64__)
-typedef unsigned int uint32;
-#else
-typedef unsigned long uint32;
-#endif
-
-struct MD5Context {
- uint32 buf[4];
- uint32 bits[2];
- unsigned char in[64];
-};
-
-void MD5Init(struct MD5Context *context);
-void MD5Update(struct MD5Context *context, unsigned char const *buf,
- unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
-void MD5Transform(uint32 buf[4], uint32 const in[16]);
-
-/*
- * This is needed to make RSAREF happy on some MS-DOS compilers.
- */
-typedef struct MD5Context MD5_CTX;
-
-#endif /* !MD5_H */
+++ /dev/null
-Tired of running into "Too many levels of symlinks" problems on
-your 4.2 BSD derivitive machine?
-
-We sure did... our NFS'ed network of lots of Suns, Vaxen and so forth
-made it impossible at times to trace down where a file REALLY lived.
-I mean ls -l is nice, but wouldn't you like to follow things like
-the namei routine in the kernel does?
-
-Well here it is.... the namei program. It follows things out until
-a terminal state is found.
-
-This program compiles and runs under:
-
- SunOS 4.0.1 (sun3's)
- SunOS 4.0.3 (sun4's)
- SunOS 4.1.1 (sun4's)
- Ultrix 3.1
- BSD 4.3
-
-and probably a host of other 4.2 derived systems (but probably not
-System V).
-
-Anyway, if anyone has any bugs (or enhancements), please send them to
-me in E-mail form.
-
-And, by the way, if you make LOTS of money off of this program, please
-don't tell me :-).
-
- -Roger (rogers@fangorn.wr.tek.com)
- UUCP: ...!uunet!tektronix!fangorn.wr.tek.com!rogers
- ARPA: <rogers%fangorn.wr.tek.com@RELAY.CS.NET>
+++ /dev/null
-
-** NAMEI has local modifications, do not delete source when cleaning up **
-
-"You're in a twisty maze of symbolic links, all different"
-
-namei - a utility to chase down a pathname and print details at each
-level, especialy when following symbolic links. Very useful for figuring
-out whats really going on in our large environment. Named after the routine
-in the kernel that does essentialy the same thing whenever anyone tries to
-find a file.
-
-Local modifications by Steve Tell include: changing the -m option to print
-the file mode in a readable fashion, like "ls -l" does, instead of in octal.
-
+++ /dev/null
-.\"
-.\" Version 1.4 of namei
-.\"
-.TH NAMEI 1 "Local"
-.SH NAME
-namei - follow a pathname until a terminal point is found
-.SH SYNOPSIS
-.B namei
-.I [-mx]
-.I pathname
-.I "[ pathname ... ]"
-.SH DESCRIPTION
-.I Namei
-uses its arguments as pathnames to any type
-of Unix file (symlinks, files, directories, and so forth).
-.I Namei
-then follows each pathname until a terminal
-point is found (a file, directory, char device, etc).
-If it finds a symbolic link, we show the link, and start
-following it, indenting the output to show the context.
-.PP
-This program is useful for finding a "too many levels of
-symbolic links" problems.
-.PP
-For each line output,
-.I namei
-outputs a the following characters to identify the file types found:
-.LP
-.nf
- f: = the pathname we are currently trying to resolve
- d = directory
- l = symbolic link (both the link and it's contents are output)
- s = socket
- b = block device
- c = character device
- - = regular file
- ? = an error of some kind
-.fi
-.PP
-.I Namei
-prints an informative message when
-the maximum number of symbolic links this system can have has been exceeded.
-.SH OPTIONS
-.TP 8
-.B -x
-Show mount point directories with a 'D', rather than a 'd'.
-.TP 8
-.B -m
-Show the mode bits of each file type in the style of ls(1),
-for example 'rwxr-xr-x'.
-.SH AUTHOR
-Roger Southwick (rogers@amadeus.wr.tek.com)
-.SH BUGS
-To be discovered.
-.SH CAVEATS
-.I Namei
-will follow an infinite loop of symbolic links forever. To escape, use
-SIGINT (usually ^C).
-.SH "SEE ALSO"
-ls(1), stat(1)
+++ /dev/null
-/**
- * namei
- * copyright 1990,... by Roger S. Southwick
- * Modifications by Steve Tell
- * Further mods Charles Wilson
- *
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-
-/*-------------------------------------------------------------
-
-The namei program
-
-By: Roger S. Southwick
-
-May 2, 1990
-
-
-Modifications by Steve Tell March 28, 1991
-
-usage: namei pathname [pathname ... ]
-
-This program reads it's arguments as pathnames to any type
-of Unix file (symlinks, files, directories, and so forth).
-The program then follows each pathname until a terminal
-point is found (a file, directory, char device, etc).
-If it finds a symbolic link, we show the link, and start
-following it, indenting the output to show the context.
-
-This program is useful for finding a "too many levels of
-symbolic links" problems.
-
-For each line output, the program puts a file type first:
-
- f: = the pathname we are currently trying to resolve
- d = directory
- D = directory that is a mount point
- l = symbolic link (both the link and it's contents are output)
- s = socket
- b = block device
- c = character device
- - = regular file
- ? = an error of some kind
-
-The program prints an informative messages when we exceed
-the maximum number of symbolic links this system can have.
-
-The program exits with a 1 status ONLY if it finds it cannot
-chdir to /, or if it encounters an unknown file type.
-
-1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
-- added Native Language Support
-
--------------------------------------------------------------*/
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "common.h"
-
-int main(int argc, char *argv[]);
-
-#ifndef PACKAGE
-#define PACKAGE "cygutils"
-#endif
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#define ERR strerror(errno),errno
-
-int symcount;
-int mflag = 0;
-int xflag = 0;
-
-#ifndef MAXSYMLINKS
-#define MAXSYMLINKS 256
-#endif
-
-static char *pperm(unsigned short);
-static void namei(char *, int);
-static void usage(void);
-
-int
-main(int argc, char **argv) {
- extern int optind;
- int c;
- char curdir[MAXPATHLEN];
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if(argc < 2)
- usage();
-
- while((c = getopt(argc, argv, "mx")) != EOF){
- switch(c){
- case 'm':
- mflag = !mflag;
- break;
-
- case 'x':
- xflag = !xflag;
- break;
-
- case '?':
- default:
- usage();
- }
- }
-
- if(getcwd(curdir, sizeof(curdir)) == NULL){
- (void)fprintf(stderr,
- _("namei: unable to get current directory - %s\n"),
- curdir);
- exit(1);
- }
-
-
- for(; optind < argc; optind++){
- (void)printf("f: %s\n", argv[optind]);
- symcount = 1;
- namei(argv[optind], 0);
-
- if(chdir(curdir) == -1){
- (void)fprintf(stderr,
- _("namei: unable to chdir to %s - %s (%d)\n"),
- curdir, ERR);
- exit(1);
- }
- }
- return 0;
-}
-
-static void
-usage(void) {
- (void)fprintf(stderr,_("usage: namei [-mx] pathname [pathname ...]\n"));
- exit(1);
-}
-
-#ifndef NODEV
-#define NODEV (dev_t)(-1)
-#endif
-
-static void
-namei(char *file, int lev) {
- char *cp;
- char buf[BUFSIZ], sym[BUFSIZ];
- struct stat stb;
- int i;
- dev_t lastdev = NODEV;
-
- /*
- * See if the file has a leading /, and if so cd to root
- */
-
- if(*file == '/'){
- while(*file == '/')
- file++;
-
- if(chdir("/") == -1){
- (void)fprintf(stderr,_("namei: could not chdir to root!\n"));
- exit(1);
- }
- for(i = 0; i < lev; i++)
- (void)printf(" ");
-
- if(stat("/", &stb) == -1){
- (void)fprintf(stderr, _("namei: could not stat root!\n"));
- exit(1);
- }
- lastdev = stb.st_dev;
-
- if(mflag)
- (void)printf(" d%s /\n", pperm(stb.st_mode));
- else
- (void)printf(" d /\n");
- }
-
- for(;;){
-
- if (strlen(file) >= BUFSIZ) {
- fprintf(stderr,_("namei: buf overflow\n"));
- return;
- }
-
- /*
- * Copy up to the next / (or nil) into buf
- */
-
- for(cp = buf; *file != '\0' && *file != '/'; cp++, file++)
- *cp = *file;
-
- while(*file == '/') /* eat extra /'s */
- file++;
-
- *cp = '\0';
-
- if(buf[0] == '\0'){
-
- /*
- * Buf is empty, so therefore we are done
- * with this level of file
- */
-
- return;
- }
-
- for(i = 0; i < lev; i++)
- (void)printf(" ");
-
- /*
- * See what type of critter this file is
- */
-
- if(lstat(buf, &stb) == -1){
- (void)printf(" ? %s - %s (%d)\n", buf, ERR);
- return;
- }
-
- switch(stb.st_mode & S_IFMT){
- case S_IFDIR:
-
- /*
- * File is a directory, chdir to it
- */
-
- if(chdir(buf) == -1){
- (void)printf(_(" ? could not chdir into %s - %s (%d)\n"), buf, ERR );
- return;
- }
- if(xflag && lastdev != stb.st_dev && lastdev != NODEV){
- /* Across mnt point */
- if(mflag)
- (void)printf(" D%s %s\n", pperm(stb.st_mode), buf);
- else
- (void)printf(" D %s\n", buf);
- }
- else {
- if(mflag)
- (void)printf(" d%s %s\n", pperm(stb.st_mode), buf);
- else
- (void)printf(" d %s\n", buf);
- }
- lastdev = stb.st_dev;
-
- (void)fflush(stdout);
- break;
-
- case S_IFLNK:
- /*
- * Sigh, another symlink. Read its contents and
- * call namei()
- */
-
- bzero(sym, BUFSIZ);
- if(readlink(buf, sym, BUFSIZ) == -1){
- (void)printf(_(" ? problems reading symlink %s - %s (%d)\n"), buf, ERR);
- return;
- }
-
- if(mflag)
- (void)printf(" l%s %s -> %s", pperm(stb.st_mode), buf, sym);
- else
- (void)printf(" l %s -> %s", buf, sym);
-
- if(symcount > 0 && symcount++ > MAXSYMLINKS){
- (void)printf(_(" *** EXCEEDED UNIX LIMIT OF SYMLINKS ***\n"));
- symcount = -1;
- } else {
- (void)printf("\n");
- namei(sym, lev + 1);
- }
- break;
-
- case S_IFCHR:
- if(mflag)
- (void)printf(" c%s %s\n", pperm(stb.st_mode), buf);
- else
- (void)printf(" c %s\n", buf);
- break;
-
- case S_IFBLK:
- if(mflag)
- (void)printf(" b%s %s\n", pperm(stb.st_mode), buf);
- else
- (void)printf(" b %s\n", buf);
- break;
-
- case S_IFSOCK:
- if(mflag)
- (void)printf(" s%s %s\n", pperm(stb.st_mode), buf);
- else
- (void)printf(" s %s\n", buf);
- break;
-
- case S_IFREG:
- if(mflag)
- (void)printf(" -%s %s\n", pperm(stb.st_mode), buf);
- else
- (void)printf(" - %s\n", buf);
- break;
-
- default:
- (void)fprintf(stderr,_("namei: unknown file type 0%06o on file %s\n"), stb.st_mode, buf );
- exit(1);
-
- }
- }
-}
-
-/* Take a
- * Mode word, as from a struct stat, and return
- * a pointer to a static string containing a printable version like ls.
- * For example 0755 produces "rwxr-xr-x"
- */
-static char *
-pperm(unsigned short mode) {
- unsigned short m;
- static char buf[16];
- char *bp;
- char *lschars = "xwrxwrxwr"; /* the complete string backwards */
- char *cp;
- int i;
-
- for(i = 0, cp = lschars, m = mode, bp = &buf[8];
- i < 9;
- i++, cp++, m >>= 1, bp--) {
-
- if(m & 1)
- *bp = *cp;
- else
- *bp = '-';
- }
- buf[9] = '\0';
-
- if(mode & S_ISUID) {
- if(buf[2] == 'x')
- buf[2] = 's';
- else
- buf[2] = 'S';
- }
- if(mode & S_ISGID) {
- if(buf[5] == 'x')
- buf[5] = 's';
- else
- buf[5] = 'S';
- }
- if(mode & S_ISVTX) {
- if(buf[8] == 'x')
- buf[8] = 't';
- else
- buf[8] = 'T';
- }
-
- return &buf[0];
-}
-
-
+++ /dev/null
-int main(int argc, char *argv[]);
-
-#ifndef PACKAGE
-#define PACKAGE "util-linux"
-#endif
-
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_locale_h
-# include <locale.h>
-#endif
-
-#if defined MAY_ENABLE_NLS && !defined DISABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-
+++ /dev/null
-.\" Written by Andries E. Brouwer (aeb@cwi.nl)
-.\" Placed in the public domain
-.\"
-.TH RENAME 1 "1 January 2000" "" "Linux Programmer's Manual"
-.SH NAME
-rename \- Rename files
-.SH SYNOPSIS
-.BI rename " from to file..."
-.SH DESCRIPTION
-.B rename
-will rename the specified files by replacing the first occurrence of
-.I from
-in their name by
-.IR to .
-
-For example, given the files
-.IR foo1 ", ..., " foo9 ", " foo10 ", ..., " foo278 ,
-the commands
-
-.RS
-.nf
-rename foo foo0 foo?
-rename foo foo0 foo??
-.fi
-.RE
-
-will turn them into
-.IR foo001 ", ..., " foo009 ", " foo010 ", ..., " foo278 .
-
-And
-.RS
-.nf
-rename .htm .html *.htm
-.fi
-.RE
-
-will fix the extension of your html files.
-
-.SH "SEE ALSO"
-.BR mv (1)
+++ /dev/null
-/*
- * rename.c - aeb 2000-01-01
- *
---------------------------------------------------------------
-#!/bin/sh
-if [ $# -le 2 ]; then echo call: rename from to files; exit; fi
-FROM="$1"
-TO="$2"
-shift
-shift
-for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done
---------------------------------------------------------------
- * This shell script will do renames of files, but may fail
- * in cases involving special characters. Here a C version.
- */
-#ifndef HAVE_locale_h
-#define HAVE_locale_h
-#endif
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "nls.h"
-
-#ifndef util_linux_version
-#define util_linux_version "util-linux-2.11y"
-#endif
-
-static char *progname;
-
-static int
-do_rename(char *from, char *to, char *s) {
- char *newname, *where, *p, *q;
- int flen, tlen, slen;
-
- where = strstr(s, from);
- if (where == NULL)
- return 0;
-
- flen = strlen(from);
- tlen = strlen(to);
- slen = strlen(s);
- newname = malloc(tlen+slen+1);
- if (newname == NULL) {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
-
- p = s;
- q = newname;
- while (p < where)
- *q++ = *p++;
- p = to;
- while (*p)
- *q++ = *p++;
- p = where+flen;
- while (*p)
- *q++ = *p++;
- *q = 0;
-
- if (rename(s, newname) != 0) {
- int errsv = errno;
- fprintf(stderr, _("%s: renaming %s to %s failed: %s\n"),
- progname, s, newname, strerror(errsv));
- exit(1);
- }
-
- return 1;
-}
-
-int
-main(int argc, char **argv) {
- char *from, *to, *p;
- int i, ct;
-
- progname = argv[0];
- if ((p = strrchr(progname, '/')) != NULL)
- progname = p+1;
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (argc == 2) {
- if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
- printf(_("%s from %s\n"),
- progname, util_linux_version);
- return 0;
- }
- }
-
- if (argc < 3) {
- fprintf(stderr, _("call: %s from to files...\n"), progname);
- exit(1);
- }
-
- from = argv[1];
- to = argv[2];
-
- ct = 0;
- for (i=3; i<argc; i++)
- ct += do_rename(from, to, argv[i]);
- return 0;
-}
+++ /dev/null
-.\" Copyright (c) 1985, 1992 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" from: @(#)rev.1 6.3 (Berkeley) 3/21/92
-.\" Modified for Linux by Charles Hannum (mycroft@gnu.ai.mit.edu)
-.\" and Brian Koehmstedt (bpk@gnu.ai.mit.edu)
-.\" $Id$
-.\"
-.Dd March 21, 1992
-.Dt REV 1
-.Os
-.Sh NAME
-.Nm rev
-.Nd reverse lines of a file
-.Sh SYNOPSIS
-.Nm rev
-.Op Ar file
-.Sh DESCRIPTION
-The
-.Nm rev
-utility copies the specified files to the standard output, reversing the
-order of characters in every line.
-If no files are specified, the standard input is read.
+++ /dev/null
-/*-
- * Copyright (c) 1987, 1992 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Modified for Linux by Charles Hannum (mycroft@gnu.ai.mit.edu)
- * and Brian Koehmstedt (bpk@gnu.ai.mit.edu)
- *
- * Wed Sep 14 22:26:00 1994: Patch from bjdouma <bjdouma@xs4all.nl> to handle
- * last line that has no newline correctly.
- * 3-Jun-1998: Patched by Nicolai Langfeldt to work better on Linux:
- * Handle any-length-lines. Code copied from util-linux' setpwnam.c
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- * added Native Language Support
- * 1999-09-19 Bruno Haible <haible@clisp.cons.org>
- * modified to work correctly in multi-byte locales
- * 2002-07-12 Charles Wilson <cwilson@ece.gatech.edu>
- * modified to work on cygwin; integrated into cygutils package
- *
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "common.h"
-
-/* included by common.h *//*
-#include <stdarg.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-*/
-#ifndef LOCALEDIR
-#define LOCALEDIR "/usr/share/locale"
-#endif
-
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#if !HAVE_SETLOCALE
-# undef setlocale(a, b)
-# define setlocale(a, b) /* empty */
-#endif
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-# ifdef gettext_noop
-# define N_(String) gettext_noop (String)
-# else
-# define N_(String) (String)
-# endif
-#else
-# undef bindtextdomain
-# define bindtextdomain(Domain, Directory) /* empty */
-# undef textdomain
-# define textdomain(Domain) /* empty */
-# define _(Text) (Text)
-# define N_(Text) (Text)
-#endif
-
-#include "widechar.h"
-
-void usage(void);
-void warn(const char *, ...);
-
-int
-main(int argc, char *argv[])
-{
- register char *filename;
- register wchar_t *t;
- size_t buflen = 512;
- wchar_t *p = malloc(buflen*sizeof(wchar_t));
- size_t len;
- FILE *fp;
- int ch, rval;
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- while ((ch = getopt(argc, argv, "")) != EOF)
- switch(ch) {
- case '?':
- default:
- usage();
- }
-
- argc -= optind;
- argv += optind;
-
- fp = stdin;
- filename = "stdin";
- rval = 0;
- do {
- if (*argv) {
- if ((fp = fopen(*argv, "r")) == NULL) {
- warn("%s: %s", *argv, strerror(errno));
- rval = 1;
- ++argv;
- continue;
- }
- filename = *argv++;
- }
-
- while (fgetws(p, buflen, fp)) {
-
- len = wcslen(p);
-
- /* This is my hack from setpwnam.c -janl */
- while (p[len-1] != '\n' && !feof(fp)) {
- /* Extend input buffer if it failed getting the whole line */
-
- /* So now we double the buffer size */
- buflen *= 2;
-
- p = realloc(p, buflen*sizeof(wchar_t));
- if (p == NULL) {
- fprintf(stderr,_("Unable to allocate bufferspace\n"));
- exit(1);
- }
-
- /* And fill the rest of the buffer */
- if (fgetws(&p[len], buflen/2, fp) == NULL) break;
-
- len = wcslen(p);
-
- /* That was a lot of work for nothing. Gimme perl! */
- }
-
- t = p + len - 1 - (*(p+len-1)=='\r' || *(p+len-1)=='\n');
- for ( ; t >= p; --t)
- if (*t != 0)
- putwchar(*t);
- putwchar('\n');
- }
- fflush(fp);
- if (ferror(fp)) {
- warn("%s: %s", filename, strerror(errno));
- rval = 1;
- }
- if (fclose(fp))
- rval = 1;
- } while(*argv);
- exit(rval);
-}
-
-void
-warn(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- (void)fprintf(stderr, "rev: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
-}
-
-void
-usage(void)
-{
- (void)fprintf(stderr, _("usage: rev [file ...]\n"));
- exit(1);
-}
+++ /dev/null
-/*
- * 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 2
- * of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the COPYING file for license information.
- */
-#ifndef WIDECHAR_H
-#define WIDECHAR_H
-/* Declarations for wide characters */
-/* This file must be included last because the redefinition of wchar_t may
- cause conflicts when system include files were included after it. */
-#if HAVE_CONFIG_H
-# include "config.h" /* for ENABLE_WIDECHAR */
-#endif
-/* don't include "common.h" here */
-
-#ifdef ENABLE_WIDECHAR
-
-# include <wchar.h>
-# include <wctype.h>
-#if 0 /* for testing on platforms without built-in wide character support */
-# include <libutf8.h>
-#endif
-
-#if 1
-/* explicit prototypes, since sometimes <wchar.h> does not give them */
-extern int wcwidth (wint_t c);
-extern int wcswidth (const wchar_t *s, size_t n);
-extern size_t wcslen (const wchar_t *s);
-extern wchar_t *wcsdup (const wchar_t *s);
-#endif
-
-#else
-
-# include <ctype.h>
- /* Fallback for types */
-# define wchar_t char
-# define wint_t int
-# define WEOF EOF
- /* Fallback for input operations */
-# define fgetwc fgetc
-# define getwc getc
-# define getwchar getchar
-# define fgetws fgets
- /* Fallback for output operations */
-# define fputwc fputc
-# define putwc putc
-# define putwchar putchar
-# define fputws fputs
- /* Fallback for character classification */
-# define iswgraph isgraph
-# define iswprint isprint
-# define iswspace isspace
- /* Fallback for string functions */
-# define wcschr strchr
-# define wcsdup strdup
-# define wcslen strlen
-
-# define wcwidth(c) 1
-
-#endif
-#endif