2 次代码提交

作者 SHA1 备注 提交日期
  myitinos 0f8e5e8e78 v1.0 5 年前
  myitinos 2676fcc5b6 updated LICENSE file 5 年前
共有 4 个文件被更改,包括 106 次插入1 次删除
  1. +1
    -1
      LICENSE
  2. 二进制
      calc
  3. +104
    -0
      calc.c
  4. +1
    -0
      calc.sh

+ 1
- 1
LICENSE 查看文件

@ -1,5 +1,5 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2018 Leonardo Deo Gratias Agamus
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

二进制
calc 查看文件


+ 104
- 0
calc.c 查看文件

@ -0,0 +1,104 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
/*
* SIGFPE bisa nempel di CPU, perlu dicari solusi
* Test openssl lewat socat
*/
void signal_handler(int sig)
{
signal(SIGFPE, signal_handler);
system("/bin/sh");
exit(1);
}
int main(int argc, char const *argv[])
{
int i_a = 0;
int i_b = 0;
int total = 0;
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
signal(SIGFPE, signal_handler);
puts("Welcome to Online Calculator v3.1");
puts("");
puts("Operator supported: + - * /");
puts("ex: 2 + 2");
puts("ex: 2 + a //'a' to use last results");
puts("");
puts("------------------------------------");
while (1)
{
char c_a[11] = "";
char c_b[11] = "";
char opt = 0;
printf(">");
if (scanf("%10s %c %10s", c_a, &opt, c_b) < 3)
{
puts("Failed to parse expression!");
return 0;
}
else
{
int r1_a = sscanf(c_a, "%d", &i_a);
int r2_a = strcmp("a", c_a) == 0;
int r1_b = sscanf(c_b, "%d", &i_b);
int r2_b = strcmp("a", c_b) == 0;
if ((i_b == 0 && r2_a) && opt == '/')
{
puts("Floating point exception (core dumped)");
return 0;
}
if (r2_a)
{
i_a = total;
}
if (r2_b)
{
i_b = total;
}
if ((r1_a || r2_a) && (r1_b || r2_b))
{
switch (opt)
{
case '+':
total = i_a + i_b;
break;
case '-':
total = i_a - i_b;
break;
case '*':
total = i_a * i_b;
break;
case '/':
total = i_a / i_b;
break;
default:
puts("Unknown operator!");
return 0;
}
printf("=%d\n", total);
}
else
{
puts("Failed to parse operand!");
return 0;
}
}
}
return 0;
}

+ 1
- 0
calc.sh 查看文件

@ -0,0 +1 @@
socat TCP-listen:8080,reuseaddr,fork EXEC:./calc

正在加载...
取消
保存