Skip to content

Commit

Permalink
Make leading whitespace consistent in C sources
Browse files Browse the repository at this point in the history
Four spaces, two spaces, tabs... let's go with four spaces, since
that's what the Kotlin code does (because that's IntelliJ's default).
  • Loading branch information
ctrueden committed Feb 10, 2024
1 parent a43ff05 commit 6d814ff
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 92 deletions.
40 changes: 20 additions & 20 deletions src/c/jaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ static int launch_jvm(
//
// The trailing slashes make the math simpler in the path function logic.
const char *JAUNCH_SEARCH_PATHS[] = {
"jaunch"SLASH,
".jaunch"SLASH,
"config"SLASH"jaunch"SLASH,
".config"SLASH"jaunch"SLASH,
"Contents"SLASH"MacOS"SLASH,
NULL,
"jaunch"SLASH,
".jaunch"SLASH,
"config"SLASH"jaunch"SLASH,
".config"SLASH"jaunch"SLASH,
"Contents"SLASH"MacOS"SLASH,
NULL,
};

/* result=$(dirname "$argv0")/$subdir$command */
Expand Down Expand Up @@ -203,20 +203,20 @@ int main(const int argc, const char *argv[]) {
char *command = NULL;
size_t search_path_count = sizeof(JAUNCH_SEARCH_PATHS) / sizeof(char *);
for (size_t i = 0; i < search_path_count; i++) {
// First, look for jaunch configurator with a `-<os>-<arch>` suffix.
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], "jaunch-" OS_NAME "-" OS_ARCH EXE_SUFFIX);
if (file_exists(command)) break;
else debug("[JAUNCH] No configurator at %s", command);

// If not found, look for plain jaunch configurator with no suffix.
free(command);
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], "jaunch" EXE_SUFFIX);
if (file_exists(command)) break;
else debug("[JAUNCH] No configurator at %s", command);

// Nothing at this search path; clean up and move on to the next one.
free(command);
command = NULL;
// First, look for jaunch configurator with a `-<os>-<arch>` suffix.
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], "jaunch-" OS_NAME "-" OS_ARCH EXE_SUFFIX);
if (file_exists(command)) break;
else debug("[JAUNCH] No configurator at %s", command);

// If not found, look for plain jaunch configurator with no suffix.
free(command);
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], "jaunch" EXE_SUFFIX);
if (file_exists(command)) break;
else debug("[JAUNCH] No configurator at %s", command);

// Nothing at this search path; clean up and move on to the next one.
free(command);
command = NULL;
}
if (command == NULL) {
error("Failed to locate the jaunch configurator program.");
Expand Down
10 changes: 5 additions & 5 deletions src/c/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#define OS_NAME "linux"

int startup_jvm(
const char *libjvm_path, const size_t jvm_argc, const char *jvm_argv[],
const char *main_class_name, const size_t main_argc, const char *main_argv[])
const char *libjvm_path, const size_t jvm_argc, const char *jvm_argv[],
const char *main_class_name, const size_t main_argc, const char *main_argv[])
{
return launch_jvm(
libjvm_path, jvm_argc, jvm_argv,
main_class_name, main_argc, main_argv);
return launch_jvm(
libjvm_path, jvm_argc, jvm_argv,
main_class_name, main_argc, main_argv);
}

int isCommandAvailable(const char *command) {
Expand Down
102 changes: 51 additions & 51 deletions src/c/macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,76 @@
#define OS_NAME "macos"

void show_alert(const char *title, const char *message) {
/* TODO: Get this objc code working.
// Create an NSString from the C string
id nsMessage = objc_msgSend((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), message);
/* TODO: Get this objc code working.
// Create an NSString from the C string
id nsMessage = objc_msgSend((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), message);
// Create an NSAlert
id alert = objc_msgSend((id)objc_getClass("NSAlert"), sel_registerName("alloc"));
objc_msgSend(alert, sel_registerName("init"));
objc_msgSend(alert, sel_registerName("setMessageText:"), nsMessage);
// Create an NSAlert
id alert = objc_msgSend((id)objc_getClass("NSAlert"), sel_registerName("alloc"));
objc_msgSend(alert, sel_registerName("init"));
objc_msgSend(alert, sel_registerName("setMessageText:"), nsMessage);
// Run the alert modal
objc_msgSend(alert, sel_registerName("runModal"));
*/
// Run the alert modal
objc_msgSend(alert, sel_registerName("runModal"));
*/
}

struct JVMConfiguration {
const char *libjvm_path;
size_t jvm_argc;
const char **jvm_argv;
const char *main_class_name;
size_t main_argc;
const char **main_argv;
const char *libjvm_path;
size_t jvm_argc;
const char **jvm_argv;
const char *main_class_name;
size_t main_argc;
const char **main_argv;
};

static struct JVMConfiguration config = {
.libjvm_path = NULL,
.jvm_argc = 0,
.jvm_argv = NULL,
.main_class_name = NULL,
.main_argc = 0,
.main_argv = NULL
.libjvm_path = NULL,
.jvm_argc = 0,
.jvm_argv = NULL,
.main_class_name = NULL,
.main_argc = 0,
.main_argv = NULL
};

static void dummy_call_back(void *info) { }

static void *startup_jvm_macos(void *dummy) {
exit(launch_jvm(
config.libjvm_path, config.jvm_argc, config.jvm_argv,
config.main_class_name, config.main_argc, config.main_argv
));
exit(launch_jvm(
config.libjvm_path, config.jvm_argc, config.jvm_argv,
config.main_class_name, config.main_argc, config.main_argv
));
}

int startup_jvm(
const char *libjvm_path, const size_t jvm_argc, const char *jvm_argv[],
const char *main_class_name, const size_t main_argc, const char *main_argv[])
const char *libjvm_path, const size_t jvm_argc, const char *jvm_argv[],
const char *main_class_name, const size_t main_argc, const char *main_argv[])
{
// Save arguments into global struct, for later retrieval.
config.libjvm_path = libjvm_path;
config.jvm_argc = jvm_argc;
config.jvm_argv = jvm_argv;
config.main_class_name = main_class_name;
config.main_argc = main_argc;
config.main_argv = main_argv;
// Save arguments into global struct, for later retrieval.
config.libjvm_path = libjvm_path;
config.jvm_argc = jvm_argc;
config.jvm_argv = jvm_argv;
config.main_class_name = main_class_name;
config.main_argc = main_argc;
config.main_argv = main_argv;

// Start the JVM on a dedicated thread.
pthread_t thread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&thread, &attr, startup_jvm_macos, NULL);
pthread_attr_destroy(&attr);
// Start the JVM on a dedicated thread.
pthread_t thread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&thread, &attr, startup_jvm_macos, NULL);
pthread_attr_destroy(&attr);

