|
|
1.1 ! root 1: # De-ANSI-fy C programs ! 2: ! 3: # change void* to char * ! 4: { gsub(/void *\*/, "char *") } ! 5: ! 6: # remove args from function declarations and typedefs ! 7: # assume one per line (fitting on one line) ! 8: ! 9: /^[a-zA-Z0-9_]+.*\([^(]*\);.*/ { ! 10: if($0 !~ /^print\(/ && $0 !~ /^fprint\(/ && $0 !~ /^if\(/) { ! 11: sub(/\([^(]*\);/, "();") ! 12: print ! 13: next ! 14: } ! 15: } ! 16: ! 17: # change function definition headers to old-style ! 18: # function definition headers on one line, ending with ')', ! 19: # with the return type (if not omitted) on previous line ! 20: # assume no parentheses inside arg list ! 21: ! 22: /^[a-zA-Z0-9_]+\(.*\)$/ { ! 23: st = index($0, "(") + 1 ! 24: n = length($0) - st ! 25: rawargs = substr($0, st, n) ! 26: printf("%s(", substr($0, 1, st-2)) ! 27: if( rawargs == "void" ) { ! 28: printf(")\n"); ! 29: next ! 30: } ! 31: nargs = split(rawargs, args, ", *") ! 32: for(i = 1; i <= nargs; i++){ ! 33: if(! match(args[i], /[a-zA-Z0-9_]+ *$/)){ ! 34: if(! match(args[i], /[a-zA-Z0-9_]+\[.*\]$/)) ! 35: id = "OOPS" ! 36: else { ! 37: id = substr(args[i], RSTART) ! 38: sub(/\[.*\]/, "", id) ! 39: } ! 40: } else ! 41: id = substr(args[i], RSTART, RLENGTH) ! 42: printf("%s", id) ! 43: if(i < nargs) printf(", ") ! 44: } ! 45: printf(")\n") ! 46: for(i = 1; i <= nargs; i++) ! 47: printf("\t%s;\n", args[i]) ! 48: next ! 49: } ! 50: ! 51: # remove pragmas ! 52: ! 53: /^#[ ]*pragma/ { next } ! 54: ! 55: # just print remaining lines ! 56: { print }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.