[go: up one dir, main page]

File: gen_srt.c

package info (click to toggle)
libkate 0.3.7-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,484 kB
  • ctags: 4,083
  • sloc: ansic: 10,002; sh: 8,853; yacc: 2,250; python: 721; lex: 362; makefile: 239
file content (101 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright (C) 2009 Vincent Penquerc'h.
   This file is part of the Kate codec library.
   Written by Vincent Penquerc'h.

   Use, distribution and reproduction of this library is governed
   by a BSD style source license included with this source in the
   file 'COPYING'. Please read these terms before distributing. */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

static int get_random(int n)
{
  return (rand()>>8)%n;
}

static int time_total_milliseconds(float t)
{
    return (int)(t*1000.0f+0.5f);
}

static int time_hours(float t)
{
  return time_total_milliseconds(t)/(60*60*1000);
}

static int time_minutes(float t)
{
  return time_total_milliseconds(t)/(60*1000)%60;
}

static int time_seconds(float t)
{
  return time_total_milliseconds(t)/1000%60;
}

static int time_milliseconds(float t)
{
  return time_total_milliseconds(t)%1000;
}

static void gen_time(float *t,float dt)
{
  float r=*t+(rand()/(float)RAND_MAX)*dt;
  *t+=dt;
  printf("%02d:%02d:%02d,%03d",time_hours(r),time_minutes(r),time_seconds(r),time_milliseconds(r));
}

static void gen_text()
{
  int line,nlines=1+get_random(5);
  for (line=0;line<nlines;++line) {
    int n,nchars=1+get_random(128);
    for (n=0;n<nchars;++n) {
      int c=26+get_random(100);
      if (n==0 && c==' ' || strchr("\r\n",c)) ++c;
      printf("%c",c);
    }
    printf("\n");
  }
}

int main(int argc,char **argv)
{
  int item,items;
  float t=0.0f;

  if (argc==1 || *argv[1]!='-') {
    srand(argc==1?time(NULL):atoi(argv[1]));

    items=argc==1?262144:get_random(256);
    for (item=1;item<=items;++item) {
      printf("%d\n",item);
      gen_time(&t,0.5f);
      printf(" --> ");
      gen_time(&t,2.5f);
      printf("\n");
      gen_text();
      printf("\n");
    }
  }
  else {
    for (item=0;item<=1000;++item) {
      printf("%d\n",item+1);
      t=(float)item/1000.0f;
      gen_time(&t,0.0f);
      printf(" --> ");
      t+=2.5f;
      gen_time(&t,0.0f);
      printf("\n");
      printf("Text.\n");
      printf("\n");
    }
  }

  return 0;
}