Commit f05166a6 authored by Eric Wong's avatar Eric Wong

command.c: shorten common variable names to argc and argv

Any C programmer with half a clue knows they mean argArrayLength and argArray, and I find the code much easier to read and work with. git-svn-id: https://svn.musicpd.org/mpd/trunk@4480 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 49d580b9
...@@ -158,20 +158,20 @@ static void addCommand(char *name, ...@@ -158,20 +158,20 @@ static void addCommand(char *name,
insertInList(commandList, cmd->cmd, cmd); insertInList(commandList, cmd->cmd, cmd);
} }
static int handleUrlHandlers(FILE * fp, int *permission, int argArrayLength, static int handleUrlHandlers(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return printRemoteUrlHandlers(fp); return printRemoteUrlHandlers(fp);
} }
static int handlePlay(FILE * fp, int *permission, int argArrayLength, static int handlePlay(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int song = -1; int song = -1;
char *test; char *test;
if (argArrayLength == 2) { if (argc == 2) {
song = strtol(argArray[1], &test, 10); song = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"need a positive integer", NULL); "need a positive integer", NULL);
...@@ -181,14 +181,14 @@ static int handlePlay(FILE * fp, int *permission, int argArrayLength, ...@@ -181,14 +181,14 @@ static int handlePlay(FILE * fp, int *permission, int argArrayLength,
return playPlaylist(fp, song, 0); return playPlaylist(fp, song, 0);
} }
static int handlePlayId(FILE * fp, int *permission, int argArrayLength, static int handlePlayId(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int id = -1; int id = -1;
char *test; char *test;
if (argArrayLength == 2) { if (argc == 2) {
id = strtol(argArray[1], &test, 10); id = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"need a positive integer", NULL); "need a positive integer", NULL);
...@@ -198,14 +198,14 @@ static int handlePlayId(FILE * fp, int *permission, int argArrayLength, ...@@ -198,14 +198,14 @@ static int handlePlayId(FILE * fp, int *permission, int argArrayLength,
return playPlaylistById(fp, id, 0); return playPlaylistById(fp, id, 0);
} }
static int handleStop(FILE * fp, int *permission, int argArrayLength, static int handleStop(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return stopPlaylist(fp); return stopPlaylist(fp);
} }
static int handleCurrentSong(FILE * fp, int *permission, int argArrayLength, static int handleCurrentSong(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int song = getPlaylistCurrentSong(); int song = getPlaylistCurrentSong();
...@@ -216,14 +216,14 @@ static int handleCurrentSong(FILE * fp, int *permission, int argArrayLength, ...@@ -216,14 +216,14 @@ static int handleCurrentSong(FILE * fp, int *permission, int argArrayLength,
} }
static int handlePause(FILE * fp, int *permission, static int handlePause(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
if (argArrayLength == 2) { if (argc == 2) {
char *test; char *test;
int pause = strtol(argArray[1], &test, 10); int pause = strtol(argv[1], &test, 10);
if (*test != '\0' || (pause != 0 && pause != 1)) { if (*test != '\0' || (pause != 0 && pause != 1)) {
commandError(fp, ACK_ERROR_ARG, "\"%s\" is not 0 or 1", commandError(fp, ACK_ERROR_ARG, "\"%s\" is not 0 or 1",
argArray[1]); argv[1]);
return -1; return -1;
} }
return playerSetPause(fp, pause); return playerSetPause(fp, pause);
...@@ -231,8 +231,8 @@ static int handlePause(FILE * fp, int *permission, ...@@ -231,8 +231,8 @@ static int handlePause(FILE * fp, int *permission,
return playerPause(fp); return playerPause(fp);
} }
static int commandStatus(FILE * fp, int *permission, int argArrayLength, static int commandStatus(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
char *state = NULL; char *state = NULL;
int updateJobId; int updateJobId;
...@@ -295,22 +295,22 @@ static int commandStatus(FILE * fp, int *permission, int argArrayLength, ...@@ -295,22 +295,22 @@ static int commandStatus(FILE * fp, int *permission, int argArrayLength,
return 0; return 0;
} }
static int handleKill(FILE * fp, int *permission, int argArrayLength, static int handleKill(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return COMMAND_RETURN_KILL; return COMMAND_RETURN_KILL;
} }
static int handleClose(FILE * fp, int *permission, int argArrayLength, static int handleClose(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return COMMAND_RETURN_CLOSE; return COMMAND_RETURN_CLOSE;
} }
static int handleAdd(FILE * fp, int *permission, int argArrayLength, static int handleAdd(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
char *path = argArray[1]; char *path = argv[1];
if (isRemoteUrl(path)) if (isRemoteUrl(path))
return addToPlaylist(fp, path, 0); return addToPlaylist(fp, path, 0);
...@@ -318,19 +318,19 @@ static int handleAdd(FILE * fp, int *permission, int argArrayLength, ...@@ -318,19 +318,19 @@ static int handleAdd(FILE * fp, int *permission, int argArrayLength,
return addAllIn(fp, path); return addAllIn(fp, path);
} }
static int handleAddId(FILE * fp, int *permission, int argArrayLength, static int handleAddId(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return addToPlaylist(fp, argArray[1], 1); return addToPlaylist(fp, argv[1], 1);
} }
static int handleDelete(FILE * fp, int *permission, int argArrayLength, static int handleDelete(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int song; int song;
char *test; char *test;
song = strtol(argArray[1], &test, 10); song = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"need a positive integer", NULL); "need a positive integer", NULL);
...@@ -339,13 +339,13 @@ static int handleDelete(FILE * fp, int *permission, int argArrayLength, ...@@ -339,13 +339,13 @@ static int handleDelete(FILE * fp, int *permission, int argArrayLength,
return deleteFromPlaylist(fp, song); return deleteFromPlaylist(fp, song);
} }
static int handleDeleteId(FILE * fp, int *permission, int argArrayLength, static int handleDeleteId(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int id; int id;
char *test; char *test;
id = strtol(argArray[1], &test, 10); id = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"need a positive integer", NULL); "need a positive integer", NULL);
...@@ -354,77 +354,77 @@ static int handleDeleteId(FILE * fp, int *permission, int argArrayLength, ...@@ -354,77 +354,77 @@ static int handleDeleteId(FILE * fp, int *permission, int argArrayLength,
return deleteFromPlaylistById(fp, id); return deleteFromPlaylistById(fp, id);
} }
static int handlePlaylist(FILE * fp, int *permission, int argArrayLength, static int handlePlaylist(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return showPlaylist(fp); return showPlaylist(fp);
} }
static int handleShuffle(FILE * fp, int *permission, int argArrayLength, static int handleShuffle(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return shufflePlaylist(fp); return shufflePlaylist(fp);
} }
static int handleClear(FILE * fp, int *permission, int argArrayLength, static int handleClear(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return clearPlaylist(fp); return clearPlaylist(fp);
} }
static int handleSave(FILE * fp, int *permission, int argArrayLength, static int handleSave(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return savePlaylist(fp, argArray[1]); return savePlaylist(fp, argv[1]);
} }
static int handleLoad(FILE * fp, int *permission, int argArrayLength, static int handleLoad(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return loadPlaylist(fp, argArray[1]); return loadPlaylist(fp, argv[1]);
} }
static int handleListPlaylist(FILE * fp, int *permission, int argArrayLength, static int handleListPlaylist(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return PlaylistInfo(fp, argArray[1], 0); return PlaylistInfo(fp, argv[1], 0);
} }
static int handleListPlaylistInfo(FILE * fp, int *permission, static int handleListPlaylistInfo(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
return PlaylistInfo(fp, argArray[1], 1); return PlaylistInfo(fp, argv[1], 1);
} }
static int handleLsInfo(FILE * fp, int *permission, int argArrayLength, static int handleLsInfo(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
if (argArrayLength == 1) { if (argc == 1) {
if (printDirectoryInfo(fp, NULL) < 0) if (printDirectoryInfo(fp, NULL) < 0)
return -1; return -1;
else else
return lsPlaylists(fp, ""); return lsPlaylists(fp, "");
} else { } else {
if (printDirectoryInfo(fp, argArray[1]) < 0) if (printDirectoryInfo(fp, argv[1]) < 0)
return -1; return -1;
else else
return lsPlaylists(fp, argArray[1]); return lsPlaylists(fp, argv[1]);
} }
} }
static int handleRm(FILE * fp, int *permission, int argArrayLength, static int handleRm(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return deletePlaylist(fp, argArray[1]); return deletePlaylist(fp, argv[1]);
} }
static int handlePlaylistChanges(FILE * fp, int *permission, static int handlePlaylistChanges(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
unsigned long version; unsigned long version;
char *test; char *test;
version = strtoul(argArray[1], &test, 10); version = strtoul(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "need a positive integer", commandError(fp, ACK_ERROR_ARG, "need a positive integer",
NULL); NULL);
...@@ -434,12 +434,12 @@ static int handlePlaylistChanges(FILE * fp, int *permission, ...@@ -434,12 +434,12 @@ static int handlePlaylistChanges(FILE * fp, int *permission,
} }
static int handlePlaylistChangesPosId(FILE * fp, int *permission, static int handlePlaylistChangesPosId(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
unsigned long version; unsigned long version;
char *test; char *test;
version = strtoul(argArray[1], &test, 10); version = strtoul(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "need a positive integer", commandError(fp, ACK_ERROR_ARG, "need a positive integer",
NULL); NULL);
...@@ -449,13 +449,13 @@ static int handlePlaylistChangesPosId(FILE * fp, int *permission, ...@@ -449,13 +449,13 @@ static int handlePlaylistChangesPosId(FILE * fp, int *permission,
} }
static int handlePlaylistInfo(FILE * fp, int *permission, static int handlePlaylistInfo(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
int song = -1; int song = -1;
char *test; char *test;
if (argArrayLength == 2) { if (argc == 2) {
song = strtol(argArray[1], &test, 10); song = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"need a positive integer", NULL); "need a positive integer", NULL);
...@@ -466,13 +466,13 @@ static int handlePlaylistInfo(FILE * fp, int *permission, ...@@ -466,13 +466,13 @@ static int handlePlaylistInfo(FILE * fp, int *permission,
} }
static int handlePlaylistId(FILE * fp, int *permission, static int handlePlaylistId(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
int id = -1; int id = -1;
char *test; char *test;
if (argArrayLength == 2) { if (argc == 2) {
id = strtol(argArray[1], &test, 10); id = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"need a positive integer", NULL); "need a positive integer", NULL);
...@@ -482,14 +482,14 @@ static int handlePlaylistId(FILE * fp, int *permission, ...@@ -482,14 +482,14 @@ static int handlePlaylistId(FILE * fp, int *permission,
return playlistId(fp, id); return playlistId(fp, id);
} }
static int handleFind(FILE * fp, int *permission, int argArrayLength, static int handleFind(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int ret; int ret;
LocateTagItem *items; LocateTagItem *items;
int numItems = newLocateTagItemArrayFromArgArray(argArray + 1, int numItems = newLocateTagItemArrayFromArgArray(argv + 1,
argArrayLength - 1, argc - 1,
&items); &items);
if (numItems <= 0) { if (numItems <= 0) {
...@@ -504,14 +504,14 @@ static int handleFind(FILE * fp, int *permission, int argArrayLength, ...@@ -504,14 +504,14 @@ static int handleFind(FILE * fp, int *permission, int argArrayLength,
return ret; return ret;
} }
static int handleSearch(FILE * fp, int *permission, int argArrayLength, static int handleSearch(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int ret; int ret;
LocateTagItem *items; LocateTagItem *items;
int numItems = newLocateTagItemArrayFromArgArray(argArray + 1, int numItems = newLocateTagItemArrayFromArgArray(argv + 1,
argArrayLength - 1, argc - 1,
&items); &items);
if (numItems <= 0) { if (numItems <= 0) {
...@@ -528,8 +528,8 @@ static int handleSearch(FILE * fp, int *permission, int argArrayLength, ...@@ -528,8 +528,8 @@ static int handleSearch(FILE * fp, int *permission, int argArrayLength,
static int listHandleUpdate(FILE * fp, static int listHandleUpdate(FILE * fp,
int *permission, int *permission,
int argArrayLength, int argc,
char **argArray, char **argv,
ListNode * commandNode, CommandEntry * cmd) ListNode * commandNode, CommandEntry * cmd)
{ {
static List *pathList = NULL; static List *pathList = NULL;
...@@ -539,8 +539,8 @@ static int listHandleUpdate(FILE * fp, ...@@ -539,8 +539,8 @@ static int listHandleUpdate(FILE * fp,
if (!pathList) if (!pathList)
pathList = makeList(NULL, 1); pathList = makeList(NULL, 1);
if (argArrayLength == 2) if (argc == 2)
insertInList(pathList, argArray[1], NULL); insertInList(pathList, argv[1], NULL);
else else
insertInList(pathList, "", NULL); insertInList(pathList, "", NULL);
...@@ -559,13 +559,13 @@ static int listHandleUpdate(FILE * fp, ...@@ -559,13 +559,13 @@ static int listHandleUpdate(FILE * fp,
return 0; return 0;
} }
static int handleUpdate(FILE * fp, int *permission, int argArrayLength, static int handleUpdate(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
if (argArrayLength == 2) { if (argc == 2) {
int ret; int ret;
List *pathList = makeList(NULL, 1); List *pathList = makeList(NULL, 1);
insertInList(pathList, argArray[1], NULL); insertInList(pathList, argv[1], NULL);
ret = updateInit(fp, pathList); ret = updateInit(fp, pathList);
freeList(pathList); freeList(pathList);
return ret; return ret;
...@@ -573,35 +573,35 @@ static int handleUpdate(FILE * fp, int *permission, int argArrayLength, ...@@ -573,35 +573,35 @@ static int handleUpdate(FILE * fp, int *permission, int argArrayLength,
return updateInit(fp, NULL); return updateInit(fp, NULL);
} }
static int handleNext(FILE * fp, int *permission, int argArrayLength, static int handleNext(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return nextSongInPlaylist(fp); return nextSongInPlaylist(fp);
} }
static int handlePrevious(FILE * fp, int *permission, int argArrayLength, static int handlePrevious(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return previousSongInPlaylist(fp); return previousSongInPlaylist(fp);
} }
static int handleListAll(FILE * fp, int *permission, int argArrayLength, static int handleListAll(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
char *directory = NULL; char *directory = NULL;
if (argArrayLength == 2) if (argc == 2)
directory = argArray[1]; directory = argv[1];
return printAllIn(fp, directory); return printAllIn(fp, directory);
} }
static int handleVolume(FILE * fp, int *permission, int argArrayLength, static int handleVolume(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int change; int change;
char *test; char *test;
change = strtol(argArray[1], &test, 10); change = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "need an integer", NULL); commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1; return -1;
...@@ -609,13 +609,13 @@ static int handleVolume(FILE * fp, int *permission, int argArrayLength, ...@@ -609,13 +609,13 @@ static int handleVolume(FILE * fp, int *permission, int argArrayLength,
return changeVolumeLevel(fp, change, 1); return changeVolumeLevel(fp, change, 1);
} }
static int handleSetVol(FILE * fp, int *permission, int argArrayLength, static int handleSetVol(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int level; int level;
char *test; char *test;
level = strtol(argArray[1], &test, 10); level = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "need an integer", NULL); commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1; return -1;
...@@ -623,13 +623,13 @@ static int handleSetVol(FILE * fp, int *permission, int argArrayLength, ...@@ -623,13 +623,13 @@ static int handleSetVol(FILE * fp, int *permission, int argArrayLength,
return changeVolumeLevel(fp, level, 0); return changeVolumeLevel(fp, level, 0);
} }
static int handleRepeat(FILE * fp, int *permission, int argArrayLength, static int handleRepeat(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int status; int status;
char *test; char *test;
status = strtol(argArray[1], &test, 10); status = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "need an integer", NULL); commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1; return -1;
...@@ -637,13 +637,13 @@ static int handleRepeat(FILE * fp, int *permission, int argArrayLength, ...@@ -637,13 +637,13 @@ static int handleRepeat(FILE * fp, int *permission, int argArrayLength,
return setPlaylistRepeatStatus(fp, status); return setPlaylistRepeatStatus(fp, status);
} }
static int handleRandom(FILE * fp, int *permission, int argArrayLength, static int handleRandom(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int status; int status;
char *test; char *test;
status = strtol(argArray[1], &test, 10); status = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "need an integer", NULL); commandError(fp, ACK_ERROR_ARG, "need an integer", NULL);
return -1; return -1;
...@@ -651,35 +651,35 @@ static int handleRandom(FILE * fp, int *permission, int argArrayLength, ...@@ -651,35 +651,35 @@ static int handleRandom(FILE * fp, int *permission, int argArrayLength,
return setPlaylistRandomStatus(fp, status); return setPlaylistRandomStatus(fp, status);
} }
static int handleStats(FILE * fp, int *permission, int argArrayLength, static int handleStats(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return printStats(fp); return printStats(fp);
} }
static int handleClearError(FILE * fp, int *permission, int argArrayLength, static int handleClearError(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
clearPlayerError(); clearPlayerError();
return 0; return 0;
} }
static int handleList(FILE * fp, int *permission, int argArrayLength, static int handleList(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int numConditionals = 0; int numConditionals = 0;
LocateTagItem *conditionals = NULL; LocateTagItem *conditionals = NULL;
int tagType = getLocateTagItemType(argArray[1]); int tagType = getLocateTagItemType(argv[1]);
int ret; int ret;
if (tagType < 0) { if (tagType < 0) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not known", argArray[1]); "\"%s\" is not known", argv[1]);
return -1; return -1;
} }
/* for compatibility with < 0.12.0 */ /* for compatibility with < 0.12.0 */
if (argArrayLength == 3) { if (argc == 3) {
if (tagType != TAG_ITEM_ALBUM) { if (tagType != TAG_ITEM_ALBUM) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"should be \"%s\" for 3 arguments", "should be \"%s\" for 3 arguments",
...@@ -687,12 +687,12 @@ static int handleList(FILE * fp, int *permission, int argArrayLength, ...@@ -687,12 +687,12 @@ static int handleList(FILE * fp, int *permission, int argArrayLength,
return -1; return -1;
} }
conditionals = newLocateTagItem(mpdTagItemKeys[TAG_ITEM_ARTIST], conditionals = newLocateTagItem(mpdTagItemKeys[TAG_ITEM_ARTIST],
argArray[2]); argv[2]);
numConditionals = 1; numConditionals = 1;
} else { } else {
numConditionals = numConditionals =
newLocateTagItemArrayFromArgArray(argArray + 2, newLocateTagItemArrayFromArgArray(argv + 2,
argArrayLength - 2, argc - 2,
&conditionals); &conditionals);
if (numConditionals < 0) { if (numConditionals < 0) {
...@@ -710,158 +710,158 @@ static int handleList(FILE * fp, int *permission, int argArrayLength, ...@@ -710,158 +710,158 @@ static int handleList(FILE * fp, int *permission, int argArrayLength,
return ret; return ret;
} }
static int handleMove(FILE * fp, int *permission, int argArrayLength, static int handleMove(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int from; int from;
int to; int to;
char *test; char *test;
from = strtol(argArray[1], &test, 10); from = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[1]); "\"%s\" is not a integer", argv[1]);
return -1; return -1;
} }
to = strtol(argArray[2], &test, 10); to = strtol(argv[2], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[2]); "\"%s\" is not a integer", argv[2]);
return -1; return -1;
} }
return moveSongInPlaylist(fp, from, to); return moveSongInPlaylist(fp, from, to);
} }
static int handleMoveId(FILE * fp, int *permission, int argArrayLength, static int handleMoveId(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int id; int id;
int to; int to;
char *test; char *test;
id = strtol(argArray[1], &test, 10); id = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[1]); "\"%s\" is not a integer", argv[1]);
return -1; return -1;
} }
to = strtol(argArray[2], &test, 10); to = strtol(argv[2], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[2]); "\"%s\" is not a integer", argv[2]);
return -1; return -1;
} }
return moveSongInPlaylistById(fp, id, to); return moveSongInPlaylistById(fp, id, to);
} }
static int handleSwap(FILE * fp, int *permission, int argArrayLength, static int handleSwap(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int song1; int song1;
int song2; int song2;
char *test; char *test;
song1 = strtol(argArray[1], &test, 10); song1 = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[1]); "\"%s\" is not a integer", argv[1]);
return -1; return -1;
} }
song2 = strtol(argArray[2], &test, 10); song2 = strtol(argv[2], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "\"%s\" is not a integer", commandError(fp, ACK_ERROR_ARG, "\"%s\" is not a integer",
argArray[2]); argv[2]);
return -1; return -1;
} }
return swapSongsInPlaylist(fp, song1, song2); return swapSongsInPlaylist(fp, song1, song2);
} }
static int handleSwapId(FILE * fp, int *permission, int argArrayLength, static int handleSwapId(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int id1; int id1;
int id2; int id2;
char *test; char *test;
id1 = strtol(argArray[1], &test, 10); id1 = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[1]); "\"%s\" is not a integer", argv[1]);
return -1; return -1;
} }
id2 = strtol(argArray[2], &test, 10); id2 = strtol(argv[2], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, "\"%s\" is not a integer", commandError(fp, ACK_ERROR_ARG, "\"%s\" is not a integer",
argArray[2]); argv[2]);
return -1; return -1;
} }
return swapSongsInPlaylistById(fp, id1, id2); return swapSongsInPlaylistById(fp, id1, id2);
} }
static int handleSeek(FILE * fp, int *permission, int argArrayLength, static int handleSeek(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int song; int song;
int time; int time;
char *test; char *test;
song = strtol(argArray[1], &test, 10); song = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[1]); "\"%s\" is not a integer", argv[1]);
return -1; return -1;
} }
time = strtol(argArray[2], &test, 10); time = strtol(argv[2], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[2]); "\"%s\" is not a integer", argv[2]);
return -1; return -1;
} }
return seekSongInPlaylist(fp, song, time); return seekSongInPlaylist(fp, song, time);
} }
static int handleSeekId(FILE * fp, int *permission, int argArrayLength, static int handleSeekId(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int id; int id;
int time; int time;
char *test; char *test;
id = strtol(argArray[1], &test, 10); id = strtol(argv[1], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[1]); "\"%s\" is not a integer", argv[1]);
return -1; return -1;
} }
time = strtol(argArray[2], &test, 10); time = strtol(argv[2], &test, 10);
if (*test != '\0') { if (*test != '\0') {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer", argArray[2]); "\"%s\" is not a integer", argv[2]);
return -1; return -1;
} }
return seekSongInPlaylistById(fp, id, time); return seekSongInPlaylistById(fp, id, time);
} }
static int handleListAllInfo(FILE * fp, int *permission, int argArrayLength, static int handleListAllInfo(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
char *directory = NULL; char *directory = NULL;
if (argArrayLength == 2) if (argc == 2)
directory = argArray[1]; directory = argv[1];
return printInfoForAllIn(fp, directory); return printInfoForAllIn(fp, directory);
} }
static int handlePing(FILE * fp, int *permission, int argArrayLength, static int handlePing(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
return 0; return 0;
} }
static int handlePassword(FILE * fp, int *permission, int argArrayLength, static int handlePassword(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
if (getPermissionFromPassword(argArray[1], permission) < 0) { if (getPermissionFromPassword(argv[1], permission) < 0) {
commandError(fp, ACK_ERROR_PASSWORD, "incorrect password", commandError(fp, ACK_ERROR_PASSWORD, "incorrect password",
NULL); NULL);
return -1; return -1;
...@@ -870,16 +870,16 @@ static int handlePassword(FILE * fp, int *permission, int argArrayLength, ...@@ -870,16 +870,16 @@ static int handlePassword(FILE * fp, int *permission, int argArrayLength,
return 0; return 0;
} }
static int handleCrossfade(FILE * fp, int *permission, int argArrayLength, static int handleCrossfade(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int time; int time;
char *test; char *test;
time = strtol(argArray[1], &test, 10); time = strtol(argv[1], &test, 10);
if (*test != '\0' || time < 0) { if (*test != '\0' || time < 0) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer >= 0", argArray[1]); "\"%s\" is not a integer >= 0", argv[1]);
return -1; return -1;
} }
...@@ -888,16 +888,16 @@ static int handleCrossfade(FILE * fp, int *permission, int argArrayLength, ...@@ -888,16 +888,16 @@ static int handleCrossfade(FILE * fp, int *permission, int argArrayLength,
return 0; return 0;
} }
static int handleEnableDevice(FILE * fp, int *permission, int argArrayLength, static int handleEnableDevice(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
int device; int device;
char *test; char *test;
device = strtol(argArray[1], &test, 10); device = strtol(argv[1], &test, 10);
if (*test != '\0' || device < 0) { if (*test != '\0' || device < 0) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer >= 0", argArray[1]); "\"%s\" is not a integer >= 0", argv[1]);
return -1; return -1;
} }
...@@ -905,23 +905,23 @@ static int handleEnableDevice(FILE * fp, int *permission, int argArrayLength, ...@@ -905,23 +905,23 @@ static int handleEnableDevice(FILE * fp, int *permission, int argArrayLength,
} }
static int handleDisableDevice(FILE * fp, int *permission, static int handleDisableDevice(FILE * fp, int *permission,
int argArrayLength, char **argArray) int argc, char **argv)
{ {
int device; int device;
char *test; char *test;
device = strtol(argArray[1], &test, 10); device = strtol(argv[1], &test, 10);
if (*test != '\0' || device < 0) { if (*test != '\0' || device < 0) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"\"%s\" is not a integer >= 0", argArray[1]); "\"%s\" is not a integer >= 0", argv[1]);
return -1; return -1;
} }
return disableAudioDevice(fp, device); return disableAudioDevice(fp, device);
} }
static int handleDevices(FILE * fp, int *permission, int argArrayLength, static int handleDevices(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
printAudioDevices(fp); printAudioDevices(fp);
...@@ -929,8 +929,8 @@ static int handleDevices(FILE * fp, int *permission, int argArrayLength, ...@@ -929,8 +929,8 @@ static int handleDevices(FILE * fp, int *permission, int argArrayLength,
} }
/* don't be fooled, this is the command handler for "commands" command */ /* don't be fooled, this is the command handler for "commands" command */
static int handleCommands(FILE * fp, int *permission, int argArrayLength, static int handleCommands(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
ListNode *node = commandList->firstNode; ListNode *node = commandList->firstNode;
CommandEntry *cmd; CommandEntry *cmd;
...@@ -947,8 +947,8 @@ static int handleCommands(FILE * fp, int *permission, int argArrayLength, ...@@ -947,8 +947,8 @@ static int handleCommands(FILE * fp, int *permission, int argArrayLength,
return 0; return 0;
} }
static int handleNotcommands(FILE * fp, int *permission, int argArrayLength, static int handleNotcommands(FILE * fp, int *permission, int argc,
char **argArray) char **argv)
{ {
ListNode *node = commandList->firstNode; ListNode *node = commandList->firstNode;
CommandEntry *cmd; CommandEntry *cmd;
...@@ -1061,7 +1061,7 @@ void finishCommands(void) ...@@ -1061,7 +1061,7 @@ void finishCommands(void)
} }
static int checkArgcAndPermission(CommandEntry * cmd, FILE * fp, static int checkArgcAndPermission(CommandEntry * cmd, FILE * fp,
int permission, int argc, char **argArray) int permission, int argc, char **argv)
{ {
int min = cmd->min + 1; int min = cmd->min + 1;
int max = cmd->max + 1; int max = cmd->max + 1;
...@@ -1082,21 +1082,21 @@ static int checkArgcAndPermission(CommandEntry * cmd, FILE * fp, ...@@ -1082,21 +1082,21 @@ static int checkArgcAndPermission(CommandEntry * cmd, FILE * fp,
if (fp) { if (fp) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"wrong number of arguments for \"%s\"", "wrong number of arguments for \"%s\"",
argArray[0]); argv[0]);
} }
return -1; return -1;
} else if (argc < min) { } else if (argc < min) {
if (fp) { if (fp) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"too few arguments for \"%s\"", "too few arguments for \"%s\"",
argArray[0]); argv[0]);
} }
return -1; return -1;
} else if (argc > max && max /* != 0 */ ) { } else if (argc > max && max /* != 0 */ ) {
if (fp) { if (fp) {
commandError(fp, ACK_ERROR_ARG, commandError(fp, ACK_ERROR_ARG,
"too many arguments for \"%s\"", "too many arguments for \"%s\"",
argArray[0]); argv[0]);
} }
return -1; return -1;
} else } else
...@@ -1106,29 +1106,29 @@ static int checkArgcAndPermission(CommandEntry * cmd, FILE * fp, ...@@ -1106,29 +1106,29 @@ static int checkArgcAndPermission(CommandEntry * cmd, FILE * fp,
static CommandEntry *getCommandEntryAndCheckArgcAndPermission(FILE * fp, static CommandEntry *getCommandEntryAndCheckArgcAndPermission(FILE * fp,
int *permission, int *permission,
int int
argArrayLength, argc,
char **argArray) char **argv)
{ {
static char unknown[] = ""; static char unknown[] = "";
CommandEntry *cmd; CommandEntry *cmd;
current_command = unknown; current_command = unknown;
if (argArrayLength == 0) if (argc == 0)
return NULL; return NULL;
if (!findInList(commandList, argArray[0], (void *)&cmd)) { if (!findInList(commandList, argv[0], (void *)&cmd)) {
if (fp) { if (fp) {
commandError(fp, ACK_ERROR_UNKNOWN, commandError(fp, ACK_ERROR_UNKNOWN,
"unknown command \"%s\"", argArray[0]); "unknown command \"%s\"", argv[0]);
} }
return NULL; return NULL;
} }
current_command = cmd->cmd; current_command = cmd->cmd;
if (checkArgcAndPermission(cmd, fp, *permission, argArrayLength, if (checkArgcAndPermission(cmd, fp, *permission, argc,
argArray) < 0) { argv) < 0) {
return NULL; return NULL;
} }
...@@ -1138,16 +1138,16 @@ static CommandEntry *getCommandEntryAndCheckArgcAndPermission(FILE * fp, ...@@ -1138,16 +1138,16 @@ static CommandEntry *getCommandEntryAndCheckArgcAndPermission(FILE * fp,
static CommandEntry *getCommandEntryFromString(char *string, int *permission) static CommandEntry *getCommandEntryFromString(char *string, int *permission)
{ {
CommandEntry *cmd = NULL; CommandEntry *cmd = NULL;
char **argArray; char **argv;
int argArrayLength = buffer2array(string, &argArray); int argc = buffer2array(string, &argv);
if (0 == argArrayLength) if (0 == argc)
return NULL; return NULL;
cmd = getCommandEntryAndCheckArgcAndPermission(NULL, permission, cmd = getCommandEntryAndCheckArgcAndPermission(NULL, permission,
argArrayLength, argc,
argArray); argv);
freeArgArray(argArray, argArrayLength); freeArgArray(argv, argc);
return cmd; return cmd;
} }
...@@ -1155,29 +1155,29 @@ static CommandEntry *getCommandEntryFromString(char *string, int *permission) ...@@ -1155,29 +1155,29 @@ static CommandEntry *getCommandEntryFromString(char *string, int *permission)
static int processCommandInternal(FILE * fp, int *permission, static int processCommandInternal(FILE * fp, int *permission,
char *commandString, ListNode * commandNode) char *commandString, ListNode * commandNode)
{ {
int argArrayLength; int argc;
char **argArray; char **argv;
CommandEntry *cmd; CommandEntry *cmd;
int ret = -1; int ret = -1;
argArrayLength = buffer2array(commandString, &argArray); argc = buffer2array(commandString, &argv);
if (argArrayLength == 0) if (argc == 0)
return 0; return 0;
if ((cmd = getCommandEntryAndCheckArgcAndPermission(fp, permission, if ((cmd = getCommandEntryAndCheckArgcAndPermission(fp, permission,
argArrayLength, argc,
argArray))) { argv))) {
if (NULL == commandNode || NULL == cmd->listHandler) { if (NULL == commandNode || NULL == cmd->listHandler) {
ret = cmd->handler(fp, permission, argArrayLength, ret = cmd->handler(fp, permission, argc,
argArray); argv);
} else { } else {
ret = cmd->listHandler(fp, permission, argArrayLength, ret = cmd->listHandler(fp, permission, argc,
argArray, commandNode, cmd); argv, commandNode, cmd);
} }
} }
freeArgArray(argArray, argArrayLength); freeArgArray(argv, argc);
current_command = NULL; current_command = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment