"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.60/util.h" (6 Nov 2019, 4515 Bytes) of package /linux/misc/asymptote-2.60.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "util.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.53_vs_2.54.

    1 /*****
    2  * util.h
    3  * Andy Hammerlindl 2004/05/10
    4  *
    5  * A place for useful utility functions.
    6  *****/
    7 
    8 #ifndef UTIL_H
    9 #define UTIL_H
   10 
   11 #include <sys/types.h>
   12 #include <iostream>
   13 #include <cstdlib>
   14 
   15 #ifdef __CYGWIN__
   16 extern "C" int sigaddset(sigset_t *set, int signum);
   17 extern "C" int sigemptyset(sigset_t *set); 
   18 extern "C" int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
   19 #endif
   20 
   21 #include <csignal>
   22 
   23 #include "common.h"
   24 
   25 #include <strings.h>
   26 
   27 // Demangle a typeid name (if the proper library is installed.
   28 string demangle(const char *s);
   29 
   30 // Duplicate a string.
   31 char *Strdup(string s);
   32 char *StrdupNoGC(string s);
   33 char *StrdupMalloc(string s);
   34   
   35 // Strip the directory from a filename.
   36 string stripDir(string name);
   37   
   38 // Strip the file from a filename, returning the directory.
   39 string stripFile(string name);
   40 
   41 // Strip the extension from a filename.
   42 string stripExt(string name, const string& suffix="");
   43 
   44 void writeDisabled();
   45   
   46 // Replace spaces in file part of name with underscores.
   47 string cleanpath(string name);
   48 
   49 // Construct the full output path.
   50 string outpath(string name);
   51   
   52 // Construct a filename from the original, adding aux at the end, and
   53 // changing the suffix.
   54 string buildname(string filename, string suffix="", string aux="");
   55 
   56 // Construct an alternate filename for a temporary file in the current
   57 // directory.
   58 string auxname(string filename, string suffix="");
   59 
   60 // Cast argument to a string.
   61 template<class T>
   62 string String(T x)
   63 {
   64   ostringstream buf;
   65   buf << x;
   66   return buf.str();
   67 }
   68 
   69 typedef void (*sighandler_t)(int);
   70 
   71 // Portable signal (sigaction wrapper).
   72 sighandler_t Signal(int signum, sighandler_t handler);
   73 
   74 // Split string S and push the pieces onto vector a.
   75 void push_split(mem::vector<string>& a, const string& S);
   76   
   77 // Wrapper to append /c start "" to MSDOS cmd.
   78 void push_command(mem::vector<string>& a, const string& s);
   79   
   80 // Return an argv array corresponding to the fields in command delimited
   81 // by spaces not within matching single quotes.
   82 char **args(const mem::vector<string> &args, bool quiet=false);
   83   
   84 // Similar to the standard system call except allows interrupts and does
   85 // not invoke a shell.
   86 int System(const mem::vector<string> &command, int quiet=0, bool wait=true,
   87            const char *hint=NULL, const char *application="",
   88            int *pid=NULL);
   89 
   90 #if defined(__DECCXX_LIBCXX_RH70)
   91 extern "C" char *strsignal(int sig);
   92 extern "C" double asinh(double x);
   93 extern "C" double acosh(double x);
   94 extern "C" double atanh(double x);
   95 extern "C" double cbrt(double x);
   96 extern "C" double erf(double x);
   97 extern "C" double erfc(double x);
   98 extern "C" double lgamma(double x);
   99 extern "C" double remainder(double x, double y);
  100 extern "C" double hypot(double x, double y) throw();
  101 extern "C" double jn(Int n, double x);
  102 extern "C" double yn(Int n, double x);
  103 extern "C" int isnan(double);
  104 #endif
  105 
  106 
  107 #if defined(__DECCXX_LIBCXX_RH70) || defined(__CYGWIN__)
  108 extern "C" int usleep(useconds_t);
  109 extern "C" int kill(pid_t pid, int sig) throw();
  110 extern "C" int snprintf(char *str, size_t size, const char *format,...);
  111 #include <stdio.h>
  112 extern "C" FILE *fdopen(int fd, const char *mode);
  113 extern "C" int fileno(FILE *);
  114 extern "C" char *strptime(const char *s, const char *format, struct tm *tm);
  115 extern "C" int setenv(const char *name, const char *value, int overwrite);
  116 extern "C" int unsetenv(const char *name);
  117 #endif
  118 
  119 extern bool False;
  120 
  121 // Strip blank lines (which would break the bidirectional TeX pipe)
  122 string stripblanklines(const string& s);
  123 
  124 const char *startPath();
  125 const char* setPath(const char *s, bool quiet=false);
  126 const char *changeDirectory(const char *s);
  127 extern char *startpath;
  128 
  129 void backslashToSlash(string& s);
  130 void spaceToUnderscore(string& s);
  131 string Getenv(const char *name, bool msdos);
  132 char *getPath(char *p=NULL);
  133 
  134 void execError(const char *command, const char *hint, const char *application);
  135   
  136 // This invokes a viewer to display the manual.  Subsequent calls will only
  137 // pop-up a new viewer if the old one has been closed.
  138 void popupHelp();
  139 
  140 #ifdef __CYGWIN__
  141 inline long long llabs(long long x) {return x >= 0 ? x : -x;}
  142 extern "C" char *initstate (unsigned seed, char *state, size_t size);
  143 extern "C" long random (void);
  144 #endif  
  145 
  146 inline Int Abs(Int x) {
  147 #ifdef HAVE_LONG_LONG
  148   return llabs(x);
  149 #else
  150 #ifdef HAVE_LONG
  151   return labs(x);
  152 #else
  153   return abs(x);
  154 #endif
  155 #endif
  156 }
  157 
  158 unsigned unsignedcast(Int n);
  159 unsignedInt unsignedIntcast(Int n);
  160 int intcast(Int n);
  161 Int Intcast(unsignedInt n);
  162 
  163 #endif