phcpack_2.4.88_e448e94a/src/Ada/CtoPHC/State/file_management_interface.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
with text_io;                           use text_io;
with Standard_Natural_Numbers;          use Standard_Natural_Numbers;
with Standard_Integer_Numbers_io;       use Standard_Integer_Numbers_io;
with Standard_Floating_Numbers;         use Standard_Floating_Numbers;
with Standard_Floating_Numbers_io;      use Standard_Floating_Numbers_io;
with Interfaces.C;
with Assignments_in_Ada_and_C;          use Assignments_in_Ada_and_C;
with PHCpack_Operations;
with File_Management;

package body File_Management_Interface is

  function File_Management_Prompt_Input_File
             ( vrblvl : integer32 := 0 ) return integer32 is
  begin
    if vrblvl > 0 then
      put("-> in file_management_interface.");
      put_line("File_Management_Prompt_Input_File.");
    end if;
    File_Management.Open_Input_File;
    return 0;
  exception
    when others => 
      if vrblvl > 0 then
        put("Exception raised in file_management_interface.");
        put_line("File_Management_Prompt_Input_File.");
      end if;
      return 130;
  end File_Management_Prompt_Input_File;

  function File_Management_Prompt_Output_File
             ( vrblvl : integer32 := 0 ) return integer32 is
  begin
    if vrblvl > 0 then
      put("-> in file_management_interface.");
      put_line("File_Management_Prompt_Output_File.");
    end if;
    File_Management.Create_Output_File;
    return 0;
  exception
    when others => 
      if vrblvl > 0 then
        put("Exception raised in file_management_interface.");
        put_line("File_Management_Prompt_Output_File.");
      end if;
      return 131;
  end File_Management_Prompt_Output_File;

  function File_Management_Set_Output
             ( a : C_intarrs.Pointer;
               b : C_intarrs.Pointer;
               vrblvl : integer32 := 0 ) return integer32 is

    v_a : constant C_Integer_Array
        := C_intarrs.Value(a,Interfaces.C.ptrdiff_t(1));
    n : constant natural32 := natural32(v_a(v_a'first));
    n1 : constant Interfaces.C.size_t := Interfaces.C.size_t(n-1);
    v_b : constant C_Integer_Array(0..n1)
        := C_Intarrs.Value(b,Interfaces.C.ptrdiff_t(n));
    s : constant String(1..integer(n)) := C_Integer_Array_to_String(n,v_b);

  begin
    if vrblvl > 0 then
      put("-> in file_management_interface.");
      put_line("File_Management_Set_Output.");
    end if;
    PHCpack_Operations.Define_Output_File(s);
    return 0;
  exception
    when others => 
      if vrblvl > 0 then
        put("Exception raised in file_management_interface.");
        put_line("File_Management_Set_Output.");
      end if;
      return 191;
  end File_Management_Set_Output;

  function File_Management_Close_Output
             ( vrblvl : integer32 := 0 ) return integer32 is
  begin
    if vrblvl > 0 then
      put("-> in file_management_interface.");
      put_line("File_Management_Close_Output.");
    end if;
    PHCpack_Operations.Close_Output_File;
    return 0;
  exception
    when others => 
      if vrblvl > 0 then
        put("Exception raised in file_management_interface.");
        put_line("File_Management_Close_Output.");
      end if;
      return 192;
  end File_Management_Close_Output;

  function File_Management_Write_String
             ( a : C_intarrs.Pointer;
               b : C_intarrs.Pointer;
               vrblvl : integer32 := 0 ) return integer32 is

    v_a : constant C_Integer_Array
        := C_intarrs.Value(a,Interfaces.C.ptrdiff_t(1));
    n : constant integer := integer(v_a(v_a'first));
    n1 : constant Interfaces.C.size_t := Interfaces.C.size_t(n-1);
    v_b : constant C_Integer_Array(0..n1)
        := C_Intarrs.Value(b,Interfaces.C.ptrdiff_t(n));
    s : constant String(1..n) := C_Integer_Array_to_String(natural32(n),v_b);

  begin
    if vrblvl > 0 then
      put("-> in standard_solutions_interface.");
      put_line("File_Management_Write_String.");
    end if;
    if PHCpack_Operations.Is_File_Defined
     then put(PHCpack_Operations.output_file,s);
     else put(standard_output,s);
    end if;
    return 0;
  exception
    when others => 
      if vrblvl > 0 then
        put("Exception raised in file_management_interface.");
        put_line("File_Management_Write_String.");
      end if;
      return 158;
  end File_Management_Write_String;

  function File_Management_Write_Integers
             ( a : C_intarrs.Pointer;
               b : C_intarrs.Pointer;
               vrblvl : integer32 := 0 ) return integer32 is

    v_a : constant C_Integer_Array
        := C_intarrs.Value(a,Interfaces.C.ptrdiff_t(1));
    n : constant natural32 := natural32(v_a(v_a'first));
    n1 : constant Interfaces.C.size_t := Interfaces.C.size_t(n-1);
    v_b : constant C_Integer_Array(0..n1)
        := C_Intarrs.Value(b,Interfaces.C.ptrdiff_t(n));

    use Interfaces.C;

  begin
    if vrblvl > 0 then
      put("-> in standard_solutions_interface.");
      put_line("File_Management_Write_Integers.");
    end if;
    if PHCpack_Operations.Is_File_Defined then
      put(PHCpack_Operations.output_file,integer32(v_b(v_b'first)),1);
      for i in v_b'first+1..v_b'last loop
        put(PHCpack_Operations.output_file," ");
        put(PHCpack_Operations.output_file,integer32(v_b(i)),1);
      end loop;
    else
      put(standard_output,integer32(v_b(v_b'first)),1);
      for i in v_b'first+1..v_b'last loop
        put(standard_output," ");
        put(standard_output,integer32(v_b(i)),1);
      end loop;
    end if;
    return 0;
  end File_Management_Write_Integers;

  function File_Management_Write_Doubles
             ( a : C_intarrs.Pointer;
               c : C_dblarrs.Pointer;
               vrblvl : integer32 := 0 ) return integer32 is

    v_a : constant C_Integer_Array
        := C_intarrs.Value(a,Interfaces.C.ptrdiff_t(1));
    n : constant natural32 := natural32(v_a(v_a'first));
    n1 : constant Interfaces.C.size_t := Interfaces.C.size_t(n-1);
    v_c : constant C_Double_Array(0..n1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(n));
    d : double_float;

    use Interfaces.C;

  begin
    if vrblvl > 0 then
      put("-> in standard_solutions_interface.");
      put_line("File_Management_Write_Doubles.");
    end if;
    d := double_float(v_c(v_c'first));
    if PHCpack_Operations.Is_File_Defined then
      put(PHCpack_Operations.output_file,d);
      for i in v_c'first+1..v_c'last loop
        put(PHCpack_Operations.output_file," ");
        d := double_float(v_c(i));
        put(PHCpack_Operations.output_file,d);
      end loop;
    else
      put(standard_output,d);
      for i in v_c'first+1..v_c'last loop
        put(standard_output," ");
        d := double_float(v_c(i));
        put(standard_output,d);
      end loop;
    end if;
    return 0;
  end File_Management_Write_Doubles;

end File_Management_Interface;