⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fortune.c

📁 操作系统源代码
💻 C
字号:
/*  fortune  -  hand out Chinese fortune cookies	Author: Bert Reuling */#include <sys/types.h>#include <sys/stat.h>#include <time.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>#define COOKIEJAR "/usr/lib/fortune.dat"static char *Copyright = "\0Copyright (c) 1990 Bert Reuling";static unsigned long seed;_PROTOTYPE(int main, (int argc, char **argv));_PROTOTYPE(unsigned long magic, (unsigned long range));int main(argc, argv)int argc;char *argv[];{  int c1, c2, c3;  struct stat cookie_stat;  FILE *cookie;  if ((cookie = fopen(COOKIEJAR, "r")) == NULL) {	printf("\nSome things better stay closed.\n  - %s\n", argv[0]);	exit (-1);  }  /* Create seed from : date, time, user-id and process-id. we can't get   * the position of the moon, unfortunately.   */  seed = time( (time_t *) 0) ^ (long) getuid() ^ (long) getpid();  if (stat(COOKIEJAR, &cookie_stat) != 0) {	printf("\nIt furthers one to see the super guru.\n  - %s\n", argv[0]);	exit (-1);  }  fseek(cookie, magic((unsigned long) cookie_stat.st_size), 0); /* m ove bu magic... */  c2 = c3 = '\n';  while (((c1 = getc(cookie)) != EOF) && ((c1 != '%') || (c2 != '%') || (c3 != '\n'))) {	c3 = c2;	c2 = c1;  }  if (c1 == EOF) {	printf("\nSomething unexpected has happened.\n  - %s", argv[0]);	exit (-1);  }  c2 = c3 = '\n';  while (((c1 = getc(cookie)) != '%') || (c2 != '%') || (c3 != '\n')) {	if (c1 == EOF) {		rewind(cookie);		continue;	}	putc(c2, stdout);	c3 = c2;	c2 = c1;  }  putc('\n', stdout);  fclose(cookie);  return (0);}/*  magic  -  please study carefull: there is more than meets the eye */unsigned long magic(range)unsigned long range;{  seed = 9065531L * (seed % 9065533L) - 2 * (seed / 9065531L) + 1L;  return (seed % range);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -