about summary refs log tree commit diff
path: root/urt/rle_addhist.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-08-19 03:12:28 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-08-19 03:12:28 +0000
commit1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch)
tree64c8c96cf54d8718847339a403e5e67b922e8c3f /urt/rle_addhist.c
downloadnetpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz
netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz
netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'urt/rle_addhist.c')
-rw-r--r--urt/rle_addhist.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c
new file mode 100644
index 00000000..04e26206
--- /dev/null
+++ b/urt/rle_addhist.c
@@ -0,0 +1,115 @@
+/*
+ * This software is copyrighted as noted below.  It may be freely copied,
+ * modified, and redistributed, provided that the copyright notice is 
+ * preserved on all copies.
+ * 
+ * There is no warranty or other guarantee of fitness for this software,
+ * it is provided solely "as is".  Bug reports or fixes may be sent
+ * to the author, who may or may not act on them as he desires.
+ *
+ * You may not include this software in a program or other software product
+ * without supplying the source, or without informing the end-user that the 
+ * source is available for no extra charge.
+ *
+ * If you modify this software, you should include a notice giving the
+ * name of the person performing the modification, the date of modification,
+ * and the reason for such modification.
+ */
+/* 
+ * rle_addhist.c - Add to the HISTORY comment in header
+ * 
+ * Author:  Andrew Marriott.
+ *      School of Computer Science 
+ *      Curtin University of Technology
+ * Date:    Mon Sept 10 1988
+ * Copyright (c) 1988, Curtin University of Technology
+ */
+
+#include "rle.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#ifdef  USE_TIME_H
+#include <time.h>
+#else
+#include <sys/types.h>
+#include <sys/time.h>
+#endif
+
+#include "mallocvar.h"
+
+/*****************************************************************
+ * TAG( rle_addhist )
+ * 
+ * Put a history comment into the header struct.
+ * Inputs:
+ *  argv:       Command line history to add to comments.
+ *  in_hdr:     Incoming header struct to use.
+ * Outputs:
+ *  out_hdr:    Outgoing header struct to add to.
+ * Assumptions:
+ *  If no incoming struct then value is NULL.
+ * Algorithm:
+ *  Calculate length of all comment strings, malloc and then set via
+ *  rle_putcom.
+ */
+
+void
+rle_addhist(char *          argv[],
+            rle_hdr * const in_hdr,
+            rle_hdr * const out_hdr) {
+
+    const char * const histoire = "HISTORY";
+    const char * const padding = "\t";
+
+    int length;
+    int i;
+    time_t  temp;
+    /* padding must give number of characters in histoire   */
+    /*     plus one for "="                 */
+    char * timedate;
+    const char * old;
+    static char * newc;
+
+    if (getenv("NO_ADD_RLE_HISTORY"))
+        return;
+    
+    length = 0;
+    for (i = 0; argv[i]; ++i)
+        length += strlen(argv[i]) +1;   /* length of each arg plus space. */
+
+    time(&temp);
+    timedate = ctime(&temp);
+    length += strlen(timedate);        /* length of date and time in ASCII. */
+
+    length += strlen(padding) + 3 + strlen(histoire) + 1;
+        /* length of padding, "on "  and length of history name plus "="*/
+    if (in_hdr) /* if we are interested in the old comments... */
+        old = rle_getcom(histoire, in_hdr);     /* get old comment. */
+    else
+        old = NULL;
+    
+    if (old && *old)
+        length += strlen(old);       /* add length if there. */
+
+    ++length;                               /*Cater for the null. */
+
+    MALLOCARRAY(newc, length);
+
+    if (newc == NULL)
+        return;
+
+    strcpy(newc,histoire);(void)strcat(newc,"=");
+    if (old && *old)
+        strcat(newc, old); /* add old string if there. */
+    for (i=0;argv[i];i++) {
+        strcat(newc, argv[i]);
+        strcat(newc, " ");
+    }
+    strcat(newc,"on ");
+    strcat(newc,timedate);         /* \n supplied by time. */
+    strcat(newc,padding);          /* to line up multiple histories.*/
+    
+    rle_putcom(newc, out_hdr);
+}