home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1917 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  30.2 KB

  1. From: jbr0@cbnews.att.com (joseph.a.brownlee)
  2. Newsgroups: alt.sources
  3. Subject: pcal 2.5, part 2 of 2
  4. Message-ID: <1990Oct5.215432.5852@cbnews.att.com>
  5. Date: 5 Oct 90 21:54:32 GMT
  6.  
  7. #!/bin/sh
  8. # This is part 02 of a multipart archive
  9. # ============= pcal.hlp ==============
  10. if test -f 'pcal.hlp' -a X"$1" != X"-c"; then
  11.     echo 'x - skipping pcal.hlp (File already exists)'
  12. else
  13. echo 'x - extracting pcal.hlp (Text)'
  14. sed 's/^X//' << 'SHAR_EOF' > 'pcal.hlp' &&
  15. 1 PCAL
  16. X        Pcal  generates  PostScript  to produce landscape or  portrait
  17. X    orientated calendars for  any  month  and  year.  The defaults for
  18. X    month and year are the current month and year.
  19. X
  20. X        VMS Version
  21. X        Execution format:
  22. X    
  23. X            pcal [options] [mm yy] [n]
  24. X
  25. X        If a file named CALENDAR.DAT  resides  in  the  caller's  home
  26. X    directory (or in a directory defined by the logical name PCAL_DIR,
  27. X    if it exists), it will be  searched for  lines with  leading dates
  28. X    matching the requested  month  and year (current by default).  Any
  29. X    text following the date  will be printed on the calendar under the
  30. X    appropriate day of the month.   Dates in the CALENDAR.DAT file may
  31. X    consist  of  a  numeric or alpha  month  (at  least  the  first  3
  32. X    characters  for  month  names)  followed  by  a  numeric  day  and
  33. X    optionally  followed  by  a year.  Any non-numeric  character  may
  34. X    separate numeric dates.  Holidays may be flagged by  following the
  35. X    date immediately with '*';  this will cause the date to be printed
  36. X    in gray.  Lines in the CALENDAR.DAT file consisting of "year xxxx"
  37. X    (where  xxxx  is a numeric year) can be used to set the  year  for
  38. X    following entries.  This assumes that the following entries do not
  39. X    contain a year;  any date entries containing year information will
  40. X    set  the  remembered  year  to  that  year.  Lines  consisting  of
  41. X    "opt <options>" can be used to  override defaults for all command-
  42. X    line flags except -e, -f, -D, and -U; any flags set in this manner
  43. X    are themselves  overridden by  flags specified  explicitly  on the
  44. X    command line.  Comments ('#' through  end-of-line) are  permitted.
  45. X
  46. X    Example:
  47. X
  48. X    # sample CALENDAR.DAT file - Raytheon holidays and exempt paydays, 1990
  49. X
  50. X    opt -t Helvetica-Bold -d Helvetica-Bold    # override default fonts
  51. X    opt -M                    # print moon phase
  52. X
  53. X    year 1990                # set default year
  54. X
  55. X    7/4* Independence Day            # '*' flags 7/4 as holiday
  56. X    7/12/90 Exempt payday            # full numeric date
  57. X    Aug 16 Exempt payday            # alternate date format
  58. X    9/3* Labor Day
  59. X    9/20 Exempt payday
  60. X    10/8* Columbus Day (observed)
  61. X    10/25 Exempt payday
  62. X    11/20 Exempt payday
  63. X    11/22* Thanksgiving
  64. X    11/23*
  65. X    12/13 Exempt payday
  66. X    12/24*
  67. X    12/25* Christmas
  68. X
  69. X    Pcal supports rudimentary cpp-like functionality in the date file,
  70. X    supporting  define | undef,  if{n}def ...  {else ...}  endif,  and
  71. X    include:
  72. X
  73. X    define meetings
  74. X
  75. X    ifdef meetings
  76. X      include meetings.dat
  77. X      undef meetings
  78. X    endif
  79. X    
  80. X    Symbol names are case-insensitive.  It is  not an error to "undef"
  81. X    an undefined symbol, nor to "define" a previously-defined one.
  82. X
  83. X    "ifdef" alone is always false; "ifndef" alone is always true.
  84. X
  85. X    The name of the file in the "include" directive may  optionally be
  86. X    surrounded  by either "" or <>, both of which are ignored.  If the
  87. X    name is not  an absolute  path, it is taken to be relative  to the
  88. X    directory where the file containing the directive is located.
  89. X
  90. X    Pcal  allows  the  user to  print  additional  notes in  an unused
  91. X    calendar  box via lines  of the  form "note <month> <text>", where
  92. X    <month>  specifies  the  month (numeric  or alphabetic  form)  and
  93. X    <text> is  the  text to  add.  All  such text  will  appear in the
  94. X    "Thursday" box on the last line (next to the small calendars).
  95. X
  96. X    Pcal also  looks  for  global  symbol PCAL_OPTS;  if defined,  its
  97. X    contents  are  parsed as  command-line flags.  These  override the
  98. X    program  defaults,  but are overridden  by any specified via "opt"
  99. X    lines in  the date file or on the command line.  Example:
  100. X
  101. X    $ define PCAL_OPTS "-n Helvetica -D meetings"      ! login.com
  102. X
  103. X    $ pcal -"U" meetings 9 90    ! un-define symbol at runtime
  104. X
  105. 2 parameters
  106. X  mm yy n
  107. X        "mm" and "yy"  are numeric values of the month (1-12) and year
  108. X    (0-99) (i.e., July 1990  would  be 7 90).  If you just include the
  109. X    "yy" option, an entire 12  months  of calendars will be generated.
  110. X    A specific month can be produced  by including the "mm" parameter.
  111. X    The  "n"  parameter will  produce the "n"  consecutive  months  of
  112. X    calendars starting with the requested month.
  113. X
  114. X        The following flags  may be specified  (in increasing order of
  115. X    precedence) in global symbol PCAL_OPTS, in "opt" lines in the date
  116. X    file (all but -e, -f, -D, -U), or on the command  line.  Any  flag
  117. X    which  normally  takes  an argument  may be specified  without the
  118. X    argument;  this resets  its  value  to the  program  default.  (-D
  119. X    alone thus clears all defined symbols; -U alone has no effect.)
  120. X
  121. X    The '-' flag has  been added to  disambiguate  cases  where an
  122. X    argument-less flag has been specified immediately before a numeric
  123. X    parameter:
  124. X
  125. X    $ pcal -t - 9 90
  126. X
  127. 2 -e
  128. X        Print an  empty  calendar (i.e., do not  print entries  from a
  129. X    CALENDAR.DAT file.)
  130. X
  131. 2 -f <FILE>
  132. X        Directs pcal to use the  file name <FILE> as the input file in
  133. X    place  of the  default  CALENDAR.DAT  file  in  the  callers  home
  134. X    directory or in the  directory specified by logical name PCAL_DIR.
  135. X
  136. 2 -o <FILE>
  137. X        Directs  pcal to  write  the  PostScript  calendar  into  FILE
  138. X    (default: CALENDAR.PS in the current directory.)
  139. X
  140. 2 -l
  141. X        This will cause the  output  to  come  out  in  landscape mode
  142. X    (default).
  143. X
  144. 2 -p
  145. X        This will cause  the  output  to  come  out  in  portrait mode
  146. X    instead of landscape mode.
  147. X
  148. 2 -b <DAY> | all
  149. X        This  will cause  all dates  on weekday  DAY to be  printed in 
  150. X    black;  "-b all" causes  all dates  to be printed  in black unless
  151. X    explicitly flagged as a holiday.
  152. X
  153. 2 -g <DAY> | all
  154. X        This  will cause  all dates  on weekday  DAY to be  printed in 
  155. X    gray; "-g all" causes all dates to be printed in gray.  Default is
  156. X    to print Saturdays  and Sundays in gray and  other dates in black.
  157. X
  158. 2 -F <DAY>
  159. X        This will cause  the weekday  DAY  to be the first day of each
  160. X    week;  weekday  DAY  will appear in  the left-most  column of each
  161. X    calendar.
  162. X
  163. 2 -t <FONT>
  164. X        This option can be used  to  change  the  font  the  title  is
  165. X    printed in  (ie. pcal -t Times-Roman).  The default is Times-Bold.
  166. X
  167. 2 -d <FONT>
  168. X        This option is the same as  -t  except  that  the font used to
  169. X    print the  day  numbers is  changed.  The  default is  Times-Bold.
  170. X
  171. 2 -n <FONT>
  172. X        This option is the same as  -n  except  that  the font used to
  173. X    print the notes in the calendar boxes is  changed.  The default is
  174. X    Helvetica-Narrow.
  175. X
  176. 2 -m
  177. X        This option causes a  moon to be printed on days corresponding
  178. X    to a full, half, or new moon (default: no moons).
  179. X
  180. 2 -"M"
  181. X        This option causes a  moon to be printed on all days (default:
  182. X    no moons).
  183. X
  184. 2 -"L" <STRING>
  185. X        This will cause STRING to be printed as a left footer.
  186. X
  187. 2 -"C" <STRING>
  188. X        This will cause STRING to be printed as a center footer.
  189. X
  190. 2 -"R" <STRING>
  191. X        This will cause STRING to be printed as a right footer.
  192. X
  193. 2 -"D" <SYM>
  194. X    This will  define symbol  SYM prior to  reading the date file;
  195. X    -D alone clears all defined symbols.
  196. X
  197. 2 -"U" <SYM>
  198. X    This will undefine symbol  SYM prior to reading the date file.
  199. X
  200. 2 CREDITS
  201. X        The original PostScript code  to  generate  the  calendars was
  202. X    written by Patrick Wood (Copywrite  (c)  1987  by  Patrick Wood of
  203. X    Pipeline  Associates, Inc.), and authorized for  modification  and
  204. X    redistribution.    The  CALENDAR.DAT  file  inclusion  code    was
  205. X    originally written in "bs(1)" by Bill Vogel of  AT&T.    Patrick's
  206. X    original  PostScript  was  modified  and enhanced several times by
  207. X    others  whose names  have  regrettably been lost.  Ken Keirnan  of
  208. X    Pacific Bell assembled the original "C" version upon which this is
  209. X    based;  additional modifications and enhancements were the work of
  210. X    Joseph P. Larson, Ed Hand, Andrew W. Rogers,  Mark Kantrowitz, Joe
  211. X    Brownlee, and Jamie Zawinski.  This  VMS HELP file was  written by
  212. X    Richard Dyson and updated by Andrew W. Rogers and Joe Brownlee.
  213. X
  214. SHAR_EOF
  215. chmod 0644 pcal.hlp ||
  216. echo 'restore of pcal.hlp failed'
  217. Wc_c="`wc -c < 'pcal.hlp'`"
  218. test 8035 -eq "$Wc_c" ||
  219.     echo 'pcal.hlp: original size 8035, current size' "$Wc_c"
  220. fi
  221. # ============= pcal.man ==============
  222. if test -f 'pcal.man' -a X"$1" != X"-c"; then
  223.     echo 'x - skipping pcal.man (File already exists)'
  224. else
  225. echo 'x - extracting pcal.man (Text)'
  226. sed 's/^X//' << 'SHAR_EOF' > 'pcal.man' &&
  227. .TH PCAL 1
  228. .SH NAME
  229. pcal \- generate PostScript calendars
  230. .SH SYNOPSIS
  231. .BR pcal " ["
  232. .BR \-e " | " \-f
  233. .I cal
  234. ] [
  235. .BI \-o " file"
  236. ] [
  237. .BR \-l " | " \-p
  238. ] [
  239. .BR \-m " | " \-M
  240. ] [
  241. .BI \-b " day"
  242. | all ]
  243. [
  244. .BI \-g " day"
  245. | all ]
  246. [
  247. .BI \-F " day"
  248. ] [
  249. .BI \-t " title_font"
  250. ] [
  251. .BI \-d " day_font"
  252. ] [
  253. .BI \-n " text_font"
  254. ] [
  255. .BI \-L " footer_string"
  256. ] [
  257. .BI \-C " footer_string"
  258. ] [
  259. .BI \-R " footer_string"
  260. ] [
  261. .BI \-D " symbol"
  262. ] [
  263. .BI \-U " symbol"
  264. ] [
  265. .B month
  266. ] [
  267. .B year
  268. ] [
  269. .B nmonths
  270. ]
  271. .SH DESCRIPTION
  272. .I Pcal
  273. generates PostScript to produce landscape or portrait calendars for any 
  274. month and year.  The arguments
  275. .BR month ,
  276. .BR year ,
  277. and
  278. .BR nmonths ,
  279. if provided, should be numeric.  The 
  280. .BR month
  281. value should be in the range 1 \- 12, and the 
  282. .BR year
  283. value should be specified as 1 or 2 digits or as the full 4 digit year.
  284. If no numeric arguments are provided, the calendar for the current month
  285. and year will be generated.
  286. .PP
  287. If one numeric argument is provided, it is interpreted as the
  288. .BR year
  289. value, and calendars for the entire year will be generated.  Otherwise, 
  290. .BR nmonth
  291. months, starting with
  292. .BR month
  293. and
  294. .BR year ,
  295. will be generated.
  296. .PP
  297. If a file named
  298. .I \.calendar
  299. (or
  300. .I calendar
  301. for compatibility with older versions)
  302. exists in the caller's home directory or in the directory pointed to by
  303. environment variable
  304. .BR PCAL_DIR ,
  305. it will be searched for lines with
  306. leading dates matching the requested month and year.
  307. Any text following the dates found will be printed on the calendar under the
  308. appropriate day of the month.  Dates in the
  309. .I \.calendar
  310. file may consist of a numeric or alphabetic month (at least the first 3
  311. characters for month names), followed by a numeric day and optionally followed
  312. by a year.  Any non-numeric character may separate numeric dates.  Holidays may
  313. be flagged by following the date immediately with `*'; this will cause the
  314. date to be printed in gray.
  315. .PP
  316. Lines in the
  317. .I \.calendar
  318. file consisting of 
  319. .B year XXXX
  320. (where
  321. .B XXXX
  322. is a numeric year) can be used
  323. to set the year for following entries.  This assumes that the following
  324. entries do not contain a year; any date entries containing year information
  325. will set the remembered year to that year.
  326. .PP
  327. Lines in the
  328. .I \.calendar
  329. file consisting of 
  330. .B opt <options>
  331. can be used to override the defaults for
  332. any command-line flags except
  333. .BR \-e ,
  334. .BR \-f ,
  335. .BR \-D ", and"
  336. .BR \-U .
  337. Any flags specified in this manner
  338. are, in turn, overridden by those specified explicitly on the command line.
  339. .PP
  340. Lines in the
  341. .I \.calendar
  342. file consisting of
  343. .B note <month>
  344. can be used to place notes regarding the
  345. entire month is one of the unused blocks of the calendar.  The
  346. .B <month>
  347. indicator may be either a number 1 through 12 or an alphabetic month name
  348. as described above.
  349. .PP
  350. Comments are supported in the
  351. .I \.calendar
  352. file.  Any characters following a `#' character through the end of the
  353. line are ignored.
  354. .PP
  355. .I Pcal
  356. supports rudimentary cpp-like functionality in the
  357. date file, allowing the following constructs:
  358. .BR "define | undef" ,
  359. .B if{n}def ... {else ...} endif,
  360. and
  361. .BR include .
  362. Note that these are not preceded by `#' as they are in C.
  363. Symbol names defined using these keywords are case-insensitive.
  364. It is not an error to
  365. .BR undef
  366. an undefined symbol, nor to
  367. .BR define
  368. a previously-defined one.  An
  369. .BR ifdef
  370. alone is always false; an
  371. .BR ifndef
  372. alone is always true.
  373. .PP
  374. The name of the file in the 
  375. .BR include
  376. directive may optionally be
  377. surrounded by either "" or <>, both of which are ignored.  If the
  378. name is not an absolute path, it is taken to be relative to the
  379. directory where the file containing the directive is located.
  380. .I Pcal
  381. is smart enough to translate
  382. .B ~/
  383. to the user's home directory.
  384. .PP
  385. .I Pcal
  386. has many options:
  387. .P
  388. .TP 12
  389. .B \-e
  390. Prints an empty calendar.  Do not print entries from a
  391. .I \.calendar
  392. file.
  393. .TP
  394. .BI \-f " cal"
  395. Directs
  396. .I pcal
  397. to use the file name
  398. .I cal
  399. as the input file in place of the default
  400. .I \.calendar
  401. file in the user's home directory (or the directory pointed to by
  402. .BR PCAL_DIR ).
  403. .TP
  404. .BI \-o " file"
  405. Directs
  406. .I pcal
  407. to write the output to
  408. .I file
  409. instead of to stdout.
  410. .TP
  411. .B \-l
  412. Causes the output to be in landscape mode (default).
  413. .TP
  414. .B \-p
  415. Causes the output to be in portrait mode.
  416. .TP
  417. .B \-m
  418. Causes moon icons to be printed on dates corresponding to
  419. new, half, and full moons (the default is that no moons are printed).
  420. .TP
  421. .B \-M
  422. Causes moon icons to be printed on all dates (the default is
  423. that no moons are printed).
  424. .TP
  425. .BI \-b " day" " | all"
  426. Causes all dates falling on weekday
  427. .I day
  428. to be printed in black;
  429. .B \-b all
  430. causes all weekdays to be printed in black.
  431. .TP
  432. .BI \-g " day" " | all"
  433. Causes all dates falling on weekday
  434. .I day
  435. to be printed in gray;
  436. .B \-g all
  437. causes all weekdays to be printed in gray.
  438. .IP
  439. The default for the
  440. .BR \-b " and " \-g
  441. flags is to print Saturdays and Sundays in gray and other days, unless
  442. flagged as holidays, in black.
  443. .TP
  444. .BI \-F " day"
  445. Selects weekday
  446. .I day
  447. as the first day of the week.  The given day will appear in the left-most
  448. column of the calendar.
  449. .TP
  450. .BI \-t " title_font"
  451. Sepcoifies the name of a font to use to print the
  452. month name and year at the top of the calendar.  For example,
  453. .BR "pcal \-t Times-Roman" .
  454. .TP
  455. .BI \-d " day_font"
  456. Similar to the
  457. .B \-t
  458. option, but selects the font used to print the day numbers.
  459. .TP
  460. .BI \-n " text_font"
  461. Similar to the
  462. .B \-t
  463. option, but selects the font used to print the text inside each day and in
  464. the notes block.
  465. .TP
  466. .BI \-D " symbol"
  467. Defines the named symbol prior to reading the date file.
  468. .TP
  469. .BI \-U " symbol"
  470. Un-defines the named symbol prior to reading the date file.
  471. .TP
  472. .BI \-L " string"
  473. Causes the accompanying string to be printed as a left-justified footer.
  474. .TP
  475. .BI \-C " string"
  476. Causes the accompanying string to be printed as a centered footer.
  477. .TP
  478. .BI \-R " string"
  479. Causes the accompanying string to be printed as a right-justified
  480. footer.
  481. .PP
  482. Any option which normally takes an argument may be specified without
  483. the argument in order to reset the value to the program default.  Note that
  484. while the
  485. .B \-D
  486. option alone clears all the defined symbols, the
  487. .B \-U
  488. option alone has no effect.  The
  489. .B \-
  490. (or
  491. .BR "\- \-" ,
  492. System V people)
  493. flag may be used to disambiguate command lines such as:
  494. .IP
  495. .B pcal \-t 9 90
  496. .PP
  497. This could be written instead as one of the following:
  498. .IP
  499. .B pcal \-t \- 9 90
  500. .br
  501. .B pcal \-t \- \- 9 90
  502. .PP
  503. If the environment variable
  504. .BR PCAL_OPTS
  505. is defined, its contents are parsed as a command line.  Flags set via
  506. .BR PCAL_OPTS
  507. override the program defaults, but are overridden by flags set via 
  508. .B opt
  509. lines in the
  510. .I \.calendar
  511. file or explicitly on the command line.
  512. .SH SEE ALSO
  513. cal(1)
  514. .SH AUTHORS
  515. The original PostScript code to generate the calendars was written by
  516. Patrick Wood (Copywrite (c) 1987 by Patrick Wood of Pipeline Associates,
  517. Inc.), and authorized for modification and redistribution.  The calendar
  518. file inclusion code was originally written in
  519. .IR bs (1)
  520. by Bill Vogel of AT&T.  Patrick's original PostScript was modified and
  521. enhanced several times by others whos names have regrettably been lost.
  522. Ken Keirnan of Pacific Bell assembled the original ``C'' version upon which
  523. this is based; additional modifications and enhancements are the work of
  524. Joseph P.  Larson, Ed Hand, Andrew W. Rogers, Mark Kantrowitz, Joe Brownlee,
  525. and Jamie Zawinski.
  526. SHAR_EOF
  527. chmod 0644 pcal.man ||
  528. echo 'restore of pcal.man failed'
  529. Wc_c="`wc -c < 'pcal.man'`"
  530. test 7393 -eq "$Wc_c" ||
  531.     echo 'pcal.man: original size 7393, current size' "$Wc_c"
  532. fi
  533. # ============= pcalinit.c ==============
  534. if test -f 'pcalinit.c' -a X"$1" != X"-c"; then
  535.     echo 'x - skipping pcalinit.c (File already exists)'
  536. else
  537. echo 'x - extracting pcalinit.c (Text)'
  538. sed 's/^X//' << 'SHAR_EOF' > 'pcalinit.c' &&
  539. /*
  540. X * Create a .h file from a .ps file.  Strips out leading and trailing 
  541. X * whitespace, blank lines, and lines consisting solely of comments,
  542. X * except for the very first block of comments/blanklines, which are
  543. X * turned into C comments at the top of the file.
  544. X * 
  545. X *   14-sep-90  Jamie Zawinski  created.
  546. X */
  547. X
  548. #include <stdio.h>
  549. #include <ctype.h>
  550. #include <string.h>
  551. X
  552. char *strip_white (string)
  553. X     char *string;
  554. {
  555. X    int n;
  556. X    for (; *string == ' ' || *string == '\t' || *string == '\n'; string++);
  557. X    n = strlen(string)-1;
  558. X    for (; string[n] == ' ' || string[n] == '\t' || string[n] == '\n'; n--)
  559. X        string[n] = '\0';
  560. X    return string;
  561. }
  562. X
  563. main (argc, argv)
  564. X     int argc; char *argv[];
  565. {
  566. X    FILE *in, *out;
  567. X    char line[256], *L;
  568. X    int in_initial_comments = 1;
  569. X    if (argc != 3) {
  570. X       fprintf(stderr, "usage: %s <infile>.ps <outfile>.h\n", argv[0]);
  571. X       exit(-1); }
  572. X    
  573. X    in = fopen(argv[1], "r");
  574. X    if (NULL == in) {
  575. X       fprintf(stderr, "%s: couldn't open %s\n", argv[0], argv[1]);
  576. X       exit(-1); }
  577. X    
  578. X    out = fopen(argv[2], "w");
  579. X    if (NULL == out) {
  580. X       fprintf(stderr, "%s: couldn't open %s\n", argv[0], argv[2]);
  581. X       exit(-1); }
  582. X    
  583. X    fprintf (out,
  584. X       "/* automatically generated from \"%s\" - DO NOT EDIT THIS FILE!\n *\n",
  585. X       argv[1]);
  586. X    for (;;) {
  587. X       if (NULL == fgets (line, 255, in)) break;
  588. X       L = strip_white(line);
  589. X       if ( in_initial_comments ) {
  590. X      if ( L[0] != '%' && L[0] != '\0' ) {
  591. X         in_initial_comments = 0;
  592. X         fprintf(out, " */\n\nchar *header[] = {\n  \"%s\",\n", L); }
  593. X      else
  594. X         fprintf(out, " * %s\n", L);
  595. X       }
  596. X       else if (L[0] != '%' && L[0] != '\0' )
  597. X          fprintf(out, "  \"%s\",\n", L);
  598. X    }
  599. X    fprintf(out, "  (char *)0,\n};\n");
  600. X    fclose(out);
  601. X    fclose(in);
  602. }
  603. SHAR_EOF
  604. chmod 0644 pcalinit.c ||
  605. echo 'restore of pcalinit.c failed'
  606. Wc_c="`wc -c < 'pcalinit.c'`"
  607. test 1792 -eq "$Wc_c" ||
  608.     echo 'pcalinit.c: original size 1792, current size' "$Wc_c"
  609. fi
  610. # ============= pcalinit.ps ==============
  611. if test -f 'pcalinit.ps' -a X"$1" != X"-c"; then
  612.     echo 'x - skipping pcalinit.ps (File already exists)'
  613. else
  614. echo 'x - extracting pcalinit.ps (Text)'
  615. sed 's/^X//' << 'SHAR_EOF' > 'pcalinit.ps' &&
  616. %!ps
  617. % pcalinit.ps - provides the PostScript routines for pcal.c
  618. %
  619. % 2.5    modified by Joe Brownlee:
  620. %
  621. %    made day numbers smaller, providing more room for event text
  622. %    repositioned event text and moons accordingly
  623. %    added support for variable first day of week
  624. %
  625. % 2.4    * no modifications *
  626. %
  627. % 2.3    modified by Jamie Zawinski <jwz@lucid.com>:
  628. %
  629. %    merged in moon routines (originally by Mark Hanson)
  630. %
  631. % 2.2    modified by Joe Brownlee:
  632. %
  633. %    add "notetext" to print notes in unused calendar box
  634. %
  635. % 2.1    modified by Mark Kantrowitz:
  636. %
  637. %    use symbolic names instead of magic numbers throughout
  638. %    support -L, -C, -R, -n options (all new)
  639. %    print holiday text in otherwise-wasted space next to date
  640. %    use larger text for dates in large calendars
  641. %
  642. % 2.0    modified by Andrew W. Rogers:
  643. %
  644. %    skip printing days of week on small calendars
  645. %    center month and year at top of calendar
  646. %    use correct algorithm for leap year calculation
  647. %    get month and day names from main program
  648. %    use table to determine color (black/gray) of weekdays and holidays
  649. %    use hanging indent to print continued text lines
  650. X
  651. /titlefontsize 48 def
  652. /weekdayfontsize 12 def
  653. /footfontsize 12 def
  654. /datefontsize 25 def
  655. /savedatefontsize datefontsize def
  656. /notesfontsize 6 def
  657. /daywidth 100 def
  658. /dayheight 80 def
  659. /negdaywidth 0 daywidth sub def
  660. /negdayheight 0 dayheight sub def
  661. /prtnum { 3 string cvs show} def
  662. X
  663. /drawgrid {        % draw calendar boxes
  664. X    dayfont findfont weekdayfontsize scalefont setfont
  665. X    0 1 6 {
  666. X        /i exch def
  667. X        submonth 0 eq {
  668. X            i daywidth mul 40 moveto
  669. X            day_names i get
  670. X            daywidth center
  671. X        } if
  672. X        i daywidth mul 35 moveto
  673. X        1.0 setlinewidth
  674. X        0 1 5 {
  675. X            gsave
  676. X            daywidth 0 rlineto
  677. X            0 negdayheight rlineto
  678. X            negdaywidth 0 rlineto
  679. X            closepath stroke
  680. X            grestore
  681. X            0 negdayheight rmoveto
  682. X         pop } for
  683. X    } for
  684. } def
  685. X
  686. X
  687. /drawnums {        % place day numbers on calendar
  688. X    dayfont findfont datefontsize scalefont setfont
  689. X    /start startday def
  690. X    /days ndays def
  691. X    /fontdiff datefontsize savedatefontsize sub def
  692. X    /n 0 def
  693. X    start daywidth mul 5 add 15 fontdiff sub rmoveto
  694. X    1 1 days {
  695. X        /day exch def
  696. X        gsave
  697. X        submonth 0 eq {
  698. X            /gray day_gray day start add 1 sub 7 mod get def
  699. X            day holidays n get eq {
  700. X                /gray holiday_gray def
  701. X                /n n 1 add def
  702. X            } if
  703. X            gray {
  704. X                0.8 setgray
  705. X            } if
  706. X        } if
  707. X        day prtnum
  708. X        grestore
  709. X        day start add 7 mod 0 eq
  710. X        {
  711. X            currentpoint exch pop dayheight sub 5 exch moveto
  712. X        }
  713. X        {
  714. X            daywidth 0 rmoveto
  715. X        } ifelse
  716. X    } for
  717. } def
  718. X
  719. X
  720. /drawfill {        % place fill squares on calendar
  721. X    /start startday def
  722. X    /days ndays def
  723. X    0 35 rmoveto
  724. X    1.0 setlinewidth
  725. X    0 1 start 1 sub {
  726. X        gsave
  727. X        .9 setgray
  728. X        daywidth 0 rlineto 
  729. X        0 negdayheight rlineto
  730. X        negdaywidth 0 rlineto
  731. X        closepath fill
  732. X        grestore
  733. X        daywidth 0 rmoveto
  734. X    pop } for
  735. X    submonth 1 eq
  736. X    {
  737. X        /lastday 42 def
  738. X        600 -365 moveto
  739. X    }
  740. X    {
  741. X        note_block
  742. X        {
  743. X            /lastday 39 def
  744. X            300 -365 moveto
  745. X        }
  746. X        {
  747. X            /lastday 40 def
  748. X            400 -365 moveto
  749. X        } ifelse
  750. X    } ifelse
  751. X    lastday -1 ndays start 1 add add
  752. X    {
  753. X        /day exch def
  754. X        gsave
  755. X        .9 setgray
  756. X        daywidth 0 rlineto 
  757. X        0 negdayheight rlineto
  758. X        negdaywidth 0 rlineto
  759. X        closepath fill
  760. X        grestore
  761. X        day 7 mod 1 eq
  762. X        { 600 -365 dayheight add moveto }
  763. X        { negdaywidth 0 rmoveto }
  764. X        ifelse
  765. X    } for
  766. } def
  767. X
  768. X
  769. /isleap {        % is this a leap year?
  770. X    year 4 mod 0 eq        % multiple of 4
  771. X    year 100 mod 0 ne     % not century
  772. X    year 400 mod 0 eq or and    % or divisible by 400
  773. } def
  774. X
  775. /isleap_2 {        % is some other year a leap year?
  776. X    /a_year exch def
  777. X     a_year 4 mod 0 eq        % multiple of 4
  778. X     a_year 100 mod 0 ne     % not century
  779. X     a_year 400 mod 0 eq or and    % or divisible by 400
  780. } def
  781. X
  782. /days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
  783. X
  784. /ndays {        % number of days in this month
  785. X    days_month month 1 sub get
  786. X    month 2 eq    % Feb
  787. X    isleap and
  788. X    {
  789. X        1 add
  790. X    } if
  791. } def
  792. X
  793. /ndays_2 {          % number of days in some other month
  794. X    /a_month exch def
  795. X    /a_year exch def
  796. X    days_month a_month 1 sub get
  797. X    a_month 2 eq            % February
  798. X    a_year isleap_2 and
  799. X    { 1 add }
  800. X    if
  801. } def
  802. X
  803. X
  804. /startday {        % starting day-of-week for this month
  805. X    /off year 2000 sub def    % offset from start of epoch
  806. X    off
  807. X    off 4 idiv add        % number of leap years
  808. X    off 100 idiv sub    % number of centuries
  809. X    off 400 idiv add    % number of years divisible by 400
  810. X    6 add 7 mod 7 add     % offset from Jan 1 2000
  811. X    /off exch def
  812. X    1 1 month 1 sub {
  813. X        /idx exch def
  814. X        days_month idx 1 sub get
  815. X        idx 2 eq
  816. X        isleap and
  817. X        {
  818. X            1 add
  819. X        } if
  820. X        /off exch off add def
  821. X    } for
  822. X    off dayoffset sub 7 add 7 mod    % 0--first day of week, 1--second, etc.
  823. } def
  824. X
  825. X
  826. /center {        % center string in given width
  827. X    /width exch def
  828. X    /str exch def width str 
  829. X    stringwidth pop sub 2 div 0 rmoveto str show
  830. } def
  831. X
  832. X
  833. /strcat {        % concatenate two strings
  834. X    2 copy
  835. X    length exch length
  836. X    dup 3 -1 roll add
  837. X    string
  838. X    dup 0 6 -1 roll putinterval
  839. X    dup 3 -1 roll 4 -1 roll putinterval
  840. } def
  841. X
  842. X
  843. /calendar
  844. {
  845. X    titlefont findfont titlefontsize scalefont setfont
  846. X    /month_name month_names month 1 sub get def
  847. X    /yearstring year 10 string cvs def
  848. X    0 60 moveto
  849. X    month_name (  ) strcat yearstring strcat 700 center
  850. %    month_name show
  851. %    daywidth 7 mul yearstring stringwidth pop sub 60 moveto
  852. %    yearstring show
  853. X
  854. X    submonth 0 eq {
  855. X        titlefont findfont footfontsize scalefont setfont
  856. X        /bottomrow { dayheight 6 mul 20 sub neg } def
  857. X        0 bottomrow moveto
  858. X        Lfootstring show
  859. X        daywidth 7 mul Rfootstring stringwidth pop sub
  860. X        bottomrow moveto
  861. X        Rfootstring show
  862. X        daywidth 7 mul Cfootstring stringwidth pop sub 2 div
  863. X        bottomrow moveto
  864. X        Cfootstring show
  865. X    } if
  866. X    0 0 moveto
  867. X    drawnums
  868. X    0 0 moveto
  869. X    drawfill
  870. X    0 0 moveto
  871. X    drawgrid
  872. X    0 0 moveto
  873. X    submonth 0 eq { drawmoons } if
  874. } def
  875. X
  876. X
  877. /daytext {
  878. X    notesfont findfont notesfontsize scalefont setfont
  879. X    /mytext    exch def /myday exch def
  880. X    startday myday 1 sub add dup 7 mod daywidth mul 2 add % gives column
  881. X    exch 7 idiv negdayheight mul 6 add    % gives row
  882. X    dup /ypos exch def moveto
  883. X    /LM currentpoint pop def /RM LM 95 add def
  884. X    mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall
  885. } def
  886. X
  887. X
  888. /holidaytext {
  889. X    notesfont findfont notesfontsize scalefont setfont
  890. X    /mytext    exch def /myday exch def
  891. X    startday myday 1 sub add dup 7 mod daywidth mul
  892. X    myday 10 lt {20} {33} ifelse add    % gives column
  893. X    exch 7 idiv negdayheight mul 27 add    % gives row
  894. X    dup /ypos exch def moveto
  895. X    /LM currentpoint pop def /RM LM myday 10 lt {75} {60} ifelse add def
  896. X    /day myday def
  897. X    do-moon-p { /RM RM 16 sub def } if
  898. X    mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall
  899. } def
  900. X
  901. X
  902. /notetext {
  903. X    dayfont findfont 12 scalefont setfont
  904. X    4 daywidth mul 4 add            % title column
  905. X    5 negdayheight mul 24 add        % title row
  906. X    moveto
  907. X    (Notes) show
  908. X    notesfont findfont notesfontsize scalefont setfont
  909. X    /mytext    exch def
  910. X    4 daywidth mul 4 add            % gives column
  911. X    5 negdayheight mul 16 add        % gives row
  912. X    dup /ypos exch def moveto
  913. X    /LM currentpoint pop def /RM LM 95 add def
  914. X    mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall
  915. } def
  916. X
  917. /crlf {
  918. X    ypos notesfontsize sub /ypos exch def LM ypos moveto
  919. } def
  920. X
  921. /prstr {
  922. X    dup stringwidth pop currentpoint pop
  923. X    add RM gt {crlf (   ) show} if show
  924. } def
  925. X
  926. /printmonth {
  927. X    landscape-p
  928. X      { 90 rotate 50 -120 translate }
  929. X      { 0.75 0.75 scale 50 500 translate }
  930. X    ifelse
  931. X    /submonth 0 def
  932. X    calendar
  933. X    month 1 sub 0 eq
  934. X    {
  935. X        /lmonth 12 def
  936. X        /lyear year 1 sub def
  937. X    }
  938. X    {
  939. X        /lmonth month 1 sub def
  940. X        /lyear year def
  941. X    } ifelse
  942. X    month 1 add 13 eq
  943. X    {
  944. X        /nmonth 1 def
  945. X        /nyear year 1 add def
  946. X    } 
  947. X    {
  948. X        /nmonth month 1 add def
  949. X        /nyear year def
  950. X    } ifelse
  951. X    /savemonth month def
  952. X    /saveyear year def
  953. X    /submonth 1 def
  954. X    /savedatefontsize datefontsize def
  955. X    /year lyear def
  956. X    /month lmonth def
  957. X    /datefontsize 48 def
  958. X    gsave
  959. X    500 -365 translate
  960. X    gsave
  961. X    .138 .138 scale
  962. X    10 -120 translate
  963. X    calendar
  964. X    grestore
  965. X    /submonth 1 def
  966. X    /year nyear def
  967. X    /month nmonth def
  968. X    100 0 translate
  969. X    gsave
  970. X    .138 .138 scale
  971. X    10 -120 translate
  972. X    calendar
  973. X    grestore
  974. X    /month savemonth def
  975. X    /year saveyear def
  976. X    /submonth 0 def
  977. X    /datefontsize savedatefontsize def
  978. X    grestore
  979. } def
  980. X
  981. % Moon functions...
  982. X
  983. /doy {    % year month day doy -- returns the number of the day of the year
  984. X    /theday exch def
  985. X    /themonth exch def
  986. X    /theyear exch def
  987. X    /dayofyear 0 def
  988. X    themonth 1 ne {
  989. X        1 1 themonth .5 sub {
  990. X            /mo exch cvi def
  991. X            /dayofyear theyear mo
  992. X                ndays_2
  993. X                dayofyear add
  994. X                def
  995. X        } for
  996. X    } if
  997. X    dayofyear theday add
  998. } def
  999. X    
  1000. /findphase {
  1001. % Find the difference between any day and the reference day of the full moon
  1002. % Note: will probably be one off if the reference is a leap year
  1003. X    /thisday exch def  
  1004. X    /thismonth exch def
  1005. X    /thisyear exch def
  1006. X    /daysdiff thisyear thismonth thisday doy
  1007. X        fullyear fullmonth fullday doy sub 
  1008. X    longer mul def            % try to be accurate about it
  1009. X    /yearsdiff thisyear fullyear sub def
  1010. X    yearsdiff 0 ne {
  1011. X        /daysdiff daysdiff yearsdiff daysperyear mul
  1012. X            yearsdiff 100 idiv yearsdiff 400 idiv sub sub add def
  1013. X    } if
  1014. X    daysdiff            % return difference in days
  1015. } def
  1016. X
  1017. /shrink {
  1018. X    2 sqrt div
  1019. } def
  1020. X
  1021. /transmogrify {
  1022. % Take a real number and 'mod it down' so it is in the range 0->period or
  1023. % -period->0.  The 10000's preserve the accuracy.
  1024. X    10000 mul cvi
  1025. X    period 10000 mul cvi mod 10000 div
  1026. } def
  1027. X
  1028. /domoon {
  1029. % draw the moon at the current phase
  1030. X    /phase exch def
  1031. X
  1032. X    0 0 radius            % might as well push these on now
  1033. X    0 0 radius 
  1034. X    phase halfperiod lt {
  1035. X        270 90 arc stroke    % line on right, fill on left
  1036. X        0 radius neg moveto
  1037. X        270 90 arcn 
  1038. X    }
  1039. X    {
  1040. X        90 270 arc stroke    % line on left, fill on right
  1041. X        0 radius neg moveto
  1042. X        270 90 arc 
  1043. X        /phase phase halfperiod sub def  % get rid of top halfperiod
  1044. X    } ifelse
  1045. X
  1046. X    % scale it down to -r(root2) -> r(root2)
  1047. X    /phase phase quartperiod sub rect mul def
  1048. X
  1049. X    phase            % x1
  1050. X    phase abs shrink    % y1 need abs!
  1051. X    phase            % x2 
  1052. X    phase abs shrink neg    % y2 need abs!
  1053. X    0            % x3
  1054. X    radius neg        % y3 
  1055. X    curveto 
  1056. X    fill
  1057. } def
  1058. X
  1059. /do-moon-p {
  1060. X    draw-moons true eq {
  1061. X        true
  1062. X    }
  1063. X    {
  1064. X        draw-moons 4 eq {
  1065. X            /p startphase day longer mul add
  1066. X            % AWR: tweaked to more accurately select date of
  1067. X            %      new/half/full moons --
  1068. X            % transmogrify neg period add
  1069. X            0.5 sub transmogrify neg period add def
  1070. X            p  0.00 gt  p  1.00 lt and
  1071. X            p  7.38 gt  p  8.38 lt and or
  1072. X            p 14.76 gt  p 15.76 lt and
  1073. X            p 22.15 gt  p 23.15 lt and or
  1074. X            or
  1075. X        }
  1076. X        {
  1077. X             false
  1078. X        } ifelse
  1079. X    } ifelse
  1080. } def
  1081. X
  1082. X
  1083. /shiftdo {
  1084. X    do-moon-p {
  1085. X        /p startphase day longer mul add transmogrify neg period add def
  1086. X        p domoon
  1087. X    } if
  1088. } def
  1089. X
  1090. X
  1091. /drawmoons {
  1092. X    % The year/month/day combo below is that of a full moon.  Any date of a
  1093. X    % full moon should work, but I haven't tried very many.  I wouldn't
  1094. X    % make this reference date fall in a leap year, because wierdness will
  1095. X    % probably happen in findphase. You will probably gain or lose a day
  1096. X    % somewhere. -- MBH
  1097. X    /fullyear 1990 def
  1098. X    /fullmonth 2 def
  1099. X    /fullday 9 def
  1100. X
  1101. X    /period 29.5306 def
  1102. X    /daysperyear 365.2422 def
  1103. X    /longer daysperyear 365 div def
  1104. X    /halfperiod period 2 div def
  1105. X    /quartperiod period 4 div def
  1106. X    /radius 6 def
  1107. X    /rect radius 2 sqrt mul quartperiod div def
  1108. X    /startphase year month 0 findphase transmogrify dup 0 lt {
  1109. X        period add
  1110. X    } if def
  1111. X    /start startday def
  1112. X    /days year month ndays_2 def
  1113. X
  1114. X    gsave
  1115. X    0.1 setlinewidth
  1116. X    newpath
  1117. X    daywidth radius sub 3 sub 35 radius 3 add sub translate
  1118. X    start daywidth mul 0 translate
  1119. X        1 1 days {
  1120. X        /day exch def
  1121. X        shiftdo
  1122. X        day start add 1 sub 7 mod 6 eq {
  1123. X            daywidth 6 mul neg dayheight neg translate
  1124. X        }
  1125. X        {
  1126. X            daywidth 0 translate
  1127. X        } ifelse
  1128. X    } for
  1129. X    grestore
  1130. } def
  1131. SHAR_EOF
  1132. chmod 0644 pcalinit.ps ||
  1133. echo 'restore of pcalinit.ps failed'
  1134. Wc_c="`wc -c < 'pcalinit.ps'`"
  1135. test 11138 -eq "$Wc_c" ||
  1136.     echo 'pcalinit.ps: original size 11138, current size' "$Wc_c"
  1137. fi
  1138. exit 0
  1139.