fix indent test and indentation

This commit is contained in:
josch
2014-09-24 11:28:35 +02:00
parent 0561a922c5
commit 6ca27f0a6a
18 changed files with 88 additions and 98 deletions

View File

@@ -30,24 +30,22 @@
#include "../mfapi/mfconn.h" #include "../mfapi/mfconn.h"
enum enum {
{
KEY_HELP, KEY_HELP,
KEY_VERSION, KEY_VERSION,
}; };
mfconn *conn; mfconn *conn;
struct mediafirefs_user_options { struct mediafirefs_user_options {
char *username; char *username;
char *password; char *password;
char *configfile; char *configfile;
char *server; char *server;
int app_id; int app_id;
char *api_key; char *api_key;
} mediafirefs_user_options = { } mediafirefs_user_options = {
NULL, NULL, NULL, NULL, -1, NULL NULL, NULL, NULL, NULL, -1, NULL};
};
static struct fuse_opt mediafirefs_opts[] = { static struct fuse_opt mediafirefs_opts[] = {
FUSE_OPT_KEY("-h", KEY_HELP), FUSE_OPT_KEY("-h", KEY_HELP),
@@ -86,8 +84,7 @@ static void usage(const char *progname)
" -k, --api-key key API Key\n" " -k, --api-key key API Key\n"
"\n" "\n"
"Notice that long options are separated from their arguments by\n" "Notice that long options are separated from their arguments by\n"
"a space and not an equal sign.\n" "a space and not an equal sign.\n" "\n", progname);
"\n", progname);
} }
static int mediafirefs_getattr(const char *path, struct stat *stbuf) static int mediafirefs_getattr(const char *path, struct stat *stbuf)
@@ -105,7 +102,8 @@ static int mediafirefs_getattr(const char *path, struct stat *stbuf)
} }
static int mediafirefs_readdir(const char *path, void *buf, static int mediafirefs_readdir(const char *path, void *buf,
fuse_fill_dir_t filldir, off_t offset, struct fuse_file_info *info) fuse_fill_dir_t filldir, off_t offset,
struct fuse_file_info *info)
{ {
(void)path; (void)path;
(void)offset; (void)offset;
@@ -144,19 +142,17 @@ static int
mediafirefs_opt_proc(void *data, const char *arg, int key, mediafirefs_opt_proc(void *data, const char *arg, int key,
struct fuse_args *outargs) struct fuse_args *outargs)
{ {
(void)data; // unused (void)data; // unused
(void)arg; // unused (void)arg; // unused
if(key == KEY_HELP) if (key == KEY_HELP) {
{
usage(outargs->argv[0]); usage(outargs->argv[0]);
fuse_opt_add_arg(outargs, "-ho"); fuse_opt_add_arg(outargs, "-ho");
fuse_main(outargs->argc, outargs->argv, &mediafirefs_oper, NULL); fuse_main(outargs->argc, outargs->argv, &mediafirefs_oper, NULL);
exit(0); exit(0);
} }
if(key == KEY_VERSION) if (key == KEY_VERSION) {
{
fuse_opt_add_arg(outargs, "--version"); fuse_opt_add_arg(outargs, "--version");
fuse_main(outargs->argc, outargs->argv, &mediafirefs_oper, NULL); fuse_main(outargs->argc, outargs->argv, &mediafirefs_oper, NULL);
exit(0); exit(0);
@@ -165,14 +161,13 @@ mediafirefs_opt_proc(void *data, const char *arg, int key,
return 1; return 1;
} }
int int main(int argc, char *argv[])
main(int argc, char *argv[])
{ {
struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
if(fuse_opt_parse
(&args, &mediafirefs_user_options, mediafirefs_opts, if (fuse_opt_parse
mediafirefs_opt_proc) == -1) (&args, &mediafirefs_user_options, mediafirefs_opts,
{ mediafirefs_opt_proc) == -1) {
exit(1); exit(1);
} }
@@ -191,10 +186,10 @@ main(int argc, char *argv[])
} }
conn = mfconn_create(mediafirefs_user_options.server, conn = mfconn_create(mediafirefs_user_options.server,
mediafirefs_user_options.username, mediafirefs_user_options.username,
mediafirefs_user_options.password, mediafirefs_user_options.password,
mediafirefs_user_options.app_id, mediafirefs_user_options.app_id,
mediafirefs_user_options.api_key); mediafirefs_user_options.api_key);
if (conn == NULL) { if (conn == NULL) {
fprintf(stderr, "Cannot establish connection\n"); fprintf(stderr, "Cannot establish connection\n");

View File

@@ -25,7 +25,8 @@
#include "../mfconn.h" #include "../mfconn.h"
#include "../apicalls.h" // IWYU pragma: keep #include "../apicalls.h" // IWYU pragma: keep
int mfconn_api_folder_create(mfconn * conn, const char *parent, const char *name) int mfconn_api_folder_create(mfconn * conn, const char *parent,
const char *name)
{ {
const char *api_call; const char *api_call;
int retval; int retval;

View File

@@ -52,15 +52,15 @@ mfconn_api_folder_get_content(mfconn * conn, int mode, mffolder * folder_curr)
folderkey = folder_get_key(folder_curr); folderkey = folder_get_key(folder_curr);
if (folderkey == NULL) { if (folderkey == NULL) {
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php", api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
"?content_type=%s" "?content_type=%s"
"&response_format=json", "&response_format=json",
content_type); content_type);
} else { } else {
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php", api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
"?folder_key=%s" "?folder_key=%s"
"&content_type=%s" "&content_type=%s"
"&response_format=json", "&response_format=json",
folderkey, content_type); folderkey, content_type);
} }
http = http_create(); http = http_create();

View File

@@ -17,7 +17,7 @@
* *
*/ */
#define _XOPEN_SOURCE // for strptime #define _XOPEN_SOURCE // for strptime
#include <jansson.h> #include <jansson.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -33,7 +33,8 @@
static int _decode_folder_get_info(mfhttp * conn, void *data); static int _decode_folder_get_info(mfhttp * conn, void *data);
int int
mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, const char *folderkey) mfconn_api_folder_get_info(mfconn * conn, mffolder * folder,
const char *folderkey)
{ {
const char *api_call; const char *api_call;
int retval; int retval;
@@ -56,8 +57,7 @@ mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, const char *folderk
} else { } else {
api_call = mfconn_create_signed_get(conn, 0, "folder/get_info.php", api_call = mfconn_create_signed_get(conn, 0, "folder/get_info.php",
"?folder_key=%s" "?folder_key=%s"
"&response_format=json", "&response_format=json", folderkey);
folderkey);
} }
http = http_create(); http = http_create();

View File

@@ -42,8 +42,7 @@ mfconn_api_user_get_session_token(mfconn * conn, const char *server,
const char *username, const char *password, const char *username, const char *password,
int app_id, const char *app_key, int app_id, const char *app_key,
uint32_t * secret_key, uint32_t * secret_key,
char **secret_time, char **secret_time, char **session_token)
char **session_token)
{ {
char *login_url; char *login_url;
char *post_args; char *post_args;

View File

@@ -109,8 +109,7 @@ const char *mfconn_create_user_signature(mfconn * conn,
return NULL; return NULL;
if (app_key == NULL) { if (app_key == NULL) {
signature_raw = strdup_printf("%s%s%d", signature_raw = strdup_printf("%s%s%d", username, password, app_id);
username, password, app_id);
} else { } else {
signature_raw = strdup_printf("%s%s%d%s", signature_raw = strdup_printf("%s%s%d%s",
username, password, app_id, app_key); username, password, app_id, app_key);
@@ -170,8 +169,7 @@ const char *mfconn_create_call_signature(mfconn * conn, const char *url,
} }
const char *mfconn_create_signed_get(mfconn * conn, int ssl, const char *mfconn_create_signed_get(mfconn * conn, int ssl,
const char *api, const char *api, const char *fmt, ...)
const char *fmt, ...)
{ {
char *api_request = NULL; char *api_request = NULL;
char *api_args = NULL; char *api_args = NULL;

View File

@@ -35,8 +35,7 @@ void mfconn_destroy(mfconn * conn);
ssize_t mfconn_download_direct(mffile * file, const char *local_dir); ssize_t mfconn_download_direct(mffile * file, const char *local_dir);
const char *mfconn_create_signed_get(mfconn * conn, int ssl, const char *mfconn_create_signed_get(mfconn * conn, int ssl,
const char *api, const char *fmt, const char *api, const char *fmt, ...);
...);
const char *mfconn_create_user_signature(mfconn * conn, const char *mfconn_create_user_signature(mfconn * conn,
const char *username, const char *username,

View File

@@ -56,7 +56,7 @@ int mfshell_cmd_file(mfshell * mfshell, int argc,
char *const argv[]); char *const argv[]);
int mfshell_cmd_folder(mfshell * mfshell, int argc, int mfshell_cmd_folder(mfshell * mfshell, int argc,
char *const argv[]); char *const argv[]);
int mfshell_cmd_links(mfshell * mfshell, int argc, int mfshell_cmd_links(mfshell * mfshell, int argc,
char *const argv[]); char *const argv[]);

View File

@@ -34,7 +34,7 @@
int mfshell_cmd_folder(mfshell * mfshell, int argc, char *const argv[]) int mfshell_cmd_folder(mfshell * mfshell, int argc, char *const argv[])
{ {
mffolder *folder; mffolder *folder;
int retval; int retval;
const char *folderkey; const char *folderkey;
const char *name; 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); printf(" %-15.15s %s\n\r", "parent:", parent);
if (revision != 0) if (revision != 0)
printf(" %-15.15s %"PRIu32"\n\r", "revision:", revision); printf(" %-15.15s %" PRIu32 "\n\r", "revision:", revision);
if (epoch != 0) { if (epoch != 0) {
memset(&tm, 0, sizeof(struct tm)); memset(&tm, 0, sizeof(struct tm));

View File

@@ -47,8 +47,7 @@ int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char *const argv[])
folder_curr = folder_get_key(mfshell->folder_curr); folder_curr = folder_get_key(mfshell->folder_curr);
retval = mfconn_api_folder_create(mfshell->conn, folder_curr, retval = mfconn_api_folder_create(mfshell->conn, folder_curr, (char *)name);
(char *)name);
mfconn_update_secret_key(mfshell->conn); mfconn_update_secret_key(mfshell->conn);
return retval; return retval;

View File

@@ -30,27 +30,25 @@
void parse_config(struct mfshell_user_options *opts) void parse_config(struct mfshell_user_options *opts)
{ {
FILE *fp; FILE *fp;
char *homedir; char *homedir;
// parse the configuration file // parse the configuration file
// if a value is not set (it is NULL) then it has not been set by the // 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 // commandline and should be set by the configuration file
// try set config file first if set // try set config file first if set
if (opts->config != NULL && if (opts->config != NULL && (fp = fopen(opts->config, "r")) != NULL) {
(fp = fopen(opts->config, "r")) != NULL) {
parse_config_file(fp, opts); parse_config_file(fp, opts);
fclose(fp); fclose(fp);
return; return;
} }
// try "./.mediafire-tools.conf" second // try "./.mediafire-tools.conf" second
if ((fp = fopen("./.mediafire-tools.conf", "r")) != NULL) { if ((fp = fopen("./.mediafire-tools.conf", "r")) != NULL) {
parse_config_file(fp, opts); parse_config_file(fp, opts);
fclose(fp); fclose(fp);
return; return;
} }
// try "~/.mediafire-tools.conf" third // try "~/.mediafire-tools.conf" third
if ((homedir = getenv("HOME")) == NULL) { if ((homedir = getenv("HOME")) == NULL) {
homedir = getpwuid(getuid())->pw_dir; homedir = getpwuid(getuid())->pw_dir;
@@ -63,17 +61,18 @@ void parse_config(struct mfshell_user_options *opts)
free(homedir); 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 // read the config file line by line and pass each line to wordexp to
// retain proper quoting // retain proper quoting
char *line = NULL; char *line = NULL;
size_t len = 0; size_t len = 0;
ssize_t read; ssize_t read;
wordexp_t p; wordexp_t p;
int ret, i; int ret,
int argc; i;
char **argv; int argc;
char **argv;
while ((read = getline(&line, &len, fp)) != -1) { while ((read = getline(&line, &len, fp)) != -1) {
if (line[0] == '#') if (line[0] == '#')
@@ -108,10 +107,10 @@ void parse_config_file(FILE *fp, struct mfshell_user_options *opts)
// parse it // parse it
argc = p.we_wordc + 1; argc = p.we_wordc + 1;
// allocate one more than argc for trailing NULL // allocate one more than argc for trailing NULL
argv = (char **)malloc(sizeof(char*)*(argc+1)); argv = (char **)malloc(sizeof(char *) * (argc + 1));
argv[0] = ""; // dummy program name argv[0] = ""; // dummy program name
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
argv[i] = p.we_wordv[i-1]; argv[i] = p.we_wordv[i - 1];
argv[argc] = NULL; argv[argc] = NULL;
parse_argv(argc, argv, opts); parse_argv(argc, argv, opts);
free(argv); free(argv);

View File

@@ -23,8 +23,8 @@
#include "options.h" #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 #endif

View File

@@ -32,6 +32,7 @@ int main(int argc, char *const argv[])
{ {
mfshell *shell; mfshell *shell;
char *auth_cmd; char *auth_cmd;
struct mfshell_user_options opts = { struct mfshell_user_options opts = {
.username = NULL, .username = NULL,
.password = NULL, .password = NULL,
@@ -53,25 +54,21 @@ int main(int argc, char *const argv[])
if (opts.server == NULL) { if (opts.server == NULL) {
opts.server = strdup("www.mediafire.com"); opts.server = strdup("www.mediafire.com");
} }
// if app_id was neither set on the commandline nor in the config, set it // if app_id was neither set on the commandline nor in the config, set it
// to the default value // to the default value
if (opts.app_id == -1) if (opts.app_id == -1)
opts.app_id = 42709; opts.app_id = 42709;
shell = mfshell_create(opts.app_id, opts.api_key, shell = mfshell_create(opts.app_id, opts.api_key, opts.server);
opts.server);
if (shell == NULL) { if (shell == NULL) {
fprintf(stderr, "cannot create shell\n"); fprintf(stderr, "cannot create shell\n");
exit(1); exit(1);
} }
// if at least username was set, authenticate automatically // if at least username was set, authenticate automatically
if (opts.username != NULL) { if (opts.username != NULL) {
if (opts.password != NULL) { if (opts.password != NULL) {
auth_cmd = strdup_printf("auth %s %s", auth_cmd = strdup_printf("auth %s %s",
opts.username, opts.username, opts.password);
opts.password);
} else { } else {
auth_cmd = strdup_printf("auth %s", opts.username); auth_cmd = strdup_printf("auth %s", opts.username);
} }

View File

@@ -35,7 +35,8 @@ struct mfcmd commands[] = {
{"whoami", "", "show basic user info", mfshell_cmd_whoami}, {"whoami", "", "show basic user info", mfshell_cmd_whoami},
{"ls", "", "show contents of active folder", {"ls", "", "show contents of active folder",
mfshell_cmd_list}, 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}, {"pwd", "", "show the active folder", mfshell_cmd_pwd},
{"lpwd", "", "show the local working directory", {"lpwd", "", "show the local working directory",
mfshell_cmd_lpwd}, mfshell_cmd_lpwd},
@@ -43,7 +44,8 @@ struct mfcmd commands[] = {
mfshell_cmd_lcd}, mfshell_cmd_lcd},
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir}, {"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
{"file", "[quickkey]", "show file information", mfshell_cmd_file}, {"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", {"links", "[quickkey]", "show access urls for the file",
mfshell_cmd_links}, mfshell_cmd_links},
{"get", "[quickkey]", "download a file", mfshell_cmd_get}, {"get", "[quickkey]", "download a file", mfshell_cmd_get},

View File

@@ -33,7 +33,8 @@ struct mfcmd {
char *name; char *name;
char *argstring; char *argstring;
char *help; char *help;
int (*handler) (mfshell * mfshell, int argc, char *const argv[]); int (*handler) (mfshell * mfshell, int argc,
char *const argv[]);
}; };
struct mfshell { struct mfshell {

View File

@@ -136,8 +136,7 @@ void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts)
exit(1); exit(1);
} }
if (opts->password != NULL && if (opts->password != NULL && opts->username == NULL) {
opts->username == NULL) {
fprintf(stderr, "You cannot pass the password without the username\n"); fprintf(stderr, "You cannot pass the password without the username\n");
exit(1); exit(1);
} }

View File

@@ -20,17 +20,18 @@
#define _MFSHELL_OPTIONS_H_ #define _MFSHELL_OPTIONS_H_
struct mfshell_user_options { struct mfshell_user_options {
char *username; char *username;
char *password; char *password;
char *command; char *command;
char *server; char *server;
char *config; char *config;
int app_id; int app_id;
char *api_key; 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 #endif

View File

@@ -13,7 +13,6 @@ case $# in
;; ;;
esac esac
ret=0
find "$source_dir" -name "*.c" -o -name "*.h" | while read f; do find "$source_dir" -name "*.c" -o -name "*.h" | while read f; do
case $f in case $f in
${source_dir}/*/CMakeFiles/*) ${source_dir}/*/CMakeFiles/*)
@@ -21,10 +20,11 @@ find "$source_dir" -name "*.c" -o -name "*.h" | while read f; do
${source_dir}/CMakeFiles/*) ${source_dir}/CMakeFiles/*)
;; ;;
*) *)
INDENT_PROFILE="${source_dir}/.indent.pro" indent -st "$f" | diff -u "$f" - INDENT_PROFILE="${source_dir}/.indent.pro" indent -st "$f" | diff -u "$f" - >&2
ret=$((ret+$?)) ret=$((ret+$?))
echo $ret
;; ;;
esac esac
done | sort -n | tail --lines=1 | while read ret; do
exit $ret
done done
exit $ret