File: stdafx.h

package info (click to toggle)
perm 0.4.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 976 kB
  • sloc: cpp: 13,499; makefile: 98; sh: 12
file content (197 lines) | stat: -rw-r--r-- 4,876 bytes parent folder | download | duplicates (2)
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
// stdafx.h is a header that almost every class in the project will include
//
#pragma once
#include <limits>
#include <vector>
#include <fstream>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include "time.h"
#include "Filename.h"
#include <bsd/string.h>
//#ifdef WIN32
#include "chdir.h"
//#else
//#include "errno.h"
//#endif
using namespace std;

// unmark the line for DEBUG
// #define DEBUG true

// Change the log level to see different level of information.
#define LOG_LEVEL 3
#define ERROR_LOG 5
#define WARNING_LOG 4
#define INFO_LOG 3
#define CONFIG_LOG 2
#define FINE_LOG 1

#ifdef _WIN32
#ifndef WIN32
#define WIN32 _WIN32
#endif
#endif

#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS true
#endif

#ifdef LOG_LEVEL
#ifdef WIN32
#define LOG_INFO printf
#else
#ifdef _WIN64
#define LOG_INFO printf
#else
#define LOG_INFO(format, level, args...) {\
    if(level >= LOG_LEVEL) {\
        if(level >= LOG_LEVEL) {\
            if (level >= WARNING_LOG) {\
                    fprintf(stderr, "%s, %d (%s)", __FILE__, __LINE__, __FUNCTION__);\
                    fprintf(stderr, format, level, ##args);\
                    fflush(stderr);\
            } else {\
                fprintf(stdout, format, level, ##args);\
                fflush(stdout);\
            }\
        }\
    }\
}
#endif
#endif
#endif

#ifndef BLANK_LINE
#define BLANK_LINE "                                         "
#endif

#define ERR printf("ERR --- %s:%d\n", __FILE__, __LINE__);

#define TIME_INFORMATION(a) {\
        time_t startt, endt;\
        time(&startt);\
        a;\
        time(&endt);\
        printf("%u seconds consumed.%s\r", (unsigned int)(endt - startt), BLANK_LINE);\
        fflush(stdout);\
    }

#define TIME_INFO(a, msg) {\
        time_t startt, endt;\
        time(&startt);\
        a;\
        time(&endt);\
        printf("%s in %u seconds.%s\r", msg, (unsigned int)(endt - startt), BLANK_LINE);\
        fflush(stdout);\
    }

#define ASSERT_TRUE(expression, message)\
    do {\
        if (!(expression))\
        { \
            printf("ERROR: %s.  Press ENTER to continue", message);\
            fflush(stdout);\
            char crap[256];\
            cin.getline(crap, 256);\
        }\
    } while(0)

#define ASSERT_EQUAL(expectation, real_value, message)\
    do {\
        if (expectation != real_value)\
        { \
			cout << '\n' << expectation << " is not equal to " << real_value << << endl;\
            printf("ERROR: %s.  Press ENTER to continue", message);\
            fflush(stdout);\
            char crap[256];\
            cin.getline(crap, 256);\
        }\
    } while(0)

#ifndef WIN32
#define MEMORY_INFO(b)\
    do {\
        FILE *xfp = fopen("/proc/self/statm", "r");\
        unsigned int l1, l2, l3, l4, l5, l6, l7;\
        int PageSize = getpagesize();\
        if(xfp == NULL) {\
            LOG_INFO("Info %d: We cannot open /proc/self/statm file (%d:%s)\n", CONFIG_LOG\
                      errno, strerror(errno));\
        } else{\
            fscanf(xfp, "%u %u %u %u %u %u %u", &l1, &l2, &l3, &l4, &l5, &l6, &l7);\
            printf("%s: %u MB memory (%u MB in stack) consumed.\n",\
                   (b), /*(unsigned int)(end - start),*/ \
                   (unsigned int)(l2*PageSize/1024/1024), (unsigned int)(l6*PageSize/1024/1024));\
        }\
        fclose(xfp);\
    } while(0)
#endif

#define STRIKE_KEY2CONTINUE\
    do {\
        cout << "Strike a key to continue" << endl;\
        char c;\
        if(scanf("%c", &c) == 0) {\
            break;\
        }\
    } while(0)

inline bool myFwrite(const void* a, size_t b, size_t c, FILE* fp)
{
    size_t stWriteByte = fwrite(a, b, c, fp);
    if (stWriteByte != c) {
        return (false);
    } else {
        return (true);
    }
}

inline bool myFread(void* a, size_t b, size_t c, FILE* fp)
{
    size_t stReadByte = fread(a, b, c, fp);
    if (stReadByte != c) {
        return (false);
    } else {
        return (true);
    }
}

inline bool assertFile(FILE* fp, const char* expCheckSum)
{
    char CheckSum[FILENAME_MAX];
    if (fscanf(fp, "\n%s\n", CheckSum) <= 0) {
        ERR;
        return(false);
    }
    if (strcmp(CheckSum, expCheckSum) != 0) {
        ERR;
        return(false);
    }
    return(true);
}

inline int myStrCpy(char* caBuf, const char* str, int iBufSize)
{
    if (caBuf == NULL) {
        ERR;
        return(-1);
    }
    int iBufSizeMinus1 = iBufSize - 1;
    int returnV = strlcpy(caBuf, str, iBufSize);
    if (iBufSizeMinus1 >= 0) {
        caBuf[iBufSizeMinus1] = '\0';
    } else {
        caBuf[0] = '\0';
    }
    return(returnV);
}
const int MAX_LINE = 2048;
const unsigned int MAXTOLERATSUBMIS = 20;
const unsigned int MIN_READ_LENGTH = 13;
const unsigned int MAX_READ_LENGTH = 64;
const unsigned int MAX_LONG_READ_LENGTH = 128;