home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
310.lha
/
ColumnSet
/
column_set.doc
< prev
next >
Wrap
Text File
|
1980-12-10
|
6KB
|
115 lines
Documentation for Modula-2 program column_set, by Kent Paul Dolan.
The purpose of column _set is to act as a text filter, accepting a file
with one "word" per line (the original was the output of the AmigaDOS
command 'list lformat="%S"', after being sorted) as input, and producing a
file with these "words" layed out in the same order in even columns, as
many as will fit across the output screen or page with at least one space
between columns.
The default input is the standard input, the default output is the standard
output, the default output file line width is 77 character positions to
match the AmigaShell window default width, and the default maximum allowed
number of "words" or layout columns per line (maxcol) is (width+1)/2 to
allow for laying out single character "words" with one space after all but
the last one on a line.
Optionally, command line parameters or redirection can name the input and
output files, and command line parameters can modify the width and maxcol
parameters. The parameters are positional, in order: infile, outfile, width,
maxcol, with missing parameters defaulted, but AmigaDOS style keywords can
override the positional nature of the parameters, and optionally Unix style
"-flag" type keywords can do the same. Also, the command line is scanned
twice, first to pull off keywords and their associated parameters, then to
pull off missing positional parameters in order from any left over command
line tokens, so some grotesque mixes of parameter styles work as hoped.
Except for errors writing output files, which sadly are not checked for in
Modula-2's standard i/o module, "all" identified error conditions are
caught and reported to the user.
Doing the column layout requires two passes over the input data, one to
find the largest "word" in the input, which allows column number and
spacing to be calculated, and one to copy the "words" to the output. Since
standard input may come from the keyboard, and so be unrewindable, in the
case that input is from standard input, a copy of the input is written to a
temporary file in "T:column_set.temp" for use in the second pass, then
deleted when the filter is ready to exit. (On a Unix system, this should be
changed in the source code to "/tmp/column_set.temp", but I cannot do it on
my Amiga because I don't have a conditional compilation prepass available.)
Program usage may be seen by typing in "column_set ?", and is reported when
a command line error is detected as well. Without going into all the
possibilities of defaults, of mixing positional with keyword parameters,
and of mixing Unix with AmigaDOS keywords; the usage, completely default,
redirected, positional, AmigaDOS keyword, and Unix keyword formats,
respectively, look like this, where "infile" and "outfile" are file path
names, "ww" and "mm" are integers, and the spaces between keyword tokens
and parameter tokens are mandatory:
column_set ?
column_set
column_set < infile > outfile [{WIDTH | -w} ww] [{MAXCOL | -m} mm]
column_set infile outfile ww mm
column_set FROM infile TO outfile WIDTH ww MAXCOL mm
column_set -i infile -o outfile -w ww -m mm
while, just for example, this will also work:
column_set MaXCoL mm -o outfile widTH ww infile
which is arrant nonsense, but did keep me up until dawn finding ways it
wouldn't work and fixing them.
As expected, the program doesn't see the redirection commands in the
version of the command line passed to it in the environment, so if you
redirect anything, keyword all the other parameters (really, the
functionality is less strict than that, but that is surely safe), or you
might get positional parameter tokens attached to the wrong parameters.
When the command line handling and file handling code are stripped away,
the remaining algorithm is simplicity itself: on the first pass through the
input data, find the length of the longest input "word"; when done with the
first pass, determine how many such words will fit on a line with at least
one space between words, and how many spaces can be put between that many
words without overflowing the line; on the second pass, copy words from
input to output, following each but the last on each line with that number
of spaces, and the last on each line with a newline, until all the words
are copied. A special case puts a newline rather than spaces after the
last word of the input, if it would not normally be the last word on a
line.
The program is copyrighted, but this is no big deal; steal what you want,
just spell my name right in the credits, and don't take a profit on the
whole thing (snips and snatches are OK) without cutting me in on the swag.
Thanks!
Oh, yeah, to be fair, AmigaDOS, Amiga, and probably AmigaShell are trademarks
belonging to Commodore, while Unix belongs to AT&T.
Kent Paul Dolan, 26 October 1989, Mountain View, California.
Example of use:
From the commands run in the Amiga directory where this code was developed
list > t:junk1 lformat="%S"
sort t:junk1 t:junk2
column_set < t:junk2 > t:junk3
at the end, t:junk3 looked like this:
column_set column_set.doc column_set.MOD
column_set.OBM column_set.RFM column_set.uu
column_set2.MOD column_set3.MOD jvert
mycopy1.MOD mycopy2.MOD mycopy3.MOD
ScheduleBasics.DEF ScheduleBasics.MOD SchedulePerson.DEF
SchedulePerson.MOD ScheduleTask.DEF ScheduleTask.MOD
Schedule_V0.01.MOD TimeSliceHandler.DEF TimeSliceHandler.MOD
tvert
which allows a directory half again as long to fit on a single screen, by
laying it out in three columns instead of two. Of such small increments is
happiness constructed. Kent.