123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- /*====================================================================*
- *
- * Copyright (c) 2013 Qualcomm Atheros, Inc.
- *
- * All rights reserved.
- *
- *====================================================================*/
- /*====================================================================*
- *
- * mme.c - Qualcomm Atheros vendor-specific message code and name printer;
- *
- * print vendor-specific mesage codes and names and with associated
- * error codes and error text on stdout in various formats; options
- * are HTML, CSV and plain text;
- *
- * Contributor(s):
- * Charles Maier <cmaier@qca.qualcomm.com>
- *
- *--------------------------------------------------------------------*/
- /*====================================================================*
- * system header files;
- *--------------------------------------------------------------------*/
- #include <stdio.h>
- #include <errno.h>
- /*====================================================================*
- * custom header files;
- *--------------------------------------------------------------------*/
- #include "../tools/getoptv.h"
- #include "../tools/putoptv.h"
- #include "../tools/number.h"
- #include "../tools/format.h"
- #include "../tools/error.h"
- #include "../tools/flags.h"
- #include "../mme/mme.h"
- /*====================================================================*
- * custom source files;
- *--------------------------------------------------------------------*/
- #ifndef MAKEFILE
- #include "../tools/getoptv.c"
- #include "../tools/putoptv.c"
- #include "../tools/version.c"
- #include "../tools/error.c"
- #include "../tools/uintspec.c"
- #include "../tools/todigit.c"
- #include "../tools/output.c"
- #endif
- #ifndef MAKEFILE
- #include "../mme/MMEName.c"
- #include "../mme/MMEMode.c"
- #endif
- /*====================================================================*
- *
- *--------------------------------------------------------------------*/
- #include "../mme/MMECode.c"
- #include "../mme/MMESize.c"
- /*====================================================================*
- * program constants;
- *--------------------------------------------------------------------*/
- #define MME_VERBOSE (1 << 0)
- #define MME_SILENCE (1 << 1)
- #define MME_ORDER (1 << 2)
- #define MME_TOCSV (1 << 3)
- #define MME_TOHTML (1 << 4)
- #define MME_TOTEXT (1 << 5)
- #define MME_TOSIZE (1 << 6)
- #define DEFAULT_COLUMN 50
- #define DEFAULT_INDENT 2
- /*====================================================================*
- *
- * void mmetocsv ();
- *
- *
- *--------------------------------------------------------------------*/
- static void mmetocsv (void)
- {
- unsigned index;
- printf ("Name,Type,Code,Text\n");
- for (index = 0; index < SIZEOF (mme_codes); index++)
- {
- unsigned type = mme_codes [index].type;
- printf ("0x%04X,", type);
- printf ("%s.%s,", MMEName (type), MMEMode (type));
- printf ("0x%02X,", mme_codes [index].code);
- printf ("\"%s\"\n", mme_codes [index].text);
- }
- return;
- }
- /*====================================================================*
- *
- * void mmetohtml (signed margin);
- *
- *
- *--------------------------------------------------------------------*/
- static void mmetohtml (unsigned margin)
- {
- unsigned index;
- output (margin++, "<table class='mme'>");
- output (margin++, "<tr class='mme'>");
- output (margin, "<th class='type'>Type</th>");
- output (margin, "<th class='name'>Name</th>");
- output (margin, "<th class='code'>Code</th>");
- output (margin, "<th class='text'>Text</th>");
- output (margin--, "</tr>");
- for (index = 0; index < SIZEOF (mme_codes); index++)
- {
- unsigned type = mme_codes [index].type;
- output (margin++, "<tr class='mme'>");
- output (margin, "<td class='type'>0x%04X</td>", type);
- output (margin, "<td class='name'>%s.%s</td>", MMEName (type), MMEMode (type));
- output (margin, "<td class='code'>0x%02X</td>", mme_codes [index].code);
- output (margin, "<td class='text'>%s</td>", mme_codes [index].text);
- output (margin--, "</tr>");
- }
- output (margin--, "</table>");
- return;
- }
- /*====================================================================*
- *
- * void mmetotext (void);
- *
- *
- *--------------------------------------------------------------------*/
- static void mmetotext (unsigned column)
- {
- unsigned index;
- for (index = 0; index < SIZEOF (mme_codes); index++)
- {
- signed indent = column;
- unsigned type = mme_codes [index].type;
- indent -= printf ("0x%04X ", type);
- indent -= printf ("%s.%s ", MMEName (type), MMEMode (type));
- while (indent-- > 0)
- {
- putc (' ', stdout);
- }
- printf ("0x%02X ", mme_codes [index].code);
- printf ("\"%s\"\n", mme_codes [index].text);
- }
- return;
- }
- /*====================================================================*
- *
- * int main (int argc, char * argv[]);
- *
- * print vendor-specific message codes and names with associated
- * error codes and text on stdout; output options are HTML, CSV
- * and plain text;
- *
- *--------------------------------------------------------------------*/
- int main (int argc, char const * argv [])
- {
- static char const * optv [] =
- {
- "chost",
- PUTOPTV_S_DIVINE,
- "Qualcomm Atheros vendor-specific message enumerator",
- "c\tprint CSV table on stdout",
- "h\tprint HTML table on stdout",
- "o\tcheck the order of MMECode table",
- "s\tprint frame size table on stdout",
- "t\tprint TEXT table on stdout",
- (char const *) (0)
- };
- unsigned column = DEFAULT_COLUMN;
- unsigned indent = DEFAULT_INDENT;
- flag_t flags = (flag_t) (0);
- signed c;
- optind = 1;
- while (~ (c = getoptv (argc, argv, optv)))
- {
- switch ((char) (c))
- {
- case 'c':
- _setbits (flags, MME_TOCSV);
- break;
- case 'h':
- _setbits (flags, MME_TOHTML);
- break;
- case 'o':
- _setbits (flags, MME_ORDER);
- break;
- case 's':
- _setbits (flags, MME_TOSIZE);
- break;
- case 't':
- _setbits (flags, MME_TOTEXT);
- break;
- default:
- break;
- }
- }
- argc -= optind;
- argv += optind;
- if (argc)
- {
- error (1, ENOTSUP, ERROR_TOOMANY);
- }
- if (_anyset (flags, MME_ORDER))
- {
- MMETest ();
- return (0);
- }
- if (_anyset (flags, MME_TOSIZE))
- {
- MMESize ();
- return (0);
- }
- if (_anyset (flags, MME_TOTEXT))
- {
- mmetotext (column);
- return (0);
- }
- if (_anyset (flags, MME_TOHTML))
- {
- mmetohtml (indent);
- return (0);
- }
- if (_anyset (flags, MME_TOCSV))
- {
- mmetocsv ();
- return (0);
- }
- mmetotext (column);
- return (0);
- }
|