X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fmeasure.c;h=65d9fdddf28934e1e0172027d7b3a46ca14d424b;hb=8b585b7a6ae9d1a90386d56e3ce484cf8204743a;hp=8de7ed1d486bf9ca62a4d399c2b12f4fcb6d8281;hpb=a258e53c63a08b0ec48aea8f03808eb651729424;p=pspp diff --git a/src/output/measure.c b/src/output/measure.c index 8de7ed1d48..65d9fdddf2 100644 --- a/src/output/measure.c +++ b/src/output/measure.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2011, 2012, 2014, 2016 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 @@ -16,19 +16,22 @@ #include -#include +#include "output/measure.h" +#include +#include #include #include #if HAVE_LC_PAPER #include #endif -#include +#include #include -#include +#include "libpspp/str.h" -#include "gl/error.h" +#include "gl/c-strcase.h" +#include "libpspp/message.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -50,7 +53,7 @@ measure_dimension (const char *dimen) char *tail; /* Number. */ - raw = strtod (dimen, &tail); + raw = c_strtod (dimen, &tail); if (raw < 0.0) goto syntax_error; @@ -62,7 +65,7 @@ measure_dimension (const char *dimen) return raw * factor; syntax_error: - error (0, 0, _("`%s' is not a valid length."), dimen); + msg (ME, _("`%s' is not a valid length."), dimen); return -1; } @@ -90,7 +93,7 @@ measure_paper (const char *size, int *h, int *v) /* Treat string that starts with digit as explicit size. */ ok = parse_paper_size (size, h, v); if (!ok) - error (0, 0, _("syntax error in paper size `%s'"), size); + msg (ME, _("syntax error in paper size `%s'"), size); } else { @@ -134,7 +137,7 @@ parse_unit (const char *unit) unit += strspn (unit, CC_SPACES); for (p = units; p < units + sizeof units / sizeof *units; p++) - if (!strcasecmp (unit, p->name)) + if (!c_strcasecmp (unit, p->name)) return p->factor; return 0.0; } @@ -150,7 +153,7 @@ parse_paper_size (const char *size, int *h, int *v) char *tail; /* Width. */ - raw_h = strtod (size, &tail); + raw_h = c_strtod (size, &tail); if (raw_h <= 0.0) return false; @@ -158,7 +161,7 @@ parse_paper_size (const char *size, int *h, int *v) tail += strspn (tail, CC_SPACES "x,"); /* Length. */ - raw_v = strtod (tail, &tail); + raw_v = c_strtod (tail, &tail); if (raw_v <= 0.0) return false; @@ -227,7 +230,7 @@ get_standard_paper_size (struct substring name, int *h, int *v) assert (ok); return ok; } - error (0, 0, _("unknown paper type `%.*s'"), + msg (ME, _("unknown paper type `%.*s'"), (int) ss_length (name), ss_data (name)); return false; } @@ -245,7 +248,7 @@ read_paper_conf (const char *file_name, int *h, int *v) file = fopen (file_name, "r"); if (file == NULL) { - error (0, errno, _("error opening input file `%s'"), file_name); + msg_error (errno, _("error opening input file `%s'"), file_name); return false; } @@ -256,7 +259,7 @@ read_paper_conf (const char *file_name, int *h, int *v) if (!ds_read_config_line (&line, &line_number, file)) { if (ferror (file)) - error (0, errno, _("error reading file `%s'"), file_name); + msg_error (errno, _("error reading file `%s'"), file_name); break; } @@ -273,8 +276,7 @@ read_paper_conf (const char *file_name, int *h, int *v) fclose (file); ds_destroy (&line); - error (0, 0, _("paper size file `%s' does not state a paper size"), - file_name); + msg (ME, _("file `%s' does not state a paper size"), file_name); return false; } @@ -294,15 +296,18 @@ get_default_paper_size (int *h, int *v) return read_paper_conf (getenv ("PAPERCONF"), h, v); #if HAVE_LC_PAPER - /* LC_PAPER is a non-standard glibc extension. */ - *h = (int) nl_langinfo(_NL_PAPER_WIDTH) * (72000 / 25.4); - *v = (int) nl_langinfo(_NL_PAPER_HEIGHT) * (72000 / 25.4); + /* LC_PAPER is a non-standard glibc extension. + The (int)(intptr_t) cast is for 64 Bit Systems where intptr_t + translates to 64 Bit long int but the upper 32 Bits have wrong + values. The result from nl_langinfo is integer (32 Bit) */ + *h = (int)(intptr_t) nl_langinfo(_NL_PAPER_WIDTH) * (72000 / 25.4); + *v = (int)(intptr_t) nl_langinfo(_NL_PAPER_HEIGHT) * (72000 / 25.4); if (*h > 0 && *v > 0) return true; #endif /* libpaper defaults to /etc/papersize. */ - if (fn_exists ("/etc/papersize")) + if (0 == access ("/etc/papersize", R_OK)) return read_paper_conf ("/etc/papersize", h, v); /* Can't find a default. */