Commit 03bd05f9 authored by Ercan Ersoy's avatar Ercan Ersoy

Some updates

Fix default language configuration in config.h, update source files for
standardization, build settings change to -01 optimisation and update
executable files.
parent 279db1fd
......@@ -2,9 +2,9 @@
# Written by Ercan Ersoy.
CC = gcc
CFLAGS = -O3 -s -c
CFLAGS = -O1 -s -c
LD = gcc
LDFLAGS = -O3 -s
LDFLAGS = -O1 -s
all: minibox*
......
No preview for this file type
No preview for this file type
......@@ -5,14 +5,14 @@
#include "../minibox.h"
#if COMMAND_BEEP
#ifdef COMMAND_BEEP
int command_beep(int argc, char *argv[])
{
int i = 2;
int frequency = 750;
int length = 1000;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_BEEP_DESCRIPTION);
......@@ -21,17 +21,17 @@ int command_beep(int argc, char *argv[])
puts(STRING_OPTIONS);
puts(STRING_MINIBOX_BEEP_OPTIONS_1);
puts(STRING_MINIBOX_BEEP_OPTIONS_2);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
for(i; i < argc; i++)
{
......@@ -54,7 +54,7 @@ int command_beep(int argc, char *argv[])
else
{
puts(STRING_INVALID_SYNTAX);
return 1;
return EXIT_FAILURE;
}
}
......
......@@ -5,7 +5,7 @@
#include "../minibox.h"
#if COMMAND_CAT
#ifdef COMMAND_CAT
int command_cat(int argc, char *argv[])
{
int i = 2;
......@@ -14,7 +14,7 @@ int command_cat(int argc, char *argv[])
unsigned char show_ends = 0;
unsigned char show_tabs = 0;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_CAT_DESCRIPTION);
......@@ -23,17 +23,17 @@ int command_cat(int argc, char *argv[])
puts(STRING_OPTIONS);
puts(STRING_MINIBOX_CAT_OPTIONS_1);
puts(STRING_MINIBOX_CAT_OPTIONS_2);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
for(i; i < argc; i++)
{
......@@ -71,6 +71,6 @@ int command_cat(int argc, char *argv[])
fclose(file_resource);
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,7 +5,7 @@
#include "../minibox.h"
#if COMMAND_CD
#ifdef COMMAND_CD
int command_cd(int argc, char *argv[])
{
if(argc == 3)
......@@ -13,10 +13,10 @@ int command_cd(int argc, char *argv[])
if(chdir(argv[2]))
{
fprintf(stderr, STRING_DOES_NOT_DIRECTORY, argv[3]);
return 1;
return EXIT_FAILURE;
}
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,29 +5,29 @@
#include "../minibox.h"
#if COMMAND_CLEAR
#ifdef COMMAND_CLEAR
int command_clear(int argc, char *argv[])
{
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_CLEAR_DESCRIPTION);
puts(" MINIBOX clear");
puts(" MINIBOX clear --help|--version\r\n");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
clrscr();
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,43 +5,44 @@
#include "../minibox.h"
#if COMMAND_CP
#ifdef COMMAND_CP
int command_cp(int argc, char *argv[])
{
#if HELP
#ifdef HELP
if(argc == 3 && !strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_CP_DESCRIPTION);
puts(STRING_MINIBOX_CP_USAGE);
puts(" MINIBOX cp --help|--version");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(argc == 3 && !strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
if(argc == 4)
{
if(link(argv[2], argv[3]))
{
fprintf(stderr, STRING_CANNOT_COPY, argv[2]);
return EXIT_FAILURE;
}
}
else if(argc < 4)
{
fputs(STRING_NO_ENOUGH_ARGUMENTS, stderr);
return EXIT_FAILURE;
}
else
{
fputs(STRING_TOO_MUCH_ARGUMENTS, stderr);
return EXIT_FAILURE;
}
return 0;
}
#endif
......@@ -5,7 +5,7 @@
#include "../minibox.h"
#if COMMAND_DATE
#ifdef COMMAND_DATE
int command_date(int argc, char *argv[])
{
time_t datetime_time_t;
......@@ -14,7 +14,7 @@ int command_date(int argc, char *argv[])
struct time set_time;
char formatted_string[DATE_AND_TIME_STRING_MAX];
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_DATE_DESCRIPTION);
......@@ -25,44 +25,44 @@ int command_date(int argc, char *argv[])
puts(STRING_MINIBOX_DATE_OPTIONS_2);
puts(STRING_MINIBOX_DATE_OPTIONS_3);
puts(STRING_MINIBOX_DATE_OPTIONS_4);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
datetime_time_t = time(NULL);
if(argc < 3)
{
puts(ctime(&datetime_time_t));
return 0;
return EXIT_SUCCESS;
}
else
{
if(!strcmp(argv[2], "-s"))
{
sscanf(argv[3], "%4hu-%2hhu-%2hhu %2hhu:%2hhu:%2hhu", &(set_date.da_year), &(set_date.da_mon), &(set_date.da_day), &(set_time.ti_hour), &(set_time.ti_min), &(set_time.ti_sec));
printf("%d:%d:%d", set_date.da_year, set_date.da_mon, set_date.da_day);
setdate(&set_date);
settime(&set_time);
return 0;
printf("%d:%d:%d", set_date.da_year, set_date.da_mon, set_date.da_day);
setdate(&set_date);
settime(&set_time);
return EXIT_SUCCESS;
}
else
{
datetime_tm = localtime(&datetime_time_t);
strftime(formatted_string, DATE_AND_TIME_STRING_MAX, argv[2], datetime_tm);
puts(formatted_string);
return 0;
return EXIT_SUCCESS;
}
}
}
......
......@@ -5,7 +5,7 @@
#include "../minibox.h"
#if COMMAND_ECHO
#ifdef COMMAND_ECHO
int command_echo(int argc, char *argv[])
{
char backslash_escapes = 0;
......@@ -15,7 +15,7 @@ int command_echo(int argc, char *argv[])
int j = 0;
char character;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_ECHO_DESCRIPTION);
......@@ -25,17 +25,17 @@ int command_echo(int argc, char *argv[])
puts(STRING_MINIBOX_ECHO_OPTIONS_1);
puts(STRING_MINIBOX_ECHO_OPTIONS_2);
puts(STRING_MINIBOX_ECHO_OPTIONS_3);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
if(!strcmp(argv[2], "-e"))
{
......@@ -150,6 +150,6 @@ int command_echo(int argc, char *argv[])
putchar('\n');
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,29 +5,74 @@
#include "../minibox.h"
#if HELP
#if COMMAND_HELP
#ifdef HELP
#ifdef COMMAND_HELP
int command_help(int argc, char *argv[])
{
puts(STRING_MINIBOX_COMMANDS);
#ifdef COMMAND_BEEP
puts("beep");
#endif
#ifdef COMMAND_CAT
puts("cat");
#endif
#ifdef COMMAND_CD
puts("cd");
#endif
#ifdef COMMAND_CD
puts("clear");
#endif
#ifdef COMMAND_CP
puts("cp");
#endif
#ifdef COMMAND_DATE
puts("date");
#endif
#ifdef COMMAND_ECHO
puts("echo");
#endif
#ifdef COMMAND_LS
puts("ls");
#endif
#ifdef COMMAND_LS
puts("mkdir");
#endif
#ifdef COMMAND_MV
puts("mv");
#endif
puts("help");
#ifdef COMMAND_PWD
puts("pwd");
#endif
#ifdef COMMAND_RM
puts("rm");
#endif
#ifdef COMMAND_RMDIR
puts("rmdir");
#endif
#ifdef COMMAND_SH
puts("sh");
#endif
#ifdef COMMAND_TIME
puts("time");
#endif
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#endif
......@@ -7,7 +7,7 @@
#define MAX_PATH_LENGTH 260
#if COMMAND_LS
#ifdef COMMAND_LS
void path_current_directory(char *path)
{
getcwd(path, MAX_PATH_LENGTH);
......@@ -31,7 +31,7 @@ int command_ls(int argc, char *argv[])
if(argc > 2)
{
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_LS_DESCRIPTION);
......@@ -41,17 +41,17 @@ int command_ls(int argc, char *argv[])
puts(STRING_MINIBOX_LS_OPTIONS_1);
puts(STRING_MINIBOX_LS_OPTIONS_2);
puts(STRING_MINIBOX_LS_OPTIONS_3);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
for(i; i < argc; i++)
{
......
......@@ -10,23 +10,23 @@ int command_mkdir(int argc, char *argv[])
{
int i = 2;
#if HELP
#if HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_MKDIR_DESCRIPTION);
puts(STRING_MINIBOX_MKDIR_USAGE);
puts(" MINIBOX mkdir --help|--version");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#if VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
for(i; i < argc; i++)
{
......@@ -36,6 +36,6 @@ int command_mkdir(int argc, char *argv[])
}
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,27 +5,27 @@
#include "../minibox.h"
#if COMMAND_MV
#ifdef COMMAND_MV
int command_mv(int argc, char *argv[])
{
#if HELP
#ifdef HELP
if(argc == 3 && !strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_MV_DESCRIPTION_1);
puts(STRING_MINIBOX_MV_DESCRIPTION_2);
puts(STRING_MINIBOX_MV_USAGE);
puts(" MINIBOX mv --help|--version");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(argc == 3 && !strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
if(argc == 4)
{
......@@ -43,6 +43,6 @@ int command_mv(int argc, char *argv[])
fputs(STRING_TOO_MUCH_ARGUMENTS, stderr);
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,28 +5,28 @@
#include "../minibox.h"
#if COMMAND_PWD
#ifdef COMMAND_PWD
int command_pwd(int argc, char *argv[])
{
char *buffer;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_PWD_DESCRIPTION);
puts(" MINIBOX pwd");
puts(" MINIBOX pwd --help|--version");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
else if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
else
{
......@@ -35,6 +35,6 @@ int command_pwd(int argc, char *argv[])
free(buffer);
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,7 +5,7 @@
#include "../minibox.h"
#if COMMAND_RM
#ifdef COMMAND_RM
char item_remove(char *removing_item_path)
{
DIR *element;
......@@ -47,7 +47,7 @@ int command_rm(int argc, char *argv[])
{
int i = 2;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_RM_DESCRIPTION);
......@@ -55,17 +55,17 @@ int command_rm(int argc, char *argv[])
puts(" MINIBOX rm --help|--version\r\n");
puts(STRING_OPTION);
puts(STRING_MINIBOX_RM_OPTION);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
if(!strcmp(argv[2], "-r"))
{
......@@ -79,7 +79,7 @@ int command_rm(int argc, char *argv[])
}
}
return 0;
return EXIT_SUCCESS;
}
else
{
......@@ -92,6 +92,6 @@ int command_rm(int argc, char *argv[])
}
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,28 +5,28 @@
#include "../minibox.h"
#if COMMAND_RMDIR
#ifdef COMMAND_RMDIR
int command_rmdir(int argc, char *argv[])
{
int i = 2;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_RMDIR_DESCRIPTION);
puts(STRING_MINIBOX_RMDIR_USAGE);
puts(" MINIBOX rmdir --help|--version");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
for(i; i < argc; i++)
{
......@@ -36,6 +36,6 @@ int command_rmdir(int argc, char *argv[])
}
}
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,12 +5,12 @@
#include "../minibox.h"
#if COMMAND_SH
#ifdef COMMAND_SH
int command_sh(int argc, char *argv[])
{
char *command_line;
#if HELP
#ifdef HELP
if(!strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_SH_DESCRIPTION);
......@@ -18,17 +18,17 @@ int command_sh(int argc, char *argv[])
puts(" MINIBOX sh --help|--version\r\n");
puts(STRING_NOTE);
puts(STRING_MINIBOX_SH_EXIT);
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#ifdef VERSION
else if(!strcmp(argv[2], "--version"))
{
version();
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
command_line = (char *) malloc(MAX_COMMAND_LINE_LENGTH);
......@@ -39,7 +39,7 @@ int command_sh(int argc, char *argv[])
if(!strcmp(command_line, "exit\n"))
{
exit(0);
exit(EXIT_SUCCESS);
}
else if(strcmp(command_line, "\n"))
{
......@@ -50,6 +50,6 @@ int command_sh(int argc, char *argv[])
free(command_line);
return 0;
return EXIT_SUCCESS;
}
#endif
......@@ -5,7 +5,7 @@
#include "../minibox.h"
#if COMMAND_TIME
#ifdef COMMAND_TIME
int command_time(int argc, char *argv[])
{
int i = 0;
......@@ -14,23 +14,23 @@ int command_time(int argc, char *argv[])
struct timeval end;
long double measured_time = 0.0;
#if HELP
#ifdef HELP
if(argc == 3 && !strcmp(argv[2], "--help"))
{
puts(STRING_MINIBOX_TIME_DESCRIPTION);
puts(STRING_MINIBOX_TIME_USAGE);
puts(" MINIBOX time --help|--version");
return 0;
return EXIT_SUCCESS;
}
#endif
#endif
#if VERSION
#if VERSION
if(argc == 3 && !strcmp(argv[2], "--version"))
{
version();
return