aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@jupiter.cs.drexel.edu>2014-04-18 16:18:06 -0400
committerCalvin Morrison <calvin@jupiter.cs.drexel.edu>2014-04-18 16:18:06 -0400
commit4698388304aba000592f71a10d1240ade01fb504 (patch)
tree50bfc7b2ee41a49bad62315c610bda73838766e1
parent1a6dae7724e2e4cf82634924adaf0101600605f4 (diff)
add OSX support, or any supprot for people without getline
-rw-r--r--Makefile.osx43
-rw-r--r--getline/getdelim.c119
-rw-r--r--getline/getdelim.h28
-rw-r--r--getline/getline.c152
-rw-r--r--getline/getline.h53
-rw-r--r--kmer_counts_per_sequence.c4
-rw-r--r--kmer_locations.c4
-rw-r--r--kmer_total_count.c4
-rw-r--r--kmer_utils.c4
9 files changed, 409 insertions, 2 deletions
diff --git a/Makefile.osx b/Makefile.osx
new file mode 100644
index 0000000..104512f
--- /dev/null
+++ b/Makefile.osx
@@ -0,0 +1,43 @@
+VERSION=\"0.0.5\"
+CC = x86_64-apple-darwin10-g++-mp-4.8
+CFLAGS = -O3 -s -march=native -Wall -Wextra -DVERSION=$(VERSION) -std=c++11
+
+DESTDIR = /usr/local
+
+all: libkmer.so kmer_total_count kmer_counts_per_sequence kmer_utils.o \
+ kmer_locations kmer_continuous_count
+
+getline.o: getline/getline.c
+ $(CC) -c getline/getline.c -o getline.o $(CFLAGS)
+
+kmer_utils.o: kmer_utils.c getline.o
+ $(CC) -c kmer_utils.c getline.o -O $(CFLAGS) -fPIC -DFORCE_GETLINE=1
+
+libkmer.so: kmer_utils.o getline.o
+ $(CC) getline.o kmer_utils.o -o libkmer.so $(CFLAGS) -shared -fPIC
+
+kmer_total_count: kmer_utils.o kmer_total_count.c kmer_utils.h
+ $(CC) getline.o kmer_utils.o kmer_total_count.c -o kmer_total_count $(CLIBS) $(CFLAGS)
+
+kmer_counts_per_sequence: kmer_utils.o kmer_counts_per_sequence.c kmer_utils.h
+ $(CC) getline.o kmer_utils.o kmer_counts_per_sequence.c -o kmer_counts_per_sequence $(CLIBS) $(CFLAGS) -DFORCE_GETLINE=1
+
+kmer_continuous_count: kmer_utils.o kmer_continuous_count.c kmer_utils.h
+ $(CC) getline.o kmer_utils.o kmer_continuous_count.c -o kmer_continuous_count $(CLIBS) $(CFLAGS)
+
+kmer_locations: kmer_utils.o kmer_locations.c kmer_utils.h
+ $(CC) getline.o kmer_utils.o kmer_locations.c -o kmer_locations $(CLIBS) $(CFLAGS) -DFORCE_GETLINE=1
+clean:
+ rm -vf kmer_total_count kmer_counts_per_sequence kmer_continuous_count \
+ kmer_utils.o libkmer.so kmer_locations getline.o
+
+debug: CFLAGS = -ggdb -Wall -Wextra -DVERSION=$(VERSION)\"-debug\" -std=c++11
+debug: all
+
+install: all
+ install kmer_counts_per_sequence $(DESTDIR)/bin
+ install kmer_total_count $(DESTDIR)/bin
+ install kmer_continuous_count $(DESTDIR)/bin
+ install kmer_locations $(DESTDIR)/bin
+ cp -vf libkmer.so $(DESTDIR)/lib/
+
diff --git a/getline/getdelim.c b/getline/getdelim.c
new file mode 100644
index 0000000..8498b75
--- /dev/null
+++ b/getline/getdelim.c
@@ -0,0 +1,119 @@
+/* getdelim.c --- Implementation of replacement getdelim function.
+ Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free
+ Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Ported from glibc by Simon Josefsson. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include "getdelim.h"
+
+#if !HAVE_FLOCKFILE
+# undef flockfile
+# define flockfile(x) ((void) 0)
+#endif
+#if !HAVE_FUNLOCKFILE
+# undef funlockfile
+# define funlockfile(x) ((void) 0)
+#endif
+
+/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
+ NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
+ NULL), pointing to *N characters of space. It is realloc'ed as
+ necessary. Returns the number of characters read (not including
+ the null terminator), or -1 on error or EOF. */
+
+ssize_t
+getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
+{
+ int result = 0;
+ ssize_t cur_len = 0;
+ ssize_t len;
+
+ if (lineptr == NULL || n == NULL || fp == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ flockfile (fp);
+
+ if (*lineptr == NULL || *n == 0)
+ {
+ *n = 120;
+ *lineptr = (char *) malloc (*n);
+ if (*lineptr == NULL)
+ {
+ result = -1;
+ goto unlock_return;
+ }
+ }
+
+ for (;;)
+ {
+ char *t;
+ 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 = 2 * (cur_len + 1) + 1; /* Be generous. */
+ char *new_lineptr;
+
+ if (needed < cur_len)
+ {
+ result = -1;
+ goto unlock_return;
+ }
+
+ new_lineptr = (char *) realloc (*lineptr, needed);
+ if (new_lineptr == NULL)
+ {
+ result = -1;
+ goto unlock_return;
+ }
+
+ *lineptr = new_lineptr;
+ *n = needed;
+ }
+
+ (*lineptr)[cur_len] = i;
+ cur_len++;
+
+ if (i == delimiter)
+ break;
+ }
+ (*lineptr)[cur_len] = '\0';
+ result = cur_len ? cur_len : result;
+
+ unlock_return:
+ funlockfile (fp);
+ return result;
+}
diff --git a/getline/getdelim.h b/getline/getdelim.h
new file mode 100644
index 0000000..8bc6130
--- /dev/null
+++ b/getline/getdelim.h
@@ -0,0 +1,28 @@
+/* getdelim.h --- Prototype for replacement getdelim function.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Written by Simon Josefsson. */
+
+/* Get size_t, FILE, ssize_t. And getdelim, if available. */
+# include <stddef.h>
+# include <stdio.h>
+# include <sys/types.h>
+
+#if !HAVE_DECL_GETDELIM
+ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream);
+#endif /* !HAVE_GETDELIM */
diff --git a/getline/getline.c b/getline/getline.c
new file mode 100644
index 0000000..889cfe0
--- /dev/null
+++ b/getline/getline.c
@@ -0,0 +1,152 @@
+/* getline.c --- Implementation of replacement getline function.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Written by Simon Josefsson. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "getdelim.h"
+#include "getline.h"
+
+ssize_t
+getline (char **lineptr, size_t *n, FILE *stream)
+{
+ return getdelim (lineptr, n, '\n', stream);
+}
+
+/* getdelim.c --- Implementation of replacement getdelim function.
+ Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free
+ Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Ported from glibc by Simon Josefsson. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include "getdelim.h"
+
+#if !HAVE_FLOCKFILE
+# undef flockfile
+# define flockfile(x) ((void) 0)
+#endif
+#if !HAVE_FUNLOCKFILE
+# undef funlockfile
+# define funlockfile(x) ((void) 0)
+#endif
+
+/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
+ NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
+ NULL), pointing to *N characters of space. It is realloc'ed as
+ necessary. Returns the number of characters read (not including
+ the null terminator), or -1 on error or EOF. */
+
+ssize_t
+getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
+{
+ int result = 0;
+ ssize_t cur_len = 0;
+ ssize_t len;
+
+ if (lineptr == NULL || n == NULL || fp == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ flockfile (fp);
+
+ if (*lineptr == NULL || *n == 0)
+ {
+ *n = 120;
+ *lineptr = (char *) malloc (*n);
+ if (*lineptr == NULL)
+ {
+ result = -1;
+ goto unlock_return;
+ }
+ }
+
+ for (;;)
+ {
+ char *t;
+ 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 = 2 * (cur_len + 1) + 1; /* Be generous. */
+ char *new_lineptr;
+
+ if (needed < cur_len)
+ {
+ result = -1;
+ goto unlock_return;
+ }
+
+ new_lineptr = (char *) realloc (*lineptr, needed);
+ if (new_lineptr == NULL)
+ {
+ result = -1;
+ goto unlock_return;
+ }
+
+ *lineptr = new_lineptr;
+ *n = needed;
+ }
+
+ (*lineptr)[cur_len] = i;
+ cur_len++;
+
+ if (i == delimiter)
+ break;
+ }
+ (*lineptr)[cur_len] = '\0';
+ result = cur_len ? cur_len : result;
+
+ unlock_return:
+ funlockfile (fp);
+ return result;
+}
diff --git a/getline/getline.h b/getline/getline.h
new file mode 100644
index 0000000..17efc23
--- /dev/null
+++ b/getline/getline.h
@@ -0,0 +1,53 @@
+/* getline.h --- Prototype for replacement getline function.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Written by Simon Josefsson. */
+
+/* Get size_t, FILE, ssize_t. And getline, if available. */
+# include <stddef.h>
+# include <stdio.h>
+# include <sys/types.h>
+
+ssize_t getline (char **lineptr, size_t *n, FILE *stream);
+
+/* getdelim.h --- Prototype for replacement getdelim function.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* Written by Simon Josefsson. */
+
+/* Get size_t, FILE, ssize_t. And getdelim, if available. */
+# include <stddef.h>
+# include <stdio.h>
+# include <sys/types.h>
+
+ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream);
diff --git a/kmer_counts_per_sequence.c b/kmer_counts_per_sequence.c
index e9ca812..95f57fa 100644
--- a/kmer_counts_per_sequence.c
+++ b/kmer_counts_per_sequence.c
@@ -8,6 +8,10 @@
#include "kmer_utils.h"
+#ifdef FORCE_GETLINE
+ #include "getline/getline.h"
+#endif
+
void help() {
printf("usage: kmer_counts_per_sequence input_file kmer [kmer-file] ...\n\n"
"count mers in each sequence of size k from a fasta file\n"
diff --git a/kmer_locations.c b/kmer_locations.c
index e118b9f..10c5339 100644
--- a/kmer_locations.c
+++ b/kmer_locations.c
@@ -8,6 +8,10 @@
#include "kmer_utils.h"
+#ifdef FORCE_GETLINE
+ #include "getline/getline.h"
+#endif
+
void print_mer(unsigned long long mer, const long long pos, const bool labels, const bool reverse, unsigned int kmer, char *label) {
if(labels) {
char *kmer_str;
diff --git a/kmer_total_count.c b/kmer_total_count.c
index c3ae070..6f1c8ee 100644
--- a/kmer_total_count.c
+++ b/kmer_total_count.c
@@ -1,8 +1,8 @@
// Copyright 2013 Calvin Morrison
#include <errno.h>
#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
#include <string.h>
#include <getopt.h>
diff --git a/kmer_utils.c b/kmer_utils.c
index a154cb2..be547dc 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -9,6 +9,10 @@
using namespace std;
+#ifdef FORCE_GETLINE
+ #include "getline/getline.h"
+#endif
+
typedef struct {
size_t operator() (const size_t &k) const {
return k;