Ejemplo n.º 1
0
void CInifile::save_as	(IWriter& writer)
{
    string4096		temp,val;
    for (RootIt r_it=DATA.begin(); r_it!=DATA.end(); ++r_it)
    {
        sprintf_s		(temp,sizeof(temp),"[%s]",*(*r_it)->Name);
        writer.w_string	(temp);
        for (SectCIt s_it=(*r_it)->Data.begin(); s_it!=(*r_it)->Data.end(); ++s_it)
        {
            const Item&	I = *s_it;
            if (*I.first)
            {
                if (*I.second) {
                    _decorate	(val,*I.second);
#ifdef DEBUG
                    if (*I.comment) {
                        // name, value and comment
                        sprintf_s	(temp,sizeof(temp),"%8s%-32s = %-32s ;%s"," ",*I.first,val,*I.comment);
                    } else
#endif
                    {
                        // only name and value
                        sprintf_s	(temp,sizeof(temp),"%8s%-32s = %-32s"," ",*I.first,val);
                    }
                } else {
#ifdef DEBUG
                    if (*I.comment) {
                        // name and comment
                        sprintf_s(temp,sizeof(temp),"%8s%-32s = ;%s"," ",*I.first,*I.comment);
                    } else
#endif
                    {
                        // only name
                        sprintf_s(temp,sizeof(temp),"%8s%-32s = "," ",*I.first);
                    }
                }
            } else {
                // no name, so no value
#ifdef DEBUG
                if (*I.comment)
                    sprintf_s		(temp,sizeof(temp),"%8s;%s"," ",*I.comment);
                else
#endif
                    temp[0]		= 0;
            }
            _TrimRight			(temp);
            if (temp[0])		writer.w_string	(temp);
        }
        writer.w_string			(" ");
    }
}
Ejemplo n.º 2
0
bool	CInifile::save_as( LPCSTR new_fname )
{
	// save if needed
    if (new_fname&&new_fname[0]){
        xr_free			(fName);
        fName			= xr_strdup(new_fname);
    }
    R_ASSERT			(fName&&fName[0]);
    IWriter* F			= FS.w_open_ex(fName);
    if (F){
        string512		temp,val;
        for (RootIt r_it=DATA.begin(); r_it!=DATA.end(); ++r_it)
		{
            sprintf_s		(temp,sizeof(temp),"[%s]",*(*r_it)->Name);
            F->w_string	(temp);
            for (SectCIt s_it=(*r_it)->Data.begin(); s_it!=(*r_it)->Data.end(); ++s_it)
            {
                const Item&	I = *s_it;
                if (*I.first) {
                    if (*I.second) {
                        _decorate	(val,*I.second);
#ifdef DEBUG
                        if (*I.comment) {
                            // name, value and comment
                            sprintf_s	(temp,sizeof(temp),"%8s%-32s = %-32s ;%s"," ",*I.first,val,*I.comment);
                        } else
#endif
						{
                            // only name and value
                            sprintf_s	(temp,sizeof(temp),"%8s%-32s = %-32s"," ",*I.first,val);
                        }
                    } else {
#ifdef DEBUG
                        if (*I.comment) {
                            // name and comment
                            sprintf_s(temp,sizeof(temp),"%8s%-32s = ;%s"," ",*I.first,*I.comment);
                        } else
#endif
						{
                            // only name
                            sprintf_s(temp,sizeof(temp),"%8s%-32s = "," ",*I.first);
                        }
                    }
                } else {
                    // no name, so no value
#ifdef DEBUG
                    if (*I.comment)
						sprintf_s		(temp,sizeof(temp),"%8s;%s"," ",*I.comment);
                    else
#endif
						temp[0]		= 0;
                }
                _TrimRight			(temp);
                if (temp[0])		F->w_string	(temp);
            }
            F->w_string		(" ");
        }
        FS.w_close			(F);
	    return true;
    }
    return false;
}