FreeCalypso > hg > freecalypso-reveng
diff fir/readfir.c @ 376:9b3e5be96bab
fir2freq: a tool for analyzing captured FIR coefficient sets
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 02 Aug 2021 04:59:46 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fir/readfir.c Mon Aug 02 04:59:46 2021 +0000 @@ -0,0 +1,83 @@ +/* + * Reading FIR coefficient tables from formatted ASCII files, + * modified version for host processing. + */ + +#include <sys/types.h> +#include <ctype.h> +#include <stdio.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> + +#include "rdcommon.c" + +static int *writeptr; + +static +process_number() +{ + char *field; + int rc, number; + + rc = get_field(&field); + if (rc < 0) + return(rc); + if (!rc) { + printf("error: %s is too short for a FIR coefficient table\n", + filename); + return(-1); + } + number = strtol(field, 0, 0); + if (number >= 32768) + number -= 65536; + *writeptr++ = number; + return(0); +} + +read_fir_coeff_table_int(filename_arg, rdbuf) + char *filename_arg; + int *rdbuf; +{ + char *field; + int rc, i; + + filename = filename_arg; + rdfile = fopen(filename, "r"); + if (!rdfile) { + perror(filename); + return(-1); + } + lineno = 0; + line_nfields = 0; + rc = get_field(&field); + if (rc <= 0) { +not_valid_fir_table: + fprintf(stderr, + "error: %s is not a valid FIR coefficient table file\n", + filename); + fclose(rdfile); + return(-1); + } + if (strcmp(field, "fir-coeff-table")) + goto not_valid_fir_table; + writeptr = rdbuf; + for (i = 0; i < 31; i++) { + rc = process_number(); + if (rc < 0) { + fclose(rdfile); + return(rc); + } + } + rc = get_field(&field); + fclose(rdfile); + if (rc < 0) + return(rc); + if (rc) { + fprintf(stderr, + "error: %s is too long for a FIR coefficient table\n", + filename); + return(-1); + } + return(0); +}