*** empty log message ***
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "errhdl.h"
|
#include "errhdl.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
#include "coc.h"
|
#include "coc.h"
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* CreateSocketAddress stolen from Tcl. Thanks to John Ousterhout */
|
/* CreateSocketAddress stolen from Tcl. Thanks to John Ousterhout */
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "errhdl.h"
|
#include "errhdl.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
#include "dlog.h"
|
#include "dlog.h"
|
||||||
|
|
||||||
#define VERSION 1.1
|
#define VERSION 1.1
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logfile.h"
|
#include "logfile.h"
|
||||||
#include "errhdl.h"
|
#include "errhdl.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
|
|
||||||
static FILE *fil=NULL;
|
static FILE *fil=NULL;
|
||||||
static char lnam[256]="", filnam[256]="";
|
static char lnam[256]="", filnam[256]="";
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "logfile.h"
|
#include "logfile.h"
|
||||||
#include "coc.h"
|
#include "coc.h"
|
||||||
#include "lsc.h"
|
#include "lsc.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
|
|
||||||
#define MC LSC_MAX_CMDS
|
#define MC LSC_MAX_CMDS
|
||||||
#define MAX_PAR 16
|
#define MAX_PAR 16
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "errhdl.h"
|
#include "errhdl.h"
|
||||||
#include "serutil.h"
|
#include "serutil.h"
|
||||||
#include "logfile.h"
|
#include "logfile.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
|
|
||||||
#define A_CHK(R) if (1!=(R)) { SerA_error(); ErrTxt(#R,0); goto OnError; }
|
#define A_CHK(R) if (1!=(R)) { SerA_error(); ErrTxt(#R,0); goto OnError; }
|
||||||
|
|
||||||
|
223
tecs/str_util.c
Normal file
223
tecs/str_util.c
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include "errhdl.h"
|
||||||
|
#include "str_util.h"
|
||||||
|
|
||||||
|
char *str_splitx(char *str, char sep, char *list[], int *n) {
|
||||||
|
int i;
|
||||||
|
char *s, *e;
|
||||||
|
|
||||||
|
s=str;
|
||||||
|
for (i=0; i<*n; i++) {
|
||||||
|
list[i]=s;
|
||||||
|
e=strchr(s, sep);
|
||||||
|
if (e==NULL) { *n=i+1; return(NULL); }
|
||||||
|
s=e+1;
|
||||||
|
e--;
|
||||||
|
while (e>str && *e==' ') e--; /* trim sequence */
|
||||||
|
e[1]='\0';
|
||||||
|
}
|
||||||
|
return(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *str_split1(char *str, char sep) {
|
||||||
|
char *s, *e;
|
||||||
|
|
||||||
|
e=strchr(str, sep);
|
||||||
|
if (e==NULL) {
|
||||||
|
s=NULL;
|
||||||
|
e=str+strlen(str);
|
||||||
|
} else {
|
||||||
|
s=e+1;
|
||||||
|
}
|
||||||
|
e--;
|
||||||
|
while (e>str && *e==' ') e--; /* trim sequence */
|
||||||
|
e[1]='\0';
|
||||||
|
return(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_ntrim(char *dest, const char *src, int ldest, int lsrc) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (lsrc>=ldest) lsrc=ldest-1;
|
||||||
|
if (dest!=src) strncpy(dest, src, lsrc);
|
||||||
|
dest[lsrc]='\0';
|
||||||
|
i=strlen(dest)-1;
|
||||||
|
while (i>0 && dest[i]==' ') i--; /* trim sequence */
|
||||||
|
i++;
|
||||||
|
dest[i]='\0';
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *str_nsplit(char *dst, const char *src, char sep, int dstlen) {
|
||||||
|
char *s;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
s=strchr(src, sep);
|
||||||
|
if (s==NULL) {
|
||||||
|
s=NULL;
|
||||||
|
i=strlen(src);
|
||||||
|
} else {
|
||||||
|
i=s-src;
|
||||||
|
s++; /* skip separator */
|
||||||
|
}
|
||||||
|
if (i>=dstlen) {
|
||||||
|
str_copy(dst, src);
|
||||||
|
} else {
|
||||||
|
strncpy(dst, src, i);
|
||||||
|
dst[i]='\0';
|
||||||
|
}
|
||||||
|
return(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *str_read_until(FILE *fil, char *term, char *buf, char *end) {
|
||||||
|
char *s;
|
||||||
|
char fmt[24];
|
||||||
|
int i, l, siz;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
siz=end-buf-1;
|
||||||
|
if (siz<1) return(NULL);
|
||||||
|
sprintf(fmt, "%s%d[^%s%s", "%", siz, term, "]%n%c");
|
||||||
|
i=fscanf(fil, fmt, buf, &l, &ch);
|
||||||
|
if (i<0) { /* eof */
|
||||||
|
buf[0]='\0';
|
||||||
|
return(&buf[0]);
|
||||||
|
} else if (i==0) { /* fscanf returns 0 if first char is terminator */
|
||||||
|
buf[0]=fgetc(fil);
|
||||||
|
return(&buf[0]);
|
||||||
|
} else if (i==1) { /* terminator not found -> read until eof */
|
||||||
|
buf[l]='\0';
|
||||||
|
return(&buf[l]);
|
||||||
|
} else {
|
||||||
|
buf[l]=ch;
|
||||||
|
if (l==siz && NULL==strchr(term, ch)) return(NULL);
|
||||||
|
return(&buf[l]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *str_read_file(char *file) {
|
||||||
|
FILE *fil;
|
||||||
|
char *str, *s, *e, *p, *q;
|
||||||
|
char ch;
|
||||||
|
int i, l, size;
|
||||||
|
struct stat statbuf;
|
||||||
|
|
||||||
|
i=stat(file, &statbuf);
|
||||||
|
if (i<0) ERR_MSG("file not found");
|
||||||
|
size=statbuf.st_size+4;
|
||||||
|
ERR_SP(str=malloc(size));
|
||||||
|
e=&str[size-1];
|
||||||
|
ERR_SP(fil=fopen(file, "r"));
|
||||||
|
s=str;
|
||||||
|
while (1) {
|
||||||
|
p=str_read_until(fil, "!", s, e);
|
||||||
|
if (p==NULL) break;
|
||||||
|
if (*p=='!') {
|
||||||
|
q=str_read_until(fil, "\n", p, e);
|
||||||
|
if (q==NULL) { p=NULL; break; }
|
||||||
|
s=p; *s='\n'; s++;
|
||||||
|
} else {
|
||||||
|
assert(*p=='\0');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ERR_SI(fclose(fil));
|
||||||
|
assert(strlen(str)<size);
|
||||||
|
return(str);
|
||||||
|
OnError: return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_replace_char(char *str, char ch, char rep) {
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
assert(ch!='\0' && ch!=rep);
|
||||||
|
s=strchr(str, ch);
|
||||||
|
while (s!=NULL) {
|
||||||
|
*s=rep;
|
||||||
|
s=strchr(s, ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_nsubstitute(char *result, char *str, char *old, char *new, int reslen) {
|
||||||
|
char *s, *p, *r;
|
||||||
|
int l, ln, lo;
|
||||||
|
|
||||||
|
p=str;
|
||||||
|
r=result;
|
||||||
|
ln=strlen(new);
|
||||||
|
lo=strlen(old);
|
||||||
|
s=strstr(p, old);
|
||||||
|
reslen--;
|
||||||
|
if (reslen<0) ERR_MSG("result buffer too short");
|
||||||
|
while (s!=NULL) {
|
||||||
|
l=s-p;
|
||||||
|
if (l>reslen) ERR_MSG("result buffer too short");
|
||||||
|
strncpy(r, p, l);
|
||||||
|
r+=l; reslen-=l;
|
||||||
|
if (ln>reslen) ERR_MSG("result buffer too short");
|
||||||
|
strncpy(r, new, reslen);
|
||||||
|
r+=ln; reslen-=ln;
|
||||||
|
p=s+lo;
|
||||||
|
s=strstr(p, old);
|
||||||
|
}
|
||||||
|
l=strlen(p);
|
||||||
|
if (l>reslen) ERR_MSG("result buffer too short");
|
||||||
|
strncpy(r, p, l);
|
||||||
|
r+=l;
|
||||||
|
*r='\0';
|
||||||
|
return(r-result);
|
||||||
|
OnError:
|
||||||
|
result[0]='\0';
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_nupcase(char *dst, const char *src, int dstlen) {
|
||||||
|
dstlen--; /* space for trailing nul */
|
||||||
|
while (*src!='\0' && dstlen>0) {
|
||||||
|
*dst=toupper(*src);
|
||||||
|
dst++; src++;
|
||||||
|
}
|
||||||
|
*dst='\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int strcasecmp(const char *str1, const char *str2) {
|
||||||
|
int i;
|
||||||
|
char ch1, ch2;
|
||||||
|
ch1=tolower(*(str1++)); ch2=tolower(*(str2++));
|
||||||
|
i=1;
|
||||||
|
while (ch1!='\0' && ch2!='\0' && ch1==ch2) {
|
||||||
|
ch1=tolower(*(str1++)); ch2=tolower(*(str2++)); i++;
|
||||||
|
}
|
||||||
|
if (ch1<ch2) {
|
||||||
|
return(-i);
|
||||||
|
} else if (ch1>ch2) {
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_ncpy(char *dst, const char *src, int maxdest) {
|
||||||
|
strncpy(dst, src, maxdest);
|
||||||
|
if (dst[maxdest-1]!='\0') {
|
||||||
|
dst[maxdest-1]='\0';
|
||||||
|
ERR_MSG("destination string too short");
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
OnError: return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_ncat(char *dst, const char *src, int maxdest) {
|
||||||
|
strncat(dst, src, maxdest-strlen(dst)-1);
|
||||||
|
if (dst[maxdest-1]!='\0') {
|
||||||
|
dst[maxdest-1]='\0';
|
||||||
|
ERR_MSG("destination string too short");
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
OnError: return(-1);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "errhdl.h"
|
#include "errhdl.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
#include "tecc.h"
|
#include "tecc.h"
|
||||||
|
|
||||||
static char device[80], command[80];
|
static char device[80], command[80];
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "errhdl.h"
|
#include "errhdl.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "logfile.h"
|
#include "logfile.h"
|
||||||
#include "util.h"
|
#include "str_util.h"
|
||||||
#include "lsc.h"
|
#include "lsc.h"
|
||||||
#include "dlog.h"
|
#include "dlog.h"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user