1#!/usr/bin/env php 2<?php 3 $codes = array(); 4 $maxlen = 0; 5 6 while (!feof(STDIN)) { 7 $line = fgets(STDIN); 8 9 if (ereg('^\{[[:space:]]+(ER_.*)[[:space:]]+,[[:space:]]*"(.*)",[[:space:]]*"(.*)"', $line, $matches)) { 10 $codes[$matches[1]] = $matches[2]; 11 $maxlen = max($maxlen, strlen($matches[1])); 12 } 13 } 14 15 if (empty($codes)) { 16 fputs(STDERR, "input doesn't look like a MySQL sql_state.h file\n"); 17 exit(3); 18 } 19 20 echo "/* DO NOT EDIT THIS FILE!!! It is auto generated by get_error_codes.php */\n"; 21 foreach ($codes as $code => $state) { 22 echo "#ifdef $code\n"; 23 printf(" case %-{$maxlen}s: return \"%s\";\n", $code, $state); 24 echo "#endif\n"; 25 } 26 27 28?> 29