Make it possible to extract example code from separate blocks.
authorThomas Vander Stichele <thomas@apestaart.org>
Wed, 15 Dec 2004 11:29:14 +0000 (11:29 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Wed, 15 Dec 2004 11:29:14 +0000 (11:29 +0000)
Original commit message from CVS:
* docs/manual/dynamic.xml:
* docs/manual/elements-api.xml:
* docs/manual/gnome.xml:
* docs/manual/helloworld2.xml:
* docs/manual/init-api.xml:
* docs/manual/queues.xml:
* docs/manual/threads.xml:
* docs/manual/xml.xml:
* examples/manual/extract.pl:
Make it possible to extract example code from separate blocks.
Should make Ronald happy.

16 files changed:
ChangeLog
docs/manual/advanced-threads.xml
docs/manual/appendix-gnome.xml
docs/manual/appendix-integration.xml
docs/manual/basics-init.xml
docs/manual/dynamic.xml
docs/manual/elements-api.xml
docs/manual/gnome.xml
docs/manual/helloworld2.xml
docs/manual/highlevel-xml.xml
docs/manual/init-api.xml
docs/manual/queues.xml
docs/manual/threads.xml
docs/manual/xml.xml
examples/manual/extract.pl
tests/old/examples/manual/extract.pl

index d0115d5..b111d5d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-12-15  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+       * docs/manual/dynamic.xml:
+       * docs/manual/elements-api.xml:
+       * docs/manual/gnome.xml:
+       * docs/manual/helloworld2.xml:
+       * docs/manual/init-api.xml:
+       * docs/manual/queues.xml:
+       * docs/manual/threads.xml:
+       * docs/manual/xml.xml:
+       * examples/manual/extract.pl:
+         Make it possible to extract example code from separate blocks.
+         Should make Ronald happy.
+
 2004-12-15  Wim Taymans  <wim@fluendo.com>
 
        * gst/schedulers/gstoptimalscheduler.c: (add_to_group),
 2004-11-29  Stefan Kost  <ensonic@users.sf.net>
 
        * docs/manual/programs.xml:
-      Added a first batch of gst-launch examples, as provided by Ronald
-      and others from the devel-mlist
+         Added a first batch of gst-launch examples, as provided by Ronald
+         and others from the devel-mlist
 
 2004-11-28  Benjamin Otte  <otte@gnome.org>
 
        * testsuite/schedulers/.cvsignore:
        * testsuite/schedulers/Makefile.am:
        * testsuite/schedulers/queue_link.c: (main):
-       Added testcase for schduler segfault.
+       Added testcase for scheduler segfault.
        Fix scheduler segfault when removing a decoupled
        entry point as the last element from a group.
 
        * docs/gst/tmpl/gstutils.sgml:
        * docs/random/ensonic/interfaces.txt:
        * gst/gstinfo.h:
-      added some more docs, removed two obsolete defines
+         added some more docs, removed two obsolete defines
 
 2004-11-02  Kjartan Maraas <as at gnome.org>
 
 
        * gst/schedulers/gstoptimalscheduler.c: (add_to_group),
        (gst_opt_scheduler_iterate):
-       Aplied patch #154061. Running a pipeline in which an element 
+       Applied patch #154061. Running a pipeline in which an element 
        calls GST_ELEMENT_ERROR in the chain function, the opt 
        scheduler doesn't unref the chain so it never gets freed.
 
 2004-10-22  Stefan Kost  <ensonic@users.sf.net>
 
        * docs/pwg/building-boiler.xml:
-      exchanged GTK_ macros with G_TYPE macros (as pointed out by mathrick)
+         exchanged GTK_ macros with G_TYPE macros (as pointed out by mathrick)
 
 2004-10-19  Wim Taymans  <wim at fluendo dot com>
 
index 05ea3cd..0f19d74 100644 (file)
@@ -82,8 +82,9 @@
   
     <para>
       <programlisting>
-/* example-begin threads.c */
-#include &lt;gst/gst.h&gt;
+<!-- example-begin threads.c a -->
+<![CDATA[
+#include <gst/gst.h>
 
 /* we set this to TRUE right before gst_main (), but there could still
    be a race condition between setting it and entering the function */
@@ -161,7 +162,8 @@ main (int argc, char *argv[])
 
   exit (0);
 }
-/* example-end threads.c */
+]]>
+<!-- example-end threads.c a -->
       </programlisting>
     </para>
   </sect1>
index b2445cc..44462b3 100644 (file)
     </para>  
 
     <programlisting>
-/* example-begin gnome.c */
-#include &lt;gnome.h&gt;
-#include &lt;gst/gst.h&gt;
+<!-- example-begin gnome.c a -->
+<![CDATA[
+#include <gnome.h>
+#include <gst/gst.h>
 
 int
 main (int argc, char **argv)
@@ -78,7 +79,8 @@ main (int argc, char **argv)
 
   return 0;
 }
-/* example-end gnome.c */
+]]>
+<!-- example-end gnome.c a -->
     </programlisting>
     <para>
       If you try out this program, you will see that when called with
