1999-10-02 16:21:10 +00:00
|
|
|
// -*- C++ -*-
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* \file lyxlib.h
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-05-30 02:24:33 +00:00
|
|
|
* A selection of useful system functions made
|
|
|
|
* handy for C++ usage.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-05-30 02:24:33 +00:00
|
|
|
* \author unknown
|
|
|
|
*/
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
#ifndef LYX_LIB_H
|
|
|
|
#define LYX_LIB_H
|
|
|
|
|
|
|
|
#include "LString.h"
|
|
|
|
|
2000-01-17 22:42:04 +00:00
|
|
|
namespace lyx {
|
2000-10-20 13:13:38 +00:00
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// get the current working directory
|
2001-03-15 18:21:56 +00:00
|
|
|
string const getcwd();
|
2002-05-30 02:24:33 +00:00
|
|
|
/// change to a directory, 0 is returned on success.
|
2001-03-15 18:21:56 +00:00
|
|
|
int chdir(string const & name);
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* rename a file, returns false if it fails.
|
|
|
|
* It can handle renames across partitions.
|
|
|
|
*/
|
2001-03-15 18:21:56 +00:00
|
|
|
bool rename(string const & from, string const & to);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// copy a file, returns false it it fails
|
2001-03-15 18:21:56 +00:00
|
|
|
bool copy(string const & from, string const & to);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// generates a checksum of a file
|
2001-03-15 18:21:56 +00:00
|
|
|
unsigned long sum(string const & file);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// FIXME: some point to this hmm ?
|
2001-03-15 18:21:56 +00:00
|
|
|
int kill(int pid, int sig);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// FIXME: same here
|
2001-03-15 18:21:56 +00:00
|
|
|
void abort();
|
2002-05-30 02:24:33 +00:00
|
|
|
/// create the given directory with the given mode
|
2001-03-15 18:21:56 +00:00
|
|
|
int mkdir(string const & pathname, unsigned long int mode);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// put a C string into the environment
|
2001-03-15 18:21:56 +00:00
|
|
|
int putenv(char const * str);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// unlink the given file
|
2001-03-15 18:21:56 +00:00
|
|
|
int unlink(string const & file);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// remove the given directory
|
2001-03-15 18:21:56 +00:00
|
|
|
int rmdir(string const & file);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// convert the given string to an integer
|
2001-03-15 18:21:56 +00:00
|
|
|
int atoi(string const & nstr);
|
2002-05-30 02:24:33 +00:00
|
|
|
/// (securely) create a temporary file in the given dir with the given prefix
|
2001-03-15 18:21:56 +00:00
|
|
|
string const tempName(string const & dir = string(),
|
|
|
|
string const & mask = string());
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* Returns true if var is approximately equal to number with allowed error
|
2001-07-28 12:24:16 +00:00
|
|
|
* of 'error'.
|
|
|
|
*
|
|
|
|
* Usage: if (float_equal(var, number, 0.0001)) { }
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2001-07-28 12:24:16 +00:00
|
|
|
* This will check if 'var' is approx. equal to 'number' with error of 1/1000
|
|
|
|
*/
|
|
|
|
inline bool float_equal(float var, float number, float error)
|
|
|
|
{
|
|
|
|
return (number - error <= var && var <= number + error);
|
|
|
|
}
|
|
|
|
|
2001-03-15 18:21:56 +00:00
|
|
|
} // namespace lyx
|
2002-05-30 02:24:33 +00:00
|
|
|
|
2000-10-20 13:13:38 +00:00
|
|
|
#endif /* LYX_LIB_H */
|