1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/* This stuff is taken from the p.map/cmd files text.h, scan_ref.c and case.c
**
** Paul W. Carlson March 1992
*/
#include <stdio.h>
#include <string.h>
#include "local_proto.h"
#define LEFT 0
#define RIGHT 1
#define LOWER 0
#define UPPER 1
#define CENTER 2
static int xok, yok;
static int ymatch (char *,int *);
static int xmatch (char *,int *);
int scan_ref (char *buf,int *xref,int *yref)
{
char word1[50], word2[50];
xok = yok = 0;
*xref = *yref = CENTER;
switch (sscanf (buf, "%s%s", word1, word2))
{
case 2:
lowercase (word2);
if (!(xmatch (word2, xref) || ymatch (word2, yref)))
return 0;
case 1:
lowercase (word1);
if (xmatch (word1, xref) || ymatch (word1, yref))
return 1;
default:
return 0;
}
}
static int xmatch ( char *word, int *xref)
{
if (strcmp (word, "center") == 0)
return 1;
if (strcmp (word, "middle") == 0)
return 1;
if (xok) return 0;
if (strcmp (word, "left") == 0)
*xref = LEFT;
else if (strcmp (word, "right") == 0)
*xref = RIGHT;
else
return 0;
xok = 1;
return 1;
}
static int ymatch (char *word,int *yref)
{
if (strcmp (word, "center") == 0)
return 1;
if (strcmp (word, "middle") == 0)
return 1;
if (yok) return 0;
if (strcmp (word, "upper") == 0)
*yref = UPPER;
else if (strcmp (word, "top") == 0)
*yref = UPPER;
else if (strcmp (word, "lower") == 0)
*yref = LOWER;
else if (strcmp (word, "bottom") == 0)
*yref = LOWER;
else
return 0;
yok = 1;
return 1;
}
int lowercase (register char *s)
{
for ( ; *s; s++)
if (*s >= 'A' && *s <= 'Z')
*s += 'a' - 'A';
return 0;
}
|