19 #define VERSION_STRING "wd v1.1 by dev@brightsilence.com\n https://github.com/bright-tools/wd"
20 #define UNRECOGNISED_ARG_STRING "Unrecognised command line argument"
21 #define NEED_PARAMETER_STRING "No parameter specified for argument"
22 #define INCOMPATIBLE_OP_STRING "Parameter incompatible with other arguments"
23 #define UNRECOGNISED_PARAM_STRING "Parameter to argument not recognised"
26 #define DEFAULT_LIST_FILE "/.wd_list"
27 #define ENV_VAR_NAME "WD_OPTS"
39 #include <sys/types.h>
49 char homedir[MAX_PATH];
50 success = SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, homedir));
53 char *homedir = getenv(
"HOME");
55 if( homedir == NULL ) {
59 struct passwd *pw = getpwuid(uid);
64 if( homedir != NULL ) {
73 size_t home_size = strlen( homedir );
74 size_t complete = home_size +
78 strcpy( p_config->
list_fn, homedir );
80 p_config->
list_fn[ complete -1 ] = 0;
102 static void show_help(
const char*
const p_cmd ) {
104 "%s [-v] [-h] [-t] [-f <fn>] [-r [dir] [-p]] [-a [dir]] [-d] [-l] [-s <c>]\n"
105 " -v : Show version information\n"
106 " -h : Show usage help\n"
107 " -d : Dump bookmark list\n"
108 " -t : Store access times for bookmarks\n"
109 " -l : List directories & bookmark names (generally for use in tab\n"
111 " -s <c> : Format paths for cygwin\n"
112 " -n <nam> : Get bookmark directory with specified shortcut name\n"
113 " -p : Prompt for input (can be used with -r instead of specifying\n"
115 " -f <fn> : Use file <fn> for storing bookmarks\n"
116 " -r [dir] : Remove specified directory or current directory if none\n"
117 " -a [dir] : Add specified directory or current directory if none\n"
125 static int process_opts(
config_container_t*
const p_config,
const int argc,
char*
const argv[],
const int p_cmd_line ) {
130 for( arg_loop = 1; arg_loop < argc; arg_loop++ )
132 char* this_arg = argv[ arg_loop ];
134 if( p_cmd_line && ( 0 == strcmp( this_arg,
"-v" ) )) {
136 }
else if( p_cmd_line && ( 0 == strcmp( this_arg,
"-h" )) ) {
137 show_help( argv[0] );
138 }
else if( p_cmd_line && ( 0 == strcmp( this_arg,
"-p" )) ) {
140 }
else if( 0 == strcmp( this_arg,
"-t" ) ) {
142 }
else if( 0 == strcmp( this_arg,
"-z" ) ) {
143 if(( arg_loop + 1 ) < argc ) {
145 sscanf(argv[arg_loop],
"%ld",(
long int*)(&p_config->
wd_now_time));
150 }
else if( 0 == strcmp( this_arg,
"-e" ) ) {
151 if(( arg_loop + 1 ) < argc ) {
154 switch( argv[ arg_loop ][0] ) {
189 }
else if( 0 == strcmp( this_arg,
"-s" ) ) {
190 if(( arg_loop + 1 ) < argc ) {
193 switch( argv[ arg_loop ][0] ) {
209 }
else if( p_cmd_line && ( 0 == strcmp( this_arg,
"-d" )) ) {
211 }
else if( p_cmd_line && ( 0 == strcmp( this_arg,
"-l" )) ) {
213 }
else if( p_cmd_line && (( 0 == strcmp( this_arg,
"-n" )) ||
214 ( 0 == strcmp( this_arg,
"-g" )))) {
215 if((( arg_loop + 1 ) < argc ) &&
216 ( argv[ arg_loop + 1 ][0] !=
'-' )) {
218 if( 0 == strcmp( this_arg,
"-n" ) ) {
228 }
else if( p_cmd_line &&
229 (( 0 == strcmp( this_arg,
"-a" )) ||
230 ( 0 == strcmp( this_arg,
"-r" ))) ) {
232 switch( this_arg[ 1 ] ) {
242 if((( arg_loop + 1 ) < argc ) &&
243 ( argv[ arg_loop + 1 ][0] !=
'-' )) {
249 GetFullPathName( argv[ arg_loop ],
254 realpath( argv[ arg_loop ], p_config->
wd_oper_dir );
259 if((( arg_loop + 1 ) < argc ) &&
260 ( argv[ arg_loop + 1 ][0] !=
'-' )) {
272 if((( arg_loop + 1 ) < argc ) &&
273 ( argv[ arg_loop + 1 ][0] !=
'-' )) {
277 }
else if( 0 == strcmp( this_arg,
"-f" ) ) {
279 if( arg_loop < argc ) {
282 p_config->
list_fn = realloc( p_config->
list_fn, strlen( argv[ arg_loop ] ));
283 strcpy( p_config->
list_fn, argv[ arg_loop ] );
307 const size_t opts_len = strlen( opts ) + 1U;
308 char* opt_copy = (
char*) malloc( opts_len );
323 for( loop = 0, src = opts, dest = opt_copy ;
325 loop++, src++, dest++ )
341 argv = malloc(
sizeof(
char*[ breaks + 2 ] ));
358 if( waiting && ( opt_copy[ loop ] !=
'0' )) {
359 argv[breaks++] = &(opt_copy[loop]);
362 }
else if( opt_copy[loop ] == 0 ) {
369 ret_val = process_opts( p_config, breaks, argv, 0 );
379 return process_opts( p_config, argc, argv, 1 );
char * wd_bookmark_name
Name of a bookmark read from the command line on which operations should be performed.
int wd_output_all
Control whether or not all items should be output regardless of whether or not they seem to point to ...
#define UNRECOGNISED_PARAM_STRING
time_t wd_now_time
Time to use as the current time when manipulating datestamps.
#define INCOMPATIBLE_OP_STRING
wd_oper_t wd_oper
Type of operation which the command line has instructed should be performed.
void init_cmdln(config_container_t *const p_config)
Initialise the specified config with default values.
char * list_fn
Directory containing list of bookmarks.
int process_cmdln(config_container_t *const p_config, const int argc, char *const argv[])
char wd_oper_dir[MAXPATHLEN]
Directory read from the command line upon which operations should be performed.
#define UNRECOGNISED_ARG_STRING
#define NEED_PARAMETER_STRING
#define DEFAULT_LIST_FILE
int wd_store_access
Indicate whether or not access times should be stored in the bookmarks.
int wd_prompt
Indicate whether or not to run in "interactive" mode.
wd_dir_format_t wd_dir_form
Format in which file paths should be output.
wd_entity_t wd_entity_type
Control which types of entity should be included in the output.
int process_env(config_container_t *const p_config)