funkalicious 0.1

material_slice.c

Go to the documentation of this file.
00001 /*
00002 ** material_slice.c
00003 ** 
00004     Copyright (C) 2009 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 Nov 29 12:21:27 2009 Johnny Q. Hacker
00023 ** Last update Sun May 12 01:17:25 2002 Speed Blue
00024 */
00025 
00026 #include <stdio.h>
00027 #include <glib-2.0/glib.h>
00028 #include <gio/gio.h>
00029 #include <libdotcode/grid1.h>
00030 #include <libdotcode/displ.h>
00031 #include "material_slice_args.h"
00032 
00033 int main(int argc, char** argv) {
00034   g_type_init();
00035   GError *err = NULL;
00036   struct args *args = process_args(argc, argv, &err);
00037   if(args == NULL) {
00038     /*If err is NULL; this means that the user just wanted the version.*/
00039     if(err == NULL) {
00040       return 0;
00041     }else{
00042       fprintf(stderr, "ERROR processing args: %s\n", err->message);
00043       return 1;
00044     }
00045   }
00046   GList *l;
00047   char* s;
00048   GFile *cwd = g_file_new_for_path(".");
00049   for(l=args->struct_list; l!=NULL; l=l->next) {
00050     err = NULL;
00051     struct dotcode_grid1* g = dotcode_displ_get_grid1((GFile*)(l->data), &err);
00052     if((g == NULL) || (err != NULL)) {
00053       s = g_file_get_uri((GFile*)(l->data));
00054       if(err == NULL) {
00055   fprintf(stderr, "WARNING: unable to read in grid1 from specified file (%s); no GError was returned, so I have no further information.\n", s);
00056       }else{
00057   fprintf(stderr, "WARNING: unable to read in grid1 from specified file (%s): %s\n", s, err->message);
00058       }
00059       g_free(s);
00060       continue;
00061     }
00062     GList *ll;
00063     for(ll = args->xslices; ll != NULL; ll=ll->next) {
00064       err = NULL;
00065       dotcode_grid1_write_assignments_slice_text(g, cwd, DOTCODE_COORD_X, *(int*)(ll->data), &err);
00066       if(err != NULL) {
00067   fprintf(stderr, "ERROR writing X slice at %d: %s\n", *(int*)(ll->data), err->message);
00068   g_error_free(err);
00069       }
00070     }
00071     for(ll = args->yslices; ll != NULL; ll=ll->next) {
00072       err = NULL;
00073       dotcode_grid1_write_assignments_slice_text(g, cwd, DOTCODE_COORD_Y, *(int*)(ll->data), &err);
00074       if(err != NULL) {
00075   fprintf(stderr, "ERROR writing Y slice at %d: %s\n", *(int*)(ll->data), err->message);
00076   g_error_free(err);
00077       }
00078     }
00079     for(ll = args->zslices; ll != NULL; ll=ll->next) {
00080       err = NULL;
00081       dotcode_grid1_write_assignments_slice_text(g, cwd, DOTCODE_COORD_Z, *(int*)(ll->data), &err);
00082       if(err != NULL) {
00083   fprintf(stderr, "ERROR writing Z slice at %d: %s\n", *(int*)(ll->data), err->message);
00084   g_error_free(err);
00085       }
00086     }
00087     dotcode_grid1_free(g);
00088   }
00089   return 0;
00090 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines