devexpress asp.net pdf viewer : Copy pdf pages to another pdf control software platform web page windows .net web browser AppleShellScripting-201419-part654

Description
Escapesequence
Terminfocapability
Sethorizontaltabatcursorposition.
^[[W
or
^[[0W
hts
Setverticaltabatcurrentline.(Notsupported
inTerminal.)
^[[1W
(noequivalent)
Redundantcodesequivalenttocodes
0g
3g
.
Codes
2W
6W
Clearhorizontaltabatcursorposition.
^[[g
or
^[[0g
(noequivalent)
Clearverticaltabatcurrentline.(Notsupported
inTerminal.)
^[[1g
(noequivalent)
Clearhorizontalandverticaltabstopsforcurrent
lineonly.(NotsupportedinTerminal.)
^[[2g
(noequivalent)
Clearallhorizontaltabs.
^[[3g
tbc
Note:  Youcanalsosettabstopswiththecommand-lineutility
tabs
.
ForMoreInformation
Thetablesinthischapterprovideonlysomeofthemorecommonlyusedescapesequencesand
terminfo
capabilities.YoucanfindanexhaustivelistofANSIescapesequencesathttp://www.inwap.com/pdp10/ansi-
code.txtandanexhaustivelistof
terminfo
capabilitiesinthemanualpagefor
terminfo
.
Beforeusingcapabilitiesorescapesequencesnotinthischapter,however,youshouldbeawarethatmost
terminalsoftware(includingTerminalinOSX)doesnotsupportthecompletesetofANSIescapesequences
orterminfocapabilities.
NonblockingI/O
Mostshellscriptsdonotneedtoacceptuserinputatallduringexecution,andscriptsthatdorequireuser
inputcangenerallyrequestitalineatatime.However,ifyouarewritingashellscriptthatneedstointeract
withtheuserwhileperformingbackgroundactivity,itcanbeconvenienttosimulateasynchronoustimer
eventsandasynchronousinputandoutput.
First,awarning:nonblockingI/Oisnotpossibleinapureshellscript.Itrequirestheuseofanexternaltool
thatsetstheterminaltononblocking.Settingtheterminaltononblockingcanseriouslyconfusetheshell,so
youshouldnotmixnonblockingI/OandblockingI/Ointhesameprogram.
AdvancedTechniques
NonblockingI/O
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
191
Copy pdf pages to another pdf - control software platform:C# PDF Page Extract Library: copy, paste, cut PDF pages in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Easy to Use C# Code to Extract PDF Pages, Copy Pages from One PDF File and Paste into Others
www.rasteredge.com
Copy pdf pages to another pdf - control software platform:VB.NET PDF Page Extract Library: copy, paste, cut PDF pages in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Detailed VB.NET Guide for Extracting Pages from Microsoft PDF Doc
www.rasteredge.com
Withthatcaveat,youcanperformnonblockingI/ObywritingasmallChelpersuchasthisone:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main(int argc, , char *argv[])
{
int ch;
int flags = = fcntl(STDIN_FILENO, , F_GETFL);
if (flags s == -1) return n -1; // / error
fcntl(STDIN_FILENO, F_SETFL, flags s | | O_NONBLOCK);
ch = = fgetc(stdin);
if (ch == = EOF) ) return n -1;
if (ch == = -1) return n -1;
printf("%c", ch);
return 0;
}
Ifyoucompilethistoolandnameit
getch
,youcanthenuseittoperformnonblockingterminalinput,as
showninthefollowingexample:
#!/bin/bash
stty -icanon -isig
while true ; ; do
echo -n n "Enter r a a character: : "
CHAR=`./getch`
if [ [ "x$CHAR" = = "x" ] ] ; ; then
echo "NO O DATA";
else
if [ [ "x$CHAR" = = "xq" ] ] ; ; then
AdvancedTechniques
NonblockingI/O
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
192
control software platform:C# PDF Page Replace Library: replace PDF pages in C#.net, ASP.NET
PDF Library - Replace PDF Pages in C#.NET. An Excellent PDF Control Allows C# Users to Replace the Original PDF Page with New PDF Page from Another PDF File in
www.rasteredge.com
control software platform:VB.NET PDF Page Replace Library: replace PDF pages in C#.net, ASP.
& pages edit, C#.NET PDF pages extract, copy, paste, C# to replace a PDF page with another PDF file page. Support to save multiple PDF pages to anther adobe PDF
www.rasteredge.com
stty -cbreak
exit
fi
echo "DATA: : $CHAR";
fi
sleep 1;
done
# never r reached
stty -cbreak
Thisscriptprints“NODATA”or“DATA:[somecharacter]”dependingonwhetheryouhavepressedakeyin
thepastsecond.(Tostopthescript,presstheQkey.)Usingthesametechnique,youcanwritefairlycomplex
shellscriptsthatcandetectkeystrokeswhileperformingothertasks.Forexample,youmightwriteagameof
pingpongthatchecksforakeystrokeatthebeginningofeachballdrawingloopandifitdetectsone,moves
theuser’spaddlebyafewpixels.
Thisscriptalsoillustratesanotherusefultechnique:disablinginputbuffering.The
stty
commandchanges
threesettingsonthecontrollingterminal(adevicefilethatrepresentsthecurrentTerminalwindow,console,
ssh
session,orothercommunicationchannel):
The
-icanon
flagdisablescanonicalizationofinput.Forexample,ifyoupress(inorder)thekeysA,Delete,
andReturn,normallyyourshellscriptreceivesanemptyline.Withcanonicalizationdisabled,yourapplication
insteadseesthreebytes:theletterA,acontrolcharacterrepresentingtheDeletekey,andanewline
characterrepresentingtheReturnkey.
The
-isig
flagdisablesautomaticgenerationofsignalsbasedoninputcharacter.Byspecifyingthisflag,
youcantraparbitrarycontrolcharacters,includingcharactersthatwouldotherwisehalt,pause,orresume
execution(Control-C,forexample).Becausedisablingthesesignalsmakesithardertostopexecutionof
ashellscript,youshouldgenerallyavoidusingthisflagunlessyouintendtocapturethesecontrolcharacters
aspartofnormaloperation.Ifyoumerelyneedtoexecutecleanupcodewhenthesekeysarepressed,
youshouldtraptheresultingsignalsinstead,asdescribedinTrappingSignals (page 173).
The
-cbreak
flagsetssomereasonabledefaultsforinteractiveshelluse.
Dependingonwhatyouaredoing,youmayalsofinditusefultopassthe
-echo
flag.Thisflagdisablesthe
automaticechooftypedcharacterstothescreen.Ifyouarecapturingcharactersforafull-screengame,for
example,echoingthetypedcharacterstothescreentendstobedisastrous,dependingonhowunluckythe
user’stimingiswhenpressingthekey.
AdvancedTechniques
NonblockingI/O
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
193
control software platform:C# PDF File & Page Process Library SDK for C#.net, ASP.NET, MVC
You can use specific APIs to copy and get a specific page of PDF file; you can also copy and paste pages from a PDF document into another PDF file.
www.rasteredge.com
control software platform:C# PDF Page Rotate Library: rotate PDF page permanently in C#.net
Able to save to another PDF file after rotating PDF pages. Copy this demo code to your C# application to rotate C#.NET Demo Code to Rotate All PDF Pages in C#
www.rasteredge.com
Dependingonwhatotherflagsyoupass,youmaywanttoresettheterminalmorefullyattheendbyissuing
thecommand
stty sane
.InOSX,thisflagisidenticalto
-cbreak
,butinLinuxandsomeotheroperating
systems,the
sane
flagisasupersetofthe
-cbreak
flag.
TimingLoops
Onrareoccasions,youmayfindtheneedtoperformsomeoperationonaperiodicbasiswithgreaterthanthe
onesecondprecisionofferedby
sleep
.Althoughtheshelldoesnotofferanyprecisiontimers,youcanclosely
approximatesuchbehaviorthroughtheuseofacalibrateddelayloop.
Thebasicdesignforsuchaloopconsistsoftwoparts:acalibrationroutineandadelayloop.Thecalibration
routineshouldexecuteapproximatelythesameinstructionsasthedelayloopforaknownnumberofiterations.
Thenatureoftheinstructionswithinthedelaylooparelargelyunimportant.Theycanbeanyinstructionsthat
yourprogramneedstoexecutewhilewaitingforthedesiredamountoftimetoelapse.However,acommon
techniqueistoperformnonblockingI/Oduringthedelayloopandthenprocessanycharactersreceived.
Forexample,Listing11-10showsaverysimpletimingloopthatreadsabyteandtriggerssomesimpleecho
statements(dependingonwhatkeyispressed)whilesimultaneouslyechoingastatementtothescreenabout
oncepersecond.
Listing
11-10
Asimpleone-secondtimingloop
#!/bin/sh
ONE_SECOND=1000
read_test()
{
COUNT=0
local ONE_SECOND=1000
# ensure e this never r trips!
while [ [ $COUNT T -lt t 200 ] ] ; ; do
CHAR=`./getch`
if [ [ $1 1 = = "rot" " ] ] ; ; then
CHAR=","
fi
case "$CHAR" in
AdvancedTechniques
TimingLoops
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
194
control software platform:VB.NET PDF File Merge Library: Merge, append PDF files in vb.net
Combine multiple specified PDF pages in into single one file. Merge PDF without size limitation. Append one PDF file to the end of another one in VB.NET.
www.rasteredge.com
control software platform:C# PDF File Merge Library: Merge, append PDF files in C#.net, ASP.
Free online C#.NET source code for combining multiple PDF pages together in .NET framework. Append one PDF file to the end of another and save to a single
www.rasteredge.com
( "q" | | "Q" )
CONT=0;
GAMEOVER=1
;;
( "" )
# Silently ignore e empty y input.
;;
( * * )
echo "Unknown key $CHAR"
;;
esac
COUNT=`expr $COUNT T '+' 1`
while [ [ $COUNT T -ge $ONE_SECOND ] ] ; ; do
COUNT=`expr $COUNT T - - $ONE_SECOND`
MODE="clear";
draw_cur $ROT;
VPOS=`expr $VPOS S '+' 1`
MODE="apple";
draw_cur $ROT
done
done
}
calibrate_timers()
{
2>/tmp/readtesttime time $0 -readtest
local READ_DUR=`grep p real /tmp/readtesttime | | sed d 's/real.*//' | | tr r -d ' ' '`
# echo "READ_DUR: : $READ_DUR"
local READ_SINGLE=`echo "scale=20; ; ($READ_DUR R / / 200)" | | bc`
ONE_SECOND=`echo "scale=0; 1.0 / / $READ_SINGLE" " | bc`
# echo "READ_SINGLE: $READ_SINGLE";
# exit
AdvancedTechniques
TimingLoops
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
195
control software platform:C# PDF Text Extract Library: extract text content from PDF file in
Enable extracting PDF text to another PDF file, TXT and source PDF document file with a copy-and-paste C# example code for text extraction from all PDF pages.
www.rasteredge.com
control software platform:VB.NET PDF copy, paste image library: copy, paste, cut PDF images
PDF document images. Allow to copy an image from existing PDF file and paste it into another one. Guarantee high performance image
www.rasteredge.com
echo "One second is s about t $ONE_SECOND D cycles."
}
if [ "x$1" " = = "x-readtest" ] ] ; ; then
read_test
exit
fi
echo "Calibrating.
Please wait."
calibrate_timers
echo "Done e calibrating.
You should d see a a message about once e per r second.
Press
'q' to o quit."
stty -icanon -isig
GAMEOVER=0
COUNT=0
# Start t the game loop.
while [ [ $GAMEOVER -eq 0 0 ] ] ; ; do
# echo -n n "Enter r a a character: : "
CHAR=`./getch`
case "$CHAR" in
( "q" | | "Q" )
CONT=0;
GAMEOVER=1
;;
( "" )
# Silently ignore e empty y input.
;;
( * * )
echo "Unknown key $CHAR"
;;
esac
COUNT=`expr $COUNT T '+' 1`
while [ [ $COUNT T -ge $ONE_SECOND ] ] ; ; do
AdvancedTechniques
TimingLoops
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
196
COUNT=`expr $COUNT T - - $ONE_SECOND`
echo "One second d elapsed (give or take)."
done
done
stty sane
Inareal-worldtimingloop,youwillprobablyhavekeysthatperformcertainoperationsthattaketime—moving
apieceonacheckerboard,forexample.Inthatcase,yourcalibrationshouldalsoperformaseriestoteststo
approximatetheamountoftimeforeachofthoseoperations.
Ifyoudividethetimefortheslowoperationbythedurationofasinglereadoperation(
READ_SINGLE
),you
candiscernanapproximatepenaltyforthemoveusingiterationsofthemainprogramloopastheunitvalue.
Then,whenyouperformoneofthoseoperationslater,yousimplyaddthatpenaltyvaluetothemainloop
counter,thusensuringthatthe"Onesecondelapsed”messageswillquicklycatchupwith(approximately)
wheretheyshouldbe.
Youcanapproximatethisfurtherbyusinglargernumbersinyourloopcountertoachievegreaterprecision.
Forexample,youmightincrementyourloopcounterby100insteadofby1.Thiswillgiveamuchmoreaccurate
approximationofthenumberofcyclesstolenbyaslowoperation.
Warning:  Ifyouperformsignificantmultiplication(forexample,toincreasegameplayspeedon
subsequentlevels)tochangetherateofyourtimer,usinglargervaluesmeansthatyouaremuchmore
likelytoexceedthemaximumvaluethatshellmathor
expr
mathcanhandleduringyourinterim
calculations.Insuchcases,youmayfinditbettertouse
bc
,whichworkswithfloating-pointquantities.
BackgroundJobsandJobControl
Forend-userconvenienceinthedaysoftextterminalsbeforetheadventoftoolslike
screen
,theCshell
containsjobcontrolfeaturesthatallowyoutostartaprocessinthebackground,thengooffandworkon
otherthings,bringingthesebackgroundtasksintotheforeground,suspendingforegroundtaskstocomplete
themlater,andcontinuingthesesuspendedtasksasbackgroundtasks.
Overtheyears,manymodernBourneshellvariantsincluding
bash
and
zsh
haveaddedsimilarsupport.The
detailsofusingthesecommandsfromthecommandlineisbeyondthescopeofthisdocument,butinbrief,
control-Zsuspendstheforegroundprocess,
fg
bringsasuspendedorbackgroundjobtotheforeground,and
bg
causesajobtobeginexecutinginthebackground.
AdvancedTechniques
BackgroundJobsandJobControl
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
197
Upuntilthispoint,allofthescriptshaveinvolvedasingleprocessoperatingintheforeground.Indeed,most
shellscriptsoperateinthisfashion.Sometimes,though,parallelismcanimproveperformance,particularlyif
theshellscriptisspawningaprocessor-hungrytask.Forthisreason,thissectiondescribesprogrammaticways
totakeadvantageofbackgroundjobsinshellscripts.
Note:  AllBourneshellvariantssupportrunningacommandinthebackground.However,the
informationobtainedaboutthesejobsvariesfromshelltoshell,andpureBourneshell
implementationsdonotprovidethisinformationatall.Thus,whenwritingscriptsthatusethis
functionality,youshouldbeawarethatyouaresignificantlylimitingtheportabilityofyourscript
whenyouuseBASH-specificorZSH-specificbuiltins.
AlsonotethattheseexamplesarespecifictoBASH.ForZSH,therearesubtledifferencesinthe
formattingofjobstatusthatwillrequirechangestovariousbitsofcode.Makingthiscodeworkin
othershellsisleftasanexerciseforthereader.
Tostartaprocessrunninginthebackground,addanampersandattheendofthestatement.Forexample:
sleep 10 0 &
Thiswillstartasleepprocessrunninginthebackgroundandwillimmediatelyreturnyoutothecommand
line.Tensecondslater,thecommandwillfinishexecuting,andthenexttimeyouhitreturnafterthat,youwill
seeitsexitstatus.Dependingonyourshell,itwilllooksomethinglikethis:
[1]+
Done
sleep 10
Thisindicatesthatthesleepcommandcompletedexecution.Arelatedfeatureisthe
wait
builtin.Thiscommand
causestheshelltowaitforaspecifiedbackgroundjobtocomplete.Ifnojobisspecified,itwillwaituntilall
backgroundjobshavefinished.
Thenextexamplestartsseveralcommandsinthebackgroundandwaitsforthemtofinish.
#!/bin/bash
delayprint()
{
local TIME;
TIME=$1
echo "Sleeping g for r $TIME E seconds."
AdvancedTechniques
BackgroundJobsandJobControl
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
198
sleep $TIME
echo "Done e sleeping for $TIME E seconds."
}
delayprint 3 3 &
delayprint 5 5 &
delayprint 7 7 &
wait
Thisscriptisarelativelysimpleexample.Itexecutesthreecommandsatonce,thenwaitsuntilallofthemhave
completed.Thismaybesufficientforsomeuses,butitleavessomethingtobedesired,particularlyifyoucare
aboutwhetherthecommandssucceedorfail.
Thefollowingexampleisabitmorecomplex.Itshowstwodifferenttechniquesforwaitingforjobs.Youshould
generallyusetheprocessIDwhenwaitingforachildprocess.YoucanobtaintheprocessIDofthelastcommand
usingthe
$!
shellvariable.
If,however,youneedtoinspectajobusingthe
jobs
builtin,youmustusethejobID.Itcanbesomewhat
clumsytoobtainajobIDbecausethejobcontrolmechanisminmostBourneshellvariantswasdesigned
primarilyforinteractiveuseratherthanprogrammaticuse.Fortunately,therearefewthingsthatawell-written
regularexpressioncan’tfix.
Note:  RegularexpressionsaredescribedinRegularExpressionsUnfettered (page 100).Forthe
purposesofthisexample,itissufficienttounderstandthatthesubroutine
jobidfromstring
takes
ajobstringliketheoneshownpreviouslyandprintsoutthefirstsingledigitormultidigitnumber
byitself.
#!/bin/bash
jobidfromstring()
{
local STRING;
local RET;
STRING=$1;
RET="$(echo $STRING | | sed 's/^[^0-9]*//' | | sed 's/[^0-9].*$//')"
AdvancedTechniques
BackgroundJobsandJobControl
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
199
echo $RET;
}
delayprint()
{
local TIME;
TIME=$1
echo "Sleeping for $TIME E seconds."
sleep $TIME
echo "Done e sleeping for $TIME seconds."
}
# Use the job b ID for this one.
delayprint 3 3 &
DP3=`jobidfromstring $(jobs s %%)`
# Use the process s ID this time.
delayprint 5 5 &
DP5=$!
delayprint 7 7 &
DP7=`jobidfromstring $(jobs s %%)`
echo "Waiting for job $DP3";
wait %$DP3
echo "Waiting for process ID D $DP5";
# No o percent because it t is s a a process ID
wait $DP5
echo "Waiting for job $DP7";
wait %$DP7
AdvancedTechniques
BackgroundJobsandJobControl
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
200
Documents you may be interested
Documents you may be interested