File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / inc / aitio.h
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Mon Mar 22 15:21:20 2010 UTC (14 years, 3 months ago) by misho
Branches: MAIN
CVS tags: io1_2, IO1_1, HEAD
new ver 1.1

    1: /*************************************************************************
    2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
    3: *  by Michael Pounov <misho@openbsd-bg.org>
    4: *
    5: * $Author: misho $
    6: * $Id: aitio.h,v 1.3 2010/03/22 15:21:20 misho Exp $
    7: *
    8: *************************************************************************/
    9: #ifndef __AITIO_H
   10: #define __AITIO_H
   11: 
   12: 
   13: typedef struct _tagURLItem {
   14: 	int	vallen;
   15: 	char	*value;
   16: } url_Item_t;
   17: 
   18: struct tagIOURL {
   19: 	unsigned char	url_line[BUFSIZ];
   20: 
   21: 	url_Item_t	url_tech;
   22: 	url_Item_t	url_user;
   23: 	url_Item_t	url_pass;
   24: 	url_Item_t	url_host;
   25: 	url_Item_t	url_port;
   26: 	url_Item_t	url_path;
   27: 	url_Item_t	url_args;
   28: 
   29: 	char		*url_reserved;
   30: };
   31: 
   32: struct tagIOCmd {
   33: 	const char *cmd_name;
   34: 	int (*cmd_func)(void *, FILE *, char **);
   35: 	const char *cmd_doc;
   36: 	const char *cmd_help;
   37: 	char *(*cmd_comp)(const char *, int);
   38: };
   39: 
   40: typedef struct tagIOCmd ioCommands_t;
   41: typedef char *io_CompEntry_t(const char *, int);
   42: typedef char **io_Completion_t(const char *, int, int);
   43: 
   44: 
   45: // io_GetErrno() Get error code of last operation
   46: inline int io_GetErrno();
   47: // io_GetError() Get error text of last operation
   48: inline const char *io_GetError();
   49: 
   50: 
   51: /*
   52:  * ioPromptRead() Read data from input h[0] with prompt to output h[1]
   53:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
   54:  * @csPrompt = Prompt before input, may be NULL
   55:  * @psData = Readed data
   56:  * @dataLen = Length of data
   57:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
   58: */
   59: int ioPromptRead(int *h, const char *csPrompt, char * __restrict psData, int dataLen);
   60: /*
   61:  * ioPromptPassword() Read password from input h[0] with prompt to output h[1]
   62:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
   63:  * @csPrompt = Prompt before input, may be NULL
   64:  * @psPass = Readed password
   65:  * @passLen = Length of password
   66:  * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
   67:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
   68: */
   69: int ioPromptPassword(int *h, const char *csPrompt, char * __restrict psPass, int passLen, int confirm);
   70: 
   71: /*
   72:  * ioRegexVerify() Function for verify data match in regex expression
   73:  * @csRegex = Regulare expression pattern
   74:  * @csData = Data for check and verify
   75:  * @startPos = Return start positions
   76:  * @endPos = Return end positions
   77:  * return: NULL not match or error; !=NULL begin of matched data
   78: */
   79: const char *ioRegexVerify(const char *csRegex, const char *csData, int *startPos, int *endPos);
   80: /*
   81:  * ioRegexGet() Function for get data match in regex expression
   82:  * @csRegex = Regulare expression pattern
   83:  * @csData = Data from get
   84:  * @psString = Returned string if match
   85:  * @strLen = Length of string
   86:  * return: 0 not match; >0 count of returned chars
   87: */
   88: int ioRegexGet(const char *csRegex, const char *csData, char * __restrict psString, int strLen);
   89: /*
   90:  * ioRegexReplace() Function for replace data match in regex expression with newdata
   91:  * @csRegex = Regulare expression pattern
   92:  * @csData = Source data
   93:  * @csNew = Data for replace
   94:  * return: NULL not match or error; !=NULL allocated new string, must be free after use!
   95: */
   96: char *ioRegexReplace(const char *csRegex, const char *csData, const char *csNew);
   97: 
   98: /*
   99:  * io_Path2File() Parse and make path/filename pair
  100:  * @csArgs = Input argument line
  101:  * @psPath = Output Path, if ==NULL path not returned
  102:  * @pathLen = Size of path array
  103:  * @psFile = Output File
  104:  * @fileLen = Size of file array
  105:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
  106: */
  107: inline int io_Path2File(const char * __restrict csArgs, char * __restrict psPath, int pathLen, 
  108: 		char * __restrict psFile, int fileLen);
  109: /*
  110:  * io_MakeAV() Parse and make attribute/value pair
  111:  * @csArgs = Input argument line
  112:  * @csDelim = Delimiter for separate
  113:  * @psAttr = Output Attribute
  114:  * @attrLen = Size of attribute array
  115:  * @psValue = Output Value, if ==NULL this element not present value or not wanted for return
  116:  * @valLen = Size of value array
  117:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
  118: */
  119: inline int io_MakeAV(const char * __restrict csArgs, const char *csDelim, 
  120: 		char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen);
  121: /*
  122:  * io_SizeArray() Parse and calculate size of array
  123:  * @csArgs = Input arguments line
  124:  * @csDelim = Delimiter(s) for separate
  125:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of items
  126: */
  127: inline int io_SizeArray(const char *csArgs, const char *csDelim);
  128: /*
  129:  * io_MakeArray() Parse and make array of arguments values ... 
  130:  *	(input string will be modified! and output array must be free)
  131:  * @psArgs = Input arguments line, after execute string is modified!!!
  132:  * @csDelim = Delimiter(s) for separate
  133:  * @args = Output array of arguments ... (must be free() after procced function!)
  134:  * @nargs = Maximum requested count of arguments from input string psArgs
  135:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
  136: */
  137: inline int io_MakeArray(char * __restrict psArgs, const char *csDelim, 
  138: 		char *** __restrict args, int nargs);
  139: 
  140: /*
  141:  * ioURLGet() Parse and get data from input URL
  142:  * @csURL = Input URL line
  143:  * @url = Output parsed URL
  144:  * return: 0 error format not find tech:// and return URL like path; 
  145:  		-1 error:: can`t read; >0 ok, up bits for known elements
  146: */
  147: int ioURLGet(const char *csURL, struct tagIOURL *url);
  148: /*
  149:  * ioURLGetValue() Get value from parsed URL
  150:  * @url = Input parsed URL
  151:  * @csAttr = Attribute for search
  152:  * @psValue = Return value of attribute, if ==NULL only check for existence of attribute
  153:  * @valLen = Size of psValue array
  154:  * return: 0 error attribute not find; -1 error:: can`t read; >0 ok, find at position
  155: */
  156: int ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen);
  157: /*
  158:  * ioURLGetFile() Get file from parsed URL
  159:  * @url = Input parsed URL
  160:  * @psValue = Return filename, if not specified file in url path, replace with /
  161:  * @valLen = Size of psValue array
  162:  * return: -1 error:: can`t read; 0 ok
  163: */
  164: int ioURLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen);
  165: 
  166: /*
  167:  * ioCLIComp() Initialize completion CLI features
  168:  * @cmdComplete = Completion function
  169:  * @cmdEntry = Compentry function
  170:  * return: none
  171: */
  172: inline void ioCLIComp(io_Completion_t *cmdComplete, io_CompEntry_t *cmdEntry);
  173: /*
  174:  * ioCLIExec() Execute CLI main loop
  175:  * @cmdList = Commands list
  176:  * @out = Output handle
  177:  * @csPrompt = Prompt text
  178:  * return: -1 error, 0 = exit w/^+D, 1 done.
  179: */
  180: int ioCLIExec(ioCommands_t *cmdList, FILE *out, const char *csPrompt);
  181: 
  182: /*
  183:  * io_Cmd_Unsupported() Builtin helper function for unsupported commands
  184:  * @cmds = Commands list
  185:  * @out = Output handle
  186:  * @args = Parsed arguments array
  187:  * return: -1 error, 0 = ok, 1 exit from Cli!
  188: */
  189: int io_Cmd_Unsupported(void *cmds, FILE *out, char ** __restrict args);
  190: /*
  191:  * io_Cmd_Help() Builtin helper function for Help screen
  192:  * @cmds = Commands list
  193:  * @out = Output handle
  194:  * @args = Parsed arguments array
  195:  * return: -1 error, 0 = ok
  196: */
  197: int io_Cmd_Help(void *cmds, FILE *out, char ** __restrict args);
  198: /*
  199:  * io_Cmd_Exit() Builtin helper function for Exit from Cli
  200:  * @cmds = Commands list
  201:  * @out = Output handle
  202:  * @args = Parsed arguments array
  203:  * return: 1 exit from Cli!
  204: */
  205: int io_Cmd_Exit(void *cmds, FILE *out, char ** __restrict args);
  206: 
  207: 
  208: /*
  209:  * io_Make_Comp_Commands - Declare helper function for Commands completion arguments
  210: */
  211: #define IO_MAKE_COMP_COMMANDS(FUNC, CMDS)	\
  212: 	char *FUNC(const char *text, int state) \
  213: 	{ \
  214: 		register int i; \
  215: 		int len = strlen(text); \
  216: 		for (i = state; CMDS[i].cmd_name; i++) { \
  217: 			if (strncmp(CMDS[i].cmd_name, "---", 3) && \
  218: 					!strncmp(CMDS[i].cmd_name, text, len)) \
  219: 				return strdup(CMDS[i].cmd_name); \
  220: 		} \
  221: 		return NULL; \
  222: 	}
  223: 
  224: /*
  225:  * io_Comp_Filename() Builtin helper function for filename completion arguments
  226:  * @text = Text line
  227:  * @state = Position state
  228:  * return: NULL not found filename, != NULL filename
  229: */
  230: char *io_Comp_Filename(const char *text, int state);
  231: 
  232: 
  233: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>