view src/xs_support.c @ 40:1788f4ce6a44

Numerous changes towards 0.8
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 19 Jun 2003 22:38:01 +0000
parents dec37e16136e
children 3518ca5c8b0f
line wrap: on
line source

/*  
   XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)

   Miscellaneous support functions
   
   Written by Matti "ccr" Hamalainen <ccr@tnsp.org>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "xmms-sid.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

/*
 * Utility routines
 */
gint xs_strcalloc(gchar **ppcResult, const gchar *pcStr)
{
 assert(ppcResult);
 assert(pcStr);
 
 /* Allocate memory for destination */
 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(pcStr) + 1);
 if (*ppcResult == NULL) return -1;

 /* Copy to the destination */
 strcpy(*ppcResult, pcStr);

 return 0;
}


int xs_strcat(gchar **ppcResult, const gchar *pcStr)
{
 assert(ppcResult);
 assert(pcStr);
 
 /* Re-allocate memory for destination */
 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + strlen(pcStr) + 1);
 if (*ppcResult == NULL) return -1;

 /* Cat to the destination */
 strcat(*ppcResult, pcStr);

 return 0;
}


int xs_strpcat(gchar **ppcResult, gint *j, const gchar *pcStr)
{
 int iLen;

 assert(ppcResult);
 assert(pcStr);
 assert(j);
 
 /* Get length of the pcString to be catted */
 iLen = strlen(pcStr);
 (*j) += iLen;

 /* Re-allocate memory for destination */
 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + iLen + 1);
 if (*ppcResult == NULL) return -1;

 /* Cat to the destination */
 strcat(*ppcResult, pcStr);

 return 0;
}


inline void xs_findnext(gchar *pcStr, gint *piPos)
{
 /* Terminating NULL-character is not whitespace! */
 while (isspace(pcStr[*piPos])) (*piPos)++;
}


inline void xs_findnum(gchar *pcStr, gint *piPos)
{
 /* Terminating NULL-character is not digit! */
 while (isdigit(pcStr[*piPos])) (*piPos)++;
}