summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/util.h
blob: 145f9717faf05062180b220661dc31b4324c0de1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*****
 * util.h
 * Andy Hammerlindl 2004/05/10
 *
 * A place for useful utility functions.
 *****/

#ifndef UTIL_H
#define UTIL_H

#include <sys/types.h>
#include <iostream>
#include <cstdlib>

#include "common.h"

#include <strings.h>

// Duplicate a string.
char *Strdup(string s);
char *StrdupNoGC(string s);
char *StrdupMalloc(string s);
  
// Strip the directory from a filename.
string stripDir(string name);
  
// Strip the file from a filename, returning the directory.
string stripFile(string name);

// Like stripTeXFile except return "" for context TeX engine.
string stripTeXFile(string name);

// Strip the extension from a filename.
string stripExt(string name, const string& suffix="");
  
void writeDisabled();
  
// Check if global writes are disabled and name contains a directory.
void checkLocal(string name);
  
// Construct a filename from the original, adding aux at the end, and
// changing the suffix.
string buildname(string filename, string suffix="", string aux="");

// Construct an alternate filename for a temporary file in the current
// directory.
string auxname(string filename, string suffix="");

// Return an argv array corresponding to the fields in command delimited
// by spaces not within matching single quotes.
char **args(const char *command, bool quiet=false);
  
// Similar to the standard system call except allows interrupts and does
// not invoke a shell.
int System(const char *command, int quiet=0, bool wait=true,
           const char *hint=NULL, const char *application="",
           int *pid=NULL);
int System(const ostringstream& command, int quiet=0, bool wait=true,
           const char *hint=NULL, const char *application="",
           int *pid=NULL); 
  
#if defined(__DECCXX_LIBCXX_RH70)
extern "C" int kill(pid_t pid, Int sig) throw();
extern "C" char *strsignal(Int sig);
extern "C" double asinh(double x);
extern "C" double acosh(double x);
extern "C" double atanh(double x);
extern "C" double cbrt(double x);
extern "C" double erf(double x);
extern "C" double erfc(double x);
extern "C" double tgamma(double x);
extern "C" double remainder(double x, double y);
extern "C" double hypot(double x, double y) throw();
extern "C" double jn(Int n, double x);
extern "C" double yn(Int n, double x);
#endif

#if defined(__mips)
extern "C" double tgamma(double x);
#endif

#if defined(__DECCXX_LIBCXX_RH70) || defined(__CYGWIN__)
extern "C" int snprintf(char *str, size_t size, const char *format,...);
extern "C" int fileno(FILE *);
extern "C" char *strptime(const char *s, const char *format, struct tm *tm);
extern "C" int setenv(const char *name, const char *value, int overwrite);
#endif

extern bool False;

// Strip blank lines (which would break the bidirectional TeX pipe)
string stripblanklines(const string& s);

extern char *currentpath;

const char *startPath();
const char* setPath(const char *s, bool quiet=false);
const char *changeDirectory(const char *s);
extern char *startpath;

void backslashToSlash(string& s);
void spaceToUnderscore(string& s);
string Getenv(const char *name, bool msdos);
char *getPath(char *p=NULL);

void execError(const char *command, const char *hint, const char *application);
  
// This invokes a viewer to display the manual.  Subsequent calls will only
// pop-up a new viewer if the old one has been closed.
void popupHelp();

inline Int Abs(Int x) {
#ifdef HAVE_LONG_LONG
  return llabs(x);
#else
#ifdef HAVE_LONG
  return labs(x);
#else
  return abs(x);
#endif
#endif
}

unsigned unsignedcast(Int n);
int intcast(Int n);
  
#endif