[svn:parrot] r39634 - in branches/cindent: . t/codingstd

jkeenan at svn.parrot.org jkeenan at svn.parrot.org
Wed Jun 17 23:40:02 UTC 2009


Author: jkeenan
Date: Wed Jun 17 23:40:02 2009
New Revision: 39634
URL: https://trac.parrot.org/parrot/changeset/39634

Log:
Create a dummy file with least possible amount of content needed to diagnose problem.

Added:
   branches/cindent/workpmc.txt
      - copied, changed from r39633, branches/cindent/src/pmc/filehandle.pmc
Modified:
   branches/cindent/t/codingstd/c_indent.t

Modified: branches/cindent/t/codingstd/c_indent.t
==============================================================================
--- branches/cindent/t/codingstd/c_indent.t	Wed Jun 17 21:31:46 2009	(r39633)
+++ branches/cindent/t/codingstd/c_indent.t	Wed Jun 17 23:40:02 2009	(r39634)
@@ -6,7 +6,7 @@
 use warnings;
 
 use lib qw( . lib ../lib ../../lib );
-use Data::Dumper;$Data::Dumper::Indent=1;
+use Data::Dumper;$Data::Dumper::Indent=0;
 use Test::More tests => 2;
 use Parrot::Distribution;
 
@@ -63,6 +63,7 @@
             $state{line_cnt}++;
             next unless defined $line;
             chomp $line;
+#print STDERR Dumper \%state;print STDERR "\n";
 
             $state{prev_last_char} = $state{last_char};
             $state{last_char} = substr( $line, -1, 1 );

Copied and modified: branches/cindent/workpmc.txt (from r39633, branches/cindent/src/pmc/filehandle.pmc)
==============================================================================
--- branches/cindent/src/pmc/filehandle.pmc	Wed Jun 17 21:31:46 2009	(r39633, copy source)
+++ branches/cindent/workpmc.txt	Wed Jun 17 23:40:02 2009	(r39634)
@@ -1,23 +1,3 @@
-/*
-Copyright (C) 2008, Parrot Foundation.
-$Id$
-
-=head1 NAME
-
-src/pmc/filehandle.pmc - FileHandle PMC
-
-=head1 DESCRIPTION
-
-The FileHandle PMC performs I/O operations on a source or destination file.
-
-=head2 Vtable Functions
-
-=over 4
-
-=cut
-
-*/
-
 #include "../src/io/io_private.h"
 
 #ifdef PARROT_HAS_READLINE
