*** empty log message ***
This commit is contained in:
@ -4,12 +4,11 @@
|
|||||||
# Markus Zolliker, March 2000
|
# Markus Zolliker, March 2000
|
||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
OBJ= tecc.o client.o coc.o errhdl.o str_util.o str_buf.o \
|
OBJ= tecc.o client.o coc.o errhdl.o str_util.o str_buf.o \
|
||||||
server.o lsc.o serutil.o logfile.o dlog.o \
|
server.o lsc.o serutil.o logfile.o dlog.o
|
||||||
asynsrv_utility.o strjoin.o geterrno.o
|
|
||||||
|
|
||||||
#------------ for DigitalUnix
|
#------------ for DigitalUnix
|
||||||
CC=cc
|
CC=cc
|
||||||
CFLAGS= -std1 -g -c -warnprotos -I.
|
CFLAGS= -std1 -g -c -warnprotos -I. -I../hardsup
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) $*.c
|
$(CC) $(CFLAGS) $*.c
|
||||||
@ -19,7 +18,7 @@ tecs: $(OBJ)
|
|||||||
ar cr libtecsl.a $(OBJ)
|
ar cr libtecsl.a $(OBJ)
|
||||||
ranlib libtecsl.a
|
ranlib libtecsl.a
|
||||||
- rm TecsServer
|
- rm TecsServer
|
||||||
cc -o TecsServer -g tecs.c -lm -L. -ltecsl
|
cc -o TecsServer -g tecs.c -lm -L. -ltecsl -L../hardsup -lhlib
|
||||||
- rm tcli
|
- rm tcli
|
||||||
cc -o tcli -g tcli.c -lm -L. -ltecsl
|
cc -o tcli -g tcli.c -lm -L. -ltecsl
|
||||||
|
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
#ifndef _asynsrv_def_
|
|
||||||
#define _asynsrv_def_
|
|
||||||
/*------------------------------------------------ AsynSrv_DEF.H Ident V01M
|
|
||||||
*/
|
|
||||||
#ifndef OffsetOf
|
|
||||||
#define OffsetOf(type, identifier) ((size_t)(&((type*) NULL)->identifier))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _asynsrv_errcodes_
|
|
||||||
#define _asynsrv_errcodes_
|
|
||||||
#include <asynsrv_errcodes.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define AsynSrv_MAX_LINK 8
|
|
||||||
/*
|
|
||||||
** Structures needed by AsynSrv_Utility.
|
|
||||||
*/
|
|
||||||
struct AsynSrv__info {
|
|
||||||
int skt; /* The socket number of the connection */
|
|
||||||
char host[20]; /* The name of RS-232-C server */
|
|
||||||
int port; /* The TCP/IP port number of server */
|
|
||||||
int chan; /* The RS-232-C channel number on server */
|
|
||||||
int msg_id;
|
|
||||||
int protocol_code; /* Flag to identify the server's protocol level */
|
|
||||||
char protocol_id[4]; /* ASCII version of server's protocol level */
|
|
||||||
int cmnd_hdr_len; /* Header length for command strings */
|
|
||||||
char cmnd_fmt[8]; /* "sprintf" format for cmnd header conversion */
|
|
||||||
int rply_hdr_len; /* Header length for response strings */
|
|
||||||
char rply_fmt[8]; /* "sscanf" format for rply header conversion */
|
|
||||||
char chan_char[4]; /* ASCII encoded version of chan */
|
|
||||||
char tmo[4]; /* ASCII encoded time-out (deci-secs) */
|
|
||||||
char eot[4]; /* Expected terminators */
|
|
||||||
int max_replies; /* Binary version of #replies in response */
|
|
||||||
int n_replies; /* # of last response returned to caller */
|
|
||||||
void (*idleHandler)(int,int); /* MZ. handler called when waiting on a response */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AsynSrv_HostPortSkt {
|
|
||||||
char host[30];
|
|
||||||
int port;
|
|
||||||
int skt;
|
|
||||||
int protocol_code;
|
|
||||||
char protocol_id[4];
|
|
||||||
int cmnd_hdr_len;
|
|
||||||
int rply_hdr_len;
|
|
||||||
int usage_cnt;
|
|
||||||
int status;
|
|
||||||
};
|
|
||||||
/*------------------------------------------------ End of AsynSrv_DEF.H --*/
|
|
||||||
#endif /* _asynsrv_def_ */
|
|
File diff suppressed because it is too large
Load Diff
@ -1,97 +0,0 @@
|
|||||||
#define ident "1B01"
|
|
||||||
#ifdef VAXC
|
|
||||||
#module GetErrno ident
|
|
||||||
#endif
|
|
||||||
#ifdef __DECC
|
|
||||||
#pragma module GetErrno ident
|
|
||||||
#pragma nostandard
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
** +--------------------------------------------------------------+
|
|
||||||
** | Paul Scherrer Institute |
|
|
||||||
** | Computing Section |
|
|
||||||
** | |
|
|
||||||
** | This software may be used freely by non-profit organizations.|
|
|
||||||
** | It may be copied provided that the name of P.S.I. and of the |
|
|
||||||
** | author is included. Neither P.S.I. nor the author assume any |
|
|
||||||
** | responsibility for the use of this software outside of P.S.I.|
|
|
||||||
** +--------------------------------------------------------------+
|
|
||||||
**
|
|
||||||
** Module Name . . . . . . . . : [...LIB.SINQ]GETERRNO.C
|
|
||||||
**
|
|
||||||
** Author . . . . . . . . . . : D. Maden
|
|
||||||
** Date of creation . . . . . . : Nov 1995
|
|
||||||
**
|
|
||||||
** To compile this module, use:
|
|
||||||
|
|
||||||
$ import tasmad
|
|
||||||
$ define/group sinq_c_tlb mad_lib:sinq_c.tlb
|
|
||||||
$ cc /debug /noopt /obj=[]GetErrno -
|
|
||||||
tasmad_disk:[mad.lib.sinq]GetErrno +
|
|
||||||
sinq_c_tlb/lib
|
|
||||||
|
|
||||||
** To include this module in SINQ.OLB, use:
|
|
||||||
|
|
||||||
$ import tasmad
|
|
||||||
$ define/group sinq_c_tlb mad_lib:sinq_c.tlb
|
|
||||||
$
|
|
||||||
$ define/group sinq_olb mad_lib:sinq_dbg.olb
|
|
||||||
$ @tasmad_disk:[mad.lib.sinq]sinq_olb GetErrno debug
|
|
||||||
$
|
|
||||||
$ define/group sinq_olb mad_lib:sinq.olb
|
|
||||||
$ @tasmad_disk:[mad.lib.sinq]sinq_olb GetErrno
|
|
||||||
**
|
|
||||||
** Updates:
|
|
||||||
** 1A01 2-Nov-1995 DM. Initial version.
|
|
||||||
** 1B01 21-Mar-1996 DM. Move from DELTAT.OLB to SINQ.OLB.
|
|
||||||
**============================================================================
|
|
||||||
** The following entry points are included:
|
|
||||||
**
|
|
||||||
#include <sinq_prototypes.h>
|
|
||||||
|
|
||||||
void GetErrno (int *his_errno, int *his_vaxc_errno)
|
|
||||||
** --------
|
|
||||||
** Input Args:
|
|
||||||
** none
|
|
||||||
** Output Args:
|
|
||||||
** his_errno - value of "errno".
|
|
||||||
** his_vaxc_errno - on VMS systems only, value of "vaxc$errno". Otherwise
|
|
||||||
** set to 1.
|
|
||||||
** Modified Args:
|
|
||||||
** none
|
|
||||||
** Return status:
|
|
||||||
** none
|
|
||||||
** Global variables modified:
|
|
||||||
** none
|
|
||||||
** Description:
|
|
||||||
** GetErrno returns a copy of the universal error variable "errno" (and,
|
|
||||||
** on VMS systems, vaxc$errno) to a local variable supplied by the user.
|
|
||||||
** This can occasionally be useful when debugging since the debugger on
|
|
||||||
** VMS can't easily examine them.
|
|
||||||
**============================================================================
|
|
||||||
** Global Definitions
|
|
||||||
*/
|
|
||||||
#ifdef VAXC
|
|
||||||
#include errno
|
|
||||||
#else
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
/*--------------------------------------------------------------------------
|
|
||||||
** Global Variables
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
|
||||||
** GetErrno: Make copies of errno and vaxc$errno for debug.
|
|
||||||
*/
|
|
||||||
void GetErrno (int *his_errno, int *his_vaxc_errno) {
|
|
||||||
/* ========
|
|
||||||
*/
|
|
||||||
*his_errno = errno; /* Make copy of errno */
|
|
||||||
#ifdef __VMS
|
|
||||||
*his_vaxc_errno = vaxc$errno; /* Make copy of vaxc$errno */
|
|
||||||
#else
|
|
||||||
*his_vaxc_errno = 1;
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*------------------------------------------------- End of GETERRNO.C =======*/
|
|
@ -1,43 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------*/
|
|
||||||
int AsynSrv_Close (
|
|
||||||
struct AsynSrv__info *asyn_info,
|
|
||||||
int force_flag);
|
|
||||||
int AsynSrv_Config (
|
|
||||||
struct AsynSrv__info *asyn_info,
|
|
||||||
...);
|
|
||||||
int AsynSrv_ConfigDflt (
|
|
||||||
char *par_id,
|
|
||||||
...);
|
|
||||||
void AsynSrv_ErrInfo (
|
|
||||||
char **entry_txt,
|
|
||||||
int *errcode,
|
|
||||||
int *my_errno,
|
|
||||||
int *vaxc_errno);
|
|
||||||
char *AsynSrv_GetReply (
|
|
||||||
struct AsynSrv__info *asyn_info,
|
|
||||||
struct RS__RespStruct *rcve_buff,
|
|
||||||
char *last_rply);
|
|
||||||
int AsynSrv_Open (
|
|
||||||
struct AsynSrv__info *asyn_info);
|
|
||||||
int AsynSrv_SendCmnds (
|
|
||||||
struct AsynSrv__info *asyn_info,
|
|
||||||
struct RS__MsgStruct *send_buff,
|
|
||||||
struct RS__RespStruct *rcve_buff,
|
|
||||||
...);
|
|
||||||
int AsynSrv_SendCmndsBig (
|
|
||||||
struct AsynSrv__info *asyn_info,
|
|
||||||
struct RS__MsgStruct *send_buff,
|
|
||||||
int send_buff_size,
|
|
||||||
struct RS__RespStruct *rcve_buff,
|
|
||||||
int rcve_buff_size,
|
|
||||||
...);
|
|
||||||
|
|
||||||
void GetErrno (
|
|
||||||
int *his_errno,
|
|
||||||
int *his_vaxc_errno);
|
|
||||||
|
|
||||||
char *StrJoin (
|
|
||||||
char *result,
|
|
||||||
int result_size,
|
|
||||||
char *str_a,
|
|
||||||
char *str_b);
|
|
186
tecs/str_buf.c
Normal file
186
tecs/str_buf.c
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "errhdl.h"
|
||||||
|
#include "str_util.h"
|
||||||
|
#include "str_buf.h"
|
||||||
|
|
||||||
|
char *str_nget_str(Str_Buf *buf, char *result, int reslen)
|
||||||
|
{ char *b, *f, *e, quote;
|
||||||
|
int res, l, ll;
|
||||||
|
|
||||||
|
if (buf->rdpos < 0 || buf->rdpos >= buf->dsize) ERR_MSG("buffer corrupt");
|
||||||
|
b=buf->buf + buf->rdpos;
|
||||||
|
if (*b=='"' || *b=='\'') { /* take string within quotes (single or double) */
|
||||||
|
quote=*b; b++;
|
||||||
|
f=strchr(b, quote);
|
||||||
|
if (f==NULL) ERR_MSG("missing '""'");
|
||||||
|
l=f-b;
|
||||||
|
e=strchr(f+1, buf->sep);
|
||||||
|
if (e==NULL) {
|
||||||
|
buf->rdpos = f - buf->buf + 1 + strlen(f+1);
|
||||||
|
} else {
|
||||||
|
buf->rdpos = e - buf->buf + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f=strchr(b, buf->sep);
|
||||||
|
if (f==NULL) {
|
||||||
|
l=strlen(b);
|
||||||
|
f=b+l;
|
||||||
|
buf->rdpos+=l;
|
||||||
|
} else {
|
||||||
|
l=f-b;
|
||||||
|
buf->rdpos+=l+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result==NULL) {
|
||||||
|
*f='\0';
|
||||||
|
return(b);
|
||||||
|
} else {
|
||||||
|
if (l>=reslen) ERR_MSG("result too short");
|
||||||
|
strncpy(result, b, l);
|
||||||
|
result[l]='\0';
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
OnError:
|
||||||
|
buf->rdpos=-1;
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_get_int(Str_Buf *buf, int *res)
|
||||||
|
{ char num[32];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ERR_P(str_get_str(buf, num));
|
||||||
|
i=sscanf(num, "%d", res);
|
||||||
|
if (i==0) ERR_MSG("illegal number");
|
||||||
|
return(0);
|
||||||
|
OnError:
|
||||||
|
buf->rdpos=-1;
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_get_float(Str_Buf *buf, float *res)
|
||||||
|
{ char num[32];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ERR_P(str_get_str(buf, num));
|
||||||
|
i=sscanf(num, "%f", res);
|
||||||
|
if (i==0) ERR_MSG("illegal number");
|
||||||
|
return(0);
|
||||||
|
OnError:
|
||||||
|
buf->rdpos=-1;
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_get_end(Str_Buf *buf)
|
||||||
|
{
|
||||||
|
if (buf->rdpos < 0 || buf->rdpos >= buf->dsize) ERR_MSG("buffer corrupt");
|
||||||
|
if (buf->rdpos != buf->wrpos) ERR_MSG("superflous content in buffer");
|
||||||
|
return(0);
|
||||||
|
OnError:
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_put_str(Str_Buf *buf, const char *str)
|
||||||
|
{ int l, pos;
|
||||||
|
char quote;
|
||||||
|
|
||||||
|
pos=buf->wrpos;
|
||||||
|
if (pos < 0 || pos >= buf->dsize) ERR_MSG("buffer corrupt");
|
||||||
|
l=strlen(str);
|
||||||
|
quote='\0';
|
||||||
|
if (buf->sep>STR_NOSEPARATOR) {
|
||||||
|
if (strchr(str, buf->sep)!=NULL) {
|
||||||
|
if (strchr(str, '"')==NULL) {
|
||||||
|
quote='"'; l+=2;
|
||||||
|
} else if (strchr(str, '\'')==NULL) {
|
||||||
|
quote='\''; l+=2;
|
||||||
|
} else {
|
||||||
|
ERR_MSG("str must not contain separator and both kind of quotes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pos+l >= buf->dsize) ERR_MSG("buffer too short");
|
||||||
|
if (quote!='\0') {
|
||||||
|
buf->buf[pos]=quote; pos++;
|
||||||
|
strcpy(buf->buf + pos, str);
|
||||||
|
buf->buf[pos]=quote; pos++;
|
||||||
|
} else {
|
||||||
|
strcpy(buf->buf + pos, str);
|
||||||
|
}
|
||||||
|
pos+=l;
|
||||||
|
if (buf->sep!=STR_NOSEPARATOR) {
|
||||||
|
buf->buf[pos]=buf->sep;
|
||||||
|
pos++;
|
||||||
|
} else {
|
||||||
|
buf->buf[pos]='\0';
|
||||||
|
}
|
||||||
|
buf->wrpos=pos;
|
||||||
|
return(0);
|
||||||
|
OnError:
|
||||||
|
buf->wrpos=-1;
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_put_int(Str_Buf *buf, int val)
|
||||||
|
{ char num[32];
|
||||||
|
|
||||||
|
sprintf(num, "%d", val);
|
||||||
|
ERR_I(str_put_str(buf, num));
|
||||||
|
return(0);
|
||||||
|
OnError:
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_put_float(Str_Buf *buf, float val)
|
||||||
|
{ char num[32];
|
||||||
|
|
||||||
|
sprintf(num, "%f", val);
|
||||||
|
ERR_I(str_put_str(buf, num));
|
||||||
|
return(0);
|
||||||
|
OnError:
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_get_start(Str_Buf *buf)
|
||||||
|
{ buf->rdpos=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_put_start(Str_Buf *buf)
|
||||||
|
{ buf->rdpos=0;
|
||||||
|
buf->wrpos=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Str_Buf *str_create_buf(size_t size, char separator)
|
||||||
|
{ Str_Buf *buf;
|
||||||
|
|
||||||
|
ERR_P(buf=malloc(sizeof(*buf)));
|
||||||
|
ERR_P(buf->buf=malloc(size));
|
||||||
|
buf->dsize=size;
|
||||||
|
buf->sep=separator;
|
||||||
|
buf->wrpos=0;
|
||||||
|
buf->rdpos=0;
|
||||||
|
return(buf);
|
||||||
|
OnError:
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_link_buf(Str_Buf *buf, char *str, int size, char separator) {
|
||||||
|
buf->buf=str;
|
||||||
|
buf->rdpos=0;
|
||||||
|
if (size==0) {
|
||||||
|
buf->wrpos=strlen(str);
|
||||||
|
buf->dsize=buf->wrpos+1;
|
||||||
|
} else {
|
||||||
|
buf->wrpos=0;
|
||||||
|
buf->dsize=size;
|
||||||
|
}
|
||||||
|
buf->sep=separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_free_buf(Str_Buf *buf)
|
||||||
|
{ free(buf->buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
142
tecs/strjoin.c
142
tecs/strjoin.c
@ -1,142 +0,0 @@
|
|||||||
#define ident "1B03"
|
|
||||||
#ifdef VAXC
|
|
||||||
#module StrJoin ident
|
|
||||||
#endif
|
|
||||||
#ifdef __DECC
|
|
||||||
#pragma module StrJoin ident
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
** +--------------------------------------------------------------+
|
|
||||||
** | Paul Scherrer Institute |
|
|
||||||
** | Department ASQ |
|
|
||||||
** | |
|
|
||||||
** | This software may be used freely by non-profit organizations.|
|
|
||||||
** | It may be copied provided that the name of P.S.I. and of the |
|
|
||||||
** | author is included. Neither P.S.I. nor the author assume any |
|
|
||||||
** | responsibility for the use of this software outside of P.S.I.|
|
|
||||||
** +--------------------------------------------------------------+
|
|
||||||
**
|
|
||||||
** Module Name . . . . . . . . : [...LIB.SINQ]STRJOIN.C
|
|
||||||
**
|
|
||||||
** Author . . . . . . . . . . : D. Maden
|
|
||||||
** Date of creation . . . . . . : Nov 1995
|
|
||||||
**
|
|
||||||
** To compile this module, use:
|
|
||||||
|
|
||||||
$ import tasmad
|
|
||||||
$ define/group sinq_c_tlb mad_lib:sinq_c.tlb
|
|
||||||
$ cc /debug /noopt /obj=[]StrEdit -
|
|
||||||
tasmad_disk:[mad.lib.sinq]StrEdit +
|
|
||||||
sinq_c_tlb/lib
|
|
||||||
|
|
||||||
** To include this module in SINQ.OLB, use:
|
|
||||||
|
|
||||||
$ import tasmad
|
|
||||||
$ define/group sinq_c_tlb mad_lib:sinq_c.tlb
|
|
||||||
$
|
|
||||||
$ define/group sinq_olb mad_lib:sinq_dbg.olb
|
|
||||||
$ @tasmad_disk:[mad.lib.sinq]sinq_olb StrEdit debug
|
|
||||||
$
|
|
||||||
$ define/group sinq_olb mad_lib:sinq.olb
|
|
||||||
$ @tasmad_disk:[mad.lib.sinq]sinq_olb StrEdit
|
|
||||||
**
|
|
||||||
** Updates:
|
|
||||||
** 1A01 2-Nov-1995 DM. Initial version.
|
|
||||||
** 1B01 21-Mar-1996 DM. Move from DELTAT.OLB to SINQ.OLB.
|
|
||||||
** 1B03 28-May-1997 DM. Allow result string to be either of source
|
|
||||||
** strings.
|
|
||||||
**============================================================================
|
|
||||||
** The following entry points are included in this module:
|
|
||||||
**
|
|
||||||
**-------------------------------------------------------------------------
|
|
||||||
** #include <sinq_prototypes.h>
|
|
||||||
**
|
|
||||||
** char *StrJoin (&result, result_size, &str_a, &str_b)
|
|
||||||
** -------
|
|
||||||
** Input Args:
|
|
||||||
** int result_size - max size of "result". The resultant string will
|
|
||||||
** have a max length of (result_size - 1) to allow
|
|
||||||
** for the zero terminator
|
|
||||||
** char *str_a - Pointer to first string to be joined.
|
|
||||||
** char *str_b - Pointer to second string to be joined.
|
|
||||||
** Output Args:
|
|
||||||
** char *result - Pointer to resulting string.
|
|
||||||
** Modified Args:
|
|
||||||
** none
|
|
||||||
** Return value:
|
|
||||||
** Pointer to resulting string.
|
|
||||||
** Global variables modified:
|
|
||||||
** none
|
|
||||||
** Routines called:
|
|
||||||
** None
|
|
||||||
** Description:
|
|
||||||
** The routine joins 2 strings, checking for total string length and
|
|
||||||
** ensuring the result will be zero terminated. The "result" arg may be
|
|
||||||
** the same as "str_a" or "str_b".
|
|
||||||
**-------------------------------------------------------------------------
|
|
||||||
** Global Definitions
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define NIL '\0'
|
|
||||||
/*
|
|
||||||
**====================================================================
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
**====================================================================
|
|
||||||
** StrJoin - join 2 strings.
|
|
||||||
** Note: strncat is used exclusively rather than
|
|
||||||
** strncpy to be sure result is always
|
|
||||||
** null terminated.
|
|
||||||
*/
|
|
||||||
char *StrJoin (
|
|
||||||
/* =======
|
|
||||||
*/ char *result,
|
|
||||||
int result_size,
|
|
||||||
char *str_a,
|
|
||||||
char *str_b) {
|
|
||||||
|
|
||||||
int i, size, size_a, size_b;
|
|
||||||
|
|
||||||
size = result_size - 1;
|
|
||||||
|
|
||||||
if (size < 0) return result;
|
|
||||||
|
|
||||||
if (result == str_a) { /* Are the result and str_a the same? */
|
|
||||||
size_a = strlen (str_a); /* Yes */
|
|
||||||
if (size_a > size) { /* Check sizes anyway. */
|
|
||||||
result[size] = NIL; /* Truncate str_a. No room for str_b! */
|
|
||||||
}else {
|
|
||||||
size = size - strlen (result); /* And append str_b */
|
|
||||||
if (size > 0) {
|
|
||||||
strncat (result, str_b, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if (result == str_b) { /* Are the result and str_b the same? */
|
|
||||||
size_a = strlen (str_a); /* Yes, this is a bit complicated! */
|
|
||||||
size_b = strlen (str_b);
|
|
||||||
if (size_a >= size) { /* If str_a completely fills result, .. */
|
|
||||||
result[0] = NIL; /* .. then just copy in str_a */
|
|
||||||
strncat (result, str_a, size);
|
|
||||||
}else {
|
|
||||||
/*
|
|
||||||
** Otherwise, str_b must first be moved to
|
|
||||||
** make room for str_a and then str_a must
|
|
||||||
** be put at the front of the result.
|
|
||||||
*/
|
|
||||||
if ((size_a + size_b) > size) size_b = size - size_a;
|
|
||||||
result[size_a+size_b] = NIL;
|
|
||||||
for (i = (size_b-1); i >= 0; i--) {
|
|
||||||
result[size_a+i] = str_b[i];
|
|
||||||
}
|
|
||||||
memcpy (result, str_a, size_a);
|
|
||||||
}
|
|
||||||
}else { /* Result is neither str_a nor str_b so .. */
|
|
||||||
result[0] = NIL; /* .. str_a needs to be copied */
|
|
||||||
strncat (result, str_a, size);
|
|
||||||
size = size - strlen (result); /* And str_a appended */
|
|
||||||
if (size > 0) strncat (result, str_b, size);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/*-------------------------------------------------- End of STRJOIN.C =======*/
|
|
Reference in New Issue
Block a user