Diff
checker
Testo
Testo
Immagini
Documenti
Excel
Cartelle
Legal
Enterprise
Applicazione per desktop
Prezzi
Accedi
Scarica Diffchecker Desktop
Confronta il testo
Trova la differenza tra due file di testo
Strumenti
Cronologia
Editor live
Comprimi invariate
Senza a capo
Layout
Diviso
Unificato
Livello di dettaglio
Intelligente
Parola
Carattere
Evidenziazione sintassi
Scegli sintassi
Ignora
Trasforma testo
Vai alla prima modifica
Modifica input
Diffchecker Desktop
Il modo più sicuro per usare Diffchecker. Ottieni l'app Diffchecker Desktop: i tuoi diff non lasciano mai il tuo computer!
Ottieni Desktop
Untitled diff
Creato
11 anni fa
Il diff non scade mai
Eliminare
Esporta
Condividere
Spiegare
12 rimozioni
Linee
Totale
Rimosso
Caratteri
Totale
Rimosso
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
80 linee
Copia tutti
49 aggiunte
Linee
Totale
Aggiunto
Caratteri
Totale
Aggiunto
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
120 linee
Copia tutti
Copia
Copiato
Copia
Copiato
import Control.Concurrent
import Control.Concurrent.STM
import Control.Concurrent.STM
import Control.Concurrent.STM.TVar
import Control.Concurrent.STM.TVar
Copia
Copiato
Copia
Copiato
import Control.Monad
import System.Directory
import System.Directory
import System.Environment (getArgs)
import System.Environment (getArgs)
Copia
Copiato
Copia
Copiato
import System.Exit
import System.INotify
import System.INotify
import System.IO
import System.IO
Copia
Copiato
Copia
Copiato
import System.Process
data Config =
data Config =
Config
Config
Copia
Copiato
Copia
Copiato
{
confCabalFile :: FilePath
{
confOutputFile :: FilePath
,
confCabalFile :: FilePath
, confWorking :: Bool
, confWorking :: Bool
} deriving (Show,Read)
} deriving (Show,Read)
main = do
main = do
args <- getArgs
args <- getArgs
let dir = head args
let dir = head args
Copia
Copiato
Copia
Copiato
let cabalOutput = args !! 1
putStrLn $ "Watching directory: " ++ dir
putStrLn $ "Watching directory: " ++ dir
Copia
Copiato
Copia
Copiato
putStrLn $ "Cabal output file: " ++ cabalOutput
contents <- getDirectoryContents dir
contents <- getDirectoryContents dir
let contents' = filter filterCabal contents
let contents' = filter filterCabal contents
case contents' of
case contents' of
Copia
Copiato
Copia
Copiato
(x:_) ->
runThread
x
dir
(x:_) ->
do
let config = Config cabalOutput x False
runThread
config
dir
[] -> do
[] -> do
putStrLn "No cabal file found!"
putStrLn "No cabal file found!"
putStrLn "Exiting"
putStrLn "Exiting"
Copia
Copiato
Copia
Copiato
runThread
cabal
dir = do
runThread
config
dir = do
config <- newTVarIO
$ C
onfig
cabal False
config <- newTVarIO
c
onfig
n <- initINotify
n <- initINotify
putStrLn "Press <Enter> to exit"
putStrLn "Press <Enter> to exit"
print n
print n
wd <- addWatch n
wd <- addWatch n
[ Modify, CloseWrite, Create, Delete, MoveIn, MoveOut ]
[ Modify, CloseWrite, Create, Delete, MoveIn, MoveOut ]
dir
dir
(eventHandler config)
(eventHandler config)
print wd
print wd
getLine
getLine
removeWatch wd
removeWatch wd
killINotify n
killINotify n
eventHandler :: TVar Config -> Event -> IO ()
eventHandler :: TVar Config -> Event -> IO ()
eventHandler conf x@(Modified _ (Just fp)) = handleFilteredFile conf x fp
eventHandler conf x@(Modified _ (Just fp)) = handleFilteredFile conf x fp
eventHandler conf x@(MovedIn _ fp _) = handleFilteredFile conf x fp
eventHandler conf x@(MovedIn _ fp _) = handleFilteredFile conf x fp
eventHandler conf x@(MovedOut _ fp _) = handleFilteredFile conf x fp
eventHandler conf x@(MovedOut _ fp _) = handleFilteredFile conf x fp
eventHandler conf x@(Created _ fp) = handleFilteredFile conf x fp
eventHandler conf x@(Created _ fp) = handleFilteredFile conf x fp
eventHandler conf x@(Deleted _ fp) = handleFilteredFile conf x fp
eventHandler conf x@(Deleted _ fp) = handleFilteredFile conf x fp
eventHandler _ _ = return ()
eventHandler _ _ = return ()
Copia
Copiato
Copia
Copiato
handleFilteredFile conf evt fp =
do
handleFilteredFile conf evt fp =
if
filterHS fp
when (
filterHS fp
) $
print evt >> doWork conf
then
print evt >> doWork conf
fp
else return ()
filterHS fp = fileExt fp == "hs"
filterHS fp = fileExt fp == "hs"
filterCabal fp = fileExt fp == "cabal"
filterCabal fp = fileExt fp == "cabal"
fileExt = reverse
fileExt = reverse
. takeWhile (/= '.')
. takeWhile (/= '.')
. reverse
. reverse
Copia
Copiato
Copia
Copiato
doWork :: TVar Config ->
FilePath ->
IO ()
doWork :: TVar Config ->
IO ()
doWork conf
fp
= do
doWork conf
= do
config <- readTVarIO conf
config <- readTVarIO conf
if confWorking config
if confWorking config
then do
then do
print "Already working!"
print "Already working!"
return ()
return ()
else do
else do
print "New work available!"
print "New work available!"
atomically $ writeTVar conf (config { confWorking = True })
atomically $ writeTVar conf (config { confWorking = True })
Copia
Copiato
Copia
Copiato
_ <- forkIO $ runCI conf
return ()
return ()
Copia
Copiato
Copia
Copiato
runCI :: TVar Config -> IO ()
runCI conf = do
runCIChain conf
config <- readTVarIO conf
atomically $ writeTVar conf (config { confWorking = False })
return ()
runCIChain :: TVar Config -> IO ()
runCIChain conf = do
cabalBuild <- runCabal conf ["build"]
print $ "*** cabal build result: " ++ show cabalBuild
case cabalBuild of
False -> return ()
True -> do
cabalTest <- runCabal conf ["test"]
print $ "*** cabal test result: " ++ show cabalTest
runCabal :: TVar Config -> [String] -> IO Bool
runCabal conf args = do
(code, out, err) <- readProcessWithExitCode "cabal" args ""
config <- readTVarIO conf
let outputFile = confOutputFile config
_ <- when (out /= []) $ appendFile outputFile out
_ <- when (err /= []) $ appendFile outputFile err
case code of
ExitSuccess -> return True
ExitFailure _ -> return False
Diff salvati
Testo originale
Apri file
import Control.Concurrent.STM import Control.Concurrent.STM.TVar import System.Directory import System.Environment (getArgs) import System.INotify import System.IO data Config = Config { confCabalFile :: FilePath , confWorking :: Bool } deriving (Show,Read) main = do args <- getArgs let dir = head args putStrLn $ "Watching directory: " ++ dir contents <- getDirectoryContents dir let contents' = filter filterCabal contents case contents' of (x:_) -> runThread x dir [] -> do putStrLn "No cabal file found!" putStrLn "Exiting" runThread cabal dir = do config <- newTVarIO $ Config cabal False n <- initINotify putStrLn "Press <Enter> to exit" print n wd <- addWatch n [ Modify, CloseWrite, Create, Delete, MoveIn, MoveOut ] dir (eventHandler config) print wd getLine removeWatch wd killINotify n eventHandler :: TVar Config -> Event -> IO () eventHandler conf x@(Modified _ (Just fp)) = handleFilteredFile conf x fp eventHandler conf x@(MovedIn _ fp _) = handleFilteredFile conf x fp eventHandler conf x@(MovedOut _ fp _) = handleFilteredFile conf x fp eventHandler conf x@(Created _ fp) = handleFilteredFile conf x fp eventHandler conf x@(Deleted _ fp) = handleFilteredFile conf x fp eventHandler _ _ = return () handleFilteredFile conf evt fp = do if filterHS fp then print evt >> doWork conf fp else return () filterHS fp = fileExt fp == "hs" filterCabal fp = fileExt fp == "cabal" fileExt = reverse . takeWhile (/= '.') . reverse doWork :: TVar Config -> FilePath -> IO () doWork conf fp = do config <- readTVarIO conf if confWorking config then do print "Already working!" return () else do print "New work available!" atomically $ writeTVar conf (config { confWorking = True }) return ()
Testo modificato
Apri file
import Control.Concurrent import Control.Concurrent.STM import Control.Concurrent.STM.TVar import Control.Monad import System.Directory import System.Environment (getArgs) import System.Exit import System.INotify import System.IO import System.Process data Config = Config { confOutputFile :: FilePath , confCabalFile :: FilePath , confWorking :: Bool } deriving (Show,Read) main = do args <- getArgs let dir = head args let cabalOutput = args !! 1 putStrLn $ "Watching directory: " ++ dir putStrLn $ "Cabal output file: " ++ cabalOutput contents <- getDirectoryContents dir let contents' = filter filterCabal contents case contents' of (x:_) -> do let config = Config cabalOutput x False runThread config dir [] -> do putStrLn "No cabal file found!" putStrLn "Exiting" runThread config dir = do config <- newTVarIO config n <- initINotify putStrLn "Press <Enter> to exit" print n wd <- addWatch n [ Modify, CloseWrite, Create, Delete, MoveIn, MoveOut ] dir (eventHandler config) print wd getLine removeWatch wd killINotify n eventHandler :: TVar Config -> Event -> IO () eventHandler conf x@(Modified _ (Just fp)) = handleFilteredFile conf x fp eventHandler conf x@(MovedIn _ fp _) = handleFilteredFile conf x fp eventHandler conf x@(MovedOut _ fp _) = handleFilteredFile conf x fp eventHandler conf x@(Created _ fp) = handleFilteredFile conf x fp eventHandler conf x@(Deleted _ fp) = handleFilteredFile conf x fp eventHandler _ _ = return () handleFilteredFile conf evt fp = when (filterHS fp) $ print evt >> doWork conf filterHS fp = fileExt fp == "hs" filterCabal fp = fileExt fp == "cabal" fileExt = reverse . takeWhile (/= '.') . reverse doWork :: TVar Config -> IO () doWork conf = do config <- readTVarIO conf if confWorking config then do print "Already working!" return () else do print "New work available!" atomically $ writeTVar conf (config { confWorking = True }) _ <- forkIO $ runCI conf return () runCI :: TVar Config -> IO () runCI conf = do runCIChain conf config <- readTVarIO conf atomically $ writeTVar conf (config { confWorking = False }) return () runCIChain :: TVar Config -> IO () runCIChain conf = do cabalBuild <- runCabal conf ["build"] print $ "*** cabal build result: " ++ show cabalBuild case cabalBuild of False -> return () True -> do cabalTest <- runCabal conf ["test"] print $ "*** cabal test result: " ++ show cabalTest runCabal :: TVar Config -> [String] -> IO Bool runCabal conf args = do (code, out, err) <- readProcessWithExitCode "cabal" args "" config <- readTVarIO conf let outputFile = confOutputFile config _ <- when (out /= []) $ appendFile outputFile out _ <- when (err /= []) $ appendFile outputFile err case code of ExitSuccess -> return True ExitFailure _ -> return False
Trovare la differenza