File: usermode.c

package info (click to toggle)
ytree 1.82-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 656 kB
  • ctags: 1,018
  • sloc: ansic: 13,766; makefile: 125
file content (91 lines) | stat: -rw-r--r-- 2,248 bytes parent folder | download | duplicates (9)
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
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/usermode.c,v 1.3 2003/08/31 11:11:00 werner Exp $
 *
 * Funktionen zur Handhabung des FILE-Windows
 *
 ***************************************************************************/


#include "ytree.h"


#define MAX( a, b ) ( ( (a) > (b) ) ? (a) : (b) )

int DirUserMode(DirEntry *dir_entry, int ch)
{
  int chremap;
  char *command_line, *aux;
  char filepath[PATH_LENGTH +1];

  GetPath( dir_entry, filepath );
  command_line = NULL;
  
  while (( aux = GetUserDirAction(ch, &chremap)) != NULL) {
     if( command_line == NULL &&
          ( command_line = malloc( COMMAND_LINE_LENGTH + 1 ) ) == NULL )
     {
        ERROR_MSG( "Malloc failed*ABORT" );
        exit( 1 );
     }
     if (strstr(aux,"%s") != NULL) {
  	(void) sprintf( command_line, aux, filepath );
     } else {
  	(void) sprintf( command_line, "%s%c%s", aux, ' ', filepath );
     }
     if(SilentSystemCall( command_line ))
     {
       (void) sprintf( message, "can't execute*%s", command_line );
       MESSAGE( message );
     }
     if (chremap == ch || chremap == 0)
       break;
     else
       ch = chremap;
  }

  if (command_line != NULL)
     free( command_line );

  return(ch);
}

int FileUserMode(FileEntryList *file_entry_list, int ch)
{
  int chremap;
  char filepath[PATH_LENGTH +1];
  char *command_line, *aux;

  GetRealFileNamePath( file_entry_list->file, filepath );

  command_line = NULL;
  while (( aux = GetUserFileAction(ch, &chremap)) != NULL) {
     if( command_line == NULL &&
          ( command_line = malloc( COMMAND_LINE_LENGTH + 1 ) ) == NULL )
     {
        ERROR_MSG( "Malloc failed*ABORT" );
        exit( 1 );
     }
  
     if (strstr(aux,"%s") != NULL) {
  	(void) sprintf( command_line, aux, filepath );
     } else {
  	(void) sprintf( command_line, "%s%c%s", aux, ' ', filepath );
     }
     if(SilentSystemCall( command_line ))
     {
       (void) sprintf( message, "can't execute*%s", command_line );
       MESSAGE( message );
     }
     if (chremap == ch || chremap == 0)
       break;
     else
       ch = chremap;
  }

  if (command_line != NULL)
     free( command_line );

  return(chremap);
}