-int main(int, char *[]);
-void printit(const char *) __attribute__((__noreturn__));
+
+static void
+init_rottbl(int rot)
+{
+ size_t i;
+
+ rot %= LETTERS;
+
+ for (i = 0; i < NCHARS; i++)
+ rottbl[i] = (unsigned char)i;
+
+ for (i = 0; i < LETTERS; i++)
+ rottbl[upper[i]] = upper[(i + rot) % LETTERS];
+
+ for (i = 0; i < LETTERS; i++)
+ rottbl[lower[i]] = lower[(i + rot) % LETTERS];
+}
+
+static void __attribute__((__noreturn__))
+printrot(const char *arg)
+{
+ int ch;
+ long rot;
+ char *endp;
+
+ errno = 0;
+ rot = strtol(arg, &endp, 10);
+ if (*endp != '\0') {
+ errx(EXIT_FAILURE, "bad rotation value: %s", arg);
+ /* NOTREACHED */
+ }
+ if (errno == ERANGE || rot < 0 || rot > INT_MAX) {
+ errx(EXIT_FAILURE, "rotation value out of range: %s", arg);
+ /* NOTREACHED */
+ }
+ init_rottbl((int)rot);
+
+ while ((ch = getchar()) != EOF) {
+ if (putchar(rottbl[ch]) == EOF) {
+ err(EXIT_FAILURE, "writing to stdout");
+ /* NOTREACHED */
+ }
+ }
+ exit(EXIT_SUCCESS);
+ /* NOTREACHED */
+}