-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsb2-superforth.sh
executable file
·109 lines (77 loc) · 2.23 KB
/
fsb2-superforth.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
# fsb2-superforth.sh
# This file is part of fsb2
# http://programandala.net/en.program.fsb2.html
# ##############################################################
# Author and license
# Copyright (C) 2015,2020 Marcos Cruz (programandala.net)
# You may do whatever you want with this work, so long as you
# retain the copyright notice(s) and this license in all
# redistributed copies and derived works. There is no warranty.
# ##############################################################
# Description
# This program converts a Forth source file from the FSB format
# to a set of individual block files suitable for Sinclair QL
# SuperForth.
# ##############################################################
# Requirements
# fsb2:
# <http://programandala.net/en.program.fsb2.html>
#
# mmv, by Vladimir Lanin:
# Included in most Linux distros.
# ##############################################################
# Usage (after installation)
# fsb2-superforth filename.fsb
# ##############################################################
# History
# 2015-12-28: Start.
#
# 2015-12-31: Removed the redirection from `mmv`; it was a
# remain of a previous version and caused trouble.
#
# 2016-08-13: Typo.
# ##############################################################
# Error checking
if [ "$#" -ne 1 ] ; then
echo "Convert a Forth source file from .fsb to SuperForth block files"
echo 'Usage:'
echo " ${0##*/} sourcefile.fsb"
exit 1
fi
if [ ! -e "$1" ] ; then
echo "Error: <$1> does not exist"
exit 1
fi
if [ ! -f "$1" ] ; then
echo "Error: <$1> is not a regular file"
exit 1
fi
if [ ! -r "$1" ] ; then
echo "Error: <$1> can not be read"
exit 1
fi
if [ ! -s "$1" ] ; then
echo "Error: <$1> is empty"
exit 1
fi
# ##############################################################
# Main
fsb2 $1
# Get the filenames:
basefilename=${1%.*}
blocksfile=$basefilename.fb
# Split the blocks file into individual files of one block:
split \
--bytes=1024 \
--numeric-suffixes \
--suffix-length=4 \
$blocksfile BLK
# Rename the block files, remove the leading zeros from the
# numeric suffix:
mmv "BLK*[1-9]*" "BLK#2#3"
# Remove block 0:
rm -f BLK0*
# Remove the blocks file:
rm -f $blocksfile
# vim:tw=64:ts=2:sts=2:et: