免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2055 | 回复: 3
打印 上一主题 下一主题

mini_httpd中一个函数的困惑?? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-04 23:21 |只看该作者 |倒序浏览
不知道这个match(...)什么意思?????
调用该函数如下:
                     match( cgi_pattern, file ) file  // cgi_pattern在conf文件或main参数中设定  file: home/www/aaa
                     match( "**MSIE**", useragent )  // useragent Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
                     
                     match( url_pattern, path )   // path = /home/www/xxx.html
                     match( lp, refhost )  // refrence不知
                     match( url_pattern, path )
请大家帮我看看这个函数作用???代码如下:

  1. int
  2. match( const char* pattern, const char* string )
  3.     {
  4.     const char* or;

  5.     for (;;)
  6.         {
  7.         or = strchr( pattern, '|' );
  8.         if ( or == (char*) 0 )
  9.             return match_one( pattern, strlen( pattern ), string );
  10.         if ( match_one( pattern, or - pattern, string ) )
  11.             return 1;
  12.         pattern = or + 1;
  13.         }
  14.     }


  15. static int
  16. match_one( const char* pattern, int patternlen, const char* string )
  17.     {
  18.     const char* p;

  19.     for ( p = pattern; p - pattern < patternlen; ++p, ++string )
  20.         {
  21.         if ( *p == '?' && *string != '\0' )
  22.             continue;
  23.         if ( *p == '*' )
  24.             {
  25.             int i, pl;
  26.             ++p;
  27.             if ( *p == '*' )
  28.                 {
  29.                 /* Double-wildcard matches anything. */
  30.                 ++p;
  31.                 i = strlen( string );
  32.                 }
  33.             else
  34.                 /* Single-wildcard matches anything but slash. */
  35.                 i = strcspn( string, "/" );
  36.             pl = patternlen - ( p - pattern );
  37.             for ( ; i >= 0; --i )
  38.                 if ( match_one( p, pl, &(string[i]) ) )
  39.                     return 1;
  40.             return 0;
  41.             }
  42.         if ( *p != *string )
  43.             return 0;
  44.         }
  45.     if ( *string == '\0' )
  46.         return 1;
  47.     return 0;
  48.     }
复制代码

[ 本帖最后由 bullity 于 2009-5-12 12:39 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-05-04 23:23 |只看该作者
还有个问题:
  1. snprintf(command, sizeof(command),
  2.          "ls -lgF '%s' | tail +2 | sed -e 's/^\\([^ ][^ ]*\\)\\(  *[^ ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*\\)\\(  *[^ ][^ ]*\\)  *\\([^ ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*\\)  *\\(.*\\)$/\\1 \\3  \\4  |\\5/' -e '/ -> /!s,|\\([^*]*\\)$,|<A HREF=\"\\1\">\\1</A>,' -e '/ -> /!s,|\\(.*\\)\\([*]\\)$,|<A HREF=\"\\1\">\\1</A>\\2,' -e '/ -> /s,|\\([^@]*\\)\\(@* -> \\),|<A HREF=\"\\1\">\\1</A>\\2,' -e 's/|//'",
  3.             file );
  4. fp = popen( command, "r" );
复制代码


ls 后面那些个是什么玩意呀????

论坛徽章:
0
3 [报告]
发表于 2009-05-04 23:38 |只看该作者
原帖由 bullity 于 2009-5-4 23:23 发表
还有个问题:
snprintf(command, sizeof(command),
         "ls -lgF '%s' | tail +2 | sed -e 's/^\\([^ ][^ ]*\\)\\(  *[^ ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*\\)\\(  *[^ ][^ ]*\\)  *\\([^ ][^ ]*  *[^ ][^ ]*  *[ ...

一个tail再加一个sed处理

论坛徽章:
0
4 [报告]
发表于 2009-05-05 13:35 |只看该作者
up
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP