Skip to content

Commit

Permalink
Support milliseconds in command line parameters (Issue #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
drfiemost committed Apr 14, 2021
1 parent 3d2edee commit cd88190
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions doc/en/sidplayfp.pod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Can include an optional level, defaults to 1.

=item B<-b>I<< <num> >>

Set start time in [mins:]secs format (compatible with sid2wav).
Set start time in [mins:]secs[.milli] format (compatible with sid2wav).

=item B<-ds>I<< <addr> >>

Expand Down Expand Up @@ -104,7 +104,7 @@ combined with the track selection to form -ols<num>.

=item B<-t>I<< <num> >>

Set play length in [mins:]secs format (0 is endless).
Set play length in [mins:]secs[.milli] format (0 is endless).

=item B<-v>I<< <n|p>[f] >>

Expand Down
27 changes: 24 additions & 3 deletions src/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,49 @@ bool parseTime(const char *str, uint_least32_t &time)
return false;

uint_least32_t _time;
uint_least32_t milliseconds = 0;

char *sep = (char *) strstr (str, ":");
if (!sep)
{ // User gave seconds
_time = atoi (str);
}
else
{ // Read in MM:SS format
// TODO parse milliseconds too
{ // Read in MM:SS[.mmm] format
int val;
*sep = '\0';
val = atoi (str);
if (val < 0 || val > 99)
return false;
_time = (uint_least32_t) val * 60;
// parse milliseconds
char *milli = (char *) strstr (sep+1, ".");
if (milli)
{
char *start = milli + 1;
char *end;
milliseconds = strtol(start, &end, 10);
switch (end - start)
{
case 1: milliseconds *= 100; break;
case 2: milliseconds *= 10; break;
case 3: break;
default: return false;
}

if (milliseconds < 0 || milliseconds > 999)
return false;

*milli = '\0';
}
val = atoi (sep + 1);
if (val < 0 || val > 59)
return false;
_time += (uint_least32_t) val;
}

time = _time * 1000;
time = _time * 1000 + milliseconds;
std::cout << time << std::endl;
return true;
}

Expand Down

0 comments on commit cd88190

Please sign in to comment.