Just another WordPress.com site

2011/06/08” タグの投稿

[Text]:My Opera コミュニティ Opera ユーザー登録 ログイン ブログ アーカイブ

[2011/06/08 17:41:19]: {sub_text}

My Opera
コミュニティ
Opera
ユーザー登録
ログイン
ブログ
アーカイブ
フォト
リンク
メンバー
プロフィール
メンバー
Atsuko Takano (anettai08)
Daniel Davis (tagawa)
Aya Ring (ayaring)
HABAAlisa (HABAAlisa)
kyu3 (kyu3)
Soumitram4u. (soumitram4u)
Mio (mioa)
mrk cradoll (cradoll)
Opera Japan Desktop (japan-desktop)
mattz (mattz)
itochan (itochan)
謎の元気配達人 (謎の元気配達人)
t.ashula (t-ashula)
AO (ux50)
Ozu Yasujiro (Yamatofan)
Andreas Bovens (andreasbovens)
Michael Vacik (mcx)
Arno (Herrscher)
saito (saito)
Ai (aida4str)
J. Maurice (wiz)
kisaragi (kisaragi)
Opera9.5 (Opera9.5)
Alexandra (alexdavydova)
Multipl (multipl)
Go Uehiro (mopera)
ko77 (ko77)
Masusam7 (minoame67)
albireo (albireo)
急襲 (Blitzstreik)
norn (norn)
GouldH (GouldH)
kyoya (kyoya)
Satoru Watanabe (Watanabe)
pande (pandesris)
坂取 (sakatori)
Lawrence Eng (Lawmune)
minel (minelowl)
kakuremino (kakuremino)

1
2
3
4
5
Next ≫

Download Opera for your phoneヘルプ/FAQ | 規約 | Web analytics powered by HitsLink

言語:


[Text]: string buffer = string.Empty;

[2011/06/08 17:24:49]: {sub_text}

string buffer = string.Empty;
int allLines = 0;
string line = string.Empty;
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader sr = new StreamReader(fs, Encoding.Default))
{
while (sr.ReadLine() != null)
allLines++;
fs.Seek(0, SeekOrigin.Begin);
if (allLines <= outputLines)
buffer = sr.ReadToEnd();
else
{
for (int i = 0; i allLines – outputLines – 1)
buffer += line + “\n”;
}
}

Console.WriteLine(buffer);

while (fOption)
{
System.Threading.Thread.Sleep(SLEEP_TIME);
while ((line = sr.ReadLine()) != null)
Console.WriteLine(line);
}
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message.ToString());
Console.Error.WriteLine(usage);
}


[Text]: private const int SLEEP_TIME = 1000;  priva

[2011/06/08 17:13:53]: {sub_text}

private const int SLEEP_TIME = 1000;
private static bool fOption = false;
private static int outputLines = 10;
private static string filename = string.Empty;
private static string usage = “Usage: Tail.exe [-n number] [-f] filename”;

static void Main(string[] args)
{
try {
for (int i = 0; i < args.Length; i++) {
if (args[i][0] == '-') {
switch (args[i][1]) {
case 'n':
outputLines = int.Parse(args[++i]);
break;
case 'f':
fOption = true;
break;
default:
Console.Error.WriteLine("Invalid Option: {0}", args[i]);
Console.Error.WriteLine(usage);
return;
}
}
else
filename = args[i];
}

string buffer = string.Empty;
int allLines = 0;
string line = string.Empty;
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
using (StreamReader sr = new StreamReader(fs, Encoding.Default)) {
while (sr.ReadLine() != null)
allLines++;
fs.Seek(0, SeekOrigin.Begin);
if (allLines <= outputLines)
buffer = sr.ReadToEnd();
else {
for (int i = 0; i allLines – outputLines – 1)
buffer += line + “\n”;
}
}

Console.WriteLine(buffer);

while (fOption) {
Thread.Sleep(SLEEP_TIME);
while ((line = sr.ReadLine()) != null)
Console.WriteLine(line);
}
}
}
}
catch (Exception ex) {
Console.Error.WriteLine(ex.Message.ToString());
Console.Error.WriteLine(usage);
}
}


[Text]: string operafilename = @”\Opera\Opera\

[2011/06/08 16:52:25]: {sub_text}

string operafilename = @”\Opera\Opera\global_history.dat”;
string filename = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + operafilename;


[Text]: string operafilename = @”\Opera\Opera\

[2011/06/08 16:52:18]: {sub_text}

string operafilename = @”\Opera\Opera\global_history.dat”;
string filename = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + operafilename;

var o = new FileWatcherEasy(filename, NotifyFilters.LastWrite);
o.Start();

while(true)
{
System.Threading.Thread.Sleep(10000);
if (o.IsChange()) { Console.WriteLine(“modify”); o.Stop(); o.Start(); };
}


[Text]: class FileWatcherEasy {  /*

[2011/06/08 16:49:52]: {sub_text}

class FileWatcherEasy
{
/*
* string filename =@”c:\hogehoge\fafa.txt”;
* var o = new FileWatcherEasy(filename, NotifyFilters.LastWrite);
* o.Start();
* while(true)
* {
* System.Threading.Thread.Sleep(10000);
* if (o.IsChange())
* {
* Console.WriteLine(“modify”);
* o.Stop();
* //…..
* o.Start();
* };
* }
*/

string f;
bool cflg;
FileSystemWatcher fsw;
public FileWatcherEasy(string filename, NotifyFilters n)
{
f = filename;
cflg = false;
fsw = new FileSystemWatcher(Path.GetDirectoryName(f),Path.GetFileName(f));
fsw.NotifyFilter = n;
fsw.Changed += (ss, ee) => { cflg = true; }; //(object sender, FileSystemEventArgs e)
}

public void Start()
{
if (!File.Exists(f)) return;
this.cflg = false;
fsw.EnableRaisingEvents = true;
}

public bool IsChange()
{
return cflg;
}

public void Stop()
{
this.cflg = false;
fsw.EnableRaisingEvents = false;
}

}


[Text]:var o = new FileWatcherEasy(filename, NotifyFilter

[2011/06/08 16:45:24]: {sub_text}

var o = new FileWatcherEasy(filename, NotifyFilters.LastWrite);
o.Start();

while(true)
{
System.Threading.Thread.Sleep(10000);
if (o.IsChange()) { Console.WriteLine(“modify”); o.Stop(); o.Start(); };
}


[Text]: string operafilename = @”\Opera\Opera\

[2011/06/08 16:29:52]: {sub_text}

string operafilename = @”\Opera\Opera\global_history.dat”;
string filename = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + operafilename;


[Text]: if (!File.Exists(filename))

[2011/06/08 16:28:20]: {sub_text}

if (!File.Exists(filename))
{
Console.Write(“noexist”);
return;
}


[Text]: //C:\Users\mono\AppData\Roaming\Opera\O

[2011/06/08 16:27:04]: {sub_text}

//C:\Users\mono\AppData\Roaming\Opera\Opera\global_history.dat;
string operafilename = @”\Opera\Opera\global_history.dat”;
string filename = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + operafilename;

if(!File.Exists(filename))
{
Console.Write(“noexist”);
return;
}

FileSystemWatcher fsw = new FileSystemWatcher(
Path.GetDirectoryName(filename),
Path.GetFileName(filename));
fsw.NotifyFilter = NotifyFilters.LastWrite;// NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

fsw.Changed += (ss,ee) =>//(object sender, FileSystemEventArgs e)
{
Console.WriteLine(“File: ” + ee.FullPath + ” ” + ee.ChangeType);
};
fsw.EnableRaisingEvents = true;
while (true)
fsw.WaitForChanged(WatcherChangeTypes.All);


[Text]: fsw.EnableRaisingEvents = true;

[2011/06/08 16:25:42]: {sub_text}

fsw.EnableRaisingEvents = true;
while (true)
fsw.WaitForChanged(WatcherChangeTypes.All);


[Text]:fsw.Changed += (ss,ee) =>//(object sender, FileSys

[2011/06/08 16:24:59]: {sub_text}

fsw.Changed += (ss,ee) =>//(object sender, FileSystemEventArgs e)
{
Console.WriteLine(“File: ” + ee.FullPath + ” ” + ee.ChangeType);
};


[Text]: FileSystemWatcher fsw = new FileSystem

[2011/06/08 16:24:38]: {sub_text}

FileSystemWatcher fsw = new FileSystemWatcher(
Path.GetDirectoryName(filename),
Path.GetFileName(filename));
fsw.NotifyFilter = NotifyFilters.LastWrite;// NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;


[Text]:NotifyFilters.LastAccess | NotifyFilters.LastWrite

[2011/06/08 16:10:06]: {sub_text}

NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;


[Text]:using System; using System.IO; class Program

[2011/06/08 15:55:37]: {sub_text}

using System;
using System.IO;

class Program
{
static void Main()
{
string filename = @”c:\test.txt”;
FileSystemWatcher fsw = new FileSystemWatcher(
Path.GetDirectoryName(filename),
Path.GetFileName(filename));
fsw.Changed += delegate(object sender, FileSystemEventArgs e)
{
Console.WriteLine(“modified!”);
};
while (true)
fsw.WaitForChanged(WatcherChangeTypes.All);
}
}


[Text]:どう書く?org tailの実装 takeru #6818(2008-07-24

[2011/06/08 15:38:40]: {sub_text}

どう書く?org
tailの実装

takeru #6818(2008-07-24 13:57) 評価-10/12=-0.83

‘tail’を実装してください。

巨大なファイルでも効率的に動作するようにしてください。

最低限必要な機能は、
行数指定
「-f」パラメータの対応

です。
タグ: なし 評価-10/12=-0.83-0+

[ 返信 ]
コメントを投稿する
投稿されたコメント – ネスト表示
フラット表示 非表示

あにす #6997(2008-08-06 16:45) 評価0/0=0.00
tailの仕様がわかりません。
検索すると概要はわかるのですが、実際にどういった動作をさせれば良いのでしょう?
UNIX環境が無いのでどうしたらよいのか…。
タグ: なし 評価0/0=0.00-0+

1 reply [ 返信 ]

raynstard #7042(2008-08-07 17:14) 評価0/0=0.00
たしかにお題を出す人にも、もうすこし丁寧に出題してほしい感じがしますね。

たぶんですが、
意訳すると以下のような感じになるのではないでしょうか?
1. 指定されたファイルの最後尾から N行表示すること
2. ファイルの更新を監視して、指定のファイルが更新された場合に、
更新分のうち、最後尾からN行を表示すること

「2.」更新分なので前回表示続きからという点が注意事項だと思います。

# 「-f」 を実装しなさいというあたり、
以前あったファイルの更新を監視するお題の
派生と考えられるのかな?
タグ: なし 評価0/0=0.00-0+

[ 返信 ]

nobsun #7626(2008-09-11 06:23) [ Haskell ] 評価0/0=0.00

とりあえず実装してみたというレベル Data.Sequenceを使ってみた 効率については考えてない orz 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 module Main where

import Control.Concurrent
import Data.Foldable
import Data.Sequence
import Prelude hiding (foldl,concat,mapM_)
import System.Console.GetOpt
import System.Environment
import System.IO

data Options = Options
{ optFollowed :: Bool
, optNumber :: Int
} deriving Show

defaultOptions = Options
{ optFollowed = False
, optNumber = 10
}

options :: [OptDescr (Options -> Options)]
options
= [ Option [‘f’] [] (NoArg (\ opts -> opts { optFollowed = True }))
“followed by addition to the file”
, Option [‘n’] [] (ReqArg (\ d opts -> opts { optNumber = read d }) “NUMBER”)
“display last NUMBER lines”]

compileOpts :: [String] -> IO (Options, [String])
compileOpts argv
= case getOpt Permute options argv of
(o,n,[] ) -> return (foldl (flip id) defaultOptions o, n)
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
where header = “Usage : tail [OPTION..] file”

main :: IO ()
main = getArgs >>= compileOpts >>= tail’

tail’ :: (Options, [String]) -> IO ()
tail’ (o,fs) = openFile (head fs) ReadMode
>>= loop empty (optNumber o) 0 (optFollowed o)

loop :: Seq String -> Int -> Int -> Bool -> Handle -> IO ()
loop q n i f h
= do { eof > lineCat h
else do { l i then loop (q |> l) n (i+1) f h
else case viewl q of
_ : loop (qs |> l) n n f h
}
}

printQ :: Seq String -> IO ()
printQ = mapM_ putStrLn

lineCat :: Handle -> IO ()
lineCat h = do { eof > lineCat h
else hGetLine h >>= putStrLn >> lineCat h
}

タグ: なし [ Haskell ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

ihag #8179(2008-12-15 15:37) [ C ] 評価0/0=0.00

行数を後ろから数えるのが面倒だなぁ,と思ったけど,よくよく考えたらmmap(2)してポインタ経由で後ろから読めばいいだけの話でした. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 #include
#include
#include
#include
#include
#include
#include

#ifndef false
# define false 0
#endif
#ifndef true
# define true !false
#endif

#define handle_error(str) \
do { perror(str); exit(EXIT_FAILURE); } while(0)

static const char *myname;

void
usage(void)
{
fprintf(stderr, “usage: %s [-n ] [-f] \n”, myname);
exit(EXIT_FAILURE);
}

void
do_flush(int fd, size_t offset, size_t file_size)
{
u_char buf[8192], *buf_p;
size_t len_r, len_w, remain_byte;

for (remain_byte = file_size – offset;
remain_byte > 0;
remain_byte -= len_r) {
if ((len_r = read(fd, buf, sizeof(buf))) == -1)
handle_error(“read”);
for (buf_p = buf; (buf_p – buf) = head; last = cur–) {
if (*cur == ‘\n’)
if (++lines > line_max)
break;
}
while ((len = write(1, last, file_size – (last – head))) > 0)
last += len;
if (len == -1)
handle_error(“write”);

if (munmap(head, file_size) == -1)
handle_error(“munmap”);
}

void
do_tailf(int fd, size_t file_size)
{
struct stat sb;

if (lseek(fd, file_size, SEEK_SET) == -1)
handle_error(“lseek”);

while (true) {
if (fstat(fd, &sb) == -1)
handle_error(“fstat”);
if (sb.st_size > file_size)
do_flush(fd, file_size, sb.st_size);
file_size = sb.st_size;
sleep(1);
}
}

void
process_file(char *filename, int line_max, int f_tailf, int f_header)
{
int fd;
size_t file_size;

if (f_header)
printf(“==> %s 0)
do_tail(fd, file_size, line_max);
if (f_tailf)
do_tailf(fd, file_size);

close(fd);
}

int
main(int argc, char **argv)
{
int ch;
int line_max = 10, f_tailf = false;

myname = argv[0];
while ((ch = getopt(argc, argv, “fn:”)) != -1) {
switch (ch) {
case ‘f’:
f_tailf = true;
break;
case ‘n’:
line_max = atoi(optarg);
break;
case ‘?’:
default:
usage();
}
}
argc -= optind; argv += optind;
if (argc 1));
argv++;
}

exit(EXIT_SUCCESS);
}

タグ: なし [ C ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

1 reply [ 返信 ]

ihag #8183(2008-12-15 18:45) [ diff ] 評価0/0=0.00

ちょうど気を抜いたところでバグってました.うーん. 1
2
3
4
5
6
7
8
9
10
11 — tail.c.orig 2008-12-15 21:28:50.000000000 +0900
+++ tail.c 2008-12-16 00:39:44.000000000 +0900
@@ -37,7 +37,7 @@
if ((len_r = read(fd, buf, sizeof(buf))) == -1)
handle_error(“read”);
for (buf_p = buf; (buf_p – buf) < len_r; buf_p += len_w)
– if ((len_w = write(1, buf, len_r)) == -1)
+ if ((len_w = write(1, buf_p, len_r – (buf_p – buf))) == -1)
handle_error("write");
}
}

タグ: なし [ diff ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

匿名 #7081(2008-08-10 06:26) [ Java ] 評価0/0=0.00
対象がファイルの場合には、予めファイル末尾を基準にシークします。これによってファイルサイズに依存しない処理時間を実現しています。

起動方法は

java Tail [-f] [-] []
-f: ファイル末尾まで読み込んでも終了せず、ファイルが成長した部分をポーリングで表示する(ファイル名を与えない場合は無視する)。
num: ファイル末尾からnum行を表示する(デフォルトは10行)。
ファイル名: 表示するファイル名。省略した場合は標準入力。

です。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 import java.io.*;

public class Tail {
private static final int MAX_LINE_LENGTH = 1000;
private static final long SLEEP_TIME = 500; // 500 m sec
private static int numOfLine = 10;
private static boolean fOption = false;
private static String fileName = null;
private static InputStream targetStream = System.in;

public static void main(String[] args) throws Exception {
for (String s: args) {
if (“-help”.equals(s)) {
System.err.println(“Usage> java Tail [-f] [-] [filename]”);
return;
}
else if (“-f”.equals(s))
fOption = true;
else if (s.startsWith(“-“))
numOfLine = -Integer.parseInt(s);
else
fileName = s;
}

if (fileName != null) {
File target = new File(fileName);
long len = target.length();
targetStream = new FileInputStream(target);
len -= MAX_LINE_LENGTH * numOfLine;
if (len > 0)
targetStream.skip(len);
}
BufferedReader br = new BufferedReader(new InputStreamReader(targetStream));
String line;
String[] lines = new String[numOfLine];
int ip = 0;
while ((line = br.readLine()) != null) {
lines[ip] = line;
if (++ip >= numOfLine)
ip = 0;
}
int i = ip;
do {
if (lines[i] != null)
System.out.println(lines[i]);
if (++i >= numOfLine)
i = 0;
} while (i != ip);
if (fOption && fileName != null) {
while (true) {
Thread.sleep(SLEEP_TIME);
line = br.readLine();
if (line != null)
System.out.println(line);
}
}
}
}

タグ: なし [ Java ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

silverwire #7213(2008-08-19 16:52) [ Batchfile ] 評価0/0=0.00
バッチです。カバレッジ稼ぎのようでちょっと恥ずかしいのですが、あまり処理を複雑に
したくなかったので、標準入力からの入力や-fオプションは実装しませんでした。

e.g.
C:\>tail 3 tail.bat
set /a i-=%1
endlocal & more +%i% %p%
goto :EOF

以下の参考サイトのものはもっと複雑で頭が下がります。

参考: 【続々々】tailコマンドの作成 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 :: tail.bat
@echo off
setlocal
set i=0
set p=%~fs2

echo %1|findstr /r “[^0-9]” >NUL 2>&1
if %ERRORLEVEL% equ 0 (call :usage & exit /b 1)

if “%p%” equ “” (call :usage & exit /b 1)

if not exist %p% (call :usage & exit /b 1)

for /f %%i in (‘find /c /v “” ^list q)))
(when f?
(with-signal-handlers ((SIGINT => (lambda _ (exit 0))))
(lambda ()
(let ((sel (make )))
(selector-add! sel
iport
(lambda (input _)
(and-let* ((line (read-line input))
((not (eof-object? line))))
(print line))
(sys-sleep 1))
‘(r))
(while #t (selector-select sel))))))
0))))

タグ: なし [ Scheme ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

seri #7175(2008-08-18 01:55) [ C# ] 評価0/0=0.00
C#でやってみました。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 using System;
using System.Text;
using System.Threading;
using System.IO;

class Tail
{
private const int SLEEP_TIME = 1000;
private static bool fOption = false;
private static int outputLines = 10;
private static string filename = string.Empty;
private static string usage = “Usage: Tail.exe [-n number] [-f] filename”;

static void Main(string[] args)
{
try {
for (int i = 0; i < args.Length; i++) {
if (args[i][0] == '-') {
switch (args[i][1]) {
case 'n':
outputLines = int.Parse(args[++i]);
break;
case 'f':
fOption = true;
break;
default:
Console.Error.WriteLine("Invalid Option: {0}", args[i]);
Console.Error.WriteLine(usage);
return;
}
}
else
filename = args[i];
}

string buffer = string.Empty;
int allLines = 0;
string line = string.Empty;
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
using (StreamReader sr = new StreamReader(fs, Encoding.Default)) {
while (sr.ReadLine() != null)
allLines++;
fs.Seek(0, SeekOrigin.Begin);
if (allLines <= outputLines)
buffer = sr.ReadToEnd();
else {
for (int i = 0; i allLines – outputLines – 1)
buffer += line + “\n”;
}
}

Console.WriteLine(buffer);

while (fOption) {
Thread.Sleep(SLEEP_TIME);
while ((line = sr.ReadLine()) != null)
Console.WriteLine(line);
}
}
}
}
catch (Exception ex) {
Console.Error.WriteLine(ex.Message.ToString());
Console.Error.WriteLine(usage);
}
}
}

