use gnu indent to enforce coding style and adapt source

- indent options are listed in ./.indent.pro
 - use test case to run indent
This commit is contained in:
josch
2014-09-20 10:59:54 +02:00
parent d8e00119b4
commit 097a855751
43 changed files with 1325 additions and 1278 deletions

View File

@@ -17,7 +17,6 @@
*
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,22 +26,21 @@
#include "../mfshell.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
static char*
_get_login_from_user(void);
static char *_get_login_from_user(void);
static char*
_get_passwd_from_user(void);
static char *_get_passwd_from_user(void);
int
mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_auth(mfshell * mfshell, int argc, char **argv)
{
char *username;
char *password;
char *username;
char *password;
if(mfshell == NULL) return -1;
if(mfshell->server == NULL) return -1;
if (mfshell == NULL)
return -1;
if (mfshell->server == NULL)
return -1;
switch (argc) {
case 1:
@@ -62,10 +60,11 @@ mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv)
return -1;
}
if(username == NULL || password == NULL) return -1;
if (username == NULL || password == NULL)
return -1;
mfshell->conn = mfconn_create(mfshell->server, username, password,
mfshell->app_id, mfshell->app_key);
mfshell->app_id, mfshell->app_key);
if (mfshell->conn != NULL)
printf("\n\rAuthentication SUCCESS\n\r");
@@ -75,39 +74,35 @@ mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv)
return (mfshell->conn != NULL);
}
char*
_get_login_from_user(void)
char *_get_login_from_user(void)
{
char *login = NULL;
size_t len;
ssize_t bytes_read;
char *login = NULL;
size_t len;
ssize_t bytes_read;
printf("login: ");
bytes_read = getline(&login,&len,stdin);
bytes_read = getline(&login, &len, stdin);
if(bytes_read < 3)
{
if(login != NULL)
{
if (bytes_read < 3) {
if (login != NULL) {
free(login);
login = NULL;
}
}
if (login[strlen(login)-1] == '\n')
login[strlen(login)-1] = '\0';
if (login[strlen(login) - 1] == '\n')
login[strlen(login) - 1] = '\0';
return login;
}
char*
_get_passwd_from_user(void)
char *_get_passwd_from_user(void)
{
char *passwd = NULL;
size_t len;
ssize_t bytes_read;
struct termios old, new;
char *passwd = NULL;
size_t len;
ssize_t bytes_read;
struct termios old,
new;
printf("passwd: ");
@@ -118,22 +113,19 @@ _get_passwd_from_user(void)
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new) != 0)
return NULL;
bytes_read = getline(&passwd,&len,stdin);
bytes_read = getline(&passwd, &len, stdin);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &old);
if(bytes_read < 3)
{
if(passwd != NULL)
{
if (bytes_read < 3) {
if (passwd != NULL) {
free(passwd);
passwd = NULL;
}
}
if (passwd[strlen(passwd)-1] == '\n')
passwd[strlen(passwd)-1] = '\0';
if (passwd[strlen(passwd) - 1] == '\n')
passwd[strlen(passwd) - 1] = '\0';
return passwd;
}

View File

@@ -17,7 +17,6 @@
*
*/
#include <stdio.h>
#include <string.h>
@@ -25,18 +24,18 @@
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_chdir(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_chdir(mfshell * mfshell, int argc, char **argv)
{
mffolder *folder_new;
const char *folder_curr;
const char *folder_parent;
const char *folderkey;
int retval;
mffolder *folder_new;
const char *folder_curr;
const char *folder_parent;
const char *folderkey;
int retval;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 2) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -44,67 +43,60 @@ mfshell_cmd_chdir(mfshell *mfshell, int argc, char **argv)
}
folderkey = argv[1];
if(folderkey == NULL) return -1;
if (folderkey == NULL)
return -1;
// change to root
if(strcmp(folderkey,"/") == 0) folderkey = "myfiles";
if (strcmp(folderkey, "/") == 0)
folderkey = "myfiles";
// user wants to navigate up a level
if(strcmp(folderkey,"..") == 0)
{
if (strcmp(folderkey, "..") == 0) {
// do several sanity checks to see if we're already at the root
folder_curr = folder_get_key(mfshell->folder_curr);
if(folder_curr == NULL) return 0;
if(strcmp(folder_curr,"myfiles") == 0) return 0;
if (folder_curr == NULL)
return 0;
if (strcmp(folder_curr, "myfiles") == 0)
return 0;
folder_parent = folder_get_parent(mfshell->folder_curr);
if(folder_parent == NULL) return 0;
if (folder_parent == NULL)
return 0;
// it's pretty sure that we're not at the root
folderkey = folder_parent;
}
// check the lenght of the key
if(strlen(folderkey) != 13)
{
if (strlen(folderkey) != 13) {
// as a folder moniker, "myfiles" is an exception
if(strcmp(folderkey,"myfiles") != 0) return -1;
if (strcmp(folderkey, "myfiles") != 0)
return -1;
}
// create a new folder object to store the results
folder_new = folder_alloc();
// navigate to root is a special case
if(strcmp(folderkey,"myfiles") == 0)
{
folder_set_key(folder_new,"myfiles");
if (strcmp(folderkey, "myfiles") == 0) {
folder_set_key(folder_new, "myfiles");
retval = 0;
}
else
{
} else {
retval = mfconn_api_folder_get_info(mfshell->conn,
folder_new,(char*)folderkey);
folder_new, (char *)folderkey);
mfconn_update_secret_key(mfshell->conn);
}
if(retval == 0)
{
if(mfshell->folder_curr != NULL)
{
if (retval == 0) {
if (mfshell->folder_curr != NULL) {
folder_free(mfshell->folder_curr);
mfshell->folder_curr = NULL;
}
mfshell->folder_curr = folder_new;
}
else
{
} else {
folder_free(folder_new);
}
return retval;
}

View File

@@ -17,17 +17,15 @@
*
*/
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include "../mfshell.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_debug(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_debug(mfshell * mfshell, int argc, char **argv)
{
(void)argv;
if (argc != 1) {
@@ -35,35 +33,21 @@ mfshell_cmd_debug(mfshell *mfshell, int argc, char **argv)
return -1;
}
printf(" %-15.15s %s\n\r",
"server:",
mfshell->server);
printf(" %-15.15s %s\n\r", "server:", mfshell->server);
const char *session_token = mfconn_get_session_token(mfshell->conn);
const char *secret_time = mfconn_get_secret_time(mfshell->conn);
uint32_t secret_key = mfconn_get_secret_key(mfshell->conn);
if(session_token != NULL && secret_time != NULL)
{
printf(" %-15.15s %"PRIu32"\n\r",
"secret key:",
secret_key);
const char *session_token = mfconn_get_session_token(mfshell->conn);
const char *secret_time = mfconn_get_secret_time(mfshell->conn);
uint32_t secret_key = mfconn_get_secret_key(mfshell->conn);
printf(" %-15.15s %s\n\r",
"secret time:",
secret_time);
if (session_token != NULL && secret_time != NULL) {
printf(" %-15.15s %" PRIu32 "\n\r", "secret key:", secret_key);
printf(" %-15.15s %s\n\r",
"status:",
"Authenticated");
}
else
{
printf(" %-15.15s %s\n\r",
"status:",
"Not authenticated");
printf(" %-15.15s %s\n\r", "secret time:", secret_time);
printf(" %-15.15s %s\n\r", "status:", "Authenticated");
} else {
printf(" %-15.15s %s\n\r", "status:", "Not authenticated");
}
return 0;
}

View File

@@ -17,7 +17,6 @@
*
*/
#include <stdio.h>
#include <string.h>
@@ -25,19 +24,19 @@
#include "../mfshell.h"
#include "../../mfapi/file.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_file(mfshell * mfshell, int argc, char **argv)
{
mffile *file;
int len;
int retval;
const char *quickkey;
const char *name;
const char *hash;
mffile *file;
int len;
int retval;
const char *quickkey;
const char *name;
const char *hash;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 2) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -45,15 +44,17 @@ mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)
}
quickkey = argv[1];
if(quickkey == NULL) return -1;
if (quickkey == NULL)
return -1;
len = strlen(quickkey);
if(len != 11 && len != 15) return -1;
if (len != 11 && len != 15)
return -1;
file = file_alloc();
retval = mfconn_api_file_get_info(mfshell->conn,file,(char*)quickkey);
retval = mfconn_api_file_get_info(mfshell->conn, file, (char *)quickkey);
if (retval != 0) {
fprintf(stderr, "api call unsuccessful\n");
}
@@ -63,20 +64,16 @@ mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)
name = file_get_name(file);
hash = file_get_hash(file);
if(name != NULL && name[0] != '\0')
printf(" %-15.15s %s\n\r",
"filename:", name);
if (name != NULL && name[0] != '\0')
printf(" %-15.15s %s\n\r", "filename:", name);
if(quickkey != NULL && quickkey[0] != '\0')
printf(" %-15.15s %s\n\r",
"quickkey:", quickkey);
if (quickkey != NULL && quickkey[0] != '\0')
printf(" %-15.15s %s\n\r", "quickkey:", quickkey);
if(hash != NULL && hash[0] != '\0')
printf(" %-15.15s %s\n\r",
"hash:", hash);
if (hash != NULL && hash[0] != '\0')
printf(" %-15.15s %s\n\r", "hash:", hash);
file_free(file);
return 0;
}

View File

@@ -17,7 +17,6 @@
*
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -28,18 +27,18 @@
#include "../mfshell.h"
#include "../../mfapi/file.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_get(mfshell * mfshell, int argc, char **argv)
{
mffile *file;
int len;
int retval;
ssize_t bytes_read;
const char *quickkey;
mffile *file;
int len;
int retval;
ssize_t bytes_read;
const char *quickkey;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 2) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -47,45 +46,42 @@ mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)
}
quickkey = argv[1];
if(quickkey == NULL) return -1;
if (quickkey == NULL)
return -1;
len = strlen(quickkey);
if(len != 11 && len != 15) return -1;
if (len != 11 && len != 15)
return -1;
file = file_alloc();
// get file name
retval = mfconn_api_file_get_info(mfshell->conn,file,(char*)quickkey);
retval = mfconn_api_file_get_info(mfshell->conn, file, (char *)quickkey);
mfconn_update_secret_key(mfshell->conn);
if(retval == -1)
{
if (retval == -1) {
file_free(file);
return -1;
}
// request a direct download (streaming) link
retval = mfconn_api_file_get_links(mfshell->conn,file,(char*)quickkey);
retval = mfconn_api_file_get_links(mfshell->conn, file, (char *)quickkey);
mfconn_update_secret_key(mfshell->conn);
if(retval == -1)
{
if (retval == -1) {
file_free(file);
return -1;
}
// make sure we have a valid working directory to download to
if(mfshell->local_working_dir == NULL)
{
mfshell->local_working_dir = (char*)calloc(PATH_MAX + 1,sizeof(char));
getcwd(mfshell->local_working_dir,PATH_MAX);
if (mfshell->local_working_dir == NULL) {
mfshell->local_working_dir = (char *)calloc(PATH_MAX + 1, sizeof(char));
getcwd(mfshell->local_working_dir, PATH_MAX);
}
bytes_read = file_download_direct(file, mfshell->local_working_dir);
if(bytes_read != -1)
printf("\r Downloaded %zd bytes OK!\n\r",bytes_read);
if (bytes_read != -1)
printf("\r Downloaded %zd bytes OK!\n\r", bytes_read);
else
printf("\r\n Download FAILED!\n\r");
@@ -93,4 +89,3 @@ mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)
return 0;
}

View File

@@ -17,33 +17,29 @@
*
*/
#include <stdio.h>
#include <string.h>
#include "../mfshell.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_help(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_help(mfshell * mfshell, int argc, char **argv)
{
(void)argv;
unsigned int column1_width = 0;
unsigned int column2_width = 0;
mfcmd *curr_cmd;
if (argc != 1) {
fprintf(stderr, "Invalid number of arguments\n");
return -1;
}
printf(
" arguments:\n\r"
" <optional>\n\r"
" [required]\n\r");
printf(" arguments:\n\r"
" <optional>\n\r" " [required]\n\r");
printf("\n\r");
unsigned int column1_width = 0;
unsigned int column2_width = 0;
mfcmd* curr_cmd;
for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) {
if (strlen(curr_cmd->name) > column1_width)
column1_width = strlen(curr_cmd->name);
@@ -52,10 +48,9 @@ mfshell_cmd_help(mfshell *mfshell, int argc, char **argv)
}
for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) {
printf("%*s %*s %s\n", column1_width, curr_cmd->name, column2_width, curr_cmd->argstring, curr_cmd->help);
printf("%*s %*s %s\n", column1_width, curr_cmd->name,
column2_width, curr_cmd->argstring, curr_cmd->help);
}
return 0;
}

