Extra useful routines. First is dbTranslateEscape
This commit is contained in:
84
src/libCom/epicsString.c
Normal file
84
src/libCom/epicsString.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*epicsString.c*/
|
||||
/*Authors: Noboru Yamamoto and Marty Kraimer*/
|
||||
/*****************************************************************
|
||||
COPYRIGHT NOTIFICATION
|
||||
*****************************************************************
|
||||
|
||||
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
|
||||
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
int dbTranslateEscape(char *to, const char *from)
|
||||
{
|
||||
const char *pfrom = from;
|
||||
char *pto = to;
|
||||
char c;
|
||||
int nto=0;
|
||||
|
||||
while( c = *pfrom++ ){
|
||||
if(c=='\\') {
|
||||
switch( *pfrom ){
|
||||
case 'a': pfrom++; *pto++ = '\a' ; nto++; break;
|
||||
case 'b': pfrom++; *pto++ = '\b' ; nto++; break;
|
||||
case 'f': pfrom++; *pto++ = '\f' ; nto++; break;
|
||||
case 'n': pfrom++; *pto++ = '\n' ; nto++; break;
|
||||
case 'r': pfrom++; *pto++ = '\r' ; nto++; break;
|
||||
case 't': pfrom++; *pto++ = '\t' ; nto++; break;
|
||||
case 'v': pfrom++; *pto++ = '\v' ; nto++; break;
|
||||
case '\\': pfrom++; *pto++ = '\\' ; nto++; break;
|
||||
case '\?': pfrom++; *pto++ = '\?' ; nto++; break;
|
||||
case '\'': pfrom++; *pto++ = '\'' ; nto++; break;
|
||||
case '\"': pfrom++; *pto++ = '\"' ; nto++; break;
|
||||
case '0' :case '1' :case '2' :case '3' :
|
||||
case '4' :case '5' :case '6' :case '7' :
|
||||
{
|
||||
int i;
|
||||
char strval[4] = {0,0,0,0};
|
||||
int ival;
|
||||
unsigned char *pchar;
|
||||
|
||||
for(i=0; i<3; i++) {
|
||||
if((*pfrom < '0') || (*pfrom > '7')) break;
|
||||
strval[i] = *pfrom++;
|
||||
}
|
||||
sscanf(strval,"%o",&ival);
|
||||
pchar = (unsigned char *)(pto++); nto++;
|
||||
*pchar = (unsigned char)(ival);
|
||||
}
|
||||
break;
|
||||
case 'x' :
|
||||
{
|
||||
int i;
|
||||
char strval[3] = {0,0,0};
|
||||
int ival;
|
||||
unsigned char *pchar;
|
||||
|
||||
pfrom++; /*skip the x*/
|
||||
for(i=0; i<2; i++) {
|
||||
if(!isxdigit(*pfrom)) break;
|
||||
strval[i] = *pfrom++;
|
||||
}
|
||||
sscanf(strval,"%x",&ival);
|
||||
pchar = (unsigned char *)(pto++); nto++;
|
||||
*pchar = (unsigned char)(ival);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*pto++ = *pfrom++;
|
||||
}
|
||||
} else {
|
||||
*pto++ = c; nto++;
|
||||
}
|
||||
}
|
||||
*pto = '\0'; /*NOTE that nto does not have to be incremented*/
|
||||
return(nto);
|
||||
}
|
||||
28
src/libCom/epicsString.h
Normal file
28
src/libCom/epicsString.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*epicsString.h*/
|
||||
/*Authors: Noboru Yamamoto and Marty Kraimer*/
|
||||
/*****************************************************************
|
||||
COPYRIGHT NOTIFICATION
|
||||
*****************************************************************
|
||||
|
||||
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
|
||||
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
**********************************************************************/
|
||||
|
||||
/* int dbTranslateEscape(char *s,const char *ct);
|
||||
*
|
||||
* copies ct to s while substituting escape sequences
|
||||
* returns the length of the resultant string (may contain nulls)
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int dbTranslateEscape(char *s,const char *ct);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
84
src/libCom/misc/epicsString.c
Normal file
84
src/libCom/misc/epicsString.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*epicsString.c*/
|
||||
/*Authors: Noboru Yamamoto and Marty Kraimer*/
|
||||
/*****************************************************************
|
||||
COPYRIGHT NOTIFICATION
|
||||
*****************************************************************
|
||||
|
||||
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
|
||||
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
int dbTranslateEscape(char *to, const char *from)
|
||||
{
|
||||
const char *pfrom = from;
|
||||
char *pto = to;
|
||||
char c;
|
||||
int nto=0;
|
||||
|
||||
while( c = *pfrom++ ){
|
||||
if(c=='\\') {
|
||||
switch( *pfrom ){
|
||||
case 'a': pfrom++; *pto++ = '\a' ; nto++; break;
|
||||
case 'b': pfrom++; *pto++ = '\b' ; nto++; break;
|
||||
case 'f': pfrom++; *pto++ = '\f' ; nto++; break;
|
||||
case 'n': pfrom++; *pto++ = '\n' ; nto++; break;
|
||||
case 'r': pfrom++; *pto++ = '\r' ; nto++; break;
|
||||
case 't': pfrom++; *pto++ = '\t' ; nto++; break;
|
||||
case 'v': pfrom++; *pto++ = '\v' ; nto++; break;
|
||||
case '\\': pfrom++; *pto++ = '\\' ; nto++; break;
|
||||
case '\?': pfrom++; *pto++ = '\?' ; nto++; break;
|
||||
case '\'': pfrom++; *pto++ = '\'' ; nto++; break;
|
||||
case '\"': pfrom++; *pto++ = '\"' ; nto++; break;
|
||||
case '0' :case '1' :case '2' :case '3' :
|
||||
case '4' :case '5' :case '6' :case '7' :
|
||||
{
|
||||
int i;
|
||||
char strval[4] = {0,0,0,0};
|
||||
int ival;
|
||||
unsigned char *pchar;
|
||||
|
||||
for(i=0; i<3; i++) {
|
||||
if((*pfrom < '0') || (*pfrom > '7')) break;
|
||||
strval[i] = *pfrom++;
|
||||
}
|
||||
sscanf(strval,"%o",&ival);
|
||||
pchar = (unsigned char *)(pto++); nto++;
|
||||
*pchar = (unsigned char)(ival);
|
||||
}
|
||||
break;
|
||||
case 'x' :
|
||||
{
|
||||
int i;
|
||||
char strval[3] = {0,0,0};
|
||||
int ival;
|
||||
unsigned char *pchar;
|
||||
|
||||
pfrom++; /*skip the x*/
|
||||
for(i=0; i<2; i++) {
|
||||
if(!isxdigit(*pfrom)) break;
|
||||
strval[i] = *pfrom++;
|
||||
}
|
||||
sscanf(strval,"%x",&ival);
|
||||
pchar = (unsigned char *)(pto++); nto++;
|
||||
*pchar = (unsigned char)(ival);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*pto++ = *pfrom++;
|
||||
}
|
||||
} else {
|
||||
*pto++ = c; nto++;
|
||||
}
|
||||
}
|
||||
*pto = '\0'; /*NOTE that nto does not have to be incremented*/
|
||||
return(nto);
|
||||
}
|
||||
28
src/libCom/misc/epicsString.h
Normal file
28
src/libCom/misc/epicsString.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*epicsString.h*/
|
||||
/*Authors: Noboru Yamamoto and Marty Kraimer*/
|
||||
/*****************************************************************
|
||||
COPYRIGHT NOTIFICATION
|
||||
*****************************************************************
|
||||
|
||||
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
|
||||
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
**********************************************************************/
|
||||
|
||||
/* int dbTranslateEscape(char *s,const char *ct);
|
||||
*
|
||||
* copies ct to s while substituting escape sequences
|
||||
* returns the length of the resultant string (may contain nulls)
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int dbTranslateEscape(char *s,const char *ct);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user