Browse Source

indent -linux on tinyrl library

git-svn-id: https://klish.googlecode.com/svn/trunk@339 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
7944a585dd
10 changed files with 1384 additions and 1711 deletions
  1. 42 60
      tinyrl/history.h
  2. 285 334
      tinyrl/history/history.c
  3. 29 32
      tinyrl/history/history_entry.c
  4. 3 5
      tinyrl/history/private.h
  5. 31 32
      tinyrl/private.h
  6. 669 739
      tinyrl/tinyrl.c
  7. 80 140
      tinyrl/tinyrl.h
  8. 49 149
      tinyrl/vt100.h
  9. 3 5
      tinyrl/vt100/private.h
  10. 193 215
      tinyrl/vt100/vt100.c

+ 42 - 60
tinyrl/history.h

@@ -13,16 +13,15 @@
 #include "lub/types.h"
 
 _BEGIN_C_DECL
-
 /**************************************
  * tinyrl_history_entry class interface
  ************************************** */
 typedef struct _tinyrl_history_entry tinyrl_history_entry_t;
 
-extern const char *
-    tinyrl_history_entry__get_line(const tinyrl_history_entry_t *instance);
-extern unsigned
-    tinyrl_history_entry__get_index(const tinyrl_history_entry_t *instance);
+extern const char *tinyrl_history_entry__get_line(const tinyrl_history_entry_t *
+						  instance);
+extern unsigned tinyrl_history_entry__get_index(const tinyrl_history_entry_t *
+						instance);
 
 /**************************************
  * tinyrl_history class interface
@@ -36,79 +35,62 @@ typedef struct _tinyrl_history_iterator tinyrl_history_iterator_t;
 /**
  * CLIENTS MUST NOT USE THESE FIELDS DIRECTLY
  */
