From owner-freebsd-chat@FreeBSD.ORG Sat Aug 21 14:41:12 2004 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 60E6616A4CE for ; Sat, 21 Aug 2004 14:41:12 +0000 (GMT) Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0DF8D43D2D for ; Sat, 21 Aug 2004 14:41:12 +0000 (GMT) (envelope-from torstenvl@gmail.com) Received: by mproxy.gmail.com with SMTP id 77so29022rnl for ; Sat, 21 Aug 2004 07:41:11 -0700 (PDT) Received: by 10.38.99.64 with SMTP id w64mr464952rnb; Sat, 21 Aug 2004 07:41:11 -0700 (PDT) Received: by 10.38.73.7 with HTTP; Sat, 21 Aug 2004 07:41:11 -0700 (PDT) Message-ID: <126eac480408210741323f9d16@mail.gmail.com> Date: Sat, 21 Aug 2004 10:41:11 -0400 From: =?UTF-8?Q?Josh_=C5=8Cckert?= To: "Jeremy C. Reed" In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable References: cc: freebsd-chat@freebsd.org Subject: Re: tool for listing C functions used in source code? X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: =?UTF-8?Q?Josh_=C5=8Cckert?= List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Aug 2004 14:41:12 -0000 On Fri, 20 Aug 2004 21:30:24 -0700 (PDT), Jeremy C. Reed wrote: > On Fri, 20 Aug 2004, [UTF-8] Josh =C5=8Cckert wrote: >=20 > > > What are some good tools for searching source code that can list all = the > > > standard libc functions used? >=20 > > for i in `ls /usr/share/man/man3/ | sed -e '/\\\..*$/d'`; do echo $i; > > grep -c $i filename.c; done >=20 > Thank you for your ideas. Nevertheless, I am looking for a tool that > actually parses the code and follows includes like cflow, cscope or cxref > (which I still can't figure out yet). >=20 > Your idea implies that the function used is accurately documented. Also i= t > is missing a cut or sed to chop the ".3" off the end. Also, your idea > could have many false positives due to matching partial function names. > Also, it could match on code that is never used (because of C processor > directives or in comments). By the time, I get a bunch of sed and grep to > help organize it, it would be easier to find a program that already does > it. >=20 > > man sed > > man grep >=20 > I know sed and grep. Along with awk, they are my good friends :) >=20 > Some things I have tried: >=20 > cflows (I also packaged it for pkgsrc.) >=20 > cflow /usr/src/bin/ls/*.c | egrep '{}$' | cut -f 3 >=20 > But the output is missing getopt and printf and probably others. Also it > shows functions that aren't shown in code (like clock(3)), but that is > probably okay since they must be called by a function in the code. (I'd > like it to tell me what functions are calling the other functions.) Any > suggestions with cflow? >=20 > I also tried cxref, like: >=20 > cxref -xref-all -raw /usr/src/*bin/*/*c | grep ^Calls | grep -v ' : /' >=20 > It appears to do a good job. I still need to figure out how to get it to > do source that is in different directories while still outputting to one > "-raw" standard output. Any examples for doing that? >=20 > I also tried cscope, but I can't figure out how to get it to what I want. > I do not want something interactive. And I don't want to manually have to > run it numerous times to get my info. >=20 > Any other suggestions? >=20 > Jeremy C. Reed >=20 > technical support & remote administration > http://www.pugetsoundtechnology.com/ >=20 >=20 >=20 > _______________________________________________ > freebsd-chat@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-chat > To unsubscribe, send any mail to "freebsd-chat-unsubscribe@freebsd.org" >=20 Your original post said 'used' -- this is kind of ambiguous. Since the call to clock() seemed okay but you complained about dead code being counted, I'll assume you mean 'called, directly or indirectly'. The problem with this is that the program would have to know the internal implementations of standard library functions when it scans the source code, or it would have to scan the binary. I don't know how to accomplish either of these ends personally (perhaps your cflow or whatever will work for you?). However, if you only want things that your code calls directly, your criticisms are unfounded. > Your idea implies that the function used is accurately documented. If it's in libc, it should be documented. > Also it > is missing a cut or sed to chop the ".3" off the end. Uhhh... really? . o O ( sed -e '/\\\..*$/d' ) > Also, your idea > could have many false positives due to matching partial function names. "you might want to replace all tokens that can separate two function calls with newlines and create a temporary file and then search that instead" Extend that a bit further and replace all whitespace with newlines, then delete newlines, then put any operators that aren't on a line by themselves on a line by themselves... If you separated out all the tokens in the code you could then check the whole line, something like ^$i\$ or whatever the syntactic mess necessary to accomplish that is. Then it would match the entire function name or not at all. > Also, it could match on code that is never used (because of C processor > directives or in comments). So uh... run the C processor err umm preprocessor on the code first...