Vari programmi di test.
[gapil.git] / sources / TestRen.c
1 /* TestRen.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 TestRen.c: 
22  * Program to test function rename
23  *
24  * Author: Simone Piccardi
25  * Oct. 2001
26  *
27  * Usage: testrem -h give all info's
28  *
29  * $Id: TestRen.c,v 1.1 2002/01/03 23:44:14 piccardi Exp $
30  *
31  ****************************************************************/
32 /* 
33  * Include needed headers
34  */
35 #include <errno.h>       /* error definitions and routines */ 
36 #include <stdlib.h>      /* C standard library */
37 #include <unistd.h>      /* unix standard library */
38 #include <stdio.h>       /* standard I/O library */
39 #include <string.h>      /* string functions */
40
41 /* Help printing routine */
42 void usage(void);
43
44 int main(int argc, char *argv[])
45 {
46 /* 
47  * Variables definition  
48  */
49     int i;
50     /*
51      * Input section: decode command line parameters 
52      * Use getopt function
53      */
54     opterr = 0;  /* don't want writing to stderr */
55     while ( (i = getopt(argc, argv, "h")) != -1) {
56         switch (i) {
57         /* 
58          * Handling options 
59          */ 
60         case 'h':   /* help option */
61             printf("Wrong -h option use\n");
62             usage();
63             return -1;
64             break;
65         case '?':   /* unrecognized options */
66             printf("Unrecognized options -%c\n",optopt);
67             usage();
68         default:    /* should not reached */
69             usage();
70         }
71     }
72     /* ***********************************************************
73      * 
74      *           Options processing completed
75      *
76      *                Main code beginning
77      * 
78      * ***********************************************************/
79     /* There must be 2 remaing parameters */
80     if ( (argc-optind) != 2 )  {
81         printf("From %d arguments, removed %d options\n", argc, optind);
82         usage();
83     }
84     if ( rename(argv[optind], argv[optind+1]) ) {
85         perror("cannot rename");
86         exit(1);
87     }
88     return 0;
89 }
90 /*
91  * routine to print usage info and exit
92  */
93 void usage(void) {
94     printf("Program testren : test renaming of file/directories  \n");
95     printf("Usage:\n");
96     printf("  testrem [-h] fileorig filedest \n");
97     printf("  -h           print this help\n");
98     
99     exit(1);
100 }
101