This is pldeco.c in view mode; [Download] [Up]
/* Decode a character string, and return an array of float integer symbol */
/* numbers. This routine is responsible for interpreting all escape */
/* sequences. At present the following escape sequences are defined */
/* (the letter following the # may be either upper or lower case): */
/* #u : up one level (returns -1) */
/* #d : down one level (returns -2) */
/* #b : backspace (returns -3) */
/* #+ : toggles overline mode (returns -4) */
/* #- : toggles underline mode (returns -5) */
/* ## : # */
/* #gx : greek letter corresponding to roman letter x */
/* #fn : switch to Normal font */
/* #fr : switch to Roman font */
/* #fi : switch to Italic font */
/* #fs : switch to Script font */
/* #(nnn) : Hershey symbol number nnn (any number of digits) */
#include "plplot.h"
#include <stdio.h>
#include <ctype.h>
#ifdef PLSTDC
#include <string.h>
#else
extern int strlen();
#endif
static char font[] = "nris";
static char greek[] = "ABGDEZYHIKLMNCOPRSTUFXQWabgdezyhiklmncoprstufxqw";
#define PLMAXSTR 300
static short symbol[PLMAXSTR];
extern short int *fntlkup;
extern short int numberfonts, numberchars;
void pldeco(sym,length,text)
int *length;
short int **sym;
char *text;
{
int ch,icol,ifont,ig,j,lentxt;
char test;
/* Initialize parameters. */
lentxt=strlen(text);
*length=0;
*sym = symbol;
gatt(&ifont,&icol);
if(ifont > numberfonts)
ifont = 1;
/* Get next character; treat non-printing characters as spaces. */
j=0;
while(j<lentxt) {
if(*length >= PLMAXSTR)
return;
test=text[j++];
ch=test;
if (ch<0 || ch>175) ch = 32;
/* Test for escape sequence (#) */
if (ch=='#' && (lentxt-j)>=1) {
test=text[j++];
if (test=='#')
symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars+ch);
else if (test=='u' || test=='U')
symbol[(*length)++] = -1;
else if (test=='d' || test=='D')
symbol[(*length)++] = -2;
else if (test=='b' || test=='B')
symbol[(*length)++] = -3;
else if (test=='+')
symbol[(*length)++] = -4;
else if (test=='-')
symbol[(*length)++] = -5;
else if (test=='(') {
symbol[*length] = 0;
while ('0'<=text[j] && text[j]<='9') {
symbol[*length] = symbol[*length]*10 + text[j] - '0';
j++;
}
(*length)++;
if (text[j]==')') j++;
} else if (test=='f' || test=='F') {
test=text[j++];
ifont = strpos(font,isupper(test)?tolower(test):test) + 1;
if (ifont==0 || ifont > numberfonts)
ifont = 1;
} else if (test=='g' || test=='G') {
test=text[j++];
ig = strpos(greek,test) + 1;
symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars + 127+ig);
} else {
;
}
}
else
/* Decode character. */
symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars + ch);
}
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.