home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume9 / month / part02 < prev    next >
Text File  |  1987-04-13  |  23KB  |  1,346 lines

  1. Subject:  v09i050:  REPOST of Visual calendar program, Part02/02
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.TMC.COM
  4.  
  5. Submitted by: trwrb!ries (Marc Ries)
  6. Mod.sources: Volume 9, Issue 50
  7. Archive-name: month/Part02
  8.  
  9. # !/bin/sh
  10. # This is a shell archive, meaning:
  11. # 1. Remove everything above the /bin/sh line.
  12. # 2. Save the resulting text in a file.
  13. # 3. Execute the file with /bin/sh (not csh).
  14. #
  15. #    This archive created: Mar 17 1987
  16. #    By:    Marc Ries
  17. #
  18. export PATH; PATH=/bin:/usr/bin:$PATH
  19. #
  20. if `test ! -f ./Makefile`
  21. then
  22. echo "writing ./Makefile"
  23. cat > ./Makefile << 'RiesES_PIECES'
  24. #*            Modification History
  25. #*
  26. #*  Origional Author:  Tom Stoehn@Tektronics[zeus!tims]
  27. #*  Modifications by:  Marc Ries@TRW[trwrb!ries]
  28. #*
  29. #*
  30.  
  31. MONTH_OBJS = display.o help.o lunar.o\
  32.          month.o appt.c psched.o schedule.o time.o user.o
  33.  
  34. # Define OSFLAG = -DBSD if target system is Berkeley 4.2
  35. # Undefine LIB2 if target system is Pyramid SystemV Universe
  36. # Note: some systems may require termlib instead of termcap
  37. CC      = cc
  38. OSFLAG  = -DBSD
  39. # OSFLAG  = -DUSG
  40. CFLAGS  = -O -c $(OSFLAG)
  41. LDFLAGS = -s -n
  42. LIBS    = -lm -lcurses $(LIB2)
  43. LIB2    = -ltermcap
  44. DESTDIR = /usr/local/bin
  45. MANDIR  = /usr/man/manl
  46.  
  47. all:    month
  48.  
  49. install:    all man
  50.     install -s -m 555 month $(DESTDIR)
  51.  
  52. man:
  53.     install -c -m 644 month.1 $(MANDIR)
  54.  
  55. month: $(MONTH_OBJS)
  56.     $(CC) $(MONTH_OBJS) $(LIBS) $(LDFLAGS) -o month
  57.  
  58. appt.o: appt.c month.h
  59.     $(CC) $(CFLAGS) appt.c
  60.  
  61. display.o: display.c month.h
  62.     $(CC) $(CFLAGS) display.c
  63.  
  64. help.o: help.c month.h
  65.     $(CC) $(CFLAGS) help.c
  66.  
  67. lunar.o: lunar.c 
  68.     $(CC) $(CFLAGS) lunar.c
  69.  
  70. psched.o: psched.c month.h
  71.     $(CC) $(CFLAGS) psched.c
  72.  
  73. month.o: month.c month.h
  74.     $(CC) $(CFLAGS) month.c
  75.  
  76. schedule.o: schedule.c month.h
  77.     $(CC) $(CFLAGS) schedule.c
  78.  
  79. time.o: time.c month.h
  80.     $(CC) $(CFLAGS) time.c
  81.  
  82. user.o: user.c month.h
  83.     $(CC) $(CFLAGS) user.c
  84.  
  85. clean:
  86.     rm *.o
  87. RiesES_PIECES
  88. else
  89.   echo "will not over write ./Makefile"
  90. fi
  91. if `test ! -f ./appt.c`
  92. then
  93. echo "writing ./appt.c"
  94. cat > ./appt.c << 'RiesES_PIECES'
  95. /*
  96.  * appt.c 
  97.  *
  98.  * This function translates the .month data base into  one  that is compatable
  99.  * with the "appt" program. 
  100.  */
  101.  
  102. /*
  103.  * Modification History 
  104.  *
  105.  * Origional Author:  Robert Dextor@Tektronics[robertd@tekigm2] Modifications by: 
  106.  * Marc Ries@TRW[trwrb!ries] 
  107.  *
  108.  */
  109.  
  110. #include <curses.h>
  111. #include "month.h"
  112.  
  113. extern short    calflag, month, this_day, this_month, this_year;
  114.  
  115. char           *m_names[] = {
  116.                  "jan",
  117.                  "feb",
  118.                  "mar",
  119.                  "apr",
  120.                  "may",
  121.                  "jun",
  122.                  "jul",
  123.                  "aug",
  124.                  "sep",
  125.                  "oct",
  126.                  "nov",
  127.                  "dec"
  128. };
  129.  
  130. char           *day_names[] = {
  131.                    "sun",
  132.                    "mon",
  133.                    "tue",
  134.                    "wed",
  135.                    "thu",
  136.                    "fri",
  137.                    "sat"
  138. };
  139.  
  140.  
  141. display_appt(event)
  142.     struct event_rec *event;
  143. {
  144.  
  145.  
  146.     if (has_smtwtfs(event->smtwtfs))
  147.         pr_day_format(event);
  148.     else
  149.         pr_date_format(event);
  150.  
  151. }
  152. pr_day_format(event)
  153.     struct event_rec *event;
  154. {
  155. int             i;
  156.  
  157.     for (i = 0; i < 7; i++)
  158.         if (event->smtwtfs[i])
  159.             if (event->monthly)
  160.                 pr_reps(event, i);
  161.             else
  162.                 pr_date_format(event);
  163. }
  164.  
  165. pr_reps(event, day)
  166.     struct event_rec *event;
  167.     int             day;
  168. {
  169. int             i;
  170.  
  171.     for (i = this_month; i < 12; i++)
  172.     {
  173.         (void) printf("%s\t", day_names[day]);
  174.         pr_time(event);
  175.         if (event->last)
  176.             (void) printf("[%s,last]\t", m_names[i]);
  177.         else
  178.             (void) printf("[%s,%d]\t", m_names[i], event->nth);
  179.         pr_event(event);
  180.     }
  181. }
  182.  
  183. pr_time(event)
  184.     struct event_rec *event;
  185. {
  186.  
  187. short           stime, etime, hours, minutes, carry;
  188.     stime = event->hour * 100 + event->minute;
  189.     if (stime > 0)
  190.     {
  191.         if (calflag)
  192.         {
  193.             (void) printf("\t%02d:%02d", event->hour, event->minute);
  194.         } else
  195.         {
  196.             (void) printf("<%04d", stime);
  197.             etime = event->span_hours * 100 + event->span_minutes;
  198.             if (etime > 0)
  199.             {
  200.                 minutes = (event->minute + event->span_minutes) % 60;
  201.                 carry = (event->minute + event->span_minutes) / 60;
  202.                 hours = (event->hour + event->span_hours + carry) * 100;
  203.                 etime = hours + minutes;
  204.                 (void) printf("-%04d", etime);
  205.             }
  206.             (void) printf(">\t");
  207.         }
  208.     }
  209.     if (calflag)
  210.         (void) printf("\n");
  211. }
  212. pr_event(event)
  213.     struct event_rec *event;
  214. {
  215.     if (calflag)
  216.         (void) printf("\t%s", event->event_string);
  217.     else
  218.         (void) printf("\t;%s\n", event->event_string);
  219. }
  220.  
  221. pr_date_format(event)
  222.     struct event_rec *event;
  223. {
  224.  
  225.     if (calflag)
  226.     {
  227.         (void) printf("%s %02d ",
  228.                m_names[event->event_month - 1], event->event_day);
  229.     } else
  230.     {
  231.         (void) printf("%d/%d\t", event->event_month, event->event_day);
  232.     }
  233.     if (!calflag)
  234.         pr_time(event);
  235.     if (event->every)
  236.     {
  237.         if (!calflag)
  238.             (void) printf("[%d] ", event->nth * 7);
  239.     }
  240.     pr_event(event);
  241.     if (calflag)
  242.         pr_time(event);
  243. }
  244. RiesES_PIECES
  245. else
  246.   echo "will not over write ./appt.c"
  247. fi
  248. if `test ! -f ./display.c`
  249. then
  250. echo "writing ./display.c"
  251. cat > ./display.c << 'RiesES_PIECES'
  252. /*
  253.  * Modification History 
  254.  *
  255.  * Origional Author:  Tom Stoehn@Tektronics[zeus!tims] Modifications by:  Marc
  256.  * Ries@TRW[trwrb!ries] 
  257.  *
  258.  */
  259.  
  260. short           days;
  261. #include <curses.h>
  262. #include "month.h"
  263.  
  264. extern char    *strcpy();
  265.  
  266. short           days;
  267. short           crow, ccol;
  268. short           current_area;
  269. short           message_line_filled;
  270. char           *blankout = "                              ";
  271. extern short    SCHEDULE_ROW, SKID_ROW;
  272.  
  273. char           *days_of_week =
  274. "Sunday    Monday   Tuesday Wednesday  Thursday    Friday  Saturday";
  275.  
  276. short           schedule_cols[] = {
  277.          0, SMONTH_COL, SDAY_COL, SYEAR_COL, MONTHLY_COL, YEARLY_COL,
  278.                    EVERY_COL, NTH_COL, LAST_COL, SMTWTFS_COL,
  279.      SMTWTFS_COL + 3, SMTWTFS_COL + 6, SMTWTFS_COL + 9, SMTWTFS_COL + 12,
  280.                    SMTWTFS_COL + 15, SMTWTFS_COL + 18, -1
  281. };
  282.  
  283. char           *month_names[] = {
  284.                  "         ",
  285.                  "JANUARY  ",
  286.                  "FEBRUARY ",
  287.                  "MARCH    ",
  288.                  "APRIL    ",
  289.                  "MAY      ",
  290.                  "JUNE     ",
  291.                  "JULY     ",
  292.                  "AUGUST   ",
  293.                  "SEPTEMBER",
  294.                  "OCTOBER  ",
  295.                  "NOVEMBER ",
  296.                  "DECEMBER ",
  297.                  "         "
  298. };
  299.  
  300. char           *smtwtfs_names[] = {
  301.                    "Sun",
  302.                    "Mon",
  303.                    "Tue",
  304.                    "Wed",
  305.                    "Thu",
  306.                    "Fri",
  307.                    "Sat",
  308. };
  309.  
  310. extern short    month, day, year, start_day, edit_flag;
  311. extern short    this_month, this_day, this_year;
  312. extern struct event_rec current_event;
  313. short           first_year;
  314.  
  315. print_screen()
  316. {
  317.     print_month(month);
  318.     print_year(year);
  319.     print_day_headers();
  320.     print_cal(month, year, (char *) 0);
  321.     print_all_months();
  322.     print_all_years(year);
  323.     hl_month_year(month, 1, year, 1);
  324. }
  325.  
  326. print_month(month)
  327.     int             month;
  328. {
  329.     mvaddstr(0, 35, month_names[month]);
  330. }
  331.  
  332. print_year(year)
  333.     int             year;
  334. {
  335. char            nbuf[8];
  336.  
  337.     (void) sprintf(nbuf, "%4d", year);
  338.     mvaddstr(0, 47, nbuf);
  339. }
  340.  
  341. print_day_headers()
  342. {
  343.     mvaddstr(2, 12, days_of_week);
  344. }
  345.  
  346. print_cal(month, year, all_events_list)
  347.     register        month, year;
  348.     char           *all_events_list;
  349. {
  350. short           i, month_is_current, cday;
  351. short           row = 4, col = 13, standing_out = 0;
  352. char            nbuf[6];
  353.  
  354.     start_day = get_start_day(month, year);
  355.     days = days_in(month, year);
  356.     if (day > days)
  357.     {
  358.         day = days;
  359.     } else if (day < 1)
  360.     {
  361.         day = 1;
  362.     }
  363.     month_is_current = ((month == this_month) && (year == this_year));
  364.  
  365.     for (i = 1, cday = 1; i <= 42; i++)
  366.     {
  367.  
  368.         if ((cday <= days) && (i >= (start_day + 1)))
  369.         {
  370.             if (all_events_list)
  371.             {
  372.                 if (all_events_list[cday] == 1)
  373.                 {
  374.                     (void) sprintf(nbuf, "(%2d)", cday);
  375.                 } else if (all_events_list[cday] == 2)
  376.                 {
  377.                     (void) sprintf(nbuf, "[%2d]", cday);
  378.                 } else
  379.                 {
  380.                     (void) sprintf(nbuf, " %2d ", cday);
  381.                 }
  382.             } else
  383.             {
  384.                 (void) sprintf(nbuf, " %2d ", cday);
  385.             }
  386.             cday++;
  387.         } else
  388.         {
  389.             (void) strcpy(nbuf, "    ");
  390.         }
  391.         if (month_is_current && ((cday - 1) == this_day))
  392.         {
  393.             standout();
  394.             standing_out = 1;
  395.             month_is_current = 0;
  396.         }
  397.         mvaddstr(row, col, nbuf);
  398.  
  399.         if (standing_out)
  400.         {
  401.             standing_out = 0;
  402.             standend();
  403.         }
  404.         if ((i % 7) == 0)
  405.         {
  406.             row += 2;
  407.             col = 13;
  408.         } else
  409.         {
  410.             col += 10;
  411.         }
  412.     }
  413. }
  414.  
  415. print_all_months()
  416. {
  417. short           i;
  418.  
  419.     standout();
  420.     for (i = 0; i <= 13; i++)
  421.     {
  422.         mvaddstr(TOP_MONTH_ROW + i, 0, month_names[i]);
  423.     }
  424.     standend();
  425. }
  426.  
  427. print_all_years(year)
  428.     int             year;
  429. {
  430. short           i;
  431. char            nbuf[8];
  432.  
  433.     first_year = year - 4;
  434.     standout();
  435.     move(YEAR_ROW, YEAR_COL);
  436.     addstr("<<");
  437.     for (i = first_year; i < (first_year + 10); i++)
  438.     {
  439.         (void) sprintf(nbuf, " %4d ", i);
  440.         addstr(nbuf);
  441.     }
  442.     addstr(">>");
  443.     standend();
  444. }
  445.  
  446. hl_month_year(month, mflag, year, yflag)
  447.     short           month, mflag, year, yflag;
  448. {
  449. short           i;
  450.  
  451.     if (mflag != -1)
  452.     {
  453.         if (!mflag)
  454.         {
  455.             standout();
  456.         }
  457.         mvaddstr(TOP_MONTH_ROW + month, 0, month_names[month]);
  458.         if (!mflag)
  459.         {
  460.             standend();
  461.         }
  462.     }
  463.     if (yflag != -1)
  464.     {
  465.         if (!yflag)
  466.         {
  467.             standout();
  468.         }
  469.         move(YEAR_ROW, 14 + (6 * (year - first_year)));
  470.         for (i = 0; i < 6; i++)
  471.         {
  472.             addch(inch());
  473.         }
  474.         if (!yflag)
  475.         {
  476.             standend();
  477.         }
  478.     }
  479. }
  480.  
  481. start_display()
  482. {
  483.     goto_day(day);
  484. }
  485.  
  486. goto_this_day(gmonth, gday, gyear)
  487.     int             gmonth, gday, gyear;
  488. {
  489.     month = gmonth;
  490.     year = gyear;
  491.     day = gday;
  492.  
  493.     print_screen();
  494.  
  495.     switch (current_area)
  496.     {
  497.     case MONTHS:
  498.         goto_month(month);
  499.         break;
  500.     case DAYS:
  501.         goto_day(day);
  502.         break;
  503.     case YEARS:
  504.         goto_year(year);
  505.         break;
  506.     }
  507. }
  508.  
  509. goto_month(month)
  510.     int             month;
  511. {
  512.     crow = TOP_MONTH_ROW + month;
  513.     ccol = 9;
  514.     current_area = MONTHS;
  515. }
  516.  
  517. goto_day(tday)
  518.     short           tday;
  519. {
  520.     day = tday;
  521.     get_row_col_from_day(&crow, &ccol, day);
  522.     current_area = DAYS;
  523. }
  524.  
  525. goto_year(year)
  526.     int             year;
  527. {
  528.     crow = YEAR_ROW;
  529.     ccol = YEAR_COL + 3 + (6 * (year - first_year));
  530.     current_area = YEARS;
  531. }
  532.  
  533. goto_schedule()
  534. {
  535.     current_area = SCHEDULE;
  536.     crow = SKID_ROW;
  537.     ccol = MONTHLY_COL;
  538. }
  539.  
  540. move_cursor(dir)
  541.     register short  dir;
  542. {
  543. short           mday, row, col;
  544.  
  545.     if ((current_area != SCHEDULE) &&
  546.         ((dir == 'm') || (dir == 'y') || (dir == 'd')))
  547.     {
  548.         if (dir == 'm')
  549.         {
  550.             goto_month(month);
  551.         } else if (dir == 'y')
  552.         {
  553.             goto_year(year);
  554.         } else
  555.         {
  556.             goto_day(day);
  557.         }
  558.         return;
  559.     }
  560.     switch (current_area)
  561.     {
  562.     case MONTHS:
  563.         switch (dir)
  564.         {
  565.         case 'j':
  566.             if (crow <= (TOP_MONTH_ROW + 12))
  567.             {
  568.                 crow++;
  569.             }
  570.             break;
  571.         case 'k':
  572.             if (crow > TOP_MONTH_ROW)
  573.             {
  574.                 crow--;
  575.             }
  576.             break;
  577.         }
  578.         break;
  579.     case YEARS:
  580.         switch (dir)
  581.         {
  582.         case 'h':
  583.             if (ccol > YEAR_COL)
  584.             {
  585.                 if (ccol == (YEAR_COL + 3))
  586.                 {
  587.                     ccol = YEAR_COL;
  588.                 } else
  589.                 {
  590.                     ccol -= 6;
  591.                 }
  592.             } else
  593.             {
  594.                 shift_years(-1);
  595.             }
  596.             break;
  597.         case 'l':
  598.             if (ccol < LAST_YEAR_COL)
  599.             {
  600.                 if (ccol == (LAST_YEAR_COL - 6))
  601.                 {
  602.                     ccol = LAST_YEAR_COL;
  603.                 } else if (ccol == YEAR_COL)
  604.                 {
  605.                     ccol = YEAR_COL + 3;
  606.                 } else
  607.                 {
  608.                     ccol += 6;
  609.                 }
  610.             } else
  611.             {
  612.                 shift_years(1);
  613.             }
  614.             break;
  615.         }
  616.         break;
  617.     case DAYS:
  618.  
  619.         row = crow;
  620.         col = ccol;
  621.  
  622.         switch (dir)
  623.         {
  624.         case 'h':
  625.             if (col > 15)
  626.             {
  627.                 col -= 10;
  628.             }
  629.             break;
  630.         case 'j':
  631.             if (row < 14)
  632.             {
  633.                 row += 2;
  634.             }
  635.             break;
  636.         case 'k':
  637.             if (row > 4)
  638.             {
  639.                 row -= 2;
  640.             }
  641.             break;
  642.         case 'l':
  643.             if (col < 74)
  644.             {
  645.                 col += 10;
  646.             }
  647.             break;
  648.         }
  649.         if ((mday = get_day_from_row_col(row, col)) > 0)
  650.         {
  651.             day = mday;
  652.             crow = row;
  653.             ccol = col;
  654.         }
  655.         break;
  656.     case SCHEDULE:
  657.         schedule_move_cursor(dir);
  658.         break;
  659.     }
  660. }
  661.  
  662. schedule_move_cursor(dir)
  663.     short           dir;
  664. {
  665. short           i;
  666.  
  667.     switch (dir)
  668.     {
  669.     case 'H':
  670.         if (crow == SKID_ROW)
  671.         {
  672.             ccol = DATE_COL;
  673.         }
  674.         break;
  675.     case 'L':
  676.         if (crow == SKID_ROW)
  677.         {
  678.             ccol = SMTWTFS_COL + 18;
  679.         }
  680.         break;
  681.     case 'h':
  682.     case 'l':
  683.         if (crow == SKID_ROW)
  684.         {
  685.             i = 0;
  686.             while (schedule_cols[++i] != ccol);
  687.             i += ((dir == 'h') ? -1 : 1);
  688.             if (schedule_cols[i] != -1)
  689.             {
  690.                 ccol = schedule_cols[i];
  691.             }
  692.         } else if ((crow == TIME_ROW) || (crow == DURATION_ROW))
  693.         {
  694.             ccol = (dir == 'h') ? TIME_COL : MINUTE_COL;
  695.         } else if (crow == ACCEPT_ROW)
  696.         {
  697.             ccol = (dir == 'h') ? ACCEPT_COL : CANCEL_COL;
  698.         }
  699.         break;
  700.     case '\t':
  701.     case '\n':
  702.     case '\r':
  703.         if (crow == SKID_ROW)
  704.         {
  705.             crow += 2;
  706.             ccol = TIME_COL;
  707.         } else if (crow == DESCRIPTION_ROW)
  708.         {
  709.             crow = ACCEPT_ROW;
  710.             ccol = ACCEPT_COL;
  711.         } else if (crow == ACCEPT_ROW)
  712.         {
  713.             crow = SKID_ROW;
  714.             ccol = MONTHLY_COL;
  715.         } else if (crow == DURATION_ROW)
  716.         {
  717.             crow = DESCRIPTION_ROW;
  718.             ccol = TIME_COL + strlen(current_event.event_string);
  719.             handle_event_description();
  720.         } else
  721.         {
  722.             crow++;
  723.         }
  724.         break;
  725.     case '\033':
  726.         goto_day(day);
  727.         break;
  728.     }
  729. }
  730.  
  731. selection()
  732. {
  733. short           new_year;
  734. int             x;
  735.  
  736.     switch (current_area)
  737.     {
  738.     case MONTHS:
  739.         if ((crow - TOP_MONTH_ROW) != month)
  740.         {
  741.             if (crow <= TOP_MONTH_ROW)
  742.             {
  743.                 hl_month_year(month, 0, 0, -1);
  744.                 month = 12;
  745.                 shift_years(-1);
  746.                 hl_month_year(month, 1, 0, -1);
  747.                 crow = TOP_MONTH_ROW + 13;
  748.             } else if (crow > (TOP_MONTH_ROW + 12))
  749.             {
  750.                 hl_month_year(month, 0, 0, -1);
  751.                 month = 1;
  752.                 shift_years(1);
  753.                 hl_month_year(month, 1, 0, -1);
  754.                 crow = TOP_MONTH_ROW;
  755.             } else
  756.             {
  757.                 hl_month_year(month, 0, 0, -1);
  758.                 month = crow - TOP_MONTH_ROW;
  759.                 hl_month_year(month, 1, 0, -1);
  760.                 print_cal(month, year, (char *) 0);
  761.             }
  762.             print_month(month);
  763.         }
  764.         break;
  765.     case YEARS:
  766.         if (ccol == YEAR_COL)
  767.         {
  768.             shift_years(-10);
  769.         } else if (ccol == LAST_YEAR_COL)
  770.         {
  771.             shift_years(10);
  772.         } else
  773.         {
  774.             new_year = first_year +
  775.                 ((ccol - (YEAR_COL + 3)) / 6);
  776.             if (new_year != year)
  777.             {
  778.                 hl_month_year(0, -1, year, 0);
  779.                 year = new_year;
  780.             }
  781.             print_cal_hl_year(month, year);
  782.         }
  783.         break;
  784.     case SCHEDULE:
  785.         if (crow == SKID_ROW)
  786.         {
  787.             select_regularity_col(ccol);
  788.         } else if (crow == ACCEPT_ROW)
  789.         {
  790.             x = (ccol == ACCEPT_COL) ? ACCEPT : CANCEL;
  791.             accept_cancel(ccol == ACCEPT_COL);
  792.             if (edit_flag)
  793.             {
  794.                 return (x);
  795.             }
  796.         } else
  797.         {
  798.             move_cursor('\t');
  799.         }
  800.         break;
  801.     }
  802.     return (NOTHING);
  803. }
  804.  
  805. shift_years(shift)
  806.     short           shift;
  807. {
  808.     if (((year + shift) < (first_year + 10)) &&
  809.         ((year + shift) >= first_year))
  810.     {
  811.         hl_month_year(0, -1, year, 0);
  812.         year += shift;
  813.         hl_month_year(0, -1, year, 1);
  814.     } else
  815.     {
  816.         year += shift;
  817.         print_all_years(first_year + shift + 4);
  818.     }
  819.     print_cal_hl_year(month, year);
  820. }
  821.  
  822. print_cal_hl_year(month, year)
  823.     int             month, year;
  824. {
  825.     print_cal(month, year, (char *) 0);
  826.     print_year(year);
  827.     hl_month_year(0, -1, year, 1);
  828. }
  829.  
  830. get_row_col_from_day(row, col, day)
  831.     short          *row, *col, day;
  832. {
  833.     *row = 4 + (((start_day + day - 1) / 7) * 2);
  834.     *col = 15 + (((start_day + day - 1) % 7) * 10);
  835. }
  836.  
  837. get_day_from_row_col(row, col)
  838.     short           row, col;
  839. {
  840. short           mday;
  841.  
  842.     mday = (7 * ((row - 4)) / 2) +
  843.         ((col - 14) / 10) - start_day + 1;
  844.  
  845.     if ((mday <= days) && (mday > 0))
  846.     {
  847.         return (mday);
  848.     }
  849.     return (0);
  850. }
  851.  
  852. print_event_regularity(event)
  853.     struct event_rec *event;
  854. {
  855.     if (event->monthly)
  856.     {
  857.         standout();
  858.     }
  859.     mvaddstr(SKID_ROW, MONTHLY_COL, "monthly");
  860.     standend();
  861.     if (event->yearly)
  862.     {
  863.         standout();
  864.     }
  865.     mvaddstr(SKID_ROW, YEARLY_COL, "yearly");
  866.     standend();
  867.     if (event->every)
  868.     {
  869.         standout();
  870.     }
  871.     mvaddstr(SKID_ROW, EVERY_COL, "every");
  872.     standend();
  873.     print_smtwtfs(event->smtwtfs);
  874.     print_nth(event);
  875.     if (event->last)
  876.     {
  877.         standout();
  878.     }
  879.     mvaddstr(SKID_ROW, LAST_COL, "last");
  880.     standend();
  881. }
  882.  
  883. print_smtwtfs(smtwtfs)
  884.     char            smtwtfs[];
  885. {
  886. short           i;
  887.  
  888.     move(SKID_ROW, SMTWTFS_COL);
  889.  
  890.     for (i = 0; i < 7; i++)
  891.     {
  892.         if (smtwtfs[i])
  893.         {
  894.             standout();
  895.         }
  896.         addstr(smtwtfs_names[i]);
  897.         if (smtwtfs[i])
  898.         {
  899.             standend();
  900.         }
  901.     }
  902. }
  903.  
  904. hl_schedule(col, hflag)
  905.     register        col, hflag;
  906. {
  907. register int    ch;
  908. short           i;
  909.  
  910.     move(SKID_ROW, col);
  911.  
  912.     if (hflag)
  913.     {
  914.         standout();
  915.     }
  916.     if ((col < SMTWTFS_COL) || (col > (SMTWTFS_COL + 18)))
  917.     {
  918.         while ((ch = inch()) != ' ')
  919.         {
  920.             move(SKID_ROW, col);
  921.             addch(ch);
  922.             col++;
  923.         }
  924.     } else
  925.     {
  926.         move(SKID_ROW, col);
  927.  
  928.         for (i = 0; i < 3; i++)
  929.         {
  930.             addch(inch());
  931.         }
  932.     }
  933.     standend();
  934. }
  935.  
  936. display_event(event)
  937.     struct event_rec *event;
  938. {
  939.     clear_schedule_area();
  940.     print_date(event->event_month, event->event_day, event->event_year, (char *) 0);
  941.     print_event_regularity(event);
  942.     print_time(event, (char *) 0);
  943.     print_span(event, (char *) 0);
  944.     print_event_description(event, (char *) 0);
  945.     print_accept();
  946. }
  947.  
  948. print_accept()
  949. {
  950.     mvaddstr(ACCEPT_ROW, TIME_COL, "Accept/Cancel");
  951. }
  952.  
  953. print_time(event, rbuf)
  954.     struct event_rec *event;
  955.     char           *rbuf;
  956. {
  957. char            buf[32];
  958. short           hour;
  959. char           *apm;
  960.  
  961.     hour = event->hour;
  962.     apm = (hour < 12) ? "AM" : "PM";
  963.  
  964.     if (hour > 12)
  965.     {
  966.         hour = hour % 12;
  967.     }
  968.     if (hour == 0)
  969.     {
  970.         hour = 12;
  971.     }
  972.     (void) sprintf((rbuf ? rbuf : buf), "time:  %2d:%02d %s", hour,
  973.                event->minute, apm);
  974.     if (!rbuf)
  975.     {
  976.         mvaddstr(TIME_ROW, 4, buf);
  977.     }
  978. }
  979.  
  980. print_span(event, rbuf)
  981.     struct event_rec *event;
  982.     char           *rbuf;
  983. {
  984. char            buf[32];
  985.  
  986.     (void) sprintf((rbuf ? rbuf : buf), "    span:  %2d:%02d", event->span_hours,
  987.                event->span_minutes);
  988.     if (!rbuf)
  989.     {
  990.         mvaddstr(DURATION_ROW, 0, buf);
  991.     }
  992. }
  993.  
  994. print_event_description(event, rbuf)
  995.     struct event_rec *event;
  996.     char           *rbuf;
  997. {
  998. char            buf[100];
  999.  
  1000.     (void) sprintf((rbuf ? rbuf : buf), "event:  %s", event->event_string);
  1001.     if (!rbuf)
  1002.     {
  1003.         mvaddstr(DESCRIPTION_ROW, 3, buf);
  1004.     }
  1005. }
  1006.  
  1007. scroll_time(dir)
  1008.     register        dir;
  1009. {
  1010. short           hour, minute, d;
  1011.  
  1012.     if (crow == TIME_ROW)
  1013.     {
  1014.         hour = current_event.hour;
  1015.         minute = current_event.minute;
  1016.     } else if (crow == DURATION_ROW)
  1017.     {
  1018.         hour = current_event.span_hours;
  1019.         minute = current_event.span_minutes;
  1020.     } else if (crow != SKID_ROW)
  1021.     {
  1022.         return;
  1023.     }
  1024.     if (ccol == TIME_COL)
  1025.     {
  1026.         if (dir == ' ')
  1027.         {
  1028.             hour = (hour + 1) % 24;
  1029.         } else
  1030.         {
  1031.             hour = (hour + 23) % 24;
  1032.         }
  1033.     } else if (ccol == MINUTE_COL)
  1034.     {
  1035.         if (dir == ' ')
  1036.         {
  1037.             minute = (minute + 15) % 60;
  1038.         } else
  1039.         {
  1040.             minute = (minute + 45) % 60;
  1041.         }
  1042.     } else
  1043.     {
  1044.         if (ccol == SMONTH_COL)
  1045.         {
  1046.             current_event.event_month += ((dir == ' ') ? 1 : -1);
  1047.             if (current_event.event_month > 12)
  1048.             {
  1049.                 current_event.event_month = 1;
  1050.             } else if (current_event.event_month <= 0)
  1051.             {
  1052.                 current_event.event_month = 12;
  1053.             }
  1054.         } else if (ccol == SDAY_COL)
  1055.         {
  1056.             d = days_in(current_event.event_month,
  1057.                     current_event.event_year);
  1058.             current_event.event_day += ((dir == ' ') ? 1 : -1);
  1059.             if (current_event.event_day > d)
  1060.             {
  1061.                 current_event.event_day = 1;
  1062.             } else if (current_event.event_day <= 0)
  1063.             {
  1064.                 current_event.event_day = d;
  1065.             }
  1066.         } else if (ccol == SYEAR_COL)
  1067.         {
  1068.             current_event.event_year += ((dir == ' ') ? 1 : -1);
  1069.             if (current_event.event_year < 0)
  1070.             {
  1071.                 current_event.event_year = this_year;
  1072.             }
  1073.         } else if (ccol == NTH_COL)
  1074.         {
  1075.             current_event.nth += ((dir == ' ') ? 1 : -1);
  1076.             if (current_event.nth < 1)
  1077.             {
  1078.                 current_event.nth = 53;
  1079.             } else if (current_event.nth > 53)
  1080.             {
  1081.                 current_event.nth = 1;
  1082.             }
  1083.         }
  1084.     }
  1085.     if (crow == TIME_ROW)
  1086.     {
  1087.         current_event.hour = hour;
  1088.         current_event.minute = minute;
  1089.         print_time(¤t_event, (char *) 0);
  1090.     } else if (crow == DURATION_ROW)
  1091.     {
  1092.         current_event.span_hours = hour;
  1093.         current_event.span_minutes = minute;
  1094.         print_span(¤t_event, (char *) 0);
  1095.     } else if (ccol <= SYEAR_COL)
  1096.     {
  1097.         print_date(current_event.event_month,
  1098.                current_event.event_day, current_event.event_year, (char *) 0);
  1099.     } else if (ccol == NTH_COL)
  1100.     {
  1101.         current_event.nth_is_on = 1;
  1102.         print_nth(¤t_event);
  1103.  
  1104.     }
  1105. }
  1106.  
  1107. hl_all(event, mf, yf, ef, nf, lf, xf)
  1108.     struct event_rec *event;
  1109.     register        mf, yf, ef, nf, lf, xf;
  1110. {
  1111. short           i;
  1112.  
  1113.     toggle_char(&(event->monthly), mf, MONTHLY_COL);
  1114.     toggle_char(&(event->yearly), yf, YEARLY_COL);
  1115.     toggle_char(&(event->every), ef, EVERY_COL);
  1116.     toggle_char(&(event->nth_is_on), nf, NTH_COL);
  1117.     toggle_char(&(event->last), lf, LAST_COL);
  1118.  
  1119.     if (xf != -1)
  1120.     {
  1121.         for (i = 0; i < 7; i++)
  1122.         {
  1123.             toggle_char(&(event->smtwtfs[i]), xf,
  1124.                     (SMTWTFS_COL + (3 * i)));
  1125.         }
  1126.     }
  1127. }
  1128.  
  1129. toggle_char(c, f, col)
  1130.     char           *c;
  1131.     register        f, col;
  1132. {
  1133.     if (f == 1)
  1134.     {
  1135.         if (!(*c))
  1136.         {
  1137.             *c = 1;
  1138.             hl_schedule(col, f);
  1139.         }
  1140.     } else if (!f)
  1141.     {
  1142.         if (*c)
  1143.         {
  1144.             *c = 0;
  1145.             hl_schedule(col, f);
  1146.         }
  1147.     }
  1148. }
  1149.  
  1150. print_date(month, day, year, rbuf)
  1151.     int             month, day, year;
  1152.     char           *rbuf;
  1153. {
  1154. char            buf[64];
  1155.  
  1156.     if (!rbuf)
  1157.     {
  1158.         standout();
  1159.     }
  1160.     (void) sprintf((rbuf ? rbuf : buf), "%2d/%2d/%4d", month, day, year);
  1161.     if (!rbuf)
  1162.     {
  1163.         mvaddstr(SKID_ROW, DATE_COL, buf);
  1164.         standend();
  1165.     }
  1166. }
  1167.  
  1168. error_message(str, sound)
  1169.     char           *str;
  1170.     int             sound;
  1171. {
  1172.     mvaddstr(0, 0, blankout);
  1173.     mvaddstr(0, 0, str);
  1174.     refresh();
  1175.     if (sound)
  1176.     {
  1177.         sound_bell();
  1178.     }
  1179.     message_line_filled = 1;
  1180. }
  1181.  
  1182. sound_bell()
  1183. {
  1184.     (void) putchar(7);
  1185.     (void) fflush(stdout);
  1186. }
  1187.  
  1188. clear_schedule_area()
  1189. {
  1190.     move(SCHEDULE_ROW, 0);
  1191.     clrtobot();
  1192. }
  1193.  
  1194. blank_out(col)
  1195.     int             col;
  1196. {
  1197.     while (col < 35)
  1198.     {
  1199.         addch(' ');
  1200.         col++;
  1201.     }
  1202. }
  1203. print_nth(event)
  1204.     struct event_rec *event;
  1205. {
  1206. char           *ns, buf[10];
  1207. short           n;
  1208.  
  1209.     if (event->nth_is_on)
  1210.     {
  1211.         standout();
  1212.     }
  1213.     n = event->nth;
  1214.     if (event->nth > 13)
  1215.     {
  1216.         n %= 10;
  1217.     }
  1218.     switch (n)
  1219.     {
  1220.     case 0:
  1221.     case 4:
  1222.     case 5:
  1223.     case 6:
  1224.     case 7:
  1225.     case 8:
  1226.     case 9:
  1227.     case 10:
  1228.     case 11:
  1229.     case 12:
  1230.     case 13:
  1231.         ns = "th";
  1232.         break;
  1233.     case 1:
  1234.         ns = "st";
  1235.         break;
  1236.     case 2:
  1237.         ns = "nd";
  1238.         break;
  1239.  
  1240.     case 3:
  1241.         ns = "rd";
  1242.         break;
  1243.     }
  1244.     (void) sprintf(buf, "%02d%s", event->nth, ns);
  1245.     mvaddstr(SKID_ROW, NTH_COL, buf);
  1246.     standend();
  1247. }
  1248.  
  1249. remind(str, minutes)
  1250.     char           *str;
  1251.     int             minutes;
  1252. {
  1253. char            s[80];
  1254.  
  1255.     if (minutes > 1)
  1256.     {
  1257.         (void) sprintf(s, "In %d minutes", minutes);
  1258.     } else if (minutes == 1)
  1259.     {
  1260.         (void) strcpy(s, "In 1 minute");
  1261.     } else
  1262.     {
  1263.         (void) strcpy(s, "Right now");
  1264.     }
  1265.     (void) printf("\n\r==========\n\r%s   \n\r%s.   \n\r==========\n\r", str, s);
  1266.     sound_bell();
  1267. }
  1268.  
  1269. clear_message_line()
  1270. {
  1271.     message_line_filled = 0;
  1272.     mvaddstr(0, 0, blankout);
  1273. }
  1274.  
  1275. incr(ch)
  1276.     int             ch;
  1277. {
  1278. short           inc;
  1279.  
  1280.     inc = ((ch == 'n') || (ch == '+')) ? 1 : -1;
  1281.  
  1282.     switch (current_area)
  1283.     {
  1284.     case MONTHS:
  1285.         hl_month_year(month, 0, 0, -1);
  1286.         if ((month == 1) && (inc < 0))
  1287.         {
  1288.             shift_years(-1);
  1289.             month = 12;
  1290.         } else if ((month == 12) && (inc > 0))
  1291.         {
  1292.             shift_years(1);
  1293.             month = 1;
  1294.         } else
  1295.         {
  1296.             month += inc;
  1297.         }
  1298.         hl_month_year(month, 1, 0, -1);
  1299.         print_month(month);
  1300.         goto_month(month);
  1301.         print_cal(month, year, (char *) 0);
  1302.         break;
  1303.     case DAYS:
  1304.         if ((inc > 0) && (day >= days))
  1305.         {
  1306.             if (month == 12)
  1307.             {
  1308.                 month = 1;
  1309.                 year++;
  1310.             } else
  1311.             {
  1312.                 month++;
  1313.             }
  1314.             day = 1;
  1315.             goto_this_day(month, day, year);
  1316.         } else if ((inc < 0) && (day <= 1))
  1317.         {
  1318.             if (month == 1)
  1319.             {
  1320.                 month = 12;
  1321.                 year--;
  1322.             } else
  1323.             {
  1324.                 month--;
  1325.             }
  1326.             day = days_in(month, year);
  1327.             goto_this_day(month, day, year);
  1328.         } else
  1329.         {
  1330.             goto_day(day + inc);
  1331.         }
  1332.         break;
  1333.     case YEARS:
  1334.         shift_years(inc);
  1335.         goto_year(year);
  1336.         break;
  1337.     }
  1338. }
  1339. RiesES_PIECES
  1340. else
  1341.   echo "will not over write ./display.c"
  1342. fi
  1343. echo "Finished archive 2 of 2"
  1344. exit 0
  1345.  
  1346.