Compare commits
8 Commits
34cd715e37
...
26b0c93f4d
Author | SHA1 | Date | |
---|---|---|---|
26b0c93f4d | |||
35a20dca79 | |||
8421f8be87 | |||
0c530dffbf | |||
d9dd4e6057 | |||
1dfad87e87 | |||
99f2b2963a | |||
666c621a02 |
7
src/dj.c
7
src/dj.c
@ -23,7 +23,7 @@
|
|||||||
#include <stdio.h> /* fprintf(3), stderr */
|
#include <stdio.h> /* fprintf(3), stderr */
|
||||||
#include <stdlib.h> /* malloc(3), strtol(3), size_t */
|
#include <stdlib.h> /* malloc(3), strtol(3), size_t */
|
||||||
#include <string.h> /* memcpy(3), memmove(3), memset(3) */
|
#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),
|
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
||||||
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
||||||
#include <sys/stat.h> /* S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR */
|
#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) {
|
if ((t = write(io->fd, io->buf, io->bufuse)) < 0) {
|
||||||
io->error = errno;
|
io->error = errno;
|
||||||
t = 0;
|
t = 0;
|
||||||
} else if (t > 0)
|
} else if (t > 0) {
|
||||||
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
|
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
|
||||||
|
}
|
||||||
|
|
||||||
io->bytes += t;
|
io->bytes += t;
|
||||||
io->prec += (t > 0 && io->bufuse > 0);
|
io->prec += (t > 0 && io->bufuse > 0);
|
||||||
@ -175,7 +176,7 @@ int main(int argc, char *argv[]) {
|
|||||||
io[i].seek = 0;
|
io[i].seek = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!argc < 0) { usage(program_name); }
|
if (!(argc < 0)) { usage(program_name); }
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
21
src/intcmp.c
21
src/intcmp.c
@ -21,7 +21,7 @@
|
|||||||
#include <stdio.h> /* fprintf(3), stderr */
|
#include <stdio.h> /* fprintf(3), stderr */
|
||||||
#include <stdlib.h> /* strtol(3), size_t, EXIT_FAILURE */
|
#include <stdlib.h> /* strtol(3), size_t, EXIT_FAILURE */
|
||||||
#include <unistd.h> /* getopt(3), optind */
|
#include <unistd.h> /* getopt(3), optind */
|
||||||
#include <sysexits.h>
|
#include <sysexits.h> /* EX_OK, EX_USAGE */
|
||||||
|
|
||||||
/* 0b00? */ /* Equal | -e | 0b001 | 1 */
|
/* 0b00? */ /* Equal | -e | 0b001 | 1 */
|
||||||
#define EQUAL 0x01 /* Greater | -g | 0b010 | 2 */
|
#define EQUAL 0x01 /* Greater | -g | 0b010 | 2 */
|
||||||
@ -33,10 +33,8 @@
|
|||||||
static char *program_name = "intcmp";
|
static char *program_name = "intcmp";
|
||||||
|
|
||||||
int usage(char *s) {
|
int usage(char *s) {
|
||||||
fprintf(
|
fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s);
|
||||||
stderr, "Usage: %s [-egl] integer integer...\n",
|
|
||||||
s == NULL ? program_name : s
|
|
||||||
);
|
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,25 +43,26 @@ int main(int argc, char *argv[]) {
|
|||||||
size_t i;
|
size_t i;
|
||||||
unsigned char mode;
|
unsigned char mode;
|
||||||
int r; /* reference integer */
|
int r; /* reference integer */
|
||||||
|
char *s = (argv[0] == NULL ? program_name : argv[0]);
|
||||||
|
|
||||||
mode = 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) {
|
while ((c = getopt(argc, argv, "egl")) != -1) {
|
||||||
switch(c){
|
switch (c){
|
||||||
case 'e': mode |= EQUAL; break;
|
case 'e': mode |= EQUAL; break;
|
||||||
case 'g': mode |= GREATER; break;
|
case 'g': mode |= GREATER; break;
|
||||||
case 'l': mode |= LESSER; 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;
|
i = optind;
|
||||||
|
|
||||||
do{
|
do {
|
||||||
r = c;
|
r = c;
|
||||||
c = strtol(argv[i], &argv[i], 10);
|
c = strtol(argv[i], &argv[i], 10);
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|| (!(mode & GREATER) && r > c)
|
|| (!(mode & GREATER) && r > c)
|
||||||
|| (!(mode & LESSER) && r < c)
|
|| (!(mode & LESSER) && r < c)
|
||||||
) { return 1; }
|
) { return 1; }
|
||||||
} while(++i < argc);
|
} while (++i < argc);
|
||||||
|
|
||||||
return EX_OK;
|
return EX_OK;
|
||||||
}
|
}
|
||||||
|
4
src/mm.c
4
src/mm.c
@ -24,8 +24,8 @@
|
|||||||
#include <stdlib.h> /* free(3), realloc(3) */
|
#include <stdlib.h> /* free(3), realloc(3) */
|
||||||
#include <string.h> /* strcmp(3), strerror(3) */
|
#include <string.h> /* strcmp(3), strerror(3) */
|
||||||
#include <unistd.h> /* getopt(3) */
|
#include <unistd.h> /* getopt(3) */
|
||||||
#include <sysexits.h>
|
#include <sysexits.h> /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */
|
||||||
#endif
|
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
/* This structure is how open files are tracked. */
|
/* This structure is how open files are tracked. */
|
||||||
|
22
src/npc.c
22
src/npc.c
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout,
|
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), putc(3), stdin, stdout,
|
||||||
* EOF */
|
* EOF */
|
||||||
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
#include <stdlib.h> /* EXIT_FAILURE */
|
||||||
#include <unistd.h> /* getopt(3) */
|
#include <unistd.h> /* getopt(3) */
|
||||||
#include <sysexits.h>
|
#include <sysexits.h> /* EX_OK, EX_USAGE */
|
||||||
|
|
||||||
int usage(char *s) {
|
int usage(char *s) {
|
||||||
fprintf(stderr, "Usage: %s [-et]\n", s);
|
fprintf(stderr, "Usage: %s [-et]\n", s);
|
||||||
@ -36,17 +36,17 @@ int main(int argc, char *argv[]) {
|
|||||||
showend = 0;
|
showend = 0;
|
||||||
showtab = 0;
|
showtab = 0;
|
||||||
|
|
||||||
if(!argc > 0) { usage(argv[0]); }
|
if (argc > 0) {
|
||||||
|
while ((c = getopt(argc, argv, "et")) != -1) {
|
||||||
while ((c = getopt(argc, argv, "et")) != -1) {
|
switch (c){
|
||||||
switch(c){
|
case 'e': showend = 1; break;
|
||||||
case 'e': showend = 1; break;
|
case 't': showtab = 1; break;
|
||||||
case 't': showtab = 1; break;
|
default: return usage(argv[0]);
|
||||||
default: return usage(argv[0]);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc > optind) { return usage(argv[0]); }
|
if (argc > optind) { return usage(argv[0]); }
|
||||||
|
|
||||||
while ((c = getc(stdin)) != EOF) {
|
while ((c = getc(stdin)) != EOF) {
|
||||||
if ((c & 0x80) != 0) { fputs("M-", stdout); }
|
if ((c & 0x80) != 0) { fputs("M-", stdout); }
|
||||||
@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case 0x7f: fputs("^?", stdout); break;
|
case 0x7f: fputs("^?", stdout); break;
|
||||||
case '\n': if (showend) { putc('$', stdout); }
|
case '\n': if (showend) { putc('$', stdout); }
|
||||||
default:
|
default:
|
||||||
if(c >= ' ' || c == '\n' || (!showtab && c == '\t')) {
|
if (c >= ' ' || c == '\n' || (!showtab && c == '\t')) {
|
||||||
putc(c, stdout);
|
putc(c, stdout);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, "^%c", c + '@');
|
fprintf(stdout, "^%c", c + '@');
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h> /* fprintf(3), stderr */
|
#include <stdio.h> /* fprintf(3), stderr */
|
||||||
#include <sysexits.h>
|
#include <sysexits.h> /* EX_OK, EX_USAGE */
|
||||||
|
|
||||||
static char *program_name = "strcmp";
|
static char *program_name = "strcmp";
|
||||||
|
|
||||||
@ -36,11 +36,11 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; *argv[1] != '\0'; ++argv[1]) {
|
for (; *argv[1] != '\0'; ++argv[1]) {
|
||||||
for(i = 2; i < argc; ++i) {
|
for (i = 2; i < argc; ++i) {
|
||||||
if (*argv[i-1] > *argv[i]) {
|
if (*argv[i-1] > *argv[i]) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (*argv[i-1] < *argv[i]++) {
|
} else if (*argv[i-1] < *argv[i]++) {
|
||||||
return 255;
|
return -1; /* actually 255 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user