Skip to content

Commit

Permalink
Beginning das3_rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiker committed Aug 2, 2024
1 parent 3291c61 commit a39f433
Show file tree
Hide file tree
Showing 8 changed files with 462 additions and 94 deletions.
1 change: 1 addition & 0 deletions buildfiles/Linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TEST_PROGS:=TestUnits TestArray TestVariable LoadStream TestBuilder \
CDF_PROGS:=das3_cdf

ifeq ($(SPICE),yes)
UTIL_PROGS:=$(UTIL_PROGS) das3_rotate
TEST_PROGS:=$(TEST_PROGS) TestSpice
endif

Expand Down
3 changes: 2 additions & 1 deletion das2/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ typedef int DasErrCode;
#define DASERR_VEC 40
#define DASERR_SERIAL 41
#define DASERR_ITER 42
#define DASERR_MAX 42
#define DASERR_SPICE 43
#define DASERR_MAX 43

#ifdef __cplusplus
}
Expand Down
14 changes: 7 additions & 7 deletions das2/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int das_send_nodata(int nDasVer, const char* sFmt, ...)
snprintf(sOut, 1151, "<exception type=\"NoDataInInterval\"\n"
" message=\"%s\" />\n", sMsgEsc);

printf("[xx]%06zu%s", strlen(sOut), sOut);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
return 0;
}
Expand All @@ -101,7 +101,7 @@ int das_send_queryerr(int nDasVer, const char* sFmt, ...)
snprintf(sOut, 1151, "<exception type=\"IllegalArgument\"\n"
" message=\"%s\" />\n", sMsgEsc);

printf("[xx]%06zu%s", strlen(sOut), sOut);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
return 47;
}
Expand All @@ -125,7 +125,7 @@ int das_vsend_queryerr(int nDasVer, const char* sFmt, va_list argp)
snprintf(sOut, 1151, "<exception type=\"IllegalArgument\"\n"
" message=\"%s\" />\n", sMsgEsc);

printf("[xx]%06zu%s", strlen(sOut), sOut);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
return 47;
}
Expand All @@ -147,7 +147,7 @@ int das_send_srverr(int nDasVer, const char* sFmt, ...)
snprintf(sOut, 1151, "<exception type=\"ServerError\"\n"
" message=\"%s\" />\n", sMsgEsc);

printf("[xx]%06zu%s", strlen(sOut), sOut);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
return 48;
}
Expand All @@ -173,7 +173,7 @@ void das_send_msg(int nDasVer, const char* sSource, const char* sFmt, ...)
" source=\"%s\"\n"
" value=\"%s\" />\n", sSrcEsc, sMsgEsc);

printf("[xx]%06zu%s", strlen(sOut), sOut);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
}

Expand All @@ -196,7 +196,7 @@ void das_send_progbeg(int nDasVer, const char* sSrc, double fBeg, double fEnd)
char sMsg[1024] = {'\0'};
snprintf(sMsg, 1023, "<comment type=\"taskSize\" value=\"100\" source=\"%s\" />\n",
sSrc);
printf("[xx]%06zu%s", strlen(sMsg), sMsg);
printf("[XX]%06zu%s", strlen(sMsg), sMsg);
}

