From 0353d94e5a5f12eaf4d23b384b6514df87b7083d Mon Sep 17 00:00:00 2001 From: duy Date: Sun, 27 May 2018 22:48:04 +0700 Subject: [PATCH 1/3] Build cppcheck, prepare for static analysis feature --- .idea/modules.xml | 1 + cctools-repo/build-i386.sh | 61 +++++++++++++++++++ cctools-repo/build.sh | 2 +- cctools-repo/doc/export.inc | 8 +-- cctools-repo/misc/build-helper/build-helper | 6 +- cctools-repo/misc/build-helper/run-helper | 2 +- cctools-repo/old/build-shell-utils-gcc-4.7.sh | 8 +-- cctools-repo/patches/dropbear-0.52.patch | 12 ++-- cctools-repo/patches/dropbear-2016.74.patch | 16 ++--- cctools-repo/patches/perl-5.18.1.patch | 4 +- 10 files changed, 91 insertions(+), 29 deletions(-) create mode 100755 cctools-repo/build-i386.sh diff --git a/.idea/modules.xml b/.idea/modules.xml index f0d738c7..bb587933 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -5,6 +5,7 @@ + diff --git a/cctools-repo/build-i386.sh b/cctools-repo/build-i386.sh new file mode 100755 index 00000000..a0e7c330 --- /dev/null +++ b/cctools-repo/build-i386.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +BUILD_START=$(date +%s) + +WRKDIR=$PWD/tmp +#WRKDIR=/mnt/nfs/Work/cctools-pro/tmp + +# +# uncomment to build pie compiler +# ------------------------------- +export BUILD_PIE_COMPILER="yes" +WRKDIR=${WRKDIR}-pie +# ------------------------------- +# + +SDKDIR=/home/duy/Android/Sdk +NDKDIR=/home/duy/Android/android-ndk-r12b +NDKSRC=/home/duy/github + +for d in binutils gcc gmp mpc mpfr cloog isl ppl llvm; do + ln -sf ${NDKSRC}/${d} src/ +done + +export PATH=~/bin/CodeSourcery/bin:$PATH + +#./build-shell-utils.sh ${PWD}/src arm-linux-androideabi ${WRKDIR}/arm-repo $NDKDIR $SDKDIR || exit 1 + +#./build-shell-utils.sh ${PWD}/src mipsel-linux-android ${WRKDIR}/mips-repo $NDKDIR $SDKDIR || exit 1 + +./build-shell-utils.sh ${PWD}/src i686-linux-android ${WRKDIR}/i686-repo $NDKDIR $SDKDIR || exit 1 + +#./build-shell-utils.sh ${PWD}/src aarch64-linux-android ${WRKDIR}/arm64-repo $NDKDIR $SDKDIR || exit 1 + +#./build-shell-utils.sh ${PWD}/src mips64el-linux-android ${WRKDIR}/mips64-repo $NDKDIR $SDKDIR || exit 1 + +#./build-shell-utils.sh ${PWD}/src x86_64-linux-android ${WRKDIR}/x86_64-repo $NDKDIR $SDKDIR || exit 1 + +test -e ${WRKDIR}/repo/armeabi-v7a || ln -sf armeabi ${WRKDIR}/repo/armeabi-v7a +test -e ${WRKDIR}/repo/mips-r2 || ln -sf mips ${WRKDIR}/repo/mips-r2 + +for d in armeabi mips x86 arm64-v8a mips64 x86_64; do + pushd . + cp -f make_packages.sh ${WRKDIR}/repo/${d}/ + cd ${WRKDIR}/repo/${d} + ./make_packages.sh + popd +done + +mkdir -p ${WRKDIR}/repo/src + +find `find src -type d` -type f -exec cp -f {} ${WRKDIR}/repo/src/ \; + +BUILD_END=$(date +%s) + +TOTAL_TIME=$(($BUILD_END - $BUILD_START)) + +echo +echo +echo "Build time: $(date -u -d @$TOTAL_TIME +%T)" +echo +echo "DONE!" diff --git a/cctools-repo/build.sh b/cctools-repo/build.sh index 1b3af1f0..5099e1cb 100755 --- a/cctools-repo/build.sh +++ b/cctools-repo/build.sh @@ -27,7 +27,7 @@ export PATH=~/bin/CodeSourcery/bin:$PATH #./build-shell-utils.sh ${PWD}/src mipsel-linux-android ${WRKDIR}/mips-repo $NDKDIR $SDKDIR || exit 1 -./build-shell-utils.sh ${PWD}/src i686-linux-android ${WRKDIR}/i686-repo $NDKDIR $SDKDIR || exit 1 +#./build-shell-utils.sh ${PWD}/src i686-linux-android ${WRKDIR}/i686-repo $NDKDIR $SDKDIR || exit 1 #./build-shell-utils.sh ${PWD}/src aarch64-linux-android ${WRKDIR}/arm64-repo $NDKDIR $SDKDIR || exit 1 diff --git a/cctools-repo/doc/export.inc b/cctools-repo/doc/export.inc index 798be36c..a4c81628 100644 --- a/cctools-repo/doc/export.inc +++ b/cctools-repo/doc/export.inc @@ -1,5 +1,5 @@ -export LD_LIBRARY_PATH='/data/data/com.pdaxrom.cctools/root/cctools/lib:/system/lib' -export PATH='/data/data/com.pdaxrom.cctools/root/cctools/sbin:/data/data/com.pdaxrom.cctools/root/cctools/bin:/system/xbin:/system/bin:/data/data/com.pdaxrom.cctools/root/cctools/bin:/data/data/com.pdaxrom.cctools/root/cctools/sbin:/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin' -export TEMPDIR='/data/data/com.pdaxrom.cctools/root/cctools/home/tmp' +export LD_LIBRARY_PATH='/data/data/${APPLICATION_ID}/root/cctools/lib:/system/lib' +export PATH='/data/data/${APPLICATION_ID}/root/cctools/sbin:/data/data/${APPLICATION_ID}/root/cctools/bin:/system/xbin:/system/bin:/data/data/${APPLICATION_ID}/root/cctools/bin:/data/data/${APPLICATION_ID}/root/cctools/sbin:/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin' +export TEMPDIR='/data/data/${APPLICATION_ID}/root/cctools/home/tmp' export TERM='xterm' -export TMPDIR='/data/data/com.pdaxrom.cctools/root/cctools/home/tmp' +export TMPDIR='/data/data/${APPLICATION_ID}/root/cctools/home/tmp' diff --git a/cctools-repo/misc/build-helper/build-helper b/cctools-repo/misc/build-helper/build-helper index dbb5d1f0..cb5af8a2 100755 --- a/cctools-repo/misc/build-helper/build-helper +++ b/cctools-repo/misc/build-helper/build-helper @@ -53,7 +53,7 @@ if [ "$openbuild" = true ]; then dialogid="$1" fi - am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.pdaxrom.cctools/.CCToolsActivity \ + am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.duy.c.cpp.compiler/.CCToolsActivity \ --es type build \ --es cmdline "build-helper --native $native --executable $executable --run $run --buildwindow $buildwindow --runwindow $runwindow --dialogid $dialogid $@" \ --es workdir "$PWD" \ @@ -87,7 +87,7 @@ run_exec() { else for m in ${CCTOOLSDIR} ${EXTERNAL_STORAGE}/CCTools; do if [ -e ${m}/share/modules/runargs.xml ]; then - am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.pdaxrom.cctools/.CCToolsActivity \ + am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.duy.c.cpp.compiler/.CCToolsActivity \ --es type module \ --es path ${m}/share/modules/runargs.xml \ --es workdir $PWD \ @@ -158,7 +158,7 @@ fi if [ "$buildwindow" = "true" ]; then for m in ${CCTOOLSDIR} ${EXTERNAL_STORAGE}/CCTools; do if [ -e ${m}/share/modules/compile.xml ]; then - am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.pdaxrom.cctools/.CCToolsActivity \ + am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.duy.c.cpp.compiler/.CCToolsActivity \ --es type module \ --es path ${m}/share/modules/compile.xml \ --es workdir $PWD \ diff --git a/cctools-repo/misc/build-helper/run-helper b/cctools-repo/misc/build-helper/run-helper index 6d471627..5f9a673a 100755 --- a/cctools-repo/misc/build-helper/run-helper +++ b/cctools-repo/misc/build-helper/run-helper @@ -10,7 +10,7 @@ mkdir -p ${CCTOOLSDIR}/tmp cp -f $in ${CCTOOLSDIR}/tmp/$out chmod 755 ${CCTOOLSDIR}/tmp/$out -am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.pdaxrom.cctools/.CCToolsActivity \ +am start $(am 2>&1 | grep -q '\-\-user' && echo '--user 0') -n com.duy.c.cpp.compiler/.CCToolsActivity \ --es type terminal \ --es title "$out" \ --es cmdline "/system/bin/sh -c \"${CCTOOLSDIR}/tmp/$out $args\"" \ diff --git a/cctools-repo/old/build-shell-utils-gcc-4.7.sh b/cctools-repo/old/build-shell-utils-gcc-4.7.sh index a3cb6475..9af31928 100644 --- a/cctools-repo/old/build-shell-utils-gcc-4.7.sh +++ b/cctools-repo/old/build-shell-utils-gcc-4.7.sh @@ -5,8 +5,8 @@ nano_version=2.2.6 busybox_version=1.20.2 emacs_version=24.2 -TARGET_INST_DIR="/data/data/com.pdaxrom.cctools/root/cctools" -#TARGET_INST_DIR="/data/data/com.pdaxrom.cctools/cache/cctools" +TARGET_INST_DIR="/data/data/${APPLICATION_ID}/root/cctools" +#TARGET_INST_DIR="/data/data/${APPLICATION_ID}/cache/cctools" SRC_PREFIX="$1" @@ -512,7 +512,7 @@ build_fpc() { OS_TARGET=linux \ CROSSBINDIR="$crossbindir" \ OPT=$opt \ - INSTALL_PREFIX=/data/data/com.pdaxrom.cctools/root/cctools || error "FPC build" + INSTALL_PREFIX=/data/data/${APPLICATION_ID}/root/cctools || error "FPC build" # PP=fpc make zipinstall \ @@ -520,7 +520,7 @@ build_fpc() { OS_TARGET=linux \ CROSSBINDIR="$crossbindir" \ OPT=$opt \ - INSTALL_PREFIX=/data/data/com.pdaxrom.cctools/root/cctools || error "FPC tgzinstall" + INSTALL_PREFIX=/data/data/${APPLICATION_ID}/root/cctools || error "FPC tgzinstall" # PP=fpc error "asd" diff --git a/cctools-repo/patches/dropbear-0.52.patch b/cctools-repo/patches/dropbear-0.52.patch index 3b1b4dde..d85f6572 100644 --- a/cctools-repo/patches/dropbear-0.52.patch +++ b/cctools-repo/patches/dropbear-0.52.patch @@ -96,11 +96,11 @@ diff -Nur dropbear-0.52-orig/options.h dropbear-0.52/options.h /* Default hostkey paths - these can be specified on the command line */ #ifndef DSS_PRIV_FILENAME -#define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key" -+#define DSS_PRIV_FILENAME "/data/data/com.pdaxrom.cctools/root/cctools/etc/dropbear_dss_host_key" ++#define DSS_PRIV_FILENAME "/data/data/com.duy.c.cpp.compiler/root/cctools/etc/dropbear_dss_host_key" #endif #ifndef RSA_PRIV_FILENAME -#define RSA_PRIV_FILENAME "/etc/dropbear/dropbear_rsa_host_key" -+#define RSA_PRIV_FILENAME "/data/data/com.pdaxrom.cctools/root/cctools/etc/dropbear_rsa_host_key" ++#define RSA_PRIV_FILENAME "/data/data/com.duy.c.cpp.compiler/root/cctools/etc/dropbear_rsa_host_key" #endif /* Set NON_INETD_MODE if you require daemon functionality (ie Dropbear listens @@ -193,7 +193,7 @@ diff -Nur dropbear-0.52-orig/options.h dropbear-0.52/options.h scripts etc. This can be overridden with the -P flag */ #ifndef DROPBEAR_PIDFILE -#define DROPBEAR_PIDFILE "/var/run/dropbear.pid" -+#define DROPBEAR_PIDFILE "/data/data/com.pdaxrom.cctools/root/dropbear.pid" ++#define DROPBEAR_PIDFILE "/data/data/com.duy.c.cpp.compiler/root/dropbear.pid" #endif /* The command to invoke for xauth when using X11 forwarding. @@ -210,13 +210,13 @@ diff -Nur dropbear-0.52-orig/options.h dropbear-0.52/options.h * be enabled */ #ifndef SFTPSERVER_PATH -#define SFTPSERVER_PATH "/usr/libexec/sftp-server" -+#define SFTPSERVER_PATH "/data/data/com.pdaxrom.cctools/root/cctools/libexec/sftp-server" ++#define SFTPSERVER_PATH "/data/data/com.duy.c.cpp.compiler/root/cctools/libexec/sftp-server" #endif /* This is used by the scp binary when used as a client binary. If you're * not using the Dropbear client, you'll need to change it */ -#define _PATH_SSH_PROGRAM "/usr/bin/dbclient" -+#define _PATH_SSH_PROGRAM "/data/data/com.pdaxrom.cctools/root/cctools/bin/dbclient" ++#define _PATH_SSH_PROGRAM "/data/data/com.duy.c.cpp.compiler/root/cctools/bin/dbclient" /* Whether to log commands executed by a client. This only logs the * (single) command sent to the server, not what a user did in a @@ -225,7 +225,7 @@ diff -Nur dropbear-0.52-orig/options.h dropbear-0.52/options.h /* The default path. This will often get replaced by the shell */ -#define DEFAULT_PATH "/usr/bin:/bin" -+#define DEFAULT_PATH "/data/data/com.pdaxrom.cctools/root/cctools/sbin:/data/data/com.pdaxrom.cctools/root/cctools/bin:/system/sbin:/system/bin:/system/xbin" ++#define DEFAULT_PATH "/data/data/com.duy.c.cpp.compiler/root/cctools/sbin:/data/data/com.duy.c.cpp.compiler/root/cctools/bin:/system/sbin:/system/bin:/system/xbin" /* Some other defines (that mostly should be left alone) are defined * in sysoptions.h */ diff --git a/cctools-repo/patches/dropbear-2016.74.patch b/cctools-repo/patches/dropbear-2016.74.patch index 28a34eda..e49f5494 100644 --- a/cctools-repo/patches/dropbear-2016.74.patch +++ b/cctools-repo/patches/dropbear-2016.74.patch @@ -272,15 +272,15 @@ diff -Nur dropbear-2016.74-orig/options.h dropbear-2016.74/options.h /* Default hostkey paths - these can be specified on the command line */ #ifndef DSS_PRIV_FILENAME -#define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key" -+#define DSS_PRIV_FILENAME "/data/data/com.pdaxrom.cctools/root/cctools/etc/dropbear/dropbear_dss_host_key" ++#define DSS_PRIV_FILENAME "/data/data/com.duy.c.cpp.compiler/root/cctools/etc/dropbear/dropbear_dss_host_key" #endif #ifndef RSA_PRIV_FILENAME -#define RSA_PRIV_FILENAME "/etc/dropbear/dropbear_rsa_host_key" -+#define RSA_PRIV_FILENAME "/data/data/com.pdaxrom.cctools/root/cctools/etc/dropbear/dropbear_rsa_host_key" ++#define RSA_PRIV_FILENAME "/data/data/com.duy.c.cpp.compiler/root/cctools/etc/dropbear/dropbear_rsa_host_key" #endif #ifndef ECDSA_PRIV_FILENAME -#define ECDSA_PRIV_FILENAME "/etc/dropbear/dropbear_ecdsa_host_key" -+#define ECDSA_PRIV_FILENAME "/data/data/com.pdaxrom.cctools/root/cctools/etc/dropbear/dropbear_ecdsa_host_key" ++#define ECDSA_PRIV_FILENAME "/data/data/com.duy.c.cpp.compiler/root/cctools/etc/dropbear/dropbear_ecdsa_host_key" #endif /* Set NON_INETD_MODE if you require daemon functionality (ie Dropbear listens @@ -344,14 +344,14 @@ diff -Nur dropbear-2016.74-orig/options.h dropbear-2016.74/options.h scripts etc. This can be overridden with the -P flag */ #ifndef DROPBEAR_PIDFILE -#define DROPBEAR_PIDFILE "/var/run/dropbear.pid" -+#define DROPBEAR_PIDFILE "/data/data/com.pdaxrom.cctools/root/cctools/var/run/dropbear.pid" ++#define DROPBEAR_PIDFILE "/data/data/com.duy.c.cpp.compiler/root/cctools/var/run/dropbear.pid" #endif /* The command to invoke for xauth when using X11 forwarding. * "-q" for quiet */ #ifndef XAUTH_COMMAND -#define XAUTH_COMMAND "/usr/bin/xauth -q" -+#define XAUTH_COMMAND "/data/data/com.pdaxrom.cctools/root/cctools/bin/xauth -q" ++#define XAUTH_COMMAND "/data/data/com.duy.c.cpp.compiler/root/cctools/bin/xauth -q" #endif /* if you want to enable running an sftp server (such as the one included with @@ -359,13 +359,13 @@ diff -Nur dropbear-2016.74-orig/options.h dropbear-2016.74/options.h * be enabled */ #ifndef SFTPSERVER_PATH -#define SFTPSERVER_PATH "/usr/libexec/sftp-server" -+#define SFTPSERVER_PATH "/data/data/com.pdaxrom.cctools/root/cctools/libexec/sftp-server" ++#define SFTPSERVER_PATH "/data/data/com.duy.c.cpp.compiler/root/cctools/libexec/sftp-server" #endif /* This is used by the scp binary when used as a client binary. If you're * not using the Dropbear client, you'll need to change it */ -#define DROPBEAR_PATH_SSH_PROGRAM "/usr/bin/dbclient" -+#define DROPBEAR_PATH_SSH_PROGRAM "/data/data/com.pdaxrom.cctools/root/cctools/bin/dbclient" ++#define DROPBEAR_PATH_SSH_PROGRAM "/data/data/com.duy.c.cpp.compiler/root/cctools/bin/dbclient" /* Whether to log commands executed by a client. This only logs the * (single) command sent to the server, not what a user did in a @@ -374,7 +374,7 @@ diff -Nur dropbear-2016.74-orig/options.h dropbear-2016.74/options.h /* The default path. This will often get replaced by the shell */ -#define DEFAULT_PATH "/usr/bin:/bin" -+#define DEFAULT_PATH "/data/data/com.pdaxrom.cctools/root/cctools/sbin:/data/data/com.pdaxrom.cctools/root/cctools/bin:/system/sbin:/system/bin:/system/xbin" ++#define DEFAULT_PATH "/data/data/com.duy.c.cpp.compiler/root/cctools/sbin:/data/data/com.duy.c.cpp.compiler/root/cctools/bin:/system/sbin:/system/bin:/system/xbin" /* Some other defines (that mostly should be left alone) are defined * in sysoptions.h */ diff --git a/cctools-repo/patches/perl-5.18.1.patch b/cctools-repo/patches/perl-5.18.1.patch index 0399dcdc..0fb169fb 100644 --- a/cctools-repo/patches/perl-5.18.1.patch +++ b/cctools-repo/patches/perl-5.18.1.patch @@ -9,7 +9,7 @@ } my $ld_run_path_shell = ""; ---- /data/data/com.pdaxrom.cctools/root/cctools/home/perl-5.18.1/Configure +--- /data/data/com.duy.c.cpp.compiler/root/cctools/home/perl-5.18.1/Configure +++ s/Configure @@ -1347,7 +1347,7 @@ @@ -40,7 +40,7 @@ foreach my $try ('/bin/pwd', '/usr/bin/pwd', '/QOpenSys/bin/pwd', # OS/400 PASE. -+ '/data/data/com.pdaxrom.cctools/root/cctools/bin/pwd', ++ '/data/data/com.duy.c.cpp.compiler/root/cctools/bin/pwd', ) { if( -x $try ) { From 95d224487a586898b918670148fa38cb02af0e4e Mon Sep 17 00:00:00 2001 From: duy Date: Sun, 27 May 2018 22:55:40 +0700 Subject: [PATCH 2/3] refactor code --- app/src/main/AndroidManifest.xml | 2 +- .../main/java/com/duy/CppIdeApplication.java | 14 +++++ .../editor/v2/TextEditorApplication.java | 52 ------------------- 3 files changed, 15 insertions(+), 53 deletions(-) create mode 100644 app/src/main/java/com/duy/CppIdeApplication.java delete mode 100644 app/src/main/java/com/jecelyin/editor/v2/TextEditorApplication.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1fd50ded..2c0d72b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ - * - * This file is part of 920 Text Editor. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jecelyin.editor.v2; - -import android.content.Context; -import android.support.multidex.MultiDexApplication; - -import com.duy.common.DLog; - -import java.util.Map; - -/** - * @author Jecelyin Peng - */ -public class TextEditorApplication extends MultiDexApplication { - private static final String TAG = "TextEditorApplication"; - private static Context context; - - public static Context getContext() { - return context; - } - - @Override - public void onCreate() { - super.onCreate(); - context = getApplicationContext(); - if (DLog.DEBUG) { - Map env = System.getenv(); - DLog.d(TAG, "onCreate: default env"); - for (Map.Entry entry : env.entrySet()) { - DLog.d(TAG, "entry = " + entry); - } - } - } - -} From f7b5d664d743b639ea3820e6ddb98f61bb4931e5 Mon Sep 17 00:00:00 2001 From: duy Date: Sun, 27 May 2018 23:06:16 +0700 Subject: [PATCH 3/3] cleanup --- .../com/pdaxrom/cctools/CCToolsActivity.java | 17 +- .../java/com/pdaxrom/editor/AsmSyntax.java | 74 -------- .../main/java/com/pdaxrom/editor/CSyntax.java | 97 ----------- .../java/com/pdaxrom/editor/CodeEditor.java | 158 +----------------- .../com/pdaxrom/editor/FortranSyntax.java | 114 ------------- .../java/com/pdaxrom/editor/JavaSyntax.java | 82 --------- .../java/com/pdaxrom/editor/LuaSyntax.java | 113 ------------- .../java/com/pdaxrom/editor/MakeSyntax.java | 81 --------- .../java/com/pdaxrom/editor/PerlSyntax.java | 92 ---------- .../java/com/pdaxrom/editor/ShellSyntax.java | 92 ---------- 10 files changed, 3 insertions(+), 917 deletions(-) delete mode 100644 app/src/main/java/com/pdaxrom/editor/AsmSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/CSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/FortranSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/JavaSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/LuaSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/MakeSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/PerlSyntax.java delete mode 100644 app/src/main/java/com/pdaxrom/editor/ShellSyntax.java diff --git a/app/src/main/java/com/pdaxrom/cctools/CCToolsActivity.java b/app/src/main/java/com/pdaxrom/cctools/CCToolsActivity.java index d3c128e7..9a2e8709 100644 --- a/app/src/main/java/com/pdaxrom/cctools/CCToolsActivity.java +++ b/app/src/main/java/com/pdaxrom/cctools/CCToolsActivity.java @@ -313,22 +313,7 @@ public void onBackPressed() { public boolean onContextItemSelected(android.view.MenuItem item) { - switch (item.getItemId()) { - case TEXT_GOTO: - gotoDialog(); - break; - case TEXT_FIND: - searchDialog(); - break; - case TEXT_UNDO: - codeEditor.undo(); - break; - case TEXT_REDO: - codeEditor.redo(); - break; - default: - return super.onContextItemSelected(item); - } + return true; } diff --git a/app/src/main/java/com/pdaxrom/editor/AsmSyntax.java b/app/src/main/java/com/pdaxrom/editor/AsmSyntax.java deleted file mode 100644 index aa24ff05..00000000 --- a/app/src/main/java/com/pdaxrom/editor/AsmSyntax.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; - -public class AsmSyntax extends SyntaxHighLighting { - private final static int GREEN = 0xff228b22; - private final static int BRIGHTGREEN = 0xff32cd32; - private final static int BRIGHTYELLOW = 0xffffff00; - private final static int BRIGHTBLUE = 0xff4169e1; - private final static int BRIGHTCYAN = 0xff00ffff; - // private final static int RED = 0xffff0000; - private final static int BRIGHTRED = 0xffff7f50; - private final static int GRAY = 0xffbebebe; - - private final static int UNKNOWN = 0; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?md)(//|@).*$|(?s)/\\*.*?\\*/|" - + - "\"(\\\\.|[^\\\\\"])*\"|" - + - "'([^'\\\\]|(\\\\[\\\\\"'abfnrtv\\\\]))'|'\\\\[0-3]?[0-7]{1,2}'|'\\\\x[0-9A-Fa-f]{1,2}'|" - + - "<([^= \t])*?>" -// + -// ";" - , UNKNOWN), - new HighLightRule( - "\\.\\b(data|subsection|text)\\b", - BRIGHTGREEN), - new HighLightRule( - "\\.\\b(align|file|globl|global|hidden|section|size|type|weak|ident|arch|fpu)\\b", - GREEN), - new HighLightRule( - "\\.\\b(ascii|asciz|byte|double|float|hword|int|long|short|single|struct|word|uleb)\\b" - , BRIGHTYELLOW), - new HighLightRule( - "(?md)^\\s*([.0-9A-Za-z_])*:", - BRIGHTRED - ), - new HighLightRule( - "(?md)^\\s*#\\s*(define|include(_next)?|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)\\b" - , BRIGHTCYAN), - }; - - public AsmSyntax() { - setRules(mRules); - } - - public void exec(Editable text) { - super.exec(text); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - if (color_id == UNKNOWN) { - return decodeUnknown(text.charAt(m.start())); - } - return color_id; - } - - private int decodeUnknown(char ch) { - switch (ch) { - case '@': - case '/': - return BRIGHTBLUE; - case '"': - case '\'': - } - return GRAY; - } -} diff --git a/app/src/main/java/com/pdaxrom/editor/CSyntax.java b/app/src/main/java/com/pdaxrom/editor/CSyntax.java deleted file mode 100644 index 91fc7166..00000000 --- a/app/src/main/java/com/pdaxrom/editor/CSyntax.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; - -public class CSyntax extends SyntaxHighLighting { - private final static int UNKNOWN = 0; - private final static int KEYWORD = 1; - private final static int VARIABLE = 2; - private final static int PREPROCESSOR = 3; - private final static int DATA = 4; - private final static int COMMENT = 5; - - private final static int COLOR_UNKNOWN = 0xff000000; - private final static int COLOR_KEYWORD = 0xffa52a2a; - private final static int COLOR_VARIABLE = 0xff2e8b57; - private final static int COLOR_PREPROCESSOR = 0xffa020f0; - private final static int COLOR_DATA = 0xffff00ff; - private final static int COLOR_COMMENT = 0xff2500ff; - private HighLightRule[] mRules = { - new HighLightRule( - "(?md)//.*$|(?s)/\\*.*?\\*/|" - + - "\"(\\\\.|[^\\\\\"])*\"|" - + - "'([^'\\\\]|(\\\\[\\\\\"'abfnrtv\\\\]))'|'\\\\[0-3]?[0-7]{1,2}'|'\\\\x[0-9A-Fa-f]{1,2}'|" - + - "<([^= \t])*?>" -// + -// ";" - , UNKNOWN), - new HighLightRule( - "(?md)^\\s*#\\s*(define|include(_next)?|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)\\b" - , PREPROCESSOR), - new HighLightRule( - "\\b(float|double|bool|char|int|short|long|sizeof|enum|void|auto|static|const|struct|union|typedef|extern|(un)?signed|inline)\\b|" + - "\\b((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\\b" - , VARIABLE), - new HighLightRule( - "\\b(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\\b|" + - "\\b(for|if|while|do|else|case|default|switch)\\b|" + - "\\b(try|throw|catch|operator|new|delete)\\b|" + - "\\b(goto|continue|break|return)\\b" - , KEYWORD), -// new HighLightRule( -// "\\b[0-9].*" -// , DATA) - }; - - public CSyntax() { - setRules(mRules); - } - - public void exec(Editable text) { - super.exec(text); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - switch (color_id) { - case VARIABLE: - return COLOR_VARIABLE; - case KEYWORD: - return COLOR_KEYWORD; - case PREPROCESSOR: - return COLOR_PREPROCESSOR; - case DATA: - return COLOR_DATA; - case COMMENT: - return COLOR_COMMENT; - case UNKNOWN: - return decodeUnknown(text.charAt(m.start())); - } - return COLOR_BLACK; - } - - private int decodeUnknown(char ch) { - switch (ch) { - case '/': - return COLOR_COMMENT; - case '"': - case '\'': - case '<': - return COLOR_DATA; -// case ';': return COLOR_KEYWORD; - } - return COLOR_UNKNOWN; - } - - public boolean isAutoPair() { - return true; - } - - public boolean isAutoIndent() { - return true; - } -} diff --git a/app/src/main/java/com/pdaxrom/editor/CodeEditor.java b/app/src/main/java/com/pdaxrom/editor/CodeEditor.java index a8f58c48..05c9a9b9 100644 --- a/app/src/main/java/com/pdaxrom/editor/CodeEditor.java +++ b/app/src/main/java/com/pdaxrom/editor/CodeEditor.java @@ -28,9 +28,6 @@ public class CodeEditor extends EditText { private final static String TAG = "cctools-codeEditor"; - Rect drawingRect = new Rect(); - Rect originalClipRect = new Rect(); - private int TYPE_DELAY = 200; private String m_FileName = null; private boolean m_textHasChanged; private boolean m_textHasChangedPrev; @@ -42,25 +39,16 @@ public class CodeEditor extends EditText { private Paint m_gutterLinePaint; private Paint m_gutterTextPaint; private FontMetrics fm; - private Handler m_Handler = new Handler(); private SyntaxHighLighting mSyntax; private int m_lastSearchPos; private String m_lastSearchText; private EditHistory m_History; - private boolean m_IsUndoOrRedo; private boolean m_useAutoPair; private boolean m_useAutoIndent; private CodeEditorInterface m_codeEditorInterface = null; private int m_gutterTextColor; private int m_gutterLineColor; private int m_gutterPadding; - private Runnable mUpdateSyntaxTask = new Runnable() { - public void run() { - if (mSyntax != null) { - mSyntax.exec(getText()); - } - } - }; public CodeEditor(Context context) { super(context); @@ -103,92 +91,6 @@ public void setDefaults(AttributeSet attrs) { super.setPadding(m_gutterSize, m_gutterPadding, m_gutterPadding, m_gutterPadding); super.setHorizontallyScrolling(true); - addTextChangedListener(new TextWatcher() { - private CharSequence mmBeforeChange; - private CharSequence mmAfterChange; - private boolean disableAutoPairing = false; - private boolean braceLeftPressed = false; - - public void afterTextChanged(Editable arg0) { - if (!m_highlightText) { - return; - } - m_Handler.removeCallbacks(mUpdateSyntaxTask); - m_Handler.postDelayed(mUpdateSyntaxTask, TYPE_DELAY); - } - - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - if (!m_IsUndoOrRedo) { - mmBeforeChange = s.subSequence(start, start + count); - } - } - - public void onTextChanged(CharSequence s, int start, int before, - int count) { - //Log.i(TAG, "onTextChanged " + start + " " + before + " " + count + " " + s.length() + "[" + s.subSequence(start, start + count) + "]"); - m_textHasChanged = true; - if (m_codeEditorInterface != null && m_textHasChanged != m_textHasChangedPrev) { - m_codeEditorInterface.textHasChanged(m_textHasChanged); - } - m_textHasChangedPrev = m_textHasChanged; - - if (!m_IsUndoOrRedo) { - mmAfterChange = s.subSequence(start, start + count); - m_History.add(new EditItem(start, mmBeforeChange, mmAfterChange)); - - if (mSyntax != null) { - if (m_useAutoPair && mSyntax.isAutoPair()) { - if (!disableAutoPairing) { - char begChar[] = {'(', '[', '"', '\''}; - CharSequence endChar[] = {")", "]", "\"", "\'"}; - int i; - for (i = 0; i < begChar.length; i++) { - if (count > 0 && mmAfterChange.charAt(0) == begChar[i]) { - disableAutoPairing = true; - getText().insert(start + 1, endChar[i]); - setSelection(start + 1); - } - } - } else { - disableAutoPairing = false; - } - } - - if (m_useAutoIndent && mSyntax.isAutoIndent()) { - if (count > 0 && mmAfterChange.charAt(0) == '\n') { - int i; - String addString = ""; - for (i = start - 1; i > 0 && getText().charAt(i) != '\n'; i--) { - char c = getText().charAt(i); - if (c == ' ' || c == '\t') { - addString = c + addString; - } else { - addString = ""; - } - } - if (m_useAutoPair && mSyntax.isAutoPair() && braceLeftPressed) { - braceLeftPressed = false; - String endLine = ""; - if (getText().length() - 1 == start) { - endLine = "\n"; - } - getText().insert(start + 1, addString + "\t\n" + addString + "}" + endLine); - setSelection(start + 2 + addString.length()); - } else { - getText().insert(start + 1, addString); - } - } - if (count > 0 && mmAfterChange.charAt(0) == '{') { - braceLeftPressed = true; - } else { - braceLeftPressed = false; - } - } - } - } - } - }); setOnKeyListener(new OnKeyListener() { @@ -262,7 +164,6 @@ private void resetHistory() { } else { m_History.clean(); } - m_IsUndoOrRedo = false; } public void setTextSize(float size) { @@ -327,17 +228,10 @@ public void setGutterSize(int g) { m_gutterSize = g; } - public boolean getAutoPair() { - return m_useAutoPair; - } - public void setAutoPair(boolean val) { m_useAutoPair = val; } - public boolean getAutoIndent() { - return m_useAutoIndent; - } public void setAutoIndent(boolean val) { m_useAutoIndent = val; @@ -414,38 +308,7 @@ protected void onDraw(Canvas canvas) { } private void setSyntax(String file) { - mSyntax = null; - String main_file = (new File(file)).getName(); - if (main_file.contentEquals("Makefile") || main_file.contentEquals("makefile")) { - mSyntax = new MakeSyntax(); - } else if (file.lastIndexOf(".") != -1) { - String ext = file.substring(file.lastIndexOf(".")); - //Log.i(TAG, "Extension " + ext); - if (ext.contentEquals(".mk") || ext.contentEquals(".mak")) { - mSyntax = new MakeSyntax(); - } else if (ext.contentEquals(".sh")) { - mSyntax = new ShellSyntax(); - } else if (ext.equals(".pl") || ext.equals(".pm")) { - mSyntax = new PerlSyntax(); - } else if (ext.contentEquals(".lua")) { - mSyntax = new LuaSyntax(); - } else if (ext.contentEquals(".java")) { - mSyntax = new JavaSyntax(); - } else if (ext.contentEquals(".f") || ext.contentEquals(".f90") || - ext.contentEquals(".f95") || ext.contentEquals(".f03")) { - mSyntax = new FortranSyntax(); - } else if (ext.contentEquals(".s") || ext.contentEquals(".S") || - ext.contentEquals(".asm")) { - mSyntax = new AsmSyntax(); - } else if (ext.contentEquals(".c") || ext.contentEquals(".cpp") || - ext.contentEquals(".c++") || - ext.contentEquals(".h") || ext.contentEquals(".hpp") || ext.contentEquals(".h++")) { - mSyntax = new CSyntax(); - } - } - if (mSyntax != null) { - mSyntax.exec(getText()); - } + } public void newFile() { @@ -480,20 +343,7 @@ public boolean loadFile(String file) { } public boolean saveFile(String file) { - m_FileName = file; - FileOutputStream fout; - try { - fout = new FileOutputStream(file); - fout.write(getText().toString().getBytes()); - fout.close(); - setSyntax(file); - resetTriggers(); - return true; - } catch (FileNotFoundException e) { - Log.i(TAG, "File not found " + e); - } catch (IOException e) { - Log.i(TAG, "Error " + e); - } + return false; } @@ -509,9 +359,7 @@ public void undo() { Editable text = getText(); int start = edit.mmIndex; int end = start + (edit.mmAfter != null ? edit.mmAfter.length() : 0); - m_IsUndoOrRedo = true; text.replace(start, end, edit.mmBefore); - m_IsUndoOrRedo = false; setSelection(edit.mmBefore == null ? start : (start + edit.mmBefore.length())); if (m_History.getPosition() == 0) { m_textHasChanged = false; @@ -530,9 +378,7 @@ public void redo() { Editable text = getText(); int start = edit.mmIndex; int end = start + (edit.mmBefore != null ? edit.mmBefore.length() : 0); - m_IsUndoOrRedo = true; text.replace(start, end, edit.mmAfter); - m_IsUndoOrRedo = false; setSelection(edit.mmAfter == null ? start : (start + edit.mmAfter.length())); } } diff --git a/app/src/main/java/com/pdaxrom/editor/FortranSyntax.java b/app/src/main/java/com/pdaxrom/editor/FortranSyntax.java deleted file mode 100644 index 455a250c..00000000 --- a/app/src/main/java/com/pdaxrom/editor/FortranSyntax.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class FortranSyntax extends SyntaxHighLighting { - private final static int QUOTE = 1; - private final static int COMMENT = 2; - private final static int COMMAND = 3; - private final static int CONDITION = 4; - private final static int FUNCTION = 5; - private final static int STATEMENT = 6; - private final static int NUMBER = 7; - private final static int UNKNOWN = 8; - - private final static int COLOR_QUOTE = 0xFFFFFF33; - private final static int COLOR_COMMENT = 0xFF0033FF; - private final static int COLOR_COMMAND = 0xFF33FF00; - private final static int COLOR_CONDITION = 0xFFFFD700; - private final static int COLOR_FUNCTION = 0xFF00B7EB; - private final static int COLOR_STATEMENT = 0xFFEE82EE; - private final static int COLOR_NUMBER = 0xFFFF0033; - private final static int COLOR_UNKNOWN = 0xff808080; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?md)!.*$|(?s)\"(\\\\.|[^\\\\\"])*\"" - , UNKNOWN), - new HighLightRule( - "(?i)\\b(action|advance|all|allocatable|allocated|any|apostrophe|" + - "append|asis|assign|assignment|associated|character|common|" + - "complex|data|default|delim|dimension|double precision|" + - "elemental|end module|end program|end subroutine|epsilon|external|file|fmt|form|format|huge|" + - "implicit|include|index|inquire|integer|intent|interface|" + - "intrinsic|iostat|kind|logical|module|none|null|only|" + - "operator|optional|pack|parameter|pointer|position|private|" + - "program|public|real|recl|recursive|subroutine|status)\\b|>" + - "\\b(selected_int_kind)\\b|\\b(selected_real_kind)\\b" - , COMMAND), - new HighLightRule( - "(?i)\\b(abs|achar|adjustl|adjustr|allocate|bit_size|call|char|" + - "close|contains|count|cpu_time|cshift|date_and_time|" + - "deallocate|digits|dot_product|eor|eoshift|function|iachar|" + - "iand|ibclr|ibits|ibset|ichar|ieor|iolength|ior|ishft|ishftc|" + - "lbound|len|len_trim|matmul|maxexponent|maxloc|maxval|merge|" + - "minexponent|minloc|minval|mvbits|namelist|nearest|nullify|" + - "open|pad|present|print|product|pure|quote|radix|" + - "random_number|random_seed|range|read|readwrite|replace|" + - "reshape|rewind|save|scan|sequence|shape|sign|size|spacing|" + - "spread|sum|system_clock|target|transfer|transpose|trim|" + - "ubound|unpack|verify|write|tiny|type|use|yes)\\b" - , FUNCTION), - new HighLightRule( - "(?i)\\b(case|do|else|else?if|else?where|end|end?do|end?if|" + - "end?select|forall|if|lge|lgt|lle|llt|" + - "repeat|select case|then|where|while)\\b|" + - "\\.\\b(and|or|eqv|neqv|not)\\b\\." - , CONDITION), - new HighLightRule( - "(?i)\\b(continue|cycle|exit|go?to|result|return)\\b" - , STATEMENT), - new HighLightRule( - "\\b[0-9]+\\b" - , NUMBER), - }; - - public FortranSyntax() { - setRules(mRules); - } - - public void exec(Editable text) { - super.exec(text); - // Replace two spaces from begin line to six spaces - Matcher m = Pattern.compile("(?m)^ $").matcher(text); - while (m.find()) - text.replace(m.start(), m.end(), " "); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - switch (color_id) { - case QUOTE: - return COLOR_QUOTE; - case COMMENT: - return COLOR_COMMENT; - case COMMAND: - return COLOR_COMMAND; - case CONDITION: - return COLOR_CONDITION; - case FUNCTION: - return COLOR_FUNCTION; - case STATEMENT: - return COLOR_STATEMENT; - case NUMBER: - return COLOR_NUMBER; - case UNKNOWN: - return decodeUnknown(text.charAt(m.start())); - } - return COLOR_BLACK; - } - - private int decodeUnknown(char ch) { - switch (ch) { - case '!': - return COLOR_COMMENT; - case '"': - return COLOR_QUOTE; - } - return COLOR_UNKNOWN; - } - - -} diff --git a/app/src/main/java/com/pdaxrom/editor/JavaSyntax.java b/app/src/main/java/com/pdaxrom/editor/JavaSyntax.java deleted file mode 100644 index 0422dae8..00000000 --- a/app/src/main/java/com/pdaxrom/editor/JavaSyntax.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; - -public class JavaSyntax extends SyntaxHighLighting { - private final static int GREEN = 0xff228b22; - // private final static int BRIGHTGREEN = 0xff32cd32; - private final static int BRIGHTYELLOW = 0xffffff00; - private final static int BRIGHTBLUE = 0xff4169e1; - private final static int BLUE = 0xff0000ee; - private final static int BRIGHTCYAN = 0xff00ffff; - private final static int RED = 0xffff0000; - // private final static int BRIGHTRED = 0xffff7f50; - private final static int GRAY = 0xffbebebe; - private final static int FUCHSIA = 0xffff00ff; - - private final static int UNKNOWN = 0; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?md)(//|@).*$|(?s)/\\*.*?\\*/|" - + - "\"(\\\\.|[^\\\\\"])*\"|" - + - "'([^'\\\\]|(\\\\[\\\\\"'abfnrtv\\\\]))'|'\\\\[0-3]?[0-7]{1,2}'|'\\\\x[0-9A-Fa-f]{1,2}'|" - + - "<([^= \t])*?>" -// + -// ";" - , UNKNOWN), - new HighLightRule( - "\\b(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\\b", - GREEN), - new HighLightRule( - "\\b(break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\\b" - , RED), - new HighLightRule( - "\\b(abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\\b" - , BRIGHTCYAN), - new HighLightRule( - "\\b(true|false|null)\\b" - , BRIGHTYELLOW), - }; - - public JavaSyntax() { - setRules(mRules); - } - - public void exec(Editable text) { - super.exec(text); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - if (color_id == UNKNOWN) { - return decodeUnknown(text.charAt(m.start())); - } - return color_id; - } - - private int decodeUnknown(char ch) { - switch (ch) { - case '@': - return BLUE; - case '/': - return BRIGHTBLUE; - case '"': - case '\'': - return FUCHSIA; - } - return GRAY; - } - - public boolean isAutoPair() { - return true; - } - - public boolean isAutoIndent() { - return true; - } -} diff --git a/app/src/main/java/com/pdaxrom/editor/LuaSyntax.java b/app/src/main/java/com/pdaxrom/editor/LuaSyntax.java deleted file mode 100644 index ee65bc10..00000000 --- a/app/src/main/java/com/pdaxrom/editor/LuaSyntax.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; - -public class LuaSyntax extends SyntaxHighLighting { - private final static int UNKNOWN = 0; - private final static int OPERATOR = 1; - private final static int STATEMENT = 2; - private final static int KEYWORD = 3; - private final static int LIBRARY = 4; - private final static int FILEHANDLE = 5; - private final static int CONSTANT = 6; - private final static int EXTFILE = 7; - private final static int NUMBER = 8; - private final static int STRING = 9; - private final static int COMMENT = 10; - private final static int SYMBOL = 11; - - private final static int COLOR_UNKNOWN = 0xff000000; - private final static int COLOR_OPERATOR = 0xffffff00; - private final static int COLOR_STATEMENT = 0xff6396fc; - private final static int COLOR_KEYWORD = 0xffffff00; - private final static int COLOR_LIBRARY = 0xffffff00; - private final static int COLOR_FILEHANDLE = 0xffffff00; - private final static int COLOR_CONSTANT = 0xffff00ff; - private final static int COLOR_EXTFILE = 0xff00ff00; - private final static int COLOR_NUMBER = 0xffff0000; - private final static int COLOR_STRING = 0xffff0000; - private final static int COLOR_COMMENT = 0xff009000; - private final static int COLOR_SYMBOL = 0xffcc009c; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?md)--[^\\[\\[].*$|(?s)--\\[\\[.*\\]\\]" - , COMMENT - ), - new HighLightRule( - "(?s)\"(\\\\.|[^\\\\\"])*\"|" + - "'([^'\\\\]|(\\\\[\\\\\"'abfnrtv\\\\]))'|'\\\\[0-3]?[0-7]{1,2}'|'\\\\x[0-9A-Fa-f]{1,2}'" - , STRING), - new HighLightRule( - ":|\\*\\*|\\*|/|%|\\+|-|\\^|>|>=|<|<=|~=|=|\\.\\.|\\b(not|and|or)\\b" - , OPERATOR), - new HighLightRule( - "\\(|\\)|\\[|\\]|\\{|\\}" - , SYMBOL), - new HighLightRule( - "\\b(do|end|while|repeat|until|if|elseif|then|else|for|in|function|local|return)\\b" - , STATEMENT), - new HighLightRule( - "io\\.\\b(close|flush|input|lines|open|output|popen|read|tmpfile|type|write)\\b|" + - "math\\.\\b(abs|acos|asin|atan2|atan|ceil|cosh|cos|deg|exp|floor|fmod|frexp|huge|ldexp|log10|log|max|min|modf|pi|pow|rad|random|randomseed|sinh|tan)\\b|" + - "os\\.\\b(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)\\b|" + - "package\\.\\b(cpath|loaded|loadlib|path|preload|seeall)\\b|" + - "string\\.\\b(byte|char|dump|find|format|gmatch|gsub|len|lower|match|rep|reverse|sub|upper)\\b|" + - "table\\.\\b(concat|insert|maxn|remove|sort)\\b|" + - "coroutine\\.\\b(create|resume|running|status|wrap|yield)\\b|" + - "debug\\.\\b(debug|getfenv|gethook|getinfo|getlocal|getmetatable|getregistry|getupvalue|setfenv|sethook|setlocal|setmetatable|setupvalue|traceback)\\b" - , LIBRARY), - new HighLightRule( - "\\b(debug|string|math|table|io|coroutine|os)\\b\\.|" + - "\\b(_G|_VERSION|assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|load|loadfile|module|next|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)\\b" - , KEYWORD), - new HighLightRule( - "\\:\\b(close|flush|lines|read|seek|setvbuf|write)\\b" - , FILEHANDLE), - new HighLightRule( - "\\b(false|nil|true)\\b" - , CONSTANT), - new HighLightRule( - "\\b(dofile|require|include)\\b" - , EXTFILE), - new HighLightRule( - "[0-9]+" - , NUMBER), - }; - - public LuaSyntax() { - setRules(mRules); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - switch (color_id) { - case UNKNOWN: - return COLOR_UNKNOWN; - case OPERATOR: - return COLOR_OPERATOR; - case STATEMENT: - return COLOR_STATEMENT; - case KEYWORD: - return COLOR_KEYWORD; - case LIBRARY: - return COLOR_LIBRARY; - case FILEHANDLE: - return COLOR_FILEHANDLE; - case CONSTANT: - return COLOR_CONSTANT; - case EXTFILE: - return COLOR_EXTFILE; - case NUMBER: - return COLOR_NUMBER; - case STRING: - return COLOR_STRING; - case COMMENT: - return COLOR_COMMENT; - case SYMBOL: - return COLOR_SYMBOL; - } - return COLOR_WHITE; - } -} diff --git a/app/src/main/java/com/pdaxrom/editor/MakeSyntax.java b/app/src/main/java/com/pdaxrom/editor/MakeSyntax.java deleted file mode 100644 index 46eaff40..00000000 --- a/app/src/main/java/com/pdaxrom/editor/MakeSyntax.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class MakeSyntax extends SyntaxHighLighting { - private final static int UNKNOWN = 0; - private final static int KEYWORD = 1; - private final static int VARIABLE = 2; - private final static int PREPROCESSOR = 3; - private final static int DATA = 4; - private final static int COMMENT = 5; - private final static int COLONEQU = 6; - private final static int TARGET = 7; - - private final static int COLOR_UNKNOWN = 0xff000000; - private final static int COLOR_COMMENT = 0xff2500ff; - private final static int COLOR_PREPROCESSOR = 0xffa52a2a; - private final static int COLOR_VARIABLE = 0xff2e8b57; - private final static int COLOR_TARGET = 0xff00a7da; - - private final static int COLOR_KEYWORD = 0xffa020f0; - private final static int COLOR_DATA = 0xffff00ff; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?md)#.*$" - , COMMENT), - new HighLightRule( - "\\b(if|ifeq|else|endif)\\b" - , PREPROCESSOR), - new HighLightRule( - ":=" - , COLONEQU), - new HighLightRule( - "(?m)^.*:[^=]" - , TARGET), - new HighLightRule( - "\\$\\(.*?\\)" - , VARIABLE), - new HighLightRule( - "\\b(cat|cd|chmod|chown|cp|echo|env|export|grep|install|let|ln|make|mkdir|mv|rm|sed|set|tar|touch|umask|unset)\\b" - , PREPROCESSOR), - }; - - public MakeSyntax() { - setRules(mRules); - } - - public void exec(Editable text) { - super.exec(text); - // Replace two spaces from begin line to two tabs - Matcher m = Pattern.compile("(?m)^ ").matcher(text); - while (m.find()) - text.replace(m.start(), m.end(), "\t\t"); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - switch (color_id) { - case VARIABLE: - return COLOR_VARIABLE; - case KEYWORD: - return COLOR_KEYWORD; - case PREPROCESSOR: - return COLOR_PREPROCESSOR; - case DATA: - return COLOR_DATA; - case COMMENT: - return COLOR_COMMENT; - case COLONEQU: - return COLOR_RED; - case TARGET: - return COLOR_TARGET; - case UNKNOWN: - return COLOR_UNKNOWN; - } - return COLOR_BLACK; - } -} diff --git a/app/src/main/java/com/pdaxrom/editor/PerlSyntax.java b/app/src/main/java/com/pdaxrom/editor/PerlSyntax.java deleted file mode 100644 index 1f62e4a4..00000000 --- a/app/src/main/java/com/pdaxrom/editor/PerlSyntax.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; - -public class PerlSyntax extends SyntaxHighLighting { - private final static int QUOTE = 1; - private final static int COMMENT = 2; - private final static int COMMAND = 3; - private final static int CONDITION = 4; - private final static int FILECONDITION = 5; - private final static int VARIABLE = 6; - private final static int CTRLCHARS = 7; - private final static int EXTCOMMAND = 8; - private final static int FUNCTION = 9; - private final static int HEADER = 10; - - private final static int COLOR_QUOTE = 0xffff00ff; - private final static int COLOR_COMMENT = 0xff2500ff; - private final static int COLOR_COMMAND = 0xffa52a2a; - private final static int COLOR_CONDITION = 0xff3a8d9b; - private final static int COLOR_FILECONDITION = 0xffec0709; - private final static int COLOR_VARIABLE = 0xff2e8b57; - private final static int COLOR_CTRLCHARS = 0xfff5ff0b; - private final static int COLOR_EXTCOMMAND = 0xffa52a2a; - private final static int COLOR_FUNCTION = 0xff04cf23; - private final static int COLOR_HEADER = 0xff6500ff; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?-md)^#!.*/p[lm]$" - , HEADER), - new HighLightRule( - "(?md)#.*$" - , COMMENT), - new HighLightRule( - "\"(\\\\.|[^\\\\\"])*\"" - , QUOTE), - new HighLightRule( - "(?md)^[0-9A-Za-z_]+\\(\\)" - , FUNCTION), - new HighLightRule( - "\\b(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\\b" - , COMMAND), - new HighLightRule( - "\\$[0-9A-Za-z_?-]+?" - , VARIABLE), - new HighLightRule( - "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" - , CTRLCHARS), - new HighLightRule( - "-(eq|ne|gt|lt|ge|le|s|n|z)" - , CONDITION), - new HighLightRule( - "-[Ldefgruwx]" - , FILECONDITION), - new HighLightRule( - "\\b(accept|alarm|atan2|bin(d|mode)|c(aller|h(dir|mod|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork)|get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join)\\b" - , EXTCOMMAND), - }; - - public PerlSyntax() { - setRules(mRules); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - switch (color_id) { - case QUOTE: - return COLOR_QUOTE; - case COMMENT: - return COLOR_COMMENT; - case COMMAND: - return COLOR_COMMAND; - case CONDITION: - return COLOR_CONDITION; - case FILECONDITION: - return COLOR_FILECONDITION; - case VARIABLE: - return COLOR_VARIABLE; - case CTRLCHARS: - return COLOR_CTRLCHARS; - case EXTCOMMAND: - return COLOR_EXTCOMMAND; - case FUNCTION: - return COLOR_FUNCTION; - case HEADER: - return COLOR_HEADER; - } - return COLOR_BLACK; - } -} diff --git a/app/src/main/java/com/pdaxrom/editor/ShellSyntax.java b/app/src/main/java/com/pdaxrom/editor/ShellSyntax.java deleted file mode 100644 index 3d1c2830..00000000 --- a/app/src/main/java/com/pdaxrom/editor/ShellSyntax.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.pdaxrom.editor; - -import android.text.Editable; - -import java.util.regex.Matcher; - -public class ShellSyntax extends SyntaxHighLighting { - private final static int QUOTE = 1; - private final static int COMMENT = 2; - private final static int COMMAND = 3; - private final static int CONDITION = 4; - private final static int FILECONDITION = 5; - private final static int VARIABLE = 6; - private final static int CTRLCHARS = 7; - private final static int EXTCOMMAND = 8; - private final static int FUNCTION = 9; - private final static int HEADER = 10; - - private final static int COLOR_QUOTE = 0xffff00ff; - private final static int COLOR_COMMENT = 0xff2500ff; - private final static int COLOR_COMMAND = 0xffa52a2a; - private final static int COLOR_CONDITION = 0xff3a8d9b; - private final static int COLOR_FILECONDITION = 0xffec0709; - private final static int COLOR_VARIABLE = 0xff2e8b57; - private final static int COLOR_CTRLCHARS = 0xfff5ff0b; - private final static int COLOR_EXTCOMMAND = 0xffa52a2a; - private final static int COLOR_FUNCTION = 0xff04cf23; - private final static int COLOR_HEADER = 0xff6500ff; - - private HighLightRule[] mRules = { - new HighLightRule( - "(?-md)^#!.*/(ba|k|pdk)?sh[-0-9_]*" - , HEADER), - new HighLightRule( - "(?md)#.*$" - , COMMENT), - new HighLightRule( - "\"(\\\\.|[^\\\\\"])*\"" - , QUOTE), - new HighLightRule( - "(?md)^[0-9A-Za-z_]+\\(\\)" - , FUNCTION), - new HighLightRule( - "\\b(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\\b" - , COMMAND), - new HighLightRule( - "\\$\\{?[0-9A-Za-z_!@#$*?-]+\\}?" - , VARIABLE), - new HighLightRule( - "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)" - , CTRLCHARS), - new HighLightRule( - "-(eq|ne|gt|lt|ge|le|s|n|z)" - , CONDITION), - new HighLightRule( - "-[Ldefgruwx]" - , FILECONDITION), - new HighLightRule( - "\\b(cat|cd|chmod|chown|cp|echo|env|export|false|grep|install|let|ln|ls|make|mkdir|mv|rm|sed|set|tar|touch|true|umask|unset)\\b" - , EXTCOMMAND), - }; - - public ShellSyntax() { - setRules(mRules); - } - - protected int getColorFor(Editable text, Matcher m, int color_id) { - switch (color_id) { - case QUOTE: - return COLOR_QUOTE; - case COMMENT: - return COLOR_COMMENT; - case COMMAND: - return COLOR_COMMAND; - case CONDITION: - return COLOR_CONDITION; - case FILECONDITION: - return COLOR_FILECONDITION; - case VARIABLE: - return COLOR_VARIABLE; - case CTRLCHARS: - return COLOR_CTRLCHARS; - case EXTCOMMAND: - return COLOR_EXTCOMMAND; - case FUNCTION: - return COLOR_FUNCTION; - case HEADER: - return COLOR_HEADER; - } - return COLOR_BLACK; - } -}