📄 mkentry.c
字号:
/* @(#)mkentry.c 1.20 3/1/92 16:13:00 *//* * mkentry - make an International Obfuscated C Code Contest entry * * usage: * mkentry -r remarks -b build -p prog.c -o ioccc.entry * * -r remarks file with remarks about the entry * -b build file containing how prog.c should be built * -p prog.c the obfuscated program source file * -o ioccc.entry ioccc entry output file * * compile by: * cc mkentry.c -o mkentry *//* * Copyright (c) 1992, Landon Curt Noll & Larry Bassel. * All Rights Reserved. Permission for personal, education or non-profit use * is granted provided this this copyright and notice are included in its * entirety and remains unaltered. All other uses must receive prior * permission in writing from both Landon Curt Noll and Larry Bassel. *//* * Placed in the public domain by Landon Curt Noll, 1992. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//* * WARNING: * * This program attempts to implement the IOCCC rules. Every attempt * has been made to make sure that this program produces an entry that * conforms to the contest rules. In all cases, where this program * differs from the contest rules, the contest rules will be used. Be * sure to check with the contest rules before submitting an entry. * * Send questions or comments (but not entries) about the contest, to: * * ...!{sun,pacbell,uunet,pyramid}!hoptoad!judges * judges@toad.com * * The rules and the guidelines may (and often do) change from year to * year. You should be sure you have the current rules and guidelines * prior to submitting entries. The IOCCC rules, guidelines and mkentry * program may be obtained from the judges using the Email address above. * Please use the following subject when sending in your request: * * send rules * * Because contest rules change from year to year, one should only use this * program for the year that it was intended. Be sure that the RULE_YEAR * define below matches this current year. */#include <stdio.h>#include <ctype.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>/* logic */#ifndef TRUE# define TRUE 1#endif /* TRUE */#ifndef FALSE# define FALSE 0#endif /* FALSE */#define EOF_OK TRUE#define EOF_NOT_OK FALSE/* global limits */#define RULE_YEAR 1992 /* NOTE: should match the current year */#define START_DATE "1Mar92 0:00 UTC" /* first confirmation received */#define MAX_COL 79 /* max column a line should hit */#define MAX_BUILD_SIZE 256 /* max how to build size */#define MAX_PROGRAM_SIZE 3217 /* max program source size */#define MAX_PROGRAM_SIZE2 1536 /* max program source size not counting whitespace and {}; not followed by whitespace or EOF */#define MAX_TITLE_LEN 10 /* max chars in the title */#define MAX_ENTRY_LEN 1 /* max length in the entry input line */#define MAX_ENTRY 8 /* max number of entries per person per year */#define MAX_FILE_LEN 1024 /* max filename length for a info file *//* where to send entries */#define ENTRY_ADDR1 "...!{apple,pyramid,sun,uunet}!hoptoad!obfuscate"#define ENTRY_ADDR2 "obfuscate@toad.com"/* uuencode process - assumes ASCII */#define UUENCODE(c) (((c)=='\0') ? '`' : (((c)&0x3f)+' '))#define UUENCODE_LEN 45 /* max uuencode chunk size */#define UUINFO_MODE 0444 /* mode of an info file's uuencode file */#define UUBUILD_MODE 0444 /* mode of the build file's uuencode file */#define UUBUILD_NAME "build" /* name for the build file's uuencode file */#define UUPROG_MODE 0444 /* mode of the program's uuencode file */#define UUPROG_NAME "prog.c" /* name for the program's uuencode file *//* global declarations */char *program; /* our name */long start_time; /* the startup time *//* forward declarations */void parse_args();void usage();FILE *open_remark();FILE *open_build();FILE *open_program();FILE *open_output();void output_entry();void output_remark();void output_author();void output_info();void output_build();void output_program();void output_end();int get_line();void output_till_dot();int col_len();void check_io();void uuencode();main(argc, argv) int argc; /* arg count */ char **argv; /* the args */{ FILE *remark=NULL; /* open remarks stream */ FILE *build=NULL; /* open build file stream */ FILE *prog=NULL; /* open program stream */ FILE *output=NULL; /* open output stream */ char *rname=NULL; /* file with remarks about the entry */ char *bname=NULL; /* file containing how prog.c should be built */ char *pname=NULL; /* the obfuscated program source file */ char *oname=NULL; /* ioccc entry output file */ struct tm *tm; /* startup time structure */ /* * check on the year */ start_time = time((long *)0); tm = gmtime(&start_time); if (tm->tm_year != RULE_YEAR-1900) { fprintf(stderr, "%s: WARNING: this program applies to %d, which differ from %d\n\n", argv[0], RULE_YEAR, 1900+tm->tm_year); } /* * parse the command line args */ parse_args(argc, argv, &rname, &bname, &pname, &oname); /* * open/check the input and output files * * We open and truncate the output file first, in case it is the same * as one of the input files. */ output = open_output(oname); remark = open_remark(rname); build = open_build(bname); prog = open_program(pname); if (output==NULL || remark==NULL || build==NULL || prog==NULL) { exit(1); } /* * output each section */ output_entry(output, oname); output_remark(output, oname, remark, rname); output_author(output, oname); output_info(output, oname); output_build(output, oname, build, bname); output_program(output, oname, prog, pname); output_end(output, oname); /* * flush the output */ if (fflush(output) == EOF) { fprintf(stderr, "%s: flush error in %s: ", program, oname); perror(""); exit(2); } /* * final words */ printf("\nYour entry can be found in %s. You should check this file\n", oname); printf("correct any problems and verify that the uudecode utility will\n"); printf("correctly decode your build file and program.\n\n"); printf("This program has been provided as a guide for submitters. In\n"); printf("cases where it conflicts with the rules, the rules shall apply.\n"); printf("It is your responsibility to ensure that your entry conforms to\n"); printf("the current rules.\n\n"); printf("Email your entries to:\n"); printf("\t%s\n", ENTRY_ADDR1); printf("\t%s\n\n", ENTRY_ADDR2); printf("Please use the following subject when you Email your entry:\n"); printf("\tioccc entry\n\n"); /* all done */ exit(0);}/* * parse_args - parse the command line args * * Given the command line args, this function parses them and sets the * required name flags. This function will return only if the command * line syntax is correct. */voidparse_args(argc, argv, rname, bname, pname, oname) int argc; /* arg count */ char **argv; /* the args */ char **rname; /* file with remarks about the entry */ char **bname; /* file containing how prog.c should be built */ char **pname; /* the obfuscated program source file */ char **oname; /* ioccc entry output file */{ char *optarg; /* -flag option operand */ int flagname; /* the name of the -flag */ int i; /* * Not everyone has getopt, so we must parse args by hand. */ program = argv[0]; for (i=1; i < argc; ++i) { /* determine the flagname */ if (argv[i][0] != '-') { usage(1); /*NOTREACHED*/ } flagname = (int)argv[i][1]; /* determine the flag's operand */ if (flagname != '\0' && argv[i][2] != '\0') { optarg = &argv[i][2]; } else { if (i+1 >= argc) { usage(2); /*NOTREACHED*/ } else { optarg = argv[++i]; } } /* save the flag's operand in the correct global variable */ switch (flagname) { case 'r': *rname = optarg; break; case 'b': *bname = optarg; break; case 'p': *pname = optarg; break; case 'o': *oname = optarg; break; default: usage(3); /*NOTREACHED*/ } } /* * verify that we have all of the required flags */ if (*rname == NULL || *bname == NULL || *pname == NULL || *oname == NULL) { usage(4); /*NOTREACHED*/ } return;}/* * usage - print a usage message and exit * * This function does not return. */voidusage(exitval) int exitval; /* exit with this value */{ fprintf(stderr, "usage: %s -r remarks -b build -p prog.c -o ioccc.entry\n\n", program); fprintf(stderr, "\t-r remarks\tfile with remarks about the entry\n"); fprintf(stderr, "\t-b build\tfile containing how prog.c should be built\n"); fprintf(stderr, "\t-p prog.c\tthe obfuscated program source file\n"); fprintf(stderr, "\t-o ioccc.entry\tioccc entry output file\n"); exit(exitval);}/* * open_remark - open/check the remark file * * The remark file should be indented by 4 spaces, and should not extend * beyond column MAX_COL. These are not requirements, so we only warn. * * This function returns NULL on I/O or format error. */FILE *open_remark(filename) char *filename;{ FILE *stream; /* the opened file stream */ char buf[BUFSIZ+1]; /* input buffer */ int toolong=0; /* number of lines that are too long */ int non_indent=0; /* number of lines not indented by 4 spaces */ /* * open the remark input file */ stream = fopen(filename, "r"); if (stream == NULL) { fprintf(stderr, "%s: cannot open remark file: %s: ", program, filename); perror(""); return(NULL); } /* * look at each line */ while (fgets(buf, BUFSIZ, stream) != NULL) { /* count lines that do not start with 4 spaces */ if (buf[0] != '\n' && strncmp(buf, " ", 4) != 0) { ++non_indent; } /* count long lines */ if (col_len(buf) > MAX_COL) { /* found a line that is too long */ ++toolong; } } /* watch for I/O errors */ check_io(stream, filename, EOF_OK); /* note long lines if needed */ if (toolong > 0) { fprintf(stderr, "%s: WARNING: %d line(s) from %s extend beyond the 80th column\n", program, toolong, filename); fprintf(stderr, "%s: This is ok, but it would be nice to avoid\n\n", program); } /* note non-indented lines, if needed */ if (non_indent > 0) { fprintf(stderr, "%s: WARNING: %d line(s) from %s are not indented by 4 spaces\n", program, non_indent, filename); fprintf(stderr, "%s: This is ok, but it would be nice to avoid\n\n", program); } /* return the open file */ rewind(stream); return(stream);}/* * open_build - open/check the build file * * The how to build file must not be longer than MAX_BUILD_SIZE bytes. * * This function returns NULL on I/O or size error. */FILE *open_build(filename) char *filename;{ FILE *stream; /* the opened file stream */ struct stat statbuf; /* the status of the open file */ /* * open the how to build input file */ stream = fopen(filename, "r"); if (stream == NULL) { fprintf(stderr, "%s: cannot open how to build file: %s: ", program, filename); perror(""); return(NULL); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -