package embox.compat.libc.stdio

@DefaultImpl(print)
abstract module print_impl {
}

static module print extends print_impl {
	option number support_floating=1

	source "printf_impl.c"
	source "printf_impl.h"

	@NoRuntime depends embox.compat.libc.math
	@NoRuntime depends embox.compat.libc.stdlib.core // atoi
	@NoRuntime depends embox.compat.libc.str
	@NoRuntime depends embox.compat.libc.type
}

static module print_stub extends print_impl {
	option number support_floating=1

	source "print_stub.c"
	source "printf_impl.h"
}

static module sprintf {
	source "sprintf.c"
	source "snprintf.c"

	@NoRuntime depends print_impl
}

static module file_pool {
	option number file_quantity = 16

	source "stdio_file.c"
}

static module open {
	source "fopen.c"

	depends file_pool
	@NoRuntime depends embox.compat.posix.file_system
	@NoRuntime depends embox.compat.libc.str
	depends embox.compat.posix.index_descriptor
}

static module fseek {
	source "fseek.c"

	@NoRuntime depends embox.compat.posix.file_system
}

static module printf {
	source "printf.c"
	source "fprintf.c"
	source "dprintf.c"

	depends fputc
	depends fputs
	/* gcc automatically repalces printf()
	 * w/ puts() if no arguments after format are given
	 */
}

static module fwrite {
	source "fwrite.c"

	depends embox.compat.posix.index_descriptor
	depends embox.kernel.task.resource.errno

	depends funopen
}

static module fputc {
	source "fputc.c"

	depends fwrite
	depends embox.compat.libc.stdio.stdio_stdstreams
}

static module fputs {
	source "fputs.c"

	depends fputc
}

@DefaultImpl(embox.compat.libc.stdio.stdio_streams_global)
abstract module stdio_stdstreams {
}

static module stdio_streams_global extends embox.compat.libc.stdio.stdio_stdstreams {
	source "stdin_stderr.c"

	source "stdout_global.h"
	source "stdout_global.c"
}

static module stdio_streams_task_resource extends embox.compat.libc.stdio.stdio_stdstreams {
	source "stdin_stderr.c"

	source "stdout_task_resource.h"

	depends embox.kernel.task.resource.stdout
}

static module funopen {
	source "funopen.c"

	depends file_pool
}

static module file_struct_header {
	@IncludeExport(path="stdio/internal")
	source "file_struct.h"
}

static module file_ops {
	source "fgetc.c"
	source "ungetc.c"
	source "fgets.c"

	source "fileno.c"

	source "feof.c"
	source "ferror.c"
	source "clearerr.c"

	source "fread.c"
	@NoRuntime depends embox.compat.posix.index_descriptor

	source "fioctl.c"
	source "fflush.c"
	source "fclose.c"

	source "buf.c"

	depends file_struct_header
	depends file_pool
	@NoRuntime depends embox.compat.posix.file_system

	source "printf.c"
	source "fprintf.c"

	@NoRuntime depends print
	depends open
	depends fputc
	depends fputs
	depends fwrite
	depends embox.compat.libc.stdio.stdio_stdstreams
}
	
static module all {
	@NoRuntime depends sprintf
	@NoRuntime depends open
	@NoRuntime depends fseek
	@NoRuntime depends file_ops
	@NoRuntime depends scanf_api
	@NoRuntime depends perror
	@NoRuntime depends div
	@NoRuntime depends tmpfile
	@NoRuntime depends ppipe
}

@DefaultImpl(tmpfile_stub)
abstract module tmpfile {
}

static module tmpfile_stub extends tmpfile {
	source "tmpfile_stub.c"
}

@DefaultImpl(ppipe_stub)
abstract module ppipe {
}

static module ppipe_stub extends ppipe {
	source "ppipe_stub.c"
}

static module perror {
	source "perror.c"
}

@DefaultImpl(scanf)
abstract module scanf_api {
}

static module scanf_without_file extends scanf_api {
	source "scanf.c", "scanf_scanchar_without_file.c"
}

static module scanf extends scanf_api {
	source "scanf.c"
	source "fscanf.c"

	depends file_ops /* ungetc() */
}

static module div {
	source "div.c"
	source "ldiv.c"
	source "lldiv.c"
}

static module asprintf {
	source "asprintf.c"
}

static module getline {
	source "getline.c"
}
