6 // Daniel Campos ( danielcampos@netcourrier.com )
12 namespace Microsoft.VisualBasic
14 [Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute]
15 sealed public class FileSystem {
16 private static System.IO.FileStream[] FHandle=new FileStream[255];
17 private static Microsoft.VisualBasic.OpenMode[] FMode= new Microsoft.VisualBasic.OpenMode[255];
18 private static string InitialPath=Environment.CurrentDirectory;
23 [MonoTODO("Needs testing")]
24 public static void ChDir (System.String Path)
26 if ( (Path=="") || (Path==null))
27 throw new System.ArgumentException("Path is empty");
30 Environment.CurrentDirectory=Path;
32 catch ( Exception e){ throw new System.IO.FileNotFoundException ("Invalid drive is specified, or drive is unavailable");}
37 public static void ChDrive (System.Char Drive) { throw new NotImplementedException (); }
39 public static void ChDrive (System.String Drive) { throw new NotImplementedException (); }
41 [MonoTODO("Needs testing")]
42 public static System.String CurDir ()
44 return Environment.CurrentDirectory;
47 [MonoTODO("Needs Testing")]
48 public static System.String CurDir (System.Char Drive)
51 string MyDrive=(Drive.ToString()).ToLower();
52 string[] buf=System.IO.Directory.GetLogicalDrives ();
53 for (int lookfor=0;lookfor<buf.Length;lookfor++)
54 if ( buf[lookfor].Substring(0,1).ToLower() == MyDrive ) {MyOK=true; break; }
56 throw new System.ArgumentException("Invalid drive is specified.");
57 if ( Environment.CurrentDirectory.Substring(0,1).ToLower() == MyDrive )
58 return Environment.CurrentDirectory ;
61 if ( InitialPath.Substring(0,1).ToLower() == MyDrive )
64 return (MyDrive.ToUpper() + Path.VolumeSeparatorChar + Path.DirectorySeparatorChar );
68 public static System.String Dir () { throw new NotImplementedException (); }
70 public static System.String Dir (System.String Pathname, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(0)] Microsoft.VisualBasic.FileAttribute Attributes) { throw new NotImplementedException (); }
72 [MonoTODO("Needs testing")]
73 public static void MkDir (System.String Path)
75 // if a file called like 'path' does exist
76 // no exception is generated using .net
78 if (Path==null || Path=="")
80 throw new System.ArgumentException();
84 if (System.IO.Directory.Exists (Path))
85 throw new System.IO.IOException("Directory already exists");
87 System.IO.Directory.CreateDirectory(Path);
91 [MonoTODO("Needs testing")]
92 public static void RmDir (System.String Path)
94 System.IO.Directory.Delete(Path);
97 [MonoTODO("Needs testing")]
98 public static void FileCopy (System.String Source, System.String Destination)
100 // using VB, filecopy always overwrites Destination
101 System.IO.File.Copy(Source,Destination,true);
104 [MonoTODO("Needs testing")]
105 public static System.DateTime FileDateTime (System.String PathName)
107 // A better exception handling is needed : exceptions
108 // are not the same as 'GetLastWriteTime'
109 return System.IO.File.GetLastWriteTime (PathName);
112 [MonoTODO("Needs Testing")]
113 public static System.Int64 FileLen(System.String PathName)
115 FileInfo MyFile=new FileInfo(PathName);
116 if ( !MyFile.Exists )
117 throw new System.ArgumentException(PathName + " does not exists");
118 return (System.Int64)MyFile.Length;
121 public static Microsoft.VisualBasic.FileAttribute GetAttr (System.String PathName) { throw new NotImplementedException (); }
123 [MonoTODO("Needs testing")]
124 public static void Kill (System.String PathName)
126 if (!System.IO.File.Exists(PathName))
127 throw new System.IO.FileNotFoundException();
129 System.IO.File.Delete(PathName);
133 public static void SetAttr (System.String PathName, Microsoft.VisualBasic.FileAttribute Attributes) { throw new NotImplementedException (); }
135 [MonoTODO("Needs testing")]
136 public static void FileOpen (System.Int32 FileNumber, System.String FileName, Microsoft.VisualBasic.OpenMode Mode, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] Microsoft.VisualBasic.OpenAccess Access, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] Microsoft.VisualBasic.OpenShare Share, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int32 RecordLength)
138 // at this moment you can open a file
139 // only for Append, Input or Output
140 System.IO.FileMode MyMode;
141 System.IO.FileAccess MyAccess;
142 System.IO.FileShare MyShare;
146 if ( RecordLength < -1 )
147 throw new System.ArgumentException("Record Length is negative (nad not equal to -1)");
148 if ( RecordLength > 32767)
149 throw new System.ArgumentException ("Invalid Record Length");
150 if (FileNumber <0 || FileNumber > 255)
151 throw new System.IO.IOException(FileNumber.ToString() + " is invalid (<-1 or >255)",5);
152 if ( (Mode == OpenMode.Output) && ( Access != OpenAccess.Default ) && ( Access != OpenAccess.Write ) )
153 throw new System.ArgumentException("To use Output Mode, you have to use OpenAccess.Write or OpenAccess.Default");
154 if ( (Mode == OpenMode.Input) && ( Access != OpenAccess.Default ) && ( Access != OpenAccess.Read ) )
155 throw new System.ArgumentException("To use Input Mode, you have to use OpenAccess.Read or OpenAccess.Default");
160 if (FHandle[FileNumber] != null)
161 throw new System.IO.IOException (FileNumber.ToString() + " is in use",5);
165 case Microsoft.VisualBasic.OpenMode.Append :
166 MyMode=System.IO.FileMode.Append ;
168 case Microsoft.VisualBasic.OpenMode.Binary :
169 throw new NotImplementedException ();
171 case Microsoft.VisualBasic.OpenMode.Input :
172 MyMode=System.IO.FileMode.Open ;
174 case Microsoft.VisualBasic.OpenMode.Output :
175 MyMode=System.IO.FileMode.OpenOrCreate ;
177 case Microsoft.VisualBasic.OpenMode.Random :
178 throw new NotImplementedException ();
180 throw new System.ArgumentException("Invalid Share");
184 case Microsoft.VisualBasic.OpenAccess.ReadWrite :
185 case Microsoft.VisualBasic.OpenAccess.Default :
186 MyAccess=System.IO.FileAccess.ReadWrite;
188 case Microsoft.VisualBasic.OpenAccess.Read :
189 MyAccess=System.IO.FileAccess.Read;
191 case Microsoft.VisualBasic.OpenAccess.Write :
192 MyAccess=System.IO.FileAccess.Write;
195 throw new System.ArgumentException("Invalid Access");
200 case Microsoft.VisualBasic.OpenShare.Default :
201 case Microsoft.VisualBasic.OpenShare.Shared :
202 MyShare=System.IO.FileShare.ReadWrite ;
204 case Microsoft.VisualBasic.OpenShare.LockRead :
205 MyShare=System.IO.FileShare.Write;
207 case Microsoft.VisualBasic.OpenShare.LockReadWrite :
208 MyShare=System.IO.FileShare.None ;
210 case Microsoft.VisualBasic.OpenShare.LockWrite :
211 MyShare=System.IO.FileShare.Read;
214 throw new System.ArgumentException("Invalid Share");
216 FHandle[FileNumber]=new System.IO.FileStream (FileName,MyMode,MyAccess,MyShare);
217 FMode[FileNumber]=Mode;
222 [MonoTODO("Needs testing")]
223 public static void FileClose (params System.Int32[] FileNumbers)
226 if (FileNumbers.Length == 0)
228 Microsoft.VisualBasic.FileSystem.Reset();
232 for(bucle=0;bucle<FileNumbers.Length;bucle++)
234 if ( FHandle [ FileNumbers[bucle] - 1 ] != null )
236 if (FileNumbers[bucle]>0 && FileNumbers[bucle]<256)
240 FHandle[ FileNumbers[bucle] - 1].Close();
241 FHandle[ FileNumbers[bucle] - 1]=null;
243 catch (Exception e){e.GetType (); FHandle[ FileNumbers[bucle] - 1]= null ;}
246 throw new System.IO.IOException (FileNumbers[bucle].ToString() + " Does not exist",52);
249 throw new System.IO.IOException (FileNumbers[bucle].ToString() + " Does not exist",52);
254 public static void FileGetObject (System.Int32 FileNumber, ref System.Object Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
256 public static void FileGet (System.Int32 FileNumber, ref System.ValueType Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
258 public static void FileGet (System.Int32 FileNumber, ref System.Array Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(false)] ref System.Boolean ArrayIsDynamic, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(false)] ref System.Boolean StringIsFixedLength) { throw new NotImplementedException (); }
260 public static void FileGet (System.Int32 FileNumber, ref System.Boolean Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
262 public static void FileGet (System.Int32 FileNumber, ref System.Byte Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
264 public static void FileGet (System.Int32 FileNumber, ref System.Int16 Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
266 public static void FileGet (System.Int32 FileNumber, ref System.Int32 Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
268 public static void FileGet (System.Int32 FileNumber, ref System.Int64 Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
270 public static void FileGet (System.Int32 FileNumber, ref System.Char Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
272 public static void FileGet (System.Int32 FileNumber, ref System.Single Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
274 public static void FileGet (System.Int32 FileNumber, ref System.Double Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
276 public static void FileGet (System.Int32 FileNumber, ref System.Decimal Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
278 public static void FileGet (System.Int32 FileNumber, ref System.String Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(false)] ref System.Boolean StringIsFixedLength) { throw new NotImplementedException (); }
280 public static void FileGet (System.Int32 FileNumber, ref System.DateTime Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber) { throw new NotImplementedException (); }
282 public static void FilePutObject (System.Int32 FileNumber, System.Object Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
284 [System.ObsoleteAttribute("Use FilePutObject to write Object types, or coerce FileNumber and RecordNumber to Integer for writing non-Object types", false)]
285 public static void FilePut (System.Object FileNumber, System.Object Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Object RecordNumber) { throw new NotImplementedException (); }
287 public static void FilePut (System.Int32 FileNumber, System.ValueType Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
289 public static void FilePut (System.Int32 FileNumber, System.Array Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(false)] System.Boolean ArrayIsDynamic, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(false)] System.Boolean StringIsFixedLength) { throw new NotImplementedException (); }
291 public static void FilePut (System.Int32 FileNumber, System.Boolean Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
293 public static void FilePut (System.Int32 FileNumber, System.Byte Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
295 public static void FilePut (System.Int32 FileNumber, System.Int16 Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
297 public static void FilePut (System.Int32 FileNumber, System.Int32 Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
299 public static void FilePut (System.Int32 FileNumber, System.Int64 Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
301 public static void FilePut (System.Int32 FileNumber, System.Char Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
303 public static void FilePut (System.Int32 FileNumber, System.Single Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
305 public static void FilePut (System.Int32 FileNumber, System.Double Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
307 public static void FilePut (System.Int32 FileNumber, System.Decimal Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
309 public static void FilePut (System.Int32 FileNumber, System.String Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(false)] System.Boolean StringIsFixedLength) { throw new NotImplementedException (); }
311 public static void FilePut (System.Int32 FileNumber, System.DateTime Value, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber) { throw new NotImplementedException (); }
313 public static void Print (System.Int32 FileNumber, params System.Object[] Output) { throw new NotImplementedException (); }
315 public static void PrintLine (System.Int32 FileNumber, params System.Object[] Output) { throw new NotImplementedException (); }
317 public static void Input (System.Int32 FileNumber, ref System.Object Value) { throw new NotImplementedException (); }
318 [MonoTODO("Needs Testing")]
319 public static void Input (System.Int32 FileNumber, ref System.Boolean Value)
322 InternalInputExceptions(FileNumber);
323 buffer=InternalInput(FileNumber,3);
329 [MonoTODO("Needs Testing")]
330 public static void Input (System.Int32 FileNumber, ref System.Byte Value)
333 InternalInputExceptions(FileNumber);
334 buffer=InternalInput(FileNumber,1);
336 throw new System.OverflowException();
338 for (int addnumber=0; addnumber < buffer.Length;addnumber++)
342 Value += Byte.Parse(buffer.Substring(addnumber,1));
347 [MonoTODO("Needs Testing")]
348 public static void Input (System.Int32 FileNumber, ref System.Int16 Value)
351 System.Int16 factor=1;
352 InternalInputExceptions(FileNumber);
353 buffer=InternalInput(FileNumber,1);
357 buffer=buffer.Substring(1);
360 for (int addnumber=0; addnumber < buffer.Length;addnumber++)
364 Value += Int16.Parse(buffer.Substring(addnumber,1));
371 [MonoTODO("Needs Testing")]
372 public static void Input (System.Int32 FileNumber, ref System.Int32 Value)
376 InternalInputExceptions(FileNumber);
377 buffer=InternalInput(FileNumber,1);
381 buffer=buffer.Substring(1);
384 for (int addnumber=0; addnumber < buffer.Length;addnumber++)
388 Value += Int32.Parse(buffer.Substring(addnumber,1));
395 [MonoTODO("Needs Testing")]
396 public static void Input (System.Int32 FileNumber, ref System.Int64 Value)
400 InternalInputExceptions(FileNumber);
401 buffer=InternalInput(FileNumber,1);
405 buffer=buffer.Substring(1);
408 for (int addnumber=0; addnumber < buffer.Length;addnumber++)
412 Value += Int64.Parse(buffer.Substring(addnumber,1));
420 public static void Input (System.Int32 FileNumber, ref System.Char Value) { throw new NotImplementedException (); }
421 [MonoTODO("Needs Testing")]
422 public static void Input (System.Int32 FileNumber, ref System.Single Value)
424 System.Single DecimalValue=0;
427 string BufDecimal="";
428 InternalInputExceptions(FileNumber);
429 buffer=InternalInput(FileNumber,2);
433 buffer=buffer.Substring(1);
435 if ( buffer.IndexOf(".")>=0)
437 if ( buffer.IndexOf(".") < (buffer.Length -1) )
438 BufDecimal=buffer.Substring(buffer.IndexOf(".")+1);
439 if ( buffer.IndexOf(".") > 0)
440 buffer=buffer.Substring(0,buffer.IndexOf("."));
446 if ( BufDecimal.Length > 0)
448 for (int addnumber=BufDecimal.Length-1; addnumber >=0;addnumber--)
451 DecimalValue += System.Single.Parse(BufDecimal.Substring(addnumber,1));
457 if (buffer.Length >0)
459 for (int addnumber=0; addnumber < buffer.Length;addnumber++)
463 Value += System.Single.Parse(buffer.Substring(addnumber,1));
470 [MonoTODO("Needs Testing")]
471 public static void Input (System.Int32 FileNumber, ref System.Double Value)
473 double DecimalValue=0;
476 string BufDecimal="";
477 InternalInputExceptions(FileNumber);
478 buffer=InternalInput(FileNumber,2);
482 buffer=buffer.Substring(1);
484 if ( buffer.IndexOf(".")>=0)
486 if ( buffer.IndexOf(".") < (buffer.Length -1) )
487 BufDecimal=buffer.Substring(buffer.IndexOf(".")+1);
488 if ( buffer.IndexOf(".") > 0)
489 buffer=buffer.Substring(0,buffer.IndexOf("."));
495 if ( BufDecimal.Length > 0)
497 for (int addnumber=BufDecimal.Length-1; addnumber >=0;addnumber--)
500 DecimalValue += Double.Parse(BufDecimal.Substring(addnumber,1));
506 if (buffer.Length >0)
508 for (int addnumber=0; addnumber < buffer.Length;addnumber++)
512 Value += Double.Parse(buffer.Substring(addnumber,1));
520 public static void Input (System.Int32 FileNumber, ref System.Decimal Value) { throw new NotImplementedException (); }
521 [MonoTODO("Needs Testing")]
522 public static void Input (System.Int32 FileNumber, ref System.String Value)
525 InternalInputExceptions(FileNumber);
526 Value=InternalInput(FileNumber,0);
529 public static void Input (System.Int32 FileNumber, ref System.DateTime Value) { throw new NotImplementedException (); }
530 private static void InternalInputExceptions(System.Int32 FileNumber)
532 if ( FileNumber < 0 || FileNumber > 255 )
533 throw new System.ArgumentException("File Number is not valid");
534 if ( FHandle[FileNumber - 1] == null)
535 throw new System.ArgumentException("File Number is not valid");
536 if ( FMode[FileNumber - 1] != OpenMode.Input && FMode[FileNumber-1] != OpenMode.Binary )
537 throw new System.IO.IOException("File Mode is invalid");
538 if ( FHandle[FileNumber - 1].Position == FHandle[FileNumber - 1].Length)
539 throw new System.IO.EndOfStreamException();
541 private static string InternalInput(System.Int32 FileNumber,int DataType)
544 // DataType : an additional filter
545 // to know if conversion is possible
547 // 1 --> To a numeric (integer) value
548 // 2 --> To a numeric (not integer) value
554 bool DecimalFound=false;
555 bool SignFound=false;
558 byte[] BufByte=new byte[1];
559 while ( !found && ( FHandle[FileNumber-1].Position < FHandle[FileNumber-1].Length ))
561 FHandle[FileNumber-1].Read (BufByte,0,1);
562 switch ((char)BufByte[0])
568 if (!firstzone && (DataType==1 || DataType==2))
575 if (literal) retval+="\t";
576 else if (!firstzone) found=true;
580 if (literal) literal=!literal;
583 if (!firstzone) found=true;
584 else literal=!literal;
588 if (!literal) found=true;
595 if (FHandle[FileNumber - 1].Length > FHandle[FileNumber - 1].Position )
597 FHandle[FileNumber - 1].Read (BufByte,0,1);
598 if (BufByte[0] != 10 )
599 FHandle[FileNumber - 1].Seek (-1,SeekOrigin.Current );
603 else { retval+="\x0d"; }
606 if (literal) retval+="\x0a";
610 retval+=((char)BufByte[0]).ToString();
617 retval=retval.Trim();
618 if (retval.Substring(0,1)=="\"")
620 if (retval.Length > 1) retval=retval.Substring (1);
623 if (retval.Length >=1)
625 if (retval.Substring (retval.Length -1 ,1)=="\"")
627 if (retval.Length > 1) retval=retval.Substring (0,retval.Length -1);
635 retval=retval.Trim();
636 for (int myloop=0; (myloop<retval.Length) && MyOK ;myloop++)
637 switch(retval[myloop])
641 if (myloop==0 || myloop == (retval.Length -1))
645 retval2=retval[myloop].ToString() + retval2;
654 case '0': case '1': case '2': case '3': case '4':
655 case '5': case '6': case '7': case '8': case '9':
656 retval2+=retval.Substring (myloop,1);
674 if (MyOK && (retval2.Length >=1 ) )
676 if (retval2[retval2.Length-1]=='.' )
678 if (retval2.Length >1)
679 retval2=retval2.Substring (0,retval2.Length -1);
688 retval=retval.Trim();
690 retval=retval.Trim();
691 if (retval=="#TRUE#" || retval=="#FALSE#" ||
692 retval.ToUpper() =="TRUE" || retval.ToUpper() =="FALSE" ||
693 retval.ToUpper() == "\"TRUE\"" || retval.ToUpper() == "\"FALSE\"")
695 if (retval=="#TRUE#" || retval.ToUpper() == "TRUE" || retval.ToUpper () == "\"TRUE\"")
700 if (retval.Substring(0,1)=="\"")
702 if (retval.Length > 1) retval=retval.Substring (1);
705 if (retval.Length >=1)
707 if (retval.Substring (retval.Length -1 ,1)=="\"")
709 if (retval.Length > 1) retval=retval.Substring (0,retval.Length -1);
713 for (int myloop=0; (myloop<retval.Length) && MyOK ;myloop++)
714 switch(retval[myloop])
718 case '1': case '2': case '3': case '4': case '5':
719 case '6': case '7': case '8': case '9':
724 if ( (myloop!=0) && (myloop!=retval.Length-1) )
738 else // TODO : string explaining cast exception
739 throw new System.InvalidCastException();
741 [MonoTODO("Needs Testing")]
742 public static void Write (System.Int32 FileNumber, params System.Object[] Output)
745 byte[] Separator=new byte[1];
746 byte[] bufout=new Byte[1];
747 Separator[0]=(byte)',';
748 if (FileNumber<1 || FileNumber>255)
749 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
750 if (FHandle[FileNumber - 1]==null)
751 throw new System.IO.IOException(FileNumber + " does not exists",52);
752 if ( FMode[ FileNumber - 1] != OpenMode.Output )
753 throw new System.IO.IOException ("FileMode is invalid");
754 if (Output.Length == 0)
756 FHandle[FileNumber - 1].Write(Separator,0,1);
760 for (int MyArgs=0;MyArgs<Output.Length;MyArgs++)
762 MyBuf=WriteAuxiliar(Output[MyArgs]);
763 for (int PutsData=0;PutsData<MyBuf.Length;PutsData++)
765 bufout[0]=(byte)MyBuf[PutsData];
766 FHandle[FileNumber-1].Write(bufout,0,1);
768 FHandle[FileNumber - 1].Write(Separator,0,1);
772 [MonoTODO("Needs Testing")]
773 public static void WriteLine (System.Int32 FileNumber, params System.Object[] Output)
775 byte[] Separator=new byte[1];
776 byte[] bufout=new Byte[1];
777 byte[] NewLine=new Byte[2];
779 Separator[0]=(byte)',';
780 NewLine[0]=(byte)'\x0D';
781 NewLine[1]=(byte)'\x0A';
782 if (FileNumber<1 || FileNumber>255)
783 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
784 if (FHandle[FileNumber - 1]==null)
785 throw new System.IO.IOException(FileNumber + " does not exists",52);
786 if ( FMode[ FileNumber - 1] != OpenMode.Output )
787 throw new System.IO.IOException ("FileMode is invalid");
788 if (Output.Length == 0)
790 FHandle[FileNumber - 1].Write(NewLine,0,2);
794 for (int MyArgs=0;MyArgs<Output.Length;MyArgs++)
796 MyBuf=WriteAuxiliar(Output[MyArgs]);
797 for (int PutsData=0;PutsData<MyBuf.Length;PutsData++)
799 bufout[0]=(byte)MyBuf[PutsData];
800 FHandle[FileNumber-1].Write(bufout,0,1);
802 if (MyArgs < (Output.Length -1))
804 FHandle[FileNumber - 1].Write(Separator,0,1);
808 FHandle[FileNumber - 1].Write(NewLine,0,2);
813 private static string WriteAuxiliar(Object Argument)
820 switch (Argument.GetType().ToString())
822 case "System.Boolean":
823 if ( (bool)Argument == true)
828 case "System.String":
829 retval="\"" + (string)Argument + "\"";
832 case "System.UInt64":
834 case "System.UInt32":
836 case "System.UInt16":
839 retval = Argument.ToString();
841 case "System.Single":
842 case "System.Double":
843 case "System.Decimal":
844 string buf= (Argument.ToString()) ;
845 if ( buf.IndexOf(",")>=0)
846 retval=buf.Substring(0, buf.IndexOf(","))
847 + "." + buf.Substring(1+buf.IndexOf(","));
849 case "System.Exception":
850 retval=((Exception)Argument).ToString();
853 retval=((char)Argument).ToString();
855 case "System.DateTime":
856 retval=((System.DateTime )Argument).ToString("u");
857 retval=retval.Substring(0,retval.Length -1);
858 if (retval.Substring(11,8)=="00:00:00")
859 retval=retval.Substring(0,10);
860 retval= "#" + retval + "#";
863 throw new NotImplementedException ();
869 [MonoTODO("Needs Testing")]
870 public static System.String InputString (System.Int32 FileNumber, System.Int32 CharCount)
876 if ( FileNumber<1 || FileNumber>255)
877 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
878 if ( FHandle[FileNumber - 1] == null)
879 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
880 if ( (FMode[FileNumber - 1] != OpenMode.Input) && (FMode[FileNumber - 1] != OpenMode.Binary ))
881 throw new System.IO.IOException ("FileMode is invalid");
882 if (CharCount <0 || CharCount>2e14 )
883 throw new System.ArgumentException();
884 if ( (CharCount + FHandle[FileNumber - 1].Position) > FHandle[FileNumber - 1].Length)
885 throw new System.IO.EndOfStreamException();
888 Buf=new byte[CharCount];
889 FHandle[FileNumber - 1].Read(Buf,0,Buf.Length);
890 for (int myloop=0;myloop<Buf.Length;myloop++)
891 retval+=((char)Buf[myloop]).ToString();
894 [MonoTODO("Needs testing")]
895 public static System.String LineInput (System.Int32 FileNumber)
900 if ( FileNumber<1 || FileNumber>255)
901 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
902 if ( FHandle[FileNumber - 1] == null)
903 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
905 if ( EOF(FileNumber) )
906 throw new System.IO.EndOfStreamException();
911 buf=FHandle[FileNumber - 1].ReadByte();
912 if ( (buf == -1) || (buf == '\x0A' ) )
915 retval+= ((char)buf).ToString();
917 if ( retval.Length > 0 )
918 if ( (buf == '\x0A') && (retval[retval.Length -1 ] == '\x0D') )
919 retval=retval.Substring(0,retval.Length -1) ;
925 public static void Lock (System.Int32 FileNumber) { throw new NotImplementedException (); }
927 public static void Lock (System.Int32 FileNumber, System.Int64 Record) { throw new NotImplementedException (); }
929 public static void Lock (System.Int32 FileNumber, System.Int64 FromRecord, System.Int64 ToRecord) { throw new NotImplementedException (); }
931 public static void Unlock (System.Int32 FileNumber) { throw new NotImplementedException (); }
933 public static void Unlock (System.Int32 FileNumber, System.Int64 Record) { throw new NotImplementedException (); }
935 public static void Unlock (System.Int32 FileNumber, System.Int64 FromRecord, System.Int64 ToRecord) { throw new NotImplementedException (); }
937 public static void FileWidth (System.Int32 FileNumber, System.Int32 RecordWidth) { throw new NotImplementedException (); }
939 [MonoTODO("Needs testing")]
940 public static System.Int32 FreeFile ()
944 for (bucle=0;bucle<255;bucle++)
945 if (FHandle[bucle]==null)
951 throw new System.IO.IOException ("More than 255 files are in use",67);
956 public static void Seek (System.Int32 FileNumber, System.Int64 Position) { throw new NotImplementedException (); }
958 public static System.Int64 Seek (System.Int32 FileNumber) { throw new NotImplementedException (); }
960 [MonoTODO("Needs testing")]
961 public static System.Boolean EOF ( System.Int32 FileNumber)
963 if (FileNumber<1 || FileNumber>255)
964 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
965 if ( FHandle[FileNumber - 1] == null)
966 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
967 if ( FHandle[FileNumber - 1].Length == FHandle[FileNumber - 1].Position)
975 public static System.Int64 Loc (System.Int32 FileNumber) { throw new NotImplementedException (); }
977 public static System.Int64 LOF (System.Int32 FileNumber)
979 if (FileNumber<1 || FileNumber>255)
980 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
981 if ( FHandle[FileNumber - 1] == null)
982 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
983 return (System.Int64)FHandle[FileNumber - 1].Length;
986 public static Microsoft.VisualBasic.TabInfo TAB () { throw new NotImplementedException (); }
988 public static Microsoft.VisualBasic.TabInfo TAB (System.Int16 Column) { throw new NotImplementedException (); }
990 public static Microsoft.VisualBasic.SpcInfo SPC (System.Int16 Count) { throw new NotImplementedException (); }
991 [MonoTODO("Needs Testing")]
992 public static Microsoft.VisualBasic.OpenMode FileAttr (System.Int32 FileNumber)
994 if (FileNumber<1 || FileNumber>255)
995 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
996 if ( FHandle[FileNumber - 1] == null)
997 throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
998 return FMode[FileNumber - 1];
1000 [MonoTODO("Needs Testing")]
1001 public static void Reset ()
1003 for(int bucle=0;bucle<255;bucle++)
1005 if (FHandle[bucle]!=null)
1008 FHandle[bucle].Close();
1012 FHandle[bucle]=null ;
1016 [MonoTODO("Needs Testing")]
1017 public static void Rename (System.String OldPath, System.String NewPath)
1019 if ( !File.Exists (OldPath) && !Directory.Exists( OldPath))
1020 throw new System.ArgumentException ( OldPath + " does not exist");
1021 if ( File.Exists ( NewPath) || Directory.Exists ( NewPath))
1022 throw new System.IO.IOException ( NewPath + " already exists");
1023 if ( File.Exists (OldPath))
1024 File.Move (OldPath, NewPath);
1026 Directory.Move (OldPath, NewPath);