void parse_s_def(char *ptr, struct defaults *def) { ptr = clear_space(ptr); char *temp = malloc(strlen(ptr) + 1); if (temp == NULL){error("Out of memory.");} if (sscanf(ptr, "%[^=]", temp) > 1) {error("Bad Defaults String."); } *temp = toupper(*temp); if (*temp == 'D') { ptr = strchr(ptr, '=') + 1; sscanf(ptr, "%d", &(def->len)); } else if (*temp == 'B') { ptr = strchr(ptr, '=') + 1; sscanf(ptr, "%d", &(def->bpm)); } else if (*temp =='O') { ptr = strchr(ptr, '=') + 1; sscanf(ptr, "%d", &(def->oct)); } else { error("Bad Default Identifier."); } free(temp); }
ctype_table(CharPred pred, int mode, WTF const& wtf) { std::copy(wtf, wtf + CT::table_size, rc); if (mode == REPLACE) std::for_each(rc, rc + CT::table_size, clear_space); for (unsigned i = 0; i<CT::table_size; ++i) { std::ctype_base::mask &m = rc[i]; if (pred(i)) { if (mode==REMOVE) clear_space(m); else set_space(m); } else { if (mode==REPLACE) clear_space(m); } } }
void Stringc::rdelete(int istart, int iend) { int i=0; if ((istart > -1)&&(istart < num_chars)&&(iend > -1)&&(iend < num_chars) &&(istart <= iend)) { int new_num = num_chars - (iend-istart+1); int new_size = ((new_num+1)/chunk_size)*chunk_size; if (new_size == total_size) { for( i=istart; i<new_num; i++) char_array[i] = char_array[i+(iend-istart+1)]; num_chars = new_num; char_array[num_chars] = '\0'; } else { int new_length = num_chars - (iend-istart+1); char *new_char = new char[new_length+1]; for (i=0; i<istart; i++) new_char[i] = char_array[i]; int j=istart; for (i=iend+1; i<num_chars; i++) { new_char[j] = char_array[i]; j++; } clear_space(); num_chars = new_length; make_space(); for ( i=0; i<num_chars; i++) char_array[i] = new_char[i]; char_array[num_chars] = '\0'; delete [] new_char; } } else { cout << "num_chars = " << num_chars << "\n"; cout << "Error in Stringc::delete routine.\n"; cout << " Bad range " << istart << " to " << iend; cout << "... Nothing will be deleted.\n"; } }
void parse_defaults(char *ptr, struct defaults *def) { // Establish default values ptr = clear_space(ptr); // advance ptr through empty space def->len = DDURATION; // establish default values def->bpm = DBPM; def->oct = DOCTAVE; char *temp = malloc(strlen(ptr) + 1); // temp var to hold scanned items sscanf(ptr, "%[^,]", temp); // scan first item and parse parse_s_def(temp, def); while ((ptr = strchr(ptr, ',')) != NULL) { // while there are more defaults, scan them and parse ptr += 1; sscanf(ptr, "%[^,]", temp); parse_s_def(temp, def); } free (temp); // free memory }
Stringc::~Stringc() { clear_space(); }