OSDN Git Service

3004c0f7320ab5f9a468a6ee209cdfbdd0930bcd
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.robertl / eb101.C
1 // Special g++ Options: -fcheck-memory-usage
2 // Build don't link: 
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 #pragma interface
31
32 #define _IOSTREAM_H
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 #define _STREAMBUF_H
60
61 #pragma interface
62
63
64    
65
66 #define _IO_NEW_STREAMS 
67
68 extern "C" {
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 #define _IO_STDIO_H
97
98   
99
100 #define _G_config_h
101 #define _G_LIB_VERSION "0.67"
102 #define _G_NAMES_HAVE_UNDERSCORE 1
103 #define _G_VTABLE_LABEL_HAS_LENGTH 1
104 #define _G_VTABLE_LABEL_PREFIX "__vt$"
105 #define _G_HAVE_ST_BLKSIZE 1
106 typedef long _G_clock_t;
107 typedef short _G_dev_t;
108 typedef long   _G_fpos_t;
109 typedef unsigned short _G_gid_t;
110 typedef unsigned long _G_ino_t;
111 typedef unsigned short _G_mode_t;
112 typedef short _G_nlink_t;
113 typedef long _G_off_t;
114 typedef int _G_pid_t;
115
116
117
118 typedef int _G_ptrdiff_t;
119 typedef int _G_sigset_t;
120
121
122
123 typedef unsigned int _G_size_t;
124 typedef long _G_time_t;
125 typedef unsigned short _G_uid_t;
126
127
128
129 typedef __wchar_t _G_wchar_t;
130 typedef int   _G_ssize_t;
131 typedef int   _G_wint_t;
132 typedef char * _G_va_list;
133 #define _G_signal_return_type void
134 #define _G_sprintf_return_type char*
135
136 typedef signed char _G_int8_t;
137
138 typedef unsigned char _G_uint8_t;
139 typedef short _G_int16_t;
140 typedef unsigned short _G_uint16_t;
141 typedef long _G_int32_t;
142 typedef unsigned long _G_uint32_t;
143
144 #define HAVE_INT64
145 typedef long long _G_int64_t;
146 typedef unsigned long long _G_uint64_t;
147
148 #define _G_BUFSIZ 1024
149 #define _G_FOPEN_MAX 32 
150 #define _G_FILENAME_MAX 1024 
151 #define _G_NULL 0 
152
153 #define _G_ARGS(ARGLIST) ARGLIST
154
155
156
157
158
159
160
161
162
163 #define _G_HAVE_ATEXIT 0
164 #define _G_HAVE_SYS_RESOURCE 1
165 #define _G_HAVE_SYS_SOCKET 1
166 #define _G_HAVE_SYS_WAIT 1
167 #define _G_HAVE_UNISTD 1
168 #define _G_HAVE_DIRENT 1
169 #define _G_HAVE_CURSES 1
170 #define _G_MATH_H_INLINES 0
171 #define _G_HAVE_BOOL 1
172
173
174 #define _IO_pos_t _G_fpos_t 
175 #define _IO_fpos_t _G_fpos_t
176 #define _IO_size_t _G_size_t
177 #define _IO_ssize_t _G_ssize_t
178 #define _IO_off_t _G_off_t
179 #define _IO_pid_t _G_pid_t
180 #define _IO_uid_t _G_uid_t
181 #define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
182 #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
183 #define _IO_BUFSIZ _G_BUFSIZ
184 #define _IO_va_list _G_va_list
185
186
187
188
189
190
191
192
193 #define __P(protos) protos
194
195
196
197
198
199
200  
201
202 #define _PARAMS(protos) __P(protos)
203
204
205
206
207
208 #define _IO_UNIFIED_JUMPTABLES 1
209
210 #define _IO_USE_DTOA 1
211
212
213
214 #define EOF (-1)
215
216
217
218
219 #define NULL (__null)
220
221
222
223
224
225
226
227
228
229 #define _IOS_INPUT      1
230 #define _IOS_OUTPUT     2
231 #define _IOS_ATEND      4
232 #define _IOS_APPEND     8
233 #define _IOS_TRUNC      16
234 #define _IOS_NOCREATE   32
235 #define _IOS_NOREPLACE  64
236 #define _IOS_BIN        128
237
238  
239
240
241
242
243
244 #define _IO_MAGIC 0xFBAD0000 
245 #define _OLD_STDIO_MAGIC 0xFABC0000 
246 #define _IO_MAGIC_MASK 0xFFFF0000
247 #define _IO_USER_BUF 1 
248 #define _IO_UNBUFFERED 2
249 #define _IO_NO_READS 4 
250 #define _IO_NO_WRITES 8 
251 #define _IO_EOF_SEEN 0x10
252 #define _IO_ERR_SEEN 0x20
253 #define _IO_DELETE_DONT_CLOSE 0x40 
254 #define _IO_LINKED 0x80 
255 #define _IO_IN_BACKUP 0x100
256 #define _IO_LINE_BUF 0x200
257 #define _IO_TIED_PUT_GET 0x400 
258 #define _IO_CURRENTLY_PUTTING 0x800
259 #define _IO_IS_APPENDING 0x1000
260 #define _IO_IS_FILEBUF 0x2000
261 #define _IO_BAD_SEEN 0x4000
262
263  
264 #define _IO_SKIPWS 01
265 #define _IO_LEFT 02
266 #define _IO_RIGHT 04
267 #define _IO_INTERNAL 010
268 #define _IO_DEC 020
269 #define _IO_OCT 040
270 #define _IO_HEX 0100
271 #define _IO_SHOWBASE 0200
272 #define _IO_SHOWPOINT 0400
273 #define _IO_UPPERCASE 01000
274 #define _IO_SHOWPOS 02000
275 #define _IO_SCIENTIFIC 04000
276 #define _IO_FIXED 010000
277 #define _IO_UNITBUF 020000
278 #define _IO_STDIO 040000
279 #define _IO_DONT_CLOSE 0100000
280 #define _IO_BOOLALPHA 0200000
281
282
283 struct _IO_jump_t;  struct _IO_FILE;
284
285  
286
287
288
289
290
291
292
293
294
295     typedef void _IO_lock_t;
296
297
298
299
300
301  
302
303 struct _IO_marker {
304   struct _IO_marker *_next;
305   struct _IO_FILE *_sbuf;
306    
307
308    
309   int _pos;
310
311 };
312
313 struct _IO_FILE {
314   int _flags;            
315 #define _IO_file_flags _flags
316
317    
318    
319   char* _IO_read_ptr;    
320   char* _IO_read_end;    
321   char* _IO_read_base;   
322   char* _IO_write_base;  
323   char* _IO_write_ptr;   
324   char* _IO_write_end;   
325   char* _IO_buf_base;    
326   char* _IO_buf_end;     
327    
328   char *_IO_save_base;  
329   char *_IO_backup_base;   
330   char *_IO_save_end;  
331
332   struct _IO_marker *_markers;
333
334   struct _IO_FILE *_chain;
335
336   int _fileno;
337   int _blksize;
338   _G_off_t  _offset;
339
340 #define __HAVE_COLUMN 
341    
342   unsigned short _cur_column;
343   char _unused;
344   char _shortbuf[1];
345
346    
347
348
349
350
351 };
352
353
354
355
356
357 struct _IO_FILE_plus;
358 extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
359 #define _IO_stdin ((_IO_FILE*)(&_IO_stdin_))
360 #define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
361 #define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
362
363
364  
365 typedef struct
366 {
367   _G_ssize_t  (*read)  (struct _IO_FILE *, void *, _G_ssize_t )  ;
368   _G_ssize_t  (*write)  (struct _IO_FILE *, const void *, _G_ssize_t )  ;
369   _G_fpos_t  (*seek)  (struct _IO_FILE *, _G_off_t , int)  ;
370   int (*close)  (struct _IO_FILE *)  ;
371 } _IO_cookie_io_functions_t;
372
373  
374 struct _IO_cookie_file
375 {
376   struct _IO_FILE file;
377   const void *vtable;
378   void *cookie;
379   _IO_cookie_io_functions_t io_functions;
380 };
381
382
383
384 extern "C" {
385
386
387 extern int __underflow  (_IO_FILE *)  ;
388 extern int __uflow  (_IO_FILE *)  ;
389 extern int __overflow  (_IO_FILE *, int)  ;
390
391 #define _IO_getc_unlocked(_fp) ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++)
392
393
394 #define _IO_peekc_unlocked(_fp) ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end && __underflow (_fp) == EOF ? EOF : *(unsigned char *) (_fp)->_IO_read_ptr)
395
396
397
398
399 #define _IO_putc_unlocked(_ch, _fp) (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) ? __overflow (_fp, (unsigned char) (_ch)) : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
400
401
402
403
404 #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
405 #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
406
407 extern int _IO_getc  (_IO_FILE *__fp)  ;
408 extern int _IO_putc  (int __c, _IO_FILE *__fp)  ;
409 extern int _IO_feof  (_IO_FILE *__fp)  ;
410 extern int _IO_ferror  (_IO_FILE *__fp)  ;
411
412 extern int _IO_peekc_locked  (_IO_FILE *__fp)  ;
413
414  
415 #define _IO_PENDING_OUTPUT_COUNT(_fp)   ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
416
417
418 extern void _IO_flockfile  (_IO_FILE *)  ;
419 extern void _IO_funlockfile  (_IO_FILE *)  ;
420 extern int _IO_ftrylockfile  (_IO_FILE *)  ;
421
422
423
424
425 #define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
426 #define _IO_flockfile(_fp) 
427 #define _IO_funlockfile(_fp) 
428 #define _IO_ftrylockfile(_fp) 
429 #define _IO_cleanup_region_start(_fct, _fp) 
430 #define _IO_cleanup_region_end(_Doit) 
431
432
433
434 extern int _IO_vfscanf  (_IO_FILE *, const char *, _G_va_list , int *)  ;
435 extern int _IO_vfprintf  (_IO_FILE *, const char *, _G_va_list )  ;
436 extern _G_ssize_t  _IO_padn  (_IO_FILE *, int, _G_ssize_t )  ;
437 extern _G_size_t  _IO_sgetn  (_IO_FILE *, void *, _G_size_t )  ;
438
439 extern _G_fpos_t  _IO_seekoff  (_IO_FILE *, _G_off_t , int, int)  ;
440 extern _G_fpos_t  _IO_seekpos  (_IO_FILE *, _G_fpos_t , int)  ;
441
442 extern void _IO_free_backup_area  (_IO_FILE *)  ;
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 #define _IO_wchar_t short
472
473
474 extern "C++" {
475 class istream;  
476 class ostream; class streambuf;
477
478  
479
480
481
482 typedef _G_off_t  streamoff;
483 typedef _G_fpos_t  streampos;
484 typedef _G_ssize_t  streamsize;
485
486 typedef unsigned long __fmtflags;
487 typedef unsigned char __iostate;
488
489 struct _ios_fields
490 {  
491     streambuf *_strbuf;
492     ostream* _tie;
493     int _width;
494     __fmtflags _flags;
495     short  _fill;
496     __iostate _state;
497     __iostate _exceptions;
498     int _precision;
499
500     void *_arrays;  
501 };
502
503 #define _IOS_GOOD       0
504 #define _IOS_EOF        1
505 #define _IOS_FAIL       2
506 #define _IOS_BAD        4
507
508 #define _IO_INPUT       1
509 #define _IO_OUTPUT      2
510 #define _IO_ATEND       4
511 #define _IO_APPEND      8
512 #define _IO_TRUNC       16
513 #define _IO_NOCREATE    32
514 #define _IO_NOREPLACE   64
515 #define _IO_BIN         128
516
517
518
519 class ios : public _ios_fields {
520   ios& operator=(ios&);   
521   ios (const ios&);  
522   public:
523     typedef __fmtflags fmtflags;
524     typedef int iostate;
525     typedef int openmode;
526     typedef int streamsize;
527     enum io_state {
528         goodbit = 0 ,
529         eofbit = 1 ,
530         failbit = 2 ,
531         badbit = 4  };
532     enum open_mode {
533         in = 1 ,
534         out = 2 ,
535         ate = 4 ,
536         app = 8 ,
537         trunc = 16 ,
538         nocreate = 32 ,
539         noreplace = 64 ,
540         bin = 128 ,  
541         binary = 128  };
542     enum seek_dir { beg, cur, end};
543     typedef enum seek_dir seekdir;
544      
545     enum { skipws= 01 ,
546            left= 02 , right= 04 , internal= 010 ,
547            dec= 020 , oct= 040 , hex= 0100 ,
548            showbase= 0200 , showpoint= 0400 ,
549            uppercase= 01000 , showpos= 02000 ,
550            scientific= 04000 , fixed= 010000 ,
551            unitbuf= 020000 , stdio= 040000 
552
553
554
555            };
556     enum {  
557         basefield=dec+oct+hex,
558         floatfield = scientific+fixed,
559         adjustfield = left+right+internal
560     };
561
562
563
564     ostream* tie() const { return _tie; }
565     ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
566
567      
568     short  fill() const { return (short )_fill; }
569     short  fill(short  newf)
570         {short  oldf = (short )_fill; _fill = (char)newf; return oldf;}
571     fmtflags flags() const { return _flags; }
572     fmtflags flags(fmtflags new_val) {
573         fmtflags old_val = _flags; _flags = new_val; return old_val; }
574     int precision() const { return _precision; }
575     int precision(int newp) {
576         unsigned short oldp = _precision; _precision = (unsigned short)newp;
577         return oldp; }
578     fmtflags setf(fmtflags val) {
579         fmtflags oldbits = _flags;
580         _flags |= val; return oldbits; }
581     fmtflags setf(fmtflags val, fmtflags mask) {
582         fmtflags oldbits = _flags;
583         _flags = (_flags & ~mask) | (val & mask); return oldbits; }
584     fmtflags unsetf(fmtflags mask) {
585         fmtflags oldbits = _flags;
586         _flags &= ~mask; return oldbits; }
587     int width() const { return _width; }
588     int width(int val) { int save = _width; _width = val; return save; }
589
590
591
592
593     void _throw_failure() const { }
594
595     void clear(iostate state = 0) {
596         _state = _strbuf ? state : state|badbit;
597         if (_state & _exceptions) _throw_failure(); }
598     void set(iostate flag) { _state |= flag;
599         if (_state & _exceptions) _throw_failure(); }
600     void setstate(iostate flag) { _state |= flag;  
601         if (_state & _exceptions) _throw_failure(); }
602     int good() const { return _state == 0; }
603     int eof() const { return _state & ios::eofbit; }
604     int fail() const { return _state & (ios::badbit|ios::failbit); }
605     int bad() const { return _state & ios::badbit; }
606     iostate rdstate() const { return _state; }
607     operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
608     int operator!() const { return fail(); }
609     iostate exceptions() const { return _exceptions; }
610     void exceptions(iostate enable) {
611         _exceptions = enable;
612         if (_state & _exceptions) _throw_failure(); }
613
614     streambuf* rdbuf() const { return _strbuf; }
615     streambuf* rdbuf(streambuf *_s) {
616       streambuf *_old = _strbuf; _strbuf = _s; clear (); return _old; }
617
618     static int sync_with_stdio(int on);
619     static void sync_with_stdio() { sync_with_stdio(1); }
620     static fmtflags bitalloc();
621     static int xalloc();
622     void*& pword(int);
623     void* pword(int) const;
624     long& iword(int);
625     long iword(int) const;
626
627
628
629
630
631
632
633
634
635      
636     class Init {
637     public:
638       Init () { }
639     };
640
641   protected:
642     inline ios(streambuf* sb = 0, ostream* tie_to = 0);
643     inline virtual ~ios();
644     inline void init(streambuf* sb, ostream* tie = 0);
645 };
646
647
648
649
650 typedef ios::seek_dir _seek_dir;
651
652
653  
654  
655  
656  
657  
658
659  
660  
661 class streammarker : private _IO_marker {
662     friend class streambuf;
663     void set_offset(int offset) { _pos = offset; }
664   public:
665     streammarker(streambuf *sb);
666     ~streammarker();
667     int saving() { return  1; }
668     int delta(streammarker&);
669     int delta();
670 };
671
672 struct streambuf : public _IO_FILE {  
673     friend class ios;
674     friend class istream;
675     friend class ostream;
676     friend class streammarker;
677     const void *&_vtable() { return *(const void**)((_IO_FILE*)this + 1); }
678   protected:
679     static streambuf* _list_all;  
680     _IO_FILE*& xchain() { return _chain; }
681     void _un_link();
682     void _link_in();
683     char* gptr() const
684       { return _flags  & 0x100  ? _IO_save_base : _IO_read_ptr; }
685     char* pptr() const { return _IO_write_ptr; }
686     char* egptr() const
687       { return _flags  & 0x100  ? _IO_save_end : _IO_read_end; }
688     char* epptr() const { return _IO_write_end; }
689     char* pbase() const { return _IO_write_base; }
690     char* eback() const
691       { return _flags  & 0x100  ? _IO_save_base : _IO_read_base;}
692     char* base() const { return _IO_buf_base; }
693     char* ebuf() const { return _IO_buf_end; }
694     int blen() const { return _IO_buf_end - _IO_buf_base; }
695     void xput_char(char c) { *_IO_write_ptr++ = c; }
696     int xflags() { return _flags ; }
697     int xflags(int f) {int fl = _flags ; _flags  = f; return fl;}
698     void xsetflags(int f) { _flags  |= f; }
699     void xsetflags(int f, int mask)
700       { _flags  = (_flags  & ~mask) | (f & mask); }
701     void gbump(int n)
702       { _flags  & 0x100  ? (_IO_save_base+=n):(_IO_read_ptr+=n);}
703     void pbump(int n) { _IO_write_ptr += n; }
704     void setb(char* b, char* eb, int a=0);
705     void setp(char* p, char* ep)
706       { _IO_write_base=_IO_write_ptr=p; _IO_write_end=ep; }
707     void setg(char* eb, char* g, char *eg) {
708       if (_flags  & 0x100 ) _IO_free_backup_area(this); 
709       _IO_read_base = eb; _IO_read_ptr = g; _IO_read_end = eg; }
710     char *shortbuf() { return _shortbuf; }
711
712     int in_backup() { return _flags & 0x100 ; }
713      
714     char *Gbase() { return in_backup() ? _IO_save_base : _IO_read_base; }
715      
716     char *eGptr() { return in_backup() ? _IO_save_end : _IO_read_end; }
717      
718     char *Bbase() { return in_backup() ? _IO_read_base : _IO_save_base; }
719     char *Bptr() { return _IO_backup_base; }
720      
721     char *eBptr() { return in_backup() ? _IO_read_end : _IO_save_end; }
722     char *Nbase() { return _IO_save_base; }
723     char *eNptr() { return _IO_save_end; }
724     int have_backup() { return _IO_save_base != (__null) ; }
725     int have_markers() { return _markers != (__null) ; }
726     void free_backup_area();
727     void unsave_markers();  
728     int put_mode() { return _flags & 0x800 ; }
729     int switch_to_get_mode();
730     
731     streambuf(int flags=0);
732   public:
733     static int flush_all();
734     static void flush_all_linebuffered();  
735     virtual ~streambuf();
736     virtual int overflow(int c = (-1) );  
737     virtual int underflow();  
738     virtual int uflow();  
739     virtual int pbackfail(int c);
740  
741     virtual streamsize xsputn(const char* s, streamsize n);
742     virtual streamsize xsgetn(char* s, streamsize n);
743     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
744     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
745
746     streampos pubseekoff(streamoff o, _seek_dir d, int mode=ios::in|ios::out)
747       { return _IO_seekoff (this, o, d, mode); }
748     streampos pubseekpos(streampos pos, int mode = ios::in|ios::out)
749       { return _IO_seekpos (this, pos, mode); }
750     streampos sseekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
751     streampos sseekpos(streampos pos, int mode = ios::in|ios::out);
752     virtual streambuf* setbuf(char* p, int len);
753     virtual int sync();
754     virtual int doallocate();
755
756     int seekmark(streammarker& mark, int delta = 0);
757     int sputbackc(char c);
758     int sungetc();
759     int unbuffered() { return _flags & 2  ? 1 : 0; }
760     int linebuffered() { return _flags & 0x200  ? 1 : 0; }
761     void unbuffered(int i)
762         { if (i) _flags |= 2 ; else _flags &= ~2 ; }
763     void linebuffered(int i)
764         { if (i) _flags |= 0x200 ; else _flags &= ~0x200 ; }
765     int allocate() {  
766         if (base() || unbuffered()) return 0;
767         else return doallocate(); }
768      
769     void allocbuf() { if (base() == (__null) ) doallocbuf(); }
770     void doallocbuf();
771     int in_avail() { return _IO_read_end - _IO_read_ptr; }
772     int out_waiting() { return _IO_write_ptr - _IO_write_base; }
773     streamsize sputn(const char* s, streamsize n) { return xsputn(s, n); }
774     streamsize padn(char pad, streamsize n) { return _IO_padn(this, pad, n); }
775     streamsize sgetn(char* s, streamsize n) { return _IO_sgetn(this, s, n); }
776     int ignore(int);
777     int get_column();
778     int set_column(int);
779     long sgetline(char* buf, _G_size_t  n, char delim, int putback_delim);
780     int sputc(int c) { return _IO_putc(c, this); }
781     int sbumpc() { return _IO_getc(this); }
782     int sgetc() { return ((  this  )->_IO_read_ptr >= (  this  )->_IO_read_end && __underflow (  this  ) == (-1)  ? (-1)  : *(unsigned char *) (  this  )->_IO_read_ptr)  ; }
783     int snextc() {
784         if (_IO_read_ptr >= _IO_read_end && __underflow(this) == (-1) )
785           return (-1) ;
786         else return _IO_read_ptr++, sgetc(); }
787     void stossc() { if (_IO_read_ptr < _IO_read_end) _IO_read_ptr++; }
788     int vscan(char const *fmt0, _G_va_list  ap, ios* stream = (__null) );
789     int scan(char const *fmt0 ...);
790     int vform(char const *fmt0, _G_va_list  ap);
791     int form(char const *fmt0 ...);
792
793
794
795
796     virtual streamsize sys_read(char* buf, streamsize size);
797     virtual streamsize sys_write(const char*, streamsize);
798     virtual streampos sys_seek(streamoff, _seek_dir);
799     virtual int sys_close();
800     virtual int sys_stat(void*);  
801 };
802
803  
804  
805
806 class filebuf : public streambuf {
807   protected:
808     void init();
809   public:
810     static const int openprot;  
811     filebuf();
812     filebuf(int fd);
813     filebuf(int fd, char* p, int len);
814
815
816
817     ~filebuf();
818     filebuf* attach(int fd);
819     filebuf* open(const char *filename, const char *mode);
820     filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
821     virtual int underflow();
822     virtual int overflow(int c = (-1) );
823     int is_open() const { return _fileno >= 0; }
824     int fd() const { return is_open() ? _fileno : (-1) ; }
825     filebuf* close();
826     virtual int doallocate();
827     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
828     virtual streambuf* setbuf(char* p, int len);
829     streamsize xsputn(const char* s, streamsize n);
830     streamsize xsgetn(char* s, streamsize n);
831     virtual int sync();
832   protected:  
833  
834     int is_reading() { return eback() != egptr(); }
835     char* cur_ptr() { return is_reading() ?  gptr() : pptr(); }
836      
837     char* file_ptr() { return eGptr(); }
838      
839     virtual streamsize sys_read(char* buf, streamsize size);
840     virtual streampos sys_seek(streamoff, _seek_dir);
841     virtual streamsize sys_write(const char*, streamsize);
842     virtual int sys_stat(void*);  
843     virtual int sys_close();
844
845
846
847
848 };
849
850 inline void ios::init(streambuf* sb, ostream* tie_to) {
851                 _state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
852                 _strbuf=sb; _tie = tie_to; _width=0; _fill=' ';
853
854                 _flags=ios::skipws|ios::dec;
855
856
857
858                 _precision=6; _arrays = 0; }
859
860 inline ios::ios(streambuf* sb, ostream* tie_to) { init(sb, tie_to); }
861
862 inline ios::~ios() {
863
864
865
866     if (_arrays) delete [] _arrays;
867 }
868 }  
869
870
871
872 extern "C++" {
873 class istream; class ostream;
874 typedef ios& (*__manip)(ios&);
875 typedef istream& (*__imanip)(istream&);
876 typedef ostream& (*__omanip)(ostream&);
877
878 extern istream& ws(istream& ins);
879 extern ostream& flush(ostream& outs);
880 extern ostream& endl(ostream& outs);
881 extern ostream& ends(ostream& outs);
882
883 class ostream : virtual public ios
884 {
885      
886     void do_osfx();
887   public:
888     ostream() { }
889     ostream(streambuf* sb, ostream* tied= (__null) );
890     int opfx() {
891         if (!good()) return 0;
892         else { if (_tie) _tie->flush();  ; return 1;} }
893     void osfx() {  ;
894                   if (flags() & (ios::unitbuf|ios::stdio))
895                       do_osfx(); }
896     ostream& flush();
897     ostream& put(char c) { _strbuf->sputc(c); return *this; }
898
899
900
901
902
903     ostream& write(const char *s, streamsize n);
904     ostream& write(const unsigned char *s, streamsize n)
905       { return write((const char*)s, n);}
906     ostream& write(const signed char *s, streamsize n)
907       { return write((const char*)s, n);}
908     ostream& write(const void *s, streamsize n)
909       { return write((const char*)s, n);}
910     ostream& seekp(streampos);
911     ostream& seekp(streamoff, _seek_dir);
912     streampos tellp();
913     ostream& form(const char *format ...);
914     ostream& vform(const char *format, _G_va_list  args);
915
916     ostream& operator<<(char c);
917     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
918     ostream& operator<<(signed char c) { return (*this) << (char)c; }
919     ostream& operator<<(const char *s);
920     ostream& operator<<(const unsigned char *s)
921         { return (*this) << (const char*)s; }
922     ostream& operator<<(const signed char *s)
923         { return (*this) << (const char*)s; }
924     ostream& operator<<(const void *p);
925     ostream& operator<<(int n);
926     ostream& operator<<(unsigned int n);
927     ostream& operator<<(long n);
928     ostream& operator<<(unsigned long n);
929
930     __extension__ ostream& operator<<(long long n);
931     __extension__ ostream& operator<<(unsigned long long n);
932
933     ostream& operator<<(short n) {return operator<<((int)n);}
934     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
935
936     ostream& operator<<(bool b) { return operator<<((int)b); }
937
938     ostream& operator<<(double n);
939     ostream& operator<<(float n) { return operator<<((double)n); }
940
941
942
943     ostream& operator<<(long double n) { return operator<<((double)n); }
944
945     ostream& operator<<(__omanip func) { return (*func)(*this); }
946     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
947     ostream& operator<<(streambuf*);
948
949
950
951 };
952
953 class istream : virtual public ios
954 {
955      
956 protected:
957     _G_size_t  _gcount;
958
959     int _skip_ws();
960   public:
961     istream(): _gcount (0) { }
962     istream(streambuf* sb, ostream*tied= (__null) );
963     istream& get(char* ptr, int len, char delim = '\n');
964     istream& get(unsigned char* ptr, int len, char delim = '\n')
965         { return get((char*)ptr, len, delim); }
966     istream& get(char& c);
967     istream& get(unsigned char& c) { return get((char&)c); }
968     istream& getline(char* ptr, int len, char delim = '\n');
969     istream& getline(unsigned char* ptr, int len, char delim = '\n')
970         { return getline((char*)ptr, len, delim); }
971     istream& get(signed char& c)  { return get((char&)c); }
972     istream& get(signed char* ptr, int len, char delim = '\n')
973         { return get((char*)ptr, len, delim); }
974     istream& getline(signed char* ptr, int len, char delim = '\n')
975         { return getline((char*)ptr, len, delim); }
976     istream& read(char *ptr, streamsize n);
977     istream& read(unsigned char *ptr, streamsize n)
978       { return read((char*)ptr, n); }
979     istream& read(signed char *ptr, streamsize n)
980       { return read((char*)ptr, n); }
981     istream& read(void *ptr, streamsize n)
982       { return read((char*)ptr, n); }
983     istream& get(streambuf& sb, char delim = '\n');
984     istream& gets(char **s, char delim = '\n');
985     int ipfx(int need = 0) {
986         if (!good()) { set(ios::failbit); return 0; }
987         else {
988            ;
989           if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
990           if (!need && (flags() & ios::skipws)) return _skip_ws();
991           else return 1;
992         }
993     }
994     int ipfx0() {  
995         if (!good()) { set(ios::failbit); return 0; }
996         else {
997            ;
998           if (_tie) _tie->flush();
999           if (flags() & ios::skipws) return _skip_ws();
1000           else return 1;
1001         }
1002     }
1003     int ipfx1() {  
1004         if (!good()) { set(ios::failbit); return 0; }
1005         else {
1006            ;
1007           if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
1008           return 1;
1009         }
1010     }
1011     void isfx() {  ; }
1012     int get() { if (!ipfx1()) return (-1) ;
1013                 else { int ch = _strbuf->sbumpc();
1014                        if (ch == (-1) ) set(ios::eofbit);
1015                        return ch;
1016                      } }
1017     int peek();
1018     _G_size_t  gcount() { return _gcount; }
1019     istream& ignore(int n=1, int delim = (-1) );
1020     int sync ();
1021     istream& seekg(streampos);
1022     istream& seekg(streamoff, _seek_dir);
1023     streampos tellg();
1024     istream& putback(char ch) {
1025         if (good() && _strbuf->sputbackc(ch) == (-1) ) clear(ios::badbit);
1026         return *this;}
1027     istream& unget() {
1028         if (good() && _strbuf->sungetc() == (-1) ) clear(ios::badbit);
1029         return *this;}
1030     istream& scan(const char *format ...);
1031     istream& vscan(const char *format, _G_va_list  args);
1032
1033
1034
1035
1036
1037
1038     istream& operator>>(char*);
1039     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
1040     istream& operator>>(signed char*p) { return operator>>((char*)p); }
1041     istream& operator>>(char& c);
1042     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
1043     istream& operator>>(signed char& c) {return operator>>((char&)c);}
1044     istream& operator>>(int&);
1045     istream& operator>>(long&);
1046
1047     __extension__ istream& operator>>(long long&);
1048     __extension__ istream& operator>>(unsigned long long&);
1049
1050     istream& operator>>(short&);
1051     istream& operator>>(unsigned int&);
1052     istream& operator>>(unsigned long&);
1053     istream& operator>>(unsigned short&);
1054
1055     istream& operator>>(bool&);
1056
1057     istream& operator>>(float&);
1058     istream& operator>>(double&);
1059     istream& operator>>(long double&);
1060     istream& operator>>( __manip func) {(*func)(*this); return *this;}
1061     istream& operator>>(__imanip func) { return (*func)(*this); }
1062     istream& operator>>(streambuf*);
1063 };
1064
1065 class iostream : public istream, public ostream
1066 {
1067   public:
1068     iostream() { }
1069     iostream(streambuf* sb, ostream*tied= (__null) );
1070 };
1071
1072 class _IO_istream_withassign : public istream {
1073 public:
1074   _IO_istream_withassign& operator=(istream&);
1075   _IO_istream_withassign& operator=(_IO_istream_withassign& rhs)
1076     { return operator= (static_cast<istream&> (rhs)); }
1077 };
1078
1079 class _IO_ostream_withassign : public ostream {
1080 public:
1081   _IO_ostream_withassign& operator=(ostream&);
1082   _IO_ostream_withassign& operator=(_IO_ostream_withassign& rhs)
1083     { return operator= (static_cast<ostream&> (rhs)); }
1084 };
1085
1086 extern _IO_istream_withassign cin;
1087  
1088 extern _IO_ostream_withassign cout, cerr;
1089
1090 extern _IO_ostream_withassign clog
1091
1092
1093
1094 ;
1095
1096 extern istream& lock(istream& ins);
1097 extern istream& unlock(istream& ins);
1098 extern ostream& lock(ostream& outs);
1099 extern ostream& unlock(ostream& outs);
1100
1101 struct Iostream_init { } ;   
1102
1103 inline ios& dec(ios& i)
1104 { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
1105 inline ios& hex(ios& i)
1106 { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
1107 inline ios& oct(ios& i)
1108 { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
1109 }  
1110
1111
1112
1113  
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139 #pragma interface
1140
1141 #define _IOMANIP_H
1142
1143
1144
1145 extern "C++" {
1146  
1147  
1148  
1149
1150  
1151  
1152  
1153  
1154 template<class TP> class smanip;  
1155
1156 template<class TP> class sapp {
1157     ios& (*_f)(ios&, TP);
1158 public: 
1159     sapp(ios& (*f)(ios&, TP)) : _f(f) {}
1160      
1161     smanip<TP> operator()(TP a) 
1162       { return smanip<TP>(_f, a); }
1163 };
1164
1165 template<class TP>
1166 inline istream& operator>>(istream& i, const smanip<TP>& m);
1167 template<class TP>
1168 inline ostream& operator<<(ostream& o, const smanip<TP>& m);
1169
1170 template <class TP> class smanip {
1171     ios& (*_f)(ios&, TP);
1172     TP _a;
1173 public:
1174     smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
1175      
1176     friend 
1177       istream& operator>> <>(istream& i, const smanip<TP>& m);
1178     friend
1179       ostream& operator<< <>(ostream& o, const smanip<TP>& m);
1180 };
1181
1182
1183 extern template class smanip<int>;
1184 extern template class smanip<ios::fmtflags>;
1185
1186
1187 template<class TP>
1188 inline istream& operator>>(istream& i, const smanip<TP>& m)
1189 { (*m._f)(i, m._a); return i; }
1190
1191 template<class TP>
1192 inline ostream& operator<<(ostream& o, const smanip<TP>& m)
1193 { (*m._f)(o, m._a); return o;}
1194
1195
1196 extern template istream& operator>>(istream&, const smanip<int>&);
1197 extern template istream& operator>>(istream&, const smanip<ios::fmtflags>&);
1198 extern template ostream& operator<<(ostream&, const smanip<int>&);
1199 extern template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&);
1200
1201
1202  
1203  
1204  
1205  
1206 template<class TP> class imanip; 
1207
1208 template<class TP> class iapp {
1209     istream& (*_f)(istream&, TP);
1210 public: 
1211     iapp(istream& (*f)(istream&,TP)) : _f(f) {}
1212      
1213     imanip<TP> operator()(TP a)
1214        { return imanip<TP>(_f, a); }
1215 };
1216
1217 template <class TP>
1218 inline istream& operator>>(istream&, const imanip<TP>&);
1219
1220 template <class TP> class imanip {
1221     istream& (*_f)(istream&, TP);
1222     TP _a;
1223 public:
1224     imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
1225      
1226     friend
1227       istream& operator>> <>(istream& i, const imanip<TP>& m);
1228 };
1229
1230 template <class TP>
1231 inline istream& operator>>(istream& i, const imanip<TP>& m)
1232 { return (*m._f)( i, m._a); }
1233
1234  
1235  
1236  
1237  
1238 template<class TP> class omanip; 
1239
1240 template<class TP> class oapp {
1241     ostream& (*_f)(ostream&, TP);
1242 public: 
1243     oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
1244      
1245     omanip<TP> operator()(TP a)
1246       { return omanip<TP>(_f, a); }
1247 };
1248
1249 template <class TP>
1250 inline ostream& operator<<(ostream&, const omanip<TP>&);
1251
1252 template <class TP> class omanip {
1253     ostream& (*_f)(ostream&, TP);
1254     TP _a;
1255 public:
1256     omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
1257      
1258     friend
1259       ostream& operator<< <>(ostream& o, const omanip<TP>& m);
1260 };
1261
1262 template <class TP>
1263 inline ostream& operator<<(ostream& o, const omanip<TP>& m)
1264 { return (*m._f)(o, m._a); }
1265
1266  
1267  
1268  
1269
1270  
1271  
1272  
1273  
1274 #define __DEFINE_IOMANIP_FN1(type,param,function) extern ios& __iomanip_##function (ios&, param); inline type<param> function (param n) { return type<param> (__iomanip_##function, n); }
1275
1276
1277
1278
1279 extern ios& __iomanip_setbase  (ios&,   int ); inline   smanip <  int >   setbase  (  int  n) { return   smanip <  int > (__iomanip_setbase , n); } 
1280 extern ios& __iomanip_setfill  (ios&,   int ); inline   smanip <  int >   setfill  (  int  n) { return   smanip <  int > (__iomanip_setfill , n); } 
1281 extern ios& __iomanip_setprecision  (ios&,   int ); inline   smanip <  int >   setprecision  (  int  n) { return   smanip <  int > (__iomanip_setprecision , n); } 
1282 extern ios& __iomanip_setw  (ios&,   int ); inline   smanip <  int >   setw  (  int  n) { return   smanip <  int > (__iomanip_setw , n); } 
1283
1284 extern ios& __iomanip_resetiosflags  (ios&,   ios::fmtflags ); inline   smanip <  ios::fmtflags >   resetiosflags  (  ios::fmtflags  n) { return   smanip <  ios::fmtflags > (__iomanip_resetiosflags , n); } 
1285 extern ios& __iomanip_setiosflags  (ios&,   ios::fmtflags ); inline   smanip <  ios::fmtflags >   setiosflags  (  ios::fmtflags  n) { return   smanip <  ios::fmtflags > (__iomanip_setiosflags , n); } 
1286 }  
1287
1288
1289
1290
1291 #define LS_hh
1292
1293
1294 #define Mouvement_hh
1295
1296
1297
1298 #define usuel_hh
1299
1300  
1301
1302
1303
1304
1305 #define         _MATH_H
1306
1307
1308 extern "C" {
1309
1310
1311 #pragma ident   "@(#)math.h     2.5     95/02/07"
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327  
1328
1329
1330 typedef union _h_val {
1331         unsigned long _i[2];
1332         double _d;
1333 } _h_val;
1334
1335
1336 extern const _h_val __huge_val;
1337
1338
1339
1340
1341
1342 #define         HUGE_VAL __huge_val._d
1343
1344
1345
1346
1347  
1348
1349
1350 #define         M_E             2.7182818284590452354
1351 #define         M_LOG2E         1.4426950408889634074
1352 #define         M_LOG10E        0.43429448190325182765
1353 #define         M_LN2           0.69314718055994530942
1354 #define         M_LN10          2.30258509299404568402
1355 #define         M_PI            3.14159265358979323846
1356 #define         M_PI_2          1.57079632679489661923
1357 #define         M_PI_4          0.78539816339744830962
1358 #define         M_1_PI          0.31830988618379067154
1359 #define         M_2_PI          0.63661977236758134308
1360 #define         M_2_SQRTPI      1.12837916709551257390
1361 #define         M_SQRT2         1.41421356237309504880
1362 #define         M_SQRT1_2       0.70710678118654752440
1363
1364 extern int signgam;
1365
1366 #define         MAXFLOAT        ((float)3.40282346638528860e+38)
1367
1368
1369  
1370
1371
1372 enum version {libm_ieee = -1, c_issue_4, ansi_1, strict_ansi};
1373
1374
1375 extern const enum version _lib_version;
1376
1377
1378
1379
1380
1381 #define exception __math_exception
1382
1383 struct __math_exception  {
1384
1385 #undef exception
1386
1387         int type;
1388         char *name;
1389         double arg1;
1390         double arg2;
1391         double retval;
1392 };
1393
1394 #define         HUGE            MAXFLOAT
1395
1396 #define         _ABS(x)         ((x) < 0 ? -(x) : (x))
1397
1398 #define         _REDUCE(TYPE, X, XN, C1, C2)    { double x1 = (double)(TYPE)X, x2 = X - x1; X = x1 - (XN) * (C1); X += x2; X -= (XN) * (C2); }
1399
1400
1401
1402 #define         DOMAIN          1
1403 #define         SING            2
1404 #define         OVERFLOW        3
1405 #define         UNDERFLOW       4
1406 #define         TLOSS           5
1407 #define         PLOSS           6
1408
1409 #define         _POLY1(x, c)    ((c)[0] * (x) + (c)[1])
1410 #define         _POLY2(x, c)    (_POLY1((x), (c)) * (x) + (c)[2])
1411 #define         _POLY3(x, c)    (_POLY2((x), (c)) * (x) + (c)[3])
1412 #define         _POLY4(x, c)    (_POLY3((x), (c)) * (x) + (c)[4])
1413 #define         _POLY5(x, c)    (_POLY4((x), (c)) * (x) + (c)[5])
1414 #define         _POLY6(x, c)    (_POLY5((x), (c)) * (x) + (c)[6])
1415 #define         _POLY7(x, c)    (_POLY6((x), (c)) * (x) + (c)[7])
1416 #define         _POLY8(x, c)    (_POLY7((x), (c)) * (x) + (c)[8])
1417 #define         _POLY9(x, c)    (_POLY8((x), (c)) * (x) + (c)[9])
1418
1419
1420
1421  
1422
1423
1424 extern double acos  (double)  ;
1425 extern double asin  (double)  ;
1426 extern double atan  (double)  ;
1427 extern double atan2  (double, double)  ;
1428 extern double cos  (double)  ;
1429 extern double sin  (double)  ;
1430 extern double tan  (double)  ;
1431
1432 extern double cosh  (double)  ;
1433 extern double sinh  (double)  ;
1434 extern double tanh  (double)  ;
1435
1436 extern double exp  (double)  ;
1437 extern double frexp  (double, int *)  ;
1438 extern double ldexp  (double, int)  ;
1439 extern double log  (double)  ;
1440 extern double log10  (double)  ;
1441 extern double modf  (double, double *)  ;
1442
1443 extern double pow  (double, double)  ;
1444 extern double sqrt  (double)  ;
1445
1446 extern double ceil  (double)  ;
1447 extern double fabs  (double)  ;
1448 extern double floor  (double)  ;
1449 extern double fmod  (double, double)  ;
1450
1451
1452
1453  
1454
1455
1456 extern double erf  (double)  ;
1457 extern double erfc  (double)  ;
1458 extern double gamma  (double)  ;
1459 extern double hypot  (double, double)  ;
1460 extern int isnan  (double)  ;
1461 extern double j0  (double)  ;
1462 extern double j1  (double)  ;
1463 extern double jn  (int, double)  ;
1464 extern double lgamma  (double)  ;
1465 extern double y0  (double)  ;
1466 extern double y1  (double)  ;
1467 extern double yn  (int, double)  ;
1468
1469
1470
1471  
1472
1473
1474 extern double acosh  (double)  ;
1475 extern double asinh  (double)  ;
1476 extern double atanh  (double)  ;
1477 extern double cbrt  (double)  ;
1478 extern double logb  (double)  ;
1479 extern double nextafter  (double, double)  ;
1480 extern double remainder  (double, double)  ;
1481 extern double scalb  (double, double)  ;
1482
1483  
1484
1485
1486 extern double expm1  (double)  ;
1487 extern int ilogb  (double)  ;
1488 extern double log1p  (double)  ;
1489 extern double rint  (double)  ;
1490
1491
1492
1493  
1494
1495
1496
1497 #define exception __math_exception
1498
1499 extern int matherr  (struct __math_exception  *)  ;
1500
1501 #undef exception
1502
1503
1504  
1505
1506
1507 extern double significand  (double)  ;
1508
1509  
1510
1511
1512 extern double copysign  (double, double)  ;
1513 extern double scalbn  (double, int)  ;
1514
1515  
1516
1517
1518
1519
1520
1521
1522
1523
1524  
1525
1526
1527 extern float modff  (float, float *)  ;
1528
1529  
1530  
1531
1532  
1533  
1534  
1535
1536
1537 #define _FLOATINGPOINT_H
1538
1539
1540 extern "C" {
1541
1542
1543 #pragma ident   "@(#)floatingpoint.h    2.4 94/06/09"
1544
1545  
1546
1547
1548
1549
1550  
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561  
1562  
1563
1564  
1565  
1566  
1567
1568  
1569
1570
1571
1572
1573 #define         _STDIO_H
1574
1575 #pragma ident   "@(#)stdio.h    1.39    95/12/04 SMI"   
1576
1577  
1578  
1579
1580  
1581  
1582  
1583
1584
1585 #define         _SYS_FEATURE_TESTS_H
1586
1587 #pragma ident   "@(#)feature_tests.h    1.7     94/12/06 SMI"
1588
1589
1590 extern "C" {
1591
1592
1593  
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606 }
1607
1608
1609
1610
1611  
1612
1613
1614
1615
1616
1617 #define         _SYS_VA_LIST_H
1618
1619 #pragma ident   "@(#)va_list.h  1.6     96/01/26 SMI"
1620
1621  
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632 extern "C" {
1633
1634
1635
1636
1637
1638 typedef void *__va_list;
1639
1640
1641
1642
1643
1644
1645
1646 }
1647
1648
1649
1650
1651
1652
1653 extern "C" {
1654
1655
1656
1657 #define         _SIZE_T
1658 typedef unsigned int    size_t;
1659
1660
1661 typedef long    fpos_t;
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672 #define         BUFSIZ  1024
1673
1674  
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685  
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703 #define         _NFILE  20      
1704
1705
1706
1707 #define         _SBFSIZ 8       
1708
1709 #define         _IOFBF          0000    
1710 #define         _IOLBF          0100    
1711 #define         _IONBF          0004    
1712 #define         _IOEOF          0020    
1713 #define         _IOERR          0040    
1714
1715 #define         _IOREAD         0001    
1716 #define         _IOWRT          0002    
1717 #define         _IORW           0200    
1718 #define         _IOMYBUF        0010    
1719
1720
1721
1722
1723
1724 #define         FOPEN_MAX       _NFILE
1725 #define         FILENAME_MAX    1024    
1726
1727 #define         SEEK_SET        0
1728 #define         SEEK_CUR        1
1729 #define         SEEK_END        2
1730 #define         TMP_MAX         17576   
1731
1732
1733
1734
1735 #define         L_ctermid       9
1736 #define         L_cuserid       9
1737
1738
1739
1740
1741
1742 #define         P_tmpdir        "/var/tmp/"
1743
1744
1745 #define         L_tmpnam        25      
1746
1747
1748 #define         stdin   (&__iob[0])
1749 #define         stdout  (&__iob[1])
1750 #define         stderr  (&__iob[2])
1751
1752
1753
1754
1755
1756
1757 typedef struct   
1758 {
1759
1760
1761
1762
1763         int             _cnt;    
1764         unsigned char   *_ptr;   
1765
1766         unsigned char   *_base;  
1767         unsigned char   _flag;   
1768         unsigned char   _file;   
1769 } FILE;
1770
1771
1772 extern FILE             __iob[20 ];
1773
1774
1775
1776 extern FILE             *_lastbuf;
1777 extern unsigned char    *_bufendtab[];
1778
1779 extern unsigned char     _sibuf[], _sobuf[];
1780
1781
1782
1783
1784 extern int      remove(const char *);
1785 extern int      rename(const char *, const char *);
1786 extern FILE     *tmpfile(void);
1787 extern char     *tmpnam(char *);
1788
1789
1790
1791 extern int      fclose(FILE *);
1792 extern int      fflush(FILE *);
1793 extern FILE     *fopen(const char *, const char *);
1794 extern FILE     *freopen(const char *, const char *, FILE *);
1795 extern void     setbuf(FILE *, char *);
1796 extern int      setvbuf(FILE *, char *, int, size_t);
1797  
1798 extern int      fprintf(FILE *, const char *, ...);
1799  
1800 extern int      fscanf(FILE *, const char *, ...);
1801  
1802 extern int      printf(const char *, ...);
1803  
1804 extern int      scanf(const char *, ...);
1805  
1806 extern int      sprintf(char *, const char *, ...);
1807  
1808 extern int      sscanf(const char *, const char *, ...);
1809 extern int      vfprintf(FILE *, const char *, __va_list);
1810 extern int      vprintf(const char *, __va_list);
1811 extern int      vsprintf(char *, const char *, __va_list);
1812 extern int      fgetc(FILE *);
1813 extern char     *fgets(char *, int, FILE *);
1814 extern int      fputc(int, FILE *);
1815 extern int      fputs(const char *, FILE *);
1816 extern int      getc(FILE *);
1817 extern int      getchar(void);
1818 extern char     *gets(char *);
1819 extern int      putc(int, FILE *);
1820 extern int      putchar(int);
1821 extern int      puts(const char *);
1822 extern int      ungetc(int, FILE *);
1823 extern size_t   fread(void *, size_t, size_t, FILE *);
1824 extern size_t   fwrite(const void *, size_t, size_t, FILE *);
1825 extern int      fgetpos(FILE *, fpos_t *);
1826 extern int      fseek(FILE *, long, int);
1827 extern int      fsetpos(FILE *, const fpos_t *);
1828 extern long     ftell(FILE *);
1829 extern void     rewind(FILE *);
1830 extern void     clearerr(FILE *);
1831 extern int      feof(FILE *);
1832 extern int      ferror(FILE *);
1833 extern void     perror(const char *);
1834
1835 extern int      __filbuf(FILE *);
1836 extern int      __flsbuf(int, FILE *);
1837
1838  
1839
1840
1841
1842
1843
1844 extern FILE     *fdopen(int, const char *);
1845 extern char     *ctermid(char *);
1846 extern int      fileno(FILE *);
1847
1848
1849
1850  
1851
1852
1853
1854
1855  
1856
1857
1858
1859
1860 extern FILE     *popen(const char *, const char *);
1861 extern char     *cuserid(char *);
1862 extern char     *tempnam(const char *, const char *);
1863 extern int      getopt(int, char *const *, const char *);
1864
1865 extern int      getsubopt(char **, char *const *, char **);
1866
1867 extern char     *optarg;
1868 extern int      optind, opterr, optopt;
1869 extern int      getw(FILE *);
1870 extern int      putw(int, FILE *);
1871 extern int      pclose(FILE *);
1872
1873
1874
1875
1876
1877  
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889 #define         getc(p)         (--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
1890 #define         putc(x, p)      (--(p)->_cnt < 0 ? __flsbuf((unsigned char) (x), (p)) : (int)(*(p)->_ptr++ = (x)))
1891
1892
1893
1894
1895
1896
1897
1898 #define         getchar()       getc(stdin)
1899 #define         putchar(x)      putc((x), stdout)
1900 #define         clearerr(p)     ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
1901 #define         feof(p)         ((p)->_flag & _IOEOF)
1902 #define         ferror(p)       ((p)->_flag & _IOERR)
1903
1904
1905
1906
1907 #define         fileno(p)       ((p)->_file)
1908
1909
1910
1911
1912
1913
1914
1915 }
1916
1917
1918
1919
1920
1921  
1922
1923
1924
1925
1926 #define _SYS_IEEEFP_H
1927
1928 #pragma ident   "@(#)ieeefp.h   2.7 94/11/09"
1929
1930
1931 extern "C" {
1932
1933
1934  
1935
1936
1937
1938 enum fp_direction_type {         
1939         fp_nearest      = 0,
1940         fp_tozero       = 1,
1941         fp_positive     = 2,
1942         fp_negative     = 3
1943 };
1944
1945 enum fp_precision_type {         
1946         fp_extended     = 0,
1947         fp_single       = 1,
1948         fp_double       = 2,
1949         fp_precision_3  = 3
1950 };
1951
1952 enum fp_exception_type {         
1953         fp_inexact      = 0,
1954         fp_division     = 1,
1955         fp_underflow    = 2,
1956         fp_overflow     = 3,
1957         fp_invalid      = 4
1958 };
1959
1960 enum fp_trap_enable_type {       
1961         fp_trap_inexact = 0,
1962         fp_trap_division        = 1,
1963         fp_trap_underflow       = 2,
1964         fp_trap_overflow        = 3,
1965         fp_trap_invalid = 4
1966 };
1967
1968
1969
1970
1971
1972
1973 enum fp_class_type {             
1974         fp_zero         = 0,
1975         fp_subnormal    = 1,
1976         fp_normal       = 2,
1977         fp_infinity     = 3,
1978         fp_quiet        = 4,
1979         fp_signaling    = 5
1980 };
1981
1982
1983 }
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999 #define N_IEEE_EXCEPTION 5      
2000
2001 typedef int sigfpe_code_type;    
2002
2003 typedef void (*sigfpe_handler_type)();   
2004
2005 #define SIGFPE_DEFAULT (void (*)())0    
2006 #define SIGFPE_IGNORE  (void (*)())1    
2007 #define SIGFPE_ABORT   (void (*)())2    
2008
2009 extern sigfpe_handler_type sigfpe  (sigfpe_code_type, sigfpe_handler_type)  ;
2010
2011  
2012
2013
2014 typedef float single;                   
2015
2016
2017 #define _EXTENDED
2018 typedef unsigned extended[3];
2019
2020
2021 typedef long double quadruple;   
2022
2023 typedef unsigned fp_exception_field_type;
2024                                  
2025
2026
2027
2028  
2029
2030
2031 #define DECIMAL_STRING_LENGTH 512       
2032
2033 typedef char decimal_string[512 ];      
2034                                  
2035
2036 typedef struct {
2037         enum fp_class_type fpclass;
2038         int     sign;
2039         int     exponent;
2040         decimal_string ds;       
2041
2042
2043         int     more;            
2044
2045
2046         int     ndigits;         
2047
2048
2049 } decimal_record;
2050
2051 enum decimal_form {
2052         fixed_form,              
2053
2054
2055         floating_form            
2056
2057 };
2058
2059 typedef struct {
2060         enum fp_direction_type rd;      
2061                                  
2062         enum decimal_form df;    
2063
2064         int ndigits;             
2065 } decimal_mode;
2066
2067 enum decimal_string_form {       
2068         invalid_form,            
2069         whitespace_form,         
2070         fixed_int_form,          
2071         fixed_intdot_form,       
2072         fixed_dotfrac_form,      
2073         fixed_intdotfrac_form,   
2074         floating_int_form,              
2075         floating_intdot_form,    
2076         floating_dotfrac_form,   
2077         floating_intdotfrac_form, 
2078         inf_form,                
2079         infinity_form,           
2080         nan_form,                
2081         nanstring_form           
2082 };
2083
2084 extern void single_to_decimal  (single *, decimal_mode *, decimal_record *,
2085                                 fp_exception_field_type *)  ;
2086 extern void double_to_decimal  (double *, decimal_mode *, decimal_record *,
2087                                 fp_exception_field_type *)  ;
2088 extern void extended_to_decimal  (extended *, decimal_mode *,
2089                                 decimal_record *, fp_exception_field_type *)  ;
2090 extern void quadruple_to_decimal  (quadruple *, decimal_mode *,
2091                                 decimal_record *, fp_exception_field_type *)  ;
2092
2093 extern void decimal_to_single  (single *, decimal_mode *, decimal_record *,
2094                                 fp_exception_field_type *)  ;
2095 extern void decimal_to_double  (double *, decimal_mode *, decimal_record *,
2096                                 fp_exception_field_type *)  ;
2097 extern void decimal_to_extended  (extended *, decimal_mode *,
2098                                 decimal_record *, fp_exception_field_type *)  ;
2099 extern void decimal_to_quadruple  (quadruple *, decimal_mode *,
2100                                 decimal_record *, fp_exception_field_type *)  ;
2101
2102 extern void string_to_decimal  (char **, int, int, decimal_record *,
2103                                 enum decimal_string_form *, char **)  ;
2104 extern void func_to_decimal  (char **, int, int, decimal_record *,
2105                                 enum decimal_string_form *, char **,
2106                                 int (*)(void), int *, int (*)(int))  ;
2107 extern void file_to_decimal  (char **, int, int, decimal_record *,
2108                                 enum decimal_string_form *, char **,
2109                                 FILE *, int *)  ;
2110
2111 extern char *seconvert  (single *, int, int *, int *, char *)  ;
2112 extern char *sfconvert  (single *, int, int *, int *, char *)  ;
2113 extern char *sgconvert  (single *, int, int, char *)  ;
2114 extern char *econvert  (double, int, int *, int *, char *)  ;
2115 extern char *fconvert  (double, int, int *, int *, char *)  ;
2116 extern char *gconvert  (double, int, int, char *)  ;
2117 extern char *qeconvert  (quadruple *, int, int *, int *, char *)  ;
2118 extern char *qfconvert  (quadruple *, int, int *, int *, char *)  ;
2119 extern char *qgconvert  (quadruple *, int, int, char *)  ;
2120
2121 extern char *ecvt  (double, int, int *, int *)  ;
2122 extern char *fcvt  (double, int, int *, int *)  ;
2123 extern char *gcvt  (double, int, char *)  ;
2124
2125  
2126
2127
2128
2129 extern double atof  (const char *)  ;
2130 extern double strtod  (const char *, char **)  ;
2131
2132
2133 }
2134
2135
2136
2137
2138
2139
2140
2141
2142 }
2143
2144
2145
2146
2147  
2148  
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168 #pragma interface
2169
2170 #define _String_h 1
2171
2172
2173  
2174  
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194 #pragma interface
2195
2196 #define _Regex_h 1
2197
2198
2199
2200
2201
2202
2203
2204 struct re_pattern_buffer;        
2205 struct re_registers;
2206
2207 class Regex
2208 {
2209 private:
2210
2211                      Regex(const Regex&) {}   
2212   void               operator = (const Regex&) {}  
2213
2214 protected:
2215   re_pattern_buffer* buf;
2216   re_registers*      reg;
2217
2218 public:
2219                      Regex(const char* t,
2220                            int fast = 0,
2221                            int bufsize = 40,
2222                            const char* transtable = 0);
2223
2224                     ~Regex();
2225
2226   int                match(const char* s, int len, int pos = 0) const;
2227   int                search(const char* s, int len,
2228                             int& matchlen, int startpos = 0) const;
2229   int                match_info(int& start, int& length, int nth = 0) const;
2230
2231   int                OK() const;   
2232 };
2233
2234  
2235
2236  
2237  
2238  
2239  
2240  
2241  
2242  
2243  
2244  
2245  
2246
2247
2248
2249
2250
2251 struct StrRep                      
2252 {
2253   unsigned short    len;          
2254   unsigned short    sz;           
2255   char              s[1];         
2256                                   
2257                                   
2258 };
2259
2260  
2261
2262 StrRep*     Salloc(StrRep*, const char*, int, int);
2263 StrRep*     Scopy(StrRep*, const StrRep*);
2264 StrRep*     Scat(StrRep*, const char*, int, const char*, int);
2265 StrRep*     Scat(StrRep*, const char*, int,const char*,int, const char*,int);
2266 StrRep*     Sprepend(StrRep*, const char*, int);
2267 StrRep*     Sreverse(const StrRep*, StrRep*);
2268 StrRep*     Supcase(const StrRep*, StrRep*);
2269 StrRep*     Sdowncase(const StrRep*, StrRep*);
2270 StrRep*     Scapitalize(const StrRep*, StrRep*);
2271
2272  
2273
2274 class String;
2275 class SubString;
2276
2277 class SubString
2278 {
2279   friend class      String;
2280 protected:
2281
2282   String&           S;         
2283   unsigned short    pos;       
2284   unsigned short    len;       
2285
2286   void              assign(const StrRep*, const char*, int = -1);
2287                     SubString(String& x, int p, int l);
2288
2289 public:
2290                     SubString(const SubString& x);  
2291
2292  
2293  
2294
2295                    ~SubString();
2296
2297   SubString&        operator =  (const String&     y);
2298   SubString&        operator =  (const SubString&  y);
2299   SubString&        operator =  (const char* t);
2300   SubString&        operator =  (char        c);
2301
2302  
2303
2304   int               contains(char        c) const;
2305   int               contains(const String&     y) const;
2306   int               contains(const SubString&  y) const;
2307   int               contains(const char* t) const;
2308   int               contains(const Regex&       r) const;
2309
2310  
2311
2312   int               matches(const Regex&  r) const;
2313
2314  
2315
2316   friend ostream&   operator<<(ostream& s, const SubString& x);
2317
2318  
2319
2320   unsigned int      length() const;
2321   int               empty() const;
2322   const char*       chars() const;
2323
2324   int               OK() const;
2325
2326 };
2327
2328
2329 class String
2330 {
2331   friend class      SubString;
2332
2333 protected:
2334   StrRep*           rep;    
2335
2336  
2337
2338   int               search(int, int, const char*, int = -1) const;
2339   int               search(int, int, char) const;
2340   int               match(int, int, int, const char*, int = -1) const;
2341   int               _gsub(const char*, int, const char* ,int);
2342   int               _gsub(const Regex&, const char*, int);
2343   SubString         _substr(int, int);
2344
2345 public:
2346
2347  
2348
2349                     String();
2350                     String(const String& x);
2351                     String(const SubString&  x);
2352                     String(const char* t);
2353                     String(const char* t, int len);
2354                     String(char c);
2355
2356                     ~String();
2357
2358   String&           operator =  (const String&     y);
2359   String&           operator =  (const char* y);
2360   String&           operator =  (char        c);
2361   String&           operator =  (const SubString&  y);
2362
2363  
2364
2365   String&           operator += (const String&     y);
2366   String&           operator += (const SubString&  y);
2367   String&           operator += (const char* t);
2368   String&           operator += (char        c);
2369
2370   void              prepend(const String&     y);
2371   void              prepend(const SubString&  y);
2372   void              prepend(const char* t);
2373   void              prepend(char        c);
2374
2375
2376  
2377  
2378
2379   friend inline void     cat(const String&, const String&, String&);
2380   friend inline void     cat(const String&, const SubString&, String&);
2381   friend inline void     cat(const String&, const char*, String&);
2382   friend inline void     cat(const String&, char, String&);
2383
2384   friend inline void     cat(const SubString&, const String&, String&);
2385   friend inline void     cat(const SubString&, const SubString&, String&);
2386   friend inline void     cat(const SubString&, const char*, String&);
2387   friend inline void     cat(const SubString&, char, String&);
2388
2389   friend inline void     cat(const char*, const String&, String&);
2390   friend inline void     cat(const char*, const SubString&, String&);
2391   friend inline void     cat(const char*, const char*, String&);
2392   friend inline void     cat(const char*, char, String&);
2393
2394  
2395  
2396  
2397
2398   friend inline void     cat(const String&,const String&, const String&,String&);
2399   friend inline void     cat(const String&,const String&,const SubString&,String&);
2400   friend inline void     cat(const String&,const String&, const char*, String&);
2401   friend inline void     cat(const String&,const String&, char, String&);
2402   friend inline void     cat(const String&,const SubString&,const String&,String&);
2403   inline friend void     cat(const String&,const SubString&,const SubString&,String&);
2404   friend inline void     cat(const String&,const SubString&, const char*, String&);
2405   friend inline void     cat(const String&,const SubString&, char, String&);
2406   friend inline void     cat(const String&,const char*, const String&,    String&);
2407   friend inline void     cat(const String&,const char*, const SubString&, String&);
2408   friend inline void     cat(const String&,const char*, const char*, String&);
2409   friend inline void     cat(const String&,const char*, char, String&);
2410
2411   friend inline void     cat(const char*, const String&, const String&,String&);
2412   friend inline void     cat(const char*,const String&,const SubString&,String&);
2413   friend inline void     cat(const char*,const String&, const char*, String&);
2414   friend inline void     cat(const char*,const String&, char, String&);
2415   friend inline void     cat(const char*,const SubString&,const String&,String&);
2416   friend inline void     cat(const char*,const SubString&,const SubString&,String&);
2417   friend inline void     cat(const char*,const SubString&, const char*, String&);
2418   friend inline void     cat(const char*,const SubString&, char, String&);
2419   friend inline void     cat(const char*,const char*, const String&,    String&);
2420   friend inline void     cat(const char*,const char*, const SubString&, String&);
2421   friend inline void     cat(const char*,const char*, const char*, String&);
2422   friend inline void     cat(const char*,const char*, char, String&);
2423
2424
2425  
2426
2427  
2428
2429   int               index(char        c, int startpos = 0) const;
2430   int               index(const String&     y, int startpos = 0) const;
2431   int               index(const SubString&  y, int startpos = 0) const;
2432   int               index(const char* t, int startpos = 0) const;
2433   int               index(const Regex&      r, int startpos = 0) const;
2434
2435  
2436
2437   int               contains(char        c) const;
2438   int               contains(const String&     y) const;
2439   int               contains(const SubString&  y) const;
2440   int               contains(const char* t) const;
2441   int               contains(const Regex&      r) const;
2442
2443  
2444  
2445
2446   int               contains(char        c, int pos) const;
2447   int               contains(const String&     y, int pos) const;
2448   int               contains(const SubString&  y, int pos) const;
2449   int               contains(const char* t, int pos) const;
2450   int               contains(const Regex&      r, int pos) const;
2451
2452  
2453
2454   int               matches(char        c, int pos = 0) const;
2455   int               matches(const String&     y, int pos = 0) const;
2456   int               matches(const SubString&  y, int pos = 0) const;
2457   int               matches(const char* t, int pos = 0) const;
2458   int               matches(const Regex&      r, int pos = 0) const;
2459
2460  
2461
2462   int               freq(char        c) const;
2463   int               freq(const String&     y) const;
2464   int               freq(const SubString&  y) const;
2465   int               freq(const char* t) const;
2466
2467  
2468
2469  
2470  
2471  
2472
2473   SubString         at(int         pos, int len);
2474   SubString         operator () (int         pos, int len);  
2475
2476   SubString         at(const String&     x, int startpos = 0);
2477   SubString         at(const SubString&  x, int startpos = 0);
2478   SubString         at(const char* t, int startpos = 0);
2479   SubString         at(char        c, int startpos = 0);
2480   SubString         at(const Regex&      r, int startpos = 0);
2481
2482   SubString         before(int          pos);
2483   SubString         before(const String&      x, int startpos = 0);
2484   SubString         before(const SubString&   x, int startpos = 0);
2485   SubString         before(const char*  t, int startpos = 0);
2486   SubString         before(char         c, int startpos = 0);
2487   SubString         before(const Regex&       r, int startpos = 0);
2488
2489   SubString         through(int          pos);
2490   SubString         through(const String&      x, int startpos = 0);
2491   SubString         through(const SubString&   x, int startpos = 0);
2492   SubString         through(const char*  t, int startpos = 0);
2493   SubString         through(char         c, int startpos = 0);
2494   SubString         through(const Regex&       r, int startpos = 0);
2495
2496   SubString         from(int          pos);
2497   SubString         from(const String&      x, int startpos = 0);
2498   SubString         from(const SubString&   x, int startpos = 0);
2499   SubString         from(const char*  t, int startpos = 0);
2500   SubString         from(char         c, int startpos = 0);
2501   SubString         from(const Regex&       r, int startpos = 0);
2502
2503   SubString         after(int         pos);
2504   SubString         after(const String&     x, int startpos = 0);
2505   SubString         after(const SubString&  x, int startpos = 0);
2506   SubString         after(const char* t, int startpos = 0);
2507   SubString         after(char        c, int startpos = 0);
2508   SubString         after(const Regex&      r, int startpos = 0);
2509
2510
2511  
2512
2513  
2514   void              del(int         pos, int len);
2515
2516  
2517
2518   void              del(const String&     y, int startpos = 0);
2519   void              del(const SubString&  y, int startpos = 0);
2520   void              del(const char* t, int startpos = 0);
2521   void              del(char        c, int startpos = 0);
2522   void              del(const Regex&      r, int startpos = 0);
2523
2524  
2525
2526   int               gsub(const String&     pat, const String&     repl);
2527   int               gsub(const SubString&  pat, const String&     repl);
2528   int               gsub(const char* pat, const String&     repl);
2529   int               gsub(const char* pat, const char* repl);
2530   int               gsub(const Regex&      pat, const String&     repl);
2531
2532  
2533
2534  
2535
2536   friend int        split(const String& x, String res[], int maxn,
2537                           const String& sep);
2538   friend int        split(const String& x, String res[], int maxn,
2539                           const Regex&  sep);
2540
2541   friend String     common_prefix(const String& x, const String& y,
2542                                   int startpos = 0);
2543   friend String     common_suffix(const String& x, const String& y,
2544                                   int startpos = -1);
2545   friend String     replicate(char        c, int n);
2546   friend String     replicate(const String&     y, int n);
2547   friend String     join(String src[], int n, const String& sep);
2548
2549  
2550
2551   friend inline String     reverse(const String& x);
2552   friend inline String     upcase(const String& x);
2553   friend inline String     downcase(const String& x);
2554   friend inline String     capitalize(const String& x);
2555
2556  
2557
2558   void              reverse();
2559   void              upcase();
2560   void              downcase();
2561   void              capitalize();
2562
2563  
2564
2565   char&             operator [] (int i);
2566   const char&       operator [] (int i) const;
2567   char              elem(int i) const;
2568   char              firstchar() const;
2569   char              lastchar() const;
2570
2571  
2572
2573                     operator const char*() const;
2574   const char*       chars() const;
2575
2576
2577  
2578
2579   friend inline ostream&   operator<<(ostream& s, const String& x);
2580   friend ostream&   operator<<(ostream& s, const SubString& x);
2581   friend istream&   operator>>(istream& s, String& x);
2582
2583   friend int        readline(istream& s, String& x,
2584                              char terminator = '\n',
2585                              int discard_terminator = 1);
2586
2587  
2588
2589   unsigned int      length() const;
2590   int               empty() const;
2591
2592  
2593   void              alloc(int newsize);
2594
2595  
2596
2597   int               allocation() const;
2598
2599
2600   void     error(const char* msg) const;
2601
2602   int               OK() const;
2603 };
2604
2605 typedef String StrTmp;  
2606
2607  
2608
2609 int        compare(const String&    x, const String&     y);
2610 int        compare(const String&    x, const SubString&  y);
2611 int        compare(const String&    x, const char* y);
2612 int        compare(const SubString& x, const String&     y);
2613 int        compare(const SubString& x, const SubString&  y);
2614 int        compare(const SubString& x, const char* y);
2615 int        fcompare(const String&   x, const String&     y);  
2616
2617 extern StrRep  _nilStrRep;
2618 extern String _nilString;
2619
2620  
2621
2622 inline unsigned int String::length() const {  return rep->len; }
2623 inline int         String::empty() const { return rep->len == 0; }
2624 inline const char* String::chars() const { return &(rep->s[0]); }
2625 inline int         String::allocation() const { return rep->sz; }
2626
2627 inline unsigned int SubString::length() const { return len; }
2628 inline int         SubString::empty() const { return len == 0; }
2629 inline const char* SubString::chars() const { return &(S.rep->s[pos]); }
2630
2631
2632  
2633
2634 inline String::String()
2635   : rep(&_nilStrRep) {}
2636 inline String::String(const String& x)
2637   : rep(Scopy(0, x.rep)) {}
2638 inline String::String(const char* t)
2639   : rep(Salloc(0, t, -1, -1)) {}
2640 inline String::String(const char* t, int tlen)
2641   : rep(Salloc(0, t, tlen, tlen)) {}
2642 inline String::String(const SubString& y)
2643   : rep(Salloc(0, y.chars(), y.length(), y.length())) {}
2644 inline String::String(char c)
2645   : rep(Salloc(0, &c, 1, 1)) {}
2646
2647 inline String::~String() { if (rep != &_nilStrRep) delete rep; }
2648
2649 inline SubString::SubString(const SubString& x)
2650   :S(x.S), pos(x.pos), len(x.len) {}
2651 inline SubString::SubString(String& x, int first, int l)
2652   :S(x), pos(first), len(l) {}
2653
2654 inline SubString::~SubString() {}
2655
2656  
2657
2658 inline String& String::operator =  (const String& y)
2659 {
2660   rep = Scopy(rep, y.rep);
2661   return *this;
2662 }
2663
2664 inline String& String::operator=(const char* t)
2665 {
2666   rep = Salloc(rep, t, -1, -1);
2667   return *this;
2668 }
2669
2670 inline String& String::operator=(const SubString&  y)
2671 {
2672   rep = Salloc(rep, y.chars(), y.length(), y.length());
2673   return *this;
2674 }
2675
2676 inline String& String::operator=(char c)
2677 {
2678   rep = Salloc(rep, &c, 1, 1);
2679   return *this;
2680 }
2681
2682
2683 inline SubString& SubString::operator = (const char* ys)
2684 {
2685   assign(0, ys);
2686   return *this;
2687 }
2688
2689 inline SubString& SubString::operator = (char ch)
2690 {
2691   assign(0, &ch, 1);
2692   return *this;
2693 }
2694
2695 inline SubString& SubString::operator = (const String& y)
2696 {
2697   assign(y.rep, y.chars(), y.length());
2698   return *this;
2699 }
2700
2701 inline SubString& SubString::operator = (const SubString& y)
2702 {
2703   assign(y.S.rep, y.chars(), y.length());
2704   return *this;
2705 }
2706
2707  
2708
2709 inline void cat(const String& x, const String& y, String& r)
2710 {
2711   r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length());
2712 }
2713
2714 inline void cat(const String& x, const SubString& y, String& r)
2715 {
2716   r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length());
2717 }
2718
2719 inline void cat(const String& x, const char* y, String& r)
2720 {
2721   r.rep = Scat(r.rep, x.chars(), x.length(), y, -1);
2722 }
2723
2724 inline void cat(const String& x, char y, String& r)
2725 {
2726   r.rep = Scat(r.rep, x.chars(), x.length(), &y, 1);
2727 }
2728
2729 inline void cat(const SubString& x, const String& y, String& r)
2730 {
2731   r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length());
2732 }
2733
2734 inline void cat(const SubString& x, const SubString& y, String& r)
2735 {
2736   r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length());
2737 }
2738
2739 inline void cat(const SubString& x, const char* y, String& r)
2740 {
2741   r.rep = Scat(r.rep, x.chars(), x.length(), y, -1);
2742 }
2743
2744 inline void cat(const SubString& x, char y, String& r)
2745 {
2746   r.rep = Scat(r.rep, x.chars(), x.length(), &y, 1);
2747 }
2748
2749 inline void cat(const char* x, const String& y, String& r)
2750 {
2751   r.rep = Scat(r.rep, x, -1, y.chars(), y.length());
2752 }
2753
2754 inline void cat(const char* x, const SubString& y, String& r)
2755 {
2756   r.rep = Scat(r.rep, x, -1, y.chars(), y.length());
2757 }
2758
2759 inline void cat(const char* x, const char* y, String& r)
2760 {
2761   r.rep = Scat(r.rep, x, -1, y, -1);
2762 }
2763
2764 inline void cat(const char* x, char y, String& r)
2765 {
2766   r.rep = Scat(r.rep, x, -1, &y, 1);
2767 }
2768
2769 inline void cat(const String& a, const String& x, const String& y, String& r)
2770 {
2771   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length());
2772 }
2773
2774 inline void cat(const String& a, const String& x, const SubString& y, String& r)
2775 {
2776   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length());
2777 }
2778
2779 inline void cat(const String& a, const String& x, const char* y, String& r)
2780 {
2781   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y, -1);
2782 }
2783
2784 inline void cat(const String& a, const String& x, char y, String& r)
2785 {
2786   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), &y, 1);
2787 }
2788
2789 inline void cat(const String& a, const SubString& x, const String& y, String& r)
2790 {
2791   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length());
2792 }
2793
2794 inline void cat(const String& a, const SubString& x, const SubString& y, String& r)
2795 {
2796   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length());
2797 }
2798
2799 inline void cat(const String& a, const SubString& x, const char* y, String& r)
2800 {
2801   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y, -1);
2802 }
2803
2804 inline void cat(const String& a, const SubString& x, char y, String& r)
2805 {
2806   r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), &y, 1);
2807 }
2808
2809 inline void cat(const String& a, const char* x, const String& y, String& r)
2810 {
2811   r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, y.chars(), y.length());
2812 }
2813
2814 inline void cat(const String& a, const char* x, const SubString& y, String& r)
2815 {
2816   r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, y.chars(), y.length());
2817 }
2818
2819 inline void cat(const String& a, const char* x, const char* y, String& r)
2820 {
2821   r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, y, -1);
2822 }
2823
2824 inline void cat(const String& a, const char* x, char y, String& r)
2825 {
2826   r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, &y, 1);
2827 }
2828
2829
2830 inline void cat(const char* a, const String& x, const String& y, String& r)
2831 {
2832   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length());
2833 }
2834
2835 inline void cat(const char* a, const String& x, const SubString& y, String& r)
2836 {
2837   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length());
2838 }
2839
2840 inline void cat(const char* a, const String& x, const char* y, String& r)
2841 {
2842   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y, -1);
2843 }
2844
2845 inline void cat(const char* a, const String& x, char y, String& r)
2846 {
2847   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), &y, 1);
2848 }
2849
2850 inline void cat(const char* a, const SubString& x, const String& y, String& r)
2851 {
2852   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length());
2853 }
2854
2855 inline void cat(const char* a, const SubString& x, const SubString& y, String& r)
2856 {
2857   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length());
2858 }
2859
2860 inline void cat(const char* a, const SubString& x, const char* y, String& r)
2861 {
2862   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y, -1);
2863 }
2864
2865 inline void cat(const char* a, const SubString& x, char y, String& r)
2866 {
2867   r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), &y, 1);
2868 }
2869
2870 inline void cat(const char* a, const char* x, const String& y, String& r)
2871 {
2872   r.rep = Scat(r.rep, a, -1, x, -1, y.chars(), y.length());
2873 }
2874
2875 inline void cat(const char* a, const char* x, const SubString& y, String& r)
2876 {
2877   r.rep = Scat(r.rep, a, -1, x, -1, y.chars(), y.length());
2878 }
2879
2880 inline void cat(const char* a, const char* x, const char* y, String& r)
2881 {
2882   r.rep = Scat(r.rep, a, -1, x, -1, y, -1);
2883 }
2884
2885 inline void cat(const char* a, const char* x, char y, String& r)
2886 {
2887   r.rep = Scat(r.rep, a, -1, x, -1, &y, 1);
2888 }
2889
2890
2891  
2892
2893 inline String& String::operator +=(const String& y)
2894 {
2895   cat(*this, y, *this);
2896   return *this;
2897 }
2898
2899 inline String& String::operator +=(const SubString& y)
2900 {
2901   cat(*this, y, *this);
2902   return *this;
2903 }
2904
2905 inline String& String::operator += (const char* y)
2906 {
2907   cat(*this, y, *this);
2908   return *this;
2909 }
2910
2911 inline String& String:: operator +=(char y)
2912 {
2913   cat(*this, y, *this);
2914   return *this;
2915 }
2916
2917  
2918
2919
2920
2921 inline String operator + (const String& x, const String& y) return r;
2922 {
2923   cat(x, y, r);
2924 }
2925
2926 inline String operator + (const String& x, const SubString& y) return r;
2927 {
2928   cat(x, y, r);
2929 }
2930
2931 inline String operator + (const String& x, const char* y) return r;
2932 {
2933   cat(x, y, r);
2934 }
2935
2936 inline String operator + (const String& x, char y) return r;
2937 {
2938   cat(x, y, r);
2939 }
2940
2941 inline String operator + (const SubString& x, const String& y) return r;
2942 {
2943   cat(x, y, r);
2944 }
2945
2946 inline String operator + (const SubString& x, const SubString& y) return r;
2947 {
2948   cat(x, y, r);
2949 }
2950
2951 inline String operator + (const SubString& x, const char* y) return r;
2952 {
2953   cat(x, y, r);
2954 }
2955
2956 inline String operator + (const SubString& x, char y) return r;
2957 {
2958   cat(x, y, r);
2959 }
2960
2961 inline String operator + (const char* x, const String& y) return r;
2962 {
2963   cat(x, y, r);
2964 }
2965
2966 inline String operator + (const char* x, const SubString& y) return r;
2967 {
2968   cat(x, y, r);
2969 }
2970
2971 inline String reverse(const String& x) return r;
2972 {
2973   r.rep = Sreverse(x.rep, r.rep);
2974 }
2975
2976 inline String upcase(const String& x) return r;
2977 {
2978   r.rep = Supcase(x.rep, r.rep);
2979 }
2980
2981 inline String downcase(const String& x) return r;
2982 {
2983   r.rep = Sdowncase(x.rep, r.rep);
2984 }
2985
2986 inline String capitalize(const String& x) return r;
2987 {
2988   r.rep = Scapitalize(x.rep, r.rep);
2989 }
2990
2991
2992
2993  
2994
2995 inline void String::prepend(const String& y)
2996 {
2997   rep = Sprepend(rep, y.chars(), y.length());
2998 }
2999
3000 inline void String::prepend(const char* y)
3001 {
3002   rep = Sprepend(rep, y, -1);
3003 }
3004
3005 inline void String::prepend(char y)
3006 {
3007   rep = Sprepend(rep, &y, 1);
3008 }
3009
3010 inline void String::prepend(const SubString& y)
3011 {
3012   rep = Sprepend(rep, y.chars(), y.length());
3013 }
3014
3015  
3016
3017
3018 inline void String::reverse()
3019 {
3020   rep = Sreverse(rep, rep);
3021 }
3022
3023
3024 inline void String::upcase()
3025 {
3026   rep = Supcase(rep, rep);
3027 }
3028
3029
3030 inline void String::downcase()
3031 {
3032   rep = Sdowncase(rep, rep);
3033 }
3034
3035
3036 inline void String::capitalize()
3037 {
3038   rep = Scapitalize(rep, rep);
3039 }
3040
3041  
3042
3043 inline char&  String::operator [] (int i)
3044 {
3045   if (((unsigned)i) >= length()) error("invalid index");
3046   return rep->s[i];
3047 }
3048
3049 inline const char&  String::operator [] (int i) const
3050 {
3051   if (((unsigned)i) >= length()) error("invalid index");
3052   return rep->s[i];
3053 }
3054
3055 inline char  String::elem (int i) const
3056 {
3057   if (((unsigned)i) >= length()) error("invalid index");
3058   return rep->s[i];
3059 }
3060
3061 inline char  String::firstchar() const
3062 {
3063   return elem(0);
3064 }
3065
3066 inline char  String::lastchar() const
3067 {
3068   return elem(length() - 1);
3069 }
3070
3071  
3072
3073 inline int String::index(char c, int startpos) const
3074 {
3075   return search(startpos, length(), c);
3076 }
3077
3078 inline int String::index(const char* t, int startpos) const
3079 {
3080   return search(startpos, length(), t);
3081 }
3082
3083 inline int String::index(const String& y, int startpos) const
3084 {
3085   return search(startpos, length(), y.chars(), y.length());
3086 }
3087
3088 inline int String::index(const SubString& y, int startpos) const
3089 {
3090   return search(startpos, length(), y.chars(), y.length());
3091 }
3092
3093 inline int String::index(const Regex& r, int startpos) const
3094 {
3095   int unused;  return r.search(chars(), length(), unused, startpos);
3096 }
3097
3098 inline int String::contains(char c) const
3099 {
3100   return search(0, length(), c) >= 0;
3101 }
3102
3103 inline int String::contains(const char* t) const
3104 {
3105   return search(0, length(), t) >= 0;
3106 }
3107
3108 inline int String::contains(const String& y) const
3109 {
3110   return search(0, length(), y.chars(), y.length()) >= 0;
3111 }
3112
3113 inline int String::contains(const SubString& y) const
3114 {
3115   return search(0, length(), y.chars(), y.length()) >= 0;
3116 }
3117
3118 inline int String::contains(char c, int p) const
3119 {
3120   return match(p, length(), 0, &c, 1) >= 0;
3121 }
3122
3123 inline int String::contains(const char* t, int p) const
3124 {
3125   return match(p, length(), 0, t) >= 0;
3126 }
3127
3128 inline int String::contains(const String& y, int p) const
3129 {
3130   return match(p, length(), 0, y.chars(), y.length()) >= 0;
3131 }
3132
3133 inline int String::contains(const SubString& y, int p) const
3134 {
3135   return match(p, length(), 0, y.chars(), y.length()) >= 0;
3136 }
3137
3138 inline int String::contains(const Regex& r) const
3139 {
3140   int unused;  return r.search(chars(), length(), unused, 0) >= 0;
3141 }
3142
3143 inline int String::contains(const Regex& r, int p) const
3144 {
3145   return r.match(chars(), length(), p) >= 0;
3146 }
3147
3148
3149 inline int String::matches(const SubString& y, int p) const
3150 {
3151   return match(p, length(), 1, y.chars(), y.length()) >= 0;
3152 }
3153
3154 inline int String::matches(const String& y, int p) const
3155 {
3156   return match(p, length(), 1, y.chars(), y.length()) >= 0;
3157 }
3158
3159 inline int String::matches(const char* t, int p) const
3160 {
3161   return match(p, length(), 1, t) >= 0;
3162 }
3163
3164 inline int String::matches(char c, int p) const
3165 {
3166   return match(p, length(), 1, &c, 1) >= 0;
3167 }
3168
3169 inline int String::matches(const Regex& r, int p) const
3170 {
3171   int l = (p < 0)? -p : length() - p;
3172   return r.match(chars(), length(), p) == l;
3173 }
3174
3175
3176 inline int SubString::contains(const char* t) const
3177 {
3178   return S.search(pos, pos+len, t) >= 0;
3179 }
3180
3181 inline int SubString::contains(const String& y) const
3182 {
3183   return S.search(pos, pos+len, y.chars(), y.length()) >= 0;
3184 }
3185
3186 inline int SubString::contains(const SubString&  y) const
3187 {
3188   return S.search(pos, pos+len, y.chars(), y.length()) >= 0;
3189 }
3190
3191 inline int SubString::contains(char c) const
3192 {
3193   return S.search(pos, pos+len, c) >= 0;
3194 }
3195
3196 inline int SubString::contains(const Regex& r) const
3197 {
3198   int unused;  return r.search(chars(), len, unused, 0) >= 0;
3199 }
3200
3201 inline int SubString::matches(const Regex& r) const
3202 {
3203   return r.match(chars(), len, 0) == len;
3204 }
3205
3206
3207 inline int String::gsub(const String& pat, const String& r)
3208 {
3209   return _gsub(pat.chars(), pat.length(), r.chars(), r.length());
3210 }
3211
3212 inline int String::gsub(const SubString&  pat, const String& r)
3213 {
3214   return _gsub(pat.chars(), pat.length(), r.chars(), r.length());
3215 }
3216
3217 inline int String::gsub(const Regex& pat, const String& r)
3218 {
3219   return _gsub(pat, r.chars(), r.length());
3220 }
3221
3222 inline int String::gsub(const char* pat, const String& r)
3223 {
3224   return _gsub(pat, -1, r.chars(), r.length());
3225 }
3226
3227 inline int String::gsub(const char* pat, const char* r)
3228 {
3229   return _gsub(pat, -1, r, -1);
3230 }
3231
3232
3233
3234 inline  ostream& operator<<(ostream& s, const String& x)
3235 {
3236    s << x.chars(); return s;
3237 }
3238
3239  
3240
3241 inline int operator==(const String& x, const String& y)
3242 {
3243   return compare(x, y) == 0;
3244 }
3245
3246 inline int operator!=(const String& x, const String& y)
3247 {
3248   return compare(x, y) != 0;
3249 }
3250
3251 inline int operator>(const String& x, const String& y)
3252 {
3253   return compare(x, y) > 0;
3254 }
3255
3256 inline int operator>=(const String& x, const String& y)
3257 {
3258   return compare(x, y) >= 0;
3259 }
3260
3261 inline int operator<(const String& x, const String& y)
3262 {
3263   return compare(x, y) < 0;
3264 }
3265
3266 inline int operator<=(const String& x, const String& y)
3267 {
3268   return compare(x, y) <= 0;
3269 }
3270
3271 inline int operator==(const String& x, const SubString&  y)
3272 {
3273   return compare(x, y) == 0;
3274 }
3275
3276 inline int operator!=(const String& x, const SubString&  y)
3277 {
3278   return compare(x, y) != 0;
3279 }
3280
3281 inline int operator>(const String& x, const SubString&  y)
3282 {
3283   return compare(x, y) > 0;
3284 }
3285
3286 inline int operator>=(const String& x, const SubString&  y)
3287 {
3288   return compare(x, y) >= 0;
3289 }
3290
3291 inline int operator<(const String& x, const SubString&  y)
3292 {
3293   return compare(x, y) < 0;
3294 }
3295
3296 inline int operator<=(const String& x, const SubString&  y)
3297 {
3298   return compare(x, y) <= 0;
3299 }
3300
3301 inline int operator==(const String& x, const char* t)
3302 {
3303   return compare(x, t) == 0;
3304 }
3305
3306 inline int operator!=(const String& x, const char* t)
3307 {
3308   return compare(x, t) != 0;
3309 }
3310
3311 inline int operator>(const String& x, const char* t)
3312 {
3313   return compare(x, t) > 0;
3314 }
3315
3316 inline int operator>=(const String& x, const char* t)
3317 {
3318   return compare(x, t) >= 0;
3319 }
3320
3321 inline int operator<(const String& x, const char* t)
3322 {
3323   return compare(x, t) < 0;
3324 }
3325
3326 inline int operator<=(const String& x, const char* t)
3327 {
3328   return compare(x, t) <= 0;
3329 }
3330
3331 inline int operator==(const SubString& x, const String& y)
3332 {
3333   return compare(y, x) == 0;
3334 }
3335
3336 inline int operator!=(const SubString& x, const String& y)
3337 {
3338   return compare(y, x) != 0;
3339 }
3340
3341 inline int operator>(const SubString& x, const String& y)
3342 {
3343   return compare(y, x) < 0;
3344 }
3345
3346 inline int operator>=(const SubString& x, const String& y)
3347 {
3348   return compare(y, x) <= 0;
3349 }
3350
3351 inline int operator<(const SubString& x, const String& y)
3352 {
3353   return compare(y, x) > 0;
3354 }
3355
3356 inline int operator<=(const SubString& x, const String& y)
3357 {
3358   return compare(y, x) >= 0;
3359 }
3360
3361 inline int operator==(const SubString& x, const SubString&  y)
3362 {
3363   return compare(x, y) == 0;
3364 }
3365
3366 inline int operator!=(const SubString& x, const SubString&  y)
3367 {
3368   return compare(x, y) != 0;
3369 }
3370
3371 inline int operator>(const SubString& x, const SubString&  y)
3372 {
3373   return compare(x, y) > 0;
3374 }
3375
3376 inline int operator>=(const SubString& x, const SubString&  y)
3377 {
3378   return compare(x, y) >= 0;
3379 }
3380
3381 inline int operator<(const SubString& x, const SubString&  y)
3382 {
3383   return compare(x, y) < 0;
3384 }
3385
3386 inline int operator<=(const SubString& x, const SubString&  y)
3387 {
3388   return compare(x, y) <= 0;
3389 }
3390
3391 inline int operator==(const SubString& x, const char* t)
3392 {
3393   return compare(x, t) == 0;
3394 }
3395
3396 inline int operator!=(const SubString& x, const char* t)
3397 {
3398   return compare(x, t) != 0;
3399 }
3400
3401 inline int operator>(const SubString& x, const char* t)
3402 {
3403   return compare(x, t) > 0;
3404 }
3405
3406 inline int operator>=(const SubString& x, const char* t)
3407 {
3408   return compare(x, t) >= 0;
3409 }
3410
3411 inline int operator<(const SubString& x, const char* t)
3412 {
3413   return compare(x, t) < 0;
3414 }
3415
3416 inline int operator<=(const SubString& x, const char* t)
3417 {
3418   return compare(x, t) <= 0;
3419 }
3420
3421
3422  
3423
3424 inline SubString String::_substr(int first, int l)
3425 {
3426   if (first < 0 || (unsigned)(first + l) > length() )
3427     return SubString(_nilString, 0, 0) ;
3428   else
3429     return SubString(*this, first, l);
3430 }
3431
3432
3433
3434
3435
3436 #define booleen_hh
3437
3438  
3439 typedef int booleen;
3440
3441 const booleen VRAI=1;
3442 const booleen FAUX=0;
3443
3444
3445
3446
3447 #define valeur_bidon 12345678
3448
3449 #define fors(type, i, imin, imax) for(type i=imin; i< imax; i++)
3450 #define fore(type, i, imin, imax) for(type i=imin; i<=imax; i++)
3451
3452 void verif_nb_param(int argc, char* argv[], int nb_params);
3453
3454 booleen f_exists(String nom);
3455
3456  
3457 template<class Type>
3458 inline Type carre(const Type x)
3459 {
3460   return x*x;
3461 }
3462
3463 template<class Type>
3464 inline Type cube(const Type x)
3465 {
3466   return x*x*x;
3467 }
3468
3469 template<class Type>
3470 inline Type rac3(const Type x)
3471 {
3472   if(fabs(x)<1E-5)
3473     return 0;
3474   else
3475     if(x>0)
3476       return exp(log(x)/3);
3477     else
3478       return -exp(log(-x)/3);
3479 }
3480
3481 template<class Type>
3482 inline Type min(const Type a,const Type b)
3483 {
3484   return (a>b)?b:a;
3485 }
3486
3487 template<class Type>
3488 inline Type max(const Type a,const Type b)
3489 {
3490   return (a<b)?b:a;
3491 }
3492
3493 template<class Type>
3494 inline Type min(const Type a,const Type b,const Type c)
3495 {
3496   return min(a,min(b,c));
3497 }
3498
3499 template<class Type>
3500 inline Type max(const Type a,const Type b,const Type c)
3501 {
3502   return max(a,max(b,c));
3503 }
3504
3505 template <class Type>
3506 inline void echange(Type& a,Type& b)
3507 {
3508   Type t=a;
3509   a=b;
3510   b=t;
3511 }
3512
3513  
3514 String i2S(int n,int l=0);
3515
3516 template <class Type>
3517 inline booleen dans(Type x, Type a, Type b)
3518 {
3519   return (a<=x) && (x<=b);
3520 }
3521
3522 template <class Type>
3523 inline Type mabs(Type x)
3524 {
3525   return (x<0) ? -x : x ;
3526 }
3527
3528 template <class Type>
3529 inline booleen dans2(Type x, Type a, Type b)       
3530    
3531 {
3532   return mabs(x-(a+b)/2) <= mabs((a-b)/2) ;
3533 }
3534
3535 template <class Type>
3536 inline booleen proche(Type x, Type y, Type eps)
3537 {
3538   return mabs(x-y)<eps;                            
3539 }
3540
3541 template <class Type>
3542 inline int arrondi(Type x)
3543 {
3544   return int(x+0.5);
3545 }
3546
3547 template<class Type>
3548 unsigned char arrondi_ng(Type x)
3549 {
3550   if((-0.5<x) && (x<255.5))
3551     return (unsigned char)(x+0.5);
3552   else
3553   {
3554     if(x<-3.0 || x>268.0)
3555       cerr<<"arrondi_ng : attention x= "<<x<<endl;
3556      
3557     if(x<0.0)
3558       return 0;
3559     else
3560       return 255;
3561   }
3562 }
3563
3564 template<class Type>
3565 unsigned char arrondi_ng_err(Type x)
3566 {
3567   if((-0.5<x) && (x<255.5))
3568     return (unsigned char)(x+0.5);
3569   else
3570   {
3571     if(x<0.0)
3572       return 0;
3573     else
3574       return 255;
3575   }
3576 }
3577
3578 inline int nb_diff2(int a,int b)                   
3579 {
3580   if(a==b)
3581     return 1;
3582   else
3583     return 2;
3584 }
3585
3586 inline int nb_diff3(int a,int b,int c)             
3587 {
3588   if(a==b || a==c)
3589     return nb_diff2(b,c);
3590   else
3591     return 1+nb_diff2(b,c);
3592 }
3593
3594 inline int nb_diff4(int a,int b,int c,int d)       
3595 {
3596   if(a==b || a==c || a==d)
3597     return nb_diff3(b,c,d);
3598   else
3599     return 1+nb_diff3(b,c,d);
3600 }
3601
3602 float echMSB(float a);
3603
3604 void plante();                                     
3605 void arrete();                                     
3606
3607 void touche();                                     
3608
3609 template<class Type>
3610 void lis_param(istream& f, Type& param)
3611 {
3612   f>>param;
3613   f.ignore(20000,'\n');                            
3614 }
3615
3616 void lis_chaine(istream& s, String chaine);
3617
3618 template<class Type_dest, class Type_source>
3619 void convert(Type_dest& dest, const Type_source& source)
3620 {
3621   dest=source;
3622 }
3623
3624
3625
3626
3627 struct Vect2Dent
3628 {
3629   int di;
3630   int dj;
3631 };
3632
3633
3634
3635
3636
3637
3638 struct depl2D
3639 {
3640   double x;
3641   double y;
3642   depl2D() : x(0.0), y(0.0)
3643   { }
3644    
3645    
3646   depl2D(double xx, double yy) : x(xx), y(yy)
3647   { }
3648   double amplitude()
3649   {
3650     return max(mabs(x),mabs(y));
3651   }
3652 };
3653
3654 ostream& operator<<(ostream& s, depl2D m);
3655
3656 class Mouvement
3657 {
3658 private:
3659   Mouvement* read_mv(istream& s);
3660 protected:
3661   double t_x;
3662   double t_y;
3663   double centre_x;
3664   double centre_y;
3665 public:
3666   Mouvement();
3667   Mouvement(double i_t_x, double i_t_y, double i_centre_x, double i_centre_y);
3668   virtual void Id()=0;
3669   virtual void centre(double x,double y)=0;
3670   virtual void applique(double& xx, double& yy, double x, double y) const=0;
3671   virtual void applique(float& xx, float& yy, float x, float y) const=0;
3672   virtual depl2D calc_depl(double x, double y)=0;
3673   double Centre_x() const
3674   {
3675     return centre_x;
3676   }
3677   double Centre_y() const
3678   {
3679     return centre_y;
3680   }
3681
3682   virtual int nb_param() const=0;
3683    
3684    
3685   virtual void init_from_vect_d(const double param[])=0;
3686   virtual void init_vect_d(double param[]) const=0;
3687   virtual void init_from_vect_f(const float param[])=0;
3688   virtual void init_vect_f(float param[]) const=0;
3689
3690   virtual Mouvement* clone() const=0;
3691   virtual String nom() const=0;
3692   virtual void dump(ostream& s) const=0;
3693
3694   virtual booleen trop_grand(float seuil) const=0;
3695   booleen trop_grand2(float seuil, float seuil_t) const;
3696 };
3697
3698 ostream& operator<<(ostream& s, const Mouvement& m);
3699 Mouvement* read_mv(istream& s);
3700
3701
3702
3703
3704 class AFF;
3705
3706 class LS : public Mouvement
3707 {
3708 protected:
3709   double k;
3710   double theta;
3711 public:
3712   LS();
3713   LS(double i_t_x, double i_t_y, double i_k, double i_theta, double i_centre_x, double i_centre_y);
3714   LS(istream& s);
3715   LS(const AFF& aff);
3716   int nb_param() const;
3717   void update(double d_t_x, double d_t_y, double d_k, double d_theta);
3718   void init_from_vect_d(const double param[]);
3719   void init_vect_d(double param[]) const;
3720   void init_from_vect_f(const float param[]);
3721   void init_vect_f(float param[]) const;
3722   friend class AFF;
3723   void dump(ostream& s) const;
3724 };
3725
3726 ostream& operator<<(ostream& s, const LS& m);
3727
3728
3729
3730
3731 #define AFF_hh
3732
3733
3734
3735 class LS;
3736
3737 class AFF: public Mouvement
3738 {
3739 protected:
3740   double a;
3741   double b;
3742   double c;
3743   double d;
3744 public:
3745   AFF();
3746   AFF(double i_t_x, double i_t_y,
3747       double i_a, double i_b, double i_c, double i_d,
3748       double i_centre_x, double i_centre_y);
3749   AFF(istream& s);
3750   AFF(const LS& ls);
3751   int nb_param() const;
3752   void init_from_vect_d(const double param[]);
3753   void init_vect_d(double param[]) const;
3754   void init_from_vect_f(const float param[]);
3755   void init_vect_f(float param[]) const;
3756
3757   friend class LS;
3758   void dump(ostream& s) const;
3759 };
3760
3761 ostream& operator<<(ostream& s, const AFF& m);
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771 LS::LS() :
3772   k(0.0), theta(0.0)
3773 { }
3774
3775 LS::LS(double i_t_x, double i_t_y,
3776        double i_k, double i_theta,
3777        double i_centre_x, double i_centre_y) :
3778   Mouvement(i_t_x, i_t_y, i_centre_x, i_centre_y),
3779   k(i_k),
3780   theta(i_theta)
3781 { }
3782
3783 LS::LS(istream& s)
3784 {
3785   s>>k>>theta>>t_x>>theta>>k>>t_y>>centre_x>>centre_y;
3786 }
3787
3788 LS::LS(const AFF& aff): Mouvement(aff.t_x, aff.t_y, aff.centre_x, aff.centre_y)
3789 {
3790   const double eps_k=1E-6;
3791   if(mabs(aff.a-aff.d)>eps_k)
3792   {
3793     cout<<"AFF_2_LS :  delta k < "<<eps_k<<endl;
3794     cout<<aff.a<<endl<<aff.d<<endl;
3795     plante();
3796   }
3797   else
3798     k=(aff.a+aff.d)/2;
3799
3800   const double eps_theta=1E-6;
3801   if(mabs(aff.c+aff.b)>eps_theta)
3802   {
3803     cout<<"AFF_2_LS :  delta theta < "<<eps_theta<<endl;
3804     plante();
3805   }
3806   else
3807     theta=(aff.c-aff.b)/2;
3808 }
3809
3810 int LS::nb_param() const
3811 {
3812   return 4;
3813 }
3814
3815 void LS::update(double d_t_x,
3816                 double d_t_y,
3817                 double d_k,
3818                 double d_theta)
3819 {
3820   t_x+=d_t_x;
3821   t_y+=d_t_y;
3822   k+=d_k;
3823   theta+=d_theta;
3824 }
3825
3826 void LS::init_from_vect_d(const double param[])
3827 {
3828   t_x=param[0];
3829   t_y=param[1];
3830   k=param[2];
3831   theta=param[3];
3832 }
3833
3834 void LS::init_vect_d(double param[]) const
3835 {
3836   param[0]=t_x;
3837   param[1]=t_y;
3838   param[2]=k;
3839   param[3]=theta;
3840 }
3841
3842 void LS::init_from_vect_f(const float param[])
3843 {
3844   t_x=param[0];
3845   t_y=param[1];
3846   k=param[2];
3847   theta=param[3];
3848 }
3849
3850 void LS::init_vect_f(float param[]) const
3851 {
3852   param[0]=t_x;
3853   param[1]=t_y;
3854   param[2]=k;
3855   param[3]=theta;
3856 }
3857
3858  
3859  
3860  
3861  
3862  
3863  
3864  
3865  
3866
3867  
3868  
3869  
3870  
3871
3872 void LS::dump(ostream& s) const
3873 {
3874   const int largeur=14;
3875   s.setf(ios::left,ios::adjustfield);
3876   s<<nom()<<endl
3877    <<setw(largeur)<<k<<setw(largeur)<<-theta<<setw(largeur)<<t_x<<endl
3878    <<setw(largeur)<<theta<<setw(largeur)<<k<<setw(largeur)<<t_y<<endl
3879    <<centre_x<<' '<<centre_y<<endl;
3880 }
3881
3882 ostream& operator<<(ostream& s, const LS& m)
3883 {
3884   m.dump(s);
3885   return s;
3886 }