Skip to content

Commit 4d26c00

Browse files
committed
Auto move to log view if diagnostic is empty
1 parent e0ddd95 commit 4d26c00

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/CompileSetting.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ private String getGCCFlags() {
8181

8282
//optimize
8383
String optimize = mPref.getString(mContext.getString(R.string.pref_option_optimization_level), "");
84-
if (!optimize.isEmpty()) builder.addFlags("-O" + optimize);
84+
if (!optimize.isEmpty()) {
85+
if (optimize.matches("(fast)|(g)|(s)|[0123]")) {
86+
builder.addFlags("-O" + optimize);
87+
}
88+
}
8589

8690
//language standard
8791
String std = mPref.getString(mContext.getString(R.string.pref_option_language_standard), "");

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/GCCCompiler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ protected String buildCommand(File[] sourceFiles) {
9898
if (Build.VERSION.SDK_INT >= 21) {
9999
builder.addFlags("-pie");
100100
}
101-
102101
// builder.addFlags("-std=c99");
103102
// builder.addFlags("-lz"/*zlib*/, "-ldl", "-lm" /*math*/, "-llog");
104103
// builder.addFlags("-lncurses");

app/src/main/java/com/duy/ccppcompiler/compiler/shell/Shell.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.FileOutputStream;
2929
import java.io.FileReader;
3030
import java.io.IOException;
31+
import java.util.regex.Matcher;
3132
import java.util.regex.Pattern;
3233

3334

@@ -92,22 +93,22 @@ public void run() {
9293

9394
//parse output
9495
StringBuilder message = new StringBuilder();
95-
int skipLine = 0; //skip echos from two command strings
96+
int skipLine = 6; //skip echos from two command strings
9697
final Pattern patClearNewLine = Pattern.compile("(\\x08)\\1+");
9798
do {
9899
String errstr;
99100
try {
100101
errstr = input.readLine();
101102
// remove escape sequence
102-
// errstr = errstr.replaceAll("\u001b\\[([0-9]|;)*m", "");
103+
errstr = errstr.replaceAll("\u001b\\[([0-9]|;)*m", "");
103104
// remove clearing new line
104-
// Matcher m = patClearNewLine.matcher(errstr);
105-
// if (m.find()) {
106-
// int length = m.end() - m.start();
107-
// if (m.start() > length) {
108-
// errstr = errstr.substring(0, m.start() - length) + errstr.substring(m.end());
109-
// }
110-
// }
105+
Matcher m = patClearNewLine.matcher(errstr);
106+
if (m.find()) {
107+
int length = m.end() - m.start();
108+
if (m.start() > length) {
109+
errstr = errstr.substring(0, m.start() - length) + errstr.substring(m.end());
110+
}
111+
}
111112
} catch (IOException e) {
112113
break;
113114
}

app/src/main/java/com/duy/ccppcompiler/diagnostic/ui/DiagnosticFragment.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.duy.ccppcompiler.diagnostic.DiagnosticClickListener;
3636
import com.duy.ccppcompiler.diagnostic.DiagnosticContract;
3737
import com.duy.ccppcompiler.diagnostic.suggestion.ISuggestion;
38+
import com.duy.common.DLog;
3839

3940
import java.util.ArrayList;
4041
import java.util.List;
@@ -46,10 +47,9 @@
4647
public class DiagnosticFragment extends Fragment implements DiagnosticContract.View, DiagnosticClickListener {
4748
private static final String KEY_LIST_DIAGNOSTIC = "KEY_LIST_DIAGNOSTIC";
4849
private static final String KEY_LOG = "KEY_LOG";
49-
50+
private static final String TAG = "DiagnosticFragment";
5051
private DiagnosticContract.Presenter mPresenter;
5152
private DiagnosticsAdapter mAdapter;
52-
5353
private RecyclerView mDiagnosticView;
5454
private TextView mLogView;
5555
private ViewPager mViewPager;
@@ -107,12 +107,21 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
107107

108108
@Override
109109
public void showDiagnostic(List<Diagnostic> diagnostics) {
110+
if (DLog.DEBUG) {
111+
DLog.d(TAG, "showDiagnostic() called with: diagnostics = [" + diagnostics + "]");
112+
}
110113
mAdapter.setData(diagnostics);
114+
if (!diagnostics.isEmpty()) {
115+
mViewPager.setCurrentItem(0);
116+
}
111117
}
112118

113119
@Override
114120
public void showLog(CharSequence log) {
115121
mLogView.setText(log);
122+
if (mAdapter.getDiagnostics().isEmpty()) {
123+
mViewPager.setCurrentItem(1);
124+
}
116125
}
117126

118127
@Override

app/src/main/java/com/duy/ccppcompiler/filemanager/install/InstallActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import android.widget.TextView;
3535

3636
import com.duy.ccppcompiler.R;
37-
import com.duy.ccppcompiler.compiler.CompileSetting;
3837
import com.duy.ccppcompiler.compiler.compilers.GCCCompiler;
3938
import com.duy.ccppcompiler.compiler.compilers.GPlusPlusCompiler;
4039
import com.duy.ccppcompiler.compiler.shell.GccCommandResult;
@@ -193,7 +192,7 @@ protected Boolean doInBackground(Void... voids) {
193192
IOUtils.write(/*"#include <stdio.h>\n" +*/ "int main(){ return 0; }", output);
194193
output.close();
195194

196-
GCCCompiler compiler = new GCCCompiler(context, new CompileSetting(context));
195+
GCCCompiler compiler = new GCCCompiler(context, null);
197196
GccCommandResult result = compiler.compile(new File[]{file});
198197
if (result == null || result.getResultCode() != 0) {
199198
publishProgress("Could not exec C compiler, please install compiler");
@@ -205,7 +204,7 @@ protected Boolean doInBackground(Void... voids) {
205204
output = new FileOutputStream(file);
206205
IOUtils.write(/*"#include <iostream>\n" + "using namespace std;\n" +*/ "int main() { return 0; }", output);
207206
output.close();
208-
compiler = new GPlusPlusCompiler(context, new CompileSetting(context));
207+
compiler = new GPlusPlusCompiler(context, null);
209208
result = compiler.compile(new File[]{file});
210209
if (result == null || result.getResultCode() != 0) {
211210
publishProgress("Could not exec C++ compiler, please install compiler");

0 commit comments

Comments
 (0)