On Sat, Aug 15, 2015 at 3:56 AM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Sat, Aug 15, 2015 at 02:01:20AM +0200, Mariusz Szczepańczyk wrote:
> > ---
> >  doc/examples/avio_list_dir.c | 92
> ++++++++++++++++++++++++++++++++++++--------
> >  1 file changed, 76 insertions(+), 16 deletions(-)
> >
> > diff --git a/doc/examples/avio_list_dir.c b/doc/examples/avio_list_dir.c
> > index 4060ba6..50c435c 100644
> > --- a/doc/examples/avio_list_dir.c
> > +++ b/doc/examples/avio_list_dir.c
>
> applied
>
> maybe the example should be renamed though as it does more than list
> directories now
>
> thanks
>
>
like this?


> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Its not that you shouldnt use gotos but rather that you should write
> readable code and code with gotos often but not always is less readable
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
From ef37d8048a739db93df2516b7428ae009c4a6752 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mariusz=20Szczepa=C5=84czyk?= <mszczepanc...@gmail.com>
Date: Sat, 15 Aug 2015 17:59:17 +0200
Subject: [PATCH] doc/examples: rename avio_list_dir -> avio_dir_cmd

---
 .gitignore                   |   2 +-
 configure                    |   4 +-
 doc/Makefile                 |   2 +-
 doc/examples/Makefile        |   2 +-
 doc/examples/avio_dir_cmd.c  | 180 +++++++++++++++++++++++++++++++++++++++++++
 doc/examples/avio_list_dir.c | 180 -------------------------------------------
 6 files changed, 185 insertions(+), 185 deletions(-)
 create mode 100644 doc/examples/avio_dir_cmd.c
 delete mode 100644 doc/examples/avio_list_dir.c

diff --git a/.gitignore b/.gitignore
index 6a3664a..cb9cbec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,7 +37,7 @@
 /doc/avoptions_codec.texi
 /doc/avoptions_format.texi
 /doc/doxy/html/
-/doc/examples/avio_list_dir
+/doc/examples/avio_dir_cmd
 /doc/examples/avio_reading
 /doc/examples/decoding_encoding
 /doc/examples/demuxing_decoding
diff --git a/configure b/configure
index 3ad72d8..381b09e 100755
--- a/configure
+++ b/configure
@@ -1343,7 +1343,7 @@ COMPONENT_LIST="
 
 EXAMPLE_LIST="
     avio_reading_example
-    avio_list_dir_example
+    avio_dir_cmd_example
     decoding_encoding_example
     demuxing_decoding_example
     extract_mvs_example
@@ -2803,7 +2803,7 @@ zoompan_filter_deps="swscale"
 
 # examples
 avio_reading="avformat avcodec avutil"
-avio_list_dir="avformat avutil"
+avio_dir_cmd="avformat avutil"
 avcodec_example_deps="avcodec avutil"
 decoding_encoding_example_deps="avcodec avformat avutil"
 demuxing_decoding_example_deps="avcodec avformat avutil"
diff --git a/doc/Makefile b/doc/Makefile
index 4573531..3e67c2a 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -36,7 +36,7 @@ DOCS-$(CONFIG_MANPAGES)  += $(MANPAGES)
 DOCS-$(CONFIG_TXTPAGES)  += $(TXTPAGES)
 DOCS = $(DOCS-yes)
 
-DOC_EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE)     += avio_list_dir
+DOC_EXAMPLES-$(CONFIG_AVIO_DIR_CMD_EXAMPLE)      += avio_dir_cmd
 DOC_EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE)      += avio_reading
 DOC_EXAMPLES-$(CONFIG_AVCODEC_EXAMPLE)           += avcodec
 DOC_EXAMPLES-$(CONFIG_DECODING_ENCODING_EXAMPLE) += decoding_encoding
diff --git a/doc/examples/Makefile b/doc/examples/Makefile
index 8c9501b..af38159 100644
--- a/doc/examples/Makefile
+++ b/doc/examples/Makefile
@@ -11,7 +11,7 @@ CFLAGS += -Wall -g
 CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
 LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
 
