Archive for November, 2007

Chapter 27 . Programming Environments and Interfaces 715 (Web site design and hosting)

Monday, November 19th, 2007

Chapter 27 . Programming Environments and Interfaces 715 routines that simplify certain parts of programming, and a variety of predefined data types and data structures. Listing 27-4 shows the same program as Listing 27-3, with appropriate updates to reflect use of S-Lang instead of ncurses. Listing 27-4: Reading Input and Writing Output with S-Lang /* * sreadkey.c - simple S-Lang-based UI */ #include #include #include int main(int argc, char *argv[]) { int i = 0; unsigned int ch; /* start s-lang */ SLtt_get_terminfo(); SLang_init_tty(-1, 0, 1); SLsmg_init_smg(); /* draw a purty border */ SLsmg_draw_box(0, 0, 24, 80); SLsmg_gotorc(1, 1); SLsmg_write_nchars( INPUT: , 7); SLsmg_refresh(); /* read characters until newline read */ while(1) { ++i; ch = SLang_getkey(); if (ch == 13) break; if (SLsmg_get_column() == 79) SLsmg_gotorc(2, 1); SLsmg_write_char(ch); SLsmg_refresh(); } /* print the character count */ SLsmg_gotorc(22, 1); SLsmg_write_nchars( characters read: , 17); SLsmg_printf( %d , i); SLsmg_refresh(); /* time to look at the screen */ sleep(3); Continued
You want to have a cheap webhost for your apache application, then check apache web hosting services.

714 Part VI . Programming in Linux Figure (Web hosting plans)

Sunday, November 18th, 2007

714 Part VI . Programming in Linux Figure 27-5: An ncurses-based TUI. Ncurses-based programs can also read input piped from stdin. Figure 27-6 shows the results of the command cat /etc/passwd | ./nreadkey. Figure 27-6: Displaying input piped to an ncursesbased program. As you saw with the command pipeline used with the readkey.c program (shown in Listing 27-2, the input is truncated at the end of the first line because each line in /etc/passwd ends with the newline character, and readkey.c uses the newline character to signal the end of input. For more information about ncurses, including download information, visit the ncurses Web page at http://dickey.his.com/ncurses/ncurses.html. Creating TUIs with S-Lang S-Lang, created by John Davis, is an alternative to ncurses for creating TUIs. In addition to providing screen manipulation and cursor control routines, S-Lang also consists of an embeddable S-Lang interpreter, a large library of built-in (intrinsic) Note
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Chapter 27 . (Christian web host) Programming Environments and Interfaces 713

Saturday, November 17th, 2007

Chapter 27 . Programming Environments and Interfaces 713 /* start ncurses */ initscr(); /* draw a purty border */ box(stdscr, ACS_VLINE, ACS_HLINE); mvwaddstr(stdscr, 1, 1, INPUT: ); refresh(); /* read characters until newline read */ noecho(); while ((c = getch()) != n ) { ++i; getyx(stdscr, y, x); /* at the right margin */ if (x == 79) { mvaddch(y + 1, 1, c); } else { waddch(stdscr, c); } waddch(stdscr, c); refresh(); } echo(); refresh(); /* print the character count */ getmaxyx(stdscr, maxy, maxx); mvwprintw(stdscr, maxy - 2, 1, characters read: %dn , i + 1); curs_set(0); refresh(); /* time to look at the screen */ sleep(3); /* shutdown ncurses */ endwin(); return 0; } One of the first things you notice is that nreadkey.c is about twice as long as readkey.c. The additional code is due entirely to the need to make sure the screen is set up, the cursor positioned appropriately, and so forth. To see if the additional code is worth it, compile nreadkey.c using the following command: $ gcc nreadkey.c -lncurses -o nreadkey To run the program, type ./nreadkey. Figure 27-5 shows the result after typing the same text as typed for readkey.c earlier.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web server hosting - 712 Part VI . Programming in Linux Creating

Friday, November 16th, 2007

712 Part VI . Programming in Linux Creating TUIs with Ncurses Screen manipulation libraries such as S-Lang and ncurses create more attractive programs, but, as you might expect, the trade-off for a nicer looking interface is more complicated code. Ncurses, which stands for new curses, is free re-implementation of the classic curses UNIX screen-handling library. The term curses derives from the phrase cursor optimization, which succinctly describes what the curses library does: computes the fastest way to redraw a text-mode screen and places the cursor in the proper location. Ncurses provides a simple, high-level interface for screen control and manipulation. It also contains powerful routines for handling keyboard and mouse input, creating and managing multiple windows, and using menus, forms, and panels. Ncurses works by generalizing the interface between an application program and the screen or terminal on which it is running. Given the literally hundreds of varieties of terminals, screens, and terminal emulation programs available, and the different features they possess (not to mention the different commands to use these features and capabilities), UNIX programmers quickly developed a way to abstract screen manipulation. Rather than write a lot of extra code to take into account the different terminal types, ncurses provides a uniform and generalized interface for the programmer. The ncurses API insulates the programmer from the underlying hardware. Ncurses gives to character-based applications many of the same features found in graphical X Window applications multiple windows, forms, menus, and panels. ncurses windows can be managed independently, may contain the same or different text, scroll or not scroll, be visible or hidden. Forms enable the programmer to create easy-to-use data entry and display windows, simplifying what is usually a difficult and application-specific coding task. Panels extend ncurses capability to deal with overlapping and stacked windows. Menus provide, well, menus, again with a simpler, generalized programming interface. To give you an idea of how ncurses works and what is involved in writing code to use it, Listing 27-3 shows the readkey.c program introduced in Listing 27-2 adapted to work with ncurses (now named nreadkey.c). Listing 27-3: Reading Input and Writing Output with Ncurses /* * readkey.c - reads characters from stdin */ #include #include int main(int argc, char *argv[]) { int c, i = 0; int maxx, maxy; int y, x;
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Chapter 27 . (Yahoo free web hosting) Programming Environments and Interfaces 711

Thursday, November 15th, 2007

Chapter 27 . Programming Environments and Interfaces 711 Listing 27-2: Reading and Writing to stdin and stdout /* * readkey.c - reads characters from stdin */ #include int main(int argc, char *argv[]) { int c, i = 0; /* read characters until newline read */ printf( INPUT: ); while ((c = getchar()) != n ) { ++i; putchar(c); } printf( ncharacters read: %dn , i + 1); return 0; } To compile this program, use the following command: $ gcc readkey.c -o readkey readkey.c reads input from stdin until it encounters a newline (such as pressing the Enter key). Then it displays the text entered and the number of characters read (the count includes the newline) and exits. Here s how it works: $ ./readkey INPUT: There are three primary means of creating programs that interact with users at the command line There are three primary means of creating programs that interact with users at the command line characters read: 96 The text wraps oddly because of this book s formatting constraints. You can also feed readkey.c input from stdin using the cat command: $ cat /etc/passwd | ./readkey INPUT: root:x:0:0::/root:/bin/bash characters read: 28 In this case, you only see the first line of /etc/passwd because each line of the file ends with a newline. It should be clear that programmatically interacting with the command line is simple, but not terribly user-friendly or attractive.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

710 Part VI . Programming in Linux feel (Web hosting domain)

Wednesday, November 14th, 2007

