📄 libtecla.h
字号:
#ifndef libtecla_h#define libtecla_h/* * Copyright (c) 2000, 2001 by Martin C. Shepherd. * * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, and/or sell copies of the Software, and to permit persons * to whom the Software is furnished to do so, provided that the above * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Except as contained in this notice, the name of a copyright holder * shall not be used in advertising or otherwise to promote the sale, use * or other dealings in this Software without prior written authorization * of the copyright holder. */#ifdef __cplusplusextern "C" {#endif#include <stdio.h> /* FILE * */#include <stdlib.h> /* size_t */#include <time.h> /* time_t *//* * The following are the three components of the libtecla version number. * Note that it is better to use the libtecla_version() function than these * macros since the macros only tell you which version of the library your * code was compiled against, whereas the libtecla_version() function * tells you which version of the shared tecla library your program is * actually linked to. */#define TECLA_MAJOR_VER 1#define TECLA_MINOR_VER 4#define TECLA_MICRO_VER 0/*....................................................................... * Query the version number of the tecla library. * * Input: * major int * The major version number of the library * will be assigned to *major. This number is * only incremented when a change to the library is * made that breaks binary (shared library) and/or * compilation backwards compatibility. * minor int * The minor version number of the library * will be assigned to *minor. This number is * incremented whenever new functions are added to * the public API. * micro int * The micro version number of the library will be * assigned to *micro. This number is incremented * whenever internal changes are made that don't * change the public API, such as bug fixes and * performance enhancements. */void libtecla_version(int *major, int *minor, int *micro);/*----------------------------------------------------------------------- * The getline module provides interactive command-line input, recall * and editing by users at terminals. See the gl_getline(3) man page for * more details. *-----------------------------------------------------------------------*//* * Provide an opaque handle for the resource object that is defined in * getline.h. */typedef struct GetLine GetLine;/* * The following two functions are used to create and delete the * resource objects that are used by the gl_getline() function. */GetLine *new_GetLine(size_t linelen, size_t histlen);GetLine *del_GetLine(GetLine *gl);/* * Read a line into an internal buffer of gl. */char *gl_get_line(GetLine *gl, const char *prompt, const char *start_line, int start_pos);/* * Configure the application specific and/or user-specific behavior of * gl_get_line(). */int gl_configure_getline(GetLine *gl, const char *app_string, const char *app_file, const char *user_file);/* * Read a line from the network into an internal buffer of gl. */char *gl_get_line_net(GetLine *gl, const char *prompt, const char *start_line, int start_pos, int val);/* * Return the current position of the cursor within the internal buffer, * and the cursor position on the terminal. */int gl_is_net(GetLine *gl);void gl_set_is_net(GetLine *gl, int is_net);int gl_get_buff_curpos(const GetLine *gl);int gl_place_cursor(GetLine *gl, int buff_curpos);int gl_redisplay_line(GetLine *gl);int gl_reset_line(GetLine *gl);int gl_get_user_event(GetLine *gl);void gl_reset_user_event(GetLine *gl);const char *gl_get_key_binding_action_name(GetLine *gl, const char *keyseq);/*----------------------------------------------------------------------- * The file-expansion module provides facilities for expanding ~user/ and * $envvar expressions, and for expanding glob-style wildcards. * See the ef_expand_file(3) man page for more details. *-----------------------------------------------------------------------*//* * ExpandFile objects contain the resources needed to expand pathnames. */typedef struct ExpandFile ExpandFile;/* * The following functions are used to create and delete the resource * objects that are used by the ef_expand_file() function. */ExpandFile *new_ExpandFile(void);ExpandFile *del_ExpandFile(ExpandFile *ef);/* * A container of the following type is returned by ef_expand_file(). */typedef struct { int exists; /* True if the files in files[] currently exist. */ /* This only time that this may not be true is if */ /* the input filename didn't contain any wildcards */ /* and thus wasn't matched against existing files. */ /* In this case the single entry in 'nfile' may not */ /* refer to an existing file. */ int nfile; /* The number of files in files[] */ char **files; /* An array of 'nfile' filenames. */} FileExpansion;/* * The ef_expand_file() function expands a specified pathname, converting * ~user/ and ~/ patterns at the start of the pathname to the * corresponding home directories, replacing $envvar with the value of * the corresponding environment variable, and then, if there are any * wildcards, matching these against existing filenames. * * If no errors occur, a container is returned containing the array of * files that resulted from the expansion. If there were no wildcards * in the input pathname, this will contain just the original pathname * after expansion of ~ and $ expressions. If there were any wildcards, * then the array will contain the files that matched them. Note that * if there were any wildcards but no existing files match them, this * is counted as an error and NULL is returned. * * The supported wildcards and their meanings are: * * - Match any sequence of zero or more characters. * ? - Match any single character. * [chars] - Match any single character that appears in 'chars'. * If 'chars' contains an expression of the form a-b, * then any character between a and b, including a and b, * matches. The '-' character looses its special meaning * as a range specifier when it appears at the start * of the sequence of characters. * [^chars] - The same as [chars] except that it matches any single * character that doesn't appear in 'chars'. * * Wildcard expressions are applied to individual filename components. * They don't match across directory separators. A '.' character at * the beginning of a filename component must also be matched * explicitly by a '.' character in the input pathname, since these * are UNIX's hidden files. * * Input: * fe ExpandFile * The pathname expansion resource object. * path const char * The path name to be expanded. * pathlen int The length of the suffix of path[] that * constitutes the filename to be expanded, * or -1 to specify that the whole of the * path string should be used. * Output: * return FileExpansion * A pointer to a results container within the * given ExpandFile object. This contains an * array of the pathnames that resulted from * expanding ~ and $ expressions and from * matching any wildcards, sorted into lexical * order. * * This container and its contents will be * recycled on subsequent calls, so if you need * to keep the results of two successive runs, * you will either have to allocate a private * copy of the array, or use two ExpandFile * objects. * * On error, NULL is returned. A description * of the error can be acquired by calling the * ef_last_error() function. */FileExpansion *ef_expand_file(ExpandFile *ef, const char *path, int pathlen);/*....................................................................... * Print out an array of matching files. * * Input: * result FileExpansion * The container of the sorted array of * expansions. * fp FILE * The output stream to write to. * term_width int The width of the terminal. * Output: * return int 0 - OK. * 1 - Error. */int ef_list_expansions(FileExpansion *result, FILE *fp, int term_width);/* * The ef_last_error() function returns a description of the last error * that occurred in a call ef_expand_file(). Note that this message is * contained in an array which is allocated as part of *ef, and its * contents thus potentially change on every call to ef_expand_file(). */const char *ef_last_error(ExpandFile *ef);/*----------------------------------------------------------------------- * The WordCompletion module is used for completing incomplete words, such * as filenames. Programs can use functions within this module to register * their own customized completion functions. *-----------------------------------------------------------------------*//* * Ambiguous completion matches are recorded in objects of the * following type. */typedef struct WordCompletion WordCompletion;/* * Create a new completion object. */WordCompletion *new_WordCompletion(void);/* * Delete a redundant completion object. */WordCompletion *del_WordCompletion(WordCompletion *cpl);/*....................................................................... * Callback functions declared and prototyped using the following macro * are called upon to return an array of possible completion suffixes * for the token that precedes a specified location in the given * input line. It is up to this function to figure out where the token * starts, and to call cpl_add_completion() to register each possible * completion before returning. * * Input: * cpl WordCompletion * An opaque pointer to the object that will * contain the matches. This should be filled * via zero or more calls to cpl_add_completion(). * data void * The anonymous 'data' argument that was * passed to cpl_complete_word() or * gl_customize_completion()). * line const char * The current input line. * word_end int The index of the character in line[] which * follows the end of the token that is being * completed. * Output * return int 0 - OK. * 1 - Error. */#define CPL_MATCH_FN(fn) int (fn)(WordCompletion *cpl, void *data, \ const char *line, int word_end)typedef CPL_MATCH_FN(CplMatchFn);/*....................................................................... * Optional callback functions declared and prototyped using the * following macro are called upon to return non-zero if a given * file, specified by its pathname, is to be included in a list of * completions. * * Input: * data void * The application specified pointer which * was specified when this callback function * was registered. This can be used to have * anything you like passed to your callback. * pathname const char * The pathname of the file to be checked to * see if it should be included in the list
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -