geekrelief / fcsh-scripts

Scripts to startup the Flex Compiler Shell as a background process built on top of vim / fcsh scripts by Mike Rowe http://www.vim.org/scripts/script.php?script_id=1793

This URL has Read+Write access

Don-Duong Quach (author)
Mon Apr 27 13:13:09 -0700 2009
fcsh-scripts / fcshserv.sh
100755 67 lines (59 sloc) 1.726 kb
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
#!/bin/bash
#creates a named pipe. reads from it. sends to fcsh. parses output of fcsh.
 
#get resources.
if [[ "$FCSH_VIM_ROOT" = "" ]]; then
FCSH_VIM_ROOT="$HOME/bin"
fi
source "$FCSH_VIM_ROOT/fcshrc.sh"
prog="fcsh"
 
# create lock directory
if mkdir "$lockdir"; then
echo "$lockdir created"
else
echo >&2 "$lockdir found. Can't continue."
    echo >&2 "killall fcsh && rm -rf $lockdir"
    exit 1
fi
 
#initialization
mkfifo "$pipein"
trap "rm -rf $lockdir" 0
trap "exit 2" 2 9 15
 
function process_fcsh_output {
#processes output of fcsh
while read line; do
echo "$line"
    if [[ "$line" == *Error* ]]; then
echo >&2 "[INFO] compilation error."
        echo "$cmpbad" > "$cmpdone"
    elif [[ "$line" == Recompile* ]]; then
echo >&2 "[INFO] incremental compilation attempt without initial compilation."
        echo "$cmpre" > "$cmpdone"
    elif [[ "$line" == *.swf\ \(* ]]; then
echo >&2 "[INFO] compilation finished."
        echo "$cmpnice" > "$cmpdone"
    elif [[ "$line" == *Assigned* ]]; then
echo >&2 "[INFO] possible id assignment."
        line="${line##*Assigned }"
        line="${line%% *}"
        if [[ "$line" == [0-9]* ]]; then
echo >&2 "[INFO] id assigned: $line"
            echo "$line" > "$idcurr"
        fi
elif [[ "$line" == \(fcsh\)* ]]; then
echo >&2 "[INFO] fcsh prompt."
        rm -rf "$cmpdone"
        echo >&2 "[INFO] $cmpdone removed"
    fi
done
}
 
function send_to_fcsh {
#reads from $pipein and sends it to fcsh
#also, writes output of fcsh to $pipeout
while sleep 1; do
read line < "$pipein"
    echo "$line"
done | "$prog" 2>&1 | process_fcsh_output
}
 
#main
echo >&2 "[INFO] starting server."
send_to_fcsh