PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/source/print.c

http://github.com/macmade/BrainDead
C | 167 lines | 111 code | 6 blank | 50 comment | 0 complexity | 5d8ba0a9c622be92eba4f989c2bc641a MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2010, Jean-David Gadina - www.xs-labs.com
  3. * Distributed under the Boost Software License, Version 1.0.
  4. *
  5. * Boost Software License - Version 1.0 - August 17th, 2003
  6. *
  7. * Permission is hereby granted, free of charge, to any person or organization
  8. * obtaining a copy of the software and accompanying documentation covered by
  9. * this license (the "Software") to use, reproduce, display, distribute,
  10. * execute, and transmit the Software, and to prepare derivative works of the
  11. * Software, and to permit third-parties to whom the Software is furnished to
  12. * do so, all subject to the following:
  13. *
  14. * The copyright notices in the Software and this entire statement, including
  15. * the above license grant, this restriction and the following disclaimer,
  16. * must be included in all copies of the Software, in whole or in part, and
  17. * all derivative works of the Software, unless such copies or derivative
  18. * works are solely in the form of machine-executable object code generated by
  19. * a source language processor.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  24. * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  25. * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  26. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. * DEALINGS IN THE SOFTWARE.
  28. ******************************************************************************/
  29. /* $Id$ */
  30. /*!
  31. * @header print.c
  32. * @copyright (c) 2010 - Jean-David Gadina - www.xs-labs.com
  33. * @abstract Print functions
  34. */
  35. #include "braindead.h"
  36. /*!
  37. * @function bd_print_version
  38. * @abstract
  39. * @result void
  40. */
  41. void bd_print_version( void )
  42. {
  43. printf( "Version: %s\n", BD_VERSION );
  44. }
  45. /*!
  46. * @function bd_print_help
  47. * @abstract Prints the program's help dialog
  48. * @param exec The program's executable name
  49. * @result void
  50. */
  51. void bd_print_help( char * exec )
  52. {
  53. printf
  54. (
  55. "\n"
  56. "Usage: %s [OPTIONS] [TARGET]\n"
  57. "--------------------------------------------------------------------------------\n"
  58. "\n"
  59. " - By default, enters the interactive mode and interprets brainfuck code\n"
  60. " from stdin.\n"
  61. " Type \"x\", \"X\", \"q\" or \"Q\" to exit the interactive mode.\n"
  62. "\n"
  63. " - If [TARGET] is specified, interprets it as a brainfuck code file and\n"
  64. " displays the result on the standard output.\n"
  65. "\n"
  66. "Code samples:\n"
  67. "--------------------------------------------------------------------------------\n"
  68. "\n"
  69. " - Here's the brainfuck code to use to print \"Hello World!\":\n"
  70. " ++++++++++\n"
  71. " [>+++>+++++++>++++++++>++++++++++>+++++++++++<<<<<-]\n"
  72. " >>++.>>+.+++++++..>+.<<<<++.>>+++++++.>>.+++.<.--------.<<<+.\n"
  73. "\n"
  74. " - Here's the brainfuck code to use to create a 'cat' like command:\n"
  75. " ,[.,]\n"
  76. "\n"
  77. "Examples:\n"
  78. "--------------------------------------------------------------------------------\n"
  79. "\n"
  80. " - Entering into interactive mode:\n"
  81. " $ braindead\n"
  82. "\n"
  83. " - Running a brainfuck script:\n"
  84. " $ braindead path/to/file\n"
  85. "\n"
  86. " - Running a brainfuck script by reading characters by characters, allocating\n"
  87. " only 2 stack cells at a time, and displaying debug informations:\n"
  88. " $ braindead -drm 1 2 path/to/file\n"
  89. "\n"
  90. " - Running a brainfuck script with input from a file instead of stdin:\n"
  91. " $ braindead path/to/file < path/to/input/file\n"
  92. "\n"
  93. "Available command line arguments:\n"
  94. "--------------------------------------------------------------------------------\n"
  95. "\n"
  96. " -h, boolean, --help\n"
  97. " Displays help about the command\n"
  98. "\n"
  99. " -v, boolean, --version\n"
  100. " Displays the version number\n"
  101. "\n"
  102. " -l, boolean, --license\n"
  103. " Displays the license text\n"
  104. "\n"
  105. " -m, integer, --malloc\n"
  106. " Allocates <X> stack cells at a time (default is 85)\n"
  107. "\n"
  108. " -r, integer, --read\n"
  109. " Read <X> bytes from input file at a time (default is 1024)\n"
  110. "\n"
  111. " -d, boolean, --debug\n"
  112. " Debug mode - Displays every operation\n"
  113. "\n"
  114. " -b, boolean, --enable-breakpoints\n"
  115. " Enables the use of '@' symbols in the brainfuck code for breakpoints\n"
  116. "\n"
  117. " -s, boolean, --enable-stack-debug\n"
  118. " Enables the use of '$' symbols in the brainfuck code for stack debugging\n"
  119. "\n"
  120. " -z, boolean, --enable-stack-reset\n"
  121. " Enables the use of '%%' symbols in the brainfuck code for stack reset\n"
  122. "\n",
  123. exec
  124. );
  125. }
  126. /*!
  127. * @function bd_print_license
  128. * @abstract Prints the program's license terms
  129. * @result void
  130. */
  131. void bd_print_license( void )
  132. {
  133. printf
  134. (
  135. "\n"
  136. "Boost Software License - Version 1.0 - August 17th, 2003\n"
  137. "\n"
  138. "Permission is hereby granted, free of charge, to any person or organization\n"
  139. "obtaining a copy of the software and accompanying documentation covered by\n"
  140. "this license (the \"Software\") to use, reproduce, display, distribute,\n"
  141. "execute, and transmit the Software, and to prepare derivative works of the\n"
  142. "Software, and to permit third-parties to whom the Software is furnished to\n"
  143. "do so, all subject to the following:\n"
  144. "\n"
  145. "The copyright notices in the Software and this entire statement, including\n"
  146. "the above license grant, this restriction and the following disclaimer,\n"
  147. "must be included in all copies of the Software, in whole or in part, and\n"
  148. "all derivative works of the Software, unless such copies or derivative\n"
  149. "works are solely in the form of machine-executable object code generated by\n"
  150. "a source language processor.\n"
  151. "\n"
  152. "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
  153. "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
  154. "FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\n"
  155. "SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\n"
  156. "FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\n"
  157. "ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n"
  158. "DEALINGS IN THE SOFTWARE.\n"
  159. "\n"
  160. );
  161. }