about summary refs log tree commit diff stats
path: root/translate_subx_debug
blob: 7f558fc9f85948d07aaa1dddc716da483055f05e (plain) (blame)
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
#!/bin/sh
# Translate given SubX files with debug information on Linux.
#
# Mu provides 3 canonical ways to translate unsafe SubX programs:
#   0. The C++ translator 'bootstrap translate' can generate traces for
#   debugging on Linux or BSD or Mac, but doesn't support any syntax sugar.
#   1. The self-hosted translator can be run natively on Linux using
#   'translate_subx'. It is fast and supports all syntax sugar, but you get no
#   trace for debugging.
#   2. The self-hosted translator can be run emulated on Linux or BSD or Mac
#   using 'translate_subx_emulated'. It supports all syntax sugar. However, it
#   can be slow if you generate traces.
#
# This script fills in the gap above by stitching together aspects from
# multiple approaches. It translates syntax sugar natively, but emulates lower
# levels using the C++ translator. The result is complete and relatively fast
# even when generating traces.
#
# The cost: it needs Linux. There is no script to generate traces while
# running emulated on BSD or Mac. That's often impractically slow.

set -e

./build

cat $*          |apps/braces          > a.braces
cat a.braces    |apps/calls           > a.calls
cat a.calls     |apps/sigils          > a.sigils

./bootstrap_bin --debug translate a.sigils -o a.elf

chmod +x a.elf
addf1cc3c1397a'>^
ff725e2b ^
fecebfe8 ^
1c907e9a ^
aa488bd9 ^
bf14a7e7 ^

2e9365cf ^
fecebfe8 ^

bf14a7e7 ^

356726c4 ^
bf14a7e7 ^

aa488bd9 ^

bf14a7e7 ^
356726c4 ^
fecebfe8 ^
ff725e2b ^


aa488bd9 ^

43e0f44a ^

43e0f44a ^
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
           


                                                                     
                                                                        
                                                                  
                                                                        

                         

                                                                

                                                        
                                                           








                                                                        

                                                                             


                                                         
 




                                                                            
 

                             
                                                                             
                                                                        

                                                           
                        
            
                                                       
                                             

                       
                                                                              

                                                                              

    
                   

                                          

                                                         
                                   
                
                                                                                  


                                                                                    

                                                      

    
      
#!/bin/bash
# This script is called whenever you preview a file.
# Its output is used as the preview.  ANSI color codes are supported.

# NOTES: This script is considered a configuration file.  If you upgrade
# ranger, it will be left untouched. (You must update it yourself)
# NEVER make this script interactive. (by starting mplayer or something)

# Meanings of exit codes:
# code | meaning    | action of ranger
# -----+------------+-------------------------------------------
# 0    | success    | success. display stdout as preview
# 1    | no preview | failure. display no preview at all
# 2    | plain text | display the plain content of the file
# 3    | fix width  | success. Don't reload when width changes
# 4    | fix height | success. Don't reload when height changes
# 5    | fix both   | success. Don't ever reload

# Meaningful aliases for arguments:
path="$1"    # Full path of the selected file
width="$2"   # Width of the preview pane (number of fitting characters)
height="$3"  # Height of the preview pane (number of fitting characters)

maxln=200    # Stop after $maxln lines.  Can be used like ls | head -n $maxln

# Find out something about the file:
mimetype=$(file --mime-type -Lb "$path")
extension=$(echo "$path" | grep '\.' | grep -o '[^.]\+$')

# Functions:
# "have $1" succeeds if $1 is an existing command/installed program
function have { type -P "$1" > /dev/null; }
# "sucess" returns the exit code of the first program in the last pipe chain
function success { test ${PIPESTATUS[0]} = 0; }

case "$extension" in
	# Archive extensions:
	7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
	rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
		atool -l "$path" | head -n $maxln && exit 3
		exit 1;;
	# PDF documents:
	pdf)
		pdftotext -q "$path" - | head -n $maxln
		success && exit 3 || exit 1;;
	# HTML Pages:
	htm|html|xhtml)
		have lynx   && lynx   -dump "$path" | head -n $maxln && exit 5
		have elinks && elinks -dump "$path" | head -n $maxln && exit 5
		;; # fall back to highlight/cat if theres no lynx/elinks
esac

case "$mimetype" in
	# Syntax highlight for text files:
	text/* | */xml)
		highlight --ansi "$path" | head -n $maxln
		success && exit 5 || exit 2;;
	# Ascii-previews of images:
	image/*)
		img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;;
	# Display information about media files:
	video/* | audio/*)
		# Use sed to remove spaces so the output fits into the narrow window
		mediainfo "$path" | sed 's/  \+:/: /;'
		success && exit 5 || exit 1;;
esac

exit 1