123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #include "strfunc.h"
- const char strfunc_id[] = "@(#)$Id $" strfunc_h;
-
-
- #include <stdlib.h>
- #include <string.h>
- #include "mode.h"
- #include "frame.h"
- typedef struct {
- char *name;
- int id;
- } conv_table;
- static const conv_table modetable[] = {
- {"MR475", MR475},
- {"MR515", MR515},
- {"MR59", MR59},
- {"MR67", MR67},
- {"MR74", MR74},
- {"MR795", MR795},
- {"MR102", MR102},
- {"MR122", MR122},
- {"MRDTX", MRDTX},
- {NULL, -1}
- };
- static const conv_table rxframetable[] = {
- {"RX_SPEECH_GOOD", RX_SPEECH_GOOD},
- {"RX_SPEECH_DEGRADED", RX_SPEECH_DEGRADED},
- {"RX_SPEECH_BAD", RX_SPEECH_BAD},
- {"RX_SID_FIRST", RX_SID_FIRST},
- {"RX_SID_UPDATE", RX_SID_UPDATE},
- {"RX_SID_BAD", RX_SID_BAD},
- {"RX_ONSET", RX_ONSET},
- {"RX_NO_DATA", RX_NO_DATA},
- {NULL, -1}
- };
- static const conv_table txframetable[] = {
- {"TX_SPEECH_GOOD", TX_SPEECH_GOOD},
- {"TX_SPEECH_DEGRADED", TX_SPEECH_DEGRADED},
- {"TX_SPEECH_BAD", TX_SPEECH_BAD},
- {"TX_SID_FIRST", TX_SID_FIRST},
- {"TX_SID_UPDATE", TX_SID_UPDATE},
- {"TX_SID_BAD", TX_SID_BAD},
- {"TX_ONSET", TX_ONSET},
- {"TX_NO_DATA", TX_NO_DATA},
- {NULL, -1}
- };
- static int search_string(const conv_table *p, const char *str)
- {
- if (str == NULL)
- return -1;
-
- do
- {
- if (strcmp(p->name, str) == 0)
- return p->id;
- p++;
- } while (p->name != NULL);
- return -1;
- }
-
- static char *search_id(const conv_table *p, int id)
- {
- if (id == -1)
- return NULL;
-
- do
- {
- if (p->id == id)
- return p->name;
- p++;
- } while (p->name != NULL);
- return NULL;
- }
-
- int str2mode(const char* str, enum Mode *mode)
- {
- int m;
- if ((m = search_string(modetable, str)) == -1)
- return 1;
- *mode = (enum Mode) m;
- return 0;
- }
- int mode2str(enum Mode mode, char** str)
- {
- return ((*str = search_id(modetable, (int) mode)) != NULL);
- }
- int rxframe2str(enum RXFrameType ft, char** str)
- {
- return ((*str = search_id(rxframetable, (int) ft)) != NULL);
- }
- int txframe2str(enum TXFrameType ft, char** str)
- {
- return ((*str = search_id(txframetable, (int) ft)) != NULL);
- }
|