home *** CD-ROM | disk | FTP | other *** search
- /* 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)
- PLINT *length;
- short int **sym;
- char *text;
- {
- PLINT 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 (tolower(test)=='u')
- symbol[(*length)++] = -1;
- else if (tolower(test)=='d')
- symbol[(*length)++] = -2;
- else if (tolower(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 (tolower(test)=='f') {
- test=text[j++];
- ifont = strpos(font,(char)tolower(test)) + 1;
- if (ifont==0 || ifont > numberfonts)
- ifont = 1;
- }
- else if (tolower(test)=='g') {
- test=text[j++];
- ig = strpos(greek,test) + 1;
- symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars + 127 + ig);
- }
- }
- else
- /* Decode character. */
- symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars + ch);
- }
- }
-