no way to compare when less than two revisions
Diferencias
Muestra las diferencias entre dos versiones de la página.
— | slowcat.c [2022/11/22 18:58] (actual) – creado peron | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
+ | <code c> | ||
+ | /* | ||
+ | * slowcat.c - slow down the display of a file | ||
+ | * copyright (c) 2001, | ||
+ | * | ||
+ | * distributed under the terms of the GNU Public license | ||
+ | * | ||
+ | * There is NO WARRANTY, and NO SUPPORT WHATSOEVER. | ||
+ | * | ||
+ | * building: make slowcat && mv slowcat $HOME/bin | ||
+ | * (assuming that you have a personal bin directory) | ||
+ | * | ||
+ | * usage: slowcat [-d usecs] filename | ||
+ | * where usecs is the number of micro-seconds to delay. | ||
+ | * | ||
+ | * feedback welcome. enjoy! | ||
+ | * ...dave | ||
+ | * | ||
+ | * | ||
+ | * 09/24/07 - modifications to include nanosleep, brian at landsberger.com | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int debug = 0; | ||
+ | |||
+ | int main(int argc, char **argv) { | ||
+ | int c; | ||
+ | unsigned long usecs,s; | ||
+ | FILE *fp; | ||
+ | char *fnam; | ||
+ | struct timespec ts; | ||
+ | |||
+ | if(argc != 2 && argc != 4) { | ||
+ | fprintf(stderr," | ||
+ | exit(1); | ||
+ | } | ||
+ | |||
+ | if(argc == 4 ) { | ||
+ | if( !strncmp(argv[1]," | ||
+ | usecs = strtoul(argv[2], | ||
+ | if(usecs< | ||
+ | usecs = 1; | ||
+ | } | ||
+ | } | ||
+ | if(debug) { | ||
+ | fprintf(stderr," | ||
+ | c = getchar(); | ||
+ | } | ||
+ | fnam = argv[3]; | ||
+ | } | ||
+ | /* set timespec */ | ||
+ | ts.tv_sec=0; | ||
+ | ts.tv_nsec=usecs; | ||
+ | |||
+ | if(argc == 2 ) { | ||
+ | fnam = argv[1]; | ||
+ | } | ||
+ | fp = fopen(fnam," | ||
+ | if(fp == NULL) { | ||
+ | fprintf(stderr," | ||
+ | exit(2); | ||
+ | } | ||
+ | |||
+ | while( (c = fgetc(fp)) != EOF) { | ||
+ | putchar(c); | ||
+ | #ifdef _POSIX_C_SOURCE // assuming >= 199309L | ||
+ | if (debug) { | ||
+ | fprintf(stderr," | ||
+ | } | ||
+ | nanosleep(& | ||
+ | # | ||
+ | if (debug) { | ||
+ | fprintf(stderr," | ||
+ | } | ||
+ | for(s=0; | ||
+ | ; | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | fclose(fp); | ||
+ | return (0); | ||
+ | } | ||
+ | </ |