Use HTTP, it's much faster

Use HTTP, it's much faster

--- src/main.c
+++ src/main.c
@@ -5,7 +5,7 @@
 #include <string.h>   // strlen
 #include <stdbool.h>

-#define URL_FIDDLYBITS  "ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/"
+#define URL_FIDDLYBITS  "http://tgftp.nws.noaa.gov/data/observations/metar/stations/"
 #define URL_STATION		"XXXX"
 #define URL_EXTENSION   ".TXT"


fix indentation lol

fix indentation lol

--- src/main.c
+++ src/main.c
@@ -258,20 +258,20 @@
 void PrintHelp(void) {
 	printf("%s\n", R3X_SYSTEM_VERSION);
 	printf("\n\n"
-		   "R3X Virtual Machine - help\n"
-	       "Usage rxvm -exe [exe file name] optional(-f [CPU Frequency])\n\n"
-		   "Copyright (C) 2015 Benderx2 <https://github.com/Benderx2>\n\n"
-	       "R3X is free software and is licensed under 2-clause BSD License <http://opensource.org/licenses/BSD-2-Clause>\n"
-		   "You are free to modify, redistrubute, or make profit of this program provided\n"
-		   "you respect it's license and terms.\n"
-		   "\n\n"
-	       "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"
-	       "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\n"
-	       "THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n"
-		   "IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
-		   "INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n"
-	       "BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\n"
-	       "OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n"
-	       "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \n"
-	       "ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n");
-}
+		"R3X Virtual Machine - help\n"
+		"Usage rxvm -exe [exe file name] optional(-f [CPU Frequency])\n\n"
+		"Copyright (C) 2015 Benderx2 <https://github.com/Benderx2>\n\n"
+		"R3X is free software and is licensed under 2-clause BSD License <http://opensource.org/licenses/BSD-2-Clause>\n"
+		"You are free to modify, redistrubute, or make profit of this program provided\n"
+		"you respect it's license and terms.\n"
+		"\n\n"
+		"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"
+		"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\n"
+		"THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n"
+		"IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
+		"INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n"
+		"BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\n"
+		"OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n"
+		"WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \n"
+		"ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n");
+}


Added more date information

Added more date information

--- src/main.c
+++ src/main.c
@@ -9,6 +9,7 @@
 static GBitmap *s_background_bitmap;
 static TextLayer *s_time_layer;
 static TextLayer *s_date_layer;
+static TextLayer *s_dow_layer;

 static void update_time() {
     time_t temp = time(NULL);
@@ -31,9 +32,18 @@
     text_layer_set_text(s_date_layer, buffer);
 }

+static void update_dow() {
+    time_t temp = time(NULL);
+    struct tm *tick_time = localtime(&temp);
+    static char buffer[] = "DOW";
+    strftime(buffer, sizeof("DOW"), "%A", tick_time);
+    text_layer_set_text(s_dow_layer, buffer);
+}
+
 static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
     update_time();
     update_date();
+    update_dow();
 }

 static void main_window_load(Window *window) {
@@ -43,7 +53,7 @@
     bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
     layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
     // ** time layer ** //
-    s_time_layer = text_layer_create(GRect(0, 15, 144, 50));
+    s_time_layer = text_layer_create(GRect(0, 5, 144, 50));
     text_layer_set_background_color(s_time_layer, GColorClear);
     text_layer_set_text_color(s_time_layer, GColorWhite);
     text_layer_set_text(s_time_layer, "00:00");
@@ -51,13 +61,21 @@
     text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
     layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
     // ** date layer ** //
-    s_date_layer = text_layer_create(GRect(0, 85, 144, 50));
+    s_date_layer = text_layer_create(GRect(0, 70, 144, 50));
     text_layer_set_background_color(s_date_layer, GColorClear);
     text_layer_set_text_color(s_date_layer, GColorWhite);
     text_layer_set_text(s_date_layer, "00-00");
-    text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
+    text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
     text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
     layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
+    // ** day of week layer ** //
+    s_dow_layer = text_layer_create(GRect(0, 115, 144, 50));
+    text_layer_set_background_color(s_dow_layer, GColorClear);
+    text_layer_set_text_color(s_dow_layer, GColorWhite);
+    text_layer_set_text(s_dow_layer, "DOW");
+    text_layer_set_font(s_dow_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
+    text_layer_set_text_alignment(s_dow_layer, GTextAlignmentCenter);
+    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_dow_layer));
 }

 static void main_window_unload(Window *window) {
@@ -66,6 +84,7 @@

     text_layer_destroy(s_time_layer);
     text_layer_destroy(s_date_layer);
+    text_layer_destroy(s_dow_layer);
 }

 static void init() {


temporarily use a fixed red buffer

temporarily use a fixed red buffer

--- src/main.c
+++ src/main.c
@@ -77,6 +77,7 @@
 static pthread_cond_t bufCond = PTHREAD_COND_INITIALIZER;
 static camera_buffer_t *bufQueue = NULL;
 static camera_buffer_t *cameraBuf = NULL;
+static unsigned char *fixedBuf = NULL;

 static camera_handle_t handle;
 static pthread_t vf_tid;
@@ -969,7 +970,8 @@
     int w = cameraBuf->framedesc.rgb8888.stride/4;
     int h = cameraBuf->framedesc.rgb8888.height;
     if (!reuse) {
-        glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, cameraBuf->framebuf);
+//        glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, cameraBuf->framebuf);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, fixedBuf);
     }

     GLint texSize = glGetUniformLocation(selectedCubeShader, "imageSize");
@@ -1232,6 +1234,17 @@
                      0);
     pthread_create(&vf_tid, NULL, vf_thread, NULL);

