Print this page
2849 uptime should use locale settings for current time
*** 77,87 ****
#define NMAX (sizeof (dummy.ut_user))
#define LMAX (sizeof (dummy.ut_line))
/* Print minimum field widths. */
#define LOGIN_WIDTH 8
! #define LINE_WIDTH 12
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
#ifdef ERR
#undef ERR
--- 77,87 ----
#define NMAX (sizeof (dummy.ut_user))
#define LMAX (sizeof (dummy.ut_line))
/* Print minimum field widths. */
#define LOGIN_WIDTH 8
! #define LINE_WIDTH 8
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
#ifdef ERR
#undef ERR
*** 125,137 ****
static struct uproc *findhash(pid_t);
static time_t findidle(char *);
static void clnarglist(char *);
static void showtotals(struct uproc *);
static void calctotals(struct uproc *);
! static void prttime(time_t, char *);
static void prtat(time_t *time);
- static void checkampm(char *str);
static char *prog; /* pointer to invocation name */
static int header = 1; /* true if -h flag: don't print heading */
static int lflag = 1; /* set if -l flag; 0 for -s flag: short form */
static char *sel_user; /* login of particular user selected */
--- 125,136 ----
static struct uproc *findhash(pid_t);
static time_t findidle(char *);
static void clnarglist(char *);
static void showtotals(struct uproc *);
static void calctotals(struct uproc *);
! static void prttime(time_t, int);
static void prtat(time_t *time);
static char *prog; /* pointer to invocation name */
static int header = 1; /* true if -h flag: don't print heading */
static int lflag = 1; /* set if -l flag; 0 for -s flag: short form */
static char *sel_user; /* login of particular user selected */
*** 274,284 ****
uptime %= (60*60*24);
hrs = uptime / (60*60);
uptime %= (60*60);
mins = uptime / 60;
! PRINTF((gettext(" up")));
if (days > 0)
PRINTF((gettext(
" %d day(s),"), days));
if (hrs > 0 && mins > 0) {
PRINTF((" %2d:%02d,", hrs, mins));
--- 273,283 ----
uptime %= (60*60*24);
hrs = uptime / (60*60);
uptime %= (60*60);
mins = uptime / 60;
! PRINTF((gettext("up")));
if (days > 0)
PRINTF((gettext(
" %d day(s),"), days));
if (hrs > 0 && mins > 0) {
PRINTF((" %2d:%02d,", hrs, mins));
*** 307,320 ****
if (firstchar == 'u') /* uptime command */
exit(0);
if (lflag) {
PRINTF((dcgettext(NULL, "User tty "
! "login@ idle JCPU PCPU what\n", LC_TIME)));
} else {
PRINTF((dcgettext(NULL,
! "User tty idle what\n", LC_TIME)));
}
if (fflush(stdout) == EOF) {
perror((gettext("%s: fflush failed\n"), prog));
exit(1);
--- 306,321 ----
if (firstchar == 'u') /* uptime command */
exit(0);
if (lflag) {
PRINTF((dcgettext(NULL, "User tty "
! "login@ idle JCPU PCPU what\n",
! LC_TIME)));
} else {
PRINTF((dcgettext(NULL,
! "User tty idle what\n",
! LC_TIME)));
}
if (fflush(stdout) == EOF) {
perror((gettext("%s: fflush failed\n"), prog));
exit(1);
*** 483,499 ****
/* print login name of the user */
PRINTF(("%-*.*s ", LOGIN_WIDTH, NMAX, ut->ut_name));
/* print tty user is on */
if (lflag) {
! PRINTF(("%-*.*s", LINE_WIDTH, LMAX, ut->ut_line));
} else {
if (ut->ut_line[0] == 'p' && ut->ut_line[1] == 't' &&
ut->ut_line[2] == 's' && ut->ut_line[3] == '/') {
! PRINTF(("%-*.3s", LMAX, &ut->ut_line[4]));
} else {
! PRINTF(("%-*.*s", LINE_WIDTH, LMAX,
ut->ut_line));
}
}
/* print when the user logged in */
--- 484,501 ----
/* print login name of the user */
PRINTF(("%-*.*s ", LOGIN_WIDTH, NMAX, ut->ut_name));
/* print tty user is on */
if (lflag) {
! PRINTF(("%-*.*s ", LINE_WIDTH, LMAX, ut->ut_line));
} else {
if (ut->ut_line[0] == 'p' && ut->ut_line[1] == 't' &&
ut->ut_line[2] == 's' && ut->ut_line[3] == '/') {
! PRINTF(("%-*.*s ", LINE_WIDTH, LMAX,
! &ut->ut_line[4]));
} else {
! PRINTF(("%-*.*s ", LINE_WIDTH, LMAX,
ut->ut_line));
}
}
/* print when the user logged in */
*** 502,516 ****
prtat(&tim);
}
/* print idle time */
idle = findidle(ut->ut_line);
! if (idle >= 36 * 60) {
! PRINTF((dcgettext(NULL, "%2ddays ", LC_TIME),
! (idle + 12 * 60) / (24 * 60)));
! } else
! prttime(idle, " ");
showtotals(findhash(ut->ut_pid));
}
if (fclose(stdout) == EOF) {
perror((gettext("%s: fclose failed"), prog));
exit(1);
--- 504,514 ----
prtat(&tim);
}
/* print idle time */
idle = findidle(ut->ut_line);
! prttime(idle, 8);
showtotals(findhash(ut->ut_pid));
}
if (fclose(stdout) == EOF) {
perror((gettext("%s: fclose failed"), prog));
exit(1);
*** 535,552 ****
calctotals(up);
if (lflag) {
/* print CPU time for all processes & children */
/* and need to convert clock ticks to seconds first */
! prttime((time_t)jobtime, " ");
/* print cpu time for interesting process */
/* and need to convert clock ticks to seconds first */
! prttime((time_t)proctime, " ");
}
/* what user is doing, current process */
! PRINTF((" %-.32s\n", doing));
}
/*
* This recursive routine descends the process
* tree starting from the given process pointer(up).
--- 533,550 ----
calctotals(up);
if (lflag) {
/* print CPU time for all processes & children */
/* and need to convert clock ticks to seconds first */
! prttime((time_t)jobtime, 8);
/* print cpu time for interesting process */
/* and need to convert clock ticks to seconds first */
! prttime((time_t)proctime, 8);
}
/* what user is doing, current process */
! PRINTF(("%-.32s\n", doing));
}
/*
* This recursive routine descends the process
* tree starting from the given process pointer(up).
*** 644,699 ****
#define HR (60 * 60)
#define DAY (24 * HR)
#define MON (30 * DAY)
/*
! * prttime prints a time in hours and minutes or minutes and seconds.
! * The character string tail is printed at the end, obvious
! * strings to pass are "", " ", or "am".
*/
static void
! prttime(time_t tim, char *tail)
{
! if (tim >= 60) {
! PRINTF((dcgettext(NULL, "%3d:%02d", LC_TIME),
! (int)tim/60, (int)tim%60));
} else if (tim > 0) {
! PRINTF((dcgettext(NULL, " %2d", LC_TIME), (int)tim));
} else {
! PRINTF((" "));
}
! PRINTF(("%s", tail));
}
/*
! * prints a 12 hour time given a pointer to a time of day
*/
static void
prtat(time_t *time)
{
struct tm *p;
p = localtime(time);
if (now - *time <= 18 * HR) {
char timestr[50];
(void) strftime(timestr, sizeof (timestr),
! dcgettext(NULL, "%l:%M""%p", LC_TIME), p);
! checkampm(timestr);
! PRINTF((" %s", timestr));
} else if (now - *time <= 7 * DAY) {
char weekdaytime[20];
(void) strftime(weekdaytime, sizeof (weekdaytime),
! dcgettext(NULL, "%a%l%p", LC_TIME), p);
! checkampm(weekdaytime);
! PRINTF((" %s", weekdaytime));
} else {
char monthtime[20];
(void) strftime(monthtime, sizeof (monthtime),
! dcgettext(NULL, "%e%b%y", LC_TIME), p);
! PRINTF((" %s", monthtime));
}
}
/*
* find & return number of minutes current tty has been idle
--- 642,705 ----
#define HR (60 * 60)
#define DAY (24 * HR)
#define MON (30 * DAY)
/*
! * Prttime prints an elapsed time in hours, minutes, or seconds,
! * right-justified with the rightmost column always blank.
! * The second argument is the minimum field width.
*/
static void
! prttime(time_t tim, int width)
{
! char value[36];
!
! if (tim >= 36 * 60) {
! (void) snprintf(value, sizeof (value), "%d:%02d:%02d",
! (int)tim / HR, (int)(tim % HR) / 60, (int)tim % 60);
! } else if (tim >= 60) {
! (void) snprintf(value, sizeof (value), "%d:%02d",
! (int)tim / 60, (int)tim % 60);
} else if (tim > 0) {
! (void) snprintf(value, sizeof (value), "%d", (int)tim);
} else {
! (void) strcpy(value, "0");
}
! width = (width > 2) ? width - 1 : 1;
! PRINTF(("%*s ", width, value));
}
/*
! * Prints the ISO date or time given a pointer to a time of day,
! * left-justfied in a 12-character expanding field with the
! * rightmost column always blank.
! * Includes a dcgettext() override in case a message catalog is needed.
*/
static void
prtat(time_t *time)
{
struct tm *p;
p = localtime(time);
if (now - *time <= 18 * HR) {
char timestr[50];
+
(void) strftime(timestr, sizeof (timestr),
! dcgettext(NULL, "%T", LC_TIME), p);
! PRINTF(("%-11s ", timestr));
} else if (now - *time <= 7 * DAY) {
char weekdaytime[20];
(void) strftime(weekdaytime, sizeof (weekdaytime),
! dcgettext(NULL, "%a %H:%M", LC_TIME), p);
! PRINTF(("%-11s ", weekdaytime));
} else {
char monthtime[20];
(void) strftime(monthtime, sizeof (monthtime),
! dcgettext(NULL, "%F", LC_TIME), p);
! PRINTF(("%-11s ", monthtime));
}
}
/*
* find & return number of minutes current tty has been idle
*** 736,752 ****
}
*c = '?';
}
}
}
-
- /* replaces all occurences of AM/PM with am/pm */
- static void
- checkampm(char *str)
- {
- char *ampm;
- while ((ampm = strstr(str, "AM")) != NULL ||
- (ampm = strstr(str, "PM")) != NULL) {
- *ampm = tolower(*ampm);
- *(ampm+1) = tolower(*(ampm+1));
- }
- }
--- 742,746 ----