This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstandalone_dependencies.c
309 lines (268 loc) · 5.95 KB
/
standalone_dependencies.c
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#define _GNU_SOURCE
/* ===============================================================================================
*/
/* ===============================================================================================
*/
/* HEADER FILES */
/* ===============================================================================================
*/
/* ===============================================================================================
*/
#include "standalone_dependencies.h"
#include <ncurses.h>
#include <string.h>
#include <time.h>
#include "streamCTRL.h"
static int wrow, wcol;
int C_ERRNO = 0;
/* ===============================================================================================
*/
/* DUPLICATED CODE */
/* ===============================================================================================
*/
struct timespec timespec_diff(struct timespec start, struct timespec end)
{
struct timespec temp;
if((end.tv_nsec - start.tv_nsec) < 0)
{
temp.tv_sec = end.tv_sec - start.tv_sec - 1;
temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
}
else
{
temp.tv_sec = end.tv_sec - start.tv_sec;
temp.tv_nsec = end.tv_nsec - start.tv_nsec;
}
return temp;
}
int print_header(const char *str, char c)
{
long n;
long i;
attron(A_BOLD);
n = strlen(str);
for(i = 0; i < (wcol - n) / 2; i++)
{
printw("%c", c);
}
printw("%s", str);
for(i = 0; i < (wcol - n) / 2 - 1; i++)
{
printw("%c", c);
}
printw("\n");
attroff(A_BOLD);
return (0);
}
void qs2l(double *array, long *array1, long left, long right)
{
register long i, j;
double x, y;
long l1;
i = left;
j = right;
x = array[(left + right) / 2];
do
{
while(array[i] < x && i < right)
{
i++;
}
while(x < array[j] && j > left)
{
j--;
}
if(i <= j)
{
y = array[i];
array[i] = array[j];
array[j] = y;
l1 = array1[i];
array1[i] = array1[j];
array1[j] = l1;
i++;
j--;
}
}
while(i <= j);
if(left < j)
{
qs2l(array, array1, left, j);
}
if(i < right)
{
qs2l(array, array1, i, right);
}
}
void quick_sort2l(double *array, long *array1, long count)
{
qs2l(array, array1, 0, count - 1);
}
void qs2l_double(double *array, long *array1, long left, long right)
{
register long i, j;
double x, y;
long l1;
i = left;
j = right;
x = array[(left + right) / 2];
do
{
while(array[i] < x && i < right)
{
i++;
}
while(x < array[j] && j > left)
{
j--;
}
if(i <= j)
{
y = array[i];
array[i] = array[j];
array[j] = y;
l1 = array1[i];
array1[i] = array1[j];
array1[j] = l1;
i++;
j--;
}
}
while(i <= j);
if(left < j)
{
qs2l_double(array, array1, left, j);
}
if(i < right)
{
qs2l_double(array, array1, i, right);
}
}
void quick_sort2l_double(double *array, long *array1, long count)
{
qs2l_double(array, array1, 0, count - 1);
}
void qs_long(long *array, long left, long right)
{
register long i, j;
long x, y;
i = left;
j = right;
x = array[(left + right) / 2];
do
{
while(array[i] < x && i < right)
{
i++;
}
while(x < array[j] && j > left)
{
j--;
}
if(i <= j)
{
y = array[i];
array[i] = array[j];
array[j] = y;
i++;
j--;
}
}
while(i <= j);
if(left < j)
{
qs_long(array, left, j);
}
if(i < right)
{
qs_long(array, i, right);
}
}
void quick_sort_long(long *array, long count)
{
qs_long(array, 0, count - 1);
}
/**
* ## Purpose
*
* Print error string
*
* ## Arguments
*
* @param[in]
* file CHAR*
* file name from which error is issued
*
* @param[in]
* func CHAR*
* function name from which error is issued
*
* @param[in]
* line int
* line number from which error is issued
*
* @param[in]
* warnmessage CHAR*
* error message to be printed
*
*/
int printERROR(const char *file, const char *func, int line, char *errmessage)
{
fprintf(stderr, "%c[%d;%dm ERROR [ %s:%d: %s ] %c[%d;m\n", (char) 27, 1, 31,
file, line, func, (char) 27, 0);
if(C_ERRNO != 0)
{
char buff[256];
if(strerror_r(errno, buff, 256) == 0)
{
fprintf(stderr, "C Error: %s\n", buff);
}
else
{
fprintf(stderr, "Unknown C Error\n");
}
}
else
{
fprintf(stderr, "No C error (errno = 0)\n");
}
fprintf(stderr, "%c[%d;%dm %s %c[%d;m\n", (char) 27, 1, 31, errmessage,
(char) 27, 0);
C_ERRNO = 0;
return(0);
}
int file_exists(const char *restrict file_name)
{
FILE *fp;
int exists = 1;
if((fp = fopen(file_name, "r")) == NULL)
{
exists = 0;
/* printf("file %s does not exist\n",file_name);*/
}
else
{
fclose(fp);
}
return(exists);
}
int is_fits_file(const char *restrict file_name)
{
FILE *fp;
int exists = 1;
if((fp = fopen(file_name, "r")) == NULL)
{
exists = 0;
/* printf("file %s does not exist\n",file_name);*/
}
else
{
fclose(fp);
}
return(exists);
}
/* ===============================================================================================
*/
/* END OF DUPLICATED CODE */
/* ===============================================================================================
*/