PreviousUpNext

15.4.424  src/lib/compiler/back/low/tools/line-number-db/gen-file.pkg

# gen-file.pkg

# Compiled by:
#     src/lib/compiler/back/low/tools/line-number-database.lib

stipulate
    package fil =  file__premicrothread;                                # file__premicrothread  is from   src/lib/std/src/posix/file--premicrothread.pkg
herein

    package   gen_file
    : (weak)  Generate_File                     # Generate_File is from   src/lib/compiler/back/low/tools/line-number-db/generate-file.api
    {
        include package   adl_error;

        bufsize = 1024*1024;

        fun gen { trans, program, file_suffix } (_, [infile])
                => 
                {   init();
                    #
                    (winix__premicrothread::path::split_base_ext  infile)
                        ->
                        { base, ext };

                    outfile =  winix__premicrothread::path::join_base_ext { base, ext=>THE file_suffix };

                    if (infile == outfile)
                        #
                        fail("input and output file the same name!");
                    fi;

                    text = trans infile;

                    fun changed ()
                        =
                        {   s = fil::open_for_read outfile;
                            t = fil::read_n (s, bufsize);
                            fil::close_input s;
                            t != text;
                        }
                        except _ = TRUE;

                    if (*error_count > 0)
                        #
                        print("[Result not written to " + outfile + "]\n"); 1;
                    else
                        if (changed ())
                            #
                            print("[Generating " + outfile + "]\n");

                            s = fil::open_for_write  outfile;
                            fil::write (s, text);
                            fil::close_output s;
                            0;
                        else
                            print ("[No change to " + outfile + "]\n");
                            0;
                        fi;
                    fi;
                }
                except  ERROR => 1;
                        exn   => fail("Uncaught exception " + exception_name exn);
                end; 

            gen { program, ... } _
                =>
                fail ("usage: " + program + " <filename>");
        end;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext