Recovered from cvs revision 2007-09-07 03:08:00
This commit is contained in:
@ -12,6 +12,17 @@ namespace ase.net
|
||||
System.Windows.Forms.TextBox consoleInput;
|
||||
System.Windows.Forms.TextBox consoleOutput;
|
||||
|
||||
System.ComponentModel.ISynchronizeInvoke si;
|
||||
|
||||
public Awk(System.ComponentModel.ISynchronizeInvoke si)
|
||||
{
|
||||
this.si = si;
|
||||
SetSourceOutputHandlers += SetSourceOutput;
|
||||
SetConsoleOutputHandlers += SetConsoleOutput;
|
||||
|
||||
AddFunction("sleep", 1, 1, Sleep);
|
||||
}
|
||||
|
||||
public bool Parse(
|
||||
System.Windows.Forms.TextBox sourceInput,
|
||||
System.Windows.Forms.TextBox sourceOutput)
|
||||
@ -31,6 +42,13 @@ namespace ase.net
|
||||
return base.Run(main, args);
|
||||
}
|
||||
|
||||
protected bool Sleep(string name, Argument[] args, Return ret)
|
||||
{
|
||||
System.Threading.Thread.Sleep((int)(args[0].LongValue*1000));
|
||||
ret.LongValue = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override int OpenSource(ASE.Net.StdAwk.Source source)
|
||||
{
|
||||
//System.IO.FileMode mode;
|
||||
@ -63,6 +81,22 @@ namespace ase.net
|
||||
return -1;
|
||||
}
|
||||
|
||||
public delegate void SetSourceOutputHandler(string text);
|
||||
public delegate void SetConsoleOutputHandler(string text);
|
||||
|
||||
public event SetSourceOutputHandler SetSourceOutputHandlers;
|
||||
public event SetConsoleOutputHandler SetConsoleOutputHandlers;
|
||||
|
||||
private void SetSourceOutput(string text)
|
||||
{
|
||||
sourceOutput.Text = text;
|
||||
}
|
||||
|
||||
private void SetConsoleOutput(string text)
|
||||
{
|
||||
consoleOutput.Text = text;
|
||||
}
|
||||
|
||||
protected override int CloseSource(ASE.Net.StdAwk.Source source)
|
||||
{
|
||||
if (source.Mode.Equals(ASE.Net.StdAwk.Source.MODE.READ))
|
||||
@ -75,9 +109,16 @@ namespace ase.net
|
||||
{
|
||||
System.IO.StreamWriter sw = (System.IO.StreamWriter)source.Handle;
|
||||
sw.Flush();
|
||||
|
||||
System.IO.MemoryStream ms = (System.IO.MemoryStream)sw.BaseStream;
|
||||
sourceOutput.Text = UnicodeEncoding.UTF8.GetString(ms.GetBuffer());
|
||||
sw.Close();
|
||||
|
||||
// MSDN: This method(GetBuffer) works when the memory stream is closed.
|
||||
//sourceOutput.Text = UnicodeEncoding.UTF8.GetString(ms.GetBuffer());
|
||||
if (si != null && si.InvokeRequired)
|
||||
si.Invoke(SetSourceOutputHandlers, new object[] { UnicodeEncoding.UTF8.GetString(ms.GetBuffer()) });
|
||||
else SetSourceOutput (UnicodeEncoding.UTF8.GetString(ms.GetBuffer()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -130,9 +171,16 @@ namespace ase.net
|
||||
{
|
||||
System.IO.StreamWriter sw = (System.IO.StreamWriter)console.Handle;
|
||||
sw.Flush();
|
||||
|
||||
System.IO.MemoryStream ms = (System.IO.MemoryStream)sw.BaseStream;
|
||||
consoleOutput.Text = UnicodeEncoding.UTF8.GetString(ms.GetBuffer());
|
||||
sw.Close();
|
||||
|
||||
// MSDN: This method(GetBuffer) works when the memory stream is closed.
|
||||
//consoleOutput.Text = UnicodeEncoding.UTF8.GetString(ms.GetBuffer());
|
||||
if (si != null && si.InvokeRequired)
|
||||
si.Invoke(SetConsoleOutputHandlers, new object[] { UnicodeEncoding.UTF8.GetString(ms.GetBuffer()) });
|
||||
else SetConsoleOutput(UnicodeEncoding.UTF8.GetString(ms.GetBuffer()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -141,7 +189,7 @@ namespace ase.net
|
||||
|
||||
protected override int ReadConsole(ASE.Net.StdAwk.Console console, char[] buf, int len)
|
||||
{
|
||||
System.IO.StreamReader sr = (System.IO.StreamReader)console.Handle;
|
||||
System.IO.StreamReader sr = (System.IO.StreamReader)console.Handle;
|
||||
return sr.Read(buf, 0, len);
|
||||
}
|
||||
|
||||
@ -149,6 +197,7 @@ namespace ase.net
|
||||
{
|
||||
System.IO.StreamWriter sw = (System.IO.StreamWriter)console.Handle;
|
||||
sw.Write(buf, 0, len);
|
||||
sw.Flush();
|
||||
return len;
|
||||
}
|
||||
|
||||
|
26
ase/test/net/AwkForm.Designer.cs
generated
26
ase/test/net/AwkForm.Designer.cs
generated
@ -47,12 +47,12 @@ namespace ase.net
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.chkStripSpaces = new System.Windows.Forms.CheckBox();
|
||||
this.chkPassArgumentsToEntryPoint = new System.Windows.Forms.CheckBox();
|
||||
this.btnClearAllArguments = new System.Windows.Forms.Button();
|
||||
this.btnAddArgument = new System.Windows.Forms.Button();
|
||||
this.tbxArgument = new System.Windows.Forms.TextBox();
|
||||
this.lbxArguments = new System.Windows.Forms.ListBox();
|
||||
this.chkStripSpaces = new System.Windows.Forms.CheckBox();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.panel3.SuspendLayout();
|
||||
@ -281,6 +281,18 @@ namespace ase.net
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Arguments";
|
||||
//
|
||||
// chkStripSpaces
|
||||
//
|
||||
this.chkStripSpaces.AutoSize = true;
|
||||
this.chkStripSpaces.Checked = true;
|
||||
this.chkStripSpaces.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.chkStripSpaces.Location = new System.Drawing.Point(19, 234);
|
||||
this.chkStripSpaces.Name = "chkStripSpaces";
|
||||
this.chkStripSpaces.Size = new System.Drawing.Size(86, 17);
|
||||
this.chkStripSpaces.TabIndex = 5;
|
||||
this.chkStripSpaces.Text = "Strip Spaces";
|
||||
this.chkStripSpaces.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// chkPassArgumentsToEntryPoint
|
||||
//
|
||||
this.chkPassArgumentsToEntryPoint.AutoSize = true;
|
||||
@ -328,18 +340,6 @@ namespace ase.net
|
||||
this.lbxArguments.Size = new System.Drawing.Size(147, 134);
|
||||
this.lbxArguments.TabIndex = 0;
|
||||
//
|
||||
// chkStripSpaces
|
||||
//
|
||||
this.chkStripSpaces.AutoSize = true;
|
||||
this.chkStripSpaces.Checked = true;
|
||||
this.chkStripSpaces.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.chkStripSpaces.Location = new System.Drawing.Point(19, 234);
|
||||
this.chkStripSpaces.Name = "chkStripSpaces";
|
||||
this.chkStripSpaces.Size = new System.Drawing.Size(86, 17);
|
||||
this.chkStripSpaces.TabIndex = 5;
|
||||
this.chkStripSpaces.Text = "Strip Spaces";
|
||||
this.chkStripSpaces.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// AwkForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user