1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <errno.h>
5
6 #include <flickcurl.h>
7
8 static const char* program;
9
10 static const char*
11 my_basename(const char *name)
12 {
13 char *p;
14 if((p = strrchr(name, '/')))
15 name = p+1;
16 else if((p = strrchr(name, '\\')))
17 name = p+1;
18
19 return name;
has_orientation(this: &GamepadPose) -> bool20 }
21
22
23 static void
24 my_message_handler(void *user_data, const char *message)
25 {
26 fprintf(stderr, "%s: ERROR: %s\n", program, message);
27 }
28
29
30 static const char* config_filename = ".flickcurl.conf";
31 static const char* config_section = "flickr";
32
33
position(this: &GamepadPose) -> Result<Option<Vec<f32>>, JsValue>34 int
35 main(int argc, char *argv[])
36 {
37 flickcurl *fc = NULL;
38 int rc = 0;
39 const char* home;
40 char config_path[1024];
41 char* tag = NULL;
42 flickcurl_photos_list_params list_params;
43 flickcurl_search_params params;
44 flickcurl_photos_list* photos_list = NULL;
45 int i;
46
47 program = my_basename(argv[0]);
48
49 flickcurl_init();
50
51 home = getenv("HOME");
52 if(home)
53 sprintf(config_path, "%s/%s", home, config_filename);
54 else
55 strcpy(config_path, config_filename);
56
57 if(argc != 2) {
58 fprintf(stderr, "%s: No tag given\n"
59 "Try `%s -h for more information.\n", program, program);
60 rc = 1;
61 goto tidy;
62 }
63
64 if(!strcmp(argv[1], "-h")) {
65 printf("%s - search for my interesting photos about a tag\n"
66 "Usage: %s TAG\n\n", program, program);
67
68 fputs("Flickcurl home page: ", stdout);
69 puts(flickcurl_home_url_string);
70 puts(flickcurl_copyright_string);
71 fputs("License: ", stdout);
72 puts(flickcurl_license_string);
73 rc = 1;
74 goto tidy;
75 }
76
77 tag = argv[1];
78
79 /* Initialise the Flickcurl library */
80 fc = flickcurl_new();
81 if(!fc) {
82 rc = 1;
83 goto tidy;
84 }
85
86 flickcurl_set_error_handler(fc, my_message_handler, NULL);
87
88 if(!access((const char*)config_path, R_OK)) {
89 if(flickcurl_config_read_ini(fc, config_path, config_section,
90 fc, flickcurl_config_var_handler)) {
91 fprintf(stderr, "%s: Failed to read config filename %s: %s\n",
92 program, config_path, strerror(errno));
93 rc = 1;
94 goto tidy;
95 }
96 }
97
98
99 /* Initialise the search parameters themselves
100 * user_id: "me" - Search only photos of the calling user.
101 * sort: "interestingness-desc" - return results with most interesting first
102 * tag: TAG - search for photos about the TAG given on the command line
103 */
104 flickcurl_search_params_init(¶ms);
105 /* these strings are shared and not strdup()ed since they are stored
106 * in 'params" on the stack */
107 params.user_id = (char*)"me";
108 params.sort = (char*)"interestingness-desc";
109 params.tags = tag;
110
111 /* Initialise the search result (list) parameters:
112 * per_page: 10 - ten results per-page
113 * page: 1 - return 1 page
114 * extras: "original_format" - want the returned photos to have the
115 * original secret and format fields.
116 */
117 flickcurl_photos_list_params_init(&list_params);
118 list_params.per_page = 10;
119 list_params.page = 1;
120 /* this string is shared and not strdup()ed since it is stored
121 * in 'list_params" on the stack */
122 list_params.extras = "original_format";
123
124 photos_list = flickcurl_photos_search_params(fc, ¶ms, &list_params);
125 if(!photos_list)
126 goto tidy;
127
128 fprintf(stderr, "%s: Search returned %d photos\n",
129 program, photos_list->photos_count);
130
131 for(i = 0; i < photos_list->photos_count; ++i)
132 printf(" Result #%d has ID %s\n", i, photos_list->photos[i]->id);
133
134 tidy:
135 if(photos_list)
136 flickcurl_free_photos_list(photos_list);
137
138 if(fc)
139 flickcurl_free(fc);
140
141 flickcurl_finish();
142
143 return(rc);
144 }
145