source: tags/ms_r16q2/SL/SEQIO/seqio.cxx

Last change on this file was 7177, checked in by westram, 13 years ago

merges [7054] [7055] [7057] [7058] [7059] [7062] from refactor

  • added GB_unfold_path()
  • added GB_install_getenv_hook(). May override expansion of environment variables.
  • added unit tests for AW_unfold_path
  • rewrote AW_unfold_path() using GB_unfold_path() + hook to expand symbolic directories (PWD and PT_SERVER_HOME)
  • replaced duplicate of AW_unfold_path() with different behavior in SL/SEQIO by calling GB_unfold_path()
  • removed default argument "PWD" from AW_unfold_path
  • swapped argument order of GB_unfold_path and AW_unfold_path to "(dir,file)"
  • Tests for path functions
  • GB_path_in_ARBLIB/ARBHOME
    • versions with one argument
    • using GB_unfold_path
  • replaced AW_unfold_path / GB_unfold_path ("ARBHOME") with GB_path_in_ARBHOME
  • replaced GB_path_in_ARBHOME("lib/") by GB_path_in_ARBLIB
  • GB_canonical_path (former GB_get_full_path)
    • old version had undefined behavior (which was working in many cases)
    • now "never" return NULL, instead it may return a non-canonical path (in case of non-existing directories)
  • assert that param 'pwd_envar' to GB_unfold_path() really is the name of an envar (to avoid passing a path by mistake)
File size: 2.8 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : seqio.cxx                                       //
4//   Purpose   :                                                 //
5//                                                               //
6//   Institute of Microbiology (Technical University Munich)     //
7//   http://www.arb-home.de/                                     //
8//                                                               //
9// ============================================================= //
10
11#include "seqio.hxx"
12
13#include <arbdb.h>
14
15#define sio_assert(cond) arb_assert(cond)
16
17char *SEQIO_fgets(char *s, int size, FILE *stream) {
18    // same as fgets but also works with file in MacOS format
19    int i;
20    for (i = 0; i<(size-1); ++i) {
21        int byte = fgetc(stream);
22        if (byte == EOF) {
23            if (i == 0) return 0;
24            break;
25        }
26
27        s[i] = byte;
28        if (byte == '\n' || byte == '\r') break;
29    }
30    s[i] = 0;
31
32    return s;
33}
34
35bool SEQIO_read_string_pair(FILE *in, char *&s1, char *&s2, size_t& lineNr) {
36    // helper function to read import/export filters.
37    // returns true if successfully read
38    //
39    // 's1' is set to a heap-copy of the first token on line
40    // 's2' is set to a heap-copy of the rest of the line (or NULL if only one token is present)
41    // 'lineNr' is incremented with each line read
42
43    s1 = 0;
44    s2 = 0;
45
46    const int  BUFSIZE = 8000;
47    char       buffer[BUFSIZE];
48    char      *res;
49
50    do {
51        res = SEQIO_fgets(&buffer[0], BUFSIZE-1, in);
52        if (res) {
53            char *p = buffer;
54
55            lineNr++;
56
57            while (*p == ' ' || *p == '\t') p++;
58            if (*p != '#') {
59                int len = strlen(p)-1;
60                while  (len >= 0 && strchr("\t \n\r", p[len])) {
61                    p[len--] = 0;
62                }
63
64                if (*p) {
65                    char *e = strpbrk(p, " \t");
66
67                    if (e) {
68                        *(e++) = 0;
69                        s1     = strdup(p);
70
71                        e += strspn(e, " \t"); // skip whitespace
72
73                        if (*e == '"') {
74                            char *k = strrchr(e, '"');
75                            if (k!=e) {
76                                e++;
77                                *k=0;
78                            }
79                        }
80                        s2 = strdup(e);
81                    }
82                    else {
83                        s1 = strdup(p);
84                    }
85                }
86            }
87        }
88    } while (res && !s1);                           // read until EOF or something found
89
90    sio_assert(correlated(res, s1));
91
92    return res;
93}
94
95
Note: See TracBrowser for help on using the repository browser.