1 Star 1 Fork 0

hetao5422877/hcxVMos操作系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hcxVMos1.3pro.cpp 34.77 KB
一键复制 编辑 原始数据 按行查看 历史
hetao5422877 提交于 2024-06-09 06:48 . add hcxVMos1.3pro.cpp.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
#include <bits/stdc++.h>
using namespace std;
struct user{
string name, type, password;
} users[101];
int usercnt = 0;
bool user_exist(string name){
for (int i=0; i<usercnt; i++){
if (users[i].name == name){
return true;
}
}
return false;
}
struct var{
string name, value;
} vars[101];
int vars_i = 0;
string reguser(string type, string name, string password, string confirm_password){
if (usercnt >= 100){
cout<<"用户过多。"<<endl;
return "UserMax";
}
if (name == ""){
cout<<"错误:用户名为空。"<<endl;
return "NameNullErr";
}
if (user_exist(name)){
cout<<"用户已经存在。"<<endl;
return "UserExistedErr";
}
users[usercnt].name = name;
users[usercnt].type = type;
if (password != confirm_password){
cout<<"错误:密码确认失败。"<<endl;
return "ConfirmErr";
}
users[usercnt].password = password;
cout<<"注册成功!"<<endl;
usercnt++;
return "NormalExit";
}
bool logined = true;
int loging_i = 0;
string login()
{
cout<<"准备开始登录。"<<endl;
cout<<"用户名:";
string name;
getline(cin, name);
bool founduser = false;
int login_i;
for (int i=0;i<usercnt; i++){
if (users[i].name == name){
cout<<"用户存在。"<<endl;
login_i = i;
founduser = true;
break;
}
}
if(!founduser){
cout<<"不存在此用户。"<<endl;
return "UserNotFound";
}
string password;
cout<<"接下来,请您输入密码:";
getline(cin, password);
if (password != users[login_i].password){
cout<<"密码错误。"<<endl;
return "WrongPassword";
}
cout<<"登录成功。"<<endl;
logined = true;
loging_i = login_i;
system("pause");
return "NormalExit";
}
void prnHelp(){
cout<<"(root) destroy --- 销毁系统。"<<endl;
cout<<"help --- 获取帮助。"<<endl;
cout<<"clear --- 清空屏幕。"<<endl;
cout<<"add [FileName]--- 添加文件(FileName: 文件名)。"<<endl;
cout<<"(Tips): 查看文件内容可以直接输入文件名。"<<endl;
cout<<"edit [FileName] --- 编辑文件(FileName: 文件名)。"<<endl;
cout<<"del [FileName] --- 删除文件(FileName: 文件名)。"<<endl;
cout<<"(root) reg [Name] [Password] [Confirm] --- 创建账户(Name: 账户名称, Password: 账户密码, Confirm: 确认密码)。"<<endl;
cout<<"logout --- 退出登录。"<<endl;
cout<<"filelist --- 文件列表。"<<endl;
cout<<"userlist --- 用户列表。"<<endl;
cout<<"myinfo --- 我的信息。"<<endl;
cout<<"define [VariableName] [VariableValue] --- 定义变量。"<<endl;
cout<<"reset [VariableName] [NewValue] --- 更改变量值。"<<endl;
cout<<"delete [VariableName] --- 删除变量。"<<endl;
cout<<"do [ScriptName] --- 执行hcxvmos脚本文件。"<<endl;
cout<<"chess --- 下棋。"<<endl;
cout<<"print [text] --- 打印。"<<endl;
cout<<"(root) setadmin [username] --- 设置管理员。"<<endl;
cout<<"(root) canceladmin [username] --- 取消管理权限。"<<endl;
}
struct file{
string name, content = "";
} files[101];
int files_i = 0;
string lower(string s){
int s_len = s.size();
for(int i=0;i<s_len;i++){
if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
}
return s;
}
bool choice(){
string choice;
cout<<"确定?(y/n): ";
getline(cin, choice);
choice = lower(choice);
if(choice == "y" || choice == "yes") return true;
return false;
}
string tokens[101];
int tokens_i = 0;
void clear_tokens(){
for (int i=0; i<101; i++){
tokens[i] = "";
}
}
string tokenizer(string cmd)
{
//清空tokens数组
clear_tokens();
tokens_i = 0;
cmd += " ";
int cmd_len = cmd.size();
int insign = 0;
string spliting = "";
for (int i=0; i<cmd_len; i++){
if (tokens_i >= 100){
return "CmdLong";
}
if (cmd[i] == '\\' && i<cmd_len-1){
if (cmd[i+1] == '"'){
continue;
}
}
if (cmd[i] == ' ' && insign == 0){
tokens[tokens_i] = spliting;
tokens_i++;
spliting = "";
continue;
}
if (cmd[i] == '"'){
if (i > 1){
if (cmd[i-1] == '\\'){
spliting += string(1, cmd[i]);
if (i == cmd_len-1 && insign > 0){
//引号不匹配
return "SignNotEnd";
}
continue;
}
}
if (insign % 2){
//还没有凑整
//这个是结尾的引号
insign--;
//不用录入
continue;
}
//已经凑整
//这个是开头的引号
insign++;
//录入,不用管他,执行到下面自动录入
}
//录入
spliting += string(1, cmd[i]);
if (i == cmd_len-1 && insign > 0){
//引号不匹配
return "SignNotEnd";
}
}
return "NormalExit";
}
//true表示wyy
bool wyy_string(string s){
if (s == "") return true;
int s_len = s.size();
for (int i=0; i<s_len; i++){
if (s[i] != ' '){
return false;
}
}
return true;
}
void del_wyy_tokens(){
string local_tokens[101];
int local_i = 0;
for (int i=0; i<tokens_i; i++){
if (!wyy_string(tokens[i])){
local_tokens[local_i] = tokens[i];
local_i++;
}
}
swap(tokens, local_tokens);
tokens_i = local_i;
}
string delHead(string s){
if (s[0] != '"') return s;
int s_len = s.size();
string result = "";
for (int i=1; i<s_len; i++){
result += string(1, s[i]);
}
return result;
}
void prnEditHelp(){
cout<<"add [String] --- 添加字符串到末尾。"<<endl;
cout<<"del [Number] --- 删除末尾Number位字符。"<<endl;
cout<<"endl --- 添加换行符。"<<endl;
cout<<"exit --- 退出编辑模式。"<<endl;
}
bool all_is_num(string s){
int s_len = s.size();
for (int i=0; i<s_len; i++){
if (s[i] < '0' || s[i] > '9'){
return false;
}
}
return true;
}
int string_to_int(string s){
int series = 1;
int s_len = s.size(), result = 0;
for (int i=s_len-1; i>=0; i--){
result += series * (s[i] - '0');
}
return result;
}
bool check_name(string name){
name = delHead(name);
if (name == "") return false;
int name_len = name.size();
for (int i=0; i<name_len; i++){
if (name[i] == '"') return false;
}
for (int i=0; i<files_i; i++){
if (files[i].name == name){
return false;
}
}
return true;
}
void delFile_i(int delpos){
file local_files[101];
int local_files_i = 0;
for (int i=0; i<files_i; i++){
if (i != delpos){
local_files[local_files_i].name = files[i].name;
local_files[local_files_i].content = files[i].content;
local_files_i++;
}
}
files_i--;
swap(files, local_files);
}
string delFile(string name){
for (int i=0; i<files_i; i++){
if (files[i].name == name){
delFile_i(i);
return "NormalExit";
}
}
//文件没有被删除
return "FileNotFound";
}
void del_var_i(int del_i){
var local_vars[101];
int local_vars_i = 0;
for (int i=0; i<vars_i; i++){
if (i == del_i){
continue;
}
local_vars[local_vars_i].name = vars[i].name;
local_vars[local_vars_i].value = vars[i].value;
local_vars_i++;
}
vars_i--;
swap(local_vars, vars);
}
string splited_cmds[101];
int splited_cmds_i = 0;
string split_command(int fi){
int now_i = 0, filesize = files[fi].content.size();
string now_spliting = "";
while (true){
if (now_i >= filesize){
splited_cmds[splited_cmds_i] = now_spliting;
splited_cmds_i++;
return "NormalExit";
}
if (splited_cmds_i >= 100){
return "Long";
}
if (files[fi].content[now_i] == '\n'){
splited_cmds[splited_cmds_i] = now_spliting;
now_spliting = "";
splited_cmds_i++;
now_i++;
continue;
}
now_spliting += files[fi].content[now_i];
now_i++;
}
}
void edit_file(int editing_i){
while (true){
system("cls");
cout<<files[editing_i].name<<":"<<endl;
cout<<files[editing_i].content<<endl;
cout<<"命令:"<<endl;
prnEditHelp();
cout<<"EditMode > ";
string editcmd;
getline(cin, editcmd);
string splitcode = tokenizer(editcmd);
del_wyy_tokens();
if (splitcode == "SignNotEnd"){
cout<<"引号不匹配。"<<endl;
system("pause");
continue;
}
if (tokens[0] == "add"){
if (tokens[1] == ""){
cout<<"缺少必要的参数。"<<endl;
system("pause");
continue;
}
if (tokens[1][0] == '"'){
tokens[1] = delHead(tokens[1]);
files[editing_i].content += tokens[1];
}
else{
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found = true;
files[editing_i].content += vars[i].value;
break;
}
}
if (!found){
cout << "未定义变量。" << endl;
system("pause");
continue;
}
}
}
else if (tokens[0] == "del"){
if (!all_is_num(tokens[1])){
cout<<"参数无效。"<<endl;
system("pause");
continue;
}
int n = string_to_int(tokens[1]);
//删除结尾n位
int content_size = files[editing_i].content.size();
if (n > content_size){
cout<<"错误:参数过大。"<<endl;
system("pause");
continue;
}
string result = "";
for (int i=0; i<content_size-n-1; i++){
result += string(1, files[editing_i].content[i]);
}
files[editing_i].content = result;
}
else if (tokens[0] == "endl"){
files[editing_i].content += "\n";
}
else if (tokens[0] == "exit"){
break;
}
else{
if (tokens[0] == ""){
system("cls");
continue;
}
cout<<"未定义编辑命令。"<<endl;
system("pause");
}
system("cls");
}
cout<<"即将退出编辑模式。"<<endl;
system("pause");
system("cls");
}
char board[13][13];
void init_chess()
{
for (int i=1; i<=9; i++){
for (int j=1; j<=9; j++){
board[i][j] = ' ';
}
}
}
void update_screen_chess()
{
system("cls");
cout << " ";
for (int i=1; i<=9; i++){
cout << i;
if (i < 9){
cout << " ";
}
else{
cout << "|";
}
}
cout << endl;
for (int i=1; i<=9; i++){
cout << i << " ";
for (int j=1; j<=9; j++){
cout << board[i][j];
if (j < 9){
cout << " ";
}
else{
cout << "|";
}
}
cout << endl;
}
cout << "--------------------" << endl;
}
bool is_all_fulled_chess()
{
for (int i=1; i<=9; i++){
for (int j=1; j<=9; j++){
if (board[i][j] == ' '){
return false;
}
}
}
return true;
}
// true表示赢了
bool is_win_chess(char actor)
{
// actor代表角色
for (int i=1; i<=9; i++){
for (int j=1; j<=9; j++){
if (board[i][j] == actor){
int cnt = 1;
// 往右边看
for (int find_j = j+1; find_j <= 9; find_j++){
if (board[i][find_j] == actor){
cnt++;
}
else{
break;
}
}
if (cnt >= 5)
return true;
cnt = 1;
for (int find_i = i+1; find_i <= 9; find_i++){
if (board[find_i][j] == actor){
cnt++;
}
else{
break;
}
}
if (cnt >= 5)
return true;
cnt = 1;
// 左上到右下
int cha = j - i;
for (int find_i = i+1; find_i <= 9; find_i++){
if (board[find_i][find_i+cha] == actor){
cnt++;
}
else{
break;
}
}
if (cnt >= 5)
return true;
cnt = 1;
// 右上到左下
int find_j = j-1;
for (int find_i = i+1; find_i <= 9; find_i++){
if (find_j < 1)
break;
if (board[find_i][find_j] == actor){
cnt++;
}
else{
break;
}
find_j--;
}
if (cnt >= 5)
return true;
cnt = 1;
}
}
}
return false;
}
string active_chess(char actor, int line, int row)
{
if (line < 1 || line > 9 || row < 1 || row > 9 || board[line][row] != ' '){
return "PosError";
}
// 验证通过
board[line][row] = actor;
return "NormalExit";
}
bool check_string_can_to_int(string s){
int s_size = s.size();
for (int i=0; i<s_size; i++){
if (!(s[i] >= '0' && s[i] <= '9')){
return false;
}
}
return true;
}
void chess()
{
init_chess();
string a_line, a_row, b_line, b_row;
while (true)
{
update_screen_chess();
if (is_win_chess('*')){
cout << "The actor * was win." << endl;
// system("pause");
system("cls");
return;
}
if (is_win_chess('o')){
cout << "The actor o was win." << endl;
system("pause");
system("cls");
return;
}
if (is_all_fulled_chess()){
cout << "The board was full." << endl;
system("pause");
system("cls");
return;
}
// 没分出胜负,直接下棋
while (true){
cout << "The actor * line: ";
getline(cin, a_line);
if (!check_string_can_to_int(a_line)){
cout << "Your input we unaccepted. " << endl;
continue;
}
cout << "The actor * row: ";
getline(cin, a_row);
if (!check_string_can_to_int(a_row)){
cout << "Your input we unaccepted. " << endl;
continue;
}
string retcode = active_chess('*', string_to_int(a_line), string_to_int(a_row));
if (retcode == "NormalExit")
break;
cout << "The position can not use." << endl;
}
update_screen_chess();
if (is_win_chess('*')){
cout << "The actor * was win." << endl;
system("pause");
system("cls");
return;
}
if (is_win_chess('o')){
cout << "The actor o was win." << endl;
system("pause");
system("cls");
return;
}
if (is_all_fulled_chess()){
cout << "The board was full." << endl;
system("pause");
system("cls");
return;
}
while (true){
cout << "The actor o line: ";
getline(cin, b_line);
if (!check_string_can_to_int(b_line)){
cout << "Your input we unaccepted. " << endl;
continue;
}
cout << "The actor o row: ";
getline(cin, b_row);
if (!check_string_can_to_int(b_row)){
cout << "Your input we unaccepted. " << endl;
continue;
}
string retcode = active_chess('*', string_to_int(b_line), string_to_int(b_row));
if (retcode == "NormalExit")
break;
cout << "The position can not use." << endl;
}
}
}
void do_command(string cmd){
string splitcode = tokenizer(cmd);
del_wyy_tokens();
if (splitcode == "SignNotEnd"){
cout<<"错误:引号不匹配。"<<endl;
return;
}
if (splitcode == "CmdLong"){
cout << "命令太长。" << endl;
return;
}
if (tokens[0] == "help"){
prnHelp();
}
else if(tokens[0] == "destroy"){
if (users[loging_i].type != "root"){
cout<<"该账户的权限需要提升。"<<endl;
return;
}
bool confirm = true;
for(int i=0;i<3;i++){
bool result = choice();
if (!result){
confirm = false;
break;
}
}
if (!confirm) return;
//毁灭吧
exit(0);
}
else if (tokens[0] == "clear"){
system("cls");
}
else if (tokens[0] == "add"){
//参数: tokens[1]: 文件名
if (files_i >= 100){
cout<<"文件数量已达上限。请通过删除文件以节省空间。"<<endl;
}
if (tokens[1] == ""){
cout<<"缺少必要的参数(FileName Not Found)。"<<endl;
return;
}
if (!check_name(tokens[1])){
cout<<"禁止文件名里包含不被允许的符号或者没有文件名,或者重名。"<<endl;
return;
}
if (tokens[1][0] == '"'){
//直接引用文件名
tokens[1] = delHead(tokens[1]); //去除引号标识符
files[files_i].name = tokens[1];
files_i++;
}
else{
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found = true;
if (files_i >= 100){
cout<<"文件数量已达上限。请通过删除文件以节省空间。"<<endl;
return;
}
files[files_i].name = vars[i].value;
files_i++;
break;
}
}
if (!found){
cout << "未定义变量。" << endl;
}
}
}
else if (tokens[0] == "edit"){
//寻找文件编号
if (tokens[1] == ""){
cout<<"缺少文件名。"<<endl;
return;
}
if (tokens[1][0] == '"'){
tokens[1] = delHead(tokens[1]);
}
else{
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found = true;
tokens[1] = vars[i].value;
break;
}
}
if (!found){
cout << "未定义变量。" << endl;
return;
}
}
int editing_i = 0;
bool found = false;
for (int i=0; i<files_i; i++){
if (files[i].name == tokens[1]){
editing_i = i;
found = true;
break;
}
}
if (!found){
cout<<"没有找到文件。"<<endl;
return;
}
//进入编辑模式
edit_file(editing_i);
}
else if (tokens[0] == "del"){
if (tokens[1] == ""){
cout<<"缺少必要的参数:文件名。"<<endl;
return;
}
if (tokens[1][0] == '"'){
tokens[1] = delHead(tokens[1]);
string delcode = delFile(tokens[1]);
if (delcode == "FileNotFound"){
cout<<"文件不存在。"<<endl;
}
}
else{
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
string delcode = delFile(vars[i].value);
if (delcode == "FileNotFound"){
cout << "文件不存在。" << endl;
}
break;
}
}
if (!found){
cout << "未定义变量。" << endl;
}
}
}
else if (tokens[0] == "reg"){
if (!(users[loging_i].type == "root" || users[loging_i].type == "admin")){
cout<<"仅有root可以创建账户。"<<endl;
return;
}
//tokens[1]名称, tokens[2]密码
if (tokens[1] == "" || tokens[2] == "" || tokens[3] == ""){
cout<<"缺少参数。"<<endl;
return;
}
if (tokens[1][0] == '"'){
tokens[1] = delHead(tokens[1]);
if (tokens[2][0] == '"')
{
tokens[2] = delHead(tokens[2]);
if (tokens[3][0] == '"'){
tokens[3] = delHead(tokens[3]);
reguser("user", tokens[1], tokens[2], tokens[3]);
}
else{
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[3]){
found = true;
reguser("user", tokens[1], tokens[2], vars[i].value);
break;
}
}
if (!found){
cout << "变量未找到。" << endl;
}
}
}
else{
cout<<"当前版本不支持引用变量当作密码。"<<endl;
return;
}
}
else{
cout<<"该版本不支持引用变量当作账户名称。"<<endl;
return;
}
}
else if (tokens[0] == "logout"){
system("cls");
logined = false;
return;
}
else if (tokens[0] == "filelist"){
if (files_i == 0){
cout << "无文件。" << endl;
return;
}
for (int i=0; i<files_i; i++){
cout << files[i].name << endl;
}
}
else if (tokens[0] == "userlist"){
cout << "Name / Type";
if (users[loging_i].type == "root"){
cout << " / Password" << endl;
}
else{
cout << endl;
}
for (int i=0; i<usercnt; i++){
cout << users[i].name << " --- " << users[i].type;
if (users[loging_i].type == "root"){
cout << " --- " << users[i].password << endl;
}
else{
cout << endl;
}
}
}
else if (tokens[0] == "myinfo"){
cout << "我的用户名:" << users[loging_i].name << endl;
cout << "我的权限:" << users[loging_i].type << endl;
cout << "我的密码:" << users[loging_i].password << endl;
}
else if (tokens[0] == "define"){
if (tokens[1][0] != '"'){
cout << "当前版本不支持引用变量当作参数。" << endl;
return;
}
bool found = false;
if (tokens[2][0] != '"'){
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[2]){
found = true;
if (vars_i >= 100){
cout << "变量空间不足。请删除一些变量以节省空间。" << endl;
}
vars[vars_i].name = delHead(tokens[1]);
vars[vars_i].value = vars[i].value;
vars_i++;
}
}
}
if (!found && tokens[2][0] != '"'){
cout << "变量未定义。" << endl;
return;
}
tokens[1] = delHead(tokens[1]);
tokens[2] = delHead(tokens[2]);
if (vars_i >= 100){
cout << "变量空间不足。请删除一些变量以节省空间。" << endl;
}
vars[vars_i].name = tokens[1];
vars[vars_i].value = tokens[2];
vars_i++;
}
else if (tokens[0] == "reset"){
if (tokens[1][0] != '"'){
cout << "当前版本不支持引用变量当作参数。" << endl;
return;
}
bool found = false;
if (tokens[2][0] != '"'){
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[2]){
found = true;
bool reseted = false;
for (int j=0; j<vars_i; j++){
if (vars[j].name == delHead(tokens[1])){
reseted = true;
vars[j].value = vars[i].value;
break;
}
}
if (!reseted){
cout << "变量未找到。" << endl;
return;
}
break;
}
}
}
if (!found && tokens[2][0] != '"'){
cout << "未定义变量。" << endl;
return;
}
tokens[1] = delHead(tokens[1]);
tokens[2] = delHead(tokens[2]);
bool reseted = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
reseted = true;
vars[i].value = tokens[2];
break;
}
}
if (!reseted){
cout << "变量未找到。" << endl;
}
}
else if (tokens[0] == "delete"){
bool found = false;
if (tokens[1][0] != '"'){
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found = true;
bool found_var = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found_var = true;
del_var_i(i);
break;
}
}
if (!found_var){
cout << "变量未找到。" << endl;
return;
}
break;
}
}
}
if (!found && tokens[1][0] != '"'){
cout << "未定义变量。" << endl;
return;
}
tokens[1] = delHead(tokens[1]);
bool found_var = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found_var = true;
del_var_i(i);
break;
}
}
if (!found_var){
cout << "变量未找到。" << endl;
}
}
else if (tokens[0] == "do"){
bool found = false, need_delhead = true;
if (tokens[1][0] != '"'){
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
found = true;
need_delhead = false;
tokens[1] = vars[i].value;
break;
}
}
}
if (!found && tokens[1][0] != '"'){
cout << "未定义变量。" << endl;
return;
}
if (need_delhead){
tokens[1] = delHead(tokens[1]);
}
int fi;
found = false;
for (int i=0; i<files_i; i++){
if (files[i].name == tokens[1]){
fi = i;
found = true;
break;
}
}
if (!found){
cout << "未找到脚本文件。" << endl;
return;
}
string split_lines_code = split_command(fi);
if (split_lines_code == "Long"){
cout << "太长的脚本文件。" << endl;
return;
}
// 分解成功,逐行执行
for (int i=0; i<splited_cmds_i; i++){
do_command(splited_cmds[i]);
}
cout << "脚本执行完毕。" << endl;
}
else if (tokens[0] == "chess"){
chess();
}
else if (tokens[0] == "print"){
if (tokens[1] == ""){
cout << "错误:text null. " << endl;
return;
}
bool found = false;
if (tokens[1][0] != '"'){
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
cout << vars[i].value << endl;
found = true;
return;
}
}
if (!found){
cout << "错误:No variable. " << endl;
return;
}
}
tokens[1] = delHead(tokens[1]);
cout << tokens[1] << endl;
}
else if (tokens[0] == "setadmin"){
if (users[loging_i].type != "root"){
cout << "您不具备有所需的权限。" << endl;
return;
}
if (tokens[1] == ""){
cout << "错误:无用户名。" << endl;
return;
}
if (tokens[1][0] != '"'){
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
tokens[1] = vars[i].value;
found = true;
break;
}
}
if (!found){
cout << "变量未找到。" << endl;
return;
}
}
else{
tokens[1] = delHead(tokens[1]);
}
for (int i=0; i<usercnt; i++){
if (users[i].name == tokens[1] && users[i].type != "root"){
users[i].type = "admin";
return;
}
}
cout << "未找到用户或对root使用操作。" << endl;
}
else if (tokens[0] == "canceladmin"){
if (users[loging_i].type != "root"){
cout << "您不具备有所需的权限。" << endl;
return;
}
if (tokens[1] == ""){
cout << "无用户名。" << endl;
return;
}
if (tokens[1][0] != '"'){
bool found = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[1]){
tokens[1] = vars[i].value;
found = true;
break;
}
}
if (!found){
cout << "变量未找到。" << endl;
}
}
else{
tokens[1] = delHead(tokens[1]);
}
for (int i=0; i<usercnt; i++){
if (users[i].name == tokens[1] && users[i].type != "root"){
users[i].type = "user";
return;
}
}
cout << "用户未找到或对root使用操作。" << endl;
}
else{
if (tokens[0] == ""){
return;
}
//变量优先查找,文件最后查找
bool isvar = false;
for (int i=0; i<vars_i; i++){
if (vars[i].name == tokens[0]){
cout << vars[i].value << endl;
isvar = true;
break;
}
}
if (isvar){
return;
}
bool isFile = false;
for (int i=0; i<files_i; i++){
if (files[i].name == tokens[0]){
cout<<files[i].content<<endl;
isFile = true;
break;
}
}
if (isFile){
return;
}
cout<<"命令无效。"<<endl;
}
}
int main()
{
cout<<"欢迎初次使用hcx系统。该系统仅支持中文模式。"<<endl;
system("pause");
cout<<"接下来将为您注册root用户。"<<endl;
while (true)
{
string name;
cout<<"账户名称:";
getline(cin, name);
string password;
cout<<"密码:";
getline(cin, password);
cout<<"确认密码:";
string confirm;
getline(cin, confirm);
string regcode = reguser("root", name, password, confirm);
if (regcode != "NormalExit"){
cout<<"请重新注册。"<<endl;
continue;
}
break;
}
cout<<"root用户注册成功,您接下来可以以root的权限使用这个系统。"<<endl;
system("pause");
system("cls");
while (true)
{
if(!logined){
cout<<"您已经退出登录。请登录。"<<endl;
// 显示所有用户
cout << "此电脑上的所有用户:" << endl;
cout << "Name / Type" << endl;
for (int i=0; i<usercnt; i++){
cout << users[i].name << " --- " << users[i].type << endl;
}
while (true){
string logcode = login();
if(logcode != "NormalExit"){
cout<<"请重新登录。"<<endl;
continue;
}
break;
}
system("cls");
continue;
}
string cmd;
cout<<users[loging_i].type<<" > ";
getline(cin, cmd);
do_command(cmd);
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hetao5422877/hcx-vmos.git
[email protected]:hetao5422877/hcx-vmos.git
hetao5422877
hcx-vmos
hcxVMos操作系统
master

搜索帮助