home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume19 / xtolplcs / part02 < prev    next >
Encoding:
Text File  |  1993-04-27  |  53.8 KB  |  1,590 lines

  1. Newsgroups: comp.sources.x
  2. From: adam@iset.scan.mc.xerox.com (Adam Stein)
  3. Subject: v19i076:  Xtoolplaces - save current X desktop window information, Part02/03
  4. Message-ID: <1993Apr6.143502.15292@sparky.imd.sterling.com>
  5. X-Md4-Signature: 2f7854d98e280da15f0db09edf21e8a6
  6. Date: Tue, 6 Apr 1993 14:35:02 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: adam@iset.scan.mc.xerox.com (Adam Stein)
  10. Posting-number: Volume 19, Issue 76
  11. Archive-name: Xtoolplaces/part02
  12. Environment: X11, !mwm, !tvtwm
  13. Supersedes: Xtoolplaces: Volume 14, Issue 2-3
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # Contents:  Makefile.simple adddisplay.c addon.c combine.c copyright.c
  20. #   fix_command.c get_geometry.c getgeom.c make_list.c xtoolplaces.c
  21. #   xtoolplaces.man
  22. # Wrapped by chris@sparky on Tue Apr  6 09:15:54 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 2 (of 3)."'
  26. if test -f 'Makefile.simple' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Makefile.simple'\"
  28. else
  29.   echo shar: Extracting \"'Makefile.simple'\" \(1845 characters\)
  30.   sed "s/^X//" >'Makefile.simple' <<'END_OF_FILE'
  31. X# Copyright (c) 1993 Xerox Corporation.  All Rights Reserved. 
  32. X#
  33. X# Permission to use,  copy,  modify  and  distribute  without
  34. X# charge this software, documentation, images, etc. is grant-
  35. X# ed, provided that this copyright and the author's  name  is 
  36. X# retained. 
  37. X# 
  38. X# A fee may be charged for this program ONLY to recover costs 
  39. X# for distribution (i.e. media costs).  No profit can be made    
  40. X# on this program. 
  41. X# 
  42. X# The author assumes no responsibility for disasters (natural 
  43. X# or otherwise) as a consequence of use of this software.  
  44. X# 
  45. X# Adam Stein (adam@iset.scan.mc.xerox.com)
  46. X
  47. X# Name of program to build
  48. XTARGET=xtoolplaces
  49. X
  50. X# Name of resource file
  51. XRESOURCE=Xtoolplaces
  52. X
  53. X# Directories to install to
  54. XBINDIR=/usr/local/bin
  55. XMANDIR=/usr/local/man/man1
  56. XAPPSDIR=/usr/lib/X11/app-defaults
  57. X
  58. X# Top level of X directory structure
  59. XXTOP=/usr/local/openwin
  60. X
  61. X#Choose a C compiler
  62. X#CC=gcc
  63. XCC=cc
  64. X
  65. X# Choose the flags needed for the C compiler, the first one is for gcc
  66. X#CFLAGS=-I${XTOP}/include -traditional -fpcc-struct-return -c -O
  67. XCFLAGS=-I${XTOP}/include
  68. X
  69. XINCS=addon.h patchlevel.h xtoolplaces.h
  70. XSRCS=copyright.c adddisplay.c addon.c combine.c fix_command.c\
  71. X     getargs.c getgeom.c getinfo.c is.c make_list.c missing.c\
  72. X     strdup.c strstr.c xtoolplaces.c
  73. XOBJS=copyright.o adddisplay.o addon.o combine.o fix_command.o\
  74. X     getargs.o getgeom.o getinfo.o is.o make_list.o missing.o\
  75. X     strdup.o strstr.o xtoolplaces.o
  76. X
  77. X.KEEP_STATE:
  78. X
  79. X${TARGET}: ${OBJS}
  80. X    ${CC} -o ${TARGET} ${OBJS} -lX11
  81. X
  82. Xinstall: ${TARGET}
  83. X    install -s ${TARGET} ${BINDIR}
  84. X    install ${TARGET}.man ${MANDIR}/${TARGET}.1
  85. X    install ${RESOURCE}.ad ${APPSDIR}/${RESOURCE}
  86. X
  87. Xclean:
  88. X    rm -f core makelog ${TARGET} ${OBJS}
  89. X
  90. Xshar:
  91. X    shar -c -o ${TARGET} -l50 README CHANGES MANIFEST Imakefile \
  92. X    Makefile.simple ${RESOURCE}.ad xtoolplaces.man ${SRCS} ${INCS} \
  93. X    addon.sample missing.sample
  94. X
  95. END_OF_FILE
  96.   if test 1845 -ne `wc -c <'Makefile.simple'`; then
  97.     echo shar: \"'Makefile.simple'\" unpacked with wrong size!
  98.   fi
  99.   # end of 'Makefile.simple'
  100. fi
  101. if test -f 'adddisplay.c' -a "${1}" != "-c" ; then 
  102.   echo shar: Will not clobber existing file \"'adddisplay.c'\"
  103. else
  104.   echo shar: Extracting \"'adddisplay.c'\" \(1951 characters\)
  105.   sed "s/^X//" >'adddisplay.c' <<'END_OF_FILE'
  106. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  107. X
  108. X  Permission to use,  copy,  modify  and  distribute  without
  109. X  charge this software, documentation, images, etc. is grant-
  110. X  ed, provided that this copyright and the author's  name  is
  111. X  retained.
  112. X
  113. X  A fee may be charged for this program ONLY to recover costs
  114. X  for distribution (i.e. media costs).  No profit can be made
  115. X  on this program.
  116. X
  117. X  The author assumes no responsibility for disasters (natural
  118. X  or otherwise) as a consequence of use of this software.
  119. X
  120. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  121. X*/
  122. X
  123. X#include <stdio.h>
  124. X#include <X11/Xos.h>
  125. X
  126. Xextern FILE *fp;
  127. X
  128. X/*This function will add the '-display' to windows that don't already have
  129. X  it if xtoolplaces is saving from more than 1 screen.  This is done
  130. X  because a user might start an application in 1 screen (so that -display
  131. X  isn't needed) and run xtoolplaces from another.  To insure that the
  132. X  applications starts up on the right screen, '-display' is added to all
  133. X  applications.
  134. X
  135. X  Three assumptions are made:
  136. X
  137. X  1) if a colon (:) is found on the command line, it belongs to
  138. X     HOST:SERVER.SCREEN and not to some other option
  139. X  2) if a window already has a '-display' option (i.e. a colon was
  140. X     found in the command line), it points to the correct screen
  141. X     and nothing is changed or added
  142. X  3) every window that has '-display' added used '-display' (and
  143. X     not '-d' or something else)
  144. X
  145. X  Inputs:  command_line   - command line to see if it already has option or not
  146. X       display_number - number of the display this will be working under
  147. X       screen_number  - number of the screen this window is on
  148. X  Outputs: none
  149. X  Locals:  none
  150. X  Globals: fp             - file pointer to write window information to
  151. X*/
  152. Xchar *adddisplay(command_line,displaynum,screennum)
  153. Xregister int displaynum,screennum;
  154. Xregister char *command_line;
  155. X{
  156. X    if(!index(command_line,':'))
  157. X      fprintf(fp,"-display :%d.%d ",displaynum,screennum);
  158. X}
  159. X
  160. END_OF_FILE
  161.   if test 1951 -ne `wc -c <'adddisplay.c'`; then
  162.     echo shar: \"'adddisplay.c'\" unpacked with wrong size!
  163.   fi
  164.   # end of 'adddisplay.c'
  165. fi
  166. if test -f 'addon.c' -a "${1}" != "-c" ; then 
  167.   echo shar: Will not clobber existing file \"'addon.c'\"
  168. else
  169.   echo shar: Extracting \"'addon.c'\" \(4825 characters\)
  170.   sed "s/^X//" >'addon.c' <<'END_OF_FILE'
  171. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  172. X
  173. X  Permission to use,  copy,  modify  and  distribute  without
  174. X  charge this software, documentation, images, etc. is grant-
  175. X  ed, provided that this copyright and the author's  name  is
  176. X  retained.
  177. X
  178. X  A fee may be charged for this program ONLY to recover costs
  179. X  for distribution (i.e. media costs).  No profit can be made
  180. X  on this program.
  181. X
  182. X  The author assumes no responsibility for disasters (natural
  183. X  or otherwise) as a consequence of use of this software.
  184. X
  185. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  186. X*/
  187. X
  188. X#include <stdio.h>
  189. X#include <ctype.h>
  190. X#include <X11/Xos.h>
  191. X#include "addon.h"
  192. X
  193. XADDON *head = NULL;
  194. Xextern char *program,*addon;
  195. Xextern FILE *fp;
  196. X
  197. X/*This function will read in a file containing strings to put onto the
  198. X  command line.  This is used when WM_COMMAND isn't complete.  In the case
  199. X  of xrolo, the data file is never listed in WM_COMMAND and must be put
  200. X  added.  I don't know if this is an XVIEW bug or not.  I haven't seen it
  201. X  with any other program (yet).
  202. X
  203. X  Inputs:  none
  204. X  Outputs: none
  205. X  Locals:  fp      - file pointer to read from
  206. X       line    - line of text read in
  207. X  Globals: addon   - name of file containing commands to add on
  208. X       program - name of currently executing program
  209. X       stderr  - standard error
  210. X       NULL    - 0
  211. X*/
  212. Xread_addon()
  213. X{
  214. X    register char line[200];
  215. X    register FILE *fp;
  216. X
  217. X    /*Open the file for reading*/
  218. X    if((fp = fopen(addon,"r")) == NULL) {
  219. X      fprintf(stderr,"%s: can't open {%s}\n",program,addon);
  220. X      exit(1);
  221. X    }
  222. X
  223. X    /*Read lines from file until there is no more*/
  224. X    while(fgets(line,200,fp) != NULL)
  225. X      switch(line[0]) {
  226. X        case '#':            /*Comment character - ignore line*/
  227. X        case '\n':            /*Blank line - ignore line*/
  228. X            break;
  229. X        default:
  230. X            line[strlen(line)-1] = '\0';  /*Take out NL char*/
  231. X            insert(line);
  232. X
  233. X            break;
  234. X      }
  235. X}
  236. X
  237. X/*This function will insert commands to be added into a linked list.
  238. X
  239. X  Inputs:  line    - line containing program name and commands to be added
  240. X  Outputs: none
  241. X  Locals:  next    - next available structure entry to fill in
  242. X       pointer - point to : to separater program from commands and to
  243. X             skip over white space to point to commands
  244. X  Globals: addon   - name of file containing commands to add on
  245. X       head    - pointer to head of linked list
  246. X       program - name of currently executing program
  247. X       stderr  - standard error
  248. X       ADDON   - structure holding program and command line info
  249. X       NULL    - 0
  250. X*/
  251. Xinsert(line)
  252. Xregister char *line;
  253. X{
  254. X    register char *pointer;
  255. X    register ADDON *next;
  256. X    char *calloc(),*strdup();
  257. X
  258. X    /*Find colon to make it a NULL thereby making line equal to just
  259. X      the program name.  Syntax error if the colon isn't found*/
  260. X    if((pointer = index(line,':')) == NULL) {
  261. X      fprintf(stderr,"%s: syntax error in {%s}\n",program,addon);
  262. X      exit(1);
  263. X    }
  264. X
  265. X    /*Insert new entry*/
  266. X    if(!head) {
  267. X      if((head = (ADDON *) calloc(1,sizeof(ADDON))) == NULL) {
  268. X        perror(program);
  269. X        exit(1);
  270. X      }
  271. X
  272. X      next = head;
  273. X    } else {
  274. X         for(next = head;next->next;next = next->next)
  275. X           ;
  276. X
  277. X         if((next->next = (ADDON *) calloc(1,sizeof(ADDON))) == NULL) { 
  278. X           perror(program);
  279. X           exit(1);
  280. X         }
  281. X
  282. X         next = next->next;
  283. X           }
  284. X
  285. X    /*Make colon NULL so that line equals just the program name*/
  286. X    *pointer = '\0';
  287. X
  288. X    if((next->program = strdup(line)) == NULL) {
  289. X      perror(program);
  290. X      exit(1);
  291. X    }
  292. X
  293. X    /*Put colon back and skip past whitespace to get to first character
  294. X      in command line*/
  295. X    *(pointer) = ':';
  296. X    while(isspace(*(++pointer))) ;
  297. X
  298. X    if((next->cmmd_line = strdup(pointer)) == NULL) {
  299. X      perror(program);
  300. X      exit(1);
  301. X    }
  302. X
  303. X    next->next = (ADDON *) NULL;
  304. X}
  305. X
  306. X/*This function will find the corresponding addon commands to the program
  307. X  being written out and at the commands to the command line being written
  308. X  out.
  309. X
  310. X  Inputs:  name - name of program being written out
  311. X  Outputs: none
  312. X  Locals:  list    - pointer to go through linked list
  313. X       pointer - pointer to make name equal to just the first word in string
  314. X  Globals: fp      - file pointer to write window information to
  315. X       head    - pointer to head of linked list
  316. X       NULL    - 0
  317. X*/
  318. Xaddto(name)
  319. Xregister char *name;
  320. X{
  321. X    register char *pointer;
  322. X    register ADDON *list;
  323. X
  324. X    /*If there is whitespace in the name string then put in a NULL to
  325. X      make name equal to just the first word in the string, otherwise
  326. X      assume the string is only made up of one word*/
  327. X    if((pointer = index(name,' ')) != NULL)
  328. X      *pointer = '\0';
  329. X
  330. X    /*Loop through linked list to match the program information saved with
  331. X      the name of the program being written out.  Write out saved addon
  332. X      command line when we find a match*/
  333. X    for(list = head;list;list = list->next)
  334. X      if(!strcmp(name,list->program)) {
  335. X        fprintf(fp,"%s ",list->cmmd_line);
  336. X        break;
  337. X      }
  338. X
  339. X    /*Put whitespace back to put the string back to normal*/
  340. X    if(pointer) *pointer = ' ';
  341. X}
  342. X
  343. END_OF_FILE
  344.   if test 4825 -ne `wc -c <'addon.c'`; then
  345.     echo shar: \"'addon.c'\" unpacked with wrong size!
  346.   fi
  347.   # end of 'addon.c'
  348. fi
  349. if test -f 'combine.c' -a "${1}" != "-c" ; then 
  350.   echo shar: Will not clobber existing file \"'combine.c'\"
  351. else
  352.   echo shar: Extracting \"'combine.c'\" \(2496 characters\)
  353.   sed "s/^X//" >'combine.c' <<'END_OF_FILE'
  354. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  355. X
  356. X  Permission to use,  copy,  modify  and  distribute  without
  357. X  charge this software, documentation, images, etc. is grant-
  358. X  ed, provided that this copyright and the author's  name  is
  359. X  retained.
  360. X
  361. X  A fee may be charged for this program ONLY to recover costs
  362. X  for distribution (i.e. media costs).  No profit can be made
  363. X  on this program.
  364. X
  365. X  The author assumes no responsibility for disasters (natural
  366. X  or otherwise) as a consequence of use of this software.
  367. X
  368. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  369. X*/
  370. X
  371. X#include <stdio.h>
  372. X
  373. Xextern char *program;
  374. X
  375. X/*This function will combine multiple argv[] strings into a single string.
  376. X  For command lines that are in multiple argv[] strings, any argument with
  377. X  whitespace will be double quoted.  It is assumed that command lines already
  378. X  in a single string have double quoted any white space arguments they have.
  379. X
  380. X  Inputs:  argc     - number of arguments
  381. X       argv     - list of arguments
  382. X  Outputs: pointer  - pointer to single string of arguments
  383. X  Locals:  loop     - loop through arguments
  384. X       numbytes - number of bytes needed for single argument string
  385. X       pointer  - pointer to single string of arguments
  386. X  Globals: NULL     - 0
  387. X*/
  388. Xchar *combine(argc,argv)
  389. Xregister int argc;
  390. Xregister char *argv[];
  391. X{
  392. X    register int numbytes,loop;
  393. X    register char *pointer;
  394. X    char *malloc(),*strdup(),*index();
  395. X
  396. X    /*If argc equals 1, then all the arguments are already in a single
  397. X      string and there's no reason to do anything else but copy it*/
  398. X    if(argc != 1) {
  399. X      /*Set numbytes initially to count the spaces between arguments
  400. X        and the NULL (number of arguments - 1 + 1)*/
  401. X      numbytes = argc;
  402. X
  403. X      /*Count bytes in each argument, add double quotes if argument
  404. X        has whitespace*/
  405. X      for(loop = 0;loop < argc;++loop) {
  406. X        if((index(argv[loop],' ') || index(argv[loop],'\t')) &&
  407. X           (argv[loop][0] != '"')) {
  408. X          if((pointer = malloc(strlen(argv[loop]) + 3)) == NULL) {
  409. X        perror(program);
  410. X        exit(1);
  411. X          } else {
  412. X               sprintf(pointer,"\"%s\"",argv[loop]);
  413. X               argv[loop] = pointer;
  414. X             }
  415. X        }
  416. X        numbytes += strlen(argv[loop]);
  417. X      }
  418. X
  419. X      if((pointer = malloc(numbytes)) == NULL) {
  420. X        perror(program);
  421. X        exit(1);
  422. X      }
  423. X
  424. X      strcpy(pointer,argv[0]);
  425. X
  426. X      for(loop = 1;loop < argc;++loop) {
  427. X        strcat(pointer," ");
  428. X        strcat(pointer,argv[loop]);
  429. X      }
  430. X    } else if((pointer = strdup(argv[0])) == NULL) {
  431. X         perror(program);
  432. X         exit(1);
  433. X           }
  434. X
  435. X    return(pointer);
  436. X}
  437. X
  438. END_OF_FILE
  439.   if test 2496 -ne `wc -c <'combine.c'`; then
  440.     echo shar: \"'combine.c'\" unpacked with wrong size!
  441.   fi
  442.   # end of 'combine.c'
  443. fi
  444. if test -f 'copyright.c' -a "${1}" != "-c" ; then 
  445.   echo shar: Will not clobber existing file \"'copyright.c'\"
  446. else
  447.   echo shar: Extracting \"'copyright.c'\" \(643 characters\)
  448.   sed "s/^X//" >'copyright.c' <<'END_OF_FILE'
  449. Xchar copyright[] =
  450. X"\
  451. XCopyright (c) 1993 Xerox Corporation.  All Rights Reserved.\n\
  452. X    \n\
  453. XPermission to use,  copy,  modify  and  distribute  without\n\
  454. Xcharge this software, documentation, images, etc. is grant-\n\
  455. Xed, provided that this copyright and the author's  name  is\n\
  456. Xretained.\n\
  457. X    \n\
  458. XA fee may be charged for this program ONLY to recover costs\n\
  459. Xfor distribution (i.e. media costs).  No profit can be made\n\
  460. Xon this program.\n\
  461. X    \n\
  462. XThe author assumes no responsibility for disasters (natural\n\
  463. Xor otherwise) as a consequence of use of this software.\n\
  464. X    \n\
  465. XAdam Stein (adam@iset.scan.mc.xerox.com)\n\
  466. X    \n\
  467. X";
  468. X
  469. END_OF_FILE
  470.   if test 643 -ne `wc -c <'copyright.c'`; then
  471.     echo shar: \"'copyright.c'\" unpacked with wrong size!
  472.   fi
  473.   # end of 'copyright.c'
  474. fi
  475. if test -f 'fix_command.c' -a "${1}" != "-c" ; then 
  476.   echo shar: Will not clobber existing file \"'fix_command.c'\"
  477. else
  478.   echo shar: Extracting \"'fix_command.c'\" \(2177 characters\)
  479.   sed "s/^X//" >'fix_command.c' <<'END_OF_FILE'
  480. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  481. X
  482. X  Permission to use,  copy,  modify  and  distribute  without
  483. X  charge this software, documentation, images, etc. is grant-
  484. X  ed, provided that this copyright and the author's  name  is
  485. X  retained.
  486. X
  487. X  A fee may be charged for this program ONLY to recover costs
  488. X  for distribution (i.e. media costs).  No profit can be made
  489. X  on this program.
  490. X
  491. X  The author assumes no responsibility for disasters (natural
  492. X  or otherwise) as a consequence of use of this software.
  493. X
  494. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  495. X*/
  496. X
  497. X#include <stdio.h>
  498. X#include <ctype.h>
  499. X#include "xtoolplaces.h"
  500. X
  501. X/*This routine will fix a problem caused by xview.  This routine is needed
  502. X  since xview seems to screw up WM_COMMAND when a command is started using
  503. X  the -Wl option (window label) with a string of more than 23 characters.  It
  504. X  does this by putting some of the label string after the last number for the
  505. X  icon position.  For exmaple, if a WM_SAVE_YOURSELF is sent to xrolo,
  506. X  WM_COMMAND is set to:
  507. X
  508. Xxrolo -Wp 29 278 -Ws 592 309 -WP 1085 241 1)" -Wl "Rolo - .work  (Card 1 of 1)"
  509. X
  510. X  The ' 1)"' after -WP 1085 241 shouldn't be there.  It seems to do this only
  511. X  with WM_COMMAND strings that are a single string (as opposed to xcalctool
  512. X  for example which breaks up the WM_COMMAND string where each word is it's
  513. X  own string).
  514. X
  515. X  To fix the problem, the offending characters are replaces with spaces.
  516. X
  517. X  Inputs:  string  - WM_COMMAND string
  518. X  Outputs: none
  519. X  Locals:  pointer - pointer to go through string
  520. X  Globals: NULL    - 0
  521. X*/
  522. Xfix_command(string)
  523. Xregister char *string;
  524. X{
  525. X    register char *pointer;
  526. X    char *strstr();
  527. X
  528. X    /*See if we have a string with the potential -WP problem*/
  529. X    if((pointer = strstr(string,"-WP")) != NULL) {
  530. X      /*Get to 2nd icon position*/
  531. X      pointer = strstr(pointer," ");
  532. X      pointer = strstr(++pointer," ");
  533. X
  534. X      /*Skip over Y icon position, which can consist of numbers or
  535. X        the + or - signs*/
  536. X      while(isdigit(*(++pointer)) || (*pointer == '+') ||
  537. X        (*pointer == '-'))
  538. X        ;
  539. X
  540. X      /*Change screwed up characters to spaces*/
  541. X      while(*pointer && *pointer != '-' && *pointer != '+')
  542. X        *(pointer++) = ' ';
  543. X    }
  544. X}
  545. X
  546. END_OF_FILE
  547.   if test 2177 -ne `wc -c <'fix_command.c'`; then
  548.     echo shar: \"'fix_command.c'\" unpacked with wrong size!
  549.   fi
  550.   # end of 'fix_command.c'
  551. fi
  552. if test -f 'get_geometry.c' -a "${1}" != "-c" ; then 
  553.   echo shar: Will not clobber existing file \"'get_geometry.c'\"
  554. else
  555.   echo shar: Extracting \"'get_geometry.c'\" \(7840 characters\)
  556.   sed "s/^X//" >'get_geometry.c' <<'END_OF_FILE'
  557. X/*Copyright (c) 1991 Xerox Corporation.  All Rights Reserved.
  558. X
  559. X  Permission to use,  copy,  modify  and  distribute  without
  560. X  charge this software, documentation, images, etc. is grant-
  561. X  ed, provided that this copyright and the author's  name  is
  562. X  retained.
  563. X
  564. X  A fee may be charged for this program ONLY to recover costs
  565. X  for distribution (i.e. media costs).  No profit can be made
  566. X  on this program.
  567. X
  568. X  The author assumes no responsibility for disasters (natural
  569. X  or otherwise) as a consequence of use of this software.
  570. X
  571. X  Adam Stein (stein.wbst129@xerox.com)
  572. X*/
  573. X
  574. X#include <stdio.h>
  575. X#include <X11/Xos.h>
  576. X#include <X11/Xlib.h>
  577. X#include <X11/Xutil.h>
  578. X
  579. Xextern char *program;
  580. Xextern Display *display;
  581. X
  582. X/*This function will get the window and icon geometry and add them to the
  583. X  command line.  For window geometry, it will add position and size.  For
  584. X  icon geometry, it will only add position.  This function makes some
  585. X  assumptions:
  586. X
  587. X    1) windows use "-g" for window geometry (which is an abbreviation for
  588. X       "-geom" or "-geometry")
  589. X    2) normal applications use "-iconGeom" for icon geometry while
  590. X       xterm uses "#"
  591. X    3) normal applications take the geometry size in pixels while
  592. X       xterm takes geometry size in characters
  593. X
  594. X  Inputs:  command_line  - command line arguments
  595. X       window        - ID of the window that we are going to check
  596. X  Outputs: command_line  - command line arguments with geometry info added
  597. X  Locals:  dummy     - dummary variable for return value we don't want
  598. X       dummywin     - dummary variable for return value we don't want
  599. X       geometry_args - geometry arguments to add to command line
  600. X       height     - height of window (in pixels)
  601. X       height_inc     - height increment
  602. X       hints     - window size hints
  603. X       icon_arg      - icon geometry argument
  604. X       icon_hints    - icon position hints
  605. X       icon_x     - X coordinate of icon
  606. X       icon_y     - Y coordinate of icon
  607. X       root         - root window of this window
  608. X       status        - status of get call
  609. X       supplied      - flag telling which size hints are available
  610. X       tx         - translated X coordinate
  611. X       ty         - translated Y coordinate
  612. X       width     - width of window (in pixels)
  613. X       width_inc     - width increment
  614. X       x         - X coordinate of window
  615. X       y         - Y coordinate of window
  616. X  Globals: display       - interface info to X display
  617. X       program     - name of currently executing program
  618. X       NULL         - 0
  619. X       PResizeInc    - flag bit to check if resize increment hint is avail.
  620. X*/
  621. Xchar *get_geometry(window,command_line)
  622. Xregister char *command_line;
  623. Xregister Window window;
  624. X{
  625. X    register int width_inc,height_inc;
  626. X    int x,y,tx,ty,icon_x,icon_y;
  627. X    unsigned int width,height,dummy;
  628. X    long supplied;
  629. X    register char *icon_arg,geometry_args[100];
  630. X    register Status status;
  631. X    Window root,dummywin;
  632. X    XSizeHints hints;
  633. X    register XWMHints *icon_hints;
  634. X    char *strip_geometry(),*strip_xterm_geometry(),*realloc(),*strdup();
  635. X
  636. X    /*Get icon position*/
  637. X    icon_x = icon_y = -1;
  638. X    icon_hints = XGetWMHints(display,window);
  639. X    if(icon_hints) {
  640. X      icon_x = icon_hints->icon_x;
  641. X      icon_y = icon_hints->icon_y;
  642. X      XFree(hints);
  643. X    }
  644. X
  645. X    /*Get window geometry*/
  646. X    status = XGetGeometry(display,window,&root,&x,&y,&width,&height,&dummy,
  647. X                  &dummy);
  648. X
  649. X    if(status) {
  650. X      width_inc = 1;
  651. X      height_inc = 1;
  652. X      icon_arg = "-iconGeom ";
  653. X
  654. X      /*Translate coordinate relative to root window*/
  655. X      XTranslateCoordinates(display,window,root,0,0,&tx,&ty,&dummywin);
  656. X
  657. X      /*Xterm is a special case (isn't it always?).  Unlike other programs,
  658. X        xterm takes it's dimensions in characters, not pixels.  This
  659. X        means we have to get it's increment size (i.e. font size) and
  660. X        divide the size of the window (in pixels) by it's font size to
  661. X        determine it's character size.  In addition, the argument to
  662. X        specify icon position is different from normal*/
  663. X      if(is_xterm(window) == 1) {
  664. X        /*Get increment (i.e. font size)*/
  665. X        status = XGetWMNormalHints(display,window,&hints,&supplied);
  666. X        if(!status || !(supplied & PResizeInc)) return(command_line);
  667. X
  668. X        width_inc = hints.width_inc;
  669. X        height_inc = hints.height_inc;
  670. X        icon_arg = "#";
  671. X
  672. X        /*Strip old geometry arguments out of command line (if the
  673. X          command line has any geometry arguments)*/
  674. X        command_line = strip_xterm_geometry(command_line);
  675. X      } else command_line = strip_geometry(command_line);
  676. X
  677. X      /*Put geometry information together in a string.  Put in icon
  678. X        information is there was icon information*/
  679. X      if(icon_x == -1)
  680. X        sprintf(geometry_args," -geom %dx%d+%d+%d",width/width_inc,height/height_inc,tx-x,ty-y);
  681. X      else
  682. X        sprintf(geometry_args," -geom %dx%d+%d+%d %s+%d+%d",width/width_inc,height/height_inc,tx-x,ty-y,icon_arg,icon_x,icon_y);
  683. X
  684. X      /*Add window and icon geometry*/
  685. X      if((command_line = realloc(command_line,strlen(command_line)+
  686. X                     strlen(geometry_args)+1)) == NULL) {
  687. X        perror(program);
  688. X        exit(1);
  689. X      }
  690. X
  691. X      strcat(command_line,geometry_args);
  692. X    }
  693. X
  694. X    return(command_line);
  695. X}
  696. X
  697. X/*This will strip out the geometry arguments for a normal X application.
  698. X
  699. X  Inputs:  command_line - command line arguments
  700. X  Outputs: command_line - command line arguments without geometry info
  701. X  Locals:  none
  702. X  Globals: none
  703. X*/
  704. Xchar *strip_geometry(command_line)
  705. Xregister char *command_line;
  706. X{
  707. X    char *strip_arg();
  708. X
  709. X    /*Strip window geometry*/
  710. X    command_line = strip_arg(command_line,"-g");
  711. X
  712. X    /*Strip icon geometry*/
  713. X    command_line = strip_arg(command_line,"-iconGeom");
  714. X
  715. X    return(command_line);
  716. X}
  717. X
  718. X/*This will strip out the geometry arguments for an xterm window.
  719. X
  720. X  Inputs:  command_line - command line arguments
  721. X  Outputs: command_line - command line arguments without geometry info
  722. X  Locals:  none
  723. X  Globals: none
  724. X*/
  725. Xchar *strip_xterm_geometry(command_line)
  726. Xregister char *command_line;
  727. X{
  728. X    char *strip_arg();
  729. X
  730. X    /*Strip window geometry*/
  731. X    command_line = strip_arg(command_line,"-g");
  732. X
  733. X    /*Strip icon geometry*/
  734. X    command_line = strip_arg(command_line,"#");
  735. X
  736. X    return(command_line); 
  737. X}
  738. X
  739. X/*This function will strip an argument from a string.
  740. X
  741. X  Inputs:  arg              - argument to strip
  742. X       command_line     - command line arguments
  743. X  Outputs: new_command_line - command line without 'arg'
  744. X  Locals:  new_command_line - command line without 'arg'
  745. X       numbytes        - number of bytes to copy from old command line
  746. X       pointer1        - pointer to start of 'arg'
  747. X       pointer2        - pointer to any arguments after 'arg'
  748. X  Globals: program        - name of currently executing program
  749. X       NULL            - 0
  750. X*/
  751. Xchar *strip_arg(command_line,arg)
  752. Xregister char *command_line,*arg;
  753. X{
  754. X    register int numbytes;
  755. X    register char *pointer1,*pointer2,*new_command_line;
  756. X    char *malloc(),*strstr();
  757. X
  758. X    /*If the argument to strip isn't here, then just return the original
  759. X      string*/
  760. X    if((pointer1 = strstr(command_line,arg)) == NULL)
  761. X      return(command_line);
  762. X    else {
  763. X           /*Find next character after argument*/
  764. X           pointer2 = pointer1 + strlen(arg);
  765. X           pointer2 = index(pointer2+1,' ');
  766. X
  767. X           /*Find out how much space to allocate for command line minus
  768. X         the argument to strip*/
  769. X           /*Null out byte before argument to be able to use strlen()*/
  770. X           *pointer1 = '\0';
  771. X           numbytes = strlen(command_line);
  772. X           /*Count bytes after argument (if there are any) plus 1 for NULL*/
  773. X           /*Have to use pointer2+1 instead of doing ++pointer2 so we
  774. X         can check if pointer2 = NULL (++pointer2 would have it = 1)*/
  775. X           if(pointer2) numbytes += strlen(pointer2+1)+1;
  776. X
  777. X           /*Allocate space and copy over all arguments except argument*/
  778. X           if((new_command_line = malloc(numbytes)) == NULL) {
  779. X         perror(program);
  780. X         exit(1);
  781. X           }
  782. X           strcpy(new_command_line,command_line);
  783. X           if(pointer2) strcat(new_command_line,pointer2+1);
  784. X
  785. X           /*Restore command_line to it's original condition so we can
  786. X         free up all the space it's using*/
  787. X           *pointer1 = '-';
  788. X           free(command_line);
  789. X         }
  790. X
  791. X    return(new_command_line);
  792. X}
  793. X
  794. END_OF_FILE
  795.   if test 7840 -ne `wc -c <'get_geometry.c'`; then
  796.     echo shar: \"'get_geometry.c'\" unpacked with wrong size!
  797.   fi
  798.   # end of 'get_geometry.c'
  799. fi
  800. if test -f 'getgeom.c' -a "${1}" != "-c" ; then 
  801.   echo shar: Will not clobber existing file \"'getgeom.c'\"
  802. else
  803.   echo shar: Extracting \"'getgeom.c'\" \(9362 characters\)
  804.   sed "s/^X//" >'getgeom.c' <<'END_OF_FILE'
  805. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  806. X
  807. X  Permission to use,  copy,  modify  and  distribute  without
  808. X  charge this software, documentation, images, etc. is grant-
  809. X  ed, provided that this copyright and the author's  name  is
  810. X  retained.
  811. X
  812. X  A fee may be charged for this program ONLY to recover costs
  813. X  for distribution (i.e. media costs).  No profit can be made
  814. X  on this program.
  815. X
  816. X  The author assumes no responsibility for disasters (natural
  817. X  or otherwise) as a consequence of use of this software.
  818. X
  819. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  820. X*/
  821. X
  822. X#include <stdio.h>
  823. X#include <X11/Xos.h>
  824. X#include <X11/Xlib.h>
  825. X#include <X11/Xutil.h>
  826. X
  827. Xchar *strip_arg2(),*malloc(),*index();
  828. Xextern char *program;
  829. Xextern Display *display;
  830. X
  831. X/*This function will get the window and icon geometry and add them to the
  832. X  command line.  For window geometry, it will add position and size.  For
  833. X  icon geometry, it will only add position.
  834. X
  835. X  Inputs:  command_line  - command line arguments
  836. X       window        - ID of the window that we are going to check
  837. X  Outputs: command_line  - command line arguments with geometry info added
  838. X  Locals:  dummy     - dummary variable for return value we don't want
  839. X       dummywin     - dummary variable for return value we don't want
  840. X       geometry_args - geometry arguments to add to command line
  841. X       height     - height of window (in pixels)
  842. X       height_inc     - height increment
  843. X       hints     - window size hints
  844. X       icon_arg      - icon geometry argument
  845. X       icon_hints    - icon position hints
  846. X       icon_x     - X coordinate of icon
  847. X       icon_y     - Y coordinate of icon
  848. X       ptr           - pointer to characters within a string
  849. X       rearrange     - rearrange args so geometry is first
  850. X       root         - root window of this window
  851. X       status        - status of get call
  852. X       supplied      - flag telling which size hints are available
  853. X       tx         - translated X coordinate
  854. X       ty         - translated Y coordinate
  855. X       width     - width of window (in pixels)
  856. X       width_inc     - width increment
  857. X       x         - X coordinate of window
  858. X       y         - Y coordinate of window
  859. X  Globals: display       - interface info to X display
  860. X       program     - name of currently executing program
  861. X       NULL         - 0
  862. X       PResizeInc    - flag bit to check if resize increment hint is avail.
  863. X*/
  864. Xchar *getgeom(window,command_line)
  865. Xregister char *command_line;
  866. Xregister Window window;
  867. X{
  868. X    register int width_inc,height_inc;
  869. X    int x,y,tx,ty,icon_x,icon_y;
  870. X    unsigned int width,height,dummy;
  871. X    long supplied;
  872. X    register char *icon_arg,*geom_arg,geometry_args[100],*rearrange,*ptr;
  873. X    register Status status;
  874. X    Window root,dummywin;
  875. X    XSizeHints hints;
  876. X    register XWMHints *icon_hints;
  877. X    char *strip_geometry(),*strip_xterm_geometry(),*strip_emacs_geometry();
  878. X    char *strdup();
  879. X
  880. X    /*Get icon position*/
  881. X    icon_x = icon_y = -1;
  882. X    icon_hints = XGetWMHints(display,window);
  883. X    if(icon_hints) {
  884. X      icon_x = icon_hints->icon_x;
  885. X      icon_y = icon_hints->icon_y;
  886. X      XFree(icon_hints);
  887. X    }
  888. X
  889. X    /*Get window geometry*/
  890. X    status = XGetGeometry(display,window,&root,&x,&y,&width,&height,&dummy,
  891. X                  &dummy);
  892. X
  893. X    if(status) {
  894. X      width_inc = 1;
  895. X      height_inc = 1;
  896. X      geom_arg = "-geom";
  897. X      icon_arg = "-iconGeom ";
  898. X
  899. X      /*Translate coordinate relative to root window*/
  900. X      XTranslateCoordinates(display,window,root,0,0,&tx,&ty,&dummywin);
  901. X
  902. X      /*Xterm is a special case (isn't it always?).  Unlike other programs,
  903. X        xterm takes it's dimensions in characters, not pixels.  This
  904. X        means we have to get it's increment size (i.e. font size) and
  905. X        divide the size of the window (in pixels) by it's font size to
  906. X        determine it's character size.  In addition, the argument to
  907. X        specify icon position is different from normal*/
  908. X      if(is_xterm(window) == 1) {
  909. X        /*Get increment (i.e. font size)*/
  910. X        status = XGetWMNormalHints(display,window,&hints,&supplied);
  911. X        if(!status || !(supplied & PResizeInc)) return(command_line);
  912. X
  913. X        width_inc = hints.width_inc;
  914. X        height_inc = hints.height_inc;
  915. X        icon_arg = "#";
  916. X
  917. X        XFree(hints);
  918. X
  919. X        /*Strip old geometry arguments out of command line (if the
  920. X          command line has any geometry arguments)*/
  921. X        command_line = strip_xterm_geometry(command_line);
  922. X      } else if(is_emacs(window) == 1) {
  923. X           /*Get increment (i.e. font size), like xterm, emacs also
  924. X             takes size in characters, not pixels*/
  925. X           status = XGetWMNormalHints(display,window,&hints,&supplied);
  926. X           if(!status || !(supplied & PResizeInc)) return(command_line);
  927. X
  928. X           width_inc = hints.width_inc;
  929. X           height_inc = hints.height_inc;
  930. X           icon_x = -1;                /*No icon arg*/
  931. X           geom_arg = "-w";            /*Figures...*/
  932. X
  933. X           XFree(hints);
  934. X
  935. X           /*Strip old geometry arguments out of command line (if the
  936. X             command line has any geometry arguments)*/
  937. X           command_line = strip_emacs_geometry(command_line);
  938. X         } else command_line = strip_geometry(command_line);
  939. X
  940. X      /*Calctool is special in that it thinks it has icon geometry, and
  941. X        it doesn't.  Also, it doesn't set the increment right.*/
  942. X      if(is_calctool(window) == 1) {
  943. X        icon_x = -1;
  944. X        width_inc = height_inc = 1;
  945. X      }
  946. X
  947. X      /*Put geometry information together in a string.  Put in icon
  948. X        information is there was icon information*/
  949. X      if(icon_x == -1)
  950. X        sprintf(geometry_args," %s %dx%d+%d+%d",geom_arg,width/width_inc,height/height_inc,tx-x,ty-y);
  951. X      else
  952. X        sprintf(geometry_args," %s %dx%d+%d+%d %s+%d+%d",geom_arg,width/width_inc,height/height_inc,tx-x,ty-y,icon_arg,icon_x,icon_y);
  953. X
  954. X      /*Add window and icon geometry as first arguments*/
  955. X      if((rearrange = malloc(command_line,strlen(command_line) +
  956. X                 strlen(geometry_args) + 1)) == NULL) {
  957. X        perror(program);
  958. X        exit(1);
  959. X      }
  960. X      if(ptr = index(command_line,' ')) {
  961. X        *ptr = '\0';
  962. X        sprintf(rearrange,"%s%s %s",command_line,geometry_args,ptr + 1);
  963. X        *ptr = ' ';
  964. X      } else sprintf(rearrange,"%s%s",command_line,geometry_args);
  965. X    }
  966. X
  967. X    free(command_line);
  968. X
  969. X    return(rearrange);
  970. X}
  971. X
  972. X/*This will strip out the geometry arguments for a normal X application.
  973. X
  974. X  Inputs:  command_line - command line arguments
  975. X  Outputs: command_line - command line arguments without geometry info
  976. X  Locals:  none
  977. X  Globals: none
  978. X*/
  979. Xchar *strip_geometry(command_line)
  980. Xregister char *command_line;
  981. X{
  982. X    /*Strip window geometry*/
  983. X    command_line = strip_arg2(command_line,"-g");
  984. X
  985. X    /*Strip icon geometry*/
  986. X    command_line = strip_arg2(command_line,"-iconGeom");
  987. X
  988. X    return(command_line);
  989. X}
  990. X
  991. X/*This will strip out the geometry arguments for an xterm window.
  992. X
  993. X  Inputs:  command_line - command line arguments
  994. X  Outputs: command_line - command line arguments without geometry info
  995. X  Locals:  none
  996. X  Globals: none
  997. X*/
  998. Xchar *strip_xterm_geometry(command_line)
  999. Xregister char *command_line;
  1000. X{
  1001. X    /*Strip window geometry*/
  1002. X    command_line = strip_arg2(command_line,"-g");
  1003. X
  1004. X    /*Strip icon geometry*/
  1005. X    command_line = strip_arg2(command_line,"#");
  1006. X
  1007. X    return(command_line); 
  1008. X}
  1009. X
  1010. X/*This will strip out the geometry arguments for an emacs window.
  1011. X
  1012. X  Inputs:  command_line - command line arguments
  1013. X  Outputs: command_line - command line arguments without geometry info
  1014. X  Locals:  none
  1015. X  Globals: none
  1016. X*/
  1017. Xchar *strip_emacs_geometry(command_line)
  1018. Xregister char *command_line;
  1019. X{
  1020. X    /*Strip window geometry*/
  1021. X    command_line = strip_arg2(command_line,"-geometry");
  1022. X    command_line = strip_arg2(command_line,"-w");
  1023. X
  1024. X    return(command_line); 
  1025. X}
  1026. X
  1027. X/*This function will strip two arguments from a string.
  1028. X
  1029. X  Inputs:  arg              - argument to start stripping at
  1030. X       command_line     - command line arguments
  1031. X  Outputs: new_command_line - command line without 'arg' & following arg
  1032. X  Locals:  new_command_line - command line without 'arg' & following arg
  1033. X       numbytes        - number of bytes to copy from old command line
  1034. X       pointer1        - pointer to start of 'arg'
  1035. X       pointer2        - pointer to any arguments after 2nd arg
  1036. X  Globals: program        - name of currently executing program
  1037. X       NULL            - 0
  1038. X*/
  1039. Xchar *strip_arg2(command_line,arg)
  1040. Xregister char *command_line,*arg;
  1041. X{
  1042. X    register int numbytes;
  1043. X    register char *pointer1,*pointer2,*new_command_line;
  1044. X    char *strstr();
  1045. X
  1046. X    /*If the argument to strip isn't here, then just return the original
  1047. X      string*/
  1048. X    if((pointer1 = strstr(command_line,arg)) == NULL)
  1049. X      return(command_line);
  1050. X    else {
  1051. X           /*Find next character after argument*/
  1052. X           pointer2 = pointer1 + strlen(arg);
  1053. X           pointer2 = index(pointer2+1,' ');    /*After 'arg'*/
  1054. X           if(pointer2)
  1055. X             pointer2 = index(pointer2+1,' ');    /*After 2nd arg*/
  1056. X
  1057. X           /*Find out how much space to allocate for command line minus
  1058. X         the argument to strip*/
  1059. X           /*Null out byte before argument to be able to use strlen()*/
  1060. X           *pointer1 = '\0';
  1061. X           numbytes = strlen(command_line);
  1062. X           /*Count bytes after argument (if there are any) plus 1 for NULL*/
  1063. X           /*Have to use pointer2+1 instead of doing ++pointer2 so we
  1064. X         can check if pointer2 = NULL (++pointer2 would have it = 1)*/
  1065. X           if(pointer2) numbytes += strlen(pointer2+1)+1;
  1066. X
  1067. X           /*Allocate space and copy over all arguments except argument*/
  1068. X           if((new_command_line = malloc(numbytes + 1)) == NULL) {
  1069. X         perror(program);
  1070. X         exit(1);
  1071. X           }
  1072. X           strcpy(new_command_line,command_line);
  1073. X           if(pointer2) strcat(new_command_line,pointer2+1);
  1074. X
  1075. X           /*Restore command_line to it's original condition so we can
  1076. X         free up all the space it's using*/
  1077. X           *pointer1 = '-';
  1078. X           free(command_line);
  1079. X         }
  1080. X
  1081. X    return(new_command_line);
  1082. X}
  1083. X
  1084. END_OF_FILE
  1085.   if test 9362 -ne `wc -c <'getgeom.c'`; then
  1086.     echo shar: \"'getgeom.c'\" unpacked with wrong size!
  1087.   fi
  1088.   # end of 'getgeom.c'
  1089. fi
  1090. if test -f 'make_list.c' -a "${1}" != "-c" ; then 
  1091.   echo shar: Will not clobber existing file \"'make_list.c'\"
  1092. else
  1093.   echo shar: Extracting \"'make_list.c'\" \(2593 characters\)
  1094.   sed "s/^X//" >'make_list.c' <<'END_OF_FILE'
  1095. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  1096. X
  1097. X  Permission to use,  copy,  modify  and  distribute  without
  1098. X  charge this software, documentation, images, etc. is grant-
  1099. X  ed, provided that this copyright and the author's  name  is
  1100. X  retained.
  1101. X
  1102. X  A fee may be charged for this program ONLY to recover costs
  1103. X  for distribution (i.e. media costs).  No profit can be made
  1104. X  on this program.
  1105. X
  1106. X  The author assumes no responsibility for disasters (natural
  1107. X  or otherwise) as a consequence of use of this software.
  1108. X
  1109. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  1110. X*/
  1111. X
  1112. X#include <stdio.h>
  1113. X#include <X11/Xos.h>
  1114. X
  1115. Xextern char *list,*program;
  1116. X
  1117. X/*This function will put together a list of screens to save information from.
  1118. X
  1119. X  Inputs:  default_screen - default screen to use if no option list given
  1120. X       total_screens  - total number of screens this server knows about
  1121. X  Outputs: screens      - list of screen numbers to save from
  1122. X  Locals:  loop          - loop through list array
  1123. X       numscreens     - number of screens in list
  1124. X       pointer      - loop through option list
  1125. X       screens      - array of screen numbers
  1126. X  Globals: list          - option list of screens to save from
  1127. X       program      - name of currently executing program
  1128. X       NULL          - 0
  1129. X*/
  1130. Xint *make_list(default_screen,total_screens)
  1131. Xregister int default_screen,total_screens;
  1132. X{
  1133. X    register int *screens,numscreens,loop;
  1134. X    register char *pointer;
  1135. X    char *calloc();
  1136. X
  1137. X    /*Found out how big an array we need - how many screens to save
  1138. X      from*/
  1139. X    if(!list) numscreens = 2;
  1140. X    else if(strcmp(list,"all")) numscreens = count_spaces(list)+2;
  1141. X         else numscreens = total_screens + 1;
  1142. X
  1143. X    if((screens = (int *) calloc(numscreens,sizeof(int *))) == NULL) {
  1144. X      perror(program);
  1145. X      exit(1);
  1146. X    }
  1147. X
  1148. X    /*Set up array list*/
  1149. X    if(!list) {
  1150. X      screens[0] = default_screen;
  1151. X      screens[1] = -1;
  1152. X    } else if(strcmp(list,"all")) {
  1153. X         loop = 0;
  1154. X             for(pointer = list;pointer;pointer = index(pointer+1,' '))
  1155. X               sscanf(pointer,"%d",&screens[loop++]);
  1156. X         screens[loop] = -1;
  1157. X           } else {
  1158. X            for(loop = 0;loop < total_screens;++loop)
  1159. X                      screens[loop] = loop;
  1160. X            screens[loop] = -1;
  1161. X              }
  1162. X
  1163. X    return(screens);
  1164. X}
  1165. X
  1166. X/*Count the number of spaces in a string.
  1167. X
  1168. X  Inputs:  string    - string to count spaces in
  1169. X  Outputs: numspaces - number of spaces in a string
  1170. X  Locals:  numspaces - number of spaces in a string
  1171. X       pointer   - pointer to spaces in string
  1172. X  Globals: none
  1173. X*/
  1174. Xcount_spaces(string)
  1175. Xregister char *string;
  1176. X{
  1177. X    register int numspaces = 0;
  1178. X    register char *pointer = string;
  1179. X
  1180. X    while(pointer = index(pointer+1,' ')) ++numspaces;
  1181. X
  1182. X    return(numspaces);
  1183. X}
  1184. X
  1185. END_OF_FILE
  1186.   if test 2593 -ne `wc -c <'make_list.c'`; then
  1187.     echo shar: \"'make_list.c'\" unpacked with wrong size!
  1188.   fi
  1189.   # end of 'make_list.c'
  1190. fi
  1191. if test -f 'xtoolplaces.c' -a "${1}" != "-c" ; then 
  1192.   echo shar: Will not clobber existing file \"'xtoolplaces.c'\"
  1193. else
  1194.   echo shar: Extracting \"'xtoolplaces.c'\" \(2630 characters\)
  1195.   sed "s/^X//" >'xtoolplaces.c' <<'END_OF_FILE'
  1196. X/*Copyright (c) 1993 Xerox Corporation.  All Rights Reserved.
  1197. X
  1198. X  Permission to use,  copy,  modify  and  distribute  without
  1199. X  charge this software, documentation, images, etc. is grant-
  1200. X  ed, provided that this copyright and the author's  name  is
  1201. X  retained.
  1202. X
  1203. X  A fee may be charged for this program ONLY to recover costs
  1204. X  for distribution (i.e. media costs).  No profit can be made
  1205. X  on this program.
  1206. X
  1207. X  The author assumes no responsibility for disasters (natural
  1208. X  or otherwise) as a consequence of use of this software.
  1209. X
  1210. X  Adam Stein (adam@iset.scan.mc.xerox.com)
  1211. X*/
  1212. X
  1213. X#include <stdio.h>
  1214. X#include <X11/Xos.h>
  1215. X
  1216. Xint console_checking;            /*Console checking flag*/
  1217. Xchar *addon;                /*File containing stuff to add*/
  1218. Xchar *list;                /*List of screens to save*/
  1219. Xchar *missing;                /*File containing apps to save*/
  1220. Xchar *remote;                /*Command to use for remote apps*/
  1221. Xchar *program;                /*Program name*/
  1222. XFILE *fp;                /*File pointer to write to*/
  1223. X
  1224. X/*This program will write the current state of every window on an X desktop to
  1225. X  a file (or stdout).  It is the X equivalent to Sunview's toolplaces program.
  1226. X
  1227. X
  1228. X  Inputs:  argc    - number of command line arguments
  1229. X       argv    - command line arguments
  1230. X  Outputs: 0
  1231. X  Locals:  none
  1232. X  Globals: addon   - name of file containing commands to add on
  1233. X       fp      - file pointer to write window information to
  1234. X       missing - name of file containing X applications
  1235. X       program - name of currently executing program
  1236. X       stdout  - standard output
  1237. X*/
  1238. Xmain(argc,argv)
  1239. Xregister int argc;
  1240. Xregister char *argv[];
  1241. X{
  1242. X    program = argv[0];
  1243. X
  1244. X    /*Get and parse arguments and resources*/
  1245. X    getargs(argc,argv);
  1246. X
  1247. X        /*If -a option given, read in addon file*/
  1248. X        if(addon) read_addon();
  1249. X        /*If -m option given, read in missing apps file*/
  1250. X        if(missing) read_missing();
  1251. X    /*Get application information*/
  1252. X    getinfo();
  1253. X
  1254. X    /*If we were writing to a file (as opposed to stdout), close the file*/
  1255. X    if(fp != stdout) fclose(fp);
  1256. X
  1257. X    exit(0);
  1258. X}
  1259. X
  1260. X/*This function will write out the header for a Bourne shell script.  It will
  1261. X  also write out the current date and time.
  1262. X
  1263. X  Inputs:  none
  1264. X  Outputs: none
  1265. X  Locals:  date - current date and time
  1266. X           tp   - date & time info structure
  1267. X  Globals: fp   - file pointer to write window information to
  1268. X           NULL - 0
  1269. X*/
  1270. Xwrite_header()
  1271. X{
  1272. X        register char *date;
  1273. X        struct timeval tp;
  1274. X
  1275. X        /*Get current date & time*/
  1276. X        gettimeofday(&tp,NULL);
  1277. X        date = asctime(localtime(&tp.tv_sec));
  1278. X
  1279. X        fputs("#!/bin/sh\n",fp);
  1280. X        fputs("#\n",fp);
  1281. X        fprintf(fp,"# Created by 'xtoolplaces' on %s",date);
  1282. X        fputs("#\n\n",fp);
  1283. X}
  1284. X
  1285. END_OF_FILE
  1286.   if test 2630 -ne `wc -c <'xtoolplaces.c'`; then
  1287.     echo shar: \"'xtoolplaces.c'\" unpacked with wrong size!
  1288.   fi
  1289.   # end of 'xtoolplaces.c'
  1290. fi
  1291. if test -f 'xtoolplaces.man' -a "${1}" != "-c" ; then 
  1292.   echo shar: Will not clobber existing file \"'xtoolplaces.man'\"
  1293. else
  1294.   echo shar: Extracting \"'xtoolplaces.man'\" \(11365 characters\)
  1295.   sed "s/^X//" >'xtoolplaces.man' <<'END_OF_FILE'
  1296. X.ll 6.5i
  1297. X.TH XTOOLPLACES 1 "13-Feb-93"
  1298. X.SH NAME
  1299. Xxtoolplaces - save current X desktop window information
  1300. X.SH SYNOPSIS
  1301. Xxtoolplaces [-a filename] [-c] [-display host:display.screen] [-f filename] [-m filename] [-r command] [-s {list | all}] [-v]
  1302. X.SH DESCRIPTION
  1303. XXtoolplaces collects current state information for all windows running on
  1304. Xan X display at the time of execution.  This information can then be saved
  1305. Xand used to restart the X display.  Applications started remotely are saved
  1306. Xcorrectly.  Local applications lines are of the form:
  1307. X
  1308. X.in +5
  1309. XWM_COMMAND
  1310. X.in -5
  1311. X
  1312. Xwhile remote application lines are of the form:
  1313. X
  1314. X.in +5
  1315. Xrsh -n <machine> WM_COMMAND
  1316. X.in -5
  1317. X
  1318. XWM_COMMAND is the command line to use to re-create the application as it
  1319. Xcurrently exists and <machine> is the remote application's host.  The '-r'
  1320. Xoption can be used to change the command used to start remote applications
  1321. X(i.e. rcmd or xon).  If an application doesn't update WM_COMMAND, the geometry
  1322. Xinformation will be gotten manually.  Use the '-m' option to save those
  1323. Xapplications that don't set WM_COMMAND (i.e. xman).
  1324. X
  1325. XXtoolplaces will lock the pointer, change the cursor to a watch, and beep
  1326. Xonce to announce that it's starting.  The pointer is locked so that the user
  1327. Xcan't change anything once xtoolplaces starts.  When the program is finished
  1328. Xit releases the pointer, changes the cursor back to the normal shape, and
  1329. Xbeeps twice.
  1330. X
  1331. XThe default filename to store the window information is ~/.xtoolplaces.  This
  1332. Xcan be overridden with the '-f' option (including writing to \f2stdout\f1).
  1333. X
  1334. XThis is the X equivalent of Sunview's toolplaces (but is not limited to
  1335. XSuns -- I hope).  Xtoolplaces was written entirely in Xlib to make it as
  1336. Xportable across X platforms as possible.  This tool was born out of the
  1337. Xneed to replace the functionality of toolplaces in X.  The Open Look window
  1338. Xmanager (olwm) could only save the window information into one place.  In
  1339. Xaddition, it could only save applications that correctly saved their startup
  1340. Xstate in WM_COMMAND.  Since I needed different initialization files depending
  1341. Xon what machine I was on and I used applications that weren't "well-behaved",
  1342. Xthis became a little limited.  Therefore, xtoolplaces was made.
  1343. X.SH OPTIONS
  1344. XDescriptions of the '-a', '-c', '-m', and '-s' options are listed in greater
  1345. Xdetail in following sections.  A description of resources is listed in
  1346. Xthe section entitled RESOURCES.
  1347. X
  1348. X.IP "-a filename"
  1349. XRead in a file ('filename') containing arguments to add on to the end of
  1350. Xcommand lines.  See ADDING ARGUMENTS below for more detail.
  1351. X.IP -c
  1352. XPut special 'if ... fi' statement around any console windows found.  See
  1353. XCONSOLE CHECKING below for more detail.
  1354. X.IP "-d host:display.screen"
  1355. XSave window information from an alternate display.
  1356. X.IP "-f filename"
  1357. XWrite window information to 'filename'.  Default is '~/.xtoolplaces'.
  1358. XWindow information can be written to \f2stdout\f1 by specifying '-' as the
  1359. Xfilename.
  1360. X.IP "-m filename"
  1361. XRead in a file ('filename') containing a list of X applications that don't set
  1362. XWM_COMMAND and need to be saved.  Normally, X windows that don't have
  1363. XWM_COMMAND set aren't saved.  See MISSING APPLICATIONS below for more
  1364. Xdetail.
  1365. X.IP "-r command"
  1366. XCommand to use to start remote applications.  Default is 'rsh -n'.  The '-n'
  1367. Xoption of rsh is used to redirect input to /dev/null.  See the rsh man page
  1368. Xfor more information on '-n'.
  1369. X.IP "-s {list | all}"
  1370. XSpecify what screens to save information from.  Either a list of screen
  1371. Xnumbers can be given or the keyword 'all' which specifies to do all the screens
  1372. Xthat a server knows about.  See SCREEN LISTS below for more detail.
  1373. X.IP -v
  1374. XPrint the current version number and patchlevel and quit.  No processing is
  1375. Xdone.
  1376. X.SH ADDING ARGUMENTS (-a)
  1377. XThe '-a' option was added because of a possible xview problem.  For some
  1378. Xreason, some windows don't fill in the WM_COMMAND string completely.  For
  1379. Xexample, xrolo is an xview program.  When it saves it's state in WM_COMMAND,
  1380. Xit never saves the filename it is using.  This option allows a user to
  1381. Xhave a file containing the name of the program and any arguments to be added
  1382. Xon to the end of the command line (gotten from WM_COMMAND).  If multiple
  1383. Xversions of the program are running, the extra arguments will go onto the end
  1384. Xof the command line for each of them.  If the same program is listed more
  1385. Xthan once in the file, only the first occurrence is used.
  1386. X
  1387. XAn addon file can consist of three different types of lines:
  1388. X
  1389. X.in +5
  1390. X.nf
  1391. Xcomment lines
  1392. Xblank lines
  1393. Xargument lines
  1394. X.fi
  1395. X.in -5
  1396. X
  1397. XComment lines are lines where the first character is a pound sign (#).
  1398. X
  1399. XBlank lines are lines where the first character is a newline.
  1400. X
  1401. XArgument lines are of the form:
  1402. X
  1403. X.in +5
  1404. Xname: argument(s)
  1405. X.in -5
  1406. X
  1407. Xwhere 'name' is the name of the program whose command line you want to
  1408. Xadd onto and 'argument(s)' are the arguments to add.  Everything from the
  1409. Xfirst non-whitespace after to colon to the newline is considered arguments to
  1410. Xadd.
  1411. X.SH CONSOLE CHECKING (-c)
  1412. XA console checking option was added out of a need to NOT start a console window
  1413. Xif running from an X terminal without having a special initialization file for
  1414. Xthe terminal.  This option will try to determine which windows (if any) are the
  1415. Xconsole windows and put an 'if' statement around them to start only if the
  1416. Xcurrent tty equals '/dev/console'.  This allows a user to have the same
  1417. Xinitialization file for starting X on the console of machine A and for an X
  1418. Xterminal running off of machine A.
  1419. X
  1420. XA console window if first checked by it's class.  While there is no default
  1421. Xclass for console windows, maybe this program will create one.  Xtoolplaces
  1422. Xchecks for a class of 'XConsole'.  If the class doesn't match, it checks to
  1423. Xsee if the window is one of the more common console programs.  As far as I
  1424. Xknow, only \f2xconsole\f1, by Roman J. Budzianowski, sets the class
  1425. Xto 'XConsole'.
  1426. X
  1427. XThe more common console programs this version currently searchs for are:
  1428. X\f2contool\f1, a console program to capture and display console output by
  1429. XChuck Musciano; Sun's \f2shelltool\f1 and \f2cmdtool\f1 in console mode; and
  1430. X\f2xterm\f1 in console mode, by Tom Weinstein and a whole bunch of other people.
  1431. X
  1432. XFor \f2contool\f1, it checks it's window name.  For \f2{shell,cmd}tool\f1, it
  1433. Xchecks the icon name.  For \f2xterm\f1, it checks the options that xterm was
  1434. Xstarted with.
  1435. X.SH MISSING APPLICATIONS (-m)
  1436. XThe '-m' option was added because some older X applications don't set
  1437. XWM_COMMAND.  Xtoolplaces uses the existance of WM_COMMAND to know what
  1438. Xwindows to save information from.  The missing applications (to save despite
  1439. Xnot having WM_COMMAND set) file is a list of applications, one per line.
  1440. XMissing applications files have the same three line types as addons (see
  1441. XADDING ARGUMENTS above) except that the argument lines consist of just the name
  1442. X(as gotten from WM_NAME) of the application to save.  For example, we know
  1443. Xthat the programs \f2xman\f1 and \f2xyz\f1 don't set WM_COMMAND but we wish
  1444. Xto save their states anyway.  The file specifed with '-m' would look like:
  1445. X
  1446. X.in +5
  1447. X.nf
  1448. Xxman
  1449. Xxyz
  1450. X.fi
  1451. X.in -5
  1452. X.SH SCREEN LISTS
  1453. XA list of screens is a list of numbers seperated by spaces and quoted (by
  1454. Xsingle or double quotes) to prevent the shell from parsing the list (i.e. to
  1455. Xsave screens 1 and 3 would be -s '1 3').  The default screen to save is the
  1456. Xone listed in either the environment variable \f2DISPLAY\f1 or with the '-d'
  1457. Xoption.  The screen specified by the '-d' option would override the one
  1458. Xin \f2DISPLAY\f1.
  1459. X
  1460. XWhen saving from multiple screens, each window saved has the '-display' option
  1461. Xadded to it if it doesn't already have it.  This is done in case a user starts
  1462. Xa window from one screen (so as not to need -display) and runs xtoolplaces
  1463. Xfrom another.  To insure that the window starts up on the right screen,
  1464. Xthe '-display' option is added.
  1465. X
  1466. XThree assumptions are made when adding the '-display' option:
  1467. X
  1468. X.in +5
  1469. X.nf
  1470. X1) if a colon (:) is found on the command line, it belongs
  1471. X   to HOST:SERVER.SCREEN and not to some other option
  1472. X2) if a window already has a '-display' option, it points
  1473. X   to the correct screen and nothing is changed or added
  1474. X3) every window that has '-display' added uses '-display'
  1475. X   (and not '-d' or something else)
  1476. X.fi
  1477. X.in -5
  1478. X.SH RESOURCES
  1479. XAll of the options available on the command line can be put into a resource
  1480. Xfile (and in fact most are in the default resource file,
  1481. X/usr/lib/X11/app-defaults/Xtoolplaces), with the exception of the version (-v)
  1482. Xflag.  The order in which resources are read in (with each layer overwriting
  1483. Xthe previous layers) are as follows:
  1484. X
  1485. X.nf
  1486. X        1) Hardcoded defaults
  1487. X        2) Values in /usr/lib/X11/app-defaults/Xtoolplaces
  1488. X        3) Values in $XUSERFILESEARCHPATH/Xtoolplaces or
  1489. X           $XAPPLRESDIR/Xtoolplaces
  1490. X        4) Values set using xrdb, either through the
  1491. X           XResourceMangerString macro or, if that's empty, the
  1492. X           .Xdefaults file in the user's home directory
  1493. X        5) Values in the file specified by the XENVIRONMENT
  1494. X           environment variable or, if that's not set, the
  1495. X           .Xdefaults-hostname file in the user's home directory
  1496. X           (where hostname is the name of the machine)
  1497. X        6) Command line arguments
  1498. X.fi
  1499. X
  1500. XDescriptions of each resource can be found in the OPTIONS section.  The
  1501. Xresource names are as follows:
  1502. X.IP xtoolplaces.addon
  1503. X-a option (i.e. xtoolplaces.addon: /adm/addon)
  1504. X.IP xtoolplaces.console
  1505. X-c option (i.e. xtoolplaces.console:)
  1506. X.IP xtoolplaces.display
  1507. X-d option (i.e. xtoolplaces.display: chroma:1)
  1508. X.IP xtoolplaces.saveto
  1509. X-f option (i.e. xtoolplaces.saveto: /home/abb/.startup)
  1510. X.IP xtoolplaces.missing
  1511. X-m option (i.e. xtoolplaces.missing: /adm/missing)
  1512. X.IP xtoolplaces.remote
  1513. X-r option (i.e. xtoolplaces.remote: rsh)
  1514. X.IP xtoolplaces.screens
  1515. X-s option (i.e. xtoolplaces.screens: 1 3 4)
  1516. X.SH FILES
  1517. X.IP "/usr/lib/X11/app-defaults/Xtoolplaces" 2i
  1518. Xdefault resource file
  1519. X.IP "$USERFILESEARCHPATH/Xtoolplaces" 2i
  1520. Xresource file
  1521. X.IP "$XAPPLRESDIR/Xtoolplaces" 2i
  1522. Xresource file
  1523. X.IP "~/.Xdefaults" 2i
  1524. Xuser's resource file
  1525. X.IP "$XENVIRONMENT" 2i
  1526. Xresource file
  1527. X.IP "~/.Xdefaults-hostname" 2i
  1528. Xresource file for a specific machine
  1529. X.IP "~/.xtoolplaces" 2i
  1530. Xdefault file to store window information
  1531. X.SH SEE ALSO
  1532. Xtoolplaces(1), xprop(1), xwininfo(1), xplaces(X)
  1533. X.SH BUGS
  1534. XXtoolplaces goes VERY out it's way to capture as many X applications as
  1535. Xpossible (including ill-behaved ones :-{).  The most up-to-date information
  1536. Xcomes from WM_COMMAND if the application understands WM_SAVE_YOURSELF.  Don't
  1537. Xblame me if all the information isn't there for ill-behaved applications, I
  1538. Xtried!
  1539. X
  1540. XIf the application doesn't put the icon position in WM_COMMAND or into
  1541. Xwindow manager hints, there is no way to save that information.
  1542. X
  1543. XFor windows in which the geometry has to be gotten manually, xtoolplaces
  1544. Xdoesn't put on the command line whether to start iconic or not (even if the
  1545. Xapplication is iconic at the time).  This is because different applications
  1546. Xtake different arguments to start iconic (if they CAN be started iconic).
  1547. X
  1548. XThis program WILL NOT work with mwm (Motif Window Manager) and tvtwm (the
  1549. Xvirtual version of twm).  It seems to work with all the others (olwm, olvwm,
  1550. Xtwm) from what I've been told (I only use olvwm myself).
  1551. X.SH AUTHOR
  1552. X.nf
  1553. XAdam Stein
  1554. X800 Phillips Road, 129-71B
  1555. XWebster, New York  14580
  1556. X.ta 10
  1557. XInternet:    adam@iset.scan.mc.xerox.com
  1558. X.br
  1559. X    stein.wbst129@xerox.com
  1560. END_OF_FILE
  1561.   if test 11365 -ne `wc -c <'xtoolplaces.man'`; then
  1562.     echo shar: \"'xtoolplaces.man'\" unpacked with wrong size!
  1563.   fi
  1564.   # end of 'xtoolplaces.man'
  1565. fi
  1566. echo shar: End of archive 2 \(of 3\).
  1567. cp /dev/null ark2isdone
  1568. MISSING=""
  1569. for I in 1 2 3 ; do
  1570.     if test ! -f ark${I}isdone ; then
  1571.     MISSING="${MISSING} ${I}"
  1572.     fi
  1573. done
  1574. if test "${MISSING}" = "" ; then
  1575.     echo You have unpacked all 3 archives.
  1576.     rm -f ark[1-9]isdone
  1577. else
  1578.     echo You still must unpack the following archives:
  1579.     echo "        " ${MISSING}
  1580. fi
  1581. exit 0
  1582. exit 0 # Just in case...
  1583. -- 
  1584.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  1585. \X/  Amiga - The only way to fly!      |
  1586.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  1587.   casual observer..."                  |
  1588.