home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: The Abacus * HST/DS * Potterville, MI
- Date: 04-23-93 (22:53) Number: 80
- From: JERRY COFFIN Refer#: NONE
- To: ALL Recvd: NO
- Subj: translat.c Conf: (36) C Language
- ---------------------------------------------------------------------------
- /* Public Domain by Jerry Coffin. Tested with MSC 7.0. Should
- * be quite portable.
- *
- * Interpets a string in a manner similar to that the compiler
- * does string literals in a program. All escape sequences are
- * longer than their translated equivalant, so the string is
- * translated in place and either remains the same length or
- * becomes shorter.
- */
-
- #include <string.h>
- #include <stdio.h>
-
- char *translate(char *string ) {
-
- char *here=string;
- size_t len=strlen(string);
- int num;
- int numlen;
-
- while (NULL!=(here=strchr(here,'\\'))) {
- numlen=1;
- switch(here[1]) {
- case '\\':
- break;
- case 'r':
- *here = '\r';
- break;
- case 'n':
- *here = '\n';
- break;
- case 't':
- *here = '\t';
- break;
- case 'v':
- *here = '\v';
- break;
- case 'a':
- *here = '\a';
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- numlen = sscanf(here,"%o",&num);
- *here = (char)num;
- break;
- case 'x':
- numlen = sscanf(here,"%x",&num);
- *here = (char) num;
- break;
- }
- num = here - string + numlen;
- here++;
- memmove(here,here+numlen,len-num );
- }
- return string;
- }
- Later,
- Jerry.
-
- --- PPoint 1.38
- * Origin: Point Pointedly Pointless (1:128/77.3)
- SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
- SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 280/1
- SEEN-BY: 390/1 396/1 5 15 2270/1 2440/5 3603/20
-