/[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 158 by capela, Tue Jun 29 16:39:11 2004 UTC revision 163 by capela, Wed Jun 30 15:16:03 2004 UTC
# Line 445  lscp_param_t *lscp_psplit_create ( const Line 445  lscp_param_t *lscp_psplit_create ( const
445          ppSplit[i].key = pszHead;          ppSplit[i].key = pszHead;
446          pszHead = pch + cchSeps1;          pszHead = pch + cchSeps1;
447          *pch = (char) 0;          *pch = (char) 0;
448          ppSplit[i].value.psz = lscp_unquote(&pszHead, 0);          ppSplit[i].value = lscp_unquote(&pszHead, 0);
449          if ((pch = strpbrk(pszHead, pszSeps2)) != NULL) {          if ((pch = strpbrk(pszHead, pszSeps2)) != NULL) {
450              pszHead = pch + cchSeps2;              pszHead = pch + cchSeps2;
451              *pch = (char) 0;              *pch = (char) 0;
# Line 455  lscp_param_t *lscp_psplit_create ( const Line 455  lscp_param_t *lscp_psplit_create ( const
455              ppNewSplit = (lscp_param_t *) malloc(iSize * sizeof(lscp_param_t));              ppNewSplit = (lscp_param_t *) malloc(iSize * sizeof(lscp_param_t));
456              if (ppNewSplit) {              if (ppNewSplit) {
457                  for (j = 0; j < i; j++) {                  for (j = 0; j < i; j++) {
458                      ppNewSplit[j].key = ppSplit[j].key;                      ppNewSplit[j].key   = ppSplit[j].key;
459                      ppNewSplit[j].value.psz = ppSplit[j].value.psz;                      ppNewSplit[j].value = ppSplit[j].value;
460                  }                  }
461                  free(ppSplit);                  free(ppSplit);
462                  ppSplit = ppNewSplit;                  ppSplit = ppNewSplit;
# Line 468  lscp_param_t *lscp_psplit_create ( const Line 468  lscp_param_t *lscp_psplit_create ( const
468          free(pszHead);          free(pszHead);
469    
470      for ( ; i < iSize; i++) {      for ( ; i < iSize; i++) {
471          ppSplit[i].key = NULL;          ppSplit[i].key   = NULL;
472          ppSplit[i].value.psz = NULL;          ppSplit[i].value = NULL;
473      }      }
474    
475      return ppSplit;      return ppSplit;
# Line 579  void lscp_driver_info_reset ( lscp_drive Line 579  void lscp_driver_info_reset ( lscp_drive
579  }  }
580    
581    
582    //-------------------------------------------------------------------------
583    // Parameter struct helper functions.
584    
585    void lscp_param_info_init ( lscp_param_info_t *pParamInfo )
586    {
587        pParamInfo->type          = LSCP_TYPE_NONE;
588        pParamInfo->description   = NULL;
589        pParamInfo->mandatory     = 0;
590        pParamInfo->fix           = 0;
591        pParamInfo->multiplicity  = 0;
592        pParamInfo->depends       = NULL;
593        pParamInfo->defaultv      = NULL;
594        pParamInfo->range_min     = NULL;
595        pParamInfo->range_max     = NULL;
596        pParamInfo->possibilities = NULL;
597    }
598    
599    void lscp_param_info_reset ( lscp_param_info_t *pParamInfo )
600    {
601        if (pParamInfo->description)
602            free(pParamInfo->description);
603        lscp_szsplit_destroy(pParamInfo->depends);
604        if (pParamInfo->defaultv)
605            free(pParamInfo->defaultv);
606        if (pParamInfo->range_min)
607            free(pParamInfo->range_min);
608        if (pParamInfo->range_max)
609            free(pParamInfo->range_max);
610        lscp_szsplit_destroy(pParamInfo->possibilities);
611        
612        lscp_param_info_init(pParamInfo);
613    }
614    
615    
616    //-------------------------------------------------------------------------
617    // Concatenate a parameter list (key='value'...) into a string.
618    
619    int lscp_param_concat ( char *pszBuffer, int cchMaxBuffer, lscp_param_t *pParams )
620    {
621        int cchBuffer, cchParam, i;
622    
623        if (pszBuffer == NULL || pParams == NULL)
624            return 0;
625    
626        cchBuffer = strlen(pszBuffer);
627        for (i = 0; pParams[i].key && pParams[i].value; i++) {
628            cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4;
629            if (cchBuffer + cchParam < cchMaxBuffer) {
630                sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value);
631                cchBuffer += cchParam;
632            }
633        }
634        return cchBuffer;
635    }
636    
637    
638  // end of common.c  // end of common.c

Legend:
Removed from v.158  
changed lines
  Added in v.163

  ViewVC Help
Powered by ViewVC