00001
00005 #ifndef FISH_COMMON_H
00006
00009 #define FISH_COMMON_H
00010
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013 #include <wchar.h>
00014 #include <termios.h>
00015
00016 #include "util.h"
00017
00021 #define MAX_UTF8_BYTES 6
00022
00026 #define ENCODE_DIRECT_BASE 0xf100
00027
00031 #define ASCII_MAX 127u
00032
00036 #define UCS2_MAX 0xffffu
00037
00041 #define BYTE_MAX 0xffu
00042
00046 #define UNESCAPE_SPECIAL 1
00047
00051 #define UNESCAPE_INCOMPLETE 2
00052
00056 #define ESCAPE_ALL 1
00057
00060 #define ESCAPE_NO_QUOTED 2
00061
00062
00066 extern struct termios shell_modes;
00067
00072 extern wchar_t ellipsis_char;
00073
00078 extern int debug_level;
00079
00083 extern char *profile;
00084
00089 extern wchar_t *program_name;
00090
00097 #define CHECK( arg, retval ) \
00098 if( !(arg) ) \
00099 { \
00100 debug( 0, \
00101 _( L"function %s called with null value for argument %s. " ), \
00102 __func__, \
00103 #arg ); \
00104 bugreport(); \
00105 show_stackframe(); \
00106 return retval; \
00107 }
00108
00112 #define FATAL_EXIT() \
00113 { \
00114 int exit_read_count;char exit_read_buff; \
00115 show_stackframe(); \
00116 exit_read_count=read( 0, &exit_read_buff, 1 ); \
00117 exit( 1 ); \
00118 } \
00119
00120
00124 #define DIE_MEM() \
00125 { \
00126 fwprintf( stderr, \
00127 L"fish: Out of memory on line %d of file %s, shutting down fish\n", \
00128 __LINE__, \
00129 __FILE__ ); \
00130 FATAL_EXIT(); \
00131 }
00132
00137 #define CHECK_BLOCK( retval ) \
00138 if( signal_is_blocked() ) \
00139 { \
00140 debug( 0, \
00141 _( L"function %s called while blocking signals. " ), \
00142 __func__); \
00143 bugreport(); \
00144 show_stackframe(); \
00145 return retval; \
00146 }
00147
00151 #define _(wstr) wgettext(wstr)
00152
00157 #define N_(wstr) wstr
00158
00162 #define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
00163
00166 #define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
00167
00171 void show_stackframe();
00172
00178 wchar_t **list_to_char_arr( array_list_t *l );
00179
00191 int fgetws2( wchar_t **buff, int *len, FILE *f );
00192
00197 void sort_list( array_list_t *comp );
00198
00206 wchar_t *str2wcs( const char *in );
00207
00216 wchar_t *str2wcs_internal( const char *in, wchar_t *out );
00217
00225 char *wcs2str( const wchar_t *in );
00226
00235 char *wcs2str_internal( const wchar_t *in, char *out );
00236
00241 char **wcsv2strv( const wchar_t **in );
00242
00246 wchar_t **strv2wcsv( const char **in );
00247
00248
00253 __sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
00254
00266 wchar_t *wcsvarname( const wchar_t *str );
00267
00268
00275 wchar_t *wcsfuncname( const wchar_t *str );
00276
00283 int wcsvarchr( wchar_t chr );
00284
00285
00289 int my_wcswidth( const wchar_t *c );
00290
00298 wchar_t *quote_end( const wchar_t *in );
00299
00308 void error_reset();
00309
00316 const wchar_t *wsetlocale( int category, const wchar_t *locale );
00317
00325 __sentinel int contains_internal( const wchar_t *needle, ... );
00326
00332 int read_blocked(int fd, void *buf, size_t count);
00333
00338 ssize_t write_loop(int fd, char *buff, size_t count);
00339
00340
00359 void debug( int level, const wchar_t *msg, ... );
00360
00370 wchar_t *escape( const wchar_t *in, int escape_all );
00371
00383 wchar_t *unescape( const wchar_t * in,
00384 int escape_special );
00385
00395 int acquire_lock_file( const char *lockfile, const int timeout, int force );
00396
00404 int common_get_width();
00412 int common_get_height();
00413
00419 void common_handle_winch( int signal );
00420
00425 void write_screen( const wchar_t *msg, string_buffer_t *buff );
00426
00435 void tokenize_variable_array( const wchar_t *val, array_list_t *out );
00436
00443 int create_directory( wchar_t *d );
00444
00448 void bugreport();
00449
00453 void sb_format_size( string_buffer_t *sb,
00454 long long sz );
00455
00463 double timef();
00464
00465
00466 #endif
00467