|
Packit |
78deda |
/*
|
|
Packit |
78deda |
* This software is copyrighted as noted below. It may be freely copied,
|
|
Packit |
78deda |
* modified, and redistributed, provided that the copyright notice is
|
|
Packit |
78deda |
* preserved on all copies.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* There is no warranty or other guarantee of fitness for this software,
|
|
Packit |
78deda |
* it is provided solely "as is". Bug reports or fixes may be sent
|
|
Packit |
78deda |
* to the author, who may or may not act on them as he desires.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* You may not include this software in a program or other software product
|
|
Packit |
78deda |
* without supplying the source, or without informing the end-user that the
|
|
Packit |
78deda |
* source is available for no extra charge.
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* If you modify this software, you should include a notice giving the
|
|
Packit |
78deda |
* name of the person performing the modification, the date of modification,
|
|
Packit |
78deda |
* and the reason for such modification.
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
/*
|
|
Packit |
78deda |
* rle_addhist.c - Add to the HISTORY comment in header
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* Author: Andrew Marriott.
|
|
Packit |
78deda |
* School of Computer Science
|
|
Packit |
78deda |
* Curtin University of Technology
|
|
Packit |
78deda |
* Date: Mon Sept 10 1988
|
|
Packit |
78deda |
* Copyright (c) 1988, Curtin University of Technology
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
#include <string.h>
|
|
Packit |
78deda |
#include <stdio.h>
|
|
Packit |
78deda |
#include <time.h>
|
|
Packit |
78deda |
|
|
Packit |
78deda |
#include "netpbm/mallocvar.h"
|
|
Packit |
78deda |
#include "rle.h"
|
|
Packit |
78deda |
|
|
Packit |
78deda |
|
|
Packit |
78deda |
/*****************************************************************
|
|
Packit |
78deda |
* TAG( rle_addhist )
|
|
Packit |
78deda |
*
|
|
Packit |
78deda |
* Put a history comment into the header struct.
|
|
Packit |
78deda |
* Inputs:
|
|
Packit |
78deda |
* argv: Command line history to add to comments.
|
|
Packit |
78deda |
* in_hdr: Incoming header struct to use.
|
|
Packit |
78deda |
* Outputs:
|
|
Packit |
78deda |
* out_hdr: Outgoing header struct to add to.
|
|
Packit |
78deda |
* Assumptions:
|
|
Packit |
78deda |
* If no incoming struct then value is NULL.
|
|
Packit |
78deda |
* Algorithm:
|
|
Packit |
78deda |
* Calculate length of all comment strings, malloc and then set via
|
|
Packit |
78deda |
* rle_putcom.
|
|
Packit |
78deda |
*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
void
|
|
Packit |
78deda |
rle_addhist(char * argv[],
|
|
Packit |
78deda |
rle_hdr * const in_hdr,
|
|
Packit |
78deda |
rle_hdr * const out_hdr) {
|
|
Packit |
78deda |
|
|
Packit |
78deda |
const char * const histoire = "HISTORY";
|
|
Packit |
78deda |
const char * const padding = "\t";
|
|
Packit |
78deda |
|
|
Packit |
78deda |
int length;
|
|
Packit |
78deda |
int i;
|
|
Packit |
78deda |
time_t temp;
|
|
Packit |
78deda |
/* padding must give number of characters in histoire */
|
|
Packit |
78deda |
/* plus one for "=" */
|
|
Packit |
78deda |
char * timedate;
|
|
Packit |
78deda |
const char * old;
|
|
Packit |
78deda |
static char * newc;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
if (getenv("NO_ADD_RLE_HISTORY"))
|
|
Packit |
78deda |
return;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
length = 0;
|
|
Packit Service |
2370ca |
for (i = 0; argv[i]; ++i)
|
|
Packit |
78deda |
length += strlen(argv[i]) +1; /* length of each arg plus space. */
|
|
Packit |
78deda |
|
|
Packit |
78deda |
time(&temp);
|
|
Packit |
78deda |
timedate = ctime(&temp);
|
|
Packit |
78deda |
length += strlen(timedate); /* length of date and time in ASCII. */
|
|
Packit Service |
2370ca |
|
|
Packit |
78deda |
length += strlen(padding) + 3 + strlen(histoire) + 1;
|
|
Packit |
78deda |
/* length of padding, "on " and length of history name plus "="*/
|
|
Packit |
78deda |
if (in_hdr) /* if we are interested in the old comments... */
|
|
Packit |
78deda |
old = rle_getcom(histoire, in_hdr); /* get old comment. */
|
|
Packit |
78deda |
else
|
|
Packit |
78deda |
old = NULL;
|
|
Packit |
78deda |
|
|
Packit Service |
2370ca |
if (old && *old)
|
|
Packit |
78deda |
length += strlen(old); /* add length if there. */
|
|
Packit |
78deda |
|
|
Packit |
78deda |
++length; /*Cater for the null. */
|
|
Packit |
78deda |
|
|
Packit |
78deda |
MALLOCARRAY(newc, length);
|
|
Packit |
78deda |
|
|
Packit |
78deda |
if (newc == NULL)
|
|
Packit |
78deda |
return;
|
|
Packit |
78deda |
|
|
Packit |
78deda |
strcpy(newc,histoire);(void)strcat(newc,"=");
|
|
Packit |
78deda |
if (old && *old)
|
|
Packit |
78deda |
strcat(newc, old); /* add old string if there. */
|
|
Packit |
78deda |
for (i=0;argv[i];i++) {
|
|
Packit |
78deda |
strcat(newc, argv[i]);
|
|
Packit |
78deda |
strcat(newc, " ");
|
|
Packit |
78deda |
}
|
|
Packit |
78deda |
strcat(newc,"on ");
|
|
Packit |
78deda |
strcat(newc,timedate); /* \n supplied by time. */
|
|
Packit |
78deda |
strcat(newc,padding); /* to line up multiple histories.*/
|
|
Packit |
78deda |
|
|
Packit |
78deda |
rle_putcom(newc, out_hdr);
|
|
Packit |
78deda |
}
|