Commit 45561722 authored by Philipp Giebel's avatar Philipp Giebel
Browse files

initial import

parents
ews ag
ijij
޳ v0.1
޳
޳ NewsMag creates nice
޳ ansi-files from dull
޳ text-files to easily
޳ provide users with
޳ news about your BBS.
޳ (Don't confuse with
޳ "NewsCenter" by fU!)
޳
޳ Requires: Perl
ijij
\ No newline at end of file
Copyright (c) 2015, Philipp Giebel <spam@stimpyrama.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NewsMag2k v0.1
by Philipp Giebel <spam@stimpyrama.org>
http://kuehlbox.ws
telnet://kuelbox.ws
INTRODUCTION
This tool was one of the first, I ever wrote for public use back in 1994.
The original was a DOS .exe written in TurboPascal and the source code is
long lost.
Since I started a BBS again in 2015 and I needed something exacly like this,
I re-coded it using Perl, so it runs on any operating system..
USE
NewsMag uses a simple textfile + some template files to create a good looking
ansi-file, you can use as news for and about your BBS.
Don't confuse it with fUs "NewsCenter", which creates ansis of existing news:
With NewsMag you'll have to write the news yourself! ;)
INSTALLATION
None required. Simply run "newsmag.pl" or "newsmag.pl -h" for help.
USAGE
Simple: ~# ./newsmag.pl
Help: ~# ./newsmag.pl -h
More help: ~# ./newsmag.pl --longhelp
By default, newsmag searches for the input text-file and all templates at
the directory, you're in while running the script, but you can provide
alternative paths and filenames for everything. Check "newsmag.pl -h" for
a list of all available options and their default values.
INPUT FILE
default: ./news.txt
parameter: --infile=/path/to/your/news.txt
You write news in this file using this very simple format:
<DATE>
<SUBJECT>
<CONTENT>
<MORE CONTENT>
<...>
@NEXT@
<DATE>
<SUBJECT>
<CONTENT>
Order doesn't matter, NewsMag always sorts the input by date, newest first.
TEMPLATES
NewsMag comes with some template examples, you are free to use. But you can
also create your own using the examples and/or this description:
- Header:
default: ./newshdr.ans
parameter: --filehdr=/path/to/your/headertemplate.ans
This file holds your header template to be displayed above all the news.
It has no special variables (yet)..
- Footer:
default: ./newsftr.ans
parameter: --fileftr=/path/to/your/footertemplate.ans
This file holds your footer template to be displayed beneath all the news.
It can hold one special variable:
@COPYRIGHT@ - Will be replaced by a short copyright notice. If omitted,
the notice will be auto-appended below the footer.
- Entries:
default: ./entryhdr.ans
parameter: --fileentry=/path/to/your/entrytemplate.ans
This file holds your entry-template used to display each news entry.
It must hold three special variables:
@DATE@ - Will be replaced by the first line of your entries at news.txt
@SUBJECT@ - Will be replaced by the second line of your entries at news.txt
@CONTENT@ - Will be replaced by all the lines between the second and the
next one containing the tag "@NEXT@" (See section "INPUT FILE")
Also takes all characters to the left and repeats them on
subsequent lines.
Padding:
You can pad these variables to fit into your template files by appending
"<length><direction>@".
e.g:
@DATE@16L@ - This will pad the date to 16 characters by adding
whitespace to the left.
@SUBJECT@32R@ - This will pad the subject to 32 characters by adding
whitespace to the right.
Wrapping:
Content lines are wrapped to 75 characters by default. Also, all characters
to the left of the @CONTENT@ tag in your template.ans are repeated on
subsequent lines.
You can change the line width by adding "<width>@" to the variable.
e.g:
@SUBJECT@70@ - This will wrap lines at 70 characters.
If any of these template files are omitted or not found, NewsMag will use
very simple, hardcoded defaults.
OUTPUT
default: ./news.ans
parameter: --outfile=/path/to/your/outputfile.ans
Using all these different input files, NewsMag creates one huge ansi-file
containing all news entries from your news.txt.
You can limit the news to be displayed with the option "--num=<num>"
BBS CONFIGURATION
Some BBS systems automaticaly display files called "news.ans" at the login
process if they have changed since the users last visit.
some other systems have to be configured that way.
MysticBBS
For MysticBBS, I've attached a small .mps script you can include into your
"prelogin" menu with the name of your news.ans inside the text directory
of your MysticBBS theme:
- (E)dit -> (M)enu Editor -> default (or your template) -> prelogin
- Press enter to edit the first entry called "FIRSTCMD"
- Press tab to edit the commands
- Navigate to a position in your login process, you'ld like the news
to be displayed
- Press "/", then "i" to insert a new command
- Select (C)ommand: "(GX) Execute MPL program"
- Add (D)ata: newsmag news
Exit and save.
Now, users will see the news.ans inside the "text-directory" of your BBS
(default: /mystic/text) everytime they log in and the file has changed
since their last login.
At the moment, the attached .mps is simply the "onlyonce.mps", which comes
with MysticBBS, but with a "Pause Prompt" at the end.
Probably, I'll enhance it later..
CONTACT
Philipp Giebel
BBS: telnet://kuehlbox.wtf
WEB: http://kuehlbox.wtf
FidoNet: 2:240/5853
E-Mail: stimpy@kuehlbox.wtf
COPYRIGHT
This script has been released under BSD license. This basically means,
you can do whatever you want with it but you'll have to note me as the
original author.
A LOT! ;)
 @SUBJECT@32R@@DATE@16L@
 @CONTENT@


