changeset 12:a6f51c76dea8

add grep.c
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 28 Jun 2011 16:25:37 +0900
parents 1e0cd7fade8b
children 30c56504824c
files pyrect/pyrect/a.out pyrect/pyrect/grep.c pyrect/pyrect/grep.c~ regen/src/generator/cbc.o regen/src/generator/dot.o regen/src/generator/function.o regen/src/generator/label.o regen/src/grep/#grep_jobs.c# regen/src/grep/#grep_jobs.cbc.c# regen/src/grep/Makefile regen/src/grep/Makefile~ regen/src/grep/c_grep regen/src/grep/cbc_grep regen/src/grep/grep regen/src/grep/grep.c regen/src/grep/grep.c~ regen/src/grep/grep.o regen/src/grep/grepAAA.c regen/src/grep/grepAAA.cbc.c regen/src/grep/grep_jobs.c regen/src/grep/grep_jobs.c_back regen/src/grep/grep_jobs.cbc.c regen/src/grep/grep_jobs.cbc.c~ regen/src/grep/grep_jobs.c~ regen/src/grep/include/task.c~ regen/src/grep/include/task.h regen/src/grep/include/task.h~ regen/src/grep/jobs.txt regen/src/grep/jobs.txt~ regen/src/grep/jobs_grep regen/src/grep/jobs_grep_cbc regen/src/grep/jobs_grep_cbc.dSYM/Contents/Info.plist regen/src/grep/jobs_grep_cbc.dSYM/Contents/Resources/DWARF/jobs_grep_cbc regen/src/regen regen/src/template/cbc.c
diffstat 35 files changed, 3797 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
Binary file pyrect/pyrect/a.out has changed
--- a/pyrect/pyrect/grep.c	Sun Jun 19 16:36:05 2011 +0900
+++ b/pyrect/pyrect/grep.c	Tue Jun 28 16:25:37 2011 +0900
@@ -113,6 +113,7 @@
   for (i=0; i<num; i++){
     iret = pthread_create( &threads[i], NULL, matcherp, (void*)thargs[i] );
   }  
+
   //  matcher(beg, beg, end);
 
   for ( i=0; i<num; i++) {
@@ -157,8 +158,7 @@
   env.count = 0;
   goto entry(beg, buf, end, &env);
 _return:
-  pthread_cancel(pthread_self());   
-  //  return env.count;
+  return env.count;
 }
 
 void *matcherp(void *p) {
@@ -172,7 +172,8 @@
   THARGP tharg = (THARGP)p;
   goto entry(tharg->beg, tharg->buf, tharg->end, &env);
 _end:
-  exit(0);
+  pthread_cancel(pthread_self());   
+  //  exit(0);
 }
 
 __code entry(UCHARP beg, UCHARP buf, UCHARP end, ENVP envp) {
--- a/pyrect/pyrect/grep.c~	Sun Jun 19 16:36:05 2011 +0900
+++ b/pyrect/pyrect/grep.c~	Tue Jun 28 16:25:37 2011 +0900
@@ -111,13 +111,15 @@
 
   int i;
   for (i=0; i<num; i++){
-    iret = pthread_create( &threads[i], NULL, matcherp, (void*)thargs[0] );
+    iret = pthread_create( &threads[i], NULL, matcherp, (void*)thargs[i] );
   }  
+
   //  matcher(beg, beg, end);
 
   for ( i=0; i<num; i++) {
     pthread_join( threads[i], NULL);
   }
+
   munmap(file_mmap, size);
   return;
 }
@@ -156,7 +158,8 @@
   env.count = 0;
   goto entry(beg, buf, end, &env);
 _return:
-  return env.count;
+  pthread_cancel(pthread_self());   
+  //  return env.count;
 }
 
 void *matcherp(void *p) {
@@ -209,13 +212,12 @@
   off_t rem = size % num;
   UCHARP end;
   for ( i=1; i<num+1; i++) {
-    p[1-i] = malloc(sizeof(THARG));
+    p[i-1] = malloc(sizeof(THARG));
     end = beg + dsize * i;
-    createArg( p[1-i], fdp, beg+dsize*(i-1), buf+dsize*(i-1), end);
+    createArg( p[i-1], fdp, beg+dsize*(i-1), buf+dsize*(i-1), end);
   }
 }
 
