NetSurf
Macros | Functions | Variables
main.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/select.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include "utils/config.h"
#include "utils/sys_time.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/filepath.h"
#include "utils/nsoption.h"
#include "utils/nsurl.h"
#include "netsurf/misc.h"
#include "netsurf/netsurf.h"
#include "netsurf/url_db.h"
#include "netsurf/cookie_db.h"
#include "content/fetch.h"
#include "content/backing_store.h"
#include "monkey/output.h"
#include "monkey/dispatch.h"
#include "monkey/browser.h"
#include "monkey/401login.h"
#include "monkey/filetype.h"
#include "monkey/fetch.h"
#include "monkey/schedule.h"
#include "monkey/bitmap.h"
#include "monkey/layout.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define LANGV_SIZE   32
 maximum number of languages in language vector More...
 
#define LANGS_SIZE   4096
 maximum length of all strings in language vector More...
 

Functions

static void die (const char *const error)
 Cause an abnormal program termination. More...
 
static const char * get_language (void)
 obtain language from environment More...
 
static const char *const * get_languagev (void)
 provide a string vector of languages in preference order More...
 
static char ** nsmonkey_init_resource (const char *resource_path)
 Create an array of valid paths to search for resources. More...
 
static void monkey_quit (void)
 
static nserror gui_launch_url (struct nsurl *url)
 
static nserror gui_present_cookies (const char *search_term)
 
static void quit_handler (int argc, char **argv)
 
static void monkey_options_handle_command (int argc, char **argv)
 
static nserror set_defaults (struct nsoption_s *defaults)
 Set option defaults for monkey frontend. More...
 
static bool nslog_stream_configure (FILE *fptr)
 Ensures output logging stream is correctly configured. More...
 
static void monkey_run (void)
 
int main (int argc, char **argv)
 Normal entry point from OS. More...
 

Variables

char ** respaths
 resource search path vector More...
 
static bool monkey_done = false
 
static struct gui_misc_table monkey_misc_table
 

Macro Definition Documentation

◆ LANGS_SIZE

#define LANGS_SIZE   4096

maximum length of all strings in language vector

Definition at line 56 of file main.c.

◆ LANGV_SIZE

#define LANGV_SIZE   32

maximum number of languages in language vector

Definition at line 54 of file main.c.

Function Documentation

◆ die()

static void die ( const char *const  error)
static

Cause an abnormal program termination.

Note
This never returns and is intended to terminate without any cleanup.
Parameters
errorThe message to display to the user.

Definition at line 70 of file main.c.

References MOUT_DIE, and moutf().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_language()

static const char * get_language ( void  )
static

obtain language from environment

start with GNU extension LANGUAGE environment variable and then try POSIX variables LC_ALL, LC_MESSAGES and LANG

Definition at line 83 of file main.c.

Referenced by get_languagev().

Here is the caller graph for this function:

◆ get_languagev()

static const char *const * get_languagev ( void  )
static

provide a string vector of languages in preference order

environment variables are processed to aquire a colon separated list of languages which are converted into a string vector. The vector will always have the C language as its last entry.

This implementation creates an internal static representation of the vector when first called and returns that for all subsequent calls. i.e. changing the environment does not change the returned vector on repeated calls.

If the environment variables have more than LANGV_SIZE languages or LANGS_SIZE bytes of data the results list will be curtailed.

Definition at line 126 of file main.c.

References get_language(), LANGS_SIZE, and LANGV_SIZE.

Referenced by nsmonkey_init_resource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_launch_url()

static nserror gui_launch_url ( struct nsurl url)
static

Definition at line 214 of file main.c.

References MOUT_GENERIC, moutf(), NSERROR_OK, and nsurl_access().

Here is the call graph for this function:

◆ gui_present_cookies()

static nserror gui_present_cookies ( const char *  search_term)
static

Definition at line 220 of file main.c.

References MOUT_GENERIC, moutf(), and NSERROR_OK.

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Normal entry point from OS.

Normal entry point from OS.

/param argc The number of arguments in the string vector. /param argv The argument string vector. /return The return code to the OS

Normal entry point from OS.

Todo:
logging file descriptor update belongs in a nslog_init callback

Definition at line 389 of file main.c.