710 Part VI . Programming in Linux feel more comfortable with and work more productively using the tools I have been using since 1993: vi or emacs for writing and editing code, gcc and make for compilation, and gdb and kgdb for debugging. In any event, the lines are not so sharply drawn. Emacs, for example, has the facility to invoke both compilation and debugging facilities, has an extremely rich code editing interface (syntax highlighting and automatic indentation, for example), and also supports other code development features such as source code control, symbol and class browsing, and built-in support for at least three different online help facilities. If you prefer vi, it also can be configured to support symbol and class browsing using the ctags program, has basic syntax highlighting (depending on the implementation), and can also work with the error messages produced by failed compilation. Perhaps the GUI versus CLI debate boils down to this distinction: CLI-oriented programming environments give developers direct access to the tools and utilities they need, don t consume system resources to draw an attractive GUI, and don t provide so-called point-and-click programming. GUI-oriented programming environments hide the tools and utilities underneath a consistent, unified interface; provide a convenient dashboard or instrument panel for access to the necessary programming tools; and let developers take advantage of some of the conveniences associated with graphical environments. Linux Programming Interfaces As defined at the beginning of this chapter, a programming interface refers to the rules or methods followed to accomplish a particular task. Programming interfaces are usually thought of as graphical or command-line. Graphical interfaces use the X Window System to receive and process user input and display information. Command-line interfaces, sometimes referred to as text-mode user interfaces (TUIs), are strictly text-based and do not require a windowing system to run but, thanks to the X Window System, you can also execute CLI-based programs in terminal emulators running on top of X. There is a third type of interface, however: an application programming interface or API. This section of the chapter looks at the ncurses library used to create text-mode user interfaces, examines some of the popular graphical interfaces in use today, and describes a small set of the most popular APIs used by Linux programmers. Creating Command-Line Interfaces There are three primary means of creating programs that interact with users at the command line. Two use libraries of screen manipulation routines, S-Lang and ncurses, to create TUIs, and the third just uses standard input and standard output, conventionally known as stdin and stdout, respectively. Using stdin and stdout is trivially simple. Input and output occur one line at a time; users type input using the keyboard or pipe input in from a file, and output is displayed to the screen or redirected to a file. Listing 27-2, readkey.c, shows such a program.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Chapter 27 . Programming Environments and Interfaces 709 (Windows 2003 server web)

Tuesday, November 13th, 2007

