diff --git a/README.md b/README.md index c24ff24..8d7fc51 100644 --- a/README.md +++ b/README.md @@ -122,13 +122,12 @@ In its present form, the module has these limitations: * filenames are limited to 255 chars * file contents must be text * or have a `\n` at least every 4096 characters - * `sed()` requires lines <=2048 characters, and this `sed()` won't match binary chars + * `sed()` requires lines <=2048 characters, and this `sed()` will not match binary chars * in the simple shell * filenames must not have spaces * patterns with spaces ***must*** be quoted - * the target of `cp` and `mv` *cannot* be a simple a directory-name as in Linux; write the whole filename *w.r.t,* the current directory -* for the `sed` function and command, the -[search](https://docs.micropython.org/en/latest/library/ure.html) pattern can have wildcards like ``\s`, `\w` and `\d`. The replace pattern cannot have *any* of these, and can only have `\0`, `\1`, etc + * the target of `cp` and `mv` *cannot* be a simple a directory-name as in Linux; write the whole filename *w.r.t* the current directory +* for the `sed` function and command, the [search](https://docs.micropython.org/en/latest/library/ure.html) pattern can have wildcards like ``\s`, `\w` and `\d`. The replace pattern cannot have *any* of these, and can only have `\0`, `\1`, etc * search patterns involving \ escapes other than those and `\'` probably won't work * the complexity of pattern matching is limited. * try to format the grep patterns so they avoid deep stack recursion. For example, `([^#]|\\#)\s*` has a very generous search term as the first half, and can cause deep-stack recursion. The equivalent `(\\#|[^#])\s*` is more likely to succeed. @@ -230,6 +229,7 @@ exec # execute a small python file free # display the heap size: used + free wc # display the line count, word count and bytes less/more [-n] # similar to cat, but displays 30 lines at a time +btree # display the content of a BTREE database ``` Synonyms: `ip = ifconfig`, `more = less`, `dig = nslookup = host` diff --git a/tf_extend.py b/tf_extend.py index e1c4e35..3d177e8 100644 --- a/tf_extend.py +++ b/tf_extend.py @@ -1,4 +1,4 @@ -import os,sys,network,socket,time,machine,gc,tf +import os,sys,network,socket,time,machine,gc,tf,btree # these helper classes let us use the tf.transfer() iterator, # by intercepting the .write() @@ -81,12 +81,33 @@ def cmd(args): print("ch: {}\tRSSI: {}\t{}\tSSID: {}".format(i[2],i[3],"open" if i[4]==0 else "",i[0])) elif cmd=='freq': - if len(args)==1 or args[1] in ("160","80"): + # identify esp32 or esp8266 + try: # is this esp8266 + machine.TouchPad + freqs=("160","80","240") + except AttributeError: + freqs=("160","80") + if len(args)==1 or args[1] in freqs: if len(args)>1: machine.freq(int(args[1])*1000000) print("master cpu frequency {}MHz".format(machine.freq()//1000000)) else: - print("syntax: freq [ 160 | 80 ]") + print("syntax: freq [ 160 | 80 | 240 ] ") + + elif cmd=='btree': + try: + f=open(args[1]) + b=btree.open(f) + print("Key\t\tValue") + i=0 + for w in b: + print("{}\t{}".format(w,b[w])) + i+=1 + if i%30==0: + r=input("continue? ") + if r=='n': break + except OSError: + print("file not found or is not a btree database") elif cmd=='exec': try: @@ -99,9 +120,10 @@ def cmd(args): print("==Extended commands") print(" connect \tscan") print(" ifconfig/ip \t\thost/dig/nslookup ") - print(" freq [ 160 | 80 ] \t\texec ") + print(" freq [160 | 80 | 240]\texec ") print(" free \t\t\twc ") print(" less/more [-n] ") + print(" bt-list ") else: # command not found return False return True