2006年06月14日

这两天闲着没事,看了点css的资料,算是扫一下盲了。

高手做出的东西是漂亮,看看 css Zen Gardendodo的博客 就能体会其魅力了。

还有更好玩的:css House 和另一个 css House

2005年12月29日

老大可能看了我写的那些模块,今天过来批评我,说我的数据不能没有意义。
我承认,我在写的时候,测试程序功能时,测试数据只是和数据库中所规定的类型相匹配了,具体数据意义不在我的考虑范围。比如一本书名,我也会输:111;比如作者名,我会输入:aaa来看程序功能执行了没。我觉得如果一边在做一边还正经的写数据:《精通C#数据库开发》、王华杰  李律松 孙一波 ,那我光写测试数据就半天了。有时一个错误,可能测试10遍、20遍,那我要写10遍、20遍的正经数据,那我还活吗?
这个要求我难以接受,我保留我的意见。
在老大看来,因为他要随时发出我们的进行中版本给客户看,当他们看到111、aaa这些数据时会搞糊涂,所以要我在写的时候用正经数据。哎,他不在写程序,不知道我的苦啊~
我想,在开发阶段,没有必要每个版本都是用户能够理解的。如果做到每个版本用户都理解,那用户要付额外的费用(那是我额外的辛勤劳动啊)给我,哈哈!我觉得在开发阶段,客户不懂111和aaa不怕,我们有人可以去解释,反正肯定有人在讲解的,那就多讲一点嘛。
其实还有个办法,专门建2个数据库,都给在开发的系统用。一个用正经数据,给客户看;一个用来给程序员用。那多好!不过不太现实,在开发过程中,难免会要改动数据库的数据结构。维护一个库就够烦了,再来一个就不用说了。
总之,在开发阶段如果要方便客户,那自然就增大了软件开发的成本了。我不爽

2005年07月10日


今天短学期结束

       关于这次短学期,我有些想不通,我们是软件工程专业的,短学期名为“软件实习”,怎么就是做个人网站呢?本来也许我不会去学网站制作方面的东西的,虽然我知道,网络是将来生活的很大一部分。我觉得,正因为网络太普及,什么鸟都有,加你一个不多,少你一个不少。在我看来,我在这方面发展前途不乐观,所以我舍弃了它。结果,我还是在这个短学期碰到了。
        可能小型网站开发过程可以是软件开发过程的一个缩影吧。老师选这个角度,一来叫我们了解网站设计,二来,也是对项目过程的一次实习。可能于此来说,"软件实习"之名还是可冠的。

        我做的网站是《Gundam SEED》主题的站点。有空整理一下,把有用的东西发上来。

        先看看我的页面吧:

头页

        首页:

首页

2005年07月01日
c语言实现wc命令简单功能
 
程序功能简述

c语言实现了linux环境下的wc命令的功能

用法:mywc [选项]…[文件]…

打印出每个文件的字节数,词数,行数,如果文件数超过1个,还会打印出一行总计。当[文件] 缺省时,wc从标准输入设备(终端)读取,此时,[Esc] 键停止输入。

选项:

-c, –bytes 打印字节个数

-m, –chars 打印字母个数

-l, –lines 打印行数

-L, –max-line-length 打印最长行的字节数

-w, –words 打印词数

    –help 打印帮助信息并退出

    –version 打印版本信息并退出

 

编程要点

       1.对参数的出现与否设置标志量(flags)。

       2.在数的时候,明白何时字节数增1,何时字符数增1,何时行数增1,何时词数增1,最长行如何统计,在文件数大于1时,如何统计总合。

       3.需要先读取所有参数,然后再对参数种出现的文件进行统计,如果没有提供文件,则从终端读取并统计。

       4.有良好的用户帮助

 

实现结果:(mywc与系统wc对比)

 

 

[gary@localhost gary]$ ./mywc test

        6       7       23      test

 

[gary@localhost gary]$ ./mywc a b

        154     328     4224    a

        56      55      156     b

        210     383     4380    general

 

[gary@localhost gary]$ ./mywc -w b

        55      b

 

