Announcement

Collapse
No announcement yet.

DecodeCGI - Why was it done this way? PBCGI.INC

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • DecodeCGI - Why was it done this way? PBCGI.INC

    Any thoughts....

    Why was this done this way?

    Code:
    FUNCTION DecodeCGI(BYVAL t AS STRING) AS STRING
      DIM b_in  AS BYTE PTR
      DIM b_out AS BYTE PTR
      DIM h     AS STRING PTR * 2
      DIM a     AS ASCIIZ PTR
      IF LEN(t) = 0 THEN
        EXIT FUNCTION
      END IF
      b_in  = STRPTR(t)
      b_out = b_in
      DO
        IF @b_in = 43 THEN          'convert plus to space
          @b_out = 32
        ELSEIF @b_in = 37 THEN      'process special chars
          h = b_in + 1
          @b_out = VAL("&H" + @h)
          b_in = b_in + 2
        ELSE
          @b_out = @b_in
        END IF
        INCR b_in
        INCR b_out
      LOOP UNTIL @b_in = 0
      @b_out = 0
      a = STRPTR(t)
      FUNCTION = @a
    END FUNCTION


    Why not just use REPLACE when you find a + in the string? There are only two cases here, right?
    I am assuming the use of Pointers makes this fast?

    Just wondering....

  • #2
    ?????
    Is CGI for Color Graphic Interface (old video standard (low res)), Common Gateway Interface (web server side processing of return data from web pages), or Computer Generated Imagery?

    PBCGI.inc; is that from Jose's site or somewhere else? Because it does not come with PowerBASIC.

    With some hint as to why a "+" is in the string, someone might recognize why it's done that way.

    Maybe because that include file pre-dates existance of REPLACE statement in PB.

    Cheers,
    Dale

    Comment


    • #3
      Originally posted by Dale Yarker View Post
      ?????
      Maybe because that include file pre-dates existance of REPLACE statement in PB.

      Cheers,
      That would be my guess.

      --
      [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
      PNG Domain Hosting[/URL]

      Comment


      • #4
        Also, must step through pointer to each character in string to process "%", then may as well do "+" if at that pointer. (instead of going through the string a second time with REPLACE.)

        Cheers,
        Dale

        Comment


        • #5
          Is this the file? From 1998, last update 2000? For PB/CC 2.0 and later?

          https://forum.powerbasic.com/forum/u...nc-file-update

          Certainly pre-dates REPLACE
          --
          [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
          PNG Domain Hosting[/URL]

          Comment


          • #6
            Just looked at the code in question. Its not a simple replace. It replaces URL encoded characters in the form "%xx". i.e. "%20" is converted to a space "%21" to a "!", all the way up to "%FF" = ÿ

            Since you are stepping through the string to do that, it makes sense to handle the "+" at the same time.
            --
            [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
            PNG Domain Hosting[/URL]

            Comment


            • #7
              Stuart,

              And that old forum thread you gave link for answers another of the questions. The "CGI" is for Common Gateway Interface.
              Dale

              Comment


              • #8
                THANKS!
                I think Stuart is right about " It replaces URL encoded characters in the form "%xx".

                Comment


                • #9
                  Why?

                  Maybe it was simply "programmer preference."

                  That is allowed, you know!








                  Comment


                  • #10
                    Originally posted by Stuart McLachlan View Post
                    Is this the file? From 1998, last update 2000? For PB/CC 2.0 and later?

                    https://forum.powerbasic.com/forum/u...nc-file-update

                    Certainly pre-dates REPLACE
                    It doesn't predate REPLACE. I just did a quick search through my old PB/DOS sources and found the REPLACE command in source files dating back to 1990.

                    Comment


                    • #11
                      Originally posted by Knuth Konrad View Post

                      It doesn't predate REPLACE. I just did a quick search through my old PB/DOS sources and found the REPLACE command in source files dating back to 1990.
                      I stand corrected
                      --
                      [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                      PNG Domain Hosting[/URL]

                      Comment

                      Working...
                      X