Permalink
Browse files

-added Simon's re-implementation of getline called rax_getline() such…

… that it should work/compile on MACs and Windows
  • Loading branch information...
1 parent c6d3162 commit 7bbd1a620d51ece46f2453a574e4e763a1c671b2 @stamatak committed Nov 23, 2012
Showing with 81 additions and 11 deletions.
  1. +1 −1 README
  2. +1 −1 Release-Notes
  3. +77 −7 axml.c
  4. +2 −2 axml.h
View
2 README
@@ -1,4 +1,4 @@
-Standard RAxML version 7.4.1
+Standard RAxML version 7.4.2
Compiling under Linux:
View
@@ -1,4 +1,4 @@
-RAxML v7.4.1
+RAxML v7.4.2
We view RAxML code development as permanent work in progress.
View
84 axml.c
@@ -604,6 +604,76 @@ void hookupDefault (nodeptr p, nodeptr q, int numBranches)
/***********************reading and initializing input ******************/
+static void rax_getline_insptr_valid(char **lineptr, size_t *n, size_t ins_ptr )
+{
+ const size_t
+ n_inc = 1024;
+
+ if(ins_ptr >= *n)
+ {
+ assert( *n <= (SSIZE_MAX - n_inc));
+
+ *n += n_inc;
+
+ *lineptr = (char*)realloc((void*)(*lineptr), *n * sizeof(char));
+
+ assert(*lineptr != 0);
+ }
+}
+
+static ssize_t rax_getline(char **lineptr, size_t *n, FILE *h)
+{
+ size_t
+ ins_ptr = 0;
+
+ /* this implementation does not conform to the standard regarding error checking (i.e., asserts on errors ) */
+
+ assert(h != (FILE*)NULL);
+
+ if(*lineptr == (char *)NULL)
+ *n = 0;
+
+ while(1)
+ {
+ int
+ c = fgetc(h);
+
+ /* handle EOF: if no character has been read on the current line throw an error.
+ Otherwise treat as end-of-line. Don't know if this is correct,
+ as I don't have the POSIX standard and the linux manpage is unclear. */
+
+ if(c == EOF)
+ {
+ if(ins_ptr == 0)
+ return -1;
+ else
+ break;
+ }
+
+ if(c == '\r')
+ {
+ /* windows line-end: must be followed by a '\n'. Don't tolerate anything else. */
+ c = fgetc(h);
+ assert(c == '\n');
+ }
+
+ /* insert character (including '\n') into buffer */
+ rax_getline_insptr_valid(lineptr, n, ins_ptr);
+ (*lineptr)[ins_ptr] = c;
+ ++ins_ptr;
+
+ if(c == '\n')
+ break;
+ }
+
+ /* null-terminate */
+ rax_getline_insptr_valid( lineptr, n, ins_ptr );
+ (*lineptr)[ins_ptr] = 0;
+
+ return ((ssize_t)ins_ptr);
+}
+
+
static void getnums (rawdata *rdta, analdef *adef)
{
if(fscanf(INFILE, "%d %d", & rdta->numsp, & rdta->sites) != 2)
@@ -618,18 +688,18 @@ static void getnums (rawdata *rdta, analdef *adef)
read;
int
- sequenceLength,
+ sequenceLength = 0,
sequences = 0,
taxa = 0,
- sites;
+ sites =0;
if(processID == 0)
{
printf("\nRAxML can't, parse the alignment file as phylip file \n");
printf("it will now try to parse it as FASTA file\n\n");
}
- while((read = getline(&line, &len, INFILE)) != -1)
+ while((read = rax_getline(&line, &len, INFILE)) != -1)
{
ssize_t
i = 0;
@@ -693,7 +763,7 @@ static void getnums (rawdata *rdta, analdef *adef)
if(sequenceLength != sites && processID == 0)
{
printf("Fasta parsing error, RAxML expects an alignment.\n");
- printf("the last sequence in the alignment seems to have a different length\n", line);
+ printf("the last sequence in the alignment seems to have a different length\n");
errorExit(-1);
}
@@ -1426,13 +1496,13 @@ static void parseFasta(analdef *adef, rawdata *rdta, tree *tr)
read;
int
- sequenceLength,
+ sequenceLength = 0,
sequences = 0,
taxa = 0,
- sites;
+ sites = 0;
- while((read = getline(&line, &len, INFILE)) != -1)
+ while((read = rax_getline(&line, &len, INFILE)) != -1)
{
ssize_t
i = 0;
View
4 axml.h
@@ -157,8 +157,8 @@
#define PointGamma(prob,alpha,beta) PointChi2(prob,2.0*(alpha))/(2.0*(beta))
#define programName "RAxML"
-#define programVersion "7.4.1"
-#define programDate "November 16 2012"
+#define programVersion "7.4.2"
+#define programDate "November 23 2012"
#define TREE_EVALUATION 0

0 comments on commit 7bbd1a6

Please sign in to comment.