Ignore:
Timestamp:
Nov 25, 2014, 9:16:10 AM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
3848e0e
Parents:
d11f789
Message:

re-inserted remove and reorder hoisted aggregate, fixed example programs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/examples/fstream.c

    rd11f789 r42dcae7  
    1 // "cfa -E fstream.c > fstream_out.c"
    2 // "cfa -c -o fstream.o fstream.c"
    3 
    41#include "fstream.h"
    52
     
    1411};
    1512
    16 ofstream * write( ofstream *os, const char *data, streamsize_type size ) {
    17     if( !os->fail ) {
     13ofstream *write( ofstream *os, const char *data, streamsize_type size ) {
     14    if ( ! os->fail ) {
    1815        fwrite( data, size, 1, os->file );
    1916        os->fail = ferror( os->file );
     
    2623}
    2724
    28 static ofstream * make_ofstream() {
     25static ofstream *make_ofstream() {
    2926    ofstream *new_stream = malloc( sizeof( ofstream ) );
    3027    new_stream->fail = 0;
     
    3229}
    3330
    34 ofstream * ofstream_stdout() {
     31ofstream *ofstream_stdout() {
    3532    ofstream *stdout_stream = make_ofstream();
    3633    stdout_stream->file = stdout;
     
    3835}
    3936
    40 ofstream * ofstream_stderr() {
     37ofstream *ofstream_stderr() {
    4138    ofstream *stderr_stream = make_ofstream();
    4239    stderr_stream->file = stderr;
     
    4441}
    4542
    46 ofstream * ofstream_fromfile( const char *name ) {
     43ofstream *ofstream_fromfile( const char *name ) {
    4744    ofstream *file_stream = make_ofstream();
    4845    file_stream->file = fopen( name, "w" );
     
    5249
    5350void ofstream_close( ofstream *os ) {
    54     if( os->file != stdout && os->file != stderr ) {
     51    if ( os->file != stdout && os->file != stderr ) {
    5552        os->fail = fclose( os->file );
    5653    }
     
    6461};
    6562
    66 ifstream * read( ifstream *is, char *data, streamsize_type size ) {
    67     if( !is->fail && !is->eof ) {
     63ifstream *read( ifstream *is, char *data, streamsize_type size ) {
     64    if ( ! is->fail && ! is->eof ) {
    6865        fread( data, size, 1, is->file );
    6966        is->fail = ferror( is->file );
     
    7471 
    7572ifstream *unread( ifstream *is, char c ) {
    76     if( !is->fail ) {
    77         if( EOF == ungetc( c, is->file ) ) {
     73    if ( ! is->fail ) {
     74        if ( ! EOF == ungetc( c, is->file ) ) {
    7875            is->fail = 1;
    7976        }
     
    9087}
    9188
    92 static ifstream * make_ifstream() {
     89static ifstream *make_ifstream() {
    9390    ifstream *new_stream = malloc( sizeof( ifstream ) );
    9491    new_stream->fail = 0;
     
    9794}
    9895
    99 ifstream * ifstream_stdin() {
     96ifstream *ifstream_stdin() {
    10097    ifstream *stdin_stream = make_ifstream();
    10198    stdin_stream->file = stdin;
     
    103100}
    104101
    105 ifstream * ifstream_fromfile( const char *name ) {
     102ifstream *ifstream_fromfile( const char *name ) {
    106103    ifstream *file_stream = make_ifstream();
    107104    file_stream->file = fopen( name, "r" );
Note: See TracChangeset for help on using the changeset viewer.