]> Pileus Git - ~andy/ct/commitdiff
update knot other
authorAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 03:43:13 +0000 (03:43 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 03:43:13 +0000 (03:43 +0000)
knot/crown.txt [new file with mode: 0644]
knot/hitch.txt
knot/html.ct
knot/knot.c
knot/knot.h
knot/mkfile
knot/overhand.txt [new file with mode: 0644]

diff --git a/knot/crown.txt b/knot/crown.txt
new file mode 100644 (file)
index 0000000..aebd89d
--- /dev/null
@@ -0,0 +1,45 @@
+     ||
+  ...||.
+.--||--'
+'--||--.
+  ||'||--.
+  |'-||--'
+  '--'''
+
+      ||
+  ...-||.
+.--||---'
+'--||.||
+  '--|'|
+  .--|-'
+  '||'
+   ||
+   ''
+  ...--.
+.--||-.|
+'--||.||
+  '--||---
+  .--||---
+  '||'''
+   ||
+   ''
+
+     ||
+  ...||.
+.--||--'
+'--||--.
+  '--||--.
+  .--||--'
+  '||'''
+   ||
+   ''
+   ..
+   ||
+  .''--.
+  |    '-.
+  |    .-'
+.-'    |
+'-.    |
+  '--..'
+     ||
+     ||
index a131f4b3d5db6d573eb1ea61f4ed33859fad1bbb..7793dd2c9d13d184618aa208d8364e754d89a5cb 100644 (file)
@@ -1,6 +1,6 @@
- |      
+ |
 .---..--.
-'|. ||.-|-+
+'|. ||.-|-
  ||.-|-.|
 .||-||-||---
 '-|-'|'-'
index 40fbe44c88be7bad8d379559aed257b6a633caad..a80c21d450d15db9f533d28bbf0c26b5e8702066 100644 (file)
@@ -9,7 +9,7 @@
        <% } %>
 <% } %>
 
