~ubuntu-branches/ubuntu/precise/mm3d/precise

« back to all changes in this revision

Viewing changes to .pc/debian-changes-1.3.7-1.2ubuntu1/src/libmm3d/mm3dport.cc

  • Committer: Package Import Robot
  • Author(s): Florian Brandes
  • Date: 2011-09-26 14:02:17 UTC
  • Revision ID: package-import@ubuntu.com-20110926140217-nssj733wsx5q02jx
Tags: 1.3.7-1.2ubuntu1
* acinclude.m4
 -Fix Qt search path for x64 maschines (LP: #770975)
 -change order of Qt linker test (so it will link with ld --as-needed option in ubuntu)
 -change order of OpenGL linker test (same as above)
 -Fixed AC_SUBST( DLOPEN_LIBS) substitution, so autoreconf will run
* src/Makefile.am
 -change order of linker libraries (see above)
* debian/control
 -added dh-autoreconf as build dependency
* debian/rules
 -added dh_autoreconf
* added quilt as patch system

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Misfit Model 3D
 
2
 * 
 
3
 *  Copyright (c) 2004-2007 Kevin Worcester
 
4
 * 
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
 
18
 *  USA.
 
19
 *
 
20
 *  See the COPYING file for full license text.
 
21
 */
 
22
 
 
23
#include "mm3dport.h"
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <time.h>
 
27
#include <ctype.h>
 
28
#include <string.h>
 
29
#include <limits.h>
 
30
 
 
31
#include "config.h"
 
32
#include "log.h" // FIXME debugging
 
33
 
 
34
#ifdef HAVE_GETTIMEOFDAY
 
35
#include <sys/time.h>
 
36
#else
 
37
#include <sys/timeb.h>
 
38
#endif // HAVE_GETTIMEOFDAY
 
39
 
 
40
#include <unistd.h>
 
41
 
 
42
char * PORT_getenv( const char * name )
 
43
{
 
44
#ifdef WIN32
 
45
   return "C:/";  // TODO do registry lookup (if it's ever needed)
 
46
#else
 
47
   return getenv( name );
 
48
#endif // WIN32
 
49
}
 
50
 
 
51
int PORT_lstat( const char * filename, struct stat * buf )
 
52
{
 
53
#ifdef WIN32
 
54
   return stat( filename, buf );
 
55
#else
 
56
   return lstat( filename, buf );
 
57
#endif // WIN32
 
58
}
 
59
 
 
60
// FIXME add thorough testing for the manual part of this (the case where
 
61
// realpath fails because the directories don't exist).
 
62
char * PORT_realpath( const char * path, char * resolved_path, size_t len )
 
63
{
 
64
#ifdef WIN32
 
65
   char * rval = _fullpath( resolved_path, path, len );
 
66
#else
 
67
   char * rval = realpath( path, resolved_path );
 
68
#endif // WIN32
 
69
   if ( !rval )
 
70
   {
 
71
      if ( len > 0 )
 
72
      {
 
73
         if ( path[0] == '/' )
 
74
         {
 
75
            strncpy( resolved_path, path, len );
 
76
         }
 
77
         else
 
78
         {
 
79
            char pwd[1024];
 
80
            getcwd(pwd, sizeof(pwd));
 
81
            PORT_snprintf( resolved_path, len, "%s/%s", pwd, path );
 
82
         }
 
83
         resolved_path[ len - 1 ] = '\0';
 
84
         rval = resolved_path;
 
85
 
 
86
         // Remove "/./" and "//"
 
87
         char * end = rval + strlen(rval);
 
88
 
 
89
         char * s = rval;
 
90
         while ( (s = strstr(s, "/./")) != NULL )
 
91
         {
 
92
            memmove( s, s + 2, end - (s + 2) );
 
93
            end -= 2;
 
94
            end[0] = '\0';
 
95
         }
 
96
 
 
97
         s = rval;
 
98
         while ( (s = strstr(s, "//")) != NULL )
 
99
         {
 
100
            memmove( s, s + 1, end - (s + 1) );
 
101
            --end;
 
102
            end[0] = '\0';
 
103
         }
 
104
 
 
105
         // Remove "/../"
 
106
         s = rval;
 
107
         while ( (s = strstr(s, "/../")) != NULL )
 
108
         {
 
109
            char * lastSlash = s - 1;
 
110
            while ( lastSlash >= rval )
 
111
            {
 
112
               if ( *lastSlash != '/' )
 
113
                  --lastSlash;
 
114
               else
 
115
                  break;
 
116
            }
 
117
 
 
118
            if ( lastSlash >= rval )
 
119
            {
 
120
               int len = (end - s) - 3;
 
121
               memmove( lastSlash, s+3, len );
 
122
               end = lastSlash + len;
 
123
               end[0] = '\0';
 
124
               s = lastSlash;
 
125
            }
 
126
            else
 
127
            {
 
128
               return rval;
 
129
            }
 
130
         }
 
131
 
 
132
         //log_warning( "normalized path = '%s'\n", rval );
 
133
      }
 
134
   }
 
135
   return rval;
 
136
}
 
137
 
 
138
struct tm * PORT_localtime_r( const time_t * timep, struct tm * result )
 
139
{
 
140
#ifdef WIN32
 
141
   *result = *localtime( timep );
 
142
#else
 
143
   localtime_r( timep, result );
 
144
#endif
 
145
   return result;
 
146
}
 
147
 
 
148
void PORT_gettimeofday( PORT_timeval * tv )
 
149
{
 
150
#ifdef HAVE_GETTIMEOFDAY
 
151
   struct timeval tval;
 
152
   gettimeofday( &tval, NULL );
 
153
   tv->tv_sec  = tval.tv_sec;
 
154
   tv->tv_msec = tval.tv_usec / 1000;
 
155
#else
 
156
   struct timeb tb;
 
157
   ftime( &tb );
 
158
   tv->tv_sec = tb.time;
 
159
   tv->tv_msec = tb.millitm;
 
160
#endif // HAVE_GETTIMEOFDAY
 
161
}
 
162
 
 
163
char * PORT_asctime_r( const struct tm * tmval, char * buf )
 
164
{
 
165
#ifdef WIN32
 
166
   char *tmptmstr = asctime( tmval );
 
167
   strcpy( buf, tmptmstr );
 
168
#else
 
169
   asctime_r( tmval, buf );
 
170
#endif
 
171
   return buf;
 
172
}
 
173
 
 
174
int PORT_symlink( const char * oldpath, const char * newpath )
 
175
{
 
176
#ifdef WIN32
 
177
   return 0;
 
178
#else
 
179
   return symlink( oldpath, newpath );
 
180
#endif // WIN32
 
181
}
 
182
 
 
183
int PORT_mkdir( const char * pathname, mode_t mode )
 
184
{
 
185
#ifdef WIN32
 
186
   return mkdir( pathname );
 
187
#else
 
188
   return mkdir( pathname, mode );
 
189
#endif // WIN32
 
190
}
 
191
 
 
192
int PORT_snprintf( char * dest, size_t len, const char * fmt, ... )
 
193
{
 
194
   int rval = -1;
 
195
   if ( dest && fmt && len > 0 )
 
196
   {
 
197
      va_list args;
 
198
      va_start( args, fmt );
 
199
      rval = PORT_vsnprintf( dest, len, fmt, args );
 
200
   }
 
201
   return rval;
 
202
}
 
203
 
 
204
int PORT_vsnprintf( char * dest, size_t len, const char * fmt, va_list args )
 
205
{
 
206
   int rval = -1;
 
207
   if ( dest && fmt && len > 0 )
 
208
   {
 
209
      rval = vsnprintf( dest, len, fmt, args );
 
210
      dest[ len - 1 ] = '\0';
 
211
   }
 
212
   return rval;
 
213
}
 
214
 
 
215
#ifdef WIN32
 
216
char * PORT_strcasestr( const char * haystack, const char * needle )
 
217
{
 
218
   bool match;
 
219
 
 
220
   size_t hlen = strlen( haystack );
 
221
   size_t nlen = strlen( needle );
 
222
 
 
223
   match = false;
 
224
 
 
225
   size_t i;
 
226
   size_t j;
 
227
 
 
228
   for ( i = 0; !match && i < hlen - nlen; i++ )
 
229
   {
 
230
      match = true;
 
231
      for ( j = 0; match && j < nlen; j++ )
 
232
      {
 
233
         if ( toupper(haystack[i+j]) != toupper(needle[j]) ) 
 
234
         {
 
235
            match = false;
 
236
         }
 
237
      }
 
238
   }
 
239
 
 
240
   if ( match )
 
241
   {
 
242
      return (char *) &haystack[i];
 
243
   }
 
244
   else
 
245
   {
 
246
      return NULL;
 
247
   }
 
248
}
 
249
#else
 
250
char * PORT_strcasestr( const char * haystack, const char * needle )
 
251
{
 
252
   return strcasestr( haystack, needle );
 
253
}
 
254
#endif // WIN32
 
255
 
 
256
char * PORT_basename( const char * path )
 
257
{
 
258
   static char rval[ PATH_MAX ] = "";
 
259
   if ( path )
 
260
   {
 
261
      char * start = strrchr( path, '/' );
 
262
 
 
263
      if ( !start )
 
264
      {
 
265
         // no forward slash, try backslash
 
266
         start = strrchr( path, '\\' );
 
267
      }
 
268
 
 
269
      if ( start )
 
270
      {
 
271
         start++;
 
272
         strncpy( rval, start, PATH_MAX );
 
273
         rval[ PATH_MAX - 1 ] = '\0';
 
274
         return rval;
 
275
      }
 
276
 
 
277
      // no directory, just filename
 
278
      strncpy( rval, path, PATH_MAX );
 
279
      rval[ PATH_MAX - 1 ] = '\0';
 
280
      return rval;
 
281
   }
 
282
 
 
283
   // path not set
 
284
   rval[0] = '\0';
 
285
   return rval;
 
286
}
 
287
 
 
288
char * PORT_dirname( const char * path )
 
289
{
 
290
   static char rval[ PATH_MAX ] = "";
 
291
   if ( path )
 
292
   {
 
293
      strncpy( rval, path, PATH_MAX );
 
294
      rval[ PATH_MAX - 1 ] = '\0';
 
295
 
 
296
      char * end = strrchr( rval, '/' );
 
297
 
 
298
      if ( !end )
 
299
      {
 
300
         // no forward slash, try backslash
 
301
         end = strrchr( rval, '\\' );
 
302
      }
 
303
 
 
304
      if ( end )
 
305
      {
 
306
         if ( end == rval )
 
307
            end[1] = '\0';
 
308
         else
 
309
            end[0] = '\0';
 
310
         return rval;
 
311
      }
 
312
   }
 
313
 
 
314
   // path not set, or no slash character
 
315
   strcpy( rval, "." );
 
316
   return rval;
 
317
}
 
318