Skip to content

Commit ca13f10

Browse files
committed
refactor: use CArgs in C
1 parent 26b5e53 commit ca13f10

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

lib/grammars/c.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const windows = OperatingSystem.isWindows()
1010
const options = "-Wall -include stdio.h"
1111

1212
// TODO add windows support
13-
function args({ filepath }) {
13+
function CArgs({ filepath }) {
1414
let cmdArgs = ""
1515
switch (os) {
1616
case "darwin":
@@ -29,20 +29,8 @@ function args({ filepath }) {
2929
const C = {
3030
"File Based": {
3131
command: "bash",
32-
args({ filepath }) {
33-
let cmdArgs = ""
34-
switch (os) {
35-
case "darwin":
36-
cmdArgs = `xcrun clang ${options} -fcolor-diagnostics '${filepath}' -o /tmp/c.out && /tmp/c.out`
37-
break
38-
case "linux":
39-
cmdArgs = `cc ${options} '${filepath}' -o /tmp/c.out && /tmp/c.out`
40-
break
41-
default: {
42-
atom.notifications.addError(`Not support on ${os}`)
43-
}
44-
}
45-
return ["-c", cmdArgs]
32+
args(opts) {
33+
return CArgs(opts)
4634
},
4735
},
4836

@@ -51,20 +39,7 @@ const C = {
5139
args(context) {
5240
const code = context.getCode()
5341
const tmpFile = GrammarUtils.createTempFileWithCode(code, ".c")
54-
let cmdArgs = ""
55-
switch (os) {
56-
case "darwin":
57-
cmdArgs = `xcrun clang ${options} -fcolor-diagnostics ${tmpFile} -o /tmp/c.out && /tmp/c.out`
58-
break
59-
case "linux":
60-
cmdArgs = `cc ${options} ${tmpFile} -o /tmp/c.out && /tmp/c.out`
61-
break
62-
default: {
63-
atom.notifications.addError(`Not support on ${os}`)
64-
}
65-
}
66-
67-
return ["-c", cmdArgs]
42+
return CArgs({ filepath: tmpFile })
6843
},
6944
},
7045
}

0 commit comments

Comments
 (0)