home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8712 / 6 < prev    next >
Encoding:
Internet Message Format  |  1990-07-13  |  5.5 KB

  1. Path: uunet!husc6!necntc!ncoast!allbery
  2. From: neilc@dmscanb.oz.au.UUCP (Neil Crellin)
  3. Newsgroups: comp.sources.misc
  4. Subject: PScal - PostScript Calendar generator: leap year bug fixed
  5. Message-ID: <6404@ncoast.UUCP>
  6. Date: 11 Dec 87 02:33:43 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Organization: CSIRO Division of Mathematics and Statistics
  9. Lines: 245
  10. Approved: allbery@ncoast.UUCP
  11. X-Archive: comp.sources.misc/8712/6
  12.  
  13. Dear Brandon,
  14.  
  15. Could this possibly be suitable for comp.sources.misc ? It was once
  16. a net.sources submission, which has been hacked about a little.
  17.  
  18. Some time ago, this really useful shell script to print a PostScript
  19. calendar was sent to net.sources. Unfortunately, it had a bug in the
  20. PostScript which meant that the calendar was wrong for leap years,
  21. certainly for Feb. 1988 onwards. It's short enough that rather than
  22. just post the diffs, I've re-sent the whole script, which here at dmscanb
  23. we call PScal. 
  24.  
  25.   Syntax is: PScal <month> <year>
  26.   eg.        PScal 2 1988
  27.  
  28. You should change the default printer variable below. It is set at -Plaser
  29. currently.
  30.  
  31. Regards,
  32.     Neil Crellin (neilc@dmscanb.dms.oz.au)
  33.  
  34. =-=-=-=-=-=-=-=-=-=-=-(cut here - this is not a shar)-=-=-=-=-=-=-=-=-=-=-=
  35. #!/bin/csh -f
  36. #
  37. # From: patwood@unirot.UUCP (Patrick Wood)
  38. # Newsgroups: net.sources
  39. # Subject: PostScript Calendar
  40. # Date: 7 Mar 87 18:43:51 GMT
  41. # Organization: Public Access Unix, Piscataway, NJ
  42. # The following is a PostScript program to print calendars.  It doesn't
  43. # work on or before 1752.
  44. # Shell stuff added 3/9/87 by King Ables
  45. # Leap year bug fixed Dec. 4th, 1987 by Neil Crellin (neilc@dmscanb.dms.oz.au)
  46. #
  47. set printer="-Plaser"
  48.  
  49. top:
  50. if ($#argv > 0) then
  51.     switch ("$argv[1]")
  52.         case -*:
  53.             set printer="$argv[1]"
  54.             shift argv
  55.             goto top
  56.         case *:
  57.             if ($?month) then
  58.                 set year="$argv[1]"
  59.             else if ($?year) then
  60.                 echo "usage: $0 [-Pprinter] month year"
  61.                 exit 1
  62.             else
  63.                 set month="$argv[1]"
  64.             endif
  65.             shift argv
  66.             goto top
  67.     endsw
  68. endif
  69.  
  70. if ($?year) then
  71. else 
  72.     echo "usage: $0 [-Pprinter] month year"
  73.     exit 1
  74. endif
  75.  
  76. lpr $printer <<END-OF-CALENDAR
  77. %!
  78. % PostScript program to draw calendar
  79. % Copyright (C) 1987 by Pipeline Associates, Inc.
  80. % Permission is granted to modify and distribute this free of charge.
  81.  
  82. % /month should be set to a number from 1 to 12
  83. % /year should be set to the year you want
  84. % you can change the title and date fonts, if you want
  85. % we figure out the rest
  86. % won't produce valid calendars before 1800 (weird stuff happened
  87. % in September of 1752)
  88.  
  89. /month $month def
  90. /year $year def
  91. /titlefont /Times-Bold def
  92. /dayfont /Helvetica-Bold def
  93.  
  94. /month_names [ (January) (February) (March) (April) (May) (June) (July)
  95.         (August) (September) (October) (November) (December) ] def
  96. /month_name month_names month 1 sub get def
  97.  
  98. /prtnum { 3 string cvs show} def
  99.  
  100. /drawgrid {        % draw calendar boxes
  101.     dayfont findfont 10 scalefont setfont
  102.     0 1 6 {
  103.         dup dup 100 mul 40 moveto
  104.         [ (Sun) (Mon) (Tue) (Wed) (Thu) (Fri) (Sat) ] exch get
  105.         90 center
  106.         100 mul 38 moveto
  107.         .5 setlinewidth
  108.         60 {
  109.             gsave
  110.             90 0 rlineto stroke
  111.             grestore
  112.             0 -10 rmoveto
  113.         } repeat
  114.     } for
  115.  
  116. } def
  117.  
  118. /drawnums {        % place day numbers on calendar
  119.     dayfont findfont 40 scalefont setfont
  120.     /start startday def
  121.     /days ndays def
  122.     start 100 mul 0 rmoveto
  123.     1 1 days {
  124.         /day exch def
  125.         gsave
  126.           isdouble
  127.           {
  128.             day prtdouble
  129.           }
  130.           {
  131.             day prtnum
  132.           } ifelse
  133.         grestore
  134.         day start add 7 mod 0 eq
  135.         {
  136.             currentpoint exch pop 100 sub 0 exch moveto
  137.         }
  138.         {
  139.             100 0 rmoveto
  140.         } ifelse
  141.     } for
  142. } def
  143.  
  144. /isdouble {        % is today going to be overlaid on next week's?
  145.     days start add 35 gt
  146.     {
  147.         day start add 35 gt
  148.         {
  149.             true true
  150.         }
  151.         {
  152.             day start add 28 gt
  153.             day 7 add days le and
  154.             {
  155.                 false true
  156.             }
  157.             {
  158.                 false
  159.             } ifelse
  160.         } ifelse
  161.     }
  162.     {
  163.         false
  164.     } ifelse
  165. } def
  166.  
  167. /prtdouble {
  168.     gsave
  169.       dayfont findfont 20 scalefont setfont
  170.       exch
  171.       {
  172.         30 100 rmoveto
  173.         prtnum
  174.       }
  175.       {
  176.         0 12 rmoveto
  177.         prtnum
  178.         0 -12 rmoveto
  179.         gsave
  180.           dayfont findfont 40 scalefont setfont
  181.           (/) show
  182.         grestore
  183.       } ifelse
  184.     grestore
  185. } def
  186.  
  187. /isleap {        % is this a leap year?
  188.     year 4 mod 0 eq        % multiple of 4
  189.     year 100 mod 0 ne     % not century
  190.     year 1000 mod 0 eq or and    % unless it's a millenia
  191. } def
  192.  
  193. /days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
  194.  
  195. /ndays {        % number of days in this month
  196.     days_month month 1 sub get
  197.     month 2 eq    % Feb
  198.     isleap and
  199.     {
  200.         1 add
  201.     } if
  202. } def
  203.  
  204. /startday {        % starting day-of-week for this month
  205.     /off year 2000 sub def    % offset from start of "epoch"
  206.     off
  207.     off 4 idiv add        % number of leap years
  208.     off 100 idiv sub    % number of centuries
  209.     off 1000 idiv add    % number of millenia
  210.     6 add 7 mod 7 add     % offset from Jan 1 2000
  211.     /off exch def
  212.     1 1 month 1 sub {
  213.                 1 copy
  214.         days_month exch 1 sub get
  215.         exch 2 eq
  216.         isleap and
  217.         {
  218.             1 add
  219.         } if
  220.         /off exch off add def
  221.     } for
  222.     off 7 mod        % 0--Sunday, 1--monday, etc.
  223. } def
  224.  
  225. /center {        % center string in given width
  226.     /width exch def
  227.     /str exch def width str 
  228.     stringwidth pop sub 2 div 0 rmoveto str show
  229. } def
  230.  
  231. 90 rotate
  232. 50 -120 translate
  233.  
  234. titlefont findfont 48 scalefont setfont
  235. 0 60 moveto
  236. month_name show
  237. /yearstring year 10 string cvs def
  238. 700 yearstring stringwidth pop sub 60 moveto
  239. yearstring show
  240.  
  241. 0 0 moveto
  242. drawnums
  243.  
  244. 0 0 moveto
  245. drawgrid
  246.  
  247. showpage
  248.  
  249.  
  250. END-OF-CALENDAR
  251. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=(cut here too)=-=-=-=-=-=-=-=-=-=-=-=-=-=
  252. Neil Crellin, CSIRO Division of Mathematics and Statistics, 
  253. GPO Box 1965, Canberra, ACT 2601, Australia.  PHONE:    +61 62 818 529
  254. ACSNET:    neilc@dmscanb.oz    ARPA: neilc%dmscanb.oz@uunet.uu.net
  255. UUCP:    ....{uunet,hplabs,mcvax,ukc,nttlab}!munnari!dmscanb.oz!neilc
  256.