-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.cpp
More file actions
60 lines (60 loc) · 1.97 KB
/
options.cpp
File metadata and controls
60 lines (60 loc) · 1.97 KB
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
#include <stdio.h>
#include <unistd.h>
#include "options.h"
//-------------------------------------------------------------------------------------------------
COptions options;
//-------------------------------------------------------------------------------------------------
static inline void print_usage()
{
fprintf(stderr, "Usage: csv2dxf [-KL] [-s skip_lines] [-r round_to_digits] [-l label_template] {source_file} {destination_file}\n");
}
//-------------------------------------------------------------------------------------------------
int cmd_options(int argc, char *argv[])
{
if(argc < 3)
{
fprintf(stderr, "Not enough parameters\n");
print_usage();
return 1;
}
options.csv_file_name = argv[argc - 2];
options.dxf_file_name = argv[argc - 1];
options.dxf_version = DL_Codes::AC1009;
int opt;
char *endptr = NULL;
while((opt = getopt(argc, argv, "KLs:r:l:")) != -1)
{
switch(opt)
{
case 'K':
options.split_by_code = true;
break;
case 'L':
options.split_labels = true;
break;
case 's':
options.skip_first_lines = strtol(optarg, &endptr, 10);
if(*endptr)
{
fprintf(stderr, "Invalid value for parameter -s\n");
print_usage();
return 1;
}
break;
case 'r':
options.round_digits = strtol(optarg, &endptr, 10);
if(*endptr)
{
fprintf(stderr, "Invalid value for parameter -r\n");
print_usage();
return 1;
}
break;
case 'l':
options.custom_label = optarg;
break;
}
}
return 0;
}
//-------------------------------------------------------------------------------------------------