ln: Added ln
[mutos-utils.git] / echo.c
blobbc23a7a139e7b6098fb2723e5669c600a3a5acd0
1 /*
2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdbool.h>
19 #define VERSION "0.01"
21 struct {
22 bool newline;
23 } flags;
25 int main(int argc, char* argv[])
27 flags.newline = false;
29 // flag parsing
30 int arg = 0;
31 for (arg = 1; arg < argc; arg++)
33 if (strcmp("-n", argv[arg]) == 0) {
34 flags.newline = true;
35 } else if (strcmp("--help", argv[arg]) == 0 || strcmp("-h", argv[arg]) == 0) {
36 printf("Usage: %s [options] [string ...]\n", argv[0]);
37 printf("\n"
38 " -n Don't print the trailing newline.\n"
39 "\n"
40 " --help Print this message.\n"
41 " --version Show version info.\n");
42 return 0;
43 } else if (strcmp("--version", argv[arg]) == 0 || strcmp("-v", argv[arg]) == 0) {
44 printf("echo (mutos) v"VERSION"\n");
45 return 0;
46 } else if (strcmp("--", argv[arg]) == 0) {
47 arg++;
48 break;
49 } else {
50 // no more flags
51 break;
55 for ( ; arg < argc; arg++)
57 printf("%s%s", argv[arg], arg != argc - 1 ? " " : (flags.newline ? "" : "\n"));
60 return 0;