Home

BAKALÁŘSKÁ PRÁCE - Univerzita Karlova v Praze

image

Contents

1. p name value declares new environment variables arrays a functions f F or lists their values 7p or sets finds out the integer i read only r and export x status The t attribute is ignored and integer attribute may be set but has no special meaning otherwise behaves same as Bash e echo neE arg prints its arguments to the standard output If n is set the ending new line character is suppressed The other options are ignored escape characters are not interpreted e help s command pattern displays a usage message for commands that match given patterns The detailed description is not supplied so the s option is assumed always turned on If no parameters are given help displays the list of all commands supported by BashCommander e let expression expression each expression one argument is evaluated the same way as in an arithmetical command same as in Bash e read rs t timeout p prompt a array n nchars d delim name reads the values of given variables from standard input May read elements of an array a end when given number of characters is read n or a timeout seconds elapses t divide the values with a custom delimiter d and display a prompt p For r reads raw input s suppresses the echoing of characters read Splits the characters using IFS and sets the resulting fields in the variables supplied or in REPLY variable the suppor
2. sti programu docela ast 3 5 Prom nn prost ed shellu Ve ker informace o prom nn ch a jin ch objektech nach zej c ch se v prost ed b c ho shellu jsou ulo eny a na v jimky p i spou t n p kaz na pozad vjedin instanci t dy Env Ta m e krom hodnot prom nn ch poskytovat i dal funkce v pisy apod Nejde z hlediska n vrhu o nej ist e en ale vzhledem k v cem n n hodn pot eb r zn ch funkc r zn mi programy a nutnosti jejich centr ln ho ulo en o z ejm nejjednodu V prom nn m prost ed se tak nach z seznam v ech prom nn ch v etn speci ln ch jako je k d skon en posledn ho spu t n ho p kazu alias hash cest ke spou t n m program pol i u ivatelem nadefinovan ch funkc ten je implementov n kontejnerem typu multimap s vyhled v n m podle n zv spole n se z sobn kem vol n funkc z sobn kem ve ker ch p esm rov n objektem nastaven a objektem o et en sign l D ky z sobn kov struktu e seznamu p esm rov n je mo n uchov vat informace o v ech otev en ch vstupech a v stupech bez jejich vz jemn ho p eps n a jednodu e vracet na dotaz trojici aktu ln platn ch standardn ch handles bez jejich vz jemn ho p eps n Tato funkce je velice asto vyu van v echny tec a v pisov funkce i nastaven vstup a v stup pro spou t n programy se bez n
3. aktu ln ho vzhledu konzole P ed odesl n m ka d dosti o p ekreslen shell p ekop ruje pr v zobrazovan pohled pr v na toto m sto GUI odtud na t znaky a postupn je zobrazuje Sd len pam se pou v je t pro ovl d n shellu ze souborov ho mana eru V takov m p pad je pro ka d p kaz pos lan commanderem Bashi vytvo ena nov oblast sd len pam ti m e se znovu pou t ji existuj c p jemce toto ale nepozn a mapov n prov d poka d a do n p eps n jeho text Stejn se d je i p i zm n pracovn ho adres e V commanderu Neobvyklym p padem v komunikaci mezi GUI a shellem je vyd n p kazu ke spu t n souboru vybran ho ve v pisu v okn commanderu Pokud u ivatel stiskne Enter a m v souborov m mana eru vybran n jak dek v seznamu nap ed se o t to ud losti dozv s m shell jeho GUI okno m v dy privilegium p ij mat vstup z kl vesnice a automaticky ho i v etn stisku t to kl vesy p epos l p mo k n mu Pouze shell je nav c schopen rozhodnout o n sledn prov d n akci pokud toti jeho vstup ji obsahuje n jak zadan p kaz mus se prov d t ten a kdy ne je douc aby commander otev el nebo spustil soubor podle u ivatelova v b ru Proto shell pos l sv d c aplikaci v sledn rozhodnut a pokud jde o spu t n programu pod kurzorem dost v jeho cestu a 21 p
4. na umo n n spu t n konfigura n ch a instala n ch skript nikoliv na interaktivn pr ci u ivatele kter je ale tak mo n Oproti Cygwinu nebo i BashCommanderu v ak nelze ne se spokojit se standardn m konzolov m oknem kter nab z opera n syst m Podpora vlastnost GNU Bashe je takt stoprocentn a to aktu ln ve verzi 3 1 tak doch z ke kompilaci z p vodn ch zdrojov ch k d ale pro Bash je alespo p i sta en bin rn ch soubor p mo od zdroje st le pot eba podp rn ch knihoven a integrace do syst mu tak vypad podobn jako u Cygwinu Na internetu lze tak nal zt samostatn bashov aplikace pro Windows kter nejsou sou st v t ch projekt nap Steve org uk GNU Bash for Windows 9 zalo en na zdrojov ch k dech star verze Bashe 2 03 Jeho podpora je tedy tak pln ale dnes jde o ji zastaralou verzi z roku 1999 Nepot ebuje dn b hov 27 prost ed jen jednu dynamickou knihovnu kter je s n m ale dod van jde ve skute nosti o k d od GNU kompilovan s pomoc p edch dce Cygwinu Tato implementace funguje m ale probl my p i spolupr ci s textov mi utilitami GnuWin32 citlivost na znaky konce dk CR LF a integrace do Windows tak nen pln Lep v sledky v tomto ohledu dosahuje win bash 10 tak nejde o p m p eps n ale port existuj c ch k d od GNU zde pln bez pot eby n jak ch
5. p pad o kter m se je t zm n m pozd ji je spojen HANDLE pro vstup nebo v stup s objektem a funkce na n m V GUI bylo e en nej ast j ho probl mu to jest spojen okna s objektem n le c m k n mu v v ech pot ebn ch prom nn ch realizov no pomoc program torem definovan ho pointeru kter je d ky funkci Win32 API mo n ulo it ke ka d mu vytv en mu oknu a kter okno dostane v parametrech vytv ej c funkce detaily viz SetWindowLongPtr v 7 Procedura standardn ho tvaru kter p ij m syst movou zpr vy pro dan okno potom hodnotu tohoto pointeru zjist a pou ije jako odkaz na p slu n objekt kter mu p ed zpr vu B hem zpracov n zpr vy se tak volaj u funkce na konkr tn m objektu Sch ma Bashe a jeho rozd len na r zn sti podle funkce je zhruba n sleduj c hlavn objekt typu WinShell zprost edkov v na ten i spou t n v ech p kaz Obsahuje objekt Parser kter je zodpov dn za spr vn d len p kaz a jejich jednotliv ch typ podle nich vyr b ze vstupu r zn objekty v elijak strukturovan ch p kaz nap while for jednoduch p kaz a ostatn druhy p kaz Bashe maj sv C t dy b hem pr ce uchov v ste n zpracovan vstup Hlavn objekt od parseru dost v objekty p kaz kter postupn spou t a n sledn shroma uje pro op tovn pou it Mohou b t ulo eny ve
6. Like Bash BashCommander has its execution environment a set of things common for all executed commands The environment may contain string variables aliases functions described in the next section and one dimensional arrays Variables and arrays may be set as integer with the declare command but BashCommander does not treat them in any special way like GNU Bash or they may be set as read only functions too using the readonly command The 39 BashCommander environment is not identical to the Windows program environment it s operated internally You may however declare variables and functions as exported via the export command and then they are copied to the Windows program environment too and therefore they are visible in all the programs launched from within BashCommander e g running scripts etc Variables and arrays may be assigned to at the beginning of each command the syntax is var name value Shell expansions except word splitting and file name matching are performed on the value before the assignation If the command following the assignation is not empty given values are valid for this command only Otherwise they re valid for all the following commands until any further change Array variables may be assigned to directly array subscript value subscript value or through their subscripts array subscript value Arrays are one dimensional with numerical subscripts they are eva
7. MS DOS a pou van i na modern ch syst mech Norton Commander Total Commander Umo uj rychlej pr ci s v ce soubory podporuj r zn kl vesov zkratky a n kter z nich maj mnoho pokro ilej ch funkc jejich hlavn p ednost je v ak d raz na ovl d n kl vesnic a zobrazen ve dvou panelech Dal mo nost je vyu it p kazov dky textov ho shellu Zjednodu uje u ivateli opakovan kony pomoc skript a d vkov ch soubor Naopak pln z kladn akce jako v pis seznamu soubor v adres i jsou oproti p edchoz m variant m o trochu t kop dn j Nav c na v dne n dob nejv ce pou van m opera n m syst mu Windows nej ast ji st le ve verz ch XP a 2000 je i automatizace d vkov mi soubory bat pon kud nepohodln Opera n syst my typu Unix nab zej v b r n kolika shell a tedy i skriptovac ch jazyk z nich nejb n j a pom rn p stupn a inn je Bash 1 Tato bakal sk pr ce se bude v novat jeho za len n do syst mu Windows a spojen s druh m efektivn m zp sobem pr ce se soubory dvoupanelov m souborov m mana erem 1 2 Zad n pr ce P edm tem pr ce je vytvo it program pro efektivn spr vu soubor a pou v n textov ch p kaz pro Windows P jde o dvoupanelov souborov mana er t sn prov zan s konzol pro textov p kazy pou vaj c syntaxi unixov ho Shellu P i
8. Scroll the console one page up Shift PageUp Scroll the console one page down Shift PageDown Shell auto complete function Tab The second one is for use within file manager windows only however the two set must not overlap i e if you set the same key combination for second action in any of the sets the first action will not have any short cut assigned Action Short cut Move the highlight one line up Up Move the highlight down Down Move one page up PageUp Move one page down PageDown Switch between panels Ctrl Tab Select deselect highlighted file Ctrl Space Toggle file selection and move up Ctrl Up Toggle file selection and move down Ctrl Down Select all files Ctrl A 3 Programmer s manual 3 1 Used language The whole application code is written in C language with heavy use of the STL libraries mostly string sstream vector ete Many of the internal supportive structures are derived classes of some STL containers or have STL container features Use of parameter pointers is preferred over the use of plain parameters to improve speed at most places this means that most of the structures have internal pointers and need to have explicit destructor functions The return values of supportive functions may be either const pointers and then they should not be deleted or a normal pointers and then it s up to the calling function what to do with the pointer In most cas
9. The syntax is if conditionl commands then executive commands elif condition2 commands then executive commands else executive commands fi As in GNU Bash there may be more elif branches or the else and or elif branch may be missing e case matches a word against sets of shell patterns and executes the commands corresponding to the first fitting one if the word matches one of the patterns in the set Has the same behaviour as in GNU Bash the syntax is following case word in patternla patternlb commands pattern2 commands esac The BashCommander parser however does not allow the lists of patterns to be enclosed in both parentheses as in GNU there must be the right parenthesis only For details on patterns there are some limitations see Patterns e select allows for user selections i e simple menus The syntax is similar to the for command including the fact that given no value list it uses the positional arguments select var name in valuel value2 do commands done It also has the same behaviour as Bash repeats asking user for input the line number sets the control variable accordingly and executes the commands in the loop e arithmetical command computes a given arithmetical expression along with any side effects it may have variable assignations and returns a zero OK exit status if the value of the expression was non zero The behaviour is the same as in Bash arithmetical expre
10. VERUMEI o eene REIS dut Anu DM Vn AM ed 22 Bal Parser a prikazy 1010 NNN tor O etin v m taut iane t lumus 24 25 Prom nn prost ed shelli coisir ra maie task khaki ure nbn RISE 25 Elitr RT T 27 4 1 Srovn n s jin mi implementacemi Bashe ve Windows 27 4 2 Hodnocen spln n c le pr amp ce iu ees ei kika adiudu sloiakok de MA ete QUE 28 Lt o T 29 MVEA PM CM SOV P O PEK PRO P T T 30 P loha As dokumentace Gumglic Ry aus avsak evqew poA ase 31 TAbout the DOE LAT es eres occ PERIERE uva QT eed top In PGA NN MEDI PHA 31 TA SOT Tata Oi ce seo did aoa HOMINEM M MUT I Uem kaki DN MEM MEN 31 12 ql UE RET TOT 31 1 5 Dn ERLEORUS ce ct HE TRU rU pu TEN prada Cadeau aed ai au RE VMR I rti 32 PALA hi EURDZIC RT CT 33 2 1 Installation unimnstallatiOni uiid eet au seoidasd ednisd cok coden da ka DNA ERES 33 2 2 Usine the GU Denince ena UNAM QI MEM serene et EEGA 33 2 3 The Bash scripting apad Beast ertet ev tI css Rusa centas 34 23 l COmMmmMaIndS AAS ER O O E P M E eee 35 2 3 2 Platrcortibadide sicco eme ec i Inr ee 35 2 3 3 Structured COINS asco Ert rbv icio EUN MNT EE Bari PU E MEME CIR UNT 36 2 34 EXDatslOlls enee apu aM DRAN NN em kasta eMe AU CUN OECD eaten 38 2 3 5 Environment variables uocis ere REN UR ER D RE RAIN Hes pA 39 PRATE DOTEE O I SS adiectione ec iv Sur E Ursa be utu Du da MU OREL UE 41 2 07 ATi MING C ooi Roter nma Tast
11. d Command je definov na virtu ln funkce exec kter p kaz provede proto je mo n spou t t postupn v echny operace cyklu bez ohledu na jejich strukturu V echny se tak um j p ev st v etn sv ch vno en ch zp t na text co slou zejm na historii p kaz Pro ve ker operace kter pot ebuj pro svoje vykon n nahrazov n jmen soubor prom nn ch aritmetiku apod inicializuj jednotliv p kazy speci ln objekty b n jde hlavn o t du Expandor a volaj jejich funkce b hem sv ho prov d n Kontrola toku pomoc bashov ch vol n break a continue je zaji t na speci ln mi typy C v jimek kter zachycuj pr v jen strukturovan p kazy p i b hu strukturovan jazykov konstrukce se tak tok k du vr t p esn na pot ebn m sto Jako hlavn kontejner pro p kazy je pou v na speci ln t da Cmavect odvozen od standardn ablony vector z knihoven STL a to jak uvnit samotn ch strukturovan ch p kaz tak glob ln v hlavn m objektu shellu pro udr en historie p kaz Slou tak k p ed v n p kaz ze vstupu po anal ze parserem D ky jej m funkc m lze p kazy jednodu e spou t t skupinov v etn pipelines nebo podm n n ch konstrukc s oper tory amp amp a Pou it odvozenin standardn ch ablon obohacen ch o dal funkce pro jednoduchou pr ci s danou strukturou je obecn v bashov
12. dkou syst mu tak e se pro pou it v projektu v t inou nehod N kter operace se nav c ve Windows neprov d v bec p eform tov n textu p i zm n velikosti konzolov ho okna Pravd podobn nejv t m probl mem konzolov ch oken ve Windows je praktick nemo nost detekce zm ny na v stupu pokud aplikace spu t n zevnit konzolov ho programu n co vyp e do t to konzole vn j program se o zm n nedozv a nem mo nost ji nijak propagovat ven tedy ani do GUI termin lov ho programu viz 5 V diskutovan ch opera n ch syst mech je tak p stup k vstupu a v stupu do a ze soubor pojat rozd ln V Unixu je v podstat libovoln za zen ozna eno jako soubor v konzole a je udr ov n seznam tzv file descriptor speci ln ch popisn ch datov ch struktur otev en ch soubor kter se p ed v potomk m spu t n m rodi ovsk m programem Naproti tomu ve Windows se pro p stup k soubor m ale i jin m objekt m jejich druh je ov em mnohem podrobn ji rozli ov n pou v speci ln ho typu HANDLE jde vlastn o identifika n slo otev en ho objektu kter je mo n jednak p ed vat spou t n m potomk m a jednak pos lat jin m proces m dal mi zp soby Probl m s HANDLE a dal mi operacemi se objevuje p i pokusu o kontrolu spou t n ch aplikac ta ve Windows na rozd l od unixov ch syst m prakticky neexistuje p
13. jm no adres e nebo i po adovat p ed jejich spu t n m vstup od u ivatele a ten v nich pak pou t Commander jen vlo do v sledn ho p kazu aktu ln hodnoty po adovan ch prom nn ch viz u ivatelsk dokumentace a p ed Bashi p kaz kjeho spu t n Takto jde vytvo it nap s pomoc v projektu obsa en ch unixov ch program v echny b n funkce souborov ch mana er kop rov n p episov n vytvo en adres e apod p i em mo nosti jejich nastaven se neomezuj zdaleka jen na toto Pokud jde o podporu v ech vlastnost Bashe sna il jsem se o co nejv t a z rove smyslupln rozsah kter je s prost edky Win32 API a v r mci tohoto projektu dosa iteln Jako v choz popis vlastnost slou il referen n manu l Bashe 1 p padn pro testy nep li podrobn zdokumentovan ch funkc GNU Bash ve verzi 3 1 V r mci podporovan ch funkc by m ly b t ob verze ekvivalentn Z jazyka je mo n pou t ve ker konstrukce krom substituce proces process substitution a here dokument n kter dk syntaktick obraty hlavi ky funkc bez p esm rov n gt amp tak podporov ny nejsou Omezen m i podpora wildcard a nastaven vlastnost chov n shellu Vynech ny byly n kter nep li d le it nebo ve Windows implementa n p li n ro n i nesmysln intern p kazy jmenovit bind enab
14. kdy nejsou otev en dn panely shell p ev d n na aktu ln okno shellu i pokud je toto okno zobrazov no jako sou st commanderu M e tak jednodu eji pos lat vstup sv instanci Bashe k testov n kl vesov ch zkratek vol funkce na objektu hlavn ho okna Pro pr ci vcommanderu byla zvolena varianta bez p ep n n kontextu tedy vstup z kl vesnice p ij m v hradn okno shellu a p padn ho p epos l pr v aktivn mu panelu s v pisem soubor To vynucuje pou it v ce kl vesov ch zkratek kter se nesm j kr t ale zase je mo n nastavit i ovl d n pohybu mezi 18 soubory ve v pisu co by v p pad e by tento standardn ovl dac prvek skute n p ij mal vstup z kl vesnice nebylo mo n Pr ce s commanderem bez p ep n n kontextu nav c vy aduje rozli ov n mezi spou t n aplikac z v pisu stiskem kl vesy Enter a od dkov n m na konzoli to je e eno pomoc p kaz kter konzolov st pos l GUI v ce viz 3 1 Pokud v bashov sti b p kaz nelze spou t t dal ani p ech zet mezi adres i Commanderov sti byla pro v t prov z n s Bashem d na je t jedna vlastnost samotn souborov mana er um jen vypisovat soubory a spou t t p kazy v Bashi pro ty lze ale nastavit kl vesov zkratky a do jejich textu je mo n vlo it n zvy vybran ch soubor z panelov ho v pisu p padn
15. own thread and commanders run in tabs classes ShellWindow and Commander and may open the settings dialogue represented by the SettingsDialog class The MainWin ShellWindow and Commander classes and their C inheritance connections are described in detail in the subsections There are several settings dialogue windows in the GUI and corresponding to them there are setting dialogue classes SettingsDialog ShortcutDialog and CustomCommandDialog Generally if a class is bound with a window its instance is the window itself i e upon window creation the pointer to the object the window belongs to is set up at the standard Win32 API GWLP USERDATA place holder and in the window procedure all the messages are redirected to a similar procedure invoked on this object So the window is totally bound with its instance of a class and all the actions are processed through this instance The class itself has the window Win32 API HWND value as one of its members so the connection is mutual The GUI settings are stored and loaded from a file via the Settings class There s a special struct to represent the settings in the memory SettingsData The keyboard short cuts have their settings stored in special classes which are enclosed in the global settings The most important is ShortcutData a container capable of testing for the presence of a given shortcut For the file manager custom command short cuts there s the CustomCommandData class that
16. p edpoklad bez p ep n n kontextu a se spou t n m p kaz kl vesov mi zkratkami p padn termin lov emul tor oboj kombinovan s interpretem jazyka Bash Podpora syntaxe Bashe a unixov ch p kaz tak odpov d zad n jedin co jsem p edpokl dal ve v t m rozsahu jsou mo nosti nastaven barev pro konzolov okna automatick dopl ov n n zv soubor a obecn v t p v tivost k u ivateli Za hlavn p nos pr ce pova uji jednak implementaci jazyka Bash pod Windows kter je s opera n m syst mem t sn prov zan a jednak kombinaci souborov ho mana eru s textov m shellem bez nutnosti p ep nat mezi dv ma aplikacemi veZ U ite nost programu by rozhodn pr v snadn j operace s grafick m rozhran m o hodn zv ily zad n pr ce s n m takov m nepo talo ale v razn m vylep en m by byla rozhodn spolupr ce s vnit n schr nkou Windows pro vkl d n a kop rov n textu na konzoli nebo podpora technologie drag and drop v p pad p esouv n soubor v commanderu BashCommander nyn spolupracuje s opera n m syst mem velice t sn pokud jde o textov prost ed Bashe v GUI v ak je co zlep ovat 28 5 Z v r Program by m l nal zt vyu it zejm na u u ivatel kte ve Windows asto operuj se soubory pomoc dvoupanelov ho mana eru a z rove pou vaj p kazovou dku nebo n kterou z ji existu
17. vol n je pou ito ist Win32 API bez roz en MFC jednak vzhledem k m m p edchoz m zku enostem jednak kv li ot zce rychlosti k du nutnosti pou it speci ln ch dynamick ch knihoven a umo n n kompilace zdrojov ch k d ve voln dostupn verzi Microsoft Visual C p esto e k v voji bylo pou ito pln MS Visual Studio NET 11 2 Anal za probl mu 2 1 N vrh P i uva ov n rozd len cel aplikace se objevuje n kolik ot zek Prvn z nich je propojen termin lov ho programu souborov ho mana eru samotn ho shellu a funkc pro pr ci se soubory je mo n v e integrovat do jednoho spustiteln ho modulu nebo naopak funkce v ce i m n striktn odd lit V takov m p pad je d le nutn e it zp sob a m ru komunikace mezi takto vznikl mi sou stmi Na druhou stranu slou en v ech komponent ste n nebo zcela zamez jejich odd len mu vyu it zven co pova uji za dost v raznou nev hodu Bez ohledu na GUI aplikace a funkce pro pr ci se soubory je nutn d le navrhnout vnit n stavbu samotn ho shellu kter je z ejm technicky nejslo it j sou st aplikace Jde nap o probl m d len funkc pro ten a zpracov n p kaz a v echny operace kter s nimi shell mus prov st p padn jejich uchov v n s ohledem na znovupou it e en vy aduje i nalezen zp sobu jak m bude shell operovat s objekty opera n ho sys
18. branches FunctionCommand representing the whole code of a function and finally ListCommand that serves for sub shell execution and plain command lists All the commands have their execSync method overridden the right way for their execution All the commands must have all their arguments and sub commands supplied upon creation which happens in parser the subcommands of the incomplete commands are stored in ctriStack and then put together into the constructor for the specific command The commands may be also copied using the clone method which is also virtual and always creates the right type for the given command 3 5 5 Expansions and execution For all the shell expansions the command objects use the Expandor class That is derived from ArgExpandor class which is able to perform the expansions on everything except variable assignations and file redirections The ArgExpandor class is used in some cases where those are not needed There are also several supportive expansion classes i e for to split test expressions or to create variables from given name and value strings or to be used in the auto completion feature AutoCompletor All the expansion classes are derived from the ExpansionBasicFunctions class that provides several vital functions for any expansion the most important is findNestedEnd that given a string and a position searches for the end of the nesting e g parameter expansion nested command using a nest
19. en kl ov Alternativa pou it vl ken vy aduje dodate nou synchronizaci kterou ale lze pomoc prost edk OS zajistit Nav c otv r mo nost v t integrace prom nn ho prost ed Bashe kter se kv li mnoha spou t n m potomk m v Unixu t t nap p i ten z pipeline p kazem while co je sice vlastnost odli n od unixov verze ale pro program tora skript v naprost v t in p pad p zniv Techni t j m probl mem je p stup ke konzolov m funkc m Windows je sice mo n je pln ignorovat a implementovat vlastn pseudokonzoli s pomoc rour ale t m dojde ke ztr t dal ch informac nap o barv ch a stisc ch kl ves kter se nep ev d j na platn znaky tak e pro jednoduch programy by byl takov syst m vhodn j ale slo it j m kter pou vaj n zko rov ov konzolov funkce by uzav ral cestu Dal alternativou je pou it n zko rov ov ho konzolov ho API Windows to sice p edstavuje naprogramovat znovu vy funkce textov ch oken proto e pro b n pou it v programu je nutn jednotn p stup ke konzol m rour m i soubor m zato dovoluje spou t t libovoln programy a prov d t s konzol i slo it j operace vy adovan nap bashovou funkc read Pou it vysoko rov ov ho API je implementa n nen ro n a pro spou t n libovoln ch program vyhovuj c ale omezuje
20. getter functions return a direct constant pointer to the inside of the environment unless specified otherwise in the code so the value of e g a string may be used directly but for write operations a copy is required Some of the getter functions just return the value e g of an array element some return directly the object that stores it Besides that Env is used to store all the input and output handles The getStdHandles method returns a const pointer to the handles that are currently valid for the application all commands before their execution push their input output handles containing any redirected handles or NULL s onto Env s so called pipe stack pipeStackPush After their execution they are no longer valid for the environment and may be pushed off pipeStackPop The getStdHandles function browses the stack from the upper side until it finds valid non NULL handles for all the standard streams and returns the result in a copy If some of the handles are still NULL all the way through the stack it returns the standard handles for the shell process This computation is moreover buffered and performed only when the handles change Env also stores a copy of the process input handle needed because of the buffering see Input and output handles and a copy of the input handle from the time the shell was launched needed if the read function is called from within a script that has its main input handle redirected to read the comm
21. h and except cpp that contains definitions of most of the exceptions Special exceptions used for control flow changes break continue etc are written in flowctrlexcept h and flowctrlexcept cpp The files intemds h intemds cpp and 52 intemds support cpp contain the implementation of all the supported shell internal commands The rest of the files are mostly some supportive structures such as signal handler sighandler h sighandler cpp shell settings settings h settings cpp or definitions of various containers e g the command container or input and output handles container residing in supstruct h and supstruct cpp The routines needed for communication with the GUI if run under GUI are located in msgthread h and msgthread cpp 3 2 4 The GUI The GUI code consists of relatively small number of files in the GUI folder The wmain function is located in the main cpp file The most important GUI object enclosing the main window is in the mainwin cpp file Its declaration along with the some supportive declarations is to be found in the mainwin h file The object responsible for displaying one shell tab is in shellwindow h and shellwindow cpp the file manager window is represented by commander h and commander cpp with a support class in inputbox h and inputbox cpp The abstract base classes for these windows are located in controller h and shell h The rest of the files involve mostly the settings of the whole GUI and keyboar
22. ho mana eru d le it je tak co nejlep kompatibilita s unixov m Bashem Hlavn m p nosem programu by m lo b t pokud mo no co nejhlad spojen konzolov ch operac s prac v souborov m mana eru a t m zefektivn n operac se soubory ve Windows P jde tak o dosa en pou itelnosti jako o n co pohodln j n hrady p kazov dky Windows d ky mo nosti otev t v ce oken sou asn a v t mu rozsahu nastaven a p izp soben u ivateli Aplikace by d le m la b t vyu iteln pro samostatn spou t n skript p mo z prost ed OS V pr ci nejde o implementaci unixov ho prost ed na platform Windows jak toto prov d nap projekt Cygwin 2 BashCommander bude co nejv ce prov z n se syst mem Windows a jeho nastaven m nap domovsk ch adres u ivatel cest ke spustiteln m soubor m apod Nav c z n j bude mo n spou t t v echny nativn aplikace pro Windows a u konzolov nebo grafick podobn jako je to mo n v unixov ch syst mech s grafickou nadstavbou nap KDE a Bash b c pod termin lov m programem Konsole 3 Tak se nejedn jen o p enesen Bashe pod Windows i kdy pr v tato st pr ce je z hlediska naprogramov n asov nejn ro n j Pr ce bude obsahovat i hlavn unixov programy pro pr ci se soubory a hlavn termin lov program kombinovan se souborov m mana erem po tom se nepo aduj
23. neobejdou proto bylo u ito jednoduch vyrovn vac pam ti pro n vratov hodnoty 25 O et en sign l je sou st prom nn ho prost ed hlavn kv li nutnosti zp stupn n jejich nastavov n z intern ho p kazu trap Je sice mo n upravit o et en v ech unixov ch sign l re ln funguje ale jenom SIGINT tedy Ctrl C spole n s intern mi bashov mi sign ly DEBUG apod Z podobn ho d vodu Env obsahuje i objekt nastaven shellu Operace s prom nn mi a poli slou hlavn nahrazov n jejich hodnot v textu ostatn funkce jsou vyu v ny pov t inou pro intern p kazy shellu jako nap declare readonly hash apod jimi prov d n nastaven ale berou v potaz v echny sou sti shellu 26 4 Hodnocen 4 1 Srovn n s jin mi implementacemi Bashe ve Windows Pokud je mi zn mo neexistuje dn aplikace kter by m la alespo zhruba stejn vlastnosti jako BashCommander a tedy se sn m p mo dala srovn vat Samoz ejm ale je mo n ho porovnat s jin mi projekty kter p ev d j Bash pod opera n syst m Windows u proto e pr v Bash je z hlediska k du nejobjemn j sti projektu Srovn n s b n mi souborov mi mana ery nen p li na m st je jasn e v po tu funkc tento projekt zdaleka p evy uj integraci se textov m shellem v ak u nich nal zt nelze Pravd podobn nejzn m j projekt kter se zab
24. pr ci s programem bude u ivatel moci rychle p ep nat mezi ovl d n m panel s v pisem soubor v adres ch a psan m do textov ho okna konzole Zm na pracovn ho adres e v panelov m v pisu se odraz i v konzolov m okn V stup spou t n ch textov ch aplikac bude mo n zobrazit v konzoli Konzolov ch oken program umo n otev t n kolik a p ep nat mezi nimi v panelech podobn jako u linuxov ch termin lov ch program Pro textov okno konzole i v pis soubor bude mo n nastavit font barvy a jejich rozlo en a toto nastaven ulo it Konzolov st aplikace se pokus sv m ovl d n m co nejv ce p ibl it unixov mu Bashi hlavn syntax p kaz a jazykov ch konstrukc ale i nap automatick m dopl ov n m n zv soubor nebo nastaven m promptu Integrov ny budou i z kladn unixov p kazy pro pr ci se soubory cd cp ls In rm mv apod nep jde ale o prost ed pro b h unixov ch aplikac Jako p kazy bude mo n spou t t nativn aplikace pro Windows Program bude podporovat i zpracov n soubor s bashov mi skripty Projekt bude ps n v jazyce C s vyu it m funkc Win32 API bude ur en pro opera n syst my Windows 2000 a XP 1 3 C l pr ce C lem pr ce je vytvo it program BashCommander pokud mo no podle definovan ho zad n s t m e hlavn d raz je kladen na spojen a spolupr ci jednotliv ch st konzole a souborov
25. speci ln ch pol ch kter implementuj funkce pro jejich celkov nebo ste n proveden najednou takto si je uchov v jak hlavn objekt tak jednotliv strukturovan nad zen p kazy Detaily pr ce s nimi viz odd l 3 4 Cel prom nn prost ed shellu je obsa eno v objektu t dy Env p kazy a ostatn objekty cel aplikace na n j uchov vaj ukazatel Intern p kazy Bashe jsou implementov ny jako statick funkce pro tento el vytvo en t dy Vzhledem k rychlosti v sledn ho programu a ji popisovan mo nosti lep integrace prom nn ho prost ed bylo p ed spou t n m st le nov ch kopi Bashe pro vno en p kazy a roury up ednostn no pou it vl ken Bash tedy pokud nen p mo vol no prov d n skriptu v extern m souboru nevytv svoje kopie prom nn prost ed z st v zachov no spole n pro v echny p kazy kter nejsou spou t ny na pozad to se t k i v ech p kaz v pipeline krom posledn ho To znamen e ostatn p kazy vid zm ny prost ed proveden i ve vno en ch p kazech a posledn ch p kazech v pipeline s unixov m Bashem toto sice nen kompatibiln ale v praxi k pou it vhodn j Synchronizace s takto vytv en mi vl kny nemus b t p li slo it v t inou se jedn o prost ek n na jejich skon en Pr ce s konzolov m oknem byla vy e ena pomoc n zko rov ov ho konz
26. stack There are also several support functions for the other classes The ArgExpandor class main function is expand which uses several other functions that correspond to all the kinds of expansions shell is supposed to perform i e expandBraces expandTilde expandVars expandNestedCommands which moreover use e g performNestedCommand or performVarSubstitution to do the executive work Because the quotes and backslashes that come as a result of an expansion must be retained these methods must have an indication of whether they are currently inside of quotes or not the inQuotes parameter If not the quotes apostrophes and backslashes that result from the expansion are all backslashed backslashUnquoted This holds only for the variable and nested commands substitution the other types either don t result in any quotes arithmetical substitution or are always unquoted tilde expansion file name matching for such types doubleBackslashReplace is used and no indication of being in quotes required For the command substitution ArgExpandor uses a special thread created from within performNestedCommand and represented by the nestedCmdThread function 60 3 5 6 Signal handler The signal handler is represented by the SigHandler class There s only one instance of it in the program which is shared by all the Env instances Upon startup the default Ctrl C event handler is set up ctrlCSignalHandler which resets the parser a
27. t dy Handle kter tvo nadstavbu nad standardn mi Windows API funkcemi Zvn j ku jde o obecn vstupy a v stupy pro s t mito objekty pracuj c funkce tedy neznamen pr ce s rourami konzol a souborem 22 dn rozd l Jednotliv instance t chto t d lze tak t m neomezen konvertovat z a na standardn typ HANDLE pro tento el jsou v k du naps ny speci ln C oper tory T da Handle vlastn obsahuje jen onen identifik tor vstupu nebo v stupu a mo nost zji t n zda jde o konzoli i p esm rov n do souboru VW Z obou odvozen ch typ je OutputHandle ten jednodu nebo jeho metody mohly b t vytvo eny s pou it m standardn API funkce WriteFile kter v t inu pot ebn ch krok zajist sama V stup do soubor a rour pou v dle sou asn ch zvyklost intern k dovou str nku Windows p ed vol n m WriteFile jsou do n p evedeny pro z pis na konzoli je pro zachov n znak v k dov n Unicode pou ito vol n WriteConsole kter je na rozd l od p edchoz ho schopn se s Sirsimi znaky vypo dat bez dal ch prav Z pis do zvolen ho OutputHandle se prov d vol n m p et en ho oper toru operator lt lt a je tak mo n pou vat tento typ podobn jako ostream z C Vytvo en t dy pro ten ze vstupu bylo pon kud slo it j Je zde nutn rozli ovat mezi r zn mi druhy vstupu a pokud jde o konzoli pou vat pouze
28. the exit status of the last one of them is non zero runs the executive commands and test commands again Otherwise the looping ends e while is similar while test commands do executive commands done As in GNU Bash this continues looping until the exit status of the last of the test commands is non zero e for a different kind of loop and also same as that in Bash The syntax is for var name in words do commands done This takes the variable and for each iteration sets it a value from the list given or from the positional arguments see Environment variables if there is no list The loop iterates as many times as the number of values given or the number of positional arguments the shell has got e arithmetical for different from the usual for loop more similar to the one that is found in C C and other programming languages The syntax for initial expression test expression iterate expression do commands done It treats the things it finds in the brackets between the semicolons as arithmetical expressions and evaluates them in the same way Repeats the loop as long as the test 36 expression has a value of non zero For details on arithmetical expressions see Arithmetic e if the usual conditional construction the conditions are also commands that are being tested for non zero status The first branch for which a non zero status is found is executed This behaves the same way as in Bash
29. to write to a file for the owner the file is marked as read only Otherwise the supported options work the same as in GNU chmod see chmod reference for details cp abfipRTuvx t target dir S backup suffix filel file2 file copies source files to given destination It can create backups of existing files b with default or pre set suffix S force overwrite of existing read only files prompt before overwrite of all i preserve file attributes p work recursively R r copy all files into target directory t or not consider any target directory T omit newer files from rewriting update u display the names of files being copied v or never copy across physical drives x The a option is equivalent to pR Other options of GNU cp are ignored e ls aAbBcCdfFgGhklmnopqOQrRsStUxXl i ignore pattern w width file lists the contents of a directory The supported options are other options are ignored a A display also files whose names begin with that are hidden by default A does not display and b q print non graphic characters as their octal escapes as B ignore files whose names end with c if used with 1t or none of these sort the files by their access time for 1 only display access time instead of modification time C list entries by columns default d treat directories same as files d
30. to n kter funkce Bashe nap automatick dopl ov n n zv soubor P i e en probl mu s p stupem k soubor m tak existuj dva postupy bu emulace zp sobu pr ce se soubory v Unixu pln e en v etn r zn ch pseudosoubor atd nelze ne p enechat projekt m typu Cygwin ale emulace file descriptor je provediteln nebo omezen se na standardn vstupy a v stupy ty jsou naprosto nezbytn a ponech n zbytku podle filosofie Windows V ot zce pr v k soubor m nelze ne p istoupit na ur it stupe p edst r n pokud je vy adov na kompatibilita s Bashem p mo zasahovat do slo it ho syst mu pr v NTFS s naprosto jin m zp sobem fungov n by nem lo smysl a mohlo by zp sobovat probl my nav c by operace stejn nefungovaly na st le pou van m souborov m syst mu FAT32 Detekce zm n ve v stupu na konzoli je jak u bylo pops no ve Windows standardn neprovediteln e en proto mus probl m obch zet Jednou mo nost je pravideln p ekreslov n obrazovky bez ohledu na zm ny co bohu el nemus zachytit v echny zm ny a nav c jde o pl tv n hardwarov mi prost edky p i patn konfiguraci obnovovac frekvence Krom toho ale zb v jen p m fyzick integrace konzolov ho okna do GUI aplikace co naopak p in komplikace p i zm n jeho pozice a velikosti a p ed v n p kaz a kl vesov ch zkratek Probl m kontroly ap
31. to word and word is assigned to var var word expands to var if var is not set words is written to error stream and an non interactive shell exits var word expands to word if var is set to empty string otherwise var offset length expands to sub string of var of given length starting at given offset The length setting may be omitted prefix prefix expand to list of names of environment variables whose names start with prefix S array array G expand to list of indices set in the array variable strlen expands to length of the given variable value 38 S param pattern S param pattern S param pattern S param pattern S param pattern string param pattern string may be used to strip parts of a parameter matching the pattern off the beginning or end or replacing them with a given string For details please see the Bash reference manual 4 Command substitution runs the contents of this string as a command and then replaces it with its output The syntax is command text or command text BashCommander creates a special thread to run the command and read its output This command may access and change the BashCommander environment no sub shell is created The command substitutions may be nested but for the backward apostrophe syntax the nested apostrophes must be backslashed BashCommander does not allow the file construct 5 Arithmeti
32. Bash e trap lp arg sigspec sets a trap command arg to handle a signal it s possible to set a trap for all the Unix signals but most of them will never be hit since Windows does not support them Meaningful values of sigspec are SIGINT ERR or DEBUG executed upon Ctrl C command with non zero exit status or the execution of any command For 1 prints a list of available signal specifications for p prints the trap for given signals same as in Bash e umask p S mode sets the internal umask file access rights creation mask under Windows it has no effect but pretends to be behaving equally to umask in Bash e unset fv name unsets a function or a variable in the environment for v the name refers to a variable for f to a function same as in Bash 2 4 2 Bash built ins Fh The bind enable local logout printf shopt type typeset and ulimit built ins are not supported 45 e alias p name value sets the aliases or displays current settings with p same as in Bash e builtin name args runs a shell built in used to override functions with same name same as in Bash command pVv name args either runs a shell built in or an external command and overrides functions or prints a description of the given command for v V which vary in the amount of details The p option is ignored otherwise behaves equally to Bash e declare afFirtx
33. Command objects All the shell commands except for command lists amp amp and connected commands and pipelines are objects of their own All the types of commands are derived from the Command class which is abstract and contains the member functions and variables common for all kinds of commands that means pointer to Env redirections standard handles and execution flags The command object has also virtual methods to exec itself or to convert itself to string getAsString predefined All the commands also are able to create redirection files and open them and clean that up afterwards and print debug trace All the commands may be also executed on background the background Thread serves for this The simple commands are represented by PlainCommand which is able only to execute the one function call internal built in or external program Other kinds of commands usually contain vectors of sub commands or even vectors of vectors of commands e g for e1if branches as well as vectors of commands bound to a pattern for case branches and execute them one by one or 59 selectively see e g CmdVect and execAll method There s IfCommand for all types of if then else tests TestLoopCommand for while and until loops ForCommand for for and select commands ArithmCommand for arithmetical commands and TestCommand for test commands special ArithmForCommand class for representing arithmetical for loops CaseCommand for the case
34. R ERAI Gd a ulia Dp an Cr E a RUE 57 a T The maiumobjectca cupa dd miscet uu i PR TD PARU hdd RUE 57 35 2 Et virOntHebk aeo peto E E edn vb PNIS ERE NoD E ge E EENNSE REOR kva a 57 a5 3 MAC rat SE S oce t pP intem antes tid ed br 59 dod Command objects sure ita ne S RUE P Ra cas REN RE RR ina ae etr ERE 59 3 5 5 Expansions and Gxecution ue vea p n ERO UT OP dapt Uus 60 3 5 6 IOLA AACE Ts screen s ev Cam WE RO Note dui s dosi debo 61 3 5 7 Internal commands iei ne ret e in ire re E E p EN SEEN ERE 61 3 PROCESS CconmtiricatlOE cze p c riiit 62 3 6 1 Message thread in Bash eee eee rete eee neenon etna 62 56 9 Shared niemioEy eeepc etie Eh Pune RUN TORRE PR RO E NON NIME 63 3 7 Doxygen generated documentation eese 64 P loha B obsah CD oie eret enr eae a a ROSE ARES NERVAE edu erm itur 65 N zev pr ce BashCommander Autor Ond ej Du ek Katedra stav Katedra softwarov ho in en rstv Vedouc bakal sk pr ce RNDr Jan Kofro e mail vedouc ho jan kofron mff cuni cz Abstrakt Pr ce se zab v implementac programu BashCommander slou c ho k efektivn spr v soubor ve Windows s pou it m textov ch p kaz Jde o dvoupanelov souborov mana er t sn prov zan s konzol pro textov p kazy kde se pou v syntaxe jazyka Bash Implementace sest v z grafick ho u ivatelsk ho rozhran se souborov m mana erem a termin lov m programem pro zobra
35. Univerzita Karlova v Praze Matematicko fyzik ln fakulta BAKAL SK PR CE Ond ej Du ek BashCommander Katedra softwarov ho in en rstv Vedouc bakal sk pr ce RNDr Jan Kofro Studijn program Informatika programov n 2007 Cht l bych na tomto m st pod kovat panu RNDr Janu Kofro ovi za veden m pr ce a cenn rady a pozn mky Tak bych r d vyj d il d k sv rodin za podporu a trp livost Prohla uji e jsem svou bakal skou pr ci napsal a samostatn a v hradn s pou it m citovan ch pramen Souhlas m se zap j ov n m pr ce V Praze dne 7 srpna 2007 Ond ej Du ek PS ERN TD TNT 7 TEC Pra Ene E E sa 9 RI O EAEE O E O 9 LT RBS MS Leoben XH CRY ceti benda Rial ut etes Da P era 9 og rene MR 9 ois ss MM 10 1 4 Volba jazyka a DTP ON eire IRE ae n Std aut VASE ISSUE UR BUS HE 11 2 Analy DE KM eet tie ADU Det ee es 12 SL o R l EM eet UE UEM M MM RUE 12 2 2 Technick probl my implementace eee 12 2 3 Anal za mo nost TOSODIL uo car eoe PE FRA ERREUR akad RE CER UF NeEA A ERERERAE 14 2 4 Zvolen postupy hlavn struktura eee 16 a Nektere detaily a R P R O O O O Unis s 20 3 1 Komunikace DEI A shell sys tte ient dois vict z acd VE DM icd 20 3 2 Duane GRIS Y OL aocstetitsbunto pite hA ME NR NEP DU n HEN UR EEIEpUE 22 3 3 Konzolov vstup
36. a lt p gt v souboru 1 parametr V sledek vyp e na standardn v stup e until sh demonstrace p kazu until po t od 20 do 10 while sh demonstrace p kazu while po t od o do 9 e install obsahuje spustiteln instala n bal ek aplikace detailn popis instalace kter v ak prob h pln b n m zp sobem lze nal zt v u ivatelsk dokumentaci e src ve ker zdrojov k dy cel aplikace BASH zdrojov k dy implementace Bashe COMMAND implementace unixov ch program pro pr ci se soubory COMMON v k du v eobecn pou van podp rn knihovny DOC dokumentace zdrojov ch k d generovan programem Doxygen GUI implementace grafick ho rozhran 65
37. activate the window tab switching opening a new window and simply type The console supports most usual editing features such as Home and End keys the auto completion of file names and command history The default auto completion key is Tab but this may be customized in the settings window The same is for command history keys by default Alt Up and Alt Down The command history always displays whole commands even if they were structured or spanned across multiple lines The history and auto completion features are unusable when running the shell application outside of GUI Using the file manager window is also very simple You may type into the console the same way as when opening a simple shell window but at the same time it s possible to operate the files in the listing panels you may select and de select files using mouse or keyboard the default selection key is Ctrl Space switch between the two panels using Ctrl Tab change the current drive Alt F1 Alt F2 and toggle some action with the highlighted file in the active panel by double clicking or hitting Enter If the file is an executable it s run in the shell If it s a directory the listing view and shell s working directory change to that directory Otherwise the commander tries to open the file in the default program However the behaviour of the Enter key changes if you have previously typed an unfinished command in the console In that case this command will be execut
38. ands The Env class also stores some other settings e g whether a nested thread is currently run whether the Ctrl C has been sent whether a command list is being run umask setting and a few more It has the signal handler as its member object and that is shared by all the instances of Env as only the first is created via the plain constructor the others must be clone d and take only the pointer The current loop depth for break and continue commands is stored there loopDepthGet etc and a directory stack is implemented but currently remains unused Last but not least the Env objects store the shell call stack for functions when a function is launched it s pushed on the call stack callStackPush and for subsequent requests for positional arguments or return command the right information is supplied After the execution of the function call command it s pushed off again callStackPop 58 3 5 3 The parser The parser splits the input into the commands as the lines are read Its main function is parse which is given a line of input and always returns all the complete commands that were found if a line is read and contains an incomplete command it is temporarily saved in the parser s internal structures until its end is reached Therefore the function may return an empty vector as well as several commands if they are on the same line of input With commands even structured commands including loops and nested l
39. arrows PgUp PgDn etc and F1 F12 keys Be sure not 48 to use just plain characters e g D as a short cut since you will need to type them in the console window which this would prevent You may also reset the keyboard settings to default To define the file manager commands short cuts click the custom commands Settings button in the settings dialogue window You may then add a new command or delete an existing one by clicking the corresponding button or edit a previously defined command by double clicking it A custom command definition window appears where you need to set up the keyboard short cut by clicking the appropriate button and fill in the command syntax You may also want to add titles to any input boxes that may appear when executing the command which will be explained in a moment The command syntax may contain anything a Bash command may contain as well as some special variable values These variables are connected to the running file manager instance the Bash commentary mark is used as their prefix They may be the following e 1 2 9 these expand to the first second etc file that is selected in the active file listing panel e i expand to the list of all files selected in the active inactive panel e D 0 expand to the name of the current opposite panel directory e ir expands to the name of the currently highlighted file e A B C when these are used an input box with g
40. ashrc file in the Application data folder upon its launch Some of the Bash features are implemented differently mostly due to implementation reasons or better conformity with the Windows environment i e the pipes are created via background threads so the last command in the pipe may affect the current environment if it s an internal command as opposed to Bash BashCommander also includes all of the commands found in the original Bourne shell some of them may have limited features i e the signal command since the signals under Windows don t have such a great significance as in Linux Some Bash commands at least the most important such as echo or read are supported There are a few basic file operation programs that come with the BashCommander installation It s ls for listing the contents of directories cp mv and rm for copying moving and deleting files mkdir and rmdir to operate directories and chmod which is used to alter file access rights but only the read only Windows file attribute is changed Most of the other programs support all the options that make sense even under Windows Other programs such as the Unix text utilities are not supplied and I recommend using their GnuWin32 implementation The GUI provides the execution of several Bash or commander instances in easy to switch tabs It s aimed at simple keyboard control the user may customize the keyboard short cuts for most of the operations such as conso
41. ation with the Windows clipboard more customization options colours etc improve the auto completion allow the user to switch backwards and maybe add more mouse support scrolling More Unix programs than those supplied are usually needed but since their GNU Win32 implementations are usually sufficient it s not a very significant problem 2 User manual 2 1 Installation uninstallation BashCommander is designed for Windows 2000 and newer and has been tested on Windows 2000 and Windows XP On older versions of Windows such as Windows 95 98 and ME the application will not start up and the behaviour of the installer is undefined The program is provided as an easy to use installation package To install just run the executable and follow the instructions For some steps the administrator rights are needed the program adds its installation directory to Windows PATH environment variable in order for the user to be able to comfortably execute the Unix file handling routines provided The program short cuts in Start menu and Desktop are also created for all users However the program settings and start up scripts are stored separately for each user in their Application data folders under BashCommander folder The existence and access to this folder is vital for smooth application run The user must agree with the BSD licence under which is this program being released and select an installation directory There are no limitation
42. c expansion expands arithmetical expressions to their values The expressions must be enclosed in double parentheses such as expression The expressions may be nested This works the same way as the Bash version except that the behaviour upon computation error is undefined For details on the expression syntax see Arithmetic 6 Word splitting splits the words regarding the characters of the IFS environment as blanks i e word delimiters Quoted apostrophe enclosed and backslashed blanks are retained Unquoted empty words are removed If IFS is unset no splitting occurs 7 File name expansion for any word with an unquoted wildcard character or a file name expansion is performed i e the word is treated as a pattern and expanded to a list of file names that match it If no file names match the pattern no expansion is performed The pattern support is quite limited in comparison with GNU Bash For details see Patterns 8 Quote removal as the last thing just before the execution BashCommander removes all the outer quotes apostrophes and backslashes i e those that are not backslashed or enclosed in quotes or apostrophes themselves The quotes and backslashes that resulted from tilde expansion variable or command substitution or file name expansion are retained because the results of those expansions have their value backslashed this works the same way as Bash 2 3 5 Environment variables
43. ce numeric or one character parameters separated with two dots are expanded as a whole sequence i e 1 1 5 expands to 11 12 13 14 15 This may be turned on or off using the set built in 2 Tilde expansion expands parameters beginning with unquoted tilde All the characters up to the first unquoted slash are considered tilde prefix If the tilde prefix is just the tilde character it s expanded to the current user home directory path usually c Documents and Settings User or similar if it s it expands to the current directory path PWD environment variable expands to OLDPWD environment variable If the tilde prefix is a user name of a user of this computer which has his hers home directory in Documents and Settings it expands to his hers home directory Other types of tilde expansion found in Bash using directory stack or in variable assignments are not performed in BashCommander 3 Variable expansion expands the environment variable names prefixed with may and in some cases must be enclosed in curly braces e g var to their value The array variables with subscripts see Environment variables must be enclosed in curly braces Unset environment variables have a value of empty string Other more complex types of parameter variable expansions are also supported same as in GNU Bash var word expands to var if var is set to parameter otherwise var word expands to var if var is not set expands
44. common base classes for Commander and MainWin or Commander and ShellWindow Both of them have no data members and no function code defined so there are no problems with the fact that Commander class is derived from both it in fact needs to have all the functions some of them are invoked by the main window some of them by the shell Therefore it serves mostly as an intermediate stage between the shell and main window Many of the functions are just passed on in the right direction but some values are altered by the commander e g the height of the console window for shells that is lower within file manager there needs to be place to put the file listings to It also ensures the redrawing and selecting of files in the listing panels 56 is done and reguests to run custom commands are passed to the shell executeUnderCursor postShellCommand postShellCd 3 5 Bash application code The application code except for the above mentioned support libraries that are shared with the file utilities is stored in the BASH folder The most important object are the WinShell and Env which represent the shell instance itself and not only one in the whole program and the execution environment They then use and or contain the other objects as their members The most important of them are described in the following sections 3 5 1 The main object The main object is WinShell it represents the whole program Upon start up one instance of W
45. controls and stores all the settings 3 4 1 The main window The application main window is bound with and created in the class MainWin this class is a singleton It contains all the data for program settings keyboard shortcuts and also windows settings which mostly overlap This class also stores a list of pointers to Shell classes currently open tabs there s no difference as to whether it is a commander or shell window both of them inherit all the members of Shell class It is responsible for creating new and closing the running 55 both types of shells To communicate with the shells it uses windows messages each of them has its own message processing procedure It also does some services for the individual shells commanders i e it is responsible for changing the caption of a tab when a shell asks for it Because the shells need to access the application global settings as read only it provides a method of receiving a pointer to them getWinInfo It also provides a way to access the keyboard short cuts settings or search within them there are two functions one for file manager windows and one for plain shells the actual work is however done within the settings member which is of SettingsDialog type 3 4 2 The shell tabs One ShellWindow instance is responsible for all the communication with its Bash instance for reposting any key presses and redrawing the output of its screen buffer It also receives t
46. d shortcuts keycode h guisettings h guisettings cpp shortcuts h shortcutdata cpp and shortcutdialog cpp and custom commands settings in customcmds h and customcmds cpp In the other files the GUIException class is defined which is thrown for GUI errors and should not occur in the ideal case guiexcept h guiexcept cpp and some constants gui const h The source code also contains some resource files needed by the Windows applications dialogue windows and icons for the buttons and the application itself These involve all the ico files as well as common resource h and winbash gui rc files 3 3 Supportive libraries objects The supportive libraries shared by Bash and Unix file utilities contain a few small but very important classes that are used all across the project All of them are enclosed in the namespace cmdcommon The most important of them are the input and output handles which are going to be discussed in the subsection Then there are a few exception classes it s AbstractException the base class for all the exceptions outside of GUI which defines a simple interface with the what function as seen in std exception that alas does not support wide strings the WException which is the base class for command file exceptions and contains an error message and the special OutOfMemoryException set in all the non GUI programs as the handling routine in case new fails due to memory shortage th
47. der e filel ot file2 filel nt file2 filel ef file2 tests for age older than newer than or equality of two files same file nodes e intl eg ne lt le ge gt int2 compares two integer values For other options found in GNU Bash BashCommander returns always false for they cannot be meaningfully tested in Windows e g actualities involving sockets and others The u 0O G and g expressions have different meaning in BashCommander since the ownership of a file cannot be tested in the Unix way 2 3 9 Patterns Shell pattern implementation in BashCommander is limited in comparison to GNU Bash A pattern in BashCommander is a word that contains one or more unquoted characters or known as wildcards The quotation mark stands for exactly one arbitrary character the asterisk may represent any number including zero of any characters A word matches a pattern if there exists any allowed replacement for all the wildcard characters so that its result sums up to the word 2 4 Supported internal commands BashCommander supports all of the Bourne shell built in commands but some of them may have limited options as some of the options don t have any meaning on Windows It also supports a set of most used Bash built ins sometimes with limitations too By same as in Bash here the GNU version of Bash is meant The list of all supported commands may be displayed with the ne1p co
48. dnorozm rn co usnad uje p ech zen po napsan m vstupu kter bylo nutn zobrazit do v ce dk pozice je upravov na na z klad obdr en ch informac o stisc ch kl ves ipek Home End i samotn ch znak Pro p jem p kaz ze souborov ho mana eru je v InputHandle implementov na je t jedna funkce krom samotn ho vstupu je mo n ekat je t na ur enou ud lost synchroniza n objekt syst mu a pokud ta nastane p eru it ten a vyvolat speci ln v jimku Na t n vstupu v hlavn m objektu Bashe a nikde jinde ne nap p i p esm rov n v stup p kaz apod takto nastav p ed ten m tuto ud lost a v p padn m o et en vznikl v jimky provede commanderem po adovan p kaz Tak je zaji t no jeho synchronn vykon n u ivatel b hem n j nem e spou t t dal p kazy kter by zp sobovaly nesrovnalosti na v stupu nebo probl my se synchronizac 3 4 Parser a p kazy v shellu Parser reprezentovan stejnojmennou t dou je jednou z nejd le it j ch sou st Bashe star se o kompletn p eveden vstupu na jednotliv i strukturovan p kazy vynech v jen nahrazov n prov d n po spu t n p kazu a tak d len vno en ch p kaz aritmetiky a test o co se star jin t da nebo i jin Parser Vstup dod van do n j po dk ch se d l podle metaznak shellu jejich v znam je d
49. dynamick ch knihoven podpora funkc je ale zalo ena na velice star verzi GNU Bashe 1 14 2 1994 U obou t chto projekt je ale u ivatel op t nucen pou vat konzoli syst mu Windows Bash v BashCommanderu tedy neposkytuje tolik funkc a plnou kompatibilitu jako jeho kolegov z projekt Cygwin nebo MinGW nepot ebuje ale dn b hov prost ed se slo itou konfigurac a mnohem v ce spolupracuje s Windows a jeho programy Mno iny funkc Bashe m ho projektu a popisovan ch dvou samostatn ch implementac pro Windows jsou z ejm neporovnateln v ka d verzi chyb jin a BashCommander nav c n kter operace prov d jinak p id v ale emulaci termin lu odhl dn me od souborov ho mana eru a proti prvn mu p padu v razn lep integraci do opera n ho syst mu vzhledem k druh mu jen o n co lep P i p en en bashov ch skript je nutn prov d t pravy z ejm ve v ech p padech i kdy pro m j projekt jich z ejm bude vy adov no o n co v c Vo pro interaktivn pr ci je BashCommander pravd podobn o n co pohodln j 4 2 Hodnocen spln n c le pr ce Moje hodnocen bude z ejm nutn subjektivn p i pokusu o n j se ale budu sna it soust edit na fakta Pokud jde o spln n zad n projektu bylo ho z v t sti dosa eno v sledn program je souborov mana er t sn prov zan soknem shellu je t t sn ji ne byl p vodn
50. ectly by name i e a instead of a even if just reading the value The syntax of the expressions is the same as in Bash and similar to any usual C like programming language You may assign variables compute compound expressions using parentheses and access array subscripts too The supported operations are 41 e vart var var var incrementation and decrementation e unary plus minus logical and bitwise negation e varl var2 exponentiation e binary 2 lt lt gt gt multiplication division remainder addition substraction and bitwise shifts e lt gt lt gt comparisons their value is o false or 1 true e lt bitwise AND XOR OR amp amp logical AND and OR e expr exprl expr2 ternary operator conditional expression e types of assignations e exprl expr2 comma both expressions are computed the first value is thrown away Constants are also interpreted the same as in Bash decimal hexadecimal octal and bases number syntax is supported As in Bash no overflow checking is done just the division by zero raises an error For operator precedence and further details see the Bash reference manual lt lt 227 amp various 2 3 8 Tests As in GNU Bash you may let the program test for some actualities e g the existence of a file or non emptiness of a string The tes
51. ed and the selected and highlighted files in the listings have no effect on that At the time a command is being run in the shell window no other operations than file selections are allowed in the list view hitting Enter or double clicking will toggle no action When working with the file manager window you may also use custom keyboard short cuts to run some previously defined commands in the shell window These may contain some variables regarding the current state of the file manager view e g the current directory list of selected files etc and therefore provide the functionality of the usual file manager You may define them using a special dialogue window in settings for details see Settings and start up scripts 2 3 The Bash scripting language The language is almost the same as GNU Bash so for detailed descriptions please see the Bash reference manual The following section describes the language very briefly but mentions the differences from the original version The Bash implementation executable for BashCommander is winbash exe located in the installation folder 34 2 3 1 Commands The whole Bash language consists of commands The commands may be simple such as executing a program or a shell built in a small subroutine that does a simple operation or compound such as list of commands connected with amp amp or etc The input is separated by the parser into commands regarding the so called shell meta cha
52. edure as a second HANDLE to wait for When a WM RUNCMD Or WM CHANGEDIR message arrives this event is set the waiting ends with an exception that is caught by the WinShell object and the command may be run synchronously Some other messages such as WM EXECUTEUNDERCURSOR and WM ENABLE PANELS are used to coordinate the functions of shell and file manager 3 6 2 Shared memory The shared memory is used as a storage space for all the GUI Bash messages that need more than two pointer parameters except command running and directory messages that use a shared memory of their own which may be reinitialized every time a message is sent It s created as a shared file memory mapping in the associateMaster function of the Bash message thread The handle to the mapping is then duplicated and sent to the master application It contains a buffer to store a copy of the current console view must be as big as largest console window that may be created in the system information about the size and position of the console screen buffer which is updated as the console scrolls or is resized and the cursor position as well as a name of the program currently running in Bash which is refreshed by Bash and notifications are sent to the master application The definition of the shared memory file format is located in comm h file in the COMMON sources folder along with the definition of all the window messages 63 3 7 Doxygen generated documentation T
53. ek ek kter se objevily p i v voji aplikace BashCommander m la p vod v rozd lnosti syst m typu Unix z kter ch poch z Bash a jeho zp sob pr ce a syst m rodiny Windows c lov platformy 12 Standardn knihovny funkc kter se nach zej na v t in po ta s opera n m syst mem Linux a jemu podobn mi jsou mnohem l pe uzp sobeny pro pr ci s konzolov mi aplikacemi ne API syst m Windows To je mnohem v ce zam eno na grafick u ivatelsk rozhran kter je v unixov ch syst mech e eno jako nadstavba ale s konzol prov zan Windows poskytuje program tor m funkce pro pr ci s textov mi okny v etn zm ny jejich velikosti barev apod a to funkce dvou typ tzv vysoko rov ov a n zko rov ov prvn pro b n operace s relativn snadn m pou it m druh pro p m p stup k vstupu a v stupu na konzoli a tedy docela t kop dn N zko rov ov vstup vypad jako proud ud lost my i kl vesnice apod kter je nutn rozli ovat a d le z nich zji ovat jak maj vliv na pr ci programu v stup je ve Win32 API e en pomoc bufferu kter obsahuje dvourozm rn pole znak spolu s jejich vlastnostmi barvy Vysoko rov ov funkce bohu el neumo uj p li mnoho pokro il ch operac nap ten s ek n m na dan znak na vstupu nebo time out a jsou dost jednostrann zam eny na pr ci se standardn p kazovou
54. en dua E C Men ooo oo doo 41 DADS TOSS decvisi E P Xm MM UD Uic uM A UMVVIMA EIE 42 230 Patterns sien ae op ERRASSE ae koa UE stris eee eee oak vean RES 43 2 4 Supported internal commands scu trop ti tees oves o ta da rares 43 2 4 1 Bourne shell butlt IUsi oes occi eee ieee 43 24 9 Bash D llt IBB erede e RE E DE RN NOD DS a be 45 2 5 Supplemented Unix file operating programs eene 46 2 6 Settings and start up scripts eese ete tescesestpra ero adeo aUe eee ed rante 48 27 GUIshort ctts table ione et rt RE RN TERES did ed V ska ec 49 3 Proptamtiet s miattUdl sedo cia DECR RR Pies p din vies 50 3 1 Used l tigtiages ou ee e ioci ete cs cese e eU per ease Chov do So ERR 50 4 2 Source code files strict t uei ae nes her ers e Da Ra A I EU NOS ae 51 3 2 1 Common supportive libraries eese 51 3 2 2 The simple file operating programs eren 52 3 2 3 The Bash applications iere trapo eire Rr RE HAP TERT eK eR s eb reed OA 52 cR BI GUI MT 53 3 3 Supportive libraries objects eese eee ee eene eene ente nnn 53 3 3 1 The input and output handles eeeseeeeeeeeeeer 54 S4 GUI code SCHEIN A sua o Ep EAE II orm E aait 55 34 i Te Wal WINDOW eraspena ean Ser se nM e rto ute tite I asii 55 32 5 The S el BS udin DEN a A ia EN 56 3 4 3 The file manager windows esses ener 56 2 5 Bash application eode si p rr R
55. entheses are required and the declaration must be a separate command To execute a defined function just use its name as a command name e g execute command fc name paraml param2 The parameters you use are available inside the function in special variables named 1 2 etc the same as the positional arguments outside of a function All the variables in BashCommander are global you may not create local variables unlike in GNU Bash i e if you change a variable inside a function the change persists even after the function execution finishes unless the function is executed on background Inside of a function you can also see the variables declared previously outside it Functions may be set as exported in that case they are converted to their string value and set as variables in the Windows environment All the BashCommander instances search for function code in the Windows environment and import it if any code is found so you may export a function and use it inside a script then This works equally to GNU Bash 2 3 7 Arithmetic Like Bash BashCommander has the ability to compute simple integer arithmetical expressions they are implemented completely and behave equally as in GNU Bash 3 1 The arithmetical expressions are used in array subscripts arithmetical commands and arithmetical expansions Inside of an expression normal variable substitution is performed but apart from it you may use variables dir
56. es it s written in the source code commentaries at the function definition what the function returns a direct 50 pointer or a copy and also what it does with its parameters some functions take their parameters and save them in some internal structure after which the parameter pointer must not be used in calling function For all the input and output operations window creations etc bare Windows API functions are used There are some functions used that are not available in Windows NT4 95 98 ME or older so the application won t run on older versions of Windows Some common controls library functions are used too so comctl32 lib is needed for compilation The definition of the Windows version is in the header file common h which is included in most other files For the code editing and compilation of the binaries Microsoft Visual Studio NET 2005 has been used the Visual Studio project and solution files are supplied with the sources AI the string operations are done with wide strings Unicode i e the std wstring and std wstringstream classes are used instead of std string and so on Even all the hard coded constants in the application are wide strings All the input that is read from files and pipes is automatically transferred to wide strings using Windows API functions 3 2 Source code files structure The BashCommander sources are divided into four directories BASH that contains all the sources exclusive
57. escription BashCommander is an implementation of the Bash language for Windows 2000 XP i e a shell application along with a set of common little Unix file handling programs such as Is rm mv cp and a GUI terminal application capable of running several instances of the shell in tabs in the same way as the well known Linux terminal applications e g Konsole for KDE all combined with a two panel file manager the so called commander It covers most of the features of the GNU Bash as known today including the language constructions variables arrays arithmetic and the most important internal commands and aims to provide an efficient command line interface for Windows However support of some common Unix features e g file access rights or file descriptors is quite limited due to differences between the two operating systems Some of the implemented commands are tweaked so that they fit the Windows environment better that covers mostly the line feed character and backslashes in pathnames There are also some minor differences in the language so it s not 10096 compatible with GNU Bash but most of the Bash scripts should work under BashCommander without need for major changes The file manager is closely connected to the shell window i e a change of directory in the shell window reflects in the active panel of the commander and vice versa and all the operations of the commander just launch appropriate commands in the shel
58. etod na v konn m objektu je jednodu a tedy preferovan Syst mov zpr vy mezi b c m procesem Bashe a GUI maj n kolik funkc Jednou z nejd le it j ch je samotn nav z n komunikace po spu t n shellu grafick aplikace st dav n kolik okam ik ek a pokou se poslat nov vytvo en mu procesu speci ln zpr vu pro otev en komunikace V n m je toti hned po spu t n vyroben speci ln thread pro p jem rozkaz od GUI reprezentovan t dou MsgThread ekaj c pr v na inicializa n zpr vu Toto teoreticky m e selhat a pak dojde k vyps n chyby a otev en nov ho panelu nen provedeno v praxi se to v ak stane jen v p pad probl m se samotn m opera n m syst mem Nav z n dialogu mezi ob ma procesy je nakonec shellem 20 potvrzov no Spolu s t mito zpr vami se p ed vaj HWND identifik tory c lov ch oken pro n kter dal zpr vy konzole shellu okno panelu GUI za shell zodpov dn ho a tak HANDLE sd len pam ti Shell potom sv mu p nu master grafick mu oknu pos l dosti o p ekreslen v stupu a zm nu n zvu panelu n zev aktu ln spu t n ho programu a dost v potvrzen o jejich proveden co za cenu o n co v t ho provozu p edch z zahlcen zpr vami stejn ho typu ke kter mu v praxi bez tohoto opat en skute n doch zelo GUI shellu a to p mo onomu dedikovan mu
59. fic built ins The supportive functions that may be called by more than one internal command have a pointer to its main function as a parameter to display the error messages right For the error messages there s a special exception class IntCmdsException which has the command function pointer as one of its parameters and when displaying the message it always prefixes it with the right command name 3 6 Process communication The process communication between the GUI and shell instances is done via Windows application messages so called user defined message types from the range of constants not used by Microsoft When the Bash application is run from within the GUI the GUI associates it with its Shell object by sending a WM ASSOC MASTER message and from that time on it may be controlled by it and send back status messages such as WM ASSOC SLAVE confirmation In the association messages the Window HWND of the shell GUI window and a HANDLE to the shared memory area are always sent The shared memory is a place where some vital informations about the current size and actualities of the Bash console window are stored as well as a copy of the current shell window view 3 6 1 Message thread in Bash The Bash application has a special thread encapsulated in a MsgThread object to receive and send the messages The messages are sent to it from the master application the GUI using the Post ThreadMessage function There s a usual Windo
60. gHandler that lists all the names of signals which are stored there in a hard coded constant that is used by Env as a support for the trap 1 command 3 5 7 Internal commands All the internal shell commands functions are located in the IntCmds class All the members of this class are static that means no object needs to be created upon the launch of an internal command Every command has its own main function always called cmd command name gt e g cmdEcho or cmdPwd which may then call other supportive functions The command functions are all declared private so they must not be called directly For all the other classes use there is the main function exec which given an ArgVector that includes a command name searches for such command in a list of string constants corresponding to function pointers and launches the appropriate function or returns false if no built in has such name This may be done because all the commands main functions have the same set of parameters the ArgVector with the commands pointer to Env and line number and script file name indication to display error messages correctly Most of the commands use the getOpts method to parse their options It is also used by the getopts command and has therefore a wide variety of parameter 61 settings it also supports the more complicated options of the set built in Other support functions such as declareVars or splitToVars are only used by some speci
61. ground then you don t have any means of controlling it from within BashCommander divide the command from others with amp instead of new line or Each command also returns its exit status a small non negative number If this equals zero that means the command ended without any errors The return status is set as a special environment variable and may be tested for 2 3 2 Plain commands When a command is read its first word is checked to see if it has an alias as soon as upon parsing and if found it s expanded and may be expanded recursively Upon execution Bash first takes the command name and tries to find such user defined function If this fails a built in command is searched for If there is no built in command Bash searches for a program of that name and or path When searching for the program the common executable file suffixes bat com exe are appended to its name if needed so you may use program exe as well as program only If the program name contains any forward or backward they are always converted to backslashes upon search slash characters its regarded as a pathname and only this path is tested 35 Otherwise BashCommander looks for the program in all the directories defined in the PATH environment variable and same as Bash does not include the current directory in the search which is what the standard Windows command line does 2 3 3 Structured commands Ba
62. he message thread MsgThread This means mainly sending keys to its own input displaying the commands in history or the auto completion feature The shell object also stores the current script file name and line number which is needed by most of the commands for displaying error messages 3 5 2 Environment The Env class represents the shell environment A pointer to the usually only one except for background threads instance is spread across the whole memory each command has a pointer to it the parser and WinShell class too it s needed for all the expansions that are performed it s a service class almost for every other executive class in the application 57 This class stores all the user variables arrays command hashes functions and aliases in its globalEnv member it is a map name to value these are all derived classes of the Var class It s capable of setting unsetting swapping values listing all values etc all the functions directly correspond to the needs of the internal commands and expansions It also handles export and read only statuses of variables Some special variables have also special means of setting them i e the command exit status and the shell arguments setLastExitStatus setShellArgs All of the setting functions take directly the pointers supplied to them and store them in the environment no copying is done but the pointers must not be used after the call to the setting function The
63. he BashCommander source codes have their in line commentaries scheme designed for easy Doxygen documentation generation the documentation is included with the sources 64 P loha B obsah CD Tato st zahrnuje seznam adres p padn soubor v nich um st n ch na CD spole n s popisem jejich obsahu e bin p edkompilovan verze v ech spustiteln ch modul i bez instalace je lze pou t pro jejich spr vnou kooperaci v ak mus b t v echny ve stejn m adres i kter je nav c uveden v prom nn PATH opera n ho syst mu doc text bakal sk pr ce ve form tu PDF e example n kolik uk zkov ch skript for sh demonstrace p kazu for vyp e v echny soubory v adres i jednotliv podle v stupu z 1s helloworld sh nejjednodu Hello World skript makelist sh vyp e HTML k d s odkazy na v echny soubory v zadan m adres i 1 parametr p padn s vlastn hlavi kou a pati kou 2 a 3 parametr Vy aduje p tomnost unixov ho programu sed v adres i uveden m v PATH renamer sh automatick p ejmenov n soubor detaily viz koment e v samotn m skriptu tak vy aduje sed sguare sh demonstrace ten ze vstupu a pou it funkc po t druhou mocninu sla kter si vy d na vstupu txt2htm sh odd len odstavc rozpozn v je podle pr zdn ch dk HTML tagy lt p gt
64. he messages from the main window i e to close the shell The object itself has a private constructor and must be created via the Create function which runs a special thread for its instance too The thread function is shThreadFunc The shell graphical window may be created and controlled either by the main window directly or by a commander it holds a pointer to a general Controller object which is a common base class of both of them Apart from the reposting of input and receiving messages from the Bash instance and main or commander window which is handled directly in the processMessage method sometimes through postShellKey and other supportive methods it needs to be able to redraw the output of the Bash console updateScreen and also resize the console if the user resizes the main window resizeConsole If the user switches between the Shells they are notified by the main window that they are or are not going to be the topmost ones from that time on setTopmost If a Shell is not set as topmost it does not redraw the console output because it s not visible anyway 3 4 3 The file manager windows The file manager windows needed to be put somewhere in between the main window and shell windows because they are created as tabs under the main window and themselves create the shell windows The C multiple inheritance has been used to achieve this effect There are two abstract classes Controller and Shell that serve as
65. he pattern matching is done using the Matcher class from the files matcher h and matcher cpp The last thing shared by Bash and the Unix utilities 51 is ArgVector class simple class derived from a vector of wide string pointers this is used almost everywhere for command arguments and similar objects 3 2 2 The simple file operating programs All the sources of the Unix file operation utilities reside in the COMMAND folder It s just the commands main files with same names as the commands itself and four support libraries First of them is cmdexcept h amp cmdexcept cpp containing a definition of the commands standard exception The other is cmdenv h amp cmdenv cpp definition of the CmdEnv class that stores all the settings for the command i e what options were turned on The next pair of files contains the Question class it s used to ask the user questions and return yes no always never as an answer The last one is fileop h and fileop cpp with the File class an abstraction of a Windows file containing functions to test its attributes size etc AI the utilities also use the input and output objects from the COMMON folder and exceptions too Matcher class is required by 1s only to test the ignore patterns The rmdir and mv utilities don t have sources of their own because their features are included in mkdir and cp commands their executables are created simply by copying which is set up in the Visual Studio
66. ile removes a file from the disk It s possible to force the removal of read only files f recursively remove directories too r R prompt before each removal i or only before removal of more than 3 files or a recursive removal of a directory I and display a message for all the actions performed v e rmdir pv dir dir removes a directory directories they must be empty the options are the same as for mkdir the mkdir and rmdir executables are identical 2 6 Settings and start up scripts In the settings window the user may alter several program options It s possible to turn off the toolbar and and use all the space for shell windows In that case you may only turn the toolbar back on using a keyboard short cut Ctrl Shift P by default You may also alter the font setting only mono spaced fonts are suitable The font is changed in a standard Windows font dialogue window A background colour for the shell windows may be set up too The most important setting is the keyboard short cuts It s possible to customize the short cuts for most of the operations The set up is very straightforward just select the Settings button near to Keyboard short cuts caption in the dialogue window then select the desired action from the list double click its name and press the desired short cut Only the short cuts involving some valid key are accepted valid keys are character keys
67. inShell is created by the wmain function Its main method is work this tries to read and subsequently execute commands until the end of input or an ending command is found It also catches the various exceptions the program may raise i e syntax errors or program execution errors as well as control flow exceptions The normal way of handling an exception is to display its message and continue WinShell has its own Parser object that receives the input and returns it split into command objects It also has its own Env object that means the environment where all the variables and other settings are stored e g the standard handles shell settings and signal handles However not every WinShell instance has an Env of its own it is to say that in several situations such as when running a command substitution or for sourced scripts other WinShell objects may be created Those shell objects share the Env with the main and basic one which is by that time waiting until their execution ends This objects also retains its command cache which is used for storing commands before their execution as well as for command history Some methods involve reading the commands from the standard input handles that are stored in Env or displaying the prompt This object is also responsible for processing the command arguments i e running the right script file or the start up scripts A lot of work of WinShell is done in cooperation with its member t
68. ing a given exit status default is 0 same as in Bash e export fn p name value exports or reverts the export for n given variables or functions for f With p just lists exported variables functions same as in Bash getopts optstring var name args simulates the Unix getopts function takes subsequently the options from either positional arguments or supplied arguments and returns them in given variable same as in Bash e hash rl p filename d name hashes a program name to a path so there s no need to search for it later With default settings this is done automatically for all commands hash displays the paths found for supplied command names 1 in a reusable format clears the table or just given hashes r d or forces hashing a command to given file name The t option is currently not supported e pwd L P prints the current directory name The options are accepted but don t have any meaning e readonly apf name may set a variable an array or a function as read only Lists the read only variables or functions for p same as in Bash e return n returns from a function or a script executed with source command with given exit status same as in Bash remark currently does not return the right exit status in source scripts e set aBheknfutvCx o opt name args switches on or off some shell settings and or replaces the she
69. is is done via the Win32 APIfunction set new handler The perhaps most used class of all is ArgVector in the Bash application its more sophisticated derivative is used It s itself derived from the std vector std wstring gt class but has more features it s possible to decide 53 whether you want a member of it being just erased from vector or erased and freed in the memory most of them involve freeing or not freeing memory this provides an easy way to insert and delete string pointers without the need of copying the actual strings It also has the ability to convert itself to a string by concatenating all its elements The Matcher class is responsible for all the pattern matching operations in the whole project except for file name matching which is currently done via the Win32 API FindFirstFile function It contains static public functions match and replaceLongestMatch that provide the all the interface needed it has not got any constructors so all the usage of this class is just through its static functions 3 3 1 The input and output handles The input and output handle are used in all the console programs from the project They in fact beyond other things recreate the insufficient Win32 API high level console functions using the low level ones All the objects contain a Win32 API HANDLE value and may be converted to and from it The base class for handles is Handle its derivatives are InputHandle a
70. is resized properly when the user sizes the GUI window WM RESIZECONSOLE The messages are also used for some less vital functions of the GUI Bash cooperation such as console window scrolling There are four messages telling the Bash application to scroll the console up or down by one line or whole page MsgThread ensures this in the scrollConsole function For the auto complete feature of the GUI the WM AUTOCOMPLETE message is used It calls the appropriate function on the WinShell object The same is with WM HISTORYFW and WM HISTORYRW messages that provide the Bash history functionality Only because of these messages and them being handled from a different thread than the main shell one asynchronously and instantly must the input handles have their buffer protected by synchronization functions and CRITICAL SECTION Several messages are also needed to provide the connection of file manager with the shell the most important of them are WM RUNCMD that triggers the execution of a command in the shell the command is passed in as a handle to a shared memory area that contains it or WM CHANGEDIR to change the directory may be sent in both directions depending on whether the user changes the directory by typing in the console or entering it in file listing To execute the commands synchronously and only when the shell is waiting for some input from the user there s a Windows event object that is passed to the main input reading proc
71. iven question that is to be filled in the mentioned edit fields appears and the variable is expanded to the input the user types in e is the same as alone so that you may even supply the commands with a commentary The settings are saved immediately after clicking the OK button of the main settings dialogue window which also closes it The application also remembers its window size and position and starts always in the same position it was previously closed in All the GUI settings are stored in the file settings conf in the Application data BashCommander directory If you delete the file you revert all the settings back to default 2 7 GUI short cuts table This table shows the actions along with the default short cuts that are pre set upon program installation and the user may revert back to them in the short cut settings window by clicking the Reset defaults button The first set of short cuts may be used anywhere in the program Action Short cut Close the active tab Ctrl W Command history back Alt Up Command history forward Alt Down Move one tab to the left Ctrl PageUp 49 Action Short cut Move one tab to the right Ctrl PageDown Open a new Bash instance tab Ctrl N Open a new commander tab Ctrl Shift N Open the settings dialogue window Ctrl Shift P Scroll the console one line up Shift Up Scroll the console one line down Shift Down
72. j c ch implementac Bashe Spojen commanderu a shellu je nov p stup proto m ru jeho vyu v n nelze je t odhadovat Roz i ov n schopnost programu a dal vylep ov n jist v razn zlep pohodlnost pr ce s programem ale dle m ho n zoru je u vt to verzi v praxi pou iteln P ehled v ech funkc aplikace a jejich technick popis obsahuje p ilo en dokumentace Jej text je v angli tin nebo v echny identifik tory v k du programu koment e v k du i v pisy konzolov aplikace a popisky grafick ho u ivatelsk ho rozhran jsou naps ny v tomto jazyce kter je nap pro pl novan zp stupn n programu na internetu vhodn j Druhou p lohou je obsah p ilo en ho CD kter zahrnuje i popis funkce uk zkov ch skript demonstrace schopnost implementace Bashe 29 Odkazy 1 Bash Reference Manual http www gnu org 2 Cygwin http www cygwin com 3 KDE Konsole http www kde org 4 GnuWin32 project http www gnuwin32 org 5 Critical comments http world std com jmhart critcom htm 6 MSDN Magazine 02 04 http msdn microsoft com msdnmag issues 04 02 CQA 7 Microsoft Developer Network http msdn microsoft com 8 MinGW http www mingw org 9 Steve org uk GNU Bash for Windows http www steve org uk Software bash 10 win bash http win bash sourceforge net 30 P loha A dokumentace anglicky 1 About the program 1 1 D
73. kaz ke spu t n v p pad zm ny pracovn ho adres e vypad v sledek dost podobn V jin m p pad dost v jen potvrzen p ijet p vodn zpr vy GUI m e samo otev t soubor dokumentu v syst mem p i azen m programu Po dobu ek n na reakci GUI je cel proces shellu zmrazen 3 2 Dva druhy panel v GUI Grafick prost ed BashCommanderu d v u ivateli mo nost otev t n kolik panel a rychle mezi nimi p ep nat Nav c jsou na v b r jejich dva druhy prost okno shellu a kombinace se souborov m mana erem V k du aplikace jsem pro to musel vytvo it pokud mo no mo no co nejnen ro n j o et en hlavn m probl mem byl vztah mezi jednotliv mi okny a jejich p slu n mi C t dami hlavn m oknem programu oknem shellu a oknem souborov ho mana eru Hlavn okno p edstavovan t dou MainWin toti mus udr ovat seznam zobrazen ch panel nejl pe bez rozd lu druhu spu t n shell t da ShellWindow by se nem l chovat r zn v z vislosti na tom b li pod commanderem nebo p mo pod hlavn m oknem jako jeden vlastn panel a pro okno mana eru neboli t du Commander je t eba spolupr ce s ob ma ostatn mi sou stmi Pro vy e en situace by bylo mo n pou t dv r zn t dy zobrazuj c okno Bashe znamenalo by to ale probl my v p pad p epos l n p kaz k nim od hlavn ho okna p es commander Jako v hodn j
74. kazu read Samoz ejm je mo n nastavit i horn limit na po et na ten ch znak Kv li funkc m vy adovan m GUI lze tak vnit n buffer ji na ten ch znak kter je t nevyhovuj podm nk m pro n vrat z funkce a ek se tedy na dal za b hu m nit nap automatick dokon ov n n zv soubor si zjist jeho obsah vezme posledn napsan slovo a sna se ho dokon it podle n zv soubor v dan m adres i pokud usp je dop e konec bufferu a ten vr t zp t Proto e jsou p kazy p edan z GUI prov d ny v jin m threadu ne samotn pr ce shellu v echny operace s vnit n m bufferem jsou synchronizov ny s pomoc kritick sekce jednoho z k tomu ur en ch prost edk opera n ho syst mu 23 Zobrazov n aktu ln ho obsahu bufferu konzole bylo tak nutn e it n zko rov ov na t n nevypisuje napsan znaky automaticky Krom toho by po zm n obsahu cel ho bufferu tak doch zelo k probl m m Proto si InputHandle mus pamatovat pozici kurzoru v okam iku kdy ten za alo a od n vypisovat znaky z bufferu to se prov d jednodu e pomoc funkce WriteConsole pou v se standardn v stup programu bez ohledu na jeho p esm rov n v r mci p kaz Bashe V t probl m je aktu ln pozice kurzoru ta se mus podle ky konzole a po tu stisk kl vesy Enter dopo tat Vnit n je toti pozice kurzoru reprezentov na jen je
75. l window It s possible to simulate all the typical file manager functions copying and moving of files creation of a directory that way Al the programming code is written in C using bare Win32 API For almost all of the internal operations BashCommander does not need to use child processes and works rather with threads Therefore the execution speed is relatively high The whole set of applications is available under BSD style license including the source code Visual Studio 2005 may be needed to compile the sources easily 1 2 Features The BashCommander implementation of Bash scripting language contains almost all of the main language constructions including simple commands command lists pipes loops such as while until or for loops conditional constructs functions case commands aliases and more Variables including one dimensional arrays with number indices are also supported Splitting of the commands and several types of substitutions are done in the same way as in GNU Bash This includes brace expansion tilde expansion variable parameter 31 expansions command and arithmetic substitutions word splitting and quote removal Process substitution is not supported and file name expansion is little bit more limited patterns support only and as wildcards Built in Bash also supports arithmetic and test commands with most of the usual options Start up scripts are also supported the bash application reads the b
76. le local logout printf shopt type typeset and ulimit Ur it p ep na e n kter ch intern ch p kaz jsou nav c ignorov ny jde zejm na o ty kter by v c lov m opera n m syst mu nem ly smysl detailn popis viz u ivatelsk dokumentace Jak u bylo v e pops no p kazy spu t n na pozad nelze nijak kontrolovat T m ale v et nepodporovan ch vlastnost kon 19 3 N kter detaily e en Tento odd l obsahuje do detailu rozvedenou diskusi e en probl m z nich n kter byly ji obecn probran v p edchoz sekci Jde hlavn o komplikovan j sti projektu ste n z hlediska pou it API syst mu Windows ste n objektov m n vrhem a integrac jazyka Bash Technick popis v ech hlavn ch sou st projektu je mo n nal zt v p ilo en program torsk dokumentaci 3 1 Komunikace GUI a shellu Z kladem komunikace mezi grafickou st aplikace a shellem jsou jak u bylo nazna eno zpr vy syst mu Windows Obecn ka d syst mov zpr va m sv j identifik tor druhu a m e n st a dva parametry v echno jsou 32 bitov sla Ve Win API je ur it rozsah sel druh zpr v ponech n k voln mu upot eben aplika n m program tor m eho BashCommander vyu v Celkem je v programu definov no 28 druh zpr v pro komunikaci jednak mezi jednotliv mi stmi grafick aplikace a jednak mezi GUI a shellem Ty slou k na
77. le scrolling tab creation or switching The GUI saves its settings and window position in a file in the Application data folder All the commander windows work in close connection with their shell window the user may customize keyboard short cuts that launch commands in the shell The commands may contain values of several variables such as names of selected files in the active listing panel the name of the current directory or a value that will be asked for via input box There s no need to switch between the file listing panel and the shell window in the commander the user types in the shell window and may control the listing at the same time 1 3 Limitations As mentioned earlier this Bash language implementation does not include all the features of the GNU Bash Some of them have no meaning under Windows due to different access e g to file rights some may be implemented but the complications of this process were not worth the effort or at least not for now and for me BashCommander currently does not support process substitution several rare syntax phrases such as amp for redirecting output and error stream to the same file or function headers without and some Bash commands It 32 also doesn t have some common Bash variables set up such as BASH VERSION The background job control is also not supported For more comfortable user experience it would also be appropriate to add some more features such as integr
78. le br n v potaz d ky n kolika p znak m kter se mohou vrstvit na z sobn k Pro zpracov n slo it j ch jazykov ch konstrukc parser operuje s dal m z sobn kem na kter se ukl daj na ten d l p kazy nedokon en ch struktur nap v echny operace jedn while smy ky K jejich ulo en se pou v speci ln ch t d odvozen ch od t dy Control z visl ch na druhu konstrukce odpov daj d c m kl ov m slov m jazyka kter ji uvozuj nap case elif until Pokud je nalezeno ukon ovac slovo parser vytvo z obsahu vrcholu z sobn ku fin ln objekt p kazu kter je vlo en do nov ho vrcholu po odebr n pou it ch struktur Kdy je po vytvo en hotov ho p kazu tento z sobn k pr zdn m e b t p kaz vr cen ven k proveden parser vrac v dy v echny p kazy dokon en na aktu ln dce tak e jich m e b t i v ce Ka d bashov p kaz je instanc n jak t dy odvozen od abstraktn t dy Command kter poskytuje funkce spole n pro v echny druhy jako nap p esm rov n v stup V jimku tvo pipelines a podm n n konstrukce kdy 24 ka d jejich len je reprezentov n samostatn m objektem p i vykon v n se na tento fakt ale bere ohled N kter typy p kaz mohou obsahovat dal nap v echny p kazy v cyklu a takto vytv ej v podstat stromovou strukturu Na t
79. likac spu t n ch z prost ed Bashe lze e it jen ste n takov program je mo n ukon it p i ukon ov n samotn ho Bashe ten ale u nem p ehled o j m spu t n ch programech alespo ne b n mi prost edky nav c takov ukon en programu je pova ov no za nestandardn a nemus doj t kuvoln n syst mov ch prost edk t mto programem alokovanych viz TerminateProcess v 7 15 V souborov m mana eru je nutn e it problematiku p ech zen mezi konzolov m oknem a dv ma panely v pisu seznamu soubor Pokud by u ivatel mezi ob ma stmi p ep nal z ejm my nebo kl vesovou zkratkou znamenalo by to sice komplikovan j ovl d n ale tyto dv sti by mohly reagovat mnohem samostatn ji Naopak lze celou v c pro rychlej pr ci implementovat pln bez p ep n n kontextu u ivatel by si musel zvyknout na v ce r zn ch kl vesov ch zkratek proto e se pro pr ci v konzoli a v souborov m v pise mus pou vat r zn ale ve v sledku by pr ce s takov m oknem byla snadn j Cel toto e en nav c skr v probl m s p en en m informac z kl vesnice a implementac v pisu soubor p i pou it standardn ho ovl dac ho prvku Windows listboxu Probl m s informacemi o stisc ch kl ves lze e it z ejm jejich p m m p epos l n m co ale nen mo n v p pad pou it standardn ch dialogov ch ovl dac ch pr
80. ll arguments The other possible settings characters are accepted but don t do any change Otherwise the behaviour is same as in GNU Bash The list of possible settings 44 a allexport exports all variables e e errexit exits upon ERR trap signal f noglob disables file name expansions e h hashall hashes all paths of the commands executed default on k keyword the search for variable assignments in a command won t stop after finding the command name n noexec just parses the commands doesn t execute them e u unset triggers an error upon the usage of an undefined variable v verbose echoes all the read shell input B braceexpand turns on brace expansion default on e t onecmd exits after the execution of one command e C noclobber file redirections are not allowed to overwrite existing files x xtrace prints the commands before executing them e shift n shifts shell the positional arguments variables 1 2 by given offset to the left The value of the variable is adjusted accordingly same as in Bash e test expression tests for a given expression similarly as in test commands For details on the expression syntax see Tests same as in Bash times prints the CPU times under user and kernel mode for this shell instance and its child processes which is not guaranteed by Windows just an estimation same as in
81. luated as arithmetical expressions If you assign a non array value to an array variable it s assigned to the array element with zero subscript The same happens with variable substitution This behaves the same as in GNU Bash Aliases are in fact also string variables They may be declared using the alias command and are expanded upon command parsing and may replace the command name There are some variables with special meaning that are always set the most usual Bourne shell and some Bash special variables e 1 2 3 etc contains the values of the positional arguments of this shell instance useful in scripts and may be altered using the set or shift commands e S contain the last command s exit status this instance of Bash Windows process ID the same you find in the Windows Task Manager the list of currently active settings that may be changed via the set built in and the number of shell positional arguments respectively e PS1 PS2 PS3 PS4 the values of the various prompts BashCommander may display is exactly the same as in Bash e IFS the separator used to split words in the shell expansions performed e PWD the current home directory e 6Q all the command arguments together for the differences between the two and further details see Bash reference manual There are more variables such as HOME or PATH that are always set on any correct Windows installation because all the Wind
82. mmand 2 4 1 Bourne shell built ins e file arguments dot command reads and executes commands from a file with given arguments in the current shell context The file if its name does not contain any slashes or backslashes is searched for in all the PATH directories and current directory as in GNU Bash non POSIX mode e args colon does nothing beyond argument expansion and redirections same as in Bash 43 e expression the same as test command except for the square brackets same as in Bash e break n exitsa for while until or select loop Exits as many nested loops as the number specifies default is 1 same as in Bash e cd L P dir changes the current directory The L and P options are accepted but don t change the behaviour of the command e continue n continues a while for until or select loop in its next iteration exits one nested loop less than the number specifies same as in Bash e eval args the arguments are read and executed as a command again so that the expansions are performed twice same as in Bash e exec cl a name command arguments executes another process and immediately after that exits there s no exec function on Windows so this is a simulation The 1 option is accepted but has no meaning c clears the environment for the new process and a passes the given string as a new program name e exit n exits the shell return
83. n zko rov ov API spole n s mnoha dal mi funkcemi pro dosa en schopnost kter pot ebuj funkce spolupracuj c s GUI dopl ov n n zv soubor historie p kaz a intern p kaz Bashe read P i ten se pak st d ek n na ud lost na vstupu konzoli nebo rou e pro ten ze souboru toto odpad a vol n pomocn funkce kter dod po adovan nebo men po et znak ten z konzole je zaji ov no n zko rov ovou funkc ReadConsoleInput kdy se obdr en informace o stisc ch kl ves n sledn p ev d j na znaky a pohyb kurzoru Pokud n kter funkce po aduj vr cen v sledku ihned po na ten ur en ho znaku je nutn obdr en text kontrolovat na v skyt onoho znaku a zkracovat jeho zbytek se ulo do vnit n ho bufferu a je odtud vr cen p i p t m ten Tento z sobn k se nav c mus m nit stejn pro v echny instance InputHandle s identick m intern m HANDLE aby byla zachov na koherence na ten ch dat To je e eno pou it m zjednodu en ch po tan ch odkaz p i kop rov n objekt t to t dy Probl m by samoz ejm vy e ilo i prost na t n po jednom znaku to ale nen p li v hodn z hlediska rychlosti vol n funkc opera n ho syst mu v dy p edstavuje zdr en P i ek n na vstup se m e aplikovat i pr b n p epo t van time out pot ebn pro zaji t n jedn vlastnosti p
84. nd OutputHandle the names are self explanatory The OutputHandle enables the Windows file or console output or pipe handles to be used in a same way as C streams it has a heavily overloaded operator able to output wide strings numbers and other things The operator is also NULL proof Otherwise the OutputHandle is the simpler class it does not need to alter any Win32 API console functions The InputHandle on the other hand contains many internal variables and functions to be able to recreate the feel of console input and at the same time support such things as auto completion resetting the buffer or time outs for input The main functions are the two overloads of readLine one of which has more features such as the above mentioned time out and uses the other Both the functions use readFile and for console handles also processConsoleInput and others All the internal variables buffers flags etc are created as mutable because const handles are used in many places of the code And logically the truly one needed thing that must not be changed when reading input from the handle is the handle value itself All the functions that change the buffer buf member are thread safe i e they need to initialize and enter the critical section that is connected with this handle the critSect member Because for file and pipe input it is never known which character is going to be the delimiter and calling the read operation for o
85. nd sets a flag indicating that the command has been interrupted in Env it also sends the shell s console input the Esc and Enter keys to reset the current line For this the SigHandler class must have a pointer to the instance of WinShell that created it it s given in its constructor The flag in Env is checked for by all the types of commands and upon the execution of a next one a special exception is raised However the Ctrl C signal in fact doesn t interrupt the innermost plain commands for the flag is checked only once upon the launch of a command The Ctrl C signal handler may be changed to perform some given commands using the t rap built in as well as other signals but there is probably no situation upon which they could be raised by Windows There is one method signalHandler that s always set as a handler except for the default Ctrl C handler and performs the commands that it s given upon a signal raise it decides which commands to launch by the signal number The trap commands are performed in a dedicated thread because Windows signal handlers must not contain such things as memory allocation and others SigHandler also supports the user preset Bash events such as DEBUG or ERR traps These are triggered with the triggerEvent and triggerDebugEvent functions their commands are executed synchronously They also heed the errexit shell setting and may set a flag in the Env telling the shell to exit There s also a function in Si
86. ne char only in a loop would be a waste of system resources the handle also contains a buffer of pre loaded input preloaded member Therefore one must be very careful when copying the handle the buffer is not copied completely in the copy constructor only the pointer is copied and a special parameter instance count is incremented So the copying from InputHandle to another InputHandle is correct but a copy through standard Win32 API HANDLE spoils the pre load buffer 54 The InputHandle class also contains various support functions i e to return the last error that occurred when reading from the file or check whether the buffer contains reguested amount of characters or the delimiter To enable console scrolling any redrawing of the buffer spoils it for console input handles there is a flag that turns the redraw off until a first valid character is read i e a key is pressed To support receiving of commands from the file manager InputHandle has another feature it s possible to set up another handle to be waiting for i e an event handle other than the internal one and if this handle is OK with the wait function i e the event occurs an exception of type InterruptedException is raised This is used in the Bash application itself only 3 4 GUI code schema The GUI code is quite simple the main object is practically the main window MainWin class It controls the individual shells each of which has its
87. o not list their contents F p Q append file type indicator append to directory names append double quotes g G o n in long listing 1 display no owner group specification with their numerical values all of which in fact under Windows have no real meaning h display human readable size in kilo mega gigabytes instead of bytes I pattern ignore files matching the given pattern 47 k size of block should be one kilobyte instead of 512 bytes 1 long listing with modification time size owner group and access rights m comma separated listing r reverse sort order R recursive s prefix the output with the total size of listed files in blocks S t X U sort by size modification time extension don t sort default sort by name w force given screen width X list entries by lines 1 one per line output e mkdir pv dir dir creates a directory If p is set creates all the parent directories if they don t exist For v shows output for current actions e mv bfiRTuvx t target dir S backup suffix filel file2 file moves files ie gives them a new pathname Its options are equivalent to cp except that it lacks a and p file attributes are always preserved as long as the file is moved not copied cp and mv executables are in fact the same and the action is decided by the name they were called e rm frRilv file f
88. okud jeden proces spust jin ten se st v naprosto nez visl m a nap i po skon en p vodn ho b d l Pro komunikaci mezi procesy nav c nelze vyu t v Unixu velmi ast ch sign l oproti unixov m 32 druh m je prakticky pou iteln jen jedin a v t inu jimi prov d n ch operac bez p edchoz domluvy aplikac nelze e it ani jinou cestou Pro Bash implementovan v BashCommanderu z toho plynou n kter omezen Komplikaci p edstavuje tak jin p stup k p stupov m pr v m soubor vobou syst mech V Unixu lze standardn po tat s p stupov mi pr vy pro u ivatele skupinu a ostatn ve Windows nic takov ho neexistuje a stoj vedle sebe dva syst my soubor FAT32 bez jak chkoliv p stupov ch pr v a NTFS vows s mnohem slo it j strukturou tzv access control list 13 V GUI sti se nav c objevuje dal probl m ovl d n kl vesnic Nutn se cel okno programu mus skl dat z n kolika d l ch oken nap konzolov v pis hlavn okno panel n stroj ve Windows v ak jen jedno z nich m e dost vat od syst mu informace o stisc ch kl ves m tzv keyboard focus Toto opr vn n lze mezi okny p ed vat 2 3 Anal za mo nost e en Z hlediska celkov ho rozd len aplikace lze uva ovat dva sm ry k odd len jednotliv ch funk nost do r zn ch spustiteln ch modul versus ke slou en v ech
89. olov ho Win32 API Funkce pro b n ten z konzole musely b t implementov ny znova aby obsahovaly pokro ilej mo nosti nastaven 17 vyu van automatick m dopl ov n m n zv soubor nebo histori p kaz S HANDLE na vstup nebo v stup libovoln je sv zan objekt kter poskytuje obecn funkce ten nebo z pisu Ty pak rozli uj typ dan ho vstupu nebo v stupu Dal detaily operac s konzolov m oknem a vstupem a v stupem viz 3 3 T dy pro ten a v pis jsou pou v ny jak v Bashi tak v jednotliv ch unixov ch p kazech Simulace unixov ch file descriptor do Bashe zavedena nebyla proto e nativn aplikace Windows kter j m budou nej ast ji spou t ny by tuto mo nost neum ly vyu t zbylo by upot eben uvnit Bashe samotn ho kter ale nen p li ast pravd podobn by nevyv ilo n ro nost implementace Proto se operace p esm rov n vstup a v stup mus omezit na soubory standardn vstup a standardn a chybov v stup Stejn tak pr va p stupu k soubor m jsou pouze simulov na tedy lze zm nit pr va soubor p padn i jejich standardn masku umask na realitu to ale nem efekt Jedin co p kaz chmod a p kazy jako 1s berou v potaz je standardn atribut soubor ve Windows jen pro ten k takov m soubor m se chovaj stejn jako kdyby na soubor dn ze skupin u ivatel nem la pr vo z pi
90. oops are meant here Other functions return status of whether it contains an incomplete command in its member structures and allow for complete parser reset e g upon Ctrl C hit Internally the parser stores a control stack ctrlStack consists of Control objects for keeping the various incomplete structured commands such as the parameters of a while or for loops The beginnings of compound commands are pushed on the stack and if and end such as done or fi is found the whole command is completed created as an object and stored in the buffer to return it For reading simple commands even as parts of compound commands the parser has a tokenStorage vector containing all the read words split by blanks It also stores some flags nestStack in a stack to search for the matching quotes or the end of arithmetical expression or command substitution and so on The behaviour of the parser is influenced by the contents of the ctrlStack as well as cmdExeFlags a set of flags useful for pipelines command list function definitions and sub shell execution The main parsing function is splitWords with the help of checkMetaCharacters The parser also expands the aliases and may do that recursively and parses all the redirection information and cuts it out of the command to be handled separately All the functions may throw exceptions which are caught outside in WinShell The parser is reset by WinShell after that 3 5 4
91. ov aplikace a ka d unixov p kaz net k se t ch v Bashi integrovan ch je jeden samostatn program Tim odpad slo it komunikace mezi sou stmi GUI a je umo n no samostatn pou it Bashe nebo unixov ch podp rn ch p kaz Komunikaci mezi GUI a shellem ale bylo nutn vy e it pro c l pr ce se nejl pe hodilo pou it syst mov ch zpr v Windows v kombinaci se sd lenou pam t GUI st programu standardn zpracov v syst mov zpr vy Windows jako ka d b n grafick aplikace na tomto syst mu mezi nimi ale m e dost vat i speci ln od Bashe ve kter m je na p jem zpr v od GUI dedikov no jedno speci ln vl kno Bylo by mo n pou t i roury ale bez syst mov ch zpr v Windows by se potom e en nevyhnulo tajn m parametr m spou t n aplikace ty d ky sv rychlosti a neviditelnosti pro u ivatele p edstavuj nejv hodn j e en Takto sice p i spou t n Bashe samostatn st le ek jedno vl kno programu na p choz 16 inicializa n syst movou zpr vu od GUI ale d ky tomu setrv v v klidov m stavu a nespot ebov v syst mov prost edky Jak u bylo zm n no na po tku bylo nutn n jak propojit Win32 API s objektov m modelem aplikace Toto nen p li probl m Bashe a textov ch p kaz kde nejsou jeho funkce vol ny p li asto a pov t inou nejsou sv z ny s n jak m konkr tn m objektem jedin slo it j
92. ows environment variables are imported into BashCommander environment upon its launch BashCommander therefore uses Windows PATH variable for programs search and Windows home directory settings e g for tilde expansion The BashCommander environment is shared for all the commands that are being executed synchronously including nested commands command substitution the last elements of pipelines and commands executed upon 40 reguest from the file manager window The environment is always copied for all the commands that are executed in background that means the changes made by these commands are not visible to others All the elements of pipelines except the last one are also executed in background so their changes to the environment are also not visible Note that for other programs executed by BashCommander i e running a script or another executable or executing a list of commands in a sub shell only the values of the exported variables and functions are visible The environment behaves differently from GNU Bash in some ways it is much more shared in general 2 3 6 Functions Functions are a way of storing lists of commands for later and repeated execution Functions in BashCommander behave egually as in Bash with some limitations Its Bash parser does not allow all the usual ways of declaring them The declaration of function looks like this function fc_name commands Theword function may be omitted but the par
93. p li pokro il funkce ostatn nap p enos soubor po FTP nebo p stup do komprimovan ch archiv b n funkce souborov ch mana er p li nevyhovuj spolupr ci s konzolovou st V programu budou zahrnuty jen p kazy z Unixu pro pr ci se soubory ne programy pro automatizovanou pravu textu Tyto mohou b t pro aplikaci cenn m p nosem d ky prov zanosti s nativn mi programy pro Windows je mo n a vhodn pou t dohromady s BashCommanderem jejich implementaci odjinud nap GnuWin32 4 10 1 4 Volba jazyka a platformy Pro pr ci byl zvolen programovac jazyk C vzhledem ke spojen rychlosti v sledn ho k du s mo nost objektov ho p stupu k probl mu e en nav c nutn vy aduje pou it relativn n zko rov ov ch API funkc kter jsou z prost ed vy ch jazyk jako Java nebo Cs dostupn jen obt n Proto e byl od za tku jako c lov opera n syst m vybr n Windows a p enesen Bashe pod Windows je jedn m z c l pr ce nen t eba uva ovat p enositelnost na jin syst my Windows verz NT4 95 98 a ME a star ch jsou v dne n dob i Microsoftem pova ov ny za ji p ekonan a pou vaj se pouze na velmi mal m procentu v ech po ta s Windows proto je program ur en jen pro nov j verze a profituje z vyu it n kolika nov ch funkc Win32 API kter jsou dostupn a pro Windows 2000 a nov j Pro syst mov
94. project 3 2 3 The Bash application The Bash application has its sources located in the BASH folder the wmain function is in main cpp the rest are definitions of the main classes and supportive classes All of the source files for Bash implementation include the winsh h which contains all the standard defined constants Some more constants closely connected with the Bash language i e meta characters blank charcters etc are in lang const h The main program object is located in winshell h amp winshell cpp The environment which is shared by most of the objects is in env h amp env cpp in a class named Env Definitions of various kinds of variables arrays functions hashes aliases are in var h and var cpp All the classes that ensure the parameter expansions etc are declared in expandor h and defined in several files argexpandor cpp expansionbase cpp and expandor cpp Other classes serve as support for the expansions such as tester h and tester cpp or arithm h with arithm cpp All the expansion classes along with the Executor class executor h executor cpp serve the various command classes for them to be able to execute themselves these are located in the command h command cpp pair of files The parser responsible for splitting the input into commands uses the files parser h and parser cpp as well as some supportive objects from control h and control cpp All the classes that throw some exceptions use execept
95. racters such as new line or and the individual commands are split into words regarding blank characters space tab new line The first word of a command is the command name it may be a name of a shell built in an external program or a shell function the rest of the command are parameters A simple command may also contain some variable assignments preceding the command name see Environment variables and redirections Before a command is executed variable assignations and redirections are applied and it undergoes several types of expansions same as GNU Bash A redirection means that the command input or output is being written or read from somewhere else than usually In BashCommander you may redirect the input or output or the error stream from to a file and you may append to the file or redirect error stream to output and vice versa The syntax is quite straightforward for input redirection it s 0 lt file for output 1 2 gt file appending to a file 1 2 gt gt file and combination of the outputs 112 amp 112 Other types of redirections involving file descriptor numbers other than standard o input 1 output 2 error stream are not supported Here documents here strings and manipulation with file descriptors are also not supported When a command is executed in a normal way Bash waits for it to finish also if an external program is executed If you want a command to be executed on the back
96. s in this step but I recommend leaving the default setting Whether the Start menu and Desktop short cuts are created is up to user s selection However the program always tries to change the PATH variable Uninstallation may be done via the short cut in the Start menu which is added upon installation or through the common Windows Add Remove programs interface Just select the uninstallation and confirm its proceeding 2 2 Using the GUI To start the program GUI click the icon in Start menu or on the Desktop or execute the bashcom exe program in the installation directory When launched an empty window with no open tabs appears There are six icons for the most basic operations with shells The first of them creates a new shell instance which is run in a tab The second one opens a new commander window including the shell The third tries to force close the currently active tab no matter what type of tab The next two buttons serve to switch between the shell tabs in both directions left and right You may also switch the shells and commanders by 33 clicking on the tab names in the bottom If a shell is closed e g by typing an exit command its tab either shell window or file manager disappears instantly The last button opens the settings window simple dialogue window involving several settings for detailed description see section Settings and start up scripts To use the shell in an open tab just click or otherwise
97. se uk zalo vyu it d di nosti pro t dy oken a p stupu k ostatn m okn m p es spole nou z kladovou t du Byla vytvo ena obecn t da Controller pro cokoliv co m e ovl dat okno shellu hlavn okno commander a Shell pro cokoliv co m e b c Bash zobrazovat a kontrolovat commander okno shellu V p pad okna souborov ho mana eru se tu tedy objevuje v cen sobn d di nost vzhledem k hlavn mu oknu je pova ov n za obecn panel vzhledem k oknu shellu jde o jeho nad zen ho Vol n metod a syst mov zpr vy asto p ed v d l p slu n m sm rem m e ale v sledky upravovat nap v p pad zji ov n velikosti konzolov ho okna vrac men v ku aby se do zbyl ho prostoru mohl vm stnat v pis seznam soubor v adres ch Proto e jsou ob z kladov t dy de facto abstraktn a neobsahuj dn datov polo ky ani t la metod a jde o virtu ln d di nost nedoch z s jej m zaveden m k dn m probl m m Vjazyc ch typu Java by bylo mo n pou t m sto z kladov ch t d interface a v sledek by byl ekvivalentn C tento syntaktick obrat nenab z a tak je n sobn d di nost zp sob jak dos hnout jeho efektu 3 3 Konzolov vstup a v stup Pro ten z libovoln ho vstupu a v pis v stupu je v cel m Bashi i dod van ch unixov ch p kazech pou v no t d InputHandle a OutputHandle odvozen ch od z kladn
98. shCommander also supports all the structured commands you may find in Bash this includes the code flow control commands usually found in any programming language as well as command lists to simplify redirections or execute something in a sub shell The list of the supported commands e command lists sequences of commands connected with amp amp or 11 which means that a command is executed only if the commands that precede it in a command list have exited normally for amp amp or with errors for In other cases the given command and all its successors are not going to be executed e pipelines sequences of commands connected with The second command in a pipeline reads the output of the first one and gives its output to the third and so on The first command in the pipeline reads from the standard input the last one writes to the standard output if not redirected As opposed to GNU Bash there is no child process creation for all the pipeline members if they are not external programs However all the commands except the last one are executed in background using different threads so they cannot affect the shell environment but the last pipeline member can e until the syntax is until test commands do executive commands done This is almost the usual repeat until loop except that the condition is tested in the beginning It behaves exactly the same as in Bash runs the test commands and if
99. ssions are described in detail in the Arithmetic section The syntax is expression e test command tests for a given condition see Tests and returns a zero exit status if it was fulfilled Also has the same behaviour as the test commands in GNU Bash The syntax expression e command groups lists of commands put together either to simplify redirection one redirection for all the commands or to be executed in a sub shell and not affect the current environment i e variables current directory etc This also has the same behaviour as in Bash The commands look like this commands for plain command group and commands for sub shell execution The commands that are about to be executed in a sub shell are written to a temporary file and a new BashCommander process is created to execute them The temporary file is deleted afterwards Be sure to have your Windows temporary files directory set up and accessible All the types of commands may of course be nested which creates the structure of the whole scripts 37 2 3 4 Expansions Before the execution of each simple command BashCommander performs several expansions most of them work the same as in GNU Bash All the common expansions are performed except for process substitution which is not supported by BashCommander They are done in this order 1 Brace expansion parameters within braces are expanded i e d a b c e is expanded to dae dbe d
100. st do jedn Druh alternativa m v hodu v tom e odpad e en komunikace mezi stmi pomoc prost edk opera n ho syst mu a v e je mo n prov st p m m vol n m funkc a p ed v n m parametr Probl m je ov em to e n kter funkce vy aduj GUI program a n kter naopak konzolovou aplikaci nap pouh kop rov n soubor nebo v pis adres e p padn zpracov n souboru skriptu dn GUI nepot ebuje pro interaktivn pr ci je ale nezbytn Ve Windows ale nelze uspokojiv napsat aplikaci kter by vyhovovala ob ma lze vytvo it bu konzolovou aplikaci kter sice m e vytvo it okno ale jej konzole z stane viditeln lze ji schovat ale v dy bude n jakou dobu vid t nebo GUI program kter se ale nebude schopen p ipojit k ji existuj c mu konzolov mu oknu ze kter ho byl spu t n a v dy bude m t jen mo nost vytvo it nov program tory Microsoftu navrhovan e en tohoto probl mu je tak upraveno i nap MS Visual Studio je pou it dvou samostatn ch modul detaily viz 6 Slou en v ech funkc do jednoho modulu nav c komplikuje pou it jednotliv ch sou st zven nap p kazu cp jako samostatn ho programu nebo samotn ho Bashe jako interpret skript bylo by nutn pou t p ed v n tajn ho parametru co je pro vn j kompatibilitu s unixov mi programy nemo n p padn pos l n speci ln zpr vy s
101. su Tento p znak lze tak p kazem chmod m nit Bash tak ne e probl m ukon en j m spu t n ch aplikac p i b n pr ci toto nen p li probl m konzolov aplikace je ve Windows typicky mo n ukon it pomoc sign lu Ct r1 C krom toho by i p i hl d n vytvo en ch proces vznikaly ji zmi ovan pot e pro programy z nich spou t n Proto nen implementov na ani kontrola proces spou t n ch z Bashe na pozad S prov z n m GUI a Bashe je spojen ot zka zji ov n zm ny na v stupu konzole to je provedeno ji nast n n m automatick m obnovov n m stavu zobrazen zde na frekvenci max cca 20x sec ka d obnoven mus m t od GUI potvrzen p ekreslen tak e nehroz zahlcen grafick sti syst mov mi zpr vami takto se nav c obnovuje jen to okno shellu kter je zrovna viditeln aktivn topmost tak e nejde o p li hardwarov n ro n proces Oproti jin m podobn m aplikac m viz Unix pseudoterminal emulation frustrations v 5 nav c b n nem e doj t ke ztr t zobrazovan ch dat p li rychl m v pisem je toti mo n pomoc syst mov ch zpr v vyvolat scrollovani p mo v bufferu konzolov aplikace kter by m l b t pro toto dost velk zobrazen je p epos l no do GUI Keyboard focus v GUI tedy p jem zpr v o stisknut ch kl ves ch je za ka d ch okolnost krom p padu
102. t mu nap rourami nebo procesy tedy i zp sob spou t n jin ch program p padn ten jejich v stupu V pr ci se uva uje i spou t n shellu sebou sam m jeho efektu lze dos hnout i jinak ne form ln op tovn m spu t n m vlastn ho modulu Podstatnou ot zkou je tak ovl d n GUI aplikace podle c le pr ce nutn zam en hlavn na pr ci s kl vesnic Je t eba vy e it jednak p ev d n stisk kl ves na znaky v konzolov m okn v speci ln ch znak pro pohyb kurzoru apod a jednak jejich odd len od kl vesov ch zkratek pro pr ci s GUI programu Tak spolupr ce v pisu seznamu soubor v souborov m mana eru s konzolov m oknem mus b t co nejefektivn j a pro u ivatele co nejp jemn j probl m souborov ho mana eru otv r i dal ot zky jeho integrace s Bashem Vzhledem ke zvolen platform tedy ist mu Win32 API a programovac mu jazyku C je nutn i e en prov z n objekt jazyka C s navenek neobjektov m p stupem funkc opera n ho syst mu designovan ch pro pou it z jazyka C Podstatnou ot zkou je tak rozsah podpory intern ch p kaz a vlastnost Bashe jde hlavn o uv en frekvence jejich pou v n u ite nosti v etn vztahu k syst mu Windows a jejich smyslu v n m a tak n ro nosti jejich naprogramov n s prost edky Win32 API 2 2 Technick probl my implementace V t ina technick ch p
103. ted options work in the same way as in Bash e source filename seethe dot command same as in Bash e unalias a name removes the aliases for given names or all aliases for a same as in Bash 2 5 Supplemented Unix file operating programs BashCommander installation contains a small set of most used Unix file operating programs Their executables are copied to the BashCommander installation directory which is added into Windows PATH environment variable and so they may be executed comfortably from within BashCommander and also Windows Command Line for example by just typing their name Usually they 46 work the same as their GNU versions except that they lack long option names and some options may also be unsupported They are e cat AbeEnstTv file echoes the contents of files or standard input if none are given on the standard output It s able to number non blank lines b print at the end of the lines E number all the lines n suppress blanks longer than one line s show tab characters as I T and show non printing characters except new line and tab A is the equivalent of vET e is vE t is vT The supported options work equally to GNU cat e chmod Rcvf mode file file in Unix this changes the file access rights this implementation supports only the changes in the read only attribute of files this means that if you take away the right
104. the console window Bash language interpreter for Windows and several simple file operating programs well known from the Unix like operating systems The program itself is not an execution environment for Unix applications nor does it reguire one to run Any Windows application may be run as a command As to the Bash language and its internal commands implementation the goal is to achieve as close compatibility with the original version as possible although limited in some ways The execution of script files written in this language is also supported the application aims to provide their easy portability The thesis also includes an analysis of the implementation problems discussion of possible solutions and a comparison of BashCommander with existing Bash interpreters for Windows Keywords file manager Bash Windows terminal program Text pr ce 1 vod 1 1 Motivace Pro operace se soubory m na v t in sou asn ch opera n ch syst m u ivatel n kolik mo nost jak p stup zvolit Pravd podobn nejpou van j m ale z hlediska rychlosti a efektivity nep li v konn m je pou it b n ch souborov ch mana er jako nap Pr zkumn k Windows kde se p edpokl daj hlavn akce prov d n s pou it m my i a p ep n n mezi n kolika otev en mi okny programu v vA Druhou efektivn j mo nost p edstavuj dvoupanelov souborov mana ery commandery zn m ji z prost ed
105. to the shell application itself COMMAND containing the source files of all the implemented Unix file operation commands COMMON in which there are files needed for more than one part i e all the support functions for both Bash and Unix utilities or a header file for memory mapping definition shared by Bash and the GUI The last directory GUI contains the files needed exclusively by the GUI All the C code is divided into object declarations in h files and definitions in cpp files one header declarations file may contain declarations of more than one C class and the definitions may be contained in more code files 3 2 1 Common supportive libraries There are some objects that are shared by Bash and the Unix file utilities mostly related to reading standard input and writing output and to matching the shell patterns Some definitions of commonly used exceptions are also shared All the files of this type are located in the COMMON folder The most significant of them are probably the definitions of input and output objects in the files streams h and streams cpp The exception definitions are in except common h except common cpp and outofmem h outofmem cpp all the exception classes for both Bash and Unix file operations are derived from the class AbstractException which is to be found in the first pair of files The other one contains special exceptions used to handle out of memory errors new failures All t
106. ts are used in test commands and in the test built in The test commands consists of expressions they may be enclosed in brackets negated with or connected with amp amp a for test built in and o The possible expressions are a e u O G file true if file exists e d g file true if file exists and is a directory e f file true if file exists and is not a directory e n string true if string is not empty o option name true if the shell option with this name is enabled details in the description of set built in e p file true if file exists and is a named pipe e r file true if file exists and is readable e s file true if file exists and its size is non zero e t number true if given number is a file descriptor referring to a terminal i e if it s O 1 or 2 and the given standard handle is not redirected e w file true if given file is writeable e x file true if given file is executable tests it according to the file s suffix e z string true if the length of the given string is zero 42 e N file rue if file exists and its last access time is lower or equal to its modification time e string pattern string pattern in test commands matches a string against pattern In test built in just tests for equality of the two strings e stringl lt string2 stringl gt string2 tests for string alphabetical or
107. v p ev d n m unixov ch program tzn i Bashe do prost ed Windows je Cygwin 2 Je tedy z ejm prvn m kandid tem ke srovn v n Na rozd l od BashCommanderu v tomto projektu jde o zaji t n v ech b n ch unixov ch API funkc a t m p enos jednodu e p ekompilovan ch zdrojov ch soubor nap linuxov ch program na opera n syst m od Microsoftu Pro Cygwin tedy existuje obrovsk mno stv unixov ch utilit a Bash je jen jedna z nich V sou asn dob srpen 2007 jde o aktu ln verzi Bashe 3 2 je vytvo en ze stejn ch zdrojov ch k d jako GNU Bash tak e je s n m naprosto kompatibiln Lze pro n j pou t i n kter grafick termin lov program d ky podpo e syst m X Window Bash v BashCommanderu m ur it omezen viz sekce 2 4 nicm n na druhou stranu je l pe prov z n se syst mem Windows b hov prost ed Cygwinu vytv pro sv programy speci ln ko enov adres vlastn domovsk adres e u ivatel atp tak e nutn doch z k d len program na ty kter jsou v Cygwinu a ty venku M j projekt se naopak sna o integraci do ji existuj c ch struktur Nav c pro n j nen t eba dn zvl tn b hov prost ed ani dn podp rn dynamick knihovny Velice podobn m p padem je Bash jako sou st projektu MSYS pod MinGW 8 MinGW takt p ev d unixov GNU programy na Windows MSYS je zam en hlavn
108. v z n komunikace a potom k pos l n p kaz a informov n o jejich proveden Pro p ed v n objemn j ch zpr v je k dispozici oblast sd len pam ti V r mci GUI se mezi jednotliv mi okny m sto vol n funkc na jim p slu n ch objektech viz popis p i azen okna k objektu v p edchoz sekci asto pou vaj pr v syst mov zpr vy Takto jsou nap panely informov ny o aktivov n zobrazen navrchu nebo hlavn okno ostisku n kter kl vesov zkratky Hlavn d vodem volby tohoto postupu je v cevl knovost grafick sti programu krom prvn ho threadu obsluhuj c ho hlavn okno je po otev en ka d ho panelu spu t n dal kter se v nuje jen zobrazov n okna shellu a komunikace s n m Pou it syst mov ch zpr v je nejjednodu cesta k zaji t n proveden po adovan operace v jin m vl kn pokud nen p li d le it doba vykon n co u v t iny akc programu nenast v mal zpo d n nap u zmi ovan ho stisknut kl vesov zkratky je akceptovateln Syst mov zpr vy v r mci jedn aplikace nav c maj tu v hodu e jako jejich parametry lze p ed vat p m ukazatele na r zn datov struktury nap kdy nov spu t n shell po aduje p id n do seznamu panel hlavn ho okna pos l ukazatel s m na sebe Samoz ejm pokud nez le na tom ve kter m vl kn bude akce provedena prost vol n m
109. vk proto e ty nedod vaj pln daje jen notifikace stisk kl ves Windows toti pou vaj pro dod v n informac syst mov zpr vy hlavn n stroj komunikace syst mu s aplikacemi i aplikac mezi sebou a to 3 druhy pro stisk kl vesy pu t n kl vesy a naps n znaku p i em t et typ zpr v se vyr b nep mo z prvn ch dvou pomoc syst mov ho vol n P m p evod z informac o stisc ch kl ves na napsan znaky nen mo n stejn tak p epos l n stisk kl ves mezi aplikacemi to lze jen pro zpr vy o naps n znaku Nav c nen mo n ze znak nebo k d kl ves jednodu e syntetizovat zpr vy o stisc ch kl ves nejde to v p pad stisku modifik tor jako je Ctrl nebo Shift I p i pou it standardn ch ovl dac ch prvk lze probl m vy e it p ep n n m keyboard focusu je ale nutn rozhodnout kter okno bude v echny stisky kl ves dost vat v vahu p ipad bu hlavn okno GUI nebo termin lov okno aktu ln zobrazovan ho shellu vobou e en ch nen velk rozd l snad jen to e termin lov okno m lep p stup k shellu a hlavn okno zas snadn ji rozhoduje o glob ln ch kl vesov ch zkratk ch 2 4 Zvolen postupy hlavn struktura Z mo nost rozd len jednotliv ch funkc aplikace do samostatn ch modul jsem vybral tuto cel GUI st je jeden spustiteln program Bash je druh jako samostatn konzol
110. vl knu p ed v rozkazy k vykon n v emo n ch akc nap scrollov n konzolov ho okna stisk n kter ch speci ln ch kl ves F10 TAB ipky apod zobrazen historie p kaz nebo automatick dopl ov n n zv soubor Zpr vy o stisc ch kl ves b n ch znak jsou pos l ny ve standardn m syst mov m tvaru WM CHAR p mo konzolov mu oknu shellu tak e se projev p i vol n libovoln ch API funkc ten Automatick dopl ov n n zv soubor a historii p kaz kv li zp sobu implementace nelze pou t p i samostatn m spu t n Bashe bez GUI to ale projekt p edpokl d jako v t inou neinteraktivn ist za elem prov d n skript tak e to nep edstavuje p li v raznou nev hodu V hodou je naopak mo nost nastaven kl vesov zkratky pro proveden t chto dvou akc Jak jsem ji p edeslal krom syst mov ch zpr v pou vaj procesy pro p ed v n informac tak sd lenou pam vytvo enou ve Windows b n m zp sobem mapov n m fiktivn ho do asn ho souboru do pam ti P i navazov n kontaktu se shellem je vytvo ena jedna st l oblast sd len pam ti HANDLE na n se shellu pos l v inicializa n zpr v kter slou po as cel ho jeho b hu Obsahuje parametry konzolov ho okna m n se p mo a na zm nu se upozor uje k tomu ur enou zpr vou n zev pr v spou t n ho programu a prostor pro kop rov n
111. ws message loop in its thread function threadProc that lasts for all the application life It handles only the messages from the master application upon start up it waits for the WM ASSOC MASTER with the right parameters for shells that aren t run under GUI this waiting never ends when it s given this message it creates the shared memory and sends a handle back in WM ASSOC SLAVE from associateMaster From that time on the communication is established and the message thread sends the main application refresh status messages WM UPDATESCREEN which must be confirmed by the master WM SCREENOK The screen is updated once in a while pre set at 50 ms may take longer if the WM SCREENOK message is not received a timer is always set to ensure this The redrawing messages may be switched on or off on request from the master WM SETTOPMOST The application may be also forced to close by the GUI when it sends a WM CLOSEAPP message the MsgThread calls a function in WinShell telling it to exit by a direct call to ExitProcess Bash when being run under GUI has its console window hidden and does not receive any input from Windows all the input is sent by the master application either directly to the console window the WM CHAR messages or also through the message thread WM KEYUP WM KEYDOWN that are then converted and written as console input by the corresponding WinShell object This thread also ensures 62 that the console
112. yst mu co zas pro u ivatele p i spou t n nen provediteln Druhou mo nost je odd len v ech funkc souborov ho mana eru termin lov ho programu Bashe i v ech unixov ch pomocn ch program To ov em p in nemal n roky na komunikaci mezi takto vznikl mi moduly p edev m GUI aplikacemi a Bashem cel e en je ale technicky s pomoc prost edk opera n ho syst mu provediteln Implementa n jednodu odpad dost komunikace nav c a dal probl my nevznikaj se jev slou en v ech GUI funkc do jednoho modulu Slou en n kter ch GUI a konzolov ch st vytv v e popisovan probl m slou en v ech konzolov ch st op t zamezuje pou it unixov ch p kaz samostatn proto nen vhodn V kontextu samotn ho Bashe existuj dv alternativy p stupu ke spou t n dal ch program hlavn sebe sama a vytv en pipelines ada program spojen ch rourami ka d te v stup p edchoz ho a zapisuje do vstupu n sleduj c ho toti p vodn unixov tedy spou t n dal ho Bashe pro v stup z vno en ch p kaz a pipelines a jako druh pou it nov ch prost edk hlavn vl ken Prvn mo nost je z ejm kompatibiln j s unixovou verz Bashe ale ve v Windows nar na probl m neexistence funkce fork klonov n ji spu t n ho 14 programu kter je hlavn pro rychlost tohoto e
113. zov n konzole interpretu jazyka Bash pro Windows a n kolika jednoduch ch program pro pr ci se soubory zn m ch z opera n ch syst m typu Unix Program nen prost ed pro b h unixov ch aplikac ani takov prost ed pro sv vlastn fungov n nevy aduje jako p kazy je mo n spou t t libovoln nativn aplikace pro Windows Co se t e implementace jazyka Bash a jeho intern ch p kaz c lem je co nejv t p ibl en se origin ln verzi i kdy s n kter mi omezen mi Podporov no je i spou t n soubor se skripty psan mi v tomto jazyce aplikace se sna zajistit jejich snadnou p enositelnost Sou st pr ce je d le anal za probl m implementace diskuse jejich e en a srovn n s existuj c mi interprety jazyka Bash pro Windows Kl ov slova souborov mana er Bash Windows termin lov program Title BashCommander Author Ond ej Du ek Department Department of Software Engineering Supervisor RNDr Jan Kofro Supervisor s e mail address jan kofron mff cuni cz Abstract The thesis deals with the implementation of the BashCommander application which serves to effectively manage files in the Windows operating system environment with the use of text commands It combines a two panel file manager with a text command console that uses Bash language syntax The implementation covers a graphical user interface with file manager and terminal program to display

Download Pdf Manuals

image

Related Search

Related Contents

農研機構 食品総合研究所 研究報告 77号  Sony RMT-VP1K Operating Instructions  operation manual manuel d'instructions guida utente manual de  Archive InterOperability Users Manual  Arat NS1007.10 holder  "取扱説明書"  PDF簡易取扱説明書  Alarm Talker©  

Copyright © All rights reserved.
Failed to retrieve file