ref: 80075967797d5ccd098ad496a9f9f963ddd95ce0
parent: 948d0a1180a57f61285abd4a59c7351b6197d3d5
author: cinap_lenrek <[email protected]>
date: Mon Sep 24 18:50:44 EDT 2012
mothra: forgot to add snarf.c
--- /dev/null
+++ b/sys/src/cmd/mothra/libpanel/snarf.c
@@ -1,0 +1,60 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+#include <panel.h>
+#include "pldefs.h"
+
+void plputsnarf(char *s){
+ int fd;
+
+ if(s==0 || *s=='\0')
+ return;
+ if((fd=open("/dev/snarf", OWRITE|OTRUNC))>=0){
+ write(fd, s, strlen(s));
+ close(fd);
+ }
+}
+char *plgetsnarf(void){
+ int fd, n, r;
+ char *s, *x;
+
+ if((fd=open("/dev/snarf", OREAD))<0)
+ return nil;
+ n=0;
+ s=nil;
+ for(;;){
+ if((x=realloc(s, n+1024))==0)
+ break;
+ s=x;
+ if((r = read(fd, s+n, 1024)) <= 0)
+ break;
+ n += r;
+ }
+ close(fd);
+ if(n <= 0){
+ free(s);
+ return nil;
+ }
+ s[n] = '\0';
+ return s;
+}
+void plsnarf(Panel *p){
+ char *s;
+
+ if(p==0 || p->snarf==0)
+ return;
+ s=p->snarf(p);
+ plputsnarf(s);
+ free(s);
+}
+void plpaste(Panel *p){
+ char *s;
+
+ if(p==0 || p->paste==0)
+ return;
+ if(s=plgetsnarf()){
+ p->paste(p, s);
+ free(s);
+ }
+}