View File

@@ -17,7 +17,6 @@
*
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,16 +24,14 @@
#include "../mfshell.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
static char*
_get_host_from_user(void);
static char *_get_host_from_user(void);
int
mfshell_cmd_host(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_host(mfshell * mfshell, int argc, char **argv)
{
char *alt_host = NULL;
char *host;
char *alt_host = NULL;
char *host;
switch (argc) {
case 1:
@@ -49,17 +46,15 @@ mfshell_cmd_host(mfshell *mfshell, int argc, char **argv)
return -1;
}
if(mfshell->server != NULL)
{
if (mfshell->server != NULL) {
// do nothing if the server is exactly the same
if(strcmp(mfshell->server,host) == 0)
{
if(alt_host != NULL) free(alt_host);
if (strcmp(mfshell->server, host) == 0) {
if (alt_host != NULL)
free(alt_host);
return 0;
}
if(mfshell->server != NULL)
{
if (mfshell->server != NULL) {
free(mfshell->server);
mfshell->server = NULL;
}
@@ -69,27 +64,26 @@ mfshell_cmd_host(mfshell *mfshell, int argc, char **argv)
mfconn_destroy(mfshell->conn);
if(alt_host != NULL) free(alt_host);
if (alt_host != NULL)
free(alt_host);
return 0;
}
char*
_get_host_from_user(void)
char *_get_host_from_user(void)
{
size_t len = 0;
char *host = NULL;
size_t len = 0;
char *host = NULL;
printf("host: [www.mediafire.com] ");
getline(&host,&len,stdin);
if (host[strlen(host)-1] == '\n')
host[strlen(host)-1] = '\0';
getline(&host, &len, stdin);
if (host[strlen(host) - 1] == '\n')
host[strlen(host) - 1] = '\0';
if(host == NULL)
if (host == NULL)
return strdup("www.mediafire.com");
if(strlen(host) < 2)
{
if (strlen(host) < 2) {
free(host);
return strdup("www.mediafire.com");
}

View File

@@ -17,22 +17,21 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../mfshell.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_lcd(mfshell * mfshell, int argc, char **argv)
{
int retval;
const char *dir;
int retval;
const char *dir;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 2) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -40,15 +39,15 @@ mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)
}
dir = argv[1];
if(dir == NULL) return -1;
if (dir == NULL)
return -1;
if(strlen(dir) < 1) return -1;
if (strlen(dir) < 1)
return -1;
retval = chdir(dir);
if(retval == 0)
{
if(mfshell->local_working_dir != NULL)
{
if (retval == 0) {
if (mfshell->local_working_dir != NULL) {
free(mfshell->local_working_dir);
mfshell->local_working_dir = NULL;
}
@@ -58,4 +57,3 @@ mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)
return retval;
}

View File

@@ -17,7 +17,6 @@
*
*/
#include <stdio.h>
#include <string.h>
@@ -25,20 +24,20 @@
#include "../mfshell.h"
#include "../../mfapi/file.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_links(mfshell * mfshell, int argc, char **argv)
{
mffile *file;
int len;
int retval;
const char *quickkey;
const char *share_link;
const char *direct_link;
const char *onetime_link;
mffile *file;
int len;
int retval;
const char *quickkey;
const char *share_link;
const char *direct_link;
const char *onetime_link;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 2) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -46,15 +45,17 @@ mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)
}
quickkey = argv[1];
if(quickkey == NULL) return -1;
if (quickkey == NULL)
return -1;
len = strlen(quickkey);
if(len != 11 && len != 15) return -1;
if (len != 11 && len != 15)
return -1;
file = file_alloc();
retval = mfconn_api_file_get_links(mfshell->conn,file,(char*)quickkey);
retval = mfconn_api_file_get_links(mfshell->conn, file, (char *)quickkey);
if (retval != 0) {
fprintf(stderr, "api call unsuccessful\n");
}
@@ -64,20 +65,16 @@ mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)
direct_link = file_get_direct_link(file);
onetime_link = file_get_onetime_link(file);
if(share_link != NULL && share_link[0] != '\0')
printf(" %-15.15s %s\n\r",
"sharing url:", share_link);
if (share_link != NULL && share_link[0] != '\0')
printf(" %-15.15s %s\n\r", "sharing url:", share_link);
if(direct_link != NULL && direct_link[0] != '\0')
printf(" %-15.15s %s\n\r",
"direct url:", direct_link);
if (direct_link != NULL && direct_link[0] != '\0')
printf(" %-15.15s %s\n\r", "direct url:", direct_link);
if(onetime_link != NULL && onetime_link[0] != '\0')
printf(" %-15.15s %s\n\r",
"1-time url:", onetime_link);
if (onetime_link != NULL && onetime_link[0] != '\0')
printf(" %-15.15s %s\n\r", "1-time url:", onetime_link);
file_free(file);
return 0;
}

View File

@@ -17,23 +17,22 @@
*
*/
#include <stdio.h>
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_list(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_list(mfshell * mfshell, int argc, char **argv)
{
(void)argv;
int retval;
const char *folder_curr;
int retval;
const char *folder_curr;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 1) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -43,22 +42,22 @@ mfshell_cmd_list(mfshell *mfshell, int argc, char **argv)
folder_curr = folder_get_key(mfshell->folder_curr);
// safety check... this should never happen
if(folder_curr == NULL)
folder_set_key(mfshell->folder_curr,"myfiles");
if (folder_curr == NULL)
folder_set_key(mfshell->folder_curr, "myfiles");
// safety check... this should never happen
if(folder_curr[0] == '\0')
folder_set_key(mfshell->folder_curr,"myfiles");
if (folder_curr[0] == '\0')
folder_set_key(mfshell->folder_curr, "myfiles");
// first folders
retval = mfconn_api_folder_get_content(mfshell->conn, 0, mfshell->folder_curr);
retval =
mfconn_api_folder_get_content(mfshell->conn, 0, mfshell->folder_curr);
mfconn_update_secret_key(mfshell->conn);
// then files
retval = mfconn_api_folder_get_content(mfshell->conn, 1, mfshell->folder_curr);
retval =
mfconn_api_folder_get_content(mfshell->conn, 1, mfshell->folder_curr);
mfconn_update_secret_key(mfshell->conn);
return retval;
}

View File

@@ -17,34 +17,31 @@
*
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../mfshell.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_lpwd(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_lpwd(mfshell * mfshell, int argc, char **argv)
{
(void)argv;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 1) {
fprintf(stderr, "Invalid number of argumens\n");
return -1;
}
if(mfshell->local_working_dir == NULL)
{
mfshell->local_working_dir = (char*)calloc(PATH_MAX + 1,sizeof(char));
getcwd(mfshell->local_working_dir,PATH_MAX);
if (mfshell->local_working_dir == NULL) {
mfshell->local_working_dir = (char *)calloc(PATH_MAX + 1, sizeof(char));
getcwd(mfshell->local_working_dir, PATH_MAX);
}
printf("%s\n\r", mfshell->local_working_dir);
return 0;
}

View File

@@ -17,23 +17,22 @@
*
*/
#include <stdio.h>
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_mkdir(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char **argv)
{
int retval;
const char *folder_curr;
const char *name;
int retval;
const char *folder_curr;
const char *name;
if(mfshell == NULL) return -1;
if (mfshell == NULL)
return -1;
if (argc != 2) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -41,24 +40,25 @@ mfshell_cmd_mkdir(mfshell *mfshell, int argc, char **argv)
}
name = argv[1];
if (name == NULL) return -1;
if (name == NULL)
return -1;
folder_curr = folder_get_key(mfshell->folder_curr);
// safety check... this should never happen
if(folder_curr == NULL)
folder_set_key(mfshell->folder_curr,"myfiles");
if (folder_curr == NULL)
folder_set_key(mfshell->folder_curr, "myfiles");
// safety check... this should never happen
if(folder_curr[0] == '\0')
folder_set_key(mfshell->folder_curr,"myfiles");
if (folder_curr[0] == '\0')
folder_set_key(mfshell->folder_curr, "myfiles");
folder_curr = folder_get_key(mfshell->folder_curr);
retval = mfconn_api_folder_create(mfshell->conn,(char*)folder_curr,(char*)name);
retval =
mfconn_api_folder_create(mfshell->conn, (char *)folder_curr,
(char *)name);
mfconn_update_secret_key(mfshell->conn);
return retval;
}

View File

@@ -17,24 +17,24 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "../../utils/strings.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_pwd(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_pwd(mfshell * mfshell, int argc, char **argv)
{
(void)argv;
const char *folder_name;
char *folder_name_tmp = NULL;
const char *folder_name;
char *folder_name_tmp = NULL;
if(mfshell == NULL) return -1;
if(mfshell->folder_curr == NULL) return -1;
if (mfshell == NULL)
return -1;
if (mfshell->folder_curr == NULL)
return -1;
if (argc != 1) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -42,16 +42,15 @@ mfshell_cmd_pwd(mfshell *mfshell, int argc, char **argv)
}
folder_name = folder_get_name(mfshell->folder_curr);
if(folder_name[0] == '\0') return -1;
if (folder_name[0] == '\0')
return -1;
folder_name_tmp = strdup_printf("< %s >",folder_name);
folder_name_tmp = strdup_printf("< %s >", folder_name);
printf("%-15.13s %-50.50s\n\r",
folder_get_key(mfshell->folder_curr),
folder_name_tmp);
folder_get_key(mfshell->folder_curr), folder_name_tmp);
free(folder_name_tmp);
return 0;
}

View File

@@ -17,19 +17,17 @@
*
*/
#include <stdio.h>
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_whoami(mfshell *mfshell, int argc, char **argv)
int mfshell_cmd_whoami(mfshell * mfshell, int argc, char **argv)
{
(void)argv;
int retval;
int retval;
if (argc != 1) {
fprintf(stderr, "Invalid number of arguments\n");
@@ -41,5 +39,3 @@ mfshell_cmd_whoami(mfshell *mfshell, int argc, char **argv)
return retval;
}