fork download
  1. #define RAND() ((unsigned int)((rand() & 0xff) | ((rand() & 0xff) << 8) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 24)))
  2. #define GIGA (uint64_t)((uint64_t)0x400*(uint64_t)0x400*(uint64_t)0x400)
  3. #define MAX_LENGTH_SECTION 0x1f
  4. #define MAX_LENGTH_TEXT 0x7f
  5. #define MAX_LENGTH_BUF 0xff
  6. #define MAX_UINT32 0xffffffff
  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. time_t u_time = time(NULL);
  54. tm* pt_tm = ::localtime(&u_time);
  55. uint64_t u_pos;
  56.  
  57. ::srand((unsigned int)time(NULL));
  58.  
  59. for (;;) {
  60. // ①セクション名
  61. // ex. SECTION_NAME ①
  62. ::fprintf(fp, "%s\x0a", gen_string2(sz_buf, 1 + (RAND() % MAX_LENGTH_SECTION)));
  63.  
  64. // ②セクション集計値
  65. // ex. 11200 11200 2 Jun 9 23:23:00 2018 ②
  66. // u_xy_recs = RAND() % 0x8000000 + 1;
  67. u_xy_recs = RAND() % 0x8000 + 1;
  68. u_hatena = u_xy_recs;
  69. u_string_recs = RAND() % 0x20 + 1;
  70. ::sprintf(sz_buf, "%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);
  71. ::fprintf(fp, "%u %u %u %s\x0a", u_xy_recs, u_hatena, u_string_recs, sz_buf);
  72.  
  73. // ③テキスト
  74. // ex. This is pen. ③
  75. // hello world. ③
  76. for (unsigned int j = 0; j < u_string_recs; ++j) {
  77. ::fprintf(fp, "%s\x0a", gen_string1(sz_buf, 1 + (RAND() % MAX_LENGTH_TEXT)));
  78. }
  79.  
  80. // ④数値
  81. // ex. x 1 2 ④
  82. for (unsigned int j = 0; j < u_xy_recs; ++j) {
  83. x_or_y = (RAND() % 2) ? 'x' : 'y';
  84. // u_num_recs = RAND() % 0x400 + 1;
  85. u_num_recs = RAND() % 0x100 + 1;
  86. ::fprintf(fp, "%c %u %u\x0a", x_or_y, j + 1, u_num_recs);
  87. if (RAND() % 2) {
  88. // ⑤QQ 謎の行
  89. // QQ subname -1 0 0 1 -21000000 600000 2
  90. ::fprintf(fp, "QQ %s %d %d %d %d %d %d %d\x0a",
  91. gen_string2(sz_buf, 1 + (RAND() % MAX_LENGTH_SECTION)),
  92. (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND());
  93. }
  94. if (x_or_y == 'x') {
  95. for (unsigned int k = 0; k < u_num_recs; ++k) {
  96. // 100 1 -2000 10
  97. ::fprintf(fp, "%d %d %d %d\x0a",
  98. (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND(), (int32_t)RAND());
  99. }
  100. } else {
  101. for (unsigned int k = 0; k < u_num_recs; ++k) {
  102. // -100 10000
  103. ::fprintf(fp, "%d %d\x0a",
  104. (int32_t)RAND(), (int32_t)RAND());
  105. }
  106. }
  107. }
  108.  
  109. u_pos = ftello(fp);
  110.  
  111. if (u_pos > GIGA * (uint64_t)u_GiB) {
  112. break;
  113. }
  114. }
  115.  
  116. return 0;
  117. }
  118.  
  119. int main(int argc, char** argv) {
  120.  
  121. if (argc != 3) {
  122. ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", argv[0]);
  123. return 1;
  124. }
  125.  
  126. char* filename = argv[1];
  127. size_t u_GiB = ::strtoul(argv[2], NULL, 10);;
  128.  
  129. if (u_GiB == 0) {
  130. ::fprintf(stderr, "Usage: %s <filepath> <GiB size>\n", argv[0]);
  131. ::fprintf(stderr, "<GiB size> must be greater than zero\n");
  132. return 1;
  133. }
  134.  
  135. FILE* fp = ::fopen(filename, "w");
  136.  
  137. if (::gen_data(fp, u_GiB) < 0) {fclose(fp); return -1;}
  138. fclose(fp);
  139. return 0;
  140. }
  141.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:12:43: error: unknown type name ‘size_t’
 static char* gen_string1(char* sz_string, size_t u_length) {
                                           ^~~~~~
prog.c:25:43: error: unknown type name ‘size_t’
 static char* gen_string2(char* sz_string, size_t u_length) {
                                           ^~~~~~
prog.c:44:14: error: unknown type name ‘FILE’
 int gen_data(FILE* fp, size_t u_GiB) {
              ^~~~
prog.c:44:24: error: unknown type name ‘size_t’
 int gen_data(FILE* fp, size_t u_GiB) {
                        ^~~~~~
prog.c: In function ‘main’:
prog.c:122:3: error: expected expression before ‘:’ token
   ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", argv[0]);
   ^
prog.c:127:2: error: unknown type name ‘size_t’
  size_t u_GiB = ::strtoul(argv[2], NULL, 10);;
  ^~~~~~
prog.c:127:17: error: expected expression before ‘:’ token
  size_t u_GiB = ::strtoul(argv[2], NULL, 10);;
                 ^
prog.c:130:3: error: expected expression before ‘:’ token
   ::fprintf(stderr, "Usage: %s <filepath> <GiB size>\n", argv[0]);
   ^
prog.c:131:3: error: expected expression before ‘:’ token
   ::fprintf(stderr, "<GiB size> must be greater than zero\n");
   ^
prog.c:135:2: error: unknown type name ‘FILE’
  FILE* fp = ::fopen(filename, "w");
  ^~~~
prog.c:135:13: error: expected expression before ‘:’ token
  FILE* fp = ::fopen(filename, "w");
             ^
prog.c:137:6: error: expected expression before ‘:’ token
  if (::gen_data(fp, u_GiB) < 0) {fclose(fp); return -1;}
      ^
prog.c:137:34: warning: implicit declaration of function ‘fclose’ [-Wimplicit-function-declaration]
  if (::gen_data(fp, u_GiB) < 0) {fclose(fp); return -1;}
                                  ^~~~~~
prog.c:126:8: warning: unused variable ‘filename’ [-Wunused-variable]
  char* filename = argv[1];
        ^~~~~~~~
At top level:
prog.c:8:20: warning: ‘asz_mon’ defined but not used [-Wunused-variable]
 static char const* asz_mon[12] = {
                    ^~~~~~~
stdout
Standard output is empty