From a60344e9bb9d9067f589f38fd8fea010ed352149 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Sat, 19 Mar 2022 18:14:59 +0000 Subject: [PATCH] building: moved line-count into start.script --- apps/script_console.cpp | 1 + .../{Hack License.md => Hack License.txt} | 0 util/build.c | 62 ------------------- util/script.c | 10 +++ util/start.script | 62 +++++++++++++++++-- 5 files changed, 69 insertions(+), 66 deletions(-) rename res/Fonts/{Hack License.md => Hack License.txt} (100%) diff --git a/apps/script_console.cpp b/apps/script_console.cpp index 699f0d2..353f68a 100644 --- a/apps/script_console.cpp +++ b/apps/script_console.cpp @@ -470,6 +470,7 @@ EXTERNAL_STUB(ExternalPersistWrite); // TODO Functions only available in the POSIX subsystem: EXTERNAL_STUB(ExternalConsoleGetLine); EXTERNAL_STUB(ExternalConsoleWriteStdout); +EXTERNAL_STUB(ExternalConsoleWriteStderr); EXTERNAL_STUB(ExternalSystemShellExecute); EXTERNAL_STUB(ExternalSystemShellExecuteWithWorkingDirectory); EXTERNAL_STUB(ExternalSystemShellEvaluate); diff --git a/res/Fonts/Hack License.md b/res/Fonts/Hack License.txt similarity index 100% rename from res/Fonts/Hack License.md rename to res/Fonts/Hack License.txt diff --git a/util/build.c b/util/build.c index 0f1e694..40e1f76 100644 --- a/util/build.c +++ b/util/build.c @@ -859,30 +859,6 @@ void FixReplacedFieldName(const char *oldName, const char *newName) { CallSystem("unlink bin/errors.tmp"); } -void LineCountFile(const char *folder, const char *name) { - int lineCountBefore = 0; - - { - CallSystem("paste -sd+ bin/count.tmp | bc > bin/count2.tmp"); - FILE *f = fopen("bin/count2.tmp", "rb"); - char buffer[16] = {}; - fread(buffer, 1, sizeof(buffer), f); - fclose(f); - lineCountBefore = atoi(buffer); - } - - CallSystemF("awk 'NF' \"%s%s\" | wc -l >> bin/count.tmp", folder, name); - - { - CallSystem("paste -sd+ bin/count.tmp | bc > bin/count2.tmp"); - FILE *f = fopen("bin/count2.tmp", "rb"); - char buffer[16] = {}; - fread(buffer, 1, sizeof(buffer), f); - fclose(f); - printf("%5d %s%s\n", atoi(buffer) - lineCountBefore, folder, name); - } -} - void AddressToLine(const char *symbolFile) { char buffer[4096]; sprintf(buffer, "echo %s > bin/all_symbol_files.dat", symbolFile); @@ -1359,44 +1335,6 @@ void DoCommand(const char *l) { } printf("Created " ColorHighlight "bin/essence.iso" ColorNormal ".\n"); - } else if (0 == strcmp(l, "line-count")) { - FILE *f = fopen("bin/count.tmp", "wb"); - fprintf(f, "0"); - fclose(f); - - LineCountFile("", "start.sh"); - - const char *folders[] = { - "desktop/", "boot/x86/", "drivers/", "kernel/", - "apps/", "apps/file_manager/", "shared/", "util/", - "arch/", "arch/x86_32/", "arch/x86_64/", - }; - - for (uintptr_t i = 0; i < sizeof(folders) / sizeof(folders[0]); i++) { - const char *folder = folders[i]; - DIR *directory = opendir(folder); - struct dirent *entry; - - while ((entry = readdir(directory))) { - if (0 == strcmp(entry->d_name, "nanosvg.h")) continue; - if (0 == strcmp(entry->d_name, "hsluv.h")) continue; - if (0 == strcmp(entry->d_name, "stb_ds.h")) continue; - if (0 == strcmp(entry->d_name, "stb_image.h")) continue; - if (0 == strcmp(entry->d_name, "stb_sprintf.h")) continue; - if (0 == strcmp(entry->d_name, "stb_truetype.h")) continue; - if (entry->d_type != DT_REG) continue; - - LineCountFile(folder, entry->d_name); - } - - closedir(directory); - } - - printf("\nTotal line count:" ColorHighlight "\n"); - CallSystem("paste -sd+ bin/count.tmp | bc"); - unlink("bin/count.tmp"); - unlink("bin/count2.tmp"); - printf(ColorNormal); } else if (0 == memcmp(l, "a2l ", 4)) { AddressToLine(l + 3); } else if (0 == strcmp(l, "build-port") || 0 == memcmp(l, "build-port ", 11)) { diff --git a/util/script.c b/util/script.c index 388d14f..2cd45fa 100644 --- a/util/script.c +++ b/util/script.c @@ -771,6 +771,7 @@ char baseModuleSource[] = { "str ConsoleGetLine() #extcall;" "void ConsoleWriteStdout(str x) #extcall;" + "void ConsoleWriteStderr(str x) #extcall;" "err[str] SystemGetEnvironmentVariable(str name) #extcall;" "err[void] SystemSetEnvironmentVariable(str name, str value) #extcall;" "bool SystemShellExecute(str x) #extcall;" // Returns true on success. @@ -791,6 +792,7 @@ int ExternalTextMonospaced(ExecutionContext *context, Value *returnValue); int ExternalTextPlain(ExecutionContext *context, Value *returnValue); int ExternalConsoleGetLine(ExecutionContext *context, Value *returnValue); int ExternalConsoleWriteStdout(ExecutionContext *context, Value *returnValue); +int ExternalConsoleWriteStderr(ExecutionContext *context, Value *returnValue); int ExternalStringSlice(ExecutionContext *context, Value *returnValue); int ExternalCharacterToByte(ExecutionContext *context, Value *returnValue); int ExternalSystemShellExecute(ExecutionContext *context, Value *returnValue); @@ -836,6 +838,7 @@ ExternalFunction externalFunctions[] = { { .cName = "TextPlain", .callback = ExternalTextPlain }, { .cName = "ConsoleGetLine", .callback = ExternalConsoleGetLine }, { .cName = "ConsoleWriteStdout", .callback = ExternalConsoleWriteStdout }, + { .cName = "ConsoleWriteStderr", .callback = ExternalConsoleWriteStderr }, { .cName = "StringSlice", .callback = ExternalStringSlice }, { .cName = "CharacterToByte", .callback = ExternalCharacterToByte }, { .cName = "SystemShellExecute", .callback = ExternalSystemShellExecute }, @@ -7069,6 +7072,13 @@ int ExternalConsoleWriteStdout(ExecutionContext *context, Value *returnValue) { return EXTCALL_NO_RETURN; } +int ExternalConsoleWriteStderr(ExecutionContext *context, Value *returnValue) { + (void) returnValue; + STACK_POP_STRING(entryText, entryBytes); + fprintf(stderr, "%.*s", (int) entryBytes, (char *) entryText); + return EXTCALL_NO_RETURN; +} + int ExternalLogOpenGroup(ExecutionContext *context, Value *returnValue) { (void) returnValue; if (context->c->stackPointer < 1) return -1; diff --git a/util/start.script b/util/start.script index 4d14a4b..273677d 100644 --- a/util/start.script +++ b/util/start.script @@ -108,6 +108,60 @@ void Setup(bool forAutomation) { } } +void DoCommand(str command) { + if command == "line-count" { + int count = 0; + int countKernel = 0; + int countDesktop = 0; + int countApps = 0; + int countBoot = 0; + int countDrivers = 0; + int countHelp = 0; + int countShared = 0; + int countArch = 0; + int countOther = 0; + + str[] files = DirectoryEnumerateRecursively("."):assert(); + + for str file in files { + bool ignore = file == "tags" || StringStartsWith(file, "bin/") || StringStartsWith(file, "cross/") || StringStartsWith(file, ".") + || StringStartsWith(file, "old/") || StringStartsWith(file, "root/") || StringStartsWith(file, "ports/") + || file == "util/hsluv.h" || file == "util/luigi.h" || file == "util/stb_ds.h" || file == "util/script.c" + || file == "util/nanosvg.h" || file == "util/stb_truetype.h" || file == "res/Keyboard Layouts/index.ini"; + bool isSourceFile = StringEndsWith(file, ".c") || StringEndsWith(file, ".cpp") || StringEndsWith(file, ".h") + || StringEndsWith(file, ".header") || StringEndsWith(file, ".ini") || StringEndsWith(file, ".ld") + || StringEndsWith(file, ".md") || StringEndsWith(file, ".s") || StringEndsWith(file, ".script") || StringEndsWith(file, ".sh"); + + if !ignore && isSourceFile { + int c = StringSplitByCharacter(FileReadAll(file):assert(), "\n", false):len(); + count += c; + if StringStartsWith(file, "kernel/") countKernel += c; + else if StringStartsWith(file, "desktop/") countDesktop += c; + else if StringStartsWith(file, "apps/") countApps += c; + else if StringStartsWith(file, "boot/") countBoot += c; + else if StringStartsWith(file, "drivers/") countDrivers += c; + else if StringStartsWith(file, "help/") countHelp += c; + else if StringStartsWith(file, "shared/") countShared += c; + else if StringStartsWith(file, "arch/") countArch += c; + else countOther += c; + } + } + + Log("Total line count: %TextColorHighlight()%%count%"); + Log("- Kernel: %TextColorHighlight()%%countKernel%"); + Log("- Desktop: %TextColorHighlight()%%countDesktop%"); + Log("- Apps: %TextColorHighlight()%%countApps%"); + Log("- Boot: %TextColorHighlight()%%countBoot%"); + Log("- Drivers: %TextColorHighlight()%%countDrivers%"); + Log("- Help: %TextColorHighlight()%%countHelp%"); + Log("- Shared: %TextColorHighlight()%%countShared%"); + Log("- Arch: %TextColorHighlight()%%countArch%"); + Log("- Other: %TextColorHighlight()%%countOther%"); + } else { + SystemShellExecute("bin/build %command%"); + } +} + void Start() { Setup(false); PathDelete("bin/dependencies.ini"); @@ -121,9 +175,9 @@ void Start() { bool running = true; while running { - ConsoleWriteStdout("\n> %TextColorHighlight()%"); + ConsoleWriteStderr("\n> %TextColorHighlight()%"); str command = StringTrim(ConsoleGetLine()); - ConsoleWriteStdout(TextPlain()); + ConsoleWriteStderr(TextPlain()); if command == "" { command = previousCommand; @@ -133,12 +187,12 @@ void Start() { if command == "exit" || command == "x" || command == "quit" || command == "q" { running = false; } else { - SystemShellExecute("bin/build %command%"); + DoCommand(command); previousCommand = command; } } } else { - SystemShellExecute("bin/build %options%"); + DoCommand(options); } }