-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stopped displaying usage when error.
- Loading branch information
Showing
8 changed files
with
72 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# @configure_input@ | ||
# Makefile.in - Last modified: 03-Feb-2024 (kobayasy) | ||
# Makefile.in - Last modified: 10-Feb-2024 (kobayasy) | ||
# | ||
# Copyright (C) 2018-2024 by Yuichi Kobayashi <[email protected]> | ||
# | ||
|
@@ -36,11 +36,7 @@ datarootdir = @datarootdir@ | |
mandir = @mandir@ | ||
|
||
CC = @CC@ | ||
CFLAGS = @CFLAGS@ | ||
#CFLAGS += -Wno-shift-count-overflow | ||
#CFLAGS += -Wno-tautological-constant-out-of-range-compare | ||
#CFLAGS += -Wno-unused-result | ||
#CFLAGS += -Wno-format-truncation | ||
CFLAGS = @CFLAGS@ | ||
DEFS = @DEFS@ | ||
LIBS = @LIBS@ | ||
INSTALL = @INSTALL@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#! /bin/sh | ||
# Guess values for system-dependent variables and create Makefiles. | ||
# Generated by GNU Autoconf 2.69 for pSync 2.33. | ||
# Generated by GNU Autoconf 2.69 for pSync 2.34. | ||
# | ||
# Report bugs to <[email protected]>. | ||
# | ||
|
@@ -582,8 +582,8 @@ MAKEFLAGS= | |
# Identity of this package. | ||
PACKAGE_NAME='pSync' | ||
PACKAGE_TARNAME='psync' | ||
PACKAGE_VERSION='2.33' | ||
PACKAGE_STRING='pSync 2.33' | ||
PACKAGE_VERSION='2.34' | ||
PACKAGE_STRING='pSync 2.34' | ||
PACKAGE_BUGREPORT='[email protected]' | ||
PACKAGE_URL='http://kobayasy.com/psync/' | ||
|
||
|
@@ -1258,7 +1258,7 @@ if test "$ac_init_help" = "long"; then | |
# Omit some internal or obsolete options to make the list less imposing. | ||
# This message is too long to be a string in the A/UX 3.1 sh. | ||
cat <<_ACEOF | ||
\`configure' configures pSync 2.33 to adapt to many kinds of systems. | ||
\`configure' configures pSync 2.34 to adapt to many kinds of systems. | ||
Usage: $0 [OPTION]... [VAR=VALUE]... | ||
|
@@ -1323,7 +1323,7 @@ fi | |
|
||
if test -n "$ac_init_help"; then | ||
case $ac_init_help in | ||
short | recursive ) echo "Configuration of pSync 2.33:";; | ||
short | recursive ) echo "Configuration of pSync 2.34:";; | ||
esac | ||
cat <<\_ACEOF | ||
|
@@ -1422,7 +1422,7 @@ fi | |
test -n "$ac_init_help" && exit $ac_status | ||
if $ac_init_version; then | ||
cat <<\_ACEOF | ||
pSync configure 2.33 | ||
pSync configure 2.34 | ||
generated by GNU Autoconf 2.69 | ||
Copyright (C) 2012 Free Software Foundation, Inc. | ||
|
@@ -1793,7 +1793,7 @@ cat >config.log <<_ACEOF | |
This file contains any messages produced by compilers while | ||
running configure, to aid debugging if configure makes a mistake. | ||
It was created by pSync $as_me 2.33, which was | ||
It was created by pSync $as_me 2.34, which was | ||
generated by GNU Autoconf 2.69. Invocation command line was | ||
$ $0 $@ | ||
|
@@ -5087,7 +5087,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 | |
# report actual input values of CONFIG_FILES etc. instead of their | ||
# values after options handling. | ||
ac_log=" | ||
This file was extended by pSync $as_me 2.33, which was | ||
This file was extended by pSync $as_me 2.34, which was | ||
generated by GNU Autoconf 2.69. Invocation command line was | ||
CONFIG_FILES = $CONFIG_FILES | ||
|
@@ -5150,7 +5150,7 @@ _ACEOF | |
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 | ||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" | ||
ac_cs_version="\\ | ||
pSync config.status 2.33 | ||
pSync config.status 2.34 | ||
configured by $0, generated by GNU Autoconf 2.69, | ||
with options \\"\$ac_cs_config\\" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# configure.ac - Last modified: 03-Feb-2024 (kobayasy) | ||
# configure.ac - Last modified: 10-Feb-2024 (kobayasy) | ||
# | ||
# Copyright (C) 2018-2024 by Yuichi Kobayashi <[email protected]> | ||
# | ||
|
@@ -23,7 +23,7 @@ | |
# SOFTWARE. | ||
|
||
AC_PREREQ(2.69) | ||
AC_INIT([pSync], [2.33], [[email protected]], [psync], [http://kobayasy.com/psync/]) | ||
AC_INIT([pSync], [2.34], [[email protected]], [psync], [http://kobayasy.com/psync/]) | ||
AC_COPYRIGHT([Copyright @{:@C@:}@ 2018-2024 by Yuichi Kobayashi <[email protected]>]) | ||
AC_CONFIG_SRCDIR([psync.c]) | ||
AC_CONFIG_AUX_DIR([conf]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* main.c - Last modified: 29-Mar-2023 (kobayasy) | ||
/* main.c - Last modified: 10-Feb-2024 (kobayasy) | ||
* | ||
* Copyright (C) 2018-2023 by Yuichi Kobayashi <[email protected]> | ||
* Copyright (C) 2018-2024 by Yuichi Kobayashi <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation files | ||
|
@@ -62,7 +62,6 @@ | |
#define SSHPORT 22 | ||
#endif /* #ifndef SSHPORT */ | ||
|
||
#define ERROR_HELP 3 | ||
#define ERROR_ENVS (-26) | ||
#define ERROR_CONF (-27) | ||
#define ERROR_ARGS (-28) | ||
|
@@ -415,6 +414,10 @@ static int get_config(const char *confname, PSP *psp) { | |
} | ||
|
||
typedef struct { | ||
enum { | ||
RUN=0, | ||
USAGE | ||
} command; | ||
PSYNC_MODE mode; | ||
char *hostname; | ||
bool verbose; | ||
|
@@ -435,10 +438,8 @@ static int get_opts(char *argv[], OPTS *opts) { | |
goto error; | ||
case '-': | ||
++s; | ||
if (!strcmp(s, "help")) { | ||
status = ERROR_HELP; | ||
goto error; | ||
} | ||
if (!strcmp(s, "help")) | ||
opts->command = USAGE; | ||
else if (!strcmp(s, "remote")) | ||
opts->mode = PSYNC_SLAVE; | ||
else if (!strcmp(s, "sync")) | ||
|
@@ -491,30 +492,36 @@ static int get_opts(char *argv[], OPTS *opts) { | |
} | ||
opts->hostname = *argv; | ||
} | ||
switch (opts->mode) { | ||
case PSYNC_MASTER: | ||
case PSYNC_MASTER_PUT: | ||
case PSYNC_MASTER_GET: | ||
if (opts->hostname == NULL) { | ||
fprintf(stderr, "Error: HOST is required\n"); | ||
status = ERROR_ARGS; | ||
goto error; | ||
switch (opts->command) { | ||
case RUN: | ||
switch (opts->mode) { | ||
case PSYNC_MASTER: | ||
case PSYNC_MASTER_PUT: | ||
case PSYNC_MASTER_GET: | ||
if (opts->hostname == NULL) { | ||
fprintf(stderr, "Error: HOST is required\n"); | ||
status = ERROR_ARGS; | ||
goto error; | ||
} | ||
break; | ||
case PSYNC_SLAVE: | ||
default: | ||
if (opts->hostname != NULL) { | ||
fprintf(stderr, "Error: HOST is not required\n"); | ||
status = ERROR_ARGS; | ||
goto error; | ||
} | ||
} | ||
break; | ||
case PSYNC_SLAVE: | ||
default: | ||
if (opts->hostname != NULL) { | ||
fprintf(stderr, "Error: HOST is not required\n"); | ||
status = ERROR_ARGS; | ||
goto error; | ||
} | ||
} | ||
status = 0; | ||
error: | ||
return status; | ||
} | ||
|
||
static void usage(FILE *fp) { | ||
static int usage(FILE *fp) { | ||
int status = INT_MIN; | ||
|
||
fprintf(fp, PACKAGE_STRING" (protocol %c%c%c%u)\n" | ||
"\n", PSYNC_PROTID, PSYNC_PROTID >> 8, PSYNC_PROTID >> 16, PSYNC_PROTID >> 24 ); | ||
fprintf(fp, "Usage: "PACKAGE_TARNAME" [--sync] [-v|-q] [USER@]HOST[#PORT]\n" | ||
|
@@ -539,12 +546,15 @@ static void usage(FILE *fp) { | |
fprintf(fp, "subcommand\n" | ||
" --help show this help\n" | ||
"\n" ); | ||
status = 0; | ||
return status; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
int status = INT_MIN; | ||
PSP *psp = NULL; | ||
OPTS opts = { | ||
.command = RUN, | ||
.mode = PSYNC_MASTER, | ||
.verbose = true, | ||
.hostname = NULL | ||
|
@@ -555,36 +565,40 @@ int main(int argc, char *argv[]) { | |
if (s == NULL) { | ||
fprintf(stderr, "Error: $HOME is not set.\n"); | ||
status = ERROR_ENVS; | ||
goto run; | ||
goto error; | ||
} | ||
if (chdir(s) == -1) { | ||
fprintf(stderr, "Error: Can not change diractory to %s\n", s); | ||
status = ERROR_ENVS; | ||
goto run; | ||
goto error; | ||
} | ||
psp = psp_new(&priv.stop); | ||
if (psp == NULL) { | ||
fprintf(stderr, "Error: Out of memory.\n"); | ||
status = ERROR_MEMORY; | ||
goto run; | ||
goto error; | ||
} | ||
status = get_config(CONFFILE, psp); | ||
if (ISERR(status)) | ||
goto run; | ||
goto error; | ||
priv.namelen = status; | ||
status = get_opts(argv, &opts); | ||
run: | ||
switch (status) { | ||
case 0: | ||
if (ISERR(status)) | ||
goto error; | ||
switch (opts.command) { | ||
case RUN: | ||
status = run(opts.mode, psp, opts.verbose, opts.hostname); | ||
if (status != ERROR_ARGS) | ||
switch (status) { | ||
case ERROR_ARGS: | ||
fprintf(stderr, "Error: PORT is invalid.\n"); | ||
break; | ||
fprintf(stderr, "Error: PORT is invalid.\n"); | ||
} | ||
break; | ||
case USAGE: | ||
default: | ||
if (ISERR(status)) | ||
fputc('\n', stdout); | ||
usage(stdout); | ||
status = usage(stdout); | ||
} | ||
error: | ||
if (psp != NULL) | ||
psp_free(psp); | ||
if (ISERR(status)) | ||
|