Skip to content

Commit 13a9d47

Browse files
committed
toBranch
1 parent dcb5f22 commit 13a9d47

29 files changed

+184
-7
lines changed

.gitignore

100644100755
File mode changed.

CMakeLists.txt

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ include_directories(${CMAKE_SOURCE_DIR}/linux/include)
1818
link_directories(${CMAKE_SOURCE_DIR}/linux/lib)
1919

2020

21-
add_executable(gopher main.c general/lib/utils/utils.c general/include/utils.h)
21+
add_executable(gopher main.c general/lib/utils/utils.c general/include/utils.h general/lib/io/config_file.c general/include/config_file.h linux/lib/io/gopher_server_configuration_linux.c linux/include/gopher_server_configuration_linux.h linux/lib/utils/utils.c linux/include/utils.h general/lib/portable/portables.c general/include/portables.h)

general/.gitkeep

Whitespace-only changes.

general/include/.gitkeep

Whitespace-only changes.

general/include/config_file.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by andreabacciu on 6/6/19.
3+
//
4+
5+
#ifndef PROJECT_CONFIG_FILE_H
6+
#define PROJECT_CONFIG_FILE_H
7+
8+
#endif //PROJECT_CONFIG_FILE_H

general/include/portables.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Created by valerioneri on 6/6/19.
3+
//
4+
5+
#ifndef GOPHER_PORTABLES_H
6+
#define GOPHER_PORTABLES_H
7+
8+
#endif //GOPHER_PORTABLES_H
9+
10+
11+
int po_cd(char* path);

general/include/utils.h

100644100755
+5-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
void print(int i);
99
int mul(int a);
1010
int mul2(int a, int b);
11-
11+
int utParseConfigurationFile(char *path);
1212
#endif //GOPHER_UTILS_H
13+
14+
15+
16+

general/keep.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for D in `find . -type d`
2+
do
3+
touch ${D}/.gitkeep
4+
done

general/lib/.gitkeep

Whitespace-only changes.

general/lib/gopher/.gitkeep

Whitespace-only changes.

general/lib/io/.gitkeep

Whitespace-only changes.

general/lib/io/config_file.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Created by andreabacciu on 6/6/19.
3+
//
4+
5+
#include "config_file.h"
6+
#ifdef __unix__
7+
#endif
8+
/*
9+
int utParseConfigurationFile(char *path) {
10+
FILE *file = fopen(path, "r");
11+
int CUR_MAX = 4095;
12+
char *buffer = (char*) malloc(sizeof(char) * CUR_MAX); // allocate buffer.
13+
char currentline[BASEVALUE];
14+
v
15+
if (file != NULL) {
16+
return 1;
17+
}
18+
19+
while (fgets(buffer, sizeof(char) * BASEVALUE, file) != NULL) {
20+
fprintf(stderr, "got line: %s\n", buffer);
21+
}
22+
(void) fclose(file);
23+
return EXIT_SUCCESS;
24+
}
25+
26+
27+
28+
*/
29+
30+
void keep(){}
31+

general/lib/lock/.gitkeep

Whitespace-only changes.

general/lib/logs/.gitkeep

Whitespace-only changes.

general/lib/memory_mapping/.gitkeep

Whitespace-only changes.

general/lib/portable/.gitkeep

Whitespace-only changes.

general/lib/portable/portables.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Created by valerioneri on 6/6/19.
3+
//
4+
5+
#include "portables.h"
6+
#include "gopher_server_configuration_linux.h"
7+
8+
int po_cd(char* path){
9+
10+
return 0;
11+
}

general/lib/process/.gitkeep

Whitespace-only changes.

general/lib/signals/.gitkeep

Whitespace-only changes.

general/lib/socket/.gitkeep

Whitespace-only changes.

general/lib/thead/.gitkeep

Whitespace-only changes.

general/lib/utils/.gitkeep

Whitespace-only changes.

general/lib/utils/utils.c

100644100755
+12-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@
44

55
#include <stdio.h>
66
#include "utils.h"
7+
#include <stdlib.h>
78

8-
void print(int i){
9+
#include "config_file.h"
10+
11+
#ifdef __unix__
12+
13+
#include "gopher_server_configuration_linux.h"
14+
15+
#endif
16+
17+
void print(int i) {
918
printf("%d\n", i);
1019
}
1120

12-
int mul(int a){
21+
int mul(int a) {
1322
return a * 2;
1423
}
1524

25+

gopher_server_configuration.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
port 70
2+
mode_concurrency Thread
3+
root_dir /opt/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by andreabacciu on 6/6/19.
3+
//
4+
5+
#ifndef GOPHER_GOPHER_SERVER_CONFIGURATION_LINUX_H
6+
#define GOPHER_GOPHER_SERVER_CONFIGURATION_LINUX_H
7+
8+
#endif //GOPHER_GOPHER_SERVER_CONFIGURATION_LINUX_H

linux/include/utils.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by andreabacciu on 6/6/19.
3+
//
4+
5+
#ifndef GOPHER_UTILS_H
6+
#define GOPHER_UTILS_H
7+
int __cd(char* path);
8+
#endif //GOPHER_UTILS_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Created by andreabacciu on 6/6/19.
3+
//
4+
5+
#include "gopher_server_configuration_linux.h"
6+
#include <zconf.h>
7+
8+
int __cd(char* path){
9+
return chdir(path);
10+
}
11+
12+
13+
14+
15+

linux/lib/utils/utils.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by andreabacciu on 6/6/19.
3+
//
4+
5+
#include "utils.h"
6+
7+
8+

main.c

100644100755
+59-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
11
#include <stdio.h>
2-
#include "utils.h"
2+
#include <getopt.h>
3+
#include <stdlib.h>
4+
#include <memory.h>
5+
#include <assert.h>
6+
7+
//#include "utils.h"
8+
9+
// reformat Sh + ò
10+
// comment Sh + ù
11+
// run Sh + Enter
12+
// Ctrl + Enter
13+
14+
struct Configs {
15+
int port_number;
16+
char* mode_concurrency;
17+
char* root_dir;
18+
} configs;
19+
20+
void help(){
21+
char* helpString = "";
22+
printf("%s\n", helpString);
23+
}
24+
25+
int main(int argc, char *argv[]) {
26+
27+
int opt;
28+
29+
configs.root_dir = malloc(50 * sizeof(char));
30+
31+
// chiamata alla lettura del file di configurazione
32+
33+
while((opt = getopt(argc, argv, "m:d:p:")) != -1)
34+
{
35+
switch(opt)
36+
{
37+
case 'p':
38+
printf("%s \n", optarg);
39+
configs.port_number = atoi(optarg);
40+
break;
41+
case 'm':
42+
assert(strcmp(optarg, "Thread") != 0 || strcmp(optarg, "Process") != 0);
43+
configs.mode_concurrency = optarg;
44+
break;
45+
case 'd':
46+
configs.root_dir = optarg;
47+
break;
48+
case '?':
49+
if (optopt == 'c')
50+
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
51+
else
52+
fprintf (stderr,
53+
"Unknown option character `\\x%x'.\n",
54+
optopt);
55+
return 1;
56+
}
57+
}
58+
59+
printf("%d %s %s\n", configs.port_number, configs.mode_concurrency, configs.root_dir);
60+
361

4-
int main() {
562
printf("Hello, World!\n");
6-
print(mul(4));
763
// print(mul2(4, 5));
864
return 0;
965
}

0 commit comments

Comments
 (0)