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

  1. /********************************************************************
  2. **  YRCLJUL.C v0.17T  Copyright (c) 1987, 1988, 1989 by Paul M. Sittler.
  3. **
  4. **  Produces 3-digit Julian date calendars 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 char *lingo[];            /* Names of languages array */
  26. extern char *mnam[][12];        /* Names of months array */
  27.  
  28. extern char *new_file;
  29. extern char *file;
  30. extern FILE *fp;
  31.  
  32.  
  33.  
  34. void jul_printer(int year, char out, char base, int lang, char pause)
  35. /* char base;    Number base used, 0 = Decimal, H = Hex, O = Octal */
  36. /* int lang;    Language used 1=Danish, 2=Dutch, 3=English etc. */
  37. /* char pause;    Page pause True/False */
  38. {
  39.     int month,
  40.     day,
  41.     stat,
  42.     count,
  43.     leep;
  44.     char  temp[BUF];
  45.     int jul[12][31];            /* Array for Julian yr, */
  46.                     /* 12 months/year */
  47.                     /* 31 days/month */
  48.     char *off = (out == 'V') ?
  49.              " " :
  50.                "   "  ;
  51.     int month_length[12] =
  52.     {
  53.     0,  31,  59,  90, 120, 151, 181, 212, 243, 273, 304, 334
  54.     };
  55.  
  56.     char jul1[] =
  57.     {"Month:   Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec"};
  58.  
  59.     char jul2[] =
  60.     {"         ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---"};
  61.  
  62.     leep = leap(year);            /* Find out if leap year */
  63.     sprintf(jul1,
  64.     "         %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s  %3.3s",
  65.        mnam[lang - 1][0], mnam[lang - 1][ 1], mnam[lang - 1][ 2],
  66.        mnam[lang - 1][3], mnam[lang - 1][ 4], mnam[lang - 1][ 5],
  67.        mnam[lang - 1][6], mnam[lang - 1][ 7], mnam[lang - 1][ 8],
  68.        mnam[lang - 1][9], mnam[lang - 1][10], mnam[lang - 1][11] );
  69.  
  70.     if (out == 'F')
  71.     {
  72.     sprintf(file, "%dJUL%c", year, base);
  73.     strcpy(new_file, file);
  74.     strcat(file, ".$$$");
  75.     sprintf(temp, ".%3.3s", lingo[lang - 1]);
  76.     strcat(new_file, temp);
  77.     fp = fopen(file, "w");
  78.     }
  79.  
  80.     if (pause     &&            /* User wants time after each page */
  81.     out == 'P' )            /* gets printed to add paper etc... */
  82.     hold();                /* Wait for keystroke */
  83.  
  84.     fputs("\n\n\n", fp);
  85.     sprintf(temp, "%s%s%s%s 3-Digit Julian Calendar for %d",
  86.          (base == 'O') ? "Olde " : "" ,
  87.          base ? "Hacker's " : "" ,
  88.          base ? ( (base == 'O') ? "Octal " : "Hexadecimal ") : "",
  89.          lingo[lang - 1],
  90.          year);
  91.     fputs(center(temp, (out == 'V') ? 75 : 89), fp);
  92.     fputs("\n\n\n", fp);
  93.     fprintf(fp, "%s%s\n", off, jul1);
  94.     fprintf(fp, "%s%s\n", off, jul2);
  95.  
  96.     for (month = 0;
  97.      month < 12;            /* 12 months */
  98.      month++)
  99.     for (day = 1;
  100.          day < 32;            /* 31 days possible */
  101.          day++)
  102.     {
  103.         count = (day + month_length[month] + ((month > 1) ? leep : 0) );
  104.         if (count > (month_length[month + 1] + ((month) ? leep : 0)) )
  105.         count = 0;
  106.         jul[month][day - 1] = count;
  107.     }
  108.  
  109.     for (day = 0;
  110.      day < 31;
  111.      day++)
  112.     {
  113.     if ( (day)       &&
  114.          (!(day % 2)) )
  115.         fprintf(fp, "\n");
  116.  
  117.     fprintf(fp, "%sDay #%2d", off, day + 1);
  118.  
  119.     for (month = 0;
  120.          month < 12;
  121.          month++)
  122.     {
  123.         if (jul[month][day])
  124.         {
  125.         fprintf(fp,
  126.            (base ?
  127.                ((base == 'O') ?
  128.                   "  %3o" :
  129.                   "  %3X" ) :
  130.                   "  %3d"    ),
  131.               jul[month][day]);
  132.         }
  133.         else
  134.         fprintf(fp, "     ");
  135.     }
  136.     fprintf(fp, "   Day #%2d\n", day + 1);
  137.     }
  138.  
  139.     if (out != 'V')
  140.     fputs("\f\r", fp);        /* No FF for screen */
  141.  
  142.     if (out == 'F')            /* Setup for file output */
  143.     if ((stat = fclose(fp)) == ERROR)
  144.         printf("\nCan't close %s.\n", file);
  145.  
  146.     if (out == 'F')
  147.     if ((stat = rename(file, new_file)) == ERROR)
  148.         printf(
  149.         "\nCan't rename %s to %s.  %s may already exist.\n",
  150.                 file, new_file,
  151.                        new_file);
  152. }
  153.  
  154.  
  155.  
  156.