File: edit.c

package info (click to toggle)
ytree 1.94-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 796 kB
  • ctags: 1,085
  • sloc: ansic: 14,373; makefile: 208
file content (90 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/edit.c,v 1.14 2003/03/16 13:13:29 werner Exp $
 *
 * Edit-Kommando-Bearbeitung
 *
 ***************************************************************************/


#include "ytree.h"



int Edit(DirEntry * dir_entry, char *file_path)
{
  char *command_line;
  int  result = -1;
  char *file_p_aux=NULL;
  char cwd[PATH_LENGTH + 1];
  char path[PATH_LENGTH + 1];


  if( mode != DISK_MODE && mode != USER_MODE )
  {
    beep();
    return( -1 );
  }

  if( access( file_path, R_OK ) )
  {
    (void) sprintf( message, 
		    "Edit not possible!*\"%s\"*%s", 
		    file_path, 
		    strerror(errno) 
		  );
    MESSAGE( message );
    ESCAPE;
  }

  if( ( file_p_aux = (char *)malloc( COMMAND_LINE_LENGTH ) ) == NULL )
  {
    ERROR_MSG( "Malloc failed*ABORT" );
    exit( 1 );
  }
  StrCp(file_p_aux, file_path);

  if( ( command_line = (char *)malloc( COMMAND_LINE_LENGTH ) ) == NULL )
  {
    ERROR_MSG( "Malloc failed*ABORT" );
    exit( 1 );
  }
  (void) strcpy( command_line, EDITOR );
  (void) strcat( command_line, " " );
  (void) strcat( command_line, file_p_aux );
  free( file_p_aux);

  /*  result = SystemCall(command_line);
    --crb3 29apr02: perhaps finally eliminate the problem with jstar writing new
    files to the ytree starting cwd. new code grabbed from execute.c.
    --crb3 01oct02: move Getcwd operation within the IF DISKMODE stuff.
  */                                                                              

  if (mode == DISK_MODE)
  {
    if (Getcwd(cwd, PATH_LENGTH) == NULL)
    {
            WARNING("Getcwd failed*\".\"assumed");
            (void) strcpy(cwd, ".");
    }

    if (chdir(GetPath(dir_entry, path)))
    {
            (void) sprintf(message, "Can't change directory to*\"%s\"", path);
            MESSAGE(message);
    }else{
            result = SystemCall(command_line);
    }
    (void) chdir(cwd);
  }else{
    result = SystemCall(command_line);
  }                                                                         
  free( command_line );
 
FNC_XIT:

  return( result );
}