int main (int argc, char const * argv []) { static char const * optv [] = { "c:w:x", PUTOPTV_S_FILTER, "extend FORTRAN style comment bars", "c c\tcomments start with character c [" LITERAL (FBAR_START) "]", "w n\tbar width is (n) [" LITERAL (FBAR_WIDTH) "]", "x\tmake file executable", (char const *) (0) }; flag_t flags = (flag_t) (0); size_t length = _LINESIZE; size_t width = FBAR_WIDTH; char start = FBAR_START; char space = FBAR_SPACE; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'c': start = (char) (* optarg); break; case 'x': _setbits (flags, FBAR_EXECUTE); break; case 'w': width = uintspec (optarg, 0, length); break; default: break; } } argc -= optind; argv += optind; if (!argc) { function (start, space, width, length, flags); } while ((argc) && (* argv)) { if (vfopen (* argv)) { function (start, space, width, length, flags); if (_anyset (flags, FBAR_EXECUTE)) { if (chmod (* argv, 0755)) { error (0, errno, "can't chmod %s", * argv); } } } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "clear screen and position cursor", PUTOPTV_S_FUNNEL, "tmb", "t\ttop of screen", "m\tmiddle of screen", "b\tbottom of screen", (char const *) (0) }; unsigned line; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 't': line = 0; break; case 'm': line = VT_LINES >> 1; break; case 'b': line = VT_LINES; break; default: break; } } fprintf (stderr, "\033[2J\033[%2d;1H", line); exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "", "", "Template Program", (char const *) (0) }; signed c; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { default: break; } } argc -= optind; argv += optind; if (!argc) { function (); } while ((argc) && (* argv)) { function (); argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "prepend/append prefix/suffix to multiple files", PUTOPTV_S_FILTER, "p:qs:v", "p s\tprefix file is (s)", "q\tquiet mode", "s s\tsuffix file is (s)", "v\tverbose mode", (char const *) (0) }; flag_t flags = (flag_t) (0); signed length = 1024; signed prefix = -1; signed suffix = -1; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'h': if ((prefix = open (optarg, O_RDONLY)) == -1) { error (1, errno, "%s", optarg); } break; case 'f': if ((suffix = open (optarg, O_RDONLY)) == -1) { error (1, errno, "%s", optarg); } break; case 'q': _setbits (flags, PREAMBLE_SILENCE); break; case 'v': _setbits (flags, PREAMBLE_VERBOSE); break; } } argc -= optind; argv += optind; if (! argc) { function (prefix, suffix, length); } while ((argc) && (* argv)) { if (vfopen (* argv)) { function (prefix, suffix, length); } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "", PUTOPTV_S_DIVINE, "Atheros Ethernet Interface Enumerator", (char const *) (0) }; signed c; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ECANCELED, ERROR_TOOMANY); } enumerate (); return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "imqrv", "file [file] [...]", "Qualcomm Atheros PLC Image File Validator", "i\tprint firmware identity string", "m\tdisplay manifest", "q\tsuppress messages", "r\tprint firmware revision string", "v\tverbose messages", (char const *) (0) }; flag_t flags = (flag_t)(0); signed state = 0; signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'i': _setbits (flags, NVM_IDENTITY); break; case 'm': _setbits (flags, NVM_MANIFEST); break; case 'r': _setbits (flags, NVM_FIRMWARE); break; case 'q': _setbits (flags, NVM_SILENCE); break; case 'v': _setbits (flags, NVM_VERBOSE); break; default: break; } } argc -= optind; argv += optind; while ((argc) && (* argv)) { if (chknvm (* argv, flags)) { state = 1; } else if (_allclr (flags, (NVM_VERBOSE|NVM_SILENCE|NVM_MANIFEST|NVM_FIRMWARE|NVM_IDENTITY))) { printf ("%s looks good\n", * argv); } argc--; argv++; } return (state); }
int main (int argc, const char * argv []) { static const char * optv [] = { "b:l:qs:uv", PUTOPTV_S_FUNNEL, "Atheros device password generator", "b n\tbunching factor [" LITERAL (DEFAULT_GROUP) "]", "l n\tpassword letters [" LITERAL (DEFAULT_COUNT) "]", "q\tomit device address on output", "v\tprepend PTS flag on output", (const char *)(0) }; unsigned count = DEFAULT_COUNT; unsigned group = DEFAULT_GROUP; unsigned space = '-'; flag_t flags = (flag_t)(0); signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char)(c)) { case 'b': group = (unsigned)(uintspec (optarg, 0, UCHAR_MAX)); break; case 'l': count = (unsigned)(uintspec (optarg, 12, 64)); break; case 'q': _setbits (flags, PASSWORD_SILENCE); break; case 'u': case 'v': _setbits (flags, PASSWORD_VERBOSE); break; default: break; } } argc -= optind; argv += optind; if (!argc) { function ("stdin", count, group, space, flags); } while ((argv) && (* argv)) { if (!freopen (* argv, "rb", stdin)) { error (1, EINVAL, "Can't open %s", * argv); } function (* argv, count, group, space, flags); argc--; argv++; } return (0); }
int main (int argc, char const * argv []) { extern FIND find; static char const * optv [] = { "convert pkgconfig dependency information to CSV dependency format", PUTOPTV_S_DIVINE, "rb", "r\trecursive search", (char const *) (0) }; char const * paths [MAX_PATHS]; char * buffer = (char *) (0); size_t index; flag_t flags = (flag_t) (0); signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'r': _setbits (find.flagword, FIND_B_RECURSE); break; default: break; } } argc -= optind; argv += optind; if (! argc) { buffer = strdup (getenv ("PKG_CONFIG_PATH")); strsplit (paths, MAX_PATHS, buffer, PATH_C_SEPARATOR); for (index = 0; paths [index] != (char const *) (0); index++) { strcpy (find.fullname, paths [index]); strcpy (find.wildcard, "*.pc"); find.pathname [0] = (char) (0); find.filename [0] = (char) (0); find.basename [0] = (char) (0); find.extender [0] = (char) (0); findfile (& find, flags); } } while ((argc) && (* argv)) { strcpy (find.fullname, * argv); strcpy (find.wildcard, "*.pc"); find.pathname [0] = (char) (0); find.filename [0] = (char) (0); find.basename [0] = (char) (0); find.extender [0] = (char) (0); findfile (& find, flags); argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "align character to column", PUTOPTV_S_FILTER, "a:b:c:t:", "a n\tafter column (n)", "b n\tbefore column (n)", "c c\talignment character (c)", "t n\talignment column (n)", (char const *) (0) }; unsigned minimum = 0; unsigned maximum = -1; unsigned character = 0; unsigned column = 0; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'a': minimum = uintspec (optarg, 0, SHRT_MAX); break; case 'b': maximum = uintspec (optarg, 0, SHRT_MAX); break; case 'c': character = * optarg; break; case 't': column = uintspec (optarg, 0, SHRT_MAX); break; default: break; } } argc -= optind; argv += optind; if (! argc) { function (minimum, maximum, column, character); } while ((argc) && (* argv)) { if (vfopen (* argv)) { function (minimum, maximum, column, character); } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "cdst", PUTOPTV_S_FUNNEL, "enumerate html/xhtml/xml document fragments", "c\tprint CSS stylesheet on stdout", "d\tprint document as text", "s\tprint document as stream", "t\tprint document as tree", (char const *)(0) }; struct node node; void (* xmldump) (struct node const *) = xmlindent; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'c': xmldump = csstree; break; case 'd': xmldump = xmlindent; break; case 's': xmldump = xmlstream; break; case 't': xmldump = xmltree; break; default: break; } } argc -= optind; argv += optind; if (!argc) { error (1, ENOTSUP, "No filenames given!"); } while ((argc) && (* argv)) { xmlread (& node, * argv); xmlscan (& node); reorder (& node); xmldump (& node); xmlfree (& node); argc--; argv++; } return (0); }
int main (int argc, const char * argv []) { static const char * optv [] = { "b:l:n:quv", "address [address] [...]", "Atheros device password generator", "b n\tbunching factor [" LITERAL (DEFAULT_GROUP) "]", "l n\tpassword letters [" LITERAL (DEFAULT_COUNT) "]", "n n\tgenerate n consecutive passwords [" LITERAL (DEFAULT_RANGE) "]", "q\tomit device address on output", "v\tprepend PTS flag on output", (const char *)(0) }; uint32_t range = DEFAULT_RANGE; unsigned count = DEFAULT_COUNT; unsigned group = DEFAULT_GROUP; unsigned space = '-'; flag_t flags = (flag_t)(0); signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char)(c)) { case 'b': group = (unsigned)(uintspec (optarg, 0, UCHAR_MAX)); break; case 'l': count = (unsigned)(uintspec (optarg, 12, 64)); break; case 'n': range = (uint32_t)(uintspec (optarg, 0, 0x00FFFFFF)); break; case 'q': _setbits (flags, PASSWORD_SILENCE); break; case 'v': _setbits (flags, PASSWORD_VERBOSE); break; default: break; } } argc -= optind; argv += optind; while ((argv) && (* argv)) { function (* argv, range, count, group, space, flags); argc--; argv++; } return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "f:qv", "pib-file [pib-file] [...]", "Qualcomm Atheros PLC Parameter File Editor", "f f\txmlfile is (f)", "q\tquiet", "v\tverbose", (char const *) (0) }; struct node * node = (struct node *)(0); flag_t flags = (flag_t)(0); signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 'f': node = xmlopen (optarg); break; case 'm': _setbits (flags, PIB_MANIFEST); break; case 'q': _setbits (flags, PIB_SILENCE); break; case 'v': _setbits (flags, PIB_VERBOSE); break; default: break; } } argc -= optind; argv += optind; while ((argc) && (* argv)) { function (* argv, node); argc--; argv++; } if (_anyset (flags, PIB_VERBOSE)) { xmltree (node); } xmlfree (node); return (0); }
int main (int argc, char const * argv []) { extern signed order; static char const * optv [] = { "b:dl:", PUTOPTV_S_FILTER, "sort files", "b n\tmaximum sort block is (n) lines [0x1000]", "d\tarrange output in descending order", "l n\tmaximum line length is (n) bytes [0x0400]", (char const *) (0) }; size_t heapsize = _HEAPSIZE; size_t linesize = _LINESIZE; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'd': order = - 1; break; case 'b': heapsize = uintspec (optarg, 1, UINT_MAX); break; case 'l': linesize = uintspec (optarg, 1, UINT_MAX); break; default: break; } } argc -= optind; argv += optind; if (!argc) { function (heapsize, linesize); } while ((argc) && (* argv)) { if (vfopen (* argv)) { function (heapsize, linesize); } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "l:w:", PUTOPTV_S_FUNNEL, "copy one or more file headers to stdout", "l n\tdisplay line count is (n) [" LITERAL (VT_LINES) "]", "w n\tdisplay line width is (n) [" LITERAL (VT_LIMIT) "]", (char const *)(0) }; unsigned lines = VT_LINES; unsigned width = VT_LIMIT; signed c; getviewport (& lines, & width); lines--; lines--; width--; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'l': lines = uintspec (optarg, 1, SHRT_MAX); break; case 'w': width = uintspec (optarg, 1, SHRT_MAX); break; default: break; } } argc -= optind; argv += optind; if (!argc) { function (lines, width); } while ((argc) && (* argv)) { if (efreopen (* argv, "rb", stdin)) { function (lines, width); } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "", "pibfile [< scalers]", "load prescalers into int6000 and qca7000 parameter file", (char const *) (0) }; struct _file_ pib; signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { default: break; } } argc -= optind; argv += optind; if (argc > 1) { error (1, ECANCELED, "Only one target file allowed"); } if ((argc) && (* argv)) { pib.name = * argv; if ((pib.file = open (pib.name, O_BINARY|O_RDWR)) == -1) { error (1, errno, "Can't open %s", pib.name); } else if (pibfile (&pib)) { error (1, errno, "Bad PIB file: %s", pib.name); } else if (psin (&pib)) { error (1, ECANCELED, "%s", pib.name); } else if (piblock (&pib)) { error (1, ECANCELED, "%s", pib.name); } close (pib.file); } return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "qv", "file [file] [...] [> file]", "Qualcomm Atheros PLC Firmware Image File Splicer", "q\tsuppress messages", "v\tverbose messages", (char const *) (0) }; flag_t flags = (flag_t)(0); signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'q': _setbits (flags, NVM_SILENCE); break; case 'v': _setbits (flags, NVM_VERBOSE); break; default: break; } } argc -= optind; argv += optind; #ifdef WIN32 setmode (fileno (stdin), O_BINARY); setmode (fileno (stdout), O_BINARY); #endif while ((argc) && (* argv)) { function (* argv, argc-1, flags); argv++; argc--; } return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "cl:qv", "", "Atheros UART Device Detector", "c\tassume device is in command mode", "l f\tserial port is (f) [" SERIAL_PORT "]", "q\tquiet mode", "v\tverbose mode", (char const *) (0) }; signed c; char const *line = SERIAL_PORT; struct serial serial; struct serial_mode serial_mode; flag_t flags = 0; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'c': _setbits (flags, INT6KDETECT_CMD_MODE); break; case 'l': line = optarg; break; case 'q': _setbits (flags, INT6KDETECT_QUIET); break; default: break; } } argc -= optind; argv += optind; if (open_serial (line, &serial) == -1) error (1, errno, "could not open %s", line); if (detect (&serial, &serial_mode, flags) == -1) error (1, 0, "could not detect device"); printf ("Detected the following serial mode:\n"); dump_serial_mode (&serial_mode); close_serial (&serial); return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "copy one or more files to stdout", PUTOPTV_S_FUNNEL, "b:u", "b n\tbuffer size is (n) bytes [" LITERAL (BUFFERSIZE) "]", "u\tunbuffered copy", (char const *) (0) }; signed length = BUFFERSIZE; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'b': length = uintspec (optarg, 1, SHRT_MAX); break; case 'u': length = 1; break; default: break; } } argc -= optind; argv += optind; if (! argc) { function (length); } while ((argc) && (* argv)) { if (efreopen (* argv, "rb", stdin)) { function (length); } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "hqv", "", "enumerate available pcap devices on stdout", "h\tprint host definitions for scripting", "q\tquiet", "v\tverbose messages", (char const *) (0) }; flag_t flags = PCAP_DEVICES; signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'h': _clrbits (flags, (PCAP_DEVICES)); _setbits (flags, (PCAP_NICS | PCAP_MACS)); break; case 'q': _setbits (flags, PCAP_SILENCE); break; case 'v': _setbits (flags, PCAP_VERBOSE); break; default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ECANCELED, ERROR_TOOMANY); } pcap_enum (flags); return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "convert hex dump files to hex file", PUTOPTV_S_FUNNEL, "w:", "w n\twidth is (n) characters [" LITERAL (WIDTH) "]", (char const *) (0) }; unsigned width = WIDTH; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'w': width = (unsigned) (uintspec(optarg, 2, 256)); break; default: break; } } argc -= optind; argv += optind; if (! argc) { function (getc (stdin), width); } while ((argc) && (* argv)) { if (! freopen (* argv, "rb", stdin)) { error (1, errno, "%s", * argv); } function (getc (stdin), width); argc--; argv++; } return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "w", PUTOPTV_S_FUNNEL, "print difference between consecutive unsigned decimal integers", "w n\twidth in digits is (n) [" LITERAL (DIGITS) "]", (char const *)(0) }; unsigned width = DIGITS; flag_t flags = (flag_t)(0); signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'w': width = (unsigned)(uintspec (optarg, 1, 16)); default: break; } } argc -= optind; argv += optind; if (!argc) { function ("stdin", width, flags); } while ((argc) && (* argv)) { if (efreopen (* argv, "rb", stdin)) { function (* argv, width, flags); } argc--; argv++; } return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "n:", "path [path] [...] [> stdout]", "print folder hierarchy on stdout", "n n\tshow n levels [" LITERAL (DEPTH) "]", (char const *) (0) }; char filename [FILENAME_MAX]; unsigned depth = DEPTH; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'n': depth = (unsigned)(uintspec (optarg, 1, FILE_DIR_MAX)); break; default: break; } } argc -= optind; argv += optind; if (!argc) { strcpy (filename, getenv ("PWD")); function (filename, filename, depth); } while ((argc) && (* argv)) { strcpy (filename, * argv); function (filename, filename, depth); argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "C/C++ language blocker", PUTOPTV_S_FILTER, "p", "p\tinsert empty function preambles", (char const *) (0) }; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'p': level = 0; break; default: break; } } argc -= optind; argv += optind; if (! argc) { program (NUL, EOF); } while ((argc) && (* argv)) { if (vfopen (* argv)) { program (NUL, EOF); } argc--; argv++; } return (0); }
int main (int argc, char const * argv []) { extern struct channel channel; static char const * optv [] = { "qt:v", PUTOPTV_S_DIVINE, "Atheros Ethernet Interface Enumerator", (char const *) (0) }; struct nic nics [16]; unsigned size = hostnics (nics, sizeof (nics) / sizeof (struct nic)); signed c; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 'q': _setbits (channel.flags, CHANNEL_SILENCE); break; case 't': channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX)); break; case 'v': _setbits (channel.flags, CHANNEL_VERBOSE); break; default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ENOTSUP, ERROR_TOOMANY); } enumerate (&channel, nics, size); return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "print a simple sign on stdout", PUTOPTV_S_DIVINE, "c:w:", "c c\tfill character is c [\'c\']", "w n\tpage width is n [78]", (char const *) (0) }; char o = '#'; size_t width = 78; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'c': o = * optarg; break; case 'w': width = uintspec (optarg, 1, UCHAR_MAX); break; default: break; } } argc -= optind; argv += optind; while ((argc) && (* argv)) { signf (* argv, o, width); argc--; argv++; } exit (0); }
int main (int argc, char const *argv []) { static char const *optv [] = { "h", "findspec [ findspec [ ... ] ] [> stdout]", "demonstrate pathname expansion function, findpath() ", "h\thelp summary ", NULL }; struct _find_ find; // signed argn; signed c; optind = 1; opterr = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case ':': exit (1); case '?': exit (1); default: break; } } argc -= optind; argv += optind; while ((argc-- > 0) && (*argv != (char *)(0))) { makefind (&find, *argv++, FIND_M_NORMAL); showfind (&find, stdout); } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "", PUTOPTV_S_FILTER, "include all C language support files", (char const *) (0) }; char pathname [FILENAME_MAX]; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { default: break; } } argc -= optind; argv += optind; while ((argc) && (* argv)) { char const * vector [200]; makepath (pathname, getenv ("PWD"), * argv); vector [0] = strdup (pathname); vector [1] = (char *)(0); function (pathname, vector); for (argc = 0; vector [argc]; argc++) { fprintf (stderr, "%s\n", vector [argc]); } argc--; argv++; } exit (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "", PUTOPTV_S_FUNNEL, "hexadecimal to binary file concatenate", (char const *)(0) }; signed c; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { default: break; } } argc -= optind; argv += optind; if (!argc) { function ("standard input"); } while ((argc) && (* argv)) { if (!freopen (* argv, "rb", stdin)) { error (1, errno, "%s", * argv); } function (* argv); argc--; argv++; } return (0); }
int main (int argc, char const * argv []) { extern signed c; static char const * optv [] = { "", PUTOPTV_S_FUNNEL, "example command line program", (char const *) (0) }; TREE * node = (TREE *) (0); optind = 1; opterr = 1; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { default: break; } } argc -= optind; argv += optind; while (~ (c = odcl::grab (STDIN_FILENO))) { node = odcl::line (); if ((c != ';') && (c != EOF)) { edl::error (1, 0, odcl::format, c, ';'); } odcl::tree (node); odcl::free (node); } return (0); }
int main (int argc, const char * argv []) { extern struct channel channel; static const char *optv [] = { "C:i:eFN:p:P:qt:vx", "-C file -P file -N file", "Atheros Powerline Device Flash Utility for INT6300", "C f\twrite CFG file to device using VS_SET_SDRAM", "e\tredirect stderr messages to stdout", #if defined (WINPCAP) || defined (LIBPCAP) "i n\thost interface number [2]", #else "i s\thost interface name [" CHANNEL_ETHDEVICE "]", #endif "F[F]\tflash [force] NVRAM after firmware start using VS_MOD_NVM", "N f\twrite NVM file to device using VS_WR_MEM", "P f\twrite PIB file to device using VS_WR_MEM", "q\tquiet mode", #if defined (WINPCAP) || defined (LIBPCAP) "t n\tread capture time is (n) milliseconds [50]", #else "t n\tread timeout is (n) milliseconds [50]", #endif "v\tverbose mode", "x\texit on error", (const char *) (0) }; #include "../plc/plc.c" char firmware [PLC_VERSION_STRING]; signed c; if (getenv (PLCDEVICE)) { #if defined (WINPCAP) || defined (LIBPCAP) channel.ifindex = atoi (getenv (PLCDEVICE)); #else channel.ifname = strdup (getenv (PLCDEVICE)); #endif } optind = 1; opterr = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'i': #if defined (WINPCAP) || defined (LIBPCAP) channel.ifindex = atoi (optarg); #else channel.ifname = optarg; #endif break; case 'q': _setbits (channel.flags, CHANNEL_SILENCE); break; case 't': channel.timeout = (unsigned)(uintspec (optarg, 0, UINT_MAX)); break; case 'v': _setbits (channel.flags, CHANNEL_VERBOSE); break; } } openchannel (&channel); desuid (); optind = 1; opterr = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'C': if (!checkfilename (optarg)) { error (1, EINVAL, "%s", optarg); } if ((plc.CFG.file = open (optarg, O_BINARY|O_RDONLY)) == -1) { error (1, errno, "%s", optarg); } if (sdramfile (plc.CFG.file, optarg, plc.flags)) { error (1, ECANCELED, "CFG file %s is corrupt", optarg); } _setbits (plc.flags, PLC_SDRAM_CONFIG); plc.CFG.name = optarg; break; case 'e': dup2 (STDOUT_FILENO, STDERR_FILENO); break; case 'F': _setbits (plc.module, PLC_MODULE_NVM_PIB); if (_anyset (plc.flags, PLC_FLASH_DEVICE)) { _setbits (plc.module, VS_MODULE_FORCE); } _setbits (plc.flags, PLC_FLASH_DEVICE); break; case 'N': if (!checkfilename (optarg)) { error (1, EINVAL, "%s", optarg); } if ((plc.NVM.file = open (optarg, O_BINARY|O_RDONLY)) == -1) { error (1, errno, "%s", optarg); } plc.NVM.name = optarg; if (nvmfile1 (&plc.NVM)) { error (1, errno, "Bad firmware file: %s", plc.NVM.name); } _setbits (plc.flags, PLC_WRITE_MAC); break; case 'P': if (!checkfilename (optarg)) { error (1, EINVAL, "%s", optarg); } if ((plc.PIB.file = open (optarg, O_BINARY|O_RDONLY)) == -1) { error (1, errno, "%s", optarg); } plc.PIB.name = optarg; if (pibfile1 (&plc.PIB)) { error (1, errno, "Bad parameter file: %s", plc.PIB.name); } _setbits (plc.flags, PLC_WRITE_PIB); break; case 'q': _setbits (plc.flags, PLC_SILENCE); break; case 'v': _setbits (plc.flags, PLC_VERBOSE); break; case 'x': _setbits (plc.flags, PLC_BAILOUT); break; default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ECANCELED, "Too many arguments"); } if (plc.CFG.file == -1) { error (1, ECANCELED, "No CFG file specified"); } if (plc.PIB.file == -1) { error (1, ECANCELED, "No PIB file specified"); } if (plc.NVM.file == -1) { error (1, ECANCELED, "No NVM file specified"); } if (!(plc.message = malloc (sizeof (struct message)))) { error (1, errno, PLC_NOMEMORY); } if (WaitForStart (&plc, firmware, sizeof (firmware))) { Failure (&plc, "Device must be connected"); return (-1); } if (plc.hardwareID > CHIPSET_INT6300) { Failure (&plc, "Device must be %s or earlier; try using int6kboot.", chipsetname (CHIPSET_INT6300)); return (-1); } if (strcmp (firmware, "BootLoader")) { Failure (&plc, "Bootloader must be running"); return (-1); } if (!StartDevice1 (&plc)) { if (_anyset (plc.flags, PLC_FLASH_DEVICE)) { UpgradeDevice1 (&plc); } } free (plc.message); closechannel (&channel); exit (0); }