mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 21:24:28 -08:00
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:
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -27,46 +26,49 @@
|
||||
#include "mfshell.h"
|
||||
#include "../mfapi/folder.h"
|
||||
|
||||
struct mfcmd commands[] = {
|
||||
{"help", "", "show this help", mfshell_cmd_help},
|
||||
{"debug", "", "show debug information", mfshell_cmd_debug},
|
||||
{"host", "<server>", "change target server", mfshell_cmd_host},
|
||||
{"auth", "<user <pass>>", "authenticate with active server",
|
||||
mfshell_cmd_auth},
|
||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||
{"ls", "", "show contents of active folder",
|
||||
mfshell_cmd_list},
|
||||
{"cd", "[folderkey]", "change active folder", mfshell_cmd_chdir},
|
||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||
{"lpwd", "", "show the local working directory",
|
||||
mfshell_cmd_lpwd},
|
||||
{"lcd", "[dir]", "change the local working directory",
|
||||
mfshell_cmd_lcd},
|
||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||
{"links", "[quickkey]", "show access urls for the file",
|
||||
mfshell_cmd_links},
|
||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
struct mfcmd commands[] = {
|
||||
{"help", "", "show this help", mfshell_cmd_help},
|
||||
{"debug", "", "show debug information", mfshell_cmd_debug},
|
||||
{"host", "<server>", "change target server", mfshell_cmd_host},
|
||||
{"auth", "<user <pass>>", "authenticate with active server",
|
||||
mfshell_cmd_auth},
|
||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||
{"ls", "", "show contents of active folder",
|
||||
mfshell_cmd_list},
|
||||
{"cd", "[folderkey]", "change active folder", mfshell_cmd_chdir},
|
||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||
{"lpwd", "", "show the local working directory",
|
||||
mfshell_cmd_lpwd},
|
||||
{"lcd", "[dir]", "change the local working directory",
|
||||
mfshell_cmd_lcd},
|
||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||
{"links", "[quickkey]", "show access urls for the file",
|
||||
mfshell_cmd_links},
|
||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
mfshell*
|
||||
mfshell_create(int app_id,char *app_key,char *server)
|
||||
mfshell *mfshell_create(int app_id, char *app_key, char *server)
|
||||
{
|
||||
mfshell *shell;
|
||||
mfshell *shell;
|
||||
|
||||
if(app_id <= 0) return NULL;
|
||||
if(app_key == NULL) return NULL;
|
||||
if(server == NULL) return NULL;
|
||||
if (app_id <= 0)
|
||||
return NULL;
|
||||
if (app_key == NULL)
|
||||
return NULL;
|
||||
if (server == NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
check to see if the server contains a forward-slash. if so,
|
||||
the caller did not understand the API and passed in the wrong
|
||||
type of server resource.
|
||||
*/
|
||||
if(strchr(server,'/') != NULL) return NULL;
|
||||
check to see if the server contains a forward-slash. if so,
|
||||
the caller did not understand the API and passed in the wrong
|
||||
type of server resource.
|
||||
*/
|
||||
if (strchr(server, '/') != NULL)
|
||||
return NULL;
|
||||
|
||||
shell = (mfshell*)calloc(1,sizeof(mfshell));
|
||||
shell = (mfshell *) calloc(1, sizeof(mfshell));
|
||||
|
||||
shell->app_id = app_id;
|
||||
shell->app_key = strdup(app_key);
|
||||
@@ -74,7 +76,7 @@ mfshell_create(int app_id,char *app_key,char *server)
|
||||
|
||||
// object to track folder location
|
||||
shell->folder_curr = folder_alloc();
|
||||
folder_set_key(shell->folder_curr,"myfiles");
|
||||
folder_set_key(shell->folder_curr, "myfiles");
|
||||
|
||||
// shell commands
|
||||
shell->commands = commands;
|
||||
@@ -82,10 +84,10 @@ mfshell_create(int app_id,char *app_key,char *server)
|
||||
return shell;
|
||||
}
|
||||
|
||||
int
|
||||
mfshell_exec(mfshell *shell, int argc, char **argv)
|
||||
int mfshell_exec(mfshell * shell, int argc, char **argv)
|
||||
{
|
||||
mfcmd* curr_cmd;
|
||||
mfcmd *curr_cmd;
|
||||
|
||||
for (curr_cmd = shell->commands; curr_cmd->name != NULL; curr_cmd++) {
|
||||
if (strcmp(argv[0], curr_cmd->name) == 0) {
|
||||
return curr_cmd->handler(shell, argc, argv);
|
||||
@@ -94,24 +96,35 @@ mfshell_exec(mfshell *shell, int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
mfshell_exec_shell_command(mfshell *shell,char *command)
|
||||
int mfshell_exec_shell_command(mfshell * shell, char *command)
|
||||
{
|
||||
wordexp_t p;
|
||||
int retval;
|
||||
|
||||
if(shell == NULL) return -1;
|
||||
if(command == NULL) return -1;
|
||||
if (shell == NULL)
|
||||
return -1;
|
||||
if (command == NULL)
|
||||
return -1;
|
||||
|
||||
// FIXME: handle non-zero return value of wordexp
|
||||
retval = wordexp(command, &p, WRDE_SHOWERR | WRDE_UNDEF);
|
||||
if (retval != 0) {
|
||||
switch (retval) {
|
||||
case WRDE_BADCHAR: fprintf(stderr, "wordexp: WRDE_BADCHAR\n"); break;
|
||||
case WRDE_BADVAL: fprintf(stderr, "wordexp: WRDE_BADVAL\n"); break;
|
||||
case WRDE_CMDSUB: fprintf(stderr, "wordexp: WRDE_CMDSUB\n"); break;
|
||||
case WRDE_NOSPACE: fprintf(stderr, "wordexp: WRDE_NOSPACE\n"); break;
|
||||
case WRDE_SYNTAX: fprintf(stderr, "wordexp: WRDE_SYNTAX\n"); break;
|
||||
case WRDE_BADCHAR:
|
||||
fprintf(stderr, "wordexp: WRDE_BADCHAR\n");
|
||||
break;
|
||||
case WRDE_BADVAL:
|
||||
fprintf(stderr, "wordexp: WRDE_BADVAL\n");
|
||||
break;
|
||||
case WRDE_CMDSUB:
|
||||
fprintf(stderr, "wordexp: WRDE_CMDSUB\n");
|
||||
break;
|
||||
case WRDE_NOSPACE:
|
||||
fprintf(stderr, "wordexp: WRDE_NOSPACE\n");
|
||||
break;
|
||||
case WRDE_SYNTAX:
|
||||
fprintf(stderr, "wordexp: WRDE_SYNTAX\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,4 +141,3 @@ mfshell_exec_shell_command(mfshell *shell,char *command)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user