29#include <unixlib/local.h>
30#include <fpu_control.h>
31#include <oslib/help.h>
33#include <oslib/inetsuite.h>
34#include <oslib/pdriver.h>
35#include <oslib/osfile.h>
36#include <oslib/hourglass.h>
37#include <oslib/osgbpb.h>
38#include <oslib/osbyte.h>
39#include <oslib/osmodule.h>
40#include <oslib/osfscontrol.h>
106 __RISCOSIFY_NO_REVERSE_SUFFIX;
114#define CHOICES_PREFIX "<Choices$Write>.WWW.NetSurf."
127 message_HELP_REQUEST,
130 message_DATA_SAVE_ACK,
132 message_DATA_LOAD_ACK,
135 message_SAVE_DESKTOP,
136 message_MENU_WARNING,
137 message_MENUS_DELETED,
139 message_CLAIM_ENTITY,
140 message_DATA_REQUEST,
144 message_PALETTE_CHANGE,
145 message_FONT_CHANGED,
147 message_URI_RETURN_RESULT,
148 message_INET_SUITE_OPEN_URL,
151 message_PRINT_TYPE_ODD,
179 static const char base_url[] =
"file:///NetSurf:/Resources/";
181 size_t path_len, length;
186 if (strcmp(
path,
"adblock.css") == 0) {
189 }
else if (strcmp(
path,
"default.css") == 0) {
192 }
else if (strcmp(
path,
"quirks.css") == 0) {
195 }
else if (strcmp(
path,
"favicon.ico") == 0) {
196 path =
"Icons/content.png";
198 }
else if (strcmp(
path,
"user.css") == 0) {
204 path_len = strlen(
path);
209 length =
SLEN(base_url) +
213 raw = malloc(length);
216 char *ptr = memcpy(raw, base_url,
SLEN(base_url));
217 ptr +=
SLEN(base_url);
221 if (path_len >
SLEN(
".html") &&
222 strncmp(
path + path_len -
SLEN(
".html"),
223 ".html",
SLEN(
".html")) == 0) {
224 ptr += sprintf(ptr,
"%s/", lang);
228 memcpy(ptr,
path, path_len);
258 os_PALETTE(20) palette;
260 error = xwimp_read_true_palette((os_palette *) &palette);
263 "xwimp_read_palette: 0x%x: %s",
268 def_colour = palette.entries[wimp] >> 8;
271 opts[option].
value.
c = def_colour;
290 static const struct {
294 } sys_colour_map[]= {
295 { NSOPTION_sys_colour_AccentColor, wimp_COLOUR_CREAM, 0x00dddddd },
296 { NSOPTION_sys_colour_AccentColorText, wimp_COLOUR_BLACK, 0x00000000 },
297 { NSOPTION_sys_colour_ActiveText, wimp_COLOUR_BLACK, 0x00000000 },
298 { NSOPTION_sys_colour_ButtonBorder, wimp_COLOUR_VERY_LIGHT_GREY,0x00aa0000 },
299 { NSOPTION_sys_colour_ButtonFace, wimp_COLOUR_VERY_LIGHT_GREY, 0x00aaaaaa },
300 { NSOPTION_sys_colour_ButtonText, wimp_COLOUR_BLACK, 0x00000000 },
301 { NSOPTION_sys_colour_Canvas, wimp_COLOUR_VERY_LIGHT_GREY, 0x00aaaaaa },
302 { NSOPTION_sys_colour_CanvasText, wimp_COLOUR_BLACK, 0x00000000 },
303 { NSOPTION_sys_colour_Field, wimp_COLOUR_WHITE, 0x00ffffff },
304 { NSOPTION_sys_colour_FieldText, wimp_COLOUR_BLACK, 0x00000000 },
305 { NSOPTION_sys_colour_GrayText, wimp_COLOUR_MID_LIGHT_GREY, 0x00777777 },
306 { NSOPTION_sys_colour_Highlight, wimp_COLOUR_BLACK, 0x00ee0000 },
307 { NSOPTION_sys_colour_HighlightText, wimp_COLOUR_WHITE, 0x00ffffff },
308 { NSOPTION_sys_colour_LinkText, wimp_COLOUR_BLACK, 0x00ee0000 },
309 { NSOPTION_sys_colour_Mark, wimp_COLOUR_VERY_LIGHT_GREY,0x00eeeeee },
310 { NSOPTION_sys_colour_MarkText, wimp_COLOUR_BLACK, 0x00000000},
311 { NSOPTION_sys_colour_SelectedItem, wimp_COLOUR_MID_LIGHT_GREY, 0x00777777 },
312 { NSOPTION_sys_colour_SelectedItemText, wimp_COLOUR_BLACK, 0x00000000 },
313 { NSOPTION_sys_colour_VisitedText, wimp_COLOUR_BLACK, 0x00000000 },
325 NSLOG(netsurf, INFO,
"Failed initialising default options");
343 sys_colour_map[idx].wcol,
344 sys_colour_map[idx].option,
345 sys_colour_map[idx].c);
363 path = getenv(
"NetSurf$ChoicesSave");
365 die(
"Failed to find NetSurf Choices save path");
367 snprintf(buf,
sizeof(buf),
"%s",
path);
386 xosfile_create_dir(buf, 0);
398 xos_cli(
"FontRemove NetSurf:Resources.Fonts.");
407 static const os_error error = { 1,
"NetSurf has detected a serious "
408 "error and must exit. Please submit a bug report, "
409 "attaching the browser log file." };
410 os_colour old_sand, old_glass;
415 xhourglass_colours(0x0000ffff, 0x000000ff, &old_sand, &old_glass);
422 xos_read_var_val_size(
"NetSurf$CoreDump", 0, 0, &used, 0, 0);
425 xwimp_slot_size(-1, -1, &curr_slot, 0, 0);
426 NSLOG(netsurf, INFO,
"saving WimpSlot, size 0x%x", curr_slot);
427 xosfile_save(
"$.NetSurf_Slot", 0x8000, 0,
429 (
byte *) 0x8000 + curr_slot);
435 &base_address, 0, 0, 0, 0, 0);
437 "saving DA %i, base %p, size 0x%x",
441 xosfile_save(
"$.NetSurf_DA",
442 (bits) base_address, 0,
444 base_address + size);
450 const _kernel_oserror *err = __unixlib_write_coredump (NULL);
452 NSLOG(netsurf, INFO,
"Coredump failed: %s", err->errmess);
455 xhourglass_colours(old_sand, old_glass, 0, 0);
458 __write_backtrace(sig);
460 xwimp_report_error_by_category(&error,
461 wimp_ERROR_BOX_GIVEN_CATEGORY |
462 wimp_ERROR_BOX_CATEGORY_ERROR <<
463 wimp_ERROR_BOX_CATEGORY_SHIFT,
464 "NetSurf",
"!netsurf",
465 (osspriteop_area *) 1,
"Quit", 0);
466 xos_cli(
"Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.Log");
490 do { c = getc(fp); }
while (c != EOF && 32 <= c);
493 do { c = getc(fp); }
while (c != EOF && c < 32);
504 }
while (c != EOF && 32 <= c);
507 while (c != EOF && c < 32)
534 fp = fopen(file_name,
"rb");
536 NSLOG(netsurf, INFO,
"fopen(\"%s\", \"rb\"): %i: %s",
537 file_name, errno, strerror(errno));
544 goto uri_syntax_error;
548 strspn(
line,
"0123456789") != strlen(
line))
549 goto uri_syntax_error;
553 goto uri_syntax_error;
565 if (uri_title &&
line[0] && ((
line[0] !=
'*') ||
line[1])) {
566 *uri_title = strdup(
line);
596 fp = fopen(file_name,
"r");
598 NSLOG(netsurf, INFO,
"fopen(\"%s\", \"r\"): %i: %s",
599 file_name, errno, strerror(errno));
604 if (!fgets(
line,
sizeof line, fp)) {
606 NSLOG(netsurf, INFO,
"fgets: %i: %s", errno,
642 fp = fopen(file_name,
"r");
644 NSLOG(netsurf, INFO,
"fopen(\"%s\", \"r\"): %i: %s",
645 file_name, errno, strerror(errno));
650 while (fgets(
line,
sizeof line, fp)) {
651 if (strncmp(
line,
"URL=", 4) == 0) {
654 url = strdup(
line + 4);
664 NSLOG(netsurf, INFO,
"fgets: %i: %s", errno, strerror(errno));
686 int file_type = message->data.data_xfer.file_type;
707 data.data_xfer.file_name);
713 len = strlen(message->data.data_xfer.file_name);
714 if (len < 9 || strcmp(
".!NetSurf",
715 message->data.data_xfer.file_name + len - 9))
732 message->action = message_DATA_LOAD_ACK;
733 message->your_ref = message->my_ref;
734 oserror = xwimp_send_message(wimp_USER_MESSAGE, message, message->sender);
736 NSLOG(netsurf, INFO,
"xwimp_send_message: 0x%x: %s",
737 oserror->errnum, oserror->errmess);
765 int file_type = message->data.data_xfer.file_type;
811 case osfile_TYPE_DRAW:
814 case osfile_TYPE_SPRITE:
815 case osfile_TYPE_TEXT:
856 message->action = message_DATA_LOAD_ACK;
857 message->your_ref = message->my_ref;
858 oserror = xwimp_send_message(wimp_USER_MESSAGE, message,
861 NSLOG(netsurf, INFO,
"xwimp_send_message: 0x%x: %s",
862 oserror->errnum, oserror->errmess);
878 const char *ep = (
char*)message + message->size;
879 char *p = message->file_name;
881 if ((
size_t)message->size >=
sizeof(*message))
882 ep = (
char*)message +
sizeof(*message) - 1;
884 while (p < ep && *p >=
' ') p++;
894 wimp_full_message_data_xfer *dataxfer = (wimp_full_message_data_xfer*)message;
904 switch (dataxfer->file_type) {
915 case osfile_TYPE_DRAW:
918 case osfile_TYPE_SPRITE:
919 case osfile_TYPE_TEXT:
925 dataxfer->your_ref = dataxfer->my_ref;
926 dataxfer->size = offsetof(wimp_full_message_data_xfer, file_name) + 16;
927 dataxfer->action = message_DATA_SAVE_ACK;
928 dataxfer->est_size = -1;
929 memcpy(dataxfer->file_name,
"<Wimp$Scrap>", 13);
931 error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)dataxfer, message->sender);
934 "xwimp_send_message: 0x%x: %s",
984 message->your_ref = message->my_ref;
985 error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE,
986 message, message->sender);
988 NSLOG(netsurf, INFO,
"xwimp_send_message: 0x%x:%s",
989 error->errnum, error->errmess);
1005 error = xosgbpb_writew(message->data.save_desktopw.file,
1006 (
const byte*)
"Run ", 4, NULL);
1008 error = xosgbpb_writew(message->data.save_desktopw.file,
1011 error = xos_bputw(
'\n', message->data.save_desktopw.file);
1015 NSLOG(netsurf, INFO,
"xosgbpb_writew/xos_bputw: 0x%x:%s",
1016 error->errnum, error->errmess);
1020 message->your_ref = message->my_ref;
1021 error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE,
1022 message, message->sender);
1024 NSLOG(netsurf, INFO,
"xwimp_send_message: 0x%x:%s",
1025 error->errnum, error->errmess);
1039 wimp_full_message_window_info *wi;
1046 wi = (wimp_full_message_window_info*)message;
1063 os_MODEVAR_XWIND_LIMIT,
1065 os_MODEVAR_YWIND_LIMIT,
1066 os_MODEVAR_XEIG_FACTOR,
1067 os_MODEVAR_YEIG_FACTOR,
1076 NSLOG(netsurf, INFO,
"xos_read_vdu_variables: 0x%x: %s",
1077 error->errnum, error->errmess);
1092 resolvers = getenv(
"Inet$Resolvers");
1093 if (resolvers && resolvers[0]) {
1094 NSLOG(netsurf, INFO,
"Inet$Resolvers '%s'", resolvers);
1096 NSLOG(netsurf, INFO,
"Inet$Resolvers not set or empty");
1114 os_MODEVAR_MODE_FLAGS, &var_val, &psr);
1116 NSLOG(netsurf, ERROR,
"xos_read_mode_variable: 0x%x: %s",
1117 error->errnum, error->errmess);
1121 return (var_val == (1 << 15));
1133 void (*sigabrt)(int);
1134 void (*sigfpe)(int);
1135 void (*sigill)(int);
1136 void (*sigint)(int);
1137 void (*sigsegv)(int);
1138 void (*sigterm)(int);
1139 void (*sigoserror)(int);
1156 _FPU_SETCW(_FPU_IEEE & ~(_FPU_MASK_PM | _FPU_MASK_UM));
1158 xhourglass_start(1);
1163 xos_byte(osbyte_IN_KEY, 0, 0xff, &
os_version, NULL);
1166 NSLOG(netsurf, INFO,
"OS supports alpha sprites: %s",
1171 if (!xosmodule_lookup(
"VideoHWSMI", NULL, NULL, &
base, NULL, NULL)) {
1173 const char *help = (
char*)
base + ((
int*)
base)[5];
1174 while (*help > 9) help++;
1175 while (*help == 9) help++;
1176 if (!memcmp(help,
"0.55", 4))
1194 if (prev_sigs.sigabrt == SIG_ERR || prev_sigs.sigfpe == SIG_ERR ||
1195 prev_sigs.sigill == SIG_ERR ||
1196 prev_sigs.sigint == SIG_ERR ||
1197 prev_sigs.sigsegv == SIG_ERR ||
1198 prev_sigs.sigterm == SIG_ERR ||
1199 prev_sigs.sigoserror == SIG_ERR)
1200 die(
"Failed registering signal handlers");
1205 die(
"Unable to load Sprites.");
1208 nsdir_temp = getenv(
"NetSurf$Dir");
1210 die(
"Failed to locate NetSurf directory");
1213 die(
"Failed duplicating NetSurf directory string");
1230 error = xwimp_initialise(wimp_VERSION_RO38,
task_name,
1234 NSLOG(netsurf, INFO,
"xwimp_initialise: 0x%x: %s",
1235 error->errnum, error->errmess);
1236 die(error->errmess);
1272 if (getenv(
"NetSurf$Start_URI_Handler"))
1273 xwimp_start_task(
"Desktop", 0);
1276 if ((length = snprintf(
path,
sizeof(
path),
1277 "NetSurf:Resources.%s.Templates",
1279 die(
"Failed to locate Templates resource.");
1280 error = xwimp_open_template(
path);
1282 NSLOG(netsurf, INFO,
"xwimp_open_template failed: 0x%x: %s",
1283 error->errnum, error->errmess);
1284 die(error->errmess);
1312 wimp_close_template();
1324 NSLOG(netsurf, INFO,
"parameters: '%s'", argv[1]);
1326 if (strcasecmp(argv[1],
"-nowin") == 0) {
1331 else if (argc == 3) {
1332 NSLOG(netsurf, INFO,
"parameters: '%s' '%s'", argv[1],
1337 if (strcasecmp(argv[1],
"-html") == 0) {
1341 else if (strcasecmp(argv[1],
"-urlf") == 0) {
1344 NSLOG(netsurf, INFO,
"allocation failed");
1345 die(
"Insufficient memory for URL");
1351 else if (strcasecmp(argv[1],
"-url") == 0) {
1356 NSLOG(netsurf, INFO,
"Unknown parameters: '%s' '%s'",
1403 error = xosbyte_read(osbyte_VAR_COUNTRY_NUMBER, &country);
1405 NSLOG(netsurf, INFO,
"xosbyte_read failed: 0x%x: %s",
1406 error->errnum, error->errmess);
1426 sprintf(
path,
"NetSurf:Resources.%s", lang);
1446 char *canonical_path;
1455 error = xosfscontrol_canonicalise_path(
path, 0, 0, 0, 0, &spare);
1457 NSLOG(netsurf, INFO,
1458 "xosfscontrol_canonicalise_path failed: 0x%x: %s",
1465 canonical_path = malloc(1 - spare);
1466 if (canonical_path == NULL) {
1467 free(canonical_path);
1471 error = xosfscontrol_canonicalise_path(
path, canonical_path, 0, 0, 1 - spare, 0);
1473 NSLOG(netsurf, INFO,
1474 "xosfscontrol_canonicalise_path failed: 0x%x: %s",
1478 free(canonical_path);
1483 unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0);
1485 if (unix_path == NULL) {
1486 NSLOG(netsurf, INFO,
"__unixify failed: %s", canonical_path);
1487 free(canonical_path);
1490 free(canonical_path);
1493 ret =
url_escape(unix_path,
false,
"/", &escaped_path);
1502 url = malloc(urllen);
1504 NSLOG(netsurf, INFO,
"Unable to allocate url");
1509 if (*escaped_path ==
'/') {
1510 snprintf(url, urllen,
"%s%s",
1513 snprintf(url, urllen,
"%s%s",
1536 lwc_string *urlpath;
1545 if ((url == NULL) || (path_out == NULL)) {
1551 if (lwc_string_caseless_isequal(scheme, corestring_lwc_file,
1552 &match) != lwc_error_ok)
1556 lwc_string_unref(scheme);
1557 if (match ==
false) {
1562 if (urlpath == NULL) {
1567 lwc_string_length(urlpath),
1570 lwc_string_unref(urlpath);
1576 path = malloc(unpath_len + 100);
1582 r = __riscosify(unpath, 0, __RISCOSIFY_NO_SUFFIX,
1583 path, unpath_len + 100, 0);
1650 wimp_key *key = (wimp_key *) pw;
1653 os_error *error = xwimp_process_key(key->c);
1655 NSLOG(netsurf, INFO,
"xwimp_process_key: 0x%x: %s",
1656 error->errnum, error->errmess);
1670 if (key->c == wimp_KEY_ESCAPE &&
1680 }
else if (key->c == 22 ) {
1684 copy = malloc(
sizeof(wimp_key));
1687 memcpy(copy, key,
sizeof(wimp_key));
1691 os_error *error = xwimp_process_key(key->c);
1693 NSLOG(netsurf, INFO,
"xwimp_process_key: 0x%x: %s",
1694 error->errnum, error->errmess);
1710 switch (message->action) {
1711 case message_DATA_LOAD:
1714 if (event == wimp_USER_MESSAGE_ACKNOWLEDGE) {
1718 (wimp_full_message_data_xfer *) message) ==
false) {
1723 case message_DATA_LOAD_ACK:
1728 case message_MENU_WARNING:
1733 case message_MENUS_DELETED:
1738 case message_CLAIM_ENTITY:
1742 case message_DATA_REQUEST:
1746 case message_MODE_CHANGE:
1748 rufl_invalidate_cache();
1751 case message_PALETTE_CHANGE:
1754 case message_FONT_CHANGED:
1758 case message_URI_PROCESS:
1759 if (event != wimp_USER_MESSAGE_ACKNOWLEDGE)
1762 case message_URI_RETURN_RESULT:
1765 case message_INET_SUITE_OPEN_URL:
1766 if (event == wimp_USER_MESSAGE_ACKNOWLEDGE) {
1773 case message_PRINT_SAVE:
1774 if (event == wimp_USER_MESSAGE_ACKNOWLEDGE)
1777 case message_PRINT_ERROR:
1780 case message_PRINT_TYPE_ODD:
1802 case wimp_NULL_REASON_CODE:
1807 case wimp_REDRAW_WINDOW_REQUEST:
1811 case wimp_OPEN_WINDOW_REQUEST:
1815 case wimp_CLOSE_WINDOW_REQUEST:
1819 case wimp_POINTER_LEAVING_WINDOW:
1823 case wimp_POINTER_ENTERING_WINDOW:
1827 case wimp_MOUSE_CLICK:
1831 case wimp_USER_DRAG_BOX:
1835 case wimp_KEY_PRESSED:
1839 case wimp_MENU_SELECTION:
1847 case wimp_SCROLL_REQUEST:
1852 case wimp_USER_MESSAGE:
1853 case wimp_USER_MESSAGE_RECORDED:
1854 case wimp_USER_MESSAGE_ACKNOWLEDGE:
1866 wimp_event_no event;
1868 const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN | wimp_SAVE_FP;
1869 os_t track_poll_offset;
1875 os_t t = os_read_monotonic_time();
1877 if (track_poll_offset > 0) {
1878 t += track_poll_offset;
1887 event = wimp_poll_idle(mask, &block, t, 0);
1889 event = wimp_poll(wimp_MASK_NULL | mask, &block, 0);
1901 if (event == wimp_NULL_REASON_CODE) {
1919 error = xwimp_open_window(open);
1921 NSLOG(netsurf, INFO,
"xwimp_open_window: 0x%x: %s",
1922 error->errnum, error->errmess);
1939 filename = ((wimp_full_message_data_xfer *)message)->file_name;
1940 sprintf(command,
"@RunType_FFF %s", filename);
1941 error = xwimp_start_task(command, 0);
1943 NSLOG(netsurf, INFO,
"xwimp_start_task failed: 0x%x: %s",
1944 error->errnum, error->errmess);
1957 wimp_full_message_data_xfer message;
1961 const uint8_t *source_data;
1978 error = xosfile_read_no_path(temp_name, &objtype, 0, 0, 0, 0);
1979 if ((!error) && (objtype == osfile_IS_FILE)) {
1980 snprintf(message.file_name, 212,
"%s", temp_name);
1981 message.file_name[211] =
'\0';
1994 char full_name[256];
2003 full_name[255] =
'\0';
2004 r = __riscosify(full_name, 0, __RISCOSIFY_NO_SUFFIX,
2005 message.file_name, 212, 0);
2007 NSLOG(netsurf, INFO,
"__riscosify failed");
2010 message.file_name[211] =
'\0';
2012 error = xosfile_save_stamped(message.file_name,
2014 (
byte *) source_data,
2015 (
byte *) source_data + source_size);
2017 NSLOG(netsurf, INFO,
2018 "xosfile_save_stamped failed: 0x%x: %s",
2027 message.your_ref = 0;
2028 message.size = 44 + ((strlen(message.file_name) + 4) & (~3u));
2029 message.action = message_DATA_OPEN;
2034 message.est_size = 0;
2035 message.file_type = 0xfff;
2037 (wimp_message*)&message, 0,
2075 die(
"Out of memory");
2078 die(
"Out of memory");
2090 NSLOG(netsurf, INFO,
"%s %s", warning, detail);
2093 char warn_buffer[300];
2094 snprintf(warn_buffer,
sizeof warn_buffer,
"%s %s",
2096 detail ? detail :
"");
2097 warn_buffer[
sizeof warn_buffer - 1] = 0;
2101 wimp_ICON_DELETED, wimp_ICON_DELETED);
2108 snprintf(error.errmess,
sizeof error.errmess,
"%s %s",
2110 detail ? detail :
"");
2111 error.errmess[
sizeof error.errmess - 1] = 0;
2112 xwimp_report_error_by_category(&error,
2113 wimp_ERROR_BOX_OK_ICON |
2114 wimp_ERROR_BOX_GIVEN_CATEGORY |
2115 wimp_ERROR_BOX_CATEGORY_ERROR <<
2116 wimp_ERROR_BOX_CATEGORY_SHIFT,
2117 "NetSurf",
"!netsurf",
2118 (osspriteop_area *) 1, 0, 0);
2130void die(
const char *
const error)
2132 os_error warn_error;
2134 NSLOG(netsurf, INFO,
"%s", error);
2136 warn_error.errnum = 1;
2138 sizeof(warn_error.errmess)-1);
2139 warn_error.errmess[
sizeof(warn_error.errmess)-1] =
'\0';
2140 xwimp_report_error_by_category(&warn_error,
2141 wimp_ERROR_BOX_OK_ICON |
2142 wimp_ERROR_BOX_GIVEN_CATEGORY |
2143 wimp_ERROR_BOX_CATEGORY_ERROR <<
2144 wimp_ERROR_BOX_CATEGORY_SHIFT,
2145 "NetSurf",
"!netsurf",
2146 (osspriteop_area *) 1, 0, 0);
2183 const char *elm[16];
2187 size_t fname_len = 0;
2192 if ((nelm == 0) || (nelm > 16)) {
2195 if ((*str != NULL) && (size == NULL)) {
2205 for (elm_idx = 0; elm_idx < nelm; elm_idx++) {
2206 elm[elm_idx] = va_arg(ap,
const char *);
2208 if (elm[elm_idx] == NULL) {
2211 elm_len[elm_idx] = strlen(elm[elm_idx]);
2212 fname_len += elm_len[elm_idx];
2218 if (fname != NULL) {
2219 if (fname_len > *size) {
2223 fname = malloc(fname_len);
2224 if (fname == NULL) {
2233 memmove(curp, elm[0], elm_len[0]);
2244 for (elm_idx = 1; elm_idx < nelm; elm_idx++) {
2245 for (idx = 0; idx < elm_len[elm_idx]; idx++) {
2246 if (elm[elm_idx][idx] ==
DIR_SEP) {
2249 *curp = elm[elm_idx][idx];
2258 assert((curp - fname) <= (
int)fname_len);
2288 const char *leafname;
2303 fname = strdup(leafname);
2304 if (fname == NULL) {
2310 for (temp = fname; *temp != 0; temp++) {
2318 *size = strlen(fname);
2337 dname = strdup(fname);
2340 while ((cur = strchr(cur,
'.'))) {
2342 xosfile_create_dir(dname, 0);
2369 FILE *stream = fopen(
"<Wimp$ScrapDir>.WWW.NetSurf.dump",
"w");
2371 NSLOG(netsurf, INFO,
"fopen: errno %i", errno);
2381 error = xwimp_start_task(
"Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.dump",
2384 NSLOG(netsurf, INFO,
"xwimp_start_task failed: 0x%x: %s",
2385 error->errnum, error->errmess);
2418 char *cachepath = NULL;
2421 cachedir = getenv(
"Cache$Dir");
2422 if ((cachedir == NULL) || (cachedir[0] == 0)) {
2423 NSLOG(netsurf, INFO,
"cachedir was null");
2462 die(
"NetSurf operation table failed registration");
2467 error = xos_read_var_val_size(
"NetSurf$Logging", 0, os_VARTYPE_STRING,
2468 &used, NULL, &
type);
2469 if (error != NULL ||
type != os_VARTYPE_STRING || used != -2) {
2472 char logging_env[2];
2473 error = xos_read_var_val(
"NetSurf$Logging", logging_env,
2474 sizeof(logging_env), 0, os_VARTYPE_STRING,
2475 &used, NULL, &
type);
2476 if (error != NULL || logging_env[0] !=
'0') {
2491 die(
"Options failed to initialise");
2500 if (((length = snprintf(
path,
2502 "NetSurf:Resources.%s.Messages",
2504 (length >= (
int)
sizeof(
path))) {
2505 die(
"Failed to locate Messages resource.");
2518 die(
"NetSurf failed to initialise core");
const char * fetch_filetype(const char *unix_path)
Determine the MIME type of a local file.
int main(int argc, char **argv)
Normal entry point from OS.
Content for image/x-artworks (RISC OS interface).
static nserror artworks_init(void)
int schedule_run(void)
Process events up to current time.
Low-level source data cache backing store interface.
struct gui_llcache_table * filesystem_llcache_table
Browser window creation and manipulation interface.
nserror browser_window_navigate(struct browser_window *bw, struct nsurl *url, struct nsurl *referrer, enum browser_window_nav_flags flags, char *post_urlenc, struct fetch_multipart_data *post_multipart, struct hlcache_handle *parent)
Start fetching a page in a browser window.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
nserror browser_window_debug_dump(struct browser_window *bw, FILE *f, enum content_debug op)
Dump debug info concerning the browser window's contents to file.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
@ BW_NAVIGATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
void ro_gui_buffer_close(void)
Closes any open buffer and flushes the contents to screen.
Screen buffering (interface).
@ CONTENT_DEBUG_RENDER
Debug the contents rendering.
Unified cookie database public interface.
void urldb_save_cookies(const char *filename)
Save persistent cookies to file.
void urldb_load_cookies(const char *filename)
Load a cookie file into the database.
Useful interned string pointers (interface).
#define FILE_SCHEME_PREFIX_LEN
File url prefix length.
#define FILE_SCHEME_PREFIX
File url prefix.
static nserror hotlist_save(const char *path)
nserror hotlist_init(const char *load_path, const char *save_path)
Initialise the hotlist.
nserror search_web_init(const char *provider_fname)
Initialise the web search operations.
nserror search_web_select_provider(const char *selection)
Change the currently selected web search provider.
void ro_gui_dialog_close_persistent(wimp_w parent)
Close persistent dialogs associated with a window.
void ro_gui_dialog_open(wimp_w w)
Open a dialog box, centred on the screen.
void ro_gui_dialog_init(void)
Load and create dialogs from template file.
void ro_gui_dialog_close(wimp_w close)
Close a dialog box.
Content for image/x-drawfile (RISC OS interface).
static nserror draw_init(void)
nserror
Enumeration of error codes.
@ NSERROR_NOSPACE
Insufficient space.
@ NSERROR_NOT_FOUND
Requested item not found.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_NOMEM
Memory exhaustion.
const char * filename_request(void)
Request a new, unique, filename.
bool filename_initialise(void)
Initialise the filename provider.
#define TEMP_FILENAME_PREFIX
struct gui_bitmap_table * riscos_bitmap_table
bitmap operations table
void ro_gui_download_init(void)
Load the download window template.
bool ro_gui_download_prequit(void)
Respond to PreQuit message, displaying a prompt message if we need the user to confirm the shutdown.
struct gui_download_table * riscos_download_table
void ro_gui_download_datasave_ack(wimp_message *message)
Handle Message_DataSaveAck for a drag from a download window.
void nsfont_init(void)
Initialize font handling.
void ro_gui_wimp_get_desktop_font(void)
Retrieve the current desktop font family, size and style from the WindowManager in a form suitable fo...
struct gui_layout_table * riscos_layout_table
nserror ro_gui_global_history_finalise(void)
Free any resources allocated for the global history window.
RISc OS global history interface.
void ro_gui_hotlist_add_cleanup(void)
Clean up RMA storage used by the Message_HotlistAddURL protocol.
nserror ro_gui_hotlist_finalise(void)
Free any resources allocated for the cookie window.
#define message_HOTLIST_CHANGED
#define message_HOTLIST_ADD_URL
nserror ro_gui_local_history_finalise(void)
Free any resources allocated for the local history window.
RISC OS local history interface.
void ro_mouse_pointer_leaving_window(wimp_leaving *leaving)
Process Wimp_PointerLeaving events by terminating an active mouse track and passing the details on to...
os_t ro_mouse_poll_interval(void)
Return the desired polling interval to allow the mouse tracking to be carried out.
void ro_mouse_drag_end(wimp_dragged *dragged)
Process Wimp_DragEnd events by terminating an active drag track and passing the details on to any reg...
void ro_mouse_poll(void)
Process Null polls for any drags and mouse trackers that are currently active.
Mouse dragging and tracking support interface for RISC OS.
void ro_print_dataload_bounce(wimp_message *m)
Handle a bounced dataload message.
void ro_print_cleanup(void)
Cleanup after printing.
void ro_print_error(wimp_message *m)
Handle message_PRINT_ERROR.
bool ro_print_ack(wimp_message *m)
Handle message_DATASAVE_ACK for the printing protocol.
struct gui_window * ro_print_current_window
void ro_print_save_bounce(wimp_message *m)
Handle a bounced message_PRINT_SAVE.
void ro_print_type_odd(wimp_message *m)
Handle message_PRINT_TYPE_ODD.
void ro_gui_selection_data_request(wimp_full_message_data_request *req)
Responds to DATA_REQUEST message, returning information about the clipboard contents if we own the cl...
void ro_gui_selection_claim_entity(wimp_full_message_claim_entity *claim)
Responds to CLAIM_ENTITY message notifying us that the caret and selection or clipboard have been cla...
struct gui_clipboard_table * riscos_clipboard_table
bool ro_gui_selection_prepare_paste_datasave(wimp_full_message_data_xfer *dataxfer)
Prepare to paste data from another application (step 2)
void ro_gui_selection_prepare_paste(wimp_w w, ro_gui_selection_prepare_paste_cb cb, void *pw)
Prepare to paste data from another application.
void ro_gui_selection_dragging(wimp_message *message)
Handler for Message_Dragging, used to implement auto-scrolling and ghost caret when a drag is in prog...
bool ro_gui_selection_prepare_paste_dataload(wimp_full_message_data_xfer *dataxfer)
Prepare to paste data from another application (step 3)
void ro_gui_selection_drag_claim(wimp_message *message)
Text selection import/export (interface).
Browser window handling (interface).
#define ro_gui_window_close_all
Close all browser windows.
void ro_gui_iconbar_initialise(void)
Initialise the iconbar menus, create an icon and register the necessary handlers to look after them a...
Iconbar icon and menus (interface).
Public content interface.
struct nsurl * hlcache_handle_get_url(const struct hlcache_handle *handle)
Retrieve the URL associated with a high level cache handle.
const uint8_t * content_get_source_data(struct hlcache_handle *h, size_t *size)
Retrieve source of content.
Interface to platform-specific fetcher operations.
Interface to platform-specific miscellaneous browser operation table.
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
Initialise the logging system.
bool verbose_log
flag to enable verbose logging
void nslog_finalise(void)
Shut down the logging system.
#define NSLOG(catname, level, logmsg, args...)
bool ro_message_handle_message(wimp_event_no event, wimp_message *message)
Attempts to route a message.
bool ro_message_send_message(wimp_event_no event, wimp_message *message, wimp_t task, void(*callback)(wimp_message *message))
Sends a message and registers a return route for a bounce.
bool ro_message_register_route(unsigned int message_code, void(*callback)(wimp_message *message))
Registers a route for a message code.
Automated RISC OS message routing (interface).
nserror messages_add_from_file(const char *path)
Read keys and values from messages file into the standard Messages hash.
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
NetSurf core interface registration, construction and destruction.
void netsurf_exit(void)
Finalise NetSurf core.
nserror netsurf_init(const char *store_path)
Initialise netsurf core.
nserror netsurf_register(struct netsurf_table *table)
Register operation table.
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
lwc_string * nsurl_get_component(const nsurl *url, nsurl_component part)
Get part of a URL as a lwc_string, from a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
void ro_gui_query_init(void)
nserror ro_gui_cookies_finalise(void)
Free any resources allocated for the cookie window.
nserror ro_gui_cookies_present(const char *search_term)
make the cookie window visible.
Interface to riscos cookie viewing using riscos core window.
struct core_window_table * riscos_core_window_table
RISC OS core window interface.
char * fetch_mimetype(const char *ro_path)
Find a MIME type for a local file.
int ro_content_filetype(struct hlcache_handle *c)
Determine the RISC OS filetype for a content.
RISC OS filetpe interface.
#define FILETYPE_ARTWORKS
#define FILETYPE_ACORN_URI
void ro_gui_screen_size(int *width, int *height)
Find screen size in OS units.
static void ro_gui_cleanup(void)
Ensures the gui exits cleanly.
static bool ro_gui_uri_file_parse_line(FILE *fp, char *b)
Read a "line" from an Acorn URI file.
const char *const __dynamic_da_name
For UnixLib.
static void ro_gui_check_resolvers(void)
Warn the user if Inet$Resolvers is not set.
ro_gui_drag_type gui_current_drag_type
static void riscos_poll(void)
Poll the RISC OS wimp for events.
static nsurl * gui_get_resource_url(const char *path)
Callback to translate resource to full url for RISC OS.
void ro_gui_view_source(struct hlcache_handle *c)
Send the source of a content to a text editor.
static struct gui_fetch_table riscos_fetch_table
static void ro_msg_datasave(wimp_message *message)
Handle Message_DataSave.
int __dynamic_da_max_size
For UnixLib.
static nserror gui_launch_url(struct nsurl *url)
Broadcast an URL that we can't handle.
osspriteop_area * gui_sprites
Sprite area containing pointer and hotlist sprites.
static nserror riscos_mkpath(char **str, size_t *size, size_t nelm, va_list ap)
Generate a riscos path from one or more component elemnts.
bool ro_gui_prequit(void)
Test whether it's okay to shutdown, prompting the user if not.
static void ro_gui_user_message(wimp_event_no event, wimp_message *message)
Handle the three User_Message events.
static nserror gui_init(int argc, char **argv)
Initialise the RISC OS specific GUI.
static nserror set_defaults(struct nsoption_s *defaults)
Set option defaults for riscos frontend.
static void ro_gui_get_screen_properties(void)
Get screen properties following a mode change.
wimp_t task_handle
RISC OS wimp task handle.
static bool nslog_stream_configure(FILE *fptr)
Ensures output logging stream is correctly configured.
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
static void ro_msg_save_desktop(wimp_message *message)
Handle SaveDesktop message.
static void ro_gui_close_window_request(wimp_close *close)
Handle Close_Window_Request events.
static void gui_quit(void)
Close down the gui (RISC OS).
void ro_gui_dump_browser_window(struct browser_window *bw)
Send the debug dump of a content to a text editor.
static void ro_gui_keypress_cb(void *pw)
Handle key press paste callback.
static void ro_gui_handle_event(wimp_event_no event, wimp_block *block)
Process a Wimp_Poll event.
static nserror set_colour_from_wimp(struct nsoption_s *opts, wimp_colour wimp, enum nsoption_e option, colour def_colour)
Set colour option from wimp.
static void ro_gui_signal(int sig)
Handles a signal.
bool ro_plot_patterned_lines
One version of the A9home OS is incapable of drawing patterned lines.
static char * ro_gui_url_file_parse(const char *file_name)
Parse an ANT URL file.
static void ro_msg_dataopen(wimp_message *message)
Handle Message_DataOpen (double-click on file in the Filer).
void die(const char *const error)
Display an error and exit.
static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out)
Create a path from a nsurl using posix file handling.
static char * get_cachepath(void)
static void ro_gui_choose_language(void)
Choose the language to use.
static nserror ro_path_to_nsurl(const char *path, struct nsurl **url_out)
Create a nsurl from a RISC OS pathname.
static nserror riscos_mkdir_all(const char *fname)
Ensure that all directory elements needed to store a filename exist.
int __feature_imagefs_is_file
For UnixLib.
static void ro_msg_window_info(wimp_message *message)
Handle WindowInfo message (part of the iconising protocol)
static clock_t gui_last_poll
Time of last wimp_poll.
static void ro_msg_prequit(wimp_message *message)
Handle PreQuit message.
static nserror riscos_basename(const char *path, char **str, size_t *size)
Get the basename of a file using posix path handling.
void ro_gui_open_window_request(wimp_open *open)
Handle Open_Window_Request events.
static void ro_gui_keypress(wimp_key *key)
Handle gui keypress.
static void ro_msg_dataload(wimp_message *message)
Handle Message_DataLoad (file dragged in).
static void ro_gui_view_source_bounce(wimp_message *message)
source bounce callback.
static void ro_gui_create_dirs(void)
Create intermediate directories for Choices and User Data files.
bool os_alpha_sprite_supported
static struct gui_misc_table riscos_misc_table
static bool ro_gui__os_alpha_sprites_supported(void)
Determine whether the OS version supports alpha channels.
static ns_wimp_message_list task_messages
Accepted wimp user messages.
static void ro_msg_terminate_filename(wimp_full_message_data_xfer *message)
Ensure that the filename in a data transfer message is NULL terminated (some applications,...
static const char * task_name
static char * ro_gui_ieurl_file_parse(const char *file_name)
Parse an IEURL file.
static struct gui_file_table riscos_file_table
const char * ro_gui_default_language(void)
Determine the default language to use.
static char * ro_gui_uri_file_parse(const char *file_name, char **uri_title)
Parse an Acorn URI file.
static void ro_msg_datasave_ack(wimp_message *message)
Handle Message_DataSaveAck.
static struct @46 screen_info
os_t sched_time
Time of soonest scheduled event (valid only if sched_active is true).
nserror riscos_schedule(int t, void(*callback)(void *p), void *p)
Schedule a callback.
bool sched_active
Items have been scheduled.
#define ICON_WARNING_HELP
struct gui_search_table * riscos_search_table
#define ICON_WARNING_MESSAGE
void ro_gui_interactive_help_request(wimp_message *message)
Attempts to process an interactive help message request.
Interactive help (interface).
nserror ro_gui_pageinfo_finalise(void)
Free any resources allocated for the page info window.
Interface to page info core window for RISC OS.
File/object/selection saving (Interface).
void ro_gui_theme_initialise(void)
Initialise the theme handler.
void ro_gui_throb(void)
Animate the "throbbers" of all browser windows.
struct gui_window * ro_gui_toolbar_lookup(wimp_w window)
Convert a toolbar RISC OS window handle to a gui_window.
void ro_gui_window_update_boxes(void)
Redraw any pending update boxes.
bool ro_gui_toolbar_dataload(struct gui_window *g, wimp_message *message)
Handle Message_DataLoad (file dragged in) for a toolbar.
struct gui_window_table * riscos_window_table
bool ro_gui_alt_pressed(void)
Returns true iff one or more Alt keys is held down.
void ro_gui_window_iconise(struct gui_window *g, wimp_full_message_window_info *wi)
Window is being iconised.
struct gui_window * ro_gui_window_lookup(wimp_w window)
Convert a RISC OS window handle to a gui_window.
bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message)
Handle Message_DataLoad (file dragged in) for a window.
void ro_gui_window_quit(void)
Destroy all browser windows.
void ro_gui_window_initialise(void)
Initialise the browser window module and its menus.
void ro_gui_drag_box_cancel(void)
void ro_gui_saveas_quit(void)
Clean-up function that releases our sprite area and memory.
void ro_gui_save_datasave_ack(wimp_message *message)
Handle Message_DataSaveAck for a drag from the save dialog or browser window, or Clipboard protocol.
void save_complete_init(void)
Initialise save complete module.
Save HTML document with dependencies (interface).
core web search facilities interface.
Content for image/x-riscos-sprite (RISC OS interface).
static nserror sprite_init(void)
Interface to utility string handling.
function table for fetcher operations.
const char *(* filetype)(const char *unix_path)
Determine the MIME type of a local file.
/brief function table for file and filename operations.
nserror(* mkpath)(char **str, size_t *size, size_t nemb, va_list ap)
Generate a path from one or more component elemnts.
Graphical user interface browser misc function table.
nserror(* schedule)(int t, void(*callback)(void *p), void *p)
Schedule a callback.
first entry in window list
struct browser_window * bw
The 'content' window that is rendered in the gui_window.
NetSurf operation function table.
struct gui_misc_table * misc
Browser table.
union nsoption_s::@149 value
#define alpha_SPRITE_MODE
uint32_t colour
Colour type: XBGR.
struct gui_utf8_table * riscos_utf8_table
UCS conversion tables (interface) This is only used if nothing claims Service_International,...
void ro_uri_message_received(wimp_message *msg)
void ro_uri_bounce(wimp_message *msg)
nserror url_escape(const char *unescaped, bool sptoplus, const char *escexceptions, char **result)
Escape a string suitable for inclusion in an URL.
nserror url_unescape(const char *str, size_t length, size_t *length_out, char **result_out)
Convert an escaped string to plain.
Interface to URL parsing and joining operations.
void ro_gui_url_bar_fini(void)
Finalise the url bar module.
bool ro_gui_url_bar_init(void)
Initialise the url bar module.
Unified URL information database public interface.
nserror urldb_save(const char *filename)
Export the current database to file.
nserror urldb_load(const char *filename)
Import an URL database from file, replacing any existing database.
void ro_url_broadcast(const char *url)
Broadcast an ANT URL message.
void ro_url_message_received(wimp_message *message)
Handle a Message_InetSuiteOpenURL.
void ro_url_bounce(wimp_message *message)
Handle a bounced Message_InetSuiteOpenURL.
ANT URL launching protocol (interface).
nserror netsurf_mkdir_all(const char *fname)
Ensure that all directory elements needed to store a filename exist.
nserror netsurf_nsurl_to_path(struct nsurl *url, char **path_out)
Create a path from a nsurl.
nserror netsurf_path_to_nsurl(const char *path, struct nsurl **url)
Create a nsurl from a path.
nserror netsurf_mkpath(char **str, size_t *size, size_t nelm,...)
Generate a path from one or more component elemnts.
Default operations table for files.
struct nsoption_s * nsoptions_default
global default option table.
static struct nsoption_s defaults[]
The table of compiled in default options.
nserror nsoption_dump(FILE *outf, struct nsoption_s *opts)
Write all options to a stream.
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
struct nsoption_s * nsoptions
global active option table.
nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
Process commandline and set options approriately.
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
#define nsoption_setnull_charp(OPTION, VALUE)
set string option in default table if currently unset
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
#define nsoption_bool(OPTION)
Get the value of a boolean option.
#define nsoption_set_uint(OPTION, VALUE)
set an unsigned integer option in the default table
Interface to a number of general purpose functionality.
#define SLEN(x)
Calculate length of constant C string.
bool is_dir(const char *path)
Check if a directory exists.
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
Set the contents of a text or sprite icon to a string.
osspriteop_area * ro_gui_load_sprite_file(const char *pathname)
Load a sprite file into memory.
void ro_gui_scroll(wimp_scroll *scroll)
Generic window scroll event handler.
General RISC OS WIMP/OS library functions (interface).
bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer)
Handles a mouse click event in a registered window.
bool ro_gui_wimp_event_redraw_window(wimp_draw *redraw)
Handle any redraw window requests.
bool ro_gui_wimp_event_scroll_window(wimp_scroll *scroll)
Handle any scroll window requests.
bool ro_gui_wimp_event_open_window(wimp_open *open)
Handle any open window requests.
bool ro_gui_wimp_event_close_window(wimp_w w)
Service any close window handlers.
bool ro_gui_wimp_event_pointer_entering_window(wimp_entering *entering)
Handle any pointer entering window requests.
bool ro_gui_wimp_event_keypress(wimp_key *key)
Handle any registered keypresses, and the standard RISC OS ones.
Automated RISC OS WIMP event handling (interface).
A collection of grubby utilities for working with OSLib's wimp API.
#define PTR_WIMP_MESSAGE_LIST(l)
#define PTR_OS_VDU_VAR_LIST(l)
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.