Creating HTML with M4

Total Page:16

File Type:pdf, Size:1020Kb

Creating HTML with M4 KNOW HOW GNU m4 GNU m4 Creating HTML pages m4 is a macro language used for text processing. It simply copies its input to its output, while expanding built-in or user-defined macros. It can also capture output from standard Linux commands. BY STIG BRAUTASET e will cover the basics of m4 configure script familiar to anyone At this point you may ask “What’s the by separating out content and installing software directly from source. point then? I may as well be writing the Wlayout of HTML web pages. As mentioned earlier, m4 allows us to HTML code in the usual way, instead of The techniques shown are not by any easily define our own macros, and this is using this m4 mumbo-jumbo!” The means restricted to HTML, but are the feature we will focus on. We will astute reader would, of course, be 100% applicable elsewhere as well. learn how to hide layout specifics, long- correct in this observation. However, winded code or arcane syntax behind read on as the benefits will be explained Before we begin… our own simple macros. in the next couple of paragraphs. Very basic knowledge of HTML would be Consider a snip of HTML you write a lot; beneficial, but should not be necessary to How m4 can help you write a simple example is the code for creating read and comprehend the material HTML links. Chances are it will be like this: covered in this article. It is m4’s There are no (to the author’s knowledge) capabilities as a macro processor ready-made macros for writing HTML, <a href="http://www.w3.org">U language the author wishes to communi- so we we will have to write them ourself. www.w3.org</a> cate; HTML was chosen because it is something most people should be at least Naming conventions vaguely familiar with. When splitting the content from the layout of web pages, the author prefers to call the common What is m4? macro file for html.m4.The content of each page goes in a file with the ending “.mac”,e.g. index.mac and so on.When explaining this,however,we develop our macro and .mac files bit by m4 is a macro processor used by bit,so we need to refer to several different files.Thus it is convenient to name them first.m4, Sendmail and GNU Autoconf, etc. first.mac and so on. Sendmail relies on m4 for creating its See the sidebar “Joining the content and layout”how to create the resulting HTML file from the (in)famous sendmail.cf configuration file macros and the content. while Autoconf uses m4 to create the 40 November 2002 www.linux-magazine.com GNU m4 KNOW HOW Now, what if we instead define a simple Comments: documenting The only change is that we now have macro that will allow us to write “$1” and “$2” instead of “$*”. “$1” and our macros “$2” refer to the first and the second __elink(www.w3.org) If a macro is not self-explanatory,we would argument of our macro. The arguments like to put an explanatory comment along are separated by the comma character. side the macro definition. m4 naturally and let m4 do the tedious job of filling in So, Sherlock, what now if we want to allows us to do this; it provides the built-in the necessary bits? That’s less than half create a macro that can take an dnl which reads and discards all characters, the number of characters already. up to and including the first newline. argument with a comma in it? That, my Additionally, observe that we only had to good Watson, is simple. We just have to dnl Iamanexample comment. write the link name once, so there is less put quote the argument. When you dnl Iamhighly unhelpful, chance of us spelling it wrong. quote something, everything between dnl but 100% correct. Another example is if we have a note the quote-characters will be treated as a Using dnl as part of a string does not exhibit on our page telling visitors the date of single argument, even if it consist in this behaviour. the last update. It is tedious work entirety of a string of, say, 90 commas. searching through all the files you have The default opening quote is a “`” changed, searching for and updating body. We will refer to the whole line as (back-tick) and the default closing quote date stamps. Instead we can simply the macro definition. The definition line is a “‘” (single quote). We can now define a macro named, say, __today that above in English: “Define a new macro invoke __link2 with a comma in the will expand into today’s date. The named __link. Everywhere where this second argument thus: search-and-replace business will then be macro occurs, substitute the macro name taken care of for us automatically. How for the body of the macro, but substitute __link2(www.gnu.org, U to do this will be shown later; we need to the macro’s arguments (whatever is 'www.GNU.org, the home of much U take care of the basics first. inside the parentheses following the software') macro name) for “$*” wherever “$*” Getting your hands dirty occurs in the macro body.” The second comma is now quoted, so As mentioned earlier, m4 allow us to We will store the macros we write the macro is indeed invoked with only define our own macros with ease. The ourselves, such as the above, in a file two arguments. Note that only one layer command to let us do this is cunningly called html.m4. Se sidebar “Comments: named define. Here’s how to define a documenting our macros” for details Listing 1: sample.html macro to let us use the link shorthand about how we can mix comments and <html> above: macros in this file. <head> It’s worth noting that macro names do <meta http-equiv="Content-Type"U define(__link, U not have to start with two underscores. It content= "text/html; charset=iso-U <a href="http://$*">$*</a>) is just a convention, because we need to 8859-1"> make sure that we do not pick a string <meta name="description" U The part before the comma (but inside that naturally occurs in the text. content="Sample HTML page"> the parentheses) is the macro name, and Otherwise we may get spurious <meta name="keywords" U the part after the comma is the macro replacements of the macro. content="gnu m4 html"> <meta name="author" content="U Joining the content and Multiple arguments and quoting Stig Brautaset"> layout <title>sample html page</title> The define command we used above Here’s how you create the resulting </head> expects two arguments; the new macro index.html from the macro definitions in <body> name, and what to replace the macro html.m4 and the content in index.mac: <p>Hello, World</p> name with. Considering again the $m4html.m4 index.mac > </body> example with the __link macro above, index.html </html> This invokes the m4 processor with two what should we do if we don’t want to arguments.The m4 command will take the use the URL as the visible, “clickable” macro definitions it finds,do the necessary link? We could simply create a new Listing 2: first.mac macro that takes several arguments, and substitutions and output the result on its __title({Hello World, HTML U standard output.However,we make use of invoke it thus (in context this time, just version}) the shell’s redirection facilities to make the to show that it is possible): “Here is <h1>Hello World</h1> output go to a file instead of the screen (if __link2(www.w3.org, a link to w3.org). <p>Look at this link: U this makes no sense to you,just tag along It is an informative website.” Here’s how __link(www.w3.org)</p> and follow the directions,but you should to define such a beast: consider reading up on shell basics).Now <p>Last updated: __today</p> open first.html in a browser,and voil! We </body> define(__link2, U have a web page! </html> <a href="http://$1">$2</a>) www.linux-magazine.com November 2002 41 KNOW HOW GNU m4 of quotes (the outermost) are stripped by and can even be called several times m4, so the apostrophe in the following from the same file. Listing 5: second.m4 invokation will not yield an error: The effect is immediate, but only for this changequote({,}) U invokation of m4. The author strongly dnl change quote character __link2(www.gnu.org, U advocates that you stick to one set of dnl two macros for link-creation. 'GNU, RMS's pet hobby-horse') quotes, as it quickly becomes rather define(__link, U hairy having to remember which quotes <a href="http://$*">$*</a>) The author usually changes the default go where. define(__link2, U quote characters into “{” and “}” for The quoting “characters”, by the way, <a href="http://$1">$2</a>) readability and ease of typing. The need not be single characters; you may dnl abstract away all the U command for changing the quote use “{([whoopee->” as your opening layout cruft at the beginning. characters, with an appropriate com- quote if you wish. Neither is there any define(__title, { ment attached (see the “Comments: need for the closing quote to correspond <html> documenting our macros” sidebar), is: logically to the opening quote. It is just a <head> convention, and makes the macros <meta http-equiv=U changequote({,}) dnl U easier to read 3 months hence.
Recommended publications
  • Administering Unidata on UNIX Platforms
    C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\ADMINUNIX\ADMINUNIXTITLE.fm March 5, 2010 1:34 pm Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta UniData Administering UniData on UNIX Platforms UDT-720-ADMU-1 C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\ADMINUNIX\ADMINUNIXTITLE.fm March 5, 2010 1:34 pm Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Notices Edition Publication date: July, 2008 Book number: UDT-720-ADMU-1 Product version: UniData 7.2 Copyright © Rocket Software, Inc. 1988-2010. All Rights Reserved. Trademarks The following trademarks appear in this publication: Trademark Trademark Owner Rocket Software™ Rocket Software, Inc. Dynamic Connect® Rocket Software, Inc. RedBack® Rocket Software, Inc. SystemBuilder™ Rocket Software, Inc. UniData® Rocket Software, Inc. UniVerse™ Rocket Software, Inc. U2™ Rocket Software, Inc. U2.NET™ Rocket Software, Inc. U2 Web Development Environment™ Rocket Software, Inc. wIntegrate® Rocket Software, Inc. Microsoft® .NET Microsoft Corporation Microsoft® Office Excel®, Outlook®, Word Microsoft Corporation Windows® Microsoft Corporation Windows® 7 Microsoft Corporation Windows Vista® Microsoft Corporation Java™ and all Java-based trademarks and logos Sun Microsystems, Inc. UNIX® X/Open Company Limited ii SB/XA Getting Started The above trademarks are property of the specified companies in the United States, other countries, or both. All other products or services mentioned in this document may be covered by the trademarks, service marks, or product names as designated by the companies who own or market them. License agreement This software and the associated documentation are proprietary and confidential to Rocket Software, Inc., are furnished under license, and may be used and copied only in accordance with the terms of such license and with the inclusion of the copyright notice.
    [Show full text]
  • Types and Programming Languages by Benjamin C
    < Free Open Study > . .Types and Programming Languages by Benjamin C. Pierce ISBN:0262162091 The MIT Press © 2002 (623 pages) This thorough type-systems reference examines theory, pragmatics, implementation, and more Table of Contents Types and Programming Languages Preface Chapter 1 - Introduction Chapter 2 - Mathematical Preliminaries Part I - Untyped Systems Chapter 3 - Untyped Arithmetic Expressions Chapter 4 - An ML Implementation of Arithmetic Expressions Chapter 5 - The Untyped Lambda-Calculus Chapter 6 - Nameless Representation of Terms Chapter 7 - An ML Implementation of the Lambda-Calculus Part II - Simple Types Chapter 8 - Typed Arithmetic Expressions Chapter 9 - Simply Typed Lambda-Calculus Chapter 10 - An ML Implementation of Simple Types Chapter 11 - Simple Extensions Chapter 12 - Normalization Chapter 13 - References Chapter 14 - Exceptions Part III - Subtyping Chapter 15 - Subtyping Chapter 16 - Metatheory of Subtyping Chapter 17 - An ML Implementation of Subtyping Chapter 18 - Case Study: Imperative Objects Chapter 19 - Case Study: Featherweight Java Part IV - Recursive Types Chapter 20 - Recursive Types Chapter 21 - Metatheory of Recursive Types Part V - Polymorphism Chapter 22 - Type Reconstruction Chapter 23 - Universal Types Chapter 24 - Existential Types Chapter 25 - An ML Implementation of System F Chapter 26 - Bounded Quantification Chapter 27 - Case Study: Imperative Objects, Redux Chapter 28 - Metatheory of Bounded Quantification Part VI - Higher-Order Systems Chapter 29 - Type Operators and Kinding Chapter 30 - Higher-Order Polymorphism Chapter 31 - Higher-Order Subtyping Chapter 32 - Case Study: Purely Functional Objects Part VII - Appendices Appendix A - Solutions to Selected Exercises Appendix B - Notational Conventions References Index List of Figures < Free Open Study > < Free Open Study > Back Cover A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute.
    [Show full text]
  • Top 15 ERP Software Vendors – 2010
    Top 15 ERP Software Vendors – 2010 Profiles of the Leading ERP Vendors Find the best ERP system for your company. For more information visit Business-Software.com/ERP. About ERP Software Enterprise resource planning (ERP) is not a new concept. It was introduced more than 40 years ago, when the first ERP system was created to improve inventory control and management at manufacturing firms. Throughout the 70’s and 80’s, as the number of companies deploying ERP increased, its scope expanded quite a bit to include various production and materials management functions, although it was designed primarily for use in manufacturing plants. In the 1990’s, vendors came to realize that other types of business could benefit from ERP, and that in order for a business to achieve true organizational efficiency, it needed to link all its internal business processes in a cohesive and coordinated way. As a result, ERP was transformed into a broad-reaching environment that encompassed all activities across the back office of a company. What is ERP? An ERP system combines methodologies with software and hardware components to integrate numerous critical back-office functions across a company. Made up of a series of “modules”, or applications that are seamlessly linked together through a common database, an ERP system enables various departments or operating units such as Accounting and Finance, Human Resources, Production, and Fulfillment and Distribution to coordinate activities, share information, and collaborate. Key Benefits for Your Company ERP systems are designed to enhance all aspects of key operations across a company’s entire back-office – from planning through execution, management, and control.
    [Show full text]
  • UNIX Workshop Series: Quick-Start Objectives
    Part I UNIX Workshop Series: Quick-Start Objectives Overview – Connecting with ssh Command Window Anatomy Command Structure Command Examples Getting Help Files and Directories Wildcards, Redirection and Pipe Create and edit files Overview Connecting with ssh Open a Terminal program Mac: Applications > Utilities > Terminal ssh –Y [email protected] Linux: In local shell ssh –Y [email protected] Windows: Start Xming and PuTTY Create a saved session for the remote host name centos.css.udel.edu using username Connecting with ssh First time you connect Unix Basics Multi-user Case-sensitive Bash shell, command-line Commands Command Window Anatomy Title bar Click in the title bar to bring the window to the front and make it active. Command Window Anatomy Login banner Appears as the first line of a login shell. Command Window Anatomy Prompts Appears at the beginning of a line and usually ends in $. Command Window Anatomy Command input Place to type commands, which may have options and/or arguments. Command Window Anatomy Command output Place for command response, which may be many lines long. Command Window Anatomy Input cursor Typed text will appear at the cursor location. Command Window Anatomy Scroll Bar Will appear as needed when there are more lines than fit in the window. Command Window Anatomy Resize Handle Use the mouse to change the window size from the default 80x24. Command Structure command [arguments] Commands are made up of the actual command and its arguments. command -options [arguments] The arguments are further broken down into the command options which are single letters prefixed by a “-” and other arguments that identify data for the command.
    [Show full text]
  • Avoiding the Top 10 Software Security Design Flaws
    AVOIDING THE TOP 10 SOFTWARE SECURITY DESIGN FLAWS Iván Arce, Kathleen Clark-Fisher, Neil Daswani, Jim DelGrosso, Danny Dhillon, Christoph Kern, Tadayoshi Kohno, Carl Landwehr, Gary McGraw, Brook Schoenfield, Margo Seltzer, Diomidis Spinellis, Izar Tarandach, and Jacob West CONTENTS Introduction ..................................................................................................................................................... 5 Mission Statement ..........................................................................................................................................6 Preamble ........................................................................................................................................................... 7 Earn or Give, but Never Assume, Trust ...................................................................................................9 Use an Authentication Mechanism that Cannot be Bypassed or Tampered With .................... 11 Authorize after You Authenticate ...........................................................................................................13 Strictly Separate Data and Control Instructions, and Never Process Control Instructions Received from Untrusted Sources ........................................................................................................... 14 Define an Approach that Ensures all Data are Explicitly Validated .............................................16 Use Cryptography Correctly ....................................................................................................................
    [Show full text]
  • HECO-UNIX-Top Cladding Screw Into the Timber
    HECO-UNIX -top Cladding Screw THE UNIQUE CLADDING SCREW WITH CONTRACTION EFFECT APPLICATION EXAMPLES Façade construction Secure and reliable façade fixing Louvred façades 1 2 3 The variable pitch of the HECO-UNIX full The smaller thread pitch means that the Gap free axial fixing of the timber board thread takes hold boards are clamped firmly together via the HECO-UNIX full thread PRODUCT CHARACTERISTICS The HECO-UNIX-top Cladding Screw into the timber. The façade is secured axially via with contraction effect the thread, which increases the pull-out strength. HECO-UNIX-top full thread This results in fewer fastening points and an Timber façades are becoming increasingly popular ultimately more economical façade construction. Contraction effect thanks to the full in both new builds and renovations. This applica - Thanks to the full thread, the sole function of thread with variable thread pitch tion places high demands on fastenings. The the head is to fit the screw drive. As such, the Axial fixing of component façade must be securely fixed to the sub-structure HECO-UNIX-top façade screw has a small and the fixings should be invisible or attractive raised head, which allows simple, concealed Reduced spreading effect thanks to to look at. In addition, the structure must be installation preventing any water penetration the HECO-TOPIX ® tip permanently sound if it is constantly exposed to through the screw. The screws are made of the weather. The HECO-UNIX-top façade screw stainless steel A2, which safely eliminates the Raised countersunk head is the perfect solution to all of these requirements.
    [Show full text]
  • System Log Commands
    System Log Commands • system set-log , on page 2 • show system logging-level, on page 3 • show log, on page 4 System Log Commands 1 System Log Commands system set-log system set-log To set the log level and log type of messages, use the system set-log command in privileged EXEC mode. system set-log level {debug | info | warning | error | critical} logtype {configuration | operational | all} Syntax Description level Specifies the log level. debug Logs all messages. info Logs all messages that have info and higher severity level. warning Logs all messages that have warning and higher severity level. error Logs all messages that have error and higher severity level. critical Logs all messages that have critical severity level. logtype Specifies the log type. configuration Configuration log messages are recorded. operational Operational log messages are recorded. all All types of log messages are recorded. Command Default For the configuration log, info is the default level. For the operational log, warning is the default level. Command Modes Privileged EXEC (#) Command History Release Modification 3.5.1 This command was introduced. Usage Guidelines After a system reboot, the modified logging configuration is reset to the default level, that is, info for the configuration log and warning for the operational log. Example The following example shows how to configure a log level: nfvis# system set-log level error logtype all System Log Commands 2 System Log Commands show system logging-level show system logging-level To view the log level and log type settings, use the show system logging-level command in privileged EXEC mode.
    [Show full text]
  • Dell EMC Powerstore CLI Guide
    Dell EMC PowerStore CLI Guide May 2020 Rev. A01 Notes, cautions, and warnings NOTE: A NOTE indicates important information that helps you make better use of your product. CAUTION: A CAUTION indicates either potential damage to hardware or loss of data and tells you how to avoid the problem. WARNING: A WARNING indicates a potential for property damage, personal injury, or death. © 2020 Dell Inc. or its subsidiaries. All rights reserved. Dell, EMC, and other trademarks are trademarks of Dell Inc. or its subsidiaries. Other trademarks may be trademarks of their respective owners. Contents Additional Resources.......................................................................................................................4 Chapter 1: Introduction................................................................................................................... 5 Overview.................................................................................................................................................................................5 Use PowerStore CLI in scripts.......................................................................................................................................5 Set up the PowerStore CLI client........................................................................................................................................5 Install the PowerStore CLI client..................................................................................................................................
    [Show full text]
  • Epmp Command Line Interface User Guide
    USER GUIDE ePMP Command Line Interface ePMP Command Line Interface User Manual Table of Contents 1 Introduction ...................................................................................................................................... 3 1.1 Purpose ................................................................................................................................ 3 1.2 Command Line Access ........................................................................................................ 3 1.3 Command usage syntax ...................................................................................................... 3 1.4 Basic information ................................................................................................................. 3 1.4.1 Context sensitive help .......................................................................................................... 3 1.4.2 Auto-completion ................................................................................................................... 3 1.4.3 Movement keys .................................................................................................................... 3 1.4.4 Deletion keys ....................................................................................................................... 4 1.4.5 Escape sequences .............................................................................................................. 4 2 Command Line Interface Overview ..............................................................................................
    [Show full text]
  • BSD UNIX Toolbox 1000+ Commands for Freebsd, Openbsd
    76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iii BSD UNIX® TOOLBOX 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD®Power Users Christopher Negus François Caen 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ii 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page i BSD UNIX® TOOLBOX 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ii 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iii BSD UNIX® TOOLBOX 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD®Power Users Christopher Negus François Caen 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iv BSD UNIX® Toolbox: 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD® Power Users Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-37603-4 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data is available from the publisher. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permis- sion should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
    [Show full text]
  • Project1: Build a Small Scanner/Parser
    Project1: Build A Small Scanner/Parser Introducing Lex, Yacc, and POET cs5363 1 Project1: Building A Scanner/Parser Parse a subset of the C language Support two types of atomic values: int float Support one type of compound values: arrays Support a basic set of language concepts Variable declarations (int, float, and array variables) Expressions (arithmetic and boolean operations) Statements (assignments, conditionals, and loops) You can choose a different but equivalent language Need to make your own test cases Options of implementation (links available at class web site) Manual in C/C++/Java (or whatever other lang.) Lex and Yacc (together with C/C++) POET: a scripting compiler writing language Or any other approach you choose --- must document how to download/use any tools involved cs5363 2 This is just starting… There will be two other sub-projects Type checking Check the types of expressions in the input program Optimization/analysis/translation Do something with the input code, output the result The starting project is important because it determines which language you can use for the other projects Lex+Yacc ===> can work only with C/C++ POET ==> work with POET Manual ==> stick to whatever language you pick This class: introduce Lex/Yacc/POET to you cs5363 3 Using Lex to build scanners lex.yy.c MyLex.l lex/flex lex.yy.c a.out gcc/cc Input stream a.out tokens Write a lex specification Save it in a file (MyLex.l) Compile the lex specification file by invoking lex/flex lex MyLex.l A lex.yy.c file is generated
    [Show full text]
  • What Is UNIX? the Directory Structure Basic Commands Find
    What is UNIX? UNIX is an operating system like Windows on our computers. By operating system, we mean the suite of programs which make the computer work. It is a stable, multi-user, multi-tasking system for servers, desktops and laptops. The Directory Structure All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash / ) Basic commands When you first login, your current working directory is your home directory. In UNIX (.) means the current directory and (..) means the parent of the current directory. find command The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files that match the supplied search criteria. The syntax looks like this: find where-to-look criteria what-to-do All arguments to find are optional, and there are defaults for all parts. where-to-look defaults to . (that is, the current working directory), criteria defaults to none (that is, select all files), and what-to-do (known as the find action) defaults to ‑print (that is, display the names of found files to standard output). Examples: find . –name *.txt (finds all the files ending with txt in current directory and subdirectories) find . -mtime 1 (find all the files modified exact 1 day) find . -mtime -1 (find all the files modified less than 1 day) find . -mtime +1 (find all the files modified more than 1 day) find .
    [Show full text]