-<% void print_index(tile_t **tiles) { %>
+<% void print_index(row_t *rows) { %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
        <head>
                <style type="text/css">
-                       *   { border:0; margin:0; padding:0; }
-                       table { border-collapse:separate; margin:auto; width:1800px;}
-                       td  { width:64px; height:64px; border-spacing:0px 0px;}
+                       td  { min-width:64px; height:64px; }
                        img { position:absolute; }
                </style>
        </head>
        <body>
-       <table cellpadding="0" cellspacing="0">
-               <% for (int row = 1; row < 10; row++) { %>
-               <tr>
-                       <% for (int col = 1; col < 30; col++) { %>
-                       <td>
-                       <% print_img(tiles[row][col].bot); %>
-                       <% print_img(tiles[row][col].top); %>
-                       </td>
+               <table cellpadding="0" cellspacing="0">
+                       <% for (int row = 0; rows[row].ncols >= 0; row++) { %>
+                       <tr>
+                               <% for (int col = 0; col < rows[row].ncols; col++) { %>
+                               <td>
+                                       <% print_img(rows[row].cols[col].bot); %>
+                                       <% print_img(rows[row].cols[col].top); %>
+                               </td>
+                               <% } %>
+                       </tr>
                        <% } %>
-               </tr>
-               <% } %>
                </table>
        </body>
 </html>
index 13954d1aaf647800691c2355fe6acfb776dada24..a859babf35560df6c537d76f34faa76c81ddd12d 100644 (file)
@@ -1,18 +1,15 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "knot.h"
 
-static void do_tile(tile_t **tiles, int row, int col)
+static void do_tile(row_t *rows, int row, int col)
 {
-       tile_t *t = &tiles[row][col];
-       tile_t *l = &tiles[row][col-1];
-       tile_t *r = &tiles[row][col+1];
-       tile_t *u = &tiles[row-1][col];
-       //tile_t *d = &tiles[row+1][col];
+       tile_t *t = &rows[row].cols[col];
 
        /* Fill in what we know */
-       switch (tiles[row][col].c) {
+       switch (t->c) {
        case '-':  t->top = LEFT | RIGHT; break;
        case '|':  t->top = UP | DOWN;    break;
        case '\'': t->top = UP;           break;
@@ -20,14 +17,21 @@ static void do_tile(tile_t **tiles, int row, int col)
        }
 
        /* Follow bottoms */
-       if (t->c == '|' && (l->top | l->bot) & RIGHT)
-               t->bot = LEFT | RIGHT;
-       if (t->c == '-' && (u->top | u->bot) & DOWN)
-               t->bot = UP | DOWN;
+       if (col > 0) {
+               tile_t *l = &rows[row].cols[col-1];
+               if (t->c == '|' && (l->top | l->bot) & RIGHT)
+                       t->bot = LEFT | RIGHT;
+       }
+       if (row > 0 && rows[row-1].ncols > col) {
+               tile_t *u = &rows[row-1].cols[col];
+               if (t->c == '-' && (u->top | u->bot) & DOWN)
+                       t->bot = UP | DOWN;
+       }
 
        /* Adds sides for ''s and .'s */
        if (t->c == '.' || t->c == '\'') {
-               if ((l->top | l->bot) & RIGHT)
+               tile_t *l = &rows[row].cols[col-1];
+               if (col > 0 && (l->top | l->bot) & RIGHT)
                        t->top |= LEFT;
                else
                        t->top |= RIGHT;
@@ -46,40 +50,44 @@ static void print_ptrn(int ptrn)
 int main()
 {
        /* Init tiles */
-       tile_t *tiles[64];
-       for (int i = 0; i < 64; i++)
-               tiles[i] = calloc(512, sizeof(tile_t));
-
-       /* Read data */
        char c;
-       int row = 1, col = 1;
+       int row = 0, col = 0;
+       row_t *rows = calloc(sizeof(row_t), (row+2));
        while ((c = getchar()) != EOF) {
-               if (row > 63 || col > 511)
-                       exit(-1);
                if (c == '\n') {
                        row++;
-                       col = 1;
+                       col = 0;
+                       rows = realloc(rows, sizeof(row_t) * (row+2));
+                       rows[row+0] = (row_t){.ncols =  0};
+                       rows[row+1] = (row_t){.ncols = -1};
                } else {
-                       tiles[row][col].c = c;
+                       rows[row].cols = realloc(rows[row].cols, sizeof(tile_t) * (col+1));
+                       rows[row].ncols = col+1;
+                       rows[row].cols[col] = (tile_t){.c = c};
+                       do_tile(rows, row, col);
                        col++;
                }
        }
 
-       /* Process */
-       for (row = 1; row < 63; row++)
-               for (col = 1; col < 511; col++)
-                       do_tile(tiles, row, col);
-
        /* Output */
-       //for (row = 1; row < 63; row++) {
-       //      for (col = 1; col < 511; col++) {
-       //              print_ptrn(tiles[row][col].top);
-       //              print_ptrn(tiles[row][col].bot);
-       //              printf(" ");
-       //      }
-       //      printf("\n");
-       //}
+       if (0)
+       for (row = 0; rows[row].ncols >= 0; row++) {
+               for (col = 0; col > rows[row].ncols; col++) {
+                       print_ptrn(rows[row].cols[col].top);
+                       print_ptrn(rows[row].cols[col].bot);
+                       printf(" ");
+               }
+               printf("\n");
+       }
 
        /* HTML */
-       print_index(tiles);
+       print_index(rows);
+
+       /* Free tile */
+       for (int row = 0; rows[row].ncols >= 0; row++)
+               if (rows[row].cols > 0)
+                       free(rows[row].cols);
+       free(rows);
+
+       return 0;
 }
index 0e777975c1e1ca7f707ea1cbec302f8145845647..52a1aef8677121cee35a7a4982c0a4e82552eef7 100644 (file)
@@ -11,4 +11,9 @@ typedef struct {
        int bot;
 } tile_t;
 
-void print_index(tile_t **tiles);
+typedef struct {
+       tile_t *cols;
+       int ncols;
+} row_t;
+
+void print_index(row_t *rows);
index f38e2c9e9cedf243eb055c734696eb1b82144539..dc787dd0a961e3f2122dff10a384aacd45256397 100644 (file)
@@ -1,7 +1,9 @@
 PROGS=knot
 CLEAN=html.c *.html
 
-default:V: hitch.html
+knots=`{ls *.txt}
+default:V: ${knots:%.txt=%.html}
+
 knot: knot.o html.o knot.h 
 
 %.html: $PROGS %.txt
diff --git a/knot/overhand.txt b/knot/overhand.txt
new file mode 100644 (file)
index 0000000..de5057b
--- /dev/null
@@ -0,0 +1,19 @@
+ ..
+.-|-
+'|'
+ |
+
+ _ _
+( \ )
+ / /
+/ " \
+
+-. _ _ .-
+  \ \ \
+  \" "/
+   '-'
+
+  _ _
+ / \ \
+--' '|-
+ '---'