-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
75 lines (62 loc) · 1.88 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>
<?php
$vars = $_GET["vars"];
$polys = $_GET["polys"];
$ord = $_GET["ord"];
$rcp = $_GET["rcp"];
$hide = $_GET["hide"];
$terms = $_GET["terms"];
$polysA = explode("\n", $polys);
$code = 'LIB "teachstd.lib";' . "\n" . 'LIB "latex.lib";' . "\n";
$code .= 'ring r = 0, (' . $vars . '), ' . $ord . ';' . "\n";
$inputcode = 'list input = ';
for ($i = 0; $i < count($polysA); $i++) {
$poly = trim($polysA[$i]);
if ($poly != "") {
$code .= 'poly p' . ($i+1) . ' = ' . $poly . ';' . "\n";
if ($i > 0)
$inputcode .= ', ';
$inputcode .= 'p' . ($i+1);
}
}
$inputcode .= ';' . "\n";
$code .= $inputcode;
$code .= 'int hidechains = ';
if ($hide == 'yes')
$code .= '1';
else
$code .= '0';
$code .= ';' . "\n";
$code .= 'int rcp = ';
if ($rcp == 'yes')
$code .= '1';
else
$code .= '0';
$code .= ';' . "\n";
if ($terms != "") {
$code .= 'int TeXwidth = ';
$code .= $terms . ';' . "\n";
}
$code .= file_get_contents("buchberger2-singular.txt");
$tmp_singularcode_file = tmpfile();
$tmp_singularcode_path = stream_get_meta_data($tmp_singularcode_file)['uri'];
fwrite($tmp_singularcode_file, $code);
$commandline = "Singular -q -b < " . $tmp_singularcode_path . " 2>&1";
exec($commandline, $output, $retval);
fclose($tmp_singularcode_file);
echo "<body><div>\n";
for ($i=0; $i<count($output); $i++) {
$line = $output[$i];
if (strpos($line, "?") != FALSE || strpos($line, "error") != FALSE) {
echo "<code>" . $line . "</code><br>";
}
else
echo $output[$i];
}
echo "</div></body>";
?>
</html>