File: FileParser.cpp

package info (click to toggle)
clustalx 2.1%2Blgpl-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,320 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 16
file content (103 lines) | stat: -rw-r--r-- 1,981 bytes parent folder | download | duplicates (12)
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
/**
 * Author: Mark Larkin
 * 
 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
 */
/**
 * 10-02-07,Nigel Brown(EMBL): Removed delimiter and findDelimiter()
 * members, as functionality now handled by the stream class.
 */

#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif
#include "FileParser.h"
const char LF = 0x0a;  //linefeed
const char CR = 0x0d;  //carriage return





namespace clustalw
{
FileParser::FileParser()
{
    parseExitCode = OK;
}

FileParser::~FileParser()
{
    // Dont do anything!!!!
}


void FileParser::fillCharTab(void)
{
    register int i;
    register char c;

    for (i = 0; i < 128; chartab[i++] = 0)
        ;
    for (i = 0; i <= userParameters->getMaxAA() + 1; i++)
    {
        c = userParameters->getAminoAcidCode(i);
        chartab[(int)c] = chartab[tolower(c)] = c;
    }
}

void FileParser::freeFileResources(InFileStream* filePtr)
{
    if(filePtr != 0)
    {
        filePtr->close();
        delete filePtr;
        filePtr = 0;    
    }
}


char FileParser::getDelimiter(string filename)
{
    ifstream in;
    int type = 0;
    char delim;

    in.open(filename.c_str(), ios::in);
    in.seekg(0, ios::beg);

    //look for CR or LF or CRLF (or LFCR)
    if (in.is_open()) {
        char c;
        while (in.get(c)) {
            if (c == CR)
                type |= 1;
            else if (c == LF)
                type |= 2;
            else if (type)
                break;
        }
    }
    in.close();

    switch (type) {
        case 1:
            //cout << "file is Mac System 9" << endl;
            delim = '\r';
            break;
        case 2:
            //cout << "file is UNIX" << endl;
            delim = '\n';
            break;
        case 3:
            //cout << "file is DOS" << endl;
            delim = '\n';
            break;
        default: //short or empty file
            //cout << "file is UNIX (default)" << endl;
            delim = '\n';
    }
    return delim;
}

}