void das_send_progup(
Expand All @@ -214,7 +214,7 @@ void das_send_progup(
char sMsg[1024] = {'\0'};
snprintf(sMsg, 1023, "<comment type=\"taskProgress\" value=\"%d\" source=\"%s\" />\n",
nProg, sSrc);
printf("[xx]%06zu%s", strlen(sMsg), sMsg);
printf("[XX]%06zu%s", strlen(sMsg), sMsg);

g_nLastProg = nProg;
}
Expand Down
35 changes: 26 additions & 9 deletions das2/spice.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <SpiceUsr.h>

#include "defs.h"
#include "util.h"
#include "send.h"

void das_spice_err_setup()
Expand Down Expand Up @@ -45,17 +47,32 @@ int das_send_spice_err(int nDasVer, const char* sErrType)

fprintf(stderr, "ERROR: %s\n", sMsg);

if(nDasVer == 2){
_das_escape_xml(sMsgEsc, 2047, sMsg);
snprintf(sOut, 3071,
"<exception type=\"%s\"\n"
" message=\"%s\" />\n", sErrType, sMsgEsc
);

printf("[xx]%06zu%s", strlen(sOut), sOut);
if(nDasVer > 1){
_das_escape_xml(sMsgEsc, 2047, sMsg);

if(nDasVer == 2){

snprintf(sOut, 3071,
"<exception type=\"%s\"\n"
" message=\"%s\" />\n", sErrType, sMsgEsc
);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
else{
if(nDasVer == 3){
snprintf(sOut, 3071,
"<exception type=\"%s\">\n"
"%s\n"
"</exception>\n", sErrType, sMsgEsc
);
printf("[XX]%06zu%s", strlen(sOut), sOut);
}
}
das_error(DASERR_SPICE, "Unknown stream version %d", nDasVer);
}

return 89;
return DASERR_SPICE;
}

int das_print_spice_error(const char* sProgName)
Expand All @@ -78,5 +95,5 @@ int das_print_spice_error(const char* sProgName)
if(sProgName) fprintf(stderr, "ERROR (%s): %s\n", sProgName, sMsg);
else fprintf(stderr, "ERROR: %s\n", sMsg);

return 89;
return DASERR_SPICE;
}
56 changes: 56 additions & 0 deletions das2/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,3 +950,59 @@ double das_strtod_c(const char *nptr, char **endptr){
}

#endif

/* ************************************************************************* */
/* Command line helps */

/* See a given string matches the short or long form of an argument */
bool dascmd_isArg(
const char* sArg, const char* sShort, const char* sLong, bool* pLong
){
if(strcmp(sArg, sShort) == 0){
if(pLong) *pLong = false;
return true;
}
size_t uLen = strlen(sLong); /* Include the '=' */

if(strncmp(sArg, sLong, uLen) == 0){
if(pLong) *pLong = true;
return true;
}
return false;
}

/* Get the value of an argument if the current entry in argv matches
* either the short or long form */

bool dascmd_getArgVal(
char* sDest, size_t uDest, char** argv, int argc, int* pArgIdx,
const char* sShort, const char* sLong
){
bool bIsLong = false;

if(! dascmd_isArg(argv[*pArgIdx], sShort, sLong, &bIsLong))
return false;

const char* sVal;
if(bIsLong){
size_t uLongSz = strlen(sLong);
if(argv[*pArgIdx][uLongSz] == '\0') /* Nothing in str after prefix */
goto NO_ARG;

sVal = argv[*pArgIdx] + uLongSz;
}
else{
if(*pArgIdx > argc-2) /* Ain't no subsequent arg */
goto NO_ARG;

sVal = argv[*pArgIdx+1];
++(*pArgIdx);
}

strncpy(sDest, sVal, uDest - 1);
return true;

NO_ARG:
das_error(DASERR_UTIL, "Missing option after argument %s", argv[*pArgIdx]);
return false;
}
56 changes: 56 additions & 0 deletions das2/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,62 @@ DAS_API int das_dirlist(
*/
DAS_API double das_strtod_c(const char *nptr, char **endptr);

/** See a given string matches the short or long form of an option
*
* This is commonly used in loops over each command line argument. It
* works for arguments in the form:
*
* -a value
* --my-arg=value
*
* The form that has spaces between the long option name and the value
* is not supported
*
* @param sArg - A string to test
* @param sShort - The short form of an option
* @param sLong - The long form of an option
* @param pLong - If not NULL, the associated bool value is set to true if
* the long form of a argument was found.
*
* @returns true if the string matches the given option, false otherwise
*/
bool dascmd_isArg(const char* sArg, const char* sShort, const char* sLong, bool* pLong);


/** Get the value of an argument if the current entry in argv matches
* either the short or long form of an option.
*
* This is typically used to test command line arguments in a loop. It
* works for arguments in the form:
*
* -a value
* --my-arg=value
*
* The form that has spaces between the long option name and the value
* is not supported
*
* @param sDest - The location to recieve the option value
* @param uDest - The size of the location to recive the option value
* Note the macro DAS_FIELD_SZ is useful for getting
* the size of a field in a structure.
* @param argv - The list of command line parameters
* @param argc - The number of command line parameters
* @param pArgIdx - A pointer to the current argument index. It is
* incremented if the option is found.
* @param sShort - The short form of the option
* @param sLong - The long form of the option
*
* @returns false if the argument was not found or the option value
* missing ofter the argument, true otherwise and the index at
* pArgInd is incremented.
*
* @see also DAS_FIELD_SZ
*/
bool dascmd_getArgVal(
char* sDest, size_t uDest, char** argv, int argc, int* pArgIdx,
const char* sShort, const char* sLong
);

/** @} */


Expand Down
Loading

0 comments on commit a39f433

Please sign in to comment.