X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ffile-handle.q;h=00c3fefd76f910d4168130d0d7e38aabebec6682;hb=4255c7e5a693e09a97dc7a3cca0634bb2adaba2d;hp=9c3a81a366a4bf5de31e657ba27e6a8ee6a8ae3b;hpb=b321086267ad1014dc5d09886396cde30f094437;p=pspp diff --git a/src/file-handle.q b/src/file-handle.q index 9c3a81a366..00c3fefd76 100644 --- a/src/file-handle.q +++ b/src/file-handle.q @@ -30,6 +30,8 @@ #include "error.h" #include "magic.h" #include "var.h" +#include "linked-list.h" + /* (headers) */ /* File handle. */ @@ -215,6 +217,16 @@ create_file_handle (const char *handle_name, const char *filename) return handle; } +static void +destroy_file_handle(void *fh_, void *aux UNUSED) +{ + struct file_handle *fh = fh_; + free (fh->name); + free (fh->filename); + fn_free_identity (fh->identity); + free (fh); +} + static const char * mode_name (const char *mode) { @@ -304,6 +316,10 @@ fh_close (struct file_handle *h, const char *type, const char *mode) return h->open_cnt; } + +static struct linked_list *handle_list; + + /* Parses a file handle name, which may be a filename as a string or a file handle name as an identifier. Returns the file handle or NULL on failure. */ @@ -330,11 +346,13 @@ fh_parse (void) char *handle_name = xmalloc (strlen (filename) + 3); sprintf (handle_name, "\"%s\"", filename); handle = create_file_handle (handle_name, filename); + ll_push_front(handle_list, handle); free (handle_name); } lex_get (); + return handle; } @@ -386,6 +404,23 @@ handle_get_tab_width (const struct file_handle *handle) return handle->tab_width; } + +void +fh_init(void) +{ + handle_list = ll_create(destroy_file_handle,0); +} + +void +fh_done(void) +{ + assert(handle_list); + + ll_destroy(handle_list); + handle_list = 0; +} + + /* Local variables: mode: c