/[svn]/liblscp/trunk/src/common.c
ViewVC logotype

Diff of /liblscp/trunk/src/common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 179 by capela, Tue Jul 6 16:24:41 2004 UTC revision 187 by capela, Wed Jul 7 23:41:07 2004 UTC
# Line 223  char *lscp_unquote ( char **ppsz, int du Line 223  char *lscp_unquote ( char **ppsz, int du
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 )
# Line 346  int *lscp_isplit_create ( const char *ps Line 358  int *lscp_isplit_create ( const char *ps
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...
# Line 355  int *lscp_isplit_create ( const char *ps Line 372  int *lscp_isplit_create ( const char *ps
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;
# Line 556  void lscp_plist_append ( lscp_param_t ** Line 572  void lscp_plist_append ( lscp_param_t **
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);
# Line 578  void lscp_plist_append ( lscp_param_t ** Line 601  void lscp_plist_append ( lscp_param_t **
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 )
# Line 592  int lscp_plist_count ( lscp_param_t **pp Line 616  int lscp_plist_count ( lscp_param_t **pp
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  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 778  int lscp_param_concat ( char *pszBuffer, Line 802  int lscp_param_concat ( char *pszBuffer,
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);

Legend:
Removed from v.179  
changed lines
  Added in v.187

  ViewVC Help
Powered by ViewVC