Re: [PHP-DEV] Using CLI as a shell

2003-02-04 Thread Michael Mauch
Marcus Börger [EMAIL PROTECTED] wrote:

 There is a difference between interactive mode and this idea. The
 idea was to execute every single line. So if you type 'echo Hello\n;
 and press enter Hello should be displayed.

That's how it works for me (PHP-4.3.0). The only pitfall is that you
need to use ?php:

# php -a
Interactive mode enabled

?php
echo Hello\n;
Hello

 
Regards...
Michael

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Using CLI as a shell

2003-02-03 Thread Derick Rethans
On Mon, 3 Feb 2003, Marcus [iso-8859-1] Börger wrote:

 After adding -B, -F, -R and -E which will hopefully liked by the rest
 of development team so that the stuff need not to be removed.

Perhaps start by explaining what they do?

 I (or better a friend of mine) had another idea. Here comes:
 
Why not use CLI as a shell?
 
 I'd say adding a command line switch say -S which parses and executes every
 line that is entered. What do you think?

PHP is not a shell, and we have interactive mode for that already. I 
really don't see the use for this.

Derick

-- 

-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Using CLI as a shell

2003-02-03 Thread Marcus Börger
At 19:37 03.02.2003, Derick Rethans wrote:

On Mon, 3 Feb 2003, Marcus [iso-8859-1] Börger wrote:

 After adding -B, -F, -R and -E which will hopefully liked by the rest
 of development team so that the stuff need not to be removed.

Perhaps start by explaining what they do?


First simply use php -h but i am also thinking about adding a man
page.

Ok an example even though i do not know if it is a good one because
you may find better solutions but it shows how it works. Type the
following shell command at the php source directory:

find . -name '*.c' -o -name '*.h' | php -B '$l=0;' -R 
'$f=count(file($argn)); echo $argn($n)\n;$l+=$f;' -E 'echo Files: $argi, 
Lines: $l\n;'

This one uses find to search for all .c and .h files in the current directory.
At startup it initialises $l to zero. For every line reported by find (every
file) the statement in -R gets executed. That statement counts the lines
in the current file and shows its name and linecount. After all files are
processed the statement in -E show the result (line count of all files).

I hope the above example points out the idea.


 I (or better a friend of mine) had another idea. Here comes:

Why not use CLI as a shell?

 I'd say adding a command line switch say -S which parses and executes every
 line that is entered. What do you think?

PHP is not a shell, and we have interactive mode for that already. I
really don't see the use for this.


Just an idea to think about

There is a difference between interactive mode and this idea. The
idea was to execute every single line. So if you type 'echo Hello\n;
and press enter Hello should be displayed.


regards
marcus


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Using CLI as a shell

2003-02-03 Thread gk
At 07:31 PM 2/3/2003 +0100, Marcus Börger wrote:

After adding -B, -F, -R and -E which will hopefully liked by the rest of 
development
team so that the stuff need not to be removed. I (or better a friend of 
mine) had another
idea. Here comes:

I am glad to hear someone else is interested in php.cli improvements.

I have written an extension to Gnu Make which enables using sapi/cli/php in 
a makefile environment with auto-detection of dependencies. See: 
http://www.xmake.org

I have previously posted twice on the subject of a -M switch (similar to 
gcc -M), for enabling proper use of sapi/cli/php in a makefile environment 
- I got no responses.

Here is the proposal:

* Add a '-M' option to sapi/cli/php that would behave essentially the same 
as gcc -M and enable the use of php command-line scripts to work properly 
in a makefile build environment (See below for explanation of gcc -M).

* 'php -M -f myFile.php' should differ from 'gcc -M myFile.c', in two ways:
a) Command output should only list prerequisite files rather than 
a complete dependency makefile rule since there is no standard suffix for 
php output as for C [ myFile.o : myFile.c ... ]
b) Detect dependencies other than included and required files, as 
reported by get_included_files(). There are many other ways that a PHP 
script could become dependent on other files which cannot easily be 
determined automatically unless a function is available for a script to 
explicitly declare that it depends on an external file. [Example: ? if 
(file_exists($myFile)) echo hello;?].

* Add two built-in PHP functions to allow '-M' option to accurately 
identify file dependencies in PHP source files (the names could change):
void register_prerequisite_file( string $myFile )
Array get_prerequisite_files( )

* With the above two functions, this is how the system should work:
In the following example, /usr/local/bin/php-cli is the command-line 
version of PHP: sapi/cli/php
- file: test.php
#!/usr/local/bin/php-cli
?
php include( myIncludedFile.php );
register_prerequisite_file( myRequiredFile)
if (file_exists( myRequiredFile )) echo got file;
?
 eof

