fork download
  1. #define READ_BLOCK_SIZE (0x80*0x400)
  2. #define MAX_LINE_LENGTH 0x400
  3. #define BUF_SIZE (READ_BLOCK_SIZE+MAX_LINE_LENGTH)
  4.  
  5. #define MAX_SECTION_LENGTH 0x3ff
  6.  
  7. inline static int baka_atoi(char const* buf, char const** pc_next) {
  8. int i_sign;
  9. int i_val = 0;
  10. if (*buf == '-') {
  11. i_sign = -1;
  12. ++buf;
  13. } else {
  14. i_sign = 1;
  15. }
  16. for (; isdigit(*buf); ++buf) {
  17. i_val = i_val * 10 + *buf - '0';
  18. }
  19. *pc_next = buf;
  20. return i_val * i_sign;
  21. }
  22.  
  23. inline static unsigned int baka_atou(char const* buf, char const** pc_next) {
  24. int i_val = 0;
  25. for (; isdigit(*buf); ++buf) {
  26. i_val = i_val * 10 + *buf - '0';
  27. }
  28. *pc_next = buf;
  29. return i_val;
  30. }
  31.  
  32. inline static int baka_read(int fd, char* p_buf, char const** pc_buf_e, char const* c_buf_p, uint64_t* pu_buf_offset, bool* pb_is_not_eof) {
  33.  
  34. ::memcpy(p_buf, c_buf_p, *pc_buf_e - c_buf_p);
  35. *pu_buf_offset += (c_buf_p - p_buf);
  36. p_buf += (*pc_buf_e - c_buf_p);
  37. *pc_buf_e = p_buf;
  38.  
  39. int i_size = ::read(fd, p_buf, READ_BLOCK_SIZE);
  40. if (i_size < 0) { ::fprintf(stderr, "read error\n"); return -1;}
  41.  
  42. *pb_is_not_eof = i_size == READ_BLOCK_SIZE ? true : false;
  43. *pc_buf_e += i_size;
  44. return 0;
  45. }
  46.  
  47. int read_section(int fd) {
  48. char buf[BUF_SIZE];
  49. char const* c_buf_b = buf;
  50. char const* c_buf_p = buf;
  51. char const* c_buf_e = buf;
  52. uint64_t u_offset = 0;
  53. bool is_not_eof = true;
  54.  
  55. char sz_section[MAX_SECTION_LENGTH + 1];
  56. unsigned int u_string_recs;
  57. unsigned int u_hatena;
  58. unsigned int u_xy_recs;
  59. unsigned int u_num_recs;
  60.  
  61. unsigned int u_qq_recs;
  62. char const* c_buf_bs;
  63. char const* c_buf_es;
  64. char const* c_buf_bc;
  65. char const* c_buf_ec;
  66.  
  67. uint64_t u_lines = 0;
  68. int32_t i_val[8]; // とりあえずの一時バッファ
  69. uint32_t u_val[8]; // とりあえずの一時バッファ
  70.  
  71. //
  72. // タイトル名
  73. // ex. TITLE_NAME ①
  74. //
  75.  
  76. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  77. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  78. if (buf == c_buf_e) return 0;
  79. c_buf_p = buf;
  80. }
  81. ++u_lines; c_buf_b = c_buf_p;
  82.  
  83. c_buf_bs = c_buf_p; // begin title
  84. for (; *c_buf_p != ' '; ++c_buf_p) ; // skip until LF
  85. c_buf_es = c_buf_p; // end title
  86.  
  87. ++c_buf_p; // skip SP
  88.  
  89. i_val[0] = baka_atou(c_buf_p, &c_buf_p); // mag
  90. #ifdef DEBUG_WRITE
  91. // ↓ココで取得
  92. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 0. title=\"%.*s\", mag = %u\n",
  93. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), (c_buf_es - c_buf_bs), c_buf_bs, i_val[0]);
  94. #endif
  95.  
  96. ++c_buf_p; // skip LF
  97.  
  98. do {
  99.  
  100. //
  101. // ①セクション名
  102. // ex. SECTION_NAME ①
  103. //
  104.  
  105. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  106. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  107. if (buf == c_buf_e) return 0;
  108. c_buf_p = buf;
  109. }
  110. ++u_lines; c_buf_b = c_buf_p;
  111.  
  112. for (; *c_buf_p != '\x0a'; ++c_buf_p) ; // skip until LF
  113. #ifdef DEBUG_WRITE
  114. // ↓ココで取得
  115. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 1. section = \"%.*s\"\n",
  116. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), (c_buf_p - c_buf_b), c_buf_b);
  117. #endif
  118. ++c_buf_p; // skip LF
  119.  
  120. //
  121. // ②セクション集計値
  122. // ex. 11200 11200 2 Jun 9 23:23:00 2018 ②
  123. //
  124.  
  125. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  126. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  127. if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 2 (L%"PRIu64")\n", u_lines); return -1;};
  128. c_buf_p = buf;
  129. }
  130. ++u_lines; c_buf_b = c_buf_p;
  131.  
  132. u_xy_recs = baka_atou(c_buf_p, &c_buf_p);
  133. ++c_buf_p; // skip SP
  134. u_hatena = baka_atou(c_buf_p, &c_buf_p);
  135. ++c_buf_p; // skip SP
  136. u_string_recs = baka_atou(c_buf_p, &c_buf_p);
  137. ++c_buf_p; // skip SP
  138. for (; *c_buf_p != '\x0a'; ++c_buf_p) ; // skip until LF
  139. #ifdef DEBUG_WRITE
  140. // ↓ココで取得
  141. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 2. u_xy_recs = %d, u_hatena = %u, u_string_recs = %u\n",
  142. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), u_xy_recs, u_hatena, u_string_recs);
  143. #endif
  144. ++c_buf_p; // skip LF
  145.  
  146. //
  147. // ③テキスト
  148. // ex. This is pen. ③
  149. // hello world. ③
  150. //
  151.  
  152. for (unsigned int i = 0; i < u_string_recs; ++i) {
  153.  
  154. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  155. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  156. if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 3 (L%"PRIu64")\n", u_lines); return -1; };
  157. c_buf_p = buf;
  158. }
  159. ++u_lines; c_buf_b = c_buf_p;
  160.  
  161. for (; *c_buf_p != '\x0a'; ++c_buf_p) ; // skip until LF
  162. #ifdef DEBUG_WRITE
  163. // ↓ココで取得
  164. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 3[%u]. text = \"%.*s\"\n",
  165. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, (c_buf_p - c_buf_b), c_buf_b);
  166. #endif
  167. ++c_buf_p; // skip LF
  168. }
  169.  
  170. //
  171. // ④数値
  172. // ex. x 1 2 ④
  173. //
  174.  
  175. for (unsigned int i = 0; i < u_xy_recs; ++i) {
  176.  
  177. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  178. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  179. if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4 (L%"PRIu64")\n", u_lines); return -1; };
  180. c_buf_p = buf;
  181. }
  182. ++u_lines; c_buf_b = c_buf_p;
  183.  
  184. switch (*c_buf_b) {
  185.  
  186. //
  187. // ex. x 1 2
  188. //
  189.  
  190. case 'x': {
  191. c_buf_p += 2; // skip 'x' and SP
  192. for (; *c_buf_p != ' '; ++c_buf_p) ; // skip until SP
  193. ++c_buf_p; // skip SP
  194. u_num_recs = baka_atou(c_buf_p, &c_buf_p);
  195. if (*c_buf_p != '\x0a') {
  196. ++c_buf_p; // skip SP
  197. c_buf_bc = c_buf_p; // begin c
  198. if (*c_buf_bc == 'c') {
  199. ++c_buf_p; // skip 'c'
  200. c_buf_ec = c_buf_p; // end c
  201. } else {
  202. c_buf_ec = c_buf_p; // end c
  203. }
  204. if (*c_buf_p != '\x0a') {
  205. ++c_buf_p; // skip SP
  206. i_val[0] = baka_atoi(c_buf_p, &c_buf_p);
  207. ++c_buf_p; // skip SP
  208. i_val[1] = baka_atoi(c_buf_p, &c_buf_p);
  209. ++c_buf_p; // skip SP
  210. i_val[2] = baka_atoi(c_buf_p, &c_buf_p);
  211. ++c_buf_p; // skip SP
  212. i_val[3] = baka_atoi(c_buf_p, &c_buf_p);
  213. ++c_buf_p; // skip SP
  214. i_val[4] = baka_atoi(c_buf_p, &c_buf_p);
  215. ++c_buf_p; // skip SP
  216. i_val[5] = baka_atoi(c_buf_p, &c_buf_p);
  217. if (*c_buf_p != '\x0a') {
  218. ++c_buf_p; // skip SP
  219. u_val[0] = baka_atou(c_buf_p, &c_buf_p);
  220. #ifdef DEBUG_WRITE
  221. // ↓ココで取得
  222. // ex. x 2 4 c -1 0 0 1 -21000000 600000 2
  223. // ex. x 2 4 -1 0 0 1 -21000000 600000 2
  224. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x[%u]. \"%c\", u_num_recs = %u, c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d, nazoc=%u\n",
  225. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs, (c_buf_ec - c_buf_bc), c_buf_bc,
  226. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5], u_val[0]);
  227. #endif
  228. } else {
  229. #ifdef DEBUG_WRITE
  230. // ↓ココで取得
  231. // ex. x 2 4 c -1 0 0 1 -21000000 600000
  232. // ex. x 2 4 -1 0 0 1 -21000000 600000
  233. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x[%u]. \"%c\", u_num_recs = %u, c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d\n",
  234. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs, (c_buf_ec - c_buf_bc), c_buf_bc,
  235. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5]);
  236. #endif
  237. }
  238. } else {
  239. #ifdef DEBUG_WRITE
  240. // ↓ココで取得
  241. // ex. x 2 4 c
  242. // ex. x 2 4
  243. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x[%u]. \"%c\", u_num_recs = %u, c=\"%.*s\"\n",
  244. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs, (c_buf_ec - c_buf_bc), c_buf_bc);
  245. #endif
  246. }
  247. } else {
  248. #ifdef DEBUG_WRITE
  249. // ↓ココで取得
  250. // ex. x 2 4
  251. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x[%u]. \"%c\", u_num_recs = %u\n",
  252. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs);
  253. #endif
  254. }
  255.  
  256. ++c_buf_p; // skip LF
  257. u_qq_recs = 0;
  258.  
  259. for (unsigned int j = 0; j < u_num_recs; ++j) {
  260. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  261. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  262. if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.x (L%"PRIu64")\n", u_lines); return -1; };
  263. c_buf_p = buf;
  264. }
  265. ++u_lines; c_buf_b = c_buf_p;
  266.  
  267. if (*c_buf_p == 'Q') {
  268.  
  269. //
  270. // ⑤QQ 謎の行
  271. // QQ subname -1 0 0 1 -21000000 600000 2
  272. //
  273.  
  274. c_buf_p += 3; // skip 'QQ' and SP
  275. c_buf_bs = c_buf_p; // begin subname
  276. for (; *c_buf_p != ' ' && *c_buf_p != '\x0a' ; ++c_buf_p) ; // skip until SP or LF
  277. c_buf_es = c_buf_p; // end subname
  278.  
  279. if (*c_buf_p != '\x0a') {
  280. ++c_buf_p; // skip SP
  281. c_buf_bc = c_buf_p; // begin c
  282. if (*c_buf_bc == 'c') {
  283. ++c_buf_p; // skip 'c'
  284. c_buf_ec = c_buf_p; // end c
  285. } else {
  286. c_buf_ec = c_buf_p; // end c
  287. }
  288. if (*c_buf_p != '\x0a') {
  289. ++c_buf_p; // skip SP
  290. i_val[0] = baka_atoi(c_buf_p, &c_buf_p);
  291. ++c_buf_p; // skip SP
  292. i_val[1] = baka_atoi(c_buf_p, &c_buf_p);
  293. ++c_buf_p; // skip SP
  294. i_val[2] = baka_atoi(c_buf_p, &c_buf_p);
  295. ++c_buf_p; // skip SP
  296. i_val[3] = baka_atoi(c_buf_p, &c_buf_p);
  297. ++c_buf_p; // skip SP
  298. i_val[4] = baka_atoi(c_buf_p, &c_buf_p);
  299. ++c_buf_p; // skip SP
  300. i_val[5] = baka_atoi(c_buf_p, &c_buf_p);
  301. if (*c_buf_p != '\x0a') {
  302. ++c_buf_p; // skip SP
  303. u_val[0] = baka_atou(c_buf_p, &c_buf_p);
  304. #ifdef DEBUG_WRITE
  305. // ↓ココで取得
  306. // ex. QQ subname c -1 0 0 1 -21000000 600000 2
  307. // ex. QQ subname -1 0 0 1 -21000000 600000 2
  308. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x.QQ[%u]. \"%c\", c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d, nazoc=%u\n",
  309. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, (c_buf_ec - c_buf_bc), c_buf_bc,
  310. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5], u_val[0]);
  311. #endif
  312. } else {
  313. #ifdef DEBUG_WRITE
  314. // ↓ココで取得
  315. // ex. QQ subname c -1 0 0 1 -21000000 600000
  316. // ex. QQ subname -1 0 0 1 -21000000 600000
  317. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x.QQ[%u]. \"%c\", c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d\n",
  318. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, (c_buf_ec - c_buf_bc), c_buf_bc,
  319. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5]);
  320. #endif
  321. }
  322. } else {
  323. #ifdef DEBUG_WRITE
  324. // ↓ココで取得
  325. // ex. QQ subname c
  326. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x.QQ[%u]. QQ = \"%.*s\", c=\"%.*s\"\n",
  327. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i,
  328. (c_buf_es - c_buf_bs), c_buf_bs, (c_buf_ec - c_buf_bc), c_buf_bc);
  329. #endif
  330. }
  331. } else {
  332. #ifdef DEBUG_WRITE
  333. // ↓ココで取得
  334. // ex. QQ subname
  335. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x.QQ[%u]. QQ = \"%.*s\"\n",
  336. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i,
  337. (c_buf_es - c_buf_bs), c_buf_bs);
  338. #endif
  339. }
  340.  
  341. ++c_buf_p; // skip LF
  342. ++u_qq_recs;
  343. ++u_num_recs;
  344.  
  345. } else if (*c_buf_p == 'R') {
  346. c_buf_p += 3; // skip 'RR' and SP
  347. u_val[0] = baka_atou(c_buf_p, &c_buf_p);
  348. #ifdef DEBUG_WRITE
  349. // ↓ココで取得
  350. // ex. RR 3
  351. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x.RR[%u]. number = %u\n",
  352. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, u_val[0]);
  353. #endif
  354. ++c_buf_p; // skip LF
  355. ++u_qq_recs;
  356. ++u_num_recs;
  357. } else {
  358.  
  359. //
  360. // 100 1 -2000 10
  361. //
  362.  
  363. i_val[0] = baka_atoi(c_buf_p, &c_buf_p);
  364. ++c_buf_p; // skip SP
  365. i_val[1] = baka_atoi(c_buf_p, &c_buf_p);
  366. ++c_buf_p; // skip SP
  367. i_val[2] = baka_atoi(c_buf_p, &c_buf_p);
  368. ++c_buf_p; // skip SP
  369. i_val[3] = baka_atoi(c_buf_p, &c_buf_p);
  370. #ifdef DEBUG_WRITE
  371. // ↓ココで取得
  372. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.x[%u][%u]. %d, %d, %d, %d\n",
  373. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, j - u_qq_recs, i_val[0], i_val[1], i_val[2], i_val[3]);
  374. #endif
  375. ++c_buf_p; // skip LF
  376. }
  377. }
  378. break;
  379. }
  380.  
  381. //
  382. // ex. y 2 4
  383. //
  384.  
  385. case 'y': {
  386. c_buf_p += 2; // skip 'y' and SP
  387. for (; *c_buf_p != ' '; ++c_buf_p) ; // skip until SP
  388. ++c_buf_p; // skip SP
  389. u_num_recs = baka_atou(c_buf_p, &c_buf_p);
  390. if (*c_buf_p != '\x0a') {
  391. ++c_buf_p; // skip SP
  392. c_buf_bc = c_buf_p; // begin c
  393. if (*c_buf_bc == 'c') {
  394. ++c_buf_p; // skip 'c'
  395. c_buf_ec = c_buf_p; // end c
  396. } else {
  397. c_buf_ec = c_buf_p; // end c
  398. }
  399. if (*c_buf_p != '\x0a') {
  400. ++c_buf_p; // skip SP
  401. i_val[0] = baka_atoi(c_buf_p, &c_buf_p);
  402. ++c_buf_p; // skip SP
  403. i_val[1] = baka_atoi(c_buf_p, &c_buf_p);
  404. ++c_buf_p; // skip SP
  405. i_val[2] = baka_atoi(c_buf_p, &c_buf_p);
  406. ++c_buf_p; // skip SP
  407. i_val[3] = baka_atoi(c_buf_p, &c_buf_p);
  408. ++c_buf_p; // skip SP
  409. i_val[4] = baka_atoi(c_buf_p, &c_buf_p);
  410. ++c_buf_p; // skip SP
  411. i_val[5] = baka_atoi(c_buf_p, &c_buf_p);
  412. if (*c_buf_p != '\x0a') {
  413. ++c_buf_p; // skip SP
  414. u_val[0] = baka_atou(c_buf_p, &c_buf_p);
  415. #ifdef DEBUG_WRITE
  416. // ↓ココで取得
  417. // ex. y 2 4 c -1 0 0 1 -21000000 600000 2
  418. // ex. y 2 4 -1 0 0 1 -21000000 600000 2
  419. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y[%u]. \"%c\", u_num_recs = %u, c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d, nazoc=%u\n",
  420. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs, (c_buf_ec - c_buf_bc), c_buf_bc,
  421. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5], u_val[0]);
  422. #endif
  423. } else {
  424. #ifdef DEBUG_WRITE
  425. // ↓ココで取得
  426. // ex. y 2 4 c -1 0 0 1 -21000000 600000
  427. // ex. y 2 4 -1 0 0 1 -21000000 600000
  428. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y[%u]. \"%c\", u_num_recs = %u, c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d\n",
  429. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs, (c_buf_ec - c_buf_bc), c_buf_bc,
  430. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5]);
  431. #endif
  432. }
  433. } else {
  434. #ifdef DEBUG_WRITE
  435. // ↓ココで取得
  436. // ex. y 2 4 c
  437. // ex. y 2 4
  438. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y[%u]. \"%c\", u_num_recs = %u, c=\"%.*s\"\n",
  439. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs, (c_buf_ec - c_buf_bc), c_buf_bc);
  440. #endif
  441. }
  442. } else {
  443. #ifdef DEBUG_WRITE
  444. // ↓ココで取得
  445. // ex. y 2 4
  446. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y[%u]. \"%c\", u_num_recs = %u\n",
  447. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, u_num_recs);
  448. #endif
  449. }
  450.  
  451. ++c_buf_p; // skip LF
  452. u_qq_recs = 0;
  453.  
  454. for (unsigned int j = 0; j < u_num_recs; ++j) {
  455. if (c_buf_e - c_buf_p < MAX_LINE_LENGTH && is_not_eof) {
  456. if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
  457. if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.y (L%"PRIu64")\n", u_lines); return -1; };
  458. c_buf_p = buf;
  459. }
  460. ++u_lines; c_buf_b = c_buf_p;
  461.  
  462. if (*c_buf_p == 'Q') {
  463.  
  464. //
  465. // ⑤QQ 謎の行
  466. // QQ subname -1 0 0 1 -21000000 600000 2
  467. //
  468.  
  469. c_buf_p += 3; // skip 'QQ' and SP
  470. c_buf_bs = c_buf_p; // begin subname
  471. for (; *c_buf_p != ' ' && *c_buf_p != '\x0a' ; ++c_buf_p) ; // skip until SP or LF
  472. c_buf_es = c_buf_p; // end subname
  473.  
  474. if (*c_buf_p != '\x0a') {
  475. ++c_buf_p; // skip SP
  476. c_buf_bc = c_buf_p; // begin c
  477. if (*c_buf_bc == 'c') {
  478. ++c_buf_p; // skip 'c'
  479. c_buf_ec = c_buf_p; // end c
  480. } else {
  481. c_buf_ec = c_buf_p; // end c
  482. }
  483. if (*c_buf_p != '\x0a') {
  484. ++c_buf_p; // skip SP
  485. i_val[0] = baka_atoi(c_buf_p, &c_buf_p);
  486. ++c_buf_p; // skip SP
  487. i_val[1] = baka_atoi(c_buf_p, &c_buf_p);
  488. ++c_buf_p; // skip SP
  489. i_val[2] = baka_atoi(c_buf_p, &c_buf_p);
  490. ++c_buf_p; // skip SP
  491. i_val[3] = baka_atoi(c_buf_p, &c_buf_p);
  492. ++c_buf_p; // skip SP
  493. i_val[4] = baka_atoi(c_buf_p, &c_buf_p);
  494. ++c_buf_p; // skip SP
  495. i_val[5] = baka_atoi(c_buf_p, &c_buf_p);
  496. if (*c_buf_p != '\x0a') {
  497. ++c_buf_p; // skip SP
  498. u_val[0] = baka_atou(c_buf_p, &c_buf_p);
  499. #ifdef DEBUG_WRITE
  500. // ↓ココで取得
  501. // ex. QQ subname c -1 0 0 1 -21000000 600000 2
  502. // ex. QQ subname -1 0 0 1 -21000000 600000 2
  503. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y.QQ[%u]. \"%c\", c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d, nazoc=%u\n",
  504. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, (c_buf_ec - c_buf_bc), c_buf_bc,
  505. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5], u_val[0]);
  506. #endif
  507. } else {
  508. #ifdef DEBUG_WRITE
  509. // ↓ココで取得
  510. // ex. QQ subname c -1 0 0 1 -21000000 600000
  511. // ex. QQ subname -1 0 0 1 -21000000 600000
  512. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y.QQ[%u]. \"%c\", c=\"%.*s\", qq_type1=%d, qq_type2=%d, qq_type3=%d, qq_type4=%d, nazo1=%d, nazo2=%d\n",
  513. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, *c_buf_b, (c_buf_ec - c_buf_bc), c_buf_bc,
  514. i_val[0], i_val[1], i_val[2], i_val[3], i_val[4], i_val[5]);
  515. #endif
  516. }
  517. } else {
  518. #ifdef DEBUG_WRITE
  519. // ↓ココで取得
  520. // ex. QQ subname c
  521. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y.QQ[%u]. QQ = \"%.*s\", c=\"%.*s\"\n",
  522. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i,
  523. (c_buf_es - c_buf_bs), c_buf_bs, (c_buf_ec - c_buf_bc), c_buf_bc);
  524. #endif
  525. }
  526. } else {
  527. #ifdef DEBUG_WRITE
  528. // ↓ココで取得
  529. // ex. QQ subname c
  530. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y.QQ[%u]. QQ = \"%.*s\"\n",
  531. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i,
  532. (c_buf_es - c_buf_bs), c_buf_bs);
  533. #endif
  534. }
  535.  
  536. ++c_buf_p; // skip LF
  537. ++u_qq_recs;
  538. ++u_num_recs;
  539.  
  540. } else if (*c_buf_p == 'R') {
  541. c_buf_p += 3; // skip 'RR' and SP
  542. u_val[0] = baka_atou(c_buf_p, &c_buf_p);
  543. #ifdef DEBUG_WRITE
  544. // ↓ココで取得
  545. // ex. RR 3
  546. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y.RR[%u]. number = %u\n",
  547. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, u_val[0]);
  548. #endif
  549. ++c_buf_p; // skip LF
  550. ++u_qq_recs;
  551. ++u_num_recs;
  552. } else {
  553.  
  554. //
  555. // ex. -100 10000
  556. //
  557.  
  558. i_val[0] = baka_atoi(c_buf_p, &c_buf_p);
  559. ++c_buf_p; // skip SP
  560. i_val[1] = baka_atoi(c_buf_p, &c_buf_p);
  561. #ifdef DEBUG_WRITE
  562. // ↓ココで取得
  563. ::fprintf(stdout, "(L%"PRIu64":%"PRIu64"-C%d) 4.y[%u][%u]. %d, %d\n",
  564. u_lines, u_offset + (c_buf_b - buf), (c_buf_p - c_buf_b), i, j - u_qq_recs, i_val[0], i_val[1]);
  565. #endif
  566. ++c_buf_p; // skip LF
  567. }
  568. }
  569. break;
  570. }
  571.  
  572. default:
  573. ::fprintf(stderr, "fatal error: unexpected format 4.1 (L%"PRIu64")\n", u_lines);
  574. return -1;
  575. }
  576. }
  577.  
  578. } while (c_buf_e != c_buf_p && is_not_eof);
  579.  
  580. return 0;
  581. }
  582.  
  583. int main(int argc, char** argv) {
  584.  
  585. if (argc != 2) {
  586. ::fprintf(stderr, "Usage: %s <filepath>\n", argv[0]);
  587. return 1;
  588. }
  589.  
  590. char* filename = argv[1];
  591.  
  592. int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
  593.  
  594. if (fd < 0) {
  595. ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
  596. return 1;
  597. }
  598.  
  599. ::fprintf(stderr, "strat... %s %s %s\n", argv[0], argv[1], argv[2]);
  600.  
  601. time_t u_start = time(NULL);
  602. if (::read_section(fd) < 0) { close(fd); return 1; };
  603. ::fprintf(stdout, "%d", time(NULL) - u_start);
  604.  
  605. ::fprintf(stderr, "done... %s %s %s\n", argv[0], argv[1], argv[2]);
  606. close(fd);
  607. return 0;
  608. }
  609.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int baka_atoi(const char*, const char**)’:
