/* * === FUNCTION ====================================================================== * Name: uri_remove_dot_segments * Description: Implements RFC 3986 section 5.2.4 * use for interpreting and removing the special "." and ".." complete * path segments from a referenced path. This is done after the path is * extracted from a reference, whether or not the path was relative, in * order to remove any invalid or extraneous dot-segments prior to * forming the target URI. Although there are many ways to accomplish * this removal process, we describe a simple method using two string * buffers. * * ===================================================================================== */ extern char * uri_remove_dot_segments( char **path ) { char *ou_buffer = NULL, *in_buffer = NULL, *segment = NULL, sl = '\0'; int len = 0; if( *(path) == NULL ) { return NULL; } in_buffer = strdup( *(path)); len = strlen( in_buffer ) + 1; ou_buffer = (char *) malloc( len ); ou_buffer[0] = '\0'; while( in_buffer != NULL ){ segment = get_next_segment( &in_buffer); if( strcmp( segment, "../") == 0 || strcmp(segment,"./") == 0){ shift_segment( &in_buffer, 0); } else if( strcmp(segment, "/./") == 0 || strcmp(segment,"/.") == 0){ replace_prefix( &in_buffer); } else if( strcmp( segment,"/../") == 0 || strcmp(segment,"/..") == 0){ replace_prefix(&in_buffer); pop_segment(&ou_buffer); } else if( strcmp( in_buffer, ".") == 0 || strcmp( in_buffer, "..") == 0){ in_buffer = NULL; } else if( segment) { sl = segment[ strlen(segment) - 1]; if( sl == '/'){ segment = shift_segment(&in_buffer, 0); } else { segment = shift_segment(&in_buffer, 1); } strcat(ou_buffer, segment); } } len = strlen(ou_buffer) + 1; realloc( (void *) ou_buffer, len); return ou_buffer; }
void dot_multi(long npoint, long nvector, double** data, long* segments, double* output) { long segment_end = *segments; for (long ipoint=0; ipoint < npoint; ipoint++) { // shift the output array if needed shift_segment(ipoint, segments, segment_end, output, 1); // add product to output *output += data_product(ipoint, nvector, data); #ifdef DEBUG printf("*output=%f; ipoint=%i; segment_end=%i\n", *output, ipoint, segment_end); #endif } }
void dot_multi_moments(long npoint, long nvector, double** data, double* points, double* center, long lmax, long mtype, long* segments, double* output, long nmoment) { if (lmax<0) { throw std::domain_error("lmax can not be negative."); } if ((mtype < 1) || (mtype > 4)) { throw std::domain_error("mtype should be 1, 2, 3 or 4."); } long segment_end = *segments; for (long ipoint=0; ipoint < npoint; ipoint++) { // shift the output array if needed shift_segment(ipoint, segments, segment_end, output, nmoment); // do the usual product of integranda double term = data_product(ipoint, nvector, data); output[0] += term; if (lmax > 0) { // construct relative vector double delta[3]; delta[0] = points[ipoint*3 ] - center[0]; delta[1] = points[ipoint*3+1] - center[1]; delta[2] = points[ipoint*3+2] - center[2]; // evaluate polynomials in work array double work[nmoment-1]; fill_polynomials_wrapper(work, delta, lmax, mtype); // add product of polynomial and integrand to output for (long imoment=1; imoment < nmoment; imoment++) { output[imoment] += term*work[imoment-1]; } } } }