223 |
return psz; |
return psz; |
224 |
} |
} |
225 |
|
|
226 |
|
// Unquote and make a duplicate of an in-split string. |
227 |
|
void lscp_unquote_dup ( char **ppszDst, char **ppszSrc ) |
228 |
|
{ |
229 |
|
// Free desteny string, if already there. |
230 |
|
if (*ppszDst) |
231 |
|
free(*ppszDst); |
232 |
|
*ppszDst = NULL; |
233 |
|
// Unquote and duplicate. |
234 |
|
if (*ppszSrc) |
235 |
|
*ppszDst = lscp_unquote(ppszSrc, 1); |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
// Custom tokenizer. |
// Custom tokenizer. |
240 |
char *lscp_strtok ( char *pchBuffer, const char *pszSeps, char **ppch ) |
char *lscp_strtok ( char *pchBuffer, const char *pszSeps, char **ppch ) |
358 |
int iSize, i, j, cchSeps; |
int iSize, i, j, cchSeps; |
359 |
int *piSplit, *piNewSplit; |
int *piSplit, *piNewSplit; |
360 |
|
|
361 |
|
// Get it clean first. |
362 |
|
pchHead = lscp_ltrim((char *) pszCsv); |
363 |
|
if (*pchHead == (char) 0) |
364 |
|
return NULL; |
365 |
|
|
366 |
// Initial size is one chunk away. |
// Initial size is one chunk away. |
367 |
iSize = LSCP_SPLIT_CHUNK1; |
iSize = LSCP_SPLIT_CHUNK1; |
368 |
// Allocate and split... |
// Allocate and split... |
372 |
|
|
373 |
// Make a copy of the original string. |
// Make a copy of the original string. |
374 |
i = 0; |
i = 0; |
|
pchHead = (char *) pszCsv; |
|
375 |
if ((piSplit[i++] = atoi(pchHead)) < 0) { |
if ((piSplit[i++] = atoi(pchHead)) < 0) { |
376 |
free(piSplit); |
free(piSplit); |
377 |
return NULL; |
return NULL; |
572 |
|
|
573 |
if (ppList && *ppList) { |
if (ppList && *ppList) { |
574 |
pParams = *ppList; |
pParams = *ppList; |
575 |
while (pParams[i].key) |
while (pParams[i].key) { |
576 |
|
if (strcasecmp(pParams[i].key, pszKey) == 0) { |
577 |
|
if (pParams[i].value) |
578 |
|
free(pParams[i].value); |
579 |
|
pParams[i].value = strdup(pszValue); |
580 |
|
return; |
581 |
|
} |
582 |
i++; |
i++; |
583 |
|
} |
584 |
iSize = LSCP_SPLIT_SIZE(i); |
iSize = LSCP_SPLIT_SIZE(i); |
585 |
pParams[i].key = strdup(pszKey); |
pParams[i].key = strdup(pszKey); |
586 |
pParams[i].value = strdup(pszValue); |
pParams[i].value = strdup(pszValue); |
601 |
} |
} |
602 |
} |
} |
603 |
|
|
604 |
|
#ifdef LSCP_PLIST_COUNT |
605 |
|
|
606 |
// Compute a parameter list valid item count. |
// Compute a parameter list valid item count. |
607 |
int lscp_plist_count ( lscp_param_t **ppList ) |
int lscp_plist_count ( lscp_param_t **ppList ) |
616 |
return i; |
return i; |
617 |
} |
} |
618 |
|
|
|
|
|
619 |
// Compute the legal parameter list size. |
// Compute the legal parameter list size. |
620 |
int lscp_plist_size ( lscp_param_t **ppList ) |
int lscp_plist_size ( lscp_param_t **ppList ) |
621 |
{ |
{ |
622 |
return LSCP_SPLIT_SIZE(lscp_plist_count(ppList)); |
return LSCP_SPLIT_SIZE(lscp_plist_count(ppList)); |
623 |
} |
} |
624 |
|
|
625 |
|
#endif // LSCP_PLIST_COUNT |
626 |
|
|
627 |
|
|
628 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
802 |
{ |
{ |
803 |
int cchBuffer, cchParam, i; |
int cchBuffer, cchParam, i; |
804 |
|
|
805 |
if (pszBuffer == NULL || pParams == NULL) |
if (pszBuffer == NULL) |
806 |
return 0; |
return 0; |
807 |
|
|
808 |
cchBuffer = strlen(pszBuffer); |
cchBuffer = strlen(pszBuffer); |
809 |
for (i = 0; pParams[i].key && pParams[i].value; i++) { |
for (i = 0; pParams && pParams[i].key && pParams[i].value; i++) { |
810 |
cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4; |
cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4; |
811 |
if (cchBuffer + cchParam + 2 < cchMaxBuffer) { |
if (cchBuffer + cchParam + 2 < cchMaxBuffer) { |
812 |
sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value); |
sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value); |
817 |
if (cchBuffer + 2 < cchMaxBuffer) { |
if (cchBuffer + 2 < cchMaxBuffer) { |
818 |
pszBuffer[cchBuffer++] = '\r'; |
pszBuffer[cchBuffer++] = '\r'; |
819 |
pszBuffer[cchBuffer++] = '\n'; |
pszBuffer[cchBuffer++] = '\n'; |
820 |
|
pszBuffer[cchBuffer ] = (char) 0; |
821 |
} |
} |
822 |
|
|
823 |
return cchBuffer; |
return cchBuffer; |