Files
ioccc/2004/hibachi/src-alt/ioccc.c
T
Cody Boone Ferguson 0d65af1b2b Add unobfuscated code from @SirWumpus
The entries 2004/hibachi and 2005/mynx have unobfuscated code now.

2004/hibachi has a configure script that is used along the lines of the
original entry (with some adjustments and fixes) and the hibachi.alt.c
had to have ctype.h included too. The directory src/localhost was copied
to src-alt/localhost but the rest of src/ was from Anthony. The Makefile
had to be updated to build this version.

2005/mynx does have a configure script but it is, just like the original
entry, unused and so the unobfuscated (in source-alt/) is also unused.
The mynx.alt.c was changed to mynx.alt2.c and the unobfuscated code was
made mynx.alt.c.

Updated manifest, rebuilt .entry.json and index.html files.

After a question is answered and taken care of (in one of 199[1-3]/ant -
not sure which one) issue #2513 can possibly be closed as complete
(though the manifest updates will have to be looked at more when 2004
and 2005 are reviewed).
2024-07-08 13:11:00 -07:00

118 lines
2.4 KiB
C

/*
* ioccc.c IOCCC 2001 Source Size Rule
*
* Public Domain 1992 by Anthony Howe. All rights released.
*
*
* SYNOPSIS
*
* ioccc [-s]
*
* DESCRIPION
*
* Taking input from standard input, apply the IOCCC Source Size
* Rule for 2001. The program's offical length is written to
* standard error. Also filter out C comment blocks sending the
* modified source to standard output.
*
* The 2001 Source Size Rule is:
*
* Your entry must be <= 4096 bytes in length. The number of characters
* excluding whitespace (tab, space, newline, formfeed, return), and
* excluding any ';', '{' or '}' followed by whitespace or end of file,
* must be <= 2048.
*
* The -s option siliences standard output.
*
* NOTE the overall length is not counted since this can be checked
* with "ls -l".
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
char usage_err[] = "usage: ioccc [-s]\n";
int count(int silience);
int
main(int argc, char **argv)
{
char *ap;
int silence = 0;
for (--argc, ++argv; 0 < argc && **argv == '-'; --argc, ++argv) {
ap = &argv[0][1];
if (*ap == '-' && ap[1] == '\0') {
--argc;
++argv;
break;
}
while (*ap != '\0') {
switch (*ap++) {
case 's':
silence = 1;
break;
default:
fprintf(stderr, usage_err);
return (2);
}
break;
}
}
(void) count(silence);
return (0);
}
/*
* Count chacacters and strip comments. The stripped input is
* sent to standard output. The count of character is sent to
* to standard error.
*
* If silence is true, then do not print anything to standard output.
*/
int
count(int silence)
{
int i, j, k;
char *p, buf[256];
for (i = k = 0; fgets(buf, 256, stdin) != NULL;) {
for (p = buf; *p != '\0'; ++p) {
if (k == 1) {
if (*p == '*' && p[1] == '/') {
/* End of comment. */
k = 0;
++p;
}
/* Skip characters in comment block. */
continue;
}
if (*p == '/' && p[1] == '*') {
/* Begin comment block. */
k = 1;
++p;
continue;
}
/* Everything above here is stripped from the input. */
if (!silence)
putchar(*p);
/* Ignore all whitespace. */
if (isspace(*p))
continue;
/* Ignore curly braces and semicolons when followed
* by any whitspace or EOF.
*/
if (strchr("{;}", *p) != NULL
&& (isspace(p[1]) || p[1] == '\0'))
continue;
/* Count this character. */
++i;
}
}
fprintf(stderr, "%d\n", i);
return (i);
}