cpoach.sh 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/index.js +89 -0
  4. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Subhajit Sahu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ ![](https://github.com/user-attachments/assets/459f91c1-c313-4f3a-b4e1-14edc4fb358f)
2
+
3
+ **cpoach** is a support tool designed to simplify the use of single-file C/C++ libraries. These libraries can be effortlessly installed via `npm`, making it easier to integrate them into your projects without the hassle of *managing build systems* or including third-party libraries in your version control.
4
+
5
+ <br>
6
+
7
+ ## Features
8
+
9
+ - Install and use C/C++ libraries as easily as `#include <stdio.h>`.
10
+ - Libraries are available via NPM for seamless installation.
11
+ - Ideal for in-class demonstrations and assignments.
12
+ - Access libraries for high-performance computing, graphics, networking, cryptography, and more.
13
+
14
+ <br>
15
+
16
+ ## Installation
17
+
18
+ To install *cpoach*, use the following command:
19
+
20
+ ```bash
21
+ npm i -g cpoach.sh
22
+ ```
23
+
24
+ <br>
25
+
26
+ ## Usage
27
+
28
+ After installation, you can include the desired libraries in your C/C++ projects. For example, if you want to use the [tigr.c] library for graphics, follow these steps:
29
+
30
+ Run:
31
+ ```bash
32
+ $ npm i tigr.c
33
+ ```
34
+
35
+ And then include `tigr.h` as follows:
36
+ ```c
37
+ // main.c
38
+ #define TIGR_IMPLEMENTATION
39
+ #include <tigr.h>
40
+
41
+ int main() { /* ... */ }
42
+ ```
43
+
44
+ And then compile with `clang` or `gcc` as usual.
45
+
46
+ ```bash
47
+ $ clang $(cpoach i) main.c # or, use gcc
48
+ $ gcc $(cpoach i) main.c
49
+ ```
50
+
51
+ Refer to the [website](https://nodef.github.io) for a categorized list of available libraries.
52
+
53
+ <br>
54
+
55
+ ## Contributing
56
+
57
+ We welcome contributions! If you have suggestions, please open an issue on our [GitHub repository](https://github.com/nodef/cpoach.sh/issues).
58
+
59
+ <br>
60
+ <br>
61
+
62
+
63
+ [![ORG](https://img.shields.io/badge/org-nodef-green?logo=Org)](https://nodef.github.io)
64
+ ![](https://ga-beacon.deno.dev/G-RC63DPBH3P:SH3Eq-NoQ9mwgYeHWxu7cw/github.com/nodef/cpoach.sh)
65
+
66
+ [tigr.c]: https://www.npmjs.com/package/tigr.c
package/index.js ADDED
@@ -0,0 +1,89 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+
5
+ // Run the `includes` command, which generates compiler flags for include paths.
6
+ function runIncludes(opt) {
7
+ const includes = [];
8
+ const cwd = process.cwd();
9
+ const pth = path.basename(cwd) === 'node_modules'? cwd : path.join(cwd, 'node_modules');
10
+ for (const ent of fs.readdirSync(pth)) {
11
+ if (!ent.endsWith('.c') && !ent.endsWith('.cxx')) continue;
12
+ includes.push(path.join(pth, ent));
13
+ }
14
+ const FLAG = opt.compiler==='msvc'? '/I' : '-I';
15
+ console.log(includes.map(pth => `${FLAG}"${pth}"`).join(' ').trim());
16
+ }
17
+
18
+
19
+ // Run the help command, which displays usage information.
20
+ function runHelp() {
21
+ console.error(
22
+ `Usage: cpoach [command] [options]\n` +
23
+ `\n` +
24
+ `Commands:\n` +
25
+ ` i | includes Generate compiler flags for include paths.\n` +
26
+ `\n` +
27
+ `Options:\n` +
28
+ ` --compiler [name] Specify the compiler (msvc, gcc, clang). Default is gcc.\n` +
29
+ ` --msvc Shortcut for --compiler msvc.\n` +
30
+ ` --gcc Shortcut for --compiler gcc.\n` +
31
+ ` --clang Shortcut for --compiler clang.\n`
32
+ );
33
+ }
34
+
35
+
36
+ // Parse the command name.
37
+ function parseCommand(opt, cmd) {
38
+ if (/i|includes/.test(cmd)) opt.command = 'includes';
39
+ else opt.error = `Unknown option: ${cmd}`;
40
+ }
41
+
42
+ // Parse a single command-line argument.
43
+ function parseArg(opt, argv, k, i) {
44
+ if (k==='--help') opt.help = true;
45
+ else if (k==='--compiler') opt.compiler = argv[++i];
46
+ else if (k==='--msvc') opt.compiler = 'msvc';
47
+ else if (k==='--gcc') opt.compiler = 'gcc';
48
+ else if (k==='--clang') opt.compiler = 'clang';
49
+ else if (!opt.command) parseCommand(opt, k);
50
+ else opt.error = `Unknown option: ${k}`;
51
+ return i;
52
+ }
53
+
54
+ // Parse command-line arguments.
55
+ function parseArgs(argv) {
56
+ const opt = {
57
+ error: null,
58
+ help: false,
59
+ command: 'includes',
60
+ compiler: 'gcc'
61
+ };
62
+ for (let i=2; i<argv.length; i++)
63
+ i = parseArg(opt, argv, argv[i], i);
64
+ return opt;
65
+ }
66
+
67
+
68
+ // Main entry point.
69
+ function main(argv) {
70
+ const opt = parseArgs(argv);
71
+ if (opt.error) {
72
+ console.error(opt.error + '\n');
73
+ console.error('Use "cpoach --help" for usage information.');
74
+ process.exit(1);
75
+ }
76
+ if (opt.help) {
77
+ runHelp();
78
+ process.exit(0);
79
+ }
80
+ switch (opt.command) {
81
+ case 'includes': runIncludes(opt); break;
82
+ default:
83
+ console.error(`Unknown command: ${opt.command}`);
84
+ process.exit(1);
85
+ }
86
+ }
87
+
88
+ // Run the main entry point.
89
+ main(process.argv);
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "cpoach.sh",
3
+ "version": "0.0.0",
4
+ "description": "Support tool for for easy-to-use, C/C++ libraries that can be effortlessly installed via NPM.",
5
+ "keywords": [
6
+ "c",
7
+ "c++",
8
+ "cpoach",
9
+ "includes",
10
+ "support",
11
+ "tool",
12
+ "library",
13
+ "npm",
14
+ "compiler",
15
+ "flags",
16
+ "includes",
17
+ "path",
18
+ "gcc",
19
+ "clang",
20
+ "clang++",
21
+ "msvc"
22
+ ],
23
+ "bin": {
24
+ "cpoach": "./index.js"
25
+ },
26
+ "homepage": "https://github.com/nodef/cpoach.sh#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/nodef/cpoach.sh/issues"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/nodef/cpoach.sh.git"
33
+ },
34
+ "license": "MIT",
35
+ "author": "wolfram77@gmail.com",
36
+ "type": "commonjs",
37
+ "main": "index.js",
38
+ "scripts": {
39
+ "test": "exit"
40
+ }
41
+ }