Commit 60fdcb6c authored by Frédéric Krüger's avatar Frédéric Krüger
Browse files

Ajout d'une fonction custom pour le strndup pour MAC

parent ca98311c
This diff is collapsed.
......@@ -3,7 +3,7 @@
#include <clex.h>
#line 67 "EaseaLex.l"
#line 153 "EaseaLex.l"
// forward references
class CEASEAParser;
......@@ -60,7 +60,7 @@ protected:
virtual int yyaction(int action);
public:
#line 82 "EaseaLex.l"
#line 168 "EaseaLex.l"
protected:
CSymbolTable *pSymbolTable; // the symbol table
......
......@@ -19,6 +19,92 @@ Centre de Math�matiques Appliqu�es
#else
#include <unistd.h>
#endif
#ifdef __APPLE__
/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
char *strndup (const char *s, size_t n){
size_t len = strlen (s);
char *ret;
if (len <= n)
return strdup (s);
ret = (char *)malloc(n + 1);
strncpy(ret, s, n);
ret[n] = '\0';
return ret;
}
ssize_t getline (char **lineptr, size_t *n, FILE *fp){
ssize_t result;
size_t cur_len = 0;
if (lineptr == NULL || n == NULL || fp == NULL){
errno = EINVAL;
return -1;
}
if (*lineptr == NULL || *n == 0){
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL){
result = -1;
goto end;
}
}
for (;;){
int i;
i = getc (fp);
if (i == EOF){
result = -1;
break;
}
/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n){
size_t needed_max = SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;
if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed){
result = -1;
goto end;
}
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL){
result = -1;
goto end;
}
*lineptr = new_lineptr;
*n = needed;
}
(*lineptr)[cur_len] = i;
cur_len++;
if (i == '\n')
break;
}
(*lineptr)[cur_len] = '\0';
result = cur_len ? (ssize_t) cur_len : result;
end:
return result;
}
#endif
/* getline implementation is copied from glibc. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
#endif
#include "debug.h"
#include <iostream>
#include <sstream>
......
......@@ -81,9 +81,9 @@ endif
EaseaParse.o: EaseaParse.cpp EaseaLex.cpp
$(CPPC) $(CPPFLAGS) $< -o $@ -c 2>/dev/null
$(CPPC) $(CPPFLAGS) $< -o $@ -c #2>/dev/null
EaseaLex.o: EaseaLex.cpp
$(CPPC) $(CPPFLAGS) $< -o $@ -c 2>/dev/null
$(CPPC) $(CPPFLAGS) $< -o $@ -c #2>/dev/null
%.o:%.cpp
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment