中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
« [1] [2] [3] »
作者:
标题: 523066680编辑区 上一主题 | 下一主题
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 16 楼』:  Delta2


#include <Conio.h>
#include <graphics.h>
#include <stdlib.h>
#define closegr closegraph
#define NDOT 3


typedef struct
{
   int a,b,x,y;
} DotInf;


void initgr(void) /* BGI初始化 */
{
  int gd = DETECT, gm = 0;
  registerbgidriver(EGAVGA_driver);
  initgraph(&gd, &gm, "");
}

void delta(DotInf dot[],int c)
{
   int i,j;
   setcolor(c);
     for (i=0;i<NDOT;i++)
     for (j=i+1;j<NDOT;j++)
     {line(dot[i].x,dot[i].y,dot[j].x,dot[j].y);}
}

int main(void)
{
  int i,j,whi=0,edotn=0;
  DotInf snk[NDOT];
  DotInf edot[10][NDOT];
   for (i=0;i<9;i++) for (j=0;j<NDOT-1;j++) {edot[i][j].x=edot[i][j].y=0;}

  initgr(); /* BGI初始化 */

  for (i=0;i<NDOT;i++) {
   snk[i].a=snk[i].b=snk[i].x=snk[i].y=200;
   edot[edotn][i].x=edot[edotn][i].y=200;
  }
  randomize();
  while (!kbhit())
  {
    if (edotn<9) edotn++; else edotn=0;
    if (whi<NDOT) whi++; else whi=0;
    for (i=0;i<400;i++) delay(15);
    if (edot[edotn][i].x!=0) delta(edot[edotn],0);
    delta(snk,2);

    for (i=0;i<NDOT;i++){
      if ((snk[i].x==snk[i].a)&&(snk[i].y==snk[i].b)){
         snk[i].a=rand()%600+1;
         snk[i].b=rand()%400+20;
      }
    }
    for (i=0;i<NDOT;i++){
    if (whi>i) continue;
       if (snk[i].x>snk[i].a)
         snk[i].x--;
       else if (snk[i].x<snk[i].a)
         snk[i].x++;
       else
       {
           if (snk[i].y>snk[i].b)
             snk[i].y--;
           else if (snk[i].y<snk[i].b)
             snk[i].y++;
       }

    edot[edotn][i].x=snk[i].x;
    edot[edotn][i].y=snk[i].y;

    }


  }

  getch();
  closegr(); /* 恢复TEXT屏幕模式 */
  return 0;
}




综合型编程论坛

我的作品索引
  
2009-8-23 07:19
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 17 楼』:  时间随机按位显示


@echo off
setlocal enabledelayedexpansion
mode con cols=25 lines=5
title %date%
set "str=xxxxxxxx"
:a
set t=%time:~0,8%
call :next
ping -n 3 127.1>nul
set "t=        "
call :next
goto :a

   :next
    for /l %%a in (0,1,7) do (set num%%a=%%a)
    set /a aa=8
    :aa
     set /a rand=%random%%%aa,aa-=1
     set /a x=num%rand%,xb=x+1
     set str=!str:~0,%x%!!t:~%x%,1!!str:~%xb%!
     set num%rand%=!num%aa%!
     ping -n 1 127.1>nul
     cls
     echo,   %str%
    if %aa% gtr 0 (goto :aa)
   goto :eof
[ Last edited by 523066680 on 2009-8-23 at 07:22 ]



综合型编程论坛

我的作品索引
  
2009-8-23 07:20
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 18 楼』:  

把一个自然数分解成  n个连续自然数。
@echo off
:a
set "inp="
set /p inp="input a number: "
set /a act=2,end=inp/2,inp*=10,the500=1,the001=1
:lp
set /a x=inp/act,xx=inp%%act,xxx=act%%2
if defined the%x:~-1%%xx%%xxx% (call :func %x:~-1%)
if %act% lss %end% (set /a act+=1 &goto :lp)
pause &goto :a

:func
set /a a=(x-%1)/10-(act-1)/2,b=(x+%1)/10+(act-1)/2
if %a% lss 0 (set /a end=0 &goto :eof)
for /l %%a in (%a%,1,%b%) do set /p= %%a<nul
echo,&echo, &goto :eof
组成的数中有负数的:
@echo off
:a
set /p inp="input a number: "
set /a act=2,end=inp/2,inp*=10,the500=1,the001=1
:lp
set /a x=inp/act,xx=inp%%act,xxx=act%%2
if defined the%x:~-1%%xx%%xxx% (call :func %x:~-1%)
if %act% lss %end% (set /a act+=1 &goto :lp)
pause &set "inp=" &goto :a

