91 #define _POSIX_C_SOURCE 2 108 #define _WIN32_WINNT 0x0500 113 #ifndef TINYFD_NOSELECTFOLDERWIN 119 #define TINYFD_NOCCSUNICODE 121 int tinyfd_winUtf8 = 0 ;
127 #include <sys/utsname.h> 132 #define MAX_PATH_OR_CMD 1024 133 #define MAX_MULTIPLE_FILES 32 141 #if defined(TINYFD_NOLIB) && defined(_WIN32) 166 #if defined(TINYFD_NOLIB) && defined(_WIN32) 172 static char const gTitle[]=
"missing software! (we will try basic console input)";
182 \ntiny file dialogs on Windows needs:\ 183 \n a graphic display\ 184 \nor dialog.exe (enhanced console mode)\ 185 \nor a console for basic input";
194 \ntiny file dialogs on UNIX needs:\ 197 \nor zenity (or matedialog or qarma)\ 198 \nor python (2 or 3)\ 199 \n + tkinter + python-dbus (optional)\ 200 \nor dialog (opens console if needed)\ 202 \n (opens console for basic input)\ 203 \nor existing console for basic input";
207 #pragma warning(disable:4996) 208 #pragma warning(disable:4100) 209 #pragma warning(disable:4706) 213 char *
const aoDestination,
214 char const *
const aSource)
219 lTmp = strrchr(aSource,
'/');
222 lTmp = strrchr(aSource,
'\\');
226 strncpy(aoDestination, aSource, lTmp - aSource );
227 aoDestination[lTmp - aSource] =
'\0';
231 * aoDestination =
'\0';
236 * aoDestination =
'\0';
238 return aoDestination;
243 char *
const aoDestination,
244 char const *
const aSource)
250 lTmp = strrchr(aSource,
'/');
253 lTmp = strrchr(aSource,
'\\');
257 strcpy(aoDestination, lTmp + 1);
261 strcpy(aoDestination, aSource);
266 * aoDestination =
'\0';
268 return aoDestination;
274 if ( aioString && strlen( aioString ) )
276 char * lastcar = aioString + strlen( aioString ) - 1 ;
277 if ( strncmp( lastcar ,
SLASH , 1 ) )
279 strcat( lastcar ,
SLASH ) ;
286 unsigned char aoResultRGB [3] )
288 char lColorChannel [8] ;
293 strcpy(lColorChannel, aHexRGB ) ;
294 aoResultRGB[2] = (
unsigned char)strtoul(lColorChannel+5,
NULL,16);
295 lColorChannel[5] =
'\0';
296 aoResultRGB[1] = (
unsigned char)strtoul(lColorChannel+3,
NULL,16);
297 lColorChannel[3] =
'\0';
298 aoResultRGB[0] = (
unsigned char)strtoul(lColorChannel+1,
NULL,16);
310 static void RGB2Hex(
unsigned char const aRGB [3] ,
311 char aoResultHexRGB [8] )
313 if ( aoResultHexRGB )
317 #if defined(__GNUC__) && defined(_WIN32) 318 sprintf(aoResultHexRGB,
"#%02hx%02hx%02hx",
320 sprintf(aoResultHexRGB,
"#%02hhx%02hhx%02hhx",
322 aRGB[0], aRGB[1], aRGB[2]);
336 char const *
const aOldSubStr ,
337 char const *
const aNewSubStr ,
338 char *
const aoDestination )
340 char const * pOccurence ;
342 char const * lNewSubStr =
"" ;
343 size_t lOldSubLen = strlen( aOldSubStr ) ;
347 * aoDestination =
'\0' ;
352 strcpy( aoDestination , aSource ) ;
357 lNewSubStr = aNewSubStr ;
360 * aoDestination =
'\0' ;
361 while ( ( pOccurence = strstr( p , aOldSubStr ) ) !=
NULL )
363 strncat( aoDestination , p , pOccurence - p ) ;
364 strcat( aoDestination , lNewSubStr ) ;
365 p = pOccurence + lOldSubLen ;
367 strcat( aoDestination , p ) ;
373 if ( ! aFileNameWithoutPath
374 || ! strlen(aFileNameWithoutPath)
375 || strpbrk(aFileNameWithoutPath ,
"\\/:*?\"<>|") )
387 if ( ! aFilePathAndName || ! strlen(aFilePathAndName) )
391 lIn = fopen( aFilePathAndName ,
"r" ) ;
400 #elif defined(TINYFD_NOLIB) 402 static int fileExists(
char const *
const aFilePathAndName )
405 if ( ! aFilePathAndName || ! strlen(aFilePathAndName) )
410 if ( tinyfd_winUtf8 )
413 lIn = fopen( aFilePathAndName ,
"r" ) ;
431 if (stat(aFilename, &st) == 0)
433 if ((lIn = fopen(aFilename,
"w")))
435 for (i = 0; i < st.st_size; i++)
447 static int replaceChr(
char *
const aString ,
459 if ( aOldChr == aNewChr )
465 while ( (p = strchr( p , aOldChr )) )
476 static int dirExists(
char const *
const aDirPath)
480 if (!aDirPath || !strlen(aDirPath))
482 if (stat(aDirPath, &lInfo) != 0)
484 else if ( tinyfd_winUtf8 )
486 else if (lInfo.st_mode & S_IFDIR)
506 static void wipefileW(
wchar_t const *
const aFilename)
512 if (_wstat(aFilename, &st) == 0)
514 if ((lIn = _wfopen(aFilename, L
"w")))
516 for (i = 0; i < st.st_size; i++)
526 static wchar_t * getPathWithoutFinalSlashW(
527 wchar_t *
const aoDestination,
528 wchar_t const *
const aSource)
530 wchar_t const * lTmp;
533 lTmp = wcsrchr(aSource, L
'/');
536 lTmp = wcsrchr(aSource, L
'\\');
540 wcsncpy(aoDestination, aSource, lTmp - aSource);
541 aoDestination[lTmp - aSource] = L
'\0';
545 *aoDestination = L
'\0';
550 *aoDestination = L
'\0';
552 return aoDestination;
556 static wchar_t * getLastNameW(
557 wchar_t *
const aoDestination,
558 wchar_t const *
const aSource)
561 wchar_t const * lTmp;
564 lTmp = wcsrchr(aSource, L
'/');
567 lTmp = wcsrchr(aSource, L
'\\');
571 wcscpy(aoDestination, lTmp + 1);
575 wcscpy(aoDestination, aSource);
580 *aoDestination = L
'\0';
582 return aoDestination;
586 static void Hex2RGBW(
wchar_t const aHexRGB[8],
587 unsigned char aoResultRGB[3])
589 wchar_t lColorChannel[8];
594 wcscpy(lColorChannel, aHexRGB);
595 aoResultRGB[2] = (
unsigned char)wcstoul(lColorChannel + 5,
NULL, 16);
596 lColorChannel[5] =
'\0';
597 aoResultRGB[1] = (
unsigned char)wcstoul(lColorChannel + 3,
NULL, 16);
598 lColorChannel[3] =
'\0';
599 aoResultRGB[0] = (
unsigned char)wcstoul(lColorChannel + 1,
NULL, 16);
612 static void RGB2HexW(
613 unsigned char const aRGB[3],
614 wchar_t aoResultHexRGB[8])
621 swprintf(aoResultHexRGB,
622 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
625 L
"#%02hhx%02hhx%02hhx", aRGB[0], aRGB[1], aRGB[2]);
629 aoResultHexRGB[0] = 0;
630 aoResultHexRGB[1] = 0;
631 aoResultHexRGB[2] = 0;
637 #if !defined(WC_ERR_INVALID_CHARS) 639 #define WC_ERR_INVALID_CHARS 0x00000080 643 static int sizeUtf16(
char const *
const aUtf8string)
645 return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
646 aUtf8string, -1,
NULL, 0);
650 static int sizeUtf8(
wchar_t const *
const aUtf16string)
652 return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
657 static int sizeMbcs(
wchar_t const *
const aMbcsString)
659 int lRes = WideCharToMultiByte(CP_ACP, 0,
666 static wchar_t * utf8to16(
char const *
const aUtf8string)
668 wchar_t * lUtf16string ;
669 int lSize = sizeUtf16(aUtf8string);
670 lUtf16string = (
wchar_t *) malloc( lSize *
sizeof(
wchar_t) );
671 lSize = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
672 aUtf8string, -1, lUtf16string, lSize);
682 static wchar_t * mbcsTo16(
char const *
const aMbcsString)
684 wchar_t * lMbcsString;
685 int lSize = sizeUtf16(aMbcsString);
686 lMbcsString = (
wchar_t *)malloc(lSize *
sizeof(
wchar_t));
687 lSize = MultiByteToWideChar(CP_ACP, 0,
688 aMbcsString, -1, lMbcsString, lSize);
698 static char * utf16to8(
wchar_t const *
const aUtf16string)
701 int lSize = sizeUtf8(aUtf16string);
702 lUtf8string = (
char *) malloc( lSize );
703 lSize = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
704 aUtf16string, -1, lUtf8string, lSize,
NULL,
NULL);
714 static char * utf16toMbcs(
wchar_t const *
const aUtf16string)
717 int lSize = sizeMbcs(aUtf16string);
718 lMbcsString = (
char *)malloc(lSize);
719 lSize = WideCharToMultiByte(CP_ACP, 0,
720 aUtf16string, -1, lMbcsString, lSize,
NULL,
NULL);
730 static int dirExists(
char const *
const aDirPath)
739 lDirLen = strlen(aDirPath);
742 if ( (lDirLen == 2) && (aDirPath[1] ==
':') )
747 lTmpWChar = utf8to16(aDirPath);
748 lStatRet = _wstat(lTmpWChar, &lInfo);
752 else if (lInfo.st_mode & S_IFDIR)
757 else if (_stat(aDirPath, &lInfo) != 0)
759 else if (lInfo.st_mode & S_IFDIR)
766 static int fileExists(
char const *
const aFilePathAndName)
773 if (!aFilePathAndName || !strlen(aFilePathAndName))
780 lTmpWChar = utf8to16(aFilePathAndName);
781 lStatRet = _wstat(lTmpWChar, &lInfo);
785 else if (lInfo.st_mode & _S_IFREG)
792 lIn = fopen(aFilePathAndName,
"r");
802 static int replaceWchar(
wchar_t *
const aString,
803 wchar_t const aOldChr,
804 wchar_t const aNewChr)
814 if (aOldChr == aNewChr)
820 while ((p = wcsrchr(p, aOldChr)))
823 #ifdef TINYFD_NOCCSUNICODE 837 char const *
const aSourcePathsAndNames)
839 char * lDestination = aDestination;
844 if (!aSourcePathsAndNames)
848 lLen = strlen(aSourcePathsAndNames);
854 p = aSourcePathsAndNames;
855 while ((p2 = strchr(p,
'|')) !=
NULL)
858 memmove(lDestination, p, lLen);
859 lDestination[lLen] =
'\0';
862 lDestination += lLen;
871 memmove(lDestination, p, lLen);
872 lDestination[lLen] =
'\0';
876 *(lDestination - 1) =
'\0';
884 static int __stdcall EnumThreadWndProc(HWND hwnd, LPARAM lParam)
886 wchar_t lTitleName[MAX_PATH];
887 GetWindowTextW(hwnd, lTitleName, MAX_PATH);
889 if (wcscmp(L
"tinyfiledialogsTopWindow", lTitleName) == 0)
891 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
898 static void hiddenConsoleW(
wchar_t const *
const aString,
wchar_t const *
const aDialogTitle,
int const aInFront)
900 STARTUPINFOW StartupInfo;
901 PROCESS_INFORMATION ProcessInfo;
903 if (!aString || !wcslen(aString) )
return;
905 memset(&StartupInfo, 0,
sizeof(StartupInfo));
906 StartupInfo.cb =
sizeof(STARTUPINFOW);
907 StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
908 StartupInfo.wShowWindow = SW_HIDE;
912 &StartupInfo, &ProcessInfo))
917 WaitForInputIdle(ProcessInfo.hProcess, INFINITE);
920 while (EnumWindows(EnumThreadWndProc, (LPARAM)
NULL)) {}
921 SetWindowTextW(GetForegroundWindow(), aDialogTitle);
923 WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
924 CloseHandle(ProcessInfo.hThread);
925 CloseHandle(ProcessInfo.hProcess);
929 int tinyfd_messageBoxW(
930 wchar_t const *
const aTitle,
931 wchar_t const *
const aMessage,
932 wchar_t const *
const aDialogType,
933 wchar_t const *
const aIconType,
934 int const aDefaultButton)
939 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return 1; }
941 if (aIconType && !wcscmp(L
"warning", aIconType))
943 aCode = MB_ICONWARNING;
945 else if (aIconType && !wcscmp(L
"error", aIconType))
947 aCode = MB_ICONERROR;
949 else if (aIconType && !wcscmp(L
"question", aIconType))
951 aCode = MB_ICONQUESTION;
955 aCode = MB_ICONINFORMATION;
958 if (aDialogType && !wcscmp(L
"okcancel", aDialogType))
960 aCode += MB_OKCANCEL;
963 aCode += MB_DEFBUTTON2;
966 else if (aDialogType && !wcscmp(L
"yesno", aDialogType))
971 aCode += MB_DEFBUTTON2;
981 lBoxReturnValue = MessageBoxW(GetForegroundWindow(), aMessage, aTitle, aCode);
983 && wcscmp(L
"okcancel", aDialogType)
984 && wcscmp(L
"yesno", aDialogType)))
985 || (lBoxReturnValue == IDOK)
986 || (lBoxReturnValue == IDYES))
997 static int messageBoxWinGui8(
998 char const *
const aTitle,
999 char const *
const aMessage,
1000 char const *
const aDialogType,
1001 char const *
const aIconType,
1002 int const aDefaultButton)
1007 wchar_t * lDialogType;
1008 wchar_t * lIconType;
1010 lTitle = utf8to16(aTitle);
1011 lMessage = utf8to16(aMessage);
1012 lDialogType = utf8to16(aDialogType);
1013 lIconType = utf8to16(aIconType);
1015 lIntRetVal = tinyfd_messageBoxW(lTitle, lMessage,
1016 lDialogType, lIconType, aDefaultButton );
1028 int tinyfd_notifyPopupW(
1029 wchar_t const *
const aTitle,
1030 wchar_t const *
const aMessage,
1031 wchar_t const *
const aIconType)
1033 wchar_t * lDialogString;
1036 size_t lDialogStringLen;
1038 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return 1; }
1040 lTitleLen = aTitle ? wcslen(aTitle) : 0;
1041 lMessageLen = aMessage ? wcslen(aMessage) : 0;
1043 lDialogString = (
wchar_t *)malloc(2 * lDialogStringLen);
1045 wcscpy(lDialogString, L
"powershell.exe -command \"\ 1046 function Show-BalloonTip {\ 1049 [string]$Title = ' ', \ 1050 [string]$Message = ' ', \ 1051 [ValidateSet('info', 'warning', 'error')] \ 1052 [string]$IconType = 'info');\ 1053 [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null ; \ 1054 $balloon = New-Object System.Windows.Forms.NotifyIcon ; \ 1055 $path = Get-Process -id $pid | Select-Object -ExpandProperty Path ; \ 1056 $icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;");
1058 wcscat(lDialogString, L
"\ 1059 $balloon.Icon = $icon ; \ 1060 $balloon.BalloonTipIcon = $IconType ; \ 1061 $balloon.BalloonTipText = $Message ; \ 1062 $balloon.BalloonTipTitle = $Title ; \ 1063 $balloon.Text = 'lalala' ; \ 1064 $balloon.Visible = $true ; \ 1065 $balloon.ShowBalloonTip(5000)};\ 1068 if (aTitle && wcslen(aTitle))
1070 wcscat(lDialogString, L
" -Title '");
1071 wcscat(lDialogString, aTitle);
1072 wcscat(lDialogString, L
"'");
1074 if (aMessage && wcslen(aMessage))
1076 wcscat(lDialogString, L
" -Message '");
1077 wcscat(lDialogString, aMessage);
1078 wcscat(lDialogString, L
"'");
1080 if (aMessage && wcslen(aIconType))
1082 wcscat(lDialogString, L
" -IconType '");
1083 wcscat(lDialogString, aIconType);
1084 wcscat(lDialogString, L
"'");
1086 wcscat(lDialogString, L
"\"");
1090 hiddenConsoleW(lDialogString, aTitle, 0);
1091 free(lDialogString);
1096 static int notifyWinGui(
1097 char const *
const aTitle,
1098 char const *
const aMessage,
1099 char const *
const aIconType)
1103 wchar_t * lIconType;
1107 lTitle = utf8to16(aTitle);
1108 lMessage = utf8to16(aMessage);
1109 lIconType = utf8to16(aIconType);
1113 lTitle = mbcsTo16(aTitle);
1114 lMessage = mbcsTo16(aMessage);
1115 lIconType = mbcsTo16(aIconType);
1118 tinyfd_notifyPopupW( lTitle, lMessage, lIconType);
1127 wchar_t const * tinyfd_inputBoxW(
1128 wchar_t const *
const aTitle,
1129 wchar_t const *
const aMessage,
1130 wchar_t const *
const aDefaultInput)
1133 wchar_t * lDialogString;
1139 size_t lDialogStringLen;
1141 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return (
wchar_t const *)1; }
1143 lTitleLen = aTitle ? wcslen(aTitle) : 0 ;
1144 lMessageLen = aMessage ? wcslen(aMessage) : 0 ;
1146 lDialogString = (
wchar_t *)malloc(2 * lDialogStringLen);
1150 swprintf(lDialogString,
1151 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
1154 L
"%ls\\AppData\\Local\\Temp\\tinyfd.vbs", _wgetenv(L
"USERPROFILE"));
1158 swprintf(lDialogString,
1159 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
1162 L
"%ls\\AppData\\Local\\Temp\\tinyfd.hta", _wgetenv(L
"USERPROFILE"));
1164 lIn = _wfopen(lDialogString, L
"w");
1167 free(lDialogString);
1171 if ( aDefaultInput )
1173 wcscpy(lDialogString, L
"Dim result:result=InputBox(\"");
1174 if (aMessage && wcslen(aMessage))
1176 wcscpy(lBuff, aMessage);
1177 replaceWchar(lBuff, L
'\n', L
' ');
1178 wcscat(lDialogString, lBuff);
1180 wcscat(lDialogString, L
"\",\"tinyfiledialogsTopWindow\",\"");
1181 if (aDefaultInput && wcslen(aDefaultInput))
1183 wcscpy(lBuff, aDefaultInput);
1184 replaceWchar(lBuff, L
'\n', L
' ');
1185 wcscat(lDialogString, lBuff);
1187 wcscat(lDialogString, L
"\"):If IsEmpty(result) then:WScript.Echo 0");
1188 wcscat(lDialogString, L
":Else: WScript.Echo \"1\" & result : End If");
1192 wcscpy(lDialogString, L
"\n\ 1197 wcscat(lDialogString, L
"tinyfiledialogsTopWindow");
1198 wcscat(lDialogString, L
"</title>\n\ 1201 APPLICATIONNAME = 'tinyfd_inputBox'\n\ 1202 MINIMIZEBUTTON = 'no'\n\ 1203 MAXIMIZEBUTTON = 'no'\n\ 1204 BORDER = 'dialog'\n\ 1206 SINGLEINSTANCE = 'yes'\n\ 1207 WINDOWSTATE = 'hidden'>\n\ 1209 <script language = 'VBScript'>\n\ 1211 intWidth = Screen.Width/4\n\ 1212 intHeight = Screen.Height/6\n\ 1213 ResizeTo intWidth, intHeight\n\ 1214 MoveTo((Screen.Width/2)-(intWidth/2)),((Screen.Height/2)-(intHeight/2))\n\ 1217 Sub Window_onLoad\n\ 1222 wcscat(lDialogString, L
"\ 1223 Sub Window_onUnload\n\ 1224 Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n\ 1225 Set oShell = CreateObject(\"WScript.Shell\")\n\ 1226 strHomeFolder = oShell.ExpandEnvironmentStrings(\"%USERPROFILE%\")\n\ 1227 Set objFile = objFSO.CreateTextFile(strHomeFolder & \"\\AppData\\Local\\Temp\\tinyfd.txt\",True,True)\n\ 1228 If result = 1 Then\n\ 1229 objFile.Write 1 & txt_input.Value\n\ 1236 Sub Run_ProgramOK\n\ 1241 Sub Run_ProgramCancel\n\ 1246 wcscat(lDialogString, L
"Sub Default_Buttons\n\ 1247 If Window.Event.KeyCode = 13 Then\n\ 1249 ElseIf Window.Event.KeyCode = 27 Then\n\ 1256 <body style = 'background-color:#EEEEEE' onkeypress = 'vbs:Default_Buttons' align = 'top'>\n\ 1257 <table width = '100%' height = '80%' align = 'center' border = '0'>\n\ 1258 <tr border = '0'>\n\ 1259 <td align = 'left' valign = 'middle' style='Font-Family:Arial'>\n");
1261 wcscat(lDialogString, aMessage ? aMessage : L
"");
1263 wcscat(lDialogString, L
"\n\ 1265 <td align = 'right' valign = 'middle' style = 'margin-top: 0em'>\n\ 1266 <table align = 'right' style = 'margin-right: 0em;'>\n\ 1267 <tr align = 'right' style = 'margin-top: 5em;'>\n\ 1268 <input type = 'button' value = 'OK' name = 'btn_OK' onClick = 'vbs:Run_ProgramOK' style = 'width: 5em; margin-top: 2em;'><br>\n\ 1269 <input type = 'button' value = 'Cancel' name = 'btn_Cancel' onClick = 'vbs:Run_ProgramCancel' style = 'width: 5em;'><br><br>\n\ 1276 wcscat(lDialogString, L
"<table width = '100%' height = '100%' align = 'center' border = '0'>\n\ 1278 <td align = 'left' valign = 'top'>\n\ 1279 <input type = 'password' id = 'txt_input'\n\ 1280 name = 'txt_input' value = '' style = 'float:left;width:100%' ><BR>\n\ 1288 fputws(lDialogString, lIn);
1293 swprintf(lDialogString,
1294 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
1297 L
"%ls\\AppData\\Local\\Temp\\tinyfd.txt",_wgetenv(L
"USERPROFILE"));
1299 #ifdef TINYFD_NOCCSUNICODE 1300 lFile = _wfopen(lDialogString, L
"w");
1304 lFile = _wfopen(lDialogString, L
"wt, ccs=UNICODE");
1308 wcscpy(lDialogString, L
"cmd.exe /c cscript.exe //U //Nologo ");
1309 wcscat(lDialogString, L
"\"%USERPROFILE%\\AppData\\Local\\Temp\\tinyfd.vbs\" ");
1310 wcscat(lDialogString, L
">> \"%USERPROFILE%\\AppData\\Local\\Temp\\tinyfd.txt\"");
1314 wcscpy(lDialogString,
1315 L
"cmd.exe /c mshta.exe \"%USERPROFILE%\\AppData\\Local\\Temp\\tinyfd.hta\"");
1320 hiddenConsoleW(lDialogString, aTitle, 1);
1322 swprintf(lDialogString,
1323 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
1326 L
"%ls\\AppData\\Local\\Temp\\tinyfd.txt", _wgetenv(L
"USERPROFILE"));
1328 #ifdef TINYFD_NOCCSUNICODE 1329 if (!(lIn = _wfopen(lDialogString, L
"r")))
1331 if (!(lIn = _wfopen(lDialogString, L
"rt, ccs=UNICODE")))
1334 _wremove(lDialogString);
1335 free(lDialogString);
1341 #ifdef TINYFD_NOCCSUNICODE 1347 wipefileW(lDialogString);
1348 _wremove(lDialogString);
1352 swprintf(lDialogString,
1353 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
1356 L
"%ls\\AppData\\Local\\Temp\\tinyfd.vbs",
1357 _wgetenv(L
"USERPROFILE"));
1361 swprintf(lDialogString,
1362 #
if !defined(__BORLANDC__) && !defined(__TINYC__) && ( !defined(__GNUC__) || (__GNUC__) >= 5 )
1365 L
"%ls\\AppData\\Local\\Temp\\tinyfd.hta",
1366 _wgetenv(L
"USERPROFILE"));
1368 _wremove(lDialogString);
1369 free(lDialogString);
1371 #ifdef TINYFD_NOCCSUNICODE 1372 lResult = !wcsncmp(lBuff+1, L
"1", 1);
1374 lResult = !wcsncmp(lBuff, L
"1", 1);
1385 #ifdef TINYFD_NOCCSUNICODE 1388 lDialogStringLen = wcslen(lBuff) ;
1389 lBuff[lDialogStringLen - 1] = L
'\0';
1390 lBuff[lDialogStringLen - 2] = L
'\0';
1394 if (aDefaultInput) lBuff[wcslen(lBuff) - 1] = L
'\0';
1400 static char const * inputBoxWinGui(
1401 char *
const aoBuff,
1402 char const *
const aTitle,
1403 char const *
const aMessage,
1404 char const *
const aDefaultInput)
1408 wchar_t * lDefaultInput;
1409 wchar_t const * lTmpWChar;
1414 lTitle = utf8to16(aTitle);
1415 lMessage = utf8to16(aMessage);
1416 lDefaultInput = utf8to16(aDefaultInput);
1420 lTitle = mbcsTo16(aTitle);
1421 lMessage = mbcsTo16(aMessage);
1422 lDefaultInput = mbcsTo16(aDefaultInput);
1425 lTmpWChar = tinyfd_inputBoxW( lTitle, lMessage, lDefaultInput);
1429 free(lDefaultInput);
1438 lTmpChar = utf16to8(lTmpWChar);
1442 lTmpChar = utf16toMbcs(lTmpWChar);
1444 strcpy(aoBuff, lTmpChar);
1451 wchar_t const * tinyfd_saveFileDialogW(
1452 wchar_t const *
const aTitle,
1453 wchar_t const *
const aDefaultPathAndFile,
1454 int const aNumOfFilterPatterns,
1455 wchar_t const *
const *
const aFilterPatterns,
1456 wchar_t const *
const aSingleFilterDescription)
1464 wchar_t const * ldefExt =
NULL;
1467 OPENFILENAMEW ofn = {0};
1469 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return (
wchar_t const *)1; }
1471 lHResult = CoInitializeEx(
NULL, 0);
1473 getPathWithoutFinalSlashW(lDirname, aDefaultPathAndFile);
1474 getLastNameW(lBuff, aDefaultPathAndFile);
1476 if (aNumOfFilterPatterns > 0)
1478 ldefExt = aFilterPatterns[0];
1480 if (aSingleFilterDescription && wcslen(aSingleFilterDescription))
1482 wcscpy(lFilterPatterns, aSingleFilterDescription);
1483 wcscat(lFilterPatterns, L
"\n");
1485 wcscat(lFilterPatterns, aFilterPatterns[0]);
1486 for (i = 1; i < aNumOfFilterPatterns; i++)
1488 wcscat(lFilterPatterns, L
";");
1489 wcscat(lFilterPatterns, aFilterPatterns[i]);
1491 wcscat(lFilterPatterns, L
"\n");
1492 if (!(aSingleFilterDescription && wcslen(aSingleFilterDescription)))
1494 wcscpy(lDialogString, lFilterPatterns);
1495 wcscat(lFilterPatterns, lDialogString);
1497 wcscat(lFilterPatterns, L
"All Files\n*.*\n");
1498 p = lFilterPatterns;
1499 while ((p = wcschr(p, L
'\n')) !=
NULL)
1506 ofn.lStructSize =
sizeof(OPENFILENAMEW);
1507 ofn.hwndOwner = GetForegroundWindow();
1509 ofn.lpstrFilter = lFilterPatterns && wcslen(lFilterPatterns) ? lFilterPatterns :
NULL;
1510 ofn.lpstrCustomFilter =
NULL;
1511 ofn.nMaxCustFilter = 0;
1512 ofn.nFilterIndex = 1;
1513 ofn.lpstrFile = lBuff;
1516 ofn.lpstrFileTitle =
NULL;
1518 ofn.lpstrInitialDir = lDirname && wcslen(lDirname) ? lDirname :
NULL;
1519 ofn.lpstrTitle = aTitle && wcslen(aTitle) ? aTitle :
NULL;
1520 ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST ;
1521 ofn.nFileOffset = 0;
1522 ofn.nFileExtension = 0;
1523 ofn.lpstrDefExt = ldefExt;
1525 ofn.lpfnHook =
NULL;
1526 ofn.lpTemplateName =
NULL;
1528 if (GetSaveFileNameW(&ofn) == 0)
1537 if (lHResult == S_OK || lHResult == S_FALSE)
1545 static char const * saveFileDialogWinGui8(
1546 char *
const aoBuff,
1547 char const *
const aTitle,
1548 char const *
const aDefaultPathAndFile,
1549 int const aNumOfFilterPatterns,
1550 char const *
const *
const aFilterPatterns,
1551 char const *
const aSingleFilterDescription)
1554 wchar_t * lDefaultPathAndFile;
1555 wchar_t * lSingleFilterDescription;
1556 wchar_t * * lFilterPatterns;
1557 wchar_t const * lTmpWChar;
1561 lFilterPatterns = (
wchar_t **) malloc(aNumOfFilterPatterns*
sizeof(
wchar_t *));
1562 for (i = 0; i < aNumOfFilterPatterns; i++)
1564 lFilterPatterns[
i] = utf8to16(aFilterPatterns[i]);
1567 lTitle = utf8to16(aTitle);
1568 lDefaultPathAndFile = utf8to16(aDefaultPathAndFile);
1569 lSingleFilterDescription = utf8to16(aSingleFilterDescription);
1571 lTmpWChar = tinyfd_saveFileDialogW(
1573 lDefaultPathAndFile,
1574 aNumOfFilterPatterns,
1577 lSingleFilterDescription);
1580 free(lDefaultPathAndFile);
1581 free(lSingleFilterDescription);
1582 for (i = 0; i < aNumOfFilterPatterns; i++)
1584 free(lFilterPatterns[i]);
1586 free(lFilterPatterns);
1593 lTmpChar = utf16to8(lTmpWChar);
1594 strcpy(aoBuff, lTmpChar);
1601 wchar_t const * tinyfd_openFileDialogW(
1602 wchar_t const *
const aTitle,
1603 wchar_t const *
const aDefaultPathAndFile,
1604 int const aNumOfFilterPatterns,
1605 wchar_t const *
const *
const aFilterPatterns,
1606 wchar_t const *
const aSingleFilterDescription,
1607 int const aAllowMultipleSelects)
1616 wchar_t * lRetval, *
p;
1620 OPENFILENAMEW ofn = { 0 };
1622 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return (
wchar_t const *)1; }
1624 lHResult = CoInitializeEx(
NULL, 0);
1626 getPathWithoutFinalSlashW(lDirname, aDefaultPathAndFile);
1627 getLastNameW(lBuff, aDefaultPathAndFile);
1629 if (aNumOfFilterPatterns > 0)
1631 if (aSingleFilterDescription && wcslen(aSingleFilterDescription))
1633 wcscpy(lFilterPatterns, aSingleFilterDescription);
1634 wcscat(lFilterPatterns, L
"\n");
1636 wcscat(lFilterPatterns, aFilterPatterns[0]);
1637 for (i = 1; i < aNumOfFilterPatterns; i++)
1639 wcscat(lFilterPatterns, L
";");
1640 wcscat(lFilterPatterns, aFilterPatterns[i]);
1642 wcscat(lFilterPatterns, L
"\n");
1643 if (!(aSingleFilterDescription && wcslen(aSingleFilterDescription)))
1645 wcscpy(lDialogString, lFilterPatterns);
1646 wcscat(lFilterPatterns, lDialogString);
1648 wcscat(lFilterPatterns, L
"All Files\n*.*\n");
1649 p = lFilterPatterns;
1650 while ((p = wcschr(p, L
'\n')) !=
NULL)
1657 ofn.lStructSize =
sizeof(OPENFILENAME);
1658 ofn.hwndOwner = GetForegroundWindow();
1660 ofn.lpstrFilter = lFilterPatterns && wcslen(lFilterPatterns) ? lFilterPatterns :
NULL;
1661 ofn.lpstrCustomFilter =
NULL;
1662 ofn.nMaxCustFilter = 0;
1663 ofn.nFilterIndex = 1;
1664 ofn.lpstrFile = lBuff;
1666 ofn.lpstrFileTitle =
NULL;
1668 ofn.lpstrInitialDir = lDirname && wcslen(lDirname) ? lDirname :
NULL;
1669 ofn.lpstrTitle = aTitle && wcslen(aTitle) ? aTitle :
NULL;
1670 ofn.Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
1671 ofn.nFileOffset = 0;
1672 ofn.nFileExtension = 0;
1673 ofn.lpstrDefExt =
NULL;
1675 ofn.lpfnHook =
NULL;
1676 ofn.lpTemplateName =
NULL;
1678 if (aAllowMultipleSelects)
1680 ofn.Flags |= OFN_ALLOWMULTISELECT;
1683 if (GetOpenFileNameW(&ofn) == 0)
1689 lBuffLen = wcslen(lBuff);
1690 lPointers[0] = lBuff + lBuffLen + 1;
1691 if (!aAllowMultipleSelects || (lPointers[0][0] == L
'\0'))
1700 lLengths[
i] = wcslen(lPointers[i]);
1701 lPointers[i + 1] = lPointers[
i] + lLengths[
i] + 1;
1703 }
while (lPointers[i][0] != L
'\0');
1707 for (j = i; j >= 0; j--)
1710 memmove(p, lPointers[j], lLengths[j]*
sizeof(
wchar_t));
1714 memmove(p, lBuff, lBuffLen*
sizeof(
wchar_t));
1723 if (lHResult == S_OK || lHResult == S_FALSE)
1731 static char const * openFileDialogWinGui8(
1732 char *
const aoBuff,
1733 char const *
const aTitle,
1734 char const *
const aDefaultPathAndFile,
1735 int const aNumOfFilterPatterns,
1736 char const *
const *
const aFilterPatterns,
1737 char const *
const aSingleFilterDescription,
1738 int const aAllowMultipleSelects)
1741 wchar_t * lDefaultPathAndFile;
1742 wchar_t * lSingleFilterDescription;
1743 wchar_t * * lFilterPatterns;
1744 wchar_t const * lTmpWChar;
1748 lFilterPatterns = (
wchar_t * *) malloc(aNumOfFilterPatterns*
sizeof(
wchar_t *));
1749 for (i = 0; i < aNumOfFilterPatterns; i++)
1751 lFilterPatterns[
i] = utf8to16(aFilterPatterns[i]);
1754 lTitle = utf8to16(aTitle);
1755 lDefaultPathAndFile = utf8to16(aDefaultPathAndFile);
1756 lSingleFilterDescription = utf8to16(aSingleFilterDescription);
1758 lTmpWChar = tinyfd_openFileDialogW(
1760 lDefaultPathAndFile,
1761 aNumOfFilterPatterns,
1764 lSingleFilterDescription,
1765 aAllowMultipleSelects);
1768 free(lDefaultPathAndFile);
1769 free(lSingleFilterDescription);
1770 for (i = 0; i < aNumOfFilterPatterns; i++)
1772 free(lFilterPatterns[i]);
1774 free(lFilterPatterns);
1781 lTmpChar = utf16to8(lTmpWChar);
1782 strcpy(aoBuff, lTmpChar);
1788 #ifndef TINYFD_NOSELECTFOLDERWIN 1790 BOOL CALLBACK BrowseCallbackProc_enum(HWND hWndChild, LPARAM lParam)
1793 GetClassNameA(hWndChild, buf,
sizeof(buf));
1794 if (strcmp(buf,
"SysTreeView32") == 0) {
1795 HTREEITEM hNode = TreeView_GetSelection(hWndChild);
1796 TreeView_EnsureVisible(hWndChild, hNode);
1804 BOOL CALLBACK BrowseCallbackProcW_enum(HWND hWndChild, LPARAM lParam)
1807 GetClassNameW(hWndChild, buf,
sizeof(buf));
1808 if (wcscmp(buf, L
"SysTreeView32") == 0) {
1809 HTREEITEM hNode = TreeView_GetSelection(hWndChild);
1810 TreeView_EnsureVisible(hWndChild, hNode);
1816 static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
1819 case BFFM_INITIALIZED:
1820 SendMessage(hwnd, BFFM_SETSELECTION,
TRUE, pData);
1822 case BFFM_SELCHANGED:
1823 EnumChildWindows(hwnd, BrowseCallbackProc_enum, 0);
1829 static int __stdcall BrowseCallbackProcW(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
1832 case BFFM_INITIALIZED:
1833 SendMessage(hwnd, BFFM_SETSELECTIONW,
TRUE, (LPARAM)pData);
1835 case BFFM_SELCHANGED:
1836 EnumChildWindows(hwnd, BrowseCallbackProcW_enum, 0);
1841 wchar_t const * tinyfd_selectFolderDialogW(
1842 wchar_t const *
const aTitle,
1843 wchar_t const *
const aDefaultPath)
1849 LPITEMIDLIST lpItem;
1852 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return (
wchar_t const *)1; }
1854 lHResult = CoInitializeEx(
NULL, COINIT_APARTMENTTHREADED);
1856 bInfo.hwndOwner = GetForegroundWindow();
1857 bInfo.pidlRoot =
NULL;
1858 bInfo.pszDisplayName = lBuff;
1859 bInfo.lpszTitle = aTitle && wcslen(aTitle) ? aTitle :
NULL;
1860 if (lHResult == S_OK || lHResult == S_FALSE)
1862 bInfo.ulFlags = BIF_USENEWUI;
1864 bInfo.lpfn = BrowseCallbackProcW;
1865 bInfo.lParam = (LPARAM)aDefaultPath;
1868 lpItem = SHBrowseForFolderW(&bInfo);
1875 SHGetPathFromIDListW(lpItem, lBuff);
1879 if (lHResult == S_OK || lHResult == S_FALSE)
1887 static char const * selectFolderDialogWinGui8(
1888 char *
const aoBuff ,
1889 char const *
const aTitle ,
1890 char const *
const aDefaultPath )
1893 wchar_t * lDefaultPath;
1894 wchar_t const * lTmpWChar;
1897 lTitle = utf8to16(aTitle);
1898 lDefaultPath = utf8to16(aDefaultPath);
1900 lTmpWChar = tinyfd_selectFolderDialogW(
1911 lTmpChar = utf16to8(lTmpWChar);
1912 strcpy(aoBuff, lTmpChar);
1920 wchar_t const * tinyfd_colorChooserW(
1921 wchar_t const *
const aTitle,
1922 wchar_t const *
const aDefaultHexRGB,
1923 unsigned char const aDefaultRGB[3],
1924 unsigned char aoResultRGB[3])
1926 static wchar_t lResultHexRGB[8];
1928 COLORREF crCustColors[16];
1929 unsigned char lDefaultRGB[3];
1934 if (aTitle&&!wcscmp(aTitle, L
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows_wchar");
return (
wchar_t const *)1; }
1936 lHResult = CoInitializeEx(
NULL, 0);
1940 Hex2RGBW(aDefaultHexRGB, lDefaultRGB);
1944 lDefaultRGB[0] = aDefaultRGB[0];
1945 lDefaultRGB[1] = aDefaultRGB[1];
1946 lDefaultRGB[2] = aDefaultRGB[2];
1950 cc.lStructSize =
sizeof(CHOOSECOLOR);
1951 cc.hwndOwner = GetForegroundWindow();
1952 cc.hInstance =
NULL;
1953 cc.rgbResult = RGB(lDefaultRGB[0], lDefaultRGB[1], lDefaultRGB[2]);
1954 cc.lpCustColors = crCustColors;
1955 cc.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR ;
1958 cc.lpTemplateName =
NULL;
1960 lRet = ChooseColorW(&cc);
1967 aoResultRGB[0] = GetRValue(cc.rgbResult);
1968 aoResultRGB[1] = GetGValue(cc.rgbResult);
1969 aoResultRGB[2] = GetBValue(cc.rgbResult);
1971 RGB2HexW(aoResultRGB, lResultHexRGB);
1973 if (lHResult == S_OK || lHResult == S_FALSE)
1978 return lResultHexRGB;
1982 static char const * colorChooserWinGui8(
1983 char const *
const aTitle,
1984 char const *
const aDefaultHexRGB,
1985 unsigned char const aDefaultRGB[3],
1986 unsigned char aoResultRGB[3])
1988 static char lResultHexRGB[8];
1991 wchar_t * lDefaultHexRGB;
1992 wchar_t const * lTmpWChar;
1995 lTitle = utf8to16(aTitle);
1996 lDefaultHexRGB = utf8to16(aDefaultHexRGB);
1998 lTmpWChar = tinyfd_colorChooserW(
2005 free(lDefaultHexRGB);
2011 lTmpChar = utf16to8(lTmpWChar);
2012 strcpy(lResultHexRGB, lTmpChar);
2015 return lResultHexRGB;
2019 static int messageBoxWinGuiA(
2020 char const *
const aTitle ,
2021 char const *
const aMessage ,
2022 char const *
const aDialogType ,
2023 char const *
const aIconType ,
2024 int const aDefaultButton )
2026 int lBoxReturnValue;
2029 if ( aIconType && ! strcmp(
"warning" , aIconType ) )
2031 aCode = MB_ICONWARNING ;
2033 else if ( aIconType && ! strcmp(
"error", aIconType))
2035 aCode = MB_ICONERROR ;
2037 else if ( aIconType && ! strcmp(
"question", aIconType))
2039 aCode = MB_ICONQUESTION ;
2043 aCode = MB_ICONINFORMATION ;
2046 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
2048 aCode += MB_OKCANCEL ;
2049 if ( ! aDefaultButton )
2051 aCode += MB_DEFBUTTON2 ;
2054 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
2057 if ( ! aDefaultButton )
2059 aCode += MB_DEFBUTTON2 ;
2062 else if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
2064 aCode += MB_YESNOCANCEL;
2065 if (!aDefaultButton)
2067 aCode += MB_DEFBUTTON3;
2069 else if (aDefaultButton == 2)
2071 aCode += MB_DEFBUTTON2;
2079 aCode += MB_TOPMOST;
2081 lBoxReturnValue = MessageBoxA(GetForegroundWindow(), aMessage, aTitle, aCode);
2083 if (((aDialogType && !strcmp(
"yesnocancel", aDialogType))
2084 && (lBoxReturnValue == IDNO)))
2089 if ( ( ( aDialogType
2090 && strcmp(
"yesnocancel", aDialogType)
2091 && strcmp(
"okcancel", aDialogType)
2092 && strcmp(
"yesno", aDialogType)))
2093 || (lBoxReturnValue == IDOK)
2094 || (lBoxReturnValue == IDYES) )
2105 static char const * saveFileDialogWinGuiA(
2106 char *
const aoBuff ,
2107 char const *
const aTitle ,
2108 char const *
const aDefaultPathAndFile ,
2109 int const aNumOfFilterPatterns ,
2110 char const *
const *
const aFilterPatterns ,
2111 char const *
const aSingleFilterDescription )
2120 char const * ldefExt =
NULL;
2121 OPENFILENAMEA ofn = { 0 };
2123 lHResult = CoInitializeEx(
NULL,0);
2128 if (aNumOfFilterPatterns > 0)
2130 ldefExt = aFilterPatterns[0];
2132 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
2134 strcpy(lFilterPatterns, aSingleFilterDescription);
2135 strcat(lFilterPatterns,
"\n");
2137 strcat(lFilterPatterns, aFilterPatterns[0]);
2138 for (i = 1; i < aNumOfFilterPatterns; i++)
2140 strcat(lFilterPatterns,
";");
2141 strcat(lFilterPatterns, aFilterPatterns[i]);
2143 strcat(lFilterPatterns,
"\n");
2144 if ( ! (aSingleFilterDescription && strlen(aSingleFilterDescription) ) )
2146 strcpy(lDialogString, lFilterPatterns);
2147 strcat(lFilterPatterns, lDialogString);
2149 strcat(lFilterPatterns,
"All Files\n*.*\n");
2150 p = lFilterPatterns;
2151 while ((p = strchr(p,
'\n')) !=
NULL)
2158 ofn.lStructSize =
sizeof(OPENFILENAME) ;
2159 ofn.hwndOwner = GetForegroundWindow();
2161 ofn.lpstrFilter = lFilterPatterns && strlen(lFilterPatterns) ? lFilterPatterns :
NULL;
2162 ofn.lpstrCustomFilter =
NULL ;
2163 ofn.nMaxCustFilter = 0 ;
2164 ofn.nFilterIndex = 1 ;
2165 ofn.lpstrFile = aoBuff;
2168 ofn.lpstrFileTitle =
NULL ;
2170 ofn.lpstrInitialDir = lDirname && strlen(lDirname) ? lDirname :
NULL;
2171 ofn.lpstrTitle = aTitle && strlen(aTitle) ? aTitle :
NULL;
2172 ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR ;
2173 ofn.nFileOffset = 0 ;
2174 ofn.nFileExtension = 0 ;
2175 ofn.lpstrDefExt = ldefExt;
2176 ofn.lCustData = 0L ;
2177 ofn.lpfnHook =
NULL ;
2178 ofn.lpTemplateName =
NULL ;
2180 if ( GetSaveFileNameA ( & ofn ) == 0 )
2189 if (lHResult==S_OK || lHResult==S_FALSE)
2197 static char const * openFileDialogWinGuiA(
2198 char *
const aoBuff ,
2199 char const *
const aTitle ,
2200 char const *
const aDefaultPathAndFile ,
2201 int const aNumOfFilterPatterns ,
2202 char const *
const *
const aFilterPatterns ,
2203 char const *
const aSingleFilterDescription ,
2204 int const aAllowMultipleSelects )
2216 OPENFILENAMEA ofn = {0};
2218 lHResult = CoInitializeEx(
NULL,0);
2223 if (aNumOfFilterPatterns > 0)
2225 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
2227 strcpy(lFilterPatterns, aSingleFilterDescription);
2228 strcat(lFilterPatterns,
"\n");
2230 strcat(lFilterPatterns, aFilterPatterns[0]);
2231 for (i = 1; i < aNumOfFilterPatterns; i++)
2233 strcat(lFilterPatterns,
";");
2234 strcat(lFilterPatterns, aFilterPatterns[i]);
2236 strcat(lFilterPatterns,
"\n");
2237 if ( ! (aSingleFilterDescription && strlen(aSingleFilterDescription) ) )
2239 strcpy(lDialogString, lFilterPatterns);
2240 strcat(lFilterPatterns, lDialogString);
2242 strcat(lFilterPatterns,
"All Files\n*.*\n");
2243 p = lFilterPatterns;
2244 while ((p = strchr(p,
'\n')) !=
NULL)
2251 ofn.lStructSize =
sizeof( OPENFILENAME ) ;
2252 ofn.hwndOwner = GetForegroundWindow();
2254 ofn.lpstrFilter = lFilterPatterns && strlen(lFilterPatterns) ? lFilterPatterns :
NULL;
2255 ofn.lpstrCustomFilter =
NULL ;
2256 ofn.nMaxCustFilter = 0 ;
2257 ofn.nFilterIndex = 1 ;
2258 ofn.lpstrFile = aoBuff ;
2260 ofn.lpstrFileTitle =
NULL ;
2262 ofn.lpstrInitialDir = lDirname && strlen(lDirname) ? lDirname :
NULL;
2263 ofn.lpstrTitle = aTitle && strlen(aTitle) ? aTitle :
NULL;
2264 ofn.Flags = OFN_EXPLORER | OFN_NOCHANGEDIR ;
2265 ofn.nFileOffset = 0 ;
2266 ofn.nFileExtension = 0 ;
2267 ofn.lpstrDefExt =
NULL ;
2268 ofn.lCustData = 0L ;
2269 ofn.lpfnHook =
NULL ;
2270 ofn.lpTemplateName =
NULL ;
2272 if ( aAllowMultipleSelects )
2274 ofn.Flags |= OFN_ALLOWMULTISELECT;
2277 if ( GetOpenFileNameA( & ofn ) == 0 )
2283 lBuffLen = strlen(aoBuff) ;
2284 lPointers[0] = aoBuff + lBuffLen + 1 ;
2285 if ( !aAllowMultipleSelects || (lPointers[0][0] ==
'\0') )
2294 lLengths[
i] = strlen(lPointers[i]);
2295 lPointers[i+1] = lPointers[
i] + lLengths[
i] + 1 ;
2298 while ( lPointers[i][0] !=
'\0' );
2302 for ( j = i ; j >=0 ; j-- )
2305 memmove(p, lPointers[j], lLengths[j]);
2309 memmove(p, aoBuff, lBuffLen);
2318 if (lHResult==S_OK || lHResult==S_FALSE)
2325 #ifndef TINYFD_NOSELECTFOLDERWIN 2326 static char const * selectFolderDialogWinGuiA(
2327 char *
const aoBuff ,
2328 char const *
const aTitle ,
2329 char const *
const aDefaultPath )
2332 LPITEMIDLIST lpItem ;
2334 char * lRetval =
NULL ;
2336 lHResult = CoInitializeEx(
NULL, COINIT_APARTMENTTHREADED);
2339 bInfo.hwndOwner = GetForegroundWindow();
2340 bInfo.pidlRoot =
NULL ;
2341 bInfo.pszDisplayName = aoBuff ;
2342 bInfo.lpszTitle = aTitle && strlen(aTitle) ? aTitle :
NULL;
2343 if (lHResult == S_OK || lHResult == S_FALSE)
2345 bInfo.ulFlags = BIF_USENEWUI;
2347 bInfo.lpfn = BrowseCallbackProc;
2348 bInfo.lParam = (LPARAM)aDefaultPath;
2351 lpItem = SHBrowseForFolderA( & bInfo ) ;
2354 SHGetPathFromIDListA( lpItem , aoBuff ) ;
2358 if (lHResult==S_OK || lHResult==S_FALSE)
2367 static char const * colorChooserWinGuiA(
2368 char const *
const aTitle,
2369 char const *
const aDefaultHexRGB,
2370 unsigned char const aDefaultRGB[3],
2371 unsigned char aoResultRGB[3])
2373 static char lResultHexRGB[8];
2376 COLORREF crCustColors[16];
2377 unsigned char lDefaultRGB[3];
2380 if ( aDefaultHexRGB )
2382 Hex2RGB(aDefaultHexRGB, lDefaultRGB);
2386 lDefaultRGB[0]=aDefaultRGB[0];
2387 lDefaultRGB[1]=aDefaultRGB[1];
2388 lDefaultRGB[2]=aDefaultRGB[2];
2392 cc.lStructSize =
sizeof( CHOOSECOLOR ) ;
2393 cc.hwndOwner = GetForegroundWindow();
2394 cc.hInstance =
NULL ;
2395 cc.rgbResult = RGB(lDefaultRGB[0], lDefaultRGB[1], lDefaultRGB[2]);
2396 cc.lpCustColors = crCustColors;
2397 cc.Flags = CC_RGBINIT | CC_FULLOPEN;
2400 cc.lpTemplateName =
NULL;
2402 lRet = ChooseColorA(&cc);
2409 aoResultRGB[0] = GetRValue(cc.rgbResult);
2410 aoResultRGB[1] = GetGValue(cc.rgbResult);
2411 aoResultRGB[2] = GetBValue(cc.rgbResult);
2413 RGB2Hex(aoResultRGB, lResultHexRGB);
2415 return lResultHexRGB;
2420 static int dialogPresent(
void)
2422 static int lDialogPresent = -1 ;
2425 char const * lString =
"dialog.exe";
2426 if ( lDialogPresent < 0 )
2428 if (!(lIn = _popen(
"where dialog.exe",
"r")))
2430 lDialogPresent = 0 ;
2433 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
2436 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
2438 lBuff[strlen( lBuff ) -1] =
'\0' ;
2440 if ( strcmp(lBuff+strlen(lBuff)-strlen(lString),lString) )
2442 lDialogPresent = 0 ;
2446 lDialogPresent = 1 ;
2449 return lDialogPresent;
2453 static int messageBoxWinConsole(
2454 char const *
const aTitle ,
2455 char const *
const aMessage ,
2456 char const *
const aDialogType ,
2457 char const *
const aIconType ,
2458 int const aDefaultButton )
2465 strcpy( lDialogString ,
"dialog " ) ;
2466 if ( aTitle && strlen(aTitle) )
2468 strcat(lDialogString,
"--title \"") ;
2469 strcat(lDialogString, aTitle) ;
2470 strcat(lDialogString,
"\" ") ;
2473 if ( aDialogType && ( !strcmp(
"okcancel" , aDialogType )
2474 || !strcmp(
"yesno", aDialogType) || !strcmp(
"yesnocancel", aDialogType) ) )
2476 strcat(lDialogString,
"--backtitle \"") ;
2477 strcat(lDialogString,
"tab: move focus") ;
2478 strcat(lDialogString,
"\" ") ;
2481 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
2483 if ( ! aDefaultButton )
2485 strcat( lDialogString ,
"--defaultno " ) ;
2487 strcat( lDialogString ,
2488 "--yes-label \"Ok\" --no-label \"Cancel\" --yesno " ) ;
2490 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
2492 if ( ! aDefaultButton )
2494 strcat( lDialogString ,
"--defaultno " ) ;
2496 strcat( lDialogString ,
"--yesno " ) ;
2498 else if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
2500 if (!aDefaultButton)
2502 strcat(lDialogString,
"--defaultno ");
2504 strcat(lDialogString,
"--menu ");
2508 strcat( lDialogString ,
"--msgbox " ) ;
2511 strcat( lDialogString ,
"\"" ) ;
2512 if ( aMessage && strlen(aMessage) )
2515 strcat(lDialogString, lBuff) ;
2518 strcat(lDialogString,
"\" ");
2520 if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
2522 strcat(lDialogString,
"0 60 0 Yes \"\" No \"\"");
2523 strcat(lDialogString,
"2>>");
2527 strcat(lDialogString,
"10 60");
2528 strcat(lDialogString,
" && echo 1 > ");
2531 strcpy(lDialogFile, getenv(
"USERPROFILE"));
2532 strcat(lDialogFile,
"\\AppData\\Local\\Temp\\tinyfd.txt");
2533 strcat(lDialogString, lDialogFile);
2536 system( lDialogString ) ;
2538 if (!(lIn = fopen(lDialogFile,
"r")))
2540 remove(lDialogFile);
2543 while (fgets(lBuff,
sizeof(lBuff), lIn) !=
NULL)
2546 remove(lDialogFile);
2547 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
2549 lBuff[strlen( lBuff ) -1] =
'\0' ;
2553 if ( ! strlen(lBuff) )
2558 if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
2560 if (lBuff[0] ==
'Y')
return 1;
2568 static char const * inputBoxWinConsole(
2569 char *
const aoBuff ,
2570 char const *
const aTitle ,
2571 char const *
const aMessage ,
2572 char const *
const aDefaultInput )
2579 strcpy(lDialogFile, getenv(
"USERPROFILE"));
2580 strcat(lDialogFile,
"\\AppData\\Local\\Temp\\tinyfd.txt");
2581 strcpy(lDialogString ,
"echo|set /p=1 >" ) ;
2582 strcat(lDialogString, lDialogFile);
2583 strcat( lDialogString ,
" & " ) ;
2585 strcat( lDialogString ,
"dialog " ) ;
2586 if ( aTitle && strlen(aTitle) )
2588 strcat(lDialogString,
"--title \"") ;
2589 strcat(lDialogString, aTitle) ;
2590 strcat(lDialogString,
"\" ") ;
2593 strcat(lDialogString,
"--backtitle \"") ;
2594 strcat(lDialogString,
"tab: move focus") ;
2595 if ( ! aDefaultInput )
2597 strcat(lDialogString,
" (sometimes nothing, no blink nor star, is shown in text field)") ;
2600 strcat(lDialogString,
"\" ") ;
2602 if ( ! aDefaultInput )
2604 strcat( lDialogString ,
"--insecure --passwordbox" ) ;
2608 strcat( lDialogString ,
"--inputbox" ) ;
2610 strcat( lDialogString ,
" \"" ) ;
2611 if ( aMessage && strlen(aMessage) )
2613 strcat(lDialogString, aMessage) ;
2615 strcat(lDialogString,
"\" 10 60 ") ;
2616 if ( aDefaultInput && strlen(aDefaultInput) )
2618 strcat(lDialogString,
"\"") ;
2619 strcat(lDialogString, aDefaultInput) ;
2620 strcat(lDialogString,
"\" ") ;
2623 strcat(lDialogString,
"2>>");
2624 strcpy(lDialogFile, getenv(
"USERPROFILE"));
2625 strcat(lDialogFile,
"\\AppData\\Local\\Temp\\tinyfd.txt");
2626 strcat(lDialogString, lDialogFile);
2627 strcat(lDialogString,
" || echo 0 > ");
2628 strcat(lDialogString, lDialogFile);
2631 system( lDialogString ) ;
2633 if (!(lIn = fopen(lDialogFile,
"r")))
2635 remove(lDialogFile);
2643 remove(lDialogFile);
2644 if ( aoBuff[strlen( aoBuff ) -1] ==
'\n' )
2646 aoBuff[strlen( aoBuff ) -1] =
'\0' ;
2651 lResult = strncmp( aoBuff ,
"1" , 1) ? 0 : 1 ;
2662 static char const * saveFileDialogWinConsole(
2663 char *
const aoBuff ,
2664 char const *
const aTitle ,
2665 char const *
const aDefaultPathAndFile )
2671 strcpy( lDialogString ,
"dialog " ) ;
2672 if ( aTitle && strlen(aTitle) )
2674 strcat(lDialogString,
"--title \"") ;
2675 strcat(lDialogString, aTitle) ;
2676 strcat(lDialogString,
"\" ") ;
2679 strcat(lDialogString,
"--backtitle \"") ;
2680 strcat(lDialogString,
2681 "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ;
2682 strcat(lDialogString,
"\" ") ;
2684 strcat( lDialogString ,
"--fselect \"" ) ;
2685 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
2688 strcpy(lPathAndFile, aDefaultPathAndFile);
2689 replaceChr( lPathAndFile ,
'\\' ,
'/' ) ;
2693 if ( ! strchr(lPathAndFile,
'/') )
2695 strcat(lDialogString,
"./") ;
2697 strcat(lDialogString, lPathAndFile) ;
2698 strcat(lDialogString,
"\" 0 60 2>");
2699 strcpy(lPathAndFile, getenv(
"USERPROFILE"));
2700 strcat(lPathAndFile,
"\\AppData\\Local\\Temp\\tinyfd.txt");
2701 strcat(lDialogString, lPathAndFile);
2704 system( lDialogString ) ;
2706 if (!(lIn = fopen(lPathAndFile,
"r")))
2708 remove(lPathAndFile);
2714 remove(lPathAndFile);
2715 replaceChr( aoBuff ,
'/' ,
'\\' ) ;
2718 if ( ! strlen(lDialogString) )
2726 static char const * openFileDialogWinConsole(
2727 char *
const aoBuff ,
2728 char const *
const aTitle ,
2729 char const *
const aDefaultPathAndFile ,
2730 int const aAllowMultipleSelects )
2736 strcpy( lDialogString ,
"dialog " ) ;
2737 if ( aTitle && strlen(aTitle) )
2739 strcat(lDialogString,
"--title \"") ;
2740 strcat(lDialogString, aTitle) ;
2741 strcat(lDialogString,
"\" ") ;
2744 strcat(lDialogString,
"--backtitle \"") ;
2745 strcat(lDialogString,
2746 "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ;
2747 strcat(lDialogString,
"\" ") ;
2749 strcat( lDialogString ,
"--fselect \"" ) ;
2750 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
2753 strcpy(lFilterPatterns, aDefaultPathAndFile);
2754 replaceChr( lFilterPatterns ,
'\\' ,
'/' ) ;
2758 if ( ! strchr(lFilterPatterns,
'/') )
2760 strcat(lDialogString,
"./") ;
2762 strcat(lDialogString, lFilterPatterns) ;
2763 strcat(lDialogString,
"\" 0 60 2>");
2764 strcpy(lFilterPatterns, getenv(
"USERPROFILE"));
2765 strcat(lFilterPatterns,
"\\AppData\\Local\\Temp\\tinyfd.txt");
2766 strcat(lDialogString, lFilterPatterns);
2769 system( lDialogString ) ;
2771 if (!(lIn = fopen(lFilterPatterns,
"r")))
2773 remove(lFilterPatterns);
2779 remove(lFilterPatterns);
2780 replaceChr( aoBuff ,
'/' ,
'\\' ) ;
2786 static char const * selectFolderDialogWinConsole(
2787 char *
const aoBuff ,
2788 char const *
const aTitle ,
2789 char const *
const aDefaultPath )
2795 strcpy( lDialogString ,
"dialog " ) ;
2796 if ( aTitle && strlen(aTitle) )
2798 strcat(lDialogString,
"--title \"") ;
2799 strcat(lDialogString, aTitle) ;
2800 strcat(lDialogString,
"\" ") ;
2803 strcat(lDialogString,
"--backtitle \"") ;
2804 strcat(lDialogString,
2805 "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ;
2806 strcat(lDialogString,
"\" ") ;
2808 strcat( lDialogString ,
"--dselect \"" ) ;
2809 if ( aDefaultPath && strlen(aDefaultPath) )
2812 strcpy(lString, aDefaultPath) ;
2814 replaceChr( lString ,
'\\' ,
'/' ) ;
2815 strcat(lDialogString, lString) ;
2820 strcat(lDialogString,
"./") ;
2822 strcat(lDialogString,
"\" 0 60 2>");
2823 strcpy(lString, getenv(
"USERPROFILE"));
2824 strcat(lString,
"\\AppData\\Local\\Temp\\tinyfd.txt");
2825 strcat(lDialogString, lString);
2828 system( lDialogString ) ;
2830 if (!(lIn = fopen(lString,
"r")))
2839 replaceChr( aoBuff ,
'/' ,
'\\' ) ;
2846 char const *
const aTitle ,
2847 char const *
const aMessage ,
2848 char const *
const aDialogType ,
2849 char const *
const aIconType ,
2850 int const aDefaultButton )
2854 #ifndef TINYFD_NOLIB 2856 && (!getenv(
"SSH_CLIENT") || getenv(
"DISPLAY")))
2858 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){ strcpy(
tinyfd_response,
"windows");
return 1; }
2861 return messageBoxWinGui8(
2862 aTitle, aMessage, aDialogType, aIconType, aDefaultButton);
2866 return messageBoxWinGuiA(
2867 aTitle, aMessage, aDialogType, aIconType, aDefaultButton);
2872 if ( dialogPresent() )
2874 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return 0;}
2875 return messageBoxWinConsole(
2876 aTitle,aMessage,aDialogType,aIconType,aDefaultButton);
2880 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return 0;}
2884 printf(
"\n\n%s\n",
gTitle);
2887 if ( aTitle && strlen(aTitle) )
2889 printf(
"\n%s\n\n", aTitle);
2891 if ( aDialogType && !strcmp(
"yesno",aDialogType) )
2895 if ( aMessage && strlen(aMessage) )
2897 printf(
"%s\n",aMessage);
2900 lChar = (char) tolower( _getch() ) ;
2903 while ( lChar !=
'y' && lChar !=
'n' ) ;
2904 return lChar ==
'y' ? 1 : 0 ;
2906 else if ( aDialogType && !strcmp(
"okcancel",aDialogType) )
2910 if ( aMessage && strlen(aMessage) )
2912 printf(
"%s\n",aMessage);
2914 printf(
"[O]kay/[C]ancel: ");
2915 lChar = (char) tolower( _getch() ) ;
2918 while ( lChar !=
'o' && lChar !=
'c' ) ;
2919 return lChar ==
'o' ? 1 : 0 ;
2921 else if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
2925 if (aMessage && strlen(aMessage))
2927 printf(
"%s\n", aMessage);
2929 printf(
"[Y]es/[N]o/[C]ancel: ");
2930 lChar = (char)tolower(_getch());
2932 }
while (lChar !=
'y' && lChar !=
'n' && lChar !=
'c');
2933 return (lChar ==
'y') ? 1 : (lChar ==
'n') ? 2 : 0 ;
2937 if ( aMessage && strlen(aMessage) )
2939 printf(
"%s\n\n",aMessage);
2941 printf(
"press enter to continue ");
2942 lChar = (char) _getch() ;
2952 char const *
const aTitle ,
2953 char const *
const aMessage ,
2954 char const *
const aIconType )
2956 #ifndef TINYFD_NOLIB 2958 GetConsoleWindow() ||
2960 && ( !getenv(
"SSH_CLIENT") || getenv(
"DISPLAY") ) )
2962 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"windows");
return 1;}
2963 return notifyWinGui(aTitle, aMessage, aIconType);
2975 char const *
const aTitle ,
2976 char const *
const aMessage ,
2977 char const *
const aDefaultInput )
2982 #ifndef TINYFD_NOLIB 2984 HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
2987 GetConsoleWindow() ||
2989 && ( !getenv(
"SSH_CLIENT") || getenv(
"DISPLAY") ) )
2991 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"windows");
return (
char const *)1;}
2993 return inputBoxWinGui(lBuff, aTitle, aMessage, aDefaultInput);
2997 if ( dialogPresent() )
2999 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
3001 return inputBoxWinConsole(lBuff,aTitle,aMessage,aDefaultInput);
3005 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return (
char const *)0;}
3010 printf(
"\n\n%s\n",
gTitle);
3013 if ( aTitle && strlen(aTitle) )
3015 printf(
"\n%s\n\n", aTitle);
3017 if ( aMessage && strlen(aMessage) )
3019 printf(
"%s\n",aMessage);
3021 printf(
"(ctrl-Z + enter to cancel): ");
3022 #ifndef TINYFD_NOLIB 3023 if ( ! aDefaultInput )
3025 GetConsoleMode(hStdin,&mode);
3026 SetConsoleMode(hStdin,mode & (~ENABLE_ECHO_INPUT) );
3034 #ifndef TINYFD_NOLIB 3035 if ( ! aDefaultInput )
3037 SetConsoleMode(hStdin,mode);
3042 if ( strchr(lBuff,27) )
3046 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
3048 lBuff[strlen( lBuff ) -1] =
'\0' ;
3056 char const *
const aTitle ,
3057 char const *
const aDefaultPathAndFile ,
3058 int const aNumOfFilterPatterns ,
3059 char const *
const *
const aFilterPatterns ,
3060 char const *
const aSingleFilterDescription )
3066 #ifndef TINYFD_NOLIB 3068 && ( !getenv(
"SSH_CLIENT") || getenv(
"DISPLAY") ) )
3070 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"windows");
return (
char const *)1;}
3073 p = saveFileDialogWinGui8(lBuff,
3074 aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription);
3078 p = saveFileDialogWinGuiA(lBuff,
3079 aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription);
3084 if ( dialogPresent() )
3086 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
3087 p = saveFileDialogWinConsole(lBuff,aTitle,aDefaultPathAndFile);
3091 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return (
char const *)0;}
3095 if ( ! p || ! strlen( p ) )
3100 if ( strlen( lString ) && !
dirExists( lString ) )
3115 char const *
const aTitle ,
3116 char const *
const aDefaultPathAndFile ,
3117 int const aNumOfFilterPatterns ,
3118 char const *
const *
const aFilterPatterns ,
3119 char const *
const aSingleFilterDescription ,
3120 int const aAllowMultipleSelects )
3124 #ifndef TINYFD_NOLIB 3126 && ( !getenv(
"SSH_CLIENT") || getenv(
"DISPLAY") ) )
3128 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"windows");
return (
char const *)1;}
3131 p = openFileDialogWinGui8(lBuff,
3132 aTitle, aDefaultPathAndFile, aNumOfFilterPatterns,
3133 aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects);
3137 p = openFileDialogWinGuiA(lBuff,
3138 aTitle, aDefaultPathAndFile, aNumOfFilterPatterns,
3139 aFilterPatterns, aSingleFilterDescription, aAllowMultipleSelects);
3144 if ( dialogPresent() )
3146 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
3147 p = openFileDialogWinConsole(lBuff,
3148 aTitle,aDefaultPathAndFile,aAllowMultipleSelects);
3152 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return (
char const *)0;}
3156 if ( ! p || ! strlen( p ) )
3160 if ( aAllowMultipleSelects && strchr(p,
'|') )
3174 char const *
const aTitle ,
3175 char const *
const aDefaultPath )
3179 #ifndef TINYFD_NOLIB 3181 && ( !getenv(
"SSH_CLIENT") || getenv(
"DISPLAY") ) )
3183 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"windows");
return (
char const *)1;}
3186 #ifndef TINYFD_NOSELECTFOLDERWIN 3187 p = selectFolderDialogWinGui8(lBuff, aTitle, aDefaultPath);
3191 p = selectFolderDialogWinGuiA(lBuff, aTitle, aDefaultPath);
3197 if ( dialogPresent() )
3199 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
3200 p = selectFolderDialogWinConsole(lBuff,aTitle,aDefaultPath);
3204 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return (
char const *)0;}
3208 if ( ! p || ! strlen( p ) || !
dirExists( p ) )
3221 char const *
const aTitle,
3222 char const *
const aDefaultHexRGB,
3223 unsigned char const aDefaultRGB[3],
3224 unsigned char aoResultRGB[3])
3226 char lDefaultHexRGB[8];
3227 char * lpDefaultHexRGB;
3231 #ifndef TINYFD_NOLIB 3233 && (!getenv(
"SSH_CLIENT") || getenv(
"DISPLAY")) )
3235 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"windows");
return (
char const *)1;}
3238 return colorChooserWinGui8(
3239 aTitle, aDefaultHexRGB, aDefaultRGB, aoResultRGB);
3243 return colorChooserWinGuiA(
3244 aTitle, aDefaultHexRGB, aDefaultRGB, aoResultRGB);
3249 if ( aDefaultHexRGB )
3251 lpDefaultHexRGB = (
char *) aDefaultHexRGB ;
3255 RGB2Hex( aDefaultRGB , lDefaultHexRGB ) ;
3256 lpDefaultHexRGB = (
char *) lDefaultHexRGB ;
3259 "Enter hex rgb color (i.e. #f5ca20)",lpDefaultHexRGB);
3260 if (aTitle&&!strcmp(aTitle,
"tinyfd_query"))
return p;
3262 if ( !p || (strlen(p) != 7) || (p[0] !=
'#') )
3266 for ( i = 1 ; i < 7 ; i ++ )
3268 if ( ! isxdigit( p[i] ) )
3286 static int lsIsDarwin = -1 ;
3287 struct utsname lUtsname ;
3288 if ( lsIsDarwin < 0 )
3290 lsIsDarwin = !uname(&lUtsname) && !strcmp(lUtsname.sysname,
"Darwin") ;
3299 if ( ! aDirPath || ! strlen( aDirPath ) )
3301 lDir = opendir( aDirPath ) ;
3317 strcat( lTestedString , aExecutable ) ;
3318 strcat( lTestedString,
" 2>/dev/null ");
3319 lIn = popen( lTestedString ,
"r" ) ;
3320 if ( ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
3321 && ( ! strchr( lBuff ,
':' ) )
3322 && ( strncmp(lBuff,
"no ", 3) ) )
3325 if (
tinyfd_verbose) printf(
"detectPresence %s %d\n", aExecutable, 1);
3331 if (
tinyfd_verbose) printf(
"detectPresence %s %d\n", aExecutable, 0);
3344 strcpy( lTestedString , aExecutable ) ;
3345 strcat( lTestedString ,
" --version" ) ;
3347 lIn = popen( lTestedString ,
"r" ) ;
3348 lTmp = fgets( lBuff ,
sizeof( lBuff ) , lIn ) ;
3351 lTmp += strcspn(lTmp,
"0123456789");
3359 static int lArray [3] ;
3363 lArray[0] = atoi( strtok(lTmp,
" ,.-") ) ;
3365 lArray[1] = atoi( strtok(0,
" ,.-") ) ;
3367 lArray[2] = atoi( strtok(0,
" ,.-") ) ;
3370 if ( !lArray[0] && !lArray[1] && !lArray[2] )
return NULL;
3380 lIn = popen( aCommand ,
"r" ) ;
3381 if ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) ==
NULL )
3397 static int lIsTerminalRunning = -1 ;
3398 if ( lIsTerminalRunning < 0 )
3400 lIsTerminalRunning = isatty(1);
3401 if (
tinyfd_verbose) printf(
"isTerminalRunning %d\n", lIsTerminalRunning );
3403 return lIsTerminalRunning;
3409 static char lDialogName[128] =
"*" ;
3410 if ( lDialogName[0] ==
'*' )
3412 if (
isDarwin() && * strcpy(lDialogName ,
"/opt/local/bin/dialog" )
3415 else if ( * strcpy(lDialogName ,
"dialog" )
3420 strcpy(lDialogName ,
"" );
3423 return lDialogName ;
3429 char const * lDialogName ;
3442 if ( ! strlen(lDialogName) || !(lVersion = (
char *)
getVersion(lDialogName)) )
return 0 ;
3445 strcpy(lBuff,lVersion);
3446 lMajor = atoi( strtok(lVersion,
" ,.-") ) ;
3448 lMinorP = strtok(0,
" ,.-abcdefghijklmnopqrstuvxyz");
3449 lMinor = atoi( lMinorP ) ;
3451 lDate = atoi( strtok(0,
" ,.-") ) ;
3452 if (lDate<0) lDate = - lDate;
3454 lLetter = lMinorP + strlen(lMinorP) ;
3455 strcpy(lVersion,lBuff);
3456 strtok(lLetter,
" ,.-");
3458 lResult = (lMajor > 0) || ( ( lMinor == 9 ) && (*lLetter ==
'b') && (lDate >= 20031126) );
3466 static int lWhiptailPresent = -1 ;
3467 if ( lWhiptailPresent < 0 )
3471 return lWhiptailPresent ;
3477 static char lTerminalName[128] =
"*" ;
3478 char lShellName[64] =
"*" ;
3481 if ( lTerminalName[0] ==
'*' )
3485 strcpy(lShellName ,
"bash -c " ) ;
3489 strcpy(lShellName ,
"sh -c " ) ;
3493 strcpy(lTerminalName ,
"" ) ;
3499 if ( * strcpy(lTerminalName ,
"/opt/X11/bin/xterm" )
3502 strcat(lTerminalName ,
" -fa 'DejaVu Sans Mono' -fs 10 -title tinyfiledialogs -e " ) ;
3503 strcat(lTerminalName , lShellName ) ;
3507 strcpy(lTerminalName ,
"" ) ;
3510 else if ( * strcpy(lTerminalName,
"xterm")
3513 strcat(lTerminalName ,
" -fa 'DejaVu Sans Mono' -fs 10 -title tinyfiledialogs -e " ) ;
3514 strcat(lTerminalName , lShellName ) ;
3516 else if ( * strcpy(lTerminalName,
"terminator")
3519 strcat(lTerminalName ,
" -x " ) ;
3520 strcat(lTerminalName , lShellName ) ;
3522 else if ( * strcpy(lTerminalName,
"lxterminal")
3525 strcat(lTerminalName ,
" -e " ) ;
3526 strcat(lTerminalName , lShellName ) ;
3528 else if ( * strcpy(lTerminalName,
"konsole")
3531 strcat(lTerminalName ,
" -e " ) ;
3532 strcat(lTerminalName , lShellName ) ;
3534 else if ( * strcpy(lTerminalName,
"kterm")
3537 strcat(lTerminalName ,
" -e " ) ;
3538 strcat(lTerminalName , lShellName ) ;
3540 else if ( * strcpy(lTerminalName,
"tilix")
3543 strcat(lTerminalName ,
" -e " ) ;
3544 strcat(lTerminalName , lShellName ) ;
3546 else if ( * strcpy(lTerminalName,
"xfce4-terminal")
3549 strcat(lTerminalName ,
" -x " ) ;
3550 strcat(lTerminalName , lShellName ) ;
3552 else if ( * strcpy(lTerminalName,
"mate-terminal")
3555 strcat(lTerminalName ,
" -x " ) ;
3556 strcat(lTerminalName , lShellName ) ;
3558 else if ( * strcpy(lTerminalName,
"Eterm")
3561 strcat(lTerminalName ,
" -e " ) ;
3562 strcat(lTerminalName , lShellName ) ;
3564 else if ( * strcpy(lTerminalName,
"evilvte")
3567 strcat(lTerminalName ,
" -e " ) ;
3568 strcat(lTerminalName , lShellName ) ;
3570 else if ( * strcpy(lTerminalName,
"pterm")
3573 strcat(lTerminalName ,
" -e " ) ;
3574 strcat(lTerminalName , lShellName ) ;
3576 else if ( * strcpy(lTerminalName,
"gnome-terminal")
3578 && ((lArray[0]<3) || (lArray[0]==3 && lArray[1]<=6)) )
3580 strcat(lTerminalName ,
" --disable-factory -x " ) ;
3581 strcat(lTerminalName , lShellName ) ;
3585 strcpy(lTerminalName ,
"" ) ;
3591 if ( strlen(lTerminalName) )
3593 return lTerminalName ;
3604 char const * lDialogName ;
3608 return lDialogName ;
3619 int lWhiptailPresent ;
3623 return lWhiptailPresent ;
3636 && ( getenv(
"DISPLAY")
3637 || (
isDarwin() && (!getenv(
"SSH_TTY") || getenv(
"DISPLAY") ) ) ) ;
3643 static int lPactlPresent = -1 ;
3644 if ( lPactlPresent < 0 )
3648 return lPactlPresent ;
3654 static int lSpeakertestPresent = -1 ;
3655 if ( lSpeakertestPresent < 0 )
3659 return lSpeakertestPresent ;
3665 static int lBeepexePresent = -1 ;
3666 if ( lBeepexePresent < 0 )
3670 return lBeepexePresent ;
3676 static int lXmessagePresent = -1 ;
3677 if ( lXmessagePresent < 0 )
3687 static int lGxmessagePresent = -1 ;
3688 if ( lGxmessagePresent < 0 )
3698 static int lGmessagePresent = -1 ;
3699 if ( lGmessagePresent < 0 )
3709 static int lNotifysendPresent = -1 ;
3710 if ( lNotifysendPresent < 0 )
3720 static int lPerlPresent = -1 ;
3724 if ( lPerlPresent < 0 )
3729 lIn = popen(
"perl -MNet::DBus -e \"Net::DBus->session->get_service('org.freedesktop.Notifications')\" 2>&1" ,
"r" ) ;
3730 if ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) ==
NULL )
3744 static int lAfplayPresent = -1 ;
3748 if ( lAfplayPresent < 0 )
3751 if ( lAfplayPresent )
3753 lIn = popen(
"test -e /System/Library/Sounds/Ping.aiff || echo Ping" ,
"r" ) ;
3754 if ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) ==
NULL )
3756 lAfplayPresent = 2 ;
3768 static int lXdialogPresent = -1 ;
3769 if ( lXdialogPresent < 0 )
3779 static int lGdialoglPresent = -1 ;
3780 if ( lGdialoglPresent < 0 )
3790 static int lOsascriptPresent = -1 ;
3791 if ( lOsascriptPresent < 0 )
3796 return lOsascriptPresent &&
graphicMode() && !getenv(
"SSH_TTY") ;
3802 static int lQarmaPresent = -1 ;
3803 if ( lQarmaPresent < 0 )
3813 static int lMatedialogPresent = -1 ;
3814 if ( lMatedialogPresent < 0 )
3824 static int lShellementaryPresent = -1 ;
3825 if ( lShellementaryPresent < 0 )
3827 lShellementaryPresent = 0 ;
3835 static int lZenityPresent = -1 ;
3836 if ( lZenityPresent < 0 )
3846 static int lZenity3Present = -1 ;
3851 if ( lZenity3Present < 0 )
3853 lZenity3Present = 0 ;
3856 lIn = popen(
"zenity --version" ,
"r" ) ;
3857 if ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
3859 if ( atoi(lBuff) >= 3 )
3861 lZenity3Present = 3 ;
3862 lIntTmp = atoi(strtok(lBuff,
".")+2 ) ;
3863 if ( lIntTmp >= 18 )
3865 lZenity3Present = 5 ;
3867 else if ( lIntTmp >= 10 )
3869 lZenity3Present = 4 ;
3872 else if ( ( atoi(lBuff) == 2 ) && ( atoi(strtok(lBuff,
".")+2 ) >= 32 ) )
3874 lZenity3Present = 2 ;
3887 static int lKdialogPresent = -1 ;
3892 if ( lKdialogPresent < 0 )
3896 lDesktop = getenv(
"XDG_SESSION_DESKTOP");
3897 if ( !lDesktop || ( strcmp(lDesktop,
"KDE") && strcmp(lDesktop,
"lxqt") ) )
3899 lKdialogPresent = 0 ;
3900 return lKdialogPresent ;
3905 if ( lKdialogPresent && !getenv(
"SSH_TTY") )
3907 lIn = popen(
"kdialog --attach 2>&1" ,
"r" ) ;
3908 if ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
3910 if ( ! strstr(
"Unknown" , lBuff ) )
3912 lKdialogPresent = 2 ;
3913 if (
tinyfd_verbose) printf(
"kdialog-attach %d\n", lKdialogPresent);
3918 if (lKdialogPresent == 2)
3920 lKdialogPresent = 1 ;
3921 lIn = popen(
"kdialog --passivepopup 2>&1" ,
"r" ) ;
3922 if ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
3924 if ( ! strstr(
"Unknown" , lBuff ) )
3926 lKdialogPresent = 2 ;
3927 if (
tinyfd_verbose) printf(
"kdialog-popup %d\n", lKdialogPresent);
3940 static int lOsx9orBetter = -1 ;
3945 if ( lOsx9orBetter < 0 )
3948 lIn = popen(
"osascript -e 'set osver to system version of (system info)'" ,
"r" ) ;
3949 if ( ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
3950 && ( 2 == sscanf(lBuff,
"%d.%d", &V, &v) ) )
3959 if (
tinyfd_verbose) printf(
"Osx10 = %d, %d = %s\n", lOsx9orBetter, V, lBuff) ;
3961 return lOsx9orBetter ;
3967 static int lPython2Present = -1 ;
3970 if ( lPython2Present < 0 )
3972 lPython2Present = 0 ;
3977 for ( i = 9 ; i >= 0 ; i -- )
3982 lPython2Present = 1;
3992 if (
tinyfd_verbose) printf(
"lPython2Present %d\n", lPython2Present) ;
3995 return lPython2Present ;
4001 static int lPython3Present = -1 ;
4004 if ( lPython3Present < 0 )
4006 lPython3Present = 0 ;
4011 for ( i = 9 ; i >= 0 ; i -- )
4016 lPython3Present = 1;
4026 if (
tinyfd_verbose) printf(
"lPython3Present %d\n", lPython3Present) ;
4029 return lPython3Present ;
4035 static int lTkinter2Present = -1 ;
4036 char lPythonCommand[256];
4037 char lPythonParams[256] =
4038 "-S -c \"try:\n\timport Tkinter;\nexcept:\n\tprint 0;\"";
4041 if ( lTkinter2Present < 0 )
4043 lTkinter2Present = 0 ;
4046 sprintf( lPythonCommand ,
"%s %s" ,
gPython2Name , lPythonParams ) ;
4047 lTkinter2Present =
tryCommand(lPythonCommand) ;
4049 if (
tinyfd_verbose) printf(
"lTkinter2Present %d\n", lTkinter2Present) ;
4057 static int lTkinter3Present = -1 ;
4058 char lPythonCommand[256];
4059 char lPythonParams[256] =
4060 "-S -c \"try:\n\timport tkinter;\nexcept:\n\tprint(0);\"";
4062 if ( lTkinter3Present < 0 )
4064 lTkinter3Present = 0 ;
4067 sprintf( lPythonCommand ,
"%s %s" ,
gPython3Name , lPythonParams ) ;
4068 lTkinter3Present =
tryCommand(lPythonCommand) ;
4070 if (
tinyfd_verbose) printf(
"lTkinter3Present %d\n", lTkinter3Present) ;
4078 static int lDbusPresent = -1 ;
4079 char lPythonCommand[256];
4080 char lPythonParams[256] =
4081 "-c \"try:\n\timport dbus;bus=dbus.SessionBus();\ 4082 notif=bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications');\ 4083 notify=dbus.Interface(notif,'org.freedesktop.Notifications');\nexcept:\n\tprint(0);\"";
4085 if ( lDbusPresent < 0 )
4091 sprintf( lPythonCommand ,
"%s %s" ,
gPythonName , lPythonParams ) ;
4098 sprintf( lPythonCommand ,
"%s %s" ,
gPythonName , lPythonParams ) ;
4112 if ( ( lIn = popen(
"pactl unload-module module-sine" ,
"r" ) ) )
4120 char lDialogString [256] ;
4127 strcpy( lDialogString ,
"afplay /System/Library/Sounds/Ping.aiff") ;
4131 strcpy( lDialogString ,
"osascript -e 'tell application \"System Events\" to beep'") ;
4138 strcpy( lDialogString ,
"thnum=$(pactl load-module module-sine frequency=440);sleep .3;pactl unload-module $thnum" ) ;
4143 strcpy( lDialogString ,
"( speaker-test -t sine -f 440 > /dev/tty )& pid=$!;sleep .3; kill -9 $pid" ) ;
4147 strcpy( lDialogString ,
"beep.exe 440 300" ) ;
4151 strcpy( lDialogString ,
"printf '\a' > /dev/tty" ) ;
4154 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
4156 if ( ( lIn = popen( lDialogString ,
"r" ) ) )
4163 signal(SIGINT, SIG_DFL);
4169 char const *
const aTitle ,
4170 char const *
const aMessage ,
4171 char const *
const aDialogType ,
4172 char const *
const aIconType ,
4173 int const aDefaultButton )
4176 char * lDialogString =
NULL ;
4177 char * lpDialogString;
4179 int lWasGraphicDialog = 0 ;
4183 struct termios infoOri;
4184 struct termios info;
4186 size_t lMessageLen ;
4190 lTitleLen = aTitle ? strlen(aTitle) : 0 ;
4191 lMessageLen = aMessage ? strlen(aMessage) : 0 ;
4192 if ( !aTitle || strcmp(aTitle,
"tinyfd_query") )
4194 lDialogString = (
char *) malloc(
MAX_PATH_OR_CMD + lTitleLen + lMessageLen );
4199 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return 1;}
4201 strcpy( lDialogString ,
"osascript ");
4202 if ( !
osx9orBetter() ) strcat( lDialogString ,
" -e 'tell application \"System Events\"' -e 'Activate'");
4203 strcat( lDialogString ,
" -e 'try' -e 'set {vButton} to {button returned} of ( display dialog \"") ;
4204 if ( aMessage && strlen(aMessage) )
4206 strcat(lDialogString, aMessage) ;
4208 strcat(lDialogString,
"\" ") ;
4209 if ( aTitle && strlen(aTitle) )
4211 strcat(lDialogString,
"with title \"") ;
4212 strcat(lDialogString, aTitle) ;
4213 strcat(lDialogString,
"\" ") ;
4215 strcat(lDialogString,
"with icon ") ;
4216 if ( aIconType && ! strcmp(
"error" , aIconType ) )
4218 strcat(lDialogString,
"stop " ) ;
4220 else if ( aIconType && ! strcmp(
"warning" , aIconType ) )
4222 strcat(lDialogString,
"caution " ) ;
4226 strcat(lDialogString,
"note " ) ;
4228 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
4230 if ( ! aDefaultButton )
4232 strcat( lDialogString ,
"default button \"Cancel\" " ) ;
4235 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
4237 strcat( lDialogString ,
"buttons {\"No\", \"Yes\"} " ) ;
4240 strcat( lDialogString ,
"default button \"Yes\" " ) ;
4244 strcat( lDialogString ,
"default button \"No\" " ) ;
4246 strcat( lDialogString ,
"cancel button \"No\"" ) ;
4248 else if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType ) )
4250 strcat( lDialogString ,
"buttons {\"No\", \"Yes\", \"Cancel\"} " ) ;
4251 switch (aDefaultButton)
4253 case 1: strcat( lDialogString ,
"default button \"Yes\" " ) ;
break;
4254 case 2: strcat( lDialogString ,
"default button \"No\" " ) ;
break;
4255 case 0: strcat( lDialogString ,
"default button \"Cancel\" " ) ;
break;
4257 strcat( lDialogString ,
"cancel button \"Cancel\"" ) ;
4261 strcat( lDialogString ,
"buttons {\"OK\"} " ) ;
4262 strcat( lDialogString ,
"default button \"OK\" " ) ;
4264 strcat( lDialogString,
")' ") ;
4266 strcat( lDialogString,
4267 "-e 'if vButton is \"Yes\" then' -e 'return 1'\ 4268 -e 'else if vButton is \"OK\" then' -e 'return 1'\ 4269 -e 'else if vButton is \"No\" then' -e 'return 2'\ 4270 -e 'else' -e 'return 0' -e 'end if' " );
4272 strcat( lDialogString,
"-e 'on error number -128' " ) ;
4273 strcat( lDialogString,
"-e '0' " );
4275 strcat( lDialogString,
"-e 'end try'") ;
4276 if ( !
osx9orBetter() ) strcat( lDialogString,
" -e 'end tell'") ;
4280 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return 1;}
4282 strcpy( lDialogString ,
"kdialog" ) ;
4285 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
4288 strcat( lDialogString ,
" --" ) ;
4289 if ( aDialogType && ( ! strcmp(
"okcancel" , aDialogType )
4290 || ! strcmp(
"yesno" , aDialogType ) || ! strcmp(
"yesnocancel" , aDialogType ) ) )
4292 if ( aIconType && ( ! strcmp(
"warning" , aIconType )
4293 || ! strcmp(
"error" , aIconType ) ) )
4295 strcat( lDialogString ,
"warning" ) ;
4297 if ( ! strcmp(
"yesnocancel" , aDialogType ) )
4299 strcat( lDialogString ,
"yesnocancel" ) ;
4303 strcat( lDialogString ,
"yesno" ) ;
4306 else if ( aIconType && ! strcmp(
"error" , aIconType ) )
4308 strcat( lDialogString ,
"error" ) ;
4310 else if ( aIconType && ! strcmp(
"warning" , aIconType ) )
4312 strcat( lDialogString ,
"sorry" ) ;
4316 strcat( lDialogString ,
"msgbox" ) ;
4318 strcat( lDialogString ,
" \"" ) ;
4321 strcat( lDialogString , aMessage ) ;
4323 strcat( lDialogString ,
"\"" ) ;
4324 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
4326 strcat( lDialogString ,
4327 " --yes-label Ok --no-label Cancel" ) ;
4329 if ( aTitle && strlen(aTitle) )
4331 strcat(lDialogString,
" --title \"") ;
4332 strcat(lDialogString, aTitle) ;
4333 strcat(lDialogString,
"\"") ;
4336 if ( ! strcmp(
"yesnocancel" , aDialogType ) )
4338 strcat( lDialogString ,
"; x=$? ;if [ $x = 0 ] ;then echo 1;elif [ $x = 1 ] ;then echo 2;else echo 0;fi");
4342 strcat( lDialogString ,
";if [ $? = 0 ];then echo 1;else echo 0;fi");
4349 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return 1;}
4350 strcpy( lDialogString ,
"szAnswer=$(zenity" ) ;
4353 strcat(lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
4358 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return 1;}
4359 strcpy( lDialogString ,
"szAnswer=$(matedialog" ) ;
4363 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return 1;}
4364 strcpy( lDialogString ,
"szAnswer=$(shellementary" ) ;
4368 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return 1;}
4369 strcpy( lDialogString ,
"szAnswer=$(qarma" ) ;
4370 if ( !getenv(
"SSH_TTY") )
4372 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
4375 strcat(lDialogString,
" --");
4377 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
4379 strcat( lDialogString ,
4380 "question --ok-label=Ok --cancel-label=Cancel" ) ;
4382 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
4384 strcat( lDialogString ,
"question" ) ;
4386 else if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType ) )
4388 strcat( lDialogString ,
"list --column \"\" --hide-header \"Yes\" \"No\"" ) ;
4390 else if ( aIconType && ! strcmp(
"error" , aIconType ) )
4392 strcat( lDialogString ,
"error" ) ;
4394 else if ( aIconType && ! strcmp(
"warning" , aIconType ) )
4396 strcat( lDialogString ,
"warning" ) ;
4400 strcat( lDialogString ,
"info" ) ;
4402 if ( aTitle && strlen(aTitle) )
4404 strcat(lDialogString,
" --title=\"") ;
4405 strcat(lDialogString, aTitle) ;
4406 strcat(lDialogString,
"\"") ;
4408 if ( aMessage && strlen(aMessage) )
4410 strcat(lDialogString,
" --no-wrap --text=\"") ;
4411 strcat(lDialogString, aMessage) ;
4412 strcat(lDialogString,
"\"") ;
4416 strcat( lDialogString ,
" --icon-name=dialog-" ) ;
4417 if ( aIconType && (! strcmp(
"question" , aIconType )
4418 || ! strcmp(
"error" , aIconType )
4419 || ! strcmp(
"warning" , aIconType ) ) )
4421 strcat( lDialogString , aIconType ) ;
4425 strcat( lDialogString ,
"information" ) ;
4429 if (
tinyfd_silent) strcat( lDialogString ,
" 2>/dev/null ");
4431 if ( ! strcmp(
"yesnocancel" , aDialogType ) )
4433 strcat( lDialogString ,
4434 ");if [ $? = 1 ];then echo 0;elif [ $szAnswer = \"No\" ];then echo 2;else echo 1;fi");
4438 strcat( lDialogString ,
");if [ $? = 0 ];then echo 1;else echo 0;fi");
4443 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python2-tkinter");
return 1;}
4448 strcat( lDialogString ,
" -i" ) ;
4451 strcat( lDialogString ,
4452 " -S -c \"import Tkinter,tkMessageBox;root=Tkinter.Tk();root.withdraw();");
4456 strcat( lDialogString ,
4457 "import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ 4458 frontmost of process \\\"Python\\\" to true' ''');");
4461 strcat( lDialogString ,
"res=tkMessageBox." ) ;
4462 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
4464 strcat( lDialogString ,
"askokcancel(" ) ;
4465 if ( aDefaultButton )
4467 strcat( lDialogString ,
"default=tkMessageBox.OK," ) ;
4471 strcat( lDialogString ,
"default=tkMessageBox.CANCEL," ) ;
4474 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
4476 strcat( lDialogString ,
"askyesno(" ) ;
4477 if ( aDefaultButton )
4479 strcat( lDialogString ,
"default=tkMessageBox.YES," ) ;
4483 strcat( lDialogString ,
"default=tkMessageBox.NO," ) ;
4486 else if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType ) )
4488 strcat( lDialogString ,
"askyesnocancel(" ) ;
4489 switch ( aDefaultButton )
4491 case 1: strcat( lDialogString ,
"default=tkMessageBox.YES," );
break;
4492 case 2: strcat( lDialogString ,
"default=tkMessageBox.NO," );
break;
4493 case 0: strcat( lDialogString ,
"default=tkMessageBox.CANCEL," );
break;
4498 strcat( lDialogString ,
"showinfo(" ) ;
4501 strcat( lDialogString ,
"icon='" ) ;
4502 if ( aIconType && (! strcmp(
"question" , aIconType )
4503 || ! strcmp(
"error" , aIconType )
4504 || ! strcmp(
"warning" , aIconType ) ) )
4506 strcat( lDialogString , aIconType ) ;
4510 strcat( lDialogString ,
"info" ) ;
4513 strcat(lDialogString,
"',") ;
4514 if ( aTitle && strlen(aTitle) )
4516 strcat(lDialogString,
"title='") ;
4517 strcat(lDialogString, aTitle) ;
4518 strcat(lDialogString,
"',") ;
4520 if ( aMessage && strlen(aMessage) )
4522 strcat(lDialogString,
"message='") ;
4523 lpDialogString = lDialogString + strlen(lDialogString);
4525 strcat(lDialogString,
"'") ;
4528 if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType ) )
4530 strcat(lDialogString,
");\n\ 4531 if res is None :\n\tprint 0\n\ 4532 elif res is False :\n\tprint 2\n\ 4533 else :\n\tprint 1\n\"" ) ;
4537 strcat(lDialogString,
");\n\ 4538 if res is False :\n\tprint 0\n\ 4539 else :\n\tprint 1\n\"" ) ;
4544 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python3-tkinter");
return 1;}
4547 strcat( lDialogString ,
4548 " -S -c \"import tkinter;from tkinter import messagebox;root=tkinter.Tk();root.withdraw();");
4550 strcat( lDialogString ,
"res=messagebox." ) ;
4551 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
4553 strcat( lDialogString ,
"askokcancel(" ) ;
4554 if ( aDefaultButton )
4556 strcat( lDialogString ,
"default=messagebox.OK," ) ;
4560 strcat( lDialogString ,
"default=messagebox.CANCEL," ) ;
4563 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
4565 strcat( lDialogString ,
"askyesno(" ) ;
4566 if ( aDefaultButton )
4568 strcat( lDialogString ,
"default=messagebox.YES," ) ;
4572 strcat( lDialogString ,
"default=messagebox.NO," ) ;
4575 else if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType ) )
4577 strcat( lDialogString ,
"askyesnocancel(" ) ;
4578 switch ( aDefaultButton )
4580 case 1: strcat( lDialogString ,
"default=messagebox.YES," );
break;
4581 case 2: strcat( lDialogString ,
"default=messagebox.NO," );
break;
4582 case 0: strcat( lDialogString ,
"default=messagebox.CANCEL," );
break;
4587 strcat( lDialogString ,
"showinfo(" ) ;
4590 strcat( lDialogString ,
"icon='" ) ;
4591 if ( aIconType && (! strcmp(
"question" , aIconType )
4592 || ! strcmp(
"error" , aIconType )
4593 || ! strcmp(
"warning" , aIconType ) ) )
4595 strcat( lDialogString , aIconType ) ;
4599 strcat( lDialogString ,
"info" ) ;
4602 strcat(lDialogString,
"',") ;
4603 if ( aTitle && strlen(aTitle) )
4605 strcat(lDialogString,
"title='") ;
4606 strcat(lDialogString, aTitle) ;
4607 strcat(lDialogString,
"',") ;
4609 if ( aMessage && strlen(aMessage) )
4611 strcat(lDialogString,
"message='") ;
4612 lpDialogString = lDialogString + strlen(lDialogString);
4614 strcat(lDialogString,
"'") ;
4617 if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType ) )
4619 strcat(lDialogString,
");\n\ 4620 if res is None :\n\tprint(0)\n\ 4621 elif res is False :\n\tprint(2)\n\ 4622 else :\n\tprint 1\n\"" ) ;
4626 strcat(lDialogString,
");\n\ 4627 if res is False :\n\tprint(0)\n\ 4628 else :\n\tprint(1)\n\"" ) ;
4635 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"gxmessage");
return 1;}
4636 strcpy( lDialogString ,
"gxmessage");
4640 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"gmessage");
return 1;}
4641 strcpy( lDialogString ,
"gmessage");
4645 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xmessage");
return 1;}
4646 strcpy( lDialogString ,
"xmessage");
4649 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType) )
4651 strcat( lDialogString ,
" -buttons Ok:1,Cancel:0");
4652 switch ( aDefaultButton )
4654 case 1: strcat( lDialogString ,
" -default Ok");
break;
4655 case 0: strcat( lDialogString ,
" -default Cancel");
break;
4658 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType) )
4660 strcat( lDialogString ,
" -buttons Yes:1,No:0");
4661 switch ( aDefaultButton )
4663 case 1: strcat( lDialogString ,
" -default Yes");
break;
4664 case 0: strcat( lDialogString ,
" -default No");
break;
4667 else if ( aDialogType && ! strcmp(
"yesnocancel" , aDialogType) )
4669 strcat( lDialogString ,
" -buttons Yes:1,No:2,Cancel:0");
4670 switch ( aDefaultButton )
4672 case 1: strcat( lDialogString ,
" -default Yes");
break;
4673 case 2: strcat( lDialogString ,
" -default No");
break;
4674 case 0: strcat( lDialogString ,
" -default Cancel");
break;
4679 strcat( lDialogString ,
" -buttons Ok:1");
4680 strcat( lDialogString ,
" -default Ok");
4683 strcat( lDialogString ,
" -center \"");
4684 if ( aMessage && strlen(aMessage) )
4686 strcat( lDialogString , aMessage ) ;
4688 strcat(lDialogString,
"\"" ) ;
4689 if ( aTitle && strlen(aTitle) )
4691 strcat( lDialogString ,
" -title \"");
4692 strcat( lDialogString , aTitle ) ;
4693 strcat( lDialogString,
"\"" ) ;
4695 strcat( lDialogString ,
" ; echo $? ");
4701 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"gdialog");
return 1;}
4702 lWasGraphicDialog = 1 ;
4703 strcpy( lDialogString ,
"(gdialog " ) ;
4707 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xdialog");
return 1;}
4708 lWasGraphicDialog = 1 ;
4709 strcpy( lDialogString ,
"(Xdialog " ) ;
4713 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return 0;}
4716 strcpy( lDialogString ,
"(dialog " ) ;
4722 strcat( lDialogString ,
"'(" ) ;
4724 strcat( lDialogString ,
" " ) ;
4729 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"whiptail");
return 0;}
4730 strcpy( lDialogString ,
"(whiptail " ) ;
4734 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"whiptail");
return 0;}
4737 strcat( lDialogString ,
"'(whiptail " ) ;
4740 if ( aTitle && strlen(aTitle) )
4742 strcat(lDialogString,
"--title \"") ;
4743 strcat(lDialogString, aTitle) ;
4744 strcat(lDialogString,
"\" ") ;
4749 if ( aDialogType && ( !strcmp(
"okcancel" , aDialogType ) || !strcmp(
"yesno" , aDialogType )
4750 || !strcmp(
"yesnocancel" , aDialogType ) ) )
4752 strcat(lDialogString,
"--backtitle \"") ;
4753 strcat(lDialogString,
"tab: move focus") ;
4754 strcat(lDialogString,
"\" ") ;
4758 if ( aDialogType && ! strcmp(
"okcancel" , aDialogType ) )
4760 if ( ! aDefaultButton )
4762 strcat( lDialogString ,
"--defaultno " ) ;
4764 strcat( lDialogString ,
4765 "--yes-label \"Ok\" --no-label \"Cancel\" --yesno " ) ;
4767 else if ( aDialogType && ! strcmp(
"yesno" , aDialogType ) )
4769 if ( ! aDefaultButton )
4771 strcat( lDialogString ,
"--defaultno " ) ;
4773 strcat( lDialogString ,
"--yesno " ) ;
4775 else if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
4777 if (!aDefaultButton)
4779 strcat(lDialogString,
"--defaultno ");
4781 strcat(lDialogString,
"--menu ");
4785 strcat( lDialogString ,
"--msgbox " ) ;
4788 strcat( lDialogString ,
"\"" ) ;
4789 if ( aMessage && strlen(aMessage) )
4791 strcat(lDialogString, aMessage) ;
4793 strcat(lDialogString,
"\" ");
4795 if ( lWasGraphicDialog )
4797 if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
4799 strcat(lDialogString,
"0 60 0 Yes \"\" No \"\") 2>/tmp/tinyfd.txt;\ 4800 if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ 4801 tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ;
4805 strcat(lDialogString,
4806 "10 60 ) 2>&1;if [ $? = 0 ];then echo 1;else echo 0;fi");
4811 if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
4813 strcat(lDialogString,
"0 60 0 Yes \"\" No \"\" >/dev/tty ) 2>/tmp/tinyfd.txt;\ 4814 if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ 4815 tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ;
4819 strcat(lDialogString,
" >/tmp/tinyfd0.txt';cat /tmp/tinyfd0.txt");
4823 strcat(lDialogString,
"; clear >/dev/tty") ;
4828 strcat(lDialogString,
"10 60 >/dev/tty) 2>&1;if [ $? = 0 ];");
4831 strcat( lDialogString ,
4832 "then\n\techo 1\nelse\n\techo 0\nfi >/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt");
4836 strcat(lDialogString,
4837 "then echo 1;else echo 0;fi;clear >/dev/tty");
4844 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return 0;}
4846 strcat( lDialogString ,
"'" ) ;
4850 strcat( lDialogString ,
"echo \"" ) ;
4851 strcat( lDialogString,
gTitle) ;
4852 strcat( lDialogString ,
"\";" ) ;
4853 strcat( lDialogString ,
"echo \"" ) ;
4855 strcat( lDialogString ,
"\";echo;echo;" ) ;
4857 if ( aTitle && strlen(aTitle) )
4859 strcat( lDialogString ,
"echo \"" ) ;
4860 strcat( lDialogString, aTitle) ;
4861 strcat( lDialogString ,
"\";echo;" ) ;
4863 if ( aMessage && strlen(aMessage) )
4865 strcat( lDialogString ,
"echo \"" ) ;
4866 strcat( lDialogString, aMessage) ;
4867 strcat( lDialogString ,
"\"; " ) ;
4869 if ( aDialogType && !strcmp(
"yesno",aDialogType) )
4871 strcat( lDialogString ,
"echo -n \"y/n: \"; " ) ;
4872 strcat( lDialogString ,
"stty sane -echo;" ) ;
4873 strcat( lDialogString ,
4874 "answer=$( while ! head -c 1 | grep -i [ny];do true ;done);");
4875 strcat( lDialogString ,
4876 "if echo \"$answer\" | grep -iq \"^y\";then\n");
4877 strcat( lDialogString ,
"\techo 1\nelse\n\techo 0\nfi" ) ;
4879 else if ( aDialogType && !strcmp(
"okcancel",aDialogType) )
4881 strcat( lDialogString ,
"echo -n \"[O]kay/[C]ancel: \"; " ) ;
4882 strcat( lDialogString ,
"stty sane -echo;" ) ;
4883 strcat( lDialogString ,
4884 "answer=$( while ! head -c 1 | grep -i [oc];do true ;done);");
4885 strcat( lDialogString ,
4886 "if echo \"$answer\" | grep -iq \"^o\";then\n");
4887 strcat( lDialogString ,
"\techo 1\nelse\n\techo 0\nfi" ) ;
4889 else if ( aDialogType && !strcmp(
"yesnocancel",aDialogType) )
4891 strcat( lDialogString ,
"echo -n \"[Y]es/[N]o/[C]ancel: \"; " ) ;
4892 strcat( lDialogString ,
"stty sane -echo;" ) ;
4893 strcat( lDialogString ,
4894 "answer=$( while ! head -c 1 | grep -i [nyc];do true ;done);");
4895 strcat( lDialogString ,
4896 "if echo \"$answer\" | grep -iq \"^y\";then\n\techo 1\n");
4897 strcat( lDialogString ,
"elif echo \"$answer\" | grep -iq \"^n\";then\n\techo 2\n" ) ;
4898 strcat( lDialogString ,
"else\n\techo 0\nfi" ) ;
4902 strcat(lDialogString ,
"echo -n \"press enter to continue \"; ");
4903 strcat( lDialogString ,
"stty sane -echo;" ) ;
4904 strcat( lDialogString ,
4905 "answer=$( while ! head -c 1;do true ;done);echo 1");
4907 strcat( lDialogString ,
4908 " >/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt");
4912 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python-dbus");
return 1;}
4914 strcat( lDialogString ,
" -c \"import dbus;bus=dbus.SessionBus();");
4915 strcat( lDialogString ,
"notif=bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications');" ) ;
4916 strcat( lDialogString ,
"notify=dbus.Interface(notif,'org.freedesktop.Notifications');" ) ;
4917 strcat( lDialogString ,
"notify.Notify('',0,'" ) ;
4918 if ( aIconType && strlen(aIconType) )
4920 strcat( lDialogString , aIconType ) ;
4922 strcat(lDialogString,
"','") ;
4923 if ( aTitle && strlen(aTitle) )
4925 strcat(lDialogString, aTitle) ;
4927 strcat(lDialogString,
"','") ;
4928 if ( aMessage && strlen(aMessage) )
4930 lpDialogString = lDialogString + strlen(lDialogString);
4933 strcat(lDialogString,
"','','',5000)\"") ;
4937 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"perl-dbus");
return 1;}
4939 sprintf( lDialogString ,
"perl -e \"use Net::DBus;\ 4940 my \\$sessionBus = Net::DBus->session;\ 4941 my \\$notificationsService = \\$sessionBus->get_service('org.freedesktop.Notifications');\ 4942 my \\$notificationsObject = \\$notificationsService->get_object('/org/freedesktop/Notifications',\ 4943 'org.freedesktop.Notifications');\ 4944 my \\$notificationId;\\$notificationId = \\$notificationsObject->Notify(shift, 0, '%s', '%s', '%s', [], {}, -1);\" ",
4945 aIconType?aIconType:
"", aTitle?aTitle:
"", aMessage?aMessage:
"" ) ;
4950 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"notifysend");
return 1;}
4951 strcpy( lDialogString ,
"notify-send" ) ;
4952 if ( aIconType && strlen(aIconType) )
4954 strcat( lDialogString ,
" -i '" ) ;
4955 strcat( lDialogString , aIconType ) ;
4956 strcat( lDialogString ,
"'" ) ;
4958 strcat( lDialogString ,
" \"" ) ;
4959 if ( aTitle && strlen(aTitle) )
4961 strcat(lDialogString, aTitle) ;
4962 strcat( lDialogString ,
" | " ) ;
4964 if ( aMessage && strlen(aMessage) )
4969 strcat(lDialogString, lBuff) ;
4971 strcat( lDialogString ,
"\"" ) ;
4975 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return 0;}
4979 printf(
"\n\n%s\n",
gTitle);
4982 if ( aTitle && strlen(aTitle) )
4984 printf(
"\n%s\n", aTitle);
4987 tcgetattr(0, &infoOri);
4988 tcgetattr(0, &info);
4989 info.c_lflag &= ~ICANON;
4990 info.c_cc[VMIN] = 1;
4991 info.c_cc[VTIME] = 0;
4992 tcsetattr(0, TCSANOW, &info);
4993 if ( aDialogType && !strcmp(
"yesno",aDialogType) )
4997 if ( aMessage && strlen(aMessage) )
4999 printf(
"\n%s\n",aMessage);
5001 printf(
"y/n: "); fflush(
stdout);
5002 lChar = tolower( getchar() ) ;
5005 while ( lChar !=
'y' && lChar !=
'n' );
5006 lResult = lChar ==
'y' ? 1 : 0 ;
5008 else if ( aDialogType && !strcmp(
"okcancel",aDialogType) )
5012 if ( aMessage && strlen(aMessage) )
5014 printf(
"\n%s\n",aMessage);
5016 printf(
"[O]kay/[C]ancel: "); fflush(
stdout);
5017 lChar = tolower( getchar() ) ;
5020 while ( lChar !=
'o' && lChar !=
'c' );
5021 lResult = lChar ==
'o' ? 1 : 0 ;
5023 else if ( aDialogType && !strcmp(
"yesnocancel",aDialogType) )
5027 if ( aMessage && strlen(aMessage) )
5029 printf(
"\n%s\n",aMessage);
5031 printf(
"[Y]es/[N]o/[C]ancel: "); fflush(
stdout);
5032 lChar = tolower( getchar() ) ;
5035 while ( lChar !=
'y' && lChar !=
'n' && lChar !=
'c' );
5036 lResult = (lChar ==
'y') ? 1 : (lChar ==
'n') ? 2 : 0 ;
5040 if ( aMessage && strlen(aMessage) )
5042 printf(
"\n%s\n\n",aMessage);
5044 printf(
"press enter to continue "); fflush(
stdout);
5049 tcsetattr(0, TCSANOW, &infoOri);
5050 free(lDialogString);
5054 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
5056 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
5058 free(lDialogString);
5061 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
5067 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
5069 lBuff[strlen( lBuff ) -1] =
'\0' ;
5073 if (aDialogType && !strcmp(
"yesnocancel", aDialogType))
5075 if ( lBuff[0]==
'1' )
5077 if ( !strcmp( lBuff+1 ,
"Yes" )) strcpy(lBuff,
"1");
5078 else if ( !strcmp( lBuff+1 ,
"No" )) strcpy(lBuff,
"2");
5083 lResult = !strcmp( lBuff ,
"2" ) ? 2 : !strcmp( lBuff ,
"1" ) ? 1 : 0;
5086 free(lDialogString);
5093 char const *
const aTitle ,
5094 char const *
const aMessage ,
5095 char const *
const aIconType )
5098 char * lDialogString =
NULL ;
5099 char * lpDialogString ;
5102 size_t lMessageLen ;
5104 if ( getenv(
"SSH_TTY") )
5109 lTitleLen = aTitle ? strlen(aTitle) : 0 ;
5110 lMessageLen = aMessage ? strlen(aMessage) : 0 ;
5111 if ( !aTitle || strcmp(aTitle,
"tinyfd_query") )
5113 lDialogString = (
char *) malloc(
MAX_PATH_OR_CMD + lTitleLen + lMessageLen );
5118 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return 1;}
5120 strcpy( lDialogString ,
"osascript ");
5121 if ( !
osx9orBetter() ) strcat( lDialogString ,
" -e 'tell application \"System Events\"' -e 'Activate'");
5122 strcat( lDialogString ,
" -e 'try' -e 'display notification \"") ;
5123 if ( aMessage && strlen(aMessage) )
5125 strcat(lDialogString, aMessage) ;
5127 strcat(lDialogString,
" \" ") ;
5128 if ( aTitle && strlen(aTitle) )
5130 strcat(lDialogString,
"with title \"") ;
5131 strcat(lDialogString, aTitle) ;
5132 strcat(lDialogString,
"\" ") ;
5135 strcat( lDialogString,
"' -e 'end try'") ;
5136 if ( !
osx9orBetter() ) strcat( lDialogString,
" -e 'end tell'") ;
5140 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return 1;}
5141 strcpy( lDialogString ,
"kdialog" ) ;
5143 if ( aIconType && strlen(aIconType) )
5145 strcat( lDialogString ,
" --icon '" ) ;
5146 strcat( lDialogString , aIconType ) ;
5147 strcat( lDialogString ,
"'" ) ;
5149 if ( aTitle && strlen(aTitle) )
5151 strcat( lDialogString ,
" --title \"" ) ;
5152 strcat( lDialogString , aTitle ) ;
5153 strcat( lDialogString ,
"\"" ) ;
5156 strcat( lDialogString ,
" --passivepopup" ) ;
5157 strcat( lDialogString ,
" \"" ) ;
5160 strcat( lDialogString , aMessage ) ;
5162 strcat( lDialogString ,
" \" 5" ) ;
5170 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return 1;}
5171 strcpy( lDialogString ,
"zenity" ) ;
5175 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return 1;}
5176 strcpy( lDialogString ,
"matedialog" ) ;
5180 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return 1;}
5181 strcpy( lDialogString ,
"shellementary" ) ;
5185 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return 1;}
5186 strcpy( lDialogString ,
"qarma" ) ;
5189 strcat( lDialogString ,
" --notification");
5191 if ( aIconType && strlen( aIconType ) )
5193 strcat( lDialogString ,
" --window-icon '");
5194 strcat( lDialogString , aIconType ) ;
5195 strcat( lDialogString ,
"'" ) ;
5198 strcat( lDialogString ,
" --text \"" ) ;
5199 if ( aTitle && strlen(aTitle) )
5201 strcat(lDialogString, aTitle) ;
5202 strcat(lDialogString,
"\n") ;
5204 if ( aMessage && strlen( aMessage ) )
5206 strcat( lDialogString , aMessage ) ;
5208 strcat( lDialogString ,
" \"" ) ;
5212 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"perl-dbus");
return 1;}
5213 sprintf( lDialogString ,
"perl -e \"use Net::DBus;\ 5214 my \\$sessionBus = Net::DBus->session;\ 5215 my \\$notificationsService = \\$sessionBus->get_service('org.freedesktop.Notifications');\ 5216 my \\$notificationsObject = \\$notificationsService->get_object('/org/freedesktop/Notifications',\ 5217 'org.freedesktop.Notifications');\ 5218 my \\$notificationId;\\$notificationId = \\$notificationsObject->Notify(shift, 0, '%s', '%s', '%s', [], {}, -1);\" ",
5219 aIconType?aIconType:
"", aTitle?aTitle:
"", aMessage?aMessage:
"" ) ;
5223 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python-dbus");
return 1;}
5225 strcat( lDialogString ,
" -c \"import dbus;bus=dbus.SessionBus();");
5226 strcat( lDialogString ,
"notif=bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications');" ) ;
5227 strcat( lDialogString ,
"notify=dbus.Interface(notif,'org.freedesktop.Notifications');" ) ;
5228 strcat( lDialogString ,
"notify.Notify('',0,'" ) ;
5229 if ( aIconType && strlen(aIconType) )
5231 strcat( lDialogString , aIconType ) ;
5233 strcat(lDialogString,
"','") ;
5234 if ( aTitle && strlen(aTitle) )
5236 strcat(lDialogString, aTitle) ;
5238 strcat(lDialogString,
"','") ;
5239 if ( aMessage && strlen(aMessage) )
5241 lpDialogString = lDialogString + strlen(lDialogString);
5244 strcat(lDialogString,
"','','',5000)\"") ;
5248 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"notifysend");
return 1;}
5249 strcpy( lDialogString ,
"notify-send" ) ;
5250 if ( aIconType && strlen(aIconType) )
5252 strcat( lDialogString ,
" -i '" ) ;
5253 strcat( lDialogString , aIconType ) ;
5254 strcat( lDialogString ,
"'" ) ;
5256 strcat( lDialogString ,
" \"" ) ;
5257 if ( aTitle && strlen(aTitle) )
5259 strcat(lDialogString, aTitle) ;
5260 strcat( lDialogString ,
" | " ) ;
5262 if ( aMessage && strlen(aMessage) )
5267 strcat(lDialogString, lBuff) ;
5269 strcat( lDialogString ,
"\"" ) ;
5276 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
5278 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
5280 free(lDialogString);
5285 free(lDialogString);
5292 char const *
const aTitle ,
5293 char const *
const aMessage ,
5294 char const *
const aDefaultInput )
5297 char * lDialogString =
NULL;
5298 char * lpDialogString;
5301 int lWasGdialog = 0 ;
5302 int lWasGraphicDialog = 0 ;
5304 int lWasBasicXterm = 0 ;
5305 struct termios oldt ;
5306 struct termios newt ;
5309 size_t lMessageLen ;
5313 lTitleLen = aTitle ? strlen(aTitle) : 0 ;
5314 lMessageLen = aMessage ? strlen(aMessage) : 0 ;
5315 if ( !aTitle || strcmp(aTitle,
"tinyfd_query") )
5317 lDialogString = (
char *) malloc(
MAX_PATH_OR_CMD + lTitleLen + lMessageLen );
5322 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return (
char const *)1;}
5323 strcpy( lDialogString ,
"osascript ");
5324 if ( !
osx9orBetter() ) strcat( lDialogString ,
" -e 'tell application \"System Events\"' -e 'Activate'");
5325 strcat( lDialogString ,
" -e 'try' -e 'display dialog \"") ;
5326 if ( aMessage && strlen(aMessage) )
5328 strcat(lDialogString, aMessage) ;
5330 strcat(lDialogString,
"\" ") ;
5331 strcat(lDialogString,
"default answer \"") ;
5332 if ( aDefaultInput && strlen(aDefaultInput) )
5334 strcat(lDialogString, aDefaultInput) ;
5336 strcat(lDialogString,
"\" ") ;
5337 if ( ! aDefaultInput )
5339 strcat(lDialogString,
"hidden answer true ") ;
5341 if ( aTitle && strlen(aTitle) )
5343 strcat(lDialogString,
"with title \"") ;
5344 strcat(lDialogString, aTitle) ;
5345 strcat(lDialogString,
"\" ") ;
5347 strcat(lDialogString,
"with icon note' ") ;
5348 strcat(lDialogString,
"-e '\"1\" & text returned of result' " );
5349 strcat(lDialogString,
"-e 'on error number -128' " ) ;
5350 strcat(lDialogString,
"-e '0' " );
5351 strcat(lDialogString,
"-e 'end try'") ;
5352 if ( !
osx9orBetter() ) strcat(lDialogString,
" -e 'end tell'") ;
5356 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return (
char const *)1;}
5357 strcpy( lDialogString ,
"szAnswer=$(kdialog" ) ;
5361 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
5364 if ( ! aDefaultInput )
5366 strcat(lDialogString,
" --password ") ;
5370 strcat(lDialogString,
" --inputbox ") ;
5373 strcat(lDialogString,
"\"") ;
5374 if ( aMessage && strlen(aMessage) )
5376 strcat(lDialogString, aMessage ) ;
5378 strcat(lDialogString ,
"\" \"" ) ;
5379 if ( aDefaultInput && strlen(aDefaultInput) )
5381 strcat(lDialogString, aDefaultInput ) ;
5383 strcat(lDialogString ,
"\"" ) ;
5384 if ( aTitle && strlen(aTitle) )
5386 strcat(lDialogString,
" --title \"") ;
5387 strcat(lDialogString, aTitle) ;
5388 strcat(lDialogString,
"\"") ;
5390 strcat( lDialogString ,
5391 ");if [ $? = 0 ];then echo 1$szAnswer;else echo 0$szAnswer;fi");
5397 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return (
char const *)1;}
5398 strcpy( lDialogString ,
"szAnswer=$(zenity" ) ;
5401 strcat( lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
5406 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return (
char const *)1;}
5407 strcpy( lDialogString ,
"szAnswer=$(matedialog" ) ;
5411 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return (
char const *)1;}
5412 strcpy( lDialogString ,
"szAnswer=$(shellementary" ) ;
5416 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return (
char const *)1;}
5417 strcpy( lDialogString ,
"szAnswer=$(qarma" ) ;
5418 if ( !getenv(
"SSH_TTY") )
5420 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
5423 strcat( lDialogString ,
" --entry" ) ;
5425 if ( aTitle && strlen(aTitle) )
5427 strcat(lDialogString,
" --title=\"") ;
5428 strcat(lDialogString, aTitle) ;
5429 strcat(lDialogString,
"\"") ;
5431 if ( aMessage && strlen(aMessage) )
5433 strcat(lDialogString,
" --text=\"") ;
5434 strcat(lDialogString, aMessage) ;
5435 strcat(lDialogString,
"\"") ;
5437 if ( aDefaultInput && strlen(aDefaultInput) )
5439 strcat(lDialogString,
" --entry-text=\"") ;
5440 strcat(lDialogString, aDefaultInput) ;
5441 strcat(lDialogString,
"\"") ;
5445 strcat(lDialogString,
" --hide-text") ;
5447 if (
tinyfd_silent) strcat( lDialogString ,
" 2>/dev/null ");
5448 strcat( lDialogString ,
5449 ");if [ $? = 0 ];then echo 1$szAnswer;else echo 0$szAnswer;fi");
5454 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"gxmessage");
return (
char const *)1;}
5455 strcpy( lDialogString ,
"szAnswer=$(gxmessage -buttons Ok:1,Cancel:0 -center \"");
5459 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"gmessage");
return (
char const *)1;}
5460 strcpy( lDialogString ,
"szAnswer=$(gmessage -buttons Ok:1,Cancel:0 -center \"");
5463 if ( aMessage && strlen(aMessage) )
5465 strcat( lDialogString , aMessage ) ;
5467 strcat(lDialogString,
"\"" ) ;
5468 if ( aTitle && strlen(aTitle) )
5470 strcat( lDialogString ,
" -title \"");
5471 strcat( lDialogString , aTitle ) ;
5472 strcat(lDialogString,
"\" " ) ;
5474 strcat(lDialogString,
" -entrytext \"" ) ;
5475 if ( aDefaultInput && strlen(aDefaultInput) )
5477 strcat( lDialogString , aDefaultInput ) ;
5479 strcat(lDialogString,
"\"" ) ;
5480 strcat( lDialogString ,
");echo $?$szAnswer");
5484 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python2-tkinter");
return (
char const *)1;}
5488 strcat( lDialogString ,
" -i" ) ;
5491 strcat( lDialogString ,
5492 " -S -c \"import Tkinter,tkSimpleDialog;root=Tkinter.Tk();root.withdraw();");
5496 strcat( lDialogString ,
5497 "import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ 5498 frontmost of process \\\"Python\\\" to true' ''');");
5501 strcat( lDialogString ,
"res=tkSimpleDialog.askstring(" ) ;
5502 if ( aTitle && strlen(aTitle) )
5504 strcat(lDialogString,
"title='") ;
5505 strcat(lDialogString, aTitle) ;
5506 strcat(lDialogString,
"',") ;
5508 if ( aMessage && strlen(aMessage) )
5511 strcat(lDialogString,
"prompt='") ;
5512 lpDialogString = lDialogString + strlen(lDialogString);
5514 strcat(lDialogString,
"',") ;
5516 if ( aDefaultInput )
5518 if ( strlen(aDefaultInput) )
5520 strcat(lDialogString,
"initialvalue='") ;
5521 strcat(lDialogString, aDefaultInput) ;
5522 strcat(lDialogString,
"',") ;
5527 strcat(lDialogString,
"show='*'") ;
5529 strcat(lDialogString,
");\nif res is None :\n\tprint 0");
5530 strcat(lDialogString,
"\nelse :\n\tprint '1'+res\n\"" ) ;
5534 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python3-tkinter");
return (
char const *)1;}
5536 strcat( lDialogString ,
5537 " -S -c \"import tkinter; from tkinter import simpledialog;root=tkinter.Tk();root.withdraw();");
5538 strcat( lDialogString ,
"res=simpledialog.askstring(" ) ;
5539 if ( aTitle && strlen(aTitle) )
5541 strcat(lDialogString,
"title='") ;
5542 strcat(lDialogString, aTitle) ;
5543 strcat(lDialogString,
"',") ;
5545 if ( aMessage && strlen(aMessage) )
5548 strcat(lDialogString,
"prompt='") ;
5549 lpDialogString = lDialogString + strlen(lDialogString);
5551 strcat(lDialogString,
"',") ;
5553 if ( aDefaultInput )
5555 if ( strlen(aDefaultInput) )
5557 strcat(lDialogString,
"initialvalue='") ;
5558 strcat(lDialogString, aDefaultInput) ;
5559 strcat(lDialogString,
"',") ;
5564 strcat(lDialogString,
"show='*'") ;
5566 strcat(lDialogString,
");\nif res is None :\n\tprint(0)");
5567 strcat(lDialogString,
"\nelse :\n\tprint('1'+res)\n\"" ) ;
5573 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"gdialog");
return (
char const *)1;}
5574 lWasGraphicDialog = 1 ;
5576 strcpy( lDialogString ,
"(gdialog " ) ;
5580 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xdialog");
return (
char const *)1;}
5581 lWasGraphicDialog = 1 ;
5582 strcpy( lDialogString ,
"(Xdialog " ) ;
5586 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
5589 strcpy( lDialogString ,
"(dialog " ) ;
5595 strcat( lDialogString ,
"'(" ) ;
5597 strcat( lDialogString ,
" " ) ;
5602 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"whiptail");
return (
char const *)0;}
5603 strcpy( lDialogString ,
"(whiptail " ) ;
5607 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"whiptail");
return (
char const *)0;}
5610 strcat( lDialogString ,
"'(whiptail " ) ;
5613 if ( aTitle && strlen(aTitle) )
5615 strcat(lDialogString,
"--title \"") ;
5616 strcat(lDialogString, aTitle) ;
5617 strcat(lDialogString,
"\" ") ;
5622 strcat(lDialogString,
"--backtitle \"") ;
5623 strcat(lDialogString,
"tab: move focus") ;
5624 if ( ! aDefaultInput && !lWasGdialog )
5626 strcat(lDialogString,
" (sometimes nothing, no blink nor star, is shown in text field)") ;
5628 strcat(lDialogString,
"\" ") ;
5631 if ( aDefaultInput || lWasGdialog )
5633 strcat( lDialogString ,
"--inputbox" ) ;
5639 strcat( lDialogString ,
"--insecure " ) ;
5641 strcat( lDialogString ,
"--passwordbox" ) ;
5643 strcat( lDialogString ,
" \"" ) ;
5644 if ( aMessage && strlen(aMessage) )
5646 strcat(lDialogString, aMessage) ;
5648 strcat(lDialogString,
"\" 10 60 ") ;
5649 if ( aDefaultInput && strlen(aDefaultInput) )
5651 strcat(lDialogString,
"\"") ;
5652 strcat(lDialogString, aDefaultInput) ;
5653 strcat(lDialogString,
"\" ") ;
5655 if ( lWasGraphicDialog )
5657 strcat(lDialogString,
") 2>/tmp/tinyfd.txt;\ 5658 if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ 5659 tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ;
5663 strcat(lDialogString,
">/dev/tty ) 2>/tmp/tinyfd.txt;\ 5664 if [ $? = 0 ];then tinyfdBool=1;else tinyfdBool=0;fi;\ 5665 tinyfdRes=$(cat /tmp/tinyfd.txt);echo $tinyfdBool$tinyfdRes") ;
5669 strcat(lDialogString,
" >/tmp/tinyfd0.txt';cat /tmp/tinyfd0.txt");
5673 strcat(lDialogString,
"; clear >/dev/tty") ;
5679 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return (
char const *)0;}
5680 lWasBasicXterm = 1 ;
5682 strcat( lDialogString ,
"'" ) ;
5690 strcat( lDialogString ,
"echo \"" ) ;
5691 strcat( lDialogString, aTitle) ;
5692 strcat( lDialogString ,
"\";echo;" ) ;
5695 strcat( lDialogString ,
"echo \"" ) ;
5696 if ( aMessage && strlen(aMessage) )
5698 strcat( lDialogString, aMessage) ;
5700 strcat( lDialogString ,
"\";read " ) ;
5701 if ( ! aDefaultInput )
5703 strcat( lDialogString ,
"-s " ) ;
5705 strcat( lDialogString ,
"-p \"" ) ;
5706 strcat( lDialogString ,
"(esc+enter to cancel): \" ANSWER " ) ;
5707 strcat( lDialogString ,
";echo 1$ANSWER >/tmp/tinyfd.txt';" ) ;
5708 strcat( lDialogString ,
"cat -v /tmp/tinyfd.txt");
5713 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"no_solution");
return (
char const *)0;}
5718 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"basicinput");
return (
char const *)0;}
5724 if ( aTitle && strlen(aTitle) )
5726 printf(
"\n%s\n", aTitle);
5728 if ( aMessage && strlen(aMessage) )
5730 printf(
"\n%s\n",aMessage);
5732 printf(
"(esc+enter to cancel): "); fflush(
stdout);
5733 if ( ! aDefaultInput )
5735 tcgetattr(STDIN_FILENO, & oldt) ;
5737 newt.c_lflag &= ~ECHO ;
5738 tcsetattr(STDIN_FILENO, TCSANOW, & newt);
5743 if ( ! lEOF || (lBuff[0] ==
'\0') )
5745 free(lDialogString);
5749 if ( lBuff[0] ==
'\n' )
5753 if ( ! lEOF || (lBuff[0] ==
'\0') )
5755 free(lDialogString);
5760 if ( ! aDefaultInput )
5762 tcsetattr(STDIN_FILENO, TCSANOW, & oldt);
5766 if ( strchr(lBuff,27) )
5768 free(lDialogString);
5771 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
5773 lBuff[strlen( lBuff ) -1] =
'\0' ;
5775 free(lDialogString);
5779 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
5780 lIn = popen( lDialogString ,
"r" );
5786 remove(
"/tmp/tinyfd.txt");
5791 remove(
"/tmp/tinyfd0.txt");
5793 free(lDialogString);
5796 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
5804 remove(
"/tmp/tinyfd.txt");
5809 remove(
"/tmp/tinyfd0.txt");
5814 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
5816 lBuff[strlen( lBuff ) -1] =
'\0' ;
5819 if ( lWasBasicXterm )
5821 if ( strstr(lBuff,
"^[") )
5823 free(lDialogString);
5828 lResult = strncmp( lBuff ,
"1" , 1) ? 0 : 1 ;
5832 free(lDialogString);
5836 free(lDialogString);
5843 char const *
const aTitle ,
5844 char const *
const aDefaultPathAndFile ,
5845 int const aNumOfFilterPatterns ,
5846 char const *
const *
const aFilterPatterns ,
5847 char const *
const aSingleFilterDescription )
5854 int lWasGraphicDialog = 0 ;
5862 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return (
char const *)1;}
5863 strcpy( lDialogString ,
"osascript ");
5864 if ( !
osx9orBetter() ) strcat( lDialogString ,
" -e 'tell application \"Finder\"' -e 'Activate'");
5865 strcat( lDialogString ,
" -e 'try' -e 'POSIX path of ( choose file name " );
5866 if ( aTitle && strlen(aTitle) )
5868 strcat(lDialogString,
"with prompt \"") ;
5869 strcat(lDialogString, aTitle) ;
5870 strcat(lDialogString,
"\" ") ;
5873 if ( strlen(lString) )
5875 strcat(lDialogString,
"default location \"") ;
5876 strcat(lDialogString, lString ) ;
5877 strcat(lDialogString ,
"\" " ) ;
5880 if ( strlen(lString) )
5882 strcat(lDialogString,
"default name \"") ;
5883 strcat(lDialogString, lString ) ;
5884 strcat(lDialogString ,
"\" " ) ;
5886 strcat( lDialogString ,
")' " ) ;
5887 strcat(lDialogString,
"-e 'on error number -128' " ) ;
5888 strcat(lDialogString,
"-e 'end try'") ;
5889 if ( !
osx9orBetter() ) strcat( lDialogString,
" -e 'end tell'") ;
5893 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return (
char const *)1;}
5895 strcpy( lDialogString ,
"kdialog" ) ;
5898 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
5900 strcat( lDialogString ,
" --getsavefilename " ) ;
5902 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
5904 if ( aDefaultPathAndFile[0] !=
'/' )
5906 strcat(lDialogString,
"$PWD/") ;
5908 strcat(lDialogString,
"\"") ;
5909 strcat(lDialogString, aDefaultPathAndFile ) ;
5910 strcat(lDialogString ,
"\"" ) ;
5914 strcat(lDialogString,
"$PWD/") ;
5917 if ( aNumOfFilterPatterns > 0 )
5919 strcat(lDialogString ,
" \"" ) ;
5920 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
5922 strcat( lDialogString , aFilterPatterns [i] ) ;
5923 strcat( lDialogString ,
" " ) ;
5925 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
5927 strcat( lDialogString ,
" | " ) ;
5928 strcat( lDialogString , aSingleFilterDescription ) ;
5930 strcat( lDialogString ,
"\"" ) ;
5932 if ( aTitle && strlen(aTitle) )
5934 strcat(lDialogString,
" --title \"") ;
5935 strcat(lDialogString, aTitle) ;
5936 strcat(lDialogString,
"\"") ;
5943 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return (
char const *)1;}
5944 strcpy( lDialogString ,
"zenity" ) ;
5947 strcat( lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
5952 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return (
char const *)1;}
5953 strcpy( lDialogString ,
"matedialog" ) ;
5957 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return (
char const *)1;}
5958 strcpy( lDialogString ,
"shellementary" ) ;
5962 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return (
char const *)1;}
5963 strcpy( lDialogString ,
"qarma" ) ;
5964 if ( !getenv(
"SSH_TTY") )
5966 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
5969 strcat(lDialogString,
" --file-selection --save --confirm-overwrite" ) ;
5971 if ( aTitle && strlen(aTitle) )
5973 strcat(lDialogString,
" --title=\"") ;
5974 strcat(lDialogString, aTitle) ;
5975 strcat(lDialogString,
"\"") ;
5977 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
5979 strcat(lDialogString,
" --filename=\"") ;
5980 strcat(lDialogString, aDefaultPathAndFile) ;
5981 strcat(lDialogString,
"\"") ;
5983 if ( aNumOfFilterPatterns > 0 )
5985 strcat( lDialogString ,
" --file-filter='" ) ;
5986 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
5988 strcat( lDialogString , aSingleFilterDescription ) ;
5989 strcat( lDialogString ,
" | " ) ;
5991 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
5993 strcat( lDialogString , aFilterPatterns [i] ) ;
5994 strcat( lDialogString ,
" " ) ;
5996 strcat( lDialogString ,
"' --file-filter='All files | *'" ) ;
5998 if (
tinyfd_silent) strcat( lDialogString ,
" 2>/dev/null ");
6002 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python2-tkinter");
return (
char const *)1;}
6006 strcat( lDialogString ,
" -i" ) ;
6008 strcat( lDialogString ,
6009 " -S -c \"import Tkinter,tkFileDialog;root=Tkinter.Tk();root.withdraw();");
6013 strcat( lDialogString ,
6014 "import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set\ 6015 frontmost of process \\\"Python\\\" to true' ''');");
6018 strcat( lDialogString ,
"print tkFileDialog.asksaveasfilename(");
6019 if ( aTitle && strlen(aTitle) )
6021 strcat(lDialogString,
"title='") ;
6022 strcat(lDialogString, aTitle) ;
6023 strcat(lDialogString,
"',") ;
6025 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6028 if ( strlen(lString) )
6030 strcat(lDialogString,
"initialdir='") ;
6031 strcat(lDialogString, lString ) ;
6032 strcat(lDialogString ,
"'," ) ;
6035 if ( strlen(lString) )
6037 strcat(lDialogString,
"initialfile='") ;
6038 strcat(lDialogString, lString ) ;
6039 strcat(lDialogString ,
"'," ) ;
6042 if ( ( aNumOfFilterPatterns > 1 )
6043 || ( (aNumOfFilterPatterns == 1)
6044 && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] !=
'*' ) ) )
6046 strcat(lDialogString ,
"filetypes=(" ) ;
6047 strcat( lDialogString ,
"('" ) ;
6048 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
6050 strcat( lDialogString , aSingleFilterDescription ) ;
6052 strcat( lDialogString ,
"',(" ) ;
6053 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
6055 strcat( lDialogString ,
"'" ) ;
6056 strcat( lDialogString , aFilterPatterns [i] ) ;
6057 strcat( lDialogString ,
"'," ) ;
6059 strcat( lDialogString ,
"))," ) ;
6060 strcat( lDialogString ,
"('All files','*'))" ) ;
6062 strcat( lDialogString ,
")\"" ) ;
6066 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python3-tkinter");
return (
char const *)1;}
6068 strcat( lDialogString ,
6069 " -S -c \"import tkinter;from tkinter import filedialog;root=tkinter.Tk();root.withdraw();");
6070 strcat( lDialogString ,
"print( filedialog.asksaveasfilename(");
6071 if ( aTitle && strlen(aTitle) )
6073 strcat(lDialogString,
"title='") ;
6074 strcat(lDialogString, aTitle) ;
6075 strcat(lDialogString,
"',") ;
6077 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6080 if ( strlen(lString) )
6082 strcat(lDialogString,
"initialdir='") ;
6083 strcat(lDialogString, lString ) ;
6084 strcat(lDialogString ,
"'," ) ;
6087 if ( strlen(lString) )
6089 strcat(lDialogString,
"initialfile='") ;
6090 strcat(lDialogString, lString ) ;
6091 strcat(lDialogString ,
"'," ) ;
6094 if ( ( aNumOfFilterPatterns > 1 )
6095 || ( (aNumOfFilterPatterns == 1)
6096 && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] !=
'*' ) ) )
6098 strcat(lDialogString ,
"filetypes=(" ) ;
6099 strcat( lDialogString ,
"('" ) ;
6100 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
6102 strcat( lDialogString , aSingleFilterDescription ) ;
6104 strcat( lDialogString ,
"',(" ) ;
6105 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
6107 strcat( lDialogString ,
"'" ) ;
6108 strcat( lDialogString , aFilterPatterns [i] ) ;
6109 strcat( lDialogString ,
"'," ) ;
6111 strcat( lDialogString ,
"))," ) ;
6112 strcat( lDialogString ,
"('All files','*'))" ) ;
6114 strcat( lDialogString ,
"))\"" ) ;
6120 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xdialog");
return (
char const *)1;}
6121 lWasGraphicDialog = 1 ;
6122 strcpy( lDialogString ,
"(Xdialog " ) ;
6126 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
6127 strcpy( lDialogString ,
"(dialog " ) ;
6131 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
6134 strcat( lDialogString ,
"'(" ) ;
6136 strcat( lDialogString ,
" " ) ;
6139 if ( aTitle && strlen(aTitle) )
6141 strcat(lDialogString,
"--title \"") ;
6142 strcat(lDialogString, aTitle) ;
6143 strcat(lDialogString,
"\" ") ;
6148 strcat(lDialogString,
"--backtitle \"") ;
6149 strcat(lDialogString,
6150 "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ;
6151 strcat(lDialogString,
"\" ") ;
6154 strcat( lDialogString ,
"--fselect \"" ) ;
6155 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6157 if ( ! strchr(aDefaultPathAndFile,
'/') )
6159 strcat(lDialogString,
"./") ;
6161 strcat(lDialogString, aDefaultPathAndFile) ;
6165 strcat(lDialogString, getenv(
"HOME")) ;
6166 strcat(lDialogString,
"/") ;
6170 strcat(lDialogString,
"./") ;
6173 if ( lWasGraphicDialog )
6175 strcat(lDialogString,
"\" 0 60 ) 2>&1 ") ;
6179 strcat(lDialogString,
"\" 0 60 >/dev/tty) ") ;
6182 strcat( lDialogString ,
6183 "2>/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt");
6187 strcat(lDialogString,
"2>&1 ; clear >/dev/tty") ;
6196 if ( strlen( lString ) && !
dirExists( lString ) )
6201 if ( ! strlen(lString) )
6208 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
6209 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
6213 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
6216 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
6218 lBuff[strlen( lBuff ) -1] =
'\0' ;
6221 if ( ! strlen(lBuff) )
6226 if ( strlen( lString ) && !
dirExists( lString ) )
6241 char const *
const aTitle ,
6242 char const *
const aDefaultPathAndFile ,
6243 int const aNumOfFilterPatterns ,
6244 char const *
const *
const aFilterPatterns ,
6245 char const *
const aSingleFilterDescription ,
6246 int const aAllowMultipleSelects )
6255 int lWasKdialog = 0 ;
6256 int lWasGraphicDialog = 0 ;
6262 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return (
char const *)1;}
6263 strcpy( lDialogString ,
"osascript ");
6264 if ( !
osx9orBetter() ) strcat( lDialogString ,
" -e 'tell application \"System Events\"' -e 'Activate'");
6265 strcat( lDialogString ,
" -e 'try' -e '" );
6266 if ( ! aAllowMultipleSelects )
6270 strcat( lDialogString ,
"POSIX path of ( " );
6274 strcat( lDialogString ,
"set mylist to " );
6276 strcat( lDialogString ,
"choose file " );
6277 if ( aTitle && strlen(aTitle) )
6279 strcat(lDialogString,
"with prompt \"") ;
6280 strcat(lDialogString, aTitle) ;
6281 strcat(lDialogString,
"\" ") ;
6284 if ( strlen(lString) )
6286 strcat(lDialogString,
"default location \"") ;
6287 strcat(lDialogString, lString ) ;
6288 strcat(lDialogString ,
"\" " ) ;
6290 if ( aNumOfFilterPatterns > 0 )
6292 strcat(lDialogString ,
"of type {\"" );
6293 strcat( lDialogString , aFilterPatterns [0] + 2 ) ;
6294 strcat( lDialogString ,
"\"" ) ;
6295 for ( i = 1 ; i < aNumOfFilterPatterns ; i ++ )
6297 strcat( lDialogString ,
",\"" ) ;
6298 strcat( lDialogString , aFilterPatterns [i] + 2) ;
6299 strcat( lDialogString ,
"\"" ) ;
6301 strcat( lDialogString ,
"} " ) ;
6303 if ( aAllowMultipleSelects )
6305 strcat( lDialogString ,
"multiple selections allowed true ' " ) ;
6306 strcat( lDialogString ,
6307 "-e 'set mystring to POSIX path of item 1 of mylist' " );
6308 strcat( lDialogString ,
6309 "-e 'repeat with i from 2 to the count of mylist' " );
6310 strcat( lDialogString ,
"-e 'set mystring to mystring & \"|\"' " );
6311 strcat( lDialogString ,
6312 "-e 'set mystring to mystring & POSIX path of item i of mylist' " );
6313 strcat( lDialogString ,
"-e 'end repeat' " );
6314 strcat( lDialogString ,
"-e 'mystring' " );
6318 strcat( lDialogString ,
")' " ) ;
6320 strcat(lDialogString,
"-e 'on error number -128' " ) ;
6321 strcat(lDialogString,
"-e 'end try'") ;
6322 if ( !
osx9orBetter() ) strcat( lDialogString,
" -e 'end tell'") ;
6326 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return (
char const *)1;}
6329 strcpy( lDialogString ,
"kdialog" ) ;
6332 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
6334 strcat( lDialogString ,
" --getopenfilename " ) ;
6336 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6338 if ( aDefaultPathAndFile[0] !=
'/' )
6340 strcat(lDialogString,
"$PWD/") ;
6342 strcat(lDialogString,
"\"") ;
6343 strcat(lDialogString, aDefaultPathAndFile ) ;
6344 strcat(lDialogString ,
"\"" ) ;
6348 strcat(lDialogString,
"$PWD/") ;
6351 if ( aNumOfFilterPatterns > 0 )
6353 strcat(lDialogString ,
" \"" ) ;
6354 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
6356 strcat( lDialogString , aFilterPatterns [i] ) ;
6357 strcat( lDialogString ,
" " ) ;
6359 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
6361 strcat( lDialogString ,
" | " ) ;
6362 strcat( lDialogString , aSingleFilterDescription ) ;
6364 strcat( lDialogString ,
"\"" ) ;
6366 if ( aAllowMultipleSelects )
6368 strcat( lDialogString ,
" --multiple --separate-output" ) ;
6370 if ( aTitle && strlen(aTitle) )
6372 strcat(lDialogString,
" --title \"") ;
6373 strcat(lDialogString, aTitle) ;
6374 strcat(lDialogString,
"\"") ;
6381 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return (
char const *)1;}
6382 strcpy( lDialogString ,
"zenity" ) ;
6385 strcat( lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
6390 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return (
char const *)1;}
6391 strcpy( lDialogString ,
"matedialog" ) ;
6395 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return (
char const *)1;}
6396 strcpy( lDialogString ,
"shellementary" ) ;
6400 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return (
char const *)1;}
6401 strcpy( lDialogString ,
"qarma" ) ;
6402 if ( !getenv(
"SSH_TTY") )
6404 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
6407 strcat( lDialogString ,
" --file-selection" ) ;
6409 if ( aAllowMultipleSelects )
6411 strcat( lDialogString ,
" --multiple" ) ;
6413 if ( aTitle && strlen(aTitle) )
6415 strcat(lDialogString,
" --title=\"") ;
6416 strcat(lDialogString, aTitle) ;
6417 strcat(lDialogString,
"\"") ;
6419 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6421 strcat(lDialogString,
" --filename=\"") ;
6422 strcat(lDialogString, aDefaultPathAndFile) ;
6423 strcat(lDialogString,
"\"") ;
6425 if ( aNumOfFilterPatterns > 0 )
6427 strcat( lDialogString ,
" --file-filter='" ) ;
6428 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
6430 strcat( lDialogString , aSingleFilterDescription ) ;
6431 strcat( lDialogString ,
" | " ) ;
6433 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
6435 strcat( lDialogString , aFilterPatterns [i] ) ;
6436 strcat( lDialogString ,
" " ) ;
6438 strcat( lDialogString ,
"' --file-filter='All files | *'" ) ;
6440 if (
tinyfd_silent) strcat( lDialogString ,
" 2>/dev/null ");
6444 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python2-tkinter");
return (
char const *)1;}
6448 strcat( lDialogString ,
" -i" ) ;
6450 strcat( lDialogString ,
6451 " -S -c \"import Tkinter,tkFileDialog;root=Tkinter.Tk();root.withdraw();");
6455 strcat( lDialogString ,
6456 "import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ 6457 frontmost of process \\\"Python\\\" to true' ''');");
6459 strcat( lDialogString ,
"lFiles=tkFileDialog.askopenfilename(");
6460 if ( aAllowMultipleSelects )
6462 strcat( lDialogString ,
"multiple=1," ) ;
6464 if ( aTitle && strlen(aTitle) )
6466 strcat(lDialogString,
"title='") ;
6467 strcat(lDialogString, aTitle) ;
6468 strcat(lDialogString,
"',") ;
6470 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6473 if ( strlen(lString) )
6475 strcat(lDialogString,
"initialdir='") ;
6476 strcat(lDialogString, lString ) ;
6477 strcat(lDialogString ,
"'," ) ;
6480 if ( strlen(lString) )
6482 strcat(lDialogString,
"initialfile='") ;
6483 strcat(lDialogString, lString ) ;
6484 strcat(lDialogString ,
"'," ) ;
6487 if ( ( aNumOfFilterPatterns > 1 )
6488 || ( ( aNumOfFilterPatterns == 1 )
6489 && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] !=
'*' ) ) )
6491 strcat(lDialogString ,
"filetypes=(" ) ;
6492 strcat( lDialogString ,
"('" ) ;
6493 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
6495 strcat( lDialogString , aSingleFilterDescription ) ;
6497 strcat( lDialogString ,
"',(" ) ;
6498 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
6500 strcat( lDialogString ,
"'" ) ;
6501 strcat( lDialogString , aFilterPatterns [i] ) ;
6502 strcat( lDialogString ,
"'," ) ;
6504 strcat( lDialogString ,
"))," ) ;
6505 strcat( lDialogString ,
"('All files','*'))" ) ;
6507 strcat( lDialogString ,
");\ 6508 \nif not isinstance(lFiles, tuple):\n\tprint lFiles\nelse:\ 6509 \n\tlFilesString=''\n\tfor lFile in lFiles:\n\t\tlFilesString+=str(lFile)+'|'\ 6510 \n\tprint lFilesString[:-1]\n\"" ) ;
6514 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python3-tkinter");
return (
char const *)1;}
6516 strcat( lDialogString ,
6517 " -S -c \"import tkinter;from tkinter import filedialog;root=tkinter.Tk();root.withdraw();");
6518 strcat( lDialogString ,
"lFiles=filedialog.askopenfilename(");
6519 if ( aAllowMultipleSelects )
6521 strcat( lDialogString ,
"multiple=1," ) ;
6523 if ( aTitle && strlen(aTitle) )
6525 strcat(lDialogString,
"title='") ;
6526 strcat(lDialogString, aTitle) ;
6527 strcat(lDialogString,
"',") ;
6529 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6532 if ( strlen(lString) )
6534 strcat(lDialogString,
"initialdir='") ;
6535 strcat(lDialogString, lString ) ;
6536 strcat(lDialogString ,
"'," ) ;
6539 if ( strlen(lString) )
6541 strcat(lDialogString,
"initialfile='") ;
6542 strcat(lDialogString, lString ) ;
6543 strcat(lDialogString ,
"'," ) ;
6546 if ( ( aNumOfFilterPatterns > 1 )
6547 || ( ( aNumOfFilterPatterns == 1 )
6548 && ( aFilterPatterns[0][strlen(aFilterPatterns[0])-1] !=
'*' ) ) )
6550 strcat(lDialogString ,
"filetypes=(" ) ;
6551 strcat( lDialogString ,
"('" ) ;
6552 if ( aSingleFilterDescription && strlen(aSingleFilterDescription) )
6554 strcat( lDialogString , aSingleFilterDescription ) ;
6556 strcat( lDialogString ,
"',(" ) ;
6557 for ( i = 0 ; i < aNumOfFilterPatterns ; i ++ )
6559 strcat( lDialogString ,
"'" ) ;
6560 strcat( lDialogString , aFilterPatterns [i] ) ;
6561 strcat( lDialogString ,
"'," ) ;
6563 strcat( lDialogString ,
"))," ) ;
6564 strcat( lDialogString ,
"('All files','*'))" ) ;
6566 strcat( lDialogString ,
");\ 6567 \nif not isinstance(lFiles, tuple):\n\tprint(lFiles)\nelse:\ 6568 \n\tlFilesString=''\n\tfor lFile in lFiles:\n\t\tlFilesString+=str(lFile)+'|'\ 6569 \n\tprint(lFilesString[:-1])\n\"" ) ;
6575 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xdialog");
return (
char const *)1;}
6576 lWasGraphicDialog = 1 ;
6577 strcpy( lDialogString ,
"(Xdialog " ) ;
6581 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
6582 strcpy( lDialogString ,
"(dialog " ) ;
6586 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
6589 strcat( lDialogString ,
"'(" ) ;
6591 strcat( lDialogString ,
" " ) ;
6594 if ( aTitle && strlen(aTitle) )
6596 strcat(lDialogString,
"--title \"") ;
6597 strcat(lDialogString, aTitle) ;
6598 strcat(lDialogString,
"\" ") ;
6603 strcat(lDialogString,
"--backtitle \"") ;
6604 strcat(lDialogString,
6605 "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ;
6606 strcat(lDialogString,
"\" ") ;
6609 strcat( lDialogString ,
"--fselect \"" ) ;
6610 if ( aDefaultPathAndFile && strlen(aDefaultPathAndFile) )
6612 if ( ! strchr(aDefaultPathAndFile,
'/') )
6614 strcat(lDialogString,
"./") ;
6616 strcat(lDialogString, aDefaultPathAndFile) ;
6620 strcat(lDialogString, getenv(
"HOME")) ;
6621 strcat(lDialogString,
"/");
6625 strcat(lDialogString,
"./") ;
6628 if ( lWasGraphicDialog )
6630 strcat(lDialogString,
"\" 0 60 ) 2>&1 ") ;
6634 strcat(lDialogString,
"\" 0 60 >/dev/tty) ") ;
6637 strcat( lDialogString ,
6638 "2>/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt");
6642 strcat(lDialogString,
"2>&1 ; clear >/dev/tty") ;
6657 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
6658 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
6664 while ( fgets( p ,
sizeof( lBuff ) , lIn ) !=
NULL )
6669 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
6671 lBuff[strlen( lBuff ) -1] =
'\0' ;
6674 if ( lWasKdialog && aAllowMultipleSelects )
6677 while ( ( p = strchr( p ,
'\n' ) ) )
6681 if ( ! strlen( lBuff ) )
6685 if ( aAllowMultipleSelects && strchr(lBuff,
'|') )
6704 char const *
const aTitle ,
6705 char const *
const aDefaultPath )
6711 int lWasGraphicDialog = 0 ;
6717 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return (
char const *)1;}
6718 strcpy( lDialogString ,
"osascript ");
6719 if ( !
osx9orBetter() ) strcat( lDialogString ,
" -e 'tell application \"System Events\"' -e 'Activate'");
6720 strcat( lDialogString ,
" -e 'try' -e 'POSIX path of ( choose folder ");
6721 if ( aTitle && strlen(aTitle) )
6723 strcat(lDialogString,
"with prompt \"") ;
6724 strcat(lDialogString, aTitle) ;
6725 strcat(lDialogString,
"\" ") ;
6727 if ( aDefaultPath && strlen(aDefaultPath) )
6729 strcat(lDialogString,
"default location \"") ;
6730 strcat(lDialogString, aDefaultPath ) ;
6731 strcat(lDialogString ,
"\" " ) ;
6733 strcat( lDialogString ,
")' " ) ;
6734 strcat(lDialogString,
"-e 'on error number -128' " ) ;
6735 strcat(lDialogString,
"-e 'end try'") ;
6736 if ( !
osx9orBetter() ) strcat( lDialogString,
" -e 'end tell'") ;
6740 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return (
char const *)1;}
6741 strcpy( lDialogString ,
"kdialog" ) ;
6744 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
6746 strcat( lDialogString ,
" --getexistingdirectory " ) ;
6748 if ( aDefaultPath && strlen(aDefaultPath) )
6750 if ( aDefaultPath[0] !=
'/' )
6752 strcat(lDialogString,
"$PWD/") ;
6754 strcat(lDialogString,
"\"") ;
6755 strcat(lDialogString, aDefaultPath ) ;
6756 strcat(lDialogString ,
"\"" ) ;
6760 strcat(lDialogString,
"$PWD/") ;
6763 if ( aTitle && strlen(aTitle) )
6765 strcat(lDialogString,
" --title \"") ;
6766 strcat(lDialogString, aTitle) ;
6767 strcat(lDialogString,
"\"") ;
6774 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return (
char const *)1;}
6775 strcpy( lDialogString ,
"zenity" ) ;
6778 strcat( lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
6783 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return (
char const *)1;}
6784 strcpy( lDialogString ,
"matedialog" ) ;
6788 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return (
char const *)1;}
6789 strcpy( lDialogString ,
"shellementary" ) ;
6793 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return (
char const *)1;}
6794 strcpy( lDialogString ,
"qarma" ) ;
6795 if ( !getenv(
"SSH_TTY") )
6797 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
6800 strcat( lDialogString ,
" --file-selection --directory" ) ;
6802 if ( aTitle && strlen(aTitle) )
6804 strcat(lDialogString,
" --title=\"") ;
6805 strcat(lDialogString, aTitle) ;
6806 strcat(lDialogString,
"\"") ;
6808 if ( aDefaultPath && strlen(aDefaultPath) )
6810 strcat(lDialogString,
" --filename=\"") ;
6811 strcat(lDialogString, aDefaultPath) ;
6812 strcat(lDialogString,
"\"") ;
6814 if (
tinyfd_silent) strcat( lDialogString ,
" 2>/dev/null ");
6818 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python2-tkinter");
return (
char const *)1;}
6822 strcat( lDialogString ,
" -i" ) ;
6824 strcat( lDialogString ,
6825 " -S -c \"import Tkinter,tkFileDialog;root=Tkinter.Tk();root.withdraw();");
6829 strcat( lDialogString ,
6830 "import os;os.system('''/usr/bin/osascript -e 'tell app \\\"Finder\\\" to set \ 6831 frontmost of process \\\"Python\\\" to true' ''');");
6834 strcat( lDialogString ,
"print tkFileDialog.askdirectory(");
6835 if ( aTitle && strlen(aTitle) )
6837 strcat(lDialogString,
"title='") ;
6838 strcat(lDialogString, aTitle) ;
6839 strcat(lDialogString,
"',") ;
6841 if ( aDefaultPath && strlen(aDefaultPath) )
6843 strcat(lDialogString,
"initialdir='") ;
6844 strcat(lDialogString, aDefaultPath ) ;
6845 strcat(lDialogString ,
"'" ) ;
6847 strcat( lDialogString ,
")\"" ) ;
6851 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python3-tkinter");
return (
char const *)1;}
6853 strcat( lDialogString ,
6854 " -S -c \"import tkinter;from tkinter import filedialog;root=tkinter.Tk();root.withdraw();");
6855 strcat( lDialogString ,
"print( filedialog.askdirectory(");
6856 if ( aTitle && strlen(aTitle) )
6858 strcat(lDialogString,
"title='") ;
6859 strcat(lDialogString, aTitle) ;
6860 strcat(lDialogString,
"',") ;
6862 if ( aDefaultPath && strlen(aDefaultPath) )
6864 strcat(lDialogString,
"initialdir='") ;
6865 strcat(lDialogString, aDefaultPath ) ;
6866 strcat(lDialogString ,
"'" ) ;
6868 strcat( lDialogString ,
") )\"" ) ;
6874 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xdialog");
return (
char const *)1;}
6875 lWasGraphicDialog = 1 ;
6876 strcpy( lDialogString ,
"(Xdialog " ) ;
6880 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
6881 strcpy( lDialogString ,
"(dialog " ) ;
6885 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"dialog");
return (
char const *)0;}
6888 strcat( lDialogString ,
"'(" ) ;
6890 strcat( lDialogString ,
" " ) ;
6893 if ( aTitle && strlen(aTitle) )
6895 strcat(lDialogString,
"--title \"") ;
6896 strcat(lDialogString, aTitle) ;
6897 strcat(lDialogString,
"\" ") ;
6902 strcat(lDialogString,
"--backtitle \"") ;
6903 strcat(lDialogString,
6904 "tab: focus | /: populate | spacebar: fill text field | ok: TEXT FIELD ONLY") ;
6905 strcat(lDialogString,
"\" ") ;
6908 strcat( lDialogString ,
"--dselect \"" ) ;
6909 if ( aDefaultPath && strlen(aDefaultPath) )
6911 strcat(lDialogString, aDefaultPath) ;
6916 strcat(lDialogString, getenv(
"HOME")) ;
6917 strcat(lDialogString,
"/");
6921 strcat(lDialogString,
"./") ;
6924 if ( lWasGraphicDialog )
6926 strcat(lDialogString,
"\" 0 60 ) 2>&1 ") ;
6930 strcat(lDialogString,
"\" 0 60 >/dev/tty) ") ;
6933 strcat( lDialogString ,
6934 "2>/tmp/tinyfd.txt';cat /tmp/tinyfd.txt;rm /tmp/tinyfd.txt");
6938 strcat(lDialogString,
"2>&1 ; clear >/dev/tty") ;
6946 if ( !p || ! strlen( p ) || !
dirExists( p ) )
6952 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
6953 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
6957 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
6960 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
6962 lBuff[strlen( lBuff ) -1] =
'\0' ;
6965 if ( ! strlen( lBuff ) || !
dirExists( lBuff ) )
6978 char const *
const aTitle ,
6979 char const *
const aDefaultHexRGB ,
6980 unsigned char const aDefaultRGB[3] ,
6981 unsigned char aoResultRGB[3] )
6983 static char lBuff [128] ;
6986 char lDefaultHexRGB[8];
6987 char * lpDefaultHexRGB;
6988 unsigned char lDefaultRGB[3];
6992 int lWasZenity3 = 0 ;
6993 int lWasOsascript = 0 ;
6994 int lWasXdialog = 0 ;
6997 if ( aDefaultHexRGB )
6999 Hex2RGB( aDefaultHexRGB , lDefaultRGB ) ;
7000 lpDefaultHexRGB = (
char *) aDefaultHexRGB ;
7004 lDefaultRGB[0]=aDefaultRGB[0];
7005 lDefaultRGB[1]=aDefaultRGB[1];
7006 lDefaultRGB[2]=aDefaultRGB[2];
7007 RGB2Hex( aDefaultRGB , lDefaultHexRGB ) ;
7008 lpDefaultHexRGB = (
char *) lDefaultHexRGB ;
7013 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"applescript");
return (
char const *)1;}
7015 strcpy( lDialogString ,
"osascript");
7019 strcat( lDialogString ,
" -e 'tell application \"System Events\"' -e 'Activate'");
7020 strcat( lDialogString ,
" -e 'try' -e 'set mycolor to choose color default color {");
7024 strcat( lDialogString ,
7025 " -e 'try' -e 'tell app (path to frontmost application as Unicode text) \ 7026 to set mycolor to choose color default color {");
7029 sprintf(lTmp,
"%d", 256 * lDefaultRGB[0] ) ;
7030 strcat(lDialogString, lTmp ) ;
7031 strcat(lDialogString,
"," ) ;
7032 sprintf(lTmp,
"%d", 256 * lDefaultRGB[1] ) ;
7033 strcat(lDialogString, lTmp ) ;
7034 strcat(lDialogString,
"," ) ;
7035 sprintf(lTmp,
"%d", 256 * lDefaultRGB[2] ) ;
7036 strcat(lDialogString, lTmp ) ;
7037 strcat(lDialogString,
"}' " ) ;
7038 strcat( lDialogString ,
7039 "-e 'set mystring to ((item 1 of mycolor) div 256 as integer) as string' " );
7040 strcat( lDialogString ,
7041 "-e 'repeat with i from 2 to the count of mycolor' " );
7042 strcat( lDialogString ,
7043 "-e 'set mystring to mystring & \" \" & ((item i of mycolor) div 256 as integer) as string' " );
7044 strcat( lDialogString ,
"-e 'end repeat' " );
7045 strcat( lDialogString ,
"-e 'mystring' ");
7046 strcat(lDialogString,
"-e 'on error number -128' " ) ;
7047 strcat(lDialogString,
"-e 'end try'") ;
7048 if ( !
osx9orBetter() ) strcat( lDialogString,
" -e 'end tell'") ;
7052 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"kdialog");
return (
char const *)1;}
7053 strcpy( lDialogString ,
"kdialog" ) ;
7056 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
7058 sprintf( lDialogString + strlen(lDialogString) ,
" --getcolor --default '%s'" , lpDefaultHexRGB ) ;
7060 if ( aTitle && strlen(aTitle) )
7062 strcat(lDialogString,
" --title \"") ;
7063 strcat(lDialogString, aTitle) ;
7064 strcat(lDialogString,
"\"") ;
7072 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity3");
return (
char const *)1;}
7073 strcpy( lDialogString ,
"zenity" );
7076 strcat( lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
7081 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return (
char const *)1;}
7082 strcpy( lDialogString ,
"matedialog" ) ;
7086 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return (
char const *)1;}
7087 strcpy( lDialogString ,
"shellementary" ) ;
7091 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return (
char const *)1;}
7092 strcpy( lDialogString ,
"qarma" ) ;
7093 if ( !getenv(
"SSH_TTY") )
7095 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
7098 strcat( lDialogString ,
" --color-selection --show-palette" ) ;
7099 sprintf( lDialogString + strlen(lDialogString),
" --color=%s" , lpDefaultHexRGB ) ;
7101 if ( aTitle && strlen(aTitle) )
7103 strcat(lDialogString,
" --title=\"") ;
7104 strcat(lDialogString, aTitle) ;
7105 strcat(lDialogString,
"\"") ;
7107 if (
tinyfd_silent) strcat( lDialogString ,
" 2>/dev/null ");
7111 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"xdialog");
return (
char const *)1;}
7113 strcpy( lDialogString ,
"Xdialog --colorsel \"" ) ;
7114 if ( aTitle && strlen(aTitle) )
7116 strcat(lDialogString, aTitle) ;
7118 strcat(lDialogString,
"\" 0 60 ") ;
7119 sprintf(lTmp,
"%hhu %hhu %hhu",lDefaultRGB[0],
7120 lDefaultRGB[1],lDefaultRGB[2]);
7121 strcat(lDialogString, lTmp) ;
7122 strcat(lDialogString,
" 2>&1");
7126 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python2-tkinter");
return (
char const *)1;}
7130 strcat( lDialogString ,
" -i" ) ;
7133 strcat( lDialogString ,
7134 " -S -c \"import Tkinter,tkColorChooser;root=Tkinter.Tk();root.withdraw();");
7138 strcat( lDialogString ,
7139 "import os;os.system('''osascript -e 'tell app \\\"Finder\\\" to set \ 7140 frontmost of process \\\"Python\\\" to true' ''');");
7143 strcat( lDialogString ,
"res=tkColorChooser.askcolor(color='" ) ;
7144 strcat(lDialogString, lpDefaultHexRGB ) ;
7145 strcat(lDialogString,
"'") ;
7148 if ( aTitle && strlen(aTitle) )
7150 strcat(lDialogString,
",title='") ;
7151 strcat(lDialogString, aTitle) ;
7152 strcat(lDialogString,
"'") ;
7154 strcat( lDialogString ,
");\ 7155 \nif res[1] is not None:\n\tprint res[1]\"" ) ;
7159 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"python3-tkinter");
return (
char const *)1;}
7161 strcat( lDialogString ,
7162 " -S -c \"import tkinter;from tkinter import colorchooser;root=tkinter.Tk();root.withdraw();");
7163 strcat( lDialogString ,
"res=colorchooser.askcolor(color='" ) ;
7164 strcat(lDialogString, lpDefaultHexRGB ) ;
7165 strcat(lDialogString,
"'") ;
7167 if ( aTitle && strlen(aTitle) )
7169 strcat(lDialogString,
",title='") ;
7170 strcat(lDialogString, aTitle) ;
7171 strcat(lDialogString,
"'") ;
7173 strcat( lDialogString ,
");\ 7174 \nif res[1] is not None:\n\tprint(res[1])\"" ) ;
7180 "Enter hex rgb color (i.e. #f5ca20)",lpDefaultHexRGB);
7181 if ( !p || (strlen(p) != 7) || (p[0] !=
'#') )
7185 for ( i = 1 ; i < 7 ; i ++ )
7187 if ( ! isxdigit( p[i] ) )
7196 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
7197 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
7201 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
7205 if ( ! strlen( lBuff ) )
7211 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
7213 lBuff[strlen( lBuff ) -1] =
'\0' ;
7218 if ( lBuff[0] ==
'#' )
7220 if ( strlen(lBuff)>7 )
7230 else if ( lBuff[3] ==
'(' ) {
7231 sscanf(lBuff,
"rgb(%hhu,%hhu,%hhu",
7232 & aoResultRGB[0], & aoResultRGB[1],& aoResultRGB[2]);
7235 else if ( lBuff[4] ==
'(' ) {
7236 sscanf(lBuff,
"rgba(%hhu,%hhu,%hhu",
7237 & aoResultRGB[0], & aoResultRGB[1],& aoResultRGB[2]);
7241 else if ( lWasOsascript || lWasXdialog )
7244 sscanf(lBuff,
"%hhu %hhu %hhu",
7245 & aoResultRGB[0], & aoResultRGB[1],& aoResultRGB[2]);
7261 char const *
const aTitle ,
7262 int const aNumOfColumns ,
7263 char const *
const *
const aColumns ,
7264 int const aNumOfRows ,
7265 char const *
const *
const aCells )
7279 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"zenity");
return (
char const *)1;}
7280 strcpy( lDialogString ,
"zenity" ) ;
7283 strcat( lDialogString,
" --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
7288 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"matedialog");
return (
char const *)1;}
7289 strcpy( lDialogString ,
"matedialog" ) ;
7293 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"shellementary");
return (
char const *)1;}
7294 strcpy( lDialogString ,
"shellementary" ) ;
7298 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"qarma");
return (
char const *)1;}
7299 strcpy( lDialogString ,
"qarma" ) ;
7300 if ( !getenv(
"SSH_TTY") )
7302 strcat(lDialogString,
" --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)");
7305 strcat( lDialogString ,
" --list --print-column=ALL" ) ;
7307 if ( aTitle && strlen(aTitle) )
7309 strcat(lDialogString,
" --title=\"") ;
7310 strcat(lDialogString, aTitle) ;
7311 strcat(lDialogString,
"\"") ;
7314 if ( aColumns && (aNumOfColumns > 0) )
7316 for ( i = 0 ; i < aNumOfColumns ; i ++ )
7318 strcat( lDialogString ,
" --column=\"" ) ;
7319 strcat( lDialogString , aColumns [i] ) ;
7320 strcat( lDialogString ,
"\"" ) ;
7324 if ( aCells && (aNumOfRows > 0) )
7326 strcat( lDialogString ,
" " ) ;
7327 for ( i = 0 ; i < aNumOfRows*aNumOfColumns ; i ++ )
7329 strcat( lDialogString ,
"\"" ) ;
7330 strcat( lDialogString , aCells [i] ) ;
7331 strcat( lDialogString ,
"\" " ) ;
7337 if (aTitle&&!strcmp(aTitle,
"tinyfd_query")){strcpy(
tinyfd_response,
"");
return (
char const *)0;}
7341 if (
tinyfd_verbose) printf(
"lDialogString: %s\n" , lDialogString ) ;
7342 if ( ! ( lIn = popen( lDialogString ,
"r" ) ) )
7346 while ( fgets( lBuff ,
sizeof( lBuff ) , lIn ) !=
NULL )
7349 if ( lBuff[strlen( lBuff ) -1] ==
'\n' )
7351 lBuff[strlen( lBuff ) -1] =
'\0' ;
7354 if ( ! strlen( lBuff ) )
7529 #pragma warning(default:4996) 7530 #pragma warning(default:4100) 7531 #pragma warning(default:4706) static char * getLastName(char *const aoDestination, char const *const aSource)
static void ensureFinalSlash(char *const aioString)
static char const * ensureFilesExist(char *const aDestination, char const *const aSourcePathsAndNames)
static int isTerminalRunning(void)
char const * tinyfd_saveFileDialog(char const *const aTitle, char const *const aDefaultPathAndFile, int const aNumOfFilterPatterns, char const *const *const aFilterPatterns, char const *const aSingleFilterDescription)
static int zenityPresent(void)
static int osx9orBetter(void)
static int whiptailPresent(void)
static int filenameValid(char const *const aFileNameWithoutPath)
static int pythonDbusPresent(void)
char tinyfd_response[1024]
static int afplayPresent(void)
static int graphicMode(void)
static int python2Present(void)
static int tkinter3Present(void)
char const * tinyfd_colorChooser(char const *const aTitle, char const *const aDefaultHexRGB, unsigned char const aDefaultRGB[3], unsigned char aoResultRGB[3])
static void replaceSubStr(char const *const aSource, char const *const aOldSubStr, char const *const aNewSubStr, char *const aoDestination)
static int gdialogPresent(void)
char const * tinyfd_arrayDialog(char const *const aTitle, int const aNumOfColumns, char const *const *const aColumns, int const aNumOfRows, char const *const *const aCells)
static int tkinter2Present(void)
static int gmessagePresent(void)
static int qarmaPresent(void)
GLenum GLuint GLenum GLsizei const GLchar * buf
#define MAX_MULTIPLE_FILES
static int *const getMajorMinorPatch(char const *const aExecutable)
static int beepexePresent(void)
static int gWarningDisplayed
static char * getPathWithoutFinalSlash(char *const aoDestination, char const *const aSource)
static char const * dialogNameOnly(void)
static int isDarwin(void)
static char const gTitle[]
static int osascriptPresent(void)
static int whiptailPresentOnly(void)
static int fileExists(char const *const aFilePathAndName)
static char gPython3Name[16]
int tinyfd_notifyPopup(char const *const aTitle, char const *const aMessage, char const *const aIconType)
static int shellementaryPresent(void)
static int kdialogPresent(void)
static char gPythonName[16]
int tinyfd_messageBox(char const *const aTitle, char const *const aMessage, char const *const aDialogType, char const *const aIconType, int const aDefaultButton)
char const * tinyfd_inputBox(char const *const aTitle, char const *const aMessage, char const *const aDefaultInput)
static int pactlPresent(void)
static int gxmessagePresent(void)
int isDialogVersionBetter09b(void)
static int notifysendPresent(void)
static int xdialogPresent(void)
static char const * getVersion(char const *const aExecutable)
static void sigHandler(int sig)
char const * tinyfd_openFileDialog(char const *const aTitle, char const *const aDefaultPathAndFile, int const aNumOfFilterPatterns, char const *const *const aFilterPatterns, char const *const aSingleFilterDescription, int const aAllowMultipleSelects)
static int python3Present(void)
static char const * terminalName(void)
static int speakertestPresent(void)
static char const * dialogName(void)
char const * tinyfd_selectFolderDialog(char const *const aTitle, char const *const aDefaultPath)
static char gPython2Name[16]
static int perlPresent(void)
static int dirExists(char const *const aDirPath)
static int zenity3Present(void)
static void Hex2RGB(char const aHexRGB[8], unsigned char aoResultRGB[3])
static void wipefile(char const *const aFilename)
char const tinyfd_version[8]
static int matedialogPresent(void)
static int tryCommand(char const *const aCommand)
static int detectPresence(char const *const aExecutable)
static int xmessagePresent(void)
char const tinyfd_needs[]
static void SetWindowPos(ImGuiWindow *window, const ImVec2 &pos, ImGuiSetCond cond)
static void RGB2Hex(unsigned char const aRGB[3], char aoResultHexRGB[8])