| 1 |
/* Copyright (C) 2009 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_milliseconds(float t) |
| 21 |
{ |
| 22 |
return (int)(t*1000.0f+0.5f); |
| 23 |
} |
| 24 |
|
| 25 |
static int time_hours(float t) |
| 26 |
{ |
| 27 |
return time_total_milliseconds(t)/(60*60*1000); |
| 28 |
} |
| 29 |
|
| 30 |
static int time_minutes(float t) |
| 31 |
{ |
| 32 |
return time_total_milliseconds(t)/(60*1000)%60; |
| 33 |
} |
| 34 |
|
| 35 |
static int time_seconds(float t) |
| 36 |
{ |
| 37 |
return time_total_milliseconds(t)/1000%60; |
| 38 |
} |
| 39 |
|
| 40 |
static int time_milliseconds(float t) |
| 41 |
{ |
| 42 |
return time_total_milliseconds(t)%1000; |
| 43 |
} |
| 44 |
|
| 45 |
static void gen_time(float *t,float dt) |
| 46 |
{ |
| 47 |
float r=*t+(rand()/(float)RAND_MAX)*dt; |
| 48 |
*t+=dt; |
| 49 |
printf("%02d:%02d:%02d,%03d",time_hours(r),time_minutes(r),time_seconds(r),time_milliseconds(r)); |
| 50 |
} |
| 51 |
|
| 52 |
static void gen_text() |
| 53 |
{ |
| 54 |
int line,nlines=1+get_random(5); |
| 55 |
for (line=0;line<nlines;++line) { |
| 56 |
int n,nchars=1+get_random(128); |
| 57 |
for (n=0;n<nchars;++n) { |
| 58 |
int c=26+get_random(100); |
| 59 |
if ((n==0 && c==' ') || strchr("\r\n",c)) ++c; |
| 60 |
printf("%c",c); |
| 61 |
} |
| 62 |
printf("\n"); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
int main(int argc,char **argv) |
| 67 |
{ |
| 68 |
int item,items; |
| 69 |
float t=0.0f; |
| 70 |
|
| 71 |
if (argc==1 || *argv[1]!='-') { |
| 72 |
srand(argc==1?time(NULL):atoi(argv[1])); |
| 73 |
|
| 74 |
items=argc==1?262144:get_random(256); |
| 75 |
for (item=1;item<=items;++item) { |
| 76 |
printf("%d\n",item); |
| 77 |
gen_time(&t,0.5f); |
| 78 |
printf(" --> "); |
| 79 |
gen_time(&t,2.5f); |
| 80 |
printf("\n"); |
| 81 |
gen_text(); |
| 82 |
printf("\n"); |
| 83 |
} |
| 84 |
} |
| 85 |
else { |
| 86 |
for (item=0;item<=1000;++item) { |
| 87 |
printf("%d\n",item+1); |
| 88 |
t=(float)item/1000.0f; |
| 89 |
gen_time(&t,0.0f); |
| 90 |
printf(" --> "); |
| 91 |
t+=2.5f; |
| 92 |
gen_time(&t,0.0f); |
| 93 |
printf("\n"); |
| 94 |
printf("Text.\n"); |
| 95 |
printf("\n"); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return 0; |
| 100 |
} |
| 101 |
|