1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include "clog.h"
// ⚠ This might make a mess, i.e., make it harder to call the real GCC. We'll see...
#define _strings_match(s1, s2) (strcmp((s1), (s2)) == 0)
int main(int argc, const char* argv[]) {
// Assume that the command is always called as:
// gcc -o «executable» «▒▒▒.c»
// This won't be perfect at first. We will walk through some pitfalls.
//
// THIS IS BUGGY (SO FAR)
const char* this_executable = argv[0];
if(argc != 4) { // because our specification is very narrow for this
fprintf(stderr, "%s: Need exactly 3 arguments\n", this_executable);
exit(EXIT_FAILURE);
}
else {
const char* flag = argv[1];
const char* executable_path = argv[2];
const char* c_path = argv[3];
if(!_strings_match(flag, "-o")) {
fprintf(stderr, "%s: First argument must be \"-o\"\n", this_executable);
exit(EXIT_FAILURE);
}
if(strlen(executable_path) == 0) {
fprintf(stderr, "%s: Second argument must not be blank.\n", this_executable);
exit(EXIT_FAILURE);
}
// Make sure the .c file ends with .c
if(c_path[strlen(c_path) -2] != '.' || c_path[strlen(c_path) - 1] != 'c') {
fprintf(stderr, "%s: Third argument must end with .c\n", this_executable);
exit(EXIT_FAILURE);
}
printf("# TODO: Compile %s to create executable %s.\n", argv[3], argv[2]);
}
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2020 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.