:func
set /a a=(x-%1)/10-(act-1)/2,b=(x+%1)/10+(act-1)/2
for /l %%a in (%a%,1,%b%) do set /p= %%a<nul
echo,&echo, &goto :eof
列出1000左右不能拆分位n个连续自然数的:
@echo off
set /a inp=0,the500=1,the001=1
:a
set /a inp+=1,act=2,end=inp/2,inp*=10,have=0
:lp
  set /a x=inp/act,xx=inp%%act,xxx=act%%2
  if defined the%x:~-1%%xx%%xxx% (set /a inp/=10 &goto :a)
  if %act% lss %end% (set /a act+=1 &goto :lp)
set /a inp/=10
echo,%inp%
if %inp% lss 1000 goto :a
pause




综合型编程论坛

我的作品索引
  
2009-9-3 09:11
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 19 楼』:  [TestCscript]ListErrLines


set wsx=createobject("wscript.shell")
if wscript.arguments.count = 0 then
  wsx.run "cmd /c cscript " &wscript.scriptname & " 1 &pause>nul"
  wscript.quit
end if

checkfile="test1.vbs"
argu=""
set start=wsx.exec("cscript " &checkfile &argu)
set errinfo=start.stderr
set echo=wscript.stdout

x=errinfo.readline

if x="" then
echo.writeline "No error information."
else
str=""
echo.writeline ""
t1=split(x,",")
tt1=split(t1(0),"(")
tt2=split(t1(1),")")
y=tt1(1) : x=tt2(0)
for i = 2 to x
   str=str & " "
next
echo.writeline "Filename: " & tt1(0)
echo.writeline "ErrInfo : " & tt2(1)
echo.writeline "(Lines = " &y &" , cols =" &x & ")"
echo.writeline str & "↓"

set readx=createobject("scripting.filesystemobject").opentextfile(checkfile,1)
for i = 2 to y
   readx.readline
next
echo.writeline readx.readline
if readx.atendofstream then
    echo.writeline "Check Info: End of line."
else
    for i = 1 to 4
      if readx.atendofstream = false then
         echo.writeline readx.readline
      end if
    next
end if
read.xclose
end if

echo.write vbcrlf &"Press any key to continue..."
echo.close
wscript.quit




综合型编程论坛

我的作品索引
  
2009-9-15 22:30
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 20 楼』:  

今天很无聊……
@echo off
setlocal enabledelayedexpansion
for /l %%a in (1,1,40) do (set spc=  !spc!)
set strx=%spc: =x%
for /l %%a in (1,1,20) do (set ln%%a=%spc%)
set /a a=-20
:a
set inp=%a:-=%
set /a n=inp*2,stra=(80-n)/2,la=(24-inp)/2,a+=2
for /l %%a in (1,1,1) do (ping -n 1 127.1>nul)
cls
for /l %%a in (1,1,%la%) do (echo, )
for /l %%a in (1,1,%inp%) do (echo,!spc:~-%stra%!!strx:~-%n%!)
if %a% geq 20 set a=-20
goto :a

   此帖被 +1 点积分    点击查看详情   
评分人:【 vsbat 分数: +1  时间:2009-12-10 15:27




综合型编程论坛

我的作品索引
  
2009-11-20 20:09
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 21 楼』:  [shell日记]read

[shell日记]read
文:523066680
今天第一篇。
算是一种笔记吧,就像流水帐一样
算不上分享,因为每个人都会经历自己探索的过程。

顺便学英语,就把原帮助一起拉上来

参数和对应实例:
-a array        assign the words read to sequential indices of the array
                    variable ARRAY, starting at zero   
把输入内容按分隔符(空格或者跳格之类)分配给数组,连续的空格也算为1个分割。
输入后,数组规格跟c语言一样,用var[n]的格式表示,下标从0开始,
直接echo $var 的效果等于echo ${var[0]}
当echo 数组带下标的时候,记得加{}表达,比如echo ${a[1]}
定义数组变量: read -a arr  就可以了;  read -a arr[1] 出错。
但是你直接 read arr[1] 是允许的,就是直接赋值数组某个元素嘛。

-d delim        continue until the first character of DELIM is read, rather
                    than newline
就是读取输入,直到某个字符出现为止,而不是转行结束。当然,“某个字符”不算进去。
测试结果:
1,  指定是某个字符后,回车也被读进去,而不会因回车结束
(嘿嘿,没试过该参数以回车字符结束,不会弄+多余)
2,  -dstr 不会到 str结束,是s结束,所以人家才说是character
3,  -dx str  ;# 转了n行+输入字符 ; echo $str 并不会把转行输出来
要echo "$str" 才会转行。

(以下不知道的都直接引用help内容)
-e  use Readline to obtain the line in an interactive shell
不知道,好像是默认的读取一行就结束?以后知道了补上

-i text    Use TEXT as the initial text for Readline

-n nchars        return after reading NCHARS characters rather than waiting
                    for a newline
                rather than 在这里指:而不是。
读取到了第N个字符就结束~ 而不是等待一个新的行。
结果按回车将提前结束了 [ 感觉没有-d 那么严,还说nchars]
感觉描述的不严密, 实际规则是{ 如果 转行||字符数为n ;则 结束 }
(这个参数的help一度让我以为rather than是或者的意思)

-p prompt  prompt就是提示的意思,就是先显示"prompt"字符串,在后面等待你输入。
                 有提示选项就不用另外echo提示啦。

-r                do not allow backslashes to escape any characters
             backslash 反斜杠 "\";
             escape    逃脱;在这里指:转义
             翻译:不允许反斜杠来转义任何字符。

-s                do not echo input coming from a terminal
             不显示正在从终端输入的字符。(就像输入密码时),
             说真的,想象不到-s跟这功能的联系,学它就像背书一样

-t timeout        time out and return failure if a complete line of input is
                    not read withint TIMEOUT seconds.  The value of the TMOUT
                    variable is the default timeout.  TIMEOUT may be a
                    fractional number.  If TIMEOUT is 0, read returns success only
                    if input is available on the specified file descriptor.  The
                    exit status is greater than 128 if the timeout is exceeded
             1.如果在 timeout 秒内一个还没写完(触发终止输入条件),就超时退出 + 命令会返回一个
             错误码。[不会真的提示错误,是返回错误代码。 echo $? ;我看到错误代号为 142]
             2.这句话没看出来,不过执行TMOUT=1, 命令行1秒后就退出了
             3.timeout 的值可以是一个分数[fractional number],当然并不是真的用分数表示法
             他是告诉你,可以使用一个非整数,比如 -t0.5  就是限制半秒内输入。
             4.如果设timeout为0,则仅当 从有效的特殊文件描述中输入 时返回成功。[看不出来]
             5.exceed 超出;如果超时,退出状态[退出代码]就大于128。
-u fd                read from file descriptor FD instead of the standard input
             不说了,都不知道fd是什么,相关资料:http://baike.baidu.com/view/1303430.htm
             “linux下,所有的操作都是对文件进行操作,而对文件的操作是利用文件描述符
              (file descriptor)来实现的。在源代码中,一般用fd作为文件描述符的标识。”


# 仍然不知道几个参数的含义,所以以后知道了会回来修改的…… #


终: read 后面不加变量名,会把值赋给REPLY这个变量,
但是,如果你给了一个新的变量名,REPLY不会同步更新。



+++++++++++++++++学点英语+++++++++++++
#1     -e        use Readline to obtain the line in an interactive shell
百度搜索:
obtain            获得;得到
实例: He failed to obtain a scholarship.  他没有获得奖学金。

interactive      互相作用的;交互式的

#2     -n nchars    return after reading NCHARS characters rather than waiting
            for a newline

rather than : 而不是

#3     -t timeout
                time out and return [failure] if a complete line of input is
                    not read withint TIMEOUT seconds.  The value of the TMOUT
                    variable is the default timeout.  TIMEOUT may be a
                    [fractional] number.  If TIMEOUT is 0, read returns success only
                    if input is available on the specified file descriptor.  The
                    exit status is greater than 128 if the timeout is [exceeded]

failure n. 失败
He was doomed to failure. 他注定失败

fractional 形容词:小量的;分数的

exceed  超过



综合型编程论坛

我的作品索引
  
2010-1-6 19:34
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 22 楼』:  

