/*

    File: unitools.cc

    Copyright (C) 2002  Dmitry Udalov
    Email: uddm@penza.net
  
    This software 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.
    
 */

#include <time.h>
#include "unitools.h"

//delete spaces with begin and end string
void trim(char *instr, char *outstr){
        if(((instr==NULL)||(outstr==NULL))||(strlen(instr)==0))
                return;
        int res=1;
        char *str=instr;
        while(res==1){
                if(str[0]==' '){
                        str=str+1;
                        res=1;
                }
                else
                        res=0;
        }
	res=1;
        while(res==1){
                if(str[strlen(str)-1]==' '){
                        str[strlen(str)-1]='\0';
        		res=1;
                }
                else
                	res=0;
        }
	strcpy(outstr,str);
}

//convert all char at string to upper case
char* strupr(char *str){
   for(int i=0;i<strlen(str);i++){
       if((str[i]>=97)&&(str[i]<=122))
           str[i]=str[i]-32;
   }
   return str;
}

//convert all char at string to lower case
void delay(int iSec){
    time_t starttime,curtime;
    time(&starttime);
    while((time(&curtime)-starttime)<iSec);
}

char* strlwr(char *str){
   for(int i=0;i<strlen(str);i++){
       if((str[i]>=41)&&(str[i]<=90))
           str[i]=str[i]+32;
   }
   return str;
}

//add to end of string slash e.g. '/' char
char* normaldir(char *lpszFileName){
    if(strcmp(lpszFileName,"")!=0){
        if(lpszFileName[strlen(lpszFileName)-1]!='/')
            strcat(lpszFileName,"/");
    }
    return lpszFileName;
}

