char *format(char *message, char *twitter_date, int utc_offset) { char *safe_message = ALLOC_STR(140); strlcpy(safe_message, message, 141); char *placeholder_message = Formatting::add_date_placeholder(safe_message); char *cleaned = Formatting::utf8_strip(placeholder_message); xfree(placeholder_message); uint8_t word_count = 0; char **words = Formatting::strsplit(cleaned, &word_count); xfree(cleaned); char *justified = Formatting::justify(words, word_count); for (int i = 0; i < word_count; ++i) { xfree(words[i]); } xfree(words); char *date = Formatting::convert_date(twitter_date, utc_offset); char *result = Formatting::add_date(justified, date); xfree(date); return result; }
/* IMPORTANT: be sure to free() the returned string after use */ char *url_encode(const char *str) { char current; const char *cursor = NULL; // if all bytes need encoding, the string will grow with a maximum of three // times its own size char *result = ALLOC_STR(strlen(str) * 3); char *result_cursor = result; for (cursor = str; (current = *cursor); cursor++) // let’s hope all our urlencoded strings ends with \0 { if (isalnum(current) || current == '-' || current == '_' || current == '.' || current == '~') { *result_cursor++ = current; } else if (current == ' ') { *result_cursor++ = '+'; } else { *result_cursor++ = '%'; *result_cursor++ = to_hex(current >> 4); *result_cursor++ = to_hex(current & 0x0F); } } *result_cursor = '\0'; return result; }
sp_link * sp_link_create_from_user(sp_user *user) { sp_link *link = ALLOC(sp_link); link->data = ALLOC_STR(strlen("spotify:user:"******"spotify:user:%s", user->canonical_name); return link; }
sp_link * sp_link_create_from_search(sp_search *search) { char *uri_encoded = url_encode(search->query); char *uri = ALLOC_STR(strlen("spotify:search:") + strlen(uri_encoded)); sprintf(uri, "spotify:search:%s", uri_encoded); return sp_link_create_from_string(uri); }
/******************************************************************************* * Call for individual allocation routines to size the run-time arrays. *******************************************************************************/ void setup_alloc( input_data *input_vars, para_data *para_vars, sn_data *sn_vars, data_data *data_vars, int *flg, int *ierr, char **error ) { int tmpStrLen = 0; *flg = 0; sn_allocate ( sn_vars, input_vars, ierr ); glmax_i ( ierr, COMM_SNAP ); if ( *ierr != 0 ) { tmpStrLen = strlen ( "***ERROR: SETUP_ALLOC: " "Allocation error in SN_ALLOCATE\n" ); ALLOC_STR(*error, tmpStrLen + 1, ierr); snprintf ( (char *) *error, tmpStrLen + 1, "***ERROR: SETUP_ALLOC: " "Allocation error in SN_ALLOCATE\n" ); return; } data_allocate( data_vars, input_vars, sn_vars, ierr ); glmax_i ( ierr, COMM_SNAP ); if ( *ierr != 0 ) { *flg = 1; tmpStrLen = strlen ( "***ERROR: SETUP_ALLOC: " "Allocation error in DATA_ALLOCATE\n" ); ALLOC_STR(*error, tmpStrLen + 1, ierr); snprintf ( (char *) *error, tmpStrLen + 1, "***ERROR: SETUP_ALLOC: " "Allocation error in DATA_ALLOCATE\n" ); return; } }
sp_playlist * sp_session_starred_for_user_create(sp_session *session, const char *name) { char *link; if (sp_session_connectionstate(session) != SP_CONNECTION_STATE_LOGGED_IN) { return NULL; } link = ALLOC_STR(strlen("spotify:user:"******":starred")); sprintf(link, "spotify:user:%s:starred", name); return (sp_playlist *)registry_find(link); }
char * strclone(const char *string) { char *clone = NULL; if (string == NULL) { return NULL; } clone = ALLOC_STR(strlen(string)); strcpy(clone, string); return clone; }
/* * Takes a string of UTF8-encoded data and strips all characters we cannot use. * * - multibyte characters we can display are mapped over * - all other multibyte characters are stripped * - characters we cannot handle are turned into nulls * * Also see: http://en.wikipedia.org/wiki/Utf8 */ char *utf8_strip(const char *dirty) { // optimistic result: we end up with the same string uint8_t length = strlen(dirty), ci = 0, di = 0; unsigned char bytes = 0; unsigned char current = 0x00, next = 0x00; char *cleaned = ALLOC_STR(length); // iterate character by character and replace it for (di = 0, ci = 0; di < length; di++) { current = dirty[di]; if ( ! valid_utf8(current)) // invalid byte { continue; } else if ( ! is_ascii(current)) // multibyte { if (current == 0xC3 && (di + 1) < length) // might be åäöÅÄÖ, they all are 0xC3xx { next = dirty[++di]; // we consume the next character if (is_ascii(next)) // somehow, next byte is ascii (invalid utf8), so abort { // we cannot safely map the next byte in our charmap as it’ll collide // with the ascii characters which might be bad! continue; } else { current = next; } } else // skip all the additional bytes { bytes = (current & 0xF0); // 1111 xxxx while (bytes <<= 1) di += 1; current = '\0'; // let charmap handle it } } cleaned[ci++] = charmap[current]; } return cleaned; }
/* Parse out the value located at current input data line */ void get_input_value ( char *lineData, char *valueID, char **tmpData ) { int tmpStrLen = 0; int ierr = 0; // Trim all excess chars and white space following immediate input value while ( !(isspace(lineData[strlen(valueID) + tmpStrLen])) ) { tmpStrLen += 1; } ALLOC_STR( *tmpData, tmpStrLen, &ierr ); // Copies value to tmpData string, snprintf ( *tmpData, tmpStrLen+1, "%s", &lineData[strlen(valueID)] ); }
sp_playlistcontainer * sp_session_publishedcontainer_for_user_create(sp_session *session, const char *username) { char *link; if (sp_session_connectionstate(session) != SP_CONNECTION_STATE_LOGGED_IN) { return NULL; } if (username == NULL && session->user) { username = session->user->canonical_name; } link = ALLOC_STR(strlen("spotify:container:") + strlen(username)); sprintf(link, "spotify:container:%s", username); return (sp_playlistcontainer *)registry_find(link); }
sp_link * sp_link_create_from_track(sp_track *track, int offset) { const char *link = registry_reverse_find((void *) track); int mins = 0, secs = 0; char *link_with_offset = NULL; if (offset > 0) { link_with_offset = ALLOC_STR(strlen(link) + strlen("#00:00")); offset = offset / 1000; mins = (offset / 60) % 60; secs = (offset - mins * 60) % 60; sprintf(link_with_offset, "%s", link); sprintf(link_with_offset + strlen(link), "#%02d:%02d", mins, secs); return sp_link_create_from_string(link_with_offset); } else { return sp_link_create_from_string(link); } }
/*********************************************************************** * Read the input file. ***********************************************************************/ int read_input ( FILE *fp_in, FILE *fp_out, input_data *input_vars, para_data *para_vars, time_data *time_vars ) { /*********************************************************************** * Local variables. ***********************************************************************/ double t1, t2; int ierr = 0; char *error = NULL; char *line = NULL; size_t len = 0; ssize_t read; char *tmpData = NULL; int tmpStrLen, i; /*********************************************************************** * Read the input file. Echo to output file. Call for an input variable * check. Only root reads, echoes, checks input. ***********************************************************************/ t1 = wtime (); if ( IPROC == ROOT ) { if ( !fp_in ) { tmpStrLen = strlen (" ***ERROR: READ_INPUT:" " Problem reading input file.\n"); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: READ_INPUT:" " Problem reading input file.\n" ); print_error ( fp_out, error, IPROC, ROOT ); FREE ( error ); ierr = 1; } else { while ( (read = getline(&line, &len, fp_in)) != -1 ) { i = 0; while ( isspace(line[i]) ) { i++; } // Parallel processing inputs // npey: number of process elements in y-dir if ( strncmp(&line[i], "npey=", strlen("npey=")) == 0 ) { get_input_value ( &line[i], "npey=", &tmpData ); NPEY = atoi ( tmpData ); } // npez: input number of process elements in z-dir else if ( strncmp(&line[i], "npez=", strlen("npez=")) == 0 ) { get_input_value ( &line[i], "npez=", &tmpData ); NPEZ = atoi ( tmpData ); } // ichunk: else if ( strncmp(&line[i], "ichunk=", strlen("ichunk=")) == 0 ) { get_input_value ( &line[i], "ichunk=", &tmpData ); ICHUNK = atoi ( tmpData ); } // nthreads: input number of threads else if ( strncmp(&line[i], "nthreads=", strlen("nthreads=")) == 0 ) { get_input_value ( &line[i], "nthreads=", &tmpData ); NTHREADS = atoi ( tmpData ); } // nnested: else if ( strncmp(&line[i], "nnested=", strlen("nnested=")) == 0 ) { get_input_value ( &line[i], "nnested=", &tmpData ); NNESTED = atoi ( tmpData ); } // Geometry inputs // ndimen: else if ( strncmp(&line[i], "ndimen=", strlen("ndimen=")) == 0 ) { get_input_value ( &line[i], "ndimen=", &tmpData ); NDIMEN = atoi ( tmpData ); } // nx: else if ( strncmp(&line[i], "nx=", strlen("nx=")) == 0 ) { get_input_value ( &line[i], "nx=", &tmpData ); NX = atoi ( tmpData ); } // ny: else if ( strncmp(&line[i], "ny=", strlen("ny=")) == 0 ) { get_input_value ( &line[i], "ny=", &tmpData ); NY = atoi ( tmpData ); } // nz: else if ( strncmp(&line[i], "nz=", strlen("nz=")) == 0 ) { get_input_value ( &line[i], "nz=", &tmpData ); NZ = atoi ( tmpData ); } // lx: else if ( strncmp(&line[i], "lx=", strlen("lx=")) == 0 ) { get_input_value ( &line[i], "lx=", &tmpData ); LX = atof ( tmpData ); } // ly: else if ( strncmp(&line[i], "ly=", strlen("ly=")) == 0 ) { get_input_value ( &line[i], "ly=", &tmpData ); LY = atof ( tmpData ); } // lz: else if ( strncmp(&line[i], "lz=", strlen("lz=")) == 0 ) { get_input_value ( &line[i], "lz=", &tmpData ); LZ = atof ( tmpData ); } // Sn inputs // nmom: else if ( strncmp(&line[i], "nmom=", strlen("nmom=")) == 0 ) { get_input_value ( &line[i], "nmom=", &tmpData ); NMOM = atoi ( tmpData ); } // nang: else if ( strncmp(&line[i], "nang=", strlen("nang=")) == 0 ) { get_input_value ( &line[i], "nang=", &tmpData ); NANG = atoi ( tmpData ); } // Data inputs // ng: else if ( strncmp(&line[i], "ng=", strlen("ng=")) == 0 ) { get_input_value ( &line[i], "ng=", &tmpData ); NG = atoi ( tmpData ); } // mat_opt: else if ( strncmp(&line[i], "mat_opt=", strlen("mat_opt=")) == 0 ) { get_input_value ( &line[i], "mat_opt=", &tmpData ); MAT_OPT = atoi ( tmpData ); } // src_opt: else if ( strncmp(&line[i], "src_opt=", strlen("src_opt=")) == 0 ) { get_input_value ( &line[i], "src_opt=", &tmpData ); SRC_OPT = atoi ( tmpData ); } // scatp: else if ( strncmp(&line[i], "scatp=", strlen("scatp=")) == 0 ) { get_input_value ( &line[i], "scatp=", &tmpData ); SCATP = atoi ( tmpData ); } // Control inputs // epsi: else if ( strncmp(&line[i], "epsi=", strlen("epsi=")) == 0 ) { get_input_value ( &line[i], "epsi=", &tmpData ); EPSI = atof ( tmpData ); } // tf: else if ( strncmp(&line[i], "tf=", strlen("tf=")) == 0 ) { get_input_value ( &line[i], "tf=", &tmpData ); TF = atof ( tmpData ); } // iitm: else if ( strncmp(&line[i], "iitm=", strlen("iitm=")) == 0 ) { get_input_value ( &line[i], "iitm=", &tmpData ); IITM = atoi ( tmpData ); } // oitm: else if ( strncmp(&line[i], "oitm=", strlen("oitm=")) == 0 ) { get_input_value ( &line[i], "oitm=", &tmpData ); OITM = atoi ( tmpData ); } // timedep: else if ( strncmp(&line[i], "timedep=", strlen("timedep=")) == 0 ) { get_input_value ( &line[i], "timedep=", &tmpData ); TIMEDEP = atoi ( tmpData ); } // nsteps: else if ( strncmp(&line[i], "nsteps=", strlen("nsteps=")) == 0 ) { get_input_value ( &line[i], "nsteps=", &tmpData ); NSTEPS = atoi ( tmpData ); } // it_det: else if ( strncmp(&line[i], "it_det=", strlen("it_det=")) == 0 ) { get_input_value ( &line[i], "it_det=", &tmpData ); IT_DET = atoi ( tmpData ); } // fluxp: else if ( strncmp(&line[i], "fluxp=", strlen("fluxp=")) == 0 ) { get_input_value ( &line[i], "fluxp=", &tmpData ); FLUXP = atoi ( tmpData ); } // fixup: else if ( strncmp(&line[i], "fixup=", strlen("fixup=")) == 0 ) { get_input_value ( &line[i], "fixup=", &tmpData ); FIXUP = atoi ( tmpData ); } } // Free temp data from memory FREE ( tmpData ); } } bcast_i_scalar ( &ierr, COMM_SNAP, ROOT, NPROC ); if ( ierr != 0 ) { return ierr; } if ( IPROC == ROOT ) { input_echo ( input_vars, fp_out ); ierr = input_check ( fp_out, input_vars, para_vars ); } /*********************************************************************** * Broadcast the data to all processes. ***********************************************************************/ ierr = var_bcast ( input_vars, para_vars ); t2 = wtime(); time_vars->tinp = t2 - t1; return ierr; }
/*********************************************************************** * Checks input for valid entries. ***********************************************************************/ int input_check ( FILE *fp_out, input_data *input_vars, para_data *para_vars ) { // Local variables char *error = NULL; int ierr = 0; int tmpStrLen; // Check the parallel environment variables. // Parallel processing inputs. if ( NPEY < 1 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEY must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NPEY must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NPEZ < 1 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEZ must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NPEZ must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN > 1) && (NY % NPEY != 0) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEY must divide evenly into NY\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NPEY must divide evenly into NY\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN > 2) && (NZ % NPEZ != 0) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEZ must divide evenly into NZ\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NPEZ must divide evenly into NZ\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN < 2) && (NPEY != 1) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEY must be 1 if not 2-D problem\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NPEY must be 1 if not 2-D problem\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN < 3) && (NPEZ != 1) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEZ must be 1 if not 3-D problem\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NPEZ must be 1 if not 3-D problem\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NPEY * NPEZ != NPROC ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NPEY*NPEZ must equal MPI NPROC\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1 , " ***ERROR: INPUT_CHECK:" " NPEY*NPEZ must equal MPI NPROC\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( ICHUNK > NX ) { ICHUNK = NX; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " ICHUNK cannot exceed NX; reset to NX\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " ICHUNK cannot exceed NX; reset to NX\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN == 1) && (ICHUNK != NX) ) ICHUNK = NX; if ( NX % ICHUNK != 0 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " ICHUNK must divide evenly into NX\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " ICHUNK must divide evenly into NX\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NTHREADS < 1 ) { NTHREADS = 1; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " NTHREADS must be positive;" " reset to 1\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " NTHREADS must be positive;" " reset to 1\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NNESTED < 0 ) { NNESTED = 0; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " NNESTED must be non-negative;" " reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " NNESTED must be non-negative;" " reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NNESTED == 1 ) { NNESTED = 0; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " NNESTED=1 same as 0+overhead;" " reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " NNESTED=1 same as 0+overhead;" " reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } // Geometry inputs. if ( (NDIMEN < 1) || (NDIMEN > 3) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NDIMEN must be 1, 2, or 3\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NDIMEN must be 1, 2, or 3\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NX < 4 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NX must be at least 4\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NX must be at least 4\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NY < 4) && (NDIMEN > 1) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NY must be at least 4\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NY must be at least 4\n"); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NZ < 4) && (NDIMEN > 2) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NZ must be at least 4\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NZ must be at least 4\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( LX <= 0 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " LX must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " LX must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( LY <= 0 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " LY must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " LY must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( LZ <= 0 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " LZ must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " LZ must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN < 2) && ((NY > 1) || (LY != 1)) ) { NY = 1; LY = 0; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " NY and LY reset for 1-D problem\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" "NY and LY reset for 1-D problem\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (NDIMEN < 3) && ((NZ > 1) || (LZ != 1)) ) { NZ = 1; LZ = 0; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " NZ and LZ reset for 1/2-D problem\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " NZ and LZ reset for 1/2-D problem\n" ); print_error ( fp_out, error, IPROC, ROOT ); } // Sn inputs. if ( (NMOM < 1) || (NMOM > 4) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NMOM must be positive and less than 5\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NMOM must be positive and less than 5\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NANG < 1 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NANG must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NANG must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } // Data inputs. if ( NG < 1 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NG must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NG must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( NTHREADS > NG ) { NTHREADS = NG; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " NTHREADS should be <= NG;" " reset to NG\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " NTHREADS should be <= NG;" " reset to NG\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (MAT_OPT < 0) || (MAT_OPT > 2) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " MAT_OPT must be 0/1/2\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " MAT_OPT must be 0/1/2\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (SRC_OPT < 0) || (SRC_OPT > 3) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " SRC_OPT must be 0/1/2/3\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " SRC_OPT must be 0/1/2/3\n" ); print_error ( fp_out, error, IPROC, ROOT ); } // Commented out in original code // if ( (SRC_OPT == 3) && (MAT_OPT != 0) ) // { // MAT_OPT = 0; // // tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" // " MAT_OPT must be 0 for SRC_OPT=3\n" ); // ALLOC_STR ( error, tmpStrLen + 1, &ierr ); // snprintf ( error, tmpStrLen + 1, // " *WARNING: INPUT_CHECK:" // " MAT_OPT must be 0 for SRC_OPT=3\n" ); // // print_error ( fp_out, error, IPROC, ROOT ); // } if ( (SCATP != 0) && (SCATP != 1) ) { SCATP = 0; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " SCATP must be 0/1; reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " SCATP must be 0/1; reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } // Control inputs. if ( (EPSI <= 0) || (EPSI >= 1.0E-2) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " EPSI must be positive, less than 1.0E-2\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " EPSI must be positive, less than 1.0E-2\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( IITM < 1 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " IITM must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " IITM must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( OITM < 1 ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " OITM must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " OITM must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (TIMEDEP != 0) && (TIMEDEP != 1) ) { TIMEDEP = 0; tmpStrLen = strlen ( " *WARNING: INPUT_CHECK:" " TIMEDEP must be 0/1; reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " *WARNING: INPUT_CHECK:" " TIMEDEP must be 0/1; reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (TIMEDEP == 1) && (TF <= 0) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " TF must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " TF must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (TIMEDEP == 1) && (NSTEPS < 1) ) { ierr = ierr + 1; tmpStrLen = strlen ( " ***ERROR: INPUT_CHECK:" " NSTEPS must be positive\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***ERROR: INPUT_CHECK:" " NSTEPS must be positive\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (TIMEDEP == 0) && (NSTEPS != 1) ) { NSTEPS = 1; tmpStrLen = strlen ( " ***WARNING: INPUT_CHECK:" " NSTEPS reset to 1 for static calc\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***WARNING: INPUT_CHECK:" " NSTEPS reset to 1 for static calc\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (IT_DET != 0) && (IT_DET != 1) ) { IT_DET = 0; tmpStrLen = strlen ( " ***WARNING: INPUT_CHECK:" " IT_DET must equal 0/1; reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***WARNING: INPUT_CHECK:" " IT_DET must equal 0/1; reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (FLUXP < 0) || (FLUXP > 2) ) { FLUXP = 0; tmpStrLen = strlen ( " ***WARNING: INPUT_CHECK:" " FLUXP must equal 0/1/2; reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***WARNING: INPUT_CHECK:" " FLUXP must equal 0/1/2; reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } if ( (FIXUP != 0) && (FIXUP != 1) ) { FIXUP = 0; tmpStrLen = strlen ( " ***WARNING: INPUT_CHECK:" " FIXUP must equal 0/1; reset to 0\n" ); ALLOC_STR ( error, tmpStrLen + 1, &ierr ); snprintf ( error, tmpStrLen + 1, " ***WARNING: INPUT_CHECK:" " FIXUP must equal 0/1; reset to 0\n" ); print_error ( fp_out, error, IPROC, ROOT ); } return ierr; }
sp_search * sp_mock_search_create(sp_error error, const char *query, const char *did_you_mean, int total_tracks, int num_tracks, const sp_track **tracks, int total_albums, int num_albums, const sp_album **albums, int total_artists, int num_artists, const sp_artist **artists, int total_playlists, int num_playlists, const sp_playlist **playlists, search_complete_cb *callback, void *userdata) { int i = 0, length = 0; sp_link *uri = NULL; sp_session *session = NULL; sp_image *image = NULL; sp_search *search = ALLOC(sp_search); search->error = error; search->query = strclone(query); if (did_you_mean) { search->did_you_mean = strclone(did_you_mean); } search->total_tracks = total_tracks; search->total_artists = total_artists; search->total_albums = total_albums; search->total_playlists = total_playlists; search->num_tracks = num_tracks; search->num_artists = num_artists; search->num_albums = num_albums; search->num_playlists = search->num_playlist_names = search->num_playlist_uris = search->num_playlist_image_uris = num_playlists; search->tracks = ALLOC_N(sp_track *, num_tracks); search->artists = ALLOC_N(sp_artist *, num_artists); search->albums = ALLOC_N(sp_album *, num_artists); MEMCPY_N(search->tracks, tracks, sp_track *, num_tracks); MEMCPY_N(search->artists, artists, sp_artist *, num_artists); MEMCPY_N(search->albums, albums, sp_album *, num_albums); search->playlist_names = ALLOC_N(char *, num_playlists); search->playlist_uris = ALLOC_N(char *, num_playlists); search->playlist_image_uris = ALLOC_N(char *, num_playlists); for (i = 0; i < num_playlists; ++i) { const sp_playlist *playlist = playlists[i]; search->playlist_names[i] = strclone(playlist->name); uri = sp_link_create_from_playlist((sp_playlist *) playlist); if (uri) { length = sp_link_as_string(uri, NULL, 0); search->playlist_uris[i] = ALLOC_STR(length); sp_link_as_string(uri, search->playlist_uris[i], length + 1); } if (playlist->image) { image = sp_image_create(session, playlist->image); if (image) { uri = sp_link_create_from_image(image); length = sp_link_as_string(uri, NULL, 0); search->playlist_image_uris[i] = ALLOC_STR(length); sp_link_as_string(uri, search->playlist_image_uris[i], length + 1); } } } search->callback = callback; search->userdata = userdata; return search; }
int input() { CHAR *p; ival i = 0; value *l; int c; char vty; int (*infunc)(void); int firsttime=0; int noerr; int frfile = 0; STR st = NULL; infunc = in1line; c=getch(); if(c=='"'){ p=line; while(*point && *point != '"'){ *p++ = *point++; i++; } if(*point) point++; if(getch()!=';') error(SYNTAX); *p=0; firsttime++; } else if(c=='#'){ i=evalint(); if(getch()!=',') error(SYNTAX); _curinfile = getf(i, _READ); infunc = in1file; frfile = 1; } else point--; l= (value *)getname(0); vty=vartype; for(;;){ if(!frfile){ if(!firsttime){ *line='?'; i=1; } firsttime=0; VOID edit(i,i,(ival)0); if(trapped){ point=savepoint; /* restore point to start of in. */ return(-1); /* will trap at start of this in. */ } in1iline = line + i; } do { /* ignore leading spaces */ while( (c = (*infunc)()) == ' '); if(!c && vty != SVAL) continue; pushback = c; if(vty == SVAL){ st = ALLOC_STR( (ival)LOC_BUF_SIZ); noerr = getstrdt(infunc, st); } else noerr = getdata(infunc); if(noerr) while( (c = (*infunc)()) == ' '); if(!noerr || (c && c != ',')){ if(vty == SVAL && st != NULL) FREE_STR(st); if(frfile) error(26); prints("Bad data redo\n"); break; } if(vty == SVAL) stringassign( (stringp)l, curentry, st, 0); else putin(l, (int)vty); if(getch()!=','){ point--; normret; } l= (value *)getname(0); vty=vartype; } while(c); } }