Internally php-cli -M would call get_included_files() and 
get_prerequisite_files() and join them together in a space separated list, 
with the first item being the source file. Here is what php-cli would do 
from the command line:

$/usr/local/bin/php-cli -M -f test.php
test.php myIncludedFile.php myRequiredFile

---
# example makefile which implements the functionality without php -M

# Command for generating output files from source files
# the command-line version of php binary must be specified in: 
XME_php.cli_outfileCmd
# this is built under php_source_dir/sapi/cli/php
XME_php.cli_outfileCmd:=/usr/local/bin/php

# Command to generate a list of dependencies from a source file (including 
the source file)
# $(1) - source file
define XME_php.cli_dependCmd
$(shell $(XME_php.cli_outfileCmd) -r 'include $(1); $$tmpFile = 
$(XMAKE_TMP_DIR)/php.cli_dependCmd_out; if 
(function_exists('get_prerequisite_files')){ $$files = 
get_prerequisite_files();}else{$$files = get_included_files();} $$str = 
join( ,$$files); $$fp  = @fopen( $$tmpFile, w); fputs( $$fp, $$str );' 
1$(XMAKE_TMP_DIR)/php.cli_dependCmd_junk || { cat 
$(XMAKE_TMP_DIR)/php.cli_dependCmd_junk; exit 1; }; cat 
$(XMAKE_TMP_DIR)/php.cli_dependCmd_out; )
endef

# end of makefile


Below is what the include file looks like

?php
/*
These functions supporting php dependency makefile rule generation
This file would become obsolete if sapi/cli/php -M option is approved for 
inclusion in PHP

USAGE:
// paths to files must be ABSOLUTE paths, resolving any symbolic links
// assume your script uses a file 'file1', in the same directory as the 
script file
// $file1=realpath(file1) doesn't work since it returns false if the file 
doesn't exist
// since file1 may be created by XMake, we need the path whether or not it 
exists
// Try this:

require_once( getenv(XMAKE_HOME)./config/XMExtensions/php.cli.inc );
$filesArray=array( dirname(__FILE__).'/file1'  );
register_prerequisite_files( $filesArray );

*/

$XMAKE_PHP_PREREQUISITE_FILES=array();

function register_prerequisite_files( $filesArray ){
global $XMAKE_PHP_PREREQUISITE_FILES;
$XMAKE_PHP_PREREQUISITE_FILES = 
array_merge($XMAKE_PHP_PREREQUISITE_FILES, $filesArray);
}

function get_prerequisite_files(){
global $XMAKE_PHP_PREREQUISITE_FILES;
$filesArray = array_merge(get_included_files(), 
$XMAKE_PHP_PREREQUISITE_FILES);
return $filesArray;
}
?

- Greg Keraunen
http://www.xmake.org
http://www.xmlmake.com


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Using CLI as a shell

2003-02-03 Thread Harald Radi

 There is a difference between interactive mode and this idea. The
 idea was to execute every single line. So if you type 'echo Hello\n;
 and press enter Hello should be displayed.

i like this idea, so i no longer have to type echo Hello on my bash prompt
:)

harald


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Using CLI as a shell

2003-02-03 Thread Richard Heyes
  There is a difference between interactive mode and this idea. The
  idea was to execute every single line. So if you type 'echo Hello\n;
  and press enter Hello should be displayed.

 i like this idea, so i no longer have to type echo Hello on my bash
prompt
 :)

At least with this (presumably) Python style shell you could use readline to
prevent you typing echo Hello twice (as opposed to current php -a). :)

--
Richard Heyes



-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DEV] Using CLI as a shell

2003-02-03 Thread David Sklar
   There is a difference between interactive mode and this idea. The
   idea was to execute every single line. So if you type 'echo Hello\n;
   and press enter Hello should be displayed.
 
  i like this idea, so i no longer have to type echo Hello on my bash
 prompt
  :)

 At least with this (presumably) Python style shell you could use
 readline to
 prevent you typing echo Hello twice (as opposed to current php -a). :)

The Command Shell program in Recipe 20.9 of the PHP Cookbook uses
readline() to implement a PHP shell-style prompt, where each line is
executed as you type it. It also uses readline_completion_function() to
provide tab-completion for function names.

You can download it in the archive of code from the book at:
-- http://examples.oreilly.com/phpckbk/


-dave


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php