ref: dff69d59222cc0431bdea15ee31a87b557872c08
parent: 40f69f4df5f228459cebab1b529ad84bf18c86e1
author: ftrvxmtrx <ftrvxmtrx@gmail.com>
date: Tue Oct 18 16:02:01 EDT 2016
samterm: support "showdata" plumb action
--- a/sys/src/cmd/samterm/plan9.c
+++ b/sys/src/cmd/samterm/plan9.c
@@ -184,8 +184,8 @@
plumbformat(int i)
{
Plumbmsg *m;
- char *addr, *data, *act;
- int n;
+ char *addr, *data, *act, *s;
+ int n, replaced;
data = (char*)plumbbuf[i].data;
m = plumbunpack(data, plumbbuf[i].n);
@@ -197,6 +197,37 @@
return 0;
}
act = plumblookup(m->attr, "action");
+
+ if(act != nil && strcmp(act, "showdata") == 0){
+ addr = plumblookup(m->attr, "filename");
+ n = sprint(data, "B \n");
+ if(addr != nil)
+ n += sprint(data+n, "f %s\n", addr);
+ n += sprint(data+n, "c\n");
+ s = memmove(data+n, m->data, m->ndata);
+ n += m->ndata;
+ if(data[n-1] != '\n')
+ data[n++] = '\n';
+ data[n] = 0;
+ replaced = 0;
+ for(;;){
+ s = strstr(s, ".\n");
+ if(s == nil)
+ break;
+ if(s[-1] != '\n')
+ continue;
+ s[0] = '';
+ s += 2;
+ replaced = 1;
+ }
+ n += sprint(data+n, ".\n");
+ if(replaced)
+ n += sprint(data+n, ",s/^$/./g\n");
+ plumbbuf[i].n = n;
+ plumbfree(m);
+ return 1;
+ }
+
if(act!=nil && strcmp(act, "showfile")!=0){
/* can't handle other cases yet */
plumbfree(m);