[gary@localhost gary]$ ./mywc -w b -c

        55      156     b

 

[gary@localhost gary]$ ./mywc -w b c -c

        55      156     b

        32      87      c

        87      243     general

 

[gary@localhost gary]$ ./mywc –help

usage: mywc [option]…[FILE]…

Print byte,word,and newline counts for each FILE,and a total line if more than one FILE is specified. With on File,read standard input, press key [Esc] to end inputting

        -c, –bytes     Print the byte counts.

        -m, –chars     Print the character counts.

        -l, –lines     Print the newline counts.

        -L, –max-line-length   Print the length of the longest line.

        -w, –words     Print the word counts.

            –help      Print this usage message and then exit

            –version   Print version information and then exit.

 

Report bugs to <gary@mail.hdss.org>.

 

[gary@localhost gary]$ ./mywc -L b -w

        55      2       b

 

[gary@localhost gary]$ ./mywc c -c –words

        32      87      c

 

[gary@localhost gary]$ ./mywc c -L -c –words

        32      87      2       c

 

[gary@localhost gary]$ ./mywc test -L -c –words

        7       23      6       test

 

[gary@localhost gary]$ ./mywc test b c -L -c –words

        7       23      6       test

        55      156     2       b

        32      87      2       c

        94      266     6       general

 

[gary@localhost gary]$ ./mywc

asdf

 g g

 

aaabc

