M4 (computer language)

m4
Paradigmmacro
Designed byBrian Kernighan, Dennis Ritchie
First appeared1977; 48 years ago (1977)
Major implementations
GNU m4

m4 is a general-purpose macro processor included in most Unix-like operating systems, and is a component of the POSIX standard.

The language was designed by Brian Kernighan and Dennis Ritchie for the original versions of UNIX. It is an extension of an earlier macro processor, m3, written by Ritchie for an unknown AP-3 minicomputer.[1]

The macro preprocessor operates as a text-replacement tool. It is employed to re-use text templates, typically in computer programming applications, but also in text editing and text-processing applications. Most users require m4 as a dependency of GNU autoconf.

History

Macro processors became popular when programmers commonly used assembly language. In those early days of programming, programmers noted that much of their programs consisted of repeated text, and they invented simple means for reusing this text. Programmers soon discovered the advantages not only of reusing entire blocks of text, but also of substituting different values for similar parameters. This defined the usage range of macro processors at the time.[2]

In the 1960s, an early general-purpose macro processor, M6, was in use at AT&T Bell Laboratories, which was developed by Douglas McIlroy, Robert Morris and Andrew Hall.[3]

Kernighan and Ritchie developed m4 in 1977, basing it on the ideas of Christopher Strachey. The distinguishing features of this style of macro preprocessing included:

  • free-form syntax (not line-based like a typical macro preprocessor designed for assembly-language processing)
  • the high degree of re-expansion (a macro's arguments get expanded twice: once during scanning and once at interpretation time)

The implementation of Rational Fortran used m4 as its macro engine from the beginning, and most Unix variants ship with it.

As of 2024 many applications continue to use m4 as part of the GNU Project's autoconf. It also appears in the configuration process of sendmail (a widespread[citation needed] mail transfer agent) and for generating footprints in the gEDA toolsuite. The SELinux Reference Policy relies heavily on the m4 macro processor.

m4 has many uses in code generation, but (as with any macro processor) problems can be hard to debug.[4]

Features

m4 offers these facilities:

  • a free-form syntax, rather than line-based syntax
  • a high degree of macro expansion (arguments get expanded during scan and again during interpretation)
  • text replacement
  • parameter substitution
  • file inclusion
  • string manipulation
  • conditional evaluation
  • arithmetic expressions
  • system interface
  • programmer diagnostics
  • programming language independent
  • human language independent
  • provides programming language capabilities

Unlike most earlier macro processors, m4 does not target any particular computer or human language; historically, however, its development originated for supporting the Ratfor dialect of Fortran. Unlike some other macro processors, m4 is Turing-complete as well as a practical programming language.

Unquoted identifiers which match defined macros are replaced with their definitions. Placing identifiers in quotes suppresses expansion until possibly later, such as when a quoted string is expanded as part of macro replacement. Unlike most languages, strings in m4 are quoted using the backtick (`) as the starting delimiter, and apostrophe (') as the ending delimiter. Separate starting and ending delimiters allows the arbitrary nesting of quotation marks in strings to be used, allowing a fine degree of control of how and when macro expansion takes place in different parts of a string.

Example

The following fragment gives a simple example that could form part of a library for generating HTML code. It defines a commented macro to number sections automatically:

divert(-1)

m4 has multiple output queues that can be manipulated with the
`divert' macro. Valid queues range from 0 to 10, inclusive, with
the default queue being 0. As an extension, GNU m4 supports more
diversions, limited only by integer type size.

Calling the `divert' macro with an invalid queue causes text to be
discarded until another call.  Note that even while output is being
discarded, quotes around `divert' and other macros are needed to
prevent expansion.

# Macros aren't expanded within comments, meaning that keywords such
# as divert and other built-ins may be used without consequence.

# HTML utility macro:

define(`H2_COUNT', 0)

# The H2_COUNT macro is redefined every time the H2 macro is used:

define(`H2',
	`define(`H2_COUNT', incr(H2_COUNT))<h2>H2_COUNT. $1</h2>')

divert(1)dnl
dnl
dnl The dnl macro causes m4 to discard the rest of the line, thus
dnl preventing unwanted blank lines from appearing in the output.
dnl
H2(First Section)
H2(Second Section)
H2(Conclusion)
dnl
divert(0)dnl
dnl
<HTML>
undivert(1)dnl One of the queues is being pushed to output.
</HTML>

Processing this code with m4 generates the following text:

<HTML>
<h2>1. First Section</h2>
<h2>2. Second Section</h2>
<h2>3. Conclusion</h2>
</HTML>

Implementations

FreeBSD, NetBSD, and OpenBSD provide independent implementations of the m4 language. Furthermore, the Heirloom Project Development Tools includes a free version of the m4 language, derived from OpenSolaris.

M4 has been included in the Inferno operating system. This implementation is more closely related to the original m4 developed by Kernighan and Ritchie in Version 7 Unix than its more sophisticated relatives in UNIX System V and POSIX.[5]

GNU m4 is an implementation of m4 for the GNU Project.[6][7] It is designed to avoid many kinds of arbitrary limits found in traditional m4 implementations, such as maximum line lengths, maximum size of a macro and number of macros. Removing such arbitrary limits is one of the stated goals of the GNU Project.[8]

The GNU Autoconf package makes extensive use of the features of GNU m4.

GNU m4 is currently maintained by Gary V. Vaughan and Eric Blake.[6] GNU m4 is free software, released under the terms of the GNU General Public License.

See also

References

  1. ^ Brian W. Kernighan and Dennis M. Ritchie. The m4 macro processor. Technical report, Bell Laboratories, Murray Hill, New Jersey, USA, 1977. pdf
  2. ^ History of GNU m4
  3. ^ Hall, Andrew D. (1972). The M6 Macro Processor. Computing Science Technical Report #2 (PDF) (Report). Bell Labs.
  4. ^ Kenneth J. Turner. Exploiting the m4 macro language. Technical Report CSM-126, Department of Computing Science and Mathematics, University of Stirling, Scotland, September 1994. pdf
  5. ^ m4(1) – Inferno General commands Manual
  6. ^ a b GNU m4 web site "GNU M4", accessed January 25, 2020.
  7. ^ GNU m4 manual, online and for download in HTML, PDF, and other forms. "GNU M4 — GNU macro processor", accessed January 25, 2020.
  8. ^ "GNU Coding Standards: Writing Robust Programs". quote: "Avoid arbitrary limits on the length or number of any data structure".

Read other articles:

الصفحه دى ممكن تحتاج تتويك علشان تبقا حسب معايير ويكيپيديا كمان يمكن الصفحه مافيهاش لينكات لصفحات تانيه, حاول تضيف فيها لينكات لصفحات تانيه متعلقه بيها او تحسين تنسيق الصفحه. رينيه كروز (بالانجليزى: Renae Cruz)    معلومات شخصيه الميلاد 29 نوفمبر 1987 (36 سنة)[1][2]  نيويو

 

此條目可参照英語維基百科相應條目来扩充。若您熟悉来源语言和主题,请协助参考外语维基百科扩充条目。请勿直接提交机械翻译,也不要翻译不可靠、低品质内容。依版权协议,译文需在编辑摘要注明来源,或于讨论页顶部标记{{Translated page}}标签。 2005年5月的加薩走廊地圖,標注藍色的為以色列的定居點 2005年8月18日,加薩走廊定居點克法达罗姆(英语:Kfar Darom)拒絕撤

 

American politician (1929–2009) For other people named Robert Scott, see Robert Scott (disambiguation). Bob Scott67th Governor of North CarolinaIn officeJanuary 3, 1969 – January 5, 1973LieutenantHoyt Patrick Taylor Jr.Preceded byDan K. MooreSucceeded byJames Holshouser25th Lieutenant Governor of North CarolinaIn officeJanuary 8, 1965 – January 3, 1969GovernorDan K. MoorePreceded byHarvey Cloyd PhilpottSucceeded byHoyt Patrick Taylor Jr. Personal detailsBornRobert Walt...

LeRoy Collins Thomas LeRoy Collins (* 10. März 1909 in Tallahassee, Florida; † 12. März 1991 ebenda) war ein US-amerikanischer Politiker und von 1955 bis 1961 der 33. Gouverneur von Florida. Inhaltsverzeichnis 1 Frühe Jahre und politischer Aufstieg 2 Gouverneur von Florida 3 Weiterer Lebenslauf 4 Literatur 5 Weblinks Frühe Jahre und politischer Aufstieg LeRoy Collins besuchte die Leon Highschool in Tallahasse und die Eastman School of Business in New York City. Anschließend studierte e...

 

Weinberg Gipfel des Weinbergs Höhe 88 m ü. NHN Lage Brandenburg, Deutschland Koordinaten 52° 16′ 10″ N, 13° 22′ 40″ O52.26937713.37774388Koordinaten: 52° 16′ 10″ N, 13° 22′ 40″ O Weinberg (Glienick) (Brandenburg) Typ Endmoränenkuppe Glienicker Weinberg auf dem Schmettauschen Kartenwerk von 1767–87 Der Weinberg ist eine an seiner höchsten Stelle 88 Meter hohe Erhebung der Stadt Zossen im Landkr...

 

Пам'ятник Іванові Франку Пам'ятник Іванові Франку. Загальний вигляд 49°33′10″ пн. ш. 25°35′34″ сх. д. / 49.552917° пн. ш. 25.592861° сх. д. / 49.552917; 25.592861Координати: 49°33′10″ пн. ш. 25°35′34″ сх. д. / 49.552917° пн. ш. 25.592861° сх. д. / 49.552...

Peta negara bagian di Nigeria Negara bagian adalah wilayah administratif tingkat satu di Nigeria. Lihat pula ISO 3166-2:NG Templat:Negara bagian di Nigeria Artikel bertopik Nigeria ini adalah sebuah rintisan. Anda dapat membantu Wikipedia dengan mengembangkannya.lbs

 

Historic church in New York, United States United States historic placeFirst Presbyterian ChurchU.S. National Register of Historic PlacesU.S. National Historic Landmark The First Presbyterian Church with steeple (before 1938)Show map of New YorkShow map of the United StatesLocation44 Union Street, Sag Harbor, NYCoordinates40°59′50″N 72°17′37″W / 40.99722°N 72.29361°W / 40.99722; -72.29361Built1844ArchitectMinard LafeverArchitectural styleEgyptian Reviv...

 

You can help expand this article with text translated from the corresponding article in Swedish. (March 2022) Click [show] for important translation instructions. Machine translation, like DeepL or Google Translate, is a useful starting point for translations, but translators must revise errors as necessary and confirm that the translation is accurate, rather than simply copy-pasting machine-translated text into the English Wikipedia. Do not translate text that appears unreliable or low-...

1994 studio album by AutomatonDub Terror ExhaustStudio album by AutomatonReleasedAugust 12, 1994 (1994-08-12)StudioGreenpoint (Brooklyn)GenreAmbient dubLength46:54LabelStrataProducerBill LaswellAutomaton chronology Dub Terror Exhaust(1994) Jihad (Points of Order)(1994) Bill Laswell chronology Cymatic Scan(1994) Dub Terror Exhaust(1994) Visitation(1994) Professional ratingsReview scoresSourceRatingAllMusic[1] Dub Terror Exhaust is an album by American composer Bi...

 

1700 minor battle of the Great Northern War Unless otherwise stated, this article uses contemporary regions as reference and dates from the Gregorian calendar, in preference to the Swedish or the Julian calendar which were used simultaneously. Battle of PalangaPart of the Great Northern WarBattle of Palanga in 1705Date2 February 1705 (O.S.)3 February 1705 (Swedish calendar)13 February 1705 (N.S.)LocationPalanga, Samogitia, LithuaniaResult Swedish victoryBelligerents Swedish Empire Tsardom of ...

 

Multinational wheeled armoured fighting vehicle Boxer Australian Boxer in 2016TypeArmoured fighting vehiclePlace of originMultinationalService historyIn service2011–present (Afghanistan war)Used bySee OperatorsProduction historyDesignerARTEC GmbHDesigned1998–2009Produced2009–presentNo. built539 as of February 2020[1]SpecificationsMass24,000 kg (standard); 36,500 – 38,500 kg (combat);[2] 41,000 kg (technical)[3]Length7.93 m (26 ...

English professional golfer For the American golfer, see Andrew Johnson (golfer). Andrew JohnstonPersonal informationFull nameAndrew Thomas JohnstonNicknameBeef[1]Born (1989-02-18) 18 February 1989 (age 34)London, EnglandHeight1.76 m (5 ft 9 in)Weight96 kg (212 lb; 15.1 st)Sporting nationality EnglandResidenceFriern Barnet, EnglandCareerTurned professional2009Current tour(s)European TourFormer tour(s)Challenge TourPGA TourProfessional wins5Highe...

 

Tenun GorontaloSarung Tenun Gorontalo berwarna hitam dengan motif berwarna emas tahun 1864JenisKain tenunBahanSutra, KapasTempat asalGorontaloPemanufakturGorontalo, Sulawesi, IndonesiaTenun Gorontalo atau Tenun Hulontalo merupakan salah satu ragam wastra atau kain tradisional nusantara yang berasal dari Gorontalo, Pulau Sulawesi.[1] Kain tradisional ini telah menjadi bagian penting dari Suku Gorontalo karena dianggap memiliki makna filosofis, sejarah dan simbol yang bernilai tinggi.&#...

 

United States historic placeMonsrud BridgeFormerly listed on the U.S. National Register of Historic Places Show map of IowaShow map of the United StatesLocationSwebakken Rd. over Paint CreekNearest cityWaterville, IowaCoordinates43°13′08″N 91°19′36″W / 43.21889°N 91.32667°W / 43.21889; -91.32667Built1887Built byKing Iron Bridge Co.Architectural styleBowstring pony archMPSHighway Bridges of Iowa MPSNRHP reference No.98000771[1]Sig...

Sharafnama AuthorSharaf Khan BidlisiCountrySafavid IranLanguagePersianGenreHistoryPublication date1597Media typePrint (Hardback & Paperback) & Audio bookOCLC55981507 The Sharafnama (Kurdish: شەرەفنامە Şerefname, The Book of Honor, Persian: Sharafname, شرفنامه) is the famous book of Sharaf al-Din Bitlisi (a medieval Kurdish historian and poet) (1543–1599), which he wrote in 1597, in Persian.[1] Sharafnama is regarded as an important and oldest source on ...

 

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (يونيو 2019) والتر تشانينج   معلومات شخصية الميلاد 23 سبتمبر 1940  دوفر  تاريخ الوفاة 12 مارس 2015 (74 سنة)   مواطنة الولايات المتحدة  الزوجة ستوكارد تشانينج (1963–1967)...

 

Malaysian federal constituency For Selangor, see Batu (Selangor federal constituency). Batu (P115) the Federal Territories of Malaysia constituencyFederal constituencyLegislatureDewan RakyatMPPrabakaran ParameswaranPHConstituency created1984First contested1986Last contested2022DemographicsPopulation (2020)[1]219,132Electors (2022)[2]113,863Area (km²)[3]20Pop. density (per km²)10,956.6 Batu is a federal constituency in the Federal Territories, Malaysia, that has been ...

ШварценбергSchwarzenberg (Vorarlberg) Герб Координати 47°24′48″ пн. ш. 09°51′11″ сх. д.H G O Країна АвстріяАвстріяЗемля ФорарльбергОкруг БрегенцМежує з сусідні нас. пункти Дорнбірн, Альбершвенде, Егг ? Площа 25,76 км²[1]Висота центру 696 мНаселення 1850 осіб (1 січня 2018)...

 

Questa voce o sezione sull'argomento centri abitati della Spagna non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. Segui i suggerimenti del progetto di riferimento. Navadijoscomune Navadijos – Veduta LocalizzazioneStato Spagna Comunità autonoma Castiglia e León Provincia Ávila TerritorioCoordinate40°25′32.16″N 5°05′00.96″W...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!