FreeCalypso > hg > freecalypso-tools
comparison librftab/readtxramp.c @ 314:a0f79bba0ad8
librftab: reading of Tx ramp template files split from rftablerd module
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 22 Nov 2017 18:12:04 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
313:a9bd4b15f502 | 314:a0f79bba0ad8 |
---|---|
1 /* | |
2 * Reading Tx ramp templates from formatted ASCII files, used for the ttw | |
3 * command in fc-tmsh. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <ctype.h> | |
8 #include <stdio.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <stdlib.h> | |
12 #include "../rvinterf/include/exitcodes.h" | |
13 | |
14 #include "rdcommon.c" | |
15 | |
16 static u_char *writeptr; | |
17 | |
18 static | |
19 process_txramp_number() | |
20 { | |
21 char *field; | |
22 int rc; | |
23 u_long number; | |
24 | |
25 rc = get_field(&field); | |
26 if (rc < 0) | |
27 return(ERROR_USAGE); | |
28 if (!rc) { | |
29 printf("error: %s is too short for a Tx ramp template\n", | |
30 filename); | |
31 return(ERROR_USAGE); | |
32 } | |
33 number = strtoul(field, 0, 0); | |
34 *writeptr++ = number; | |
35 return(0); | |
36 } | |
37 | |
38 static | |
39 read_txramp_16num() | |
40 { | |
41 int i, rc; | |
42 | |
43 for (i = 0; i < 16; i++) { | |
44 rc = process_txramp_number(); | |
45 if (rc) | |
46 return(rc); | |
47 } | |
48 return(0); | |
49 } | |
50 | |
51 read_tx_ramp_template(filename_arg, rdbuf) | |
52 char *filename_arg; | |
53 u_char *rdbuf; | |
54 { | |
55 char *field; | |
56 int rc; | |
57 | |
58 filename = filename_arg; | |
59 rdfile = fopen(filename, "r"); | |
60 if (!rdfile) { | |
61 perror(filename); | |
62 return(ERROR_UNIX); | |
63 } | |
64 lineno = 0; | |
65 line_nfields = 0; | |
66 rc = get_field(&field); | |
67 if (rc <= 0) { | |
68 not_valid_ramp_file: | |
69 printf("error: %s is not a valid Tx ramp template file\n", | |
70 filename); | |
71 fclose(rdfile); | |
72 return(ERROR_USAGE); | |
73 } | |
74 if (strcmp(field, "ramp-up")) | |
75 goto not_valid_ramp_file; | |
76 writeptr = rdbuf; | |
77 rc = read_txramp_16num(); | |
78 if (rc) { | |
79 fclose(rdfile); | |
80 return(rc); | |
81 } | |
82 rc = get_field(&field); | |
83 if (rc <= 0) | |
84 goto not_valid_ramp_file; | |
85 if (strcmp(field, "ramp-down")) | |
86 goto not_valid_ramp_file; | |
87 rc = read_txramp_16num(); | |
88 if (rc) { | |
89 fclose(rdfile); | |
90 return(rc); | |
91 } | |
92 rc = get_field(&field); | |
93 fclose(rdfile); | |
94 if (rc < 0) | |
95 return(ERROR_USAGE); | |
96 if (rc) { | |
97 printf("error: %s is too long for a Tx ramp template\n", | |
98 filename); | |
99 return(ERROR_USAGE); | |
100 } | |
101 return(0); | |
102 } |