FreeCalypso > hg > fc-pcsc-tools
comparison simtool/pbrestore.c @ 88:ae831b21ef77
lnd-restore command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Feb 2021 07:16:31 +0000 |
parents | bc862d41f96b |
children | 9c10afbb745a |
comparison
equal
deleted
inserted
replaced
87:bc862d41f96b | 88:ae831b21ef77 |
---|---|
198 } | 198 } |
199 } | 199 } |
200 fclose(inf); | 200 fclose(inf); |
201 return(0); | 201 return(0); |
202 } | 202 } |
203 | |
204 cmd_lnd_restore(argc, argv) | |
205 char **argv; | |
206 { | |
207 int rc; | |
208 FILE *inf; | |
209 int lineno; | |
210 char linebuf[1024]; | |
211 u_char *databuf; | |
212 | |
213 rc = select_ef_lnd(); | |
214 if (rc < 0) | |
215 return(rc); | |
216 databuf = malloc(curfile_total_size); | |
217 if (!databuf) { | |
218 perror("malloc for full EF_LND"); | |
219 return(-1); | |
220 } | |
221 inf = fopen(argv[1], "r"); | |
222 if (!inf) { | |
223 perror(argv[1]); | |
224 free(databuf); | |
225 return(-1); | |
226 } | |
227 memset(databuf, 0xFF, curfile_total_size); | |
228 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | |
229 if (!index(linebuf, '\n')) { | |
230 fprintf(stderr, | |
231 "%s line %d: too long or missing newline\n", | |
232 argv[1], lineno); | |
233 fclose(inf); | |
234 free(databuf); | |
235 return(-1); | |
236 } | |
237 if (linebuf[0] != '#' || !isdigit(linebuf[1])) | |
238 continue; | |
239 rc = process_record(linebuf, databuf, argv[1], lineno); | |
240 if (rc < 0) { | |
241 fclose(inf); | |
242 free(databuf); | |
243 return(rc); | |
244 } | |
245 } | |
246 fclose(inf); | |
247 rc = restore_bin_cyclic(databuf); | |
248 free(databuf); | |
249 return(rc); | |
250 } |