Skip to content

Commit 23fdf78

Browse files
committed
Gadgets/Coliru: Fetch default compiler and language from element class
1 parent cd8e45b commit 23fdf78

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

gadgets/coliru_compiler.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,48 @@ function Editor(root) {
6363
opt: ' -O2 -Wall -Wextra -pedantic -pthread -pedantic-errors main.cpp -lm ',
6464
}
6565

66+
var std_ids = {
67+
'cxx98' : { c: 'cxx', id: 5 },
68+
'cxx03' : { c: 'cxx', id: 5 },
69+
'cxx11' : { c: 'cxx', id: 6 },
70+
'cxx14' : { c: 'cxx', id: 7 },
71+
'c89' : { c: 'cc', id: 4 },
72+
'c99' : { c: 'cc', id: 5 },
73+
'c11' : { c: 'cc', id: 5 }
74+
}
75+
76+
this.get_std_id = function() {
77+
if (this.root.hasClass('t-example-std-cxx98'))
78+
return 'cxx98'
79+
if (this.root.hasClass('t-example-std-cxx03'))
80+
return 'cxx03'
81+
if (this.root.hasClass('t-example-std-cxx11'))
82+
return 'cxx11'
83+
if (this.root.hasClass('t-example-std-cxx14'))
84+
return 'cxx14'
85+
if (this.root.hasClass('t-example-std-c89'))
86+
return 'c89'
87+
if (this.root.hasClass('t-example-std-c99'))
88+
return 'c99'
89+
if (this.root.hasClass('t-example-std-c11'))
90+
return 'c11'
91+
return null;
92+
}
93+
94+
this.std_id = this.get_std_id();
95+
6696
this.check_is_cxx = function() {
67-
if (mw.config.get('wgTitle').indexOf('c/') == 0) {
68-
return false;
69-
} else {
70-
return true;
97+
if (this.std_id == null) {
98+
if (mw.config.get('wgTitle').indexOf('c/') == 0) {
99+
return false;
100+
} else {
101+
return true;
102+
}
71103
}
104+
105+
if (this.std_ids[this.std_id].c == 'cc')
106+
return false
107+
return true
72108
};
73109

74110
if (this.check_is_cxx()) {
@@ -77,6 +113,16 @@ function Editor(root) {
77113
this.cmd_info = cmd_info_c;
78114
}
79115

116+
this.get_cmd_default_id = function() {
117+
if (this.std_id == null) {
118+
return this.cmd_info.default_id;
119+
} else {
120+
return this.cmd_ids[this.cmd_id].id;
121+
}
122+
}
123+
124+
this.cmd_default_id = this.get_cmd_default_id();
125+
80126
this.cmd_run_normal = ' 2>&1 | sed "s/^/☘/"; if [ -x a.out ]; then ./a.out | sed "s/^/☢/"; fi'
81127
this.cmd_run_share = ' && ./a.out';
82128

@@ -108,7 +154,7 @@ function Editor(root) {
108154
$('<option/>').text(cmd.title).attr('value', i.toString())
109155
.appendTo(this.el.cc_select);
110156
}
111-
this.el.cc_select.val(this.cmd_info.default_id.toString());
157+
this.el.cc_select.val(this.cmd_default_id.toString());
112158

113159
this.el.pwr = $('<div>Powered by <a href="http://coliru.stacked-crooked.com">Coliru</a> online compiler</div>')
114160
.addClass('coliru-powered')

0 commit comments

Comments
 (0)