index b2445cc..44462b3 100644 (file)
     </para>  
 
     <programlisting>
-/* example-begin gnome.c */
-#include &lt;gnome.h&gt;
-#include &lt;gst/gst.h&gt;
+<!-- example-begin gnome.c a -->
+<![CDATA[
+#include <gnome.h>
+#include <gst/gst.h>
 
 int
 main (int argc, char **argv)
@@ -78,7 +79,8 @@ main (int argc, char **argv)
 
   return 0;
 }
-/* example-end gnome.c */
+]]>
+<!-- example-end gnome.c a -->
     </programlisting>
     <para>
       If you try out this program, you will see that when called with
index 054b7b5..d47d1d1 100644 (file)
@@ -19,9 +19,8 @@
   </para>
 
   <programlisting>
+<!-- example-begin init.c a -->
 <![CDATA[
-/* example-begin init.c */
-
 #include <gst/gst.h>
 
 int
@@ -37,8 +36,8 @@ main (int argc, char *argv[])
 
   return 0;
 }
-/* example-end init.c */
 ]]>
+<!-- example-end init.c a -->
   </programlisting>
   <para>
     Use the <symbol>GST_VERSION_MAJOR</symbol>,
@@ -60,9 +59,9 @@ You can also use a popt table to initialize your own parameters as shown in the
 next example:
     </para>
     <programlisting>
-/* example-begin popt.c */
-
-#include &lt;gst/gst.h&gt;
+<!-- example-begin popt.c a -->
+<![CDATA[
+#include <gst/gst.h>
 
 int
 main(int argc, char *argv[])
@@ -83,7 +82,9 @@ main(int argc, char *argv[])
 
   return 0;
 }
-/* example-end popt.c */
+]]>
+<!-- example-end popt.c a -->
+
     </programlisting>
     <para>
       As shown in this fragment, you can use a <ulink
index 50731db..bf558b5 100644 (file)
     We'll start with a simple main function:
   </para>
   <programlisting>
-
-/* example-begin dynamic.c */
-#include &lt;string.h&gt;
-#include &lt;gst/gst.h&gt;
+<!-- example-begin dynamic.c a -->
+<![CDATA[
+#include <string.h>
+#include <gst/gst.h>
 
 void 
 eof (GstElement *src) 
@@ -164,7 +164,8 @@ main (int argc, char *argv[])
 
   return 0;
 }
-/* example-end dynamic.c */
+]]>
+<!-- example-end dynamic.c a -->
   </programlisting>
   <para>
     We create two elements: a file source and an MPEG demuxer. 
index c9c80fe..236e6d8 100644 (file)
@@ -31,8 +31,8 @@ The following example &EXAFOOT; shows how to create an element named
 After checking, it unrefs the element.
     </para>
     <programlisting>
+<!-- example-begin elementmake.c a -->
 <![CDATA[
-/* example-begin elementmake.c */
 
 #include <gst/gst.h>
 
@@ -44,7 +44,11 @@ main (int argc, char *argv[])
   gst_init (&argc, &argv);
 
   element = gst_element_factory_make ("fakesrc", "source");
+]]>
+<!-- example-end elementmake.c a -->
 
+<!-- example-begin elementmake.c b -->
+<![CDATA[
   if (!element) {
     g_error ("Could not create an element from 'fakesrc' factory.\n");
   }
@@ -53,9 +57,8 @@ main (int argc, char *argv[])
 
   return 0;
 }
-
-/* example-end elementmake.c */
 ]]>
+<!-- example-end elementmake.c b -->
     </programlisting>
     <para> 
 <function>gst_element_factory_make</function> is actually a shorthand
@@ -121,9 +124,8 @@ will use the element factory to create an element with the given name.
       <classname>GObject</classname> property mechanism as shown below.
     </para> 
     <programlisting>
+<!-- example-begin elementget.c a -->
 <![CDATA[
-/* example-begin elementget.c */
-
 #include <gst/gst.h>
 
 int
@@ -143,9 +145,8 @@ main (int argc, char *argv[])
 
   return 0;
 }
-
-/* example-end elementget.c */
 ]]>
+<!-- example-end elementget.c a -->
     </programlisting>
     <para> 
       Most plugins provide additional properties to provide more information
index b2445cc..44462b3 100644 (file)
     </para>  
 
     <programlisting>
