summaryrefslogtreecommitdiff
path: root/contrib/string
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1998-08-30 19:37:51 +0000
committerMarc G. Fournier <scrappy@hub.org>1998-08-30 19:37:51 +0000
commiteec4c7366f04aa258bb8b7fcd2bbc90eda1cc271 (patch)
treedfb6b70845221063cc0515177b993713595ff69c /contrib/string
parent3067ac8e77369c1b41195b4d90e2ff2c0b23bc7f (diff)
downloadpostgresql-eec4c7366f04aa258bb8b7fcd2bbc90eda1cc271.tar.gz
From: Massimo Dal Zotto <dz@cs.unitn.it>
Here is a tar file the new directories, which substitute the old ones in contrib. Please remove the old directories array, datetime, miscutil, string and userlock before unpacking the tar file in contrib. Note that as the modules are now installed in lib/modules I install all my sql code in lib/sql. In my opinion also the other contributors should follow these rules.
Diffstat (limited to 'contrib/string')
-rw-r--r--contrib/string/Makefile39
-rw-r--r--contrib/string/string_io.c63
-rw-r--r--contrib/string/string_io.doc16
-rw-r--r--contrib/string/string_io.h9
-rw-r--r--contrib/string/string_io.sql.in87
5 files changed, 98 insertions, 116 deletions
diff --git a/contrib/string/Makefile b/contrib/string/Makefile
index 4aba948277..ea42cfa91b 100644
--- a/contrib/string/Makefile
+++ b/contrib/string/Makefile
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------
#
-# Makefile--
-# Makefile for new string I/O functions.
+# Makefile --
+# Makefile for string I/O module.
#
#-------------------------------------------------------------------------
@@ -15,36 +15,35 @@ INCLUDE_OPT = -I ./ \
-I $(SRCDIR)/include \
-I $(SRCDIR)/port/$(PORTNAME)
-CFLAGS += $(INCLUDE_OPT)
-
-ifeq ($(PORTNAME), linux)
- ifdef LINUX_ELF
- ifeq ($(CC), gcc)
- CFLAGS += -fPIC
- endif
- endif
-endif
-
-ifeq ($(PORTNAME), i386_solaris)
- CFLAGS+= -fPIC
-endif
+CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL)
MODNAME = string_io
MODULE = $(MODNAME)$(DLSUFFIX)
+MODDIR = $(LIBDIR)/modules
+
+SQLDIR = $(LIBDIR)/sql
+
all: module sql
module: $(MODULE)
sql: $(MODNAME).sql
-install: $(MODULE)
- cp -p $(MODULE) $(LIBDIR)/modules
- cd $(LIBDIR)/modules; strip $(MODULE)
+install: $(MODULE) $(MODDIR) $(SQLDIR)
+ cp -p $(MODULE) $(MODDIR)/
+ strip $(MODDIR)/$(MODULE)
+ cp -p $(MODNAME).sql $(SQLDIR)/
+
+$(MODDIR):
+ mkdir -p $@
+
+$(SQLDIR):
+ mkdir -p $@
%.sql: %.sql.in
- sed "s|MODULE_PATHNAME|$(LIBDIR)/modules/$(MODULE)|" < $< > $@
+ sed "s|MODULE_PATHNAME|$(MODDIR)/$(MODULE)|" < $< > $@
.SUFFIXES: $(DLSUFFIX)
@@ -55,7 +54,7 @@ depend dep:
$(CC) -MM $(INCLUDE_OPT) *.c >depend
clean:
- rm -f $(MODULE) $(MODNAME).sql
+ rm -f *~ $(MODULE) $(MODNAME).sql
ifeq (depend,$(wildcard depend))
include depend
diff --git a/contrib/string/string_io.c b/contrib/string/string_io.c
index b163fb75c6..03b7169a54 100644
--- a/contrib/string/string_io.c
+++ b/contrib/string/string_io.c
@@ -1,9 +1,12 @@
/*
* string_io.c --
*
- * This file defines new input/output conversion routines for strings.
+ * This file defines C-like input/output conversion routines for strings.
*
- * Copyright (c) 1996, Massimo Dal Zotto <dz@cs.unitn.it>
+ * Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
+ *
+ * This file is distributed under the GNU General Public License
+ * either version 2, or (at your option) any later version.
*/
#include <ctype.h>
@@ -33,14 +36,14 @@
* string_output() --
*
* This function takes a pointer to a string data and an optional
- * data size and returns a printable representation of the data
+ * data size and returns a printable representation of the string
* translating all escape sequences to C-like \nnn or \c escapes.
* The function is used by output methods of various string types.
*
* Arguments:
* data - input data (can be NULL)
* size - optional size of data. A negative value indicates
- * that data is a null terminated string.
+ * that data is a null terminated string.
*
* Returns:
* a pointer to a new string containing the printable
@@ -165,13 +168,13 @@ string_output(char *data, int size)
* Arguments:
* str - input string possibly with escapes
* size - the required size of new data. A value of 0
- * indicates a variable size string, while a
- * negative value indicates a variable size string
- * of size not greater than this absolute value.
+ * indicates a variable size string, while a
+ * negative value indicates a variable size string
+ * of size not greater than this absolute value.
* hdrsize - size of an optional header to be allocated before
- * the data. It must then be filled by the caller.
+ * the data. It must then be filled by the caller.
* rtn_size - an optional pointer to an int variable where the
- * size of the new string is stored back.
+ * size of the new string is stored back.
*
* Returns:
* a pointer to the new string or the header.
@@ -293,32 +296,8 @@ c_charout(int32 c)
return (string_output(str, 1));
}
-char *
-c_char2out(uint16 s)
-{
- return (string_output((char *) &s, 2));
-}
-
-char *
-c_char4out(uint32 s)
-{
- return (string_output((char *) &s, 4));
-}
-
-char *
-c_char8out(char *s)
-{
- return (string_output(s, 8));
-}
-
-char *
-c_char16out(char *s)
-{
- return (string_output(s, 16));
-}
-
/*
- * This can be used for text, bytea, SET and unknown data types
+ * This can be used for SET, bytea, text and unknown data types
*/
char *
@@ -368,13 +347,19 @@ c_textin(char *str)
return (result);
}
-char *
-c_char16in(char *str)
+int32 *
+c_charin(char *str)
{
- return (string_input(str, 16, 0, NULL));
+ return (string_input(str, 1, 0, NULL));
}
-
#endif
-
/* end of file */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/contrib/string/string_io.doc b/contrib/string/string_io.doc
new file mode 100644
index 0000000000..af4b974785
--- /dev/null
+++ b/contrib/string/string_io.doc
@@ -0,0 +1,16 @@
+These output functions can be used as substitution of the standard text
+output functions to get the value of text fields printed in the format
+used for C strings. This allows the output of queries or the exported
+files to be processed more easily using standard unix filter programs
+like perl or awk.
+
+If you use the standard functions instead you could find a single tuple
+splitted into many lines and the tabs embedded in the values could be
+confused with those used as field delimters.
+
+My function translates all non-printing characters into corresponding
+esacape sequences as defined by the C syntax. All you need to reconstruct
+the exact value in your application is a corresponding unescape function
+like the string_input defined in the source code.
+
+Massimo Dal Zotto <dz@cs.unitn.it>
diff --git a/contrib/string/string_io.h b/contrib/string/string_io.h
index b2af60f62c..1ac0f2fb16 100644
--- a/contrib/string/string_io.h
+++ b/contrib/string/string_io.h
@@ -14,7 +14,14 @@ char *c_varcharout(char *s);
#if 0
struct varlena *c_textin(char *str);
char *c_char16in(char *str);
-
#endif
#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/contrib/string/string_io.sql.in b/contrib/string/string_io.sql.in
index ad1a51607c..a1fafbc3ae 100644
--- a/contrib/string/string_io.sql.in
+++ b/contrib/string/string_io.sql.in
@@ -1,32 +1,18 @@
+-- string_io.sql --
+--
-- SQL code to define the new string I/O functions
-
--- This is not needed because escapes are handled by the parser
--
--- create function c_textin(opaque)
--- returns text
--- as 'MODULE_PATHNAME'
--- language 'c';
+-- Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
+--
+-- This file is distributed under the GNU General Public License
+-- either version 2, or (at your option) any later version.
+-- Define the new output functions.
+--
create function c_charout(opaque) returns int4
as 'MODULE_PATHNAME'
language 'c';
-create function c_char2out(opaque) returns int4
- as 'MODULE_PATHNAME'
- language 'c';
-
-create function c_char4out(opaque) returns int4
- as 'MODULE_PATHNAME'
- language 'c';
-
-create function c_char8out(opaque) returns int4
- as 'MODULE_PATHNAME'
- language 'c';
-
-create function c_char16out(opaque) returns int4
- as 'MODULE_PATHNAME'
- language 'c';
-
create function c_textout(opaque) returns int4
as 'MODULE_PATHNAME'
language 'c';
@@ -35,70 +21,59 @@ create function c_varcharout(opaque) returns int4
as 'MODULE_PATHNAME'
language 'c';
+-- This is not needed because escapes are handled by the parser
+--
+-- create function c_textin(opaque)
+-- returns text
+-- as 'MODULE_PATHNAME'
+-- language 'c';
--- Define a function which sets the new output routines for char types
+-- Define a function which sets the new output routines for char types.
--
-- select c_mode();
--
create function c_mode() returns text
- as 'update pg_type set typoutput=''c_charout'' where typname=''char'';
- update pg_type set typoutput=''c_char2out'' where typname=''char2'';
- update pg_type set typoutput=''c_char4out'' where typname=''char4'';
- update pg_type set typoutput=''c_char8out'' where typname=''char8'';
- update pg_type set typoutput=''c_char16out'' where typname=''char16'';
- update pg_type set typoutput=''c_textout'' where typname=''text'';
+ as 'update pg_type set typoutput=''c_textout'' where typname=''SET'';
+ update pg_type set typoutput=''c_varcharout'' where typname=''bpchar'';
update pg_type set typoutput=''c_textout'' where typname=''bytea'';
+ update pg_type set typoutput=''c_charout'' where typname=''char'';
+ update pg_type set typoutput=''c_textout'' where typname=''text'';
update pg_type set typoutput=''c_textout'' where typname=''unknown'';
- update pg_type set typoutput=''c_textout'' where typname=''SET'';
update pg_type set typoutput=''c_varcharout'' where typname=''varchar'';
- update pg_type set typoutput=''c_varcharout'' where typname=''bpchar'';
select ''c_mode''::text'
language 'sql';
--- Define a function which restores the original routines for char types
+-- Define a function which restores the standard routines for char types.
--
-- select pg_mode();
--
create function pg_mode() returns text
- as 'update pg_type set typoutput=''charout'' where typname=''char'';
- update pg_type set typoutput=''char2out'' where typname=''char2'';
- update pg_type set typoutput=''char4out'' where typname=''char4'';
- update pg_type set typoutput=''char8out'' where typname=''char8'';
- update pg_type set typoutput=''char16out'' where typname=''char16'';
- update pg_type set typoutput=''textout'' where typname=''text'';
+ as 'update pg_type set typoutput=''textout'' where typname=''SET'';
+ update pg_type set typoutput=''varcharout'' where typname=''bpchar'';
update pg_type set typoutput=''textout'' where typname=''bytea'';
+ update pg_type set typoutput=''charout'' where typname=''char'';
+ update pg_type set typoutput=''textout'' where typname=''text'';
update pg_type set typoutput=''textout'' where typname=''unknown'';
- update pg_type set typoutput=''textout'' where typname=''SET'';
update pg_type set typoutput=''varcharout'' where typname=''varchar'';
- update pg_type set typoutput=''varcharout'' where typname=''bpchar'';
select ''pg_mode''::text'
language 'sql';
-
--- Use these if you want do the updates manually
+-- Use these to do the changes manually.
--
+-- update pg_type set typoutput='textout' where typname='SET';
+-- update pg_type set typoutput='varcharout' where typname='bpchar';
+-- update pg_type set typoutput='textout' where typname='bytea';
-- update pg_type set typoutput='charout' where typname='char';
--- update pg_type set typoutput='char2out' where typname='char2';
--- update pg_type set typoutput='char4out' where typname='char4';
--- update pg_type set typoutput='char8out' where typname='char8';
--- update pg_type set typoutput='char16out' where typname='char16';
-- update pg_type set typoutput='textout' where typname='text';
--- update pg_type set typoutput='textout' where typname='bytea';
-- update pg_type set typoutput='textout' where typname='unknown';
--- update pg_type set typoutput='textout' where typname='SET';
-- update pg_type set typoutput='varcharout' where typname='varchar';
--- update pg_type set typoutput='varcharout' where typname='bpchar';
--
+-- update pg_type set typoutput='c_textout' where typname='SET';
+-- update pg_type set typoutput='c_varcharout' where typname='bpchar';
+-- update pg_type set typoutput='c_textout' where typname='bytea';
-- update pg_type set typoutput='c_charout' where typname='char';
--- update pg_type set typoutput='c_char2out' where typname='char2';
--- update pg_type set typoutput='c_char4out' where typname='char4';
--- update pg_type set typoutput='c_char8out' where typname='char8';
--- update pg_type set typoutput='c_char16out' where typname='char16';
-- update pg_type set typoutput='c_textout' where typname='text';
--- update pg_type set typoutput='c_textout' where typname='bytea';
-- update pg_type set typoutput='c_textout' where typname='unknown';
--- update pg_type set typoutput='c_textout' where typname='SET';
-- update pg_type set typoutput='c_varcharout' where typname='varchar';
--- update pg_type set typoutput='c_varcharout' where typname='bpchar';
-- end of file