Enlightenment CVS committal Author : devilhorns Project : e17 Module : apps/emprint
Dir : e17/apps/emprint/src/bin Modified Files: main.c Log Message: When failing during startup, make sure we do the necessary shutdowns. Use exit(code) rather than returns; Fix formatting issues. Remove whitespace. =================================================================== RCS file: /cvs/e/e17/apps/emprint/src/bin/main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- main.c 3 Jan 2008 21:35:40 -0000 1.7 +++ main.c 3 Jan 2008 22:03:57 -0000 1.8 @@ -15,7 +15,7 @@ #include <Ecore_X.h> #include <Ecore_X_Cursor.h> #include <Edje.h> -#include "config.h" +#include <getopt.h> #if TIME_WITH_SYS_TIME # include <sys/time.h> # include <time.h> @@ -26,8 +26,8 @@ # include <time.h> # endif #endif +#include "config.h" #include "emprint.h" -#include <getopt.h> /* Function Prototypes */ static void _em_parse_cmdln(Options *o, int argc, char *argv[]); @@ -71,24 +71,46 @@ opts = calloc(1, sizeof(Options)); if (opts == NULL) { - fprintf(stderr,"calloc() failed."); - exit( EXIT_FAILURE ); + printf("calloc() failed."); + exit(EXIT_FAILURE); } /* parse our command line */ _em_parse_cmdln(opts, argc, argv); /* initialize ecore */ - if (!ecore_init()) return -1; + if (!ecore_init()) + { + _em_free_options(); + exit(EXIT_FAILURE); + } /* initialize ecore_evas */ - if (!ecore_evas_init()) return -1; + if (!ecore_evas_init()) + { + _em_free_options(); + ecore_shutdown(); + exit(EXIT_FAILURE); + } /* initialize ecore_x */ - if (!ecore_x_init(NULL)) return -1; + if (!ecore_x_init(NULL)) + { + _em_free_options(); + ecore_evas_shutdown(); + ecore_shutdown(); + exit(EXIT_FAILURE); + } /* initialize edje */ - if (!edje_init()) return -1; + if (!edje_init()) + { + _em_free_options(); + ecore_x_shutdown(); + ecore_evas_shutdown(); + ecore_shutdown(); + exit(EXIT_FAILURE); + } /* set app arguments */ ecore_app_args_set(argc, (const char **)argv); @@ -127,63 +149,65 @@ _em_parse_cmdln(Options *o, int argc, char *argv[]) { int tw, th, ts; - struct option longopts[] = { - {"beep", no_argument, &(o->beep), 1 }, - {"delay", required_argument, 0, 'd'}, - {"app", required_argument, 0, 'a'}, - {"thumb", required_argument, 0, 't'}, - {"thumb-geom", required_argument, 0, 'g'}, - {"quality", required_argument, 0, 'q'}, - {"region", no_argument, &(o->region), 1 }, - {"window", no_argument, &(o->window), 1 }, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'v'}, - {NULL, 0, NULL, 0 } - }; char c; + struct option longopts[] = + { + {"beep", no_argument, &(o->beep), 1}, + {"delay", required_argument, 0, 'd'}, + {"app", required_argument, 0, 'a'}, + {"thumb", required_argument, 0, 't'}, + {"thumb-geom", required_argument, 0, 'g'}, + {"quality", required_argument, 0, 'q'}, + {"region", no_argument, &(o->region), 1}, + {"window", no_argument, &(o->window), 1}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'v'}, + {NULL, 0, NULL, 0} + }; /* parse the options provided by user */ - while ( (c = getopt_long_only(argc, argv, "d:a:t:g:q:hv", longopts, NULL)) != -1) + while ((c = getopt_long_only(argc, argv, "d:a:t:g:q:hv", longopts, NULL)) != -1) { switch (c) { - case 0: /* Flags were set.... do nothing. */ - break; - case 'd': - o->delay = atoi(optarg); - break; - case 'a': - o->app = evas_stringshare_add(optarg); - break; - case 't': - o->use_thumb = 1; - o->thumb.filename = evas_stringshare_add(optarg); - break; - case 'g': - o->use_thumb = 1; - if (strstr(optarg, "x")) - { - sscanf(optarg, "%ix%i", &tw, &th); - o->thumb.width = tw; - o->thumb.height = th; - } - else - { - ts = atoi(optarg); - if (ts < 1) ts = 1; - else if (ts > 100) ts = 100; - o->thumb.size = ts; - } - break; - case 'q': - o->quality = atoi(optarg); - break; - case 'v': /* Print version and bail */ - _em_print_version(); - break; - case '?': /* ErrMsg is printed, then Fallthrough */ - case 'h': /* Fallthrough */ - default: - _em_print_help(); + case 0: /* Flags were set.... do nothing. */ + break; + case 'd': + o->delay = atoi(optarg); + break; + case 'a': + o->app = evas_stringshare_add(optarg); + break; + case 't': + o->use_thumb = 1; + o->thumb.filename = evas_stringshare_add(optarg); + break; + case 'g': + o->use_thumb = 1; + if (strstr(optarg, "x")) + { + sscanf(optarg, "%ix%i", &tw, &th); + o->thumb.width = tw; + o->thumb.height = th; + } + else + { + ts = atoi(optarg); + if (ts < 1) ts = 1; + else if (ts > 100) ts = 100; + o->thumb.size = ts; + } + break; + case 'q': + o->quality = atoi(optarg); + break; + case 'v': /* Print version and bail */ + _em_print_version(); + break; + case '?': /* ErrMsg is printed, then Fallthrough */ + case 'h': /* Fallthrough */ + default: + _em_print_help(); + break; } } @@ -222,16 +246,15 @@ ); _em_free_options(); - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); } static void _em_print_version(void) { printf("emprint version "VERSION"\n"); - _em_free_options(); - exit( EXIT_SUCCESS ); + exit(EXIT_SUCCESS); } static void @@ -525,7 +548,7 @@ /* no thumbname filename supplied, create one */ ext = ecore_file_strip_ext(opts->filename); snprintf(buf, sizeof(buf), "%s-thumb", ext); - + /* check for extension */ ext = strrchr(opts->filename, '.'); if (ext) @@ -664,7 +687,7 @@ if (ecore_x_window_parent_get(win) == root) break; win = ecore_x_window_parent_get(win); } - + /* get this window's dimensions */ ecore_x_window_geometry_get(win, &x, &y, &w, &h); ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs