[comp.sources.misc] v06i087: mti, travel itinerary macros for *roff, version 2.0

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (04/24/89)

Posting-number: Volume 6, Issue 87
Submitted-by: jdpeek@rodan.acs.syr.edu (Jerry Peek)
Archive-name: mti.roff

[Apologies for disappearing, folks -- shock brought on by the phone bill.
;-) :-(  I'll try to get stuff out on a weekly basis from now on; perhaps
I'll be able to make other arrangements later.  But long-distance phone
calls to Virginia aren't cheap -- not on a daily basis.  ++bsa]

If you're planning a road trip, these macros for {n,t,di,etc}roff can
help.  You plug in the timepoints, distance between the timepoints,
your gas/oil costs per mile/km, and any other expenses (like food).
They print a formatted itinerary, including daily and grand totals of the
distance travelled and your expenses.  They're real nice for long trips
because it's easy to scope out an itinerary, let *roff calculate the
costs and distances, then rearrange things if you need to.
Plus, you get a nice itinerary printout to give friends/boss/parents.

I released the first version of these a few years ago.  This shar file
includes a man page with examples and a short sample itinerary for you
to format.  The shar file has a "tr" command in it, so if you're not
using a UNIX-like shell to un-shar it, see README.mti for help.
Enjoy, happy travels, etc.  Let me know how you like these.

--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
  jdpeek@rodan.acs.syr.edu, jdpeek@suvm.bitnet
  +1 315 443-3995

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by rodan.acs.syr.edu!jdpeek on Thu Apr  6 22:17:30 EDT 1989
# Contents:  README.mti mti.7 sample.mti tmac.ti
 
echo extracting - README.mti
sed 's/^X//' > "README.mti" <<'X//E*O*F README.mti//'
XThe -mti macros make formatted travel itineraries.  This is version 2.0.
XI released an earlier version a few years ago.  This one has more
Xerror-checking and some bug fixes.
X
XThis shar file has:
X	tmac.ti		The *roff formatter macro package
X	mti.7		The manual page source for tmac.ti
X	sample.mti	Sample itinerary source file
X	README.mti	This file
X
XNOTE: The real tmac.ti file has some control-G characters in it.  But,
Xsome mail/news handlers strip out these control characters.  So, in
Xthis shar file, they're packed as capital Z characters.  A "tr" command
Xtranslates the Z's back to ^G's.  If you don't have "tr", use an editor
Xto change each Z into ^G (or any non-text character).
X
XThe sample.mti file is an itinerary I made up to show what a source
Xfile might look like.  I use one like it as a template; when I want a
Xnew itinerary, I just plug in the new starting day/date and change the
Xentries.  The comments in the file make it so easy that I never look at
Xthe man page.
X
XYou might start by un-sharing these files and formatting the man page:
X	Xroff -man mti.7 > somefile
X(If you need a formatted copy of the man page, let me know.)
X
XNext, try feeding the sample.mti file to your version of *roff.
XIf you put tmac.ti in your /usr/lib/tmac directory, you can do:
X	Xroff -mti sample.mti > itinerary
XOr, you can feed the macro file to *roff directly:
X	Xroff tmac.ti sample.mti > itinerary
X
XThen look at the output "itinerary" file.  It should have a title page
Xand two more pages.  The last day's entry should start:
X	DAY #5 OF TRIP: Monday, 5/22
Xand end:
X	TODAY: travel 473 miles in 13 hours for $15; other costs $8; total $23
X	TO DATE: 1331 miles, $215
Xif not, your formatter might have some math troubles.
X
XFinally, compare the itinerary to the sample output in the manual
Xpage.  If they have the same format, you're probably all set.  If you
Xhave trouble -- or, if you find bugs and fix them -- PLEASE tell me.
X
XBy the way, do whatever you want with these macros.  If you
Xredistribute them or edit them, please give me credit.  If you sell
Xthem, I wouldn't mind a share of the proceeds. :-)
X
X				Jerry Peek, Syracuse University
X				jdpeek@rodan.acs.syr.edu, jdpeek@suvm.bitnet
X//E*O*F README.mti//
chmod u=rw,g=r,o=r README.mti
 
echo extracting - mti.7
sed 's/^X//' > "mti.7" <<'X//E*O*F mti.7//'
X.de xX	\" automatic revision-date macro
X.ds Da \\$4
X..
X.xX $Header: /u3/acs/jdpeek/.man/man7/mti.7,v 2.0 89/04/06 20:55:47 jdpeek Exp $
X.\"
X.TH MTI 7 "\*(Da"
X.UC 4
X.SH NAME
Xmti \- travel-itinerary formatting macros
X.SH SYNOPSIS
X\fBnroff  \-mti\fP  [ \-rQ2 ]  [ options ]  file  ...
X.br
X\fBtroff  \-mti\fP  [ \-rQ2 ]  [ options ]  file  ...
X.SH DESCRIPTION
XThis package of \fInroff\fP\| and \fItroff\fP\|
Xmacro definitions makes formatted travel itineraries.
XThey're especially designed for road trips \(em 
Xthrough they'll work for other kinds of travel, too.
X.PP
XYou give them the starting date, the time and mileage points you'll
Xhit each day, and each food/lodging expense you plan.
X(You also need to store the cost of travelling \(em usually fuel economy,
Xwith other fixed traveling expenses optional).
XThey'll output an itinerary that lists each timepoint and expense,
Xas well as daily and running totals of cost and distance.
X.SH EXAMPLE
XHere's a small part of a finished (fictional) itinerary, with `. . .' in place
Xof the omitted lines:
X.nf
X'\" kludges to make .tl titles line up with current margins:
X.lt -0.5i
X.po +0.5i
X.ft B
X	  .
X	  .
X.tl'ITINERARY'Page 6'CROSS-COUNTRY MOVE'
X	  .
X	  .
X.in -0.5i
X6 PM  Camp near Dustbowl, NM
XLODGING: Camping fee  $8.
X
XTODAY: 415 mi. in 9 hours for $18; other costs $8; total $26
XTO DATE: 1690 miles, $77
X\l'6i'
XDAY #7 OF TRIP: Friday, 6/21
X.in
X
X.tl '7 AM  NM-18, US-87 to Dalhart, TX''129 mi'
X.tl '9 AM  Time-zone change from MDT to CDT'''
X.tl '10 AM  TX-297, TX-281, US-22, US-83 to Canadian, TX''135 mi'
X.tl 'FOOD: Lunch in Canadian?  $6.'''
X.tl '1 PM  US-83, OK-54, I-40 to Oklahoma City''140 mi'
X.in -0.5i
X4 PM  Arrive at Fred Smith's home
X
XTODAY: 404 mi. in 8 hours for $17; other costs $6; total $23
XTO DATE: 2094 miles, $100
X\l'6i'
XDAY #8 OF TRIP: Saturday, 6/22
X	  .
X	  .
X'\" if this line crosses a page boundary, page footer/header will be indented!
X.ft P
X.in
X.lt +0.5i
X.po -0.5i
X.fi
X.ad
X.PP
XThe source (unformatted) itinerary commands are flexible enough that it's easy
Xto rearrange your itinerary, try alternate routes, etc... after you've set up
Xan itinerary, the macros will calculate the total trip length and expenses.
X.PP
XFor example, here are the lines that produced the itinerary above.
XStart each day with \fI.SD\fR, use \fI.EN\fR for each entry, and
Xuse \fI.ED\fR at the end of each day.
XLodging expenses are marked with \fI.LO\fR, and \fI.FO\fR is for food:
X.nf
X.na
X.ft B
X.sp
X  .EN 6 PM "Camp near Dustbowl, NM"
X  .LO "Camping fee" 8
X  .ED 9
X  .SD
X  .EN 7 AM "NM-18, US-87 to Dalhart, TX" 129
X  .EN 9 AM "Time-zone change from MDT to CDT" 0
X  .EN 10 AM "TX-297, TX-281, US-22, US-83 to Canadian, TX" 135
X  .FO "Lunch in Canadian?" 6
X  .EN 1 PM "US-83, OK-54, I-40 to Oklahoma City" 140
X  .EN 4 PM "Arrive at Fred Smith's home" 0
X  .ED 8
X  .SD
X.ft P
X.fi
X.ad
X.sp
XThe argument to ED is the number of hours spent traveling that day.
XThe last argument to EN is the number of miles driven since the previous
Xtimepoint.
X.PP
XAll the \fI\-mti\fR macros are defined below.
XIt's okay to use most \fInroff\fP\| and \fItroff\fP\| requests
Xwith this package.
XHowever, watch out for fill- and non-fill modes, because
Xthe macros switch back and forth between the two modes.
XSee the individual macro descriptions below.
XAlso, be careful about setting number and string registers:
Xthe macros use a few of them (see the list below).
X.PP
XFont and point size changes with \ef and \es are also allowed;
Xfor example, ``\efIword\efR'' will italicize \fIword.\fP
X.SH OPTION
XIf you use \fI\-rQ2\fR on the command line, the macros won't print the
X\fBTODAY:\fR and \fBTO DATE:\fR summaries at the end of each day.
XOther command-line options go directly to \fInroff\fR or \fItroff\fR.
X.SH REGISTERS AND MACROS
XHere's a summary of the number and string registers \(em and the macros \(em
Xthat make up the
X.I \-mti
Xmacros.
XAfter the summary are detailed explanations and examples of each.
XSo, beginners can safely skip this reference section for now.
XThis list doesn't include internal macros and registers.
X.if n .in 0
X.tr _.
X.ta \w'Regist.Nam'u +\w'InitialVal'u +\w'String/ 'u
X.sp
X.ne 2
X.nf
XRegist.	Initial	String/	\0 Explanation
XName	Value	Number
X.sp .3
XCS	$	str	currency-unit symbol
XDT	\-	num	numerical date of trip start
XDU	\-	num	distance per currency unit
XDY	\-	str	name of day when trip starts
XFD	\-	num	number of days in February
XMN	\_	num	numerical month of trip start
XTI	\_	str	title for top corner each page
XUL	miles	str	distance unit name, long
XUS	mi	str	distance unit name, short
X.sp 2
X.ta \w'MacroNam'u +\w'NumberAr'u +\w'ReqdOptl 'u
X.sp .3
XMacro	Number	Req'd/	\0 Explanation
XName	Args.	Opt'nl
X.sp .3
X_ED	1	reqd	end of day
X_EN	4	reqd	timepoint entry
X_ET	0	reqd	end of title page
X_FO	2	optl	food expense
X_LO	2	optl	lodging expense
X_OE	2	optl	other expenses
X_SD	0	reqd	start of daily entry
X_ST	2	reqd	start of title block
X.fi
X.SH "SOURCE-FILE DESCRIPTION"
XThis part of the manual describes what you should put in a
Xsource (unformatted) itinerary file.
X.sp 2
XThe \fBFIRST SECTION\fR of each file stores numbers and strings (words) that
Xset the initial conditions (starting date, fuel economy, etc.).
XYou can put these first few lines in any order, as long as they're all at
Xthe top of the file.
XIndividual descriptions:
X.TP 12
X.B \&.ds DY Day
X.I Required:
Xday of the week that trip starts.
XFirst letter of day must be capitalized, rest lower-case.
XNo abbreviations.
XExample:
X.br
X	\fB.ds DY Saturday\fR
X.TP 12
X.B \&.nr DT Date
X.I Required:
Xnumerical date when the trip starts.
XFor example, if the trip started on August 15th:
X.br
X	\fB.nr DT 15\fR
X.TP 12
X.B \&.nr MN Month\fR
X.I Required:
Xnumerical month that the trip starts (January = 1, February = 2, etc.).
XExample:
X.br
X	\fB.nr MN 8\fR
X.TP 12
X.B \&.nr DU xx
X.I Required:
XDistance you can travel for each currency-unit you spend (in the U.S.,
Xnumber of miles that cost one dollar; in France, kilometres you can travel for
Xone Franc; etc.).
XThis rather weird number was designed to get around a problem:
X.I nroff
Xand
X.I troff
Xcan't do decimal arithmetic -- only integers.
XHere are two examples that should clear things up:
X.sp
XOn your trip across the U.S., you guess that you'll get 30 miles/gallon,
Xand that gas will cost $1.25 per gallon.
XSo, the miles per dollar are:
X.ft B
X.nf
X.na
X.sp
X	    30 miles/gallon
X	-----------------------\0=\024\0miles/dollar
X	  1.25 dollars/gallon
X.ad
X.fi
X.ft P
X.sp
X\&...which means that you'd put this line in your source file:
X.br
X	\fB.nr DU 24\fR
X.sp
XOr, if you were driving across Europe, getting 17 kilometres/litre and
Xspending DKK 6- per litre, the setting of \fBDU\fP should be 17 divided by 6,
Xor about 3 kilometres per DKK.
XSo, you'd put this line in your itinerary:
X.br
X	\fB.nr DU 3\fR
X.TP 12
X.B \&.nr FD 2x
X.I Required:
XNumber of days in February \(em 28 or 29.
XTells program whether this is a leap year.
XMust be set, even if your itinerary doesn't include February.
XFor example, if there are 28 days in February during the year of your trip (a
Xnon-leap year):
X.br
X	\fB.nr FD 28\fR
X.sp
XIf your trip crosses two years but only one February, set FD for the 
Xnumber of days in the February when you'll be traveling.
X.TP 12
X.B \&.ds TI TITLE
X.I Optional:
Xtitle for upper right-hand corner of each page.
XIf you don't define it, it'll be blank.
XHere's how you could define it:
X.br
X	\fB.ds TI CROSS-COUNTRY TRIP\fR
X.TP 12
X.B \&.ds CS xxx
X.I Optional:
Xcurrency symbol (default = \fB$\fR).
XCan be set to other currency names, like \fISKR\fR, this way:
X.br
X	\fB.ds CR SKR\fR
X.sp
XThis is used in the \fBTODAY:\fR and \fBTO DATE:\fR lines printed at the end
Xof each day.
X.sp
XNormally, the currency symbol and the cost are printed touching each other,
Xlike \fB$123\fR or \fBhfl162\fR (Dutch Guilder).
XIf you want space after the currency symbol (like \fBhfl\ 162\fR),
Xuse a backslash and a trailing blank when you define the currency symbol.
XFor example,
X.br
X	\fB.ds CR hfl\e\ \fR
X.br
XJust be sure to put the blank after the backslash!
X.TP 12
X.B \&.ds US units
X.I Optional:
Xthe units of distance, short name.
XThe default is \fImi\fR (miles).
XTo change it to, say, \fIkm\fR:
X.br
X	\fB.ds US km\fR
X.TP 12
X.B \&.ds UL units
X.I Optional:
Xthe units of distance, long name, plural.
XThe default is \fImiles\fR.
XTo change it to, say, \fIkilometers\fR:
X.br
X	\fB.ds UL kilometers\fR
X.PP
X.sp
XThe \fBTITLE SECTION\fR is usually short.
XIt starts with the \fI.ST\fR macro, and ends with \fI.ET\fR.
XIf you want other text on the title page, you can put it between the macro
Xcalls.
X.TP 12
X\fB\&.ST\0"First line"\0"Second line"\fR
X.I Required:
Xafter you've set the number and string registers in the first section,
Xyou must use \fI.ST\fR (start title page).
XIf you want a title on the first page, it can have one or two lines...
Xthe macros will make it in larger type and center each line.
X.sp
XQuote each line of the title, and put the text on the same line as
Xthe \fI.ST\fR call.
XIf you don't want one or both lines, just leave them out.
XExample:
X.br
X	\fB.ST\0"Our trip"\0"to Lower Slobovia"\fR
X.sp
XAfter the \fI.ST\fP, you can put text for the title page.
XYou'll usually want to skip down a few lines (say, \fB.sp 5\fR)
Xbefore starting the text.
XThe title page is made in no-fill mode, so what you type in will be exactly
Xwhat appears on the title page.
XYou can start fill mode (\fB.fi\fR and maybe \fB.ad\fR), but BE SURE to
Xgo back to non-fill mode (\fB.nf\fR) before you use the \fB.ET\fR macro!
X.TP 12
X.B \&.ET
X.I Required:
XAt the end of the title page (after the \fB.ST\fP and the optional text),
Xend the title page with \fB.ET\fR.
X.PP
X.sp 2
XThe last part of the file are the \fBDAILY ENTRIES\fR, which are enclosed
Xwith \fB.SD\fR and \fB.ED\fR macro calls.  Here are the details:
X.TP 12
X.B \&.SD
XEach day's entry must start with the \fI.SD\fR macro.
XPut it on a line by itself.
X.TP 12
X\fB\&.EN time AM/PM "description" distance
X.I Required:
XFor each timepoint in a day, use the \fI.EN\fR (entry) macro.
XThe first argument is the clock time, a number between 1 and 12 (though
X24-hour time will work fine here).
X.sp
XIf you use a 12-hour clock, the second argument should be AM, PM, NOON, or
Xsomething like that.
XOn a 24-hour clock, use your imagination.
X.sp
XYou should put quotes around the third argument, which is usually the
Xdescription of a route you're taking since the last timepoint.
XIt can also hold the name of a destination.
X.sp
XThe fourth argument must be a number \(em the distance travelled
Xduring this entry.
X(Or, in other words, the distance travelled since the previous entry.)
X.sp
XHere's an example.
XIt's 10 AM and you're about to leave Auckland, New Zealand for a trip to
XRotorua.
XThe trip is via highways 3 and 12 and is 200 kilometres long (I'm making this
Xup!).
XYou'd write this \fI.EN\fP macro:
X.br
X	\fB.EN\010\0AM\0"Hwys. 3, 12 to Rotorua"\0200\fR
X.sp
XYou can omit the fourth argument in places where it isn't needed:
X.br
X	\fB.EN\04\0PM\0"Arrive in Timbuktu"\fR
X.TP 12
X\fB\&.FO "description" cost\fR
X.I Optional:
XWhen you plan to spend money for food, note it with \fI.FO\fR.
XYou must use \fI.FO\fR between a pair of \fI.SD\fR and \fI.ED\fR macros.
X.sp
XExample: in the middle of the day, you plan to spend $55 for lunch for your tour
Xgroup.
XYou might use this entry:
X.br
X	\fB.FO "lunch at Grease Cafe, El Paso" 55\fR
X.TP 12
X\fB\&.LO "description" cost\fR
X.I Optional:
XWhen you plan lodging expenses, note them with \fI.LO\fR.
XUse \fI.LO\fR between a pair of \fI.SD\fR and \fI.ED\fR macros.
X.sp
XExample: You'll be staying at the Waldorf-Astoria tonight, spending $1000.
XYou might use this entry, including the phone number for convenience:
X.br
X	\fB.LO "Waldorf-Astoria, 212/345-2999" 1000\fR
X.TP 12
X\fB\&.OE "description" cost\fR
X.I Optional:
XThe \fI.OE\fR (capital letter O) macro is for expenses besides food and
Xlodging.
XYou have to use \fI.OE\fR between a pair of \fI.SD\fR and \fI.ED\fR macros.
X.sp
XExample: You expect a transmission overhaul in Nairobi:
X.br
X	\fB.OE "Rebuild transmission" 550\fR
X.TP 12
X.B \&.ED total-time
X.I Required:
XAt the end of each day's entries, use \fI.ED\fR with the total time spent
Xtraveling that day.
XThis is usually the elapsed time between the first and last timepoints in the
Xday \(em unless you're crossing time zones.
X.sp
XExample: If you started traveling at 9 AM and finished at 5 PM, that's 8
Xhours of traveling:
X.br
X	\fB.ED 8\fR
X.TP 12
X.B \&.HL
X.I Optional:
XDraws a horizontal dashed line across the page.
X.TP 12
X.B lines with no macros
XIf you don't use a macro on a line, the line will be copied directly
Xto the itinerary without filling, adjusting, or wrapping.
XThe lines may look better if you indent them with a tab character.
X.SH FILES
X/u3/acs/jdpeek/.lib/tmac/tmac.ti
X.SH SEE ALSO
X.IR ms (7),
X.IR nroff (1),
X.IR troff (1).
X.SH BUGS
XMore default settings might be nice.
XSome parts could be shortened by using subroutines.
XInternal register names aren't unique enough and may conflict with any
Xregisters that the user defines.
X.SH AUTHOR
XJerry Peek; Syracuse University; Syracuse, New York.
X.PP
XI'm not an expert at formatter macros, so use these at your own risk.
XI'll take no responsibility for their accuracy or suitability for any purpose.
X.PP
XBugs (and kudos) to jdpeek@rodan.acs.syr.edu or jdpeek@suvm.bitnet.
XFlames will probably be ".ig"'ed. :-)
X//E*O*F mti.7//
chmod u=rw,g=r,o=r mti.7
 
echo extracting - sample.mti
sed 's/^X//' > "sample.mti" <<'X//E*O*F sample.mti//'
X.ds TI TRIP TO WASHINGTON, DC
X.nr FD 28	\" number of days in February (29 on leap years, 28 non-leap)
X.nr MN 5	\" month (1 = January, etc.) of first day of trip
X.nr DT 18	\" date of month for first day of trip
X'\" Distance traveled per currency unit (here, miles/dollar).
X'\" To calculate, divide the distance/fuel-unit by the cost/fuel-unit.
X'\" For example, if you get 35 miles/gallon and gas costs $1.50/gallon,
X'\" DU would be 35 divided by 1.5, or 23 miles/dollar.
X'\" Make sure that units here are the same as the units shown in the CS string.
X'\" You can also include costs for oil, tires, etc. if you want.
X.nr DU 30
X'\" day of month of first day of trip:
X.ds DY Thursday
X.ST "Trip to Washington, DC" "(camping by the coast in Maryland)"
X.HL
XBefore trip:
X.sp
X\(sq  Remember tarp and shovel
X\(sq  Take good clothes for dinner out
X.ET
X.SD
X.EN 7 AM "I-81 to Harrisburg, PA" 273
X.EN 12 NOON "I-83 to Baltimore, MD" 87
X.FO "Lunch on the road" 5
X.EN 2 PM "I-695 westbound, MD-3, MD-4, MD-497 to Calvert Cliffs Park" 95
X.EN 4 PM "Get to Calvert Cliffs"
X.LO "Camp at Calvert Cliffs State Park, Maryland; (301)456-7890" 10
X.ED 9
X.SD
X.FO "Breakfast" 4
X.EN 8 AM "MD-4, MD-235 to Maryland's first Capitol" 20
X.EN 9 AM "MD-235, MD-5, MD-234, US-301, MD-5 to Washington" 78
X.EN 11 AM "Get to Washington"
X.FO "Picnic lunch" 6
X.FO "Dinner" 15
X.EN 8 PM "Pennsylvania Ave., MD-4 to campground" 60
X.EN 9 PM "Get to campground"
X.LO "Calvert Cliffs State Park" 10
X.ED 13
X.SD
X.FO "Breakfast" 4
X.EN 9 AM "MD-4, some street to Washington" 60
X.EN 10 AM "Get to Washington"
X.FO "Lunch at sidewalk stand or ?" 10
X.FO "Dinner" 20
X.EN 8 PM "Pennsylvania Ave., MD-4 to campground" 60
X.EN 9 PM "Get to campground"
X.LO "Calvert Cliffs State Park" 10
X.ED 12
X.SD
X.FO "Breakfast" 4
X.EN 8 AM "MD-4, MD-506, MD-231, MD-5, Suitland Pkwy. to Washington, DC" 65
X.EN 10 AM "Get to Washington"
X.FO "Picnic lunch" 6
X.FO "Dinner someplace nice" 50
X.EN 8 PM "Pennsylvania Ave., MD-4 to campground" 60
X.EN 9 PM "Get to campground"
X.LO "Calvert Cliffs State Park" 10
X.ED 13
X.SD
X.EN 8 AM "MD-4 to Prince Frederick; MD-402&261 to Friendship; MD-2 to Annapolis" 56
X.EN 9 AM "Get to Annapolis"
X.OE "Museum admission" 8
X.EN 12 NOON "US-301, I-97, MD-3 to Baltimore; I-695 west to Timonium" 47
X.EN 1 PM "Lunch at Rax Restaurant" 10
X.EN 2 PM "I-83 to Harrisburg, PA" 87
X.EN 4 PM "I-81 to Syracuse" 273
X.EN 9 PM "Get to Syracuse"
X.ED 13
X//E*O*F sample.mti//
chmod u=rw,g=r,o=r sample.mti
 
echo extracting - tmacTEMP.ti
sed 's/^X//' <<'X//E*O*F tmac.ti//' > "tmacTEMP.ti"
X'\" $Header: /u3/acs/jdpeek/.lib/tmac/tmac.ti,v 2.0 89/04/06 10:50:14 jdpeek Exp $
X'\"
X'\"  	ti travel-itinerary macros for nroff/troff
X'\"	Jerry Peek; Syracuse, NY; jdpeek@rodan.acs.syr.edu, jdpeek@suvm.bitnet
X'\"
X'\"	If you make changes or bug fixes, please send me a copy so I can
X'\"	pass them on to other people...
X'\"
X.nf
X.na
X'\" Set line length to 8 inches (nroff only) so ".EN" entries can be longer:
X.nr St 0	\" dumb register that counts use of ST and ET macros
X.if n \{\
X.ll 8i
X.lt 8i \}
X.nr MI 0	\" total miles/kilometers
X.nr MT 0	\" miles or km today
X.nr CO 0	\" total cost
X.nr CT 0	\" cost today
X.nr DA 0 1	\" total number of days and amount (1 day) to increment by
X'\" Units to use: miles or km.  UL is long, for daily summaries; US is short,
X'\" used on each line.  User can re-define in file; should be lower-case:
X.ds UL miles
X.ds US mi
X'\" Currency symbol.  User can re-define in file.
X'\" Can have several characters, including trailing blanks:
X.ds CS $
X'\" Start-itinerary macro.  $1 = title for first page.
X'\" $2 = optional second title line.
X.de ST
X'\" Check flag to see if user has already invoked ST macro.  If so, scream.
X'\" If not, set flag:
X.if !\\n(sT=0 .ER "only one .ST per file, please."
X.nr sT 1
X.if !\\n(eT=0 .ER "You must use the .ET macro after the .ST"
X.if \\n(.$>2 .ER ".ST: you can't use more than two arguments."
X'\" Because first .SD will increment starting day, decrement it here.
X'\" Also, be sure starting day name is valid (if valid, set cK to 0):
X.nr cK 1
X.if '\\*(DY'Sunday' \{\
X.ds Dy Saturday
X.nr cK 0\}
X.if '\\*(DY'Monday' \{\
X.ds Dy Sunday
X.nr cK 0\}
X.if '\\*(DY'Tuesday' \{\
X.ds Dy Monday
X.nr cK 0\}
X.if '\\*(DY'Wednesday' \{\
X.ds Dy Tuesday
X.nr cK 0\}
X.if '\\*(DY'Thursday' \{\
X.ds Dy Wednesday
X.nr cK 0\}
X.if '\\*(DY'Friday' \{\
X.ds Dy Thursday
X.nr cK 0\}
X.if '\\*(DY'Saturday' \{\
X.ds Dy Friday
X.nr cK 0\}
X.if \\n(cK .ER ".ST: day name DY is missing or invalid."
X.rr cK
X.rm DY
X.if \\n(DU<1 .ER ".ST: DU undefined or less than 1.  Can't calculate fuel cost."
X.if (\\n(FD<28):(\\n(FD>29) .ER ".ST: FD undefined, or not 28 or 29."
X.if (\\n(MN<1):(\\n(MN>12) .ER ".ST: MN (\\n(MN) undefined, less than 1 or more than 12."
X.if \\n(DT<1 .ER ".ST: starting date DT is less than 1 or not defined."
X'\" Put DT (starting date: 1, 2, ..., 31) in Dt (date register);
X'\" set Dt to one day before start of trip because first .SD will increment it:
X.nr Dt \\n(DT-1 1
X.rm DT
X.sp 1i
X.ps +4
X.ce 3
XITINERARY \(em
X.sp 2
X\\$1
X.sp
X\\$2
X.ps
X'\" Don't print info below if user put -rQn on commandline:
X.if \\nQ=0 \{\
X.sp 2
X.ce 2
XThe traveling costs in this itinerary are based on the assumption that
Xeach \\n(DU \*(UL travelled will cost one \\*(CS for gas, oil, etc.
X.sp \}
X..
X.de ET	\" end of title page macro
X.ie !\\n(sT=1 .ER ".ET: You must use the ST macro first."
X.el .nr sT 0
X.ie !\\n(eT=0 .ER ".ET: Only one .ET per file."
X.el .nr eT 1
X'\" set eD register so that first .SD doesn't say "missing .ED":
X.nr eD 1
X.nr sD 0
X'\" Set page number to one so first page of itinerary will have that number:
X.pn 1
X.bp
X..
X.de ER
X.fl
X.ab*** ERROR at input line \\n(.c: \\$1 ***
X..
X.de NP	\" new-page macro (from Kernighan tutorial, pg. 8)
X'bp
X.ps +2
X'sp 0.5i
X.if t .sp 0.3i	\" more space if using troff
X'tl ZITINERARYZPage %Z\\*(TIZ
X'sp 0.3i
X.ps
X..
X.wh -1i NP	\" when get within 1 inch of page bottom, do NP (no . needed)
X.de EM	\" end-of-input macro (called by the ".em EM" trap)
X.ie !\\n(eD=1 .ER "Missing .ED at end of file"
X..
X.em EM
X'\" .HL draws em-dashes margin-to-margin.
X.de HL
X.br
X\l'\\n(.lu-\\n(.iu\&\(em'
X.br
X..
X'\" Start-of-day macro
X.de SD
X.if !\\n(.$=0 .ER "Don't use any argument with .SD."
X.if !\\n(eT=1 .ER ".SD: You must use .ET first."
X.ie !\\n(eD=1 .ER ".SD: Missing .ED"
X.el .nr eD 0
X.ie !\\n(sD=0 .ER ".SD: Two .SD's with no .ED between"
X.el .nr sD 1
X.nr MT 0	\" set today's mileage (kilometrage?)  to zero
X.nr CT 0	\" set today's cost to zero
X'\" handle month changes
X.if \\n(MN=1  .if \\n(Dt>30\{
X.nr MN 2
X.nr Dt 0\}
X.if \\n(MN=2 .if \\n(Dt>(\\n(FD-1)\{\
X.nr MN 3
X.nr Dt 0\}
X.if \\n(MN=3  .if \\n(Dt>30\{
X.nr MN 4
X.nr Dt 0\}
X.if \\n(MN=4  .if \\n(Dt>29\{
X.nr MN 5
X.nr Dt 0\}
X.if \\n(MN=5  .if \\n(Dt>30\{
X.nr MN 6
X.nr Dt 0\}
X.if \\n(MN=6  .if \\n(Dt>29\{
X.nr MN 7
X.nr Dt 0\}
X.if \\n(MN=7  .if \\n(Dt>30\{
X.nr MN 8
X.nr Dt 0\}
X.if \\n(MN=8  .if \\n(Dt>30\{
X.nr MN 9
X.nr Dt 0\}
X.if \\n(MN=9  .if \\n(Dt>29\{
X.nr MN 10
X.nr Dt 0\}
X.if \\n(MN=10  .if \\n(Dt>30\{
X.nr MN 11
X.nr Dt 0\}
X.if \\n(MN=11  .if \\n(Dt>29\{
X.nr MN 12
X.nr Dt 0\}
X.if \\n(MN=12  .if \\n(Dt>30\{
X.nr MN 1
X.nr Dt 0\}
X'\" change day
X.ie '\\*(Dy'Sunday' .ds Dy Monday
X.el .ie '\\*(Dy'Monday' .ds Dy Tuesday
X.el .ie '\\*(Dy'Tuesday' .ds Dy Wednesday
X.el .ie '\\*(Dy'Wednesday' .ds Dy Thursday
X.el .ie '\\*(Dy'Thursday' .ds Dy Friday
X.el .ie '\\*(Dy'Friday' .ds Dy Saturday
X.el .ds Dy Sunday
X'\" start keep (from Kernighan tutorial, pg. 12)
X.br	\" start fresh line
X.di Xx	\" collect text in diversion (macro) Xx
XDAY #\\n+(DA OF TRIP: \\*(Dy, \\n(MN/\\n+(Dt
X.sp
X..
X'\" Entry macro.  $1 = hour, $2 = AM/PM/etc., "$3" = description, $4 = miles/km
X.de EN
X.if !\\n(sD=1 .ER ".EN: Missing .SD"
X.if \\n(.$<3 .ER ".EN: Not enough arguments"
X'\" THIS NEXT TEST IS SORT OF A PAIN.  COMMENTED OUT FOR NOW:
X'\".ie ((\\$1=0):(\\$1=1):(\\$1=2):(\\$1=3):(\\$1=4):(\\$1=5):(\\$1=6):(\\$1=7):(\\$1=8):(\\$1=9):(\\$1=10):(\\$1=11):(\\$1=12)) '\" Do nothing
X'\".el .ER ".EN: first argument has to be hour digit"
X.ie \\$4>0 .tl Z\\$1 \\$2\0\0\\$3ZZ\\$4 \*(USZ
X.el \\$1 \\$2\0\0\\$3
X.nr MT +\\$4
X..
X'\" Food macro.  $1 = Description; $2 = cost in CS units, decimals truncated:
X.de FO
X.if !\\n(sD=1 .ER ".FO: Missing .SD"
X.if !\\n(.$=2 .ER "Usage is:  .FO description cost"
X.nr CT +\\$2
X.br
XFOOD: \\$1  \\*(CS\\$2.
X..
X'\" Lodging macro.  $1 = Description; $2 = cost in CS units, decimals truncated:
X.de LO
X.if !\\n(sD=1 .ER ".LO: Missing .SD"
X.if !\\n(.$=2 .ER "Usage is:  .LO description cost"
X.nr CT +\\$2
X.br
XLODGING: \\$1  \\*(CS\\$2.
X..
X'\" Other-expense macro.  $1 = Description; $2 = cost in CS units:
X.de OE
X.if !\\n(sD=1 .ER ".OE: Missing .SD"
X.if !\\n(.$=2 .ER "Usage is:  .OE description cost"
X.nr CT +\\$2
X.br
XOTHER: \\$1  \\*(CS\\$2.
X..
X'\" End of day macro.  $1 = number of hours today
X.de ED
X.ie !\\n(sD=1 .ER ".ED: Missing .SD"
X.el .nr sD 0
X.ie !\\n(eD=0 .ER ".ED: Two .ED's with no .SD between."
X.el .nr eD 1
X.if !\\n(.$=1 .ER ".ED: missing or too many arguments."
X.nr TT (\\n(MT/\\n(DU)	\" total travel cost = miles divided by miles/dollar 
X.nr OT \\n(CT		\" other total (TT not added in yet)
X.nr CT (\\n(TT+\\n(OT)	\" overwrite CT to hold total cost today: TT + OT
X.nr CO +\\n(CT		\" add today's cost to total trip cost
X.nr MI +\\n(MT		\" add today's miles (MT) to total trip miles (MI)
X.sp
X.fi
X'\" If -rQ1 was used on commandline, don't print lines:
X.if \\nQ=0 \{\
XTODAY:\0travel \\n(MT \\*(UL in \\$1
X.ie '\\$1'1' hour
X.el hours
Xfor \\*(CS\\n(TT; other costs \\*(CS\\n(OT; total \\*(CS\\n(CT
X.nf
XTO DATE:\0\\n(MI \\*(UL, \\*(CS\\n(CO \}
X.HL
X'\" end keep
X.br	\" get last partial line
X.di	\" end diversion
X.if \\n(dn>=\\n(.t .bp	\" do .bp if text doesn't fit on current page
X.Xx	\" bring back text stored in Xx macro
X..
X//E*O*F tmac.ti//
echo making tmacTEMP.ti into tmac.ti
tr Z '\007' < "tmacTEMP.ti" > "tmac.ti"
rm tmacTEMP.ti
chmod u=rw,g=r,o=r tmac.ti
 
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
      50     383    2186 README.mti
     427    2304   13238 mti.7
      69     453    2390 sample.mti
     249    1305    7129 tmac.ti
     795    4445   24943 total
!!!
wc  README.mti mti.7 sample.mti tmac.ti | sed 's/^X//' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0