home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / J-Shell-1.1 / cwdcmd.c next >
Encoding:
C/C++ Source or Header  |  1993-03-06  |  844 b   |  44 lines

  1. /* $Id: cwdcmd.c,v 1.0 1993/03/07 04:42:04 jct Exp $ */
  2.  
  3. # include <stdio.h>
  4. # include <string.h>
  5. # include <malloc.h>
  6. # include <sys/param.h>
  7.  
  8. # ifdef ROBUST_VERSION
  9. main(argc, argv)
  10.      int argc;
  11.      char *argv[];
  12. {
  13.   char *intro = "\033EmAcScd ";
  14.   char path[MAXPATHLEN];
  15.   char *message;
  16.   
  17.   if (getwd(path) == NULL)
  18.     {
  19.       fprintf(stderr, "%s: %s\n", argv[0], path);
  20.       exit(1);
  21.     }
  22.   
  23.   if ((message = malloc(strlen(intro) + strlen(path) + 2)) == NULL)
  24.     {
  25.       fprintf(stderr, "%s: out of memory\n", argv[0]);
  26.       exit(1);
  27.     }
  28.   
  29.   strcpy(message, intro);
  30.   strcat(message, path);
  31.   strcat(message, "\n");
  32.   write(1, message, strlen(message));
  33. }
  34. # else
  35. main()
  36. {
  37.   static char message[MAXPATHLEN + 12] = "\033EmAcScd ";
  38.   
  39.   getwd(message + 9);
  40.   strcat(message, "\n");
  41.   write(1, message, strlen(message));
  42. }
  43. # endif
  44.