// Run the AppKit event loop here on the main thread.
CFRunLoopSourceContext context;
memset(&context, 0, sizeof(context));
context.perform = &dummy_call_back;
// Run the AppKit event loop here on the main thread.
CFRunLoopSourceContext context;
memset(&context, 0, sizeof(context));
context.perform = &dummy_call_back;

CFRunLoopSourceRef ref = CFRunLoopSourceCreate(NULL, 0, &context);
CFRunLoopAddSource (CFRunLoopGetCurrent(), ref, kCFRunLoopCommonModes);
CFRunLoopRun();
CFRunLoopSourceRef ref = CFRunLoopSourceCreate(NULL, 0, &context);
CFRunLoopAddSource (CFRunLoopGetCurrent(), ref, kCFRunLoopCommonModes);
CFRunLoopRun();

return 0;
return 0;
}
32 changes: 16 additions & 16 deletions src/c/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void writeLine(HANDLE stdinWrite, const char *input) {
}

int file_exists(const char *path) {
return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES;
return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES;
}

int run_command(const char *command,
Expand Down Expand Up @@ -65,14 +65,14 @@ int run_command(const char *command,
// from the stdin stream. We do this to avoid issues with quoting.
char *commandPlusDash = malloc(strlen(command) + 3);
if (commandPlusDash == NULL) {
error("Failed to allocate memory (command plus dash)");
return ERROR_MALLOC;
error("Failed to allocate memory (command plus dash)");
return ERROR_MALLOC;
}
strcpy(commandPlusDash, command);
strcat(commandPlusDash, " -");
if (!CreateProcess(NULL, (LPSTR)commandPlusDash, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
free(commandPlusDash);
handleError("Error creating process");
free(commandPlusDash);
handleError("Error creating process");
}
free(commandPlusDash);

Expand All @@ -87,8 +87,8 @@ int run_command(const char *command,
// those lines, even though the pipe is not yet closed. This avoids deadlocks.
char *numInputString = (char *)malloc(21);
if (numInputString == NULL) {
error("Failed to allocate memory (input line count)");
return ERROR_MALLOC;
error("Failed to allocate memory (input line count)");
return ERROR_MALLOC;
}
snprintf(numInputString, 21, "%zu", numInput);
writeLine(stdinWrite, numInputString);
Expand All @@ -108,17 +108,17 @@ int run_command(const char *command,
char *outputBuffer = malloc(bufferSize);

if (outputBuffer == NULL) {
error("Failed to allocate memory (output buffer)");
return ERROR_MALLOC;
error("Failed to allocate memory (output buffer)");
return ERROR_MALLOC;
}

while (ReadFile(stdoutRead, buffer, sizeof(buffer), &bytesRead, NULL) && bytesRead > 0) {
if (totalBytesRead + bytesRead > bufferSize) {
bufferSize *= 2;
outputBuffer = realloc(outputBuffer, bufferSize);
if (outputBuffer == NULL) {
error("Failed to reallocate memory (output buffer)");
return ERROR_REALLOC;
error("Failed to reallocate memory (output buffer)");
return ERROR_REALLOC;
}
}
memcpy(outputBuffer + totalBytesRead, buffer, bytesRead);
Expand All @@ -141,12 +141,12 @@ int run_command(const char *command,
}

int startup_jvm(
const char *libjvm_path, const size_t jvm_argc, const char *jvm_argv,
const char *main_class_name, const size_t main_argc, const char *main_argv)
const char *libjvm_path, const size_t jvm_argc, const char *jvm_argv,
const char *main_class_name, const size_t main_argc, const char *main_argv)
{
return launch_jvm(
libjvm_path, jvm_argc, jvm_argv[],
main_class_name, main_argc, main_argv[]);
return launch_jvm(
libjvm_path, jvm_argc, jvm_argv[],
main_class_name, main_argc, main_argv[]);
}

void show_alert(const char *title, const char *message) {
Expand Down

0 comments on commit 6d814ff

Please sign in to comment.