Git init
[external/mawk.git] / msdos / examples / winobj.awk
1 # Ben Myers <0003571400@mcimail.com>
2
3 # Sum up sizes of Windows OBJ files in current directory
4 # requires DOS 5.0 and Borland TDUMP
5 # A clumsy script to count Windows OBJs and sum up the CODE sizes
6 # run with
7 #       awk -fwinobj.awk work1
8 # where work1 is a work file
9 # You must have at least one filename as an arg, else awk will want to read
10 # from con:, hence the requirement for work1
11 BEGIN {
12 # redirection done by shelled command
13 ocount = 0  # obj module counter
14 otsize = 0  # text size accumulator
15 odsize = 0  # data size accumulator
16 system("del workfile.$%$") # Will probably cause a File Not Found message
17 # Generate a list of OBJs
18 system("dir *.obj /b >" ARGV[1])
19 while (getline < ARGV[1] > 0) {
20 # TDUMP selects only the SEGDEFs to speed things up a lot
21 # and keeps on piping to the workfile
22 system("tdump " $1 " -oiSEGDEF >>workfile.$%$")
23 ocount++
24 }
25 # Now read workfile back, processing lines that are module ids and SEGDEF info
26 # Print one line for each SEGDEF processed
27 j = 1
28 while (getline < "workfile.$%$" > 0) {
29 # module name
30 if($1 == "Display" && $2 == "of" && $3 == "File") { module_name = $4 }
31 # SEGDEF CODE
32 if($2 == "SEGDEF" && $9 =="'CODE'") {
33 decval = hexdec($11)
34 otsize += decval
35 printf ("%12s CODE %4s %7i\n", module_name, $11, decval)
36 j++ }
37 # SEGDEF DATA
38 if($2 == "SEGDEF" && $9 =="'DATA'") {
39 decval = hexdec($11)
40 odsize += decval
41 printf ("%12s DATA %4s %7i\n", module_name, $11, decval)
42 j++ }
43 } # while
44 } # end of BEGIN section
45 # no main loop at all!
46 END {
47 # print summary and delete work files
48 printf ("%i OBJ files\n", ocount)
49 printf ("Total CODE size   %04x %7li bytes\n", otsize, otsize)
50 printf ("Total DATA size   %04x %7li bytes\n", odsize, odsize)
51 system("del "ARGV[1])
52 system("del workfile.$%$")
53 }  # end of END section
54
55 # No scanf in awk, so convert hex string x to decimal the hard way
56 function hexdec (x) {
57 result = 0
58 for (i=1; i<=length(x); i++) {
59 thechar = substr(x,i,1)
60 # digits 0-9 and lower case hex produced by TDUMP
61 # use brute force
62 if (thechar == "0") {result = result*16}
63 if (thechar == "1") {result = result*16 + 1}
64 if (thechar == "2") {result = result*16 + 2}
65 if (thechar == "3") {result = result*16 + 3}
66 if (thechar == "4") {result = result*16 + 4}
67 if (thechar == "5") {result = result*16 + 5}
68 if (thechar == "6") {result = result*16 + 6}
69 if (thechar == "7") {result = result*16 + 7}
70 if (thechar == "8") {result = result*16 + 8}
71 if (thechar == "9") {result = result*16 + 9}
72 if (thechar == "a") {result = result*16 + 10}
73 if (thechar == "b") {result = result*16 + 11}
74 if (thechar == "c") {result = result*16 + 12}
75 if (thechar == "d") {result = result*16 + 13}
76 if (thechar == "e") {result = result*16 + 14}
77 if (thechar == "f") {result = result*16 + 15}
78 } # for (i=1;i<length(x);i++)
79 return result
80 } # function hexdec (x)
81