--- /dev/null
+#!/bin/bash
+#
+# Translate really simple html to googlecode.com wiki.
+#
+# Usage: cat input.html | html2wiki.sh > outputwiki.txt
+#
+# Most of this script is simple sed substitutions with an awk script to handle
+# hierarchical lists.
+
+# Awk program to escape all instances of * outside of <listing></listing>
+awk '
+BEGIN { in_listing = 0; }
+/<[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 1; }
+/<\/[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 0; }
+/.*/ {
+ if (in_listing) {
+ print $0;
+ } else {
+ print gensub("*", "`*`", "g", $0)
+ }
+}' | \
+# Awk program to convert hierachical unordered and ordered lists into
+# googlecode wiki list markup. This is limited to converting very simple
+# html lists in the form:
+#
+# <ul>
+# <li>item 1</li>
+# ...
+# <li>item N</li>
+# </ul>
+#
+# This script also removes leading spaces from all lines outside of <listing>
+# sections.
+awk '
+BEGIN {
+ list_type_none = 0;
+ list_type_ordered = 1;
+ list_type_unordered = 2;
+ # Number of nested lists.
+ list_depth = 0;
+ # Number of items in the list.
+ list_items[list_depth] = 0;
+ # Type of list.
+ list_type[list_depth] = list_type_none;
+ # Do nott strip whitespace from listing sections.
+ in_listing = 0;
+}
+
+# Generate a string of indent spaces.
+function list_indent(indent) {
+ format = sprintf("%%%ds", indent);
+ return sprintf(format, "");
+}
+
+/<[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 1; }
+/<\/[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 0; }
+
+# Process all lines non-blank lines.
+/^.*$/ {
+ # Remove leading white space.
+ if (!in_listing) {
+ output_string = gensub(/^ */, "", 1, $0);
+ } else {
+ output_string = $0;
+ }
+ search_string = output_string
+
+ # Replace list tags with googlecode wiki markup.
+ while (match(search_string, /<[^>]*>/, matches)) {
+ tag = matches[0];
+ search_string = substr(search_string,
+ matches[0, "start"] + matches[0, "length"]);
+ if (match(tag, /^<[Uu][Ll]>$/)) {
+ list_depth++;
+ list_type[list_depth] = list_type_unordered;
+ list_items[list_depth] = 0;
+ output_string = gensub(tag, "", 1, output_string);
+ } else if (match(tag, /^[Oo][Ll]>$/)) {
+ list_depth++;
+ list_type[list_depth] = list_type_ordered;
+ list_items[list_depth] = 0;
+ output_string = gensub(tag, "", 1, output_string);
+ } else if (match(tag, /^<\/[Ll][Ii]>$/)) {
+ output_string = gensub(tag, "", 1, output_string);
+ } else if (list_depth) {
+ if (match(tag, /^<[Ll][Ii]>$/)) {
+ if (list_type[list_depth] == list_type_unordered) {
+ output_string = gensub(tag, list_indent(list_depth) "* ", 1,
+ output_string);
+ } else if (list_type[list_depth] == list_type_ordered) {
+ output_string = gensub(tag, list_indent(list_depth) "# ", 1,
+ output_string);
+ }
+ } else if (match(tag, /^<\/[Uu][Ll]>$/) ||
+ match(tag, /^<\/[Ou][Ll]>$/)) {
+ output_string = gensub(tag, "", 1, output_string);
+ list_depth --;
+ }
+ }
+ }
+ # If a list is being parsed then filter blank lines.
+ if (list_depth == 0 || length(output_string)) {
+ print output_string
+ }
+}
+' | \
+# This sed program translates really simple html into wiki suitable for
+# googlecode.com.
+#
+# Supported tags:
+# <p>
+# <br>
+# <h1>
+# <h2>
+# <h3>
+# <h4>
+# <h5>
+# <b>
+# <i>
+# <a href="#.*">.*</a>
+# <a href=".*">.*</a>
+# <a name=".*'>.*</a>
+#
+# Supported entities:
+# >
+# <
+#
+# Limitations:
+# * Anchors must be on a single line and must contain one of either the name or
+# href attributes.
+# * All external links are relative to
+# http://cmockery.googlecode.com/svn/trunk/doc/
+sed -r '
+s@<[Pp]>@\n@g;
+s@<[[Bb][Rr]]>@\n@g;
+s@</?[Hh]1>@=@g;
+s@</?[Hh]2>@==@g;
+s@</?[Hh]3>@===@g;
+s@</?[Hh]4>@====@g;
+s@</?[Hh]5>@====@g;
+s@</?[Bb]>@*@g;
+s@</?[Ii]>@_@g;
+s@<[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>@{{{@g;
+s@</[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>@}}}@g;
+s@<[Aa].*?href="#(.*)?">(.*)?</[Aa]>@[#\1 \2]@g;
+s@<[Aa].*?href="(.*)?">(.*)?</[Aa]>@[http://cmockery.googlecode.com/svn/trunk/doc/\1 \2]@g;
+s@<[Aa].*?name="(.*)?">@@g;
+s@</[Aa]>@@g;
+s@<.*?>@@g;
+s@<@<@g;
+s@>@>@g;'
the test succeeded.</p>
<h4>Using run_tests()</h4>
-<listing>
<a href="../src/example/run_tests.c">run_tests.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
<li><a href="#TestState">Mismatched setup and tear down functions</a></li>
<li><a href="#MockFunctionsReturnValues">Missing mock return values</a></li>
<li><a href="#MockFunctionsReturnValues">Unused mock return values</a></li>
- <li><a href="#MockFunctionsCheckingParameters">Missing expected parameter
- values</a></li>
- <li><a href="#MockFunctionsCheckingParameters">Unused expected parameter
- values</a></li>
+ <li><a href="#MockFunctionsCheckingParameters">Missing expected parameter values</a></li>
+ <li><a href="#MockFunctionsCheckingParameters">Unused expected parameter values</a></li>
</ul>
</p>
<b>expect_assert_failure()</b> a test failure is signalled.</p>
<h4>Using mock_assert()</h4>
-<listing>
<a href="../src/example/assert_module.c">assert_module.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <assert.h>
// If unit testing is enabled override assert with mock_assert().
*value --;
}
}
-
+</listing>
<a href="../src/example/assert_module_test.c">assert_module_test.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
debugging of failing test cases.</p>
<h4>Using assert_{type}_equal() macros</h4>
-<listing>
<a href="../src/example/assert_macro.c">assert_macro.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <string.h>
static const char* status_code_strings[] = {
}
return ~0U;
}
-
+</listing>
<a href="../src/example/assert_macro_test.c">assert_macro_test.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
the test application to exit prematurely.</p>
<h4>Using Cmockery's Allocators</h4>
-<listing>
<a href="../src/example/allocate_module.c">allocate_module.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <malloc.h>
#if UNIT_TESTING
memory[-1] = '!';
free(memory);
}
-
-
+</listing>
<a href="../src/example/allocate_module_test.c">allocate_module_test.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
multiple calls to a mock function.</p>
<h4>Using will_return()</h4>
-<listing>
<a name="../src/example/database.h" href="database.h">database.h</a>
--------------------------------------------------------------------------------
+<listing>
typedef struct DatabaseConnection DatabaseConnection;
/* Function that takes an SQL query string and sets results to an array of
// Connect to a database.
DatabaseConnection* connect_to_database(const char * const url,
const unsigned int port);
-
-
+</listing>
<a href="../src/example/customer_database.c">customer_database.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stddef.h>
#include <stdio.h>
-#include <a href="#database.h"><database.h></a>
+#include <database.h>
#ifdef _WIN32
#define snprintf _snprintf
#endif // _WIN32
}
return (unsigned int)results[0];
}
-
-
+</listing>
<a href="../src/example/customer_database_test.c">customer_database_test.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmockery.h>
-#include <a href="#database.h"><database.h></a>
+#include <database.h>
extern DatabaseConnection* connect_to_customer_database();
no more parameter values are queued a test failure occurs.</p>
<h4>Using expect_*()</h4>
-<listing>
<a href="../src/example/product_database.c">product_database.c</a>
--------------------------------------------------------------------------------
-#include <a href="#database.h"><database.h></a>
+<listing>
+#include <database.h>
// Connect to the database containing customer information.
DatabaseConnection* connect_to_product_database() {
return connect_to_database("products.abcd.org", 322);
}
-
+</listing>
<a href="../src/example/product_database_test.c">product_database_test.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmockery.h>
-#include <a href="#database.h"><database.h></a>
+#include <database.h>
extern DatabaseConnection* connect_to_product_database();
executed for a test case even when it fails.</p>
<h4>Using unit_test_setup_teardown()</h4>
-<listing>
<a href="../src/example/key_value.c">key_value.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
qsort(key_values, number_of_key_values, sizeof(*key_values),
key_value_compare_keys);
}
-
+</listing>
<a href="../src/example/key_value_test.c">key_value_test.c</a>
--------------------------------------------------------------------------------
+<listing>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
<hr>
<address></address>
-<!-- hhmts start --> Last modified: Mon Jul 6 12:21:30 PDT 2009 <!-- hhmts end -->
+<!-- hhmts start --> Last modified: Mon Jul 20 15:57:27 PDT 2009 <!-- hhmts end -->
</body> </html>