home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zodiac Super OZ
/
MEDIADEPOT.ISO
/
FILES
/
16
/
FREEDOS.ZIP
/
FD_A4PRE.ZIP
/
SOURCE
/
MICROC.ZIP
/
DATE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-25
|
4KB
|
160 lines
/*
DATE.C - Program to change system date
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
Added support for international date formats
*/
#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"};
char *Datestyle[] = {"mm%syy%sdd", "dd%smm%syy", "yy%smm%sdd"};
void usage (void);
void F_putdate (struct country Cinfo);
void F_setdate (struct country Cinfo, 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_putdate (Cinfo);
exit (0);
default:
usage ();
break;
}
}
/* Check if there are enough args left */
if ((argc - optind) != 0)
{
strcpy (Buf, "");
for (i = optind; i < argc; i++)
{
strcat (Buf, argv[i]);
strcat (Buf, " ");
}
F_setdate (Cinfo, Buf);
F_putdate (Cinfo);
}
else
{
/* Get the current date */
F_putdate (Cinfo);
sprintf (Buf, Datestyle[Cinfo.co_datefmt],
Cinfo.co_dtsep, Cinfo.co_dtsep);
/* Get the new date */
printf ("New date (%s): ", Buf);
if (strlen(gets (Buf)))
{
F_setdate (Cinfo, Buf);
F_putdate (Cinfo);
}
}
exit (0);
}
void F_setdate (struct country Cinfo, char *Buf)
{
int n1, n2, n3, Month, Day, Year;
n1 = atoi(strtok(Buf, " .,-/\\\t"));
n2 = atoi(strtok(NULL, " .,-/\\\t"));
n3 = atoi(strtok(NULL, " .,-/\\\t"));
switch (Cinfo.co_datefmt)
{
case 1:
Day = n1; Month = n2; Year = n3; break;
case 2:
Year = n1; Month = n2; Day = n3; break;
default:
Month = n1; Day = n2; Year = n3; break;
}
/* Is it a 2 digit date? */
if (Year <= 79) Year += 2000;
else if (Year <= 99) Year += 1900;
/* Set the date */
if ((set_date (Day, Month, Year)) == -1)
{
printf ("Invalid Date: %s\n", Buf);
abort (1);
}
return TRUE;
}
void F_putdate (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 usage (void)
{
printp ("DATE", "Display and change system date");
printc ("1995", "James Hall and M. \"Hannibal\" Toal");
printu ("DATE", "[/D] [mm/dd/yy]");
printo ("D", "Display date only, do not change");
exit (1);
}