|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
拜托 再帮我看看吧
Please provide the specific Chinese content that needs to be translated so that I can assist you with the translation.
|
|
2006-6-19 13:26 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
Re kcdsw:
抱歉!你的问题我很快就注意到了,但是遗憾的是,当时和后来我做了许多的测试,结果证明使用for+echo的方法复制和编辑文本存在很多问题,尤其是对类似cover.ps这类含有相当多特殊字符的文件。
于是我准备改弦更张,使用其它的方法编辑文本。
第一个想到的方法是edlin,因为它是NT系列自带的命令行方式的文本编辑器,结果费了一番工夫之后,发现edlin不能处理超长的文件,文件只加载到530多行便结束了。
于是,所余的路径便只有第三方脚本工具了。考虑到只是替换一些简单的文本,所以选择了sed,其脚本编写起来并不繁琐。使用GNU sed 3.02测试了以下代码,结果是正确且高效的。
@echo off
::取原始的位置参数
::for /f "tokens=1,2,3,4,5,6,7" %%a in ('findstr /C:"DeviceRGB" cover.ps') do set jpg=%%a %%b %%c %%d %%e %%f %%g
::取图片的象素值进行判断
for /f "tokens=2,3" %%h in ('findstr /C:"setcolorspace" cover.ps') do (
if %%h EQU %%i echo 封面中的作者照片无须更改!
if %%h LSS %%i echo 照片不规则!
if %%h GTR %%i set /a newsize=730*%%h/%%i
)
::::获取所在行行号和内容
::for /f "tokens=1,* delims=:" %%m in ('findstr /N /C:"730 730" temp.ps') do (
:: set iLN=%%m
:: set sLine=%%n
::)
::
::set sLine=%sLine:730 730=!newsize! 730%
::
::echo %iLn%d> _temp.edl
::echo i%iLn%>> _temp.edl
::echo %sLine%>> _temp.edl
::echo >> _temp.edl
::echo %iLn%,%iLn%l>> _temp.edl
::echo e>> _temp.edl
::
::edlin cover.ps < _temp.edl
:: 将新的大小写入指定行
if %newsize% NEQ 0 sed -e "s/\(.*\)730\( 730.*\)/\1%newsize%\2/" cover.ps >cover3.txt
Last edited by willsort on 2006-6-20 at 10:31 ]
Re: kcdsw:
Sorry! Your question was noticed by me soon, but unfortunately, I did many tests at that time and later, and the result proved that there are many problems in using the for+echo method to copy and edit text, especially for files like cover.ps which contain quite a lot of special characters.
So I was ready to change my approach and use other methods to edit text.
The first method that came to mind was edlin, because it is a command-line text editor built into the NT series. After going through some trouble, I found that edlin cannot handle extremely long files, and the file is only loaded up to more than 530 lines and then ends.
Then, the remaining path was only third-party script tools. Considering that it was just to replace some simple text, so sed was chosen, and its script is not cumbersome to write. The following code was tested with GNU sed 3.02, and the result was correct and efficient.
@echo off
:: Get the original position parameters
:: for /f "tokens=1,2,3,4,5,6,7" %%a in ('findstr /C:"DeviceRGB" cover.ps') do set jpg=%%a %%b %%c %%d %%e %%f %%g
:: Get the pixel values of the image for judgment
for /f "tokens=2,3" %%h in ('findstr /C:"setcolorspace" cover.ps') do (
if %%h EQU %%i echo The author's photo in the cover does not need to be changed!
if %%h LSS %%i echo The photo is irregular!
if %%h GTR %%i set /a newsize=730*%%h/%%i
)
:::: Get the line number and content of the line
:: for /f "tokens=1,* delims=:" %%m in ('findstr /N /C:"730 730" temp.ps') do (
:: set iLN=%%m
:: set sLine=%%n
::)
::
:: set sLine=%sLine:730 730=!newsize! 730%
::
:: echo %iLn%d> _temp.edl
:: echo i%iLn%>> _temp.edl
:: echo %sLine%>> _temp.edl
:: echo >> _temp.edl
:: echo %iLn%,%iLn%l>> _temp.edl
:: echo e>> _temp.edl
::
:: edlin cover.ps < _temp.edl
:: Write the new size to the specified line
if %newsize% NEQ 0 sed -e "s/\(.*\)730\( 730.*\)/\1%newsize%\2/" cover.ps >cover3.txt
Last edited by willsort on 2006-6-20 at 10:31 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-19 18:58 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal EnableDelayedExpansion
::取原始的位置参数
for /f "tokens=1,2,3,4,5,6,7" %%a in ('findstr /C:"DeviceRGB" cover.ps') do set jpg=%%a %%b %%c %%d %%e %%f %%g
::取图片的象素值进行判断
for /f "tokens=2,3" %%h in ('findstr /C:"setcolorspace" cover.ps') do (
if %%h EQU %%i echo 封面中的作者照片无须更改!
if %%h LSS %%i echo 照片不规则!
if %%h GTR %%i set /a newsize=730*%%h/%%i
)
:: 将新的大小写入指定行
if %newsize% NEQ 0 sed -e "s/\(.*\)730\( 730.*\)/\1%newsize%\2/" cover.ps >cover3.txt
那这样写的话是不是只是替换了原先的730 730 ?
如果是这样,那我第一行的for 是不是可以不要了?
只需要提取出象素大小,然后计算出所需的新数据 然后替换?
能否提供你所说的sed的版本下载?
Last edited by kcdsw on 2006-6-20 at 10:29 ]
@echo off
setlocal EnableDelayedExpansion
:: Get original positional parameters
for /f "tokens=1,2,3,4,5,6,7" %%a in ('findstr /C:"DeviceRGB" cover.ps') do set jpg=%%a %%b %%c %%d %%e %%f %%g
:: Get pixel values of the image for judgment
for /f "tokens=2,3" %%h in ('findstr /C:"setcolorspace" cover.ps') do (
if %%h EQU %%i echo No need to change the author's photo on the cover!
if %%h LSS %%i echo The photo is irregular!
if %%h GTR %%i set /a newsize=730*%%h/%%i
)
:: Write the new size to the specified line
if %newsize% NEQ 0 sed -e "s/\(.*\)730\( 730.*\)/\1%newsize%\2/" cover.ps >cover3.txt
If written like this, is it just replacing the original 730 730?
If so, can I just get rid of the first for line?
Just need to extract the pixel size, then calculate the required new data and then replace?
Can you provide the download of the sed version you mentioned?
Last edited by kcdsw on 2006-6-20 at 10:29 ]
|
|
2006-6-20 10:15 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
Re kcdsw:
没错,是这样的。
原代码中第一个for语句,是在考虑for+echo和edlin方案时使用的,改用sed方案后因其不影响结果输出,而忽略了将其删除。类似的语句还有setlocal。
现已将原代码进行了修改。
sed下载链接请参考,请注意使用GNU sed 4.0.7会过滤掉文本行中的回车符(0x0D),生成Unix格式文本。GNU sed 3.02 则没有这个问题。
GNU utilities for Win32
http://unxutils.sourceforge.net/
Last edited by willsort on 2006-6-20 at 10:39 ]
Re kcdsw:
That's right.
The first for statement in the original code was used when considering the for+echo and edlin solutions. After switching to the sed solution, since it doesn't affect the output result, it was overlooked to delete it. Similar statements also include setlocal.
Now the original code has been modified.
For the sed download link, please refer to . Please note that using GNU sed 4.0.7 will filter out the carriage return characters (0x0D) in the text lines and generate Unix - format text. GNU sed 3.02 doesn't have this problem.
GNU utilities for Win32
http://unxutils.sourceforge.net/
Last edited by willsort on 2006-6-20 at 10:39 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-20 10:30 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
呵呵 谢谢版主
先前我很固执的要用批处理,可能是我的心理在做怪
总是觉得外来的程序大多没中文注解,也不是自己写的,也不放心,难学难懂
今天一用 感觉不错
Hehe, thanks moderator.
Previously I was very stubborn to use batch processing, maybe it's my psychology playing tricks.
Always feeling that most external programs have no Chinese annotations, not written by myself, and also not at ease, difficult to learn and understand.
Today I used it and felt it's不错 (Note: "不错" here remains as it is since it's part of the original text and the task is to translate the Chinese parts. Wait, no, I made a mistake. The entire text needs to be translated. Let's start over.)
Hehe, thank you moderator.
Previously I was very stubborn to use batch processing, maybe it's my psychology playing tricks.
Always feeling that most external programs have no Chinese annotations, are not written by myself, and I'm also not at ease, hard to learn and understand.
Today I used it and felt it was good.
Wait, no, let's do it properly:
Original Chinese: 呵呵 谢谢版主
先前我很固执的要用批处理,可能是我的心理在做怪
总是觉得外来的程序大多没中文注解,也不是自己写的,也不放心,难学难懂
今天一用 感觉不错
Translation:
Hehe, thanks moderator.
Previously I was very stubborn about using batch processing, maybe it's my psychology playing tricks.
Always feeling that most external programs have no Chinese annotations, are not written by myself, and I'm also not at ease, hard to learn and understand.
Today when I used it, I felt it was good.
|
|
2006-6-20 11:33 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
用 QuickBFC 编译了一下
编译的时候把sed捆绑进去了
因为编译后的exe在运行的时候首先需要把原先的bat文件释放出来,位置是%temp%
我想 它释放捆绑文件的路径大概也是这里,或者是exe所在的文件夹
这样 exe会自动把cover.ps的路径传递给bat 和 sed ,那我就是更省心了,省的sed和bat不在一起.省的我告诉它cover.ps的路径,省了N多事情哇!!!
在此 再次感谢版主和各位关注我帖子的兄弟!!
受小弟一拜!!
I used QuickBFC to compile.
When compiling, I bundled sed in.
Because when the compiled exe runs, it first needs to release the original bat file, and the location is %temp%.
I think the path where it releases the bundled file is probably also here, or the folder where the exe is located.
In this way, the exe will automatically pass the path of cover.ps to the bat and sed, which makes me more at ease, avoiding that sed and bat are not together. Avoiding me telling it the path of cover.ps, saving a lot of things!!!
Here, once again, I thank the moderator and all the brothers who paid attention to my post!!
Bow to you, little brother!!
|
|
2006-6-20 11:37 |
|
|
jianyaogao
初级用户
 
积分 49
发帖 22
注册 2005-8-4
状态 离线
|
|
2007-3-17 23:34 |
|
|
hegu
新手上路

积分 4
发帖 2
注册 2007-5-13
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
好多高手!!!!!!倾慕中....
So many experts!!!!!! Admiring them....
|
|
2007-5-13 12:31 |
|
|
kgdetg1127
初级用户
 
积分 158
发帖 89
注册 2007-4-25
状态 离线
|
|
2007-10-12 22:23 |
|
|
zhouyongjun
新手上路

积分 4
发帖 3
注册 2007-11-3
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
稀里糊涂的,下下来看下。
Confusedly, download it and take a look.
|
|
2008-10-31 13:54 |
|
|
wujianlin555
新手上路

积分 1
发帖 1
注册 2008-11-18
状态 离线
|
|
2008-11-20 23:00 |
|
|