-
Notifications
You must be signed in to change notification settings - Fork 2
/
fourkc
executable file
·105 lines (90 loc) · 2.77 KB
/
fourkc
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
#!/bin/bash
########################################################################
# FourK - Concatenative, stack based, Forth like language optimised for
# non-interactive 4KB size demoscene presentations.
#
# Copyright (C) 2009, 2010, 2011 Wojciech Meyer, Josef P. Bernhart
#
# This program 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/>.
########################################################################
quiet_job=
dirty_job=
verbose=
small=
in_file=
out_file=a.out
self=${0}
#bootstrap=src/bootstrap.4k
image4k=bin/image4k
fourk=bin/4k-party
ref_suffix=-ref
function usage()
{
echo "4K - an interactive tool for non-interactive 4KB presentations"
echo "Compiler front end."
echo "Idea at the Function 2009."
echo "Please use with precatious, might compress the Universe into 4k."
echo
echo "Syntax: ${0} [-q] [-o <out file name prefix> <sources>"
echo
echo "Options: "
echo " -q - quiet job control. Suppress stupid messages."
echo " -d - dirty job mode(sometimes called debug mode). Don't clean up any temporary files."
echo " -o <file name> - generate output file name, instead of ./4k"
echo
echo
}
function msg()
{
if [[ -z "${quiet_job}" ]]; then
echo "${*}"
fi
}
function fatal()
{
echo "Error: ${self}: ${1}" >&2;exit 1
}
# Standard house keeping, boring part
if [ "$#" -eq "0" ]; then
usage
exit 0
fi
while getopts "dqo:" opt; do
case ${opt} in
q) quiet_job=yes;;
d) dirty_job=yes;;
o) out_file=${OPTARG};;
*) fatal "Unrecognized option: ${opt}";;
esac
done
shift $(( ${OPTIND}-1 ))
rm -f boot.4k
##rm -f boot${ref_suffix}.4k
cat $1 >> boot.4k
##cat $1 >> boot${ref_suffix}.4k
echo "save-image boot.4ki" >> boot.4k
##echo "save-image boot${ref_suffix}.4ki" >> boot${ref_suffix}.4k
${fourk} < boot.4k
##${fourk}${ref_suffix} < boot${ref_suffix}.4k
cp ${fourk} temp
##${image4k} -link boot.4ki boot${ref_suffix}.4ki temp
${image4k} -link boot.4ki temp
cp temp ${out_file}
${image4k} -strip temp
# Compress it
cp unpack.header ${out_file}
lzma -c9 temp >> ${out_file}
chmod +x ${out_file}
msg $(ls -l temp | awk '{ print "Un-compressed size: " $5}')
msg $(ls -l ${out_file} | awk '{ print "Compressed size: " $5}')