2 Copyright (C) 2005,2006,2007,2008 Eugene K. Ressler, Jr.
4 This file is part of Sketch, a small, simple system for making
5 3d drawings with LaTeX and the PSTricks or TikZ package.
7 Sketch is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Sketch is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Sketch; see the file COPYING.txt. If not, see
19 http://www.gnu.org/copyleft */
27 return '0' <= ch
&& ch
<= '9';
33 return ('A' <= ch
&& ch
<= 'Z') ? ch
+ ('a' - 'A') : ch
;
39 return ('a' <= ch
&& ch
<= 'z') || ('A' <= ch
&& ch
<= 'Z');
43 parse_pst_version (PST_VERSION
*v
, char *str
, SRC_LINE line
)
45 #define M (sizeof v->key / 2)
46 int i
= 0, iv
= 0, i_minor
= -1;
48 memset(v
->key
, '0', sizeof v
->key
);
49 memset(v
->str
, '\0', sizeof v
->str
);
51 if (strlen(str
) > sizeof v
->str
- 1)
53 err (line
, "PSTricks version string too long");
57 if ( is_digit (str
[i
]) )
59 v
->str
[iv
++] = str
[i
++];
64 err (line
, "bad character '%c' in PSTricks version", str
[i
]);
68 if ( is_digit (str
[i
]) )
70 v
->str
[iv
++] = str
[i
++];
73 else if ( str
[i
] == '.' )
75 memcpy (&v
->key
[M
- i
], v
->str
, i
); // save major in key
76 v
->str
[iv
++] = str
[i
++];
77 i_minor
= iv
; // remember where minor version starts
82 err (line
, "expected dot in PSTricks version");
86 if ( is_digit (str
[i
]) )
88 v
->str
[iv
++] = str
[i
++];
93 err (line
, "expected digit after dot in PSTricks version");
97 if ( is_digit (str
[i
]) )
99 v
->str
[iv
++] = str
[i
++];
102 else if ( is_alpha(str
[i
]) )
104 v
->str
[iv
++] = lower (str
[i
++]);
107 else if ( str
[i
] == '\0' )
109 memcpy (&v
->key
[M
], &v
->str
[i_minor
], i
- i_minor
); // save minor in key
110 return 0; /* accept */
114 err (line
, "expected digit or subversion letter in PSTricks version");
118 if ( str
[i
] == '\0' )
120 memcpy (&v
->key
[M
], &v
->str
[i_minor
], i
- i_minor
);
121 return 0; /* accept */
125 err (line
, "expected end of PSTricks version, found '%c'", str
[i
]);
132 pst_version_cmp(PST_VERSION
*a
, PST_VERSION
*b
)
134 return strncmp(a
->key
, b
->key
, sizeof a
->key
);
137 int parse_tikz_version (TIKZ_VERSION
*v
, char *str
, SRC_LINE line
)
139 return parse_pst_version(v
, str
, line
);
142 int tikz_version_cmp(TIKZ_VERSION
*a
, TIKZ_VERSION
*b
)
144 return pst_version_cmp(a
, b
);