00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <fcntl.h>
00025 #include <string.h>
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <unistd.h>
00029
00030 #include <iostream>
00031 #include <string>
00032 #include <drizzled/message/table.pb.h>
00033 #include <google/protobuf/io/zero_copy_stream.h>
00034 #include <google/protobuf/io/zero_copy_stream_impl.h>
00035 #include <google/protobuf/text_format.h>
00036
00037 using namespace std;
00038 using namespace drizzled;
00039 using namespace google;
00040
00041
00042 static void print_table(const message::Table &table)
00043 {
00044 string proto_as_text("");
00045
00046 protobuf::TextFormat::PrintToString(table, &proto_as_text);
00047
00048 cout << proto_as_text;
00049 }
00050
00051 int main(int argc, char* argv[])
00052 {
00053 GOOGLE_PROTOBUF_VERIFY_VERSION;
00054
00055 if (argc != 2) {
00056 fprintf(stderr, "Usage: %s SCHEMA\n", argv[0]);
00057 return -1;
00058 }
00059
00060 message::Table table;
00061
00062 {
00063 int fd= open(argv[1], O_RDONLY);
00064
00065 if (fd == -1)
00066 {
00067 perror("Failed to open table definition file");
00068 return -1;
00069 }
00070
00071 protobuf::io::ZeroCopyInputStream* input=
00072 new protobuf::io::FileInputStream(fd);
00073
00074 if (!table.ParseFromZeroCopyStream(input))
00075 {
00076 fprintf(stderr, "Failed to parse table.");
00077 close(fd);
00078 return -1;
00079 }
00080
00081 close(fd);
00082 }
00083
00084 print_table(table);
00085
00086 return 0;
00087 }