-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.c
More file actions
118 lines (99 loc) · 1.89 KB
/
reader.c
File metadata and controls
118 lines (99 loc) · 1.89 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "queueModule.h"
#include "constants.h"
#include <string.h>
void *reader( void *readerQueue){
char *ch = (char*)calloc(1,sizeof(char));
char *buffer = (char*)calloc(BUFF_SIZE,sizeof(char));
char *temp;
int index, i;
index = 0;
// Read the stdin
while((*ch = fgetc(stdin)) != EOF){
/*
if(index > BUFF_SIZE) {
fprintf(stderr,"LINE TOOOOO BIGG");
exit(EXIT_FAILURE);
}
else if(*ch == '\n' && index <= BUFF_SIZE)
{
temp = (char*)calloc(BUFF_SIZE,sizeof(char));
for(i = 0; i < BUFF_SIZE; i++)
{
temp[i] = buffer[i];
}
temp[i] = '\0';
+
EnqueueString((Queue*)readerQueue, temp);
index = 0;
}
else if(index > BUFF_SIZE)
{
index
}
else{
buffer[index] = *ch;
index++;
}
if(*ch == '\n' && index >= BUFF_SIZE)
{
memset((void*)buffer, 0, BUFF_SIZE );
index = 0;
}
else if(*ch == '\n' && index < BUFF_SIZE)
{
temp = (char*)calloc(BUFF_SIZE,sizeof(char));
if (temp == NULL) {
fprintf(stderr,"temp malloc in reader.c failed");
}
for(i = 0; i < BUFF_SIZE; i++)
{
temp[i] = buffer[i];
}
temp[i] = '\0';
EnqueueString((Queue*)readerQueue, temp);
memset((void*)buffer, 0, BUFF_SIZE);
index = 0;
}
else if(index < BUFF_SIZE)
{
buffer[index] = *ch;
index++;
}
else
{
index++;
}
*/
if(*ch == '\n')
{
if(index < buffsize - 1) //figure it out later
{
//enqueue
}
else
{
//ignore i
}
}
else
{
if(index <= buffsize)
{
buffer[index] = *ch;
}
index++;
}
}
char *endString = (char*)malloc(5*sizeof(char));
if (endString == NULL) {
fprintf(stderr,"malloc in reader.c failed");
}
strncpy(endString, "STOP\0", 5);
EnqueueString((Queue*)readerQueue, endString);
fprintf(stdout,"in reader before free");
//free(ch);
pthread_exit(0);
}