XML Output: libxo - provide single API to output TXT, XML, JSON and HTML

Garance A Drosehn drosih at rpi.edu
Fri Aug 15 19:42:45 UTC 2014


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 at rpi.edu
Senior Systems Programmer               or   gad at FreeBSD.org
Rensselaer Polytechnic Institute;             Troy, NY;  USA


More information about the freebsd-arch mailing list