Mercurial > urweb
annotate src/c/lacweb.c @ 107:bed5cf0b6b75
Optimizing attrification of constants
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 10 Jul 2008 15:58:16 -0400 |
parents | d101cb1efe55 |
children | 94856a3b4752 |
rev | line source |
---|---|
adamc@102 | 1 #include <stdio.h> |
adamc@106 | 2 #include <ctype.h> |
adamc@102 | 3 |
adamc@102 | 4 #include "types.h" |
adamc@102 | 5 |
adamc@102 | 6 lw_unit lw_unit_v = {}; |
adamc@102 | 7 |
adamc@106 | 8 void lw_writec(char c) { |
adamc@106 | 9 fputc(c, stdout); |
adamc@106 | 10 } |
adamc@106 | 11 |
adamc@102 | 12 void lw_write(const char* s) { |
adamc@102 | 13 fputs(s, stdout); |
adamc@102 | 14 } |
adamc@106 | 15 |
adamc@106 | 16 char *lw_Basis_attrifyInt(lw_Basis_int n) { |
adamc@106 | 17 return "0"; |
adamc@106 | 18 } |
adamc@106 | 19 |
adamc@106 | 20 char *lw_Basis_attrifyFloat(lw_Basis_float n) { |
adamc@106 | 21 return "0.0"; |
adamc@106 | 22 } |
adamc@106 | 23 |
adamc@106 | 24 char *lw_Basis_attrifyString(lw_Basis_string s) { |
adamc@106 | 25 return ""; |
adamc@106 | 26 } |
adamc@106 | 27 |
adamc@106 | 28 char *lw_Basis_attrifyInt_w(lw_Basis_int n) { |
adamc@106 | 29 printf("%d", n); |
adamc@106 | 30 } |
adamc@106 | 31 |
adamc@106 | 32 char *lw_Basis_attrifyFloat_w(lw_Basis_float n) { |
adamc@106 | 33 printf("%g", n); |
adamc@106 | 34 } |
adamc@106 | 35 |
adamc@106 | 36 char *lw_Basis_attrifyString_w(lw_Basis_string s) { |
adamc@106 | 37 for (; *s; s++) { |
adamc@106 | 38 char c = *s; |
adamc@106 | 39 |
adamc@106 | 40 if (c == '"') |
adamc@106 | 41 lw_write("""); |
adamc@106 | 42 else if (isprint(c)) |
adamc@106 | 43 lw_writec(c); |
adamc@106 | 44 else { |
adamc@106 | 45 lw_write("&#"); |
adamc@106 | 46 lw_Basis_attrifyInt_w(c); |
adamc@106 | 47 lw_writec(';'); |
adamc@106 | 48 } |
adamc@106 | 49 } |
adamc@106 | 50 lw_write(s); |
adamc@106 | 51 } |