-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathios.cpp
104 lines (83 loc) · 1.89 KB
/
ios.cpp
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
#include "ios.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
extern char * program_invocation_name;
char *invertLookupLimit(char *source, char *stop)
{
int length = strlen(source), max = 0, i = length;
char tmp[length];
strcpy(tmp, source);
while (i>-1) {
if (tmp[i] == *stop) {
i = 0;
} else {
max++;
}
i--;
}
char *output = new char;
char tmpout[max];
i = 0;
while (i<max) {
tmpout[i] = tmp[(length +1 - max)+i];
i++;
}
strcpy(output, tmpout);
return output;
}
namespace ios {
IOS::IOS()
{
char *str = new char;
cuserid(str);
char* pPath;
pPath = program_invocation_name;
if (pPath!=nullptr) {
char name[strlen(str)];
strcpy(name, str);
char appName[strlen(invertLookupLimit(pPath, "/"))];
strcpy(appName, invertLookupLimit(pPath, "/"));
char outputFile[500] = "/home/";
strcat(outputFile, name);
strcat(outputFile, "/Desktop/");
strcat(outputFile, appName);
strcat(outputFile, "_log.txt");
streaming.open(outputFile, std::ios_base::app);
}
}
IOS::~IOS()
{
if (this->streaming.is_open()) {
streaming.close();
}
}
IOS *IOS::instance()
{
static IOS *ios = new IOS;
return ios;
}
void IOS::output(const char *c)
{
IOS::instance()->streaming << c;
IOS::instance()->streaming.flush();
}
void IOS::output(void *ptr)
{
IOS::instance()->streaming << ptr;
IOS::instance()->streaming.flush();
}
void IOS::output(const int i)
{
IOS::instance()->streaming << i;
IOS::instance()->streaming.flush();
}
void IOS::setOutputFile(const char *file)
{
if (IOS::instance()->streaming.is_open()) {
IOS::instance()->streaming.close();
}
IOS::instance()->streaming.open(file);
}
}