mme.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * mme.c - Atheros vendor-specific message code and name printer;
  44. *
  45. * print vendor-specific mesage codes and names and with associated
  46. * error codes and error text on stdout in various formats; options
  47. * are HTML, CSV and plain text;
  48. *
  49. *
  50. * Contributor(s):
  51. * Charles Maier
  52. *
  53. *--------------------------------------------------------------------*/
  54. /*====================================================================*
  55. * system header files;
  56. *--------------------------------------------------------------------*/
  57. #include <stdio.h>
  58. #include <errno.h>
  59. /*====================================================================*
  60. * custom header files;
  61. *--------------------------------------------------------------------*/
  62. #include "../tools/getoptv.h"
  63. #include "../tools/putoptv.h"
  64. #include "../tools/number.h"
  65. #include "../tools/format.h"
  66. #include "../tools/error.h"
  67. #include "../tools/flags.h"
  68. /*====================================================================*
  69. * custom source files;
  70. *--------------------------------------------------------------------*/
  71. #ifndef MAKEFILE
  72. #include "../tools/getoptv.c"
  73. #include "../tools/putoptv.c"
  74. #include "../tools/version.c"
  75. #include "../tools/error.c"
  76. #include "../tools/uintspec.c"
  77. #include "../tools/todigit.c"
  78. #include "../tools/output.c"
  79. #endif
  80. #ifndef MAKEFILE
  81. #include "../mme/MMEName.c"
  82. #include "../mme/MMEMode.c"
  83. #endif
  84. #include "../mme/MMECode.c"
  85. /*====================================================================*
  86. * program constants;
  87. *--------------------------------------------------------------------*/
  88. #define MME_VERBOSE (1 << 0)
  89. #define MME_SILENCE (1 << 1)
  90. #define MME_TOCSV (1 << 2)
  91. #define MME_TOHTML (1 << 3)
  92. /*====================================================================*
  93. *
  94. * int main (int argc, char * argv[]);
  95. *
  96. * print vendor-specific message codes and names with associated
  97. * error codes and text on stdout; output options are HTML, CSV
  98. * and plain text;
  99. *
  100. *
  101. *--------------------------------------------------------------------*/
  102. #define DEFAULT_COLUMN 40
  103. int main (int argc, char const * argv [])
  104. {
  105. static char const * optv [] =
  106. {
  107. "cht:",
  108. PUTOPTV_S_DIVINE,
  109. "Atheros vendor-specific message enumerator",
  110. "c\toutput CSV table",
  111. "h\toutput HTML table",
  112. "t n\ttab to column (n) [" LITERAL (DEFAULT_COLUMN) "]",
  113. (char const *) (0)
  114. };
  115. signed column = DEFAULT_COLUMN;
  116. signed index;
  117. uint16_t type;
  118. flag_t flags = (flag_t)(0);
  119. signed c;
  120. optind = 1;
  121. while ((c = getoptv (argc, argv, optv)) != -1)
  122. {
  123. switch ((char) (c))
  124. {
  125. case 'c':
  126. _setbits (flags, MME_TOCSV);
  127. break;
  128. case 'h':
  129. _setbits (flags, MME_TOHTML);
  130. break;
  131. case 't':
  132. column = (signed)(uintspec (optarg, 0, 255));
  133. default:
  134. break;
  135. }
  136. }
  137. argc -= optind;
  138. argv += optind;
  139. if (argc)
  140. {
  141. error (1, ENOTSUP, ERROR_TOOMANY);
  142. }
  143. if (_anyset (flags, MME_TOHTML))
  144. {
  145. signed margin = 2;
  146. output (margin++, "<table class='mme'>");
  147. output (margin++, "<tr class='mme'>");
  148. output (margin, "<th class='type'>Type</th>");
  149. output (margin, "<th class='name'>Name</th>");
  150. output (margin, "<th class='code'>Code</th>");
  151. output (margin, "<th class='text'>Text</th>");
  152. output (margin--, "</tr>");
  153. for (index = 0; index < (signed)(SIZEOF (mme_codes)); index++)
  154. {
  155. type = mme_codes [index].type;
  156. output (margin++, "<tr class='mme'>");
  157. output (margin, "<td class='type'>0x%04X</td>", type);
  158. output (margin, "<td class='name'>%s.%s</td>", MMEName (type), MMEMode (type));
  159. output (margin, "<td class='code'>0x%02X</td>", mme_codes [index].code);
  160. output (margin, "<td class='text'>%s</td>", mme_codes [index].text);
  161. output (margin--, "</tr>");
  162. }
  163. output (margin--, "</table>");
  164. return (0);
  165. }
  166. if (_anyset (flags, MME_TOCSV))
  167. {
  168. printf ("Name,Type,Code,Text\n");
  169. for (index = 0; index < (signed)(SIZEOF (mme_codes)); index++)
  170. {
  171. type = mme_codes [index].type;
  172. printf ("0x%04X,", type);
  173. printf ("%s.%s,", MMEName (type), MMEMode (type));
  174. printf ("0x%02X,", mme_codes [index].code);
  175. printf ("\"%s\"\n", mme_codes [index].text);
  176. }
  177. return (0);
  178. }
  179. for (index = 0; index < (signed)(SIZEOF (mme_codes)); index++)
  180. {
  181. signed indent = column;
  182. type = mme_codes [index].type;
  183. indent -= printf ("0x%04X ", type);
  184. indent -= printf ("%s.%s ", MMEName (type), MMEMode (type));
  185. while (indent-- > 0)
  186. {
  187. putc (' ', stdout);
  188. }
  189. printf ("0x%02X ", mme_codes [index].code);
  190. printf ("\"%s\"\n", mme_codes [index].text);
  191. }
  192. return (0);
  193. }