#define VERSION "2.23"
/*
 *  units, a program for units conversion
 *  Copyright (C) 1996, 1997, 1999, 2000-2007, 2009, 2011-2020, 2022, 2024
 *  Free Software Foundation, Inc
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 *  Boston, MA 02110-1301 USA
 *     
 *  This program was written by Adrian Mariano (adrianm@gnu.org)
 */

#define LICENSE "\
Copyright (C) 2024 Free Software Foundation, Inc.\n\
GNU Units comes with ABSOLUTELY NO WARRANTY.\n\
You may redistribute copies of GNU Units\n\
under the terms of the GNU General Public License."

#define _XOPEN_SOURCE 600

#if defined (_WIN32) && defined (_MSC_VER)
# include <windows.h>
# include <winbase.h>
#endif
#if defined (_WIN32) && defined (HAVE_MKS_TOOLKIT)
# include <sys/types.h>
#endif
# include <sys/stat.h>

#include <ctype.h>
#include <float.h>

#include <stdio.h>
#include <signal.h>
#include <stdarg.h>
#include <time.h>

#if defined (_WIN32) && defined (_MSC_VER)
# include <io.h>
# define fileno _fileno
# define isatty _isatty
# define stat   _stat
#endif

#ifdef HAVE_IOCTL
#  include <sys/ioctl.h>
#  include <fcntl.h>
#endif

#ifndef NO_SETLOCALE
#  include<locale.h>
#endif

#ifdef SUPPORT_UTF8
/* Apparently this define is needed to get wcswidth() prototype */
#  include <wchar.h>
#  include <langinfo.h>
#  define UTF8VERSTR "with utf8"
#else
#  define UTF8VERSTR "without utf8"
#endif

#ifdef READLINE
#  define RVERSTR "with readline"
#  include <readline/readline.h>
#  include <readline/history.h>
#  define HISTORY_FILE ".units_history"
#else
#  define RVERSTR "without readline"
#endif

#include "getopt.h"
#include "units.h"

#ifndef UNITSFILE
#  define UNITSFILE "definitions.units"
#endif

#ifndef LOCALEMAP
#  define LOCALEMAP "locale_map.txt"
#endif

#ifndef DATADIR
#  ifdef _WIN32
#    define DATADIR   "..\\share\\units"
#  else
#    define DATADIR   "../share/units"
#  endif
#endif

#if defined (_WIN32) && defined (_MSC_VER)
#  include <direct.h>
#  define getcwd _getcwd
#else
#  include <unistd.h>
#endif

#ifdef _WIN32
#  define EXE_EXT ".exe"
#  define PATHSEP ';'
#  define DIRSEP '\\'
#  define DIRSEPSTR "\\"        /* for building pathnames */
#else
#  define EXE_EXT ""
#  define PATHSEP ':'
#  define DIRSEP '/'
#  define DIRSEPSTR "/"         /* for building pathnames */
#endif

#define PRIMITIVECHAR '!'       /* Character that marks irreducible units */
#define COMMENTCHAR '#'         /* Comments marked by this character */
#define COMMANDCHAR '!'         /* Unit database commands marked with this */
#define UNITSEPCHAR ';'         /* Separator for unit lists.  Include this */
                                /*    char in rl_basic_word_break_characters */
                                /*    and in nonunitchars defined in parse.y */
#define FUNCSEPCHAR ';'         /* Separates forward and inverse definitions */
#define REDEFCHAR '+'           /* Mark unit as redefinition to suppress warning message */
#ifdef _WIN32
#  define DEFAULTPAGER "more"             /* Default pager for Windows */
#else
#  define DEFAULTPAGER "/usr/bin/pager"   /* Default pager for Unix */
#endif
#define DEFAULTLOCALE "en_US"   /* Default locale */
#define MAXINCLUDE 5            /* Max depth of include files */
#define MAXFILES 25             /* Max number of units files on command line */
#define NODIM "!dimensionless"  /* Marks dimensionless primitive units, such */
                                /*    as the radian, which are ignored when */
                                /*    doing unit comparisons */
#define NOPOINT -1              /* suppress display of pointer in processunit*/
#define NOERRMSG -2             /* no error messages in checkunitlist() */
#define ERRMSG -3
#define SHOWFILES -4

#define MAXHISTORYFILE 5000     /* max length of history file for readline */

#define MAXPRODUCTREDUCTIONS 1000  /* If we make this many reductions, declare */
                                   /*    a circular reference */

/* values for output number format */
#define BASE_FORMATS "gGeEf"    /* printf() format types recognized pre-C99 */
#define DEFAULTPRECISION 8      /* default significant digits for printf() */
#define DEFAULTTYPE 'g'         /* default number format type for printf() */
#define MAXPRECISION DBL_DIG    /* maximum number precision for printf() */

#define HOME_UNITS_ENV "MYUNITSFILE"  /* Personal units file environment var */

#define NOERROR_KEYWORD "noerror "   /* The trailing space is important */
#define CO_NOARG -1

#define HELPCOMMAND "help"      /* Command to request help at prompt */
#define SEARCHCOMMAND "search"  /* Command to request text search of units */
#define UNITMATCH "?"           /* Command to request conformable units */
char *exit_commands[]={"quit","exit",0};
char *all_commands[]={"quit","exit",HELPCOMMAND,SEARCHCOMMAND,UNITMATCH,0};

/* Key words for function definitions */
struct {
  char *word;
  char delimit;
  int checkopen;  /* allow open intervals with parentheses */
} fnkeywords[]={ {"units=",  FUNCSEPCHAR, 0}, 
                 {"domain=", ',', 1}, 
                 {"range=", ',',1}, 
                 {NOERROR_KEYWORD, ' ',CO_NOARG}, 
                 {0,0}};
#define FN_UNITS 0
#define FN_DOMAIN 1
#define FN_RANGE 2
#define FN_NOERROR 3

char *builtins[] = {"sin", "cos", "tan","ln", "log", "exp", 
                    "acos", "atan", "asin", "sqrt", "cuberoot", "per",
                    "sinh", "cosh", "tanh", "asinh", "atanh", "acosh", 0};

struct {
  char *format;         /* printf() format specification for numeric output */
  int width;            /* printf() width from format */
  int precision;        /* printf() precision from format */
  char type;            /* printf() type from format */
} num_format;


struct {    /* Program command line option flags */
 int
   interactive,
   unitlists,     /* Perform unit list output if set */
   oneline,       /* Suppresses the second line of output */
   quiet,         /* Supress prompting (-q option) */
   round,         /* Round the last of unit list output to nearest integer */
   showconformable, /*   */
   showfactor,    /*   */
   strictconvert, /* Strict conversion (disables reciprocals) */
   unitcheck,     /* Enable unit checking: 1 for regular check, 2 for verbose*/
   verbose,       /* Flag for output verbosity */
   readline;      /* Using readline library? */
} flags;


#define UTF8MARKER "\xEF\xBB\xBF"   /* UTF-8 marker inserted by some Windows */
                                    /* programs at start of a UTF-8 file */

struct parseflag parserflags;   /* parser options */


char *homeunitsfile = ".units"; /* Units filename in home directory */
char *homedir = NULL;           /* User's home direcotry */
char *homedir_error = NULL;     /* Error message for home directory search */
char *pager;                    /* Actual pager (from PAGER environment var) */
char *mylocale;                 /* Locale in effect (from LC_CTYPE or LANG) */
int utf8mode;                   /* Activate UTF8 support */
char *powerstring = "^";        /* Exponent character used in output */
char *unitsfiles[MAXFILES+1];   /* Null terminated list of units file names */
char *logfilename=NULL;         /* Filename for logging */
FILE *logfile=NULL;             /* File for logging */
char *promptprefix=NULL;        /* Prefix added to prompt */
char *progname;                 /* Used in error messages */
char *fullprogname;             /* Full path of program; printversion() uses */
char *progdir;                  /* Used to find supporting files */
char *datadir;                  /* Used to find supporting files */
char *deftext="";/* Output text when printing definition */
char *digits = "0123456789.,";


#define QUERYHAVE  "You have: "  /* Prompt text for units to convert from */
#define QUERYWANT  "You want: "  /* Prompt text for units to convert to */

#define LOGFROM    "From: "     /* tag for log file */
#define LOGTO      "To:   "     /* tag for log file */


#define  HASHSIZE 101           /* Values from K&R 2nd ed., Sect. 6.6 */
#define  HASHNUMBER 31

#define  SIMPLEHASHSIZE 128
#define  simplehash(str) (*(str) & 127)    /* "hash" value for prefixes */

#define POINTER  "^"		/* pointer to location of a parse error */

#define ERRNUMFMT "%.8g"        /* Numerical format for certain error messages */

char *errormsg[]={
          /*  0 */ "Successful completion", 
          /*  1 */ "Parse error",           
          /*  2 */ "Product overflow",      
          /*  3 */ "Unit reduction error (bad unit definition)",
	  /*  4 */ "Circular unit definition",
          /*  5 */ "Invalid sum or difference of non-conformable units",
          /*  6 */ "Unit not dimensionless",
          /*  7 */ "Unit not a root",
          /*  8 */ "Unknown unit",
          /*  9 */ "Bad argument",
          /* 10 */ "Weird nonlinear unit type (bug in program)",
          /* 11 */ "Function argument has wrong dimension",
          /* 12 */ "Argument of function outside domain",
          /* 13 */ "Nonlinear unit definition has unit error",
          /* 14 */ "No inverse defined",
          /* 15 */ "Parser memory overflow (recursive function definition?)",
          /* 16 */ "Argument wrong dimension or bad nonlinear unit definition",
          /* 17 */ "Cannot open units file",
          /* 18 */ "Units file contains errors",
          /* 19 */ "Memory allocation error",
          /* 20 */ "Malformed number",
          /* 21 */ "Unit name ends with a digit other than 0 or 1 without preceding '_'",
          /* 22 */ "No previous result; '_' not set",
          /* 23 */ "Base unit not dimensionless; rational exponent required",
          /* 24 */ "Base unit not a root",
          /* 25 */ "Exponent not dimensionless",
          /* 26 */ "Unknown function name",
          /* 27 */ "Overflow: number too large",
          /* 28 */ "Underflow: number too small"
};

char *invalid_utf8 = "invalid/nonprinting UTF-8";

char *irreducible=0;            /* Name of last irreducible unit */


/* Hash table for unit definitions. */

struct unitlist {
   char *name;                  /* unit name */
   char *value;                 /* unit value */
   int linenumber;              /* line in units data file where defined */
   char *file;                  /* file where defined */ 
   struct unitlist *next;       /* next item in list */
} *utab[HASHSIZE];


/* Table for prefix definitions. */

struct prefixlist {
   int len;                     /* length of name string */
   char *name;                  /* prefix name */
   char *value;                 /* prefix value */
   int linenumber;              /* line in units data file where defined */
   char *file;                  /* file where defined */ 
   struct prefixlist *next;     /* next item in list */
} *ptab[SIMPLEHASHSIZE];


struct wantalias {
  char *name;
  char *definition;
  struct wantalias *next;
  int linenumber;
  char *file;
};

struct wantalias *firstalias = 0;
struct wantalias **aliaslistend = &firstalias; /* Next list entry goes here */

/* Table for function definitions */

struct func *ftab[SIMPLEHASHSIZE];

/* 
   Used for passing parameters to the parser when we are in the process
   of parsing a unit function.  If function_parameter is non-nil, then 
   whenever the text in function_parameter appears in a unit expression
   it is replaced by the unit value stored in parameter_value.
*/

char *function_parameter = 0; 
struct unittype *parameter_value = 0;

/* Stores the last result value for replacement with '_' */

int lastunitset = 0;
struct unittype lastunit;

char *NULLUNIT = "";  /* Used for units that are canceled during reduction */

#define startswith(string, prefix) (!strncmp(string, prefix, strlen(prefix)))
#define lastchar(string) (*((string)+strlen(string)-1))
#define emptystr(string) (*(string)==0)
#define nonempty(list)  ((list) && *(list))


#ifdef READLINE

char *historyfile;           /* Filename for readline history */
int init_history_length;      /* Length of history read from the history file*/
int init_history_base;

void
save_history(void)
{
  int newentries;
  int err;

  newentries = history_length-init_history_length;
  if (history_max_entries > 0){
    newentries += history_base - init_history_base;
    if (newentries > history_max_entries)
      newentries = history_max_entries;
  }
  
  err = append_history(newentries,historyfile);
  if (err){
    if (err == ENOENT)
      err = write_history(historyfile);
    if (err) {
      printf("Unable to write history to '%s': %s\n",historyfile,strerror(err));
      return;
    }
  } 
  history_truncate_file(historyfile,MAXHISTORYFILE);
}
#endif


/* Increases the buffer by BUFGROW bytes and leaves the new pointer in buf
   and the new buffer size in bufsize. */

#define BUFGROW 100

void
growbuffer(char **buf, int *bufsize)
{
  int usemalloc;

  usemalloc = !*buf || !*bufsize;
  *bufsize += BUFGROW;
  if (usemalloc)
    *buf = malloc(*bufsize);
  else
    *buf = realloc(*buf,*bufsize);
  if (!*buf){
    fprintf(stderr, "%s: memory allocation error (growbuffer)\n",progname);  
    exit(EXIT_FAILURE); 
  }
}


FILE *
openfile(char *file,char *mode)
{
  FILE *fileptr;

  struct stat statbuf;
  if (stat(file, &statbuf)==0 && statbuf.st_mode & S_IFDIR){
    errno=EISDIR;
    return NULL;
  }
  fileptr = fopen(file,mode);
  return fileptr;
}  



void
logprintf(const char *format, ...)
{
  va_list args;

  va_start(args, format);
  vprintf(format, args);
  va_end(args);
  if (logfile) {
    va_start(args, format);
    vfprintf(logfile, format, args);
    va_end(args);
  }
}

void
logputchar(char c)
{
  putchar(c);
  if (logfile) fputc(c, logfile);
}

void
logputs(const char *s)
{
  fputs(s, stdout);
  if (logfile) fputs(s, logfile);
}
    

/* Look for a subscript in the input string.  A subscript starts with
   '_' and is followed by a sequence of only digits (matching the
   regexp "_[0-9]+").  The function returns 1 if it finds a subscript
   and zero otherwise.  Note that it returns 1 for an input that is 
   entirely subscript, with the '_' appearing in the first position. */

int
hassubscript(const char *str)
{
  const char *ptr = &lastchar(str);
  while (ptr>str){
    if (!strchr(digits, *ptr))
      return 0;
    ptr--;
    if (*ptr=='_')
      return 1;
  }
  return 0;
}


/* replace various Unicode operator symbols with stanard ASCII equivalents */
void
replace_operators(char *input)
{
  struct{
    char *unicode;
    char replacement;
  } repl_table[]={
                   {"\xE2\x80\x92", '-'}, /* U+2012: figure dash */
                   {"\xE2\x80\x93", '-'}, /* U+2013: en dash */
                   {"\xE2\x88\x92", '-'}, /* U+2212: minus */
                   {"\xC3\x97", '*'},     /* U+00D7: times */
                   {"\xE2\xA8\x89" ,'*'}, /* U+2A09: N-ary times operator */
                   {"\xC2\xB7", '*'},     /* U+00B7: middle dot */
                   {"\xE2\x8B\x85", '*'}, /* U+22C5: dot operator */
                   {"\xC3\xB7", '/'},     /* U+00F7: division sign */
                   {"\xE2\x88\x95", '/'}, /* U+2215: division slash */
                   {"\xE2\x81\x84", '|'}, /* U+2044: fraction slash */
                   {0,0}
  };
  char *inptr, *outptr, *ptr;

  for (int i=0; repl_table[i].unicode; i++) {
    inptr = outptr = input;
    do {
      ptr = strstr(inptr, repl_table[i].unicode);    /* find next unicode symbol */
      if (ptr) {
        while (inptr < ptr)                          /* copy the input up to the unicode */
          *outptr++ = *inptr++;
        inptr = ptr + strlen(repl_table[i].unicode); /* skip over unicode */
        *outptr++ = repl_table[i].replacement;       /* Output replacement */
      }
    } while (ptr);
    
    /* If replacement were made, copy remaining input to end of string */

    if (inptr > input) {
      while (*inptr)
        *outptr++ = *inptr++;
      *outptr = '\0';
    }
  }
}



/* Replace all control chars with a space */

void
replacectrlchars(char *string)
{
  for(;*string;string++)
    if (iscntrl(*string))
      *string = ' ';
}

/* 
   Fetch a line of data with backslash for continuation.  The
   parameter count is incremented to report the number of newlines
   that are read so that line numbers can be accurately reported. 
*/

char *
fgetscont(char *buf, int size, FILE *file, int *count)
{
  if (!fgets(buf,size,file))
    return 0;
  (*count)++;
  while(strlen(buf)>=2 && 0==strcmp(buf+strlen(buf)-2,"\\\n")){
    (*count)++;
    buf[strlen(buf)-2] = 0; /* delete trailing \n and \ char */
    if (strlen(buf)>=size-1) /* return if the buffer is full */
      return buf;
    if (!fgets(buf+strlen(buf), size - strlen(buf), file))
      return buf;  /* already read some data so return success */
  }
  if (lastchar(buf) == '\\') {   /* If last char of buffer is \ then   */
    ungetc('\\', file);           /* we don't know if it is followed by */
    lastchar(buf) = 0;           /* a \n, so put it back and try again */
  }
  return buf;
}


/* 
   Gets arbitrarily long input data into a buffer using growbuffer().
   Returns 0 if no data is read.  Increments count by the number of
   newlines read unless it points to NULL. 
 
   Replaces tabs and newlines with spaces before returning the result.
*/

char *
fgetslong(char **buf, int *bufsize, FILE *file, int *count)
{
  int dummy;
  if (!count)
    count = &dummy;
  if (!*bufsize) growbuffer(buf,bufsize);
  if (!fgetscont(*buf, *bufsize, file, count))
    return 0;
  while (lastchar(*buf) != '\n' && !feof(file)){
    growbuffer(buf, bufsize);
    fgetscont(*buf+strlen(*buf), *bufsize-strlen(*buf), file, count);
    (*count)--;
  }  
  /* These nonprinting characters must be removed so that the test
     for UTF-8 validity will work. */ 
  replacectrlchars(*buf);
  return *buf;
}

/* Allocates memory and aborts if malloc fails. */

void *
mymalloc(int bytes,const char *mesg)
{
   void *pointer;

   pointer = malloc(bytes);
   if (!pointer){
     fprintf(stderr, "%s: memory allocation error %s\n", progname, mesg);
     exit(EXIT_FAILURE);
   }
   return pointer;
}


/* Duplicates a string */

char *
dupstr(const char *str)
{
   char *ret;

   ret = mymalloc(strlen(str) + 1,"(dupstr)");
   strcpy(ret, str);
   return ret;
}

/* Duplicates a string that is not null-terminated, 
   adding the null to the copy */

char *
dupnstr(const char *string, int length)
{  
  char *newstr;
  newstr = mymalloc(length+1,"(dupnstr)");
  strncpy(newstr, string, length);
  newstr[length]=0;
  return newstr;
}
  

#ifdef SUPPORT_UTF8

/* 
   The strwidth function gives the printed width of a UTF-8 byte sequence.
   It will return -1 if the sequence is an invalid UTF-8 sequence or
   if the sequence contains "nonprinting" characters.  Note that \n and \t are 
   "nonprinting" characters. 
*/

int 
strwidth(const char *str)
{
  wchar_t *widestr;
  int len;

  if (!utf8mode)
    return strlen(str);
  len = strlen(str)+1;
  widestr = mymalloc(sizeof(wchar_t)*len, "(strwidth)");
  len = mbsrtowcs(widestr, &str, len, NULL);

  if (len==-1){
    free(widestr);
    return -1; /* invalid multibyte sequence */
  }

  len=wcswidth(widestr, len);
  free(widestr);
  return len;
}
#else
#  define strwidth strlen
#endif 



/* hashing algorithm for units */

unsigned
uhash(const char *str)
{
   unsigned hashval;

   for (hashval = 0; *str; str++)
      hashval = *str + HASHNUMBER * hashval;
   return (hashval % HASHSIZE);
}


/* Lookup a unit in the units table.  Returns the definition, or NULL
   if the unit isn't found in the table. */

struct unitlist *
ulookup(const char *str)
{
   struct unitlist *uptr;

   for (uptr = utab[uhash(str)]; uptr; uptr = uptr->next)
      if (strcmp(str, uptr->name) == 0)
         return uptr;
   return NULL;
}

/* Lookup a prefix in the prefix table.  Finds the longest prefix that
   matches the beginning of the input string.  Returns NULL if no
   prefixes match. */

struct prefixlist *
plookup(const char *str)
{
   struct prefixlist *prefix;
   struct prefixlist *bestprefix=NULL;
   int bestlength=0;

   for (prefix = ptab[simplehash(str)]; prefix; prefix = prefix->next) {
     if (prefix->len > bestlength && !strncmp(str, prefix->name, prefix->len)){
       bestlength = prefix->len;
       bestprefix = prefix;
     }
   }
   return bestprefix;
}

/* Look up function in the function linked list */

struct func *
fnlookup(const char *str)
{ 
  struct func *funcptr;

  for(funcptr=ftab[simplehash(str)];funcptr;funcptr = funcptr->next)
    if (!strcmp(funcptr->name, str))
      return funcptr;
  return 0;
}

struct wantalias *
aliaslookup(const char *str)
{
  struct wantalias *aliasptr;
  for(aliasptr = firstalias; aliasptr; aliasptr=aliasptr->next)
    if (!strcmp(aliasptr->name, str))
      return aliasptr;
  return 0;
}


/* Insert a new function into the linked list of functions */

void
addfunction(struct func *newfunc)
{
  int val;

  val = simplehash(newfunc->name);
  newfunc->next = ftab[val];
  ftab[val] = newfunc;
}


/* Free the fields in the function except for the name so that it
   can be redefined.  It remains in position in the linked list. */
void
freefunction(struct func *funcentry)
{
  if (funcentry->table){
    free(funcentry->table);
    free(funcentry->tableunit);
  } else {
    free(funcentry->forward.param);
    free(funcentry->forward.def);
    if (funcentry->forward.domain_min) free(funcentry->forward.domain_min);
    if (funcentry->forward.domain_max) free(funcentry->forward.domain_max);
    if (funcentry->inverse.domain_min) free(funcentry->inverse.domain_min);
    if (funcentry->inverse.domain_max) free(funcentry->inverse.domain_max);
    if (funcentry->forward.dimen) free(funcentry->forward.dimen);
    if (funcentry->inverse.dimen) free(funcentry->inverse.dimen);
    if (funcentry->inverse.def) free(funcentry->inverse.def);    
    if (funcentry->inverse.param) free(funcentry->inverse.param);
  }
}

/* Remove leading and trailing spaces from the input */

void
removespaces(char *in)
{
  char *ptr;
  if (*in) {
    for(ptr = in + strlen(in) - 1; *ptr==' '; ptr--); /* Last non-space */
    *(ptr+1)=0;
    if (*in==' '){
      ptr = in + strspn(in," ");
      memmove(in, ptr, strlen(ptr)+1);
    }
  }
}


/* 
   Looks up an inverse function given as a ~ character followed by
   spaces and then the function name.  The spaces will be deleted as a
   side effect.  If an inverse function is found returns the function
   pointer, otherwise returns null.
*/

struct func *
invfnlookup(char *str)
{
  if (*str != '~')
    return 0;
  removespaces(str+1);
  return fnlookup(str+1);
}


char *
strip_comment(char *line)
{
  char *comment = 0;
  
  if ((line = strchr(line,COMMENTCHAR))) {
    comment = line+1;
    *line = 0;
  }
  return comment;
}


/* Print string but replace two consecutive spaces with one space. */

void
tightprint(FILE *outfile, char *string)
{
  while(*string){
    fputc(*string, outfile);
    if (*string != ' ') string++;
    else while(*string==' ') string++;
  }
}

/*
    Copy string to buf, replacing two or more consecutive spaces with
    one space.
*/
void
tightbufprint(char *buf, char *string)
{
  while(*string) {
    *buf++ = *string;
    if (*string != ' ')
	string++;
    else {
	while(*string==' ')
	    string++;
    }
  }
  *buf = '\0';
}


#define readerror (goterr=1) && errfile && fprintf

#define VAGUE_ERR "%s: error in units file '%s' line %d\n", \
                       progname, file, linenum

/* Print out error message encountered while reading the units file. */


/*
  Splits the line into two parts.  The first part is space delimited.
  The second part is everything else.  Removes trailing spaces from
  the second part.  Returned items are null if no parameter was found.
*/
  
void
splitline(char *line, char **first, char **second)
{
  *second = 0;
  *first = strtok(line, " ");
  if (*first){
    *second = strtok(0, "\n");
    if (*second){
      removespaces(*second);
      if (emptystr(*second))
        *second = 0;
    }
  }
}


/* see if character is part of a valid decimal number */

int
isdecimal(char c)
{
  return strchr(digits, c) != NULL;
}


/* 
   Check for some invalid unit names.  Print error message.  Returns 1 if 
   unit name is bad, zero otherwise.  
*/
int
checkunitname(char *name, int linenum, char *file, FILE *errfile)
{
  char nonunitchars[] = "~;+-*/|^)";  /* Also defined in parse.y with a few more characters */
  char **ptr;
  char *cptr;

  if ((cptr=strpbrk(name, nonunitchars))){
    if (errfile) fprintf(errfile,
         "%s: unit '%s' in units file '%s' on line %d ignored.  It contains invalid character '%c'\n",
              progname, name, file, linenum, *cptr);
    return 1;
  }
  if (strchr(digits, name[0])){
    if (errfile) fprintf(errfile,
         "%s: unit '%s' in units file '%s' on line %d ignored.  It starts with a digit\n", 
              progname, name, file, linenum);
    return 1;
  }
  for(ptr=builtins;*ptr;ptr++)
    if (!strcmp(name, *ptr)){
      if (errfile) fprintf(errfile,
           "%s: redefinition of built-in function '%s' in file '%s' on line %d ignored.\n",
                           progname, name, file, linenum);
      return 1;
    }
  for(ptr=all_commands;*ptr;ptr++)
    if (!strcmp(name, *ptr)){
      if (errfile) fprintf(errfile,
           "%s: unit name '%s' in file '%s' on line %d may be hidden by command with the same name.\n",
                           progname, name, file, linenum);
    }
  return 0;
}

int
newunit(char *unitname, char *unitdef, int *count, int linenum, 
        char *file,FILE *errfile, int redefine, int userunit)
{
  struct unitlist *uptr;
  unsigned hashval; 

  /* units ending with '_' create ambiguity for exponents */

  if ((unitname[0]=='_' && !userunit) || lastchar(unitname)=='_'){
    if (errfile) fprintf(errfile,
       "%s: unit '%s' on line %d of '%s' ignored.  It starts or ends with '_'\n",
              progname, unitname, linenum, file);
    return E_BADFILE;
  }

  /* Units that end in [2-9] can never be accessed */
  if (strchr(".,23456789", lastchar(unitname)) && !hassubscript(unitname)){
    if (errfile) fprintf(errfile,
       "%s: unit '%s' on line %d of '%s' ignored.  %s\n",
        progname, unitname, linenum, file,errormsg[E_UNITEND]);
    return E_BADFILE;
  }

  if (checkunitname(unitname, linenum, file, errfile))
    return E_BADFILE;

  if ((uptr=ulookup(unitname))) {    /* Is it a redefinition? */
    if (flags.unitcheck && errfile && !redefine)
      fprintf(errfile,
      "%s: unit '%s' defined on line %d of '%s' is redefined on line %d of '%s'.\n",
              progname, unitname, uptr->linenumber,uptr->file,
              linenum, file);
    free(uptr->value);
  } else {       
    /* make new units table entry */

    uptr = (struct unitlist *) mymalloc(sizeof(*uptr),"(newunit)");
    uptr->name = dupstr(unitname);

    /* install unit name/value pair in list */

    hashval = uhash(uptr->name);
    uptr->next = utab[hashval];
    utab[hashval] = uptr;
    (*count)++;
  }
  uptr->value = dupstr(unitdef);
  uptr->linenumber = linenum;
  uptr->file = file;
  return 0;
}
  


int 
newprefix(char *unitname, char *unitdef, int *count, int linenum, 
          char *file,FILE *errfile, int redefine)
{
  struct prefixlist *pfxptr;
  unsigned pval;

  lastchar(unitname) = 0;
  if (checkunitname(unitname,linenum,file,errfile))
    return E_BADFILE;
  if ((pfxptr = plookup(unitname))     /* already there: redefinition */
      && !strcmp(pfxptr->name, unitname)){
    if (flags.unitcheck && errfile && !redefine)
      fprintf(errfile,
             "%s: prefix '%s-' defined on line %d of '%s' is redefined on line %d of '%s'.\n",
              progname, unitname, pfxptr->linenumber,pfxptr->file,
              linenum, file);
    free(pfxptr->value);
  } else {  
    pfxptr = (struct prefixlist *) mymalloc(sizeof(*pfxptr),"(newprefix)");  
    pfxptr->name = dupstr(unitname);
    pfxptr->len = strlen(unitname);
    pval = simplehash(unitname);
    pfxptr->next = ptab[pval];
    ptab[pval] = pfxptr;
    (*count)++;
  }
  pfxptr->value = dupstr(unitdef);
  pfxptr->linenumber = linenum;
  pfxptr->file = file;
  return 0;
}


/* 
   parsepair() looks for data of the form [text1,text2] where the ',' is a 
   specified delimiter.  The second argument, text2, is optional and if it's 
   missing then second is set to NULL.  The parameters are allowed to be 
   empty strings.  The function returns the first character after the 
   closing bracket if no errors occur or the NULL pointer on error.
*/

char *
parsepair(char *input, char **first, char **second, 
          int *firstopen, int *secondopen, char delimiter, int checkopen,
          char *unitname, int linenum, char *file,FILE *errfile)
{
  char *start, *end, *middle;

  start = strpbrk(input, checkopen?"[(":"[");
  if (!start){
    if (errfile) fprintf(errfile,
             "%s: expecting '[' %s in definition of '%s' in '%s' line %d\n",
             progname, checkopen ? "or '('":"", unitname, file, linenum);
    return 0;
  }
  if (*start=='(') *firstopen=1;
  else *firstopen=0;
  *start++=0;
  removespaces(input);
  if (!emptystr(input)){
    if (errfile) fprintf(errfile,
        "%s: unexpected characters before '%c' in definition of '%s' in '%s' line %d\n",
        progname, *firstopen?'(':'[',unitname, file, linenum);
    return 0;
  }
  end = strpbrk(start, checkopen?"])":"]");
  if (!end){
    if (errfile) fprintf(errfile,
             "%s: expecting ']' %s in definition of '%s' in '%s' line %d\n",
             progname, checkopen?"or ')'":"",unitname, file, linenum);
    return 0;
  }
  if (*end==')') *secondopen=1;
  else *secondopen=0;
  *end++=0;

  middle = strchr(start,delimiter);
  
  if (middle){
    *middle++=0;
    removespaces(middle);
    *second = middle;
  } else
    *second = 0;

  removespaces(start);
  *first = start;
  return end;
}


/* 
   Extract numbers from two text strings and place them into pointers. 
   Has two error codes for decreasing interval or bad numbers in the 
   text strings.  Returns 0 on success.  
*/

#define EI_ERR_DEC 1    /* Decreasing interval */
#define EI_ERR_MALF 2   /* Malformed number */

int
extract_interval(char *first, char *second, 
                 double **firstout, double **secondout)
{
  double val;
  char *end;

  if (!emptystr(first)){
    val = strtod(first, &end);
    if (*end)
      return EI_ERR_MALF;
    else {
      *firstout=(double *)mymalloc(sizeof(double), "(extract_interval)");
      **firstout = val;
    }
  }
  if (nonempty(second)) {
    val = strtod(second, &end);
    if (*end)
      return EI_ERR_MALF;
    else if (*firstout && **firstout>=val)
      return EI_ERR_DEC;
    else {
      *secondout=(double *)mymalloc(sizeof(double), "(extract_interval)");
      **secondout = val;
    }
  }
  return 0;
}


 
void 
copyfunctype(struct functype *dest, struct functype *src)
{
  dest->domain_min_open = src->domain_min_open;
  dest->domain_max_open = src->domain_max_open;
  dest->param = dest->def = dest->dimen = NULL;
  dest->domain_min = dest->domain_max = NULL;
  if (src->param) dest->param = dupstr(src->param); 
  if (src->def) dest->def = dupstr(src->def);
  if (src->dimen) dest->dimen = dupstr(src->dimen);
  if (src->domain_min){
    dest->domain_min = (double *) mymalloc(sizeof(double), "(copyfunctype)");
    *dest->domain_min = *src->domain_min;
  }
  if (src->domain_max){
    dest->domain_max = (double *) mymalloc(sizeof(double), "(copyfunctype)");
    *dest->domain_max = *src->domain_max;
  }
}


int
copyfunction(char *unitname, char *funcname, int *count, int linenum, 
             char *file, FILE *errfile)
{
  struct func *source, *funcentry;
  int i;
  if (checkunitname(unitname, linenum, file, errfile))
    return E_BADFILE;
  removespaces(funcname);
  i = strlen(funcname)-2;                /* strip trailing () if present */
  if (i>0 && !strcmp(funcname+i,"()"))  
    funcname[i]=0;
  source = fnlookup(funcname);
  if (!source) {
    if (errfile){ 
      if (!strpbrk(funcname," ;][()+*/-^")) 
        fprintf(errfile,"%s: bad definition for '%s' in '%s' line %d, function '%s' not defined\n",
                progname, unitname, file, linenum, funcname);
      else
        fprintf(errfile,"%s: bad function definition of '%s' in '%s' line %d\n",
                progname,unitname,file,linenum);
    }
    return E_BADFILE;
  }
  if ((funcentry=fnlookup(unitname))){
    if (flags.unitcheck && errfile)          
      fprintf(errfile,
             "%s: function '%s' defined on line %d of '%s' is redefined on line %d of '%s'.\n",
              progname, unitname, funcentry->linenumber,funcentry->file,
              linenum, file);
    freefunction(funcentry);
  } else {
    funcentry = (struct func*)mymalloc(sizeof(struct func),"(newfunction)");    
    funcentry->name = dupstr(unitname);
    addfunction(funcentry);
    (*count)++;
  }
  funcentry->linenumber = linenum;
  funcentry->file = file;
  funcentry->skip_error_check = source->skip_error_check;
  if (source->table){
    funcentry->tablelen = source->tablelen;
    funcentry->tableunit = dupstr(source->tableunit);
    funcentry->table = (struct pair *)
        mymalloc(sizeof(struct pair)*funcentry->tablelen, "(copyfunction)");
    for(i=0;i<funcentry->tablelen;i++){
      funcentry->table[i].location = source->table[i].location;
      funcentry->table[i].value = source->table[i].value;
    }
  } else {
    funcentry->table = 0;
      copyfunctype(&funcentry->forward, &source->forward);
      copyfunctype(&funcentry->inverse, &source->inverse);
  }
  return 0;
}


#define FREE_STUFF {if (forward_dim) free(forward_dim);\
                    if (inverse_dim) free(inverse_dim);\
                    if (domain_min) free(domain_min);\
                    if (domain_max) free(domain_max);\
                    if (range_min) free(range_min);\
                    if (range_max) free(range_max);}

#define REPEAT_ERR \
  if (errfile) fprintf(errfile, \
     "%s: keyword '%s' repeated in definition of '%s' on line %d of '%s'.\n",\
                      progname,fnkeywords[i].word,unitname, linenum, file)

int
newfunction(char *unitname, char *unitdef, int *count, 
            int linenum, char *file,FILE *errfile, int redefine)
{
  char *start, *end, *inv, *forward_dim, *inverse_dim, *first, *second;
  double *domain_min, *domain_max, *range_min, *range_max;
  struct func *funcentry;
  int looking_for_keywords,i, firstopen, secondopen;
  int domain_min_open, domain_max_open, range_min_open, range_max_open;
  int noerror = 0;

  if (*unitname=='('){
    if (errfile) fprintf(errfile,
         "%s: unit '%s' on line %d of '%s' ignored.  It starts with a '('\n", 
         progname, unitname, linenum, file);
    return E_BADFILE;
  }
                                   /* coverity[returned_null] */
  start = strchr(unitname,'(');
  end = strchr(unitname,')');
  *start++ = 0;
    
  if (checkunitname(unitname,linenum,file,errfile))
    return E_BADFILE;
  
  if (start==end)  /* no argument: function() so make a function copy */
    return copyfunction(unitname, unitdef, count, linenum, file, errfile);

  if (!end || strlen(end)>1){
    if (errfile) fprintf(errfile,
              "%s: bad function definition of '%s' in '%s' line %d\n",
              progname,unitname,file,linenum);
    return E_BADFILE;
  }
  *end=0;
  forward_dim = NULL;
  inverse_dim = NULL;
  domain_min = NULL;
  domain_max = NULL;
  range_min = NULL;
  range_max = NULL;
  domain_min_open = 0;
  domain_max_open = 0;
  range_min_open = 0;
  range_max_open = 0;
  looking_for_keywords=1;
  while (looking_for_keywords) {
    looking_for_keywords = 0;
    for(i=0;fnkeywords[i].word;i++){
      if (startswith(unitdef, fnkeywords[i].word)){
        looking_for_keywords = 1;  /* found keyword so keep looking */
        unitdef+=strlen(fnkeywords[i].word);
        if (fnkeywords[i].checkopen!=CO_NOARG){
          unitdef = parsepair(unitdef,&first, &second, &firstopen, &secondopen, 
                            fnkeywords[i].delimit, fnkeywords[i].checkopen,
                            unitname, linenum, file,errfile);
          if (!unitdef){
            FREE_STUFF;
            return E_BADFILE;
          }
          removespaces(unitdef);
        }
        if (i==FN_NOERROR)
          noerror = 1;
        if (i==FN_UNITS){
          if (forward_dim || inverse_dim){
            REPEAT_ERR;
            return E_BADFILE;
          }
          forward_dim = dupstr(first);
          if (second)
            inverse_dim = dupstr(second);
        }
        if (i==FN_DOMAIN){
          int err=0;
          if (domain_min || domain_max){
            REPEAT_ERR;
            return E_BADFILE;
          }
          err = extract_interval(first,second,&domain_min, &domain_max);
          domain_min_open = firstopen;
          domain_max_open = secondopen;
          if (err)
            FREE_STUFF;
          if (err==EI_ERR_DEC){
            if (errfile) fprintf(errfile,
               "%s: second endpoint for domain must be greater than the first\n       in definition of '%s' in '%s' line %d\n",
                progname, unitname, file, linenum);
            return E_BADFILE;
          }
          if (err==EI_ERR_MALF){
            if (errfile) fprintf(errfile,
              "%s: malformed domain in definition of '%s' in '%s' line %d\n",
              progname, unitname, file, linenum);
            return E_BADFILE;
          }
        } 
        if (i==FN_RANGE){
          int err=0;
          if (range_min || range_max){
            REPEAT_ERR;
            FREE_STUFF;
            return E_BADFILE;
          }
          err = extract_interval(first,second,&range_min, &range_max);
          range_min_open = firstopen;
          range_max_open = secondopen;
          if (err)
            FREE_STUFF;
          if (err==EI_ERR_DEC){
            if (errfile) fprintf(errfile,
               "%s: second endpoint for range must be greater than the first\n       in definition of '%s' in '%s' line %d\n",
                progname, unitname, file, linenum);
            return E_BADFILE;
          }
          if (err==EI_ERR_MALF){
            if (errfile) fprintf(errfile,
              "%s: malformed range in definition of '%s' in '%s' line %d\n",
              progname, unitname, file, linenum);
            return E_BADFILE;
          }
        }
      }
    }
  }

  if (emptystr(unitdef)){
    if (errfile) fprintf(errfile,
                 "%s: function '%s' lacks a definition at line %d of '%s'\n",
                 progname, unitname, linenum, file);
    FREE_STUFF;
    return E_BADFILE;
  }

  if (*unitdef=='['){
    if (errfile) fprintf(errfile,
         "%s: function '%s' missing keyword before '[' on line %d of '%s'\n", 
         progname, unitname, linenum, file);
    FREE_STUFF;
    return E_BADFILE;
  }

  /* Check that if domain and range are specified and nonzero then the 
     units are given.  Otherwise these are meaningless.  */
  if (!forward_dim &&
      ((domain_min && *domain_min) || (domain_max && *domain_max))){ 
    if (errfile)
      fprintf(errfile,"%s: function '%s' defined on line %d of '%s' has domain with no units.\n", 
              progname, unitname, linenum, file);
    FREE_STUFF;
    return E_BADFILE;
  }
  if (!inverse_dim &&
      ((range_min && *range_min) || (range_max && *range_max))){ 
    if (errfile)
      fprintf(errfile,"%s: function '%s' defined on line %d of '%s' has range with no units.\n", 
              progname, unitname, linenum, file);
    FREE_STUFF;
    return E_BADFILE;
  }
  if ((funcentry=fnlookup(unitname))){
    if (flags.unitcheck && errfile && !redefine)
      fprintf(errfile,
             "%s: function '%s' defined on line %d of '%s' is redefined on line %d of '%s'.\n",
              progname, unitname, funcentry->linenumber,funcentry->file,
              linenum, file);
    freefunction(funcentry);
  } else {
    funcentry = (struct func*)mymalloc(sizeof(struct func),"(newfunction)");    
    funcentry->name = dupstr(unitname);
    addfunction(funcentry);
    (*count)++;
  }
  funcentry->table = 0;
  funcentry->skip_error_check = noerror;
  funcentry->forward.dimen = forward_dim;
  funcentry->inverse.dimen = inverse_dim;
  funcentry->forward.domain_min = domain_min;
  funcentry->forward.domain_max = domain_max;
  funcentry->inverse.domain_min = range_min;
  funcentry->inverse.domain_max = range_max;
  funcentry->forward.domain_min_open = domain_min_open;
  funcentry->forward.domain_max_open = domain_max_open;
  funcentry->inverse.domain_min_open = range_min_open;
  funcentry->inverse.domain_max_open = range_max_open;
  inv = strchr(unitdef,FUNCSEPCHAR);
  if (inv)
    *inv++ = 0;
  funcentry->forward.param = dupstr(start);
  removespaces(unitdef);
  funcentry->forward.def = dupstr(unitdef);
  if (inv){
    removespaces(inv);
    funcentry->inverse.def = dupstr(inv);
    funcentry->inverse.param = dupstr(unitname);
  } 
  else {
    funcentry->inverse.def = 0;
    funcentry->inverse.param = 0;
  }
  funcentry->linenumber = linenum;
  funcentry->file = file;
  return 0;
}


int 
newtable(char *unitname,char *unitdef, int *count,
         int linenum, char *file,FILE *errfile, int redefine)
{
  char *start, *end;
  char *tableunit;
  int tablealloc, tabpt;
  struct pair *tab;
  struct func *funcentry;
  int noerror = 0;

                                      /* coverity[returned_null] */
  tableunit = strchr(unitname,'[');
  end = strchr(unitname,']');
  *tableunit++=0;
  if (checkunitname(unitname, linenum, file, errfile))
    return E_BADFILE;
  if (!end){
    if (errfile) fprintf(errfile,"%s: missing ']' in units file '%s' line %d\n",
              progname,file,linenum);
    return E_BADFILE;
  } 
  if (strlen(end)>1){
    if (errfile) fprintf(errfile,
              "%s: unexpected characters after ']' in units file '%s' line %d\n",
              progname,file,linenum);
    return E_BADFILE;
  }
  *end=0;
  tab = (struct pair *)mymalloc(sizeof(struct pair)*20, "(newtable)");
  tablealloc=20;
  tabpt = 0;
  start = unitdef;
  if (startswith(start, NOERROR_KEYWORD)) {
    noerror = 1;
    start += strlen(NOERROR_KEYWORD);
    removespaces(start);
  }
  while (1) {
    if (tabpt>=tablealloc){
      tablealloc+=20;
      tab = (struct pair *)realloc(tab,sizeof(struct pair)*tablealloc);
      if (!tab){
        if (errfile) fprintf(errfile, "%s: memory allocation error (newtable)\n",
                  progname);  
        return E_MEMORY;
      }
    }
    tab[tabpt].location = strtod(start,&end);
    if (start==end || (!emptystr(end) && *end !=' ')){ 
      if (!emptystr(start)) {  
        if (strlen(start)>15) start[15]=0;  /* Truncate for error msg display */
        if (errfile) fprintf(errfile, 
             "%s: cannot parse table definition %s at '%s' on line %d of '%s'\n", 
             progname, unitname, start, linenum, file);
        free(tab);
        return E_BADFILE;
      }
      break;
    }
    if (tabpt>0 && tab[tabpt].location<=tab[tabpt-1].location){
      if (errfile)
        fprintf(errfile,"%s: points don't increase (" ERRNUMFMT " to " ERRNUMFMT
                        ") in units file '%s' line %d\n",
                progname, tab[tabpt-1].location, tab[tabpt].location,
                file, linenum);
      free(tab);
      return E_BADFILE;
    }
    start=end+strspn(end," ");
    tab[tabpt].value = strtod(start,&end);
    if (start==end){
      if (errfile)
        fprintf(errfile,"%s: missing value after " ERRNUMFMT " in units file '%s' line %d\n",
                progname, tab[tabpt].location, file, linenum);
      free(tab);
      return E_BADFILE;
    }
    tabpt++;
    start=end+strspn(end," ,");
  }
  if ((funcentry=fnlookup(unitname))){
    if (flags.unitcheck && errfile && !redefine)
      fprintf(errfile,
      "%s: unit '%s' defined on line %d of '%s' is redefined on line %d of '%s'.\n",
                    progname, unitname, funcentry->linenumber,funcentry->file,
                                         linenum, file);
    freefunction(funcentry);
  } else {
    funcentry = (struct func *)mymalloc(sizeof(struct func),"(newtable)");
    funcentry->name = dupstr(unitname);
    addfunction(funcentry);
    (*count)++;
  }
  funcentry->tableunit = dupstr(tableunit);
  funcentry->tablelen = tabpt;
  funcentry->table = tab;
  funcentry->skip_error_check = noerror;
  funcentry->linenumber = linenum;
  funcentry->file = file;
  return 0;
}


int
newalias(char *unitname, char *unitdef,int linenum, char *file,FILE *errfile)
{
  struct wantalias *aliasentry;

  if (!strchr(unitdef, UNITSEPCHAR)){
    if (errfile) fprintf(errfile,
            "%s: unit list missing '%c' on line %d of '%s'\n",
            progname, UNITSEPCHAR, linenum, file);
    return E_BADFILE;
  }
  if ((aliasentry=aliaslookup(unitname))){   /* duplicate alias */
    if (flags.unitcheck && errfile)
      fprintf(errfile,
              "%s: unit list '%s' defined on line %d of '%s' is redefined on line %d of '%s'.\n",
              progname, unitname, aliasentry->linenumber,
              aliasentry->file, linenum, file);
    free(aliasentry->definition);
  } else { 
    aliasentry = (struct wantalias *)
      mymalloc(sizeof(struct wantalias),"(newalias)");
    aliasentry->name = dupstr(unitname);
    aliasentry->next = 0;
    *aliaslistend = aliasentry;
    aliaslistend = &aliasentry->next;
  }
  aliasentry->definition = dupstr(unitdef);
  aliasentry->linenumber = linenum;
  aliasentry->file = file;
  return 0;
}


/* 
   Check environment variable name to see if its value appears on the
   space delimited text string pointed to by list.  Returns 2 if the
   environment variable is not set, return 1 if its value appears on
   the list and zero otherwise.
*/

int
checkvar(char *name, char *list)
{
  char *listitem;
  name = getenv(name);
  if (!name)
    return 2;
  listitem = strtok(list," ");
  while (listitem){
    if (!strcmp(name, listitem))
      return 1;
    listitem = strtok(0," ");
  }
  return 0;
}


#ifdef NO_SETENV
int
setenv(const char *name, const char *val, int overwrite)
{
  char *environment;

  if (!overwrite && getenv(name) != NULL)
    return 0;
  environment = (char *) malloc(strlen(name) + strlen(val) + 2);
  if (!environment)
    return 1;
  strcpy(environment, name);
  strcat(environment, "=");
  strcat(environment, val);

  /* putenv() doesn't copy its argument, so don't free environment */

#if defined (_WIN32) && defined (_MSC_VER)
  return _putenv(environment);
#else
  return putenv(environment);
#endif
}
#endif

#ifdef _WIN32
#  define  isdirsep(c)  ((c) == '/' || (c) == '\\')
#  define  hasdirsep(s) strpbrk((s),"/\\")
#else
#  define  isdirsep(c)  ((c) == '/')
#  define  hasdirsep(s) strchr((s),'/')
#endif
#define  isexe(s) ((strlen(s) == 4) && (tolower(s[1]) == 'e') \
                 && (tolower(s[2]) == 'x') && (tolower(s[3]) == 'e'))

/* Returns a pointer to the end of the pathname part of the 
   specified filename */

char *
pathend(char *filename)
{
  char *pointer;

  for(pointer=filename+strlen(filename);pointer>filename;pointer--){
    if (isdirsep(*pointer)) {
      pointer++;
      break;
    }
  }
  return pointer;
}

int
isfullpath(char *path)
{
#ifdef _WIN32
  /* handle Windows drive specifier */
  if (isalpha(*path) && *(path + 1) == ':')
      path += 2;
#endif
  return isdirsep(*path);
}

/* 
   Read in units data.  

   file - Filename to load
   errfile - File to receive messages about errors in the units database.  
             Set it to 0 to suppress errors. 
   unitcount, prefixcount, funccount - Return statistics to the caller.  
                                       Must initialize to zero before calling.
   depth - Used to prevent recursive includes.  Call with it set to zero.

   The global variable progname is used in error messages.  
*/

int
readunits(char *file, FILE *errfile, 
          int *unitcount, int *prefixcount, int *funccount, int depth)
{
   FILE *unitfile;
   char *line = 0, *lineptr, *unitdef, *unitname, *permfile;
   int linenum, linebufsize, goterr, retcode;
   int locunitcount, locprefixcount, locfunccount, redefinition;
   int wronglocale = 0;   /* If set then we are currently reading data */
   int inlocale = 0;      /* for the wrong locale so we should skip it */
   int in_utf8 = 0;       /* If set we are reading utf8 data */
   int invar = 0;         /* If set we are in data for an env variable.*/
   int wrongvar = 0;      /* If set then we are not processing */

   locunitcount = 0;
   locprefixcount = 0;
   locfunccount  = 0;
   linenum = 0;
   linebufsize = 0;
   goterr = 0;

   unitfile = openfile(file, "rt");
   
   if (!unitfile){
     if (errfile)
       fprintf(errfile, "%s: Unable to read units file '%s': %s\n", progname, file, strerror(errno));
     return E_FILE;
   }
   growbuffer(&line,&linebufsize);
                                            /* coverity[alloc_fn] */
   permfile = dupstr(file);    /* This is a permanent copy to reference in */
                               /* the database. It is never freed. */
   while (!feof(unitfile)) {
      if (!fgetslong(&line, &linebufsize, unitfile, &linenum)) 
        break;
      if (linenum==1 && startswith(line, UTF8MARKER)){ 
        int i;
        for(lineptr=line,i=0;i<strlen(UTF8MARKER);i++, lineptr++)
          *lineptr=' ';
      }
      strip_comment(line);
      if (-1 == strwidth(line)){
        readerror(errfile, "%s: %s on line %d of '%s'\n",
                      progname, invalid_utf8, linenum, file);
        continue;
      }
      replace_operators(line);

      if (*line == COMMANDCHAR) {         /* Process units file commands */
        unitname = strtok(line+1, " ");
        if (!unitname){
          readerror(errfile, VAGUE_ERR);
          continue;
        }

        /* Check for locale and utf8 declarations.  Any other commands
           most likely belong after these tests. */
        if (!strcmp(unitname,"var") || !strcmp(unitname,"varnot")){
          int not = 0;
          if (unitname[3]=='n')
            not = 1;
          unitname=strtok(0," ");
          unitdef=strtok(0,"");  /* Get rest of the line */
          if (!unitname)
            readerror(errfile, 
                      "%s: no variable name specified on line %d of '%s'\n",
                      progname, linenum, file);
          else if (!unitdef)
            readerror(errfile, 
                      "%s: no value specified on line %d of '%s'\n",
                      progname, linenum, file);
          else if (invar)
            readerror(errfile,
                 "%s: nested var statements not allowed, line %d of '%s'\n",
                      progname, linenum, file);
          else {
            int check;
            invar = 1;
            check = checkvar(unitname, unitdef);
            if (check==2){
              readerror(errfile,
                 "%s: environment variable %s not set at line %d of '%s'\n",
                         progname, unitname, linenum, file);
              wrongvar = 1;
            }
            else if (!(not^check))
              wrongvar = 1;
          }         
          continue;
        }
        else if (!strcmp(unitname, "endvar")){
          if (!invar)
            readerror(errfile, 
                      "%s: unmatched !endvar on line %d of '%s'\n",
                      progname, linenum, file);
          wrongvar = 0;
          invar = 0;
          continue;
        }
        else if (!strcmp(unitname,"locale")){ 
          unitname = strtok(0, " "); 
          if (!unitname)
            readerror(errfile, 
                      "%s: no locale specified on line %d of '%s'\n",
                      progname, linenum, file);
          else if (inlocale)
            readerror(errfile,
                      "%s: nested locales not allowed, line %d of '%s'\n",
                      progname, linenum, file);
          else {
            inlocale = 1;
            if (strcmp(unitname,mylocale))  /* locales don't match           */
              wronglocale = 1;
          }
          continue;
        } 
        else if (!strcmp(unitname, "endlocale")){
          if (!inlocale)
            readerror(errfile, 
                      "%s: unmatched !endlocale on line %d of '%s'\n",
                      progname, linenum, file);
          wronglocale = 0;
          inlocale = 0;
          continue;
        }
        else if (!strcmp(unitname, "utf8")){
          if (in_utf8)
            readerror(errfile,"%s: nested utf8 not allowed, line %d of '%s'\n",
                              progname, linenum, file);
          else in_utf8 = 1;
          continue;
        } 
        else if (!strcmp(unitname, "endutf8")){
          if (!in_utf8)
            readerror(errfile,"%s: unmatched !endutf8 on line %d of '%s'\n",
                      progname, linenum, file);
          in_utf8 = 0;
          continue;
        }
        if (in_utf8 && !utf8mode) continue;
        if (wronglocale || wrongvar) continue;

        if (!strcmp(unitname,"prompt")){
          unitname = strtok(0,"");     /* Rest of the line */
          if (promptprefix)
            free(promptprefix);
          if (!unitname)
            promptprefix=0;
          else
            promptprefix = dupstr(unitname);
          continue;
        }
        if (!strcmp(unitname,"message")){
          unitname = strtok(0,"");     /* Rest of the line */
          if (!flags.quiet){
            if (unitname) logputs(unitname);
            logputchar('\n');
          }
          continue; 
        }
        else if (!strcmp(unitname,"set")) {
          unitname = strtok(0," ");
          unitdef = strtok(0," ");
          if (!unitname)
            readerror(errfile, 
                      "%s: no variable name specified on line %d of '%s'\n",
                      progname, linenum, file);
          else if (!unitdef)
            readerror(errfile, 
                      "%s: no value specified on line %d of '%s'\n",
                      progname, linenum, file);
          else 
            setenv(unitname, unitdef, 0);
          continue;
        }
        else if (!strcmp(unitname,"unitlist")){
          splitline(0,&unitname, &unitdef); /* 0 continues strtok call */
          if (!unitname || !unitdef)
            readerror(errfile,VAGUE_ERR);
          else {
            if (newalias(unitname, unitdef, linenum, permfile, errfile))
              goterr = 1;
          }
          continue;
        }
        else if (!strcmp(unitname, "include")){
          if (depth>MAXINCLUDE){
            readerror(errfile, 
                "%s: max include depth of %d exceeded in file '%s' line %d\n",
                progname, MAXINCLUDE, file, linenum);
          } else {
            int readerr;
            char *includefile;

            unitname = strtok(0, " "); 
            if (!unitname){
              readerror(errfile,
                        "%s: missing include filename on line %d of '%s'\n",
                        progname, linenum, file);
              continue;
            }
            includefile = mymalloc(strlen(file)+strlen(unitname)+1, "(readunits)");
            if (isfullpath(unitname))
              strcpy(includefile,unitname);
            else {
              strcpy(includefile,file);
              strcpy(pathend(includefile), unitname);
            }

            readerr = readunits(includefile, errfile, unitcount, prefixcount, 
                                funccount, depth+1);
            if (readerr == E_MEMORY){
              fclose(unitfile);
              free(line);
              free(includefile);
              return readerr;
            }
            if (readerr == E_FILE) {
              readerror(errfile, "%s:   file was included at line %d of file '%s'\n", progname,linenum, file);
            }
            
            if (readerr)
              goterr = 1;
            free(includefile);
          }
        } else                             /* not a valid command */
          readerror(errfile,VAGUE_ERR);
        continue;
      } 
      if (in_utf8 && !utf8mode) continue;
      if (wronglocale || wrongvar) continue;
      splitline(line, &unitname, &unitdef);
      if (!unitname) continue;

      if (*unitname == REDEFCHAR){
        unitname++;
        redefinition=1;
        if (strlen(unitname)==0){
          readerror(errfile,
               "%s: expecting name of unit to redefine after '+' at line %d of '%s'\n",
               progname, linenum,file);
          continue;
        }
      } else
        redefinition=0;
      if (!strcmp(unitname,"-")) {
          readerror(errfile,
               "%s: expecting prefix name before '-' at line %d of '%s'\n",
               progname, linenum,file);
          continue;
      }
      if (!unitdef){
        readerror(errfile,
              "%s: unit '%s' lacks a definition at line %d of '%s'\n",
                  progname, unitname, linenum, file);
        continue;
      }

      if (lastchar(unitname) == '-'){      /* it's a prefix definition */
        if (newprefix(unitname,unitdef,&locprefixcount,linenum,
                      permfile,errfile,redefinition))
          goterr=1;
      }
      else if (strchr(unitname,'[')){     /* table definition  */
        retcode=newtable(unitname,unitdef,&locfunccount,linenum,
                         permfile,errfile,redefinition);
        if (retcode){
          if (retcode != E_BADFILE){
            fclose(unitfile);
            free(line);
            return retcode;
          }
          goterr=1;
        }
      }
      else if (strchr(unitname,'(')){     /* function definition */
        if (newfunction(unitname,unitdef,&locfunccount,linenum,
                        permfile,errfile,redefinition))
          goterr = 1;
      }
      else {                              /* ordinary unit definition */
        if (newunit(unitname,unitdef,&locunitcount,linenum,permfile,errfile,redefinition,0))
          goterr = 1;
      }
   }
   fclose(unitfile);
   free(line);
   if (unitcount)
     *unitcount+=locunitcount;
   if (prefixcount)
     *prefixcount+=locprefixcount;
   if (funccount)
     *funccount+=locfunccount;
   if (goterr)
     return E_BADFILE;
   else return 0;
}

/* Initialize a unit to be equal to 1. */

void
initializeunit(struct unittype *theunit)
{
   theunit->factor = 1.0;
   theunit->numerator[0] = theunit->denominator[0] = NULL;
}


/* Free a unit: frees all the strings used in the unit structure.
   Does not free the unit structure itself.  */

void
freeunit(struct unittype *theunit)
{
   char **ptr;

   for(ptr = theunit->numerator; *ptr; ptr++)
     if (*ptr != NULLUNIT) free(*ptr);
   for(ptr = theunit->denominator; *ptr; ptr++)
     if (*ptr != NULLUNIT) free(*ptr);

   /* protect against repeated calls to freeunit() */

   theunit->numerator[0] = 0;  
   theunit->denominator[0] = 0;
}


/* Print out a unit  */

void
showunit(struct unittype *theunit)
{
   char **ptr;
   int printedslash;
   int counter = 1;

   logprintf(num_format.format, theunit->factor);

   for (ptr = theunit->numerator; *ptr; ptr++) {
      if (ptr > theunit->numerator && **ptr &&
          !strcmp(*ptr, *(ptr - 1)))
         counter++;
      else {
         if (counter > 1)
           logprintf("%s%d", powerstring, counter);
         if (**ptr)
           logprintf(" %s", *ptr);
         counter = 1;
      }
   }
   if (counter > 1)
     logprintf("%s%d", powerstring, counter);
   counter = 1;
   printedslash = 0;
   for (ptr = theunit->denominator; *ptr; ptr++) {
      if (ptr > theunit->denominator && **ptr &&
          !strcmp(*ptr, *(ptr - 1)))
         counter++;
      else {
         if (counter > 1)
           logprintf("%s%d", powerstring, counter);
         if (**ptr) {
            if (!printedslash)
              logprintf(" /");
            printedslash = 1;
            logprintf(" %s", *ptr);
         }
         counter = 1;
      }
   }
   if (counter > 1)
     logprintf("%s%d", powerstring, counter);
}


/* qsort comparison function */

int
compare(const void *item1, const void *item2)
{
   return strcmp(*(char **) item1, *(char **) item2);
}

/* Sort numerator and denominator of a unit so we can compare different
   units */

void
sortunit(struct unittype *theunit)
{
   char **ptr;
   int count;

   for (count = 0, ptr = theunit->numerator; *ptr; ptr++, count++);
   qsort(theunit->numerator, count, sizeof(char *), compare);
   for (count = 0, ptr = theunit->denominator; *ptr; ptr++, count++);
   qsort(theunit->denominator, count, sizeof(char *), compare);
}


/* Cancels duplicate units that appear in the numerator and
   denominator.  The input unit must be sorted. */

void
cancelunit(struct unittype *theunit)
{
   char **den, **num;
   int comp;

   den = theunit->denominator;
   num = theunit->numerator;

   while (*num && *den) { 
      comp = strcmp(*den, *num);
      if (!comp) { /* units match, so cancel them */
         if (*den!=NULLUNIT) free(*den);
         if (*num!=NULLUNIT) free(*num);  
         *den++ = NULLUNIT;
         *num++ = NULLUNIT;
      } else if (comp < 0) /* Move up whichever pointer is alphabetically */
         den++;            /* behind to look for future matches */
      else
         num++;
   }
}


/*
   Looks up the definition for the specified unit including prefix processing
   and plural removal.

   Returns a pointer to the definition or a null pointer
   if the specified unit does not appear in the units table.

   Sometimes the returned pointer will be a pointer to the special
   buffer created to hold the data.  This buffer grows as needed during 
   program execution.  

   Note that if you pass the output of lookupunit() back into the function
   again you will get correct results, but the data you passed in may get
   clobbered if it happened to be the internal buffer.  
*/

static int bufsize=0;
static char *buffer;  /* buffer for lookupunit answers with prefixes */


/* 
  Plural rules for english: add -s
  after x, sh, ch, ss   add -es
  -y becomes -ies except after a vowel when you just add -s as usual
*/
  

char *
lookupunit(char *unit,int prefixok)
{
   char *copy;
   struct prefixlist *pfxptr;
   struct unitlist *uptr;

   if ((uptr = ulookup(unit)))
      return uptr->value;

   if (strwidth(unit)>2 && lastchar(unit) == 's') {
      copy = dupstr(unit);
      lastchar(copy) = 0;
      if (lookupunit(copy,prefixok)){
         while(strlen(copy)+1 > bufsize) {
            growbuffer(&buffer, &bufsize);
         }
         strcpy(buffer, copy);  /* Note: returning looked up result seems   */
         free(copy);            /*   better but it causes problems when it  */
         return buffer;         /*   contains PRIMITIVECHAR.                */
      }
      if (strlen(copy)>2 && lastchar(copy) == 'e') {
         lastchar(copy) = 0;
         if (lookupunit(copy,prefixok)){
            while (strlen(copy)+1 > bufsize) {
               growbuffer(&buffer,&bufsize);
            }
            strcpy(buffer,copy);
            free(copy);
            return buffer;
         }
      }
      if (strlen(copy)>2 && lastchar(copy) == 'i') {
         lastchar(copy) = 'y';
         if (lookupunit(copy,prefixok)){
            while (strlen(copy)+1 > bufsize) {
               growbuffer(&buffer,&bufsize);
            }
            strcpy(buffer,copy);
            free(copy);
            return buffer;
         }
      }
      free(copy);
   }
   if (prefixok && (pfxptr = plookup(unit))) {
      copy = unit + pfxptr->len;
      if (emptystr(copy) || lookupunit(copy,0)) {
         char *tempbuf;
         while (strlen(pfxptr->value)+strlen(copy)+2 > bufsize){
            growbuffer(&buffer, &bufsize);
         }
         tempbuf = dupstr(copy);   /* copy might point into buffer */
         strcpy(buffer, pfxptr->value);
         strcat(buffer, " ");
         strcat(buffer, tempbuf);
         free(tempbuf);
         return buffer;
      }
   }
   return 0;
}


/* Points entries of product[] to the strings stored in tomove[].  
   Leaves tomove pointing to a list of NULLUNITS.  */

int
moveproduct(char *product[], char *tomove[])
{
   char **dest, **src;

   dest=product;
   for(src = tomove; *src; src++){
     if (*src == NULLUNIT) continue;
     for(; *dest && *dest != NULLUNIT; dest++);
     if (dest - product >= MAXSUBUNITS - 1) {
       return E_PRODOVERFLOW;
     }
     if (!*dest)
        *(dest + 1) = 0;
     *dest = *src;
     *src=NULLUNIT;
   }
   return 0;
}

/* 
   Make a copy of a product list.  Note that no error checking is done
   for overflowing the product list because it is assumed that the
   source list doesn't overflow, so the destination list shouldn't
   overflow either.  (This assumption could be false if the
   destination is not actually at the start of a product buffer.) 
*/

void
copyproduct(char **dest, char **source)
{
   for(;*source;source++,dest++) {
     if (*source==NULLUNIT)
       *dest = NULLUNIT;
     else
       *dest=dupstr(*source);
   }
   *dest=0;
}

/* Make a copy of a unit */ 

void
unitcopy(struct unittype *dest, struct unittype *source)
{
  dest->factor = source->factor;
  copyproduct(dest->numerator, source->numerator);
  copyproduct(dest->denominator, source->denominator);
}


/* Multiply left by right.  In the process, all of the units are
   deleted from right (but it is not freed) */

int 
multunit(struct unittype *left, struct unittype *right)
{
  int myerr;
  left->factor *= right->factor;
  myerr = moveproduct(left->numerator, right->numerator);
  if (!myerr)
    myerr = moveproduct(left->denominator, right->denominator);
  return myerr;
}

int 
divunit(struct unittype *left, struct unittype *right)
{
  int myerr;
  left->factor /= right->factor;
  myerr = moveproduct(left->numerator, right->denominator);
  if (!myerr)
    myerr = moveproduct(left->denominator, right->numerator);
  return myerr;
}


/*
   reduces a product of symbolic units to primitive units.
   The three low bits are used to return flags:

   bit 0 set if reductions were performed without error.
   bit 1 set if no reductions are performed.
   bit 2 set if an unknown unit is discovered.

   Return values from multiple calls will be ORed together later.
 */

#define DIDREDUCTION    (1<<0)
#define NOREDUCTION     (1<<1)
#define REDUCTIONERROR  (1<<2)
#define CIRCULARDEF     (1<<3)

int
reduceproduct(struct unittype *theunit, int flip)
{

   char *toadd;
   char **product;
   int didsomething = NOREDUCTION;
   struct unittype newunit;
   int ret;
   int itcount=0;    /* Count iterations to catch infinite loops */
   
   if (flip)
      product = theunit->denominator;
   else
      product = theunit->numerator;

   for (; *product; product++) {
      for (;;) {
         if (!strlen(*product))
            break;

         /* check for infinite loop */
         itcount++;
         if (itcount>MAXPRODUCTREDUCTIONS) 
           return CIRCULARDEF;
         
         toadd = lookupunit(*product,1);
         if (!toadd) {
            if (!irreducible)
              irreducible = dupstr(*product);
            return REDUCTIONERROR;
         }
         if (strchr(toadd, PRIMITIVECHAR))
            break;
         didsomething = DIDREDUCTION;
         if (*product != NULLUNIT) {
            free(*product);
            *product = NULLUNIT;
         }
         if (parseunit(&newunit, toadd, 0, 0))
            return REDUCTIONERROR;
         if (flip) ret=divunit(theunit,&newunit);
         else ret=multunit(theunit,&newunit);
         freeunit(&newunit);
         if (ret) 
            return REDUCTIONERROR;
      }
   }
   return didsomething;
}


#if 0
void showunitdetail(struct unittype *foo)
{
  char **ptr;

  printf("%.17g ", foo->factor);

  for(ptr=foo->numerator;*ptr;ptr++)
    if (*ptr==NULLUNIT) printf("NULL ");
    else printf("`%s' ", *ptr);
  printf(" / ");
  for(ptr=foo->denominator;*ptr;ptr++)
    if (*ptr==NULLUNIT) printf("NULL ");
    else printf("`%s' ", *ptr);
  putchar('\n');
}
#endif


/*
   Reduces numerator and denominator of the specified unit.
   Returns 0 on success, or 1 on unknown unit error.
 */

int
reduceunit(struct unittype *theunit)
{
   int ret;

   if (irreducible)
     free(irreducible);
   irreducible=0;
   ret = DIDREDUCTION;

   /* Keep calling reduceproduct until it doesn't do anything */

   while (ret & DIDREDUCTION) {
      ret = reduceproduct(theunit, 0);
      if (!(ret & REDUCTIONERROR))
        ret |= reduceproduct(theunit, 1);
      if (ret & REDUCTIONERROR){
         if (irreducible) 
           return E_UNKNOWNUNIT;
         else
           return E_REDUCE;
      }
      else if (ret & CIRCULARDEF)
	return E_CIRCULARDEF;
   }
   return 0;
}

/* 
   Returns one if the argument unit is defined in the data file as a   
  dimensionless unit.  This is determined by comparing its definition to
  the string NODIM.  
*/

int
ignore_dimless(char *name)
{
  struct unitlist *ul;
  if (!name) 
    return 0;
  ul = ulookup(name);
  if (ul && !strcmp(ul->value, NODIM))
    return 1;
  return 0;
}

int 
ignore_nothing(char *name)
{
  return 0;
}


int
ignore_primitive(char *name)
{
  struct unitlist *ul;
  if (!name) 
    return 0;
  ul = ulookup(name);
  if (ul && strchr(ul->value, PRIMITIVECHAR))
    return 1;
  return 0;
}


/* 
   Compare two product lists, return zero if they match and one if
   they do not match.  They may contain embedded NULLUNITs which are
   ignored in the comparison. Units defined as NODIM are also ignored
   in the comparison.
*/

int
compareproducts(char **one, char **two, int (*isdimless)(char *name))
{
   int oneblank, twoblank;
   while (*one || *two) {
      oneblank = (*one==NULLUNIT) || isdimless(*one);    
      twoblank = (*two==NULLUNIT) || isdimless(*two);    
      if (!*one && !twoblank)
         return 1;
      if (!*two && !oneblank)
         return 1;
      if (oneblank)
         one++;
      else if (twoblank)
         two++;
      else if (strcmp(*one, *two))
         return 1;
      else
         one++, two++;
   }
   return 0;
}


/* Return zero if units are compatible, nonzero otherwise.  The units
   must be reduced, sorted and canceled for this to work.  */

int
compareunits(struct unittype *first, struct unittype *second, 
             int (*isdimless)(char *name))
{
   return
      compareproducts(first->numerator, second->numerator, isdimless) ||
      compareproducts(first->denominator, second->denominator, isdimless);
}


/* Reduce a unit as much as possible */

int
completereduce(struct unittype *unit)
{
   int err;

   if ((err=reduceunit(unit)))
     return err;
   
   sortunit(unit);
   cancelunit(unit);
   return 0;
}


/* Raise theunit to the specified power.  This function does not fill
   in NULLUNIT gaps, which could be considered a deficiency. */

int
expunit(struct unittype *theunit, int  power)
{
  char **numptr, **denptr;
  double thefactor;
  int i, uind, denlen, numlen;

  if (power==0){
    freeunit(theunit);
    initializeunit(theunit);
    return 0;
  }
  numlen=0;
  for(numptr=theunit->numerator;*numptr;numptr++) numlen++;
  denlen=0;
  for(denptr=theunit->denominator;*denptr;denptr++) denlen++;
  thefactor=theunit->factor;
  for(i=1;i<power;i++){
    theunit->factor *= thefactor;
    for(uind=0;uind<numlen;uind++){
      if (theunit->numerator[uind]!=NULLUNIT){
        if (numptr-theunit->numerator>=MAXSUBUNITS-1) {
           *numptr=*denptr=0;
           return E_PRODOVERFLOW;
        }
        *numptr++=dupstr(theunit->numerator[uind]);
      }
    }
    for(uind=0;uind<denlen;uind++){
      if (theunit->denominator[uind]!=NULLUNIT){
        *denptr++=dupstr(theunit->denominator[uind]);
        if (denptr-theunit->denominator>=MAXSUBUNITS-1) {
          *numptr=*denptr=0;
          return E_PRODOVERFLOW;
        }
      }   
    }
  }
  *numptr=0;
  *denptr=0;
  return 0;
}


int
unit2num(struct unittype *input)
{
  struct unittype one;
  int err;

  initializeunit(&one);
  if ((err=completereduce(input)))
    return err;
  if (compareunits(input,&one,ignore_nothing))
    return E_NOTANUMBER;
  freeunit(input);
  return 0;
}


int
unitdimless(struct unittype *input)
{
  struct unittype one;
  initializeunit(&one);
  if (compareunits(input, &one, ignore_dimless))
    return 0;
  freeunit(input);  /* Eliminate dimensionless units from list */
  return 1;
}
                       

