mkwnew.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. void
  12. main(int argc, char *argv[])
  13. {
  14. int i, fd, pid, n;
  15. char wdir[256];
  16. int dflag;
  17. dflag = 0;
  18. ARGBEGIN{
  19. case 'd':
  20. dflag = 1;
  21. break;
  22. default:
  23. fprint(2, "usage: wnew [-d] [label]\n");
  24. }ARGEND
  25. pid = getpid();
  26. wdir[0] = '\0';
  27. if(!dflag)
  28. getwd(wdir, sizeof wdir);
  29. if(argc>0)
  30. for(i=0; i<argc; i++)
  31. snprint(wdir, sizeof wdir, "%s%c%s", wdir, i==0? '/' : '-', argv[i]);
  32. else
  33. snprint(wdir, sizeof wdir, "%s/-win", wdir);
  34. if((fd = open("/dev/wnew", ORDWR)) < 0)
  35. sysfatal("wnew: can't open /dev/wnew: %r");
  36. if(fprint(fd, "%d %s", pid, wdir+dflag) < 0)
  37. sysfatal("wnew: can't create window: %r");
  38. if(seek(fd, 0, 0) != 0)
  39. sysfatal("wnew: can't seek: %r");
  40. if((n=read(fd, wdir, sizeof wdir-1)) < 0)
  41. sysfatal("wnew: can't read window id: %r");
  42. wdir[n] = '\0';
  43. print("%s\n", wdir);
  44. exits(nil);
  45. }