This commit is contained in:
Sandipsinh Rathod 2024-11-17 19:47:48 -05:00
commit af46e2a811
15 changed files with 1263 additions and 0 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
/target

622
Cargo.lock generated Normal file

@ -0,0 +1,622 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys 0.59.0",
]
[[package]]
name = "anyhow"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "backtrace"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
]
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "bytes"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "cpgen"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miniz_oxide"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
dependencies = [
"adler2",
]
[[package]]
name = "mio"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec"
dependencies = [
"hermit-abi",
"libc",
"wasi",
"windows-sys 0.52.0",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "object"
version = "0.36.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
]
[[package]]
name = "pin-project-lite"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff"
[[package]]
name = "proc-macro2"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
dependencies = [
"bitflags",
]
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "socket2"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tokio"
version = "1.41.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
]
[[package]]
name = "unicode-ident"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

11
Cargo.toml Normal file

@ -0,0 +1,11 @@
[package]
name = "cpgen"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.21", features = ["derive"] }
anyhow = "1.0.93"
tokio = { version = "1.10.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

116
cpp/bits/stdc++.h Normal file

@ -0,0 +1,116 @@
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

176
cpp/dbg.h Normal file

@ -0,0 +1,176 @@
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& vec) {
if (vec.empty()) {
out << "[]";
return out;
}
out << '[';
for (int i = 0; i < vec.size() - 1; i++) {
out << vec[i] << ", ";
}
return out << vec.back() << ']';
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::stack<T>& stk) {
std::stack<T> t = stk;
if (t.empty()) {
out << "[]";
return out;
}
out << '[';
while(!t.empty()) {
out << t.top() << ", ";
t.pop();
}
return out << "\b\b]";
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::queue<T>& que) {
std::queue<T> t = que;
if (t.empty()) {
out << "[]";
return out;
}
out << '[';
while(!t.empty()) {
out << t.front() << ", ";
t.pop();
}
return out << "\b\b]";
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::priority_queue<T>& pque) {
std::priority_queue<T> t = pque;
if (t.empty()) {
out << "[]";
return out;
}
out << '[';
while(!t.empty()) {
out << t.top() << ", ";
t.pop();
}
return out << "\b\b]";
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::pair<T1, T2>& pair) {
return out << '(' << pair.first << ", " << pair.second << ')';
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::deque<T>& deq) {
if (deq.empty()) {
out << "[]";
return out;
}
out << '[';
for (int i = 0; i < deq.size() - 1; i++) {
out << deq[i] << ", ";
}
return out << deq.back() << ']';
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::unordered_map<T1, T2>& map) {
out << '{';
for (auto it = map.begin(); it != map.end(); it++) {
std::pair<T1, T2> element = *it;
out << element.first << ": " << element.second;
if (std::next(it) != map.end()) {
out << ", ";
}
}
return out << '}';
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::map<T1, T2>& map) {
out << '{';
for (auto it = map.begin(); it != map.end(); it++) {
std::pair<T1, T2> element = *it;
out << element.first << ": " << element.second;
if (std::next(it) != map.end()) {
out << ", ";
}
}
return out << '}';
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::unordered_set<T>& set) {
out << '{';
for (auto it = set.begin(); it != set.end(); it++) {
T element = *it;
out << element;
if (std::next(it) != set.end()) {
out << ", ";
}
}
return out << '}';
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::multiset<T>& set) {
out << '{';
for (auto it = set.begin(); it != set.end(); it++) {
T element = *it;
out << element;
if (std::next(it) != set.end()) {
out << ", ";
}
}
return out << '}';
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::unordered_multiset<T>& set) {
out << '{';
for (auto it = set.begin(); it != set.end(); it++) {
T element = *it;
out << element;
if (std::next(it) != set.end()) {
out << ", ";
}
}
return out << '}';
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::set<T>& set) {
out << '{';
for (auto it = set.begin(); it != set.end(); it++) {
T element = *it;
out << element;
if (std::next(it) != set.end()) {
out << ", ";
}
}
return out << '}';
}
// Source: https://stackoverflow.com/a/31116392/12128483
template<typename Type, unsigned N, unsigned Last>
struct TuplePrinter {
static void print(std::ostream& out, const Type& value) {
out << std::get<N>(value) << ", ";
TuplePrinter<Type, N + 1, Last>::print(out, value);
}
};
template<typename Type, unsigned N>
struct TuplePrinter<Type, N, N> {
static void print(std::ostream& out, const Type& value) {
out << std::get<N>(value);
}
};
template<typename... Types>
std::ostream& operator<<(std::ostream& out, const std::tuple<Types...>& value) {
out << '(';
TuplePrinter<std::tuple<Types...>, 0, sizeof...(Types) - 1>::print(out, value);
return out << ')';
}

58
cpp/main.cpp Normal file

@ -0,0 +1,58 @@
#include "bits/stdc++.h"
#ifdef LOCAL
#include "dbg.h"
#define dbg(a) pt "Line " << __LINE__ << ": " << #a << " = " << (a) << nl
#else
#define dbg(a) 7
#define dbb(a) 7
#define dbgnl 7
#endif
#define pt cout <<
#define nl '\n'
#define in cin >>
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).rbegin(), (i).rend()
#define yn(x) pt (x ? "YES": "NO")
#define fio ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define MOD (ll)(1e9 + 7)
using ll = long long;
using ld = long double;
using namespace std;
template<typename T>
istream &operator>>(istream &i, vector<T> &v) {
for (auto &j: v) i >> j;
return i;
}
template<typename T>
ostream &operator>>(ostream &i, vector<T> &v) {
for (auto &j: v) i >> j;
return i;
}
void solve() {
}
int32_t main() {
fio
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ll t = 1;
in t;
while (t--)
solve();
return 0;
}

116
rust/main.rs Normal file

@ -0,0 +1,116 @@
#![allow(dead_code)]
#![allow(unused)]
// Template by SSDD (https://codeforces.com/profile/ifail)
// Feel free to use it :p
// don't forget to add `local` feature in Cargo.toml
// while compiling pass `--features local` or `--all-features` for it
// to perform file IO from local files
use std::fs::File;
use std::io::{BufReader, BufWriter, Read, Write};
struct Reader<T: Read> {
reader: T,
buffer: Vec<String>,
}
macro_rules! wrt { // for actual print
($writer:expr, $($value:expr),*) => {
$(write!($writer, "{}", $value).unwrap();)*
};
}
#[cfg(feature = "local")]
macro_rules! wrtd { // for debug print
($writer:expr, $($value:expr),*) => {
$(write!($writer, "{:?}\n", $value).unwrap();)*
};
}
#[cfg(not(feature = "local"))]
macro_rules! wrtd { // debug print won't do anything when ans is submitted
($writer:expr, $($value:expr),*) => ();
}
fn yn<T: Write>(writer: &mut T, x: bool) {
wrt!(writer, if x { "YES\n" } else { "NO\n" });
}
impl<T: std::io::BufRead> Reader<T> {
fn new(reader: T) -> Reader<T> {
Self {
reader,
buffer: vec![],
}
}
fn next<I: std::str::FromStr>(&mut self) -> I where <I as std::str::FromStr>::Err: std::fmt::Debug {
loop {
if let Some(token) = self.buffer.pop() {
return token.parse().ok()
.expect("Failed to parse!");
}
let mut input = String::new();
self.reader.read_line(&mut input)
.expect("Failed to read!");
self.buffer = input.split_whitespace().rev().map(String::from).collect();
}
}
fn next_usz(&mut self) -> usize {
self.next()
}
fn next_st(&mut self) -> String {
self.next()
}
fn next_int(&mut self) -> i32 {
self.next()
}
fn next_ll(&mut self) -> i64 {
self.next()
}
fn next_ft(&mut self) -> f32 {
self.next()
}
fn next_ft6(&mut self) -> f64 {
self.next()
}
fn next_chars(&mut self) -> Vec<char> {
self.next::<String>().chars().collect()
}
}
fn solve<R: std::io::BufRead, W: Write>(reader: &mut Reader<R>, writer: &mut W) {
}
fn main() {
#[cfg(feature = "local")]
let stdin = BufReader::new(File::open("in.txt").unwrap());
#[cfg(not(feature = "local"))]
let stdin = std::io::stdin().lock();
#[cfg(feature = "local")]
let mut stdout = BufWriter::new(File::create("out.txt").unwrap());
#[cfg(not(feature = "local"))]
let mut stdout = std::io::stdout().lock();
// Example to write: `wrt!(writer, ans, "\n");` you can pass several of args
// use `wrtd!` for debug print, it won't print anything in non-local env
let mut reader = Reader::new(stdin);
let t = 1;
// let t = reader.next_usz();
for _ in 0..t {
solve(&mut reader, &mut stdout);
}
}

8
src/lang.rs Normal file

@ -0,0 +1,8 @@
use clap::ValueEnum;
#[derive(ValueEnum, Default, Clone)]
pub enum Language {
#[default]
Cpp,
Rust,
}

3
src/lib.rs Normal file

@ -0,0 +1,3 @@
pub mod runner;
pub mod lang;
pub mod r#static;

