forked from bonsai/harakit
pg(1): make it fit the project better
This commit is contained in:
parent
e26d8e0e1b
commit
ea8b58554e
@ -1,4 +1,9 @@
|
||||
.TH P 1
|
||||
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
|
||||
.TH PG 1
|
||||
|
||||
.SH NAME
|
||||
|
||||
|
40
src/pg.c
40
src/pg.c
@ -1,8 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
/*
|
||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 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 Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#if !defined EX_USAGE || !defined EX_SOFTWARE
|
||||
#include <stdio.h> /* fclose(3), feof(3), fgetc(3), fgets(3), fopen(3),
|
||||
* fprintf(3), fputc(3), stderr, stdin, stdout, EOF, FILE,
|
||||
* NULL */
|
||||
#include <stdlib.h> /* size_t */
|
||||
#include <string.h> /* strchr */
|
||||
|
||||
#if !defined EX_OK || !defined EX_SOFTWARE || !defined EX_USAGE
|
||||
# include <sysexits.h>
|
||||
#endif
|
||||
|
||||
@ -14,13 +34,13 @@
|
||||
|
||||
static size_t l = 22; /* plan9 default */
|
||||
|
||||
static char *program_name = "p";
|
||||
static char *program_name = "pg";
|
||||
|
||||
static int print_lines(FILE *f, size_t l){
|
||||
int c;
|
||||
|
||||
while((c = getc(f)) != EOF)
|
||||
if((c = putc(c, stdout)) == EOF || (l -= (c == '\n')) == 0)
|
||||
while((c = fgetc(f)) != EOF)
|
||||
if((c = fputc(c, stdout)) == EOF || (l -= (c == '\n')) == 0)
|
||||
break;
|
||||
|
||||
return c;
|
||||
@ -45,12 +65,12 @@ int main(int argc, char *argv[]){
|
||||
}
|
||||
|
||||
while(print_lines(stdin, l) != EOF){
|
||||
fgets(cmd, (sizeof cmd) / (sizeof *cmd), t);
|
||||
for(p = cmd; *p != '\0' && strchr(" \t", *p) != NULL; ++p);
|
||||
fgets((char *)cmd, (sizeof cmd) / (sizeof *cmd), t);
|
||||
for(p = (char *)cmd; *p != '\0' && strchr(" \t", *p) != NULL; ++p);
|
||||
if(feof(t) || (*p | 32) == 'q')
|
||||
break;
|
||||
}
|
||||
|
||||
exit: fclose(t);
|
||||
return 0;
|
||||
return EX_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user