ebook img

Internet Programming with OmniMark PDF

391 Pages·2002·5.09 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Internet Programming with OmniMark

Internet Programming with OmniMark Internet Programming with OmniMark Edited by Mark Baker KLUWER ACADEMIC PUBLISHERS NEW YORK / BOSTON / DORDRECHT/LONDON / MOSCOW eBookISBN: 0-306-46989-8 Print ISBN: 0-792-37237-9 ©2002 Kluwer Academic Publishers New York, Boston, Dordrecht, London, Moscow All rights reserved No part of this eBook may be reproduced or transmitted in any form or by any means, electronic, mechanical, recording, or otherwise, without written consent from the Publisher Created in the United States of America Visit Kluwer Online at: http://www.kluweronline.com and Kluwer's eBookstore at: http://www.ebooks.kluweronline.com v Table of contents Introduction:WhyOmniMark?...................................................................................1 The streaming programming model ............................................................................1 Impact of the Internet revolution ................................................................................2 What is a stream? ........................................................................................................3 A stream has a source and a destination .................................................................3 A stream has movement .........................................................................................4 A stream has structure ............................................................................................4 Streams are of unknown length ..................................................................................5 A streaming programming language ...........................................................................5 Source and destination abstraction .........................................................................5 High level data scanning features ...........................................................................6 High level context management ............................................................................. 6 Placeholder capability .............................................................................................6 Data structures where required ...............................................................................7 Broad-based connectivity........................................................................................ 7 vi Internet Programmingwith OmniMark Co-routine support ............................................................................................... 8 Robust high level server programming support .................................................. 8 The benefits of streaming programming .................................................................. 8 Performance..........................................................................................................9 Robustness ...........................................................................................................9 Productivity..........................................................................................................10 What are streaming programming languages good for? .......................................... 10 Is streaming programming a low-level approach?...................................................11 Are there any other streaming programminglanguages? .........................................11 Streaming languages vs . object-oriented languages ...............................................11 About this book ........................................................................................................12 1:Helloworld..............................................................................................................15 Hello World CGI.................................................................................................17 Hello World server ..............................................................................................18 Writing“Hello World” to a file .............................................................................20 Technique.................................................................................................................... 20 The universal output mechanism .........................................................................20 Managing output destinations with output scopes ............................................... 21 Streams.................................................................................................................23 Directing output to multiple destinations.............................................................24 Line end and network protocols ...............................................................................26 Syntax...........................................................................................................................27 General OmniMark syntax rules ..............................................................................27 Keywords................................................................................................................28 process......................................................................................................................28 output.......................................................................................................................28 stream......................................................................................................................28 using output as ..................................................................................................... 28 local..........................................................................................................................29 open.........................................................................................................................29 #current-output........................................................................................................29 #process-output........................................................................................................29 "%n"......................................................................................................................... 29 Table ofcontents vii | | ............................................................................................................................29 Review........................................................................................................................30 Exercises....................................................................................................................30 2: Converting text to HTML ........................................................................................31 Technique ...................................................................................................................34 Establishing sources with “using input as” ............................................................34 Scanning the input stream ..........................................................................................34 Setting traps for data using find rules ....................................................................35 Rules and the structure of OmniMark programs....................................................37 Watch and learn .....................................................................................................38 Establishing sources directly .................................................................................39 Syntax .........................................................................................................................39 #args .......................................................................................................................39 #current-input.............................................................................................................40 submit.....................................................................................................................40 using input as .........................................................................................................40 find .........................................................................................................................40 Review ........................................................................................................................40 Exercises .....................................................................................................................41 3: Converting an ASCII table to HTML...........................................................43 Technique ....................................................................................................................45 Syntax.........................................................................................................................47 Literal strings ..................................... ........................................................................47 line-start......................................................................................................................48 Occurrence indicators .............................................................................................48 Groups....................................................................................................................48 Review........................................................................................................................49 Exercises .....................................................................................................................49 viii Internet Programming with OmniMark 4:Findinglinksinaweb page...........................................................................51 Technique..........................................................................................................................52 A sponge rule ................................................................................................................52 Using character classes .................................................................................................53 Capturing matched data: Pattern variables ...................................................................55 Finding data in context ...........................................................................................55 Case insensitive pattern matching.........................................................................57 Capturing partial patterns .......................................................................................57 More on character classes ......................................................................................58 Built-in character classes .........................................................................................58 User defined character classes ...............................................................................59 Using macros to encapsulate character classes ............................................................61 Using macros to encapsulate common patterns ...........................................................61 Syntax.......................................................................................................................62 patternvariableassignmentoperator(=>)......................................................................62 User defined character classes ...............................................................................63 ul..........................................................................................................................63 lookahead.................................................................................................................. 64 Review............................................................................................................................ 64 Exercises........................................................................................................................ 64 5: Displaying the CGI environment variables ............................................................67 Technique......................................................................................................................69 Reading data from the CGI interface ...................................................................69 Using shelves ............................................................................................................70 Repeating over a shelf .............................................................................................71 Retrieving a key ........................................................................................................71 Escaping markup characters when generating HTML .............................................. 71 Syntax.............................................................................................................................72 variable.....................................................................................................................72 repeat over ................................................................................................................72 key of .........................................................................................................................72 Review............................................................................................................................73 Exercises........................................................................................................................73 Table of contents ix 6: Disaster countdown .......................................................................................75 Technique................................................................................................................78 Retrieving specific items from a shelf ................................................................78 A CGI program with multiple modes ..................................................................79 Pulling values out of a string ..............................................................................80 Converting a number to text for output ...............................................................81 Turning off input buffering .................................................................................82 Syntax...................................................................................................................... 82 shelves................................................................................................................82 has key................................................................................................................. 83 format operator (%)............................................................................................83 do when..............................................................................................................84 do scan ....................................................................................................................84 match..................................................................................................................85 Review....................................................................................................................85 Exercises.....................................................................................................................86 7: Hit counter ...........................................................................................................87 Technique................................................................................................................88 The integer data type ...........................................................................................89 Setting the value of a data destination ................................................................89 Streams as strings ...............................................................................................90 Syntax.....................................................................................................................91 set........................................................................................................................91 integer..................................................................................................................91 initial....................................................................................................................91 increment.............................................................................................................92 Review.....................................................................................................................92 Exercises..................................................................................................................92 x Internet Programmingwith OmniMark 8: Database to XML ...................................................................................................93 Technique................................................................................................................94 Accessingdatabases............................................................................................ 94 GeneratingXML.................................................................................................95 Handling errors ...................................................................................................96 Using always to ensure a valid document is returned ........................................97 Syntax.....................................................................................................................97 catch....................................................................................................................98 #external-exception.............................................................................................98 number of ............................................................................................................99 dbOpenODBC.....................................................................................................99 dbQuery...............................................................................................................100 dbFieldValue.......................................................................................................100 dbRecordMove....................................................................................................100 dbRecordExists....................................................................................................101 always..................................................................................................................102 number of ............................................................................................................102 halt.......................................................................................................................102 Review....................................................................................................................102 Exercises ................................................................................................................103 9: A game of hangman ...............................................................................................105 Technique................................................................................................................109 Scanning as a programming technique ...............................................................109 Flow control in a streaming program ..................................................................111 Using do scan for flow control ...........................................................................111 Encapsulating logic with functions .....................................................................113 Using exceptions for exceptional cases .............................................................. 113 Guarding statements ...........................................................................................115 Basic error reporting ...........................................................................................115 Using reopen to append data to a file .................................................................. 116 Syntax...................................................................................................................... 117 reopen..................................................................................................................117 formatitems.........................................................................................................117 #program-error ....................................................................................................118 Tableofcontents xi when and unless ............................................................................................................118 repeat scan .......................................................................................................................119 any**........................................................................................................................119 = | .............................................................................................................................120 declare catch ............................................................................................................ 121 catch.........................................................................................................................121 throw........................................................................................................................121 ~ (identity) ..............................................................................................................122 drop (and take) .........................................................................................................122 modulo..................................................................................................................... 122 define function ......................................................................................................... 123 matches..................................................................................................................... 123 UTIL_rand...............................................................................................................124 global.......................................................................................................................124 Review.........................................................................................................................124 Exercises......................................................................................................................124 10: Using formatting templates ......................................................................................127 Technique....................................................................................................................128 An optimized bucket match ....................................................................................129 Using an argument file to parameterize a program .................................................129 Centralizing template processing ........................................................................... 131 The template processing function ........................................................................... 131 Handling template errors ........................................................................................ 133 Syntax.......................................................................................................................... 134 define function (with arguments) ........................................................................... 134 has key ...................................................................................................................136 key of ..................................................................................................................... 136 set new ................................................................................................................... 136 Review....................................................................................................................... 137 Exercises....................................................................................................................138

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.