⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.txt

📁 这是一个C程序分析工具
💻 TXT
字号:
MetreCopyright (c) 1993-1995 by Paul Long  All rights reserved.This file contains installation instructions to enable a systemadministrator to build, verify, and install the Metre tools, Mtree andMetre. It also contains a brief description of how to modify the Metretools or write a new one.Building Metre--------------The simplest way to build the Metre metrics tool is to use one of thefollowing commands according to which development environment you areusing. They are for Borland (MS-DOS), Microsoft (MS-DOS), Sun (SunOS),and Gnu (UNIX), respectively. Extrapolate from these examples for otherenvironments. To build the Mtree call-tree tool instead, replace "metre"with "mtree" and "metrules" with "trerules". That is all there is to it.   bcc -A -w-rch -w-ccc -w-eff -emetre.exe metrules.c ytab.c lex_yy.c   cl -Za -w -Femetre.exe metrules.c ytab.c lex_yy.c   acc -w -o metre metrules.c ytab.c lex_yy.c -lm   gcc -ansi -w -o metre metrules.c ytab.c lex_yy.c -lmPortabilityMetre is portable across operating systems (e.g., MS-DOS, UNIX, ULTRIX,and VMS), Standard C compilers (e.g., Sun acc, Gnu gcc, Borland bcc, andMicrosoft cl), and various flavors of lex (i.e., AT&T lex, MKS lex,Abraxas pclex, and flex) and yacc (i.e., AT&T yacc, MKS yacc, Abraxaspcyacc, and bison).Detailed InstructionsThe following explains in more detail how to build the Metre metricstool whos behavior is defined by the set of rules in the metrules.cfile. As described above, to build the call-hierarchy tool, Mtree,instead, replace "metre" with "mtree" and "metrules" with "trerules".While this section discusses how to build and test the tools "by hand,"makefiles are also included which do this for you. There is one for UNIX(makefile.unx) and one for MS-DOS (makefile.dos). Read their commentsfor more information on how to use them.Metre is distributed as a set of lex, yacc, and Standard C files. Withthe C source and header files, you should be able to build an executablefor any environment that has a Standard C compiler. You must use aStandard, or "ANSI," C compiler to build Metre. A pre-ANSI, K&R Ccompiler, such as cc, will not work.For example, to build the Metre metrics tool with Borland's MS-DOS Ccompiler, use this command:   bcc -A -w-rch -w-ccc -w-eff -emetre.exe metrules.c ytab.c lex_yy.cIf you have lex and yacc, you can modify the lex and yacc specificationsin scan.l and gram.y, respectively, and regenerate the parser's C sourcefiles. However, you are better off just using the lex_yy.c, ytab.c, andytab.h files that I provide. Although these files were generated by MKSlex/yacc under MS-DOS, they should compile under any operating system(see the section, lex_yy.c Assumes ASCII, below).In addition to there being no benefit to regenerating these intermediatefiles for the sole purpose of regenerating them, the reason to use mylex_yy.c is that lexers generated from my lex specification by flex andpclex do not make the source line available for printing diagnostics andcopying input to output. This is not the fault of either of these tools.It is because I am more familiar with MKS and AT&T lex and have nottaken the time to discover how to do this with flex and pclex.If you have MKS lex/yacc and have modified the parser which is definedin scan.l and gram.y, you can regenerate the intermediate C files withthese two commands under MS-DOS before compiling and linking everything:   yacc -d gram.y   lex scan.lThe -d tells yacc to generate a token header file that the lexspecification includes. Being an MS-DOS implementation, this header fileis called ytab.h instead of the normal, UNIX y.tab.h. So if you use ayacc that generates y.tab.h, you need to either rename it to ytab.h orchange the #include directive in scan.l to include y.tab.h instead ofytab.h. I prefer the former so that I do not have to change the sourcefile. For example, under SunOS using AT&T lex/yacc and Sun's ANSI Ccompiler, acc, the Metre executable can be built from the ground up withthese commands:   yacc -d gram.y   mv y.tab.h ytab.h   lex scan.l   acc -o metre metrules.c y.tab.c lex.yy.c -lmIf you use flex and bison instead of lex and yacc, replace "lex" on thecommand line with "flex" and "yacc" with "bison". With bison, also usethe -y command-line option so that it generates files with yacc-likenames. The -lm option at the end of the acc command line links in themath library that contains the definition of log10() which metrules.creferences. This math library does not need to be linked in whenbuilding the Mtree call-hierarchy tool.Warning SuppressionWithout the -w command-line compiler options which you may have noticed,I get various warnings depending on which compiler I am using. Thesewarnings can be safely ignored. The Borland compiler warns aboutunreachable code, condition always being true/false, and code having noeffect. The Sun ANSI C compiler warns about -1 (~0) not fitting as aninitializer for yy_check[] in lex_yy.c. The Sun and Microsoft Ccompilers both generate signed-vs-unsigned-chars warnings regardingyytext[]. These warnings are a result of 1) having source that iscompilable under various development environments and 2) the parserbeing machine-generated. If you have problems after you build the Metretools, you should probably rebuild them without the -w options and seeif you notice anything suspicious in the diagnostics.End-of-line CaveatRemember that MS-DOS and UNIX use different end-of-line characters, andI suppose that there are environments out there that use othercharacters. If your compiler chokes mysteriously on a source file that Ihave provided, make sure that it is in the correct format for yourdevelopment environment. If not, you must convert it. For this, I useflip and mud, a couple of MS-DOS tools that I downloaded from somewhere.Macintosh PortabilityI cannot tell you conclusively whether Metre is portable to the Mac. Intheory, you should not have a problem at all if you have access to a lexand are able to regenerate the lexer from scan.l and not use thelex_yy.c that I provide. (Be careful, though. I have heard that,especially on the Mac, you need to make sure that your lexer iscompatible with your compiler--that, specifically, they agree about theinternal value of newline.)You may have a problem, however, if you use my lex_yy.c. You see, lexgenerates a lexer that indexes into tables based on the value ofcharacters. I generated lex_yy.c as an ASCII lexer (see the section,lex_yy.c Assumes ASCII, below) that uses the value, 10, as the internalvalue of newline. All of the C compilers I know about for MS-DOS, UNIX,and VMS also use this as the internal value of newline. Programscompiled with them work great with lex_yy.c.On the Mac, however, things are not so rosy. At least one Mac C compileruses 13 for newline (and 10 for \r, curiously enough). Withoutmodification, the lexer in lex_yy.c would report all newlines asnon-standard characters because it sees 13 instead of the value fornewline that it expects, 10. There is hope, though--I modified the lexerto handle this.If the lexer detects that your compiler's internal value for newline isnot what it expects, it makes the substitution as each character is readin. That simple. These characters are never displayed as part of anoutput string, all other newlines in the program that get displayed, forexample, are left alone, and the lexer sees the newline that it wasbuilt to recognize. I have thought about this a lot, and a couple of Macguys agree with me that this should work. However, it does not.The reported problem once the modification is made (I do not have a Macon which to test any of this stuff) is that sometimes the lexer somehowmisses a newline and grafts two lines together. Specifically, itcomplained about the '#' character in a #line directive. It must havenot been able to recognize beginning-of-line that the newline would havepresented.So, where are we? I left the modification in so that lex_yy.c shouldwork on any system, not just the Mac, regardless of the internal valueof newline. I cannot explain why it has been reported to fail on theMac. In truth, I have only heard from one Mac guy. Perhaps there wassomething peculiar about his development environment that we overlooked.Perhaps it will work on another Mac. Perhaps yours.If you would like to take a shot at it, the user was kind enough to giveme the following commands that he used to build Metre under MPW 3.1.   C metrules.c; C ytab.c; C lex_yy.c   Link -t MPST -c 'MPS ' -o metre <0xB6>      -sn STDIO=Main -sn INTENV=Main -sn %A5Init=Main <0xB6>      ytab.c.o lex_yy.c.o metrules.c.o <0xB6>      "{Libraries}"Stubs.o "{CLibraries}"StdCLib.o <0xB6>      "{CLibraries}"Math.o "{Libraries}"Runtime.o <0xB6>      "{Libraries}"Interface.o "{Libraries}"ToolLibs.oHe said that <0xB6> is where a line-continuation character with thatvalue goes. I assume that if you are a Mac user, you know how to type insuch a character at your keyboard--I have no idea.If you get lex_yy.c to work correctly on a Mac, please send me someemail. I would love to hear about it.lex_yy.c Assumes ASCIIlex_yy.c contains tables that were built assuming an ASCII encoding ofcharacters. It, therefore, will not work on a non-ASCII system, such asone that uses EBCDIC. If you intend to use Metre on a non-ASCII system,you must generate a new lexer from the lex specification in scan.l witha lex that builds tables for your encoding scheme. There is also a wayto define the character set in the lex specification for an otherwiseASCII lex. "This is left as an exercise to the reader."Certified OutputYou can determine whether your executables were built correctly bycomparing the results of the following commands with the corresponding"certifiably correct" output files, metrules.out and trerules.out, whichare included with this distribution.        metre -DBOOLEAN=int -Dva_list=int -H -a metrules.c        mtree -DBOOLEAN=int -rrules -l -t trerules.cFor example, using the UNIX diff and rm commands:        metre -DBOOLEAN=int -Dva_list=int -H -a metrules.c >tmp.tmp        diff metrules.out tmp.tmp        mtree -DBOOLEAN=int -rrules -l -t trerules.c >tmp.tmp        diff trerules.out tmp.tmp        rm tmp.tmpUnder MS-DOS, you would use fc and del in place of diff and rm,respectively.The -D command-line option instructs Metre to use int whenever itencounters BOOLEAN in metrules.c so that you do not need to run apreprocessor first. (Read the Adaptability section for more informationabout using the -D option.) Metre then displays various metrics aboutthe code contained in the file. Note that for most non-trivial Cprograms, you have to run the source through a C preprocessor first.Also, you only need to specify "-DBOOLEAN=int -Dva_list=int" for thistest, not every time you run Metre.NOTE: Due to the floating-point calculations performed by Metre and thevarying internal floating-point representations and rounding schemes ofC compilers, some data generated by your copy of Metre may be slightlydifferent than the data in the certified output files.Man PagesMetre comes with the man pages, metre.1 and mtree.1, for use with theUNIX man command. Copy them to a directory where man will find them.They contain the same information as the metre.doc file, so you are notmissing any crucial information if you are running on a non-UNIX systemand have no way to access man pages.fcnrules.cThe file, fcnrules.c, contains a small set of rules for a tool thatwrites each function out to a separate file whose name is the name ofthe function. It is mainly provided to show the variety of things thatcan be done with Metre. Unlike the other tools, it is not generallyuseful and is not practical for environments with minimal file-namelengths, such as MS-DOS. For these reasons, there is no further mentionor support for it in the distribution. For example, the make files willnot build it. Read the comments in fcnrules.c for further information,and build it in the same way as the other tools.Modifying Metre---------------Like Abraxas' CodeCheck product, Metre is rule-based. Different behavioris obtained by simply modifying or replacing the rules in the rules file(metrules.c for example) rather than modifying the more complex code ofthe parser (in scan.l and gram.y) that is the core of Metre. As a matterof fact, most of the tool-specific behavior described in this documentis implemented with rules. Therefore, for your own good, make changes tothe rules file if at all possible. Only tinker with gram.y and scan.l ifthe behavior you seek cannot be expressed with rules using the existingparser.Note: The metrules.c file contains rules that reflect my own programmingsensibilities. For example, it generates a warning if a function hasmore than one return statement. If you do not like this, remove therule.The parser can be used to construct other tools. Think of it as a basic,easy-to-use parser for Standard C. As an example, by only providing afew rules and not modifying the parser at all, I built a special versionof the UNIX tool, diff, that has the dual granularity of text lines andC functions. My version indicates whether a function has been removed oradded, and if a function has been modified, it names it and thengenerates the normal diff output showing which lines have been added,removed, or modified.There must always be a rules() function linked with the parser. Itcontains a set of "rules" that define how the resulting executablebehaves. With no rules, for example, void rules(void){}, the result isjust a C syntax checker. A rule is of the following form:         if (<trigger>)            <action>Trigger is an expression of terms taken from the structs and functionsdeclared in the provided metre.h header file. See the rules files (e.g.,metrules.c) for examples. See the metre.h file for other possibilities.A rule should NEVER have an else, although the action may contain if'swith else's. The rule's else would effectively be executed ALL THE TIMEexcept when the trigger occurs. Not a pretty sight.Action is any statement, including the compound statement, {...}. Hereare some examples:         if (keyword("goto"))            ++fcn_gotos;         if (fcn.begin)         {            fcn_gotos = 0;            fcn_continues = 0;            fcn_returns = 0;            fcn_depth_max = 0;         }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -