Skip to content

Commit

Permalink
kappa: Improved NDF config handling in configecho.
Browse files Browse the repository at this point in the history
Used ndfBegin and ndfEnd and AST string routines.  Added
more status checking.  Addressed compiler warnings,
improved the error message and updated the DisplayKeyMap
comment.
  • Loading branch information
grahambell committed Feb 15, 2013
1 parent 9425a4d commit 7228994
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions applications/kappa/libkappa/configecho.c
Expand Up @@ -215,7 +215,7 @@ F77_SUBROUTINE(configecho)( INTEGER(STATUS) ){
char defval[250];
char name[250];
const char *value;
char *historyValue = 0;
const char *historyValue = 0;
int showall;
int sort;
size_t size;
Expand Down Expand Up @@ -244,7 +244,8 @@ F77_SUBROUTINE(configecho)( INTEGER(STATUS) ){
}
}

/* Get the NDF file handle if requested. */
/* Get the NDF identifier if requested. */
ndfBegin();
if (*STATUS == SAI__OK) {
ndfAssoc("NDF", "READ", &indf, STATUS);
if (*STATUS == PAR__NULL) {
Expand Down Expand Up @@ -307,11 +308,11 @@ F77_SUBROUTINE(configecho)( INTEGER(STATUS) ){
}
}

if (! historyConfig) {
if (*STATUS == SAI__OK && ! historyConfig) {
*STATUS = SAI__ERROR;

errRep("CONFIGECHO_ERR", "CONFIGECHO: Failed to find application "
"configuration in NDF history.", STATUS);
errRepf("CONFIGECHO_ERR", "CONFIGECHO: Failed to find %s "
"configuration in NDF history.", STATUS, application);
}
else if (! keymap) {
keymap = historyConfig;
Expand Down Expand Up @@ -416,9 +417,7 @@ L999:;
astEnd;

/* Close the NDF if open. */
if (indf) {
ndfAnnul(&indf, STATUS);
}
ndfEnd(STATUS);

/* If an error has occurred, issue another error report identifying the
program which has failed (i.e. this one). */
Expand Down Expand Up @@ -455,15 +454,16 @@ static void DisplayKeyMap( AstKeyMap *km, int sort, const char *prefix,
* A string to prepend to eack key.
* refkm
* Reference key map (e.g. values from the supplied configuration
* rather than the NDF history).
* rather than the NDF history), or null if not required.
* status
* Inherited status pointer.
* Description:
* This function displays the contents of a supplied KeyMap as
* a series of "key = value" strings, one per line. It calls itself
* recursively if a nested KeyMap is found, adding a suitable
* prefix to the nested keys.
* prefix to the nested keys. If a reference key map is supplied then
* the output shows how the main key map differs from it.
*/

/* Local Variables: */
Expand Down Expand Up @@ -499,7 +499,7 @@ static void DisplayKeyMap( AstKeyMap *km, int sort, const char *prefix,
astMapGet0A( km, key, &avalue );
if (refkm) {
if (! astMapGet0A(refkm, key, &refavalue)) {
refavalue = astKeyMap("");
refavalue = (AstObject*) astKeyMap("");
}
}
else {
Expand Down Expand Up @@ -605,7 +605,8 @@ void HistoryKeyMap(int n, char* const text[], int* status) {
char patt_group[] = "Group:";
char patt_cont[] = " ";
char patt_name[] = "CONFIG";
char buff[1000000];
char* buff = NULL;
int nc = 0;
char line[NDF__SZHIS + 1];
char* p;
char* q;
Expand All @@ -615,6 +616,7 @@ void HistoryKeyMap(int n, char* const text[], int* status) {
Grp* grp;
size_t grpsize;
int grpadded, grpflag;
if (*status != SAI__OK) return;

/* Loop over history text lines, copying each into line for editing
and setting p to point at the start of line. */
Expand All @@ -633,7 +635,7 @@ void HistoryKeyMap(int n, char* const text[], int* status) {
p += strlen(patt_cont);
while (*p == ' ') p++;
while (p[strlen(p) - 1] == ' ') p[strlen(p) - 1] = '\0';
strncat(buff, p, sizeof(buff) - strlen(buff) - 1);
buff = astAppendString(buff, &nc, p);
continue;
}
else {
Expand Down Expand Up @@ -670,7 +672,7 @@ void HistoryKeyMap(int n, char* const text[], int* status) {
if (*p == '"') p++;
while (*p == ' ') p++;
while (p[strlen(p) - 1] == ' ') p[strlen(p) - 1] = '\0';
strncpy(buff, p, sizeof(buff));
buff = astAppendString(astFree(buff), &nc, p);
groupcontinuing = 1;
}
}
Expand Down Expand Up @@ -705,5 +707,6 @@ void HistoryKeyMap(int n, char* const text[], int* status) {

kpg1Kymap(grp, &historyConfig, status);
grpDelet(&grp, status);
buff = astFree(buff);
}
}

0 comments on commit 7228994

Please sign in to comment.