diff --git a/docs/pg.1 b/docs/pg.1 index e0f1f99..53aced0 100644 --- a/docs/pg.1 +++ b/docs/pg.1 @@ -1,4 +1,9 @@ -.TH P 1 +.\" Copyright (c) 2024 DTB +.\" +.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, +.\" visit . + +.TH PG 1 .SH NAME diff --git a/src/pg.c b/src/pg.c index 5cb02a1..5130450 100644 --- a/src/pg.c +++ b/src/pg.c @@ -1,8 +1,28 @@ -#include -#include -#include +/* + * Copyright (c) 2024 DTB + * 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 /* fclose(3), feof(3), fgetc(3), fgets(3), fopen(3), + * fprintf(3), fputc(3), stderr, stdin, stdout, EOF, FILE, + * NULL */ +#include /* size_t */ +#include /* strchr */ + +#if !defined EX_OK || !defined EX_SOFTWARE || !defined EX_USAGE # include #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; }