75 {
76 SCANNED_ARG *scanned;
77 long i_arg, type, inHeader = 1;
78 char *input, *output;
79 unsigned long pipeFlags;
80 FILE *fpi, *fpo;
81 char s1[SDDS_MAXLINE], s2[SDDS_MAXLINE];
82 char *name, *format, *value;
83
85 argc =
scanargs(&scanned, argc, argv);
86 if (argc < 3) {
87 fprintf(stderr, "%s\n", USAGE);
88 exit(EXIT_FAILURE);
89 }
90
91 input = output = format = value = NULL;
92 pipeFlags = 0;
93 for (i_arg = 1; i_arg < argc; i_arg++) {
94 if (scanned[i_arg].arg_type == OPTION) {
95 switch (
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
96 case SET_PIPE:
97 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipeFlags)) {
98 fprintf(stderr, "Error: Invalid -pipe syntax.\n");
99 exit(EXIT_FAILURE);
100 }
101 break;
102 default:
103 fprintf(stderr, "Error: Unknown option '%s'.\n", scanned[i_arg].list[0]);
104 exit(EXIT_FAILURE);
105 break;
106 }
107 } else {
108 if (!input) {
109 input = scanned[i_arg].list[0];
110 } else if (!output) {
111 output = scanned[i_arg].list[0];
112 } else {
113 fprintf(stderr, "Error: Too many filenames provided.\n");
114 exit(EXIT_FAILURE);
115 }
116 }
117 }
118
120
121 if (!input)
122 fpi = stdin;
123 else if (!(fpi = fopen(input, "r"))) {
124 fprintf(stderr, "Error: Unable to open input file '%s'.\n", input);
125 exit(EXIT_FAILURE);
126 }
127
128 if (!output)
129 fpo = stdout;
130 else if (!(fpo = fopen(output, "w"))) {
131 fprintf(stderr, "Error: Unable to open output file '%s'.\n", output);
132 exit(EXIT_FAILURE);
133 }
134
135 fprintf(fpo, "SDDS1\n");
136 if (!fgets(s1, SDDS_MAXLINE, fpi)) {
137 SDDS_Bomb(
"Input file ends prematurely");
138 }
139
140 while (s1[0] == '@') {
144 }
145 if ((type = identifyType(format)) < 0) {
146 fprintf(stderr, "Error (TFS2sdds): Unknown format string: %s\n", format);
147 exit(EXIT_FAILURE);
148 }
149 fprintf(fpo, "¶meter name=%s, type=%s, fixed_value=\"%s\" &end\n", name, typeName[type], value);
150
151 if (!fgets(s1, SDDS_MAXLINE, fpi)) {
152 SDDS_Bomb(
"Input file ends prematurely");
153 }
154 inHeader = 0;
155 }
156
157 if (!fgets(s2, SDDS_MAXLINE, fpi)) {
158 SDDS_Bomb(
"Input file ends prematurely");
159 }
160
161 if (s1[0] != '*') {
163 }
164 if (s2[0] != '$') {
165 SDDS_Bomb(
"Column format line not seen");
166 }
172 }
173 fprintf(fpo, "&column name=%s, type=", name);
174 if ((type = identifyType(format)) < 0) {
175 fprintf(stderr, "Error (TFS2sdds): Unknown format string: %s\n", format);
176 exit(EXIT_FAILURE);
177 }
178 fprintf(fpo, "%s &end\n", typeName[type]);
179 }
180
181 if (inHeader == 0) {
182 fputs("&data mode=ascii, no_row_counts=1 &end\n", fpo);
183 }
184
185 while (fgets(s1, SDDS_MAXLINE, fpi)) {
186 if (inHeader) {
187 if (s1[0] == '@') {
191 }
192 if ((type = identifyType(format)) < 0) {
193 fprintf(stderr, "Error (TFS2sdds): Unknown format string: %s\n", format);
194 exit(EXIT_FAILURE);
195 }
196 fprintf(fpo, "¶meter name=%s, type=%s, fixed_value=\"%s\" &end\n", name, typeName[type], value);
197 continue;
198 }
199 inHeader = 0;
200 fputs("&data mode=ascii, no_row_counts=1 &end\n", fpo);
201 }
202 fputs(s1, fpo);
203 }
204 if (inHeader) {
205 fputs("&data mode=ascii, no_row_counts=1 &end\n\n", fpo);
206 }
207
208 return EXIT_SUCCESS;
209}
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
char * get_token(char *s)
Extracts the next token from the input string.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.