fork download
  1.  
  2. #define RAND() ((unsigned int)((rand() & 0xff) | ((rand() & 0xff) << 8) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 24)))
  3. #define GIGA (uint64_t)((uint64_t)0x400*(uint64_t)0x400*(uint64_t)0x400)
  4. #define MAX_LENGTH_SECTION 0x1f
  5. #define MAX_LENGTH_TEXT 0x7f
  6. #define MAX_LENGTH_BUF 0xff
  7.  
  8. static char const* asz_mon[12] = {
  9. "Jan","Feb","Mar","Apr","May","Jun",
  10. "Jul","Aug","Sep","Oct","Nov","Dec"};
  11.  
  12. static char* gen_string1(char* sz_string, size_t u_length) {
  13.  
  14. unsigned char* psz_string = (unsigned char*)sz_string;
  15. unsigned char* psz_string_end = (unsigned char*)sz_string + u_length;
  16.  
  17. for (; psz_string < psz_string_end; ++psz_string) {
  18. *psz_string = 0x21 + (RAND() % 94);
  19. }
  20.  
  21. *psz_string = '\0';
  22. return sz_string;
  23. }
  24.  
  25. static char* gen_string2(char* sz_string, size_t u_length) {
  26.  
  27. unsigned char c;
  28. char* psz_string = sz_string;
  29. char* psz_string_end = sz_string + u_length;
  30.  
  31. for (; psz_string < psz_string_end; ++psz_string) {
  32. c = RAND() % 52;
  33. if (c < 26) {
  34. *psz_string = 'A' + c;
  35. } else {
  36. *psz_string = 'a' + (c -26);
  37. }
  38. }
  39.  
  40. *psz_string = '\0';
  41. return sz_string;
  42. }
  43.  
  44. int gen_data(FILE* fp, size_t u_GiB) {
  45.  
  46. char sz_buf[MAX_LENGTH_BUF+1];
  47.  
  48. unsigned int u_string_recs;
  49. unsigned int u_hatena;
  50. unsigned int u_xy_recs;
  51. unsigned int u_num_recs;
  52. char x_or_y;
  53. uint64_t u_pos;
  54.  
  55. time_t u_time = time(NULL);
  56. tm* pt_tm = ::localtime(&u_time);
  57. char sz_timestamp[0x20];
  58. ::sprintf(sz_timestamp, "%s %.2d %02d:%02d:%02d %d", asz_mon[pt_tm->tm_mon], pt_tm->tm_mday, pt_tm->tm_hour, pt_tm->tm_min, pt_tm->tm_sec, pt_tm->tm_year+1900);
  59.  
  60. char sz_qq_buf[MAX_LENGTH_BUF+0x40+1];
  61.  
  62. // タイトル、倍率(mag)。(この係数を使って④の数値から割る、正の整数。unsigned int)
  63. ::srand((unsigned int)time(NULL));
  64. ::fprintf(fp, "%s %u\x0a", gen_string2(sz_buf, 1 + (RAND() % MAX_LENGTH_SECTION)), RAND());
  65.  
  66. for (;;) {
  67. // ①セクション名
  68. // ex. SECTION_NAME ①
  69. ::fprintf(fp, "%s\x0a", gen_string2(sz_buf, 1 + (RAND() % MAX_LENGTH_SECTION)));
  70.  
  71. // ②セクション集計値
  72. // ex. 11200 11200 2 Jun 9 23:23:00 2018 ②
  73. // u_xy_recs = RAND() % 0x8000000 + 1;
  74. u_xy_recs = RAND() % 0x8000 + 1;
  75. u_hatena = u_xy_recs;
  76. u_string_recs = RAND() % 0x20 + 1;
  77.  
  78. ::fprintf(fp, "%u %u %u %s\x0a", u_xy_recs, u_hatena, u_string_recs, sz_timestamp);
  79.  
  80. // ③テキスト
  81. // ex. This is pen. ③
  82. // hello world. ③
  83. for (unsigned int j = 0; j < u_string_recs; ++j) {
  84. ::fprintf(fp, "%s\x0a", gen_string1(sz_buf, 1 + (RAND() % MAX_LENGTH_TEXT)));
  85. }
  86.  
  87. // ④数値
  88. // ex. x 1 2 ④
  89. for (unsigned int j = 0; j < u_xy_recs; ++j) {
  90. x_or_y = (RAND() % 2) ? 'x' : 'y';
  91. // u_num_recs = RAND() % 0x400 + 1;
  92. u_num_recs = RAND() % 0x100 + 1;
  93.  
  94. switch (RAND() % 3) {
  95.  
  96. case 0:
  97. // ⑤QQ 謎の行
  98. // QQ subname -1 0 0 1 -21000000 600000 2
  99. // →この行が無いファイルもある。
  100. // →7,8カラムは1行目の倍率数字で割る(数値行と同じ計算)
  101. // →3~6カラムは -1, 0, 1, のいずれか。この4つの組み合わせであとで計算に使うことがある。
  102. // 1 0 0 1 →TYPE_A
  103. // 0 1 -1 0 →TYPE_B
  104. // -1 0 0 -1 →TYPE_C
  105. // 0 -1 1 0 →TYPE_D
  106. // -1 0 0 1 →TYPE_E
  107. // 0 -1 -1 0 →TYPE_F
  108. // 1 0 0 -1 →TYPE_G
  109. // 0 1 1 0 →TYPE_H
  110. // →9カラム目は正の整数。(unsigned int)
  111. // →下記6つのバリエーションがあります。
  112. // QQ subname
  113. // QQ subname c
  114. // QQ subname -1 0 0 1 -21000000 600000
  115. // QQ subname -1 0 0 1 -21000000 600000 2
  116. // QQ subname c -1 0 0 1 -21000000 600000
  117. // QQ subname c -1 0 0 1 -21000000 600000 2
  118. // ※cはcという文字列固定
  119. // ※1つのファイルに存在するのはいずれか1つのフォーマット
  120. switch (RAND() % 3) {
  121. case 0:
  122. ::sprintf(sz_qq_buf, "%s",
  123. RAND() % 2 ? " c" : "");
  124. break;
  125. case 1:
  126. ::sprintf(sz_qq_buf, "%s %d %d %d %d %d %d",
  127. RAND() % 2 ? " c" : "",
  128. (int)(RAND() % 3) - 1, (int)(RAND() % 3) - 1, (int)(RAND() % 3) - 1, (int)(RAND() % 3) - 1,
  129. (int32_t)RAND(), (int32_t)RAND());
  130. break;
  131. default:
  132. ::sprintf(sz_qq_buf, "%s %d %d %d %d %d %d %u",
  133. RAND() % 2 ? " c" : "",
  134. (int)(RAND() % 3) - 1, (int)(RAND() % 3) - 1, (int)(RAND() % 3) - 1, (int)(RAND() % 3) - 1,
  135. (int32_t)RAND(), (int32_t)RAND(), RAND());
  136. break;
  137. }
  138. // 上記QQ行は先頭のQQがなくなってx, y行に存在することがあります。
  139. // 1つのファイル内でQQ行とx, yの後ろにくるパターンの両方は存在せず、片方が出てきたらもう片方は出てきません。
  140. // x, yと同じ行にくる場合のフォーマットもQQ行の規則と同じです。
  141. // x 1 234 subname -1 0 0 1 -21000000 600000 2
  142. // y 2 234 subname -1 0 0 1 -21000000 600000 2
  143. if (RAND() % 2) {
  144. ::fprintf(fp, "%c %u %u%s\x0a", x_or_y, j + 1, u_num_recs, sz_qq_buf);
  145. } else {
  146. ::fprintf(fp, "%c %u %u\x0a", x_or_y, j + 1, u_num_recs);
  147. ::fprintf(fp, "QQ %s%s\x0a", gen_string2(sz_buf, 1 + (RAND() % MAX_LENGTH_SECTION)), sz_qq_buf);
  148. }
  149. break;
  150.  
  151. case 1:
  152. // RR行があります。
  153. // これもQQ同様x, yの次の行にあったりなかったりします。
  154. // QQとRRが一緒に出てくることは無いと思います。
  155. // フォーマットは「RR 正の整数」でQQのようにx,yの後ろに来ることはありません。
  156. ::fprintf(fp, "%c %u %u\x0a", x_or_y, j + 1, u_num_recs);
  157. ::fprintf(fp, "RR %u\x0a", RAND());
  158. break;
  159.  
  160. default:
  161. ::fprintf(fp, "%c %u %u\x0a", x_or_y, j + 1, u_num_recs);
  162. break;
  163. }
  164.  
  165. if (x_or_y == 'x') {
  166. for (unsigned int k = 0; k < u_num_recs; ++k) {
  167. // 100 1 -2000 10
  168. ::fprintf(fp, "%d %d %d %d\x0a",
  169. (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND());
  170. }
  171. } else {
  172. for (unsigned int k = 0; k < u_num_recs; ++k) {
  173. // -100 10000
  174. ::fprintf(fp, "%d %d\x0a",
  175. (int32_t)RAND(), (int32_t)RAND());
  176. }
  177. }
  178. }
  179.  
  180. u_pos = ftello(fp);
  181.  
  182. if (u_pos > GIGA * (uint64_t)u_GiB) {
  183. break;
  184. }
  185. }
  186.  
  187. return 0;
  188. }
  189.  
  190. int main(int argc, char** argv) {
  191.  
  192. if (argc != 3) {
  193. ::fprintf(stderr, "Usage: %s <filepath> <GiB size>\n", argv[0]);
  194. return 1;
  195. }
  196.  
  197. char* filename = argv[1];
  198. size_t u_GiB = ::strtoul(argv[2], NULL, 10);;
  199.  
  200. if (u_GiB == 0) {
  201. ::fprintf(stderr, "Usage: %s <filepath> <GiB size>\n", argv[0]);
  202. ::fprintf(stderr, "<GiB size> must be greater than zero\n");
  203. return 1;
  204. }
  205.  
  206. FILE* fp = ::fopen(filename, "wb");
  207. if (fp == NULL) {
  208. ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
  209. return 1;
  210. }
  211.  
  212. if (::gen_data(fp, u_GiB) < 0) {fclose(fp); return -1;}
  213. fclose(fp);
  214. return 0;
  215. }
  216.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:12:43: error: ‘size_t’ has not been declared
 static char* gen_string1(char* sz_string, size_t u_length) {
                                           ^~~~~~
prog.cpp: In function ‘char* gen_string1(char*, int)’:
prog.cpp:2:38: error: ‘rand’ was not declared in this scope
 #define RAND() ((unsigned int)((rand() & 0xff) | ((rand() & 0xff) << 8) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 24)))
                                      ^
prog.cpp:18:25: note: in expansion of macro ‘RAND’
   *psz_string = 0x21 + (RAND() % 94);
                         ^~~~
prog.cpp: At global scope:
prog.cpp:25:43: error: ‘size_t’ has not been declared
 static char* gen_string2(char* sz_string, size_t u_length) {
                                           ^~~~~~
prog.cpp: In function ‘char* gen_string2(char*, int)’:
prog.cpp:2:38: error: ‘rand’ was not declared in this scope
 #define RAND() ((unsigned int)((rand() & 0xff) | ((rand() & 0xff) << 8) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 24)))
                                      ^
prog.cpp:32:7: note: in expansion of macro ‘RAND’
   c = RAND() % 52;
       ^~~~
prog.cpp: At global scope:
prog.cpp:44:14: error: ‘FILE’ was not declared in this scope
 int gen_data(FILE* fp, size_t u_GiB) {
              ^~~~
prog.cpp:44:20: error: ‘fp’ was not declared in this scope
 int gen_data(FILE* fp, size_t u_GiB) {
                    ^~
prog.cpp:44:24: error: ‘size_t’ was not declared in this scope
 int gen_data(FILE* fp, size_t u_GiB) {
                        ^~~~~~
prog.cpp:44:36: error: expression list treated as compound expression in initializer [-fpermissive]
 int gen_data(FILE* fp, size_t u_GiB) {
                                    ^
stdout
Standard output is empty