summaryrefslogtreecommitdiff
path: root/fonts/hershey/parse.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /fonts/hershey/parse.c
Initial commit
Diffstat (limited to 'fonts/hershey/parse.c')
-rw-r--r--fonts/hershey/parse.c176
1 files changed, 176 insertions, 0 deletions
diff --git a/fonts/hershey/parse.c b/fonts/hershey/parse.c
new file mode 100644
index 0000000000..2dd5430192
--- /dev/null
+++ b/fonts/hershey/parse.c
@@ -0,0 +1,176 @@
+#include <stdio.h>
+#include <ctype.h>
+#include "parse.h"
+
+static char copyright[] = "Copyright (C) Ken Yap 1988";
+
+static char zerostring[] = "0";
+static char onestring[] = "1";
+charinfo global = {
+ -1, -1,
+ onestring, onestring,
+ };
+charinfo perchar;
+
+static char *skipblanks(p)
+ char *p;
+{
+ while (isspace(*p) || *p == ',') /* , is also space */
+ ++p;
+ return (p);
+}
+
+static char *skipnonblanks(p)
+ char *p;
+{
+ while (*p != '\0' && !(isspace(*p) || *p == ','))
+ ++p;
+ return (p);
+}
+
+static char *skippast(p, c)
+ char *p, c;
+{
+ while (*p != '\0' && *p != c)
+ ++p;
+ return (*p == c ? p + 1 : p);
+}
+
+static int match(p, word)
+ char *p, *word;
+{
+ register int l;
+
+ l = strlen(word);
+ return (strncmp(p, word, l) == 0);
+}
+
+static int getparams(p, ci)
+ char *p;
+ charinfo *ci;
+{
+ if (*p == '\'') /* collect ascii index */
+ {
+ if (*++p != '\\')
+ ci->asciiindex = (int)*p;
+ else if (*++p == '\\')
+ ci->asciiindex = (int)*p;
+ else if (sscanf(p, "%o", &ci->asciiindex) != 1)
+ {
+ (void)fprintf(stderr, "Bad char index spec %s", p);
+ return (0);
+ }
+ p = skippast(p+1, ',');
+ p = skipblanks(p);
+ if (!isdigit(*p))
+ {
+ (void)fprintf(stderr, "Missing Hershey index %s", p);
+ return (0);
+ }
+ ci->hersheyindex = atoi(p);
+ p = skippast(p, ',');
+ }
+ else if (isdigit(*p))
+ {
+ if (*p == '0')
+ {
+ if (sscanf(p, "%o", &ci->asciiindex) != 1)
+ {
+ (void)fprintf(stderr, "Bad char index spec %s", p);
+ return (0);
+ }
+ }
+ else
+ {
+ if (sscanf(p, "%d", &ci->asciiindex) != 1)
+ {
+ (void)fprintf(stderr, "Bad char index spec %s", p);
+ return (0);
+ }
+ }
+ p = skippast(p+1, ',');
+ p = skipblanks(p);
+ if (!isdigit(*p))
+ {
+ (void)fprintf(stderr, "Missing Hershey index %s", p);
+ return (0);
+ }
+ ci->hersheyindex = atoi(p);
+ p = skippast(p, ',');
+ }
+ p = skipblanks(p);
+ while (*p != '\0')
+ {
+ if (match(p, "hoff"))
+ {
+ p = skippast(p, '=');
+ p = skipblanks(p);
+ ci->hoff = p;
+ }
+ if (match(p, "voff"))
+ {
+ p = skippast(p, '=');
+ p = skipblanks(p);
+ ci->voff = p;
+ }
+ if (match(p, "hratio"))
+ {
+ p = skippast(p, '=');
+ p = skipblanks(p);
+ ci->hratio = p;
+ }
+ if (match(p, "vratio"))
+ {
+ p = skippast(p, '=');
+ p = skipblanks(p);
+ ci->vratio = p;
+ }
+ p = skipnonblanks(p);
+ if (*p != '\0')
+ {
+ *p = '\0';
+ p = skipblanks(p+1);
+ }
+ }
+ return (1);
+}
+
+int parsespecs(line)
+ char *line;
+{
+ register int l;
+ register char *p;
+ char *malloc();
+
+ line = skipblanks(line);
+ if (*line == '\'')
+ {
+ perchar = global; /* copy globals */
+ return (getparams(line, &perchar));
+ }
+ else
+ {
+ l = strlen(line) + 1;
+ if ((p = malloc(l)) == NULL)
+ {
+ perror("malloc");
+ exit(1);
+ }
+ (void)strcpy(p, line);
+ if (!getparams(p, &global))
+ (void)fprintf(stderr, "Bad global spec %s", line);
+ return (0);
+ }
+ /*NOTREACHED*/
+}
+
+#ifdef STANDALONE
+main()
+{
+ char line[256];
+
+ while (fgets(line, sizeof(line), stdin) != NULL)
+ parsespecs(line);
+ exit(0);
+}
+#endif STANDALONE