fix (and simplify) reading strings into waveform, aai, aao, lsi, lso
This commit is contained in:
@ -116,17 +116,11 @@ static long readData(dbCommon *record, format_t *format)
|
|||||||
if ((length = streamScanfN(record, format,
|
if ((length = streamScanfN(record, format,
|
||||||
(char *)aai->bptr, aai->nelm)) == ERROR)
|
(char *)aai->bptr, aai->nelm)) == ERROR)
|
||||||
{
|
{
|
||||||
memset(aai->bptr, 0, aai->nelm);
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
if (lval < (ssize_t)aai->nelm)
|
if (length < (ssize_t)aai->nelm)
|
||||||
{
|
{
|
||||||
memset(((char*)aai->bptr)+lval , 0, aai->nelm-lval);
|
((char*)aai->bptr)[length] = 0;
|
||||||
lval++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
((char*)aai->bptr)[aai->nelm-1] = 0;
|
|
||||||
}
|
}
|
||||||
aai->nord = (long)length;
|
aai->nord = (long)length;
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -108,22 +108,16 @@ static long readData(dbCommon *record, format_t *format)
|
|||||||
case DBF_CHAR:
|
case DBF_CHAR:
|
||||||
case DBF_UCHAR:
|
case DBF_UCHAR:
|
||||||
{
|
{
|
||||||
ssize_t length;
|
ssize_t length;
|
||||||
aao->nord = 0;
|
aao->nord = 0;
|
||||||
if ((length = streamScanfN(record, format,
|
if ((length = streamScanfN(record, format,
|
||||||
(char *)aao->bptr, aao->nelm)) == ERROR)
|
(char *)aao->bptr, aao->nelm)) == ERROR)
|
||||||
{
|
{
|
||||||
memset(aao->bptr, 0, aao->nelm);
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
if (length < (ssize_t)aao->nelm)
|
if (length < (ssize_t)aao->nelm)
|
||||||
{
|
{
|
||||||
memset(((char*)aao->bptr)+lval , 0, aao->nelm-lval);
|
((char*)aao->bptr)[length] = 0;
|
||||||
lval++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
((char*)aao->bptr)[aao->nelm-1] = 0;
|
|
||||||
}
|
}
|
||||||
aao->nord = (long)length;
|
aao->nord = (long)length;
|
||||||
goto end_no_check;
|
goto end_no_check;
|
||||||
|
@ -23,30 +23,27 @@
|
|||||||
static long readData(dbCommon *record, format_t *format)
|
static long readData(dbCommon *record, format_t *format)
|
||||||
{
|
{
|
||||||
lsiRecord *lsi = (lsiRecord *)record;
|
lsiRecord *lsi = (lsiRecord *)record;
|
||||||
|
ssize_t length;
|
||||||
|
|
||||||
if (format->type == DBF_STRING)
|
if (format->type != DBF_STRING) return ERROR;
|
||||||
|
if ((length = streamScanfN(record, format, lsi->val, (long)lsi->sizv)) == ERROR)
|
||||||
{
|
{
|
||||||
long len;
|
return ERROR;
|
||||||
if ((len = streamScanfN(record, format, lsi->val, lsi->sizv) == ERROR))
|
|
||||||
{
|
|
||||||
lsi->len = 0;
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
lsi->len = len;
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
return ERROR;
|
if (length < (ssize_t)lsi->sizv)
|
||||||
|
{
|
||||||
|
lsi->val[length] = 0;
|
||||||
|
}
|
||||||
|
lsi->len = length;
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long writeData(dbCommon *record, format_t *format)
|
static long writeData(dbCommon *record, format_t *format)
|
||||||
{
|
{
|
||||||
lsiRecord *lsi = (lsiRecord *)record;
|
lsiRecord *lsi = (lsiRecord *)record;
|
||||||
|
|
||||||
if (format->type == DBF_STRING)
|
if (format->type != DBF_STRING) return ERROR;
|
||||||
{
|
return streamPrintf(record, format, lsi->val);
|
||||||
return streamPrintf(record, format, lsi->val);
|
|
||||||
}
|
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static long initRecord(dbCommon *record)
|
static long initRecord(dbCommon *record)
|
||||||
|
@ -24,17 +24,19 @@
|
|||||||
static long readData(dbCommon *record, format_t *format)
|
static long readData(dbCommon *record, format_t *format)
|
||||||
{
|
{
|
||||||
lsoRecord *lso = (lsoRecord *)record;
|
lsoRecord *lso = (lsoRecord *)record;
|
||||||
long len;
|
ssize_t length;
|
||||||
unsigned short monitor_mask;
|
unsigned short monitor_mask;
|
||||||
|
|
||||||
if (format->type != DBF_STRING)
|
if (format->type != DBF_STRING) return ERROR;
|
||||||
return ERROR;
|
if ((length = streamScanfN(record, format, lso->val, lso->sizv)) == ERROR)
|
||||||
if ((len = streamScanfN(record, format, lso->val, lso->sizv) == ERROR))
|
|
||||||
{
|
{
|
||||||
lso->len = 0;
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
lso->len = len;
|
if (length < (ssize_t)lso->sizv)
|
||||||
|
{
|
||||||
|
lso->val[length] = 0;
|
||||||
|
}
|
||||||
|
lso->len = length;
|
||||||
if (record->pact) return OK;
|
if (record->pact) return OK;
|
||||||
/* In @init handler, no processing, enforce monitor updates. */
|
/* In @init handler, no processing, enforce monitor updates. */
|
||||||
monitor_mask = recGblResetAlarms(record);
|
monitor_mask = recGblResetAlarms(record);
|
||||||
@ -60,11 +62,8 @@ static long writeData(dbCommon *record, format_t *format)
|
|||||||
{
|
{
|
||||||
lsoRecord *lso = (lsoRecord *)record;
|
lsoRecord *lso = (lsoRecord *)record;
|
||||||
|
|
||||||
if (format->type == DBF_STRING)
|
if (format->type != DBF_STRING) return ERROR;
|
||||||
{
|
return streamPrintf(record, format, lso->val);
|
||||||
return streamPrintf(record, format, lso->val);
|
|
||||||
}
|
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static long initRecord(dbCommon *record)
|
static long initRecord(dbCommon *record)
|
||||||
|
@ -117,21 +117,15 @@ static long readData(dbCommon *record, format_t *format)
|
|||||||
if ((length = streamScanfN(record, format,
|
if ((length = streamScanfN(record, format,
|
||||||
(char *)wf->bptr, wf->nelm)) == ERROR)
|
(char *)wf->bptr, wf->nelm)) == ERROR)
|
||||||
{
|
{
|
||||||
memset(wf->bptr, 0, wf->nelm);
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
if (length < (ssize_t)wf->nelm)
|
if (length < (ssize_t)wf->nelm)
|
||||||
{
|
{
|
||||||
memset(((char*)wf->bptr)+lval , 0, wf->nelm-lval);
|
((char*)wf->bptr)[length] = 0;
|
||||||
lval++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
((char*)wf->bptr)[wf->nelm-1] = 0;
|
|
||||||
}
|
}
|
||||||
wf->nord = (long)length;
|
wf->nord = (long)length;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
errlogSevPrintf(errlogFatal,
|
errlogSevPrintf(errlogFatal,
|
||||||
"readData %s: can't convert from string to %s\n",
|
"readData %s: can't convert from string to %s\n",
|
||||||
|
Reference in New Issue
Block a user