diff --git a/AVRsack.xcodeproj/project.pbxproj b/AVRsack.xcodeproj/project.pbxproj index 5722dc4..4ea99a3 100644 --- a/AVRsack.xcodeproj/project.pbxproj +++ b/AVRsack.xcodeproj/project.pbxproj @@ -539,7 +539,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx10.12; + SDKROOT = macosx10.13; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -577,7 +577,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx10.12; + SDKROOT = macosx10.13; }; name = Release; }; diff --git a/AVRsack/ASApplication.swift b/AVRsack/ASApplication.swift index c845dd3..379d67f 100644 --- a/AVRsack/ASApplication.swift +++ b/AVRsack/ASApplication.swift @@ -85,6 +85,8 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate { let examplePath = arduinoURL.appendingPathComponent("Contents/Resources/Java/examples", isDirectory:true).path ASSketchBook.addSketches(menu: menu, target: self, action: #selector(ASApplication.openExample(_:)), path: examplePath, sketches: &examples) } + ASLibraries.instance().addContribLibraryExamplesToMenu(menu: menu, sketches: &examples) + ASLibraries.instance().addStandardLibraryExamplesToMenu(menu: menu, sketches: &examples) case "Import Standard Library": menu.removeAllItems() ASLibraries.instance().addStandardLibrariesToMenu(menu: menu) diff --git a/AVRsack/ASHardware.swift b/AVRsack/ASHardware.swift index 193e28c..caa683d 100644 --- a/AVRsack/ASHardware.swift +++ b/AVRsack/ASHardware.swift @@ -189,6 +189,31 @@ class ASLibraries : NSObject { menuItem.tag = index } } + func addStandardLibraryExamplesToMenu(menu: NSMenu, sketches: inout [String]) { + addLibraryExamplesToMenu(library: standardLib, menu: menu, sketches: &sketches) + } + func addContribLibraryExamplesToMenu(menu: NSMenu, sketches: inout [String]) { + addLibraryExamplesToMenu(library: contribLib, menu: menu, sketches: &sketches) + } + func addLibraryExamplesToMenu(library: [String], menu: NSMenu, sketches: inout [String]) { + let fileManager = FileManager.default + let application = NSApplication.shared().delegate as! ASApplication + var hasSeparator = false + for (_,lib) in library.enumerated() { + let examplePath = (lib as NSString).appendingPathComponent("examples") + if fileManager.fileExists(atPath: examplePath) { + if !hasSeparator { + menu.addItem(NSMenuItem.separator()) + hasSeparator = true + } + let menuItem = menu.addItem(withTitle: (lib as NSString).lastPathComponent, action: nil, keyEquivalent: "") + let submenu = NSMenu() + submenu.autoenablesItems = false + ASSketchBook.addSketches(menu: submenu, target: application, action: #selector(ASApplication.openExample(_:)), path: examplePath, sketches: &sketches) + menu.setSubmenu(submenu, for: menuItem) + } + } + } @IBAction func importStandardLibrary(_ menuItem: AnyObject) { if let tag = (menuItem as? NSMenuItem)?.tag { NSApplication.shared().sendAction(#selector(ASProjDoc.importLibrary(_:)), to: nil, from: standardLib[tag]) diff --git a/AVRsack/BuildProject b/AVRsack/BuildProject index f77ec79..6c56f22 100755 --- a/AVRsack/BuildProject +++ b/AVRsack/BuildProject @@ -78,9 +78,9 @@ def parseInoFiles # Find protypes: prototypes = contents.dup # - Strip comments, quoted strings, and preprocessor directives - prototypes.gsub!(%r{'(?:[^']|\\')+'|"(?:[^"]|\\")*"|//.*?$|/\*.*?\*/|^\s*?#.*?$}m, ' ') + prototypes.gsub!(%r{'(?:\\'|[^'])+'|"(?:\\"|[^"])*"|//.*?$|/\*.*?\*/|^\s*?#.*?$}m, ' ') # Collapse braces - while prototypes.sub!(/(\{)(?:[^{}]+|\{[^{}]*\})/m, '\1') do + while prototypes.sub!(/(\{)([^{}]+|\{[^{}]*\})/m, '\1') do end existingProto = {} prototypes.scan(/[\w\[\]\*]+\s+[&\[\]\*\w\s]+\([&,\[\]\*\w\s]*\)(?=\s*;)/) {|p| @@ -92,7 +92,7 @@ def parseInoFiles proto << p+";\n" unless existingProto[p] } contents.each_line do |line| - if line =~ /^\s*#include\s+[<"](.*)[">]\s*(#.*)?$/ + if line =~ %r{^\s*#include\s+[<"](.*)[">]\s*(#.*|/\*.*?\*/\s*|//.*)?$} addLibrary($1) end end