home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / jove-4.16-src.tgz / tar.out / bsd / jove / teachjove.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  82 lines

  1. /************************************************************************
  2.  * This program is Copyright (C) 1986-1996 by Jonathan Payne.  JOVE is  *
  3.  * provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is *
  5.  * included in all the files.                                           *
  6.  ************************************************************************/
  7.  
  8. #include "tune.h"
  9. #include "paths.h"
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #ifdef REALSTDC
  14. # include <stdlib.h>
  15. # define proto(x)        x
  16. #else
  17. # define proto(x)        ()
  18. extern char    *getenv proto((const char *));
  19. #endif
  20.  
  21. /* A couple of bits stolen from externs.h: */
  22.  
  23. extern int    access proto((const char */*path*/, int /*mode*/));
  24. #ifndef W_OK
  25. #   define W_OK    2
  26. #   define F_OK    0
  27. #endif
  28.  
  29. # if !defined(ZTCDOS) && !defined(__BORLANDC__)
  30. /* Zortech incorrectly defines argv as const char **.
  31.  * Borland incorrectly defines argv as char *[] and omits some consts
  32.  * on execl and execlp parameters.
  33.  * On the other hand, each supplies declarations for these functions.
  34.  */
  35. extern int    execlp proto((const char */*file*/, const char */*arg*/, ...));
  36. # endif
  37.  
  38.  
  39. static char    ShareDir[FILESIZE] = SHAREDIR;
  40.  
  41. int
  42. main(argc, argv)
  43. int    argc;
  44. char    *argv[];
  45. {
  46.     char
  47.         cmd[FILESIZE*3],
  48.         fname[FILESIZE],
  49.         *home,
  50.         teachjove[FILESIZE];
  51.  
  52.     if (argc == 3 && strcmp(argv[1], "-s") == 0) {
  53.         if (strlen(argv[2]) >= FILESIZE*sizeof(char)) {
  54.             printf("teachjove: -s argument too long\n");
  55.             exit(-1);
  56.         }
  57.         strcpy(ShareDir, argv[2]);
  58.     } else if (argc != 1) {
  59.         printf("Usage: teachjove [-s sharedir]\n");
  60.         exit(-1);
  61.     }
  62.     /* ??? "teach-jove" is too long for MSDOS */
  63.     (void) sprintf(teachjove, "%s/teach-jove", ShareDir);
  64.     if ((home = getenv("HOME")) == NULL) {
  65. #ifdef __amigaos__
  66.           home = "/tmp";
  67. #else
  68.         printf("teachjove: cannot find your home!\n");
  69.         exit(-1);
  70. #endif
  71.     }
  72.     /* ??? "teach-jove" is too long for MSDOS */
  73.     (void) sprintf(fname, "%s/teach-jove", home);
  74.     if (access(fname, F_OK) != 0) {
  75.         (void) sprintf(cmd, "cp %s %s; chmod 644 %s", teachjove, fname, fname);
  76.         system(cmd);
  77.     }
  78.     (void) execlp("jove", "teachjove", fname, (char *) NULL);
  79.     printf("teachjove: cannot execl jove!\n");
  80.     return 1;
  81. }
  82.