-/* example-begin gnome.c */
-#include &lt;gnome.h&gt;
-#include &lt;gst/gst.h&gt;
+<!-- example-begin gnome.c a -->
+<![CDATA[
+#include <gnome.h>
+#include <gst/gst.h>
 
 int
 main (int argc, char **argv)
@@ -78,7 +79,8 @@ main (int argc, char **argv)
 
   return 0;
 }
-/* example-end gnome.c */
+]]>
+<!-- example-end gnome.c a -->
     </programlisting>
     <para>
       If you try out this program, you will see that when called with
index 6f76885..7d29660 100644 (file)
@@ -20,8 +20,9 @@
     </para>
 
     <programlisting>
-/* example-begin helloworld2.c */
-#include &lt;gst/gst.h&gt;
+<!-- example-begin helloworld2.c a -->
+<![CDATA[
+#include <gst/gst.h>
 
 static void    gst_play_have_type      (GstElement *typefind, GstCaps *caps, GstElement *pipeline);
 static void    gst_play_cache_empty    (GstElement *element, GstElement *pipeline);
@@ -156,7 +157,8 @@ main (int argc, char *argv[])
 
   exit(0);
 }
-/* example-end helloworld2.c */
+]]>
+<!-- example-end helloworld2.c a -->
     </programlisting>
     <para>
       We start by constructing a 'filesrc' element and an 'autobin' element that
index cd01041..e3e01bf 100644 (file)
     </para>
 
     <programlisting>
-/* example-begin xml-mp3.c */
-#include &lt;stdlib.h&gt;
-#include &lt;gst/gst.h&gt;
+
+<!-- example-begin xml-mp3.c a -->
+<![CDATA[
+#include <stdlib.h>
+#include <gst/gst.h>
 
 gboolean playing;
 
@@ -88,7 +90,8 @@ main (int argc, char *argv[])
 
   exit (0);
 }
-/* example-end xml-mp3.c */
+]]>
+<!-- example-end xml-mp3.c a -->
     </programlisting>
     <para>
       The most important line is:
index 054b7b5..d47d1d1 100644 (file)
@@ -19,9 +19,8 @@
   </para>
 
   <programlisting>
+<!-- example-begin init.c a -->
 <![CDATA[
-/* example-begin init.c */
-
 #include <gst/gst.h>
 
 int
@@ -37,8 +36,8 @@ main (int argc, char *argv[])
 
   return 0;
 }
-/* example-end init.c */
 ]]>
+<!-- example-end init.c a -->
   </programlisting>
   <para>
     Use the <symbol>GST_VERSION_MAJOR</symbol>,
@@ -60,9 +59,9 @@ You can also use a popt table to initialize your own parameters as shown in the
 next example:
     </para>
     <programlisting>
-/* example-begin popt.c */
-
-#include &lt;gst/gst.h&gt;
+<!-- example-begin popt.c a -->
+<![CDATA[
+#include <gst/gst.h>
 
 int
 main(int argc, char *argv[])
@@ -83,7 +82,9 @@ main(int argc, char *argv[])
 
   return 0;
 }
-/* example-end popt.c */
+]]>
+<!-- example-end popt.c a -->
+
     </programlisting>
     <para>
       As shown in this fragment, you can use a <ulink
index d7f96c0..380b30d 100644 (file)
   </para>
 
   <programlisting>
-/* example-begin queue.c */
-#include &lt;stdlib.h&gt;
-#include &lt;gst/gst.h&gt;
+<!-- example-begin queue.c a -->
+<![CDATA[
+#include <stdlib.h>
+#include <gst/gst.h>
 
 gboolean playing;
 
@@ -121,9 +122,7 @@ main (int argc, char *argv[])
 
   return 0;
 }
-/* example-end queue.c */
+]]>
+<!-- example-end queue.c a -->
   </programlisting>
-
-
-
 </chapter>
index 05ea3cd..0f19d74 100644 (file)
@@ -82,8 +82,9 @@
   
     <para>
       <programlisting>
-/* example-begin threads.c */
-#include &lt;gst/gst.h&gt;
+<!-- example-begin threads.c a -->
+<![CDATA[
+#include <gst/gst.h>
 
 /* we set this to TRUE right before gst_main (), but there could still
    be a race condition between setting it and entering the function */
@@ -161,7 +162,8 @@ main (int argc, char *argv[])
 
   exit (0);
 }
-/* example-end threads.c */
+]]>
+<!-- example-end threads.c a -->
       </programlisting>
     </para>
   </sect1>
index cd01041..e3e01bf 100644 (file)
     </para>
 
     <programlisting>
-/* example-begin xml-mp3.c */
-#include &lt;stdlib.h&gt;
-#include &lt;gst/gst.h&gt;
+
+<!-- example-begin xml-mp3.c a -->
+<![CDATA[
+#include <stdlib.h>
+#include <gst/gst.h>
 
 gboolean playing;
 
@@ -88,7 +90,8 @@ main (int argc, char *argv[])
 
   exit (0);
 }
-/* example-end xml-mp3.c */
+]]>
+<!-- example-end xml-mp3.c a -->
     </programlisting>
     <para>
       The most important line is:
