2001-05-25 Joel Sherrill <joel@OARcorp.com>

* shell/cmds.c: Removed code from inappropriate source.
This commit is contained in:
Joel Sherrill
2001-05-25 17:52:03 +00:00
parent 88249fa074
commit 5fef5234a4
4 changed files with 36 additions and 94 deletions

View File

@@ -1,3 +1,7 @@
2001-05-25 Joel Sherrill <joel@OARcorp.com>
* shell/cmds.c: Removed code from inappropriate source.
2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es> 2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
* monitor/mon-prmisc.c: Correct print line. * monitor/mon-prmisc.c: Correct print line.

View File

@@ -10,8 +10,6 @@
* A 'monitor' command is added to adapt the call rtems monitor commands * A 'monitor' command is added to adapt the call rtems monitor commands
* at my call procedure * at my call procedure
* *
* MINIX date.c is adapted to run here. Like a exercise only....
*
* TODO: A lot of improvements of course. * TODO: A lot of improvements of course.
* cp, mv, ... * cp, mv, ...
* hexdump, * hexdump,
@@ -385,56 +383,24 @@ int main_rm (int argc, char *argv[])
return 0; return 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* date - print or set time and date Author: Jan Looyen */ /* date - print or set time and date */
/* MINIX 1.5 GPL'ed */
#define MIN 60L /* # seconds in a minute */
#define HOUR (60 * MIN) /* # seconds in an hour */
#define DAY (24 * HOUR) /* # seconds in a day */
#define YEAR (365 * DAY) /* # seconds in a year */
static int conv(unsigned32 *value,char **ptr,unsigned32 max)
{
int buf;
*ptr -= 2;
buf = atoi(*ptr);
**ptr = 0;
if (buf < 0 || buf > max) {
fprintf(stderr, "Date: bad conversion\n");
return 0;
};
*value=buf;
return 1;
}
static int set_time(char *t) static int set_time(char *t)
{ {
rtems_time_of_day tod; rtems_time_of_day tod;
FILE * rtc; FILE * rtc;
char *tp;
int len; int len;
if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL ) if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL )
memset( &tod, 0, sizeof(tod) ); memset( &tod, 0, sizeof(tod) );
len = strlen(t);
if (len != 12 && len != 10 && len != 6 && len != 4) return 0; /* JRS
tp = t; *
while (*tp) * This code that was used to parse the command line was taken
if (!isdigit(*tp++)) { * from an inappropriate source. It has been removed and needs
fprintf(stderr, "date: bad conversion\n"); * to be replaced.
return 0; */
};
if (len == 6 || len == 12)
if (!conv(&tod.second,&tp, 59)) return 0;
if (!conv(&tod.minute,&tp, 59)) return 0;
if (!conv(&tod.hour,&tp, 23)) return 0;
if (len == 12 || len == 10) {
if (!conv(&tod.year,&tp, 99)) return 0;
tod.year+=1900;
if (tod.year<TOD_BASE_YEAR) tod.year+=100;
if (!conv(&tod.day ,&tp, 31)) return 0;
if (!conv(&tod.month ,&tp, 12)) return 0;
}
if (!_TOD_Validate(&tod)) { if (!_TOD_Validate(&tod)) {
fprintf(stderr, "Invalid date value\n"); fprintf(stderr, "Invalid date value\n");
} else { } else {
@@ -452,7 +418,8 @@ static int set_time(char *t)
int main_date(int argc,char *argv[]) int main_date(int argc,char *argv[])
{ {
time_t t; time_t t;
if (argc == 2) set_time(argv[1]); if (argc == 2)
set_time(argv[1]);
time(&t); time(&t);
printf("%s", ctime(&t)); printf("%s", ctime(&t));
return 0; return 0;

View File

@@ -1,3 +1,7 @@
2001-05-25 Joel Sherrill <joel@OARcorp.com>
* shell/cmds.c: Removed code from inappropriate source.
2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es> 2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
* monitor/mon-prmisc.c: Correct print line. * monitor/mon-prmisc.c: Correct print line.

View File

@@ -10,8 +10,6 @@
* A 'monitor' command is added to adapt the call rtems monitor commands * A 'monitor' command is added to adapt the call rtems monitor commands
* at my call procedure * at my call procedure
* *
* MINIX date.c is adapted to run here. Like a exercise only....
*
* TODO: A lot of improvements of course. * TODO: A lot of improvements of course.
* cp, mv, ... * cp, mv, ...
* hexdump, * hexdump,
@@ -385,56 +383,24 @@ int main_rm (int argc, char *argv[])
return 0; return 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* date - print or set time and date Author: Jan Looyen */ /* date - print or set time and date */
/* MINIX 1.5 GPL'ed */
#define MIN 60L /* # seconds in a minute */
#define HOUR (60 * MIN) /* # seconds in an hour */
#define DAY (24 * HOUR) /* # seconds in a day */
#define YEAR (365 * DAY) /* # seconds in a year */
static int conv(unsigned32 *value,char **ptr,unsigned32 max)
{
int buf;
*ptr -= 2;
buf = atoi(*ptr);
**ptr = 0;
if (buf < 0 || buf > max) {
fprintf(stderr, "Date: bad conversion\n");
return 0;
};
*value=buf;
return 1;
}
static int set_time(char *t) static int set_time(char *t)
{ {
rtems_time_of_day tod; rtems_time_of_day tod;
FILE * rtc; FILE * rtc;
char *tp;
int len; int len;
if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL ) if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL )
memset( &tod, 0, sizeof(tod) ); memset( &tod, 0, sizeof(tod) );
len = strlen(t);
if (len != 12 && len != 10 && len != 6 && len != 4) return 0; /* JRS
tp = t; *
while (*tp) * This code that was used to parse the command line was taken
if (!isdigit(*tp++)) { * from an inappropriate source. It has been removed and needs
fprintf(stderr, "date: bad conversion\n"); * to be replaced.
return 0; */
};
if (len == 6 || len == 12)
if (!conv(&tod.second,&tp, 59)) return 0;
if (!conv(&tod.minute,&tp, 59)) return 0;
if (!conv(&tod.hour,&tp, 23)) return 0;
if (len == 12 || len == 10) {
if (!conv(&tod.year,&tp, 99)) return 0;
tod.year+=1900;
if (tod.year<TOD_BASE_YEAR) tod.year+=100;
if (!conv(&tod.day ,&tp, 31)) return 0;
if (!conv(&tod.month ,&tp, 12)) return 0;
}
if (!_TOD_Validate(&tod)) { if (!_TOD_Validate(&tod)) {
fprintf(stderr, "Invalid date value\n"); fprintf(stderr, "Invalid date value\n");
} else { } else {
@@ -452,7 +418,8 @@ static int set_time(char *t)
int main_date(int argc,char *argv[]) int main_date(int argc,char *argv[])
{ {
time_t t; time_t t;
if (argc == 2) set_time(argv[1]); if (argc == 2)
set_time(argv[1]);
time(&t); time(&t);
printf("%s", ctime(&t)); printf("%s", ctime(&t));
return 0; return 0;