-EXAMPLES=       avio_list_dir                      \
+EXAMPLES=       avio_dir_cmd                       \
                 avio_reading                       \
                 decoding_encoding                  \
                 demuxing_decoding                  \
diff --git a/doc/examples/avio_dir_cmd.c b/doc/examples/avio_dir_cmd.c
new file mode 100644
index 0000000..50c435c
--- /dev/null
+++ b/doc/examples/avio_dir_cmd.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2014 Lukasz Marek
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavformat/avio.h>
+
+static const char *type_string(int type)
+{
+    switch (type) {
+    case AVIO_ENTRY_DIRECTORY:
+        return "<DIR>";
+    case AVIO_ENTRY_FILE:
+        return "<FILE>";
+    case AVIO_ENTRY_BLOCK_DEVICE:
+        return "<BLOCK DEVICE>";
+    case AVIO_ENTRY_CHARACTER_DEVICE:
+        return "<CHARACTER DEVICE>";
+    case AVIO_ENTRY_NAMED_PIPE:
+        return "<PIPE>";
+    case AVIO_ENTRY_SYMBOLIC_LINK:
+        return "<LINK>";
+    case AVIO_ENTRY_SOCKET:
+        return "<SOCKET>";
+    case AVIO_ENTRY_SERVER:
+        return "<SERVER>";
+    case AVIO_ENTRY_SHARE:
+        return "<SHARE>";
+    case AVIO_ENTRY_WORKGROUP:
+        return "<WORKGROUP>";
+    case AVIO_ENTRY_UNKNOWN:
+    default:
+        break;
+    }
+    return "<UNKNOWN>";
+}
+
+static int list_op(const char *input_dir)
+{
+    AVIODirEntry *entry = NULL;
+    AVIODirContext *ctx = NULL;
+    int cnt, ret;
+    char filemode[4], uid_and_gid[20];
+
+    if ((ret = avio_open_dir(&ctx, input_dir, NULL)) < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Cannot open directory: %s.\n", av_err2str(ret));
+        goto fail;
+    }
+
+    cnt = 0;
+    for (;;) {
+        if ((ret = avio_read_dir(ctx, &entry)) < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Cannot list directory: %s.\n", av_err2str(ret));
+            goto fail;
+        }
+        if (!entry)
+            break;
+        if (entry->filemode == -1) {
+            snprintf(filemode, 4, "???");
+        } else {
+            snprintf(filemode, 4, "%3"PRIo64, entry->filemode);
+        }
+        snprintf(uid_and_gid, 20, "%"PRId64"(%"PRId64")", entry->user_id, entry->group_id);
+        if (cnt == 0)
+            av_log(NULL, AV_LOG_INFO, "%-9s %12s %30s %10s %s %16s %16s %16s\n",
+                   "TYPE", "SIZE", "NAME", "UID(GID)", "UGO", "MODIFIED",
+                   "ACCESSED", "STATUS_CHANGED");
+        av_log(NULL, AV_LOG_INFO, "%-9s %12"PRId64" %30s %10s %s %16"PRId64" %16"PRId64" %16"PRId64"\n",
+               type_string(entry->type),
+               entry->size,
+               entry->name,
+               uid_and_gid,
+               filemode,
+               entry->modification_timestamp,
+               entry->access_timestamp,
+               entry->status_change_timestamp);
+        avio_free_directory_entry(&entry);
+        cnt++;
+    };
+
+  fail:
+    avio_close_dir(&ctx);
+    return ret;
+}
+
+static int del_op(const char *url)
+{
+    int ret = avpriv_io_delete(url);
+    if (ret < 0)
+        av_log(NULL, AV_LOG_ERROR, "Cannot delete '%s': %s.\n", url, av_err2str(ret));
+    return ret;
+}
+
+static int move_op(const char *src, const char *dst)
+{
+    int ret = avpriv_io_move(src, dst);
+    if (ret < 0)
+        av_log(NULL, AV_LOG_ERROR, "Cannot move '%s' into '%s': %s.\n", src, dst, av_err2str(ret));
+    return ret;
+}
+
+
+static void usage(const char *program_name)
+{
+    fprintf(stderr, "usage: %s OPERATION entry1 [entry2]\n"
+            "API example program to show how to manipulate resources "
+            "accessed through AVIOContext.\n"
+            "OPERATIONS:\n"
+            "list      list content of the directory\n"
+            "move      rename content in directory\n"
+            "del       delete content in directory\n",
+            program_name);
+}
+
+int main(int argc, char *argv[])
+{
+    const char *op = NULL;
+    int ret;
+
+    av_log_set_level(AV_LOG_DEBUG);
+
+    if (argc < 2) {
+        usage(argv[0]);
+        return 1;
+    }
+
+    /* register codecs and formats and other lavf/lavc components*/
+    av_register_all();
+    avformat_network_init();
+
+    op = argv[1];
+    if (strcmp(op, "list") == 0) {
+        if (argc < 3) {
+            av_log(NULL, AV_LOG_INFO, "Missing argument for list operation.\n");
+            ret = AVERROR(EINVAL);
+        } else {
+            ret = list_op(argv[2]);
+        }
+    } else if (strcmp(op, "del") == 0) {
+        if (argc < 3) {
+            av_log(NULL, AV_LOG_INFO, "Missing argument for del operation.\n");
+            ret = AVERROR(EINVAL);
+        } else {
+            ret = del_op(argv[2]);
+        }
+    } else if (strcmp(op, "move") == 0) {
+        if (argc < 4) {
+            av_log(NULL, AV_LOG_INFO, "Missing argument for move operation.\n");
+            ret = AVERROR(EINVAL);
+        } else {
+            ret = move_op(argv[2], argv[3]);
+        }
+    } else {
+        av_log(NULL, AV_LOG_INFO, "Invalid operation %s\n", op);
+        ret = AVERROR(EINVAL);
+    }
+
+    avformat_network_deinit();
+
+    return ret < 0 ? 1 : 0;
+}
diff --git a/doc/examples/avio_list_dir.c b/doc/examples/avio_list_dir.c
deleted file mode 100644
index 50c435c..0000000
--- a/doc/examples/avio_list_dir.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (c) 2014 Lukasz Marek
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
-#include <libavformat/avio.h>
-
-static const char *type_string(int type)
-{
-    switch (type) {
-    case AVIO_ENTRY_DIRECTORY:
-        return "<DIR>";
-    case AVIO_ENTRY_FILE:
-        return "<FILE>";
-    case AVIO_ENTRY_BLOCK_DEVICE:
-        return "<BLOCK DEVICE>";
-    case AVIO_ENTRY_CHARACTER_DEVICE:
-        return "<CHARACTER DEVICE>";
-    case AVIO_ENTRY_NAMED_PIPE:
-        return "<PIPE>";
-    case AVIO_ENTRY_SYMBOLIC_LINK:
-        return "<LINK>";
-    case AVIO_ENTRY_SOCKET:
-        return "<SOCKET>";
-    case AVIO_ENTRY_SERVER:
-        return "<SERVER>";
-    case AVIO_ENTRY_SHARE:
-        return "<SHARE>";
-    case AVIO_ENTRY_WORKGROUP:
-        return "<WORKGROUP>";
-    case AVIO_ENTRY_UNKNOWN:
-    default:
-        break;
-    }
-    return "<UNKNOWN>";
-}
-
-static int list_op(const char *input_dir)
-{
-    AVIODirEntry *entry = NULL;
-    AVIODirContext *ctx = NULL;
-    int cnt, ret;
-    char filemode[4], uid_and_gid[20];
-
-    if ((ret = avio_open_dir(&ctx, input_dir, NULL)) < 0) {
-        av_log(NULL, AV_LOG_ERROR, "Cannot open directory: %s.\n", av_err2str(ret));
-        goto fail;
-    }
-
-    cnt = 0;
-    for (;;) {
-        if ((ret = avio_read_dir(ctx, &entry)) < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Cannot list directory: %s.\n", av_err2str(ret));
-            goto fail;
-        }
-        if (!entry)
-            break;
-        if (entry->filemode == -1) {
-            snprintf(filemode, 4, "???");
-        } else {
-            snprintf(filemode, 4, "%3"PRIo64, entry->filemode);
-        }
-        snprintf(uid_and_gid, 20, "%"PRId64"(%"PRId64")", entry->user_id, entry->group_id);
-        if (cnt == 0)
-            av_log(NULL, AV_LOG_INFO, "%-9s %12s %30s %10s %s %16s %16s %16s\n",
-                   "TYPE", "SIZE", "NAME", "UID(GID)", "UGO", "MODIFIED",
-                   "ACCESSED", "STATUS_CHANGED");
-        av_log(NULL, AV_LOG_INFO, "%-9s %12"PRId64" %30s %10s %s %16"PRId64" %16"PRId64" %16"PRId64"\n",
-               type_string(entry->type),
-               entry->size,
-               entry->name,
-               uid_and_gid,
-               filemode,
-               entry->modification_timestamp,
-               entry->access_timestamp,
-               entry->status_change_timestamp);
-        avio_free_directory_entry(&entry);
-        cnt++;
-    };
-
-  fail:
-    avio_close_dir(&ctx);
-    return ret;
-}
-
-static int del_op(const char *url)
-{
-    int ret = avpriv_io_delete(url);
-    if (ret < 0)
-        av_log(NULL, AV_LOG_ERROR, "Cannot delete '%s': %s.\n", url, av_err2str(ret));
-    return ret;
-}
-
-static int move_op(const char *src, const char *dst)
-{
-    int ret = avpriv_io_move(src, dst);
-    if (ret < 0)
-        av_log(NULL, AV_LOG_ERROR, "Cannot move '%s' into '%s': %s.\n", src, dst, av_err2str(ret));
-    return ret;
-}
-
-
-static void usage(const char *program_name)
-{
-    fprintf(stderr, "usage: %s OPERATION entry1 [entry2]\n"
-            "API example program to show how to manipulate resources "
-            "accessed through AVIOContext.\n"
-            "OPERATIONS:\n"
-            "list      list content of the directory\n"
-            "move      rename content in directory\n"
-            "del       delete content in directory\n",
-            program_name);
-}
-
-int main(int argc, char *argv[])
-{
-    const char *op = NULL;
-    int ret;
-
-    av_log_set_level(AV_LOG_DEBUG);
-
-    if (argc < 2) {
-        usage(argv[0]);
-        return 1;
-    }
-
-    /* register codecs and formats and other lavf/lavc components*/
-    av_register_all();
-    avformat_network_init();
-
-    op = argv[1];
-    if (strcmp(op, "list") == 0) {
-        if (argc < 3) {
-            av_log(NULL, AV_LOG_INFO, "Missing argument for list operation.\n");
-            ret = AVERROR(EINVAL);
-        } else {
-            ret = list_op(argv[2]);
-        }
-    } else if (strcmp(op, "del") == 0) {
-        if (argc < 3) {
-            av_log(NULL, AV_LOG_INFO, "Missing argument for del operation.\n");
-            ret = AVERROR(EINVAL);
-        } else {
-            ret = del_op(argv[2]);
-        }
-    } else if (strcmp(op, "move") == 0) {
-        if (argc < 4) {
-            av_log(NULL, AV_LOG_INFO, "Missing argument for move operation.\n");
-            ret = AVERROR(EINVAL);
-        } else {
-            ret = move_op(argv[2], argv[3]);
-        }
-    } else {
-        av_log(NULL, AV_LOG_INFO, "Invalid operation %s\n", op);
-        ret = AVERROR(EINVAL);
-    }
-
-    avformat_network_deinit();
-
-    return ret < 0 ? 1 : 0;
-}
-- 
2.4.6

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to