[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [BusyBox] rev and tac
From: Matt Kraai <kraai () alumni ! carnegiemellon ! edu>
Date: 2000-08-26 8:02:49
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
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
["rev.c" (text/plain)]
/* vi: set sw=4 ts=4: */
/*
* Mini rev implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Matt Kraai <kraai@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:
*/
["tac.c" (text/plain)]
/* vi: set sw=4 ts=4: */
/*
* Mini tac implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Matt Kraai <kraai@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:
*/
[Attachment #7 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic