?? mkentry.c
字號:
perror(""); return(NULL); } /* * determine the size of the file */ if (fstat(fileno(stream), &statbuf) < 0) { fprintf(stderr, "%s: cannot stat how to build file: %s: ", program, filename); perror(""); return(NULL); } if (statbuf.st_size > MAX_BUILD_SIZE) { fprintf(stderr, "%s: FATAL: the how to build file: %s, is %d bytes long\n", program, filename, statbuf.st_size); fprintf(stderr, "%s: it may not be longer than %d bytes\n", program, MAX_BUILD_SIZE); return(NULL); } /* return the open file */ return(stream);}/* * open_program - open/check the program source file * * The program source file must be <= 3217 bytes. The number of * non-whitespace and }{; chars not followed by whitespace must * be <= 1536 bytes. * * This function returns NULL on I/O or size error. */FILE *open_program(filename) char *filename;{ FILE *stream; /* the opened file stream */ struct stat statbuf; /* the status of the open file */ int count; /* special count size */ int c; /* the character read */ /* * open the program source input file */ stream = fopen(filename, "r"); if (stream == NULL) { fprintf(stderr, "%s: cannot open program source file: %s: ", program, filename); perror(""); exit(7); } /* * determine the size of the file */ if (fstat(fileno(stream), &statbuf) < 0) { fprintf(stderr, "%s: cannot stat program source file: %s: ", program, filename); perror(""); return(NULL); } if (statbuf.st_size > MAX_PROGRAM_SIZE) { fprintf(stderr, "%s: FATAL: the program source file: %s, is %d bytes long\n", program, filename, statbuf.st_size); fprintf(stderr, "%s: it may not be longer than %d bytes\n", program, MAX_PROGRAM_SIZE); return(NULL); } /* * count the non-whitespace, non {}; followed by whitespace chars */ count = 0; c = 0; while ((c=fgetc(stream)) != EOF) { /* look at non-whitespace */ if (!isascii(c) || !isspace(c)) { switch (c) { case '{': /* count if not followed by EOF or whitespace */ case '}': case ';': /* peek at next char */ c = fgetc(stream); if (c != EOF && isascii(c) && !isspace(c)) { /* not followed by whitespace or EOF, count it */ ungetc(c, stream); ++count; } break; default: ++count; break; } } } /* watch for I/O errors */ check_io(stream, filename, EOF_OK); /* look at the special size */ if (count > MAX_PROGRAM_SIZE2) { fprintf(stderr, "%s: FATAL: the number of bytes that are non-whitespace, and\n", program); fprintf(stderr, "%s: that are not '{', '}', ';' followed by whitespace\n", program); fprintf(stderr, "%s: or EOF must be <= %d bytes\n", program, MAX_PROGRAM_SIZE2); fprintf(stderr, "%s: in %s, %d bytes were found\n", program, filename, count); return(NULL); } /* return the open file */ rewind(stream); return(stream);}/* * open_output - open/check the entry output file * * This function returns NULL on open error. */FILE *open_output(filename) char *filename;{ FILE *stream; /* the opened file stream */ /* * open the ioccc entry output file */ stream = fopen(filename, "w"); if (stream == NULL) { fprintf(stderr, "%s: cannot open ioccc entry file for output: %s: ", program, filename); perror(""); exit(8); } /* return the open file */ return(stream);}/* * output_entry - output the ---entry--- section * * Read the needed information form stdin, and write the entry section. */voidoutput_entry(output, oname) FILE *output; /* entry's output file stream */ char *oname; /* name of the output file */{ char title[MAX_TITLE_LEN+1+1]; /* the entry's title */ char buf[MAX_COL+1+1]; /* I/O buffer */ int entry=0; /* entry number */ int ret; /* fields processed by fscanf */ int ok_line=0; /* 0 => the line is not ok */ char skip; /* input to skip */ FILE *date_pipe; /* pipe to a date command */ time_t epoch_sec; /* seconds since the epoch */ char *p; /* * write the start of the section */ fprintf(output, "---entry---\n"); check_io(output, oname, EOF_NOT_OK); /* * write the rule year */ fprintf(output, "rule:\t%d\n", RULE_YEAR); check_io(output, oname, EOF_NOT_OK); /* determine if this is a fix */ printf("Is this a fix, update or resubmittion to a "); printf("previous entry (enter y or n)? "); while (get_line(buf, 1+1, 0) <= 0 || !(buf[0]=='y' || buf[0]=='n')) { printf("\nplease answer y or n: "); } if (buf[0] == 'y') { fprintf(output, "fix:\ty\n"); check_io(output, oname, EOF_NOT_OK); printf("\nBe sure that the title and entry number that you give\n"); printf("are the same of as the entry you are replacing\n"); } else { fprintf(output, "fix:\tn\n"); check_io(output, oname, EOF_NOT_OK); } /* * write the title */ printf("\nYour title must match expression be a [a-zA-Z0-9_=] character\n"); printf("followed by 0 to %d more [a-zA-Z0-9_=+-] characters.\n\n", MAX_TITLE_LEN-1); printf("It is suggested, but not required, that the title should\n"); printf("incorporate your username; in the\n"); printf("case of multiple authors, consider using parts of the usernames\n"); printf("of the authors.\n\n"); printf("enter your title: "); do { /* prompt and read a line */ if ((ok_line = get_line(title, MAX_TITLE_LEN+1, MAX_COL-9)) <= 0) { printf("\ntitle is too long, please re-enter: "); continue; } /* verify the pattern, not everyone has regexp, so do it by hand */ if (!isascii((int)title[0]) || !(isalnum((int)title[0]) || title[0] == '_' || title[0] == '=')) { printf("\ninvalid first character in the title\n\n"); printf("enter your title: "); ok_line = 0; } else { for (p=(&title[1]); *p != '\0' && *p != '\n'; ++p) { if (!isascii((int)*p) || !(isalnum((int)*p) || *p == '_' || *p == '=' || *p == '+' || *p == '-')) { printf("\ninvalid character in the title\n\n"); printf("enter your title: "); ok_line = 0; } } } } while (ok_line <= 0); fprintf(output, "title:\t%s", title); check_io(output, oname, EOF_NOT_OK); /* * write the entry number */ printf("\nEach person may submit up to %d entries per year.\n\n", MAX_ENTRY); printf("enter an entry number from 0 to %d inclusive: ", MAX_ENTRY-1); do { /* get a valid input line */ fflush(stdout); ret = fscanf(stdin, "%d[\n]", &entry); check_io(stdin, "stdin", EOF_NOT_OK); /* skip over input until newline is found */ do { skip = fgetc(stdin); check_io(stdin, "stdin", EOF_NOT_OK); if (skip != '\n') { /* bad text in input, invalidate entry number */ entry = -1; } } while (skip != '\n'); /* check if we have a number, and if it is in range */ if (ret != 1 || entry < 0 || entry > MAX_ENTRY-1) { printf( "\nThe entry number must be between 0 and %d inclusive\n\n", MAX_ENTRY-1); printf("enter the entry number: "); } } while (ret != 1 || entry < 0 || entry > MAX_ENTRY-1); fprintf(output, "entry:\t%d\n", entry); check_io(output, oname, EOF_NOT_OK); /* * write the submission date */ /* returns a newline */ epoch_sec = time(NULL); fprintf(output, "date:\t%s", asctime(gmtime(&epoch_sec))); check_io(output, oname, EOF_NOT_OK); /* * write the OS/machine host information */ printf( "\nEnter the machine(s) and OS(s) under which your entry was tested.\n"); output_till_dot(output, oname, "host:");}/* * output_remark - output the ---remark--- section * * Read the needed information form stdin, and write the entry section. */voidoutput_remark(output, oname, remark, rname) FILE *output; /* entry's output file stream */ char *oname; /* name of the output file */ FILE *remark; /* stream to the file containing remark text */ char *rname; /* name of the remark file */{ char buf[BUFSIZ+1]; /* input/output buffer */ /* * write the start of the section */ fprintf(output, "---remark---\n"); check_io(output, oname, EOF_NOT_OK); /* * copy the remark file to the section */ while (fgets(buf, BUFSIZ, remark) != NULL) { fputs(buf, output); check_io(output, oname, EOF_NOT_OK); } check_io(remark, rname, EOF_OK); /* be sure that the remark section ends with a newline */ if (buf[strlen(buf)-1] != '\n') { fputc('\n', output); check_io(output, oname, EOF_NOT_OK); }}/* * output_author - output the ---author--- section * * Read the needed information from stdin, and write the author section. * If multiple authors exist, multiple author sections will be written. */voidoutput_author(output, oname) FILE *output; /* entry's output file stream */ char *oname; /* name of the output file */{ char buf[MAX_COL+1+1]; /* I/O buffer */ int more_auths; /* TRUE => more authors to note */ int auth_cnt=0; /* number of authors processed */ /* * prompt the user for the author section */ printf("\nEnter information about each author. If your entry is after\n"); printf("%s and before the contest deadline, the judges\n", START_DATE); printf("will attempt to Email back a confirmation to the first author\n"); /* * place author information for each author in an individual section */ do { /* write the start of the section */ fprintf(output, "---author---\n"); check_io(output, oname, EOF_NOT_OK); /* write the author */ printf("\nAuthor #%d name: ", ++auth_cnt); while (get_line(buf, MAX_COL+1, MAX_COL-9) <= 0) { printf("\nname too long, please re-enter: "); } fprintf(output, "name:\t%s", buf); check_io(output, oname, EOF_NOT_OK); /* write the organization */ printf("\nEnter the School/Company/Organization of author #%d\n", auth_cnt); printf("\nAuthor #%d org: ", auth_cnt); while (get_line(buf, MAX_COL+1, MAX_COL-9) <= 0) { printf("\nline too long, please re-enter: "); } fprintf(output, "org:\t%s", buf); check_io(output, oname, EOF_NOT_OK); /* write the address */ printf( "\nEnter the postal address for author #%d. Be sure to include\n", auth_cnt); printf("your country and do not include your name.\n"); output_till_dot(output, oname, "addr:"); /* write the Email address */ printf( "\nEnter the Email address for author #%d. Use an address from\n", auth_cnt); printf( "a registered domain or well known site. If you give several\n"); printf("forms, list them one per line.\n"); output_till_dot(output, oname, "email:"); /* write the anonymous status */ printf("\nShould author #%d remain anonymous (enter y or n)? ", auth_cnt); while (get_line(buf, 1+1, 0) <= 0 || !(buf[0]=='y' || buf[0]=='n')) { printf("\nplease answer y or n: "); } fprintf(output, "anon:\t%s", buf); check_io(output, oname, EOF_NOT_OK); /* determine if there is another author */ printf("\nIs there another author (enter y or n)? "); while (get_line(buf, 1+1, 0) <= 0 || !(buf[0]=='y' || buf[0]=='n')) { printf("\nplease answer y or n: "); } if (buf[0] == 'y') { more_auths = TRUE; } else { more_auths = FALSE; } } while (more_auths == TRUE);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -