CVS: libraries/mspgcc escape_decode.c,1.2,1.3 escape_encode.c,1.3,1.4 hex_encode.c,1.3,1.4 hexdigits.c,1.1,1.2

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/libraries/mspgcc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27555/libraries/mspgcc

Modified Files:
	escape_decode.c escape_encode.c hex_encode.c hexdigits.c 
Log Message:
docs

Index: escape_decode.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/mspgcc/escape_decode.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- escape_decode.c	16 Sep 2005 13:28:39 -0000	1.2
+++ escape_decode.c	18 Sep 2005 15:05:57 -0000	1.3
@@ -1,5 +1,8 @@
 #include "mspgcc/util.h"
 
+// decode a string containing '\' escaped characters
+// the output may contain null bytes
+
 unsigned int escape_decode(void *dst, unsigned int maxsize, const char *src) {
     unsigned int output_size = 0;
     enum {M_PRINT, M_ESCAPE, M_HEX_DIGIT_1, M_HEX_DIGIT_0} mode = M_PRINT;
@@ -8,6 +11,7 @@
         unsigned character = ((unsigned char*)src)[pos];
         switch (mode) {
             case M_PRINT:
+                // copy char to the output, except when the escape char is found
                 if (((unsigned char*)src)[pos] == '\\') {
                     mode = M_ESCAPE;
                 } else {
@@ -15,6 +19,7 @@
                 }
                 break;
             case M_ESCAPE:
+                // interpret escapes
                 switch (character) {
                     case '0':
                         ((unsigned char *)dst)[output_size++] = '\0';
@@ -49,15 +54,18 @@
                 }
                 break;
             case M_HEX_DIGIT_1:
+                // for \xNN, parse first digit
                 ((unsigned char *)dst)[output_size] = hex_fromdigit(character) << 4;
                 mode = M_HEX_DIGIT_0;
                 break;
             case M_HEX_DIGIT_0:
+                // for \xNN, parse second digit
                 ((unsigned char *)dst)[output_size++] |= hex_fromdigit(character);
                 mode = M_PRINT;
                 break;
         }
     }
+    //write trailing null byte if there is enough space
     if (output_size < maxsize) ((unsigned char *)dst)[output_size] = '\0';
     return output_size;
 }

Index: escape_encode.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/mspgcc/escape_encode.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- escape_encode.c	18 Sep 2005 12:22:25 -0000	1.3
+++ escape_encode.c	18 Sep 2005 15:05:57 -0000	1.4
@@ -1,5 +1,8 @@
 #include "mspgcc/util.h"
 
+// encode a string or binary to a string containing '\' escaped characters
+// the input may contain null bytes, the output is null terminated
+
 unsigned int escape_encode(char *dst, unsigned int maxsize, const void *src, unsigned int size) {
     unsigned int output_size = 0;
     
@@ -9,7 +12,8 @@
             ((unsigned char *)dst)[output_size++] = c;
         }
     }
-    //internal helper function, append a escaped character ('\\' prefixed)
+    
+    //internal helper function, output an escaped character ('\\' prefixed)
     void escape(char c) {
         out('\\');
         out(c);
@@ -38,6 +42,7 @@
                 break;
         }
     }
+    //write trailing null byte
     out('\0');
     return output_size;
 }

Index: hex_encode.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/mspgcc/hex_encode.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- hex_encode.c	18 Sep 2005 12:22:25 -0000	1.3
+++ hex_encode.c	18 Sep 2005 15:05:57 -0000	1.4
@@ -10,6 +10,7 @@
         maxsize -= 2;
         count += 2;
     }
+    
     //write trailing null byte if there is enough space
     if (maxsize) {
         *dst = '\0';

Index: hexdigits.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/mspgcc/hexdigits.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- hexdigits.c	18 Sep 2005 12:22:25 -0000	1.1
+++ hexdigits.c	18 Sep 2005 15:05:57 -0000	1.2
@@ -1 +1,3 @@
+
+// an array containing all the hexadcimal digits
 const unsigned char HEX_DIGITS[16] = "0123456789ABCDEF";



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.