index 578357d..3a0a9af 100755 (executable)
@@ -7,6 +7,10 @@
 # main
 
 # decodes xml by translating &amp; &lt; &gt; back to what they should be
+# and also ignore
+# <![CDATA[
+# and
+# ]]>
 sub
 xml_decode ($)
 {
@@ -16,6 +20,10 @@ xml_decode ($)
   $input =~ s/&lt;/</g;
   $input =~ s/&gt;/>/g;
 
+  if ($input =~ /<!\[CDATA\[/) { $input = ""; }
+  if ($input =~ /]]>/) { $input = ""; }
+
+  #print "Returning line $input";
   return $input;
 }
 
@@ -23,6 +31,7 @@ xml_decode ($)
 my $output = shift @ARGV;
 
 $found = 0;
+%blocks = ();
 
 foreach $file (@ARGV)
 {
@@ -30,31 +39,40 @@ foreach $file (@ARGV)
 
   while ($line = <FILE>)
   {
-    if ($line =~ /\/\* example-begin $output \*\//)
+    if ($line =~ /<!-- example-begin $output (.*) -->/)
     {
-      print "Extracting $output from $file\n";
       $found = 1;
-      open OUTPUT, ">$output";
-      print OUTPUT xml_decode ($line); 
-      my $example = 1;
-      while (($line = <FILE>) && $example)
+      $block_id = $1;
+      $block = "\n/*** block $block_id from $file ***/\n";
+
+      print "Extracting $output block $block_id from $file\n";
+
+      while ($line = <FILE>)
       {
-        if ($line =~ /\/\* example-end/)
-        {
-          print OUTPUT xml_decode ($line);
-          close OUTPUT;
-          $example = 0;
-        }
-        else
+        if ($line =~ /<!-- example-end $output (.*) -->/)
         {
-          print OUTPUT xml_decode ($line);
+          last;
         }
+        $block .= xml_decode ($line);
       }
+      $blocks{$block_id} = $block;
     }
   }
 }
+
+
 if (!$found)
 {
   print "Could not find $output example !\n";
   exit(1);
 }
+
+# now output all the blocks in the right order
+open OUTPUT, ">$output";
+@block_ids = keys %blocks;
+foreach $block_id (sort @block_ids)
+{
+  print "Writing block with id $block_id\n";
+  print OUTPUT $blocks{$block_id};
+}
+close OUTPUT;
index 578357d..3a0a9af 100755 (executable)
@@ -7,6 +7,10 @@
 # main
 
 # decodes xml by translating &amp; &lt; &gt; back to what they should be
+# and also ignore
+# <![CDATA[
+# and
+# ]]>
 sub
 xml_decode ($)
 {
@@ -16,6 +20,10 @@ xml_decode ($)
   $input =~ s/&lt;/</g;
   $input =~ s/&gt;/>/g;
 
+  if ($input =~ /<!\[CDATA\[/) { $input = ""; }
+  if ($input =~ /]]>/) { $input = ""; }
+
+  #print "Returning line $input";
   return $input;
 }
 
@@ -23,6 +31,7 @@ xml_decode ($)
 my $output = shift @ARGV;
 
 $found = 0;
+%blocks = ();
 
 foreach $file (@ARGV)
 {
@@ -30,31 +39,40 @@ foreach $file (@ARGV)
 
   while ($line = <FILE>)
   {
-    if ($line =~ /\/\* example-begin $output \*\//)
+    if ($line =~ /<!-- example-begin $output (.*) -->/)
     {
-      print "Extracting $output from $file\n";
       $found = 1;
-      open OUTPUT, ">$output";
-      print OUTPUT xml_decode ($line); 
-      my $example = 1;
-      while (($line = <FILE>) && $example)
+      $block_id = $1;
+      $block = "\n/*** block $block_id from $file ***/\n";
+
+      print "Extracting $output block $block_id from $file\n";
+
+      while ($line = <FILE>)
       {
-        if ($line =~ /\/\* example-end/)
-        {
-          print OUTPUT xml_decode ($line);
-          close OUTPUT;
-          $example = 0;
-        }
-        else
+        if ($line =~ /<!-- example-end $output (.*) -->/)
         {
-          print OUTPUT xml_decode ($line);
+          last;
         }
+        $block .= xml_decode ($line);
       }
+      $blocks{$block_id} = $block;
     }
   }
 }
+
+
 if (!$found)
 {
   print "Could not find $output example !\n";
   exit(1);
 }
+
+# now output all the blocks in the right order
+open OUTPUT, ">$output";
+@block_ids = keys %blocks;
+foreach $block_id (sort @block_ids)
+{
+  print "Writing block with id $block_id\n";
+  print OUTPUT $blocks{$block_id};
+}
+close OUTPUT;