add title level
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 19 Dec 2024 14:31:59 +0000 (15:31 +0100)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 19 Dec 2024 14:31:59 +0000 (15:31 +0100)
display.c
function.c
test.sok
type.h

index 22d857fd655f06f1b581159d43311f893731945d..75ec61fe55e0bccfee0a5fe50c11cf4d31e0350d 100644 (file)
--- a/display.c
+++ b/display.c
@@ -289,8 +289,11 @@ void boardwindow (board_t *board)
 
     set_color (white);
     _dobound (board->xsize, board->ysize, board->xoffset, board->yoffset);
+    if (board->title) {
+        _displaytitle (board->title, board->xoffset, board->yoffset - 1);
+    }
 
-   for (i = 0; i < board->width; i++) {
+    for (i = 0; i < board->width; i++) {
         for (j = 0; j < board->height; j++) {
             _element (board, i, j, getvalue (board, i, j));
         }
index c6ea897ad272512220678d037f71c8341ae8ca50..0e81095e3cf74bf2adf636dd6dafc3a75477f638 100644 (file)
@@ -33,6 +33,7 @@ board_t *initboard (int width, int height)
     board->tab = (char *) calloc (1, width * height + 1);
     CHECKALLOC (board->tab);
     memset (board->tab, ' ', width * height);
+    board->title = NULL;
     board->scale = 0;
     board->xsize = board->width = width;
     board->ysize = board->height = height;
@@ -47,6 +48,9 @@ board_t *copyboard (board_t *board)
     CHECKALLOC (board);
     memcpy (newboard, board, sizeof (board_t));
     newboard->tab = (char *) calloc (1, board->width * board->height + 1);
+    if (board->title) {
+        newboard->title = strdup (board->title);
+    }
     CHECKALLOC (newboard->tab);
     memcpy (newboard->tab, board->tab, board->width * board->height + 1);
     return newboard;
@@ -80,6 +84,7 @@ void freeboard (board_t *board)
 {
     if (board) {
         free (board->tab);
+        free (board->title);
     }
     free (board);
 }
@@ -174,6 +179,7 @@ board_t *loadboard (char *str)
     int width = 0;
     int height = 0;
     char *tab = NULL;
+    char *title = NULL;
 
     char *saveptr1, *saveptr2;
 
@@ -193,6 +199,8 @@ board_t *loadboard (char *str)
             height = atoi (value);
         } else if (strcmp (keyword,  "tab") == 0) {
             tab = atos (value);
+        } else if (strcmp (keyword,  "title") == 0) {
+            title = atos (value);
         } else if (strcmp (keyword,  "rem") == 0) {
             /* nothing to do with remark */
         } else {
@@ -206,6 +214,9 @@ board_t *loadboard (char *str)
     if ((tab) && (strlen (tab) == (size_t)(width * height))) {
         board = initboard (width, height);
         memcpy (board->tab, tab, width * height);
+        if (title) {
+            board->title = strdup (title);
+        }
     }
 
     return board;
index 1b1a4e93e0cfbbf528268a0b2bf525177384c996..3ed58da41805ed6b71c2d5a914465753cdd71c1e 100644 (file)
--- a/test.sok
+++ b/test.sok
@@ -1,3 +1,4 @@
 width: 7
 height: 5
 tab: "#####  #@  #  # #$#### $ ..########"
+title: "Tutorial"
diff --git a/type.h b/type.h
index 34ea36521c6194f96303fe65152f755cb4c37555..8014e1d7ef550749f79602c0369b729a80584dff 100644 (file)
--- a/type.h
+++ b/type.h
@@ -5,6 +5,7 @@ typedef struct {
     int width;
     int height;
     char *tab;
+    char *title;
     int scale;
     int xsize;
     int ysize;