-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtime_stamp.c
116 lines (106 loc) · 3.64 KB
/
time_stamp.c
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* ----------------------------- MNI Header -----------------------------------
@NAME : time_stamp.c
@DESCRIPTION: File containing routine to create a time stamp string.
@METHOD :
@CREATED : February 1, 1993 (Peter Neelin)
@MODIFIED :
* $Log: time_stamp.c,v $
* Revision 1.1 2002-03-20 22:16:34 jason
* Initial revision
*
* Revision 6.1 2002/01/14 21:28:26 neelin
* Moved nd_loop, voxel_loop, ParseArgv and time_stamp from ../progs/Proglib
* in order to include them in the main minc library.
*
* Revision 6.2 1999/10/19 15:57:18 neelin
* Fixed log message containing log substitution
*
* Revision 6.1 1999/10/19 14:45:14 neelin
* Fixed Log subsitutions for CVS
*
* Revision 6.0 1997/09/12 13:23:41 neelin
* Release of minc version 0.6
*
* Revision 5.0 1997/08/21 13:24:41 neelin
* Release of minc version 0.5
*
* Revision 4.0 1997/05/07 20:00:50 neelin
* Release of minc version 0.4
*
* Revision 3.0 1995/05/15 19:31:35 neelin
* Release of minc version 0.3
*
* Revision 2.0 1994/09/28 10:34:30 neelin
* Release of minc version 0.2
*
* Revision 1.4 94/09/28 10:34:20 neelin
* Pre-release
*
* Revision 1.3 93/08/04 13:03:56 neelin
* Added RCS Log to keep track of modifications in source
*
@COPYRIGHT :
Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre,
Montreal Neurological Institute, McGill University.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies. The author and McGill University
make no representations about the suitability of this
software for any purpose. It is provided "as is" without
express or implied warranty.
---------------------------------------------------------------------------- */
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <time_stamp.h>
#ifndef lint
static char rcsid[]="$Header: /private-cvsroot/INSECT/classify/time_stamp.c,v 1.1 2002-03-20 22:16:34 jason Exp $";
#endif
/* ----------------------------- MNI Header -----------------------------------
@NAME : time_stamp
@INPUT : argc - number of arguments
argv - list of arguments
@OUTPUT :
@RETURNS : pointer to string containing time stamp.
@DESCRIPTION: Function to produce a time stamp string for a program.
Returns a string of the form "date > command". The command
is simply the concatenation of argv elements.
@METHOD :
@GLOBALS :
@CALLS :
@CREATED : February 1, 1993 (Peter Neelin)
@MODIFIED :
---------------------------------------------------------------------------- */
char *time_stamp(int argc, char *argv[])
{
char *str, *the_time;
int length, i, last;
static char separator[]={">>>"};
time_t timer;
/* Get the time, overwriting newline */
timer = time(NULL);
the_time = ctime(&timer);
/* Get the total length of the string and allocate space */
length=strlen(the_time) + strlen(separator) + 2;
for(i=0; i<argc; i++) {
length += strlen(argv[i]) + 1;
}
str = malloc(length);
/* Copy the time and separator */
(void) strcpy(str, the_time);
str[strlen(str)-1]='\0';
(void) strcat(str, separator);
/* Copy the program name and arguments */
for (i=0; i<argc; i++) {
last = strlen(str);
str[last]=' ';
str[last+1]='\0';
(void) strcat(str, argv[i]);
}
/* Add a terminating newline */
last = strlen(str);
str[last]='\n';
str[last+1]='\0';
return str;
}