File: execute.c

package info (click to toggle)
ytree 1.94-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 836 kB
  • ctags: 1,510
  • sloc: ansic: 15,271; makefile: 208
file content (163 lines) | stat: -rw-r--r-- 3,119 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/execute.c,v 1.13 2004/11/13 20:38:40 werner Exp $
 *
 * Ausfuehren von System-Kommandos
 *
 ***************************************************************************/


#include "ytree.h"


extern int chdir(const char *);


int Execute(DirEntry *dir_entry, FileEntry *file_entry)
{
  static char command_line[COMMAND_LINE_LENGTH + 1];
  char cwd[PATH_LENGTH+1];
  char path[PATH_LENGTH+1];
  int  result;

  result = -1;

  if( file_entry )
  {
    if( file_entry->stat_struct.st_mode & 
	( S_IXUSR | S_IXGRP | S_IXOTH ) )
    {
      /* ausfuehrbare Datei */
      /*--------------------*/

      (void) StrCp( command_line, file_entry->name );
    }
  }

  MvAddStr( LINES - 2, 1, "Command:" );
  if( !GetCommandLine( command_line ) )
  {
    if( Getcwd( cwd, PATH_LENGTH ) == NULL )
    {
      WARNING( "Getcwd failed*\".\"assumed" );
      (void) strcpy( cwd, "." );
    }

    if( mode == DISK_MODE || mode == USER_MODE )
    {
      if( chdir( GetPath( dir_entry, path ) ) )
      {
        (void) sprintf( message, "Can't change directory to*\"%s\"", path );
        MESSAGE( message );
      }
      else
      {
        refresh();
        result = QuerySystemCall( command_line );
      }
      (void) chdir( cwd );
    }
    else
    {
      refresh();
      result = QuerySystemCall( command_line );
    }
  }
  
  return( result );
}




int GetCommandLine(char *command_line)
{
  int result;

  result = -1;

  ClearHelp();

  MvAddStr( LINES - 2, 1, "Command: " );
  if( InputString( command_line, LINES - 2, 10, 0, COLS - 11, "\r\033" ) == CR )
  {
    move( LINES - 2, 1 ); clrtoeol();
    result = 0;
  }

  move( LINES - 2, 1 ); clrtoeol();

  return( result );
}

    

int GetSearchCommandLine(char *command_line)
{
  int  result;
  int  pos;
  char *cptr;

  result = -1;

  ClearHelp();

  MvAddStr( LINES - 2, 1, "Search untag command: " );
  strcpy( command_line, SEARCHCOMMAND );

  cptr = strstr( command_line, "{}" );
  if(cptr) {
    pos = (cptr - command_line) - 1;
    if(pos < 0)
      pos = 0;
  } else {
    pos = 0;
  }
  if( InputString( command_line, LINES - 2, 23, pos, COLS - 24, "\r\033" ) == CR )
  {
    move( LINES - 2, 1 ); clrtoeol();
    result = 0;
  }

  move( LINES - 2, 1 ); clrtoeol();

  return( result );
}

    

int ExecuteCommand(FileEntry *fe_ptr, WalkingPackage *walking_package)
{
  char command_line[COMMAND_LINE_LENGTH + 1];
  int i, result;
  char c;
  char *cptr;

  command_line[0] = '\0';
  cptr = command_line;

  walking_package->new_fe_ptr = fe_ptr;  /* unchanged */

  for( i=0; (c = walking_package->function_data.execute.command[i]); i++ )
  {
    if( c == '{' && walking_package->function_data.execute.command[i+1] == '}' )
    {
      (void) GetFileNamePath( fe_ptr, cptr );
      cptr = &command_line[ strlen( command_line ) ];
      i++;
    }
    else
    {
      *cptr++ = c;
    }
  }
  *cptr = '\0';

  result = SilentSystemCall( command_line );

  /* Ignore Result */
  /*---------------*/

  return( result );
}