]> git.draconx.ca Git - liblbx.git/commitdiff
lbximg: Use the new lbximg_fopen interface.
authorNick Bowler <nbowler@draconx.ca>
Wed, 10 Feb 2010 04:29:40 +0000 (23:29 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 10 Feb 2010 04:29:40 +0000 (23:29 -0500)
src/lbximg.c

index 1173538856b94ae4781a78aedd86795d18719433..c4075b0d37eb21966ae16913b573a543959d5c63 100644 (file)
@@ -370,9 +370,9 @@ err:
 int main(int argc, char **argv)
 {
        int mode = MODE_NONE, opt, rc = EXIT_FAILURE;
-       struct lbx_pipe_state state = { .f = stdin };
+       struct lbx_pipe_state stdin_handle = { .f = stdin };
        FILE *palf = NULL, *overf = NULL;
-       const char *name = "stdin";
+       const char *file = NULL;
        LBX_IMG *img;
 
        static const char *sopts = "idvf:p:O:V";
@@ -406,13 +406,7 @@ int main(int argc, char **argv)
                        verbose = 1;
                        break;
                case 'f':
-                       name = strrchr(optarg, '/');
-                       name = name ? name+1 : optarg;
-
-                       if (!freopen(optarg, "rb", state.f)) {
-                               errmsg("failed to open %s: %m\n", optarg);
-                               return EXIT_FAILURE;
-                       }
+                       file = optarg;
                        break;
                case 'p':
                        palf = fopen(optarg, "rb");
@@ -449,10 +443,10 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       if (fseek(state.f, 0, SEEK_CUR) == 0)
-               img = lbximg_open(state.f, &lbx_default_fops, NULL);
+       if (file)
+               img = lbximg_fopen(file);
        else
-               img = lbximg_open(&state, &lbx_pipe_fops, NULL);
+               img = lbximg_open(&stdin_handle, &lbx_pipe_fops, NULL);
 
        if (!img) {
                errmsg("failed to open image: %s.\n", lbx_strerror());
@@ -461,10 +455,13 @@ int main(int argc, char **argv)
 
        if (verbose || mode == MODE_IDENT) {
                struct lbx_imginfo info;
-               lbximg_getinfo(img, &info);
 
+               if (!file)
+                       file = "stdin";
+
+               lbximg_getinfo(img, &info);
                printf("%s is %ux%u LBX image, %u frame(s)%s%s\n",
-                      name, info.width, info.height, info.nframes,
+                      file, info.width, info.height, info.nframes,
                       info.palettesz ? ", embedded palette" : "",
                       info.chunk     ? ", chunked" : "",
                       info.looping   ? ", loops" : "");