|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 16 楼』:
Delta2
使用 LLM 解释/回答一下
#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.x,dot.y,dot.x,dot.y);}
}
int main(void)
{
int i,j,whi=0,edotn=0;
DotInf snk;
DotInf edot;
for (i=0;i<9;i++) for (j=0;j<NDOT-1;j++) {edot.x=edot.y=0;}
initgr(); /* BGI初始化 */
for (i=0;i<NDOT;i++) {
snk.a=snk.b=snk.x=snk.y=200;
edot.x=edot.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.x!=0) delta(edot,0);
delta(snk,2);
for (i=0;i<NDOT;i++){
if ((snk.x==snk.a)&&(snk.y==snk.b)){
snk.a=rand()%600+1;
snk.b=rand()%400+20;
}
}
for (i=0;i<NDOT;i++){
if (whi>i) continue;
if (snk.x>snk.a)
snk.x--;
else if (snk.x<snk.a)
snk.x++;
else
{
if (snk.y>snk.b)
snk.y--;
else if (snk.y<snk.b)
snk.y++;
}
edot.x=snk.x;
edot.y=snk.y;
}
}
getch();
closegr(); /* 恢复TEXT屏幕模式 */
return 0;
}
```cpp
#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 initialization */
{
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.x, dot.y, dot.x, dot.y);
}
}
int main(void)
{
int i, j, whi = 0, edotn = 0;
DotInf snk;
DotInf edot;
for (i = 0; i < 9; i++)
for (j = 0; j < NDOT - 1; j++)
{
edot.x = edot.y = 0;
}
initgr(); /* BGI initialization */
for (i = 0; i < NDOT; i++)
{
snk.a = snk.b = snk.x = snk.y = 200;
edot.x = edot.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.x != 0)
delta(edot, 0);
delta(snk, 2);
for (i = 0; i < NDOT; i++)
{
if ((snk.x == snk.a) && (snk.y == snk.b))
{
snk.a = rand() % 600 + 1;
snk.b = rand() % 400 + 20;
}
}
for (i = 0; i < NDOT; i++)
{
if (whi > i)
continue;
if (snk.x > snk.a)
snk.x--;
else if (snk.x < snk.a)
snk.x++;
else
{
if (snk.y > snk.b)
snk.y--;
else if (snk.y < snk.b)
snk.y++;
}
edot.x = snk.x;
edot.y = snk.y;
}
}
getch();
closegr(); /* Restore TEXT screen mode */
return 0;
}
```
|

