source: translator/examples/iostream.c @ a0d9f94

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since a0d9f94 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1// "cfa -c -o iostream.o iostream.c"
2// "cfa -v -E iostream.c > iostream_out.c"
3// "cfa -CFA iostream.c > iostream_out.c"
4// "cfa iostream_out.c"
5// "gcc32 iostream_out.c LibCfa/libcfa.a"
6
7#include "iostream.h"
8#undef __cplusplus
9extern "C" {
10#include <string.h>
11#include <ctype.h>
12#include <stdio.h>
13}
14
15forall( dtype ostype | ostream( ostype ) )
16ostype *
17?<<?( ostype *os, char c )
18{
19  return write( os, &c, 1 );
20}
21
22forall( dtype ostype | ostream( ostype ) )
23ostype *
24?<<?( ostype *os, int i )
25{
26  char buffer[20];      // larger than the largest integer
27  sprintf( buffer, "%d", i );
28  return write( os, buffer, strlen( buffer ) );
29}
30
31forall( dtype ostype | ostream( ostype ) )
32ostype *
33?<<?( ostype *os, const char *cp )
34{
35  return write( os, cp, strlen( cp ) );
36}
37
38forall( dtype istype | istream( istype ) )
39istype *
40?>>?( istype *is, char *cp )
41{
42  return read( is, cp, 1 );
43}
44
45forall( dtype istype | istream( istype ) )
46istype *
47?>>?( istype *is, int *ip )
48{
49  char cur;
50 
51  // skip some whitespace
52  do {
53    is >> &cur;
54    if( fail( is ) || eof( is ) ) return is;
55  } while( !( cur >= '0' && cur <= '9' ) );
56 
57  // accumulate digits
58  *ip = 0;
59  while( cur >= '0' && cur <= '9' ) {
60    *ip = *ip * 10 + ( cur - '0' );
61    is >> &cur;
62    if( fail( is ) || eof( is ) ) return is;
63  }
64 
65  unread( is, cur );
66  return is;
67}
Note: See TracBrowser for help on using the repository browser.