home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / pldeco.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  3.0 KB  |  102 lines

  1. /* Decode a character string, and return an array of float integer symbol */
  2. /* numbers. This routine is responsible for interpreting all escape */
  3. /* sequences. At present the following escape sequences are defined */
  4. /* (the letter following the # may be either upper or lower case): */
  5.  
  6. /* #u       :      up one level (returns -1) */
  7. /* #d       :      down one level (returns -2) */
  8. /* #b       :      backspace (returns -3) */
  9. /* #+       :      toggles overline mode (returns -4) */
  10. /* #-       :      toggles underline mode (returns -5) */
  11. /* ##       :      # */
  12. /* #gx      :      greek letter corresponding to roman letter x */
  13. /* #fn      :      switch to Normal font */
  14. /* #fr      :      switch to Roman font */
  15. /* #fi      :      switch to Italic font */
  16. /* #fs      :      switch to Script font */
  17. /* #(nnn)   :      Hershey symbol number nnn (any number of digits) */
  18.  
  19. #include "plplot.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #ifdef PLSTDC
  23. #include <string.h>
  24. #else
  25. extern int strlen();
  26. #endif
  27.  
  28. static char font[] = "nris";
  29. static char greek[] = "ABGDEZYHIKLMNCOPRSTUFXQWabgdezyhiklmncoprstufxqw";
  30. #define PLMAXSTR      300
  31. static short symbol[PLMAXSTR];
  32.  
  33. extern short int *fntlkup;
  34. extern short int numberfonts, numberchars;
  35.  
  36. void pldeco(sym,length,text)
  37. PLINT *length;
  38. short int **sym;
  39. char *text;
  40. {
  41.    PLINT ch,icol,ifont,ig,j,lentxt;
  42.    char test;
  43.  
  44.    /* Initialize parameters. */
  45.    lentxt=strlen(text);
  46.    *length=0;
  47.    *sym = symbol;
  48.    gatt(&ifont,&icol);
  49.    if(ifont > numberfonts)
  50.       ifont = 1;
  51.  
  52.    /* Get next character; treat non-printing characters as spaces. */
  53.    j=0;
  54.    while(j<lentxt) {
  55.      if(*length >= PLMAXSTR)
  56.         return;
  57.      test=text[j++];
  58.      ch=test;
  59.      if (ch<0 || ch>175)   ch = 32;
  60.  
  61.      /* Test for escape sequence (#) */
  62.      if (ch=='#' && (lentxt-j)>=1) {
  63.        test=text[j++];
  64.        if (test=='#')
  65.          symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars+ch);
  66.        else if (tolower(test)=='u')
  67.          symbol[(*length)++] = -1;
  68.        else if (tolower(test)=='d')
  69.          symbol[(*length)++] = -2;
  70.        else if (tolower(test)=='b')
  71.          symbol[(*length)++] = -3;
  72.        else if (test=='+')
  73.          symbol[(*length)++] = -4;
  74.        else if (test=='-')
  75.          symbol[(*length)++] = -5;
  76.        else if (test=='(') {
  77.          symbol[*length] = 0;
  78.          while ('0'<=text[j] && text[j]<='9') {
  79.            symbol[*length] = symbol[*length]*10 + text[j] - '0';
  80.            j++;
  81.          }
  82.          (*length)++;
  83.          if (text[j]==')') j++;
  84.        }
  85.        else if (tolower(test)=='f') {
  86.          test=text[j++];
  87.          ifont = strpos(font,(char)tolower(test)) + 1;
  88.          if (ifont==0 || ifont > numberfonts)
  89.             ifont = 1;
  90.        }
  91.        else if (tolower(test)=='g') {
  92.          test=text[j++];
  93.          ig = strpos(greek,test) + 1;
  94.          symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars + 127 + ig);
  95.        }
  96.      }
  97.      else
  98.        /* Decode character. */
  99.        symbol[(*length)++] = *(fntlkup+(ifont-1)*numberchars + ch);
  100.    }
  101. }
  102.