plirof2

parse_sgd10000b.php v03d - test All Case Comb

Apr 14th, 2022 (edited)
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.85 KB | None | 0 0
  1. <?php
  2. /*
  3. v220410 - v03d - Case insensitive .DAT file
  4. v220310 - v03c - added filter
  5. v220212 - removed spaces from filename
  6. v211117 -
  7. v211110 - initial
  8. ln -s /opt/spectrum/zx-spectrum10k-sgd/SPECCY/ /opt/lampp/htdocs/zx
  9.  
  10. ln -s /opt/spectrum/zx-spectrum10k-sgd/SPECCY/
  11.  
  12. */
  13. $myfilename="GAMES.DAT";
  14. $myfile_path="SPECCY/";
  15. $filename_possibilities_array=Array();
  16.  
  17.  
  18. function enumerate($str,int  $n)
  19. {
  20.   global $filename_possibilities_array;
  21.   //echo "| $str"; // Print one solution
  22.   while (++$n < strlen($str)) // Loop while you don't reach the end
  23.     {
  24.     //if ($str[$n] > 96 && $str[$n] < 123) // Check if str[n] is alphabetic
  25.       //{
  26.         //char *tmp = calloc(strlen(str) + 1, sizeof(char));
  27.         //$char=new Array(strlen($str)+1);
  28.         $tmp=$str;
  29.  
  30.         //strcpy(tmp, str); // Create a copy of the initial string
  31.         $tmp[$n] = strtoupper($tmp[$n]) ; // Put tmp[n] = str[n] in uppercase
  32.         $filename_possibilities_array[]=$tmp;
  33.        
  34.         enumerate($tmp, $n); // Call recursion with new string and current position
  35.      }
  36. }
  37.  
  38. enumerate(strtolower($myfilename), -1);
  39. //print_r($filename_possibilities_array);
  40.  
  41.  
  42.  
  43.  
  44. function fileExists($myfile_path,$filename_possibilities_array ) {
  45.     foreach($filename_possibilities_array as $file )
  46.     {
  47.       //echo "<HR>".$file;
  48.       if(file_exists($myfile_path.$file)) {
  49.        return $file;
  50.       }
  51.     }
  52.  
  53.  
  54.     return "NOT_FOUND";
  55. }
  56.  
  57.  
  58.  
  59.  
  60. $myfilename=fileExists($myfile_path,$filename_possibilities_array);
  61. //echo "<h1> myfilename=$myfilename </h1>";
  62.  
  63.  
  64.  
  65. $myfile = fopen($myfile_path.$myfilename, "r") or die("Unable to open file!");
  66. $qaopURL='http://localhost/zx/QAOP/qaop.html';
  67. $snapsURL='http://localhost/zx/SPECCY/';
  68. $snapPATH="SPECCY/";
  69. $snapsURL='http://localhost/zx/'.$snapPATH;
  70.  
  71.  
  72. //#################### filter##############################
  73. $display_scr=true;
  74. $ignore_filter=false;
  75. ?>
  76. <hr>
  77. <form action="" method="post">
  78. <!-- url: <input type="text" name="url"><br>-->
  79. filter (values seperated by | ): <input type="text" name="filter" value="(z80|sna|tap)" > (eg (z80|sna|tap) or (monty|chess|pacman) or (.*)=ALL<br>
  80. show SCR: <input type="radio" name="showscr"  > <br>
  81.  
  82. <input type="submit">
  83. <?php #echo "Last URL= $url <BR> Last Filter =$keywords_pattern "; ?>
  84. </form>
  85. <hr>
  86.  
  87. <?php
  88.  
  89. //$keywords_pattern='#\b(u12|u99|etc)\b#i';
  90. $keywords_pattern='/\b(.*)\b/i';
  91. if (@$_REQUEST["showscr"]!="") {
  92.  
  93.     //$url="https://chess-results.com/tnr609201.aspx?lan=1&art=1&rd=7";
  94.     $display_scr=$_REQUEST["showscr"];
  95.   }
  96.    else {
  97.    $display_scr = false;
  98.  }
  99.  
  100. //Check if filter is given
  101. if (@$_REQUEST["filter"]!="") {
  102.  
  103.     $keywords_pattern='#\b('.$_REQUEST["filter"].')\b#i';
  104.   }
  105.    else {
  106.     $keywords_pattern='#\b(.*)\b#i';
  107. }
  108. //#################### filter##############################
  109.  
  110.  
  111.  
  112. function process_fields($fields){
  113. global $qaopURL,$snapsURL,$snapPATH,$display_scr;
  114. global $keywords_pattern;
  115.  
  116. echo "<tr><td>";
  117. if($display_scr){
  118.   $filename_no_ext=substr($fields[4], 0, strrpos($fields[4], '.'));
  119.   //$img_final="<img src= $snapsURL".get_path($filename_no_ext)."SCRSHOT/".$scr2png_text." >";
  120.   //$img_final=$snapPATH.get_path($filename_no_ext)."SCRSHOT/".$filename_no_ext.".SCR ";
  121.   $img_final=$snapPATH."SCRSHOT/".$filename_no_ext.".SCR ";
  122.   //$img_final=$snapPATH."Scrshot/".$filename_no_ext.".SCR ";
  123.   $scr2png_text="scr2png.php?scrimg=".$img_final;
  124.  
  125.   echo "<img src= $scr2png_text >";
  126. }
  127.  
  128.  
  129. echo "</td><td>".$fields[1];
  130.  
  131. echo "</td><td>".$fields[2];
  132.  
  133. echo "</td><td>".$fields[3];
  134.  
  135. //echo "</td><td>".$fields[4];
  136. //echo "</td><td><a href=".$qaopURL."?#l=".$snapsURL.rawurlencode($fields[4]). ">".$fields[4]."</a> ";
  137. echo "</td><td><a href=".$qaopURL."?#l=".$snapsURL.$fields[4]. ">".$fields[4]."</a> ";
  138. echo "</td><td>".$fields[5];
  139. echo "</td><td>".$fields[6];
  140.  
  141. echo "</td></tr>";
  142.  //print_r($fields);
  143.  
  144. };
  145.  
  146. echo "<table border=1 >";
  147. // Output one line until end-of-file
  148. while(!feof($myfile)) {
  149.  
  150.   $s= fgets($myfile);
  151.  
  152.  // echo "$s" . "<br>";
  153.  
  154.     $fields[1] = substr($s,0,36);  // gamename first field:  first 10 characters of the line
  155.     $fields[2] = substr($s,37,4);  // year second field: next 5 characters of the line
  156.     $fields[3] = substr($s,42,36); // Publisher  third field:  next 12 characters of the line
  157.     $fields[4] = str_replace(' ', '', substr($s,93,12));  //PC filename -REMOVED spaces
  158.     $fields[5] = substr($s,106,7); // Type
  159.     $fields[6] = substr($s,150,37); // Type
  160.     //$fields[6] = substr($s,43,89);
  161.     //$fields[7] = substr($s,43,89);
  162.  
  163.  
  164.  
  165.   //process_fields($fields);
  166.   if ($ignore_filter || preg_match_all($keywords_pattern, $s)) process_fields($fields);  
  167.  
  168. }
  169. echo "</tr></table>";
  170. fclose($myfile);
  171.  
  172.  
  173. ?>
  174. <!--
  175. The current database format is:
  176.  
  177. Field        Start Length  Notes
  178.  
  179. Name             1     36
  180. Year            38      4  Year-2000 compliant :-)
  181. Publisher       43     36
  182. Memory          80      3  Either one of " 16", " 48", "128", "4/1", "US0",
  183.                            " +2", " +3" or "Pen"
  184. # Players       84      1
  185. Together        86      1  Only 'Y' if > 1 player, space otherwise
  186. Joysticks       88      5  Shrunk leftward, order is 'K12CR' for
  187.                            Kempston, Intf2#1, Intf2#2, Cursor and Redefineable.
  188. PC-Name         94     12  The '.'s are aligned (raw name padded)
  189. Type           107      7
  190. PathIndex      115      3  Index number of the appropriate `GameDir' entry
  191. FileSize       119      7  Is '+' if the size has more than 7 digits
  192. Orig screen    127      1  'Y' if checked, space otherwise
  193. Origin         129      1  ' ' = (unknown)
  194.                            'O' = Original release
  195.                            'R' = Re-release
  196.                            'C' = Compilation release
  197.                            'M' = Magazine conver-tape version
  198.                            'T' = Type-in
  199.                            'H' = Hacked/cracked version
  200.                            'I' = Incomplete version
  201.                            'B' = Buggered/corrupted version
  202. FloppyId       131      4  Marked floppy number, or 0 for harddisk etc.
  203. Emul override  136      2  -1 = none
  204.                            0  = Z80
  205.                            1  = JPP
  206.                            2  = Warajevo
  207.                            3  = X128
  208.                            4  = WSpecEm
  209.                            5  = ZX
  210.                            6  = Spanish
  211.                            7  = ZX-32
  212.                            8  = R80
  213.                            9  = Russian/Shalayev
  214.                            10 = Russian/Yudin
  215. AYSound        139      1  'Y' if checked, space otherwise
  216. MultiLoad      141      1  'Y' if multi-load in both 48K and 128K mode
  217.                            '4' if multi-load only in 48K mode
  218.                            ' ' if not multi-load at all
  219. Language       143      3
  220. Score          147      3  0  = not set
  221. Author         151    100
  222.  
  223.     -->
Add Comment
Please, Sign In to add comment