From 6be3193593d6fe6dc36e584a44ec629a44fc394b Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Apr 2025 21:19:44 +0200 Subject: First Commit --- src/glautils/gla.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/glautils/gla.c (limited to 'src/glautils') diff --git a/src/glautils/gla.c b/src/glautils/gla.c new file mode 100644 index 0000000..7922c4f --- /dev/null +++ b/src/glautils/gla.c @@ -0,0 +1,139 @@ +/** + * 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 +#include +#include + +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, "")) { + 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, "")) { + 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, "")) { + // 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, "")) { + // 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, "")) { + printf("\n"); + glafound = 0; + } + } + line_start = line_end+1; + + } + + free(buffer); + return 0; +} -- cgit v1.2.3