[amx-netlinx-common] r26 committed - - Added io library...

6 views
Skip to first unread message

amx-netli...@googlecode.com

unread,
May 17, 2010, 2:54:00 AM5/17/10
to netlinx-comm...@googlegroups.com
Revision: 26
Author: kim.john.burgess
Date: Sun May 16 23:53:19 2010
Log: - Added io library
- Modified debug library to use the io library for console output
- Modified string library to use the io library for console output
- Changed names in program_name to be lowercase
- Basic comment updates
http://code.google.com/p/amx-netlinx-common/source/detail?r=26

Added:
/trunk/io.axi
Modified:
/trunk/Debug.axi
/trunk/Math.axi
/trunk/String.axi

=======================================
--- /dev/null
+++ /trunk/io.axi Sun May 16 23:53:19 2010
@@ -0,0 +1,106 @@
+/* The contents of this file are subject to the Mozilla Public License
Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is an input/output (IO) library designed to expand on
the
+ * base functionality provided in the NetLinx language.
+ *
+ * The Initial Developer of the Original Code is Queensland Department of
+ * Justice and Attorney-General.
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Kim Burgess <kim.b...@justice.qld.gov.au>
+ *
+ * $Id: io.axi 23 2010-05-12 16:29:43Z kim.john.burgess $
+ * tab-width: 4 columns: 80
+ */
+
+program_name='io'
+#if_not_defined __NCL_LIB_IO
+#define __NCL_LIB_IO
+
+
+define_variable
+persistent dev io_out = 0:0:0 // output stream device
+persistent integer io_out_mtu = 131 // max characters to transmit (the
+ // NL diagnositics console will only
+ // display a max of 131 characters per
+ // line)
+persistent char io_line_seperator = $0A // seperator to insert between
lines
+
+
+/**
+ * Write a character array to the output device.
+ *
+ * If the outgoing data exceeds io_out_mtu it will be split into multiple
+ * packets. If a non printable char is located within the last half of the
+ * current packet it will split at the non printable character, otherwise
all
+ * data up to io_out_mtu will be sent in the packet.
+ *
+ * If io_out_mtu is 0 all data will be sent in a single packet.
+ *
+ * @param buf the character array to write
+ * @param offset the offset to begin writing from (offset 0 == character 1)
+ * @param len the number of characters to write
+ */
+define_function write(char buf[], integer offset, integer len)
+{
+ stack_var integer start
+ stack_var integer end
+ stack_var integer min_len
+
+ if (io_out_mtu && len > io_out_mtu) {
+ min_len = type_cast(io_out_mtu / 2)
+ start = offset + 1
+ while (start < offset + len) {
+ end = min_value(start + io_out_mtu, offset + len)
+ while (end > start + min_len) {
+ if ((buf[end] > $08 && buf[end] < $0E) ||
+ (buf[end] > $1B && buf[end] < $21)) {
+ end++
+ break
+ }
+ end--
+ }
+
+ if (end <= start + min_len) {
+ end = min_value(start + io_out_mtu, offset + len + 1)
+ }
+
+ write(buf, start - 1, end - start)
+ start = end
+ }
+ } else {
+ send_string io_out, mid_string(buf, offset + 1, len)
+ }
+}
+
+/**
+ * Print a character array to the output stream.
+ *
+ * @param x a string containing the data to output
+ */
+define_function print(char x[])
+{
+ write(x, 0, length_string(x))
+}
+
+/**
+ * Print a line to the output stream.
+ *
+ * @param x a string containing the data to output
+ */
+define_function println(char x[])
+{
+ write("x, io_line_seperator", 0, length_string(x))
+}
+
+#end_if
=======================================
--- /trunk/Debug.axi Wed May 12 09:29:43 2010
+++ /trunk/Debug.axi Sun May 16 23:53:19 2010
@@ -24,13 +24,12 @@
* tab-width: 4 columns: 80
*/

-program_name='Debug'
+program_name='debug'
#if_not_defined __NCL_LIB_DEBUG
#define __NCL_LIB_DEBUG


-define_device
-console = 0:0:0 // Device to send debug messages to
+include 'io'


define_constant
@@ -75,46 +74,10 @@
debug_level = x
} else {
debug_msg(DEBUG_WARN, "'Invalid debug level, defaulting to ',
- debug_get_level_string(DEBUG_ERROR)")
+ debug_get_level_string(DEBUG_ERROR)")
debug_set_level(DEBUG_ERROR)
}
}
-
-/**
- * Print a line to the console (diagnostics).
- *
- * The diagnostics output is limited to 131 characters per line. If the
- * message to print is longer than this it will wrap into multiple lines,
with
- * linebreaks inserted at any whitespace found near (character 80 onwards)
the
- * end of a line.
- *
- * @param x a string containing the message to send
- */
-define_function println(char x[])
-{
- stack_var integer start
- stack_var integer end
- stack_var integer len
- start = 1
- len = length_string(x)
- while (start < len) {
- end = min_value(start + 131, len)
- while (end > start + 80) {
- if ((x[end] > $08 &&
- x[end] < $0E) ||
- (x[end] > $1B && x[end] < $21)) {
- end++
- break
- }
- end--
- }
- if (end <= start + 80) { // No whitespace found, or short line
- end = min_value(start + 131, len)
- }
- send_string console, mid_string(x, start, (end - start) + 1)
- start = end
- }
-}

/**
* Voices a debug message if required by the current debug level. All
system
=======================================
--- /trunk/Math.axi Wed May 12 09:29:43 2010
+++ /trunk/Math.axi Sun May 16 23:53:19 2010
@@ -8,8 +8,8 @@
* for the specific language governing rights and limitations under the
* License.
*
- * The Original Code is math library to expand on the base math
functionality
- * provided by the NetLinx language.
+ * The Original Code is a math library to expand on the base math
+ * functionality provided by the NetLinx language.
*
* The Initial Developer of the Original Code is Queensland Department of
* Justice and Attorney-General.
@@ -23,7 +23,7 @@
* tab-width: 4 columns: 80
*/

-program_name='Math'
+program_name='math'
#if_not_defined __NCL_LIB_MATH
#define __NCL_LIB_MATH

=======================================
--- /trunk/String.axi Thu May 13 04:14:11 2010
+++ /trunk/String.axi Sun May 16 23:53:19 2010
@@ -26,10 +26,14 @@
* tab-width: 4 columns: 80
*/

-program_name='String'
+program_name='string'
#if_not_defined __NCL_LIB_STRING
#define __NCL_LIB_STRING

+
+include 'io'
+
+
define_constant
STRING_RETURN_SIZE_LIMIT = 1024 // Maximum string return size
// for string manipulation functions.
@@ -48,7 +52,7 @@
define_function char[STRING_RETURN_SIZE_LIMIT] string_size_error()
{
// handle, alert, ignore etc here
- send_string 0, "'Return size to small in String.axi'"
+ println("'Return size to small in String.axi'")

return 'error'
}
Reply all
Reply to author
Forward
0 new messages