mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
fix indent test and indentation
This commit is contained in:
@@ -56,7 +56,7 @@ int mfshell_cmd_file(mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
|
||||
int mfshell_cmd_folder(mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
char *const argv[]);
|
||||
|
||||
int mfshell_cmd_links(mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
int mfshell_cmd_folder(mfshell * mfshell, int argc, char *const argv[])
|
||||
{
|
||||
mffolder *folder;
|
||||
mffolder *folder;
|
||||
int retval;
|
||||
const char *folderkey;
|
||||
const char *name;
|
||||
@@ -93,7 +93,7 @@ int mfshell_cmd_folder(mfshell * mfshell, int argc, char *const argv[])
|
||||
printf(" %-15.15s %s\n\r", "parent:", parent);
|
||||
|
||||
if (revision != 0)
|
||||
printf(" %-15.15s %"PRIu32"\n\r", "revision:", revision);
|
||||
printf(" %-15.15s %" PRIu32 "\n\r", "revision:", revision);
|
||||
|
||||
if (epoch != 0) {
|
||||
memset(&tm, 0, sizeof(struct tm));
|
||||
|
||||
@@ -47,8 +47,7 @@ int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char *const argv[])
|
||||
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
retval = mfconn_api_folder_create(mfshell->conn, folder_curr,
|
||||
(char *)name);
|
||||
retval = mfconn_api_folder_create(mfshell->conn, folder_curr, (char *)name);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
return retval;
|
||||
|
||||
@@ -30,27 +30,25 @@
|
||||
|
||||
void parse_config(struct mfshell_user_options *opts)
|
||||
{
|
||||
FILE *fp;
|
||||
char *homedir;
|
||||
FILE *fp;
|
||||
char *homedir;
|
||||
|
||||
// parse the configuration file
|
||||
// if a value is not set (it is NULL) then it has not been set by the
|
||||
// commandline and should be set by the configuration file
|
||||
|
||||
// try set config file first if set
|
||||
if (opts->config != NULL &&
|
||||
(fp = fopen(opts->config, "r")) != NULL) {
|
||||
if (opts->config != NULL && (fp = fopen(opts->config, "r")) != NULL) {
|
||||
parse_config_file(fp, opts);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
// try "./.mediafire-tools.conf" second
|
||||
if ((fp = fopen("./.mediafire-tools.conf", "r")) != NULL) {
|
||||
parse_config_file(fp, opts);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
// try "~/.mediafire-tools.conf" third
|
||||
if ((homedir = getenv("HOME")) == NULL) {
|
||||
homedir = getpwuid(getuid())->pw_dir;
|
||||
@@ -63,17 +61,18 @@ void parse_config(struct mfshell_user_options *opts)
|
||||
free(homedir);
|
||||
}
|
||||
|
||||
void parse_config_file(FILE *fp, struct mfshell_user_options *opts)
|
||||
void parse_config_file(FILE * fp, struct mfshell_user_options *opts)
|
||||
{
|
||||
// read the config file line by line and pass each line to wordexp to
|
||||
// retain proper quoting
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
wordexp_t p;
|
||||
int ret, i;
|
||||
int argc;
|
||||
char **argv;
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
wordexp_t p;
|
||||
int ret,
|
||||
i;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
while ((read = getline(&line, &len, fp)) != -1) {
|
||||
if (line[0] == '#')
|
||||
@@ -108,10 +107,10 @@ void parse_config_file(FILE *fp, struct mfshell_user_options *opts)
|
||||
// parse it
|
||||
argc = p.we_wordc + 1;
|
||||
// allocate one more than argc for trailing NULL
|
||||
argv = (char **)malloc(sizeof(char*)*(argc+1));
|
||||
argv[0] = ""; // dummy program name
|
||||
argv = (char **)malloc(sizeof(char *) * (argc + 1));
|
||||
argv[0] = ""; // dummy program name
|
||||
for (i = 1; i < argc; i++)
|
||||
argv[i] = p.we_wordv[i-1];
|
||||
argv[i] = p.we_wordv[i - 1];
|
||||
argv[argc] = NULL;
|
||||
parse_argv(argc, argv, opts);
|
||||
free(argv);
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
#include "options.h"
|
||||
|
||||
void parse_config(struct mfshell_user_options *opts);
|
||||
void parse_config(struct mfshell_user_options *opts);
|
||||
|
||||
void parse_config_file(FILE *fp, struct mfshell_user_options *opts);
|
||||
void parse_config_file(FILE * fp, struct mfshell_user_options *opts);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,7 @@ int main(int argc, char *const argv[])
|
||||
{
|
||||
mfshell *shell;
|
||||
char *auth_cmd;
|
||||
|
||||
struct mfshell_user_options opts = {
|
||||
.username = NULL,
|
||||
.password = NULL,
|
||||
@@ -53,25 +54,21 @@ int main(int argc, char *const argv[])
|
||||
if (opts.server == NULL) {
|
||||
opts.server = strdup("www.mediafire.com");
|
||||
}
|
||||
|
||||
// if app_id was neither set on the commandline nor in the config, set it
|
||||
// to the default value
|
||||
if (opts.app_id == -1)
|
||||
opts.app_id = 42709;
|
||||
|
||||
shell = mfshell_create(opts.app_id, opts.api_key,
|
||||
opts.server);
|
||||
shell = mfshell_create(opts.app_id, opts.api_key, opts.server);
|
||||
if (shell == NULL) {
|
||||
fprintf(stderr, "cannot create shell\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// if at least username was set, authenticate automatically
|
||||
if (opts.username != NULL) {
|
||||
if (opts.password != NULL) {
|
||||
auth_cmd = strdup_printf("auth %s %s",
|
||||
opts.username,
|
||||
opts.password);
|
||||
opts.username, opts.password);
|
||||
} else {
|
||||
auth_cmd = strdup_printf("auth %s", opts.username);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ struct mfcmd commands[] = {
|
||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||
{"ls", "", "show contents of active folder",
|
||||
mfshell_cmd_list},
|
||||
{"cd", "<folderkey>", "change active folder (default: root)", mfshell_cmd_chdir},
|
||||
{"cd", "<folderkey>", "change active folder (default: root)",
|
||||
mfshell_cmd_chdir},
|
||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||
{"lpwd", "", "show the local working directory",
|
||||
mfshell_cmd_lpwd},
|
||||
@@ -43,7 +44,8 @@ struct mfcmd commands[] = {
|
||||
mfshell_cmd_lcd},
|
||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||
{"folder", "<folderkey>", "show folder information (default:root)", mfshell_cmd_folder},
|
||||
{"folder", "<folderkey>", "show folder information (default:root)",
|
||||
mfshell_cmd_folder},
|
||||
{"links", "[quickkey]", "show access urls for the file",
|
||||
mfshell_cmd_links},
|
||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||
|
||||
@@ -33,7 +33,8 @@ struct mfcmd {
|
||||
char *name;
|
||||
char *argstring;
|
||||
char *help;
|
||||
int (*handler) (mfshell * mfshell, int argc, char *const argv[]);
|
||||
int (*handler) (mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
};
|
||||
|
||||
struct mfshell {
|
||||
|
||||
@@ -136,8 +136,7 @@ void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (opts->password != NULL &&
|
||||
opts->username == NULL) {
|
||||
if (opts->password != NULL && opts->username == NULL) {
|
||||
fprintf(stderr, "You cannot pass the password without the username\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -20,17 +20,18 @@
|
||||
#define _MFSHELL_OPTIONS_H_
|
||||
|
||||
struct mfshell_user_options {
|
||||
char *username;
|
||||
char *password;
|
||||
char *command;
|
||||
char *server;
|
||||
char *config;
|
||||
int app_id;
|
||||
char *api_key;
|
||||
char *username;
|
||||
char *password;
|
||||
char *command;
|
||||
char *server;
|
||||
char *config;
|
||||
int app_id;
|
||||
char *api_key;
|
||||
};
|
||||
|
||||
void print_help(const char *cmd);
|
||||
void print_help(const char *cmd);
|
||||
|
||||
void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts);
|
||||
void parse_argv(int argc, char *const argv[],
|
||||
struct mfshell_user_options *opts);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user