<commit_before>#include "global.h"
#include "textlist.h"

int quit = FALSE;

wchar_t input_str[256];
size_t input_str_len = 0;

SDL_Thread *thread1 = NULL;
int use_espeak_thread = FALSE;
SDL_sem *espeak_lock = NULL;

int espeak_thread(void *data) {
  int local_use_espeak = FALSE;
  while (quit == FALSE) {

    SDL_SemWait(espeak_lock);
    local_use_espeak = use_espeak_thread;
    SDL_SemPost(espeak_lock);

    if (local_use_espeak == TRUE) {
      wchar_t espeak_command_w[256] = L"espeak -v mb/mb-de4 -s 90 \"";
      wcscat(espeak_command_w, textlist_get_current());
      wcscat(espeak_command_w, L"\" 2>/dev/null");
      char espeack_command[256];
      wcstombs(espeack_command, espeak_command_w, 255);
      system(espeack_command);
      SDL_Delay(500);
    } else {
      SDL_Delay(1);
    }
  }

  return 0;
}

void input_init() {
  wcscpy(input_str, L"");
}

int main() {
  setlocale(LC_ALL, "de_DE.UTF-8");

  textlist_load();
  textlist_set_random_pos();

  use_espeak_thread = TRUE;
  thread1 = SDL_CreateThread(espeak_thread, NULL);

  while (quit == FALSE) {

    fgetws(input_str, 255, stdin);
    input_str[wcslen(input_str) - 1] = L'\0';
    if (wcscmp(input_str, L"ende") == 0) {
      quit = TRUE;
    } else if (textlist_current_compare(input_str) == 0) {
      wprintf(L"richtig\n");
      SDL_SemWait(espeak_lock);
      use_espeak_thread = FALSE;
      SDL_SemPost(espeak_lock);

      textlist_remove_current();
      quit = (textlist_set_random_pos() == TRUE) ? FALSE : TRUE;
      if (quit == FALSE) {
        input_init();

        SDL_SemWait(espeak_lock);
        use_espeak_thread = TRUE;
        SDL_SemPost(espeak_lock);
      }
    } else {
      wprintf(L"falsch\n");
    }

    SDL_Delay(1);
  }

  SDL_WaitThread(thread1, NULL);
  SDL_DestroySemaphore(espeak_lock);

  return 0;
}<commit_msg>use mutex / condition<commit_after>#include "global.h"
#include "textlist.h"

int quit = FALSE;

wchar_t input_str[256];
size_t input_str_len = 0;

SDL_Thread *thread1 = NULL;
SDL_mutex *espeak_lock = NULL;
SDL_cond *can_espeak = NULL;

int espeak_thread(void *data) {
  while (quit == FALSE) {
    SDL_CondWait(can_espeak, espeak_lock);

    wchar_t espeak_command_w[256] = L"espeak -v mb/mb-de4 -s 90 \"";

    SDL_mutexP(espeak_lock);
    wcscat(espeak_command_w, textlist_get_current());
    SDL_mutexV(espeak_lock);

    wcscat(espeak_command_w, L"\" 2>/dev/null");
    char espeack_command[256];
    wcstombs(espeack_command, espeak_command_w, 255);
    system(espeack_command);
  }
  return 0;
}

void input_init() {
  wcscpy(input_str, L"");
}

int main() {
  setlocale(LC_ALL, "de_DE.UTF-8");

  textlist_load();
  textlist_set_random_pos();

  espeak_lock = SDL_CreateMutex();
  can_espeak = SDL_CreateCond();

  thread1 = SDL_CreateThread(espeak_thread, NULL);

  while (quit == FALSE) {
    SDL_CondSignal(can_espeak);
    fgetws(input_str, 255, stdin);
    input_str[wcslen(input_str) - 1] = L'\0';
    if (wcscmp(input_str, L"ende") == 0) {
      quit = TRUE;
    } else if (textlist_current_compare(input_str) == 0) {
      wprintf(L"richtig\n");

      SDL_mutexP(espeak_lock);
      textlist_remove_current();
      quit = (textlist_set_random_pos() == TRUE) ? FALSE : TRUE;
      SDL_mutexV(espeak_lock);

      if (quit == FALSE) {
        input_init();
      }
    } else {
      wprintf(L"falsch\n");
    }

    SDL_Delay(1);
  }

  SDL_WaitThread(thread1, NULL);
  SDL_DestroyMutex(espeak_lock);
  SDL_DestroyCond(can_espeak);

  return 0;
}
{'fraction_non_alphanumeric': 0.13550600343053174, 'fraction_numerical': 0.018867924528301886, 'mean_word_length': 3.520671834625323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2663434', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1368, 'n_words': 233}