// str is a line of digits, starting with a line number. Parse it, // returning the first number in *lnno and the rest in a newly // allocated Counts struct. If lnno is non-NULL, treat the first // number as a line number and assign it to *lnno instead of // incorporating it in the counts array. static Counts* splitUpCountsLine ( SOURCE* s, /*OUT*/UWord* lnno, char* str ) { #define N_TMPC 50 Bool ok; Counts* counts; ULong tmpC[N_TMPC]; Int n_tmpC = 0; while (1) { ok = parse_ULong( &tmpC[n_tmpC], &str ); if (!ok) break; n_tmpC++; if (n_tmpC >= N_TMPC) barf(s, "N_TMPC too low. Increase and recompile."); } if (*str != 0) parseError(s, "garbage in counts line"); if (lnno ? (n_tmpC < 2) : (n_tmpC < 1)) parseError(s, "too few counts in count line"); if (lnno) { *lnno = (UWord)tmpC[0]; counts = new_Counts( n_tmpC-1, /*COPIED*/&tmpC[1] ); } else { counts = new_Counts( n_tmpC, /*COPIED*/&tmpC[0] ); } return counts; #undef N_TMPC }
// str is a line of integers, starting with a line number. Parse it, // returning the first number in *lnno and the rest in a newly // allocated Counts struct. If lnno is non-NULL, treat the first // number as a line number and assign it to *lnno instead of // incorporating it in the counts array. static Counts* splitUpCountsLine ( SOURCE* s, /*OUT*/UWord* lnno, const char* str ) { Bool ok; Counts* counts; ULong *tmpC = NULL; UInt n_tmpC = 0, tmpCsize = 0; while (1) { if (n_tmpC >= tmpCsize) { tmpCsize += 50; tmpC = realloc(tmpC, tmpCsize * sizeof *tmpC); if (tmpC == NULL) mallocFail(s, "splitUpCountsLine:"); } ok = parse_ULong( &tmpC[n_tmpC], &str ); if (!ok) break; n_tmpC++; } if (*str != 0) parseError(s, "garbage in counts line"); if (lnno ? (n_tmpC < 2) : (n_tmpC < 1)) parseError(s, "too few counts in count line"); if (lnno) { *lnno = (UWord)tmpC[0]; counts = new_Counts( n_tmpC-1, /*COPIED*/&tmpC[1] ); } else { counts = new_Counts( n_tmpC, /*COPIED*/&tmpC[0] ); } free(tmpC); return counts; }
static Counts* dopy_Counts ( Counts* cts ) { return new_Counts( cts->n_counts, cts->counts ); }