Beispiel #1
0
static void SaveParse(CFGSTRUCT *cfgst, FILE *fp)
{
        int x=0;

	while(cfgst[x].ptr)
        {
         if(!cfgst[x].name)     // Link to new config structure
	 {
	  SaveParse((CFGSTRUCT*)cfgst[x].ptr,fp);	// Recursion is sexy.  I could
					// save a little stack space if I made
					// the file pointer a non-local
					// variable...
	  x++;
	  continue;
	 }

         if(cfgst[x].len)               // Plain data
          SetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len);
         else                           // String
          if(*(char **)cfgst[x].ptr)    // Only save it if there IS a string.
           SetValueR(fp,cfgst[x].name,*(char **)cfgst[x].ptr,
                        strlen(*(char **)cfgst[x].ptr)+1);
         x++;
        }
}
Beispiel #2
0
/**
* Parses a c onfiguration structure and saves information from the structure into a file.
*
* @param cfgst The configuration structure.
* @param fp File handle.
**/
void SaveParse(const CFGSTRUCT *cfgst, FILE *fp)
{
	int x=0;

	while(cfgst[x].ptr)
	{

		//structure contains another embedded structure.
		//recurse.
		if(!cfgst[x].name) {
			SaveParse((CFGSTRUCT*)cfgst[x].ptr, fp);
			x++;
			continue;
		}

		if(cfgst[x].len)
		{
			// Plain data
			SetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len);
		}
		else
		{
			// String
			if(*(char **)cfgst[x].ptr)
			{
				// Only save it if there IS a string.
				unsigned int len = strlen(*(char **)cfgst[x].ptr);
				SetValueR(fp,cfgst[x].name,*(char **)cfgst[x].ptr, len + 1);
			}
		}

		x++;
	}
}