|
| 1 | +#!/bin/gawk -f |
| 2 | +BEGIN { |
| 3 | + # Set output field separator |
| 4 | + OFS=" | "; |
| 5 | + # Initialize mapping associative array |
| 6 | + while ((getline < "docs/_appendixdata/appendix_b.map") > 0) { |
| 7 | + if ($1 ~ /^[[:digit:]]+$/ && $2 ~ /^[[:digit:]]+$/) { |
| 8 | + old_id_array[$2]=$1; |
| 9 | + } |
| 10 | + } |
| 11 | +} |
| 12 | +{ |
| 13 | + # Input is a stream of the first 4 lines of every .md file in section 4-language-usage |
| 14 | + if ($1 == "#" && $2 ~ /^G-[[:digit:]]+/ ) { |
| 15 | + # From the first of the 4 lines we grab the G- new id |
| 16 | + new_id=substr($2,3,length($2)-3); |
| 17 | + # Get old id from mapping array |
| 18 | + old_id=old_id_array[new_id]; |
| 19 | + # Default to n/a |
| 20 | + if (old_id == "") {old_id="n/a"} |
| 21 | + # The text of the rule is most of the first line |
| 22 | + text=$0; |
| 23 | + # We just remove the # G-<id>: from the beginning of the text |
| 24 | + dummy=sub(/^# G-[[:digit:]]+: /,"",text); |
| 25 | + |
| 26 | + # Get the second of the 4 lines and ignore it, it's empty |
| 27 | + getline; |
| 28 | + |
| 29 | + # Get the third of the 4 lines |
| 30 | + getline; |
| 31 | + # Retrieve the severity field from the third line |
| 32 | + severity=substr($3,2,length($3)-2); |
| 33 | + |
| 34 | + # Get the fourth and last of the 4 lines |
| 35 | + getline; |
| 36 | + # If the char array was filled from the last iteration, we need to empty it here |
| 37 | + char[1]=""; |
| 38 | + char[2]=""; |
| 39 | + char[3]=""; |
| 40 | + char[4]=""; |
| 41 | + char[5]=""; |
| 42 | + char[6]=""; |
| 43 | + char[7]=""; |
| 44 | + char[8]=""; |
| 45 | + |
| 46 | + # The fourth line is a comma-separated list of characteristics - split them into an array |
| 47 | + no_of_characteristics=split($0,characteristics,","); |
| 48 | + for (i in characteristics) { |
| 49 | + # If the characteristics array value is one of 8 values, we put a mark in the corresponding value of char array |
| 50 | + if (characteristics[i] ~ /Changeability/ ) {char[1]="✘"} |
| 51 | + if (characteristics[i] ~ /Efficiency/ ) {char[2]="✘"} |
| 52 | + if (characteristics[i] ~ /Maintainability/ ) {char[3]="✘"} |
| 53 | + if (characteristics[i] ~ /Portability/ ) {char[4]="✘"} |
| 54 | + if (characteristics[i] ~ /Reliability/ ) {char[5]="✘"} |
| 55 | + if (characteristics[i] ~ /Reusability/ ) {char[6]="✘"} |
| 56 | + if (characteristics[i] ~ /Security/ ) {char[7]="✘"} |
| 57 | + if (characteristics[i] ~ /Testability/ ) {char[8]="✘"} |
| 58 | + |
| 59 | + # If the characteristics value is something other than these 8 values, we output an error in the text so it'll be noticed |
| 60 | + if (!(characteristics[i] ~ /Changeability/ || \ |
| 61 | + characteristics[i] ~ /Efficiency/ || \ |
| 62 | + characteristics[i] ~ /Maintainability/ || \ |
| 63 | + characteristics[i] ~ /Portability/ || \ |
| 64 | + characteristics[i] ~ /Reliability/ || \ |
| 65 | + characteristics[i] ~ /Reusability/ || \ |
| 66 | + characteristics[i] ~ /Security/ || \ |
| 67 | + characteristics[i] ~ /Testability/ )) {text="!!!CHARACTERISTIC ERROR!!!"} |
| 68 | + } |
| 69 | + |
| 70 | + # Output the fields of the markdown table in appendix B |
| 71 | + print old_id, new_id, text, severity, char[1], char[2], char[3], char[4], char[5], char[6], char[7], char[8]; |
| 72 | + |
| 73 | + # Special handling - between rule G-5040 and G-5050 we output the old rule 54 that is not mapped to any new rule |
| 74 | + if (new_id == "5040") { |
| 75 | + print "54 | n/a | Avoid use of EXCEPTION_INIT pragma for a 20nnn error. | Major | | | | | ✘ | | | "; |
| 76 | + } |
| 77 | + |
| 78 | + # Done handling the 4 lines of one .md file. Next 4 lines will be from another .md file and be handled in the next iteration. |
| 79 | + } |
| 80 | +} |
| 81 | + |
0 commit comments