Subject: a few minor cleanups to src/share/misc/style
To: None <tech-kern@netbsd.org, tech-userlevel@netbsd.org>
From: Chris G. Demetriou <cgd@sibyte.com>
List: tech-kern
Date: 03/21/2001 17:53:29
Here are a few minor cleanups to src/share/misc/style:

* Fix a malformed pair of block comments (lack of space between them),
  in the way that I think is appropriate: combining them into one.

* convert exit codes to use EXIT_SUCCESS and EXIT_FAILURE rather than
  0 and 1.  (following c89.)

* explicitly mention that exits from main() should be done via exit(),
  rather than return.  This was already demonstrated implicitly by the
  sample code, but probably bears explicit mention.


Any objections?


cgd
===================================================================
Index: style
===================================================================
RCS file: /cvsroot/sharesrc/share/misc/style,v
retrieving revision 1.18
diff -c -r1.18 style
*** style	2001/02/21 00:04:43	1.18
--- style	2001/03/22 01:49:54
***************
*** 10,17 ****
   * (Previously known as KNF - Kernel Normal Form).
   *
   *	from: @(#)style	1.12 (Berkeley) 3/18/94
!  */
! /*
   * An indent(1) profile approximating the style outlined in
   * this document lives in /usr/share/misc/indent.pro.  It is a
   * useful tool to assist in converting code to KNF, but indent(1)
--- 10,16 ----
   * (Previously known as KNF - Kernel Normal Form).
   *
   *	from: @(#)style	1.12 (Berkeley) 3/18/94
!  *
   * An indent(1) profile approximating the style outlined in
   * this document lives in /usr/share/misc/indent.pro.  It is a
   * useful tool to assist in converting code to KNF, but indent(1)
***************
*** 206,212 ****
  		case 'n':
  			num = strtol(optarg, &ep, 10);
  			if (num <= 0 || *ep != '\0')
! 				errx(1, "illegal number -- %s", optarg);
  			break;
  		case '?':
  		default:
--- 205,212 ----
  		case 'n':
  			num = strtol(optarg, &ep, 10);
  			if (num <= 0 || *ep != '\0')
! 				errx(EXIT_FAILURE, "illegal number -- %s",
! 				    optarg);
  			break;
  		case '?':
  		default:
***************
*** 266,272 ****
  
  	/* No spaces after function names. */
  	if ((result = function(a1, a2, a3, a4)) == NULL)
! 		exit(1);
  
  	/*
  	 * Unary operators don't require spaces, binary operators do.
--- 266,272 ----
  
  	/* No spaces after function names. */
  	if ((result = function(a1, a2, a3, a4)) == NULL)
! 		exit(EXIT_FAILURE);
  
  	/*
  	 * Unary operators don't require spaces, binary operators do.
***************
*** 278,288 ****
  	k = !(l & FLAGS);
  
  	/*
! 	 * Exits should be 0 on success, and 1 on failure.  Don't denote
! 	 * all the possible exit points, using the integers 1 through 300.
! 	 * Avoid obvious comments such as "Exit 0 on success."
  	 */
! 	exit(0);
  }
  
  /*
--- 278,292 ----
  	k = !(l & FLAGS);
  
  	/*
! 	 * Exits should be EXIT_SUCCESS on success, and EXIT_FAILURE on
! 	 * failure.  Don't denote all the possible exit points, using the
! 	 * integers 1 through 300.  Avoid obvious comments such as "Exit
! 	 * with status indicating success."
! 	 *
! 	 * Exits from main() should be done with exit(), rather than a
! 	 * return statement.
  	 */
! 	exit(EXIT_SUCCESS);
  }
  
  /*
***************
*** 327,335 ****
  	 * Use err/warn(3), don't roll your own!
  	 */
  	if ((four = malloc(sizeof(struct foo))) == NULL)
! 		err(1, NULL);
  	if ((six = (int *)overflow()) == NULL)
! 		errx(1, "Number overflowed.");
  	return (eight);
  }
  
--- 331,339 ----
  	 * Use err/warn(3), don't roll your own!
  	 */
  	if ((four = malloc(sizeof(struct foo))) == NULL)
! 		err(EXIT_FAILURE, NULL);
  	if ((six = (int *)overflow()) == NULL)
! 		errx(EXIT_FAILURE, "Number overflowed.");
  	return (eight);
  }
  
***************
*** 345,351 ****
  {	/* Insert an empty line if the function has no local variables. */
  
  	if (stat(p, sb) < 0)
! 		err(1, "Unable to stat %s", p);
  
  	/*
  	 * To printf 64 bit quantities, use %ll and cast to (long long).
--- 349,355 ----
  {	/* Insert an empty line if the function has no local variables. */
  
  	if (stat(p, sb) < 0)
! 		err(EXIT_FAILURE, "Unable to stat %s", p);
  
  	/*
  	 * To printf 64 bit quantities, use %ll and cast to (long long).
***************
*** 396,400 ****
  	 * "usage: f [-a | -b] [-c [-de] [-n number]]\n"
  	 */
  	(void)fprintf(stderr, "usage: %s [-ab]\n", getprogname());
! 	exit(1);
  }
--- 400,404 ----
  	 * "usage: f [-a | -b] [-c [-de] [-n number]]\n"
  	 */
  	(void)fprintf(stderr, "usage: %s [-ab]\n", getprogname());
! 	exit(EXIT_FAILURE);
  }