home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume21 / xcal / part02 < prev    next >
Encoding:
Text File  |  1993-12-22  |  52.8 KB  |  1,870 lines

  1. Newsgroups: comp.sources.x
  2. From: pc@hillside.co.uk (Peter Collinson)
  3. Subject: v21i077:  xcal - A calendar program for X, Part02/08
  4. Message-ID: <1993Dec21.161715.21816@sparky.sterling.com>
  5. X-Md4-Signature: 26af0fbcf6b0f9350ad7d699a4737af9
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Hillside Systems, 61 Hillside Avenue, Canterbury, Kent CT2 8HA
  8. Date: Tue, 21 Dec 1993 16:17:15 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: pc@hillside.co.uk (Peter Collinson)
  12. Posting-number: Volume 21, Issue 77
  13. Archive-name: xcal/part02
  14. Environment: X11
  15. Supersedes: xcal: Volume 12, Issue 101
  16.  
  17. Xcal is a calendar program. For more details see Part 1 of this posting
  18.  
  19. Part 2 of 8
  20. --shar starts here--
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then unpack
  23. # it by saving it into a file and typing "sh file".  To overwrite existing
  24. # files, type "sh file -c".  You can also feed this as standard input via
  25. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  26. # will see the following message at the end:
  27. #        "End of archive 2 (of 8)."
  28. # Contents:  XCal.help strftime/strftime.c strftime/tzfile.h xcal.h
  29. #   xcal_cal/xcal_cal.c xcal_days.c xcal_help.c xcalpr/xcal_days.c
  30. # Wrapped by pc@hillside on Wed Nov 17 11:24:35 1993
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'XCal.help' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'XCal.help'\"
  34. else
  35. echo shar: Extracting \"'XCal.help'\" \(4973 characters\)
  36. sed "s/^X//" >'XCal.help' <<'END_OF_FILE'
  37. XXCal.Help XCal.help 1.2 93/10/23
  38. X{strip
  39. XThe date strip consists of a number of lines of text. 
  40. X
  41. XLine 1:    The Month and the Year of the strip.
  42. X    The information may be duplicated in the window
  43. X    manager title line. In this case the line may be omitted
  44. X    by setting the resource `useWmTitle' to False.
  45. X
  46. XLine 2:    The main control buttons for the strip actioned by the
  47. X    left mouse button.
  48. X    <    Generates last month's strip in a separate window
  49. X    Quit    Close this script
  50. X    >    Generates next month's strip in a separate window
  51. X
  52. XLine 3: The Help button.
  53. X    Help can be suppressed by setting the resource `giveHelp' to False.
  54. X
  55. XThen -  A line for each day in the month.
  56. X
  57. X    Each line is two areas:
  58. X
  59. X    The left hand side shows the day in the month and the name of
  60. X    the day of the week. `Today' may be highlighted specially in
  61. X    this region.
  62. X
  63. X    The right hand side is an active button. When pressed it starts
  64. X    up an editor for the day. This will create a file for the day
  65. X    in the user's Calendar directory. The label on the button will
  66. X    be the first few characters of the file, if there are any.
  67. X
  68. X    You can paste selected characters into a day. Sweep out the
  69. X    characters that you want to load and click with the middle
  70. X    mouse button in the day of your choice. This is just like
  71. X    normal pasting of text. You will get a complaint if the day is
  72. X    already being edited.
  73. X
  74. XXCal was written by Peter Collinson (pc@hillside.co.uk)
  75. X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  76. X}
  77. X{edit
  78. XThis editing window will create or delete a day file for the day shown
  79. Xin the title. The file is stored in a directory specified by the
  80. Xresource `directory', this is usually `Calendar' in your home
  81. Xdirectory.
  82. X
  83. XCalendar will usually contain directories, one for each year, and the
  84. Xday file will be stored in one of these directories. However, this
  85. Xmakes xcal incompatible with xcalendar - so if the resource
  86. XxcalendarCompat is True then the use of subdirectories is suppressed.
  87. X
  88. XThe large area in the edit window is a normal text input area. Text is
  89. Xsimply be typed into it, the text is saved by hitting the save button
  90. Xwhich is set to sensitive when the text is changed.  Saving an empty
  91. Xbuffer will delete the file.  The Quit button will exit. Some more
  92. Xquestions will be asked if leaving will result in losing information.
  93. X
  94. XXCal was written by Peter Collinson (pc@hillside.co.uk)
  95. X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  96. X}
  97. X{memo
  98. XThe memo window is intended to do three things. First, it allows a
  99. Xsingle button click to display today's actions from your diary.
  100. XSecond, it provides a way of displaying regular weekly events.  Third,
  101. Xit provides an editable window whose contents can be saved in a file.
  102. XThe idea is that this file will contain reminders and other notes.  The
  103. Xfile is usually called `memo' and is stored in a directory specified by
  104. Xthe resource `directory', usually `Calendar' in your home directory.
  105. X
  106. XThe window is split into three areas. The top section shows the current
  107. Xdiary entry and cannot be altered by editing. Hit the edit button to
  108. Xstart a standard day editor window on today's date. The middle section
  109. Xshows the weekly entry. Again the edit button allows you to edit these
  110. XThe bottom section contains the memo file text area. Text is simply
  111. Xtyped into it and is stored saved by hitting the save button. This
  112. Xwill go black when the text is changed.
  113. XSaving an empty buffer will delete the file.
  114. X
  115. XThe Quit button will exit. Some more questions will be asked if
  116. Xleaving will result in losing information.
  117. X
  118. XXCal was written by Peter Collinson (pc@hillside.co.uk)
  119. X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  120. X}
  121. X{main
  122. XThe command box contains a number of buttons.
  123. X
  124. XMove the mouse into the area showing the date and use
  125. Xthe mouse buttons to select further actions:
  126. X
  127. X    - Left mouse button pops up this month's calendar strip
  128. X    - Middle mouse button permits date selection
  129. X    - Right mouse button allows exit
  130. X
  131. XClick with the left mouse button in the small box holding
  132. Xthe mouse icon to edit a memo file.
  133. X
  134. XThe Question Mark button shows this information, as you have already
  135. Xdiscovered.
  136. X
  137. XXCal was written by Peter Collinson (pc@hillside.co.uk)
  138. X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  139. X}
  140. X{weekly
  141. XThe weekly strip consists of a number of lines of text.
  142. X
  143. XLine 1: The title
  144. XLine 2: The Quit button that removes the strip from the screen
  145. XLine 3: The Help Button.
  146. X    Help can be suppressed by setting `giveHelp' to False.
  147. X
  148. XThen -  A line for each day in the week.
  149. X    Each line is two areas:
  150. X    The left hand side shows the day in the week
  151. X    The right hand side is an active button. When pressed it starts
  152. X    up an editor for the day. This will create a file for the day
  153. X    in the user's Calendar directory. The label on the button will
  154. X    be the first few characters of the file, if there are any.
  155. X
  156. XXCal was written by Peter Collinson
  157. X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  158. X}
  159. END_OF_FILE
  160. if test 4973 -ne `wc -c <'XCal.help'`; then
  161.     echo shar: \"'XCal.help'\" unpacked with wrong size!
  162. fi
  163. # end of 'XCal.help'
  164. fi
  165. if test -f 'strftime/strftime.c' -a "${1}" != "-c" ; then 
  166.   echo shar: Will not clobber existing file \"'strftime/strftime.c'\"
  167. else
  168. echo shar: Extracting \"'strftime/strftime.c'\" \(6862 characters\)
  169. sed "s/^X//" >'strftime/strftime.c' <<'END_OF_FILE'
  170. X/*
  171. X * Copyright (c) 1989 The Regents of the University of California.
  172. X * All rights reserved.
  173. X *
  174. X * Redistribution and use in source and binary forms, with or without
  175. X * modification, are permitted provided that the following conditions
  176. X * are met:
  177. X * 1. Redistributions of source code must retain the above copyright
  178. X *    notice, this list of conditions and the following disclaimer.
  179. X * 2. Redistributions in binary form must reproduce the above copyright
  180. X *    notice, this list of conditions and the following disclaimer in the
  181. X *    documentation and/or other materials provided with the distribution.
  182. X * 3. All advertising materials mentioning features or use of this software
  183. X *    must display the following acknowledgement:
  184. X *    This product includes software developed by the University of
  185. X *    California, Berkeley and its contributors.
  186. X * 4. Neither the name of the University nor the names of its contributors
  187. X *    may be used to endorse or promote products derived from this software
  188. X *    without specific prior written permission.
  189. X *
  190. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  191. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  192. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  193. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  194. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  195. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  196. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  197. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  198. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  199. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  200. X * SUCH DAMAGE.
  201. X */
  202. X
  203. X#if defined(LIBC_SCCS) && !defined(lint)
  204. Xstatic char sccsid[] = "@(#)strftime.c    5.11 (Berkeley) 2/24/91";
  205. X#endif /* LIBC_SCCS and not lint */
  206. X
  207. X#include <sys/types.h>
  208. X#include <sys/time.h>
  209. X#include <tzfile.h>
  210. X#include <string.h>
  211. X
  212. Xstatic char *afmt[] = {
  213. X    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
  214. X};
  215. Xstatic char *Afmt[] = {
  216. X    "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
  217. X    "Saturday",
  218. X};
  219. Xstatic char *bfmt[] = {
  220. X    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
  221. X    "Oct", "Nov", "Dec",
  222. X};
  223. Xstatic char *Bfmt[] = {
  224. X    "January", "February", "March", "April", "May", "June", "July",
  225. X    "August", "September", "October", "November", "December",
  226. X};
  227. X
  228. Xstatic size_t gsize;
  229. Xstatic char *pt;
  230. Xstatic int _add(), _conv(), _secs();
  231. X
  232. Xsize_t
  233. Xstrftime(s, maxsize, format, t)
  234. X    char *s;
  235. X    size_t maxsize;
  236. X    const char *format;
  237. X    const struct tm *t;
  238. X{
  239. X    static size_t _fmt();
  240. X
  241. X    pt = s;
  242. X    if ((gsize = maxsize) < 1)
  243. X        return(0);
  244. X    if (_fmt(format, t)) {
  245. X        *pt = '\0';
  246. X        return(maxsize - gsize);
  247. X    }
  248. X    return(0);
  249. X}
  250. X
  251. Xstatic size_t
  252. X_fmt(format, t)
  253. X    register char *format;
  254. X    struct tm *t;
  255. X{
  256. X    for (; *format; ++format) {
  257. X        if (*format == '%')
  258. X            switch(*++format) {
  259. X            case '\0':
  260. X                --format;
  261. X                break;
  262. X            case 'A':
  263. X                if (t->tm_wday < 0 || t->tm_wday > 6)
  264. X                    return(0);
  265. X                if (!_add(Afmt[t->tm_wday]))
  266. X                    return(0);
  267. X                continue;
  268. X            case 'a':
  269. X                if (t->tm_wday < 0 || t->tm_wday > 6)
  270. X                    return(0);
  271. X                if (!_add(afmt[t->tm_wday]))
  272. X                    return(0);
  273. X                continue;
  274. X            case 'B':
  275. X                if (t->tm_mon < 0 || t->tm_mon > 11)
  276. X                    return(0);
  277. X                if (!_add(Bfmt[t->tm_mon]))
  278. X                    return(0);
  279. X                continue;
  280. X            case 'b':
  281. X            case 'h':
  282. X                if (t->tm_mon < 0 || t->tm_mon > 11)
  283. X                    return(0);
  284. X                if (!_add(bfmt[t->tm_mon]))
  285. X                    return(0);
  286. X                continue;
  287. X            case 'C':
  288. X                if (!_fmt("%a %b %e %H:%M:%S %Y", t))
  289. X                    return(0);
  290. X                continue;
  291. X            case 'c':
  292. X                if (!_fmt("%m/%d/%y %H:%M:%S", t))
  293. X                    return(0);
  294. X                continue;
  295. X            case 'D':
  296. X                if (!_fmt("%m/%d/%y", t))
  297. X                    return(0);
  298. X                continue;
  299. X            case 'd':
  300. X                if (!_conv(t->tm_mday, 2, '0'))
  301. X                    return(0);
  302. X                continue;
  303. X            case 'e':
  304. X                if (!_conv(t->tm_mday, 2, ' '))
  305. X                    return(0);
  306. X                continue;
  307. X            case 'H':
  308. X                if (!_conv(t->tm_hour, 2, '0'))
  309. X                    return(0);
  310. X                continue;
  311. X            case 'I':
  312. X                if (!_conv(t->tm_hour % 12 ?
  313. X                    t->tm_hour % 12 : 12, 2, '0'))
  314. X                    return(0);
  315. X                continue;
  316. X            case 'j':
  317. X                if (!_conv(t->tm_yday + 1, 3, '0'))
  318. X                    return(0);
  319. X                continue;
  320. X            case 'k':
  321. X                if (!_conv(t->tm_hour, 2, ' '))
  322. X                    return(0);
  323. X                continue;
  324. X            case 'l':
  325. X                if (!_conv(t->tm_hour % 12 ?
  326. X                    t->tm_hour % 12 : 12, 2, ' '))
  327. X                    return(0);
  328. X                continue;
  329. X            case 'M':
  330. X                if (!_conv(t->tm_min, 2, '0'))
  331. X                    return(0);
  332. X                continue;
  333. X            case 'm':
  334. X                if (!_conv(t->tm_mon + 1, 2, '0'))
  335. X                    return(0);
  336. X                continue;
  337. X            case 'n':
  338. X                if (!_add("\n"))
  339. X                    return(0);
  340. X                continue;
  341. X            case 'p':
  342. X                if (!_add(t->tm_hour >= 12 ? "PM" : "AM"))
  343. X                    return(0);
  344. X                continue;
  345. X            case 'R':
  346. X                if (!_fmt("%H:%M", t))
  347. X                    return(0);
  348. X                continue;
  349. X            case 'r':
  350. X                if (!_fmt("%I:%M:%S %p", t))
  351. X                    return(0);
  352. X                continue;
  353. X            case 'S':
  354. X                if (!_conv(t->tm_sec, 2, '0'))
  355. X                    return(0);
  356. X                continue;
  357. X            case 's':
  358. X                if (!_secs(t))
  359. X                    return(0);
  360. X                continue;
  361. X            case 'T':
  362. X            case 'X':
  363. X                if (!_fmt("%H:%M:%S", t))
  364. X                    return(0);
  365. X                continue;
  366. X            case 't':
  367. X                if (!_add("\t"))
  368. X                    return(0);
  369. X                continue;
  370. X            case 'U':
  371. X                if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7,
  372. X                    2, '0'))
  373. X                    return(0);
  374. X                continue;
  375. X            case 'W':
  376. X                if (!_conv((t->tm_yday + 7 -
  377. X                    (t->tm_wday ? (t->tm_wday - 1) : 6))
  378. X                    / 7, 2, '0'))
  379. X                    return(0);
  380. X                continue;
  381. X            case 'w':
  382. X                if (!_conv(t->tm_wday, 1, '0'))
  383. X                    return(0);
  384. X                continue;
  385. X            case 'x':
  386. X                if (!_fmt("%m/%d/%y", t))
  387. X                    return(0);
  388. X                continue;
  389. X            case 'y':
  390. X                if (!_conv((t->tm_year + TM_YEAR_BASE)
  391. X                    % 100, 2, '0'))
  392. X                    return(0);
  393. X                continue;
  394. X            case 'Y':
  395. X                if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0'))
  396. X                    return(0);
  397. X                continue;
  398. X            case 'Z':
  399. X                if (!t->tm_zone || !_add(t->tm_zone))
  400. X                    return(0);
  401. X                continue;
  402. X            case '%':
  403. X            /*
  404. X             * X311J/88-090 (4.12.3.5): if conversion char is
  405. X             * undefined, behavior is undefined.  Print out the
  406. X             * character itself as printf(3) does.
  407. X             */
  408. X            default:
  409. X                break;
  410. X        }
  411. X        if (!gsize--)
  412. X            return(0);
  413. X        *pt++ = *format;
  414. X    }
  415. X    return(gsize);
  416. X}
  417. X
  418. Xstatic
  419. X_secs(t)
  420. X    struct tm *t;
  421. X{
  422. X    static char buf[15];
  423. X    register time_t s;
  424. X    register char *p;
  425. X    struct tm tmp;
  426. X
  427. X    /* Make a copy, mktime(3) modifies the tm struct. */
  428. X    tmp = *t;
  429. X    s = mktime(&tmp);
  430. X    for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
  431. X        *p-- = s % 10 + '0';
  432. X    return(_add(++p));
  433. X}
  434. X
  435. Xstatic
  436. X_conv(n, digits, pad)
  437. X    int n, digits;
  438. X    char pad;
  439. X{
  440. X    static char buf[10];
  441. X    register char *p;
  442. X
  443. X    for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
  444. X        *p-- = n % 10 + '0';
  445. X    while (p > buf && digits-- > 0)
  446. X        *p-- = pad;
  447. X    return(_add(++p));
  448. X}
  449. X
  450. Xstatic
  451. X_add(str)
  452. X    register char *str;
  453. X{
  454. X    for (;; ++pt, --gsize) {
  455. X        if (!gsize)
  456. X            return(0);
  457. X        if (!(*pt = *str++))
  458. X            return(1);
  459. X    }
  460. X}
  461. END_OF_FILE
  462. if test 6862 -ne `wc -c <'strftime/strftime.c'`; then
  463.     echo shar: \"'strftime/strftime.c'\" unpacked with wrong size!
  464. fi
  465. # end of 'strftime/strftime.c'
  466. fi
  467. if test -f 'strftime/tzfile.h' -a "${1}" != "-c" ; then 
  468.   echo shar: Will not clobber existing file \"'strftime/tzfile.h'\"
  469. else
  470. echo shar: Extracting \"'strftime/tzfile.h'\" \(5120 characters\)
  471. sed "s/^X//" >'strftime/tzfile.h' <<'END_OF_FILE'
  472. X/*
  473. X * Copyright (c) 1988 Regents of the University of California.
  474. X * All rights reserved.
  475. X *
  476. X * This code is derived from software contributed to Berkeley by
  477. X * Arthur David Olson of the National Cancer Institute.
  478. X *
  479. X * Redistribution and use in source and binary forms, with or without
  480. X * modification, are permitted provided that the following conditions
  481. X * are met:
  482. X * 1. Redistributions of source code must retain the above copyright
  483. X *    notice, this list of conditions and the following disclaimer.
  484. X * 2. Redistributions in binary form must reproduce the above copyright
  485. X *    notice, this list of conditions and the following disclaimer in the
  486. X *    documentation and/or other materials provided with the distribution.
  487. X * 3. All advertising materials mentioning features or use of this software
  488. X *    must display the following acknowledgement:
  489. X *    This product includes software developed by the University of
  490. X *    California, Berkeley and its contributors.
  491. X * 4. Neither the name of the University nor the names of its contributors
  492. X *    may be used to endorse or promote products derived from this software
  493. X *    without specific prior written permission.
  494. X *
  495. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  496. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  497. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  498. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  499. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  500. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  501. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  502. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  503. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  504. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  505. X * SUCH DAMAGE.
  506. X *
  507. X *    @(#)tzfile.h    5.10 (Berkeley) 4/3/91
  508. X */
  509. X
  510. X#ifndef _TZFILE_H_
  511. X#define    _TZFILE_H_
  512. X
  513. X/*
  514. X * Information about time zone files.
  515. X */
  516. X            /* Time zone object file directory */
  517. X#define TZDIR        "/usr/share/zoneinfo"
  518. X#define TZDEFAULT    "/etc/localtime"
  519. X#define TZDEFRULES    "posixrules"
  520. X
  521. X/*
  522. X** Each file begins with. . .
  523. X*/
  524. X
  525. Xstruct tzhead {
  526. X    char    tzh_reserved[24];    /* reserved for future use */
  527. X    char    tzh_ttisstdcnt[4];    /* coded number of trans. time flags */
  528. X    char    tzh_leapcnt[4];        /* coded number of leap seconds */
  529. X    char    tzh_timecnt[4];        /* coded number of transition times */
  530. X    char    tzh_typecnt[4];        /* coded number of local time types */
  531. X    char    tzh_charcnt[4];        /* coded number of abbr. chars */
  532. X};
  533. X
  534. X/*
  535. X** . . .followed by. . .
  536. X**
  537. X**    tzh_timecnt (char [4])s        coded transition times a la time(2)
  538. X**    tzh_timecnt (unsigned char)s    types of local time starting at above
  539. X**    tzh_typecnt repetitions of
  540. X**        one (char [4])        coded GMT offset in seconds
  541. X**        one (unsigned char)    used to set tm_isdst
  542. X**        one (unsigned char)    that's an abbreviation list index
  543. X**    tzh_charcnt (char)s        '\0'-terminated zone abbreviations
  544. X**    tzh_leapcnt repetitions of
  545. X**        one (char [4])        coded leap second transition times
  546. X**        one (char [4])        total correction after above
  547. X**    tzh_ttisstdcnt (char)s        indexed by type; if TRUE, transition
  548. X**                    time is standard time, if FALSE,
  549. X**                    transition time is wall clock time
  550. X**                    if absent, transition times are
  551. X**                    assumed to be wall clock time
  552. X*/
  553. X
  554. X/*
  555. X** In the current implementation, "tzset()" refuses to deal with files that
  556. X** exceed any of the limits below.
  557. X*/
  558. X
  559. X/*
  560. X** The TZ_MAX_TIMES value below is enough to handle a bit more than a
  561. X** year's worth of solar time (corrected daily to the nearest second) or
  562. X** 138 years of Pacific Presidential Election time
  563. X** (where there are three time zone transitions every fourth year).
  564. X*/
  565. X#define TZ_MAX_TIMES    370
  566. X
  567. X#define NOSOLAR            /* 4BSD doesn't currently handle solar time */
  568. X
  569. X#ifndef NOSOLAR
  570. X#define TZ_MAX_TYPES    256    /* Limited by what (unsigned char)'s can hold */
  571. X#else
  572. X#define TZ_MAX_TYPES    10    /* Maximum number of local time types */
  573. X#endif
  574. X
  575. X#define TZ_MAX_CHARS    50    /* Maximum number of abbreviation characters */
  576. X
  577. X#define    TZ_MAX_LEAPS    50    /* Maximum number of leap second corrections */
  578. X
  579. X#define SECSPERMIN    60
  580. X#define MINSPERHOUR    60
  581. X#define HOURSPERDAY    24
  582. X#define DAYSPERWEEK    7
  583. X#define DAYSPERNYEAR    365
  584. X#define DAYSPERLYEAR    366
  585. X#define SECSPERHOUR    (SECSPERMIN * MINSPERHOUR)
  586. X#define SECSPERDAY    ((long) SECSPERHOUR * HOURSPERDAY)
  587. X#define MONSPERYEAR    12
  588. X
  589. X#define TM_SUNDAY    0
  590. X#define TM_MONDAY    1
  591. X#define TM_TUESDAY    2
  592. X#define TM_WEDNESDAY    3
  593. X#define TM_THURSDAY    4
  594. X#define TM_FRIDAY    5
  595. X#define TM_SATURDAY    6
  596. X
  597. X#define TM_JANUARY    0
  598. X#define TM_FEBRUARY    1
  599. X#define TM_MARCH    2
  600. X#define TM_APRIL    3
  601. X#define TM_MAY        4
  602. X#define TM_JUNE        5
  603. X#define TM_JULY        6
  604. X#define TM_AUGUST    7
  605. X#define TM_SEPTEMBER    8
  606. X#define TM_OCTOBER    9
  607. X#define TM_NOVEMBER    10
  608. X#define TM_DECEMBER    11
  609. X
  610. X#define TM_YEAR_BASE    1900
  611. X
  612. X#define EPOCH_YEAR    1970
  613. X#define EPOCH_WDAY    TM_THURSDAY
  614. X
  615. X/*
  616. X** Accurate only for the past couple of centuries;
  617. X** that will probably do.
  618. X*/
  619. X
  620. X#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
  621. X
  622. X#endif /* !_TZFILE_H_ */
  623. END_OF_FILE
  624. if test 5120 -ne `wc -c <'strftime/tzfile.h'`; then
  625.     echo shar: \"'strftime/tzfile.h'\" unpacked with wrong size!
  626. fi
  627. # end of 'strftime/tzfile.h'
  628. fi
  629. if test -f 'xcal.h' -a "${1}" != "-c" ; then 
  630.   echo shar: Will not clobber existing file \"'xcal.h'\"
  631. else
  632. echo shar: Extracting \"'xcal.h'\" \(6899 characters\)
  633. sed "s/^X//" >'xcal.h' <<'END_OF_FILE'
  634. X/*
  635. X *    xcal.h    3.32    10/31/93
  636. X *
  637. X *    Header file for the xcal program
  638. X */
  639. X
  640. X/*
  641. X *    On 32 bit machines we can pack the date into one word
  642. X *    if not we have to use two callbacks
  643. X *    so undef if not true
  644. X *    and fiddle with the definitions below
  645. X */
  646. X/* #define    LONG_IS_32_BITS */
  647. X
  648. X/* pack year and month into Cardinals */
  649. X#ifdef LONG_IS_32_BITS
  650. X#define    DatePack(w, d, m, y)    ((((w)&0x7)<<21) | (((d)&0x1f)<<16) | (((m)&0xf)<<12) | ((y)&0xfff))
  651. X#define YrUnpack(v)    ((v)&0xfff)
  652. X#define MoUnpack(v)    (((v)>>12)&0xf)
  653. X#define DyUnpack(v)    (((v)>>16)&0x1f)
  654. X#define WdUnpack(v)    (((v)>>21)&0x7)
  655. X#else /*  LONG_IS_32_BITS */
  656. X#define    DatePack(m, y)    ((((m)&0xf)<<12) | ((y)&0xfff))
  657. X#define DayPack(w, d)    ((((w)&0x7)<<5) | ((d)&0x1f))
  658. X#define YrUnpack(v)    ((v)&0xfff)
  659. X#define MoUnpack(v)    (((v)>>12)&0xf)
  660. X#define DyUnpack(v)    ((v)&0x1f)
  661. X#define WdUnpack(v)    (((v)>>5)&0xf)
  662. X#endif /* LONG_IS_32_BITS */
  663. X
  664. X/*
  665. X *    Foreground/Background colours
  666. X */
  667. Xtypedef struct
  668. X{    Pixel    bg;
  669. X    Pixel    fg;
  670. X} Colour;
  671. X
  672. X/*
  673. X *    Time structure
  674. X */
  675. Xtypedef struct tm Tm;
  676. X
  677. X/*
  678. X *    resources used by xcal.c
  679. X */
  680. Xstruct resources
  681. X{    Boolean    debug;        /* Debug switch - currently used to fast fwd */
  682. X                /* the date */
  683. X    Boolean    alarmScan;    /* Debug switch for alarm system */
  684. X    Boolean    reverseVideo;    /* Display in Reverse video */
  685. X    Boolean    useWmTitle;    /* When displaying strips do not include a */
  686. X                /* month - year value */
  687. X    Boolean    markToday;    /* Mark today with today's colours */
  688. X    Boolean    calCompat;    /* True if handle files like xcalendar */
  689. X    Boolean giveHelp;    /* True if help is needed (default) */
  690. X    Boolean helpFromFile;    /* True if read help text from a file */
  691. X    String    helpfile;    /* Where to find the help file */
  692. X    Boolean initialCalendar;/* Pop up Calendar on startup if True */
  693. X    Boolean initialEdit;    /* Pop up today's Edit on startup if True */
  694. X    Boolean    initialMemo;    /* Pop up memo box on start */
  695. X    String    format;        /* Date format string to use in the main box */
  696. X    String    stripfmt;    /* Date format to use at the top of strips */
  697. X    String    editfmt;    /* Date format in edit windows */
  698. X    String    mon[12];    /* Long month names */
  699. X    String    smon[12];    /* Short month names */
  700. X    String    day[7];        /* Day names - full */
  701. X    String    sday[7];    /* Short day names */
  702. X    String    weekly;        /* Title of weekly edit strip */
  703. X    Colour    today;        /* What to mark today with */
  704. X    XFontStruct *fontToday; /* We can also do Today in a different font */
  705. X    String    directory;    /* Directory under home where Calendar files */
  706. X                /* can be found */
  707. X    int    textbufsz;    /* Text buffer size for editing */
  708. X    Dimension minstripwidth; /* Minimum strip width */
  709. X    Dimension maxstripheight; /* Maximum strip height */
  710. X    Boolean    alarms;        /* false - no alarms, true - alarms */
  711. X    Boolean    execalarms;    /* false - no exec alarms, true - exec alarms */
  712. X    XtIntervalId interval_id;/* store XtAddTimeOut value */
  713. X    int    clocktick;    /* how often the toplevel widget is polled */
  714. X    int    update;        /* interval between peeks (60 secs) */
  715. X    int    volume;        /* how loud to beep the alarm 0-100 */
  716. X    int    nbeeps;        /* how many beeps for an alarm ? */
  717. X    int    autoquit;    /* Automatically delete message boxes */
  718. X    String    countdown;    /* Comma separated countdown string for alarms */
  719. X    String    cmd;        /* command to execute for every alarm */
  720. X    String    alarmleft;    /* string containing a message - %d mins left */
  721. X    String    alarmnow;    /* string containing a message - Now! */
  722. X    Boolean    alarmWarp;    /* whether to take times from 0:XX - */
  723. X                /* minAlarmWarp:XX as PM */
  724. X    int    minAlarmWarp;    /* time threshold for alarmWarp */
  725. X    String    private;    /* string containing the word - Private */
  726. X    String    already;    /* date format for "Already editing day month year" */
  727. X    String    alreadyWeekly;    /* date format for "Already editing day" */
  728. X    Boolean    useMemo;    /* true use top-level memo button, false - don't */
  729. X    Boolean memoLeft;    /* True if on left of date, false otherwise */
  730. X    String    memoFile;    /* name of the file where the memo data is stored */
  731. X    int    maxDisplayLines;/* maximum number of lines that we want to */
  732. X                /* allow the top half of a memo window to */
  733. X                /* stretch to */
  734. X    char    *otheruser;    /* the name of another user */
  735. X};
  736. X
  737. X#define    MyCalendar    (appResources.otheruser == NULL)
  738. X
  739. Xextern    struct resources    appResources;
  740. X
  741. X/*
  742. X *    Application context for the program - set in xcal.c
  743. X */
  744. Xextern XtAppContext    appContext;
  745. X/*
  746. X *      Date structure
  747. X */
  748. Xtypedef struct
  749. X{       Cardinal        day;
  750. X        Cardinal        month;
  751. X        Cardinal        year;
  752. X        Cardinal        wday;
  753. X} Date;
  754. X/*
  755. X *    A month entry
  756. X */
  757. Xtypedef struct me
  758. X{
  759. X    Cardinal    me_year;    /* map year */
  760. X    Cardinal    me_month;    /* which month */
  761. X    String        me_have[32];    /* if a file present for the day */
  762. X                    /* then will have a non-zero entry */
  763. X    int        me_type;    /* type of displayed strip */
  764. X} MonthEntry;
  765. X
  766. X#define ME_MONTHLY    1        /* `Normal' monthly strip */
  767. X#define ME_WEEKLY    2        /* Weekly strip */
  768. X
  769. X/*
  770. X *    An instance of the strip
  771. X */
  772. Xtypedef    struct    instance
  773. X{    struct    instance *i_next;    /* next object */
  774. X    Widget    i_w;            /* the widget top level */
  775. X    Widget    i_day_label[32];    /* the handle to the label on each day */
  776. X                    /* so we can change dates at night */
  777. X    Widget    i_day_info[32];        /* The info field for this date - so */
  778. X                    /* we can sensitise/desensitise on editing */
  779. X    Colour    i_col;            /* what the fg/bg colours used to be */
  780. X    XFontStruct    *i_font;    /* what the font was */
  781. X} Instance;
  782. X
  783. XInstance *RegisterMonth();
  784. XInstance *FindInstanceList();
  785. X
  786. X/*
  787. X *    Alarm structure
  788. X *    one of these exists for each event in the timeout queue
  789. X *    the list is sorted in event order
  790. X */
  791. Xtypedef struct _alarm
  792. X{    struct _alarm *next;    /* pointer to next alarm */
  793. X    String    alarm;        /* alarm string */
  794. X    String    what;        /* what is message */
  795. X    int    alarm_mm;    /* hour*60 + min */
  796. X    int    alarm_state;    /* what time left to `real' timeout */
  797. X    Boolean isAction;    /* more than alarm */
  798. X} Alarm;
  799. X
  800. X/*
  801. X *    We occasionally need these
  802. X */
  803. Xextern    Widget    toplevel;
  804. Xextern    Date    today;
  805. Xextern  char    date_area[];
  806. Xextern    Boolean    FoundCalendarDir;
  807. Xextern    char    *MapStem;        /* pointer to the string which is */
  808. X                    /* where the map data is stored */
  809. X
  810. Xextern    Boolean    FoundCalendarDir;    /* whether the Calendar directory */
  811. X                    /* exists */
  812. X
  813. X/*
  814. X *    Global routines
  815. X */
  816. Xvoid    HelpShow();
  817. Xvoid    InitAlarms();
  818. Xvoid    DoTemplate();
  819. Xvoid    FmtTime();
  820. Xvoid    MouseShow();
  821. Xvoid    Leave();
  822. Xvoid    Fatal();
  823. XDimension wHeight();
  824. Xvoid    SetWidgetHeightMax();
  825. Xvoid    SetDate();
  826. Xvoid    AskLeave();
  827. Xvoid    DialogPopup();
  828. Xvoid    TextCal();
  829. Xvoid     LoadDateStrip();
  830. Xvoid    DoCalendar();
  831. Xvoid    DoMemo();
  832. Xvoid    DoWeekly();
  833. Xvoid    MemoPoll();
  834. Xvoid    NewMonthStrip();
  835. Xvoid    InitMonthEntries();
  836. Xvoid    ChangeHighlight();
  837. Xvoid    NoEditIsPossible();
  838. Xvoid    NoDayEditIsPossible();
  839. Xvoid    StartEditing();
  840. XMonthEntry *GetMonthEntry();
  841. XMonthEntry *GetWeeklyEntry();
  842. Xvoid    AlarmFilePoll();
  843. XString    ReadCalendarFile();
  844. Xvoid    UpdateMemo();
  845. XString    MakeWeeklyName();
  846. XString    GetWeeklyFile();
  847. XBoolean    NeedTop();
  848. Xvoid    AppendText();
  849. Xvoid    ButtonOff();
  850. Xvoid    ButtonOn();
  851. Xvoid    FmtDate();
  852. Xlong    ClockSync();
  853. XCardinal    NumberOfDays();
  854. XCardinal    FirstDay();
  855. X
  856. Xtime_t    time();
  857. END_OF_FILE
  858. if test 6899 -ne `wc -c <'xcal.h'`; then
  859.     echo shar: \"'xcal.h'\" unpacked with wrong size!
  860. fi
  861. # end of 'xcal.h'
  862. fi
  863. if test -f 'xcal_cal/xcal_cal.c' -a "${1}" != "-c" ; then 
  864.   echo shar: Will not clobber existing file \"'xcal_cal/xcal_cal.c'\"
  865. else
  866. echo shar: Extracting \"'xcal_cal/xcal_cal.c'\" \(5229 characters\)
  867. sed "s/^X//" >'xcal_cal/xcal_cal.c' <<'END_OF_FILE'
  868. X#ifndef lint
  869. Xstatic char *sccsid = "@(#)xcal_cal.c    1.1+ (Hillside Systems) 7/14/90";
  870. X#endif  /* lint */
  871. X/***
  872. X
  873. X* program name:
  874. X    xcal_cal.c
  875. X* function:
  876. X    read files generated by xcal and produce a file compatible
  877. X    with the standard "calendar" utility
  878. X* switches:
  879. X    -d dir    use "dir" instead of "Calendar"
  880. X    -f file use "file" instead of .xcal
  881. X    -m    copy all of multi-line entries
  882. X* history:
  883. X    Written July, 1990
  884. X    Ed Gould
  885. X    mt Xinu, Inc.
  886. X* (C) Copyright: 1990 mt Xinu, Inc.
  887. X    
  888. X    Permission to use, copy, modify, and distribute this software
  889. X    and its documentation for any purpose is hereby granted to
  890. X    anyone, provided that the above copyright notice appear in
  891. X    all copies and that both that copyright notice and this
  892. X    permission notice appear in supporting documentation, and
  893. X    that the names of Ed Gould and mt Xinu, Inc. not be used
  894. X    in advertising or publicity pertaining to distribution of
  895. X    the software without specific, written prior permission.
  896. X    mt Xinu, Inc. makes no representations about the suitability
  897. X    of this software for any purpose.  It is provided "as is"
  898. X    without express or implied warranty.
  899. X
  900. X    Ed Gould and mt Xinu, Inc. DISCLAIM ALL WARRANTIES WITH
  901. X    REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  902. X    OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL Ed Gould
  903. X    or mt Xinu, Inc. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  904. X    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  905. X    FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  906. X    CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  907. X    OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  908. X    SOFTWARE.
  909. X
  910. X***/
  911. X#include <stdio.h>
  912. X#include <ctype.h>
  913. X#include <sys/param.h>
  914. X#include <unistd.h>
  915. X#if defined(NeXT)
  916. X# include <sys/fcntl.h>
  917. X# include <sys/dir.h>
  918. X# include <sys/dirent.h>
  919. X#else
  920. X# include <dirent.h>
  921. X#endif
  922. X#include <string.h>
  923. X#include <time.h>
  924. X
  925. X
  926. Xchar    *directory    = "Calendar";
  927. Xchar    *file        = ".xcal";
  928. Xchar    *home;
  929. X
  930. X#ifndef MAXPATHLEN
  931. X#  define MAXPATHLEN 256
  932. X#endif
  933. X
  934. Xchar    usedir[MAXPATHLEN];
  935. Xchar    usefile[MAXPATHLEN];
  936. Xchar    line[BUFSIZ];
  937. X
  938. Xchar    *months[]    = {"jan", "feb", "mar", "apr", "may", "jun",
  939. X               "jul", "aug", "sep", "oct", "nov", "dec"};
  940. X
  941. Xint    debug;
  942. Xint    mflag;
  943. X
  944. XFILE    *out;
  945. X
  946. Xvoid
  947. Xmain(argc, argv)
  948. X    char **argv;
  949. X{
  950. X    register int c;
  951. X    time_t now;
  952. X    register struct tm *lt;
  953. X    char *getenv();
  954. X
  955. X    while((c = getopt(argc, argv, "d:f:m#")) != EOF) {
  956. X        extern char *optarg;
  957. X
  958. X        switch (c) {
  959. X
  960. X        case 'd':
  961. X            directory = optarg;
  962. X            break;
  963. X
  964. X        case 'f':
  965. X            file = optarg;
  966. X            break;
  967. X
  968. X        case 'm':
  969. X            mflag++;
  970. X            break;
  971. X
  972. X        case '#':
  973. X            debug++;
  974. X            break;
  975. X
  976. X        case '?':
  977. X        default:
  978. X            fprintf(stderr, "usage: %s [-d dir] [-f file]\n",
  979. X                                argv[0]);
  980. X            exit(1);
  981. X        }
  982. X    }
  983. X    home = getenv("HOME");
  984. X    /*
  985. X     * For both directory and output file, 
  986. X     *
  987. X     *   /...    is absolute path
  988. X     *   ./...    is relative to current directory
  989. X     *
  990. X     * otherwise, relative to $HOME, if available
  991. X     */
  992. X    if(file[0] == '/' || (file[0] == '.' && file[1] == '/') ||
  993. X       home == NULL)
  994. X        strcpy(usefile, file);
  995. X    else
  996. X        sprintf(usefile, "%s/%s", home, file);
  997. X    if(debug)
  998. X        fprintf(stderr, "output to %s\n", usefile);
  999. X    if((out = fopen(usefile, "w")) == NULL) {
  1000. X        perror(usefile);
  1001. X        exit(1);
  1002. X    }
  1003. X    now = time((time_t *)NULL);
  1004. X    lt = localtime(&now);
  1005. X    calfiles(directory, lt->tm_year + 1900, lt->tm_mon, lt->tm_mday);
  1006. X    if(lt->tm_mday >= 25 ) {
  1007. X        /*
  1008. X         * close to end of month: include next month, too
  1009. X         */
  1010. X        if(lt->tm_mon == 11)
  1011. X            calfiles(directory, lt->tm_year + 1900 + 1, 0, 1);
  1012. X        else
  1013. X            calfiles(directory, lt->tm_year + 1900,
  1014. X                            lt->tm_mon + 1, 1);
  1015. X    }
  1016. X}
  1017. X
  1018. Xcalfiles(dir, year, thismonth, today)
  1019. X    register char *dir;
  1020. X{
  1021. X    register DIR *dp;
  1022. X    register char *to;
  1023. X    register char *from;
  1024. X    register struct dirent *d;
  1025. X    char day[3];
  1026. X    char month[4];
  1027. X
  1028. X    if(dir[0] == '/' || (dir[0] == '.' && dir[1] == '/') ||
  1029. X       home == NULL)
  1030. X        sprintf(usedir, "%s/xy%4d", dir, year);
  1031. X    else
  1032. X        sprintf(usedir, "%s/%s/xy%4d", home, dir, year);
  1033. X    if(debug)
  1034. X        fprintf(stderr, "looking in directory %s\n", usedir);
  1035. X    if((dp = opendir(usedir)) == NULL) {
  1036. X        perror(usedir);
  1037. X        exit(1);
  1038. X    }
  1039. X    while((d = readdir(dp)) != NULL) {
  1040. X        register FILE *in;
  1041. X
  1042. X        if(d->d_name[0] != 'x' || d->d_name[1] != 'c' ||
  1043. X           !isascii(d->d_name[2]) || !isdigit(d->d_name[2]))
  1044. X            continue;
  1045. X        sprintf(usefile, "%s/%s", usedir, d->d_name);
  1046. X        if(debug)
  1047. X            fprintf(stderr, "looking in file %s\n", usefile);
  1048. X        if((in = fopen(usefile, "r")) == NULL) {
  1049. X            if(debug)
  1050. X                perror(usefile);
  1051. X            continue;
  1052. X        }
  1053. X        from = &d->d_name[2];
  1054. X        to = day;
  1055. X        while(isascii(*from) && isdigit(*from))
  1056. X            *to++ = *from++;
  1057. X        *to = '\0';
  1058. X        to = month;
  1059. X        while(isascii(*from) && !isdigit(*from)) {
  1060. X            if(isupper(*from))
  1061. X                *from = tolower(*from);
  1062. X            *to++ = *from++;
  1063. X        }
  1064. X        *to = '\0';
  1065. X        if(strcmp(month, months[thismonth]) != 0 ||
  1066. X           atoi(day) < today) {
  1067. X            if(debug)
  1068. X                fprintf(stderr, "\tskipped - date\n");
  1069. X            fclose(in);
  1070. X            continue;
  1071. X        }
  1072. X        while(fgets(line, sizeof(line), in) != NULL) {
  1073. X            char *cp;
  1074. X
  1075. X            if((to = strchr(line, '\n')) != NULL)
  1076. X                *to = '\0';
  1077. X            cp = line;
  1078. X            while(isspace(*cp))
  1079. X                cp++;
  1080. X            if(*cp == '\0') {
  1081. X                if(debug)
  1082. X                    fprintf(stderr, "\tskipped - empty\n");
  1083. X                continue;
  1084. X            }
  1085. X            if(debug)
  1086. X                fprintf(stderr, "==>\t%s %s\t%s\n", month,
  1087. X                                day, cp);
  1088. X            fprintf(out, "%s %s\t%s\n", month, day, cp);
  1089. X            if(mflag == 0)
  1090. X                break;
  1091. X        }
  1092. X        fclose(in);
  1093. X    }
  1094. X}
  1095. END_OF_FILE
  1096. if test 5229 -ne `wc -c <'xcal_cal/xcal_cal.c'`; then
  1097.     echo shar: \"'xcal_cal/xcal_cal.c'\" unpacked with wrong size!
  1098. fi
  1099. # end of 'xcal_cal/xcal_cal.c'
  1100. fi
  1101. if test -f 'xcal_days.c' -a "${1}" != "-c" ; then 
  1102.   echo shar: Will not clobber existing file \"'xcal_days.c'\"
  1103. else
  1104. echo shar: Extracting \"'xcal_days.c'\" \(5186 characters\)
  1105. sed "s/^X//" >'xcal_days.c' <<'END_OF_FILE'
  1106. X#ifndef lint
  1107. Xstatic char    *sccsid = "@(#)xcal_days.c    1.2 (Hillside Systems) 10/28/93";
  1108. Xstatic char    *copyright = "@(#)Copyright 1993 Peter Collinson, Hillside Systems";
  1109. X#endif                /* lint */
  1110. X/***
  1111. X
  1112. X* module name:
  1113. X    xcal_days.c.c
  1114. X* function:
  1115. X    Provide two routines
  1116. X        NumberOfDays(month, year)
  1117. X            the number of days in a Month and Year
  1118. X        FirstDay(month, year)
  1119. X            the day a month starts on
  1120. X* history:
  1121. X    Adapted from UCB NetII cal.c
  1122. X    October 1993
  1123. X    Peter Collinson
  1124. X    Hillside Systems
  1125. X* (C) Copyright: 1993 Hillside Systems/Peter Collinson
  1126. X    
  1127. X    For full permissions and copyright notice - see xcal.c
  1128. X***/
  1129. X
  1130. X#include <X11/Intrinsic.h>
  1131. X
  1132. X/*
  1133. X * This notice and the string below must not be removed from this code
  1134. X */
  1135. X
  1136. X/*
  1137. X * Copyright (c) 1989 The Regents of the University of California.
  1138. X * All rights reserved.
  1139. X *
  1140. X * This code is derived from software contributed to Berkeley by
  1141. X * Kim Letkeman.
  1142. X *
  1143. X * Redistribution and use in source and binary forms, with or without
  1144. X * modification, are permitted provided that the following conditions
  1145. X * are met:
  1146. X * 1. Redistributions of source code must retain the above copyright
  1147. X *    notice, this list of conditions and the following disclaimer.
  1148. X * 2. Redistributions in binary form must reproduce the above copyright
  1149. X *    notice, this list of conditions and the following disclaimer in the
  1150. X *    documentation and/or other materials provided with the distribution.
  1151. X * 3. All advertising materials mentioning features or use of this software
  1152. X *    must display the following acknowledgement:
  1153. X *    This product includes software developed by the University of
  1154. X *    California, Berkeley and its contributors.
  1155. X * 4. Neither the name of the University nor the names of its contributors
  1156. X *    may be used to endorse or promote products derived from this software
  1157. X *    without specific prior written permission.
  1158. X *
  1159. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1160. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1161. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1162. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1163. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1164. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1165. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1166. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1167. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1168. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1169. X * SUCH DAMAGE.
  1170. X */
  1171. X
  1172. X#ifndef lint
  1173. Xchar bsdcopyright[] =
  1174. X"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
  1175. X All rights reserved.\n";
  1176. X#endif /* not lint */
  1177. X
  1178. X#ifndef lint
  1179. Xstatic char bsdsccsid[] = "@(#)cal.c    5.2 (Berkeley) 4/19/91";
  1180. X#endif /* not lint */
  1181. X
  1182. X
  1183. X#define    THURSDAY        4        /* for reformation */
  1184. X#define    SATURDAY         6        /* 1 Jan 1 was a Saturday */
  1185. X
  1186. X#define    FIRST_MISSING_DAY     639787        /* 3 Sep 1752 */
  1187. X#define    NUMBER_MISSING_DAYS     11        /* 11 day correction */
  1188. X
  1189. Xstatic int days_in_month[2][13] = {
  1190. X    {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  1191. X    {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  1192. X};
  1193. X
  1194. X/* leap year -- account for gregorian reformation in 1752 */
  1195. X#define    leap_year(yr) \
  1196. X    ((yr) <= 1752 ? !((yr) % 4) : \
  1197. X    !((yr) % 4) && ((yr) % 100) || !((yr) % 400))
  1198. X
  1199. X/* number of centuries since 1700, not inclusive */
  1200. X#define    centuries_since_1700(yr) \
  1201. X    ((yr) > 1700 ? (yr) / 100 - 17 : 0)
  1202. X
  1203. X/* number of centuries since 1700 whose modulo of 400 is 0 */
  1204. X#define    quad_centuries_since_1700(yr) \
  1205. X    ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
  1206. X
  1207. X/* number of leap years between year 1 and this year, not inclusive */
  1208. X#define    leap_years_since_year_1(yr) \
  1209. X    ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
  1210. X
  1211. Xstatic int day_in_year();
  1212. Xstatic int day_in_week();
  1213. X
  1214. XCardinal
  1215. XFirstDay(month, year)
  1216. X    int    month;
  1217. X    int    year;
  1218. X{    
  1219. X    /* Months in xcal are 0 - 11 */
  1220. X    if (month == 8 && year == 1752)    /* this should work but doesn't */
  1221. X        return 2;
  1222. X    return day_in_week(1, month, year);
  1223. X}
  1224. X
  1225. XCardinal
  1226. XNumberOfDays(month, year)
  1227. X    int    month;
  1228. X    int    year;
  1229. X{
  1230. X
  1231. X    /* Months in xcal are 0 - 11 */
  1232. X    if (month == 8 && year == 1752)
  1233. X        return 19;
  1234. X    return days_in_month[leap_year(year)][month];
  1235. X}
  1236. X
  1237. X
  1238. X/*
  1239. X * day_in_year --
  1240. X *    return the 1 based day number within the year
  1241. X */
  1242. Xstatic int
  1243. Xday_in_year(day, month, year)
  1244. X    register int day, month;
  1245. X    int year;
  1246. X{
  1247. X    register int i, leap;
  1248. X
  1249. X    leap = leap_year(year);
  1250. X    for (i = 0; i < month; i++)
  1251. X        day += days_in_month[leap][i];
  1252. X    return(day);
  1253. X}
  1254. X
  1255. X/*
  1256. X * day_in_week
  1257. X *    return the 0 based day number for any date from 1 Jan. 1 to
  1258. X *    31 Dec. 9999.  Assumes the Gregorian reformation eliminates
  1259. X *    3 Sep. 1752 through 13 Sep. 1752.  Returns Thursday for all
  1260. X *    missing days.
  1261. X */
  1262. Xstatic int
  1263. Xday_in_week(day, month, year)
  1264. X    int day, month, year;
  1265. X{
  1266. X    long temp;
  1267. X
  1268. X    temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
  1269. X        + day_in_year(day, month, year);
  1270. X    if (temp < FIRST_MISSING_DAY)
  1271. X        return((temp - 1 + SATURDAY) % 7);
  1272. X    if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
  1273. X        return(((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
  1274. X    return(THURSDAY);
  1275. X}
  1276. END_OF_FILE
  1277. if test 5186 -ne `wc -c <'xcal_days.c'`; then
  1278.     echo shar: \"'xcal_days.c'\" unpacked with wrong size!
  1279. fi
  1280. # end of 'xcal_days.c'
  1281. fi
  1282. if test -f 'xcal_help.c' -a "${1}" != "-c" ; then 
  1283.   echo shar: Will not clobber existing file \"'xcal_help.c'\"
  1284. else
  1285. echo shar: Extracting \"'xcal_help.c'\" \(7751 characters\)
  1286. sed "s/^X//" >'xcal_help.c' <<'END_OF_FILE'
  1287. X#ifndef lint
  1288. Xstatic char    *sccsid = "@(#)xcal_help.c    3.19 (Hillside Systems) 11/6/93";
  1289. Xstatic char    *copyright = "@(#)Copyright 1989,1990,1993 Peter Collinson, Hillside Systems";
  1290. X#endif                /* lint */
  1291. X/***
  1292. X
  1293. X* module name:
  1294. X    xcal_help.c
  1295. X* function:
  1296. X    Generate help screens in separate popup windows
  1297. X* history:
  1298. X    Written December 1989
  1299. X    Completelt redone October 1993
  1300. X    Peter Collinson
  1301. X    Hillside Systems
  1302. X* (C) Copyright: 1989,1990,1993 Hillside Systems/Peter Collinson
  1303. X    
  1304. X    For full permissions and copyright notice - see xcal.c
  1305. X***/
  1306. X#include <sys/types.h>
  1307. X#include "xcal_mmap.h"
  1308. X#ifndef NO_MMAP
  1309. X#include <sys/mman.h>
  1310. X#endif
  1311. X#include <sys/stat.h>
  1312. X#include <stdio.h>
  1313. X#include <ctype.h>
  1314. X#include <string.h>
  1315. X#include <X11/Intrinsic.h>
  1316. X#include <X11/StringDefs.h>
  1317. X#include <X11/Shell.h>
  1318. X#include <X11/Xaw/AsciiText.h>
  1319. X#include <X11/Xaw/Text.h>
  1320. X#include <X11/Xaw/Command.h>
  1321. X#include <X11/Xaw/Form.h>
  1322. X#include <X11/Xaw/Paned.h>
  1323. X#include "xcal.h"
  1324. X
  1325. X#define argLD(N,V) { XtSetArg(args[nargs], N, V); nargs++; }
  1326. X
  1327. Xstatic XtCallbackRec callbacks[] = {
  1328. X    {NULL, NULL},
  1329. X    {NULL, NULL}
  1330. X};
  1331. X
  1332. Xstatic    Boolean    helpRead = False;
  1333. X
  1334. Xtypedef struct helpdata {
  1335. X    String    name;        /* Help name */
  1336. X    String    text;        /* the text we are showing */
  1337. X    Widget    popup;        /* Widget value */
  1338. X} Help;
  1339. X
  1340. Xstatic Help help[] = {
  1341. X    { "nohelp", "Sadly, Xcal help has not been installed correctly\nSee your sysadmin\n",},
  1342. X    { "main", },        /* don't move from here - see PopdownHelp */
  1343. X    { "edit", },
  1344. X    { "memo", },
  1345. X    { "weekly", },    
  1346. X    { "strip", },
  1347. X    { NULL, }
  1348. X};
  1349. X
  1350. Xstatic Help    *findHelp();
  1351. Xstatic void    initHelp();
  1352. Xstatic char    *connectHelp();
  1353. Xstatic Widget   DisplayHelpWindow();
  1354. Xstatic void    PopdownHelp();
  1355. Xstatic void    makeHelpPopup();
  1356. X#ifdef NO_MMAP
  1357. Xstatic char    *readbfile();
  1358. X#endif
  1359. X
  1360. X/*
  1361. X *    Initialise the help system
  1362. X *    Two methods - from a help file
  1363. X *    compiled in
  1364. X */
  1365. Xchar    *helpText;
  1366. X/* defines helpdata[] */
  1367. X#include "xcal_help.h"
  1368. X
  1369. X/*
  1370. X * Search the help structure looking for a name
  1371. X */
  1372. Xstatic Help *
  1373. XfindHelp(name)
  1374. X    String name;
  1375. X{
  1376. X    Help *h;
  1377. X
  1378. X    for (h = help; h->name; h++)
  1379. X        if (strcmp(name, h->name) == 0)
  1380. X            return h;
  1381. X    return NULL;
  1382. X}
  1383. X
  1384. X/*
  1385. X * Initialise help data
  1386. X */
  1387. Xstatic void
  1388. XinitHelp()
  1389. X{
  1390. X    Help    *he;
  1391. X    char    *h;
  1392. X    char    *name;
  1393. X    char    *text;
  1394. X    char    *vers;
  1395. X    int    lastc;
  1396. X    register int    vlen;
  1397. X    extern char     version[];
  1398. X
  1399. X    /* 
  1400. X     * Find the text for the help data
  1401. X     * If take from a file - then connect the file in memory
  1402. X     * If that fails, then use the text compiled into the program
  1403. X     */
  1404. X    if (appResources.helpFromFile == True) {
  1405. X        helpText = connectHelp();
  1406. X        if (helpText == NULL)
  1407. X            helpText = helpdata;
  1408. X    } else
  1409. X        helpText = helpdata;
  1410. X    /*
  1411. X     * Allow you to compile NO text into the program
  1412. X     */
  1413. X    if (*helpText == '\0')
  1414. X        helpText = NULL;
  1415. X    /*
  1416. X     * helpRead says - I have TRIED to find the data
  1417. X     */
  1418. X    helpRead = True;
  1419. X    if (helpText == NULL)
  1420. X        return;
  1421. X
  1422. X    vlen = strlen(version);
  1423. X
  1424. X    for (h = helpText; *h; ) {
  1425. X        if ((h = strchr(h, '{')) == NULL)
  1426. X            break;
  1427. X        h++;            /* h points to name */
  1428. X        name = h;
  1429. X
  1430. X        /* look for the end of the name */
  1431. X        while (!isspace(*h))    /* name is terminated by white space */
  1432. X            h++;        /* or a newline */
  1433. X        lastc = *h;
  1434. X        *h++ = '\0';
  1435. X        if (lastc != '\n') {
  1436. X            while(isspace(*h))
  1437. X                h++;
  1438. X        }
  1439. X        text = h;        /* that's the start of the text */
  1440. X
  1441. X        /* find the place to insert the version */
  1442. X        do {
  1443. X            if ((h = strchr(h, '+')) == NULL)
  1444. X                Fatal("Missing +++ lines in help text - %s\n", name);
  1445. X        } while (h[1] != '+' && h[2] != '+');
  1446. X        vers = h;
  1447. X        
  1448. X        /* and the end of the text */
  1449. X        h = strchr(h, '}');
  1450. X        if (h == NULL)
  1451. X            Fatal("Missing } in help text - %s\n", name);
  1452. X        *h++ = '\0';
  1453. X
  1454. X        /* Insert version */
  1455. X        memcpy(vers, version, vlen);
  1456. X        vers[vlen] = '\n';
  1457. X        vers[vlen + 1] = '\0';
  1458. X
  1459. X        /*
  1460. X         * That was a bit scrappy..
  1461. X         * insert the details in the structure
  1462. X         */
  1463. X        if (he = findHelp(name))
  1464. X            he->text = text;
  1465. X    }
  1466. X}    
  1467. X
  1468. X/*
  1469. X * If we are getting help from a file then the name is in the
  1470. X * resources. The trick here is to map the file into memory privately
  1471. X * so that it is just like one compiled in vector
  1472. X */
  1473. Xstatic char *
  1474. XconnectHelp()
  1475. X{
  1476. X        int     fd;
  1477. X        struct  stat statb;
  1478. X     char    *fibase;
  1479. X
  1480. X        if ((fd = open(appResources.helpfile, 0)) < 0)
  1481. X                return NULL;
  1482. X        if (fstat(fd, &statb) < 0) {
  1483. X                printf("Cannot fstat %s (shouldn't happen)\n", appResources.helpfile);
  1484. X        close(fd);
  1485. X        return NULL;
  1486. X     }
  1487. X
  1488. X        if (statb.st_size == 0) {
  1489. X                printf("Zero length file? (%s)\n", appResources.helpfile);
  1490. X        close(fd);
  1491. X         return NULL;
  1492. X    }
  1493. X#ifdef NO_MMAP
  1494. X    fibase = readbfile(fd, statb.st_size);
  1495. X#else
  1496. X        fibase = (char *) mmap(0, statb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
  1497. X#endif
  1498. X        if ((int)fibase == -1) {
  1499. X                printf("Cannot map %s into memory\n", appResources.helpfile);
  1500. X         return NULL;
  1501. X    }
  1502. X        close(fd);      /* we have it now */
  1503. X        fibase[statb.st_size] = '\0';    /* we don't mind losing the last char */
  1504. X        return(fibase);
  1505. X}
  1506. X        
  1507. Xstatic Widget
  1508. XDisplayHelpWindow(str)
  1509. X    String          str;
  1510. X{
  1511. X    Widget          shell, form, title;
  1512. X    Arg             args[10];
  1513. X    Cardinal        nargs;
  1514. X
  1515. X    shell = XtCreatePopupShell("help", topLevelShellWidgetClass, toplevel, NULL, 0);
  1516. X
  1517. X    form = XtCreateManagedWidget("helpPanel", panedWidgetClass, shell, NULL, 0);
  1518. X
  1519. X    nargs = 0;
  1520. X    argLD(XtNshowGrip, False);
  1521. X    argLD(XtNdefaultDistance, 2);
  1522. X    title = XtCreateManagedWidget("helpForm", formWidgetClass, form, args, nargs);
  1523. X    /*
  1524. X     * Exit button Take "Quit" from resources
  1525. X     */
  1526. X    callbacks[0].callback = PopdownHelp;
  1527. X    callbacks[0].closure = (caddr_t) shell;
  1528. X    nargs = 0;
  1529. X    argLD(XtNcallback, callbacks);
  1530. X    argLD(XtNfromHoriz, NULL);
  1531. X    argLD(XtNleft, XtChainLeft);
  1532. X    argLD(XtNright, XtChainLeft);
  1533. X    (void) XtCreateManagedWidget("helpQuit", commandWidgetClass, title, args, nargs);
  1534. X    /*
  1535. X     * Now the text which is the remainder of the panel
  1536. X     */
  1537. X    nargs = 0;
  1538. X    argLD(XtNshowGrip, False);
  1539. X    argLD(XtNstring, str);
  1540. X    argLD(XtNdisplayCaret, False);
  1541. X    (void) XtCreateManagedWidget("helpText", asciiTextWidgetClass, form, args, nargs);
  1542. X
  1543. X    XtPopup(shell, XtGrabNone);
  1544. X    return shell;
  1545. X}
  1546. X
  1547. X/* ARGSUSED */
  1548. Xstatic void
  1549. XPopdownHelp(w, closure, call_data)
  1550. X    Widget          w;
  1551. X    caddr_t         closure;
  1552. X    caddr_t         call_data;
  1553. X{
  1554. X    extern Widget   mHelp;
  1555. X
  1556. X    if (help[1].popup == (Widget)closure)
  1557. X         HelpShow(mHelp, False);
  1558. X    XtPopdown((Widget) closure);
  1559. X    HelpButtonOn((Widget) closure);
  1560. X}
  1561. X
  1562. X/*
  1563. X * Create a Help Popup
  1564. X */
  1565. Xstatic void
  1566. XmakeHelpPopup(w, name)
  1567. X    Widget     w;
  1568. X    char    *name;
  1569. X{
  1570. X    Help    *he;
  1571. X
  1572. X    if (helpRead == False)
  1573. X        initHelp();
  1574. X
  1575. X    he = findHelp(name);
  1576. X    if (he == NULL || he->text == NULL)
  1577. X        he->text = help[0].text;
  1578. X    
  1579. X    if (he->popup)
  1580. X        XtPopup(he->popup, XtGrabNone);
  1581. X    else    he->popup = DisplayHelpWindow(he->text);
  1582. X
  1583. X    ButtonOff(w, he->popup);
  1584. X}
  1585. X
  1586. X/* ARGSUSED */
  1587. Xvoid
  1588. XStripHelp(w, closure, call_data)
  1589. X    Widget          w;
  1590. X    caddr_t         closure;
  1591. X    caddr_t         call_data;
  1592. X{
  1593. X    makeHelpPopup(w, "strip");    
  1594. X}
  1595. X
  1596. X/* ARGSUSED */
  1597. Xvoid
  1598. XEditHelp(w, closure, call_data)
  1599. X    Widget          w;
  1600. X    caddr_t         closure;
  1601. X    caddr_t         call_data;
  1602. X{
  1603. X    makeHelpPopup(w, "edit");    
  1604. X}
  1605. X
  1606. X/* ARGSUSED */
  1607. Xvoid
  1608. XMemoHelp(w, closure, call_data)
  1609. X    Widget          w;
  1610. X    caddr_t         closure;
  1611. X    caddr_t         call_data;
  1612. X{
  1613. X    makeHelpPopup(w, "memo");    
  1614. X}
  1615. X
  1616. X/* ARGSUSED */
  1617. Xvoid
  1618. XMainHelp(w, closure, call_data)
  1619. X    Widget          w;
  1620. X    caddr_t         closure;
  1621. X    caddr_t         call_data;
  1622. X{
  1623. X    extern    Widget mHelp;
  1624. X
  1625. X    HelpShow(mHelp, True);
  1626. X    makeHelpPopup(w, "main");    
  1627. X}
  1628. X
  1629. X/* ARGSUSED */
  1630. Xvoid
  1631. XWeeklyHelp(w, closure, call_data)
  1632. X    Widget          w;
  1633. X    caddr_t         closure;
  1634. X    caddr_t         call_data;
  1635. X{
  1636. X    makeHelpPopup(w, "weekly");    
  1637. X}
  1638. X
  1639. X#ifdef NO_MMAP
  1640. X/*
  1641. X * If the system as no mmap malloc some memory and
  1642. X * read the file into it
  1643. X */
  1644. Xstatic char *
  1645. Xreadbfile(fd, len)
  1646. X    int    fd;
  1647. X    int    len;
  1648. X{
  1649. X    char    *base;
  1650. X    
  1651. X    base = XtMalloc(len+1);
  1652. X    if (read(fd, base, len) != len)
  1653. X        return ((char *)-1);
  1654. X    return base;
  1655. X}
  1656. X#endif
  1657. END_OF_FILE
  1658. if test 7751 -ne `wc -c <'xcal_help.c'`; then
  1659.     echo shar: \"'xcal_help.c'\" unpacked with wrong size!
  1660. fi
  1661. # end of 'xcal_help.c'
  1662. fi
  1663. if test -f 'xcalpr/xcal_days.c' -a "${1}" != "-c" ; then 
  1664.   echo shar: Will not clobber existing file \"'xcalpr/xcal_days.c'\"
  1665. else
  1666. echo shar: Extracting \"'xcalpr/xcal_days.c'\" \(5186 characters\)
  1667. sed "s/^X//" >'xcalpr/xcal_days.c' <<'END_OF_FILE'
  1668. X#ifndef lint
  1669. Xstatic char    *sccsid = "@(#)xcal_days.c    1.2 (Hillside Systems) 10/28/93";
  1670. Xstatic char    *copyright = "@(#)Copyright 1993 Peter Collinson, Hillside Systems";
  1671. X#endif                /* lint */
  1672. X/***
  1673. X
  1674. X* module name:
  1675. X    xcal_days.c.c
  1676. X* function:
  1677. X    Provide two routines
  1678. X        NumberOfDays(month, year)
  1679. X            the number of days in a Month and Year
  1680. X        FirstDay(month, year)
  1681. X            the day a month starts on
  1682. X* history:
  1683. X    Adapted from UCB NetII cal.c
  1684. X    October 1993
  1685. X    Peter Collinson
  1686. X    Hillside Systems
  1687. X* (C) Copyright: 1993 Hillside Systems/Peter Collinson
  1688. X    
  1689. X    For full permissions and copyright notice - see xcal.c
  1690. X***/
  1691. X
  1692. X#include <X11/Intrinsic.h>
  1693. X
  1694. X/*
  1695. X * This notice and the string below must not be removed from this code
  1696. X */
  1697. X
  1698. X/*
  1699. X * Copyright (c) 1989 The Regents of the University of California.
  1700. X * All rights reserved.
  1701. X *
  1702. X * This code is derived from software contributed to Berkeley by
  1703. X * Kim Letkeman.
  1704. X *
  1705. X * Redistribution and use in source and binary forms, with or without
  1706. X * modification, are permitted provided that the following conditions
  1707. X * are met:
  1708. X * 1. Redistributions of source code must retain the above copyright
  1709. X *    notice, this list of conditions and the following disclaimer.
  1710. X * 2. Redistributions in binary form must reproduce the above copyright
  1711. X *    notice, this list of conditions and the following disclaimer in the
  1712. X *    documentation and/or other materials provided with the distribution.
  1713. X * 3. All advertising materials mentioning features or use of this software
  1714. X *    must display the following acknowledgement:
  1715. X *    This product includes software developed by the University of
  1716. X *    California, Berkeley and its contributors.
  1717. X * 4. Neither the name of the University nor the names of its contributors
  1718. X *    may be used to endorse or promote products derived from this software
  1719. X *    without specific prior written permission.
  1720. X *
  1721. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1722. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1723. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1724. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1725. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1726. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1727. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1728. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1729. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1730. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1731. X * SUCH DAMAGE.
  1732. X */
  1733. X
  1734. X#ifndef lint
  1735. Xchar bsdcopyright[] =
  1736. X"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
  1737. X All rights reserved.\n";
  1738. X#endif /* not lint */
  1739. X
  1740. X#ifndef lint
  1741. Xstatic char bsdsccsid[] = "@(#)cal.c    5.2 (Berkeley) 4/19/91";
  1742. X#endif /* not lint */
  1743. X
  1744. X
  1745. X#define    THURSDAY        4        /* for reformation */
  1746. X#define    SATURDAY         6        /* 1 Jan 1 was a Saturday */
  1747. X
  1748. X#define    FIRST_MISSING_DAY     639787        /* 3 Sep 1752 */
  1749. X#define    NUMBER_MISSING_DAYS     11        /* 11 day correction */
  1750. X
  1751. Xstatic int days_in_month[2][13] = {
  1752. X    {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  1753. X    {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  1754. X};
  1755. X
  1756. X/* leap year -- account for gregorian reformation in 1752 */
  1757. X#define    leap_year(yr) \
  1758. X    ((yr) <= 1752 ? !((yr) % 4) : \
  1759. X    !((yr) % 4) && ((yr) % 100) || !((yr) % 400))
  1760. X
  1761. X/* number of centuries since 1700, not inclusive */
  1762. X#define    centuries_since_1700(yr) \
  1763. X    ((yr) > 1700 ? (yr) / 100 - 17 : 0)
  1764. X
  1765. X/* number of centuries since 1700 whose modulo of 400 is 0 */
  1766. X#define    quad_centuries_since_1700(yr) \
  1767. X    ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
  1768. X
  1769. X/* number of leap years between year 1 and this year, not inclusive */
  1770. X#define    leap_years_since_year_1(yr) \
  1771. X    ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
  1772. X
  1773. Xstatic int day_in_year();
  1774. Xstatic int day_in_week();
  1775. X
  1776. XCardinal
  1777. XFirstDay(month, year)
  1778. X    int    month;
  1779. X    int    year;
  1780. X{    
  1781. X    /* Months in xcal are 0 - 11 */
  1782. X    if (month == 8 && year == 1752)    /* this should work but doesn't */
  1783. X        return 2;
  1784. X    return day_in_week(1, month, year);
  1785. X}
  1786. X
  1787. XCardinal
  1788. XNumberOfDays(month, year)
  1789. X    int    month;
  1790. X    int    year;
  1791. X{
  1792. X
  1793. X    /* Months in xcal are 0 - 11 */
  1794. X    if (month == 8 && year == 1752)
  1795. X        return 19;
  1796. X    return days_in_month[leap_year(year)][month];
  1797. X}
  1798. X
  1799. X
  1800. X/*
  1801. X * day_in_year --
  1802. X *    return the 1 based day number within the year
  1803. X */
  1804. Xstatic int
  1805. Xday_in_year(day, month, year)
  1806. X    register int day, month;
  1807. X    int year;
  1808. X{
  1809. X    register int i, leap;
  1810. X
  1811. X    leap = leap_year(year);
  1812. X    for (i = 0; i < month; i++)
  1813. X        day += days_in_month[leap][i];
  1814. X    return(day);
  1815. X}
  1816. X
  1817. X/*
  1818. X * day_in_week
  1819. X *    return the 0 based day number for any date from 1 Jan. 1 to
  1820. X *    31 Dec. 9999.  Assumes the Gregorian reformation eliminates
  1821. X *    3 Sep. 1752 through 13 Sep. 1752.  Returns Thursday for all
  1822. X *    missing days.
  1823. X */
  1824. Xstatic int
  1825. Xday_in_week(day, month, year)
  1826. X    int day, month, year;
  1827. X{
  1828. X    long temp;
  1829. X
  1830. X    temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
  1831. X        + day_in_year(day, month, year);
  1832. X    if (temp < FIRST_MISSING_DAY)
  1833. X        return((temp - 1 + SATURDAY) % 7);
  1834. X    if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
  1835. X        return(((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
  1836. X    return(THURSDAY);
  1837. X}
  1838. END_OF_FILE
  1839. if test 5186 -ne `wc -c <'xcalpr/xcal_days.c'`; then
  1840.     echo shar: \"'xcalpr/xcal_days.c'\" unpacked with wrong size!
  1841. fi
  1842. # end of 'xcalpr/xcal_days.c'
  1843. fi
  1844. echo shar: End of archive 2 \(of 8\).
  1845. cp /dev/null ark2isdone
  1846. MISSING=""
  1847. for I in 1 2 3 4 5 6 7 8 ; do
  1848.     if test ! -f ark${I}isdone ; then
  1849.     MISSING="${MISSING} ${I}"
  1850.     fi
  1851. done
  1852. if test "${MISSING}" = "" ; then
  1853.     echo You have unpacked all 8 archives.
  1854.     rm -f ark[1-9]isdone
  1855. else
  1856.     echo You still need to unpack the following archives:
  1857.     echo "        " ${MISSING}
  1858. fi
  1859. ##  End of shell archive.
  1860. exit 0
  1861.  
  1862. exit 0 # Just in case...
  1863. -- 
  1864.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1865. \X/  Amiga: The only way to fly!  |    sources-x@sterling.com
  1866.        "It's intuitively obvious to the most casual observer..."
  1867.  GCS d++(--) -p+ c++ !l u++ e+ m+(-) s++/++ n h--- f+ g+++ w+ t++ r+ y+
  1868.