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