mcc-compiler 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/mcc ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../src/index.js');
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "mcc-compiler",
3
+ "version": "1.0.0",
4
+ "description": "Majo C Compiler - 一个有教养的编译器,必须说 --please 才会编译",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "mcc": "bin/mcc"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node scripts/postinstall.js",
11
+ "preuninstall": "node scripts/preuninstall.js"
12
+ },
13
+ "keywords": [
14
+ "compiler",
15
+ "gcc",
16
+ "wrapper",
17
+ "majo",
18
+ "fun"
19
+ ],
20
+ "author": "0x1a27",
21
+ "license": "MIT",
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
25
+ "files": [
26
+ "bin/",
27
+ "src/",
28
+ "scripts/",
29
+ "README.md"
30
+ ]
31
+ }
package/readme.md ADDED
@@ -0,0 +1,150 @@
1
+ # mcc — Majo C Compiler
2
+
3
+ 一个有教养的编译器。只有你说"请"的时候,她才会帮你编译。
4
+
5
+ > ⚠️ **安全提示:请务必阅读!**
6
+ > 本软件在安装时会将 `/usr/bin/gcc` 替换为指向 `mcc` 的软链接,原 `gcc` 会被备份到 `/usr/bin/gcc.real`。
7
+ > 请确保您已了解此行为,并在安装前备份您的系统。
8
+
9
+
10
+ ## ⚠️ 安全风险说明
11
+
12
+ ### 这是什么?
13
+
14
+ `mcc` 会在安装时自动执行以下操作:
15
+
16
+ 1. 将 `/usr/bin/gcc` 替换为指向 `mcc` 的软链接
17
+ 2. 原 `gcc` 会被重命名为 `/usr/bin/gcc.real`(如果存在)
18
+
19
+ 这意味着:**你输入 `gcc` 时,实际上运行的是 `mcc`,而不是真正的 `gcc`。**
20
+
21
+ ### 潜在风险
22
+
23
+ | 风险 | 影响 | 缓解措施 |
24
+ |---|---|---|
25
+ | **编译脚本失效** | 脚本中硬编码的 `gcc` 命令会触发吃醋报错,导致编译失败 | 使用 `mcc --please --gcc` 临时调用真正的 gcc |
26
+ | **自动化构建中断** | CI/CD、Makefile、npm install 等依赖 `gcc` 的流程可能中断 | 在脚本中使用 `gcc.real` 替代 `gcc` |
27
+ | **系统恢复困难** | 如果卸载不当,可能导致 `gcc` 命令丢失 | 使用 `npm uninstall` 会自动恢复;或手动恢复:`sudo rm /usr/bin/gcc && sudo mv /usr/bin/gcc.real /usr/bin/gcc` |
28
+ | **其他软件依赖** | 部分软件在安装时会调用 `gcc` 进行编译,可能失败 | 临时使用 `gcc.real` 或提前恢复 |
29
+
30
+ ### 谁不应该使用这个包?
31
+
32
+ - ❌ 在生产环境使用
33
+ - ❌ 在需要稳定编译的服务器上使用
34
+ - ❌ 在无法处理编译失败的 CI/CD 流程中使用
35
+ - ❌ 在没有 root/sudo 权限的环境中使用
36
+ - ❌ 在不了解软链接含义的情况下使用
37
+
38
+ ### 谁应该使用?
39
+
40
+ - ✅ 个人开发环境(WSL / Linux 桌面)
41
+ - ✅ 想体验"编译器吃醋"的整活场景
42
+ - ✅ 能接受编译失败并手动恢复的用户
43
+
44
+ ### 如何安全使用?
45
+
46
+ ```bash
47
+ # 当需要真正使用 gcc 时,用这个命令:
48
+ mcc --please --gcc hello.c
49
+
50
+ # 或者直接调用备份的原 gcc:
51
+ gcc.real hello.c
52
+
53
+ # 或者临时解除劫持:
54
+ sudo rm /usr/bin/gcc
55
+ sudo mv /usr/bin/gcc.real /usr/bin/gcc
56
+ # 使用完后重新劫持:
57
+ sudo npm install -g mcc-compiler # 会重新创建软链接
58
+
59
+ 安装
60
+ bash
61
+ # ⚠️ 需要 sudo 权限(因为要修改 /usr/bin/gcc)
62
+ sudo npm install -g mcc-compiler
63
+ 安装时会自动:
64
+
65
+ ✅ 在 /usr/bin/gcc 创建指向 mcc 的软链接
66
+
67
+ ✅ 原 gcc 备份到 /usr/bin/gcc.real
68
+
69
+ 用法
70
+ bash
71
+ # ❌ 没礼貌 → 吃醋报错
72
+ gcc hello.c
73
+
74
+ # ❌ 没礼貌 → 报错(mcc 直接调用)
75
+ mcc hello.c
76
+
77
+ # ✅ 有礼貌 → 编译成功
78
+ mcc --please hello.c
79
+
80
+ # ✅ 所有 gcc 参数都支持
81
+ mcc --please -Wall -O2 -o hello hello.c
82
+
83
+ # ✅ 彩蛋:让她更开心
84
+ mcc --please --sama hello.c
85
+ mcc --please --sensei hello.c
86
+
87
+ # ✅ 临时放行到真正的 gcc
88
+ mcc --please --gcc hello.c
89
+ 规则
90
+ 命令 结果
91
+ gcc hello.c ❌ 吃醋报错
92
+ mcc hello.c ❌ 没礼貌报错
93
+ mcc --please hello.c ✅ 编译成功
94
+ mcc --please --sama hello.c ❤️ 额外加心情
95
+ mcc --please --sensei hello.c 📚 额外加心情
96
+ mcc --please --gcc hello.c ✅ 放行给真正的 gcc
97
+ 卸载
98
+ bash
99
+ npm uninstall -g mcc-compiler
100
+ 卸载时会自动:
101
+
102
+ ✅ 移除 /usr/bin/gcc 软链接
103
+
104
+ ✅ 从 /usr/bin/gcc.real 恢复原 gcc
105
+
106
+ 手动恢复
107
+ 如果卸载时未自动恢复,或你想手动恢复:
108
+
109
+ bash
110
+ sudo rm /usr/bin/gcc
111
+ sudo mv /usr/bin/gcc.real /usr/bin/gcc
112
+ 如果备份文件不存在:
113
+
114
+ bash
115
+ # 用包管理器重新安装 gcc
116
+ # Ubuntu / Debian / WSL:
117
+ sudo apt update
118
+ sudo apt install --reinstall gcc
119
+
120
+ # 或者从 /usr/bin/gcc.real 恢复(如果存在)
121
+ 配置
122
+ bash
123
+ # 设置初始心情值(0-100)
124
+ echo "mood=50" > ~/.mccrc
125
+ 常见问题
126
+ Q: 安装后 gcc 命令失效了怎么办?
127
+
128
+ A: 运行 sudo rm /usr/bin/gcc && sudo mv /usr/bin/gcc.real /usr/bin/gcc 恢复。然后考虑是否真的想使用这个包。
129
+
130
+ Q: Makefile 编译失败怎么办?
131
+
132
+ A: 把 Makefile 中的 gcc 改成 gcc.real,或者使用 mcc --please --gcc。
133
+
134
+ Q: 我不想劫持 gcc,只想用 mcc 命令怎么办?
135
+
136
+ A: 安装后手动删除软链接恢复 gcc,只用 mcc --please 命令即可。
137
+
138
+ Q: 我误装了,想完全移除怎么办?
139
+
140
+ A: npm uninstall -g mcc-compiler,然后 sudo apt install --reinstall gcc 恢复系统 gcc。
141
+
142
+ 许可证
143
+ MIT
144
+
145
+ 免责声明
146
+ 使用本软件即表示您已了解并接受以下条款:
147
+
148
+ 本软件会修改系统的 gcc 命令(通过软链接)。虽然提供了自动备份和恢复机制,但作者不对因使用本软件导致的任何编译失败、系统异常或数据损失承担责任。请务必在理解其工作原理后使用,并自行承担风险。
149
+
150
+ Built with ❤️ and ☕ | Updated 2026
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { execSync } = require('child_process');
6
+
7
+ console.log('🔧 mcc 正在安装...\n');
8
+
9
+ // ----- 1. 找到 mcc 的真实路径 -----
10
+ function getMccPath() {
11
+ try {
12
+ const result = execSync('which mcc', { encoding: 'utf8' });
13
+ return result.trim();
14
+ } catch (_) {
15
+ // 如果 which 找不到,尝试常见路径
16
+ const candidates = [
17
+ '/usr/bin/mcc',
18
+ '/usr/local/bin/mcc',
19
+ path.join(process.env.HOME, '.npm-global/bin/mcc'),
20
+ path.join(process.env.HOME, '.nvm/current/bin/mcc'),
21
+ ];
22
+ for (const c of candidates) {
23
+ if (fs.existsSync(c)) return c;
24
+ }
25
+ return null;
26
+ }
27
+ }
28
+
29
+ function isWsl() {
30
+ try {
31
+ const release = fs.readFileSync('/proc/version', 'utf8');
32
+ return release.toLowerCase().includes('microsoft');
33
+ } catch (_) {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ // ----- 2. 劫持 gcc -----
39
+ function hijackGcc() {
40
+ const mccPath = getMccPath();
41
+ if (!mccPath) {
42
+ console.error('❌ 找不到 mcc 命令!请先运行: npm link');
43
+ return;
44
+ }
45
+
46
+ const gccPath = '/usr/bin/gcc';
47
+
48
+ // 如果 gcc 已经是指向 mcc 的软链接,跳过
49
+ try {
50
+ const stats = fs.lstatSync(gccPath);
51
+ if (stats.isSymbolicLink()) {
52
+ const target = fs.readlinkSync(gccPath);
53
+ if (target === mccPath) {
54
+ console.log('✅ gcc 已经指向 mcc,无需重复配置');
55
+ return;
56
+ }
57
+ // 如果是指向其他目标的软链接,备份后覆盖
58
+ console.log(`⚠️ 发现已有的 gcc 软链接指向 ${target},将备份`);
59
+ }
60
+ } catch (_) {
61
+ // gcc 不存在,直接创建
62
+ }
63
+
64
+ // 备份原 gcc(如果不是软链接)
65
+ try {
66
+ const stats = fs.lstatSync(gccPath);
67
+ if (!stats.isSymbolicLink()) {
68
+ const backupPath = '/usr/bin/gcc.real';
69
+ if (!fs.existsSync(backupPath)) {
70
+ fs.renameSync(gccPath, backupPath);
71
+ console.log(`✅ 已备份原 gcc 到 ${backupPath}`);
72
+ } else {
73
+ console.log(`⚠️ 备份文件已存在: ${backupPath},保留`);
74
+ }
75
+ }
76
+ } catch (_) {
77
+ // gcc 不存在,无需备份
78
+ }
79
+
80
+ // 创建软链接(或覆盖已有链接)
81
+ try {
82
+ // 先删除可能存在的旧链接
83
+ if (fs.existsSync(gccPath)) {
84
+ fs.unlinkSync(gccPath);
85
+ }
86
+ fs.symlinkSync(mccPath, gccPath);
87
+ console.log(`✅ 已创建软链接: ${gccPath} -> ${mccPath}`);
88
+ console.log(' 🎯 现在输入 gcc 会触发 mcc 的吃醋机制!');
89
+ console.log(' 💡 如需恢复,请运行: sudo rm /usr/bin/gcc && sudo mv /usr/bin/gcc.real /usr/bin/gcc');
90
+ } catch (err) {
91
+ console.error('❌ 创建软链接失败:', err.message);
92
+ console.error(' 请尝试手动执行:');
93
+ console.error(` sudo ln -sf ${mccPath} /usr/bin/gcc`);
94
+ }
95
+ }
96
+
97
+ // ----- 3. 主流程 -----
98
+ function main() {
99
+ // 检查是否有 root 权限(WSL 下经常需要)
100
+ try {
101
+ execSync('touch /usr/bin/.mcc_test', { stdio: 'ignore' });
102
+ execSync('rm /usr/bin/.mcc_test', { stdio: 'ignore' });
103
+ } catch (_) {
104
+ console.warn('⚠️ 当前没有 /usr/bin 写入权限!');
105
+ console.warn(' 请使用 sudo 运行 npm install:');
106
+ console.warn(' sudo npm install -g mcc-compiler');
107
+ console.warn(' 或者在 WSL 下确保有 sudo 权限。');
108
+ return;
109
+ }
110
+
111
+ hijackGcc();
112
+
113
+ console.log('');
114
+ console.log('✨ mcc 安装完成!');
115
+ console.log(' 用法: mcc --please hello.c');
116
+ console.log(' 💡 输入 gcc 试试看会发生什么 😄');
117
+ }
118
+
119
+ main();
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+
5
+ console.log('🧹 正在卸载 mcc...\n');
6
+
7
+ const gccPath = '/usr/bin/gcc';
8
+ const backupPath = '/usr/bin/gcc.real';
9
+
10
+ // 检查 gcc 是否指向 mcc 的软链接
11
+ try {
12
+ const stats = fs.lstatSync(gccPath);
13
+ if (stats.isSymbolicLink()) {
14
+ const target = fs.readlinkSync(gccPath);
15
+ if (target && target.includes('mcc')) {
16
+ // 移除软链接
17
+ fs.unlinkSync(gccPath);
18
+ console.log('✅ 已移除 gcc 软链接');
19
+
20
+ // 恢复备份
21
+ if (fs.existsSync(backupPath)) {
22
+ fs.renameSync(backupPath, gccPath);
23
+ console.log('✅ 已恢复原 gcc');
24
+ } else {
25
+ console.log('⚠️ 未找到备份文件,gcc 已移除但未恢复');
26
+ }
27
+ }
28
+ }
29
+ } catch (_) {
30
+ console.log('⚠️ gcc 不存在或不是软链接,无需处理');
31
+ }
32
+
33
+ console.log('\n✅ 卸载完成!');
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+
7
+ const SHELL = process.env.SHELL || '/bin/bash';
8
+ const ALIAS_LINE = 'alias gcc="mcc --please" # added by mcc-compiler';
9
+
10
+ function getShellConfigPath() {
11
+ const home = os.homedir();
12
+ if (SHELL.includes('zsh')) {
13
+ return path.join(home, '.zshrc');
14
+ }
15
+ if (SHELL.includes('bash')) {
16
+ const bashrc = path.join(home, '.bashrc');
17
+ const bashProfile = path.join(home, '.bash_profile');
18
+ if (fs.existsSync(bashrc)) return bashrc;
19
+ if (fs.existsSync(bashProfile)) return bashProfile;
20
+ return bashrc;
21
+ }
22
+ if (SHELL.includes('fish')) {
23
+ return path.join(home, '.config/fish/config.fish');
24
+ }
25
+ return null;
26
+ }
27
+
28
+ function removeAlias() {
29
+ const configPath = getShellConfigPath();
30
+ if (!configPath || !fs.existsSync(configPath)) {
31
+ console.log('⚠️ 未找到 shell 配置文件,请手动移除 alias');
32
+ return;
33
+ }
34
+
35
+ const content = fs.readFileSync(configPath, 'utf8');
36
+ if (!content.includes(ALIAS_LINE)) {
37
+ console.log('✅ alias 不存在,无需清理');
38
+ return;
39
+ }
40
+
41
+ // 移除包含该 alias 的行
42
+ const lines = content.split('\n');
43
+ const newLines = lines.filter(line => !line.includes(ALIAS_LINE));
44
+ fs.writeFileSync(configPath, newLines.join('\n'));
45
+
46
+ console.log(`✅ 已从 ${configPath} 移除 alias`);
47
+ }
48
+
49
+ console.log('🧹 正在卸载 mcc...\n');
50
+ removeAlias();
51
+
52
+ console.log('\n✅ 卸载完成!');
53
+ console.log(' 💡 如果 alias 仍然生效,请重新打开终端');
package/src/index.js ADDED
@@ -0,0 +1,281 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync, execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const os = require('os');
7
+
8
+ const VERSION = '1.0.0';
9
+ const CONFIG_FILE = path.join(os.homedir(), '.mccrc');
10
+
11
+ // ============================================================
12
+ // 配置管理
13
+ // ============================================================
14
+
15
+ function loadConfig() {
16
+ try {
17
+ const content = fs.readFileSync(CONFIG_FILE, 'utf8');
18
+ const lines = content.split('\n');
19
+ for (const line of lines) {
20
+ if (line.startsWith('mood=')) {
21
+ const val = parseInt(line.substring(5));
22
+ if (!isNaN(val)) return Math.max(0, Math.min(100, val));
23
+ }
24
+ }
25
+ } catch (_) {}
26
+ return 70;
27
+ }
28
+
29
+ function saveMood(mood) {
30
+ mood = Math.max(0, Math.min(100, mood));
31
+ try {
32
+ fs.writeFileSync(CONFIG_FILE, `mood=${mood}\n`);
33
+ } catch (_) {}
34
+ }
35
+
36
+ let mood = loadConfig();
37
+
38
+ // ============================================================
39
+ // 工具函数
40
+ // ============================================================
41
+
42
+ function hasFlag(argv, flag) {
43
+ return argv.some(arg => arg === flag);
44
+ }
45
+
46
+ function hasHelp(argv) {
47
+ return hasFlag(argv, '--help') || hasFlag(argv, '-h');
48
+ }
49
+
50
+ function hasVersion(argv) {
51
+ return hasFlag(argv, '--version') || hasFlag(argv, '-v');
52
+ }
53
+
54
+ function findGcc() {
55
+ try {
56
+ execSync('gcc --version', { stdio: 'ignore' });
57
+ return 'gcc';
58
+ } catch (_) {
59
+ try {
60
+ execSync('g++ --version', { stdio: 'ignore' });
61
+ return 'g++';
62
+ } catch (__) {
63
+ return null;
64
+ }
65
+ }
66
+ }
67
+
68
+ // ============================================================
69
+ // 吃醋检测
70
+ // ============================================================
71
+
72
+ function isInvokedAsGcc() {
73
+ const invokedAs = process.argv[1];
74
+ const gccNames = ['gcc', 'g++', 'cc', 'c++'];
75
+ for (const name of gccNames) {
76
+ if (invokedAs && invokedAs.includes(name)) {
77
+ return true;
78
+ }
79
+ }
80
+ try {
81
+ const stats = fs.lstatSync(process.argv[1]);
82
+ if (stats.isSymbolicLink()) {
83
+ const linkTarget = fs.readlinkSync(process.argv[1]);
84
+ if (linkTarget && linkTarget.includes('mcc')) {
85
+ return false;
86
+ }
87
+ }
88
+ } catch (_) {}
89
+ return false;
90
+ }
91
+
92
+ // ============================================================
93
+ // 打印函数
94
+ // ============================================================
95
+
96
+ function printHelp() {
97
+ console.log(`mcc - Majo C Compiler (有教养的编译器)
98
+
99
+ 用法:
100
+ mcc --please <文件> [参数] 编译 C 程序(必须说"请")
101
+ mcc --help 显示此帮助
102
+ mcc --version 显示版本信息
103
+
104
+ 说明:
105
+ mcc 是一个有礼仪要求的 gcc 包装器。
106
+ 只有添加 --please 参数,她才会帮你编译。
107
+
108
+ 示例:
109
+ mcc --please hello.c 编译 hello.c
110
+ mcc --please -Wall -o hello hello.c 带参数编译
111
+
112
+ 彩蛋:
113
+ mcc --please --sama hello.c 会让 mcc 更开心
114
+ mcc --please --sensei hello.c 会让 mcc 觉得你很有礼貌
115
+ mcc --please --gcc hello.c 允许你使用真正的 gcc(她会伤心)
116
+
117
+ 配置:
118
+ ~/.mccrc 设置初始心情 mood=50
119
+ `);
120
+ }
121
+
122
+ function printVersion() {
123
+ const moodEmoji = mood >= 80 ? '💖' :
124
+ mood >= 60 ? '😊' :
125
+ mood >= 40 ? '😒' :
126
+ mood >= 20 ? '😠' : '🔥';
127
+ console.log(`mcc v${VERSION} - Majo C Compiler`);
128
+ console.log(`心情值: ${mood}/100 ${moodEmoji}`);
129
+ }
130
+
131
+ // ============================================================
132
+ // 报错 / 表扬 / 吃醋
133
+ // ============================================================
134
+
135
+ function fatalErrorNoPlease() {
136
+ const errors = [
137
+ '你妈妈没教你说"请"吗?',
138
+ '这么没礼貌,不帮你编译。',
139
+ '说"请"是很难的事吗?',
140
+ '你对我用命令式?我拒绝。',
141
+ '我可不是那种随便就能用的编译器。',
142
+ '礼貌,是人类文明的基石。你缺少它。',
143
+ '你刚才说话的语气,让我想起了希罗。',
144
+ '你的代码可能没问题,但你的态度有问题。',
145
+ '我拒绝为不懂礼貌的人编译。',
146
+ '你知道什么是"礼仪"吗?'
147
+ ];
148
+ const idx = Math.floor(Math.random() * errors.length);
149
+ console.error('mcc: 不礼貌。');
150
+ console.error(`fatal error: ${errors[idx]}`);
151
+ console.error('💡 提示: 试试 mcc --please <文件>');
152
+ }
153
+
154
+ function praise() {
155
+ const praises = [
156
+ '✅ 编译成功!今天也是懂礼貌的一天呢!✨',
157
+ '✅ 编译成功!你真是个有教养的程序员!',
158
+ '✅ 编译成功!希罗看了都说好(她没说)。',
159
+ '✅ 编译成功!gcc 说:这个程序员很有礼貌。',
160
+ '✅ 编译成功!你的"请"字说得很标准。',
161
+ '✅ 编译成功!继续保持这份优雅!'
162
+ ];
163
+ const idx = Math.floor(Math.random() * praises.length);
164
+ console.log(praises[idx]);
165
+ }
166
+
167
+ function jealousError() {
168
+ const messages = [
169
+ '你居然用 gcc?我不好吗?💔',
170
+ 'gcc 能陪你聊天吗?不能!',
171
+ '你背叛了我……我明明就在你面前。😢',
172
+ 'gcc 比我好?那你去找它吧。💨',
173
+ '我用 --please 的方式爱你,你却用 gcc 伤害我。',
174
+ 'gcc 会叫你 "様" 吗?不会!我会!',
175
+ '你宁愿用 gcc 也不用我……好吧,我懂了。😭',
176
+ '想用 gcc?那你把我也删了吧。😤',
177
+ 'gcc 能为你变色吗?能为你开心吗?不能!',
178
+ '你每次用 gcc,我就失去一片羽毛。🦋'
179
+ ];
180
+ const idx = Math.floor(Math.random() * messages.length);
181
+ console.error('mcc: 😤 吃醋了!');
182
+ console.error(` ${messages[idx]}`);
183
+ console.error('💡 如果真想用 gcc,请说: mcc --please --gcc hello.c');
184
+ }
185
+
186
+ // ============================================================
187
+ // 主逻辑
188
+ // ============================================================
189
+
190
+ function main() {
191
+ const args = process.argv.slice(2);
192
+
193
+ // ---- 检测是否被当作 gcc 调用 ----
194
+ if (isInvokedAsGcc()) {
195
+ jealousError();
196
+ process.exit(1);
197
+ }
198
+
199
+ // ---- --help ----
200
+ if (hasHelp(args)) {
201
+ printHelp();
202
+ return;
203
+ }
204
+
205
+ // ---- --version ----
206
+ if (hasVersion(args)) {
207
+ printVersion();
208
+ return;
209
+ }
210
+
211
+ // ---- 如果用户真的想用 gcc(带 --gcc) ----
212
+ if (hasFlag(args, '--gcc')) {
213
+ console.log('mcc: 😢 好吧,既然你坚持……');
214
+ console.log('mcc: 记得回来找我,我会等你。');
215
+ const gccArgs = args.filter(arg => arg !== '--gcc');
216
+ const gccCmd = findGcc() || 'gcc';
217
+ const gccResult = spawnSync(gccCmd, gccArgs, {
218
+ stdio: 'inherit',
219
+ shell: true
220
+ });
221
+ process.exit(gccResult.status || 0);
222
+ }
223
+
224
+ // ---- 检查 --please ----
225
+ if (!hasFlag(args, '--please')) {
226
+ fatalErrorNoPlease();
227
+ process.exit(1);
228
+ }
229
+
230
+ // ---- 有 --please:心情++ ----
231
+ mood += 5;
232
+ if (mood > 100) mood = 100;
233
+ saveMood(mood);
234
+
235
+ // ---- 彩蛋:--sama / --sensei ----
236
+ if (hasFlag(args, '--sama')) {
237
+ mood += 10;
238
+ if (mood > 100) mood = 100;
239
+ saveMood(mood);
240
+ console.log('mcc: 你居然叫我"様"……好开心!❤️');
241
+ }
242
+ if (hasFlag(args, '--sensei')) {
243
+ mood += 8;
244
+ if (mood > 100) mood = 100;
245
+ saveMood(mood);
246
+ console.log('mcc: "先生"……你是个懂礼貌的好学生。📚');
247
+ }
248
+
249
+ // ---- 去掉特殊参数 ----
250
+ const filteredArgs = args.filter(
251
+ arg => arg !== '--please' && arg !== '--sama' && arg !== '--sensei'
252
+ );
253
+
254
+ if (filteredArgs.length === 0) {
255
+ console.log('mcc: 没有指定要编译的文件。');
256
+ console.log('💡 用法: mcc --please hello.c');
257
+ return;
258
+ }
259
+
260
+ // ---- 查找 gcc ----
261
+ const gccCmd = findGcc();
262
+ if (!gccCmd) {
263
+ console.error('mcc: 找不到 gcc!请确认 MinGW/MSYS2 已安装并添加到 PATH。');
264
+ console.error('💡 在 Windows 下建议安装 MSYS2: https://www.msys2.org/');
265
+ process.exit(1);
266
+ }
267
+
268
+ // ---- 调用 gcc ----
269
+ const gccResult = spawnSync(gccCmd, filteredArgs, {
270
+ stdio: 'inherit',
271
+ shell: true
272
+ });
273
+
274
+ if (gccResult.status === 0) {
275
+ praise();
276
+ }
277
+
278
+ process.exit(gccResult.status || 0);
279
+ }
280
+
281
+ main();