1
0
mirror of https://github.com/fumiama/simple-dict.git synced 2026-06-05 02:00:25 +08:00

add printall

This commit is contained in:
源文雨
2023-04-02 15:05:18 +08:00
parent 3d769ecd13
commit a1283e714d
2 changed files with 36 additions and 1 deletions

View File

@@ -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)

33
printall.c Normal file
View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <string.h>
#include <simple_protobuf.h>
#include <sys/types.h>
#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: <dict.sp>");
}