#!/usr/bin/env jsish /* Show ASCII table, -showAll true to include control codes */ function showASCIITable(args:array|string=void, conf:object=void) { var options = { // Rosetta Code, Show ASCII table rootdir :'', // Root directory. showAll : false // include control code labels if true }; var self = {}; parseOpts(self, options, conf); function main() { var e; var first = (self.showAll) ? 0 : 2; var filler = '='.repeat(19 + ((first) ? 0 : 9)); puts(filler, "ASCII table", filler + '='); var labels = [ 'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS ', 'HT ', 'LF ', 'VT ', 'FF ', 'CR ', 'SO ', 'SI ', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM ', 'SUB', 'ESC', 'FS ', 'GS ', 'RS ', 'US ']; var table = new Array(128); for (e = 0; e < 32; e++) table[e] = labels[e]; for (e = 32; e < 127; e++) table[e] = ' ' + Util.fromCharCode(e) + ' '; table[32] = 'SPC'; table[127] = 'DEL'; for (var row = 0; row < 16; row++) { for (var col = first; col < 8; col++) { e = row + col * 16; printf('%03d %s ', e, table[e]); } printf('\n'); } } return main(); } provide(showASCIITable, 1); if (isMain()) { if (Interp.conf('unitTest')) showASCIITable('', {showAll:true}); else runModule(showASCIITable); } /* =!EXPECTSTART!= ============================ ASCII table ============================= 000 NUL 016 DLE 032 SPC 048 0 064 @ 080 P 096 ` 112 p 001 SOH 017 DC1 033 ! 049 1 065 A 081 Q 097 a 113 q 002 STX 018 DC2 034 " 050 2 066 B 082 R 098 b 114 r 003 ETX 019 DC3 035 # 051 3 067 C 083 S 099 c 115 s 004 EOT 020 DC4 036 $ 052 4 068 D 084 T 100 d 116 t 005 ENQ 021 NAK 037 % 053 5 069 E 085 U 101 e 117 u 006 ACK 022 SYN 038 & 054 6 070 F 086 V 102 f 118 v 007 BEL 023 ETB 039 ' 055 7 071 G 087 W 103 g 119 w 008 BS 024 CAN 040 ( 056 8 072 H 088 X 104 h 120 x 009 HT 025 EM 041 ) 057 9 073 I 089 Y 105 i 121 y 010 LF 026 SUB 042 * 058 : 074 J 090 Z 106 j 122 z 011 VT 027 ESC 043 + 059 ; 075 K 091 [ 107 k 123 { 012 FF 028 FS 044 , 060 < 076 L 092 \ 108 l 124 | 013 CR 029 GS 045 - 061 = 077 M 093 ] 109 m 125 } 014 SO 030 RS 046 . 062 > 078 N 094 ^ 110 n 126 ~ 015 SI 031 US 047 / 063 ? 079 O 095 _ 111 o 127 DEL =!EXPECTEND!= */