3 # ascq_tbl.sh - Translate SCSI t10.org's "asc-num.txt" file of
4 # SCSI Additional Sense Code & Qualifiers (ASC/ASCQ's)
5 # into something useful in C, creating "ascq_tbl.c" file.
7 #*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*#
9 PREF_INFILE="t10.org/asc-num.txt" # From SCSI t10.org
10 PREF_OUTFILE="ascq_tbl.c"
12 #*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*#
18 OUTFILE = "'"${PREF_OUTFILE}"'";
23 # read and discard all lines up to and including the one that begins
24 # with the "magic token" of "------- -------------- ---"...
26 while (!headers_gone) {
29 header_line[++hdrs] = $0;
31 printf("header_line[%d] = :%s:\n", ++hdrs, $0);
32 if ($0 ~ /^------- -------------- ---/) {
42 printf( "DBG: %s\n", $0 );
43 ASC[outcount] = substr($0,1,2);
44 ASCQ[outcount] = substr($0,5,2);
45 devtypes = substr($0,10,14);
46 gsub(/ /, ".", devtypes);
47 DESCRIP[outcount] = substr($0,26);
49 if (!(devtypes in DevTypesVoodoo)) {
50 DevTypesVoodoo[devtypes] = ++voodoo;
51 DevTypesIdx[voodoo] = devtypes;
53 DEVTYPES[outcount] = DevTypesVoodoo[devtypes];
55 # Handle 0xNN exception stuff...
56 if (ASCQ[outcount] == "NN" || ASCQ[outcount] == "nn")
57 ASCQ[outcount] = "FF";
61 printf("#ifndef SCSI_ASCQ_TBL_C_INCLUDED\n") > OUTFILE;
62 printf("#define SCSI_ASCQ_TBL_C_INCLUDED\n") >> OUTFILE;
64 printf("\n/* AuToMaGiCaLlY generated from: %s'"${FIN}"'%s\n", DQ, DQ) >> OUTFILE;
65 printf(" *******************************************************************************\n") >> OUTFILE;
66 for (i=1; i<=hdrs; i++) {
67 printf(" * %s\n", header_line[i]) >> OUTFILE;
69 printf(" */\n") >> OUTFILE;
71 printf("\n") >> OUTFILE;
72 for (i=1; i<=voodoo; i++) {
73 printf("static char SenseDevTypes%03d[] = %s%s%s;\n", i, DQ, DevTypesIdx[i], DQ) >> OUTFILE;
76 printf("\nstatic ASCQ_Table_t ASCQ_Table[] = {\n") >> OUTFILE;
77 for (i=1; i<=outcount; i++) {
78 printf(" {\n") >> OUTFILE;
79 printf(" 0x%s, 0x%s,\n", ASC[i], ASCQ[i]) >> OUTFILE;
80 printf(" SenseDevTypes%03d,\n", DEVTYPES[i]) >> OUTFILE;
81 printf(" %s%s%s\n", DQ, DESCRIP[i], DQ) >> OUTFILE;
82 printf(" },\n") >> OUTFILE;
84 printf( "};\n\n" ) >> OUTFILE;
86 printf( "static int ASCQ_TableSize = %d;\n\n", outcount ) >> OUTFILE;
87 printf( "Total of %d ASC/ASCQ records generated\n", outcount );
88 printf("\n#endif\n") >> OUTFILE;
94 #*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*#
98 echo "INFO: No input filename supplied - using: $PREF_INFILE" >&2
102 if [ "$FIN" != "$PREF_INFILE" ]; then
103 echo "INFO: Ok, I'll try chewing on '$FIN' for SCSI ASC/ASCQ combos..." >&2
108 cat $FIN | xlate_ascq