0

So I'm trying to make a relatively complicated php script, using some code written in pike. The full source code is available here: http://www.text-image.com/pic2html.pike . It's only a learning experience really, as I'm not going to release it. However I would like to get it working!

int main(int arg 

            if (temp > 10485760) {
                werr("Image too large (10MB limit).");
                return 0;
        }

        string info = Stdio.stdin.read(temp);

        if (strlen(info) < temp) {
                werr("Insufficient data uploaded.");
                return 0;
        }

I understand the if statement on line 3."If the integer 'temp' is larger then 10485760, execute function 'werr' with the string ('Image too large (10MB limit.');

I also understand the if statement on line 8, which is very similar to the first statement.

What I don't understand is the

string info = Stdio.stdin.read(temp);

I don't understand the

int main(int arg 

If I had to guess, I'd say the result of the function would be applied to an integer called 'main'? Is that right? How could this be emulated in php?

Thanks for your time!

Starkers
  • 10,273
  • 21
  • 95
  • 158
  • This looks like C++ code. – Mawg says reinstate Monica Feb 18 '13 at 01:54
  • Yes, it's something called 'Pike', which is very, very similar to C++. Nobody seems to use it, but it's so similar to C++ I'm sure someone will know! – Starkers Feb 18 '13 at 01:57
  • 1
    It is pike, a powerful script language with c-systax: http://pike.lysator.liu.se/ You have truncated the first line. It should be `int main(int argc, array(string) argv) {`, a normal c-like header for the main function. In `argc` you get the number of arguments passed to the program, and in `argv` you get the values of the arguments. You don't need that in PHP. `string info = Stdio.stdin.read(temp);` reads `temp` number of bytes from _standard input_ (the CGI-data) into the variable `info` and that is later decoded with `object msg = MIME.Message( info, headies );` PHP does that automagically. – some Jul 23 '13 at 22:22

2 Answers2

2

I don't know this language, but seems very similar to C++.

The:

int main(int arg 

is the beginning of the main function wich doesn't exist in PHP therefore you can just omit it. In compiled languages the main function is the first function to be called when the program starts. In PHP the file requested is just executed line per line.

And the:

string info = Stdio.stdin.read(temp);

feels like:

std::string info;
std::cin >> info;

which just read from the standard input stream. There's nothing such a thing as iostream in PHP, the inputs are cookies, POST, GET, DELETE, PUT etc. and are made per request.

Shoe
  • 74,840
  • 36
  • 166
  • 272
2

This looks like C++ code (amybe Java or C#? but I don't know either of htose). All C and C++ programs must have exactly one function called main(). When a .exe compiled from C or C++ code runs execution starts there. It retuns an integer so that whatever called it can tell if it was successful or not.

The werr call is probably some kid of "write error".

Line 8 : string info = Stdio.stdin.read(temp); is reading a line from standard input (stdin) using standard i/o routines (in stdio) and storing it in a variable called info which is of type string.

To convert to PHP, try googling ;-)

Hint: you will porbably need a form (but see also this question).

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551