c1aa8ab5cd95 — Sean Farley 12 years ago
fast-bookmark: factor out 'cat' into its own function
1 files changed, 12 insertions(+), 7 deletions(-)

M fast-hg-bookmark.c
M fast-hg-bookmark.c +12 -7
@@ 27,13 27,14 @@ void go_up_one_dir(char* dir_path) {
   }
 }
 
-int parse_bookmarks(const char *hg_path) {
+/* return 0 if successfully printed out from file */
+int cat_file(const char *hg_path, const char *file_name) {
   FILE *f;
-  char bookmarks[PATH_MAX+1];
+  char full_path[PATH_MAX+1];
   char c = EOF;
 
-  sprintf(bookmarks, "%s/bookmarks.current", hg_path);
-  f = fopen(bookmarks, "r");
+  sprintf(full_path, "%s/%s", hg_path, file_name);
+  f = fopen(full_path, "r");
 
   if (f && (c=fgetc(f)) && c != EOF && c != '\n') { /* this checks for an empty file; probably a
                                                         little fragile, we should check for any

          
@@ 44,11 45,15 @@ int parse_bookmarks(const char *hg_path)
       putchar(c);
 
     fclose(f);
-  } else {
-    printf("default");
+
+    return 0;
   }
 
-  return 0;
+  return -1;
+}
+
+int parse_bookmarks(const char *hg_path) {
+  return cat_file(hg_path, "bookmarks.current");
 }
 
 int main() {