CC = gcc
-# Cflags = -Wall
-# Cflags = -Wall -g -O0 # for valgrind
-Cflags = -Wall -g -pg # for gprof
+# Cflags = -Wall -Werror
+Cflags = -Wall -Werror -g -pg # for gprof
-INC_DIR = inc/
-LIB_DIR = lib/
+INC_DIR = inc/
+LIB_DIR = lib/
+TEST_DIR = test/
INC = -I $(INC_DIR)
LIB = -lm $(LIB_DIR)*.o
-all: libs test test_revcomp fasta_count test_fasta test_oligo2bin repeat-O-matic test_list test_hash test_split test_binary_search test_biotools test_file_buffer test_bed
+all: libs utest fasta_count repeat-O-matic
libs:
cd $(LIB_DIR) && ${MAKE} all
-test: test.c
- $(CC) $(Cflags) $(INC) $(LIB) test.c -o test
-
-test_revcomp: test_revcomp.c
- $(CC) $(Cflags) $(INC) $(LIB) test_revcomp.c -o test_revcomp
+utest:
+ cd $(TEST_DIR) && ${MAKE} all
fasta_count: fasta_count.c
$(CC) $(Cflags) $(INC) $(LIB) fasta_count.c -o fasta_count
-test_fasta: test_fasta.c
- $(CC) $(Cflags) $(INC) $(LIB) test_fasta.c -o test_fasta
-
-test_oligo2bin: test_oligo2bin.c
- $(CC) $(Cflags) $(INC) $(LIB) test_oligo2bin.c -o test_oligo2bin
-
repeat-O-matic: repeat-O-matic.c
$(CC) $(Cflags) $(INC) $(LIB) repeat-O-matic.c -o repeat-O-matic
-test_list: test_list.c
- $(CC) $(Cflags) $(INC) $(LIB) test_list.c -o test_list
-
-test_hash: test_hash.c
- $(CC) $(Cflags) $(INC) $(LIB) test_hash.c -o test_hash
-
-test_split: test_split.c
- $(CC) $(Cflags) $(INC) $(LIB) test_split.c -o test_split
-
-test_binary_search: test_binary_search.c
- $(CC) $(Cflags) $(INC) $(LIB) test_binary_search.c -o test_binary_search
-
-test_biotools: test_biotools.c
- $(CC) $(Cflags) $(INC) $(LIB) test_biotools.c -o test_biotools
-
-test_file_buffer: test_file_buffer.c $(LIB_DIR)filesys.c
- $(CC) $(Cflags) $(INC) $(LIB) test_file_buffer.c -o test_file_buffer
-
-test_bed: test_bed.c $(LIB_DIR)ucsc.c
- $(CC) $(Cflags) $(INC) $(LIB) test_bed.c -o test_bed
-
clean:
cd $(LIB_DIR) && ${MAKE} clean
- rm -f test test_revcomp fasta_count test_fasta test_oligo2bin repeat-O-matic test_list test_hash test_split test_binary_search test_biotools test_file_buffer test_bed
+ cd $(TEST_DIR) && ${MAKE} clean
+ rm -f fasta_count repeat-O-matic
#include <unistd.h>
#include <ctype.h>
#include <math.h>
+#include <assert.h>
/* Define a shorthand for unsigned int */
#define uint unsigned int
#define FALSE 0
/* Macro for resetting a pointer to all \0's. */
-#define ZERO( pt ) ( memset( pt, '\0', sizeof( *pt ) ) )
+#define MEM_ZERO( pt ) ( memset( pt, '\0', sizeof( *pt ) ) )
/* Macro for dynamic allocation of memory. */
#define MEM_GET( pt ) ( pt = mem_get( sizeof( *pt ) ) )
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STRUCTURE DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
+// At some point test if typdef struct list list will allow us to move all this stuff to list.h and list.c
+
+
/* Singly linked list with a pointer to the next element and a pointer to a value. */
struct list
{
--- /dev/null
+/* Locate a substr in a str allowing for a given number of mismatches. */
+/* Returns position of match begin or -1 if not found. */
+int match_substr( char *str, int str_len, char *substr, int substr_len, int mismatch );
CC = gcc
-# Cflags = -Wall
-Cflags = -Wall -g -pg # gprof
+# Cflags = -Wall -Werror
+Cflags = -Wall -Werror -g -pg # gprof
INC_DIR = -I ../inc/
-all: common.o seq.o filesys.o fasta.o list.o hash.o ucsc.o
+all: common.o strings.o seq.o filesys.o fasta.o list.o hash.o ucsc.o
common.o: common.c
$(CC) $(Cflags) $(INC_DIR) -c common.c
+strings.o: strings.c
+ $(CC) $(Cflags) $(INC_DIR) -c strings.c
+
seq.o: seq.c
$(CC) $(Cflags) $(INC_DIR) -c seq.c
$(CC) $(Cflags) $(INC_DIR) -c ucsc.c
clean:
- rm common.o seq.o filesys.o fasta.o list.o hash.o ucsc.o
+ rm common.o strings.o seq.o filesys.o fasta.o list.o hash.o ucsc.o
if ( pt != NULL )
{
- ZERO( pt );
+ MEM_ZERO( pt );
free( pt );
pt = NULL;
list_add( fields, field_copy );
- ZERO( field );
+ MEM_ZERO( field );
j = 0;
}
--- /dev/null
+#include "common.h"
+#include "strings.h"
+
+int match_substr( char *str, int str_len, char *substr, int substr_len, int mismatch )
+{
+ /* Martin A. Hansen, August 2008. */
+
+ /* Locate a substr in a str allowing for a given number of mismatches. */
+ /* Returns position of match begin or -1 if not found. */
+
+ int pos;
+ int i;
+ int count;
+
+ for ( pos = 0; pos < str_len - substr_len + 1; pos++ )
+ {
+ count = 0;
+
+ for ( i = 0; i < substr_len; i++ )
+ {
+ if ( str[ pos + i ] != substr[ i ] )
+ {
+ count++;
+
+ if ( count > mismatch ) {
+ break;
+ }
+ }
+ }
+
+ if ( count <= mismatch ) {
+ return pos;
+ }
+ }
+
+ return -1;
+}
if ( block_pos == 0 )
{
- ZERO( block );
+ MEM_ZERO( block );
block_beg = chr_pos;
--- /dev/null
+CC = gcc
+# Cflags = -Wall -Werror
+Cflags = -Wall -Werror -g -pg # for gprof
+
+INC_DIR = ../inc/
+LIB_DIR = ../lib/
+
+INC = -I $(INC_DIR)
+LIB = -lm $(LIB_DIR)*.o
+
+all: test
+
+test: test_strings
+
+test_strings: test_strings.c
+ $(CC) $(Cflags) $(INC) $(LIB) test_strings.c -o test_strings
+
+clean:
+ rm -f test_strings
--- /dev/null
+#include "common.h"
+
+static void test_strings();
+static void test_match_substr( char *str, int str_len, char *substr, int substr_len, int mismatch );
+
+
+int main()
+{
+ test_strings();
+
+ return 0;
+}
+
+
+static void test_strings()
+{
+ char *str = "MARTIN";
+ char *substr = "TXN";
+ int str_len = strlen( str );
+ int substr_len = strlen( substr );
+ int mismatch = 1;
+
+ test_match_substr( str, str_len, substr, substr_len, mismatch );
+}
+
+
+static void test_match_substr( char *str, int str_len, char *substr, int substr_len, int mismatch )
+{
+ fprintf( stderr, "Running test_match_substr\n" );
+
+ fprintf( stderr, " Testing that str is not NULL ... " );
+ assert( str != NULL );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that substr is not NULL ... " );
+ assert( substr != NULL );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that str_len > zero ... " );
+ assert( str_len > 0 );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that substr_len > zero ... " );
+ assert( substr_len > 0 );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing str_len ... " );
+ assert( strlen( str ) == str_len );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing substr_len ... " );
+ assert( strlen( substr ) == substr_len );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that mismatch >= zero ... " );
+ assert( mismatch > 0 );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that mismatch < substr_len ... " );
+ assert( mismatch < substr_len );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that substr_len <= str_len ... " );
+ assert( substr_len <= str_len );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that str is '\\0' terminated ... " );
+ assert( str[ str_len ] == '\0' );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, " Testing that substr is '\\0' terminated ... " );
+ assert( substr[ substr_len ] == '\0' );
+ fprintf( stderr, "done\n" );
+
+ fprintf( stderr, "test_match_substr OK\n" );
+}
+
+
--- /dev/null
+#include <stdio.h>
+
+void func1();
+void func2();
+
+int main()
+{
+ char p1 = 0;
+ char p2 = 0;
+ char p3 = 0;
+ char p4 = 0;
+
+ printf( "main p1: val->%c address->%p\n", p1, &p1 );
+ printf( "main p2: val->%c address->%p\n", p2, &p2 );
+ printf( "main p3: val->%c address->%p\n", p3, &p3 );
+ printf( "main p4: val->%c address->%p\n", p4, &p4 );
+
+ func1();
+ func2();
+
+ return 0;
+}
+
+void func1()
+{
+ char p1 = 0;
+ char p2 = 0;
+ char p3 = 0;
+ char p4 = 0;
+
+ printf( "func1 p1: val->%c address->%p\n", p1, &p1 );
+ printf( "func1 p2: val->%c address->%p\n", p2, &p2 );
+ printf( "func1 p3: val->%c address->%p\n", p3, &p3 );
+ printf( "func1 p4: val->%c address->%p\n", p4, &p4 );
+
+}
+
+void func2()
+{
+ char p1 = 0;
+ char p2 = 0;
+ char p3 = 0;
+ char p4 = 0;
+
+ printf( "func2 p1: val->%c address->%p\n", p1, &p1 );
+ printf( "func2 p2: val->%c address->%p\n", p2, &p2 );
+ printf( "func2 p3: val->%c address->%p\n", p3, &p3 );
+ printf( "func2 p4: val->%c address->%p\n", p4, &p4 );
+}