?? output.cpp
字號:
#include <ctype.h>
#include "common.h"
#include "calculate.h"
void PrintResult (
NODE *Result
)
{
char format[10];
char c = '%';
if (error != NULL || vision == false) {
return;
}
sprintf (format,"%c.%df\n",c,prec);
printf ("= ");
if (Result->Term.Operand.DataSignal == INTEGER) {
printf ("%d\n",Result->Term.Operand.Data.Integer);
} else {
printf (format,Result->Term.Operand.Data.Real);
}
putchar ('\n');
}
void PrintError (
void
)
{
printf ("error[%d]:",error);
switch (error) {
case the_name_is_too_long:
printf ("變量的名字好長啊...\n");
break;
case can_not_identify_identifier:
printf ("以前好像沒有見過變量:%s\n",VarName);
break;
case the_data_bit_is_too_long:
printf ("數據也太大了一點吧\n");
break;
case the_real_number_is_illegal:
printf ("小數點只有一個,看你打了幾個\n");
break;
case illegal_compages:
printf ("好像不是這回事\n");
break;
case the_brackets_are_not_match:
printf ("括號是成對出現的,不要棒打鴛鴦噢\n");
break;
case the_mode_operator_only_accept_integral_operands:
printf ("好像只能對整數求余吧\n");
break;
case the_divisor_can_not_be_zero:
printf ("你見過除數為 0 的表達式嗎\n");
break;
case the_stack_is_null:
printf ("不知道錯哪了,檢查了半天也沒查出什么錯了");
break;
case memmory_allocation_failed:
printf ("電腦內存有點小噢\n");
break;
case the_argument_cannot_been_explained:
printf ("還是說中文吧,不懂啊\n");
break;
case find_some_illegal_word:
printf ("這里只用全英文的變量名\n");
break;
case the_precision_or_mode_only_accept_integral_argument:
printf ("全局變量的值只能是 0 -100 的整數啊,我是認真的");
break;
case the_command_is_incorrect:
printf ("看來我應該抓緊時間學習,才能弄懂你的語言\n");
break;
case the_var_is_not_seen_before:
printf ("以前好像沒見過變量:%s\n",Command[1]);
break;
case find_some_illegal_alpha:
printf ("有些東西不認識\n");
break;
case the_prec_value_range_from_0_to_100:
printf ("prec 的值只能是從 0 到 100\n");
break;
case connot_use_system_identify:
printf ("那是我自己用的名字\n");
default:
break;
}
putchar ('\n');
}
void CmdExecute (
void
)
{
if (error != NULL) {
return;
}
switch (ArgCounter) {
case 0:
return;
case 1:
if (infocmd == 0) {
Calculator ();
return;
} else if (infocmd == 1 || infocmd == 2) {
error = the_command_is_incorrect;
return;
} else if (infocmd == 3) {
usage ();
return;
} else {
exit (0);
}
case 2:
if (infocmd != 2 ) {
error = the_command_is_incorrect;
return;
} else {
if (infoarg == 1) {
printf ("prec : %d\n\n",prec);
return;
} else if (infoarg == 2) {
printf ("prec : %d\n",prec);
PrintVariable ();
putchar ('\n');
return;
} else {
VARIABLE *tmp;
for (int i = 0;Command[1][i] != NULL;i ++) {
if (!isalpha (Command[1][i])) {
error = find_some_illegal_word;
return;
}
}
if (tmp = VariableSearch (VariableList,Command[1])) {
printf ("%s : ",Command[1]);
if (tmp->Operand.DataSignal == FLOAT) {
printf ("%f\n",tmp->Operand.Data.Real);
} else {
printf ("%d\n",tmp->Operand.Data.Integer);
}
} else {
error = the_var_is_not_seen_before;
return;
}
return;
}
}
case 3:
if (infocmd != 1) {
error = the_command_is_incorrect;
return;
} else {
Calculator ();
if (error != NULL) {
return;
}
if (infoarg == 1) {
if (ExpressionHead->Term.Operand.DataSignal == FLOAT) {
error = the_precision_or_mode_only_accept_integral_argument;
return;
}
if (ExpressionHead->Term.Operand.Data.Integer > 100 || ExpressionHead->Term.Operand.Data.Integer < 0) {
error = the_prec_value_range_from_0_to_100;
return;
}
prec = ExpressionHead->Term.Operand.Data.Integer;
printf ("命令成功執行\n\n");
return;
} else if (infoarg == 2) {
error = the_command_is_incorrect;
return;
} else {
VARIABLE *tmp;
for (int i = 0;Command[1][i] != NULL;i ++) {
if (!isalpha (Command[1][i])) {
error = find_some_illegal_word;
return;
}
}
if (tmp = VariableSearch (VariableList,Command[1])) {
tmp->Operand = ExpressionHead->Term.Operand;
printf ("命令成功執行\n\n");
return;
}
tmp = NewVarNode (Command[1],ExpressionHead->Term.Operand);
VariableListTail = InsertVarNode (VariableListTail,tmp);
printf ("命令成功執行\n\n");
}
}
}
}
void Output (
void
)
{
CmdExecute ();
if (error != NULL) {
PrintError ();
error = NULL;
vision = false;
}
PrintResult (ExpressionHead);
ArgCounter = 0;
infoarg = 0;
infocmd = 0;
vision = false;
DeleteList (ExpressionHead);
ExpressionHead = NULL;
FreeCMD ();
free (Unknown);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -