home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!zaphod.mps.ohio-state.edu!usc!apple!sun-barr!cronkite.Central.Sun.COM!newstop!exodus!wrc.xerox.com
- From: stein@wrc.xerox.com (adam stein)
- Newsgroups: comp.sources.x
- Subject: v14i003: xtoolplaces, Part02/02
- Message-ID: <19068@exodus.Eng.Sun.COM>
- Date: 27 Aug 91 04:58:13 GMT
- References: <csx-14i002-xtoolplaces@uunet.UU.NET>
- Sender: news@exodus.Eng.Sun.COM
- Lines: 421
- Approved: argv@sun.com
-
- Submitted-by: stein@wrc.xerox.com (adam stein)
- Posting-number: Volume 14, Issue 3
- Archive-name: xtoolplaces/part02
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # This is part 02 of a multipart archive
- # ============= xtoolplaces.c ==============
- if test -f 'xtoolplaces.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xtoolplaces.c (File already exists)'
- else
- echo 'x - extracting xtoolplaces.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtoolplaces.c' &&
- /*Copyright (c) 1991 Xerox Corporation. All Rights Reserved.
- X
- X Permission to use, copy, modify and distribute without
- X charge this software, documentation, images, etc. is grant-
- X ed, provided that this copyright and the author's name is
- X retained.
- X
- X A fee may be charged for this program ONLY to recover costs
- X for distribution (i.e. media costs). No profit can be made
- X on this program.
- X
- X The author assumes no responsibility for disasters (natural
- X or otherwise) as a consequence of use of this software.
- X
- X Adam Stein (stein.wbst129@xerox.com)
- */
- X
- #include <stdio.h>
- #include <malloc.h>
- #include <X11/Xos.h>
- #include "xtoolplaces.h"
- #include "patchlevel.h"
- X
- int console_checking; /*Console checking flag*/
- char *addon; /*File containing stuff to add*/
- char *list; /*List of screens to save*/
- char *missing; /*File containing apps to save*/
- char *remote; /*Command to use for remote apps*/
- char *use_display; /*Display to use*/
- char *program; /*Program name*/
- FILE *fp; /*File pointer to write to*/
- X
- /*This program will write the current state of every window on an X desktop to
- X a file (or stdout). It is the X equivalent to Sunview's toolplaces program.
- X
- X
- X Inputs: argc - number of command line arguments
- X argv - command line arguments
- X Outputs: 0
- X Locals: none
- X Globals: fp - file pointer to write window information to
- X program - name of currently executing program
- X stdout - standard output
- */
- main(argc,argv)
- register int argc;
- register char *argv[];
- {
- X program = argv[0];
- X
- X getargs(argc,argv);
- X
- X getinfo();
- X
- X if(fp != stdout) fclose(fp);
- X
- X exit(0);
- }
- X
- /*This function will parse the command line arguments and act on them.
- X
- X Inputs: argc - number of command line arguments
- X argv - command line arguments
- X Outputs: none
- X Locals: home - home directory
- X filename - name of file to write window information to
- X loop - loop through arguments
- X pointer - point to option letter
- X Globals: addon - file containing commands to add on to end of
- X window command arguments
- X console_checking - flag indicating to put special 'if ... fi'
- X statements around console windows
- X filename - name of file to write window info to
- X fp - file pointer to write window information to
- X list - list of screens to save
- X missing - file containing apps that don't set WM_COMMAND
- X program - name of currently executing program
- X remote - command to use for remote applications
- X stderr - standard error
- X stdout - standard output
- X use_display - display to use
- X DEFAULT_FILENAME - default filename to write window info to
- X DEFAULT_REMOTE - default remote command to use
- X HOME - home environment variable
- X NULL - 0
- X PATCHLEVEL - current program patchlevel
- X USAGE - usage line
- X VERSION - current program version
- */
- getargs(argc,argv)
- register int argc;
- register char *argv[];
- {
- X register int loop;
- X register char *pointer,*home,*filename;
- X char *getenv(),*strdup();
- X
- X /*Set defaults*/
- X console_checking = 0;
- X addon = filename = list = missing = use_display = NULL;
- X remote = DEFAULT_REMOTE;
- X
- X /*Loop through and parse arguments*/
- X for(loop = 1;loop < argc;++loop) {
- X pointer = &argv[loop][1];
- X
- X switch(*pointer) {
- X case 'a': /*File containing options to addon*/
- X if(++loop == argc) {
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X } else if((addon = strdup(argv[loop])) == NULL) {
- X perror(program);
- X exit(1);
- X }
- X
- X break;
- X case 'c': /*Check for console window*/
- X console_checking = 1;
- X
- X break;
- X case 'd': /*Use another display*/
- X if(!strcmp(pointer,"display"))
- X if(++loop == argc) {
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X } else
- X if((use_display = strdup(argv[loop])) == NULL) {
- X perror(program);
- X exit(1);
- X }
- X
- X break;
- X case 'f': /*Filename to write to*/
- X if(++loop == argc) {
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X } else if((filename = strdup(argv[loop])) == NULL) {
- X perror(program);
- X exit(1);
- X }
- X
- X break;
- X case 'm': /*File containing apps w/out WM_COMMAND*/
- X if(++loop == argc) {
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X } else if((missing = strdup(argv[loop])) == NULL) {
- X perror(program);
- X exit(1);
- X }
- X
- X break;
- X case 'r': /*Command to start remote applications*/
- X if(++loop == argc) {
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X } else if((remote = strdup(argv[loop])) == NULL) {
- X perror(program);
- X exit(1);
- X }
- X break;
- X case 's': /*List of screens to save*/
- X if(++loop == argc) {
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X } else if((list = strdup(argv[loop])) == NULL) {
- X perror(program);
- X exit(1);
- X }
- X break;
- X case 'v': /*Print version*/
- X fprintf(stderr,"%s: version %s, patchlevel %d\n",
- X program,VERSION,PATCHLEVEL);
- X exit(0);
- X default:
- X fprintf(stderr,"usage: %s %s\n",program,USAGE);
- X exit(1);
- X }
- X }
- X
- X /*If filename isn't given, use default ~/.xtoolplaces
- X else if filename matches -, write to stdout, else
- X open the filename given for writing*/
- X if(!filename) {
- X /*Get home directory for default filename*/
- X if((home = getenv(HOME)) == NULL) {
- X fprintf(stderr,"%s: can't find %s in environment, no default for filename\n",program,HOME);
- X exit(1);
- X }
- X
- X if((filename = malloc(strlen(home)+strlen(DEFAULT_FILENAME)+2))
- X == NULL) {
- X perror(program);
- X exit(1);
- X }
- X
- X strcpy(filename,home);
- X strcat(filename,"/");
- X strcat(filename,DEFAULT_FILENAME);
- X }
- X
- X if(strcmp(filename,"-")) {
- X if((fp = fopen(filename,"w")) == NULL) {
- X fprintf(stderr,"%s: can't open {%s} for writing\n",program,filename);
- X exit(1);
- X }
- X } else fp = stdout;
- X
- X /*If -a option given, read in addon file*/
- X if(addon) read_addon();
- X
- X /*If -m option given, read in missing apps file*/
- X if(missing) read_missing();
- X
- X write_header();
- }
- X
- /*This function will write out the header for a Bourne shell script. It will
- X also write out the current date and time.
- X
- X Inputs: none
- X Outputs: none
- X Locals: date - current date and time
- X tp - date & time info structure
- X Globals: fp - file pointer to write window information to
- X NULL - 0
- */
- write_header()
- {
- X register char *date;
- X struct timeval tp;
- X
- X /*Get current date & time*/
- X gettimeofday(&tp,NULL);
- X date = asctime(localtime(&tp.tv_sec));
- X
- X fputs("#!/bin/sh\n",fp);
- X fputs("#\n",fp);
- X fprintf(fp,"# Created by 'xtoolplaces' on %s",date);
- X fputs("#\n\n",fp);
- }
- X
- SHAR_EOF
- chmod 0644 xtoolplaces.c ||
- echo 'restore of xtoolplaces.c failed'
- Wc_c="`wc -c < 'xtoolplaces.c'`"
- test 6839 -eq "$Wc_c" ||
- echo 'xtoolplaces.c: original size 6839, current size' "$Wc_c"
- fi
- # ============= addon.h ==============
- if test -f 'addon.h' -a X"$1" != X"-c"; then
- echo 'x - skipping addon.h (File already exists)'
- else
- echo 'x - extracting addon.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'addon.h' &&
- /*Copyright (c) 1991 Xerox Corporation. All Rights Reserved.
- X
- X Permission to use, copy, modify and distribute without
- X charge this software, documentation, images, etc. is grant-
- X ed, provided that this copyright and the author's name is
- X retained.
- X
- X A fee may be charged for this program ONLY to recover costs
- X for distribution (i.e. media costs). No profit can be made
- X on this program.
- X
- X The author assumes no responsibility for disasters (natural
- X or otherwise) as a consequence of use of this software.
- X
- X Adam Stein (stein.wbst129@xerox.com)
- */
- X
- /*Structure for items to addon*/
- typedef struct _addon {
- X char *program; /*Program to add onto*/
- X char *cmmd_line; /*Command line to add*/
- X struct _addon *next; /*Pointer to next link*/
- } ADDON;
- X
- SHAR_EOF
- chmod 0644 addon.h ||
- echo 'restore of addon.h failed'
- Wc_c="`wc -c < 'addon.h'`"
- test 773 -eq "$Wc_c" ||
- echo 'addon.h: original size 773, current size' "$Wc_c"
- fi
- # ============= patchlevel.h ==============
- if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
- echo 'x - skipping patchlevel.h (File already exists)'
- else
- echo 'x - extracting patchlevel.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
- /*Copyright (c) 1991 Xerox Corporation. All Rights Reserved.
- X
- X Permission to use, copy, modify and distribute without
- X charge this software, documentation, images, etc. is grant-
- X ed, provided that this copyright and the author's name is
- X retained.
- X
- X A fee may be charged for this program ONLY to recover costs
- X for distribution (i.e. media costs). No profit can be made
- X on this program.
- X
- X The author assumes no responsibility for disasters (natural
- X or otherwise) as a consequence of use of this software.
- X
- X Adam Stein (stein.wbst129@xerox.com)
- */
- X
- #define PATCHLEVEL 0
- X
- SHAR_EOF
- chmod 0644 patchlevel.h ||
- echo 'restore of patchlevel.h failed'
- Wc_c="`wc -c < 'patchlevel.h'`"
- test 592 -eq "$Wc_c" ||
- echo 'patchlevel.h: original size 592, current size' "$Wc_c"
- fi
- # ============= xtoolplaces.h ==============
- if test -f 'xtoolplaces.h' -a X"$1" != X"-c"; then
- echo 'x - skipping xtoolplaces.h (File already exists)'
- else
- echo 'x - extracting xtoolplaces.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xtoolplaces.h' &&
- /*Copyright (c) 1991 Xerox Corporation. All Rights Reserved.
- X
- X Permission to use, copy, modify and distribute without
- X charge this software, documentation, images, etc. is grant-
- X ed, provided that this copyright and the author's name is
- X retained.
- X
- X A fee may be charged for this program ONLY to recover costs
- X for distribution (i.e. media costs). No profit can be made
- X on this program.
- X
- X The author assumes no responsibility for disasters (natural
- X or otherwise) as a consequence of use of this software.
- X
- X Adam Stein (stein.wbst129@xerox.com)
- */
- X
- /*User modifiable defines*/
- #define CONSOLE_CLASS "XConsole" /*Class of console windows*/
- #define DEFAULT_FILENAME ".xtoolplaces" /*Default name to save to*/
- #define DEFAULT_REMOTE "rsh -n" /*Default remote command*/
- #define HOME "HOME" /*Home environment variable*/
- X
- /*3 popular console terminal windows and the method to identify when
- X they are present and in console mode since there is no console class*/
- #define CONTOOL_NAME "Contool" /*Name given to contool window*/
- #define SUN_TOOLS_ICON_NAME "CONSOLE" /*Icon name for sun consoles*/
- #define XTERM_OPTION "-C" /*Console option for xterm*/
- X
- X
- /*Do not modify anything below this line*/
- X
- /*Global definitions*/
- #define USAGE "[-a filename] [-c] [-display host:display.screen] [-f filename] [-m filename] [-r command] [-s {list | all}] [-v]"
- #define VERSION "1.0" /*Version*/
- X
- SHAR_EOF
- chmod 0644 xtoolplaces.h ||
- echo 'restore of xtoolplaces.h failed'
- Wc_c="`wc -c < 'xtoolplaces.h'`"
- test 1417 -eq "$Wc_c" ||
- echo 'xtoolplaces.h: original size 1417, current size' "$Wc_c"
- fi
- # ============= addon.sample ==============
- if test -f 'addon.sample' -a X"$1" != X"-c"; then
- echo 'x - skipping addon.sample (File already exists)'
- else
- echo 'x - extracting addon.sample (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'addon.sample' &&
- # Sample addon file to add the '.work' argument to the end of the xrolo
- # command line
- X
- xrolo: .work
- SHAR_EOF
- chmod 0644 addon.sample ||
- echo 'restore of addon.sample failed'
- Wc_c="`wc -c < 'addon.sample'`"
- test 101 -eq "$Wc_c" ||
- echo 'addon.sample: original size 101, current size' "$Wc_c"
- fi
- # ============= missing.sample ==============
- if test -f 'missing.sample' -a X"$1" != X"-c"; then
- echo 'x - skipping missing.sample (File already exists)'
- else
- echo 'x - extracting missing.sample (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'missing.sample' &&
- # Sample missing applications files to save xman
- XXman
- X
- SHAR_EOF
- chmod 0644 missing.sample ||
- echo 'restore of missing.sample failed'
- Wc_c="`wc -c < 'missing.sample'`"
- test 55 -eq "$Wc_c" ||
- echo 'missing.sample: original size 55, current size' "$Wc_c"
- fi
- exit 0
-
- --
- Dan Heller
- O'Reilly && Associates Z-Code Software Comp-sources-x:
- Senior Writer President comp-sources-x@uunet.uu.net
- argv@ora.com argv@zipcode.com
-