本来read -n1 就可以只读取一个字符,按键就下一句了。
我写了一个循环read -n1 的  就是按任意键继续重复这一操作,为了让循环等待我的确认。

结果 按下 键盘"右键"  一下子循环n次,  原来这些方向键等的,按一下就值好几个字符
害我一下循环n 次…… (变成某个键n次了吗 O_o)

所以再整个 `read -n9 -t0.1`  ,在read -n1 前面, 也就是:
在读取一个字符后,
0.1秒内,不管有没有9个字符,都吃掉他
(我以为-t0可以瞬间吃掉,结果发现还是有一个按键下来,出现的几个字符还是有时间差的,就0.1了)
#!/bin/bash

while true
do
  g++ -o wasdq -lglut wasdq.c
  ./wasdq
  echo "Press any key to continue"
  read -s -n1 REPLY
  read -t0.1 -n9
done
试了下,吃字符的话直接 read -t0.1  是不行的, 他只等待0.1秒 而不读取字符
(因为默认是以回车键来作输入结束)
照理说会造成 无限循环,而不等待,单这里只连续循环了几次。
差点忘了,原来是前面有个 read -n1  在每次循环中读取一个字符~。

同时感觉到了 -n 这个选项 来读取n个字符的时候,打破以 Enter 结束输入的限制。
-t -n 就是“或”限制了~   (超时)||(读取到n个字符的时候)  则 结束
=================================================================
改下变成 q 键退出的
#!/bin/bash

while true
do
  g++ -o wasdq -lglut wasdq.c
  ./wasdq
  echo "Press any key to continue"
  read -s -n1 REPLY
  read -t0.1 -n9 other
  if [ "$REPLY" == "q" ]; then exit ;fi
done
[ Last edited by 523066680 on 2010-1-24 at 22:14 ]



综合型编程论坛

我的作品索引
  
2010-1-24 21:46
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 23 楼』:  [批处理]备份目录系的更新

本来用xcopy就可以更新备份目录系到 我的移动硬盘了
但是xcopy只负责复制的,所以每次备份的时候有增无减

虽然可以先全部删除而后xcopy,这样节省代码,但复制时更消耗时间。

于是增加了一段代码,删除 源目录没有而备份目录有的东西
采用for 结合dir 遍历目录树,

判断如果是目录就 rd 目录系,如果是文件就 delete (判断句 if exist "%%a\" )
但是第一次的时候出了错,原因是:  

    有的主目录已经删除了,所以其下的目录系和文件也被删除了,
而dir出的目录系是不更新的,仍然会列出其子目录,就造成了子目录已经不存在
却还继续执行删除的错误。

所以在每个删除操作执行前又增加了一判断:该目标是否存在。

特性: 如果用于备份的目的磁盘不存在,会提前退出
如果成功执行,会生成删除文件的日志。
先删除,后xcopy
@echo off
rem code by 523066680@cn-dos.net
setlocal enabledelayedexpansion
set source=%~dp0
set dest=d:\烧录文件更新区

rem 源路径可以是自身路径,考虑到输入和%~dp0都可能出现末尾有\的情况,
rem 增加了判断及处理

if "%source:~-1%"=="\" (set source=%source:~0,-1%)
if "%dest:~-1%"=="\" (set dest=%dest:~0,-1%)

if not exist "%source%\" (
   echo 源[目录]不存在,按任意键退出
   pause>nul
   exit
)

echo 请确认: 源目录 %source%
echo 备份到 %dest%
if not exist "%dest%\" (
  echo 作为备份的目录%dest%  不存在,将尝试建立。
  (md "%dest%")||(
    echo 目标不能建立,可能是目标磁盘不存在,按任意键退出。
    pause>nul
    exit
  )
  goto :justcopy
)

type nul>DelFile.txt
type nul>DelFold.txt

echo _
echo 按任意键开始搜索+清理 "%dest%"中可能多出的文件或子文件夹
pause>nul
echo _

for /f "tokens=*" %%a in ('dir /a /s /b "%dest%"') do (
  set pathname=%%a
  set pathname=!pathname:%dest%\=!
  if exist "%%a" (
      if not exist %source%\!pathname! (
            if exist "%%a\" (
                 rd /s /q "%%a"
                 echo Remove directory : %%a>>DelFold.txt
            ) else (
                 del /f /s /a /q "%%a">>DelFile.txt
            )
      )
  )
)
echo 本次清理生成日志 DelFold.txt DelFile.txt
type "DelFold.txt" "Delfile.txt"