Chapter 27 . Programming Environments and Interfaces 709 There are many more IDEs than the three discussed in this section. Some are less mature or still in beta stage. Others are special-purpose IDEs, such as the Quanta HTML editor, the GLADE interface designer for GNOME. If Eclipse, KDevelop, and Code Crusader don t appeal to you, a quick search at Freshmeat (use URL http: //freshmeat/net/browse/65/ to get right to the IDE category) or SourceForge (http://sourceforge.net/softwaremap/trove_list.php?form_cat=65 takes you straight to the IDE category) should turn up many options from which to choose. When this paragraph was written in September 2004, the Freshmeat IDE category had 151 entries and the SourceForge IDE category had 453 entries; there s something available for everyone. This is Linux, after all, so you are free to choose the IDE that appeals to you the most. As you ll learn in the next subsection, though, not everyone wants (or needs) a GUI IDE. The Command-Line Programming Environment The Linux command-line programming environment or CLI (command-line interface) stands in sharp contrast to the GUI IDEs described in the previous section. It often shocks developers who have only a Windows development background and who aren t accustomed to using a CLI. To be fair, it must be intimidating to find yourself in front of a command prompt without anything to double-click to start and not the faintest clue how to proceed. That said, while a CLI might seem Spartan to the newcomer, programming at the command line is surprisingly powerful and allows you to mix and match best-ofbreed tools in a way that most IDEs cannot begin to approach. The CLI programming environment can match the environment provided by GUIs feature for feature, with the single exception of the graphical interface itself. The inconvenience, if inconvenience it is, arises from the fact that the CLI programming environment relies on separate tools. For example, assuming you are working in the X Window System, you might be running one or more text editors, such as vi, pico, nano, joe, or emacs, each in its own xterms You might use another xterm for compiling your program, either by invoking the compiler gcc (the GNU compiler collection) directly, or by using the make utility. In still another window you might be running a debugger such as gdb (the GNU debugger). If you are unfamiliar with the library you are using, you might have a Web browser open to view some sort of online documentation, or you might be using a program such as xman, that displays Linux manual (man) pages in a graphical format. It is not a given, however, that graphical IDEs are better than using discrete tools. Rather, it is a matter of with what model developers feel most comfortable, what method makes developers the most productive, and what approach best fits each developer s personal working style. Even though I work for a company that develops and sells an Eclipse-based set of development tools for embedded Linux, I personally
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Web design company - 708 Part VI . Programming in Linux Code

Monday, November 12th, 2007

708 Part VI . Programming in Linux Code Crusader Code Crusader is a commercially available and supported IDE written in C++ and specifically targeted at the Linux developer; it is not available for Windows. You can use Code Crusader to write Java, FORTAN, C++, and, of course, C programs. Unlike the IDEs discussed so far, Code Crusader does not include a built-in debugger. Rather, New Planet Software, developers of Code Crusader, makes its debugger application, Code Medic, available separately (although you can buy the two together as an IDE bundle). Figure 27-4 shows Code Crusader with the forkexec.c program from Listing 27-1 open in an editor window. Figure 27-4: The Code Crusader IDE. As you can see in Figure 27-4, Code Crusader has a much simpler, cleaner interface than the other IDEs mentioned so far. Another significant difference between Code Crusader and the larger IDEs like Eclipse and KDevelop is that each IDE component, such as the project browser, the class browser, editor windows, and the log viewer, open in their own, independent windows rather than being part of a single-document interface (SDI). Having multiple windows is more consistent with traditional Linux and UNIX windowing conventions, but developers coming from a Windows background might find Code Crusader s multiple-document interface (MDI) a little jarring at first. On the other hand, programmers who prefer a leaner, cleaner interface might prefer Code Crusader to the rather overstuffed-looking interfaces that Eclipse and KDevelop offer. For more information about Code Crusader, including download information, visit the Code Crusader home page at www.newplanetsoftware.com/jcc/. Note
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Chapter 27 . Programming Environments and Interfaces 707 (Top ten web hosting)

Sunday, November 11th, 2007

Chapter 27 . Programming Environments and Interfaces 707 KDevelop: KDE s IDE KDevelop, another open source IDE licensed under the GPL, was originally created to provide an IDE that interoperated seamlessly with KDE and the Qt framework (a large C++ application framework) on which KDE is based. Over the years, however, KDevelop has evolved into an attractive, feature-rich development environment supporting a number of languages other than C++. Today, KDevelop is a general-purpose IDE, although it works best when used to create Qt-based applications written in C++. Figure 27-3 shows a representative screenshot of Kdevelop. Figure 27-3: The KDevelop IDE. If you compare KDevelop s appearance to Eclipse s appearance, you will see that both have the same type of components. In Figure 27-3, the class browser is located on the left side of the screen, the project window is located in the upper-right portion of the screen, and KDevelop s version of the Declaration view is displayed in the lower-right portion of the screen. The log view that occupies the bottom of the KDevelop interface in Figure 27-3 shows the compilation process. As with Eclipse, KDevelop s toolbars and menus are stuffed with buttons and menu items that cater to the needs of developers, just as a word processor is customized with buttons and menu items specific to the task of writing and formatting documents. For more information about KDevelop, including download information, visit the KDevelop home page at http://kdevelop.kde.org/. The language status support page (www.kdevelop.org/HEAD/doc/api/html/LangSupportStatus. html) shows the current list of supported programming languages. Note
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

706 Part VI . (Free web host) Programming in Linux Figure

Saturday, November 10th, 2007

706 Part VI . Programming in Linux Figure 27-1 illustrates a number of characteristics typical of IDEs. The project view on the left side of the screen provides a project file browser that enables you to see at a glance the contents of the programming project. You can see the primary project folder, HelloWorld, and some of the associated files necessary to support Java projects, such as the default package for Java projects and a folder containing the necessary JRE (Java Runtime Environment) files. The code editor view in the center of the screen shows the code for the HelloWorld.java program. Although it isn t visible in the black-and-white figure produced for this book, the code editor performs on-the-fly syntax highlight using color and font-style changes. Java keywords are purple; plain comments appear in green; javadoc-style comments appear in a pale blue; strings are colored blue; and normal code is black. The right side of Eclipse displays another feature common among IDEs, a class browser. Class browsers enable developers to see the structure of their programs from the point of view of the code modules that make up the program rather than as mere files in a directory. This feature is not terribly useful for a small program such as HelloWorld.java, but larger programs that consist of dozens of classes or code modules are much easier to navigate using a code or class browser. The bottom of the screen shows various information and status windows. For example, the Problems view shows problems that might have occurred while compiling the program. Eclipse, like many other IDEs, enables you to double-click on an error in the Problems view to jump right to the error in the associated code file (see Figure 27-2). Figure 27-2: Eclipse s Problems view. The Javadoc view, which is unique to the Eclipse Java development plug-in, enables you to view the output of Javadoc, a tool that creates documentation from specially formatted Java source code comments. The Declaration view works in combination with the class browser to show you the complete declaration of methods and data types. The Console view shows the actual output of the Java program. For more information about Eclipse, including download information, visit the Eclipse home page at www.eclipse.org/. Note
In case you need quality webspace to host and run your web applications, try our personal web hosting services.