Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rle_addhist.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * rle_addhist.c - Add to the HISTORY comment in header
20  *
21  * Author: Andrew Marriott.
22  * School of Computer Science
23  * Curtin University of Technology
24  * Date: Mon Sept 10 1988
25  * Copyright (c) 1988, Curtin University of Technology
26  */
27 
28 #include "rle.h"
29 #include <stdio.h>
30 
31 #ifdef USE_TIME_H
32 #include <time.h>
33 #else
34 #include <sys/types.h>
35 #include <sys/time.h>
36 #endif
37 
38 /*****************************************************************
39  * TAG( rle_addhist )
40  *
41  * Put a history comment into the header struct.
42  * Inputs:
43  * argv: Command line history to add to comments.
44  * in_hdr: Incoming header struct to use.
45  * Outputs:
46  * out_hdr: Outgoing header struct to add to.
47  * Assumptions:
48  * If no incoming struct then value is NULL.
49  * Algorithm:
50  * Calculate length of all comment strings, malloc and then set via
51  * rle_putcom.
52  */
53 
55 register char *argv[];
56 rle_hdr *in_hdr,*out_hdr;
57 {
58  register int length,i;
59  time_t temp;
60  /* padding must give number of characters in histoire */
61  /* plus one for "=" */
62  static CONST_DECL char *histoire="HISTORY",
63  *padding="\t";
64  char *timedate,*old= NULL;
65  static char *newc;
66 
67  if(getenv("NO_ADD_RLE_HISTORY"))return;
68 
69  length=0;
70  for(i=0;argv[i];i++)
71  length+= strlen(argv[i]) +1; /* length of each arg plus space. */
72 
73  (void)time (&temp);
74  timedate=ctime(&temp);
75  length+= strlen(timedate); /* length of date and time in ASCII. */
76 
77  length+= strlen(padding) + 3 + strlen(histoire) + 1; /* length of padding, "on " and length of history name plus "="*/
78  if(in_hdr) /* if we are interested in the old comments... */
79  old=rle_getcom(histoire,in_hdr); /* get old comment. */
80 
81  if((old) && (*old)) length+= strlen(old); /* add length if there. */
82 
83  length++; /*Cater for the null. */
84 
85  if((newc=(char *)malloc((unsigned int) length)) == NULL)return;
86 
87  (void)strcpy(newc,histoire);(void)strcat(newc,"=");
88  if((old) && (*old)) (void)strcat(newc,old); /* add old string if there. */
89  for(i=0;argv[i];i++)
90  {
91  (void)strcat(newc,argv[i]);(void)strcat(newc," ");
92  }
93  (void)strcat(newc,"on ");(void)strcat(newc,timedate); /* \n supplied by time. */
94  (void)strcat(newc,padding); /* to line up multiple histories.*/
95 
96  (void)rle_putcom(newc,out_hdr);
97 
98 }
#define USE_TIME_H
Definition: rle_config.h:20
#define CONST_DECL
Definition: rle_config.h:42
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_addhist.c:54
char * rle_getcom(char *name, rle_hdr *the_hdr) const
Definition: rle_getcom.c:81
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
Definition: rle_putcom.c:82