From f994729999b9512693be15a16097fa21410031ba Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 28 Feb 2015 22:40:20 -0800 Subject: [PATCH] Parse and use dependent groups - Parse #if, #ifdef, etc. for rules to enable fields --- Marlin/configurator/css/configurator.css | 4 + Marlin/configurator/index.html | 2 +- Marlin/configurator/js/configurator.js | 276 +++++++++++++++++------ 3 files changed, 214 insertions(+), 68 deletions(-) diff --git a/Marlin/configurator/css/configurator.css b/Marlin/configurator/css/configurator.css index 645907f0a..a0874507e 100644 --- a/Marlin/configurator/css/configurator.css +++ b/Marlin/configurator/css/configurator.css @@ -91,6 +91,8 @@ label { margin-right: -450px; text-align: right; } +label.blocked { color: #AAA; } + input[type="text"], select { margin: 0.75em 0 0; } input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; } input[type="checkbox"].enabler, input[type="radio"].enabler { margin-left: 1em; } @@ -308,3 +310,5 @@ a.download-all { margin: 9px 2em 0; color: #449; border-color: #449; } .disclose { display: none; } } + +/*.blocked { display: none; }*/ diff --git a/Marlin/configurator/index.html b/Marlin/configurator/index.html index aad6736e2..a804e7c74 100644 --- a/Marlin/configurator/index.html +++ b/Marlin/configurator/index.html @@ -26,7 +26,7 @@
- + Download Zip diff --git a/Marlin/configurator/js/configurator.js b/Marlin/configurator/js/configurator.js index 81dacd4ca..1405bea20 100644 --- a/Marlin/configurator/js/configurator.js +++ b/Marlin/configurator/js/configurator.js @@ -142,8 +142,10 @@ window.configuratorApp = (function(){ $tooltip = $('#tooltip'), $cfg = $('#config_text'), $adv = $('#config_adv_text'), $config = $cfg.find('pre'), $config_adv = $adv.find('pre'), + define_info = {}, define_list = [[],[]], define_section = {}, + dependentGroups = {}, boards_list = {}, therms_list = {}, total_config_lines, @@ -321,7 +323,7 @@ window.configuratorApp = (function(){ /** * Init the thermistors array from the Configuration.h file */ - initThermistorsFromText: function(txt) { + initThermistorList: function(txt) { // Get all the thermistors and save them into an object var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g'); r = findDef.exec(txt); @@ -334,7 +336,7 @@ window.configuratorApp = (function(){ /** * Get all the unique define names */ - updateDefinesFromText: function(index, txt) { + initDefineList: function(index, txt) { var section = 'hidden', leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'], define_sect = {}, @@ -343,7 +345,7 @@ window.configuratorApp = (function(){ var name = r[2]; if (r[1] == '@section') section = name; - else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_sect)) + else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect)) define_sect[name] = section; } define_list[index] = Object.keys(define_sect); @@ -351,22 +353,101 @@ window.configuratorApp = (function(){ this.log(define_list[index], 2); }, + /** + * Get all condition blocks and their line ranges. + * Conditions may control multiple line-ranges + * across both config files. + */ + initDependentGroups: function() { + var findDef = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm, + leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H']; + $.each([$config, $config_adv], function(i, $v) { + var ifStack = []; + var r, txt = $v.text(); + while((r = findDef.exec(txt)) !== null) { + var lineNum = txt.substr(0, r.index).lineCount(); + var code = r[2].replace(/[ \t]*\/\/.*$/, ''); + switch(r[1]) { + case 'if': + var code = code + .replace(/([A-Z][A-Z0-9_]+)/g, 'self.defineValue("$1")') + .replace(/defined[ \t]*\(?[ \t]*self.defineValue\(("[A-Z][A-Z0-9_]+")\)[ \t]*\)?/g, 'self.defineIsEnabled($1)'); + ifStack.push(['('+code+')', lineNum]); // #if starts on next line + self.log("push if " + code, 4); + break; + case 'ifdef': + if ($.inArray(code, leave_out_defines) < 0) { + ifStack.push(['self.defineIsEnabled("' + code + '")', lineNum]); + self.log("push ifdef " + code, 4); + } + else { + ifStack.push(0); + } + break; + case 'ifndef': + if ($.inArray(code, leave_out_defines) < 0) { + ifStack.push(['!self.defineIsEnabled("' + code + '")', lineNum]); + self.log("push ifndef " + code, 4); + } + else { + ifStack.push(0); + } + break; + case 'else': + case 'endif': + var c = ifStack.pop(); + if (c) { + var cond = c[0], line = c[1]; + self.log("pop " + c[0], 4); + if (dependentGroups[cond] === undefined) dependentGroups[cond] = []; + dependentGroups[cond].push({adv:i,start:line,end:lineNum}); + if (r[1] == 'else') { + // Reverse the condition + cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond); + ifStack.push([cond, lineNum]); + self.log("push " + cond, 4); + } + } + else { + if (r[1] == 'else') ifStack.push(0); + } + break; + } + } + }); // text blobs loop + }, + + /** + * Init all the defineInfo structures after reload + * The "enabled" field may need an update for newly-loaded dependencies + */ + initDefineInfo: function() { + $.each(define_list, function(e,def_list){ + var adv = e == 1; + $.each(def_list, function(i,name) { + define_info[name] = self.getDefineInfo(name, adv); + }); + }); + }, + /** * Create fields for any defines that have none */ - createFieldsForDefines: function(adv) { - var e = adv ? 1 : 0, n = 0; - var fail_list = []; + createFieldsForDefines: function(e) { + var n = 0, fail_list = []; $.each(define_list[e], function(i,name) { var section = define_section[name]; if (section != 'hidden' && !$('#'+name).length) { - var inf = self.getDefineInfo(name, adv); + var inf = define_info[name]; if (inf) { var $ff = $('#'+section), $newfield, + avail = eval(inf.enabled), $newlabel = $('