#!/bin/sh # # $Id$ # # Copyright 1989-2016 MINES ParisTech # # This file is part of PIPS. # # PIPS 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 # any later version. # # PIPS 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 PIPS. If not, see . # # Usage: logfile_to_tpips # # Convert the logfile of the named workspace # created by wpips to a tpips source. # # Known limitations: # # - does not display all the resources for a # rule creating multiple resources. # # TODO: rewrite with some other script language than sh/sed? # extract all setenv of cpp-related pips variables? (even from pyps)? # what about adding some options, such as --delete for an initial cleanup? # see #645 # sed=${PIPS_SED:-sed} WS=${1:?"Please give me the workspace name to work with"} # Remove trailing slash in WS WS= `echo "${WS}" | sed -e "s/\/*$//" ` if [ `basename $WS` != "$WS" ] then echo $0 can only be used on a local database exit 1 fi if [ `basename $WS .database` != "$WS" ] then WS=`basename $WS .database` fi WDIR=${WS}.database CAT=${PAGER:-cat} if [ ! -r $WDIR/Logfile ] then echo $0: Cannot open: $WDIR/Logfile exit 1 fi echo \# echo \# file generated by logfile_to_tpips for workspace $WS echo \# #echo \# initial cleanup #echo delete $WS echo \# generated tpips script $sed -n \ "/^echo/p; /^shell/p; /^cd/p; /^set/p; s,${PIPS_ROOT},\\\${PIPS_ROOT},g; s,^Registering file \(.*\),create $WS \1,p; s,^Module \(.*\) selected,module \1,p; s,^Closing all modules\.,close,p; s,^Workspace [^ ]* opened\.,open $WS,p; s,^Directory \(.*\) selected,cd \1,p; s,^Request: build resource \(.*\) for module \(.*\).,display \1[\2],p; s,^Request: build phase/rule \(.*\) for module \(.*\).,apply \1[\2],p; s,^Request: capply \(.*\) for module \[\(.*\)\].,capply \1[\2],p; s,^Request: perform rule \(.*\) on module \(.*\).,apply \1[\2],p; s,^Options: phase \(.*\) (\(.*\)) set on.,activate \2 # \1,p; s,^Selecting rule: \(.*\),activate \1,p; s,^HPFC View of \"\(.*\)\" done.,shell $CAT $WDIR\/hpfc\/\1,p; s,^User Request...,# user request :,p; s,^\"\(.*\)\"\$,\1,p" $WS.database/Logfile | { tr '\012' ' ' ; echo ; } | $sed "s, create $WS,,g; s,,,g; s, \$,,; s,\(apply UNSPLIT\)\[\],\1," | tr ' ' '\012' echo quit echo \# EOF #end