home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / net / vcal.1 / text0000.txt < prev   
Encoding:
Text File  |  1987-02-20  |  25.4 KB  |  1,196 lines

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