#!/usr/bin/perl -w
# This script is intended to make fidogate areas & areas.bbs files
# from exported fastecho 1.46 (dos/os2/win*) areas.bbs. This script may be
# usefull only when you wanna keep your old messagebase by exporting it from
# "fake" point address. You have to make %rescan for this "fake" point & then
# put outbound for this "fake" point into your protected inbound dir & run 
# fidogate with configs created by this script - them may allow you avoiding of
# export messages from your "fake" point to downlinks.
# This script will crreate configs usefull ONLY IN THIS CASE. 
# Use fe2fgate_areas.pl to make configs for real work. May work w/ other 
# fastecho versions, but tested only w/ version 1.46 . 
# (c) Olli (olli@digger.org.NOSPAMru,remove NOSPAM before mailing)
# greetz: i_L, Corvin, Vika
# Thanx : Peter V. Chernikoff (peter@digger.org.ru) for help in moving my node to
# Linux. =)
# HOWTO: make fake point w/ unical number in FE configs, link him to areas you
# wanna save, send NetMail from this "fake" point addr containng rescan 
# instructions:
# %rescan
# =*
# Export FE configs,set correct paths & AKAs in vars, then run.
# You should CHECK RESULTS! I wrote this for MY config & didn't read dox on
# FE configs, thus even if this does work for me it CAN give you wrong results.
# Beware that "dead" passthrough areas (exported only to uplink) are never 
# placed by this script in fidogate areas or areas.bbs.
# Look at log file twice.=)
$mnt="/os2";
$replace_char="_"; # &$`'!  - must be converted for ctlinnd to work right way.
$fe_dir="$mnt/m/fe";
$dos_drive="C";
$fe_areas="$fe_dir/areas.bbs";
$fgate_path="/tmp/fidogate";
$fg_areas="$fgate_path/alt_areas";
$fg_areas_bbs="$fgate_path/alt_areas.bbs";
$log_file="$fgate_path/log_file";
$fake_point=".100";
$primary_aka="2:5020/1234";
### internal vars. DO NOT EDIT lines below.
$l_area="";
$links=$fake_point;
$area="";
local (@area_arr);

############### proggie goes:
system `mkdir $fgate_path 2>/dev/null`;
open( AREAS,   "<$fe_areas" ) || die "Can't read FE areas $fe_areas: $!.\n";
open( LOGF,    ">$log_file") || die "Can't write to $log_file: $!.\n";
open( FGBBS,   ">$fg_areas_bbs" ) || die "Can't write to $fg_areas_bbs: $!.\n"; 
open( FG_AR,   ">$fg_areas" ) || die "Can't write to $fg_areas: $!.\n";
print "Log will be in $log_file.\n";
print "Alt. fidogate areas will be in $fg_areas\n";
print "Alt. fidogate areas.bbs will be in $fg_areas_bbs\n";
print "More comments are inside this script: $0\n\n";
print "\t\t\t.USE WITH CARE.\n\n";
print FGBBS "!\n";
while(<AREAS>) 
{
next if (/^;/);
 s/\r//;
 chomp;
next if (/^P\s/); # end of work on passthrough =) 
if (/^\!/)
 {/^\!\S+\s+/;
  print LOGF "Read:$_\n";
  $_=$';
  /^(\S+)/;
  $area=$1;
  if (/^(\S+)\s+/)
   {print LOGF "Area $area,links are:\n$'\n\n";
    next if (!(/$fake_point/)); 
    push(@area_arr,$area);
    next;
   }
  next;
 } # exported
if (/^\$/)
 {/^\$\S+\s+/;
  print LOGF "$_\n";
  $_=$';
  /^(\S+)/;
  $area=$1;
  if (/^(\S+)\s+/)
   {print LOGF "Area $area,links are:\n$'\n\n";
    next if (!(/$fake_point/)); 
    push(@area_arr,$area);
    next;
   }
   next;
 } # exported
if (/^$dos_drive/)
 {/^$dos_drive\S+\s+/;
  $_=$';
  print LOGF "\n$_\n";
  /^(\S+)/;
  $area=$1;
  if (/^(\S+)\s+/)
  {print LOGF "Area $area,links are:\n$'\n\n";
   next if (!(/$fake_point/)); 
   push(@area_arr,$area);
   next;
  }
  next;
 } # end of exported
} # EOF <AREAS>
foreach $area (@area_arr)
{print FGBBS "X $area -a $primary_aka $links\n";
 $_=$area;
 tr/A-Z/a-z/;
 s/\$/$replace_char/g;
 s/\&/$replace_char/g;
 s/\`/$replace_char/g; #` idiotic perl syntax highliting in mcedit..
 s/\'/$replace_char/g;
 s/\!/$replace_char/g;
 $l_area=$_;
 print FG_AR "$area\t$l_area -a $primary_aka -8\n";
}
close(AREAS);
close(FG_AR);
close(LOGF);
exit;
