Archive for December, 2007

776 Part VI . Programming (Adelphia web hosting) in Linux To

Wednesday, December 12th, 2007

776 Part VI . Programming in Linux To compile this program using the following command: $ gcc sreadkey.c -lslang -o sreadkey To run the program, type ./sreadkey. Figure 28-7 shows the result after typing the same text as typed for readkey.c earlier. Figure 28-7: An S-Lang based TUI. As you can see from Figure 28-7, the basic appearance and functionality of sreadkey.c is the same as nreadkey.c. The differences between the two, which have to do with the TUI framework used to create sreadkey.c, are invisible to the user. S-Lang-based programs can also read input piped from stdin. From a developer s perspective, there are significant differences between ncurses and S-Lang in program structure and the actual library usage, but the output is almost identical. For more information about S-Lang, including download information, visit the S-Lang Web page at www.s-lang.org. Creating Graphical Interfaces When it comes to creating GUIs, Linux programmers have more options available than they do for creating TUIs. Probably the most popular and certainly the best known toolkits used to create graphical applications are Qt and GTK+. Qt is the C++ application framework that powers KDE, the K Desktop Environment. GTK+ is the toolkit underneath GNOME, the GNU Network Object Model Environment. GTK+ is written largely in C, but it has language bindings available for many other Note
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Web site development - Chapter 28 . Programming Environments and Interfaces 775

Tuesday, December 11th, 2007

Chapter 28 . Programming Environments and Interfaces 775 Listing 28-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); /* shutdown s-lang */ SLsmg_reset_smg(); SLang_reset_tty(); return 0; }
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

774 Part VI . (Anonymous web server) Programming in Linux Figure

Monday, December 10th, 2007

774 Part VI . Programming in Linux Figure 28-5: An ncursesbased TUI. Figure 28-6: Displaying input piped to an ncurses-based program. As you saw with the command pipeline used with the readkey.c program (shown in Listing 28-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 Text-Mode User Interfaces 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) routines that simplify certain parts of programming, and a variety of predefined data types and data structures. Listing 28-4 shows the same program as Listing 28-3, with appropriate updates to reflect use of S-Lang instead of ncurses. Note
We recommend high quality webhost to host and run your jsp application: christian web host services.

Chapter 28 . Programming Environments and Interfaces 773 (Affordable web design)

Sunday, December 9th, 2007

Chapter 28 . Programming Environments and Interfaces 773 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 addresses the need to set up the screen, position the cursor, 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 28-5 shows the result after typing the same text as typed for readkey.c earlier. Ncurses-based programs can also read input piped from stdin. Figure 28-6 shows the results of the command cat /etc/passwd | ./nreadkey.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

772 Part VI . Programming in Linux Ncurses (Web hosting reviews)

Saturday, December 8th, 2007

772 Part VI . Programming in Linux 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 28-3 shows the readkey.c program (now named nreadkey.c) introduced in Listing 28-2, adapted here to work with ncurses. Listing 28-3: Reading Input and Writing Output with ncurses /* * nreadkey.c - reads characters from stdin */ #include #include int main(int argc, char *argv[]) { int c, i = 0; int maxx, maxy; int y, x; /* start ncurses */ initscr(); /* draw a purty border */ box(stdscr, ACS_VLINE, ACS_HLINE);
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Fedora web server - Chapter 28 . Programming Environments and Interfaces 771

Friday, December 7th, 2007

Chapter 28 . Programming Environments and Interfaces 771 putchar(c); } printf( ncharacters read: %dn , i + 1); return 0; } To compile this program, use the following command: $ gcc readkey.c -o readkey In the preceding code listing, readkey.c reads input from stdin until it encounters a newline (which is generated when you press 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 see only 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. Creating Text-Mode User Interfaces with ncurses Screen manipulation libraries such as S-Lang and ncurses create more attractive programs, but, as you might expect, the tradeoff 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: compute the fastest way to redraw a text-mode screen and place the cursor in the proper location.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Dedicated web hosting - 770 Part VI . Programming in Linux Linux

Wednesday, December 5th, 2007

770 Part VI . Programming in Linux 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. Like programming environments, programming interfaces are usually thought of as either 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 textmode user interfaces (TUIs), are strictly text-based and do not require a windowing system to run. Thanks to the X Window System, however, you can also execute CLIbased programs in terminal emulators running on top of X. There also is a third type of interface: 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 28-2 shows such a program, readkey.c. Listing 28-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;
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Chapter 28 . Programming Environments and Interfaces 769 (Free web hosting services)

Wednesday, December 5th, 2007

Chapter 28 . Programming Environments and Interfaces 769 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 xterm. 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 which model developers feel most comfortable using, which method makes developers the most productive, and which approach best fits each developer s personal working style. Many long-time UNIX and Linux developers feel more comfortable with and work more productively using command-line tools: 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 codeediting interface (syntax highlighting and automatic indentation, for example), and also supports other code development features. Emacs also includes 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 can be also 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 dash board or instrument panel for access to the necessary programming tools; and let developers take advantage of some of the conveniences associated with graphical environments.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

768 Part VI . Programming in Linux Figure (Email web hosting)

Tuesday, December 4th, 2007

768 Part VI . Programming in Linux Figure 28-4: The Code Crusader IDE. For more information about Code Crusader, including download information, visit the Code Crusader home page at www.newplanetsoftware.com/jcc/. 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, or 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. As of this writing, the Freshmeat IDE category has 163 entries and the SourceForge IDE category has 540 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, however, 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. Note
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Chapter 28 . Programming Environments and Interfaces 767 (Web hosting plans)

Monday, December 3rd, 2007

Chapter 28 . Programming Environments and Interfaces 767 Figure 28-3: The KDevelop IDE. 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, developer of Code Crusader, makes its debugger application, Code Medic, available separately (although you can buy the two together as an IDE bundle). Figure 28-4 shows Code Crusader with the forkexec.c program from Listing 28-1 open in an editor window. As you can see in Figure 28-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 such as 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 singledocument 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 over-stuffed looking interfaces that Eclipse and KDevelop offer.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.