FreeCalypso > hg > freecalypso-sw
comparison rvinterf/etmsync/fswrite.c @ 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 |
comparison
equal
deleted
inserted
replaced
291:69e8ae2b5ba2 | 292:3aa03b9519c0 |
---|---|
1 /* | 1 /* |
2 * FFS write operation commands | 2 * FFS write operation commands |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <ctype.h> | |
6 #include <stdio.h> | 7 #include <stdio.h> |
7 #include <stdlib.h> | 8 #include <stdlib.h> |
8 #include <string.h> | 9 #include <string.h> |
9 #include <strings.h> | 10 #include <strings.h> |
10 #include "etm.h" | 11 #include "etm.h" |
97 return(ERROR_TARGET); | 98 return(ERROR_TARGET); |
98 } | 99 } |
99 return(0); | 100 return(0); |
100 } | 101 } |
101 | 102 |
103 hexdigit(c) | |
104 { | |
105 if (isdigit(c)) | |
106 return(c - '0'); | |
107 else if (isupper(c)) | |
108 return(c - 'A' + 10); | |
109 else | |
110 return(c - 'a' + 10); | |
111 } | |
112 | |
102 fwrite_hex_string(pathname, strarg) | 113 fwrite_hex_string(pathname, strarg) |
103 char *pathname, *strarg; | 114 char *pathname, *strarg; |
104 { | 115 { |
105 fprintf(stderr, "This function is not yet implemented\n"); | 116 u_char buf[256]; |
106 return(ERROR_BUG); | 117 int maxlen, len; |
118 char *cp; | |
119 | |
120 maxlen = max_short_file_write(pathname); | |
121 for (cp = strarg, len = 0; ; cp += 2) { | |
122 while (isspace(*cp)) | |
123 cp++; | |
124 if (!*cp) | |
125 break; | |
126 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) { | |
127 fprintf(stderr, "error: invalid hex string argument\n"); | |
128 return(ERROR_USAGE); | |
129 } | |
130 if (len >= maxlen) { | |
131 fprintf(stderr, | |
132 "error: hex string exceeds write packet limit\n"); | |
133 return(ERROR_USAGE); | |
134 } | |
135 buf[len++] = hexdigit(cp[0]) << 4 | hexdigit(cp[1]); | |
136 } | |
137 return do_short_fwrite(pathname, buf, len); | |
107 } | 138 } |
108 | 139 |
109 fwrite_from_file(pathname, srcfile) | 140 fwrite_from_file(pathname, srcfile) |
110 char *pathname, *srcfile; | 141 char *pathname, *srcfile; |
111 { | 142 { |