summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xspreed.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/spreed.c b/spreed.c
index 40376ea..a646e4f 100755
--- a/spreed.c
+++ b/spreed.c
@@ -5,15 +5,13 @@ exit
#define _POSIX_C_SOURCE 200809L
-#include <locale.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <wchar.h>
-#include <wctype.h>
+#include <locale.h> // setlocale
+#include <stdio.h> // getchar, stdin/out/err
+#include <stdlib.h> // getenv, strtoll
+#include <string.h> // strstr
+#include <time.h> // timespec
+#include <wchar.h> // fwide, mbrtowc, putwchar
+#include <wctype.h> // iswprint, iswspace, iswalnum
#define SPRD_VER L"0.1"
#define CLR_FG L"\033[31m"
@@ -21,11 +19,11 @@ exit
#define SPRD_CLOCK CLOCK_MONOTONIC
#define MS_PER_MIN (60ll * 1000000000ll)
-#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))
+#define SPRD_CLOCK_DIFF(t1, t2) ((((long int)t1.tv_sec * 1000000000ll) + (long int)t1.tv_nsec) - (((long int)t2.tv_sec * 1000000000ll) + (long int)t2.tv_nsec))
-const uint8_t orps[9] = {0,0,0,1,1,2,2,2,2};
+const unsigned char orps[9] = {0,0,0,1,1,2,2,2,2};
-uint8_t get_optimal_recognition_point(size_t len) {
+unsigned char get_optimal_recognition_point(size_t len) {
if (len >= 10) return 3;
return orps[len-1];
}
@@ -36,10 +34,10 @@ int main(int argc, char *argv[])
wchar_t word[37];
wchar_t wc;
char *str;
- int64_t cooldown, wpm_ns;
+ long int cooldown, wpm_ns;
int c;
char chararr[4];
- uint8_t u, uu, ichar, iword, b_word_break;
+ unsigned char u, uu, ichar, iword, b_word_break;
setlocale(LC_ALL, "");
fwide(stdout, 1);
@@ -55,7 +53,10 @@ int main(int argc, char *argv[])
if (argc > 1) {
if (strstr(argv[1], "-v") || strstr(argv[1], "--v") || strstr(argv[1], "-V") || strstr(argv[1], "--V")) {
- fwprintf(stdout, "spreed version "SPRD_VER"\n");
+ c = fputws(L"spreed version " SPRD_VER L"\n", stdout);
+ if (c == EOF) {
+ perror("fputws()");
+ }
return 0;
}
}
@@ -67,18 +68,17 @@ int main(int argc, char *argv[])
if (str != NULL) {
wpm_ns = strtoll(str, NULL, 10);
if (wpm_ns == 0) {
- fwprintf(stdout, L"Error: parsed '%s' as %ll, setting to default of 250\n", str, wpm_ns);
+
+ fputws(L"Error: parsed wpm as 0, setting to default of 250\n", stdout);
wpm_ns = 250;
} else if (wpm_ns > (60 * 30)) {
wpm_ns = 60 * 30;
- fwprintf(stdout, L"Limiting to %i wpm (30 fps)\n", 60 * 30);
+ fputws(L"Limiting to 1800 wpm (30 fps)\n", stdout);
}
wpm_ns = MS_PER_MIN / wpm_ns;
}
- fwprintf(stdout, L"Clock (%i) accuracy: %li.%09lls\n", SPRD_CLOCK, ts_last.tv_sec, ts_last.tv_nsec);
-
- fwprintf(stdout, L" V\n");
+ fputws(L" V\n", stdout);
clock_gettime(SPRD_CLOCK, &ts_current);
ts_last = ts_current;
ts_last.tv_sec -= 60;
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
case (size_t)-1:
if (ichar == 4) {
// emojis return (size_t)-1 until we have all the bytes
- fwprintf(stderr, L"\nmbrtowc encoding error\n");
+ fputws(L"\nmbrtowc encoding error\n", stderr);
return 1;
}
continue;
@@ -146,7 +146,7 @@ END_OF_WORD:
if (b_word_break != 0 || iword >= 37) {
if (iword == 0) {
- fwprintf(stderr, L"\n0 length word\n");
+ fputws(L"\n0 length word\n", stderr);
return 2;
}
ichar = get_optimal_recognition_point(iword);
@@ -159,11 +159,11 @@ END_OF_WORD:
}
if (uu < iword) {
if (u == 10) {
- fwprintf(stdout, L"%ls", CLR_FG);
+ fputws(CLR_FG, stdout);
}
putwchar(word[uu++]);
if (u == 10) {
- fwprintf(stdout, L"%ls", CLR_RESET);
+ fputws(CLR_RESET, stdout);
}
continue;
}