posts - 23, comments - 0, trackbacks - 0, articles - 3
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

家里学习总结

Posted on 2010-07-16 19:58 beauty9235 阅读(222) 评论(0)  编辑  收藏

 

LINUX编程学习

作者:罗小强 beauty9235(at)gmail.com

发布记录:Sun Dec 27 16:33:01 CST 2009

 

文档说明

参与人员:

 

作者

联络

罗小强

beauty9235 beauty9235(at)gmail.com

 

(at) email @ 符号

发布记录

 

版本

 日期

 作者

 说明

1.0

081218

罗小强

第一版

 

 

 

 

 

 

 

 

 

 

 

 


 

删除所.svn. 2

c.vim.. 2

获取格式化时间... 2

strtok的使用... 2

strcpy ,strncasecmp, strsep, calloc,free的使用... 2

enum的使用... 3

字符串匹配... 3

字符串组合... 5

字符串数组引用调用及文件流的读取... 5

文件流的读取与写入... 6

va_listva_startva_argva_end的原理与使用... 6

 

find ./ -name ".svn"  | xargs rm –rf

下载地址 http://www.vim.org/scripts/script.php?script_id=213

unzip cvim.zip  -d ./cvim

mv software/cvim  .vim

修改个人设置./.vim/c-support/templates中的Template保存着个人设置信息

如果你对部分定义的代码不满意,可以修改对应的文件中的相应部分。如你对使用快捷键“\im”产生的mian函数的骨架不满意,可以修改templates\c.idioms.template文件中的“== idioms.main ==”部分。

time_t now;

char timebuf[100] = {0};

now = time(NULL);

strftime ( timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime (&now) );

printf("Date: %s\r\n", timebuf );

strtok的使用

char bufline[]="name=\"value\"";

    char *tmp = strtok(bufline, "\"");//以“分隔  返回“之前的字符串 name=

    tmp = strtok(NULL, "\"");//再以“分隔 返回“之前的字符串 value

    printf("%s",tmp);

    char *g_http_line_buf;

    g_http_line_buf=(char *)calloc(1,128);

    strcpy(g_http_line_buf,"GET /index.html?user=\"zhanshan\" HTTP/1.1^M");

    printf("%s\n",g_http_line_buf);

    if (strncasecmp(g_http_line_buf, "GET", 3) && strncasecmp(g_http_line_buf, "POST", 4))

    {

        printf("include get or post" );

    }

    char *method,*path,*protocol,*file,*query;

    method = path = g_http_line_buf;

    strsep ( &path, " " );

    protocol = path;

    strsep ( &protocol, " " );

    file = &(path[1]);///后面的字符串指针给file

    query = strchr ( file, '?' );

    if(query)

    {

    *query++ = 0;

    }

    printf("method:%s\npath:%s\nprotocol:%s\nfile:%s\nquery:%s\n",method,path,protocol,file,query);

free(g_http_line_buf);

enum的使用

enum {

    admin=100,

    users=103

} G3_USER_GROUP;

G3_USER_GROUP = admin;

printf("%d\n",G3_USER_GROUP);

static int match_one ( const char *pattern, int patternlen, const char *string )

{

         const char *p = NULL;

         for ( p = pattern; ( p - pattern ) < patternlen; ++p, ++string )

         {

                   if ( ( '?' == *p ) && ( *string != '\0' ) )//如果p为? string没有结束则继续

                   {

                            continue;

                   }

                   if ( '*' == *p )

                   {

                            int i, pl;

                            ++p;

                            if ( '*' == *p)

                            {

                                     /*两个通配符'*'匹配所有字符 */

                                     ++p;

                                     i = strlen (string);

                            }

                            else

                            {

                                     /*单个通配符'*'匹配除了'/'字符外的所有字符*/

                                     i = strcspn ( string, "/" );

                            }

                            pl = patternlen - ( p - pattern );

                            for ( ; i >= 0; --i )

                            {

                                     if ( match_one ( p, pl, &(string[i]) ) )

                                     {

                                               return (1);

                                     }

                            }

                            return (0);

                   }

                   if ( *p != *string )

                   {

                            return (0);

                   }

         }

         if ( '\0' == *string )

         {

                   return (1);

         }

         return (0);

}

int match ( const char *pattern, const char *string )

{

         const char *or;

         for ( ; ; )

         {

                   or = strchr ( pattern, '|' );//**.html

                   if ( or == (char *) 0 )

                   {

                            return match_one ( pattern, strlen (pattern), string );

                   }

                   if ( match_one ( pattern, or - pattern, string ) )

                   {

                            return (1);

                   }

                   pattern = or + 1;

         }

}

