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

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