comparison c/dfaTobin/main.cc @ 47:3d59066744d8

fix
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Mon, 25 May 2015 14:50:51 +0900
parents e13aac1cff0f
children
comparison
equal deleted inserted replaced
46:e13aac1cff0f 47:3d59066744d8
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5
6 const char *usr_help_str = "./dfa2bin -regex [regex]";
7
8 typedef struct dfa{
9 short int state : 1;
10 }dfa,*dfaPtr;
11
12 void checkAppearChar(unsigned char* regex, int regexLength){
13 int charTable[256];
14
15 for (int i = 0; i < regexLength; i++) {
16 charTable[i] += 1;
17 }
18
19 for (int i = 0; i < 256; i++) {
20 printf("charTable[%d] : %d\n",i,charTable[i]);
21 }
22 }
23
24 void dfa2bin(unsigned char *regex){
25 int regexLength = strlen((char*)regex);
26 char *regexCharTable = (char*)malloc(sizeof(char)*regexLength);
27 dfaPtr dfa = (dfaPtr)malloc(sizeof(dfa)*(regexLength+1));
28
29 for (int i = 0; i < regexLength+1 ; i++) {
30 dfa[i].state = 0;
31 }
32
33 dfa[0].state = 1;
34
35 checkAppearChar(regex,regexLength);
36 }
37
2 38
3 int main(int argc, char *argv[]){ 39 int main(int argc, char *argv[]){
4 40
5 char *regex = 0; 41 unsigned char *regex = 0;
6 42
7 for (int i = 1; argv[i]; ++i) { 43 for (int i = 1; argv[i]; ++i) {
8 if (strcmp(argv[i], "-file") == 0){ 44 if (strcmp(argv[i], "-regex") == 0){
9 regex = argv[i+1]; 45 regex = (unsigned char*)argv[i+1];
10 } 46 }
11 } 47 }
12 48
13 if (regex == 0){ 49 if (regex == 0){
14 puts(usr_help_str); 50 puts(usr_help_str);
15 exit(1); 51 exit(1);
16 } 52 }
17 53
54 dfa2bin(regex);
55
56 printf("regex : %s\n",regex);
18 return 0; 57 return 0;
19 } 58 }