DAYTIME.C give the current time and date in a nice, expanded format

25/12/2008 - 18:29 von Alexander Horn | Report spam
Hallo VMS-Community,

ich habe noch nie so 'nen kultigen C Source Code gesehen! Aeh, vorab
natuerlich noch Frohe Weihnachten, Happy Chanukah 5769 und natuerlich
'nen gut'n Rutsch ins Jahr 2009!

Bis denne,
Euer Vaxima

/* <TITLE>DAYTIME.C give the current time and date in a nice, expanded format </TITLE> */
DAYTIME.C by Jeff Mercer, based on DAYTIME.PAS by Greg O'Rear

Written: January 2nd-4th, 1992
Updated: January 4th, 1992
Purpose: To give the current time and date in a nice, expanded format not
offered under any normal VMS time functions. Also prints out
a message on certain specific dates.
History: DAYTIME.C is simply a somewhat-updated form of DAYTIME.PAS that
was originally written by Greg O'Rear in January of 1986. His
version did not utilize the LIB$DAY_OF_WEEK routine, did not
print date suffixes, and used a data file to read in special
messages for certain dates. These were cosmetic changes I added
when doing this conversion as an exercise. I consider DAYTIME to
be a neat little time utility that could easily be expanded.
Location: DAYTIME.C and DAYTIME.PAS were both written on the CIRCA VAX
system of the University of Florida for personal usage.
Running : The program should compile, link, and run fine under any VMS 5.x
system, though if the LIB$DAY_OF_WEEK routine isn't available, it
will fail.

#include <stdio>
#include <stdlib>
#include <string>
#include <time>
#include starlet
#include lib$routines

typedef char linetype[80];
typedef char linefrag[24];

time_t BinTim;
unsigned short NumTim[7];
int DayNumber, Error, Month, Date, Date1,
Hour, Hr, Min, Min1, Min2;
char Suff[2];
linetype DateLine[13][32];

/* The following string array declerations are done in this manner to save
source-code space. */
linefrag NumWord[20] = /* The words for for 1 thru 19 */
{"", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"},

TensWord[6] = /* The words for 20, 30, 40, and 50 */
{"", "", "Twenty", "Thirty", "Forty", "Fifty"},

MonthName[13] = /* The names of the months */
{"", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"},

DayName[8] = /* The names of the days of the week */
{"", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"};

daytime() {
/* Load special dates into DateLine array */
strcpy(DateLine[1][1], "New Year's Day");
strcpy(DateLine[2][2], "Ground Hog Day");
strcpy(DateLine[2][14], "St. Valentine's Day");
strcpy(DateLine[2][12], "Abraham Lincon's birthday");
strcpy(DateLine[2][22], "George Washington's birthday");
strcpy(DateLine[3][17], "St. Patrick's Day");
strcpy(DateLine[4][1], "April Fools! Day");
strcpy(DateLine[4][6], "Happy Birthday, JTR!");
strcpy(DateLine[6][14], "Flag Day");
strcpy(DateLine[7][4], "Fourth Of July - Independence Day");
strcpy(DateLine[10][31], "Halloween");
strcpy(DateLine[11][11], "Veterans' Day");
strcpy(DateLine[12][25], "Christmas Day");
strcpy(DateLine[12][31], "New Year's Eve day");

/* get the current date and time */
Error=sys$gettim(BinTim); /* Get time in 64-bit binary format */
Error=sys$numtim(NumTim, BinTim); /* Divide into integer values */

/* Next, determine day of the week */
lib$day_of_week(0, &DayNumber); /* Never works if given actual date */

/* Set-up variables for outputing time */
Month=NumTim[1]; /* Take time values out of the NumTim */
Date=NumTim[2]; /* array and put into individual */
Hr=Hour=NumTim[3]; /* variables. Seconds and hundredths of */
Min=NumTim[4]; /* a second are never used. Min1 and */
Min1=Min/10; Min2=Min-(Min1*10); /* Min2 are the tens and ones value of */
if (Hr>11) Hr=Hr-12; /* the minutes. Hr is the hours in */
Date1=Date-((Date/10)*10); /* civilian value. Date1 is the ones */
/* value of the date. */

/* Determine what suffix to use with the date of the month */
strcpy(Suff, "th");
if (Date1==1) strcpy(Suff, "st");
else if (Date1==2) strcpy(Suff, "nd");
else if (Date1==3) strcpy(Suff, "rd");

/* Now, begin out-putting time in word format */
/* The hour */
if (Hr==0) /* Could have loaded NumWord[0] with */
printf("Twelve "); /* the word Twelve, but that would */
else /* look silly. */
printf("%s ", NumWord[Hr]);

/* The minutes */
if (Min==0) /* Check for on-the-dot hour */
printf("O'Clock, ");
else {
if ((Min>9) && (Min<20)) /* Output for the teens range of the */
printf("%s, ", NumWord[Min]); /* minutes. */
else {
if (Min>19) { /* Output appropiate tens word if more */
printf("%s", TensWord[Min1]); /* than 19 minutes after the hour. */
if (Min2>0) printf("-");
else /* Output appropiate ones word for the */
printf("Oh-"); /* minutes. This is for both less than */
printf("%s, ", NumWord[Min2]); /* 10 and more than 19 minute values. */
} /* (No ones-word is given is Min2=0 */

/* The Day, with modifiers */
if ((Hour>-1 && Hour<6) || /* It's an "early" time of day if between */
(Hour>11 && Hour<14) || /* midnight and 6am, 11am and 2pm, or 5pm */
(Hour>17 && Hour<20)) /* and 8pm. */
printf("early ");
if ((Hour>9 && Hour<12) || /* It's a "late" time of day if between */
(Hour>15 && Hour<18) || /* 9am and noon, 3pm and 6pm, or 10pm */
(Hour>21)) /* and midnight (just before). */
printf("late ");

printf("%s ", DayName[DayNumber]); /* Day of the week, calculated earlier */

if (Hour<12) /* It's morning if between midnight and just */
printf("morning"); /* before noon. */
if (Hour<18) /* It's afternoon if between noon and 6pm. */
printf("evening"); /* It's evening if between 6pm and midnight. */

/* The complete date */
printf(" - %s %d%s, %d",
MonthName[NumTim[1]], /* Full name of the month */
NumTim[2], Suff, /* Date of month with suffix */
NumTim[0]); /* The year (numerical) */

/* Special date name, if any */
if (DateLine[Month][Date][0]!='\0')
printf("%s", DateLine[Month][Date]);

} /* End DayTime */

main() {
} /* End Program */

MARWAY.ORG (Hosting, Domains, Shells) | Alexander Horn
10 Bruckner, Sindelfingen 71065 Germany | UNIX Hostmaster & OpenVMS Admin
Website: | Phone: +491724972944 +497031873360
eMail: | eMail:

Lesen sie die antworten

#1 Michael Welle
25/12/2008 - 21:14 | Warnen spam

Alexander Horn writes:
char Suff[2];

strcpy(Suff, "th");

suff, jupp ;). War das mit 'kultig' gemeint?


biff4emacsen - A biff-like tool for (X)Emacs
Flood - Your friendly network packet generator

Ähnliche fragen