]> mj.ucw.cz Git - umpf.git/commitdiff
xrealloc
authorAnicka Bernathova <anicka@anicka.net>
Mon, 21 Jul 2008 15:08:54 +0000 (17:08 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Mon, 21 Jul 2008 15:08:54 +0000 (17:08 +0200)
brum.c
brum.h
ham.c
int.c
lex.c

diff --git a/brum.c b/brum.c
index 171cb076ba8331587d8792090fc1967a19d88a01..b6fa451f87f64150f0c225f466725e3e46bc7b3a 100644 (file)
--- a/brum.c
+++ b/brum.c
@@ -22,6 +22,7 @@ main(int argc, char** argv)
        var_hash = new_var_hash();
 
        current_headers = make_hlist();
+       current_body = get_body();
 //     print_headers(current_headers);
 
        save_current_headers(var_hash);
diff --git a/brum.h b/brum.h
index 3692182d93f638e2b21cef5e0b742775419e1632..f5e2372ed77092d8d3041501515cbc287a53943c 100644 (file)
--- a/brum.h
+++ b/brum.h
@@ -70,6 +70,7 @@ struct tree* input_tree;
 /* lex.c */
 #define CC(a,b) ((a<<8)|b)
 void* xmalloc(size_t size);
+void* xrealloc(void* buf, size_t size);
 char* xstrdup(char* s);
 void __attribute__ ((noreturn)) die(char* msg, ...);
 void read_conf(char* filename);
@@ -92,6 +93,7 @@ struct hlist {
 
 struct email {
        struct list* headers;
+       char* body;
 };
 
 struct action {
@@ -111,6 +113,8 @@ void save_current_headers(struct list* hash);
 
 /* ham.c */
 struct list* current_headers;
+char* current_body;
 struct list* make_hlist(void);
 void print_headers(struct list* l);
 void do_action(struct action* a);
+char* get_body(void);
diff --git a/ham.c b/ham.c
index 04153c5bb68ee9db8b3215d66398c8acd2a296c3..16d7b36cc115ce8d7e271b06e8d60d13128e136a 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -8,18 +8,6 @@
 
 int curbufsize;
 
-static char* //TODO: rewrite
-buf_double(char* buf, int size)
-{
-       buf = realloc(buf, 2*size);
-       
-       if (!buf)
-               die("Low memory");
-
-       return buf;
-
-}
-
 static void
 new_header(char* buf, struct list* h)
 {
@@ -56,16 +44,14 @@ make_hlist(void)
                if (c == '\r')
                        continue;
 
-               if (i >= curbufsize-2){
-                       buf = buf_double(buf, curbufsize);
-                       curbufsize *= 2;
-               }
-
+               if (i >= curbufsize-2)
+                       buf = xrealloc(buf, curbufsize *= 2);
+               
                buf[i++] = c; 
                if (c == '\n'){
                        if (last == '\n')
                                break;
-                       if ((c = getchar())!=' ' && c!='\t'){
+                       if ((c = getchar()) != ' ' && c != '\t'){
                                if (c != EOF)
                                        ungetc(c, stdin);
                                buf[i] = 0;
@@ -80,6 +66,27 @@ make_hlist(void)
        return l;
 }
 
+char*
+get_body(void)
+{
+       char* buf;
+       int c;
+       int i = 0;
+       int curbufsize = BUFSIZE;
+
+       buf = xmalloc(BUFSIZE);
+       while ((c = getchar()) != EOF){
+               buf[i++] = c;
+
+               if (i >= curbufsize - 1)
+                       buf = xrealloc(buf, curbufsize *= 2);
+       }
+
+       buf[i] = 0;
+
+       return buf; 
+}
+
 void
 print_headers(struct list* l)
 {
@@ -92,16 +99,12 @@ print_headers(struct list* l)
 void
 do_action(struct action* a)
 {
-       puts("--do action--");
-       if (a->l)
-               puts(a->l);
-       printf("->");
-       if (a->r)
-               puts(a->r);
-       putchar(' ');
-       if (a->s)
-               puts(a->s);
-       puts("with email\n");
-       print_headers(a->e.headers);
-       puts("\n--Muhehehechlemst!--\n");
+       //just deliver e-mail, do not look at left side now
+/*     if (! a->r ){
+
+       } else if (!strcmp(a->r,"pipe")){
+               1;
+       }       
+*/
+
 }
diff --git a/int.c b/int.c
index 8da089bfa4c15f5e73474107222aa8f4c997d2c6..795b843bd6ccbfa9c2765b1e44a69be2b7046466 100644 (file)
--- a/int.c
+++ b/int.c
@@ -46,7 +46,7 @@ find_var(char* name, char* value, struct list* hash)
        struct variable *p;
 
        n = get_bucket_number(name);
-       int nocase = !isupper(*name);
+       int nocase = isupper(*name);
        LIST_FOREACH(p, hash + n)
                if (!(nocase ? strcasecmp : strcmp)(p->name,name)){
                        if (value){
@@ -292,6 +292,7 @@ new_action(char* l, char* r, char* s, struct list* hash)
 
        modify_headers(current_headers, hash);
        a->e.headers = copy_headers(current_headers);
+       a->e.body = xstrdup(current_body);
        a->l = l;
        a->r = r;
        a->s = s;
diff --git a/lex.c b/lex.c
index 25e3a8a7bb7b02f15f2d3b2daff7f16f1521d828..4beb8bb1afaf3ac8f438dd425895f21b533b1549 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -55,6 +55,17 @@ xmalloc(size_t size)
         return ret;
 }
 
+void*
+xrealloc(void* buf, size_t size)
+{
+       buf = realloc(buf, size);
+       
+       if (!buf)
+               die("Low memory");
+
+       return buf;
+}
+
 static void __attribute__ ((noreturn)) 
 parse_err(char* msg, ...)
 {