-
 void mallocTh(pthread_t *threads, int num) {
   int i;
   threads = malloc(sizeof(pthread_t) * num);
Binary file regen/src/generator/cbc.o has changed
Binary file regen/src/generator/dot.o has changed
Binary file regen/src/generator/function.o has changed
Binary file regen/src/generator/label.o has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/#grep_jobs.c#	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,313 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include "./include/task.h"
+
+/*
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+*/
+
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void *s0p(void *p);
+static void run_start();
+void regiTask(TASKP p, UCHARP beg, UCHARP end,  ENVP env);
+void *_read();
+void *_exec();
+void *_write();
+
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  //  s0(beg, beg, end, env);
+
+  int iret;
+  TASK task;
+  pthread_t thread;
+
+  createTask( &task, beg, buf, env, end);
+  iret = pthread_create( &thread, NULL, s0p, (void*)&task );
+  pthread_join( thread, NULL);
+
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void *s0p(void *p) {
+  THARGP tharg = (THARGP)p;
+  filter(tharg->beg, tharg->buf, tharg->end, tharg->env);
+  return;
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2, /* s */ [115] = (void*)s5};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4, /* s */ [115] = (void*)s6};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
+
+
+static int division = 16; // in kbyte
+static void
+run_start() {
+
+
+}
+
+void regiTask(TASKP p, UCHARP beg, UCHARP end,  ENVP env){
+
+
+}
+
+void *_read(){
+
+}
+
+void *_exec(){
+
+}
+
+void *_write(){
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/#grep_jobs.cbc.c#	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,272 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <setjmp.h>
+//#include "./include/task.h"
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+  jmp_buf *ret;
+} *ENVP;
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.c"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  env->ret = (jmp_buf *)malloc(sizeof(int)*100); // allocate dumy fields. for protect real ret addres.
+  env->ret = (jmp_buf *)malloc(sizeof(jmp_buf));
+  if (env == NULL) {
+    fprintf(stderr, "can't allocate jmp_buf");
+    exit(0);
+  }
+  int ret;
+  if ((ret = setjmp(env->ret)) == 0) {
+    goto _s0(beg, buf, end, env);
+  }
+  //free(env->ret); danger!
+  return;
+}
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto filter(beg, buf, end, env);
+}
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  buf = end;
+  goto reject(beg, buf, end, env);
+next:
+  goto s1(beg, buf, end, env);
+}
+
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  UCHAR c = *buf++;
+  goto tbl[c](beg, buf, end, env);
+}
+
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* c */ [99] = (void*)s5, /* h */ [104] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* c */ [99] = (void*)s6, /* h */ [104] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      longjmp(env->ret, 1);
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      longjmp(env->ret, 1);
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  goto _s0(beg, buf, end, env);
+}
+
+__code
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  if (buf >= end) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    longjmp(env->ret, 1);
+  }
+  beg = buf;
+  goto _s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/Makefile	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,12 @@
+# Makefile
+program = grep
+objs	= grep.o
+CC	= gcc
+CFLAGS 	= -O0 -g
+#CFLAGS 	= -O2 -Wall
+
+$(program): $(objs)
+	$(CC) $(CFLAGS) -o $(program) $^
+
+clean:
+	rm *.o
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/Makefile~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,12 @@
+# Makefile
+program = grep_jobs.c
+CC	= gcc
+CFLAGS 	= -O0 -g
+
+
+
+
+
+all: $(TARGET)
+
+$(TARGET): 
\ No newline at end of file
Binary file regen/src/grep/c_grep has changed
Binary file regen/src/grep/cbc_grep has changed
Binary file regen/src/grep/grep has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep.c	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,417 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include "./include/task.h"
+
+/*
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+*/
+
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void *s0p(void *p);
+
+static void run_start();
+void regiTask(UCHARP beg, ENVP env, UCHARP end);
+void runTask();
+void *runMulti();
+void readTask(TASKP task);
+void execTask(TASKP task);
+void writeTask(TASKP task);
+void nop();
+
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+
+  run_start(beg, env, end, 3);
+
+  /*
+  int iret;
+  TASK task;
+  pthread_t thread;
+  createTask( &task, beg, env, end);
+  iret = pthread_create( &thread, NULL, s0p, (void*)&task );
+  pthread_join( thread, NULL);
+  */
+
+  //  s0(beg, beg, end, env);
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void *s0p(void *p) {
+  THARGP tharg = (THARGP)p;
+  filter(tharg->beg, tharg->buf, tharg->end, tharg->env);
+  return;
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2, /* s */ [115] = (void*)s5};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4, /* s */ [115] = (void*)s6};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
+
+static int division = 16;
+
+static void
+run_start(UCHARP beg, ENVP env, UCHARP end, int cpu_num) {
+  queueInit();
+
+  regiTask(beg, env, end);
+
+  //  runTask();
+
+  int iret;
+  
+  pthread_t thread;
+  iret = pthread_create( &thread, NULL, runMulti , NULL);
+  pthread_join(thread, NULL);
+
+  /*
+  pthread_t *threads;
+  mallocTh(threads, cpu_num);
+  int i;
+  for( i=0; i < cpu_num; i++ ) {
+    pthread_create( &threads[i], NULL, runMulti , NULL);    
+  }
+
+  for( i=0; i < cpu_num; i++ ) {
+    pthread_join(threads[i], NULL);
+  }
+  */
+
+}
+
+void regiTask(UCHARP beg, ENVP env, UCHARP end){
+
+  UCHARP dbeg, dend; 
+  //  const off_t dsize = 1024 * division; // 16k
+  const off_t dsize = 64 * division; 
+
+  for( dbeg=beg+dsize; dbeg < end; dbeg += dsize){
+    dend = dbeg + dsize;
+    if( dend > end) dend = end;
+    TASKP task = malloc(sizeof(TASK));
+    createTask(task, dbeg, env, dend);
+    task->read = (void *)readTask;
+    task->exec = (void *)execTask;
+    task->write = (void *) writeTask;
+    putTask(task);
+  }
+
+}
+
+void runTask() {
+  TASKP task1, task2, task3;
+
+  TASK taskNop;
+  taskNop.exec = (void *)nop;
+  taskNop.write = (void *)nop;
+
+  task2 = task3 = &taskNop;
+
+  while(!taskEmpty()){
+    task1 = getTask(); 
+ 
+    task1->read(task1);
+    task2->exec(task2);
+    task3->write(task3);
+      
+    task2 = task1;
+    task3 = task2;
+
+    free(task3);
+  }
+
+}
+
+void *runMulti() {
+
+  TASKP task1, task2, task3;
+
+  TASK taskNop;
+  taskNop.exec = (void *)nop;
+  taskNop.write = (void *)nop;
+
+  task2 = task3 = &taskNop;
+
+  while(!taskEmpty()){
+    task1 = getTask(); 
+ 
+    task1->read(task1);
+    task2->exec(task2);
+    task3->write(task3);
+      
+    task2 = task1;
+    task3 = task2;
+
+    free(task3);
+  }
+
+}
+
+// 行の初めにbegを持ってくる
+void readTask(TASKP task){
+  UCHARP beg = task->beg;
+  UCHARP end = task->end;
+
+  // これでは最初の1行目を飛ばしてしまう
+  beg = memchr(beg, '\n', end-beg);
+  task->beg = beg;
+  task->buf = beg;
+}
+
+void execTask(TASKP task){
+  s0(task->beg, task->buf, task-> end, task->env);
+}
+
+void writeTask(TASKP task){
+  //  print_line(task->beg, task->end);  
+}
+
+void nop(){
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep.c~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,368 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include "./include/task.h"
+
+/*
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+*/
+
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void *s0p(void *p);
+
+static void run_start();
+void regiTask(UCHARP beg, ENVP env, UCHARP end);
+void runTask();
+void readTask(TASKP task);
+void execTask(TASKP task);
+void writeTask(TASKP task);
+void nop();
+
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  //  s0(beg, beg, end, env);
+
+  int iret;
+  TASK task;
+  pthread_t thread;
+
+  run_start(beg, env, end);
+
+  createTask( &task, beg, env, end);
+  iret = pthread_create( &thread, NULL, s0p, (void*)&task );
+  pthread_join( thread, NULL);
+
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void *s0p(void *p) {
+  THARGP tharg = (THARGP)p;
+  filter(tharg->beg, tharg->buf, tharg->end, tharg->env);
+  return;
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2, /* s */ [115] = (void*)s5};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4, /* s */ [115] = (void*)s6};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
+
+static int division = 16;
+
+static void
+run_start(UCHARP beg, ENVP env, UCHARP end) {
+  
+
+  queueInit();
+
+  regiTask(beg, env, end);
+
+  runTask();
+
+}
+
+void regiTask(UCHARP beg, ENVP env, UCHARP end){
+
+  UCHARP dbeg, dend; 
+  //  const off_t dsize = 1024 * division; // 16k
+  const off_t dsize = 64 * division; // 16k
+
+  queueInit();
+  for( dbeg=beg; dbeg < end; dbeg += dsize){
+    dend = dbeg + dsize;
+    if( dend > end) dend = end;
+    TASKP task = malloc(sizeof(TASK));
+    createTask(task, dbeg, env, dend);
+    task->read = (void *)readTask;
+    task->exec = (void *)execTask;
+    task->write = (void *) writeTask;
+    putTask(task);
+  }
+
+}
+
+void runTask() {
+  TASKP task1, task2, task3;
+
+  TASK taskNop;
+  taskNop.exec = (void *)nop;
+  taskNop.write = (void *)nop;
+
+  task2 = task3 = &taskNop;
+
+  while(!taskEmpty()){
+    task1 = getTask(); 
+
+    task1->read(task1);
+    task2->exec(task2);
+    task3->write(task3);
+      
+    task2 = task1;
+    task3 = task2;
+
+    free(task3);
+  }
+
+}
+
+void readTask(TASKP task){
+
+}
+
+void execTask(TASKP task){
+
+}
+
+void writeTask(TASKP task){
+  //  print_line(task->beg, task->end);  
+}
+
+void nop(){
+
+}
+
Binary file regen/src/grep/grep.o has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grepAAA.c	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,259 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "AAA"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"AAA";
+  int i, len = 3;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return accept(beg, buf, end, env);
+}
+
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const void * tbl[256] = {[0 ... 255] &&skip, [0] &&involve, [1] &&involve, [2] &&involve, [4] &&involve, [65] &&involve};
+skip:
+  if ((buf += 2) > end) return reject(beg, end, end, env);
+  goto *tbl[*buf++];
+involve:
+  return s1(beg, buf - 3, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)predict, /* NL */ [10] = (void*)reject, /* A */ [65] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)predict, /* NL */ [10] = (void*)reject, /* A */ [65] = (void*)s3};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)predict, /* NL */ [10] = (void*)reject, /* A */ [65] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grepAAA.cbc.c	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,271 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <setjmp.h>
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+  jmp_buf *ret;
+} *ENVP;
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "AAA"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  env->ret = (jmp_buf *)malloc(sizeof(int)*100); // allocate dumy fields. for protect real ret addres.
+  env->ret = (jmp_buf *)malloc(sizeof(jmp_buf));
+  if (env == NULL) {
+    fprintf(stderr, "can't allocate jmp_buf");
+    exit(0);
+  }
+  int ret;
+  if ((ret = setjmp(env->ret)) == 0) {
+    goto _s0(beg, buf, end, env);
+  }
+  //free(env->ret); danger!
+  return;
+}
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto filter(beg, buf, end, env);
+}
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"AAA";
+  int i, len = 3;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  buf = end;
+  goto reject(beg, buf, end, env);
+next:
+  goto accept(beg, buf, end, env);
+}
+
+__code predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const void * tbl[256] = {[0 ... 255] &&skip, [0] &&involve, [1] &&involve, [2] &&involve, [4] &&involve, [65] &&involve};
+skip:
+  if ((buf += 2) > end) {
+    buf = end;
+    goto reject(beg, buf, end, env);
+  }
+  goto *tbl[*buf++];
+involve:
+  buf -= 3;
+  goto s1(beg, buf, end, env);
+}
+
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)predict, /* NL */ [10] = (void*)reject, /* A */ [65] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)predict, /* NL */ [10] = (void*)reject, /* A */ [65] = (void*)s3};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)predict, /* NL */ [10] = (void*)reject, /* A */ [65] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      longjmp(env->ret, 1);
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      longjmp(env->ret, 1);
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  goto _s0(beg, buf, end, env);
+}
+
+__code
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  if (buf >= end) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    longjmp(env->ret, 1);
+  }
+  beg = buf;
+  goto _s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep_jobs.c	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,313 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include "./include/task.h"
+
+/*
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+*/
+
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void *s0p(void *p);
+static void run_start();
+void regiTask(TASKP p, UCHARP beg, UCHARP end,  ENVP env);
+void *_read();
+void *_exec();
+void *_write();
+
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  //  s0(beg, beg, end, env);
+
+  int iret;
+  TASK task;
+  pthread_t thread;
+
+  createTask( &task, beg, buf, env, end);
+  iret = pthread_create( &thread, NULL, s0p, (void*)&task );
+  pthread_join( thread, NULL);
+
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void *s0p(void *p) {
+  THARGP tharg = (THARGP)p;
+  filter(tharg->beg, tharg->buf, tharg->end, tharg->env);
+  return;
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2, /* s */ [115] = (void*)s5};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4, /* s */ [115] = (void*)s6};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
+
+
+static int division = 16; // in kbyte
+static void
+run_start() {
+
+
+}
+
+void regiTask(TASKP p, UCHARP beg, UCHARP end,  ENVP env){
+
+
+}
+
+void *_read(){
+
+}
+
+void *_exec(){
+
+}
+
+void *_write(){
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep_jobs.c_back	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,261 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2, /* s */ [115] = (void*)s5};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4, /* s */ [115] = (void*)s6};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep_jobs.cbc.c	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,271 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <setjmp.h>
+//#include "./include/task.h"
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+  jmp_buf *ret;
+} *ENVP;
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.c"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  env->ret = (jmp_buf *)malloc(sizeof(int)*100); // allocate dumy fields. for protect real ret addres.
+  env->ret = (jmp_buf *)malloc(sizeof(jmp_buf));
+  if (env == NULL) {
+    fprintf(stderr, "can't allocate jmp_buf");
+    exit(0);
+  }
+  int ret;
+  if ((ret = setjmp(env->ret)) == 0) {
+    goto _s0(beg, buf, end, env);
+  }
+  //free(env->ret); danger!
+  return;
+}
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto filter(beg, buf, end, env);
+}
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  buf = end;
+  goto reject(beg, buf, end, env);
+next:
+  goto s1(beg, buf, end, env);
+}
+
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* c */ [99] = (void*)s5, /* h */ [104] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* c */ [99] = (void*)s6, /* h */ [104] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      longjmp(env->ret, 1);
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      longjmp(env->ret, 1);
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  goto _s0(beg, buf, end, env);
+}
+
+__code
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  if (buf >= end) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    longjmp(env->ret, 1);
+  }
+  beg = buf;
+  goto _s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep_jobs.cbc.c~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,270 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <setjmp.h>
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+  jmp_buf *ret;
+} *ENVP;
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.c"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+__code s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  env->ret = (jmp_buf *)malloc(sizeof(int)*100); // allocate dumy fields. for protect real ret addres.
+  env->ret = (jmp_buf *)malloc(sizeof(jmp_buf));
+  if (env == NULL) {
+    fprintf(stderr, "can't allocate jmp_buf");
+    exit(0);
+  }
+  int ret;
+  if ((ret = setjmp(env->ret)) == 0) {
+    goto _s0(beg, buf, end, env);
+  }
+  //free(env->ret); danger!
+  return;
+}
+__code _s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto filter(beg, buf, end, env);
+}
+
+__code filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  buf = end;
+  goto reject(beg, buf, end, env);
+next:
+  goto s1(beg, buf, end, env);
+}
+
+__code s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* c */ [99] = (void*)s5, /* h */ [104] = (void*)s2};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static __code (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* c */ [99] = (void*)s6, /* h */ [104] = (void*)s4};
+  if (buf > end) goto tbl['\n'](beg, buf, end, env);
+  goto tbl[*buf++](beg, buf, end, env);
+}
+
+__code s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  goto accept(beg, buf - 1, end, env);
+}
+
+__code
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      longjmp(env->ret, 1);
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      longjmp(env->ret, 1);
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  goto _s0(beg, buf, end, env);
+}
+
+__code
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  if (buf >= end) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    longjmp(env->ret, 1);
+  }
+  beg = buf;
+  goto _s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/grep_jobs.c~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,263 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include "./include/task.h"
+
+//typedef unsigned char UCHAR;
+//typedef unsigned char* UCHARP;
+
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void predict(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+#define __REGEX__ "h.s"
+
+UCHARP get_line_beg(UCHARP p, UCHARP beg) {
+  while(p > beg) {
+    if ((*--p) == '\n') return p+1;
+  }
+  return beg;
+}
+
+void print_line(UCHARP beg, UCHARP end) {
+  fwrite(beg, sizeof(char), (end - beg + 1), stdout);
+}
+
+void grep(int fd, ENVP env) {
+  caddr_t file_mmap;
+  UCHARP buf, end, beg;
+  off_t size;
+  struct stat sb;
+
+  if (fstat(fd, &sb)) {
+    fprintf(stderr, "can't fstat %s\n", env->filename);
+    exit(0);
+  }
+
+  size = sb.st_size;
+  file_mmap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+
+  if (file_mmap == (caddr_t)-1) {
+    fprintf(stderr, "can't mmap %s\n", env->filename);
+    exit(0);
+  }
+
+  beg = buf = (UCHARP) file_mmap;
+  end = beg + size - 1;
+  env->count = 0;
+
+  s0(beg, beg, end, env);
+
+  munmap(file_mmap, size);
+  return;
+}
+
+void stdingrep(ENVP env) {
+  char buf_[BUFSIZ];
+  UCHARP buf, beg, end;
+  buf = beg = (UCHARP) buf_;
+
+  while (fgets(buf_, BUFSIZ, stdin) != NULL) {
+    env->count = 0;
+    end = buf + strlen(buf_) - 1;
+    s0(beg, buf, end, env);
+  }
+}
+
+int main(int argc, char* argv[]) {
+  int i, fd, opt, with_filename = 0;
+
+  ENVP env = (ENVP)calloc(sizeof(ENVP), 1);
+
+  while ((opt=getopt(argc, argv, "chH")) != -1) {
+    switch (opt) {
+    case 'c':
+      env->print_count = 1;
+      break;
+    case 'h':
+      with_filename = -1;
+      break;
+    case 'H':
+      with_filename = 1;
+      break;
+    default:
+      fprintf(stderr, "invalid option.");
+      exit(0);
+    }
+  }
+
+  if (optind == argc) {
+    if (with_filename) {
+      /* handle -h/-H as help */
+      printf("grep pattern: %s\n", __REGEX__);
+      exit(1);
+    } else {
+      stdingrep(env);
+    }
+  } else {
+    switch (with_filename) {
+    case 0:  //default
+      if (argc == optind + 1) {
+        /* just grep 1 file. */
+        env->print_filename = FALSE;
+      } else {
+        /* grep 1 more files. */
+        env->print_filename = TRUE;
+      }
+      break;
+    // option
+    case -1:
+      env->print_filename = FALSE;
+      break;
+    case 1:
+      env->print_filename = TRUE;
+      break;
+    default: break;
+    }
+    for (i = optind; i < argc; i++) {
+      fd = open(argv[i], O_RDONLY, 0666);
+      if (fd == 0) {
+        printf("%d, %s\n", i, argv[i]);
+        fprintf(stderr, "can't open %s:", argv[i]);
+        continue;
+      }
+      env->filename = argv[i];
+      grep(fd, env);
+      close(fd);
+    }
+  }
+
+  return 0;
+}
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env);
+
+void s0(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return filter(beg, buf, end, env);
+}
+
+void filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static const UCHARP const key = (UCHARP)"h";
+  int i, len = 1;
+loop:
+  while ((buf = memchr(buf, key[0], end-buf))) {
+    for (i = 1; i < len; i++) {
+      if (buf[i] != key[i]) {
+        buf++;
+        goto loop;
+      }
+    }
+    goto next;
+  }
+  return reject(beg, end, end, env);
+next:
+  return s1(beg, buf, end, env);
+}
+
+void s1(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s2(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s3(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s1, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s2, /* s */ [115] = (void*)s5};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s4(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  static void (*tbl[256])(UCHARP, UCHARP, UCHARP, ENVP) = {[0 ... 255] = (void*)s3, /* NL */ [10] = (void*)reject, /* h */ [104] = (void*)s4, /* s */ [115] = (void*)s6};
+  if (buf > end) return tbl['\n'](beg, buf, end, env);
+  return tbl[*buf++](beg, buf, end, env);
+}
+
+void s5(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void s6(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  return accept(beg, buf - 1, end, env);}
+
+void
+accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP env)
+{
+  if (buf < beg) buf = beg;
+  UCHARP ret = (buf < end) ? (UCHARP) memchr(buf, '\n', (end - buf)) : NULL;
+  if (env->print_count) {
+    env->count++;
+    if (ret == NULL) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+      return;
+    }
+    beg = buf = ret + 1;
+  } else {
+    beg = get_line_beg(buf, beg);
+    if (env->print_filename) {
+      printf("%s:", env->filename);
+    }
+    if (ret == NULL) {
+      print_line(beg, end);
+      return;
+    }
+    print_line(beg, ret);
+    beg = buf = ret + 1;
+  }
+  return s0(beg, buf, end, env);
+}
+
+void
+reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP env) {
+  UCHARP ret;
+  if (buf >= end) {
+    ret = NULL;
+  } else {
+    if (*(buf-1) == '\n') {
+      ret = buf-1;
+    } else {
+      ret = (UCHARP)memchr(buf, '\n', (end - buf));
+    }
+  }
+  if (ret == NULL) {
+    if (env->print_count) {
+      if (env->print_filename) {
+        printf("%s:", env->filename);
+      }
+      printf("%d\n", env->count);
+    }
+    return;
+  }
+  beg = buf = ret + 1;
+  return s0(beg, buf, end, env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/include/task.c~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,10 @@
+#include <pthread.h>
+
+
+typedef struct THARG {
+  int *fdp;
+  UCHARP beg, buf, end;
+} THARG;
+typedef THARG *THARGP;
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/include/task.h	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,97 @@
+#include <pthread.h>
+
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+
+typedef struct THARG {
+  //  int *fdp;
+  UCHARP beg, buf, end;
+  ENVP env;
+  //  off_t size;
+} THARG;
+typedef THARG *THARGP;
+
+typedef struct TASK{
+  UCHARP beg, buf, end;
+  ENVP env;
+  /*
+  void (*read)(TASKP);
+  void (*exec)(TASKP);
+  void (*write)(TASKP);
+  */
+  void (*read)(void*);
+  void (*exec)(void*);
+  void (*write)(void*);
+} TASK;
+typedef TASK *TASKP;
+
+
+#define MAX 100
+static TASKP taskQueue[MAX];
+static int head, tail;
+
+
+//void createArg(THARGP p, int *fdp, UCHARP beg, UCHARP buf, off_t size ,ENVP env, UCHARP end, ) {
+void createTask(TASKP p, UCHARP beg, ENVP env, UCHARP end ) {
+  //  p->fdp = fdp;
+  p->beg = beg;
+  p->buf = beg;
+  p->end = end;
+  p->env = env;
+  //  p->size = size;
+}
+
+void createTasks(TASKP *p, UCHARP beg, UCHARP buf, off_t size, ENVP env, int num) {
+  int i;
+  off_t dsize = size / num;
+  off_t rem = size % num;
+  UCHARP end;
+  for ( i=1; i<num+1; i++) {
+    p[i-1] = malloc(sizeof(THARG));
+    end = beg + dsize * i;
+    createTask( p[i-1], beg+dsize*(i-1), env, end);
+    //    createTask( p[i-1], beg+dsize*(i-1), buf+dsize*(i-1), env, end);
+  }
+}
+
+void mallocTh(pthread_t *threads, int num) {
+  int i;
+  threads = malloc(sizeof(pthread_t) * num);
+
+  for( i=0; i<num; i++) {
+    threads[i] = malloc(sizeof(pthread_t));
+  }
+}
+
+void queueInit() {
+  head = 0;
+  tail = 0;
+}
+
+void putTask(TASKP task) {
+  taskQueue[tail++] = task;
+  if(tail > MAX) tail = 0;
+}
+
+TASKP getTask() {
+  TASKP task = taskQueue[head++];
+  if(head > MAX) head = 0;
+  return task;
+}
+
+int taskEmpty() {
+  return ( head == tail);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/include/task.h~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,97 @@
+#include <pthread.h>
+
+
+typedef unsigned char UCHAR;
+typedef unsigned char* UCHARP;
+
+typedef enum BOOL {
+  FALSE = 0,
+  TRUE  = 1
+} BOOL;
+
+typedef struct ENV {
+  BOOL print_count;
+  BOOL print_filename;
+  int count;
+  char *filename;
+} *ENVP;
+
+typedef struct THARG {
+  //  int *fdp;
+  UCHARP beg, buf, end;
+  ENVP env;
+  //  off_t size;
+} THARG;
+typedef THARG *THARGP;
+
+typedef struct TASK{
+  UCHARP beg, buf, end;
+  ENVP env;
+  void (*read)(TASKP);
+  void (*exec)(TASKP);
+  void (*write)(TASKP);
+  /*
+  void *read;
+  void *exec;
+  void *write;
+  */
+} TASK;
+typedef TASK *TASKP;
+
+#define MAX 100
+static TASKP taskQueue[MAX];
+static int head, tail;
+
+
+
+//void createArg(THARGP p, int *fdp, UCHARP beg, UCHARP buf, off_t size ,ENVP env, UCHARP end, ) {
+void createTask(TASKP p, UCHARP beg, ENVP env, UCHARP end ) {
+  //  p->fdp = fdp;
+  p->beg = beg;
+  p->buf = beg;
+  p->end = end;
+  p->env = env;
+  //  p->size = size;
+}
+
+void createTasks(TASKP *p, UCHARP beg, UCHARP buf, off_t size, ENVP env, int num) {
+  int i;
+  off_t dsize = size / num;
+  off_t rem = size % num;
+  UCHARP end;
+  for ( i=1; i<num+1; i++) {
+    p[i-1] = malloc(sizeof(THARG));
+    end = beg + dsize * i;
+    createTask( p[i-1], beg+dsize*(i-1), env, end);
+    //    createTask( p[i-1], beg+dsize*(i-1), buf+dsize*(i-1), env, end);
+  }
+}
+
+void mallocTh(pthread_t *threads, int num) {
+  int i;
+  threads = malloc(sizeof(pthread_t) * num);
+
+  for( i=0; i<num; i++) {
+    threads[i] = malloc(sizeof(pthread_t));
+  }
+}
+
+void queueInit() {
+  head = 0;
+  tail = 0;
+}
+
+void putTask(TASKP task) {
+  taskQueue[tail++] = task;
+  if(tail > MAX) tail = 0;
+}
+
+TASKP getTask() {
+  TASKP task = taskQueue[head++];
+  if(head > MAX) head = 0;
+  return task;
+}
+
+int taskEmpty() {
+  return ( head == tail);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/jobs.txt	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,199 @@
+Thank you.
+
+I'm honored to be with you today for your commencement from one of the finest universities in the world.
+ Truth be told, I never graduated from college, and this is the closest I've ever gotten to a college graduation.
+ Today, I want to tell you three stories from my life.
+ That's it.
+ No big deal.
+ Just three stories.
+
+
+The first story is about connecting the dots.
+ I dropped out of Reed College after the first six months, but then stayed around as a drop-in for another 18 months or so before I really quit.
+ So why did I drop out?
+
+It started before I was born.
+ My biological mother was a young, unwed graduate student, and she decided to put me up for adoption.
+ She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife -- except that when I popped out they decided at the last minute that they really wanted a girl.
+
+
+So my parents, who were on a waiting list, got a call in the middle of the night asking, "We've got an unexpected baby boy; do you want him?" They said, "Of course.
+" My biological mother found out later that my mother had never graduated from college and that my father had never graduated from high school.
+ She refused to sign the final adoption papers.
+ She only relented a few months later when my parents promised that I would go to college.
+ This was the start in my life.
+
+
+And 17 years later I did go to college.
+ But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents' savings were being spent on my college tuition.
+ After six months, I couldn't see the value in it.
+ I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out.
+ And here I was spending all of the money my parents had saved their entire life.
+
+
+So I decided to drop out and trust that it would all work out okay.
+ It was pretty scary at the time, but looking back it was one of the best decisions I ever made.
+ The minute I dropped out I could stop taking the required classes that didn't interest me, and begin dropping in on the ones that looked far more interesting.
+
+
+It wasn't all romantic.
+ I didn't have a dorm room, so I slept on the floor in friends' rooms.
+ I returned coke bottles for the five cent deposits to buy food with, and I would walk the seven miles across town every Sunday night to get one good meal a week at the Hare Krishna temple.
+ I loved it.
+ And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on.
+ Let me give you one example:
+
+Reed College at that time offered perhaps the best calligraphy instruction in the country.
+ Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed.
+ Because I had dropped out and didn't have to take the normal classes, I decided to take a calligraphy class to learn how to do this.
+ I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great.
+ It was beautiful, historical, artistically subtle in a way that science can't capture, and I found it fascinating.
+
+
+None of this had even a hope of any practical application in my life.
+ But ten years later, when we were designing the first Macintosh computer, it all came back to me.
+ And we designed it all into the Mac.
+ It was the first computer with beautiful typography.
+ If I had never dropped in on that single course in college, the "Mac" would have never had multiple typefaces or proportionally spaced fonts.
+ And since Windows just copied the Mac, it's likely that no personal computer would have them.
+ If I had never dropped out, I would have never dropped in on that calligraphy class, and personal computers might not have the wonderful typography that they do.
+ Of course it was impossible to connect the dots looking forward when I was in college.
+ But it was very, very clear looking backwards 10 years later.
+
+Again, you can't connect the dots looking forward; you can only connect them looking backwards.
+ So you have to trust that the dots will somehow connect in your future.
+ You have to trust in something -- your gut, destiny, life, karma, whatever -- because believing that the dots will connect down the road will give you the confidence to follow your heart, even when it leads you off the well-worn path, and that will make all the difference.
+
+
+My second story is about love and loss.
+
+
+I was lucky -- I found what I loved to do early in life.
+ Woz and I started Apple in my parents' garage when I was 20.
+ We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a two billion dollar company with over 4000 employees.
+ We'd just released our finest creation -- the Macintosh -- a year earlier, and I had just turned 30.
+
+
+And then I got fired.
+ How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well.
+ But then our visions of the future began to diverge and eventually we had a falling out.
+ When we did, our Board of Directors sided with him.
+ And so at 30, I was out.
+ And very publicly out.
+ What had been the focus of my entire adult life was gone, and it was devastating.
+
+
+I really didn't know what to do for a few months.
+ I felt that I had let the previous generation of entrepreneurs down -- that I had dropped the baton as it was being passed to me.
+ I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly.
+ I was a very public failure, and I even thought about running away from the valley.
+ But something slowly began to dawn on me: I still loved what I did.
+ The turn of events at Apple had not changed that one bit.
+ I had been rejected, but I was still in love.
+ And so I decided to start over.
+
+
+I didn't see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me.
+ The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything.
+ It freed me to enter one of the most creative periods of my life.
+
+
+During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife.
+ Pixar went on to create the world's first computer-animated feature film, Toy Story, and is now the most successful animation studio in the world.
+ In a remarkable turn of events, Apple bought NeXT, and I retuned to Apple, and the technology we developed at NeXT is at the heart of Apple's current renaissance.
+ And Laurene and I have a wonderful family together.
+
+
+I'm pretty sure none of this would have happened if I hadn't been fired from Apple.
+ It was awful tasting medicine, but I guess the patient needed it.
+ Sometime life -- Sometimes life's going to hit you in the head with a brick.
+ Don't lose faith.
+ I'm convinced that the only thing that kept me going was that I loved what I did.
+ You've got to find what you love.
+
+
+And that is as true for work as it is for your lovers.
+ Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work.
+ And the only way to do great work is to love what you do.
+ If you haven't found it yet, keep looking -- and don't settle.
+ As with all matters of the heart, you'll know when you find it.
+ And like any great relationship, it just gets better and better as the years roll on.
+ So keep looking -- don't settle.
+
+
+My third story is about death.
+
+
+When I was 17, I read a quote that went something like: "If you live each day as if it was your last, someday you'll most certainly be right.
+" It made an impression on me, and since then, for the past 33 years, I've looked in the mirror every morning and asked myself: "If today were the last day of my life, would I want to do what I am about to do today?" And whenever the answer has been "No" for too many days in a row, I know I need to change something.
+
+
+Remembering that I'll be dead soon is the most important tool I've ever encountered to help me make the big choices in life.
+ Because almost everything -- all external expectations, all pride, all fear of embarrassment or failure -- these things just fall away in the face of death, leaving only what is truly important.
+ Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose.
+ You are already naked.
+ There is no reason not to follow your heart.
+
+
+About a year ago I was diagnosed with cancer.
+ I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas.
+ I didn't even know what a pancreas was.
+ The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months.
+ My doctor advised me to go home and get my affairs in order, which is doctor's code for "prepare to die.
+" It means to try and tell your kids everything you thought you'd have the next 10 years to tell them in just a few months.
+ It means to make sure everything is buttoned up so that it will be as easy as possible for your family.
+ It means to say your goodbyes.
+
+
+I lived with that diagnosis all day.
+ Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach into my intestines, put a needle into my pancreas and got a few cells from the tumor.
+ I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery.
+ I had the surgery and, thankfully, I'm fine now.
+
+
+This was the closest I've been to facing death, and I hope it's the closest I get for a few more decades.
+ Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept: No one wants to die.
+
+
+Even people who want to go to heaven don't want to die to get there.
+ And yet death is the destination we all share.
+ No one has ever escaped it.
+ And that is as it should be, because Death is very likely the single best invention of Life.
+ It's Life's change agent.
+ It clears out the old to make way for the new.
+ Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away.
+ Sorry to be so dramatic, but it's quite true.
+
+
+Your time is limited, so don't waste it living someone else's life.
+ Don't be trapped by dogma -- which is living with the results of other people's thinking.
+ Don't let the noise of others' opinions drown out your own inner voice.
+ And most important, have the courage to follow your heart and intuition.
+ They somehow already know what you truly want to become.
+ Everything else is secondary.
+
+
+When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the "bibles" of my generation.
+ It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch.
+ This was in the late 60s, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and Polaroid cameras.
+ It was sort of like Google in paperback form, 35 years before Google came along.
+ It was idealistic, overflowing with neat tools and great notions.
+
+
+Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue.
+ It was the mid-1970s, and I was your age.
+ On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous.
+ Beneath it were the words: "Stay Hungry.
+ Stay Foolish.
+" It was their farewell message as they signed off.
+ Stay Hungry.
+ Stay Foolish.
+ And I've always wished that for myself.
+ And now, as you graduate to begin anew, I wish that for you.
+
+
+Stay Hungry.
+ Stay Foolish.
+
+
+Thank you all very much.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/jobs.txt~	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,60 @@
+Thank you.
+
+I'm honored to be with you today for your commencement from one of the finest universities in the world. Truth be told, I never graduated from college, and this is the closest I've ever gotten to a college graduation. Today, I want to tell you three stories from my life. That's it. No big deal. Just three stories.
+
+The first story is about connecting the dots. I dropped out of Reed College after the first six months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out?
+
+It started before I was born. My biological mother was a young, unwed graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife -- except that when I popped out they decided at the last minute that they really wanted a girl.
+
+So my parents, who were on a waiting list, got a call in the middle of the night asking, "We've got an unexpected baby boy; do you want him?" They said, "Of course." My biological mother found out later that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would go to college. This was the start in my life.
+
+And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents' savings were being spent on my college tuition. After six months, I couldn't see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life.
+
+So I decided to drop out and trust that it would all work out okay. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn't interest me, and begin dropping in on the ones that looked far more interesting.
+
+It wasn't all romantic. I didn't have a dorm room, so I slept on the floor in friends' rooms. I returned coke bottles for the five cent deposits to buy food with, and I would walk the seven miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example:
+
+Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn't have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can't capture, and I found it fascinating.
+
+None of this had even a hope of any practical application in my life. But ten years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the "Mac" would have never had multiple typefaces or proportionally spaced fonts. And since Windows just copied the Mac, it's likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on that calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards 10 years later.
+Again, you can't connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something -- your gut, destiny, life, karma, whatever -- because believing that the dots will connect down the road will give you the confidence to follow your heart, even when it leads you off the well-worn path, and that will make all the difference.
+
+My second story is about love and loss.
+
+I was lucky -- I found what I loved to do early in life. Woz and I started Apple in my parents' garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a two billion dollar company with over 4000 employees. We'd just released our finest creation -- the Macintosh -- a year earlier, and I had just turned 30.
+
+And then I got fired. How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him. And so at 30, I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating.
+
+I really didn't know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down -- that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me: I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over.
+
+I didn't see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life.
+
+During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the world's first computer-animated feature film, Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, and I retuned to Apple, and the technology we developed at NeXT is at the heart of Apple's current renaissance. And Laurene and I have a wonderful family together.
+
+I'm pretty sure none of this would have happened if I hadn't been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometime life -- Sometimes life's going to hit you in the head with a brick. Don't lose faith. I'm convinced that the only thing that kept me going was that I loved what I did. You've got to find what you love.
+
+And that is as true for work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking -- and don't settle. As with all matters of the heart, you'll know when you find it. And like any great relationship, it just gets better and better as the years roll on. So keep looking -- don't settle.
+
+My third story is about death.
+
+When I was 17, I read a quote that went something like: "If you live each day as if it was your last, someday you'll most certainly be right." It made an impression on me, and since then, for the past 33 years, I've looked in the mirror every morning and asked myself: "If today were the last day of my life, would I want to do what I am about to do today?" And whenever the answer has been "No" for too many days in a row, I know I need to change something.
+
+Remembering that I'll be dead soon is the most important tool I've ever encountered to help me make the big choices in life. Because almost everything -- all external expectations, all pride, all fear of embarrassment or failure -- these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.
+
+About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn't even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctor's code for "prepare to die." It means to try and tell your kids everything you thought you'd have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.
+
+I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and, thankfully, I'm fine now.
+
+This was the closest I've been to facing death, and I hope it's the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept: No one wants to die.
+
+Even people who want to go to heaven don't want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It's Life's change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it's quite true.
+
+Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma -- which is living with the results of other people's thinking. Don't let the noise of others' opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.
+
+When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the "bibles" of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 60s, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and Polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along. It was idealistic, overflowing with neat tools and great notions.
+
+Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: "Stay Hungry. Stay Foolish." It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I've always wished that for myself. And now, as you graduate to begin anew, I wish that for you.
+
+Stay Hungry. Stay Foolish.
+
+Thank you all very much.
\ No newline at end of file
Binary file regen/src/grep/jobs_grep has changed
Binary file regen/src/grep/jobs_grep_cbc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regen/src/grep/jobs_grep_cbc.dSYM/Contents/Info.plist	Tue Jun 28 16:25:37 2011 +0900
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+	<dict>
+		<key>CFBundleDevelopmentRegion</key>
+		<string>English</string>
+		<key>CFBundleIdentifier</key>
+		<string>com.apple.xcode.dsym.jobs_grep_cbc</string>
+		<key>CFBundleInfoDictionaryVersion</key>
+		<string>6.0</string>
+		<key>CFBundlePackageType</key>
+		<string>dSYM</string>
+		<key>CFBundleSignature</key>
+		<string>????</string>
+		<key>CFBundleShortVersionString</key>
+		<string>1.0</string>
+		<key>CFBundleVersion</key>
+		<string>1</string>
+	</dict>
+</plist>
Binary file regen/src/grep/jobs_grep_cbc.dSYM/Contents/Resources/DWARF/jobs_grep_cbc has changed
Binary file regen/src/regen has changed
--- a/regen/src/template/cbc.c	Sun Jun 19 16:36:05 2011 +0900
+++ b/regen/src/template/cbc.c	Tue Jun 28 16:25:37 2011 +0900
@@ -18,7 +18,7 @@
       printf("%s:", env->filename);
     }
     if (ret == NULL) {
-      print_line(beg, ret);
+      print_line(beg, end);
       longjmp(env->ret, 1);
     }
     print_line(beg, ret);