functions.php
changeset 34 3b817b961984
parent 33 3b4aef1efff6
child 50 1b4288399b1f
equal deleted inserted replaced
33:3b4aef1efff6 34:3b817b961984
    22  * @param string Error message
    22  * @param string Error message
    23  */
    23  */
    24 
    24 
    25 function burnout($msg)
    25 function burnout($msg)
    26 {
    26 {
       
    27   global $use_colors;
    27   $h = @fopen('php://stderr', 'w');
    28   $h = @fopen('php://stderr', 'w');
    28   fwrite($h, "\x1B[31;1m[Greyhound] fatal: \x1B[37;1m");
    29   if ( $use_colors )
    29   fwrite($h, "$msg\x1B[0m\n");
    30   {
       
    31     fwrite($h, "\x1B[31;1m[Greyhound] fatal: \x1B[37;1m");
       
    32     fwrite($h, "$msg\x1B[0m\n");
       
    33   }
       
    34   else
       
    35   {
       
    36     fwrite($h, "[Greyhound] fatal: $msg\n");
       
    37   }
    30   fclose($h);
    38   fclose($h);
    31   exit(1);
    39   exit(1);
    32 }
    40 }
    33 
    41 
    34 /**
    42 /**
    35  * Print a stylized status message, compatible with Linux consoles
    43  * Print a stylized status message, compatible with Linux consoles. Falls back to no control characters if on unsupported terminal.
    36  * @param string Status message
    44  * @param string Status message
    37  */
    45  */
    38 
    46 
    39 function status($msg)
    47 function status($msg)
    40 {
    48 {
       
    49   global $use_colors;
    41   $h = @fopen('php://stderr', 'w');
    50   $h = @fopen('php://stderr', 'w');
    42   $label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . substr(strval(getmypid()), -3) : 'Greyhound';
    51   $label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . substr(strval(getmypid()), -3) : 'Greyhound';
    43   fwrite($h, "\x1B[32;1m[$label] \x1B[32;0m$msg\x1B[0m\n");
    52   if ( $use_colors )
       
    53   {
       
    54     fwrite($h, "\x1B[32;1m[$label] \x1B[32;0m$msg\x1B[0m\n");
       
    55   }
       
    56   else
       
    57   {
       
    58     fwrite($h, "[$label] $msg\n");
       
    59   }
    44   fclose($h);
    60   fclose($h);
    45 }
    61 }
    46 
    62 
    47 /**
    63 /**
    48  * Print a stylized warning message, compatible with Linux consoles
    64  * Print a stylized warning message, compatible with Linux consoles
    49  * @param string message message
    65  * @param string message message
    50  */
    66  */
    51 
    67 
    52 function warning($msg)
    68 function warning($msg)
    53 {
    69 {
       
    70   global $use_colors;
    54   $h = @fopen('php://stderr', 'w');
    71   $h = @fopen('php://stderr', 'w');
    55   fwrite($h, "\x1B[33;1m[Greyhound] \x1B[0m\x1B[33mWarning:\x1B[0m $msg\n");
    72   if ( $use_colors )
       
    73   {
       
    74     fwrite($h, "\x1B[33;1m[Greyhound] \x1B[0m\x1B[33mWarning:\x1B[0m $msg\n");
       
    75   }
       
    76   else
       
    77   {
       
    78     fwrite($h, "[Greyhound] Warning: $msg\n");
       
    79   }
    56   fclose($h);
    80   fclose($h);
    57 }
    81 }
    58 
    82 
    59 /**
    83 /**
    60  * Performs an action with DCOP.
    84  * Performs an action with DCOP.