]> mj.ucw.cz Git - umpf.git/blob - ham.c
16d7b36cc115ce8d7e271b06e8d60d13128e136a
[umpf.git] / ham.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "brum.h"
6
7 #define BUFSIZE 1024 
8
9 int curbufsize;
10
11 static void
12 new_header(char* buf, struct list* h)
13 {
14         char* p;
15         struct hlist* new;
16
17         new = xmalloc(sizeof(struct hlist));
18
19         p = strchr(buf, ':');
20         if (!p)
21                 new->value = xstrdup("");
22         else {
23                 *p = 0;
24                 new->value = xstrdup(p+1);
25         }
26         new->name = xstrdup(buf);
27
28         list_add_last(h, &new->car);
29 }
30
31 struct list*
32 make_hlist(void)
33 {
34         struct list* l = xmalloc(sizeof(struct list));
35         char* buf;
36         int i = 0; /* current position */
37         int c, last = 0;
38
39         list_init(l);
40         buf = xmalloc(BUFSIZE);
41         curbufsize = BUFSIZE;
42         
43         while ((c = getchar()) != EOF){
44                 if (c == '\r')
45                         continue;
46
47                 if (i >= curbufsize-2)
48                         buf = xrealloc(buf, curbufsize *= 2);
49                 
50                 buf[i++] = c; 
51                 if (c == '\n'){
52                         if (last == '\n')
53                                 break;
54                         if ((c = getchar()) != ' ' && c != '\t'){
55                                 if (c != EOF)
56                                         ungetc(c, stdin);
57                                 buf[i] = 0;
58                                 new_header(buf, l);
59                                 i = 0;
60                         } else
61                                 buf[i++] = c;
62                 }
63                         last = c;
64         }
65         free(buf);
66         return l;
67 }
68
69 char*
70 get_body(void)
71 {
72         char* buf;
73         int c;
74         int i = 0;
75         int curbufsize = BUFSIZE;
76
77         buf = xmalloc(BUFSIZE);
78         while ((c = getchar()) != EOF){
79                 buf[i++] = c;
80
81                 if (i >= curbufsize - 1)
82                         buf = xrealloc(buf, curbufsize *= 2);
83         }
84
85         buf[i] = 0;
86
87         return buf; 
88 }
89
90 void
91 print_headers(struct list* l)
92 {
93         struct hlist* p;
94
95         LIST_FOREACH(p,l)
96                 printf("%s:%s",p->name,p->value);
97 }
98
99 void
100 do_action(struct action* a)
101 {
102         //just deliver e-mail, do not look at left side now
103 /*      if (! a->r ){
104
105         } else if (!strcmp(a->r,"pipe")){
106                 1;
107         }       
108 */
109
110 }