w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dimen.c
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) Yves Arrouye <Yves.Arrouye@marin.fdn.fr>, 1996.
4  *
5  * Use under the GPL version 2. You are not allowed to remove this
6  * copyright notice.
7  *
8  */
9 
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 
14 #include <ctype.h>
15 #include <string.h>
16 #include <stdlib.h>
17 
18 #include "dimen.h"
19 
20 static struct {
21  const char* name;
22  float factor;
23 } units[] = {
24  { "in", 1. },
25  { "ft", 12. },
26  { "pt", 1. / 72. },
27  { "m", 100. / 2.54 },
28  { "dm", 10. / 2.54 },
29  { "cm", 1. / 2.54 },
30  { "mm", .1 / 2.54 },
31  { 0 }
32 };
33 
34 float unitfactor(const char* unit)
35 {
36  int i;
37 
38  for (i = 0; units[i].name; ++i) {
39  if (!strcasecmp(units[i].name, unit)) {
40  return units[i].factor;
41  }
42  }
43 
44  return 0;
45 }
46 
47 int psdimension(const char* what, int* dim)
48 {
49  const char* unit;
50  int dot = 0;
51 
52  if (!what || !*what) return -1;
53 
54  if (*(unit = what) == '-') ++unit;
55 
56  for (; isdigit((unsigned char)*unit) || (*unit == '.' && !dot++); ++unit);
57 
58  if (*unit && !isalpha((unsigned char)*unit)) {
59  return -1;
60  } else {
61  double base = atof(what);
62  double factor = unitfactor(unit);
63 
64  if (factor) {
65  *dim = base * factor * 72;
66  return 0;
67  }
68 
69  return 1;
70  }
71 }
72 
#define dot
Definition: globals.h:56
int base
Definition: gsftopk.c:1502
unsigned long dim
Definition: hpcdtoppm.c:62
small capitals from c petite p scientific i
Definition: afcover.h:80
int psdimension(char *what, int *dim)
Definition: dimen.c:47
float factor
Definition: dimen.c:22
float unitfactor(char *unit)
Definition: dimen.c:34
char * name
Definition: dimen.c:21
double atof(const char *)
#define strcasecmp
Definition: c-auto.h:150
#define isdigit(c)
Definition: snprintf.c:177
int unit
Definition: tfmread.c:8
#define isalpha(ch)
Definition: utype.h:82
Definition: fio.h:71