Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

parse_util.c File Reference

Various mostly unrelated utility functions related to parsing, loading and evaluating fish code. More...

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <wctype.h>
#include <wchar.h>
#include <time.h>
#include <assert.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "common.h"
#include "tokenizer.h"
#include "parse_util.h"
#include "expand.h"
#include "intern.h"
#include "exec.h"
#include "env.h"
#include "signal.h"
#include "wildcard.h"
#include "halloc_util.h"

Data Structures

struct  autoload_t
 A structure representing the autoload state for a specific variable, e.g. More...

Defines

#define AUTOLOAD_MAX   10
 Maximum number of autoloaded items opf a specific type to keep in memory at a time.
#define AUTOLOAD_MIN_AGE   60
 Minimum time, in seconds, before an autoloaded item will be unloaded.

Functions

int parse_util_lineno (const wchar_t *str, int len)
 Get the linenumber at the specified character offset.
int parse_util_get_line_from_offset (wchar_t *buff, int pos)
 Calculate the line number of the specified cursor position.
int parse_util_get_offset_from_line (wchar_t *buff, int line)
 Get the offset of the first character on the specified line.
int parse_util_get_offset (wchar_t *buff, int line, int line_offset)
 Return the total offset of the buffer for the cursor position nearest to the specified poition.
int parse_util_locate_cmdsubst (const wchar_t *in, wchar_t **begin, wchar_t **end, int allow_incomplete)
 Find the beginning and end of the first subshell in the specified string.
void parse_util_cmdsubst_extent (const wchar_t *buff, int cursor_pos, wchar_t **a, wchar_t **b)
 Find the beginning and end of the command substitution under the cursor.
static void job_or_process_extent (const wchar_t *buff, int cursor_pos, wchar_t **a, wchar_t **b, int process)
 Get the beginning and end of the job or process definition under the cursor.
void parse_util_process_extent (const wchar_t *buff, int pos, wchar_t **a, wchar_t **b)
 Find the beginning and end of the process definition under the cursor.
void parse_util_job_extent (const wchar_t *buff, int pos, wchar_t **a, wchar_t **b)
 Find the beginning and end of the job definition under the cursor.
void parse_util_token_extent (const wchar_t *buff, int cursor_pos, wchar_t **tok_begin, wchar_t **tok_end, wchar_t **prev_begin, wchar_t **prev_end)
 Find the beginning and end of the token under the cursor and the toekn before the current token.
static void clear_hash_value (void *key, void *data, void *aux)
 Free hash value, but not hash key.
static void clear_loaded_entry (void *key, void *data, void *handler)
 Part of the autoloader cleanup.
static void parse_util_destroy ()
 The autoloader cleanup function.
void parse_util_load_reset (const wchar_t *path_var_name, void(*on_load)(const wchar_t *cmd))
 Reset the loader for the specified path variable.
int parse_util_unload (const wchar_t *cmd, const wchar_t *path_var_name, void(*on_load)(const wchar_t *cmd))
 Tell the autoloader that the specified file, in the specified path, is no longer loaded.
static void parse_util_autounload (const wchar_t *path_var_name, const wchar_t *skip, void(*on_load)(const wchar_t *cmd))
 Unload all autoloaded items that have expired, that where loaded in the specified path.
static int parse_util_load_internal (const wchar_t *cmd, void(*on_load)(const wchar_t *cmd), int reload, autoload_t *loaded, array_list_t *path_list)
 This internal helper function does all the real work.
int parse_util_load (const wchar_t *cmd, const wchar_t *path_var_name, void(*on_load)(const wchar_t *cmd), int reload)
 Autoload the specified file, if it exists in the specified path.
void parse_util_set_argv (wchar_t **argv, array_list_t *named_arguments)
 Set the argv environment variable to the specified null-terminated array of strings.
wchar_t * parse_util_unescape_wildcards (const wchar_t *str)
 Make a duplicate of the specified string, unescape wildcard characters but not performing any other character transformation.

Variables

static hash_table_tall_loaded = 0
 Set of files which have been autoloaded.


Detailed Description

Various mostly unrelated utility functions related to parsing, loading and evaluating fish code.

This library can be seen as a 'toolbox' for functions that are used in many places in fish and that are somehow related to parsing the code.


Function Documentation

