Skip to content

Commit

Permalink
Stopped displaying usage when error.
Browse files Browse the repository at this point in the history
  • Loading branch information
kobayasy committed Feb 10, 2024
1 parent 4522160 commit 500d10a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 62 deletions.
8 changes: 4 additions & 4 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

<img src="psync.png" alt="pSync" align="right">

[pSync] is an open-source cloud storage.
[pSync] is an open source cloud file sharing system.
Securely and speedy synchronize your files by authenticate, encrypt and compress with SSH.
So for this to work, you must be able to login to the sync-host with SSH.

## Installation
This work is required for each sync-host include local-host.
1. Do the following to build and install.
```
curl -LOJs https://github.com/kobayasy/pSync/releases/download/2.33/psync-2.33.tar.gz
tar xzf psync-2.33.tar.gz
cd psync-2.33
curl -LOJs https://github.com/kobayasy/pSync/releases/download/2.34/psync-2.34.tar.gz
tar xzf psync-2.34.tar.gz
cd psync-2.34
./configure --prefix=$HOME
make install
Expand Down
10 changes: 5 additions & 5 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

<img src="psync.png" alt="pSync" align="right">

[pSync] はオープンソースのクラウドストーレージです
[pSync] はオープンソースのクラウドファイル共有システムです
SSH によって認証/暗号化/圧縮を行い、安全かつ高速にファイル同期を行ないます。
よってこれを動かすには、SSH で同期先ホストへログイン出来る必要が有ります。
その為、これを動かすには SSH で同期先ホストへログイン出来る必要が有ります。

## インストール
ローカルホストを含めた全ての同期ホストに対してこの作業が必要です。
1. 以下の手順でビルドとインストールを行ないます。
```
curl -LOJs https://github.com/kobayasy/pSync/releases/download/2.33/psync-2.33.tar.gz
tar xzf psync-2.33.tar.gz
cd psync-2.33
curl -LOJs https://github.com/kobayasy/pSync/releases/download/2.34/psync-2.34.tar.gz
tar xzf psync-2.34.tar.gz
cd psync-2.34
./configure --prefix=$HOME
make install
Expand Down
Binary file modified psync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions src/Makefile.in
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]>
#
Expand Down Expand Up @@ -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@
Expand Down
2 changes: 1 addition & 1 deletion src/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pSync is an open-source cloud storage.
pSync is an open source cloud file sharing system.
Securely and speedy synchronize your files by authenticate, encrypt and compress with SSH.
So for this to work, you must be able to login to the sync-host with SSH.

Expand Down
18 changes: 9 additions & 9 deletions src/configure
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]>.
#
Expand Down Expand Up @@ -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/'

Expand Down Expand Up @@ -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]...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 $@
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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\\"
Expand Down
4 changes: 2 additions & 2 deletions src/configure.ac
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]>
#
Expand All @@ -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])
Expand Down
84 changes: 49 additions & 35 deletions src/main.c
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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"))
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 500d10a

Please sign in to comment.