Compare commits

..

8 Commits

5 changed files with 30 additions and 30 deletions

View File

@ -23,7 +23,7 @@
#include <stdio.h> /* fprintf(3), stderr */
#include <stdlib.h> /* malloc(3), strtol(3), size_t */
#include <string.h> /* memcpy(3), memmove(3), memset(3) */
#include <sysexits.h>
#include <sysexits.h> /* EX_OK, EX_OSERR, EX_USAGE */
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
#include <sys/stat.h> /* S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR */
@ -96,8 +96,9 @@ static struct Io * Io_write(struct Io *io) {
if ((t = write(io->fd, io->buf, io->bufuse)) < 0) {
io->error = errno;
t = 0;
} else if (t > 0)
} else if (t > 0) {
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
}
io->bytes += t;
io->prec += (t > 0 && io->bufuse > 0);
@ -175,7 +176,7 @@ int main(int argc, char *argv[]) {
io[i].seek = 0;
}
if (!argc < 0) { usage(program_name); }
if (!(argc < 0)) { usage(program_name); }
int c;

View File

@ -21,7 +21,7 @@
#include <stdio.h> /* fprintf(3), stderr */
#include <stdlib.h> /* strtol(3), size_t, EXIT_FAILURE */
#include <unistd.h> /* getopt(3), optind */
#include <sysexits.h>
#include <sysexits.h> /* EX_OK, EX_USAGE */
/* 0b00? */ /* Equal | -e | 0b001 | 1 */
#define EQUAL 0x01 /* Greater | -g | 0b010 | 2 */
@ -33,10 +33,8 @@
static char *program_name = "intcmp";
int usage(char *s) {
fprintf(
stderr, "Usage: %s [-egl] integer integer...\n",
s == NULL ? program_name : s
);
fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s);
return EX_USAGE;
}
@ -45,25 +43,26 @@ int main(int argc, char *argv[]) {
size_t i;
unsigned char mode;
int r; /* reference integer */
char *s = (argv[0] == NULL ? program_name : argv[0]);
mode = 0;
if(argc < 3) { return usage(argv[0]); }
if (argc == 0 | argc < 3) { return usage(s); }
while ((c = getopt(argc, argv, "egl")) != -1) {
switch(c){
switch (c){
case 'e': mode |= EQUAL; break;
case 'g': mode |= GREATER; break;
case 'l': mode |= LESSER; break;
default: return usage(argv[0]);
default: return usage(s);
}
}
if(optind + 2 /* ref cmp */ > argc){ return usage(argv[0]); }
if (optind + 2 /* ref cmp */ > argc) { return usage(s); }
i = optind;
do{
do {
r = c;
c = strtol(argv[i], &argv[i], 10);
@ -82,7 +81,7 @@ int main(int argc, char *argv[]) {
|| (!(mode & GREATER) && r > c)
|| (!(mode & LESSER) && r < c)
) { return 1; }
} while(++i < argc);
} while (++i < argc);
return EX_OK;
}

View File

@ -24,8 +24,8 @@
#include <stdlib.h> /* free(3), realloc(3) */
#include <string.h> /* strcmp(3), strerror(3) */
#include <unistd.h> /* getopt(3) */
#include <sysexits.h>
#endif
#include <sysexits.h> /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */
extern int errno;
/* This structure is how open files are tracked. */

View File

@ -19,9 +19,9 @@
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout,
* EOF */
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
#include <stdlib.h> /* EXIT_FAILURE */
#include <unistd.h> /* getopt(3) */
#include <sysexits.h>
#include <sysexits.h> /* EX_OK, EX_USAGE */
int usage(char *s) {
fprintf(stderr, "Usage: %s [-et]\n", s);
@ -36,17 +36,17 @@ int main(int argc, char *argv[]) {
showend = 0;
showtab = 0;
if(!argc > 0) { usage(argv[0]); }
while ((c = getopt(argc, argv, "et")) != -1) {
switch(c){
case 'e': showend = 1; break;
case 't': showtab = 1; break;
default: return usage(argv[0]);
if (argc > 0) {
while ((c = getopt(argc, argv, "et")) != -1) {
switch (c){
case 'e': showend = 1; break;
case 't': showtab = 1; break;
default: return usage(argv[0]);
}
}
}
if(argc > optind) { return usage(argv[0]); }
if (argc > optind) { return usage(argv[0]); }
while ((c = getc(stdin)) != EOF) {
if ((c & 0x80) != 0) { fputs("M-", stdout); }
@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
case 0x7f: fputs("^?", stdout); break;
case '\n': if (showend) { putc('$', stdout); }
default:
if(c >= ' ' || c == '\n' || (!showtab && c == '\t')) {
if (c >= ' ' || c == '\n' || (!showtab && c == '\t')) {
putc(c, stdout);
} else {
fprintf(stdout, "^%c", c + '@');

View File

@ -18,7 +18,7 @@
*/
#include <stdio.h> /* fprintf(3), stderr */
#include <sysexits.h>
#include <sysexits.h> /* EX_OK, EX_USAGE */
static char *program_name = "strcmp";
@ -36,11 +36,11 @@ int main(int argc, char *argv[]) {
}
for (; *argv[1] != '\0'; ++argv[1]) {
for(i = 2; i < argc; ++i) {
for (i = 2; i < argc; ++i) {
if (*argv[i-1] > *argv[i]) {
return 1;
} else if (*argv[i-1] < *argv[i]++) {
return 255;
return -1; /* actually 255 */
}
}
}