On May 22, 2012, at 1:48 AM, Bruce Evans wrote: > On Mon, 21 May 2012, Guy Helmer wrote: > >> Log: >> Apply style(9) to return and switch/case statements. >> >> Reviewed by: delphij (prior version of the patch) >> >> Modified: >> head/lib/libc/gen/getnetgrent.c >> >> Modified: head/lib/libc/gen/getnetgrent.c >> ============================================================================== >> --- head/lib/libc/gen/getnetgrent.c Mon May 21 19:58:40 2012 >> (r235738) >> +++ head/lib/libc/gen/getnetgrent.c Mon May 21 21:04:29 2012 >> (r235739) >> ... >> @@ -311,32 +311,35 @@ _revnetgr_lookup(char* lookupdom, char* >> >> for (rot = 0; ; rot++) { >> switch (rot) { >> - case(0): snprintf(key, MAXHOSTNAMELEN, "%s.%s", >> - str, dom?dom:lookupdom); >> - break; >> - case(1): snprintf(key, MAXHOSTNAMELEN, "%s.*", >> - str); >> - break; >> - case(2): snprintf(key, MAXHOSTNAMELEN, "*.%s", >> - dom?dom:lookupdom); >> - break; >> - case(3): snprintf(key, MAXHOSTNAMELEN, "*.*"); >> - break; >> - default: return(0); >> + case(0): >> + snprintf(key, MAXHOSTNAMELEN, "%s.%s", str, >> + dom ? dom : lookupdom); >> + break; >> + case(1): >> + snprintf(key, MAXHOSTNAMELEN, "%s.*", str); >> + break; >> + case(2): >> + snprintf(key, MAXHOSTNAMELEN, "*.%s", >> + dom ? dom : lookupdom); >> + break; >> + case(3): >> + snprintf(key, MAXHOSTNAMELEN, "*.*"); >> + break; > > Thanks, but a fuller application would have removed the obfuscatory > parentheses that make case() look like a function call... > >> + default: return (0); > > ... and split the case statements after ":" in all cases. > >> } >> y = yp_match(lookupdom, map, key, strlen(key), &result, >> &resultlen); > > You fixed the continuation indentation in the case statement but not here. > >> if (y == 0) { >> rv = _listmatch(result, group, resultlen); >> free(result); >> - if (rv) return(1); >> + if (rv) return (1); > > Another statement not started on a new line. > >> } else if (y != YPERR_KEY) { >> /* >> * If we get an error other than 'no >> * such key in map' then something is >> * wrong and we should stop the search. >> */ >> - return(-1); >> + return (-1); >> } >> } >> } > > These style bugs weren't in the CSRG version of course. The YP code added > many. The most obvious ones are the case(n) and gnu-style continuation > indentation. >
I am not sure how to best resolve the long lines in the block of code to free grp->ng_str[] elements. The indentation is quite deep at that point, and breaking short statements over multiple lines would make the code quite ugly. Would this resolve the other issues you pointed out? Index: lib/libc/gen/getnetgrent.c =================================================================== --- lib/libc/gen/getnetgrent.c (revision 235784) +++ lib/libc/gen/getnetgrent.c (working copy) @@ -309,28 +309,30 @@ for (rot = 0; ; rot++) { switch (rot) { - case(0): + case 0: snprintf(key, MAXHOSTNAMELEN, "%s.%s", str, dom ? dom : lookupdom); break; - case(1): + case 1: snprintf(key, MAXHOSTNAMELEN, "%s.*", str); break; - case(2): + case 2: snprintf(key, MAXHOSTNAMELEN, "*.%s", dom ? dom : lookupdom); break; - case(3): + case 3: snprintf(key, MAXHOSTNAMELEN, "*.*"); break; - default: return (0); + default: + return (0); } y = yp_match(lookupdom, map, key, strlen(key), &result, - &resultlen); + &resultlen); if (y == 0) { rv = _listmatch(result, group, resultlen); free(result); - if (rv) return (1); + if (rv) + return (1); } else if (y != YPERR_KEY) { /* * If we get an error other than 'no @@ -418,7 +420,7 @@ parse_netgrp(const char *group) { char *spos, *epos; - int len, strpos; + int len, strpos, freepos; #ifdef DEBUG int fields; #endif @@ -476,17 +478,16 @@ } else len = strlen(spos); if (len > 0) { - grp->ng_str[strpos] = (char *) - malloc(len + 1); + grp->ng_str[strpos] = + malloc(len + 1); if (grp->ng_str[strpos] == NULL) { - int freepos; for (freepos = 0; freepos < strpos; freepos++) free(grp->ng_str[freepos]); free(grp); return (1); } bcopy(spos, grp->ng_str[strpos], - len + 1); + len + 1); } } else { /* @@ -508,13 +509,13 @@ * stay silent by default for compatibility's sake. */ if (fields < 3) - fprintf(stderr, "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n", - grp->ng_str[NG_HOST] == NULL ? "" : grp->ng_str[NG_HOST], - grp->ng_str[NG_USER] == NULL ? "" : ",", - grp->ng_str[NG_USER] == NULL ? "" : grp->ng_str[NG_USER], - grp->ng_str[NG_DOM] == NULL ? "" : ",", - grp->ng_str[NG_DOM] == NULL ? "" : grp->ng_str[NG_DOM], - lp->l_groupname); + fprintf(stderr, "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n", + grp->ng_str[NG_HOST] == NULL ? "" : grp->ng_str[NG_HOST], + grp->ng_str[NG_USER] == NULL ? "" : ",", + grp->ng_str[NG_USER] == NULL ? "" : grp->ng_str[NG_USER], + grp->ng_str[NG_DOM] == NULL ? "" : ",", + grp->ng_str[NG_DOM] == NULL ? "" : grp->ng_str[NG_DOM], + lp->l_groupname); #endif } else { spos = strsep(&pos, ", \t"); @@ -552,7 +553,7 @@ if(yp_get_default_domain(&_netgr_yp_domain)) continue; if (yp_match(_netgr_yp_domain, "netgroup", group, - strlen(group), &result, &resultlen)) { + strlen(group), &result, &resultlen)) { free(result); if (_use_only_yp) return ((struct linelist *)0); @@ -613,7 +614,7 @@ } else cont = 0; if (len > 0) { - linep = (char *)reallocf(linep, olen + len + 1); + linep = reallocf(linep, olen + len + 1); if (linep == NULL) { free(lp->l_groupname); free(lp); -------- This message has been scanned by ComplianceSafe, powered by Palisade's PacketSure. _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"