Mercurial > hg > Applications > Grep
changeset 53:82fbc8478f7b
add regexParser
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Jun 2015 18:04:42 +0900 |
parents | a2826bf4e80a |
children | f540de861cd6 |
files | c/regexParser/Makefile c/regexParser/main.cc |
diffstat | 2 files changed, 69 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/regexParser/Makefile Thu Jun 04 18:04:42 2015 +0900 @@ -0,0 +1,10 @@ +TARGET= regexParser +OPTION= -Wall -O0 -g + +$(TARGET):main.cc + clang $(OPTION) -o $(TARGET) main.cc + +clean: + rm -f $(TARGET) + rm -r $(TARGET).dSYM + rm -f *~ \#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/regexParser/main.cc Thu Jun 04 18:04:42 2015 +0900 @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int bitBlock = sizeof(unsigned long) * 8; + +typedef struct bitInfo { + int arrayNum; + unsigned long *bitContainer; +}BitInfo,*BitInfoPtr; + +void bitSet(BitInfoPtr bi, int bitSetPosition) { + + unsigned long tmp = 1; + int arrayPosition = 0; + + arrayPosition = bitSetPosition / bitBlock; + bitSetPosition = bitSetPosition % bitBlock; + + tmp = tmp << (bitBlock - 1 - bitSetPosition); + bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; +} + +void bitPrint(BitInfoPtr bi) { + for (int i = 0; i < bi->arrayNum ; i++) { + for (int j = bitBlock - 1; j >= 0; j--) { + printf( "%lu", ( bi->bitContainer[i] >> j ) & 1 ); + } + printf(" "); + } + puts(""); +} + +int main(int argc, char **argv) { + + BitInfoPtr bi = (BitInfoPtr)malloc(sizeof(BitInfo)); + int bitSetPosition = 0; + + for (int i = 1; i < argc ; i++) { + if (strcmp(argv[i],"-n") == 0) { + bitSetPosition = atoi(argv[i+1]); + } + } + + bi->arrayNum = (bitSetPosition + 1) / bitBlock; + if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; + + printf("Array Num : %d\n",bi->arrayNum); + + unsigned long bitContainer[bi->arrayNum]; + for (int i = 0; i < bi->arrayNum; i++) { + bitContainer[i] = 0; + } + + bi->bitContainer = bitContainer; + bitSet(bi,bitSetPosition); + bitPrint(bi); + return 0; +}