<commit_before>/*
** Copyright 2001, <NAME>. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <libsys/syscalls.h>
#include <libsys/stdio.h>
#include <libc/string.h>
#include <libc/ctype.h>

#include "commands.h"

int cmd_exit(int argc, char *argv[])
{
	return -1;
}

int cmd_exec(int argc, char *argv[])
{
	proc_id pid;

	if(argc <= 1) {
		printf("not enough args to exec\n");
		return 0;
	}

	printf("executing binary '%s'\n", argv[1]);

	pid = sys_proc_create_proc(argv[1], argv[1], 5);
	if(pid >= 0) {
		int retcode;
		sys_proc_wait_on_proc(pid, &retcode);
		printf("spawned process was pid 0x%x, retcode 0x%x\n", pid, retcode);
	}

	return 0;
}

int cmd_mount(int argc, char *argv[])
{
	int i, rc;

	if(argc < 4) {
		printf("not enough arguments to mount:\n");
		printf("usage: mount <path> <device> <fsname>\n");
		return 0;
	}

	rc = sys_mount(argv[1], argv[2], argv[3], NULL);
	if (rc < 0) {
		printf("sys_mount() returned error %d\n", rc);
	} else {
		printf("%s successfully mounted on %s.\n", argv[2], argv[1]);
	}

	return 0;
}

int cmd_unmount(int argc, char *argv[])
{
	int rc;

	if(argc < 2) {
		printf("not enough arguments to unmount\n");
		return 0;
	}

	rc = sys_unmount(argv[1]);
	if (rc < 0) {
		printf("sys_unmount() returned error %d\n", rc);
	} else {
		printf("%s successfully unmounted.\n", argv[1]);
	}

	return 0;
}

int cmd_mkdir(int argc, char *argv[])
{
	int rc;

	if(argc < 2) {
		printf("not enough arguments to mkdir\n");
		return 0;
	}

	rc = sys_create(argv[1], STREAM_TYPE_DIR);
	if (rc < 0) {
		printf("sys_mkdir() returned error %d\n", rc);
	} else {
		printf("%s successfully created.\n", argv[1]);
	}

	return 0;
}

int cmd_cat(int argc, char *argv[])
{
	int rc;
	int fd;
	char buf[257];
	int len;

	if(argc < 2) {
		printf("not enough arguments to cat\n");
		return 0;
	}

	fd = sys_open(argv[1], STREAM_TYPE_FILE, 0);
	if(fd < 0) {
		printf("cat: sys_open() returned %d!\n", fd);
		goto done_cat;
	}

	for(;;) {
		rc = sys_read(fd, buf, -1, sizeof(buf) -1);
		if(rc <= 0)
			break;

		buf[rc] = '\0';
		printf("%s", buf);
	}
	sys_close(fd);

done_cat:
	return 0;
}

int cmd_cd(int argc, char *argv[])
{
	int rc;

	if(argc < 2) {
		printf("not enough arguments to cat\n");
		return 0;
	}<commit_msg>Fear the dangers of cut & paste!  :-)<commit_after>/*
** Copyright 2001, <NAME>. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <libsys/syscalls.h>
#include <libsys/stdio.h>
#include <libc/string.h>
#include <libc/ctype.h>

#include "commands.h"

int cmd_exit(int argc, char *argv[])
{
	return -1;
}

int cmd_exec(int argc, char *argv[])
{
	proc_id pid;

	if(argc <= 1) {
		printf("not enough args to exec\n");
		return 0;
	}

	printf("executing binary '%s'\n", argv[1]);

	pid = sys_proc_create_proc(argv[1], argv[1], 5);
	if(pid >= 0) {
		int retcode;
		sys_proc_wait_on_proc(pid, &retcode);
		printf("spawned process was pid 0x%x, retcode 0x%x\n", pid, retcode);
	}

	return 0;
}

int cmd_mount(int argc, char *argv[])
{
	int i, rc;

	if(argc < 4) {
		printf("not enough arguments to mount:\n");
		printf("usage: mount <path> <device> <fsname>\n");
		return 0;
	}

	rc = sys_mount(argv[1], argv[2], argv[3], NULL);
	if (rc < 0) {
		printf("sys_mount() returned error %d\n", rc);
	} else {
		printf("%s successfully mounted on %s.\n", argv[2], argv[1]);
	}

	return 0;
}

int cmd_unmount(int argc, char *argv[])
{
	int rc;

	if(argc < 2) {
		printf("not enough arguments to unmount\n");
		return 0;
	}

	rc = sys_unmount(argv[1]);
	if (rc < 0) {
		printf("sys_unmount() returned error %d\n", rc);
	} else {
		printf("%s successfully unmounted.\n", argv[1]);
	}

	return 0;
}

int cmd_mkdir(int argc, char *argv[])
{
	int rc;

	if(argc < 2) {
		printf("not enough arguments to mkdir\n");
		return 0;
	}

	rc = sys_create(argv[1], STREAM_TYPE_DIR);
	if (rc < 0) {
		printf("sys_mkdir() returned error %d\n", rc);
	} else {
		printf("%s successfully created.\n", argv[1]);
	}

	return 0;
}

int cmd_cat(int argc, char *argv[])
{
	int rc;
	int fd;
	char buf[257];
	int len;

	if(argc < 2) {
		printf("not enough arguments to cat\n");
		return 0;
	}

	fd = sys_open(argv[1], STREAM_TYPE_FILE, 0);
	if(fd < 0) {
		printf("cat: sys_open() returned %d!\n", fd);
		goto done_cat;
	}

	for(;;) {
		rc = sys_read(fd, buf, -1, sizeof(buf) -1);
		if(rc <= 0)
			break;

		buf[rc] = '\0';
		printf("%s", buf);
	}
	sys_close(fd);

done_cat:
	return 0;
}

int cmd_cd(int argc, char *argv[])
{
	int rc;

	if(argc < 2) {
		printf("not enough arguments to cd\n");
		return 0;
	}
{'fraction_non_alphanumeric': 0.18767751802490715, 'fraction_numerical': 0.022285339742189207, 'mean_word_length': 3.624242424242424, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7209111', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1888, 'n_words': 514}