-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwc.cpp
More file actions
150 lines (129 loc) · 2.95 KB
/
wc.cpp
File metadata and controls
150 lines (129 loc) · 2.95 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "stdafx.h"
#include "util.h"
#include "fgd_identifiers.h"
using namespace std;
int is_in_wc(ifstream& iwc)
{
iwc.seekg(0, iwc.end);
unsigned int length = static_cast<int>(iwc.tellg());
iwc.seekg(0, iwc.beg);
char *buffer = new char[length];
iwc.read(buffer, length);
string extract;
for (unsigned int i = 0; i < length; i++)
{
int n = static_cast<int>(buffer[i]);
if ((n >= -1) && (n <= 255))
{
if (!iscntrl(buffer[i]) && extract.empty())
{
extract += buffer[i];
}
else if (!iscntrl(buffer[i]) && !extract.empty())
{
extract += buffer[i];
}
else if (iscntrl(buffer[i]) && !extract.empty())
{
if (extract == wc_args[0])
{
delete[] buffer;
return 0;
}
extract.clear();
}
}
}
int n = static_cast<int>(buffer[35]);
delete[] buffer;
return n;
}
bool put_in_wc(ofstream& owc, char* ente)
{
string buffer;
buffer.reserve(11388);
char null(0);
char one(1);
char num(static_cast<char>((wc_args.size() - 1) / 2));
string s = ente;
wc_args[1] = s;
int size = 0;
int length = wc_args[0].length();
buffer.replace(size, length, wc_args[0]);
size += length;
buffer.replace(size, 128 - length, 128 - length, null);
size += (128 - length);
buffer.replace(size, 1, { num });
size++;
buffer.replace(size, 3, 3, null);
size += 3;
for (unsigned int i = 1; i < wc_args.size(); i++)
{
if ((i % 2) == 1)
{
buffer.replace(size, 1, { one });
size++;
buffer.replace(size, 3, 3, null);
size += 3;
if (iscntrl(wc_args[i][0])) {buffer.replace(size, 2, wc_args[i]);}
else { buffer.replace(size, 2, 2, null); }
size += 2;
buffer.replace(size, 2, 2, null);
size += 2;
length = wc_args[i].length();
buffer.replace(size, length, wc_args[i]);
size += length;
buffer.replace(size, 260 - length, 260 - length, null);
size += (260 - length);
}
else
{
length = wc_args[i].length();
buffer.replace(size, length, wc_args[i]);
size += length;
buffer.replace(size, 528 - length, 528 - length, null);
size += (528 - length);
buffer.replace(size, 1, { one });
size++;
buffer.replace(size, 7, 7, null);
size += 7;
}
}
owc.write(buffer.c_str(), (buffer.size()));
owc.close();
return true;
}
bool process_wc(string& file, char* ente)
{
ifstream iwc(file, ifstream::binary);
if (!iwc.is_open())
{
return false;
}
int val = is_in_wc(iwc);
if (val == 0)
{
return false;
}
else
{
ofstream owc(file,(ofstream::binary | ofstream::out | ofstream::in));
if (!owc.is_open())
{
return false;
}
char cd(val + 1);
char c[] = {cd};
owc.seekp(ios_base::beg + 35);
owc.write(c, 1);
if (owc.bad() || owc.fail())
{
owc.close();
return false;
}
owc.close();
owc.open(file, (ofstream::binary | ofstream::app));
owc.seekp(ios_base::end);
return put_in_wc(owc, ente);
}
}