:justcopy
echo _
echo 按任意键继续开始XCOPY...
pause>nul
echo _
  if exist cut.txt (
    xcopy /s /d /c /h /exclude:cut.txt  "%source%" "%dest%"
  ) else (
    xcopy /s /d /c /h "%source%" "%dest%"
  )
echo 按任意键退出
pause>nul
exit
我知道有些软件可以实现,但是批处理的好处就在于可以自己实现一些细节操作,
比如 /exclude:cut.txt 参数,用来指定cut.txt文本中列出的文件名或者文件夹
不被拷贝。

[ Last edited by 523066680 on 2010-3-20 at 12:17 ]



综合型编程论坛

我的作品索引
  
2010-3-14 22:27
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 24 楼』:  


@echo off
setlocal enabledelayedexpansion
::为了减少判断+名字编号部分整齐(统一两位编号),文件个数不能大于99呢,即指定了01-99
::初步验证
if "%~1"=="" (
  echo 您没有拖入文件到我身上,于是第一个参数为空,按任意键拜拜~
  pause>nul
  exit
) else (
  if exist "%~1" (
    echo 拖放文件所在文件夹 "%~dp1"
    echo _
    set /p "inp=批量重命名之前,请指定名字前缀:"
    set /a n=1
    set "nx=000!n!"
    set "xformat=%~x1"
    set "xpath=%~dp1"
  ) else (echo 有参数但不对头,拜拜 &pause>nul &exit)
)

::如果%~1非空,且是存在的,才会到达这里
:main
if not "%~1"=="" (
   if exist "%~1" (
      echo 执行的操作: ren "%~nx1" "!inp!!n!%~x1%#"
      ren "%~1" "!inp!!nx:~-2!%~x1%#"
      set /a n+=1
      set nx=000!n!
   ) else (echo "%~1" is not exist)
   shift /1
   goto :main
) else (
   echo 现在还原格式 ren "%xpath%*%xformat%#" "*%xformat%"
   ren "%xpath%*%xformat%#" "*%xformat%"
   pause
   exit
)




综合型编程论坛

我的作品索引
  
2010-4-13 11:14
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
yonghu111
初级用户





积分 90
发帖 57
注册 2010-4-12
状态 离线
『第 25 楼』:  

感谢分享啦啊!!

2010-4-13 15:30
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 26 楼』:  让OPENGL通过读取脚本绘图

读取脚本,并可以通过向脚本a.x  追加指令,继续描点着色,观察

着是雏形,只识别三道指令:
color red,green,blue
point x,y,z
sleep time
/* Directscript  Reader , code by 523066680, 20100522 */

#include <stdio.h>
#include <GL/glut.h>
#include <stdlib.h>

#define xpix 500
#define ypix 500

int winid;
float deepa=-1.0,deepb=1.0;

FILE *openx;



void display(void)
{
   static int clear=0;
   if (clear==0) { glClear(GL_COLOR_BUFFER_BIT); clear=1; }
   glutSwapBuffers();
}


void reshape(int wx,int wy)
{
   glViewport(0,0,wx,wy);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0,xpix,0.0,ypix,1.0,-1.0);
   glMatrixMode(GL_MODELVIEW);
}

void hitkey(unsigned char key,int mousex,int mousey)
{
    switch(key) {
      case 'q':
         glutDestroyWindow(winid);
         exit(0);
         break;
    }
}

void init(void)
{
   glClearColor(0.0,0.0,0.0,0.0);
   glPointSize(10);
   if ((openx=fopen("./a.x","r"))==NULL) {
       printf("File not exist !");
       exit(0);
   }

}


int main(int argc,char *argv[])
{
     void readfile(void);
/*CreateGraphWindow*/
     glutInit(&argc,argv);
     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
     glutInitWindowPosition(0,0);
     glutInitWindowSize(xpix,ypix);
     winid=glutCreateWindow("dict");
     init();
     glutReshapeFunc(reshape);
     glutKeyboardFunc(hitkey);
     glutDisplayFunc(display);
     glutIdleFunc(readfile);
     glutMainLoop();

     return 0;
}

