announcements
play

Announcements Check course web page under assignments for FAQs - PowerPoint PPT Presentation

Announcements Check course web page under assignments for FAQs Read FAQs before sending mail Assignment Clarification Semantics of = differ slightly between chmod and chmod2: Suppose file1 has permission rwxrwxrwx chmod u=rw


  1. Announcements � Check course web page under assignments for FAQs � Read FAQs before sending mail

  2. Assignment Clarification � Semantics of = differ slightly between chmod and chmod2: � Suppose file1 has permission rwxrwxrwx � chmod u=rw file1 gives rw-rwxrwx � chmd2 {u=rw} file1 gives rw------- � So the = in chmod2 is absolute for everything, but chmod it affects only the party specified (ie. u).

  3. Clarifications Cont’d � C vs. C++: I encourage you to do the assignment in C++, but not mandatory � Do not have to use all of C++, like streams. OK to embed C function calls inside implementation of objects � Part 1 of assignment: no prompting! � Part 2 of assignment: when using –e option, use quotes: findcode –e ‘{.txt;.ini}’ because ; is a special character for the shell

  4. Getting input � Here is one way: //-------------------------------------------------------------------------------------------- int main(void) { char buf[MAX_LINE_LENGTH]; while(fgets(buf,MAX_LINE_LENGTH,stdin)) { //strip the new line: buf[strlen(buf)-1]=0; processLine(buf); } }

  5. Changing permissions: � You will need stat(), and chmod() � stat() was talked about in tutorial today. � int chmod(const char *path, mode_t mode); � Not the same as the command chmod! � path tells chmod() which file’s permission to change � mode is the octal number we talked about last week

  6. Assignment marking criteria � Tests on basic functionality ~ 40% � How solid is your code? ~ 40% � Tests � Code inspection: memory leaks, dangling file descriptors, memory corruption � Coding style ~20% � Crashes – seg faults – are more serious than a failed test

  7. Coding style: a sample of criteria � Appropriate arrangement of modules � Magic numbers � Variable naming � Code duplication � Giant methods � Unnecessarily complicated or inefficient code � Utterly unsafe code � And…comments

  8. Comments: under commented if [ $# -ne 1 ] What does this code do? then don’t answer if you know shell exit 1 fi scripting if [ ! -d "$1" ] then exit 2 fi cd $1 ls -a | cpio -o >/dev/rmt0 if [ $? -eq 0 ] then rm * else exit 3 fi

  9. About right… # A program to backup files in a directory. Removes the files if # backup is successful. if [ $# -ne 1 ] # $# refers to the number of args then exit 1 fi # -d tests if something is a directory, $1 = 1 st arg if [ ! -d "$1" ] then exit 2 fi cd $1 ls -a | cpio -o >/dev/rmt0 if [ $? -eq 0 ] # $? = return value. 0 if successful. then rm * else exit 3 fi

  10. Overdone: # A program to backup files in a directory. Removes the files if # backup is successful. if [ $# -ne 1 ] # $# refers to the number of args then exit 1 # quit the program with code 1 fi # -d tests if something is a directory, $1 = 1 st arg if [ ! -d "$1" ] then exit 2 # quite the program with code 2 fi cd $1 ls -a | cpio -o >/dev/rmt0 if [ $? -eq 0 ] # $? = return value. 0 if successful. then rm * # remove all files… else exit 3 # exit with code 3… fi

  11. Software Tools

  12. Absolute Basics Command Description cd change current working directory pwd print current working directory mkdir creates a directory rmdir removes directory, must be empty rm removes a file. cp copies files/dirs mv moves files/dirs chmod change file permissions – discussed in class

  13. Basics: covered in web tutorial Command Description ls lists files – more discussion to come in class cat displays a file more like cat, but displays a file 1 screen at a time ps lists processes kill kills an active process who displays currently logged on users finger displays more details about a user su switch accounts du disk usage display 1 st /last couple of lines head, tail wc counts the number of lines,words, characters in a file lpr, lpq, lprm printing related commands clear clears the screen

  14. Advanced tools – topic today Command Description grep,egrep search file(s) for strings sort sorts the contents of files uniq eliminates duplicate lines find search for files and much more tar archive files/dirs diff show change(s) made to a file by comparing to new version compress, compress/decompress files uncompress, gzip, gunzip sed stream editor – transforms text as it streams through

  15. grep, egrep & regular expressions � grep, egrep searches for text � Uses regular expressions � Reg. Exprn = sequence of ordinary chars and special chars (\, ^, *, $, [],.) Simplest reg. Exprn = just a string: � werewolf:~% grep 'con' socket*.cpp socketclient.cpp: if( connect(sockfd,(struct sockaddr *)&server,SIZE)==-1) socketclient.cpp: printf("connect call fails\n"); socketserv.cpp: printf("waiting for connection...\n"); socketserv.cpp: continue; socketserv.cpp: //parent should close the new socket connection.

  16. Special characters � Dot (.) matches any 1 character: � w.r matches lowercase, worship or warning. � [] restricts range: � w[ea]r matches lowercase, warning � Supports negation with w[^ea]r (anything but) � Specify range with dash(-) : w[a-z]r � \{ and \} matches specific # of chars: � n\{2,4\}

  17. Special chars cont’d � * matches zero or more of the preceding expression: � grep 'p*' myfile displays _____________________ � grep 'ppp*' myfile displays___________________ � ^ anchors in front, $ anchors at the end � grep '^[Tt]he' myfile displays _________________ � grep '\.$' myfile displays_____________________

  18. egrep � Like grep, but supports more matching options � + matches 1 or more occurrence � ? Matches 0 or 1 occurrence of anything � Allows search for A or B using | � egrep 'dd+|socket' socket*.cpp displays: ________________________________

  19. Sort Name Age Team Prelim Final Stanford, Jeffrey 25 HIMA 47.07 46.32 Liggett, Michael 27 DYNA 47.25 48.12 Baker, Chase 29 GMUP 56.28 57.79 Kittredge, Brad 25 TOC 45.05 46.22 Richner, Thomas 27 UCLA 50.00 48.79 McCormick, Aaron 27 RMM 49.00 49.30 Thorum, Thomas 29 UTAH 50.00 49.45 Paul, Darcy 26 NEM 52.00 50.17 Welting, Evan 27 DYNA 50.50 51.04 Wanie, Lee 28 TOC 46.00 46.39 Linderman, Ross 25 PNA 52.55 51.17 Wen, Patrick 29 UCLA 57.50 55.93 Frohlich, Jon 29 UTAH 49.10 49.20 Parnes, Jason 29 SDSM 63.00 59.11 Perunovich, Steven 27 HIMA 59.50 52.93

  20. Sort $ sort swimresults Baker, Chase 29 GMUP 56.28 57.79 Frohlich, Jon 29 UTAH 49.10 49.20 Kittredge, Brad 25 TOC 45.05 46.22 Liggett, Michael 27 DYNA 47.25 48.12 Linderman, Ross 25 PNA 52.55 51.17 McCormick, Aaron 27 RMM 49.00 49.30 Parnes, Jason 29 SDSM 63.00 59.11 Paul, Darcy 26 NEM 52.00 50.17 Perunovich, Steven 27 HIMA 59.50 52.93 Richner, Thomas 27 UCLA 50.00 48.79 Stanford, Jeffrey 25 HIMA 47.07 46.32 Thorum, Thomas 29 UTAH 50.00 49.45 Wanie, Lee 28 TOC 46.00 46.39 Welting, Evan 27 DYNA 50.50 51.04 Wen, Patrick 29 UCLA 57.50 55.93 $

  21. Skip fields with + $sort +2 swimresults Wanie, Lee 28 TOC 46.00 46.39 Paul, Darcy 26 NEM 52.00 50.17 Baker, Chase 29 GMUP 56.28 57.79 Wen, Patrick 29 UCLA 57.50 55.93 Welting, Evan 27 DYNA 50.50 51.04 Parnes, Jason 29 SDSM 63.00 59.11 Frohlich, Jon 29 UTAH 49.10 49.20 Thorum, Thomas 29 UTAH 50.00 49.45 Linderman, Ross 25 PNA 52.55 51.17 Kittredge, Brad 25 TOC 45.05 46.22 Richner, Thomas 27 UCLA 50.00 48.79 Liggett, Michael 27 DYNA 47.25 48.12 McCormick, Aaron 27 RMM 49.00 49.30 Stanford, Jeffrey 25 HIMA 47.07 46.32 Perunovich, Steven 27 HIMA 59.50 52.93 Why didn’t it work?? �

  22. Skip leading spaces with –b % sort -b +2 swimresults Stanford, Jeffrey 25 HIMA 47.07 46.32 Linderman, Ross 25 PNA 52.55 51.17 Kittredge, Brad 25 TOC 45.05 46.22 Paul, Darcy 26 NEM 52.00 50.17 Liggett, Michael 27 DYNA 47.25 48.12 Welting, Evan 27 DYNA 50.50 51.04 Perunovich, Steven 27 HIMA 59.50 52.93 McCormick, Aaron 27 RMM 49.00 49.30 Richner, Thomas 27 UCLA 50.00 48.79 Wanie, Lee 28 TOC 46.00 46.39 Baker, Chase 29 GMUP 56.28 57.79 Parnes, Jason 29 SDSM 63.00 59.11 Wen, Patrick 29 UCLA 57.50 55.93 Frohlich, Jon 29 UTAH 49.10 49.20 Thorum, Thomas 29 UTAH 50.00 49.45

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend