FreeCalypso > hg > fc-sim-tools
comparison libcommon/be_init.c @ 9:c9ef9e91dd8e
new libcommon, initial version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Mar 2021 06:55:38 +0000 |
| parents | |
| children | e2ef4b8e4136 |
comparison
equal
deleted
inserted
replaced
| 8:34bbb0585cab | 9:c9ef9e91dd8e |
|---|---|
| 1 /* | |
| 2 * This module is responsible for collecting the initial info | |
| 3 * strings emitted by the back end. | |
| 4 */ | |
| 5 | |
| 6 #include <ctype.h> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <strings.h> | |
| 11 | |
| 12 extern FILE *rpipeF; | |
| 13 | |
| 14 #define MAX_INIT_STRING 254 | |
| 15 | |
| 16 char be_reader_name[MAX_INIT_STRING+1]; | |
| 17 char be_atr_string[MAX_INIT_STRING+1]; | |
| 18 | |
| 19 static void | |
| 20 copy_without_leading_space(input_str, dest) | |
| 21 char *input_str, *dest; | |
| 22 { | |
| 23 char *cp; | |
| 24 | |
| 25 for (cp = input_str; isspace(*cp); cp++) | |
| 26 ; | |
| 27 strcpy(dest, cp); | |
| 28 } | |
| 29 | |
| 30 collect_backend_init_strings() | |
| 31 { | |
| 32 char inbuf[MAX_INIT_STRING+2], *cp; | |
| 33 | |
| 34 for (;;) { | |
| 35 if (!fgets(inbuf, sizeof inbuf, rpipeF)) { | |
| 36 fprintf(stderr, | |
| 37 "start-up error: EOF reading init strings from back end\n"); | |
| 38 exit(1); | |
| 39 } | |
| 40 cp = index(inbuf, '\n'); | |
| 41 if (!cp) { | |
| 42 fprintf(stderr, | |
| 43 "start-up error: init string from back end has no newline\n"); | |
| 44 exit(1); | |
| 45 } | |
| 46 *cp = '\0'; | |
| 47 if (!inbuf[0]) | |
| 48 break; | |
| 49 switch (inbuf[0]) { | |
| 50 case 'A': | |
| 51 copy_without_leading_space(inbuf + 1, be_atr_string); | |
| 52 break; | |
| 53 case 'R': | |
| 54 copy_without_leading_space(inbuf + 1, be_reader_name); | |
| 55 break; | |
| 56 } | |
| 57 } | |
| 58 return(0); | |
| 59 } |
