Writing Your Own Text Editor, Part 1

Total Page:16

File Type:pdf, Size:1020Kb

Writing Your Own Text Editor, Part 1 Search Java Magazine Menu Topics Issues Downloads Subscribe September 2019 For the Fun of It: Writing Your Own CODING Text Editor, Part 1 The Line Between Layers of Code For the Fun of It: Writing Your Own Buffer Management Text Editor, Part 1 UI/Command Structure Using a layered design and iterative Parameterized Testing development, a line editor evolves into a Further Work text editor in this new article series. Code Reuse by Ian Darwin Getting the Code August 26, 2019 Conclusion After reading the title of this article, you might be thinking, “A text editor in Also in This Issue Java? Why would you want to do that? Isn’t Java just for enterprise web apps?” My first answer is heck no! Java is still alive and well on the desktop. My second answer is that getting away from the web environment—some Java developers’ main “comfort zone”—moves the focus towards design and interesting implementation issues. In this first article, I focus on building a simple line-mode text editor. I do this through iterative implementation. That is, I start with a simple implementation. Then, as I add new features, I update the design and reimplement it. In an upcoming article, I will turn it into a graphical desktop editor. In all its variations, it will remain a pure text editor; that is, a program for changing a plain-text file. Plain text—no font or color changes—still makes up the bulk of the world’s computer-facing information: batch/script files, program source files, configuration files, log files, and much more. There’s a big jump from a plain-text editor to a full word processor that provides the ability to select typefaces and type size and color; embed images and spreadsheets; align text left, right, or center; and so much more. It would be difficult to focus on all that in a series of short articles, so for the time being, I’ll focus on plain text. When you design an editor, the two main things to think about are the user interface (UI) or command layer and buffer management. The UI or command layer defines what the user can do to work on the in-memory buffer. These tasks may be simple commands for a line editor, mouse gestures on a screen editor, voice commands on an interactive system, and so on. Buffer management is how the user works on the text in a buffer. Text editors—along with their larger kin, word processors— generally keep an in-memory copy of the file on which changes are made. This copy is stored in memory in a buffer. The editor will write this modified text in place of the original file on disk when the user exits the editor or when some kind of “save” command is issued. Buffer management, also known as the model code, is concerned with looking after the in-memory contents of the file being edited. Both the UI and buffer management, as well as the all-important interface between them, need to be well designed for the end product to be both useful and maintainable. The Line Between Layers of Code Defining a Java interface is a powerful (and common) way of separating logical layers of code. Interfaces should be used between layers of an application and on any class that is likely to have (now or later) multiple implementations. The classes can then depend on the interface, not the particular implementations. In this case, the BufferPrims interface meets both needs: It is a layer boundary, and it has multiple implementations. This is similar to a database-backed application, where you’d likely have an interface between the middle (business logic) layer and the database code. This would allow switching among JDBC, Java Persistence API (JPA)/Hibernate, and maybe NoSQL databases. Some have argued that the JPA EntityManager or Hibernate’s Session are general-enough interfaces for this purpose; others suggest using an application-specific interface. There’s no one right answer for all applications, but these are the design considerations. The editor needs an interface between the command layer and the buffer management layer. A very trivial interface between these layers might look like this: public interface BufferPrims { addLineAfter(int afterLine, String newLine); deleteLine(int lineNumber); replaceText(oldText, newText); } This interface tells the command code nothing much about how the buffer management works, and at the same time it tells the buffer management nothing about how the UI works. That’s important, because it’s desirable to be able to replace either part without having any effect on the other. And that is true of layered software in general: Layers should know nothing at all about the layer above them (so they can be invoked from different UIs, say) and know only how to invoke the layer directly below them, nothing more. To make an actual editor, the interface needs to be a bit more comprehensive. I wound up with something like this version: public interface BufferPrims { final int NO_NUM = 0, INF = Integer.MAX_VALUE; void addLines(List<String> newLines); void addLines(int start, List<String> newLines) void deleteLines(int start, int end); void clearBuffer(); void readBuffer(String fileName); void writeBuffer(String fileName); int getCurrentLineNumber(); String getCurrentLine(); int goToLine(int n); int size(); // Number of lines, as per old C /** Retrieve one or more lines */ String getLine(int ln); List<String> getLines(int i, int j); /** Replace first/all occurrences of 'old' regex * with 'new' text, in current line only */ void replace(String oldRE, String newStr, boolea /** Replace first/all occurrences in each line * void replace(String oldRE, String newStr, boolean all, int startLine, int endLine); boolean isUndoSupported(); /** Undo the most recent operation; * optional method */ default void undo() { throw new UnsupportedOperationException(); } } Most of the operations probably seem straightforward. The source code for this article provides three implementations of the BufferPrims interface. The optional undo method is in one of these implementations but not the others; I discussed that implementation previously in this article on the Command design pattern. Some might argue that read() and write() don’t belong here and that the main program should read the file a line at a time and ingest the lines using one of the add() methods. The read() and write() methods are in this interface for efficiency; there may be versions where you read the entire file with a single read operation. Buffer Management Having multiple implementations that differ significantly provides some evidence that the interface is based on a sensible design. But it doesn’t say anything about efficiency—speaking of which, if you didn’t care about efficiency, you could just keep everything in a single String object. Because strings are immutable, this approach would require a lot of reallocation, so a StringBuilder or StringBuffer is a better basis for a naive implementation. In fact, the first implementation of the buffer primitives (BufferPrims) will use BufferPrimsStringBuffer. Although a StringBuffer has some advantages—such as built-in methods for modifying the contents of the buffer—it is not a natural organization for what is essentially a list of lists of words or, more precisely, a list of lines. Accordingly, the StringBuffer implementation, which I talked myself into writing to show that it could be done, has to do some work just to find where the lines begin and end. To keep things consistent, I made the assumption that each line would end with a single newline character ('\n'); carriage returns ('\r') would be banned altogether. With this approach, I can find where one line ends and the next begins just by looking for those newline characters. Most of the operations in this class end by calling StringBuffer methods to get or set characters at particular positions in the StringBuffer. For example, here’s the code to get the current line’s contents: @Override public String getCurrentLine() { int startOffset = findLineOffset(current); int len = findLineLengthAt(startOffset); return buffer.substring(startOffset, startOffset + len); } The findLineOffset method uses a regular expression to find the lines, so it’s a bit more than just a for loop looking for newline characters, although that would be a workable naive implementation. Similarly, the StringBuffer-based line deletion makes use of the same two methods: @Override public void deleteLines(int startLine, int endLine) if (startLine > endLine) { throw new IllegalArgumentException(); } int startOffset = findLineOffset(startLine), endOffset = findLineOffset(endLine); buffer.delete(startOffset, endOffset + findLineLengthAt(endOffset) + 1 } The substitute (s) command is probably the most complicated command; I describe the variations of it in the “UI/Command Structure” section. When all the command options have been parsed, the UI layer has to call one of two methods: void replace(String oldRE, String newStr, boolean all); void replace(String oldRE, String newStr, boolean all, int startLine, int endLine); The variable all controls whether all occurrences, or just the first, are to be replaced. Here’s the implementation of the one-line version of replace: @Override public void replace(String oldRE, String newStr, boolean all) { int startOffset = findLineOffset(current); int length = findLineLengthAt(startOffset); String tmp = buffer.substring(startOffset, length); tmp = all ? tmp.replaceAll(oldRE, newStr) : tmp.replace(oldRE newStr); buffer.replace(startOffset, length, tmp); } A second implementation. The second implementation of the buffer code, BufferPrimsNoUndo, stores the buffer data in a List<String> , which is a data structure that’s easier to work with on a line-by-line basis. For example, getting the current line consists of just the following code: @Override public String getCurrentLine() { return buffer.get( lineNumToIndex(current)); } (Because the line numbers start at 1 but List indices start at 0, there’s a lineNumToIndex() method to convert from a line number to an array index.
Recommended publications
  • 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]
  • Unix/Linux Command Reference
    Unix/Linux Command Reference .com File Commands System Info ls – directory listing date – show the current date and time ls -al – formatted listing with hidden files cal – show this month's calendar cd dir - change directory to dir uptime – show current uptime cd – change to home w – display who is online pwd – show current directory whoami – who you are logged in as mkdir dir – create a directory dir finger user – display information about user rm file – delete file uname -a – show kernel information rm -r dir – delete directory dir cat /proc/cpuinfo – cpu information rm -f file – force remove file cat /proc/meminfo – memory information rm -rf dir – force remove directory dir * man command – show the manual for command cp file1 file2 – copy file1 to file2 df – show disk usage cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it du – show directory space usage doesn't exist free – show memory and swap usage mv file1 file2 – rename or move file1 to file2 whereis app – show possible locations of app if file2 is an existing directory, moves file1 into which app – show which app will be run by default directory file2 ln -s file link – create symbolic link link to file Compression touch file – create or update file tar cf file.tar files – create a tar named cat > file – places standard input into file file.tar containing files more file – output the contents of file tar xf file.tar – extract the files from file.tar head file – output the first 10 lines of file tar czf file.tar.gz files – create a tar with tail file – output the last 10 lines
    [Show full text]
  • EMERSON CENTER: HARDWARE Comp.Chem.20
    EMERSON CENTER: HARDWARE comp.chem.20 ssh –Y [email protected] euch4e.chem.emory.edu Passwd: HOME=/home/chemistry/ch_res/eclab cd spark cd star cd fire $HOME/spark $HOME/star $HOME/fire mkdir USER mkdir USER mkdir USER cd USER cd USER cd USER # Nodes = 36 # Nodes = 36 # Nodes = 16 + 1 GPU # Cores/node = 24 # Cores/node = 24, 16 # Cores/node = 56 + 5000 # Speed = 2.6 GHz # Speed = 2.5 GHz # Speed = 2.6 GHz # Memory = 96 GB # Memory = 80 GB # Memory = 196 GB # Classes = spark24p # Classes = star24p # Classes = fire28p spark12p star16p fire-gpu star8p stars (1 core) spark (or spark.chem.emory.edu) star (or star.chem.emory.edu) fire (or fire.chem.emory.edu) Login the Emerson Center’s Computers From a Unix/MAC/iPad/iPhone terminal ssh -Y [email protected] From PC 1) Download and run PuTTY (www.putty.org) 2) Enable X-forwarding (Connection -> SSH -> Tunnels) 3) Under Session, choose SSH on port 22 4) Type euch4e.chem.emory.edu as host name 5) Click Open A few UNIX commands and vi Editor UNIX Tree Structure: Files and Directories cd - change directory: cd directory_name rm - remove command: rm file_name: also: rmdir, rm –I mv - move comman: mv file_name mkdir - make directory: mkdir directory_name cp - copy command: cp file_name_1 file_name_2 ls - list command VI (View) Command mode and Insert mode vi file_name Type i for insert command Use backspace in order to correct mistake :w :w! or :wq :wq! Write or write and quit :q :q! quit dd n delete o Insert line EMERSON CENTER: Software (Selected List) Electronic Structure MD Simulation & Modeling Gaussian-16, 09 GROMACS-19.1 Molpro-15.1 NAMD-2.6 MOLCAS Rosetta GAMESS Amber-14 TURBOMOLE ORCA VASP-5.2 DFTB+ Graphics & Programming MATLAB 2019 Mathematica 12.0 Gauss View 6 Command file (for LoadLeveler only): #!/bin/ksh # ### # @ error = errcl.log # # @ initialdir = /star/chemistry/eclab/YOUR # @ requirements = (Arch == "R6000") && (OpSys == "AIX53") # @ notify_user = name@euch4e # @ class = star16p # @ group = ch_res # @ queue # INPF= test_inp OUTF= test_out .
    [Show full text]
  • PWD 3000 Cu / Cu-Al
    PWD 3000 Cu / Cu-Al High Precision Holding Devices Cable holding device featuring water flow system Pneumatic Cable Holding Device This special holding device allows high precision cable resistance for determining the Cable Resistance measurements on stranding machines even all main parts of it (the compactor and the cable take up mechanism ) are grounded! on non isolated No necessity for isolating machine parts! Stranding Machines The precision holding device PWD 3000 is used for the determination of the electric resistance per meter of power and medium voltage cables. The measurement is based on the 4-pole method according to Kelvin in order to eliminate the feed line resistances. The measuring current is supplied via pneumatically operated jaws, the measuring voltage picked-up via spring-supported taps, with a distance between the taps of 1000 mm (+/- 0,2mm). The current jaws and thus the current feeding points are arranged at a sufficient distance to the taps in accordance with DIN / IEC to ensure a constant and uniform distribution of the current across the actual measuring distance. The cable section is placed in two inner troughs which are filled with flowing water when the pump is running and are containing the potential bars for picking up the measuring voltage; it is here where the actual measurement takes place at a constant (water- ) temperature. Features The Microohmmeter which is part of the equipment additionally measures the (water-) temperature via a probe, • Holds diameters from 10 mm² to 1200 mm² and converts the previously measured resistance value to 20°C (or e.g. 23°C if wanted).
    [Show full text]
  • Nsight Compute OLCF Webinar
    Nsight Compute OLCF Webinar Felix Schmitt, Mahen Doshi, Jonathan Vincent Nsight Product Family Workflow Nsight Systems - Analyze application algorithms system-wide https://www.olcf.ornl.gov/calendar/nvidia-profiling-tools-nsight-systems/ Start here Nsight Compute - Analyze CUDA kernels Systems Nsight Graphics - Debug/analyze graphics workloads You are here Compute Graphics 2 Nsight Compute 3 Nsight Compute CUDA Kernel profiler Targeted metric sections for various performance aspects Customizable data collection and presentation (tables, charts, …) UI and Command Line Python-based rules for guided analysis (or post-processing) 4 Nsight Compute Detailed memory workload analysis chart and tables 5 Nsight Compute Comparison of results directly within the tool with “Baselines” Supported across kernels, reports, and GPU architectures 6 Nsight Compute Source/PTX/SASS analysis and correlation Source metrics per instruction and aggregated (e.g. PC sampling data) Metric heatmap 7 Nsight Compute Full command line interface (CLI) for data collection and analysis On your workstation Support for remote profiling across machines, platforms (Linux, Windows, …) in UI and CLI 8 Nsight Compute on Summit 9 Loading Module Use nv-nsight-cu-cli command line interface for data collection in batch environments Available as part of the CUDA toolkit $ module load cuda/10.1.243 $ /sw/summit/cuda/10.1.243/nsight-compute/nv-nsight-cu-cli Or as standalone installation (e.g. newer release than CUDA) $ module load nsight-compute/2019.5.0 $ /sw/summit/nsight-compute/2019.5.0/nv-nsight-cu-cli
    [Show full text]
  • Duane's Incredibly Brief Intro to Unix How to Get Help on Unix: Man
    Duane’s Incredibly Brief Intro to Unix Duane’s Ten Ways To Make Your Unix Life More Reasonable How to get help on unix: 0. Walk away from the machine. Don’t waste your time in front of a man <command-name> Get full description of command machine if you’re not making any progress. Print a listing and walk away. man -k <keyword> List commands mentioning keyword in title Make and take a friend with you. Life will be better if you reconsider the situation without the pressure of a computer. Logging in and out: logout Terminate session 1. Read the man pages. exit Terminate current "shell" Realize, if you haven’t already, that you don’t know everything. Learn. ssh <remote host> Login securely to a remote host The world travels about 66,600 miles an hour about our Sun, and the Sun glides gracefully along its own path dragging us along. File manipulation: Hackers have no impact. None. emacs <file> Edit a text file (see "cheat sheet") mv <old> <new> Rename/move <old> file to a <new> name 2. Learn the emacs keystrokes. It will save you when you have to rm <file(s)> Delete file(s) from system use a system whose mouse is not working. Avoid the "arrow keys". Why?... cp <orig> <duplicate> Copy <orig> to file named <duplicate> sftp <remote host> Secure batch file transfers between mach’ns 3. Use emacs keystrokes in the shell. Many cursor manipulation keystrokes scp host:<orig> host:<dup> Securely transfer files between machines from emacs recall history in the "bash" shell: cat <file> Display/catenate file contents to screen ^P = previous command, ^N = next command, more <file> Display file, page by page (but: use less) ^R = search for command from the past by typing a few letters less <file> Display file, page by page (avoid more) ^A = go to beginning of command line head <file> Display the first few lines of a file ^E = go to end of command line tail <file> Display the last few lines of a file ^B = go back one character grep <pattern> <file(s)> Search for/display pattern within file(s) ^F = go forward one character source <file> Read commands from <file> (also: .
    [Show full text]
  • 6. Environmental Variables Appropriate for Monitoring
    6. Environmental variables appropriate for monitoring 6.1. INTRODUCTION Chapter 5 above outlined the three major problem areas considered to be most relevant for early implementation in any global monitoring programme as follows: 1. Potentially adverseclimatic change resulting from human activities 2. Potentially adverse changes in biota and man from contamination by toxic substances,including radionuclides 3. Potentially adversechangesin biologicalproductivity causedby improper land-use (reduced soil fertility, soil erosion, extension of arid zones etc.) We now have to discuss which environmental parameters describe and quantify these problems in a useful way. These can be broadly classified under the followingheadings: la. Physical and chemical data from the atmosphere pertinent to climatic change potential b. Physical and chemical data from air, water, soils and biota pertinent to human health and welfare 2a. Physical, chemical and biological data reflecting the state of human health b. Biologicaldata reflecting the performance of biological systems 6.2. PHYSICAL AND CHEMICAL DATA FROM THE ATMOSPHERE PERTINENTTO GLOBALCLIMATICCHANGE In the previous chapter the important global environmental problems related to climatic change were discussed: increases of carbon dioxide and particulate matter in the atmosphere, changes in global albedo and the earth's surface, changes in cloudiness, production of waste heat, and contamination of the stratosphere. Since this discussionfocuses on climatic changes of global significancethe measurements and observations must be representative of large portions of the atmosphere (background values) and free of local contamination. The atmosphere has few mixing constraints and, therefore, this can be achievedby measurements in remote areas and in the upper atmosphere. Carbon dioxide. Our knowledge of the historical trend of atmospheric carbon dioxide as well as estimates of future concentrations are based primarily on a sole set of continuous observations, which dates only from 1958.
    [Show full text]
  • Bender Tutorial
    UC Riverside CS/EE 147 Bender Tutorial ♦ Overview In this tutorial, we will learn how to log into the EE server, Bender. Then, we will write and run a basic CUDA application on it. In short, we will do the following: 1. Access a terminal 2. Log into Bender 3. Write a simple CUDA code 4. Compile and run the CUDA code ♦ Access a terminal In order to log into Bender, you will need to access a terminal or SSH client first. You will then use it to connect to Bender via a secure shell protocol (SSH). For Windows, there are several free applications you could use to this end, such as PuTTY, MobaXTerm and Windows Subsystem for Linux (WSL). For Unix-based operating systems, there is already a pre-installed Terminal application. Therefore, you may skip this step if you are using Linux and open the Terminal for the next step. In this tutorial, we will use MobaXTerm due to its ease of use and fast preparation time. 1. Go to this link: https://mobaxterm.mobatek.net/download-home-edition.html 2. You may choose either the portable edition or the installer edition. (The portable edition requires no installation and can be run immediately.) 3. Run MobaXTerm. 4. Click “Start local terminal” in the middle or the “+” on the top (as shown by the red boxes) to open a terminal tab. 1 UC Riverside CS/EE 147 ♦ Login into Bender After opening the terminal, you can now SSH into the Bender machine. 1. Type the following command into the terminal: ssh <ENGR UNAME>@bender.engr.ucr.edu 2.
    [Show full text]
  • Development of a Distributed Design System For
    DEVELOPMENT OF A DISTRIBUTED DESIGN SYSTEM FOR INTEGRATED CIRCUIT DESIGN USING VAX 1117 50 AND SCALDSYSTEM COMPUTERS A Thesf-s Presented to The FacuJ.ty of the Col.1.ege of Engineering and Technology Ohfo University In Partial. Ful.fi.l.lment of the Requttements for the Degree Master of Science Robert Stratton Nobl.es,, TI -4L March, 1986 ACKNOWLEDGEMENTS I wou1.d Iike to thank my advl.sor, Dr. Harold KJ.ock not only for his support of this thesi.~,but for his interest in and support of my graduate work altogether. My thanks to the members of my committee: Dr. Janusz Starzyk and Dr. Robert Curt!.s who helped to form my earliest interest in VLSI deslgn (whj.c.h launched this thesis), and t.o Dr. Israel Uri.el.1, for his interest and val.uab1.e sugges- t l.ons . I wou1.d also I.lke to express my appreci.at!.on here for the help given to me by my mother and father, who have al-ways belleved j.n me. And final.l.y, my deepest gratitude goes to my wife, Kfm, whose support has meant everything to me. TABLE OF CONTENTS Page ACKNOWLEDGEMENTS i LIST OF FIGURES CHAPTER 1 : INTRODUCTION CHAPTER 2: AN INTRODUCTION TO THE UNIX SYSTEM 2.1 A Short View of rhe Hi-story of UNIX 2.2 Conventions Used In Thfs Thesis 2.3 The UNIX File System 9 2.4 UNIX System I/O 2.5 The UNIX Command Intetpreter(SheJ.1.) CHAPTER 3: VAX AND SCALDSYSTEX DESIGN ENVIRONMENTS 17 3.1 SCALDsystem Resources 3.1.1 Hardware Resources 3.1.2 The 0peratJ.ng System and F3.l.e System Layouts 20 3.1.3 SCALDsystem Integrated Cj.rcuf.t Desi.gn Software 26 3.2 VAX System Resources 3.2.1 Hardware Resources 3.2.2 The Operating System and File System Layouts 35 3.2.3 Integrated Circuit Design Software 41 CHAPTER 4: VAX/SCALDSYSTEM COMMUNICATIONS 4 5 4.1 Communi.catj.ons Usi.ng the Tip Program 4 5 4.2 Ini.t.Sal.iz3.ng UNIX Terminal.
    [Show full text]
  • Linux Shell Scripting Cookbook Second Edition
    Linux Shell Scripting Cookbook Second Edition Over 110 practical recipes to solve real-world shell problems, guaranteed to make you wonder how you ever lived without them Shantanu Tushar Sarath Lakshman BIRMINGHAM - MUMBAI Linux Shell Scripting Cookbook Second Edition Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: January 2011 Second edition: May 2013 Production Reference: 1140513 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78216-274-2 www.packtpub.com Cover Image by Parag Kadam ([email protected]) Credits Authors Project Coordinator Shantanu Tushar Shiksha Chaturvedi Sarath Lakshman Proofreader Reviewers Linda Morris Rajeshwari K. John C. Kennedy Indexer Hemangini Bari Anil Kumar Sudhendu Kumar Production Coordinator Aravind SV Shantanu Zagade Acquisition Editor Cover Work Kartikey Pandey Shantanu Zagade Lead Technical Editor Ankita Shashi Technical Editors Jalasha D'costa Amit Ramadas Lubna Shaikh About the Authors Shantanu Tushar is an advanced GNU/Linux user since his college days.
    [Show full text]
  • SAS on Unix/Linux- from the Terminal to GUI
    SAS on Unix/Linux- from the terminal to GUI. L Gakava & S Kannan – October 2015 Agenda All about the terminal o Customising your terminal o Basic Linux terminal commands o Running SAS in non-interactive mode o Available SAS file editors o What to look out for on Unix/Linux platform All about Graphical User Interface (GUI) o Launching SAS GUI. o Changing SAS default behaviour o SAS ToolBox commands o SAS editor commands. Motivation - Why Use SAS On Unix/Linux? Using SAS on UNIX/Linux Platform o Company migrating to UNIX/Linux o Joining a company which is using SAS on the Linux platform Challenge Too many commands to learn! Why Use SAS On Unix/Linux o Customising Linux sessions will ensure you increase work efficiency by taking advantage of the imbedded Linux tools. In general transferring and running large files will be quicker in Linux compared to PC*. Terminal What to expect when you login? % pwd /home/username % ls Customise: Update .bashrc file with this line PS1='$IV $PWD$EE> ' will change your prompt to show the following: /home/username> Terminal Navigation Command Meaning ls list files and directories ls -a list all files and directories mkdir make a directory cd directory change to named directory cd change to home-directory cd ~ change to home-directory cd .. change to parent directory Terminal Navigation Command Meaning cp file1 file2 copy file1 and call it file2 mv file1 file2 move or rename file1 to file2 rm file remove a file rmdir directory remove a directory cat file display a file less file display a file a page at a time head file display the first few lines of a file tail file display the last few lines of a file grep 'keyword' file search a file for keywords count number of lines/words/ wc file characters in file Terminal useful commands How do you find out if a version of a file has changed? /home/username>diff file1.txt file2.txt Command to compare two files.
    [Show full text]
  • Cpsc 101 Lab 1 Fall 2015 Introduction to Unix Systems and C
    CpSc 101 Lab 1 Fall 2015 Introduction to Unix Systems and C How to login On the login screen is a place to enter your user name, and four controls: "Language", "Session", "Restart", and "Shutdown" • These controls are generally not useful, but you might find “session” useful in rare instances of severe “desktop malfunction.” • Type your CU username in the space provided and then press the enter key. • When prompted, enter your password to complete the login procedure. Managing Files and directories Creating directories • Open a terminal window • Enter the pwd command. (It stands for “print working directory”). The working directory should be "/users/your_username". This is also known as your home directory. Terminal windows open to this location by default. All your files and directories will be kept in a directory tree with this directory as root. • Enter mkdir 101 to create a directory for your CPSC 101 files. • Enter ls to list the contents of the current directory. You should see the new 101 directory. • Enter cd 101 to change to the 101 directory. • Enter mkdir lab1 to create a directory for today's lab. • Enter mkdir temp to create a temporary directory. Creating Files • Select the Applications control on the top panel and then left click "Text Editor". This will start the gedit text editor. You may also want to create a gedit launcher on the top panel or on the desktop. • You can use gedit to create and edit any type of text files including C programs. For now, create a file named test.txt and save it in 101/temp/.
    [Show full text]