<commit_before>/*
 *  einit-feedbackd.c
 *  einit
 *
 *  Created by <NAME> on 16/02/2008.
 *  Copyright 2008 <NAME>. All rights reserved.
 *
 */

/*
Copyright (c) 2008, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
          this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
    * Neither the name of the project nor the names of its contributors may be
          used to endorse or promote products derived from this software without
          specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <string.h>

#include <einit/event.h>

#include <einit/configuration-static.h>

#include <einit/einit.h>
#include <einit/tree.h>

#include <curses.h>
#include <pthread.h>

struct module_status {
 enum einit_module_status status;
 char *name;
 char feedback_job;
};

#define attr_red 1
#define attr_blue 2
#define attr_green 3
#define attr_yellow 4
#define attr_white 5

struct stree *status_tree = NULL;

struct textbuffer_entry {
 char *rid;
 char *message;
};

enum control_type {
 control_automatic,
 control_manual
};

struct textbuffer_entry **textbuffer = NULL;

int progress = 0;
int starting_bufferitem = 0;
char *mode = "(none)";
char *mode_to = "(none)";

enum control_type control_mode = control_automatic;

void set_module_status (char *name, enum einit_module_status status) {
 struct stree *e;
 if (!status_tree || !(e = streefind (status_tree, name, tree_find_first))) {
  struct module_status s;

  s.status = status;
  s.name = einit_module_get_name(name);

  char **t = einit_module_get_options(name);
  s.feedback_job = inset ((const void **)t, "job-feedback", SET_TYPE_STRING);

  status_tree = streeadd (status_tree, name, &s, sizeof (s), NULL);
 } else {
  struct module_status *s = e->value;

  if (s->status & status_failed) {
    s->status = status | ((status & status_enabled) ? status_failed : 0);
  } else
   s->status = status;
 }
}

void add_text_buffer_entry (char *rid, char *message) {
 struct textbuffer_entry ne = {
  .rid = rid,
  .message = message
 };
 textbuffer = (struct textbuffer_entry **)set_fix_add ((void **)textbuffer, &ne, sizeof (ne));
}

void move_to_right_border () {
 int x, y, maxx, maxy;

 getyx (stdscr, y, x);
 getmaxyx(stdscr, maxy, maxx);

 move (y, maxx - 13);<commit_msg>smoother scrolling<commit_after>/*
 *  einit-feedbackd.c
 *  einit
 *
 *  Created by <NAME> on 16/02/2008.
 *  Copyright 2008 <NAME>. All rights reserved.
 *
 */

/*
Copyright (c) 2008, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
          this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
    * Neither the name of the project nor the names of its contributors may be
          used to endorse or promote products derived from this software without
          specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <string.h>

#include <einit/event.h>

#include <einit/configuration-static.h>

#include <einit/einit.h>
#include <einit/tree.h>

#include <curses.h>
#include <pthread.h>

struct module_status {
 enum einit_module_status status;
 char *name;
 char feedback_job;
};

#define attr_red 1
#define attr_blue 2
#define attr_green 3
#define attr_yellow 4
#define attr_white 5

struct stree *status_tree = NULL;

struct textbuffer_entry {
 char *rid;
 char *message;
};

enum control_type {
 control_automatic,
 control_manual
};

struct textbuffer_entry **textbuffer = NULL;

int progress = 0;
int starting_bufferitem = 0;
char *mode = "(none)";
char *mode_to = "(none)";

enum control_type control_mode = control_automatic;

void set_module_status (char *name, enum einit_module_status status) {
 struct stree *e;
 if (!status_tree || !(e = streefind (status_tree, name, tree_find_first))) {
  struct module_status s;

  s.status = status;
  s.name = einit_module_get_name(name);

  char **t = einit_module_get_options(name);
  s.feedback_job = inset ((const void **)t, "job-feedback", SET_TYPE_STRING);

  status_tree = streeadd (status_tree, name, &s, sizeof (s), NULL);
 } else {
  struct module_status *s = e->value;

  if (s->status & status_failed) {
    s->status = status | ((status & status_enabled) ? status_failed : 0);
  } else
   s->status = status;
 }
}

void add_text_buffer_entry (char *rid, char *message) {
 struct textbuffer_entry ne = {
  .rid = rid,
  .message = message
 };

 if (!message[0]) return;

 if (textbuffer) {
  int i = 0;
  for (; textbuffer[i]; i++) ;

  if (i > 0) {
   i--;
   if (strmatch (rid, textbuffer[i]->rid) && strmatch (message, textbuffer[i]->message)) return;
  }
 }

 textbuffer = (struct textbuffer_entry **)set_fix_add ((void **)textbuffer, &ne, sizeof (ne));
}

void move_to_right_border () {
 int x, y, maxx, maxy;

 getyx (stdscr, y, x);
 getmaxyx(stdscr, maxy, maxx);

 move (y, maxx - 13);
{'fraction_non_alphanumeric': 0.0979569746989582, 'fraction_numerical': 0.007441482884589365, 'mean_word_length': 4.238837703756201, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 50, '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': '315751', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2235, 'n_words': 863}