home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume14 / xtoolplaces / part02 < prev    next >
Encoding:
Text File  |  1991-08-26  |  13.2 KB  |  433 lines

  1. Path: uunet!zaphod.mps.ohio-state.edu!usc!apple!sun-barr!cronkite.Central.Sun.COM!newstop!exodus!wrc.xerox.com
  2. From: stein@wrc.xerox.com (adam stein)
  3. Newsgroups: comp.sources.x
  4. Subject: v14i003: xtoolplaces, Part02/02
  5. Message-ID: <19068@exodus.Eng.Sun.COM>
  6. Date: 27 Aug 91 04:58:13 GMT
  7. References: <csx-14i002-xtoolplaces@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 421
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: stein@wrc.xerox.com (adam stein)
  13. Posting-number: Volume 14, Issue 3
  14. Archive-name: xtoolplaces/part02
  15.  
  16. ---- Cut Here and feed the following to sh ----
  17. #!/bin/sh
  18. # This is part 02 of a multipart archive
  19. # ============= xtoolplaces.c ==============
  20. if test -f 'xtoolplaces.c' -a X"$1" != X"-c"; then
  21.     echo 'x - skipping xtoolplaces.c (File already exists)'
  22. else
  23. echo 'x - extracting xtoolplaces.c (Text)'
  24. sed 's/^X//' << 'SHAR_EOF' > 'xtoolplaces.c' &&
  25. /*Copyright (c) 1991 Xerox Corporation.  All Rights Reserved.
  26. X
  27. X  Permission to use,  copy,  modify  and  distribute  without
  28. X  charge this software, documentation, images, etc. is grant-
  29. X  ed, provided that this copyright and the author's  name  is
  30. X  retained.
  31. X
  32. X  A fee may be charged for this program ONLY to recover costs
  33. X  for distribution (i.e. media costs).  No profit can be made
  34. X  on this program.
  35. X
  36. X  The author assumes no responsibility for disasters (natural
  37. X  or otherwise) as a consequence of use of this software.
  38. X
  39. X  Adam Stein (stein.wbst129@xerox.com)
  40. */
  41. X
  42. #include <stdio.h>
  43. #include <malloc.h>
  44. #include <X11/Xos.h>
  45. #include "xtoolplaces.h"
  46. #include "patchlevel.h"
  47. X
  48. int console_checking;            /*Console checking flag*/
  49. char *addon;                /*File containing stuff to add*/
  50. char *list;                /*List of screens to save*/
  51. char *missing;                /*File containing apps to save*/
  52. char *remote;                /*Command to use for remote apps*/
  53. char *use_display;            /*Display to use*/
  54. char *program;                /*Program name*/
  55. FILE *fp;                /*File pointer to write to*/
  56. X
  57. /*This program will write the current state of every window on an X desktop to
  58. X  a file (or stdout).  It is the X equivalent to Sunview's toolplaces program.
  59. X
  60. X
  61. X  Inputs:  argc    - number of command line arguments
  62. X       argv    - command line arguments
  63. X  Outputs: 0
  64. X  Locals:  none
  65. X  Globals: fp      - file pointer to write window information to
  66. X       program - name of currently executing program
  67. X       stdout  - standard output
  68. */
  69. main(argc,argv)
  70. register int argc;
  71. register char *argv[];
  72. {
  73. X    program = argv[0];
  74. X
  75. X    getargs(argc,argv);
  76. X
  77. X    getinfo();
  78. X
  79. X    if(fp != stdout) fclose(fp);
  80. X
  81. X    exit(0);
  82. }
  83. X
  84. /*This function will parse the command line arguments and act on them.
  85. X
  86. X  Inputs:  argc - number of command line arguments
  87. X       argv - command line arguments
  88. X  Outputs: none
  89. X  Locals:  home             - home directory
  90. X       filename         - name of file to write window information to
  91. X       loop             - loop through arguments
  92. X       pointer          - point to option letter
  93. X  Globals: addon        - file containing commands to add on to end of
  94. X                  window command arguments
  95. X       console_checking - flag indicating to put special 'if ... fi'
  96. X                  statements around console windows
  97. X       filename         - name of file to write window info to
  98. X       fp            - file pointer to write window information to
  99. X       list            - list of screens to save
  100. X       missing        - file containing apps that don't set WM_COMMAND
  101. X       program          - name of currently executing program
  102. X       remote        - command to use for remote applications
  103. X       stderr        - standard error
  104. X       stdout        - standard output
  105. X       use_display      - display to use
  106. X       DEFAULT_FILENAME - default filename to write window info to
  107. X       DEFAULT_REMOTE   - default remote command to use
  108. X       HOME            - home environment variable
  109. X       NULL            - 0
  110. X       PATCHLEVEL       - current program patchlevel
  111. X       USAGE            - usage line
  112. X       VERSION          - current program version
  113. */
  114. getargs(argc,argv)
  115. register int argc;
  116. register char *argv[];
  117. {
  118. X    register int loop;
  119. X    register char *pointer,*home,*filename;
  120. X    char *getenv(),*strdup();
  121. X
  122. X    /*Set defaults*/
  123. X    console_checking = 0;
  124. X    addon = filename = list = missing = use_display = NULL;
  125. X    remote = DEFAULT_REMOTE;
  126. X
  127. X    /*Loop through and parse arguments*/
  128. X    for(loop = 1;loop < argc;++loop) {
  129. X      pointer = &argv[loop][1];
  130. X
  131. X      switch(*pointer) {
  132. X        case 'a':        /*File containing options to addon*/
  133. X            if(++loop == argc) {
  134. X              fprintf(stderr,"usage: %s %s\n",program,USAGE);
  135. X              exit(1);
  136. X            } else if((addon = strdup(argv[loop])) == NULL) {
  137. X                  perror(program);
  138. X                      exit(1);
  139. X                    }
  140. X
  141. X            break;
  142. X        case 'c':        /*Check for console window*/
  143. X            console_checking = 1;
  144. X
  145. X            break;
  146. X        case 'd':        /*Use another display*/
  147. X            if(!strcmp(pointer,"display"))
  148. X              if(++loop == argc) {
  149. X                fprintf(stderr,"usage: %s %s\n",program,USAGE);
  150. X                exit(1);
  151. X              } else
  152. X                  if((use_display = strdup(argv[loop])) == NULL) {
  153. X                    perror(program);
  154. X                    exit(1);
  155. X                  }
  156. X
  157. X            break;
  158. X        case 'f':        /*Filename to write to*/
  159. X            if(++loop == argc) {
  160. X              fprintf(stderr,"usage: %s %s\n",program,USAGE);
  161. X              exit(1);
  162. X            } else if((filename = strdup(argv[loop])) == NULL) {
  163. X                 perror(program);
  164. X                     exit(1);
  165. X                   }
  166. X
  167. X            break;
  168. X        case 'm':        /*File containing apps w/out WM_COMMAND*/
  169. X            if(++loop == argc) {
  170. X              fprintf(stderr,"usage: %s %s\n",program,USAGE);
  171. X              exit(1);
  172. X            } else if((missing = strdup(argv[loop])) == NULL) {
  173. X                  perror(program);
  174. X                      exit(1);
  175. X                    }
  176. X
  177. X            break;
  178. X        case 'r':        /*Command to start remote applications*/
  179. X            if(++loop == argc) {
  180. X              fprintf(stderr,"usage: %s %s\n",program,USAGE);
  181. X              exit(1);
  182. X            } else if((remote = strdup(argv[loop])) == NULL) {
  183. X                 perror(program);
  184. X                     exit(1);
  185. X                   }
  186. X            break;
  187. X        case 's':        /*List of screens to save*/
  188. X            if(++loop == argc) {
  189. X              fprintf(stderr,"usage: %s %s\n",program,USAGE);
  190. X              exit(1);
  191. X            } else if((list = strdup(argv[loop])) == NULL) {
  192. X                 perror(program);
  193. X                     exit(1);
  194. X                   }
  195. X            break;
  196. X        case 'v':        /*Print version*/
  197. X                fprintf(stderr,"%s: version %s, patchlevel %d\n",
  198. X                program,VERSION,PATCHLEVEL);
  199. X                exit(0);
  200. X        default:
  201. X            fprintf(stderr,"usage: %s %s\n",program,USAGE);
  202. X            exit(1);
  203. X      }
  204. X    }
  205. X
  206. X    /*If filename isn't given, use default ~/.xtoolplaces
  207. X      else if filename matches -, write to stdout, else
  208. X      open the filename given for writing*/
  209. X    if(!filename) {
  210. X      /*Get home directory for default filename*/
  211. X      if((home = getenv(HOME)) == NULL) {
  212. X        fprintf(stderr,"%s: can't find %s in environment, no default for filename\n",program,HOME);
  213. X        exit(1);
  214. X      }
  215. X
  216. X      if((filename = malloc(strlen(home)+strlen(DEFAULT_FILENAME)+2))
  217. X         == NULL) {
  218. X        perror(program);
  219. X        exit(1);
  220. X      }
  221. X
  222. X      strcpy(filename,home);
  223. X      strcat(filename,"/");
  224. X      strcat(filename,DEFAULT_FILENAME);
  225. X    }
  226. X
  227. X    if(strcmp(filename,"-")) {
  228. X      if((fp = fopen(filename,"w")) == NULL) {
  229. X       fprintf(stderr,"%s: can't open {%s} for writing\n",program,filename);
  230. X       exit(1);
  231. X      }
  232. X    } else fp = stdout;
  233. X
  234. X    /*If -a option given, read in addon file*/
  235. X    if(addon) read_addon();
  236. X
  237. X    /*If -m option given, read in missing apps file*/
  238. X    if(missing) read_missing();
  239. X
  240. X    write_header();
  241. }
  242. X
  243. /*This function will write out the header for a Bourne shell script.  It will
  244. X  also write out the current date and time.
  245. X
  246. X  Inputs:  none
  247. X  Outputs: none
  248. X  Locals:  date - current date and time
  249. X       tp   - date & time info structure
  250. X  Globals: fp   - file pointer to write window information to
  251. X       NULL - 0
  252. */
  253. write_header()
  254. {
  255. X    register char *date;
  256. X    struct timeval tp;
  257. X
  258. X    /*Get current date & time*/
  259. X    gettimeofday(&tp,NULL);
  260. X    date = asctime(localtime(&tp.tv_sec));
  261. X
  262. X    fputs("#!/bin/sh\n",fp);
  263. X    fputs("#\n",fp);
  264. X    fprintf(fp,"# Created by 'xtoolplaces' on %s",date);
  265. X    fputs("#\n\n",fp);
  266. }
  267. X
  268. SHAR_EOF
  269. chmod 0644 xtoolplaces.c ||
  270. echo 'restore of xtoolplaces.c failed'
  271. Wc_c="`wc -c < 'xtoolplaces.c'`"
  272. test 6839 -eq "$Wc_c" ||
  273.     echo 'xtoolplaces.c: original size 6839, current size' "$Wc_c"
  274. fi
  275. # ============= addon.h ==============
  276. if test -f 'addon.h' -a X"$1" != X"-c"; then
  277.     echo 'x - skipping addon.h (File already exists)'
  278. else
  279. echo 'x - extracting addon.h (Text)'
  280. sed 's/^X//' << 'SHAR_EOF' > 'addon.h' &&
  281. /*Copyright (c) 1991 Xerox Corporation.  All Rights Reserved.
  282. X
  283. X  Permission to use,  copy,  modify  and  distribute  without
  284. X  charge this software, documentation, images, etc. is grant-
  285. X  ed, provided that this copyright and the author's  name  is
  286. X  retained.
  287. X
  288. X  A fee may be charged for this program ONLY to recover costs
  289. X  for distribution (i.e. media costs).  No profit can be made
  290. X  on this program.
  291. X
  292. X  The author assumes no responsibility for disasters (natural
  293. X  or otherwise) as a consequence of use of this software.
  294. X
  295. X  Adam Stein (stein.wbst129@xerox.com)
  296. */
  297. X
  298. /*Structure for items to addon*/
  299. typedef struct _addon {
  300. X    char *program;                /*Program to add onto*/
  301. X    char *cmmd_line;            /*Command line to add*/
  302. X    struct _addon *next;            /*Pointer to next link*/
  303. } ADDON;
  304. X
  305. SHAR_EOF
  306. chmod 0644 addon.h ||
  307. echo 'restore of addon.h failed'
  308. Wc_c="`wc -c < 'addon.h'`"
  309. test 773 -eq "$Wc_c" ||
  310.     echo 'addon.h: original size 773, current size' "$Wc_c"
  311. fi
  312. # ============= patchlevel.h ==============
  313. if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
  314.     echo 'x - skipping patchlevel.h (File already exists)'
  315. else
  316. echo 'x - extracting patchlevel.h (Text)'
  317. sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
  318. /*Copyright (c) 1991 Xerox Corporation.  All Rights Reserved.
  319. X
  320. X  Permission to use,  copy,  modify  and  distribute  without
  321. X  charge this software, documentation, images, etc. is grant-
  322. X  ed, provided that this copyright and the author's  name  is
  323. X  retained.
  324. X
  325. X  A fee may be charged for this program ONLY to recover costs
  326. X  for distribution (i.e. media costs).  No profit can be made
  327. X  on this program.
  328. X
  329. X  The author assumes no responsibility for disasters (natural
  330. X  or otherwise) as a consequence of use of this software.
  331. X
  332. X  Adam Stein (stein.wbst129@xerox.com)
  333. */
  334. X
  335. #define PATCHLEVEL 0
  336. X
  337. SHAR_EOF
  338. chmod 0644 patchlevel.h ||
  339. echo 'restore of patchlevel.h failed'
  340. Wc_c="`wc -c < 'patchlevel.h'`"
  341. test 592 -eq "$Wc_c" ||
  342.     echo 'patchlevel.h: original size 592, current size' "$Wc_c"
  343. fi
  344. # ============= xtoolplaces.h ==============
  345. if test -f 'xtoolplaces.h' -a X"$1" != X"-c"; then
  346.     echo 'x - skipping xtoolplaces.h (File already exists)'
  347. else
  348. echo 'x - extracting xtoolplaces.h (Text)'
  349. sed 's/^X//' << 'SHAR_EOF' > 'xtoolplaces.h' &&
  350. /*Copyright (c) 1991 Xerox Corporation.  All Rights Reserved.
  351. X
  352. X  Permission to use,  copy,  modify  and  distribute  without
  353. X  charge this software, documentation, images, etc. is grant-
  354. X  ed, provided that this copyright and the author's  name  is
  355. X  retained.
  356. X
  357. X  A fee may be charged for this program ONLY to recover costs
  358. X  for distribution (i.e. media costs).  No profit can be made
  359. X  on this program.
  360. X
  361. X  The author assumes no responsibility for disasters (natural
  362. X  or otherwise) as a consequence of use of this software.
  363. X
  364. X  Adam Stein (stein.wbst129@xerox.com)
  365. */
  366. X
  367. /*User modifiable defines*/
  368. #define CONSOLE_CLASS "XConsole"        /*Class of console windows*/
  369. #define DEFAULT_FILENAME ".xtoolplaces"        /*Default name to save to*/
  370. #define DEFAULT_REMOTE "rsh -n"            /*Default remote command*/
  371. #define HOME "HOME"                /*Home environment variable*/
  372. X
  373. /*3 popular console terminal windows and the method to identify when
  374. X  they are present and in console mode since there is no console class*/
  375. #define CONTOOL_NAME "Contool"            /*Name given to contool window*/
  376. #define SUN_TOOLS_ICON_NAME "CONSOLE"        /*Icon name for sun consoles*/
  377. #define XTERM_OPTION "-C"            /*Console option for xterm*/
  378. X
  379. X
  380. /*Do not modify anything below this line*/
  381. X
  382. /*Global definitions*/
  383. #define USAGE "[-a filename] [-c] [-display host:display.screen] [-f filename] [-m filename] [-r command] [-s {list | all}] [-v]"
  384. #define VERSION "1.0"                /*Version*/
  385. X
  386. SHAR_EOF
  387. chmod 0644 xtoolplaces.h ||
  388. echo 'restore of xtoolplaces.h failed'
  389. Wc_c="`wc -c < 'xtoolplaces.h'`"
  390. test 1417 -eq "$Wc_c" ||
  391.     echo 'xtoolplaces.h: original size 1417, current size' "$Wc_c"
  392. fi
  393. # ============= addon.sample ==============
  394. if test -f 'addon.sample' -a X"$1" != X"-c"; then
  395.     echo 'x - skipping addon.sample (File already exists)'
  396. else
  397. echo 'x - extracting addon.sample (Text)'
  398. sed 's/^X//' << 'SHAR_EOF' > 'addon.sample' &&
  399. # Sample addon file to add the '.work' argument to the end of the xrolo
  400. # command line
  401. X
  402. xrolo: .work
  403. SHAR_EOF
  404. chmod 0644 addon.sample ||
  405. echo 'restore of addon.sample failed'
  406. Wc_c="`wc -c < 'addon.sample'`"
  407. test 101 -eq "$Wc_c" ||
  408.     echo 'addon.sample: original size 101, current size' "$Wc_c"
  409. fi
  410. # ============= missing.sample ==============
  411. if test -f 'missing.sample' -a X"$1" != X"-c"; then
  412.     echo 'x - skipping missing.sample (File already exists)'
  413. else
  414. echo 'x - extracting missing.sample (Text)'
  415. sed 's/^X//' << 'SHAR_EOF' > 'missing.sample' &&
  416. # Sample missing applications files to save xman
  417. XXman
  418. X
  419. SHAR_EOF
  420. chmod 0644 missing.sample ||
  421. echo 'restore of missing.sample failed'
  422. Wc_c="`wc -c < 'missing.sample'`"
  423. test 55 -eq "$Wc_c" ||
  424.     echo 'missing.sample: original size 55, current size' "$Wc_c"
  425. fi
  426. exit 0
  427.  
  428. --
  429. Dan Heller
  430. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  431. Senior Writer                President          comp-sources-x@uunet.uu.net
  432. argv@ora.com                 argv@zipcode.com
  433.