Files
secondo/Tools/Generators/TextRelations/createTextRelation

136 lines
3.4 KiB
Plaintext
Raw Permalink Normal View History

2026-01-23 17:03:45 +08:00
#!/bin/sh
#
# This file is part of SECONDO.
#
# Copyright (C) 2005, University in Hagen, Department of Computer Science,
# Database Systems for New Applications.
#
# SECONDO is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# SECONDO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SECONDO; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
# script for creating a relation containing filenames and contents
# call this script via: createTextRel <objectname> <filename_1>..<filename_n>
# example for storing all html in the home directory (incluve subfolders) into a relation:
# createTextRelation htmlfiles $(find $HOME -name "*.html") > htmlfilesobj
# after that, you can restore the relation in Secondo with: restore htmlfiles from htmlfilesobj
#
# for many files (more than the possible argumentlist of the current bash)
# or for files with spaces in filenames use a pipe for creating the Relation
#
# example: find $HOME -name "*.txt" | createTextRelation txtrelation >txtRelationObj
#
# written, 2005, January - Th. Behr
# you can simply changes this script for creating
# relations of other file types
# change the type here
# examples are text, or binfile
CONTENTTYPE="text"
#
# change the content here
# allowed values ares text and file
CONTENT="text"
#
#
# change here the name of the content
# avoid to use 'filename' as contentname
#
CONTENTNAME="TheText"
### end of configurable part ####
if [ "$CONTENTNAME" = "Filename" ]; then
echo "Error in configuration " >&2
echo "filename not allowed as name of content" >&2
exit 1
fi
if [ "$CONTENT" = "text" ]; then
CONTENTSTART="<text>"
CONTENTEND="</text--->"
fi
if [ "$CONTENT" = "file" ]; then
CONTENTSTART="<file>"
CONTENTEND="</file--->"
fi
if [ -z "$CONTENTSTART" ]; then
echo "Error in configuration, unknow content: $CONTENT" >&2
echo " Allowed values are text and file"; >&2
exit -1
fi
USAGE="createTextRelation [--oldstyle] ObjectName [<file_1>..<file_n>] \n"
if [ $1 = "--oldstyle" ]; then
END=")())"
shift
else
END="))"
fi
HEADER="(OBJECT $1 () (rel (tuple ( (Filename text)($CONTENTNAME $CONTENTTYPE ) ))) ("
if [ "$#" = "0" ]; then
echo "$USAGE" >&2
exit
fi
# case filenames specified
echo -e "$HEADER"
if [ "$#" -gt "1" ]; then
C=1
for F in $*
do
if [ "$C" -gt 1 ]; then
echo -e "( <text>$F</text---> "
echo -n -e " $CONTENTSTART"
if [ "$CONTENT" = "text" ]; then
cat "$F"
else
echo -n -e "$F"
fi
echo -e "$CONTENTEND"")\n"
fi
C=$(expr "$C" + 1)
done
else # no file specified, read from standardinput e.g. a pipe (use for long argumentlists)
read F
while [ "$F" ]; do
echo -e "(<text>$F</text---> "
echo -n -e "$CONTENTSTART"
if [ "$CONTENT" = "text" ]; then
cat "$F"
else
echo -n -e "$F"
fi
echo -n -e "$CONTENTEND"")\n"
read F
done
fi
echo "$END"