home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / net / vcal < prev    next >
Internet Message Format  |  1987-02-04  |  26KB

  1. From me@pinot Thu Jan 29 20:33:32 1987
  2. Path: beno!seismo!rutgers!sri-spam!ames!lll-lcc!ptsfa!varian!zehntel!me@pinot (Mike Essex)
  3. From: me@pinot (Mike Essex)
  4. Newsgroups: net.sources
  5. Subject: visual calendar and activities programs, part 1
  6. Message-ID: <136@zehntel.UUCP>
  7. Date: 30 Jan 87 01:33:32 GMT
  8. Sender: news@zehntel.UUCP
  9. Organization: Zehntel Inc., Walnut Creek CA
  10. Lines: 1207
  11.  
  12.  
  13. echo x - README
  14. sed 's/^X//' >README <<'*-*-END-of-README-*-*'
  15. X            VCAL AND FRIENDS                  1/29/87
  16. X
  17. Xdef.:  a set of calendar and appointment utility programs to replace
  18. X       the traditional paper calendar.
  19. X       
  20. XVcal and friends allow the user to view a calendar, enter dates and
  21. Xtimes of activities, set times for prompts to the CRT and to produce
  22. Xlists of a month's activities.  Multiple data files may be used to
  23. Xallow the user to have one calendar for personal activities, one for
  24. Xbusiness activities, one for project milestones, etc.
  25. X
  26. XThese programs are written in 'C' and run under UNIX.  To date they
  27. Xhave been compiled and execute on the following systems:
  28. X
  29. XDEC PDP 11/70    UNIX Version 7
  30. XDEC VAX 11/750    UNIX BSD 4.2 and 4.3
  31. XSun 2/170    UNIX BSD 4.2
  32. XSun 3/160    UNIX BSD 4.2
  33. XSun 3/260     UNIX BSD 4.2
  34. X
  35. XIncluded in this package are six source files, six manual files, a
  36. Xmakefile and this introduction.  The makefile is for use with the
  37. Xstandard "make" utility on a VAX 11/750 under BSD 4.3.  For use with
  38. Xa PDP 11/70 BSD Version 7 change the makefile library entry from
  39. X"termlib" to "termcap".
  40. X
  41. XAll the "vcal" files have been combined here with the "shar" script.
  42. XSince the combined size of the files are greater than 65,000
  43. Xcharacters they have been broken into two parts for transmission.
  44. XPart 1 contains makefile, appts.c, autocall.c and callme.c along
  45. Xwith the manual pages for these.  Part 2 contains eappts.c, lcal.c
  46. Xand vcal.c and their manual pages.
  47. X
  48. XSynopsis of files:
  49. X
  50. Xappts        displays the current or specified day's activities
  51. X
  52. Xautocall    starts background reminder processes for each of the
  53. X        current day's activities
  54. X
  55. Xcallme        starts a background reminder process for a specified
  56. X        time and activity
  57. X
  58. Xeappts        allows activities to be entered into a data file from
  59. X        the command line
  60. X
  61. Xlcal        produces a tabular listing of the current or specified
  62. X        month's activities
  63. X
  64. Xvcal        visual calendar displaying the current or specified
  65. X        month's activities; allows entries to be added, changed
  66. X        or deleted
  67. X
  68. Xmakefile    makefile for all of the "vcal" programs
  69. X
  70. Xmanual pages:    appts.l autocall.l callme.l eappts.l lcal.l vcal.l
  71. X
  72. XComments and suggestions will be appreciated and considered.
  73. X
  74. XMike Essex  (~me)
  75. X
  76. X     ....!ucbvax!zehntel!me
  77. X     ....!decvax!sytek!zehntel!me
  78. X     ...."zehntel!me"@BERKELEY
  79. *-*-END-of-README-*-*
  80. echo x - makefile
  81. sed 's/^X//' >makefile <<'*-*-END-of-makefile-*-*'
  82. X.SUFFIXES:     .c
  83. X
  84. XLIBS          = -ltermcap
  85. X
  86. XLINKER          = cc
  87. XCC          = cc
  88. XAR          = ar
  89. XNM            = nm
  90. X
  91. XMAKEFILE      = makefile
  92. X
  93. XSRCS          = $.c
  94. X
  95. XOBJS          = $.o
  96. X
  97. XPROGRAMS      = appts\
  98. X        autocall\
  99. X        eappts\
  100. X        callme\
  101. X        vcal\
  102. X        lcal
  103. X
  104. X
  105. Xall:        $(PROGRAMS)
  106. X
  107. Xappts:    appts.c
  108. X    $(CC) -O -o appts appts.c
  109. X
  110. Xautocall:    autocall.c
  111. X    $(CC) -O -o autocall autocall.c
  112. X
  113. Xcallme:    callme.c
  114. X    $(CC) -O -o callme callme.c
  115. X
  116. Xeappts:    eappts.c
  117. X    $(CC) -O -o eappts eappts.c
  118. X
  119. Xvcal:    vcal.c
  120. X    $(CC) -O -o vcal vcal.c  $(LIBS)
  121. X
  122. Xlcal:    lcal.c
  123. X    $(CC) -O -o lcal lcal.c
  124. X
  125. *-*-END-of-makefile-*-*
  126. echo x - appts.c
  127. sed 's/^X//' >appts.c <<'*-*-END-of-appts.c-*-*'
  128. X/*
  129. X * Module:    appts.c
  130. X *
  131. X * Purpose:    Displays current or specified date's appointments
  132. X *
  133. X * Author:    Mike Essex
  134. X *
  135. X * Date:    Sep. 16, 1986
  136. X *
  137. X * Includes:
  138. X *    time.h, stdio.h, ctype.h
  139. X *
  140. X * Discussion:
  141. X *    This program reads a designated data file or, by default,
  142. X *    the .appointments file in the user's home directory and
  143. X *    displays the current days appointments if no command line
  144. X *    arguement is given.  An optional numeric month, day and
  145. X *    year arguement may be specified to display appointments
  146. X *    for a different day.  Output is standard out.
  147. X *
  148. X * Edit History
  149. X * ==== =======
  150. X *
  151. X * Date      Who    What
  152. X * ----      ---    ----------------------------------------------
  153. X * 11/26/86  me        added multi-datafile capability
  154. X * 11/26/86  me        fixed 'home' bug
  155. X * 12/08/86  me        modified "No appointments" to print filenames
  156. X *
  157. X */
  158. X
  159. X#include <time.h>
  160. X#include <stdio.h>
  161. X#include <ctype.h>
  162. X
  163. Xint        monthdata[1000];
  164. Xint        daydata[1000];
  165. Xint        yeardata[1000];
  166. Xint        timedata[1000];
  167. Xlong        juliedata[1000];
  168. Xchar        *msgdata[1000];
  169. Xint        month,day,year,hour,mhour,min,sec,dow,ampm;
  170. Xint        argvindex;
  171. Xlong        julie;
  172. Xint        maxentries = 1000;
  173. Xint        cntr;
  174. Xchar    *dlist[8] = {"x","Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
  175. Xint    mdays[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  176. X
  177. X
  178. X
  179. X/*
  180. X * Procedure:    main()
  181. X *
  182. X * Function:    initializes values, gets current day, parses command
  183. X *        line arguements, loads file data, outputs table
  184. X */
  185. X
  186. Xmain(argc,argv)
  187. X
  188. Xint        argc;
  189. Xchar        *argv[];
  190. X
  191. X{
  192. X    int        go,none,cntr,cnt,timeout,status,nowtime;
  193. X    int        loaddata();
  194. X    int        wday;
  195. X    int        atoi();
  196. X    int        setdow();
  197. X    int        tempmonth,tempday,tempyear;
  198. X    int        maxindex;
  199. X    int        holdargvi,holdmaxi;
  200. X    long    setjulie();
  201. X
  202. X    timeset();
  203. X
  204. X    if (argc > 3) {
  205. X    tempmonth = atoi(argv[1]);
  206. X    tempday = atoi(argv[2]);
  207. X    tempyear = atoi(argv[3]);
  208. X    if (tempmonth && tempday && tempyear){
  209. X        month = tempmonth;
  210. X        day = tempday;
  211. X        year = tempyear;
  212. X        if (year < 100) year += 1900;
  213. X        if (argc > 4) {
  214. X        argvindex = 4;
  215. X        maxindex = argc;
  216. X        }
  217. X        else {
  218. X        argvindex = 0;
  219. X        maxindex = 1;
  220. X        }
  221. X    }
  222. X    else {
  223. X        if (tempmonth || tempday || tempyear) {
  224. X        printf("Syntax error:  Incorrect date arguments\n");
  225. X        exit(1);
  226. X        }
  227. X        else {
  228. X        argvindex = 1;
  229. X        maxindex = argc;
  230. X        }
  231. X    }
  232. X    }
  233. X    else {
  234. X        if (argc == 1) {
  235. X        argvindex = 0;
  236. X        maxindex = argc;
  237. X    }
  238. X    else {
  239. X        argvindex = 1;
  240. X        maxindex = argc;
  241. X    }
  242. X    }
  243. X
  244. X    julie = setjulie(month,day,year);
  245. X    wday = setdow(month,day,year);
  246. X
  247. X
  248. X    go = 1;
  249. X    holdargvi = argvindex;
  250. X    holdmaxi = maxindex;
  251. X    while (go) {
  252. X    printf("-------------------------------------------------------------------------------\n");
  253. X    printf("|                       Appointments for %-3.3s  %2d/%2d/%4d                      |\n",dlist[wday],month,day,year);
  254. X
  255. X
  256. X    while (argvindex < maxindex) {
  257. X        cnt = loaddata(argv[argvindex]);
  258. X        cntr = 0;
  259. X        none = 1;
  260. X        while (cntr < cnt) {
  261. X        if (juliedata[cntr] == julie) {
  262. X            printf("| %4d  %-69.69s |\n",timedata[cntr],msgdata[cntr]);
  263. X            none = 0;
  264. X        };
  265. X        cntr++;
  266. X        }
  267. X        if (none) {
  268. X        if (argvindex == 0) {
  269. X            printf("| No appointments today.                                                      |\n");
  270. X        }
  271. X        else {
  272. X            printf("| No appointments in:  %-40.40s               |\n",argv[argvindex]);
  273. X        }
  274. X        }
  275. X        argvindex++;
  276. X    }
  277. X    printf("-------------------------------------------------------------------------------\n");
  278. X    if ((wday == 5) || (wday == 6)) {
  279. X        wday++;
  280. X        julie++;
  281. X        date(julie);
  282. X        go = 1;
  283. X    }
  284. X    else {
  285. X        go = 0;
  286. X    }
  287. X    argvindex = holdargvi;
  288. X    maxindex = holdmaxi;
  289. X    }
  290. X    exit(0);
  291. X} /* main */
  292. X
  293. X
  294. X/*
  295. X * Procedure:    timeset()
  296. X *
  297. X * Function:    Gets current time and date
  298. X *
  299. X * Return Values:
  300. X *    loads time and date info into global variables
  301. X *
  302. X */
  303. X
  304. Xtimeset()
  305. X
  306. X{
  307. X    struct    tm *localtime();
  308. X
  309. X    struct tm *tp;        /* time structure */
  310. X    long    tloc;        /* number of seconds since 1970 */
  311. X
  312. X    time(&tloc);    /* fills tloc */
  313. X
  314. X    tp = localtime(&tloc);
  315. X
  316. X    dow =    tp->tm_wday;
  317. X    year =    tp->tm_year;
  318. X    month =    tp->tm_mon + 1;
  319. X    day =    tp->tm_mday;
  320. X    hour = tp->tm_hour;
  321. X    mhour = tp->tm_hour;
  322. X    min = tp->tm_min;
  323. X    sec = tp->tm_sec;
  324. X
  325. X    year += 1900;
  326. X
  327. X    if (sec >= 30)
  328. X    {
  329. X    min += 1;    /* round up minutes */
  330. X    if (min == 60)
  331. X    {
  332. X    mhour += 1;
  333. X    min = 0;
  334. X    }
  335. X    }
  336. X
  337. X    if (hour > 12)
  338. X    {
  339. X    hour -= 12;
  340. X    }
  341. X    if (hour >= 12)
  342. X    {
  343. X    ampm = 0;
  344. X    }
  345. X    else {
  346. X    ampm = 1;
  347. X    }
  348. X} /* timeset */
  349. X
  350. X
  351. X/*
  352. X * Procedure:    loaddata()
  353. X *
  354. X * Function:    loads appointment data from ~/.appointments file
  355. X *
  356. X * Return Values:
  357. X *    various global arrays loaded with appointment data
  358. X *
  359. X */
  360. X
  361. Xloaddata(filename)
  362. X
  363. Xchar    *filename;
  364. X{
  365. X    char    basedata[80];
  366. X    char    tmpbuf[80];
  367. X    char    *getenv();
  368. X    FILE     *fptr;
  369. X    char    home[80];
  370. X    int        i,j,k,l,field;
  371. X    long    setjulie();
  372. X    char    *malloc();
  373. X
  374. X    i = 0;
  375. X    while (i < maxentries) {
  376. X    daydata[i] = 0;
  377. X    monthdata[i] = 0;
  378. X    yeardata[i] = 0;
  379. X    msgdata[i] = 0;
  380. X    i++;
  381. X    }
  382. X
  383. X    if (argvindex == 0) {
  384. X    strcpy(home,getenv("HOME"));
  385. X    strcat(home,"/.appointments");
  386. X    }
  387. X    else {
  388. X    strcpy(home,filename);
  389. X    }
  390. X
  391. X    if ((fptr = fopen(home,"r")) != NULL) {
  392. X    i = 0;
  393. X    while((fgets(basedata,80,fptr) != NULL)) {
  394. X
  395. X        basedata[strlen(basedata)-1] = NULL;
  396. X
  397. X        j = 0;
  398. X        k = 0;
  399. X        field = 0;
  400. X        while (basedata[j] != NULL ) {
  401. X                 
  402. X                if (basedata[j] != ',') {
  403. X
  404. X            tmpbuf[k++] = basedata[j];
  405. X        }
  406. X        else {
  407. X            switch (field) {
  408. X
  409. X            case 0 : {
  410. X                tmpbuf[k] = NULL;
  411. X                monthdata[i] = atoi(tmpbuf);
  412. X                k = 0;
  413. X                break;
  414. X            }
  415. X            case 1 : {
  416. X                tmpbuf[k] = NULL;
  417. X                daydata[i] = atoi(tmpbuf);
  418. X                k = 0;
  419. X                break;
  420. X            }
  421. X            case 2 : {
  422. X                tmpbuf[k] = NULL;
  423. X                yeardata[i] = atoi(tmpbuf);
  424. X                k = 0;
  425. X                break;
  426. X            }
  427. X            case 3 : {
  428. X                tmpbuf[k] = NULL;
  429. X                timedata[i] = atoi(tmpbuf);
  430. X                k = 0;
  431. X                break;
  432. X            }
  433. X            }
  434. X            field++;
  435. X        }
  436. X        j++;
  437. X        }
  438. X        tmpbuf[k] = NULL;
  439. X        msgdata[i] = malloc(40);
  440. X        strcpy(msgdata[i],tmpbuf);
  441. X        juliedata[i] = setjulie(monthdata[i],daydata[i],yeardata[i]);
  442. X
  443. X        if (i >= maxentries) {
  444. X        printf("Warning:  Over 1000 entries in %s file.  Data truncated.\n",filename);
  445. X        break;
  446. X        }
  447. X        i++;
  448. X    }
  449. X    fclose(fptr);
  450. X    }
  451. X    else {
  452. X    printf("Error:  cannot open %s file\n",filename);
  453. X    exit(1);
  454. X    }
  455. X    return(i);
  456. X} /* loaddata */
  457. X
  458. X
  459. X/*
  460. X * Procedure:    setdow(tmonth,tday,tyear)
  461. X *
  462. X * Function:    <short functional description>
  463. X *
  464. X * Parameters:
  465. X *    p1    - int - month
  466. X *    p2    - int - day
  467. X *    p3    - int - year
  468. X *
  469. X * Return Values:
  470. X *    interger value representing day of week with 1=sat, . . ., etc
  471. X *
  472. X */
  473. X
  474. Xsetdow(tmonth,tday,tyear)
  475. X
  476. Xint         tmonth,tday,tyear;
  477. X
  478. X{
  479. X
  480. X    int        mcnt;
  481. X    long    days;
  482. X    int        tdow;
  483. X    int        smonth,sday,syear;
  484. X
  485. X    smonth = 1;
  486. X    sday = 1;
  487. X    syear = 1979;
  488. X
  489. X    if ((tmonth == smonth) && (tyear == syear)) {
  490. X    days = abs(sday - tday);
  491. X    }
  492. X    else {
  493. X        days = mdays[smonth] - sday;
  494. X        if (tyear == syear) {
  495. X            while (++smonth < tmonth) {
  496. X            days += mdays[smonth];
  497. X            if ((smonth == 2) && ((syear % 4) == 0)) days++;
  498. X        }
  499. X        }
  500. X        else {
  501. X            while (++smonth < 13) {
  502. X            days += mdays[smonth];
  503. X                if ((smonth == 2) && ((syear % 4) == 0)) days++;
  504. X            }
  505. X        while (++syear < tyear) {
  506. X            days += 365;
  507. X            if ((syear % 4) == 0 ) days ++;
  508. X            }
  509. X    
  510. X        mcnt = 0;
  511. X            while (++mcnt < tmonth) {
  512. X            days += mdays[mcnt];
  513. X            if ((mcnt == 2) && ((tyear % 4) == 0)) days++;
  514. X        }
  515. X        }
  516. X        days += tday;
  517. X    }
  518. X
  519. X    tdow = ((days%7) + 1);
  520. X
  521. X    return(tdow);
  522. X} /* setdow */
  523. X
  524. X
  525. X/*
  526. X * Procedure:    setjulie(tmonth,tday,tyear)
  527. X *
  528. X * Function:    calculates the julian date
  529. X *
  530. X * Parameters:
  531. X *    p1    - int - month
  532. X *    p2    - int - day
  533. X *    p2    - int - year
  534. X *
  535. X * Return Values:
  536. X *    julian date as a long
  537. X *
  538. X */
  539. X
  540. Xlong setjulie(tmonth,tday,tyear)
  541. X
  542. Xint        tmonth,tday,tyear;
  543. X
  544. X{
  545. X
  546. X    int        mcnt;
  547. X    long    days;
  548. X    int        tdow;
  549. X    int        smonth,sday,syear;
  550. X
  551. X    smonth = 1;
  552. X    sday = 1;
  553. X    syear = 1979;
  554. X
  555. X    if ((tmonth == smonth) && (tyear == syear)) {
  556. X    days = abs(sday - tday);
  557. X    }
  558. X    else {
  559. X        days = mdays[smonth] - sday;
  560. X        if (tyear == syear) {
  561. X            while (++smonth < tmonth) {
  562. X            days += mdays[smonth];
  563. X            if ((smonth == 2) && ((syear % 4) == 0)) days++;
  564. X        }
  565. X        }
  566. X        else {
  567. X            while (++smonth < 13) {
  568. X            days += mdays[smonth];
  569. X                if ((smonth == 2) && ((syear % 4) == 0)) days++;
  570. X            }
  571. X        while (++syear < tyear) {
  572. X            days += 365;
  573. X            if ((syear % 4) == 0 ) days ++;
  574. X            }
  575. X    
  576. X        mcnt = 0;
  577. X            while (++mcnt < tmonth) {
  578. X            days += mdays[mcnt];
  579. X            if ((mcnt == 2) && ((tyear % 4) == 0)) days++;
  580. X        }
  581. X        }
  582. X        days += tday;
  583. X    }
  584. X
  585. X    return(days);
  586. X} /* setjulie */
  587. X
  588. X
  589. X/*
  590. X * Procedure:    date(days)
  591. X *
  592. X * Function:    calculates the current month, day and year
  593. X *
  594. X * Parameters:
  595. X *    p1    - int - number days offset from 1,1,1979
  596. X *
  597. X * Return Values:
  598. X *    sets global variable, month, day and year to calc value
  599. X *
  600. X */
  601. X
  602. Xdate(days)
  603. X
  604. Xlong   days;
  605. X
  606. X{
  607. X
  608. X    int    cnt;
  609. X
  610. X    month = 1;
  611. X    day = 1;
  612. X    year = 1979;
  613. X
  614. X    while (days--) {
  615. X    if (++day > mdays[month]) {
  616. X        day = 1;
  617. X        if (++month > 12) {
  618. X        month = 1;
  619. X        year++;
  620. X        }
  621. X        if ((month == 2) && !(year % 4)) {
  622. X        day--;
  623. X        }
  624. X    }
  625. X    }
  626. X} /* date */
  627. *-*-END-of-appts.c-*-*
  628. echo x - autocall.c
  629. sed 's/^X//' >autocall.c <<'*-*-END-of-autocall.c-*-*'
  630. X/*
  631. X * Module:    autocall.c
  632. X *
  633. X * Purpose:    notifies user at specified day and time of an
  634. X *        appointment
  635. X *
  636. X * Author:    Mike Essex
  637. X *
  638. X * Date:    Sep 19, 1986
  639. X *
  640. X * Includes:
  641. X *    time.h, stdio.h, signal.h
  642. X *
  643. X * Discussion:
  644. X *    This program spawns background processes for each of the
  645. X *    current date's entries in the user's ~/.appointments file.
  646. X *      At the specified time of day the process outputs the
  647. X *    message associated with the entry and dies.
  648. X * 
  649. X *
  650. X * Edit History
  651. X * ==== =======
  652. X *
  653. X * Date      Who    What
  654. X * ----      ---    ----------------------------------------------
  655. X * 12/1/86   me        added multi-datafile capability
  656. X * 12/1/86   me        changed 'home' from *home[80] to home[80]
  657. X * 12/1/86   me        changed int maxentries to #define MAXENTRIES
  658. X *
  659. X */
  660. X
  661. X#include <time.h>
  662. X#include <stdio.h>
  663. X#include <signal.h>
  664. X
  665. X#define        MAXENTRIES 1000
  666. X
  667. Xint        monthdata[MAXENTRIES];
  668. Xint        daydata[MAXENTRIES];
  669. Xint        yeardata[MAXENTRIES];
  670. Xint        timedata[MAXENTRIES];
  671. Xchar        *msgdata[MAXENTRIES];
  672. Xint        month,day,year,hour,mhour,min,sec,dow,ampm;
  673. Xint        cntr;
  674. Xint        argvindex;
  675. X
  676. X
  677. X/*
  678. X * Procedure:    main()
  679. X *
  680. X * Function:    initializes variables, calls data load, calculates
  681. X *        sleep time for message, forks message process
  682. X */
  683. X
  684. Xmain(argc,argv)
  685. X
  686. Xint    argc;
  687. Xchar    *argv[];
  688. X
  689. X{
  690. X    int        cnt,timeout,status,nowtime;
  691. X    int        loaddata();
  692. X
  693. X    signal(SIGINT,SIG_IGN);
  694. X    signal(SIGQUIT,SIG_IGN);
  695. X
  696. X    if (argc > 1) {
  697. X    argvindex = 1;
  698. X    }
  699. X    else {
  700. X    argvindex = 0;
  701. X    }
  702. X    while (argvindex <= argc) {
  703. X    cntr = 0;
  704. X    if ((cnt = loaddata(argv[argvindex])) != 0 ) {
  705. X        timeset();
  706. X        while (cntr < cnt) {
  707. X        nowtime = (mhour * 60) + min;
  708. X        if ((monthdata[cntr] == month) && (daydata[cntr] == day)
  709. X        && (yeardata[cntr] == year) && (timedata[cntr] > nowtime)) {
  710. X            timeout = (timedata[cntr] - nowtime) * 60;
  711. X            if ( timeout > 300 ) {
  712. X            timeout -= 300;
  713. X            }
  714. X            if ((status = fork()) == 0) {
  715. X            ringer(timeout,msgdata[cntr]);
  716. X            exit(0);
  717. X            }
  718. X            else {
  719. X            if (status < 0) {
  720. X                printf("Error:  Cannot start new autocall process\n");
  721. X            }
  722. X            }
  723. X        }
  724. X        cntr++;
  725. X        }
  726. X    }
  727. X    argvindex++;
  728. X    }
  729. X    exit(0);
  730. X} /* main */
  731. X
  732. X
  733. X
  734. X/*
  735. X * Procedure:    timeset()
  736. X *
  737. X * Function:    sets current date and time
  738. X *
  739. X * Return Values:
  740. X *    sets global varialbes to date and time
  741. X */
  742. X
  743. Xtimeset()
  744. X
  745. X{
  746. X    struct    tm *localtime();
  747. X
  748. X    struct tm *tp;        /* time structure */
  749. X    long    tloc;        /* number of seconds since 1970 */
  750. X
  751. X    time(&tloc);    /* fills tloc */
  752. X
  753. X    tp = localtime(&tloc);
  754. X
  755. X    dow =    tp->tm_wday;
  756. X    year =    tp->tm_year;
  757. X    month =    tp->tm_mon + 1;
  758. X    day =    tp->tm_mday;
  759. X    hour = tp->tm_hour;
  760. X    mhour = tp->tm_hour;
  761. X    min = tp->tm_min;
  762. X    sec = tp->tm_sec;
  763. X
  764. X    year += 1900;
  765. X
  766. X    if (sec >= 30)
  767. X    {
  768. X    min += 1;    /* round up minutes */
  769. X    if (min == 60)
  770. X    {
  771. X    mhour += 1;
  772. X    hour += 1;
  773. X    min = 0;
  774. X    }
  775. X    }
  776. X
  777. X    if (hour > 12)
  778. X    {
  779. X    hour -= 12;
  780. X    }
  781. X    if (mhour >= 12)
  782. X    {
  783. X    ampm = 1;
  784. X    }
  785. X    else {
  786. X    ampm = 0;
  787. X    }
  788. X} /* timeset */
  789. X
  790. X
  791. X
  792. X/*
  793. X * Procedure:    loaddata()
  794. X *
  795. X * Function:    load appointments data
  796. X *
  797. X * Return Values:
  798. X *    loads various global arrays with appointment data
  799. X *
  800. X * Discussion:
  801. X *    opens ~/.appointments file and inputs data, then puts
  802. X *    it into appropriate arrays
  803. X */
  804. X
  805. Xloaddata(datafile)
  806. X
  807. Xchar    *datafile;
  808. X{
  809. X    char    basedata[80];
  810. X    char    tmpbuf[80];
  811. X    char    *getenv();
  812. X    FILE     *fptr;
  813. X    char    home[80];
  814. X    int        msgtime,i,j,k,l,field;
  815. X    char    *malloc();
  816. X
  817. X    i = 0;
  818. X    while (i < MAXENTRIES) {
  819. X    daydata[i] = 0;
  820. X    monthdata[i] = 0;
  821. X    yeardata[i] = 0;
  822. X    msgdata[i] = 0;
  823. X    i++;
  824. X    }
  825. X
  826. X    if (argvindex == 0) {
  827. X    strcpy(home,getenv("HOME"));
  828. X    strcat(home,"/.appointments");
  829. X    }
  830. X    else {
  831. X    strcpy(home,datafile);
  832. X    }
  833. X
  834. X    if ((fptr = fopen(home,"r")) != NULL) {
  835. X    i = 0;
  836. X    while((fgets(basedata,80,fptr) != NULL)) {
  837. X
  838. X        basedata[strlen(basedata)-1] = NULL;
  839. X
  840. X        j = 0;
  841. X        k = 0;
  842. X        field = 0;
  843. X        while (basedata[j] != NULL ) {
  844. X                 
  845. X                if (basedata[j] != ',') {
  846. X
  847. X            tmpbuf[k++] = basedata[j];
  848. X        }
  849. X        else {
  850. X            switch (field) {
  851. X
  852. X            case 0 : {
  853. X                tmpbuf[k] = NULL;
  854. X                monthdata[i] = atoi(tmpbuf);
  855. X                k = 0;
  856. X                break;
  857. X            }
  858. X            case 1 : {
  859. X                tmpbuf[k] = NULL;
  860. X                daydata[i] = atoi(tmpbuf);
  861. X                k = 0;
  862. X                break;
  863. X            }
  864. X            case 2 : {
  865. X                tmpbuf[k] = NULL;
  866. X                yeardata[i] = atoi(tmpbuf);
  867. X                k = 0;
  868. X                break;
  869. X            }
  870. X            case 3 : {
  871. X                tmpbuf[k] = NULL;
  872. X                msgtime = atoi(tmpbuf);
  873. X                timedata[i] = ((msgtime / 100 ) * 60) + (msgtime % 100);
  874. X                k = 0;
  875. X                break;
  876. X            }
  877. X            }
  878. X            field++;
  879. X        }
  880. X        j++;
  881. X        }
  882. X        tmpbuf[k] = NULL;
  883. X        msgdata[i] = malloc(40);
  884. X        strcpy(msgdata[i],tmpbuf);
  885. X
  886. X        if (i >= MAXENTRIES) {
  887. X        printf("Warning:  Over 1000 entries in %s file.  Data truncated.\n",datafile);
  888. X        break;
  889. X        }
  890. X        i++;
  891. X    }
  892. X    fclose(fptr);
  893. X    }
  894. X    else {
  895. X    printf("Error:  cannot open %s file.\n",datafile);
  896. X    }
  897. X    return(i);
  898. X} /* loaddata */
  899. X
  900. X
  901. X/*
  902. X * Procedure:    ringer(delay,message)
  903. X *
  904. X * Function:    outputs appointment message at appropriate time
  905. X *
  906. X * Parameters:
  907. X *    p1    - int - delay time in seconds
  908. X *    p2    - char pointer - pointer to appointment message
  909. X *
  910. X * Discussion:
  911. X *    Takes in delay time and sleeps until delay is completed.
  912. X *    Then it outputs the message to standard out and dies.
  913. X */
  914. X
  915. Xringer(delay,message)
  916. X
  917. X    int        delay;
  918. X    char    *message;
  919. X{
  920. X    sleep(delay);
  921. X    timeset();
  922. X    printf("\r\nTime %d:%02d %2s    ", hour, min, (ampm == 0 ? "AM" : "PM"));
  923. X    printf("Activity scheduled:  %s \r\n\n",message);
  924. X} /* ringer */
  925. *-*-END-of-autocall.c-*-*
  926. echo x - callme.c
  927. sed 's/^X//' >callme.c <<'*-*-END-of-callme.c-*-*'
  928. X/*
  929. X * Module:    callme.c
  930. X *
  931. X * Purpose:    prompts user at time of an appointment
  932. X *
  933. X * Author:    Mike Essex
  934. X *
  935. X * Date:    Sep. 16, 1986
  936. X *
  937. X * Includes:
  938. X *    time.h, stdio.h, signal.h
  939. X *
  940. X * Discussion:
  941. X *    Takes in time and message from commands line, sleeps an
  942. X *    appropriate amount of time and then displays message.
  943. X * 
  944. X *
  945. X * Edit History
  946. X * ==== =======
  947. X *
  948. X * Date      Who    What
  949. X * ----      ---    ----------------------------------------------
  950. X *
  951. X */
  952. X
  953. X
  954. X#include <time.h>
  955. X#include <stdio.h>
  956. X#include <signal.h>
  957. X
  958. Xint        mindata,timedata;
  959. Xchar        msgdata[512];
  960. Xint        month,day,year,hour,mhour,min,sec,dow,ampm;
  961. X
  962. X
  963. X/*
  964. X * Procedure:    main.c
  965. X *
  966. X * Function:    parses command line, calculates delay and starts
  967. X *        background process for message.
  968. X */
  969. X
  970. Xmain(argc,argv)
  971. X
  972. Xint        argc;
  973. Xchar        *argv[];
  974. X
  975. X{
  976. X    int        i,timeout,status,nowtime;
  977. X
  978. X    signal(SIGINT,SIG_IGN);
  979. X    signal(SIGQUIT,SIG_IGN);
  980. X
  981. X    if (argc < 3) {
  982. X    printf("\r\n          Syntax error:  Incorrect number of arguments          \r\n");
  983. X    printf("          Syntax:  callme (time) (message)                        \r\n\n");
  984. X    exit(1);
  985. X    }
  986. X
  987. X    timedata = atoi(argv[1]);
  988. X    mindata = (60*(timedata/100)) + (timedata % 100);
  989. X    i = 2;
  990. X    while (i < argc) {
  991. X        strcat(msgdata,argv[i++]);
  992. X    strcat(msgdata," ");
  993. X    }
  994. X    timeset();
  995. X    nowtime = (mhour * 60) + min;
  996. X    if ( mindata > nowtime) {
  997. X    timeout = (mindata - nowtime) * 60;
  998. X    if ( timeout > 300 ) {
  999. X        timeout -= 300;
  1000. X    }
  1001. X    if ((status = fork()) == 0) {
  1002. X        ringer(timeout,msgdata);
  1003. X        exit(0);
  1004. X    }
  1005. X    else {
  1006. X        if (status < 0) {
  1007. X        printf("* Cannot start new sleeper process *\n");
  1008. X        }
  1009. X    }
  1010. X    }
  1011. X    else {
  1012. X    printf("It is already past %d\n",timedata);
  1013. X    }
  1014. X    exit(0);
  1015. X} /* main */
  1016. X
  1017. X
  1018. X
  1019. X/*
  1020. X * Procedure:    timeset()
  1021. X *
  1022. X * Function:    loads current time
  1023. X *
  1024. X * Return Values:
  1025. X *    sets global variables for time and date
  1026. X */
  1027. X
  1028. Xtimeset()
  1029. X
  1030. X{
  1031. X    struct    tm *localtime();
  1032. X
  1033. X    struct tm *tp;        /* time structure */
  1034. X    long    tloc;        /* number of seconds since 1970 */
  1035. X
  1036. X    time(&tloc);    /* fills tloc */
  1037. X
  1038. X    tp = localtime(&tloc);
  1039. X
  1040. X    dow =    tp->tm_wday;
  1041. X    year =    tp->tm_year;
  1042. X    month =    tp->tm_mon + 1;
  1043. X    day =    tp->tm_mday;
  1044. X    hour = tp->tm_hour;
  1045. X    mhour = tp->tm_hour;
  1046. X    min = tp->tm_min;
  1047. X    sec = tp->tm_sec;
  1048. X
  1049. X    year += 1900;
  1050. X
  1051. X    if (sec >= 30)
  1052. X    {
  1053. X    min += 1;    /* round up minutes */
  1054. X    if (min == 60)
  1055. X    {
  1056. X    mhour += 1;
  1057. X    hour += 1;
  1058. X    min = 0;
  1059. X    }
  1060. X    }
  1061. X
  1062. X    if (hour > 12)
  1063. X    {
  1064. X    hour -= 12;
  1065. X    }
  1066. X    if (mhour >= 12)
  1067. X    {
  1068. X    ampm = 1;
  1069. X    }
  1070. X    else {
  1071. X    ampm = 0;
  1072. X    }
  1073. X} /* timeset */
  1074. X
  1075. X
  1076. X
  1077. X/*
  1078. X * Procedure:    ringer(delay,message)
  1079. X *
  1080. X * Function:    prompts user with message at appropriate time
  1081. X *
  1082. X * Parameters:
  1083. X *    p1    - int - delay time
  1084. X *    p2    - character pointer - pointer to message
  1085. X * Discussion:
  1086. X *    sleeps specified amount of time, then outputs message and dies.
  1087. X */
  1088. X
  1089. Xringer(delay,message)
  1090. X
  1091. X    int        delay;
  1092. X    char    *message;
  1093. X{
  1094. X    sleep(delay);
  1095. X    timeset();
  1096. X    printf("\r\n                                                                               \r\n"); 
  1097. X    printf("Time %d:%02d %2s   ", hour, min, (ampm == 0 ? "AM" : "PM"));
  1098. X    printf("Activity scheduled:  %-41.41s ",message);
  1099. X    printf("\r\n                                                                               \r\n"); 
  1100. X} /* ringer */
  1101. *-*-END-of-callme.c-*-*
  1102. echo x - appts.l
  1103. sed 's/^X//' >appts.l <<'*-*-END-of-appts.l-*-*'
  1104. X.TH APPTS 1 
  1105. X.SH NAME
  1106. Xappts \- display current or selected day's appointments
  1107. X.SH SYNOPSIS
  1108. X.B appts 
  1109. X[ month day year ] [ filename(s) ]
  1110. X.sp
  1111. Xwhere
  1112. X.I        month
  1113. Xis a numeric value between 1 and 12,
  1114. X.I        day
  1115. Xis a numeric value between 1 and 31,
  1116. X.I        year
  1117. Xis a numeric four digit value and
  1118. X.I        filename(s)
  1119. Xis the name of the data file(s) to access.
  1120. X.SH DESCRIPTION
  1121. X.I Appts
  1122. Xis a program which uses the data stored by "vcal" or "eappts" to
  1123. Xdisplay the user's appointments to standard out.
  1124. X.PP
  1125. XWhen a date argument is present,
  1126. X.I appts
  1127. Xwill display appointments for the requested month, day and year.
  1128. XThe default argument values are the current month, day and year.
  1129. XWhen one or more filename arguments are used,
  1130. Xthose data files will be searched.
  1131. X.PP
  1132. XFive companion programs are available to use with the
  1133. X.I appts
  1134. Xprogram.  These are:
  1135. X.br
  1136. X.sp
  1137. X.nf
  1138. Xvcal            calendar and notes program
  1139. Xeappts          enter appointments from the UNIX command line
  1140. Xautocall        set appointment reminders for the current day
  1141. Xlcal            displays month's appointments in tablular form
  1142. Xcallme          sets a reminder prompt
  1143. X.fi
  1144. X.sp
  1145. XFor further information on these, reference the appropriate "man"
  1146. Xentries.
  1147. X.SH AUTHOR
  1148. XMike Essex
  1149. X.SH FILES
  1150. Xappts
  1151. X.br
  1152. X~/.appointments
  1153. X.br
  1154. X.SH "SEE ALSO"
  1155. Xvcal(1), eappts(1), autocall(1), lcal(1), callme(1)
  1156. X.SH BUGS
  1157. XThere are year 2000 time bombs.
  1158. *-*-END-of-appts.l-*-*
  1159. echo x - autocall.l
  1160. sed 's/^X//' >autocall.l <<'*-*-END-of-autocall.l-*-*'
  1161. X.TH AUTOCALL 1 
  1162. X.SH NAME
  1163. Xautocall \- appointment reminder program
  1164. X.SH SYNOPSIS
  1165. X.B autocall [ filename(s) ]
  1166. X.SH DESCRIPTION
  1167. X.I Autocall
  1168. Xis a program which will start appointment reminders running in
  1169. Xthe background.  At the desired time the user will be reminded
  1170. Xthat it is time for the appointment.
  1171. X.I Autocall
  1172. Xsearches ~/.appointments by default or if filename(s) are
  1173. Xspecified it accesses those files.
  1174. X.PP
  1175. XData used by
  1176. X.I autocall
  1177. Xmay be entered using either of two companion programs.
  1178. XThese are:
  1179. X.br
  1180. X.sp
  1181. X.nf
  1182. Xvcal            calendar and notes program
  1183. Xeappts          enter appointments from the UNIX command line
  1184. X.fi
  1185. X.sp
  1186. XFor further information on these, reference the appropriate "man"
  1187. Xentries.
  1188. X.SH AUTHOR
  1189. XMike Essex
  1190. X.SH FILES
  1191. Xautocall
  1192. X.br
  1193. X~/.appointments
  1194. X.br
  1195. X.SH "SEE ALSO"
  1196. Xvcal(1), eappts(1), callme(1), lcal(1), appts(1)
  1197. *-*-END-of-autocall.l-*-*
  1198. echo x - callme.l
  1199. sed 's/^X//' >callme.l <<'*-*-END-of-callme.l-*-*'
  1200. X.TH CALLME 1 
  1201. X.SH NAME
  1202. Xcallme \- appointment reminder program
  1203. X.SH SYNOPSIS
  1204. X.B callme
  1205. X(time) (message)
  1206. X.SH DESCRIPTION
  1207. X.I Callme
  1208. Xis a program which will start appointment reminders running in
  1209. Xthe background.  At the desired time the user will be reminded
  1210. Xthat it is time for the appointment.  The time and message for the
  1211. Xcall are entered on the command line.  The time must be entered in
  1212. X24 hour time with no colon.
  1213. X.SH AUTHOR
  1214. XMike Essex
  1215. X.SH "SEE ALSO"
  1216. Xautocall(1), vcal(1), callme(1), lcal(1), appts(1), eappts(1)
  1217. *-*-END-of-callme.l-*-*
  1218. exit
  1219.  
  1220.  
  1221.