comparison src/c/lacweb.c @ 106:d101cb1efe55

More with attributes and efficient serialization
author Adam Chlipala <adamc@hcoop.net>
date Thu, 10 Jul 2008 15:49:14 -0400
parents 5f04adf47f48
children 94856a3b4752
comparison
equal deleted inserted replaced
105:da760c34f5ed 106:d101cb1efe55
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <ctype.h>
2 3
3 #include "types.h" 4 #include "types.h"
4 5
5 lw_unit lw_unit_v = {}; 6 lw_unit lw_unit_v = {};
6 7
8 void lw_writec(char c) {
9 fputc(c, stdout);
10 }
11
7 void lw_write(const char* s) { 12 void lw_write(const char* s) {
8 fputs(s, stdout); 13 fputs(s, stdout);
9 } 14 }
15
16 char *lw_Basis_attrifyInt(lw_Basis_int n) {
17 return "0";
18 }
19
20 char *lw_Basis_attrifyFloat(lw_Basis_float n) {
21 return "0.0";
22 }
23
24 char *lw_Basis_attrifyString(lw_Basis_string s) {
25 return "";
26 }
27
28 char *lw_Basis_attrifyInt_w(lw_Basis_int n) {
29 printf("%d", n);
30 }
31
32 char *lw_Basis_attrifyFloat_w(lw_Basis_float n) {
33 printf("%g", n);
34 }
35
36 char *lw_Basis_attrifyString_w(lw_Basis_string s) {
37 for (; *s; s++) {
38 char c = *s;
39
40 if (c == '"')
41 lw_write("&quot;");
42 else if (isprint(c))
43 lw_writec(c);
44 else {
45 lw_write("&#");
46 lw_Basis_attrifyInt_w(c);
47 lw_writec(';');
48 }
49 }
50 lw_write(s);
51 }