xref: /netbsd-src/external/bsd/file/file2netbsd (revision 84d8cf07eca93794e884a16e57c9d8ab143d0380)
11594e4f0Schristos#! /bin/sh
21594e4f0Schristos#
3*84d8cf07Schristos#	$NetBSD: file2netbsd,v 1.4 2013/01/03 23:04:52 christos Exp $
41594e4f0Schristos#
51594e4f0Schristos# Copyright (c) 2003, 2011 The NetBSD Foundation, Inc.
61594e4f0Schristos# All rights reserved.
71594e4f0Schristos#
81594e4f0Schristos# Redistribution and use in source and binary forms, with or without
91594e4f0Schristos# modification, are permitted provided that the following conditions
101594e4f0Schristos# are met:
111594e4f0Schristos# 1. Redistributions of source code must retain the above copyright
121594e4f0Schristos#    notice, this list of conditions and the following disclaimer.
131594e4f0Schristos# 2. Redistributions in binary form must reproduce the above copyright
141594e4f0Schristos#    notice, this list of conditions and the following disclaimer in the
151594e4f0Schristos#    documentation and/or other materials provided with the distribution.
161594e4f0Schristos#
171594e4f0Schristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
181594e4f0Schristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
191594e4f0Schristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
201594e4f0Schristos# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
211594e4f0Schristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
221594e4f0Schristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
231594e4f0Schristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
241594e4f0Schristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
251594e4f0Schristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
261594e4f0Schristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
271594e4f0Schristos# POSSIBILITY OF SUCH DAMAGE.
281594e4f0Schristos#
291594e4f0Schristos# file2netbsd:  convert a file source tree into a
301594e4f0Schristos# format suitable for import.  Works on current dir.
311594e4f0Schristos# You can run this only once if you want it to work.
321594e4f0Schristos#
331594e4f0Schristos# based on texinfo2netbsd
341594e4f0Schristos#
351594e4f0SchristosPROG="$(basename "$0")"
361594e4f0Schristos
371594e4f0Schristosif [ -z "$1" ]
381594e4f0Schristosthen
391594e4f0Schristos	echo "Usage: $PROG <directory>" 1>&2
401594e4f0Schristos	exit 1
411594e4f0Schristosfi
421594e4f0SchristosFILE="$1"
431594e4f0Schristos
441594e4f0Schristosfile_vers="$(awk -F', ' '/AC_INIT\(/ { print $2 }' "$FILE/configure.ac")"
451594e4f0Schristos
461594e4f0Schristos### Wipe out stuff we don't want
471594e4f0Schristosfind "$FILE" -name .cvsignore -delete
481594e4f0Schristos
491594e4f0Schristos### Remove the $'s around RCS tags
500e7bd658Schristoscleantags "$FILE"
511594e4f0Schristos
521594e4f0Schristos### Add NetBSD RCS Id
531594e4f0Schristosfind "$FILE" -type f -name '*.[chly]' -print | while read c; do
541594e4f0Schristos	sed -e '1{/$NetBSD/!{i\
551594e4f0Schristos/*	\$NetBSD\$	*/\
561594e4f0Schristos
571594e4f0Schristos};}
581594e4f0Schristos/#ifndef[ 	]lint/{N;/FILE_RCSID/s/\n/\
591594e4f0Schristos#if 0\
601594e4f0Schristos/
611594e4f0Schristosa\
621594e4f0Schristos#else\
631594e4f0Schristos__RCSID("\$NetBSD\$");\
641594e4f0Schristos#endif
651594e4f0Schristos}' $c > /tmp/file3$$
661594e4f0Schristosmv /tmp/file3$$ $c && echo did source mods for $c
671594e4f0Schristosdone
681594e4f0Schristos
691594e4f0Schristos#### Move files to proper names
70*84d8cf07Schristosmv -f $FILE/doc/file.man $FILE/doc/file.1
71*84d8cf07Schristosmv -f $FILE/doc/libmagic.man $FILE/doc/libmagic.3
72*84d8cf07Schristosmv -f $FILE/doc/magic.man $FILE/doc/magic.5
731594e4f0Schristos
741594e4f0Schristos#### Add RCS tags to man pages
751594e4f0Schristosfind "$FILE" -type f -name '*.[0-9]' -print | while read m; do
761594e4f0Schristos	sed -e '1{/$NetBSD/!i\
771594e4f0Schristos.\\"	\$NetBSD\$\
781594e4f0Schristos.\\"
791594e4f0Schristos
801594e4f0Schristos}'	    -e 's/__CSECTION__/1/g' \
811594e4f0Schristos	    -e 's/__FSECTION__/5/g' \
821594e4f0Schristos	    -e 's/__VERSION__/'"${file_vers}/g" \
831594e4f0Schristos	    -e 's,__MAGIC__,/usr/share/misc/magic,g' \
841594e4f0Schristos	    $m > /tmp/file4$$
851594e4f0Schristosmv /tmp/file4$$ $m && echo did manpage mods for $m
861594e4f0Schristosdone
871594e4f0Schristos
881594e4f0Schristos#### de-"capsize" the magdir
89*84d8cf07Schristosmv $FILE/magic/Magdir $FILE/magic/magdir
901594e4f0Schristos
911594e4f0Schristos#### Make building easier, don't build magic and doc
921594e4f0Schristosecho '/^SUBDIRS/
931594e4f0Schristost.
941594e4f0Schristoss/^/#/
951594e4f0Schristos-
961594e4f0Schristoss/ magic.*//
971594e4f0Schristoswq' | ed Makefile.in > /dev/null 2>&1
981594e4f0Schristos
991594e4f0Schristosecho done
1001594e4f0Schristos
1011594e4f0Schristosecho You can import now.  Use the following command:
1020e7bd658Schristosecho cvs -d cvs.netbsd.org:/cvsroot import src/external/bsd/file/dist CHRISTOS FILE${file_vers%.*}_${file_vers#*.}
1031594e4f0Schristos
1041594e4f0Schristosexit 0
105