home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zodiac Super OZ
/
MEDIADEPOT.ISO
/
FILES
/
16
/
FREEDOS.ZIP
/
FD_A4PRE.ZIP
/
SOURCE
/
MICROC.ZIP
/
TIME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-26
|
4KB
|
153 lines
/*
TIME.C - Program to change system time
Original code by: James Hall
Ported to MICRO-C by: M. "Hannibal" Toal
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Changes:
JH Jan 95 Original Program in MS-C
MT Apr 95 Ported to MICRO-C
*/
#include <stdio.h>
#include "freedos.h"
#include "getopt.c"
#include "country.c"
char *Months[] =
{"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"};
char *Weekdays[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"};
void usage (void);
void F_puttime (struct country Cinfo);
void F_settime (char *Buf);
main (int argc, char **argv)
{
int i;
char Buf[MAX_STR];
struct country Cinfo;
get_country (Cinfo);
/* Scan the command line */
while ((i = getopt (argc, argv, "D?", "")) != EOF)
{
switch (i)
{
case 'D':
F_puttime (Cinfo);
exit (0);
default:
usage ();
break;
}
}
/* Set time if specified on command line */
if ((argc - optind) != 0)
{
strcpy (Buf, "");
for (i = optind; i < argc; i++)
{
strcat (Buf, argv[i]); /* Get all args on command line */
strcat (Buf, " "); /* We have to keep args separated */
}
F_settime (Buf);
F_puttime (Cinfo);
}
/* Input a string for time and process that, then */
else
{
F_puttime (Cinfo); /* Get the current date */
/* Get the new date, make prompt comform to country style*/
printf ("New time (HH%sMM%sSS): ",
Cinfo.co_tmsep, Cinfo.co_tmsep);
if (strlen(gets (Buf)))
{
F_settime (Buf);
F_puttime (Cinfo);
}
}
exit (0);
}
void F_puttime (struct country Cinfo)
{
int Year, Month, Day, Hour, Min, Sec, Dayofweek;
Dayofweek = Weekdays[get_date (&Day, &Month, &Year)];
get_time (&Hour, &Min, &Sec);
printf ("%s %02d %s %04d %02d%s%02d%s%02d\n",
Dayofweek, Day, Months[Month-1], Year,
Hour, Cinfo.co_tmsep, Min, Cinfo.co_tmsep, Sec);
}
void F_settime (char *Buf)
{
int Hrs, Min, Sec, PM;
PM = FALSE;
/* Determine if time is AM or PM */
if (strchr (Buf, 'P') || strchr (Buf, 'p'))
PM = TRUE;
/* Peel off each argument from the string */
Hrs = atoi(strtok(Buf, " .,-:/\\\t"));
Min = atoi(strtok(NULL, " .,-:/\\\tAPMapm"));
Sec = atoi(strtok(NULL, " .,-:/\\\tAPMapm"));
/* if we have a PM time, convert it to 24 hour format */
if (PM)
{
if (Hrs < 12) Hrs = Hrs + 12;
if (Hrs == 12) Hrs = 0;
}
/* Set the date */
if ((set_time (Hrs, Min, Sec)) == -1)
{
printf ("Invalid Time: %s\n", Buf);
abort (1);
}
return TRUE;
}
void usage (void)
{
printp ("TIME", "Display and change system date");
printc ("1995", "James Hall and M. \"Hannibal\" Toal");
printu ("TIME", "[/D] [mm/dd/yy]");
printo ("D", "Display time only, do not change");
exit (1);
}