 |
 |
BBEdit script: .c source -> compile - > run
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
hey there
i know that this is what project builder is meant for but since i'm used to bbedit, i prefer to code there...
anyway, i'm taking a university course in C and have been writing my source in bbedit and then working in the terminal to compile the program, change its file name and then execute the program...this was tedious at first but i've since gotten a little more unix savvy learning about command history and such. however, this is even getting tedious for instance if i make a bunch of little quick changes trying to see what happens (i'm used to web based, interpretted languages).
anyway, i was wondering if there's a way i can create a quick apple script or shell script that i can stick in the bbedit script menu that'll simply input these commands:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
>cc filename.c <font color = brown>// where filename is automatically extracted</font>
>mv a.out filename
>./filename
</font>[/code]
then, selecting the script compiles the sucker and exectues it for me...
so if there are any suggestions, or solutions, it's much appreciated,
thanks
amit
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Oct 2001
Location: Los Angeles
Status:
Offline
|
|
...kinda reminds me of emacs actually. I've always thought of BBEdit as Emacs for the Mac and wondered why it didn't do this (or at least make it obvious).
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Lisbon, Portugal
Status:
Offline
|
|
hum...meybe you'll be happier to know that you don't need to make that 'mv' command if you do something like 'cc source.c -o filename'
try it 
you can even make a script called run.sh that compiles everything and runs it...it's not that hard.
|
|
z0mbi3@TiBook 400 (w/384 MB RAM)
"One good thing about music, when it hits you you feel no pain" - Brad Nowell (Sublime) (Bob Marley's Cover - Trenchtown Rock)
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status:
Offline
|
|
OK, here's a rust-riddled attempt at producing something like a script to do what you requested from BBEdit. Saving it as a compiled script in BBEdit's scripts folder is probably the easiest way to access it from that editor: you might want to assign a keyboard shortcut as well.
A couple of things to watch for: as per the comment at the head of the script, your executable's return value has to be 0 for the "do shell script" command to succeed. At least that's my reading of the situation. "display dialog" might not be appropriate, depending on the size of the output that you're seeing. If you need acres of display space you might want to open a new bbedit window with that content.
Anyway, hope this at least gives you some ideas.
Cheers,
Paul
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
(* If the frontmost bbedit window is called <font color = red>"something.c"</font> and has been saved as
/path/to/source/something.c then this script should compile it using
<font color = red>"cc -o /path/to/source/something /path/to/source/something.c"</font> and then run it via
<font color = red>"/path/to/source/something"</font>. Things to watch for: your executable should exit
cleanly, or you'll get the same <font color = red>"execution error"</font> output from <font color = red>"do shell script"</font>
that plagued me while writing what's below. Looks like that command just groans
when it sees anything other than an exit status of <font color = blue>0.</font> *)
tell application <font color = red>"BBEdit <font color = blue>6.5</font>"</font>
set open_filename to the name of window <font color = blue>1</font> -- filename of the frontmost file in bbedit
if ((text items <font color = blue>-2</font> thru <font color = blue>-1</font> of open_filename) as text) is not <font color = red>".c"</font> then
tell me to activate
display dialog <font color = red>"Sorry, not a .c file"</font>
return
else if (modified of window <font color = blue>1</font>) then
activate
set save_flag to display dialog <font color = red>"Save your work first, then compile!"</font> buttons {<font color = red>"Cancel"</font>, <font color = red>"Save"</font>} default button <font color = red>"Save"</font>
if button returned of save_flag is <font color = red>"Save"</font> then
save window <font color = blue>1</font>
else
return
end if
end if
set bare_name to (text items <font color = blue>1</font> thru <font color = blue>-3</font> of open_filename) as text --ie, without suffix
set assoc_file to POSIX path of ((file of window <font color = blue>1</font>) as text) -- unix-style path to file
my shellit(open_filename, bare_name, assoc_file)
end tell
on shellit(source_file, output_file, path_to_source)
set working_dir to my parentdir(path_to_source)
set compile_command to <font color = red>"cc -o "</font> & working_dir & <font color = red>"/"</font> & output_file & <font color = red>" "</font> & working_dir & <font color = red>"/"</font> & source_file
set run_command to working_dir & <font color = red>"/"</font> & output_file
set shelloutput to do shell script compile_command
set shelloutput to do shell script run_command
activate
display dialog <font color = red>"\"</font>" & output_file & <font color = red>"\"</font> produced the following output:" & return & shelloutput
end shellit
on parentdir(unix_filepath)
set olddelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to <font color = red>"/"</font>
set path_to_dir to (text items <font color = blue>1</font> thru <font color = blue>-2</font> of unix_filepath) as text
set AppleScript's text item delimiters to olddelims
return path_to_dir
end parentdir
</font>[/code]
[ 02-06-2002: Message edited by: Paul McCann ]
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
Originally posted by z0mbi3:
<STRONG>hum...meybe you'll be happier to know that you don't need to make that 'mv' command if you do something like 'cc source.c -o filename'
try it 
you can even make a script called run.sh that compiles everything and runs it...it's not that hard.</STRONG>
well, that helps some...and paul, thanks for the applescript, i'll be trying that shortly once i completely understand what's going on that script...despite applescripts desire to sound more like english, i find it even more foreign looking than actual code.
anyway, thanks for your help...
amit
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Aug 2001
Location: CA
Status:
Offline
|
|
There's no reason why you can't edit the file in BBEdit, and compile/run/debug with project builder at the same time. PB will know that you changed the file. No fancy scripts required.
|
|
Dual 800 - GF3 - 1.5GB
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|