home *** CD-ROM | disk | FTP | other *** search
- # QTAwk program to scan C source files for keywords defined in the ANSI C
- # standard keywords:
- # macro or function names defined in the standard
- # types or constants defined in the standard
- #
- # program to illustrate GROUP pattern keyword
- #
- # input: C source file
- # output: all lines containing ANSI C standard defined keywords
- #
- # use 'GROUP' pattern keyword to form one large GROUP of patterns to speed
- # search. Only two actions defined:
- # 1) action to print macro or function names
- # 2) action to print types or constants
- #
- #
- BEGIN {
- #
- # ANSI C key words
- #
- # expression for leader
- ldr = /(^|{_w})/;
- # opening function parenthesis - look-ahead to find
- o_p = /@{_w}*\(/;
- }
- #
- #
- # Following are macro or functions names as defined by ANSI C standard
- #
- # 1
- GROUP /{ldr}assert{o_p}/
- # 2
- GROUP /{ldr}is(al(num|pha)|cntrl|x?digit|graph|lower|p(rint|unct)|space|upper){o_p}/
- # 3
- GROUP /{ldr}to(lower|upper){o_p}/
- # 4
- GROUP /{ldr}set(locale|v?buf){o_p}/
- # 5
- GROUP /{ldr}a(cos|sin|tan2?|bort){o_p}/
- # 6
- GROUP /{ldr}(cos|sin|tan)h?{o_p}/
- # 7
- GROUP /{ldr}(fr|ld)?exp{o_p}/
- # 8
- GROUP /{ldr}log(10)?{o_p}/
- # 9
- GROUP /{ldr}modf{o_p}/
- # 10
- GROUP /{ldr}pow{o_p}/
- # 11
- GROUP /{ldr}sqrt{o_p}/
- # 12
- GROUP /{ldr}ceil{o_p}/
- # 13
- GROUP /{ldr}(f|l)?abs{o_p}/
- # 14
- GROUP /{ldr}f(loor|mod){o_p}/
- # 15
- GROUP /{ldr}jmp_buf{o_p}/
- # 16
- GROUP /{ldr}(set|long)jmp{o_p}/
- # 17
- GROUP /{ldr}signal{o_p}/
- # 18
- GROUP /{ldr}raise{o_p}/
- # 19
- GROUP /{ldr}va_(arg|end|list|start){o_p}/
- # 20
- GROUP /{ldr}re(move|name|wind){o_p}/
- # 21
- GROUP /{ldr}tmp(file|nam){o_p}/
- # 22
- GROUP /{ldr}(v?[fs])?printf{o_p}/
- # 23
- GROUP /{ldr}[fs]?scanf{o_p}/
- # 24
- GROUP /{ldr}f?get(c(har)?|s|env){o_p}/
- # 25
- GROUP /{ldr}f?put(c(har)?|s){o_p}/
- # 26
- GROUP /{ldr}ungetc{o_p}/
- # 27
- GROUP /{ldr}f(close|flush|(re)?open|read|write|[gs]etpos|seek|tell|eof|ree|pos_t){o_p}/
- # 28
- GROUP /{ldr}clearerr{o_p}/
- # 29
- GROUP /{ldr}[fp]error{o_p}/
- # 30
- GROUP /{ldr}ato[fil]{o_p}/
- # 31
- GROUP /{ldr}str(to(d|k|u?l)|n?c(py|at|mp)|coll|r?chr|c?spn|pbrk|str|error|len){o_p}/
- # 32
- GROUP /{ldr}nd{o_p}/
- # 33
- GROUP /{ldr}(c|m|re)?alloc{o_p}/
- # 34
- GROUP /{ldr}?exit{o_p}/
- # 35
- GROUP /{ldr}(f|mk|asc|c|gm|local|strf)?time{o_p}/ {
- printf("Macro/function\n%uE - %luR: %s\n%s\n",NG,FNR,$0,$$0);
- mf_count++;
- }
- #
- # following are types or constants
- #
- # 36
- GROUP /errno/
- # 37
- GROUP /NULL/
- # 38
- GROUP /offsetof/
- # 39
- GROUP /ptrdiff_t/
- # 40
- GROUP /size_t/
- # 41
- GROUP /NDEBUG/
- # 42
- GROUP /LC_(ALL|COLLATE|CTYPE|NUMERIC|TIME)/
- # 43
- GROUP /E(DOM|RANGE|OF)/
- # 44
- GROUP /HUGE_VAL/
- # 45
- GROUP /sig_atomic_t/
- # 46
- GROUP /SIG(_(DFL|ERR|IGN)|ABRT|FPE|ILL|INT|SEGV|TERM)/
- # 47
- GROUP /FILE/
- # 48
- GROUP /_IO[FLN]BF/
- # 49
- GROUP /BUFSIZ/
- # 50
- GROUP /L_tmpnam/
- # 51
- GROUP /(OPEN|RAND|TMP|U(CHAR|INT|LONG|SHRT))_MAX/
- # 52
- GROUP /SEEK_(CUR|END|SET)/
- # 53
- GROUP /std(err|in|out)/
- # 54
- GROUP /l?div_t/
- # 55
- GROUP /CLK_TCK/
- # 56
- GROUP /(clock|time)_t/
- # 57
- GROUP /tm_(sec|min|hour|[mwy]day|mon|year|isdst)/
- # 58
- GROUP /CHAR_(BIT|M(AX|IN))/
- # 59
- GROUP /(INT|LONG|S(CHAR|HRT))_(M(IN|AX))/
- # 60
- GROUP /(L?DBL|FLT)_((MANT_)?DIG|EPSILON|M(AX|IN)(_(10_)?EXP)?)/
- # 61
- GROUP /FLT_R(ADIX|OUNDS)/ {
- printf("type/constant\n%uE - %luR: %s\n%s\n",NG,FNR,$0,$$0);
- tc_count++;
- }
-
- FINAL {
- printf("Total Lines Scanned: %lu\n",FNR);
- printf("Total Line containing macro/function names: %lu\n",mf_count);
- printf("Total Line containing type/constant names: %lu\n",tc_count);
- }
-