From owner-svn-src-head@freebsd.org Thu Apr 21 05:24:49 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 30D7CB16BC9; Thu, 21 Apr 2016 05:24:49 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E224F1E70; Thu, 21 Apr 2016 05:24:48 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3L5OmMj038341; Thu, 21 Apr 2016 05:24:48 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3L5Ol00038339; Thu, 21 Apr 2016 05:24:47 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201604210524.u3L5Ol00038339@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Thu, 21 Apr 2016 05:24:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298388 - head/usr.bin/units X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2016 05:24:49 -0000 Author: eadler Date: Thu Apr 21 05:24:47 2016 New Revision: 298388 URL: https://svnweb.freebsd.org/changeset/base/298388 Log: Bring a little more compability with GNU units 2.12 - notionally support a 'history file' flag. This doesn't do much now, but is there to prevent scripts written against GNU units from breaking - correctly gracefully quit rather than exit (this will make it easier to support a history file in the future) - remove the "t" flag from fopen which was there to support windows. We have not supported windows since at the latest, the introduction of capsicum. Modified: head/usr.bin/units/units.1 head/usr.bin/units/units.c Modified: head/usr.bin/units/units.1 ============================================================================== --- head/usr.bin/units/units.1 Thu Apr 21 04:33:07 2016 (r298387) +++ head/usr.bin/units/units.1 Thu Apr 21 05:24:47 2016 (r298388) @@ -8,6 +8,7 @@ .Sh SYNOPSIS .Nm .Op Fl f Ar filename +.Op Fl H Ar filename .Op Fl qvUV .Op Ar from-unit to-unit .Sh OPTIONS @@ -17,6 +18,8 @@ The following options are available: Show an overview of options .It Fl f Ar filename No , Fl -file Ar filename Specify the name of the units data file to load. +.It Fl H Ar filename No , Fl -historyfile Ar filename +Ignored, for compatibility with GNU units. .It Fl e , Fl -exponential Behave as if -o '%6e' was typed. .It Fl q No , Fl -quiet Modified: head/usr.bin/units/units.c ============================================================================== --- head/usr.bin/units/units.c Thu Apr 21 04:33:07 2016 (r298387) +++ head/usr.bin/units/units.c Thu Apr 21 05:24:47 2016 (r298388) @@ -33,10 +33,8 @@ static const char rcsid[] = #include -#define _PATH_UNITSLIB "/usr/share/misc/definitions.units" - #ifndef UNITSFILE -#define UNITSFILE _PATH_UNITSLIB +#define UNITSFILE "/usr/share/misc/definitions.units" #endif #define MAXUNITS 1000 @@ -47,6 +45,7 @@ static const char rcsid[] = #define PRIMITIVECHAR '!' static const char *powerstring = "^"; +static const char *numfmt = "%.8g"; static struct { char *uname; @@ -128,12 +127,12 @@ readunits(const char *userfile) linenum = 0; if (userfile) { - unitfile = fopen(userfile, "rt"); + unitfile = fopen(userfile, "r"); if (!unitfile) errx(1, "unable to open units file '%s'", userfile); } else { - unitfile = fopen(UNITSFILE, "rt"); + unitfile = fopen(UNITSFILE, "r"); if (!unitfile) { char *direc, *env; char filename[1000]; @@ -255,7 +254,7 @@ showunit(struct unittype * theunit) int printedslash; int counter = 1; - printf("%.8g", theunit->factor); + printf(numfmt, theunit->factor); if (theunit->offset) printf("&%.8g", theunit->offset); for (ptr = theunit->numerator; *ptr; ptr++) { @@ -723,7 +722,7 @@ static void usage(void) { fprintf(stderr, - "usage: units [-f unitsfile] [-UVq] [from-unit to-unit]\n"); + "usage: units [-f unitsfile] [-H historyfile] [-UVq] [from-unit to-unit]\n"); exit(3); } @@ -731,6 +730,7 @@ static struct option longopts[] = { {"help", no_argument, NULL, 'h'}, {"exponential", no_argument, NULL, 'e'}, {"file", required_argument, NULL, 'f'}, + {"history", required_argument, NULL, 'H'}, {"output-format", required_argument, NULL, 'o'}, {"quiet", no_argument, NULL, 'q'}, {"terse", no_argument, NULL, 't'}, @@ -749,15 +749,19 @@ main(int argc, char **argv) int optchar; bool quiet; bool readfile; + bool quit; History *inhistory; EditLine *el; HistEvent ev; int inputsz; + char const * history_file; quiet = false; readfile = false; - outputformat = "%.8g"; - while ((optchar = getopt_long(argc, argv, "+ehf:oqtvUV", longopts, NULL)) != -1) { + history_file = NULL; + outputformat = numfmt; + quit = false; + while ((optchar = getopt_long(argc, argv, "+ehf:oqtvHUV", longopts, NULL)) != -1) { switch (optchar) { case 'e': outputformat = "%6e"; @@ -769,6 +773,9 @@ main(int argc, char **argv) else readunits(optarg); break; + case 'H': + history_file = optarg; + break; case 'q': quiet = true; break; @@ -833,31 +840,41 @@ main(int argc, char **argv) if (!quiet) printf("%d units, %d prefixes\n", unitcount, prefixcount); - for (;;) { + while (!quit) { do { initializeunit(&have); if (!quiet) promptstr = "You have: "; havestr = el_gets(el, &inputsz); - if (havestr == NULL) - exit(0); + if (havestr == NULL) { + quit = true; + break; + } if (inputsz > 0) history(inhistory, &ev, H_ENTER, havestr); } while (addunit(&have, havestr, 0, 1) || completereduce(&have)); + if (quit) { + break; + } do { initializeunit(&want); if (!quiet) promptstr = "You want: "; wantstr = el_gets(el, &inputsz); - if (wantstr == NULL) - exit(0); + if (wantstr == NULL) { + quit = true; + break; + } if (inputsz > 0) history(inhistory, &ev, H_ENTER, wantstr); } while (addunit(&want, wantstr, 0, 1) || completereduce(&want)); + if (quit) { + break; + } showanswer(&have, &want); }