home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 November / Chip_2003-11_cd1.bin / software / dave / dqsd.exe / searches / chmodconv.xml < prev    next >
Text File  |  2002-12-14  |  2KB  |  71 lines

  1. <search function="chmodconv">
  2.   <name>chmod conversion</name>
  3.   <description>
  4.     Convert chmod strings to numbers and numbers to strings.<br/>
  5.     <div class="helpboxDescLabels">Examples:</div>
  6.     <table class="helpboxDescTable">
  7.           <tr><td>chmodconv 755</td><td>returns rwxr-xr-x in the edit box</td></tr>
  8.           <tr><td>chmodconv rwxr-x---</td><td>returns 750 in the edit box</td></tr>
  9.       </table>
  10.   </description>
  11.   <category>Functions</category>
  12.   <contributor>Brent Beardsley</contributor>
  13.   
  14.   <script><![CDATA[
  15.     function chmodconv_string_from_digit(dig)
  16.     {
  17.       var result = "";
  18.       result += (dig & 4) ? "r" : "-";
  19.       result += (dig & 2) ? "w" : "-";
  20.       result += (dig & 1) ? "x" : "-";
  21.       return result;
  22.     }
  23.  
  24.     function chmodconv_digit_from_string(str)
  25.     {
  26.       var result = 0;
  27.       for (var i=0; i < 3; i++) {
  28.           var ch = str.charAt(i);
  29.           switch (ch)
  30.           {
  31.           case 'r': result += 4; break;
  32.           case 'w': result += 2; break;
  33.           case 'x': result += 1; break;
  34.           }
  35.       }
  36.       return result;
  37.     }
  38.  
  39.     function chmodconv(q)
  40.     {
  41.     }
  42.     function chmodconv(q)
  43.     {
  44.       if( nullArgs("chmodconv",q) )
  45.         return false;
  46.  
  47.       if (q.match(/^[0-9]{3}$/)) {
  48.           // calc string ie: rwxrwxrwx
  49.           var owner = chmodconv_string_from_digit(q.charAt(0));
  50.           var group = chmodconv_string_from_digit(q.charAt(1));
  51.           var other = chmodconv_string_from_digit(q.charAt(2))
  52.           setSearchWindowText(owner + group + other, true);
  53.       } else if (q.match(/^((r|-)(w|-)(x|-)){3}$/)) {
  54.           // calc num ie: 755
  55.           var owner = chmodconv_digit_from_string(q.substr(0,3))*100;
  56.           var group = chmodconv_digit_from_string(q.substr(3, 3))*10;
  57.           var other = chmodconv_digit_from_string(q.substr(6, 3));
  58.           setSearchWindowText(owner + group + other, true);
  59.       } else {
  60.         nullArgs("chmodconv","?");
  61.       }
  62.     }
  63.   ]]></script>
  64.  
  65.   <copyright>
  66.     Copyright (c) 2002 David Bau
  67.     Distributed under the terms of the
  68.     GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  69.   </copyright>
  70. </search>
  71.