From 4f81e90d7207a63a7ded8d4702e66909eee79300 Mon Sep 17 00:00:00 2001
From: Aaron <aaronquinlan@gmail.com>
Date: Sat, 23 Jan 2010 13:09:52 -0500
Subject: [PATCH] Corrected commnad line parsing for all tools.

	There was a problem with the way args with a value were being parsed.
---
 src/closestBed/closestMain.cpp                | 24 +++++++----
 src/complementBed/complementMain.cpp          | 16 ++++---
 src/coverageBed/coverageMain.cpp              | 16 ++++---
 src/fastaFromBed/fastaFromBedMain.cpp         | 24 +++++++----
 src/genomeCoverageBed/genomeCoverageMain.cpp  | 26 +++++------
 src/intersectBed/intersectMain.cpp            | 18 ++++----
 src/linksBed/linksMain.cpp                    | 26 +++++++----
 src/maskFastaFromBed/maskFastaFromBedMain.cpp | 24 +++++++----
 src/mergeBed/mergeMain.cpp                    | 16 ++++---
 src/pairToBed/pairToBedMain.cpp               | 16 ++++---
 src/pairToPair/pairToPairMain.cpp             | 15 ++++---
 src/shuffleBed/shuffleBedMain.cpp             | 32 ++++++++------
 src/slopBed/slopBedMain.cpp                   | 43 +++++++++++--------
 src/sortBed/sortMain.cpp                      | 14 +++---
 src/subtractBed/subtractMain.cpp              | 12 +++---
 src/windowBed/windowMain.cpp                  | 42 +++++++++++-------
 16 files changed, 218 insertions(+), 146 deletions(-)

diff --git a/src/closestBed/closestMain.cpp b/src/closestBed/closestMain.cpp
index 4ae7ae5d..d72fa759 100755
--- a/src/closestBed/closestMain.cpp
+++ b/src/closestBed/closestMain.cpp
@@ -59,22 +59,28 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-a", 2, parameterLength)) {
-			haveBedA = true;
-			bedAFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBedA = true;
+				bedAFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
-			haveBedB = true;
-			bedBFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBedB = true;
+				bedBFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-s", 2, parameterLength)) {
 			forceStrand = true;
 		}
 		else if (PARAMETER_CHECK("-t", 2, parameterLength)) {
-			haveTieMode = true;
-			tieMode = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveTieMode = true;
+				tieMode = argv[i + 1];
+				i++;
+			}
 		}	
 	}
 
diff --git a/src/complementBed/complementMain.cpp b/src/complementBed/complementMain.cpp
index 8f36b672..f8407872 100755
--- a/src/complementBed/complementMain.cpp
+++ b/src/complementBed/complementMain.cpp
@@ -56,14 +56,18 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
  		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-g", 2, parameterLength)) {
-			haveGenome = true;
-			genomeFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveGenome = true;
+				genomeFile = argv[i + 1];
+				i++;
+			}
 		}
 		else {
 		  cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
diff --git a/src/coverageBed/coverageMain.cpp b/src/coverageBed/coverageMain.cpp
index 4ae9c55e..db41fc28 100755
--- a/src/coverageBed/coverageMain.cpp
+++ b/src/coverageBed/coverageMain.cpp
@@ -57,14 +57,18 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-a", 2, parameterLength)) {
-			haveBedA = true;
-			bedAFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBedA = true;
+				bedAFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
-			haveBedB = true;
-			bedBFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBedB = true;
+				bedBFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-s", 2, parameterLength)) {
 			forceStrand = true;
diff --git a/src/fastaFromBed/fastaFromBedMain.cpp b/src/fastaFromBed/fastaFromBedMain.cpp
index d536809e..5d48d80c 100755
--- a/src/fastaFromBed/fastaFromBedMain.cpp
+++ b/src/fastaFromBed/fastaFromBedMain.cpp
@@ -63,19 +63,25 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-fi", 3, parameterLength)) {
-			haveFastaDb = true;
-			fastaDbFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveFastaDb = true;
+				fastaDbFile = argv[i + 1];
+				i++;
+			}
 		} 
 		else if(PARAMETER_CHECK("-fo", 3, parameterLength)) {
-			haveFastaOut = true;
-			fastaOutFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveFastaOut = true;
+				fastaOutFile = argv[i + 1];
+				i++;
+			}
 		} 
 		else if(PARAMETER_CHECK("-bed", 4, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-name", 5, parameterLength)) {
 			useNameOnly = true;
diff --git a/src/genomeCoverageBed/genomeCoverageMain.cpp b/src/genomeCoverageBed/genomeCoverageMain.cpp
index 5befca26..88cbdea0 100755
--- a/src/genomeCoverageBed/genomeCoverageMain.cpp
+++ b/src/genomeCoverageBed/genomeCoverageMain.cpp
@@ -59,25 +59,27 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
  		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-g", 2, parameterLength)) {
-			haveGenome = true;
-			genomeFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveGenome = true;
+				genomeFile = argv[i + 1];
+				i++;
+			}
 		}	
 		else if(PARAMETER_CHECK("-d", 2, parameterLength)) {
 			eachBase = true;
 		}
-		//else if(PARAMETER_CHECK("-s", 2, parameterLength)) {
-		//	startSites = true;
-		//	i++;
-		//}
 		else if(PARAMETER_CHECK("-max", 4, parameterLength)) {
-			max = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				max = atoi(argv[i + 1]);
+				i++;
+			}
 		}
 		else {
 		  cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
diff --git a/src/intersectBed/intersectMain.cpp b/src/intersectBed/intersectMain.cpp
index f623262f..27098694 100755
--- a/src/intersectBed/intersectMain.cpp
+++ b/src/intersectBed/intersectMain.cpp
@@ -73,23 +73,23 @@ int main(int argc, char* argv[]) {
 				haveBedA = true;
 				outputIsBam = false;
 				bedAFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-abam", 5, parameterLength)) {
 			if ((i+1) < argc) {
 				haveBedA = true;
 				inputIsBam = true;
-				bedAFile = argv[i + 1];			
-			}
-			i++;
+				bedAFile = argv[i + 1];
+				i++;		
+			}	
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
 			if ((i+1) < argc) {
 				haveBedB = true;
 				bedBFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-bed", 4, parameterLength)) {
 			outputIsBam = false;
@@ -98,9 +98,11 @@ int main(int argc, char* argv[]) {
 			anyHit = true;
 		}
 		else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
-			haveFraction = true;
-			overlapFraction = atof(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveFraction = true;
+				overlapFraction = atof(argv[i + 1]);
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-wa", 3, parameterLength)) {
 			writeA = true;
diff --git a/src/linksBed/linksMain.cpp b/src/linksBed/linksMain.cpp
index 267f8aeb..f5b8ea2a 100755
--- a/src/linksBed/linksMain.cpp
+++ b/src/linksBed/linksMain.cpp
@@ -57,21 +57,29 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-base", 5, parameterLength)) {
-			base = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				base = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-org", 4, parameterLength)) {
-			org = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				org = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-db", 3, parameterLength)) {
-			db = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				db = argv[i + 1];
+				i++;
+			}
 		}	
 		else {
 			cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
diff --git a/src/maskFastaFromBed/maskFastaFromBedMain.cpp b/src/maskFastaFromBed/maskFastaFromBedMain.cpp
index 0d9957d0..00add002 100755
--- a/src/maskFastaFromBed/maskFastaFromBedMain.cpp
+++ b/src/maskFastaFromBed/maskFastaFromBedMain.cpp
@@ -62,19 +62,25 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-fi", 3, parameterLength)) {
-			haveFastaIn = true;
-			fastaInFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveFastaIn = true;
+				fastaInFile = argv[i + 1];
+				i++;
+			}
 		} 
 		else if(PARAMETER_CHECK("-fo", 3, parameterLength)) {
-			haveFastaOut = true;
-			fastaOutFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveFastaOut = true;
+				fastaOutFile = argv[i + 1];
+				i++;
+			}
 		} 
 		else if(PARAMETER_CHECK("-bed", 4, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-soft", 5, parameterLength)) {
 			softMask = true;
diff --git a/src/mergeBed/mergeMain.cpp b/src/mergeBed/mergeMain.cpp
index f00037ea..3fde15ee 100755
--- a/src/mergeBed/mergeMain.cpp
+++ b/src/mergeBed/mergeMain.cpp
@@ -60,17 +60,21 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-n", 2, parameterLength)) {
 			numEntries = true;
 		}
 		else if(PARAMETER_CHECK("-d", 2, parameterLength)) {
-			haveMaxDistance = true;
-			maxDistance = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveMaxDistance = true;
+				maxDistance = atoi(argv[i + 1]);
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-s", 2, parameterLength)) {
 			forceStrand = true;
diff --git a/src/pairToBed/pairToBedMain.cpp b/src/pairToBed/pairToBedMain.cpp
index 0dce99d5..5b50666c 100755
--- a/src/pairToBed/pairToBedMain.cpp
+++ b/src/pairToBed/pairToBedMain.cpp
@@ -69,6 +69,7 @@ int main(int argc, char* argv[]) {
 				haveBedA = true;
 				outputIsBam  = false;
 				bedAFile = argv[i + 1];
+				i++;
 			}
 			i++;
 		}
@@ -77,15 +78,16 @@ int main(int argc, char* argv[]) {
 				haveBedA = true;
 				inputIsBam = true;
 				bedAFile = argv[i + 1];			
+				i++;
 			}
-			i++;
+			
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
 			if ((i+1) < argc) {
 				haveBedB = true;
 				bedBFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-bedpe", 6, parameterLength)) {
 			outputIsBam = false;
@@ -94,13 +96,15 @@ int main(int argc, char* argv[]) {
 			if ((i+1) < argc) {
 				haveSearchType = true;
 				searchType = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
-			haveFraction = true;
-			overlapFraction = atof(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveFraction = true;
+				overlapFraction = atof(argv[i + 1]);
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-s", 2, parameterLength)) {
 			forceStrand = true;
diff --git a/src/pairToPair/pairToPairMain.cpp b/src/pairToPair/pairToPairMain.cpp
index e2e8a1b1..aec4986d 100755
--- a/src/pairToPair/pairToPairMain.cpp
+++ b/src/pairToPair/pairToPairMain.cpp
@@ -66,31 +66,32 @@ int main(int argc, char* argv[]) {
 			if ((i+1) < argc) {
 				haveBedA = true;
 				bedAFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
 			if ((i+1) < argc) {
 				haveBedB = true;
 				bedBFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}	
 		else if(PARAMETER_CHECK("-type", 5, parameterLength)) {
 			if ((i+1) < argc) {
 				haveSearchType = true;
 				searchType = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
-			haveFraction = true;
-			overlapFraction = atof(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveFraction = true;
+				overlapFraction = atof(argv[i + 1]);
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-is", 3, parameterLength)) {
 			ignoreStrand = true;
-			i++;
 		}
 		else {
 			cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
diff --git a/src/shuffleBed/shuffleBedMain.cpp b/src/shuffleBed/shuffleBedMain.cpp
index bed823d5..c996ca19 100755
--- a/src/shuffleBed/shuffleBedMain.cpp
+++ b/src/shuffleBed/shuffleBedMain.cpp
@@ -61,24 +61,32 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
  		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-g", 2, parameterLength)) {
-			haveGenome = true;
-			genomeFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveGenome = true;
+				genomeFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-excl", 5, parameterLength)) {
-			haveExclude = true;
-			excludeFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveExclude = true;
+				excludeFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-seed", 5, parameterLength)) {
-			haveSeed = true;
-			seed = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveSeed = true;
+				seed = atoi(argv[i + 1]);
+				i++;
+			}
 		}	
 		else if(PARAMETER_CHECK("-chrom", 6, parameterLength)) {
 			sameChrom = true;
diff --git a/src/slopBed/slopBedMain.cpp b/src/slopBed/slopBedMain.cpp
index 4504d28a..e4f35fed 100755
--- a/src/slopBed/slopBedMain.cpp
+++ b/src/slopBed/slopBedMain.cpp
@@ -63,34 +63,43 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
  		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-g", 2, parameterLength)) {
-			haveGenome = true;
-			genomeFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveGenome = true;
+				genomeFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-l", 2, parameterLength)) {
-			haveLeft = true;
-			leftSlop = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveLeft = true;
+				leftSlop = atoi(argv[i + 1]);
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-r", 2, parameterLength)) {
-			haveRight = true;			
-			rightSlop = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveRight = true;			
+				rightSlop = atoi(argv[i + 1]);
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
-			haveBoth = true;
-			leftSlop = atoi(argv[i + 1]);
-			rightSlop = atoi(argv[i + 1]);			
-			i++;
+			if ((i+1) < argc) {
+				haveBoth = true;
+				leftSlop = atoi(argv[i + 1]);
+				rightSlop = atoi(argv[i + 1]);			
+				i++;
+			}
 		}				
 		else if(PARAMETER_CHECK("-s", 2, parameterLength)) {
 			forceStrand = true;
-			i++;
 		}	
 		else {
 		  cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
diff --git a/src/sortBed/sortMain.cpp b/src/sortBed/sortMain.cpp
index bfb83edb..d5bea823 100755
--- a/src/sortBed/sortMain.cpp
+++ b/src/sortBed/sortMain.cpp
@@ -60,39 +60,35 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-i", 2, parameterLength)) {
-			haveBed = true;
-			bedFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBed = true;
+				bedFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-sizeA", 6, parameterLength)) {
 			sortBySizeAsc = true;
 			sortChoices++;
-			i++;
 		}
 		else if(PARAMETER_CHECK("-sizeD", 6, parameterLength)) {
 			sortBySizeDesc = true;
 			sortChoices++;
-			i++;
 		}
 		else if(PARAMETER_CHECK("-chrThenSizeA", 13, parameterLength)) {
 			sortByChromThenSizeAsc = true;
 			sortChoices++;
-			i++;
 		}
 		else if(PARAMETER_CHECK("-chrThenSizeD", 13, parameterLength)) {
 			sortByChromThenSizeDesc = true;
 			sortChoices++;
-			i++;
 		}	
 		else if(PARAMETER_CHECK("-chrThenScoreA", 14, parameterLength)) {
 			sortByChromThenScoreAsc = true;
 			sortChoices++;
-			i++;
 		}
 		else if(PARAMETER_CHECK("-chrThenScoreD", 14, parameterLength)) {
 			sortByChromThenScoreDesc = true;
 			sortChoices++;
-			i++;
 		}	
 		else {
 			cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
diff --git a/src/subtractBed/subtractMain.cpp b/src/subtractBed/subtractMain.cpp
index 7889a386..3efccc19 100755
--- a/src/subtractBed/subtractMain.cpp
+++ b/src/subtractBed/subtractMain.cpp
@@ -64,20 +64,22 @@ int main(int argc, char* argv[]) {
 			if ((i+1) < argc) {
 				haveBedA = true;
 				bedAFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
 			if ((i+1) < argc) {
 				haveBedB = true;
 				bedBFile = argv[i + 1];
+				i++;
 			}
-			i++;
 		}	
 		else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
-			haveFraction = true;
-			overlapFraction = atof(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveFraction = true;
+				overlapFraction = atof(argv[i + 1]);
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-s", 2, parameterLength)) {
 			forceStrand = true;
diff --git a/src/windowBed/windowMain.cpp b/src/windowBed/windowMain.cpp
index 5346b653..bc8f1e12 100755
--- a/src/windowBed/windowMain.cpp
+++ b/src/windowBed/windowMain.cpp
@@ -68,14 +68,18 @@ int main(int argc, char* argv[]) {
 		int parameterLength = (int)strlen(argv[i]);
 
 		if(PARAMETER_CHECK("-a", 2, parameterLength)) {
-			haveBedA = true;
-			bedAFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBedA = true;
+				bedAFile = argv[i + 1];
+				i++;
+			}
 		}
 		else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
-			haveBedB = true;
-			bedBFile = argv[i + 1];
-			i++;
+			if ((i+1) < argc) {
+				haveBedB = true;
+				bedBFile = argv[i + 1];
+				i++;
+			}
 		}	
 		else if(PARAMETER_CHECK("-u", 2, parameterLength)) {
 			anyHit = true;
@@ -93,20 +97,26 @@ int main(int argc, char* argv[]) {
 			matchOnStrand = true;
 		}
 		else if (PARAMETER_CHECK("-w", 2, parameterLength)) {
-			haveSlop = true;
-			leftSlop = atoi(argv[i + 1]);
-			rightSlop = leftSlop;
-			i++;
+			if ((i+1) < argc) {
+				haveSlop = true;
+				leftSlop = atoi(argv[i + 1]);
+				rightSlop = leftSlop;
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-l", 2, parameterLength)) {
-			haveLeft = true;
-			leftSlop = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveLeft = true;
+				leftSlop = atoi(argv[i + 1]);
+				i++;
+			}
 		}
 		else if (PARAMETER_CHECK("-r", 2, parameterLength)) {
-			haveRight = true;
-			rightSlop = atoi(argv[i + 1]);
-			i++;
+			if ((i+1) < argc) {
+				haveRight = true;
+				rightSlop = atoi(argv[i + 1]);
+				i++;
+			}
 		}		
 		else {
 			cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
-- 
GitLab