@camjn/getargv 0.0.3 → 0.0.5
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.
- package/LICENSE.txt +29 -0
- package/README.md +16 -3
- package/dist/binding.d.ts +5 -2
- package/dist/binding.js +28 -0
- package/package.json +10 -7
- package/src/getargv.c +16 -15
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022, 2023
|
|
4
|
+
Camden Narzt <getargv@narzt.cam>. All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -5,11 +5,24 @@
|
|
|
5
5
|
|
|
6
6
|
This module allows you to query the arguments of other processes on macOS.
|
|
7
7
|
|
|
8
|
-
## Installation
|
|
8
|
+
## Module Installation
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
- Install `libgetargv` to your system (see below).
|
|
11
|
+
- Install the module and add to the application's package.json by executing:
|
|
11
12
|
|
|
12
|
-
$ npm
|
|
13
|
+
$ npm install --save-optional @camjn/getargv
|
|
14
|
+
|
|
15
|
+
Saving this module as optional is important because it can only build on macOS, so npm needs to be able to exclude it on other OSs.
|
|
16
|
+
|
|
17
|
+
## Library Installation
|
|
18
|
+
|
|
19
|
+
- To get access to `libgetargv`, sign up for an appropriate [sponsorship tier](https://github.com/sponsors/CamJN).
|
|
20
|
+
- Clone the `libgetargv` repo: `git clone https://github.com/getargv/getargv.git`.
|
|
21
|
+
- Running `make install_dylib`, installs the library to the `/usr/local/` prefix by default; you can change the install location with the `PREFIX` `make` variable: `make PREFIX=/opt install_dylib`.
|
|
22
|
+
|
|
23
|
+
## Building `libgetargv`
|
|
24
|
+
|
|
25
|
+
I've built `libgetargv` on macOS 10.7-13, using only the <abbr title="Command Line Tools">CLT</abbr> package, not the full Xcode install. If you need to override variables, do so inside the `make` command, eg: `make EXTRA_CPPFLAGS=-DMACRO EXTRA_CFLAGS=-std=c17 dylib`.
|
|
13
26
|
|
|
14
27
|
## Usage
|
|
15
28
|
|
package/dist/binding.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
type Labels = "866" | "ansi_x3.4-1968" | "arabic" | "ascii" | "asmo-708" | "big5" | "big5-hkscs" | "chinese" | "cn-big5" | "cp1250" | "cp1251" | "cp1252" | "cp1253" | "cp1254" | "cp1255" | "cp1256" | "cp1257" | "cp1258" | "cp819" | "cp866" | "csbig5" | "cseuckr" | "cseucpkdfmtjapanese" | "csgb2312" | "csibm866" | "csiso2022jp" | "csiso2022kr" | "csiso58gb231280" | "csiso88596e" | "csiso88596i" | "csiso88598e" | "csiso88598i" | "csisolatin1" | "csisolatin2" | "csisolatin3" | "csisolatin4" | "csisolatin5" | "csisolatin6" | "csisolatin9" | "csisolatinarabic" | "csisolatincyrillic" | "csisolatingreek" | "csisolatinhebrew" | "cskoi8r" | "csksc56011987" | "csmacintosh" | "csshiftjis" | "cyrillic" | "dos-874" | "ecma-114" | "ecma-118" | "elot_928" | "euc-jp" | "euc-kr" | "gb18030" | "gb2312" | "gb_2312" | "gb_2312-80" | "gbk" | "greek" | "greek8" | "hebrew" | "hz-gb-2312" | "ibm819" | "ibm866" | "iso-2022-cn" | "iso-2022-cn-ext" | "iso-2022-jp" | "iso-2022-kr" | "iso-8859-1" | "iso-8859-10" | "iso-8859-11" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-6-e" | "iso-8859-6-i" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-e" | "iso-8859-8-i" | "iso-8859-9" | "iso-ir-100" | "iso-ir-101" | "iso-ir-109" | "iso-ir-110" | "iso-ir-126" | "iso-ir-127" | "iso-ir-138" | "iso-ir-144" | "iso-ir-148" | "iso-ir-149" | "iso-ir-157" | "iso-ir-58" | "iso8859-1" | "iso8859-10" | "iso8859-11" | "iso8859-13" | "iso8859-14" | "iso8859-15" | "iso8859-2" | "iso8859-3" | "iso8859-4" | "iso8859-6" | "iso8859-7" | "iso8859-8" | "iso8859-9" | "iso88591" | "iso885910" | "iso885911" | "iso885913" | "iso885914" | "iso885915" | "iso88592" | "iso88593" | "iso88594" | "iso88595" | "iso88596" | "iso88597" | "iso88598" | "iso88599" | "iso_8859-1" | "iso_8859-1:1987" | "iso_8859-2" | "iso_8859-2:1987" | "iso_8859-3" | "iso_8859-3:1988" | "iso_8859-4" | "iso_8859-4:1988" | "iso_8859-5" | "iso_8859-5:1988" | "iso_8859-6" | "iso_8859-6:1987" | "iso_8859-7" | "iso_8859-7:1987" | "iso_8859-8" | "iso_8859-8:1988" | "iso_8859-9" | "iso_8859-9:1989" | "koi" | "koi8" | "koi8-r" | "koi8-u" | "koi8_r" | "korean" | "ks_c_5601-1987" | "ks_c_5601-1989" | "ksc5601" | "ksc_5601" | "l1" | "l2" | "l3" | "l4" | "l5" | "l6" | "l9" | "latin1" | "latin2" | "latin3" | "latin4" | "latin5" | "latin6" | "latin9" | "logical" | "mac" | "macintosh" | "ms_kanji" | "shift-jis" | "shift_jis" | "sjis" | "sun_eu_greek" | "tis-620" | "unicode-1-1-utf-8" | "us-ascii" | "utf-16" | "utf-16be" | "utf-16le" | "utf-8" | "utf8" | "visual" | "windows-1250" | "windows-1251" | "windows-1252" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "windows-31j" | "windows-874" | "windows-949" | "x-cp1250" | "x-cp1251" | "x-cp1252" | "x-cp1253" | "x-cp1254" | "x-cp1255" | "x-cp1256" | "x-cp1257" | "x-cp1258" | "x-euc-jp" | "x-gbk" | "x-mac-cyrillic" | "x-mac-roman" | "x-mac-ukrainian" | "x-sjis" | "x-user-defined" | "x-x-big5";
|
|
1
2
|
interface GetArgv {
|
|
2
3
|
readonly PID_MAX: number;
|
|
3
4
|
readonly ARG_MAX: number;
|
|
4
|
-
get_argv_of_pid(pid: number, nuls: boolean, skip: number):
|
|
5
|
-
|
|
5
|
+
get_argv_of_pid(pid: number, nuls: boolean, skip: number): ArrayBuffer;
|
|
6
|
+
as_string(pid: number, encoding: Labels, nuls: boolean, skip: number): String;
|
|
7
|
+
get_argv_and_argc_of_pid(pid: number): Array<ArrayBuffer>;
|
|
8
|
+
as_array(pid: number, encoding: Labels): Array<string>;
|
|
6
9
|
}
|
|
7
10
|
declare const addon: GetArgv;
|
|
8
11
|
export = addon;
|
package/dist/binding.js
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const addon = require('../build/Release/getargv_native');
|
|
3
|
+
addon.as_string = function as_string(pid, encoding, nuls, skip) {
|
|
4
|
+
if (!pid) {
|
|
5
|
+
throw new TypeError('The "pid" argument must be specified');
|
|
6
|
+
}
|
|
7
|
+
if (!encoding) {
|
|
8
|
+
throw new TypeError('The "encoding" argument must be specified');
|
|
9
|
+
}
|
|
10
|
+
const decoder = new TextDecoder(encoding);
|
|
11
|
+
const array = addon.get_argv_of_pid(pid, nuls !== null && nuls !== void 0 ? nuls : false, skip !== null && skip !== void 0 ? skip : 0);
|
|
12
|
+
return decoder.decode(array);
|
|
13
|
+
};
|
|
14
|
+
addon.as_array = function as_array(pid, encoding) {
|
|
15
|
+
if (!pid) {
|
|
16
|
+
throw new TypeError('The "pid" argument must be specified');
|
|
17
|
+
}
|
|
18
|
+
if (!encoding) {
|
|
19
|
+
throw new TypeError('The "encoding" argument must be specified');
|
|
20
|
+
}
|
|
21
|
+
const decoder = new TextDecoder(encoding);
|
|
22
|
+
const array = addon.get_argv_and_argc_of_pid(pid);
|
|
23
|
+
return array.map(b => decoder.decode(b));
|
|
24
|
+
};
|
|
25
|
+
exports.PID_MAX = addon.PID_MAX;
|
|
26
|
+
exports.ARG_MAX = addon.ARG_MAX;
|
|
27
|
+
exports.get_argv_of_pid = addon.get_argv_of_pid;
|
|
28
|
+
exports.as_string = addon.as_string;
|
|
29
|
+
exports.get_argv_and_argc_of_pid = addon.get_argv_and_argc_of_pid;
|
|
30
|
+
exports.as_array = addon.as_array;
|
|
3
31
|
module.exports = addon;
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"getargv": "lib/cli.js"
|
|
4
4
|
},
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@types/node": "^18.
|
|
7
|
-
"typescript": "^4.9.
|
|
6
|
+
"@types/node": "^18.14.6",
|
|
7
|
+
"typescript": "^4.9.5"
|
|
8
8
|
},
|
|
9
9
|
"os": [
|
|
10
10
|
"darwin"
|
|
@@ -16,17 +16,20 @@
|
|
|
16
16
|
"name": "@camjn/getargv",
|
|
17
17
|
"homepage": "https://getargv.narzt.cam/",
|
|
18
18
|
"author": "Camden Narzt <getargv@narzt.cam>",
|
|
19
|
-
"version": "0.0.
|
|
19
|
+
"version": "0.0.5",
|
|
20
20
|
"description": "This library allows you to query the arguments of other processes on macOS.",
|
|
21
21
|
"main": "dist/binding.js",
|
|
22
22
|
"scripts": {
|
|
23
|
+
"prebuild": "tsc",
|
|
23
24
|
"build": "node-gyp configure build",
|
|
24
|
-
"pretest": "
|
|
25
|
+
"pretest": "npm run build",
|
|
25
26
|
"test": "node --napi-modules ./test/test_binding.js",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
27
|
+
"prepack": "npm run build",
|
|
28
|
+
"precli": "npm run build",
|
|
28
29
|
"cli": "node dist/cli.js",
|
|
29
|
-
"
|
|
30
|
+
"preconsole": "npm run build",
|
|
31
|
+
"console": "node --napi-modules -r ./dist/binding.js -e 'const GetArgv = require.cache[Object.keys(require.cache)[0]].exports;' -i",
|
|
32
|
+
"start": "npm run console"
|
|
30
33
|
},
|
|
31
34
|
"files": [
|
|
32
35
|
"/README.md",
|
package/src/getargv.c
CHANGED
|
@@ -19,7 +19,7 @@ napi_value get_undefined(napi_env env) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
napi_value create_system_error(napi_env env, errno_t err) {
|
|
22
|
-
//we skip checking status in here because we already have a failure
|
|
22
|
+
// we skip checking status in here because we already have a failure
|
|
23
23
|
napi_value code;
|
|
24
24
|
napi_create_string_utf8(env, "ERR_SYSTEM_ERROR", NAPI_AUTO_LENGTH, &code);
|
|
25
25
|
|
|
@@ -129,15 +129,16 @@ napi_value GetArgvOfPid(napi_env env, napi_callback_info info) {
|
|
|
129
129
|
|
|
130
130
|
napi_throw(env, error);
|
|
131
131
|
} else {
|
|
132
|
-
|
|
132
|
+
char *innerbuff = NULL;
|
|
133
|
+
if (napi_create_arraybuffer(env,
|
|
133
134
|
result.end_pointer - result.start_pointer + 1,
|
|
134
|
-
&args) != napi_ok) {
|
|
135
|
-
// args not guaranteed to be utf8 or even latin1/ascii, but ruby, swift,
|
|
136
|
-
// and node all want strings to be properly encoded
|
|
135
|
+
(void **)&innerbuff, &args) != napi_ok) {
|
|
137
136
|
napi_throw_error(env, "ERR_INTERNAL_ASSERTION",
|
|
138
137
|
"Unable to create return value");
|
|
138
|
+
} else {
|
|
139
|
+
memcpy(innerbuff, result.start_pointer, result.end_pointer - result.start_pointer + 1);
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
+
free_ArgvResult(&result);
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
return args;
|
|
@@ -158,24 +159,24 @@ napi_value GetArgvAndArgcOfPid(napi_env env, napi_callback_info info) {
|
|
|
158
159
|
"Unable to create return value");
|
|
159
160
|
} else {
|
|
160
161
|
for (size_t i = 0; i < result.argc; i++) {
|
|
161
|
-
napi_value
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (
|
|
165
|
-
|
|
162
|
+
napi_value buffer;
|
|
163
|
+
char *innerbuff = NULL;
|
|
164
|
+
size_t len = strlen(result.argv[i]) + 1;
|
|
165
|
+
if (napi_create_arraybuffer(env, len, (void **)&innerbuff, &buffer) !=
|
|
166
|
+
napi_ok) {
|
|
166
167
|
napi_throw_error(env, "ERR_INTERNAL_ASSERTION",
|
|
167
|
-
"Unable to create
|
|
168
|
+
"Unable to create ArrayBuffer");
|
|
168
169
|
break;
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
+
memcpy(innerbuff, result.argv[i], len);
|
|
172
|
+
if (napi_ok != napi_set_element(env, args, i, buffer)) {
|
|
171
173
|
napi_throw_error(env, "ERR_INTERNAL_ASSERTION",
|
|
172
174
|
"Unable to populate array");
|
|
173
175
|
break;
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
|
-
|
|
178
|
-
free(result.buffer);
|
|
179
|
+
free_ArgvArgcResult(&result);
|
|
179
180
|
}
|
|
180
181
|
|
|
181
182
|
return args;
|