From owner-p4-projects@FreeBSD.ORG Fri Aug 15 16:44:59 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3F540106566C; Fri, 15 Aug 2008 16:44:59 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 03161106564A for ; Fri, 15 Aug 2008 16:44:59 +0000 (UTC) (envelope-from konrad@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id D713E8FC20 for ; Fri, 15 Aug 2008 16:44:58 +0000 (UTC) (envelope-from konrad@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7FGiwoW012304 for ; Fri, 15 Aug 2008 16:44:58 GMT (envelope-from konrad@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7FGiwFN012302 for perforce@freebsd.org; Fri, 15 Aug 2008 16:44:58 GMT (envelope-from konrad@FreeBSD.org) Date: Fri, 15 Aug 2008 16:44:58 GMT Message-Id: <200808151644.m7FGiwFN012302@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to konrad@FreeBSD.org using -f From: Konrad Jankowski To: Perforce Change Reviews Cc: Subject: PERFORCE change 147472 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2008 16:44:59 -0000 http://perforce.freebsd.org/chv.cgi?CH=147472 Change 147472 by konrad@vspredator on 2008/08/15 16:44:48 Get rid of the global variables. Affected files ... .. //depot/projects/soc2008/konrad_collation/test/sort/sort.c#3 edit Differences ... ==== //depot/projects/soc2008/konrad_collation/test/sort/sort.c#3 (text+ko) ==== @@ -13,9 +13,7 @@ char *trans; } *lines[MAXSIZE]; -static int max_lines; /* Numer of lines read from input. */ - -static void +static int read_input(void) { char buf[1000]; @@ -35,7 +33,7 @@ lines[i] = line; i++; } - max_lines = i; + return i; } static int @@ -56,11 +54,11 @@ } static void -write_output(void) +write_output(int num_lines) { int i; - for (i = 0; i < max_lines; i++) { + for (i = 0; i < num_lines; i++) { printf("%s\n", lines[i]->sline); } } @@ -70,19 +68,22 @@ { char *p; int ch; + int num_lines; /* Number of lines read from input. */ int xfrm; /* Do we use strxfrm? */ - while ((ch = getopt(argc, argv, "x")) != -1) { + while ((ch = getopt(argc, argv, "xh")) != -1) { switch (ch) { case 'x': xfrm = 1; break; case '?': default: printf( "usage: " - "%s [-x]\n" - "\tsort lines in standard input according to the " - "current collation\n" - "\t-x use strxfrm and strcmp instead of strcoll\n" + "%s [-h] [-x]\n" + "\tsort lines in standard input according " + "to the current collation\n" + "\t-h this help message\n" + "\t-x use strxfrm and strcmp instead of " + "strcoll\n" , argv[0]); return EX_USAGE; break; @@ -90,13 +91,13 @@ } if ((p = setlocale(LC_ALL, "")) == NULL) errx(1, "setlocale"); - read_input(); + num_lines = read_input(); fprintf(stderr, "setlocale: %s\n", p); if (xfrm) - qsort(lines, max_lines, sizeof(struct line *), strcmp_compare); + qsort(lines, num_lines, sizeof(struct line *), strcmp_compare); else - qsort(lines, max_lines, sizeof(struct line *), strcoll_compare); - write_output(); + qsort(lines, num_lines, sizeof(struct line *), strcoll_compare); + write_output(num_lines); return 0; }