#!/bin/sh
# sorter – Sorter fullformsordlistene.
#
# Copyright © 2008, 2009 Karl Ove Hufthammer <karl@huftis.org>.
#
#     This file is part of Ordbanken.
#
#     Ordbanken 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 3 of the License, or
#     (at your option) any later version.
#
#     This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

# Filnamna til fullformsordlistene.
nn_fil=../fullform_nn.txt
nb_fil=../fullform_bm.txt
nnp_fil=../paradigme_nn.txt
nbp_fil=../paradigme_bm.txt
opphav_fil=../opphavsrett.txt

svn revert $opphav_fil

export LC_ALL=C # For å unngå feilaktig sortering av «aa».

# Mellombelse filer for å helda dei sorterte ordlistene
nn_tmp=$(mktemp)
nb_tmp=$(mktemp)
nnp_tmp=$(mktemp)
nbp_tmp=$(mktemp)

# Fjern infoteksten før sortering.
grep -v ^\* $nn_fil | sort --stable -t"	" -k2,2 -k1,1n -k5,5 > $nn_tmp
grep -v ^\* $nb_fil | sort --stable -t"	" -k2,2 -k1,1n -k5,5 > $nb_tmp
grep -v ^\* $nnp_fil > $nnp_tmp
grep -v ^\* $nbp_fil > $nbp_tmp

# Lagra infotekst + sortert liste over originalfilene.
cat $opphav_fil > $nn_fil
cat $opphav_fil > $nb_fil
cat $opphav_fil > $nnp_fil
cat $opphav_fil > $nbp_fil
cat $nn_tmp >> $nn_fil
cat $nb_tmp >> $nb_fil
cat $nnp_tmp >> $nnp_fil
cat $nbp_tmp >> $nbp_fil

# Fjern dei mellombelse filene.
rm -f $nn_tmp $nb_tmp $nnp_tmp $nbp_tmp

