Mercurial > msvpvf
comparison src/main.c @ 88:af4ed765c1ac
*: add IUP GUI
a lot simpler than win32, but I assume there's more going on in
the background that I don't know about :)
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 14 Jul 2025 02:39:24 -0400 |
| parents | 1acd477da42f |
| children |
comparison
equal
deleted
inserted
replaced
| 87:2e819b84d7c0 | 88:af4ed765c1ac |
|---|---|
| 7 #include <getopt.h> | 7 #include <getopt.h> |
| 8 #include <libgen.h> | 8 #include <libgen.h> |
| 9 | 9 |
| 10 #include "common.h" | 10 #include "common.h" |
| 11 | 11 |
| 12 /* non-portable functions */ | 12 static const char *type_extensions[] = { |
| 13 static char* msvpvf_internal_strdup(const char* str) { | |
| 14 size_t len = strlen(str) + 1; | |
| 15 | |
| 16 char* copy = malloc(len); | |
| 17 if (!copy) | |
| 18 return NULL; | |
| 19 | |
| 20 memcpy(copy, str, len); | |
| 21 return copy; | |
| 22 } | |
| 23 | |
| 24 static char *msvpvf_internal_asnprintf(const char *format, ...) { | |
| 25 va_list args; | |
| 26 int needed_size; | |
| 27 char *output = NULL; | |
| 28 | |
| 29 va_start(args, format); | |
| 30 | |
| 31 needed_size = vsnprintf(NULL, 0, format, args); | |
| 32 if (needed_size < 0) | |
| 33 return NULL; | |
| 34 | |
| 35 va_end(args); | |
| 36 | |
| 37 output = malloc((needed_size + 1) * sizeof(char)); | |
| 38 if (!output) | |
| 39 return NULL; | |
| 40 | |
| 41 va_start(args, format); | |
| 42 | |
| 43 needed_size = vsnprintf(output, needed_size + 1, format, args); | |
| 44 if (needed_size < 0) { | |
| 45 free(output); | |
| 46 return NULL; | |
| 47 } | |
| 48 | |
| 49 va_end(args); | |
| 50 | |
| 51 return output; | |
| 52 } | |
| 53 | |
| 54 /* source needs read permissions, target needs write permissions, both must be in binary mode */ | |
| 55 static int copy_file(FILE* source, FILE* target) { | |
| 56 char ch[4096]; | |
| 57 | |
| 58 while (!feof(source)) { | |
| 59 size_t b = fread(ch, 1, sizeof(ch), source); | |
| 60 if (b) | |
| 61 fwrite(ch, 1, b, target); | |
| 62 } | |
| 63 | |
| 64 return 0; | |
| 65 } | |
| 66 | |
| 67 static const char* type_names[] = { | |
| 68 [TYPES_VF] = "Movie Studio", | |
| 69 [TYPES_VEG] = "Vegas Pro", | |
| 70 [TYPES_UNKNOWN] = "Unknown", | |
| 71 }; | |
| 72 | |
| 73 static const char* type_extensions[] = { | |
| 74 [TYPES_VF] = "vf", | 13 [TYPES_VF] = "vf", |
| 75 [TYPES_VEG] = "veg", | 14 [TYPES_VEG] = "veg", |
| 76 }; | 15 }; |
| 77 | 16 |
| 78 #ifndef ARRAYSIZE | |
| 79 #define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) | |
| 80 #endif | |
| 81 | |
| 82 static const char* help_text = | 17 static const char* help_text = |
| 83 "msvpvf help text\n" | 18 "msvpvf help text\n" |
| 84 "author: Paper <paper@paper.us.eu.org>\n" | 19 "author: Paper <paper@tflc.us>\n" |
| 85 "usage: %s <input>... (arguments)\n" | 20 "usage: %s <input>... (arguments)\n" |
| 86 "\n" | 21 "\n" |
| 87 "arguments:\n" | 22 "arguments:\n" |
| 88 " -t, --type one of [vf,veg] (required)\n" | 23 " -t, --type one of [vf,veg] (required)\n" |
| 89 " -v, --version version to convert to (required)\n" | 24 " -v, --version version to convert to (required)\n" |
| 166 printf("Input file version: %u\n", file_version); | 101 printf("Input file version: %u\n", file_version); |
| 167 printf("Input file type: %s\n\n", type_names[file_type]); | 102 printf("Input file type: %s\n\n", type_names[file_type]); |
| 168 | 103 |
| 169 { | 104 { |
| 170 /* open the output file... */ | 105 /* open the output file... */ |
| 171 char* basec = msvpvf_internal_strdup(input); | 106 char* basec = str_dup(input); |
| 172 char* bname = basename(basec); | 107 char* bname = basename(basec); |
| 173 int ext = strrchr(bname, '.') - bname; | 108 int ext = strrchr(bname, '.') - bname; |
| 174 | 109 |
| 175 char *output = msvpvf_internal_asnprintf("V%u_%.*s.%s", version, ext, bname, type_extensions[type]); | 110 char *output = msvpvf_asprintf("V%u_%.*s.%s", version, ext, bname, type_extensions[type]); |
| 176 if (!output) { | 111 if (!output) { |
| 177 fprintf(stderr, "[ERROR]: msvpvf_internal_asnprintf failed!\n"); | 112 fprintf(stderr, "[ERROR]: msvpvf_asprintf failed!\n"); |
| 178 free(basec); | 113 free(basec); |
| 179 free(output); | 114 free(output); |
| 180 fclose(input_file); | 115 fclose(input_file); |
| 181 continue; | 116 continue; |
| 182 } | 117 } |
