diff --git a/CMakeLists.txt b/CMakeLists.txt index 71203d8..1a204d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.0) project(simple-dict-server C) SET(CMAKE_BUILD_TYPE "Release") @@ -49,12 +49,14 @@ message(STATUS "optional:-std=gnu99") add_executable(simple-dict-server server.c) add_executable(simple-dict-client client.c) add_executable(cfgwriter cfgwriter.c) +add_executable(printall printall.c) #add_executable(migrate migrate.c) #add_executable(migratenew migratenew.c) target_link_libraries(simple-dict-server scrypto libspb.a pthread) target_link_libraries(simple-dict-client scrypto libspb.a pthread) target_link_libraries(cfgwriter libspb.a) +target_link_libraries(printall libspb.a) #target_link_libraries(migrate libspb.a) #target_link_libraries(migratenew libspb.a) diff --git a/printall.c b/printall.c new file mode 100644 index 0000000..08dd906 --- /dev/null +++ b/printall.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include "dict.h" + +static struct dict_t d; +static uint8_t buf[8+DICTSZ]; + +#define has_next(fp, ch) ((ch=getc(fp)),(feof(fp)?0:(ungetc(ch,fp),1))) + +int main(int argc, char** argv) { + if(argc == 2) { + uint32_t* items_len = align_struct(DICTSZ, 2, d.key, d.data); + FILE* f = fopen(argv[1], "rb"); + if(f) { + int ch; + + while(has_next(f, ch)) { + SIMPLE_PB* spb = read_pb_into(f, (SIMPLE_PB*)buf); + struct dict_t* d; + if(!spb) { + fputs("Bad spb file", stderr); + exit(EXIT_FAILURE); + } + dict_t* dd = (dict_t*)spb->target; + printf("%s\t\t%s\n", dd->key, dd->data); + } + fclose(f); + } else puts("Open file error."); + } else puts("Usage: "); +}