From owner-freebsd-arch@FreeBSD.ORG Fri Aug 15 19:42:45 2014 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B75AC690 for ; Fri, 15 Aug 2014 19:42:45 +0000 (UTC) Received: from smtp9.server.rpi.edu (smtp9.server.rpi.edu [128.113.2.229]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 839A22162 for ; Fri, 15 Aug 2014 19:42:45 +0000 (UTC) Received: from smtp-auth1.server.rpi.edu (route.canit.rpi.edu [128.113.2.231]) by smtp9.server.rpi.edu (8.14.3/8.14.3/Debian-9.4) with ESMTP id s7FJghWB026418 for ; Fri, 15 Aug 2014 15:42:43 -0400 Received: from smtp-auth1.server.rpi.edu (localhost [127.0.0.1]) by smtp-auth1.server.rpi.edu (Postfix) with ESMTP id AC7FA580DE for ; Fri, 15 Aug 2014 15:42:43 -0400 (EDT) Received: from [128.113.24.47] (gilead-qc124.netel.rpi.edu [128.113.124.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: drosih) by smtp-auth1.server.rpi.edu (Postfix) with ESMTPSA id 9DF2A580CD for ; Fri, 15 Aug 2014 15:42:43 -0400 (EDT) From: "Garance A Drosehn" To: arch@freebsd.org Subject: Re: XML Output: libxo - provide single API to output TXT, XML, JSON and HTML Date: Fri, 15 Aug 2014 15:42:41 -0400 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailer: MailMate (1.7.2r3905) X-Virus-Scanned: ClamAV using ClamSMTP X-Bayes-Prob: 0.0001 (Score 0, tokens from: outgoing, @@RPTN) X-Spam-Score: 0.00 () [Hold at 15.10] X-CanIt-Incident-Id: 02MD7GHts X-CanIt-Geo: ip=128.113.124.17; country=US; region=New York; city=Troy; latitude=42.7495; longitude=-73.5951; http://maps.google.com/maps?q=42.7495,-73.5951&z=6 X-CanItPRO-Stream: outgoing X-Canit-Stats-ID: Bayes signature not available X-Scanned-By: CanIt (www . roaringpenguin . com) on 128.113.2.229 X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 19:42:45 -0000 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 #include #include #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