////////////////////////////////
// Functions: File Handle Printf

MR4TH_SYMBOL void
m4_printf(char *fmt, ...){
  ArenaTemp scratch = arena_get_scratch(0, 0);
  va_list args;
  va_start(args, fmt);
  String8 str = str8_pushfv(scratch.arena, fmt, args);
  va_end(args);
  fwrite(str.str, 1, str.size, stdout);
  arena_release_scratch(&scratch);
}

MR4TH_SYMBOL void
m4_fprintf(FILE *file, char *fmt, ...){
  ArenaTemp scratch = arena_get_scratch(0, 0);
  va_list args;
  va_start(args, fmt);
  String8 str = str8_pushfv(scratch.arena, fmt, args);
  va_end(args);
  fwrite(str.str, 1, str.size, file);
  arena_release_scratch(&scratch);
}

MR4TH_SYMBOL void
m4_print_str8list(String8List *out){
  m4_fprint_str8list(stdout, out);
}

MR4TH_SYMBOL void
m4_fprint_str8list(FILE *file, String8List *out){
  for (String8Node *node = out->first;
       node != 0;
       node = node->next){
    fwrite(node->string.str, node->string.size, 1, file);
  }
}

// TODO(allen): integrate here
MR4TH_SYMBOL_STATIC void
stream_fprint(FILE *file, STREAM *stream){
  for (STREAM_Node *node = stream->first_node;
       node != 0;
       node = node->next){
    fwrite(node->data, 1, node->size, file);
  }
}

////////////////////////////////
// LogToProc for (FILE*)

MR4TH_SYMBOL void
cstd_logto_file_handle(void *uptr, String8 str){
  fwrite(str.str, 1, str.size, (FILE*)uptr);
}
