430405efcc31 — Sean Farley 12 years ago
fast-bookmark: factor out cat_file
3 files changed, 25 insertions(+), 24 deletions(-)

M fast-hg-bookmark.c
M fast-hg-common.c
M fast-hg-common.h
M fast-hg-bookmark.c +0 -24
@@ 9,30 9,6 @@ 
 
 #include "fast-hg-common.h"
 
-/* return 0 if successfully printed out from file */
-int cat_file(const char *pwd, const char *file_name) {
-  FILE *f;
-  char full_path[PATH_MAX+1];
-  char c = EOF;
-
-  sprintf(full_path, "%s/%s", pwd, 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
-                                                        white space */
-    putchar(c);
-
-    while ((c = fgetc(f)) != EOF && c != '\n') putchar(c);
-
-    fclose(f);
-
-    return 0;
-  }
-
-  return -1;
-}
-
 int parse_bookmarks(const char *pwd) {
   if (cat_file(pwd, ".hg/bookmarks.current")) {
     /* fallback to branch name if bookmark isn't active */

          
M fast-hg-common.c +24 -0
@@ 41,3 41,27 @@ int map(int (*apply)(const char*)) {
 
   return 0;
 }
+
+/* return 0 if successfully printed out from file */
+int cat_file(const char *pwd, const char *file_name) {
+  FILE *f;
+  char full_path[PATH_MAX+1];
+  char c = EOF;
+
+  sprintf(full_path, "%s/%s", pwd, 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
+                                                        white space */
+    putchar(c);
+
+    while ((c = fgetc(f)) != EOF && c != '\n') putchar(c);
+
+    fclose(f);
+
+    return 0;
+  }
+
+  return -1;
+}

          
M fast-hg-common.h +1 -0
@@ 21,3 21,4 @@ 
 
 void go_up_one_dir(char* dir_path);
 int map(int (*apply)(const char*));
+int cat_file(const char *pwd, const char *file_name);