^[

        4       4       17

 

[gary@localhost gary]$ ./mywc -L -wl

asdf

 g g

the longest line

^[

        3       6       16

 

[gary@localhost gary]$ ./mywc -w -

asdf sdf

sdf dsf

^[

        4

 

[gary@localhost gary]$ ./mywc -b b

mywc: wrong option -"b"

try "mywc –help" to get more infomations

 

[gary@localhost gary]$ ./mywc –hhelp

mywc: can’t identify option "–hhelp"

try "mywc –help" to get more infomations

 

[gary@localhost gary]$ cat >noC

[gary@localhost gary]$ ./mywc noC

        0       0       0       noC

 

 

[gary@localhost gary]$ wc test

      6       7      23 test

 

[gary@localhost gary]$ wc a b

    154     328    4224 a

     56      55     156 b

210     383    4380 总用量

 

[gary@localhost gary]$ wc -w b

     55 b

 

[gary@localhost gary]$ wc -w b -c

55               156 b

 

[gary@localhost gary]$ wc -w b c -c

     55     156 b

     32      87 c

     87     243 总用量

 

[gary@localhost gary]$ wc –help

用法:wc [选项]… [文件]…

Print byte, word, and newline counts for each FILE, and a total line if

more than one FILE is specified.  With no FILE, or when FILE is -,

read standard input.

  -c, –bytes            print the byte counts

  -m, –chars            print the character counts

  -l, –lines            print the newline counts

  -L, –max-line-length  print the length of the longest line

  -w, –words            print the word counts

      –help     显示此帮助信息并离开

      –version  显示版本信息并离开

 

Report bugs to <bug-coreutils@gnu.org>.

 

 

[gary@localhost gary]$ wc -L b -w

55                     2 b

 

[gary@localhost gary]$ wc c -c –words

32                  87 c

 

[gary@localhost gary]$ wc c -L -c –words

     32      87       2 c

 

[gary@localhost gary]$ wc test -L -c –words

      7      23       6 test

 

[gary@localhost gary]$ wc test b c -L -c –words

      7      23       6 test

     55     156       2 b

     32      87       2 c

     94     266       6 总用量

 

[gary@localhost gary]$ wc

asdf

 g g

 

aaabc

      4       4      17

 

 

[gary@localhost gary]$ wc -L -wl

asdf

 g g

the longest line

      3       6      16

 

 

[gary@localhost gary]$ wc -w -

asdf sdf

sdf dsf

      4 –

 

 

[gary@localhost gary]$ wc -b b

wc:无效选项 — b

请尝试执行‘wc –help’来获取更多信息。

 

[gary@localhost gary]$ wc –hhelp

wc:无法识别的选项“–hhelp

请尝试执行‘wc –help’来获取更多信息。

 

[gary@localhost gary]$ cat >noC

[gary@localhost gary]$ wc noC

      0       0       0 noC

 

 

[gary@localhost gary]$ ./mywc test

        6       7       23      test

 

[gary@localhost gary]$ ./mywc a b

        154     328     4224    a

        56      55      156     b

        210     383     4380    general

 

[gary@localhost gary]$ ./mywc -w b

        55      b

 

[gary@localhost gary]$ ./mywc -w b -c

        55      156     b

 

[gary@localhost gary]$ ./mywc -w b c -c

        55      156     b

        32      87      c

        87      243     general

 

[gary@localhost gary]$ ./mywc –help

usage: mywc [option]…[FILE]…

Print byte,word,and newline counts for each FILE,and a total line if more than one FILE is specified. With on File,read standard input, press key [Esc] to end inputting

        -c, –bytes     Print the byte counts.

        -m, –chars     Print the character counts.

        -l, –lines     Print the newline counts.

        -L, –max-line-length   Print the length of the longest line.

        -w, –words     Print the word counts.

            –help      Print this usage message and then exit

            –version   Print version information and then exit.

 

Report bugs to <gary@mail.hdss.org>.

 

[gary@localhost gary]$ ./mywc -L b -w

        55      2       b

 

[gary@localhost gary]$ ./mywc c -c –words

        32      87      c

 

[gary@localhost gary]$ ./mywc c -L -c –words

        32      87      2       c

 

[gary@localhost gary]$ ./mywc test -L -c –words

        7       23      6       test

 

[gary@localhost gary]$ ./mywc test b c -L -c –words

        7       23      6       test

        55      156     2       b

        32      87      2       c

        94      266     6       general

 

[gary@localhost gary]$ ./mywc

asdf

 g g

 

aaabc

^[

        4       4       17

 

[gary@localhost gary]$ ./mywc -L -wl

asdf

 g g

the longest line

^[

        3       6       16

 

[gary@localhost gary]$ ./mywc -w -

asdf sdf

sdf dsf

^[

        4

 

[gary@localhost gary]$ ./mywc -b b

mywc: wrong option -"b"

try "mywc –help" to get more infomations

 

[gary@localhost gary]$ ./mywc –hhelp

mywc: can’t identify option "–hhelp"

try "mywc –help" to get more infomations

 

[gary@localhost gary]$ cat >noC

[gary@localhost gary]$ ./mywc noC

        0       0       0       noC

 

 

[gary@localhost gary]$ wc test

      6       7      23 test

 

[gary@localhost gary]$ wc a b

    154     328    4224 a

     56      55     156 b

210     383    4380 总用量

 

[gary@localhost gary]$ wc -w b

     55 b

 

[gary@localhost gary]$ wc -w b -c

55               156 b

 

[gary@localhost gary]$ wc -w b c -c

     55     156 b

     32      87 c

     87     243 总用量

 

[gary@localhost gary]$ wc –help

用法:wc [选项]… [文件]…

Print byte, word, and newline counts for each FILE, and a total line if

more than one FILE is specified.  With no FILE, or when FILE is -,

read standard input.

  -c, –bytes            print the byte counts

  -m, –chars            print the character counts

  -l, –lines            print the newline counts

  -L, –max-line-length  print the length of the longest line

  -w, –words            print the word counts

      –help     显示此帮助信息并离开

      –version  显示版本信息并离开

 

Report bugs to <bug-coreutils@gnu.org>.

 

 

[gary@localhost gary]$ wc -L b -w

55                     2 b

 

[gary@localhost gary]$ wc c -c –words

32                  87 c

 

[gary@localhost gary]$ wc c -L -c –words

     32      87       2 c

 

[gary@localhost gary]$ wc test -L -c –words

      7      23       6 test

 

[gary@localhost gary]$ wc test b c -L -c –words

      7      23       6 test

     55     156       2 b

     32      87       2 c

     94     266       6 总用量

 

[gary@localhost gary]$ wc

asdf

 g g

 

aaabc

      4       4      17

 

 

[gary@localhost gary]$ wc -L -wl

asdf

 g g

the longest line

      3       6      16

 

 

[gary@localhost gary]$ wc -w -

asdf sdf

sdf dsf

      4 –

 

 

[gary@localhost gary]$ wc -b b

wc:无效选项 — b

请尝试执行‘wc –help’来获取更多信息。

 

[gary@localhost gary]$ wc –hhelp

wc:无法识别的选项“–hhelp

请尝试执行‘wc –help’来获取更多信息。

 

[gary@localhost gary]$ cat >noC

[gary@localhost gary]$ wc noC

      0       0       0 noC

 

程序流程图:


下面是对中间“读入参数设置flags”和“统计输出”分别细化的流程图:

.

.

.

.

(附)程序代码


///////////////////////////

//wc 命令功能c语言程序实现

//02101231 俞健伟

//

#include <ctype.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

void showhelp(void); //显示帮助

void showversion(void); //显示版本

void showerr_s(char * s); //–string选项错误

void showerr_c(char c); //-char选项错误

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

{

     FILE *fp;

     int  nOver = 1;//屏幕输入状态

     int cflag = 0, mflag = 0, lflag = 0, Lflag = 0, wflag = 0;//统计对象标志

     int i = 0, j = 0, k = 0;

     char curChar,preChar;

     long noLines = 0,noWords = 0,noCharacters = 0,noBytes = 0,nomaxlen = 0;

     long tnoLines = 0,tnoWords = 0,tnoCharacters = 0,tnoBytes = 0,tnomaxlen = 0;//全局用量

     long lentemp = 0;

     char * filename[30];//mywc带的文件名

 

     for(i = 1; i<argc; i++)//读入所有参数,if argc == 1,not go into for{}

     {

         if(argv[i][0] == ‘-’)//is options

         {

              if(argv[i][1] == ‘-’)

              {

                   if(strcmp(argv[i],"–help")==0)

                   {

                       showhelp();

                       exit(0);

                   }

                   else if(strcmp(argv[i],"–version")==0)

                   {

                       showversion();

                       exit(0);

                   }

                   else if(strcmp(argv[i],"–bytes")==0)

                       cflag = 1;

                   else if(strcmp(argv[i],"–chars")==0)

                       mflag = 1;

                   else if(strcmp(argv[i],"–lines")==0)

                       lflag = 1;

                   else if(strcmp(argv[i],"–words")==0)

                       wflag = 1;

                   else if(strcmp(argv[i],"–max-line-length")==0)

                       Lflag = 1;

                   else

                   {

                       showerr_s(argv[i]);

                       exit(1);

                   }

              }

              else//short options

              {

                   for(j = 1; j<strlen(argv[i]); j++)

                   {

                       switch(argv[i][j])

                       {

                       case ‘c’:

                            cflag = 1;

                            break;

                       case ‘m’:

                            mflag = 1;

                            break;

                       case ‘l’:

                            lflag = 1;

                            break;

                       case ‘L’:

                            Lflag = 1;

                            break;

                       case ‘w’:

                            wflag = 1;

                            break;

                       default:

                            {

                                 showerr_c(argv[i][j]);

                                 exit(1);

                            }

                       }

                   }

              }

         }

         else//不是选项

         {//文件名处理

              filename[k] = argv[i];

              k++;

         }

     }//读完mywc所带所有参数

 

     if(k == 0)//不带文件名参数,统计屏幕输入

     {

         preChar = 0;

         curChar = getchar();

         noLines = 0;

         while(nOver)

         {

              switch(curChar)

              {

              case ‘\t’:

              case ‘ ‘:

                   if(preChar!=’ ‘&&preChar!=’\t’&&preChar!=’\n’&&preChar!=0)

                       noWords++;

                   noBytes++;

                   lentemp++;

                   break;

              case ‘\n’:

                   if(preChar!=’ ‘&&preChar!=’\t’&&preChar!=’\n’&&preChar!=0)

                       noWords++;

                   noLines++;

                   noBytes++;

                   if(lentemp>nomaxlen)

                       nomaxlen = lentemp;

                   lentemp = 0;

                   break;

              case 4:            //Ctrl+d, end of input

              case 0:            //Can’t be catched??? 

              case 27:      //Esc, end of input

                   nOver = 0;

                   if(preChar!=’ ‘&&preChar!=’\t’&&preChar!=’\n’&&preChar!=0)

                       noWords++;

                   break;

              default:

                   noBytes++;

                   lentemp++;

                   if(isalpha(curChar))

                       noCharacters++;

              }

              preChar = curChar;

              curChar = getchar();

         }

         //根据flags输出

         if(cflag == 0 && lflag == 0 && wflag == 0 && mflag == 0 && Lflag == 0)

              printf("\t%d\t%d\t%d\n",noLines,noWords,noBytes);

         else

         {

              if(lflag == 1)

                   printf("\t%d",noLines);

              if(wflag == 1)

                   printf("\t%d",noWords);

              if(cflag == 1)

                   printf("\t%d",noBytes);

              if(mflag == 1)

                   printf("\t%d",noCharacters);

              if(Lflag == 1)

                   printf("\t%d",nomaxlen);

              printf("\n");

         }

     }

     else//分别对每个文件进行统计,如果2个以上文件,计算全局用量general

     {

         for(j = 0; j<k; j++)

         {

              noLines = 0;

              noWords = 0;

              noCharacters = 0;

              noBytes = 0;

              if( (fp = fopen(filename[j],"r"))==NULL )

              {

                   printf("mywc: %s: not exists or other errors occur\n",filename[j]);

                   continue;

              }

              preChar = 0;

              while((curChar = fgetc(fp))!=EOF)

              {

                   switch(curChar)

                   {

                   case ‘\t’:

                   case ‘ ‘:

                       if(preChar!=’ ‘&&preChar!=’\t’&&preChar!=’\n’&&preChar!=0)

                            noWords++;

                       noBytes++;

                       lentemp++;

                       break;

                   case ‘\n’:

                       if(preChar!=’ ‘&&preChar!=’\t’&&preChar!=’\n’&&preChar!=0)

                            noWords++;

                       noLines++;

                       noBytes++;

 

                       if(lentemp>nomaxlen)

                       {

                            nomaxlen = lentemp;

                            if(nomaxlen>tnomaxlen)

                                 tnomaxlen = nomaxlen;

                       }

                       lentemp = 0;

                       break;

                   default:

                       noBytes++;

                       lentemp++;

                       if(isalpha(curChar))

                            noCharacters++;

                   }

                   preChar = curChar;

              }

         //读到EOF出循环后,判断

              if(preChar!=’ ‘&&preChar!=’\t’&&preChar!=’\n’&&preChar!=0)

              {

                   noWords++;

                   if(lentemp>nomaxlen)

                   {

                       nomaxlen = lentemp;

                       if(nomaxlen>tnomaxlen)

                            tnomaxlen = nomaxlen;

                   }

              }

              fclose(fp);

              //根据标志输出

              if(cflag == 0 && lflag == 0 && wflag == 0 && mflag == 0 && Lflag == 0)

                   printf("\t%d\t%d\t%d\t%s\n",noLines,noWords,noBytes,filename[j]);

              else

              {

                   if(lflag == 1)

                       printf("\t%d",noLines);

                   if(wflag == 1)

                       printf("\t%d",noWords);

                   if(cflag == 1)

                       printf("\t%d",noBytes);

                   if(mflag == 1)

                       printf("\t%d",noCharacters);

                   if(Lflag == 1)

                       printf("\t%d",nomaxlen);

                   printf("\t%s\n",filename[j]);

              }

         tnoLines += noLines;

         tnoWords += noWords;

         tnoCharacters += noCharacters;

         tnoBytes += noBytes;

         nomaxlen = 0;

         }

     }

     if(k>1)//文件数大于1

     {

         if(cflag == 0 && lflag == 0 && wflag == 0 && mflag == 0 && Lflag == 0)//use these as well

              printf("\t%d\t%d\t%d\tgeneral\n",tnoLines,tnoWords,tnoBytes);

         else

         {

              if(lflag == 1)

                   printf("\t%d",tnoLines);

              if(wflag == 1)

                   printf("\t%d",tnoWords);

              if(cflag == 1)

                   printf("\t%d",tnoBytes);

              if(mflag == 1)

                   printf("\t%d",tnoCharacters);

              if(Lflag == 1)

                   printf("\t%d",tnomaxlen);

              printf("\tgeneral\n");

         }

     }

     return 0;

}

 

/////////////////////

//showhelp

//

void showhelp(void)

{

     printf("usage: mywc [option]…[FILE]…\n");

     printf("Print byte,word,and newline counts for each FILE,and a total line if more than one FILE is specified. With on File,read standard input, press key [Esc] to end inputting\n");

     printf("\t-c, –bytes\tPrint the byte counts.\n");

     printf("\t-m, –chars\tPrint the character counts.\n");

     printf("\t-l, –lines\tPrint the newline counts.\n");

     printf("\t-L, –max-line-length\tPrint the length of the longest line.\n");

     printf("\t-w, –words\tPrint the word counts.\n");

     printf("\t    –help\tPrint this usage message and then exit\n");

     printf("\t    –version\tPrint version information and then exit.\n");

     printf("\nReport bugs to <gary@mail.hdss.org>.\n");

}

 

/////////////////////

//showversion

//

void showversion(void)

{

     printf("mywc by imitating wc in Redhat 9.0\n");

     printf("Written by Gary(02101231).\n");

     printf("This version is free.\n");

}

 

/////////////////////

//showerr_s

//

void showerr_s(char * s)

{

     printf("mywc: can’t identify option \"%s\"\n",s);

     printf("try \"mywc –help\" to get more infomations\n");

}

 

/////////////////////

//showerr_c

//

void showerr_c(char c)

{

     printf("mywc: wrong option -\"%c\"\n",c);

     printf("try \"mywc –help\" to get more infomations\n");

}

 

c语言实现more命令简单功能
 
程序功能简述
        利用linux下的curses库,用c语言实现了linux环境下的more命令的功能子集,能够在24*80的终端(窗口)屏幕全屏翻屏。
        键入mmore filename 后(mMore.c源文件编译成可执行文件mmore),mmore先初始化自己的窗口,然后分屏显示文件内容。
        键盘按键:
                n/N往下翻屏(无需回车,直接接收,屏幕不显示所按键对应字符)
                b/B 往回翻屏(无需回车,直接接收,屏幕不显示所按键对应字符)
                q/Q 退出more并关闭窗口,回到终端。(无需回车,直接接收,屏幕不显示所按键对应字符)
 
编程要点
       1.需要知道curses库中常用函数,会使用这些函数。
       2.文件需要读到缓冲(buffer)中,以方便频繁换屏显示时读取所需内容。
       3.建立数据结构,存储每屏显示开始点在buffer中的确切位置,当需显示该屏内容时,及时找到起始点读取并显示。
       4.处理长于80byie的行恰好位于前后两屏显示的中间时的情况。(比如一行有90字节,则前80字节在一屏结束行显示,后10字节在接下去一屏的开始行显示。)
       5.编译时不要忘记连接ncurses库。(我用:gcc mMore.c –o mmore –l ncurses)
 
实现结果
程序流程图

(附)程序代码


///////////////////////////////

///more 功能的c语言实现

///02101231 Gary

///

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <curses.h>

 

#define SCREEN_LINES 22     //show (0->SCREEN_LINES)SCREEN_LINES+1 lines

int getoneline(char * a);   //得到一行的长度

 

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

{

     FILE *fp;

     char filename[20];

     long filelength, pointer;

     char *buffer;          //文件缓冲

     char CLine[512], key;

     int linenum, curline;

     int i,len, *points,p;

     int curX,curY, preY;        //光标在屏幕中的坐标(Y为行,X为列)

 

     if(argc < 2)

     {

         fprintf(stderr, "usage: %s filename\n",argv[0]);

         exit(1);

     }

 

     strcpy(filename, argv[1]);

 

     if((fp = fopen(filename, "r")) == NULL)   //打开文件

     {

         fprintf(stderr,"file %s can not be opened!\n", filename);

         exit(2);

     }

 

     filelength = 0L;

     fseek(fp, 0L, SEEK_END);

     filelength = ftell(fp);              //得到文件长度

 

     if((buffer = (char*)malloc(filelength+1)) == NULL)

     {

         fprintf(stderr,"not enough memery for store the file!\n");

         exit(3);

     }

 

     memset(buffer,0×00,filelength+1);

 

     fseek(fp, 0l, SEEK_SET);

 

     linenum = 0;

     pointer = 0L;

 

     while(!feof(fp))   //文件进缓冲

     {

         memset(CLine,0×00,512);

         fgets(CLine,512,fp);        //Cline 可能越界,不过前面memset0了,因该可以。

         len = strlen(CLine);

         strncat(buffer + pointer, CLine, strlen(CLine));

         pointer += strlen(CLine);

         if( len/80>0 && len%80>0 )

              linenum += len/80+1;

         else if(len>80 && len%80==0)

              linenum += len/80;

         else

              linenum++;

     }

 

     for(i = 0; i<filelength+1; i++)      //有些文件的行末不光一个‘\n’,而以"\r\n"结束,去‘\r’

     {                                    //否则addstr(str),或printw(format,str)对它不能正常显示

         if(*(buffer+i)==’\r’&&*(buffer+i+1)==’\n’)

              *(buffer+i)=’ ‘;

     }

 

     if( (points = (int *)malloc((linenum/SCREEN_LINES +1)*sizeof(int))) == NULL )//每屏始点记录数组

     {

         fprintf(stderr,"not enough memery!");

         exit(3);

     }

 

     pointer = 0l;

     curline = 0;

     p = -1;

 

     curX = curY = preY = 0;

     initscr();         //初始化窗口

     cbreak();     //除了 DELETE CTRL 等仍被视为特殊控制字元外一切输入的字元将立刻被一一读取

     noecho();     //屏幕上不显示在终端上

     intrflush(stdscr,FALSE);    //??不是很清楚。。。

     keypad(stdscr,TRUE);        //可以使用键盘上的一些特殊字元, 如上下左右等方向键

     refresh();         //首次使用,清屏

     while(1)

     {

         move(curY,curX);

         if(curline == 0)

         {

              //record the point that may return;

              points[++p] = pointer;

         }

         len = getoneline(buffer + pointer);

         memset(CLine,0×00,512);

         strncpy(CLine,buffer + pointer, len);

         printw("%s",CLine);         //在窗口屏幕中输出CLine

         preY = curY;

         getyx(stdscr,curY,curX);//得到当前的光标坐标

         if(curY>SCREEN_LINES)  //长行跨屏显示时,pointer记录下一屏的起始点的正确地点

         {

              if(len<=(SCREEN_LINES+1-preY)*80)

                   pointer += len;

              else

                   pointer += (SCREEN_LINES+1 – preY )*80;

         }

         else                   //一般情况下的pointer

              pointer += len;

         curline = curY;

         if(curY>SCREEN_LINES || p*(SCREEN_LINES+1)+curY+1>=linenum )//屏幕显示满,或文件终结

         {

              mvprintw(SCREEN_LINES+1,0,"                                                                                ");

              attron(A_REVERSE);

              mvprintw(SCREEN_LINES+1,0,"  —This is Gary(02101231)’s mmore!—  [ b/B: back, n/N: next, q/Q: quit ]   ");

              attroff(A_REVERSE);

              move(SCREEN_LINES+1,79);

              refresh();         //显示屏幕给用户看

wait:

              key = getch();     //得到按键命令[ b/B: back, n/N: next, q/Q: quit ]

              switch(key)

              {

              case ‘b’:

              case ‘B’:

                   if(p>0)       //得到需要的起始点,points数组中已存

                   {

                       pointer = points[--p];//point at SCREEN_LINES or n lines before

                       p–;

                   }

                   else

                   {

                       pointer = 0;

                       p–;

                   }

                   curY=curX=0;

                   curline = 0;

                   clear();      //清屏

                   break;

              case ‘n’:

              case ‘N’:

                   if(p*(SCREEN_LINES+1)+curY+1 >= linenum)//文件终结,不能下翻页

                   {

                       goto wait;

                   }

                   curY=curX=0;

                   curline = 0;

                   clear();      //清屏

                   break;

              case ‘q’:

              case ‘Q’:

                   endwin();     //结束,关闭窗口,回到终端。

                   exit(0);

                   break;

              default :

                   goto wait;

                   break;

              }

         }

     }

 

     endwin();

     fclose(fp);

     free(points);

 

     return 0;

}

 

////////////////////////////

///getoneline

///

int getoneline(char * a)

{

     int lenofline = 0;

     while(*a != ‘\n’ && *a != ‘\0′)

     {

         lenofline++;

         a++;

     }

     if(*a == ‘\n’)

         lenofline++;

     return lenofline;

}

2005年06月08日

同学写了一个vb程序,说出现栈溢出。他查不错误,叫我过去看看
我看了半天,也不知道错在哪里。

是什么东西不停地在把数据写入栈呢?死循环吗?看了一下,程序更本没循环结构。函数调用死循环吗?也没有。断点后单步执行了一下,发现程序在一个属性的set里不出来了,直到栈溢出而发生异常。

看了一下,他定义的成员是整型的 aINC,但是属性INC中set 时,语句为INC = Value。我开始看的时候没注意到这里赋值语句里用了属性名。属性赋值时调用属性的set,但是set中继续调用set,如此循环下去了。怪不得它一直不停地在这里做,不出来了。改成aINC = Value就OK了。

不过感觉vb编译有些奇怪,不知道它是怎么编译的,程序根本没有执行到要赋值的语句,在编译时就栈溢出了。编译时对函数调用关系怎么搞的啊?不清楚

上个周末把组件作业做了,我做的是一个菜单项控件。多亏了有本参考书(vb.net彻底研究》)有一个菜单组件的范例,否则光靠我查msdn或是上网搜(我搜了n遍,没结果),我估计我是画不出控件来的。老师说很有新意,我感觉很惭愧,我只是不小心捡到一段我感兴趣的代码,小心看了一下,模仿做出来而已。惭愧。。。

感觉GDI这个东西确实很好玩,只是我不熟悉。

至于我真正自己做的一个针对RichTextBox控件的一个工具控件,老师几乎都没看啊。55555555555555伤心中。。。

我把这两个东西结合起来,做了一个文本编辑器。但是使我超级郁闷的是save的时候达不到我的要求啊。我看了很久msdnRichTextBoxSaveFile方法的介绍,就算存成RTF格式,还是不能把RichTextBox中带字体的格式保存。我知道这肯定是可以的,而且有方法,只是我没找到,或是我没想到。只好继续找方法了。。。

实现后界面如图:


界面

2005年06月01日

利用vb所提供的控件,做简单的图片浏览器

具体实现:

所用控件为:DriveDirFileimage

实现效果:


实现代码:

Option Explicit

 

 

Private Sub Dir1_Change()

    File1.Path = Dir1.Path

End Sub

 

 

Private Sub Drive1_Change()

    Dir1.Path = Drive1.Drive

End Sub

 

 

Private Sub File1_Click()

 

 

    Dim strFname As String

    If Right(Dir1.Path, 1) <> "\" Then

        strFname = Dir1.Path & "\" & File1.FileName

    Else

        strFname = Dir1.Path & File1.FileName

    End If

   

    Image1.Picture = LoadPicture(strFname)

   

End Sub

 

 

Private Sub Form_Load()

    Drive1.Drive = "c:"

    File1.Pattern = "*.bmp;*.jpeg;*.jpg;*.gif;*.ico"

End Sub