removal due to another working script
[trueprint.git] / src / tpsearch.c
blob35cce77574ff5fe493e44a6e29a119065dd1a755
1 /* search files related to print (still in development)
3 This program is free software: you can
4 redistribute it and/or modify it under the
5 terms of the GNU General Public License as
6 published by the Free Software Foundation;
7 either version 3 of the License, or (at your
8 option) any later version.
10 This program is distributed in the hope that it
11 will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the GNU General Public License for
15 more details.
17 You should have received a copy of the GNU
18 General Public License along with this
19 program. If not, see http://www.gnu.org/licenses/.
24 #include<stdio.h>
25 #include<sys/stat.h>
26 #include<sys/types.h>
27 #include<pwd.h>
28 #include<unistd.h>
29 #include<string.h>
30 #include<errno.h>
31 #include<dirent.h>
32 #include<stdbool.h>
35 int main(int argc, char *argv[]) {
36 int i =0;
37 char *p;
38 FILE *sfile;
39 char buffer[200];
40 char *sword = "file.c"; /* testing */
41 bool found = false;
42 struct passwd *pw = getpwuid(getuid());
44 char *homedir = pw->pw_dir;
45 const char *plocation = "/.trueprint/files";
46 /* printf("%s\n",homedir); */
47 const char *npath = strcat(homedir,plocation);
48 int value = chdir(npath);
49 DIR *opendirp = opendir(npath);
50 struct dirent *d;
51 while ((d = readdir(opendirp)) != NULL )
52 /* for (i=0;i<=5;i++) */
54 sfile=fopen(d->d_name,"r");
55 while (!found && (fgets(buffer, sizeof(buffer), sfile ) != 0))
57 found = strstr(buffer,sword);
59 /* printf("%d\n",found); */
60 if (found == 1)
61 printf("found in: %s\n",d->d_name);
62 fclose(sfile);
64 /* printf("%d %d\n",value,errno); */
65 /* printf("%s\n",d->d_name); */
67 closedir(opendirp);
69 return 0;