home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume2 / cal.bs < prev    next >
Internet Message Format  |  1991-08-07  |  13KB

  1. From: wrv@ihlpm.UUCP (Vogel)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i098: personal postscript calendars
  4. Message-ID: <1839@ihlpm.ATT.COM>
  5. Date: 18 Apr 88 18:32:05 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. comp.sources.misc: Volume 2, Issue 98
  9. Submitted-By: "Vogel" <wrv@ihlpm.UUCP>
  10. Archive-Name: cal.bs
  11.  
  12. It prints fancy postscript calendars, however, it allows you to
  13. put your own appointments, etc. in for a given day.  In addition,
  14. it keeps track of changes you've made to your calendar file, and
  15. prints only updated calendar months.  You can run this program
  16. nightly or weekly with a cron or at job.
  17.  
  18. 8<-----8<-----8<-----8<----- < CUT HERE >----->8----->8----->8----->8
  19. #
  20. # cal.bs -> bs program to print personal calendars on postscript printers.
  21. #
  22. # This program looks in your home directory for your calendar file,
  23. # comparing it to a previously hidden copy.  Any months with items
  24. # changed will result in a calendar page being printed for that month.
  25. # It is possible and reasonable to run this program once a day/week
  26. # at 2:00am.  This first time you run it, it will print all calendar
  27. # pages for the current year.  The format of the .calendar file is
  28. # as follows:
  29. #
  30. #   first line should contain:
  31. #   year <whitespace> nnnn
  32. #
  33. #   subsequent lines contain entries as follows:
  34. #   MM/DD <whitespace> text of something happenning on that day.
  35. #
  36. #   example .calendar file:
  37. #   year    1988
  38. #   04/15    Tax day
  39. #   04/16    Darcie's birthday
  40. #   05/30    Memorial Day, party!
  41. #   07/01    My birthday
  42. #   07/04    Fourth of July, party!
  43. #
  44. # rules:
  45. #  1) blank lines are ignored, but no whitespace allowed at beginning of line.
  46. #  2) there can be more than one entry for a single day
  47. #  3) if there is more than one entry for a single day, they MUST
  48. #     appear sequentially in the file.  It is a good idea to keep the
  49. #     entries for a given month sorted.  Months should go sequentially too.
  50. #  4) If there are no entries for a given month, it won't be printed.
  51. #  5) You can specify months into the next year, however you can not
  52. #     specify more than a twelve month span.  I.E., if your first
  53. #     month's entry in the .calendar file is April, then you can fill every
  54. #     month until March of the next year.
  55. #
  56. # To run this program, first see instructions below on modifying the
  57. # thing to work in your environment (very easy).  Then type:
  58. #
  59. # bs cal.bs
  60. #
  61. # Thats it!  If you're system doesn't have bs, complain!  After all,
  62. # its been in UNIX since v7 and is a great language for this kind of
  63. # stuff.
  64. #
  65. # There may be bugs, I threw this together in a real hurry.  Please
  66. # let me know if you find any, and I'll try to fix 'em.
  67. #
  68. # Bill Vogel, AT&T BL, ...ihnp4!ihlpm!wrv
  69. #
  70. ########################################
  71. #
  72. # Here is the copyright on the original part of the postscript
  73. # code which is included in a modified form within this program.
  74. #
  75. # PostScript portion of this program to draw calendar ->
  76. #
  77. #   Copyright (C) 1987 by Pipeline Associates, Inc.
  78. #   Permission is granted to modify and distribute this free of charge.
  79. #
  80. ########################################
  81. #    
  82. # Things you need to modify:
  83. #
  84. # home  -> your home directory.
  85. # lpcmd -> the command line used which will accept standard input as
  86. #          raw postscript and print it on the local printer.
  87. #
  88. ########################################
  89. #                                      #
  90. # BEGIN LINES WHICH NEED MODIFICATION  #
  91. #                                      #
  92. ########################################
  93.  
  94. home  = "/x1/wrv"    # -> your home directory
  95.  
  96. lpcmd = "!lp -or"    # -> your local printer command for printing raw
  97.                         #    postscript.  Note that the '!' MUST be there.
  98.  
  99. ########################################
  100. #                                      #
  101. # END LINES WHICH NEED MODIFICATION    #
  102. #                                      #
  103. ########################################
  104. #
  105.  
  106. #
  107. # You can change these if you insist on changing the name of the
  108. # calendar file.
  109. #
  110. cf    = home_"/.calendar"
  111. ci    = home_"/.calendar.bak"
  112.  
  113. #
  114. #    pattern strings.  don't muckety-muck with these.
  115. #
  116. pstr1 = "\([0-9]*\)/\([0-9]*\)[     ]*\(.*\)"
  117. pstr2 = "year[     ]\([0-9]*\)"
  118.  
  119. #
  120. #    initialize month counters
  121. #
  122. for j = 1 12
  123.     mthcnt[j] = 0
  124.     altcnt[j] = 0
  125. next
  126. frstmo = -1
  127.  
  128. #
  129. #    parse the calendar file, break it up into an array
  130. #
  131. open("fdc", cf, "r")
  132. while ?(i = fdc)
  133.     if match(i, pstr1)
  134.         month = mstring(1)
  135.         if ( frstmo == -1 ) frstmo = month
  136.         x = mthcnt[month]
  137.         mdata[month, x, 1] = mstring(2)
  138.         mdata[month, x, 2] = mstring(3)
  139.         mthcnt[month] = x + 1
  140.     elif match(i, pstr2)
  141.         year = mstring(1)
  142.     fi
  143. next
  144. close("fdc")
  145.  
  146. #
  147. #    parse the backup calendar file.
  148. #
  149. if ?eval("open(\"fdi\", ci, \"r\")")
  150.     while ?(i = fdi)
  151.         if match(i, pstr1)
  152.             month = mstring(1)
  153.             x = altcnt[month]
  154.             altdata[month, x, 1] = mstring(2)
  155.             altdata[month, x, 2] = mstring(3)
  156.             altcnt[month] = x + 1
  157.         elif match(i, pstr2)
  158.             altyear = mstring(1)
  159.         fi
  160.     next
  161.     close("fdi")
  162. else
  163.     for j = 1 12
  164.         domonth[j] = 2
  165.     next
  166. fi
  167.  
  168. #
  169. #    now, go thru and compare months
  170. #
  171. for i = 1 12
  172.     if (altcnt[i] != mthcnt[i]) | (altyear != year)
  173.         domonth[i] = 1
  174.         continue
  175.     fi
  176.     if mthcnt[i]
  177.         for j = 0 mthcnt[i] -1
  178.             if mdata[i, j, 1] != altdata[i, j, 1]
  179.                 domonth[i] = 1
  180.                 continue
  181.             fi
  182.             if mdata[i, j, 2] != altdata[i, j, 2]
  183.                 domonth[i] = 1
  184.                 continue
  185.             fi
  186.         next
  187.     fi
  188. next
  189.  
  190. #
  191. #    make backup copy of the .calendar file.  This may do
  192. #    weird stuff if you don't keep your .calendar writeable or
  193. #    if you run with a funny umask.
  194. #
  195. open("command", "!cp "_cf_" "_ci, "w")
  196.         close("command")
  197.  
  198. #
  199. #    now, generate the postscript commands for each
  200. #    entry in the file.
  201. #
  202. beginm    =    frstmo
  203. header    =    0
  204. for j = 1 12
  205.     if (domonth[beginm] == 2) | (domonth[beginm] & mthcnt[beginm])
  206.         put = "printing month "_beginm_", year "_year
  207.         if (header == 0)
  208.             header = 1
  209.             open("lpout", lpcmd, "w")
  210.             pheader()
  211.         fi
  212.         pmonth(beginm)
  213.     fi
  214.     beginm = beginm + 1
  215.     if beginm > 12
  216.         beginm = 1
  217.         year = year + 1
  218.     fi
  219. next
  220. #
  221. #    close the output file
  222. #
  223. if ( header ) close("lpout")
  224.  
  225. #
  226. #    print the postscript commands for one month
  227. #
  228. fun pmonth(m)
  229.     lpout = "/year "_year_" def"
  230.     lpout = "/month "_m_" def"
  231.     lpout = "printmonth"
  232.     oldday = -1
  233.  
  234.     if ( mthcnt[m] == 0 )
  235.         lpout = "showpage"
  236.         return 0
  237.     fi
  238.     for i = 0 mthcnt[m] - 1
  239.         day = mdata[m, i, 1] # day
  240.         if day != oldday
  241.             if oldday == -1
  242.                 lpout = day_" [ "
  243.             else
  244.                 lpout = " ] daytext "_day_" [  "
  245.             fi
  246.             oldday = day
  247.         else
  248.             lpout = "(.p)"
  249.         fi
  250.         nb = 0
  251.         s = mdata[m, i, 2]   # text
  252.         while (n = match(s, "[     ]*\([^     ][^     ]*\)"))
  253.             lpout = "("_mstring(1)_")"
  254.             s = substr(s, n+1, 900)
  255.         next
  256.     next
  257.     lpout = "] daytext showpage clear"
  258. nuf
  259.  
  260. fun pheader()
  261.     lpout = "/titlefont /Times-Bold def"
  262.     lpout = "/dayfont /Helvetica-Bold def"
  263.     lpout = "/month_names [ (January) (February) (March) (April) (May) (June) (July)"
  264.     lpout = "        (August) (September) (October) (November) (December) ] def"
  265.     lpout = "/prtnum { 3 string cvs show} def"
  266.     lpout = "/drawgrid {        % draw calendar boxes"
  267.     lpout = "    dayfont findfont 10 scalefont setfont"
  268.     lpout = "    0 1 6 {"
  269.     lpout = "        dup dup 100 mul 40 moveto"
  270.     lpout = "        [ (Sunday) (Monday) (Tuesday) (Wednesday) (Thursday) (Friday) (Saturday) ] exch get"
  271.     lpout = "        100 center"
  272.     lpout = "        100 mul 35 moveto"
  273.     lpout = "        1.0 setlinewidth"
  274.     lpout = "        0 1 5 {"
  275.     lpout = "            gsave"
  276.     lpout = "            100 0 rlineto "
  277.     lpout = "            0 -80 rlineto"
  278.     lpout = "            -100 0 rlineto"
  279.     lpout = "            closepath stroke"
  280.     lpout = "            grestore"
  281.     lpout = "            0 -80 rmoveto"
  282.     lpout = "        } for"
  283.     lpout = "    } for"
  284.     lpout = "} def"
  285.     lpout = "/drawnums {        % place day numbers on calendar"
  286.     lpout = "    dayfont findfont 30 scalefont setfont"
  287.     lpout = "    /start startday def"
  288.     lpout = "    /days ndays def"
  289.     lpout = "    start 100 mul 5 add 10 rmoveto"
  290.     lpout = "    1 1 days {"
  291.     lpout = "        /day exch def"
  292.     lpout = "        gsave"
  293.     lpout = "        day start add 7 mod 1 eq"
  294.     lpout = "        {"
  295.     lpout = "            submonth 0 eq"
  296.     lpout = "            {"
  297.     lpout = "                .8 setgray"
  298.     lpout = "            } if"
  299.     lpout = "        } if"
  300.     lpout = "        day prtnum"
  301.     lpout = "        grestore"
  302.     lpout = "        day start add 7 mod 0 eq"
  303.     lpout = "        {"
  304.     lpout = "            currentpoint exch pop 80 sub 5 exch moveto"
  305.     lpout = "        }"
  306.     lpout = "        {"
  307.     lpout = "            100 0 rmoveto"
  308.     lpout = "        } ifelse"
  309.     lpout = "    } for"
  310.     lpout = "} def"
  311.     lpout = "/drawfill {        % place fill squares on calendar"
  312.     lpout = "    /start startday def"
  313.     lpout = "    /days ndays def"
  314.     lpout = "    0 35 rmoveto"
  315.     lpout = "    1.0 setlinewidth"
  316.     lpout = "    0 1 start 1 sub {"
  317.     lpout = "        gsave"
  318.     lpout = "        .9 setgray"
  319.     lpout = "        100 0 rlineto "
  320.     lpout = "        0 -80 rlineto"
  321.     lpout = "        -100 0 rlineto"
  322.     lpout = "        closepath fill"
  323.     lpout = "        grestore"
  324.     lpout = "        100 0 rmoveto"
  325.     lpout = "    } for"
  326.     lpout = "    submonth 1 eq"
  327.     lpout = "    {"
  328.     lpout = "        /lastday 42 def"
  329.     lpout = "        600 -365 moveto"
  330.     lpout = "    }"
  331.     lpout = "    {"
  332.     lpout = "        /lastday 40 def"
  333.     lpout = "        400 -365 moveto"
  334.     lpout = "    } ifelse"
  335.     lpout = "    lastday -1 ndays start 1 add add"
  336.     lpout = "    {"
  337.     lpout = "        /day exch def"
  338.     lpout = "        gsave"
  339.     lpout = "        .9 setgray"
  340.     lpout = "        100 0 rlineto "
  341.     lpout = "        0 -80 rlineto"
  342.     lpout = "        -100 0 rlineto"
  343.     lpout = "        closepath fill"
  344.     lpout = "        grestore"
  345.     lpout = "        day 7 mod 1 eq"
  346.     lpout = "        {"
  347.     lpout = "            600 -365 80 add moveto"
  348.     lpout = "        }"
  349.     lpout = "        {"
  350.     lpout = "            -100 0 rmoveto"
  351.     lpout = "        } ifelse"
  352.     lpout = "    } for"
  353.     lpout = "} def"
  354.     lpout = "/isleap {        % is this a leap year?"
  355.     lpout = "    year 4 mod 0 eq        % multiple of 4"
  356.     lpout = "    year 100 mod 0 ne     % not century"
  357.     lpout = "    year 1000 mod 0 eq or and    % unless it's a millenia"
  358.     lpout = "} def"
  359.     lpout = "/days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def"
  360.     lpout = "/ndays {        % number of days in this month"
  361.     lpout = "    days_month month 1 sub get"
  362.     lpout = "    month 2 eq    % Feb"
  363.     lpout = "    isleap and"
  364.     lpout = "    {"
  365.     lpout = "        1 add"
  366.     lpout = "    } if"
  367.     lpout = "} def"
  368.     lpout = "/startday {        % starting day-of-week for this month"
  369.     lpout = "    /off year 2000 sub def    % offset from start of epoch"
  370.     lpout = "    off"
  371.     lpout = "    off 4 idiv add        % number of leap years"
  372.     lpout = "    off 100 idiv sub    % number of centuries"
  373.     lpout = "    off 1000 idiv add    % number of millenia"
  374.     lpout = "    6 add 7 mod 7 add     % offset from Jan 1 2000"
  375.     lpout = "    /off exch def"
  376.     lpout = "    1 1 month 1 sub {"
  377.     lpout = "        /idx exch def"
  378.     lpout = "        days_month idx 1 sub get"
  379.     lpout = "        idx 2 eq"
  380.     lpout = "        isleap and"
  381.     lpout = "        {"
  382.     lpout = "            1 add"
  383.     lpout = "        } if"
  384.     lpout = "        /off exch off add def"
  385.     lpout = "    } for"
  386.     lpout = "    off 7 mod        % 0--Sunday, 1--monday, etc."
  387.     lpout = "} def"
  388.     lpout = "/center {        % center string in given width"
  389.     lpout = "    /width exch def"
  390.     lpout = "    /str exch def width str "
  391.     lpout = "    stringwidth pop sub 2 div 0 rmoveto str show"
  392.     lpout = "} def"
  393.     lpout = "/calendar"
  394.     lpout = "{"
  395.     lpout = "    titlefont findfont 48 scalefont setfont"
  396.     lpout = "    0 60 moveto"
  397.     lpout = "    /month_name month_names month 1 sub get def"
  398.     lpout = "    month_name show"
  399.     lpout = "    /yearstring year 10 string cvs def"
  400.     lpout = "    700 yearstring stringwidth pop sub 60 moveto"
  401.     lpout = "    yearstring show"
  402.     lpout = "    0 0 moveto"
  403.     lpout = "    drawnums"
  404.     lpout = "    0 0 moveto"
  405.     lpout = "    drawfill"
  406.     lpout = "    0 0 moveto"
  407.     lpout = "    drawgrid"
  408.     lpout = "} def"
  409.     lpout = "/daytext {"
  410.     lpout = "    /Helvetica-Narrow findfont 6 scalefont setfont"
  411.     lpout = "    /mytext    exch def /myday exch def"
  412.     lpout = "    startday myday 1 sub add dup 7 mod 100 mul 5 add % gives column"
  413.     lpout = "    exch 7 idiv -80 mul % gives row"
  414.     lpout = "    dup /ypos exch def moveto"
  415.     lpout = "    /LM currentpoint pop def /RM LM 95 add def"
  416.     lpout = "        mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall"
  417.     lpout = "} def"
  418.     lpout = "/crlf {"
  419.     lpout = "    ypos 8 sub /ypos exch def LM ypos moveto"
  420.     lpout = "} def"
  421.     lpout = "/prstr {"
  422.     lpout = "    dup stringwidth pop currentpoint pop"
  423.     lpout = "    add RM gt {crlf} if show"
  424.     lpout = "} def"
  425.     lpout = "/printmonth {"
  426.     lpout = "    90 rotate"
  427.     lpout = "    50 -120 translate"
  428.     lpout = "    /submonth 0 def"
  429.     lpout = "    calendar"
  430.     lpout = "    month 1 sub 0 eq"
  431.     lpout = "    {"
  432.     lpout = "        /lmonth 12 def"
  433.     lpout = "        /lyear year 1 sub def"
  434.     lpout = "    }"
  435.     lpout = "    {"
  436.     lpout = "        /lmonth month 1 sub def"
  437.     lpout = "        /lyear year def"
  438.     lpout = "    } ifelse"
  439.     lpout = "    month 1 add 13 eq"
  440.     lpout = "    {"
  441.     lpout = "        /nmonth 1 def"
  442.     lpout = "        /nyear year 1 add def"
  443.     lpout = "    } "
  444.     lpout = "    {"
  445.     lpout = "        /nmonth month 1 add def"
  446.     lpout = "        /nyear year def"
  447.     lpout = "    } ifelse"
  448.     lpout = "    /savemonth month def"
  449.     lpout = "    /saveyear year def"
  450.     lpout = "    /submonth 1 def"
  451.     lpout = "    /year lyear def"
  452.     lpout = "    /month lmonth def"
  453.     lpout = "    gsave"
  454.     lpout = "    500 -365 translate"
  455.     lpout = "    gsave"
  456.     lpout = "    .138 .138 scale"
  457.     lpout = "    10 -120 translate"
  458.     lpout = "    calendar"
  459.     lpout = "    grestore"
  460.     lpout = "    /submonth 1 def"
  461.     lpout = "    /year nyear def"
  462.     lpout = "    /month nmonth def"
  463.     lpout = "    100 0 translate"
  464.     lpout = "    gsave"
  465.     lpout = "    .138 .138 scale"
  466.     lpout = "    10 -120 translate"
  467.     lpout = "    calendar"
  468.     lpout = "    grestore"
  469.     lpout = "    /month savemonth def"
  470.     lpout = "    /year saveyear def"
  471.     lpout = "    /submonth 0 def"
  472.     lpout = "    grestore"
  473.     lpout = "} def"
  474. nuf
  475.  
  476. run
  477. exit
  478.