@@ -47,306 +27,6 @@
     ATTR unsigned char *buffer_next;  /* Current read/write pointer   */
 
 /*
- * Using INTVAL for process_id is a temporary solution.
- * We may need to define a custom type to store it in a platform
- * dependant way.
- */
-
-/*
-
-=item C<void init()>
-
-Initializes a newly created FileHandle object.
-
-=cut
-
-*/
-
-    VTABLE void init() {
-        Parrot_FileHandle_attributes *data_struct =
-                mem_allocate_typed(Parrot_FileHandle_attributes);
-
-        PMC_data(SELF)             = data_struct;
-        data_struct->flags         = 0;
-        data_struct->filename      = NULL;
-        data_struct->mode          = NULL;
-        data_struct->encoding      = NULL;
-        data_struct->process_id    = 0;
-        data_struct->file_size     = 0;
-        data_struct->file_pos      = piooffsetzero;
-        data_struct->last_pos      = piooffsetzero;
-        data_struct->buffer_size   = 0;
-        data_struct->buffer_flags  = 0;
-        data_struct->buffer_start  = NULL;
-        data_struct->buffer_end    = NULL;
-        data_struct->buffer_next   = NULL;
-
-        /* Initialize the os_handle to the platform-specific value for closed. */
-        data_struct->os_handle     = (PIOHANDLE) PIO_INVALID_HANDLE;
-
-        PObj_custom_mark_SET(SELF);
-        PObj_active_destroy_SET(SELF);
-    }
-
-/*
-
-=item C<PMC *clone()>
-
-Create a copy of the filehandle.
-
-=cut
-
-*/
-
-    VTABLE PMC *clone() {
-        Parrot_FileHandle_attributes * const old_struct  = PARROT_FILEHANDLE(SELF);
-        PMC * const copy = Parrot_io_new_pmc(interp, old_struct->flags);
-        Parrot_FileHandle_attributes * const data_struct = PARROT_FILEHANDLE(copy);
-
-        data_struct->os_handle    = Parrot_dup(old_struct->os_handle);
-
-        return copy;
-    }
-
-/*
-
-=item C<void mark()>
-
-Mark active filehandle data as live.
-
-=cut
-
-*/
-
-    VTABLE void mark() {
-        Parrot_FileHandle_attributes * const data_struct = PARROT_FILEHANDLE(SELF);
-        if (data_struct->mode)
-            Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->mode);
-        if (data_struct->filename)
-            Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->filename);
-        if (data_struct->encoding)
-            Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->encoding);
-    }
-
-/*
-
-=item C<void destroy()>
-
-Free structures.
-
-=cut
-
-*/
-    VTABLE void destroy() {
-        if (PARROT_FILEHANDLE(SELF)) {
-            Parrot_FileHandle_attributes *data_struct = PARROT_FILEHANDLE(SELF);
-
-            if (!Parrot_io_is_closed_filehandle(INTERP, SELF)) {
-                if (data_struct->flags & PIO_F_SHARED)
-                    Parrot_io_flush_filehandle(INTERP, SELF);
-                else
-                    Parrot_io_close_filehandle(INTERP, SELF);
-            }
-
-            if (data_struct->buffer_start)
-                mem_sys_free(data_struct->buffer_start);
-
-            mem_sys_free(PARROT_FILEHANDLE(SELF));
-            PMC_data(SELF) = NULL;
-        }
-    }
-
-/*
-
-=item C<INTVAL get_integer_keyed_int(INTVAL key)>
-
-Shortcut to get the value of some attributes.
-For internal usage only, subject to change without notice.
-
-=cut
-
-*/
-
-    VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
-        INTVAL result;
-        switch (key) {
-            case 0:
-                GET_ATTR_process_id(INTERP, SELF, result);
-                break;
-            default:
-                result = 0;
-        }
-        return result;
-    }
-
-/*
-
-=item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
-
-Shortcut to set the value of some attributes
-For internal usage only, subject to change without notice.
-
-=cut
-
-*/
-
-    VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
-        switch (key) {
-            case 0:
-                SET_ATTR_process_id(INTERP, SELF, value);
-                break;
-            default:
-                break;
-        }
-    }
-
-/*
-
-=item C<INTVAL get_bool()>
-
-Returns whether the FileHandle has reached the end of the file.
-
-=cut
-
-*/
-
-    VTABLE INTVAL get_bool() {
-        return !Parrot_io_eof(INTERP, SELF);
-    }
-
-
-/*
-
-=back
-
-=head2 Methods
-
-=over 4
-
-=item C<METHOD open(STRING *filename :optional, STRING *mode :optional)>
-
-Opens the file at the given filename (including path) with the given mode. The
-invocant is modified and becomes an open filehandle. A copy of the invocant is
-also returned by the method (some subclasses may create this as the primary
-filehandle, rather than modifying the invocant).
-
-=cut
-
-*/
-
-    METHOD open(STRING *filename :optional, INTVAL got_filename :opt_flag,
-        STRING *mode :optional, INTVAL got_mode :opt_flag) {
-        PMC *filehandle;
-        STRING *open_filename, *open_mode;
-
-        if (!Parrot_io_is_closed_filehandle(INTERP, SELF))
-            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
-                                "Cannot reopen already open filehandle");
-
-        if (got_mode && !STRING_IS_NULL(mode))
-            SET_ATTR_mode(INTERP, SELF, Parrot_str_copy(INTERP, mode));
-
-        if (got_filename && !STRING_IS_NULL(filename))
-            SET_ATTR_filename(INTERP, SELF, Parrot_str_copy(INTERP, filename));
-
-        /* Open the file. When no options are passed, reopen the same file as
-         * before */
-        GET_ATTR_filename(INTERP, SELF, open_filename);
-        GET_ATTR_mode(INTERP, SELF, open_mode);
-
-
-        if (STRING_IS_NULL(open_filename))
-            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
-                            "Cannot open filehandle, no filename");
-
-        if (STRING_IS_NULL(open_mode)) {
-            open_mode = CONST_STRING(INTERP, "r");
-            SET_ATTR_mode(INTERP, SELF, open_mode);
-        }
-
-        filehandle = Parrot_io_open(INTERP, SELF, open_filename, open_mode);
-
-        RETURN(PMC *filehandle);
-    }
-
-/*
-
-=item C<METHOD isatty()>
-
-=cut
-
-*/
-    METHOD isatty() {
-        INTVAL isatty = (PARROT_FILEHANDLE(SELF)->flags & PIO_F_CONSOLE) == PIO_F_CONSOLE;
-        RETURN(INTVAL isatty);
-    }
-
-/*
-
-=item C<METHOD close()>
-
-Close the filehandle.
-
-=cut
-
-*/
-
-    METHOD close() {
-        INTVAL status;
-        status = Parrot_io_close(INTERP, SELF);
-        RETURN(INTVAL status);
-    }
-
-/*
-
-=item C<METHOD is_closed()>
-
-Test if the filehandle is closed.
-
-=cut
-
-*/
-
-    METHOD is_closed() {
-        INTVAL status;
-        status = Parrot_io_is_closed(interp, SELF);
-        RETURN(INTVAL status);
-    }
-
-/*
-
-=item C<METHOD read(INTVAL bytes)>
-
-Read the given number of bytes from the filehandle and return them in a string.
-
-=cut
-
-*/
-
-    METHOD read(INTVAL length) {
-        STRING *string_result = NULL;
-        string_result = Parrot_io_reads(INTERP, SELF, length);
-
-        RETURN(STRING *string_result);
-    }
-
-/*
-
-=item C<METHOD readline()>
-
-Read a line from the filehandle and return it in a string.
-
-=cut
-
-*/
-
-    METHOD readline() {
-        STRING *string_result;
-        string_result = Parrot_io_readline(INTERP, SELF);
-        RETURN(STRING *string_result);
-    }
-
-/*
 
 =item C<METHOD readline_interactive(STRING *prompt)>
 
@@ -373,320 +53,12 @@
         if (got_prompt)
             fprintf(stderr, "%s", prompt->strstart);
 
-        if (!(PARROT_FILEHANDLE(SELF)->flags & PIO_F_LINEBUF))
-            Parrot_io_setlinebuf(INTERP, SELF);
-
-        string_result = Parrot_io_reads(INTERP, SELF, 0);
-        if (string_result) {
-            UINTVAL len = Parrot_str_byte_length(INTERP, string_result);
-            if (len < 1)
-                string_result = NULL;
-            else {
-                while (len > 0 &&
-                        (((char*)string_result->strstart)[len - 1] == '\n' ||
-                         ((char*)string_result->strstart)[len - 1] == '\r')) {
-                    --len;
-                    --string_result->strlen;
-                    --string_result->bufused;
-                }
-            }
-        }
 #endif
         if (string_result)
             RETURN(STRING *string_result);
         else
             RETURN(PMC *PMCNULL);
     }
-
-/*
-
-=item METHOD readall(STRING *name);
-
-Read the entire contents of a file named I<name> into a Parrot string. On a
-filehandle object that isn't opened yet, the path to a file can be passed to
-C<readall> and it will open a filehandle on that file, read in the contents,
-and close the filehandle.
-
-  .local pmc pio
-  pio = new 'FileHandle'
-  $S0 = pio.'readall'('the_file')
-
-If the filehandle is already open, then no file path should be passed. The
-C<readall> method will read the contents of the file, and will not close the
-filehandle when finished.
-
-  pio = open 'the_file', 'r'
-  $S0 = pio.'readall'()
-
-=cut
-
-*/
-
-    METHOD readall(STRING *name :optional, INTVAL got_name :opt_flag) {
-        STRING *result;
-
-        if (got_name) {
-            /* called as class method - open, slurp, close file */
-            PMC *filehandle;
-            STRING *encoding;
-            size_t size;
-            GET_ATTR_encoding(INTERP, SELF, encoding);
-            if (!Parrot_io_is_closed_filehandle(INTERP, SELF)) {
-                Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
-                                "Cannot readall on a new file from an already open filehandle");
-            }
-            filehandle  = Parrot_io_open(INTERP, PMCNULL, name, NULL);
-            PARROT_ASSERT(filehandle->vtable->base_type == enum_class_FileHandle);
-            SET_ATTR_encoding(INTERP, filehandle, encoding);
-            size = (size_t)(Parrot_stat_info_intval(INTERP, name, STAT_FILESIZE));
-
-            result = Parrot_io_reads(INTERP, filehandle, size);
-            Parrot_io_close(INTERP, filehandle);
-            RETURN(STRING *result);
-        }
-        else {
-            /* slurp open file */
-            if (Parrot_io_is_closed_filehandle(INTERP, SELF)) {
-                Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
-                                "Cannot readall without a file name or open filehandle");
-            }
-            result = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0);
-
-            /* Do line buffering on the filehandle */
-            if (!(PARROT_FILEHANDLE(SELF)->flags & PIO_F_LINEBUF))
-                Parrot_io_setlinebuf(INTERP, SELF);
-
-            do {
-                STRING * const part = Parrot_io_reads(INTERP, SELF, 0);
-
-                result = Parrot_str_append(INTERP, result, part);
-                if (Parrot_io_eof(INTERP, SELF))
-                    break;
-            } while (1);
-        }
-
-        RETURN(STRING *result);
-    }
-
-/*
-
-=item C<METHOD flush()>
-
-Flushes the filehandle.
-
-=cut
-
-*/
-
-    METHOD flush() {
-        Parrot_io_flush(INTERP, SELF);
-    }
-
-/*
-
-=item C<METHOD print([INTVAL|FLOATVAL|STRING *|PMC*] value)>
-
-Print the passed in integer, number, string, or PMC to the filehandle.
-(Integers, numbers, and strings are auto-boxed as PMCs.)
-
-=cut
-
-*/
-
-    METHOD print(PMC *to_print) {
-        STRING * const string_to_print = VTABLE_get_string(INTERP, to_print);
-
-        Parrot_io_putps(interp, SELF, string_to_print);
-    }
-
-/*
-
-=item C<METHOD puts(STRING *value)>
-
-Print the string to the filehandle.
-
-=cut
-
-*/
-
-    METHOD puts(STRING *to_print) {
-        INTVAL status;
-        status = Parrot_io_putps(INTERP, SELF, to_print);
-        RETURN(INTVAL status);
-    }
-
-/*
-
-=item C<METHOD buffer_type(STRING *new_type :optional)>
-
-Set or retrieve the buffering behavior for the filehandle. The argument and
-return value are one of the following:
-
-=over
-
-=item C<unbuffered>
-
-Buffering disabled, bytes are sent as soon as possible.
-
-=item C<line-buffered>
-
-Line buffering, bytes are sent when a record separator is encountered.
-
-=item C<full-buffered>
-
-Full buffering, bytes are sent when the buffer is full.
-
-=cut
-
-*/
-
-    METHOD buffer_type(STRING *new_type :optional, INTVAL got_type :opt_flag) {
-        INTVAL flags;
-        STRING * const nobuffer_string   = CONST_STRING(INTERP, "unbuffered");
-        STRING * const linebuffer_string = CONST_STRING(INTERP, "line-buffered");
-        STRING * const fullbuffer_string = CONST_STRING(INTERP, "full-buffered");
-
-        if (got_type) {
-            if (Parrot_str_equal(INTERP, new_type, nobuffer_string))
-                Parrot_io_setbuf(INTERP, SELF, PIOCTL_NONBUF);
-            else if (Parrot_str_equal(INTERP, new_type, linebuffer_string))
-                Parrot_io_setlinebuf(INTERP, SELF);
-            else if (Parrot_str_equal(INTERP, new_type, fullbuffer_string))
-                Parrot_io_setbuf(INTERP, SELF, PIO_UNBOUND);
-        }
-
-        GET_ATTR_flags(INTERP, SELF, flags);
-
-        if (flags & PIO_F_LINEBUF)
-            RETURN(STRING *linebuffer_string);
-        else if (flags & PIO_F_BLKBUF)
-            RETURN(STRING *fullbuffer_string);
-
-        RETURN(STRING *nobuffer_string);
-
-    }
-
-/*
-
-=item C<METHOD buffer_size(INTVAL new_size :optional)>
-
-Set or retrieve the buffer size for the filehandle.
-
-=cut
-
-*/
-
-    METHOD buffer_size(INTVAL new_size :optional, INTVAL got_size :opt_flag) {
-        INTVAL buffer_size;
-
-        if (got_size) {
-            Parrot_io_setbuf(INTERP, SELF, (size_t) new_size);
-        }
-
-        buffer_size = (INTVAL) Parrot_io_get_buffer_size(INTERP, SELF);
-
-        RETURN(INTVAL buffer_size);
-
-    }
-
-/*
-
-=item C<METHOD mode()>
-
-Retrieve the read mode string for the filehandle.
-
-=cut
-
-*/
-
-    METHOD mode() {
-        STRING *mode, *mode_copy;
-
-        GET_ATTR_mode(INTERP, SELF, mode);
-        mode_copy = Parrot_str_copy(INTERP, mode);
-
-        RETURN(STRING *mode_copy);
-
-    }
-
-/*
-
-=item C<METHOD encoding(STRING *new_encoding)>
-
-Set or retrieve the encoding attribute (a string name of the selected encoding
-scheme) for the filehandle.
-
-=cut
-
-*/
-
-    METHOD encoding(STRING *new_encoding :optional, INTVAL got_encoding :opt_flag) {
-        STRING *encoding;
-        STRING *encoding_copy = NULL;
-
-        if (got_encoding) {
-            if (!STRING_IS_NULL(new_encoding))
-                encoding_copy = Parrot_str_copy(INTERP, new_encoding);
-            SET_ATTR_encoding(INTERP, SELF, encoding_copy);
-            RETURN(STRING *new_encoding);
-        }
-
-        GET_ATTR_encoding(INTERP, SELF, encoding);
-        if (!STRING_IS_NULL(encoding))
-            encoding_copy = Parrot_str_copy(INTERP, encoding);
-
-        RETURN(STRING *encoding_copy);
-
-    }
-
-/*
-
-=item C<METHOD eof()>
-
-Returns true if the filehandle is at end-of-file, returns false otherwise.
-
-=cut
-
-*/
-
-    METHOD eof() {
-        INTVAL flags;
-        flags = Parrot_io_eof(INTERP, SELF);
-        RETURN(INTVAL flags);
-    }
-
-
-/*
-
-=item C<METHOD get_fd()>
-
-Retrieve the integer file descriptor for the FileHandle (only available on
-platforms that use integer file descriptors).
-
-=cut
-
-*/
-
-    METHOD get_fd() {
-#ifndef PIO_OS_STDIO
-        INTVAL os_handle;
-        GET_ATTR_os_handle(INTERP, SELF, os_handle);
-        RETURN(INTVAL os_handle);
-#endif /*PIO_OS_STDIO*/
-
-        RETURN(INTVAL -1);
-
-    }
-
-
-/*
-
-=back
-
-=cut
-
-*/
-
 } /* end pmclass */
 
 /*


More information about the parrot-commits mailing list