changeset 292:3aa03b9519c0

fc-fsio: fwrite hex string implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 01 Mar 2014 03:09:10 +0000
parents 69e8ae2b5ba2
children ffeea2f9d149
files rvinterf/etmsync/fswrite.c
diffstat 1 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/fswrite.c	Sat Mar 01 02:36:25 2014 +0000
+++ b/rvinterf/etmsync/fswrite.c	Sat Mar 01 03:09:10 2014 +0000
@@ -3,6 +3,7 @@
  */
 
 #include <sys/types.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -99,11 +100,41 @@
 	return(0);
 }
 
+hexdigit(c)
+{
+	if (isdigit(c))
+		return(c - '0');
+	else if (isupper(c))
+		return(c - 'A' + 10);
+	else
+		return(c - 'a' + 10);
+}
+
 fwrite_hex_string(pathname, strarg)
 	char *pathname, *strarg;
 {
-	fprintf(stderr, "This function is not yet implemented\n");
-	return(ERROR_BUG);
+	u_char buf[256];
+	int maxlen, len;
+	char *cp;
+
+	maxlen = max_short_file_write(pathname);
+	for (cp = strarg, len = 0; ; cp += 2) {
+		while (isspace(*cp))
+			cp++;
+		if (!*cp)
+			break;
+		if (!isxdigit(cp[0]) || !isxdigit(cp[1])) {
+			fprintf(stderr, "error: invalid hex string argument\n");
+			return(ERROR_USAGE);
+		}
+		if (len >= maxlen) {
+			fprintf(stderr,
+			"error: hex string exceeds write packet limit\n");
+			return(ERROR_USAGE);
+		}
+		buf[len++] = hexdigit(cp[0]) << 4 | hexdigit(cp[1]);
+	}
+	return do_short_fwrite(pathname, buf, len);
 }
 
 fwrite_from_file(pathname, srcfile)