タグ: なし [ C# ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

匿名 #7209(2008-08-19 14:27) [ Python ] 評価0/0=0.00
手抜きで行末記号を”\n”で決め打ちです。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 import sys
import time
import StringIO

def gettail(fp, n):
start = fp.tell()
fp.seek(0, 2)
end = fp.tell()
s = ”
while len(s) < end – start and s.count('\n')
c match {
case ‘:’ => l match {
case List() => throw new InvalidArgumentException
case h::r => (h._1,true)::r
}
case k => (k.toString,false)::l
}
}.reverse

def parse(a:Array[String]):GetOpt = {
def _parse(o:HashMap[Any,Any],l:List[String]):Tuple2[HashMap[Any,Any],List[String]] = l match {
case List() => (o,List())
case h::r => h.toList match {
case ‘-‘::k => {
_params.find { e => e._1 == new String(k.toArray) } match {
case Some(Tuple2(_,true)) => {
if (r.size == 0) throw new InvalidArgumentException
o.update(new String(k.toArray),r.head)
_parse(o,r.tail)
}
case Some(Tuple2(_,false)) => {
o.update(new String(k.toArray),true)
_parse(o,r)
}
case _ => throw new InvalidArgumentException
}
}
case _ => (o,l)
}
}
_parse(new HashMap[Any,Any],a.toList) match {
case Tuple2(o,r) => { _opt = o; _rest = r.toArray }
}
this
}

def getopt(k:String):Any = _opt.isDefinedAt(k) match {
case true => _opt.apply(k)
case _ => false
}

def rest:Array[String] = _rest
}

