funkalicious 0.1

round-trip-grid-file.c

Go to the documentation of this file.
00001 /*
00002 ** round-trip-grid-file.c
00003 ** 
00004     Copyright (C) 2010 Joseph Pingenot
00005 
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Affero General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Affero General Public License for more details.
00015 
00016     You should have received a copy of the GNU Affero General Public License
00017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 ** Made by (Johnny Q. Hacker)
00020 ** Login   <solarion@nathan>
00021 ** 
00022 ** Started on  Sun Feb 28 06:54:55 2010 Johnny Q. Hacker
00023 ** Last update Sun May 12 01:17:25 2002 Speed Blue
00024 */
00025 
00026 #include <stdio.h>
00027 #include <libdotcode/read_binary_data.h>
00028 #include <libdotcode/write_binary_data.h>
00029 
00030 int main(int argc, char** argv) {
00031   if(argc < 3) {
00032     fprintf(stderr, "ERROR: you must give two arguments: the input file and the output file.\n");
00033     return 1;
00034   }
00035   g_type_init();
00036   //fprintf(stderr, "=%s\n", argv[0]);
00037   //fprintf(stderr, "=%s\n", argv[1]);
00038   GFile* inf = g_file_new_for_commandline_arg(argv[1]);
00039   GFile* ouf = g_file_new_for_commandline_arg(argv[2]);
00040   printf("Roundtripping from \"%s\" to \"%s\"\n", argv[1], argv[2]);
00041   GError *e = NULL;
00042   enum dotcode_type t;
00043   void* g = read_dotcode_generic_file(&t, inf, &e);
00044   if(e != NULL) {
00045     fprintf(stderr, "ERROR reading input file: %s\n", e->message);
00046     return 10;
00047   }
00048   if(g == NULL) {
00049     fprintf(stderr, "ERROR read_dotcode_generic_file returned NULL!\n");
00050     return 11;
00051   }
00052   if(t != DOTCODE_GRID) {
00053     fprintf(stderr, "ERROR got incorrect dotcode type (should be grid!): was %d (%s)\n", t, dotcode_string_from_type2(t));
00054     return 12;
00055   }
00056   e = dotcode_write_typed_file(t, g, ouf);
00057   if(e != NULL) {
00058     fprintf(stderr, "ERROR writing input file back out again: %s\n", e->message);
00059     return 20;
00060   }
00061   return 0;
00062 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines