[PHP-DEV] New CLI switches (was [PHP-DEV] Using CLI as a shell)

2003-02-04 Thread Edin Kadribasic
First simply use php -h but i am also thinking about adding a man
page.

That is a bit too much text for 'php -h'. It should be moved to the
online manual. Adding a man page would be great too.

[snip]
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 appears to be equivelant of:

find . -name '*.c' -o -name '*.h' | php -r 'while (!feof(STDIN)) {
$q=count(file($n=trim(fgets(STDIN; echo $n($q)\n; $l+=$q;
$f++; } echo Files $f, Lines: $l\n;'

Am I correct in this assumption? If yes, could please try to point
out what are the advantages of -B -R -E and -F over using just -r?

Edin


-- 
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-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




[PHP-DEV] Re: New CLI switches (was [PHP-DEV] Using CLI as a shell)

2003-02-04 Thread Marcus Börger
At 10:28 04.02.2003, Edin Kadribasic wrote:

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

That is a bit too much text for 'php -h'. It should be moved to the
online manual. Adding a man page would be great too.


I wrote already i will do so...but haven't yet the time.


[snip]
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 appears to be equivelant of:

find . -name '*.c' -o -name '*.h' | php -r 'while (!feof(STDIN)) {
$q=count(file($n=trim(fgets(STDIN; echo $n($q)\n; $l+=$q;
$f++; } echo Files $f, Lines: $l\n;'

Am I correct in this assumption? If yes, could please try to point
out what are the advantages of -B -R -E and -F over using just -r?


Yes it is the same result. I never said you cannot do it otherwise.
The reason i implemented the switches is that it makes thinks easier.
And sometimes making things easier for users is better than knowing
as a developer that there is a solution.

regards
marcus


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




Re: [PHP-DEV] Re: New CLI switches (was [PHP-DEV] Using CLI as a shell)

2003-02-04 Thread Sander Roobol
On Tue, Feb 04, 2003 at 08:25:45PM +0100, Marcus B?rger wrote:
 Am I correct in this assumption? If yes, could please try to point
 out what are the advantages of -B -R -E and -F over using just -r?
 
 Yes it is the same result. I never said you cannot do it otherwise.
 The reason i implemented the switches is that it makes thinks easier.
 And sometimes making things easier for users is better than knowing
 as a developer that there is a solution.

I don't like this. IMO all those switches make it messy... and I really
don't see the advantage of this over -r. PHP isn't supposed to be used
like this. If it things get too complicated for -r, write a separate
script instead of hacking up the command line. 
-1 on this.

Sander

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




Re: [PHP-DEV] Re: New CLI switches (was [PHP-DEV] Using CLI as a shell)

2003-02-04 Thread Andrei Zmievski
  I don't like this. IMO all those switches make it messy... and I really
  don't see the advantage of this over -r. PHP isn't supposed to be used
  like this. If it things get too complicated for -r, write a separate
  script instead of hacking up the command line. 
  -1 on this.
 
 Yeah, I still dont see the real advantages here.

Same here.

-Andrei   http://www.gravitonic.com/

Don't sweat it -- it's not real life.  It's only ones and zeroes.
   -- Gene Spafford

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




[PHP-DEV] Re: New CLI switches (was [PHP-DEV] Using CLI as a shell)

2003-02-04 Thread Edin Kadribasic
On Tuesday 04 February 2003 20:25, Marcus Börger wrote:
[snip]
 That is a bit too much text for 'php -h'. It should be moved to the
 online manual. Adding a man page would be great too.

 I wrote already i will do so...but haven't yet the time.

Could you please then remove the explanation from the php -h output?

[snip]
 Yes it is the same result. I never said you cannot do it otherwise.
 The reason i implemented the switches is that it makes thinks easier.
 And sometimes making things easier for users is better than knowing
 as a developer that there is a solution.

After having played a bit with the new switches I begun to see the idea. I 
actually kind of like the ease of use that they give for providing search  
replace sort of capability and using extensive array of PHP string functions.

For example its quite easy to strip tags from an html file/output:

php -d html_errors=1 -i | php -R 'echo strip_tags($argn).\n;'

So provided that you remove large (and imho confusing) output on the bottom of 
-h I'm +1 on keeping these changes.

Edin

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




[PHP-DEV] Using CLI as a shell

2003-02-03 Thread Marcus Börger
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:

  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?

regards
marcus


--
--- mailto:[EMAIL PROTECTED] --
We are animals among animals, all children of matter,
save that we are the more disarmed. But since, unlike animals,
we know that we must die, let us prepare for that moment
by enjoying the life that has been given us by chance and for chance.
   Umberto Eco, The island of the day before
- http://marcus-boerger.de -


--
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