Use info.repl in updateDefineFromField, fix regex
This commit is contained in:
parent
12a3975341
commit
2647402095
3 changed files with 63 additions and 74 deletions
|
@ -6,8 +6,8 @@ body { margin: 0; padding: 0; background: #56A; color: #FFC; font-family: sans-s
|
||||||
#main { max-width: 1000px; margin: 0 auto; }
|
#main { max-width: 1000px; margin: 0 auto; }
|
||||||
#main { padding: 0 4%; width: 92%; }
|
#main { padding: 0 4%; width: 92%; }
|
||||||
#main { font-family: monospace; }
|
#main { font-family: monospace; }
|
||||||
|
h1, #message { text-align: center; }
|
||||||
#message { width: 80%; margin: 0 auto 0.25em; color: #FF0; text-align: center; }
|
#message { width: 80%; margin: 0 auto 0.25em; color: #FF0; }
|
||||||
#message p { padding: 2px 0; }
|
#message p { padding: 2px 0; }
|
||||||
#message p.error, #message p.message { color: #F00; background: #FF4; font-weight: bold; border-radius: 0.8em; }
|
#message p.error, #message p.message { color: #F00; background: #FF4; font-weight: bold; border-radius: 0.8em; }
|
||||||
#message p.message { color: #080; background: #CFC; }
|
#message p.message { color: #080; background: #CFC; }
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<section id="main">
|
<section id="main">
|
||||||
<h1>Marlin Configurator 0.1a</h1>
|
<h1>Marlin Configurator</h1>
|
||||||
|
|
||||||
<div id="message">
|
<div id="message">
|
||||||
<p class="info">Enter values in the form, get a Marlin configuration.<br/>Will include a drop-down of known configurations.</p>
|
<p class="info">Enter values in the form, get a Marlin configuration.<br/>Will include a drop-down of known configurations.</p>
|
||||||
|
|
|
@ -125,7 +125,7 @@ var configuratorApp = (function(){
|
||||||
complete: function() {
|
complete: function() {
|
||||||
ajax_count++;
|
ajax_count++;
|
||||||
if (ajax_count >= 3) {
|
if (ajax_count >= 3) {
|
||||||
$.each(config_files, function(i,fname){ if (typeof loaded_items[fname] != 'undefined') loaded_items[fname](); });
|
$.each(config_files, function(i,fname){ if (loaded_items[fname] !== undefined) loaded_items[fname](); });
|
||||||
self.refreshConfigForm();
|
self.refreshConfigForm();
|
||||||
if (success_count < ajax_count)
|
if (success_count < ajax_count)
|
||||||
self.setMessage('Unable to load configurations. Use the upload field instead.', 'error');
|
self.setMessage('Unable to load configurations. Use the upload field instead.', 'error');
|
||||||
|
@ -137,7 +137,7 @@ var configuratorApp = (function(){
|
||||||
|
|
||||||
setMessage: function(msg,type) {
|
setMessage: function(msg,type) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
if (typeof type == 'undefined') type = 'message';
|
if (type === undefined) type = 'message';
|
||||||
var $err = $('<p class="'+type+'">'+msg+'</p>'), err = $err[0];
|
var $err = $('<p class="'+type+'">'+msg+'</p>'), err = $err[0];
|
||||||
$('#message').prepend($err);
|
$('#message').prepend($err);
|
||||||
var baseColor = $err.css('color').replace(/rgba?\(([^),]+,[^),]+,[^),]+).*/, 'rgba($1,');
|
var baseColor = $err.css('color').replace(/rgba?\(([^),]+,[^),]+,[^),]+).*/, 'rgba($1,');
|
||||||
|
@ -155,7 +155,7 @@ var configuratorApp = (function(){
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('#message p.error, #message p.warning').each(function() {
|
$('#message p.error, #message p.warning').each(function() {
|
||||||
if (typeof this.pulser != 'undefined' && this.pulser)
|
if (this.pulser !== undefined && this.pulser)
|
||||||
clearInterval(this.pulser);
|
clearInterval(this.pulser);
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
|
@ -440,30 +440,16 @@ var configuratorApp = (function(){
|
||||||
switch(inf.type) {
|
switch(inf.type) {
|
||||||
case 'switch':
|
case 'switch':
|
||||||
var slash = val ? '' : '//';
|
var slash = val ? '' : '//';
|
||||||
newline = (inf.pre + slash + inf.define + inf.post);
|
newline = inf.line.replace(inf.repl, '$1'+slash+'$3');
|
||||||
break;
|
break;
|
||||||
case 'quoted':
|
case 'quoted':
|
||||||
if (isCheck) {
|
|
||||||
this.log(name + ' should not be a checkbox', 1);
|
|
||||||
var slash = val ? '' : '//';
|
|
||||||
newline = (inf.pre + slash + inf.define + '"'+val+'"' + inf.post);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
newline = inf.pre + inf.define + '"'+val+'"' + inf.post;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'plain':
|
case 'plain':
|
||||||
if (isCheck) {
|
if (isCheck)
|
||||||
this.log(name + ' should not be a checkbox', 1);
|
this.setMessage(name + ' should not be a checkbox!', 'error');
|
||||||
var slash = val ? '' : '//';
|
else
|
||||||
newline = (inf.pre + slash + inf.define + val + inf.post);
|
newline = inf.line.replace(inf.repl, '$1'+val.replace('$','\\$')+'$3');
|
||||||
}
|
|
||||||
else {
|
|
||||||
newline = inf.pre + inf.define + val + inf.post;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setDefineLine(name, newline);
|
this.setDefineLine(name, newline);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -536,7 +522,7 @@ var configuratorApp = (function(){
|
||||||
* Purge #define information for one of the config files
|
* Purge #define information for one of the config files
|
||||||
*/
|
*/
|
||||||
purgeDefineInfo: function(adv) {
|
purgeDefineInfo: function(adv) {
|
||||||
if (typeof adv == 'undefined') adv = false;
|
if (adv === undefined) adv = false;
|
||||||
$('[defineInfo]').each(function() {
|
$('[defineInfo]').each(function() {
|
||||||
if (adv === this.defineInfo.adv) $(this).removeProp('defineInfo');
|
if (adv === this.defineInfo.adv) $(this).removeProp('defineInfo');
|
||||||
});
|
});
|
||||||
|
@ -546,7 +532,7 @@ var configuratorApp = (function(){
|
||||||
* Update #define information for one of the config files
|
* Update #define information for one of the config files
|
||||||
*/
|
*/
|
||||||
refreshDefineInfo: function(adv) {
|
refreshDefineInfo: function(adv) {
|
||||||
if (typeof adv == 'undefined') adv = false;
|
if (adv === undefined) adv = false;
|
||||||
$('[defineInfo]').each(function() {
|
$('[defineInfo]').each(function() {
|
||||||
if (adv == this.defineInfo.adv) this.defineInfo = self.getDefineInfo(this.id, adv);
|
if (adv == this.defineInfo.adv) this.defineInfo = self.getDefineInfo(this.id, adv);
|
||||||
});
|
});
|
||||||
|
@ -561,7 +547,7 @@ var configuratorApp = (function(){
|
||||||
* Determine the line number of the #define so it can be scrolled to.
|
* Determine the line number of the #define so it can be scrolled to.
|
||||||
*/
|
*/
|
||||||
getDefineInfo: function(name, adv) {
|
getDefineInfo: function(name, adv) {
|
||||||
if (typeof adv == 'undefined') adv = false;
|
if (adv === undefined) adv = false;
|
||||||
this.log('getDefineInfo:'+name,4);
|
this.log('getDefineInfo:'+name,4);
|
||||||
var $elm = $('#'+name), elm = $elm[0];
|
var $elm = $('#'+name), elm = $elm[0];
|
||||||
var $c = adv ? $config_adv : $config;
|
var $c = adv ? $config_adv : $config;
|
||||||
|
@ -569,63 +555,66 @@ var configuratorApp = (function(){
|
||||||
// a switch line with no value
|
// a switch line with no value
|
||||||
var findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + ')([ \\t]*/[*/].*)?$', 'm');
|
var findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + ')([ \\t]*/[*/].*)?$', 'm');
|
||||||
var result = findDef.exec($c.text());
|
var result = findDef.exec($c.text());
|
||||||
|
var info = { type:0, adv:adv, field:$c[0], val_i: 2 };
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
var info = {
|
$.extend(info, {
|
||||||
type:'switch', adv:adv, field:$c[0], val_i: 1,
|
val_i: 1,
|
||||||
|
type: 'switch',
|
||||||
line: result[0], // whole line
|
line: result[0], // whole line
|
||||||
pre: result[1] === undefined ? '' : result[1].replace('//',''),
|
pre: result[1] === undefined ? '' : result[1].replace('//',''),
|
||||||
define: result[2],
|
define: result[2],
|
||||||
post: result[3] === undefined ? '' : result[3]
|
post: result[3] === undefined ? '' : result[3]
|
||||||
};
|
});
|
||||||
info.repl = info.regex = new RegExp('(.*//)?(.*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
|
info.regex = new RegExp('( *//)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
|
||||||
info.lineNum = this.getLineInText(info.line, $c.text());
|
info.repl = new RegExp('( *)(\/\/)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
|
||||||
this.log(info,2);
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// a define with quotes
|
// a define with quotes
|
||||||
findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
|
findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
|
||||||
result = findDef.exec($c.text());
|
result = findDef.exec($c.text());
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
var info = {
|
$.extend(info, {
|
||||||
type:'quoted', adv:adv, field:$c[0], val_i: 2,
|
type: 'quoted',
|
||||||
line: result[0],
|
line: result[0],
|
||||||
pre: result[1] === undefined ? '' : result[1].replace('//',''),
|
pre: result[1] === undefined ? '' : result[1].replace('//',''),
|
||||||
define: result[2],
|
define: result[2],
|
||||||
post: result[4] === undefined ? '' : result[4]
|
post: result[4] === undefined ? '' : result[4]
|
||||||
};
|
});
|
||||||
info.regex = new RegExp('(.*//)?.*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
|
info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
|
||||||
info.repl = new RegExp('((.*//)?.*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
|
info.repl = new RegExp('(( *//)? *' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
|
||||||
info.lineNum = this.getLineInText(info.line, $c.text());
|
|
||||||
this.log(info,2);
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// a define with no quotes
|
// a define with no quotes
|
||||||
findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
|
findDef = new RegExp('^( *//)?( *#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
|
||||||
result = findDef.exec($c.text());
|
result = findDef.exec($c.text());
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
var info = {
|
$.extend(info, {
|
||||||
type:'plain', adv:adv, field:$c[0], val_i: 2,
|
type: 'plain',
|
||||||
line: result[0],
|
line: result[0],
|
||||||
pre: result[1] === undefined ? '' : result[1].replace('//',''),
|
pre: result[1] === undefined ? '' : result[1].replace('//',''),
|
||||||
define: result[2],
|
define: result[2],
|
||||||
post: result[4] === undefined ? '' : result[4]
|
post: result[4] === undefined ? '' : result[4]
|
||||||
};
|
});
|
||||||
info.regex = new RegExp('(.*//)?.*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
|
info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
|
||||||
info.repl = new RegExp('((.*//)?.*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
|
info.repl = new RegExp('(( *//)? *' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
|
||||||
info.lineNum = this.getLineInText(info.line, $c.text());
|
}
|
||||||
this.log(info,2);
|
}
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
if (info.type) {
|
||||||
|
info.lineNum = this.getLineNumberOfText(info.line, $c.text());
|
||||||
|
this.log(info,2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
info = null;
|
||||||
|
|
||||||
|
return info;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count the number of lines before a match, return -1 on fail
|
* Count the number of lines before a match, return -1 on fail
|
||||||
*/
|
*/
|
||||||
getLineInText: function(line, txt) {
|
getLineNumberOfText: function(line, txt) {
|
||||||
var pos = txt.indexOf(line);
|
var pos = txt.indexOf(line);
|
||||||
return (pos < 0) ? pos : txt.substr(0, pos).lineCount();
|
return (pos < 0) ? pos : txt.substr(0, pos).lineCount();
|
||||||
},
|
},
|
||||||
|
@ -636,7 +625,7 @@ var configuratorApp = (function(){
|
||||||
},
|
},
|
||||||
|
|
||||||
logOnce: function(o) {
|
logOnce: function(o) {
|
||||||
if (typeof o.didLogThisObject === 'undefined') {
|
if (o.didLogThisObject === undefined) {
|
||||||
this.log(o);
|
this.log(o);
|
||||||
o.didLogThisObject = true;
|
o.didLogThisObject = true;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue