diff --git a/nxscript.c b/nxscript.c index fb93a260..810417cf 100644 --- a/nxscript.c +++ b/nxscript.c @@ -1491,6 +1491,37 @@ static int SPutAddType(void *message, void *userData) } return MPCONTINUE; } +/*----------------------------------------------------------------------- +Writing should not fail due to some error in padding. Thus this routine +protects against errors but does not fail + ------------------------------------------------------------------------*/ +static int SPutPadding(void *message, void *userData) +{ + pPutMessage self = (pPutMessage)message; + char *pPtr = NULL, *pEnd = NULL; + unsigned int len, i; + + if(self->v.dataType == HIPTEXT && strstr(self->v.v.text,"@len") != NULL){ + pPtr = strchr(self->v.v.text,'='); + pPtr++; + pEnd = strchr(pPtr,'@'); + if(pPtr != NULL && pEnd != NULL){ + *pEnd = '\0'; + len = atoi(pPtr); + } + pPtr = malloc(len*sizeof(char)); + if(pPtr != NULL){ + memset(pPtr,0,len*sizeof(char)); + strncpy(pPtr,pEnd+1,len); + for(i = strlen(pPtr); i < len-1; i++){ + pPtr[i] = ' '; + } + free(self->v.v.text); + self->v.v.text = pPtr; + } + } + return MPCONTINUE; +} /*------------------------------------------------------------------------*/ static int SPutDim(void *message, void *userData) { @@ -1604,6 +1635,7 @@ static void configurePutPipe() AppendMPFilter(putPipe,SGetData, NULL,NULL); AppendMPFilter(putPipe,GetDefString, NULL,NULL); AppendMPFilter(putPipe,SPutAddType, NULL,NULL); + /* AppendMPFilter(putPipe,SPutPadding, NULL,NULL); */ AppendMPFilter(putPipe,SPutDim, NULL,NULL); AppendMPFilter(putPipe,SPutWrite, NULL,NULL); }