commit 3f114cd8cb6f27aea493842ac778c526fcaaa704
parent 2baba01117d87fd7ae83df457fd84f6dfeae1f5b
Author: parazyd <parazyd@dyne.org>
Date: Wed, 28 Feb 2018 18:51:59 +0100
Include rohrpost.c & co.
Diffstat:
10 files changed, 266 insertions(+), 22 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,17 +1,39 @@
# rp - simple email tools
# See LICENSE file for copyright and license details.
+.POSIX:
include config.mk
-all:
+BIN = $(NAME)
+OBJ = $(BIN:=.o) headers.o ind.o
+
+all: $(BIN)
+
+$(OBJ): config.mk
+
+$(BIN): $(OBJ)
+ $(CC) $(OBJ) $(LDFLAGS) -o $@
+
+clean:
+ cd bin; \
+ for i in `../$(NAME) -i`; do \
+ rm -f $$i;\
+ done
+ rm -f $(BIN) $(OBJ) bin/$(NAME)
install: all
+ cp -f $(NAME) bin
mkdir -p $(DESTDIR)$(PREFIX)/bin
cd bin; \
for i in `ls -1`; do \
cp $$i $(DESTDIR)$(PREFIX)/bin; \
chmod 755 $(DESTDIR)$(PREFIX)/bin/$$i; \
+ done; \
+ for i in `../$(NAME) -i`; do \
+ ln -s $(NAME) $$i; \
done
+ cp $(NAME) $(DESTDIR)$(PREFIX)/bin
+ chmod 755 $(DESTDIR)$(PREFIX)/bin/$(NAME)
sed "s,SHAREPREFIX,$(SHAREPREFIX),g" < bin/rpinit > $(DESTDIR)$(PREFIX)/bin/rpinit
chmod 755 $(DESTDIR)$(PREFIX)/bin/rpinit
mkdir -p $(DESTDIR)$(SHAREPREFIX)
diff --git a/arg.h b/arg.h
@@ -0,0 +1,48 @@
+/*
+ * Copy me if you can.
+ * by 20h
+ */
+
+#ifndef ARG_H__
+#define ARG_H__
+
+extern char *argv0;
+
+/* use main(int argc, char *argv[]) */
+#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
+ argv[0] && argv[0][0] == '-'\
+ && argv[0][1];\
+ argc--, argv++) {\
+ char argc_;\
+ char **argv_;\
+ int brk_;\
+ if (argv[0][1] == '-' && argv[0][2] == '\0') {\
+ argv++;\
+ argc--;\
+ break;\
+ }\
+ for (brk_ = 0, argv[0]++, argv_ = argv;\
+ argv[0][0] && !brk_;\
+ argv[0]++) {\
+ if (argv_ != argv)\
+ break;\
+ argc_ = argv[0][0];\
+ switch (argc_)
+#define ARGEND }\
+ }
+
+#define ARGC() argc_
+
+#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ ((x), abort(), (char *)0) :\
+ (brk_ = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
+
+#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ (char *)0 :\
+ (brk_ = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
+
+#endif
diff --git a/bin/rpheaders b/bin/rpheaders
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-profile="${RPPROFILE:-$HOME/.rp/default}"
-. "$HOME"/.rp/rplib/common.sh
-
-usage() {
- einfo "usage: $(basename $0) [header ...]"
- exit 1
-}
-
-headers="$(cat | sed '/^$/q')"
-
-get() {
- grep "^$1:" | cut -d: -f2- | cut -c 2-
-}
-
-
-for i in $@; do
- printf "$headers\n" | get "$i"
-done
diff --git a/config.mk b/config.mk
@@ -1,6 +1,12 @@
-NAME = rp
+NAME = rohrpost
# paths
PREFIX = /usr/local
SHAREPREFIX = $(PREFIX)/share/$(NAME)
MANPREFIX = $(PREFIX)/share/man
+
+CFLAGS = -O2 -Wall -pedantic
+LDFLAGS = -static -s
+
+.c.o:
+ $(CC) $(CFLAGS) -c $<
diff --git a/examples/plain-ml.txt b/examples/plain-ml.txt
@@ -0,0 +1,31 @@
+To: gentoo-user@lists.gentoo.org
+From: Grant Edwards <grant.b.edwards@gmail.com>
+Subject: [gentoo-user] Blacklist one of the pool's rsync server?
+Date: Wed, 28 Feb 2018 01:25:27 +0000 (UTC)
+User-Agent: slrn/1.0.2 (Linux)
+List-Id: Gentoo Linux mail <gentoo-user.gentoo.org>
+Reply-to: gentoo-user@lists.gentoo.org
+
+Is there any way for me to "blacklist" a pool rsync server so that
+emerge --sync won't try to use it?
+
+I'm using the sync-url rsync://rsync.us.gentoo.org/gentoo-portage, but
+one of the pool's servers is barely usable for me. I don't know if
+it's a server problem or if traffic between my and that server is
+routed through a Mars orbiter. When any other server is chosen, the
+file list scrolls by faster than you can read it. Via the Mars
+orbibiter the list ticks by about one file every 5-10 seconds. It
+will usually finish (eventually), but sometimes hangs and times out.
+It's been like for at least a year or two.
+
+[FWIW, I'm uable to ping the server, and tracroute is unable to produce
+a route to it. However, I can telnet to the rsync port on that host
+and it connects.]
+
+When I see that server has been selected, I usually just hit Ctrl-C
+and try again.
+
+Is there any way to configure portage to not use that server?
+
+--
+Grant
diff --git a/headers.c b/headers.c
@@ -0,0 +1,39 @@
+/*
+ * Copy me if you can
+ * by parazyd
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "arg.h"
+#include "headers.h"
+#include "ind.h"
+
+char *argv0;
+
+void headersusage(void) {
+ einfo("usage: %s [header [header [...]]]\n", argv0);
+ exit(1);
+}
+
+int headersmain(int argc, char *argv[]) {
+ int i;
+ char l[MAXLINESIZE];
+
+ if (argc < 2)
+ headersusage();
+
+ while (fgets(l, sizeof(l), stdin)) {
+ if (!strncmp("\n", l, 1))
+ return 0;
+ for (i = 1; i < argc; i++) {
+ if (!strncmp(l, argv[i], strlen(argv[i]))) {
+ printf("%s", l + strlen(argv[i])+2);
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/headers.h b/headers.h
@@ -0,0 +1,11 @@
+/*
+ * Copy me if you can
+ * by parazyd
+ */
+
+#ifndef __HEADERS_H__
+#define __HEADERS_H__
+
+int headersmain(int argc, char *argv[]);
+
+#endif
diff --git a/ind.c b/ind.c
@@ -0,0 +1,33 @@
+/*
+ * Copy me if you can.
+ * by parazyd
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void edie(char *fmt, ...) {
+ va_list fmtargs;
+ va_start(fmtargs, fmt);
+ fprintf(stderr, " \033[31m*\033[0m ");
+ vfprintf(stderr, fmt, fmtargs);
+ va_end(fmtargs);
+ exit(1);
+}
+
+void einfo(char *fmt, ...) {
+ va_list fmtargs;
+ va_start(fmtargs, fmt);
+ fprintf(stderr, " \033[32m*\033[0m ");
+ vfprintf(stderr, fmt, fmtargs);
+ va_end(fmtargs);
+}
+
+void ewarn(char *fmt, ...) {
+ va_list fmtargs;
+ va_start(fmtargs, fmt);
+ fprintf(stderr, " \033[33m*\033[0m ");
+ vfprintf(stderr, fmt, fmtargs);
+ va_end(fmtargs);
+}
diff --git a/ind.h b/ind.h
@@ -0,0 +1,17 @@
+/*
+ * Copy me if you can
+ * by parazyd
+ */
+
+#ifndef __IND_H__
+#define __IND_H__
+
+#define MAXLINESIZE 1048576
+
+#define nelem(x) (sizeof(x) / sizeof((x)[0]))
+
+void edie(char *fmt, ...);
+void einfo(char *fmt, ...);
+void ewarn(char *fmt, ...);
+
+#endif
diff --git a/rohrpost.c b/rohrpost.c
@@ -0,0 +1,57 @@
+/*
+ * Copy me if you can
+ * by parazyd
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "arg.h"
+#include "headers.h"
+#include "ind.h"
+
+char *argv0;
+
+void usage(void) {
+ einfo("usage: %s cmd [args]", argv0);
+ exit(1);
+}
+
+struct command {
+ char *cmd;
+ int flags;
+ int (*main)(int, char **);
+};
+
+/* The flag whether to output it on the -i(nstall) request. */
+enum {
+ DONTINSTALL = 0x00,
+ DOINSTALL = 0x01
+};
+
+struct command cmds[] = {
+ {"rpheaders", DOINSTALL, headersmain},
+};
+
+int main(int argc, char *argv[]) {
+ int i;
+
+ ARGBEGIN {
+ case 'i':
+ for (i = 0; i < nelem(cmds); i++)
+ printf("%s\n", cmds[i].cmd);
+ return 0;
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc > 0) {
+ for (i = 0; nelem(cmds); i++) {
+ if (!strcmp(argv[0], cmds[i].cmd))
+ return cmds[i].main(argc, argv);
+ }
+ }
+
+ usage();
+}