From nobody@FreeBSD.org  Thu Nov 22 16:37:58 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id DDA4A37B405
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 22 Nov 2001 16:37:57 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id fAN0bv704598;
	Thu, 22 Nov 2001 16:37:57 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200111230037.fAN0bv704598@freefall.freebsd.org>
Date: Thu, 22 Nov 2001 16:37:57 -0800 (PST)
From: mikem <mike_makonnen@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] Remove code redundancy in usr.sbin/lpr/common_source/printcap.c
X-Send-Pr-Version: www-1.0

>Number:         32204
>Category:       bin
>Synopsis:       [PATCH] Remove code redundancy in usr.sbin/lpr/common_source/printcap.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gad
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 22 16:40:04 PST 2001
>Closed-Date:    Tue Dec 11 13:16:59 PST 2001
>Last-Modified:  Tue Dec 11 13:18:31 PST 2001
>Originator:     mikem
>Release:        4-stable
>Organization:
>Environment:
FreeBSD blackbox.pacbell.net 4.4-STABLE FreeBSD 4.4-STABLE #3: Fri Nov 16 01:35:39 PST 2001     mikem@blackbox.pacbell.net:/usr/obj/src/stable/src/sys/BLACKBOX  i386

>Description:
The functions firstprinter and nextprinter are nearly identical. It would be simpler to have firstprinter initialize the printer structure and then call nextprinter.
>How-To-Repeat:

>Fix:
--- printcap.c.original Thu Nov 22 01:30:54 2001
+++ printcap.c  Thu Nov 22 01:31:53 2001
@@ -141,28 +141,13 @@
 
 /*
  * Scan through the database of printers using cgetfirst/cgetnext.
- * Return false of error or end-of-database; else true.
+ * Return false if error or end-of-database; else true.
  */
 int
 firstprinter(struct printer *pp, int *error)
 {
-       int status;
-       char *bp;
-
        init_printer(pp);
-       status = cgetfirst(&bp, printcapdb);
-       if (firstnextmap(&status) == 0) {
-               if (error)
-                       *error = status;
-               return 0;
-       }
-       if (error)
-               *error = status;
-       status = getprintcap_int(bp, pp);
-       free(bp);
-       if (error && status)
-               *error = status;
-       return 1;
+       return ( nextprinter(pp, error) );
 }
 
 int

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->gad 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Fri Nov 23 02:30:33 PST 2001 
Responsible-Changed-Why:  
Garance. 


http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32204 
State-Changed-From-To: open->feedback 
State-Changed-By: gad 
State-Changed-When: Tue Nov 27 20:43:56 PST 2001 
State-Changed-Why:  

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32204 

From: Garance A Drosehn <gad@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/32204: [PATCH] Remove code redundancy in
 usr.sbin/lpr/common_source/printcap.c
Date: Thu, 29 Nov 2001 13:48:11 -0500

 At 8:48 PM -0800 11/27/01, <gad@FreeBSD.org> wrote:
 >    State-Changed-From-To: open->feedback
 >    State-Changed-By: gad
 >    State-Changed-When: Tue Nov 27 20:43:56 PST 2001
 
 Arg.  I started to write something for this PR, went to check something,
 and somehow managed to change the status without including any reason.
 
 So, here's the reason.  This patch would change firstprinter so it
 calls cgetnext without calling cgetfirst.  I understand that cgetnext
 will act like cgetfirst the *first* time it is called, but I do not
 believe that all callers of 'firstprinter' can safely assume that the
 call to cgetfirst is not necessary.  This is particularly likely in the
 calls from 'lpc', where we may loop thru all printers (or even "several
 printers") many times in a single lpc process.
 
 I might try this and see if I can come up with an explicit example
 where skipping the 'cgetfirst' does cause a problem.
 
 -- 
 Garance Alistair Drosehn            =   gad@eclipse.acs.rpi.edu
 Senior Systems Programmer                   or  gad@freebsd.org
 Rensselaer Polytechnic Institute            or  drosehn@rpi.edu
State-Changed-From-To: feedback->closed 
State-Changed-By: gad 
State-Changed-When: Tue Dec 11 13:16:59 PST 2001 
State-Changed-Why:  
While we may do something about this in the future, this specific patch is 
probably not a good idea.  What is there does work OK, so improving it is 
a lower priority than some other things. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32204 
>Unformatted:
