Blob Blame Raw

#include "parser.c"


void run(U32 count, const char *code) {
  prepareKeys();
  Lex *l = lexParse(code);
  //lexChainPrint(l, stderr); fprintf(stderr, "\n");
  Op *op = opParse(l);
  //opPrint(op, stderr, 0);
  for(U32 t = 0; !count || t < count; ++t) {
    fputc(asint(opCall(op, t)) & 0xff, stdout);
    //printf("t%d %d\n", t, asint(opCall(op, t)) & 0xff);
  }
  opDestroy(op);
  free(l);
}


void run2(U32 count, const char *codeL, const char *codeR) {
  prepareKeys();
  Lex *ll = lexParse(codeL);
  Lex *lr = lexParse(codeR);
  Op *opl = opParse(ll);
  Op *opr = opParse(lr);
  for(U32 t = 0; !count || t < count; ++t) {
    fputc(asint(opCall(opl, t)) & 0xff, stdout);
    fputc(asint(opCall(opr, t)) & 0xff, stdout);
  }
  opDestroy(opl);
  opDestroy(opr);
  free(ll);
  free(lr);
}



int main(int argc, char **argv) {
  if (argc < 3 || argc > 4) {
    fprintf(stderr, "Usage:\n  bytebeat <count> <code> [<other-channel-code>]\n");
    exit(1);
  }

  U32 count = (U32)atoll(argv[1]);
  if (argc >= 4) run2(count, argv[2], argv[3]);
            else run(count, argv[2]);
  return 0;
}