initial setup of thesis repository
[cluster_expansion_thesis.git] / little_helpers / tikz / sketch-0.2.161 / langver.c
blob6ecff8ef0b074317b1d080e23ffe0f6f0128d855
1 /* langver.c
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)
10 any later version.
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 */
21 #include <string.h>
22 #include "langver.h"
24 int
25 is_digit (int ch)
27 return '0' <= ch && ch <= '9';
30 int
31 lower (int ch)
33 return ('A' <= ch && ch <= 'Z') ? ch + ('a' - 'A') : ch;
36 int
37 is_alpha(int ch)
39 return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z');
42 int
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");
54 return 1;
56 A :
57 if ( is_digit (str[i]) )
59 v->str[iv++] = str[i++];
60 goto B;
62 else
64 err (line, "bad character '%c' in PSTricks version", str[i]);
65 return 2;
67 B :
68 if ( is_digit (str[i]) )
70 v->str[iv++] = str[i++];
71 goto B;
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
78 goto C;
80 else
82 err (line, "expected dot in PSTricks version");
83 return 3;
85 C :
86 if ( is_digit (str[i]) )
88 v->str[iv++] = str[i++];
89 goto D;
91 else
93 err (line, "expected digit after dot in PSTricks version");
94 return 4;
96 D :
97 if ( is_digit (str[i]) )
99 v->str[iv++] = str[i++];
100 goto D;
102 else if ( is_alpha(str[i]) )
104 v->str[iv++] = lower (str[i++]);
105 goto F;
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 */
112 else
114 err (line, "expected digit or subversion letter in PSTricks version");
115 return 5;
118 if ( str[i] == '\0' )
120 memcpy (&v->key[M], &v->str[i_minor], i - i_minor);
121 return 0; /* accept */
123 else
125 err (line, "expected end of PSTricks version, found '%c'", str[i]);
126 return 6;
128 return -1;
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);