调用

int main ( int argc, char *argv[] )

{

    if(match("**.htm|**.jsp","index.hml"))

         {

                   printf("match\n");

         }

         else

         {

                   printf("not match\n");

         }

         exit(0);

}       

char lang_file[30];

sprintf(lang_file, "/usr/sbin/%s.js", lang_info);可以是一个变量

sprintf(lang_file, "/usr/sbin/%s.js", "cn");也可以是一个值

 

char header[10000];

memset(header, 0, sizeof(header));

snprintf ( header, sizeof (header), "WWW-Authenticate: Basic realm=\"%s\"", realm );

char page_language[128];

memset( page_language, 0, sizeof(page_language) );//初始化页面语言字符串

FILE *fp = fopen(lang_file, "r");//判断文件是否存在

if (fp == NULL)

{

  fprintf( stderr, "open language file(%s) error(%d)\n", lang_file, errno );

  return ;

}

trans_js_name(fp, "lang_charset.set", page_language, sizeof(page_language));

fclose(fp);

char *trans_js_name(FILE *fp, const char *name, char *value, int maxlen)

{

    char bufline[256];

    char *temp;

    if (fp == NULL || name == NULL || value == NULL)

    {

        return NULL;

    }

    temp = value;

    while (fgets(bufline, sizeof(bufline) - 1, fp) != NULL)//循环读取文件流的每一件

    {

        if (strstr(bufline, name))//如果包含了相对应的name=”value

        {

            char *tmp = strtok(bufline, "\"");以“分隔  

            tmp = strtok(NULL, "\"");再以“分隔

            strncpy(value, tmp, maxlen);//取出对应的值

            return temp;

        }

    }

    return temp;

}

typedef FILE * webs_t;

int websWrite ( webs_t wp, char *fmt, ... )

{

        va_list args;

        char buf[1024];

        int ret;

        FILE *fp = wp;

        if ( !wp || !fmt )

        {

                return -1;

        }

        va_start ( args, fmt );

        vsnprintf ( buf, sizeof ( buf ), fmt, args );

        ret = fprintf ( fp, "%s", buf );

        va_end ( args );

        fflush ( wp );

        return ret;

}

int

main ( int argc, char *argv[] )

{

        FILE *wp = fopen("./tmp", "ab+");

        websWrite (wp, "%s","hello,world!\n");

        if (wp == NULL)

        {

                  fprintf( stderr, "open file error(%d)\n", errno );

                  return ;

        }

        fclose(wp);

        wp=fopen("./tmp", "r");

        char bufline[256];

        while (fgets(bufline, sizeof(bufline) - 1, wp) != NULL)//循环读取文件流的每一件

        {

                printf("%s\n",bufline);

        }

        fclose(wp);

    exit(0);

} 

va_listva_startva_argva_end的原理与使用

void test_va(const char *name,...)

{

    va_list list;

    if (!name)

    {

        return NULL;

    }

    va_start ( list, name );

    char *arg = NULL;

    char buf[128];

    vsnprintf ( buf, sizeof ( buf ), name, list );

    printf("%s\n",buf);

/*

    while (1)

    {

        arg = va_arg( list, char *);

        if ( strcmp( arg, "") == 0 )

        break;

        printf("%s\n", arg);

    }

    while ((arg = va_arg(list, char *)) != NULL)

    {

        printf("arg=%s\n",arg);

    }

    */

    va_end(list);

}

 

void arg_cnt(int cnt, ...)

{

     int value="0";

     int i="0";

     int arg_cnt=cnt;

     va_list arg_ptr;

     va_start(arg_ptr, cnt);

     for(i = 0; i < cnt; i++)

    {

    value = va_arg(arg_ptr,int);

    printf("value%d=%d\n", i+1, value);

    }

}

int main ( int argc, char *argv[] )

{

    test_va("%s %s %s", "test","hello","world");

    arg_cnt(4,1,2,3,4);

    exit(0);

} 

AT&T汇编

lxq@lxq:~/tmp$ as -o hw.o hw.s

lxq@lxq:~/tmp$ ld -o hw hw.o 

dd-wrt

http://www.dd-wrt.com/wiki/index.php/Building_From_Source#Building_DD-WRT_From_Source

svn co svn://svn.dd-wrt.com/DD-WRT .

DGB调试

d   空格加断点num,是去断点的,c是跳到下一个断点

进入子进程调试

set follow-fork-mode child

参考资料:

http://www.ibm.com/developerworks/cn/linux/l-cn-gdbmp/index.html


只有注册用户登录后才能发表评论。


网站导航: