[BusyBox] rev and tac
Matt Kraai
kraai at alumni.carnegiemellon.edu
Sat Aug 26 08:02:49 UTC 2000
Howdy,
I've coded up rev and tac for busybox. Should I commit them, or is this
yet another instance of "feature creep?" Copies of rev.c and tac.c are
included for your enjoyment.
Matt
-------------- next part --------------
/* vi: set sw=4 ts=4: */
/*
* Mini rev implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Matt Kraai <kraai at alumni.carnegiemellon.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
static void
rev_file(FILE *file)
{
char *line, *s;
while ((line = get_line_from_file(file)) != NULL) {
s = line + strlen(line) - 1;
if (line <= s && *s == '\n')
s--;
while (line <= s) {
fputc(*s, stdout);
s--;
}
fputc('\n', stdout);
free(line);
}
}
int
rev_main(int argc, char **argv)
{
int status = 0;
FILE *file;
if (argc == 1) {
rev_file(stdin);
} else {
while (*++argv) {
if ((file = fopen(*argv, "r")) != NULL) {
rev_file(file);
fclose(file);
} else {
errorMsg("%s: %s\n", *argv, strerror(errno));
status = 1;
}
}
}
return status;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
-------------- next part --------------
/* vi: set sw=4 ts=4: */
/*
* Mini tac implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Matt Kraai <kraai at alumni.carnegiemellon.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
static void
tac_file(FILE *file)
{
char *line;
if ((line = get_line_from_file(file)) != NULL) {
tac_file(file);
fputs(line, stdout);
free(line);
}
}
int
tac_main(int argc, char **argv)
{
int status = 0;
FILE *file;
if (argc == 1) {
tac_file(stdin);
} else {
while (*++argv) {
if ((file = fopen(*argv, "r")) != NULL) {
tac_file(file);
fclose(file);
} else {
errorMsg("%s: %s\n", *argv, strerror(errno));
status = 1;
}
}
}
return status;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20000826/2abed5dd/attachment.pgp
More information about the busybox
mailing list