prog.cpp:16:21: error: ‘isdigit’ was not declared in this scope
  for (; isdigit(*buf); ++buf) {
                     ^
prog.cpp: In function ‘unsigned int baka_atou(const char*, const char**)’:
prog.cpp:25:21: error: ‘isdigit’ was not declared in this scope
  for (; isdigit(*buf); ++buf) {
                     ^
prog.cpp: At global scope:
prog.cpp:32:95: error: ‘uint64_t’ has not been declared
 inline static int  baka_read(int fd, char* p_buf, char const** pc_buf_e, char const* c_buf_p, uint64_t* pu_buf_offset, bool* pb_is_not_eof) {
                                                                                               ^~~~~~~~
prog.cpp: In function ‘int baka_read(int, char*, const char**, const char*, int*, bool*)’:
prog.cpp:34:2: error: ‘::memcpy’ has not been declared
  ::memcpy(p_buf, c_buf_p, *pc_buf_e - c_buf_p);
  ^~
prog.cpp:39:15: error: ‘::read’ has not been declared
  int i_size = ::read(fd, p_buf, READ_BLOCK_SIZE);
               ^~
prog.cpp:40:20: error: ‘::fprintf’ has not been declared
  if (i_size < 0) { ::fprintf(stderr, "read error\n"); return -1;}
                    ^~
prog.cpp:40:30: error: ‘stderr’ was not declared in this scope
  if (i_size < 0) { ::fprintf(stderr, "read error\n"); return -1;}
                              ^~~~~~
prog.cpp: In function ‘int read_section(int)’:
prog.cpp:52:2: error: ‘uint64_t’ was not declared in this scope
  uint64_t u_offset = 0;
  ^~~~~~~~
prog.cpp:67:11: error: expected ‘;’ before ‘u_lines’
  uint64_t u_lines = 0;
           ^~~~~~~
prog.cpp:68:2: error: ‘int32_t’ was not declared in this scope
  int32_t i_val[8]; // とりあえずの一時バッファ
  ^~~~~~~
prog.cpp:69:2: error: ‘uint32_t’ was not declared in this scope
  uint32_t u_val[8]; // とりあえずの一時バッファ
  ^~~~~~~~
prog.cpp:77:46: error: ‘u_offset’ was not declared in this scope
   if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                              ^~~~~~~~
prog.cpp:81:4: error: ‘u_lines’ was not declared in this scope
  ++u_lines; c_buf_b = c_buf_p;
    ^~~~~~~
prog.cpp:89:2: error: ‘i_val’ was not declared in this scope
  i_val[0] = baka_atou(c_buf_p, &c_buf_p); // mag
  ^~~~~
prog.cpp:106:47: error: ‘u_offset’ was not declared in this scope
    if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                               ^~~~~~~~
prog.cpp:126:47: error: ‘u_offset’ was not declared in this scope
    if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                               ^~~~~~~~
prog.cpp:127:26: error: ‘::fprintf’ has not been declared
    if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 2 (L%"PRIu64")\n", u_lines); return -1;};
                          ^~
prog.cpp:127:36: error: ‘stderr’ was not declared in this scope
    if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 2 (L%"PRIu64")\n", u_lines); return -1;};
                                    ^~~~~~
prog.cpp:127:88: error: unable to find string literal operator ‘operator""PRIu64’ with ‘const char [39]’, ‘long unsigned int’ arguments
    if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 2 (L%"PRIu64")\n", u_lines); return -1;};
                                                                                        ^~~~~
prog.cpp:155:48: error: ‘u_offset’ was not declared in this scope
     if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                                ^~~~~~~~
prog.cpp:156:27: error: ‘::fprintf’ has not been declared
     if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 3 (L%"PRIu64")\n", u_lines); return -1; };
                           ^~
prog.cpp:156:37: error: ‘stderr’ was not declared in this scope
     if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 3 (L%"PRIu64")\n", u_lines); return -1; };
                                     ^~~~~~
prog.cpp:156:89: error: unable to find string literal operator ‘operator""PRIu64’ with ‘const char [39]’, ‘long unsigned int’ arguments
     if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 3 (L%"PRIu64")\n", u_lines); return -1; };
                                                                                         ^~~~~
prog.cpp:178:48: error: ‘u_offset’ was not declared in this scope
     if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                                ^~~~~~~~
prog.cpp:179:27: error: ‘::fprintf’ has not been declared
     if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4 (L%"PRIu64")\n", u_lines); return -1; };
                           ^~
prog.cpp:179:37: error: ‘stderr’ was not declared in this scope
     if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4 (L%"PRIu64")\n", u_lines); return -1; };
                                     ^~~~~~
prog.cpp:179:89: error: unable to find string literal operator ‘operator""PRIu64’ with ‘const char [39]’, ‘long unsigned int’ arguments
     if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4 (L%"PRIu64")\n", u_lines); return -1; };
                                                                                         ^~~~~
prog.cpp:219:9: error: ‘u_val’ was not declared in this scope
         u_val[0] = baka_atou(c_buf_p, &c_buf_p);
         ^~~~~
prog.cpp:261:51: error: ‘u_offset’ was not declared in this scope
        if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                                   ^~~~~~~~
prog.cpp:262:30: error: ‘::fprintf’ has not been declared
        if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.x (L%"PRIu64")\n", u_lines); return -1; };
                              ^~
prog.cpp:262:40: error: ‘stderr’ was not declared in this scope
        if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.x (L%"PRIu64")\n", u_lines); return -1; };
                                        ^~~~~~
prog.cpp:262:94: error: unable to find string literal operator ‘operator""PRIu64’ with ‘const char [41]’, ‘long unsigned int’ arguments
        if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.x (L%"PRIu64")\n", u_lines); return -1; };
                                                                                              ^~~~~
prog.cpp:303:11: error: ‘u_val’ was not declared in this scope
           u_val[0] = baka_atou(c_buf_p, &c_buf_p);
           ^~~~~
prog.cpp:347:8: error: ‘u_val’ was not declared in this scope
        u_val[0] = baka_atou(c_buf_p, &c_buf_p);
        ^~~~~
prog.cpp:414:9: error: ‘u_val’ was not declared in this scope
         u_val[0] = baka_atou(c_buf_p, &c_buf_p);
         ^~~~~
prog.cpp:456:51: error: ‘u_offset’ was not declared in this scope
        if (baka_read(fd, buf, &c_buf_e, c_buf_p, &u_offset, &is_not_eof) < 0) return -1;
                                                   ^~~~~~~~
prog.cpp:457:30: error: ‘::fprintf’ has not been declared
        if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.y (L%"PRIu64")\n", u_lines); return -1; };
                              ^~
prog.cpp:457:40: error: ‘stderr’ was not declared in this scope
        if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.y (L%"PRIu64")\n", u_lines); return -1; };
                                        ^~~~~~
prog.cpp:457:94: error: unable to find string literal operator ‘operator""PRIu64’ with ‘const char [41]’, ‘long unsigned int’ arguments
        if (buf == c_buf_e) { ::fprintf(stderr, "fatal error: unexpected format 4.y (L%"PRIu64")\n", u_lines); return -1; };
                                                                                              ^~~~~
prog.cpp:498:11: error: ‘u_val’ was not declared in this scope
           u_val[0] = baka_atou(c_buf_p, &c_buf_p);
           ^~~~~
prog.cpp:542:8: error: ‘u_val’ was not declared in this scope
        u_val[0] = baka_atou(c_buf_p, &c_buf_p);
        ^~~~~
prog.cpp:573:6: error: ‘::fprintf’ has not been declared
      ::fprintf(stderr, "fatal error: unexpected format 4.1 (L%"PRIu64")\n", u_lines);
      ^~
prog.cpp:573:16: error: ‘stderr’ was not declared in this scope
      ::fprintf(stderr, "fatal error: unexpected format 4.1 (L%"PRIu64")\n", u_lines);
                ^~~~~~
prog.cpp:573:70: error: unable to find string literal operator ‘operator""PRIu64’ with ‘const char [41]’, ‘long unsigned int’ arguments
      ::fprintf(stderr, "fatal error: unexpected format 4.1 (L%"PRIu64")\n", u_lines);
                                                                      ^~~~~
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:586:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "Usage: %s <filepath>\n", argv[0]);
   ^~
prog.cpp:586:13: error: ‘stderr’ was not declared in this scope
   ::fprintf(stderr, "Usage: %s <filepath>\n", argv[0]);
             ^~~~~~
prog.cpp:592:11: error: ‘::open’ has not been declared
  int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
           ^~
prog.cpp:592:28: error: ‘O_RDONLY’ was not declared in this scope
  int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
                            ^~~~~~~~
prog.cpp:592:37: error: ‘O_LARGEFILE’ was not declared in this scope
  int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
                                     ^~~~~~~~~~~
prog.cpp:595:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
   ^~
prog.cpp:595:13: error: ‘stderr’ was not declared in this scope
   ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
             ^~~~~~
prog.cpp:599:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stderr, "strat... %s %s %s\n", argv[0], argv[1], argv[2]);
  ^~
prog.cpp:599:12: error: ‘stderr’ was not declared in this scope
  ::fprintf(stderr, "strat... %s %s %s\n", argv[0], argv[1], argv[2]);
            ^~~~~~
prog.cpp:601:2: error: ‘time_t’ was not declared in this scope
  time_t u_start = time(NULL);
  ^~~~~~
prog.cpp:602:40: error: ‘close’ was not declared in this scope
  if (::read_section(fd) < 0) { close(fd); return 1; };
                                        ^
prog.cpp:603:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stdout, "%d", time(NULL) - u_start);
  ^~
prog.cpp:603:12: error: ‘stdout’ was not declared in this scope
  ::fprintf(stdout, "%d", time(NULL) - u_start);
            ^~~~~~
prog.cpp:603:31: error: ‘NULL’ was not declared in this scope
  ::fprintf(stdout, "%d", time(NULL) - u_start);
                               ^~~~
prog.cpp:603:35: error: ‘time’ was not declared in this scope
  ::fprintf(stdout, "%d", time(NULL) - u_start);
                                   ^
prog.cpp:603:39: error: ‘u_start’ was not declared in this scope
  ::fprintf(stdout, "%d", time(NULL) - u_start);
                                       ^~~~~~~
prog.cpp:605:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stderr, "done... %s %s %s\n", argv[0], argv[1], argv[2]);
  ^~
prog.cpp:606:10: error: ‘close’ was not declared in this scope
  close(fd);
          ^
stdout
Standard output is empty