References die(), filepath_find(), filepath_sfinddef(), filesystem_llcache_table, messages_add_from_file(), netsurf_table::misc, monkey_bitmap_table, monkey_download_table, monkey_fetch_filetype_init(), monkey_fetch_table, monkey_free_handlers(), monkey_kill_browser_windows(), monkey_layout_table, monkey_login_handle_command(), monkey_misc_table, monkey_options_handle_command(), monkey_register_handler(), monkey_run(), monkey_window_handle_command(), monkey_window_table, MOUT_GENERIC, moutf(), netsurf_exit(), netsurf_init(), netsurf_register(), NSERROR_OK, NSLOG, nslog_finalise(), nslog_init(), nslog_stream_configure(), nsmonkey_init_resource(), nsoption_charp, nsoption_commandline(), nsoption_finalise(), nsoption_init(), nsoption_read(), nsoptions, nsoptions_default, options, PATH_MAX, quit_handler(), respaths, set_defaults(), urldb_load(), and urldb_load_cookies().

Here is the call graph for this function:

◆ monkey_options_handle_command()

static void monkey_options_handle_command ( int  argc,
char **  argv 
)
static

Definition at line 235 of file main.c.

References nsoption_commandline(), and nsoptions.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ monkey_quit()

static void monkey_quit ( void  )
static

Definition at line 207 of file main.c.

References monkey_fetch_filetype_fin(), nsoption_charp, urldb_save(), and urldb_save_cookies().

Here is the call graph for this function:

◆ monkey_run()

static void monkey_run ( void  )
static

Definition at line 277 of file main.c.

References fetch_fdset(), monkey_done, monkey_process_command(), monkey_schedule_run(), MOUT_GENERIC, moutf(), and NSLOG.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nslog_stream_configure()

static bool nslog_stream_configure ( FILE *  fptr)
static

Ensures output logging stream is correctly configured.

Definition at line 260 of file main.c.

Referenced by main().

Here is the caller graph for this function:

◆ nsmonkey_init_resource()

static char ** nsmonkey_init_resource ( const char *  resource_path)
static

Create an array of valid paths to search for resources.

The idea is that all the complex path computation to find resources is performed here, once, rather than every time a resource is searched for.

Parameters
resource_pathA shell style colon separated path list
Returns
A string vector of valid paths where resources can be found

Definition at line 190 of file main.c.

References filepath_free_strvec(), filepath_generate(), filepath_path_to_strvec(), and get_languagev().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ quit_handler()

static void quit_handler ( int  argc,
char **  argv 
)
static

Definition at line 230 of file main.c.

References monkey_done.

Referenced by main().

Here is the caller graph for this function:

◆ set_defaults()

static nserror set_defaults ( struct nsoption_s defaults)
static

Set option defaults for monkey frontend.

Parameters
defaultsThe option table to update.
Returns
error status.

Definition at line 246 of file main.c.

References NSERROR_OK, and nsoption_setnull_charp.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ monkey_done

bool monkey_done = false
static

Definition at line 61 of file main.c.

Referenced by monkey_run(), and quit_handler().

◆ monkey_misc_table

struct gui_misc_table monkey_misc_table
static
Initial value:
= {
.schedule = monkey_schedule,
.quit = monkey_quit,
.launch_url = gui_launch_url,
.present_cookies = gui_present_cookies,
}
nserror gui_401login_open(struct nsurl *url, const char *realm, const char *username, const char *password, nserror(*cb)(const char *username, const char *password, void *pw), void *cbpw)
Definition: login.cpp:175
static nserror gui_launch_url(struct nsurl *url)
Definition: main.c:214
static void monkey_quit(void)
Definition: main.c:207
static nserror gui_present_cookies(const char *search_term)
Definition: main.c:220
nserror monkey_schedule(int tival, void(*callback)(void *p), void *p)
Schedule a callback.
Definition: schedule.c:100

Definition at line 268 of file main.c.

Referenced by main().

◆ respaths

char** respaths

resource search path vector

Definition at line 59 of file main.c.

Referenced by get_resource_url(), gui_get_resource_url(), main(), nsgtk_get_resource_url(), nsw32_messages_init(), nsw32_option_init(), and WinMain().