summaryrefslogtreecommitdiff
path: root/src/helloworld.c
blob: 396f30097dcbf2541d58fbe942071ede7400f243 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Hello World Recipe
 *
 * Copyright (C) 2010 by Multi-Tech Systems
 *
 * Author: James Maki <jmaki@multitech.com>
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <time.h>

#include "helloworld.h"

static void print_version(const char *name) {
	printf("%s (" PACKAGE ") " VERSION " (" __DATE__ " " __TIME__ ")\n", name);
	printf("Copyright (C) 2010 by Multi-Tech Systems\n");
	printf(
"This program is free software; you may redistribute it under the terms of\n"
"the GNU General Public License version 2 or (at your option) any later version.\n"
"This program has absolutely no warranty.\n");
}

static void usage(FILE *out) {
	fprintf(out, "Usage: helloworld [ <things> ]\n");
	fprintf(out, "\n");
}

enum {
	OPT_VERSION = 128,
	OPT_HELP,
};

static char *short_options = "";
static struct option long_options[] = {
	{"version", 0, NULL, OPT_VERSION},
	{"help", 0, NULL, OPT_HELP},
	{0, 0, 0, 0},
};

int main(int argc, char *argv[]) {
	int i;
	int option_index;

	while((i = getopt_long(argc, argv, short_options, long_options, &option_index)) >= 0) {
		switch(i) {
		case 0:
			break;

		case OPT_VERSION:
			print_version("helloworld");
			exit(0);
			break;

		case OPT_HELP:
			usage(stdout);
			exit(0);
			break;

		default:
			usage(stderr);
			exit(1);
		}
	}

	if(optind < argc) {
		while(optind < argc) {
			printf("Hello %s!\n", argv[optind++]);
		}
	} else {
		printf("Hello Autotools!\n");
	}

	return 0;
}