From 62348e78df0a73827498f34ae25babbddb9fca1a Mon Sep 17 00:00:00 2001 From: b Date: Sun, 9 Jul 2023 22:01:16 +0000 Subject: [PATCH] error code, drop config config, data dir --- makefile | 8 +++++--- makefile.1.mak | 8 +++++--- sendpost.1.pl | 41 ++++++++++++++++++++++------------------- settings-debug.txt | 5 +---- settings-release.txt | 5 +---- settings.txt | 8 ++++---- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/makefile b/makefile index 277394e..731ea39 100644 --- a/makefile +++ b/makefile @@ -31,9 +31,10 @@ MKDIR=/usr/bin/mkdir RM =/usr/bin/rm PERL =/usr/bin/perl -BIN_PATH = /botm/bin/test-post -LIB_PATH = /botm/lib/test-post -TMP_PATH = /botm/tmp/test-post +BIN_PATH = /botm/bin/test-post +DATA_PATH = /botm/data/test-post +LIB_PATH = /botm/lib/test-post +TMP_PATH = /botm/tmp/test-post CONFIGFILE = settings-$(TARGET).txt settings.txt @@ -51,6 +52,7 @@ sendpost.pl DIR=\ $(BIN_PATH)\ +$(DATA_PATH)\ $(LIB_PATH)\ $(TMP_PATH) diff --git a/makefile.1.mak b/makefile.1.mak index f258dde..5a25251 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -31,9 +31,10 @@ PERL = perl ###MAKE_RM: RM = rm ###MAKE_PERL: PERL = perl -###MAKE_BIN_PATH: BIN_PATH = /botm/bin/post -###MAKE_LIB_PATH: LIB_PATH = /botm/lib/post -###MAKE_TMP_PATH: TMP_PATH = /botm/tmp/post +###MAKE_BIN_PATH: BIN_PATH = /botm/bin/post +###MAKE_DATA_PATH: DATA_PATH = /botm/data/post +###MAKE_LIB_PATH: LIB_PATH = /botm/lib/post +###MAKE_TMP_PATH: TMP_PATH = /botm/tmp/post CONFIGFILE = settings-$(TARGET).txt settings.txt @@ -51,6 +52,7 @@ sendpost.pl DIR=\ $(BIN_PATH)\ +$(DATA_PATH)\ $(LIB_PATH)\ $(TMP_PATH) diff --git a/sendpost.1.pl b/sendpost.1.pl index ff301cb..906eac1 100644 --- a/sendpost.1.pl +++ b/sendpost.1.pl @@ -31,6 +31,11 @@ use botm_common ( 'system_encoded' ); +use constant OK => 0; +use constant POST_INVALID => 1; +use constant POST_FAILED => 2; +use constant POST_NOT_ACCEPTED => 3; + ###PERL_VERSION: use constant VERSION => 'x.x.x'; ###PERL_ENCODING_FILE: use constant ENCODING_FILE => 'UTF-8'; @@ -161,7 +166,7 @@ if ((scalar @ARGV) == 0) { @ARGV = (\*STDIN); } -my $code = 0; +my $code = OK; foreach my $arg (@ARGV) { my $r; @@ -181,9 +186,9 @@ foreach my $arg (@ARGV) { unless (keys %data) { unless ($options{'quiet'} ne '') { print "NO DATA\n"; - if ($code == 0) { - $code = 1; - } + } + if ($code == OK) { + $code = POST_INVALID; } print STDERR 'No data'; unless ($arg == \*STDIN) { @@ -213,11 +218,11 @@ foreach my $arg (@ARGV) { # } unless ($options{'no-mirror'}) { $r = post_to_mirror(\%options, \%post); - if ($r == 0) { + if ($r == OK) { next; } } - if ($code == 0) { + if ($code == OK) { $code = $r; } } @@ -383,7 +388,7 @@ sub post_to_mirror { print 'INVALID ID '.$cmd_options->{'edit'}."\n"; } print STDERR 'Not a valid mirror post ID: '.$cmd_options->{'edit'}."\n"; - return 1; + return POST_INVALID; } $query_data{'e'} = 'm'.$cmd_options->{'edit'}; } @@ -410,7 +415,7 @@ sub post_to_mirror { print "WGET FAIL $r\n"; } print STDERR "Failed to get edit page: wget: $r\n"; - return $r; + return POST_FAILED; } unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) { @@ -418,7 +423,7 @@ sub post_to_mirror { print "FAIL open $tmp_path\n"; } print STDERR "Failed to open edit page. $tmp_path\n"; - return 1; + return POST_FAILED; } %header = read_header_file($fh, ENCODING_MIRROR()); @@ -432,7 +437,7 @@ sub post_to_mirror { print 'FAIL '.$header{':status-code'}.' '.$header{':reason-phrase'}."\n"; } print STDERR 'Failed to get edit page: '.$header{':status-code'}.' '.$header{':reason-phrase'}."\n"; - return int($header{':status-code'}) + return POST_FAILED; } if (($cmd_options->{'edit'} ne '') and ($cmd_options->{'append'} ne '')) { @@ -442,7 +447,7 @@ sub post_to_mirror { print "FAIL previous post\n"; } print STDERR 'Failed getting previous post content: '.$previous_post{'error'}."\n"; - return 1; + return POST_FAILED; } if ($cmd_options->{'verbose'} ne '') { print "PREVIOUS POST\n"; @@ -510,8 +515,8 @@ sub post_to_mirror { unless ($cmd_options->{'quiet'} ne '') { print "WGET FAIL $r\n"; } - print STDERR "Failed to open post submit response: wget: $r\n"; - return $r; + print STDERR "Failed to get post submit response: wget: $r\n"; + return POST_FAILED; } unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) { @@ -519,7 +524,7 @@ sub post_to_mirror { print "FAIL open $tmp_path\n"; } print STDERR "Failed to open post submit response. $tmp_path\n"; - return 1; + return POST_FAILED; } %header = read_header_file($fh, ENCODING_MIRROR()); @@ -533,7 +538,7 @@ sub post_to_mirror { print 'FAIL '.$header{':status-code'}.' '.$header{':reason-phrase'}."\n"; } print STDERR 'Failed to get post submit response page: '.$header{':status-code'}.' '.$header{':reason-phrase'}."\n"; - return int($header{':status-code'}) + return POST_FAILED; } ($r, $s) = get_mirror_post_status($fh); @@ -544,7 +549,7 @@ sub post_to_mirror { print "FAIL $s\n"; } print STDERR "Post not accepted by mirror: $s.\n"; - return 1; + return POST_NOT_ACCEPTED; } unless ($cmd_options->{'quiet'} ne '') { @@ -562,8 +567,7 @@ sub post_to_mirror { unlink($tmp_path, $cookie_path, $postdata_path); } - return 0; - + return OK; } sub get_mirror_post_status { @@ -731,7 +735,6 @@ sub wget { my $r = system_encoded(WGET, @arg); - return $r; } diff --git a/settings-debug.txt b/settings-debug.txt index 0f754a9..3fb8390 100644 --- a/settings-debug.txt +++ b/settings-debug.txt @@ -2,14 +2,11 @@ # where TARGET_NAME is the value target: debug -# The configuration tool -# http://bicyclesonthemoon.info/git/botm-config -# alternatively, copy configure.pl to source directory. -configure: /botm/bin/config/configure.pl bin_path: /botm/bin/test-post lib_path: /botm/lib/test-post tmp_path: /botm/tmp/test-post +data_path: /botm/data/test-post mirror_url: http://1190.botcastle1b/ott diff --git a/settings-release.txt b/settings-release.txt index 01c2ca7..59c0959 100644 --- a/settings-release.txt +++ b/settings-release.txt @@ -2,14 +2,11 @@ # where TARGET_NAME is the value target: release -# The configuration tool -# http://bicyclesonthemoon.info/git/botm-config -# alternatively, copy configure.pl to source directory. -configure: /botm/bin/config/configure.pl bin_path: /botm/bin/post lib_path: /botm/lib/post tmp_path: /botm/tmp/post +data_path: /botm/data/post # TODO: wget doesn't accept my https :( mirror_url: http://1190.bicyclesonthemoon.info/ott diff --git a/settings.txt b/settings.txt index e323205..b882072 100644 --- a/settings.txt +++ b/settings.txt @@ -24,7 +24,6 @@ _PERL_USE_2: use $0 $1; _PERL_CONSTANT: use constant $0 => $1; _PERL_CONSTANT_STR: @_PERL_CONSTANT($0,@_PERL_STR($1)) -MAKE_CONFIGURE = CONFIGURE = $configure MAKE_TARGET = TARGET = $target MAKE_CHMOD = CHMOD=$chmod @@ -36,9 +35,10 @@ MAKE_RM = RM =$rm MAKE_CC = CC =$CC MAKE_CF = CF =$CF -MAKE_BIN_PATH = BIN_PATH = $bin_path -MAKE_LIB_PATH = LIB_PATH = $lib_path -MAKE_TMP_PATH = TMP_PATH = $tmp_path +MAKE_BIN_PATH = BIN_PATH = $bin_path +MAKE_DATA_PATH = DATA_PATH = $data_path +MAKE_LIB_PATH = LIB_PATH = $lib_path +MAKE_TMP_PATH = TMP_PATH = $tmp_path PERL_DEFAULT_PASSWORD = @_PERL_CONSTANT_STR( DEFAULT_PASSWORD , $default_password) -- 2.30.2