25
src/main.rs Normal file

@ -0,0 +1,25 @@
use std::cell::Cell;
thread_local! {
static TRACING_GUARD: Cell<bool> = const { Cell::new(false) };
}
fn init() -> anyhow::Result<()> {
tracing_subscriber::fmt().init();
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
rt.block_on(cpgen::runner::run())
}
fn main() {
match init() {
Ok(_) => {}
Err(e) => {
eprintln!("{}", e);
std::process::exit(1);
}
}
}

23
src/runner/commands.rs Normal file

@ -0,0 +1,23 @@
use clap::{Parser, Subcommand};
use crate::lang::Language;
#[derive(Parser)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand, Clone)]
pub enum Command {
Init {
#[arg(required = true)]
contest_urls: Vec<String>,
},
Gen {
#[arg(required = true)]
file_dirs: Vec<String>,
#[arg(short, long)]
language: Option<Language>,
},
}

73
src/runner/gen.rs Normal file

@ -0,0 +1,73 @@
use std::io::Write;
use std::path::PathBuf;
use crate::lang::Language;
pub struct Generator {
pub file_dirs: Vec<String>,
pub language: Language,
}
impl Generator {
pub fn new<T: AsRef<[String]>>(file_dirs: T, language: Option<Language>) -> Self {
Self {
file_dirs: file_dirs.as_ref().iter().map(|v| v.to_string()).collect(),
language: language.unwrap_or_default(),
}
}
pub fn generate(&self) -> anyhow::Result<()> {
for file_dir in &self.file_dirs {
tracing::info!("Generating files in {}", file_dir);
let path = PathBuf::try_from(file_dir);
match path {
Ok(file_dir) => {
generate(file_dir.to_str().unwrap(), &self.language)?;
},
Err(_) => {
return Err(anyhow::anyhow!("Invalid path: {}", file_dir));
}
}
}
Ok(())
}
}
struct InnerGenerator {
files: Vec<(String, String)>,
}
impl InnerGenerator {
fn new<T: AsRef<str>, S: AsRef<str>>(files: Vec<(T, S)>) -> Self {
Self {
files: files.into_iter().map(|(t, s)| (t.as_ref().to_string(), s.as_ref().to_string())).collect(),
}
}
fn run(self, dir_path: &str) -> anyhow::Result<()> {
for (file_name, content) in self.files {
let file_path = PathBuf::from(format!("{}/{}", dir_path, file_name));
std::fs::create_dir_all(file_path.parent().ok_or(anyhow::anyhow!("Invalid parent dir"))?)?;
let mut file = std::fs::File::create(file_path)?;
file.write_all(content.as_bytes())?;
}
Ok(())
}
}
fn generate(dir_path: &str, lang: &Language) -> anyhow::Result<()> {
let inner_gen = match lang {
Language::Cpp => {
let cpp_files = vec![crate::r#static::MAIN_CPP, crate::r#static::BITS, crate::r#static::DBG_H];
InnerGenerator::new(cpp_files)
}
Language::Rust => {
let rust_files = vec![crate::r#static::MAIN_RS];
InnerGenerator::new(rust_files)
}
};
inner_gen.run(dir_path)
}

5
src/runner/mod.rs Normal file

@ -0,0 +1,5 @@
mod run;
mod commands;
mod gen;
pub use run::*;

16
src/runner/run.rs Normal file

@ -0,0 +1,16 @@
use crate::runner::commands::{Cli, Command};
use clap::Parser;
use crate::runner::gen::Generator;
pub async fn run() -> anyhow::Result<()> {
let cli: Cli = Cli::parse();
let command = cli.command;
match command {
Command::Init { .. } => todo!(),
Command::Gen { file_dirs, language } => {
let generator = Generator::new(file_dirs, language);
generator.generate()?;
}
}
Ok(())
}

10
src/static.rs Normal file

@ -0,0 +1,10 @@
/// CPP
pub const MAIN_CPP: (&'static str, &'static str) = ("main.cpp", include_str!("../cpp/main.cpp"));
pub const DBG_H: (&'static str, &'static str) = ("debug.h", include_str!("../cpp/dbg.h"));
pub const BITS: (&'static str, &'static str) = ("bits/stdc++.h", include_str!("../cpp/bits/stdc++.h"));
pub const CPP_CMD: &'static str = r#"g++ main.cpp -o main -DLOCAL"#;
/// Rust
pub const MAIN_RS: (&'static str, &'static str) = ("main.rs", include_str!("../rust/main.rs"));
pub const RS_CMD: &'static str = r#"rustc main.rs --cfg 'feature="local"'"#;