1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#include "emb-reader-writer.h"
#include "emb-logging.h"
#include "emb-format.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void usage(void)
{
EmbFormatList* formatList = 0;
EmbFormatList* curFormat = 0;
const char* extension = 0;
const char* description = 0;
char readerState;
char writerState;
int numReaders = 0;
int numWriters = 0;
printf(" _____________________________________________________________________________ \n");
printf("| _ _ ___ ___ _____ ___ ___ __ _ ___ ___ ___ _ _ |\n");
printf("| | | | | _ \\| __| | _ \\| _ \\ / \\| | \\| __| _ \\ | | | |\n");
printf("| | |_| | _ <| __| | | | _ <| /| () | | |) | __| / |__ | |\n");
printf("| |___|_|___/|___|_|_|_|___/|_|\\_\\\\__/|_|___/|___|_|\\_\\|___| |\n");
printf("| ___ __ ___ _ _ _ ___ ___ _____ |\n");
printf("| / __|/ \\| | | \\ / | __| _ \\|_ _| |\n");
printf("| ( (__| () | | | |\\ \\/ /| __| / | | |\n");
printf("| \\___|\\__/|_|___| \\__/ |___|_|\\_\\ |_| |\n");
#if defined(EMSCRIPTEN)
printf("| |\n");
printf("| * Emscripten Version * |\n");
#endif
printf("|_____________________________________________________________________________|\n");
printf("| |\n");
printf("| Usage: libembroidery-convert fileToRead filesToWrite ... |\n");
printf("|_____________________________________________________________________________|\n");
printf(" \n");
printf(" _____________________________________________________________________________ \n");
printf("| |\n");
printf("| List of Formats |\n");
printf("|_____________________________________________________________________________|\n");
printf("| |\n");
printf("| 'S' = Yes, and is considered stable. |\n");
printf("| 'U' = Yes, but may be unstable. |\n");
printf("| ' ' = No. |\n");
printf("|_____________________________________________________________________________|\n");
printf("| | | | |\n");
printf("| Format | Read | Write | Description |\n");
printf("|________|_______|_______|____________________________________________________|\n");
printf("| | | | |\n");
formatList = embFormatList_create();
if(!formatList) { embLog_error("libembroidery-convert-main.c usage(), cannot allocate memory for formatList\n"); return; }
curFormat = formatList;
while(curFormat)
{
extension = embFormat_extension(curFormat);
description = embFormat_description(curFormat);
readerState = embFormat_readerState(curFormat);
writerState = embFormat_writerState(curFormat);
numReaders += readerState != ' '? 1 : 0;
numWriters += writerState != ' '? 1 : 0;
printf("| %-4s | %c | %c | %-49s |\n", extension, readerState, writerState, description);
curFormat = curFormat->next;
}
embFormatList_free(formatList);
formatList = 0;
printf("|________|_______|_______|____________________________________________________|\n");
printf("| | | | |\n");
printf("| Total: | %3d | %3d | |\n", numReaders, numWriters);
printf("|________|_______|_______|____________________________________________________|\n");
printf("| |\n");
printf("| http://embroidermodder.org |\n");
printf("|_____________________________________________________________________________|\n");
printf("\n");
}
/* TODO: Add capability for converting multiple files of various types to a single format. Currently, we only convert a single file to multiple formats. */
/*! Developers incorporating libembroidery into another project should use the SHORT_WAY of using libembroidery. It uses
* convenience functions and is approximately 20 lines shorter than the long way.
*
* Developers who are interested improving libembroidery or using it to its fullest extent should use the LONG_WAY.
* It essentially does the same work the convenience function do.
*
* Both methods are acceptable and it is up to you which to choose. Both will stay here for regression testing.
*/
#define SHORT_WAY
int main(int argc, const char* argv[])
{
EmbPattern* p = 0;
int successful = 0, i = 0;
int formatType;
#ifdef SHORT_WAY
if(argc < 3)
{
usage();
exit(0);
}
p = embPattern_create();
if(!p) { embLog_error("libembroidery-convert-main.c main(), cannot allocate memory for p\n"); exit(1); }
successful = embPattern_read(p, argv[1]);
if(!successful)
{
embLog_error("libembroidery-convert-main.c main(), reading file %s was unsuccessful\n", argv[1]);
embPattern_free(p);
exit(1);
}
formatType = embFormat_typeFromName(argv[1]);
if(formatType == EMBFORMAT_OBJECTONLY && argc == 3) /* TODO: fix this to work when writing multiple files */
{
formatType = embFormat_typeFromName(argv[2]);
if(formatType == EMBFORMAT_STITCHONLY)
embPattern_movePolylinesToStitchList(p);
}
i = 2;
for(i = 2; i < argc; i++)
{
successful = embPattern_write(p, argv[i]);
if(!successful)
embLog_error("libembroidery-convert-main.c main(), writing file %s was unsuccessful\n", argv[i]);
}
embPattern_free(p);
return 0;
#else /* LONG_WAY */
EmbReaderWriter* reader = 0, *writer = 0;
if(argc < 3)
{
usage();
exit(0);
}
p = embPattern_create();
if(!p) { embLog_error("libembroidery-convert-main.c main(), cannot allocate memory for p\n"); exit(1); }
successful = 0;
reader = embReaderWriter_getByFileName(argv[1]);
if(!reader)
{
successful = 0;
embLog_error("libembroidery-convert-main.c main(), unsupported read file type: %s\n", argv[1]);
}
else
{
successful = reader->reader(p, argv[1]);
if(!successful) embLog_error("libembroidery-convert-main.c main(), reading file was unsuccessful: %s\n", argv[1]);
}
free(reader);
if(!successful)
{
embPattern_free(p);
exit(1);
}
formatType = embFormat_typeFromName(argv[1]);
if(formatType == EMBFORMAT_OBJECTONLY && argc == 3) /* TODO: fix this to work when writing multiple files */
{
formatType = embFormat_typeFromName(argv[2]);
if(formatType == EMBFORMAT_STITCHONLY)
embPattern_movePolylinesToStitchList(p);
}
i = 2;
for(i = 2; i < argc; i++)
{
writer = embReaderWriter_getByFileName(argv[i]);
if(!writer)
{
embLog_error("libembroidery-convert-main.c main(), unsupported write file type: %s\n", argv[i]);
}
else
{
successful = writer->writer(p, argv[i]);
if(!successful)
embLog_error("libembroidery-convert-main.c main(), writing file %s was unsuccessful\n", argv[i]);
}
free(writer);
}
embPattern_free(p);
return 0;
#endif /* SHORT_WAY */
}
/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
|