00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if defined( __MINGW32__) || defined (WIN32)
00024
00025
00026 #include <windows.h>
00027 #include "math.h"
00028
00029 #ifdef _MBCS
00030 bool chdir(const char* path)
00031 {
00032 return !SetCurrentDirectory(path);
00033 }
00034
00035 int mkdir(const char* path, unsigned int attribute)
00036 {
00037 return CreateDirectory(path,NULL);
00038 }
00039
00040 char* getcwd(char* str, unsigned int size)
00041 {
00042 GetCurrentDirectory(size, str);
00043 return str;
00044 }
00045 void getFaustPathname(char* str, unsigned int size)
00046 {
00047 GetModuleFileName(NULL, str, size);
00048 }
00049 #else
00050 bool chdir(const char* path)
00051 {
00052 wchar_t wstr[2048];
00053 mbstowcs(wstr,path,2048);
00054 return !SetCurrentDirectory(wstr);
00055 }
00056
00057 int mkdir(const char* path, unsigned int attribute)
00058 {
00059 wchar_t wstr[2048];
00060 mbstowcs(wstr,path,2048);
00061 return CreateDirectory(wstr,NULL);
00062 }
00063
00064 char* getcwd(char* str, unsigned int size)
00065 {
00066 wchar_t wstr[2048];
00067 GetCurrentDirectory(2048, wstr);
00068 wcstombs(str,wstr,size);
00069 return str;
00070 }
00071
00072 void getFaustPathname(char* str, unsigned int size)
00073 {
00074 wchar_t wstr[2048];
00075 GetModuleFileName(NULL, wstr, 2048);
00076 wcstombs(str,wstr,size);
00077 }
00078
00079 #endif
00080
00081 int isatty(int file)
00082 {
00083 return 0;
00084 }
00085
00086 #if !defined(__MINGW32__)
00087
00088 typedef union
00089 {
00090 double value;
00091 struct
00092 {
00093 unsigned int lsw;
00094 unsigned int msw;
00095 } parts;
00096 } ieee_double_shape_type;
00097
00098
00099 #define EXTRACT_WORDS(ix0,ix1,d) \
00100 do { \
00101 ieee_double_shape_type ew_u; \
00102 ew_u.value = (d); \
00103 (ix0) = ew_u.parts.msw; \
00104 (ix1) = ew_u.parts.lsw; \
00105 } while (0)
00106
00107
00108
00109 #define GET_HIGH_WORD(i,d) \
00110 do { \
00111 ieee_double_shape_type gh_u; \
00112 gh_u.value = (d); \
00113 (i) = gh_u.parts.msw; \
00114 } while (0)
00115
00116
00117
00118 #define GET_LOW_WORD(i,d) \
00119 do { \
00120 ieee_double_shape_type gl_u; \
00121 gl_u.value = (d); \
00122 (i) = gl_u.parts.lsw; \
00123 } while (0)
00124
00125 #define SET_HIGH_WORD(d,v) \
00126 do { \
00127 ieee_double_shape_type sh_u; \
00128 sh_u.value = (d); \
00129 sh_u.parts.msw = (v); \
00130 (d) = sh_u.value; \
00131 } while (0)
00132
00133 double remainder(double x, double p)
00134 {
00135 int hx,hp;
00136 unsigned int sx,lx,lp;
00137 double p_half;
00138
00139 EXTRACT_WORDS(hx,lx,x);
00140 EXTRACT_WORDS(hp,lp,p);
00141 sx = hx&0x80000000;
00142 hp &= 0x7fffffff;
00143 hx &= 0x7fffffff;
00144
00145
00146 if((hp|lp)==0) return (x*p)/(x*p);
00147 if((hx>=0x7ff00000)||
00148 ((hp>=0x7ff00000)&&
00149 (((hp-0x7ff00000)|lp)!=0)))
00150 return (x*p)/(x*p);
00151
00152
00153 static const double zero = 0.0;
00154 if (hp<=0x7fdfffff) x = fmod(x,p+p);
00155 if (((hx-hp)|(lx-lp))==0) return zero*x;
00156 x = fabs(x);
00157 p = fabs(p);
00158 if (hp<0x00200000) {
00159 if(x+x>p) {
00160 x-=p;
00161 if(x+x>=p) x -= p;
00162 }
00163 } else {
00164 p_half = 0.5*p;
00165 if(x>p_half) {
00166 x-=p;
00167 if(x>=p_half) x -= p;
00168 }
00169 }
00170 GET_HIGH_WORD(hx,x);
00171 SET_HIGH_WORD(x,hx^sx);
00172 return x;
00173 }
00174 #endif
00175 char* dirname(char *path)
00176 {
00177 return path;
00178 }
00179
00180 #else // Linux
00181
00182 #include <stdlib.h>
00183 #include <string.h>
00184 void getFaustPathname(char* str, unsigned int size)
00185 {
00186 char* path = getenv("_");
00187 if (path) {
00188 strncpy(str, path, size);
00189 } else {
00190
00191 strncpy(str, "/usr/local/bin/faust", size);
00192 }
00193 }
00194
00195 #endif
00196
00197