class CTail(n:Int,f:Boolean,i:File) {

val s:FileInputStream = new FileInputStream(i)

def this(o:GetOpt) =this(o.getopt(“n”) match { case Some(false) => 10; case n => n.asInstanceOf[String].toInt },o.getopt(“f”).asInstanceOf[Boolean],new File(o.rest.apply(0)))

def tailn:Unit = {

val BUF_SIZE:Int = 4096
val e:Long = i.length

def _tailn(p:Long,n:Int,b:Array[Byte]):Array[Byte] = {
var t:Array[Byte] = null
var l:Int = n
(p > BUF_SIZE) match {
case true => {
t = new Array[Byte](BUF_SIZE)
s.getChannel.position(p – BUF_SIZE)
s.read(t,0,BUF_SIZE)
}
case _ => {
t = new Array[Byte](p.toInt)
s.read(t,0,p.toInt)
}
}
t = t.reverse.takeWhile { c => if (c == ‘\n’) l = l – 1; (l > 0) }.reverse
((p t ++ b
case _ => _tailn(p – BUF_SIZE, l, t ++ b)
}
}

print(new String(_tailn(e, n, new Array[Byte](0))))
s.getChannel.position(e)
}

def tailf:Unit = {
def _tailf(b:List[Byte]):List[Byte] = {
val c:Int = s.read
(c >= 0) match {
case true => _tailf(b + c.toByte)
case _ => b
}
}
print(new String(_tailf(List[Byte]()).toArray))
Thread.sleep(100)
tailf
}

def tail:CTail = {
tailn
if (f) tailf
this
}

def close:Unit = s.close
}

object Tail {
def main(args:Array[String]):Unit = {
try {
val o:GetOpt = new GetOpt(“n:f”).parse(args)
(new CTail(o)).tail.close
} catch {
case e:InvalidArgumentException => println(“usage: scala Tail [-n ] [-f] file”)
case e:FileNotFoundException => print(“file not found.”)
case e:Exception => e.printStackTrace
}
}
}

タグ: なし [ Scala ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

kkobayashi #7009(2008-08-07 00:40) [ R ] 評価0/0=0.00

まじめに書いたらCのようになってしまいました。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 read.file <- function (infile, offset=0){
con <- file(infile)
open(con)
seek(con, offset)
lines <- readLines(con)
cur.offset <- seek(con)
close(con)
list(l=lines, o=cur.offset)
}

my.tail <- function(infile, n=10, follow=FALSE){
lines <- read.file(infile)
writeLines(tail(lines$l, n))
if(follow){
size <- file.info(infile)$size
repeat{
if(size < (s <- file.info(infile)$size)){
lines <- read.file(infile, lines$o)
writeLines(lines$l)
size 0 and: [lineCount < numOfLines]]
whileTrue: [file back = 13 ifTrue: [lineCount := lineCount + 1]].

file ascii.
World findATranscript: nil.
Transcript cr; show: file upToEnd.
savedPosition := file position.
file close.
isFollowMode ifTrue: [
[Sensor keyboardPressed] whileFalse: [
(Delay forSeconds: 5) wait.
file reopen; position: savedPosition.
Transcript show: file upToEnd.
savedPosition := file position.
file close]]

タグ: なし [ Smalltalk ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

lunlumo #7153(2008-08-17 15:55) [ Ruby ] 評価0/0=0.00

 Rubyもまだの様なので書いてみました。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 #! /usr/bin/ruby

class Tail
BUF_SIZE = 4096

attr_accessor :lines, :follow, :file, :quit, :_f
private :_f

def initialize(lines,follow,file)
self.lines = lines ? lines.to_i : 10
self.follow = follow ? follow : false
self.file = file
quit = false
self.send(:_f=,File.open(file,'r').binmode)
self
end

def _tailn
lines = self.lines
size = _f.lstat.size
pos = size
tail = ''
tails = []
until(pos <= 0) do
buf = ''
if pos lines
end
tail = tail.gsub(/(\x0d\x0a|\x0d|\x0a)/,”\n”)
tails = tail.split(/\n/)
tails.push(“”) if tail =~ /\n\z/
print tails.reverse.first(lines).reverse.join(“\n”)
STDOUT.flush
_f.pos = size
self
end

def _tailf
until(quit) do
buf = ”
buf = _f.read
raise IOException.new(‘cannot read file.’) unless(buf)
if (buf.size > 0)
buf = buf.gsub(/(\x0d\x0a|\x0d|\x0a)/,”\n”)
print buf
STDOUT.flush
end
sleep(1)
end
self
end

def tail
_tailn
_tailf if follow
end

def finalize
_f.close
end
end

require “optparse”

tail = nil

conf = Hash.new
opts = OptionParser.new
opts.on(“-n MANDATORY”) { |v| conf[:n] = v }
opts.on(“-f”) { |v| conf[:f] = v }
opts.parse!

if ARGV.size == 0
puts “usage: ruby #{$0} [-n lines] [-f] filename”
else
begin
tail = Tail.new(conf[:n],conf[:f],ARGV.shift)
Signal.trap(:INT) { tail.quit = true }
tail.tail
tail.finalize
rescue => e
puts e.message
end
end

タグ: なし [ Ruby ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

lunlumo #7135(2008-08-16 22:25) [ Perl ] 評価0/0=0.00

 末尾から読み込む様にしてみました。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140 #! /usr/bin/perl

use strict;

package Tail;

$Tail::BUF_SIZE = 4096;

sub new {
my ($pkg,$lines,$follow,$file) = @_;
my $self = bless({},$pkg);
$self->file($file);
$self->lines(defined($lines) ? $lines : 10);
$self->follow(defined($follow) ? $follow : 0);
$self;
}

sub lines {
my ($self,$lines) = @_;
$self->{‘lines’} = $lines if (defined($lines));
$self->{‘lines’};
}

sub follow {
my ($self,$follow) = @_;
$self->{‘follow’} = $follow if (defined($follow));
$self->{‘follow’};
}

sub file {
my ($self,$file) = @_;
$self->{‘file’} = $file if (defined($file));
$self->{‘file’};
}

sub quit {
my ($self,$quit) = @_;
$self->{‘quit’} = $quit if (defined($quit));
$self->{‘quit’};
}

sub _fh {
my ($self,$fh) = @_;
$self->{‘_fh’} = $fh if (defined($fh));
$self->{‘_fh’};
}

sub initialize {
my ($self) = @_;
my $fh;
open ($fh,”file()) || die “cannot open file.”;
binmode($fh);
$self->_fh($fh);
$self->quit(0);
$|=1;
$self;
}

sub _tailn {
my ($self) = @_;
my $lines = $self->lines();
my $size = -s $self->file();
my $fh = $self->_fh();
my $pos = $size;
my $head;
my $tail = ”;
while ($pos > 0) {
my $buf = ”;
my $ret;
if ($pos $lines);
}
$pos = length($tail) – 1;
while ($pos >= 0) {
my $c = substr($tail,$pos,1);
if ($c eq “\x0d” || $c eq “\x0a”) {
last if (–$lines 0 && substr($tail,$pos-1,1) eq “\x0d”);
}
$pos–;
};
$tail = substr($tail,$pos+1,length($tail)-$pos-1);
$tail =~ s/(\x0d\x0a|\x0d|\x0a)/\n/g;
print $tail;
seek($fh,$size,0);
$self;
}

sub _tailf {
my ($self) = @_;
my $fh = $self->_fh();
until ($self->quit()) {
my $buf = ”;
seek($fh,tell($fh),0);
until (eof($fh)) {
die “cannot read file.” unless (defined(read($fh,$buf,$Tail::BUF_SIZE)));
$buf =~ s/(\x0d\x0a|\x0d|\x0a)/\n/g;
print $buf;
}
sleep(1);
}
$self;
}

sub tail {
my ($self) = @_;
$self->_tailn();
$self->_tailf() if ($self->follow());
}

sub finalize {
my ($self) = @_;
close($self->_fh());
}

package main;

use Getopt::Std;

my $opt = {};
my $tail;
eval {
getopts(‘n:f’,$opt);
$tail = new Tail($opt->{‘n’},$opt->{‘f’},shift(@ARGV))->initialize();
$SIG{INT} = sub { $tail->quit(1); };
$tail->tail();
$tail->finalize();
};
print “error: $@” if ($@);

1;

タグ: なし [ Perl ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

uehaj #9549(2009-09-02 17:57) [ Groovy ] 評価0/0=0.00

効率よく動作するようにnioのファイルマップドIOを使って実装しています。

参考: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 import java.nio.*
import java.nio.channels.*

ByteBuffer.metaClass.getAt = { int index ->
get(index)
}

cli = new CliBuilder(usage:’tail -f -n file’)
cli.f(args:0, ‘follow output’)
cli.n(args:1, ‘lines to print from tail’)

def opt
if (!(opt = cli.parse(args))) {
System.exit(1)
}
def params = opt.arguments()
if (params.size() != 1) {
System.exit(1)
}

// setup file mapped buffer
FileChannel fc = new FileInputStream(new File(params[0])).getChannel()
MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size())

// print opt.n lines from tail
int i = fc.size()-1
if (mbb[i] == “\n”) { i– }
int counter = 0
def lines = opt.n ? opt.n.toInteger() : 10
while (counter < lines) {
while (mbb[i] != '\n') {
i–
}
counter++
i–
}
StringBuilder bb = new StringBuilder();
for (i+=2; i < fc.size(); i++) {
bb.append(new String(mbb[i]))
}
print bb.toString();

// for -f option
def length = fc.size()
if (opt.f) {
while (true) {
def diff = fc.size() – length
if (diff != 0) {

mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size())
fc.force(true)
StringBuilder sbuf = new StringBuilder();
for (int j=0; j>>
haldaemon:x:111:123:Hardware abstraction layer,,,:/var/run/hald:/bin/false
sshd:x:112:65534::/var/run/sshd:/usr/sbin/nologin
statd:x:113:65534::/var/lib/nfs:/bin/false
telnetd:x:114:125::/nonexistent:/bin/false
… 1秒おきに繰り返し 1
2
3
4
5
6
7
8
9
10
11
12
13
14 (defun tail (file lines &key (follow nil) (external-format :utf-8))
(when (< 0 lines)
(let ((pool (make-array lines)))
(with-open-file (in file :external-format external-format)
(loop :DO (loop :for line := (read-line in nil nil) :while line
:for pos := 0 :then (mod (1+ pos) lines)
:do (setf (aref pool pos) line)
:finally (loop :for p :from pos
:for x :across pool
:do (princ (aref pool (mod (1+ p) lines)))
(terpri)))
:WHILE follow
:DO (file-position in 0)
(sleep 1))))))

タグ: なし [ Common Lisp ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

1 reply [ 返信 ]

mc #7940(2008-11-03 12:59) [ Common Lisp ] 評価0/0=0.00
すいません、間違ったものを貼りつけてました。前のでは、ファイルの行数が指定より少ない場合に余計な出力が出てしまいます。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 (defun tail (file lines &key (follow nil) (external-format :utf-8))
(when (< 0 lines)
(let ((pool (make-array lines :initial-element nil)))
(with-open-file (in file :external-format external-format)
(loop :DO (loop :for line := (read-line in nil nil) :while line
:for pos := 0 :then (mod (1+ pos) lines)
:do (setf (aref pool pos) line)
:finally (loop :for p :from pos
:for x :across pool
:do (let ((line (aref pool (mod (1+ p) lines))))
(when line
(princ line)
(terpri)))))
:WHILE follow
:DO (file-position in 0)
(sleep 1))))))

タグ: なし [ Common Lisp ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

mc #7945(2008-11-04 11:30) [ Common Lisp ] 評価0/0=0.00
該当行のファイルポジションを割出してから表示するようにしてみました。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 (defun tail (file lines &key (follow nil) (external-format :utf-8))
(when (< 0 lines)
(with-open-file (in file :external-format external-format)
(loop :FOR pos := (last-n-line-position lines file)
:THEN (last-n-line-position lines file :offset pos)
:DO (file-position in pos)
(loop :for line := (read-line in nil nil) :while line
:do (princ line) (terpri))
:WHILE follow :DO (sleep 1)))))

(defun last-n-line-position (n file &key (newline-char #\Newline) (offset 0))
(declare ((integer 0 *) n offset))
(let* ((n (1+ n)) ;改行で数えているので1+
(pool (make-array n :initial-element nil)))
(with-open-file (in file :element-type '(unsigned-byte 8))
(file-position in offset)
(loop :with nl := (char-code newline-char)
:and pos := 0
:for byte := (read-byte in nil nil) :while byte
:for file-pos :from 0
:when (eql nl byte)
:do (setq pos (mod (1+ pos) n))
(setf (aref pool pos) file-pos)
:finally (return
(let ((ans (loop :for p :across pool
:minimize (or p 0))))
(+ offset
(if (zerop ans) 0 (1+ ans)))))))))

タグ: なし [ Common Lisp ] [ ダウンロード ] [ HTML ]

評価0/0=0.00-0+

[ 返信 ]

一覧
言語
お題
トピック
投稿
評価の高い投稿
タグ
フィード
最新のトピック
新着投稿
その他
Q&A
フィードバック
リンク
サイボウズ・ラボ
Django
このサイトの内容は、 クリエイティブ・コモンズ・ライセンスの下でライセンスされています。 [詳細]


[Bitmap]:https://jupiter333.files.wordpress.com/2011/06/634431388308822687.jpg

[2011/06/08 14:07:10]:


[Text]:SQLite系のポーリングについて SQLite DBをポーリングする場合 orgDB->copy

[2011/06/08 13:43:16]: {sub_text}

SQLite系のポーリングについて
SQLite DBをポーリングする場合 orgDB->copy->tempDBにコピーしなければなないので

1.orgDB timestampをみる。監視時間と比較 更新されてないなら 打ち切り
2.更新されているなら、コピー ->tempDB ポーリング
がいい。


[FileDrop]:D:\taihi\game\黙って私のムコになれ!\ensemble\黙って私のムコになれ!\RIO

[2011/06/08 13:39:09]:

D:\taihi\game\黙って私のムコになれ!\ensemble\黙って私のムコになれ!\RIO.INI
D:\taihi\game\黙って私のムコになれ!\ensemble\黙って私のムコになれ!\SETUP.DLL
D:\taihi\game\黙って私のムコになれ!\ensemble\黙って私のムコになれ!\SETUP.INI
D:\taihi\game\黙って私のムコになれ!\ensemble\黙って私のムコになれ!\UNINST.EXE


[Text]: #region Chrome history ChromehistoryPollin

[2011/06/08 12:24:31]: {sub_text}

#region Chrome history ChromehistoryPolling_Init
ArrayList Chromelist;
Timer ChromehistoryPolling;
DateTime Chromestockdatetime;

public void ChromehistoryPolling_Init()
{
Chromelist = new ArrayList();

this.ChromehistoryPolling = new System.Windows.Forms.Timer();
this.ChromehistoryPolling.Interval = 10 * 1000 +10;////

this.ChromehistoryPolling.Start();
stockdatetime = DateTime.Now;
this.IEhistoryPolling.Tick += (m_s, m_e) => //————————
{

this.ChromehistoryPolling.Stop();
var worker = new BackgroundWorker();
worker.DoWork += (s, e) =>
{
Chromelist.Clear();
Chromelist = new ArrayList();

string Chromedbfile = @”\Mozilla\Chrome\Profiles\o86ky63z.default\places.sqlite”;
string dbname = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Chromedbfile;

String path_to_db = dbname;
String path_to_temp = System.IO.Path.GetTempFileName();

if (System.IO.File.Exists(path_to_temp)) System.IO.File.Delete(path_to_temp);

System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection(“Data Source=” + path_to_temp + “;Version=3;Compress=True;”);//Read Only=True;”);
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();

DateTime yest = Chromestockdatetime;
long Chrometime = MonoSystem.Util.UtilUnixTime.ToUnixTime(yest.ToUniversalTime()) * 1000000;
Chromestockdatetime = DateTime.Now;

string sqlc = string.Format(“select * from moz_places where last_visit_date > {0} order by last_visit_date desc”, Chrometime);

sqlite_command.CommandText = sqlc;// string.Format(“select * from moz_places”);// where last_visit_date > {0}”,Chrometime);
SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
{
// Prints out the url field from the table:
string str = string.Format(“{0}:{1}”, sqlite_datareader[“url”], sqlite_datareader[“last_visit_date”]);
if( !(str == “:”))Chromelist.Add(str);
}

sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);

e.Result = Chromelist;
};
worker.RunWorkerCompleted += (s, e) =>
{

if (e.Result != null)
{
string str = “”;
foreach (string nn in (ArrayList)e.Result)
{
//test show
str += nn + Environment.NewLine;
}

this.debug_textBox2.Text += str;
}
this.ChromehistoryPolling.Start();

};

worker.RunWorkerAsync();

};//—————————————————————-

}
#endregion


[Text]: //C:\Users\mono\AppData\Local\Google\Ch

[2011/06/08 12:22:04]: {sub_text}

//C:\Users\mono\AppData\Local\Google\Chrome\User Data\Default\History”
string chromedbfile = @”\Google\Chrome\User Data\Default\History”;
string dbname = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData/*ApplicationData*/) + chromedbfile;

if (!System.IO.File.Exists(dbname))
{
Console.WriteLine(“noexsit{0}”, dbname);
return;
}
String path_to_db = dbname;
String path_to_temp = System.IO.Path.GetTempFileName();
System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection(“Data Source=” + path_to_temp + “;Version=3;Compress=True;”);//Read Only=True;”);
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();

DateTime yest = DateTime.Now;
long chrometime = UnixTime.ToChromeTime(yest.ToUniversalTime()) * 1000000;
//select * from urls where last_visit_time > 12951956932000000 order by last_visit_time desc
string sqlc = string.Format(“select * from urls where last_visit_time > {0} order by last_visit_time desc”, chrometime);

sqlite_command.CommandText = sqlc;// string.Format(“select * from moz_places”);// where last_visit_date > {0}”,firefoxtime);
SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
{
// Prints out the url field from the table:
string str = string.Format(“{0}:{1}”, sqlite_datareader[“url”], sqlite_datareader[“last_visit_time”]);
Console.WriteLine(str);
}

sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);


[Text]: //C:\Users\mono\AppData\Local\Google\C

[2011/06/08 12:20:47]: {sub_text}

//C:\Users\mono\AppData\Local\Google\Chrome\User Data\Default\History”
string chromedbfile = @”\Google\Chrome\User Data\Default\History”;
string dbname = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData/*ApplicationData*/) + chromedbfile;

if (!System.IO.File.Exists(dbname))
{
Console.WriteLine(“noexsit{0}”, dbname);
return;
}
String path_to_db = dbname;
String path_to_temp = System.IO.Path.GetTempFileName();
System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection(“Data Source=” + path_to_temp + “;Version=3;Compress=True;”);//Read Only=True;”);
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();

DateTime yest = DateTime.Now;
long chrometime = UnixTime.ToChromeTime(yest.ToUniversalTime()) * 1000000;
//select * from urls where last_visit_time > 12951956932000000 order by last_visit_time desc
string sqlc = string.Format(“select * from urls where last_visit_time > {0} order by last_visit_time desc”, chrometime);

sqlite_command.CommandText = sqlc;// string.Format(“select * from moz_places”);// where last_visit_date > {0}”,firefoxtime);
SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
{
// Prints out the url field from the table:
string str = string.Format(“{0}:{1}”, sqlite_datareader[“url”], sqlite_datareader[“last_visit_time”]);
Console.WriteLine(str);
}

sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);


[Text]: #region Chrome history ChromehistoryPollin

[2011/06/08 12:20:22]: {sub_text}

#region Chrome history ChromehistoryPolling_Init
ArrayList Chromelist;
Timer ChromehistoryPolling;
DateTime Chromestockdatetime;

public void ChromehistoryPolling_Init()
{
Chromelist = new ArrayList();

this.ChromehistoryPolling = new System.Windows.Forms.Timer();
this.ChromehistoryPolling.Interval = 10 * 1000 +10;////

this.ChromehistoryPolling.Start();
stockdatetime = DateTime.Now;
this.IEhistoryPolling.Tick += (m_s, m_e) => //————————
{

this.ChromehistoryPolling.Stop();
var worker = new BackgroundWorker();
worker.DoWork += (s, e) =>
{
Chromelist.Clear();
Chromelist = new ArrayList();

string Chromedbfile = @”\Mozilla\Chrome\Profiles\o86ky63z.default\places.sqlite”;
string dbname = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Chromedbfile;

String path_to_db = dbname;
String path_to_temp = System.IO.Path.GetTempFileName();

if (System.IO.File.Exists(path_to_temp)) System.IO.File.Delete(path_to_temp);

System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection(“Data Source=” + path_to_temp + “;Version=3;Compress=True;”);//Read Only=True;”);
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();

DateTime yest = Chromestockdatetime;
long Chrometime = MonoSystem.Util.UtilUnixTime.ToUnixTime(yest.ToUniversalTime()) * 1000000;
Chromestockdatetime = DateTime.Now;

string sqlc = string.Format(“select * from moz_places where last_visit_date > {0} order by last_visit_date desc”, Chrometime);

sqlite_command.CommandText = sqlc;// string.Format(“select * from moz_places”);// where last_visit_date > {0}”,Chrometime);
SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
{
// Prints out the url field from the table:
string str = string.Format(“{0}:{1}”, sqlite_datareader[“url”], sqlite_datareader[“last_visit_date”]);
if( !(str == “:”))Chromelist.Add(str);
}

sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);

e.Result = Chromelist;
};
worker.RunWorkerCompleted += (s, e) =>
{

if (e.Result != null)
{
string str = “”;
foreach (string nn in (ArrayList)e.Result)
{
//test show
str += nn + Environment.NewLine;
}

this.debug_textBox2.Text += str;
}
this.ChromehistoryPolling.Start();

};

worker.RunWorkerAsync();

};//—————————————————————-

}
#endregion


[Text]: #region FireFox history FireFoxhistoryPoll

[2011/06/08 12:19:38]: {sub_text}

#region FireFox history FireFoxhistoryPolling_Init
ArrayList FireFoxlist;
Timer FireFoxhistoryPolling;
DateTime FireFoxstockdatetime;

public void FireFoxhistoryPolling_Init()
{
FireFoxlist = new ArrayList();

this.FireFoxhistoryPolling = new System.Windows.Forms.Timer();
this.FireFoxhistoryPolling.Interval = 10 * 1000 +10;////

this.FireFoxhistoryPolling.Start();
stockdatetime = DateTime.Now;
this.IEhistoryPolling.Tick += (m_s, m_e) => //————————
{

this.FireFoxhistoryPolling.Stop();
var worker = new BackgroundWorker();
worker.DoWork += (s, e) =>
{
FireFoxlist.Clear();
FireFoxlist = new ArrayList();

string firefoxdbfile = @”\Mozilla\Firefox\Profiles\o86ky63z.default\places.sqlite”;
string dbname = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + firefoxdbfile;

String path_to_db = dbname;
String path_to_temp = System.IO.Path.GetTempFileName();

if (System.IO.File.Exists(path_to_temp)) System.IO.File.Delete(path_to_temp);

System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection(“Data Source=” + path_to_temp + “;Version=3;Compress=True;”);//Read Only=True;”);
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();

DateTime yest = FireFoxstockdatetime;
long firefoxtime = MonoSystem.Util.UtilUnixTime.ToUnixTime(yest.ToUniversalTime()) * 1000000;
FireFoxstockdatetime = DateTime.Now;

string sqlc = string.Format(“select * from moz_places where last_visit_date > {0} order by last_visit_date desc”, firefoxtime);

sqlite_command.CommandText = sqlc;// string.Format(“select * from moz_places”);// where last_visit_date > {0}”,firefoxtime);
SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
{
// Prints out the url field from the table:
string str = string.Format(“{0}:{1}”, sqlite_datareader[“url”], sqlite_datareader[“last_visit_date”]);
if( !(str == “:”))FireFoxlist.Add(str);
}

sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);

e.Result = FireFoxlist;
};
worker.RunWorkerCompleted += (s, e) =>
{

if (e.Result != null)
{
string str = “”;
foreach (string nn in (ArrayList)e.Result)
{
//test show
str += nn + Environment.NewLine;
}

this.debug_textBox2.Text += str;
}
this.FireFoxhistoryPolling.Start();

};

worker.RunWorkerAsync();

};//—————————————————————-

}
#endregion