// 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 #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*/ }