comp.lang.ada
 help / color / mirror / Atom feed
* Direct IO Help needed
@ 2002-02-27 11:56 Joshua Shriver
  0 siblings, 0 replies; 2+ messages in thread
From: Joshua Shriver @ 2002-02-27 11:56 UTC (permalink / raw)


Here is the src I've created, now I need to create a main application that uses
these procedures, how is this done? it seems this is a "generic package" or
something so I can't just use with dfs; use dfs and then do:

dfs.switch_file_lines(...);

Here is the .adb



-- Joshua Shriver
-- Lab 2
-- Direct File Stuff package

with direct_io;

package body dfs is

procedure switch_file_lines(source_file: in string; line1: integer; line2:
integer) is

s_file: dfs_pkg.file_type;
buffer1: item;
buffer2: item;

Begin
	-- Swap file lines
	open(s_file, inout_file, source_file);
	read(s_file, buffer1, positive_count(line1));
	read(s_file, buffer2, positive_count(line2));
	write(s_file, buffer1, positive_count(line2));
	write(s_file, buffer2, positive_count(line1));

	close(s_file);

end switch_file_lines;

procedure swap_head_tail(source_file: in string; lines: integer) is
s_file: dfs_pkg.file_type;
i: integer;
last: count;
Begin
	-- Store file variables
	open(s_file, inout_file, source_file);
	last := size(s_file);
	close(s_file);

	i := 1;
	for i in 1.. lines loop
		switch_file_lines(source_file, i, integer(last));
		last := last - 1;
	end loop;


end swap_head_tail;

procedure get_middle(source_file: in string; found: out item) is
s_file: dfs_pkg.file_type;
middle: count;

Begin

	open(s_file, inout_file, source_file);
	middle := size(s_file) / 2;
	read(s_file, found, middle);	

end get_middle;

end dfs;

Here is the .ads


with direct_io;

generic 
	type item is private;

package dfs is
	package dfs_pkg is new direct_io(item);
        use dfs_pkg;

procedure switch_file_lines(source_file: in string; line1: integer; line2:
integer);

procedure swap_head_tail(source_file: in string; lines: integer);

procedure get_middle(source_file: in string; found: out item);

end dfs;

Any help is appreciated.

Sincerely,
Joshua Shriver
jshriver@mix.wvu.edu




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Direct IO Help needed
@ 2002-02-27 12:23 Christoph Grein
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Grein @ 2002-02-27 12:23 UTC (permalink / raw)


> with direct_io;
> 
> generic 
> 	type item is private;
> 
> package dfs is
> 	package dfs_pkg is new direct_io(item);
>         use dfs_pkg;
> 
>   procedure switch_file_lines(source_file: in string;
>                               line1: integer; line2:integer);
> 
>   procedure swap_head_tail(source_file: in string; lines: integer);
> 
>   procedure get_middle(source_file: in string; found: out item);
> 
> end dfs;
);
> 
> end dfs;

with dfs;

procedure Thus is

  type XXX is any definite non-limited type;

  package XXX_dfs is new dfs (XXX);

  The_Answer: Positive;
  pragma Import (Convention => Ada, Entity => The_Answer,
                 External_Name => "A_complicated_experiment_performed_by_Mice");

begin

  XXX_dfs.switch_file_lines (source_file => "Your_Choice",
                             line_1 => 42,
                             line_2 => The_Answer);
end Thus;



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-02-27 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-27 12:23 Direct IO Help needed Christoph Grein
  -- strict thread matches above, loose matches on Subject: below --
2002-02-27 11:56 Joshua Shriver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox