home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume02 / cal.bs < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  13.2 KB

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