forked from YogeshJangir/token-bucket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.c
More file actions
95 lines (91 loc) · 2.81 KB
/
Copy pathtoken.c
File metadata and controls
95 lines (91 loc) · 2.81 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
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
//
// main.c
// Warmup2-new
//
// Created by Abhishek Trigunayat on 6/12/14.
// Copyright (c) 2014 Abhishek Trigunayat. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "mylist.h"
#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
#include "token.h"
int main(int argc, char *argv[])
{
float lambda=0.5,mu=0.35,r=1.5;
long B=10,P=3,num=20;
char * tsfile = NULL;
int i=1;
for(i=1;i<argc;i++){
if(strcmp("-lambda", argv[i])==0){
if(i!=argc && strstr(argv[i+1],"-")==NULL){
lambda = atof(argv[i+1]);
}
else{
fprintf(stderr,"Please provide a valid value with -lambda argument, else remove -lambda to use default value\n");
exit(1);
}
}
if(strcmp("-mu", argv[i])==0){
if(i!=argc && strstr(argv[i+1],"-")==NULL){
mu = atof(argv[i+1]);
}
else{
fprintf(stderr,"Please provide a valid value with -mu argument, else remove -mu to use default value\n");
exit(1);
}
}
if(strcmp("-r", argv[i])==0){
if(i!=argc && strstr(argv[i+1],"-")==NULL){
r = atof(argv[i+1]);
}
else{
fprintf(stderr,"Please provide a valid value with -r argument, else remove -r to use default value\n");
exit(1);
}
}
if(strcmp("-B", argv[i])==0){
if(i!=argc && strstr(argv[i+1],"-")==NULL){
B = atol(argv[i+1]);
}
else{
fprintf(stderr,"Please provide a valid value with -B argument, else remove -B to use default value\n");
exit(1);
}
}
if(strcmp("-P", argv[i])==0){
if(i!=argc && strstr(argv[i+1],"-")==NULL){
P = atof(argv[i+1]);
}
else{
fprintf(stderr,"Please provide a valid value with -P argument, else remove -P to use default value\n");
exit(1);
}
}
if(strcmp("-n", argv[i])==0){
if(i!=argc && strstr(argv[i+1],"-")==NULL){
num = atof(argv[i+1]);
}
else{
fprintf(stderr,"Please provide a valid value with -num argument, else remove -num to use default value\n");
exit(1);
}
}
if(strcmp("-t", argv[i])==0){
if(i!=argc){
tsfile = malloc(sizeof(argv[i+1]));
strcpy(tsfile,argv[i+1]);
}
else{
fprintf(stderr,"Please provide a file name with -t argument");
exit(1);
}
}
}
process(lambda,mu,r,B,P,num,tsfile);
return 0;
}