From 130c054fa62bc1f13efc3c22ee393e7e9ecbd197 Mon Sep 17 00:00:00 2001 From: Hydroque Date: Thu, 21 Sep 2017 04:49:05 -0400 Subject: [PATCH] updated README.md (removed Post-Exist for %* for args support, too - so no need as you can just use -p to post exist.. resolves to luaw.exe --- README.md | 12 ++---- src/console.c | 113 ++++++++++++++++++++++++++++++++++++++---------- src/consolew.c | 115 +++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 185 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index a03240d..9a94927 100644 --- a/README.md +++ b/README.md @@ -44,11 +44,10 @@ For example,
# Bonus Put luaw.exe into C:\Windows\System32 and use resource hacker program (3rd party program) to put an icon into your .exe at -1, and enjoy this context menu edit as well as graphics with the .reg script below. Use at your own discression. I can't be held accountable for you breaking your system, as registry is pretty delicate. -- allows to double click to run script files -- right click Post-Exist allows to keep lua console open +- allows to be in the common path - see a cool icon on all your .lua files - get a cool icon on your .exe -- (can add ;.LUA to EXTS env variable so you don't have to type in full name to run the file, eg run.lua > run) +- (can add ;.LUA to EXTS env variable so you don't have to type in full name to run the file, eg "run" instead of "run.lua") ```reg Windows Registry Editor Version 5.00 @@ -63,12 +62,7 @@ Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\Applications\luaw.exe\shell\open] [HKEY_CURRENT_USER\Software\Classes\Applications\luaw.exe\shell\open\command] -@="\"C:\\Windows\\System32\\luaw.exe\" \"%1\"" - -[HKEY_CURRENT_USER\Software\Classes\Applications\luaw.exe\shell\Post-Exist] - -[HKEY_CURRENT_USER\Software\Classes\Applications\luaw.exe\shell\Post-Exist\command] -@="luaw.exe %1 -p" +@="\"C:\\Windows\\System32\\luaw.exe\" \"%1\" %*" [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.lua] diff --git a/src/console.c b/src/console.c index 4a6889f..9d400a2 100644 --- a/src/console.c +++ b/src/console.c @@ -13,15 +13,34 @@ * */ -#if defined(__linux__) || defined(__unix__) -#include -#include -#include +// unsupported feature, defined to prepare for future +#define USE_ADDITIONS + +#define PRIMARY_BUFFER_SIZE (1024 + 1) +#define SECONDARY_BUFFER_SIZE (1032 + 1) + +#define DEFINES_INIT 4 +#define DEFINES_EXPANSION 4 + +#if defined(linux) || defined(__linux__) || defined(__linux) +# include +# include +# include +#elif defined(unix) || defined(__unix__) || defined(__unix) +# include +# include +# include +#elif defined(__APPLE__) || defined(__MACH__) +# include +# include +# include +#elif defined(_WIN32) || defined(_WIN64) +# include +# include +# include +# include #else -#include -#include -#include -#include +# error "Not familiar. Set up headers accordingly, or -D__linux__ or -D__APPLE__ or -D_WIN32" #endif #include @@ -30,13 +49,12 @@ #include "lualib.h" #include "lauxlib.h" -#include "additions.h" - +#if defined(USE_ADDITIONS) +# include "additions.h" +#endif -#define LUA_CONSOLE_COPYRIGHT "LuaConsole Copyright MIT (C) 2017 Hydroque\n" -#define PRIMARY_BUFFER_SIZE 1025 -#define SECONDARY_BUFFER_SIZE 1033 +#define LUA_CONSOLE_COPYRIGHT "LuaConsole Copyright MIT (C) 2017 Hydroque\n" // internal enums, represent lua error category @@ -67,6 +85,7 @@ const char HELP_MESSAGE[] = "-s \t Issues a new root path\n" "-a \t Removes the additions\n" "-c \t No copyright on init\n" + "-d \t Defines a global variable as value after '='\n" "-n \t Start of parameter section\n" "-? \t Displays this help message\n"; @@ -146,15 +165,19 @@ int start_protective_mode(lua_CFunction func, const char* file, char** parameter // handles arguments, cwd, loads necessary data, executes lua int main(int argc, char* argv[]) { - int print_version = 0; - int change_start = 0; - int no_file = 0; - char* start = 0; - int no_additions = 0; - int copyright_squelch = 0; + static int print_version = 0; + static int change_start = 0; + static int no_file = 0; + static char* start = 0; + static int no_additions = 0; + static int copyright_squelch = 0; - size_t parameters = 0; - char** parameters_argv = 0; + static size_t parameters = 0; + static char** parameters_argv = 0; + + static size_t globals = 0; + static size_t globals_argv_len = 0; + static char** globals_argv = 0; // handle arguments if(argc == 1) { // post-exist if !(arguments > 1) @@ -194,8 +217,28 @@ int main(int argc, char* argv[]) case 'c': case 'C': copyright_squelch = 1; break; + case 'd': case 'D': + if(globals_argv == 0) { + globals_argv = malloc(DEFINES_INIT * sizeof(char*)); + if(globals_argv == 0) { + fprintf(stderr, "%s\n", "[1] Out of memory"); + return EXIT_FAILURE; + } + globals_argv_len = DEFINES_INIT; + } + if(globals == globals_argv_len) { + globals_argv_len += DEFINES_EXPANSION; + globals_argv = realloc(globals_argv, (globals_argv_len + DEFINES_EXPANSION) * sizeof(char*)); + if(globals_argv == 0) { + fprintf(stderr, "%s\n", "[1] Out of memory"); + return EXIT_FAILURE; + } + } + globals_argv[globals] = argv[i]; + globals++; + break; case 'n': case 'N': - parameters = argc - i - 1; + parameters = (argc - i) - 1; parameters_argv = &(argv[i+1]); break; case '?': @@ -217,10 +260,34 @@ int main(int argc, char* argv[]) // initiate lua L = luaL_newstate(); if(L == 0) { - fprintf(stderr, "%s\n", "Allocation Failed: Out of Memory"); + fprintf(stderr, "%s\n", "Lua Allocation Failed: Out of Memory"); return EXIT_FAILURE; } + // initiate global variables set up, needs solidifed + if(globals != 0) { + // this is a hack, need to switch to strtok that doesn't modify original string + for (size_t i=0; i -#include -#include +// unsupported feature, defined to prepare for future +#define USE_ADDITIONS + +#define PRIMARY_BUFFER_SIZE (1024 + 1) +#define SECONDARY_BUFFER_SIZE (1032 + 1) + +#define DEFINES_INIT 4 +#define DEFINES_EXPANSION 4 + +#if defined(linux) || defined(__linux__) || defined(__linux) +# include +# include +# include +#elif defined(unix) || defined(__unix__) || defined(__unix) +# include +# include +# include +#elif defined(__APPLE__) || defined(__MACH__) +# include +# include +# include +#elif defined(_WIN32) || defined(_WIN64) +# include +# include +# include +# include #else -#include -#include -#include -#include +# error "Not familiar. Set up headers accordingly, or -D__linux__ or -D__APPLE__ or -D_WIN32" #endif #include @@ -30,13 +49,13 @@ #include "lualib.h" #include "lauxlib.h" -#include "additions.h" +#if defined(USE_ADDITIONS) +# include "additions.h" +#endif -#define LUA_CONSOLE_COPYRIGHT "LuaConsole Copyright MIT (C) 2017 Hydroque\n" +#define LUA_CONSOLE_COPYRIGHT "LuaConsole Copyright MIT (C) 2017 Hydroque\n" -#define PRIMARY_BUFFER_SIZE 1025 -#define SECONDARY_BUFFER_SIZE 1033 // internal enums, represent lua error category typedef enum LuaConsoleError { @@ -68,6 +87,7 @@ const char HELP_MESSAGE[] = "-p \t Has console post exist after script in line by line mode\n" "-a \t Removes the additions\n" "-c \t No copyright on init\n" + "-d \t Defines a global variable as value after '='\n" "-n \t Start of parameter section\n" "-? \t Displays this help message\n"; @@ -225,17 +245,20 @@ int start_protective_mode(lua_CFunction func, const char* file, char** parameter // handles arguments, cwd, loads necessary data, executes lua int main(int argc, char* argv[]) { - int print_version = 0; - int change_start = 0; - int post_exist = 0; - int no_file = 0; - char* start = 0; - int no_additions = 0; - int copyright_squelch = 0; + static int print_version = 0; + static int change_start = 0; + static int post_exist = 0; + static int no_file = 0; + static char* start = 0; + static int no_additions = 0; + static int copyright_squelch = 0; - size_t parameters = 0; - char** parameters_argv = 0; + static size_t parameters = 0; + static char** parameters_argv = 0; + static size_t globals = 0; + static size_t globals_argv_len = 0; + static char** globals_argv = 0; // handle arguments if(argc == 1) { // post-exist if !(arguments > 1) @@ -279,8 +302,28 @@ int main(int argc, char* argv[]) case 'c': case 'C': copyright_squelch = 1; break; + case 'd': case 'D': + if(globals_argv == 0) { + globals_argv = malloc(DEFINES_INIT * sizeof(char*)); + if(globals_argv == 0) { + fprintf(stderr, "%s\n", "[1] Out of memory"); + return EXIT_FAILURE; + } + globals_argv_len = DEFINES_INIT; + } + if(globals == globals_argv_len) { + globals_argv_len += DEFINES_EXPANSION; + globals_argv = realloc(globals_argv, (globals_argv_len + DEFINES_EXPANSION) * sizeof(char*)); + if(globals_argv == 0) { + fprintf(stderr, "%s\n", "[1] Out of memory"); + return EXIT_FAILURE; + } + } + globals_argv[globals] = argv[i]; + globals++; + break; case 'n': case 'N': - parameters = argc - i - 1; + parameters = (argc - i) - 1; parameters_argv = &(argv[i+1]); break; case '?': @@ -302,10 +345,34 @@ int main(int argc, char* argv[]) // initiate lua L = luaL_newstate(); if(L == 0) { - fprintf(stderr, "%s\n", "Allocation Failed: Out of Memory"); + fprintf(stderr, "%s\n", "Lua Allocation Failed: Out of Memory"); return EXIT_FAILURE; } + // initiate global variables set up, needs solidifed + if(globals != 0) { + // this is a hack, need to switch to strtok that doesn't modify original string + for (size_t i=0; i