Merge branch 'master' of ssh://gapil.gnulinux.it/srv/git/gapil
[gapil.git] / sources / testctime.c
1 /* testctime.c
2  * 
3  * Copyright (C) 2001 Simone Piccardi
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /****************************************************************
20  *
21  * Program test_ctime.c: 
22  * Program to test function ctime
23  *
24  * Author: Simone Piccardi
25  * Oct. 2001
26  *
27  *
28  ****************************************************************/
29 /* 
30  * Include needed headers
31  */
32 #define _GNU_SOURCE
33 #include <errno.h>       /* error definitions and routines */ 
34 #include <stdlib.h>      /* C standard library */
35 #include <unistd.h>      /* unix standard library */
36 #include <stdio.h>       /* standard I/O library */
37 #include <string.h>      /* C strings library */
38 #include <time.h>
39
40 /* Help printing routine */
41 void usage(void);
42
43 int main(int argc, char *argv[])
44 {
45 /* 
46  * Variables definition  
47  */
48     int i;
49     /*
50      * Input section: decode command line parameters 
51      * Use getopt function
52      */
53     opterr = 0;  /* don't want writing to stderr */
54     while ( (i = getopt(argc, argv, "h")) != -1) {
55         switch (i) {
56         /* 
57          * Handling options 
58          */ 
59         case 'h':   /* help option */
60             printf("Wrong -h option use\n");
61             usage();
62             return -1;
63             break;
64         case '?':   /* unrecognized options */
65             printf("Unrecognized options -%c\n",optopt);
66             usage();
67         default:    /* should not reached */
68             usage();
69         }
70     }
71     /* ***********************************************************
72      * 
73      *           Options processing completed
74      *
75      *                Main code beginning
76      * 
77      * ***********************************************************/
78     time_t t;
79     t = time(NULL);
80     printf("%s", ctime(&t));
81     return 0;
82 }
83 /*
84  * routine to print usage info and exit
85  */
86 void usage(void) {
87     printf("Program testctime : test ctime functon \n");
88     printf("Usage:\n");
89     printf("  testctime [-h] \n");
90     printf("  -h           print this help\n");
91     
92     exit(1);
93 }
94