/* Program SLOWLOOK */ /* A program to read a file and output the file SLOWLY. */ /* ----------------- * Modification history: * 5/5/1997 - dde - add a fflush() call after the putchar. * 6/17/1998 - dde - use "usleep()" system call instead of a * delay loop. * 6/24/2001 - dde - make the numerator of the divide be * 6000000 rather than 1000000, to make the * arg more like a baud rate. *************************************************************/ #include #include void main(int argc, char **argv) { int lnno; /* Line number counter */ char line[90], ch[2]; /* Single character string. */ int chr; /* Single character input */ unsigned i; /* loop counter */ unsigned long loopval; int succ; /* sscanf success. */ lnno = 0; ch[1] = '\0'; /* Make ch look like a 1-character string. */ /* Get argument if provided. */ succ = 0; /* Assume sscanf failed. */ if (argc > 1) { succ = sscanf(argv[1],"%ld", &loopval); loopval = 6000000 / loopval; /* Do it in thousands. */ } if(succ == 0) loopval = 6000000 / 600; /* Simulate 600 baud. */ while ((chr = getchar()) != EOF) { usleep(loopval) /* New, 6/17/1998, dde */ ; if (chr == '\n') ++lnno; putchar(chr); fflush(stdout); /* Line new, 5/5/1997, dde */ } printf("\n\n Number of lines output: %d\n",lnno); }