/* 
   The unitroot function takes the nth root of an input unit which has
   been completely reduced.  Returns 1 if the unit is not a power of n. 
   Input data can contain NULLUNITs.  
*/

int 
subunitroot(int n,char *current[], char *out[])
{
  char **ptr;
  int count=0;

  while(*current==NULLUNIT) current++;  /* skip past NULLUNIT entries */
  ptr=current;
  while(*ptr){
    while(*ptr){
      if (*ptr!=NULLUNIT){
        if (strcmp(*current,*ptr)) break;
        count++;
      }
      ptr++;
    }
    if (count % n != 0){  /* If not dimensionless generate error, otherwise */
      if (!ignore_dimless(*current))    /* just skip over it */
        return E_NOTROOT;
    } else {
      for(count /= n;count>0;count--) *(out++) = dupstr(*current);
    }
    current=ptr;
  }
  *out = 0;
  return 0;
}
  

int 
rootunit(struct unittype *inunit,int n)
{
   struct unittype outunit;
   int err;

   initializeunit(&outunit);
   if ((err=completereduce(inunit)))
     return err;
   /* Roots of negative numbers fail in pow(), even odd roots */
   if (inunit->factor < 0)
     return E_NOTROOT;
   outunit.factor = pow(inunit->factor,1.0/(double)n);
   if ((err = subunitroot(n, inunit->numerator, outunit.numerator)))
     return err;
   if ((err = subunitroot(n, inunit->denominator, outunit.denominator)))
     return err;
   freeunit(inunit);
   initializeunit(inunit);
   return multunit(inunit,&outunit);
}


/* Compute the inverse of a unit (1/theunit) */

void
invertunit(struct unittype *theunit)
{
  char **ptr, *swap;
  int numlen, length, ind;

  theunit->factor = 1.0/theunit->factor;  
  length=numlen=0;
  for(ptr=theunit->denominator;*ptr;ptr++,length++);
  for(ptr=theunit->numerator;*ptr;ptr++,numlen++);
  if (numlen>length)
    length=numlen;
  for(ind=0;ind<=length;ind++){
    swap = theunit->numerator[ind];
    theunit->numerator[ind] = theunit->denominator[ind];
    theunit->denominator[ind] = swap;
  }
}


int
float2rat(double y, int *p, int *q)
{
  int coef[20];           /* How long does this buffer need to be? */
  int i,termcount,saveq;
  double fracpart,x;

  /* Compute continued fraction approximation */

  x=y;
  termcount=0;
  while(1){
    coef[termcount] = (int) floor(x);
    fracpart = x-coef[termcount];
    if (fracpart < .001 || termcount==19) break;
    x = 1/fracpart;
    termcount++;
  }

  /* Compress continued fraction into rational p/q */
 
  *p=0;
  *q=1;
  for(i=termcount;i>=1;i--) {
    saveq=*q;
    *q = coef[i] * *q + *p;
    *p = saveq;
  }
  *p+=*q*coef[0];
  return *q<MAXSUBUNITS && fabs((double)*p / (double)*q - y) < DBL_EPSILON;
}


/* Raise a unit to a power */

int
unitpower(struct unittype *base, struct unittype *exponent)
{
  int errcode, p, q;

  errcode = unit2num(exponent);
  if (errcode == E_NOTANUMBER)
    return E_DIMEXPONENT;
  if (errcode) 
    return errcode;
  errcode = unit2num(base);
  if (!errcode){                     /* Exponent base is dimensionless */
    base->factor = pow(base->factor,exponent->factor);
    if (errno)
      return E_FUNC;
  }
  else if (errcode==E_NOTANUMBER) {          /* Base not dimensionless */
    if (!float2rat(exponent->factor,&p,&q)){ /* Exponent must be rational */
      if (unitdimless(base)){
        base->factor = pow(base->factor,exponent->factor);
        if (errno)
          return E_FUNC;
      }
      else
        return E_IRRATIONAL_EXPONENT;
    } else {
      if (q!=1) {
        errcode = rootunit(base, q);
        if (errcode == E_NOTROOT) 
          return E_BASE_NOTROOT;
        if (errcode)
          return errcode;
      }
      errcode = expunit(base, abs(p));
      if (errcode)
        return errcode;
      if (p<0)
        invertunit(base);
    }
  } 
  else return errcode;
  return 0;
}


/* Old units program would give message about what each operand
   reduced to, showing that they weren't conformable.  Can this
   be achieved here?  */

int
addunit(struct unittype *unita, struct unittype *unitb)
{
  int err;

  if ((err=completereduce(unita)))
    return err;
  if ((err=completereduce(unitb)))
    return err;
  if (compareunits(unita,unitb,ignore_nothing))
    return E_BADSUM;
  unita->factor += unitb->factor;
  freeunit(unitb);
  return 0;
}


double
linearinterp(double  a, double b, double aval, double bval, double c)
{
  double lambda;

  lambda = (b-c)/(b-a);
  return lambda*aval + (1-lambda)*bval;
}


/* evaluate a user function */

#define INVERSE 1
#define FUNCTION 0
#define ALLERR 1
#define NORMALERR 0

int
evalfunc(struct unittype *theunit, struct func *infunc, int inverse, 
         int allerrors)
{
   struct unittype result;
   struct functype *thefunc;
   int err;
   double value;
   int foundit, count;
   struct unittype *save_value;
   char *save_function;

   if (infunc->table) {  /* Tables are short, so use dumb search algorithm */
     err = parseunit(&result, infunc->tableunit, 0, 0);
     if (err)
       return E_BADFUNCDIMEN;
     if (inverse){
       err = divunit(theunit, &result);
       if (err)
         return err;
       err = unit2num(theunit);
       if (err==E_NOTANUMBER)
         return E_BADFUNCARG;
       if (err)
         return err;
       value = theunit->factor;
       foundit=0;
       for(count=0;count<infunc->tablelen-1;count++)
         if ((infunc->table[count].value<=value &&
              value<=infunc->table[count+1].value) ||
             (infunc->table[count+1].value<=value &&
              value<=infunc->table[count].value)){
           foundit=1;
           value  = linearinterp(infunc->table[count].value,
                                 infunc->table[count+1].value,
                                 infunc->table[count].location,
                                 infunc->table[count+1].location,
                                 value);
           break;
         }
       if (!foundit)
         return E_NOTINDOMAIN;
       freeunit(&result);
       freeunit(theunit);
       theunit->factor = value;
       return 0;
     } else {
       err=unit2num(theunit);
       if (err)
         return err;
       value=theunit->factor;
       foundit=0;
       for(count=0;count<infunc->tablelen-1;count++)
         if (infunc->table[count].location<=value &&
             value<=infunc->table[count+1].location){
           foundit=1;
           value =  linearinterp(infunc->table[count].location,
                        infunc->table[count+1].location,
                        infunc->table[count].value,
                        infunc->table[count+1].value,
                        value);
           break;
         } 
       if (!foundit)
         return E_NOTINDOMAIN;
       result.factor *= value;
     }
   } else {  /* it's a function */
     if (inverse){
       thefunc=&(infunc->inverse);
       if (!thefunc->def)
         return E_NOINVERSE;
     }
     else
       thefunc=&(infunc->forward);
     err = completereduce(theunit);
     if (err)
       return err;
     if (thefunc->dimen){
       err = parseunit(&result, thefunc->dimen, 0, 0);
       if (err)
         return E_BADFUNCDIMEN;
       err = completereduce(&result);
       if (err)
         return E_BADFUNCDIMEN;
       if (compareunits(&result, theunit, ignore_nothing))
         return E_BADFUNCARG;
       value = theunit->factor/result.factor;
     } else 
       value = theunit->factor;
     if (thefunc->domain_max && 
         (value > *thefunc->domain_max || 
          (thefunc->domain_max_open && value == *thefunc->domain_max)))
       return E_NOTINDOMAIN;
     if (thefunc->domain_min && 
         (value < *thefunc->domain_min ||
          (thefunc->domain_min_open && value == *thefunc->domain_min)))
       return E_NOTINDOMAIN;
     save_value = parameter_value;
     save_function = function_parameter;
     parameter_value = theunit;
     function_parameter = thefunc->param;
     err = parseunit(&result, thefunc->def, 0,0);
     function_parameter = save_function;
     parameter_value = save_value;
     if (err && (allerrors == ALLERR || err==E_PARSEMEM || err==E_PRODOVERFLOW 
                 || err==E_NOTROOT || err==E_BADFUNCTYPE))
       return err;
     if (err)
       return E_FUNARGDEF;
   }
   freeunit(theunit);
   initializeunit(theunit);
   multunit(theunit, &result);
   return 0;
}


/*
    append a formatted string to a buffer; first character of buffer
    should be '\0' on first call
*/
size_t
vbufprintf(char **buf, size_t *bufsize, char *fmt, ...)
{
    va_list args;
    size_t
	oldlen,			/* length of current buffer contents */
	newlen,			/* length of string to be added */
	buflen;			/* length of new buffer contents */
    double growfactor = 1.5;
    static char *newbuf = NULL;
    char *oldbuf;

    oldlen = strlen(*buf);
    oldbuf = dupstr(*buf);

    /* get length of formatted string to be appended to buffer */
    va_start(args, fmt);
    newlen = vsnprintf(NULL, 0, fmt, args);
    va_end(args);

    /* allocate a buffer for the new string */
    newbuf = (char *) malloc(newlen + 1);
    if (newbuf == NULL) {
	fprintf(stderr, "%s (bufprintf): memory allocation error\n", progname);  
	exit(EXIT_FAILURE); 
    }

    /* expand main buffer if necessary */
    if (*bufsize < oldlen + newlen + 1) {
	*bufsize = (size_t) ((oldlen + newlen) * growfactor + 1);

	*buf = (char *) realloc(*buf, *bufsize);
	if (*buf == NULL) {
	    fprintf(stderr, "%s (bufprintf): memory allocation error\n", progname);  
	    exit(EXIT_FAILURE); 
	}
    }

    /* generate the new formatted string */
    va_start(args, fmt);
    newlen = vsprintf(newbuf, fmt, args);
    va_end(args);

    /* copy old and new strings to buffer */
    strcpy(*buf, oldbuf);
    strcat(*buf, newbuf);
    buflen = strlen(*buf);

    free(oldbuf);
    free(newbuf);

    return buflen;
}


/*
    similar to showunit(), but it saves the string in a buffer rather
    than sending it to an output stream
*/
char *
buildunitstr(struct unittype *theunit)
{
    char **ptr;
    char *buf;
    int printedslash;
    int counter = 1;
    size_t bufsize, newlen;

    bufsize = 256;
    buf = (char *) mymalloc(bufsize, "(buildunitstr)");
    *buf = '\0';

    /* factor */
    newlen = vbufprintf(&buf, &bufsize, num_format.format, theunit->factor);

    /* numerator */
    for (ptr = theunit->numerator; *ptr; ptr++) {
	if (ptr > theunit->numerator && **ptr &&
	  !strcmp(*ptr, *(ptr - 1)))
	    counter++;
	else {
	    if (counter > 1)
		newlen = vbufprintf(&buf, &bufsize, "%s%d", powerstring, counter);
		if (**ptr)
		    newlen = vbufprintf(&buf, &bufsize, " %s", *ptr);
		counter = 1;
	}
    }
    if (counter > 1)
	newlen = vbufprintf(&buf, &bufsize, "%s%d", powerstring, counter);
    counter = 1;
    printedslash = 0;

    /* denominator */
    for (ptr = theunit->denominator; *ptr; ptr++) {
	if (ptr > theunit->denominator && **ptr &&
          !strcmp(*ptr, *(ptr - 1)))
	    counter++;
	else {
	    if (counter > 1)
		newlen = vbufprintf(&buf, &bufsize, "%s%d", powerstring, counter);
		if (**ptr) {
		    if (!printedslash)
			newlen = vbufprintf(&buf, &bufsize, " /");
		    printedslash = 1;
		    newlen = vbufprintf(&buf, &bufsize, " %s", *ptr);
		}
	    counter = 1;
	}
    }
    if (counter > 1)
	newlen = vbufprintf(&buf, &bufsize, "%s%d", powerstring, counter);

   return buf;
}

/* 
   If the given character string has only one unit name in it, then print out
   the rule for that unit.  In any case, print out the reduced form for
   the unit.
*/

void
showdefinition(char *unitstr, struct unittype *theunit)
{
  size_t bufsize = 256;
  char *buf, *showstr;

  logputs(deftext);
  showstr = buildunitstr(theunit);
  buf = (char *) mymalloc(bufsize, "(showdefinition)");

  while((unitstr = lookupunit(unitstr,1))
        && strspn(unitstr,digits) != strlen(unitstr)
        && !strchr(unitstr,PRIMITIVECHAR)) {
    if (strlen(unitstr) > bufsize - 1) {
	bufsize = strlen(unitstr) + 1;
	buf = realloc(buf, bufsize);
    }
    tightbufprint(buf, unitstr);
    logputs(buf);
    if (strcmp(buf, showstr))
	logputs(" = ");
  } 

  if (strcmp(buf, showstr))
      logputs(showstr);
  logputchar('\n');
  free(buf);
  free(showstr);
}


void 
showfunction(struct functype *func)
{
  struct unittype unit;
  int not_dimensionless, i;

  if (!func->def) {
    logputs(" is undefined");
    return;
  }

  if (func->dimen){                       /* coverity[check_return] */
    parseunit(&unit,func->dimen,0,0);     /* unit2num returns 0 for */
    not_dimensionless = unit2num(&unit);  /* dimensionless units    */
  } 
    
  logprintf("(%s) = %s", func->param, func->def);
  if (func->domain_min || func->domain_max){
    logputchar('\n');
    for(i=strwidth(deftext);i;i--) logputchar(' ');
    logputs("defined for ");
    if (func->domain_min && func->domain_max) {
      logprintf(num_format.format, *func->domain_min);
      if (func->dimen && (not_dimensionless || unit.factor != 1)){
        if (isdecimal(*func->dimen))
          logputs(" *");
        logprintf(" %s",func->dimen);
      }
      logputs(func->domain_min_open?" < ":" <= ");
    }
    logputs(func->param);
    if (func->domain_max){
      logputs(func->domain_max_open?" < ":" <= ");
      logprintf(num_format.format, *func->domain_max);
    }
    else {
      logputs(func->domain_min_open?" > ":" >= ");
      logprintf(num_format.format, *func->domain_min);
    }
    if (func->dimen && (not_dimensionless || unit.factor != 1)){
      if (isdecimal(*func->dimen))
        logputs(" *");
      logprintf(" %s",func->dimen);
    }
    if (!func->dimen) logputs(" (any units)");
  } else if (func->dimen){
    logputchar('\n');
    for(i=strwidth(deftext);i;i--) logputchar(' ');
    if (not_dimensionless) 
      logprintf("%s has units %s",func->param, func->dimen);
    else
      logprintf("%s is dimensionless",func->param);
  }    
  logputchar('\n');
}

void
showtable(struct func *fun, int inverse)
{
  int i;

  logprintf("%sinterpolated table with points\n",deftext);
  if (inverse){
    int reverse, j;
    reverse = (fun->table[0].value > fun->table[fun->tablelen-1].value);
    for(i=0;i<fun->tablelen;i++){
      if (reverse) j = fun->tablelen-i-1;
      else j=i;
      if (flags.verbose>0)
        logputs("\t\t    ");
      logprintf("~%s(", fun->name);
      logprintf(num_format.format, fun->table[j].value);
      if (isdecimal(fun->tableunit[0]))
        logputs(" *");
      logprintf(" %s",fun->tableunit);
      logputs(") = ");
      logprintf(num_format.format, fun->table[j].location);
      logputchar('\n');
    }
  } else {
    for(i=0;i<fun->tablelen;i++){
      if (flags.verbose>0)
        logputs("\t\t    ");
      logprintf("%s(", fun->name);
      logprintf(num_format.format, fun->table[i].location);
      logputs(") = ");
      logprintf(num_format.format, fun->table[i].value);
      if (isdecimal(fun->tableunit[0]))
        logputs(" *");
      logprintf(" %s\n",fun->tableunit);
    }
  }
}


void
showfuncdefinition(struct func *fun, int inverse)
{
  if (fun->table)  /* It's a table */
    showtable(fun, inverse);
  else { 
    logprintf("%s%s%s", deftext,inverse?"~":"", fun->name);
    if (inverse)
      showfunction(&fun->inverse);
    else
      showfunction(&fun->forward);
  }
}


void
showunitlistdef(struct wantalias *alias)
{
  logprintf("%sunit list, ",deftext);
  tightprint(stdout,alias->definition);
  if (logfile) tightprint(logfile,alias->definition);
  logputchar('\n');
}


/* Show conversion to a function.  Input unit 'have' is replaced by the 
   function inverse and completely reduced. */

int
showfunc(char *havestr, struct unittype *have, struct func *fun)
{
   int err;
   char *dimen;

   err = evalfunc(have, fun, INVERSE, NORMALERR);
   if (!err)
     err = completereduce(have);
   if (err) {
     if (err==E_BADFUNCARG){
       logputs("conformability error");
       if (fun->table)
         dimen = fun->tableunit;
       else if (fun->inverse.dimen)
         dimen = fun->inverse.dimen;
       else 
         dimen = 0;
       if (!dimen)
         logputchar('\n');
       else {
         struct unittype want;
         
         if (emptystr(dimen))
           dimen = "1";
         logprintf(": conversion requires dimensions of '%s'\n",dimen);
         if (flags.verbose==2) logprintf("\t%s = ",havestr);
         else if (flags.verbose==1) logputchar('\t');
         showunit(have);
         if (flags.verbose==2) logprintf("\n\t%s = ",dimen);
         else if (flags.verbose==1) logprintf("\n\t");
         else logputchar('\n');            /* coverity[check_return] */
         parseunit(&want, dimen, 0, 0);    /* coverity[check_return] */
         completereduce(&want);         /* dimen was already checked for */
         showunit(&want);               /* errors so no need to check here */
         logputchar('\n');
         }
     } else if (err==E_NOTINDOMAIN)
       logprintf("Value '%s' is not in the function's range\n",havestr);
     else if (err==E_NOINVERSE)
       logprintf("Inverse of the function '%s' is not defined\n",fun->name);
     else
       logputs("Function evaluation error (bad function definition)\n");
     return 1;
   }
   if (flags.verbose==2)
     logprintf("\t%s = %s(", havestr, fun->name);
   else if (flags.verbose==1) 
     logputchar('\t');
   showunit(have);
   if (flags.verbose==2)
     logputchar(')');
   logputchar('\n');
   return 0;
}

/* Print the conformability error message */

void
showconformabilityerr(char *havestr,struct unittype *have,
                      char *wantstr,struct unittype *want)
{
  logputs("conformability error\n");
  if (flags.verbose==2)
    logprintf("\t%s = ",havestr);
  else if (flags.verbose==1)
    logputchar('\t');
  showunit(have);
  if (flags.verbose==2)
    logprintf("\n\t%s = ",wantstr);
  else if (flags.verbose==1)
    logputs("\n\t");
  else
    logputchar('\n');
  showunit(want);
  logputchar('\n');
} /* end showconformabilityerr */



/*
  determine whether a unit string begins with a fraction; assume it
  does if it starts with an integer, '|', and another integer
*/
int
isfract(const char *unitstr)
{
  char *enddouble=0, *endlong=0;

  while (isdigit(*unitstr))
    unitstr++;
  if (*unitstr++ == '|') {
    (void)strtod(unitstr, &enddouble);
    (void)strtol(unitstr, &endlong, 10);
    if (enddouble == endlong)
      return 1;
  }
  return 0;
}

int
checksigdigits(char *arg)
{
  int errors, ival;
  char *nonum;

  errors = 0;

  if (!strcmp(arg, "max"))
    num_format.precision = MAXPRECISION;
  else {
    ival = (int) strtol(arg, &nonum, 10);
    if (!emptystr(nonum)) {
      fprintf(stderr,
      "%s: invalid significant digits (%s)--integer value or 'max' required\n",
              progname, arg);
      errors++;
    }
    else if (ival <= 0) {
      fprintf(stderr, "%s: number of significant digits must be positive\n",
              progname);
      errors++;
    }
    else if (ival > MAXPRECISION) {
      fprintf(stderr,
           "%s: too many significant digits (%d)--using maximum value (%d)\n",
           progname, ival, MAXPRECISION);
      num_format.precision = MAXPRECISION;
    }
    else
      num_format.precision = ival;
  }
  if (errors)
    return -1;
  else
    return 0;
}

/* set output number format specification from significant digits and type */

int
setnumformat()
{
  size_t len;

  if (strchr("Ee", num_format.type))
    num_format.precision--;

  len = 4;      /* %, decimal point, type, terminating NUL */
  if (num_format.precision > 0)
    len += (size_t) floor(log10((double) num_format.precision))+1;
  num_format.format = (char *) mymalloc(len, "(setnumformat)");
  sprintf(num_format.format, "%%.%d%c", num_format.precision, num_format.type);
  return 0;
}

/*
    parse and validate the output number format specification and
    extract its type and precision into the num_format structure.
    Returns nonzero for invalid format.
*/

int
parsenumformat()
{
  static char *format_types = NULL;
  static char *format_flags = "+-# 0'";
  static char badflag;
  char *two = "0x1p+1";
  char *valid="ABCDEFGHIJKLMNOPQRSTUVWXYXabcdefghijklmnopqrstuvwxyx.01234567890";
  char *dotptr, *lptr, *nonum, *p;
  char testbuf[80];
  int errors, ndx;

  if (format_types == NULL){
    format_types = (char *) mymalloc(strlen(BASE_FORMATS)+4, "(parsenumformat)");
    strcpy(format_types,BASE_FORMATS);

    /* check for support of type 'F' (MS VS 2012 doesn't have it) */
    sprintf(testbuf, "%.1F", 1.2);
    if (strlen(testbuf) == 3 && testbuf[0] == '1' && testbuf[2] == '2')
      strcat(format_types,"F");

    /* check for support of hexadecimal floating point */
    sprintf(testbuf, "%.0a", 2.0);
    if (!strcmp(testbuf,two))
      strcat(format_types, "aA");

    /* check for support of digit-grouping (') flag */
    sprintf(testbuf, "%'.0f", 1234.0);
    if (strlen(testbuf) > 2 && testbuf[0] == '1' && testbuf[2] == '2')
      badflag = '\0'; /* supported */
    else
      badflag = '\''; /* not supported */
  }

  errors = 0;

  p = num_format.format;

  if (*p != '%') {
    fprintf(stderr, "%s: number format specification must start with '%%'\n",
            progname);
    errors++;
  }
  else if (strrchr(num_format.format, '%') != num_format.format) {
    fprintf(stderr, "%s: only one '%%' allowed in number format specification\n",
            progname);
    errors++;
    p++;
  }
  else
    p++;

  dotptr = strchr(num_format.format, '.');
  if (dotptr && strrchr(num_format.format, '.') != dotptr) {
    fprintf(stderr, "%s: only one '.' allowed in number format specification\n",
            progname);
    errors++;
  }

  /* skip over flags */
  while (*p && strchr(format_flags, *p)) {
    if (*p == badflag) {   /* only if digit-grouping flag (') not supported */
      fprintf(stderr, "%s: digit-grouping flag (') not supported\n", progname);
      errors++;
    }
    p++;
  }

  /* check for type length modifiers, which aren't allowed */
  if ((lptr = strstr(num_format.format, "hh"))
     || (lptr = strstr(num_format.format, "ll"))) {
    fprintf(stderr, "%s: type length modifier (%.2s) not supported\n", progname, lptr);
    errors++;
  }
  else if ((lptr = strpbrk(num_format.format, "hjLltz"))) {
    fprintf(stderr, "%s: type length modifier (%c) not supported\n", progname, lptr[0]);
    errors++;
  }

  /* check for other invalid characters */
  ndx = strspn(p, valid);
  if (ndx < strlen(p)) {
    fprintf(stderr, "%s: invalid character (%c) in width, precision, or type\n",
    progname, p[ndx]);
    errors++;
  }

  if (errors) { /* results of any other checks are likely to be misleading */
    fprintf(stderr, "%s: invalid number format specification (%s)\n", 
                    progname, num_format.format);
    fprintf(stderr, "%s: valid specification is %%[flags][width][.precision]type\n",
            progname);
    return -1;
  }

  /* get width and precision if specified; check precision */
  num_format.width = (int) strtol(p, &nonum, 10);

  if (*nonum == '.'){
    if (isdigit(nonum[1]))
      num_format.precision = (int) strtol(nonum+1, &nonum, 10);
    else {
      num_format.precision = 0;
      nonum++;
    }
  }
  else  /* precision not given--use printf() default */
    num_format.precision = 6;

  /* check for valid format type */
  if (emptystr(nonum)) {
    fprintf(stderr, "%s: missing format type\n", progname);
    errors++;
  }
  else {
    if (strchr(format_types, *nonum)) {
      if (nonum[1]) {
        fprintf(stderr, "%s: invalid character(s) (%s) after format type\n",
                progname, nonum + 1);
        errors++;
      }
      else 
        num_format.type = *nonum;
    }
    else {
      fprintf(stderr,
              "%s: invalid format type (%c)--valid types are [%s]\n",
              progname, *nonum, format_types);
      errors++;
    }
  }

  if (num_format.precision == 0 && 
      (num_format.type == 'G' || num_format.type == 'g'))
    num_format.precision = 1;

  if (errors) {
    fprintf(stderr, "%s: invalid number format specification (%s)\n", 
                    progname, num_format.format);
    fprintf(stderr, "%s: valid specification is %%[flags][width][.precision]type\n",
            progname);
    return -1;
  }
  else
    return 0;
}

/*
   round a number to the lesser of the displayed precision or the
   remaining significant digits; indicate in hasnondigits if a number
   will contain any character other than the digits 0-9 in the current
   display format.
*/

double
round_output(double value, int sigdigits, int *hasnondigits)
{
  int buflen;
  char *buf;
  double rounded;  
  double mult_factor, rdigits;
  int fmt_digits;       /* decimal significant digits in format */

  if (!isfinite(value)){
    if (hasnondigits)
      *hasnondigits = 1;
    return value;
  }

  fmt_digits = num_format.precision;
  switch (num_format.type) {
    case 'A':
    case 'a':
      sigdigits = round(sigdigits * log2(10) / 4);
      fmt_digits++;
      break;
    case 'E':
    case 'e':
      fmt_digits++;
      break;
    case 'F':
    case 'f':
      if (fabs(value) > 0)
        fmt_digits += ceil(log10(fabs(value)));
      break;
  }

  if (sigdigits < fmt_digits)
    rdigits = sigdigits;
  else
    rdigits = fmt_digits;

  /* place all significant digits to the right of the radix */
  if (value != 0)
    rdigits -= ceil(log10(fabs(value)));
  /* then handle like rounding to specified decimal places */
  mult_factor = pow(10.0, rdigits);
  rounded = round(value * mult_factor) / mult_factor;

  /* allow for sign (1), radix (1), exponent (5), E or E formats (1), NUL */
  buflen = num_format.precision + 9;

  if (num_format.width > buflen)
    buflen = num_format.width;

  if (strchr("Ff", num_format.type)) {
    int len=num_format.precision+2;
    if (fabs(value) > 1.0)
      len += (int) floor(log10(fabs(value))) + 1;
    if (len > buflen)
      buflen = len;
  }

  /* allocate space for thousands separators with digit-grouping (') flag */
  /* assume worst case--that all groups are two digits */
  if (strchr(num_format.format, '\'') && strchr("FfGg", num_format.type)) 
    buflen = buflen*3/2;

  buf = (char *) mymalloc(buflen, "(round_output)");
  sprintf(buf, num_format.format, value);

  if (hasnondigits){
    if (strspn(buf, "1234567890") != strlen(buf))
      *hasnondigits = 1;
    else
      *hasnondigits = 0;
  }

  free(buf);
  return rounded;
}

/* 
   Determine significant digits in remainder relative to an original
   value which is assumed to have full double precision.  Returns
   the number of binary or decimal digits depending on the value
   of base, which must be 2 or 10. 
*/

int
getsigdigits(double original, double remainder, int base)
{
  int sigdigits;
  double maxdigits;
  double (*logfunc)(double);

  if (base == 2) {
    maxdigits = DBL_MANT_DIG;
    logfunc = log2;
  }
  else {
    maxdigits = DBL_MANT_DIG * log10(2.0);
    logfunc = log10;
  }

  if (original == 0)
    return floor(maxdigits);
  else if (remainder == 0)
    return 0;

  sigdigits = floor(maxdigits - logfunc(fabs(original/remainder)));

  if (sigdigits < 0)
    sigdigits = 0;

  return sigdigits;
}

/* Rounds a double to the specified number of binary or decimal 
   digits.  The base argument must be 2 or 10.  */

double
round_digits(double value, int digits, int base)
{
  double mult_factor;
  double (*logfunc)(double);

  if (digits == 0)
    return 0.0;

  if (base == 2)
    logfunc = log2;
  else
    logfunc = log10;

  if (value != 0)
    digits -= ceil(logfunc(fabs(value)));

  mult_factor = pow((double) base, digits);

  return round(value*mult_factor)/mult_factor;
}


/* Returns true if the value will display as equal to the reference 
   and if hasnondigits is non-null then return true if the displayed
   output contains any character in "0123456789".  */

int 
displays_as(double reference, double value, int *hasnondigits)
{
  int buflen;
  char *buf;
  double rounded;  

  if (!isfinite(value)){
    if (hasnondigits)
      *hasnondigits = 1;
    return 0;
  }
  
  /* allow for sign (1), radix (1), exponent (5), E or E formats (1), NUL */
  buflen = num_format.precision + 9;

  if (num_format.width > buflen)
    buflen = num_format.width;

  if (strchr("Ff", num_format.type)) {
    int len=num_format.precision+2;
    if (fabs(value) > 1.0)
      len += (int) floor(log10(fabs(value))) + 1;
    if (len > buflen)
      buflen = len;
  }

  /* allocate space for thousands separators with digit-grouping (') flag */
  /* assume worst case--that all groups are two digits */
  if (strchr(num_format.format, '\'') && strchr("FfGg", num_format.type)) 
    buflen = buflen*3/2;

  buf = (char *) mymalloc(buflen, "(round_to_displayed)");
  sprintf(buf, num_format.format, value);

  if (hasnondigits){
    if (strspn(buf, "1234567890") != strlen(buf))
      *hasnondigits = 1;
    else
      *hasnondigits = 0;
  }
  rounded = strtod(buf, NULL);
  free(buf);
  
  return rounded==reference;
}



/* Print the unit in 'unitstr' along with any necessary punctuation.
   The 'value' is the multiplier for the unit.  If printnum is set
   to PRINTNUM then this value is printed, or set it to NOPRINTNUM
   to prevent the value from being printed. 
*/

#define PRINTNUM 1
#define NOPRINTNUM 0

void
showunitname(double value, char *unitstr, int printnum)
{
  int hasnondigits;     /* flag to indicate nondigits in displayed value */
  int is_one;           /* Does the value display as 1? */

  is_one = displays_as(1, value, &hasnondigits);

  if (printnum && !(is_one && isdecimal(*unitstr)))
    logprintf(num_format.format, value);

  if (strpbrk(unitstr, "+-"))   /* show sums and differences of units */
    logprintf(" (%s)", unitstr);   /* in parens */
     /* fractional unit 1|x and multiplier is all digits and not one--   */
     /* no space or asterisk or numerator (3|8 in instead of 3 * 1|8 in) */
  else if (printnum && !flags.showfactor
           && startswith(unitstr,"1|") && isfract(unitstr)
           && !is_one && !hasnondigits)
    logputs(unitstr+1);
     /* multiplier is unity and unit begins with a number--no space or       */
     /* asterisk (multiplier was not shown, and the space was already output)*/
  else if (is_one && isdecimal(*unitstr))
    logputs(unitstr);
     /* unitstr begins with a non-fraction number and multiplier was */
     /* shown--prefix a spaced asterisk */
  else if (isdecimal(unitstr[0]))
    logprintf(" * %s", unitstr);
  else
    logprintf(" %s", unitstr);
} 


/* Show the conversion factors or print the conformability error message */

int
showanswer(char *havestr,struct unittype *have,
           char *wantstr,struct unittype *want)
{
   struct unittype invhave;
   int doingrec;  /* reciprocal conversion? */
   char *right = NULL, *left = NULL;

   doingrec=0;
   if (compareunits(have, want, ignore_dimless)) {
        char **src,**dest;

        invhave.factor=1/have->factor;
        for(src=have->numerator,dest=invhave.denominator;*src;src++,dest++)
           *dest=*src;
        *dest=0;
        for(src=have->denominator,dest=invhave.numerator;*src;src++,dest++)
           *dest=*src;
        *dest=0;
        if (flags.strictconvert || compareunits(&invhave, want, ignore_dimless)){
          showconformabilityerr(havestr, have, wantstr, want);
          return -1;
        }
        if (flags.verbose>0)
          logputchar('\t');
        logputs("reciprocal conversion\n");
        have=&invhave;
        doingrec=1;
   } 
   if (flags.verbose==2) {
     if (!doingrec) 
       left=right="";
     else if (strchr(havestr,'/')) {
       left="1 / (";
       right=")";
     } else {
       left="1 / ";
       right="";
     }
   }   

   /* Print the first line of output. */

   if (flags.verbose==2) 
     logprintf("\t%s%s%s = ",left,havestr,right);
   else if (flags.verbose==1)
     logputs("\t* ");
   if (flags.verbose==2)
     showunitname(have->factor / want->factor, wantstr, PRINTNUM);
   else
     logprintf(num_format.format, have->factor / want->factor);

   /* Print the second line of output. */

   if (!flags.oneline){
     if (flags.verbose==2) 
       logprintf("\n\t%s%s%s = (1 / ",left,havestr,right);
     else if (flags.verbose==1)
       logputs("\n\t/ ");
     else 
       logputchar('\n');
     logprintf(num_format.format, want->factor / have->factor);
     if (flags.verbose==2) {
       logputchar(')');
       showunitname(0,wantstr, NOPRINTNUM); 
     }
   }
   logputchar('\n');
   return 0;
}


/* Checks that the function definition has a valid inverse 
   Prints a message to stdout if function has bad definition or
   invalid inverse. 
*/

#define SIGN(x) ( (x) > 0.0 ?   1 :   \
                ( (x) < 0.0 ? (-1) :  \
                                0 ))

void
checkfunc(struct func *infunc, int verbose)
{
  struct unittype theunit, saveunit;
  struct prefixlist *prefix;
  int err, i;
  double direction;

  if (infunc->skip_error_check){
    if (verbose)
      printf("skipped function '%s'\n", infunc->name);
    return;
  }
  if (verbose)
    printf("doing function '%s'\n", infunc->name);
  if ((prefix=plookup(infunc->name)) 
      && strlen(prefix->name)==strlen(infunc->name))
    printf("Warning: '%s' defined as prefix and function\n",infunc->name);
  if (infunc->table){
    /* Check for valid unit for the table */
    if (parseunit(&theunit, infunc->tableunit, 0, 0) ||
        completereduce(&theunit))
      printf("Table '%s' has invalid units '%s'\n",
             infunc->name, infunc->tableunit);
    freeunit(&theunit);

    /* Check for monotonicity which is needed for unique inverses */
    if (infunc->tablelen<=1){ 
      printf("Table '%s' has only one data point\n", infunc->name);
      return;
    }
    direction = SIGN(infunc->table[1].value -  infunc->table[0].value);
    for(i=2;i<infunc->tablelen;i++)
      if (SIGN(infunc->table[i].value-infunc->table[i-1].value) != direction){
        printf("Table '%s' lacks unique inverse around entry " ERRNUMFMT "\n",
               infunc->name, infunc->table[i].location);
        return;
      }
    return;
  }
  if (infunc->forward.dimen){
    if (parseunit(&theunit, infunc->forward.dimen, 0, 0) ||
        completereduce(&theunit)){
      printf("Function '%s' has invalid units '%s'\n", 
             infunc->name, infunc->forward.dimen);
      freeunit(&theunit);
      return;
    }
  } else initializeunit(&theunit); 
  if (infunc->forward.domain_max && infunc->forward.domain_min)
    theunit.factor *= 
             (*infunc->forward.domain_max+*infunc->forward.domain_min)/2;
  else if (infunc->forward.domain_max) 
    theunit.factor = theunit.factor * *infunc->forward.domain_max - 1;
  else if (infunc->forward.domain_min)
    theunit.factor = theunit.factor * *infunc->forward.domain_min + 1;
  else 
    theunit.factor *= 7;   /* Arbitrary choice where we evaluate inverse */
  if (infunc->forward.dimen){
    unitcopy(&saveunit, &theunit);
    err = evalfunc(&theunit, infunc, FUNCTION, ALLERR);
    if (err) {
      printf("Error in definition %s(%s) as '%s':\n",
             infunc->name, infunc->forward.param, infunc->forward.def);
      printf("      %s\n",errormsg[err]);
      freeunit(&theunit);
      freeunit(&saveunit);
      return;
    }
  } else {
#   define MAXPOWERTOCHECK 4
    struct unittype resultunit, arbunit;
    char unittext[9]; 
    double factor;
    int errors[MAXPOWERTOCHECK], errcount=0;
    char *indent;

    strcpy(unittext,"(kg K)^ ");
    factor = theunit.factor;
    initializeunit(&saveunit);
    initializeunit(&resultunit);
    for(i=0;i<MAXPOWERTOCHECK;i++){
      lastchar(unittext) = '0'+i;
      err = parseunit(&arbunit, unittext, 0, 0);
      if (err) initializeunit(&arbunit);
      arbunit.factor = factor;
      unitcopy(&resultunit, &arbunit);
      errors[i] = evalfunc(&resultunit, infunc, FUNCTION, ALLERR); 
      if (errors[i]) errcount++;
      else {
        freeunit(&saveunit);
        freeunit(&theunit);
        unitcopy(&saveunit, &arbunit);
        unitcopy(&theunit, &resultunit);
      }
      freeunit(&resultunit);
      freeunit(&arbunit);
    }
    if (!errors[0] && errcount==3) {
      printf("Warning: function '%s(%s)' defined as '%s'\n",
             infunc->name, infunc->forward.param, infunc->forward.def);
      printf("         appears to require a dimensionless argument, 'units' keyword not given\n");
      indent = "         ";
    }
    else if (errcount==MAXPOWERTOCHECK) {
      printf("Error or missing 'units' keyword in definion %s(%s) as '%s'\n",
             infunc->name, infunc->forward.param, infunc->forward.def);
      indent="      ";
    }
    else if (errcount){
      printf("Warning: function '%s(%s)' defined as '%s'\n",
             infunc->name, infunc->forward.param, infunc->forward.def);
      printf("         failed for some test inputs:\n");
      indent = "         ";
    }
    for(i=0;i<MAXPOWERTOCHECK;i++) 
      if (errors[i]) {
        lastchar(unittext) = '0'+i;
        printf("%s%s(",indent,infunc->name);
        printf(num_format.format, factor);
        printf("%s): %s\n", unittext, errormsg[errors[i]]);
      }
  }
  if (completereduce(&theunit)){
    printf("Definition %s(%s) as '%s' is irreducible\n",
           infunc->name, infunc->forward.param, infunc->forward.def);
    freeunit(&theunit);
    freeunit(&saveunit);
    return;
  }    
  if (!(infunc->inverse.def)){
    printf("Warning: no inverse for function '%s'\n", infunc->name);
    freeunit(&theunit);
    freeunit(&saveunit);
    return;
  }
  err = evalfunc(&theunit, infunc, INVERSE, ALLERR);
  if (err){
    printf("Error in inverse ~%s(%s) as '%s':\n",
           infunc->name,infunc->inverse.param, infunc->inverse.def);
    printf("      %s\n",errormsg[err]);
    freeunit(&theunit);
    freeunit(&saveunit);
    return;
  }
  divunit(&theunit, &saveunit);
  if (unit2num(&theunit) || fabs(theunit.factor-1)>1e-12)
    printf("Inverse is not the inverse for function '%s'\n", infunc->name);
  freeunit(&theunit);
}


struct namedef { 
  char *name;
  char *def;
};
    
#define CONFORMABLE 1
#define TEXTMATCH 2

void 
addtolist(struct unittype *have, char *searchstring, char *rname, char *name, 
               char *def, struct namedef **list, int *listsize, 
               int *maxnamelen, int *count, int searchtype)
{
  struct unittype want;
  int len = 0;
  int keepit = 0;

  if (!name) 
    return;
  if (searchtype==CONFORMABLE){
    initializeunit(&want);
    if (!parseunit(&want, name,0,0) && !completereduce(&want))
      keepit = !compareunits(have,&want,ignore_dimless);
  } else if (searchtype == TEXTMATCH) {
    keepit = (strstr(rname,searchstring) != NULL);
  }
  if (keepit){
    if (*count==*listsize){
      *listsize += 100;
      *list = (struct namedef *) 
        realloc(*list,*listsize*sizeof(struct namedef));
      if (!*list){
        fprintf(stderr, "%s: memory allocation error (addtolist)\n",
                progname);  
        exit(EXIT_FAILURE);
      }
    }
    (*list)[*count].name = rname;
    if (strchr(def, PRIMITIVECHAR))
      (*list)[*count].def = "<primitive unit>";
    else
      (*list)[*count].def = def;
    (*count)++;
    len = strwidth(name);
    if (len>*maxnamelen)
          *maxnamelen = len;
  }
  if (searchtype == CONFORMABLE)
    freeunit(&want);
}


int 
compnd(const void *a, const void *b)
{
  return strcmp(((struct namedef *)a)->name, ((struct namedef *)b)->name);
}


int 
screensize()
{
   int lines = 20;      /* arbitrary but probably safe value */

#if defined (_WIN32) && defined (_MSC_VER)
   CONSOLE_SCREEN_BUFFER_INFO csbi;

   if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
       lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
#endif

#ifdef HAVE_IOCTL
   struct winsize ws;
   int fd;
   fd = open("/dev/tty", O_RDWR);
   if (fd>=0 && ioctl(fd, TIOCGWINSZ, &ws)==0)
     lines = ws.ws_row;
#endif

   return lines;
}

/*
  determines whether the output will fit on the screen, and opens a
  pager if it won't
*/
FILE *
get_output_fp(int lines)
{
  FILE *fp = NULL;

  if (isatty(fileno(stdout)) && screensize() < lines) {
    if ((fp = popen(pager, "w")) == NULL) {
      fprintf(stderr, "%s: can't run pager '%s--'", progname, pager);
      perror((char*) NULL);
    }
  }
  if (!fp)
    fp = stdout;

  return fp;
}

int
countlines(char *msg)
{
  int nlines = 0;
  char *p;

  for (p = msg; *p; p++)
    if (*p == '\n')
      nlines++;

  return nlines;
}

/* 
   If have is non-NULL then search through all units and print the ones
   which are conformable with have.  Otherwise search through all the 
   units for ones whose names contain the second argument as a substring.
*/

void 
tryallunits(struct unittype *have, char *searchstring)
{
  struct unitlist *uptr;
  struct namedef *list;
  int listsize, maxnamelen, count;
  struct func *funcptr;
  struct wantalias *aliasptr;
  int i, j, searchtype;
  FILE *outfile;
  char *seploc, *firstunit;

  list = (struct namedef *) mymalloc( 100 * sizeof(struct namedef), 
                                       "(tryallunits)");
  listsize = 100;
  maxnamelen = 0;
  count = 0;

  if (have)
    searchtype = CONFORMABLE;
  else {
    if (!searchstring)
      searchstring="";
    searchtype = TEXTMATCH;
  }

  for(i=0;i<HASHSIZE;i++)
    for (uptr = utab[i]; uptr; uptr = uptr->next)
      addtolist(have, searchstring, uptr->name, uptr->name, uptr->value, 
                &list, &listsize, &maxnamelen, &count, searchtype);
  for(i=0;i<SIMPLEHASHSIZE;i++)
    for(funcptr=ftab[i];funcptr;funcptr=funcptr->next){
      if (funcptr->table) 
        addtolist(have, searchstring, funcptr->name, funcptr->tableunit, 
                "<piecewise linear>", &list, &listsize, &maxnamelen, &count, 
                searchtype);
      else
        addtolist(have, searchstring, funcptr->name, funcptr->inverse.dimen, 
                "<nonlinear>", &list, &listsize, &maxnamelen, &count, 
                searchtype);
  }
  for(aliasptr=firstalias;aliasptr;aliasptr=aliasptr->next){
    firstunit = dupstr(aliasptr->definition);/* coverity[var_assigned] */
    seploc = strchr(firstunit,UNITSEPCHAR);  /* Alias definitions allowed in */
    *seploc = 0;                             /* database contain UNITSEPCHAR */
    addtolist(have, searchstring, aliasptr->name, firstunit, 
              aliasptr->definition, &list, &listsize, &maxnamelen, &count,
              searchtype);
    free(firstunit);
  }
    
  qsort(list, count, sizeof(struct namedef), compnd);

  if (count==0)
    puts("No matching units found.");
#ifdef SIGPIPE
  signal(SIGPIPE, SIG_IGN);
#endif
  /* see if we need a pager */
  outfile = get_output_fp(count);
  for(i=0;i<count;i++){
    fputs(list[i].name,outfile);
    if (flags.verbose > 0 || flags.interactive) {
        for(j=strwidth(list[i].name);j<=maxnamelen;j++)
          putc(' ',outfile);
        tightprint(outfile,list[i].def);
    }
    fputc('\n',outfile);
  }
  if (outfile != stdout)
    pclose(outfile);
#ifdef SIGPIPE
  signal(SIGPIPE, SIG_DFL);
#endif
}


/* If quiet is false then prompt user with the query.  

   Fetch one line of input and return it in *buffer.

   The bufsize argument is a dummy argument if we are using readline. 
   The readline version frees buffer if it is non-null.  The other
   version keeps the same buffer and grows it as needed.

   If no data is read, then this function exits the program. 
*/


void
getuser_noreadline(char **buffer, int *bufsize, const char *query)
{
#ifdef SUPPORT_UTF8
  int valid = 0;
  while(!valid){
    fputs(query, stdout);
    if (!fgetslong(buffer, bufsize, stdin,0)){
      if (!flags.quiet)
        putchar('\n');
      exit(EXIT_SUCCESS);
    }
    valid = strwidth(*buffer)>=0;
    if (!valid)
      printf("Error: %s\n",invalid_utf8);
  }
#else
  fputs(query, stdout);
  if (!fgetslong(buffer, bufsize, stdin,0)){
    if (!flags.quiet)
      putchar('\n');
    exit(EXIT_SUCCESS);
  }
#endif
}  


#ifndef READLINE
#  define getuser getuser_noreadline
#else 
           /* we DO have readline */
void
getuser_readline(char **buffer, int *bufsize, const char *query)
{
#ifdef SUPPORT_UTF8
  int valid = 0;
  while (!valid){
    if (*buffer) free(*buffer);
    *buffer = readline(query);
    if (*buffer)
      replacectrlchars(*buffer);
    if (!*buffer || strwidth(*buffer)>=0)
        valid=1;
    else
      printf("Error: %s\n",invalid_utf8);
  }
#else
    if (*buffer) free(*buffer);
    *buffer = readline(query);
    if (*buffer)
      replacectrlchars(*buffer);
#endif
  if (nonempty(*buffer)) add_history(*buffer);
  if (!*buffer){
    if (!flags.quiet)
       putchar('\n');
    exit(EXIT_SUCCESS);
  }
}


void
getuser(char **buffer, int *bufsize, const char *query)
{
  if (flags.readline)
    getuser_readline(buffer,bufsize,query);
  else
    getuser_noreadline(buffer,bufsize,query);
}


/* Unit name completion for readline.  

   Complete function names or alias names or builtin functions.  

   Complete to the end of a prefix or complete to the end of a unit.
   If the text includes a full prefix plus part of a unit and if the
   prefix is longer than one character then complete that compound.
   Don't complete a prefix fragment into prefix plus anything.
*/
   
#define CU_ALIAS 0
#define CU_BUILTIN 1
#define CU_FUNC 2
#define CU_PREFIX 3
#define CU_UNITS 4
#define CU_DONE 5

char *
completeunits(char *text, int state)
{
  static int uhash, fhash, phash, checktype;
  static struct prefixlist *curprefix, *unitprefix;
  static struct unitlist *curunit;
  static struct func *curfunc;
  static struct wantalias *curalias;
  static char **curbuiltin;
  char *output = 0;

#ifndef NO_SUPPRESS_APPEND
  rl_completion_suppress_append = 1;
#endif
  
  if (!state){     /* state == 0 means this is the first call, so initialize */
    checktype = 0; /* start at first type */
    fhash = uhash = phash = 0;
    unitprefix=0; /* search for unit continuations starting with this prefix */
    curfunc=ftab[fhash];
    curunit=utab[uhash];
    curprefix=ptab[phash];
    curbuiltin = builtins;
    curalias = firstalias;
  }
  while (checktype != CU_DONE){
    if (checktype == CU_ALIAS){
      while(curalias){
        if (startswith(curalias->name,text))
          output = dupstr(curalias->name);
        curalias = curalias->next;
        if (output) return output;
      }
      checktype++;
    }
    if (checktype == CU_BUILTIN){
      while(*curbuiltin){
        if (startswith(*curbuiltin,text))
          output = dupstr(*curbuiltin);
        curbuiltin++;
        if (output) return output;
      }
      checktype++;
    }
    while (checktype == CU_FUNC){
      while (!curfunc && fhash<SIMPLEHASHSIZE-1){
        fhash++;
        curfunc = ftab[fhash];
      }
      if (!curfunc) 
        checktype++;
      else {
        if (startswith(curfunc->name,text))
          output = dupstr(curfunc->name);
        curfunc = curfunc->next;
        if (output) return output;  
      }
    }
    while (checktype == CU_PREFIX){
      while (!curprefix && phash<SIMPLEHASHSIZE-1){
        phash++;
        curprefix = ptab[phash];
      }
      if (!curprefix)
        checktype++;
      else {
        if (startswith(curprefix->name,text))
          output = dupstr(curprefix->name);
        curprefix = curprefix->next;
        if (output) return output;
      }
    }
    while (checktype == CU_UNITS){    
      while (!curunit && uhash<HASHSIZE-1){
        uhash++;
        curunit = utab[uhash];
      }
      /* If we're done with the units go through them again with */
      /* the largest possible prefix stripped off */
      if (!curunit && !unitprefix 
            && (unitprefix = plookup(text)) && strlen(unitprefix->name)>1){
        uhash = 0;
        curunit = utab[uhash];
      }
      if (!curunit) {
        checktype++;
        break;
      }
      if (unitprefix){
        if (startswith(curunit->name, text+unitprefix->len)){
          output = (char *)mymalloc(1+strlen(curunit->name)+unitprefix->len,
                                    "(completeunits)");
          strcpy(output, unitprefix->name);
          strcat(output, curunit->name);
        }       
      } 
      else if (startswith(curunit->name,text)) 
        output = dupstr(curunit->name);
      curunit=curunit->next;
      if (output)
        return output;
    }
  } 
  return 0;
}

#endif /* READLINE */



/* see if current directory contains an executable file */
int
checkcwd (char *file)
{
  FILE *fp;
  char *p;

  fp = openfile(file, "r");
  if (fp){
    fclose(fp);
    return 1;
  }
#ifdef _WIN32
  else if (!((p = strrchr(file, '.')) && isexe(p))) {
    char *pathname;

    pathname = mymalloc(strlen(file) + strlen(EXE_EXT) + 1,
                        "(checkcwd)");
    strcpy(pathname, file);
    strcat(pathname, EXE_EXT);
    fp = openfile(pathname, "r");
    free(pathname);
    if (fp) {
      fclose(fp);
      return 1;
    }
  }
#endif

  return 0;
}

/* 
   return the last component of a pathname, and remove a .exe extension
   if one exists.
*/

char *
getprogramname(char *path)
{
  size_t proglen;
  char *p;

  path = pathend(path);

  /* get rid of filename extensions in Windows */
  proglen = strlen(path);

  if ((p = strrchr(path, '.')) && isexe(p))
    proglen -= 4;
  return dupnstr(path, proglen);
}

/*
   Find the directory that contains the invoked executable.
*/

char *
getprogdir(char *progname, char **fullprogname)
{
  char *progdir = NULL;
  char *p;

#if defined (_WIN32) && defined (_MSC_VER)
  char buf[FILENAME_MAX + 1];

  /* get the full pathname of the current executable and be done with it */
  /* TODO: is there way to do this with gcc? */

  if (GetModuleFileName(NULL, buf, FILENAME_MAX + 1))
    progdir = dupstr(buf);
#endif

  /* If path name is absolute or includes more than one component use it */

  if (!progdir && (isfullpath(progname) || hasdirsep(progname)))
    progdir = dupstr(progname);


  /*
  command.com and cmd.exe under Windows always run a program that's in the
  current directory whether or not the current directory is in PATH, so we need
  to check the current directory.

  This could return a false positive if units is run from a Unix-like command
  interpreter under Windows if the current directory is not in PATH but
  contains 'units' or 'units.exe'
  */
#if defined (_WIN32) && !defined (_MSC_VER)
  if (!progdir && checkcwd(progname)) 
      progdir = dupstr(progname);
#endif

  /* search PATH to find the executable */
  if (!progdir) {
    char *env;
    env = getenv("PATH");
    if (env) {
      /* search PATH */
      char *direc, *direc_end, *pathname;
      int len;
      FILE *fp;

      pathname = mymalloc(strlen(env)+strlen(progname)+strlen(EXE_EXT)+2,
                                                         "(getprogdir)");
      direc = env;
      while (direc) {
        direc_end = strchr(direc,PATHSEP);
        if (!direc_end)
          len = strlen(direc);
        else 
          len = direc_end-direc;
        strncpy(pathname, direc, len);
        if (len>0)
          pathname[len++]=DIRSEP;
        strcpy(pathname+len, progname);
        fp = openfile(pathname, "r");
        if (fp){
          progdir = dupstr(pathname);
          break;
        }
#ifdef _WIN32
        /*
          executable may or may not have '.exe' suffix, so we need to
          look for both
        */
        if (!((p = strrchr(pathname, '.')) && isexe(p))) {
          strcat(pathname, EXE_EXT);
          fp = openfile(pathname, "r");
          if (fp){
            progdir = dupstr(pathname);
            break;
          }
        }
#endif
        direc = direc_end;
        if (direc) direc++;
      }
      free(pathname);
      if (fp)
        fclose(fp);
    }
  }

  if (!progdir) {
    fprintf(stderr, "%s: cannot find program directory\n", progname);
    exit(EXIT_FAILURE);
  }

  *fullprogname = dupstr(progdir);      /* used by printversion() */
  p = pathend(progdir);
  *p = '\0';  
 
  return progdir; 
}

/*
  find a possible data directory relative to a 'bin' directory that
  contains the executable
*/

char *
getdatadir()
{
    int progdirlen;
    char *p;

    if (isfullpath(DATADIR))
      return DATADIR;
    if (!progdir || emptystr(DATADIR))
      return NULL;
    progdirlen = strlen(progdir);
    datadir = (char *) mymalloc(progdirlen + strlen(DATADIR) + 2,
				"(getdatadir)");
    strcpy(datadir, progdir);
    if (isdirsep(progdir[progdirlen - 1]))
      datadir[progdirlen - 1] = '\0';   /* so pathend() can work */
    p = pathend(datadir);
    if ((strlen(p) == 3) && (tolower(p[0]) == 'b') \
       && (tolower(p[1]) == 'i') && (tolower(p[2]) == 'n')) {
      p = DATADIR;
      while (*p == '.')         /* ignore "./", "../" */
	p++;
      if (isdirsep(*p))
	p++;
      strcpy(pathend(datadir), p);
      
      return datadir;
    }
    else
      return NULL;
}

void
showfilecheck(int errnum, char *filename)
{
  if (errnum==ENOENT)
    printf("  Checking %s\n", filename);
  else
    printf("  Checking %s: %s\n", filename, strerror(errnum)); 
}

/*
  On Windows, find the locale map
  
  If print is set to ERRMSG then display error message if the file is
  not valid.  If print is set to SHOWFILES then display files that are
  checked (when the filename is not a fully specified path).  If print
  is set to NOERRMSG then do not display anything.

  Returns filename of valid local map file or NULL if no file was found.
*/
#ifdef _WIN32
char *
findlocalemap(int print)
{
  FILE *map = NULL;
  char *filename = NULL;
  char *file;

  /*
      Try the environment variable UNITSLOCALEMAP, then the #defined
      value LOCALEMAP, then the directory containing the units
      executable, then the directory given by datadir, and finally
      the directory containing the units data file.
  */

  /* check the environment variable UNITSLOCALEMAP */
  file = getenv("UNITSLOCALEMAP");
  if (nonempty(file)) {
    map = openfile(file,"rt");
    if (!map) {
      if (print == ERRMSG) {
        fprintf(stderr,
                "%s: cannot open locale map '%s'\n  specified in UNITSLOCALEMAP environment variable. ",
                progname, file);
        perror((char *) NULL);
      }
      return NULL;
    }
    else
      filename = dupstr(file);
  }

  /* check the #defined value LOCALEMAP */
  if (!map) {
    file = LOCALEMAP;
    map = openfile(file,"rt");
    if (map)
      filename = dupstr(file);
  }

  if (!map && !progdir) {
    if (print == ERRMSG) {
      fprintf(stderr,
              "%s: cannot find locale map--program directory not set\n",
              progname);
      exit(EXIT_FAILURE);
    }
    else
      return NULL;
  }

  /* check the directory with the units executable */
  if (!map) {
    filename = (char *) mymalloc(strlen(progdir) + strlen(file) + 2,
               "(findlocalemap)");
    strcpy(filename, progdir);
    strcat(filename, file);
    map = openfile(filename,"rt");
    if (print==SHOWFILES && !map)
      showfilecheck(errno, filename);
  }

  /* check data directory */
  if (!map && datadir) {     
    if (filename)
      free(filename);
    filename = (char *) mymalloc(strlen(datadir) + strlen(file) + 3,
                                 "(findlocalemap)");
    strcpy(filename, datadir);
    strcat(filename, DIRSEPSTR);
    strcat(filename, file);
    map = openfile(filename, "rt");
    if (print==SHOWFILES && !map)
      showfilecheck(errno, filename);
  }

  /* check the directory with the units data file  */
  if (!map && unitsfiles[0]) {
    char *lastfilename = NULL;

    if (filename) {
      if (datadir)
	lastfilename = dupstr(filename);
      free(filename);
    }
    filename = (char *) mymalloc(strlen(unitsfiles[0]) + strlen(file) + 2,
               "(findlocalemap)");
    strcpy(filename, unitsfiles[0]);
    strcpy(pathend(filename), file);

    /* don't bother if we've just checked for it */
    if (lastfilename && strcmp(filename, lastfilename)) {
      map = openfile(filename,"rt");
      if (print==SHOWFILES && !map)
	showfilecheck(errno, filename);
    }
  }

  if (map) {
    fclose(map);
    return filename;
  }
  else {
    if (filename)
      free(filename);
    return NULL;
  }
}
#endif

/*
  Find the units database file. 
  
  If print is set to ERRMSG then display error message if the file is
  not valid.  If print is set to SHOWFILES then display files that are
  checked (when the filename is not a fully specified path).  If print
  is set to NOERRMSG then do not display anything.

  Returns filename of valid database file or NULL if no file
  was found.  
*/

char *
findunitsfile(int print)
{
  FILE *testfile=0;
  char *file;

  file = getenv("UNITSFILE");
  if (nonempty(file)) {
    testfile = openfile(file, "rt");
    if (!testfile) {
      if (print==ERRMSG) {
        fprintf(stderr,
                "%s: cannot open units file '%s' in environment variable UNITSFILE.  ",
                progname, file);
        perror((char *) NULL);
      }
      return NULL;
    }
  }

  if (!testfile && isfullpath(UNITSFILE)){
    file = UNITSFILE;
    testfile = openfile(file, "rt");
    if (!testfile) {
      if (print==ERRMSG) {
        fprintf(stderr,
                "%s: cannot open units data file '%s'.  ", progname, UNITSFILE);
        perror((char *) NULL);
      }
      return NULL;
    }
  }      

  if (!testfile && !progdir) {
    if (print==ERRMSG) {
      fprintf(stderr,
              "%s: cannot open units file '%s' and cannot find program directory.\n", progname, UNITSFILE);
      perror((char *) NULL);
    }
    return NULL;
  }

  if (!testfile) {
    /* check the directory containing the units executable */
    file = (char *) mymalloc(strlen(progdir)+strlen(UNITSFILE)+1,
                             "(findunitsfile)");
    strcpy(file, progdir);
    strcat(file, UNITSFILE);
    testfile = openfile(file, "rt");
    if (print==SHOWFILES && !testfile)
      showfilecheck(errno, file);
    if (!testfile)
      free(file);
  }

  /* check data directory */
  if (!testfile && datadir) {
    file = (char *) mymalloc(strlen(datadir) + strlen(UNITSFILE) + 2,
                             "(findunitsfile)");
    strcpy(file, datadir);
    strcat(file, DIRSEPSTR);
    strcat(file, UNITSFILE);
    testfile = openfile(file, "rt");
    if (print==SHOWFILES && !testfile)
      showfilecheck(errno, file);
    if (!testfile)
      free(file);
  }

  if (!testfile) {
    if (print==ERRMSG)
      fprintf(stderr,"%s: cannot find units file '%s'\n", progname, UNITSFILE);
     return NULL;
  }
  else {
    fclose(testfile);
    return file;
  }
}

/*
  Find the user's home directory.  Unlike *nix, Windows doesn't usually
  set HOME, so we check several other places as well.
*/
char *
findhome(char **errmsg)
{
  struct stat statbuf;
  int allocated = 0;
  char *homedir;
  char notfound[] = "Specified home directory '%s' does not exist";
  char notadir[] = "Specified home directory '%s' is not a directory";

  /*
    Under UNIX just check HOME.  Under Windows, if HOME is not set then
    check HOMEDRIVE:HOMEPATH and finally USERPROFILE
  */
  homedir = getenv("HOME");

#ifdef _WIN32
  if (!nonempty(homedir)) {
    /* try a few other places */
    /* try HOMEDRIVE and HOMEPATH */
    char *homedrive, *homepath;
    if ((homedrive = getenv("HOMEDRIVE")) && *homedrive && (homepath = getenv("HOMEPATH")) && *homepath) {
      homedir = mymalloc(strlen(homedrive)+strlen(homepath)+1,"(personalfile)");
      allocated = 1;
      strcpy(homedir, homedrive);
      strcat(homedir, homepath);
    }
    else
      /* finally, try USERPROFILE */
      homedir = getenv("USERPROFILE");
  }
#endif
  
  /*
    If a home directory is specified, see if it exists and is a
    directory.  If not set error message text. 
  */
  
  if (nonempty(homedir)) {
    if (stat(homedir, &statbuf) != 0) {
      *errmsg = malloc(strlen(notfound)+strlen(homedir));
      sprintf(*errmsg, notfound, homedir);
    }
    else if (!(statbuf.st_mode & S_IFDIR)) {
      *errmsg = malloc(strlen(notadir)+strlen(homedir));
      sprintf(*errmsg, notadir, homedir);
    }
    if (!allocated)
      homedir = dupstr(homedir);
    return homedir;
  }
  else {
    *errmsg = "no home directory";
    return NULL;
  }
}

/*
  Find a personal file.  First checks the specified environment variable 
  (envname) for the filename to  use.  If this is unset then search user's 
  home directory for basename.  If there is no home directory, returns 
  NULL.  Otherwise if the file exists then returns its name in newly allocated
  space and sets *exists to 1. If the file does not exist then sets *exist to 
  zero and:
      With checkonly == 0, prints error message and returns NULL
      With checkonly != 0, returns filename (does not print error message)
*/
char *
personalfile(const char *envname, const char *basename,
             int checkonly, int *exists)
{
  FILE *testfile;
  char *filename=NULL;

  *exists = 0; 

  /* First check the specified environment variable for a file name */ 
  if (envname) 
    filename = getenv(envname);
  if (nonempty(filename)){       
    testfile = openfile(filename, "rt");
    if (testfile){
      fclose(testfile);
      *exists = 1;
      return filename;
    }
    if (checkonly)
      return filename;
    else {
      fprintf(stderr, "%s: cannot open file '%s' specified in %s environment variable: ",
              progname, filename, envname);
      perror((char *) NULL);
      return NULL;
    }
  }
  /* Environment variable not set: look in home directory */
  else if (nonempty(homedir)) {
    filename = mymalloc(strlen(homedir)+strlen(basename)+2,
                        "(personalfile)");
    strcpy(filename,homedir);

    if (strcmp(homedir, "/") && strcmp(homedir, "\\"))
      strcat(filename,DIRSEPSTR);
    strcat(filename,basename);

    testfile = openfile(filename, "rt");
    if (testfile){
      fclose(testfile);
      *exists = 1;
      return filename;
    }
    if (checkonly)
      return filename;
    else {
      if (errno==EACCES || errno==EISDIR) {
        fprintf(stderr,"%s: cannot open file '%s': ",progname,filename);
        perror(NULL);
      }
      free(filename);
      return NULL;
    }
  }
  else
    return NULL;
}


/* print usage message */

void 
usage()
{
  int nlines;
  char *unitsfile;
  char *msg = "\nUsage: %s [options] ['from-unit' 'to-unit']\n\n\
Options:\n\
    -h, --help           show this help and exit\n\
    -c, --check          check that all units reduce to primitive units\n\
        --check-verbose  like --check, but lists units as they are checked\n\
        --verbose-check    so you can find units that cause endless loops\n\
    -d, --digits         show output to specified number of digits (default: %d)\n\
    -e, --exponential    exponential format output\n\
    -f, --file           specify a units data file (-f '' loads default file)\n"
#ifdef READLINE
"\
    -H, --history        specify readline history file (-H '' disables history)\n"
#endif
"\
    -L, --log            specify a file to log conversions\n\
    -l, --locale         specify a desired locale\n\
    -m, --minus          make - into a subtraction operator (default)\n\
        --oldstar        use old '*' precedence, higher than '/'\n\
        --newstar        use new '*' precedence, equal to '/'\n\
    -n, --nolists        disable conversion to unit lists\n\
    -S, --show-factor    show non-unity factor before 1|x in multi-unit output\n\
        --conformable    in non-interactive mode, show all conformable units\n\
    -o, --output-format  specify printf numeric output format (default: %%.%d%c)\n\
    -p, --product        make '-' into a product operator\n\
    -q, --quiet          suppress prompting\n\
        --silent         same as --quiet\n\
    -s, --strict         suppress reciprocal unit conversion (e.g. Hz<->s)\n\
    -v, --verbose        show slightly more verbose output\n\
        --compact        suppress printing of tab, '*', and '/' character\n\
    -1, --one-line       suppress the second line of output\n\
    -t, --terse          terse output (--strict --compact --quiet --one-line)\n\
    -r, --round          round last element of unit list output to an integer\n\
    -U, --unitsfile      show units data filename and exit\n\
    -u, --units          specify a CGS units system or natural units system:\n\
                            gauss[ian],esu,emu,hlu,natural,natural-gauss,\n\
                            hartree,planck,planck-red,si\n\
    -V, --version        show version, data filenames (with -t: version only)\n\
    -I, --info           show version, files, and program properties\n";
  FILE *fp = NULL;

  unitsfile = findunitsfile(NOERRMSG);

  nlines = countlines(msg);
  /* see if we need a pager */
  fp = get_output_fp(nlines + 4);

  fprintf(fp, msg, progname, DEFAULTPRECISION, DEFAULTPRECISION, DEFAULTTYPE);
  if (!unitsfile)
    fprintf(fp, "Units data file '%s' not found.\n\n", UNITSFILE);
  else
    fprintf(fp, "\nTo learn about the available units look in '%s'\n\n", unitsfile);
  fputs("Report bugs to adrianm@gnu.org.\n\n", fp);

  if (fp != stdout)
    pclose(fp);
}

/* Print message about how to get help */

void 
helpmsg()
{
  fprintf(stderr,"\nTry '%s --help' for more information.\n",progname);
  exit(EXIT_FAILURE);
}

/* show units version, and optionally, additional information */
void
printversion()
{
  int exists;
  char *u_unitsfile = NULL;  /* units data file specified in UNITSFILE */
  char *m_unitsfile;         /* personal units data file from HOME_UNITS_ENV */
  char *p_unitsfile;         /* personal units data file */
  FILE *fp, *histfile;
#ifdef _WIN32
  char *localemap;
#endif

  if (flags.verbose == 0) {
    printf("GNU Units version %s\n", VERSION);
    return;
  }

  printf("GNU Units version %s\n%s, %s, locale %s\n",
         VERSION, RVERSTR,UTF8VERSTR,mylocale);
#if defined (_WIN32) && defined (HAVE_MKS_TOOLKIT)
  puts("With MKS Toolkit");
#endif

  if (flags.verbose == 2) {
    if (!fullprogname)
      getprogdir(progname, &fullprogname);
    if (fullprogname)
      printf("\n%s program is %s\n", progname, fullprogname);
  }

  /* units data file */

  putchar('\n');
  if (isfullpath(UNITSFILE))
    printf("Default units data file is '%s'\n", UNITSFILE);
  else
    printf("Default units data file is '%s';\n  %s will search for this file\n",
           UNITSFILE, progname);
  if (flags.verbose < 2)
    printf("Default personal units file: %s\n", homeunitsfile);

  if (flags.verbose == 2){
    u_unitsfile = getenv("UNITSFILE");
    if (u_unitsfile)
      printf("Environment variable UNITSFILE set to '%s'\n", u_unitsfile);
    else
      puts("Environment variable UNITSFILE not set");

    unitsfiles[0] = findunitsfile(SHOWFILES);
    
    if (unitsfiles[0]) {
      /* We searched for the file in program and data dirs */
      if (!isfullpath(UNITSFILE) && !nonempty(u_unitsfile))
        printf("Found data file '%s'\n", unitsfiles[0]);
      else
        printf("Units data file is '%s'\n", unitsfiles[0]);
    } 
    else {
      if (errno && (nonempty(u_unitsfile) || isfullpath(UNITSFILE)))
        printf("*** Units data file invalid: %s ***\n",strerror(errno));
      else
        puts("*** Units data file not found ***");
    }
    if (homedir_error)
      printf("\n%s\n", homedir_error);
    else
      printf("\nHome directory is '%s'\n", homedir);
  }

  /* personal units data file: environment */
  if (flags.verbose == 2){
    m_unitsfile = getenv(HOME_UNITS_ENV);
    putchar('\n');
    if (m_unitsfile) {
      printf("Environment variable %s set to '%s'\n",
             HOME_UNITS_ENV,m_unitsfile);
    }
    else
      printf("Environment variable %s not set\n", HOME_UNITS_ENV);

    p_unitsfile = personalfile(HOME_UNITS_ENV, homeunitsfile, 1, &exists);
    if (p_unitsfile) {
      printf("Personal units data file is '%s'\n", p_unitsfile);
      if (!exists){
        if (homedir_error && !nonempty(m_unitsfile))
          printf("  (File invalid: %s)\n", homedir_error);
        else if (errno==ENOENT && !nonempty(m_unitsfile))
          puts("  (File does not exist)");
        else 
          printf("  (File invalid: %s)\n",strerror(errno));
      }  
    }
    else
      puts("Personal units data file not found: no home directory");
  }
#ifdef READLINE
  if (flags.verbose == 2) {
    historyfile = personalfile(NULL,HISTORY_FILE,1,&exists);
    if (historyfile){
      printf("\nDefault readline history file is '%s'\n", historyfile);
      histfile = openfile(historyfile,"r+");
      if (!histfile)
        printf("  (File invalid: %s)\n",
               homedir_error ? homedir_error : strerror(errno));
      else
        fclose(histfile);
    }  
    else 
      puts("\nReadline history file unusable: no home directory");
  }
#endif

#ifdef _WIN32
  /* locale map */
  if (flags.verbose == 2) {
    putchar('\n');
    localemap = getenv("UNITSLOCALEMAP");
    if (localemap)
      printf("Environment variable UNITSLOCALEMAP set to '%s'\n", localemap);
    else
      puts("Environment variable UNITSLOCALEMAP not set");

    if (isfullpath(LOCALEMAP))
      printf("Default locale map is '%s'\n", LOCALEMAP);
    else
      printf("Default locale map is '%s';\n  %s will search for this file\n",
             LOCALEMAP, progname);

    localemap = findlocalemap(SHOWFILES);
    if (localemap && !isfullpath(LOCALEMAP))
      printf("Found locale map '%s'\n", localemap);
    else if (localemap)
      printf("Locale map is '%s'\n", localemap);
    else
      puts("*** Locale map not found ***");
  }
#endif

  printf("\n%s\n\n", LICENSE);
}

void
showunitsfile()
{
  char *unitsfile;
  unitsfile = findunitsfile(NOERRMSG);
  if (unitsfile)
    printf("%s\n", unitsfile);
  else
    puts("Units data file not found");
}


char *shortoptions = "VIUu:vqechSstf:o:d:mnpr1l:L:"
#ifdef READLINE
    "H:"
#endif
  ;

struct option longoptions[] = {
  {"check", no_argument, &flags.unitcheck, 1},
  {"check-verbose", no_argument, &flags.unitcheck, 2},
  {"compact", no_argument, &flags.verbose, 0},
  {"digits", required_argument, 0, 'd'},
  {"exponential", no_argument, 0, 'e'},
  {"file", required_argument, 0, 'f'},
  {"help", no_argument, 0, 'h'},
#ifdef READLINE  
  {"history", required_argument, 0, 'H'},
#endif  
  {"info", no_argument, 0, 'I'},
  {"locale", required_argument, 0, 'l'}, 
  {"log", required_argument, 0, 'L'}, 
  {"minus", no_argument, &parserflags.minusminus, 1},
  {"newstar", no_argument, &parserflags.oldstar, 0},
  {"nolists", no_argument, 0, 'n'},
  {"oldstar", no_argument, &parserflags.oldstar, 1},
  {"one-line", no_argument, &flags.oneline, 1},
  {"output-format", required_argument, 0, 'o'},
  {"product", no_argument, &parserflags.minusminus, 0},
  {"quiet", no_argument, &flags.quiet, 1},
  {"round",no_argument, 0, 'r'},
  {"show-factor", no_argument, 0, 'S'},
  {"conformable", no_argument, &flags.showconformable, 1 },
  {"silent", no_argument, &flags.quiet, 1},
  {"strict",no_argument,&flags.strictconvert, 1},
  {"terse",no_argument, 0, 't'},
  {"unitsfile", no_argument, 0, 'U'},
  {"units", required_argument, 0, 'u'},
  {"verbose", no_argument, &flags.verbose, 2},
  {"verbose-check", no_argument, &flags.unitcheck, 2},
  {"version", no_argument, 0, 'V'},
  {0,0,0,0} };

/* Process the args.  Returns 1 if interactive mode is desired, and 0
   for command line operation.  If units appear on the command line
   they are returned in the from and to parameters. */

int
processargs(int argc, char **argv, char **from, char **to)
{
   optarg = 0;
   optind = 0;
   int optchar, optindex;
   int ind;
   int doprintversion=0;
   char *unitsys=0, *temp;

   while ( -1 != 
      (optchar = 
         getopt_long(argc, argv,shortoptions,longoptions, &optindex ))) {
      switch (optchar) {
         case 'm':
            parserflags.minusminus = 1;
            break;
         case 'p':
            parserflags.minusminus = 0;
            break;
         case 't':
            flags.oneline = 1;
            flags.quiet = 1;
            flags.strictconvert = 1;
            flags.verbose = 0;
            break;

         /* numeric output format */
         case 'd':
            if (checksigdigits(optarg) < 0)
              exit(EXIT_FAILURE);
            else    /* ignore anything given with 'o' option */
              num_format.format = NULL; 
            break;
         case 'e':  /* ignore anything given with 'o' option */
            num_format.format = NULL;   
            num_format.type = 'e';
            break;
         case 'o':
            num_format.format = optarg;
            break;

         case 'c':
            flags.unitcheck = 1;
            break;
         case 'f':
            for(ind=0;unitsfiles[ind];ind++); 
            if (ind==MAXFILES){
              fprintf(stderr, "At most %d -f specifications are allowed\n",
                      MAXFILES);
              exit(EXIT_FAILURE);
            }
            if (optarg && *optarg)
              unitsfiles[ind] = optarg;
            else {
              unitsfiles[ind] = findunitsfile(ERRMSG);
              if (!unitsfiles[ind]) 
                exit(EXIT_FAILURE);
            }
            unitsfiles[ind+1] = 0;
            break;
         case 'L':
            logfilename = optarg;
            break;
         case 'l':
            mylocale = optarg;
            break;
         case 'n':
            flags.unitlists = 0;
            break;
         case 'q':
            flags.quiet = 1;
            break; 
         case 'r':
            flags.round = 1;
            break;
         case 'S':
            flags.showfactor = 1;
            break;
         case 's':
            flags.strictconvert = 1;
            break;
         case 'v':
            flags.verbose = 2;
            break;
         case '1':
            flags.oneline = 1;
            break;
         case 'I':
            flags.verbose = 2;  /* fall through */
         case 'V':
            doprintversion = 1;
            break;
         case 'U':
            showunitsfile();
            exit(EXIT_SUCCESS);
            break;
         case 'u':
            unitsys = optarg;
            for(ind=0;unitsys[ind];ind++)
              unitsys[ind] = tolower(unitsys[ind]);
            break;
         case 'h':
            usage();
            exit(EXIT_SUCCESS);
#ifdef READLINE     
         case 'H':
           if (emptystr(optarg))
              historyfile=NULL;
            else
              historyfile = optarg;
            break;
#endif      
         case 0: break;  /* This is reached if a long option is 
                            processed with no return value set. */
         case '?':        /* Invalid option or missing argument returns '?' */
         default:
            helpmsg();    /* helpmsg() exits with error */
      } 
   }

   temp = strchr(mylocale,'.');
   if (temp)
     *temp = '\0';

   if (doprintversion){
     printversion();
     exit(EXIT_SUCCESS);
   }

   /* command-line option overwrites environment */
   if (unitsys)
     setenv("UNITS_SYSTEM", unitsys, 1);

   if (flags.unitcheck) {
     if (optind != argc){
       fprintf(stderr, 
               "Too many arguments (arguments are not allowed with -c).\n");
       helpmsg();         /* helpmsg() exits with error */
     }
   } else {
     if (optind == argc - 2) {
        if (flags.showconformable) {
          fprintf(stderr,"Too many arguments (only one unit expression allowed with '--conformable').\n");
          helpmsg();             /* helpmsg() exits with error */
        }
        flags.quiet=1;
        *from = argv[optind];
        *to = dupstr(argv[optind+1]); /* This string may get rewritten later */
        return 0;                     /* and we might call free() on it      */
     }

     if (optind == argc - 1) {
        flags.quiet=1;
        *from = argv[optind];
        *to=0;
        return 0;
     }
     if (optind < argc - 2) {
        fprintf(stderr,"Too many arguments (maybe you need quotes).\n");
        helpmsg();             /* helpmsg() exits with error */
     }
   }

   return 1;
}

/* 
   Show a pointer under the input to indicate a problem.
   Prints 'position' spaces and then the pointer.
   If 'position' is negative, nothing is printed.
 */

void
showpointer(int position)
{
  if (position >= 0){
    while (position--) putchar(' ');
    puts(POINTER);
  }
} /* end showpointer */


/*
   Process the string 'unitstr' as a unit, placing the processed data
   in the unit structure 'theunit'.  Returns 0 on success and 1 on
   failure.  If an error occurs an error message is printed to stdout.
   A pointer ('^') will be printed if an error is detected, and  promptlen 
   should be set to the printing width of the prompt string, or set 
   it to NOPOINT to supress printing of the pointer.  
 */

 
int 
processunit(struct unittype *theunit, char *unitstr, int promptlen)
{
  char *errmsg;
  int errloc,err;
  char savechar;

  if (flags.unitlists && strchr(unitstr, UNITSEPCHAR)){
    puts("Unit list not allowed");
    return 1;
  }
  if ((err=parseunit(theunit, unitstr, &errmsg, &errloc))){
    if (promptlen >= 0){
      if (err!=E_UNKNOWNUNIT || !irreducible){
        if (errloc>0) {
          savechar = unitstr[errloc];
          unitstr[errloc] = 0;
          showpointer(promptlen+strwidth(unitstr)-1);
          unitstr[errloc] = savechar;
        } 
        else showpointer(promptlen);
      }
    }
    else
      printf("Error in '%s': ", unitstr);
    fputs(errmsg,stdout);
    if (err==E_UNKNOWNUNIT && irreducible)
      printf(" '%s'", irreducible);
    putchar('\n');
    return 1;
  }
  if ((err=completereduce(theunit))){
    fputs(errormsg[err],stdout);
    if (err==E_UNKNOWNUNIT)
      printf(" '%s'", irreducible);
    putchar('\n');
    return 1;
  }
  return 0;
}


/* Checks for a new unit defined on the prompt with the form _<NAME> = <DEF> */

int
definevariable(char *def, int promptlen)
{
  int dummy, err;
  struct unittype unit;
  
  char *value = strchr(def,'=');
  if (!value)
    return 0;
  *value++=0;
  if (processunit(&unit, value, promptlen + (value-def)))
      return 1;
  removespaces(def);
  removespaces(value);
  err = *def!='_' || newunit(def,value, &dummy, 0, 0, NULL, 1, 1);
  if (err)
    printf("Invalid variable name: %s\n", def);
  return 1;
}  




/*
   Checks the input parameter unitstr (a list of units separated by
   UNITSEPCHAR) for errors.  All units must be parseable and
   conformable to each other.  Returns 0 on success and 1 on failure.

   If an error is found then print an error message on stdout.  A
   pointer ('^') will be printed to mark the error.  The promptlen
   parameter should be set to the printing width of the prompt string
   so that the pointer is correctly aligned.

   To suppress the printing of the pointer set promptlen to NOPOINT.
   To suppress printing of error messages entirely set promptlen to 
   NOERRMSG.
*/


int
checkunitlist(char *unitstr, int promptlen)
{
  struct unittype unit[2], one;
  char *firstunitstr,*nextunitstr;
  int unitidx = 0;

  int printerror = promptlen != NOERRMSG;

  initializeunit(&one);

  firstunitstr = unitstr;

  initializeunit(unit);
  initializeunit(unit+1);

  while (unitstr) {
    if ((nextunitstr = strchr(unitstr, UNITSEPCHAR)) != 0)
      *nextunitstr = '\0';

    if (!unitstr[strspn(unitstr, " ")]) {  /* unitstr is blank */
      if (!nextunitstr) {  /* terminal UNITSEPCHAR indicates repetition */
        freeunit(unit);    /* of last unit and is permitted */
        return 0;
      }
      else {               /* internal blank units are not allowed */
        if (printerror){
          showpointer(promptlen);
          puts("Error: blank unit not allowed");
        }
        freeunit(unit);
        return 1;
      }
    }

    /* processunit() prints error messages; avoid it to supress them */

    if ((printerror && processunit(unit+unitidx,unitstr,promptlen)) ||
        (!printerror && 
           (parseunit(unit+unitidx, unitstr,0,0) 
             || completereduce(unit+unitidx) 
             || compareunits(unit+unitidx,&one, ignore_primitive)))){
      if (printerror)
        printf("Error in unit list entry: %s\n",unitstr);
      freeunit(unit);
      freeunit(unit+1);
      return 1;
    }


    if (unitidx == 0)
      unitidx = 1;
    else {
      if (compareunits(unit, unit+1, ignore_dimless)){
        if (printerror){
          int wasverbose = flags.verbose;
          FILE *savelog = logfile;
          logfile=0;
          flags.verbose = 2;   /* always use verbose form to be unambiguous */
                               /* coverity[returned_null] */
          *(strchr(firstunitstr, UNITSEPCHAR)) = '\0';
          removespaces(firstunitstr);
          removespaces(unitstr);
          showpointer(promptlen);
          showconformabilityerr(firstunitstr, unit, unitstr, unit+1);
          flags.verbose = wasverbose;
          logfile = savelog;
        }
        freeunit(unit);
        freeunit(unit+1);
        return 1;
      }
      freeunit(unit+1);
    }

    if (nextunitstr) {
      if (promptlen >= 0) promptlen += strwidth(unitstr)+1;
      *(nextunitstr++) = UNITSEPCHAR;
    }
    unitstr = nextunitstr;
  }

  freeunit(unit);

  return 0;
} /* end checkunitlist */


/*
   Call either processunit or checkunitlist, depending on whether the
   string 'unitstr' contains a separator character.  Returns 0 on
   success and 1 on failure.  If an error occurs an error message is
   printed to stdout.

   A pointer will be printed if an error is detected, and  promptlen 
   should be set to the printing width of the prompt string, or set 
   it to NOPOINT to supress printing of the pointer.  
*/

int
processwant(struct unittype *theunit, char *unitstr, int promptlen)
{
  if (flags.unitlists && strchr(unitstr, UNITSEPCHAR))
    return checkunitlist(unitstr, promptlen);
  else
    return processunit(theunit, unitstr, promptlen);
}


void
checkallaliases(int verbose)
{
  struct wantalias *aliasptr;

  for(aliasptr = firstalias; aliasptr; aliasptr=aliasptr->next){
    if (verbose)
      printf("doing unit list '%s'\n", aliasptr->name);
    if (checkunitlist(aliasptr->definition,NOERRMSG))
      printf("Unit list '%s' contains errors\n", aliasptr->name);
    if (ulookup(aliasptr->name))
      printf("Unit list '%s' hides a unit definition.\n", aliasptr->name);
    if (fnlookup(aliasptr->name))
      printf("Unit list '%s' hides a function definition.\n", aliasptr->name);
  }
}



/* 
   Check that all units and prefixes are reducible to primitive units and that
   function definitions are valid and have correct inverses.  A message is
   printed for every unit that does not reduce to primitive units.

*/


void 
checkunits(int verbosecheck)
{
  struct unittype have,second,one;
  struct unitlist *uptr;
  struct prefixlist *pptr;
  struct func *funcptr;
  char *prefixbuf, *testunit;
  int i, reduce_err;
  char *err;

  initializeunit(&one);

  /* Check all functions for valid definition and correct inverse */
  
  for(i=0;i<SIMPLEHASHSIZE;i++)
    for(funcptr=ftab[i];funcptr;funcptr=funcptr->next)
      checkfunc(funcptr, verbosecheck);

  checkallaliases(verbosecheck);

  /* Now check all units for validity */

  for(i=0;i<HASHSIZE;i++)
    for (uptr = utab[i]; uptr; uptr = uptr->next){
      if (verbosecheck)
        printf("doing '%s'\n",uptr->name);
      if (strchr(uptr->value, PRIMITIVECHAR))
        continue; 
      else if (fnlookup(uptr->name)) 
          printf("Unit '%s' hidden by function '%s'\n", uptr->name, uptr->name);
      else if (parseunit(&have, uptr->value,&err,0))
          printf("'%s' defined as '%s': %s\n",uptr->name, uptr->value,err);
      else if ((reduce_err=completereduce(&have))){
          printf("'%s' defined as '%s' irreducible: %s",uptr->name, uptr->value,errormsg[reduce_err]);
          if (reduce_err==E_UNKNOWNUNIT && irreducible)
            printf(" '%s'", irreducible);
          putchar('\n');
      }
      else {
        parserflags.minusminus = !parserflags.minusminus; 
                                                 /* coverity[check_return] */
        parseunit(&second, uptr->name, 0, 0);    /* coverity[check_return] */
        completereduce(&second);     /* Can't fail because it worked above */
        if (compareunits(&have, &second, ignore_nothing)){
          printf("'%s': replace '-' with '+-' for subtraction or '*' to multiply\n", uptr->name);
        }
        freeunit(&second);
        parserflags.minusminus=!parserflags.minusminus;
      }

      freeunit(&have);
    }

  /* Check prefixes */ 

  testunit="meter";
  for(i=0;i<SIMPLEHASHSIZE;i++)
    for(pptr = ptab[i]; pptr; pptr = pptr->next){
      if (verbosecheck)
        printf("doing '%s-'\n",pptr->name);
      prefixbuf = mymalloc(strlen(pptr->name) + strlen(testunit) + 1,
                           "(checkunits)");
      strcpy(prefixbuf,pptr->name);
      strcat(prefixbuf,testunit);
      if (parseunit(&have, prefixbuf,0,0) || completereduce(&have) || 
          compareunits(&have,&one,ignore_primitive))
        printf("'%s-' defined as '%s' irreducible\n",pptr->name, pptr->value);
      else { 
        int plevel;    /* check for bad '/' character in prefix */
        char *ch;
        plevel = 0;
        for(ch=pptr->value;*ch;ch++){
          if (*ch==')') plevel--;
          else if (*ch=='(') plevel++;
          else if (plevel==0 && *ch=='/'){
            printf(
              "'%s-' defined as '%s' contains a bad '/'. (Add parentheses.)\n",
              pptr->name, pptr->value);
            break;
          }
        }           
      }  
      freeunit(&have);
      free(prefixbuf);
    }
}


/*
   Converts the input value 'havestr' (which is already parsed into
   the unit structure 'have') into a sum of the UNITSEPCHAR-separated
   units listed in 'wantstr'.  You must call checkunitlist first to
   ensure 'wantstr' is error-free.  Prints the results (or an error message)
   on stdout.  Returns 0 on success and 1 on failure.
*/

int
showunitlist(char *havestr, struct unittype *have, char *wantstr)
{
  struct unittype want, lastwant;
  char *lastunitstr, *nextunitstr, *lastwantstr=0;
  double remainder;     /* portion of have->factor remaining */
  double round_dir;     /* direction of rounding */
  double value;         /* value (rounded to integer with 'r' option) */
  int firstunit = 1;    /* first unit in a multi-unit string */
  int value_shown = 0;  /* has a value been shown? */
  int sigdigits;
  char val_sign;  

  initializeunit(&want);
  remainder = fabs(have->factor);
  val_sign = have->factor < 0 ? '-' : '+';
  lastunitstr = 0;
  nextunitstr = 0;
  round_dir = 0;

  if (flags.round) {
    /* disable unit repetition with terminal UNITSEPCHAR when rounding */
    if (lastchar(wantstr) == UNITSEPCHAR)
      lastchar(wantstr) = 0;
    if ((lastwantstr = strrchr(wantstr, UNITSEPCHAR)))
      lastwantstr++;
  }

  while (wantstr) {
    if ((nextunitstr = strchr(wantstr, UNITSEPCHAR)))
      *(nextunitstr++) = '\0';
    removespaces(wantstr);

    /*
      if wantstr ends in UNITSEPCHAR, repeat last unit--to give integer
      and fractional parts (3 oz + 0.371241 oz rather than 3.371241 oz)
    */
    if (emptystr(wantstr))              /* coverity[alias_transfer] */
      wantstr = lastunitstr;

    if (processunit(&want, wantstr, NOPOINT)) {
      freeunit(&want);
      return 1;
    }

    if (firstunit){
      /* checkunitlist() ensures conformability within 'wantstr',
         so we just need to check the first unit to see if it conforms
         to 'have' */
      if (compareunits(have, &want, ignore_dimless)) {
        showconformabilityerr(havestr, have, wantstr, &want);
        freeunit(&want);
        return 1;
      }

      /* round to nearest integral multiple of last unit */
      if (flags.round) {
        value = remainder;
        if (nonempty(lastwantstr)) {      /* more than one unit */
          removespaces(lastwantstr);
          initializeunit(&lastwant);
          if (processunit(&lastwant, lastwantstr, NOPOINT)) {
            freeunit(&lastwant);
            return 1;
          }
          remainder = round(remainder / lastwant.factor) * lastwant.factor;
        }
        else    /* first unit is last unit */
          remainder = round(remainder / want.factor) * want.factor;

        round_dir = remainder - value;
      }
      if (flags.verbose == 2) {
        removespaces(havestr);
        logprintf("\t%s = ", havestr);
      } else if (flags.verbose == 1)
        logputchar('\t');
    } /* end if first unit */

    if (0==(sigdigits = getsigdigits(have->factor, remainder, 10)))
      break;    /* nothing left */

    /* Remove sub-precision junk accumulating in the remainder.  Rounding
       is base 2 to ensure that we keep all valid bits. */
    remainder = round_digits(remainder,
                             getsigdigits(have->factor,remainder,2),2);
    if (nextunitstr)
      remainder = want.factor * modf(remainder / want.factor, &value);
    else
      value = remainder / want.factor;

    /* The remainder represents less than one of the current want unit.
       But with display rounding it may round up to 1, leading to an output
       like "4 feet + 12 inch".  Check for this case and if the remainder 
       indeed rounds up to 1 then add that remainder into the current unit 
       and set the remainder to zero. */
    if (nextunitstr){
      double rounded_next =
          round_digits(remainder/want.factor,
                       getsigdigits(have->factor, remainder / want.factor, 10),
                       10);
      if (displays_as(1,rounded_next, NULL)){
        value++;               
        remainder = 0;         /* Remainder is zero */
      }
    }

    /* Round the value to significant digits to prevent display
       of bogus sub-precision decimal digits */
    value = round_digits(value,sigdigits,10);

    /* This ensures that testing value against zero will work below
       at the last unit, which is the only case where value is not integer */
    if (!nextunitstr && displays_as(0, value, NULL))
      value=0;

    if (!flags.verbose){
      if (!firstunit) 
        logputchar(UNITSEPCHAR);
      logprintf(num_format.format,value);
      value_shown=1;
    } else { /* verbose case */
      if (value != 0) {
        if (value_shown) /* have already displayed a number so need a '+' */
          logprintf(" %c ",val_sign);
        else if (val_sign=='-')
          logputs("-");
        showunitname(value, wantstr, PRINTNUM);
        if (sigdigits <= floor(log10(value))+1)   /* Used all sig digits */
          logprintf(" (at %d-digit precision limit)", DBL_DIG);
        value_shown=1;
      }
    }
    
    freeunit(&want);
    lastunitstr = wantstr;
    wantstr = nextunitstr;
    firstunit = 0;
  }

  /* if the final unit value was rounded print indication */
  if (!value_shown) {  /* provide output if every value rounded to zero */
    logputs("0 ");
    if (isdecimal(*lastunitstr))
      logputs("* ");
    logputs(lastunitstr);
  }

  if (round_dir != 0) {
    if (flags.verbose){
      if (round_dir > 0)
        logprintf(" (rounded up to nearest %s) ", lastunitstr);
      else
        logprintf(" (rounded down to nearest %s) ", lastunitstr);
    } else 
      logprintf("%c%c", UNITSEPCHAR, round_dir > 0 ?'-':'+');   
  }
  logputchar('\n');
  return 0;
} /* end showunitlist */


#if defined (_WIN32) && defined (HAVE_MKS_TOOLKIT)
int
ismksmore(char *pager)
{
    static int mksmore = -1;

    if (mksmore >= 0)
      return mksmore;

    /*
      Tries to determine whether the MKS Toolkit version of more(1) or
      less(1) will run.  In older versions of the Toolkit, neither
      accepted '+<lineno>', insisting on the POSIX-compliant '+<lineno>g'.
    */
    if (strstr(pager, "more") || strstr(pager, "less")) {
      char *mypager, *mkspager, *mksroot, *p;
      char pathbuf[FILENAME_MAX + 1];
      struct _stat mybuf, mksbuf;

      mypager = NULL;
      mkspager = NULL;
      mksmore = 0;
      if (strlen(pager) > FILENAME_MAX) {
        fprintf(stderr, "%s: cannot invoke pager--value '%s' in PAGER too long\n",
                progname, pager);
        return 0;       /* TODO: this really isn't the right value */
      }
      else if (!isfullpath(pager)) {
        mypager = (char *) mymalloc(strlen(pager) + strlen(EXE_EXT) + 1, "(ishelpquery)");
        strcpy(mypager, pager);
        if (!((p = strrchr(mypager, '.')) && isexe(p)))
          strcat(mypager, EXE_EXT);

        _searchenv(mypager, "PATH", pathbuf);
      }
      else
        strcpy(pathbuf, pager);

      mksroot = getenv("ROOTDIR");
      if (mksroot) {
        char * mksprog;

        if (strstr(pager, "more"))
          mksprog = "more.exe";
        else
          mksprog = "less.exe";
        mkspager = (char *) mymalloc(strlen(mksroot) + strlen("/mksnt/") + strlen(mksprog) + 1,
                                     "(ishelpquery)");
        strcpy(mkspager, mksroot);
        strcat(mkspager, "\\mksnt\\");
        strcat(mkspager, mksprog);
      }

      if (*pathbuf && mksroot) {
        if (_stat(mkspager, &mksbuf)) {
          fprintf(stderr, "%s: cannot stat file '%s'. ", progname, mkspager);
          perror((char *) NULL);
          return 0;
        }
        if (_stat(pathbuf, &mybuf)) {
          fprintf(stderr, "%s: cannot stat file '%s'. ", progname, pathbuf);
          perror((char *) NULL);
          return 0;
        }
        /*
          if we had inodes, this would be simple ... but if it walks
          like a duck and swims like a duck and quacks like a duck ...
        */
        if (mybuf.st_size   == mksbuf.st_size
          && mybuf.st_ctime == mksbuf.st_ctime
          && mybuf.st_mtime == mksbuf.st_mtime
          && mybuf.st_atime == mksbuf.st_atime
          && mybuf.st_mode  == mksbuf.st_mode)
            mksmore = 1;
      }
      if (mypager)
        free(mypager);
      if (mkspager)
        free(mkspager);
    }

    return mksmore;
}
#endif

/* 
   Checks to see if the input string contains HELPCOMMAND possibly
   followed by a unit name on which help is sought.  If not, then
   return 0.  Otherwise invoke the pager on units file at the line
   where the specified unit is defined.  Then return 1.  */

int
ishelpquery(char *str, struct unittype *have)
{
  struct unitlist *unit;
  struct func *function;
  struct wantalias *alias;
  struct prefixlist *prefix;
  char commandbuf[1000];  /* Hopefully this is enough overkill as no bounds */
  int unitline;           /* checking is performed. */
  char *file;
  char **exitptr;
  char *commandstr;	  /* command string varies with OS */
  
  if (have && !strcmp(str, UNITMATCH)){
    tryallunits(have,0);
    return 1;
  }
  for(exitptr=exit_commands;*exitptr;exitptr++)
    if (!strcmp(str, *exitptr))
      exit(EXIT_SUCCESS);
  if (startswith(str, SEARCHCOMMAND)){
    str+=strlen(SEARCHCOMMAND);
    if (!emptystr(str) && *str != ' ')
      return 0;
    removespaces(str);
    if (emptystr(str)){
      printf("\n\
Type 'search text' to see a list of all unit names \n\
containing 'text' as a substring\n\n");
      return 1;
    }
    tryallunits(0,str);
    return 1;
  }
  if (startswith(str, HELPCOMMAND)){
    str+=strlen(HELPCOMMAND);
    if (!emptystr(str) && *str != ' ')
      return 0;
    removespaces(str);

    if (emptystr(str)){
      int nlines;
      char *unitsfile;
      char *msg = "\n\
%s converts between different measuring systems and    %s6 inches\n\
acts as a units-aware calculator.  At the '%s'    %scm\n\
prompt, type in the units you want to convert from or             * 15.24\n\
an expression to evaluate.  At the '%s' prompt,           / 0.065\n\
enter the units to convert to or press return to see\n\
the reduced form or definition.                           %stempF(75)\n\
                                                          %stempC\n\
The first example shows that 6 inches is about 15 cm              23.889\n\
or (1/0.065) cm.  The second example shows how to\n\
convert 75 degrees Fahrenheit to Celsius.  The third      %sbu^(1/3)\n\
example converts the cube root of a bushel to a list      %sft;in\n\
of semicolon-separated units.                                     1 ft + 0.9 in\n\
\n\
To quit from %s type 'quit' or 'exit'.       %s2 btu + 450 ft lbf\n\
                                                %s(kg^2/s)/(day lb/m^2)\n\
At the '%s' prompt type '%s' to get a            * 1.0660684e+08\n\
list of conformable units.  At either prompt you        / 9.3802611e-09\n\
type 'help myunit' to browse the units database\n\
and read the comments relating to myunit or see         %s6 tbsp sugar\n\
other units related to myunit.  Typing 'search          %sg\n\
text' will show units whose names contain 'text'.               * 75\n\
                                                                / 0.013333333\n\n";
    char *fmsg = "To learn about the available units look in '%s'\n\n";
    FILE *fp;

    /* presumably, this cannot fail because it was already checked at startup */
    unitsfile = findunitsfile(NOERRMSG);

    nlines = countlines(msg);
    /* but check again anyway ... */
    if (unitsfile)
      nlines += countlines(fmsg);

    /* see if we need a pager */
    fp = get_output_fp(nlines);

    fprintf(fp, msg, 
      progname, QUERYHAVE,
      QUERYHAVE, QUERYWANT,
      QUERYWANT,
      QUERYHAVE,QUERYWANT,QUERYHAVE,QUERYWANT,
      progname, QUERYHAVE,QUERYWANT,
      QUERYWANT,
      UNITMATCH,
      QUERYHAVE,QUERYWANT);

      if (unitsfile)
        fprintf(fp, fmsg, unitsfile);

      if (fp != stdout)
        pclose(fp);

      return 1;
    }
    if ((function = fnlookup(str))){
      file = function->file;
      unitline = function->linenumber;
    }
    else if ((unit = ulookup(str))){
      unitline = unit->linenumber;
      file = unit->file;
    }
    else if ((prefix = plookup(str)) && strlen(str)==prefix->len){
      unitline = prefix->linenumber;
      file = prefix->file;
    }
    else if ((alias = aliaslookup(str))){
      unitline = alias->linenumber;
      file = alias->file;
    }
    else {
      printf("Unknown unit '%s'\n",str);
      return 1;
    }

  /*
    With Microsoft compilers, system() uses cmd.exe.
    Inner escaped quotes are necessary for filenames with spaces; outer
    escaped quotes are necessary for cmd.exe to see the command as a
    single string containing one or more quoted strings
    (e.g., cmd /c ""command" "arg1" "arg2" ... ")
  */
#if defined (_WIN32)
  #if defined (HAVE_MKS_TOOLKIT)
    if (strstr(pager, "pg"))
      commandstr = "\"\"%s\" +%d \"%s\"\"";
    else if (ismksmore(pager)) {
      /*
	use the POSIX-compliant '+<number>g' for compatibility with older
	versions of the Toolkit that don't accept '+<number>'
      */
      commandstr = "\"\"%s\" +%dg \"%s\"\"";
    }
    else {
      /*
	more.com apparently takes the number as an offset rather than a
	line number, so that '+1' starts at line 2 of the file.
	more.com also cannot back up, so allow two lines of preceding
	context.
      */
      unitline -= 3;
      if (unitline < 0)
	unitline = 0;
      commandstr = "\"\"%s\"  +%d \"%s\"\"";
    }
  #else /* more.com is probably the only option */
    unitline -= 3;
    if (unitline < 0)
      unitline = 0;
    commandstr = "\"\"%s\"  +%d \"%s\"\"";
  #endif
#else	/* *nix */
    commandstr = "%s +%d %s";
#endif
    sprintf(commandbuf, commandstr, pager, unitline, file);
    if (system(commandbuf))
      fprintf(stderr,"%s: cannot invoke pager '%s' to display help\n", 
              progname, pager);
    return 1;
  }
  return 0;
}


#ifdef SUPPORT_UTF8
void
checklocale()
{
  char *temp;
  temp = setlocale(LC_CTYPE,"");
  utf8mode = (strcmp(nl_langinfo(CODESET),"UTF-8")==0);
  if (temp){
    mylocale = dupstr(temp);
    temp = strchr(mylocale,'.');
    if (temp)
      *temp = 0;
  } else
    mylocale = DEFAULTLOCALE;
}

#else

void
checklocale()
{
  char *temp=0;
  /* environment overrides system */
  temp = getenv("LC_CTYPE");
  if (!temp)
    temp = getenv("LC_ALL");
  if (!temp)
    temp = getenv("LANG");
#ifndef NO_SETLOCALE  
  if (temp)
    temp = setlocale(LC_CTYPE,temp);
  if (!temp)
    temp = setlocale(LC_CTYPE,"");	/* try system default */
#endif
  if (!temp)
    mylocale = DEFAULTLOCALE;
  else {
    mylocale = dupstr(temp);  
    temp = strchr(mylocale,'.');
    if (temp)
      *temp = 0;
  }
}

#endif

/* 
   Replaces an alias in the specified string input.  Returns 1 if the
   alias that is found contains errors. 
*/

int
replacealias(char **string, int *buflen)
{
  int usefree = 1;
  struct wantalias *aliasptr;
  char *input;

  if (!flags.readline && buflen)
    usefree = 0;

  if (nonempty(*string)) {  /* check that string is defined and nonempty */
    input = *string;
    removespaces(input);
    if ((aliasptr=aliaslookup(input))){
      if (checkunitlist(aliasptr->definition,NOERRMSG)){
        puts("Unit list definition contains errors.");
        return 1;
      }
      if (usefree){
        free(*string);
        *string = dupstr(aliasptr->definition);
      } else {                           /* coverity[dead_error_line] */
        while (strlen(aliasptr->definition)>*buflen)
          growbuffer(string, buflen);
        strcpy(*string, aliasptr->definition);
      }
    }
  }
  return 0;
}


/* 
   Remaps the locale name returned on Windows systems to the value
   returned on Unix-like systems
*/

void
remaplocale(char *filename)
{
  FILE *map;
  char *value;
  char name[80];

  map = openfile(filename,"rt");
  if (!map) {
    fprintf(stderr,"%s: cannot open locale map '%s'. ",progname,filename);
    perror((char *) NULL);
  }
  else {
    while(!feof(map)){
      if (!fgets(name,80,map))
        break;
      lastchar(name) = 0;
      value=strchr(name,'#');
      if (value) *value=0;
      value=strchr(name,'\t');
      if (!value) continue;
      *value++=0;
      removespaces(value);
      removespaces(name);
      if (!strcmp(name, mylocale))
        mylocale = dupstr(value);
    }
    fclose(map);
  }
}


void
close_logfile(void)
{
  if (logfile){
    fputc('\n',logfile);
    fclose(logfile);
  }
}


void
open_logfile(void)
{  
  time_t logtime;
  char * timestr;

  logfile = openfile(logfilename, "at");
  if (!logfile){
    fprintf(stderr, "%s: cannot write to log file '%s'.  ", 
            progname, logfilename);
    perror(0);
    exit(EXIT_FAILURE);
  }
  time(&logtime);
  timestr = ctime(&logtime);
  fprintf(logfile, "### Log started %s \n", timestr);
  atexit(close_logfile);
}

void
write_files_sig(int sig)
{
#ifdef READLINE
  if (historyfile)
    save_history();
#endif
  close_logfile();
  signal(sig, SIG_DFL);
  raise(sig);
}



int test_int(int a, int b)
{
    return a + b;
}

char *g_argv_0 = NULL;


void conversion_setup();

#define exit return
int
conversion_worker(char *havestr, char *wantstr)
{
    struct func *funcval;
    struct wantalias *alias;
    struct unittype have;
    struct unittype want;

    conversion_setup();

    replacectrlchars(havestr);
    if (wantstr)
        replacectrlchars(wantstr);
#ifdef SUPPORT_UTF8
    if (strwidth(havestr)<0){
       printf("Error: %s on input\n",invalid_utf8);
       exit(EXIT_FAILURE);
     }
     if (wantstr && strwidth(wantstr)<0){
       printf("Error: %s on input\n",invalid_utf8);
       exit(EXIT_FAILURE);
     }
#endif
    replace_operators(havestr);
    removespaces(havestr);
    if (wantstr) {
        replace_operators(wantstr);
        removespaces(wantstr);
    }
    if ((funcval = fnlookup(havestr))){
        showfuncdefinition(funcval, FUNCTION);
        exit(EXIT_SUCCESS);
    }
    if ((funcval = invfnlookup(havestr))){
        showfuncdefinition(funcval, INVERSE);
        exit(EXIT_SUCCESS);
    }

    if ((alias = aliaslookup(havestr))){
        showunitlistdef(alias);
        exit(EXIT_SUCCESS);
    }
    if (processunit(&have, havestr, NOPOINT))
        exit(EXIT_FAILURE);
    if (flags.showconformable == 1) {
        tryallunits(&have,0);
        exit(EXIT_SUCCESS);
    }
    if (!wantstr){
        showdefinition(havestr,&have);
        exit(EXIT_SUCCESS);
    }
    if (replacealias(&wantstr, 0)) /* the 0 says that we can free wantstr */
        exit(EXIT_FAILURE);
    if ((funcval = fnlookup(wantstr))){
        if (showfunc(havestr, &have, funcval))  /* Clobbers have */
            exit(EXIT_FAILURE);
        else
            exit(EXIT_SUCCESS);
    }
    if (processwant(&want, wantstr, NOPOINT))
        exit(EXIT_FAILURE);
    if (strchr(wantstr, UNITSEPCHAR)){
        if (showunitlist(havestr, &have, wantstr))
            exit(EXIT_FAILURE);
        else
            exit(EXIT_SUCCESS);
    }
    if (showanswer(havestr,&have,wantstr,&want))
        exit(EXIT_FAILURE);
    else
        exit(EXIT_SUCCESS);
}
#undef exit


void
conversion_setup()
{
    static int setup = 0;

    if (setup)
        return;

    setup = 1;

    flags.quiet = 1;       /* Do not supress prompting */
    flags.unitcheck = 0;   /* Unit checking is off */
    flags.verbose = 2;     /* Medium verbosity */
    flags.round = 0;       /* Rounding off */
    flags.strictconvert=0; /* Strict conversion disabled (reciprocals active) */
    flags.unitlists = 1;   /* Multi-unit conversion active */
    flags.oneline = 1;     /* One line output is disabled */
    flags.showconformable=0;  /* show unit conversion rather than all conformable units */
    flags.showfactor = 0;  /* Don't show a multiplier for a 1|x fraction */
    /*       in unit list output */
    parserflags.minusminus = 1;  /* '-' character gives subtraction */
    parserflags.oldstar = 0;     /* '*' has same precedence as '/' */

    progname = getprogramname(g_argv_0);



    if (!(isfullpath(UNITSFILE) && isfullpath(LOCALEMAP)))
        progdir = getprogdir(g_argv_0, &fullprogname);
    else {
        progdir = NULL;
        fullprogname = NULL;
    }
    datadir = getdatadir();      /* directory to search as last resort */

    checklocale();

    homedir = findhome(&homedir_error);

    unitsfiles[0] = 0;

    if (!unitsfiles[0]){
        char *unitsfile;
        unitsfile = findunitsfile(ERRMSG);
        if (!unitsfile)
            exit(EXIT_FAILURE);
        else {
            int file_exists;

            unitsfiles[0] = unitsfile;
            unitsfiles[1] = personalfile(HOME_UNITS_ENV,homeunitsfile,
                                         0, &file_exists);
            unitsfiles[2] = 0;
        }
    }

    char **unitfileptr;
    for(unitfileptr=unitsfiles;*unitfileptr;unitfileptr++){
        int unitcount, prefixcount, funccount;
        int readerr = readunits(*unitfileptr, stderr, &unitcount, &prefixcount,
                                &funccount, 0);
        if (readerr==E_MEMORY || readerr==E_FILE)
            exit(EXIT_FAILURE);
    }
}


void
do_a_conversion(char *input, char *output)
{
    char *inp, *out;

    char units[] = "./units";

    g_argv_0 = units;

    checklocale();

    num_format.format = NULL;
    num_format.precision = DEFAULTPRECISION;
    num_format.type = DEFAULTTYPE;

    if (num_format.format != NULL) {
        if (parsenumformat())
            exit(EXIT_FAILURE);
    }
    else
        setnumformat();

    conversion_worker(input, output);
}


int test_main()
{
    char a[] = "pi", b[] = "";
    do_a_conversion(a, b);
    do_a_conversion(a, b);
    do_a_conversion(a, b);
}


int
old_main(int argc, char **argv)
{
    static struct unittype have, want;
    char *havestr=0, *wantstr=0;
    int leading_spaces;
    struct func *funcval;
    struct wantalias *alias;
    int havestrsize=0;   /* Only used if READLINE is undefined */
    int wantstrsize=0;   /* Only used if READLINE is undefined */
    int readerr;
    char **unitfileptr;
    int unitcount=0, prefixcount=0, funccount=0;   /* for counting units */
    char *queryhave, *querywant, *comment;
    int queryhavewidth, querywantwidth;
#ifdef _WIN32
    char *localemap;
#endif

    /* Set program parameter defaults */
    num_format.format = NULL;
    num_format.precision = DEFAULTPRECISION;
    num_format.type = DEFAULTTYPE;

    flags.quiet = 0;       /* Do not supress prompting */
    flags.unitcheck = 0;   /* Unit checking is off */
    flags.verbose = 1;     /* Medium verbosity */
    flags.round = 0;       /* Rounding off */
    flags.strictconvert=0; /* Strict conversion disabled (reciprocals active) */
    flags.unitlists = 1;   /* Multi-unit conversion active */
    flags.oneline = 0;     /* One line output is disabled */
    flags.showconformable=0;  /* show unit conversion rather than all conformable units */
    flags.showfactor = 0;  /* Don't show a multiplier for a 1|x fraction */
    /*       in unit list output */
    parserflags.minusminus = 1;  /* '-' character gives subtraction */
    parserflags.oldstar = 0;     /* '*' has same precedence as '/' */

    progname = getprogramname(argv[0]);

    /*
      unless UNITSFILE and LOCALEMAP have absolute pathnames, we may need
      progdir to search for supporting files
    */
    if (!(isfullpath(UNITSFILE) && isfullpath(LOCALEMAP)))
        progdir = getprogdir(argv[0], &fullprogname);
    else {
        progdir = NULL;
        fullprogname = NULL;
    }
    datadir = getdatadir();      /* directory to search as last resort */

    checklocale();

    homedir = findhome(&homedir_error);

#ifdef READLINE
    #  if RL_READLINE_VERSION > 0x0402
      rl_completion_entry_function = (rl_compentry_func_t *)completeunits;
#  else
      rl_completion_entry_function = (Function *)completeunits;
#  endif
   rl_basic_word_break_characters = " \t+-*/()|^;";
   flags.readline = isatty(0);
   if (flags.readline){
     int file_exists;
     historyfile = personalfile(NULL,HISTORY_FILE,1,&file_exists);
   }
#else
    flags.readline = 0;
#endif

    unitsfiles[0] = 0;

#ifdef _WIN32
    if (!strcmp(homeunitsfile,".units"))
     homeunitsfile = "unitdef.units";
#endif

    pager = getenv("PAGER");
    if (!pager)
        pager = DEFAULTPAGER;

    flags.interactive = processargs(argc, argv, &havestr, &wantstr);

#ifdef READLINE
    if (flags.interactive && flags.readline && historyfile){
     rl_initialize();
     read_history(historyfile);
     init_history_length = history_length;
     init_history_base = history_base;
     atexit(save_history);
   }
#endif

    signal(SIGINT, write_files_sig);
    signal(SIGTERM, write_files_sig);
#ifdef SIGQUIT
    signal(SIGQUIT, SIG_IGN);         /* Ignore QUIT signal sent by Ctrl-\ or Ctrl-4 */
#endif
    if (logfilename) {
        if (!flags.interactive)
            fprintf(stderr,
                    "Log file '%s' ignored in non-interactive mode.\n",logfilename);
        else open_logfile();
    }

    /* user has specified the complete format--use it */
    if (num_format.format != NULL) {
        if (parsenumformat())
            exit(EXIT_FAILURE);
    }
    else
        setnumformat();

    if (flags.verbose==0)
        deftext = "";

    if (!unitsfiles[0]){
        char *unitsfile;
        unitsfile = findunitsfile(ERRMSG);
        if (!unitsfile)
            exit(EXIT_FAILURE);
        else {
            int file_exists;

            unitsfiles[0] = unitsfile;
            unitsfiles[1] = personalfile(HOME_UNITS_ENV,homeunitsfile,
                                         0, &file_exists);
            unitsfiles[2] = 0;
        }
    }

#ifdef _WIN32
    localemap = findlocalemap(ERRMSG);
   if (localemap)
     remaplocale(localemap);
#endif

    for(unitfileptr=unitsfiles;*unitfileptr;unitfileptr++){
        readerr = readunits(*unitfileptr, stderr, &unitcount, &prefixcount,
                            &funccount, 0);
        if (readerr==E_MEMORY || readerr==E_FILE)
            exit(EXIT_FAILURE);
    }

    if (flags.quiet)
        queryhave = querywant = "";   /* No prompts are being printed */
    else {
        if (!promptprefix){
            queryhave = QUERYHAVE;
            querywant = QUERYWANT;
        } else {
            queryhave = (char *)mymalloc(strlen(promptprefix)+strlen(QUERYHAVE)+1,
                                         "(main)");
            querywant = (char *)mymalloc(strlen(promptprefix)+strlen(QUERYWANT)+1,
                                         "(main)");
            strcpy(queryhave, promptprefix);
            strcat(queryhave, QUERYHAVE);
            memset(querywant, ' ', strlen(promptprefix));
            strcpy(querywant+strlen(promptprefix), QUERYWANT);
        }
        printf("%d units, %d prefixes, %d nonlinear units\n\n",
               unitcount, prefixcount,funccount);
    }
    queryhavewidth = strwidth(queryhave);
    querywantwidth = strwidth(querywant);

    if (flags.unitcheck) {
        checkunits(flags.unitcheck==2 || flags.verbose==2);
        exit(EXIT_SUCCESS);
    }

    if (!flags.interactive) {
        replacectrlchars(havestr);
        if (wantstr)
            replacectrlchars(wantstr);
#ifdef SUPPORT_UTF8
        if (strwidth(havestr)<0){
       printf("Error: %s on input\n",invalid_utf8);
       exit(EXIT_FAILURE);
     }
     if (wantstr && strwidth(wantstr)<0){
       printf("Error: %s on input\n",invalid_utf8);
       exit(EXIT_FAILURE);
     }
#endif
        replace_operators(havestr);
        removespaces(havestr);
        if (wantstr) {
            replace_operators(wantstr);
            removespaces(wantstr);
        }
        if ((funcval = fnlookup(havestr))){
            showfuncdefinition(funcval, FUNCTION);
            exit(EXIT_SUCCESS);
        }
        if ((funcval = invfnlookup(havestr))){
            showfuncdefinition(funcval, INVERSE);
            exit(EXIT_SUCCESS);
        }
        if ((alias = aliaslookup(havestr))){
            showunitlistdef(alias);
            exit(EXIT_SUCCESS);
        }
        if (processunit(&have, havestr, NOPOINT))
            exit(EXIT_FAILURE);
        if (flags.showconformable == 1) {
            tryallunits(&have,0);
            exit(EXIT_SUCCESS);
        }
        if (!wantstr){
            showdefinition(havestr,&have);
            exit(EXIT_SUCCESS);
        }
        if (replacealias(&wantstr, 0)) /* the 0 says that we can free wantstr */
            exit(EXIT_FAILURE);
        if ((funcval = fnlookup(wantstr))){
            if (showfunc(havestr, &have, funcval))  /* Clobbers have */
                exit(EXIT_FAILURE);
            else
                exit(EXIT_SUCCESS);
        }
        if (processwant(&want, wantstr, NOPOINT))
            exit(EXIT_FAILURE);
        if (strchr(wantstr, UNITSEPCHAR)){
            if (showunitlist(havestr, &have, wantstr))
                exit(EXIT_FAILURE);
            else
                exit(EXIT_SUCCESS);
        }
        if (showanswer(havestr,&have,wantstr,&want))
            exit(EXIT_FAILURE);
        else
            exit(EXIT_SUCCESS);
    } else {
        /******************/
        /**  interactive **/
        /******************/
        for (;;) {
            do {
                fflush(stdout);
                getuser(&havestr,&havestrsize,queryhave);
                replace_operators(havestr);
                comment = strip_comment(havestr);
                leading_spaces = strspn(havestr," ");
                removespaces(havestr);
                if (logfile && comment && emptystr(havestr))
                    fprintf(logfile, "#%s\n", comment);
            } while (emptystr(havestr)
                     || ishelpquery(havestr,0)
                     || definevariable(havestr,queryhavewidth+leading_spaces)
                     || (!fnlookup(havestr)
                         && !invfnlookup(havestr)
                         && !aliaslookup(havestr)
                         && processunit(&have, havestr, queryhavewidth+leading_spaces)));
            if (logfile) {
                if (comment)
                    fprintf(logfile, "%s%s\t#%s\n", LOGFROM, havestr,comment);
                else
                    fprintf(logfile, "%s%s\n", LOGFROM, havestr);
            }
            if ((alias = aliaslookup(havestr))){
                showunitlistdef(alias);
                continue;
            }
            if ((funcval = fnlookup(havestr))){
                showfuncdefinition(funcval, FUNCTION);
                continue;
            }
            if ((funcval = invfnlookup(havestr))){
                showfuncdefinition(funcval, INVERSE);
                continue;
            }
            do {
                int repeat;
                do {
                    repeat = 0;
                    fflush(stdout);
                    getuser(&wantstr,&wantstrsize,querywant);
                    replace_operators(wantstr);
                    comment = strip_comment(wantstr);
                    leading_spaces = strspn(wantstr," ");
                    removespaces(wantstr);
                    if (logfile && comment && emptystr(wantstr)){
                        fprintf(logfile, "#%s\n", comment);
                        repeat = 1;
                    }
                    if (ishelpquery(wantstr, &have)){
                        repeat = 1;
                        printf("%s%s\n",queryhave, havestr);
                    }
                } while (repeat);
            } while (replacealias(&wantstr, &wantstrsize)
                     || (!fnlookup(wantstr)
                         && processwant(&want, wantstr, querywantwidth+leading_spaces)));
            if (logfile) {
                fprintf(logfile, "%s", LOGTO);
                tightprint(logfile, wantstr);
                if (comment)
                    fprintf(logfile, "\t#%s", comment);
                putc('\n', logfile);
            }
            if (emptystr(wantstr))
                showdefinition(havestr,&have);
            else if (strchr(wantstr, UNITSEPCHAR))
                showunitlist(havestr, &have, wantstr);
            else if ((funcval = fnlookup(wantstr)))
                showfunc(havestr, &have, funcval); /* Clobbers have */
            else {
                showanswer(havestr,&have,wantstr, &want);
                freeunit(&want);
            }
            unitcopy(&lastunit, &have);
            lastunitset=1;
            freeunit(&have);
        }
    }
    return (0);
}

/* NOTES:

mymalloc, growbuffer and tryallunits are the only places with print
statements that should (?) be removed to make a library.  How can
error reporting in these functions (memory allocation errors) be
handled cleanly for a library implementation?  

Way to report the reduced form of the two operands of a sum when
they are not conformable.

Way to report the required domain when getting an domain error.

*/
