From b36e5262c74e7f32bcb80cc52d2066fc452eb471 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 21 Aug 2020 17:59:46 -0500 Subject: [PATCH] const init a char array from a string value --- documentation/RELEASE_NOTES.md | 17 ++++++++++++++++- modules/database/src/std/link/lnkConst.c | 13 +++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/documentation/RELEASE_NOTES.md b/documentation/RELEASE_NOTES.md index f3e6a934f..0ec080579 100644 --- a/documentation/RELEASE_NOTES.md +++ b/documentation/RELEASE_NOTES.md @@ -17,11 +17,26 @@ should also be read to understand what has changed since earlier releases. +### Using a `{const:"string"}` to initialize an array of `DBF_CHAR` + +It is now possible to use a JSON Const link with a string value to initialize +an aai or waveform record that has `FTVL` set to `CHAR` through the INP link. +The string length is not limited to 40 characters. This should also work for +aSub record inputs similarly configured as long strings. + +``` + record(waveform, "wf") { + field(NELM, 100) + field(FTVL, CHAR) + field(INP, {const:"This is a waveform and more than 40 characters"}) + } +``` + ### RELEASE files may use `undefine` GNUmake added the directive `undefine` in version 3.82 to allow variables to be undefined. Support for this has been added to the EPICS Release file parser, -so `undefine` can now be used in configure/RELEASE files. +so `undefine` can now be used in configure/RELEASE files to unset variables. ## EPICS Release 7.0.4.1 diff --git a/modules/database/src/std/link/lnkConst.c b/modules/database/src/std/link/lnkConst.c index e990e91af..4e15fa803 100644 --- a/modules/database/src/std/link/lnkConst.c +++ b/modules/database/src/std/link/lnkConst.c @@ -489,8 +489,17 @@ static long lnkConst_loadArray(struct link *plink, short dbrType, void *pbuffer, case sc40: if (clink->jlink.debug) printf(" sc40 '%s'\n", clink->value.scalar_string); - status = dbFastPutConvertRoutine[DBF_STRING][dbrType] - (clink->value.scalar_string, pbuffer, NULL); + if (dbrType != DBF_CHAR) { + status = dbFastPutConvertRoutine[DBF_STRING][dbrType] + (clink->value.scalar_string, pbuffer, NULL); + } + else { + /* Long string conversion */ + strncpy(pbuffer, clink->value.scalar_string, *pnReq); + ((char *)pbuffer)[*pnReq] = 0; + nElems = strlen(pbuffer) + 1; + status = 0; + } break; case ai64: