Ignore:
Timestamp:
Apr 28, 2018, 9:20:28 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
6926a6d
Parents:
aa5fdac
Message:

shorten experimental code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/evaluation/c-print.c

    raa5fdac rac4dad2  
    44#include "c-print.h"
    55
    6 void print_string(FILE* out, const char* x) { fprintf(out, "%s", x); }
     6void print_string( FILE * out, const char * x ) { fprintf( out, "%s", x ); }
    77
    8 void print_bool(FILE* out, _Bool x) { fprintf(out, "%s", x ? "true" : "false"); }
     8void print_bool( FILE * out, _Bool x ) { fprintf( out, "%s", x ? "true" : "false" ); }
    99
    10 void print_char(FILE* out, char x) {
    11         if ( 0x20 <= x && x <= 0x7E ) { fprintf(out, "'%c'", x); }
    12         else { fprintf(out, "'\\%x'", x); }
     10void print_char( FILE * out, char x ) {
     11        if ( 0x20 <= x && x <= 0x7E ) { fprintf( out, "'%c'", x ); }
     12        else { fprintf( out, "'\\%x'", x ); }
    1313}
    1414
    15 void print_int(FILE* out, int x) { fprintf(out, "%d", x); }
     15void print_int( FILE * out, int x ) { fprintf( out, "%d", x ); }
    1616
    17 void print_fmt(FILE* out, char fmt, void* p) {
     17void print_fmt( FILE * out, char fmt, void * p ) {
    1818        switch( fmt ) {
    19         case 's': print_string(out, (const char*)p); break; /***/
    20         case 'b': print_bool(out, *(_Bool*)p); break; /***/
    21         case 'c': print_char(out, *(char*)p); break; /***/
    22         case 'd': print_int(out, *(int*)p); break; /***/
     19        case 's': print_string( out, (const char*)p ); break; /***/
     20        case 'b': print_bool( out, *(_Bool*)p ); break; /***/
     21        case 'c': print_char( out, *(char*)p ); break; /***/
     22        case 'd': print_int( out, *(int*)p ); break; /***/
    2323        }
    2424}
    2525
    26 void print(FILE* out, const char* fmt, ...) {
     26void print( FILE * out, const char * fmt, ... ) {
    2727        va_list args;
    2828        va_start(args, fmt);
    29         for (const char* it = fmt; *it; ++it) {
     29        for ( const char * it = fmt; *it; ++it ) {
    3030                switch( *it ) {
    31                 case 's': print_string(out, va_arg(args, const char*)); break; /***/
    32                 case 'b': print_bool(out, va_arg(args, int)); break; /***/
    33                 case 'c': print_char(out, va_arg(args, int)); break; /***/
    34                 case 'd': print_int(out, va_arg(args, int)); break; /***/
     31                case 's': print_string( out, va_arg( args, const char * ) ); break; /***/
     32                case 'b': print_bool( out, va_arg( args, int ) ); break; /***/
     33                case 'c': print_char( out, va_arg( args, int ) ); break; /***/
     34                case 'd': print_int( out, va_arg( args, int ) ); break; /***/
    3535                case 'p': {
    36                         const struct pair x = va_arg(args, const struct pair); /***/
    37                         fprintf(out, "[");
    38                         print_fmt(out, *++it, x.first); /***/
    39                         fprintf(out, ", ");
    40                         print_fmt(out, *++it, x.second); /***/
    41                         fprintf(out, "]");
     36                        const struct pair x = va_arg( args, const struct pair ); /***/
     37                        fprintf( out, "[" );
     38                        print_fmt( out, *++it, x.first ); /***/
     39                        fprintf( out, ", " );
     40                        print_fmt( out, *++it, x.second ); /***/
     41                        fprintf( out, "]" );
    4242                        break;
    4343                }
    4444                }
    4545        }
    46         va_end(args);
     46        va_end( args );
    4747}
Note: See TracChangeset for help on using the changeset viewer.