Add mes and mescc-tools-extra

mescc-tools-extra contains two important tools:
- cp
- chmod

mes first builds itself from a mes 0.21 seed as used by guix, and then
builds a mes 0.22 and then mes 0.22 using that created mes 0.22.

It does /not/ use bootstrap.sh as we don't have a proper shell at this
point, it has been manually adapted for kaem.
This commit is contained in:
fosslinux 2020-12-25 18:40:14 +11:00
parent 2706e07556
commit 649d7b68dc
1029 changed files with 120985 additions and 18 deletions

View file

@ -0,0 +1,172 @@
/* Copyright (C) 2020 fosslinux
* This file is part of mescc-tools
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
/* Define all of the constants */
// CONSTANT FALSE 0
#define FALSE 0
// CONSTANT TRUE 1
#define TRUE 1
// CONSTANT MAX_STRING 4096
#define MAX_STRING 4096
// CONSTANT MAX_ARRAY 256
#define MAX_ARRAY 256
/* There are all of the constants we need for the bitmask */
/* constant name */ /* decimal */ /* octal */
// CONSTANT S_ISUID 2048 /* 04000 */
// CONSTANT S_ISGID 1024 /* 02000 */
// CONSTANT S_ISVTX 512 /* 01000 */
// CONSTANT S_IRUSR 256 /* 00400 */
// CONSTANT S_IWUSR 128 /* 00200 */
// CONSTANT S_IXUSR 64 /* 00100 */
// CONSTANT S_IRGRP 32 /* 00040 */
// CONSTANT S_IWGRP 16 /* 00020 */
// CONSTANT S_IXGRP 8 /* 00010 */
// CONSTANT S_IROTH 4 /* 00004 */
// CONSTANT S_IWOTH 2 /* 00002 */
// CONSTANT S_IXOTH 1 /* 00001 */
/* Prototypes for external funcs */
void file_print(char* s, FILE* f);
char* prepend_char(char a, char* s);
int numerate_string(char *a);
void require(int bool, char* error);
char* copy_string(char* target, char* source);
int match(char* a, char* b);
/* Globals */
int verbose;
/* UTILITY FUNCTIONS */
/* Function to find the length of a char**; an array of strings */
int array_length(char** array)
{
int length = 0;
while(array[length] != NULL)
{
length = length + 1;
}
return length;
}
/* PROCESSING FUNCTIONS */
int main(int argc, char** argv)
{
/* Initialize variables */
char** files = calloc(MAX_ARRAY, sizeof(char*));
require(files != NULL, "Memory initialization of files failed\n");
int files_index = 0;
char* mode = NULL;
/* Set defaults */
verbose = FALSE;
int i = 1;
/* Loop arguments */
while(i <= argc)
{
if(NULL == argv[i])
{ /* Ignore and continue */
i = i + 1;
}
else if(match(argv[i], "-h") || match(argv[i], "--help"))
{
file_print("Usage: ", stdout);
file_print(argv[0], stdout);
file_print(" [-h | --help] [-V | --version] [-v | --verbose]\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "-V") || match(argv[i], "--version"))
{ /* Output version */
file_print("chmod version 1.1.0\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "-v") || match(argv[i], "--verbose"))
{
verbose = TRUE;
i = i + 1;
}
else if(argv[i][0] != '-')
{ /* It must be the file or the mode */
if(mode == NULL)
{ /* Mode always comes first */
mode = calloc(MAX_STRING, sizeof(char));
require(mode != NULL, "Memory initialization of mode failed\n");
copy_string(mode, argv[i]);
}
else
{ /* It's a file, as the mode is already done */
files[files_index] = calloc(MAX_STRING, sizeof(char));
require(files[files_index] != NULL, "Memory initialization of files[files_index] failed\n");
copy_string(files[files_index], argv[i]);
files_index = files_index + 1;
}
i = i + 1;
}
else
{ /* Unknown argument */
file_print("UNKNOWN_ARGUMENT\n", stderr);
exit(EXIT_FAILURE);
}
}
/* Ensure the two values have values */
require(mode != NULL, "Provide a mode\n");
require(files[0] != NULL, "Provide a file\n");
/* Convert the mode str into octal */
if(mode[0] != '0')
{ /* We need to indicate it is octal */
mode = prepend_char('0', mode);
}
int omode = numerate_string(mode);
/* Loop over files to be operated on */
FILE* test;
for(i = 0; i < array_length(files); i = i + 1)
{
/* Make sure the file can be opened */
test = fopen(files[i], "r");
require(test != NULL, "A file cannot be read\n");
fclose(test);
/* Verbose message */
if(verbose)
{
file_print("mode of '", stdout);
file_print(files[i], stdout);
file_print("' changed to ", stdout);
file_print(mode, stdout);
file_print("\n", stdout);
}
/* Perform the chmod */
chmod(files[i], omode);
free(files[i]);
}
free(mode);
free(files);
}

334
sysa/mescc-tools-extra/cp.c Normal file
View file

@ -0,0 +1,334 @@
/* Copyright (C) 2020 fosslinux
* This file is part of mescc-tools
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
/* Define all of the constants */
// CONSTANT FALSE 0
#define FALSE 0
// CONSTANT TRUE 1
#define TRUE 1
// CONSTANT MAX_STRING 4096
#define MAX_STRING 4096
// CONSTANT MAX_ARRAY 256
#define MAX_ARRAY 256
/* Prototypes for external funcs */
int match(char* a, char* b);
void file_print(char* s, FILE* f);
char* copy_string(char* target, char* source);
char* prepend_string(char* add, char* base);
void require(int bool, char* error);
char* postpend_char(char* s, char a);
int string_length(char* a);
void require(int bool, char* error);
/* Globals */
int verbose;
/* UTILITY FUNCTIONS */
/* Function to find a character's position in a string (last match) */
int find_last_char_pos(char* string, char a)
{
int i = string_length(string) - 1;
if(i < 0) return i;
while(i >= 0)
{
/*
* This conditional should be in the while conditional but we are
* running into the M2-Planet short-circuit bug.
*/
if(a == string[i]) break;
i = i - 1;
}
return i;
}
/* Function to find the length of a char**; an array of strings */
int array_length(char** array)
{
int length = 0;
while(array[length] != NULL)
{
length = length + 1;
}
return length;
}
/* PROCESSING FUNCTIONS */
char* directory_dest(char* dest, char* source, int require_directory)
{
/*
* First, check if it is a directory to copy to.
* We have two ways of knowing this:
* - If the destination ends in a slash, the user has explicitly said
* it is a directory.
* - Normally we would use stat() but we don't want to force support for
* that syscall onto the kernel, so we just attempt to chdir() into it
* and if it works then it must be a directory. A bit hacky, bit it
* works.
*/
int isdirectory = FALSE;
if(dest[string_length(dest) - 1] == '/')
{
isdirectory = TRUE;
}
if(!isdirectory)
{ /* Use the other testing method */
/*
* Get the current path so that we can chdir back to it if it does
* chdir successfully.
*/
char* current_path = calloc(MAX_STRING, sizeof(char));
require(current_path != NULL, "Memory initialization of current_path in directory_dest failed\n");
getcwd(current_path, MAX_STRING);
require(!match("", current_path), "getcwd() failed\n");
/*
* chdir expects an absolute path.
* If the first character is / then it is already absolute, otherwise
* it is relative and needs to be changed (by appending current_path
* to the dest path).
*/
char* chdir_dest = calloc(MAX_STRING, sizeof(char));
require(chdir_dest != NULL, "Memory initialization of chdir_dest in directory_dest failed\n");
if(dest[0] != '/')
{ /* The path is relative, append current_path */
copy_string(chdir_dest, prepend_string(prepend_string(current_path, "/"), dest));
}
else
{ /* The path is absolute */
copy_string(chdir_dest, dest);
}
if(0 <= chdir(chdir_dest))
{ /* chdir returned successfully */
/*
* But because of M2-Planet, that dosen't mean anything actually
* happened, check that before we go any further.
*/
char* new_path = calloc(MAX_STRING, sizeof(char));
require(new_path != NULL, "Memory initialization of new_path in directory_dest failed\n");
getcwd(new_path, MAX_STRING);
if(!match(current_path, new_path))
{
isdirectory = TRUE;
chdir(current_path);
}
}
free(chdir_dest);
free(current_path);
}
/*
* If it isn't a directory, and we require one, error out.
* Otherwise, just return what we were given, we're done here.
*/
if(require_directory) require(isdirectory, "Provide a directory destination for multiple source files\n");
if(!isdirectory) return dest;
/* If it is, we need to make dest a full path */
/* 1. Get the basename of source */
char* basename = calloc(MAX_STRING, sizeof(char));
require(basename != NULL, "Memory initialization of basename in directory_dest failed\n");
int last_slash_pos = find_last_char_pos(source, '/');
if(last_slash_pos >= 0)
{ /* Yes, there is a slash in it, copy over everything after that pos */
int spos; /* source pos */
int bpos = 0; /* basename pos */
int source_length = string_length(source);
/* Do the actual copy */
for(spos = last_slash_pos + 1; spos < string_length(source); spos = spos + 1)
{
basename[bpos] = source[spos];
bpos = bpos + 1;
}
}
else
{ /* No, there is no slash in it, hence the basename is just the source */
copy_string(basename, source);
}
/* 2. Ensure our dest (which is a directory) has a trailing slash */
if(dest[string_length(dest) - 1] != '/')
{
dest = postpend_char(dest, '/');
}
/* 3. Add the basename to the end of the directory */
dest = prepend_string(dest, basename);
free(basename);
/* Now we have a returnable path! */
return dest;
}
int copy_file(char* source, char* dest)
{
if(verbose)
{ /* Output message */
/* Of the form 'source' -> 'dest' */
file_print("'", stdout);
file_print(source, stdout);
file_print("' -> '", stdout);
file_print(dest, stdout);
file_print("'\n", stdout);
}
/* Open source and dest as FILE*s */
FILE* fsource = fopen(source, "r");
require(fsource != NULL, prepend_string(
prepend_string("Error opening source file ", source), "\n"));
FILE* fdest = fopen(dest, "w");
require(fdest >= 0, prepend_string(
prepend_string("Error opening destination file", dest), "\n"));
/*
* The following loop reads a character from the source and writes it to the
* dest file. This is all M2-Planet supports.
*/
char c = fgetc(fsource);
while(c != EOF)
{
fputc(c, fdest);
c = fgetc(fsource);
}
/* Cleanup */
fclose(fsource);
fclose(fdest);
}
int main(int argc, char** argv)
{
/* Initialize variables */
char** sources = calloc(MAX_ARRAY, sizeof(char*));
require(sources != NULL, "Memory initialization of sources failed\n");
int sources_index = 0;
char* dest = NULL;
/* Set defaults */
verbose = FALSE;
int i = 1;
int j;
int args_found;
/* Loop arguments */
while(i <= argc)
{
if(NULL == argv[i])
{ /* Ignore and continue */
i = i + 1;
}
else if(match(argv[i], "-h") || match(argv[i], "--help"))
{
file_print("Usage: ", stdout);
file_print(argv[0], stdout);
file_print(" [-h | --help] [-V | --version] [-v | --verbose] source1 source2 sourcen destination\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "-V") || match(argv[i], "--version"))
{ /* Output version */
file_print("cp version 1.1.0\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "-v") || match(argv[i], "--verbose"))
{
verbose = TRUE;
i = i + 1;
}
else if(argv[i][0] != '-')
{ /* It is not an option */
/*
* We can tell if this is the source file or the destination file
* through looking *ahead*. If it is the last of this type of argument then
* it must be the destination. (1 destination, many sources).
*/
j = i + 1;
args_found = 0;
while(j < array_length(argv))
{
if(argv[j][0] != '-')
{ /* It's one of these type of arguments */
args_found = args_found + 1;
}
j = j + 1;
}
if(args_found == 0)
{ /* We are setting the destination (there are no more left after this) */
dest = calloc(MAX_STRING, sizeof(char));
require(dest != NULL, "Memory initialization of dest failed\n");
copy_string(dest, argv[i]);
}
else
{ /* We are setting a source */
require(sources_index < MAX_ARRAY, "Too many files\n");
sources[sources_index] = calloc(MAX_STRING, sizeof(char));
require(sources[sources_index] != NULL, "Memory initialization of sources[source_index] failed\n");
copy_string(sources[sources_index], argv[i]);
sources_index = sources_index + 1;
}
i = i + 1;
}
else
{ /* Unknown argument */
file_print("UNKNOWN_ARGUMENT\n", stderr);
exit(EXIT_FAILURE);
}
}
/* Sanitize values */
/* Ensure the two values have values */
/* Another workaround for short-circuit bug */
int error = FALSE;
if(sources[0] == NULL) error = TRUE;
if(error == FALSE) if(match(sources[0], "")) error = TRUE;
require(!error, "Provide a source file\n");
error = FALSE;
if(dest == NULL) error = TRUE;
if(error == FALSE) if(match(dest, "")) error = TRUE;
require(!error, "Provide a destination file\n");
/* Loop through all of the sources, copying each one */
char* this_dest;
for(i = 0; i < array_length(sources); i = i + 1)
{
/* Convert the dest variable to a full path if it's a directory copying to */
/*
* Also, if there is more than one source, we have to be copying to
* a directory destination...
*/
if(array_length(sources) == 1)
{
dest = directory_dest(dest, sources[i], FALSE);
copy_file(sources[i], dest);
}
else
{
this_dest = calloc(MAX_STRING, sizeof(char));
require(this_dest != NULL, "Memory initalization of this_dest failed\n");
this_dest = directory_dest(dest, sources[i], TRUE);
copy_file(sources[i], this_dest);
}
/* Perform the actual copy */
free(sources[i]);
}
free(sources);
free(dest);
}

View file

@ -0,0 +1,27 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of mescc-tools.
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include<stdio.h>
// void fputc(char s, FILE* f);
void file_print(char* s, FILE* f)
{
while(0 != s[0])
{
fputc(s[0], f);
s = s + 1;
}
}

View file

@ -0,0 +1,32 @@
/* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* This file is part of mescc-tools.
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#define FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int in_set(int c, char* s)
{
while(0 != s[0])
{
if(c == s[0]) return TRUE;
s = s + 1;
}
return FALSE;
}

View file

@ -0,0 +1,35 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of mescc-tools.
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#define FALSE 0
// CONSTANT FALSE 0
#define TRUE 1
// CONSTANT TRUE 1
int match(char* a, char* b)
{
int i = -1;
do
{
i = i + 1;
if(a[i] != b[i])
{
return FALSE;
}
} while((0 != a[i]) && (0 !=b[i]));
return TRUE;
}

View file

@ -0,0 +1,170 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of mescc-tools.
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include<stdlib.h>
// void* calloc(int count, int size);
#define TRUE 1
//CONSTANT TRUE 1
#define FALSE 0
//CONSTANT FALSE 0
int in_set(int c, char* s);
//CONSTANT NULL 0
char* numerate_number(int a)
{
char* result = calloc(16, sizeof(char));
if(NULL == result) return NULL;
int i = 0;
/* Deal with Zero case */
if(0 == a)
{
result[0] = '0';
return result;
}
/* Deal with negatives */
if(0 > a)
{
result[0] = '-';
i = 1;
a = a * -1;
}
/* Using the largest 10^n number possible in 32bits */
int divisor = 0x3B9ACA00;
/* Skip leading Zeros */
while(0 == (a / divisor)) divisor = divisor / 10;
/* Now simply collect numbers until divisor is gone */
while(0 < divisor)
{
result[i] = ((a / divisor) + 48);
a = a % divisor;
divisor = divisor / 10;
i = i + 1;
}
return result;
}
int char2hex(int c)
{
if (c >= '0' && c <= '9') return (c - 48);
else if (c >= 'a' && c <= 'f') return (c - 87);
else if (c >= 'A' && c <= 'F') return (c - 55);
else return -1;
}
int hex2char(int c)
{
if((c >= 0) && (c <= 9)) return (c + 48);
else if((c >= 10) && (c <= 15)) return (c + 55);
else return -1;
}
int char2dec(int c)
{
if (c >= '0' && c <= '9') return (c - 48);
else return -1;
}
int dec2char(int c)
{
if((c >= 0) && (c <= 9)) return (c + 48);
else return -1;
}
int index_number(char* s, char c)
{
int i = 0;
while(s[i] != c)
{
i = i + 1;
if(0 == s[i]) return -1;
}
return i;
}
int toupper(int c)
{
if(in_set(c, "abcdefghijklmnopqrstuvwxyz")) return (c & 0xDF);
return c;
}
int set_reader(char* set, int mult, char* input)
{
int n = 0;
int i = 0;
int hold;
int negative_p = FALSE;
if(input[0] == '-')
{
negative_p = TRUE;
i = i + 1;
}
while(in_set(input[i], set))
{
n = n * mult;
hold = index_number(set, toupper(input[i]));
/* Input managed to change between in_set and index_number */
if(-1 == hold) return 0;
n = n + hold;
i = i + 1;
}
/* loop exited before NULL and thus invalid input */
if(0 != input[i]) return 0;
if(negative_p)
{
n = 0 - n;
}
return n;
}
int numerate_string(char *a)
{
/* If NULL string */
if(0 == a[0]) return 0;
/* Deal with binary*/
else if ('0' == a[0] && 'b' == a[1])
{
return set_reader("01", 2, a+2);
}
/* Deal with hex */
else if ('0' == a[0] && 'x' == a[1])
{
return set_reader("0123456789ABCDEFabcdef", 16, a+2);
}
/* Deal with octal */
else if('0' == a[0])
{
return set_reader("01234567", 8, a+1);
}
/* Deal with decimal */
else
{
return set_reader("0123456789", 10, a);
}
}

View file

@ -0,0 +1,31 @@
/* Copyright (C) 2016 Jeremiah Orians
* Copyright (C) 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* This file is part of mescc-tools.
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include<stdio.h>
#include<stdlib.h>
void file_print(char* s, FILE* f);
void require(int bool, char* error)
{
if(!bool)
{
file_print(error, stderr);
exit(EXIT_FAILURE);
}
}

View file

@ -0,0 +1,70 @@
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of mescc-tools.
*
* mescc-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mescc-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
*/
#include<stdlib.h>
#include<stdio.h>
#define MAX_STRING 4096
//CONSTANT MAX_STRING 4096
// void* calloc(int count, int size);
void file_print(char* s, FILE* f);
char* copy_string(char* target, char* source)
{
while(0 != source[0])
{
target[0] = source[0];
target = target + 1;
source = source + 1;
}
return target;
}
char* postpend_char(char* s, char a)
{
char* ret = calloc(MAX_STRING, sizeof(char));
if(NULL == ret) return NULL;
char* hold = copy_string(ret, s);
hold[0] = a;
return ret;
}
char* prepend_char(char a, char* s)
{
char* ret = calloc(MAX_STRING, sizeof(char));
if(NULL == ret) return NULL;
ret[0] = a;
copy_string((ret+1), s);
return ret;
}
char* prepend_string(char* add, char* base)
{
char* ret = calloc(MAX_STRING, sizeof(char));
if(NULL == ret) return NULL;
copy_string(copy_string(ret, add), base);
return ret;
}
int string_length(char* a)
{
int i = 0;
while(0 != a[i]) i = i + 1;
return i;
}

View file

@ -0,0 +1,81 @@
#!/bin/sh
set -ex
# cp command
M2-Planet \
-f /M2-Planet/test/common_x86/functions/file.c \
-f /M2-Planet/test/common_x86/functions/exit.c \
-f /M2-Planet/test/common_x86/functions/malloc.c \
-f /M2-Planet/test/common_x86/functions/getcwd.c \
-f /M2-Planet/test/common_x86/functions/chdir.c \
-f functions/string.c \
-f functions/file_print.c \
-f functions/match.c \
-f functions/require.c \
-f /M2-Planet/functions/calloc.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f cp.c \
--architecture x86 \
--debug \
-o cp.M1
blood-elf -f cp.M1 -o cp-footer.M1
M1 \
-f /M2-Planet/test/common_x86/x86_defs.M1 \
-f /M2-Planet/test/common_x86/libc-core.M1 \
-f cp.M1 \
-f cp-footer.M1 \
--LittleEndian \
--architecture x86 \
-o hold
hex2 \
-f /M2-Planet/test/common_x86/ELF-i386-debug.hex2 \
-f hold \
--LittleEndian \
--architecture x86 \
--BaseAddress 0x8048000 \
-o /after/bin/cp \
--exec_enable
# chmod command
M2-Planet \
-f /M2-Planet/test/common_x86/functions/file.c \
-f /M2-Planet/test/common_x86/functions/exit.c \
-f /M2-Planet/test/common_x86/functions/malloc.c \
-f /M2-Planet/test/common_x86/functions/getcwd.c \
-f /M2-Planet/test/common_x86/functions/chdir.c \
-f functions/string.c \
-f functions/file_print.c \
-f functions/match.c \
-f functions/require.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f /M2-Planet/functions/calloc.c \
-f /M2-Planet/test/common_x86/functions/stat.c \
-f chmod.c \
--architecture x86 \
--debug \
-o chmod.M1
blood-elf -f chmod.M1 -o chmod-footer.M1
M1 \
-f /M2-Planet/test/common_x86/x86_defs.M1 \
-f /M2-Planet/test/common_x86/libc-core.M1 \
-f chmod.M1 \
-f chmod-footer.M1 \
--LittleEndian \
--architecture x86 \
-o hold
hex2 \
-f /M2-Planet/test/common_x86/ELF-i386-debug.hex2 \
-f hold \
--LittleEndian \
--architecture x86 \
--BaseAddress 0x8048000 \
-o /after/bin/chmod \
--exec_enable