void readfile(void)
{
    int code;
    enum command {color,sleep,point} cmd;
    float a,b,c;
    char str[10];
    int apology(char *tmpstr);
        fscanf(openx,"%s ",str);
        if (!feof(openx)) {
          code=apology(str);
          switch (code) {
          case color :
            printf("read color : ");
            fscanf(openx,"%f,%f,%f",&a,&b,&c);
            printf("%f %f %f\n",a,b,c);
            a=(int)a%100/100.0; b=(int)b%100/100.0; c=(int)c%100/100.0;
            glColor3f(a,b,c);
            glutPostRedisplay();
            break;
          case sleep :
             printf("sleep!\n");
             fscanf(openx,"%f",&a);
             _sleep((int)(600 * a));
             break;
          case point :
             fscanf(openx,"%f,%f,%f",&a,&b,&c);
             if (c<deepa || c>deepb) {printf("ERR : z=%f , out of your window\n",c); }
             glBegin(GL_POINTS);
              glVertex3f(a,b,c);
             glEnd();
             glutPostRedisplay();
             printf("vertex3f: %f %f %f\n",a,b,c);
             break;
          default :
             printf("No this command\n");
             break;
          }
        } //else {usleep(600000.0);printf("end of text stream\n");}
}

int apology(char *tmpstr)
{
    int i,fo=3;
    char str[][10]={"color","sleep","point"};
    for (i=0;i<fo;i++) {
      if (strcmp(str[i],tmpstr)==0) {break;}
    }
    return i;
}
windows 下dev-cpp (含了glut库 ) 编译通过。

以下批处理生成随机指令,观察效果
@echo off
set dict=project1.exe

type nul>a.x

set /a n=0
:a
  set /a x=(%random% %%20) * 11,y=(%random% %%20) *11 ,z=0
  set /a a=%random% %%100,b=%random% %%100,c=%random% %%100
  echo color %a%,%b%,%c%  >>a.x
  echo point %x%,%y%,%z%  >>a.x
  echo sleep 0.1  >>a.x
if %n% lss 80 (set /a n+=1 &goto a)
echo 在图形窗口按q 可退出
start %dict%
pause
exit
我认为会是一个还可以的开始~

[ Last edited by 523066680 on 2010-5-23 at 18:50 ]



综合型编程论坛

我的作品索引
  
2010-5-23 18:47
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 27 楼』:  个人写的记事工具


@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::
:: 临时记事,code by 523066680@cn-dos.net
::
:: 参数: add 记事内容         添加记事内容到记事列表
:: 参数: del 编号1 编号2 .... 删除指定编号的记事
:: 参数为空                   直接读取记事文本
::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set notebook=notebook.x
set arg_del=del
set arg_add=add
set arg_=type

if not exist "%notebook%" (
   echo %notebook% 不存在,将建立
   type nul>>notebook.x
   exit /b
)

if not defined arg_%1 (
   echo 指令 %1 不存在
   exit /b
) else (
   if "%1"=="" (goto :func_)
)

:read_it
::如果参数不为空就来到这里,增加项目编号和删除项目,都要先读取文本信息
::text format: $number $date $note , range of number : [0-99]
set /a note_n=0
for /f "tokens=1,2,*" %%a in ('type %notebook%') do (
   set note_info_#%%a=%%b %%c
   set /a note_n+=1
)
::然后才跳转到功能块
goto :func_%1


:func_
  type %notebook%
  exit /b

:func_del
  set /a x=-1
  if "%2"=="" (echo arg2 = NULL &exit /b)
  if not defined note_info_#%2 (echo no this item. &exit /b)
  ::假设删除一个以上项目,参数以空格的方式隔开,以总参数为字符串,用于判断
  for /f "tokens=1,*" %%a in ("%*") do (set note_items=%%b)
  ::像10这样的,删除的是0,单纯替换0以后也会变化,后面判断将进行删除,所以是危险的,增加判断因素
  set note_items=#%note_items: =#%#
  echo,>%notebook%
  for /f "tokens=2,* delims==#" %%a in ('set note_info_#') do (
    if "!note_items:#%%a#=!"=="!note_items!" (
       set /a x+=1
       set xnum=  !x!
       set xnum=!xnum:~-2!
       echo !xnum! %%b>>%notebook%
    ) else (
       echo 删除项 - %%a %%b
    )
  )
  echo %notebook% 重新排列 , 现状 :
  type %notebook%
  exit /b
:func_add
   if "%2"=="" (echo 附加信息为空 &exit /b)
   set xnum=  %note_n%
   set xnum=!xnum:~-2!
   set strnow=%*
   ::::cut string - "add "
   set strnow=%strnow:~4%
   (echo %xnum% %date:~0,10% %strnow%)>>%notebook%
   echo %notebook% 现状 :
   type %notebook%
   exit /b
测试:

  Quote:
c:\test>note add 这是个测试项
notebook.x 现状 :

0 2010-06-08 快递代收货款未到
1 2010-06-08 物料未清点
2 2010-06-09 制作一份供应商地址电话信息表
3 2010-06-09 这是个测试项

c:\test>note del 1 2
删除项 - 1 2010-06-08 物料未清点
删除项 - 2 2010-06-09 制作一份供应商地址电话信息表
notebook.x 重新排列 , 现状 :

0 2010-06-08 快递代收货款未到
1 2010-06-09 这是个测试项

c:\test>

[ Last edited by 523066680 on 2010-6-9 at 21:26 ]

   此帖被 +2 点积分    点击查看详情   
评分人:【 zzz19760225 分数: +2  时间:2017-12-26 13:29




综合型编程论坛

我的作品索引
  
2010-6-9 19:38
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 28 楼』:  借Wget批量下载死神漫画

我是几十集没看的那种
你知道啦,在网上看很辛苦的,一张张翻,所以决定全都下载。
getpic.sh
#!/bin/bash
for ((fold=350;fold<=380;fold++))
do
   if [ ! -e $fold ]
   then
        mkdir $fold
   fi
   cd ./$fold
   wget --no-clobber http://178.manmankan.com/BLEACH/$fold/{001..025}.jpg
   cd ..
done
echo end
read -n1
死神一下看完了,于是下火影
由于工作的关系我经常跨系统,偷偷摸摸嘛,也整个批处理版的:
真羡慕bash支持 {1..4}=1 2 3 4 这样的扩展..... 改成批处理就粗起来了。
@echo off
setlocal enabledelayedexpansion
set name=naruto
for /l %%x in (420,1,500) do (
  if not exist %name%_%%x (md %name%_%%x)
  cd %name%_%%x
  for /l %%a in (1,1,25) do (
    set num=000%%a
    set num=!num:~-3!
    wget -nc http://140.manmankan.com/naruto/%%x/!num!.jpg
  )
  cd ..
)
最后这样用图片浏览器看着果然不舒服,批量导入网页吧
一集的图片列在一个页面,这样看一集翻一次就OK了。
@echo off
setlocal enabledelayedexpansion

for /l %%i in (420,1,500) do (
type nul>na_%%i.html
set /a left=%%i-1,right=%%i+1
echo ^<a href="na_!left!.html"^> 上一页 ^</a^> >>na_%%i.html
echo ^<a href="na_!right!.html"^> 下一页 ^</a^> ^<br^> >>na_%%i.html
for /l %%j in (1,1,25) do (
   set num=000%%j
   set num=!num:~-3!
   (
   echo ^<img src="naruto_%%i\!num!.jpg" /^>
   echo ^<br^>
   echo -----------------------------------------------------
   echo ^</br^>
   )>>na_%%i.html
)
echo ^<a href="na_!left!.html"^> 上一页 ^</a^> >>na_%%i.html
echo ^<br^> ^<a href="na_!right!.html"^> 下一页 ^</a^> >>na_%%i.html
echo %%i
)
pause
exit
[ Last edited by 523066680 on 2010-7-13 at 17:46 ]



综合型编程论坛

我的作品索引
  
2010-7-13 17:36
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 29 楼』:  H

执行顺序是:先MainGet.bat 然后Act.bat
其他两个是受调用的

MainGet.bat
先获取1-10张附有名单列表的页面,那里由我要的子页面
@echo off
set /a x=1
:main
wget -T 8 -t 1 主页_和谐/List/class_61_%x%.Html
if %x% lss 10 (set /a x+=1 &goto :main)
Act.bat
负责提取名单和子页地址,交给下载脚本
@echo off
setlocal enabledelayedexpansion
set /a i=1
:main
echo class_61_%i%
for /f "tokens=*" %%a in ('type class_61_%i%.html ^|find /i "span class"') do (
set str=%%a
set str=!str:*/html/=!
for /f "tokens=1 delims=." %%x in ("!str!") do (
      if not exist %%x (call downer.bat %%x)
)
)
if %i% lss 10 (set /a i+=1 &goto :main)
downer.bat     受act.bat调用
分析子页面中的图片链接,全部下载~
等等,节外生枝,为什么i % 3 = 1 和 2 时要外部调用下载呢
你知道啦,代码速度>下载速度, 外部调用,多进程下载就不用占时间了
取余为0时 ,当前进程下载,这是为了缓冲,如果全部调用外部,
没有缓冲,会变成炸弹脚本的。
@echo off
setlocal enabledelayedexpansion
set src=http://主页_被我和谐了/html/
set act=%1

:main
wget -T 5 -t 1 -nc %src%%act%.html
if %errorlevel% neq 0 (goto :eof)
if not exist %act% (mkdir %act%) else (goto :eof)
set /a i=0
cd %act%
for /f "tokens=2 delims= " %%a in ('type ..\%act%.html ^| find /i "img src"') do (
  set /a i+=1,p=i %% 3
  set str=%%a
  set str=!str:*http=!
  set str=!str:"=!
  set name=000!i!
  set name=!name:~-3!
  echo !name!
  if !p! equ 0 (
    wget -T 8 -t 1 -O !name!.jpg http!str!
    if !errorlevel! neq 0 (del !name!.jpg)
  ) else (
    start /min ..\geter.bat %cd% !name!.jpg http!str!
  )
)
cd ..
geter.bat
受 downer.bat调用
@echo off
echo %1 %2 %3
cd %1
wget -T 8 -nc -t 1 -O %2 %3
if %errorlevel% neq 0 (del %2)
exit
[ Last edited by 523066680 on 2010-7-19 at 12:34 ]



综合型编程论坛

我的作品索引
  
2010-7-18 15:22
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
523066680
银牌会员

SuperCleaner


积分 2362
发帖 1133
注册 2008-2-2
状态 离线
『第 30 楼』:  


::::::::::::::::::::::::::::::::::::::::::::::::::
:: code by 523066680@163.com
:: 从F盘开始,找出存在isme.x[标志性文件]的磁盘 Then
:: 读取isme.x内的相关目录名,并将当前目录更新备份到那里
:: 因为我的移动硬盘盘符时而变动,所以才写了一个根据标记文件寻找备份目的地的。
:: [源/目标]可能会有多个,所以find /i "目标信息",以匹配上正确的路径
:: 例isme.x内容 Files\me 表示终点为当前磁盘的files\me目录
::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal enabledelayedexpansion
set source=%~dp0
::寻在isme.x所在磁盘,找到就读取目标路径
for %%a in (f g h i j k l m n o p q r s t u v w x y z) do (
if exist %%a:\isme.x (
     for /f "tokens=*" %%s in ('type %%a:\isme.x ^|find /i "me"') do (
       set dest=%%s
       set dest=%%a:\!dest!
     )
)
)

if defined dest (goto :act) else (echo NOT FOUND &pause &exit)

:act
if "%source:~-1%"=="\" (set source=%source:~0,-1%)
if "%dest:~-1%"=="\" (set dest=%dest:~0,-1%)

if not exist "%dest%\" (
  echo 作为备份的目录%dest%  不存在,将尝试建立。
  (md "%dest%")||(
    echo 出错了...
    pause>nul
    exit
  )
  goto :justcopy
)

echo 正搜索+清理 "%dest%"中可能多出的文件或子文件夹
for /f "tokens=*" %%a in ('dir /a /s /b "%dest%"') do (
  set pathname=%%a
  set pathname=!pathname:%dest%\=!
  if exist "%%a" (
      if not exist %source%\!pathname! (
            if exist "%%a\" (
                 tree %%a
                 rd /s /q "%%a"
            ) else (
                 del /f /a /q "%%a"
            )
      )
  )
)

:justcopy
echo xcopying
if exist cut.txt (
   xcopy /f /s /d /c /h /y /exclude:cut.txt  "%source%" "%dest%"
) else (
   xcopy /f /s /d /c /h /y "%source%" "%dest%"
)
echo 按任意键退出
pause>nul
exit
[ Last edited by 523066680 on 2010-7-30 at 20:23 ]



综合型编程论坛

我的作品索引
  
2010-7-30 20:18
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (523066680)  编辑帖子  回复  引用回复
« [1] [2] [3] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: