Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
unix
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
tu-wien
unix
Commits
f36156d4
Commit
f36156d4
authored
Dec 16, 2018
by
Ivaylo Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix splitting bug
parent
5d438703
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
cpair/cpair.c
cpair/cpair.c
+22
-20
No files found.
cpair/cpair.c
View file @
f36156d4
...
@@ -134,12 +134,12 @@ int main(int argc, char *argv[]) {
...
@@ -134,12 +134,12 @@ int main(int argc, char *argv[]) {
close
(
in_pipe_a
[
1
]);
close
(
in_pipe_a
[
1
]);
close
(
STDIN_FILENO
);
close
(
STDIN_FILENO
);
if
(
dup2
(
in_pipe_a
[
0
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
if
(
dup2
(
in_pipe_a
[
0
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN"
);
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
execlp
(
argv
[
0
],
argv
[
0
],
NULL
);
execlp
(
argv
[
0
],
argv
[
0
],
NULL
);
fprintf
(
stderr
,
"ERROR: Failed to load program into child"
);
fprintf
(
stderr
,
"ERROR: Failed to load program into child
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
default:
default:
/// Parent execution
/// Parent execution
...
@@ -154,12 +154,12 @@ int main(int argc, char *argv[]) {
...
@@ -154,12 +154,12 @@ int main(int argc, char *argv[]) {
close
(
in_pipe_b
[
1
]);
close
(
in_pipe_b
[
1
]);
close
(
STDIN_FILENO
);
close
(
STDIN_FILENO
);
if
(
dup2
(
in_pipe_b
[
0
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
if
(
dup2
(
in_pipe_b
[
0
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN"
);
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
execlp
(
argv
[
0
],
argv
[
0
],
NULL
);
execlp
(
argv
[
0
],
argv
[
0
],
NULL
);
fprintf
(
stderr
,
"ERROR: Failed to load program into child"
);
fprintf
(
stderr
,
"ERROR: Failed to load program into child
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
default:
default:
/// Parent execution
/// Parent execution
...
@@ -180,14 +180,16 @@ int main(int argc, char *argv[]) {
...
@@ -180,14 +180,16 @@ int main(int argc, char *argv[]) {
/// Separate the lists based on the mean
/// Separate the lists based on the mean
current
=
head
;
current
=
head
;
while
(
current
!=
NULL
)
{
while
(
current
->
next
!=
NULL
)
{
if
(
current
->
points
[
0
]
<=
x_mean
)
{
if
(
current
->
points
[
0
]
<=
x_mean
)
{
first_part_buff
->
points
[
0
]
=
current
->
points
[
0
];
first_part_buff
->
points
[
0
]
=
current
->
points
[
0
];
first_part_buff
->
points
[
1
]
=
current
->
points
[
1
];
first_part_buff
->
next
=
malloc
(
sizeof
(
node_t
));
first_part_buff
->
next
=
malloc
(
sizeof
(
node_t
));
first_part_buff
=
first_part_buff
->
next
;
first_part_buff
=
first_part_buff
->
next
;
first_part_len
++
;
first_part_len
++
;
}
else
{
}
else
{
second_part_buff
->
points
[
0
]
=
current
->
points
[
0
];
second_part_buff
->
points
[
0
]
=
current
->
points
[
0
];
second_part_buff
->
points
[
1
]
=
current
->
points
[
1
];
second_part_buff
->
next
=
malloc
(
sizeof
(
node_t
));
second_part_buff
->
next
=
malloc
(
sizeof
(
node_t
));
second_part_buff
=
second_part_buff
->
next
;
second_part_buff
=
second_part_buff
->
next
;
second_part_len
++
;
second_part_len
++
;
...
@@ -200,22 +202,22 @@ int main(int argc, char *argv[]) {
...
@@ -200,22 +202,22 @@ int main(int argc, char *argv[]) {
* Send first half to first child
* Send first half to first child
*
*
**/
**/
if
(
dup2
(
in_pipe_a
[
1
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
/// Setup string for first child pipe
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN"
);
exit
(
EXIT_FAILURE
);
}
/// Setup string for pipe
current
=
first_part
;
current
=
first_part
;
char
first_part_string
[
first_part_len
+
1
][
__UINT8_MAX__
];
char
first_part_string
[
first_part_len
][
__UINT8_MAX__
];
int
i
=
0
;
int
i
=
0
;
while
(
current
!=
NULL
)
{
while
(
current
->
next
!=
NULL
)
{
sprintf
(
first_part_string
[
i
],
"%f %f
\n
"
,
current
->
points
[
0
],
current
->
points
[
1
]);
sprintf
(
first_part_string
[
i
],
"%f %f
\n
"
,
current
->
points
[
0
],
current
->
points
[
1
]);
i
++
;
i
++
;
current
=
current
->
next
;
current
=
current
->
next
;
}
}
first_part_string
[
first_part_len
][
0
]
=
EOF
;
first_part_string
[
first_part_len
][
0
]
=
EOF
;
if
(
dup2
(
in_pipe_a
[
1
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN
\n
"
);
exit
(
EXIT_FAILURE
);
}
/// Write to pipe
/// Write to pipe
if
(
write
(
in_pipe_a
[
1
],
first_part_string
,
first_part_len
*
__UINT8_MAX__
)
<
0
)
{
if
(
write
(
in_pipe_a
[
1
],
first_part_string
,
first_part_len
*
__UINT8_MAX__
)
<
0
)
{
fprintf
(
stderr
,
"ERROR: Failed writing to child
\n
"
);
fprintf
(
stderr
,
"ERROR: Failed writing to child
\n
"
);
...
@@ -228,22 +230,22 @@ int main(int argc, char *argv[]) {
...
@@ -228,22 +230,22 @@ int main(int argc, char *argv[]) {
* Send second half to second child
* Send second half to second child
*
*
**/
**/
if
(
dup2
(
in_pipe_b
[
1
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
/// Setup string for second child pipe
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN
\n
"
);
exit
(
EXIT_FAILURE
);
}
/// Setup string for pipe
current
=
second_part
;
current
=
second_part
;
char
second_part_string
[
second_part_len
+
1
][
__UINT8_MAX__
];
char
second_part_string
[
second_part_len
+
1
][
__UINT8_MAX__
];
i
=
0
;
i
=
0
;
while
(
current
!=
NULL
)
{
while
(
current
->
next
!=
NULL
)
{
sprintf
(
second_part_string
[
i
],
"%f %f
\n
"
,
current
->
points
[
0
],
current
->
points
[
1
]);
sprintf
(
second_part_string
[
i
],
"%f %f
\n
"
,
current
->
points
[
0
],
current
->
points
[
1
]);
i
++
;
i
++
;
current
=
current
->
next
;
current
=
current
->
next
;
}
}
second_part_string
[
second_part_len
][
0
]
=
EOF
;
second_part_string
[
second_part_len
][
0
]
=
EOF
;
if
(
dup2
(
in_pipe_b
[
1
],
STDIN_FILENO
)
!=
STDIN_FILENO
)
{
fprintf
(
stderr
,
"ERROR: Failed duplicating STDIN
\n
"
);
exit
(
EXIT_FAILURE
);
}
/// Write to pipe
/// Write to pipe
if
(
write
(
in_pipe_b
[
1
],
second_part_string
,
second_part_len
*
__UINT8_MAX__
)
<
0
)
{
if
(
write
(
in_pipe_b
[
1
],
second_part_string
,
second_part_len
*
__UINT8_MAX__
)
<
0
)
{
fprintf
(
stderr
,
"ERROR: Failed writing to child
\n
"
);
fprintf
(
stderr
,
"ERROR: Failed writing to child
\n
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment