| 1 |
/* Copyright (C) 2010 Vincent Penquerc'h. |
| 2 |
This file is part of the Kate codec library. |
| 3 |
Written by Vincent Penquerc'h. |
| 4 |
|
| 5 |
Use, distribution and reproduction of this library is governed |
| 6 |
by a BSD style source license included with this source in the |
| 7 |
file 'COPYING'. Please read these terms before distributing. */ |
| 8 |
|
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
#include <string.h> |
| 13 |
#include <time.h> |
| 14 |
|
| 15 |
static int get_random(int n) |
| 16 |
{ |
| 17 |
return (rand()>>8)%n; |
| 18 |
} |
| 19 |
|
| 20 |
static int time_total_centiseconds(float t) |
| 21 |
{ |
| 22 |
return (int)(t*100.0f+0.5f); |
| 23 |
} |
| 24 |
|
| 25 |
static int time_minutes(float t) |
| 26 |
{ |
| 27 |
return time_total_centiseconds(t)/(60*100); |
| 28 |
} |
| 29 |
|
| 30 |
static int time_seconds(float t) |
| 31 |
{ |
| 32 |
return time_total_centiseconds(t)/100%60; |
| 33 |
} |
| 34 |
|
| 35 |
static int time_centiseconds(float t) |
| 36 |
{ |
| 37 |
return time_total_centiseconds(t)%100; |
| 38 |
} |
| 39 |
|
| 40 |
static void gen_time(float *t,float dt) |
| 41 |
{ |
| 42 |
float r=*t+(rand()/(float)RAND_MAX)*dt; |
| 43 |
*t+=dt; |
| 44 |
printf("[%d:%02d.%02d]",time_minutes(r),time_seconds(r),time_centiseconds(r)); |
| 45 |
} |
| 46 |
|
| 47 |
static void gen_text() |
| 48 |
{ |
| 49 |
int n,nchars=1+get_random(128); |
| 50 |
for (n=0;n<nchars;++n) { |
| 51 |
int c=26+get_random(100); |
| 52 |
if ((n==0 && c==' ') || strchr("\r\n<",c)) ++c; |
| 53 |
printf("%c",c); |
| 54 |
} |
| 55 |
printf("\n"); |
| 56 |
} |
| 57 |
|
| 58 |
int main(int argc,char **argv) |
| 59 |
{ |
| 60 |
int item,items; |
| 61 |
float t=0.0f; |
| 62 |
|
| 63 |
if (argc==1 || *argv[1]!='-') { |
| 64 |
srand(argc==1?time(NULL):atoi(argv[1])); |
| 65 |
|
| 66 |
items=argc==1?262144:get_random(256); |
| 67 |
for (item=1;item<=items;++item) { |
| 68 |
gen_time(&t,0.5f); |
| 69 |
gen_text(); |
| 70 |
} |
| 71 |
} |
| 72 |
else { |
| 73 |
for (item=0;item<=100;++item) { |
| 74 |
t=(float)item/100.0f; |
| 75 |
gen_time(&t,0.0f); |
| 76 |
printf("Text.\n"); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
gen_time(&t,0.0f); |
| 81 |
printf("\n"); |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |
| 85 |
|