Skip to content
Merged

12 25 #172

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions src/common/blib_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count,
var_num_t *xvals, int xcount, int chart, int marks) {
var_num_t lx, ly;
char buf[32];
int32_t color = 0;
int32_t color = dev_fgcolor;
int rx1 = x1;

// ready
Expand Down Expand Up @@ -1052,6 +1052,7 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count,
case 5:
// line chart
// points
dev_settextcolor(color, 15);
if (chart == 5) {
for (int i = 0; i < count; i++) {
dev_setpixel(pts[i * 2], pts[i * 2 + 1]);
Expand All @@ -1061,6 +1062,7 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count,
dev_line(pts[(i - 1) * 2], pts[(i - 1) * 2 + 1], pts[i * 2], pts[i * 2 + 1]);
}
}
dev_settextcolor(0, 15);

// draw marks
if (marks & 0x1) {
Expand Down Expand Up @@ -1094,19 +1096,12 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count,
// draw rect
color = 0;
for (int i = 1; i < count; i++) {
if (os_color_depth > 2) {
dev_setcolor(color);
color++;
if (color >= 15) {
color = 0;
}
}
dev_setcolor(color);
color = (color + 1) % 16;
dev_rect(pts[(i - 1) * 2], pts[(i - 1) * 2 + 1], pts[i * 2] - 2, y2, 1);
}

if (os_color_depth > 2) {
dev_setcolor(color);
}
dev_setcolor(color);
dev_rect(pts[(count - 1) * 2], pts[(count - 1) * 2 + 1],
pts[(count - 1) * 2] + lx - 1, y2, 1);

Expand All @@ -1121,23 +1116,18 @@ void chart_draw(int x1, int y1, int x2, int y2, var_num_t *vals, int count,
int mx = pts[i * 2] + lx / 2 - fw / 2;
int my = pts[i * 2 + 1];

if (os_color_depth > 2) {
if (my - fh >= y1) {
dev_settextcolor(0, 15);
if (my - fh >= y1) {
dev_settextcolor(0, 15);
} else {
if (color >= 7 && color != 8) {
dev_settextcolor(0, color);
} else {
if (color >= 7 && color != 8) {
dev_settextcolor(0, color);
} else {
dev_settextcolor(15, color);
}
}

color++;
if (color >= 15) {
color = 0;
dev_settextcolor(15, color);
}
}

color = (color + 1) % 16;

if (my - fh >= y1) {
my -= fh;
}
Expand Down
4 changes: 0 additions & 4 deletions src/common/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ void g_line(int x1, int y1, int x2, int y2, void (*dotproc) (int, int));
*
* @code
* byte os_charset; // System's charset (see os_charset_codes)
* uint32_t os_color_depth; // The number of bits of the supported colors
* // (i.e.: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)
* byte os_graphics; // Non-zero if the driver supports graphics
* int os_graf_mx; // Graphic mode: screen width
* int os_graf_my; // Graphic mode: screen height
Expand Down Expand Up @@ -128,8 +126,6 @@ enum os_charset_codes {
extern byte os_charset;

extern byte os_color; // true if the output has real colors (256+ colors)
extern uint32_t os_color_depth; // the number of bits of the supported colors
// (ex: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)
extern byte os_graphics; // non-zero if the driver supports graphics
extern int os_graf_mx; // graphic mode: maximum x
extern int os_graf_my; // graphic mode: maximum y
Expand Down
1 change: 0 additions & 1 deletion src/common/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
c |= ((y > dev_Vy2) << 3); }
#define CLIPIN(c) ((c & 0xF) == 0)

uint32_t os_color_depth = 16;
byte os_graphics = 0; // CONSOLE
int os_graf_mx = 80;
int os_graf_my = 25;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
applicationId 'net.sourceforge.smallbasic'
minSdkVersion 16
targetSdkVersion 33
versionCode 54
versionCode 55
versionName '12.25'
resConfigs 'en'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -103,6 +104,7 @@ public class MainActivity extends NativeActivity {
private final ExecutorService _audioExecutor = Executors.newSingleThreadExecutor();
private final Queue<Sound> _sounds = new ConcurrentLinkedQueue<>();
private final Handler _keypadHandler = new Handler(Looper.getMainLooper());
private final Map<String, Boolean> permittedHost = new ConcurrentHashMap<>();
private String[] _options = null;
private MediaPlayer _mediaPlayer = null;
private LocationAdapter _locationAdapter = null;
Expand Down Expand Up @@ -149,13 +151,13 @@ public int ask(final byte[] titleBytes, final byte[] promptBytes, final boolean
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(title).setMessage(prompt);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
builder.setPositiveButton(R.string.YES, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.setYes();
mutex.release();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
builder.setNegativeButton(R.string.NO, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.setNo();
mutex.release();
Expand All @@ -169,7 +171,7 @@ public void onCancel(DialogInterface dialog) {
}
});
if (cancel) {
builder.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
builder.setNeutralButton(R.string.CANCEL, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.setCancel();
mutex.release();
Expand Down Expand Up @@ -501,8 +503,7 @@ public void setClipboardText(final byte[] textBytes) {
final String text = new String(textBytes, CP1252);
runOnUiThread(new Runnable() {
public void run() {
ClipboardManager clipboard =
(ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newPlainText("text", text);
clipboard.setPrimaryClip(clip);
Expand Down Expand Up @@ -577,8 +578,9 @@ public void showAlert(final byte[] titleBytes, final byte[] messageBytes) {
runOnUiThread(new Runnable() {
public void run() {
new AlertDialog.Builder(activity)
.setTitle(title).setMessage(message)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
.setTitle(title)
.setMessage(message)
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}
}).show();
}
Expand Down Expand Up @@ -771,6 +773,14 @@ private void installSamples() {
}
}

private boolean isHostDenied(String remoteHost) {
return (remoteHost != null && permittedHost.get(remoteHost) != null && Boolean.FALSE.equals(permittedHost.get(remoteHost)));
}

private boolean isHostNotPermitted(String remoteHost) {
return (remoteHost == null || permittedHost.get(remoteHost) == null || !Boolean.TRUE.equals(permittedHost.get(remoteHost)));
}

private boolean locationPermitted() {
String permission = Manifest.permission.ACCESS_FINE_LOCATION;
return (ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED);
Expand All @@ -797,11 +807,11 @@ private void processSettings() {
is = getApplication().openFileInput("settings.txt");
Properties p = new Properties();
p.load(is);
int socket = Integer.parseInt(p.getProperty("serverSocket", "-1"));
int port = Integer.parseInt(p.getProperty("serverSocket", "-1"));
String token = p.getProperty("serverToken", new Date().toString());
if (socket > 1023 && socket < 65536) {
if (port > 1023 && port < 65536) {
WebServer webServer = new WebServerImpl();
webServer.run(socket, token);
webServer.run(port, token);
} else {
Log.i(TAG, "Web service disabled");
}
Expand Down Expand Up @@ -848,6 +858,27 @@ private String readLine(InputStream inputReader) throws IOException {
return b == -1 ? null : out.size() == 0 ? "" : out.toString();
}

private void requestHostPermission(String remoteHost) {
final Activity activity = this;
runOnUiThread(new Runnable() {
public void run() {
new AlertDialog.Builder(activity)
.setTitle(R.string.PORTAL_PROMPT)
.setMessage(getString(R.string.PORTAL_QUESTION, remoteHost))
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
permittedHost.put(remoteHost, Boolean.TRUE);
}
})
.setNegativeButton(R.string.CANCEL, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
permittedHost.put(remoteHost, Boolean.FALSE);
}
}).show();
}
});
}

private String saveSchemeData(final String buffer) throws IOException {
File outputFile = new File(_storage.getInternal(), SCHEME_BAS);
BufferedWriter output = new BufferedWriter(new FileWriter(outputFile));
Expand All @@ -863,6 +894,12 @@ private void setupStorageEnvironment() {
setenv("LEGACY_DIR", _storage.getMedia());
}

private void validateAccess(String remoteHost) throws IOException {
if (isHostNotPermitted(remoteHost)) {
throw new IOException(getString(R.string.PORTAL_DENIED));
}
}

private static class BasFileFilter implements FilenameFilter {
@Override
public boolean accept(File dir, String name) {
Expand Down Expand Up @@ -944,7 +981,8 @@ protected byte[] decodeBase64(String data) {
}

@Override
protected void deleteFile(String fileName) throws IOException {
protected void deleteFile(String remoteHost, String fileName) throws IOException {
validateAccess(remoteHost);
if (fileName == null) {
throw new IOException("Empty file name");
}
Expand All @@ -958,19 +996,30 @@ protected void deleteFile(String fileName) throws IOException {
}

@Override
protected void execStream(InputStream inputStream) throws IOException {
MainActivity.this.execStream(inputStream);
protected void execStream(String remoteHost, InputStream inputStream) throws IOException {
if (isHostDenied(remoteHost)) {
throw new IOException(getString(R.string.PORTAL_DENIED));
}
if (isHostNotPermitted(remoteHost)) {
requestHostPermission(remoteHost);
} else {
MainActivity.this.execStream(inputStream);
}
}

@Override
protected Response getFile(String path, boolean asset) throws IOException {
protected Response getFile(String remoteHost, String path, boolean asset) throws IOException {
Response result;
if (asset) {
String name = "webui/" + path;
long length = getFileLength(name);
log("Opened " + name + " " + length + " bytes");
result = new Response(getAssets().open(name), length);
if ("index.html".equals(path) && isHostNotPermitted(remoteHost)) {
requestHostPermission(remoteHost);
}
} else {
validateAccess(remoteHost);
File file = getFile(path);
if (file != null) {
result = new Response(new FileInputStream(file), file.length());
Expand All @@ -982,7 +1031,8 @@ protected Response getFile(String path, boolean asset) throws IOException {
}

@Override
protected Collection<FileData> getFileData() throws IOException {
protected Collection<FileData> getFileData(String remoteHost) throws IOException {
validateAccess(remoteHost);
Collection<FileData> result = new ArrayList<>();
result.addAll(getFiles(new File(_storage.getExternal())));
result.addAll(getFiles(new File(_storage.getMedia())));
Expand All @@ -1001,7 +1051,8 @@ protected void log(String message) {
}

@Override
protected void renameFile(String from, String to) throws IOException {
protected void renameFile(String remoteHost, String from, String to) throws IOException {
validateAccess(remoteHost);
if (to == null) {
throw new IOException("Empty file name");
}
Expand All @@ -1019,7 +1070,8 @@ protected void renameFile(String from, String to) throws IOException {
}

@Override
protected void saveFile(String fileName, byte[] content) throws IOException {
protected void saveFile(String remoteHost, String fileName, byte[] content) throws IOException {
validateAccess(remoteHost);
File file = new File(_storage.getExternal(), fileName);
if (file.exists()) {
throw new IOException("File already exists: " + fileName);
Expand Down
Loading