forked from Baael/moxa-nport-driver-3.11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mxcfmat.c
102 lines (87 loc) · 2.14 KB
/
mxcfmat.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "nport.h"
#include <string.h>
#include <stdlib.h>
#define ER_ARG -10
#define ARGUMENT_NUM 11
int main(int arg, char *argv[])
{
int i, j, len, flag;
char *tmpstr, *token, *minor_token, *chk;
char delim[] = " \t";
char major[20];
FILE *f, *ft;
tmpstr = (char *)malloc(256);
len = 256;
token = (char *)malloc(256);
sprintf(tmpstr, "%s/npreal2d.cf", DRIVERPATH);
f = fopen (tmpstr, "r");
if (f == NULL)
{
printf("file open error1\n");
free(tmpstr);
free(token);
return(0);
}
ft = fopen ("/tmp/npr_tmpfile3", "w");
if (ft == NULL)
{
printf("file open error2\n");
free(tmpstr);
free(token);
return(0);
}
for (;;)
{
flag = 0;
memset(token, '\0', 256);
if (getline (&tmpstr, &len, f) < 0)
{
break;
}
if (strstr(tmpstr, "#") != NULL)
{
fputs (tmpstr, ft);
continue;
}
memset(major, '\0', 20);
sscanf(tmpstr, "%s", major);
if (strstr(major, "ttymajor") != NULL ||
strstr(major, "calloutmajor") != NULL )
{
// printf("number = [%d]\n", atoi(strstr(major, "=")+1));
fputs (tmpstr, ft);
continue;
}
for (i=0; i<ARGUMENT_NUM; i++)
{
if (i==0)
{
minor_token = strtok(tmpstr, delim); // [minor]
sprintf(token, "%s", minor_token);
}
else
{
chk = strtok(NULL, delim);
if (chk == NULL)
{
flag = 1;
break;
}
sprintf(token, "%s\t%s", token, chk); // [Nport IP]
}
}
if (flag == 1)
{
continue;
}
fputs (token, ft);
}
fclose(ft);
fclose(f);
sprintf(tmpstr, "cp -f /tmp/npr_tmpfile3 %s/npreal2d.cf", DRIVERPATH);
system(tmpstr);
system("rm -f /tmp/npr_tmpfile3");
free(tmpstr);
free(token);
return 0;
}