/***************************** Global.cpp **********************************
 *   Copyright (C) 2004 by Sébastien SIVERA & Sevin Roland                 *
 *   upsis@club-internet.fr                                                *
 *                                                                         *
 *   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.             *
 ***************************************************************************/

//=============================================== INCLUDES ============================================================
#include "Global.h"
#include <qfile.h> 


#include <qmessagebox.h> 
#include "../../MedinTuxTools/CGestIni.h"


//---------------------------------- SaveString ---------------------------------------------------------------------------------
void SaveString(QString path, QString &str, const char* ext   /* = ".txt" */)
{
 QFile qfile(path);
 if (qfile.open(IO_ReadWrite)==FALSE)
    {QMessageBox::critical (0, "Sauver un fichier", 
	                       "Le fichier n'a pu etre ouvert", 
	                      QMessageBox::Abort, QMessageBox::NoButton, QMessageBox::NoButton );        
    }
  else if (str !="")
    {qfile.remove();
     int pos = path.findRev(".");
     if (pos==-1) 
        {path += ext;
	}
     else
        {path = path.left(pos)+ ext;
	}
        
     qfile.setName (path);
     if (qfile.open(IO_WriteOnly)==FALSE)
        {QMessageBox::critical (0, "Sauver un fichier", 
	                           "Le fichier n'a pu etre reouvert", 
	                           QMessageBox::Abort, QMessageBox::NoButton, QMessageBox::NoButton ); 
        }
     else
        {qfile.writeBlock (str, str.length()); 
         qfile.close();         
        } 
     }
  else
     {qfile.close();
     }
}

//------------------------------ GotoNextDebLigne -----------------------------------------
char *GotoNextDebLigne(const char* txt)
{char *pt  = (char*) txt; 
 while (*pt)
    {if      ( pt [0]=='\\'&& pt [1] !=0)            (pt+=2);
     else if ( pt [0]=='\r'&& pt [1] =='\n')  return (pt+=2);
     else if ( pt [0]=='\n'&& pt [1] =='\r')  return (pt+=2);
     else if ( pt [0]=='\n'|| pt [0] =='\r')  return (pt+1);
     else ++pt;
    }
 return pt;
}

//------------------------------ GotoEndOfLigne -----------------------------------------
char *GotoEndOfLigne(const char* txt)
{char *pt  = (char*) txt; 
 while (*pt)
    {if      ( pt [0]=='\\'&& pt [1] !=0)            (pt+=2);
     else if ( pt [0]=='\r'&& pt [1] =='\n')  return pt;
     else if ( pt [0]=='\n'&& pt [1] =='\r')  return pt;
     else if ( pt [0]=='\n'|| pt [0] =='\r')  return pt;
     else ++pt;
    }
 return pt;
}

//------------------------------ GotoNextSignifiant -----------------------------------------
char *GotoNextSignifiant(const char* txt)
{char *pt  = (char*) txt; 
 while (*pt && (*pt==' ' || *pt=='\t'))
    {++pt;
    } 
 return pt;
}
