File: sprt.c

package info (click to toggle)
robotour 3.1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,596 kB
  • ctags: 2,972
  • sloc: cpp: 17,705; sh: 3,060; ansic: 2,778; makefile: 144
file content (47 lines) | stat: -rwxr-xr-x 1,009 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* sprt.c: */
#include <stdio.h>
#include "xtdio.h"

/* -------------------------------------------------------------------------
 * Local Definitions:
 */
#define BUFSIZE 261
#define SFTY      5

/* sprt: this routine makes string characters all visible */
#ifdef __PROTOTYPE__
char *sprt(const char *s)
#else	/* __PROTOTYPE__ */
char *sprt(s)
char *s;
#endif	/* __PROTOTYPE__ */
{
static char buf1[BUFSIZE];
static char buf2[BUFSIZE];
static char buf3[BUFSIZE];
static char buf4[BUFSIZE];
char *b,*bend;
static char *buf=buf3;
int ic;

/* allows up to three sprt()s in one function call */
if(buf == buf1)      buf= buf2;
else if(buf == buf2) buf= buf3;
else if(buf == buf3) buf= buf4;
else                 buf= buf1;

buf[0]= '\0';
bend  = buf + BUFSIZE - SFTY;
if(s) for(b= buf; *s && b < bend; ++s, b+= strlen(b)) {
	ic= (int) *s;
	if(ic < 31)        sprintf(b,"^%c",(char) (ic + 64));
	else if(ic >= 128) sprintf(b,"~%3d",ic);
	else {
		*b    = *s;
		*(b+1)= '\0';
		}
	b+= strlen(b);
	}
return buf;
}