playStdin

play recorded stdin with the commnad recordStdin. Time delays between lines are kept
git clone https://noulin.net/git/playStdin.git
Log | Files | Refs | LICENSE

playStdin.c (655B)


      1 #! /usr/bin/env sheepy
      2 
      3 #include "libsheepyObject.h"
      4 
      5 int main(int ARGC, char** ARGV) {
      6 
      7     if (ARGC < 2) {
      8         puts(BLD RED "Missing record name!" RST);
      9         XFAILURE
     10     }
     11 
     12     FILE *f = fopen(ARGV[1], "r");
     13     if (!f) {
     14         puts(BLD RED "Couldn't open record file!" RST);
     15         XFAILURE
     16     }
     17 
     18     char b[2*1024*1024];
     19     while (fgets(b, sizeof b, f)) {
     20         char **l = split(b, ",");
     21         char *timeS = dequeueG(&l, unusedV);
     22         char *s  = join(l, ",");
     23         freeG(l);
     24 
     25         printf("%s", s);
     26 
     27         u64 time = parseInt(timeS);
     28         nanoSleep(time * 1000000); 
     29 
     30         freeManyS(timeS, s);
     31     }
     32     fclose(f);
     33 }