array.c
//returns newly allocated array splice from ap from start (incl.) to end (excl.) with step
//step may be negative; if step == 0 only element in return array is at start
//if end < 0, it is set to array length + end (wraps around in reverse)
//if start < 0, it is set to array length + start (wraps around in reverse)
returns newly allocated array splice from ap from start (incl.) to end (excl.) with step
step may be negative; if step == 0 only element in return array is at start
if end < 0, it is set to array length + end (wraps around in reverse)
if start < 0, it is set to array length + start (wraps around in reverse)
returns newly allocated array splice from ap from start ( incl . ) to end ( excl . ) with step step may be negative ; if step == 0 only element in return array is at start if end < 0 it is set to array length + end ( wraps around in reverse ) if start < 0 it is set to array length + start ( wraps around in reverse )
array_t* array_splice(array_t* ap, int start, int end, int step) {
	array_t* ret = new_array(10);
	int i;
	if( start < 0 ) {
		start += ap->length;
	}
	if( end < 0 ) {
		end += ap->length;
	}
	if( (start > ap->length) || (start < 0) ) {
		WARN("start index out of bounds for array splice");
		EXIT();
		return(NULL);
	}
	if( (end > ap->length) || (end < 0) ) {
		WARN("end index out of bounds for array splice");
		EXIT();
		return(NULL);
	}
	if( step == 0 ) {
		array_append(ret, ap->array[start]);
	}
	else if( step > 0 ) {
		for(i=start; i<=end; i+=step) {
			array_append(ret, ap->array[i]);
		}
	}
	else { 
		for(i=start; i>=end; i+=step) {
			array_append(ret, ap->array[i]);
		}
	}
	return(ret);
}
array_t * array_splice ( array_t * ap , int start , int end , int step ) { array_t * ret = new_array ( 10 ) ; int i ; if ( start < 0 ) { start += ap -> length ; } if ( end < 0 ) { end += ap -> length ; } if ( ( start > ap -> length ) || ( start < 0 ) ) { WARN ( " " ) ; EXIT ( ) ; return ( NULL ) ; } if ( ( end > ap -> length ) || ( end < 0 ) ) { WARN ( " " ) ; EXIT ( ) ; return ( NULL ) ; } if ( step == 0 ) { array_append ( ret , ap -> array [ start ] ) ; } else if ( step > 0 ) { for ( i = start ; i <= end ; i += step ) { array_append ( ret , ap -> array [ i ] ) ; } } else { for ( i = start ; i >= end ; i += step ) { array_append ( ret , ap -> array [ i ] ) ; } } return ( ret ) ; }
returns newly allocated array splice from ap from start (incl.)
returns newly allocated array splice from ap from start ( incl . )
//step < 0