SDC C-Project CF Review 프로그램
LYW
2021-08-10 8ac7359b04409c2a1426f9a179c00b1c966d0146
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#include "StdAfx.h"
#include "akGridData.h"
 
 
void CakParser::process( const char* pText, const char* pToken /*= " \r\n\t,^"*/ )
{
    //{
        m_vecTokLen.clear();
        m_vecTokPos.clear();
    //}
 
    m_pSrcText = pText;
 
    unsigned int i_index;
    unsigned int index;
 
    unsigned int nTokenLen = (unsigned int)strlen(pToken);
    unsigned int string_length = (unsigned int)strlen(pText);
    unsigned char bitmask[32]={0}; //256°¡ bit maskingÀ» »ç¿ëÇϱâ À§Çؼ­.
 
    //token ¹è¿­¿¡ ÀúÀåµÈ ¹®ÀÚÀÇ ascii index À§Ä¡¿¡ maskingÀ» ÇÑ´Ù.
    for( i_index=0; i_index<nTokenLen; i_index++)
        bitmask[ pToken[i_index] >> 3] |= (1 << ( pToken[i_index] & 7));
 
 
    int nStartPoint=-1;
    for( index=0; index<string_length; index++)
    {
        if( (bitmask[pText[index] >> 3]) & (1 << (pText[index] & 7)) ) //±¸ºÐÀڠãÀ½ ÅÂÇö[2017/12/7]
        {
            if(nStartPoint != -1)
            {
                m_vecTokPos.push_back(nStartPoint);
                m_vecTokLen.push_back(index-nStartPoint);
                nStartPoint = -1;
            }
        }
        else if(nStartPoint < 0) //±¸ºÐÀÚµµ ¸øÃ£°í ½ÃÀÛµµ ¾ÈÇÔ
        {
            nStartPoint = index;
        }
 
    }
    if(nStartPoint >= 0)
    {
        m_vecTokPos.push_back(nStartPoint);
        m_vecTokLen.push_back(string_length-nStartPoint);
    }
 
};
 
 
const char* CakParser::getTokStr( int nIndex )
{
    m_strTokBuffer.clear();
    if(nIndex >= m_vecTokPos.size()) return "";
 
    m_strTokBuffer.append(&m_pSrcText[m_vecTokPos[nIndex]], m_vecTokLen[nIndex]);
    return m_strTokBuffer.c_str();        
}
 
bool CakParser::getTokStr( int nTokIndex, char* pBuf, int nLen )
{
    // NULL °ª °í·Á
    if(nLen-1 < m_vecTokLen[nTokIndex]) return false;
 
    strncpy(pBuf, &m_pSrcText[m_vecTokPos[nTokIndex]], m_vecTokLen[nTokIndex]);
    pBuf[m_vecTokLen[nTokIndex]] = 0;
    
    return true;    
}
 
CakTextMatrix::CakTextMatrix(void)
{
    m_nRowsNum = m_nColsNum = 0;
 
    m_nIntervalLength = 0;
    m_vecIntervalPos.clear();
    
    setDevideFlag();
}
 
CakTextMatrix::~CakTextMatrix(void)
{
}
 
bool CakTextMatrix::ImportFile( char* pFileName )
{
    
    FILE* pf = fopen(pFileName, "r");
    if(pf)
    {
        CakParser parser;
        setRowCount(0);
        setColCount(0);
 
 
        char buffer[2048]={};
        
        while (fgets(buffer, 2048, pf))
        {
            parser.process(buffer);
            
            setRowCount(1, TRUE);
            if(parser.getTokNum() > getColCount()) setColCount(parser.getTokNum());
 
            int nTokenNum = parser.getTokNum();
            int nRowIndex = getRowCount()-1;
            for(int i=0; i<nTokenNum; i++)
            {
                setItemText(nRowIndex, i, parser.getTokStr(i));
            }
        }
        
        fclose(pf);
 
        return true;
    }
 
    return false;
}
 
bool CakTextMatrix::ImportText( char* pText )
{
    if(pText == NULL) return false;
    CakParser parserLine;
    CakParser parserTok;
    parserLine.process(pText, "\n");
 
    char* pStrLineData;
    char* pStrLineTock;
    int nLineNum = parserLine.getTokNum();
    setRowCount(nLineNum);
    for(int i=0; i<nLineNum; i++)
    {
        pStrLineData = (char*)parserLine.getTokStr(i);
        
        parserTok.process(pStrLineData, m_strDevideFlag.c_str());
        int nTockNum = parserTok.getTokNum();
        setColCount(nTockNum);
        for(int j=0; j<nTockNum; j++)
        {
            pStrLineTock = (char*)parserTok.getTokStr(j);
            setItemText(i,j, pStrLineTock);
        }
    }
 
    return true;
}
 
 
bool CakTextMatrix::AddRowData( char* pTextData )
{
    if(pTextData == NULL) return false;
    
    CakParser parserTok;
    parserTok.process(pTextData, m_strDevideFlag.c_str());
    
    int nTockNum = parserTok.getTokNum();
    
    setColCount(nTockNum);
    setRowCount(1, true);
 
    int nRowIndex = getRowCount();
    char* pStrTok;
    
    for(int j=0; j<nTockNum; j++)
    {
        pStrTok = (char*)parserTok.getTokStr(j);
        setItemText(nRowIndex,j, pStrTok);
    }
 
    return true;
}
 
 
 
