annotate src/main.c @ 85:1acd477da42f

posix: improvements
author Paper <paper@paper.us.eu.org>
date Mon, 17 Jun 2024 21:18:37 -0400
parents c06dcab17923
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include <stdio.h>
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
2 #include <stdint.h>
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include <stdlib.h>
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
4 #include <stdarg.h>
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <string.h>
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
6
13
a4e604789e2e Multiple changes
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7 #include <getopt.h>
42
d873a04165f9 use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 16
diff changeset
8 #include <libgen.h>
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
9
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
10 #include "common.h"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
11
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
12 /* non-portable functions */
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
13 static char* msvpvf_internal_strdup(const char* str) {
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
14 size_t len = strlen(str) + 1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
15
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
16 char* copy = malloc(len);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
17 if (!copy)
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
18 return NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
19
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
20 memcpy(copy, str, len);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
21 return copy;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
22 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
23
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
24 static char *msvpvf_internal_asnprintf(const char *format, ...) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
25 va_list args;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
26 int needed_size;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
27 char *output = NULL;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
28
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
29 va_start(args, format);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
30
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
31 needed_size = vsnprintf(NULL, 0, format, args);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
32 if (needed_size < 0)
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
33 return NULL;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
34
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
35 va_end(args);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
36
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
37 output = malloc((needed_size + 1) * sizeof(char));
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
38 if (!output)
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
39 return NULL;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
40
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
41 va_start(args, format);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
42
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
43 needed_size = vsnprintf(output, needed_size + 1, format, args);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
44 if (needed_size < 0) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
45 free(output);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
46 return NULL;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
47 }
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
48
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
49 va_end(args);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
50
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
51 return output;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
52 }
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
53
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
54 /* source needs read permissions, target needs write permissions, both must be in binary mode */
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
55 static int copy_file(FILE* source, FILE* target) {
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
56 char ch[4096];
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
57
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
58 while (!feof(source)) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
59 size_t b = fread(ch, 1, sizeof(ch), source);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
60 if (b)
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
61 fwrite(ch, 1, b, target);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
62 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
63
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
64 return 0;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
65 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
66
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
67 static const char* type_names[] = {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
68 [TYPES_VF] = "Movie Studio",
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
69 [TYPES_VEG] = "Vegas Pro",
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
70 [TYPES_UNKNOWN] = "Unknown",
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
71 };
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
72
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
73 static const char* type_extensions[] = {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
74 [TYPES_VF] = "vf",
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
75 [TYPES_VEG] = "veg",
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
76 };
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
77
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
78 #ifndef ARRAYSIZE
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
79 #define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80 #endif
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
82 static const char* help_text =
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
83 "msvpvf help text\n"
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
84 "author: Paper <paper@paper.us.eu.org>\n"
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
85 "usage: %s <input>... (arguments)\n"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
86 "\n"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
87 "arguments:\n"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
88 " -t, --type one of [vf,veg] (required)\n"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
89 " -v, --version version to convert to (required)\n"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
90 " -h, --help show this screen (optional)\n";
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
91
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92 static struct option options_long[] = {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 {"version", required_argument, NULL, 'v'},
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 {"type", required_argument, NULL, 't'},
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
95 {"help", 0, NULL, 'h'},
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96 };
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
98 int main(int argc, char *argv[]) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
99 uint8_t version = 0;
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
100 enum types type = TYPES_VEG; /* ...? */
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
102 int c;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
103 int option_index = 0;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
104 while ((c = getopt_long(argc, argv, "v:t:h", options_long, &option_index)) != -1) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
105 /* option argument */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
106 switch (c) {
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 case 'v':
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
108 version = atoi(optarg);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 case 't':
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
111 if (!strcmp(optarg, "vf")) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
112 type = TYPES_VF;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
113 } else if (!strcmp(optarg, "veg")) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
114 type = TYPES_VEG;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
115 } else {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
116 fprintf(stderr, "[ERROR]: Received an invalid type parameter!\n");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
117 printf(help_text, argv[0]);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
118 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
119
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
120 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
121 case 'h':
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122 default:
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
123 printf(help_text, argv[0]);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
124 break;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
127
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
128 if (argc <= optind) {
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
129 fprintf(stderr, "[ERROR]: Missing input file(s)!\n");
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
130 printf(help_text, argv[0]);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
133
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
134 if (!version || !type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
135 printf(help_text, (argc > 0) ? argv[0] : "msvpvf");
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
138
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
139 while (optind < argc) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
140 const char* input = argv[optind++];
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
141 FILE *input_file, *output_file = NULL;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
142 uint8_t file_version = 0;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
143 enum types file_type = TYPES_UNKNOWN;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
144
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
145 printf("Input file name: %s\n", input);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
146
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
147 /* print information about the input file */
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
148 input_file = fopen(input, "rb");
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
149 if (!input_file) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
150 fprintf(stderr, "[ERROR]: Error opening input file %s!\n\n", input);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
151 continue;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
152 }
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
153
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
154 if (fgetc(input_file) == EOF) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
155 fprintf(stderr, "[ERROR]: Input file \"%s\" is empty.\n", input);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
156 fclose(input_file);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
157 continue;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
158 }
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
159
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
160 if (get_file_information(input_file, &file_version, &file_type)) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
161 fprintf(stderr, "[ERROR]: Failed to get file information for input file \"%s\"!\n", input);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
162 fclose(input_file);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
163 continue;
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
164 }
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
165
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
166 printf("Input file version: %u\n", file_version);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
167 printf("Input file type: %s\n\n", type_names[file_type]);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
168
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
169 {
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
170 /* open the output file... */
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
171 char* basec = msvpvf_internal_strdup(input);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
172 char* bname = basename(basec);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
173 int ext = strrchr(bname, '.') - bname;
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
174
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
175 char *output = msvpvf_internal_asnprintf("V%u_%.*s.%s", version, ext, bname, type_extensions[type]);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
176 if (!output) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
177 fprintf(stderr, "[ERROR]: msvpvf_internal_asnprintf failed!\n");
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
178 free(basec);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
179 free(output);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
180 fclose(input_file);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
181 continue;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
182 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
183
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
184 output_file = fopen(output, "w+b");
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
185 if (!output_file) {
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
186 fprintf(stderr, "[ERROR]: Failed to open output file %s! Do you have write permissions?\n", output);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
187 free(basec);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
188 free(output);
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
189 fclose(input_file);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
190 continue;
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
191 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
192
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
193 free(basec);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
194 free(output);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
195 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
196
85
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
197 copy_file(input_file, output_file);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
198
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
199 fflush(stdout);
1acd477da42f posix: improvements
Paper <paper@paper.us.eu.org>
parents: 81
diff changeset
200 fclose(input_file);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
201
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
202 set_file_information(output_file, version, type);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
203 fclose(output_file);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
204 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 58
diff changeset
205
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
206 return 0;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
207 }