Uploading broken stuff...
This commit is contained in:
parent
a5a5f45338
commit
698348d2e2
9
compile.sh
Normal file
9
compile.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
gcc -g -ansi -Wall -Wextra -Wpedantic -o xd xd.c
|
||||
clang -g -ansi -Weverything -o xd xd.c
|
||||
valgrind --show-leak-kinds=all --leak-check=full --log-file=log.txt ./xd
|
||||
|
||||
exit
|
7
install.sh
Normal file
7
install.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
sudo cp xd /usr/bin/xd
|
||||
|
||||
exit
|
155
xd.c
Normal file
155
xd.c
Normal file
@ -0,0 +1,155 @@
|
||||
#include <xolatile/xyntax.h>
|
||||
#include <xolatile/xyntax.c>
|
||||
#include <xolatile/xurses.h>
|
||||
#include <xolatile/xurses.c>
|
||||
|
||||
static int active = 1;
|
||||
static char prompt [144] = "";
|
||||
|
||||
static int command_count = 0;
|
||||
static int * command_copy = NULL;
|
||||
static char * * command_nick = NULL;
|
||||
static char * * command_name = NULL;
|
||||
static char * command_argument = NULL;
|
||||
static void (* * command_function) (void) = NULL;
|
||||
|
||||
static void command_define (int copy, char * nick, char * name, void (* function) (void)) {
|
||||
command_copy = reallocate (command_copy, (command_count + 1) * (int) sizeof (* command_copy));
|
||||
command_nick = reallocate (command_nick, (command_count + 1) * (int) sizeof (* command_nick));
|
||||
command_name = reallocate (command_name, (command_count + 1) * (int) sizeof (* command_name));
|
||||
command_function = reallocate (command_function, (command_count + 1) * (int) sizeof (* command_function));
|
||||
|
||||
command_copy [command_count] = copy;
|
||||
command_function [command_count] = function;
|
||||
|
||||
command_nick [command_count] = allocate (string_length (nick) + 1);
|
||||
command_name [command_count] = allocate (string_length (name) + 1);
|
||||
|
||||
string_copy (command_nick [command_count], nick);
|
||||
string_copy (command_name [command_count], name);
|
||||
|
||||
++command_count;
|
||||
}
|
||||
|
||||
static void echo_help (void) {
|
||||
echo ("-h --help | Print help information to standard output.\n");
|
||||
echo ("-v --version | Print version information to standard output.\n");
|
||||
echo ("-l --license | Print license information to standard output.\n");
|
||||
}
|
||||
|
||||
static void echo_version (void) {
|
||||
echo ("xd : Non-standard text editor (v6.6.6)\n");
|
||||
}
|
||||
|
||||
static void echo_license (void) {
|
||||
echo ("xd : Non-standard text editor (GNU/GPLv3)\n");
|
||||
}
|
||||
|
||||
static void quit (void) {
|
||||
active = 0;
|
||||
}
|
||||
|
||||
static void echoes (void) {
|
||||
int offset = 0;
|
||||
int index = 0;
|
||||
int length = 0;
|
||||
|
||||
if (file_list_active >= file_list_count) {
|
||||
echo ("Unknown active file (out of range)...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_list_data [file_list_active] == NULL) {
|
||||
echo ("Null pointer for file data...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (offset = 0; file_list_data [file_list_active] [offset] != '\0'; offset += length) {
|
||||
syntax_select (& file_list_data [file_list_active] [offset], & index, & length);
|
||||
|
||||
if (index >= syntax_count) {
|
||||
curses_style (EFFECT_NORMAL, COLOUR_WHITE);
|
||||
} else {
|
||||
curses_style (syntax_effect [index], syntax_colour [index]);
|
||||
}
|
||||
|
||||
out (& file_list_data [file_list_active] [offset], length);
|
||||
|
||||
curses_style (-1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
static void import (void) {
|
||||
echo ("Importing file \"");
|
||||
echo (command_argument);
|
||||
echo ("\"...\n");
|
||||
|
||||
file_list_import (command_argument);
|
||||
}
|
||||
|
||||
int main (int argc, char * * argv) {
|
||||
int command_index;
|
||||
|
||||
argument_define ("-h", "--help", echo_help);
|
||||
argument_define ("-v", "--version", echo_version);
|
||||
argument_define ("-l", "--license", echo_license);
|
||||
|
||||
argument_select (argc, argv);
|
||||
|
||||
command_define (0, "q", "quit", quit);
|
||||
command_define (0, "e", "echo", echoes);
|
||||
command_define (1, "o", "open", import);
|
||||
|
||||
do {
|
||||
int index;
|
||||
|
||||
command_index = -1;
|
||||
|
||||
string_delete (prompt, (int) sizeof (prompt));
|
||||
|
||||
in (prompt, (int) sizeof (prompt));
|
||||
|
||||
if (prompt [0] == '`') {
|
||||
echo ("Executing shell command (this is so fucking unsafe I'm almost ashamed)...\n");
|
||||
(void) system (& prompt [1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
(void) string_split_space (prompt);
|
||||
|
||||
for (index = 0; index != command_count; ++index) {
|
||||
/*if ((string_compare_limit (prompt, command_nick [index], string_length (command_nick [index])) != 0)
|
||||
|| (string_compare_limit (prompt, command_name [index], string_length (command_name [index])) != 0)) {*/
|
||||
if ((string_compare (prompt, command_nick [index]) != 0)
|
||||
|| (string_compare (prompt, command_name [index]) != 0)) {
|
||||
command_index = index;
|
||||
}
|
||||
}
|
||||
|
||||
if (command_copy [command_index] != 0) {
|
||||
command_argument = & prompt [string_length (prompt) + 1];
|
||||
}
|
||||
|
||||
if (command_index != -1) {
|
||||
command_function [command_index] ();
|
||||
} else {
|
||||
echo ("Unknown command!\n");
|
||||
}
|
||||
} while (active != 0);
|
||||
|
||||
file_list_delete ();
|
||||
|
||||
for (command_index = 0; command_index != command_count; ++command_index) {
|
||||
command_nick [command_index] = deallocate (command_nick [command_index]);
|
||||
command_name [command_index] = deallocate (command_name [command_index]);
|
||||
}
|
||||
|
||||
command_copy = deallocate (command_copy);
|
||||
command_nick = deallocate (command_nick);
|
||||
command_name = deallocate (command_name);
|
||||
command_function = deallocate (command_function);
|
||||
|
||||
argument_delete ();
|
||||
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
Loading…
Reference in New Issue
Block a user