Home > Mac, Programming > Applescript to add inclusion guards to C++ Header files in Xcode

Applescript to add inclusion guards to C++ Header files in Xcode

I got tired of manually adding them, so here’s a little script…

set list_lib to load script alias “Path:To:List Utilities.scpt”

tell application “Xcode”

Get file name of front-most document (via window)

set header_file_path to associated file name of window 1

 

Go back and get the source file using the name

set header_file to first source document whose path is header_file_path

Turn the file into a list of lines to
— find the insertion point for the inclusion guard

set lines_of_header to paragraphs of text of header_file

Create the inclusion guard based on the file name

set inclusion_guard_token to first word of (get name of header_file) 
& “_H_INCLUDED_”

set guard_start to “\n#ifndef “ & inclusion_guard_token 
& “\n” & “#define “ & inclusion_guard_token & “\n”

 

Insert the start of the guard

set lines_of_header to list_lib‘s list_insert(lines_of_header, guard_start, 9)

Insert the end of the guard

set end of lines_of_header to “\n\n#endif”

Set the revised contents of the file

set text of header_file to (lines_of_header as text)

end tell

List Utilities.scpt (code from AppleScript: The Definitive Guide, 2nd Edition:

on find_in_list(what, L)

repeat with i from 1 to count L

if item i of L is what then

return (a reference to item i of L)

end if

end repeat

return

end find_in_list

on list_insert(L, what, ix)

if ix = 1 then

return {what} & L

else

return {item 1 of L} & list_insert(rest of L, what, ix - 1)

end if

end list_insert

Categories: Mac, Programming Tags: , ,

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip
\n