home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / STPXLATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.9 KB  |  71 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. *        const char *ptable   Pointer to string table of
  10. *                     characters to be translated.
  11. *        const 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. *
  22. *             = BLANK if the position of psource[k] in ptable
  23. *               is greater than the length of ptrans.
  24. *
  25. *             = trans[j] otherwise, where j is the position of
  26. *               psource[k] in ptable.
  27. *
  28. * Returns    presult     Pointer to the translated string.
  29. *        psource     The same as presult; psource
  30. *                translated.
  31. *
  32. * Version    6.00 (C)Copyright Blaise Computing Inc.  1983,1987,1989
  33. *
  34. **/
  35.  
  36.  
  37. #include <stdio.h>    /* For definition of NULL.            */
  38. #include <string.h>
  39.  
  40. #include <bstrings.h>
  41.  
  42. #define BLANK    ' '
  43. #define NUL    '\0'
  44.  
  45.  
  46. char *stpxlate(psource,ptable,ptrans)
  47. register char *psource;
  48. const char    *ptable;
  49. const char    *ptrans;
  50. {
  51.     register int tindex, i;
  52.     int      len_trans;
  53.     char     ch, *ptemp;
  54.  
  55.     len_trans = (int) strlen (ptrans);    /* Length of ptrans.        */
  56.     ptemp     = psource;
  57.  
  58.     for (i = 0;  ((ch = *psource) != NUL);  i++)
  59.     {
  60.     tindex = stschind (ch, ptable);
  61.     if (tindex >= 0)        /* psource[i] is in ptable. */
  62.        if ((tindex + 1) > len_trans)/* Indices start from zero. */
  63.           *psource = BLANK;
  64.        else
  65.           *psource = ptrans[tindex];
  66.     psource++;
  67.     }
  68.  
  69.     return (ptemp);
  70. }
  71.