Git Product home page Git Product logo

expect's Introduction

"expect / send" in C

Copyright © 2012 Bart Massey

This work is licensed under the "MIT License". Please see the file COPYING in the source distribution of this work for license terms.

This is an implementation of "expect / send" in C. There are many such implementations; this one is neither particularly nice nor particularly well-debugged nor particularly well-supported. On the other hand, it is small and simple, and has a liberal license.

The interface is as follows:

    extern void csend(FILE *fp, char *cmd, ...);

The csend() function is essentially a fancy fprintf(). It adds a newline to its output and flushes it automatically.

The csend() function will echo its output to stderr if the cexpect_verbose variable described below is set to true.

    extern int cexpects(FILE *fp, int codes[], int ncodes, char *msg);

The cexpects() function reads a line from fp. It expects the line to start with a 3-digit ASCII response code followed by a space character. It parses that response code and compares it with each code in the codes array. If any code matches, cexpects() returns the code. Otherwise, it prints an error message containing msg and exits the program with status 1. (Yes, this is obnoxious behavior and should probably be changed. Caveat emptor.)

The cexpects() function will echo its input to stderr if the cexpect_verbose variable described below is set to true.

    extern void cexpect(FILE *fp, int code, char *msg);

The cexpect() function is just a simplified interface to cexpects() in the case that only one code is expected.

The cexpect() function will echo its input to stderr if the cexpect_verbose variable described below is set to true.

    extern char cexpect_response[];

This largeish static buffer (currently 2048 bytes, but check its size with sizeof(cexpect_response)) will contain the remainder of the last response processed by cexpect() or csend() after the response code has been parsed and thrown away. If the response contains information beyond the code, this is where to find it.

    extern int cexpect_verbose;

The cexpect_verbose variable defaults to false (zero). When set to true (non-zero) it causes cexpects(), cexpect() and csend() to echo their work to stderr.

expect's People

Contributors

bartmassey avatar

Stargazers

Alan Grosskurth avatar

Watchers

 avatar James Cloos avatar  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.