1 /*$Id: l_lib.h,v 26.81 2008/05/27 05:34:00 al Exp $ -*- C++ -*-
2  * Copyright (C) 2001 Albert Davis
3  * Author: Albert Davis <aldavis@gnu.org>
4  *
5  * This file is part of "Gnucap", the Gnu Circuit Analysis Package
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  */
22 //testing=script 2006.07.13
23 #ifndef L_LIB_H
24 #define L_LIB_H
25 #include "md.h"
26 /*--------------------------------------------------------------------------*/
27 	  char*		trim(char*);
28 INTERFACE bool		Umatch(const std::string&, const std::string&);
29 INTERFACE bool		wmatch(const std::string& s1,const std::string& s2);
30 INTERFACE std::string	to_string(unsigned);
31 INTERFACE std::string	to_string(int);
32 INTERFACE std::string	to_string(double);
33 INTERFACE char*		ftos(double,int,int,int);
34 /*--------------------------------------------------------------------------*/
35 //ftos stuff
36 enum {			/* formatting bit-fields */
37   ftos_DEFAULT = 0,	/* default formatting, with letters */
38   ftos_EXP = 1,		/* use 'e' notation, almost like printf */
39   ftos_SIGN = 2,	/* always include sign */
40   ftos_FILL = 4		/* fill in trailing zeros */
41 };
42 /*--------------------------------------------------------------------------*/
43 // wrappers for old standard C lpbrary
44 namespace OS {
system(const std::string & s)45   inline void system(const std::string& s) {itested();
46     ::system(s.c_str());
47   }
48 
chdir(const std::string & s)49   inline void chdir(const std::string& s) {itested();
50     ::chdir(s.c_str());
51   }
52 
remove(const std::string & s)53   inline void remove(const std::string& s) {itested();
54     ::remove(s.c_str());
55   }
56 
access_ok(const std::string & file,int mode)57   inline bool access_ok(const std::string& file, int mode) {
58     return (::access(file.c_str(), mode) == 0/*file_ok*/);
59   }
60 
getcwd()61   inline std::string getcwd() {itested();
62     char buf[BUFLEN+1];
63     char* cwd = ::getcwd(buf,BUFLEN);
64     if (cwd) {itested();
65       return cwd;
66     }else{untested();
67       return "";
68     }
69   }
70 
getenv(const std::string & s)71   inline std::string getenv(const std::string& s) {
72     char* ev = ::getenv(s.c_str());
73     if (ev) {
74       return ev;
75     }else{itested();
76       return "";
77     }
78   }
79 };
80 /*--------------------------------------------------------------------------*/
81 /*--------------------------------------------------------------------------*/
82 #endif
83