=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/encrypt/encrypt.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/encrypt/encrypt.c 1996/08/08 02:07:22 1.1 --- src/usr.bin/encrypt/encrypt.c 1996/08/08 04:37:02 1.2 *************** *** 1,4 **** ! /* $OpenBSD: encrypt.c,v 1.1 1996/08/08 02:07:22 downsj Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. --- 1,4 ---- ! /* $OpenBSD: encrypt.c,v 1.2 1996/08/08 04:37:02 downsj Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. *************** *** 45,50 **** --- 45,66 ---- errx(1, "usage: %s [-m] [-s salt] [string]", __progname); } + char *trim(line) + char *line; + { + char *ptr; + + for (ptr = &line[strlen(line)-1]; ptr > line; ptr--) { + if (!isspace(*ptr)) + break; + } + ptr[1] = '\0'; + + for (ptr = line; *ptr && isspace(*ptr); ptr++); + + return(ptr); + } + int main(argc, argv) int argc; char *argv[]; *************** *** 73,90 **** usage(); if ((argc - optind) < 1) { ! char line[BUFSIZ]; /* Encrypt stdin to stdout. */ while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) { ! if ((line[0] == '\0') || (line[0] == '\n')) continue; ! /* Kill the newline. */ ! if (line[strlen(line)] == '\n') ! line[strlen(line)] = '\0'; ! ! fputs(crypt(line, (do_md5 ? "$1$" : salt)), stdout); fputc('\n', stdout); } } else { --- 89,104 ---- usage(); if ((argc - optind) < 1) { ! char line[BUFSIZ], *string; /* Encrypt stdin to stdout. */ while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) { ! /* Kill the whitesapce. */ ! string = trim(line); ! if (*string == '\0') continue; ! fputs(crypt(string, (do_md5 ? "$1$" : salt)), stdout); fputc('\n', stdout); } } else {