interpolate.c - pointtools - Simple point utilities to hold text presentations. HTML git clone git://bitreich.org/pointtools/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/pointtools/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- interpolate.c (1587B) --- 1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <unistd.h> 5 6 #define STEPS 32 7 8 /* SLEEPTIME in microseconds */ 9 #define SLEEPTIME 100 10 11 int 12 main(int argc, char *argv[]) 13 { 14 FILE *from, *to; 15 int i, j, k; 16 int width, height; 17 int fromn, ton; 18 size_t linesize; 19 ssize_t r; 20 char **fromlines, **tolines, *line; 21 char fromc, toc; 22 23 if (argc < 3) 24 return 1; 25 26 if (!(from = fopen(argv[1], "r"))) 27 return 1; 28 29 if (!(to = fopen(argv[2], "r"))) 30 return 1; 31 32 line = NULL; 33 linesize = 0; 34 width = 0; 35 36 fromn = 0; 37 fromlines = NULL; 38 while ((r = getline(&line, &linesize, from)) != -1) { 39 if (line[r-1] == '\n') 40 line[--r] = '\0'; 41 fromn++; 42 fromlines = realloc(fromlines, fromn * sizeof(*fromlines)); 43 fromlines[fromn-1] = strdup(line); 44 if (r > width) 45 width = r; 46 } 47 fclose(from); 48 49 ton = 0; 50 tolines = NULL; 51 while ((r = getline(&line, &linesize, to)) != -1) { 52 if (line[r-1] == '\n') 53 line[--r] = '\0'; 54 ton++; 55 tolines = realloc(tolines, ton * sizeof(*tolines)); 56 tolines[ton-1] = strdup(line); 57 if (r > width) 58 width = r; 59 } 60 fclose(to); 61 62 height = ton > fromn ? ton : fromn; 63 64 printf("\033[2J"); 65 for (k = 0; k <= STEPS; k++) { 66 printf("\033[;H"); 67 for (i = 0; i < height; i++) { 68 for (j = 0; j < width; j++) { 69 fromc = ' '; 70 toc = ' '; 71 if (i < fromn && j < strlen(fromlines[i])) 72 fromc = fromlines[i][j]; 73 if (i < ton && j < strlen(tolines[i])) 74 toc = tolines[i][j]; 75 if (toc & 128) 76 putchar(toc); 77 else 78 putchar(fromc + (toc - fromc) * k / STEPS); 79 } 80 putchar('\n'); 81 } 82 usleep(SLEEPTIME); 83 } 84 85 return 0; 86 }