posts - 23, comments - 0, trackbacks - 0, articles - 3
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          家里學習總結

          Posted on 2010-07-16 19:58 beauty9235 閱讀(225) 評論(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_start、va_arg、va_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_arg、va_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


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 景德镇市| 荆州市| 甘洛县| 岳西县| 洛扎县| 石首市| 柘荣县| 田林县| 铁岭县| 麻栗坡县| 南丰县| 迁安市| 奉新县| 富顺县| 改则县| 涿州市| 喀喇沁旗| 海丰县| 岑巩县| 民勤县| 青河县| 江西省| 全椒县| 托克托县| 嫩江县| 新绛县| 马公市| 县级市| 同德县| 祁阳县| 洪湖市| 桐庐县| 屏边| 平昌县| 恩平市| 普兰县| 达拉特旗| 射洪县| 元江| 南通市| 佛冈县|