summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2026-04-24 11:58:48 -0400
committerJonathan Bradley <jcb@pikum.xyz>2026-04-24 11:58:48 -0400
commita20572b4b15a63e3a2df3c59cf3f59409e0c4718 (patch)
tree32830f90e511684a7253423e686f7674d6fe5358
parentdad50dfd83d36044d3900265110914f1383f3dcc (diff)
convert to cooldown timer, pad sentence end
-rwxr-xr-xsrc/spreed.c33
-rw-r--r--test.txt2
2 files changed, 19 insertions, 16 deletions
diff --git a/src/spreed.c b/src/spreed.c
index 4046282..406c288 100755
--- a/src/spreed.c
+++ b/src/spreed.c
@@ -19,9 +19,9 @@ exit
#define CLR_FG L"\033[31m"
#define CLR_RESET L"\033[0m"
#define SPRD_CLOCK CLOCK_MONOTONIC
-#define MS_PER_MIN (60llu * 1000000000llu)
+#define MS_PER_MIN (60ll * 1000000000ll)
-#define SPRD_CLOCK_DIFF(t1, t2) ((((uint64_t)t1.tv_sec * 1000000000llu) + (uint64_t)t1.tv_nsec) - (((uint64_t)t2.tv_sec * 1000000000llu) + (uint64_t)t2.tv_nsec))
+#define SPRD_CLOCK_DIFF(t1, t2) ((((int64_t)t1.tv_sec * 1000000000ll) + (int64_t)t1.tv_nsec) - (((int64_t)t2.tv_sec * 1000000000ll) + (int64_t)t2.tv_nsec))
const uint8_t orps[9] = {0,0,0,1,1,2,2,2,2};
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
wchar_t word[37];
wchar_t wc;
char *str;
- uint64_t u64, wpm_ns;
+ int64_t cooldown, wpm_ns;
int c;
char chararr[4];
uint8_t u, uu, ichar, iword, b_word_break;
@@ -46,7 +46,7 @@ int main(int argc, char *argv[])
clock_getres(SPRD_CLOCK, &ts_last);
memset(word, 0, 37 * sizeof(wchar_t));
- u64 = 0;
+ cooldown = 0;
wpm_ns = MS_PER_MIN / 250;
memset(chararr, 0, sizeof(chararr));
ichar = 0;
@@ -65,9 +65,9 @@ int main(int argc, char *argv[])
str = argv[1];
}
if (str != NULL) {
- wpm_ns = strtoull(str, NULL, 10);
+ wpm_ns = strtoll(str, NULL, 10);
if (wpm_ns == 0) {
- fwprintf(stdout, L"Error: parsed '%s' as %llu, setting to default of 250\n", str, wpm_ns);
+ fwprintf(stdout, L"Error: parsed '%s' as %ll, setting to default of 250\n", str, wpm_ns);
wpm_ns = 250;
} else if (wpm_ns > (60 * 30)) {
wpm_ns = 60 * 30;
@@ -76,24 +76,22 @@ int main(int argc, char *argv[])
wpm_ns = MS_PER_MIN / wpm_ns;
}
- fwprintf(stdout, L"Clock (%i) accuracy: %llu.%09llus\n", SPRD_CLOCK, ts_last.tv_sec, ts_last.tv_nsec);
+ fwprintf(stdout, L"Clock (%i) accuracy: %ll.%09lls\n", SPRD_CLOCK, ts_last.tv_sec, ts_last.tv_nsec);
fwprintf(stdout, L" V\n");
clock_gettime(SPRD_CLOCK, &ts_current);
ts_last = ts_current;
ts_last.tv_sec -= 60;
do {
- while (u64 < wpm_ns) {
+ while (cooldown > 0) {
clock_gettime(SPRD_CLOCK, &ts_current);
- u64 = SPRD_CLOCK_DIFF(ts_current, ts_last);
- if (u64 >= wpm_ns) {
+ cooldown -= SPRD_CLOCK_DIFF(ts_current, ts_last);
+ if (cooldown <= 0) {
break;
}
- u64 = wpm_ns - u64;
ts_sleep.tv_sec = 0;
- ts_sleep.tv_nsec = u64 > 1000000000llu ? 999999999 : u64;
+ ts_sleep.tv_nsec = cooldown > 1000000000ll ? 999999999ll : cooldown;
nanosleep(&ts_sleep, NULL);
- u64 = 0;
}
b_word_break = 0;
c = getchar();
@@ -172,11 +170,16 @@ END_OF_WORD:
putwchar(L' ');
}
+ fflush(stdout);
+
+ if (word[iword-1] == L'.') {
+ cooldown += wpm_ns;
+ }
+ cooldown += wpm_ns;
+
iword = 0;
memset(word, 0, 37 * sizeof(wchar_t));
- u64 = 0;
ts_last = ts_current;
- fflush(stdout);
}
ichar = 0;
diff --git a/test.txt b/test.txt
index 73cb2d9..ed00213 100644
--- a/test.txt
+++ b/test.txt
@@ -1,4 +1,4 @@
-this ain't workin
+this ain't workin.
1
22
333