mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-27 14:50:23 +05:30
99 lines
2.1 KiB
C
99 lines
2.1 KiB
C
/*
|
|
* extol.modern.c [joke!]
|
|
*
|
|
* A modern C version of extol.c
|
|
*
|
|
* Author: Intel A80486DX2-66
|
|
* License: Creative Commons Zero 1.0 Universal
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
enum
|
|
{
|
|
EXTOL_NORMAL,
|
|
EXTOL_QUIET
|
|
} EXTOL_MODE;
|
|
|
|
#define EXTOL_PROTOTYPE "int extol(FILE* file)"
|
|
#define EXTOL_FILE_NAME "extol.txt"
|
|
#define EXTOL_FILE_LIMIT 128
|
|
|
|
int extol(FILE *file);
|
|
int extol_interface(int type);
|
|
void extol_quiet(void);
|
|
|
|
int extol(FILE *file)
|
|
{
|
|
static bool spec_run = true;
|
|
int result;
|
|
off_t size;
|
|
|
|
if (spec_run == false)
|
|
{
|
|
printf("\n");
|
|
return !(spec_run = true) - spec_run;
|
|
}
|
|
|
|
if (file == NULL)
|
|
{
|
|
FILE *file_handler = fopen(EXTOL_FILE_NAME, "a");
|
|
if (file_handler == NULL)
|
|
{
|
|
perror("fopen");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
fseek(file_handler, 0L, SEEK_END);
|
|
size = ftello(file_handler);
|
|
if (size == -1)
|
|
{
|
|
perror("ftello");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
else if (size > EXTOL_FILE_LIMIT)
|
|
{
|
|
FILE *new_file_handler =
|
|
freopen(EXTOL_FILE_NAME, "w", file_handler);
|
|
if (new_file_handler == NULL)
|
|
{
|
|
perror("freopen");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
file_handler = new_file_handler;
|
|
}
|
|
result = extol(file_handler);
|
|
for (uint_fast8_t i = 0; i < 16; i++)
|
|
fputc('=', file_handler);
|
|
fprintf(file_handler, "\n");
|
|
fclose(file_handler);
|
|
}
|
|
else
|
|
{
|
|
result = fprintf(file, "PRAISE THE USER!\n");
|
|
}
|
|
spec_run = false;
|
|
return result;
|
|
}
|
|
|
|
int extol_interface(int type)
|
|
{
|
|
return printf(EXTOL_PROTOTYPE " returns %d\n",
|
|
extol(type == EXTOL_NORMAL ? stdout : NULL));
|
|
}
|
|
|
|
void extol_quiet(void)
|
|
{
|
|
extol_interface(EXTOL_QUIET);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
for (uint_fast8_t i = 0; i < 2; i++)
|
|
printf(EXTOL_PROTOTYPE ": %d\n", extol_interface(EXTOL_NORMAL));
|
|
atexit(&extol_quiet);
|
|
return 0;
|
|
}
|