ascq_tbl.sh
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #!/bin/sh
  2. #
  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.
  6. #
  7. #*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*#
  8. PREF_INFILE="t10.org/asc-num.txt" # From SCSI t10.org
  9. PREF_OUTFILE="ascq_tbl.c"
  10. #*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*#
  11. xlate_ascq() {
  12. cat | awk '
  13. BEGIN {
  14. DQ = "42";
  15. OUTFILE = "'"${PREF_OUTFILE}"'";
  16. TRUE = 1;
  17. FALSE = 0;
  18. #debug = TRUE;
  19. #  read and discard all lines up to and including the one that begins
  20. #  with the "magic token" of "-------  --------------  ---"...
  21. headers_gone = FALSE;
  22. while (!headers_gone) {
  23. if (getline <= 0)
  24. exit 1;
  25. header_line[++hdrs] = $0;
  26. if (debug)
  27. printf("header_line[%d] = :%s:n", ++hdrs, $0);
  28. if ($0 ~ /^-------  --------------  ---/) {
  29. headers_gone = TRUE;
  30. }
  31. }
  32. outcount = 0;
  33. }
  34. (NF > 1) {
  35. ++outcount;
  36. if (debug)
  37. printf( "DBG: %sn", $0 );
  38. ASC[outcount] = substr($0,1,2);
  39. ASCQ[outcount] = substr($0,5,2);
  40. devtypes = substr($0,10,14);
  41. gsub(/ /, ".", devtypes);
  42. DESCRIP[outcount] = substr($0,26);
  43. if (!(devtypes in DevTypesVoodoo)) {
  44. DevTypesVoodoo[devtypes] = ++voodoo;
  45. DevTypesIdx[voodoo] = devtypes;
  46. }
  47. DEVTYPES[outcount] = DevTypesVoodoo[devtypes];
  48. #  Handle 0xNN exception stuff...
  49. if (ASCQ[outcount] == "NN" || ASCQ[outcount] == "nn")
  50. ASCQ[outcount] = "FF";
  51. }
  52. END {
  53. printf("#ifndef SCSI_ASCQ_TBL_C_INCLUDEDn") > OUTFILE;
  54. printf("#define SCSI_ASCQ_TBL_C_INCLUDEDn") >> OUTFILE;
  55. printf("n/* AuToMaGiCaLlY generated from: %s'"${FIN}"'%sn", DQ, DQ) >> OUTFILE;
  56. printf(" *******************************************************************************n") >> OUTFILE;
  57. for (i=1; i<=hdrs; i++) {
  58. printf(" * %sn", header_line[i]) >> OUTFILE;
  59. }
  60. printf(" */n") >> OUTFILE;
  61. printf("n") >> OUTFILE;
  62. for (i=1; i<=voodoo; i++) {
  63. printf("static char SenseDevTypes%03d[] = %s%s%s;n", i, DQ, DevTypesIdx[i], DQ) >> OUTFILE;
  64. }
  65. printf("nstatic ASCQ_Table_t ASCQ_Table[] = {n") >> OUTFILE;
  66. for (i=1; i<=outcount; i++) {
  67. printf("  {n") >> OUTFILE; 
  68. printf("    0x%s, 0x%s,n", ASC[i], ASCQ[i]) >> OUTFILE;
  69. printf("    SenseDevTypes%03d,n", DEVTYPES[i]) >> OUTFILE;
  70. printf("    %s%s%sn", DQ, DESCRIP[i], DQ) >> OUTFILE;
  71. printf("  },n") >> OUTFILE;
  72. }
  73. printf( "};nn" ) >> OUTFILE;
  74. printf( "static int ASCQ_TableSize = %d;nn", outcount ) >> OUTFILE;
  75. printf( "Total of %d ASC/ASCQ records generatedn", outcount );
  76. printf("n#endifn") >> OUTFILE;
  77. close(OUTFILE);
  78. }'
  79. return
  80. }
  81. #*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*#
  82. # main()
  83. if [ $# -lt 1 ]; then
  84. echo "INFO: No input filename supplied - using: $PREF_INFILE" >&2
  85. FIN=$PREF_INFILE
  86. else
  87. FIN="$1"
  88. if [ "$FIN" != "$PREF_INFILE" ]; then
  89. echo "INFO: Ok, I'll try chewing on '$FIN' for SCSI ASC/ASCQ combos..." >&2
  90. fi
  91. shift
  92. fi
  93. cat $FIN | xlate_ascq
  94. exit 0