aboutsummaryrefslogtreecommitdiff
path: root/libexe/platform-unix.c
blob: 0738bdd15c8c6965cb82c752167868b5dffa8c0d (plain) (blame)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962

// platform-unix.c  -- unix platform specific stuff
// BRING UP A FILE CHOOSER
//
//     RETURNS:
//          -1 if they hit Cancel (filename[0] = '\0')
//           0 if filename chosen
//
//     USAGE:
//        const char *title          = "Open Document File";
//        const char *comment        = "Doc files are *.doc";
//        static char filename[512]  = "/usr/tmp/foo.doc";
//        int         filemax        = sizeof(filename) - 1;
//        static char filter[80]     = "*.doc";
//        int         filtermax      = sizeof(filter) - 1;
//
//        if ( file_chooser(title, comment, filename, filemax, 
//                          filter, filtermax) < 0 )
//        {
//            printf("File you picked is: %s\n", filename);
//        }
//
#include <stdio.h>
#define POINT VERT
int
SetCursorPos( int a, int b )
{
}

int
GetCursorPos( POINT * p )
{
	p->x = valuator[MOUSEX];
	p->y = valuator[MOUSEY];
}

void
Sleep( int a )
{
	a = a;
}

int
getTAB(  )
{
	return ( 0 );
}

int
getESCAPE(  )
{
	return ( 0 );
}

int
getSHIFT(  )
{
	return ( 0 );
}

int
getCTRL(  )
{
	return ( 0 );
}

int
filechooserSV(					//const 
				  char *title,
				  //const 
				  char *comment, char *filename, int filenamemax, char *filter, int filtermax )
{
	// INVOKE THE EXTERNAL FILE CHOOSER
	//    For one thing, fltk is c++, so we don't wanna try to link that in
	//    to our cckr program (joe doesn't like modules, as you can see).
	//    Also, fltk will likely want to open its own X display and graphics
	//    contexts, so to prevent collisions, we make the chooser an external
	//    program.
	//
	//    External program returns a filename either as '/usr/tmp/foo.hair',
	//    or as '' indicating 'cancel' was hit.
	//
	char            s[256];
	FILE           *fp;
	int             ret = -1;

	// OPEN READ PIPE TO FILE CHOOSER
	sprintf( s, "filechooser-unix '%s' '%s' '%s'", ( ( title ) ? title : "" ), ( ( filename ) ? filename : "" ), ( ( filter ) ? filter : "" ) );
	fprintf( stderr, "EXECUTING: '%s'\n", s );
	if( ( fp = popen( s, "r" ) ) == NULL )
	{
		perror( s );
		return ( -1 );
	}
	// READ FILENAME CHOOSER RETURNS
	s[0] = '\0';
	if( fgets( s, sizeof( s ) - 1, fp ) != NULL )
	{
		char            foo[256];

		fprintf( stderr, "RAW RETURN: '%s'\n", s );
		sscanf( s, "'%255[^']'", filename );
		fprintf( stderr, "RETURN FILENAME: '%s'\n", filename );
		ret = 0;
	}
	else
	{
		ret = -1;
	}
	pclose( fp );
	return ( ret );
#ifdef NOTNOW
	if( title == 0 )
		title = "";
	if( comment == 0 )
		comment = "";
	fprintf( stderr, "filechooser: NOT YET IMPLEMENTED\n" );
	fprintf( stderr, "TITLE=%s\nEnter Filename: ", title );
	fgets( filename, filenamemax - 1, stdin );
	{
		int             t;

		for( t = 0; filename[t]; t++ )
			if( filename[t] == '\n' )
				filename[t] = '\0';
	}
	fprintf( stderr, "FILENAME='%s'\n", filename );
	return ( 0 );
#endif /*NOTNOW*/
}

int
filechooser(					//const 
				char *title,
				//const 
				char *comment, char *filename, int filenamemax, char *filter, int filtermax )
{
	// INVOKE THE EXTERNAL FILE CHOOSER
	//    For one thing, fltk is c++, so we don't wanna try to link that in
	//    to our cckr program (joe doesn't like modules, as you can see).
	//    Also, fltk will likely want to open its own X display and graphics
	//    contexts, so to prevent collisions, we make the chooser an external
	//    program.
	//
	//    External program returns a filename either as '/usr/tmp/foo.hair',
	//    or as '' indicating 'cancel' was hit.
	//
	char            s[256];
	FILE           *fp;
	int             ret = -1;

	// OPEN READ PIPE TO FILE CHOOSER
	sprintf( s, "filechooser-unix '%s' '%s' '%s'", ( ( title ) ? title : "" ), ( ( filename ) ? filename : "" ), ( ( filter ) ? filter : "" ) );
	fprintf( stderr, "EXECUTING: '%s'\n", s );
	if( ( fp = popen( s, "r" ) ) == NULL )
	{
		perror( s );
		return ( -1 );
	}
	// READ FILENAME CHOOSER RETURNS
	s[0] = '\0';
	if( fgets( s, sizeof( s ) - 1, fp ) != NULL )
	{
		char            foo[256];

		fprintf( stderr, "RAW RETURN: '%s'\n", s );
		sscanf( s, "'%255[^']'", filename );
		fprintf( stderr, "RETURN FILENAME: '%s'\n", filename );
		ret = 0;
	}
	else
	{
		ret = -1;
	}
	pclose( fp );
	return ( ret );
#ifdef NOTNOW
	if( title == 0 )
		title = "";
	if( comment == 0 )
		comment = "";
	fprintf( stderr, "filechooser: NOT YET IMPLEMENTED\n" );
	fprintf( stderr, "TITLE=%s\nEnter Filename: ", title );
	fgets( filename, filenamemax - 1, stdin );
	{
		int             t;

		for( t = 0; filename[t]; t++ )
			if( filename[t] == '\n' )
				filename[t] = '\0';
	}
	fprintf( stderr, "FILENAME='%s'\n", filename );
	return ( 0 );
#endif /*NOTNOW*/
}