home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-22 | 52.8 KB | 1,870 lines |
- Newsgroups: comp.sources.x
- From: pc@hillside.co.uk (Peter Collinson)
- Subject: v21i077: xcal - A calendar program for X, Part02/08
- Message-ID: <1993Dec21.161715.21816@sparky.sterling.com>
- X-Md4-Signature: 26af0fbcf6b0f9350ad7d699a4737af9
- Sender: chris@sparky.sterling.com (Chris Olson)
- Organization: Hillside Systems, 61 Hillside Avenue, Canterbury, Kent CT2 8HA
- Date: Tue, 21 Dec 1993 16:17:15 GMT
- Approved: chris@sterling.com
-
- Submitted-by: pc@hillside.co.uk (Peter Collinson)
- Posting-number: Volume 21, Issue 77
- Archive-name: xcal/part02
- Environment: X11
- Supersedes: xcal: Volume 12, Issue 101
-
- Xcal is a calendar program. For more details see Part 1 of this posting
-
- Part 2 of 8
- --shar starts here--
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 2 (of 8)."
- # Contents: XCal.help strftime/strftime.c strftime/tzfile.h xcal.h
- # xcal_cal/xcal_cal.c xcal_days.c xcal_help.c xcalpr/xcal_days.c
- # Wrapped by pc@hillside on Wed Nov 17 11:24:35 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'XCal.help' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'XCal.help'\"
- else
- echo shar: Extracting \"'XCal.help'\" \(4973 characters\)
- sed "s/^X//" >'XCal.help' <<'END_OF_FILE'
- XXCal.Help XCal.help 1.2 93/10/23
- X{strip
- XThe date strip consists of a number of lines of text.
- X
- XLine 1: The Month and the Year of the strip.
- X The information may be duplicated in the window
- X manager title line. In this case the line may be omitted
- X by setting the resource `useWmTitle' to False.
- X
- XLine 2: The main control buttons for the strip actioned by the
- X left mouse button.
- X < Generates last month's strip in a separate window
- X Quit Close this script
- X > Generates next month's strip in a separate window
- X
- XLine 3: The Help button.
- X Help can be suppressed by setting the resource `giveHelp' to False.
- X
- XThen - A line for each day in the month.
- X
- X Each line is two areas:
- X
- X The left hand side shows the day in the month and the name of
- X the day of the week. `Today' may be highlighted specially in
- X this region.
- X
- X The right hand side is an active button. When pressed it starts
- X up an editor for the day. This will create a file for the day
- X in the user's Calendar directory. The label on the button will
- X be the first few characters of the file, if there are any.
- X
- X You can paste selected characters into a day. Sweep out the
- X characters that you want to load and click with the middle
- X mouse button in the day of your choice. This is just like
- X normal pasting of text. You will get a complaint if the day is
- X already being edited.
- X
- XXCal was written by Peter Collinson (pc@hillside.co.uk)
- X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- X}
- X{edit
- XThis editing window will create or delete a day file for the day shown
- Xin the title. The file is stored in a directory specified by the
- Xresource `directory', this is usually `Calendar' in your home
- Xdirectory.
- X
- XCalendar will usually contain directories, one for each year, and the
- Xday file will be stored in one of these directories. However, this
- Xmakes xcal incompatible with xcalendar - so if the resource
- XxcalendarCompat is True then the use of subdirectories is suppressed.
- X
- XThe large area in the edit window is a normal text input area. Text is
- Xsimply be typed into it, the text is saved by hitting the save button
- Xwhich is set to sensitive when the text is changed. Saving an empty
- Xbuffer will delete the file. The Quit button will exit. Some more
- Xquestions will be asked if leaving will result in losing information.
- X
- XXCal was written by Peter Collinson (pc@hillside.co.uk)
- X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- X}
- X{memo
- XThe memo window is intended to do three things. First, it allows a
- Xsingle button click to display today's actions from your diary.
- XSecond, it provides a way of displaying regular weekly events. Third,
- Xit provides an editable window whose contents can be saved in a file.
- XThe idea is that this file will contain reminders and other notes. The
- Xfile is usually called `memo' and is stored in a directory specified by
- Xthe resource `directory', usually `Calendar' in your home directory.
- X
- XThe window is split into three areas. The top section shows the current
- Xdiary entry and cannot be altered by editing. Hit the edit button to
- Xstart a standard day editor window on today's date. The middle section
- Xshows the weekly entry. Again the edit button allows you to edit these
- XThe bottom section contains the memo file text area. Text is simply
- Xtyped into it and is stored saved by hitting the save button. This
- Xwill go black when the text is changed.
- XSaving an empty buffer will delete the file.
- X
- XThe Quit button will exit. Some more questions will be asked if
- Xleaving will result in losing information.
- X
- XXCal was written by Peter Collinson (pc@hillside.co.uk)
- X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- X}
- X{main
- XThe command box contains a number of buttons.
- X
- XMove the mouse into the area showing the date and use
- Xthe mouse buttons to select further actions:
- X
- X - Left mouse button pops up this month's calendar strip
- X - Middle mouse button permits date selection
- X - Right mouse button allows exit
- X
- XClick with the left mouse button in the small box holding
- Xthe mouse icon to edit a memo file.
- X
- XThe Question Mark button shows this information, as you have already
- Xdiscovered.
- X
- XXCal was written by Peter Collinson (pc@hillside.co.uk)
- X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- X}
- X{weekly
- XThe weekly strip consists of a number of lines of text.
- X
- XLine 1: The title
- XLine 2: The Quit button that removes the strip from the screen
- XLine 3: The Help Button.
- X Help can be suppressed by setting `giveHelp' to False.
- X
- XThen - A line for each day in the week.
- X Each line is two areas:
- X The left hand side shows the day in the week
- X The right hand side is an active button. When pressed it starts
- X up an editor for the day. This will create a file for the day
- X in the user's Calendar directory. The label on the button will
- X be the first few characters of the file, if there are any.
- X
- XXCal was written by Peter Collinson
- X+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- X}
- END_OF_FILE
- if test 4973 -ne `wc -c <'XCal.help'`; then
- echo shar: \"'XCal.help'\" unpacked with wrong size!
- fi
- # end of 'XCal.help'
- fi
- if test -f 'strftime/strftime.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'strftime/strftime.c'\"
- else
- echo shar: Extracting \"'strftime/strftime.c'\" \(6862 characters\)
- sed "s/^X//" >'strftime/strftime.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1989 The Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the University of
- X * California, Berkeley and its contributors.
- X * 4. Neither the name of the University nor the names of its contributors
- X * may be used to endorse or promote products derived from this software
- X * without specific prior written permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- X * SUCH DAMAGE.
- X */
- X
- X#if defined(LIBC_SCCS) && !defined(lint)
- Xstatic char sccsid[] = "@(#)strftime.c 5.11 (Berkeley) 2/24/91";
- X#endif /* LIBC_SCCS and not lint */
- X
- X#include <sys/types.h>
- X#include <sys/time.h>
- X#include <tzfile.h>
- X#include <string.h>
- X
- Xstatic char *afmt[] = {
- X "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
- X};
- Xstatic char *Afmt[] = {
- X "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
- X "Saturday",
- X};
- Xstatic char *bfmt[] = {
- X "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
- X "Oct", "Nov", "Dec",
- X};
- Xstatic char *Bfmt[] = {
- X "January", "February", "March", "April", "May", "June", "July",
- X "August", "September", "October", "November", "December",
- X};
- X
- Xstatic size_t gsize;
- Xstatic char *pt;
- Xstatic int _add(), _conv(), _secs();
- X
- Xsize_t
- Xstrftime(s, maxsize, format, t)
- X char *s;
- X size_t maxsize;
- X const char *format;
- X const struct tm *t;
- X{
- X static size_t _fmt();
- X
- X pt = s;
- X if ((gsize = maxsize) < 1)
- X return(0);
- X if (_fmt(format, t)) {
- X *pt = '\0';
- X return(maxsize - gsize);
- X }
- X return(0);
- X}
- X
- Xstatic size_t
- X_fmt(format, t)
- X register char *format;
- X struct tm *t;
- X{
- X for (; *format; ++format) {
- X if (*format == '%')
- X switch(*++format) {
- X case '\0':
- X --format;
- X break;
- X case 'A':
- X if (t->tm_wday < 0 || t->tm_wday > 6)
- X return(0);
- X if (!_add(Afmt[t->tm_wday]))
- X return(0);
- X continue;
- X case 'a':
- X if (t->tm_wday < 0 || t->tm_wday > 6)
- X return(0);
- X if (!_add(afmt[t->tm_wday]))
- X return(0);
- X continue;
- X case 'B':
- X if (t->tm_mon < 0 || t->tm_mon > 11)
- X return(0);
- X if (!_add(Bfmt[t->tm_mon]))
- X return(0);
- X continue;
- X case 'b':
- X case 'h':
- X if (t->tm_mon < 0 || t->tm_mon > 11)
- X return(0);
- X if (!_add(bfmt[t->tm_mon]))
- X return(0);
- X continue;
- X case 'C':
- X if (!_fmt("%a %b %e %H:%M:%S %Y", t))
- X return(0);
- X continue;
- X case 'c':
- X if (!_fmt("%m/%d/%y %H:%M:%S", t))
- X return(0);
- X continue;
- X case 'D':
- X if (!_fmt("%m/%d/%y", t))
- X return(0);
- X continue;
- X case 'd':
- X if (!_conv(t->tm_mday, 2, '0'))
- X return(0);
- X continue;
- X case 'e':
- X if (!_conv(t->tm_mday, 2, ' '))
- X return(0);
- X continue;
- X case 'H':
- X if (!_conv(t->tm_hour, 2, '0'))
- X return(0);
- X continue;
- X case 'I':
- X if (!_conv(t->tm_hour % 12 ?
- X t->tm_hour % 12 : 12, 2, '0'))
- X return(0);
- X continue;
- X case 'j':
- X if (!_conv(t->tm_yday + 1, 3, '0'))
- X return(0);
- X continue;
- X case 'k':
- X if (!_conv(t->tm_hour, 2, ' '))
- X return(0);
- X continue;
- X case 'l':
- X if (!_conv(t->tm_hour % 12 ?
- X t->tm_hour % 12 : 12, 2, ' '))
- X return(0);
- X continue;
- X case 'M':
- X if (!_conv(t->tm_min, 2, '0'))
- X return(0);
- X continue;
- X case 'm':
- X if (!_conv(t->tm_mon + 1, 2, '0'))
- X return(0);
- X continue;
- X case 'n':
- X if (!_add("\n"))
- X return(0);
- X continue;
- X case 'p':
- X if (!_add(t->tm_hour >= 12 ? "PM" : "AM"))
- X return(0);
- X continue;
- X case 'R':
- X if (!_fmt("%H:%M", t))
- X return(0);
- X continue;
- X case 'r':
- X if (!_fmt("%I:%M:%S %p", t))
- X return(0);
- X continue;
- X case 'S':
- X if (!_conv(t->tm_sec, 2, '0'))
- X return(0);
- X continue;
- X case 's':
- X if (!_secs(t))
- X return(0);
- X continue;
- X case 'T':
- X case 'X':
- X if (!_fmt("%H:%M:%S", t))
- X return(0);
- X continue;
- X case 't':
- X if (!_add("\t"))
- X return(0);
- X continue;
- X case 'U':
- X if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7,
- X 2, '0'))
- X return(0);
- X continue;
- X case 'W':
- X if (!_conv((t->tm_yday + 7 -
- X (t->tm_wday ? (t->tm_wday - 1) : 6))
- X / 7, 2, '0'))
- X return(0);
- X continue;
- X case 'w':
- X if (!_conv(t->tm_wday, 1, '0'))
- X return(0);
- X continue;
- X case 'x':
- X if (!_fmt("%m/%d/%y", t))
- X return(0);
- X continue;
- X case 'y':
- X if (!_conv((t->tm_year + TM_YEAR_BASE)
- X % 100, 2, '0'))
- X return(0);
- X continue;
- X case 'Y':
- X if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0'))
- X return(0);
- X continue;
- X case 'Z':
- X if (!t->tm_zone || !_add(t->tm_zone))
- X return(0);
- X continue;
- X case '%':
- X /*
- X * X311J/88-090 (4.12.3.5): if conversion char is
- X * undefined, behavior is undefined. Print out the
- X * character itself as printf(3) does.
- X */
- X default:
- X break;
- X }
- X if (!gsize--)
- X return(0);
- X *pt++ = *format;
- X }
- X return(gsize);
- X}
- X
- Xstatic
- X_secs(t)
- X struct tm *t;
- X{
- X static char buf[15];
- X register time_t s;
- X register char *p;
- X struct tm tmp;
- X
- X /* Make a copy, mktime(3) modifies the tm struct. */
- X tmp = *t;
- X s = mktime(&tmp);
- X for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
- X *p-- = s % 10 + '0';
- X return(_add(++p));
- X}
- X
- Xstatic
- X_conv(n, digits, pad)
- X int n, digits;
- X char pad;
- X{
- X static char buf[10];
- X register char *p;
- X
- X for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
- X *p-- = n % 10 + '0';
- X while (p > buf && digits-- > 0)
- X *p-- = pad;
- X return(_add(++p));
- X}
- X
- Xstatic
- X_add(str)
- X register char *str;
- X{
- X for (;; ++pt, --gsize) {
- X if (!gsize)
- X return(0);
- X if (!(*pt = *str++))
- X return(1);
- X }
- X}
- END_OF_FILE
- if test 6862 -ne `wc -c <'strftime/strftime.c'`; then
- echo shar: \"'strftime/strftime.c'\" unpacked with wrong size!
- fi
- # end of 'strftime/strftime.c'
- fi
- if test -f 'strftime/tzfile.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'strftime/tzfile.h'\"
- else
- echo shar: Extracting \"'strftime/tzfile.h'\" \(5120 characters\)
- sed "s/^X//" >'strftime/tzfile.h' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1988 Regents of the University of California.
- X * All rights reserved.
- X *
- X * This code is derived from software contributed to Berkeley by
- X * Arthur David Olson of the National Cancer Institute.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the University of
- X * California, Berkeley and its contributors.
- X * 4. Neither the name of the University nor the names of its contributors
- X * may be used to endorse or promote products derived from this software
- X * without specific prior written permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- X * SUCH DAMAGE.
- X *
- X * @(#)tzfile.h 5.10 (Berkeley) 4/3/91
- X */
- X
- X#ifndef _TZFILE_H_
- X#define _TZFILE_H_
- X
- X/*
- X * Information about time zone files.
- X */
- X /* Time zone object file directory */
- X#define TZDIR "/usr/share/zoneinfo"
- X#define TZDEFAULT "/etc/localtime"
- X#define TZDEFRULES "posixrules"
- X
- X/*
- X** Each file begins with. . .
- X*/
- X
- Xstruct tzhead {
- X char tzh_reserved[24]; /* reserved for future use */
- X char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
- X char tzh_leapcnt[4]; /* coded number of leap seconds */
- X char tzh_timecnt[4]; /* coded number of transition times */
- X char tzh_typecnt[4]; /* coded number of local time types */
- X char tzh_charcnt[4]; /* coded number of abbr. chars */
- X};
- X
- X/*
- X** . . .followed by. . .
- X**
- X** tzh_timecnt (char [4])s coded transition times a la time(2)
- X** tzh_timecnt (unsigned char)s types of local time starting at above
- X** tzh_typecnt repetitions of
- X** one (char [4]) coded GMT offset in seconds
- X** one (unsigned char) used to set tm_isdst
- X** one (unsigned char) that's an abbreviation list index
- X** tzh_charcnt (char)s '\0'-terminated zone abbreviations
- X** tzh_leapcnt repetitions of
- X** one (char [4]) coded leap second transition times
- X** one (char [4]) total correction after above
- X** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
- X** time is standard time, if FALSE,
- X** transition time is wall clock time
- X** if absent, transition times are
- X** assumed to be wall clock time
- X*/
- X
- X/*
- X** In the current implementation, "tzset()" refuses to deal with files that
- X** exceed any of the limits below.
- X*/
- X
- X/*
- X** The TZ_MAX_TIMES value below is enough to handle a bit more than a
- X** year's worth of solar time (corrected daily to the nearest second) or
- X** 138 years of Pacific Presidential Election time
- X** (where there are three time zone transitions every fourth year).
- X*/
- X#define TZ_MAX_TIMES 370
- X
- X#define NOSOLAR /* 4BSD doesn't currently handle solar time */
- X
- X#ifndef NOSOLAR
- X#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
- X#else
- X#define TZ_MAX_TYPES 10 /* Maximum number of local time types */
- X#endif
- X
- X#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
- X
- X#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
- X
- X#define SECSPERMIN 60
- X#define MINSPERHOUR 60
- X#define HOURSPERDAY 24
- X#define DAYSPERWEEK 7
- X#define DAYSPERNYEAR 365
- X#define DAYSPERLYEAR 366
- X#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
- X#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
- X#define MONSPERYEAR 12
- X
- X#define TM_SUNDAY 0
- X#define TM_MONDAY 1
- X#define TM_TUESDAY 2
- X#define TM_WEDNESDAY 3
- X#define TM_THURSDAY 4
- X#define TM_FRIDAY 5
- X#define TM_SATURDAY 6
- X
- X#define TM_JANUARY 0
- X#define TM_FEBRUARY 1
- X#define TM_MARCH 2
- X#define TM_APRIL 3
- X#define TM_MAY 4
- X#define TM_JUNE 5
- X#define TM_JULY 6
- X#define TM_AUGUST 7
- X#define TM_SEPTEMBER 8
- X#define TM_OCTOBER 9
- X#define TM_NOVEMBER 10
- X#define TM_DECEMBER 11
- X
- X#define TM_YEAR_BASE 1900
- X
- X#define EPOCH_YEAR 1970
- X#define EPOCH_WDAY TM_THURSDAY
- X
- X/*
- X** Accurate only for the past couple of centuries;
- X** that will probably do.
- X*/
- X
- X#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
- X
- X#endif /* !_TZFILE_H_ */
- END_OF_FILE
- if test 5120 -ne `wc -c <'strftime/tzfile.h'`; then
- echo shar: \"'strftime/tzfile.h'\" unpacked with wrong size!
- fi
- # end of 'strftime/tzfile.h'
- fi
- if test -f 'xcal.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xcal.h'\"
- else
- echo shar: Extracting \"'xcal.h'\" \(6899 characters\)
- sed "s/^X//" >'xcal.h' <<'END_OF_FILE'
- X/*
- X * xcal.h 3.32 10/31/93
- X *
- X * Header file for the xcal program
- X */
- X
- X/*
- X * On 32 bit machines we can pack the date into one word
- X * if not we have to use two callbacks
- X * so undef if not true
- X * and fiddle with the definitions below
- X */
- X/* #define LONG_IS_32_BITS */
- X
- X/* pack year and month into Cardinals */
- X#ifdef LONG_IS_32_BITS
- X#define DatePack(w, d, m, y) ((((w)&0x7)<<21) | (((d)&0x1f)<<16) | (((m)&0xf)<<12) | ((y)&0xfff))
- X#define YrUnpack(v) ((v)&0xfff)
- X#define MoUnpack(v) (((v)>>12)&0xf)
- X#define DyUnpack(v) (((v)>>16)&0x1f)
- X#define WdUnpack(v) (((v)>>21)&0x7)
- X#else /* LONG_IS_32_BITS */
- X#define DatePack(m, y) ((((m)&0xf)<<12) | ((y)&0xfff))
- X#define DayPack(w, d) ((((w)&0x7)<<5) | ((d)&0x1f))
- X#define YrUnpack(v) ((v)&0xfff)
- X#define MoUnpack(v) (((v)>>12)&0xf)
- X#define DyUnpack(v) ((v)&0x1f)
- X#define WdUnpack(v) (((v)>>5)&0xf)
- X#endif /* LONG_IS_32_BITS */
- X
- X/*
- X * Foreground/Background colours
- X */
- Xtypedef struct
- X{ Pixel bg;
- X Pixel fg;
- X} Colour;
- X
- X/*
- X * Time structure
- X */
- Xtypedef struct tm Tm;
- X
- X/*
- X * resources used by xcal.c
- X */
- Xstruct resources
- X{ Boolean debug; /* Debug switch - currently used to fast fwd */
- X /* the date */
- X Boolean alarmScan; /* Debug switch for alarm system */
- X Boolean reverseVideo; /* Display in Reverse video */
- X Boolean useWmTitle; /* When displaying strips do not include a */
- X /* month - year value */
- X Boolean markToday; /* Mark today with today's colours */
- X Boolean calCompat; /* True if handle files like xcalendar */
- X Boolean giveHelp; /* True if help is needed (default) */
- X Boolean helpFromFile; /* True if read help text from a file */
- X String helpfile; /* Where to find the help file */
- X Boolean initialCalendar;/* Pop up Calendar on startup if True */
- X Boolean initialEdit; /* Pop up today's Edit on startup if True */
- X Boolean initialMemo; /* Pop up memo box on start */
- X String format; /* Date format string to use in the main box */
- X String stripfmt; /* Date format to use at the top of strips */
- X String editfmt; /* Date format in edit windows */
- X String mon[12]; /* Long month names */
- X String smon[12]; /* Short month names */
- X String day[7]; /* Day names - full */
- X String sday[7]; /* Short day names */
- X String weekly; /* Title of weekly edit strip */
- X Colour today; /* What to mark today with */
- X XFontStruct *fontToday; /* We can also do Today in a different font */
- X String directory; /* Directory under home where Calendar files */
- X /* can be found */
- X int textbufsz; /* Text buffer size for editing */
- X Dimension minstripwidth; /* Minimum strip width */
- X Dimension maxstripheight; /* Maximum strip height */
- X Boolean alarms; /* false - no alarms, true - alarms */
- X Boolean execalarms; /* false - no exec alarms, true - exec alarms */
- X XtIntervalId interval_id;/* store XtAddTimeOut value */
- X int clocktick; /* how often the toplevel widget is polled */
- X int update; /* interval between peeks (60 secs) */
- X int volume; /* how loud to beep the alarm 0-100 */
- X int nbeeps; /* how many beeps for an alarm ? */
- X int autoquit; /* Automatically delete message boxes */
- X String countdown; /* Comma separated countdown string for alarms */
- X String cmd; /* command to execute for every alarm */
- X String alarmleft; /* string containing a message - %d mins left */
- X String alarmnow; /* string containing a message - Now! */
- X Boolean alarmWarp; /* whether to take times from 0:XX - */
- X /* minAlarmWarp:XX as PM */
- X int minAlarmWarp; /* time threshold for alarmWarp */
- X String private; /* string containing the word - Private */
- X String already; /* date format for "Already editing day month year" */
- X String alreadyWeekly; /* date format for "Already editing day" */
- X Boolean useMemo; /* true use top-level memo button, false - don't */
- X Boolean memoLeft; /* True if on left of date, false otherwise */
- X String memoFile; /* name of the file where the memo data is stored */
- X int maxDisplayLines;/* maximum number of lines that we want to */
- X /* allow the top half of a memo window to */
- X /* stretch to */
- X char *otheruser; /* the name of another user */
- X};
- X
- X#define MyCalendar (appResources.otheruser == NULL)
- X
- Xextern struct resources appResources;
- X
- X/*
- X * Application context for the program - set in xcal.c
- X */
- Xextern XtAppContext appContext;
- X/*
- X * Date structure
- X */
- Xtypedef struct
- X{ Cardinal day;
- X Cardinal month;
- X Cardinal year;
- X Cardinal wday;
- X} Date;
- X
- X/*
- X * A month entry
- X */
- Xtypedef struct me
- X{
- X Cardinal me_year; /* map year */
- X Cardinal me_month; /* which month */
- X String me_have[32]; /* if a file present for the day */
- X /* then will have a non-zero entry */
- X int me_type; /* type of displayed strip */
- X} MonthEntry;
- X
- X#define ME_MONTHLY 1 /* `Normal' monthly strip */
- X#define ME_WEEKLY 2 /* Weekly strip */
- X
- X/*
- X * An instance of the strip
- X */
- Xtypedef struct instance
- X{ struct instance *i_next; /* next object */
- X Widget i_w; /* the widget top level */
- X Widget i_day_label[32]; /* the handle to the label on each day */
- X /* so we can change dates at night */
- X Widget i_day_info[32]; /* The info field for this date - so */
- X /* we can sensitise/desensitise on editing */
- X Colour i_col; /* what the fg/bg colours used to be */
- X XFontStruct *i_font; /* what the font was */
- X} Instance;
- X
- XInstance *RegisterMonth();
- XInstance *FindInstanceList();
- X
- X/*
- X * Alarm structure
- X * one of these exists for each event in the timeout queue
- X * the list is sorted in event order
- X */
- Xtypedef struct _alarm
- X{ struct _alarm *next; /* pointer to next alarm */
- X String alarm; /* alarm string */
- X String what; /* what is message */
- X int alarm_mm; /* hour*60 + min */
- X int alarm_state; /* what time left to `real' timeout */
- X Boolean isAction; /* more than alarm */
- X} Alarm;
- X
- X/*
- X * We occasionally need these
- X */
- Xextern Widget toplevel;
- Xextern Date today;
- Xextern char date_area[];
- Xextern Boolean FoundCalendarDir;
- Xextern char *MapStem; /* pointer to the string which is */
- X /* where the map data is stored */
- X
- Xextern Boolean FoundCalendarDir; /* whether the Calendar directory */
- X /* exists */
- X
- X/*
- X * Global routines
- X */
- Xvoid HelpShow();
- Xvoid InitAlarms();
- Xvoid DoTemplate();
- Xvoid FmtTime();
- Xvoid MouseShow();
- Xvoid Leave();
- Xvoid Fatal();
- XDimension wHeight();
- Xvoid SetWidgetHeightMax();
- Xvoid SetDate();
- Xvoid AskLeave();
- Xvoid DialogPopup();
- Xvoid TextCal();
- Xvoid LoadDateStrip();
- Xvoid DoCalendar();
- Xvoid DoMemo();
- Xvoid DoWeekly();
- Xvoid MemoPoll();
- Xvoid NewMonthStrip();
- Xvoid InitMonthEntries();
- Xvoid ChangeHighlight();
- Xvoid NoEditIsPossible();
- Xvoid NoDayEditIsPossible();
- Xvoid StartEditing();
- XMonthEntry *GetMonthEntry();
- XMonthEntry *GetWeeklyEntry();
- Xvoid AlarmFilePoll();
- XString ReadCalendarFile();
- Xvoid UpdateMemo();
- XString MakeWeeklyName();
- XString GetWeeklyFile();
- XBoolean NeedTop();
- Xvoid AppendText();
- Xvoid ButtonOff();
- Xvoid ButtonOn();
- Xvoid FmtDate();
- Xlong ClockSync();
- XCardinal NumberOfDays();
- XCardinal FirstDay();
- X
- Xtime_t time();
- END_OF_FILE
- if test 6899 -ne `wc -c <'xcal.h'`; then
- echo shar: \"'xcal.h'\" unpacked with wrong size!
- fi
- # end of 'xcal.h'
- fi
- if test -f 'xcal_cal/xcal_cal.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xcal_cal/xcal_cal.c'\"
- else
- echo shar: Extracting \"'xcal_cal/xcal_cal.c'\" \(5229 characters\)
- sed "s/^X//" >'xcal_cal/xcal_cal.c' <<'END_OF_FILE'
- X#ifndef lint
- Xstatic char *sccsid = "@(#)xcal_cal.c 1.1+ (Hillside Systems) 7/14/90";
- X#endif /* lint */
- X/***
- X
- X* program name:
- X xcal_cal.c
- X* function:
- X read files generated by xcal and produce a file compatible
- X with the standard "calendar" utility
- X* switches:
- X -d dir use "dir" instead of "Calendar"
- X -f file use "file" instead of .xcal
- X -m copy all of multi-line entries
- X* history:
- X Written July, 1990
- X Ed Gould
- X mt Xinu, Inc.
- X* (C) Copyright: 1990 mt Xinu, Inc.
- X
- X Permission to use, copy, modify, and distribute this software
- X and its documentation for any purpose is hereby granted to
- X anyone, provided that the above copyright notice appear in
- X all copies and that both that copyright notice and this
- X permission notice appear in supporting documentation, and
- X that the names of Ed Gould and mt Xinu, Inc. not be used
- X in advertising or publicity pertaining to distribution of
- X the software without specific, written prior permission.
- X mt Xinu, Inc. makes no representations about the suitability
- X of this software for any purpose. It is provided "as is"
- X without express or implied warranty.
- X
- X Ed Gould and mt Xinu, Inc. DISCLAIM ALL WARRANTIES WITH
- X REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- X OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL Ed Gould
- X or mt Xinu, Inc. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- X CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
- X FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- X CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- X OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- X SOFTWARE.
- X
- X***/
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <sys/param.h>
- X#include <unistd.h>
- X#if defined(NeXT)
- X# include <sys/fcntl.h>
- X# include <sys/dir.h>
- X# include <sys/dirent.h>
- X#else
- X# include <dirent.h>
- X#endif
- X#include <string.h>
- X#include <time.h>
- X
- X
- Xchar *directory = "Calendar";
- Xchar *file = ".xcal";
- Xchar *home;
- X
- X#ifndef MAXPATHLEN
- X# define MAXPATHLEN 256
- X#endif
- X
- Xchar usedir[MAXPATHLEN];
- Xchar usefile[MAXPATHLEN];
- Xchar line[BUFSIZ];
- X
- Xchar *months[] = {"jan", "feb", "mar", "apr", "may", "jun",
- X "jul", "aug", "sep", "oct", "nov", "dec"};
- X
- Xint debug;
- Xint mflag;
- X
- XFILE *out;
- X
- Xvoid
- Xmain(argc, argv)
- X char **argv;
- X{
- X register int c;
- X time_t now;
- X register struct tm *lt;
- X char *getenv();
- X
- X while((c = getopt(argc, argv, "d:f:m#")) != EOF) {
- X extern char *optarg;
- X
- X switch (c) {
- X
- X case 'd':
- X directory = optarg;
- X break;
- X
- X case 'f':
- X file = optarg;
- X break;
- X
- X case 'm':
- X mflag++;
- X break;
- X
- X case '#':
- X debug++;
- X break;
- X
- X case '?':
- X default:
- X fprintf(stderr, "usage: %s [-d dir] [-f file]\n",
- X argv[0]);
- X exit(1);
- X }
- X }
- X home = getenv("HOME");
- X /*
- X * For both directory and output file,
- X *
- X * /... is absolute path
- X * ./... is relative to current directory
- X *
- X * otherwise, relative to $HOME, if available
- X */
- X if(file[0] == '/' || (file[0] == '.' && file[1] == '/') ||
- X home == NULL)
- X strcpy(usefile, file);
- X else
- X sprintf(usefile, "%s/%s", home, file);
- X if(debug)
- X fprintf(stderr, "output to %s\n", usefile);
- X if((out = fopen(usefile, "w")) == NULL) {
- X perror(usefile);
- X exit(1);
- X }
- X now = time((time_t *)NULL);
- X lt = localtime(&now);
- X calfiles(directory, lt->tm_year + 1900, lt->tm_mon, lt->tm_mday);
- X if(lt->tm_mday >= 25 ) {
- X /*
- X * close to end of month: include next month, too
- X */
- X if(lt->tm_mon == 11)
- X calfiles(directory, lt->tm_year + 1900 + 1, 0, 1);
- X else
- X calfiles(directory, lt->tm_year + 1900,
- X lt->tm_mon + 1, 1);
- X }
- X}
- X
- Xcalfiles(dir, year, thismonth, today)
- X register char *dir;
- X{
- X register DIR *dp;
- X register char *to;
- X register char *from;
- X register struct dirent *d;
- X char day[3];
- X char month[4];
- X
- X if(dir[0] == '/' || (dir[0] == '.' && dir[1] == '/') ||
- X home == NULL)
- X sprintf(usedir, "%s/xy%4d", dir, year);
- X else
- X sprintf(usedir, "%s/%s/xy%4d", home, dir, year);
- X if(debug)
- X fprintf(stderr, "looking in directory %s\n", usedir);
- X if((dp = opendir(usedir)) == NULL) {
- X perror(usedir);
- X exit(1);
- X }
- X while((d = readdir(dp)) != NULL) {
- X register FILE *in;
- X
- X if(d->d_name[0] != 'x' || d->d_name[1] != 'c' ||
- X !isascii(d->d_name[2]) || !isdigit(d->d_name[2]))
- X continue;
- X sprintf(usefile, "%s/%s", usedir, d->d_name);
- X if(debug)
- X fprintf(stderr, "looking in file %s\n", usefile);
- X if((in = fopen(usefile, "r")) == NULL) {
- X if(debug)
- X perror(usefile);
- X continue;
- X }
- X from = &d->d_name[2];
- X to = day;
- X while(isascii(*from) && isdigit(*from))
- X *to++ = *from++;
- X *to = '\0';
- X to = month;
- X while(isascii(*from) && !isdigit(*from)) {
- X if(isupper(*from))
- X *from = tolower(*from);
- X *to++ = *from++;
- X }
- X *to = '\0';
- X if(strcmp(month, months[thismonth]) != 0 ||
- X atoi(day) < today) {
- X if(debug)
- X fprintf(stderr, "\tskipped - date\n");
- X fclose(in);
- X continue;
- X }
- X while(fgets(line, sizeof(line), in) != NULL) {
- X char *cp;
- X
- X if((to = strchr(line, '\n')) != NULL)
- X *to = '\0';
- X cp = line;
- X while(isspace(*cp))
- X cp++;
- X if(*cp == '\0') {
- X if(debug)
- X fprintf(stderr, "\tskipped - empty\n");
- X continue;
- X }
- X if(debug)
- X fprintf(stderr, "==>\t%s %s\t%s\n", month,
- X day, cp);
- X fprintf(out, "%s %s\t%s\n", month, day, cp);
- X if(mflag == 0)
- X break;
- X }
- X fclose(in);
- X }
- X}
- END_OF_FILE
- if test 5229 -ne `wc -c <'xcal_cal/xcal_cal.c'`; then
- echo shar: \"'xcal_cal/xcal_cal.c'\" unpacked with wrong size!
- fi
- # end of 'xcal_cal/xcal_cal.c'
- fi
- if test -f 'xcal_days.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xcal_days.c'\"
- else
- echo shar: Extracting \"'xcal_days.c'\" \(5186 characters\)
- sed "s/^X//" >'xcal_days.c' <<'END_OF_FILE'
- X#ifndef lint
- Xstatic char *sccsid = "@(#)xcal_days.c 1.2 (Hillside Systems) 10/28/93";
- Xstatic char *copyright = "@(#)Copyright 1993 Peter Collinson, Hillside Systems";
- X#endif /* lint */
- X/***
- X
- X* module name:
- X xcal_days.c.c
- X* function:
- X Provide two routines
- X NumberOfDays(month, year)
- X the number of days in a Month and Year
- X FirstDay(month, year)
- X the day a month starts on
- X* history:
- X Adapted from UCB NetII cal.c
- X October 1993
- X Peter Collinson
- X Hillside Systems
- X* (C) Copyright: 1993 Hillside Systems/Peter Collinson
- X
- X For full permissions and copyright notice - see xcal.c
- X***/
- X
- X#include <X11/Intrinsic.h>
- X
- X/*
- X * This notice and the string below must not be removed from this code
- X */
- X
- X/*
- X * Copyright (c) 1989 The Regents of the University of California.
- X * All rights reserved.
- X *
- X * This code is derived from software contributed to Berkeley by
- X * Kim Letkeman.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the University of
- X * California, Berkeley and its contributors.
- X * 4. Neither the name of the University nor the names of its contributors
- X * may be used to endorse or promote products derived from this software
- X * without specific prior written permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- X * SUCH DAMAGE.
- X */
- X
- X#ifndef lint
- Xchar bsdcopyright[] =
- X"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- X All rights reserved.\n";
- X#endif /* not lint */
- X
- X#ifndef lint
- Xstatic char bsdsccsid[] = "@(#)cal.c 5.2 (Berkeley) 4/19/91";
- X#endif /* not lint */
- X
- X
- X#define THURSDAY 4 /* for reformation */
- X#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
- X
- X#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
- X#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
- X
- Xstatic int days_in_month[2][13] = {
- X {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- X {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- X};
- X
- X/* leap year -- account for gregorian reformation in 1752 */
- X#define leap_year(yr) \
- X ((yr) <= 1752 ? !((yr) % 4) : \
- X !((yr) % 4) && ((yr) % 100) || !((yr) % 400))
- X
- X/* number of centuries since 1700, not inclusive */
- X#define centuries_since_1700(yr) \
- X ((yr) > 1700 ? (yr) / 100 - 17 : 0)
- X
- X/* number of centuries since 1700 whose modulo of 400 is 0 */
- X#define quad_centuries_since_1700(yr) \
- X ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
- X
- X/* number of leap years between year 1 and this year, not inclusive */
- X#define leap_years_since_year_1(yr) \
- X ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
- X
- Xstatic int day_in_year();
- Xstatic int day_in_week();
- X
- XCardinal
- XFirstDay(month, year)
- X int month;
- X int year;
- X{
- X /* Months in xcal are 0 - 11 */
- X if (month == 8 && year == 1752) /* this should work but doesn't */
- X return 2;
- X return day_in_week(1, month, year);
- X}
- X
- XCardinal
- XNumberOfDays(month, year)
- X int month;
- X int year;
- X{
- X
- X /* Months in xcal are 0 - 11 */
- X if (month == 8 && year == 1752)
- X return 19;
- X return days_in_month[leap_year(year)][month];
- X}
- X
- X
- X/*
- X * day_in_year --
- X * return the 1 based day number within the year
- X */
- Xstatic int
- Xday_in_year(day, month, year)
- X register int day, month;
- X int year;
- X{
- X register int i, leap;
- X
- X leap = leap_year(year);
- X for (i = 0; i < month; i++)
- X day += days_in_month[leap][i];
- X return(day);
- X}
- X
- X/*
- X * day_in_week
- X * return the 0 based day number for any date from 1 Jan. 1 to
- X * 31 Dec. 9999. Assumes the Gregorian reformation eliminates
- X * 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
- X * missing days.
- X */
- Xstatic int
- Xday_in_week(day, month, year)
- X int day, month, year;
- X{
- X long temp;
- X
- X temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
- X + day_in_year(day, month, year);
- X if (temp < FIRST_MISSING_DAY)
- X return((temp - 1 + SATURDAY) % 7);
- X if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
- X return(((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
- X return(THURSDAY);
- X}
- END_OF_FILE
- if test 5186 -ne `wc -c <'xcal_days.c'`; then
- echo shar: \"'xcal_days.c'\" unpacked with wrong size!
- fi
- # end of 'xcal_days.c'
- fi
- if test -f 'xcal_help.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xcal_help.c'\"
- else
- echo shar: Extracting \"'xcal_help.c'\" \(7751 characters\)
- sed "s/^X//" >'xcal_help.c' <<'END_OF_FILE'
- X#ifndef lint
- Xstatic char *sccsid = "@(#)xcal_help.c 3.19 (Hillside Systems) 11/6/93";
- Xstatic char *copyright = "@(#)Copyright 1989,1990,1993 Peter Collinson, Hillside Systems";
- X#endif /* lint */
- X/***
- X
- X* module name:
- X xcal_help.c
- X* function:
- X Generate help screens in separate popup windows
- X* history:
- X Written December 1989
- X Completelt redone October 1993
- X Peter Collinson
- X Hillside Systems
- X* (C) Copyright: 1989,1990,1993 Hillside Systems/Peter Collinson
- X
- X For full permissions and copyright notice - see xcal.c
- X***/
- X#include <sys/types.h>
- X#include "xcal_mmap.h"
- X#ifndef NO_MMAP
- X#include <sys/mman.h>
- X#endif
- X#include <sys/stat.h>
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <string.h>
- X#include <X11/Intrinsic.h>
- X#include <X11/StringDefs.h>
- X#include <X11/Shell.h>
- X#include <X11/Xaw/AsciiText.h>
- X#include <X11/Xaw/Text.h>
- X#include <X11/Xaw/Command.h>
- X#include <X11/Xaw/Form.h>
- X#include <X11/Xaw/Paned.h>
- X#include "xcal.h"
- X
- X#define argLD(N,V) { XtSetArg(args[nargs], N, V); nargs++; }
- X
- Xstatic XtCallbackRec callbacks[] = {
- X {NULL, NULL},
- X {NULL, NULL}
- X};
- X
- Xstatic Boolean helpRead = False;
- X
- Xtypedef struct helpdata {
- X String name; /* Help name */
- X String text; /* the text we are showing */
- X Widget popup; /* Widget value */
- X} Help;
- X
- Xstatic Help help[] = {
- X { "nohelp", "Sadly, Xcal help has not been installed correctly\nSee your sysadmin\n",},
- X { "main", }, /* don't move from here - see PopdownHelp */
- X { "edit", },
- X { "memo", },
- X { "weekly", },
- X { "strip", },
- X { NULL, }
- X};
- X
- Xstatic Help *findHelp();
- Xstatic void initHelp();
- Xstatic char *connectHelp();
- Xstatic Widget DisplayHelpWindow();
- Xstatic void PopdownHelp();
- Xstatic void makeHelpPopup();
- X#ifdef NO_MMAP
- Xstatic char *readbfile();
- X#endif
- X
- X/*
- X * Initialise the help system
- X * Two methods - from a help file
- X * compiled in
- X */
- Xchar *helpText;
- X/* defines helpdata[] */
- X#include "xcal_help.h"
- X
- X/*
- X * Search the help structure looking for a name
- X */
- Xstatic Help *
- XfindHelp(name)
- X String name;
- X{
- X Help *h;
- X
- X for (h = help; h->name; h++)
- X if (strcmp(name, h->name) == 0)
- X return h;
- X return NULL;
- X}
- X
- X/*
- X * Initialise help data
- X */
- Xstatic void
- XinitHelp()
- X{
- X Help *he;
- X char *h;
- X char *name;
- X char *text;
- X char *vers;
- X int lastc;
- X register int vlen;
- X extern char version[];
- X
- X /*
- X * Find the text for the help data
- X * If take from a file - then connect the file in memory
- X * If that fails, then use the text compiled into the program
- X */
- X if (appResources.helpFromFile == True) {
- X helpText = connectHelp();
- X if (helpText == NULL)
- X helpText = helpdata;
- X } else
- X helpText = helpdata;
- X /*
- X * Allow you to compile NO text into the program
- X */
- X if (*helpText == '\0')
- X helpText = NULL;
- X /*
- X * helpRead says - I have TRIED to find the data
- X */
- X helpRead = True;
- X if (helpText == NULL)
- X return;
- X
- X vlen = strlen(version);
- X
- X for (h = helpText; *h; ) {
- X if ((h = strchr(h, '{')) == NULL)
- X break;
- X h++; /* h points to name */
- X name = h;
- X
- X /* look for the end of the name */
- X while (!isspace(*h)) /* name is terminated by white space */
- X h++; /* or a newline */
- X lastc = *h;
- X *h++ = '\0';
- X if (lastc != '\n') {
- X while(isspace(*h))
- X h++;
- X }
- X text = h; /* that's the start of the text */
- X
- X /* find the place to insert the version */
- X do {
- X if ((h = strchr(h, '+')) == NULL)
- X Fatal("Missing +++ lines in help text - %s\n", name);
- X } while (h[1] != '+' && h[2] != '+');
- X vers = h;
- X
- X /* and the end of the text */
- X h = strchr(h, '}');
- X if (h == NULL)
- X Fatal("Missing } in help text - %s\n", name);
- X *h++ = '\0';
- X
- X /* Insert version */
- X memcpy(vers, version, vlen);
- X vers[vlen] = '\n';
- X vers[vlen + 1] = '\0';
- X
- X /*
- X * That was a bit scrappy..
- X * insert the details in the structure
- X */
- X if (he = findHelp(name))
- X he->text = text;
- X }
- X}
- X
- X/*
- X * If we are getting help from a file then the name is in the
- X * resources. The trick here is to map the file into memory privately
- X * so that it is just like one compiled in vector
- X */
- Xstatic char *
- XconnectHelp()
- X{
- X int fd;
- X struct stat statb;
- X char *fibase;
- X
- X if ((fd = open(appResources.helpfile, 0)) < 0)
- X return NULL;
- X
- X if (fstat(fd, &statb) < 0) {
- X printf("Cannot fstat %s (shouldn't happen)\n", appResources.helpfile);
- X close(fd);
- X return NULL;
- X }
- X
- X if (statb.st_size == 0) {
- X printf("Zero length file? (%s)\n", appResources.helpfile);
- X close(fd);
- X return NULL;
- X }
- X#ifdef NO_MMAP
- X fibase = readbfile(fd, statb.st_size);
- X#else
- X fibase = (char *) mmap(0, statb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
- X#endif
- X if ((int)fibase == -1) {
- X printf("Cannot map %s into memory\n", appResources.helpfile);
- X return NULL;
- X }
- X close(fd); /* we have it now */
- X fibase[statb.st_size] = '\0'; /* we don't mind losing the last char */
- X return(fibase);
- X}
- X
- Xstatic Widget
- XDisplayHelpWindow(str)
- X String str;
- X{
- X Widget shell, form, title;
- X Arg args[10];
- X Cardinal nargs;
- X
- X shell = XtCreatePopupShell("help", topLevelShellWidgetClass, toplevel, NULL, 0);
- X
- X form = XtCreateManagedWidget("helpPanel", panedWidgetClass, shell, NULL, 0);
- X
- X nargs = 0;
- X argLD(XtNshowGrip, False);
- X argLD(XtNdefaultDistance, 2);
- X title = XtCreateManagedWidget("helpForm", formWidgetClass, form, args, nargs);
- X /*
- X * Exit button Take "Quit" from resources
- X */
- X callbacks[0].callback = PopdownHelp;
- X callbacks[0].closure = (caddr_t) shell;
- X nargs = 0;
- X argLD(XtNcallback, callbacks);
- X argLD(XtNfromHoriz, NULL);
- X argLD(XtNleft, XtChainLeft);
- X argLD(XtNright, XtChainLeft);
- X (void) XtCreateManagedWidget("helpQuit", commandWidgetClass, title, args, nargs);
- X /*
- X * Now the text which is the remainder of the panel
- X */
- X nargs = 0;
- X argLD(XtNshowGrip, False);
- X argLD(XtNstring, str);
- X argLD(XtNdisplayCaret, False);
- X (void) XtCreateManagedWidget("helpText", asciiTextWidgetClass, form, args, nargs);
- X
- X XtPopup(shell, XtGrabNone);
- X return shell;
- X}
- X
- X/* ARGSUSED */
- Xstatic void
- XPopdownHelp(w, closure, call_data)
- X Widget w;
- X caddr_t closure;
- X caddr_t call_data;
- X{
- X extern Widget mHelp;
- X
- X if (help[1].popup == (Widget)closure)
- X HelpShow(mHelp, False);
- X XtPopdown((Widget) closure);
- X HelpButtonOn((Widget) closure);
- X}
- X
- X/*
- X * Create a Help Popup
- X */
- Xstatic void
- XmakeHelpPopup(w, name)
- X Widget w;
- X char *name;
- X{
- X Help *he;
- X
- X if (helpRead == False)
- X initHelp();
- X
- X he = findHelp(name);
- X if (he == NULL || he->text == NULL)
- X he->text = help[0].text;
- X
- X if (he->popup)
- X XtPopup(he->popup, XtGrabNone);
- X else he->popup = DisplayHelpWindow(he->text);
- X
- X ButtonOff(w, he->popup);
- X}
- X
- X/* ARGSUSED */
- Xvoid
- XStripHelp(w, closure, call_data)
- X Widget w;
- X caddr_t closure;
- X caddr_t call_data;
- X{
- X makeHelpPopup(w, "strip");
- X}
- X
- X/* ARGSUSED */
- Xvoid
- XEditHelp(w, closure, call_data)
- X Widget w;
- X caddr_t closure;
- X caddr_t call_data;
- X{
- X makeHelpPopup(w, "edit");
- X}
- X
- X/* ARGSUSED */
- Xvoid
- XMemoHelp(w, closure, call_data)
- X Widget w;
- X caddr_t closure;
- X caddr_t call_data;
- X{
- X makeHelpPopup(w, "memo");
- X}
- X
- X/* ARGSUSED */
- Xvoid
- XMainHelp(w, closure, call_data)
- X Widget w;
- X caddr_t closure;
- X caddr_t call_data;
- X{
- X extern Widget mHelp;
- X
- X HelpShow(mHelp, True);
- X makeHelpPopup(w, "main");
- X}
- X
- X/* ARGSUSED */
- Xvoid
- XWeeklyHelp(w, closure, call_data)
- X Widget w;
- X caddr_t closure;
- X caddr_t call_data;
- X{
- X makeHelpPopup(w, "weekly");
- X}
- X
- X#ifdef NO_MMAP
- X/*
- X * If the system as no mmap malloc some memory and
- X * read the file into it
- X */
- Xstatic char *
- Xreadbfile(fd, len)
- X int fd;
- X int len;
- X{
- X char *base;
- X
- X base = XtMalloc(len+1);
- X if (read(fd, base, len) != len)
- X return ((char *)-1);
- X return base;
- X}
- X#endif
- END_OF_FILE
- if test 7751 -ne `wc -c <'xcal_help.c'`; then
- echo shar: \"'xcal_help.c'\" unpacked with wrong size!
- fi
- # end of 'xcal_help.c'
- fi
- if test -f 'xcalpr/xcal_days.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xcalpr/xcal_days.c'\"
- else
- echo shar: Extracting \"'xcalpr/xcal_days.c'\" \(5186 characters\)
- sed "s/^X//" >'xcalpr/xcal_days.c' <<'END_OF_FILE'
- X#ifndef lint
- Xstatic char *sccsid = "@(#)xcal_days.c 1.2 (Hillside Systems) 10/28/93";
- Xstatic char *copyright = "@(#)Copyright 1993 Peter Collinson, Hillside Systems";
- X#endif /* lint */
- X/***
- X
- X* module name:
- X xcal_days.c.c
- X* function:
- X Provide two routines
- X NumberOfDays(month, year)
- X the number of days in a Month and Year
- X FirstDay(month, year)
- X the day a month starts on
- X* history:
- X Adapted from UCB NetII cal.c
- X October 1993
- X Peter Collinson
- X Hillside Systems
- X* (C) Copyright: 1993 Hillside Systems/Peter Collinson
- X
- X For full permissions and copyright notice - see xcal.c
- X***/
- X
- X#include <X11/Intrinsic.h>
- X
- X/*
- X * This notice and the string below must not be removed from this code
- X */
- X
- X/*
- X * Copyright (c) 1989 The Regents of the University of California.
- X * All rights reserved.
- X *
- X * This code is derived from software contributed to Berkeley by
- X * Kim Letkeman.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the University of
- X * California, Berkeley and its contributors.
- X * 4. Neither the name of the University nor the names of its contributors
- X * may be used to endorse or promote products derived from this software
- X * without specific prior written permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- X * SUCH DAMAGE.
- X */
- X
- X#ifndef lint
- Xchar bsdcopyright[] =
- X"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- X All rights reserved.\n";
- X#endif /* not lint */
- X
- X#ifndef lint
- Xstatic char bsdsccsid[] = "@(#)cal.c 5.2 (Berkeley) 4/19/91";
- X#endif /* not lint */
- X
- X
- X#define THURSDAY 4 /* for reformation */
- X#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
- X
- X#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
- X#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
- X
- Xstatic int days_in_month[2][13] = {
- X {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- X {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- X};
- X
- X/* leap year -- account for gregorian reformation in 1752 */
- X#define leap_year(yr) \
- X ((yr) <= 1752 ? !((yr) % 4) : \
- X !((yr) % 4) && ((yr) % 100) || !((yr) % 400))
- X
- X/* number of centuries since 1700, not inclusive */
- X#define centuries_since_1700(yr) \
- X ((yr) > 1700 ? (yr) / 100 - 17 : 0)
- X
- X/* number of centuries since 1700 whose modulo of 400 is 0 */
- X#define quad_centuries_since_1700(yr) \
- X ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
- X
- X/* number of leap years between year 1 and this year, not inclusive */
- X#define leap_years_since_year_1(yr) \
- X ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
- X
- Xstatic int day_in_year();
- Xstatic int day_in_week();
- X
- XCardinal
- XFirstDay(month, year)
- X int month;
- X int year;
- X{
- X /* Months in xcal are 0 - 11 */
- X if (month == 8 && year == 1752) /* this should work but doesn't */
- X return 2;
- X return day_in_week(1, month, year);
- X}
- X
- XCardinal
- XNumberOfDays(month, year)
- X int month;
- X int year;
- X{
- X
- X /* Months in xcal are 0 - 11 */
- X if (month == 8 && year == 1752)
- X return 19;
- X return days_in_month[leap_year(year)][month];
- X}
- X
- X
- X/*
- X * day_in_year --
- X * return the 1 based day number within the year
- X */
- Xstatic int
- Xday_in_year(day, month, year)
- X register int day, month;
- X int year;
- X{
- X register int i, leap;
- X
- X leap = leap_year(year);
- X for (i = 0; i < month; i++)
- X day += days_in_month[leap][i];
- X return(day);
- X}
- X
- X/*
- X * day_in_week
- X * return the 0 based day number for any date from 1 Jan. 1 to
- X * 31 Dec. 9999. Assumes the Gregorian reformation eliminates
- X * 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
- X * missing days.
- X */
- Xstatic int
- Xday_in_week(day, month, year)
- X int day, month, year;
- X{
- X long temp;
- X
- X temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
- X + day_in_year(day, month, year);
- X if (temp < FIRST_MISSING_DAY)
- X return((temp - 1 + SATURDAY) % 7);
- X if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
- X return(((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
- X return(THURSDAY);
- X}
- END_OF_FILE
- if test 5186 -ne `wc -c <'xcalpr/xcal_days.c'`; then
- echo shar: \"'xcalpr/xcal_days.c'\" unpacked with wrong size!
- fi
- # end of 'xcalpr/xcal_days.c'
- fi
- echo shar: End of archive 2 \(of 8\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 8 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
- exit 0 # Just in case...
- --
- // chris@Sterling.COM | Send comp.sources.x submissions to:
- \X/ Amiga: The only way to fly! | sources-x@sterling.com
- "It's intuitively obvious to the most casual observer..."
- GCS d++(--) -p+ c++ !l u++ e+ m+(-) s++/++ n h--- f+ g+++ w+ t++ r+ y+
-