diff -urN soojung-0.4.10/classes/Counter.class.php soojung/classes/Counter.class.php
--- soojung-0.4.10/classes/Counter.class.php	2005-06-16 19:50:48.000000000 +0900
+++ soojung/classes/Counter.class.php	2005-10-16 16:40:46.000000000 +0900
@@ -39,15 +39,11 @@
       $lastdate = date("Y-m-d");
     }
 
-    if ($fd = @fopen("contents/.count", "w")) {
-      flock($fd, LOCK_EX);
-      fwrite($fd, "$lastdate\n$today\n$total\n");
-      foreach ($recent as $recentitem) {
-	fwrite($fd, "$recentitem\n");
-      }
-      flock($fd, LOCK_UN);
-      fclose($fd);
+    $data = "$lastdate\n$today\n$total\n";
+    foreach ($recent as $recentitem) {
+	$data .= "$recentitem\n";
     }
+    locked_filewrite("contents/.count", $data);
 
     $this->today = $today;
     $this->total = $total;
diff -urN soojung-0.4.10/classes/Entry.class.php soojung/classes/Entry.class.php
--- soojung-0.4.10/classes/Entry.class.php	2005-06-16 19:50:48.000000000 +0900
+++ soojung/classes/Entry.class.php	2005-10-16 17:28:32.000000000 +0900
@@ -264,7 +264,29 @@
   /**
    * static method
    */
-  function search($keyword) {
+  function search($keyword, $mode = "all") {
+    $founds = array();
+    if ($keyword == "") {
+      return $founds;
+    }
+    if ($mode == "all") {
+      $filenames = Soojung::queryFilenameMatch("^[0-9].+[.]entry$");
+      rsort($filenames);
+      foreach($filenames as $f) {
+	$fd = fopen($f, "r");
+	$data = fread($fd, filesize($f));
+	fclose($fd);
+	if (strpos($data, $keyword) !== FALSE) {
+	  $founds[] = new Entry($f);
+	}
+      }
+    } else { // search title
+      $founds = Entry::searchByTitle($keyword);
+    }
+    return $founds;
+  }
+
+  function searchByTitle($keyword) {
     $founds = array();
     if ($keyword == "") {
       return $founds;
@@ -273,11 +295,15 @@
     rsort($filenames);
     foreach($filenames as $f) {
       $fd = fopen($f, "r");
-      $data = fread($fd, filesize($f));
-      fclose($fd);
-      if (strpos($data, $keyword) !== FALSE) {
-	$founds[] = new Entry($f);
+      while (($line = fgets($fd, 1024)) !== FALSE) {
+	if (strpos($line, "Title:") === 0) {
+	  if (strpos($line, $keyword) !== FALSE) {
+	    $founds[] = new Entry($f);
+	    break;
+	  }
+	}
       }
+      fclose($fd);
     }
     return $founds;
   }
diff -urN soojung-0.4.10/classes/Formatter.class.php soojung/classes/Formatter.class.php
--- soojung-0.4.10/classes/Formatter.class.php	2005-08-26 13:45:05.000000000 +0900
+++ soojung/classes/Formatter.class.php	2005-09-08 18:37:24.000000000 +0900
@@ -349,7 +349,7 @@
 
     foreach ($lines as $line) {
       # empty line
-	  $line = trim($line);
+	  $line = rtrim($line);
       if (strlen($line) == 0) {
         if ($in_pre) { $pre_line.="\n";continue;}
         if ($in_li) { $text.="<br />\n";$li_empty=1; continue;}
diff -urN soojung-0.4.10/classes/Soojung.class.php soojung/classes/Soojung.class.php
--- soojung-0.4.10/classes/Soojung.class.php	2005-07-05 15:14:42.000000000 +0900
+++ soojung/classes/Soojung.class.php	2005-10-16 16:40:49.000000000 +0900
@@ -102,11 +102,7 @@
     flock($fd, LOCK_UN);
     fclose($fd);
     
-    $fd = fopen("contents/.info", "w");
-    flock($fd, LOCK_EX);
-    fwrite($fd, $i + 1);
-    flock($fd, LOCK_UN);
-    fclose($fd);
+    locked_filewrite("contents/.info", ((int)$i)  + 1);
     return $i;
   }
 
@@ -250,12 +246,7 @@
         $array[] = $referer;
       }
 
-      if ($fd = @fopen("contents/.referer", "w")) {
-      	flock($fd, LOCK_EX);
-	fwrite($fd, implode($array, "\r\n"));
-        flock($fd, LOCK_UN);
-        fclose($fd);
-      }
+      locked_filewrite("contents/.referer", implode($array, "\r\n"));
     }
   }
 
diff -urN soojung-0.4.10/index.php soojung/index.php
--- soojung-0.4.10/index.php	2005-06-16 19:50:48.000000000 +0900
+++ soojung/index.php	2005-10-16 17:28:32.000000000 +0900
@@ -48,7 +48,11 @@
   } else if (isset($_GET["search"])) {
     $template->assign('view', 'search');
     $template->assign('keyword', $_GET["search"]);
-    $template->assign('entries', Entry::search($_GET["search"]));
+    $search_mode = "all";
+    if (isset($_GET["mode"])) {
+      $search_mode = $_GET["mode"];
+    }
+    $template->assign('entries', Entry::search($_GET["search"], $search_mode));
   } else {
     $template->assign('view', 'index');
     $template->assign('keyword', "all");
diff -urN soojung-0.4.10/libs/util.php soojung/libs/util.php
--- soojung-0.4.10/libs/util.php	2005-02-19 05:43:23.000000000 +0900
+++ soojung/libs/util.php	2005-10-16 16:40:51.000000000 +0900
@@ -157,4 +157,35 @@
   return trim($array[0]);
 }
 
+function locked_filewrite($filename, $data) {
+   ignore_user_abort(1);
+   $lockfile = $filename . '.lock';
+
+   // if a lockfile already exists, but it is more than 5 seconds old,
+   // we assume the last process failed to delete it
+   // this would be very rare, but possible and must be accounted for
+   if (file_exists($lockfile)) {
+       if (time() - filemtime($lockfile) > 5) unlink($lockfile);
+   }
+
+   $lock_ex = @fopen($lockfile, 'x');
+   for ($i=0; ($lock_ex === false) && ($i < 20); $i++) {
+       clearstatcache();
+       usleep(rand(9, 999));
+       $lock_ex = @fopen($lockfile, 'x');
+   }
+
+   $success = false;
+   if ($lock_ex !== false) {
+       $fp = @fopen($filename, 'w');
+       if (@fwrite($fp, $data)) $success = true;
+       @fclose($fp);
+       fclose($lock_ex);
+       unlink($lockfile);
+   }
+
+   ignore_user_abort(0);
+   return $success;
+}
+
 ?>
diff -urN soojung-0.4.10/post.php soojung/post.php
--- soojung-0.4.10/post.php	2005-06-17 09:08:05.000000000 +0900
+++ soojung/post.php	2005-09-22 11:59:26.000000000 +0900
@@ -1,5 +1,5 @@
 <?php
-session_cache_limiter('private'); 
+#session_cache_limiter('private'); 
 session_start();
 
 include("config.php");
@@ -72,7 +72,7 @@
   if (empty($title) || empty($body) || empty($date) || empty($format) || empty($category) ) {
     echo "<font color=\"red\">WARNING: Input title, body, date, category, format</font>";
   } else {
-    if (isset($_POST["id"])) {
+    if (isset($_POST["id"]) and is_numeric($_POST["id"])) {
       Entry::editEntry($_POST["id"], $title, $body, $date, $category, $options, $format);
     } else {
       $date = time() + 10;
diff -urN soojung-0.4.10/settings.php soojung/settings.php
--- soojung-0.4.10/settings.php	2005-09-04 14:20:32.000000000 +0900
+++ soojung/settings.php	2005-09-24 09:44:05.000000000 +0900
@@ -1,6 +1,6 @@
 <?php
 
-$soojung_version = '0.4.10';
+$soojung_version = '0.4.11';
 setlocale(LC_TIME, "C");
 
 header("Content-type: text/html; charset=utf-8");
diff -urN soojung-0.4.10/templates/admin/data.tpl soojung/templates/admin/data.tpl
--- soojung-0.4.10/templates/admin/data.tpl	2005-04-19 21:46:19.000000000 +0900
+++ soojung/templates/admin/data.tpl	2005-09-09 17:54:05.000000000 +0900
@@ -13,9 +13,9 @@
 <br />
 Version: 
 <select name="version">
-<!--<option value="0.2">0.2.*</option>-->
-<option value="0.3.2">0.3.2</option>
 <option value="0.4">0.4</option>
+<option value="0.3.2">0.3.2</option>
+<!--<option value="0.2">0.2.*</option>-->
 </select>
 <br />
 <input type="hidden" name="mode" value="import" />
@@ -93,4 +93,4 @@
 <input type="submit" value="import!" />
 </form>
 
-{include file="footer.tpl"}
\ No newline at end of file
+{include file="footer.tpl"}
diff -urN soojung-0.4.10/templates/admin/javascript.js soojung/templates/admin/javascript.js
--- soojung-0.4.10/templates/admin/javascript.js	2005-04-27 23:05:30.000000000 +0900
+++ soojung/templates/admin/javascript.js	2005-09-22 11:56:57.000000000 +0900
@@ -2,7 +2,28 @@
 	window.location.href = loc;
 }
 
-function appendLink(link) {
+function appendLink(baseurl, path, name) {
+
+	if (window.opener.document.postForm.format[0].checked ) {
+		/* plain */
+		link = '<a href="' + path + '">' + name + '</a>'
+	}
+	else if (window.opener.document.postForm.format[1].checked ) {
+		/* html */
+		link = baseurl + '/' + path;
+	}
+	else if ( window.opener.document.postForm.format[2].checked ) {
+		/* bbcode */
+		link = '[url]' + path + '[/url]';
+	}
+	else if (window.opener.document.postForm.format[3].checked) {
+		/* moniwiki */
+		link = "attachment:" + escape(name);
+	}
+	else {
+		link = escape(path);
+	}
+
 	if(window.opener) {
 		var target = window.opener.document.postForm.body;
 		target.value += link;
@@ -28,4 +49,4 @@
 
 function changeCategory($category) {
 	location.href = "admin.php?mode=list&flag=" + $category.value;
-}
\ No newline at end of file
+}
diff -urN soojung-0.4.10/templates/admin/styles.css soojung/templates/admin/styles.css
--- soojung-0.4.10/templates/admin/styles.css	2005-07-10 19:19:27.000000000 +0900
+++ soojung/templates/admin/styles.css	2005-09-22 11:56:57.000000000 +0900
@@ -187,7 +187,7 @@
 { 
   margin-left: 10px;
   width: 290px;
-  overflow: hidden
+  overflow: hidden;
   white-space:nowrap;
   text-align: left;
 }
diff -urN soojung-0.4.10/templates/admin/upload.tpl soojung/templates/admin/upload.tpl
--- soojung-0.4.10/templates/admin/upload.tpl	2005-05-17 19:29:07.000000000 +0900
+++ soojung/templates/admin/upload.tpl	2005-09-22 11:56:57.000000000 +0900
@@ -23,7 +23,7 @@
 </td>
 <td>
 <strong>
-<a href="#" onclick="return appendLink('{$baseurl}/{$file.path|escape:'quotes'|escape}');">append</a>
+<a href="#" onclick="return appendLink('{$baseurl}', '{$file.path|escape:'quotes'|escape}', '{$file.name|escape}');">append</a>
 <a href="{$baseurl}/upload.php?mode=delete&file={$file.path|escape:'url'|escape}">delete</a>
 </strong>
 </td>
diff -urN soojung-0.4.10/templates/simple/index.tpl soojung/templates/simple/index.tpl
--- soojung-0.4.10/templates/simple/index.tpl	2005-07-10 19:51:41.000000000 +0900
+++ soojung/templates/simple/index.tpl	2005-10-16 17:28:32.000000000 +0900
@@ -36,11 +36,15 @@
 		<br />
 	{/foreach}
 {elseif $view == "search"}
+	{if count($entries) == 1}
+		<script>location.href="{$entries[0]->getHref()|escape}"</script>
+	{else}
 	{foreach from=$entries item=entry}
 		<a href="{$entry->getHref()|escape}">{$entry->title|escape}</a>
 		{$entry->date|date_format:"%B %d, %Y"}
 		<br />
 	{/foreach}
+	{/if}
 {/if}
 
 {include file="footer.tpl"}
