errors.awk 1.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
BEGIN {
	print "/* Machine generated. Do not edit. */"
	print ""
	lines = 0
}
{ 
	split($0, array, FS)

	if (NF > 0 && length(array[1]) > 0) {
		lines++

12
		# save the first word (or '&' separated list of words) in the names array
13 14 15 16 17 18 19 20 21 22 23 24
		if (array[2] == "&") {
			if (array[4] == "&") {
				names[lines] = array[1] " " array[2] " " array[3] " " array[4] " " array[5]
				start =  6
			} else {
				names[lines] = array[1] " " array[2] " " array[3]
				start = 4 
			}
		} else {
			names[lines] = array[1] 
			start = 2
		}
25 26 27 28

		# create the WCHAR version of the name
		printf "static const WCHAR name%dW[] = { ", lines
		i = 1
29
		len = length(names[lines]) + 1
30
		while (i < len) {
31
			printf "'%s',", substr(names[lines],i,1)
32 33 34 35 36 37
			i++
		}
		print  "0 };"
	
		# create the CHAR version of the description
		printf "static const CHAR description%dA[] = \"", lines
38
		word = start 
39 40 41 42 43 44 45 46 47 48
		while (word < (NF + 1)) {
			printf "%s", array[word]
			if (word < NF )
				printf " "
			word++
		}
		print  "\";"
	
		# create the WCHAR version of the description
		printf "static const WCHAR description%dW[] = { ", lines
49
		word = start
50 51 52 53
		while (word < (NF + 1)) {
			i = 1
			len = length(array[word]) + 1
			while (i < len) {
54
				if (substr(array[word],i,1) == "'")
55 56 57
					printf "'\\'',"
				else
					printf "'%s',", substr(array[word],i,1)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
				i++
			}
			if (word < NF )
				printf "' ',"
			word++
		}
		print  "0 };"
	}
}
END {
	print ""
	print "static const error_info info[] = {"

	i = 1 
	while ( i <= lines) { 
73
		split(names[i], words, FS)
74
		printf "    { %s, \"%s\", name%dW, description%dA, description%dW },\n", 
75
			words[1], names[i], i, i,i 
76 77 78 79 80
		i++
	}

	print "};"
}