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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>common.cpp</h1><a href="common_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026 <font class="preprocessor">#include "<a class="code" href="stdmisc_8h.html">stdmisc.h</a>"</font>
00027
00028 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00029 <font class="preprocessor"></font><font class="preprocessor">#include <windows.h></font>
00030 <font class="preprocessor">#elif defined NL_OS_UNIX</font>
00031 <font class="preprocessor"></font><font class="preprocessor">#include <<a class="code" href="unistd_8h.html">unistd.h</a>></font>
00032 <font class="preprocessor">#include <string.h></font>
00033 <font class="preprocessor">#include <errno.h></font>
00034 <font class="preprocessor">#endif</font>
00035 <font class="preprocessor"></font>
00036 <font class="preprocessor">#include "<a class="code" href="command_8h.html">nel/misc/command.h</a>"</font>
00037
00038 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00039
00040 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00041 <font class="preprocessor"></font><font class="preprocessor"># ifdef __STL_DEBUG</font>
00042 <font class="preprocessor"></font><font class="preprocessor"># define STL_MODE "debug"</font>
00043 <font class="preprocessor"></font><font class="preprocessor"># else</font>
00044 <font class="preprocessor"></font><font class="preprocessor"># define STL_MODE "normal"</font>
00045 <font class="preprocessor"></font><font class="preprocessor"># endif // __STL_DEBUG</font>
00046 <font class="preprocessor"></font><font class="preprocessor"># if(__SGI_STL_PORT < 0x400)</font>
00047 <font class="preprocessor"></font><font class="preprocessor"># define STL_STR_VER "< 4.0"</font>
00048 <font class="preprocessor"></font><font class="preprocessor"># elif(__SGI_STL_PORT == 0x400)</font>
00049 <font class="preprocessor"></font><font class="preprocessor"># define STL_STR_VER "4.0"</font>
00050 <font class="preprocessor"></font><font class="preprocessor"># elif(__SGI_STL_PORT == 0x450)</font>
00051 <font class="preprocessor"></font><font class="preprocessor"># define STL_STR_VER "4.5"</font>
00052 <font class="preprocessor"></font><font class="preprocessor"># elif(__SGI_STL_PORT > 0x450)</font>
00053 <font class="preprocessor"></font><font class="preprocessor"># define STL_STR_VER "> 4.5"</font>
00054 <font class="preprocessor"></font><font class="preprocessor"># endif // __SGI_STL_PORT</font>
00055 <font class="preprocessor"></font><font class="preprocessor"># pragma message("Using STLport version "STL_STR_VER" in "STL_MODE" mode")</font>
00056 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00057 <font class="preprocessor"></font>
00058 <font class="keyword">namespace </font>NLMISC
00059 {
00060
00061 <font class="comment">/*</font>
00062 <font class="comment"> * Portable Sleep() function that suspends the execution of the calling thread for a number of milliseconds.</font>
00063 <font class="comment"> * Note: the resolution of the timer is system-dependant and may be more than 1 millisecond.</font>
00064 <font class="comment"> */</font>
00065 <font class="keywordtype">void</font> <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a>( uint32 ms )
00066 {
00067 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00068 <font class="preprocessor"></font>
00070 <font class="preprocessor">#ifdef NL_DEBUG</font>
00071 <font class="preprocessor"></font> ms = max(ms, (uint32)1);
00072 <font class="preprocessor">#endif</font>
00073 <font class="preprocessor"></font>
00074 Sleep( ms );
00075
00076 <font class="preprocessor">#elif defined NL_OS_UNIX</font>
00077 <font class="preprocessor"></font> usleep( ms*1000 );
00078 <font class="preprocessor">#endif</font>
00079 <font class="preprocessor"></font>}
00080
00081
00082 <font class="comment">/*</font>
00083 <font class="comment"> * Returns Thread Id (note: on Linux, Process Id is the same as the Thread Id)</font>
00084 <font class="comment"> */</font>
00085 uint <a class="code" href="namespaceNLMISC.html#a237">getThreadId</a>()
00086 {
00087 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00088 <font class="preprocessor"></font> <font class="keywordflow">return</font> GetCurrentThreadId();
00089 <font class="preprocessor">#elif defined NL_OS_UNIX</font>
00090 <font class="preprocessor"></font> <font class="keywordflow">return</font> getpid();
00091 <font class="preprocessor">#endif</font>
00092 <font class="preprocessor"></font>
00093 }
00094
00095
00096 <font class="comment">/*</font>
00097 <font class="comment"> * Returns a readable string from a vector of bytes. '\0' are replaced by ' '</font>
00098 <font class="comment"> */</font>
00099 string <a class="code" href="namespaceNLMISC.html#a238">stringFromVector</a>( <font class="keyword">const</font> vector<uint8>& <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, <font class="keywordtype">bool</font> limited )
00100 {
00101 string <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00102
00103 <font class="keywordflow">if</font> (!<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.empty())
00104 {
00105 <font class="keywordtype">int</font> size = <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.size ();
00106 <font class="keywordflow">if</font> (limited && size > 1000)
00107 {
00108 string middle = <font class="stringliteral">"...<buf too big,skip middle part>..."</font>;
00109 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.resize (1000 + middle.size());
00110 memcpy (&*<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.begin(), &*<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.begin(), 500);
00111 memcpy (&*<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.begin()+500, &*middle.begin(), middle.size());
00112 memcpy (&*<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.begin()+500+middle.size(), &*<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.begin()+size-500, 500);
00113 }
00114 <font class="keywordflow">else</font>
00115 {
00116 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.resize (size);
00117 memcpy( &*<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.begin(), &*<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.begin(), <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.size() );
00118 }
00119
00120 <font class="comment">// Replace '\0' characters</font>
00121 string::iterator is;
00122 <font class="keywordflow">for</font> ( is=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.begin(); is!=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>.end(); ++is )
00123 {
00124 <font class="comment">// remplace non printable char and % with '?' chat</font>
00125 <font class="keywordflow">if</font> ( ! isprint((uint8)(*is)) || (*is) == <font class="charliteral">'%'</font>)
00126 {
00127 (*is) = <font class="charliteral">'?'</font>;
00128 }
00129 }
00130 }
00131 <font class="comment">/*</font>
00132 <font class="comment"> if ( ! v.empty() )</font>
00133 <font class="comment"> {</font>
00134 <font class="comment"> // Copy contents</font>
00135 <font class="comment"> s.resize( v.size() );</font>
00136 <font class="comment"> memcpy( &*s.begin(), &*v.begin(), v.size() );</font>
00137 <font class="comment"></font>
00138 <font class="comment"> // Replace '\0' characters</font>
00139 <font class="comment"> string::iterator is;</font>
00140 <font class="comment"> for ( is=s.begin(); is!=s.end(); ++is )</font>
00141 <font class="comment"> {</font>
00142 <font class="comment"> // remplace non printable char and % with '?' chat</font>
00143 <font class="comment"> if ( ! isprint((*is)) || (*is) == '%')</font>
00144 <font class="comment"> {</font>
00145 <font class="comment"> (*is) = '?';</font>
00146 <font class="comment"> }</font>
00147 <font class="comment"> }</font>
00148 <font class="comment"> }</font>
00149 <font class="comment">*/</font> <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00150 }
00151
00152
00153 sint <a class="code" href="namespaceNLMISC.html#a211">smprintf</a>( <font class="keywordtype">char</font> *buffer, size_t count, <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ... )
00154 {
00155 sint ret;
00156
00157 va_list args;
00158 va_start( args, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a> );
00159 ret = vsnprintf( buffer, count, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, args );
00160 <font class="keywordflow">if</font> ( ret == -1 )
00161 {
00162 buffer[count-1] = <font class="charliteral">'\0'</font>;
00163 }
00164 va_end( args );
00165
00166 <font class="keywordflow">return</font>( ret );
00167 }
00168
00169
00170 sint64 <a class="code" href="namespaceNLMISC.html#a239">atoiInt64</a> (<font class="keyword">const</font> <font class="keywordtype">char</font> *ident, sint64 base)
00171 {
00172 sint64 number = 0;
00173 <font class="keywordtype">bool</font> neg = <font class="keyword">false</font>;
00174
00175 <font class="comment">// NULL string</font>
00176 <a class="code" href="debug_8h.html#a6">nlassert</a> (ident != NULL);
00177
00178 <font class="comment">// empty string</font>
00179 <font class="keywordflow">if</font> (*ident == <font class="charliteral">'\0'</font>) <font class="keywordflow">goto</font> end;
00180
00181 <font class="comment">// + sign</font>
00182 <font class="keywordflow">if</font> (*ident == <font class="charliteral">'+'</font>) ident++;
00183
00184 <font class="comment">// - sign</font>
00185 <font class="keywordflow">if</font> (*ident == <font class="charliteral">'-'</font>) { neg = <font class="keyword">true</font>; ident++; }
00186
00187 <font class="keywordflow">while</font> (*ident != <font class="charliteral">'\0'</font>)
00188 {
00189 <font class="keywordflow">if</font> (isdigit(*ident))
00190 {
00191 number *= base;
00192 number += (*ident)-<font class="charliteral">'0'</font>;
00193 }
00194 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (base > 10 && islower(*ident))
00195 {
00196 number *= base;
00197 number += (*ident)-<font class="charliteral">'a'</font>+10;
00198 }
00199 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (base > 10 && isupper(*ident))
00200 {
00201 number *= base;
00202 number += (*ident)-<font class="charliteral">'A'</font>+10;
00203 }
00204 <font class="keywordflow">else</font>
00205 {
00206 <font class="keywordflow">goto</font> end;
00207 }
00208 ident++;
00209 }
00210 end:
00211 <font class="keywordflow">if</font> (neg) number = -number;
00212 <font class="keywordflow">return</font> number;
00213
00215 <font class="comment">/* uint64 k = 0;</font>
00216 <font class="comment"></font>
00217 <font class="comment"> while (*ident != '\0')</font>
00218 <font class="comment"> {</font>
00219 <font class="comment"> switch(*(ident++))</font>
00220 <font class="comment"> {</font>
00221 <font class="comment"> case '0':</font>
00222 <font class="comment"> k +=0;</font>
00223 <font class="comment"> break;</font>
00224 <font class="comment"> case '1':</font>
00225 <font class="comment"> k +=1;</font>
00226 <font class="comment"> break;</font>
00227 <font class="comment"> case '2':</font>
00228 <font class="comment"> k +=2;</font>
00229 <font class="comment"> break;</font>
00230 <font class="comment"> case '3':</font>
00231 <font class="comment"> k +=3;</font>
00232 <font class="comment"> break;</font>
00233 <font class="comment"> case '4':</font>
00234 <font class="comment"> k +=4;</font>
00235 <font class="comment"> break;</font>
00236 <font class="comment"> case '5':</font>
00237 <font class="comment"> k +=5;</font>
00238 <font class="comment"> break;</font>
00239 <font class="comment"> case '6':</font>
00240 <font class="comment"> k +=6;</font>
00241 <font class="comment"> break;</font>
00242 <font class="comment"> case '7':</font>
00243 <font class="comment"> k +=7;</font>
00244 <font class="comment"> break;</font>
00245 <font class="comment"> case '8':</font>
00246 <font class="comment"> k +=8;</font>
00247 <font class="comment"> break;</font>
00248 <font class="comment"> case '9':</font>
00249 <font class="comment"> k +=9;</font>
00250 <font class="comment"> break;</font>
00251 <font class="comment"> case 'a':</font>
00252 <font class="comment"> k +=10;</font>
00253 <font class="comment"> break;</font>
00254 <font class="comment"> case 'b':</font>
00255 <font class="comment"> k +=11;</font>
00256 <font class="comment"> break;</font>
00257 <font class="comment"> case 'c':</font>
00258 <font class="comment"> k +=12;</font>
00259 <font class="comment"> break;</font>
00260 <font class="comment"> case 'd':</font>
00261 <font class="comment"> k +=13;</font>
00262 <font class="comment"> break;</font>
00263 <font class="comment"> case 'e':</font>
00264 <font class="comment"> k +=14;</font>
00265 <font class="comment"> break;</font>
00266 <font class="comment"> case 'f':</font>
00267 <font class="comment"> k +=15;</font>
00268 <font class="comment"> break;</font>
00269 <font class="comment"></font>
00270 <font class="comment"> case 'A':</font>
00271 <font class="comment"> k +=10;</font>
00272 <font class="comment"> break;</font>
00273 <font class="comment"> case 'B':</font>
00274 <font class="comment"> k +=11;</font>
00275 <font class="comment"> break;</font>
00276 <font class="comment"> case 'C':</font>
00277 <font class="comment"> k +=12;</font>
00278 <font class="comment"> break;</font>
00279 <font class="comment"> case 'D':</font>
00280 <font class="comment"> k +=13;</font>
00281 <font class="comment"> break;</font>
00282 <font class="comment"> case 'E':</font>
00283 <font class="comment"> k +=14;</font>
00284 <font class="comment"> break;</font>
00285 <font class="comment"> case 'F':</font>
00286 <font class="comment"> k +=15;</font>
00287 <font class="comment"> break;</font>
00288 <font class="comment"></font>
00289 <font class="comment"> case 0:</font>
00290 <font class="comment"> return k;</font>
00291 <font class="comment"> break;</font>
00292 <font class="comment"> }</font>
00293 <font class="comment"> if(*ident != 0) k *= base;</font>
00294 <font class="comment"> }</font>
00295 <font class="comment"></font>
00296 <font class="comment"> return k;</font>
00297 <font class="comment">*/</font>
00298 }
00299
00300 <font class="keywordtype">void</font> <a class="code" href="namespaceNLMISC.html#a240">itoaInt64</a> (sint64 number, <font class="keywordtype">char</font> *str, sint64 base)
00301 {
00302 str[0] = <font class="charliteral">'\0'</font>;
00303 <font class="keywordtype">char</font> b[256];
00304 <font class="keywordflow">if</font>(!number)
00305 {
00306 str[0] = <font class="charliteral">'0'</font>;
00307 str[1] = <font class="charliteral">'\0'</font>;
00308 <font class="keywordflow">return</font>;
00309 }
00310 memset(b,<font class="charliteral">'\0'</font>,255);
00311 memset(b,<font class="charliteral">'0'</font>,64);
00312 sint n;
00313 sint64 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = number;
00314 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> < 0) <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = -<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00315 <font class="keywordtype">char</font> baseTable[] = <font class="stringliteral">"0123456789abcdefghijklmnopqrstuvwyz"</font>;
00316 <font class="keywordflow">for</font>(n = 0; n < 64; n ++)
00317 {
00318 sint <a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a> = (sint)(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> % base);
00319 b[64 - n] = baseTable[<a class="code" href="driver__opengl__extension__def_8h.html#a410">num</a>];
00320 <font class="keywordflow">if</font>(!<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
00321 {
00322 <font class="keywordtype">int</font> k;
00323 <font class="keywordtype">int</font> j = 0;
00324
00325 <font class="keywordflow">if</font> (number < 0)
00326 {
00327 str[j++] = <font class="charliteral">'-'</font>;
00328 }
00329
00330 <font class="keywordflow">for</font>(k = 64 - n + 1; k <= 64; k++)
00331 {
00332 str[j ++] = b[k];
00333 }
00334 str[j] = <font class="charliteral">'\0'</font>;
00335 <font class="keywordflow">break</font>;
00336 }
00337 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> /= base;
00338 }
00339 }
00340
00341 uint <a class="code" href="namespaceNLMISC.html#a223">raiseToNextPowerOf2</a>(uint <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
00342 {
00343 uint <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>=1;
00344 <font class="keywordflow">while</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a><<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
00345 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a><<=1;
00346
00347 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00348 }
00349
00350 uint <a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a>(uint <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
00351 {
00352 uint <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>=1;
00353 uint ret=0;
00354 <font class="keywordflow">while</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a><<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
00355 {
00356 ret++;
00357 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a><<=1;
00358 }
00359
00360 <font class="keywordflow">return</font> ret;
00361 }
00362
00363 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a>(sint32 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
00364 {
00365 <font class="keywordflow">while</font>(v)
00366 {
00367 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>&1)
00368 {
00369 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>>>=1;
00370 <font class="keywordflow">if</font>(v)
00371 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00372 }
00373 <font class="keywordflow">else</font>
00374 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>>>=1;
00375 }
00376
00377 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00378 }
00379
00380 string <a class="code" href="namespaceNLMISC.html#a241">bytesToHumanReadable</a> (uint32 bytes)
00381 {
00382 <font class="keyword">static</font> <font class="keywordtype">char</font> *divTable[]= { <font class="stringliteral">"b"</font>, <font class="stringliteral">"kb"</font>, <font class="stringliteral">"mb"</font>, <font class="stringliteral">"gb"</font>, <font class="stringliteral">"tb"</font> };
00383 uint div = 0;
00384 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = (float)bytes;
00385 <font class="keywordtype">float</font> newres = <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00386 <font class="keywordflow">while</font> (true)
00387 {
00388 newres /= 1024;
00389 <font class="keywordflow">if</font>(newres < 1.0f || div > 4)
00390 <font class="keywordflow">break</font>;
00391 div++;
00392 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = newres;
00393 }
00394 <font class="keywordtype">int</font> ires = (int) <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00395 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>-(float)ires < .01f)
00396 <font class="keywordflow">return</font> <a class="code" href="namespaceNLMISC.html#a243">toString</a> (<font class="stringliteral">"%.0f%s"</font>, <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>, divTable[div]);
00397 <font class="keywordflow">else</font>
00398 <font class="keywordflow">return</font> <a class="code" href="namespaceNLMISC.html#a243">toString</a> (<font class="stringliteral">"%.2f%s"</font>, <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>, divTable[div]);
00399 }
00400
00401 <a class="code" href="namespaceNLMISC.html#a288">NLMISC_COMMAND</a>(bthr, <font class="stringliteral">"Convert a bytes number into an human readable"</font>, <font class="stringliteral">"<int>"</font>)
00402 {
00403 <font class="keywordflow">if</font> (args.size() != 1)
00404 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00405
00406 log.displayNL(<font class="stringliteral">"%d -> %s"</font>, atoi(args[0].c_str()), <a class="code" href="namespaceNLMISC.html#a241">bytesToHumanReadable</a>(atoi(args[0].c_str())).c_str());
00407
00408 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00409 }
00410
00411 std::string <a class="code" href="namespaceNLMISC.html#a229">strlwr</a> ( <font class="keyword">const</font> std::string &str )
00412 {
00413 string <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00414 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>.reserve (str.size());
00415 <font class="keywordflow">for</font> (uint i=0; i<str.size(); i++)
00416 {
00417 <font class="keywordflow">if</font> ( (str[i] >= <font class="charliteral">'A'</font>) && (str[i] <= <font class="charliteral">'Z'</font>) )
00418 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> += str[i] - <font class="charliteral">'A'</font> + <font class="charliteral">'a'</font>;
00419 <font class="keywordflow">else</font>
00420 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> += str[i];
00421 }
00422
00423 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00424 }
00425
00426 std::string &<a class="code" href="namespaceNLMISC.html#a229">strlwr</a> ( std::string &str )
00427 {
00428 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=str.size()-1; i>=0; i--)
00429 {
00430 <font class="keywordflow">if</font> ( (str[i] >= <font class="charliteral">'A'</font>) && (str[i] <= <font class="charliteral">'Z'</font>) )
00431 {
00432 str[i] = str[i] - <font class="charliteral">'A'</font> + <font class="charliteral">'a'</font>;
00433 }
00434 }
00435
00436 <font class="keywordflow">return</font> (str);
00437 }
00438
00439 <font class="keywordtype">char</font> *<a class="code" href="namespaceNLMISC.html#a229">strlwr</a> ( <font class="keywordtype">char</font> *str )
00440 {
00441 <font class="keywordflow">if</font> (str == NULL)
00442 <font class="keywordflow">return</font> (NULL);
00443
00444 <font class="keywordflow">while</font> (*str != <font class="charliteral">'\0'</font>)
00445 {
00446 <font class="keywordflow">if</font> ( (*str >= <font class="charliteral">'A'</font>) && (*str <= <font class="charliteral">'Z'</font>) )
00447 {
00448 *str = *str - <font class="charliteral">'A'</font> + <font class="charliteral">'a'</font>;
00449 }
00450 str++;
00451 }
00452
00453 <font class="keywordflow">return</font> (str);
00454 }
00455
00456 std::string &<a class="code" href="namespaceNLMISC.html#a232">strupr</a> ( std::string &str )
00457 {
00458 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=str.size()-1; i>=0; i--)
00459 {
00460 <font class="keywordflow">if</font> ( (str[i] >= <font class="charliteral">'a'</font>) && (str[i] <= <font class="charliteral">'z'</font>) )
00461 {
00462 str[i] = str[i] - <font class="charliteral">'a'</font> + <font class="charliteral">'A'</font>;
00463 }
00464 }
00465
00466 <font class="keywordflow">return</font> (str);
00467 }
00468
00469 <font class="keywordtype">char</font> *<a class="code" href="namespaceNLMISC.html#a232">strupr</a> ( <font class="keywordtype">char</font> *str )
00470 {
00471 <font class="keywordflow">if</font> (str == NULL)
00472 <font class="keywordflow">return</font> (NULL);
00473
00474 <font class="keywordflow">while</font> (*str != <font class="charliteral">'\0'</font>)
00475 {
00476 <font class="keywordflow">if</font> ( (*str >= <font class="charliteral">'a'</font>) && (*str <= <font class="charliteral">'z'</font>) )
00477 {
00478 *str = *str - <font class="charliteral">'a'</font> + <font class="charliteral">'A'</font>;
00479 }
00480 str++;
00481 }
00482
00483 <font class="keywordflow">return</font> (str);
00484 }
00485
00486 sint <a class="code" href="namespaceNLMISC.html#a234">nlstricmp</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *lhs,<font class="keyword">const</font> <font class="keywordtype">char</font> *rhs)
00487 {
00488 <a class="code" href="debug_8h.html#a6">nlassert</a>(lhs);
00489 <a class="code" href="debug_8h.html#a6">nlassert</a>(rhs);
00490 uint lchar, rchar;
00491 <font class="keywordflow">while</font> (*lhs != <font class="charliteral">'\0'</font> && *rhs != <font class="charliteral">'\0'</font>)
00492 {
00493 lchar = ::toupper(*lhs);
00494 rchar = ::toupper(*rhs);
00495 <font class="keywordflow">if</font> (lchar != rchar) <font class="keywordflow">return</font> lchar - rchar;
00496 ++lhs;
00497 ++rhs;
00498 }
00499 <font class="keywordflow">if</font> (*lhs != 0) <font class="keywordflow">return</font> 1;
00500 <font class="keywordflow">if</font> (*rhs != 0) <font class="keywordflow">return</font> -1;
00501 <font class="keywordflow">return</font> 0;
00502 }
00503
00504 sint <a class="code" href="namespaceNLMISC.html#a234">nlstricmp</a>(<font class="keyword">const</font> std::string &lhs,<font class="keyword">const</font> std::string &rhs)
00505 {
00506 <font class="keywordflow">return</font> <a class="code" href="namespaceNLMISC.html#a234">nlstricmp</a>(lhs.c_str(), rhs.c_str());
00507 }
00508
00509
00510
00511 <font class="comment">//</font>
00512 <font class="comment">// Exceptions</font>
00513 <font class="comment">//</font>
00514
<a name="l00515"></a><a class="code" href="classNLMISC_1_1Exception.html#a0">00515</a> Exception::Exception() : _Reason("Unknown Exception")
00516 {
00517 <font class="comment">// nlinfo("Exception will be launched: %s", _Reason.c_str());</font>
00518 }
00519
<a name="l00520"></a><a class="code" href="classNLMISC_1_1Exception.html#a1">00520</a> Exception::Exception(<font class="keyword">const</font> std::string &reason) : _Reason(reason)
00521 {
00522 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">"Exception will be launched: %s"</font>, <a class="code" href="classNLMISC_1_1Exception.html#n0">_Reason</a>.c_str());
00523 }
00524
<a name="l00525"></a><a class="code" href="classNLMISC_1_1Exception.html#a2">00525</a> Exception::Exception(<font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ...)
00526 {
00527 <a class="code" href="common_8h.html#a0">NLMISC_CONVERT_VARGS</a> (<a class="code" href="classNLMISC_1_1Exception.html#n0">_Reason</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, NLMISC::MaxCStringSize);
00528 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">"Exception will be launched: %s"</font>, <a class="code" href="classNLMISC_1_1Exception.html#n0">_Reason</a>.c_str());
00529 }
00530
<a name="l00531"></a><a class="code" href="classNLMISC_1_1Exception.html#a4">00531</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *Exception::what() <font class="keyword">const</font> <font class="keywordflow">throw</font>()
00532 {
00533 <font class="keywordflow">return</font> _Reason.c_str();
00534 }
00535
00536 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLMISC.html#a242">launchProgram</a> (<font class="keyword">const</font> std::string &programName, <font class="keyword">const</font> std::string &arguments)
00537 {
00538
00539 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00540 <font class="preprocessor"></font>
00541 SECURITY_ATTRIBUTES sa;
00542 sa.nLength = <font class="keyword">sizeof</font> (sa);
00543 sa.lpSecurityDescriptor = NULL;
00544 sa.bInheritHandle = FALSE;
00545
00546 STARTUPINFO si;
00547 si.cb = <font class="keyword">sizeof</font> (si);
00548 si.lpReserved = NULL;
00549 si.lpDesktop = NULL;
00550 si.lpTitle = NULL;
00551 si.dwFlags = STARTF_USESHOWWINDOW;
00552 si.cbReserved2 = 0;
00553 si.wShowWindow = SW_MINIMIZE;
00554 si.lpReserved2 = NULL;
00555
00556 PROCESS_INFORMATION pi;
00557
00558 BOOL <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = CreateProcess(programName.c_str(), (<font class="keywordtype">char</font>*)arguments.c_str(), &sa, &sa, FALSE, 0, NULL, NULL, &si, &pi);
00559
00560 <font class="keywordflow">if</font> (res)
00561 {
00562 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Successful launch '%s' with arg '%s'"</font>, programName.c_str(), arguments.c_str());
00563 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00564 }
00565 <font class="keywordflow">else</font>
00566 {
00567 LPVOID lpMsgBuf;
00568 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
00569 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Failed launched '%s' with arg '%s' err %d: '%s'"</font>, programName.c_str(), arguments.c_str(), GetLastError (), lpMsgBuf);
00570 LocalFree(lpMsgBuf);
00571 }
00572
00573 <font class="preprocessor">#elif defined(NL_OS_UNIX)</font>
00574 <font class="preprocessor"></font>
00575 <font class="keywordtype">int</font> status = vfork ();
00576 <font class="keywordflow">if</font> (status == -1)
00577 {
00578 <font class="keywordtype">char</font> *err = strerror (errno);
00579 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Failed launched '%s' with arg '%s' err %d: '%s'"</font>, programName.c_str(), arguments.c_str(), errno, err);
00580 }
00581 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (status == 0)
00582 {
00583 status = execlp(programName.c_str(), programName.c_str(), arguments.c_str(), 0);
00584 <font class="keywordflow">if</font> (status == -1)
00585 {
00586 perror(<font class="stringliteral">"Failed launched"</font>);
00587 _exit(EXIT_FAILURE);
00588 }
00589 }
00590 <font class="keywordflow">else</font>
00591 {
00592 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Successful launch '%s' with arg '%s'"</font>, programName.c_str(), arguments.c_str());
00593 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00594 }
00595 <font class="preprocessor">#else</font>
00596 <font class="preprocessor"></font> <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"launchProgram() not implemented"</font>);
00597 <font class="preprocessor">#endif</font>
00598 <font class="preprocessor"></font>
00599 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00600
00601 }
00602
00603 } <font class="comment">// NLMISC</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|