Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
Diff: Scripslua/autoLettre.lua
- Revision:
- 15:3874758e8f7d
- Child:
- 16:b1bf03ee2878
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Scripslua/autoLettre.lua Mon Apr 22 13:48:44 2019 +0000
@@ -0,0 +1,95 @@
+/*
+#!/usr/local/bin/lua
+
+function convertFichTable(fichier) --tranforme un fichier en table lua
+ local tab={}
+ local f=io.open(fichier,"r")
+ local num=1
+ local flag=true
+ while f and flag do
+ local lign=f:read()
+ if lign==nil then
+ flag=false
+ else
+ tab[num]=lign
+ end
+ num=num+1
+ end
+ if f then f:close() end
+ return tab
+end
+
+function convertTableFich(tabl,path) --permet d'enregistrer les une table en un fichier
+ f=io.open(path,"w")
+ for i=1,#tabl do
+ f:write(tostring(tabl[i])..'\n')
+ end
+ if #tabl==0 then
+ f:write(" ")
+ end
+ f:close()
+end
+
+function convertSTDout(tabl) --permet d'afficher une table dans stdOut
+ for i=1,#tabl do
+ io.write(tostring(tabl[i])..'\n')
+ end
+ if #tabl==0 then
+ io.write(" ")
+ end
+end
+
+function PBMlecture(tabFich)
+ local ret={}
+ local tailleX=tonumber(tabFich[3]:sub(1,2)) --on annalyse les dimmentions pour préparer la table
+ local tailleY=0
+ if tailleX>9 then
+ tailleY=tonumber(tabFich[3]:sub(4,5))
+ else
+ tailleY=tonumber(tabFich[3]:sub(3,4))
+ end
+ local rawString=tabFich[4] --on met tous les 0 et les 1 à la suite pour simplifier la lecture
+ local i=5
+ while tabFich[i] do
+ rawString=rawString..tabFich[i]
+ i=i+1
+ end
+ --print(rawString, tailleX,tailleY)
+
+ return rawString,tailleX,tailleY --on revoie la chaine de caractère et les dimmentionsrawString,tailleX,tailleY
+end
+
+function lettreAutoLettre(nom,fichierEntree,FichierSortie)
+ local tab=convertFichTable(fichierEntree)
+ local sortie={"matrice *"..nom.."(){"," matrice* ret = (matrice*) malloc(sizeof(matrice));"," (*ret).tailleX="..tostring(#tab[1])..";"," (*ret).tailleY="..tostring(#tab)..";"}
+ for y=1,#tab do
+ sortie[#sortie+1]=""
+ for x=1,#tab[y] do
+ if tab[y]:sub(x,x)=="1" then
+ sortie[#sortie]=sortie[#sortie].." (*ret).tableau["..tostring(y-1).."]["..tostring(x-1).."]=1;"
+ else
+ sortie[#sortie]=sortie[#sortie].." (*ret).tableau["..tostring(y-1).."]["..tostring(x-1).."]=0;"
+ end
+ end
+ end
+ sortie[#sortie+1]=" return ret;"
+ sortie[#sortie+1]="}"
+ if FichierSortie then
+ convertTableFich(sortie,FichierSortie)
+ else
+ convertSTDout(sortie)
+ end
+end
+
+function lettreAuto(nom,fichierEntree,FichierSortie) --transforme le PBM en une table de O et de 1 formatée correctement
+ local rawString,tailleX,tailleY=PBMlecture(convertFichTable(fichierEntree))
+ local tab={}
+ for y=1,tailleY do
+ tab[y]=rawString:sub(tailleX * (y-1) +1,tailleX * (y-1) + tailleX)
+ end
+ convertTableFich(tab,"/tmp/autoLettre")
+ lettreAutoLettre(nom,"/tmp/autoLettre",FichierSortie)
+end
+
+lettreAuto(arg[1],arg[2],arg[3])
+*/
