mirror of
				https://gitlab.com/80486DX2-66/gists
				synced 2025-05-31 08:31:41 +05:30 
			
		
		
		
	C: add extol.c [joke!]
This commit is contained in:
		
							
								
								
									
										75
									
								
								c-programming/jokes/extol.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								c-programming/jokes/extol.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
			
		||||
/*
 | 
			
		||||
 * extol.c [joke!]
 | 
			
		||||
 *
 | 
			
		||||
 * Author: Intel A80486DX2-66
 | 
			
		||||
 * License: Creative Commons Zero 1.0 Universal
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
  EXTOL_NORMAL,
 | 
			
		||||
  EXTOL_QUIET
 | 
			
		||||
} EXTOL_MODE;
 | 
			
		||||
 | 
			
		||||
#define EXTOL_PROTOTYPE "int extol(FILE* f)"
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
extol (FILE *f)
 | 
			
		||||
{
 | 
			
		||||
  static bool spec_run = true;
 | 
			
		||||
  int result;
 | 
			
		||||
 | 
			
		||||
  if (spec_run == false)
 | 
			
		||||
    {
 | 
			
		||||
      printf ("\n");
 | 
			
		||||
      return !(spec_run = true) - spec_run;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
    {
 | 
			
		||||
      FILE *fs = fopen ("extol.txt", "a+");
 | 
			
		||||
      fseek (fs, 0L, SEEK_END);
 | 
			
		||||
      result = extol (fs);
 | 
			
		||||
      for (result <<= 4; (result & 15) != 15; result++)
 | 
			
		||||
        fputc ('=', fs);
 | 
			
		||||
      result >>= 4;
 | 
			
		||||
      fprintf (fs, "\n");
 | 
			
		||||
      fclose (f);
 | 
			
		||||
    }
 | 
			
		||||
  else
 | 
			
		||||
    {
 | 
			
		||||
      result = fprintf (f, "PRAISE THE USER!\n");
 | 
			
		||||
    }
 | 
			
		||||
  spec_run = false;
 | 
			
		||||
  return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
extol_interface (signed char type)
 | 
			
		||||
{
 | 
			
		||||
  FILE *f;
 | 
			
		||||
 | 
			
		||||
  f = type == EXTOL_NORMAL ? stdout : NULL;
 | 
			
		||||
  return printf (EXTOL_PROTOTYPE " returns %d\n", extol (f));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
extol_quiet (void)
 | 
			
		||||
{
 | 
			
		||||
  extol_interface (EXTOL_QUIET);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main (void)
 | 
			
		||||
{
 | 
			
		||||
  int i;
 | 
			
		||||
 | 
			
		||||
  for (i = 0; i < 2; i++)
 | 
			
		||||
    printf (EXTOL_PROTOTYPE ": %d\n", extol_interface (EXTOL_NORMAL));
 | 
			
		||||
  atexit (&extol_quiet);
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user