-
Notifications
You must be signed in to change notification settings - Fork 10
/
encode128
executable file
·59 lines (54 loc) · 1.98 KB
/
encode128
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
"use strict";
var Encoder = require("./")
var encoder = new Encoder()
function doencode(){
var o="ascii"
var m=0
var pipe=false
for(var i = 2;i<process.argv.length;i++){
switch(process.argv[i]){
case "-o":
case "--output":
i++
o = process.argv[i]
break
case "-m":
case "--mapping":
i++
m=parseInt(process.argv[i])
break
case "-h":
case "--help":
displayHelp()
return
break
case "-":
pipe=true
process.stdin.resume()
process.stdin.setEncoding("utf-8")
process.stdin.on("data",function(data){
data = data.replace("\n","")
console.log(encoder.encode(data,{output:o,mapping:m}))
process.exit()
})
break
}
}
if(!pipe) console.log(encoder.encode(process.argv[i-1],{output:o,mapping:m}))
}
function displayHelp(){
console.log("usage: \t encode128 [OPTIONS...] STRING_TO_ENCODE\n")
console.log("OPTIONS\n-------\n\n")
console.log("-o, \t --output [output-option] \t changes the output of the encoder. possible outputs are:\n")
console.log("\t \t ascii: \t a string of ascii characters (default)")
console.log("\t \t bars: \t\t a as string of bars and spaces,\n\t\t\t\t where a bar is represented as 1 and a space represented as 0")
console.log("\t \t weights: \t a as string of weights,\n\t\t\t\t where each number represents a length of countinous spaces or lines")
console.log("\t \t codes: \t an array of code numbers,\n\t\t\t\t where each number code index in the code 128 spec")
console.log("\t \t array: \t an arry of ascii code points")
console.log("-m, \t --mapping [mapping-option] \t changes the ascii-output of the encoder. possible outputs are:\n")
console.log("\t \t 0: \t common encoding used in most fonts (default)")
console.log("\t \t 1: \t barcodesoft encoding")
console.log("\t \t 2: \t faulty encoding formaly used in wikipedias mapping table")
}
doencode()