version 1.6, 1997/07/25 02:23:34 |
version 1.7, 1997/08/21 05:46:56 |
|
|
static long maxrec; /* records to display */ |
static long maxrec; /* records to display */ |
static char *file = _PATH_WTMP; /* wtmp file */ |
static char *file = _PATH_WTMP; /* wtmp file */ |
static int fulltime = 0; /* Display seconds? */ |
static int fulltime = 0; /* Display seconds? */ |
static time_t snaptime; /* if != 0, we will only |
static time_t snaptime; /* if != 0, we will only |
* report users logged in |
* report users logged in |
* at this snapshot time |
* at this snapshot time |
*/ |
*/ |
|
|
void addarg __P((int, char *)); |
void addarg __P((int, char *)); |
|
|
case '?': |
case '?': |
default: |
default: |
(void)fprintf(stderr, |
(void)fprintf(stderr, |
"usage: last [-#] [-f file] [-T] [-t tty]" |
"usage: last [-#] [-f file] [-T] [-t tty]" |
" [-h host] [-d [MMDD]hhmm[.SS]]" |
" [-h host] [-d [[yy]yy[mm[dd[hh]]]]mm[.ss]]" |
" [user ...]\n"); |
" [user ...]\n"); |
exit(1); |
exit(1); |
} |
} |
|
|
|
|
for (step = arglist; step; step = step->next) |
for (step = arglist; step; step = step->next) |
switch (step->type) { |
switch (step->type) { |
case HOST_TYPE: |
case HOST_TYPE: |
(void)fprintf(stderr, "Warning: Ignoring hostname " |
(void)fprintf(stderr, |
"flag\n"); |
"Warning: Ignoring hostname flag\n"); |
break; |
break; |
case TTY_TYPE: |
case TTY_TYPE: |
if (!ttyflag) { /* don't print this twice */ |
if (!ttyflag) { /* don't print this twice */ |
(void)fprintf(stderr, "Warning: Ignoring " |
(void)fprintf(stderr, |
"tty flag\n"); |
"Warning: Ignoring tty flag\n"); |
ttyflag = 1; |
ttyflag = 1; |
} |
} |
break; |
break; |
case USER_TYPE: |
case USER_TYPE: |
(void)fprintf(stderr, "Warning: Ignoring " |
(void)fprintf(stderr, |
"username[s]\n"); |
"Warning: Ignoring username[s]\n"); |
break; |
break; |
default: |
default: |
/* PRINT NOTHING */ |
/* PRINT NOTHING */ |
|
|
/* |
/* |
* dateconv -- |
* dateconv -- |
* Convert the snapshot time in command line given in the format |
* Convert the snapshot time in command line given in the format |
* [[CC]YY][MMDD]hhmm[.SS]] to a time_t. |
* [[yy]yy][mmdd]hhmm[.ss]] to a time_t. |
* Derived from atime_arg1() in usr.bin/touch/touch.c |
* Derived from atime_arg1() in usr.bin/touch/touch.c |
*/ |
*/ |
time_t |
time_t |
dateconv(arg) |
dateconv(arg) |
char *arg; |
char *arg; |
{ |
{ |
time_t timet; |
time_t timet; |
struct tm *t; |
struct tm *t; |
int yearset; |
int yearset; |
char *p; |
char *p; |
|
|
/* Start with the current time. */ |
/* Start with the current time. */ |
if (time(&timet) < 0) |
if (time(&timet) < 0) |
err(1, "time"); |
err(1, "time"); |
if ((t = localtime(&timet)) == NULL) |
if ((t = localtime(&timet)) == NULL) |
err(1, "localtime"); |
err(1, "localtime"); |
|
|
/* [[CC]YY][MMDD]hhmm[.SS] */ |
/* [[yy]yy][mmdd]hhmm[.ss] */ |
if ((p = strchr(arg, '.')) == NULL) |
if ((p = strchr(arg, '.')) == NULL) |
t->tm_sec = 0; /* Seconds defaults to 0. */ |
t->tm_sec = 0; /* Seconds defaults to 0. */ |
else { |
else { |
if (strlen(p + 1) != 2) |
if (strlen(p + 1) != 2) |
goto terr; |
goto terr; |
*p++ = '\0'; |
*p++ = '\0'; |
t->tm_sec = ATOI2(p); |
t->tm_sec = ATOI2(p); |
} |
} |
|
|
yearset = 0; |
yearset = 0; |
switch (strlen(arg)) { |
switch (strlen(arg)) { |
case 12: /* CCYYMMDDhhmm */ |
case 12: /* ccyymmddhhmm */ |
t->tm_year = ATOI2(arg); |
t->tm_year = ATOI2(arg); |
t->tm_year *= 100; |
t->tm_year *= 100; |
yearset = 1; |
yearset = 1; |
/* FALLTHOUGH */ |
/* FALLTHOUGH */ |
case 10: /* YYMMDDhhmm */ |
case 10: /* yymmddhhmm */ |
if (yearset) { |
if (yearset) { |
yearset = ATOI2(arg); |
yearset = ATOI2(arg); |
t->tm_year += yearset; |
t->tm_year += yearset; |
} else { |
} else { |
yearset = ATOI2(arg); |
yearset = ATOI2(arg); |
if (yearset < 69) |
if (yearset < 69) |
t->tm_year = yearset + 2000; |
t->tm_year = yearset + 2000; |
else |
else |
t->tm_year = yearset + 1900; |
t->tm_year = yearset + 1900; |
} |
} |
t->tm_year -= 1900; /* Convert to UNIX time. */ |
t->tm_year -= 1900; /* Convert to UNIX time. */ |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case 8: /* MMDDhhmm */ |
case 8: /* MMDDhhmm */ |
t->tm_mon = ATOI2(arg); |
t->tm_mon = ATOI2(arg); |
--t->tm_mon; /* Convert from 01-12 to 00-11 */ |
--t->tm_mon; /* Convert from 01-12 to 00-11 */ |
t->tm_mday = ATOI2(arg); |
t->tm_mday = ATOI2(arg); |
t->tm_hour = ATOI2(arg); |
t->tm_hour = ATOI2(arg); |
t->tm_min = ATOI2(arg); |
t->tm_min = ATOI2(arg); |
break; |
break; |
case 4: /* hhmm */ |
case 4: /* hhmm */ |
t->tm_hour = ATOI2(arg); |
t->tm_hour = ATOI2(arg); |
t->tm_min = ATOI2(arg); |
t->tm_min = ATOI2(arg); |
break; |
break; |
default: |
default: |
goto terr; |
goto terr; |
} |
} |
t->tm_isdst = -1; /* Figure out DST. */ |
t->tm_isdst = -1; /* Figure out DST. */ |
timet = mktime(t); |
timet = mktime(t); |
if (timet == -1) |
if (timet == -1) |
terr: errx(1, |
terr: errx(1, |
"out of range or illegal time specification: [[CC]YY][MMDD]hhmm[.SS]"); |
"out of range or illegal time specification: [[yy]yy][mmdd]hhmm[.ss]"); |
return timet; |
return timet; |
} |
} |
|
|
|
|