diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f163558 --- /dev/null +++ b/src/main.c @@ -0,0 +1,92 @@ +/* Aplwc - A Programming Language With Constraints + * + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <stdio.h> +#include <stdlib.h> +#include <getopt.h> +#include <aplwc.h> +#include "nls.h" +#include "syscmd.h" +#include "readline.h" + +static struct option long_options[] = { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'v'}, + {NULL, 0, NULL, 0} +}; + +static void version(void); +static void help(int); + +int +main(int argc, char *argv[]) +{ + init_nls(); + + int opt; + while((opt = getopt_long(argc, argv, "hv", long_options, NULL)) != -1){ + switch(opt){ + case 'h': + help(EXIT_SUCCESS); + break; + case 'v': + version(); + break; + default: + help(EXIT_FAILURE); + break; + } + } + + struct aplwc *aplwc = aplwc_new(); + init_syscmds(aplwc); + init_readline(aplwc); + + char *line; + while(line = readline(" ")){ + if(strlen(line) == 0) + continue; + add_history(line); + printf(_("You typed: %s\n"), line); + free(line); + } + printf(_("bye\n")); +} + +static void +version(void) +{ + printf("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION); + printf(_("Copyright (C) 2026 Peter Mikkelsen\n")); + printf(_("License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n" + "This is free software: you are free to change and redistribute it.\n" + "There is NO WARRANTY, to the extent permitted by law.\n")); + exit(EXIT_SUCCESS); +} + +static void +help(int status) +{ + printf(_("Usage: %s [OPTION...]\n\n"), PACKAGE_NAME); + printf(_(" -h, --help display this help and exit\n")); + printf(_(" -v, --version display version information and exit\n")); + exit(status); +} |