home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / DESKTOP / YRCALEND.ZIP / YRCLSCHD.C < prev   
Text File  |  1989-10-02  |  21KB  |  589 lines

  1. /********************************************************************
  2. **  YRCLSCHD.C v0.17T  Copyright (c) 1987, 1988, 1989 by Paul M. Sittler.
  3. **
  4. **  Produces <M>onthly, <W>eekly, and <D>aily schedules for YEARCAL.
  5. **
  6. **  All rights reserved.  The copyright owner hereby authorizes the
  7. **  no-charge, noncommercial making and/or distribution of copies of
  8. **  the entirety of this work unchanged and unincorporated in any
  9. **  other work (except "LiBRary" or "ARChive" disk files for the sole
  10. **  purpose of no-charge noncommercial distribution).  No other
  11. **  reproduction or use is authorized without the express prior
  12. **  written consent of the copyright owner.
  13. **
  14. **************************************************************/
  15.  
  16. /* ANSI header files included:  */
  17. #include <stdio.h>    /* fclose, fopen, fp, fprintf, fputs, */
  18.             /* gets, printf, rename, sprintf, stderr */
  19. #include <stdlib.h>    /* exit */
  20. #include <string.h>    /* strcat, strcmp, strcpy, strlen */
  21.  
  22. #include "yearcal.def"
  23.  
  24. /* External variables and structures declared in YEARCAL.C */
  25. extern struct options Opt;        /* User definable options */
  26. extern struct LineDraw bcs[];        /* border character sets array */
  27. extern struct month mon[];        /* Month's lengths array */
  28. extern char *lingo[];            /* Names of languages array */
  29. extern char *mnam[][12];        /* Names of months array */
  30. extern char *wkday[][7];        /* Names of days array */
  31. extern int yr[][12][6][7];        /* Array for 3 yrs, 4-D, */
  32.                     /* 3 years,      12 months/year, */
  33.                     /* 6 weeks/month, 7 days/week */
  34. extern char *new_file;
  35. extern char *file;
  36. extern FILE *fp;
  37.  
  38.  
  39.  
  40. void sched_printer(int year,        char out,
  41.            int bm,          int bd,
  42.            int bh,          int nh,
  43.            int pl,          int pw,
  44.            char sched_type, char title[][LIN],
  45.            char base,       int lang,
  46.            char pause,      int indent,    int lds)
  47. /* int year;        Year for calendar */
  48. /* char out;        Output goes where? View, Printer, File */
  49. /* int bm;        Month (beginning) for schedule */
  50. /* int bd;        Day (beginning) for schedule */
  51. /* int bh;        Hour (beginning) for schedule */
  52. /* int nh;        number of hours to schedule (1-24) */
  53. /* int pl;        Page Length in lines */
  54. /* int pw;        Page Width in columns */
  55. /* char sched_type;    Schedule type M(onthly), W(eekly), D(aily) */
  56. /* char title[][LIN];   User-modifiable title line array */
  57. /* char base;        Number base used, 0 = Decimal, H = Hex, O = Octal */
  58. /* int lang;        Language used 1=Danish, 2=Dutch, 3=English etc. */
  59. /* char pause;        Page pause flag True/False */
  60. /* int indent;        Left margin indent (# of spaces) */
  61. /* int lds;         Line draw char set used 0 = Ascii Characters */
  62.             /* 1 = 1-line top, sides, inside */
  63.             /* 2 = 2-line top, sides, inside */
  64.             /* 3 = 1-line top, double sides, inside */
  65.             /* 4 = 2-line top, single sides, inside */
  66. {
  67.     int bw,                /* Box width */
  68.     day,
  69.     first_day,
  70.     i, j,
  71.     month,
  72.     stat,
  73.     w,                /* Week number for printing top */
  74.                     /* calendars */
  75.     wk_day,
  76.     y;
  77.     char  linbuf  [BUF],
  78.       temp    [BUF],
  79.       temp1   [BUF],
  80.       temp2   [BUF],
  81.       temp3   [BUF],
  82.       temp4   [BUF],
  83.       top     [BUF],        /* Top line of schedule */
  84.       top2    [BUF],        /* Top line of daily schedule */
  85.                     /* under day headers. */
  86.       botm    [BUF],        /* Bottom line of schedule */
  87.       sep     [BUF],        /* Separator line between hours */
  88.       hoursw  [BUF],        /* Spacer line for daily schedule */
  89.       spacerw [BUF],        /* Spacer line for weekly schedule */
  90.       dates   [BUF];
  91.  
  92.     char *off = ( (out == 'V') ?
  93.                " " :    /* Offset for screen */
  94.     "                                        ");
  95.     /* 40 spaces-----------------------------| Max Offset for printing */
  96.  
  97.     if (out != 'V')            /* For <F>ile or <P>rinter output */
  98.     off[indent] = '\0';        /* Clip offset to proper length */
  99.  
  100.     y = 1;                /* Make year this year */
  101.  
  102.     if (out == 'V')            /* Gonna <V>iew it, so. . . */
  103.       pw = 80  ;            /* pw is screen width */
  104.  
  105.     if (out == 'F')            /* Setup for <F>ile output */
  106.     {
  107.     (sched_type == 'M') ?
  108.         sprintf(file, "%d%3.3s%c", year, mnam[lang - 1][bm], base):
  109.         sprintf(file, "%d%02d%02d", year, bm + 1, bd);
  110.     strcpy(new_file, file);
  111.     strcat(file, ".$$$");
  112.     sprintf(temp, ".%3.3s", lingo[lang - 1]);
  113.     strcat(new_file, temp);
  114.     fp = fopen(file, "w");
  115. /*      printf("\nOpened %s for write\n", file);*/
  116.     }
  117.  
  118.     first_day = weekday(year, bm + 1, 1);    /* 1st day of month */
  119.  
  120.     if (sched_type == 'M')        /* <M>onthly schedule */
  121.     wk_day = 0;            /* Month starts on first */
  122.     else                /* <W>eekly|<D>aily schedules */
  123.     wk_day = ( (first_day + bd - 1) % 7);    /* Gives us weekday */
  124.  
  125.     /* Lines 3, 4 & 5:  prepare text for center of titles */
  126.     if (sched_type == 'M')        /* <M>onthly schedule */
  127.     sprintf(title[3], "%s %d",
  128.                mnam[lang - 1][bm],
  129.                    year );
  130.     else                /* <W>eekly|<D>aily schedules */
  131.     sprintf(title[3], "%d %s, %d",
  132.                bd,
  133.                   mnam[lang - 1][bm],
  134.                   year );
  135.  
  136.     sprintf(title[4], sched_type == 'W' ? "Week begins on %s" :
  137.               sched_type == 'D' ? "%s" :
  138.                        ""  ,
  139.                wkday[lang - 1][wk_day]);
  140.  
  141.     sprintf(title[5], "%s",
  142.            sched_type == 'M' ?    "Monthly Calendar" :
  143.            sched_type == 'W' ?     "Weekly Schedule"  :
  144.                     "Daily Schedule"   );
  145.  
  146.     /* Begin building calendar body lines with offset spaces */
  147.     strcpy(hoursw,  off);        /* Put offset into hoursw */
  148.     strcpy(spacerw, off);        /* Put offset into spacerw */
  149.     strcpy(top,     off);        /* Put offset into top boundary */
  150.     strcpy(top2,    off);        /* Put offset into top2 line */
  151.     strcpy(botm,    off);        /* Put offset into bottom boundary */
  152.     strcpy(sep,     off);        /* Put offset into separator */
  153.  
  154.     /* Add time box to calendar lines for <D>aily|<W>eekly Schedules */
  155.     if (sched_type != 'M')        /* Need Time if <D>aily|<W>eekly */
  156.     {
  157.     sprintf(temp, Opt.mil ?        /* 24 hr time selected? */
  158.          "%c %s00 %c"     :        /* 24 hr time format */
  159.          "%c %s:00%%s %c" ,        /* am/pm time format */
  160.           bcs[lds].side,        /* West side frame line */
  161.          base          ?        /* Programmer's calendar */
  162.          base == 'O' ?        /* Octal requested */
  163.          "%02o"      :        /* Octal numbering */
  164.          "%02X"      :        /* Hexadecimal numbering */
  165.          "%02d"      ,        /* Decimal numbering */
  166.              bcs[lds].ns);
  167.     strcat(hoursw, temp);        /* Add header info to hoursw */
  168.  
  169.     sprintf(temp, Opt.mil ? "%c      %c"    :       /* 24 hr time */
  170.                 "%c         %c" ,    /* am/pm time */
  171.                 bcs[lds].side,
  172.                      bcs[lds].ns);
  173.     strcat(spacerw, temp);        /* Add header info to spacerw */
  174.  
  175.     for (i =  0;
  176.          i < 12;
  177.          i++   )
  178.     {
  179.         temp1[i] = bcs[lds].ew;
  180.         temp2[i] = bcs[lds].line;
  181.     }
  182.  
  183.     temp1[i] = '\0';        /* Terminate temp1 */
  184.     temp2[i] = '\0';        /* Terminate temp2 */
  185.  
  186.     sprintf(temp, Opt.mil ? "%c%6.6s%c" :    /* 24 hr time */
  187.                 "%c%9.9s%c" ,    /* am/pm time */
  188.                  bcs[lds].nw,
  189.                    temp2,
  190.                      bcs[lds].ni);
  191.     strcat(top, temp);        /* Add header info to top */
  192.  
  193.     sprintf(temp, Opt.mil ?        /* 24 hr time selected? */
  194.           "%c%6.6s%c" :        /* 24 hr time format */
  195.           "%c%9.9s%c" ,        /* am/pm time format */
  196.            bcs[lds].sw,        /* South West corner */
  197.              temp2,
  198.               bcs[lds].si);    /* South Intersection */
  199.     strcat(botm, temp);        /* Add header info to botm */
  200.  
  201.     sprintf(temp, Opt.mil ?        /* 24 hr time selected? */
  202.           "%c%6.6s%c" :        /* 24 hr time format */
  203.           "%c%9.9s%c" ,        /* am/pm time format */
  204.            bcs[lds].wi,        /* West Intersection */
  205.              temp1,
  206.               bcs[lds].cross);    /* Interior Cross */
  207.     strcat(sep, temp);        /* Add header info to sep */
  208.     strcat(top2, temp);        /* Add header info to top2 */
  209.     }
  210.     else                /* Monthly Calendar, so. . . */
  211.     /* Add East Side to calendar lines for <M>onthly schedule */
  212.     {
  213.     sprintf(temp, "%c", bcs[lds].side);
  214.     strcat(hoursw,    temp);        /* Add header info to hoursw */
  215.     strcat(spacerw, temp);        /* Add header info to spacerw */
  216.     sprintf(temp, "%c", bcs[lds].wi);
  217.     strcat(sep,     temp);        /* Add header info to sep */
  218.     strcat(top2,     temp);        /* Add header info to top2 */
  219.     sprintf(temp, "%c", bcs[lds].nw);
  220.     strcat(top,    temp);        /* Add header info to top */
  221.     sprintf(temp, "%c", bcs[lds].sw);
  222.     strcat(botm,     temp);        /* Add header info to botm */
  223.     }
  224.  
  225.     bw = (((pw - strlen(hoursw) ) / 7) - 1);  /* Calculate Box Width */
  226.  
  227.     for (i = 0;                /* Form strings for each day */
  228.      i < bw;            /* As wide as Box Width */
  229.      i++)
  230.     {
  231.     temp [i] = ' ';            /* Using spaces */
  232.     temp1[i] = bcs[lds].line;    /* Using outer horizontal lines */
  233.     temp2[i] = bcs[lds].line;    /* Using outer horizontal lines */
  234.     temp3[i] = bcs[lds].ew;        /* Using inner horizontal lines */
  235.     temp4[i] = bcs[lds].ew;        /* Using inner horizontal lines */
  236.     }
  237.  
  238.     if (sched_type == 'M')        /* Monthly Calendar */
  239.     {
  240.     temp[i] = '\0';            /* Terminate temp string */
  241.     strcpy(dates, temp);        /* Copy temp to dates for length */
  242.     dates[i - 2] = '\0';        /* Cut dates to length */
  243.     }
  244.  
  245.     /* Build temp strings that will be multiply added to necessary strings */
  246.     /* Spacer line uses temp */
  247.     temp [i] = (sched_type == 'D')  ?    /* If Daily */
  248.                  ' ':    /* Add ' ' */
  249.              bcs[lds].ns;    /* Otherwise add '|' */
  250.  
  251.     /* Top line uses temp1 */
  252.     temp1[i] = bcs[lds].ni;        /* Add North Intersect */
  253.                     /* temp1 = "-------|" */
  254.  
  255.     /* Bottom line uses temp2 */
  256.     temp2[i] = (sched_type == 'D')  ?    /* If Daily */
  257.               bcs[lds].line :    /* Add outer line */
  258.               bcs[lds].si   ;    /* Add South Intersect */
  259.  
  260.     /* Separator line(s) uses temp3 */
  261.     temp3[i] = (sched_type == 'D')  ?    /* If Daily */
  262.               bcs[lds].ew   :    /* Add inner line */
  263.               bcs[lds].cross;    /* Otherwise add Cross */
  264.  
  265.     /* Top2 line uses temp4 */
  266.     temp4[i] = (sched_type == 'D')  ?    /* If Daily */
  267.               bcs[lds].isi  :    /* Add Inner South Intersection */
  268.               bcs[lds].cross;    /* Otherwise add Cross */
  269.     ++i;
  270.  
  271.     temp [i] = '\0';            /* Terminate temp  string */
  272.     temp1[i] = '\0';            /* Terminate temp1 string */
  273.     temp2[i] = '\0';            /* Terminate temp2 string */
  274.     temp3[i] = '\0';            /* Terminate temp3 string */
  275.     temp4[i] = '\0';            /* Terminate temp3 string */
  276.                     /* temp1 = "-------|" */
  277.  
  278.     for (i = 0;                /* Add multiple temps to hoursw, */
  279.      i < 7;                /* spacerw, top, botm, sep, top2 */
  280.      i++)
  281.     {
  282.     if (sched_type != 'M')        /* Weekly and Daily schedules */
  283.         strcat(hoursw, temp);    /* Add temp to hoursw */
  284.  
  285.     strcat(top,     temp1);        /* Add temp1 to top */
  286.     strcat(botm,    temp2);        /* Add temp2 to botm */
  287.     strcat(sep,     temp3);        /* Add temp3 to sep */
  288.     strcat(top2,    temp4);        /* Add temp4 to top2 */
  289.     strcat(spacerw, temp);        /* Add temp to spacerw */
  290.     }
  291.  
  292.     hoursw [strlen(hoursw)  - 1] = bcs[lds].side;    /* Side */
  293.     spacerw[strlen(spacerw) - 1] = bcs[lds].side;    /* Side */
  294.     top    [strlen(top)     - 1] = bcs[lds].ne;        /* NE corner */
  295.     botm   [strlen(botm)    - 1] = bcs[lds].se;        /* SE corner */
  296.     sep    [strlen(sep)     - 1] = bcs[lds].ei;        /* East Intersect */
  297.     top2   [strlen(top2)    - 1] = bcs[lds].ei;        /* East Intersect */
  298.  
  299.     strcat(spacerw, "\n");        /* Add '\n' */
  300.     strcat(hoursw,  "\n");        /* Add '\n' */
  301.     strcat(top,     "\n");        /* Add '\n' */
  302.     strcat(botm,    "\n");        /* Add '\n' */
  303.     strcat(sep,     "\n");        /* Add '\n' */
  304.     strcat(top2,    "\n");        /* Add '\n' */
  305.     /* All calendar body lines have been fully formed */
  306.  
  307.     pw = strlen(sep) - 1;        /* Adjust Page Width */
  308.  
  309.     if (pause     &&            /* User wants time after each page */
  310.     out == 'P' )            /* gets printed to add paper etc... */
  311.     hold();                /* Wait for keystroke */
  312.  
  313.     fputs("\n\n", fp);            /* Print two blank lines */
  314.  
  315.     /* Line One:  Last and Next Month's names */
  316.     sprintf(temp, "%s %d",        /* Last month's name and year */
  317.            mnam[lang - 1]    /* Use selected language */
  318.                [sched_type == 'M' ?    /* <M>onthly selected */
  319.                (bm + 11) % 12 :    /* Use previous month */
  320.                        bm ],    /* Use beginning month */
  321.             sched_type == 'M' ?    /* <M>onthly selected */
  322.                   bm == 0 ?    /* Started in Jan ? */
  323.                   year - 1 :    /* Use previous year */
  324.                   year    :    /* Otherwise use year */
  325.                   year     );
  326.  
  327.     sprintf(temp2,"%s %d",        /* Next month's name and year */
  328.            mnam[lang - 1 ]    /* Use selected language */
  329.                [(bm + 1) % 12],
  330.               bm == 11 ?    /* Month is December */
  331.               year + 1 :    /* Use next year */
  332.               year      );    /* Otherwise use year */
  333.     strcpy(linbuf, off);
  334.     strcat(linbuf, center(temp, 21));
  335.     strcat(linbuf, center(title[0], (pw - 42 - strlen(off)) ) );
  336.     strcat(linbuf, center(temp2, 21) );
  337.     strcat(linbuf, "\n");
  338.     fputs (linbuf, fp);            /* Write Line One */
  339.  
  340.     /* Line Two:  Weekday headers like: " SU MO TU WE TH FR SA" */
  341.     temp[0] = '\0';            /* Init temp */
  342.  
  343.     for (i = 0;                /* From Sunday (0) */
  344.      i < 7 ;            /* Through Saturday (6) */
  345.      i++)
  346.     {
  347.     sprintf(temp2, " %2.2s",    /* For each day name */
  348.              wkday[lang - 1][i] );    /* Use selected language */
  349.     strcat(temp, temp2);        /* Add it to temp */
  350.     }  /* Temp is now formed like:  " SU MO TU WE TH FR SA" */
  351.  
  352.     /* Start forming Line Two in linbuf */
  353.     strcpy(linbuf, off);        /* Add offset spaces */
  354.     strcat(linbuf, center(temp, 21));    /* Add prev month weekday headers */
  355.                     /* Add title text centered */
  356.     strcat(linbuf, center(title[1], (pw - 42 - strlen(off)) ) );
  357.     strcat(linbuf, center(temp, 21));    /* Add next month weekday headers */
  358.     strcat(linbuf, "\n");        /* Add newline (CR/LF) */
  359.     fputs(linbuf, fp);            /* Write Line Two */
  360.  
  361.     /* Lines 3-8:  Prev/Next Month's dates like: " 26 27 28 29 30 31   " */
  362.     for (w = 0;
  363.      w < 6;                 /* Each month can have six weeks */
  364.      w++)
  365.     {
  366.     temp [0] = '\0';        /* For Prev month's dates */
  367.     temp2[0] = '\0';        /* For Next month's dates */
  368.  
  369.     for (day = 0;
  370.          day < 7;            /* 7 days/week */
  371.          day++)
  372.     {
  373.         /* Form prev month's week day number in linbuf */
  374.         sprintf(linbuf,
  375.         /* Check for valid date in the calendar array */
  376.         /*   to determine whether to print date or spaces */
  377.         yr[sched_type == 'M' ?    /* <M>onthly selected ? */
  378.                  bm == 0 ?    /* January selected? */
  379.                    y - 1 :     /* Use prev year */
  380.                    y :    /* Use this year */
  381.                    y  ]    /* Use this year */
  382.           [sched_type == 'M' ?    /* <M>onthly selected ? */
  383.               (bm + 11) % 12 :    /* Prev month normalized */
  384.                  bm   ]    /* Use beginning month */
  385.           [w][day]         ?    /* Non-zero date in array? */
  386.             base         ?    /* Programmer's calendar? */
  387.             base == 'O'         ?    /* Octal numbering selected? */
  388.             "%3o"          :    /* Octal number format */
  389.             "%3X"         :    /* Hexadecimal number format */
  390.             "%3d"         :    /* Decimal number format */
  391.             "   "          ,    /* No date, so no number */
  392.         yr[sched_type == 'M' ?    /* <M>onthly selected ? */
  393.                  bm == 0 ?    /* January selected? */
  394.                    y - 1 :    /* Use prev year */
  395.                    y :    /* Use this year */
  396.                    y  ]    /* Use this year */
  397.           [sched_type == 'M' ?    /* <M>onthly selected ? */
  398.               (bm + 11) % 12 :    /* Prev month normalized */
  399.                   bm  ]    /* Use beginning month */
  400.            [w] [day] );
  401.         /* linbuf has Prev Month's week date like: " 26" or "   " */
  402.  
  403.         /* Form next month's week day number in temp1 */
  404.         sprintf(temp1,
  405.         /* Check for valid date in the calendar array */
  406.         /*   to determine whether to print date or spaces */
  407.         yr[bm == 11 ?        /* Beginning month is December? */
  408.               y + 1 :        /* So next month bumps year */
  409.               y      ]        /* Else use year */
  410.           [(bm + 1) % 12]    /* Next month normalized */
  411.           [w][day]    ?    /* Non-zero date in array? */
  412.               base    ?    /* Programmer's calendar? */
  413.               base == 'O' ?    /* Octal numbering selected? */
  414.             "%3o"     :    /* Octal number format */
  415.             "%3X"     :    /* Hexadecimal number format */
  416.             "%3d"     :    /* Decimal number format */
  417.             "   "      ,    /* No date, so no number */
  418.          yr[bm == 11 ?        /* Beg Month is December? */
  419.                y + 1 :        /* Bump year by one */
  420.                y  ]        /* Else same year */
  421.            [(bm + 1) % 12]    /* Next month normalized */
  422.            [w][day]);
  423.         /* temp1 has Next Month's week date like: " 26" or "   " */
  424.  
  425.         strcat(temp, linbuf);    /* Add prev month's dates to temp */
  426.         strcat(temp2, temp1);    /* Add next month's dates to temp */
  427.     } /* end for (day = 0 to 6) */
  428.  
  429.     /* temp  has Prev Month's week dates like: " 24 25 26 27 28 29 30" */
  430.     /* temp2 has Next Month's week dates like: " 26 27 28 29 30      " */
  431.  
  432.     strcpy(linbuf, off);        /* Copy offset spaces to linbuf */
  433.  
  434.     /* Add prev month's weekdays */
  435.     strcat(linbuf, center(temp, 21));
  436.  
  437.     /* Add title text centered in remaining space */
  438.     strcat(linbuf, center(title[w + 2], (pw - 42 - strlen(off)) ) );
  439.  
  440.     /* Add next month's week days centered */
  441.     strcat(linbuf, center(temp2, 21) );
  442.  
  443.     strcat(linbuf, "\n");        /* Add newline */
  444.     fputs(linbuf, fp);        /* Write Line Three-Eight */
  445.     }
  446.  
  447.     /* All eight title lines at the top of the page have been written. */
  448.     /* We are now ready to form and output the schedule itself. */
  449.  
  450.     fputs(top, fp);            /* Print Top boundary */
  451.  
  452.     /* <W>eekly|<D>aily schedules have a present week's Date Line */
  453.     /*"   |      | 1 OCT | 2 OCT | 3 OCT | 4 OCT | 5 OCT | 6 OCT | 7 OCT |" */
  454.     if (sched_type != 'M')        /* <W>eekly|<D>aily schedule */
  455.     {
  456.     sprintf(linbuf, Opt.mil ?    /* 24 hour time selected */
  457.             "%s%c      %c" :    /* 24 hr format */
  458.             "%s%c         %c",    /* am/pm format */
  459.              off,            /* Spaces offset */
  460.                bcs[lds].side,    /* Side '|' */
  461.                     bcs[lds].ns);    /* Inner '|' */
  462.  
  463.     for (i = day = bd, month = bm;
  464.          i < (bd + 7);
  465.          i++, day++)
  466.     {
  467.         if (day >  mon[month].length)    /* Past this month */
  468.         {
  469.         day -= mon[month].length;    /* So make it proper day... */
  470.         month++;            /* Of following month. . . */
  471.         month = month % 12;     /* And then normalise it. . . */
  472.         }
  473.  
  474.         sprintf(temp1, "%d %3.3s", day, mnam[lang - 1][month]);
  475.         sprintf(temp, "%s%c", center(temp1, bw), bcs[lds].ns );
  476.         strcat(linbuf, temp);
  477.     }
  478.  
  479.     linbuf[strlen(linbuf) - 1] = bcs[lds].side;    /* Last ns to side */
  480.     strcat(linbuf, "\n");        /* Add newline */
  481.     fputs(linbuf, fp);        /* Write Date line */
  482.     }
  483.  
  484.     /* All schedules have a present week's Day of the Week Line */
  485.     /*"    |      | SUNDAY | MONDAY | TUESDAY|. . . |SATURDAY|" */
  486.     sprintf(linbuf, sched_type != 'M' ?    /* Add time box */
  487.                   Opt.mil ?    /* 24 hr time selected */
  488.             "%s%c      %c"    :    /* 24 hr format */
  489.             "%s%c         %c" :    /* am/pm format */
  490.             "%s%c",        /* <M>onthly has no time box */
  491.              off,        /* Spaces offset */
  492.                bcs[lds].side,    /* Left Side */
  493.                       bcs[lds].ns);    /* Vertical */
  494.  
  495.     /* Now add names of the days of the week */
  496.     for (i = wk_day;
  497.      i < (wk_day + 7);
  498.      i++)
  499.     {
  500.     sprintf(temp1, "%3.13s", wkday[lang - 1][i % 7]);
  501.     sprintf(temp, "%s%c", center(temp1, bw), bcs[lds].ns );
  502.     strcat(linbuf, temp);        /* Add day's name */
  503.     }
  504.  
  505.     linbuf[strlen(linbuf) - 1] = bcs[lds].side;        /* Right Side */
  506.     strcat(linbuf, "\n");        /* Add newline */
  507.     fputs(linbuf, fp);            /* Write Day of Week Line */
  508.  
  509.     if (sched_type == 'M')        /* Monthly calendar */
  510.     {                    /* Months have 5 or 6 weeks */
  511.     bh = 0;
  512.     nh = (yr[y][bm][5][0])?        /* Sixth week, Sunday? */
  513.                6:        /* Six weeks/month */
  514.                5;        /* Five weeks/month */
  515.     }
  516.  
  517.     for (i = bh;            /* Start at beginning hour */
  518.      i < (bh + nh);            /* Continue to number of hours */
  519.      i++)                /* Print the hourly lines */
  520.     {
  521.     if (i == bh)            /* First Sep is Top2 */
  522.         fputs(top2, fp);        /* Print Top2 Separator line */
  523.     else
  524.         fputs(sep, fp);        /* Print Separator lines */
  525.  
  526.     if (sched_type == 'M')
  527.     {
  528.             /* Initialize hoursw */
  529.         sprintf(hoursw, "%s%c",
  530.                  off,    /* Spaces offset */
  531.                    bcs[lds].side);    /* Side '|' */
  532.  
  533.         for (j = 0;
  534.          j < 7;            /* For seven days */
  535.          j++)
  536.         {
  537.         sprintf(temp,
  538.             yr[y][bm][i][j] ?    /* Non-zero date? */
  539.             base ?        /* Programmer's calendar */
  540.             base == 'O' ?   /* Octal selected? */
  541.               "%s%2o%c" :    /* Octal number format */
  542.               "%s%2X%c" :    /* Hexadecimal number format */
  543.               "%s%2d%c" :    /* Decimal number format */
  544.               "%s  %c"   ,    /* Not good date */
  545.                dates,
  546.                  yr[y][bm][i][j] ?    /* Non-zero date? */
  547.                  yr[y][bm][i][j] :    /* Use it */
  548.                    bcs[lds].ns    ,    /* Else outer '|' */
  549.                 bcs[lds].ns   );/* Outer bar */
  550.         strcat(hoursw, temp);
  551.         }
  552.  
  553.         hoursw[strlen(hoursw) - 1] = bcs[lds].side;    /* Side */
  554.         strcat(hoursw, "\n");
  555.     }
  556.  
  557.     fprintf(fp, hoursw,        /* Write hour/week line */
  558.             Opt.mil ?        /* 24 hr time selected? */
  559.            (i % 24) :        /* 24 hr time */
  560.            (i % 12) ?        /* If after 1 pm */
  561.            (i % 12) :        /*   use hour % 12 */
  562.             12  ,        /*   else 12 */
  563.             (i % 24 < 12) ?    /* Before noon? */
  564.                  "am" :    /* Add am */
  565.                  "pm" );    /* Add pm */
  566.  
  567.     for (j = 2;
  568.          j < ((pl - 18) / nh);
  569.          j++)
  570.         fputs(spacerw, fp);        /* Write Spacer Line(s) */
  571.     }
  572.  
  573.     fputs(botm, fp);            /* Write Bottom Line */
  574.  
  575.     if (out != 'V')            /* No FF for screen */
  576.     fputs("\f\r", fp);
  577.  
  578.     if (out == 'F')            /* Setup for file output */
  579.     if ((stat = fclose(fp)) == ERROR)
  580.         printf("\nCan't close %s.\n", file);
  581.  
  582.     if (out == 'F')
  583.     if ((stat = rename(file, new_file)) == ERROR)
  584.         printf(
  585.         "\nCan't rename %s to %s.  %s may already exist.\n",
  586.                 file, new_file,
  587.                        new_file);
  588. }
  589.