void CakTextMatrix::setDevideFlag( char* pFlag /*= " \r\n\t,"*/ )
{
    m_strDevideFlag = pFlag;
 
    
}
 
void CakTextMatrix::setRowCount( int nNum/*=10*/, bool bIncrease /*= false*/ )
{
    int nIncreaseCount = 0;
    
    if(bIncrease) nIncreaseCount = nNum;
    else nIncreaseCount = nNum - m_nRowsNum;
 
    if(nIncreaseCount == 0) 
    {
        return ;
    }
    else if(nIncreaseCount > 0) //Áõ°¡
    {
        for(int i=0; i<nIncreaseCount; i++)
        {
            m_vecCellData_Row.push_back(_akCell_Row());
        }
        setColCount(m_nColsNum);
    }
    else if(nIncreaseCount < 0) //°¨¼Ò
    {
        m_vecCellData_Row.erase(m_vecCellData_Row.end() + nIncreaseCount, m_vecCellData_Row.end());
    }
 
    m_nRowsNum += nIncreaseCount;
    makeCellItemArray();
}
 
void CakTextMatrix::setColCount( int nNum/*=10*/, bool bIncrease /*= false*/ )
{
    if(bIncrease) m_nColsNum += nNum;
    else m_nColsNum = nNum;
 
    int nSize = (int)m_vecCellData_Row.size(); 
    for(int i=0; i<nSize; i++)
    {
        std::vector<_akCellData>* pVecGridCellData = &m_vecCellData_Row[i].m_vecGridCellData;
 
        int nIncreaseCount = 0;
 
        if(bIncrease) nIncreaseCount = nNum;
        else nIncreaseCount = m_nColsNum - (int)pVecGridCellData->size();
 
        
 
        if(nIncreaseCount == 0)
        {
            continue ;
        }
        else if(nIncreaseCount > 0) //Áõ°¡
        {
            for(int i=0; i<nIncreaseCount; i++)
            {
                 pVecGridCellData->push_back(_akCellData());
            }
        }
        else if(nIncreaseCount < 0) //°¨¼Ò
        {
            pVecGridCellData->erase(pVecGridCellData->end() + nIncreaseCount, pVecGridCellData->end());
        }
 
    }
 
    makeCellItemArray();
 
    
    
 
    return;
}
 
void CakTextMatrix::printOut()
{
    int nRowNum = getRowCount();
    int nColNum = getColCount();
 
    for(int y=0; y<nRowNum; y++)
    {
        for(int x=0; x<nColNum; x++)
        {
            //TRACE("%s", getItemText(x,y));
            TRACE("(%02d,%02d)%s", x,y,getItemText(y,x));
            if(x < nColNum-1) TRACE("\t");
        }
        TRACE("\n");
    }
}
 
const char* CakTextMatrix::getItemText( int nRow, int nCol )
{
    return m_vecCellItem[nRow*m_nColsNum + nCol]->m_strText.c_str();
}
 
void CakTextMatrix::setItemText( int nRow, int nCol,  const char* pText )
{
    if(pText != NULL)
        m_vecCellItem[nRow*m_nColsNum + nCol]->m_strText = pText;
}
 
void CakTextMatrix::makeCellItemArray()
{
    m_vecCellItem.clear();
 
    int nRowNum = getRowCount();
    int nColNum = getColCount();
 
    for(int y=0; y<nRowNum; y++)
    {
        for(int x=0; x<nColNum; x++)
        {
            m_vecCellItem.push_back(&m_vecCellData_Row[y].m_vecGridCellData[x]);
        }
    }
}
 
int CakTextMatrix::getRowIndex( char* pTitle )
{
    for(int i=0; i<m_nRowsNum; i++)
    {
        if(m_vecCellItem[i*m_nColsNum + 0]->m_strText.compare(pTitle))
        {
            return i;
        }
    }
 
    return -1;
}
int CakTextMatrix::getColIndex( char* pTitle )
{
    for(int i=0; i<m_nColsNum; i++)
    {
        if(m_vecCellItem[0*m_nColsNum + i]->m_strText.compare(pTitle))
        {
            return i;
        }
    }
 
    return -1;
}
 
