From d504a441ec53b5a5de54f347795e7b32658e47a6 Mon Sep 17 00:00:00 2001 From: wollman Date: Wed, 3 May 2000 14:56:20 +0000 Subject: Print files submitted at the same instant in deterministic order. PR: 18361 Submitted by: Garance A Drosehn --- usr.sbin/lpr/common_source/common.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index ebc7bfd..9a70f80 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -175,11 +175,26 @@ static int compar(p1, p2) const void *p1, *p2; { - if ((*(struct queue **)p1)->q_time < (*(struct queue **)p2)->q_time) - return(-1); - if ((*(struct queue **)p1)->q_time > (*(struct queue **)p2)->q_time) - return(1); - return(0); + const struct queue *qe1, *qe2; + qe1 = *(const struct queue **)p1; + qe2 = *(const struct queue **)p2; + + if (qe1->q_time < qe2->q_time) + return (-1); + if (qe1->q_time > qe2->q_time) + return (1); + /* + * At this point, the two files have the same last-modification time. + * return a result based on filenames, so that 'cfA001some.host' will + * come before 'cfA002some.host'. Since the jobid ('001') will wrap + * around when it gets to '999', we also assume that '9xx' jobs are + * older than '0xx' jobs. + */ + if ((qe1->q_name[3] == '9') && (qe2->q_name[3] == '0')) + return (-1); + if ((qe1->q_name[3] == '0') && (qe2->q_name[3] == '9')) + return (1); + return (strcmp(qe1->q_name,qe2->q_name)); } /* sleep n milliseconds */ -- cgit v1.1