comparison src/main.c @ 42:d873a04165f9

use basename() on cli version really stupid bug lol
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Fri, 13 May 2022 00:48:11 -0400
parents 8bcb6a2d3def
children 9b309701420e
comparison
equal deleted inserted replaced
41:02e46804c923 42:d873a04165f9
3 #include <stdio.h> 3 #include <stdio.h>
4 #include <stdlib.h> 4 #include <stdlib.h>
5 #include <string.h> 5 #include <string.h>
6 #include <unistd.h> 6 #include <unistd.h>
7 #include <getopt.h> 7 #include <getopt.h>
8 #include <libgen.h>
8 #ifdef _MSC_VER 9 #ifdef _MSC_VER
9 #define strdup(p) _strdup(p) 10 #define strdup(p) _strdup(p)
10 #endif 11 #endif
11 12
12 static struct option options_long[] = { 13 static struct option options_long[] = {
146 fflush(stdout); 147 fflush(stdout);
147 scanf("%3s", args.type); 148 scanf("%3s", args.type);
148 } 149 }
149 fflush(stdout); 150 fflush(stdout);
150 if (strcmp(args.output, " ") == 0) { /* string manipulation hell */ 151 if (strcmp(args.output, " ") == 0) { /* string manipulation hell */
151 char temp[256] = {'V'}; 152 char temp[256] = (char*)malloc(sizeof(char)*256);
152 char str_version[16] = {}; 153 char str_version[16] = {};
153 sprintf(str_version, "%d", args.version); 154 sprintf(str_version, "V%d", args.version);
154 strncat(temp, str_version, 2); 155 strncat(temp, str_version, 2);
155 strncat(temp, "_", 1); 156 strncat(temp, "_", 1);
156 strncat(temp, args.input, 248); 157 strncat(temp, basename(args.input), 248);
157 strcpy(temp, strremove(temp, strrchr(args.input, ('.')))); /* remove file extension */ 158 strcpy(temp, strremove(temp, strrchr(basename(args.input), ('.')))); /* remove file extension */
158 strncat(temp, ".", 1); 159 strncat(temp, ".", 1);
159 strncat(temp, args.type, 3); 160 strncat(temp, args.type, 3);
160 strncpy(args.output, temp, 255); 161 strncpy(args.output, temp, 255);
161 } 162 }
162 if (strcmp(args.type, "veg") == 0) { 163 if (strcmp(args.type, "veg") == 0) {