about summary refs log tree commit diff
path: root/urt/rle_getcom.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_getcom.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_getcom.c')
-rw-r--r--urt/rle_getcom.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/urt/rle_getcom.c b/urt/rle_getcom.c
new file mode 100644
index 00000000..20da56a9
--- /dev/null
+++ b/urt/rle_getcom.c
@@ -0,0 +1,99 @@
+/*
+ * 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_getcom.c - Get specific comments from the_hdr structure.
+ * 
+ * Author:	Spencer W. Thomas
+ * 		Computer Science Dept.
+ * 		University of Utah
+ * Date:	Sun Jan 25 1987
+ * Copyright (c) 1987, University of Utah
+ */
+
+#include <stdio.h>
+#include "rle.h"
+
+/*****************************************************************
+ * TAG( match )
+ * 
+ * Match a name against a test string for "name=value" or "name".
+ * If it matches name=value, return pointer to value part, if just
+ * name, return pointer to NUL at end of string.  If no match, return NULL.
+ *
+ * Inputs:
+ * 	n:	Name to match.  May also be "name=value" to make it easier
+ *		to replace comments.
+ *	v:	Test string.
+ * Outputs:
+ * 	Returns pointer as above.
+ * Assumptions:
+ *	[None]
+ * Algorithm:
+ *	[None]
+ */
+static const char *
+match(const char * const nArg,
+      const char * const vArg) {
+
+    const char * n;
+    const char * v;
+
+    for (n = nArg, v = vArg; *n != '\0' && *n != '=' && *n == *v; n++, v++)
+        ;
+    if (*n == '\0' || *n == '=') {
+        if (*v == '\0')
+            return v;
+        else if (*v == '=')
+            return ++v;
+    }
+    return NULL;
+}
+
+
+
+/*****************************************************************
+ * TAG( rle_getcom )
+ * 
+ * Return a pointer to the value part of a name=value pair in the comments.
+ * Inputs:
+ * 	name:		Name part of the comment to search for.
+ *	the_hdr:	rle_dflt_hdr structure.
+ * Outputs:
+ * 	Returns pointer to value part of comment or NULL if no match.
+ * Assumptions:
+ *	[None]
+ * Algorithm:
+ *	[None]
+ */
+const char *
+rle_getcom(const char * const name,
+           rle_hdr *    const the_hdr) {
+
+    const char ** cp;
+
+    if (the_hdr->comments == NULL)
+        return NULL;
+
+    for (cp = the_hdr->comments; *cp; ++cp) {
+        const char * const v = match(name, *cp);
+        if (v != NULL )
+            return v;
+    }
+    return NULL;
+}
+