On Aug 25, 7:52 pm, hard wyrd <[email protected]> wrote:
> use bash to create your nifty little app, and use Zenity as its "gui".
>
>
>
>
>
I tried it again, and I think I got it working now (although it is 4
AM)
Ok, here's the bash script, gscript. Must be launched with " .
gscript "
# BASH SCRIPT START
#!/bin/sh
RESULT=1
while [ "$RESULT" -gt 0 ]
do
dialog --title $(pwd) --menu "Choose folder" 20 30 14 $(/home/
knoppix/Desktop/guicd) 2>/home/knoppix/Desktop/guicd.tmp
RESULT=$(cat /home/knoppix/Desktop/guicd.tmp)
cd $(/home/knoppix/Desktop/newfolders /home/knoppix/Desktop/
guicd.tmp) > /dev/null
echo
done
exit 0
# BASH SCRIPT END
Next, is two C programs. The first one is called guicd (guicd.c) .
It feeds the dialog program with the folder names. The second one is
called newfolders (newfolders.c). The second one opens the temp file
and reads it.
// start of guicd.c
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
void newstrcat(char * dest, char * source);
void printdir(char * dir);
void inttostr(char * x);
char curdir[266] = "";
char cmdline[32000] = "";
int counter = 0;
int main()
{
int result;
getcwd(curdir, 265);
printdir(curdir);
printf("%s", cmdline);
}
void printdir(char * dir)
{
DIR * dp;
char num[20] = "";
char twobytes[2]="";
struct dirent * entry;
struct stat statbuf;
if((dp=opendir(dir)) == NULL)
{
fprintf(stderr, "Failed.\n");
return;
}
while((entry=readdir(dp))!= NULL)
{
lstat(entry->d_name, &statbuf);
if(S_ISDIR(statbuf.st_mode))
{
counter++;
newstrcat(cmdline," ");
sprintf(num, "%i ", counter);
newstrcat(cmdline,num);
strcpy(num,"");
newstrcat(cmdline, entry->d_name);
}
}
closedir(dp);
} // end of printdir()
void newstrcat(char * dest, char * source)
{
if ((strlen(dest) + strlen(source)) >= 32000)
{
fprintf(stderr, "Failed.\n");
exit(0);
}
else
{
strcat(dest,source);
}
}
// end of guicd
// start of newfolders.c
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <ctype.h>
#include <stdlib.h>
void printdir(char * dir, int whichdir);
char curdir[266] = "";
char cmdline[32000] = "";
int counter = 0;
char buffer[4]="";
char new[4] = "";
int intbuff;
int main(int args, char * argv[])
{
FILE * openit;
int result;
getcwd(curdir, 265);
openit = fopen(argv[1],"r");
fscanf(openit,"%i", &intbuff);
fclose(openit);
if(strlen(curdir)==1)
{
printdir(curdir, intbuff);
return(0);
}
else
{
if (intbuff==1)
{
printf("./");
return(0);
}
if (intbuff==2)
{
printf("../");
return(0);
}
printdir(curdir, intbuff);
return(0);
}
} // end of main()
void printdir(char * dir, int whichdir)
{
DIR * dp;
struct dirent * entry;
struct stat statbuf;
if((dp=opendir(dir)) == NULL)
{
fprintf(stderr, "Failed.\n");
return;
}
while((entry=readdir(dp))!= NULL)
{
lstat(entry->d_name, &statbuf);
if(S_ISDIR(statbuf.st_mode))
{
counter++;
if (counter==whichdir)
{
printf("./%s", entry->d_name);
closedir(dp);
exit(0);
}
}
}
closedir(dp);
} // end of printdir()
// end of newfolders.c
Well, I'm reasonably happy (although file listings aren't shown. You
will have to adjust the paths in the bash script in order to get this
to work for you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit our group at
http://groups.google.com/group/linuxusersgroup
-~----------~----~----~----~------~----~------~--~---