home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / calgen / part01 < prev    next >
Encoding:
Text File  |  1992-12-06  |  9.0 KB  |  452 lines

  1. Newsgroups: comp.sources.misc
  2. From: tonyt@cimsim.berkeley.edu (Tony Tam)
  3. Subject:  v34i006:  calgen - postscript calendar generator, Part01/01
  4. Message-ID: <1992Dec6.042142.26137@sparky.imd.sterling.com>
  5. X-Md4-Signature: 604a5b283910c8e93bb8978f76075e92
  6. Date: Sun, 6 Dec 1992 04:21:42 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tonyt@cimsim.berkeley.edu (Tony Tam)
  10. Posting-number: Volume 34, Issue 6
  11. Archive-name: calgen/part01
  12. Environment: UNIX, PostScript
  13.  
  14. During my spare time, I was playing around with the Postscript language and
  15. all I got out of it at the time was a postscript file that generated a calendar
  16. for any month of any year.
  17.  
  18. Here is a file that outputs a nice calendar that you always wanted (smile). 
  19. unshar the text below to generate a file call 'calgen' and 'chmod +x calgen'.
  20.  
  21. Type 'calgen' and it will output a postscript file with commands to draw 
  22. a nice calendar.  Try the nice graphics backgound with the '-g' option.
  23.  
  24. Tony.
  25. --------<cut here>---------------------------------------------------------
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then feed it
  28. # into a shell via "sh file" or similar.  To overwrite existing files,
  29. # type "sh file -c".
  30. # Contents:  calgen
  31. # Wrapped by kent@sparky on Sun Nov 29 15:49:16 1992
  32. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  33. echo If this archive is complete, you will see the following message:
  34. echo '          "shar: End of archive 1 (of 1)."'
  35. if test -f 'calgen' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'calgen'\"
  37. else
  38.   echo shar: Extracting \"'calgen'\" \(6621 characters\)
  39.   sed "s/^X//" >'calgen' <<'END_OF_FILE'
  40. X#! /bin/sh
  41. X# Tony Tam - 1991
  42. X#
  43. X# calgen - Version 1.0.6 3/2/91
  44. X# generate a calendar in postscript and send the output to the standard output
  45. X#
  46. X# To print it out: "calgen | lpr"
  47. X#
  48. X#Usage: calgen [-g #] [-h] [month] [year]
  49. X#
  50. X#    -h:        for help
  51. X#    -g [0-2]:    graphics to be used in background, 0 for none [0-2]
  52. X#    month:       month of the calendar (optional) [1-12]
  53. X#    year:        year of the calendar, month has to be set also
  54. X#example:
  55. X#    calgen            ; for the current month of the current year
  56. X#       calgen 11        ; for November of the current year
  57. X#    calgen -g 1 4 1991    ; for April 1991
  58. X#    calgen -g 2 4        ; for April of the current year
  59. X#
  60. X#
  61. Xprint_usage () {
  62. X    echo "" >&2
  63. X    echo "Usage: `basename $0` [-g #] [-h] [month] [year]" >&2
  64. X    echo "" >&2
  65. X    echo "    -h:        for help"
  66. X    echo "    -g [0-2]:    graphics to be used in background, 0 for none [0-2]">&2
  67. X    echo "    month:       month of the calendar (optional) [1-12]" >& 2
  68. X    echo "    year:        year of the calendar, month has to be set also" >&2
  69. X    echo "example:" >&2
  70. X    echo "    `basename $0`            ; for the current month of the current year"
  71. X    echo "    `basename $0` 12        ; for December  of the current year"
  72. X    echo "    `basename $0` -g 1 4 1991    ; for April 1991"
  73. X    echo "    `basename $0` -g 2 4        ; for April of the current year"
  74. X    echo "" >&2
  75. X    exit 1
  76. X}
  77. X
  78. XGRAPHICS="circles_round_round"
  79. X
  80. Xcase $1 in
  81. X    "-g")    
  82. X        case $2 in
  83. X            0)    GRAPHICS=""
  84. X                ;;
  85. X            1)    GRAPHICS="circles_round_round"
  86. X                ;;
  87. X            *)    GRAPHICS="sine_curve"    
  88. X                ;;
  89. X        esac
  90. X        shift; shift
  91. X        ;;
  92. X    "-h")
  93. X        print_usage;
  94. X        ;;
  95. Xesac
  96. X
  97. X[ $# -gt 2 ] && {
  98. X    print_usage;
  99. X}
  100. X
  101. X
  102. X
  103. XMONTH=${1:-"`date +%m`"}
  104. XYEAR=${2:-"19`date +%y`"}
  105. X
  106. X([ $MONTH -gt 12 ] || [ $MONTH -lt 1 ]) && {
  107. X    echo "`basename $0`: illegal 'month' " >&2
  108. X    print_usage;
  109. X    exit 2
  110. X}
  111. X
  112. X[ "$YEAR" = "" ] && {
  113. X    echo "`basename $0`: illegal 'year' " >&2
  114. X    print_usage;
  115. X    exit 2
  116. X}
  117. X
  118. X#
  119. X# here is where we dive into postscript
  120. X#
  121. Xcat <<~~~~
  122. X%!PS-Adobe-1.0
  123. X% Written by Tony Tam - Nothing is copyrighted
  124. X%
  125. X% creates a nice looking calendar with date and month
  126. X%
  127. X
  128. X/end_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
  129. X/month_arr [ (January ${YEAR}) (February ${YEAR}) 
  130. X         (March ${YEAR}) (April ${YEAR}) (May ${YEAR}) (June ${YEAR}) 
  131. X         (July ${YEAR}) (August ${YEAR})
  132. X         (September ${YEAR}) (October ${YEAR}) 
  133. X         (November ${YEAR}) (December ${YEAR}) ] def
  134. X
  135. X/inch { 72 mul } def
  136. X
  137. X/x_max 8.5 inch   def        % max width of paper
  138. X/y_max 11 inch   def        % max height of paper
  139. X
  140. X
  141. X/dow {                % returns the day of the week
  142. X                % date, month, year
  143. X    /yr exch def
  144. X    /month exch def
  145. X    /date exch def
  146. X    month 2 le { 
  147. X        /month month 12 add def
  148. X        /yr yr 1 sub def
  149. X    } if
  150. X    /n1 month 1 add 26 mul 10 idiv def
  151. X    /n2 125 yr mul 100 idiv def
  152. X    /day date n1 add n2 add yr 100 idiv sub yr 400 idiv add 
  153. X             1 sub cvi 7 mod 1 add def
  154. X} def
  155. X
  156. X1 ${MONTH} ${YEAR} dow
  157. X/start_col day def             % the column of the 1st of the month
  158. X/end_date end_month ${MONTH} 1 sub get def    % last day of the month
  159. X/month_str month_arr ${MONTH} 1 sub get def         % need the parentheses
  160. X
  161. X% nice looking curve background curve
  162. X
  163. X/sine_curve
  164. X{
  165. X    gsave
  166. X
  167. X    /sineCurve
  168. X    {
  169. X        72 72 72 -72 288 0 curveto
  170. X    } def
  171. X
  172. X    x_max 2 div .5 inch add y_max 2 div translate
  173. X    .8 .8 scale
  174. X    .99 setgray
  175. X    3 setlinewidth
  176. X    newpath
  177. X    2 {
  178. X        24 {
  179. X        0 0 moveto
  180. X            sineCurve
  181. X            360 24 div rotate
  182. X        } repeat
  183. X        -1.0 1.0 scale
  184. X    } repeat
  185. X    stroke
  186. X
  187. X    1 setgray
  188. X    0 0 10 0 360 arc fill
  189. X    grestore
  190. X} def
  191. X
  192. X
  193. X/circles_round_round {
  194. X%%%% {x-center}{y-center} {radius} circle
  195. X/circle {
  196. X    0 360 arc 
  197. X} def
  198. X
  199. X/xMid x_max 2 div def
  200. X/yMid y_max 2 div def
  201. X
  202. XxMid yMid moveto
  203. Xgsave
  204. X/Radius 1 inch def
  205. X/Num 15 def
  206. X/Angle 360 Num div def
  207. X
  208. X.95 setgray
  209. Xnewpath
  210. XxMid yMid translate
  211. XNum {
  212. X    Radius 0 Radius circle        % draw the circle
  213. X    Angle rotate
  214. X} repeat
  215. Xstroke
  216. Xclosepath
  217. Xgrestore
  218. X} def                %% circles_round_round
  219. X
  220. X/font                % size, font (set the font)
  221. X{
  222. X    findfont exch scalefont setfont
  223. X} def 
  224. X
  225. X/x_value            % x value given a point
  226. X{
  227. X    pop
  228. X} def
  229. X
  230. X/y_value            % y value given a point
  231. X{
  232. X    exch
  233. X    pop
  234. X} def
  235. X
  236. X/center_text            % string
  237. X{
  238. X    dup
  239. X        currentpoint x_value
  240. X        exch
  241. X            1 setgray
  242. X            10 exch 0 exch ashow
  243. X            0 setgray
  244. X        currentpoint x_value
  245. X        exch
  246. X        sub
  247. X        dup
  248. X        neg
  249. X        0 rmoveto
  250. X        2
  251. X        div
  252. X        neg
  253. X        0
  254. X        rmoveto
  255. X
  256. X    /_str_ exch def
  257. X    currentpoint
  258. X    2 2 neg rmoveto
  259. X    .3 setgray
  260. X    _str_ 10 exch 0 exch ashow
  261. X    0 setgray
  262. X    moveto
  263. X    _str_ 10 exch 0 exch ashow
  264. X} def
  265. X
  266. X/landscape            % change to lanscape mode
  267. X{
  268. X     x_max 0 translate
  269. X     90 rotate
  270. X     x_max             % save x_max
  271. X     /x_max y_max def
  272. X     /y_max exch def        % set y_max = x_max on stack
  273. X}   def
  274. X
  275. X/box                % draw a box given the corners    
  276. X{
  277. X    /y1 exch def
  278. X    /x1 exch def
  279. X    /y2 exch def
  280. X    /x2 exch def
  281. X
  282. X    newpath
  283. X    x1 y1 moveto
  284. X    x1 y2 lineto
  285. X    x2 y2 lineto
  286. X    x2 y1 lineto
  287. X    closepath
  288. X} def
  289. X
  290. X/fillbox { box gsave fill grestore } def
  291. X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  292. X% LET'S GET STARTED
  293. X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  294. X${GRAPHICS}
  295. X
  296. X/min_border {.5 inch .25 inch }  def
  297. X/max_border 
  298. X{
  299. X      x_max .5 inch sub 
  300. X      y_max 1.25 inch sub 
  301. X}  def
  302. X
  303. Xlandscape
  304. X
  305. Xgsave
  306. Xmin_border translate
  307. X
  308. X/border_y max_border y_value min_border y_value sub  def
  309. X/border_x max_border x_value min_border x_value sub  def
  310. X/hor_dist border_x 7 div  def
  311. X/ver_dist border_y 5 div  def
  312. X
  313. X
  314. X%box and date
  315. X
  316. X/date_show        % date, x, y 
  317. X{
  318. X      .2 inch sub
  319. X      exch
  320. X      .22 inch sub
  321. X      exch 
  322. X    moveto
  323. X    gsave
  324. X      1 setgray
  325. X      3 string cvs show
  326. X    grestore
  327. X} def
  328. X
  329. Xgsave
  330. X
  331. X.3 setgray
  332. X
  333. X16 /Times-Roman font
  334. X/_day_ 1 def
  335. X/_y border_y def
  336. X/first_col start_col def
  337. X
  338. X1 1 5 {
  339. X    hor_dist first_col mul hor_dist border_x 
  340. X    {
  341. X         _day_ end_date le 
  342. X         {
  343. X        /_x exch def
  344. X          _x
  345. X          _y
  346. X          _x .25 inch sub
  347. X          _y .25 inch sub
  348. X        fillbox
  349. X        stroke
  350. X
  351. X        _day_ _x _y date_show
  352. X        /_day_ _day_ 1 add def
  353. X         } if
  354. X    } for
  355. X    /first_col 1 def
  356. X    /_y _y ver_dist sub def
  357. X} for    
  358. X
  359. X0 setgray
  360. X/_y border_y def
  361. Xhor_dist 
  362. Xhor_dist 
  363. Xhor_dist end_date _day_ sub 1 add mul {
  364. X
  365. X        /_x exch def
  366. X          _x
  367. X          _y
  368. X          _x .25 inch sub
  369. X          _y .25 inch sub
  370. X        fillbox
  371. X        stroke
  372. X
  373. X        _day_ _x _y date_show
  374. X        /_day_ _day_ 1 add def
  375. X} for
  376. X
  377. Xgrestore
  378. X
  379. X
  380. X% draw header
  381. X18 /Times-Roman font
  382. Xgsave
  383. X    gsave
  384. X        0 setgray
  385. X        30 /Times-Roman font
  386. X        border_x 2 div border_y 28 add moveto
  387. X        month_str center_text
  388. X    grestore
  389. X
  390. X    %%% top block
  391. X       0 border_y 
  392. X       border_x border_y 24 add
  393. X    box
  394. X    gsave fill grestore
  395. X    stroke
  396. X
  397. X    1 setgray
  398. X    hor_dist 2 div 9 sub border_y 2 add moveto
  399. X    hor_dist 12 sub 0 (SMTWTFS) ashow
  400. Xgrestore
  401. X      
  402. X
  403. X% vertical grids
  404. X
  405. X1 1 6 {
  406. X     hor_dist mul /__lnStart__ exch def
  407. X     __lnStart__ 0 moveto
  408. X     0 border_y rlineto stroke
  409. X  } for
  410. X
  411. X% horizontal grids
  412. X
  413. X1 1 4 {
  414. X     ver_dist mul /__lnStart__ exch def
  415. X     0 __lnStart__ moveto
  416. X     border_x 0 rlineto stroke
  417. X  } for
  418. X
  419. Xgrestore
  420. X
  421. X   min_border
  422. X   max_border
  423. Xbox
  424. Xstroke
  425. X
  426. Xshowpage
  427. X~~~~
  428. END_OF_FILE
  429.   if test 6621 -ne `wc -c <'calgen'`; then
  430.     echo shar: \"'calgen'\" unpacked with wrong size!
  431.   fi
  432.   chmod +x 'calgen'
  433.   # end of 'calgen'
  434. fi
  435. echo shar: End of archive 1 \(of 1\).
  436. cp /dev/null ark1isdone
  437. MISSING=""
  438. for I in 1 ; do
  439.     if test ! -f ark${I}isdone ; then
  440.     MISSING="${MISSING} ${I}"
  441.     fi
  442. done
  443. if test "${MISSING}" = "" ; then
  444.     echo You have the archive.
  445.     rm -f ark[1-9]isdone
  446. else
  447.     echo You still must unpack the following archives:
  448.     echo "        " ${MISSING}
  449. fi
  450. exit 0
  451. exit 0 # Just in case...
  452.