标题: opt2byte.LIB命令行开关解析库 [打印本页]
作者: happy886rr 时间: 2016-12-5 22:30 标题: opt2byte.LIB命令行开关解析库
本帖最后由 happy886rr 于 2017-1-7 19:54 编辑
[2016/12/06]修复一处笔误。
THE OPT TO BYTE ARRAY LIB, COPYRIGHT@2016~2018 BY HAPPY, VERSION 1.0
opt2byte.LIB
摘要:
=============================================================================
这是可以解析命令行参数的库,用来帮助你快速构建命令行第三方工具的开关解析部分。
从此你无需再写开关解析。
=============================================================================
函数原型:
-----------------------------------------------------------------------------
//OPT转BYTE数组
byte* __cdecl Opt2Byte(
int argc, //argc
char** argv, //argv
char* optstr //开关正则
);
-----------------------------------------------------------------------------
引入:
-----------------------------------------------------------------------------
#include "opt2byte.h" //先引入头文件
#pragram commet(lib,"opt2byte.LIB"); //在项目中引入库文件
-lopt2byte -L./ //gcc连接参数
-----------------------------------------------------------------------------
命令开关正则语法:
-----------------------------------------------------------------------------
char* optstr="=/C* /U:utf-8 /CS /T* /D* /M* /?";
在上句opt正则中,其中第一个引号后的等号表示精确开关匹配,
即区分大小写匹配,不为等号则忽略大小写匹配。
其中*代表后继参数,一个*代表/C开关有一个后继参数。
其中:代表连参符,即/U开关后边无需空格即可连接参数,如/U:"utf-8"。
其中无*的开关表示没有任何后继参数。
opt2byte.LIB库,最大可支持99个开关解析,最多处理254个命令行参数。 当然你可以
在源码中修改以使其支持不限量的数目。
opt2byte.LIB库全部为本人原创,且不需要任何其他库文件,效率性能秒杀getopt函数,
无法解析的开关argv[unknown]将存入bp[100~127]的无法解析空间。 bp[0]表示解析状
态,即bp[0]为0时表示正常解析,否则其值为发生错误的argv序号。bp[1~99]为各开关
解析到的命令行参数argv序号。
-----------------------------------------------------------------------------
英译:
-----------------------------------------------------------------------------
THE OPT TO BYTE ARRAY LIB, COPYRIGHT@2016~2018 BY HAPPY, VERSION 1.0
-----------------------------------------------------------------------------
This is a library of command-line arguments that can help you quickly build
switch-resolution parts of command-line third-party tools.From then on you do
not have to repeat the write switch every time parsing.
-----------------------------------------------------------------------------
12/05/2016
核心代码:复制代码
使用示例:- #include <stdio.h>
- #include "opt2byte.h"
-
- int main(int argc, char** argv)
- {
- int i;
- char* optstr="=/D** /U: /S /T"; //这里填写命令开关正则
-
- byte* bp=Opt2Byte(argc, argv, optstr); //这里用来接收转化后的BYTE数组
-
- if(bp[0]==255){printf("没有任何参数\n");}
- if(bp[0]!=0){printf("在%s附近出现错误,可能是缺少参数,或是无法解析的开关\n", argv[bp[0]]);}
-
- for(i=1; i<=4; i++){printf("%d\n",bp[i]); } //打印分析后的开关BYTE数组参数
-
- return 0;
-
- }
复制代码
下载,base64加权码- @echo off
- setlocal enabledelayedexpansion
-
- ::*********BASE64 加权解码器*********
- set $=set [#]&CALL :BASE64_PRESS&set [$]=A&((for %%Z in ([,],{,},_,$,#,-,@) do (set [$]=![$]!![$]!&for %%S in (![$]!) do (for /l %%i in (1,1,6) do (!$!%%i=![#]%%i:%%Z=%%S!))))&for /l %%i in (1,1,6) do (set/p=![#]%%i:.=!<NUL))>opt2byte.BSEP&certutil -decode opt2byte.BSEP opt2byte.zip&pause&exit /b
- ::***********************************
-
- :BASE64_PRESS
-
- !$!1=UEsDBAo][BNPhkk}E]bGliL1BLAwQU]C[gs4VJYL47QeI]WAQ[Dg[AGxpYi9vcHQyYnl0ZS5o09fi5eL0Dwi5vsopMsT11N/rL3etP/V3/yOgaIiHqwJQRiHEXwEkp+AYFOQYqeDj6aSj4OwfEBnk6e4R4mBkYGhWByQsgGoUPBwDAiJ1FMJcg4I9/f0UDPUMgMbkF5QYJVWWpOoBdQK57s7OQDP8vK0UdHNgUgq6Pnr6vFxaQMzLpZyZlpeSmqYAkuDlKqksSAXxSvOKM9PzUlMUkjMSi8By1kClqXkpmWkgTfr6KH7g5QKp0FKIj09OSU3OUfAHWuQEFNHIzCtRSCxKT9YBm6OlBeKUQTkKQOcUlxRpAg0GAFBLAwQU]C[OT4ZJ/6T4/ccC[B8B[AE]GxpYi9vcHQyYnl0ZS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