FreeCalypso > hg > freecalypso-sw
annotate 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 |
rev | line source |
---|---|
290
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * FFS write operation commands |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
6 #include <ctype.h> |
290
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "etm.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "ffs.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "ffserr.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "tmffs2.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "limits.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #include "localtypes.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 #include "localstruct.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 #include "exitcodes.h" |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 extern u_char rvi_msg[]; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 extern int rvi_msg_len; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 do_mkdir_existok(pathname) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 char *pathname; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 int rc, slen; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 struct stat_info stat; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 slen = strlen(pathname); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 if (slen >= TMFFS_STRING_SIZE) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 printf("error: pathname arg exceeds string length limit\n"); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 return(ERROR_USAGE); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 dp = cmdpkt + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 *dp++ = ETM_FFS2; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 *dp++ = TMFFS_MKDIR; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 *dp++ = slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 strcpy(dp, pathname); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 dp += slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (rvi_msg_len != 5) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 printf("error: mkdir response has wrong length\n"); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (!rvi_msg[3]) /* success */ |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 if (rvi_msg[3] != TMFFS_ERR_EXISTS) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 report_ffs_err("mkdir", rvi_msg[3]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 /* object already exists: OK if it's a directory, error otherwise */ |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 rc = do_xlstat(pathname, &stat); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 if (stat.type == OT_DIR) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 else { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 printf("error: %s exists and is not a directory\n", pathname); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 cmd_mkdir(argc, argv) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 char **argv; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 return do_mkdir_existok(argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 cmd_delete(argc, argv) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 char **argv; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 int rc, slen; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 slen = strlen(argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (slen >= TMFFS_STRING_SIZE) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 printf("error: pathname arg exceeds string length limit\n"); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 return(ERROR_USAGE); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 dp = cmdpkt + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 *dp++ = ETM_FFS2; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 *dp++ = TMFFS_REMOVE; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 *dp++ = slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 strcpy(dp, argv[1]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 dp += slen + 1; |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 if (rc) |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 return(rc); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 if (rvi_msg_len != 5) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 printf("error: TMFFS_REMOVE response has wrong length\n"); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (rvi_msg[3]) { |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 report_ffs_err("ffs_remove", rvi_msg[3]); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 return(ERROR_TARGET); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 } |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 return(0); |
76228aecf0d9
fc-fsio: mkdir and delete implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 } |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
102 |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
103 hexdigit(c) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
104 { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
105 if (isdigit(c)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
106 return(c - '0'); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
107 else if (isupper(c)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
108 return(c - 'A' + 10); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
109 else |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
110 return(c - 'a' + 10); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
111 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
112 |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
113 fwrite_hex_string(pathname, strarg) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
114 char *pathname, *strarg; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
115 { |
292
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
116 u_char buf[256]; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
117 int maxlen, len; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
118 char *cp; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
119 |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
120 maxlen = max_short_file_write(pathname); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
121 for (cp = strarg, len = 0; ; cp += 2) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
122 while (isspace(*cp)) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
123 cp++; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
124 if (!*cp) |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
125 break; |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
126 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
127 fprintf(stderr, "error: invalid hex string argument\n"); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
128 return(ERROR_USAGE); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
129 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
130 if (len >= maxlen) { |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
131 fprintf(stderr, |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
132 "error: hex string exceeds write packet limit\n"); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
133 return(ERROR_USAGE); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
134 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
135 buf[len++] = hexdigit(cp[0]) << 4 | hexdigit(cp[1]); |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
136 } |
3aa03b9519c0
fc-fsio: fwrite hex string implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
291
diff
changeset
|
137 return do_short_fwrite(pathname, buf, len); |
291
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
138 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
139 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
140 fwrite_from_file(pathname, srcfile) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
141 char *pathname, *srcfile; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
142 { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
143 fprintf(stderr, "This function is not yet implemented\n"); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
144 return(ERROR_BUG); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
145 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
146 |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
147 cmd_fwrite(argc, argv) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
148 char **argv; |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
149 { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
150 if (!strcmp(argv[2], "ascii")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
151 return do_short_fwrite(argv[1], argv[3], strlen(argv[3])); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
152 else if (!strcmp(argv[2], "hex")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
153 return fwrite_hex_string(argv[1], argv[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
154 else if (!strcmp(argv[2], "file")) |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
155 return fwrite_from_file(argv[1], argv[3]); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
156 else { |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
157 fprintf(stderr, |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
158 "error: middle argument to fwrite cmd must be \"ascii\", \"hex\" or \"file\"\n" |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
159 ); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
160 return(ERROR_USAGE); |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
161 } |
69e8ae2b5ba2
fc-fsio: fwrite implementation started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
290
diff
changeset
|
162 } |