home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1603 < prev    next >
Text File  |  1990-12-28  |  67KB  |  2,251 lines

  1. Newsgroups: alt.sources
  2. From: goer@sophist.uucp (Richard Goerwitz)
  3. Subject: Jewish/Civil calendar, part 02 of 03
  4. Message-ID: <1990Jul20.001037.4499@midway.uchicago.edu>
  5. Date: Fri, 20 Jul 90 00:10:37 GMT
  6.  
  7. In article <1990Jul20.000900.4359@midway.uchicago.edu> goer@sophist.UUCP (Richard Goerwitz) writes:
  8. >
  9. >This is an experimental posting of a Unix port of an MS-DOS program
  10. >written in Icon.  Icon, for those who do not know, is the successor
  11. >language to Snobol (in fact SL5).  It retains great string handling
  12. >facilities of Snobol, and yet possesses a fully procedural structure.
  13. >It also incorporates data structures such as hash tables and linked
  14. >lists, and provides builtin garbage collection, like most dialects
  15. >of Lisp.  I personally use it for natural language processing, but
  16. >it can also be used for rapid prototying of almost anything except
  17. >low-level bit manipulation and systems programming jobs.  It is popu-
  18. >lar among people doing all varieties of nonnumeric computing.
  19. >
  20. >The program itself - yes, by Jove, there is a program here - is a
  21. >Jewish/Civil calendar display utility.  Lets you view corresponding
  22. >dates for both calendars on screen simultaneously.  I've never un-
  23. >derstood the Jewish calendar, and this seemed a good excuse to learn
  24. >all the month names.  My real reason for porting it was that it was
  25. >the first piece of software posted to comp.lang.icon that seemed a
  26. >good way of testing my rough port of the C/Unix termlib library to
  27. >Icon.  I thank Alan Corre (the original author) for permitting me to
  28. >(ab)use the original MS-DOS program in this way.
  29. >
  30. >Anyone who does not have Icon is without excuse, since it is free,
  31. >and available for many, many popular micros, minis, and some main-
  32. >frames.  Just about anything that calls itself -nix can run Icon
  33. >(Unix, Xenix, etc.).  Ftp it from cs.arizona.edu if you find your
  34. >curiosity aroused, and don't already have it installed.
  35. >
  36. >   -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  37. >   goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  38. >
  39. >
  40. >---- Cut Here and unpack ----
  41. >#!/bin/sh
  42. ># This is a shell archive (shar 3.24)
  43. ># made 07/19/1990 22:27 UTC by goer@sophist.uchicago.edu
  44. ># Source directory /u/richard/Hebcalen
  45. >#
  46. ># existing files WILL be overwritten
  47. ># This format requires very little intelligence at unshar time.
  48. ># "echo" and "sed" will be needed.
  49. >#
  50. ># This is part 1 of a multipart archive                                    
  51. ># do not concatenate these parts, unpack them in order with /bin/sh        
  52. >#
  53. ># This shar contains:
  54. ># length  mode       name
  55. ># ------ ---------- ------------------------------------------
  56. >#  23020 -r--r--r-- hebcalen.src
  57. >#  11276 -r--r--r-- itlib.icn
  58. >#   4008 -rw-r--r-- hebcalen.hlp
  59. >#   6490 -rw-r--r-- hebcalen.dat
  60. >#   2475 -rw-r--r-- README
  61. >#   1654 -rw-r--r-- Makefile.dist
  62. >#  29360 -rw-r--r-- cal.text
  63. >#
  64. >if test -r shar3_seq_.tmp; then
  65. >    echo "Must unpack archives in sequence!"
  66. >    next=`cat shar3_seq_.tmp`; echo "Please unpack part $next next"
  67. >    exit 1
  68. >fi
  69. ># ============= hebcalen.src ==============
  70. >echo "x - extracting hebcalen.src (Text)"
  71. >sed 's/^X//' << 'SHAR_EOF' > hebcalen.src &&
  72. >X##########################################################################
  73. >X#
  74. >X#    NAME:   hebcalen.icn
  75. >X#
  76. >X#    TITLE:  Combination Jewish/Civil calendar
  77. >X#
  78. >X#    AUTHOR: Alan D. Corre (ported to Unix by Richard Goerwitz)   
  79. >X#
  80. >X#    DATE:   7/19/90 (version 1.11)
  81. >X#
  82. >X##########################################################################
  83. >X#
  84. >X#  COPYRIGHT (c) 1990, Alan D. Corre
  85. >X#
  86. >X#  Permission is hereby given to all persons to copy, compile and pass
  87. >X#  to others this code provided that (1) it is not used for monetary
  88. >X#  gain; (2) it is not subverted from its original purpose, and is
  89. >X#  changed only to the extent necessary to make it work on a different
  90. >X#  computer or terminal.  No guarantees are given or implied as to the
  91. >X#  correctness of information furnished by this program.
  92. >X#
  93. >X##########################################################################
  94. >X#
  95. >X#  This work is respectfully devoted to the authors of two books
  96. >X#  consulted with much profit: "A Guide to the Solar-Lunar Calendar"
  97. >X#  by B. Elihu Rothblatt published by our sister Hebrew Dept. in
  98. >X#  Madison, Wis., and "Kiddush HaHodesh" by Rabbenu Moses ben Maimon,
  99. >X#  on whom be peace.
  100. >X#
  101. >X#  The Jewish year harmonizes the solar and lunar cycle, using the
  102. >X#  19-year cycle of Meton (c. 432 BCE). It corrects so that certain
  103. >X#  dates shall not fall on certain days for religious convenience. The
  104. >X#  Jewish year has six possible lengths, 353, 354, 355, 383, 384, and
  105. >X#  385 days, according to day and time of new year lunation and
  106. >X#  position in Metonic cycle.  Time figures from 6pm previous night.
  107. >X#  The lunation of year 1 is calculated to be on a Monday (our Sunday
  108. >X#  night) at ll:11:20pm. Our data table begins with a hypothetical
  109. >X#  year 0, corresponding to 3762 B.C.E.  Calculations in this program
  110. >X#  are figured in the ancient Babylonian unit of halaqim "parts" of
  111. >X#  the hour = 1/1080 hour.
  112. >X#
  113. >X#  Startup syntax is simply hebcalen [date], where date is a year
  114. >X#  specification of the form 5750 for a Jewish year, +1990 or 1990AD
  115. >X#  or 1990CE or -1990 or 1990BC or 1990BCE for a civil year.
  116. >X#
  117. >X#  (Bugs:  Years over 6039 are calculated from scratch (slow).  I've
  118. >X#  also noticed that the dates are incorrect (e.g. hebcalen +7777
  119. >X#  will display civil year 7757).  I have not delved into the pro-
  120. >X#  gram deep enough to pinpoint the cause of the dating discrepancy.
  121. >X#  - RLG)
  122. >X#
  123. >X##########################################################################
  124. >X
  125. >X
  126. >Xrecord date(yr,mth,day)
  127. >Xrecord molad(day,halaqim)
  128. >Xglobal cyr,jyr,days_in_jyr,current_molad,current_day,infolist
  129. >X
  130. >X
  131. >X#------- the following sections of code have been modified  - RLG -------#
  132. >X
  133. >Xprocedure main(a)
  134. >X
  135. >X    iputs(getval("ti"))
  136. >X    display_startup_screen()
  137. >X
  138. >X    if *a = 0 then {
  139. >X    #put()'ing an asterisk means that user might need help
  140. >X    n := 1; put(a,"*")
  141. >X    }
  142. >X    else n := *a
  143. >X    every p := 1 to n do {
  144. >X    initialize(a[p]) | break
  145. >X    process() | break
  146. >X    }
  147. >X    iputs(getval("te"))
  148. >X
  149. >Xend
  150. >X
  151. >X
  152. >X
  153. >Xprocedure display_startup_screen()
  154. >X
  155. >X    local T
  156. >X
  157. >X    clear()
  158. >X    banner("PERPETUAL JEWISH/CIVIL CALENDAR","by","ALAN D. CORRE")
  159. >X    # Use a combination of tricks to be sure it will be up there a sec.
  160. >X    every 1 to 10000
  161. >X    T := &time; until &time > (T+450)
  162. >X
  163. >X    return
  164. >X
  165. >Xend
  166. >X
  167. >X
  168. >X
  169. >Xprocedure banner(l[])
  170. >X
  171. >X    # Creates a banner to begin hebcalen.  Leaves it on the screen for
  172. >X    # about a second.
  173. >X
  174. >X    local m, n, CM, COLS, LINES
  175. >X
  176. >X    CM    := getval("cm")
  177. >X    COLS  := getval("co")
  178. >X    LINES := getval("li")
  179. >X    (COLS > 55, LINES > 9) |
  180. >X    stop("\nSorry, your terminal just isn't big enough.")
  181. >X
  182. >X    if LINES > 20 then {
  183. >X    # Terminal is big enough for banner.
  184. >X    iputs(igoto(CM,1,3))
  185. >X    writes("+",repl("-",COLS-3),"+")
  186. >X    iputs(igoto(CM,1,4))
  187. >X    writes("|")
  188. >X    iputs(igoto(CM,COLS-1,4))
  189. >X    writes("|")
  190. >X
  191. >X    m := 0
  192. >X    every n := 5 to (*l * 3) + 4 by 3 do {
  193. >X        iputs(igoto(CM,1,n))
  194. >X        writes("|",center(l[m+:=1],COLS-3),"|")
  195. >X        every iputs(igoto(CM,1,n+(1|2))) & writes("|")
  196. >X        every iputs(igoto(CM,COLS-1,n+(1|2))) & writes("|")
  197. >X    }
  198. >X    
  199. >X    iputs(igoto(CM,1,n+3))
  200. >X    writes("+",repl("-",COLS-3),"+")
  201. >X    iputs(igoto(CM,1,n+4))
  202. >X    write(" Copyright (c) Alan D. Corre, 1990")
  203. >X    }
  204. >X    else {
  205. >X    # Terminal is extremely short
  206. >X    iputs(igoto(CM,1,(LINES/2)-1))
  207. >X    write(center(l[1],COLS))
  208. >X    write(center("Copyright (c) Alan D. Corre, 1990",COLS))
  209. >X    }    
  210. >X
  211. >X    return
  212. >X
  213. >Xend
  214. >X
  215. >X
  216. >X
  217. >Xprocedure get_paths()
  218. >X
  219. >X    local paths, p
  220. >X
  221. >X    suspend "./" | "/usr/local/lib/hebcalen/"
  222. >X    paths := getenv("PATH")
  223. >X    \paths ? {
  224. >X    tab(match(":"))
  225. >X    while p := 1(tab(find(":")), move(1))
  226. >X    do suspend "" ~== trim(p,'/ ') || "/"
  227. >X    return "" ~== trim(tab(0) \ 1,'/ ') || "/"
  228. >X    }
  229. >X
  230. >Xend
  231. >X
  232. >X
  233. >X
  234. >Xprocedure instructions(filename)
  235. >X
  236. >X    # Gives user access to a help file which is printed out in chunks
  237. >X    # by "more."
  238. >X
  239. >X    local helpfile, pager, ans
  240. >X
  241. >X    iputs(igoto(getval("cm"),1,2))
  242. >X    writes("Do you need instructions? [ny]  ")
  243. >X    ans := map(read())
  244. >X    "q" == ans & fail
  245. >X
  246. >X    if "y" == ans then {
  247. >X    if close(open(helpfile := (get_paths()||filename)))
  248. >X    then {
  249. >X        # Kludge, kludge, kludge.
  250. >X        close(open(
  251. >X        more_file := (
  252. >X            ("" ~== getenv("PAGER")) |
  253. >X            (("/bin/"|"/usr/ucb/"|"/usr/bin/")||"more"))))
  254. >X        system(more_file || " " || helpfile)
  255. >X    }
  256. >X    else write("Can't find your hebcalen.hlp file!")
  257. >X    iputs(igoto(getval("cm"),1,getval("li")))
  258. >X    boldface()
  259. >X    writes("Press return to continue.")
  260. >X    normal()
  261. >X    "q" == map(read()) & fail
  262. >X    }
  263. >X
  264. >X    return \helpfile | "no help"
  265. >X
  266. >Xend
  267. >X
  268. >X
  269. >X
  270. >Xprocedure clear()
  271. >X
  272. >X    # Clears the screen.  Tries several methods.
  273. >X
  274. >X    if not iputs(getval("cl"))
  275. >X    then iputs(igoto(getval("cm"),1,1))
  276. >X    if not iputs(getval("cd"))
  277. >X    then {
  278. >X    every i := 1 to getval("li") do {
  279. >X        iputs(igoto(getval("cm"),1,i))
  280. >X        iputs(getval("ce"))
  281. >X    }
  282. >X    iputs(igoto(getval("cm"),1,1))
  283. >X    }
  284. >X
  285. >Xend
  286. >X
  287. >X
  288. >X
  289. >Xprocedure initialize_list()
  290. >X
  291. >X    # Put info of hebcalen.dat into a global list
  292. >X
  293. >X    local infile,n
  294. >X
  295. >X    infolist := list(301)
  296. >X    if not (infile := open(get_paths()||"hebcalen.dat")) then
  297. >X    stop("\nError:  hebcalen.dat must be in your path or the current dir.")
  298. >X
  299. >X    # The table is arranged at twenty year intervals with 301 entries.
  300. >X    every n := 1 to 301 do
  301. >X    infolist[n] := read(infile)
  302. >X    close(infile)
  303. >X
  304. >Xend
  305. >X
  306. >X
  307. >X
  308. >Xprocedure initialize_variables()
  309. >X
  310. >X    # Get the closest previous year in the table.
  311. >X
  312. >X    local line, quotient
  313. >X
  314. >X    quotient := jyr.yr / 20 + 1
  315. >X    # Only 301 entries. Figure from last if necessary.
  316. >X    if quotient > 301 then quotient := 301
  317. >X    # Pull the appropriate info, put into global variables.
  318. >X    line := infolist[quotient]
  319. >X
  320. >X    line ? {
  321. >X    current_molad.day := tab(upto('%'))
  322. >X    move(1)
  323. >X    current_molad.halaqim := tab(upto('%'))
  324. >X    move(1)
  325. >X    cyr.mth := tab(upto('%'))
  326. >X    move(1)
  327. >X    cyr.day := tab(upto('%'))
  328. >X    move(1)
  329. >X    cyr.yr := tab(upto('%'))
  330. >X    days_in_jyr := line[-3:0]
  331. >X    }
  332. >X
  333. >X    # Begin at rosh hashana.
  334. >X    jyr.day := 1
  335. >X    jyr.mth := 7
  336. >X    return
  337. >X
  338. >Xend
  339. >X
  340. >X
  341. >X
  342. >Xprocedure initialize(yr)
  343. >X
  344. >X    local year
  345. >X    static current_year
  346. >X
  347. >X    # initialize global variables
  348. >X    initial {
  349. >X    cyr := date(0,0,0)
  350. >X    jyr := date(0,0,0)
  351. >X    current_molad := molad(0,0)
  352. >X    initialize_list()
  353. >X    current_year := get_current_year()
  354. >X    }
  355. >X
  356. >X    clear()
  357. >X    #user may need help
  358. >X    if yr == "*" then {
  359. >X    instructions("hebcalen.hlp") | fail
  360. >X    clear()
  361. >X    iputs(igoto(getval("cm"),1,2))
  362. >X    write("Enter a year.  By default, all dates are interpreted")
  363. >X    write("according to the Jewish calendar.  Civil years should")
  364. >X    write("be preceded by a + or - sign to indicate occurrence")
  365. >X    write("relative to the beginning of the common era (the cur-")
  366. >X    writes("rent civil year, ",current_year,", is the default):  ")
  367. >X    boldface()
  368. >X    year := read()
  369. >X    normal()
  370. >X    "q" == map(year) & fail
  371. >X    }
  372. >X    else year := yr
  373. >X
  374. >X    "" == year & year := current_year
  375. >X    until jyr.yr := cleanup(year) do {
  376. >X    writes("\nI don't consider ")
  377. >X    boldface()
  378. >X    writes(year)
  379. >X    normal()
  380. >X    writes(" a valid date.  Try again:  ")
  381. >X    boldface()
  382. >X    year := read()
  383. >X    normal()
  384. >X    "q" == map(year) & fail
  385. >X    "" == year & year := current_year
  386. >X    }
  387. >X
  388. >X    clear()
  389. >X    initialize_variables()
  390. >X    return
  391. >X
  392. >Xend
  393. >X
  394. >X
  395. >X
  396. >Xprocedure get_current_year()
  397. >X    &date ? c_date := tab(find("/"))
  398. >X    return "+" || c_date
  399. >Xend
  400. >X
  401. >X
  402. >X
  403. >Xprocedure cleanup(str)
  404. >X
  405. >X    # Tidy up the string. Bugs still possible.
  406. >X
  407. >X    if "" == trim(str) then return ""
  408. >X
  409. >X    map(Strip(str,~(&digits++'ABCDE+-'))) ? {
  410. >X
  411. >X    if find("-"|"bc"|"bcd")
  412. >X    then return (0 < (3761 - (0 ~= checkstr(str))))
  413. >X    else if find("+"|"ad"|"ce")
  414. >X    then return ((0 ~= checkstr(str)) + 3760)
  415. >X    else if 0 < integer(str)
  416. >X    then return str
  417. >X    else fail
  418. >X    
  419. >X    }
  420. >X
  421. >Xend
  422. >X
  423. >X
  424. >X
  425. >Xprocedure Strip(s,c)
  426. >X
  427. >X    s2 := ""
  428. >X    s ? {
  429. >X    while s2 ||:= tab(upto(c))
  430. >X    do tab(many(c))
  431. >X    s2 ||:= tab(0)
  432. >X    }
  433. >X    return s2
  434. >X
  435. >Xend
  436. >X
  437. >X
  438. >X
  439. >Xprocedure checkstr(s)
  440. >X
  441. >X    # Does preliminary work on string before cleanup() cleans it up.
  442. >X
  443. >X    local letter,n,newstr
  444. >X
  445. >X    newstr := ""
  446. >X    every newstr ||:= string(integer(!s))
  447. >X    if 0 = *newstr | "" == newstr
  448. >X    then fail
  449. >X    else return newstr
  450. >X
  451. >Xend
  452. >X
  453. >X
  454. >X
  455. >Xprocedure process()
  456. >X
  457. >X    # Extracts information about the specified year.
  458. >X
  459. >X    local msg, limit, dj, dc, month_count, done
  460. >X    static how_many_per_screen, how_many_screens
  461. >X    initial {
  462. >X    how_many_per_screen := how_many_can_fit()
  463. >X    (how_many_screens := seq()) * how_many_per_screen >= 12
  464. >X    }
  465. >X
  466. >X    # 6039 is last year handled by the table in the usual way.
  467. >X    if jyr.yr > 6039
  468. >X    then msg := "Calculating.  Years over 6039 take a long time."
  469. >X    else msg := "Calculating."
  470. >X    if jyr.yr <= 6039 then {
  471. >X    limit := jyr.yr % 20 
  472. >X    jyr.yr := ((jyr.yr / 20) * 20)} else {
  473. >X            # Otherwise figure from 6020 and good luck
  474. >X        limit := jyr.yr - 6020
  475. >X        jyr.yr := 6020
  476. >X    }
  477. >X
  478. >X    ans := "y"
  479. >X    establish_jyr()
  480. >X    iputs(igoto(getval("cm"),1,2))
  481. >X    writes(msg)
  482. >X    every 1 to limit do {
  483. >X    # Increment the years, establish the type of Jewish year
  484. >X    cyr_augment()
  485. >X    jyr_augment()
  486. >X    establish_jyr()
  487. >X    }
  488. >X
  489. >X    clear() 
  490. >X    while ("y"|"") == map(ans) do {
  491. >X
  492. >X    yj := jyr.yr
  493. >X    dj := days_in_jyr
  494. >X
  495. >X    month_count := 0
  496. >X    # On the variable how_many_screens, see initial { } above
  497. >X    every n := 1 to how_many_screens do {
  498. >X        clear()
  499. >X        every 1 to how_many_per_screen do {
  500. >X        write_a_month()
  501. >X        (month_count +:= 1) = 12 & break
  502. >X        }
  503. >X        if month_count < 12 | (12 % (13 > how_many_per_screen)) = 0
  504. >X        then {
  505. >X
  506. >X        iputs(igoto(getval("cm"),1,getval("li")-2))
  507. >X        boldface()
  508. >X        writes(status_line(yj,dj))
  509. >X        normal()
  510. >X
  511. >X        if month_count < 12 | jyr.mth = 6 then {
  512. >X            iputs(igoto(getval("cm"),1,getval("li")-1))
  513. >X            writes("Press return to continue.  ")
  514. >X            "q" == map(read()) & fail
  515. >X        }
  516. >X        }
  517. >X    }
  518. >X
  519. >X    if jyr.mth = 6 then {
  520. >X        if (12 % (13 > how_many_per_screen)) = 0
  521. >X        then clear()
  522. >X        write_a_month()
  523. >X    }
  524. >X    iputs(igoto(getval("cm"),1,getval("li")-2))
  525. >X    boldface()
  526. >X    writes(status_line(yj,dj))
  527. >X    normal()
  528. >X
  529. >X    iputs(igoto(getval("cm"),1,getval("li")-1))
  530. >X    writes("Display the next year? [yn]  ")
  531. >X    ans := read()
  532. >X
  533. >X    }
  534. >X    return
  535. >X
  536. >Xend
  537. >X
  538. >X
  539. >X
  540. >Xprocedure how_many_can_fit()
  541. >X
  542. >X    local LINES, how_many
  543. >X
  544. >X    LINES := getval("li") + 1
  545. >X    (((8 * (how_many := 1 to 14)) / LINES) = 1)
  546. >X
  547. >X    return how_many - 1
  548. >X
  549. >Xend
  550. >X
  551. >X
  552. >X
  553. >Xprocedure cyr_augment()
  554. >X
  555. >X    # Make civil year a year later, we only need consider Aug,Sep,Nov.
  556. >X
  557. >X    local days,newmonth,newday
  558. >X
  559. >X    if cyr.mth = 8 then
  560. >X    days := 0 else
  561. >X    if cyr.mth = 9 then
  562. >X    days := 31 else
  563. >X    if cyr.mth = 10 then
  564. >X    days := 61 else
  565. >X    stop("Error in cyr_augment")
  566. >X
  567. >X    writes(".")
  568. >X
  569. >X    days := (days + cyr.day-365+days_in_jyr)
  570. >X    if isleap(cyr.yr + 1) then days -:= 1
  571. >X
  572. >X    # Cos it takes longer to get there.
  573. >X    if days <= 31 then {newmonth := 8; newday := days} else
  574. >X    if days <= 61 then {newmonth := 9; newday := days-31} else
  575. >X    {newmonth := 10; newday := days-61} 
  576. >X
  577. >X    cyr.mth := newmonth
  578. >X    cyr.day := newday
  579. >X    cyr.yr +:= 1
  580. >X    if cyr.yr = 0 then cyr.yr := 1
  581. >X
  582. >X    return
  583. >X
  584. >Xend
  585. >X
  586. >X
  587. >X
  588. >Xprocedure header()
  589. >X
  590. >X    # Creates the header for Jewish and English side.  Bug:  This
  591. >X    # routine, as it stands, has to rewrite the entire screen, in-
  592. >X    # cluding blank spaces.  Many of these could be elminated by
  593. >X    # judicious line clears and/or cursor movement commands.  Do-
  594. >X    # ing so would certainly speed up screen refresh for lower
  595. >X    # baud rates.  I've utilized the ch command where available,
  596. >X    # but in most cases, plain old spaces must be output.
  597. >X
  598. >X    static make_whitespace, whitespace
  599. >X    initial {
  600. >X    COLS := getval("co")
  601. >X    if getval("ch") then {
  602. >X        # Untested, but it would offer a BIG speed advantage!
  603. >X        make_whitespace := create |iputs(igoto(getval("ch"),(COLS-53)+25))
  604. >X    }
  605. >X    else {
  606. >X        # Have to do things this way, since we don't know what line
  607. >X        # we are on (cm commands usually default to row/col 1).
  608. >X        whitespace := repl(" ",COLS-53)
  609. >X        make_whitespace := create |writes(whitespace)
  610. >X    }
  611. >X    }
  612. >X
  613. >X    writes(repl(" ",7),"S",repl(" ",2),"M",repl(" ",2),"T",repl(" ",2),"W",
  614. >X       repl(" ",2),"T",repl(" ",2),"F",repl(" ",2))
  615. >X    boldface()
  616. >X    writes("S")
  617. >X    normal()
  618. >X    @make_whitespace
  619. >X    writes("S",repl(" ",2),"M",repl(" ",2),"T",repl(" ",2),"W",
  620. >X        repl(" ",2),"T",repl(" ",2),"F",repl(" ",2))
  621. >X    boldface()
  622. >X    writes("S")
  623. >X    normal()
  624. >X    iputs(getval("ce"))
  625. >X    write()
  626. >X
  627. >Xend
  628. >X
  629. >X
  630. >X
  631. >Xprocedure write_a_month()
  632. >X
  633. >X    # Writes a month on the screen
  634. >X
  635. >X    header()
  636. >X    every 1 to 5 do {
  637. >X    writes(make_a_line())
  638. >X    iputs(getval("ce"))
  639. >X    write()
  640. >X    }
  641. >X    if jyr.day ~= 1 then {
  642. >X    writes(make_a_line())
  643. >X    iputs(getval("ce"))
  644. >X    write()
  645. >X    }
  646. >X    iputs(getval("ce"))
  647. >X    write()
  648. >X
  649. >X    return
  650. >X
  651. >Xend
  652. >X
  653. >X
  654. >X
  655. >Xprocedure status_line(a,b)
  656. >X
  657. >X    # Create the status line at the bottom of screen.
  658. >X
  659. >X    local sline,c,d
  660. >X
  661. >X    c := cyr.yr
  662. >X    if (cyr.day = 1) & (cyr.mth = 1) then c -:= 1
  663. >X    d := { if isleap(c) then 366 else 365 }
  664. >X    if getval("co") > 79 then {
  665. >X    sline := ("Year of Creation: " || a || "  Days in year: " || b ||
  666. >X          "  Civil year: " || c || "  Days in year: " || d)
  667. >X    }
  668. >X    else {
  669. >X    sline := ("Jewish year " || a || " (" || b || " days)," ||
  670. >X          " Civil year " || c || " (" || d || " days)")
  671. >X    }
  672. >X
  673. >X    return center(sline,getval("co"))
  674. >X
  675. >Xend
  676. >X
  677. >X
  678. >X
  679. >Xprocedure boldface()
  680. >X    
  681. >X    static bold_str, cookie_str
  682. >X    initial {
  683. >X    if bold_str := getval("so")
  684. >X    then cookie_str := repl(getval("bc") | "\b", getval("sg"))
  685. >X    else {
  686. >X        if bold_str := getval("ul")
  687. >X        then cookie_str := repl(getval("bc") | "\b", getval("ug"))
  688. >X    }
  689. >X    }        
  690. >X    
  691. >X    iputs(\bold_str)
  692. >X    iputs(\cookie_str)
  693. >X    return
  694. >X
  695. >Xend
  696. >X
  697. >X
  698. >X
  699. >Xprocedure normal()
  700. >X
  701. >X    static UN_bold_str, cookie_str
  702. >X    initial {
  703. >X    if UN_bold_str := getval("se")
  704. >X    then cookie_str := repl(getval("bc") | "\b", getval("sg"))
  705. >X    else {
  706. >X        if UN_bold_str := getval("ue")
  707. >X        then cookie_str := repl(getval("bc") | "\b", getval("ug"))
  708. >X    }
  709. >X    }        
  710. >X    
  711. >X    iputs(\UN_bold_str)
  712. >X    iputs(\cookie_str)
  713. >X    return
  714. >X
  715. >Xend
  716. >X
  717. >X
  718. >X#--------------------- end modified sections of code ----------------------#
  719. >X
  720. >X# Okay, okay a couple of things have been modified below, but nothing major.
  721. >X
  722. >Xprocedure make_a_line()
  723. >X#make a single line of the months
  724. >Xlocal line,blanks1,blanks2,start_point,end_point,flag,fm
  725. >Xstatic number_of_spaces
  726. >Xinitial number_of_spaces := getval("co")-55
  727. >X
  728. >X#consider the first line of the month
  729. >X  if jyr.day = 1 then {
  730. >X    line := mth_table(jyr.mth,1)
  731. >X#setting flag means insert civil month at end of line    
  732. >X    flag := 1 } else
  733. >X    line := repl(" ",3)
  734. >X#consider the case where first day of civil month is on Sunday    
  735. >X  if (cyr.day = 1) & (current_day = 1) then flag := 1
  736. >X#space between month name and beginning of calendar
  737. >X  line ||:= repl(" ",2)
  738. >X#measure indentation for first line
  739. >X  line ||:= blanks1 := repl(" ",3*(current_day-1))
  740. >X#establish start point for Hebrew loop
  741. >X  start_point := current_day
  742. >X#establish end point for Hebrew loop and run civil loop
  743. >X  every end_point := start_point to 7 do {
  744. >X    line ||:= right(jyr.day,3)
  745. >X    if not j_augment() then {jyr_augment(); establish_jyr(); current_day -:= 1; if current_day = 0 then current_day := 7}
  746. >X    d_augment()
  747. >X    if jyr.day = 1 then break }
  748. >X#measure indentation for last line
  749. >X  blanks2 := repl(" ",3*(7-end_point))
  750. >X  line ||:= blanks2; line ||:= repl(" ",number_of_spaces); line ||:= blanks1
  751. >X  every start_point to end_point do {
  752. >X    line ||:= right(cyr.day,3)
  753. >X    if (cyr.day = 1) then flag := 1 
  754. >X    augment()}
  755. >X  line ||:= blanks2 ||:= repl(" ",3)
  756. >X  fm := cyr.mth
  757. >X  if cyr.day = 1 then
  758. >X    if cyr.mth = 1 then fm := 12 else fm := cyr.mth - 1
  759. >X  if \flag then line ||:= mth_table(fm,2) else
  760. >X    line ||:= repl(" ",3)
  761. >Xreturn line
  762. >Xend
  763. >X
  764. >Xprocedure mth_table(n,p)
  765. >X#generates the short names of Jewish and Civil months. Get to civil side
  766. >X#by adding 13 (=max no of Jewish months)
  767. >Xstatic corresp
  768. >Xinitial corresp := ["NIS","IYA","SIV","TAM","AV ","ELU","TIS","HES","KIS",
  769. >X"TEV","SHE","ADA","AD2","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP",
  770. >X"OCT","NOV","DEC"]
  771. >X  if (p ~= 1) & (p ~= 2) then stop("ERROR IN MTH-TABLE") else
  772. >X    if p = 2 then n +:= 13
  773. >Xreturn corresp[n]
  774. >Xend
  775. >X
  776. >Xprocedure d_augment()
  777. >X#increment the day of the week
  778. >X  current_day +:= 1
  779. >X  if current_day = 8 then current_day := 1
  780. >Xreturn
  781. >Xend
  782. >X
  783. >Xprocedure augment()
  784. >X#increments civil day, modifies month and year if necessary, stores in
  785. >X#global variable cyr
  786. >X  if cyr.day < 28 then
  787. >X    cyr.day +:= 1 else
  788. >X  if cyr.day = 28 then {
  789. >X    if (cyr.mth ~= 2) | ((cyr.mth = 2) & isleap(cyr.yr)) then
  790. >X      cyr.day := 29 else {
  791. >X        cyr.mth := 3
  792. >X    cyr.day  := 1}} else
  793. >X  if cyr.day = 29 then {
  794. >X    if cyr.mth ~= 2 then
  795. >X      cyr.day := 30 else {
  796. >X      cyr.mth := 3
  797. >X      cyr.day := 1}} else
  798. >X  if cyr.day = 30 then {
  799. >X    if is_31(cyr.mth) then
  800. >X      cyr.day := 31 else {
  801. >X      cyr.mth +:= 1
  802. >X      cyr.day := 1}} else {
  803. >X      cyr.day := 1
  804. >X      if cyr.mth ~= 12 then
  805. >X        cyr.mth +:= 1 else {
  806. >X        cyr.mth := 1
  807. >X        cyr.yr +:= 1
  808. >X        if cyr.yr = 0
  809. >X      then cyr.yr := 1}}
  810. >Xreturn
  811. >Xend
  812. >X
  813. >Xprocedure is_31(n)
  814. >X#civil months with 31 days
  815. >Xreturn n = 1 | n = 3 | n = 5 | n = 7 | n = 8 | n = 10 | n = 12
  816. >Xend
  817. >X
  818. >Xprocedure isleap(n)
  819. >X#checks for civil leap year
  820. >X  if n > 0 then
  821. >Xreturn (n % 400 = 0) | ((n % 4 = 0) & (n % 100 ~= 0)) else
  822. >Xreturn (n % 400 = -1) | ((n % 4 = -1) & (n % 100 ~= -1))
  823. >Xend
  824. >X
  825. >Xprocedure j_augment()
  826. >X#increments jewish day. months are numbered from nisan, adar sheni is 13.
  827. >X#procedure fails at elul to allow determination of type of new year
  828. >X  if jyr.day < 29 then
  829. >X    jyr.day +:= 1 else
  830. >X  if (jyr.day = 30) | always_29(jyr.mth) | ((jyr.mth = 8) & 
  831. >X    (days_in_jyr % 5 ~= 0)) | ((jyr.mth = 9) & ((days_in_jyr = 353) |
  832. >X    (days_in_jyr = 383))) then
  833. >X    jyr.mth +:= jyr.day := 1 else
  834. >X  if jyr.mth = 6 then fail else
  835. >X  if ((jyr.mth = 12) & (days_in_jyr < 383)) | (jyr.mth = 13) then
  836. >X    jyr.mth := jyr.day := 1 else
  837. >X  jyr.day := 30
  838. >Xreturn
  839. >Xend
  840. >X
  841. >Xprocedure always_29(n)
  842. >X#uncomplicated jewish months with 29 days
  843. >Xreturn n = 2 | n = 4 | n = 10
  844. >Xend
  845. >X
  846. >Xprocedure jyr_augment()
  847. >X#determines the current time of lunation, using the ancient babylonian unit
  848. >X#of 1/1080 of an hour. lunation of tishri determines type of year. allows
  849. >X#for leap year. halaqim = parts of the hour
  850. >Xlocal days, halaqim
  851. >X  days := current_molad.day + 4
  852. >X  if days_in_jyr <= 355 then {
  853. >X    halaqim :=  current_molad.halaqim + 9516
  854. >X    days := ((days +:= halaqim / 25920) % 7)
  855. >X    if days = 0 then days := 7
  856. >X    halaqim := halaqim % 25920} else {
  857. >X    days +:= 1
  858. >X    halaqim := current_molad.halaqim + 23269
  859. >X    days := ((days +:= halaqim / 25920) % 7)
  860. >X    if days = 0 then days := 7
  861. >X    halaqim := halaqim % 25920}
  862. >X  current_molad.day := days
  863. >X  current_molad.halaqim := halaqim
  864. >X#reset the global variable which holds the current jewish date
  865. >X  jyr.yr +:= 1 #increment year
  866. >X  jyr.day := 1
  867. >X  jyr.mth := 7
  868. >X  establish_jyr()
  869. >Xreturn
  870. >Xend
  871. >X
  872. >Xprocedure establish_jyr()
  873. >X#establish the jewish year from get_rh
  874. >Xlocal res
  875. >X  res := get_rh(current_molad.day,current_molad.halaqim,no_lunar_yr(jyr.yr))
  876. >X  days_in_jyr := res[2]
  877. >X  current_day := res[1]
  878. >Xreturn
  879. >Xend    
  880. >X
  881. >Xprocedure isin1(i)
  882. >X#the isin procedures are sets of years in the Metonic cycle
  883. >Xreturn i = (1 | 4 | 7 | 9 | 12 | 15 | 18)
  884. >Xend
  885. >X
  886. >Xprocedure isin2(i)
  887. >Xreturn i = (2 | 5 | 10 | 13 | 16)
  888. >Xend
  889. >X
  890. >Xprocedure isin3(i)
  891. >Xreturn i = (3 | 6 | 8 | 11 | 14 | 17 | 0)
  892. >Xend
  893. >X
  894. >Xprocedure isin4(i)
  895. >Xreturn i = (1 | 2 | 4 | 5 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18)
  896. >Xend
  897. >X
  898. >Xprocedure isin5(i)
  899. >Xreturn i = (1 | 4 | 9 | 12 | 15)
  900. >Xend
  901. >X
  902. >Xprocedure isin6(i)
  903. >Xreturn i = (2 | 5 | 7 | 10 | 13 | 16 | 18)
  904. >Xend
  905. >X
  906. >Xprocedure no_lunar_yr(i)
  907. >X#what year in the metonic cycle is it?
  908. >Xreturn i % 19
  909. >Xend
  910. >X
  911. >Xprocedure get_rh(d,h,yr)
  912. >X#this is the heart of the program. check the day of lunation of tishri
  913. >X#and determine where breakpoint is that sets the new moon day in parts
  914. >X#of the hour. return result in a list where 1 is day of rosh hashana and
  915. >X#2 is length of jewish year
  916. >Xlocal c,result
  917. >X  c := no_lunar_yr(yr)
  918. >X  result := list(2)
  919. >X  if d = 1 then {
  920. >X          result[1] := 2
  921. >X                if (h < 9924) & isin4(c) then result[2] := 353 else
  922. >X        if (h < 22091) & isin3(c) then result[2] := 383 else
  923. >X        if (h > 9923) & (isin1(c) | isin2(c)) then result[2] := 355 else
  924. >X        if (h > 22090) & isin3(c) then result[2] := 385
  925. >X        } else
  926. >X  if d = 2 then {
  927. >X          if ((h < 16789) & isin1(c)) |
  928. >X           ((h < 19440) & isin2(c)) then {
  929. >X                                 result[1] := 2
  930. >X                             result[2] := 355
  931. >X                             } else
  932. >X        if (h < 19440) & isin3(c) then  {
  933. >X                                 result[1] := 2
  934. >X                             result[2] := 385
  935. >X                             } else
  936. >X          if ((h > 16788) & isin1(c)) |
  937. >X           ((h > 19439) & isin2(c)) then {
  938. >X                                 result[1] := 3
  939. >X                             result[2] := 354
  940. >X                             } else
  941. >X                if (h > 19439) & isin3(c) then  {
  942. >X                                 result[1] := 3
  943. >X                             result[2] := 384
  944. >X                             }
  945. >X        } else
  946. >X  if d = 3 then {
  947. >X          if (h < 9924) & (isin1(c) | isin2(c)) then {
  948. >X                               result[1] := 3
  949. >X                               result[2] := 354
  950. >X                               } else
  951. >X        if (h < 19440) & isin3(c) then {
  952. >X                           result[1] := 3
  953. >X                           result[2] := 384
  954. >X                           } else
  955. >X        if (h > 9923) & isin4(c) then {
  956. >X                          result[1] := 5
  957. >X                          result[2] := 354
  958. >X                          } else
  959. >X        if (h > 19439) & isin3(c) then {
  960. >X                           result[1] := 5
  961. >X                           result[2] := 383}
  962. >X        } else
  963. >X  if d = 4 then {
  964. >X          result[1] := 5
  965. >X        if isin4(c) then result[2] := 354 else
  966. >X        if h < 12575 then result[2] := 383 else
  967. >X        result[2] := 385
  968. >X        } else
  969. >X  if d = 5 then {
  970. >X                if (h < 9924) & isin4(c) then {
  971. >X                          result[1] := 5
  972. >X                          result[2] := 354} else
  973. >X        if (h < 19440) & isin3(c) then {
  974. >X                           result[1] := 5
  975. >X                           result[2] := 385
  976. >X                           } else
  977. >X        if (9923 < h < 19440) & isin4(c) then {
  978. >X                              result[1] := 5
  979. >X                              result[2] := 355
  980. >X                              } else
  981. >X        if h > 19439 then {
  982. >X                    result[1] := 7
  983. >X                          if isin3(c) then result[2] := 383 else
  984. >X                            result[2] := 353
  985. >X                  }
  986. >X        } else
  987. >X  if d = 6 then {
  988. >X            result[1] := 7
  989. >X            if ((h < 408) & isin5(c)) | ((h < 9924) & isin6(c)) then
  990. >X                              result[2] := 353 else
  991. >X            if ((h < 22091) & isin3(c)) then result[2] := 383 else
  992. >X            if ((h > 407) & isin5(c)) | ((h > 9923) & isin6(c)) then
  993. >X                              result[2] := 355 else
  994. >X            if (h > 22090) & isin3(c) then result[2] := 385
  995. >X            } else
  996. >X  if d = 7 then    if (h < 19440) & (isin5(c) | isin6(c)) then {
  997. >X                              result[1] := 7
  998. >X                              result[2] := 355
  999. >X                              } else
  1000. >X        if (h < 19440) & isin3(c) then {
  1001. >X                           result[1] := 7
  1002. >X                           result[2] := 385
  1003. >X                           } else {
  1004. >X                                  result[1] := 2
  1005. >X                              if isin4(c) then
  1006. >X                                result[2] := 353 else
  1007. >X                            result[2] := 383}
  1008. >Xreturn result
  1009. >Xend
  1010. >SHAR_EOF
  1011. ># ============= itlib.icn ==============
  1012. >echo "x - extracting itlib.icn (Text)"
  1013. >sed 's/^X//' << 'SHAR_EOF' > itlib.icn &&
  1014. >X########################################################################
  1015. >X#    
  1016. >X#    Name:    itlib.icn
  1017. >X#    
  1018. >X#    Title:    Icon termlib-type tools
  1019. >X#    
  1020. >X#    Author:    Richard L. Goerwitz
  1021. >X#
  1022. >X#    Date:    7/19/90 (version 1.3)
  1023. >X#
  1024. >X########################################################################
  1025. >X#
  1026. >X#  Copyright (c) 1990, Richard L. Goerwitz, III
  1027. >X#
  1028. >X#  This software is intended for free and unrestricted distribution.
  1029. >X#  I place only two conditions on its use:  1) That you clearly mark
  1030. >X#  any additions or changes you make to the source code, and 2) that
  1031. >X#  you do not delete this message therefrom.  In order to protect
  1032. >X#  myself from spurious litigation, it must also be stated here that,
  1033. >X#  because this is free software, I, Richard Goerwitz, make no claim
  1034. >X#  about the applicability or fitness of this software for any
  1035. >X#  purpose, and expressly disclaim any responsibility for any damages
  1036. >X#  that might be incurred in conjunction with its use.
  1037. >X#
  1038. >X########################################################################
  1039. >X#
  1040. >X#  The following library represents a series of rough functional
  1041. >X#  equivalents to the standard Unix low-level termcap routines.  They
  1042. >X#  are not meant as exact termlib clones.  Nor are they enhanced to
  1043. >X#  take care of magic cookie terminals, terminals that use \D in their
  1044. >X#  termcap entries, or, in short, anything I felt would not affect my
  1045. >X#  normal, day-to-day work with ANSI and vt100 terminals.
  1046. >X#
  1047. >X#  Requires:  A unix platform & co-expressions.  Certainly the
  1048. >X#  package could be altered for use with MS-DOS and other systems.
  1049. >X#  Please contact me if advice on how to do this is needed.
  1050. >X#
  1051. >X#  setname(term)
  1052. >X#    Use only if you wish to initialize itermlib for a terminal
  1053. >X#  other than what your current environment specifies.  "Term" is the
  1054. >X#  name of the termcap entry to use.  Normally this initialization is
  1055. >X#  done automatically, and need not concern the user.
  1056. >X#
  1057. >X#  getval(id)
  1058. >X#    Works something like tgetnum, tgetflag, and tgetstr.  In the
  1059. >X#  spirit of Icon, all three have been collapsed into one routine.
  1060. >X#  Integer valued caps are returned as integers, strings as strings,
  1061. >X#  and flags as records (if a flag is set, then type(flag) will return
  1062. >X#  "true").  Absence of a given capability is signalled by procedure
  1063. >X#  failure.
  1064. >X#
  1065. >X#  igoto(cm,destcol,destline) - NB:  default 1 offset (*not* zero)!
  1066. >X#    Analogous to tgoto.  "Cm" is the cursor movement command for
  1067. >X#  the current terminal, as obtained via getval("cm").  Igoto()
  1068. >X#  returns a string which, when output via iputs, will cause the
  1069. >X#  cursor to move to column "destcol" and line "destline."  Column and
  1070. >X#  line are always calculated using a *one* offset.  This is far more
  1071. >X#  Iconish than the normal zero offset used by tgoto.  If you want to
  1072. >X#  go to the first square on your screen, then input
  1073. >X#  "igoto(getval("cm"),1,1)."
  1074. >X#
  1075. >X#  iputs(cp,affcnt)
  1076. >X#    Equivalent to tputs.  "Cp" is a string obtained via getval(),
  1077. >X#  or, in the case of "cm," via igoto(getval("cm"),x,y).  Affcnt is a
  1078. >X#  count of affected lines.  It is only relevant for terminals which
  1079. >X#  specify proportional (starred) delays in their termcap entries.
  1080. >X#
  1081. >X##########################################################################
  1082. >X
  1083. >X
  1084. >Xglobal tc_table, tty_speed
  1085. >Xrecord true()
  1086. >X
  1087. >X
  1088. >Xprocedure check_features()
  1089. >X
  1090. >X    local in_params, yes_tabs, line
  1091. >X    # global tty_speed
  1092. >X
  1093. >X    initial {
  1094. >X    find("unix",map(&features)) |
  1095. >X        er("check_features","unix system required",1)
  1096. >X    find("o-expres",&features) |
  1097. >X        er("check_features","co-expressions not implemented - &$#!",1)
  1098. >X    system("/bin/stty tabs") |
  1099. >X        er("check_features","can't set tabs option",1)
  1100. >X    }
  1101. >X
  1102. >X    # clumsy, clumsy, clumsy, and probably won't work on all systems
  1103. >X    in_params := open("/bin/stty 2>&1","pr") | 
  1104. >X    (ospeed := &null, fail)
  1105. >X    every line := !in_params do {
  1106. >X    yes_tabs := find("tabs",line)
  1107. >X    line ? {
  1108. >X        tty_speed := (tab(find("speed")+5), tab(many(' ')),
  1109. >X               integer(tab(many(&digits))))
  1110. >X    }
  1111. >X    }
  1112. >X    close(in_params)
  1113. >X    return "term characteristics reset; features check out"
  1114. >X
  1115. >Xend
  1116. >X
  1117. >X
  1118. >X
  1119. >Xprocedure setname(name)
  1120. >X
  1121. >X    # Sets current terminal type to "name" and builds a new termcap
  1122. >X    # capability database (residing in tc_table).  Fails if unable to
  1123. >X    # find a termcap entry for terminal type "name."  If you want it
  1124. >X    # to terminate with an error message under these circumstances,
  1125. >X    # comment out "| fail" below, and uncomment the er() line.
  1126. >X
  1127. >X    #tc_table is global
  1128. >X    
  1129. >X    check_features()
  1130. >X
  1131. >X    tc_table := maketc_table(getentry(name)) | fail
  1132. >X    # er("setname","no termcap entry found for "||name,3)
  1133. >X    return "successfully reset for terminal " || name
  1134. >X
  1135. >Xend
  1136. >X
  1137. >X
  1138. >X
  1139. >Xprocedure getname()
  1140. >X
  1141. >X    # Getname() first checks to be sure we're running under Unix, and,
  1142. >X    # if so, tries to figure out what the current terminal type is,
  1143. >X    # checking successively the value of the environment variable
  1144. >X    # TERM, and then the output of "tset -".  Terminates with an error
  1145. >X    # message if the terminal type cannot be ascertained.
  1146. >X
  1147. >X    local term, tset_output
  1148. >X
  1149. >X    check_features()
  1150. >X
  1151. >X    if not (term := getenv("TERM")) then {
  1152. >X    tset_output := open("/bin/tset -","pr") |
  1153. >X        er("getname","can't find tset command",1)
  1154. >X    term := !tset_output
  1155. >X    close(tset_output)
  1156. >X    }
  1157. >X    return \term |
  1158. >X    er("getname","can't seem to determine your terminal type",1)
  1159. >X
  1160. >Xend
  1161. >X
  1162. >X
  1163. >X
  1164. >Xprocedure er(func,msg,errnum)
  1165. >X
  1166. >X    # short error processing utility
  1167. >X    write(&errout,func,":  ",msg)
  1168. >X    exit(errnum)
  1169. >X
  1170. >Xend
  1171. >X
  1172. >X
  1173. >X
  1174. >Xprocedure getentry(name)
  1175. >X
  1176. >X    # "Name" designates the current terminal type.  Getentry() scans
  1177. >X    # the current environment for the variable TERMCAP.  If the
  1178. >X    # TERMCAP string represents a termcap entry for a terminal of type
  1179. >X    # "name," then getentry() returns the TERMCAP string.  Otherwise,
  1180. >X    # getentry() will check to see if TERMCAP is a file name.  If so,
  1181. >X    # getentry() will scan that file for an entry corresponding to
  1182. >X    # "name."  If the TERMCAP string does not designate a filename,
  1183. >X    # getentry() will scan /etc/termcap for the correct entry.
  1184. >X    # Whatever the input file, if an entry for terminal "name" is
  1185. >X    # found, getentry() returns that entry.  Otherwise, getentry()
  1186. >X    # fails.
  1187. >X
  1188. >X    local termcap_string, f, getline, line, nm, ent1, ent2
  1189. >X
  1190. >X    termcap_string := getenv("TERMCAP")
  1191. >X
  1192. >X    if \termcap_string ? (not match("/"), pos(0) | tab(find("|")+1), =name)
  1193. >X    then return termcap_string
  1194. >X    else {
  1195. >X
  1196. >X    if find("/",\termcap_string)
  1197. >SHAR_EOF
  1198. >echo "End of  part 1"
  1199. >echo "File itlib.icn is continued in part 2"
  1200. >echo "2" > shar3_seq_.tmp
  1201. >exit 0
  1202. >
  1203. >   -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1204. >   goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1205.  
  1206. ---- Cut Here and unpack ----
  1207. #!/bin/sh
  1208. # this is hebcalen.02 (part 2 of a multipart archive)
  1209. # do not concatenate these parts, unpack them in order with /bin/sh
  1210. # file itlib.icn continued
  1211. #
  1212. if test ! -r shar3_seq_.tmp; then
  1213.     echo "Please unpack part 1 first!"
  1214.     exit 1
  1215. fi
  1216. (read Scheck
  1217.  if test "$Scheck" != 2; then
  1218.     echo "Please unpack part $Scheck next!"
  1219.     exit 1
  1220.  else
  1221.     exit 0
  1222.  fi
  1223. ) < shar3_seq_.tmp || exit 1
  1224. echo "x - Continuing file itlib.icn"
  1225. sed 's/^X//' << 'SHAR_EOF' >> itlib.icn &&
  1226. X    then f := open(termcap_string)
  1227. X    /f := open("/etc/termcap") |
  1228. X        er("getentry","I can't access your /etc/termcap file",1)
  1229. X
  1230. X    getline := create read_file(f)
  1231. X    
  1232. X    while line := @getline do {
  1233. X        if line ? (pos(1) | tab(find("|")+1), =name, any(':|')) then {
  1234. X        entry := ""
  1235. X        while (\line | @getline) ? {
  1236. X            if entry ||:= 1(tab(find(":")+1), pos(0))
  1237. X            then {
  1238. X            close(f)
  1239. X            entry ?:= tab(find("tc=")) ||
  1240. X                (move(3), getentry(tab(find(":"))) ?
  1241. X                     (tab(find(":")+1), tab(0)))
  1242. X            return entry
  1243. X            }
  1244. X            else {
  1245. X            \line := &null # must precede the next line
  1246. X            entry ||:= tab(-2)
  1247. X            }
  1248. X        }
  1249. X        }
  1250. X    }
  1251. X    }
  1252. X
  1253. X    close(f)
  1254. X    er("getentry","can't find and/or process your termcap entry",3)
  1255. Xend
  1256. X
  1257. X
  1258. X
  1259. Xprocedure read_file(f)
  1260. X
  1261. X    # Suspends all non #-initial lines in the file f.
  1262. X    # Removes leading tabs and spaces from lines before suspending
  1263. X    # them.
  1264. X
  1265. X    local line
  1266. X
  1267. X    \f | er("read_tcap_file","no valid termcap file found",3)
  1268. X    while line := read(f) do {
  1269. X    match("#",line) & next
  1270. X    line ?:= (tab(many('\t ')) | &null, tab(0))
  1271. X    suspend line
  1272. X    }
  1273. X
  1274. X    fail
  1275. X
  1276. Xend
  1277. X
  1278. X
  1279. X
  1280. Xprocedure maketc_table(entry)
  1281. X
  1282. X    # Maketc_table(s) (where s is a valid termcap entry for some
  1283. X    # terminal-type): Returns a table in which the keys are termcap
  1284. X    # capability designators, and the values are the entries in
  1285. X    # "entry" for those designators.
  1286. X
  1287. X    local k, v
  1288. X
  1289. X    /entry & er("maketc_table","no entry given",8)
  1290. X    if entry[-1] ~== ":" then entry ||:= ":"
  1291. X    
  1292. X    tc_table := table()
  1293. X
  1294. X    entry ? {
  1295. X
  1296. X    tab(find(":")+1)    # tab past initial (name) field
  1297. X
  1298. X    while tab(find(":")+1) ? {
  1299. X
  1300. X        &subject == "" &next
  1301. X        if k := 1(move(2), ="=")
  1302. X        then /tc_table[k] := decode(tab(find(":")))
  1303. X        else if k := 1(move(2), ="#")
  1304. X        then /tc_table[k] := integer(tab(find(":")))
  1305. X        else if k := 1(tab(find(":")), pos(-1))
  1306. X        then /tc_table[k] := true()
  1307. X        else er("maketc_table", "your termcap file has a bad entry",3)
  1308. X
  1309. X    }
  1310. X    }
  1311. X
  1312. X    return tc_table
  1313. X
  1314. Xend
  1315. X
  1316. X
  1317. X
  1318. Xprocedure getval(id)
  1319. X
  1320. X    /tc_table := maketc_table(getentry(getname())) |
  1321. X    er("getval","can't make a table for your terminal",4)
  1322. X
  1323. X    return \tc_table[id] | fail
  1324. X    # er("getval","the current terminal doesn't support "||id,7)
  1325. X
  1326. Xend
  1327. X
  1328. X
  1329. X
  1330. Xprocedure decode(s)
  1331. X
  1332. X    new_s := ""
  1333. X
  1334. X    s ? {
  1335. X    while new_s ||:= tab(upto('\\^')) do {
  1336. X        chr := move(1)
  1337. X        if chr == "\\" then {
  1338. X        new_s ||:= {
  1339. X            case chr2 := move(1) of {
  1340. X            "\\" : "\\"
  1341. X            "^"  : "^"
  1342. X            "E"  : "\e"
  1343. X            "b"  : "\b"
  1344. X            "f"  : "\f"
  1345. X            "n"  : "\n"
  1346. X            "r"  : "\r"
  1347. X            "t"  : "\t"
  1348. X            default : {
  1349. X                if any(&digits,chr2) then {
  1350. X                char(integer("8r"||chr2||move(2 to 0 by -1))) |
  1351. X                    er("decode","bad termcap entry",3)
  1352. X                }
  1353. X               else chr2
  1354. X            }
  1355. X            }
  1356. X        }
  1357. X        }
  1358. X        else new_s ||:= char(ord(map(move(1),&lcase,&ucase)) - 64)
  1359. X    }
  1360. X    new_s ||:= tab(0)
  1361. X    }
  1362. X
  1363. X    return new_s
  1364. X
  1365. Xend
  1366. X
  1367. X
  1368. X
  1369. Xprocedure igoto(cm,col,line)
  1370. X
  1371. X    local colline, range, increment, str, outstr, chr, x, y
  1372. X
  1373. X    if col > (tc_table["co"]) | line > (tc_table["li"]) then {
  1374. X    colline := string(\col) || "," || string(\line) | string(\col|line)
  1375. X    range := "(" || tc_table["co"]-1 || "," || tc_table["li"]-1 || ")"
  1376. X    er("igoto",colline || " out of range " || (\range|""),9)
  1377. X    } 
  1378. X
  1379. X    # Use the Iconish 1;1 upper left corner & not the C-ish 0 offsets
  1380. X    increment := -1
  1381. X    outstr := ""
  1382. X    
  1383. X    cm ? {
  1384. X    while outstr ||:= tab(find("%")) do {
  1385. X        tab(match("%"))
  1386. X        chr := move(1)
  1387. X        if case chr of {
  1388. X        "." :  outstr ||:= char(line + increment)
  1389. X        "+" :  outstr ||:= char(line + ord(move(1)) + increment)
  1390. X        "d" :  {
  1391. X            str := string(line + increment)
  1392. X            outstr ||:= right(str, integer(tab(any('23'))), "0") | str
  1393. X        }
  1394. X        }
  1395. X        then line :=: col
  1396. X        else {
  1397. X        case chr of {
  1398. X            "n" :  line := ixor(line,96) & col := ixor(col,96)
  1399. X            "i" :  increment := 0
  1400. X            "r" :  line :=: col
  1401. X            "%" :  outstr ||:= "%"
  1402. X            "B" :  line := ior(ishift(line / 10, 4), line % 10)
  1403. X            ">" :  {
  1404. X            x := move(1); y := move(1)
  1405. X            line > ord(x) & line +:= ord(y)
  1406. X            &null
  1407. X            }
  1408. X        } | er("goto","bad termcap entry",5)
  1409. X        }
  1410. X    }
  1411. X    return outstr || tab(0)
  1412. X    }
  1413. X
  1414. Xend
  1415. X
  1416. X
  1417. X
  1418. Xprocedure iputs(cp, affcnt)
  1419. X
  1420. X    local baud_rates, char_rates, i, delay, PC
  1421. X    static num_chars, char_times
  1422. X    # global tty_speed
  1423. X
  1424. X    initial {
  1425. X    num_chars := &digits ++ '.'
  1426. X    char_times := table()
  1427. X    baud_rates := [0,300,600,1200,1800,2400,4800,9600,19200]
  1428. X    char_rates := [0,333,166,83,55,41,20,10,5]
  1429. X    every i := 1 to *baud_rates do {
  1430. X        char_times[baud_rates[i]] := char_rates[i]
  1431. X    }
  1432. X    }
  1433. X
  1434. X    type(cp) == "string" |
  1435. X    er("iputs","you can't iputs() a non-string value!",10)
  1436. X
  1437. X    cp ? {
  1438. X    delay := tab(many(num_chars))
  1439. X    if ="*" then {
  1440. X        delay *:= \affcnt |
  1441. X        er("iputs","affected line count missing",6)
  1442. X    }
  1443. X    writes(tab(0))
  1444. X    }
  1445. X
  1446. X    if (\delay, tty_speed ~= 0) then {
  1447. X    PC := tc_table["pc"] | "\000"
  1448. X    char_time := char_times[tty_speed] | (return "speed error")
  1449. X    delay := (delay * char_time) + (char_time / 2)
  1450. X    every 1 to delay by 10
  1451. X    do writes(PC)
  1452. X    }
  1453. X
  1454. X    return
  1455. X
  1456. Xend
  1457. SHAR_EOF
  1458. echo "File itlib.icn is complete" &&
  1459. # ============= hebcalen.hlp ==============
  1460. echo "x - extracting hebcalen.hlp (Text)"
  1461. sed 's/^X//' << 'SHAR_EOF' > hebcalen.hlp &&
  1462. X
  1463. XThis program accepts a year of the Jewish calendar, for example
  1464. X"5750", and produces on the screen a calendar of that year with a 
  1465. Xvisually equivalent civil calendar opposite it for easy conversion of 
  1466. Xdates. The months of the civil year are abbreviated to
  1467. X
  1468. XJAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
  1469. X
  1470. Xand of the Jewish calendar to
  1471. X
  1472. XNIS IYA SIV TAM AV ELU TIS HES KIS TEV SHE ADA AD2.
  1473. X
  1474. XMonths are normally displayed three at a time. You call up the next
  1475. Xthree by hitting return. At the end of the year you can indicate if
  1476. Xyou wish the program to conclude, by hitting return again. If in
  1477. Xresponse to the question, Do you wish to continue? you enter "y" and
  1478. Xhit return, the next year will be displayed.
  1479. X
  1480. XEach Jewish month has its name on the left. The corresponding secular
  1481. Xdates will have the name of the month on the right, and when the month
  1482. Xchanges it will be indicated on the right also.
  1483. X
  1484. XIf you wish, you may enter a civil year in the form -70 for BCE dates
  1485. Xand +70 for CE dates. The Jewish year beginning prior to Jan 1 of that
  1486. Xyear will be displayed, and you can continue with the next Jewish year
  1487. Xif you wish to complete the desired civil year.
  1488. X
  1489. XYou may enter CE or AD instead of + or BC or BCE instead of the minus
  1490. Xsign if you wish. It is best to avoid spaces, so enter 1987AD, for
  1491. Xexample.
  1492. X
  1493. XThe year 0 is not meaningful in either calendar. No date prior to 1 
  1494. Xin the Jewish calendar should be entered. The program will calculate
  1495. Xany future year, but will take longer for years much beyond the year
  1496. X6020 in the Jewish reckoning. For example, the year 7000 will take
  1497. Xthree minutes or so to appear. Earlier years should appear in a few
  1498. Xseconds.
  1499. X
  1500. XA status line at the bottom of the screen indicates the civil and
  1501. XJewish year, and the number of days in each. Jewish years may contain
  1502. X354, 355, 356, 384, 385 or 386 days according to circumstances.
  1503. X
  1504. XWhen you are familiar with this program you can enter the years you
  1505. Xwish to see on the command line. For example, if you call the program
  1506. X
  1507. X        iconx calendar 5704 +1987 1BC
  1508. X
  1509. Xyou will see in turn the Jewish year 5704, the Jewish year commencing
  1510. Xin 1986 and the Jewish year commencing in 2 B.C.E. You still have the
  1511. Xoption of seeing the years subsequent to these years if you wish. Just
  1512. Xenter "y" when asked if you want to continue. When you enter "n", you
  1513. Xwill get the next year of your list.
  1514. X
  1515. XAll civil dates are according to the Gregorian Calendar which first
  1516. Xcame into use in 1582 and was accepted in different places at
  1517. Xdifferent times. Prior to that date the Julian calendar was in use. At
  1518. Xthe present time the Julian calendar is 13 days behind the Gregorian
  1519. XCalendar, so that March 15 1917 in our reckoning is March 2 in the
  1520. XJulian Calendar. The following table shows the number of days that
  1521. Xmust be subtracted from the Gregorian date given here to find the Julian
  1522. Xdate. In the early centuries of this table and before the calendar was
  1523. Xintercalated erratically, so a simple subtraction is not possible. Note that
  1524. Xthe change in the number to subtract applies from March 1 in the century
  1525. Xyear, since in the Julian Calendar that will be February 29 except in years
  1526. Xdivisible by 400 which are leap years in the Gregorian calendar also.
  1527. X
  1528. XCentury          # to subtract         Century          # to subtract
  1529. X  21                    13                11                    6
  1530. X  20                    13                10                    5
  1531. X  19                    12                 9                     4
  1532. X  18                    11                 8                     4
  1533. X  17                    10                 7                     3
  1534. X  16                    10                 6                     2
  1535. X  15                     9                 5                     1
  1536. X  14                     8                 4                     1
  1537. X  13                     7                 3                     0
  1538. X  12                     7                 2                    -1
  1539. X                                           1                    -2
  1540. X
  1541. X
  1542. SHAR_EOF
  1543. # ============= hebcalen.dat ==============
  1544. echo "x - extracting hebcalen.dat (Text)"
  1545. sed 's/^X//' << 'SHAR_EOF' > hebcalen.dat &&
  1546. X3%8255%8%20%-3762%384
  1547. X4%23479%9%8%-3742%354
  1548. X4%24950%8%28%-3722%354
  1549. X5%501%8%17%-3702%385
  1550. X6%15725%9%6%-3682%355
  1551. X6%17196%8%26%-3662%355
  1552. X6%18667%8%15%-3642%383
  1553. X1%7971%9%3%-3622%353
  1554. X1%9442%8%23%-3602%383
  1555. X2%24666%9%10%-3582%354
  1556. X3%217%8%30%-3562%354
  1557. X3%1688%8%19%-3542%384
  1558. X4%16912%9%7%-3522%354
  1559. X4%18383%8%27%-3502%354
  1560. X4%19854%8%17%-3482%385
  1561. X6%9158%9%5%-3462%355
  1562. X6%10629%8%25%-3442%355
  1563. X6%12100%8%14%-3422%383
  1564. X1%1404%9%2%-3402%353
  1565. X1%2875%8%23%-3382%383
  1566. X2%18099%9%10%-3362%354
  1567. X2%19570%8%30%-3342%354
  1568. X2%21041%8%19%-3322%384
  1569. X4%10345%9%7%-3302%354
  1570. X4%11816%8%28%-3282%354
  1571. X4%13287%8%17%-3262%385
  1572. X6%2591%9%5%-3242%353
  1573. X6%4062%8%25%-3222%383
  1574. X7%19286%9%11%-3202%355
  1575. X7%20757%9%2%-3182%353
  1576. X7%22228%8%22%-3162%383
  1577. X2%11532%9%8%-3142%355
  1578. X2%13003%8%28%-3122%355
  1579. X2%14474%8%17%-3102%385
  1580. X4%3778%9%7%-3082%354
  1581. X4%5249%8%27%-3062%354
  1582. X4%6720%8%16%-3042%383
  1583. X5%21944%9%4%-3022%353
  1584. X5%23415%8%24%-3002%383
  1585. X7%12719%9%11%-2982%355
  1586. X7%14190%8%31%-2962%355
  1587. X7%15661%8%20%-2942%385
  1588. X2%4965%9%8%-2922%355
  1589. X2%6436%8%28%-2902%355
  1590. X2%7907%8%18%-2882%385
  1591. X3%23131%9%7%-2862%354
  1592. X3%24602%8%27%-2842%383
  1593. X5%13906%9%13%-2822%355
  1594. X5%15377%9%2%-2802%355
  1595. X5%16848%8%22%-2782%385
  1596. X7%6152%9%10%-2762%355
  1597. X7%7623%8%30%-2742%355
  1598. X7%9094%8%19%-2722%385
  1599. X1%24318%9%7%-2702%355
  1600. X1%25789%8%28%-2682%355
  1601. X2%1340%8%17%-2662%385
  1602. X3%16564%9%6%-2642%354
  1603. X3%18035%8%24%-2622%384
  1604. X5%7339%9%12%-2602%354
  1605. X5%8810%9%2%-2582%354
  1606. X5%10281%8%22%-2562%385
  1607. X6%25505%9%10%-2542%355
  1608. X7%1056%8%30%-2522%355
  1609. X7%2527%8%19%-2502%385
  1610. X1%17751%9%8%-2482%355
  1611. X1%19222%8%28%-2462%383
  1612. X3%8526%9%15%-2442%354
  1613. X3%9997%9%6%-2422%354
  1614. X3%11468%8%24%-2402%384
  1615. X5%772%9%12%-2382%354
  1616. X5%2243%9%1%-2362%354
  1617. X5%3714%8%21%-2342%385
  1618. X6%18938%9%9%-2322%355
  1619. X6%20409%8%29%-2302%355
  1620. X6%21880%8%19%-2282%383
  1621. X1%11184%9%7%-2262%355
  1622. X1%12655%8%27%-2242%383
  1623. X3%1959%9%14%-2222%354
  1624. X3%3430%9%3%-2202%354
  1625. X3%4901%8%24%-2182%384
  1626. X4%20125%9%12%-2162%354
  1627. X4%21596%9%1%-2142%354
  1628. X4%23067%8%21%-2122%385
  1629. X6%12371%9%9%-2102%355
  1630. X6%13842%8%30%-2082%383
  1631. X1%3146%9%18%-2062%353
  1632. X1%4617%9%7%-2042%353
  1633. X1%6088%8%27%-2022%383
  1634. X2%21312%9%14%-2002%354
  1635. X2%22783%9%3%-1982%354
  1636. X2%24254%8%23%-1962%384
  1637. X4%13558%9%11%-1942%354
  1638. X4%15029%8%31%-1922%354
  1639. X4%16500%8%20%-1902%385
  1640. X6%5804%9%9%-1882%353
  1641. X6%7275%8%29%-1862%383
  1642. X7%22499%9%17%-1842%353
  1643. X7%23970%9%6%-1822%353
  1644. X7%25441%8%26%-1802%383
  1645. X2%14745%9%13%-1782%355
  1646. X2%16216%9%2%-1762%355
  1647. X2%17687%8%22%-1742%385
  1648. X4%6991%9%11%-1722%354
  1649. X4%8462%8%31%-1702%383
  1650. X5%23686%9%20%-1682%353
  1651. X5%25157%9%9%-1662%353
  1652. X6%708%8%29%-1642%383
  1653. X7%15932%9%15%-1622%355
  1654. X7%17403%9%4%-1602%355
  1655. X7%18874%8%24%-1582%385
  1656. X2%8178%9%12%-1562%355
  1657. X2%9649%9%1%-1542%355
  1658. X2%11120%8%21%-1522%385
  1659. X4%424%9%10%-1502%354
  1660. X4%1895%8%31%-1482%383
  1661. X5%17119%9%17%-1462%355
  1662. X5%18590%9%6%-1442%355
  1663. X5%20061%8%28%-1422%383
  1664. X7%9365%9%14%-1402%355
  1665. X7%10836%9%4%-1382%355
  1666. X7%12307%8%24%-1362%385
  1667. X2%1611%9%12%-1342%355
  1668. X2%3082%9%1%-1322%385
  1669. X3%18306%9%21%-1302%354
  1670. X3%19777%9%11%-1282%354
  1671. X3%21248%8%31%-1262%383
  1672. X5%10552%9%17%-1242%355
  1673. X5%12023%9%6%-1222%355
  1674. X5%13494%8%26%-1202%385
  1675. X7%2798%9%14%-1182%355
  1676. X7%4269%9%3%-1162%355
  1677. X7%5740%8%23%-1142%385
  1678. X1%20964%9%11%-1122%355
  1679. X1%22435%8%31%-1102%385
  1680. X3%11739%9%21%-1082%354
  1681. X3%13210%9%10%-1062%354
  1682. X3%14681%8%28%-1042%384
  1683. X5%3985%9%16%-1022%354
  1684. X5%5456%9%5%-1002%354
  1685. X5%6927%8%26%-982%385
  1686. X6%22151%9%14%-962%355
  1687. X6%23622%9%3%-942%385
  1688. X1%12926%9%22%-922%355
  1689. X1%14397%9%11%-902%355
  1690. X1%15868%9%1%-882%383
  1691. X3%5172%9%19%-862%354
  1692. X3%6643%9%8%-842%354
  1693. X3%8114%8%28%-822%384
  1694. X4%23338%9%16%-802%354
  1695. X4%24809%9%5%-782%354
  1696. X5%360%8%25%-762%385
  1697. X6%15584%9%13%-742%355
  1698. X6%17055%9%2%-722%383
  1699. X1%6359%9%21%-702%353
  1700. X1%7830%9%11%-682%353
  1701. X1%9301%8%31%-662%383
  1702. X2%24525%9%18%-642%354
  1703. X3%76%9%7%-622%354
  1704. X3%1547%8%27%-602%384
  1705. X4%16771%9%16%-582%354
  1706. X4%18242%9%5%-562%385
  1707. X6%7546%9%24%-542%355
  1708. X6%9017%9%13%-522%353
  1709. X6%10488%9%2%-502%383
  1710. X7%25712%9%22%-482%353
  1711. X1%1263%9%11%-462%353
  1712. X1%2734%8%31%-442%383
  1713. X2%17958%9%18%-422%354
  1714. X2%19429%9%6%-402%355
  1715. X2%20900%8%27%-382%384
  1716. X4%10204%9%15%-362%354
  1717. X4%11675%9%4%-342%383
  1718. X6%979%9%23%-322%355
  1719. X6%2450%9%12%-302%353
  1720. X6%3921%9%2%-282%383
  1721. X7%19145%9%19%-262%355
  1722. X7%20616%9%10%-242%353
  1723. X7%22087%8%30%-222%383
  1724. X2%11391%9%16%-202%355
  1725. X2%12862%9%6%-182%385
  1726. X4%2166%9%26%-162%354
  1727. X4%3637%9%15%-142%354
  1728. X4%5108%9%4%-122%383
  1729. X5%20332%9%23%-102%353
  1730. X5%21803%9%13%-82%353
  1731. X5%23274%9%2%-62%383
  1732. X7%12578%9%19%-42%355
  1733. X7%14049%9%8%-22%355
  1734. X7%15520%8%28%-2%385
  1735. X2%4824%9%16%19%355
  1736. X2%6295%9%5%39%385
  1737. X3%21519%9%25%59%354
  1738. X3%22990%9%14%79%354
  1739. X3%24461%9%3%99%383
  1740. X5%13765%9%21%119%355
  1741. X5%15236%9%10%139%355
  1742. X5%16707%8%30%159%385
  1743. X7%6011%9%18%179%355
  1744. X7%7482%9%7%199%385
  1745. X1%22706%9%27%219%355
  1746. X1%24177%9%16%239%355
  1747. X1%25648%9%5%259%385
  1748. X3%14952%9%25%279%354
  1749. X3%16423%9%14%299%354
  1750. X3%17894%9%2%319%384
  1751. X5%7198%9%21%339%354
  1752. X5%8669%9%10%359%354
  1753. X5%10140%8%30%379%385
  1754. X6%25364%9%18%399%355
  1755. X7%915%9%7%419%385
  1756. X1%16139%9%26%439%355
  1757. X1%17610%9%15%459%355
  1758. X1%19081%9%4%479%383
  1759. X3%8385%9%22%499%354
  1760. X3%9856%9%12%519%354
  1761. X3%11327%9%1%539%384
  1762. X5%631%9%20%559%354
  1763. X5%2102%9%9%579%385
  1764. X6%17326%9%28%599%355
  1765. X6%18797%9%18%619%355
  1766. X6%20268%9%7%639%383
  1767. X1%9572%9%26%659%353
  1768. X1%11043%9%15%679%355
  1769. X1%12514%9%4%699%383
  1770. X3%1818%9%23%719%354
  1771. X3%3289%9%12%739%354
  1772. X3%4760%9%1%759%384
  1773. X4%19984%9%20%779%354
  1774. X4%21455%9%9%799%385
  1775. X6%10759%9%28%819%355
  1776. X6%12230%9%17%839%355
  1777. X6%13701%9%6%859%383
  1778. X1%3005%9%25%879%353
  1779. X1%4476%9%14%899%353
  1780. X1%5947%9%4%919%383
  1781. X2%21171%9%22%939%354
  1782. X2%22642%9%11%959%384
  1783. X4%11946%9%30%979%354
  1784. X4%13417%9%19%999%354
  1785. X4%14888%9%9%1019%385
  1786. X6%4192%9%28%1039%355
  1787. X6%5663%9%17%1059%353
  1788. X6%7134%9%6%1079%383
  1789. X7%22358%9%25%1099%353
  1790. X7%23829%9%15%1119%353
  1791. X7%25300%9%4%1139%383
  1792. X2%14604%9%21%1159%355
  1793. X2%16075%9%10%1179%385
  1794. X4%5379%9%30%1199%354
  1795. X4%6850%9%19%1219%354
  1796. X4%8321%9%8%1239%383
  1797. X5%23545%9%27%1259%353
  1798. X5%25016%9%16%1279%353
  1799. X6%567%9%5%1299%383
  1800. X7%15791%9%23%1319%355
  1801. X7%17262%9%12%1339%385
  1802. X2%6566%10%1%1359%355
  1803. X2%8037%9%20%1379%355
  1804. X2%9508%9%9%1399%385
  1805. X3%24732%9%30%1419%354
  1806. X4%283%9%19%1439%354
  1807. X4%1754%9%8%1459%383
  1808. X5%16978%9%25%1479%355
  1809. X5%18449%9%14%1499%355
  1810. X5%19920%9%6%1519%383
  1811. X7%9224%9%23%1539%355
  1812. X7%10695%9%12%1559%385
  1813. X1%25919%10%1%1579%355
  1814. X2%1470%9%20%1599%355
  1815. X2%2941%9%9%1619%385
  1816. X3%18165%9%29%1639%354
  1817. X3%19636%9%18%1659%354
  1818. X3%21107%9%7%1679%383
  1819. X5%10411%9%24%1699%355
  1820. X5%11882%9%14%1719%385
  1821. X7%1186%10%3%1739%355
  1822. X7%2657%9%22%1759%355
  1823. X7%4128%9%11%1779%385
  1824. X1%19352%9%30%1799%355
  1825. X1%20823%9%20%1819%355
  1826. X1%22294%9%9%1839%385
  1827. X3%11598%9%29%1859%354
  1828. X3%13069%9%18%1879%354
  1829. X3%14540%9%5%1899%384
  1830. X5%3844%9%25%1919%354
  1831. X5%5315%9%14%1939%385
  1832. X6%20539%10%3%1959%355
  1833. X6%22010%9%22%1979%355
  1834. X6%23481%9%11%1999%385
  1835. X1%12785%9%30%2019%355
  1836. X1%14256%9%19%2039%355
  1837. X1%15727%9%8%2059%383
  1838. X3%5031%9%26%2079%354
  1839. X3%6502%9%15%2099%384
  1840. X4%21726%10%5%2119%354
  1841. X4%23197%9%24%2139%354
  1842. X4%24668%9%13%2159%385
  1843. X6%13972%10%2%2179%355
  1844. X6%15443%9%21%2199%355
  1845. X6%16914%9%11%2219%383
  1846. X1%6218%9%30%2239%353
  1847. SHAR_EOF
  1848. # ============= README ==============
  1849. echo "x - extracting README (Text)"
  1850. sed 's/^X//' << 'SHAR_EOF' > README &&
  1851. XFor the bold in heart:  Type in "cp Makefile.dist Makefile; make" and
  1852. Xwatch the sparks fly.  When done, type "hebcalen."  If you are satis-
  1853. Xfied that it works, exit, then su root, and then type "make install."
  1854. X
  1855. XThis archive contains a test Unix port of Alan Corre's Jewish/Civil
  1856. Xcalendar for MS-DOS.  My changes to his code are extensive, and yet
  1857. Xmundane.  Mainly I just rewrote the input/output routines so that they
  1858. Xwould be portable in a Unix environment, and would work with all the
  1859. Xnon-cookie terminals I have access to (e.g. VT100, ANSI, IBM 3101).  In
  1860. Xparticular, I made sure to eliminate all assumptions about terminal
  1861. Xlength, width, and ability to display standout and/or underline modes.
  1862. XI also removed all characters which would require an unsigned internal
  1863. Xrepresentation (i.e. 8-bits).
  1864. X
  1865. XProbably the only really substantial changes I made were to add some
  1866. Xconvenient defaults.  For instance, if you press CR at the
  1867. Xinstructions prompt, you'll move on automatically to the year prompt.
  1868. XIf you press CR at the year prompt, hebcalen assumes that you want the
  1869. Xcurrent civil year.  Most of the prompts let you type "q" if you want
  1870. Xto quit at that point.  Another added default is a search mechanism
  1871. Xfor data files.  As long as the hebcalen data files are in your path,
  1872. Xyou no longer need to have them in the current directory when hebcalen
  1873. Xis invoked.  These changes represent mere conveniences, and do not
  1874. Xalter the substance of the original distribution.
  1875. X
  1876. XFrom a packaging standpoint, the original calendar program has been
  1877. Xtotally redone.  The original single file has been broken down into
  1878. Xits constituent parts, and renamed "hebcalen" so as to avoid naming
  1879. Xconflicts with tickler programs extant on many Unix systems.  I've
  1880. Xalso added a Makefile to ease the pains of installation and
  1881. Xmaintenance.  Just rename or copy Makefile.dist to Makefile, type
  1882. X"make," and then give the program a few trial runs.  When satisfied it
  1883. Xworks fine, then type "make install."  Make sure, before you do this,
  1884. Xthat you edit the makefile to reflect your local file structure.
  1885. X
  1886. XThe original distribution is included as cal.text.  Please keep it
  1887. Xaround if you plan to do any hacking, or even perusal of the code.
  1888. XIt's a nice piece of work.
  1889. X
  1890. XMany, many thanks to Alan Corre for a well-written and useful contri-
  1891. Xbution to the Icon community's code pool.
  1892. X
  1893. X
  1894. X   -Richard L. Goerwitz          goer%sophist@uchicago.bitnet
  1895. X   goer@sophist.uchicago.edu     rutgers!oddjob!gide!sophist!goer
  1896. X
  1897. SHAR_EOF
  1898. # ============= Makefile.dist ==============
  1899. echo "x - extracting Makefile.dist (Text)"
  1900. sed 's/^X//' << 'SHAR_EOF' > Makefile.dist &&
  1901. X# If you don't like this name, change it here and in the source
  1902. X# files.  In particular, don't forget to do a global search and
  1903. X# replace in hebcalen.icn, and don't forget to rename all the
  1904. X# data files!
  1905. XPROGNAME = hebcalen
  1906. X
  1907. X# Please edit these to reflect your local file structure.
  1908. XDESTDIR = /usr/local/bin
  1909. XDATA_DIR = /usr/local/lib/$(PROGNAME)
  1910. XOWNER = bin
  1911. XGROUP = bin
  1912. X
  1913. X# Itlib.icn is an Icon termlib package I added to facilitate
  1914. X# porting the package to Unix.  It is not part of the original
  1915. X# distribution.
  1916. XSRC = $(PROGNAME).icn itlib.icn
  1917. XDATA = $(PROGNAME).hlp $(PROGNAME).dat
  1918. XOTHER = README Makefile
  1919. X
  1920. X# I hope you won't have to use this.
  1921. X# DEBUGFLAG = -t
  1922. X
  1923. X# All this sh -c stuff is because some make programs can't specify
  1924. X# a default shell.  In those cases where it matters, I call sh.
  1925. X$(PROGNAME): $(SRC)
  1926. X    test -f $(PROGNAME).hlp
  1927. X    test -f $(PROGNAME).dat
  1928. X    @-sh -c "test -f cal.text || echo You've deleted cal.text\!\!"
  1929. X    icont $(DEBUGFLAG) -o $(PROGNAME) $(SRC)
  1930. X    @rm -f $(PROGNAME).icn
  1931. X
  1932. X$(PROGNAME).icn: $(PROGNAME).src
  1933. X    sh -c "sed \"s|/usr/local/lib/$(PROGNAME)|$(DATA_DIR)|g\" $(PROGNAME).src > $(PROGNAME).icn"
  1934. X
  1935. X# Pessimistic assumptions regarding the environment (in particular,
  1936. X# I don't assume you have the BSD "install" shell script).
  1937. Xinstall: $(PROGNAME)
  1938. X    @sh -c "test -d $(DESTDIR) || mkdir $(DESTDIR)"
  1939. X    cp $(PROGNAME) $(DESTDIR)/$(PROGNAME)
  1940. X    chgrp $(GROUP) $(DESTDIR)/$(PROGNAME)
  1941. X    chown $(OWNER) $(DESTDIR)/$(PROGNAME)
  1942. X    -mkdir $(DATA_DIR)
  1943. X    cp $(DATA) $(DATA_DIR)/
  1944. X    chgrp $(GROUP) $(DATA_DIR)
  1945. X    chown $(OWNER) $(DATA_DIR)
  1946. X    chgrp $(GROUP) $(DATA_DIR)/*
  1947. X    chown $(OWNER) $(DATA_DIR)/*
  1948. X    @echo "\nDone.\n"
  1949. X
  1950. Xclean:
  1951. X    -rm -f hebcalen
  1952. X    -rm -f *.u?
  1953. SHAR_EOF
  1954. # ============= cal.text ==============
  1955. echo "x - extracting cal.text (Text)"
  1956. sed 's/^X//' << 'SHAR_EOF' > cal.text &&
  1957. X#
  1958. X# This is the original calendar distribution for MS-DOS, as written
  1959. X# and packaged by Alan D. Corre.  Many thanks to him for an extremely
  1960. X# useful and well-written piece of software!  - RLG
  1961. X#
  1962. X
  1963. X#A VISUALLY EQUIVALENT JEWISH/CIVIL CALENDAR
  1964. X#ALAN D. CORRE, University of Wisonsin-Milwaukee
  1965. X#COPYRIGHT (c) 1990
  1966. X#Permission is hereby given to all persons to copy, compile and pass to
  1967. X#others this code provided that (1) it is not used for monetary gain; 
  1968. X#(2) it is not subverted from its original purpose, and is changed only
  1969. X#to the extent necessary to make it work on a different computer or terminal.
  1970. X#No guarantees are given or implied as to the correctness of information
  1971. X#furnished by this program.
  1972. X#Written in the beautiful Icon programming language. Further information from
  1973. X#icon-project@arizona.edu
  1974. X#If my math were longer this program would be shorter. Excuse me.
  1975. X#This work is respectfully devoted to the authors of two books consulted
  1976. X#with much profit: "A Guide to the Solar-Lunar Calendar" by B. Elihu Rothblatt
  1977. X#published by our sister Hebrew Dept. in Madison, Wis., and "Kiddush HaHodesh"
  1978. X#by Rabbenu Moses ben Maimon, on whom be peace.
  1979. X#The Jewish year harmonizes the solar and lunar cycle, using the 19-year cycle
  1980. X#of Meton (c. 432 BCE). It corrects so that certain dates shall not fall on
  1981. X#certain days for religious convenience. The Jewish year has six possible
  1982. X#lengths, 353,354,355,383,384,385 days, according to day and time of new
  1983. X#year lunation and position in Metonic cycle. Time figures from 6pm previous
  1984. X#night. The lunation of year 1 is calculated to be on a Monday (our Sunday
  1985. X#night) at ll:11:20pm. Our data table begins with a hypothetical year 0,
  1986. X#corresponding to 3762 B.C.E. Calculations in this program are figured in
  1987. X#the ancient Babylonian unit of halaqim "parts" of the hour = 1/1080 hour.
  1988. X#Version given here should work without change under MS-DOS. Hints are given
  1989. X#for modifying the code for other systems. Your MS-DOS should be sensitive to
  1990. X#ANSI screen controls. On many machines you may achieve this by having the
  1991. X#MS-DOS file ansi.sys available at boot time, and also a file called 
  1992. X#config.sys which contains the statement DEVICE=ANSI.SYS  Hints are offered
  1993. X#in case this is impossible.
  1994. X#Material consists of three sections separated by legend CUT HERE. This first
  1995. X#section should be placed in a file called calendar.icn. and compiled with
  1996. X#icont. Section two should be placed in a file called calendar.hlp.
  1997. X#The absence of this file will not impede the program. The information in 
  1998. X#this file is unsuitable for the Macintosh. I can supply an alternate file.
  1999. X#Section three should be placed in a file called calendar.dat. This file is
  2000. X#essential, and must contain no extraneous matter at the beginning.
  2001. X#Program is run under MS.DOS by entering the command:
  2002. X# iconx calendar
  2003. X#which may optionally be followed by the years desired in the form 5750
  2004. X#for a Jewish year +1990 or 1990AD or 1990CE or -1990 or 1990BC or
  2005. X#1990BCE for a civil year. On some systems iconx can be omitted.
  2006. X
  2007. Xrecord date(yr,mth,day)
  2008. Xrecord molad(day,halaqim)
  2009. Xglobal cyr,jyr,days_in_jyr,current_molad,current_day,infolist
  2010. X
  2011. Xprocedure main(cmd)
  2012. Xlocal COPYRIGHT
  2013. X#sticks around in memory
  2014. X  COPYRIGHT := "Copyright (c) Alan D. Corre 1990"
  2015. X#an acute accent on my e will be appreciated if available
  2016. X  clear()
  2017. X  banner("PERPETUAL JEWISH/CIVIL CALENDAR","","by","","ALAN D. CORRE")
  2018. X  write("\n\nCopyright (c) Alan D. Corre 1990")
  2019. X  if *cmd = 0 then {
  2020. X#putting an asterisk indicates that user might need help
  2021. X    n := 1; put(cmd,"*")} else
  2022. X    n := *cmd
  2023. X    every p := 1 to n do {
  2024. X  initialize(cmd[p])
  2025. X  process()}
  2026. Xend
  2027. X
  2028. Xprocedure banner(l[])
  2029. X#Creates a banner to begin programs. If you don't have the extended ASCII
  2030. X#character set, replace each char(n) with some character that you have
  2031. X#such as " " or "-"
  2032. X#Does not work well if your screen has variable spacing.
  2033. Xlocal n
  2034. X  write();write();write()
  2035. X  writes(char(201)) #top left right angle
  2036. X  writes(repl(char(205),78)) #straight line
  2037. X  writes(char(187)) #top right right angle
  2038. X  writes(char(186)) #upright line at left
  2039. X  writes(right(char(186),79)) #upright line at right
  2040. X  every n := 1 to *l do {
  2041. X    writes(char(186)) #upright line at left
  2042. X    writes(center(l[n],78),char(186)) #string centered followed by upright line
  2043. X    writes(char(186)) #upright line at left
  2044. X    writes(right(char(186),79)) #upright line at right
  2045. X}
  2046. X  writes(char(200)) #bottom left right angle
  2047. X  writes(repl(char(205),78)) #straight line
  2048. X  write(char(188)) #bottom right right angle
  2049. X  write()
  2050. Xreturn
  2051. Xend
  2052. X
  2053. Xprocedure instructions(filename)
  2054. X#Gives user access to a help file which is printed out in chunks.
  2055. Xlocal filvar,counter,line
  2056. X  writes("Do you need instructions? y/n ")
  2057. X  if upto('yY',read()) then {
  2058. X#The following if-statement fails if the file is not available
  2059. X  counter := 0
  2060. X  if filvar := open(filename) then
  2061. X#Read the help file. 
  2062. X    while line := read(filvar) do {
  2063. X#Write out a line and increment the counter
  2064. X      write(line)
  2065. X      counter +:= 1
  2066. X#Now we have a screenful; ask if we should continue
  2067. X      if counter >22 then {
  2068. X        write()
  2069. X        writes ("More? y/n ")
  2070. X#User has had enough; break out of loop
  2071. X        if upto('nN',read()) then break  else
  2072. X#User wants more; reset counter and continue
  2073. X          counter := 0}} else
  2074. X#This else goes with the second if-statement; the attempt to open the
  2075. X#help file failed:
  2076. X      write("Sorry, instructions not available.")}
  2077. X    write ("Press return to continue.")
  2078. X    read()
  2079. X#Close the file if it existed and was opened. If it was never opened
  2080. X#the value of filvar will be null. This check has to be made because
  2081. X#an attempt to use close() on a variable NOT valued at a file would
  2082. X#cause an error. 
  2083. X/filvar | close(filvar)
  2084. Xend
  2085. X
  2086. Xprocedure clear()
  2087. X#clears the screen. If you dont have ANSI omit the next line
  2088. X  writes("\e[2J")
  2089. Xend
  2090. X
  2091. Xprocedure initialize_list()
  2092. X#while user views banner, put info of calendar.dat into a global list
  2093. Xlocal infile,n
  2094. X  infolist := list(301)
  2095. X  if not (infile := open("calendar.dat")) then
  2096. X    stop("This program must have the file CALENDAR.DAT on line in order to _
  2097. X          function properly.")    
  2098. X#the table is arranged arbitrarily at twenty year intervals with 301 entries.
  2099. X  every n := 1 to 301 do
  2100. X    infolist[n] := read(infile)
  2101. X  close(infile)
  2102. Xend
  2103. X
  2104. Xprocedure initialize_variables()
  2105. X#get the closest previous year in the table
  2106. Xlocal line,quotient
  2107. X  quotient := jyr.yr / 20 + 1
  2108. X#only 301 entries. Figure from last if necessary.
  2109. X  if quotient > 301 then quotient := 301
  2110. X#pull the appropriate info, put into global variables
  2111. X  line := infolist[quotient]
  2112. X  line ? { current_molad.day := tab(upto('%'))
  2113. X         move(1)
  2114. X     current_molad.halaqim := tab(upto('%'))
  2115. X     move(1)
  2116. X     cyr.mth := tab(upto('%'))
  2117. X     move(1)
  2118. X     cyr.day := tab(upto('%'))
  2119. X     move(1)
  2120. X     cyr.yr := tab(upto('%'))
  2121. X     days_in_jyr := line[-3:0]
  2122. X     }
  2123. X#begin at rosh hashana
  2124. X  jyr.day := 1
  2125. X  jyr.mth := 7
  2126. Xreturn
  2127. Xend
  2128. X
  2129. Xprocedure initialize(yr)
  2130. Xlocal year
  2131. X#initialize global variables
  2132. Xinitial {  cyr := date(0,0,0)
  2133. X  jyr := date(0,0,0)
  2134. X  current_molad := molad(0,0)
  2135. X  initialize_list()}
  2136. X  clear()
  2137. X#user may need help
  2138. X  if yr == "*" then {
  2139. X  instructions("CALENDAR.HLP")
  2140. X  clear()
  2141. X  writes("Please enter the year. If you are entering a CIVIL year, precede _
  2142. X         by + for \ncurrent era, - (the minus sign) for before current era. ")
  2143. X  year := read()} else
  2144. X  year := yr
  2145. X  while not (jyr.yr := cleanup(year)) do {
  2146. X    writes("I do not understand ",year,". Please try again ")
  2147. X    year := read()}
  2148. X  clear()
  2149. X  initialize_variables()
  2150. Xreturn
  2151. Xend
  2152. X
  2153. Xprocedure cleanup(str)
  2154. X#tidy up the string. Bugs still possible.
  2155. X  if (not upto('.+-',str)) & integer(str) & (str > 0) then return str
  2156. X  if upto('-bB',str) then return (0 < (3761 - checkstr(str)))
  2157. X  if upto('+cCaA',str) then return (checkstr(str) + 3760)
  2158. Xfail
  2159. Xend
  2160. X
  2161. Xprocedure checkstr(s)
  2162. X#does preliminary work on string before cleanup() cleans it up
  2163. Xlocal letter,n,newstr
  2164. X  newstr := ""
  2165. X  every n := 1 to *s do
  2166. X    if integer(s[n]) then
  2167. X      newstr ||:= s[n]
  2168. X  if (*newstr = 0) | (newstr = 0) then fail
  2169. Xreturn newstr
  2170. Xend
  2171. X
  2172. Xprocedure process()
  2173. X#gets out the information
  2174. Xlocal limit,dj,dc
  2175. X#6039 is last year handled by the table in the usual way
  2176. X  if jyr.yr <= 6039 then {
  2177. X    limit := jyr.yr % 20 
  2178. X    jyr.yr := ((jyr.yr / 20) * 20)} else {
  2179. X#otherwise figure from 6020 and good luck
  2180. X    limit := jyr.yr - 6020
  2181. X    jyr.yr := 6020}
  2182. X  ans := "y"
  2183. X  establish_jyr()
  2184. X  every 1 to limit do {
  2185. X#tell user something is going on
  2186. X    writes(" .")
  2187. X#increment the years, establish the type of Jewish year
  2188. X    cyr_augment()
  2189. X    jyr_augment()
  2190. X    establish_jyr()}
  2191. X  clear() 
  2192. X  while upto('Yy',ans) do {
  2193. X  yj := jyr.yr
  2194. X  dj := days_in_jyr
  2195. X  every n := 1 to 4 do {
  2196. X    clear()
  2197. X    every 1 to 3 do
  2198. X      write_a_month()
  2199. X    write("Press the space bar to continue")
  2200. X    write()
  2201. X    writes(status_line(yj,dj))
  2202. X    getch()}
  2203. X    if jyr.mth = 6 then {
  2204. X      clear()
  2205. X      write_a_month()
  2206. X      every 1 to 15 do write()
  2207. X      write(status_line(yj,dj))}
  2208. X    write()
  2209. X    writes("Do you wish to continue? Enter y<es> or n<o>. ")
  2210. X    ans := getch()}
  2211. Xreturn
  2212. Xend
  2213. X
  2214. Xprocedure cyr_augment()
  2215. X#Make civil year a year later, we only need consider Aug,Sep,Nov.
  2216. Xlocal days,newmonth,newday
  2217. X if cyr.mth = 8 then
  2218. X   days := 0 else
  2219. X if cyr.mth = 9 then
  2220. X   days := 31 else
  2221. X if cyr.mth = 10 then
  2222. X   days := 61 else
  2223. X stop("Error in cyr_augment")
  2224. X  writes(" .")
  2225. X  days := (days + cyr.day-365+days_in_jyr)
  2226. X  if isleap(cyr.yr + 1) then days -:= 1
  2227. X#cos it takes longer to get there
  2228. X  if days <= 31 then {newmonth := 8; newday := days} else
  2229. X  if days <= 61 then {newmonth := 9; newday := days-31} else
  2230. X  {newmonth := 10; newday := days-61} 
  2231. X  cyr.mth := newmonth
  2232. X  cyr.day := newday
  2233. X  cyr.yr +:= 1
  2234. X  if cyr.yr = 0 then cyr.yr := 1
  2235. Xreturn
  2236. Xend
  2237. X
  2238. X
  2239. Xprocedure header()
  2240. X#creates the header for Jewish and English side. If ANSI not available,
  2241. X#substitute "S" for "\e[7mS\e[0m" each time.
  2242. SHAR_EOF
  2243. echo "End of  part 2"
  2244. echo "File cal.text is continued in part 3"
  2245. echo "3" > shar3_seq_.tmp
  2246. exit 0
  2247.  
  2248.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  2249.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  2250.