home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / STPXLATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.7 KB  |  63 lines

  1. /**
  2. *
  3. * Name        stpxlate -- Translate a string
  4. *
  5. * Synopsis    presult = stpxlate(psource,ptable,ptrans);
  6. *
  7. *        char *presult      Pointer to translated string
  8. *        char *psource      Pointer to source string
  9. *        char *ptable      Pointer to string table of characters
  10. *                  to be translated
  11. *        char *ptrans      Pointer to translation string
  12. *
  13. * Description    This function translates the string psource according to
  14. *        the instructions specified by ptable and ptrans.  If
  15. *        psource is the null string (""), the null string is
  16. *        returned; otherwise for each character psource[k] of
  17. *        psource, the corresponding character of presult,
  18. *        presult[k] is defined as follows:
  19. *
  20. *             = psource[k] if psource[k] is not in ptable
  21. *             = BLANK if the position of psource[k] in ptable is
  22. *               greater than the length of ptrans
  23. *             = trans[j] otherwise, where j is the position of
  24. *               psource[k] in ptable.
  25. *
  26. * Returns    presult       Pointer to the translated string
  27. *        psource       The same as presult; psource translated.
  28. *
  29. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  30. *
  31. **/
  32.  
  33. #include <string.h>
  34.  
  35. #include <bstring.h>
  36.  
  37. #define BLANK    ' '
  38.  
  39. char *stpxlate(psource,ptable,ptrans)
  40. register char *psource;
  41. char          *ptable,*ptrans;
  42. {
  43.     register int  tindex,i;
  44.     int       len_trans;
  45.     char      ch,*ptemp;
  46.  
  47.     len_trans = (int) strlen(ptrans);      /* Length of ptrans           */
  48.     ptemp     = psource;
  49.  
  50.     for (i = 0; (ch = *psource); i++)
  51.     {
  52.     tindex = stschind(ch,ptable);
  53.     if (tindex >= 0)          /* psource[i] is in ptable   */
  54.        if ((tindex + 1) > len_trans)  /* Indices start from zero   */
  55.           *psource = BLANK;
  56.        else
  57.           *psource = ptrans[tindex];
  58.     psource++;
  59.     }
  60.  
  61.     return(ptemp);
  62. }
  63.