2006-01-31 00:51:50 +08:00
|
|
|
/** \file parse_util.h
|
|
|
|
|
2006-02-19 09:54:38 +08:00
|
|
|
Various mostly unrelated utility functions related to parsing,
|
|
|
|
loading and evaluating fish code.
|
2006-01-31 00:51:50 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FISH_PARSE_UTIL_H
|
|
|
|
#define FISH_PARSE_UTIL_H
|
|
|
|
|
2012-01-26 03:47:45 +08:00
|
|
|
#include "autoload.h"
|
2006-01-31 00:51:50 +08:00
|
|
|
#include <wchar.h>
|
2012-01-24 03:42:41 +08:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
|
2006-01-31 00:51:50 +08:00
|
|
|
/**
|
2006-02-19 09:54:38 +08:00
|
|
|
Find the beginning and end of the first subshell in the specified string.
|
2011-12-27 11:18:46 +08:00
|
|
|
|
2006-01-31 00:51:50 +08:00
|
|
|
\param in the string to search for subshells
|
|
|
|
\param begin the starting paranthesis of the subshell
|
|
|
|
\param end the ending paranthesis of the subshell
|
|
|
|
\param flags set this variable to ACCEPT_INCOMPLETE if in tab_completion mode
|
|
|
|
\return -1 on syntax error, 0 if no subshells exist and 1 on sucess
|
|
|
|
*/
|
|
|
|
|
2011-12-27 11:18:46 +08:00
|
|
|
int parse_util_locate_cmdsubst( const wchar_t *in,
|
|
|
|
wchar_t **begin,
|
2006-06-14 21:22:40 +08:00
|
|
|
wchar_t **end,
|
2006-06-20 08:50:10 +08:00
|
|
|
int flags );
|
2006-01-31 00:51:50 +08:00
|
|
|
|
2006-02-09 02:47:37 +08:00
|
|
|
/**
|
2006-07-03 18:46:47 +08:00
|
|
|
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.
|
2006-02-19 09:54:38 +08:00
|
|
|
|
|
|
|
\param buff the string to search for subshells
|
|
|
|
\param cursor_pos the position of the cursor
|
|
|
|
\param a the start of the searched string
|
|
|
|
\param b the end of the searched string
|
2006-02-09 02:47:37 +08:00
|
|
|
*/
|
2006-01-31 00:51:50 +08:00
|
|
|
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
|
|
|
int cursor_pos,
|
2012-02-06 16:57:43 +08:00
|
|
|
const wchar_t **a,
|
|
|
|
const wchar_t **b );
|
2006-01-31 00:51:50 +08:00
|
|
|
|
2006-02-09 02:47:37 +08:00
|
|
|
/**
|
|
|
|
Find the beginning and end of the process definition under the cursor
|
2006-02-19 09:54:38 +08:00
|
|
|
|
|
|
|
\param buff the string to search for subshells
|
|
|
|
\param cursor_pos the position of the cursor
|
|
|
|
\param a the start of the searched string
|
|
|
|
\param b the end of the searched string
|
2006-02-09 02:47:37 +08:00
|
|
|
*/
|
2006-01-31 00:51:50 +08:00
|
|
|
void parse_util_process_extent( const wchar_t *buff,
|
2006-02-19 09:54:38 +08:00
|
|
|
int cursor_pos,
|
2012-02-06 16:57:43 +08:00
|
|
|
const wchar_t **a,
|
|
|
|
const wchar_t **b );
|
2006-01-31 00:51:50 +08:00
|
|
|
|
|
|
|
|
2006-02-09 02:47:37 +08:00
|
|
|
/**
|
|
|
|
Find the beginning and end of the job definition under the cursor
|
2006-02-19 09:54:38 +08:00
|
|
|
|
|
|
|
\param buff the string to search for subshells
|
|
|
|
\param cursor_pos the position of the cursor
|
|
|
|
\param a the start of the searched string
|
|
|
|
\param b the end of the searched string
|
2006-02-09 02:47:37 +08:00
|
|
|
*/
|
2006-01-31 00:51:50 +08:00
|
|
|
void parse_util_job_extent( const wchar_t *buff,
|
2006-02-19 09:54:38 +08:00
|
|
|
int cursor_pos,
|
2012-02-06 16:57:43 +08:00
|
|
|
const wchar_t **a,
|
|
|
|
const wchar_t **b );
|
2006-01-31 00:51:50 +08:00
|
|
|
|
2006-02-09 02:47:37 +08:00
|
|
|
/**
|
2006-06-20 08:50:10 +08:00
|
|
|
Find the beginning and end of the token under the cursor and the
|
2012-02-06 16:57:43 +08:00
|
|
|
token before the current token. Any combination of tok_begin,
|
2006-06-20 08:50:10 +08:00
|
|
|
tok_end, prev_begin and prev_end may be null.
|
2006-02-19 09:54:38 +08:00
|
|
|
|
|
|
|
\param buff the string to search for subshells
|
|
|
|
\param cursor_pos the position of the cursor
|
2006-06-20 08:50:10 +08:00
|
|
|
\param tok_begin the start of the current token
|
|
|
|
\param tok_end the end of the current token
|
|
|
|
\param prev_begin the start o the token before the current token
|
|
|
|
\param prev_end the end of the token before the current token
|
2006-02-09 02:47:37 +08:00
|
|
|
*/
|
2006-01-31 00:51:50 +08:00
|
|
|
void parse_util_token_extent( const wchar_t *buff,
|
|
|
|
int cursor_pos,
|
2012-02-06 16:57:43 +08:00
|
|
|
const wchar_t **tok_begin,
|
|
|
|
const wchar_t **tok_end,
|
|
|
|
const wchar_t **prev_begin,
|
|
|
|
const wchar_t **prev_end );
|
2006-01-31 00:51:50 +08:00
|
|
|
|
2006-02-09 02:47:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the linenumber at the specified character offset
|
|
|
|
*/
|
2006-02-05 21:10:35 +08:00
|
|
|
int parse_util_lineno( const wchar_t *str, int len );
|
|
|
|
|
2007-09-21 22:05:49 +08:00
|
|
|
/**
|
|
|
|
Calculate the line number of the specified cursor position
|
|
|
|
*/
|
2012-02-06 16:57:43 +08:00
|
|
|
int parse_util_get_line_from_offset( const wcstring &str, int pos );
|
2007-09-21 22:05:49 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the offset of the first character on the specified line
|
|
|
|
*/
|
2012-02-06 16:57:43 +08:00
|
|
|
int parse_util_get_offset_from_line( const wcstring &str, int line );
|
2007-09-21 22:05:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the total offset of the buffer for the cursor position nearest to the specified poition
|
|
|
|
*/
|
2012-02-06 16:57:43 +08:00
|
|
|
int parse_util_get_offset( const wcstring &str, int line, int line_offset );
|
2007-09-21 22:05:49 +08:00
|
|
|
|
2006-02-15 10:24:15 +08:00
|
|
|
/**
|
|
|
|
Set the argv environment variable to the specified null-terminated
|
2011-12-27 11:18:46 +08:00
|
|
|
array of strings.
|
2006-02-15 10:24:15 +08:00
|
|
|
*/
|
2012-01-30 14:06:58 +08:00
|
|
|
void parse_util_set_argv( const wchar_t * const *argv, const wcstring_list_t &named_arguments );
|
2006-02-15 10:24:15 +08:00
|
|
|
|
2006-02-19 09:14:32 +08:00
|
|
|
/**
|
2006-02-19 09:54:38 +08:00
|
|
|
Make a duplicate of the specified string, unescape wildcard
|
|
|
|
characters but not performing any other character transformation.
|
2006-02-19 09:14:32 +08:00
|
|
|
*/
|
|
|
|
wchar_t *parse_util_unescape_wildcards( const wchar_t *in );
|
|
|
|
|
2007-04-22 17:50:26 +08:00
|
|
|
|
|
|
|
|
2006-01-31 00:51:50 +08:00
|
|
|
#endif
|