#
# Usage : simple_cut <chaine> <separateur> <colonne>
#
simple_cut()
{
sep=`echo -e "\006"`
echo -n `echo -n $1 | tr "\n" $sep | tr $2 "\n" | head -n $3 | tail -n 1 | tr $sep "\n"`
}
#
# Usage : simple_cut <chaine> <separateur> <colonne>
#
simple_cut()
{
sep=`echo -e "\006"`
echo -n `echo -n $1 | tr "\n" $sep | tr $2 "\n" | head -n $3 | tail -n 1 | tr $sep "\n"`
}
using System.Reflection;
using System.IO;
namespace Tools
{
public static class PDATool
{
#region Property
public static string ApplicationDirectory
{
get
{
if (PDATool._Path == null) // On calcul la première fois le chemin.
PDATool._Path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().
GetName().CodeBase);
return (PDATool._Path);
}
}
#endregion
#region Attribut
// On conserve une le chemin pour éviter de le recalculer à chaque fois.
private static string _Path = null;
#endregion
}
}
#include <windows.h>
void getMemoryUsage(unsigned long *total,
unsigned long *avail,
float *usage,
unsigned long *virt_total,
unsigned long *virt_avail)
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
if (total != NULL) // mémoire physique totale
*total = (unsigned long)(statex.ullTotalPhys / 1024);
if (avail != NULL) // mémoire physique disponible
*avail = (unsigned long)(statex.ullAvailPhys / 1024);
if (usage != NULL) // pourcentage d'utilisation de la mémoire physique
*usage = (float)(statex.dwMemoryLoad);
if (virt_total != NULL) // mémoire virtuelle totale
*virt_total = (unsigned long)(statex.ullTotalVirtual / 1024);
if (virt_avail != NULL) // mémoire virtuelle disponible
*virt_avail = (unsigned long)(statex.ullAvailVirtual / 1024);
}
#include <windows.h>
unsigned int getCPUcount(void)
{
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return ((unsigned int)sysinfo.dwNumberOfProcessors);
}
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
public class MicroCompiler
{
public MicroCompiler()
{
this.Language = "CSharp";
this.WarningLevel = 1;
this.OutputPath = "./~TMP.exe";
}
public bool Compile()
{
this.Result = string.Empty;
this.KillCompiledProgram();
using (CodeDomProvider codeProvider = CodeDomProvider.CreateProvider(this.Language))
{
// Paramètres de la compilation
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.GenerateInMemory = false;
parameters.WarningLevel = this.WarningLevel;
parameters.OutputAssembly = this.OutputPath;
// on compile
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters,
new string[] { this.Source });
// est ce qu'il y a des erreurs ?
if (results.Errors.Count > 0)
{
foreach (CompilerError CompErr in results.Errors)
this.Result += "Line: " + CompErr.Line + " : " + CompErr.ErrorNumber +
" => " + CompErr.ErrorText + Environment.NewLine;
return (false);
}
}
// on créer le processus pour éxecuter le code
this.CompiledProgram = new Process();
this.CompiledProgram.StartInfo.FileName = this.OutputPath;
return (true);
}
public bool KillCompiledProgram()
{
if (this.CompiledProgram == null || this.CompiledProgram.HasExited)
return (false);
this.CompiledProgram.Kill();
return (true);
}
public bool StartCompiledProgram()
{
if (this.CompiledProgram == null)
return (false);
return (this.CompiledProgram.Start());
}
#region Properties
// Niveau d'avertissement.
public int WarningLevel { get; set; }
// Emplacement du programme généré
public string OutputPath { get; set; }
// Résultat de la compilation
public string Result { get; private set; }
// Le code source
public string Source { get; set; }
// Langage de la source (ex: CSharp)
public string Language { get; set; }
// Instance du programme en exécution.
public Process CompiledProgram { get; private set; }
#endregion
}
namespace Test
{
class Program
{
static void Main(string[] args)
{
MicroCompiler mc = new MicroCompiler();
mc.Source = "mettre le code C# ici!";
if (mc.Compile())
mc.StartCompiledProgram();
}
}
}
#include <windows.h>
int __stdcall FileExistsUnicode(wchar_t *fname)
{
return ((long)GetFileAttributesW(fname) > 0);
}
int __stdcall FileExistsAscii(char *fname)
{
return ((long)GetFileAttributesA(fname) > 0);
}