-struct _tinyrl_history_iterator
-{
-    const tinyrl_history_t *history;
-    unsigned                offset;
+struct _tinyrl_history_iterator {
+	const tinyrl_history_t *history;
+	unsigned offset;
 };
 
+extern tinyrl_history_t *tinyrl_history_new(unsigned stifle);
 
-extern tinyrl_history_t *
-    tinyrl_history_new(unsigned stifle);
-
-extern void
-    tinyrl_history_delete(tinyrl_history_t *instance);
-
-extern void
-    tinyrl_history_add      (tinyrl_history_t *instance, 
-                             const char       *line);
+extern void tinyrl_history_delete(tinyrl_history_t * instance);
 
-extern tinyrl_history_entry_t *
-    tinyrl_history_getfirst (const tinyrl_history_t    *instance,
-                             tinyrl_history_iterator_t *iter);
-extern tinyrl_history_entry_t *
-    tinyrl_history_getlast (const tinyrl_history_t    *instance,
-                             tinyrl_history_iterator_t *iter);
+extern void tinyrl_history_add(tinyrl_history_t * instance, const char *line);
 
-extern tinyrl_history_entry_t *
-    tinyrl_history_getnext(tinyrl_history_iterator_t *iter);
+extern tinyrl_history_entry_t *tinyrl_history_getfirst(const tinyrl_history_t *
+						       instance,
+						       tinyrl_history_iterator_t
+						       * iter);
+extern tinyrl_history_entry_t *tinyrl_history_getlast(const tinyrl_history_t *
+						      instance,
+						      tinyrl_history_iterator_t
+						      * iter);
 
-extern tinyrl_history_entry_t *
-    tinyrl_history_getprevious(tinyrl_history_iterator_t *iter);
- 
+extern tinyrl_history_entry_t *tinyrl_history_getnext(tinyrl_history_iterator_t
+						      * iter);
 
- 
+extern tinyrl_history_entry_t
+    *tinyrl_history_getprevious(tinyrl_history_iterator_t * iter);
 
 /*
 HISTORY LIST MANAGEMENT 
 */
-extern tinyrl_history_entry_t *
-    tinyrl_history_remove(tinyrl_history_t *instance,
-                          unsigned          offset);
-extern void
-    tinyrl_history_clear(tinyrl_history_t *instance);
-extern void
-    tinyrl_history_stifle(tinyrl_history_t *instance,
-                          unsigned          stifle);
-extern unsigned
-    tinyrl_history_unstifle(tinyrl_history_t *instance);
-extern bool_t
-    tinyrl_history_is_stifled(const tinyrl_history_t *instance);
+extern tinyrl_history_entry_t *tinyrl_history_remove(tinyrl_history_t *
+						     instance, unsigned offset);
+extern void tinyrl_history_clear(tinyrl_history_t * instance);
+extern void tinyrl_history_stifle(tinyrl_history_t * instance, unsigned stifle);
+extern unsigned tinyrl_history_unstifle(tinyrl_history_t * instance);
+extern bool_t tinyrl_history_is_stifled(const tinyrl_history_t * instance);
 
     /*
-INFORMATION ABOUT THE HISTORY LIST 
-*/    
-extern tinyrl_history_entry_t **
-    tinyrl_history_list(const tinyrl_history_t *instance);
-extern tinyrl_history_entry_t *
-    tinyrl_history_get(const tinyrl_history_t *instance,
-                       unsigned                offset);
+       INFORMATION ABOUT THE HISTORY LIST 
+     */
+extern tinyrl_history_entry_t **tinyrl_history_list(const tinyrl_history_t *
+						    instance);
+extern tinyrl_history_entry_t *tinyrl_history_get(const tinyrl_history_t *
+						  instance, unsigned offset);
 
 /*
  * HISTORY EXPANSION 
- */  
-typedef enum
-{
-    tinyrl_history_NO_EXPANSION,
-    tinyrl_history_EXPANDED
-} tinyrl_history_expand_t;  
+ */
+typedef enum {
+	tinyrl_history_NO_EXPANSION,
+	tinyrl_history_EXPANDED
+} tinyrl_history_expand_t;
 
 extern tinyrl_history_expand_t
-    tinyrl_history_expand(const tinyrl_history_t *instance,
-                          const char             *string, 
-                          char                  **output);
+tinyrl_history_expand(const tinyrl_history_t * instance,
+		      const char *string, char **output);
 
 _END_C_DECL
-
-#endif /* _tinyrl_history_h */
+#endif				/* _tinyrl_history_h */
 /** @} tinyrl_history */

+ 285 - 334
tinyrl/history/history.c

@@ -13,61 +13,55 @@
 
 #include "tinyrl/history.h"
 
-struct _tinyrl_history
-{
-    tinyrl_history_entry_t **entries;   /* pointer entries */
-    unsigned     length;    /* Number of elements within this array */
-    unsigned     size;      /* Number of slots allocated in this array */
-    unsigned     current_index;
-    unsigned     stifle;
+struct _tinyrl_history {
+	tinyrl_history_entry_t **entries;	/* pointer entries */
+	unsigned length;	/* Number of elements within this array */
+	unsigned size;		/* Number of slots allocated in this array */
+	unsigned current_index;
+	unsigned stifle;
 };
 
 /*------------------------------------- */
-void
-tinyrl_history_init(tinyrl_history_t *this,
-                    unsigned          stifle)
+void tinyrl_history_init(tinyrl_history_t * this, unsigned stifle)
 {
-    this->entries       = NULL;
-    this->stifle        = stifle;
-    this->current_index = 1;
-    this->length        = 0;
-    this->size          = 0;
+	this->entries = NULL;
+	this->stifle = stifle;
+	this->current_index = 1;
+	this->length = 0;
+	this->size = 0;
 }
+
 /*------------------------------------- */
-void
-tinyrl_history_fini(tinyrl_history_t *this)
+void tinyrl_history_fini(tinyrl_history_t * this)
 {
-    tinyrl_history_entry_t *entry;
-    tinyrl_history_iterator_t iter;
-    
-    /* release the resource associated with each entry */
-    for(entry = tinyrl_history_getfirst(this,&iter);
-        entry;
-        entry = tinyrl_history_getnext(&iter))
-    {
-        tinyrl_history_entry_delete(entry);
-    }
-    /* release the list */
-    free(this->entries);
-    this->entries = NULL;
+	tinyrl_history_entry_t *entry;
+	tinyrl_history_iterator_t iter;
+
+	/* release the resource associated with each entry */
+	for (entry = tinyrl_history_getfirst(this, &iter);
+	     entry; entry = tinyrl_history_getnext(&iter)) {
+		tinyrl_history_entry_delete(entry);
+	}
+	/* release the list */
+	free(this->entries);
+	this->entries = NULL;
 }
+
 /*------------------------------------- */
-tinyrl_history_t *
-tinyrl_history_new(unsigned stifle)
+tinyrl_history_t *tinyrl_history_new(unsigned stifle)
 {
-    tinyrl_history_t *this = malloc(sizeof(tinyrl_history_t));
-    if(NULL != this)
-    {
-        tinyrl_history_init(this,stifle);
-    }
-    return this;
+	tinyrl_history_t *this = malloc(sizeof(tinyrl_history_t));
+	if (NULL != this) {
+		tinyrl_history_init(this, stifle);
+	}
+	return this;
 }
+
 /*------------------------------------- */
-void
-tinyrl_history_delete(tinyrl_history_t *this)
+void tinyrl_history_delete(tinyrl_history_t * this)
 {
-    tinyrl_history_fini(this);
-    free(this);
+	tinyrl_history_fini(this);
+	free(this);
 }
 
 /*
@@ -75,18 +69,17 @@ HISTORY LIST MANAGEMENT
 */
 /*------------------------------------- */
 /* insert a new entry at the current offset */
-static void
-insert_entry(tinyrl_history_t *this,
-             const char       *line)
+static void insert_entry(tinyrl_history_t * this, const char *line)
 {
-    tinyrl_history_entry_t *new_entry = tinyrl_history_entry_new(line,this->current_index++);
-    assert(this->length);
-    assert(this->entries);
-    if(new_entry)
-    {
-        this->entries[this->length-1] = new_entry;
-    }
+	tinyrl_history_entry_t *new_entry =
+	    tinyrl_history_entry_new(line, this->current_index++);
+	assert(this->length);
+	assert(this->entries);
+	if (new_entry) {
+		this->entries[this->length - 1] = new_entry;
+	}
 }
+
 /*------------------------------------- */
 /*
  * This frees the specified entries from the 
@@ -94,23 +87,19 @@ insert_entry(tinyrl_history_t *this,
  * This function is inclusive of start and end
  */
 static void
-free_entries(const tinyrl_history_t *this,
-             unsigned                start,
-             unsigned                end)
+free_entries(const tinyrl_history_t * this, unsigned start, unsigned end)
 {
-    unsigned i;
-    assert(start <= end);
-    assert(end < this->length);
-        
-    for(i  = start;
-        i <= end;
-        i++)
-    {
-        tinyrl_history_entry_t *entry = this->entries[i];
-        tinyrl_history_entry_delete(entry);
-        entry = NULL;
-    }
+	unsigned i;
+	assert(start <= end);
+	assert(end < this->length);
+
+	for (i = start; i <= end; i++) {
+		tinyrl_history_entry_t *entry = this->entries[i];
+		tinyrl_history_entry_delete(entry);
+		entry = NULL;
+	}
 }
+
 /*------------------------------------- */
 /*
  * This removes the specified entries from the 
@@ -118,344 +107,306 @@ free_entries(const tinyrl_history_t *this,
  * This function is inclusive of start and end
  */
 static void
-remove_entries(tinyrl_history_t *this,
-               unsigned          start,
-               unsigned          end)
+remove_entries(tinyrl_history_t * this, unsigned start, unsigned end)
 {
-    unsigned delta = (end - start) + 1; /* number of entries being deleted */
-    /* number of entries to shuffle */
-    unsigned num_entries = (this->length - end) - 1; 
-    assert(start <= end);
-    assert(end < this->length);
-
-    if(num_entries)
-    {
-        /* move the remaining entries down to close the array */
-        memmove(&this->entries[start],
-                &this->entries[end+1],
-                sizeof(tinyrl_history_entry_t *) * num_entries);
-    }
-    /* now fix up the length variables */
-    this->length -= delta;
+	unsigned delta = (end - start) + 1;	/* number of entries being deleted */
+	/* number of entries to shuffle */
+	unsigned num_entries = (this->length - end) - 1;
+	assert(start <= end);
+	assert(end < this->length);
+
+	if (num_entries) {
+		/* move the remaining entries down to close the array */
+		memmove(&this->entries[start],
+			&this->entries[end + 1],
+			sizeof(tinyrl_history_entry_t *) * num_entries);
+	}
+	/* now fix up the length variables */
+	this->length -= delta;
 }
+
 /*------------------------------------- */
 /* 
 Search the current history buffer for the specified 
 line and if found remove it.
 */
-static bool_t
-remove_duplicate(tinyrl_history_t *this,
-                 const char       *line)
+static bool_t remove_duplicate(tinyrl_history_t * this, const char *line)
 {
-    bool_t result = BOOL_FALSE;
-    unsigned i;
-        
-    for(i  = 0;
-        i < this->length;
-        i++)
-    {
-        tinyrl_history_entry_t *entry = this->entries[i];
-        if(0 == strcmp(line,tinyrl_history_entry__get_line(entry)))
-        {
-            free_entries(this,i,i);
-            remove_entries(this,i,i);
-            result = BOOL_TRUE;
-            break;
-        }
-    }
-    return result;
+	bool_t result = BOOL_FALSE;
+	unsigned i;
+
+	for (i = 0; i < this->length; i++) {
+		tinyrl_history_entry_t *entry = this->entries[i];
+		if (0 == strcmp(line, tinyrl_history_entry__get_line(entry))) {
+			free_entries(this, i, i);
+			remove_entries(this, i, i);
+			result = BOOL_TRUE;
+			break;
+		}
+	}
+	return result;
 }
+
 /*------------------------------------- */
 /* 
 add an entry to the end of the current array 
 if there is no space returns -1 else 0
 */
-static void
-append_entry(tinyrl_history_t *this,
-             const char       *line)
+static void append_entry(tinyrl_history_t * this, const char *line)
 {
-    if(this->length < this->size)
-    {
-        this->length++;
+	if (this->length < this->size) {
+		this->length++;
 
-        insert_entry(this,line);
-    }
+		insert_entry(this, line);
+	}
 }
+
 /*------------------------------------- */
 /*
  add a new history entry replacing the oldest one 
  */
-static void
-add_n_replace(tinyrl_history_t *this,
-              const char       *line)
+static void add_n_replace(tinyrl_history_t * this, const char *line)
 {
-    if(BOOL_FALSE == remove_duplicate(this,line))
-    {
-        /* free the oldest entry */
-        free_entries(this,0,0);
-        /* shuffle the array */
-        remove_entries(this,0,0);
-    }
-    /* add the new entry */
-    append_entry(this,line);
+	if (BOOL_FALSE == remove_duplicate(this, line)) {
+		/* free the oldest entry */
+		free_entries(this, 0, 0);
+		/* shuffle the array */
+		remove_entries(this, 0, 0);
+	}
+	/* add the new entry */
+	append_entry(this, line);
 }
+
 /*------------------------------------- */
 /* add a new history entry growing the array if necessary */
-static void
-add_n_grow(tinyrl_history_t *this,
-           const char       *line)
+static void add_n_grow(tinyrl_history_t * this, const char *line)
 {
-    if(this->size == this->length)
-    {
-        /* increment the history memory by 10 entries each time we grow */
-        unsigned                 new_size = this->size + 10;
-        size_t                   nbytes;
-        tinyrl_history_entry_t **new_entries;
-        
-        nbytes      = sizeof(tinyrl_history_entry_t *)*new_size;
-        new_entries = realloc(this->entries,nbytes);
-        if(NULL != new_entries)
-        {
-            this->size    = new_size;
-            this->entries = new_entries;
-        }
-    }
-    (void)remove_duplicate(this,line);
-    append_entry(this,line);
+	if (this->size == this->length) {
+		/* increment the history memory by 10 entries each time we grow */
+		unsigned new_size = this->size + 10;
+		size_t nbytes;
+		tinyrl_history_entry_t **new_entries;
+
+		nbytes = sizeof(tinyrl_history_entry_t *) * new_size;
+		new_entries = realloc(this->entries, nbytes);
+		if (NULL != new_entries) {
+			this->size = new_size;
+			this->entries = new_entries;
+		}
+	}
+	(void)remove_duplicate(this, line);
+	append_entry(this, line);
 }
+
 /*------------------------------------- */
-void
-tinyrl_history_add(tinyrl_history_t *this,
-                   const char       *line)
+void tinyrl_history_add(tinyrl_history_t * this, const char *line)
 {
-    if(this->length && (this->length == this->stifle))
-    {
-        add_n_replace(this,line);
-    }
-    else
-    {
-        add_n_grow(this,line);
-    }
+	if (this->length && (this->length == this->stifle)) {
+		add_n_replace(this, line);
+	} else {
+		add_n_grow(this, line);
+	}
 }
+
 /*------------------------------------- */
-tinyrl_history_entry_t *
-tinyrl_history_remove(tinyrl_history_t *this,
-                      unsigned          offset)
+tinyrl_history_entry_t *tinyrl_history_remove(tinyrl_history_t * this,
+					      unsigned offset)
 {
-    tinyrl_history_entry_t *result = NULL;
-    
-    if(offset < this->length)
-    {
-        result = this->entries[offset];
-        /* do the biz */
-        remove_entries(this,offset,offset);
-    }
-    return result;
+	tinyrl_history_entry_t *result = NULL;
+
+	if (offset < this->length) {
+		result = this->entries[offset];
+		/* do the biz */
+		remove_entries(this, offset, offset);
+	}
+	return result;
 }
+
 /*------------------------------------- */
-void
-tinyrl_history_clear(tinyrl_history_t *this)
+void tinyrl_history_clear(tinyrl_history_t * this)
 {
-    /* free all the entries */
-    free_entries(this,0,this->length-1);
-    /* and shuffle the array */
-    remove_entries(this,0,this->length-1);
+	/* free all the entries */
+	free_entries(this, 0, this->length - 1);
+	/* and shuffle the array */
+	remove_entries(this, 0, this->length - 1);
 }
+
 /*------------------------------------- */
-void
-tinyrl_history_stifle(tinyrl_history_t *this,
-                      unsigned          stifle)
+void tinyrl_history_stifle(tinyrl_history_t * this, unsigned stifle)
 {
-    /* 
-     * if we are stifling (i.e. non zero value) then 
-     * delete the obsolete entries
-     */
-    if(stifle)
-    {
-        if(stifle < this->length)
-        {
-            unsigned num_deletes = this->length - stifle;
-            /* free the entries */
-            free_entries(this,0,num_deletes-1);
-            /* shuffle the array shut */
-            remove_entries(this,0,num_deletes-1);
-        }
-        this->stifle = stifle;
-    }
+	/* 
+	 * if we are stifling (i.e. non zero value) then 
+	 * delete the obsolete entries
+	 */
+	if (stifle) {
+		if (stifle < this->length) {
+			unsigned num_deletes = this->length - stifle;
+			/* free the entries */
+			free_entries(this, 0, num_deletes - 1);
+			/* shuffle the array shut */
+			remove_entries(this, 0, num_deletes - 1);
+		}
+		this->stifle = stifle;
+	}
 }
+
 /*------------------------------------- */
-unsigned
-tinyrl_history_unstifle(tinyrl_history_t *this)
+unsigned tinyrl_history_unstifle(tinyrl_history_t * this)
 {
-    unsigned result = this->stifle;
+	unsigned result = this->stifle;
 
-    this->stifle = 0;
+	this->stifle = 0;
 
-    return result;
+	return result;
 }
+
 /*------------------------------------- */
-bool_t
-tinyrl_history_is_stifled(const tinyrl_history_t *this)
+bool_t tinyrl_history_is_stifled(const tinyrl_history_t * this)
 {
-    return this->stifle ? BOOL_TRUE : BOOL_FALSE;
+	return this->stifle ? BOOL_TRUE : BOOL_FALSE;
 }
+
 /*
 INFORMATION ABOUT THE HISTORY LIST 
-*/    
-tinyrl_history_entry_t *
-tinyrl_history_get(const tinyrl_history_t *this,
-                   unsigned                position)
+*/
+tinyrl_history_entry_t *tinyrl_history_get(const tinyrl_history_t * this,
+					   unsigned position)
 {
-    unsigned i;
-    tinyrl_history_entry_t *entry = NULL;
-    for(i = 0;
-        i < this->length;
-        i++)
-    {
-        entry = this->entries[i];
-        if(position == tinyrl_history_entry__get_index(entry))
-        {
-            /* found it */
-            break;
-        }
-        entry = NULL;
-    }
-    return entry;
+	unsigned i;
+	tinyrl_history_entry_t *entry = NULL;
+	for (i = 0; i < this->length; i++) {
+		entry = this->entries[i];
+		if (position == tinyrl_history_entry__get_index(entry)) {
+			/* found it */
+			break;
+		}
+		entry = NULL;
+	}
+	return entry;
 }
+
 /*------------------------------------- */
 tinyrl_history_expand_t
-tinyrl_history_expand(const tinyrl_history_t *this,
-                      const char             *string, 
-                      char                  **output)
+tinyrl_history_expand(const tinyrl_history_t * this,
+		      const char *string, char **output)
 {
-    tinyrl_history_expand_t result = tinyrl_history_NO_EXPANSION; /* no expansion */
-    const char             *p,*start;
-    char                   *buffer = NULL;
-    unsigned                len;
-    
-    for(p = string,start=string,len=0;
-        *p;
-        p++,len++)
-    {
-        /* perform pling substitution */
-        if(*p == '!')
-        {
-            /* assume the last command to start with... */
-            unsigned                offset = this->current_index - 1;
-            unsigned                skip;
-            tinyrl_history_entry_t *entry;
-         
-            /* this could be an escape sequence */
-            if(p[1] != '!')
-            {
-                int tmp;
-                int res;
-                /* read the numeric identifier */
-                res = sscanf(p,"!%d",&tmp);
-                if((0 == res) || (EOF == res))
-                {
-                    /* error so ignore it */
-                    break;
-                }
-                
-                if(tmp < 0)
-                {
-                    /* this is a relative reference */
-                    /*lint -e737 Loss of sign in promotion from int to unsigend int */
-                    offset += tmp; /* adding a negative substracts... */
-                    /*lint +e737 */
-                }
-                else
-                {
-                    /* this is an absolute reference */
-                    offset = (unsigned)tmp;
-                }
-            }
-            if(len > 0)
-            {
-                /* we need to add in some previous plain text */
-                lub_string_catn(&buffer,start,len);
-            }
-            
-            /* skip the escaped chars */
-            p += skip = strspn(p,"!-0123456789");
-
-            /* try and find the history entry */
-            entry = tinyrl_history_get(this,offset);
-            if(NULL != entry)
-            {
-                /* reset the non-escaped references */
-                start = p;
-                len   = 0;
-                /* add the expanded text to the buffer */
-                result = tinyrl_history_EXPANDED;
-                lub_string_cat(&buffer,tinyrl_history_entry__get_line(entry));
-            }
-            else
-            {
-                /* we simply leave the unexpanded sequence */
-                len += skip;
-            }
-        }
-    }
-    /* add any left over plain text */
-    lub_string_catn(&buffer,start,len);
-    *output = buffer;
-    
-    return result;
+	tinyrl_history_expand_t result = tinyrl_history_NO_EXPANSION;	/* no expansion */
+	const char *p, *start;
+	char *buffer = NULL;
+	unsigned len;
+
+	for (p = string, start = string, len = 0; *p; p++, len++) {
+		/* perform pling substitution */
+		if (*p == '!') {
+			/* assume the last command to start with... */
+			unsigned offset = this->current_index - 1;
+			unsigned skip;
+			tinyrl_history_entry_t *entry;
+
+			/* this could be an escape sequence */
+			if (p[1] != '!') {
+				int tmp;
+				int res;
+				/* read the numeric identifier */
+				res = sscanf(p, "!%d", &tmp);
+				if ((0 == res) || (EOF == res)) {
+					/* error so ignore it */
+					break;
+				}
+
+				if (tmp < 0) {
+					/* this is a relative reference */
+					/*lint -e737 Loss of sign in promotion from int to unsigend int */
+					offset += tmp;	/* adding a negative substracts... */
+					/*lint +e737 */
+				} else {
+					/* this is an absolute reference */
+					offset = (unsigned)tmp;
+				}
+			}
+			if (len > 0) {
+				/* we need to add in some previous plain text */
+				lub_string_catn(&buffer, start, len);
+			}
+
+			/* skip the escaped chars */
+			p += skip = strspn(p, "!-0123456789");
+
+			/* try and find the history entry */
+			entry = tinyrl_history_get(this, offset);
+			if (NULL != entry) {
+				/* reset the non-escaped references */
+				start = p;
+				len = 0;
+				/* add the expanded text to the buffer */
+				result = tinyrl_history_EXPANDED;
+				lub_string_cat(&buffer,
+					       tinyrl_history_entry__get_line
+					       (entry));
+			} else {
+				/* we simply leave the unexpanded sequence */
+				len += skip;
+			}
+		}
+	}
+	/* add any left over plain text */
+	lub_string_catn(&buffer, start, len);
+	*output = buffer;
+
+	return result;
 }
+
 /*-------------------------------------*/
-tinyrl_history_entry_t *
-tinyrl_history_getfirst(const tinyrl_history_t    *this,
-                        tinyrl_history_iterator_t *iter)
+tinyrl_history_entry_t *tinyrl_history_getfirst(const tinyrl_history_t * this,
+						tinyrl_history_iterator_t *
+						iter)
 {
-    tinyrl_history_entry_t *result = NULL;
+	tinyrl_history_entry_t *result = NULL;
 
-    iter->history = this;
-    iter->offset  = 0;
+	iter->history = this;
+	iter->offset = 0;
 
-    if(this->length)
-    {
-        result = this->entries[iter->offset];
-    }    
-    return result;
+	if (this->length) {
+		result = this->entries[iter->offset];
+	}
+	return result;
 }
+
 /*-------------------------------------*/
-tinyrl_history_entry_t *
-tinyrl_history_getnext(tinyrl_history_iterator_t *iter)
+tinyrl_history_entry_t *tinyrl_history_getnext(tinyrl_history_iterator_t * iter)
 {
-    tinyrl_history_entry_t *result = NULL;
+	tinyrl_history_entry_t *result = NULL;
 
-    if(iter->offset < iter->history->length - 1)
-    {
-        iter->offset++;
-        result = iter->history->entries[iter->offset];
-    }
+	if (iter->offset < iter->history->length - 1) {
+		iter->offset++;
+		result = iter->history->entries[iter->offset];
+	}
 
-    return result;
+	return result;
 }
+
 /*-------------------------------------*/
-tinyrl_history_entry_t *
-tinyrl_history_getlast (const tinyrl_history_t    *this,
-                        tinyrl_history_iterator_t *iter)
+tinyrl_history_entry_t *tinyrl_history_getlast(const tinyrl_history_t * this,
+					       tinyrl_history_iterator_t * iter)
 {
-    iter->history = this;
-    iter->offset  = this->length;
-    
-    return tinyrl_history_getprevious(iter);
+	iter->history = this;
+	iter->offset = this->length;
+
+	return tinyrl_history_getprevious(iter);
 }
+
 /*-------------------------------------*/
-tinyrl_history_entry_t *
-tinyrl_history_getprevious(tinyrl_history_iterator_t *iter)
+tinyrl_history_entry_t *tinyrl_history_getprevious(tinyrl_history_iterator_t *
+						   iter)
 {
-    tinyrl_history_entry_t *result = NULL;
+	tinyrl_history_entry_t *result = NULL;
 
-    if(iter->offset)
-    {
-        iter->offset--;
-        result = iter->history->entries[iter->offset];
-    }
+	if (iter->offset) {
+		iter->offset--;
+		result = iter->history->entries[iter->offset];
+	}
 
-    return result;    
+	return result;
 }
+
 /*-------------------------------------*/

+ 29 - 32
tinyrl/history/history_entry.c

@@ -3,56 +3,53 @@
 #include "lub/string.h"
 #include <stdlib.h>
 
-struct _tinyrl_history_entry
-{
-    char       *line;
-    unsigned    index;
+struct _tinyrl_history_entry {
+	char *line;
+	unsigned index;
 };
 /*------------------------------------- */
 static void
-entry_init(tinyrl_history_entry_t *this,
-           const char             *line,
-           unsigned                index)
+entry_init(tinyrl_history_entry_t * this, const char *line, unsigned index)
 {
-    this->line = lub_string_dup(line);
-    this->index = index;
+	this->line = lub_string_dup(line);
+	this->index = index;
 }
+
 /*------------------------------------- */
-static void
-entry_fini(tinyrl_history_entry_t *this)
+static void entry_fini(tinyrl_history_entry_t * this)
 {
-    lub_string_free(this->line);
-    this->line = NULL;
+	lub_string_free(this->line);
+	this->line = NULL;
 }
+
 /*------------------------------------- */
-tinyrl_history_entry_t *
-tinyrl_history_entry_new(const char *line,
-                         unsigned    index)
+tinyrl_history_entry_t *tinyrl_history_entry_new(const char *line,
+						 unsigned index)
 {
-    tinyrl_history_entry_t *this = malloc(sizeof(tinyrl_history_entry_t));
-    if(NULL != this)
-    {
-        entry_init(this,line,index);
-    }
-    return this;
+	tinyrl_history_entry_t *this = malloc(sizeof(tinyrl_history_entry_t));
+	if (NULL != this) {
+		entry_init(this, line, index);
+	}
+	return this;
 }
+
 /*------------------------------------- */
-void
-tinyrl_history_entry_delete(tinyrl_history_entry_t *this)
+void tinyrl_history_entry_delete(tinyrl_history_entry_t * this)
 {
-    entry_fini(this);
-    free(this);
+	entry_fini(this);
+	free(this);
 }
+
 /*------------------------------------- */
-const char *
-tinyrl_history_entry__get_line(const tinyrl_history_entry_t *this)
+const char *tinyrl_history_entry__get_line(const tinyrl_history_entry_t * this)
 {
-    return this->line;
+	return this->line;
 }
+
 /*------------------------------------- */
-unsigned
-tinyrl_history_entry__get_index(const tinyrl_history_entry_t *this)
+unsigned tinyrl_history_entry__get_index(const tinyrl_history_entry_t * this)
 {
-    return this->index;
+	return this->index;
 }
+
 /*------------------------------------- */

+ 3 - 5
tinyrl/history/private.h

@@ -3,9 +3,7 @@
 /**************************************
  * protected interface to tinyrl_history_entry class
  ************************************** */
-extern tinyrl_history_entry_t *
-    tinyrl_history_entry_new(const char *line,
-                             unsigned    index);
+extern tinyrl_history_entry_t *tinyrl_history_entry_new(const char *line,
+							unsigned index);
 
-extern void
-    tinyrl_history_entry_delete(tinyrl_history_entry_t *instance);
+extern void tinyrl_history_entry_delete(tinyrl_history_entry_t * instance);

+ 31 - 32
tinyrl/private.h

@@ -4,39 +4,38 @@
 #include "tinyrl/vt100.h"
 
 /* define the class member data and virtual methods */
-struct _tinyrl
-{
-    const char               *line;
-    unsigned                  max_line_length;
-    const char               *prompt;
-    size_t                    prompt_size;
-    char                     *buffer;
-    size_t                    buffer_size;
-    bool_t                    done;
-    bool_t                    completion_over;
-    bool_t                    completion_error_over;
-    unsigned                  point;
-    unsigned                  end;
-    tinyrl_completion_func_t *attempted_completion_function;
-    int                       state;
+struct _tinyrl {
+	const char *line;
+	unsigned max_line_length;
+	const char *prompt;
+	size_t prompt_size;
+	char *buffer;
+	size_t buffer_size;
+	bool_t done;
+	bool_t completion_over;
+	bool_t completion_error_over;
+	unsigned point;
+	unsigned end;
+	tinyrl_completion_func_t *attempted_completion_function;
+	int state;
 #define RL_STATE_COMPLETING (0x00000001)
-    char                     *kill_string;
+	char *kill_string;
 #define NUM_HANDLERS 256
-    tinyrl_key_func_t        *handlers[NUM_HANDLERS];
+	tinyrl_key_func_t *handlers[NUM_HANDLERS];
 
-    tinyrl_history_t         *history;
-    tinyrl_history_iterator_t hist_iter;
-    tinyrl_vt100_t           *term;
-    void                     *context; /* context supplied by caller
-                                        * to tinyrl_readline()
-                                        */
-    char                      echo_char;
-    bool_t                    echo_enabled;
-    struct termios            default_termios;
-    bool_t                    isatty;
-    char                     *last_buffer; /* hold record of the previous 
-                                              buffer for redisplay purposes */
-    unsigned                  last_point; /* hold record of the previous 
-                                              cursor position for redisplay purposes */
-    bool_t                    utf8; /* Is the encoding UTF-8 */
+	tinyrl_history_t *history;
+	tinyrl_history_iterator_t hist_iter;
+	tinyrl_vt100_t *term;
+	void *context;		/* context supplied by caller
+				 * to tinyrl_readline()
+				 */
+	char echo_char;
+	bool_t echo_enabled;
+	struct termios default_termios;
+	bool_t isatty;
+	char *last_buffer;	/* hold record of the previous 
+				   buffer for redisplay purposes */
+	unsigned last_point;	/* hold record of the previous 
+				   cursor position for redisplay purposes */
+	bool_t utf8;		/* Is the encoding UTF-8 */
 };

File diff suppressed because it is too large
+ 669 - 739
tinyrl/tinyrl.c


+ 80 - 140
tinyrl/tinyrl.h

@@ -15,176 +15,127 @@ from a CLI in a "readline" like fashion.
 #include "lub/c_decl.h"
 #include "tinyrl/history.h"
 
-_BEGIN_C_DECL
-
-typedef struct _tinyrl tinyrl_t;
-typedef enum
-{
+_BEGIN_C_DECL typedef struct _tinyrl tinyrl_t;
+typedef enum {
     /**
      * no possible completions were found
      */
-    TINYRL_NO_MATCH = 0,
+	TINYRL_NO_MATCH = 0,
     /**
      * the provided string was already an exact match
      */
-    TINYRL_MATCH,
+	TINYRL_MATCH,
     /**
      * the provided string was ambiguous and produced
      * more than one possible completion
      */
-    TINYRL_AMBIGUOUS,
+	TINYRL_AMBIGUOUS,
     /**
      * the provided string was unambiguous and a 
      * completion was performed
      */
-    TINYRL_COMPLETED_MATCH,
+	TINYRL_COMPLETED_MATCH,
     /**
      * the provided string was ambiguous but a partial
      * completion was performed.
      */
-    TINYRL_COMPLETED_AMBIGUOUS,
+	TINYRL_COMPLETED_AMBIGUOUS,
     /**
      * the provided string was an exact match for one
      * possible value but there are other exetensions
      * of the string available.
      */
-    TINYRL_MATCH_WITH_EXTENSIONS
+	TINYRL_MATCH_WITH_EXTENSIONS
 } tinyrl_match_e;
 
 /* virtual methods */
-typedef char  *
-    tinyrl_compentry_func_t(tinyrl_t   *instance,
-                            const char *text,
-                            unsigned    offset,
-                            unsigned    state);
-typedef int
-    tinyrl_hook_func_t(tinyrl_t *instance);
-
-typedef char **
-    tinyrl_completion_func_t(tinyrl_t   *instance,
-                             const char *text, 
-                             unsigned    start,
-                             unsigned    end);
+typedef char *tinyrl_compentry_func_t(tinyrl_t * instance,
+				      const char *text,
+				      unsigned offset, unsigned state);
+typedef int tinyrl_hook_func_t(tinyrl_t * instance);
+
+typedef char **tinyrl_completion_func_t(tinyrl_t * instance,
+					const char *text,
+					unsigned start, unsigned end);
 /**
  * \return
  * - BOOL_TRUE if the action associated with the key has
  *   been performed successfully
  * - BOOL_FALSE if the action was not successful
  */
-typedef bool_t
-    tinyrl_key_func_t(tinyrl_t *instance,
-                      int       key);
-
+typedef bool_t tinyrl_key_func_t(tinyrl_t * instance, int key);
 
 /* exported functions */
-extern tinyrl_t *
-    tinyrl_new(FILE                     *instream,
-               FILE                     *outstream,
-               unsigned                  stifle,
-               tinyrl_completion_func_t *complete_fn);
-               
+extern tinyrl_t *tinyrl_new(FILE * instream,
+			    FILE * outstream,
+			    unsigned stifle,
+			    tinyrl_completion_func_t * complete_fn);
+
 /*lint -esym(534,tinyrl_printf)  Ignoring return value of function */
-extern int
-    tinyrl_printf(const tinyrl_t *instance,
-                  const char     *fmt,
-                  ...);
+extern int tinyrl_printf(const tinyrl_t * instance, const char *fmt, ...);
 
-extern void
-    tinyrl_delete(tinyrl_t *instance);
+extern void tinyrl_delete(tinyrl_t * instance);
 
-extern tinyrl_history_t *
-    tinyrl__get_history(const tinyrl_t *instance);
+extern tinyrl_history_t *tinyrl__get_history(const tinyrl_t * instance);
 
-extern const char *
-    tinyrl__get_prompt(const tinyrl_t *instance);
+extern const char *tinyrl__get_prompt(const tinyrl_t * instance);
 
-extern void
-    tinyrl_done(tinyrl_t *instance);
+extern void tinyrl_done(tinyrl_t * instance);
 
-extern void
-    tinyrl_completion_over(tinyrl_t *instance);
+extern void tinyrl_completion_over(tinyrl_t * instance);
 
-extern void
-    tinyrl_completion_error_over(tinyrl_t *instance);
+extern void tinyrl_completion_error_over(tinyrl_t * instance);
 
-extern bool_t
-    tinyrl_is_completion_error_over(const tinyrl_t *instance);
+extern bool_t tinyrl_is_completion_error_over(const tinyrl_t * instance);
 
-extern void *
-    tinyrl__get_context(const tinyrl_t *instance);
+extern void *tinyrl__get_context(const tinyrl_t * instance);
 
 /**
  * This operation returns the current line in use by the tinyrl instance
  * NB. the pointer will become invalid after any further operation on the 
  * instance.
  */
-extern const char *
-    tinyrl__get_line(const tinyrl_t *instance);
+extern const char *tinyrl__get_line(const tinyrl_t * instance);
 
-extern void
-    tinyrl__set_istream(tinyrl_t *instance,
-                        FILE     *istream);
+extern void tinyrl__set_istream(tinyrl_t * instance, FILE * istream);
 
-extern bool_t
-    tinyrl__get_isatty(const tinyrl_t *instance);
+extern bool_t tinyrl__get_isatty(const tinyrl_t * instance);
 
-extern FILE *
-    tinyrl__get_istream(const tinyrl_t *instance);
+extern FILE *tinyrl__get_istream(const tinyrl_t * instance);
 
-extern FILE *
-    tinyrl__get_ostream(const tinyrl_t *instance);
+extern FILE *tinyrl__get_ostream(const tinyrl_t * instance);
 
-extern bool_t
-    tinyrl__get_utf8(const tinyrl_t *instance);
+extern bool_t tinyrl__get_utf8(const tinyrl_t * instance);
 
-extern void
-    tinyrl__set_utf8(tinyrl_t *instance, bool_t utf8);
+extern void tinyrl__set_utf8(tinyrl_t * instance, bool_t utf8);
 
-extern char *
-    tinyrl_readline(tinyrl_t   *instance,
-                    const char *prompt,
-                    void       *context);
+extern char *tinyrl_readline(tinyrl_t * instance,
+			     const char *prompt, void *context);
 
-extern char *
-    tinyrl_forceline(tinyrl_t   *instance,
-                     const char *prompt,
-                     void       *context,
-                     const char *line);
+extern char *tinyrl_forceline(tinyrl_t * instance,
+			      const char *prompt,
+			      void *context, const char *line);
 
 extern bool_t
-    tinyrl_bind_key(tinyrl_t          *instance,
-                    int                key,
-                    tinyrl_key_func_t *fn);
-extern void
-    tinyrl_delete_matches(char **instance);
-extern char **
-    tinyrl_completion(tinyrl_t                *instance,
-                      const char              *line,
-                      unsigned                 start,
-                      unsigned                 end,
-                      tinyrl_compentry_func_t *generator);
-extern void
-    tinyrl_crlf(const tinyrl_t *instance);
-extern void
-    tinyrl_ding(const tinyrl_t *instance);
+tinyrl_bind_key(tinyrl_t * instance, int key, tinyrl_key_func_t * fn);
+extern void tinyrl_delete_matches(char **instance);
+extern char **tinyrl_completion(tinyrl_t * instance,
+				const char *line,
+				unsigned start,
+				unsigned end,
+				tinyrl_compentry_func_t * generator);
+extern void tinyrl_crlf(const tinyrl_t * instance);
+extern void tinyrl_ding(const tinyrl_t * instance);
 
-extern void
-    tinyrl_reset_line_state(tinyrl_t *instance);
+extern void tinyrl_reset_line_state(tinyrl_t * instance);
 
-extern bool_t
-    tinyrl_insert_text(tinyrl_t   *instance,
-                       const char *text);
+extern bool_t tinyrl_insert_text(tinyrl_t * instance, const char *text);
 extern void
-    tinyrl_delete_text(tinyrl_t *instance,
-                       unsigned  start,
-                       unsigned  end);
-extern void
-    tinyrl_redisplay(tinyrl_t *instance);
+tinyrl_delete_text(tinyrl_t * instance, unsigned start, unsigned end);
+extern void tinyrl_redisplay(tinyrl_t * instance);
 
 extern void
-    tinyrl_replace_line(tinyrl_t *instance,
-                        const char    *text,
-                        int            clear_undo);
+tinyrl_replace_line(tinyrl_t * instance, const char *text, int clear_undo);
 
 /**
  * Complete the current word in the input buffer, displaying
@@ -196,9 +147,8 @@ extern void
  * - If the current word is ambiguous then a list of 
  *   possible completions will be displayed.
  */
-extern tinyrl_match_e
-    tinyrl_complete(tinyrl_t *instance);
-    
+extern tinyrl_match_e tinyrl_complete(tinyrl_t * instance);
+
 /**
  * Complete the current word in the input buffer, displaying
  * a prompt to clarify any abiguity or extra extensions if necessary.
@@ -211,64 +161,54 @@ extern tinyrl_match_e
  * - If the current word is complete but there are extra
  *   completions which are an extension of that word then
  *   a list of these will be displayed.
- */                        
-extern tinyrl_match_e
-    tinyrl_complete_with_extensions(tinyrl_t *instance);
+ */
+extern tinyrl_match_e tinyrl_complete_with_extensions(tinyrl_t * instance);
 
 /**
  * Disable echoing of input characters when a line in input.
  * 
- */                    
-extern void
-    tinyrl_disable_echo(
-         /** 
+ */
+extern void tinyrl_disable_echo(
+	 /** 
           * The instance on which to operate
           */
-         tinyrl_t *instance,
-         /**
+				       tinyrl_t * instance,
+	 /**
           * The character to display instead of a key press.
           *
           * If this has the special value '/0' then the insertion point will not 
           * be moved when keys are pressed.
           */
-          char echo_char
-    ); 
+				       char echo_char);
 /**
  * Enable key echoing for this instance. (This is the default behaviour)
  */
-extern void
-    tinyrl_enable_echo(
-        /** 
+extern void tinyrl_enable_echo(
+	/** 
          * The instance on which to operate
          */
-        tinyrl_t *instance
-    );
+				      tinyrl_t * instance);
 /**
  * Indicate whether the current insertion point is quoting or not
  */
-extern bool_t 
-    tinyrl_is_quoting(
-        /** 
+extern bool_t tinyrl_is_quoting(
+	/** 
          * The instance on which to operate
          */
-        const tinyrl_t *instance
-    );
+				       const tinyrl_t * instance);
 /**
  * Limit maximum line length
  */
-extern void
-    tinyrl_limit_line_length(
-        /** 
+extern void tinyrl_limit_line_length(
+	/** 
          * The instance on which to operate
          */
-	tinyrl_t *instance,
-        /** 
+					    tinyrl_t * instance,
+	/** 
          * The length to limit to (0) is unlimited
          */
-        unsigned length
-    );
-    
-_END_C_DECL
+					    unsigned length);
 
-#endif /* _tinyrl_tinyrl_h */
+_END_C_DECL
+#endif				/* _tinyrl_tinyrl_h */
 /** @} tinyrl_tinyrl */

+ 49 - 149
tinyrl/vt100.h

@@ -25,9 +25,7 @@ doesn't support all the features of a VT100 terminal.
 #include "lub/c_decl.h"
 #include "lub/types.h"
 
-_BEGIN_C_DECL
-
-typedef struct _tinyrl_vt100 tinyrl_vt100_t;
+_BEGIN_C_DECL typedef struct _tinyrl_vt100 tinyrl_vt100_t;
 
 /* define the Key codes */
 #define KEY_NUL	0	/**< ^@	Null character */
@@ -68,161 +66,63 @@ typedef struct _tinyrl_vt100 tinyrl_vt100_t;
 /**
  * This enumeration is used to identify the types of escape code 
  */
-typedef enum
-{
-    tinyrl_vt100_UNKNOWN,      /**< Undefined escape sequence */
-    tinyrl_vt100_CURSOR_UP,    /**< Move the cursor up        */
-    tinyrl_vt100_CURSOR_DOWN,  /**< Move the cursor down      */
-    tinyrl_vt100_CURSOR_LEFT,  /**< Move the cursor left      */
-    tinyrl_vt100_CURSOR_RIGHT  /**< Move the cursor right     */      
+typedef enum {
+	tinyrl_vt100_UNKNOWN,  /**< Undefined escape sequence */
+	tinyrl_vt100_CURSOR_UP,/**< Move the cursor up        */
+	tinyrl_vt100_CURSOR_DOWN,
+			       /**< Move the cursor down      */
+	tinyrl_vt100_CURSOR_LEFT,
+			       /**< Move the cursor left      */
+	tinyrl_vt100_CURSOR_RIGHT
+			       /**< Move the cursor right     */
 } tinyrl_vt100_escape_t;
 
-extern tinyrl_vt100_t *
-    tinyrl_vt100_new(
-        FILE               *instream,
-        FILE               *outstream
-    );
-extern void
-    tinyrl_vt100_delete(tinyrl_vt100_t *instance);
+extern tinyrl_vt100_t *tinyrl_vt100_new(FILE * instream, FILE * outstream);
+extern void tinyrl_vt100_delete(tinyrl_vt100_t * instance);
 
 /*lint -esym(534,tinyrl_vt100_printf) Ignoring return value of function */
-extern int
-    tinyrl_vt100_printf(
-        const tinyrl_vt100_t *instance,
-        const char           *fmt,
-        ...
+extern int tinyrl_vt100_printf(const tinyrl_vt100_t * instance, const char *fmt, ...
     );
 extern int
-    tinyrl_vt100_vprintf(
-        const tinyrl_vt100_t *instance,
-        const char           *fmt, 
-        va_list               args
-    );
+tinyrl_vt100_vprintf(const tinyrl_vt100_t * instance,
+		     const char *fmt, va_list args);
 
-extern int
-    tinyrl_vt100_oflush(
-        const tinyrl_vt100_t *instance
-    );
-extern int
-    tinyrl_vt100_ierror(
-        const tinyrl_vt100_t *instance
-    );
-extern int
-    tinyrl_vt100_oerror(
-        const tinyrl_vt100_t *instance
-    );
-extern int
-    tinyrl_vt100_ieof(
-        const tinyrl_vt100_t *instance
-    );
-extern int
-    tinyrl_vt100_getchar(
-        const tinyrl_vt100_t *instance
-    );
-extern unsigned
-    tinyrl_vt100__get_width(
-        const tinyrl_vt100_t *instance
-    );
-extern unsigned
-    tinyrl_vt100__get_height(
-        const tinyrl_vt100_t *instance
-    );
+extern int tinyrl_vt100_oflush(const tinyrl_vt100_t * instance);
+extern int tinyrl_vt100_ierror(const tinyrl_vt100_t * instance);
+extern int tinyrl_vt100_oerror(const tinyrl_vt100_t * instance);
+extern int tinyrl_vt100_ieof(const tinyrl_vt100_t * instance);
+extern int tinyrl_vt100_getchar(const tinyrl_vt100_t * instance);
+extern unsigned tinyrl_vt100__get_width(const tinyrl_vt100_t * instance);
+extern unsigned tinyrl_vt100__get_height(const tinyrl_vt100_t * instance);
 extern void
-    tinyrl_vt100__set_istream(
-        tinyrl_vt100_t *instance,
-        FILE           *istream
-    );
-extern FILE *
-    tinyrl_vt100__get_istream(
-        const tinyrl_vt100_t *instance
-    );
-extern FILE *
-    tinyrl_vt100__get_ostream(
-        const tinyrl_vt100_t *instance
-    );
+tinyrl_vt100__set_istream(tinyrl_vt100_t * instance, FILE * istream);
+extern FILE *tinyrl_vt100__get_istream(const tinyrl_vt100_t * instance);
+extern FILE *tinyrl_vt100__get_ostream(const tinyrl_vt100_t * instance);
 
 extern tinyrl_vt100_escape_t
-    tinyrl_vt100_escape_decode(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_ding(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_reset(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_bright(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_dim(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_underscore(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_blink(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_reverse(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_attribute_hidden(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_erase_line(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_clear_screen(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_cursor_back(
-        const tinyrl_vt100_t *instance,
-        unsigned              count
-    );
-extern void
-    tinyrl_vt100_cursor_forward(
-        const tinyrl_vt100_t *instance,
-        unsigned              count
-    );
-extern void
-    tinyrl_vt100_cursor_up(
-        const tinyrl_vt100_t *instance,
-        unsigned              count
-    );
-extern void
-    tinyrl_vt100_cursor_down(
-        const tinyrl_vt100_t *instance,
-        unsigned              count
-    );
-extern void
-    tinyrl_vt100_cursor_home(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_cursor_save(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_cursor_restore(
-        const tinyrl_vt100_t *instance
-    );
-extern void
-    tinyrl_vt100_erase(
-        const tinyrl_vt100_t *instance,
-        unsigned              count
-    );
+tinyrl_vt100_escape_decode(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_ding(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_reset(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_bright(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_dim(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_underscore(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_blink(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_reverse(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_attribute_hidden(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_erase_line(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_clear_screen(const tinyrl_vt100_t * instance);
+extern void
+tinyrl_vt100_cursor_back(const tinyrl_vt100_t * instance, unsigned count);
+extern void
+tinyrl_vt100_cursor_forward(const tinyrl_vt100_t * instance, unsigned count);
+extern void
+tinyrl_vt100_cursor_up(const tinyrl_vt100_t * instance, unsigned count);
+extern void
+tinyrl_vt100_cursor_down(const tinyrl_vt100_t * instance, unsigned count);
+extern void tinyrl_vt100_cursor_home(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_cursor_save(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_cursor_restore(const tinyrl_vt100_t * instance);
+extern void tinyrl_vt100_erase(const tinyrl_vt100_t * instance, unsigned count);
 _END_C_DECL
-
-#endif /* _tinyrl_vt100_h */
+#endif				/* _tinyrl_vt100_h */
 /** @} tinyrl_vt100 */

+ 3 - 5
tinyrl/vt100/private.h

@@ -1,8 +1,6 @@
 #include "tinyrl/vt100.h"
 
-
-struct _tinyrl_vt100
-{
-    FILE *istream;
-    FILE *ostream;   
+struct _tinyrl_vt100 {
+	FILE *istream;
+	FILE *ostream;
 };

+ 193 - 215
tinyrl/vt100/vt100.c

@@ -1,338 +1,316 @@
-#undef __STRICT_ANSI__ /* we need to use fileno() */
+#undef __STRICT_ANSI__		/* we need to use fileno() */
 #include <stdlib.h>
 # include <unistd.h>
 # include <fcntl.h>
 
 #include "private.h"
 
-typedef struct
-{
-    const char            terminator;
-    tinyrl_vt100_escape_t code;
+typedef struct {
+	const char terminator;
+	tinyrl_vt100_escape_t code;
 } vt100_decode_t;
 
 /* This table maps the vt100 escape codes to an enumeration */
-static vt100_decode_t cmds[] =
-{
-    {'A',    tinyrl_vt100_CURSOR_UP},
-    {'B',    tinyrl_vt100_CURSOR_DOWN},
-    {'C',    tinyrl_vt100_CURSOR_RIGHT},
-    {'D',    tinyrl_vt100_CURSOR_LEFT},
+static vt100_decode_t cmds[] = {
+	{'A', tinyrl_vt100_CURSOR_UP},
+	{'B', tinyrl_vt100_CURSOR_DOWN},
+	{'C', tinyrl_vt100_CURSOR_RIGHT},
+	{'D', tinyrl_vt100_CURSOR_LEFT},
 };
+
 /*--------------------------------------------------------- */
-static void
-_tinyrl_vt100_setInputNonBlocking(const tinyrl_vt100_t *this)
+static void _tinyrl_vt100_setInputNonBlocking(const tinyrl_vt100_t * this)
 {
 #if defined(STDIN_FILENO)
-    int flags = (fcntl(STDIN_FILENO,F_GETFL,0) | O_NONBLOCK);
-    fcntl(STDIN_FILENO,F_SETFL,flags);
-#endif /* STDIN_FILENO */
+	int flags = (fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);
+	fcntl(STDIN_FILENO, F_SETFL, flags);
+#endif				/* STDIN_FILENO */
 }
+
 /*--------------------------------------------------------- */
-static void
-_tinyrl_vt100_setInputBlocking(const tinyrl_vt100_t *this)
+static void _tinyrl_vt100_setInputBlocking(const tinyrl_vt100_t * this)
 {
 #if defined(STDIN_FILENO)
-    int flags = (fcntl(STDIN_FILENO,F_GETFL,0) & ~O_NONBLOCK);
-    fcntl(STDIN_FILENO,F_SETFL,flags);
-#endif /* STDIN_FILENO */
+	int flags = (fcntl(STDIN_FILENO, F_GETFL, 0) & ~O_NONBLOCK);
+	fcntl(STDIN_FILENO, F_SETFL, flags);
+#endif				/* STDIN_FILENO */
 }
+
 /*--------------------------------------------------------- */
-tinyrl_vt100_escape_t
-tinyrl_vt100_escape_decode(const tinyrl_vt100_t *this)
-{
-    tinyrl_vt100_escape_t result = tinyrl_vt100_UNKNOWN;
-    char                  sequence[10],*p=sequence;
-    int                   c;
-    unsigned              i;
-    /* before the while loop, set the input as non-blocking */
-    _tinyrl_vt100_setInputNonBlocking(this); 
-
-    /* dump the control sequence into our sequence buffer 
-     * ANSI standard control sequences will end 
-     * with a character between 64 - 126
-     */
-    while(1)
-    {
-        c = getc(this->istream);
-
-        /* ignore no-character condition */
-        if(-1 != c)
-        {
-            *p++ = (c & 0xFF);
-            if( (c != '[') && (c > 63) ) 
-            {
-                /* this is an ANSI control sequence terminator code */
-                result = tinyrl_vt100_CURSOR_UP; /* just a non-UNKNOWN value */
-                break;
-            }
-        } else { 
-            result = tinyrl_vt100_UNKNOWN;
-            break;
-        }
-    }
-    /* terminate the string (for debug purposes) */
-    *p = '\0';
-    
-    /* restore the blocking status */
-    _tinyrl_vt100_setInputBlocking(this);
-
-    if(tinyrl_vt100_UNKNOWN != result)
-    {
-        /* now decode the sequence */
-        for(i = 0;
-            i < sizeof(cmds)/sizeof(vt100_decode_t);
-            i++)
-        {
-            if(cmds[i].terminator == c)
-            {
-                /* found the code in the lookup table */
-                result = cmds[i].code;
-                break;
-            }
-        }
-    }
-    
-    return result;
-}
-/*-------------------------------------------------------- */
-int 
-tinyrl_vt100_printf(const tinyrl_vt100_t *this,
-                    const char           *fmt,
-                    ...)
-{
-    va_list args;
-    int len;
-
-    va_start(args, fmt);
-    len = tinyrl_vt100_vprintf(this, fmt, args);
-    va_end(args);
-
-    return len;
+tinyrl_vt100_escape_t tinyrl_vt100_escape_decode(const tinyrl_vt100_t * this)
+{
+	tinyrl_vt100_escape_t result = tinyrl_vt100_UNKNOWN;
+	char sequence[10], *p = sequence;
+	int c;
+	unsigned i;
+	/* before the while loop, set the input as non-blocking */
+	_tinyrl_vt100_setInputNonBlocking(this);
+
+	/* dump the control sequence into our sequence buffer 
+	 * ANSI standard control sequences will end 
+	 * with a character between 64 - 126
+	 */
+	while (1) {
+		c = getc(this->istream);
+
+		/* ignore no-character condition */
+		if (-1 != c) {
+			*p++ = (c & 0xFF);
+			if ((c != '[') && (c > 63)) {
+				/* this is an ANSI control sequence terminator code */
+				result = tinyrl_vt100_CURSOR_UP;	/* just a non-UNKNOWN value */
+				break;
+			}
+		} else {
+			result = tinyrl_vt100_UNKNOWN;
+			break;
+		}
+	}
+	/* terminate the string (for debug purposes) */
+	*p = '\0';
+
+	/* restore the blocking status */
+	_tinyrl_vt100_setInputBlocking(this);
+
+	if (tinyrl_vt100_UNKNOWN != result) {
+		/* now decode the sequence */
+		for (i = 0; i < sizeof(cmds) / sizeof(vt100_decode_t); i++) {
+			if (cmds[i].terminator == c) {
+				/* found the code in the lookup table */
+				result = cmds[i].code;
+				break;
+			}
+		}
+	}
+
+	return result;
 }
 
 /*-------------------------------------------------------- */
-int
-tinyrl_vt100_vprintf(const tinyrl_vt100_t *this,
-                     const char           *fmt,
-                     va_list               args)
+int tinyrl_vt100_printf(const tinyrl_vt100_t * this, const char *fmt, ...)
 {
-    return vfprintf(this->ostream, fmt, args);
+	va_list args;
+	int len;
+
+	va_start(args, fmt);
+	len = tinyrl_vt100_vprintf(this, fmt, args);
+	va_end(args);
+
+	return len;
 }
+
 /*-------------------------------------------------------- */
 int
-tinyrl_vt100_getchar(const tinyrl_vt100_t *this)
+tinyrl_vt100_vprintf(const tinyrl_vt100_t * this, const char *fmt, va_list args)
 {
-    return getc(this->istream);
+	return vfprintf(this->ostream, fmt, args);
 }
+
 /*-------------------------------------------------------- */
-int
-tinyrl_vt100_oflush(const tinyrl_vt100_t *this)
+int tinyrl_vt100_getchar(const tinyrl_vt100_t * this)
 {
-    return fflush(this->ostream);
+	return getc(this->istream);
 }
+
 /*-------------------------------------------------------- */
-int
-tinyrl_vt100_ierror(const tinyrl_vt100_t *this)
+int tinyrl_vt100_oflush(const tinyrl_vt100_t * this)
 {
-    return ferror(this->istream);
+	return fflush(this->ostream);
 }
+
 /*-------------------------------------------------------- */
-int
-tinyrl_vt100_oerror(const tinyrl_vt100_t *this)
+int tinyrl_vt100_ierror(const tinyrl_vt100_t * this)
 {
-    return ferror(this->ostream);
+	return ferror(this->istream);
 }
+
 /*-------------------------------------------------------- */
-int
-tinyrl_vt100_ieof(const tinyrl_vt100_t *this)
+int tinyrl_vt100_oerror(const tinyrl_vt100_t * this)
 {
-    return feof(this->istream);
+	return ferror(this->ostream);
 }
+
 /*-------------------------------------------------------- */
-int
-tinyrl_vt100_eof(const tinyrl_vt100_t *this)
+int tinyrl_vt100_ieof(const tinyrl_vt100_t * this)
 {
-    return feof(this->istream);
+	return feof(this->istream);
 }
+
 /*-------------------------------------------------------- */
-unsigned
-tinyrl_vt100__get_width(const tinyrl_vt100_t *this)
+int tinyrl_vt100_eof(const tinyrl_vt100_t * this)
 {
-    this=this;
-    /* hard code until we suss out how to do it properly */
-    return 80;
+	return feof(this->istream);
 }
+
 /*-------------------------------------------------------- */
-static void
-tinyrl_vt100_init(tinyrl_vt100_t     *this,
-                  FILE               *istream,
-                  FILE               *ostream)
+unsigned tinyrl_vt100__get_width(const tinyrl_vt100_t * this)
 {
-    this->istream  = istream;
-    this->ostream = ostream;
+	this = this;
+	/* hard code until we suss out how to do it properly */
+	return 80;
 }
+
 /*-------------------------------------------------------- */
 static void
-tinyrl_vt100_fini(tinyrl_vt100_t *this)
+tinyrl_vt100_init(tinyrl_vt100_t * this, FILE * istream, FILE * ostream)
 {
-    /* nothing to do yet... */
-    this=this;
+	this->istream = istream;
+	this->ostream = ostream;
 }
+
 /*-------------------------------------------------------- */
-tinyrl_vt100_t *
-tinyrl_vt100_new(FILE               *istream,
-                 FILE               *ostream)
+static void tinyrl_vt100_fini(tinyrl_vt100_t * this)
 {
-    tinyrl_vt100_t *this = NULL;
-    
-    this = malloc(sizeof(tinyrl_vt100_t));
-    if(NULL != this)
-    {
-        tinyrl_vt100_init(this,istream,ostream);
-    }
-    
-    return this;
+	/* nothing to do yet... */
+	this = this;
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_delete(tinyrl_vt100_t *this)
+tinyrl_vt100_t *tinyrl_vt100_new(FILE * istream, FILE * ostream)
 {
-    tinyrl_vt100_fini(this);
-    /* release the memory */
-    free(this);
+	tinyrl_vt100_t *this = NULL;
+
+	this = malloc(sizeof(tinyrl_vt100_t));
+	if (NULL != this) {
+		tinyrl_vt100_init(this, istream, ostream);
+	}
+
+	return this;
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_ding(const tinyrl_vt100_t *this)
+void tinyrl_vt100_delete(tinyrl_vt100_t * this)
 {
-    tinyrl_vt100_printf(this,"%c",KEY_BEL);
-    (void)tinyrl_vt100_oflush(this);
+	tinyrl_vt100_fini(this);
+	/* release the memory */
+	free(this);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_reset(const tinyrl_vt100_t *this)
+void tinyrl_vt100_ding(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[0m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c", KEY_BEL);
+	(void)tinyrl_vt100_oflush(this);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_bright(const tinyrl_vt100_t *this)
+void tinyrl_vt100_attribute_reset(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[1m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[0m", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_dim(const tinyrl_vt100_t *this)
+void tinyrl_vt100_attribute_bright(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[2m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[1m", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_underscore(const tinyrl_vt100_t *this)
+void tinyrl_vt100_attribute_dim(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[4m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[2m", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_blink(const tinyrl_vt100_t *this)
+void tinyrl_vt100_attribute_underscore(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[5m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[4m", KEY_ESC);
 }
+
+/*-------------------------------------------------------- */
+void tinyrl_vt100_attribute_blink(const tinyrl_vt100_t * this)
+{
+	tinyrl_vt100_printf(this, "%c[5m", KEY_ESC);
+}
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_reverse(const tinyrl_vt100_t *this)
+void tinyrl_vt100_attribute_reverse(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[7m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[7m", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_attribute_hidden(const tinyrl_vt100_t *this)
+void tinyrl_vt100_attribute_hidden(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[8m",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[8m", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_erase_line(const tinyrl_vt100_t *this)
+void tinyrl_vt100_erase_line(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[2K",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[2K", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_clear_screen(const tinyrl_vt100_t *this)
+void tinyrl_vt100_clear_screen(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[2J",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[2J", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_save(const tinyrl_vt100_t *this)
+void tinyrl_vt100_cursor_save(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c7",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c7", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_restore(const tinyrl_vt100_t *this)
+void tinyrl_vt100_cursor_restore(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c8",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c8", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_forward(const tinyrl_vt100_t *this,
-                            unsigned              count)
+void tinyrl_vt100_cursor_forward(const tinyrl_vt100_t * this, unsigned count)
 {
-        tinyrl_vt100_printf(this,"%c[%dC",KEY_ESC,count);
+	tinyrl_vt100_printf(this, "%c[%dC", KEY_ESC, count);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_back(const tinyrl_vt100_t *this,
-                         unsigned              count)
+void tinyrl_vt100_cursor_back(const tinyrl_vt100_t * this, unsigned count)
 {
-        tinyrl_vt100_printf(this,"%c[%dD",KEY_ESC,count);
+	tinyrl_vt100_printf(this, "%c[%dD", KEY_ESC, count);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_up(const tinyrl_vt100_t *this,
-                       unsigned              count)
+void tinyrl_vt100_cursor_up(const tinyrl_vt100_t * this, unsigned count)
 {
-        tinyrl_vt100_printf(this,"%c[%dA",KEY_ESC,count);
+	tinyrl_vt100_printf(this, "%c[%dA", KEY_ESC, count);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_down(const tinyrl_vt100_t *this,
-                         unsigned              count)
+void tinyrl_vt100_cursor_down(const tinyrl_vt100_t * this, unsigned count)
 {
-        tinyrl_vt100_printf(this,"%c[%dB",KEY_ESC,count);
+	tinyrl_vt100_printf(this, "%c[%dB", KEY_ESC, count);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_cursor_home(const tinyrl_vt100_t *this)
+void tinyrl_vt100_cursor_home(const tinyrl_vt100_t * this)
 {
-        tinyrl_vt100_printf(this,"%c[H",KEY_ESC);
+	tinyrl_vt100_printf(this, "%c[H", KEY_ESC);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100_erase(const tinyrl_vt100_t *this,
-                   unsigned              count)
+void tinyrl_vt100_erase(const tinyrl_vt100_t * this, unsigned count)
 {
-        tinyrl_vt100_printf(this,"%c[%dP",KEY_ESC,count);
+	tinyrl_vt100_printf(this, "%c[%dP", KEY_ESC, count);
 }
+
 /*-------------------------------------------------------- */
-void
-tinyrl_vt100__set_istream(tinyrl_vt100_t *this,
-                          FILE           *istream)
+void tinyrl_vt100__set_istream(tinyrl_vt100_t * this, FILE * istream)
 {
-        this->istream = istream;
+	this->istream = istream;
 }
+
 /*-------------------------------------------------------- */
-FILE *
-tinyrl_vt100__get_istream(const tinyrl_vt100_t *this)
+FILE *tinyrl_vt100__get_istream(const tinyrl_vt100_t * this)
 {
-        return this->istream;
+	return this->istream;
 }
+
 /*-------------------------------------------------------- */
-FILE *
-tinyrl_vt100__get_ostream(const tinyrl_vt100_t *this)
+FILE *tinyrl_vt100__get_ostream(const tinyrl_vt100_t * this)
 {
-        return this->ostream;
+	return this->ostream;
 }
+
 /*-------------------------------------------------------- */

Some files were not shown because too many files changed in this diff