-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (67 loc) · 1.71 KB
/
main.cpp
File metadata and controls
79 lines (67 loc) · 1.71 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
#include <chrono>
#include <cstdio>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sys/time.h>
#include <unistd.h>
#include "Controller/Parser/command_parser.hpp"
extern std::FILE *command_in;
int main(int argc, char *arg[]) {
// Reading the input and put it in string _all_arg
std::string _all_arg;
for (int i = 1; i < argc; i++) {
_all_arg += arg[i];
if (i != argc - 1) {
_all_arg += "\n";
} else {
_all_arg += "\n;";
}
}
// Generating the temp file pFile
std::FILE *pFile;
pFile = tmpfile(); // c++ function for generating a temporary file
std::fputs(_all_arg.c_str(), pFile); // Write _all_arg in pFile
rewind(pFile); // Sets the position indicator associated with stream to the
// beginning of the file.
command_in = pFile; // Set command_in equals to pFile
/* Test to print the content of command_in
char buffer [256];
while (!feof(command_in)) {
if (fgets (buffer,256,command_in) == NULL) break;
fputs (buffer,stdout);
}
rewind(pFile);
*/
/* Test for checking the directory of the temporary file
int MAXSIZE = 0xFFF;
char proclnk[0xFFF];
char filename[0xFFF];
FILE *fp;
int fno;
ssize_t r;
fp = pFile;
if (fp != NULL)
{
fno = fileno(fp);
sprintf(proclnk, "/proc/self/fd/%d", fno);
r = readlink(proclnk, filename, MAXSIZE);
if (r < 0)
{
printf("failed to readlink\n");
exit(1);
}
filename[r] = '\0';
printf("fp -> fno -> filename: %p -> %d -> %s\n",
fp, fno, filename);
}
*/
// Calling the input parser
int result_arg = 10;
std::string width_type;
int width_value;
result_arg = command_parse(result_arg, width_type, width_value);
fclose(command_in); // closing command_in
return 0;
}