Changeset 90c3b1c for src/libcfa
- Timestamp:
- Mar 2, 2016, 4:59:19 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- bdad1679
- Parents:
- ac1ed49
- Location:
- src/libcfa
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/Makefile.in
rac1ed49 r90c3b1c 231 231 esac; \ 232 232 done; \ 233 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- gnusrc/libcfa/Makefile'; \233 echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/libcfa/Makefile'; \ 234 234 $(am__cd) $(top_srcdir) && \ 235 $(AUTOMAKE) -- gnusrc/libcfa/Makefile235 $(AUTOMAKE) --foreign src/libcfa/Makefile 236 236 .PRECIOUS: Makefile 237 237 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status -
src/libcfa/builtins.cf
rac1ed49 r90c3b1c 390 390 int __builtin_sprintf(char *, const char *, ...); 391 391 int __builtin_sscanf(const char *, const char *, ...); 392 int __builtin_vfprintf(struct _IO_FILE *, const char *, void **);393 int __builtin_vfscanf(struct _IO_FILE *, const char *, void **);394 int __builtin_vprintf(const char *, void **);395 int __builtin_vscanf(const char *, void **);396 int __builtin_vsnprintf(char *, unsigned long, const char *, void **);397 int __builtin_vsprintf(char *, const char *, void **);398 int __builtin_vsscanf(const char *, const char *, void **);392 int __builtin_vfprintf(struct _IO_FILE *, const char *, __builtin_va_list); 393 int __builtin_vfscanf(struct _IO_FILE *, const char *, __builtin_va_list); 394 int __builtin_vprintf(const char *, __builtin_va_list); 395 int __builtin_vscanf(const char *, __builtin_va_list); 396 int __builtin_vsnprintf(char *, unsigned long, const char *, __builtin_va_list); 397 int __builtin_vsprintf(char *, const char *, __builtin_va_list); 398 int __builtin_vsscanf(const char *, const char *, __builtin_va_list); 399 399 int __builtin_isalnum(int); 400 400 int __builtin_isalpha(int); … … 534 534 void __builtin_unwind_init(); 535 535 void __builtin_update_setjmp_buf(void *, int); 536 void __builtin_va_copy( void **, void **);537 void __builtin_va_end( void **);538 void __builtin_va_start( void **, ...);536 void __builtin_va_copy(__builtin_va_list, __builtin_va_list); 537 void __builtin_va_end(__builtin_va_list); 538 void __builtin_va_start(__builtin_va_list, ...); 539 539 int __builtin_va_arg_pack(); 540 540 int __builtin_va_arg_pack_len(); … … 563 563 int __builtin___snprintf_chk(char *, unsigned long, int, unsigned long, const char *, ...); 564 564 int __builtin___sprintf_chk(char *, int, unsigned long, const char *, ...); 565 int __builtin___vsnprintf_chk(char *, unsigned long, int, unsigned long, const char *, void **);566 int __builtin___vsprintf_chk(char *, int, unsigned long, const char *, void **);565 int __builtin___vsnprintf_chk(char *, unsigned long, int, unsigned long, const char *, __builtin_va_list); 566 int __builtin___vsprintf_chk(char *, int, unsigned long, const char *, __builtin_va_list); 567 567 int __builtin___fprintf_chk(struct _IO_FILE *, int, const char *, ...); 568 568 int __builtin___printf_chk(int, const char *, ...); 569 int __builtin___vfprintf_chk(struct _IO_FILE *, int, const char *, void **);570 int __builtin___vprintf_chk(int, const char *, void **);569 int __builtin___vfprintf_chk(struct _IO_FILE *, int, const char *, __builtin_va_list); 570 int __builtin___vprintf_chk(int, const char *, __builtin_va_list); 571 571 void __cyg_profile_func_enter(void *, void *); 572 572 void __cyg_profile_func_exit(void *, void *); … … 583 583 const char * __builtin_FUNCTION(); 584 584 int __builtin_LINE(); 585 typedef void ** __builtin_va_list;586 585 extern const char *__PRETTY_FUNCTION__; 587 586 typedef int wchar_t; -
src/libcfa/fstream
rac1ed49 r90c3b1c 7 7 // fstream -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:02:01201613 // Update Count : 2212 // Last Modified On : Wed Mar 2 15:08:14 2016 13 // Update Count : 78 14 14 // 15 15 … … 19 19 #include "iostream" 20 20 21 // implement context ostream 22 struct ofstream ;21 enum { separateSize = 16 }; 22 struct ofstream { void *file; int separate; char separator[separateSize]; }; 23 23 24 int fail( ofstream * os ); 25 int flush( ofstream * os ); 26 void open( ofstream ** os, const char * name, const char * mode ); 27 void close( ofstream * os ); 28 ofstream * write( ofstream * os, const char * data, streamsize_type size ); 24 _Bool sepPrt( ofstream * ); 25 void sepOn( ofstream * ); 26 void sepOff( ofstream * ); 27 void sepSet( ofstream *, const char * ); 28 const char * sepGet( ofstream * ); 29 void sepDisable( ofstream * ); 30 void sepEnable( ofstream * ); 31 int fail( ofstream * ); 32 int flush( ofstream * ); 33 void open( ofstream *, const char * name, const char * mode ); 34 void close( ofstream * ); 35 ofstream * write( ofstream *, const char * data, unsigned long int size ); 36 int prtfmt( ofstream *, const char fmt[], ... ); 29 37 30 38 extern ofstream * sout, * serr; 31 39 32 40 // implement context istream 33 struct ifstream ;41 struct ifstream { void *file; }; 34 42 35 43 int fail( ifstream * is ); 36 44 int eof( ifstream * is ); 37 void open( ifstream * *is, const char * name, const char * mode );45 void open( ifstream * is, const char * name, const char * mode ); 38 46 void close( ifstream * is ); 39 ifstream * get( ifstream * is, int * data ); 40 ifstream * read( ifstream * is, char * data, streamsize_type size ); 47 ifstream * read( ifstream * is, char * data, unsigned long int size ); 41 48 ifstream * ungetc( ifstream * is, char c ); 49 int scanfmt( ifstream *, const char fmt[], ... ); 42 50 43 51 extern ifstream *sin; … … 49 57 // tab-width: 4 // 50 58 // End: // 59 -
src/libcfa/fstream.c
rac1ed49 r90c3b1c 7 7 // fstream.c -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:03:05201613 // Update Count : 7612 // Last Modified On : Mon Feb 29 18:41:10 2016 13 // Update Count : 162 14 14 // 15 15 … … 17 17 18 18 extern "C" { 19 #include <stdio.h> 20 #include <stdlib.h> 19 #include <stdio.h> // vfprintf, vfscanf 20 #include <stdlib.h> // exit 21 #include <stdarg.h> // varargs 22 #include <string.h> // strlen 23 #include <float.h> // DBL_DIG, LDBL_DIG 24 #include <complex.h> // creal, cimag 21 25 } 22 23 struct ofstream {24 FILE *file;25 };26 26 27 27 #define IO_MSG "I/O error " 28 28 29 _Bool sepPrt( ofstream * os ) { return os->separate == 1; } 30 void sepOn( ofstream * os ) { if ( os->separate != 2 ) os->separate = 1; } 31 void sepOff( ofstream * os ) { if ( os->separate != 2 ) os->separate = 0; } 32 void sepSet( ofstream * os, const char * s ) { 33 strncpy( &(os->separator[0]), s, separateSize - 1 ); 34 os->separator[separateSize - 1] = '\0'; 35 } // sepSet 36 const char * sepGet( ofstream * os ) { return &(os->separator[0]); } 37 void sepDisable( ofstream *os ) { os->separate = 2; } 38 void sepEnable( ofstream *os ) { os->separate = 0; } 39 29 40 int fail( ofstream * os ) { 30 return ferror( os->file);41 return ferror( (FILE *)(os->file) ); 31 42 } // fail 32 43 33 44 int flush( ofstream * os ) { 34 return fflush( os->file);45 return fflush( (FILE *)(os->file) ); 35 46 } // flush 36 47 37 void open( ofstream * *os, const char * name, const char * mode ) {38 FILE * t= fopen( name, mode );39 if ( t == 0 ) {// do not change unless successful48 void open( ofstream * os, const char * name, const char * mode ) { 49 FILE *file = fopen( name, mode ); 50 if ( file == 0 ) { // do not change unless successful 40 51 perror( IO_MSG "open output" ); 41 52 exit( EXIT_FAILURE ); 42 53 } // if 43 (*os)->file = t; 54 os->file = file; 55 sepOff( os ); 56 sepSet( os, " " ); 44 57 } // open 45 58 46 59 void close( ofstream * os ) { 47 if ( os->file == stdout || os->file== stderr ) return;60 if ( (FILE *)(os->file) == stdout || (FILE *)(os->file) == stderr ) return; 48 61 49 if ( fclose( os->file) == EOF ) {62 if ( fclose( (FILE *)(os->file) ) == EOF ) { 50 63 perror( IO_MSG "close output" ); 51 64 } // if 52 65 } // close 53 66 54 ofstream * write( ofstream * os, const char * data, streamsize_typesize ) {67 ofstream * write( ofstream * os, const char * data, unsigned long int size ) { 55 68 if ( fail( os ) ) { 56 69 fprintf( stderr, "attempt write I/O on failed stream\n" ); … … 58 71 } // if 59 72 60 if ( fwrite( data, 1, size, os->file) != size ) {73 if ( fwrite( data, 1, size, (FILE *)(os->file) ) != size ) { 61 74 perror( IO_MSG "write" ); 62 75 exit( EXIT_FAILURE ); … … 65 78 } // write 66 79 67 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) }; 80 int prtfmt( ofstream * os, const char fmt[], ... ) { 81 va_list args; 82 83 va_start( args, fmt ); 84 int len = vfprintf( (FILE *)(os->file), fmt, args ); 85 if ( len == EOF ) { 86 if ( ferror( (FILE *)(os->file) ) ) { 87 fprintf( stderr, "invalid write\n" ); 88 exit( EXIT_FAILURE ); 89 } // if 90 } // if 91 va_end( args ); 92 return len; 93 } // prtfmt 94 95 96 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 0, { ' ', '\0' } }; 68 97 ofstream *sout = &soutFile; 69 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) };98 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 0, { ' ', '\0' } }; 70 99 ofstream *serr = &serrFile; 100 71 101 72 102 //--------------------------------------- 73 103 74 struct ifstream {75 FILE *file;76 };77 104 78 105 int fail( ifstream * is ) { 79 return ferror( is->file);106 return ferror( (FILE *)(is->file) ); 80 107 } // fail 81 108 82 109 int eof( ifstream * is ) { 83 return feof( is->file);110 return feof( (FILE *)(is->file) ); 84 111 } // eof 85 112 86 ifstream * get( ifstream * is, int * data ) { 87 if ( fscanf( is->file, "%d", data ) == EOF ) { 88 if ( ferror( is->file ) ) { 89 fprintf( stderr, "invalid int read\n" ); 90 exit( EXIT_FAILURE ); 91 } // if 113 void open( ifstream * is, const char * name, const char * mode ) { 114 FILE *t = fopen( name, mode ); 115 if ( t == 0 ) { // do not change unless successful 116 perror( IO_MSG "open input" ); 117 exit( EXIT_FAILURE ); 92 118 } // if 93 return is;94 } // read119 is->file = t; 120 } // open 95 121 96 ifstream * read( ifstream * is, char * data, streamsize_type size ) { 122 void close( ifstream * is ) { 123 if ( (FILE *)(is->file) == stdin ) return; 124 125 if ( fclose( (FILE *)(is->file) ) == EOF ) { 126 perror( IO_MSG "close input" ); 127 } // if 128 } // close 129 130 ifstream * read( ifstream * is, char * data, unsigned long int size ) { 97 131 if ( fail( is ) ) { 98 132 fprintf( stderr, "attempt read I/O on failed stream\n" ); … … 100 134 } // if 101 135 102 if ( fread( data, size, 1, is->file) == 0 ) {136 if ( fread( data, size, 1, (FILE *)(is->file) ) == 0 ) { 103 137 perror( IO_MSG "read" ); 104 138 exit( EXIT_FAILURE ); … … 113 147 } // if 114 148 115 if ( ungetc( c, is->file) == EOF ) {149 if ( ungetc( c, (FILE *)(is->file) ) == EOF ) { 116 150 perror( IO_MSG "ungetc" ); 117 151 exit( EXIT_FAILURE ); … … 120 154 } // ungetc 121 155 122 void open( ifstream ** is, const char * name, const char * mode ) { 123 FILE *t = fopen( name, mode ); 124 if ( t == 0 ) { // do not change unless successful 125 perror( IO_MSG "open input" ); 126 exit( EXIT_FAILURE ); 156 int scanfmt( ifstream * is, const char fmt[], ... ) { 157 va_list args; 158 159 va_start( args, fmt ); 160 int len = vfscanf( (FILE *)(is->file), fmt, args ); 161 if ( len == EOF ) { 162 if ( ferror( (FILE *)(is->file) ) ) { 163 fprintf( stderr, "invalid read\n" ); 164 exit( EXIT_FAILURE ); 165 } // if 127 166 } // if 128 (*is)->file = t; 129 } // open 167 va_end( args ); 168 return len; 169 } // prtfmt 130 170 131 void close( ifstream * is ) {132 if ( is->file == stdin ) return;133 134 if ( fclose( is->file ) == EOF ) {135 perror( IO_MSG "close input" );136 } // if137 } // close138 171 139 172 static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) }; -
src/libcfa/iostream
rac1ed49 r90c3b1c 7 7 // iostream -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:04:24201613 // Update Count : 3212 // Last Modified On : Wed Mar 2 16:44:32 2016 13 // Update Count : 81 14 14 // 15 15 16 #ifndef IOSTREAM_H17 #define IOSTREAM_H16 #ifndef __IOSTREAM_H__ 17 #define __IOSTREAM_H__ 18 18 19 19 #include "iterator" 20 20 21 typedef unsigned long streamsize_type;22 23 21 context ostream( dtype ostype ) { 22 _Bool sepPrt( ostype * ); 23 void sepOn( ostype * ); 24 void sepOff( ostype * ); 25 void sepSet( ostype *, const char * ); 26 const char * sepGet( ostype * ); 27 void sepDisable( ostype * ); 28 void sepEnable( ostype * ); 24 29 int fail( ostype * ); 25 30 int flush( ostype * ); 26 ostype * write( ostype *, const char *, streamsize_type ); 31 void open( ostype * os, const char * name, const char * mode ); 32 void close( ostype * os ); 33 ostype * write( ostype *, const char *, unsigned long int ); 34 int prtfmt( ostype *, const char fmt[], ... ); 27 35 }; 36 28 37 context writeable( type T ) { 29 38 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); … … 33 42 34 43 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char ); 44 45 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, short int ); 46 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned short int ); 35 47 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int ); 36 48 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned int ); … … 39 51 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long int ); 40 52 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long long int ); 53 41 54 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float ); // FIX ME: should not be required 42 55 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double ); 43 56 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double ); 57 44 58 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float _Complex ); 45 59 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double _Complex ); 46 60 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double _Complex ); 61 47 62 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * ); 48 63 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * ); 49 64 50 forall( dtype ostype , dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );65 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) ); 51 66 forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * ); 67 forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * ); 68 forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * ); 52 69 53 70 // writes the range [begin, end) to the given stream … … 63 80 int fail( istype * ); 64 81 int eof( istype * ); 65 istype * get( istype *, int * ); 66 istype * read( istype *, char *, streamsize_type ); 82 void open( istype * is, const char * name, const char * mode ); 83 void close( istype * is ); 84 istype * read( istype *, char *, unsigned long int ); 67 85 istype * ungetc( istype *, char ); 86 int scanfmt( istype *, const char fmt[], ... ); 68 87 }; 69 88 … … 72 91 }; 73 92 74 forall( dtype istype | istream( istype ) ) 75 istype * ?|?( istype *, char * ); 93 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * ); 76 94 77 forall( dtype istype | istream( istype ) ) 78 istype * ?|?( istype *, int * ); 95 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int * ); 96 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int * ); 97 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int * ); 98 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int * ); 99 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int * ); 100 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int * ); 101 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int * ); 102 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int * ); 79 103 80 #endif // IOSTREAM_H 104 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float * ); 105 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double * ); 106 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double * ); 107 108 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex * ); 109 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex * ); 110 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * ); 111 112 struct _Istream_str1 { char * s; }; 113 _Istream_str1 str( char * ); 114 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_str1 ); 115 116 struct _Istream_str2 { char * s; int size; }; 117 _Istream_str2 str( char *, int size ); 118 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_str2 ); 119 120 #endif // __IOSTREAM_H__ 81 121 82 122 // Local Variables: // -
src/libcfa/iostream.c
rac1ed49 r90c3b1c 7 7 // iostream.c -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:19:56201613 // Update Count : 7612 // Last Modified On : Wed Mar 2 16:20:57 2016 13 // Update Count : 207 14 14 // 15 15 … … 21 21 #include <float.h> // DBL_DIG, LDBL_DIG 22 22 #include <complex.h> // creal, cimag 23 #include <ctype.h> // isspace, ispunct 23 24 } 24 25 25 26 forall( dtype ostype | ostream( ostype ) ) 26 27 ostype * ?|?( ostype *os, char c ) { 27 return write( os, &c, 1 ); 28 prtfmt( os, "%c", c ); 29 return os; 30 } // ?|? 31 32 forall( dtype ostype | ostream( ostype ) ) 33 ostype * ?|?( ostype *os, short int si ) { 34 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 35 prtfmt( os, "%hd", si ); 36 return os; 37 } // ?|? 38 39 forall( dtype ostype | ostream( ostype ) ) 40 ostype * ?|?( ostype *os, unsigned short int usi ) { 41 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 42 prtfmt( os, "%hu", usi ); 43 return os; 28 44 } // ?|? 29 45 30 46 forall( dtype ostype | ostream( ostype ) ) 31 47 ostype * ?|?( ostype *os, int i ) { 32 char buffer[32]; 33 return write( os, buffer, sprintf( buffer, "%d", i ) ); 34 } // ?|? 35 36 forall( dtype ostype | ostream( ostype ) ) 37 ostype * ?|?( ostype *os, unsigned int i ) { 38 char buffer[32]; 39 return write( os, buffer, sprintf( buffer, "%u", i ) ); 40 } // ?|? 41 42 forall( dtype ostype | ostream( ostype ) ) 43 ostype * ?|?( ostype *os, long int i ) { 44 char buffer[32]; 45 return write( os, buffer, sprintf( buffer, "%ld", i ) ); 46 } // ?|? 47 48 forall( dtype ostype | ostream( ostype ) ) 49 ostype * ?|?( ostype *os, long long int i ) { 50 char buffer[32]; 51 return write( os, buffer, sprintf( buffer, "%lld", i ) ); 52 } // ?|? 53 54 forall( dtype ostype | ostream( ostype ) ) 55 ostype * ?|?( ostype *os, unsigned long int i ) { 56 char buffer[32]; 57 return write( os, buffer, sprintf( buffer, "%lu", i ) ); 58 } // ?|? 59 60 forall( dtype ostype | ostream( ostype ) ) 61 ostype * ?|?( ostype *os, unsigned long long int i ) { 62 char buffer[32]; 63 return write( os, buffer, sprintf( buffer, "%llu", i ) ); 48 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 49 prtfmt( os, "%d", i ); 50 return os; 51 } // ?|? 52 53 forall( dtype ostype | ostream( ostype ) ) 54 ostype * ?|?( ostype *os, unsigned int ui ) { 55 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 56 prtfmt( os, "%u", ui ); 57 return os; 58 } // ?|? 59 60 forall( dtype ostype | ostream( ostype ) ) 61 ostype * ?|?( ostype *os, long int li ) { 62 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 63 prtfmt( os, "%ld", li ); 64 return os; 65 } // ?|? 66 67 forall( dtype ostype | ostream( ostype ) ) 68 ostype * ?|?( ostype *os, unsigned long int uli ) { 69 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 70 prtfmt( os, "%lu", uli ); 71 return os; 72 } // ?|? 73 74 forall( dtype ostype | ostream( ostype ) ) 75 ostype * ?|?( ostype *os, long long int lli ) { 76 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 77 prtfmt( os, "%lld", lli ); 78 return os; 79 } // ?|? 80 81 forall( dtype ostype | ostream( ostype ) ) 82 ostype * ?|?( ostype *os, unsigned long long int ulli ) { 83 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 84 prtfmt( os, "%llu", ulli ); 85 return os; 64 86 } // ?|? 65 87 66 88 forall( dtype ostype | ostream( ostype ) ) 67 89 ostype * ?|?( ostype *os, float f ) { 68 char buffer[32]; 69 return write( os, buffer, sprintf( buffer, "%g", f ) ); 90 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 91 prtfmt( os, "%g", f ); 92 return os; 70 93 } // ?|? 71 94 72 95 forall( dtype ostype | ostream( ostype ) ) 73 96 ostype * ?|?( ostype *os, double d ) { 74 char buffer[32]; 75 return write( os, buffer, sprintf( buffer, "%.*lg", DBL_DIG, d ) ); 76 } // ?|? 77 78 forall( dtype ostype | ostream( ostype ) ) 79 ostype * ?|?( ostype *os, long double d ) { 80 char buffer[32]; 81 return write( os, buffer, sprintf( buffer, "%.*Lg", LDBL_DIG, d ) ); 82 } // ?|? 83 84 forall( dtype ostype | ostream( ostype ) ) 85 ostype * ?|?( ostype *os, float _Complex c ) { 86 return os | crealf( c ) | (cimagf( c ) < 0 ? "" : "+") | cimagf( c ) | 'i'; 87 } // ?|? 88 89 forall( dtype ostype | ostream( ostype ) ) 90 ostype * ?|?( ostype *os, double _Complex c ) { 91 return os | creal( c ) | (cimag( c ) < 0 ? "" : "+") | cimag( c ) | 'i'; 92 } // ?|? 93 94 forall( dtype ostype | ostream( ostype ) ) 95 ostype * ?|?( ostype *os, long double _Complex c ) { 96 return os | creall( c ) | (cimagl( c ) < 0 ? "" : "+") | cimagl( c ) | 'i'; 97 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 98 prtfmt( os, "%.*lg", DBL_DIG, d ); 99 return os; 100 } // ?|? 101 102 forall( dtype ostype | ostream( ostype ) ) 103 ostype * ?|?( ostype *os, long double ld ) { 104 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 105 prtfmt( os, "%.*Lg", LDBL_DIG, ld ); 106 return os; 107 } // ?|? 108 109 forall( dtype ostype | ostream( ostype ) ) 110 ostype * ?|?( ostype *os, float _Complex fc ) { 111 os | crealf( fc ); 112 if ( cimagf( fc ) >= 0 ) os | '+'; 113 os | "" | cimagf( fc ) | 'i'; 114 return os; 115 } // ?|? 116 117 forall( dtype ostype | ostream( ostype ) ) 118 ostype * ?|?( ostype *os, double _Complex dc ) { 119 os | creal( dc ); 120 if ( cimag( dc ) >= 0 ) os | '+'; 121 os | "" | cimag( dc ) | 'i'; 122 return os; 123 } // ?|? 124 125 forall( dtype ostype | ostream( ostype ) ) 126 ostype * ?|?( ostype *os, long double _Complex ldc ) { 127 os | creall( ldc ); 128 if ( cimagl( ldc ) >= 0 ) os | '+'; 129 os | "" | cimagl( ldc ) | 'i'; 130 return os; 131 } // ?|? 132 133 forall( dtype ostype | ostream( ostype ) ) 134 ostype * ?|?( ostype *os, const char *cp ) { 135 int len = strlen( cp ); 136 // null string => no separator 137 if ( len == 0 ) { sepOff( os ); return os; } 138 // first character NOT spacing or special punctuation => add left separator 139 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && cp[0] != '.' && cp[0] != ',' ) { 140 prtfmt( os, "%s", sepGet( os ) ); 141 } // if 142 // last character is spacing or special punctuation => turn off separator for next item 143 unsigned int posn = len - 1; 144 if ( isspace( cp[posn] ) || cp[posn] == ':' || cp[posn] == '$' ) { 145 sepOff( os ); 146 } else { 147 sepOn( os ); 148 } // if 149 return write( os, cp, len ); 97 150 } // ?|? 98 151 99 152 forall( dtype ostype | ostream( ostype ) ) 100 153 ostype * ?|?( ostype *os, const void *p ) { 101 char buffer[32]; 102 return write( os, buffer, sprintf( buffer, "%p", p ) ); 103 } // ?|? 104 105 forall( dtype ostype | ostream( ostype ) ) 106 ostype * ?|?( ostype *os, const char *cp ) { 107 return write( os, cp, strlen( cp ) ); 108 } // ?|? 109 110 111 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) 112 retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) { 113 return manip( os ); 114 } 154 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 155 prtfmt( os, "%p", p ); 156 return os; 157 } // ?|? 158 159 160 forall( dtype ostype | ostream( ostype ) ) 161 ostype * ?|?( ostype *os, ostype * (* manip)( ostype * ) ) { 162 return manip( os ); 163 } // ?|? 115 164 116 165 forall( dtype ostype | ostream( ostype ) ) 117 166 ostype * endl( ostype * os ) { 118 os | "\n";167 os | '\n'; 119 168 flush( os ); 169 sepOff( os ); 120 170 return os; 121 171 } // endl 122 172 173 forall( dtype ostype | ostream( ostype ) ) 174 ostype * sepOn( ostype * os ) { 175 sepOn( os ); 176 return os; 177 } // sepOn 178 179 forall( dtype ostype | ostream( ostype ) ) 180 ostype * sepOff( ostype * os ) { 181 sepOff( os ); 182 return os; 183 } // sepOff 184 123 185 //--------------------------------------- 124 186 125 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), 126 dtype os_type | ostream( os_type ) ) 127 void write( iterator_type begin, iterator_type end, os_type *os ) { 128 void print( elt_type i ) { os | i | ' '; } 187 forall( type elttype | writeable( elttype ), type iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) ) 188 void write( iteratortype begin, iteratortype end, ostype *os ) { 189 void print( elttype i ) { os | i; } 129 190 for_each( begin, end, print ); 130 191 } // ?|? 131 192 132 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), 133 dtype os_type | ostream( os_type ) ) 134 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 135 void print( elt_type i ) { os | i | ' '; } 193 forall( type elttype | writeable( elttype ), type iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) ) 194 void write_reverse( iteratortype begin, iteratortype end, ostype *os ) { 195 void print( elttype i ) { os | i; } 136 196 for_each_reverse( begin, end, print ); 137 197 } // ?|? … … 140 200 141 201 forall( dtype istype | istream( istype ) ) 142 istype * ?|?( istype *is, char *cp ) { 143 return read( is, cp, 1 ); 144 } // ?|? 145 146 forall( dtype istype | istream( istype ) ) 147 istype * ?|?( istype *is, int *ip ) { 148 return get( is, ip ); 149 } // ?|? 202 istype * ?|?( istype * is, char * c ) { 203 scanfmt( is, "%c", c ); 204 return is; 205 } // ?|? 206 207 forall( dtype istype | istream( istype ) ) 208 istype * ?|?( istype * is, short int * si ) { 209 scanfmt( is, "%hd", si ); 210 return is; 211 } // ?|? 212 213 forall( dtype istype | istream( istype ) ) 214 istype * ?|?( istype * is, unsigned short int * usi ) { 215 scanfmt( is, "%hu", usi ); 216 return is; 217 } // ?|? 218 219 forall( dtype istype | istream( istype ) ) 220 istype * ?|?( istype * is, int * i ) { 221 scanfmt( is, "%d", i ); 222 return is; 223 } // ?|? 224 225 forall( dtype istype | istream( istype ) ) 226 istype * ?|?( istype * is, unsigned int * ui ) { 227 scanfmt( is, "%u", ui ); 228 return is; 229 } // ?|? 230 231 forall( dtype istype | istream( istype ) ) 232 istype * ?|?( istype * is, long int * li ) { 233 scanfmt( is, "%ld", li ); 234 return is; 235 } // ?|? 236 237 forall( dtype istype | istream( istype ) ) 238 istype * ?|?( istype * is, unsigned long int * ulli ) { 239 scanfmt( is, "%lu", ulli ); 240 return is; 241 } // ?|? 242 243 forall( dtype istype | istream( istype ) ) 244 istype * ?|?( istype * is, long long int * lli ) { 245 scanfmt( is, "%lld", lli ); 246 return is; 247 } // ?|? 248 249 forall( dtype istype | istream( istype ) ) 250 istype * ?|?( istype * is, unsigned long long int * ulli ) { 251 scanfmt( is, "%llu", ulli ); 252 return is; 253 } // ?|? 254 255 256 forall( dtype istype | istream( istype ) ) 257 istype * ?|?( istype * is, float * f ) { 258 scanfmt( is, "%f", f ); 259 return is; 260 } // ?|? 261 262 forall( dtype istype | istream( istype ) ) 263 istype * ?|?( istype * is, double * d ) { 264 scanfmt( is, "%lf", d ); 265 return is; 266 } // ?|? 267 268 forall( dtype istype | istream( istype ) ) 269 istype * ?|?( istype * is, long double * ld ) { 270 scanfmt( is, "%Lf", ld ); 271 return is; 272 } // ?|? 273 274 275 forall( dtype istype | istream( istype ) ) 276 istype * ?|?( istype * is, float _Complex * fc ) { 277 float re, im; 278 scanfmt( is, "%g%gi", &re, &im ); 279 *fc = re + im * _Complex_I; 280 return is; 281 } // ?|? 282 283 forall( dtype istype | istream( istype ) ) 284 istype * ?|?( istype * is, double _Complex * dc ) { 285 double re, im; 286 scanfmt( is, "%lf%lfi", &re, &im ); 287 *dc = re + im * _Complex_I; 288 return is; 289 } // ?|? 290 291 forall( dtype istype | istream( istype ) ) 292 istype * ?|?( istype * is, long double _Complex * ldc ) { 293 long double re, im; 294 scanfmt( is, "%Lf%Lfi", &re, &im ); 295 *ldc = re + im * _Complex_I; 296 return is; 297 } // ?|? 298 299 _Istream_str1 str( char * s ) { _Istream_str1 s = { s }; return s; } 300 forall( dtype istype | istream( istype ) ) 301 istype * ?|?( istype * is, _Istream_str1 str ) { 302 scanfmt( is, "%s", str.s ); 303 return is; 304 } // str 305 306 _Istream_str2 str( char * s, int size ) { _Istream_str2 s = { s, size }; return s; } 307 forall( dtype istype | istream( istype ) ) 308 istype * ?|?( istype * is, _Istream_str2 str ) { 309 char buf[16]; 310 sprintf( buf, "%%%ds", str.size ); 311 scanfmt( is, buf, str.s ); 312 return is; 313 } // str 150 314 151 315 // Local Variables: // -
src/libcfa/stdlib
rac1ed49 r90c3b1c 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 5 15:21:18201613 // Update Count : 6 112 // Last Modified On : Wed Mar 2 16:52:25 2016 13 // Update Count : 63 14 14 // 15 15 … … 25 25 forall( type T ) T * malloc( void ); 26 26 forall( type T ) T * malloc( char fill ); 27 forall( type T ) T * malloc( size_t size );28 27 forall( type T ) T * malloc( T * ptr, size_t size ); 29 28 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ); -
src/libcfa/stdlib.c
rac1ed49 r90c3b1c 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 10 15:45:56201613 // Update Count : 14 012 // Last Modified On : Tue Feb 23 21:02:54 2016 13 // Update Count : 142 14 14 // 15 15 … … 123 123 return ulli; 124 124 } 125 125 126 float ato( const char * ptr ) { 126 127 float f; … … 138 139 return ld; 139 140 } 141 140 142 float _Complex ato( const char * ptr ) { 141 143 float re, im; … … 172 174 return strtoull( sptr, eptr, base ); 173 175 } 176 174 177 float strto( const char * sptr, char ** eptr ) { 175 178 return strtof( sptr, eptr ); … … 181 184 return strtold( sptr, eptr ); 182 185 } 186 183 187 float _Complex strto( const char * sptr, char ** eptr ) { 184 188 float re, im;
Note: See TracChangeset
for help on using the changeset viewer.