summaryrefslogtreecommitdiff
path: root/graphics/ketcindy/ketcindyfolder/doc/source/KetCindyPlugin/srcold/KetCindyPlugin160604.java
blob: a32b50fac77b1f833a8aa792874a893848ec51b7 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import de.cinderella.api.cs.CindyScript;
import de.cinderella.api.cs.CindyScriptPlugin;
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.RealMatrix;

import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.io.*;

public class KetCindyPlugin extends CindyScriptPlugin {

    public String getName() {
        return "KetCindy Plugin";
    }

    public String getAuthor() {
        return "The KetCindy Project Team";
    }

    @CindyScript("systemproperty")
    public String getUserID(String s) {
        return System.getProperty(s);
    }

    @CindyScript("square")
    public double quadrieren(double x) {
        return x * x;
    }

    @CindyScript("grayvalue")
    public double getGray(Color c) {
        return (c.getBlue() + c.getRed() + c.getGreen()) / 3.;
    }

    @CindyScript("testarray")
    public String writeArray(ArrayList<Double> al) {
        return Arrays.toString(al.toArray());
    }
    
    @CindyScript("getdir")
    public String getdir() {
        return System.getProperty("user.dir");
    }

    @CindyScript("gethome")
    public String gethome() {
        return System.getProperty("user.home");
    }
	
    @CindyScript("iswindows")
    static public boolean iswindows(){
        String os=System.getProperty("os.name").toLowerCase();
        if(os!=null && os.startsWith("windows")){
            return true;
        }
        else{
            return false;
        }
    }
    @CindyScript("ismacosx")
    public static boolean ismacosx(){
        String os=System.getProperty("os.name").toLowerCase();
        if(os!=null && os.startsWith("mac")){
            return true;
        }
        else{
            return false;
        }
    }
    @CindyScript("islinux")
    public static boolean islinux(){
        String os=System.getProperty("os.name").toLowerCase();
        if(os!=null && os.startsWith("linux")){
            return true;
        }
        else{
            return false;
        }
    }

    @CindyScript("iswin")
    public static boolean iswin() {
        String OS_NAME = System.getProperty("os.name").toLowerCase();
        return OS_NAME.startsWith("windows");
    }

    @CindyScript("kcnow")
    public static Long kcnow(String args){
    return System.currentTimeMillis();
   }

    @CindyScript("kcmodified")
    public static Long kcmodified(String args){
    File f = new File(args);
    return System.currentTimeMillis()-f.lastModified();
   }

    @CindyScript("kc")
    public static void kc(String args) throws IOException {}

    @CindyScript("kc")
    public static void kc(String args,String args2,String args3) throws IOException {
	ProcessBuilder pb = new ProcessBuilder();
    // 16.06.04from
    File f = new File(args);
    int flg=0;
    BufferedReader br = new BufferedReader(new FileReader(f));
    String str;
    while((str = br.readLine()) != null){
    str=str.toUpperCase();
    if(str.indexOf("RM ")>-1){
      flg=1;
    }
    if(str.indexOf("DEL ")>-1){
      flg=1;
    }
    if(str.indexOf("MV ")>-1){
      flg=1;
    }
    if(str.indexOf("RD ")>-1){
      flg=1;
    }
    if(str.indexOf("*")>-1){
      flg=1;
    }
    if(str.indexOf("?")>-1){
      flg=1;
    }
  }
  br.close();
  Long tm=System.currentTimeMillis()-f.lastModified();
//  if(tm<5000 && flg==0){
  if(flg==0){
    if(iswindows()){
      if((args.endsWith("\\kc.bat")&&args2.endsWith("\\ketbin"))&&args3.endsWith(".tex")){
        pb.command("cmd.exe","/c","start",args);
      }
    }
    else{
      if(ismacosx()){
        if((args.endsWith("/kc.sh")&&args2.endsWith("/ketbin"))&&args3.endsWith(".tex")){
          pb.command("sh",args);
        }
      }
      else{
        if((args.endsWith("/kc.sh")&&args2.endsWith("/ketbin"))&&args3.endsWith(".tex")){
          pb.command("sh",args);
        }
      }
    }
  }
  // 16.06.04upto
  Process process = pb.start();
  return;
  }

    @CindyScript("ispaulvisiting")
    public static boolean ispaulvisiting() {
        return true;
    }

    @CindyScript("texv")
    public static void texv( String s,  String d, String sf, String tf) throws Exception{
        ProcessBuilder pb = new ProcessBuilder();
        String[] cmd = {s,d,sf,tf};
        pb.command(cmd);
        Process process = pb.start();
        return ;
    }

    @CindyScript("givemeamatrix2")
    public static Object givemeamatrix2() {
        try {
            return "the Matrix: " + theGiveMeAMatrix().toString();
        } catch (Throwable e) {
            e.printStackTrace();
            return "no Matrix: " + e.toString();
        }
    }

    public static Object theGiveMeAMatrix() {
        double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
        RealMatrix m = MatrixUtils.createRealMatrix(matrixData);
        return m;
    }
    
    @CindyScript("getdirhead")
    public static String getdirhead(){
        if(iswindows()){
            return System.getProperty("user.home")+"\\ketcindy";
        }
        else if(ismacosx()){
            return System.getProperty("user.home")+"/ketcindy";
        }
        else if(islinux()){
            return "/usr/share/ketcindy";
        }
        else{
            return "unknown";
        }
    }


}