home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / jh_utils / date.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-07  |  2.6 KB  |  119 lines

  1. /*
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.  
  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.
  11.  
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program; if not, write to the Free Software
  14.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.    */
  16.  
  17. /***********************************************************************
  18.  * This function displays the date and allows the user to change it.
  19.  *
  20.  * Author: James Hall
  21.  */
  22.  
  23. #include <dos.h>
  24. #include <stdio.h>
  25. #include <conio.h>
  26. #include <string.h>
  27. #include "getopt.h"
  28. #include "freedos.h"
  29.  
  30.  
  31. /* Structure from Quick-C that sets the DOS date */
  32.  
  33. struct dosdate_t ddate;
  34.  
  35.  
  36. void usage (void);
  37.  
  38.  
  39. main (int argc, char **argv)
  40. {
  41.   int i;
  42.   unsigned uDay, uMonth, uYear;
  43.   char *prgszDays[] =
  44.   {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  45.   char szBuf[20];
  46.  
  47.   /* Scan the command line */
  48.  
  49.   while ((i = getopt (argc, argv, "?")) != EOF)
  50.     {
  51.       switch (i)
  52.     {
  53.     default:
  54.       usage ();
  55.       break;
  56.     }
  57.     }
  58.  
  59.   /* Check if there are enough args left */
  60.  
  61.   if ((argc - optind) != 0)
  62.     strcpy (szBuf, argv[1]);
  63.  
  64.   else
  65.     {
  66.       /* Get the current date */
  67.       /* _dos_getdate() from Quick-C returns the date as a struct */
  68.  
  69.       _dos_getdate (&ddate);
  70.  
  71.       printf ("Current date is: %u/%02u/%02u %s\n",
  72.           ddate.month, ddate.day, ddate.year - 1900,
  73.           prgszDays[ddate.dayofweek]);
  74.  
  75.       /* Get the new date */
  76.  
  77.       printf ("Enter new date: ");
  78.       gets (szBuf);
  79.     }
  80.  
  81.   if (strlen (szBuf))
  82.     {
  83.       sscanf (szBuf, "%u/%u/%u", &uMonth, &uDay, &uYear);
  84.  
  85.       /* Parse the new date */
  86.  
  87.       if ((uYear - 80) <= 20)
  88.     ddate.year = uYear + 1900;
  89.  
  90.       else if ((uYear >= 1980) && (uYear <= 2099))
  91.     ddate.year = uYear;
  92.  
  93.       if ((uMonth + 1) <= 13)
  94.     ddate.month = (unsigned char) uMonth;
  95.  
  96.       if ((uDay + 1) <= 32)
  97.     ddate.day = (unsigned char) uDay;
  98.  
  99.       /* Set the date */
  100.       /* _dos_setdate() from Quick-C sets the date */
  101.  
  102.       _dos_setdate (&ddate);
  103.       _dos_getdate (&ddate);
  104.  
  105.       printf ("New date: %u/%02u/%02u %s\n",
  106.           ddate.month, ddate.day, ddate.year - 1900,
  107.           prgszDays[ddate.dayofweek]);
  108.     }
  109.   exit (0);
  110. }
  111.  
  112. void 
  113. usage (void)
  114. {
  115.   printp ("DATE", "Displays the date and allows you to change it");
  116.   printu ("DATE", "[mm/dd/yy]");
  117.   exit (1);
  118. }
  119.