static void parse_util_autounload const wchar_t *  path_var_name,
const wchar_t *  skip,
void(*)(const wchar_t *cmd)  on_load
[static]
 

Unload all autoloaded items that have expired, that where loaded in the specified path.

Parameters:
path_var_name The variable containing the path to autoload in
skip unloading the the specified file
on_load the callback function to call for every unloaded file

void parse_util_cmdsubst_extent const wchar_t *  buff,
int  cursor_pos,
wchar_t **  a,
wchar_t **  b
 

Find the beginning and end of the command substitution under the cursor.

If no subshell is found, the entire string is returned. If the current command substitution is not ended, i.e. the closing parenthesis is missing, then the string from the beginning of the substitution to the end of the string is returned.

Parameters:
buff the string to search for subshells
cursor_pos the position of the cursor
a the start of the searched string
b the end of the searched string

static void parse_util_destroy  )  [static]
 

The autoloader cleanup function.

It is run on shutdown and frees any memory used by the autoloader code to keep track of loaded files.

void parse_util_job_extent const wchar_t *  buff,
int  cursor_pos,
wchar_t **  a,
wchar_t **  b
 

Find the beginning and end of the job definition under the cursor.

Parameters:
buff the string to search for subshells
cursor_pos the position of the cursor
a the start of the searched string
b the end of the searched string

int parse_util_lineno const wchar_t *  str,
int  len
 

Get the linenumber at the specified character offset.

First cached state

Second cached state

int parse_util_load const wchar_t *  cmd,
const wchar_t *  path_var_name,
void(*)(const wchar_t *cmd)  on_load,
int  reload
 

Autoload the specified file, if it exists in the specified path.

Init if this is the first time we try to autoload anything

Warn and fail on infinite recursion

Cleanup

Make sure we didn't 'drop' something

static int parse_util_load_internal const wchar_t *  cmd,
void(*)(const wchar_t *cmd)  on_load,
int  reload,
autoload_t loaded,
array_list_t path_list
[static]
 

This internal helper function does all the real work.

By using two functions, the internal function can return on various places in the code, and the caller can take care of various cleanup work.

void parse_util_load_reset const wchar_t *  path_var_name,
void(*)(const wchar_t *cmd)  on_unload
 

Reset the loader for the specified path variable.

This will cause all information on loaded files in the specified directory to be reset.

Parameters:
path_var_name the environment variable giving the search path
on_unload a callback function which will be called before (re)loading a file, may be used to unload the previous file.

int parse_util_locate_cmdsubst const wchar_t *  in,
wchar_t **  begin,
wchar_t **  end,
int  flags
 

Find the beginning and end of the first subshell in the specified string.

Parameters:
in the string to search for subshells
begin the starting paranthesis of the subshell
end the ending paranthesis of the subshell
flags set this variable to ACCEPT_INCOMPLETE if in tab_completion mode
Returns:
-1 on syntax error, 0 if no subshells exist and 1 on sucess

void parse_util_process_extent const wchar_t *  buff,
int  cursor_pos,
wchar_t **  a,
wchar_t **  b
 

Find the beginning and end of the process definition under the cursor.

Parameters:
buff the string to search for subshells
cursor_pos the position of the cursor
a the start of the searched string
b the end of the searched string

void parse_util_token_extent const wchar_t *  buff,
int  cursor_pos,
wchar_t **  tok_begin,
wchar_t **  tok_end,
wchar_t **  prev_begin,
wchar_t **  prev_end
 

Find the beginning and end of the token under the cursor and the toekn before the current token.

Any combination of tok_begin, tok_end, prev_begin and prev_end may be null.

Parameters:
buff the string to search for subshells
cursor_pos the position of the cursor
tok_begin the start of the current token
tok_end the end of the current token
prev_begin the start o the token before the current token
prev_end the end of the token before the current token

int parse_util_unload const wchar_t *  cmd,
const wchar_t *  path_var_name,
void(*)(const wchar_t *cmd)  on_unload
 

Tell the autoloader that the specified file, in the specified path, is no longer loaded.

Parameters:
cmd the filename to search for. The suffix '.fish' is always added to this name
path_var_name the environment variable giving the search path
on_unload a callback function which will be called before (re)loading a file, may be used to unload the previous file.
Returns:
non-zero if the file was removed, zero if the file had not yet been loaded


Generated on Sun Jan 13 02:52:59 2008 for fish by  doxygen 1.4.4