+    fixedBuf = calloc(1, 4096*480);
+    int x,y;
+    for (y=0; y<480; y++) {
+        for (x=0; x<640; x++) {
+            fixedBuf[y*4096+x*4] = 0x00;
+            fixedBuf[y*4096+x*4+1] = 0x00;
+            fixedBuf[y*4096+x*4+2] = 0xff;
+            fixedBuf[y*4096+x*4+3] = 0xff;
+        }
+    }
+
     while (!shutdown) {
         // Handle user input and accelerometer
         handle_events();


limpando comentarios e funcao barreira inicio

--- src/main.c
+++ src/main.c
@@ -46,7 +46,6 @@

 void destroy_semaphores();

-void get_to_starting_barrier( const char *string, const unsigned int number );
 void get_to_barrier( const char *string, const unsigned int number );

 int main() {
@@ -132,7 +131,6 @@
                 sem_post( &hacker_queue );
             }
             hackers = 0;
-            //printf("I got a hacker captain. 4 hackers on boat\n");
             is_captain = true;
         } else if ( hackers == MAX_THREADS_PER_BOAT / 2 && serfs >= MAX_THREADS_PER_BOAT / 2 ) {
             for ( int i = 0; i < MAX_THREADS_PER_BOAT / 2; i++ ) {
@@ -152,8 +150,7 @@
         sem_wait( &hacker_queue );

         board( "Hacker", my_number );
-        //get_to_barrier("Hacker", my_number);
-        pthread_barrier_wait( &_barrier );
+        get_to_barrier("Hacker", my_number);

         if ( is_captain ) {
@@ -198,9 +195,7 @@
         sem_wait( &serf_queue );

         board( "Serf", my_number );
-
-        pthread_barrier_wait( &_barrier );
-        //get_to_barrier("Serf", my_number);
+        get_to_barrier("Serf", my_number);

         if ( is_captain ) {
@@ -229,23 +224,6 @@
     sem_destroy(&hacker_queue);
     sem_destroy(&serf_queue);
     pthread_barrier_destroy(&_barrier);
-}
-
-void get_to_starting_barrier( const char *string, const unsigned int number ) {
-    int result;
-    char err_msg[LEN];
-    /*barreira para esperar todas as threads chegarem antes de começarmos*/
-    pthread_mutex_lock( &mutex );
-    printf( "%s %d got to the starting barrier\n", string, number);
-    fflush(stdout);
-    pthread_mutex_unlock( &mutex );
-    result=pthread_barrier_wait( &_barrier );
-    if(result>0) {
-        strerror_r(result,err_msg,LEN);
-        printf("Th %u - erro em barrier_wait: %s\n",number,err_msg);
-    }
-    /**********************************************************************/
-
 }

 void get_to_barrier( const char *string, const unsigned int number ) {
@@ -256,5 +234,4 @@
         strerror_r(result,err_msg,LEN);
         printf("Th %u - erro em barrier_wait: %s\n",number,err_msg);
     }
-
-}
+}


Fix an issue where len was too short for sysctl to recieve the process vm map.

--- src/os-freebsd.c
+++ src/os-freebsd.c
@@ -72,6 +72,7 @@
   buf = get_mem(len1);
   if (buf == NULL)
     return (-1);
+  len = len1;
   error = sysctl(mib, 4, buf, &len, NULL, 0);
   if (error) {
     free_mem(buf, len1);


Add missing static variables

Add missing static variables

--- src/main.c
+++ src/main.c
@@ -23,6 +23,10 @@
  */

 #include <gtk/gtk.h>
+
+
+GtkTextBuffer *buffer;
+GtkTextIter iter;

 static void activate (GtkApplication *app, gpointer user_data) {


add SIGPIPE handler (IGNORE)

add SIGPIPE handler (IGNORE)

--- src/main.c
+++ src/main.c
@@ -3,9 +3,12 @@
 #include "http.h"
 #include "log.h"
 #include "handler.h"
+#include <signal.h>

 int main(int argc, char *argv[])
 {
+  signal(SIGPIPE , SIG_IGN);
+
   sk_server server;
   server.port = 8080;
   server.addr = "127.0.0.1";


Layout Grid

Layout Grid

Layed out the status grid, and added all of the different status fields. Need to update the font to be slightly smaller in order to fit within the borders.

error: pathspec 'src/main.c' did not match any file(s) known to git

--- src/main.c
+++ src/main.c
@@ -0,0 +1,107 @@
+#include <pebble.h>
+
+// Constant text strings for the connection statuses
+const char *eth = "Eth", *ds = "DS", *radio = "Rd", *rio = "RIO", *code = "Cd", *estop = "Est", *good = "G";
+
+static Window *s_main_window;
+static Layer *s_grid_layer;
+static TextLayer *s_red_header;
+static TextLayer *s_blue_header;
+static TextLayer *s_red1;
+static TextLayer *s_red2;
+static TextLayer *s_red3;
+static TextLayer *s_blue1;
+static TextLayer *s_blue2;
+static TextLayer *s_blue3;
+
+static void canvas_update_proc(Layer *this_layer, GContext *ctx) {
+  // Draw a line down the middle of the screen
+  graphics_draw_line(ctx, GPoint(74, 0), GPoint(74, 168));
+
+  // Draw the alliance line
+  graphics_draw_line(ctx, GPoint(0, 20), GPoint(144, 20));
+
+  // Draw the 2 actual alliance dividers. They are (168-20-10)/3 pixels apart, which is 46.
+  graphics_draw_line(ctx, GPoint(0, 66), GPoint(144, 66));
+  graphics_draw_line(ctx, GPoint(0, 112), GPoint(144, 112));
+}
+
+void setup_alliance_textlayer(TextLayer **layer, Layer *parent, const char *text, int x, int y) {
+  *layer = text_layer_create(GRect(x, y, 74, 46));
+  text_layer_set_background_color(*layer, GColorClear);
+  text_layer_set_text_color(*layer, GColorBlack);
+  text_layer_set_text_alignment(*layer, GTextAlignmentCenter);
+  text_layer_set_font(*layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT));
+  text_layer_set_text(*layer, text);
+  layer_add_child(parent, text_layer_get_layer(*layer));
+}
+
+static void main_window_load(Window *window) {
+  Layer *window_layer = window_get_root_layer(window);
+  GRect bounds = layer_get_bounds(window_layer);
+
+  // Create the grid layer
+  s_grid_layer = layer_create(GRect(0, 0, bounds.size.w, bounds.size.h));
+  layer_add_child(window_layer, s_grid_layer);
+
+  // Set the grid drawing update procedure
+  layer_set_update_proc(s_grid_layer, canvas_update_proc);
+
+  // Draw the Red and Blue text for the alliance headers
+  s_red_header = text_layer_create(GRect(0, 0, 74, 20));
+  s_blue_header = text_layer_create(GRect(74, 0, 74, 20));
+  text_layer_set_background_color(s_red_header, GColorClear);
+  text_layer_set_background_color(s_blue_header, GColorClear);
+  text_layer_set_text_color(s_red_header, GColorBlack);
+  text_layer_set_text_color(s_blue_header, GColorBlack);
+  text_layer_set_text_alignment(s_red_header, GTextAlignmentCenter);
+  text_layer_set_text_alignment(s_blue_header, GTextAlignmentCenter);
+  text_layer_set_font(s_red_header, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
+  text_layer_set_font(s_blue_header, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
+  text_layer_set_text(s_red_header, "Red");
+  text_layer_set_text(s_blue_header, "Blue");
+  layer_add_child(window_layer, text_layer_get_layer(s_red_header));
+  layer_add_child(window_layer, text_layer_get_layer(s_blue_header));
+
+  // Create the layers for the different alliance statuses
+  setup_alliance_textlayer(&s_red1, window_layer, eth, 0, 20);
+  setup_alliance_textlayer(&s_red2, window_layer, ds, 0, 66);
+  setup_alliance_textlayer(&s_red3, window_layer, radio, 0, 112);
+  setup_alliance_textlayer(&s_blue1, window_layer, rio, 74, 20);
+  setup_alliance_textlayer(&s_blue2, window_layer, code, 74, 66);
+  setup_alliance_textlayer(&s_blue3, window_layer, estop, 74, 112);
+  text_layer_set_background_color(s_blue3, GColorBlack);
+  text_layer_set_text_color(s_blue3, GColorWhite);
+}
+
+static void main_window_unload(Window *window) {
+  layer_destroy(s_grid_layer);
+  text_layer_destroy(s_red_header);
+  text_layer_destroy(s_blue_header);
+  text_layer_destroy(s_red1);
+  text_layer_destroy(s_red2);
+  text_layer_destroy(s_red3);
+  text_layer_destroy(s_blue1);
+  text_layer_destroy(s_blue2);
+  text_layer_destroy(s_blue3);
+}
+
+static void init() {
+  s_main_window = window_create();
+  window_set_window_handlers(s_main_window, (WindowHandlers) {
+    .load = main_window_load,
+    .unload = main_window_unload
+  });
+
+  window_stack_push(s_main_window, true);
+}
+
+static void deinit() {
+  window_destroy(s_main_window);
+}
+
+int main() {
+  init();
+  app_event_loop();
+  deinit();
+}


freeing

freeing

--- src/main.c
+++ src/main.c
@@ -128,6 +128,7 @@
 		(*data)[i + (*datumSize)].min  = buffer[i].min;
 	}
 	*datumSize += n;
+	free(buffer);
 }

 KSEQ_INIT(gzFile, gzread)


Ajout d'idée pour la gestion des opérations

Ajout d'un morceau de code pour la gestion des opérations mathématiques entres variables, grosse note écrite dans le code pour expliquer le fonctionnement

--- src/main.c
+++ src/main.c
@@ -2,6 +2,40 @@
 #include <stdlib.h>
 #include <string.h>

+
+// Pour la mise en page des dumps et aux affichages de debug
+int debug_lvl = 0;
+
+void debug_pr_lvl() {
+    int i = 0;
+    for(; i < debug_lvl; i++)
+        fputs("|  ", stdout);
+}
+
+//=====================================================================//
+//                   Node de l'arbre binaire (Opération)
+
+// Représente les différents types possibles d'une operation
+typedef enum e_operation_type {
+	OP_NOTHING = 0,
+
+	OP_FUNC_CALL = 0x1,
+
+	OP_MATH_PLUS = 0x10, OP_MATH_MINUS = 0x11, OP_MATH_MULT = 0x12, OP_MATH_POW = 0x13, OP_MATH_DIV = 0x14, OP_MATH_MODULO = 0x15,
+
+	OP_MATH_P_UNARY = 0x20, OP_MATH_N_UNARY = 0x21,
+
+	OP_MATH_AFF = 0x30,
+
+	OP_MATH_GT = 0x40, OP_MATH_GE = 0x41, OP_MATH_LT = 0x42, OP_MATH_LE = 0x43, OP_MATH_EQ = 0x44, OP_MATH_DIF = 0x45, OP_MATH_NOT = 0x46, OP_MATH_AND = 0x47, OP_MATH_OR = 0x48,
+
+    OP_MATH_PARENTH = 0x50,
+
+	OP_VALUE = 0x60
+
+} operation_type;
+
+
 //=====================================================================//
 //                         Fonction de hashage

@@ -21,6 +55,7 @@

     return h;
 }
+

 //=====================================================================//
 //                           Type booléen
@@ -30,46 +65,78 @@
 #define true_ 1
 #define false_ 0

+
 //=====================================================================//
 //                         Langage en lui-même

 // Type de donnée possibles
 typedef enum e_language_type {
-	T_INT, T_LINT, T_FLOAT, T_DOUBLE, T_CHAR, T_BOOL, T_VOID
+	T_VOID = 0, T_BOOL = 1, T_CHAR = 2, T_INT = 3, T_LINT = 4, T_FLOAT = 5, T_DOUBLE = 6
 } language_type;

 // Représente une valeur possible
-typedef union u_language_value {
+typedef union u_Language_value {
 	int v_int;
 	long int v_lint;
 	float v_float;
 	double v_double;
 	char v_char;
 	char v_bool;
-} language_value;
+} Language_value;

 //=====================================================================//
 //               variable : variable utilisable

 // Variable en mémoire
-typedef struct s_variale {
+typedef struct s_Variale {
 	char* name;            // Nom de la variable (en toute lettre)
 	hash_t name_h;            // Hashage du nom de la variable, pour la trouver plus vite
 	language_type type;    // Type de la variable
-	language_value value;  // Valeur de la variable
-} variable;
+	Language_value value;  // Valeur de la variable
+} Variable;

 // Liste de variables
-typedef struct s_variale_list {
-	struct s_variale_list* next;
-	variable var;
-} variable_list;
-
-
-
-//=====================================================================//
-//                         Fonctions testées
+typedef struct s_Variale_list {
+	struct s_Variale_list* next;
+	Variable* var;
+} Variable_list;
+
+
+//=====================================================================//
+//                     Buffer d'erreur - provisoir
+
+typedef enum e_error_type {
+    CAST_IMPOSSIBLE, NULL_VALUE, UNKOWN_TYPE, OP_IMPOSSIBLE
+} error_type;
+
+typedef enum e_error_level {
+    E_INFO=0, E_DEBUG=1, E_WARNING=2, E_ERROR=3, E_CRITICAL=4
+} error_level;
+
+typedef struct s_Error {
+    char msg[512];
+    error_type type;
+    error_level level;
+} Error;
+
+Error e;
+
+// Affichage d'erreur
+void err_display_last(Error *e) {
+    printf("#error\n  %s\n  level %d and type %d\n", e->msg, e->level, e->type);
+}
+
+// Ajout d'erreur
+void err_add(const char* msg, error_level lvl, error_type type) {
+    strncpy(e.msg, msg, 511);
+    e.level = lvl;
+    e.type = type;
+}
+
+
+//=====================================================================//
+//                    Fonctions testées - Variables

 // copy de chaine
 char* str_copy(const char* s) {
@@ -79,58 +146,85 @@

 // Gestion variables
 // Initialisations
-variable* var_init(variable *v, char* name, language_type type) {
+Variable* var_init(Variable *v, char* name, language_type type) {

     if(v) {
-        if(name) {
-            v->name = str_copy(name);
-	    v->name_h = str_hash(name);
-        } else {
-            v->name = NULL;
-            v->name_h = (hash_t)0;
-        }
+        v->name = str_copy(name);
+        v->name_h = str_hash(name);
         v->type = type;
     }

 	return v;
 }

-variable* var_init_int(variable *v, char* name, int i) {
-
+Variable* var_init_int(Variable *v, char* name, int i) {
     if(v) var_init(v, name, T_INT)->value.v_int = i;
-
-    return v;
-}
-
-variable* var_init_lint(variable *v, char* name, long int li) {
-
+    return v;
+}
+
+Variable* var_init_lint(Variable *v, char* name, long int li) {
     if(v) var_init(v, name, T_LINT)->value.v_lint = li;
-
+    return v;
+}
+
+Variable* var_init_float(Variable *v, char* name, float f) {
+    if(v) var_init(v, name, T_FLOAT)->value.v_float = f;
+    return v;
+}
+
+Variable* var_init_double(Variable *v, char* name, double d) {
+    if(v) var_init(v, name, T_DOUBLE)->value.v_double = d;
+    return v;
+}
+
+Variable* var_init_char(Variable *v, char* name, char c) {
+    if(v) var_init(v, name, T_CHAR)->value.v_char = c;
+    return v;
+}
+
+Variable* var_init_bool(Variable *v, char* name, boolean_ b) {
+    if(v) var_init(v, name, T_BOOL)->value.v_bool = b;
     return v;
 }

 // Allocations
-variable* var_new(char* name, language_type type) {
-    return var_init((variable*)malloc(sizeof(variable)), name, type);
-}
-
-variable* var_new_int(char* name, int i) {
-    return var_init_int((variable*)malloc(sizeof(variable)), name, i);
-}
-
-variable* var_new_lint(char* name, long int li) {
-    return var_init_lint((variable*)malloc(sizeof(variable)), name, li);
+Variable* var_new(char* name, language_type type) {
+    return var_init((Variable*)malloc(sizeof(Variable)), name, type);
+}
+
+Variable* var_new_int(char* name, int i) {
+    return var_init_int((Variable*)malloc(sizeof(Variable)), name, i);
+}
+
+Variable* var_new_lint(char* name, long int li) {
+    return var_init_lint((Variable*)malloc(sizeof(Variable)), name, li);
+}
+
+Variable* var_new_float(char* name, float f) {
+    return var_init_float((Variable*)malloc(sizeof(Variable)), name, f);
+}
+
+Variable* var_new_double(char* name, double d) {
+    return var_init_double((Variable*)malloc(sizeof(Variable)), name, d);
+}
+
+Variable* var_new_char(char* name, char c) {
+    return var_init_char((Variable*)malloc(sizeof(Variable)), name, c);
+}
+
+Variable* var_new_bool(char* name, boolean_ b) {
+    return var_init_bool((Variable*)malloc(sizeof(Variable)), name, b);
 }

 // Libération
-void var_del(variable *v) {
+void var_del(Variable *v) {
     if(v) {
         if(v->name) free(v->name);
         free(v);
     }
 }

-void var_empty(variable *v) {
+void var_empty(Variable *v) {
     if(v && v->name) free(v->name);
 }

@@ -157,10 +251,14 @@
 }

 // Affichage debug
-void var_dump(variable *v) {
-    puts("\nvariable :");
+void var_dump(Variable *v) {
+    debug_pr_lvl(), puts(">variable :");
     if(v) {
-        printf("\tname : %s\n\tname_h : %lu\n\ttype : %s\n\tvalue : ", v->name, (long unsigned)v->name_h, language_type_debug(v->type));
+        debug_pr_lvl(), printf("  name : %s\n", v->name);
+        debug_pr_lvl(), printf("  name_h : %lu\n", (long unsigned)v->name_h);
+        debug_pr_lvl(), printf("  type : %s\n", language_type_debug(v->type));
+        debug_pr_lvl(), fputs("  value : ", stdout);
+
         switch(v->type) {
             case T_INT:
                 printf("%d\n", v->value.v_int);
@@ -186,24 +284,233 @@
             default :
                 puts("(Error type)");
         }
+    } else
+        debug_pr_lvl(), puts("\t(null)");
+}
+
+
+
+//=====================================================================//
+//               Fonctions testées - liste de variables
+
+
+void var_list_append(Variable_list **vl, Variable *v) {
+    Variable_list *new_vl = (Variable_list*) malloc(sizeof(Variable_list));
+    new_vl->var = v;
+
+    if(*vl) {
+        new_vl->next = (*vl)->next;
+        (*vl)->next = new_vl;
+    } else
+        new_vl->next = new_vl;
+
+    *vl = new_vl;
+}
+
+void var_list_del(Variable_list *vl) {
+    Variable_list *last_vl = vl;
+
+    if(vl) {
+        do {
+            vl = vl->next;
+            var_del(vl->var);
+        }while(vl != last_vl);
+    }
+}
+
+void var_list_dump(Variable_list *vl) {
+    Variable_list *last_vl = vl;
+    debug_pr_lvl(), puts(">list variables :");
+    debug_lvl++;
+
+    if(vl) {
+        do {
+            vl = vl->next;
+            var_dump(vl->var);
+        }while(vl != last_vl);
+    } else
+        debug_pr_lvl(), puts("  (null)");
+
+    debug_lvl--;
+}
+
+
+//=====================================================================//
+//               Fonctions testées - opérations sur variables
+
+/*
+
+    Pour des raisons de facilité, les opérations ont été découpées en plusieurs familles, suivant les types d'opérations :
+        - opération arithmétique : calcul entre deux valeurs, classique
+        - opération airthmétique unaire : calcul sur une seule valeur, par exemple +/- unaire
+        - opération logique : test entre deux valeurs
+        - opération logique unaires : test logique sur une seule valeur, par exzmple !
+        - opération d'affectation : affectation d'une valeur à une variable
+
+    Pour pouvoir effectuer ces calculs, il est obligatoire d'avoir un exemplaire de chaque opération pour chaque type géré, ce
+    qui peut vite beaucoup faire de fonctions, même après découpage. C'est pourquoi on utilise un tableau de pointeurs de fonctions
+    à deux dimension pour pouvoir aller directement dans la fonction correspondant au bon type, sans avoir besoin de beaucoup de test
+    (et cela permet d'ajouter plus facilement par la suite de nouvelles opération ou types).
+
+    Si une opération n'est pas possible pour un type (Addition de booléen, etc...), alors le pointeur correspondant à l'opération est
+    à NULL, et son test dans la fonction dédié à ce type d'opération enverra une erreur (Car on essait de faire quelque chose qui est
+    incorrect/illogique/impossible).
+
+
+    Le cast des valeurs s'effectue avant les opérations, et est dédié encore une fois à un grand nombre de fonctions pour pouvoir
+    fonctionner (du type int_to_float, int_to_lint, etc...) et certainement avec le même principe de fonctionnement (Tableau de pointeurs)
+    mais pas commencé.
+
+
+*/
+
+
+/*
+Variable* operation(Variable *a, Variable *b);*/
+
+// Calcule le type de retour suivant les priorité (tès simple donc)
+language_type var_op_compute_type(language_type a, language_type b) {
+    if( a > b ) return a;
+    else        return b;
+}
+
+Variable* var_op_cast(Variable *v, language_type type) {
+    return v;
+}
+
+Variable* var_op_add_int(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_add_lint(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_add_float(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_add_double(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_minus_int(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_minus_lint(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_minus_float(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_minus_double(Variable *a, Variable *b) {
+    return a;
+}
+
+// Format des fonctions de traitement
+typedef Variable* (*var_op_func_format) (Variable*, Variable*);
+
+// Tableau des fonctions airthmétiques (+, -, etc...)
+var_op_func_format var_op_func_arithmetic[][6] = {
+    {NULL, NULL, var_op_add_int  , var_op_add_lint  , var_op_add_float  , var_op_add_double  },  // Additions
+    {NULL, NULL, var_op_minus_int, var_op_minus_lint, var_op_minus_float, var_op_minus_double}   // Subtractions
+   /* var_op_mult,
+    var_op_pow,
+    var_op_div,
+    var_op_modulo,
+    var_op_p_unary,
+    var_op_n_unary,
+    var_op_aff*/
+};
+
+unsigned int var_op_func_arithmetic_id = 0x10; // Valeur pour rammener à zéro le premier index
+
+// Fonctions représentant des opérations mathématiques
+Variable* var_op_arithmetic(Variable *a, Variable *b, operation_type type) {
+    Variable loc_a, loc_b;
+
+    if(a && b) {
+        // Never work on the real var if there are declared variables
+        if(a->name) memcpy(&loc_a, a, sizeof(Variable)); else loc_a = *a;
+        if(b->name) memcpy(&loc_b, b,sizeof(Variable)); else loc_b = *b;
+
+        // Need a cast
+        if(loc_a.type != loc_b.type) {
+            language_type new_type = var_op_compute_type(loc_a.type, loc_b.type);
+            Variable *tmp = NULL;
+
+            if(new_type != loc_a.type) {
+                if(!(tmp = var_op_cast(&loc_a, new_type)))
+                    return NULL;
+                else
+                    loc_a = *tmp; // Error while casting !
+            }
+            else {
+                if(!(tmp = var_op_cast(&loc_b, new_type)))
+                    return NULL;
+                else
+                    loc_b = *tmp; // Error while casting !
+            }
+        }
+
+        if(var_op_func_arithmetic[type - var_op_func_arithmetic_id][loc_a.type])
+            return var_op_func_arithmetic[type - var_op_func_arithmetic_id][loc_a.type](a, b);
+        else {
+            err_add("Impossible operation for the current type of variable", E_CRITICAL, OP_IMPOSSIBLE);
+            return NULL;
+        }
     } else {
-        puts("\t(null)");
+        err_add("One of the value computed in the arithmetic operation is not defined properly in the memory", E_CRITICAL, NULL_VALUE);
+        return NULL;
     }
 }

+
+Variable* var_op_assignment(Variable *a, Variable *b) {
+    return a;
+}
+
+Variable* var_op_logical(Variable *a, Variable *b) {
+    return a;
+}
+
+
+// Effectuer une opération mathématique
+Variable* var_op(Variable *a, Variable *b, operation_type type) {
+    if(var_op_func_arithmetic_id & type)
+        return var_op_arithmetic(a, b, type);
+    else {
+        err_add("Unknown type of operation between two variable", E_CRITICAL, UNKOWN_TYPE);
+        return NULL;
+    }
+}
+
 int main(void) {

-    variable v;
-    variable *v_ptr = NULL;
+    // Variables
+    Variable v;
+    Variable *v_ptr = NULL, *v_ptr2 = NULL;

     var_init_int(&v, "test", 12);
     v_ptr = var_new_int("coucou", 23);
+    v_ptr2 = var_new_lint("long", (long int)42);

     var_dump(&v);
-    var_dump(v_ptr);
-
+    puts("");
     var_empty(&v);
-    var_del(v_ptr);
+
+    // Liste de variables
+    Variable_list *var_l = NULL;
+
+    var_list_append(&var_l, v_ptr);
+    var_list_append(&var_l, v_ptr2);
+
+    var_list_dump(var_l);
+
+    var_list_del(var_l);

     return 0;
 }


main BUGFIX standard NC error tags lock-denied, in-use and data-exists (#657)

--- src/main.c
+++ src/main.c
@@ -344,9 +344,28 @@
         /* fallthrough */
     default:
         if (strstr(message, "authorization failed")) {
+            // access-denied
             goto err_access_denied;
-        } else if (strstr(message, "is already locked")) {
+        } else if (strstr(message, "is already locked") ||
+                   strstr(message, "Module \"yang\" is locked by session")) {
+            // lock-denied
             goto err_lock_denied;
+        } else if (strstr(message, "is locked by session")) {
+            // in-use
+            e = nc_err(NC_ERR_IN_USE, NC_ERR_TYPE_PROT);
+            nc_err_set_msg(e, message, "en");
+            if (xpath) {
+                nc_err_set_path(e, xpath);
+            }
+            break;
+        } else if (strstr(message, "already exists")) {
+            // data-exists
+            e = nc_err(NC_ERR_DATA_EXISTS);
+            nc_err_set_msg(e, message, "en");
+            if (xpath) {
+                nc_err_set_path(e, xpath);
+            }
+            break;
         } else if (strstr(message, "Source and target")) {
             e = nc_err(NC_ERR_INVALID_VALUE, NC_ERR_TYPE_PROT);
             nc_err_set_msg(e, message, "en");


* status message when trying to make a move while no ongoing game is found

--- src/main.c
+++ src/main.c
@@ -251,6 +251,7 @@
 	} else {
 		// No game? Can't play.
 		if (!has_game(true)) {
+			fprintf(stderr, "No game present.\n");
 			return 1;
 		}
 		// Read game from file


Fix double-free

Fix double-free

--- src/main.c
+++ src/main.c
@@ -71,7 +71,6 @@
 		if (!newbuf) {
 			return buf;
 		}
-		free (buf);
 		return newbuf;
 	}
 #endif


Fix typo

Fix typo

--- src/main.c
+++ src/main.c
@@ -19,7 +19,7 @@
 ** then loads the entry from the terminfo database for name, if it exists.
 ** I'm using STDERR_FILENO instead of STDOUT_FILENO to take care of command
 ** substitutions so that we don't use the same file descriptor as the calling
-** command. Using STDERR_FILENO would have been a problem too for some commands
+** command. Using STDIN_FILENO would have been a problem too for some commands
 ** i.e.: rm `./ft_ls test1 test2`
 **
 ** @param		tty_name 	entry name received from the environment variable


Fixed half bug.

Fixed half bug.

--- src/main.c
+++ src/main.c
@@ -10,9 +10,9 @@
   struct tm *tick_time = localtime(&temp);

   // Write the current hours and minutes into a buffer
-  static char s_buffer[8];
-  strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ?
-                                           "%H:%M" : "%I:%M", tick_time);
+  //static char s_buffer[8];
+  //strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ?
+                                           //"%H:%M" : "%I:%M", tick_time);
   //hour
   static char out_hour_text[11];
   static char out_hour[11];
@@ -59,6 +59,7 @@
     strcpy(out_half, "half ");
   }else{
     if (bmin > 30) {
+      strcpy(out_half, "");
       *out_mins = (bmin - 60) * -1;
     }else{
       *out_mins = bmin;
@@ -85,7 +86,9 @@
   strcpy(out_text, " ");

   strcat (out_mins_c, " ");
-  strcat (out_text, out_mins_c);
+  if (bmin != 30){
+    strcat (out_text, out_mins_c);
+  }
   strcat (out_text, out_half);
   strcat (out_text, out_til_past);
   strcat (out_hour, " ");


GC stdint.h. Suggested by the includepolice.

--- src/main.c
+++ src/main.c
@@ -44,7 +44,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <signal.h>
 #include <string.h>
 #include <unistd.h>


Fix infinite loop in last commit.

Fix infinite loop in last commit.

--- src/main.c
+++ src/main.c
@@ -407,6 +407,7 @@
 					if (PianoGetPlaylist (&ph, curStation->id) !=
 							PIANO_RET_OK) {
 						BarUiMsg ("Error.\n");
+						curStation = NULL;
 					} else {
 						curSong = ph.playlist;
 						if (curSong == NULL) {


Don't use Parrot_exit in Parrot_version. Interp ins't initialized yet.

git-svn-id: 6e74a02f85675cec270f5d931b0f6998666294a3@43862 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/main.c
+++ src/main.c
@@ -327,7 +327,7 @@
 \n\
 included in the Parrot source tree.\n\n");

-    Parrot_exit(interp, 0);
+    exit(EXIT_SUCCESS);
 }
 /*


got rid of redundant startup

got rid of redundant startup

--- src/main.c
+++ src/main.c
@@ -37,8 +37,8 @@

   // Initialize Serial Communication
-//  init_mavlink();
-//  init_sensors();
+  init_mavlink();
+  init_sensors();

   /***********************/
@@ -47,12 +47,8 @@

   // Initialize Motor Mixing
   init_mixing();
+
   // Initialize Estimator
-//  init_estimator();
-
-  delay(500);
-  i2cInit(I2CDEV_2);
-  init_sensors();
   init_estimator();
 }


ctype functions take ints

ctype functions take ints

--- src/main.c
+++ src/main.c
@@ -116,11 +116,11 @@

 	/* Transfer the station id from end to beginning, simultaneously capitalizing */
 	for (i = 1; i <= stationLen; i++) {
-		if (!isalnum(station[stationLen - i])) {
+		if (!isalnum((int)station[stationLen - i])) {
 			warnx("Station ID must contain only alphanumeric characters.");
 			return false;
 		}
-		buf[(written + STATION_ID_LEN) - i] = (char)toupper(station[stationLen - i]);
+		buf[(written + STATION_ID_LEN) - i] = (char)toupper((int)station[stationLen - i]);
 	}

 	/* If it is a character short, prepend the 'K' */


[main] load modules existing in PKGLIBDIR

--- src/main.c
+++ src/main.c
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <sys/stat.h>
+#include <unistd.h>

 #ifndef WIN32
 # include <sys/socket.h>
@@ -43,6 +44,8 @@
 # include <winsock2.h>
 #endif
 #ifdef MODULES
+#include <fcntl.h>
+#include <dirent.h>
 #include <dlfcn.h>
 #endif

@@ -146,58 +149,7 @@
 	return ret;
 }

-#ifdef MODULES
-static const char *default_modules[] =
-{
-#if defined TLS
-	str_tls,
-#endif
-#if defined VHOSTS_DEPRECATED
-	str_vhosts,
-#endif
-#if defined CLIENTFILTER
-	str_clientfilter,
-#endif
-#if defined COOKIE
-	str_cookie,
-#endif
-#if defined AUTH
-	str_auth,
-#endif
-#if defined USERFILTER
-	str_userfilter,
-#endif
-#if defined METHODLOCK
-	str_methodlock,
-#endif
-#if defined SERVERHEADER
-	str_server,
-#endif
-#if defined CGI
-	str_cgi,
-#endif
-#if defined DOCUMENT
-	str_document,
-#endif
-#if defined WEBSTREAM
-	str_webstream,
-#endif
-#if defined WEBSOCKET
-	str_websocket,
-#endif
-#if defined REDIRECT
-	str_redirect404,
-	str_redirect,
-#endif
-#if defined CORS
-	str_cors,
-#endif
-#if defined TINYSVCMDNS
-	str_tinysvcmdns,
-#endif
-	NULL
-};
-#else
+#ifndef MODULES
 static const module_t *default_modules[] =
 {
 #if defined TLS
@@ -358,7 +310,7 @@
 	{
 		if (!strcmp(iterator->module->name, module->name))
 		{
-			warn("module loaded twice");
+			warn("module %s loaded twice", module->name);
 			return;
 		}
 		iterator = iterator->next;
@@ -367,6 +319,7 @@
 	new->module = module;
 	new->next = g_modules;
 	g_modules = new;
+	dbg("module %s regitered", module->name);
 }

 server_t *ouistiti_loadserver(serverconfig_t *config)
@@ -393,15 +346,34 @@
 }

 #ifdef MODULES
+static int modulefilter(const struct dirent *entry)
+{
+	return !strncmp(entry->d_name, "mod_", 4);
+}
+
 static int _ouistiti_initmodules()
 {
 	int i;
-
-	for (i = 0; default_modules[i] != NULL; i++)
-	{
-		char file[512];
-		snprintf(file, 511, PKGLIBDIR"/mod_%s.so", default_modules[i]);
-		void *dh = dlopen(file, RTLD_LAZY | RTLD_GLOBAL);
+	int cwdfd = open(".", O_DIRECTORY);
+	int pkglibfd = open(PKGLIBDIR, O_DIRECTORY);
+	if (pkglibfd == -1)
+	{
+		return EREJECT;
+	}
+	if (fchdir(pkglibfd) == -1)
+	{
+		err("Package linbrary dir "PKGLIBDIR" notfound");
+		return EREJECT;
+	}
+
+	int ret;
+	struct dirent **namelist = NULL;
+	ret = scandir(".", &namelist, &modulefilter, alphasort);
+	for (i = 0; i < ret; i++)
+	{
+		const char *name = namelist[i]->d_name;
+		void *dh = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
+
 		if (dh != NULL)
 		{
 			module_t *module = dlsym(dh, "mod_info");
@@ -414,8 +386,13 @@
 		}
 		else
 		{
-			err("module %s loading error: %s", file, dlerror());
+			err("module %s loading error: %s", name, dlerror());
 		}
+	}
+	if (fchdir(cwdfd) == -1)
+	{
+		err("Package linbrary dir "PKGLIBDIR" notfound");
+		return EREJECT;
 	}
 	return ESUCCESS;
 }


Moved strings into static buffers

Moved strings into static buffers

--- src/main.c
+++ src/main.c
@@ -76,6 +76,10 @@
 #define MS 4
 #define MSD 0

+// Strings for messages
+static char KEEP_GOING[]="Keep Going";
+static char GOOD_JOB[]="Good Job";
+static char NEW_HIGH[]="New High";

 // Timer used to determine next step check
 //static AppTimer *timer;
@@ -621,17 +625,17 @@
     }

     if(maxSteps!=0 && pedometerCount > maxSteps) {
-    	message("New High");
+    	message(NEW_HIGH);
     	maxSteps=0;
     }

 		if (pedometerCount % 2000 == 0) {
 			info_mode();
 			if (pedometerCount>=10000) {
-				message("Good Job");
+				message(GOOD_JOB);
 			}
 			else {
-				message("Keep Going");
+				message(KEEP_GOING);
 			}
 			vibes_long_pulse();
 		}


main: shorten info printout by using shorter names

Signed-off-by: Enrico Jorns <a2e5f936c390f36494e46e71bcfbe365bb1e8c49@pengutronix.de>

--- src/main.c
+++ src/main.c
@@ -266,10 +266,10 @@
 	GString *text = g_string_new(NULL);
 	gint cnt = 0;

-	g_string_append_printf(text, "Compatible String:\t'%s'\n", manifest->update_compatible);
-	g_string_append_printf(text, "Update version:   \t'%s'\n", manifest->update_version);
-	g_string_append_printf(text, "Description:      \t'%s'\n", manifest->update_description);
-	g_string_append_printf(text, "Build:            \t'%s'\n", manifest->update_build);
+	g_string_append_printf(text, "Compatible: \t'%s'\n", manifest->update_compatible);
+	g_string_append_printf(text, "Version:    \t'%s'\n", manifest->update_version);
+	g_string_append_printf(text, "Description:\t'%s'\n", manifest->update_description);
+	g_string_append_printf(text, "Build:      \t'%s'\n", manifest->update_build);

 	cnt = g_list_length(manifest->images);
 	g_string_append_printf(text, "%d Image%s%s\n", cnt, cnt == 1 ? "" : "s", cnt > 0 ? ":" : "");


Removed unnecessary error message.

Removed unnecessary error message.

--- src/main.c
+++ src/main.c
@@ -74,9 +74,6 @@
 			&startInfo,			// startup info
 			&process)			// process information
 		) {
-
-		printf("Creation of the process failed, trying to fetch error message...\n");
-
 		long lastError = GetLastError();
 		char* message = NULL;


fix -d bug

fix -d bug

--- src/main.c
+++ src/main.c
@@ -15,6 +15,11 @@
 	char db[strlen(filename)+5];
 	strcpy(db, filename);
 	strcat(db, ".midx");
+
+	if(access (filename, F_OK) == -1){
+			fprintf(stderr, "\nFATAL: One fasta file does not exist.\n       -d does not take an argument\n");
+			exit(1);
+		}

 	if(access (db, F_OK) != -1 ){
 				readDB(mins, filename);


Added mutex for hash table put

Added mutex for hash table put

--- src/main.c
+++ src/main.c
@@ -128,7 +128,11 @@
                 goto fail;

             ck_ht_entry_set(&entry, hash, my_key, key->len, etag);
+
+            /* CK doesn't support multiple writers */
+            uv_mutex_lock(&sv->etag_lock);
             e = ck_ht_put_spmc(&sv->etags, hash, &entry);
+            uv_mutex_unlock(&sv->etag_lock);
         }
     }
     while (e == 0);


change maturity

change maturity

--- src/main.h
+++ src/main.h
@@ -73,7 +73,7 @@
 /** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
 /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
-static const int COINBASE_MATURITY = 100;
+static const int COINBASE_MATURITY = 3;
 /** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
 static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov  5 00:53:20 1985 UTC
 /** Maximum number of script-checking threads allowed */


Changed sdp.packet_duration to a double to avoid rounding error

--- src/mast.h
+++ src/mast.h
@@ -146,7 +146,7 @@
     int encoding;              // a=rtpmap
     int sample_rate;           // a=rtpmap
     int channel_count;         // a=rtpmap
-    float packet_duration;     // a=ptime
+    double packet_duration;    // a=ptime

     char ptp_gmid[24];         // a=ts-refclk
     uint64_t clock_offset;     // a=mediaclk


Fix C++ compilation

Fix C++ compilation

--- src/mat5.c
+++ src/mat5.c
@@ -1974,7 +1974,8 @@
             } else if ( buf[0] != MAT_T_MATRIX ) {
                 Mat_VarFree(cells[i]);
                 cells[i] = NULL;
-                Mat_Critical("cells[%d] not MAT_T_MATRIX, fpos = %ld",i,ftell(mat->fp));
+                Mat_Critical("cells[%d] not MAT_T_MATRIX, fpos = %ld",i,
+                    ftell((FILE*)mat->fp));
                 break;
             }
             cells[i]->compression = MAT_COMPRESSION_NONE;
@@ -2346,7 +2347,8 @@
             if ( buf[0] != MAT_T_MATRIX ) {
                 Mat_VarFree(fields[i]);
                 fields[i] = NULL;
-                Mat_Critical("fields[%d] not MAT_T_MATRIX, fpos = %ld",i,ftell(mat->fp));
+                Mat_Critical("fields[%d] not MAT_T_MATRIX, fpos = %ld",i,
+                    ftell((FILE*)mat->fp));
                 return bytesread;
             } else if ( nBytes == 0 ) {
                 fields[i]->rank = 0;


mdbx: refine mdbx_meta_ot() and dependents.

Change-Id: I449d501f0c3710fdb906e01931e10300ab3b7c9d

--- src/mdbx.c
+++ src/mdbx.c
@@ -1402,9 +1402,9 @@

 enum meta_choise_mode { prefer_last, prefer_noweak, prefer_steady };

-static __inline bool mdbx_meta_ot(const MDBX_env *env, const MDBX_meta *a,
-                                  const MDBX_meta *b,
-                                  const enum meta_choise_mode mode) {
+static __inline bool mdbx_meta_ot(const enum meta_choise_mode mode,
+                                  const MDBX_env *env, const MDBX_meta *a,
+                                  const MDBX_meta *b) {
   mdbx_jitter4testing(true);
   txnid_t txnid_a = mdbx_meta_txnid_fluid(env, a);
   txnid_t txnid_b = mdbx_meta_txnid_fluid(env, b);
@@ -1458,43 +1458,43 @@
   return rc;
 }

-static __inline MDBX_meta *mdbx_meta_recent(const MDBX_env *env, MDBX_meta *a,
-                                            MDBX_meta *b,
-                                            const enum meta_choise_mode mode) {
-  const bool a_older_that_b = mdbx_meta_ot(env, a, b, mode);
+static __inline MDBX_meta *mdbx_meta_recent(const enum meta_choise_mode mode,
+                                            const MDBX_env *env, MDBX_meta *a,
+                                            MDBX_meta *b) {
+  const bool a_older_that_b = mdbx_meta_ot(mode, env, a, b);
   mdbx_assert(env, !mdbx_meta_eq(env, a, b));
   return a_older_that_b ? b : a;
 }

-static __inline MDBX_meta *mdbx_meta_ancient(const MDBX_env *env, MDBX_meta *a,
-                                             MDBX_meta *b,
-                                             const enum meta_choise_mode mode) {
-  const bool a_older_that_b = mdbx_meta_ot(env, a, b, mode);
+static __inline MDBX_meta *mdbx_meta_ancient(const enum meta_choise_mode mode,
+                                             const MDBX_env *env, MDBX_meta *a,
+                                             MDBX_meta *b) {
+  const bool a_older_that_b = mdbx_meta_ot(mode, env, a, b);
   mdbx_assert(env, !mdbx_meta_eq(env, a, b));
   return a_older_that_b ? a : b;
 }

 static __inline MDBX_meta *
-mdbx_meta_mostrecent(const MDBX_env *env, const enum meta_choise_mode mode) {
+mdbx_meta_mostrecent(const enum meta_choise_mode mode, const MDBX_env *env) {
   MDBX_meta *m0 = METAPAGE(env, 0);
   MDBX_meta *m1 = METAPAGE(env, 1);
   MDBX_meta *m2 = METAPAGE(env, 2);

-  MDBX_meta *head = mdbx_meta_recent(env, m0, m1, mode);
-  head = mdbx_meta_recent(env, head, m2, mode);
+  MDBX_meta *head = mdbx_meta_recent(mode, env, m0, m1);
+  head = mdbx_meta_recent(mode, env, head, m2);
   return head;
 }

 static __hot MDBX_meta *mdbx_meta_steady(const MDBX_env *env) {
-  return mdbx_meta_mostrecent(env, prefer_steady);
+  return mdbx_meta_mostrecent(prefer_steady, env);
 }

 static __hot MDBX_meta *mdbx_meta_head(const MDBX_env *env) {
-  return mdbx_meta_mostrecent(env, prefer_last);
+  return mdbx_meta_mostrecent(prefer_last, env);
 }

 static __hot txnid_t mdbx_reclaiming_detent(const MDBX_env *env) {
-  MDBX_meta *meta = mdbx_meta_mostrecent(env, prefer_noweak);
+  MDBX_meta *meta = mdbx_meta_mostrecent(prefer_noweak, env);
   return mdbx_meta_txnid_stable(env, meta);
 }

@@ -3784,7 +3784,7 @@
       continue;
     }

-    if (mdbx_meta_ot(env, meta, &page.mp_meta, true)) {
+    if (mdbx_meta_ot(prefer_steady, env, meta, &page.mp_meta)) {
       *meta = page.mp_meta;
       if (META_IS_WEAK(meta))
         loop_limit += 1; /* LY: should re-read to hush race with update */
@@ -3947,12 +3947,12 @@
       return MDBX_SUCCESS;
     }
   } else if (head == meta0)
-    target = mdbx_meta_ancient(env, meta1, meta2, true);
+    target = mdbx_meta_ancient(prefer_steady, env, meta1, meta2);
   else if (head == meta1)
-    target = mdbx_meta_ancient(env, meta0, meta2, true);
+    target = mdbx_meta_ancient(prefer_steady, env, meta0, meta2);
   else {
     mdbx_assert(env, head == meta2);
-    target = mdbx_meta_ancient(env, meta0, meta1, true);
+    target = mdbx_meta_ancient(prefer_steady, env, meta0, meta1);
   }

   /* LY: step#2 - update meta-page. */


Skip ResizeMemory if no need to grow

Skip ResizeMemory if no need to grow

--- source/m3_exec.c
+++ source/m3_exec.c
@@ -120,6 +120,9 @@
     u32 requiredPages = memory->numPages + numPagesToGrow;
     _r0 = memory->numPages;

+    if (numPagesToGrow == 0)
+        return nextOp ();
+
     M3Result r = ResizeMemory (runtime, requiredPages);
     if (r)
         _r0 = -1;


Ensured that the backed up code works as expected.

--- src/menu.c
+++ src/menu.c
@@ -6,13 +6,20 @@
 #include <unistd.h>

 #define CCTL ((unsigned char *) 0xD500)
-#define CART_START 0xBFFA
 #define COPY_AREA 0x1000 // NOTE This may collide with DOS.
+#define RESET 0xFFFC

-void __fastcall__ menu(void) {
-  unsigned char off = 0;
-  unsigned int *address = (unsigned int *) 0xBFFA;
+unsigned char off = 0; // NOTE Game offset in BSS.

+void __fastcall__ execute(void) {
+  // Swap the game.
+  *CCTL = off;
+
+  // Reset the console.
+  __asm__ ("jmp (%w)", RESET);
+}
+
+int main(void) {
   clrscr();
   printf("    _  _            _  __  _____ \n");
   printf("   /_\\| |_ __ _ _ _(_) \\ \\/ / __|\n");
@@ -27,24 +34,16 @@
   printf("Select a game (1-32): ");
   scanf("%d", &off);

-  // Swap the game.
-  *CCTL = off;
+  if(off > 0) {
+    // Backup exec() into the RAM not to loose it later.
+    memcpy((void *) COPY_AREA, (const void *) execute, 1024); // FIXME Compute the size somehow.

-  // Jump into the newly swapped game.
-  if(off > 0) {
-    __asm__ ("jmp (%w)", CART_START);
+    // Jump into the backup.
+    __asm__ ("jmp %w", COPY_AREA);
   }

   printf("Bye!\n");
   sleep(1);
-}
-
-int main(void) {
-  // Backup menu() into the RAM not to loose it later.
-  memcpy((void *) COPY_AREA, (const void *) menu, 1024); // FIXME Compute the size somehow.
-
-  // Jump into the backup.
-  __asm__ ("jmp %w", COPY_AREA);

   return 0;
 }


Add the number of lanes.

Add the number of lanes.

--- src/mipp.h
+++ src/mipp.h
@@ -106,6 +106,7 @@
 	#define MIPP_REQUIRED_ALIGNMENT 16
 	constexpr uint32_t RequiredAlignment = MIPP_REQUIRED_ALIGNMENT;
 	constexpr uint32_t RegisterSizeBit = 128;
+	constexpr uint32_t Lanes = 1;

 	using msk   = uint32x4_t;
 	using reg   = float32x4_t;
@@ -122,6 +123,7 @@
 	#define MIPP_REQUIRED_ALIGNMENT 64
 	constexpr uint32_t RequiredAlignment = MIPP_REQUIRED_ALIGNMENT;
 	constexpr uint32_t RegisterSizeBit = 512;
+	constexpr uint32_t Lanes = 4;

 #ifdef __AVX512BW__
 	using msk   = __mmask64;
@@ -142,6 +144,7 @@
 	#define MIPP_REQUIRED_ALIGNMENT 32
 	constexpr uint32_t RequiredAlignment = MIPP_REQUIRED_ALIGNMENT;
 	constexpr uint32_t RegisterSizeBit = 256;
+	constexpr uint32_t Lanes = 2;

 	using msk   = __m256i;
 	using reg   = __m256;
@@ -162,6 +165,7 @@
 	#define MIPP_REQUIRED_ALIGNMENT 16
 	constexpr uint32_t RequiredAlignment = MIPP_REQUIRED_ALIGNMENT;
 	constexpr uint32_t RegisterSizeBit = 128;
+	constexpr uint32_t Lanes = 1;

 	using msk   = __m128i;
 	using reg   = __m128;
@@ -191,6 +195,7 @@
 	#define MIPP_REQUIRED_ALIGNMENT 1
 	constexpr uint32_t RequiredAlignment = MIPP_REQUIRED_ALIGNMENT;
 	constexpr uint32_t RegisterSizeBit = 0;
+	constexpr uint32_t Lanes = 1;

 	using msk   = uint8_t;
 	using reg   = int32_t;
@@ -208,6 +213,7 @@
 	#define MIPP_REQUIRED_ALIGNMENT 1
 	constexpr uint32_t RequiredAlignment = MIPP_REQUIRED_ALIGNMENT;
 	constexpr uint32_t RegisterSizeBit = 0;
+	constexpr uint32_t Lanes = 1;

 	using msk   = uint8_t;
 	using reg   = int32_t;
@@ -559,28 +565,26 @@
 template <typename T>
 void dump(const mipp::reg r, std::ostream &stream = std::cout, const uint32_t elmtWidth = 6)
 {
+	constexpr int32_t lane_size = (int32_t)(mipp::N<T>() / mipp::Lanes);
+
 //	const T* data = (T*)&r;
 	T data[mipp::nElReg<T>()];
 	store<T>(data, r);

 	stream << "[";
-#if defined(__AVX__)
-	for (auto i = 0; i < mipp::nElReg<T>()/2; i++)
-		stream << std::setw(elmtWidth) << +data[i] << ((i < mipp::nElReg<T>()/2-1) ? ", " : "");
-	stream << " | ";
-	for (auto i = mipp::nElReg<T>()/2; i < mipp::nElReg<T>(); i++)
-		stream << std::setw(elmtWidth) << +data[i] << ((i < mipp::nElReg<T>()-1) ? ", " : "");
-#else
-	for (auto i = 0; i < mipp::nElReg<T>(); i++)
-		stream << std::setw(elmtWidth) << +data[i] << ((i < mipp::nElReg<T>()-1) ? ", " : "");
-#endif
-
+	for (auto l = 0; l < (int)mipp::Lanes; l++)
+	{
+		for (auto i = 0; i < lane_size; i++)
+			stream << std::setw(elmtWidth) << +data[l * lane_size +i] << ((i < lane_size -1) ? ", " : "");
+		stream << ((l < mipp::Lanes -1) ? " | " : "");
+	}
 	stream << "]";
 }

 template <int N>
 void dump(const mipp::msk m, std::ostream &stream = std::cout, const uint32_t elmtWidth = 6)
 {
+	constexpr int32_t lane_size = (int32_t)(N / mipp::Lanes);
 	constexpr int bits = mipp::RegisterSizeBit / N;

 	const auto r = cvt_msk_reg(m);
@@ -592,16 +596,12 @@
 		int8_t data[N];
 		store<int8_t>(data, r);

-#if defined(__AVX__)
-		for (auto i = 0; i < N/2; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N/2-1) ? ", " : "");
-		stream << " | ";
-		for (auto i = N/2; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#else
-		for (auto i = 0; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#endif
+		for (auto l = 0; l < (int)mipp::Lanes; l++)
+		{
+			for (auto i = 0; i < lane_size; i++)
+				stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < lane_size -1) ? ", " : "");
+			stream << ((l < mipp::Lanes -1) ? " | " : "");
+		}
 	}
 	else if (bits == 16)
 	{
@@ -609,16 +609,12 @@
 		int16_t data[N];
 		store<int16_t>(data, r);

-#if defined(__AVX__)
-		for (auto i = 0; i < N/2; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N/2-1) ? ", " : "");
-		stream << " | ";
-		for (auto i = N/2; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#else
-		for (auto i = 0; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#endif
+		for (auto l = 0; l < (int)mipp::Lanes; l++)
+		{
+			for (auto i = 0; i < lane_size; i++)
+				stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < lane_size -1) ? ", " : "");
+			stream << ((l < mipp::Lanes -1) ? " | " : "");
+		}
 	}
 	else if (bits == 32)
 	{
@@ -626,16 +622,12 @@
 		int32_t data[N];
 		store<int32_t>(data, r);

-#if defined(__AVX__)
-		for (auto i = 0; i < N/2; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N/2-1) ? ", " : "");
-		stream << " | ";
-		for (auto i = N/2; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#else
-		for (auto i = 0; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#endif
+		for (auto l = 0; l < (int)mipp::Lanes; l++)
+		{
+			for (auto i = 0; i < lane_size; i++)
+				stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < lane_size -1) ? ", " : "");
+			stream << ((l < mipp::Lanes -1) ? " | " : "");
+		}
 	}
 	else if (bits == 64)
 	{
@@ -643,16 +635,12 @@
 		int64_t data[N];
 		store<int64_t>(data, r);

-#if defined(__AVX__)
-		for (auto i = 0; i < N/2; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N/2-1) ? ", " : "");
-		stream << " | ";
-		for (auto i = N/2; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#else
-		for (auto i = 0; i < N; i++)
-			stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < N-1) ? ", " : "");
-#endif
+		for (auto l = 0; l < (int)mipp::Lanes; l++)
+		{
+			for (auto i = 0; i < lane_size; i++)
+				stream << std::setw(elmtWidth) << (data[i] ? 1 : 0) << ((i < lane_size -1) ? ", " : "");
+			stream << ((l < mipp::Lanes -1) ? " | " : "");
+		}
 	}

 	stream << "]";


Update patches.c

Update patches.c

--- source/patches.c
+++ source/patches.c
@@ -4,6 +4,7 @@
 void patchARM9(u32* FIRM, u32 search_size){
 	cleanITCM();
 	patchSignatureChecks(FIRM, search_size);
+	restoreFirmlaunchhax(FIRM, search_size);
 	return;
 }

@@ -56,4 +57,4 @@

 		patch(FIRM, search_size, svcpattern, svcpatch, sizeof(svcpattern), sizeof(svcpatch), 0);

-}+}


Added __glcUniCopy to duplicate Unicode strings

--- src/misc.c
+++ src/misc.c
@@ -134,3 +134,31 @@
   (*list)->tail = NULL;
   return GL_TRUE;
 }
+
+/* Duplicate a Unicode string */
+__glcUniChar* __glcUniCopy(__glcUniChar* inUniChar, GLint inStringType)
+{
+  __glcUniChar* outUniChar = NULL;
+  int length = 0;
+  GLCchar* buffer = NULL;
+
+  length = __glcUniEstimate(inUniChar, inStringType);
+  buffer = (GLCchar *)__glcMalloc(length);
+  if (!buffer) {
+    __glcRaiseError(GLC_RESOURCE_ERROR);
+    return NULL;
+  }
+
+  __glcUniConvert(inUniChar, buffer, inStringType, length);
+  outUniChar = (__glcUniChar*)__glcMalloc(sizeof(__glcUniChar));
+  if (!outUniChar) {
+    __glcFree(buffer);
+    __glcRaiseError(GLC_RESOURCE_ERROR);
+    return NULL;
+  }
+
+  outUniChar->ptr = buffer;
+  outUniChar->type = inStringType;
+
+  return outUniChar;
+}


Added define LOAD_LIBRARY_SEARCH_SYSTEM32 for old Windows SDKs (#9)

--- src/misc.c
+++ src/misc.c
@@ -56,6 +56,9 @@

 #endif  /* DEBUG */

+#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
+#define LOAD_LIBRARY_SEARCH_SYSTEM32        0x00000800
+#endif

 HMODULE
 wd_load_system_dll(const TCHAR* dll_name)


Import src/misc.h from ccid 1.4.19.

Import src/misc.h from ccid 1.4.19.

--- src/misc.h
+++ src/misc.h
@@ -18,9 +18,6 @@
 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

-Changes to this license can be made only by the copyright author with
-explicit written consent.
-
 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
@@ -32,7 +29,7 @@
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $Id: misc.h 6851 2014-02-14 15:43:32Z rousseau $
+ * $Id$
  */

 #ifndef __misc_h__


fixed bug

fixed bug

--- src/mjhz.c
+++ src/mjhz.c
@@ -34,46 +34,46 @@
     mj->inning = 0;
     mj->turn_time = 30;

-	/* 杭州麻将使用136张牌 */
-	/* 序数牌 */
-	n = 0;
-	for (i = 0; i < 4; i++) {
-		for (j = 0; j < 10; j++) {
-			mj->deck[n].suit = mjSuitWan;
-			mj->deck[n].sign = mj1 + j;
-			n++;
-			mj->deck[n].suit = mjSuitSuo;
-			mj->deck[n].sign = mj1 + j;
-			n++;
-			mj->deck[n].suit = mjSuitTong;
-			mj->deck[n].sign = mj1 + j;
-			n++;
-		}
-	}
-	/* 字牌 */
-	for (i = 0; i < 4; i++) {
-		mj->deck[n].suit = mjSuitFeng;
-		mj->deck[n].sign = mjEast;
-		n++;
-		mj->deck[n].suit = mjSuitFeng;
-		mj->deck[n].sign = mjSouth;
-		n++;
-		mj->deck[n].suit = mjSuitFeng;
-		mj->deck[n].sign = mjWest;
-		n++;
-		mj->deck[n].suit = mjSuitFeng;
-		mj->deck[n].sign = mjNorth;
-		n++;
-		mj->deck[n].suit = mjSuitZFB;
-		mj->deck[n].sign = mjZhong;
-		n++;
-		mj->deck[n].suit = mjSuitZFB;
-		mj->deck[n].sign = mjFa;
-		n++;
-		mj->deck[n].suit = mjSuitZFB;
-		mj->deck[n].sign = mjBai;
-		n++;
-	}
+    /* 杭州麻将使用136张牌 */
+    /* 序数牌 */
+    n = 0;
+    for (i = 0; i < 4; i++) {
+        for (j = 0; j < 10; j++) {
+            mj->deck[n].suit = mjSuitWan;
+            mj->deck[n].sign = mj1 + j;
+            n++;
+            mj->deck[n].suit = mjSuitSuo;
+            mj->deck[n].sign = mj1 + j;
+            n++;
+            mj->deck[n].suit = mjSuitTong;
+            mj->deck[n].sign = mj1 + j;
+            n++;
+        }
+    }
+    /* 字牌 */
+    for (i = 0; i < 4; i++) {
+        mj->deck[n].suit = mjSuitFeng;
+        mj->deck[n].sign = mjEast;
+        n++;
+        mj->deck[n].suit = mjSuitFeng;
+        mj->deck[n].sign = mjSouth;
+        n++;
+        mj->deck[n].suit = mjSuitFeng;
+        mj->deck[n].sign = mjWest;
+        n++;
+        mj->deck[n].suit = mjSuitFeng;
+        mj->deck[n].sign = mjNorth;
+        n++;
+        mj->deck[n].suit = mjSuitZFB;
+        mj->deck[n].sign = mjZhong;
+        n++;
+        mj->deck[n].suit = mjSuitZFB;
+        mj->deck[n].sign = mjFa;
+        n++;
+        mj->deck[n].suit = mjSuitZFB;
+        mj->deck[n].sign = mjBai;
+        n++;
+    }
     mj->deck_all_num = n;

     for(i = 0; i < MJHZ_MAX_PLAYERS; i++){
@@ -91,50 +91,50 @@
     mj->game_state = MJHZ_GAME_PLAY;
     mj->inning++;

-	mj->dice1 = rand() % 6 + 1;
-	mj->dice2 = rand() % 6 + 1;
-
-	/* 白板是财神 */
-	mj->joker.suit = mjSuitZFB;
-	mj->joker.sign = mjBai;
-
-	mj->last_played_mj.suit = 0;
-	mj->last_played_mj.sign = 0;
+    mj->dice1 = rand() % 6 + 1;
+    mj->dice2 = rand() % 6 + 1;
+
+    /* 白板是财神 */
+    mj->joker.suit = mjSuitZFB;
+    mj->joker.sign = mjBai;
+
+    mj->last_played_mj.suit = 0;
+    mj->last_played_mj.sign = 0;

     if (mj->mode == MJHZ_MODE_SERVER) {
-		/* 洗牌 */
-		mj_shuffle(mj->deck, mj->deck_all_num);
-		/* 计算起手牌位置 */
-		direct = (mj->banker_no + MJHZ_MAX_PLAYERS
-			- (mj->dice1 + mj->dice2) % MJHZ_MAX_PLAYERS)
-			% MJHZ_MAX_PLAYERS;
-		mj->deck_deal_index = direct * 17 * 2
-			+ (mj->dice1 + mj->dice2) * 2;
-		mj->deck_deal_gang = mj->deck_deal_index - 1; /* 杠抓牌 */
-		mj->deck_deal_end = (mj->deck_deal_index + mj->deck_all_num
-				- 20) % mj->deck_all_num;
-		mj->deck_valid_num = mj->deck_all_num - 20;
-
-		/* 顺时针,每人抓12张,庄家先抓 */
-		m = n = 0;
-		for (i = 0; i < MJHZ_MAX_PLAYERS; i++) {
-			direct = (mj->banker_no + i) % MJHZ_MAX_PLAYERS;
-			memcpy(mj->players[direct].cards + m, mj->deck + n, 4 * sizeof(mjpai_t));
-			n += 4;
-		}
-		m += 12;
-		/* 庄家跳牌2张,其他人一张 */
-		mj->players[mj->banker_no].cards[m].suit = mj->deck[n].suit;
-		mj->players[mj->banker_no].cards[m].sign = mj->deck[n].sign;
-		mj->players[mj->banker_no].cards[m+1].suit = mj->deck[n+4].suit;
-		mj->players[mj->banker_no].cards[m+1].sign = mj->deck[n+4].sign;
-		n++;
-		for (i = 0; i < MJHZ_MAX_PLAYERS; i++) {
-			if (i == mj->banker_no) continue;
-			direct = (mj->banker_no + i) % MJHZ_MAX_PLAYERS;
-			mj->players[direct].cards[m].suit = mj->deck[n].suit;
-			mj->players[direct].cards[m].suit = mj->deck[n].sign;
-		}
+        /* 洗牌 */
+        mj_shuffle(mj->deck, mj->deck_all_num);
+        /* 计算起手牌位置 */
+        direct = (mj->banker_no + MJHZ_MAX_PLAYERS
+                - (mj->dice1 + mj->dice2) % MJHZ_MAX_PLAYERS)
+            % MJHZ_MAX_PLAYERS;
+        mj->deck_deal_index = direct * 17 * 2
+            + (mj->dice1 + mj->dice2) * 2;
+        mj->deck_deal_gang = mj->deck_deal_index - 1; /* 杠抓牌 */
+        mj->deck_deal_end = (mj->deck_deal_index + mj->deck_all_num
+                - 20) % mj->deck_all_num;
+        mj->deck_valid_num = mj->deck_all_num - 20;
+
+        /* 顺时针,每人抓12张,庄家先抓 */
+        m = n = 0;
+        for (i = 0; i < MJHZ_MAX_PLAYERS; i++) {
+            direct = (mj->banker_no + i) % MJHZ_MAX_PLAYERS;
+            memcpy(mj->players[direct].cards + m, mj->deck + n, 4 * sizeof(mjpai_t));
+            n += 4;
+        }
+        m += 12;
+        /* 庄家跳牌2张,其他人一张 */
+        mj->players[mj->banker_no].cards[m].suit = mj->deck[n].suit;
+        mj->players[mj->banker_no].cards[m].sign = mj->deck[n].sign;
+        mj->players[mj->banker_no].cards[m+1].suit = mj->deck[n+4].suit;
+        mj->players[mj->banker_no].cards[m+1].sign = mj->deck[n+4].sign;
+        n++;
+        for (i = 0; i < MJHZ_MAX_PLAYERS; i++) {
+            if (i == mj->banker_no) continue;
+            direct = (mj->banker_no + i) % MJHZ_MAX_PLAYERS;
+            mj->players[direct].cards[m].suit = mj->deck[n].suit;
+            mj->players[direct].cards[m].suit = mj->deck[n].sign;
+        }
         /* the first player */
         mj->first_player_no = mj->banker_no;
         mj->curr_player_no = mj->first_player_no;
@@ -143,57 +143,57 @@
             memset(mj->players[i].cards, 0, sizeof(mjpai_t) * MJHZ_MAX_CARDS);
             memset(mj->players[i].cards_played, 0, sizeof(mjpai_t) * MJHZ_MAX_CARDS);
         }
-		mj->banker_no = 0;
+        mj->banker_no = 0;
         mj->first_player_no = 0;
         mj->curr_player_no = 0;
-		mj->last_played_no = 0;
+        mj->last_played_no = 0;
     }
 }

 /* 财神 万 索 筒 风 */
 void mjhz_sort(mjhz_t* mj, mjpai_t* cards, int len)
 {
-	int i,j;
-	int exchange;
-	mjpai_t temp;
-	mjpai_t *pa, *pb;
-
-	if (!mj || !cards || len < 2)
-		return;
-
-	/* 选择排序 */
-	for (i = 0; i < len - 1; ++i) {
-		exchange = 0;
-		pa = cards + i;
-		for (j = i + 1; j < len; ++j) {
-			pb = cards + j;
-			if (pb->suit == mjSuitZFB && pb->sign == mjBai) {
-				if (pa->suit != mjSuitZFB || pa->sign != mjBai) {
-					exchange = 1;
-					pa = pb;
-				}
-			} else if (pb->suit == pa->suit) {
-				if (pb->sign < pa->sign) {
-					exchange = 1;
-					pa = pb;
-				}
-			} else {
-				if (pb->suit < pa->suit) {
-					exchange = 1;
-					pa = pb;
-				}
-			}
-		}
-		if (exchange) {
-			pb = cards + i;
-			temp.suit = pb->suit;
-			temp.sign = pb->sign;
-			pb->suit = pa->suit;
-			pb->sign = pa->sign;
-			pa->suit = temp.suit;
-			pb->sign = temp.sign;
-		}
-	}
+    int i,j;
+    int exchange;
+    mjpai_t temp;
+    mjpai_t *pa, *pb;
+
+    if (!mj || !cards || len < 2)
+        return;
+
+    /* 选择排序 */
+    for (i = 0; i < len - 1; ++i) {
+        exchange = 0;
+        pa = cards + i;
+        for (j = i + 1; j < len; ++j) {
+            pb = cards + j;
+            if (pb->suit == mjSuitZFB && pb->sign == mjBai) {
+                if (pa->suit != mjSuitZFB || pa->sign != mjBai) {
+                    exchange = 1;
+                    pa = pb;
+                }
+            } else if (pb->suit == pa->suit) {
+                if (pb->sign < pa->sign) {
+                    exchange = 1;
+                    pa = pb;
+                }
+            } else {
+                if (pb->suit < pa->suit) {
+                    exchange = 1;
+                    pa = pb;
+                }
+            }
+        }
+        if (exchange) {
+            pb = cards + i;
+            temp.suit = pb->suit;
+            temp.sign = pb->sign;
+            pb->suit = pa->suit;
+            pb->sign = pa->sign;
+            pa->suit = temp.suit;
+            pb->sign = temp.sign;
+        }
+    }
 }

 const char* mjhz_hu_name(mjhz_hu_t* hu)
@@ -234,71 +234,71 @@
         return -3;
     }

-	/* 有效检查并删除这张牌 */
+    /* 有效检查并删除这张牌 */
     if (mj->mode == MJHZ_MODE_SERVER) {
-		n = -1;
-		cd = mj->players[player_no].cards;
+        n = -1;
+        cd = mj->players[player_no].cards;
         for (i = 0; i < MJHZ_MAX_CARDS; ++i){
-			if (cd->suit == card->suit && cd->sign == card->sign) {
-				n = i;
-				break;
-			}
-			cd++;
-		}
-		if (n == -1) {
+            if (cd->suit == card->suit && cd->sign == card->sign) {
+                n = i;
+                break;
+            }
+            cd++;
+        }
+        if (n == -1) {
             if (mj->debug) {
                 printf("play cards but player hasn't this card.\n");
             }
-			return -4;
+            return -4;
         } else {
-			mj->players[player_no].cards[n].suit = 0;
-			mj->players[player_no].cards[n].sign = 0;
-		}
+            mj->players[player_no].cards[n].suit = 0;
+            mj->players[player_no].cards[n].sign = 0;
+        }
     } else {
-		cd = mj->players[player_no].cards;
-		for (i = 0; i < MJHZ_MAX_CARDS; ++i) {
-			if (cd->suit == card->suit && cd->sign == card->sign) {
-				cd->suit = 0;
-				cd->sign = 0;
-				break;
-			}
-			cd++;
-		}
-	}
-	mj->last_played_mj.suit = card->suit;
-	mj->last_played_mj.sign = card->sign;
-	mj->last_played_no = player_no;
-	mj_trim(mj->players[player_no].cards, MJHZ_MAX_CARDS);
-	/* 判定吃碰杠胡 */
-	for (i = 0; i < mj->player_num; ++i) {
-		if (i != player_no) {
-			mj->players[i].can_hu = mjhz_can_hu(mj, i);
-			mj->players[i].can_gang = mjhz_can_gang(mj, i);
-			mj->players[i].can_peng = mjhz_can_peng(mj, i);
-			mj->players[i].can_chi = mjhz_can_chi(mj, i);
-		} else {
-			mj->players[i].can_hu = 0;
-			mj->players[i].can_gang = 0;
-			mj->players[i].can_peng = 0;
-			mj->players[i].can_chi = 0;
-		}
-	}
-
-	/* 无人吃碰胡则摸牌 */
-	flag = 0;
-	for (i = 0; i < mj->player_num; ++i) {
-		if (mj->players[i].can_hu ||
-				mj->players[i].can_gang ||
-				mj->players[i].can_peng ||
-				mj->players[i].can_chi) {
-			flag = 1;
-			break;
-		}
-	}
-	if (!flag) {
-		mjhz_next_player(mj);
-		mjhz_draw(mj, 0);
-	}
+        cd = mj->players[player_no].cards;
+        for (i = 0; i < MJHZ_MAX_CARDS; ++i) {
+            if (cd->suit == card->suit && cd->sign == card->sign) {
+                cd->suit = 0;
+                cd->sign = 0;
+                break;
+            }
+            cd++;
+        }
+    }
+    mj->last_played_mj.suit = card->suit;
+    mj->last_played_mj.sign = card->sign;
+    mj->last_played_no = player_no;
+    mj_trim(mj->players[player_no].cards, MJHZ_MAX_CARDS);
+    /* 判定吃碰杠胡 */
+    for (i = 0; i < mj->player_num; ++i) {
+        if (i != player_no) {
+            mj->players[i].can_hu = mjhz_can_hu(mj, i);
+            mj->players[i].can_gang = mjhz_can_gang(mj, i);
+            mj->players[i].can_peng = mjhz_can_peng(mj, i);
+            mj->players[i].can_chi = mjhz_can_chi(mj, i);
+        } else {
+            mj->players[i].can_hu = 0;
+            mj->players[i].can_gang = 0;
+            mj->players[i].can_peng = 0;
+            mj->players[i].can_chi = 0;
+        }
+    }
+
+    /* 无人吃碰胡则摸牌 */
+    flag = 0;
+    for (i = 0; i < mj->player_num; ++i) {
+        if (mj->players[i].can_hu ||
+                mj->players[i].can_gang ||
+                mj->players[i].can_peng ||
+                mj->players[i].can_chi) {
+            flag = 1;
+            break;
+        }
+    }
+    if (!flag) {
+        mjhz_next_player(mj);
+        mjhz_draw(mj, 0);
+    }

     return 1;
 }
@@ -312,98 +312,98 @@
  */
 int mjhz_can_chi(mjhz_t* mj, int player_no)
 {
-	int i,chi_info;
-	int num[10];
-	mjpai_t* p;
-	int pos1,pos2,pos3;
-
-	if (!mj)
-		return 0;
-	if (player_no >= mj->player_num)
-		return 0;
-	if (mj->curr_player_no == player_no)
-		return 0;
-	/* 只能吃万、索、筒子 */
-	if (mj->last_played_mj.suit == mj->joker.suit &&
-			mj->last_played_mj.sign == mj->joker.sign) {
-		return 0;
-	}
-	if (mj->last_played_mj.suit != mjSuitWan ||
-			mj->last_played_mj.suit != mjSuitSuo ||
-			mj->last_played_mj.suit != mjSuitTong) {
-		return 0;
-	}
-
-	/* 同类型序数牌计数 */
-	memset((void*)num, 0, sizeof(int) * 9);
-	p = mj->players[player_no].cards;
-	for (i = 0; i < MJHZ_MAX_CARDS; ++i) {
-		if (p->suit == mj->last_played_mj.suit) {
-			num[p->sign]++;
-		}
-		p++;
-	}
-	chi_info = 0;
-
-	for (i = 1; i <= 9; ++i) {
-		if ( i != mj->last_played_mj.sign)
-			continue;
-		pos1 = pos2 = pos3 = 0;
-		if (i == 1) {
-			pos1 = 1;
-		} else if (i == 2) {
-			pos1 = pos2 = 1;
-		} else if (i == 8) {
-			pos2 = pos3 = 1;
-		} else if (i == 9) {
-			pos3 = 1;
-		} else {
-			pos1 = pos2 = pos3 = 1;
-		}
-		if (pos1) {
-			if (num[i+1] > 0 && num[i+2] > 0)
-				chi_info &= 0x01;
-		}
-		if (pos2) {
-			if (num[i-1] > 0 && num[i+1] > 0)
-				chi_info &= 0x02;
-		}
-		if (pos3) {
-			if (num[i-1] > 0 && num[i-2] > 0)
-				chi_info &= 0x04;
-		}
-	}
-
+    int i,chi_info;
+    int num[10];
+    mjpai_t* p;
+    int pos1,pos2,pos3;
+
+    if (!mj)
+        return 0;
+    if (player_no >= mj->player_num)
+        return 0;
+    if (mj->curr_player_no == player_no)
+        return 0;
+    /* 只能吃万、索、筒子 */
+    if (mj->last_played_mj.suit == mj->joker.suit &&
+            mj->last_played_mj.sign == mj->joker.sign) {
+        return 0;
+    }
+    if (mj->last_played_mj.suit != mjSuitWan ||
+            mj->last_played_mj.suit != mjSuitSuo ||
+            mj->last_played_mj.suit != mjSuitTong) {
+        return 0;
+    }
+
+    /* 同类型序数牌计数 */
+    memset((void*)num, 0, sizeof(int) * 9);
+    p = mj->players[player_no].cards;
+    for (i = 0; i < MJHZ_MAX_CARDS; ++i) {
+        if (p->suit == mj->last_played_mj.suit) {
+            num[p->sign]++;
+        }
+        p++;
+    }
+    chi_info = 0;
+
+    for (i = 1; i <= 9; ++i) {
+        if ( i != mj->last_played_mj.sign)
+            continue;
+        pos1 = pos2 = pos3 = 0;
+        if (i == 1) {
+            pos1 = 1;
+        } else if (i == 2) {
+            pos1 = pos2 = 1;
+        } else if (i == 8) {
+            pos2 = pos3 = 1;
+        } else if (i == 9) {
+            pos3 = 1;
+        } else {
+            pos1 = pos2 = pos3 = 1;
+        }
+        if (pos1) {
+            if (num[i+1] > 0 && num[i+2] > 0)
+                chi_info &= 0x01;
+        }
+        if (pos2) {
+            if (num[i-1] > 0 && num[i+1] > 0)
+                chi_info &= 0x02;
+        }
+        if (pos3) {
+            if (num[i-1] > 0 && num[i-2] > 0)
+                chi_info &= 0x04;
+        }
+    }
+
     return chi_info;
 }

 int mjhz_can_peng(mjhz_t* mj, int player_no)
 {
     int i;
-	int num;
-	mjpai_t* p;
-
-	if (!mj)
-		return 0;
-	if (player_no >= mj->player_num)
-		return 0;
-	if (mj->curr_player_no == player_no)
-		return 0;
-	if (mj->last_played_mj.suit == mj->joker.suit &&
-			mj->last_played_mj.sign == mj->joker.sign) {
-		return 0;
-	}
-
-	num = 0;
-	p = mj->players[player_no].cards;
-	for (i = 0; i < MJHZ_MAX_CARDS; ++i) {
-		if (p->suit == mj->last_played_mj.suit &&
+    int num;
+    mjpai_t* p;
+
+    if (!mj)
+        return 0;
+    if (player_no >= mj->player_num)
+        return 0;
+    if (mj->curr_player_no == player_no)
+        return 0;
+    if (mj->last_played_mj.suit == mj->joker.suit &&
+            mj->last_played_mj.sign == mj->joker.sign) {
+        return 0;
+    }
+
+    num = 0;
+    p = mj->players[player_no].cards;
+    for (i = 0; i < MJHZ_MAX_CARDS; ++i) {
+        if (p->suit == mj->last_played_mj.suit &&
                 p->sign == mj->last_played_mj.sign) {
-			num++;
-		}
-		p++;
-	}
-	if (num >= 2)
+            num++;
+        }
+        p++;
+    }
+    if (num >= 2)
         return 1;
     else
         return 0;
@@ -415,14 +415,14 @@
     int i,j,num,x;
     int mask;
     int js[MJHZ_LEN_JS];
-	mjpai_t* p;
-
-	if (!mj)
-		return 0;
-	if (player_no >= mj->player_num)
-		return 0;
-	if (mj->curr_player_no == player_no)
-		return 0;
+    mjpai_t* p;
+
+    if (!mj)
+        return 0;
+    if (player_no >= mj->player_num)
+        return 0;
+    if (mj->curr_player_no == player_no)
+        return 0;

     if (mj->last_played_mj.suit > 0 &&
             mj->last_played_mj.sign > 0) {
@@ -493,22 +493,22 @@
 int mjhz_can_hu(mjhz_t* mj, int player_no)
 {
     int i,x,n;
-	int n_joker,left_joker;
-	int js[MJHZ_LEN_JS];
-	int js_joker[MJHZ_LEN_JS];
-	mjpai_t* p;
-
-	if (!mj)
-		return 0;
-	if (player_no >= mj->player_num)
-		return 0;
-	if (mj->last_played_mj.suit == mj->joker.suit &&
-			mj->last_played_mj.sign == mj->joker.sign) {
-		return 0;
-	}
-
-	n = 0;
-	n_joker = 0;
+    int n_joker,left_joker;
+    int js[MJHZ_LEN_JS];
+    int js_joker[MJHZ_LEN_JS];
+    mjpai_t* p;
+
+    if (!mj)
+        return 0;
+    if (player_no >= mj->player_num)
+        return 0;
+    if (mj->last_played_mj.suit == mj->joker.suit &&
+            mj->last_played_mj.sign == mj->joker.sign) {
+        return 0;
+    }
+
+    n = 0;
+    n_joker = 0;
     memset(js, 0, sizeof(int) * MJHZ_LEN_JS);
     p = mj->players[player_no].cards;
     for (i = 0; i < MJHZ_MAX_CARDS; ++i,p++) {
@@ -516,69 +516,69 @@
             continue;
         x = mjpai_encode(p);
         if (x >= MJHZ_LEN_JS) continue;
-		if (x == MJHZ_ID_BAI) {
-			n_joker++;
-			continue;
-		}
+        if (x == MJHZ_ID_BAI) {
+            n_joker++;
+            continue;
+        }
         js[x]++;
-		n++;
-	}
-	if (mj->curr_player_no != player_no) {
-		x = mjpai_encode(&mj->last_played_mj);
-		if (x < MJHZ_LEN_JS)
-			js[x]++;
-	}
-
-	/* 是否七对子 */
-	memcpy(js_joker, js, sizeof(int) * MJHZ_LEN_JS);
-	if (n_joker > 0) {
-		/* 财神处理 */
-		left_joker = n_joker;
-		for (i = 0; i < MJHZ_LEN_JS; ++i) {
-			if (js_joker[i] == 0) continue;
-			if ((js_joker[i] % 2) > 0) {
-				js_joker[i]++;
-				left_joker--;
-				if (left_joker == 0)
-					break;
-			}
-		}
-		if (left_joker > 0) {
-			js_joker[MJHZ_ID_BAI] += left_joker;
-		}
-	}
-	if (mj_pair7(js_joker, MJHZ_LEN_JS)) {
-		/* 是7对子得到豪华数量 */
-		mj->players[player_no].hu.isPair7 = 1;
-		mj->players[player_no].hu.pair7H4 = 0;
-		for (i = 0; i < MJHZ_LEN_JS; ++i) {
-			if (js_joker[i] == 4)
-				mj->players[player_no].hu.pair7H4++;
-		}
-		return 1;
-	}
-
+        n++;
+    }
+    if (mj->curr_player_no != player_no) {
+        x = mjpai_encode(&mj->last_played_mj);
+        if (x < MJHZ_LEN_JS)
+            js[x]++;
+    }
+
+    /* 是否七对子 */
+    memcpy(js_joker, js, sizeof(int) * MJHZ_LEN_JS);
+    if (n_joker > 0) {
+        /* 财神处理 */
+        left_joker = n_joker;
+        for (i = 0; i < MJHZ_LEN_JS; ++i) {
+            if (js_joker[i] == 0) continue;
+            if ((js_joker[i] % 2) > 0) {
+                js_joker[i]++;
+                left_joker--;
+                if (left_joker == 0)
+                    break;
+            }
+        }
+        if (left_joker > 0) {
+            js_joker[MJHZ_ID_BAI] += left_joker;
+        }
+    }
+    if (mj_pair7(js_joker, MJHZ_LEN_JS)) {
+        /* 是7对子得到豪华数量 */
+        mj->players[player_no].hu.isPair7 = 1;
+        mj->players[player_no].hu.pair7H4 = 0;
+        for (i = 0; i < MJHZ_LEN_JS; ++i) {
+            if (js_joker[i] == 4)
+                mj->players[player_no].hu.pair7H4++;
+        }
+        return 1;
+    }
+
     return 0;
 }

 int mjhz_chi(mjhz_t* mj, int player_no)
 {
-	return 0;
+    return 0;
 }

 int mjhz_peng(mjhz_t* mj, int player_no)
 {
-	return 0;
+    return 0;
 }

 int mjhz_gang(mjhz_t* mj, int player_no)
 {
-	return 0;
+    return 0;
 }

 int mjhz_hu(mjhz_t* mj, int player_no)
 {
-	return 0;
+    return 0;
 }

 /* 逆时针*/
@@ -597,20 +597,20 @@
         return;

     printf("player number:%d\n", mj->player_num);
-	printf("mamon:\n");
-	printf("%s\n", mjpai_string(&mj->joker));
+    printf("mamon:\n");
+    printf("%s\n", mjpai_string(&mj->joker));

     /* dump player's mj pai */
     printf("players mj cards:\n");
     printf("%s\n",
-		mj_string(mj->players[0].cards, MJHZ_MAX_CARDS, 10));
-	printf("%s\n",
-		mj_string(mj->players[1].cards, MJHZ_MAX_CARDS, 10));
+            mj_string(mj->players[0].cards, MJHZ_MAX_CARDS, 10));
+    printf("%s\n",
+            mj_string(mj->players[1].cards, MJHZ_MAX_CARDS, 10));
     if (mj->player_num > 2) {
-		printf("%s\n",
-			mj_string(mj->players[2].cards, MJHZ_MAX_CARDS, 10));
-		printf("%s\n",
-			mj_string(mj->players[3].cards, MJHZ_MAX_CARDS, 10));
+        printf("%s\n",
+                mj_string(mj->players[2].cards, MJHZ_MAX_CARDS, 10));
+        printf("%s\n",
+                mj_string(mj->players[3].cards, MJHZ_MAX_CARDS, 10));
     }

     printf("last mj pai:\n");


it works! remove test version.h

it works! remove test version.h

--- source/version.h
+++ source/version.h
@@ -1 +0,0 @@
-This file was made just to test the webhook! Now I need to modify it!


Fixed a typo

Fixed a typo

--- src/move.c
+++ src/move.c
@@ -238,7 +238,7 @@
             }
          }

-         if (flags == MAX_NONE)
+         if(flags != MAX_NONE)
             doMove = 0;
          else if(!doMove && (abs(np->x - oldx) > MOVE_DELTA
             || abs(np->y - oldy) > MOVE_DELTA)) {


Implement moving workspace into sibling.

--- src/move.c
+++ src/move.c
@@ -194,11 +194,6 @@

     Con * const big = ascend_mono_splits(focused);

-    if (big->type == CT_WORKSPACE) {
-        DLOG("Sorry, not implemented yet: moving workspace into siblings\n");
-        return;
-    }
-
     /* Enforce the fullscreen focus restrictions. */
     if (!con_fullscreen_permits_focusing(big->parent)) {
         LOG("Cannot move out of fullscreen container\n");
@@ -219,6 +214,12 @@

     Con * const small = descend_mono_splits(focused);
         // we don't want to take mono splits with us
+
+    if (big->type == CT_WORKSPACE) {
+        con_move_to_workspace(small, next, true, false);
+        workspace_show(next);
+        return;
+    }

     push_con_back(small, next);


Changed display of step percentage

Changed display of step percentage

--- src/nixi.c
+++ src/nixi.c
@@ -81,7 +81,7 @@

   if(mask & HealthServiceAccessibilityMaskAvailable) {
     s_steps_level = (int)health_service_sum_today(metric);
-    snprintf(steps_buffer, sizeof(steps_buffer), "%d - %d%%", s_steps_level, (int)(100.0f*s_steps_level/s_steps_average));
+    snprintf(steps_buffer, sizeof(steps_buffer), "%d [%d%%]", s_steps_level, (int)(100.0f*s_steps_level/s_steps_average));
   } else {
     snprintf(steps_buffer, sizeof(steps_buffer), "steps: N/A");
   }


document return code

document return code

--- src/node.c
+++ src/node.c
@@ -166,6 +166,8 @@
 /**
  * This function combines ['/foo', '/bar', '/{slug}'] into (/foo)|(/bar)|/([^/]+)}
  *
+ * Return -1 if error occurs
+ * Return 0 if success
  */
 int r3_tree_compile_patterns(node * n, char **errstr) {
     char * cpat;


Remove debug messages.

Remove debug messages.

--- src/node.c
+++ src/node.c
@@ -153,28 +153,24 @@

 node_t *new_node(node_type_t type) {
 	node_t *node = tmalloc(sizeof(node_t));
-	printf("+ new node\n");
 	node->type = type;
 	return (node);
 }

 node_instruction_t *new_node_instruction() {
 	node_instruction_t *node = tmalloc(sizeof(node_instruction_t));
-	printf("+ new instruction\n");
 	((node_t*)node)->type = N_INSTRUCTION;
 	return (node);
 }

 node_expression_t *new_node_expression() {
 	node_expression_t *node = tmalloc(sizeof(node_expression_t));
-	printf("+ new expression\n");
 	((node_t*)node)->type = N_EXPRESSION;
 	return (node);
 }

 node_identifier_t *new_node_identifier(char *name) {
 	node_identifier_t *node = tmalloc(sizeof(node_identifier_t));
-	printf("+ new identifier (%s)\n", name);
 	((node_t*)node)->type = N_IDENTIFIER;
 	node->name = name;
 	return (node);
@@ -182,7 +178,6 @@

 node_assignment_t *new_node_assignment(node_identifier_t *identifier, node_expression_t *expression) {
 	node_assignment_t *node = tmalloc(sizeof(node_assignment_t));
-	printf("+ new assignment\n");
 	((node_t*)node)->type = N_ASSIGNMENT;
 	node->identifier = identifier;
 	node->expression = expression;
@@ -191,7 +186,6 @@

 node_operation_t *new_node_operation(node_expression_t *op1, char operator, node_expression_t *op2) {
 	node_operation_t *node = tmalloc(sizeof(node_operation_t));
-	printf("+ new operation\n");
 	((node_t*)node)->type = N_OPERATION;
 	node->op1 = op1;
 	node->operator = operator;
@@ -201,7 +195,6 @@

 node_comparison_t *new_node_comparison(node_expression_t *op1, char bool_operator, node_expression_t *op2) {
 	node_comparison_t *node = tmalloc(sizeof(node_comparison_t));
-	printf(" + new comparison\n");
 	((node_t*)node)->type = N_COMPARISON;
 	node->op1 = op1;
 	node->bool_operator = bool_operator;
@@ -211,7 +204,6 @@

 node_condition_t *new_node_condition(node_expression_t *condition_expression, stack_t *true_instructions, stack_t *false_instructions) {
 	node_condition_t *node = tmalloc(sizeof(node_condition_t));
-	printf("+ new condition\n");
 	((node_t*)node)->type = N_CONDITION;
 	node->condition_expression = condition_expression;
 	node->true_instructions = true_instructions;
@@ -221,7 +213,6 @@

 node_while_t *new_node_while(node_expression_t *loop_expression, stack_t *instructions) {
 	node_while_t *node = tmalloc(sizeof(node_while_t));
-	printf("+ new while\n");
 	((node_t*)node)->type = N_WHILE;
 	node->loop_expression = loop_expression;
 	node->instructions = instructions;
@@ -230,7 +221,6 @@

 node_funccall_t *new_node_funccall(node_identifier_t *identifier, stack_t *parameters) {
 	node_funccall_t *node = tmalloc(sizeof(node_funccall_t));
-	printf("+ new funccall\n");
 	((node_t*)node)->type = N_FUNC_CALL;
 	node->identifier = identifier;
 	node->parameters = parameters;
@@ -239,7 +229,6 @@

 node_methcall_t *new_node_methcall(node_identifier_t *objname, node_identifier_t *methname, stack_t *parameters) {
 	node_methcall_t *node = tmalloc(sizeof(node_methcall_t));
-	printf("+ new methcall\n");
 	((node_t*)node)->type = N_METH_CALL;
 	node->objname = objname;
 	node->methname = methname;
@@ -249,7 +238,6 @@

 node_funcdef_t *new_node_funcdef(stack_t *parameters, stack_t *instructions) {
 	node_funcdef_t *node = tmalloc(sizeof(node_funcdef_t));
-	printf("+ new funcdef\n");
 	((node_t*)node)->type = N_FUNC_DEF;
 	node->parameters = parameters;
 	node->instructions = instructions;
@@ -258,7 +246,6 @@

 node_class_t *new_node_class(stack_t *instructions) {
 	node_class_t *node = tmalloc(sizeof(node_class_t));
-	printf("+ new class\n");
 	((node_t*)node)->type = N_CLASS;
 	node->instructions = instructions;
 	return (node);
@@ -266,7 +253,6 @@

 node_return_t *new_node_return(node_expression_t *value) {
 	node_return_t *node = tmalloc(sizeof(node_return_t));
-	printf("+ new return\n");
 	((node_t*)node)->type = N_RETURN;
 	node->value = value;
 	return (node);
@@ -274,21 +260,18 @@

 node_break_t *new_node_break() {
 	node_break_t *node = tmalloc(sizeof(node_return_t));
-	printf("+ new break\n");
 	((node_t*)node)->type = N_BREAK;
 	return (node);
 }

 node_continue_t *new_node_continue() {
 	node_continue_t *node = tmalloc(sizeof(node_continue_t));
-	printf("+ new continue\n");
 	((node_t*)node)->type = N_CONTINUE;
 	return (node);
 }

 node_scalar_t *new_node_string(char *str) {
 	node_scalar_t *node = tmalloc(sizeof(node_scalar_t));
-	printf("+ new string (%s)\n", str);
 	((node_t*)node)->type = N_STRING;
 	node->value.str = str;
 	return (node);
@@ -296,7 +279,6 @@

 node_scalar_t *new_node_boolean(bool boolean) {
 	node_scalar_t *node = tmalloc(sizeof(node_scalar_t));
-	printf("+ new boolean (%s)\n", boolean ? "true" : "false");
 	((node_t*)node)->type = N_BOOLEAN;
 	node->value.boolean = boolean;
 	return (node);
@@ -304,7 +286,6 @@

 node_scalar_t *new_node_number(long double number) {
 	node_scalar_t *node = tmalloc(sizeof(node_scalar_t));
-	printf("+ new number (%Lf)\n", number);
 	((node_t*)node)->type = N_NUMBER;
 	node->value.number = number;
 	return (node);


Nodes: check pointer is valid (is_equal, is_local, is_leader, is_active)

--- src/node.h
+++ src/node.h
@@ -172,19 +172,19 @@
 	}

 	static bool is_equal(const std::shared_ptr<const Node>& a, const std::shared_ptr<const Node>& b) {
-		return (a == b || *a == *b);
+		return a && b && (a == b || *a == *b);
 	}

 	static bool is_local(const std::shared_ptr<const Node>& node) {
-		return is_equal(_local_node.load(), node);
+		return node && is_equal(_local_node.load(), node);
 	}

 	static bool is_leader(const std::shared_ptr<const Node>& node) {
-		return is_equal(_leader_node.load(), node);
+		return node && is_equal(_leader_node.load(), node);
 	}

 	static bool is_active(const std::shared_ptr<const Node>& node) {
-		return node->touched >= epoch::now<>() - NODE_LIFESPAN || is_local(node);
+		return node && (node->touched >= epoch::now<>() - NODE_LIFESPAN || is_local(node));
 	}

 	static std::shared_ptr<const Node> local_node(std::shared_ptr<const Node> node = nullptr);


Minor hack of the new clipping logic, allowing the right edge of the clipping rectangle to be padded 2 pixels to the left to ensure that truncated lyrics don't appear to bleed into each other.  Updated logic to add more whitespace pixels in front of and after the moused-over lyric would still be good.

--- src/note.c
+++ src/note.c
@@ -514,7 +514,7 @@

 //Rewritten logic checks the next lyric to set an appropriate clipping rectangle for truncation purposes
-	set_clip_rect(eof_window_editor->screen, 0, EOF_EDITOR_RENDER_OFFSET + 15 + eof_screen_layout.lyric_y + 1, X2, eof_window_editor->screen->h);
+	set_clip_rect(eof_window_editor->screen, 0, EOF_EDITOR_RENDER_OFFSET + 15 + eof_screen_layout.lyric_y + 1, X2-2, eof_window_editor->screen->h);	//Alteration: Provide at least two pixels of clearance for the edge of the clip rectangle

 	if(p == 3)
 		textprintf_ex(eof_window_editor->screen, font, npos, EOF_EDITOR_RENDER_OFFSET + 15 + eof_screen_layout.lyric_y, eof_color_white, eof_color_black, "%s", np->text);


show raw tx data for non-ringct transactions added

--- src/page.h
+++ src/page.h
@@ -1643,9 +1643,6 @@
                                 = boost::find_nth(timescale, "*", point_to_find);

                         *(r.begin()) = 'R';
-                       //timescale.insert(*(r.begin()), "<span>*</span>");
-
-                        cout << timescale << endl;

                         ++idx;
                     }


Fix some more bugs in fastd_peer_claim_address

--- src/peer.c
+++ src/peer.c
@@ -326,22 +326,25 @@
 	else {
 		fastd_peer *peer;
 		for (peer = ctx->peers; peer; peer = peer->next) {
-			if (fastd_peer_address_equal(&peer->address, addr)) {
-				if (peer == new_peer)
-					break;
-
-				if (fastd_peer_is_floating(peer) || fastd_peer_is_dynamic(peer)) {
-					if (fastd_peer_is_established(peer))
-						fastd_peer_reset(ctx, peer);
-
-					memset(&peer->address, 0, sizeof(fastd_peer_address));
-					break;
-				}
-				else {
-					memset(&new_peer->address, 0, sizeof(fastd_peer_address));
-					return false;
-				}
+			if (!fastd_peer_address_equal(&peer->address, addr))
+				continue;
+
+			if (peer == new_peer)
+				break;
+
+			if (!fastd_peer_is_floating(peer)) {
+				if (fastd_peer_is_established(new_peer))
+					fastd_peer_reset(ctx, new_peer);
+
+				memset(&new_peer->address, 0, sizeof(fastd_peer_address));
+				return false;
 			}
+
+			if (fastd_peer_is_established(peer))
+				fastd_peer_reset(ctx, peer);
+
+			memset(&peer->address, 0, sizeof(fastd_peer_address));
+			break;
 		}
 	}


Make new_pipe ipc argument default to false

--- src/pipe.c
+++ src/pipe.c
@@ -26,8 +26,11 @@
   uv_pipe_t* handle;
   int ipc, ret;
   luv_ctx_t* ctx = luv_context(L);
-  luaL_checktype(L, 1, LUA_TBOOLEAN);
-  ipc = lua_toboolean(L, 1);
+  if (lua_isboolean(L, 1)) {
+    ipc = lua_toboolean(L, 1);
+  } else {
+    luaL_argcheck(L, lua_isnoneornil(L, 1), 1, "Expected boolean or nil");
+  }
   handle = (uv_pipe_t*)luv_newuserdata(L, sizeof(*handle));
   ret = uv_pipe_init(ctx->loop, handle, ipc);
   if (ret < 0) {


Add missing patomic.h to plib.h

Add missing patomic.h to plib.h

--- src/plib.h
+++ src/plib.h
@@ -23,6 +23,7 @@
 #define __PLIB_H_INSIDE__

 #include "plibconfig.h"
+#include "patomic.h"
 #include "pfile.h"
 #include "pgost3411.h"
 #include "phashtable.h"


POLY: rm unnecessary cast

POLY: rm unnecessary cast

--- src/poly.c
+++ src/poly.c
@@ -169,8 +169,8 @@
 		for (int i = ctx->N - 1; i >= 0; i--) {
 			if (j == (int)(ctx->N))
 				j = 0;
-			if (mp_cmp_d(&(a->terms[i]), (mp_digit)0) != MP_EQ &&
-					mp_cmp_d(&(b->terms[j]), (mp_digit)0) != MP_EQ) {
+			if (mp_cmp_d(&(a->terms[i]), 0) != MP_EQ &&
+					mp_cmp_d(&(b->terms[j]), 0) != MP_EQ) {
 				int result;
 				mp_int mp_modulus;
 				mp_int mp_tmp;


Added pool freelist struct for readability

This adds a git_pool_freelist_item struct that makes it a little
easier to follow what's going on with the pool free list block
management code.  It is functionally neutral.

--- src/pool.c
+++ src/pool.c
@@ -8,6 +8,11 @@
 	uint32_t size;
 	uint32_t avail;
 	char data[GIT_FLEX_ARRAY];
+};
+
+typedef struct git_pool_freelist_item git_pool_freelist_item;
+struct git_pool_freelist_item {
+	git_pool_freelist_item *next;
 };

 #define GIT_POOL_MIN_USABLE	4
@@ -150,7 +155,7 @@
 		pool->has_multi_item_alloc = 1;
 	else if (pool->free_list != NULL) {
 		ptr = pool->free_list;
-		pool->free_list = *((void **)pool->free_list);
+		pool->free_list = ((git_pool_freelist_item *)pool->free_list)->next;
 		return ptr;
 	}

@@ -235,16 +240,19 @@

 void git_pool_free(git_pool *pool, void *ptr)
 {
+	git_pool_freelist_item *item = ptr;
+
 	assert(pool && pool->item_size >= sizeof(void*));

-	if (ptr) {
-		*((void **)ptr) = pool->free_list;
-		pool->free_list = ptr;
+	if (item) {
+		item->next = pool->free_list;
+		pool->free_list = item;
 	}
 }

 void git_pool_free_array(git_pool *pool, size_t count, void **ptrs)
 {
+	git_pool_freelist_item **items = (git_pool_freelist_item **)ptrs;
 	size_t i;

 	assert(pool && ptrs && pool->item_size >= sizeof(void*));
@@ -253,10 +261,10 @@
 		return;

 	for (i = count - 1; i > 0; --i)
-		*((void **)ptrs[i]) = ptrs[i - 1];
-
-	*((void **)ptrs[0]) = pool->free_list;
-	pool->free_list = ptrs[count - 1];
+		items[i]->next = items[i - 1];
+
+	items[i]->next  = pool->free_list;
+	pool->free_list = items[count - 1];
 }

 uint32_t git_pool__open_pages(git_pool *pool)


advanced support for the valgrid memchecker

--- src/pool.c
+++ src/pool.c
@@ -7,6 +7,10 @@
 #include "pool.h"
 #include "list.h"
 #include "compiler.h"
+
+#ifdef VALGRIND
+#include <valgrind/memcheck.h>
+#endif

 #include <assert.h>
 #include <stdlib.h>
@@ -114,10 +118,18 @@

     if (recycler.num_linear_areas < RECYCLER_MAX_LINEAR_AREAS &&
         area->size <= RECYCLER_MAX_LINEAR_SIZE) {
+#ifdef VALGRIND
+        VALGRIND_MAKE_MEM_NOACCESS(area->data, area->size);
+#endif
+
         area->prev = recycler.linear_areas;
         recycler.linear_areas = area;
         ++recycler.num_linear_areas;
     } else {
+#ifdef VALGRIND
+        VALGRIND_MAKE_MEM_UNDEFINED(area, sizeof(*area) - sizeof(area->data) + area->size);
+#endif
+
         free(area);
     }
 }
@@ -206,6 +218,11 @@
     area->prev = prev;
     area->size = size;
     area->used = 0;
+
+#ifdef VALGRIND
+    VALGRIND_MAKE_MEM_NOACCESS(area->data, area->size);
+#endif
+
     return area;
 }

@@ -345,6 +362,10 @@

     p = area->data + area->used;
     area->used += size;
+
+#ifdef VALGRIND
+    VALGRIND_MAKE_MEM_UNDEFINED(p, size);
+#endif

     return p;
 }


remove reset_color_pairs call, there are some compatibility issues

--- src/pspg.c
+++ src/pspg.c
@@ -6726,12 +6726,6 @@

 #endif

-#if NCURSES_EXT_FUNCS
-
-	reset_color_pairs();
-
-#endif
-
 	/* try to reinit original color palette */
 	start_color();


SF BUG 1269290 fix: Removed code that incorrectly attempted to mark the SRK loaded.  It was all redundant except adding the key handle to the list, which is now done in the TakeOwnership code.

--- src/tspi/obj_rsakey.c
+++ src/tspi/obj_rsakey.c
@@ -108,18 +108,6 @@
 		rsaKeyParms.keyLength = 8192;
 	} else if ((initFlags & TSS_KEY_SIZE_MASK) == TSS_KEY_SIZE_16384) {
 		rsaKeyParms.keyLength = 16384;
-	}
-
-	if (initFlags & TSS_KEY_TSP_SRK) {
-		if ((result = addKeyHandle(TPM_KEYHND_SRK, *phObject))) {
-			obj_policy_remove(rsakey->usagePolicy, tspContext);
-			obj_policy_remove(rsakey->migPolicy, tspContext);
-			free(rsakey);
-			return result;
-		}
-		rsakey->privateKey.Privlen = 0;
-		rsakey->tcpaKey.PCRInfoSize = 0;
-		rsaKeyParms.keyLength = 2048;
 	}

 	/* assign encryption and signature schemes */
@@ -832,6 +820,19 @@

 	offset = rsakey->tcpaKey.pubKey.keyLength;

+	/* if this key object represents the SRK and the public key
+	 * data here is all 0's, then we shouldn't return it, we
+	 * should return TSS_E_BAD_PARAMETER. This is part of protecting
+	 * the SRK public key. */
+	if (getTCSKeyHandle(hKey) == TPM_KEYHND_SRK) {
+		BYTE zeroBlob[2048] = { 0, };
+
+		if (!memcmp(rsakey->tcpaKey.pubKey.key, zeroBlob, offset)) {
+			result = TSS_E_BAD_PARAMETER;
+			goto done;
+		}
+	}
+
 	*data = calloc_tspi(obj->tspContext, offset);
 	if (*data == NULL) {
 		LogError("malloc of %d bytes failed.", offset);


Fix 'is applied' check when asking about current node.

--- src/raft.c
+++ src/raft.c
@@ -318,6 +318,7 @@
 	raft_log_t *l = &raft->log;
 	while (l->applied < l->acked) {
 		raft_entry_t *e = &RAFT_LOG(raft, l->applied);
+		assert(e->update.len == e->bytes);
 		raft->config.applier(raft->config.userdata, e->update, false);
 		raft->log.applied++;
 		applied_now++;
@@ -661,6 +662,7 @@
 	assert(e->update.len == 0);
 	assert(e->update.data == NULL);
 	e->update.len = update.len;
+	e->bytes = update.len;
 	e->update.data = malloc(update.len);
 	memcpy(e->update.data, update.data, update.len);
 	r->log.size++;
@@ -671,9 +673,16 @@
 }

 bool raft_applied(raft_t r, int id, int index) {
-	raft_peer_t *p = r->peers + id;
-	if (!p->up) return false;
-	return p->applied >= index;
+	if (r->me == id)
+	{
+		return r->log.applied >= index;
+	}
+	else
+	{
+		raft_peer_t *p = r->peers + id;
+		if (!p->up) return false;
+		return p->applied >= index;
+	}
 }

 static bool raft_restore(raft_t r, int previndex, raft_entry_t *e) {


read +INF.0, +InF.0, +Nan.0, ...

read +INF.0, +InF.0, +Nan.0, ...

--- src/read.c
+++ src/read.c
@@ -69,6 +69,18 @@
   return c == EOF || strchr("();,|\" \t\n\r", c) != NULL; /* ignores "#", "'" */
 }

+static bool
+strcaseeq(const char *s1, const char *s2)
+{
+  char a, b;
+
+  while ((a = *s1++) * (b = *s2++)) {
+    if (tolower(a) != tolower(b))
+      return false;
+  }
+  return a == b;
+}
+
 static pic_value
 read_comment(pic_state *pic, struct pic_port *port, char c)
 {
@@ -262,10 +274,10 @@
   }
   else {
     sym = read_symbol(pic, port, c);
-    if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "-inf.0")))) {
+    if (strcaseeq(pic_symbol_name(pic, pic_sym(sym)), "-inf.0")) {
       return pic_float_value(-INFINITY);
     }
-    if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "-nan.0")))) {
+    if (strcaseeq(pic_symbol_name(pic, pic_sym(sym)), "-nan.0")) {
       return pic_float_value(-NAN);
     }
     return sym;
@@ -282,10 +294,10 @@
   }
   else {
     sym = read_symbol(pic, port, c);
-    if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "+inf.0")))) {
+    if (strcaseeq(pic_symbol_name(pic, pic_sym(sym)), "+inf.0")) {
       return pic_float_value(INFINITY);
     }
-    if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "+nan.0")))) {
+    if (strcaseeq(pic_symbol_name(pic, pic_sym(sym)), "+nan.0")) {
       return pic_float_value(NAN);
     }
     return read_symbol(pic, port, c);


Added is_root reading

Added is_root reading

--- src/read.c
+++ src/read.c
@@ -233,6 +233,12 @@
 	return 0;
 }

+static uint8_t
+ctf_is_root_from_info (uint16_t info)
+{
+	return (info & 0x0400) >> 10;
+}
+
 static int
 read_types (struct ctf_file *file, struct _section *section, struct
     _strings *strings)
@@ -251,11 +257,13 @@
 		struct _ctf_small_type *small_type = section->data + offset;
 		uint8_t kind = ctf_kind_from_info(small_type->info);
 		uint16_t vardata_length = small_type->info & CTF_VARDATA_LENGTH_MAX;
+		uint8_t is_root = ctf_is_root_from_info(small_type->info);

 		struct ctf_type *type = malloc(CTF_TYPE_SIZE);
 		type->kind = kind;
 		type->id = id;

+		type->is_root = is_root;
 		id++;

 		if (ctf_kind_is_pure_reference(kind) == 1)


Constants for various ANSI colors.

Constants for various ANSI colors.

--- src/ridl.c
+++ src/ridl.c
@@ -28,6 +28,9 @@
 #include "ridl_preferences.h"
 #include "ridl_idlpreferences.h"

+#define ANSI_COLOR_YELLOW  "\e[33m"
+#define ANSI_COLOR_RED     "\e[31m"
+#define ANSI_COLOR_RESET   "\e[0m"

 /// user information with fields: logname, homedir, pid, host, wd, date
 static IDL_USER_INFO user_info;
@@ -338,9 +341,9 @@

   if (ridl_islogging()) ridl_logcmd(ridl_expandedprompt, cmd);
   if (ridl_isnotebooking()) ridl_notebookcmd(ridl_expandedprompt, cmd);
-
+
   result = IDL_ExecuteStr(cmd);
-
+
   // add line to both Readline's history and IDL's history file
   if (save) {
     ridl_addhistoryline(cmd);
@@ -351,7 +354,10 @@
   ridl_updateprompt();

   // reset colors if there was a compile error
-  if (use_colors) fprintf(stderr, "\e[0m");
+  if (use_colors) {
+    fprintf(stderr, ANSI_COLOR_RESET);
+    fflush(stderr);
+  }

   return(result);
 }
@@ -627,7 +633,10 @@
    IDL callback registered to be called before a compiler error is shown.
 */
 void ridl_show_compile_error(void) {
-  if (use_colors) fprintf(stderr, "\e[31m");  // show compiler errors in red
+  if (use_colors) {
+    fprintf(stderr, ANSI_COLOR_RED);  // show compiler errors in red
+    fflush(stderr);
+  }
 }


Track the object list tail in rndr_ysort

--- src/rndr.c
+++ src/rndr.c
@@ -332,6 +332,9 @@
 	while (list)
 	{
 		obj_t *head = list, **trail = &sorted;
+
+		if (list->next)
+			*end = list->next;

 		list = list->next;