GithubHelp home page GithubHelp logo

svi's Introduction

#svi.c: stream editor assignment

csc322 final project from spring 2015

##overview svi.c takes, as a command line argument, a file containing a list of edit commands. It modifies the standard input according to these commands. Each line of input, and output after editing, will be no more than 256 characters long.

note: svi has many similarities with the UNIX sed. In fact, sed is much better; the two programs are hardly comparable. This is just an exercise in c programming. (clearly)

##commands Each line of the edit file is a command. A command has several parts.

1. a line range specification
2. an edit type
3. and possibly some data

The line range specification can consist of none, range, or text. Looking at line 10:

typedef enum { none, range, text } LineSpecType;

Here's an easy way to remember how they work:

// none:                applies to every line
// text:    /<text>/    applies to every line with <text>
// range:   a,b/        applies to every line in a,b inclusive

There are several edit types. I have already detailed this in lines 25 to 32 of svi.c:

char edit;
// will be in { A, d, I, O, s };
// edit operations
//      A: append to line
//      d: delete the line specification
//      I: insert at beginning of line
//      O: insert text on the line before
//      s/<old>/<new>/ replaces all occurences of <old> with <new>

The String data is simply the rest of the string.

It is helpful to define a union (15-19):

typedef union {
    bool none;      // applies to every line
    int range[2];   // applies to lines in range[0],range[1] inclusive
    String text;    // applies to lines with this text
} LineSpecRule;

to record the details of the line range specification.

We ultimately end up with a struct:

typedef struct {
    LineSpecType type;		// what type of line range spec
    LineSpecRule rule;		// the details of how the line range spec should be applied
    char edit;				// the type of edit being performed
    String data;
} Edit;

Here's what an edit file might look like:

/Never done/I---------------------------------------
1,3/IPrepended to 1,2 and 3 :
1,1/OThis must appear as the first line
A : Appended to all
/line for substitution/s/This is one/This has been substituted on a/
9,10/d
/deleted/IThis should not appear
/Never done/I---------------------------------------

##running

gcc svi.c -o svi
./svi commandFile < inputFile

svi's People

Contributors

royhowie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.