2015-03-18
Hooray, I'm using NewsMag!
From now on and forever more, I'm using the infamous, so absolutely fabolous NewsMag by kuehlbox.wtf
@NEXT@
2015-03-19
This is incredible!
I just can't contain myself:
NewsMag just made my life complete!
    @COPYRIGHT@


    
 
    

// NEWSMAG.MPS: This is just a minimal modification to the original
// ONLYONCE.MPS by g00r00 included with MysticBBS
//
// Usage:
// Menu command: GX
// Data: newsmag news
//
// The above example will display news.XXX from current text directory
// only if it has been updated since the users last login
Uses
CFG,
USER;
Var
FN : String;
Begin
GetThisUser;
FN := JustFileName(ParamStr(1));
If Pos(PathChar, ParamStr(1)) = 0 Then
FN := CfgTextPath + FN;
FindFirst (FN + '.*', 0);
While DosError = 0 Do Begin
If DirTime > UserLastOn Then Begin
DispFile(FN);
WriteLn( '|CR|PA' );
Break;
End;
FindNext
End;
FindClose;
End.
#!/usr/bin/perl
#
# NewsMag2k v0.1 (beta)
#
# Complete rewrite of NewsMag, originally released in 1994
# For more information see README
#
# Copyright 1993-2015 Philipp Giebel <stimpy@kuehlbox.wtf>
# License: BSD
#
# NewsMag WHQ: Kuehlbox BBS
# http://kuehlbox.ws
# telnet://kuehlbox.ws
# fidonet: 2:240/5853
#
use strict;
use warnings;
use utf8;
use Text::Wrap;
use Encode qw(encode decode);
use Getopt::Long;
use Data::Dumper;
my $output;
my $entryhdrfile = 'entryhdr.ans';
my $entryhdr;
my $etmp;
my $fh;
my $ref;
my @newslist;
my @news;
my $sl;
my $dl;
my $cl;
my $sa;
my $da;
my $ca;
my $stmp;
my $dtmp;
my $ctmp;
my $pre;
my $c = 0;
my $copyright = 'Created with NewsMag2k';
my $VER = '0.1';
my $optHdr = 'newshdr.ans';
my $optFtr = 'newsftr.ans';
my $optEntry = 'entryhdr.ans';
my $optInfile = 'news.txt';
my $optOutfile = 'news.ans';
my $optEnc = 'CP437';
my $optPrint;
my $optHelp;
my $optLonghelp;
my $optQuiet;
my $optNum = 0;
sub getPad {
my $tl;
my $ta;
if ( $_[0] =~ /\@$_[1]\@(\d+)(.)\@/g ) {
$tl = $1;
$ta = $2;
} else {
if ( $_[1] eq 'SUBJECT' ) {
$tl = 32;
$ta = "R";
} elsif ( $_[1] eq 'DATE' ) {
$tl = 16;
$ta = "L";
} elsif ( $_[1] eq 'CONTENT' ) {
$tl = 75;
$ta = "R";
}
}
return ( $tl, $ta );
}
sub padIt {
my $ttmp;
if ( $_[2] eq "L" ) {
$ttmp = sprintf( "%".$_[1]."s", $_[0] );
} else {
$ttmp = sprintf( "%-".$_[1]."s", $_[0] );
}
return $ttmp;
}
sub getTmpl {
my $ret;
if ( open(my $fh, "<:encoding($_[1])", $_[0]) ) {
while (my $row = <$fh>) {
chomp $row;
$ret .= $row ."\n";
}
close $fh;
print "OK\n";
} else {
$ret = $_[2];
print "NOT FOUND - using default\n";
}
return $ret;
}
GetOptions( 'filehdr=s' => \$optHdr,
'fileftr=s' => \$optFtr,
'fileentry=s' => \$optEntry,
'infile=s' => \$optInfile,
'outfile=s' => \$optOutfile,
'encoding=s' => \$optEnc,
'num=i' => \$optNum,
'p|print' => \$optPrint,
'h|help' => \$optHelp,
'longhelp' => \$optLonghelp,
'q|quiet' => \$optQuiet );
my $old_fh = select(STDOUT);
$| = 1;
select($old_fh);
if ( !$optQuiet ) {
print ' _______ _____
\ \ ______ _ ________ / \ _____ ____
/ | \_/ __ \ \/ \/ / ___// \ / \\\\__ \ / ___\ by kuehlbox.wtf
/ | \ ___/\ /\___ \/ Y \/ __ \_/ /_/ > 2:240/5853
\____|__ /\___ >\/\_//____ >____|__ (____ /\___ /
\/ \/ \/ \/ \//_____/2k v'."$VER
_____________________________________________________________________________
";
}
if ( $optHelp || $optLonghelp ) {
print "NewsMag creates beautiful ansi files out of dull textfiles, so you can easily
provide your BBS users with a stylish news file without having to hassle with
an ansi editor everytime...
Parameters: --filehdr=newshdr.ans Header template
--fileftr=newsftr.ans Footer template
--fileentry=entryhdr.ans Entries template
--infile=news.txt Input text-file
--outfile=news.ans Output ansi-file
--encoding=CP437 Output file encoding
--num=0 Only display <num> entries (0=all)
-p | --print Print output to STDOUT
-q | --quiet Be quiet (overrides -p)
-h | --help Print this help
--longhelp Print more detailed help
";
}
if ( $optLonghelp ) {
print "
Files:
- news.txt
The input-file containing news formated like this:
<DATE>
<SUBJECT>
<CONTENT>
\@NEXT\@
<DATE>
<SUBJECT>
<CONTENT>
e.g:
2015-03-18
Hooray, I'm using NewsMag!
From now on and forever more, I'm using the infamous, so absolutely fabolous NewsMag by kuehlbox.wtf
\@NEXT\@
2015-03-19
This is incredible!
I just can't contain myself:
NewsMag just made my life complete!
- newshdr.ans
Header template. If not found, a default, hardcoded version will be used.
- entryhdr.ans
Template for the news entries. If not fount, a default version will be used.
This file has to contain some variables:
\@SUBJECT\@ Will be replaced by the <SUBJECT> from your news.txt,
padded to 32 characters added to the right, by default.
\@DATE\@ Will be replaced by the <DATE> from your news.txt,
padded to 16 characters added to the left, by default.
\@CONTENT\@ Will be replaced by the <CONTENT> from your news.txt, but
with a little bit of magic:
Lines will be wrapped at 78 characters, by default and every
new line will start with the same characters, the first line
did. See example entryhdr.ans for an example.
- newsftr.ans
Footer Template. If not found, a default version will be used.
This file has to contain a variable:
\@COPYRIGHT\@ Will be replaced by a short copyright-notice. If not found,
the copyright will be appended to the news.ans anyway..
- news.ans
The output-file to include into your BBS. Doesn't really have to be ansi -
combined with the --encoding switch, you can create a whole lot of different
formats...
Variable padding:
You can set the padding of a variable by adding <width><side>\@.
e.g: \@SUBJECT\@32R\@
This will pad the variable SUBJECT to 32 by adding whitespace
to the right.
";
}
if ( $optHelp || $optLonghelp ) {
exit 1;
}
print " - Parsing input file: " if !$optQuiet;
open($fh, '<:encoding(utf-8)', $optInfile)
or die "Could not open input-file '$optInfile'\n Try '-h' for help\n";
while (my $row = <$fh>) {
chomp $row;
if ( $row eq '@NEXT@' ) {
push( @newslist, [ @news ] );
undef @news;
} elsif ( defined $news[1] ) {
$news[2] .= $row ."\n";
} elsif ( defined $news[0] ) {
$news[1] = $row;
} else {
$news[0] = $row;
}
}
push( @newslist, [ @news ] );
undef @news;
@newslist = sort { $b->[0] cmp $a->[0] } @newslist;
print "OK\n" if !$optQuiet;
print " - Reading Templates:\n" if !$optQuiet;
print " - Header: " if !$optQuiet;
$output .= getTmpl( $optHdr, $optEnc, ' _______
\ \ ______ _ ________
/ | \_/ __ \ \/ \/ / ___/
/ | \ ___/\ /\___ \
\____|__ /\___ >\/\_//____ >
_______ \/ ___ \/ _________ \/ ______________________________________________
' );
print " - Entries: " if !$optQuiet;
$entryhdr .= getTmpl( $optEntry, $optEnc, "\n---[ \@SUBJECT\@32R\@ ]---------------[ \@DATE\@16L\@ ]---\n\@CONTENT\@\n" );
print " - Processing output: " if !$optQuiet;
foreach my $n ( @newslist ) {
$c++;
if ( $c > $optNum && $optNum > 0 ) {
last;
}
$etmp = $entryhdr;
( $sl, $sa ) = getPad( "$etmp", 'SUBJECT' );
( $dl, $da ) = getPad( "$etmp", 'DATE' );
( $cl, $ca ) = getPad( "$etmp", 'CONTENT' );
if ( $etmp =~ /(.*?)\@CONTENT/g ) {
$pre = $1;
} else {
$pre = '';
}
$stmp = padIt( @$n[1], $sl, $sa );
$dtmp = padIt( @$n[0], $dl, $da );
$cl += length( $pre );
$Text::Wrap::columns = $cl;
$ctmp = wrap( $pre, $pre, @$n[2] );
chomp( $ctmp );
$etmp =~ s/\@SUBJECT\@(?:(\d+)(.)\@)?/$stmp/g;
$etmp =~ s/\@DATE\@(?:(\d+)(.)\@)?/$dtmp/g;
$etmp =~ s/.*\@CONTENT\@(?:(\d+)(.)\@)?/$ctmp/g;
$output .= $etmp;
}
print "OK\n" if !$optQuiet;
print " - Appending Footer: " if !$optQuiet;
$output .= getTmpl( $optFtr, $optEnc, "\n---------------------------------[ \@COPYRIGHT\@ ]----\n" );
if ( $output =~ s/\@COPYRIGHT\@/$copyright/g ) {
print " - Copyright OK\n" if !$optQuiet;
} else {
print " - Copyright tag not found. Appending automatically.\n";
$output .= "\n$copyright\n" if !$optQuiet;
}
print " - Writing output file: " if !$optQuiet;
open($fh, ">:encoding($optEnc)", $optOutfile) or die "Could not open file '$optOutfile' $!\n";
print $fh $output;
close $fh;
print "OK\n" if !$optQuiet;
print "* FINISHED\n" if !$optQuiet;
if ( $optPrint && !$optQuiet ) {
print "\n____[ Your output looks something like that: ]_______________________________\n\n";
print encode('utf-8', $output );
print "\n";
}
print "\n" if !$optQuiet;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment