1 // vim:ts=4:sw=4:expandtab 2 #include <config.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <yajl/yajl_gen.h> 7 #include <yajl/yajl_version.h> 8 #include <sys/stat.h> 9 #include "i3status.h" 10 11 #define STRING_SIZE 5 12 print_path_exists(path_exists_ctx_t * ctx)13void print_path_exists(path_exists_ctx_t *ctx) { 14 const char *walk; 15 char *outwalk = ctx->buf; 16 struct stat st; 17 const bool exists = (stat(ctx->path, &st) == 0); 18 19 if (exists || ctx->format_down == NULL) { 20 walk = ctx->format; 21 } else { 22 walk = ctx->format_down; 23 } 24 25 INSTANCE(ctx->path); 26 27 START_COLOR((exists ? "color_good" : "color_bad")); 28 29 char string_status[STRING_SIZE]; 30 31 snprintf(string_status, STRING_SIZE, "%s", (exists ? "yes" : "no")); 32 33 placeholder_t placeholders[] = { 34 {.name = "%title", .value = ctx->title}, 35 {.name = "%status", .value = string_status}}; 36 37 const size_t num = sizeof(placeholders) / sizeof(placeholder_t); 38 char *formatted = format_placeholders(walk, &placeholders[0], num); 39 OUTPUT_FORMATTED; 40 free(formatted); 41 42 END_COLOR; 43 OUTPUT_FULL_TEXT(ctx->buf); 44 } 45