diff options
Diffstat (limited to 'src/glautils')
-rw-r--r-- | src/glautils/fgla.c | 7 | ||||
-rw-r--r-- | src/glautils/gla.c | 139 |
2 files changed, 3 insertions, 143 deletions
diff --git a/src/glautils/fgla.c b/src/glautils/fgla.c index 68232fd..f2ed8eb 100644 --- a/src/glautils/fgla.c +++ b/src/glautils/fgla.c @@ -15,7 +15,6 @@ #include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include <errno.h>
#include "glass_data.h"
#include "glamacdef.h"
@@ -286,7 +285,7 @@ void print_header(OutputFormat format, u32 found_count, const char* search_term, }
}
-void print_glass_result(OutputFormat format, const Glass* glass, const char* glass_name, int is_first, int is_last) {
+void print_glass_result(OutputFormat format, const Glass* glass, const char* glass_name, int is_first) {
switch (format) {
case OUTPUT_CSV:
printf("%s,%.5f,%.2f,%s,%s\n",
@@ -505,7 +504,7 @@ int main(int argc, char* argv[]) { const char* glass_name = (const char*)get_glass_name(i);
if (glass && glass_name) {
- print_glass_result(output_format, glass, glass_name, j == 0, j == found_count - 1);
+ print_glass_result(output_format, glass, glass_name, j == 0);
}
}
@@ -518,4 +517,4 @@ int main(int argc, char* argv[]) { cleanup_glass_data();
return FGLA_SUCCESS;
-}
\ No newline at end of file +}
diff --git a/src/glautils/gla.c b/src/glautils/gla.c deleted file mode 100644 index 7922c4f..0000000 --- a/src/glautils/gla.c +++ /dev/null @@ -1,139 +0,0 @@ -/**
- * gla.c - main source program file for displaying the glass map.
- *
- * Copyright (C) 2025 https://optics-design.com
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * See the COPYING file for the full license text.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int main(int argc, char* argv[]){
- int filecount = 0;
- char rfilename[FILENAME_MAX];
- char glassname[50];
-
- FILE *readfile;
-
- if (argc==1){
- printf("This program is designed to work with glass data from the manufacturers\n");
- return 1;
- }
- //Argument parsing
- while (--argc>0) {
- if ((strstr((++argv)[0], ".xml"))){
- filecount++;
- strcpy(rfilename, argv[0]);
- }
- else {
- strcpy(glassname, argv[0]);
- for (int i =0; i<50; i++) {
- if (!glassname[i]){
- break;
- }
- if (glassname[i] >= 'a' && glassname[i] <= 'z'){
- glassname[i] = glassname[i] - ('a'- 'A');
- }
-
- }
- // while(*glassname){
- // if (*glassname >= 'a' && *glassname <= 'z'){
- // *glassname = *glassname - ('a'- 'A');
- // }
- // glassname++;
- // }
- // glassname = glassname -1;
-
- }
-
- }
- // printf("%s\n", rfilename);
- readfile = fopen(rfilename, "rb");
- if (readfile == NULL) {
- perror("Failed to open file");
- return 1;
- }
-
- fseek(readfile, 0, SEEK_END);
-
- long file_size = ftell(readfile);
- if (file_size == -1) {
- perror("ftell failed");
- fclose(readfile);
- return 1;
- }
- char* buffer = malloc(file_size + 1);
-
- fseek(readfile, 0, SEEK_SET);
-
- if (buffer == NULL) {
- perror("Failed to allocate memory");
- fclose(readfile);
- return 1;
- }
- // Read the file into the buffer
- size_t read_size = fread(buffer, 1, file_size, readfile);
- if (read_size != file_size) {
- perror("Failed to read the complete file");
- free(buffer);
- fclose(readfile);
- return 1;
- }
- // Null terminate the buffer (in case it's treated as a string)
- buffer[file_size] = '\0';
- fclose(readfile);
-
- // char *newline_ptr = NULL;
- // for (int i = 0; i < file_size; i++) {
- // if (buffer[i] == '\n') {
- // newline_ptr = &buffer[i];
- // break;
- // }
- // }
- // fwrite(buffer, 1, newline_ptr - buffer, stdout);
- char* line_start = buffer;
- char* line_end = NULL;
- int line_length;
- int glafound = 0;
-
- while ((line_end=strchr(line_start, '\n'))) {
- *line_end = '\0';
- if (!glafound){
- if (strstr(line_start, glassname) && strstr(line_start, "<GlassName>")) {
- line_length = strlen(line_start)-27; // 2*Length_of_tag+1 + 4
- printf("Name: %.*s, ", line_length, line_start+14); // Length_of_tag+3
- glafound = 1;
- }
- }
-
- else{
- if (strstr(line_start, "</NumericName>")) {
- line_length = strlen(line_start)-31; // 2*Length_of_tag+1 + 4
- printf("Code: %.*s", line_length, line_start+16); // Length_of_tag+3
- }
- // if (strstr(line_start, "</EquationType>")) {
- // line_length = strlen(line_start)-33; // 2*Length_of_tag+1 + 4
- // printf("Equation: %.*s\n", line_length, line_start+17); // Length_of_tag+3
- // }
- // if (strstr(line_start, "</Coefficient>")) {
- // line_length = strlen(line_start)-32; // 2*Length_of_tag+1 + 4
- // printf("Coefficient: %.*s\n", line_length, line_start+17); // Length_of_tag+3
- // }
- if (strstr(line_start, "</Glass>")) {
- printf("\n");
- glafound = 0;
- }
- }
- line_start = line_end+1;
-
- }
-
- free(buffer);
- return 0;
-}
|