+ return ret;
+}
+
+/* normally this is the main() function entry, but if OpenOCD is linked
+ * into application, then this fn will not be invoked, but rather that
+ * application will have it's own implementation of main(). */
+int openocd_main(int argc, char *argv[])
+{
+ int ret;
+
+ /* initialize commandline interface */
+ struct command_context *cmd_ctx;
+
+ cmd_ctx = setup_command_handler(NULL);
+
+ if (util_init(cmd_ctx) != ERROR_OK)
+ return EXIT_FAILURE;
+
+ if (ioutil_init(cmd_ctx) != ERROR_OK)
+ return EXIT_FAILURE;
+
+ LOG_OUTPUT("For bug reports, read\n\t"
+ "http://openocd.sourceforge.net/doc/doxygen/bugs.html"
+ "\n");
+
+ command_context_mode(cmd_ctx, COMMAND_CONFIG);
+ command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
+
+ /* Start the executable meat that can evolve into thread in future. */
+ ret = openocd_thread(argc, argv, cmd_ctx);