bool CakTextMatrix::ExportFileInterval( char* pFileName, char* pIntervalRef )
{
    FILE* pf = fopen(pFileName, "w");
    if(pf)
    {
        CakParser paserInterval;
        paserInterval.process(pIntervalRef, " ");
 
        const int nBufSize = 2048;
        char buffer[nBufSize];
        int nStrLen, nWritePoint;
        const char* pStr;
 
        int nRowNum = getRowCount();
        int nColNum = getColCount();
 
        for(int y=0; y<nRowNum; y++)
        {
            memset(buffer, ' ', sizeof(char)*nBufSize);
            for(int x=0; x<nColNum; x++)
            {
                pStr = getItemText(y,x);
                nStrLen = (int)strlen(pStr);
                nWritePoint = paserInterval.getTokPos(x);
                memcpy(&buffer[nWritePoint], pStr, sizeof(char)*nStrLen);
                
                if(nWritePoint > 0)
                {
                    buffer[nWritePoint-1] = ' '; //¹Ù·Î Á÷Àü¿¡ °ø¹éÀ¸·Î Ç¥½Ã
                }
            }
            buffer[strlen(pIntervalRef)] = 0;
            fprintf(pf, "%s", buffer);
            if(y < nRowNum-1) fprintf(pf, "\n");
        }
 
        fclose(pf);
        return true;
    }
 
    
    return false;
}
 
bool CakTextMatrix::ExportFile( char* pFileName, char* pDevideFlag/*=","*/ )
{
    //ÇÑÁÙÀ» ¸Þ¸ð¸®¿¡ Àû°í ÃÖÁ¾ÀûÀ¸·Î ÆÄÀϷΠ¾²´Â°Ô ´õ ºü¸£°ÚÁö?? ÅÂÇö[2017/12/7]
    FILE* pf = fopen(pFileName, "w");
    if(pf)
    {
        char buffer[2048]={};
 
        int nRowNum = getRowCount();
        int nColNum = getColCount();
 
        for(int y=0; y<nRowNum; y++)
        {
            memset(buffer, 0, sizeof(char)*2048);
            for(int x=0; x<nColNum; x++)
            {
                strcat(buffer, getItemText(y,x));
                if(x < nColNum-1) strcat(buffer, pDevideFlag);
            }
            
            if(y < nRowNum-1) strcat(buffer, "\n");
            fprintf(pf, "%s", buffer);
        }
 
        fclose(pf);
        return true;
    }
 
    //ÇÑÁÙÇÑÁÙ ÆÄÀÏ¿¡ ¾²´Â ¹æ½Ä ÅÂÇö[2017/12/7]
    /*
    FILE* pf = fopen(pFileName, "w");
    if(pf)
    {
        int nRowNum = getRowCount();
        int nColNum = getColCount();
 
        for(int y=0; y<nRowNum; y++)
        {
            for(int x=0; x<nColNum; x++)
            {
                fprintf(pf, "%s", getItemText(y,x));
                if(x < nColNum-1) fprintf(pf, "%s", pDevideFlag);
            }
            if(y < nRowNum-1) fprintf(pf, "\n");
        }
 
        fclose(pf);
        return true;
    }
    */ 
 
    return false;
}
bool CakTextMatrix::printLine( int nRowIndex, char* pBuf, int nLen, char* pDevideFlag/*=","*/ )
{
    int nRowNum = getRowCount();
    int nColNum = getColCount();
 
 
    if(nRowIndex < nRowNum)
    {
        memset(pBuf, 0, sizeof(char)*nLen);
 
        for(int x=0; x<nColNum; x++)
        {
            strcat(pBuf, getItemText(nRowIndex,x));
            if(x < nColNum-1) strcat(pBuf, pDevideFlag);
        }
 
        return true;
    }
 
 
    return false;
}
 
 
bool CakTextMatrix::printLineInterval( int nRowIndex, char* pBuf, int nLen )
{
    int nRowNum = getRowCount();
 
    if(nRowIndex < nRowNum && m_nIntervalLength != 0)
    {
        int nColNum = getColCount();
 
        int nStrLen, nWritePoint;
        const char* pStr;
        
        memset(pBuf, ' ', sizeof(char)*nLen);
        for(int x=0; x<nColNum; x++)
        {
            pStr = getItemText(nRowIndex,x);
            nStrLen = (int)strlen(pStr);
            nWritePoint = m_vecIntervalPos[x];
            memcpy(&pBuf[nWritePoint], pStr, sizeof(char)*nStrLen);
 
            if(nWritePoint > 0)
            {
                pBuf[nWritePoint-1] = ' '; //¹Ù·Î Á÷Àü¿¡ °ø¹éÀ¸·Î Ç¥½Ã
            }
        }
        pBuf[m_nIntervalLength] = 0;
 
 
        return true;
    }
    
    return false;
}
 
void CakTextMatrix::setIntervalRef( char* pIntervalRef )
{
    m_nIntervalLength = 0;
    m_vecIntervalPos.clear();
 
    if(pIntervalRef == NULL) return;
    
    CakParser paserInterval;
    paserInterval.process(pIntervalRef, " ");
 
    int nNum = paserInterval.getTokNum();
    for(int i=0; i<nNum; i++)
    {
        m_vecIntervalPos.push_back(paserInterval.getTokPos(i));
    }
 
    m_nIntervalLength = (int)strlen(pIntervalRef);
 
}