Mercurial > dwindows
comparison dwtest.c @ 2800:56eab3a84b62
Android: Add Android specific code to handle opening URIs in dwtest.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 17 Jul 2022 10:17:10 +0000 |
parents | b17197a2fb28 |
children | 4521f014bb17 |
comparison
equal
deleted
inserted
replaced
2799:fd7c6ff72383 | 2800:56eab3a84b62 |
---|---|
5 */ | 5 */ |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #ifdef __ANDROID__ | |
11 #include <fcntl.h> | |
12 #include <unistd.h> | |
13 #endif | |
10 #include "dw.h" | 14 #include "dw.h" |
11 /* For snprintf, strdup etc on old Windows SDK */ | 15 /* For snprintf, strdup etc on old Windows SDK */ |
12 #if defined(__WIN32__) || defined(__OS2__) | 16 #if defined(__WIN32__) || defined(__OS2__) |
13 #include "dwcompat.h" | 17 #include "dwcompat.h" |
14 #endif | 18 #endif |
295 } | 299 } |
296 | 300 |
297 char *read_file(char *filename) | 301 char *read_file(char *filename) |
298 { | 302 { |
299 char *errors = NULL; | 303 char *errors = NULL; |
300 | 304 #ifdef __ANDROID__ |
301 fp = fopen(filename, "r"); | 305 int fd = -1; |
306 | |
307 /* Special way to open for URIs on Android */ | |
308 if(strstr(filename, "://")) | |
309 { | |
310 fd = dw_file_open(filename, O_RDONLY); | |
311 fp = fdopen(fd, "r"); | |
312 } | |
313 else | |
314 #endif | |
315 fp = fopen(filename, "r"); | |
302 if(!fp) | 316 if(!fp) |
303 errors = strerror(errno); | 317 errors = strerror(errno); |
304 else | 318 else |
305 { | 319 { |
306 int i,len; | 320 int i,len; |
324 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); | 338 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); |
325 dw_scrollbar_set_pos(hscrollbar, 0); | 339 dw_scrollbar_set_pos(hscrollbar, 0); |
326 dw_scrollbar_set_range(vscrollbar, num_lines, rows); | 340 dw_scrollbar_set_range(vscrollbar, num_lines, rows); |
327 dw_scrollbar_set_pos(vscrollbar, 0); | 341 dw_scrollbar_set_pos(vscrollbar, 0); |
328 } | 342 } |
343 #ifdef __ANDROID__ | |
344 if(fd != -1) | |
345 close(fd); | |
346 #endif | |
329 return errors; | 347 return errors; |
330 } | 348 } |
331 | 349 |
332 /* When hpma is not NULL we are printing.. so handle things differently */ | 350 /* When hpma is not NULL we are printing.. so handle things differently */ |
333 void draw_file(int row, int col, int nrows, int fheight, HPIXMAP hpma) | 351 void draw_file(int row, int col, int nrows, int fheight, HPIXMAP hpma) |