-
Notifications
You must be signed in to change notification settings - Fork 1
/
opts.c
80 lines (75 loc) · 1.79 KB
/
opts.c
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
//
// opts.c
// assign1
//
// Created by Baoxu Shi on 13-8-30.
// Copyright (c) 2013年 Baoxu Shi. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "constants.h"
int opts(int argc, char **argv, char **file_list, int *cores, int *block_size, int **thread)
{
u_int32_t i;
u_int16_t file_cnt;
struct stat sb;
short rtn;
file_cnt = 0;
rtn = 1;
**thread = 1;
if (argc <= 0)
{
rtn = 0;
}
else
{
for (i = 1; i < argc; i++)
{
//options
if (argv[i][0] == '-')
{
if (!strcmp(argv[i],"-dupvote"))
{
rtn = 2;
}
else if (!strcmp(argv[i],"-cores"))
{
i += 1;
(*cores) = atoi(argv[i]);
}
else if (!strcmp(argv[i],"-blocksize"))
{
i += 1;
(*block_size) = atoi(argv[i]);
}
else
{
printf("[error] %s is not supported.\n", argv[i]);
rtn = 0;
}
}
else
{
file_list[file_cnt++] = argv[i];
if(stat(argv[i],&sb) == -1)
{
rtn = 0;
printf("[error] %s is not a valid path\n", argv[i]);
}
else
{
if(sb.st_size>=MAX_SIZE_PRE_FILE)
{
(**thread)++;
printf("thread %d \n", **thread);
}
}
}
}
}
return rtn;
}