solving a problem scandir and unix ls
play

Solving a problem: scandir and Unix ls Access all the entries in a - PowerPoint PPT Presentation

Solving a problem: scandir and Unix ls Access all the entries in a directory, or selected entries ls *.cc, ls -l *, ls -lt foo.* process the entries in some way (add sizes, print, ) What is in a directory? ., .., files,


  1. Solving a problem: scandir and Unix ls ● Access all the entries in a directory, or selected entries ➤ ls *.cc, ls -l *, ls -lt foo.* ➤ process the entries in some way (add sizes, print, …) ● What is in a directory? ➤ ., .., files, subdirectories ➤ what is a file in Unix? What kind of resources are associated with a file? How do you create/remove a file from within a running program? ➤ How are files and directories accessed from a program? ● How is a directory tree backed-up to disk/tape? ➤ What are the issues? 9. 1 Duke CPS 108

  2. Solving another problem: search for words ● Web-based search engines ➤ Search for “Titanic” + “Linux” in Alta vista ● File-based search engines ➤ What’s the file that has the reference to “elephants”? ● What are the issues in the searches? ➤ User’s perspective ➤ Programmer’s perspective ● What about approximate matches ➤ search for “pincake” or “pancake” or “pancakes” or … ➤ are approximate/fuzzy matches a good idea? 9. 2 Duke CPS 108

  3. Coping with transferable ownership ● Factory creates a class, who deletes it? Foo * f = FooFactory::makeFoo(); f->doFooStuff(); delete f; ➤ Why might this be a problem? What are alternatives? ● Instead of using a Foo pointer, use a proxy, a class that stands in for a Foo pointer ➤ looks like a Foo pointer, acts like a Foo pointer, but cleans up after itself (SmartStrings in sortall/cps 100): heap vs. stack allocation FooProxy f(FooFactory::makeFoo()); f->doFooStuff(); 9. 3 Duke CPS 108

  4. Program parameters and errors ● What are alternatives to large if/else chains to process argc and argv? ➤ What are argc/argv used for? ➤ What helper functions cope with arg parsing? ➤ What’s wrong with if (argv[k] == “-f”) ➤ Other options to getting info into program ● How do you signal an error condition? ➤ Files don’t open, times (wag) out of order, … ➤ cerr << ➤ other alternatives? 9. 4 Duke CPS 108

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