PHP Beyond the Web Shell Scripts, Desktop Software, System Daemons and More

Total Page:16

File Type:pdf, Size:1020Kb

PHP Beyond the Web Shell Scripts, Desktop Software, System Daemons and More PHP Beyond the web Shell scripts, desktop software, system daemons and more Rob Aley This book is for sale at http://leanpub.com/php This version was published on 2013-11-25 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. ©2012 - 2013 Rob Aley Tweet This Book! Please help Rob Aley by spreading the word about this book on Twitter! The suggested hashtag for this book is #phpbeyondtheweb. Find out what other people are saying about the book by clicking on this link to search for this hashtag on Twitter: https://twitter.com/search?q=#phpbeyondtheweb Contents Welcome ............................................ i About the author ...................................... i Acknowledgements ..................................... ii 1 Introduction ........................................ 1 1.1 “Use PHP? We’re not building a website, you know!”. ............... 1 1.2 Are you new to PHP? ................................. 2 1.3 Reader prerequisites. Or, what this book isn’t .................... 3 1.4 An important note for Windows and Mac users ................... 3 1.5 About the sample code ................................ 4 1.6 External resources ................................... 4 1.7 Book formats/versions available, and access to updates ............... 5 1.8 English. The Real English. .............................. 5 2 Getting away from the Web - the basics ......................... 6 2.1 PHP without a web server .............................. 6 2.2 PHP versions - what’s yours? ............................. 7 2.3 A few good reasons NOT to do it in PHP ...................... 8 2.4 Thinking about security ................................ 9 3 Understanding the CLI SAPI, and why you need to .................. 11 3.1 What’s different about the CLI SAPI? ........................ 11 3.2 CLI SAPI installation ................................. 12 3.3 PHP command line options .............................. 12 3.4 Command line arguments for your script ...................... 17 3.5 The many ways to call PHP scripts ......................... 18 3.6 “Click to Run” your PHP ............................... 22 3.7 Quitting your script .................................. 26 4 Development tools ..................................... 27 4.1 PHP REPLs ...................................... 27 4.2 Build systems ..................................... 32 4.3 Continuous Integration ................................ 33 4.4 Debuggers ....................................... 37 4.5 Testing and Unit Testing ............................... 40 4.6 Static code analysis .................................. 43 4.7 Virtual development & testing environments .................... 48 4.8 Source/version control systems & code repositories . 50 CONTENTS 4.9 IDEs and editors .................................... 52 4.10 Documentation generators .............................. 52 4.11 Profilers ........................................ 54 4.12 Other tools ....................................... 54 5 User facing software .................................... 58 5.1 Command line interface basics ............................ 59 5.2 Advanced command line input ............................ 63 5.3 Using STDIN, STOUT & STDERR .......................... 66 5.4 Partial GUI elements - dialogs ............................ 68 5.5 Dialogs invoked from the shell ............................ 68 5.6 Windows dialogs ................................... 70 5.7 Static HTML output .................................. 70 5.8 Complete graphical interfaces (GUIs) ........................ 72 5.9 Understanding GUI and event-based programming . 73 5.10 PHP-GTK ....................................... 74 5.11 wxPHP ......................................... 76 5.12 Local web server & browser ............................. 77 5.13 PHP’s Built-in testing server ............................. 78 5.14 Web sockets & browser ................................ 79 5.15 SiteFusion ....................................... 81 5.16 Winbinder ....................................... 82 5.17 Adobe AIR ....................................... 83 5.18 Titanium ........................................ 84 5.19 PHP-Qt ........................................ 84 5.20 PHP/TK ........................................ 85 6 System software ...................................... 86 6.1 Daemons in PHP ................................... 86 6.2 Creating a daemon .................................. 87 6.3 Network daemons using libevent ........................... 91 6.4 File monitoring daemons using inotify ........................ 97 6.5 Task dispatch & management systems . 102 6.6 Gearman and PHP ..................................103 6.7 Other task dispatch systems .............................105 7 Interacting with other software ............................. 107 7.1 Starting external processes from PHP, or “shelling out” . 107 7.2 Talking to other processes ..............................108 7.3 Semaphores ......................................108 7.4 Shared Memory ....................................110 7.5 PHP message queues .................................115 7.6 Third party message queues .............................120 7.7 APC cached variables .................................122 7.8 Virtual files - tmpfs ..................................123 7.9 Standard streams ...................................124 7.10 Linux signals .....................................124 CONTENTS 7.11 Task dispatch & management systems . 124 8 Talking to the system ................................... 125 8.1 Filesystem interactions ................................125 8.2 Data files & formats ..................................125 8.3 Dealing with large files ................................126 8.4 Understanding filesystem interactions . 128 8.5 The PHP file status and realpath caches . 129 8.6 Working with cross platform filesystems . 130 8.7 Accessing the Windows Registry . 130 8.8 Linux signals .....................................133 8.9 Linux timed-event signals ..............................136 8.10 Printing (to paper) ...................................139 8.11 Audio .........................................141 8.12 Databases - no change here ..............................143 8.13 Other hardware and system interactions . 143 9 Performance & stability - profiling and improving .................. 144 9.1 The background on performance . 144 9.2 Specific issues for general purpose programming . 145 9.3 Profile, profile, profile! ................................146 9.4 Manual profiling ...................................147 9.5 Profiling tools .....................................148 9.6 Low level profiling ..................................152 9.7 Profiling - the likely results ..............................152 9.8 Silver bullets ......................................153 9.9 Silver bullet #1 - Better hardware . 153 9.10 Silver bullet #2 - Newer PHP versions . 154 9.11 Silver bullet #3 - Opcode caching . 154 9.12 Silver bullet #4 - Compiling ..............................155 9.13 Silver bullet #5 - JIT compilers and alternative Virtual Machines . 157 9.14 The SPL - Standard PHP Library . 161 9.15 Garbage collection ..................................162 9.16 Multi-threading and concurrent programming in PHP . 163 9.17 Big data and PHP - MapReduce . 165 9.18 Data caching .....................................166 9.19 Know thy functions ..................................167 9.20 Outsourcing code to other languages . 168 9.21 Other performance tips and tricks . 169 9.22 Stability and performance of long running processes . 169 9.23 Avoid micro and premature optimisations . 171 10 Distribution and deployment issues ........................... 173 10.1 Error handling and logging ..............................173 10.2 Installers and bundling files .............................175 10.3 Embedded data files at end of PHP script . 175 10.4 Phar executable bundles ...............................176 CONTENTS 10.5 Generic installers ...................................178 10.6 Controlling the (PHP) environment . 178 10.7 Extending your application with plug-ins . 179 10.8 Documentation ....................................180 10.9 Licensing & legal ...................................180 10.10 Deploying frameworks ................................181 11 Where now? or, Thanks & feedback ........................... 183 11.1 Giving feedback, and getting help and support . 183 11.2 Giving testimonials ..................................183 11.3 Are you reading a “pirated” copy? . 183 Appendix A : Compiling and installing PHP and its extensions ............. 185 Compiling and installing PHP itself ............................185 Compiling and installing (extra) core extensions . 188 Installing multiple versions of PHP ............................189 PEAR and PECL .......................................190 Composer ..........................................191 Symfony2 bundles ......................................192 Appendix B : File & data format libraries for PHP ..................... 193 Office documents ......................................193 Compression, archiving & encryption . 194 Graphics ...........................................195 Audio ............................................195 Multimedia & video .....................................196
Recommended publications
  • The Shogun Machine Learning Toolbox
    The Shogun Machine Learning Toolbox Heiko Strathmann, Gatsby Unit, UCL London Open Machine Learning Workshop, MSR, NY August 22, 2014 A bit about Shogun I Open-Source tools for ML problems I Started 1999 by SÖren Sonnenburg & GUNnar Rätsch, made public in 2004 I Currently 8 core-developers + 20 regular contributors I Purely open-source community driven I In Google Summer of Code since 2010 (29 projects!) Ohloh - Summary Ohloh - Code Supervised Learning Given: x y n , want: y ∗ x ∗ I f( i ; i )gi=1 j I Classication: y discrete I Support Vector Machine I Gaussian Processes I Logistic Regression I Decision Trees I Nearest Neighbours I Naive Bayes I Regression: y continuous I Gaussian Processes I Support Vector Regression I (Kernel) Ridge Regression I (Group) LASSO Unsupervised Learning Given: x n , want notion of p x I f i gi=1 ( ) I Clustering: I K-Means I (Gaussian) Mixture Models I Hierarchical clustering I Latent Models I (K) PCA I Latent Discriminant Analysis I Independent Component Analysis I Dimension reduction I (K) Locally Linear Embeddings I Many more... And many more I Multiple Kernel Learning I Structured Output I Metric Learning I Variational Inference I Kernel hypothesis testing I Deep Learning (whooo!) I ... I Bindings to: LibLinear, VowpalWabbit, etc.. http://www.shogun-toolbox.org/page/documentation/ notebook Some Large-Scale Applications I Splice Site prediction: 50m examples of 200m dimensions I Face recognition: 20k examples of 750k dimensions ML in Practice I Modular data represetation I Dense, Sparse, Strings, Streams, ... I Multiple types: 8-128 bit word size I Preprocessing tools I Evaluation I Cross-Validation I Accuracy, ROC, MSE, ..
    [Show full text]
  • ( 12 ) United States Patent
    US010430263B2 (12 ) United States Patent ( 10 ) Patent No. : US 10 ,430 , 263 B2 Polar Seminario (45 ) Date of Patent : Oct. 1 , 2019 ( 54 ) DEVICES, SYSTEMS AND METHODS FOR ( 56 ) References Cited VALIDATING AND UPGRADING FIRMWARE IN INTELLIGENT ELECTRONIC DEVICES U . S . PATENT DOCUMENTS (71 ) Applicant: Electro Industries /Gauge Tech , 2 ,883 , 255 A 4 / 1959 Anderson Westbury , NY (US ) 2 , 987 , 704 A 6 / 1961 Gimpel et al . ( Continued ) ( 72 ) Inventor: Jorge A . Polar Seminario , Westbury, NY (US ) FOREIGN PATENT DOCUMENTS (73 ) Assignee : Electro Industries /Gauge Tech , CN 101799681 A 8 /2010 Westbury, NY (US ) WO 2009044369 A2 4 / 2009 ( * ) Notice: Subject to any disclaimer, the term of this OTHER PUBLICATIONS patent is extended or adjusted under 35 U . S . C . 154 ( b ) by 59 days. Microsoft TechNet , Using DNS Servers with DHCP, Jan . 21, 2005 , Accessed from https: // technet. microsoft . com / en -us / library / ( 21 ) Appl. No. : 15 /421 , 573 cc787034 on Jun . 9 , 2015 ; pp . 1 - 4 . (22 ) Filed : Feb . 1, 2017 (Continued ) Primary Examiner — Charles Ehne (65 ) Prior Publication Data (74 ) Attorney , Agent, or Firm — Gerald E . Hespos ; US 2017/ 0220404 A1 Aug . 3 , 2017 Michael J . Porco ; Matthew T . Hespos Related U . S . Application Data (57 ) ABSTRACT (60 ) Provisional application No . 62 /289 , 440 , filed on Feb . Apparatuses , systems, and method for validating and 1 , 2016 . upgrading firmware in an intelligent electronic device ( IED ) (51 ) Int. Ci. are provided. In one aspect of the present disclosure , an IED G06F 11 /00 ( 2006 . 01 ) is provided including at least one processor and at least one GO6F 11/ 07 (2006 .
    [Show full text]
  • Java Code Documentation Example
    Java Code Documentation Example Fruitless Martino sometimes quick-freeze his peritonitis hugely and night-club so dispraisingly! Glottogonic and sublinear Finn melt his bodice permeates podding benevolently. Oswald usually medicines surgically or orbs telescopically when polyunsaturated Hugh dement evidentially and lewdly. The javadoc itself an unsupported extension and is also important in the description for code documentation comment merely repeats the banner section DocsapijavanetURLhtmlgetAuthority-- a method getAuhority in the. API reference code comments Google Developers. Omitting many times classes being documented type, and java example of each field, all trademarks and description below code completion window, which we used to. Java Programming Style Guide. The keyboard shortcut to comment multiple in Windows is shift alt A. 10 Best Practices to multiple While Writing Code Javarevisited. Concise presentations of java programming practices tasks and conventions amply illustrated with syntax highlighted code examples. Java Documentation Comments Tutorialspoint. Java Programming Guidelines. If this tag easily comment related comments java code, this user to new field in the dependency. The following examples demonstrate a pain line summary followed by detailed documentation in song three. CS 302 Commenting Guide Program Commenting Guide File. For sober you spawn use author tag to identify the author of a. Opinions expressed by the code example code documentation is overridden in the documentation for example code base classes and decide to allow bikes to achieve these methods. Example slope from the Javadoc documentation code can be documented inline Single Line comments are started by each may be positioned after a. The Documentation Comment Specification permits leading asterisks on enough first.
    [Show full text]
  • Chapter 4: Forges
    Chapter 4: Forges Josep M. Rib´o October 15, 2010 INDEX Chapter 4: Forges 4.1 Introduction • Repositories (forges) • Repositories of repositories 4.2 Sourceforge.net 4.3 Google code 4.4 Trac 1 4.1 Introduction INDEX 4.1 Introduction A project repository (aka a forge) is a web platform that offers project hosting and infrastructure to develop an open source project following the bazaar-model This infrastructure includes: • Version control system • Bug/issue tracker • Mail lists • Monitoring tools • Software downloading tools.... A repository of repositories (aka RoRs) is a repository that aggregates projects from other repositories or private websites extracting data and collecting various measures Usually, they are not repositories that provide infrastructure to manage the project (version control system, bug tracker...) but they provide a project index meant to search for projects that satisfy specific features 2 4.1 Introduction INDEX Repositories [BLM2008] provides a list of repositories and repositories of repositories (Table from [BLM2008]) A summary of these repositories and their features is presented in the next few slides 3 4.1 Introduction INDEX • Apache (http://www.apache.org) It stores projects developed by the Apache foundation These projects have some common features: { Collaborative, community-based development process { Open software license { Managed by a self-selected team of software experts who are the project core developers { Membership to the foundation (and the right to change the repository content) is granted only to volunteers that have contributed to the project (meritocracy) The repository offers a software catalogue with a short description of each project: { Programming languages, { Categories, { Lists, { Issue tracker { License { Proejct website { ..
    [Show full text]
  • Overall Features Performance Price
    Scan this code for more info. To download a barcode app, SMS <f2k> to 56677 from a mobile phone with Internet access and camera. SMARTPHONE JOLLA Experience a different way of operating a smartphone without any home or back button — Ashok Pandey to operate, but those who are upgrading to taste the new flavor may struggle a little. At the start, it asks to setup your account and then, it guides you how to use the phone. The first screen reminded us of BB 10 OS. Since there is no Home button, you’ll have to learn a lot of gestures, shortcuts and cues. Sailfish OS sup- ports Android apps and games, and most apps run smoothly. Although there is no issue with Android apps and games on Jolla, but with third party apps like facebook you will find some functionality and notification differences, as Price: `15,490 they are not integrated with the system. Feels good and runs smooth: Jolla has 4.5-inch qHD (960x450p) display, though we were expecting a 720p display, yet screen has good viewing angles. The display is average to use in direct sunlight. It is backed by a 1.4GHz dual-core processor, 1GB RAM and 16 GB internal memory (13.7 GB available to the user) expandable via microSD card. Navigating the phone was quite easy, and launching and switching between apps was smooth. It is equipped with 8 MP rear camera with LED flash that captures quality images in day- light with decent color reproduction. The cam- here are many smartphone manufacturers era comes with several settings for the flash, and OS platforms available in the market.
    [Show full text]
  • Wxshapeframework: an Easy Way for Diagrams Manipulation in C++ Applications
    WSEAS TRANSACTIONS on COMPUTERS Michal Bliznak, Tomas Dulik, Vladimir Vasek WXSHAPEFRAMEWORK: AN EASY WAY FOR DIAGRAMS MANIPULATION IN C++ APPLICATIONS MICHAL BLIŽŇÁK1, TOMÁŠ DULÍK2, VLADIMÍR VAŠEK3 Department of Informatics and Artificial Inteligence1, 2, Department of Automation and Control Engineering3 Faculty of Applied Informatics, Tomas Bata University Nad Stráněmi 4511, 760 05, Zlín CZECH REPUBLIC [email protected], [email protected], [email protected] Abstract: wxShapeFramework is new cross-platform software library written in C++ programming language which is suitable for creation of software applications manipulating diagrams, images and other graphical objects. Thanks to the underlying technologies such as wxWidgets toolkit and its XML-based persistent data container add-on called wxXmlSerializer it is an ideal solution for rapid and easy cross-platform visualisation software development. The paper reveals how the wxSF allows user to easily create applications able to interactively handle various scenes consisting of pre-defined or user-defined graphic objects (both vector- and bitmap-based) or GUI controls, store them to XML files, export them to bitmap images, print them etc. Moreover, thanks to applied software licence the library can be used for both open-source and commercial projects on all main target platforms including MS Windows, MacOS and Linux. Keywords: Diagram, vector, bitmap, GUI, wxWidgets, wxXmlSerializer, wxShapeFramework, wxSF, C++ 1 Introduction called shapes (including basic rectangular and elliptic shapes, line and curve shapes, polygonal shapes, static Modern software applications often need the ability to and in-place editable text, bitmap images, etc.). graphically represent various data or logical structures, information flows, processes and similar The wxSF allows to define relationship between abstract information types in the form of diagrams.
    [Show full text]
  • Visual Studio Code
    Visual Studio Code What is Visual Studio Code? Any programme / software that we see or use, works on the code that runs in the background. Traditionally coding used to done in the traditional editors or even in the basic editors like notepad ! These editors used to provide basic support to the coders. Some of them, so were so basic that it was very difficult in writing basic English level programmes in them. As the time-went by, some programming languages needed specific framework and support for further coding and development in it, which was not possible using these editors. VI Editor, Sublime Text Editor and Visual Studio Code are one of the many kinds of editors that came into existence. The most prominent and which supports almost every coding language is VISUAL STUDIO CODE. Visual Studio Code features let user modify the editor as per the usage, which means, user is able to download the libraries from the internet and integrate it with the code as per his requirements. Visual Studio Code Definition and understanding it Visual Studio Code is a code editor in layman’s terms. To define it, Visual Studio Code is, “a free-editor which helps the programmer to write a code, helps in debugging and corrects the code using the intelli- sense method ”. In normal terms, it facilitates user to write the code in easy manner. Many people say that it is half of an IDE and an editor; but the decision is upto to the coders. What Visual Studio Code can do Visual Studio Code has some very unique features.
    [Show full text]
  • Escuela Politecnica Del Ejército Dpto. De Ciencias
    ESCUELA POLITECNICA DEL EJÉRCITO DPTO. DE CIENCIAS DE LA COMPUTACIÓN CARRERA DE INGENIERÍA EN SISTEMAS E INFORMÁTICA IMPLANTACIÓN DE UN SISTEMA WEB EN EL LABORATORIO OPTIMAGEM, PARA LA AUTOMATIZACIÓN DEL ENVÍO DE RESULTADOS DE EXÁMENES CLÍNICOS A LOS MÉDICOS TRATANTES Previa a la obtención del Título de: INGENIERO EN SISTEMAS E INFORMÁTICA POR: JUAN ESTEBAN CABRERA GUERRA LORENA IVETH MELO VELOZ SANGOLQUÍ, 29 de Julio de 2009 i CERTIFICACIÓN DE ELABORACIÓN DEL PROYECTO Certificamos que el presente proyecto “Implantación de un Sistema Web en el Laboratorio OPTIMAGEM S.A., para la automatización del envió de resultados de exámenes clínicos a los médicos tratantes” fue realizado en su totalidad por el Sr. JUAN ESTEBAN CABRERA GUERRA Y la Srta. LORENA IVETH MELO VELOZ, como requerimiento parcial para la obtención del título de Ingeniero en Sistemas e Informática. _________________ __________________ Ing. Rodrigo Fonseca Ing. Danilo Martínez DIRECTOR CODIRECTOR Sangolquí, 29 de julio de 2009 ii DEDICATORIA La presente tesis primero quiero dedicarla a Dios por haberme bendecido con su paciencia y enseñanza diaria, ante las adversidades de la vida, a mis padres por depositar su confianza, amor y comprensión durante toda mi carrera universitaria, a mi hermano por estar a mi lado en el día a día apoyándome en todo momento. A mis familiares, docentes y amigos que supieron apoyarme con sus consejos, conocimientos y valores durante mi permanencia en la Escuela Politécnica del Ejército. Lorena Iveth Melo Veloz La presente tesis va dedicada a DIOS por haberme dado la fortaleza y la sabiduría para concluir esta etapa de mi carrera profesional, a mis padres por el apoyo y la confianza que me supieron brindar a través de toda mi carrera estudiantil, a mi hermana, mi cuñado, mis amigos y familiares por sus consejos y apoyo que me ayudaron a nunca desmayar en este duro camino.
    [Show full text]
  • Vmpro 3.2 Open Source Licenses
    Quantum vmPRO 3.2 Open Source Licenses This document presents the open source software components used in Quantum® vmPRO™ 3.2. For information on obtaining the open source code, contact Quantum Support. Abstract This document lists the open source components used in the vmPRO product along with their licenses. 6-67728-03 Rev A, August 2014 *6-67728-02 A* Quantum vmPRO 3.2 Open Source License Agreement 6-67728-03 Rev A August 2014 Standard RPMs in the CentOS OS Package Version Build URL License ConsoleKit 0.4.1 3.el6 http://www.freedesktop.org/wiki/Software/ GPLv2+ ConsoleKit ConsoleKit- 0.4.1 3.el6 http://www.freedesktop.org/wiki/Software/ MIT libs ConsoleKit MAKEDEV 3.24 6.el6 http://www.lanana.org/docs/device-list/ GPLv2 MariaDB- 10.0.3 1 http://mariadb.org GPL compat MariaDB- 10.0.3 1 (none) GPL compat-pkg QuantumOS 2.8.0 2607 (none) Proprietary TPlugin acl 2.2.49 6.el6 http://acl.bestbits.at/ GPLv2+ aic94xx- 30 2.el6 http://www.adaptec.com/en-US/speed/scsi/ Redistributable, no firmware linux/aic94xx-seq-30-1_tar_gz.htm modification permitted atmel- 1.3 7.el6 http://at76c503a.berlios.de/ Redistributable, no firmware modification permitted attr 2.4.44 7.el6 http://acl.bestbits.at/ GPLv2+ audit-libs 2.2 2.el6 http://people.redhat.com/sgrubb/audit/ LGPLv2+ authconfig 6.1.12 13.el6 https://fedorahosted.org/authconfig GPLv2+ avahi-libs 0.6.25 12.el6 http://avahi.org LGPLv2 Made in the USA. Quantum Corporation provides this publication “as is” without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability or fitness for a particular purpose.
    [Show full text]
  • Php Editor Mac Freeware Download
    Php editor mac freeware download Davor's PHP Editor (DPHPEdit) is a free PHP IDE (Integrated Development Environment) which allows Project Creation and Management, Editing with. Notepad++ is a free and open source code editor for Windows. It comes with syntax highlighting for many languages including PHP, JavaScript, HTML, and BBEdit costs $, you can also download a free trial version. PHP editor for Mac OS X, Windows, macOS, and Linux features such as the PHP code builder, the PHP code assistant, and the PHP function list tool. Browse, upload, download, rename, and delete files and directories and much more. PHP Editor free download. Get the latest version now. PHP Editor. CodeLite is an open source, free, cross platform IDE specialized in C, C++, PHP and ) programming languages which runs best on all major Platforms (OSX, Windows and Linux). You can Download CodeLite for the following OSs. Aptana Studio (Windows, Linux, Mac OS X) (FREE) Built-in macro language; Plugins can be downloaded and installed from within jEdit using . EditPlus is a text editor, HTML editor, PHP editor and Java editor for Windows. Download For Mac For macOS or later Release notes - Other platforms Atom is a text editor that's modern, approachable, yet hackable to the core—a tool. Komodo Edit is a simple, polyglot editor that provides the basic functionality you need for programming. unit testing, collaboration, or integration with build systems, download Komodo IDE and start your day trial. (x86), Mac OS X. Download your free trial of Zend Studio - the leading PHP Editor for Zend Studio - Mac OS bit fdbbdea, Download.
    [Show full text]
  • Comments and Documentation 2501ICT/7421Ictnathan
    C Comments Using Doxygen Comments and Documentation 2501ICT/7421ICTNathan René Hexel School of Information and Communication Technology Griffith University Semester 1, 2012 René Hexel Comments and Documentation C Comments Using Doxygen Outline 1 C Comments 2 Using Doxygen René Hexel Comments and Documentation C Comments Using Doxygen Comments Plain C allows comments between /* and */ /* this is a valid C comment */ Comments may not be nested /* this /* is not a valid C comment */ */ C99 also allows double-slash // end-of-line comments // this is a valid comment no closing sequence needed – the comment ends at the end of the line René Hexel Comments and Documentation C Comments Using Doxygen Comment Example Example (Program with Comments) /* * This program prints "j = 007". * It does not take any parameters and returns 0 on success. */ int main(void)/ * main function definition */ { int j; // our int variable to play with j=7; // assign a value to be printed printf("j = %03.3dnn",j); // print value with leading zeroes return 0; // everything is fine, exit program } René Hexel Comments and Documentation C Comments Using Doxygen Where to put comments? At the beginning of each file (module) describe the name of the module, purpose, author, and dates when first created and last modified Before each function (method) describe the purpose of the function or method, input parameters (arguments), return values (output parameters), and pre- and postconditions (contract) At the beginning of each class describe the purpose of the class, and things to
    [Show full text]
  • SWIG and Ruby
    SWIG and Ruby David Grayson Las Vegas Ruby Meetup 2014-09-10 SWIG ● SWIG stands for: Simplified Wrapper and Interface Generator ● SWIG helps you access C or C++ code from 22 different languages, including Ruby SWIG inputs and outputs Ruby C extension SWIG interface file (.i) source (.c or .cxx) Simple C++ example libdavid.h: libdavid.i #include <stdio.h> %module "david" class David %{ { #include <libdavid.h> public: %} David(int x) { class David this->x = x; { } public: David(int x); void announce() void announce(); { int x; }; printf("David %d\n", x); } int x; }; Compiling Simple C++ example extconf.rb require 'mkmf' system('swig -c++ -ruby libdavid.i') or abort create_makefile('david') Commands to run: $ ruby extconf.rb # create libdavid_wrap.cxx and Makefile $ make # compile david.so $ irb -r./david # try it out irb(main):001:0> d = David::David.new(4) => #<David::David:0x007f40090a5280 @__swigtype__="_p_David"> irb(main):002:0> d.announce David 4 => nil (This example worked for me with SWIG 3.0.2 and Ruby 2.1.2.) That example was pretty simple ● All code was in a .h file ● No external libraries ● Simple data types ● No consideration of deployment ...but SWIG has tons of features C: C++: ● All ISO C datatypes ● All C++ datatypes ● Global functions ● References ● Global variables, constants ● Pointers to members ● Structures and unions ● Classes ● Pointers ● (Multiple) inheritance ● (Multidimensional) arrays ● Overloaded functions ● Pointers to functions ● Overloaded methods ● Variable length arguments ● Overloaded operators ● Typedefs ● Static members ● Enums ● Namespaces ● Templates ● Nested classes ... SWIG Typemaps ● Define custom ways to map between scripting- language types and C++ types. ● Can be used to add and remove parameters from of exposed functions.
    [Show full text]