Date: Fri, 15 Aug 2014 15:42:41 -0400 From: "Garance A Drosehn" <drosih@rpi.edu> To: arch@freebsd.org Subject: Re: XML Output: libxo - provide single API to output TXT, XML, JSON and HTML Message-ID: <5B031AE6-100F-4AD7-B721-F0FF207CAE3E@rpi.edu> In-Reply-To: <53ED578B.6070205@freebsd.org> References: <20140814052648.GM2737@kib.kiev.ua> <201408140606.s7E66XXA091972@idle.juniper.net> <20140814085257.GN2737@kib.kiev.ua> <201408140847.00573.jhb@freebsd.org> <94A47A7D-89C9-4504-B669-2A5EDA80373B@bsdimp.com> <53ED578B.6070205@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 14 Aug 2014, at 20:42, Alfred Perlstein wrote: > On 8/14/14 9:13 AM, Warner Losh wrote: >> My question for people advocating this method: Why not require all >> commands >> that generate this kind of output to support a standard command line >> option >> that causes the command to print nothing and return 0 if it supports >> reporting, >> or anything else if it doesn’t (return 0 with output, or return >> non-zero with or without >> output). This would handle the more complicated implementation issues >> with using >> DT_NEEDED and/or the ELF note, be more in line with how things are >> traditionally >> done, and offer greater flexibility of implementation. >> >> Warner > This is a decent idea, however the problem is firstly that most > short-opts are taken, second issue is that adding getopt_long to a > whole slew of programs will make the effort take a long time. It's > really better to limit scope of this such that we are just making > machine readable output. > > -Alfred [-- try #2 with this reply. arg. --] In the case of adding just one long option, you don't have to add getopt_long() to any programs. The main program would only need: /* - - - - - - - - - - - - - - - - - - - */ /* Apologies if my email client totally mangles the following source */ #include <stdarg.h> #include <stdio.h> #include <string.h> #define COMMON_LONG_ARG "-—supports-xml" int main(int argc, char **argv) { /* note this whole check could be a macro pulled from some * include file */ if (argc == 2) { argv++; if (0 == strcmp(*argv, COMMON_LONG_ARG)) { return (0); } } printf("... Standard processing of %d arguments...\n", argc); /* I'm returning "1" here to mimic what would happen * in a command which did *not* have the above check. */ return (1); } /* - - - - - - - - - - - - - - - - - - - */ I think we could do better than the suggestion Warner gave, but his suggestion is pretty trivial to implement. It gets a little messier if we want to support multiple xo-related parameters, but again we could put all that standard processing in a library subroutine, and each program which has libxo would call that standard libxo-options routine before calling anything else in the unix command. -- Garance Alistair Drosehn = drosih@rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5B031AE6-100F-4AD7-B721-F0FF207CAE3E>