5
5
#include <stdio.h>
6
6
#include <stdlib.h>
7
7
#include <string.h>
8
+ #include <sys/types.h>
9
+ #include <unistd.h>
10
+ #include <dirent.h>
11
+ #include <errno.h>
8
12
9
13
#include "patient.h"
10
14
#include "list.h"
13
17
14
18
#include "Hashtable.h"
15
19
#include "HelpFunctions.h"
20
+ #include "process_synchronization.h"
16
21
17
22
18
23
void split_line (char * * split_line , char * line )
@@ -35,11 +40,12 @@ void split_line (char ** split_line, char * line)
35
40
}
36
41
void read_file (char * path , List * listptr , Hashtable * diseases , Hashtable * countries )
37
42
{
43
+
38
44
FILE * FD = fopen (path , "r" );
39
45
if (FD == NULL )
40
- {
41
- perror ( "Fopen" );
42
- }
46
+ perror ( "Error fopen" );
47
+
48
+
43
49
44
50
char * line = malloc (512 );
45
51
char * * line_ptr = & line ;
@@ -76,4 +82,84 @@ void read_file(char * path, List * listptr, Hashtable * diseases, Hashtable * co
76
82
fclose (FD );
77
83
78
84
85
+
79
86
}
87
+
88
+
89
+ /*This Function reads a directory and returns a 2d array with all files inside a directory */
90
+ char * * open_directories (char * path , int * number_files )
91
+ {
92
+ /*Directory structures */
93
+ DIR * folder ;
94
+ struct dirent * entry ;
95
+
96
+ /*Open Directory */
97
+ folder = opendir (path );
98
+ if (folder == NULL )
99
+ {
100
+ perror ("Unable to read directory" );
101
+ exit (2 );
102
+ }
103
+ /*Count Files of Directory */
104
+ * number_files = 0 ;
105
+ while ( (entry = readdir (folder )) )
106
+ * number_files = * number_files + 1 ;
107
+ * number_files = * number_files - 2 ;
108
+
109
+ closedir (folder );
110
+
111
+ /*Create a 2d array to store all files between a directory*/
112
+ char * * directory_files = malloc (sizeof (char * )* (* number_files ) );
113
+ for (int i = 0 ; i < * number_files ; i ++ )
114
+ directory_files [i ]= malloc (512 );
115
+
116
+ folder = opendir (path );
117
+ if (folder == NULL )
118
+ {
119
+ perror ("Unable to read directory" );
120
+ exit (2 );
121
+ }
122
+ int index = 0 ;
123
+ while ( (entry = readdir (folder )) )
124
+ {
125
+ if (strcmp (entry -> d_name , "." )!= 0 && strcmp (entry -> d_name , ".." )!= 0 )
126
+ {
127
+ strcpy (directory_files [index ], path );
128
+ strcpy (directory_files [index ]+ strlen (directory_files [index ])+ 1 , entry -> d_name );
129
+ directory_files [index ][strlen (directory_files [index ])] = '/' ;
130
+
131
+ //printf("%s\n",directory_files[index]);
132
+ index ++ ;
133
+
134
+ }
135
+ }
136
+ closedir (folder );
137
+
138
+ return directory_files ;
139
+
140
+ }
141
+
142
+
143
+
144
+
145
+
146
+
147
+ void * command_prompt ()
148
+ {
149
+ char * error ;
150
+ printf ("Give command:" );
151
+
152
+ char * command = malloc (512 );
153
+ error = fgets (command , 512 , stdin );
154
+ if (error == NULL )
155
+ printf ("FOUND the bufg\n" );
156
+
157
+ command [strlen (command ) - 1 ] = '\0' ;
158
+
159
+ return command ;
160
+
161
+
162
+
163
+
164
+
165
+ }
0 commit comments