From 8bf0f28f869e729d70e11ac81d6e9e395c0ab739 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 19:54:52 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/lib/paper.c b/lib/paper.c index 8817aea..d510c85 100644 --- a/lib/paper.c +++ b/lib/paper.c @@ -20,9 +20,6 @@ #include -#include -#include - #include "paper.h" struct paper { @@ -111,27 +108,6 @@ in PAPERCONFVAR, fall-back to the old behaviour. } const char* defaultpapername(void) { -#if defined(LC_PAPER) && defined(_GNU_SOURCE) - -#define NL_PAPER_GET(x) \ - ((union { char *string; unsigned int word; })nl_langinfo(x)).word - -#define PT_TO_MM(v) (unsigned int)((v * 2.54 * 10 / 72) + 0.5) - - const struct paper* pp; - - unsigned int w = NL_PAPER_GET(_NL_PAPER_WIDTH); - unsigned int h = NL_PAPER_GET(_NL_PAPER_HEIGHT); - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if ( - PT_TO_MM(pp->pswidth) == w && - PT_TO_MM(pp->psheight) == h - ) { - return pp->name; - } - } -#endif return PAPERSIZE; } @@ -140,7 +116,7 @@ char* systempapername(void) { char* paperstr; char* paperenv; const char* paperdef; - FILE* ps = NULL; + FILE* ps; struct stat statbuf; const struct paper* pp; int c; @@ -211,10 +187,7 @@ PAPERSIZEVAR, fall-back to the old behaviour. fclose(ps); paperstr = malloc((strlen(papername) + 1) * sizeof(char)); - if (! paperstr) { - free(papername); - return 0; - } + if (! paperstr) return 0; strcpy(paperstr, papername); free(papername); @@ -227,9 +200,6 @@ PAPERSIZEVAR, fall-back to the old behaviour. } } - if (ps) - fclose(ps); - paperdef = defaultpapername(); paperstr = malloc((strlen(paperdef) + 1) * sizeof(char)); diff --git a/lib/paper.c.covscan b/lib/paper.c.covscan deleted file mode 100644 index 57db599..0000000 --- a/lib/paper.c.covscan +++ /dev/null @@ -1,265 +0,0 @@ - -/* - * Copyright (C) Yves Arrouye , 1996. - * - * Use under the GPL version 2. You are not allowed to remove this - * copyright notice. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#include "paper.h" - -struct paper { - const char* name; - double pswidth, psheight; -}; - -/* This table will be searched in order: please put typical paper sizes - at the beginning of it. */ - -/* The paper names have been got from gs 3.68 gs_stadt.ps file, with - some personal additions. */ - -static struct paper papers[] = { -#include "paperspecs.h" - { 0 } -}; - -int paperinit(void) { - return 0; -} - -int paperdone(void) { - return 0; -} - -const char* papername(const struct paper* spaper) -{ - return spaper->name; -} - -double paperpswidth(const struct paper* spaper) -{ - return spaper->pswidth; -} - -double paperpsheight(const struct paper* spaper) -{ - return spaper->psheight; -} - -const struct paper* paperfirst(void) { - return papers; -} - -const struct paper* paperlast(void) { - static const struct paper* lastpaper = 0; - - const struct paper* next = papers; - while (next->name) { - lastpaper = next, ++next; - } - - return lastpaper; -} - -const struct paper* papernext(const struct paper* spaper) -{ - return (++spaper)->name ? spaper : 0; -} - -const struct paper* paperprev(const struct paper* spaper) -{ - return spaper == papers ? 0 : --spaper; -} - -const char* defaultpapersizefile(void) { - return PAPERCONF; -} - -const char* systempapersizefile(void) { - const char* paperconf = getenv(PAPERCONFVAR); -/* -Previously PAPERCONFVAR used to contain a paper name and PAPERSIZEVAR -contained a file path. Now they're reversed. If we don't find a '/' -in PAPERCONFVAR, fall-back to the old behaviour. -*/ - - if ((paperconf != NULL) && (strchr(paperconf, '/') == NULL)) { - paperconf = getenv(PAPERSIZEVAR); - if ((paperconf != NULL) && (strchr(paperconf, '/') == NULL)) - paperconf = NULL; - } - - return paperconf ? paperconf : defaultpapersizefile(); -} - -const char* defaultpapername(void) { -#if defined(LC_PAPER) && defined(_GNU_SOURCE) - -#define NL_PAPER_GET(x) \ - ((union { char *string; unsigned int word; })nl_langinfo(x)).word - -#define PT_TO_MM(v) (unsigned int)((v * 2.54 * 10 / 72) + 0.5) - - const struct paper* pp; - - unsigned int w = NL_PAPER_GET(_NL_PAPER_WIDTH); - unsigned int h = NL_PAPER_GET(_NL_PAPER_HEIGHT); - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if ( - PT_TO_MM(pp->pswidth) == w && - PT_TO_MM(pp->psheight) == h - ) { - return pp->name; - } - } -#endif - return PAPERSIZE; -} - -char* systempapername(void) { - const char* paperconf; - char* paperstr; - char* paperenv; - const char* paperdef; - FILE* ps = NULL; - struct stat statbuf; - const struct paper* pp; - int c; - -/* -Previously PAPERSIZEVAR used to contain a file path and PAPERCONFVAR -contained a paper name. Now they're reversed. If we find a '/' in -PAPERSIZEVAR, fall-back to the old behaviour. -*/ - - paperenv = getenv(PAPERSIZEVAR); - if ((paperenv != NULL) && (strchr(paperenv, '/') != NULL)) { - paperenv = getenv(PAPERCONFVAR); - if ((paperenv != NULL) && (strchr(paperenv, '/') != NULL)) - paperenv = NULL; - } - - if (paperenv) { - paperstr = malloc((strlen(paperenv) + 1) * sizeof(char)); - - if (! paperstr) return 0; - - if ((pp = paperinfo(paperenv))) - return strcpy(paperstr, pp->name); - else - return strcpy(paperstr, paperenv); - } - - paperconf = systempapersizefile(); - if (paperconf && stat(paperconf, &statbuf) == -1) return 0; - - if (!paperconf) paperconf = defaultpapersizefile(); - - if ((stat(paperconf, &statbuf) != -1) && - (ps = fopen(paperconf, "r"))) { - - while ((c = getc(ps)) != EOF) { - if (c == '#') { - while ((c = getc(ps)) != EOF && c != '\n'); - if (c == EOF) { - break; - } - } else if (!isspace(c)) { - unsigned n = 0, m = 64; - char* papername = malloc(m * sizeof(char)); - - if (!papername) { - fclose(ps); - return 0; - } - - do { - if (n == m-1) { - char* newpaper = realloc(papername, - (m *= 2) * sizeof(char)); - if (!newpaper) { - free(papername); - fclose(ps); - return 0; - } - papername = newpaper; - } - papername[n++] = c; - } while ((c = getc(ps)) != EOF && !isspace(c)); - - papername[n] = 0; - - fclose(ps); - - paperstr = malloc((strlen(papername) + 1) * sizeof(char)); - if (! paperstr) return 0; - - strcpy(paperstr, papername); - free(papername); - - if ((pp = paperinfo(paperstr))) - return strcpy(paperstr, pp->name); - else - return paperstr; - } - } - } - - if (ps) - fclose(ps); - - paperdef = defaultpapername(); - paperstr = malloc((strlen(paperdef) + 1) * sizeof(char)); - - if (paperstr) - return strcpy(paperstr, paperdef); - else - return 0; -} - -const struct paper* paperinfo(const char* paper) -{ - const struct paper* pp; - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if (!strcasecmp(pp->name, paper)) { - return pp; - } - } - - return 0; -} - -const struct paper* paperwithsize(double pswidth, double psheight) -{ - const struct paper* pp; - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if (pp->pswidth == pswidth - && pp->psheight == psheight) { - return pp; - } - } - - return 0; -} - diff --git a/lib/paper.c.file-leak b/lib/paper.c.file-leak deleted file mode 100644 index 0039bb0..0000000 --- a/lib/paper.c.file-leak +++ /dev/null @@ -1,262 +0,0 @@ - -/* - * Copyright (C) Yves Arrouye , 1996. - * - * Use under the GPL version 2. You are not allowed to remove this - * copyright notice. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#include "paper.h" - -struct paper { - const char* name; - double pswidth, psheight; -}; - -/* This table will be searched in order: please put typical paper sizes - at the beginning of it. */ - -/* The paper names have been got from gs 3.68 gs_stadt.ps file, with - some personal additions. */ - -static struct paper papers[] = { -#include "paperspecs.h" - { 0 } -}; - -int paperinit(void) { - return 0; -} - -int paperdone(void) { - return 0; -} - -const char* papername(const struct paper* spaper) -{ - return spaper->name; -} - -double paperpswidth(const struct paper* spaper) -{ - return spaper->pswidth; -} - -double paperpsheight(const struct paper* spaper) -{ - return spaper->psheight; -} - -const struct paper* paperfirst(void) { - return papers; -} - -const struct paper* paperlast(void) { - static const struct paper* lastpaper = 0; - - const struct paper* next = papers; - while (next->name) { - lastpaper = next, ++next; - } - - return lastpaper; -} - -const struct paper* papernext(const struct paper* spaper) -{ - return (++spaper)->name ? spaper : 0; -} - -const struct paper* paperprev(const struct paper* spaper) -{ - return spaper == papers ? 0 : --spaper; -} - -const char* defaultpapersizefile(void) { - return PAPERCONF; -} - -const char* systempapersizefile(void) { - const char* paperconf = getenv(PAPERCONFVAR); -/* -Previously PAPERCONFVAR used to contain a paper name and PAPERSIZEVAR -contained a file path. Now they're reversed. If we don't find a '/' -in PAPERCONFVAR, fall-back to the old behaviour. -*/ - - if ((paperconf != NULL) && (strchr(paperconf, '/') == NULL)) { - paperconf = getenv(PAPERSIZEVAR); - if ((paperconf != NULL) && (strchr(paperconf, '/') == NULL)) - paperconf = NULL; - } - - return paperconf ? paperconf : defaultpapersizefile(); -} - -const char* defaultpapername(void) { -#if defined(LC_PAPER) && defined(_GNU_SOURCE) - -#define NL_PAPER_GET(x) \ - ((union { char *string; unsigned int word; })nl_langinfo(x)).word - -#define PT_TO_MM(v) (unsigned int)((v * 2.54 * 10 / 72) + 0.5) - - const struct paper* pp; - - unsigned int w = NL_PAPER_GET(_NL_PAPER_WIDTH); - unsigned int h = NL_PAPER_GET(_NL_PAPER_HEIGHT); - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if ( - PT_TO_MM(pp->pswidth) == w && - PT_TO_MM(pp->psheight) == h - ) { - return pp->name; - } - } -#endif - return PAPERSIZE; -} - -char* systempapername(void) { - const char* paperconf; - char* paperstr; - char* paperenv; - const char* paperdef; - FILE* ps; - struct stat statbuf; - const struct paper* pp; - int c; - -/* -Previously PAPERSIZEVAR used to contain a file path and PAPERCONFVAR -contained a paper name. Now they're reversed. If we find a '/' in -PAPERSIZEVAR, fall-back to the old behaviour. -*/ - - paperenv = getenv(PAPERSIZEVAR); - if ((paperenv != NULL) && (strchr(paperenv, '/') != NULL)) { - paperenv = getenv(PAPERCONFVAR); - if ((paperenv != NULL) && (strchr(paperenv, '/') != NULL)) - paperenv = NULL; - } - - if (paperenv) { - paperstr = malloc((strlen(paperenv) + 1) * sizeof(char)); - - if (! paperstr) return 0; - - if ((pp = paperinfo(paperenv))) - return strcpy(paperstr, pp->name); - else - return strcpy(paperstr, paperenv); - } - - paperconf = systempapersizefile(); - if (paperconf && stat(paperconf, &statbuf) == -1) return 0; - - if (!paperconf) paperconf = defaultpapersizefile(); - - if ((stat(paperconf, &statbuf) != -1) && - (ps = fopen(paperconf, "r"))) { - - while ((c = getc(ps)) != EOF) { - if (c == '#') { - while ((c = getc(ps)) != EOF && c != '\n'); - if (c == EOF) { - break; - } - } else if (!isspace(c)) { - unsigned n = 0, m = 64; - char* papername = malloc(m * sizeof(char)); - - if (!papername) { - fclose(ps); - return 0; - } - - do { - if (n == m-1) { - char* newpaper = realloc(papername, - (m *= 2) * sizeof(char)); - if (!newpaper) { - free(papername); - fclose(ps); - return 0; - } - papername = newpaper; - } - papername[n++] = c; - } while ((c = getc(ps)) != EOF && !isspace(c)); - - papername[n] = 0; - - fclose(ps); - - paperstr = malloc((strlen(papername) + 1) * sizeof(char)); - if (! paperstr) return 0; - - strcpy(paperstr, papername); - free(papername); - - if ((pp = paperinfo(paperstr))) - return strcpy(paperstr, pp->name); - else - return paperstr; - } - } - } - - paperdef = defaultpapername(); - paperstr = malloc((strlen(paperdef) + 1) * sizeof(char)); - - if (paperstr) - return strcpy(paperstr, paperdef); - else - return 0; -} - -const struct paper* paperinfo(const char* paper) -{ - const struct paper* pp; - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if (!strcasecmp(pp->name, paper)) { - return pp; - } - } - - return 0; -} - -const struct paper* paperwithsize(double pswidth, double psheight) -{ - const struct paper* pp; - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if (pp->pswidth == pswidth - && pp->psheight == psheight) { - return pp; - } - } - - return 0; -} - diff --git a/lib/paper.c.useglibcfallback b/lib/paper.c.useglibcfallback deleted file mode 100644 index d510c85..0000000 --- a/lib/paper.c.useglibcfallback +++ /dev/null @@ -1,238 +0,0 @@ - -/* - * Copyright (C) Yves Arrouye , 1996. - * - * Use under the GPL version 2. You are not allowed to remove this - * copyright notice. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include - -#include - -#include "paper.h" - -struct paper { - const char* name; - double pswidth, psheight; -}; - -/* This table will be searched in order: please put typical paper sizes - at the beginning of it. */ - -/* The paper names have been got from gs 3.68 gs_stadt.ps file, with - some personal additions. */ - -static struct paper papers[] = { -#include "paperspecs.h" - { 0 } -}; - -int paperinit(void) { - return 0; -} - -int paperdone(void) { - return 0; -} - -const char* papername(const struct paper* spaper) -{ - return spaper->name; -} - -double paperpswidth(const struct paper* spaper) -{ - return spaper->pswidth; -} - -double paperpsheight(const struct paper* spaper) -{ - return spaper->psheight; -} - -const struct paper* paperfirst(void) { - return papers; -} - -const struct paper* paperlast(void) { - static const struct paper* lastpaper = 0; - - const struct paper* next = papers; - while (next->name) { - lastpaper = next, ++next; - } - - return lastpaper; -} - -const struct paper* papernext(const struct paper* spaper) -{ - return (++spaper)->name ? spaper : 0; -} - -const struct paper* paperprev(const struct paper* spaper) -{ - return spaper == papers ? 0 : --spaper; -} - -const char* defaultpapersizefile(void) { - return PAPERCONF; -} - -const char* systempapersizefile(void) { - const char* paperconf = getenv(PAPERCONFVAR); -/* -Previously PAPERCONFVAR used to contain a paper name and PAPERSIZEVAR -contained a file path. Now they're reversed. If we don't find a '/' -in PAPERCONFVAR, fall-back to the old behaviour. -*/ - - if ((paperconf != NULL) && (strchr(paperconf, '/') == NULL)) { - paperconf = getenv(PAPERSIZEVAR); - if ((paperconf != NULL) && (strchr(paperconf, '/') == NULL)) - paperconf = NULL; - } - - return paperconf ? paperconf : defaultpapersizefile(); -} - -const char* defaultpapername(void) { - return PAPERSIZE; -} - -char* systempapername(void) { - const char* paperconf; - char* paperstr; - char* paperenv; - const char* paperdef; - FILE* ps; - struct stat statbuf; - const struct paper* pp; - int c; - -/* -Previously PAPERSIZEVAR used to contain a file path and PAPERCONFVAR -contained a paper name. Now they're reversed. If we find a '/' in -PAPERSIZEVAR, fall-back to the old behaviour. -*/ - - paperenv = getenv(PAPERSIZEVAR); - if ((paperenv != NULL) && (strchr(paperenv, '/') != NULL)) { - paperenv = getenv(PAPERCONFVAR); - if ((paperenv != NULL) && (strchr(paperenv, '/') != NULL)) - paperenv = NULL; - } - - if (paperenv) { - paperstr = malloc((strlen(paperenv) + 1) * sizeof(char)); - - if (! paperstr) return 0; - - if ((pp = paperinfo(paperenv))) - return strcpy(paperstr, pp->name); - else - return strcpy(paperstr, paperenv); - } - - paperconf = systempapersizefile(); - if (paperconf && stat(paperconf, &statbuf) == -1) return 0; - - if (!paperconf) paperconf = defaultpapersizefile(); - - if ((stat(paperconf, &statbuf) != -1) && - (ps = fopen(paperconf, "r"))) { - - while ((c = getc(ps)) != EOF) { - if (c == '#') { - while ((c = getc(ps)) != EOF && c != '\n'); - if (c == EOF) { - break; - } - } else if (!isspace(c)) { - unsigned n = 0, m = 64; - char* papername = malloc(m * sizeof(char)); - - if (!papername) { - fclose(ps); - return 0; - } - - do { - if (n == m-1) { - char* newpaper = realloc(papername, - (m *= 2) * sizeof(char)); - if (!newpaper) { - free(papername); - fclose(ps); - return 0; - } - papername = newpaper; - } - papername[n++] = c; - } while ((c = getc(ps)) != EOF && !isspace(c)); - - papername[n] = 0; - - fclose(ps); - - paperstr = malloc((strlen(papername) + 1) * sizeof(char)); - if (! paperstr) return 0; - - strcpy(paperstr, papername); - free(papername); - - if ((pp = paperinfo(paperstr))) - return strcpy(paperstr, pp->name); - else - return paperstr; - } - } - } - - paperdef = defaultpapername(); - paperstr = malloc((strlen(paperdef) + 1) * sizeof(char)); - - if (paperstr) - return strcpy(paperstr, paperdef); - else - return 0; -} - -const struct paper* paperinfo(const char* paper) -{ - const struct paper* pp; - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if (!strcasecmp(pp->name, paper)) { - return pp; - } - } - - return 0; -} - -const struct paper* paperwithsize(double pswidth, double psheight) -{ - const struct paper* pp; - - for (pp = paperfirst(); pp; pp = papernext(pp)) { - if (pp->pswidth == pswidth - && pp->psheight == psheight) { - return pp; - } - } - - return 0; -} - diff --git a/man/paperconf.1.in b/man/paperconf.1.in index a33faa8..6be58eb 100644 --- a/man/paperconf.1.in +++ b/man/paperconf.1.in @@ -48,12 +48,10 @@ looking in order at the .B @PAPERSIZEVAR@ environment variable, at the contents of the file specified by the .B @PAPERCONFVAR@ -environment variable, at the contents of the file +environment variable, at the contents of .B @PAPERCONF@ -, consulting the values controlled by the -.B LC_PAPER -locale setting, or by using -.B @PAPERSIZE@ +or by using +.B letter as a fall-back value if none of the other alternatives are successful. By default, width and height of the paper are printed in PostScript points. .SH OPTIONS diff --git a/man/paperconf.1.in.useglibcfallback b/man/paperconf.1.in.useglibcfallback deleted file mode 100644 index 6be58eb..0000000 --- a/man/paperconf.1.in.useglibcfallback +++ /dev/null @@ -1,118 +0,0 @@ -.TH PAPERCONF 1 "24 April 2001" -.SH NAME -.B paperconf -\- print paper configuration information -.SH SYNOPSIS -.B paperconf -[ -[ -.B \-p -] -.I paper -| -.B \-d -| -.B \-a -] -[ -.B \-z -] -[ -.B \-n -| -.B \-N -] -[ -.B \-s -| -.B \-w -| -.B \-h -] -[ -.B \-c -| -.B \-m -| -.B \-i -] -.SH DESCRIPTION -.B paperconf -prints information about a given paper. -The information that can be obtained is the name of the paper, its -size and its width or height. -When called without arguments, -.B paperconf -prints the name of the system- or user-specified paper, obtained by -looking in order at the -.B @PAPERSIZEVAR@ -environment variable, at the contents of the file specified by the -.B @PAPERCONFVAR@ -environment variable, at the contents of -.B @PAPERCONF@ -or by using -.B letter -as a fall-back value if none of the other alternatives are successful. -By default, width and height of the paper are printed in PostScript points. -.SH OPTIONS -.TP -.BI \-p " paper" -Specify the name of the -.I paper -about which information is asked. -.TP -.B \-d -Use the default builtin paper name. -.TP -.B \-a -Consider all known paper names. -.TP -.B \-z -If the paper name is unknown, print it but issue a message on the -standard error and exit with a non-zero code. -.TP -.B \-n -Print the name of the paper. -.TP -.B \-N -Print the name of the paper with the first letter capitalized. -.TP -.B \-s -Print the size (width followed by height) of the paper. -.TP -.B \-w -Print the width of the paper. -.TP -.B \-h -Print the height of the paper. -.TP -.B \-c -Use centimetres as unit for paper size. -.TP -.B \-m -Use millimetres as unit for paper size. -.TP -.B \-i -Use inches as unit for paper size. - -.SH ENVIRONMENT -.TP 20 -.B @PAPERSIZEVAR@ -Paper size to use regardless of what the papersize file contains. -.TP 20 -.B @PAPERCONFVAR@ -Full path to a file containing the paper size to use. -.SH FILES -.TP 20 -.B @PAPERCONF@ -Contains the name of the system-wide default paper size to be used -if the -.B @PAPERSIZEVAR@ -and -.B @PAPERCONFVAR@ -variables are not set. -.SH AUTHOR -Yves Arrouye -.SH SEE ALSO -.BR papersize (5) - diff --git a/src/paperconf.c b/src/paperconf.c index a52ef34..d0fa34f 100644 --- a/src/paperconf.c +++ b/src/paperconf.c @@ -13,7 +13,6 @@ #include #include -#include /* needed for GNU/Hurd */ @@ -100,8 +99,6 @@ int main(int argc, char** argv) const char* progname; - setlocale(LC_ALL, ""); - progname = strrchr(*argv, '/'); if (progname) { ++progname; diff --git a/src/paperconf.c.useglibcfallback b/src/paperconf.c.useglibcfallback deleted file mode 100644 index d0fa34f..0000000 --- a/src/paperconf.c.useglibcfallback +++ /dev/null @@ -1,234 +0,0 @@ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include -#include -#include - -#include - - -/* needed for GNU/Hurd */ -#ifndef MAXPATHLEN -#define MAXPATHLEN 4096 -#endif - -static void usage(const char* name) -{ - fprintf(stderr, - "usage: %s [ [ -p ] papername | -d | -a ] [ -z ] [ -n | -N ] [ -s | -w | -h ] [ -c | -m | -i ]\n", - name); - exit(1); -} - -#define OPT_NAME 1 -#define OPT_UPPERNAME 2 -#define OPT_WIDTH 4 -#define OPT_HEIGHT 8 -#define OPT_CM 16 -#define OPT_MM 32 -#define OPT_INCH 64 -#define OPT_CONTINUE 128 - -#define OPT_UNIT (OPT_CM | OPT_MM | OPT_INCH) - -#define INCHxCM 2.54 - -static void printinfo(const struct paper* paper, int options) -{ - int pr = 0; - - if ((options & ~(OPT_CONTINUE)) == 0) { - options = OPT_NAME; - } - - if (options & OPT_NAME) { - printf("%s", papername(paper)); - pr = 1; - } else if (options & OPT_UPPERNAME) { - if (islower(*papername(paper))) { - printf("%c%s", toupper(*papername(paper)), papername(paper) + 1); - } else { - printf("%s", papername(paper)); - } - pr = 1; - } - - if (options & OPT_WIDTH) { - if (pr) putchar(' '); - if (options & OPT_CM) - printf("%g cm", paperpswidth(paper) / 72.0 * INCHxCM ); - else if (options & OPT_MM) - printf("%g mm", paperpswidth(paper) / 72.0 * 10 * INCHxCM ); - else if (options & OPT_INCH) - printf("%g\"", paperpswidth(paper) / 72.0 ); - else - printf("%g", paperpswidth(paper) ); - pr = 1; - } - if (options & OPT_HEIGHT) { - if (pr) putchar(' '); - if (options & OPT_CM) - printf("%g cm", paperpsheight(paper) / 72.0 * INCHxCM ); - else if (options & OPT_MM) - printf("%g mm", paperpsheight(paper) / 72.0 * 10 * INCHxCM ); - else if (options & OPT_INCH) - printf("%g\"", paperpsheight(paper) / 72.0 ); - else - printf("%g", paperpsheight(paper) ); - pr = 1; - } - - putchar('\n'); -} - -int main(int argc, char** argv) -{ - int c; - - int all = 0; - const char* paper = 0; - unsigned options = 0; - - const char* progname; - - progname = strrchr(*argv, '/'); - if (progname) { - ++progname; - } else { - progname = *argv; - } - - while ((c = getopt(argc, argv, "adznNswhcmip:")) != EOF) { - switch (c) { - case 'a': - if (paper || all) { - usage(progname); - } - all = 1; - break; - - case 'd': - if (paper || all) { - usage(progname); - } - paper = defaultpapername(); - break; - - case 'p': - if (paper || all) { - usage(progname); - } - paper = optarg; - break; - - case 'z': - options |= OPT_CONTINUE; - break; - - case 'n': - if (options & OPT_UPPERNAME) usage(progname); - options |= OPT_NAME; - break; - - case 'N': - if (options & OPT_NAME) usage(progname); - options |= OPT_UPPERNAME; - break; - - case 's': - options |= OPT_WIDTH | OPT_HEIGHT; - break; - - case 'w': - options |= OPT_WIDTH; - break; - - case 'h': - options |= OPT_HEIGHT; - break; - - case 'c': - if (options & OPT_UNIT) usage(progname); - options |= OPT_CM; - break; - - case 'm': - if (options & OPT_UNIT) usage(progname); - options |= OPT_MM; - break; - - case 'i': - if (options & OPT_UNIT) usage(progname); - options |= OPT_INCH; - break; - - default: - usage(progname); - } - } - - if (optind < argc - 1 || (paper && optind != argc)) { - usage(progname); - } else if (optind != argc) { - paper = argv[optind]; - } - - paperinit(); - - if (all) { - const struct paper* papers; - - for (papers = paperfirst(); papers; papers = papernext(papers)) { - printinfo(papers, options); - } - } else { - const struct paper* syspaper; - - if (!paper) paper = systempapername(); - if (!paper) paper = defaultpapername(); - if (!paper) { - char errmsg[2 * MAXPATHLEN + 64]; - - sprintf(errmsg, "%s: cannot get paper size from %s", - progname, systempapersizefile()); - - if (errno) { - perror(errmsg); - } else { - fputs(errmsg, stderr); - } - - paperdone(); - - exit(3); - } - - syspaper = paperinfo(paper); - - if (syspaper) { - printinfo(syspaper, options); - } else { - fprintf(stderr, "%s: unknown paper `%s'\n", progname, paper); - if (options & OPT_CONTINUE) { - puts(paper); - } - - paperdone(); - - exit(2); - } - } - - paperdone(); - - return 0; -} -