/* example9b1.c -XT COPYRIGHT (c) 2000 Kapteyn Astronomical Institute University of Groningen - 9700 AV Groningen, The Netherlands Example program to demonstrate GgiFileBrowser. The program allows the user to open a file browser. Using this browser he or she can navigate the file system and select any file. The program then attempts to obtain the size of the file by calling fsize_c(). This can be repeated any number of times. Author: J.P. Terlouw. */ #include "stddef.h" #include "gipsyc.h" #include "cmain.h" #include "init.h" #include "finis.h" #include "userfio.h" #include "fsize.h" #include "ggi.h" static ident label; /* * Button keyword handler for quitting. */ static void quit(ident id, char *key, int code, void *arg) { bool button=toflog(FALSE); (void)userflog(&button, 1, 2, key, " "); if (tobool(button)) { wkeyf(key); /* reset button */ if (GgiVerify("Really quit?", "Yes, quit", "No, continue")) { finis_c(); /* terminate program */ } } } /* * Button keyword handler for popping the file browser up or down. */ static void browse(ident id, char *key, int code, void *arg) { bool button=toflog(FALSE); ident browser; (void)userflog(&button, 1, 2, key, " "); if (tobool(button)) { wkeyf(key); browser = GgiFileBrowser(ggiIdent, "FILENAME="); /* check existence */ if (browser) { (void)GgiFileBrowser(ggiDelete, browser); /* exists: close */ } else { browser = GgiFileBrowser(ggiCreate, "FILENAME=", "Choose file", NULL); (void)GgiFileBrowser(ggiNowait, browser); } } } /* * Keyword handler receiving the resulting file name. */ static void getfile(ident id, char *key, int code, void *arg) { fint nread, size; fchar name; char cname[128], message[200]; name.a = cname; name.l = 127; nread = userftext(name, 2, key, " "); if (nread) { size = (int)fsize_c(name); cname[nread] = '\0'; sprintf(message, "FSIZE reported a size of %d bytes\n" "for file %s", size, cname); GgiSetLabel(label, message, 0); /* update output text */ } } MAIN_PROGRAM_ENTRY { ident button, quitbtn; init_c(); GgiAutoLayout(FALSE); GgiPostponeRealize(TRUE); label = GgiLabel(" \n "); /* output text */ button = GgiButton("BROWSE=", "File selector"); /* browse button */ quitbtn = GgiButton("QUIT=", "Terminate program"); /* quit button */ GgiSetPosition(label, 0, NULL, 0, NULL); GgiSetPosition(quitbtn, 0, NULL, 0, label); GgiSetPosition(button, 500, NULL, 0, label); GgiRealize(); (void)ScheduleKeyevent(quit, "QUIT=", KEYCHANGE, NULL); (void)ScheduleKeyevent(browse, "BROWSE=", KEYCHANGE, NULL); (void)ScheduleKeyevent(getfile, "FILENAME=", KEYCHANGE, NULL); MainLoop(); }