综合型编程论坛
我的作品索引 |
|
2009-8-23 07:19 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 17 楼』:
时间随机按位显示
使用 LLM 解释/回答一下
@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 ]
```
@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 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
把一个自然数分解成 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
Decompose a natural number into n consecutive natural numbers.
```batch
@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
```
Numbers with negative numbers in the composition:
```batch
@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
```
List numbers around 1000 that cannot be split into n consecutive natural numbers:
```batch
@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 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 19 楼』:
[TestCscript]ListErrLines
使用 LLM 解释/回答一下
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
```vbscript
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 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
今天很无聊……
@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
Today is very boring...
@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 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 21 楼』:
[shell日记]read
使用 LLM 解释/回答一下
read
文:523066680
今天第一篇。
算是一种笔记吧,就像流水帐一样
算不上分享,因为每个人都会经历自己探索的过程。
顺便学英语,就把原帮助一起拉上来
参数和对应实例:
-a array assign the words read to sequential indices of the array
variable ARRAY, starting at zero
把输入内容按分隔符(空格或者跳格之类)分配给数组,连续的空格也算为1个分割。
输入后,数组规格跟c语言一样,用var的格式表示,下标从0开始,
直接echo $var 的效果等于echo ${var}
当echo 数组带下标的时候,记得加{}表达,比如echo ${a}
定义数组变量: read -a arr 就可以了; read -a arr 出错。
但是你直接 read arr 是允许的,就是直接赋值数组某个元素嘛。
-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个字符就结束~ 而不是等待一个新的行。
结果按回车将提前结束了
感觉描述的不严密, 实际规则是{ 如果 转行||字符数为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 秒内一个还没写完(触发终止输入条件),就超时退出 + 命令会返回一个
错误码。
2.这句话没看出来,不过执行TMOUT=1, 命令行1秒后就退出了
3.timeout 的值可以是一个分数,当然并不是真的用分数表示法
他是告诉你,可以使用一个非整数,比如 -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 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
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
failure n. 失败
He was doomed to failure. 他注定失败
fractional 形容词:小量的;分数的
exceed 超过
read
Text: 523066680
First one today.
It can be regarded as a kind of note, just like a log
Not really sharing, because everyone will go through their own exploration process.
By the way, learn English, so I pull up the original help together
Parameters and corresponding examples:
-a array assign the words read to sequential indices of the array
variable ARRAY, starting at zero
Assign the input content to the sequential indices of the array according to the delimiter (space or tab, etc.), and consecutive spaces are also counted as 1 division.
After input, the array specification is the same as in C language, and it is expressed in the format of var, with subscripts starting from 0.
Directly echo $var is equivalent to echo ${var}
When echoing an array with subscripts, remember to add {} to express, for example, echo ${a}
Define array variable: read -a arr is okay; read -a arr is wrong.
But you can directly read arr, which is to directly assign a certain element of the array.
-d delim continue until the first character of DELIM is read, rather
than newline
That is, read input until the first character of DELIM is read, instead of ending with a newline. Of course, the "certain character" is not counted.
Test results:
1. After specifying a certain character, the carriage return is also read in, and it will not end due to the carriage return
(Hehe, I haven't tried to end with the carriage return character, I won't make + redundant)
2. -dstr does not reach the end of str, it is the end of s, so people say it is a character
3. -dx str ;# Turned n lines + input character ; echo $str will not output the newline
To echo "$str" will output the newline.
(The following are directly quoted from the help content if I don't know)
-e use Readline to obtain the line in an interactive shell
I don't know, it seems that the default is to end after reading a line? I will make up for it later when I know.
-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 here means: instead of.
Read until the Nth character and then end~ instead of waiting for a new line.
The result is that pressing Enter will end in advance
I feel that the description is not strict. The actual rule is {If newline || the number of characters is n; then end}
(The help of this parameter once made me think that rather than means or)
-p prompt prompt is the meaning of prompt, that is, first display the "prompt" string, and then wait for you to input.
With the prompt option, there is no need to echo the prompt separately.
-r do not allow backslashes to escape any characters
backslash backslash "\";
escape escape; here means: escape
Translation: Do not allow backslashes to escape any characters.
-s do not echo input coming from a terminal
Do not display the characters being input from the terminal. (Just like when entering a password),
To be honest, I can't imagine the connection between -s and this function. Learning it is like reciting.
-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. If a line of input is not completed (triggering the termination input condition) within timeout seconds, it will time out and exit + the command will return an
error code.
2. I can't see this sentence, but executing TMOUT=1, the command line exits after 1 second
3. The value of timeout can be a fractional number , of course, it is not really expressed in fractional notation
It is to tell you that you can use a non-integer, such as -t0.5 is to limit input within half a second.
4. If timeout is set to 0, it will only return success if input is available from the effective special file descriptor.
5. exceed exceed; if timed out, the exit status is greater than 128.
-u fd read from file descriptor FD instead of the standard input
I won't say, I don't know what fd is. Relevant information: http://baike.baidu.com/view/1303430.htm
"Under linux, all operations are on files, and the operations on files are realized by using file descriptors
(file descriptor). In the source code, fd is generally used as the identifier of the file descriptor."
# Still don't know the meanings of several parameters, so I will come back to modify them when I know... #
End: If read is not followed by a variable name, the value will be assigned to the REPLY variable,
However, if you give a new variable name, REPLY will not be updated synchronously.
+++++++++++++++++Learn some English+++++++++++++
#1 -e use Readline to obtain the line in an interactive shell
Baidu search:
obtain obtain; get
Example: He failed to obtain a scholarship. He didn't get a scholarship.
interactive interactive; interactive
#2 -n nchars return after reading NCHARS characters rather than waiting
for a newline
rather than : instead of
#3 -t timeout
time out and return 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
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
failure n. failure
He was doomed to failure. He was doomed to failure
fractional adjective: small amount; fractional
exceed exceed
|

综合型编程论坛
我的作品索引 |
|
2010-1-6 19:34 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
本来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 ; then exit ;fi
done
Last edited by 523066680 on 2010-1-24 at 22:14 ]
Originally, `read -n1` can read only one character, and pressing a key would proceed to the next line.
I wrote a loop with `read -n1`, which is to repeatedly perform this operation by pressing any key, in order to make the loop wait for my confirmation.
As a result, pressing the "right arrow key" caused the loop to run n times in a flash. It turns out that these direction keys, etc., press once and correspond to several characters.
It made me run the loop n times…… (Did it become that a key was pressed n times? O_o)
So I added `read -n9 -t0.1` before `read -n1`, that is:
After reading one character,
within 0.1 seconds, regardless of whether there are 9 characters or not, eat them all
(I thought that `-t0` could instantly eat them, but I found that there was still one key press, and there was a time difference for the several characters that appeared, so I used 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
I tried it, and directly using `read -t0.1` to eat characters doesn't work. It only waits for 0.1 seconds and doesn't read characters
(Because by default, the Enter key is used as the end of input)
Logically, it would cause an infinite loop and not wait, but here it only cycled a few times continuously.
Almost forgot, originally there was a `read -n1` in each loop to read one character~.
At the same time, I felt that the `-n` option, when reading n characters, breaks the restriction of ending input with Enter.
`-t -n` is the "OR" restriction~ (timeout)||(when n characters are read) then end
=================================================================
Change it to exit when pressing the q key
#!/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 ; then exit ;fi
done
Last edited by 523066680 on 2010-1-24 at 22:14 ]
|

综合型编程论坛
我的作品索引 |
|
2010-1-24 21:46 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 23 楼』:
[批处理]备份目录系的更新
使用 LLM 解释/回答一下
本来用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 ]
Originally, using xcopy could update the backup directory system to my mobile hard drive. But xcopy only handles copying, so every time I back up, there are additions but no deletions. Although I could first delete everything and then xcopy, which saves code, copying takes more time. So I added a segment of code to delete the things that exist in the backup directory but not in the source directory. Using for combined with dir to traverse the directory tree. Judge if it's a directory, then rd the directory system; if it's a file, then delete (the judgment sentence if exist "%%a\"). But there was an error the first time. The reason was: Some main directories had already been deleted, so the subdirectories and files under them were also deleted, but the directories listed by dir were not updated and still listed their subdirectories, causing the error that subdirectories no longer existed but deletion was still continued. So I added another judgment before each deletion operation: whether the target exists. Features: If the destination disk used for backup doesn't exist, it will exit in advance. If it's executed successfully, a log of deleted files will be generated. Delete first, then xcopy.
@echo off
rem code by 523066680@cn-dos.net
setlocal enabledelayedexpansion
set source=%~dp0
set dest=d:\Burn File Update Area
rem The source path can be its own path. Considering that both input and %~dp0 may have \ at the end,
rem added judgment and processing
if "%source:~-1%"=="\" (set source=%source:~0,-1%)
if "%dest:~-1%"=="\" (set dest=%dest:~0,-1%)
if not exist "%source%\" (
echo The source does not exist, press any key to exit
pause>nul
exit
)
echo Please confirm: Source directory %source%
echo Backup to %dest%
if not exist "%dest%\" (
echo The directory %dest% used as backup does not exist, will try to create.
(md "%dest%")||(
echo The target cannot be created, maybe the target disk does not exist, press any key to exit.
pause>nul
exit
)
goto :justcopy
)
type nul>DelFile.txt
type nul>DelFold.txt
echo _
echo Press any key to start searching + cleaning up the files or subfolders that may be excessive in "%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 This cleanup generates logs DelFold.txt DelFile.txt
type "DelFold.txt" "Delfile.txt"
:justcopy
echo _
echo Press any key to continue starting 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 Press any key to exit
pause>nul
exit
I know some software can achieve this, but the advantage of batch processing is that I can implement some detailed operations by myself, such as the /exclude:cut.txt parameter, which is used to specify the file names or folders listed in the cut.txt text that are not to be copied.
Last edited by 523066680 on 2010-3-20 at 12:17 ]
|

综合型编程论坛
我的作品索引 |
|
2010-3-14 22:27 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
@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
)
```
@echo off
setlocal enabledelayedexpansion
::To reduce the judgment + the name number part is neat (uniform two-digit number), the number of files cannot be greater than 99, that is, 01-99 is specified
::Preliminary verification
if "%~1"=="" (
echo You didn't drag a file onto me, so the first parameter is empty, press any key to bye~
pause>nul
exit
) else (
if exist "%~1" (
echo The folder where the dragged file is located "%~dp1"
echo _
set /p "inp=Before batch renaming, please specify the name prefix:"
set /a n=1
set "nx=000!n!"
set "xformat=%~x1"
set "xpath=%~dp1"
) else (echo There is a parameter but it is not right, bye &pause>nul &exit)
)
::If %~1 is non-empty and exists, it will reach here
:main
if not "%~1"=="" (
if exist "%~1" (
echo The operation being performed: 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 Now restore the format ren "%xpath%*%xformat%#" "*%xformat%"
ren "%xpath%*%xformat%#" "*%xformat%"
pause
exit
)
```
|

综合型编程论坛
我的作品索引 |
|
2010-4-13 11:14 |
|
|
yonghu111
初级用户
 
积分 90
发帖 57
注册 2010-4-12
状态 离线
|
|
2010-4-13 15:30 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 26 楼』:
让OPENGL通过读取脚本绘图
使用 LLM 解释/回答一下
读取脚本,并可以通过向脚本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;
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={"color","sleep","point"};
for (i=0;i<fo;i++) {
if (strcmp(str,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 ]
Read the script, and you can continue to plot points and color by appending commands to script a.x for observation.
This is a prototype, identifying only three commands:
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;
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 = { "color","sleep","point" };
for (i = 0; i < fo; i++) {
if (strcmp(str, tmpstr) == 0) {
break;
}
}
return i;
}
Compiled under Windows with Dev-CPP (including the glut library).
The following batch processing generates random commands to observe the effect
@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 Press q in the graphics window to exit
start %dict%
pause
exit
I think this will be a pretty good start~
Last edited by 523066680 on 2010-5-23 at 18:50 ]
|

综合型编程论坛
我的作品索引 |
|
2010-5-23 18:47 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 27 楼』:
个人写的记事工具
使用 LLM 解释/回答一下
@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 :
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
测试:
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 ]
```
@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::
:: Temporary notebook, code by 523066680@cn-dos.net
::
:: Parameter: add Note content Add Note content to the note list
:: Parameter: del Number 1 Number 2 .... Delete the note with the specified number
:: Parameter is empty Directly read the note text
::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set notebook=notebook.x
set arg_del=del
set arg_add=add
set arg_=type
if not exist "%notebook%" (
echo %notebook% does not exist, will be created
type nul>>notebook.x
exit /b
)
if not defined arg_%1 (
echo Command %1 does not exist
exit /b
) else (
if "%1"=="" (goto :func_)
)
:read_it
::If the parameter is not empty, come here. Adding project numbers and deleting projects both need to read text information first
::text format: $number $date $note, range of number :
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
)
::Then jump to the function block
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)
::Assume that more than one item is deleted, the parameters are separated by spaces, and the total parameters are used as strings for judgment
for /f "tokens=1,*" %%a in ("%*") do (set note_items=%%b)
::Like 10, the deletion is 0. After simply replacing 0, it will also change. The subsequent judgment will delete, so it is dangerous. Add judgment factors
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 Deleted item - %%a %%b
)
)
echo %notebook% rearranged, current situation :
type %notebook%
exit /b
:func_add
if "%2"=="" (echo Additional information is empty &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% current situation :
type %notebook%
exit /b
```
Test:
c:\test>note add This is a test item
notebook.x current situation :
0 2010-06-08 Express delivery collection and delivery of goods not arrived
1 2010-06-08 Materials not counted
2 2010-06-09 Make a supplier address and phone information form
3 2010-06-09 This is a test item
c:\test>note del 1 2
Deleted item - 1 2010-06-08 Materials not counted
Deleted item - 2 2010-06-09 Make a supplier address and phone information form
notebook.x rearranged, current situation :
0 2010-06-08 Express delivery collection and delivery of goods not arrived
1 2010-06-09 This is a test item
c:\test>
Last edited by 523066680 on 2010-6-9 at 21:26 ]
|

综合型编程论坛
我的作品索引 |
|
2010-6-9 19:38 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 28 楼』:
借Wget批量下载死神漫画
使用 LLM 解释/回答一下
我是几十集没看的那种
你知道啦,在网上看很辛苦的,一张张翻,所以决定全都下载。
getpic.sh
#!/bin/bash
for ((fold=350;fold<=380;fold++))
do
if
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 ]
I'm the kind who hasn't watched for dozens of episodes.
You know, it's really hard to watch online, flipping through one by one, so I decided to download all.
getpic.sh
#!/bin/bash
for ((fold=350;fold<=380;fold++))
do
if
then
mkdir $fold
fi
cd ./$fold
wget --no-clobber http://178.manmankan.com/BLEACH/$fold/{001..025}.jpg
cd ..
done
echo end
read -n1
Finished watching Bleach all at once, so then download Naruto.
Due to work, I often switch systems, sneaking around, so I also made a batch processing version:
Really envy that bash supports expansions like {1..4}=1 2 3 4..... When changing to batch processing, it becomes cumbersome.
@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 ..
)
Finally, looking at it with an image viewer was really uncomfortable, so batch import into web pages.
Put the pictures of one episode on one page, so just flip once per episode.
@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 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 29 楼』:
H
使用 LLM 解释/回答一下
执行顺序是:先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 ]
The execution order is: first MainGet.bat and then Act.bat. The other two are called.
MainGet.bat
First, obtain 1 - 10 pages with the list attached, where there are the sub - pages needed.
@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
Responsible for extracting the list and sub - page addresses and handing them over to the download script.
@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 is called by Act.bat
Analyze the image links in the sub - page and download all of them. Wait, a side issue, why when i % 3 = 1 and 2, external calls for downloading are made.
You know, code speed>download speed, external call, multi - process download will not take up time.
When the remainder is 0, the current process downloads, this is for buffering. If all are called externally, there is no buffering, it will become a bomb - like script.
@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
Called by 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 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
::::::::::::::::::::::::::::::::::::::::::::::::::
:: 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 ]
::::::::::::::::::::::::::::::::::::::::::::::::::
:: Code by 523066680@163.com
:: Start from drive F, find the disk that has the isme.x Then
:: Read the relevant directory names in isme.x and update the current directory to back up there
:: Because the drive letter of my mobile hard disk changes from time to time, so I wrote one to find the backup destination according to the marker file.
:: There may be multiple , so find /i "target information" to match the correct path
:: For example, the content of isme.x is Files\me, which means the end point is the files\me directory of the current disk
::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal enabledelayedexpansion
set source=%~dp0
::Find the disk where isme.x is located, read the target path if found
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 The directory %dest% for backup does not exist, and an attempt will be made to create it.
(md "%dest%")||(
echo An error occurred...
pause>nul
exit
)
goto :justcopy
)
echo Searching and cleaning up possible extra files or subfolders in "%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 Press any key to exit
pause>nul
exit
Last edited by 523066680 on 2010-7-30 at 20:23 ]
|

综合型编程论坛
我的作品索引 |
|
2010-7-30 20:18 |
|
|