home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-01 | 7.7 MB | 214,554 lines |
Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
- %@1@%%@AH@%Microsoft C Optimizing Compiler - v6.0%@EH@%%@AE@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHRTDEMO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\CHRTDEMO.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<pgchart.h> %@NL@%
- %@AI@%#include %@AE@%"chrtdemo.h" %@NL@%
- %@NL@%
- %@AB@%/* Structures for system configuration and chart environment. */%@AE@%%@NL@%
- struct videoconfig vc;%@NL@%
- chartenv ce;%@NL@%
- %@NL@%
- %@AB@%/* Category variables. */%@AE@%%@NL@%
- short cCat;%@NL@%
- char _far *aCat[MAXVALUES];%@NL@%
- %@NL@%
- %@AB@%/* Series variables. */%@AE@%%@NL@%
- short cSeries;%@NL@%
- short _far acSeries[MAXSERIES];%@NL@%
- char _far *aSeriesName[MAXSERIES];%@NL@%
- %@NL@%
- %@AB@%/* Temporary holding array for all data. Data values for multi-series%@NL@%
- %@AB@% * bar, column, and line charts remain here. Data for other kinds of%@NL@%
- %@AB@% * charts are transferred to the arrays below.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- float _far aValue[MAXSERIES][MAXVALUES];%@NL@%
- %@NL@%
- %@AB@%/* Data values for single-series charts. First array is used for%@NL@%
- %@AB@% * bar, column, line, and pie. First and second are both used for%@NL@%
- %@AB@% * single-series scatter.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- float _far axValue[MAXVALUES];%@NL@%
- float _far ayValue[MAXVALUES];%@NL@%
- %@NL@%
- %@AB@%/* Data values for multi-series scatter charts. */%@AE@%%@NL@%
- float _far axValueMS[MAXVALUES][MAXVALUES];%@NL@%
- float _far ayValueMS[MAXVALUES][MAXVALUES];%@NL@%
- %@NL@%
- %@AB@%/* Exploded flags for pie chart. */%@AE@%%@NL@%
- short _far aExplode[MAXVALUES];%@NL@%
- %@NL@%
- %@AB@%/* Variable used to track control and screen position. */%@AE@%%@NL@%
- struct SCREENINFO si;%@NL@%
- %@NL@%
- %@AB@%/* Colors of menus and prompts. */%@AE@%%@NL@%
- struct tagColor co;%@NL@%
- %@NL@%
- %@AB@%/* Flags to indicate whether to use imported or default data. */%@AE@%%@NL@%
- BOOL fDefault = TRUE;%@NL@%
- %@NL@%
- %@AB@%/* Arrays of strings used by the Menu function. The first string is the%@NL@%
- %@AB@% * menu title. The next non-null strings are the menu selections. A null%@NL@%
- %@AB@% * string indicates the end of the list.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *pszChartOpt[] =%@NL@%
- { "Options", "Screen Mode", "Windows", "Titles",%@NL@%
- "Axis (X and Y)", "Legend", "Fonts", "Reset", "" };%@NL@%
- %@NL@%
- char *pszChartType[] =%@NL@%
- { "Type", "Bar", "Column", "Line", "Scatter", "Pie", "" };%@NL@%
- %@NL@%
- char *pszMainMenu[] =%@NL@%
- { "Main Menu", "Demo", "View Chart", "Chart Type", "Options",%@NL@%
- "Show Chart Data", "Quit", "" };%@NL@%
- %@NL@%
- %@AB@%/* Sample data. */%@AE@%%@NL@%
- %@AI@%#define %@AE@%O_JUICE 0 %@NL@%
- %@AI@%#define %@AE@%I_TEA 1 %@NL@%
- %@AI@%#define %@AE@%H_CHOC 2 %@NL@%
- %@AI@%#define %@AE@%TEMPERATURE 3 %@NL@%
- %@NL@%
- char _far *aQuarters[] =%@NL@%
- { "First", "Second", "Third", "Fourth" };%@NL@%
- %@NL@%
- char _far *aMonths[] =%@NL@%
- { "Jan", "Feb", "Mar", "Apr", "May", "Jun",%@NL@%
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };%@NL@%
- %@NL@%
- float _far aSales[3][12] =%@NL@%
- {%@NL@%
- { 3.6F, 3.2F, 3.3F, 3.4F, 3.1F, 2.9F,%@NL@%
- 3.0F, 3.6F, 3.2F, 3.3F, 3.5F, 3.9F },%@NL@%
- { 1.0F, 1.3F, 1.4F, 1.7F, 2.2F, 2.9F,%@NL@%
- 2.9F, 3.1F, 2.6F, 1.8F, 1.1F, 1.2F },%@NL@%
- { 2.4F, 2.3F, 2.0F, 1.6F, 1.3F, 1.0F,%@NL@%
- 0.9F, 0.8F, 1.1F, 1.4F, 1.9F, 2.5F }%@NL@%
- };%@NL@%
- %@NL@%
- float _far aTemperature[12] =%@NL@%
- { 2.9F, 3.2F, 3.9F, 4.8F, 6.0F, 6.5F,%@NL@%
- 7.0F, 7.2F, 6.0F, 4.7F, 4.1F, 3.0F };%@NL@%
- %@NL@%
- char _far *aSalesTitles[] =%@NL@%
- { "Orange Juice Sales", "Iced Tea Sales", "Hot Chocolate Sales" };%@NL@%
- %@NL@%
- char *TempTitle = "Average Temperature";%@NL@%
- %@NL@%
- int main()%@NL@%
- {%@NL@%
- Initialize();%@NL@%
- MainMenu();%@NL@%
- %@NL@%
- %@AB@%/* Reset the video mode and screen colors prior to leaving. */%@AE@%%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _settextcolor( co.InfoColor );%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ChartOptions - Gets chart options.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ChartOptions()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszChartOpt[0] );%@NL@%
- while( (iChoice = Menu( pszChartOpt )) != ESCAPE )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Get chart options. */%@AE@%%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Branch to the appropriate menu. */%@AE@%%@NL@%
- case 1:%@NL@%
- ScreenMode();%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- Windows();%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- Titles();%@NL@%
- break;%@NL@%
- %@NL@%
- case 4:%@NL@%
- Axes();%@NL@%
- break;%@NL@%
- %@NL@%
- case 5:%@NL@%
- Legend();%@NL@%
- break;%@NL@%
- %@NL@%
- case 6:%@NL@%
- FontOptions();%@NL@%
- break;%@NL@%
- %@NL@%
- case 7:%@NL@%
- ResetOptions();%@NL@%
- break;%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ChartType - Gets chart type.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ChartType()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Get chart type. */%@AE@%%@NL@%
- PushTitle( pszChartType[0] );%@NL@%
- iChoice = Menu( pszChartType );%@NL@%
- %@NL@%
- if( iChoice != ESCAPE )%@NL@%
- {%@NL@%
- %@AB@%/* Set the chart type, and get the chart style. */%@AE@%%@NL@%
- ce.charttype = iChoice;%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- case 2:%@NL@%
- iChoice = BlankMenu( "Style", "Plain Bars", "Stacked Bars" );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- case 4:%@NL@%
- iChoice = BlankMenu( "Style", "Lines-Points", "Points Only" );%@NL@%
- break;%@NL@%
- %@NL@%
- case 5:%@NL@%
- iChoice = BlankMenu( "Style", "Percent", "No Percent" );%@NL@%
- }%@NL@%
- %@NL@%
- if( iChoice != ESCAPE)%@NL@%
- ce.chartstyle = iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Set default data without changing environment defaults. */%@AE@%%@NL@%
- DefaultData( ce.charttype, ce.chartstyle, FALSE );%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ClearData - Clears category and value data.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: fConfirm - flag specifying whether to query for confirmation%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ClearData( BOOL fConfirm )%@NL@%
- {%@NL@%
- char chResponse = 'Y';%@NL@%
- int iCat;%@NL@%
- %@NL@%
- WrtForm( 18 );%@NL@%
- %@NL@%
- %@AB@%/* Query for confirmation. */%@AE@%%@NL@%
- if( fConfirm )%@NL@%
- chResponse = InputCh( "Are you sure? ", "YN\x1b" );%@NL@%
- %@NL@%
- if( chResponse == 'Y' )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Clear all relevant data. */%@AE@%%@NL@%
- for( iCat = 0; iCat < cCat; iCat++ )%@NL@%
- aCat[iCat] = NULL;%@NL@%
- cCat = 0;%@NL@%
- cSeries = 0;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* DefaultData - Initializes default data for each kind of chart.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iType - Chart type to be initialized%@NL@%
- %@AB@% * iStyle - Chart style%@NL@%
- %@AB@% * fClear - Signal to clear all defaults%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void DefaultData( short iType, short iStyle, BOOL fClear )%@NL@%
- {%@NL@%
- int iCat, iValue, iSubValue, iSeries;%@NL@%
- %@NL@%
- %@AB@%/* Call default chart to clear old values. */%@AE@%%@NL@%
- if( fClear )%@NL@%
- _pg_defaultchart( &ce, iType, iStyle );%@NL@%
- %@NL@%
- %@AB@%/* Initialize category titles. */%@AE@%%@NL@%
- cCat = 12;%@NL@%
- for( iCat = 0; iCat < cCat; iCat++ )%@NL@%
- aCat[iCat] = aMonths[iCat];%@NL@%
- %@NL@%
- switch( ce.charttype )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Initialize data for each chart type. */%@AE@%%@NL@%
- case _PG_BARCHART:%@NL@%
- %@NL@%
- strcpy( ce.maintitle.title, "Orange Juice and Iced Tea Sales" );%@NL@%
- cSeries = 2;%@NL@%
- for( iSeries = 0; iSeries < cSeries; iSeries++ )%@NL@%
- {%@NL@%
- aSeriesName[iSeries] = aSalesTitles[iSeries];%@NL@%
- acSeries[iSeries] = cCat;%@NL@%
- for( iValue = 0; iValue < cCat; iValue++ )%@NL@%
- aValue[iSeries][iValue] = (float)aSales[iSeries][iValue];%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case _PG_COLUMNCHART:%@NL@%
- %@NL@%
- strcpy( ce.maintitle.title, "Orange Juice Sales" );%@NL@%
- cSeries = 1;%@NL@%
- for( iSeries = 0; iSeries < cSeries; iSeries++ )%@NL@%
- {%@NL@%
- aSeriesName[iSeries] = aSalesTitles[iSeries];%@NL@%
- acSeries[iSeries] = cCat;%@NL@%
- for( iValue = 0; iValue < cCat; iValue++ )%@NL@%
- aValue[iSeries][iValue] = (float)aSales[iSeries][iValue];%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case _PG_LINECHART:%@NL@%
- %@NL@%
- strcpy( ce.maintitle.title, "Beverage Sales" );%@NL@%
- cSeries = 3;%@NL@%
- for( iSeries = 0; iSeries < cSeries; iSeries++ )%@NL@%
- {%@NL@%
- aSeriesName[iSeries] = aSalesTitles[iSeries];%@NL@%
- acSeries[iSeries] = cCat;%@NL@%
- for( iValue = 0; iValue < cCat; iValue++ )%@NL@%
- aValue[iSeries][iValue] = (float)aSales[iSeries][iValue];%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case _PG_SCATTERCHART:%@NL@%
- %@NL@%
- strcpy( ce.maintitle.title,%@NL@%
- "Average Temperature Compared to Beverage Sales" );%@NL@%
- %@AB@%/* ce.chartstyle = _PG_POINTONLY; */%@AE@%%@NL@%
- cSeries = 4;%@NL@%
- %@NL@%
- aSeriesName[0] = aSalesTitles[I_TEA];%@NL@%
- aSeriesName[2] = aSalesTitles[H_CHOC];%@NL@%
- acSeries[0] = acSeries[1] = acSeries[2] = acSeries[3] = 12;%@NL@%
- for( iValue = 0; iValue < 12; iValue++ )%@NL@%
- {%@NL@%
- aValue[0][iValue] = (float)aSales[I_TEA][iValue] ;%@NL@%
- aValue[1][iValue] = (float)aSales[TEMPERATURE][iValue] ;%@NL@%
- aValue[2][iValue] = (float)aSales[H_CHOC][iValue] ;%@NL@%
- aValue[3][iValue] = (float)aSales[TEMPERATURE][iValue] ;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- case _PG_PIECHART:%@NL@%
- default:%@NL@%
- %@NL@%
- strcpy( ce.maintitle.title, "Iced Tea Sales" );%@NL@%
- cCat = 4;%@NL@%
- for( iCat = 0; iCat < cCat; iCat++ )%@NL@%
- aCat[iCat] = aQuarters[iCat];%@NL@%
- %@NL@%
- cSeries = 1;%@NL@%
- aSeriesName[0] = aSalesTitles[I_TEA];%@NL@%
- acSeries[0] = cCat;%@NL@%
- %@NL@%
- for( iValue = 0; iValue < cCat; iValue++ )%@NL@%
- {%@NL@%
- aValue[0][iValue] = 0.0;%@NL@%
- for( iSubValue = 0; iSubValue < 3; iSubValue++ )%@NL@%
- aValue[0][iValue] += (float)aSales[I_TEA][iSubValue * iValue];%@NL@%
- }%@NL@%
- aExplode[3] = 1;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Demo - Displays a series of sample charts.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Demo()%@NL@%
- {%@NL@%
- int cValue;%@NL@%
- palettetype palette_struct;%@NL@%
- %@NL@%
- %@AB@%/* Display the sample data in spreadsheet form. */%@AE@%%@NL@%
- ShowSampleData();%@NL@%
- %@NL@%
- DefaultData( _PG_PIECHART, _PG_NOPERCENT, TRUE );%@NL@%
- %@NL@%
- %@AB@%/* Set video mode and draw charts. For each chart, set default%@NL@%
- %@AB@% * data and modify any desired environment fields. If error,%@NL@%
- %@AB@% * terminate demo.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _setvideomode( si.mode );%@NL@%
- %@NL@%
- cValue = 4;%@NL@%
- strcpy( ce.subtitle.title, "Default Pie Chart" );%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- strcpy( ce.subtitle.title, "Customized Pie Chart" );%@NL@%
- ce.chartstyle = _PG_PERCENT;%@NL@%
- ce.legend.place = _PG_BOTTOM;%@NL@%
- if (si.fColor)%@NL@%
- {%@NL@%
- ce.maintitle.titlecolor = ce.subtitle.titlecolor = 0;%@NL@%
- ce.chartwindow.background = 1;%@NL@%
- ce.datawindow.background = ce.legend.legendwindow.background = 6;%@NL@%
- ce.legend.textcolor = 1;%@NL@%
- }%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- cValue = 12;%@NL@%
- DefaultData( _PG_BARCHART, _PG_PLAINBARS, TRUE );%@NL@%
- strcpy( ce.subtitle.title, "Default Bar Chart" );%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- strcpy( ce.subtitle.title, "Customized Stacked Bar Chart" );%@NL@%
- strcpy( ce.xaxis.axistitle.title, "Sales in Thousands" );%@NL@%
- strcpy( ce.yaxis.axistitle.title, "Month" );%@NL@%
- ce.chartstyle = _PG_STACKEDBARS;%@NL@%
- ce.legend.place = _PG_RIGHT;%@NL@%
- ce.xaxis.ticdecimals = 2;%@NL@%
- if (si.fColor)%@NL@%
- {%@NL@%
- ce.maintitle.titlecolor = ce.subtitle.titlecolor = 12;%@NL@%
- ce.chartwindow.background = 7;%@NL@%
- ce.datawindow.background = 8;%@NL@%
- ce.legend.textcolor = 0;%@NL@%
- ce.legend.legendwindow.background = 8;%@NL@%
- ce.legend.autosize = FALSE;%@NL@%
- ce.legend.legendwindow.y1 = vc.numypixels - 85;%@NL@%
- ce.legend.legendwindow.y2 = vc.numypixels - 45;%@NL@%
- }%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- DefaultData( _PG_COLUMNCHART, _PG_PLAINBARS, TRUE );%@NL@%
- strcpy( ce.subtitle.title, "Default Column Chart" );%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- strcpy( ce.subtitle.title, "Customized Column Chart" );%@NL@%
- strcpy( ce.xaxis.axistitle.title, "Month" );%@NL@%
- strcpy( ce.yaxis.axistitle.title, "Sales in Thousands" );%@NL@%
- ce.legend.place = _PG_BOTTOM;%@NL@%
- if (si.fColor)%@NL@%
- {%@NL@%
- ce.maintitle.titlecolor = 0;%@NL@%
- ce.subtitle.titlecolor = 0;%@NL@%
- ce.chartwindow.background = 8;%@NL@%
- ce.datawindow.background = 2;%@NL@%
- ce.legend.legendwindow.background = 10;%@NL@%
- }%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- DefaultData( _PG_LINECHART, _PG_POINTANDLINE, TRUE );%@NL@%
- strcpy( ce.subtitle.title, "Default Line Chart" );%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- strcpy( ce.subtitle.title, "Customized Line Chart" );%@NL@%
- strcpy( ce.xaxis.axistitle.title, "Month" );%@NL@%
- strcpy( ce.yaxis.axistitle.title, "Sales in Thousands" );%@NL@%
- ce.legend.place = _PG_RIGHT;%@NL@%
- if (si.fColor)%@NL@%
- {%@NL@%
- ce.maintitle.titlecolor = 1;%@NL@%
- ce.subtitle.titlecolor = 1;%@NL@%
- ce.chartwindow.background = 3;%@NL@%
- ce.datawindow.background = 7;%@NL@%
- ce.legend.legendwindow.background = 7;%@NL@%
- ce.legend.autosize = FALSE;%@NL@%
- ce.legend.legendwindow.y1 = vc.numypixels - 85;%@NL@%
- ce.legend.legendwindow.y2 = vc.numypixels - 45;%@NL@%
- }%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- DefaultData( _PG_SCATTERCHART, _PG_POINTONLY, TRUE );%@NL@%
- strcpy( ce.subtitle.title, "Default Scatter Chart" );%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- cSeries = 4;%@NL@%
- strcpy( ce.subtitle.title, "Customized Scatter Chart" );%@NL@%
- strcpy( ce.xaxis.axistitle.title, "Sales in Thousands" );%@NL@%
- strcpy( ce.yaxis.axistitle.title, "Average Temperature" );%@NL@%
- ce.legend.place = _PG_RIGHT;%@NL@%
- if (si.fColor)%@NL@%
- {%@NL@%
- ce.maintitle.titlecolor = 0;%@NL@%
- ce.subtitle.titlecolor = 0;%@NL@%
- ce.chartwindow.background = 4;%@NL@%
- ce.datawindow.background = 8;%@NL@%
- ce.legend.legendwindow.background = 8;%@NL@%
- ce.legend.autosize = FALSE;%@NL@%
- ce.legend.legendwindow.y1 = vc.numypixels - 85;%@NL@%
- ce.legend.legendwindow.y2 = vc.numypixels - 45;%@NL@%
- }%@NL@%
- if( ViewChart() )%@NL@%
- return;%@NL@%
- else%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- DefaultData( _PG_BARCHART, _PG_PERCENT, TRUE );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* FindVideoMode - Finds the "best" video mode for the adaptor in use.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: vc - structure of type struct videoconfig%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Returns: Best mode%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int FindVideoMode( struct videoconfig vc )%@NL@%
- {%@NL@%
- switch( vc.adapter )%@NL@%
- {%@NL@%
- case _CGA:%@NL@%
- case _OCGA:%@NL@%
- return _HRESBW;%@NL@%
- case _EGA:%@NL@%
- case _OEGA:%@NL@%
- return( vc.monitor == _MONO ) ? _ERESNOCOLOR : _ERESCOLOR;%@NL@%
- case _VGA:%@NL@%
- case _OVGA:%@NL@%
- case _MCGA:%@NL@%
- return _VRES16COLOR;%@NL@%
- case _HGC:%@NL@%
- return _HERCMONO;%@NL@%
- default:%@NL@%
- return _DEFAULTMODE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Initialize - Does various initialization tasks.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Initialize( void )%@NL@%
- {%@NL@%
- int iSeries, iValue;%@NL@%
- %@NL@%
- %@AB@%/* Initialize all value arrays to missing. */%@AE@%%@NL@%
- for( iSeries = 0; iSeries < MAXSERIES; iSeries++ )%@NL@%
- {%@NL@%
- %@NL@%
- axValue[iSeries] = _PG_MISSINGVALUE;%@NL@%
- ayValue[iSeries] = _PG_MISSINGVALUE;%@NL@%
- %@NL@%
- for( iValue = 0; iValue < MAXVALUES; iValue++ )%@NL@%
- aValue[iSeries][iValue] = _PG_MISSINGVALUE;%@NL@%
- %@NL@%
- for( iValue = 0; iValue < MAXVALUES; iValue++ )%@NL@%
- {%@NL@%
- axValueMS[iSeries][iValue] = _PG_MISSINGVALUE;%@NL@%
- ayValueMS[iSeries][iValue] = _PG_MISSINGVALUE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Initialize zero sets. */%@AE@%%@NL@%
- cSeries = 0;%@NL@%
- %@NL@%
- %@AB@%/* Initialize default chart environment, screen mode, and data. */%@AE@%%@NL@%
- _pg_initchart();%@NL@%
- _getvideoconfig( &vc );%@NL@%
- %@NL@%
- %@AB@%/* Find the best available mode for display.%@NL@%
- %@AB@% * Don't set 256 color, medium resolution (_MRES256COLOR).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- si.mode = FindVideoMode( vc );%@NL@%
- %@NL@%
- if( si.mode == _TEXTMONO )%@NL@%
- {%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _outtext( "No graphics available. Can't run chart demo." );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- SetDisplayColors();%@NL@%
- %@NL@%
- SetGraphMode( si.mode );%@NL@%
- DefaultData( _PG_BARCHART, _PG_PLAINBARS, TRUE );%@NL@%
- %@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- %@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* MainMenu - Manages the main menu.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void MainMenu( void )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- char chResponse = 'Y';%@NL@%
- char chVerify;%@NL@%
- %@NL@%
- PushTitle( pszMainMenu[0] );%@NL@%
- do%@NL@%
- {%@NL@%
- %@AB@%/* If the user selects Quit, iChoice will contain 6. If the%@NL@%
- %@AB@% * user presses ESCAPE, iChoice will be ESCAPE, which is%@NL@%
- %@AB@% * equal to 27. In any case, we can test both conditions%@NL@%
- %@AB@% * by checking to see whether iChoice is less than 6.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( (iChoice = Menu( pszMainMenu )) < 6 )%@NL@%
- {%@NL@%
- %@AB@%/* Get main menu selection. */%@AE@%%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* Display demo charts. */%@AE@%%@NL@%
- Demo();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Set graphics video mode, display current chart,%@NL@%
- %@AB@% * and restore text video mode.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _setvideomode( si.mode );%@NL@%
- ViewChart();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@AB@%/* Get chart type and style. */%@AE@%%@NL@%
- ChartType();%@NL@%
- break;%@NL@%
- %@NL@%
- case 4:%@NL@%
- %@AB@%/* Get chart options. */%@AE@%%@NL@%
- ChartOptions();%@NL@%
- break;%@NL@%
- case 5:%@NL@%
- %@AB@%/* Show chart data. */%@AE@%%@NL@%
- ShowChartData();%@NL@%
- break;%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* If the user is trying to leave the program using the ESCAPE%@NL@%
- %@AB@% * key, we must verify the choice. This is done to prevent%@NL@%
- %@AB@% * an eager typist from pressing ESCAPE one time too often%@NL@%
- %@AB@% * and exiting at an unanticipated point.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( iChoice == ESCAPE )%@NL@%
- {%@NL@%
- Help( "Press \"Q\" to Actually Quit", co.InputColor );%@NL@%
- %@NL@%
- putchar( BEEP );%@NL@%
- _settextposition( si.help - 1, 32 );%@NL@%
- chVerify = getch();%@NL@%
- if( tolower( chVerify ) != 'q' )%@NL@%
- iChoice = 0;%@NL@%
- else%@NL@%
- iChoice = 6;%@NL@%
- }%@NL@%
- %@NL@%
- } while( iChoice != 6 );%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ResetOptions - After confirmation, resets chart options to default.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ResetOptions()%@NL@%
- {%@NL@%
- char chResponse;%@NL@%
- %@NL@%
- %@AB@%/* Prompt for confirmation before setting default environment. */%@AE@%%@NL@%
- ClrForm();%@NL@%
- Help( "Type 'Y' to reset all options, 'N' to keep them.", co.InputColor );%@NL@%
- chResponse = InputCh( "Are you sure? ", "YN\x1b" );%@NL@%
- if( chResponse == 'Y' )%@NL@%
- _pg_defaultchart( &ce, 1, 1 );%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* SetGraphMode - Tests the specified graphics mode and sets the xMax%@NL@%
- %@AB@% * and yMax values in the si (Screen Information) structure.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: mode number%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: FALSE if mode invalid, TRUE if valid%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL SetGraphMode(int mode)%@NL@%
- {%@NL@%
- if (!_setvideomode( mode ) )%@NL@%
- return FALSE;%@NL@%
- else%@NL@%
- {%@NL@%
- _getvideoconfig ( &vc );%@NL@%
- if( !vc.numxpixels )%@NL@%
- return FALSE;%@NL@%
- si.xMax = vc.numxpixels;%@NL@%
- si.yMax = vc.numypixels;%@NL@%
- si.mode = mode;%@NL@%
- %@NL@%
- %@AB@%/* Set flag to indicate whether multiple colors are available. */%@AE@%%@NL@%
- si.fColor = iscolor( mode );%@NL@%
- %@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowChartData - Displays the data in the chart environment.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ShowChartData()%@NL@%
- {%@NL@%
- int iRow = 2;%@NL@%
- struct _fontinfo fd;%@NL@%
- static char *szContinue =%@NL@%
- "Press any key to continue, ESC to return to the menu.";%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- SprintAt( iRow++, 1, "short charttype = %d", ce.charttype );%@NL@%
- SprintAt( iRow++, 1, "short chartstyle = %d", ce.chartstyle );%@NL@%
- SprintAt( iRow++, 1, "windowtype chartwindow =" );%@NL@%
- iRow = ShowWindowType( iRow, 1, ce.chartwindow );%@NL@%
- SprintAt( iRow++, 1, "windowtype datawindow =" );%@NL@%
- iRow = ShowWindowType( iRow, 1, ce.datawindow );%@NL@%
- SprintAt( ++iRow, 1, szContinue );%@NL@%
- if( getch() == ESCAPE )%@NL@%
- return;%@NL@%
- %@NL@%
- iRow = 2;%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- SprintAt( iRow++, 1, "titletype maintitle =" );%@NL@%
- iRow = ShowTitleType( iRow, 1, ce.maintitle );%@NL@%
- SprintAt( iRow++, 1, "titletype subtitle =" );%@NL@%
- iRow = ShowTitleType( iRow, 1, ce.subtitle );%@NL@%
- SprintAt( ++iRow, 1, szContinue );%@NL@%
- if( getch() == ESCAPE )%@NL@%
- return;%@NL@%
- %@NL@%
- iRow = 2;%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- SprintAt( iRow++, 1, "axistype xaxis =" );%@NL@%
- iRow = ShowAxisType( iRow, 1, ce.xaxis );%@NL@%
- SprintAt( ++iRow, 1, szContinue );%@NL@%
- if( getch() == ESCAPE )%@NL@%
- return;%@NL@%
- %@NL@%
- iRow = 2;%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- SprintAt( iRow++, 1, "axistype yaxis =" );%@NL@%
- iRow = ShowAxisType( iRow, 1, ce.yaxis );%@NL@%
- SprintAt( ++iRow, 1, szContinue );%@NL@%
- if( getch() == ESCAPE )%@NL@%
- return;%@NL@%
- %@NL@%
- iRow = 2;%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- SprintAt( iRow++, 1, "legendtype legend =" );%@NL@%
- iRow = ShowLegendType( iRow, 1, ce.legend );%@NL@%
- SprintAt( ++iRow, 1, szContinue );%@NL@%
- if( getch() == ESCAPE )%@NL@%
- return;%@NL@%
- %@NL@%
- iRow = 2;%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- if( _getfontinfo( &fd ) != -1 )%@NL@%
- {%@NL@%
- SprintAt( iRow++, 1, "struct _fontinfo =" );%@NL@%
- iRow = ShowFontInfo( iRow, 1, fd );%@NL@%
- SprintAt( ++iRow, 1, "Press any key to continue . . ." );%@NL@%
- getch();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowAxisType - Displays data in a variable of type "axistype".%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iRow - Row at which to start%@NL@%
- %@AB@% * iCol - Column from which to indent%@NL@%
- %@AB@% * theAxis - Variable of type "axistype" to display%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Next available row%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ShowAxisType( int iRow, int iCol, axistype theAxis )%@NL@%
- {%@NL@%
- SprintAt( iRow++, iCol + 5, "short .grid = %d", theAxis.grid );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .gridstyle = %d", theAxis.gridstyle );%@NL@%
- SprintAt( iRow++, iCol + 5, "titletype axistitle=" );%@NL@%
- iRow = ShowTitleType( iRow, iCol + 5, theAxis.axistitle );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .axiscolor = %d", theAxis.axiscolor );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .labeled = %s",%@NL@%
- (theAxis.labeled) ? "TRUE" : "FALSE" );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .rangetype = %d", theAxis.rangetype );%@NL@%
- SprintAt( iRow++, iCol + 5, "float .logbase = %f", theAxis.logbase );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .autoscale = %s",%@NL@%
- (theAxis.autoscale) ? "TRUE" : "FALSE" );%@NL@%
- SprintAt( iRow++, iCol + 5, "float .scalemin = %f", theAxis.scalemin );%@NL@%
- SprintAt( iRow++, iCol + 5, "float .scalemax = %f", theAxis.scalemax );%@NL@%
- SprintAt( iRow++, iCol + 5, "float .scalefactor = %f", theAxis.scalefactor );%@NL@%
- iRow = ShowTitleType( iRow, iCol + 5, theAxis.scaletitle );%@NL@%
- SprintAt( iRow++, iCol + 5, "float .ticinterval = %f", theAxis.ticinterval );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .ticformat = %d", theAxis.ticformat );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .ticdecimals = %d", theAxis.ticdecimals );%@NL@%
- %@NL@%
- return iRow;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowFontInfo - Displays data in a variable of type "_fontinfo".%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iRow - Row at which to start%@NL@%
- %@AB@% * iCol - Column from which to indent%@NL@%
- %@AB@% * theFont - Variable of type "_fontinfo" to display%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Next available row%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ShowFontInfo( int iRow, int iCol, struct _fontinfo theFont )%@NL@%
- {%@NL@%
- SprintAt( iRow++, iCol + 5, "int .type = %d", theFont.type );%@NL@%
- SprintAt( iRow++, iCol + 5, "int .ascent = %d", theFont.ascent );%@NL@%
- SprintAt( iRow++, iCol + 5, "int .pixwidth = %d", theFont.pixwidth );%@NL@%
- SprintAt( iRow++, iCol + 5, "int .pixheight = %d", theFont.pixheight );%@NL@%
- SprintAt( iRow++, iCol + 5, "int .avgwidth = %d", theFont.avgwidth );%@NL@%
- SprintAt( iRow++, iCol + 5, "char .filename = %s", theFont.filename );%@NL@%
- SprintAt( iRow++, iCol + 5, "char .facename = %s", theFont.facename );%@NL@%
- %@NL@%
- return iRow;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowLegendType - Displays data in a variable of type "legendtype".%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iRow - Row at which to start%@NL@%
- %@AB@% * iCol - Column from which to indent%@NL@%
- %@AB@% * theLegend - Variable of type "legendtype" to display%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Next available row%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ShowLegendType( int iRow, int iCol, legendtype theLegend )%@NL@%
- {%@NL@%
- SprintAt( iRow++, iCol + 5, "short .legend = %s",%@NL@%
- (theLegend.legend) ? "TRUE" : "FALSE" );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .place = %d", theLegend.place );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .textcolor = %d", theLegend.textcolor );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .autosize = %d", theLegend.autosize );%@NL@%
- SprintAt( iRow++, iCol + 5, "windowtype legendwindow =" );%@NL@%
- iRow = ShowWindowType( iRow, iCol + 5, theLegend.legendwindow );%@NL@%
- %@NL@%
- return iRow;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowSampleData - Displays the sample data for the demo.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ShowSampleData()%@NL@%
- {%@NL@%
- int iCat, y, iSeries, iValue;%@NL@%
- char szTmp[80];%@NL@%
- %@NL@%
- %@AB@%/* Display data in table format. */%@AE@%%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- PrintAt( 1, 40 - strlen(szTmp) / 2, "Data in Table Format", -1 );%@NL@%
- %@NL@%
- %@AB@%/* Write titles and draw separator line. */%@AE@%%@NL@%
- y = 3;%@NL@%
- for( iCat = 1; iCat <= 12; iCat++ )%@NL@%
- PrintAt( y, iCat * 6, aMonths[iCat - 1], -1 );%@NL@%
- %@NL@%
- memset( szTmp, '-', 69 );%@NL@%
- szTmp[69] = 0;%@NL@%
- PrintAt( ++y, 6, szTmp, -1 );%@NL@%
- %@NL@%
- %@AB@%/* Write data. */%@AE@%%@NL@%
- for( iSeries = 1; iSeries <= 3; iSeries++ )%@NL@%
- {%@NL@%
- PrintAt( y += 2, 4, aSalesTitles[iSeries - 1], -1 );%@NL@%
- y += 2;%@NL@%
- for( iValue = 1; iValue <= 12; iValue++ )%@NL@%
- {%@NL@%
- sprintf( szTmp, "%#3.2f", aSales[iSeries - 1][iValue - 1] );%@NL@%
- PrintAt( y, iValue * 6, (char _far *)szTmp, -1 );%@NL@%
- }%@NL@%
- }%@NL@%
- PrintAt( y += 2, 4, TempTitle, -1 );%@NL@%
- y += 2;%@NL@%
- for( iValue = 1; iValue <= 12; iValue++ )%@NL@%
- {%@NL@%
- sprintf( szTmp, "%#3.1f", aTemperature[iValue - 1] );%@NL@%
- PrintAt( y, iValue * 6, szTmp, -1 );%@NL@%
- }%@NL@%
- %@NL@%
- PrintAt( y += 2, 1, "Press any key to continue . . .", -1 );%@NL@%
- getche();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowTitleType - Displays data in a variable of type "titletype".%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iRow - Row at which to start%@NL@%
- %@AB@% * iCol - Column from which to indent%@NL@%
- %@AB@% * theTitle - Variable of type "titletype" to display%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Next available row%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ShowTitleType( int iRow, int iCol, titletype theTitle )%@NL@%
- {%@NL@%
- SprintAt( iRow++, iCol + 5, "char .title[%d] = \"%s\"", _PG_TITLELEN,%@NL@%
- theTitle.title );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .titlecolor = %d", theTitle.titlecolor );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .justify = %d", theTitle.justify );%@NL@%
- %@NL@%
- return iRow;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowWindowType - Displays data in a variable of type "windowtype".%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iRow - Row at which to start%@NL@%
- %@AB@% * iCol - Column from which to indent%@NL@%
- %@AB@% * theWindow - Variable of type "windowtype" to display%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Next available row%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ShowWindowType( int iRow, int iCol, windowtype theWindow )%@NL@%
- {%@NL@%
- SprintAt( iRow++, iCol + 5, "short .x1 = %d", theWindow.x1 );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .y1 = %d", theWindow.y1 );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .x2 = %d", theWindow.x2 );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .y2 = %d", theWindow.y2 );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .border = %d", theWindow.border );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .background = %d", theWindow.background );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .borderstyle = %d", theWindow.borderstyle );%@NL@%
- SprintAt( iRow++, iCol + 5, "short .bordercolor = %d", theWindow.bordercolor );%@NL@%
- %@NL@%
- return iRow;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ShowError - Displays error message for one of the chart library%@NL@%
- %@AB@% * errors.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iErr - Error number%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ShowError( int iErr )%@NL@%
- {%@NL@%
- char szTmp[50];%@NL@%
- %@NL@%
- %@AB@%/* Change to text screen. */%@AE@%%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- %@NL@%
- %@AB@%/* Select the error text. */%@AE@%%@NL@%
- switch( iErr )%@NL@%
- {%@NL@%
- case _PG_NOTINITIALIZED:%@NL@%
- strcpy( szTmp, "Chart Library Not Initialized" );%@NL@%
- break;%@NL@%
- case _PG_BADSCREENMODE:%@NL@%
- strcpy( szTmp, "Invalid Screen Mode" );%@NL@%
- break;%@NL@%
- case _PG_BADCHARTTYPE:%@NL@%
- strcpy( szTmp, "Invalid Chart Type" );%@NL@%
- break;%@NL@%
- case _PG_BADCHARTSTYLE:%@NL@%
- strcpy( szTmp, "Invalid Chart Style" );%@NL@%
- break;%@NL@%
- case _PG_BADLEGENDWINDOW:%@NL@%
- strcpy( szTmp, "Invalid Legend Window" );%@NL@%
- break;%@NL@%
- case _PG_BADDATAWINDOW:%@NL@%
- strcpy( szTmp, "No Room for Data window" );%@NL@%
- break;%@NL@%
- case _PG_BADCHARTWINDOW:%@NL@%
- strcpy( szTmp, "Invalid Chart window coordinates" );%@NL@%
- break;%@NL@%
- case _PG_NOMEMORY:%@NL@%
- strcpy( szTmp, "Not Enough Memory for Data Arrays" );%@NL@%
- break;%@NL@%
- case _PG_BADLOGBASE:%@NL@%
- strcpy( szTmp, "X or Y log base <= 0" );%@NL@%
- break;%@NL@%
- case _PG_BADSCALEFACTOR:%@NL@%
- strcpy( szTmp, "X or Y scale factor = 0" );%@NL@%
- break;%@NL@%
- case _PG_TOOSMALLN:%@NL@%
- strcpy( szTmp, "Too few data values" );%@NL@%
- break;%@NL@%
- case _PG_TOOFEWSERIES:%@NL@%
- strcpy( szTmp, "No data series specified" );%@NL@%
- break;%@NL@%
- default:%@NL@%
- strcpy( szTmp, "Unknown error" );%@NL@%
- }%@NL@%
- %@NL@%
- ErrorMsg( szTmp );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ViewChart - Draws the current chart.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int ViewChart()%@NL@%
- {%@NL@%
- int cValue, iValue, iSeries, iErr;%@NL@%
- %@NL@%
- %@AB@%/* Make sure some data exists. */%@AE@%%@NL@%
- if( cSeries <= 0 )%@NL@%
- {%@NL@%
- fDefault = TRUE;%@NL@%
- DefaultData( ce.charttype, ce.chartstyle, FALSE );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Find the longest series. */%@AE@%%@NL@%
- cValue = 0;%@NL@%
- for( iSeries = 0; iSeries < cSeries; iSeries++ )%@NL@%
- if( acSeries[iSeries] > cValue )%@NL@%
- cValue = acSeries[iSeries];%@NL@%
- %@NL@%
- _setvideomode( si.mode );%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Process depending on the type of chart. */%@AE@%%@NL@%
- switch( ce.charttype )%@NL@%
- {%@NL@%
- %@NL@%
- case _PG_PIECHART:%@NL@%
- case _PG_BARCHART:%@NL@%
- case _PG_COLUMNCHART:%@NL@%
- case _PG_LINECHART:%@NL@%
- %@NL@%
- %@AB@%/* Initialize data and draw pie chart or single-series bar,%@NL@%
- %@AB@% * column, or line chart.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( (cSeries == 1) ||( ce.charttype == _PG_PIECHART) )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Transfer data into a single-dimension array. */%@AE@%%@NL@%
- for( iValue = 0; iValue < cValue; iValue++ )%@NL@%
- axValue[iValue] = aValue[0][iValue];%@NL@%
- %@NL@%
- %@AB@%/* Draw chart. */%@AE@%%@NL@%
- if( ce.charttype == _PG_PIECHART )%@NL@%
- iErr = _pg_chartpie( &ce, aCat, axValue,%@NL@%
- aExplode, cValue );%@NL@%
- else%@NL@%
- iErr = _pg_chart( &ce, aCat, axValue, cValue );%@NL@%
- }%@NL@%
- %@AB@%/* If multiple-series, then data is OK. Just draw chart. */%@AE@%%@NL@%
- else%@NL@%
- iErr = _pg_chartms( &ce, aCat, (float _far *)aValue,%@NL@%
- cSeries, cValue, cValue, aSeriesName );%@NL@%
- break;%@NL@%
- %@NL@%
- case _PG_SCATTERCHART:%@NL@%
- %@NL@%
- %@AB@%/* Make sure there are enough data sets. */%@AE@%%@NL@%
- if( cSeries == 1 )%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- si.help = 10;%@NL@%
- ErrorMsg( "Too few value data columns for scatter chart." );%@NL@%
- return 1;%@NL@%
- %@NL@%
- }%@NL@%
- %@AB@%/* If it's a single-series scatter, transfer data to one-%@NL@%
- %@AB@% * dimensional arrays and make chart call.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- else if( cSeries == 2 )%@NL@%
- {%@NL@%
- for( iValue = 0; iValue < cValue; iValue++ )%@NL@%
- {%@NL@%
- axValue[iValue] = aValue[0][iValue];%@NL@%
- ayValue[iValue] = aValue[1][iValue];%@NL@%
- }%@NL@%
- cSeries = 1;%@NL@%
- iErr = _pg_chartscatter( &ce, axValue, ayValue, cValue );%@NL@%
- %@NL@%
- }%@NL@%
- %@AB@%/* If it's a multiple-series scatter, transfer odd columns to%@NL@%
- %@AB@% * X-axis data array and even columns to Y-axis array and make%@NL@%
- %@AB@% * chart call.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- else%@NL@%
- {%@NL@%
- %@NL@%
- for( iSeries = 1; iSeries < cSeries; iSeries += 2 )%@NL@%
- {%@NL@%
- aSeriesName[iSeries / 2] = aSeriesName[iSeries - 1];%@NL@%
- for( iValue = 0; iValue < cValue; iValue++ )%@NL@%
- {%@NL@%
- axValueMS[iSeries / 2][iValue] =%@NL@%
- aValue[iSeries - 1][iValue];%@NL@%
- ayValueMS[iSeries / 2][iValue] =%@NL@%
- aValue[iSeries][iValue];%@NL@%
- }%@NL@%
- }%@NL@%
- cSeries /= 2;%@NL@%
- %@NL@%
- iErr = _pg_chartscatterms( &ce, (float _far *)axValueMS,%@NL@%
- (float _far *)ayValueMS,%@NL@%
- cSeries, cValue, cValue,%@NL@%
- aSeriesName );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- if( !fDefault )%@NL@%
- ClearData( FALSE );%@NL@%
- %@NL@%
- %@AB@%/* If error, show it, else wait for keypress with chart on screen. */%@AE@%%@NL@%
- if( iErr )%@NL@%
- {%@NL@%
- ShowError( iErr );%@NL@%
- return iErr;%@NL@%
- }%@NL@%
- else%@NL@%
- return ( getch() == ESCAPE ); %@AB@%/* ESCAPE means stop demo */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHRTOPT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\CHRTOPT.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<pgchart.h> %@NL@%
- %@AI@%#include %@AE@%"chrtdemo.h" %@NL@%
- %@NL@%
- %@AB@%/* Structures for system configuration and chart environment. */%@AE@%%@NL@%
- extern struct videoconfig vc;%@NL@%
- extern chartenv ce;%@NL@%
- %@NL@%
- %@AB@%/* Variable used to track control and screen position. */%@AE@%%@NL@%
- extern struct SCREENINFO si;%@NL@%
- %@NL@%
- %@AB@%/* Colors of menus and prompts. */%@AE@%%@NL@%
- extern struct tagColor co;%@NL@%
- %@NL@%
- %@AB@%/* Arrays of strings used by the Menu function. The first string is the%@NL@%
- %@AB@% * menu title. The next non-null strings are the menu selections. A null%@NL@%
- %@AB@% * string indicates the end of the list.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *pszAxes[] =%@NL@%
- { "Axis", "X Axis", "Y Axis", "" };%@NL@%
- %@NL@%
- char *pszAxis[] =%@NL@%
- { "? Options", "Grid", "Axis Title", "Color",%@NL@%
- "Range Type", "Scale", "Tic Marks", "" };%@NL@%
- %@NL@%
- char *pszAuto[] =%@NL@%
- { "Auto", "Auto", "Manual", "" };%@NL@%
- %@NL@%
- char *pszBorder[] =%@NL@%
- { "Type", "Color", "Style", "" };%@NL@%
- %@NL@%
- char *pszChartWindow[] =%@NL@%
- { "Chart", "Size", "Color (Background)", "Border", "" };%@NL@%
- %@NL@%
- char *pszDataWindow[] =%@NL@%
- { "Data", "Color (Background)", "Border", "" };%@NL@%
- %@NL@%
- char * pszFontOpt[] =%@NL@%
- { "Font Options", "Change Typeface", "Set Character Size", "" };%@NL@%
- %@NL@%
- char *pszJustify[] =%@NL@%
- { "Justify", "Left", "Center", "Right", "" };%@NL@%
- %@NL@%
- char *pszLegendWindow[] =%@NL@%
- { "Options", "Place", "Text Color", "Size", "Color (Background)",%@NL@%
- "Border", "" };%@NL@%
- %@NL@%
- char *pszPlace[] =%@NL@%
- { "Place", "Right", "Bottom", "Overlay", "" };%@NL@%
- %@NL@%
- char *pszScale[] =%@NL@%
- { "Scale", "Low (Min)", "High (Max)", "Scale Factor", "Title", "" };%@NL@%
- %@NL@%
- char *pszSize[] =%@NL@%
- { "Size", "Top", "Left", "Bottom", "Right", "" };%@NL@%
- %@NL@%
- char *pszTic[] =%@NL@%
- { "Tic Type", "Interval", "Format", "Decimals", "" };%@NL@%
- %@NL@%
- char *pszTitleOpt[] =%@NL@%
- { "", "Text", "Color", "Justify", "" };%@NL@%
- %@NL@%
- char *pszTitles[] =%@NL@%
- { "Title", "Main Title", "Sub Title", "" };%@NL@%
- %@NL@%
- char *pszTypeface[] =%@NL@%
- { "Type Faces", "Courier", "Helv", "Tms Rmn", "Modern", "Script",%@NL@%
- "Roman", "None", "" };%@NL@%
- %@NL@%
- char *pszWindows[] =%@NL@%
- { "Window", "Chart Window", "Data Window", "" };%@NL@%
- %@NL@%
- %@AB@%/* Axes - Selects X or Y axis.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: none%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Axes()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- static axistype *patAxis[2] = { &ce.xaxis, &ce.yaxis };%@NL@%
- %@NL@%
- %@AB@%/* Get menu choice and call appropriate axis Menu. */%@AE@%%@NL@%
- PushTitle( pszAxes[0] );%@NL@%
- Help( "Choose 'X' or 'Y' Axis", co.InputColor );%@NL@%
- while( (iChoice = Menu( pszAxes )) != ESCAPE )%@NL@%
- {%@NL@%
- %@AB@%/* Modify axis title, depending on choice. */%@AE@%%@NL@%
- pszAxis[0][0] = (--iChoice == 0) ? 'X' : 'Y';%@NL@%
- %@NL@%
- %@AB@%/* Obtain axis information for appropriate axis. */%@AE@%%@NL@%
- Axis( patAxis[iChoice] );%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Axis - Selects axis options.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pat - Pointer to axistype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Axis( axistype *pat )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszAxis[0] );%@NL@%
- while( (iChoice = Menu( pszAxis )) != ESCAPE )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Get Axis option. */%@AE@%%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- %@AB@%/* Grid or not? */%@AE@%%@NL@%
- iChoice = BlankMenu( "Grid", "Grid", "No Grid" );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* If yes, set grid flag and get the grid style. */%@AE@%%@NL@%
- pat->grid = TRUE;%@NL@%
- Help( "Enter a number in the range 0-10.",%@NL@%
- co.InputColor );%@NL@%
- pat->gridstyle =%@NL@%
- InputInt( "Grid Style? ", pat->gridstyle, 0, 10 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* If no, clear grid flag. */%@AE@%%@NL@%
- pat->grid = FALSE;%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Select axis title options. */%@AE@%%@NL@%
- pszTitleOpt[0] = "Axis Title";%@NL@%
- TitleOpt( &pat->axistitle );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@AB@%/* Select color. */%@AE@%%@NL@%
- Help( "Enter a number in the range 0-15.", co.InputColor );%@NL@%
- pat->axiscolor =%@NL@%
- InputInt( "Axis Color? ", pat->axiscolor, 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 4:%@NL@%
- %@AB@%/* Get the axis range. */%@AE@%%@NL@%
- AxisRange( pat );%@NL@%
- break;%@NL@%
- %@NL@%
- case 5:%@NL@%
- %@AB@%/* Get the axis scale. */%@AE@%%@NL@%
- AxisScale( pat );%@NL@%
- break;%@NL@%
- %@NL@%
- case 6:%@NL@%
- %@AB@%/* Get axis tic mark options. */%@AE@%%@NL@%
- AxisTics( pat );%@NL@%
- break;%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* AxisRange - Selects range for an axis.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pat - pointer to axistype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void AxisRange( axistype *pat )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- iChoice = BlankMenu( "Range Type", "Normal", "Log" );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- %@AB@%/* Set range type to linear. */%@AE@%%@NL@%
- pat->rangetype = _PG_LINEARAXIS;%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Set range type to log, then query for log base. */%@AE@%%@NL@%
- pat->rangetype = _PG_LOGAXIS;%@NL@%
- Help( "Enter a value greater than or equal 2.", co.InputColor );%@NL@%
- pat->logbase = (float)InputInt( "Log base? ",%@NL@%
- (int)pat->logbase, 2, 0 );%@NL@%
- break;%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* AxisScale - Selects scale options for an axis.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pat - pointer to axistype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void AxisScale( axistype *pat )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszAuto[0] );%@NL@%
- iChoice = Menu( pszAuto );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* Set AutoScale flag. */%@AE@%%@NL@%
- pat->autoscale = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@NL@%
- %@AB@%/* Clear AutoScale flag and get scale options. */%@AE@%%@NL@%
- pat->autoscale = FALSE;%@NL@%
- PushTitle( pszScale[0] );%@NL@%
- while( (iChoice = Menu( pszScale )) != ESCAPE )%@NL@%
- {%@NL@%
- %@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1: %@NL@%
- %@AB@%/* Query for scale minimum. */%@AE@%%@NL@%
- Help( "Enter the range minimum value.", co.InputColor );%@NL@%
- pat->scalemin =%@NL@%
- (float)InputInt( "Minimum? ",%@NL@%
- (int)pat->scalemin, 1, 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2: %@NL@%
- %@AB@%/* Query for scale maximum. */%@AE@%%@NL@%
- Help( "Enter the range maximum value.", co.InputColor );%@NL@%
- pat->scalemin =%@NL@%
- (float)InputInt( "Minimum? ",%@NL@%
- (int)pat->scalemin, 1, 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@AB@%/* Query for scale factor. */%@AE@%%@NL@%
- Help( "Enter scale factor (must be 1 or greater).",%@NL@%
- co.InputColor );%@NL@%
- pat->scalefactor =%@NL@%
- (float)InputInt( "Scale Factor? ",%@NL@%
- (int)pat->scalefactor, 1, 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 4: %@NL@%
- %@AB@%/* Modify scale title, then use menu to get%@NL@%
- %@AB@% * title options.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pszTitleOpt[0] = "Scale Title";%@NL@%
- TitleOpt( &pat->scaletitle );%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* AxisTics - Selects tic options for an axis.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pat - pointer to axistype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void AxisTics( axistype *pat )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszTic[0] );%@NL@%
- while( (iChoice = Menu( pszTic )) != ESCAPE )%@NL@%
- {%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* Query for tic interval. */%@AE@%%@NL@%
- Help( "Enter distance in data units.", co.InputColor );%@NL@%
- pat->ticinterval =%@NL@%
- InputFloat( "Distance between tic marks? ",%@NL@%
- pat->ticinterval );%@NL@%
- pat->autoscale = FALSE;%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Query for tic format. */%@AE@%%@NL@%
- iChoice = BlankMenu( "Tic Format", "Normal", "Log" );%@NL@%
- if( iChoice != ESCAPE )%@NL@%
- pat->ticformat = iChoice;%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@AB@%/* Query for number of decimal places per tic. */%@AE@%%@NL@%
- pat->ticdecimals =%@NL@%
- InputInt( "Enter decimal places (0 to 9). ",%@NL@%
- pat->ticdecimals, 0, 9 );%@NL@%
- pat->autoscale = FALSE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Border - Specifies border information for a window.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pwt - Pointer to windowtype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Border( windowtype *pwt )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Ask whether a border is wanted. */%@AE@%%@NL@%
- iChoice = BlankMenu( "Border", "Border", "No Border" );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@NL@%
- %@AB@%/* If border, set Border flag and query for border options. */%@AE@%%@NL@%
- pwt->border= TRUE;%@NL@%
- PushTitle( pszBorder[0] );%@NL@%
- while( (iChoice = Menu( pszBorder )) != ESCAPE )%@NL@%
- {%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- %@AB@%/* Query for border color. */%@AE@%%@NL@%
- Help( "Enter a color in the range 0-15.",%@NL@%
- co.InputColor );%@NL@%
- pwt->bordercolor =%@NL@%
- InputInt( "Border color? ",%@NL@%
- pwt->bordercolor, 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Query for border style. */%@AE@%%@NL@%
- Help( "Enter a style in the range 0-10.", co.InputColor );%@NL@%
- pwt->borderstyle =%@NL@%
- InputInt( "Border style? ",%@NL@%
- pwt->borderstyle, 0, 10 );%@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* If no border, clear Border flag. */%@AE@%%@NL@%
- pwt->border= FALSE;%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ChangeTypeface - Allow the user to specify a new type face.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iFaceIndex - index of last typeface%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: index of new typeface%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int ChangeTypeface( int iFaceIndex )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Get menu choice and call appropriate axis Menu. */%@AE@%%@NL@%
- PushTitle( pszFontOpt[0] );%@NL@%
- Help( "Choose one of the type faces listed.", co.InputColor );%@NL@%
- %@NL@%
- if( (iChoice = Menu( pszTypeface ) - 1) != ESCAPE )%@NL@%
- {%@NL@%
- %@AB@%/* If the user wants the system font, unregister the other fonts. */%@AE@%%@NL@%
- if( iChoice == NOFONT )%@NL@%
- _unregisterfonts();%@NL@%
- %@NL@%
- %@AB@%/* If the user wants any font but the system font, make sure the%@NL@%
- %@AB@% * fonts are registered.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* If last face was NOFONT, register fonts. */%@AE@%%@NL@%
- if( iFaceIndex == NOFONT )%@NL@%
- {%@NL@%
- %@AB@%/* Assumes font files are in current directory.%@NL@%
- %@AB@% * Could be enhanced to handle any directory.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( _registerfonts( "*.FON" ) < 0 )%@NL@%
- ErrorMsg( "Font files must be in current directory" );%@NL@%
- else%@NL@%
- iFaceIndex = iChoice;%@NL@%
- }%@NL@%
- else%@NL@%
- iFaceIndex = iChoice;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- PopTitle();%@NL@%
- return iFaceIndex;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ChooseFont - Chooses a font from the font library.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: WhichFont - A member of the set [COURIER, HELV, TMS_RMN,%@NL@%
- %@AB@% * MODERN, SCRIPT, ROMAN, NOFONT]%@NL@%
- %@AB@% * Height - The desired height of the text (in pixels)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void ChooseFont( int WhichFont, int Height )%@NL@%
- {%@NL@%
- static char *FontIds[] =%@NL@%
- {%@NL@%
- "courier", "helv", "tms rmn", "modern", "script", "roman"%@NL@%
- };%@NL@%
- char SetCommand[30];%@NL@%
- %@NL@%
- %@AB@%/* Construct the command to send to _setfont. */%@AE@%%@NL@%
- sprintf( SetCommand, "t'%s'h%dw0b", FontIds[WhichFont], Height );%@NL@%
- %@NL@%
- if( _setfont( SetCommand ) < 0 )%@NL@%
- {%@NL@%
- _outtext( "Could not set. Try different font or size" );%@NL@%
- getch();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ChartWindow - Gets chart window information.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ChartWindow()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszChartWindow[0] );%@NL@%
- while( (iChoice = Menu( pszChartWindow )) != ESCAPE )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Get window options. */%@AE@%%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* Get window size. */%@AE@%%@NL@%
- WindowSize( &ce.chartwindow );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Query for background color. */%@AE@%%@NL@%
- Help( "Enter a number in the range 0-15", co.InputColor );%@NL@%
- ce.chartwindow.background =%@NL@%
- InputInt( "Background Color? ", ce.chartwindow.background,%@NL@%
- 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@NL@%
- %@AB@%/* Get border options. */%@AE@%%@NL@%
- Border( &ce.chartwindow );%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* DataWindow - Geta data window information.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void DataWindow()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszDataWindow[0] );%@NL@%
- while( (iChoice = Menu( pszDataWindow )) != ESCAPE )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Get data window menu options. */%@AE@%%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1: %@NL@%
- %@AB@%/* Query for background color. */%@AE@%%@NL@%
- Help( "Enter a number in the range 0-15", co.InputColor );%@NL@%
- ce.datawindow.background =%@NL@%
- InputInt( "Background Color? ",%@NL@%
- ce.datawindow.background,%@NL@%
- 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Get border options. */%@AE@%%@NL@%
- Border( &ce.datawindow );%@NL@%
- break;%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* FontOptions - Allows the user to modify the font used for display.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void FontOptions()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- static int iFaceIndex = NOFONT;%@NL@%
- static int iTypeSize = 8;%@NL@%
- %@NL@%
- %@AB@%/* Get menu choice and call appropriate axis Menu. */%@AE@%%@NL@%
- PushTitle( pszFontOpt[0] );%@NL@%
- %@NL@%
- while( (iChoice = Menu( pszFontOpt )) != ESCAPE )%@NL@%
- {%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@AB@%/* Change Typeface. */%@AE@%%@NL@%
- case 1:%@NL@%
- iFaceIndex = ChangeTypeface( iFaceIndex );%@NL@%
- ChooseFont( iFaceIndex, iTypeSize );%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* Change Type Size. */%@AE@%%@NL@%
- case 2:%@NL@%
- %@NL@%
- if( iFaceIndex == NOFONT )%@NL@%
- {%@NL@%
- ErrorMsg( "Select a font first" );%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- iTypeSize = InputInt( "Enter a type size. ", iTypeSize,%@NL@%
- 8, 128 );%@NL@%
- %@NL@%
- ChooseFont( iFaceIndex, iTypeSize );%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Justify - Gets title justification option.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: Pointer to titletype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Justify( titletype *ptt )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszJustify[0] );%@NL@%
- iChoice = Menu( pszJustify );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Set justification. */%@AE@%%@NL@%
- case 1:%@NL@%
- case 2:%@NL@%
- case 3:%@NL@%
- ptt->justify = iChoice;%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Legend - Asks whether a legend is desired, and if so, gets%@NL@%
- %@AB@% * legend options.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Legend()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Is legend desired? */%@AE@%%@NL@%
- iChoice = BlankMenu( "Legend", "Legend", "No Legend" );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- %@AB@%/* If legend, set legend flag and get options. */%@AE@%%@NL@%
- ce.legend.legend = TRUE;%@NL@%
- PushTitle( pszLegendWindow[0] );%@NL@%
- do%@NL@%
- {%@NL@%
- iChoice = Menu( pszLegendWindow );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* Get legend place. */%@AE@%%@NL@%
- LegendPlace();%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Query for legend color. */%@AE@%%@NL@%
- Help( "Enter a number in the range 0-15.", co.InputColor );%@NL@%
- ce.legend.textcolor =%@NL@%
- InputInt( "Text color? ",%@NL@%
- ce.legend.textcolor,%@NL@%
- 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@AB@%/* Get auto or manual sizing. */%@AE@%%@NL@%
- PushTitle( "Auto Legend" );%@NL@%
- iChoice = Menu( pszAuto );%@NL@%
- %@NL@%
- %@AB@%/* Set or clear the autosize flag. If manual%@NL@%
- %@AB@% * sizing was selected, get legend size.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- ce.legend.autosize = TRUE;%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- ce.legend.autosize = FALSE;%@NL@%
- WindowSize( &ce.legend.legendwindow );%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- break;%@NL@%
- %@NL@%
- case 4:%@NL@%
- %@AB@%/* Query for background color. */%@AE@%%@NL@%
- Help( "Type a number in the range 0-15.", co.InputColor );%@NL@%
- ce.legend.legendwindow.background =%@NL@%
- InputInt( "Background color? ",%@NL@%
- ce.legend.legendwindow.background,%@NL@%
- 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 5:%@NL@%
- %@AB@%/* Get border options for legend window. */%@AE@%%@NL@%
- Border( &ce.legend.legendwindow );%@NL@%
- }%@NL@%
- %@NL@%
- } while( iChoice != ESCAPE );%@NL@%
- PopTitle();%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* If no legend wanted, clear flag. */%@AE@%%@NL@%
- ce.legend.legend = FALSE;%@NL@%
- %@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* LegendPlace - Gets legend placement option.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void LegendPlace()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Get legend placement. */%@AE@%%@NL@%
- PushTitle( pszPlace[0] );%@NL@%
- iChoice = Menu( pszPlace );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- ce.legend.place = _PG_RIGHT;%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- ce.legend.place = _PG_BOTTOM;%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- ce.legend.place = _PG_OVERLAY;%@NL@%
- }%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ScreenMode - Gets a new screen mode.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ScreenMode()%@NL@%
- {%@NL@%
- int iMode, i;%@NL@%
- char szTmp[80], szHlp[80];%@NL@%
- static int iLegal[5][11] =%@NL@%
- {%@NL@%
- { 3, 4, 5, 6 },%@NL@%
- { 4, 4, 5, 6, 64 },%@NL@%
- { 4, 4, 5, 6, 19 },%@NL@%
- { 7, 4, 5, 6, 13, 14, 15, 16 },%@NL@%
- { 10, 4, 5, 6, 13, 14, 15, 16, 17, 18, 19 }%@NL@%
- };%@NL@%
- int iAdaptor;%@NL@%
- %@NL@%
- PushTitle( "Screen Mode" );%@NL@%
- %@NL@%
- %@AB@%/* Show appropriate help line for adaptor. */%@AE@%%@NL@%
- switch( vc.adapter )%@NL@%
- {%@NL@%
- case _HGC:%@NL@%
- PopTitle();%@NL@%
- return;%@NL@%
- case _CGA:%@NL@%
- iAdaptor = 0;%@NL@%
- break;%@NL@%
- case _OCGA:%@NL@%
- iAdaptor = 1;%@NL@%
- break;%@NL@%
- case _MCGA:%@NL@%
- iAdaptor = 2;%@NL@%
- break;%@NL@%
- case _EGA:%@NL@%
- case _OEGA:%@NL@%
- if( vc.adapter == _MONO )%@NL@%
- {%@NL@%
- PopTitle();%@NL@%
- return;%@NL@%
- }%@NL@%
- else%@NL@%
- iAdaptor = 3;%@NL@%
- break;%@NL@%
- case _VGA:%@NL@%
- case _OVGA:%@NL@%
- iAdaptor = 4;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Form the help line (which gives the choices legal for%@NL@%
- %@AB@% * the adaptor sensed in the user's machine).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for( iMode = 0, szHlp[0] = '\0'; iMode <= iLegal[iAdaptor][0]; ++iMode )%@NL@%
- {%@NL@%
- if( iMode == 0 )%@NL@%
- strcpy( szTmp, "Enter " );%@NL@%
- else if( iMode < iLegal[iAdaptor][0] )%@NL@%
- sprintf( szTmp, "%d, ", iLegal[iAdaptor][iMode] );%@NL@%
- else%@NL@%
- sprintf( szTmp, "or %d", iLegal[iAdaptor][iMode] );%@NL@%
- strcat( szHlp, szTmp );%@NL@%
- }%@NL@%
- %@NL@%
- WrtForm( 18 );%@NL@%
- Help( szHlp, co.InputColor );%@NL@%
- %@NL@%
- %@AB@%/* Query for screen mode. */%@AE@%%@NL@%
- for( ;; )%@NL@%
- {%@NL@%
- iMode = InputInt( "Screen Mode? ", si.mode, 1, 64 );%@NL@%
- for( i = 1; i <= iLegal[iAdaptor][0]; ++i ) %@AB@%/* Test legal values */%@AE@%%@NL@%
- if( iMode == iLegal[iAdaptor][i] ) %@AB@%/* If a match is found */%@AE@%%@NL@%
- break; %@AB@%/* Terminate for loop */%@AE@%%@NL@%
- if( iMode == iLegal[iAdaptor][i] ) %@AB@%/* If it's a match, */%@AE@%%@NL@%
- break; %@AB@%/* terminate do loop, */%@AE@%%@NL@%
- else %@AB@%/* otherwise BEEP, and */%@AE@%%@NL@%
- putchar( BEEP ); %@AB@%/* solicit correct data */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- PopTitle();%@NL@%
- if( SetGraphMode( iMode ) )%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- else%@NL@%
- ShowError( _PG_BADSCREENMODE );%@NL@%
- %@NL@%
- %@AB@%/* Force rescaling of the chart by resetting the window%@NL@%
- %@AB@% * rectangles for the chart and data windows to zero size.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ce.chartwindow.x1 = ce.chartwindow.x2 = ce.chartwindow.y1 =%@NL@%
- ce.chartwindow.y2 = 0;%@NL@%
- ce.datawindow = ce.chartwindow;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* TitleOpt - Gets title options.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: ptt - Pointer to titletype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void TitleOpt( titletype *ptt )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszTitleOpt[0] );%@NL@%
- do%@NL@%
- {%@NL@%
- iChoice = Menu( pszTitleOpt );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1: %@NL@%
- %@AB@%/* Query for title text. */%@AE@%%@NL@%
- Help( "70 characters maximum length.", co.InputColor );%@NL@%
- InputStr( "Enter Text: ", ptt->title );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2: %@NL@%
- %@AB@%/* Query for title color color. */%@AE@%%@NL@%
- Help( "Enter a number in the range 0-15.", co.InputColor );%@NL@%
- ptt->titlecolor =%@NL@%
- InputInt( "Title Color? ", ptt->titlecolor, 0, 15 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- %@AB@%/* Get justify option. */%@AE@%%@NL@%
- Justify( ptt );%@NL@%
- }%@NL@%
- ClrHelp();%@NL@%
- %@NL@%
- } while( iChoice != ESCAPE );%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Titles - Manages Main and Sub title menus.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Titles()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszTitles[0] );%@NL@%
- do%@NL@%
- {%@NL@%
- iChoice = Menu( pszTitles );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- %@AB@%/* Fix menu title and get options for main title. */%@AE@%%@NL@%
- pszTitleOpt[0] = "MainTitle";%@NL@%
- TitleOpt( &ce.maintitle );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- %@AB@%/* Fix menu title and get options for subtitle. */%@AE@%%@NL@%
- pszTitleOpt[0] = "Sub Title";%@NL@%
- TitleOpt( &ce.subtitle );%@NL@%
- }%@NL@%
- } while( iChoice != ESCAPE );%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Windows - Selects chart or data window, and gets options for either.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Windows()%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- PushTitle( pszWindows[0] );%@NL@%
- do%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Select window and get options for it. */%@AE@%%@NL@%
- iChoice = Menu( pszWindows );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- ChartWindow();%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- DataWindow();%@NL@%
- %@NL@%
- }%@NL@%
- } while( iChoice != ESCAPE );%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* WindowSize - Gets coordinates for window location and size.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pwt - pointer to windowtype variable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void WindowSize( windowtype *pwt )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Get window size settings. */%@AE@%%@NL@%
- PushTitle( pszSize[0] );%@NL@%
- do%@NL@%
- {%@NL@%
- %@AB@%/* Query for top, bottom, left, or right of window. */%@AE@%%@NL@%
- iChoice = Menu( pszSize );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- %@NL@%
- case 1:%@NL@%
- Help( "Enter window top in pixels.", co.InputColor );%@NL@%
- pwt->y1 = InputInt( "Top? ", pwt->y1, 0, si.yMax );%@NL@%
- break;%@NL@%
- %@NL@%
- case 2:%@NL@%
- Help( "Enter window Left in pixels.", co.InputColor );%@NL@%
- pwt->x1 = InputInt( "Left? ", pwt->x1, 0, si.xMax );%@NL@%
- break;%@NL@%
- %@NL@%
- case 3:%@NL@%
- Help( "Enter window bottom in pixels.", co.InputColor );%@NL@%
- pwt->y2 = InputInt( "Bottom? ", pwt->y2, 0, si.yMax );%@NL@%
- break;%@NL@%
- %@NL@%
- case 4:%@NL@%
- Help( "Enter window right in pixels.", co.InputColor );%@NL@%
- pwt->x2 = InputInt( "Right? ", pwt->x2, 0, si.xMax );%@NL@%
- }%@NL@%
- } while( iChoice != ESCAPE );%@NL@%
- PopTitle();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHRTSUPT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\CHRTSUPT.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdarg.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<pgchart.h> %@NL@%
- %@AI@%#include %@AE@%"chrtdemo.h" %@NL@%
- %@NL@%
- %@AB@%/* Variables to manage menus. */%@AE@%%@NL@%
- int cMenuLevel = 0; %@AB@%/* Current menu level */%@AE@%%@NL@%
- char *szMenuTitles[10]; %@AB@%/* Stack of menu titles */%@AE@%%@NL@%
- %@NL@%
- char *pszBlankMenu[4];%@NL@%
- %@NL@%
- %@AB@%/* Variables used to track control and screen position. */%@AE@%%@NL@%
- extern struct SCREENINFO si;%@NL@%
- %@NL@%
- %@AB@%/* Colors of menus and prompts. */%@AE@%%@NL@%
- extern struct tagColor co;%@NL@%
- %@NL@%
- %@AB@%/* BlankMenu - Gets responses to two specified choices.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchTitle - Menu title string%@NL@%
- %@AB@% * pchChoice1 - Selection 1 string%@NL@%
- %@AB@% * pchChoice2 - Selection 2 string%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Number of choice, or ESCAPE%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int BlankMenu( char *pchTitle, char *pchChoice1, char *pchChoice2 )%@NL@%
- {%@NL@%
- int iChoice;%@NL@%
- %@NL@%
- %@AB@%/* Initialize title and selections. */%@AE@%%@NL@%
- pszBlankMenu[0] = pchTitle;%@NL@%
- pszBlankMenu[1] = pchChoice1;%@NL@%
- pszBlankMenu[2] = pchChoice2;%@NL@%
- pszBlankMenu[3] = "\0";%@NL@%
- PushTitle( pszBlankMenu[0]);%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Accept only first letter of either selection, or ESC. */%@AE@%%@NL@%
- iChoice = Menu( pszBlankMenu );%@NL@%
- switch( iChoice )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- case 2:%@NL@%
- case ESCAPE:%@NL@%
- return iChoice;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ClrForm - Clears the center of the screen form.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ClrForm()%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Set partial screen window and clear it, then reset full screen. */%@AE@%%@NL@%
- _settextwindow( si.top, 1, si.bot, 80 );%@NL@%
- _clearscreen( _GWINDOW );%@NL@%
- _settextwindow( 1, 1, 25, 80 );%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ClrHelp - Clears the current help line.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ClrHelp()%@NL@%
- {%@NL@%
- %@AB@%/* Decrement the help line counter and clear the line. */%@AE@%%@NL@%
- _settextwindow( --si.help, 1, si.help, 80 );%@NL@%
- _clearscreen( _GWINDOW );%@NL@%
- _settextwindow( 1, 1, 25, 80 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* ErrorMsg - Displays an error message.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchMsg - error message string%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ErrorMsg( char *pchMsg )%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Beep, set error color, and display error message and continue prompt. */%@AE@%%@NL@%
- putch( BEEP );%@NL@%
- Help( pchMsg, co.ErrorColor );%@NL@%
- Help( "Press any key to continue.", co.ErrorColor );%@NL@%
- %@NL@%
- %@AB@%/* Wait for keypress and clear help lines. */%@AE@%%@NL@%
- getch();%@NL@%
- ClrHelp();%@NL@%
- ClrHelp();%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Help - Displays a help line on the screen.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchMsg - error message string%@NL@%
- %@AB@% * sColor - color for message%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Help( char *pchMsg, short sColor )%@NL@%
- {%@NL@%
- %@NL@%
- struct rccoord rcCursor;%@NL@%
- %@NL@%
- %@AB@%/* Save current cursor position. */%@AE@%%@NL@%
- rcCursor = _gettextposition();%@NL@%
- %@NL@%
- %@AB@%/* Print out help line and increment Helpline position variable. */%@AE@%%@NL@%
- PrintAt( si.help++, 5, pchMsg, sColor );%@NL@%
- %@NL@%
- %@AB@%/* Restore cursor position. */%@AE@%%@NL@%
- _settextposition( rcCursor.row, rcCursor.col );%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* InputCh - Prompts for and returns a character of input.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchPrompt - Prompt string%@NL@%
- %@AB@% * pchAccept - String of acceptable characters (case insensitive)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: Character entered%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int InputCh( char *pchPrompt, char *pchAccept )%@NL@%
- {%@NL@%
- int chResponse;%@NL@%
- %@NL@%
- %@AB@%/* Display prompt. */%@AE@%%@NL@%
- PrintAt( si.mid, 10, pchPrompt, co.InputColor );%@NL@%
- %@NL@%
- %@AB@%/* Loop until response is valid. */%@AE@%%@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- chResponse = toupper( getch() );%@NL@%
- %@NL@%
- %@AB@%/* Display and return if acceptable character, or beep if not. */%@AE@%%@NL@%
- if( *strchr( pchAccept, chResponse) )%@NL@%
- {%@NL@%
- _settextcolor( co.InfoColor );%@NL@%
- putch( chResponse );%@NL@%
- return chResponse;%@NL@%
- }%@NL@%
- else%@NL@%
- putch( BEEP );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* InputInt - Prompts for and returns an integer value within a%@NL@%
- %@AB@% * specified range.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchPrompt - Prompt string%@NL@%
- %@AB@% * iOld - Previous value%@NL@%
- %@AB@% * iMin - Minimum value of range%@NL@%
- %@AB@% * iMax - Maximum value of range%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: integer input by user%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int InputInt( char *pchPrompt, int iOld, int iMin, int iMax )%@NL@%
- {%@NL@%
- int i;%@NL@%
- char szTmp[70];%@NL@%
- %@NL@%
- %@AB@%/* Prompt for a string input and convert to an integer until a%@NL@%
- %@AB@% * value in the specified range is given. Then return the value.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- do%@NL@%
- {%@NL@%
- InputStr( pchPrompt, itoa( iOld, szTmp, 10) );%@NL@%
- i = atoi( szTmp );%@NL@%
- } while( !InRange( i, iMin, iMax) );%@NL@%
- return i;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* InputFloat - Prompts for and returns a float value.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchPrompt - Prompt string%@NL@%
- %@AB@% * fOld - Previous value%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: float input by user%@NL@%
- %@AB@% */%@AE@%%@NL@%
- float InputFloat( char *pchPrompt, float fOld )%@NL@%
- {%@NL@%
- char szTmp[70];%@NL@%
- %@NL@%
- %@AB@%/* Prompt for a string input and convert to a float. */%@AE@%%@NL@%
- sprintf( szTmp, "%f", fOld );%@NL@%
- InputStr( pchPrompt, szTmp );%@NL@%
- return (float)atof( szTmp );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* InputStr - Prompts for a string. Displays the previous string%@NL@%
- %@AB@% * until the first character is given. Then replaces it with new%@NL@%
- %@AB@% * entry.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchPrompt - Prompt string%@NL@%
- %@AB@% * pchOld - Charater buffer containing previous string; it%@NL@%
- %@AB@% * must be long enough to hold new string%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: pointer to pchOld, which now contains new string%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *InputStr( char *pchPrompt, char *pchOld )%@NL@%
- {%@NL@%
- char szTmp[81];%@NL@%
- int x = 5, y = si.mid, ch;%@NL@%
- %@NL@%
- %@AB@%/* Display prompt in center of form. */%@AE@%%@NL@%
- ClrForm();%@NL@%
- PrintAt( y, x, pchPrompt, co.InputColor );%@NL@%
- x += strlen( pchPrompt );%@NL@%
- %@NL@%
- %@AB@%/* Print the old value for reference. */%@AE@%%@NL@%
- _outtext( pchOld );%@NL@%
- _settextposition( y, x );%@NL@%
- %@NL@%
- %@AB@%/* Wait for input. When received, clear old string. */%@AE@%%@NL@%
- while( !(ch = kbhit()) )%@NL@%
- ;%@NL@%
- memset( szTmp, ' ', 80 );%@NL@%
- szTmp[80] = '\0';%@NL@%
- PrintAt( y, x, szTmp, -1 );%@NL@%
- %@NL@%
- %@AB@%/* Get new string. If string entered, return it. If null string%@NL@%
- %@AB@% * (ENTER key pressed), return old value.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _settextcolor( co.InfoColor );%@NL@%
- _settextposition( y, x );%@NL@%
- szTmp[0] = 70; %@AB@%/* Maximum length to be read */%@AE@%%@NL@%
- %@NL@%
- cgets( szTmp );%@NL@%
- if( szTmp[1] > 0 ) %@AB@%/* Are any characters read? */%@AE@%%@NL@%
- {%@NL@%
- strcpy( pchOld, &szTmp[2] );%@NL@%
- return &szTmp[2];%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _settextposition( y, x );%@NL@%
- return pchOld;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* InRange - Checks an integer to see if it is in a specified range.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: iValue - Integer to check%@NL@%
- %@AB@% * iMin - Minimum value of range%@NL@%
- %@AB@% * iMax - Maximim value of range%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: TRUE if in range, FALSE if not%@NL@%
- %@AB@% */%@AE@%%@NL@%
- BOOL InRange( int Value, int iMin, int iMax )%@NL@%
- {%@NL@%
- %@AB@%/* Check range and return true if valid, false if not. Note that%@NL@%
- %@AB@% * (iMin >= iMax) is taken as a signal to check only the minimum%@NL@%
- %@AB@% * value; there is no maximum.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( Value >= iMin )%@NL@%
- if( (Value <= iMax) || (iMin >= iMax) )%@NL@%
- return TRUE;%@NL@%
- else%@NL@%
- {%@NL@%
- ErrorMsg( "Invalid value." );%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Menu - Draws menu on screen and returns choice number.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: array of menu strings%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: number corresponding to the choice made from the menu%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Menu( char *pszMenuList[] )%@NL@%
- {%@NL@%
- int iItem, cItem, yItem, x = 10;%@NL@%
- int chResponse;%@NL@%
- %@NL@%
- %@AB@%/* Count menu items. */%@AE@%%@NL@%
- for( cItem = 1; *pszMenuList[cItem]; cItem++ )%@NL@%
- ;%@NL@%
- --cItem;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Clear the form and print the items in the menu. */%@AE@%%@NL@%
- WrtForm( 10 + cItem );%@NL@%
- for( iItem = 1, yItem = 8; iItem <= cItem; iItem++, yItem++ )%@NL@%
- {%@NL@%
- PrintAt( yItem, x, pszMenuList[iItem], co.InputColor );%@NL@%
- PrintChar( yItem, x, pszMenuList[iItem][0], co.HiliteColor );%@NL@%
- }%@NL@%
- ++yItem;%@NL@%
- %@NL@%
- %@AB@%/* Display prompt and help. */%@AE@%%@NL@%
- if( strcmpi( pszMenuList[0], "main menu" ) ) %@AB@%/* If not the main menu */%@AE@%%@NL@%
- Help( "Type the first letter of your selection or ESC to back up.",%@NL@%
- co.InputColor );%@NL@%
- else%@NL@%
- Help( "Type the first letter of your selection or \"Q\" to quit.",%@NL@%
- co.InputColor );%@NL@%
- %@NL@%
- PrintAt( yItem, x += 5, "Choice? ", co.InfoColor );%@NL@%
- x += 8;%@NL@%
- %@NL@%
- %@AB@%/* Loop until a valid choice is made. Beep at invalid choices. */%@AE@%%@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- _settextposition( yItem, x );%@NL@%
- chResponse = toupper( getch() );%@NL@%
- %@NL@%
- %@AB@%/* Back up for ESC. */%@AE@%%@NL@%
- if( chResponse == 27 )%@NL@%
- {%@NL@%
- ClrHelp();%@NL@%
- return ESCAPE;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Search first letters of choices for a match. If found, return%@NL@%
- %@AB@% * choice and clear help line.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for( iItem = 1; iItem <= cItem; iItem++ )%@NL@%
- {%@NL@%
- if( chResponse == toupper( pszMenuList[iItem][0]) )%@NL@%
- {%@NL@%
- putch( chResponse );%@NL@%
- ClrHelp();%@NL@%
- return iItem;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* If we get here, no valid choice was found, so beep and repeat. */%@AE@%%@NL@%
- putch( BEEP );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* PopTitle - Pops a menu title from the menu stack.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void PopTitle()%@NL@%
- {%@NL@%
- szMenuTitles[--cMenuLevel] = "";%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* PrintAt - Prints a string at the row/column coordinates%@NL@%
- %@AB@% * specified, in the specified color.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row - row at which to begin output of string%@NL@%
- %@AB@% * col - column at which to begin output of string%@NL@%
- %@AB@% * lpszString - zero (null) terminated string%@NL@%
- %@AB@% * sColor - color in which to output string (-1 if%@NL@%
- %@AB@% * PrintAt should leave color alone)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void PrintAt( int row, int column, char _far *lpszString, short sColor )%@NL@%
- {%@NL@%
- if( sColor != -1 )%@NL@%
- _settextcolor( sColor );%@NL@%
- _settextposition( row, column );%@NL@%
- _outtext( lpszString );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* PrintChar - Prints a character at the row/column coordinates%@NL@%
- %@AB@% * specified, in the specified color.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row - row at which to begin output of string%@NL@%
- %@AB@% * col - column at which to begin output of string%@NL@%
- %@AB@% * cChar - character to print%@NL@%
- %@AB@% * sColor - color in which to output string (-1 if%@NL@%
- %@AB@% * PrintChar should leave color alone)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void PrintChar(int row, int column, char cChar, short sColor)%@NL@%
- {%@NL@%
- char szTiny[2];%@NL@%
- %@NL@%
- szTiny[0] = cChar;%@NL@%
- szTiny[1] = '\0';%@NL@%
- PrintAt( row, column, szTiny, sColor );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* PushTitle - Pushes a menu title on to the menu stack.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: pchTitle - title string to push%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void PushTitle( char *pchTitle )%@NL@%
- {%@NL@%
- szMenuTitles[cMenuLevel++] = pchTitle;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* SetDisplayColors - Set the colors to values appropriate to the display%@NL@%
- %@AB@% * adaptor being used.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parms: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void SetDisplayColors()%@NL@%
- {%@NL@%
- if( ismono( si.mode ) )%@NL@%
- {%@NL@%
- co.InputColor = M_INPUTCOLOR;%@NL@%
- co.HiliteColor = M_HILITECOLOR;%@NL@%
- co.FormColor = M_FORMCOLOR;%@NL@%
- co.TitleColor = M_TITLECOLOR;%@NL@%
- co.ErrorColor = M_ERRORCOLOR;%@NL@%
- co.InfoColor = M_INFOCOLOR;%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- co.InputColor = C_INPUTCOLOR;%@NL@%
- co.HiliteColor = C_HILITECOLOR;%@NL@%
- co.FormColor = C_FORMCOLOR;%@NL@%
- co.TitleColor = C_TITLECOLOR;%@NL@%
- co.ErrorColor = C_ERRORCOLOR;%@NL@%
- co.InfoColor = C_INFOCOLOR;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* SprintAt - Format a string, using sprintf() and output to screen%@NL@%
- %@AB@% * using PrintAt.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Parms: iRow - Row at which to begin display%@NL@%
- %@AB@% * iCol - Column at which to begin display%@NL@%
- %@AB@% * szFmt - Format string (see run-time library documentation for%@NL@%
- %@AB@% * correct formation of a format string)%@NL@%
- %@AB@% * ... - Variables to output%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void SprintAt( int iRow, int iCol, char * szFmt, ... )%@NL@%
- {%@NL@%
- char szTmp[81];%@NL@%
- va_list Marker;%@NL@%
- va_list saveMarker;%@NL@%
- %@NL@%
- va_start( Marker, szFmt );%@NL@%
- saveMarker = Marker;%@NL@%
- vsprintf( szTmp, szFmt, Marker );%@NL@%
- va_end( Marker );%@NL@%
- %@NL@%
- PrintAt( iRow, iCol, szTmp, -1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* WrtForm - Displays screen form.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: yBot - Row number of the bottom row%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void WrtForm( int yBot )%@NL@%
- {%@NL@%
- int i;%@NL@%
- char szTmp[81];%@NL@%
- %@NL@%
- %@AB@%/* Print message in upper right. */%@AE@%%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- PrintAt( 1, 55, "Presentation Graphics Demo", co.TitleColor );%@NL@%
- %@NL@%
- %@AB@%/* Clear the top separator line. */%@AE@%%@NL@%
- memset( szTmp, ' ', 79 );%@NL@%
- szTmp[79] = 0;%@NL@%
- %@NL@%
- %@AB@%/* Display each level of the menu title. */%@AE@%%@NL@%
- _settextposition( 5, 5 );%@NL@%
- for( i = 0; i < cMenuLevel; i++ )%@NL@%
- {%@NL@%
- if( i )%@NL@%
- _outtext( " - " );%@NL@%
- _outtext( szMenuTitles[i] );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Display the top separator line. */%@AE@%%@NL@%
- memset( szTmp, 196, 80 );%@NL@%
- szTmp[80] = 0;%@NL@%
- PrintAt( 6, 1, szTmp, co.FormColor );%@NL@%
- %@NL@%
- %@AB@%/* Display the bottom separator line. */%@AE@%%@NL@%
- PrintAt( yBot, 1, szTmp, co.FormColor );%@NL@%
- %@NL@%
- %@AB@%/* Set the global screen variables. */%@AE@%%@NL@%
- %@NL@%
- si.help = yBot + 1;%@NL@%
- si.top = 7;%@NL@%
- si.bot = yBot - 1;%@NL@%
- si.mid = (si.top + si.bot) / 2;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GRDEMO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\GRDEMO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GRDEMO.C - Demonstrates capabilities of the Microsoft graphics library.%@NL@%
- %@AB@% * Uses MENU module to display menus. Uses TURTLE module for Turtle%@NL@%
- %@AB@% * graphics. This program runs only in DOS and requires GRAPHICS.LIB.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%"turtle.h" %@NL@%
- %@AI@%#include %@AE@%"menu.h" %@NL@%
- %@NL@%
- %@AB@%/* Function prototypes */%@AE@%%@NL@%
- int main( void );%@NL@%
- void Circles( void );%@NL@%
- void Sphere( void );%@NL@%
- int Polygons( void );%@NL@%
- int Spiral( int angle, double inc );%@NL@%
- int InSpiral( double side, int angle, int inc );%@NL@%
- void Bug( void );%@NL@%
- void Adjust( void );%@NL@%
- void Diamond( double xy );%@NL@%
- %@NL@%
- %@AB@%/* Returns a random number between min and max, which must be in%@NL@%
- %@AB@% * integer range.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min)) %@NL@%
- %@NL@%
- %@AB@%/* Constants */%@AE@%%@NL@%
- %@AI@%#define %@AE@%PI 3.141593 %@NL@%
- %@AI@%#define %@AE@%LASTATR 15 %@NL@%
- %@AI@%#define %@AE@%NLASTATR 14 %@NL@%
- %@NL@%
- %@AB@%/* Array and enum for main menu */%@AE@%%@NL@%
- ITEM mnuMain[] =%@NL@%
- { %@AB@%/* Highlight Char Pos */%@AE@%%@NL@%
- { 0, "Quit" }, %@AB@%/* Q 0 */%@AE@%%@NL@%
- { 0, "Circles" }, %@AB@%/* C 0 */%@AE@%%@NL@%
- { 0, "Rotating Sphere" }, %@AB@%/* R 0 */%@AE@%%@NL@%
- { 0, "Tunnel" }, %@AB@%/* T 0 */%@AE@%%@NL@%
- { 0, "Spiral" }, %@AB@%/* S 0 */%@AE@%%@NL@%
- { 0, "Inverted Spiral" }, %@AB@%/* I 0 */%@AE@%%@NL@%
- { 0, "Bug" }, %@AB@%/* B 0 */%@AE@%%@NL@%
- { 0, "Adjust Window" }, %@AB@%/* A 0 */%@AE@%%@NL@%
- { 0, "Mode Change" }, %@AB@%/* M 0 */%@AE@%%@NL@%
- { 0, "" }%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/* Define constants (0, 1, 2,...) for menu choices */%@AE@%%@NL@%
- enum CHOICES%@NL@%
- {%@NL@%
- QUIT, CIRCLES, SPHERE, TUNNEL, SPIRAL, INSPIRAL, BUG, ADJUST, CHANGE%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/* Arrays of video mode menu items and of corresponding mode numbers.%@NL@%
- %@AB@% * Each has a temporary array containing all items, and a pointer version%@NL@%
- %@AB@% * including all except Olivetti.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ITEM mnuModesT[] =%@NL@%
- { %@AB@%/* Highlight Char Pos */%@AE@%%@NL@%
- { 0, "ORESCOLOR " }, %@AB@%/* O 0 */%@AE@%%@NL@%
- { 4, "MRES4COLOR " }, %@AB@%/* 4 4 */%@AE@%%@NL@%
- { 4, "MRESNOCOLOR" }, %@AB@%/* N 4 */%@AE@%%@NL@%
- { 4, "HRESBW" }, %@AB@%/* B 4 */%@AE@%%@NL@%
- { 0, "MRES16COLOR" }, %@AB@%/* M 0 */%@AE@%%@NL@%
- { 0, "HRES16COLOR" }, %@AB@%/* H 0 */%@AE@%%@NL@%
- { 0, "ERESCOLOR" }, %@AB@%/* E 0 */%@AE@%%@NL@%
- { 4, "VRES2COLOR" }, %@AB@%/* 2 4 */%@AE@%%@NL@%
- { 0, "VRES16COLOR" }, %@AB@%/* V 0 */%@AE@%%@NL@%
- { 1, "MRES256COLOR" }, %@AB@%/* R 4 */%@AE@%%@NL@%
- { 0, "" }%@NL@%
- };%@NL@%
- ITEM *mnuModes = &mnuModesT[1]; %@AB@%/* Default is no Olivetti mode */%@AE@%%@NL@%
- %@NL@%
- int aModesT[] =%@NL@%
- {%@NL@%
- _ORESCOLOR,%@NL@%
- _MRES4COLOR,%@NL@%
- _MRESNOCOLOR,%@NL@%
- _HRESBW,%@NL@%
- _MRES16COLOR,%@NL@%
- _HRES16COLOR,%@NL@%
- _ERESCOLOR,%@NL@%
- _VRES2COLOR,%@NL@%
- _VRES16COLOR,%@NL@%
- _MRES256COLOR,%@NL@%
- _TEXTMONO,%@NL@%
- _ERESNOCOLOR,%@NL@%
- _HERCMONO%@NL@%
- };%@NL@%
- int *aModes = &aModesT[1]; %@AB@%/* Default is no Olivetti mode */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Global video configuration */%@AE@%%@NL@%
- struct videoconfig vc;%@NL@%
- %@NL@%
- int main()%@NL@%
- {%@NL@%
- int rowMid, colMid;%@NL@%
- int fColor, fFirstTime = TRUE;%@NL@%
- int iMode, iMainCur = 0, iModesCur = 0;%@NL@%
- %@NL@%
- _displaycursor( _GCURSOROFF );%@NL@%
- _getvideoconfig( &vc );%@NL@%
- rowMid = vc.numtextrows / 2;%@NL@%
- colMid = vc.numtextcols / 2;%@NL@%
- %@NL@%
- %@AB@%/* Select best graphics mode, adjust menus, set color flag. Note%@NL@%
- %@AB@% * that this requires checking both the adapter and the mode.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch( vc.adapter )%@NL@%
- {%@NL@%
- case _OCGA:%@NL@%
- mnuModes = &mnuModesT[0]; %@AB@%/* Turn on Olivetti mode */%@AE@%%@NL@%
- aModes = &aModesT[0];%@NL@%
- case _CGA:%@NL@%
- mnuModesT[4].achItem[0] = '\0'; %@AB@%/* Turn off EGA modes */%@AE@%%@NL@%
- iMode = _MRES4COLOR;%@NL@%
- break;%@NL@%
- case _HGC:%@NL@%
- mnuModesT[7].achItem[0] = '\0';%@NL@%
- iMode = _HERCMONO;%@NL@%
- break;%@NL@%
- case _OEGA:%@NL@%
- mnuModes = &mnuModesT[0]; %@AB@%/* Turn on Olivetti mode */%@AE@%%@NL@%
- aModes = &aModesT[0];%@NL@%
- case _EGA:%@NL@%
- mnuModesT[7].achItem[0] = '\0'; %@AB@%/* Turn off VGA modes */%@AE@%%@NL@%
- if( vc.memory > 64 )%@NL@%
- iMode = _ERESCOLOR;%@NL@%
- else%@NL@%
- iMode = _HRES16COLOR;%@NL@%
- break;%@NL@%
- case _OVGA:%@NL@%
- mnuModes = &mnuModesT[0]; %@AB@%/* Turn on Olivetti mode */%@AE@%%@NL@%
- aModes = &aModesT[0];%@NL@%
- case _VGA:%@NL@%
- iMode = _VRES16COLOR;%@NL@%
- break;%@NL@%
- case _MCGA:%@NL@%
- iMode = _MRES256COLOR;%@NL@%
- break;%@NL@%
- case _MDPA:%@NL@%
- default:%@NL@%
- puts( "No graphics mode available.\n" );%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- switch( vc.mode )%@NL@%
- {%@NL@%
- case _TEXTBW80:%@NL@%
- case _TEXTBW40:%@NL@%
- fColor = FALSE;%@NL@%
- break;%@NL@%
- case _TEXTMONO:%@NL@%
- case _ERESNOCOLOR:%@NL@%
- case _HERCMONO:%@NL@%
- fColor = FALSE;%@NL@%
- if( iMode != _HERCMONO )%@NL@%
- iMode = _ERESNOCOLOR;%@NL@%
- mnuMain[8].achItem[0] = '\0'; %@AB@%/* Turn off mode change */%@AE@%%@NL@%
- break;%@NL@%
- default:%@NL@%
- fColor = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Find current mode in mode array. */%@AE@%%@NL@%
- for( iModesCur = 0; aModes[iModesCur] != iMode; iModesCur++ )%@NL@%
- ;%@NL@%
- %@NL@%
- %@AB@%/* Seed randomizer with time. */%@AE@%%@NL@%
- srand( (unsigned)time( NULL ) );%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Set text mode and optionally clear the screen to blue. */%@AE@%%@NL@%
- _setvideomode(_DEFAULTMODE );%@NL@%
- if( fColor )%@NL@%
- _setbkcolor( (long)_TBLUE );%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- %@AB@%/* Select from menu. */%@AE@%%@NL@%
- iMainCur = Menu( rowMid, colMid, mnuMain, iMainCur );%@NL@%
- %@NL@%
- %@AB@%/* Set graphics mode and initialize turtle graphics. Put border%@NL@%
- %@AB@% * on window.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( iMainCur != CHANGE )%@NL@%
- {%@NL@%
- _setvideomode( iMode );%@NL@%
- _displaycursor( _GCURSOROFF );%@NL@%
- _getvideoconfig( &vc );%@NL@%
- InitTurtle( &vc );%@NL@%
- Rectangle( 2 * tc.xMax, 2 * tc.yMax );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Branch to menu choice. */%@AE@%%@NL@%
- switch( iMainCur )%@NL@%
- {%@NL@%
- case QUIT:%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- return FALSE;%@NL@%
- case CIRCLES:%@NL@%
- Circles();%@NL@%
- break;%@NL@%
- case SPHERE:%@NL@%
- Sphere();%@NL@%
- break;%@NL@%
- case TUNNEL:%@NL@%
- PenDown( FALSE );%@NL@%
- MoveTo( -tc.xMax * .2, tc.yMax * .15 );%@NL@%
- PenDown( TRUE );%@NL@%
- Polygons();%@NL@%
- while( !GetKey( NO_WAIT ) )%@NL@%
- NextColorValue( DEFAULT ); %@AB@%/* Rotate palette */%@AE@%%@NL@%
- break;%@NL@%
- case SPIRAL:%@NL@%
- if( Spiral( getrandom( 30, 80 ), (double)getrandom( 1, 5 ) ) )%@NL@%
- break;%@NL@%
- while( !GetKey( NO_WAIT ) )%@NL@%
- NextColorValue( DEFAULT );%@NL@%
- break;%@NL@%
- case INSPIRAL:%@NL@%
- NextColorIndex( 0 );%@NL@%
- if( InSpiral( (double)getrandom( 8, 20 ),%@NL@%
- getrandom( 4, 22 ),%@NL@%
- getrandom( 3, 31 ) ) )%@NL@%
- break;%@NL@%
- while( !GetKey( NO_WAIT ) )%@NL@%
- NextColorValue( DEFAULT );%@NL@%
- break;%@NL@%
- case BUG:%@NL@%
- Bug();%@NL@%
- break;%@NL@%
- case ADJUST:%@NL@%
- Adjust();%@NL@%
- continue;%@NL@%
- case CHANGE:%@NL@%
- if( fColor )%@NL@%
- _setbkcolor( (long)_TBLUE );%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- %@NL@%
- iModesCur = Menu( rowMid, colMid, mnuModes, iModesCur );%@NL@%
- iMode = aModes[iModesCur];%@NL@%
- if( vc.adapter == _MCGA )%@NL@%
- switch( iMode )%@NL@%
- {%@NL@%
- case _MRES16COLOR:%@NL@%
- case _HRES16COLOR:%@NL@%
- case _ERESCOLOR:%@NL@%
- case _VRES16COLOR:%@NL@%
- _settextposition( 1, 22 );%@NL@%
- _outtext( "Mode not recognized" );%@NL@%
- iMode = _MRES256COLOR;%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Circles - Draw circles of varying sizes and colors on screen in a%@NL@%
- %@AB@% * round pattern.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Circles()%@NL@%
- {%@NL@%
- double x, y, xyRadius;%@NL@%
- int fFill, fPenDown;%@NL@%
- %@NL@%
- %@AB@%/* Initialize and save pen and fill flags. */%@AE@%%@NL@%
- if( tc.cci <= 4 )%@NL@%
- fFill = SetFill( FALSE );%@NL@%
- else%@NL@%
- fFill = SetFill( TRUE );%@NL@%
- fPenDown = PenDown( FALSE );%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Draw circles. */%@AE@%%@NL@%
- for( xyRadius = 10.0; xyRadius <= 130.0; xyRadius++ )%@NL@%
- {%@NL@%
- x = (tc.xMax - 30) * atan( sin( xyRadius / PI ) );%@NL@%
- y = (tc.yMax - 30) * atan( cos( xyRadius / PI ) );%@NL@%
- MoveTo( x, y );%@NL@%
- PenColor( NextColorIndex( DEFAULT ) );%@NL@%
- Circle( xyRadius );%@NL@%
- if( GetKey( NO_WAIT ) )%@NL@%
- {%@NL@%
- PenDown( fPenDown );%@NL@%
- SetFill( fFill );%@NL@%
- return;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* For palette modes (except 256 color), start over. */%@AE@%%@NL@%
- if( tc.ccv == 64 || tc.ccv == 16 )%@NL@%
- {%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- SetFill( FALSE );%@NL@%
- MoveTo( 0.0, 0.0 );%@NL@%
- PenColor( WHITE );%@NL@%
- Rectangle( 2 * tc.xMax, 2 * tc.yMax );%@NL@%
- SetFill( fFill );%@NL@%
- NextColorValue( DEFAULT );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Sphere - Draw and fill slices of a sphere. Rotate colors in EGA+ modes%@NL@%
- %@AB@% * with more than 4 color indexes.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Sphere()%@NL@%
- {%@NL@%
- double xCur, xSize, ySize, xInc;%@NL@%
- short ciBorder, fFill;%@NL@%
- %@NL@%
- ySize = xSize = tc.yMax * 0.9 * 2;%@NL@%
- fFill = SetFill( FALSE );%@NL@%
- NextColorIndex( 0 );%@NL@%
- xInc = xSize / 14;%@NL@%
- ciBorder = PenColor( DEFAULT );%@NL@%
- BorderColor( ciBorder );%@NL@%
- %@NL@%
- %@AB@%/* Draw slices. */%@AE@%%@NL@%
- for( xCur = xInc; xCur <= xSize; xCur += xInc * 2 )%@NL@%
- Ellipse( xCur, ySize );%@NL@%
- SetFill( TRUE );%@NL@%
- PenDown( FALSE );%@NL@%
- Turn( 90 );%@NL@%
- xSize /= 2;%@NL@%
- MoveTo( xSize - xInc, 0.0 );%@NL@%
- %@NL@%
- NextColorValue( LIMITED );%@NL@%
- %@NL@%
- %@AB@%/* Fill slices. */%@AE@%%@NL@%
- while( tc.xCur >= (-xSize + xInc))%@NL@%
- {%@NL@%
- PenColor( NextColorIndex( DEFAULT ) );%@NL@%
- FillIn();%@NL@%
- Move( -xInc );%@NL@%
- }%@NL@%
- %@NL@%
- while( !GetKey( NO_WAIT ) )%@NL@%
- NextColorValue( LIMITED );%@NL@%
- %@NL@%
- PenDown( TRUE );%@NL@%
- SetFill( fFill );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Polygons - Draws polygons (starting with triangle) of increasing%@NL@%
- %@AB@% * size by incrementing the number of sides without changing the%@NL@%
- %@AB@% * length of sides. Make sure pen is down.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 1 for user interrupt, 0 for edge of screen encountered%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Polygons()%@NL@%
- {%@NL@%
- int cSides = 3, atrib = 1;%@NL@%
- double dxy = tc.yUnit;%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- PenColor( NextColorIndex( DEFAULT ) );%@NL@%
- if( !Poly( cSides++, dxy += 1.5 ) )%@NL@%
- return FALSE;%@NL@%
- if( GetKey( NO_WAIT ) )%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Spiral - Draw a spiral by incrementing the length of each side%@NL@%
- %@AB@% * of a rotating figure.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: ang - determines tightness%@NL@%
- %@AB@% * xyInc - determines size of sides%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 1 for user interrupt, 0 for edge of screen encountered%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Spiral( int ang, double xyInc )%@NL@%
- {%@NL@%
- double xy = tc.yUnit;%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- PenColor( NextColorIndex( DEFAULT ) );%@NL@%
- if( !Move( xy += xyInc ) )%@NL@%
- return FALSE;%@NL@%
- Turn( ang );%@NL@%
- if( GetKey( NO_WAIT ) )%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* InSpiral - Draw an inverted spiral by increasing each angle%@NL@%
- %@AB@% * of a rotating figure while keeping the length of sides constant.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: xy - determines size%@NL@%
- %@AB@% * ang - initial angle determines shape%@NL@%
- %@AB@% * angInc - determines tightness and shape%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 1 for user interrupt, 0 for edge of screen encountered%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int InSpiral( double xy, int ang, int angInc )%@NL@%
- {%@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- PenColor( NextColorIndex( DEFAULT ) );%@NL@%
- if( !Move( xy ) )%@NL@%
- return FALSE;%@NL@%
- Turn( ang += angInc );%@NL@%
- if( GetKey( NO_WAIT ))%@NL@%
- return TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Bug - Draws a winged bug on the screen. Then moves it randomly%@NL@%
- %@AB@% * around the screen.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Bug()%@NL@%
- {%@NL@%
- %@NL@%
- static unsigned char uTopWing[] = { 0x81, 0x3c, 0xc3, 0x66,%@NL@%
- 0x66, 0x0f, 0xf0, 0x18 };%@NL@%
- static unsigned char uBotWing[] = { 0x66, 0x0f, 0xf0, 0x18,%@NL@%
- 0x81, 0x3c, 0xc3, 0x66 };%@NL@%
- char *buffer; %@AB@%/* Buffer for image */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Draw bug. */%@AE@%%@NL@%
- PenDown( FALSE );%@NL@%
- SetFill( TRUE );%@NL@%
- Move( 40.0 ); %@AB@%/* Draw and fill front wings */%@AE@%%@NL@%
- Turn( 90 );%@NL@%
- Move( 80.0 );%@NL@%
- PenColor( 1 );%@NL@%
- _setfillmask( uTopWing );%@NL@%
- Ellipse( 172.0, 70.0 );%@NL@%
- Turn( 180 );%@NL@%
- Move( 160.0 );%@NL@%
- Ellipse( 172.0, 70.0 );%@NL@%
- Turn(-90 );%@NL@%
- MoveTo( 0.0, 0.0 );%@NL@%
- Move( 25.0 ); %@AB@%/* Draw and fill back wings */%@AE@%%@NL@%
- Turn( 90 );%@NL@%
- Move( 70.0 );%@NL@%
- PenColor( 2 );%@NL@%
- _setfillmask( uBotWing );%@NL@%
- Ellipse( 150.0, 70.0 );%@NL@%
- Turn( 180 );%@NL@%
- Move( 140.0 );%@NL@%
- Ellipse( 150.0, 70.0 );%@NL@%
- Turn(-90 );%@NL@%
- MoveTo( 0.0, 0.0 );%@NL@%
- _setfillmask( NULL ); %@AB@%/* Draw body */%@AE@%%@NL@%
- PenColor( 3 );%@NL@%
- BorderColor( 3 );%@NL@%
- Ellipse( 52.0, 220.0 );%@NL@%
- PenColor( 1 ); %@AB@%/* Drill eyes */%@AE@%%@NL@%
- BorderColor( 1 );%@NL@%
- SetFill( FALSE );%@NL@%
- Move( 90.0 );%@NL@%
- Turn( 90 );%@NL@%
- Move( 22.0 );%@NL@%
- Circle( 20.0 );%@NL@%
- PenColor( 0 );%@NL@%
- FillIn();%@NL@%
- PenColor( 1 );%@NL@%
- Turn( 180 );%@NL@%
- Move( 44.0 );%@NL@%
- Circle( 20.0 );%@NL@%
- PenColor( 0 );%@NL@%
- FillIn();%@NL@%
- %@NL@%
- %@AB@%/* Move into position - top-right of image. */%@AE@%%@NL@%
- MoveTo( 0.0, 0.0 );%@NL@%
- TurnTo( 0 );%@NL@%
- Move( 120.0 );%@NL@%
- Turn( -90 );%@NL@%
- Move( 175.0 );%@NL@%
- Turn( 90 );%@NL@%
- %@NL@%
- %@AB@%/* Size image and allocate memory for it. */%@AE@%%@NL@%
- buffer = (char *)malloc( (size_t)ImageSize( 350.0, 240.0 ) );%@NL@%
- GetImage( 350.0, 240.0, buffer );%@NL@%
- %@NL@%
- %@AB@%/* Move randomly, adjusting at edges. */%@AE@%%@NL@%
- while( !GetKey( NO_WAIT ) )%@NL@%
- {%@NL@%
- if( tc.xCur <= (-tc.xMax + 15.0) )%@NL@%
- TurnTo( 90 );%@NL@%
- else if( tc.yCur <= (-tc.yMax + 15.0) )%@NL@%
- TurnTo( 180 );%@NL@%
- else if( tc.xCur >= (tc.xMax - 365.0) )%@NL@%
- TurnTo( 270 );%@NL@%
- else if( tc.yCur >= (tc.yMax - 255.0) )%@NL@%
- TurnTo( 0 );%@NL@%
- else%@NL@%
- Turn( getrandom( -20, 20 ) );%@NL@%
- Move( 3.0 );%@NL@%
- PutImage( buffer, _GPSET );%@NL@%
- }%@NL@%
- free( (char *)buffer );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Adjust - Allow the user to interactively adjust the display window.%@NL@%
- %@AB@% * Unshifted direction keys adjust the window size. Shifted direction%@NL@%
- %@AB@% * keys move the window. The numeric keypad plus and minus keys adjust%@NL@%
- %@AB@% * aspect without changing the window. A window frame and a diamond give%@NL@%
- %@AB@% * visual feedback on adjustments.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc and vc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%WININC 4 %@NL@%
- void Adjust()%@NL@%
- {%@NL@%
- short iWriteMode;%@NL@%
- double xyRadius = 400.0, xEdge, yEdge;%@NL@%
- char achT[40];%@NL@%
- %@NL@%
- %@AB@%/* Display instructions. */%@AE@%%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _settextposition( 2, 2 );%@NL@%
- _outtext(" Grey PLUS and MINUS Adjust aspect" );%@NL@%
- _settextposition( 3, 2 );%@NL@%
- _outtext(" Cursor keys Size window" );%@NL@%
- _settextposition( 4, 2 );%@NL@%
- _outtext(" SHIFT cursor keys Move window" );%@NL@%
- _settextposition( 5, 2 );%@NL@%
- _outtext(" ENTER Finished" );%@NL@%
- %@NL@%
- %@AB@%/* Save old write mode and set XOR so you can erase figures by%@NL@%
- %@AB@% * redrawing. This allows lines to overwrite text without erasing.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- iWriteMode = _getwritemode();%@NL@%
- _setwritemode( _GXOR );%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Display data. */%@AE@%%@NL@%
- _settextposition( 6, 2 );%@NL@%
- sprintf( achT, " ratio=%1.2f xMax=%.f yMax=%.f",%@NL@%
- tc.yxRatio, tc.xMax, tc.yMax );%@NL@%
- _outtext( achT );%@NL@%
- %@NL@%
- %@AB@%/* Calculate current box edges. */%@AE@%%@NL@%
- xEdge = 2 * tc.xMax;%@NL@%
- yEdge = 2 * tc.yMax;%@NL@%
- %@NL@%
- %@AB@%/* Draw border rectangle and diamond that illustrates ratio. */%@AE@%%@NL@%
- Rectangle( xEdge, yEdge );%@NL@%
- Diamond( xyRadius );%@NL@%
- %@NL@%
- switch( GetKey( CLEAR_WAIT ) )%@NL@%
- {%@NL@%
- %@AB@%/* Adjust aspect. */%@AE@%%@NL@%
- case N_MINUS:%@NL@%
- if( tc.yxRatio > 0.4 )%@NL@%
- tc.yxRatio = (tc.xMax - (WININC * tc.yUnit)) / tc.yMax;%@NL@%
- break;%@NL@%
- %@NL@%
- case N_PLUS:%@NL@%
- if( tc.yxRatio < 8.0 )%@NL@%
- tc.yxRatio = (tc.xMax + (WININC * tc.yUnit)) / tc.yMax;%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* Adjust window size. */%@AE@%%@NL@%
- case U_RT:%@NL@%
- if( tc.xsLeft < (vc.numxpixels / 3) )%@NL@%
- tc.xsLeft += WININC;%@NL@%
- if( tc.xsRight > (vc.numxpixels - (vc.numxpixels / 3)) )%@NL@%
- tc.xsRight -= WININC;%@NL@%
- break;%@NL@%
- case U_LT:%@NL@%
- if( tc.xsLeft )%@NL@%
- tc.xsLeft -= WININC;%@NL@%
- if( tc.xsRight < vc.numxpixels )%@NL@%
- tc.xsRight += WININC;%@NL@%
- break;%@NL@%
- case U_DN:%@NL@%
- if( tc.ysTop < (vc.numypixels / 3) )%@NL@%
- tc.ysTop += WININC;%@NL@%
- if( tc.ysBot > (vc.numypixels - (vc.numypixels / 3)) )%@NL@%
- tc.ysBot -= WININC;%@NL@%
- break;%@NL@%
- case U_UP:%@NL@%
- if( tc.ysTop )%@NL@%
- tc.ysTop -= WININC;%@NL@%
- if( tc.ysBot < vc.numypixels )%@NL@%
- tc.ysBot += WININC;%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* Adjust window position. */%@AE@%%@NL@%
- case S_LT:%@NL@%
- if( tc.xsLeft )%@NL@%
- {%@NL@%
- tc.xsLeft -= WININC;%@NL@%
- tc.xsRight -= WININC;%@NL@%
- }%@NL@%
- break;%@NL@%
- case S_RT:%@NL@%
- if( tc.xsRight < vc.numxpixels )%@NL@%
- {%@NL@%
- tc.xsLeft += WININC;%@NL@%
- tc.xsRight += WININC;%@NL@%
- }%@NL@%
- break;%@NL@%
- case S_UP:%@NL@%
- if( tc.ysTop )%@NL@%
- {%@NL@%
- tc.ysTop -= WININC;%@NL@%
- tc.ysBot -= WININC;%@NL@%
- }%@NL@%
- break;%@NL@%
- case S_DN:%@NL@%
- if( tc.ysBot < vc.numypixels )%@NL@%
- {%@NL@%
- tc.ysTop += WININC;%@NL@%
- tc.ysBot += WININC;%@NL@%
- }%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* Finished. */%@AE@%%@NL@%
- case ENTER:%@NL@%
- _setwritemode( iWriteMode );%@NL@%
- return;%@NL@%
- %@NL@%
- %@AB@%/* Ignore unknown key. */%@AE@%%@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- %@AB@%/* Redraw figures to erase them. Reset defaults. */%@AE@%%@NL@%
- Rectangle( xEdge, yEdge );%@NL@%
- Diamond( xyRadius );%@NL@%
- Home();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Routine used by Adjust to draw its diamond. */%@AE@%%@NL@%
- void Diamond( double xy )%@NL@%
- {%@NL@%
- PenDown( FALSE );%@NL@%
- MoveTo( 0.0, xy );%@NL@%
- PenDown( TRUE );%@NL@%
- MoveTo( xy, 0.0 );%@NL@%
- MoveTo( 0.0, -xy );%@NL@%
- MoveTo( -xy, 0.0 );%@NL@%
- MoveTo( 0.0, xy );%@NL@%
- PenDown( FALSE );%@NL@%
- MoveTo( 0.0, 0.0 );%@NL@%
- PenDown( TRUE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MENU.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\MENU.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MENU - Module of functions to put menus on the screen and handle keyboard%@NL@%
- %@AB@% * input. To use it, include the MENU.H file in your program. The following%@NL@%
- %@AB@% * functions are public:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Menu - Puts a menu on screen and reads input for it%@NL@%
- %@AB@% * Box - Puts a box on screen (fill it yourself)%@NL@%
- %@AB@% * GetKey - Gets ASCII or function key%@NL@%
- %@AB@% * _outchar - Displays character using current text position and color%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The following structures are defined:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * MENU - Defines menu colors, box type, and centering%@NL@%
- %@AB@% * ITEM - Defines text of menu item and index of highlight character%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The global variable "mnuAtrib" has type MENU. Change this variable to%@NL@%
- %@AB@% * change menu appearance.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stddef.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@AI@%#include %@AE@%"menu.h" %@NL@%
- %@NL@%
- %@AB@%/* Prototype for internal function */%@AE@%%@NL@%
- static void Itemize( int row, int col, int fCur, ITEM itm, int cBlank );%@NL@%
- %@NL@%
- %@AB@%/* Default menu attribute. The default works for color or B&W. You can%@NL@%
- %@AB@% * override the default value by defining your own MENU variable and%@NL@%
- %@AB@% * assigning it to mnuAtrib, or you can modify specific fields at%@NL@%
- %@AB@% * run time. For example, you could use a different attribute for color%@NL@%
- %@AB@% * than for black and white.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- MENU mnuAtrib =%@NL@%
- {%@NL@%
- _TBLACK, _TBLACK, _TWHITE, _TBRIGHTWHITE, _TBRIGHTWHITE,%@NL@%
- _TWHITE, _TWHITE, _TBLACK, _TWHITE, _TBLACK,%@NL@%
- TRUE,%@NL@%
- '┌', '┐', '┘', '└', '│', '─'%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/* Menu - Puts menu on screen and reads menu input from keyboard. When a%@NL@%
- %@AB@% * highlighted hot key or ENTER is pressed, returns the index of the%@NL@%
- %@AB@% * selected menu item.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row and col - If "fCentered" attribute of "mnuAtrib" is true,%@NL@%
- %@AB@% * center row and column of menu; otherwise top left of menu%@NL@%
- %@AB@% * aItem - array of structure containing the text of each item%@NL@%
- %@AB@% * and the index of the highlighted hot key%@NL@%
- %@AB@% * iCur - index of the current selection--pass 0 for first item,%@NL@%
- %@AB@% * or maintain a static value%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: The index of the selected item%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: mnuAtrib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Menu( int row, int col, ITEM aItem[], int iCur )%@NL@%
- {%@NL@%
- int cItem, cchItem = 2; %@AB@%/* Counts of items and chars per item */%@AE@%%@NL@%
- int i, iPrev; %@AB@%/* Indexes - temporary and previous */%@AE@%%@NL@%
- int acchItem[MAXITEM]; %@AB@%/* Array of counts of character in items */%@AE@%%@NL@%
- char *pchT; %@AB@%/* Temporary character pointer */%@AE@%%@NL@%
- char achHilite[36]; %@AB@%/* Array for highlight characters */%@AE@%%@NL@%
- unsigned uKey; %@AB@%/* Unsigned key code */%@AE@%%@NL@%
- long bgColor; %@AB@%/* Screen color, position, and cursor */%@AE@%%@NL@%
- short fgColor;%@NL@%
- struct rccoord rc;%@NL@%
- unsigned fCursor;%@NL@%
- %@NL@%
- %@AB@%/* Save screen information. */%@AE@%%@NL@%
- fCursor = _displaycursor( _GCURSOROFF );%@NL@%
- bgColor = _getbkcolor();%@NL@%
- fgColor = _gettextcolor();%@NL@%
- rc = _gettextposition();%@NL@%
- %@NL@%
- %@AB@%/* Count items, find longest, and put count of each in array. Also,%@NL@%
- %@AB@% * put the highlighted character from each in a string.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for( cItem = 0; aItem[cItem].achItem[0]; cItem++ )%@NL@%
- {%@NL@%
- acchItem[cItem] = strlen( aItem[cItem].achItem );%@NL@%
- cchItem = (acchItem[cItem] > cchItem) ? acchItem[cItem] : cchItem;%@NL@%
- i = aItem[cItem].iHilite;%@NL@%
- achHilite[cItem] = aItem[cItem].achItem[i];%@NL@%
- }%@NL@%
- cchItem += 2;%@NL@%
- achHilite[cItem] = 0; %@AB@%/* Null-terminate and lowercase string */%@AE@%%@NL@%
- strlwr( achHilite );%@NL@%
- %@NL@%
- %@AB@%/* Adjust if centered, and draw menu box. */%@AE@%%@NL@%
- if( mnuAtrib.fCentered )%@NL@%
- {%@NL@%
- row -= cItem / 2;%@NL@%
- col -= cchItem / 2;%@NL@%
- }%@NL@%
- Box( row++, col++, cItem, cchItem );%@NL@%
- %@NL@%
- %@AB@%/* Put items on menu. */%@AE@%%@NL@%
- for( i = 0; i < cItem; i++ )%@NL@%
- {%@NL@%
- if( i == iCur )%@NL@%
- Itemize( row + i, col, TRUE, aItem[i], cchItem - acchItem[i] );%@NL@%
- else%@NL@%
- Itemize( row + i, col, FALSE, aItem[i], cchItem - acchItem[i] );%@NL@%
- }%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Wait until a uKey is pressed, then evaluate it. */%@AE@%%@NL@%
- uKey = GetKey( WAIT );%@NL@%
- switch( uKey )%@NL@%
- {%@NL@%
- case U_UP: %@AB@%/* Up key */%@AE@%%@NL@%
- iPrev = iCur;%@NL@%
- iCur = (iCur > 0) ? (--iCur % cItem) : cItem - 1;%@NL@%
- break;%@NL@%
- case U_DN: %@AB@%/* Down key */%@AE@%%@NL@%
- iPrev = iCur;%@NL@%
- iCur = (iCur < cItem) ? (++iCur % cItem) : 0;%@NL@%
- break;%@NL@%
- default:%@NL@%
- if( uKey > 256 ) %@AB@%/* Ignore unknown function key */%@AE@%%@NL@%
- continue;%@NL@%
- pchT = strchr( achHilite, (char)tolower( uKey ) );%@NL@%
- if( pchT != NULL ) %@AB@%/* If in highlight string, */%@AE@%%@NL@%
- iCur = pchT - achHilite;%@AB@%/* evaluate and fall through */%@AE@%%@NL@%
- else%@NL@%
- continue; %@AB@%/* Ignore unknown ASCII key */%@AE@%%@NL@%
- case ENTER:%@NL@%
- _setbkcolor( bgColor );%@NL@%
- _settextcolor( fgColor );%@NL@%
- _settextposition( rc.row, rc.col );%@NL@%
- _displaycursor( fCursor );%@NL@%
- return iCur;%@NL@%
- }%@NL@%
- %@AB@%/* Redisplay current and previous. */%@AE@%%@NL@%
- Itemize( row + iCur, col,%@NL@%
- TRUE, aItem[iCur], cchItem - acchItem[iCur] );%@NL@%
- Itemize( row + iPrev, col,%@NL@%
- FALSE, aItem[iPrev], cchItem - acchItem[iPrev] );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Box - Draw menu box, filling interior with blanks of the border color.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row and col - upper left of box%@NL@%
- %@AB@% * rowLast and colLast - height and width%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: mnuAtrib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Box( int row, int col, int rowLast, int colLast )%@NL@%
- {%@NL@%
- int i;%@NL@%
- char achT[MAXITEM + 2]; %@AB@%/* Temporary array of characters */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Set color and position. */%@AE@%%@NL@%
- _settextposition( row, col );%@NL@%
- _settextcolor( mnuAtrib.fgBorder );%@NL@%
- _setbkcolor( mnuAtrib.bgBorder );%@NL@%
- %@NL@%
- %@AB@%/* Draw box top. */%@AE@%%@NL@%
- achT[0] = mnuAtrib.chNW;%@NL@%
- memset( achT + 1, mnuAtrib.chEW, colLast );%@NL@%
- achT[colLast + 1] = mnuAtrib.chNE;%@NL@%
- achT[colLast + 2] = 0;%@NL@%
- _outtext( achT );%@NL@%
- %@NL@%
- %@AB@%/* Draw box sides and center. */%@AE@%%@NL@%
- achT[0] = mnuAtrib.chNS;%@NL@%
- memset( achT + 1, ' ', colLast );%@NL@%
- achT[colLast + 1] = mnuAtrib.chNS;%@NL@%
- achT[colLast + 2] = 0;%@NL@%
- for( i = 1; i <= rowLast; ++i )%@NL@%
- {%@NL@%
- _settextposition( row + i, col );%@NL@%
- _outtext( achT );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Draw box bottom. */%@AE@%%@NL@%
- _settextposition( row + rowLast + 1, col );%@NL@%
- achT[0] = mnuAtrib.chSW;%@NL@%
- memset( achT + 1, mnuAtrib.chEW, colLast );%@NL@%
- achT[colLast + 1] = mnuAtrib.chSE;%@NL@%
- achT[colLast + 2] = 0;%@NL@%
- _outtext( achT );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Itemize - Display one selection (item) of a menu. This function%@NL@%
- %@AB@% * is normally only used internally by Menu.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row and col - top left of menu%@NL@%
- %@AB@% * fCur - flag set if item is current selection%@NL@%
- %@AB@% * itm - structure containing item text and index of highlight%@NL@%
- %@AB@% * cBlank - count of blanks to fill%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: none%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: mnuAtrib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Itemize( int row, int col, int fCur, ITEM itm, int cBlank )%@NL@%
- {%@NL@%
- int i;%@NL@%
- char achT[MAXITEM]; %@AB@%/* Temporary array of characters */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Set text position and color. */%@AE@%%@NL@%
- _settextposition( row, col );%@NL@%
- if( fCur )%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgSelect );%@NL@%
- _setbkcolor( mnuAtrib.bgSelect );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgNormal );%@NL@%
- _setbkcolor( mnuAtrib.bgNormal );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Display item and fill blanks. */%@AE@%%@NL@%
- strcat( strcpy( achT, " " ), itm.achItem );%@NL@%
- _outtext( achT );%@NL@%
- memset( achT, ' ', cBlank-- );%@NL@%
- achT[cBlank] = 0;%@NL@%
- _outtext( achT );%@NL@%
- %@NL@%
- %@AB@%/* Set position and color of highlight character, then display it. */%@AE@%%@NL@%
- i = itm.iHilite;%@NL@%
- _settextposition( row, col + i + 1 );%@NL@%
- if( fCur )%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgSelHilite );%@NL@%
- _setbkcolor( mnuAtrib.bgSelHilite );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgNormHilite );%@NL@%
- _setbkcolor( mnuAtrib.bgNormHilite );%@NL@%
- }%@NL@%
- _outchar( itm.achItem[i] );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* GetKey - Gets a key from the keyboard. This routine distinguishes%@NL@%
- %@AB@% * between ASCII keys and function or control keys with different shift%@NL@%
- %@AB@% * states. It also accepts a flag to return immediately if no key is%@NL@%
- %@AB@% * available.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: fWait - Code to indicate how to handle keyboard buffer:%@NL@%
- %@AB@% * NO_WAIT Return 0 if no key in buffer, else return key%@NL@%
- %@AB@% * WAIT Return first key if available, else wait for key%@NL@%
- %@AB@% * CLEAR_WAIT Throw away any key in buffer and wait for new key%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: One of the following:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Keytype High Byte Low Byte%@NL@%
- %@AB@% * ------- --------- --------%@NL@%
- %@AB@% * No key available (only with NO_WAIT) 0 0%@NL@%
- %@AB@% * ASCII value 0 ASCII code%@NL@%
- %@AB@% * Unshifted function or keypad 1 scan code%@NL@%
- %@AB@% * Shifted function or keypad 2 scan code%@NL@%
- %@AB@% * CTRL function or keypad 3 scan code%@NL@%
- %@AB@% * ALT function or keypad 4 scan code%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Note: getkey cannot return codes for keys not recognized by BIOS%@NL@%
- %@AB@% * int 16, such as the CTRL-UP or the 5 key on the numeric keypad.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- unsigned GetKey( int fWait )%@NL@%
- {%@NL@%
- unsigned uKey, uShift;%@NL@%
- %@NL@%
- %@AB@%/* If CLEAR_WAIT, drain the keyboard buffer. */%@AE@%%@NL@%
- if( fWait == CLEAR_WAIT )%@NL@%
- while( _bios_keybrd( _KEYBRD_READY ) )%@NL@%
- _bios_keybrd( _KEYBRD_READ );%@NL@%
- %@NL@%
- %@AB@%/* If NO_WAIT, return 0 if there is no key ready. */%@AE@%%@NL@%
- if( !fWait && !_bios_keybrd( _KEYBRD_READY ) )%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Get key code. */%@AE@%%@NL@%
- uKey = _bios_keybrd( _KEYBRD_READ );%@NL@%
- %@NL@%
- %@AB@%/* If low byte is not zero, it's an ASCII key. Check scan code to see%@NL@%
- %@AB@% * if it's on the numeric keypad. If not, clear high byte and return.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( uKey & 0x00ff )%@NL@%
- if( (uKey >> 8) < 69 )%@NL@%
- return( uKey & 0x00ff );%@NL@%
- %@NL@%
- %@AB@%/* For function keys and numeric keypad, put scan code in low byte%@NL@%
- %@AB@% * and shift state codes in high byte.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- uKey >>= 8;%@NL@%
- uShift = _bios_keybrd( _KEYBRD_SHIFTSTATUS ) & 0x000f;%@NL@%
- switch( uShift )%@NL@%
- {%@NL@%
- case 0:%@NL@%
- return( 0x0100 | uKey ); %@AB@%/* None (1) */%@AE@%%@NL@%
- case 1:%@NL@%
- case 2:%@NL@%
- case 3:%@NL@%
- return( 0x0200 | uKey ); %@AB@%/* Shift (2) */%@AE@%%@NL@%
- case 4:%@NL@%
- return( 0x0300 | uKey ); %@AB@%/* Control (3) */%@AE@%%@NL@%
- case 8:%@NL@%
- return( 0x0400 | uKey ); %@AB@%/* Alt (4) */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* _outchar - Display a character. This is the character equivalent of%@NL@%
- %@AB@% * _outtext. It is affected by _settextposition, _settextcolor, and%@NL@%
- %@AB@% * _setbkcolor. It should not be used in loops. Build strings and then%@NL@%
- %@AB@% * _outtext to show multiple characters.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: out - character to be displayed%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: none%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void _outchar( char out )%@NL@%
- {%@NL@%
- static char achT[2] = " "; %@AB@%/* Temporary array of characters */%@AE@%%@NL@%
- %@NL@%
- achT[0] = out;%@NL@%
- _outtext( achT );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SNAP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\SNAP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Snap - An OS/2 screen capture utility%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Snap starts a background process containing a keyboard monitor.%@NL@%
- %@AB@% * The monitor checks for a hot key (ALT-*). If found, a thread is%@NL@%
- %@AB@% * launched to write the screen to a file. Various command line options%@NL@%
- %@AB@% * allow you to specify capture behavior or to deinstall the program.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * To compile, use the following command line:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * cl /MT /G2s snap.c%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Function prototypes */%@AE@%%@NL@%
- int Monitor( void );%@NL@%
- void Snap( unsigned long _far *arg );%@NL@%
- void BackError( char *msgErr );%@NL@%
- void Syntax( void );%@NL@%
- void EvalOptions( int argc, char **argv );%@NL@%
- %@NL@%
- %@AB@%/* Define constants to enable function groups in OS2 include files */%@AE@%%@NL@%
- %@AI@%#define %@AE@%INCL_NOCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_NOPM %@NL@%
- %@AI@%#define %@AE@%INCL_KBD // KBDKEYINFO %@NL@%
- %@AI@%#define %@AE@%INCL_VIO // Vio functions %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMEMMGR // DosGetShrSeg, DosAllocShrSeg, %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMONITORS // DosMon functions %@NL@%
- %@AI@%#define %@AE@%INCL_DOSMISC // DosGetEnv %@NL@%
- %@AI@%#define %@AE@%INCL_DOSSEMAPHORES // DosSem functions %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS // DosBeep, DosSetPrty %@NL@%
- %@AI@%#define %@AE@%INCL_DOSINFOSEG // DosGetInfoSeg %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<malloc.h> // malloc, free %@NL@%
- %@AI@%#include %@AE@%<process.h> // _beginthread, _endthread, exit, spawnl %@NL@%
- %@AI@%#include %@AE@%<string.h> // strcpy, strcat %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> // atoi, itoa, _MAX_PATH %@NL@%
- %@AI@%#include %@AE@%<stddef.h> // _threadid variable %@NL@%
- %@AI@%#include %@AE@%<stdio.h> // puts, fopen, fwrite, etc. %@NL@%
- %@AI@%#include %@AE@%<conio.h> // kbhit %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%CON 0 // Handle for the console device %@NL@%
- %@AI@%#define %@AE@%FAIL -1 // Fail to start thread %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%STAR 0x37 // Scan code for * on numeric keypad %@NL@%
- %@AI@%#define %@AE@%RELEASE 0x40 // Bit mask for key release %@NL@%
- %@NL@%
- %@AB@%/* Name and structure for shared memory data */%@AE@%%@NL@%
- char szShrSeg[] = { "\\SHAREMEM\\SNAP.DAT" };%@NL@%
- struct SHARED%@NL@%
- {%@NL@%
- BOOL fSound; // Sound flag%@NL@%
- BOOL fAppend; // Append flag%@NL@%
- BOOL fInstall; // Install flag%@NL@%
- SHORT cScreen; // Count of screens%@NL@%
- LONG lfWait; // Wait semaphore%@NL@%
- CHAR achSnap[_MAX_PATH]; // Snap file name%@NL@%
- } _far *pshrSnap = 0; // Initialize offset to 0. Segment will%@NL@%
- // be initialized by system call.%@NL@%
- %@NL@%
- %@AB@%/* Count in bytes of shared segment */%@AE@%%@NL@%
- %@AI@%#define %@AE@%C_SHARESEG sizeof( struct SHARED ) %@NL@%
- %@NL@%
- void main( int argc, char **argv )%@NL@%
- {%@NL@%
- USHORT offCmd; // Dummy for DosGetEnv%@NL@%
- CHAR *pchSnapExe = 0; // Pointer to name of executable file%@NL@%
- // (offset initialized to 0)%@NL@%
- %@NL@%
- %@AB@%/* Try to get shared segment (note how selector value is placed%@NL@%
- %@AB@% * directly in the segment word of the pointer address). There are%@NL@%
- %@AB@% * three possibilities:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * - We can't get memory. This means SNAP is not installed,%@NL@%
- %@AB@% * so we must allocate the memory and exec ourself in the%@NL@%
- %@AB@% * background to install the monitor.%@NL@%
- %@AB@% * - We can get memory and we are not installed. This means%@NL@%
- %@AB@% * we have been execed by previous process to install monitor.%@NL@%
- %@AB@% * - We can get memory and we are already installed. This means%@NL@%
- %@AB@% * we were just called to modify options.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( DosGetShrSeg( szShrSeg, (PSEL)&pshrSnap + 1 ) )%@NL@%
- {%@NL@%
- %@AB@%/* Segment doesn't exist, so try to allocate it. */%@AE@%%@NL@%
- if( DosAllocShrSeg( C_SHARESEG, szShrSeg, (PSEL)&pshrSnap + 1 ) )%@NL@%
- {%@NL@%
- puts( "Can't allocate shared memory" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* This is the first time through, so we must execute%@NL@%
- %@AB@% * ourself to do installation. First set defaults, then%@NL@%
- %@AB@% * modify for options.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pshrSnap->fSound = TRUE;%@NL@%
- pshrSnap->fAppend = TRUE;%@NL@%
- pshrSnap->cScreen = 0;%@NL@%
- pshrSnap->fInstall = FALSE;%@NL@%
- strcpy( pshrSnap->achSnap, "SNAP.IMG" );%@NL@%
- DosSemSet( &pshrSnap->lfWait );%@NL@%
- EvalOptions( argc, argv );%@NL@%
- %@NL@%
- %@AB@%/* Get our own path name from the end of the environment%@NL@%
- %@AB@% * segment. This is the most reliable way to get the full%@NL@%
- %@AB@% * path name of the current file, since the extension is%@NL@%
- %@AB@% * ommitted from argv[0].%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosGetEnv( (PUSHORT)&pchSnapExe + 1, &offCmd );%@NL@%
- %@NL@%
- %@AB@%/* Adjust forward until we point to full path of .EXE file. */%@AE@%%@NL@%
- while( *pchSnapExe++ || *pchSnapExe )%@NL@%
- ;%@NL@%
- ++pchSnapExe;%@NL@%
- %@NL@%
- %@AB@%/* Spawn ourself as a background process. Can't install%@NL@%
- %@AB@% * monitor now because we are in foreground. A background%@NL@%
- %@AB@% * process needs to install the monitor.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( spawnl( P_DETACH, pchSnapExe, pchSnapExe, NULL ) == -1 )%@NL@%
- {%@NL@%
- puts( "Can't start background process" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- puts( "Snap installed" );%@NL@%
- Syntax();%@NL@%
- %@NL@%
- %@AB@%/* Wait for background child process to report receiving%@NL@%
- %@AB@% * shared data.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosSemWait( &pshrSnap->lfWait, SEM_INDEFINITE_WAIT );%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* Already installed. We are being run to evaluate options and%@NL@%
- %@AB@% * modify behavior accordingly.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( pshrSnap->fInstall )%@NL@%
- if( argc == 1 )%@NL@%
- puts( "Snap already installed" );%@NL@%
- else%@NL@%
- EvalOptions( argc, argv );%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* Not installed, so we were execed by original SNAP to%@NL@%
- %@AB@% * install monitor. Tell parent we have received data, set%@NL@%
- %@AB@% * install flag, and install monitor.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosSemClear( &pshrSnap->lfWait );%@NL@%
- %@NL@%
- %@AB@%/* Set installed flag and start monitor. */%@AE@%%@NL@%
- pshrSnap->fInstall = TRUE;%@NL@%
- %@NL@%
- exit( Monitor() );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Monitor routine checks keystrokes as they occur and calls%@NL@%
- %@AB@% * the Snap thread if the hot key is pressed.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 1 if error, 0 if deinstalled%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: pshrSnap - Shared memory structure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Monitor()%@NL@%
- {%@NL@%
- #define BUFSIZE 128 // Size for monitor buffers:%@NL@%
- // 64 minimum, 128 recommended%@NL@%
- #define STACKSIZE 2048 // 2K minimum for any system call%@NL@%
- %@NL@%
- PMONIN pmnin;%@NL@%
- PMONOUT pmnout;%@NL@%
- %@NL@%
- struct KEYPACKET // KBD monitor data record%@NL@%
- {%@NL@%
- USHORT fMon;%@NL@%
- KBDKEYINFO kki;%@NL@%
- USHORT fDD;%@NL@%
- } keyBuff;%@NL@%
- USHORT ckeyBuff = sizeof( keyBuff );%@NL@%
- %@NL@%
- HMONITOR hKeyMon; // Keyboard handle from monitor open%@NL@%
- PGINFOSEG pGIS = 0, pLIS = 0; // Information segment structures%@NL@%
- LONG lfSnap = FALSE; // Semaphore for each Snap thread%@NL@%
- %@NL@%
- %@AB@%/* Allocate space for monitor read/write buffers and mark size. */%@AE@%%@NL@%
- pmnin = (PMONIN)malloc( BUFSIZE );%@NL@%
- pmnin->cb = BUFSIZE;%@NL@%
- pmnout = (PMONOUT)malloc( BUFSIZE );%@NL@%
- pmnout->cb = BUFSIZE;%@NL@%
- %@NL@%
- %@AB@%/* Register monitor to the keyboard device (KBD$). */%@AE@%%@NL@%
- if( DosMonOpen( "KBD$", &hKeyMon ) )%@NL@%
- {%@NL@%
- BackError( "Can't open monitor" );%@NL@%
- return 1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Get information segments (all we really need is ID of current%@NL@%
- %@AB@% * screen group from Global Information Segment).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- DosGetInfoSeg( (PSEL)&pGIS + 1, (PSEL)&pLIS + 1 );%@NL@%
- %@NL@%
- %@AB@%/* Register the monitor buffers to the current screen group */%@AE@%%@NL@%
- if( DosMonReg( hKeyMon, (PBYTE)pmnin, (PBYTE)pmnout,%@NL@%
- MONITOR_DEFAULT, pGIS->sgCurrent ) )%@NL@%
- {%@NL@%
- BackError( "Can't register monitor" );%@NL@%
- return 1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Make process time critical so keys are interpreted without delay. */%@AE@%%@NL@%
- DosSetPrty( PRTYS_PROCESS, PRTYC_TIMECRITICAL, 0, 0 );%@NL@%
- %@NL@%
- %@AB@%/* Monitor loop - read into monitor buffer and examine. Take action%@NL@%
- %@AB@% * if hot key, otherwise pass on to device driver.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( pshrSnap->fInstall )%@NL@%
- {%@NL@%
- DosMonRead( (PBYTE)pmnin, IO_WAIT, (PBYTE)&keyBuff, &ckeyBuff );%@NL@%
- %@NL@%
- %@AB@%/* Snap if ALT+STAR is down. */%@AE@%%@NL@%
- if( ((keyBuff.kki.chScan == STAR) || (keyBuff.kki.chScan == 0x2a)) &&%@NL@%
- (keyBuff.kki.fsState & ALT) &&%@NL@%
- (!(keyBuff.fDD & RELEASE)) )%@NL@%
- {%@NL@%
- %@AB@%/* Make sure last thread is finished */%@AE@%%@NL@%
- DosSemWait( &lfSnap, SEM_INDEFINITE_WAIT );%@NL@%
- if( (_beginthread( Snap, NULL, STACKSIZE,%@NL@%
- (PVOID)&lfSnap )) == FAIL )%@NL@%
- BackError( "Can't start screen capture thread" );%@NL@%
- else%@NL@%
- DosSemSet( &lfSnap );%@NL@%
- }%@NL@%
- else%@NL@%
- %@AB@%/* Pass the key through if it is not the hot key */%@AE@%%@NL@%
- DosMonWrite( (PBYTE)pmnout, (PBYTE)&keyBuff, ckeyBuff );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Close monitor */%@AE@%%@NL@%
- free( pmnin );%@NL@%
- free( pmnout );%@NL@%
- DosMonClose( hKeyMon );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Screen capture routine (run as a thread). Does a pop-up to get access%@NL@%
- %@AB@% * to the current screen. Reads characters from the screen into a buffer.%@NL@%
- %@AB@% * Then filters trailing spaces as it writes buffer to a file.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: plfSnap - pointer to flag indicated snap status%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: none%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: pshrSnap - Shared memory structure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Snap( ULONG _far *plfSnap )%@NL@%
- {%@NL@%
- enum { NOTE_B = 494, NOTE_C = 523, NOTE_F = 698 };%@NL@%
- CHAR *pchScreen; // Buffer for captured screen%@NL@%
- USHORT cbScreen; // Count of bytes in buffer%@NL@%
- FILE *sFile; // File stream%@NL@%
- USHORT usLine, usPos, usWidth;%@NL@%
- CHAR ach[5];%@NL@%
- USHORT fWait = VP_WAIT | VP_TRANSPARENT;%@NL@%
- VIOMODEINFO vmi = { sizeof( vmi ) };%@NL@%
- %@NL@%
- if( pshrSnap->fSound )%@NL@%
- DosBeep( NOTE_F, NOTE_C );%@NL@%
- %@NL@%
- %@AB@%/* Pop up to current screen and check its size. */%@AE@%%@NL@%
- VioPopUp( &fWait, CON );%@NL@%
- VioGetMode( &vmi, CON );%@NL@%
- %@NL@%
- %@AB@%/* Allocate memory for a full screen plus one byte */%@AE@%%@NL@%
- cbScreen = vmi.col * vmi.row;%@NL@%
- pchScreen = malloc( cbScreen + 1 );%@NL@%
- %@NL@%
- %@AB@%/* Read screen and end popup */%@AE@%%@NL@%
- VioReadCharStr( pchScreen, &cbScreen, 0, 0, CON );%@NL@%
- VioEndPopUp( 0 );%@NL@%
- %@NL@%
- %@AB@%/* Increment screen count (4 digits or less) and convert to string. */%@AE@%%@NL@%
- pshrSnap->cScreen = (pshrSnap->cScreen + 1) % 9999;%@NL@%
- itoa( pshrSnap->cScreen, ach, 10 );%@NL@%
- %@NL@%
- %@AB@%/* Make numbered file name if appropriate. */%@AE@%%@NL@%
- if( !pshrSnap->fAppend )%@NL@%
- strcat( strcat( strcpy( pshrSnap->achSnap, "SNAP" ), ach ), ".IMG" );%@NL@%
- %@NL@%
- %@AB@%/* Open file and write buffer to it a line at a time */%@AE@%%@NL@%
- if( (sFile = fopen( pshrSnap->achSnap, "at" )) == NULL )%@NL@%
- {%@NL@%
- BackError( "Can't open file" );%@NL@%
- --pshrSnap->cScreen;%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- if( pshrSnap->fAppend )%@NL@%
- {%@NL@%
- %@AB@%/* Not using fprintf reduces overhead. */%@AE@%%@NL@%
- fputs( "**** Screen ", sFile );%@NL@%
- fputs( ach, sFile );%@NL@%
- fputs( " ****\n", sFile );%@NL@%
- }%@NL@%
- %@NL@%
- for( usLine = 0, usPos = 0; usLine < vmi.row; usLine++ )%@NL@%
- {%@NL@%
- %@AB@%/* Throw away trailing spaces */%@AE@%%@NL@%
- for( usWidth = vmi.col;%@NL@%
- (pchScreen[usPos + usWidth - 1] == ' ' ) && usWidth;%@NL@%
- usWidth-- )%@NL@%
- ;%@NL@%
- %@AB@%/* Write line and newline */%@AE@%%@NL@%
- fwrite( pchScreen + usPos, 1, usWidth, sFile );%@NL@%
- fputc( '\n', sFile );%@NL@%
- usPos += vmi.col;%@NL@%
- }%@NL@%
- fclose( sFile );%@NL@%
- }%@NL@%
- if( pshrSnap->fSound )%@NL@%
- DosBeep( NOTE_C, NOTE_B );%@NL@%
- %@NL@%
- %@AB@%/* Free memory and let parent know we are done */%@AE@%%@NL@%
- free( pchScreen );%@NL@%
- DosSemClear( plfSnap );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Displays an error message from within a background process or thread.%@NL@%
- %@AB@% * The monitor is in the background and has no screen group, so it must%@NL@%
- %@AB@% * use VioPopUp to get access to the screen.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: msgErr - error message string%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void BackError( char *pchErr )%@NL@%
- {%@NL@%
- USHORT fWait = VP_WAIT | VP_TRANSPARENT;%@NL@%
- %@NL@%
- VioPopUp( &fWait, CON );%@NL@%
- puts( pchErr );%@NL@%
- puts( "Press any key to continue . . ." );%@NL@%
- while( !kbhit() )%@NL@%
- ;%@NL@%
- VioEndPopUp( CON );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Displays syntax.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Syntax()%@NL@%
- {%@NL@%
- puts( "\nOptions: " );%@NL@%
- puts( "\t/H\t Display help." );%@NL@%
- puts( "\t/S\t Turn sound on (default)." );%@NL@%
- puts( "\t/Q\t Turn sound off." );%@NL@%
- puts( "\t/D\t Deinstall." );%@NL@%
- puts( "\t/A [path] Append each screen to a file (complete path allowed)." );%@NL@%
- puts( "\t\t If no file given, default is SNAP.IMG in current directory" );%@NL@%
- puts( "\t\t Resets screen number to 1." );%@NL@%
- puts( "\t/N [num] Create numbered file for each screen." );%@NL@%
- puts( "\t\t Example: SNAP1.IMG, SNAP2.IMG in current directory." );%@NL@%
- puts( "\t\t Resets screen number to 1 or to num if given." );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Evaluate command-line options.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: argc - Number of arguments%@NL@%
- %@AB@% * argv - Pointer to argument list%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: none%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: Shared memory structure - pshrSnap%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void EvalOptions( int argc, char **argv )%@NL@%
- {%@NL@%
- SHORT i;%@NL@%
- %@NL@%
- %@AB@%/* Look for and handle arguments */%@AE@%%@NL@%
- for( i = 1; i < argc; i++ )%@NL@%
- {%@NL@%
- if( argv[i][0] == '/' || argv[i][0] == '-' )%@NL@%
- {%@NL@%
- switch( argv[i][1] )%@NL@%
- {%@NL@%
- case 'A':%@NL@%
- case 'a':%@NL@%
- pshrSnap->fAppend = TRUE;%@NL@%
- pshrSnap->cScreen = 0;%@NL@%
- if( (argv[++i]) &&%@NL@%
- (argv[i][0] != '/') &&%@NL@%
- (argv[i][0] != '-') )%@NL@%
- %@NL@%
- {%@NL@%
- strcpy( pshrSnap->achSnap, argv[i] );%@NL@%
- puts( "Append mode - name set" );%@NL@%
- }%@NL@%
- else%@NL@%
- puts( "Append mode" );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'N':%@NL@%
- case 'n':%@NL@%
- pshrSnap->fAppend = FALSE;%@NL@%
- puts( "Numbered file mode" );%@NL@%
- if( (argv[++i]) &&%@NL@%
- (argv[i][0] != '/') &&%@NL@%
- (argv[i][0] != '-') )%@NL@%
- {%@NL@%
- pshrSnap->cScreen = (atoi( argv[i] ) % 9999) - 1;%@NL@%
- }%@NL@%
- else%@NL@%
- pshrSnap->cScreen = 0;%@NL@%
- break;%@NL@%
- %@NL@%
- case 'Q':%@NL@%
- case 'q':%@NL@%
- pshrSnap->fSound = FALSE;%@NL@%
- puts( "Sound off" );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'S' :%@NL@%
- case 's' :%@NL@%
- pshrSnap->fSound = TRUE;%@NL@%
- puts( "Sound on" );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'D':%@NL@%
- case 'd':%@NL@%
- if( pshrSnap->fInstall )%@NL@%
- {%@NL@%
- pshrSnap->fInstall = FALSE;%@NL@%
- puts( "Deinstalling" );%@NL@%
- }%@NL@%
- else%@NL@%
- exit( 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'H' :%@NL@%
- case 'h' :%@NL@%
- if( pshrSnap->fInstall )%@NL@%
- Syntax();%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SORTDEMO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\SORTDEMO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SORTDEMO -This program graphically demonstrates six common sorting%@NL@%
- %@AB@% * algorithms. It prints 25 or 43 horizontal bars of different lengths%@NL@%
- %@AB@% * in random order, then sorts the bars from shortest to longest.%@NL@%
- %@AB@% * The program can beep to generate different pitches, depending on the%@NL@%
- %@AB@% * length and position of the bar.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The program can be created for DOS or OS/2. To create for OS/2, define%@NL@%
- %@AB@% * the symbol OS2. Command lines for DOS and OS/2 are shown below:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * DOS:%@NL@%
- %@AB@% * cl /Lr sortdemo.c graphics.lib%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * OS/2:%@NL@%
- %@AB@% * cl /Lp /DOS2 sortdemo.c grtextp.lib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<graph.h> // _outtext, _settextcolor, _settextposition %@NL@%
- %@AI@%#include %@AE@%<string.h> // strlen %@NL@%
- %@AI@%#include %@AE@%<stdio.h> // sprintf %@NL@%
- %@AI@%#include %@AE@%<conio.h> // getch %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> // srand, rand, toupper %@NL@%
- %@AI@%#include %@AE@%<malloc.h> // malloc, free %@NL@%
- %@AI@%#include %@AE@%<time.h> // time, clock %@NL@%
- %@NL@%
- enum BOOL { FALSE, TRUE };%@NL@%
- %@NL@%
- %@AB@%/* Structure type for colored bars */%@AE@%%@NL@%
- typedef struct _BAR%@NL@%
- {%@NL@%
- char len;%@NL@%
- char clr;%@NL@%
- } BAR;%@NL@%
- %@NL@%
- %@AB@%/* Structure type for screen cells */%@AE@%%@NL@%
- typedef struct _CELL%@NL@%
- {%@NL@%
- char chChar;%@NL@%
- char chAttr;%@NL@%
- } CELL;%@NL@%
- %@NL@%
- %@AB@%/* Function prototypes */%@AE@%%@NL@%
- void main( void );%@NL@%
- void Cls( void );%@NL@%
- void InitMenu( void ); // Menu Functions%@NL@%
- void DrawFrame( int iTop, int Left, int Width, int Height );%@NL@%
- void RunMenu( void );%@NL@%
- void DrawTime( int iCurrentRow );%@NL@%
- void InitBars( void ); // Bar functions%@NL@%
- void ReInitBars( void );%@NL@%
- void DrawBar( int iRow );%@NL@%
- void SwapBars( int iRow1, int iRow2 );%@NL@%
- void Swaps( BAR *one, BAR *two );%@NL@%
- void InsertionSort( void ); // Sort functions%@NL@%
- void BubbleSort( void );%@NL@%
- void HeapSort( void );%@NL@%
- void PercolateUp( int iMaxLevel );%@NL@%
- void PercolateDown( int iMaxLevel );%@NL@%
- void ExchangeSort( void );%@NL@%
- void ShellSort( void );%@NL@%
- void QuickSort( int iLow, int iHigh );%@NL@%
- void Beep( int frequency, int duration );%@NL@%
- void Sleep( clock_t wait );%@NL@%
- %@NL@%
- %@AB@%/* Macro */%@AE@%%@NL@%
- %@AI@%#define %@AE@%GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min)) %@NL@%
- %@AI@%#define %@AE@%_outtextxy( ach, x, y ) { _settextposition( y, x ); \ %@NL@%
- _outtext( ach ); }%@NL@%
- %@NL@%
- %@AB@%/* Constants */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ESC 27 %@NL@%
- %@AI@%#define %@AE@%BLANK 32 %@NL@%
- %@AI@%#define %@AE@%BLOCK 223 %@NL@%
- %@AI@%#define %@AE@%TOP 1 %@NL@%
- %@AI@%#define %@AE@%FIRSTMENU (TOP + 6) %@NL@%
- %@AI@%#define %@AE@%LEFTCOLUMN 48 %@NL@%
- %@AI@%#define %@AE@%PROMPTPOS 27 %@NL@%
- %@AI@%#define %@AE@%WIDTH (80 - LEFTCOLUMN) %@NL@%
- %@AI@%#define %@AE@%HEIGHT (cszMenu + 2) %@NL@%
- %@AI@%#define %@AE@%MENUCOLOR 15 %@NL@%
- %@AI@%#define %@AE@%BLANKCOLOR 7 %@NL@%
- %@AI@%#define %@AE@%BACKCOLOR 0L %@NL@%
- %@AI@%#define %@AE@%PAUSELIMIT 900 %@NL@%
- %@NL@%
- %@AB@%/* Global variables */%@AE@%%@NL@%
- clock_t clStart, clFinish, clPause = 30L;%@NL@%
- int fSound, iCurChoice, iSwaps, iCompares, cRow;%@NL@%
- %@NL@%
- BAR abarWork[43], abarPerm[43]; // Temporary and permanent sort arrays%@NL@%
- %@NL@%
- char *aszMenu[] =%@NL@%
- {%@NL@%
- "",%@NL@%
- " C Sorting Demo",%@NL@%
- "",%@NL@%
- " Time Swap Comp",%@NL@%
- "",%@NL@%
- "Insertion",%@NL@%
- "Bubble",%@NL@%
- "Heap",%@NL@%
- "Exchange",%@NL@%
- "Shell",%@NL@%
- "Quick",%@NL@%
- "",%@NL@%
- "Toggle Sound: ",%@NL@%
- "",%@NL@%
- "Pause Factor: ",%@NL@%
- "< (Slower)",%@NL@%
- "> (Faster)",%@NL@%
- "",%@NL@%
- "Type first character of",%@NL@%
- "choice ( I B H E S Q T < > )",%@NL@%
- "or ESC key to end program: "%@NL@%
- "",%@NL@%
- };%@NL@%
- int cszMenu = sizeof( aszMenu ) / sizeof( aszMenu[0] );%@NL@%
- %@NL@%
- void main()%@NL@%
- {%@NL@%
- cRow = _settextrows( 43 );%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _displaycursor( _GCURSOROFF );%@NL@%
- InitBars();%@NL@%
- InitMenu();%@NL@%
- RunMenu(); // Respond to menu until quit%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* InitMenu - Calls the DrawFrame procedure to draw the frame around the%@NL@%
- %@AB@% * sort menu, then prints the different options stored in the menu array.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void InitMenu()%@NL@%
- {%@NL@%
- int i;%@NL@%
- char ach[15];%@NL@%
- %@NL@%
- _settextcolor( MENUCOLOR );%@NL@%
- _setbkcolor( BACKCOLOR );%@NL@%
- DrawFrame( TOP, LEFTCOLUMN - 3, WIDTH + 3, HEIGHT );%@NL@%
- for( i = 0; i < cszMenu; i++ )%@NL@%
- _outtextxy( aszMenu[i], LEFTCOLUMN, TOP + i + 1 );%@NL@%
- %@NL@%
- %@AB@%/* Print the current value for Sound. */%@AE@%%@NL@%
- if( fSound )%@NL@%
- strcpy( ach, "ON " );%@NL@%
- else%@NL@%
- strcpy( ach, "OFF" );%@NL@%
- %@NL@%
- _outtextxy( ach, LEFTCOLUMN + 14, cszMenu - 7 );%@NL@%
- sprintf( ach, "%3.3u", clPause / 30 );%@NL@%
- _outtextxy( ach, LEFTCOLUMN + 14, cszMenu - 5 );%@NL@%
- %@NL@%
- %@AB@%/* Erase the speed option if the length of the pause is at a limit. */%@AE@%%@NL@%
- strcpy( ach, " " );%@NL@%
- if( clPause == PAUSELIMIT )%@NL@%
- _outtextxy( ach, LEFTCOLUMN, cszMenu - 4 );%@NL@%
- if( clPause == 0L )%@NL@%
- _outtextxy( ach, LEFTCOLUMN, cszMenu - 3 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* DrawFrame - Draws a rectangular frame using the double-line box%@NL@%
- %@AB@% * characters. The parameters iTop, iLeft, iWidth, and iHeight are%@NL@%
- %@AB@% * the row and column arguments for the upper-left and lower-right%@NL@%
- %@AB@% * corners of the frame.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void DrawFrame( int iTop, int iLeft, int iWidth, int iHeight )%@NL@%
- {%@NL@%
- enum { ULEFT = 201, URIGHT = 187,%@NL@%
- LLEFT = 200, LRIGHT = 188, VERTICAL = 186, HORIZONTAL = 205%@NL@%
- };%@NL@%
- int iRow;%@NL@%
- char achTmp[80];%@NL@%
- %@NL@%
- memset( achTmp, HORIZONTAL, iWidth );%@NL@%
- achTmp[0] = ULEFT;%@NL@%
- achTmp[iWidth - 1] = URIGHT;%@NL@%
- achTmp[iWidth] = '\0';%@NL@%
- _outtextxy( achTmp, iLeft, iTop );%@NL@%
- %@NL@%
- memset( achTmp, BLANK, iWidth );%@NL@%
- achTmp[0] = VERTICAL;%@NL@%
- achTmp[iWidth - 1] = VERTICAL;%@NL@%
- for( iRow = iTop + 1; iRow <= iHeight; iRow++ )%@NL@%
- _outtextxy( achTmp, iLeft, iRow );%@NL@%
- %@NL@%
- memset( achTmp, HORIZONTAL, iWidth );%@NL@%
- achTmp[0] = LLEFT;%@NL@%
- achTmp[iWidth - 1] = LRIGHT;%@NL@%
- _outtextxy( achTmp, iLeft, iTop + iHeight );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* RunMenu - The RunMenu procedure first calls the ReInitBars%@NL@%
- %@AB@% * procedure to make sure the abarWork is in its unsorted form, then%@NL@%
- %@AB@% * prompts the user to make one of the following choices:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * - Run one of the sorting algorithms%@NL@%
- %@AB@% * - Toggle sound on or off%@NL@%
- %@AB@% * - Increase or decrease speed%@NL@%
- %@AB@% * - End the program%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void RunMenu()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- iSwaps = iCompares = 0;%@NL@%
- _settextposition( TOP + cszMenu, LEFTCOLUMN + PROMPTPOS );%@NL@%
- _displaycursor( _GCURSORON );%@NL@%
- ch = getch();%@NL@%
- _displaycursor( _GCURSOROFF );%@NL@%
- %@NL@%
- %@AB@%/* Branch to the appropriate procedure depending on the key. */%@AE@%%@NL@%
- switch( toupper( ch ) )%@NL@%
- {%@NL@%
- case 'I':%@NL@%
- iCurChoice = 0;%@NL@%
- ReInitBars();%@NL@%
- InsertionSort();%@NL@%
- DrawTime( 0 ); // Print final time%@NL@%
- break;%@NL@%
- case 'B':%@NL@%
- iCurChoice = 1;%@NL@%
- ReInitBars();%@NL@%
- BubbleSort();%@NL@%
- DrawTime( 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'H':%@NL@%
- iCurChoice = 2;%@NL@%
- ReInitBars();%@NL@%
- HeapSort();%@NL@%
- DrawTime( 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'E':%@NL@%
- iCurChoice = 3;%@NL@%
- ReInitBars();%@NL@%
- ExchangeSort();%@NL@%
- DrawTime( 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'S':%@NL@%
- iCurChoice = 4;%@NL@%
- ReInitBars();%@NL@%
- ShellSort();%@NL@%
- DrawTime( 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case 'Q':%@NL@%
- iCurChoice = 5;%@NL@%
- ReInitBars();%@NL@%
- QuickSort( 0, cRow );%@NL@%
- DrawTime( 0 );%@NL@%
- break;%@NL@%
- %@NL@%
- case '>':%@NL@%
- %@AB@%/* Decrease pause length to speed up sorting time, then%@NL@%
- %@AB@% * redraw the menu to clear any timing results (since%@NL@%
- %@AB@% * they won't compare with future results).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( clPause )%@NL@%
- clPause -= 30L;%@NL@%
- InitMenu();%@NL@%
- break;%@NL@%
- %@NL@%
- case '<':%@NL@%
- %@AB@%/* Increase pause length to slow down sorting time. */%@AE@%%@NL@%
- if( clPause <= 900L )%@NL@%
- clPause += 30L;%@NL@%
- InitMenu();%@NL@%
- break;%@NL@%
- %@NL@%
- case 'T':%@NL@%
- fSound = !fSound;%@NL@%
- InitMenu();%@NL@%
- break;%@NL@%
- %@NL@%
- case ESC:%@NL@%
- return;%@NL@%
- %@NL@%
- default: // Unknown key ignored%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* DrawTime - Prints seconds elapsed since the given sorting routine%@NL@%
- %@AB@% * started. Note that this time includes both the time it takes to redraw%@NL@%
- %@AB@% * the bars plus the pause while Beep plays a note, and thus is not an%@NL@%
- %@AB@% * accurate indication of sorting speed.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void DrawTime( int iCurrentRow )%@NL@%
- {%@NL@%
- char achTiming[80];%@NL@%
- %@NL@%
- _settextcolor( MENUCOLOR );%@NL@%
- clFinish = clock();%@NL@%
- %@NL@%
- sprintf( achTiming, "%7.2f %4.i %4.i",%@NL@%
- (float)(clFinish - clStart) / CLOCKS_PER_SEC,%@NL@%
- iSwaps, iCompares );%@NL@%
- %@NL@%
- %@AB@%/* Print the number of seconds elapsed */%@AE@%%@NL@%
- _outtextxy( achTiming, LEFTCOLUMN + 11, FIRSTMENU + iCurChoice );%@NL@%
- if( fSound )%@NL@%
- {%@NL@%
- Beep( 60 * iCurrentRow, 75 ); // Play note%@NL@%
- Sleep( clPause - 75L ); // Pause adjusted for note duration%@NL@%
- }%@NL@%
- else%@NL@%
- Sleep( clPause ); // Pause%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* InitBars - Initializes the bar arrays and the menu box.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void InitBars()%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int aTemp[43], iRow, iRowMax, iRand, iColorMax, iLength;%@NL@%
- %@NL@%
- %@AB@%/* Seed the random-number generator. */%@AE@%%@NL@%
- srand( (unsigned)time( NULL ) );%@NL@%
- fSound = TRUE;%@NL@%
- clPause = 30L;%@NL@%
- %@NL@%
- %@AB@%/* If monochrome or color burst disabled, use one color */%@AE@%%@NL@%
- _getvideoconfig( &vc );%@NL@%
- if( (vc.monitor == _MONO) || (vc.mode == _TEXTBW80) ||%@NL@%
- (vc.mode == _TEXTBW40) )%@NL@%
- iColorMax = 1;%@NL@%
- else%@NL@%
- iColorMax = 15;%@NL@%
- %@NL@%
- %@AB@%/* Randomize an array of rows. */%@AE@%%@NL@%
- for( iRow = 0; iRow < cRow; iRow++ )%@NL@%
- aTemp[iRow] = iRow + 1;%@NL@%
- iRowMax = cRow - 1;%@NL@%
- for( iRow = 0; iRow < cRow; iRow++ )%@NL@%
- {%@NL@%
- %@AB@%/* Find a random element in aTemp between 0 and iRowMax,%@NL@%
- %@AB@% * then assign the value in that element to iLength.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- iRand = GetRandom( 0, iRowMax );%@NL@%
- iLength = aTemp[iRand];%@NL@%
- %@NL@%
- %@AB@%/* Overwrite the value in aTemp[iRand] with the value in%@NL@%
- %@AB@% * aTemp[iRowMax] so the value in aTemp[iRand] is%@NL@%
- %@AB@% * chosen only once.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- aTemp[iRand] = aTemp[iRowMax];%@NL@%
- %@NL@%
- %@AB@%/* Decrease the value of iRowMax so that aTemp[iRowMax] can't%@NL@%
- %@AB@% * be chosen on the next pass through the loop.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- --iRowMax;%@NL@%
- abarPerm[iRow].len = iLength;%@NL@%
- if( iColorMax == 1 )%@NL@%
- abarPerm[iRow].clr = BLANKCOLOR;%@NL@%
- else%@NL@%
- abarPerm[iRow].clr = iLength % iColorMax + 1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Assign permanent sort values to temporary and draw unsorted bars. */%@AE@%%@NL@%
- ReInitBars();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* ReInitBars - Restores the array abarWork to its original unsorted%@NL@%
- %@AB@% * state and draws the unsorted bars.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ReInitBars()%@NL@%
- {%@NL@%
- int iRow;%@NL@%
- %@NL@%
- clStart = clock();%@NL@%
- for( iRow = 0; iRow < cRow; iRow++ )%@NL@%
- {%@NL@%
- abarWork[iRow] = abarPerm[iRow];%@NL@%
- DrawBar( iRow );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* DrawBar - Prints a bar at a specified row by first blanking the%@NL@%
- %@AB@% * old bar, then drawing a new bar having the length and color given in%@NL@%
- %@AB@% * the work array.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void DrawBar( int iRow )%@NL@%
- {%@NL@%
- int cSpace;%@NL@%
- char achT[43];%@NL@%
- %@NL@%
- memset( achT, BLOCK, abarWork[iRow].len );%@NL@%
- cSpace = cRow - abarWork[iRow].len;%@NL@%
- memset( achT + abarWork[iRow].len, ' ', cSpace );%@NL@%
- achT[cRow] = '\0';%@NL@%
- _settextcolor( abarWork[iRow].clr );%@NL@%
- _outtextxy( achT, 0, iRow + 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* SwapBars - Calls DrawBar twice to switch the two bars in iRow1 and%@NL@%
- %@AB@% * iRow2, then calls DrawTime to update the time.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void SwapBars( int iRow1, int iRow2 )%@NL@%
- {%@NL@%
- DrawBar( iRow1 );%@NL@%
- DrawBar( iRow2 );%@NL@%
- DrawTime( iRow1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Swaps - Exchanges two bar structures.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Swaps( BAR *bar1, BAR *bar2 )%@NL@%
- {%@NL@%
- BAR barTmp;%@NL@%
- %@NL@%
- ++iSwaps;%@NL@%
- barTmp = *bar1;%@NL@%
- *bar1 = *bar2;%@NL@%
- *bar2 = barTmp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* InsertionSort - InsertionSort compares the length of each element%@NL@%
- %@AB@% * with the lengths of all the preceding elements. When the appropriate%@NL@%
- %@AB@% * place for the new element is found, the element is inserted and%@NL@%
- %@AB@% * all the other elements are moved down one place.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void InsertionSort()%@NL@%
- {%@NL@%
- BAR barTemp;%@NL@%
- int iRow, iRowTmp, iLength;%@NL@%
- %@NL@%
- %@AB@%/* Start at the top. */%@AE@%%@NL@%
- for( iRow = 0; iRow < cRow; iRow++ )%@NL@%
- {%@NL@%
- barTemp = abarWork[iRow];%@NL@%
- iLength = barTemp.len;%@NL@%
- %@NL@%
- %@AB@%/* As long as the length of the temporary element is greater than%@NL@%
- %@AB@% * the length of the original, keep shifting the elements down.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for( iRowTmp = iRow; iRowTmp; iRowTmp-- )%@NL@%
- {%@NL@%
- iCompares++;%@NL@%
- if( abarWork[iRowTmp - 1].len > iLength )%@NL@%
- {%@NL@%
- ++iSwaps;%@NL@%
- abarWork[iRowTmp] = abarWork[iRowTmp - 1];%@NL@%
- DrawBar( iRowTmp ); // Print the new bar%@NL@%
- DrawTime( iRowTmp ); // Print the elapsed time%@NL@%
- %@NL@%
- }%@NL@%
- else // Otherwise, exit%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Insert the original bar in the temporary position. */%@AE@%%@NL@%
- abarWork[iRowTmp] = barTemp;%@NL@%
- DrawBar( iRowTmp );%@NL@%
- DrawTime( iRowTmp );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* BubbleSort - BubbleSort cycles through the elements, comparing%@NL@%
- %@AB@% * adjacent elements and swapping pairs that are out of order. It%@NL@%
- %@AB@% * continues to do this until no out-of-order pairs are found.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void BubbleSort()%@NL@%
- {%@NL@%
- int iRow, iSwitch, iLimit = cRow;%@NL@%
- %@NL@%
- %@AB@%/* Move the longest bar down to the bottom until all are in order. */%@AE@%%@NL@%
- do%@NL@%
- {%@NL@%
- iSwitch = 0;%@NL@%
- for( iRow = 0; iRow < iLimit; iRow++ )%@NL@%
- {%@NL@%
- %@AB@%/* If two adjacent elements are out of order, swap their values%@NL@%
- %@AB@% * and redraw those two bars.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- iCompares++;%@NL@%
- if( abarWork[iRow].len > abarWork[iRow + 1].len )%@NL@%
- {%@NL@%
- Swaps( &abarWork[iRow], &abarWork[iRow + 1] );%@NL@%
- SwapBars( iRow, iRow + 1 );%@NL@%
- iSwitch = iRow;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Sort on next pass only to where the last switch was made. */%@AE@%%@NL@%
- iLimit = iSwitch;%@NL@%
- } while( iSwitch );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* HeapSort - HeapSort (also called TreeSort) works by calling%@NL@%
- %@AB@% * PercolateUp and PercolateDown. PercolateUp organizes the elements%@NL@%
- %@AB@% * into a "heap" or "tree," which has the properties shown below:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * element[1]%@NL@%
- %@AB@% * / \%@NL@%
- %@AB@% * element[2] element[3]%@NL@%
- %@AB@% * / \ / \%@NL@%
- %@AB@% * element[4] element[5] element[6] element[7]%@NL@%
- %@AB@% * / \ / \ / \ / \%@NL@%
- %@AB@% * ... ... ... ... ... ... ... ...%@NL@%
- %@AB@% *%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Each "parent node" is greater than each of its "child nodes"; for%@NL@%
- %@AB@% * example, element[1] is greater than element[2] or element[3];%@NL@%
- %@AB@% * element[4] is greater than element[5] or element[6], and so forth.%@NL@%
- %@AB@% * Therefore, once the first loop in HeapSort is finished, the%@NL@%
- %@AB@% * largest element is in element[1].%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The second loop rebuilds the heap (with PercolateDown), but starts%@NL@%
- %@AB@% * at the top and works down, moving the largest elements to the bottom.%@NL@%
- %@AB@% * This has the effect of moving the smallest elements to the top and%@NL@%
- %@AB@% * sorting the heap.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void HeapSort()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for( i = 1; i < cRow; i++ )%@NL@%
- PercolateUp( i );%@NL@%
- %@NL@%
- for( i = cRow - 1; i > 0; i-- )%@NL@%
- {%@NL@%
- Swaps( &abarWork[0], &abarWork[i] );%@NL@%
- SwapBars( 0, i );%@NL@%
- PercolateDown( i - 1 );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* PercolateUp - Converts elements into a "heap" with the largest%@NL@%
- %@AB@% * element at the top (see the diagram above).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void PercolateUp( int iMaxLevel )%@NL@%
- {%@NL@%
- int i = iMaxLevel, iParent;%@NL@%
- %@NL@%
- %@AB@%/* Move the value in abarWork[iMaxLevel] up the heap until it has%@NL@%
- %@AB@% * reached its proper node (that is, until it is greater than either%@NL@%
- %@AB@% * of its child nodes, or until it has reached 1, the top of the heap).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( i )%@NL@%
- {%@NL@%
- iParent = i / 2; // Get the subscript for the parent node%@NL@%
- %@NL@%
- iCompares++;%@NL@%
- if( abarWork[i].len > abarWork[iParent].len )%@NL@%
- {%@NL@%
- %@AB@%/* The value at the current node is bigger than the value at%@NL@%
- %@AB@% * its parent node, so swap these two array elements.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Swaps( &abarWork[iParent], &abarWork[i] );%@NL@%
- SwapBars( iParent, i );%@NL@%
- i = iParent;%@NL@%
- }%@NL@%
- else%@NL@%
- %@AB@%/* Otherwise, the element has reached its proper place in the%@NL@%
- %@AB@% * heap, so exit this procedure.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* PercolateDown - Converts elements to a "heap" with the largest elements%@NL@%
- %@AB@% * at the bottom. When this is done to a reversed heap (largest elements%@NL@%
- %@AB@% * at top), it has the effect of sorting the elements.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void PercolateDown( int iMaxLevel )%@NL@%
- {%@NL@%
- int iChild, i = 0;%@NL@%
- %@NL@%
- %@AB@%/* Move the value in abarWork[0] down the heap until it has reached%@NL@%
- %@AB@% * its proper node (that is, until it is less than its parent node%@NL@%
- %@AB@% * or until it has reached iMaxLevel, the bottom of the current heap).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Get the subscript for the child node. */%@AE@%%@NL@%
- iChild = 2 * i;%@NL@%
- %@NL@%
- %@AB@%/* Reached the bottom of the heap, so exit this procedure. */%@AE@%%@NL@%
- if( iChild > iMaxLevel )%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* If there are two child nodes, find out which one is bigger. */%@AE@%%@NL@%
- if( iChild + 1 <= iMaxLevel )%@NL@%
- {%@NL@%
- iCompares++;%@NL@%
- if( abarWork[iChild + 1].len > abarWork[iChild].len )%@NL@%
- iChild++;%@NL@%
- }%@NL@%
- %@NL@%
- iCompares++;%@NL@%
- if( abarWork[i].len < abarWork[iChild].len )%@NL@%
- {%@NL@%
- %@AB@%/* Move the value down since it is still not bigger than%@NL@%
- %@AB@% * either one of its children.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Swaps( &abarWork[i], &abarWork[iChild] );%@NL@%
- SwapBars( i, iChild );%@NL@%
- i = iChild;%@NL@%
- }%@NL@%
- else%@NL@%
- %@AB@%/* Otherwise, abarWork has been restored to a heap from 1 to%@NL@%
- %@AB@% * iMaxLevel, so exit.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* ExchangeSort - The ExchangeSort compares each element--starting with%@NL@%
- %@AB@% * the first--with every following element. If any of the following%@NL@%
- %@AB@% * elements is smaller than the current element, it is exchanged with%@NL@%
- %@AB@% * the current element and the process is repeated for the next element.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ExchangeSort()%@NL@%
- {%@NL@%
- int iRowCur, iRowMin, iRowNext;%@NL@%
- %@NL@%
- for( iRowCur = 0; iRowCur < cRow; iRowCur++ )%@NL@%
- {%@NL@%
- iRowMin = iRowCur;%@NL@%
- for( iRowNext = iRowCur; iRowNext < cRow; iRowNext++ )%@NL@%
- {%@NL@%
- iCompares++;%@NL@%
- if( abarWork[iRowNext].len < abarWork[iRowMin].len )%@NL@%
- {%@NL@%
- iRowMin = iRowNext;%@NL@%
- DrawTime( iRowNext );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* If a row is shorter than the current row, swap those two%@NL@%
- %@AB@% * array elements.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( iRowMin > iRowCur )%@NL@%
- {%@NL@%
- Swaps( &abarWork[iRowCur], &abarWork[iRowMin] );%@NL@%
- SwapBars( iRowCur, iRowMin );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* ShellSort - ShellSort is similar to the BubbleSort. However, it%@NL@%
- %@AB@% * begins by comparing elements that are far apart (separated by the%@NL@%
- %@AB@% * value of the iOffset variable, which is initially half the distance%@NL@%
- %@AB@% * between the first and last element), then comparing elements that%@NL@%
- %@AB@% * are closer together. When iOffset is one, the last iteration of%@NL@%
- %@AB@% * is merely a bubble sort.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void ShellSort()%@NL@%
- {%@NL@%
- int iOffset, iSwitch, iLimit, iRow;%@NL@%
- %@NL@%
- %@AB@%/* Set comparison offset to half the number of bars. */%@AE@%%@NL@%
- iOffset = cRow / 2;%@NL@%
- %@NL@%
- while( iOffset )%@NL@%
- {%@NL@%
- %@AB@%/* Loop until offset gets to zero. */%@AE@%%@NL@%
- iLimit = cRow - iOffset;%@NL@%
- do%@NL@%
- {%@NL@%
- iSwitch = FALSE; // Assume no switches at this offset.%@NL@%
- %@NL@%
- %@AB@%/* Compare elements and switch ones out of order. */%@AE@%%@NL@%
- for( iRow = 0; iRow <= iLimit; iRow++ )%@NL@%
- {%@NL@%
- iCompares++;%@NL@%
- if( abarWork[iRow].len > abarWork[iRow + iOffset].len )%@NL@%
- {%@NL@%
- Swaps( &abarWork[iRow], &abarWork[iRow + iOffset] );%@NL@%
- SwapBars( iRow, iRow + iOffset );%@NL@%
- iSwitch = iRow;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Sort on next pass only to where last switch was made. */%@AE@%%@NL@%
- iLimit = iSwitch - iOffset;%@NL@%
- } while( iSwitch );%@NL@%
- %@NL@%
- %@AB@%/* No switches at last offset, try one half as big. */%@AE@%%@NL@%
- iOffset = iOffset / 2;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* QuickSort - QuickSort works by picking a random "pivot" element,%@NL@%
- %@AB@% * then moving every element that is bigger to one side of the pivot,%@NL@%
- %@AB@% * and every element that is smaller to the other side. QuickSort is%@NL@%
- %@AB@% * then called recursively with the two subdivisions created by the pivot.%@NL@%
- %@AB@% * Once the number of elements in a subdivision reaches two, the recursive%@NL@%
- %@AB@% * calls end and the array is sorted.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void QuickSort( int iLow, int iHigh )%@NL@%
- {%@NL@%
- int iUp, iDown, iBreak;%@NL@%
- %@NL@%
- if( iLow < iHigh )%@NL@%
- {%@NL@%
- %@AB@%/* Only two elements in this subdivision; swap them if they are%@NL@%
- %@AB@% * out of order, then end recursive calls.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( (iHigh - iLow) == 1 )%@NL@%
- {%@NL@%
- iCompares++;%@NL@%
- if( abarWork[iLow].len > abarWork[iHigh].len )%@NL@%
- {%@NL@%
- Swaps( &abarWork[iLow], &abarWork[iHigh] );%@NL@%
- SwapBars( iLow, iHigh );%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- iBreak = abarWork[iHigh].len;%@NL@%
- do%@NL@%
- {%@NL@%
- %@AB@%/* Move in from both sides towards the pivot element. */%@AE@%%@NL@%
- iUp = iLow;%@NL@%
- iDown = iHigh;%@NL@%
- iCompares++;%@NL@%
- while( (iUp < iDown) && (abarWork[iUp].len <= iBreak) )%@NL@%
- iUp++;%@NL@%
- iCompares++;%@NL@%
- while( (iDown > iUp) && (abarWork[iDown].len >= iBreak) )%@NL@%
- iDown--;%@NL@%
- %@AB@%/* If we haven't reached the pivot, it means that two%@NL@%
- %@AB@% * elements on either side are out of order, so swap them.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( iUp < iDown )%@NL@%
- {%@NL@%
- Swaps( &abarWork[iUp], &abarWork[iDown] );%@NL@%
- SwapBars( iUp, iDown );%@NL@%
- }%@NL@%
- } while ( iUp < iDown );%@NL@%
- %@NL@%
- %@AB@%/* Move pivot element back to its proper place in the array. */%@AE@%%@NL@%
- Swaps( &abarWork[iUp], &abarWork[iHigh] );%@NL@%
- SwapBars( iUp, iHigh );%@NL@%
- %@NL@%
- %@AB@%/* Recursively call the QuickSort procedure (pass the smaller%@NL@%
- %@AB@% * subdivision first to use less stack space).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( (iUp - iLow) < (iHigh - iUp) )%@NL@%
- {%@NL@%
- QuickSort( iLow, iUp - 1 );%@NL@%
- QuickSort( iUp + 1, iHigh );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- QuickSort( iUp + 1, iHigh );%@NL@%
- QuickSort( iLow, iUp - 1 );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Beep - Sounds the speaker for a time specified in microseconds by%@NL@%
- %@AB@% * duration at a pitch specified in hertz by frequency.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Beep( int frequency, int duration )%@NL@%
- {%@NL@%
- %@AB@%/* Use system call for OS/2 */%@AE@%%@NL@%
- %@AI@%#if %@AE@%defined( OS2 ) %@NL@%
- %@AI@%#define %@AE@%INCL_NOCOMMON %@NL@%
- %@AI@%#define %@AE@%INCL_NOPM %@NL@%
- %@AI@%#define %@AE@%INCL_DOSPROCESS %@NL@%
- %@AI@%#include %@AE@%<os2.h> %@NL@%
- DosBeep( frequency, duration );%@NL@%
- %@AI@%#else %@AE@%%@NL@%
- %@AB@%/* Define procedure for DOS */%@AE@%%@NL@%
- int control;%@NL@%
- %@NL@%
- %@AB@%/* If frequency is 0, Beep doesn't try to make a sound. It%@NL@%
- %@AB@% * just sleeps for the duration.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( frequency )%@NL@%
- {%@NL@%
- %@AB@%/* 75 is about the shortest reliable duration of a sound. */%@AE@%%@NL@%
- if( duration < 75 )%@NL@%
- duration = 75;%@NL@%
- %@NL@%
- %@AB@%/* Prepare timer by sending 10111100 to port 43. */%@AE@%%@NL@%
- outp( 0x43, 0xb6 );%@NL@%
- %@NL@%
- %@AB@%/* Divide input frequency by timer ticks per second and%@NL@%
- %@AB@% * write (byte by byte) to timer.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- frequency = (unsigned)(1193180L / frequency);%@NL@%
- outp( 0x42, (char)frequency );%@NL@%
- outp( 0x42, (char)(frequency >> 8) );%@NL@%
- %@NL@%
- %@AB@%/* Save speaker control byte. */%@AE@%%@NL@%
- control = inp( 0x61 );%@NL@%
- %@NL@%
- %@AB@%/* Turn on the speaker (with bits 0 and 1). */%@AE@%%@NL@%
- outp( 0x61, control | 0x3 );%@NL@%
- }%@NL@%
- %@NL@%
- Sleep( (clock_t)duration );%@NL@%
- %@NL@%
- %@AB@%/* Turn speaker back on if necessary. */%@AE@%%@NL@%
- if( frequency )%@NL@%
- outp( 0x61, control );%@NL@%
- %@NL@%
- %@AB@%/* DOS version */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Pauses for a specified number of microseconds. */%@AE@%%@NL@%
- void Sleep( clock_t wait )%@NL@%
- {%@NL@%
- clock_t goal;%@NL@%
- %@NL@%
- goal = wait + clock();%@NL@%
- while( goal >= clock() )%@NL@%
- ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TURTLE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\MSC60\TURTLE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* TURTLE - Module of functions to implement turtle graphics. Turtle graphics%@NL@%
- %@AB@% * is a model for specifying relative movements of an imaginary pointer whose%@NL@%
- %@AB@% * direction, color, visibility, and other attributes are given default%@NL@%
- %@AB@% * values using turtle functions. To use the turtle module, include TURTLE.H%@NL@%
- %@AB@% * in your program. The following functions (many defined as macros)%@NL@%
- %@AB@% * are public :%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * InitTurtle - Initiate turtle graphics%@NL@%
- %@AB@% * Home - Reset turtle defaults%@NL@%
- %@AB@% * PenDown - Set pen visibility%@NL@%
- %@AB@% * SetFill - Set fill state%@NL@%
- %@AB@% * PenColor - Set pen color index%@NL@%
- %@AB@% * BorderColor - Set border color index%@NL@%
- %@AB@% * Turn - Set direction relative to current%@NL@%
- %@AB@% * TurnTo - Set absolute direction%@NL@%
- %@AB@% * Move - Move in current direction%@NL@%
- %@AB@% * MoveTo - Move to absolute location%@NL@%
- %@AB@% * Poly - Draw a polygon%@NL@%
- %@AB@% * Circle - Draw a circle with center at current location%@NL@%
- %@AB@% * Ellipse - Draw an ellipse with center at current location%@NL@%
- %@AB@% * Rectangle - Draw a rectangle with center at current location%@NL@%
- %@AB@% * ImageSize - Get size of rectangle with top-left origin%@NL@%
- %@AB@% * GetImage - Get rectangular image with top-left origin%@NL@%
- %@AB@% * PutImage - Put rectangular image with top-left origin%@NL@%
- %@AB@% * FillIn - Fill from the current location to border%@NL@%
- %@AB@% * NextColorIndex - Rotate to next color index%@NL@%
- %@AB@% * NextColorValue - Rotate to next color value%@NL@%
- %@AB@% * OnScreen - Report whether current location is on screen%@NL@%
- %@AB@% * RGB - Combine Red, Green, and Blue elements of color value%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The TURTLE structure, the "tc" global variable (having TURTLE type), and%@NL@%
- %@AB@% * "vlColors" variable are defined. However, these are not normally used%@NL@%
- %@AB@% * directly by the programmer.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"turtle.h" %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%PI 3.141593 %@NL@%
- %@NL@%
- long cvlColors[256]; %@AB@%/* Array of long color values */%@AE@%%@NL@%
- %@NL@%
- TURTLE tc = { 1.39 }; %@AB@%/* Initial aspect - adjust for your screen */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* InitTurtle - Initializes all turtle defaults. This function should be%@NL@%
- %@AB@% * called at least once (after _setvideomode and _getvideoconfig) and%@NL@%
- %@AB@% * additionally after any change to a new graphics mode.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: vc - pointer to videoconfig structure%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 0 if fail, 1 if success%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc structure variable cvlColors array%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short InitTurtle( struct videoconfig *vc )%@NL@%
- {%@NL@%
- int i;%@NL@%
- unsigned cvuInc, cvuRed, cvuGreen, cvuBlue; %@AB@%/* Unsigned portions of */%@AE@%%@NL@%
- static int mode = -1; %@AB@%/* color values */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Terminate if not graphics mode. */%@AE@%%@NL@%
- if( !vc->numxpixels )%@NL@%
- return 0;%@NL@%
- %@NL@%
- %@AB@%/* If mode has changed, set window coordinates. */%@AE@%%@NL@%
- if( mode != vc->mode )%@NL@%
- {%@NL@%
- mode = vc->mode;%@NL@%
- tc.xsLeft = tc.ysTop = 0;%@NL@%
- tc.xsRight = vc->numxpixels - 1;%@NL@%
- tc.ysBot = vc->numypixels - 1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Set palette flag. */%@AE@%%@NL@%
- switch( vc->adapter )%@NL@%
- {%@NL@%
- case _MDPA:%@NL@%
- case _CGA:%@NL@%
- case _OCGA:%@NL@%
- case _HGC:%@NL@%
- tc.fPalette = FALSE;%@NL@%
- break;%@NL@%
- default:%@NL@%
- tc.fPalette = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Set palette defaults. */%@AE@%%@NL@%
- switch( vc->mode )%@NL@%
- {%@NL@%
- case _HRESBW:%@NL@%
- case _HERCMONO:%@NL@%
- case _ERESNOCOLOR:%@NL@%
- case _ORESCOLOR:%@NL@%
- case _VRES2COLOR:%@NL@%
- tc.ccv = 0;%@NL@%
- tc.cci = 2;%@NL@%
- return Home();%@NL@%
- case _MRES256COLOR: %@AB@%/* Active bits in this order: */%@AE@%%@NL@%
- cvuInc = 12;%@NL@%
- tc.ccv = tc.cci = 125; %@AB@%/* ???????? ??bbbbbb ??gggggg ??rrrrrr */%@AE@%%@NL@%
- break;%@NL@%
- case _ERESCOLOR:%@NL@%
- if( vc->memory == 64 )%@NL@%
- {%@NL@%
- cvuInc = 32;%@NL@%
- tc.ccv = 16; %@AB@%/* ???????? ??????Bb ??????Gg ??????Rr */%@AE@%%@NL@%
- tc.cci = 4;%@NL@%
- break;%@NL@%
- } %@AB@%/* Else fall through */%@AE@%%@NL@%
- case _VRES16COLOR:%@NL@%
- cvuInc = 16;%@NL@%
- tc.ccv = 64; %@AB@%/* ???????? ??????bb ??????gg ??????rr */%@AE@%%@NL@%
- tc.cci = 16;%@NL@%
- break;%@NL@%
- case _MRES4COLOR:%@NL@%
- case _MRESNOCOLOR:%@NL@%
- cvuInc = 32;%@NL@%
- tc.ccv = 16; %@AB@%/* ???????? ??????Bb ??????Gg ??????Rr */%@AE@%%@NL@%
- tc.cci = 4;%@NL@%
- break;%@NL@%
- case _MRES16COLOR:%@NL@%
- case _HRES16COLOR:%@NL@%
- cvuInc = 32;%@NL@%
- tc.cci = tc.ccv = 16; %@AB@%/* ???????? ??????Bb ??????Gg ??????Rr */%@AE@%%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Fill palette arrays. */%@AE@%%@NL@%
- for( i = 0, cvuBlue = 0; cvuBlue < 64; cvuBlue += cvuInc )%@NL@%
- for( cvuGreen = 0; cvuGreen < 64; cvuGreen += cvuInc )%@NL@%
- for( cvuRed = 0; cvuRed < 64; cvuRed += cvuInc )%@NL@%
- {%@NL@%
- cvlColors[i] = RGB( cvuRed, cvuGreen, cvuBlue );%@NL@%
- %@AB@%/* Special case of 6 bits for 16 colors (RGBI).%@NL@%
- %@AB@% * If both bits are on for any color, intensity is set.%@NL@%
- %@AB@% * If one bit is set for a color, that color is on.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( cvuInc == 32 )%@NL@%
- cvlColors[i + 8] = cvlColors[i] | (cvlColors[i] >> 1);%@NL@%
- i++;%@NL@%
- }%@NL@%
- cvlColors[tc.ccv - 1] = _BRIGHTWHITE;%@NL@%
- NextColorValue( DEFAULT );%@NL@%
- return Home();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Home - Resets turtle defaults. This function can be called if you have%@NL@%
- %@AB@% * not changed the video mode, but you want to put the turtle back in%@NL@%
- %@AB@% * the center of the window and restore all defaults. For example, you can%@NL@%
- %@AB@% * change the absolute window corners and then call it to set a new%@NL@%
- %@AB@% * turtle window.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 0 if fail, 1 if success%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short Home()%@NL@%
- {%@NL@%
- struct _wxycoord xy1, xy2;%@NL@%
- %@NL@%
- _setviewport( tc.xsLeft, tc.ysTop, tc.xsRight, tc.ysBot );%@NL@%
- %@NL@%
- %@AB@%/* Set the window based on screen height 1000 and width based on%@NL@%
- %@AB@% * aspect ratio.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- tc.yMax = 500.0;%@NL@%
- tc.xMax = tc.yMax * tc.yxRatio;%@NL@%
- if( !_setwindow( FALSE, -tc.xMax, -tc.yMax, tc.xMax, tc.yMax ) )%@NL@%
- return 0;%@NL@%
- %@NL@%
- %@AB@%/* Calculate the unit size of 1 pixel using Y axis. */%@AE@%%@NL@%
- xy1 = _getwindowcoord( 1, 1 );%@NL@%
- xy2 = _getwindowcoord( 1, 2 );%@NL@%
- tc.yUnit = xy2.wy - xy1.wy;%@NL@%
- %@NL@%
- %@AB@%/* Set defaults for current pixel, angle, pen state and fill state. */%@AE@%%@NL@%
- tc.xCur = tc.yCur = 0.0;%@NL@%
- _moveto_w( tc.xCur, tc.yCur );%@NL@%
- TurnTo( 0 );%@NL@%
- PenDown( TRUE );%@NL@%
- SetFill( FALSE );%@NL@%
- %@NL@%
- %@AB@%/* Make white the last color index and set pen and border to it. */%@AE@%%@NL@%
- _remappalette( WHITE, _BRIGHTWHITE );%@NL@%
- BorderColor( WHITE );%@NL@%
- PenColor( WHITE );%@NL@%
- _setbkcolor( _BLACK );%@NL@%
- return 1;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* PenDown - Sets the visibility of the pen used by Move and MoveTo. The%@NL@%
- %@AB@% * state can be TRUE (visible), FALSE (invisible), or DEFAULT (return%@NL@%
- %@AB@% * current without changing).%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: fPenDown%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: current pen state%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int PenDown( int fPenDown )%@NL@%
- {%@NL@%
- switch( fPenDown )%@NL@%
- {%@NL@%
- case DEFAULT:%@NL@%
- break;%@NL@%
- case FALSE:%@NL@%
- tc.fPenDown = FALSE;%@NL@%
- break;%@NL@%
- default:%@NL@%
- tc.fPenDown = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- return tc.fPenDown;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* SetFill - Determines the state of filling figures such as Rectangle,%@NL@%
- %@AB@% * Circle, and Ellipse. State can be TRUE (fill inside), FALSE (border%@NL@%
- %@AB@% * only), or DEFAULT (return current fill state).%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: fFill%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: current fill state%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short SetFill( short fFill )%@NL@%
- {%@NL@%
- switch( fFill )%@NL@%
- {%@NL@%
- case DEFAULT:%@NL@%
- break;%@NL@%
- case _GBORDER:%@NL@%
- case FALSE:%@NL@%
- tc.fFill = _GBORDER;%@NL@%
- break;%@NL@%
- default:%@NL@%
- tc.fFill = _GFILLINTERIOR;%@NL@%
- break;%@NL@%
- }%@NL@%
- return tc.fFill;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* PenColor - Sets the color index of the pen.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: ciCur - any color index of DEFAULT to return without changing%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: current pen color index%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short PenColor( short ciCur )%@NL@%
- {%@NL@%
- if( ciCur != DEFAULT )%@NL@%
- _setcolor( tc.ciCur = ciCur );%@NL@%
- return tc.ciCur;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* BorderColor - Sets the color index of the border that will be recognized%@NL@%
- %@AB@% * by fills.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: ciBorder - any color index of DEFAULT to return without changing%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: current border color index%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short BorderColor( short border )%@NL@%
- {%@NL@%
- if( border != DEFAULT )%@NL@%
- tc.ciBorder = border;%@NL@%
- return tc.ciBorder;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Turn - Sets a new direction relative to the current direction.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: angCur - a positive (clockwise) or negative (counterclockwise)%@NL@%
- %@AB@% * angle in degrees%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: new current absolute angle%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short Turn( short angCur )%@NL@%
- {%@NL@%
- return( tc.angCur = ((tc.angCur + angCur) % CIRCUMFERENCE) );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* TurnTo - Sets a new absolute direction.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: angCur - a positive (clockwise) or negative (counterclockwise)%@NL@%
- %@AB@% * angle in degrees (0 points to 12 o'clock)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: new current absolute angle%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short TurnTo( short angCur )%@NL@%
- {%@NL@%
- if( angCur < 0 )%@NL@%
- return( tc.angCur = 360 - (angCur % CIRCUMFERENCE) );%@NL@%
- else%@NL@%
- return( tc.angCur = angCur % CIRCUMFERENCE );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Move - Moves from the current position in the current direction for a%@NL@%
- %@AB@% * specified distance. A line is drawn if the pen is down. The current%@NL@%
- %@AB@% * position is reset to the destination.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: dxy - difference between current xy and new xy%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 0 if new position is off screen, nonzero if on screen%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short Move( double dxy )%@NL@%
- {%@NL@%
- double dx, dy; %@AB@%/* Differences of X and Y */%@AE@%%@NL@%
- double angT;%@NL@%
- %@NL@%
- %@AB@%/* Calculate new X and Y positions. */%@AE@%%@NL@%
- angT = (tc.angCur - 90) * (PI / HALFCIRCUMFERENCE);%@NL@%
- dx = dxy * cos( angT );%@NL@%
- dy = dxy * sin( angT );%@NL@%
- %@NL@%
- %@AB@%/* Move, drawing if pen down, then update position */%@AE@%%@NL@%
- if( tc.fPenDown )%@NL@%
- _lineto_w( tc.xCur + dx, tc.yCur + dy );%@NL@%
- else%@NL@%
- _moveto_w( tc.xCur + dx, tc.yCur + dy );%@NL@%
- tc.xCur += dx;%@NL@%
- tc.yCur += dy;%@NL@%
- return OnScreen();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* MoveTo - Moves from the current position to a specified position. A%@NL@%
- %@AB@% * line is drawn if the pen is down. The current position is reset to the%@NL@%
- %@AB@% * destination. The current direction is not changed.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: x and y - destination position%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 0 if new position is off screen, nonzero if on screen%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short MoveTo( double x, double y )%@NL@%
- {%@NL@%
- if( tc.fPenDown )%@NL@%
- _lineto_w( x, y );%@NL@%
- else%@NL@%
- _moveto_w( x, y );%@NL@%
- tc.xCur = x;%@NL@%
- tc.yCur = y;%@NL@%
- return OnScreen();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Poly - Draws a polygon.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: cSide - count of polygon sides%@NL@%
- %@AB@% * dxySide - distance of each side%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: 0 if any part of polygon is off screen, nonzero if on screen%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short Poly( int cSide, double dxySide )%@NL@%
- {%@NL@%
- short i, angT, fPen, ret = TRUE;%@NL@%
- %@NL@%
- %@AB@%/* Make sure pen is down (restore pen state when done). */%@AE@%%@NL@%
- fPen = PenDown( TRUE );%@NL@%
- %@NL@%
- %@AB@%/* Calculate angle, then draw each side. */%@AE@%%@NL@%
- angT = 360 / cSide;%@NL@%
- for( i = 1; i <= cSide; i++ )%@NL@%
- {%@NL@%
- ret = Move( dxySide ) && ret;%@NL@%
- Turn( angT );%@NL@%
- }%@NL@%
- PenDown( fPen );%@NL@%
- return ret;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* NextColorIndex - Rotate to next color index. First attribute (normally%@NL@%
- %@AB@% * background) and last attribute (white) are skipped.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: ciCur - Specify DEFAULT to use color index from last call,%@NL@%
- %@AB@% * or specify a new color to rotate from%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: rotated color index%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- short NextColorIndex( short ciCur )%@NL@%
- {%@NL@%
- static short ciPrev = 0; %@AB@%/* Static to retain index between calls */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Assign new current if given. */%@AE@%%@NL@%
- if( ciCur != DEFAULT )%@NL@%
- ciPrev = ciCur;%@NL@%
- %@NL@%
- %@AB@%/* Toggle for two-color modes, rotate for multi-color modes. */%@AE@%%@NL@%
- if( tc.cci == 2 )%@NL@%
- return( ciPrev = !ciPrev );%@NL@%
- else%@NL@%
- return( ciPrev = (++ciPrev % (tc.cci - 1)) );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* NextColorValue - Rotate to next color value for adapters (EGA%@NL@%
- %@AB@% * and higher) that support remappable palettes.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: fAction - DEFAULT (rotate all) or LIMITED (rotate first 14 only)%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: tc%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void NextColorValue( int fAction )%@NL@%
- {%@NL@%
- static int icvCur = 1; %@AB@%/* Current index into color value array */%@AE@%%@NL@%
- static int ciCur = 1; %@AB@%/* Current color index */%@AE@%%@NL@%
- int icvT; %@AB@%/* Temporary index into color values */%@AE@%%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* Ignore modes with no palette values. */%@AE@%%@NL@%
- if( !tc.fPalette || !tc.ccv )%@NL@%
- return;%@NL@%
- %@NL@%
- %@AB@%/* Increment and rotate color value index. */%@AE@%%@NL@%
- icvT = (++icvCur % (tc.ccv - 2)) + 1;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* DEFAULT - Remap all color indexes, 14 at a time. For most modes,%@NL@%
- %@AB@% * this is all the indexes except first and last. For 256-color%@NL@%
- %@AB@% * mode, rotating all available indexes would be too slow.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( fAction == DEFAULT )%@NL@%
- for( i = 1; i <= 14; i++ )%@NL@%
- _remappalette( (ciCur++ % (tc.cci - 2)) + 1,%@NL@%
- cvlColors[(icvT++ % (tc.ccv - 2)) + 1] );%@NL@%
- %@NL@%
- %@AB@%/* LIMITED - Rotate only the first 14 color indexes. */%@AE@%%@NL@%
- else%@NL@%
- for( i = 1; i <= 14; i++ )%@NL@%
- _remappalette( i, cvlColors[(icvT++ % (tc.ccv - 1)) + 1] );%@NL@%
- }%@NL@%
- %@1@%%@AH@%Microsoft Quick-C Sample Code%@EH@%%@AE@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARGV.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\ARGV.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARGV.C: Demonstrate accessing command-line arguments. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void show_args( char *argument );%@NL@%
- %@NL@%
- int main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count=0; count < argc; count++ )%@NL@%
- show_args( argv[count] );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- void show_args( char *argument )%@NL@%
- {%@NL@%
- printf( "%s\n", argument );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARGV1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\ARGV1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARGV1.C: Demonstrate null pointers. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void show_args( char *argument );%@NL@%
- %@NL@%
- int main( int argc, char **argv )%@NL@%
- {%@NL@%
- while( *argv )%@NL@%
- show_args( *(argv++) );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- void show_args( char *argument )%@NL@%
- {%@NL@%
- printf( "%s\n", argument );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARRAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\ARRAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARRAY.C: Demonstrate one-dimensional array. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int j;%@NL@%
- int i_array[3];%@NL@%
- %@NL@%
- i_array[0] = 176;%@NL@%
- i_array[1] = 4069;%@NL@%
- i_array[2] = 303;%@NL@%
- %@NL@%
- printf( "--- Values -------- --- Addresses -------\n\n" );%@NL@%
- %@NL@%
- for( j = 0; j < 3; j = j + 1 )%@NL@%
- {%@NL@%
- printf( "i_array[%d] = %d", j, i_array[j] );%@NL@%
- printf( "\t&i_array[%d] = %u\n", j, &i_array[j] );%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BAR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BAR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BAR.C: Create sample bar chart. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<pgchart.h> %@NL@%
- %@AI@%#define %@AE@%MONTHS 12 %@NL@%
- typedef enum {FALSE, TRUE} boolean;%@NL@%
- float far value[MONTHS] = %@NL@%
- { %@NL@%
- 33.0, 27.0, 42.0, 64.0,106.0,157.0,%@NL@%
- 182.0,217.0,128.0, 62.0, 43.0, 36.0%@NL@%
- };%@NL@%
- char far *category[MONTHS] =%@NL@%
- {%@NL@%
- "Jan", "Feb", "Mar", "Apr",%@NL@%
- "May", "Jun", "Jly", "Aug",%@NL@%
- "Sep", "Oct", "Nov", "Dec"%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- chartenv env;%@NL@%
- int mode = _VRES16COLOR;%@NL@%
- %@AB@%/* Set highest video mode available */%@AE@%%@NL@%
- while(!_setvideomode( mode ))%@NL@%
- mode--;%@NL@%
- if(mode == _TEXTMONO)%@NL@%
- return(0);%@NL@%
- %@NL@%
- %@AB@%/* Initialize chart library and a default bar chart */%@AE@%%@NL@%
- _pg_initchart();%@NL@%
- %@NL@%
- _pg_defaultchart( &env, _PG_BARCHART, _PG_PLAINBARS %@NL@%
- );%@NL@%
- %@AB@%/* Add titles and some chart options */%@AE@%%@NL@%
- strcpy( env.maintitle.title, "Good Neighbor Grocery" );%@NL@%
- env.maintitle.titlecolor = 6;%@NL@%
- env.maintitle.justify = _PG_RIGHT;%@NL@%
- strcpy( env.subtitle.title, "Orange Juice Sales" );%@NL@%
- env.subtitle.titlecolor = 6;%@NL@%
- env.subtitle.justify = _PG_RIGHT;%@NL@%
- strcpy( env.yaxis.axistitle.title, "Months" );%@NL@%
- strcpy( env.xaxis.axistitle.title, "Quantity (cases)" );%@NL@%
- env.chartwindow.border = FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Parameters for call to _pg_chart are:%@NL@%
- %@AB@% * env - Environment variable%@NL@%
- %@AB@% * category - Category labels%@NL@%
- %@AB@% * value - Data to chart%@NL@%
- %@AB@% * MONTHS - Number of data values */%@AE@%%@NL@%
- %@NL@%
- if(_pg_chart( &env, category, value, MONTHS ))%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _outtext( "Error: can't draw chart" );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- getch(); %@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BEEP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BEEP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BEEP.C: Demonstrate simple function */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void beep( void);%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "Time to beep\n" );%@NL@%
- beep();%@NL@%
- printf( "All done\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void beep( void )%@NL@%
- {%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BEEP1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BEEP1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BEEP1.C: Demonstrate passing arguments */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void beep( int num_beep );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "Time to beep\n" );%@NL@%
- beep( 5 );%@NL@%
- printf( "All done\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void beep( int num_beep )%@NL@%
- {%@NL@%
- while( num_beep > 0 )%@NL@%
- {%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- num_beep = num_beep - 1;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BEEPER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BEEPER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BEEPER.C: Demonstrate simple function */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void beep( void);%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "Time to beep\n" );%@NL@%
- beep();%@NL@%
- printf( "All done\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void beep( void )%@NL@%
- {%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BEEPER1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BEEPER1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BEEPER1.C: Demonstrate passing arguments */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void beep( int num_beep );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "Time to beep\n" );%@NL@%
- beep( 5 );%@NL@%
- printf( "All done\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void beep( int num_beep )%@NL@%
- {%@NL@%
- while( num_beep > 0 )%@NL@%
- {%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- num_beep = num_beep - 1;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BITWISE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BITWISE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BITWISE.C: Demonstrate bitwise operators. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "255 & 15 = %d\n", 255 & 15 );%@NL@%
- printf( "255 | 15 = %d\n", 255 | 15 );%@NL@%
- printf( "255 ^ 15 = %d\n", 255 ^ 15 );%@NL@%
- printf( "2 << 2 = %d\n", 2 << 2 );%@NL@%
- printf( "16 >> 2 = %d\n", 16 >> 2 );%@NL@%
- printf( "~2 = %d\n", ~2 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BREAKER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BREAKER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BREAKER.C: Demonstrate break statement. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press any key. Press Tab to quit.\n" );%@NL@%
- while( 1 )%@NL@%
- {%@NL@%
- ch = getche();%@NL@%
- if( ch == '\t' )%@NL@%
- {%@NL@%
- printf( "\a\nYou pressed Tab\n" );%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BREAKER1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\BREAKER1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BREAKER1.C: Break only exits one loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press any key. Press Enter to quit.\n" );%@NL@%
- do%@NL@%
- {%@NL@%
- while( ( ch = getche() ) != '\r' )%@NL@%
- {%@NL@%
- if( ch == '\t' )%@NL@%
- {%@NL@%
- printf( "\a\nYou pressed Tab\n" );%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- } while( ch != '\r' );%@NL@%
- printf( "\nBye bye." );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CGA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\CGA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CGA.C: Demonstrates CGA colors */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- long bkcolor[8] = %@NL@%
- {_BLACK, _BLUE, _GREEN, _CYAN,%@NL@%
- _RED, _MAGENTA, _BROWN, _WHITE};%@NL@%
- %@NL@%
- char *bkcolor_name [] =%@NL@%
- {"_BLACK", "_BLUE", "_GREEN", "_CYAN",%@NL@%
- "_RED", "_MAGENTA", "_BROWN", "_WHITE"};%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i, j, k;%@NL@%
- _setvideomode( _MRES4COLOR );%@NL@%
- for( i=0; i<= 3; i++ )%@NL@%
- {%@NL@%
- _selectpalette( i );%@NL@%
- for( k=0; k <= 7; k++ )%@NL@%
- {%@NL@%
- _setbkcolor( bkcolor[k] );%@NL@%
- for( j=0; j<=3; j++ )%@NL@%
- {%@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "background color: %8s\n", bkcolor_name[k] );%@NL@%
- printf( "palette: %d\ncolor: %d\n", i, j );%@NL@%
- _setcolor( j );%@NL@%
- _rectangle( _GFILLINTERIOR, 160, 100, 320, 200 );%@NL@%
- getch();%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COLOR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\COLOR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COLOR.C: Sets a medium resolution mode with maximum color choices */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- struct videoconfig vc;%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- if( _setvideomode( _MRES256COLOR ) )%@NL@%
- ;%@NL@%
- else if( _setvideomode( _MRES16COLOR ) )%@NL@%
- ;%@NL@%
- else if( _setvideomode( _MRES4COLOR ) )%@NL@%
- ;%@NL@%
- else {%@NL@%
- printf( "Error: No color graphics capability\n" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- _getvideoconfig( &vc );%@NL@%
- %@NL@%
- printf( "%d available colors\n", vc.numcolors );%@NL@%
- printf( "%d horizontal pixels\n", vc.numxpixels );%@NL@%
- printf( "%d vertical pixels\n", vc.numypixels );%@NL@%
- %@NL@%
- getch();%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COLTEXT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\COLTEXT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COLTEXT.C: Displays text in color */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- char buffer [80];%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int blink,fgd;%@NL@%
- long bgd;%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- printf( "Text color attributes:\n" );%@NL@%
- %@NL@%
- for( blink=0; blink<=16; blink+=16 ) %@NL@%
- {%@NL@%
- for( bgd=0; bgd<8; bgd++ ) %@NL@%
- {%@NL@%
- _setbkcolor( bgd );%@NL@%
- _settextposition( bgd + ((blink / 16) * 9) + 3, 1 );%@NL@%
- _settextcolor( 7 );%@NL@%
- sprintf( buffer, "Bgd: %d Fgd:", bgd );%@NL@%
- _outtext( buffer );%@NL@%
- %@NL@%
- for( fgd=0; fgd<16; fgd++ ) %@NL@%
- {%@NL@%
- _settextcolor( fgd+blink );%@NL@%
- sprintf( buffer, " %2d ", fgd+blink );%@NL@%
- _outtext( buffer );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\CONT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CONT.C: Demonstrate continue statement. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count = 0; count < 10; count++ )%@NL@%
- {%@NL@%
- if( count > 3 )%@NL@%
- continue;%@NL@%
- printf( "count = %d\n", count );%@NL@%
- }%@NL@%
- printf( "Done!\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONVERT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\CONVERT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CONVERT.C: Demonstrate type conversions. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char c_val = 10;%@NL@%
- int i_val = 20;%@NL@%
- long l_val = 64000;%@NL@%
- float f_val = 3.1;%@NL@%
- int result;%@NL@%
- %@NL@%
- result = c_val + i_val + l_val + f_val; %@AB@%/* Error! */%@AE@%%@NL@%
- %@NL@%
- printf( "%d\n", result );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COPYFILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\COPYFILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COPYFILE.C: Demonstrate malloc and free functions */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* printf function and NULL */%@AE@%%@NL@%
- <io.h> %@AB@%/* low-level I/O functions */%@AE@%%@NL@%
- <conio.h> %@AB@%/* getch function */%@AE@%%@NL@%
- <sys\types.h> %@AB@%/* struct members used in stat.h */%@AE@%%@NL@%
- <sys\stat.h> %@AB@%/* S_ constants */%@AE@%%@NL@%
- <fcntl.h> %@AB@%/* O_ constants */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* malloc function */%@AE@%%@NL@%
- <errno.h> %@AB@%/* errno global variable */%@AE@%%@NL@%
- %@NL@%
- int copyfile( char *source, char *destin );%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- if( argc == 3 )%@NL@%
- if( copyfile( argv[1], argv[2] ) )%@NL@%
- printf( "Copy failed\n" );%@NL@%
- else%@NL@%
- printf( "Copy successful\n" );%@NL@%
- else%@NL@%
- printf( " SYNTAX: COPYFILE <source> <target>\n" );%@NL@%
- %@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- int copyfile( char *source, char *target )%@NL@%
- {%@NL@%
- char *buf;%@NL@%
- int hsource, htarget, ch;%@NL@%
- unsigned count = 50000;%@NL@%
- %@NL@%
- if( (hsource = open( source, O_BINARY | O_RDONLY )) == - 1 )%@NL@%
- return errno;%@NL@%
- htarget = open( target, O_BINARY | O_WRONLY | O_CREAT | O_EXCL,%@NL@%
- S_IREAD | S_IWRITE );%@NL@%
- if( errno == EEXIST )%@NL@%
- {%@NL@%
- cputs( "Target exists. Overwrite? " );%@NL@%
- ch = getch();%@NL@%
- if( (ch == 'y') || (ch == 'Y') )%@NL@%
- htarget = open( target, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC,%@NL@%
- S_IREAD | S_IWRITE );%@NL@%
- printf( "\n" );%@NL@%
- }%@NL@%
- if( htarget == -1 )%@NL@%
- return errno;%@NL@%
- %@NL@%
- if( filelength( hsource ) < count )%@NL@%
- count = (int)filelength( hsource );%@NL@%
- %@NL@%
- buf = (char *)malloc( (size_t)count );%@NL@%
- %@NL@%
- if( buf == NULL )%@NL@%
- {%@NL@%
- count = _memmax();%@NL@%
- buf = (char *)malloc( (size_t)count );%@NL@%
- if( buf == NULL )%@NL@%
- return ENOMEM;%@NL@%
- }%@NL@%
- %@NL@%
- while( !eof( hsource ) )%@NL@%
- {%@NL@%
- if( (count = read( hsource, buf, count )) == -1 )%@NL@%
- return errno;%@NL@%
- if( (count = write( htarget, buf, count )) == - 1 )%@NL@%
- return errno;%@NL@%
- }%@NL@%
- %@NL@%
- close( hsource );%@NL@%
- close( htarget );%@NL@%
- free( buf );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DECRMENT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\DECRMENT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DECRMENT.C: Demonstrate prefix and postfix operators. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val, sample = 3, proton = 3;%@NL@%
- val = sample--;%@NL@%
- printf( "val = %d sample = %d\n", val, sample );%@NL@%
- val = --proton;%@NL@%
- printf( "val = %d proton = %d\n", val, proton );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DEFINED.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\DEFINED.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DEFINED.C: Demonstrate defined operator. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%DEBUG 12345 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- #if defined( DEBUG )%@NL@%
- printf( "Hi\n" );%@NL@%
- #endif%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\DO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DO.C: Demonstrate do loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int test = 10;%@NL@%
- do%@NL@%
- {%@NL@%
- printf( "test = %d\n", test );%@NL@%
- test = test - 2;%@NL@%
- } while( test > 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EGA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\EGA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EGA.C: Demonstrates EGA palettes */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- _setvideomode( _ERESCOLOR );%@NL@%
- _setcolor( 4 );%@NL@%
- _rectangle( _GFILLINTERIOR, 50, 50, 200, 200 );%@NL@%
- %@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Normal palette\n" );%@NL@%
- printf( "Press a key" );%@NL@%
- getch();%@NL@%
- %@NL@%
- _remappalette( 4, _BLUE );%@NL@%
- %@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Remapped palette\n" );%@NL@%
- printf( "Press a key" );%@NL@%
- getch();%@NL@%
- %@NL@%
- _remappalette( 4, _RED );%@NL@%
- %@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Restored palette\n" );%@NL@%
- printf( "Press a key to clear the screen" );%@NL@%
- getch();%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ELSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\ELSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ELSE.C: Demonstrate else clause. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getch();%@NL@%
- if( ch == 'b' )%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- else%@NL@%
- printf( "Bye bye\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ELSE1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\ELSE1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ELSE1.C: Demonstrate else-if construct. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getch();%@NL@%
- if( ch == 'b' )%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- else%@NL@%
- if( ch == '\r' )%@NL@%
- printf( "Enter\n" );%@NL@%
- else%@NL@%
- printf( "Bye bye\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EMPLOY1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\EMPLOY1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EMPLOY1.C: Demonstrate structure pointers. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@NL@%
- struct employee%@NL@%
- {%@NL@%
- char name[10];%@NL@%
- int months;%@NL@%
- float wage;%@NL@%
- };%@NL@%
- %@NL@%
- void display( struct employee *e_ptr );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static struct employee jones =%@NL@%
- {%@NL@%
- "Jones, J",%@NL@%
- 77,%@NL@%
- 13.68%@NL@%
- };%@NL@%
- %@NL@%
- display( &jones );%@NL@%
- }%@NL@%
- %@NL@%
- void display( struct employee *e_ptr )%@NL@%
- {%@NL@%
- printf( "Name: %s\n", e_ptr->name );%@NL@%
- printf( "Months of service: %d\n", e_ptr->months );%@NL@%
- printf( "Hourly wage: %6.2f\n", e_ptr->wage );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EMPLOYEE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\EMPLOYEE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EMPLOYEE.C: Demonstrate structures. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- struct employee%@NL@%
- {%@NL@%
- char name[10];%@NL@%
- int months;%@NL@%
- float wage;%@NL@%
- };%@NL@%
- %@NL@%
- void display( struct employee show );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- struct employee jones;%@NL@%
- %@NL@%
- strcpy( jones.name, "Jones, J" );%@NL@%
- jones.months = 77;%@NL@%
- jones.wage = 13.68;%@NL@%
- %@NL@%
- display( jones );%@NL@%
- }%@NL@%
- %@NL@%
- void display( struct employee show )%@NL@%
- {%@NL@%
- printf( "Name: %s\n", show.name );%@NL@%
- printf( "Months of service: %d\n", show.months );%@NL@%
- printf( "Hourly wage: %6.2f\n", show.wage );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FILE1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FILE1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FILE1.C: Visibility in multiple source files.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- int chico = 20, harpo = 30;%@NL@%
- extern void yonder( void );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- yonder();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FILE2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FILE2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FILE2.C: Visibility in multiple source files.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void yonder( void )%@NL@%
- {%@NL@%
- extern int chico, harpo;%@NL@%
- printf( "chico = %d, harpo = %d\n", chico, harpo );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FORLOOP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FORLOOP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FORLOOP.C: Demonstrate for loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int test;%@NL@%
- for( test = 10; test > 0; test = test - 2 )%@NL@%
- printf( "test = %d\n", test );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FORLOOP1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FORLOOP1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FORLOOP1.C: Demonstrate multiple expressions. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a, b;%@NL@%
- for( a = 256, b = 1; b < 512; a = a / 2, b = b * 2 )%@NL@%
- printf( "a = %d b = %d\n", a, b );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FORLOOP2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FORLOOP2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FORLOOP2.C: Demonstrate similarity of for and while.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- %@NL@%
- for( count = 0; count < 10; count++ )%@NL@%
- printf( "count = %d\n", count );%@NL@%
- %@NL@%
- count = 0;%@NL@%
- while( count < 10 )%@NL@%
- {%@NL@%
- printf( "count = %d\n", count );%@NL@%
- count++;%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FUNCPTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FUNCPTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FUNCPTR.C: Demonstrate function pointers. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int (*func_ptr) ();%@NL@%
- func_ptr = printf;%@NL@%
- (*func_ptr) ( "Curiouser and curiouser...\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FUNCPTR1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\FUNCPTR1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FUNCPTR1.C: Passing function pointers as arguments. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void gimme_func( void (*func_ptr) () );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- gimme_func( puts );%@NL@%
- gimme_func( printf );%@NL@%
- }%@NL@%
- %@NL@%
- void gimme_func( void (*func_ptr) () )%@NL@%
- {%@NL@%
- (*func_ptr) ( "Ausgezeichnet!" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GRAPHIC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\GRAPHIC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GRAPHIC.C: Displays every graphics mode */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- struct videoconfig screen;%@NL@%
- int modes[12] =%@NL@%
- {%@NL@%
- _MRES4COLOR, _MRESNOCOLOR, _HRESBW,%@NL@%
- _HERCMONO,%@NL@%
- _MRES16COLOR, _HRES16COLOR, _ERESNOCOLOR, _ERESCOLOR,%@NL@%
- _VRES2COLOR, _VRES16COLOR, _MRES256COLOR, _ORESCOLOR%@NL@%
- };%@NL@%
- %@NL@%
- void print_menu( void );%@NL@%
- void show_mode( char );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char key;%@NL@%
- print_menu();%@NL@%
- while( (key = getch()) != 'x' )%@NL@%
- show_mode( key );%@NL@%
- }%@NL@%
- %@NL@%
- void print_menu( void )%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- printf( "Please choose a graphics mode\nType 'x' to exit.\n\n" );%@NL@%
- printf( "0 _MRES4COLOR\n1 _MRESNOCOLOR\n2 _HRESBW\n" );%@NL@%
- printf( "3 _HERCMONO\n4 _MRES16COLOR\n5 _HRES16COLOR\n" );%@NL@%
- printf( "6 _ERESNOCOLOR\n7 _ERESCOLOR\n" );%@NL@%
- printf( "8 _VRES2COLOR\n9 _VRES16COLOR\na _MRES256COLOR\n" );%@NL@%
- printf( "b _ORESCOLOR\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void show_mode( char which )%@NL@%
- {%@NL@%
- int nc, i;%@NL@%
- int height, width;%@NL@%
- int mode = which;%@NL@%
- %@NL@%
- if( mode < '0' || mode > '9' )%@NL@%
- if( mode == 'a' )%@NL@%
- mode = '9' + 1;%@NL@%
- else if( mode == 'b' )%@NL@%
- mode = '9' + 2;%@NL@%
- else%@NL@%
- return;%@NL@%
- %@NL@%
- if( _setvideomode( modes[mode - '0'] ) )%@NL@%
- {%@NL@%
- _getvideoconfig( &screen );%@NL@%
- nc = screen.numcolors;%@NL@%
- width = screen.numxpixels/nc;%@NL@%
- height = screen.numypixels/2;%@NL@%
- for( i = 0; i < nc; i++ )%@NL@%
- {%@NL@%
- _setcolor( i );%@NL@%
- _rectangle( _GFILLINTERIOR, i * width, 0, (i + 1) * width, height );%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( " \nVideo mode %c is not available.\n", which);%@NL@%
- printf( "Please press a key.\n" );%@NL@%
- }%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- print_menu();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HORIZON.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\HORIZON.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* HORIZON.C: VGA graphics with cycling of 256 colors */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%RED 0x0000003FL %@NL@%
- %@AI@%#define %@AE@%GRN 0x00003F00L %@NL@%
- %@AI@%#define %@AE@%BLU 0x003F0000L %@NL@%
- %@AI@%#define %@AE@%WHT 0x003F3F3FL %@NL@%
- %@AI@%#define %@AE@%STEP 21 %@NL@%
- %@NL@%
- struct videoconfig screen;%@NL@%
- long int rainbow[512];%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- long int col, gray;%@NL@%
- %@NL@%
- if( _setvideomode( _MRES256COLOR ) == 0 )%@NL@%
- {%@NL@%
- printf("This program requires a VGA card.\n" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- for( col = 0; col < 64; col++ )%@NL@%
- {%@NL@%
- gray = col | (col << 8) | (col << 16);%@NL@%
- rainbow[col] = rainbow[col + 256] = BLU & gray;%@NL@%
- rainbow[col + 64] = rainbow[col + 64 + 256] = BLU | gray;%@NL@%
- rainbow[col + 128] = rainbow[col + 128 + 256] = RED | (WHT & ~gray);%@NL@%
- rainbow[col + 192] = rainbow[col + 192 + 256] = RED & ~gray;%@NL@%
- }%@NL@%
- _setvieworg( 160, 85 );%@NL@%
- %@NL@%
- for( i = 0; i < 255; i++ )%@NL@%
- {%@NL@%
- _setcolor( 255 - i );%@NL@%
- _moveto( i, i - 255 );%@NL@%
- _lineto( -i, 255 - i );%@NL@%
- _moveto( -i, i - 255 );%@NL@%
- _lineto( i, 255 - i );%@NL@%
- _ellipse( _GBORDER, -i, -i / 2, i, i / 2 );%@NL@%
- }%@NL@%
- for( i = 0; !kbhit(); i += STEP, i %= 256 )%@NL@%
- _remapallpalette( &(rainbow[i]) );%@NL@%
- %@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%IFF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\IFF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* IFF.C: Demonstrate if statement. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getche();%@NL@%
- if( ch == 'b' )%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INPUT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\INPUT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* INPUT.C: Reads keyboard. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num, c;%@NL@%
- char name[80];%@NL@%
- float rb;%@NL@%
- %@NL@%
- puts( "** Type \"Name:\" and your name" );%@NL@%
- scanf( "Name: %40s", name );%@NL@%
- printf( "** You typed this:\n%s", name );%@NL@%
- puts( "\n\n** Try again, with the gets function." );%@NL@%
- fflush( stdin );%@NL@%
- gets( name );%@NL@%
- printf( "** You typed this:\n%s\n", name );%@NL@%
- %@NL@%
- printf( "\n** Now type an integer.\n" );%@NL@%
- scanf( "%i", &num );%@NL@%
- sprintf( name, "** You typed this number: %i\n", num );%@NL@%
- puts( name );%@NL@%
- %@NL@%
- fflush( stdin );%@NL@%
- printf( "** Enter a floating-point value.\n" );%@NL@%
- scanf( "%f", &rb );%@NL@%
- printf( "** The answer is %f or %e\n", rb, rb );%@NL@%
- %@NL@%
- printf( "** Continue? Y or N\n" );%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- c = getch();%@NL@%
- c = tolower( c );%@NL@%
- } while( c != 'y' && c != 'n' );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MACRO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\MACRO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MACRO.C: Demonstrate macros. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%ABS(value) ( (value) >= 0 ? (value) : -(value) ) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = -20;%@NL@%
- printf( "result = %d\n", ABS(val) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NFORMAT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\NFORMAT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* NFORMAT.C: Prints numbers and a string. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a = -765,%@NL@%
- b = 1,%@NL@%
- c = 44000,%@NL@%
- d = 33;%@NL@%
- float e = 1.33E8,%@NL@%
- f = -0.1234567,%@NL@%
- g = 12345.6789,%@NL@%
- h = 1.0;%@NL@%
- char i[80];%@NL@%
- %@NL@%
- strcpy( i, "word 1, word 2, word 3, word 4, word 5" );%@NL@%
- %@NL@%
- printf( "Unformatted:\n%d %d %d %d\n", a, b, c, d );%@NL@%
- printf( "%f %f %f %f\n", e, f, g, h );%@NL@%
- printf( "%s\n", i );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NOT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\NOT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* NOT.C: Demonstrate logical NOT operator. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 0;%@NL@%
- if( !val )%@NL@%
- printf( "val is zero" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%OLDSTYLE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\OLDSTYLE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* OLDSTYLE.C: Old-style function. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%PI 3.14 %@NL@%
- %@NL@%
- float sphere();%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float volume;%@NL@%
- int radius = 3;%@NL@%
- volume = sphere( radius );%@NL@%
- printf( "Volume: %f\n", volume );%@NL@%
- }%@NL@%
- %@NL@%
- float sphere( rad )%@NL@%
- int rad;%@NL@%
- {%@NL@%
- float result;%@NL@%
- result = rad * rad * rad;%@NL@%
- result = 4 * PI * result;%@NL@%
- result = result / 3;%@NL@%
- return result;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PARRAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PARRAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PARRAY.C: Demonstrate pointer to array. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int i_array[] = { 25, 300, 2, 12 };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int *ptr;%@NL@%
- int count;%@NL@%
- ptr = &i_array[0];%@NL@%
- for( count = 0; count < 4 ; count++ )%@NL@%
- {%@NL@%
- printf( "i_array[%d] = %d\n", count, *ptr );%@NL@%
- ptr++;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PARRAY1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PARRAY1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PARRAY1.C: Compact version of PARRAY.C. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int i_array[] = { 25, 300, 2, 12 };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- int *ptr = i_array;%@NL@%
- for( count = 0; count < 4 ; count++ )%@NL@%
- printf( "i_array[%d] = %d\n", count, *ptr++ );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PFUNC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PFUNC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PFUNC.C: Passing pointers to a function. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void swap( int *ptr1, int *ptr2 );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int first = 1, second = 3;%@NL@%
- int *ptr = &second;%@NL@%
- printf( "first: %d second: %d\n", first, *ptr );%@NL@%
- swap( &first, ptr );%@NL@%
- printf( "first: %d second: %d\n", first, *ptr );%@NL@%
- }%@NL@%
- %@NL@%
- void swap( int *ptr1, int *ptr2 )%@NL@%
- {%@NL@%
- int temp;%@NL@%
- temp = *ptr1;%@NL@%
- *ptr1 = *ptr2;%@NL@%
- *ptr2 = temp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PIE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PIE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PIE.C: Create sample pie chart. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<pgchart.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MONTHS 12 %@NL@%
- %@NL@%
- typedef enum {FALSE, TRUE} boolean;%@NL@%
- %@NL@%
- float far value[MONTHS] = %@NL@%
- {%@NL@%
- 33.0, 27.0, 42.0, 64.0,106.0,157.0,%@NL@%
- 182.0,217.0,128.0, 62.0, 43.0, 36.0%@NL@%
- };%@NL@%
- char far *category[MONTHS] = %@NL@%
- {%@NL@%
- "Jan", "Feb", "Mar", "Apr",%@NL@%
- "May", "Jun", "Jly", "Aug",%@NL@%
- "Sep", "Oct", "Nov", "Dec"%@NL@%
- };%@NL@%
- short far explode[MONTHS] = {0};%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- chartenv env;%@NL@%
- int mode = _VRES16COLOR;%@NL@%
- %@NL@%
- %@AB@%/* Set highest video mode available */%@AE@%%@NL@%
- while(!_setvideomode( mode ))%@NL@%
- mode--;%@NL@%
- if(mode == _TEXTMONO)%@NL@%
- return( 0 );%@NL@%
- %@NL@%
- %@AB@%/* Initialize chart library and a default pie chart */%@AE@%%@NL@%
- _pg_initchart();%@NL@%
- _pg_defaultchart( &env, _PG_PIECHART, _PG_PERCENT );%@NL@%
- %@NL@%
- %@AB@%/* Add titles and some chart options */%@AE@%%@NL@%
- strcpy( env.maintitle.title, "Good Neighbor Grocery" );%@NL@%
- env.maintitle.titlecolor = 6;%@NL@%
- env.maintitle.justify = _PG_RIGHT;%@NL@%
- strcpy( env.subtitle.title, "Orange Juice Sales" ); %@NL@%
- env.subtitle.titlecolor = 6;%@NL@%
- env.subtitle.justify = _PG_RIGHT;%@NL@%
- env.chartwindow.border = FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Parameters for call to _pg_chartpie are:%@NL@%
- %@AB@% * %@NL@%
- %@AB@% * env - Environment variable%@NL@%
- %@AB@% * category - Category labels%@NL@%
- %@AB@% * value - Data to chart%@NL@%
- %@AB@% * explode - Separated pieces%@NL@%
- %@AB@% * MONTHS - Number of data values%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if(_pg_chartpie( &env, category, value,%@NL@%
- explode, MONTHS ))%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _outtext( "Error: can't draw chart" );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- getch(); %@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- return( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%POINTER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\POINTER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* POINTER.C: Demonstrate pointer basics. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 25;%@NL@%
- int *ptr;%@NL@%
- ptr = &val;%@NL@%
- printf( " val = %d\n", val );%@NL@%
- printf( "*ptr = %d\n\n", *ptr );%@NL@%
- printf( "&val = %u\n", &val );%@NL@%
- printf( " ptr = %d\n", ptr );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%POWER2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\POWER2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* POWER2.C */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int power2( int num, int power );%@NL@%
- %@NL@%
- void main( void )%@NL@%
- {%@NL@%
- printf( "3 times 2 to the power of 5 is %d\n", \%@NL@%
- power2( 3, 5) );%@NL@%
- }%@NL@%
- %@NL@%
- int power2( int num, int power )%@NL@%
- {%@NL@%
- _asm%@NL@%
- {%@NL@%
- mov ax, num ; Get first argument%@NL@%
- mov cx, power ; Get second argument%@NL@%
- shl ax, cl ; AX = AX * ( 2 to the power of CL )%@NL@%
- }%@NL@%
- %@AB@%/* Return with result in AX */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PRTESC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PRTESC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PRTESC.C: Prints escape characters \",\n, and \t. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char b[80];%@NL@%
- int i,j;%@NL@%
- %@NL@%
- strcpy( b, "and seven years ago\n" );%@NL@%
- printf( "\"Four score\n" );%@NL@%
- printf( b );%@NL@%
- printf( "\tone tab\n\t\ttwo tabs\n\t\t\tthree tabs\n" );%@NL@%
- i = sizeof( b );%@NL@%
- j = strlen( b );%@NL@%
- printf( "Size is %d\nLength is %d.\n", i, j );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PRTSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PRTSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PRTSTR.C: Prints strings. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char aline[80], more[80];%@NL@%
- char *strptr;%@NL@%
- %@NL@%
- %@AB@%/* aline = "Another line."; */%@AE@%%@NL@%
- %@AB@%/* Note: This causes a compiler error */%@AE@%%@NL@%
- %@NL@%
- strcpy( aline, "Another line." );%@NL@%
- strcpy( more, aline );%@NL@%
- strptr = aline;%@NL@%
- strcat( aline, "dog" );%@NL@%
- printf( "A line of text." );%@NL@%
- printf( aline );%@NL@%
- printf( more );%@NL@%
- printf( strptr );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PSTRING.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PSTRING.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PSTRING.C: Demonstrate pointer to a string. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- static char name[] = "john";%@NL@%
- char *ptr = name;%@NL@%
- for( count = 0; count < 4; count++ )%@NL@%
- {%@NL@%
- printf( "name[%d]: %c\n", count, *ptr++ );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PSTRING1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PSTRING1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PSTRING1.C: Look for null at string's end. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char name[] = "john";%@NL@%
- char *ptr = name;%@NL@%
- while( *ptr )%@NL@%
- printf( "*ptr = %c\n", *ptr++ );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PSTRING2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PSTRING2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PSTRING2.C: Demonstrate strings and array notation. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- char name[] = "john";%@NL@%
- for( count = 0; count < strlen( name ); count++ )%@NL@%
- printf( "name[%d]: %c\n", count, name[count] );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PSTRING3.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PSTRING3.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PSTRING3.C: Strings and pointer notation. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- char name[] = "john";%@NL@%
- for( count = 0; count < strlen( name ); count++ )%@NL@%
- printf( "*(name+%d) = %c\n", count, *(name+count) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PTRPTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\PTRPTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PTRPTR.C: Demonstrate a pointer to a pointer. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 501;%@NL@%
- int *ptr = &val;%@NL@%
- int **ptr_ptr = &ptr;%@NL@%
- printf( "val = %d\n", **ptr_ptr );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%QCSORT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\QCSORT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* QCSORT.C: Demonstrate sorting array of pointers. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%SIZE 4 %@NL@%
- %@NL@%
- void sort( int size, double *p[] );%@NL@%
- void show( int size, double *p[], double dd[] );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int x;%@NL@%
- double d[] = { 3.333, 1.111, 2.222, 4.444 };%@NL@%
- double *d_ptr[SIZE];%@NL@%
- for( x = 0; x < SIZE; x++ )%@NL@%
- d_ptr[x] = &d[x];%@NL@%
- show( SIZE, d_ptr, d );%@NL@%
- sort( SIZE, d_ptr );%@NL@%
- show( SIZE, d_ptr, d );%@NL@%
- }%@NL@%
- %@NL@%
- void sort( int size, double *p[] )%@NL@%
- {%@NL@%
- int x, x1;%@NL@%
- double *temp;%@NL@%
- for( x = 0; x < size - 1; x++ )%@NL@%
- for( x1 = x + 1; x1 < size; x1++ )%@NL@%
- {%@NL@%
- if( *p[x] > *p[x1] )%@NL@%
- {%@NL@%
- temp = p[x1];%@NL@%
- p[x1] = p[x];%@NL@%
- p[x] = temp;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void show( int size, double *p[], double dd[] )%@NL@%
- {%@NL@%
- int x;%@NL@%
- printf( "------------------------" );%@NL@%
- printf( "------------------------\n" );%@NL@%
- for( x = 0; x < size; x++ )%@NL@%
- {%@NL@%
- printf( "*d_ptr[%d] = %1.3f ", x, *p[x]);%@NL@%
- printf( "d_ptr[%d] = %u ", x, p[x]);%@NL@%
- printf( " d[%d] = %1.3f\n", x, dd[x] );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%QCSORT1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\QCSORT1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* QCSORT1.C: Demonstrate sort with pointer notation. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%SIZE 4 %@NL@%
- %@NL@%
- void sort( int size, double **p );%@NL@%
- void show( int size, double **p, double dd[] );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int x;%@NL@%
- double d[] = { 3.333, 1.111, 2.222, 4.444 };%@NL@%
- double *d_ptr[SIZE];%@NL@%
- for( x = 0; x < SIZE; x++ )%@NL@%
- d_ptr[x] = &d[x];%@NL@%
- show( SIZE, d_ptr, d );%@NL@%
- sort( SIZE, d_ptr );%@NL@%
- show( SIZE, d_ptr, d );%@NL@%
- }%@NL@%
- %@NL@%
- void sort( int size, double **p )%@NL@%
- {%@NL@%
- int x, x1;%@NL@%
- double *temp;%@NL@%
- for( x = 0; x < size - 1; x++ )%@NL@%
- for( x1 = x + 1; x1 < size; x1++ )%@NL@%
- {%@NL@%
- if( **(p+x) > **(p+x1) )%@NL@%
- {%@NL@%
- temp = *(p+x1);%@NL@%
- *(p+x1) = *(p+x);%@NL@%
- *(p+x) = temp;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void show( int size, double **p, double dd[] )%@NL@%
- {%@NL@%
- int x;%@NL@%
- printf( "------------------------" );%@NL@%
- printf( "------------------------\n" );%@NL@%
- for( x = 0; x < size; x++ )%@NL@%
- {%@NL@%
- printf( "*d_ptr[%d] = %1.3f ", x, **(p+x) );%@NL@%
- printf( "d_ptr[%d] = %u ", x, *(p+x) );%@NL@%
- printf( " d[%d] = %1.3f\n", x, dd[x] );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RDFILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\RDFILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* RDFILE.C: Reads a file and prints characters to the screen. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int c;%@NL@%
- FILE *fp;%@NL@%
- %@NL@%
- if( fp = fopen( "c:\\testfile.asc", "rb" ) )%@NL@%
- {%@NL@%
- while( (c = fgetc( fp )) != EOF )%@NL@%
- printf( " %c\t%d\n", c, c );%@NL@%
- printf( "\nEnd of file marker: %d", c );%@NL@%
- fclose( fp );%@NL@%
- }%@NL@%
- else%@NL@%
- printf( "Error in opening file\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%REALG.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\REALG.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* REALG.C: Example of real-coordinate graphics */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TRUE 1 %@NL@%
- %@AI@%#define %@AE@%FALSE 0 %@NL@%
- %@NL@%
- int four_colors( void );%@NL@%
- void three_graphs( void );%@NL@%
- void grid_shape( void );%@NL@%
- %@NL@%
- int halfx, halfy;%@NL@%
- struct videoconfig screen;%@NL@%
- double bananas[] =%@NL@%
- { -0.3, -0.2, -0.224, -0.1, -0.5, +0.21, +2.9,%@NL@%
- +0.3, +0.2, 0.0, -0.885, -1.1, -0.3, -0.2,%@NL@%
- +.001, +.005, +0.14, 0.0, -0.9, -0.13, +0.3%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- if( four_colors() )%@NL@%
- three_graphs();%@NL@%
- else%@NL@%
- printf( "This program requires a CGA, EGA, or VGA graphics card.\n" );%@NL@%
- }%@NL@%
- %@NL@%
- int four_colors( void )%@NL@%
- {%@NL@%
- _getvideoconfig( &screen );%@NL@%
- switch( screen.adapter )%@NL@%
- {%@NL@%
- case _CGA:%@NL@%
- case _OCGA:%@NL@%
- _setvideomode( _MRES4COLOR );%@NL@%
- break;%@NL@%
- case _EGA:%@NL@%
- case _OEGA:%@NL@%
- _setvideomode( _ERESCOLOR );%@NL@%
- break;%@NL@%
- case _VGA:%@NL@%
- case _OVGA:%@NL@%
- _setvideomode( _VRES16COLOR );%@NL@%
- break;%@NL@%
- default:%@NL@%
- return( FALSE );%@NL@%
- }%@NL@%
- _getvideoconfig( &screen );%@NL@%
- return( TRUE );%@NL@%
- }%@NL@%
- %@NL@%
- void three_graphs( void )%@NL@%
- {%@NL@%
- int xwidth, yheight, cols, rows;%@NL@%
- struct _wxycoord upleft, botright;%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- xwidth = screen.numxpixels;%@NL@%
- yheight = screen.numypixels;%@NL@%
- halfx = xwidth/2;%@NL@%
- halfy = yheight/2;%@NL@%
- cols = screen.numtextcols;%@NL@%
- rows = screen.numtextrows;%@NL@%
- %@NL@%
- %@AB@%/* first window */%@AE@%%@NL@%
- _setviewport( 0, 0, halfx-1, halfy-1 );%@NL@%
- _settextwindow( 1, 1, rows/2, cols/2 );%@NL@%
- _setwindow( FALSE, -2.0, -2.0, 2.0, 2.0 );%@NL@%
- grid_shape();%@NL@%
- _rectangle( _GBORDER, 0, 0, halfx-1, halfy-1 );%@NL@%
- %@NL@%
- %@AB@%/* second window */%@AE@%%@NL@%
- _setviewport( halfx, 0, xwidth-1, halfy-1 );%@NL@%
- _settextwindow( 1, cols/2+1, rows/2, cols );%@NL@%
- _setwindow( FALSE, -3.0, -3.0, 3.0, 3.0 );%@NL@%
- grid_shape();%@NL@%
- _rectangle_w( _GBORDER, -3.0, -3.0, 3.0, 3.0 ); %@NL@%
- %@NL@%
- %@AB@%/* third window */%@AE@%%@NL@%
- _setviewport( 0, halfy, xwidth-1, yheight-1 );%@NL@%
- _settextwindow( rows/2+1, 1, rows, cols );%@NL@%
- _setwindow( TRUE, -3.0, -1.5, 1.5, 1.5 );%@NL@%
- grid_shape();%@NL@%
- upleft.wx = -3.0;%@NL@%
- upleft.wy = -1.5;%@NL@%
- botright.wx = 1.5;%@NL@%
- botright.wy = 1.5;%@NL@%
- _rectangle_wxy( _GBORDER, &upleft, &botright );%@NL@%
- %@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- void grid_shape( void )%@NL@%
- {%@NL@%
- int i, numc, x1, y1, x2, y2;%@NL@%
- double x, y;%@NL@%
- char txt[80];%@NL@%
- %@NL@%
- numc = screen.numcolors;%@NL@%
- for( i = 1; i < numc; i++ )%@NL@%
- {%@NL@%
- _settextposition( i, 2 );%@NL@%
- _settextcolor( i );%@NL@%
- sprintf( txt, "Color %d", i );%@NL@%
- _outtext( txt );%@NL@%
- }%@NL@%
- %@NL@%
- _setcolor( 1 );%@NL@%
- _rectangle_w( _GBORDER, -1.0, -1.0, 1.0, 1.0 );%@NL@%
- _rectangle_w( _GBORDER, -1.02, -1.02, 1.02, 1.02 );%@NL@%
- %@NL@%
- for( x = -0.9, i = 0; x < 0.9; x += 0.1 )%@NL@%
- {%@NL@%
- _setcolor( 2 );%@NL@%
- _moveto_w( x, -1.0 );%@NL@%
- _lineto_w( x, 1.0 );%@NL@%
- _moveto_w( -1.0, x );%@NL@%
- _lineto_w( 1.0, x );%@NL@%
- %@NL@%
- _setcolor( 3 );%@NL@%
- _moveto_w( x - 0.1, bananas[i++] );%@NL@%
- _lineto_w( x, bananas[i] );%@NL@%
- }%@NL@%
- _moveto_w( 0.9, bananas[i++] );%@NL@%
- _lineto_w( 1.0, bananas[i] );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RWFILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\RWFILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* RWFILE.C: Reads and writes a file. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%BUFF 512 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char inbuffer[BUFF];%@NL@%
- char outbuffer[BUFF];%@NL@%
- int infile, outfile, length, num;%@NL@%
- %@NL@%
- strcpy( outbuffer, "Happy Birthday." );%@NL@%
- length = strlen( outbuffer );%@NL@%
- length++;%@NL@%
- %@NL@%
- if( (outfile = open( "testfile.bin",%@NL@%
- O_CREAT | O_WRONLY | O_BINARY, S_IWRITE )) != -1 )%@NL@%
- {%@NL@%
- if( (num = write( outfile, outbuffer, length )) == -1 )%@NL@%
- perror( "Error in writing" );%@NL@%
- printf( "\nBytes written to file: %d\n", num );%@NL@%
- close( outfile );%@NL@%
- }%@NL@%
- else%@NL@%
- perror( "Error opening outfile" );%@NL@%
- %@NL@%
- if( (infile = open( "testfile.bin", O_RDONLY | O_BINARY )) != -1 )%@NL@%
- {%@NL@%
- while( length = read( infile, inbuffer, BUFF ) )%@NL@%
- printf( "%d bytes received so far.\n", length );%@NL@%
- close( infile );%@NL@%
- printf( "%s\n", inbuffer );%@NL@%
- }%@NL@%
- else%@NL@%
- perror( "Error opening infile" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SAMPLER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SAMPLER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SAMPLER.C: Display sample text in various fonts. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NFONTS 6 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static unsigned char *text[2*NFONTS] =%@NL@%
- {%@NL@%
- "COURIER", "courier",%@NL@%
- "HELV", "helv",%@NL@%
- "TMS RMN", "tms rmn",%@NL@%
- "MODERN", "modern",%@NL@%
- "SCRIPT", "script",%@NL@%
- "ROMAN", "roman"%@NL@%
- };%@NL@%
- static unsigned char *face[NFONTS] =%@NL@%
- {%@NL@%
- "t'courier'",%@NL@%
- "t'helv'",%@NL@%
- "t'tms rmn'",%@NL@%
- "t'modern'",%@NL@%
- "t'script'",%@NL@%
- "t'roman'"%@NL@%
- };%@NL@%
- static unsigned char list[20];%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _VRES16COLOR;%@NL@%
- register i;%@NL@%
- %@NL@%
- %@AB@%/* Read header info from all .FON files in%@NL@%
- %@AB@% * current directory */%@AE@%%@NL@%
- if(_registerfonts( "*.FON" )<0 )%@NL@%
- {%@NL@%
- _outtext("Error: can't register fonts");%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Set highest available video mode */%@AE@%%@NL@%
- while( !_setvideomode( mode ) )%@NL@%
- mode--;%@NL@%
- if( mode == _TEXTMONO )%@NL@%
- exit ( 0 );%@NL@%
- %@NL@%
- %@AB@%/* Copy video configuration into structure vc */%@AE@%%@NL@%
- _getvideoconfig( &vc );%@NL@%
- %@NL@%
- %@AB@%/* Display six lines of sample text */%@AE@%%@NL@%
- for( i = 0; i<NFONTS; i++ )%@NL@%
- {%@NL@%
- strcpy( list, face[i] );%@NL@%
- strcat( list, "h30w24b" );%@NL@%
- %@NL@%
- if( !_setfont( list ) )%@NL@%
- {%@NL@%
- _setcolor( i + 1 );%@NL@%
- _moveto( 0, (i * vc.numypixels) / NFONTS );%@NL@%
- _outgtext( text[i * 2] );%@NL@%
- _moveto( vc.numxpixels / 2,%@NL@%
- (i * vc.numypixels) / NFONTS );%@NL@%
- _outgtext( text[(i * 2) + 1] );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _outtext( "Error: can't set font" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- }%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- %@NL@%
- %@AB@%/* Return memory when finished with fonts */%@AE@%%@NL@%
- _unregisterfonts();%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCATTER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SCATTER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SCATTER.C: Create sample scatter diagram. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<pgchart.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MONTHS 12 %@NL@%
- typedef enum {FALSE, TRUE} boolean;%@NL@%
- %@NL@%
- %@AB@%/* Orange juice sales */%@AE@%%@NL@%
- %@NL@%
- float far xvalue[MONTHS] = %@NL@%
- { %@NL@%
- 33.0, 27.0, 42.0, 64.0,106.0,157.0,%@NL@%
- 182.0,217.0,128.0, 62.0, 43.0, 36.0%@NL@%
- };%@NL@%
- %@AB@%/* Hot chocolate sales */%@AE@%%@NL@%
- %@NL@%
- float far yvalue[MONTHS] = %@NL@%
- { %@NL@%
- 37.0, 37.0, 30.0, 19.0, 10.0, 5.0,%@NL@%
- 2.0, 1.0, 7.0, 15.0, 28.0, 39.0%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- chartenv env;%@NL@%
- int mode = _VRES16COLOR;%@NL@%
- %@NL@%
- %@AB@%/* Set highest video mode available */%@AE@%%@NL@%
- %@NL@%
- while(!_setvideomode( mode ))%@NL@%
- mode--;%@NL@%
- if(mode == _TEXTMONO)%@NL@%
- return(0);%@NL@%
- %@NL@%
- %@AB@%/* Initialize chart library and default%@NL@%
- %@AB@% * scatter diagram%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- _pg_initchart();%@NL@%
- %@NL@%
- _pg_defaultchart( &env, _PG_SCATTERCHART,%@NL@%
- _PG_POINTONLY );%@NL@%
- %@NL@%
- %@AB@%/* Add titles and some chart options */%@AE@%%@NL@%
- %@NL@%
- strcpy( env.maintitle.title, "Good Neighbor Grocery" );%@NL@%
- env.maintitle.titlecolor = 6;%@NL@%
- env.maintitle.justify = _PG_RIGHT;%@NL@%
- strcpy( env.subtitle.title,%@NL@%
- "Orange Juice vs Hot Chocolate" );%@NL@%
- env.subtitle.titlecolor = 6;%@NL@%
- env.subtitle.justify = _PG_RIGHT;%@NL@%
- env.yaxis.grid = TRUE;%@NL@%
- strcpy( env.xaxis.axistitle.title,%@NL@%
- "Orange Juice Sales" );%@NL@%
- strcpy( env.yaxis.axistitle.title,%@NL@%
- "Hot Chocolate Sales" );%@NL@%
- env.chartwindow.border = FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Parameters for call to _pg_chartscatter are:%@NL@%
- %@AB@% * env - Environment variable%@NL@%
- %@AB@% * xvalue - X-axis data%@NL@%
- %@AB@% * yvalue - Y-axis data%@NL@%
- %@AB@% * MONTHS - Number of data values%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- if(_pg_chartscatter( &env, xvalue,%@NL@%
- yvalue, MONTHS ))%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _outtext( "Error: can't draw chart" );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- getch(); %@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- return(0);%@NL@%
- } %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWME.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SHOWME.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SHOWME.C: Demonstrate passing by value. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void showme( int a, int b, int c );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int x = 10, y = 20, z = 30;%@NL@%
- showme( z, y, x );%@NL@%
- }%@NL@%
- %@NL@%
- void showme( int a, int b, int c )%@NL@%
- {%@NL@%
- printf( "a=%d b=%d c=%d", a, b, c );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWMORE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SHOWMORE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SHOWMORE.C: Demonstrate passing by value. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void showme( int any, int old, int name );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int x = 10, y = 20, z = 30;%@NL@%
- showme( z, y, x );%@NL@%
- printf( " z=%d y=%d x=%d\n", z, y, x );%@NL@%
- }%@NL@%
- %@NL@%
- void showme( int any, int old, int name )%@NL@%
- {%@NL@%
- printf( "any=%d old=%d name=%d\n", any, old, name );%@NL@%
- any = 55;%@NL@%
- old = 66;%@NL@%
- name = 77;%@NL@%
- printf( "any=%d old=%d name=%d\n", any, old, name );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SINE.C: Illustrates basic graphics commands */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%PI 3.14159 %@NL@%
- %@NL@%
- void graphics_mode( void );%@NL@%
- void draw_lines( void );%@NL@%
- void sine_wave( void );%@NL@%
- void draw_shapes( void );%@NL@%
- void end_program( void );%@NL@%
- int newx( int );%@NL@%
- int newy( int );%@NL@%
- %@NL@%
- struct videoconfig myscreen;%@NL@%
- int maxx, maxy;%@NL@%
- unsigned char diagmask[8] =%@NL@%
- { 0x93, 0xC9, 0x64, 0xB2, 0x59, 0x2C, 0x96, 0x4B };%@NL@%
- unsigned char linemask[8] =%@NL@%
- { 0xFF, 0x00, 0x7F, 0xFE, 0x00, 0x00, 0x00, 0xCC };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- graphics_mode();%@NL@%
- draw_lines();%@NL@%
- sine_wave();%@NL@%
- draw_shapes();%@NL@%
- end_program();%@NL@%
- }%@NL@%
- %@NL@%
- void graphics_mode( void )%@NL@%
- {%@NL@%
- _getvideoconfig( &myscreen );%@NL@%
- switch( myscreen.adapter )%@NL@%
- {%@NL@%
- case _CGA:%@NL@%
- _setvideomode( _HRESBW );%@NL@%
- break;%@NL@%
- case _OCGA:%@NL@%
- _setvideomode( _ORESCOLOR );%@NL@%
- break;%@NL@%
- case _EGA:%@NL@%
- case _OEGA:%@NL@%
- if( myscreen.monitor == _MONO )%@NL@%
- _setvideomode( _ERESNOCOLOR );%@NL@%
- else%@NL@%
- _setvideomode( _ERESCOLOR );%@NL@%
- break;%@NL@%
- case _VGA:%@NL@%
- case _OVGA:%@NL@%
- case _MCGA:%@NL@%
- _setvideomode( _VRES2COLOR );%@NL@%
- break;%@NL@%
- case _HGC:%@NL@%
- _setvideomode( _HERCMONO );%@NL@%
- break;%@NL@%
- default:%@NL@%
- printf( "This program requires a CGA, EGA, VGA, or Hercules card\n" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- _getvideoconfig( &myscreen );%@NL@%
- maxx = myscreen.numxpixels - 1;%@NL@%
- maxy = myscreen.numypixels - 1;%@NL@%
- }%@NL@%
- %@NL@%
- int newx( int xcoord )%@NL@%
- {%@NL@%
- int nx;%@NL@%
- float tempx;%@NL@%
- tempx = ((float) maxx)/ 1000.0;%@NL@%
- tempx = ((float) xcoord) * tempx + 0.5;%@NL@%
- return( (int) tempx );%@NL@%
- }%@NL@%
- %@NL@%
- int newy( int ycoord )%@NL@%
- {%@NL@%
- int ny;%@NL@%
- float tempy;%@NL@%
- tempy = ((float) maxy)/ 1000.0;%@NL@%
- tempy = ((float) ycoord) * tempy + 0.5;%@NL@%
- return( (int) tempy );%@NL@%
- }%@NL@%
- %@NL@%
- void sine_wave( void )%@NL@%
- {%@NL@%
- int locx, locy;%@NL@%
- double i, rad;%@NL@%
- %@NL@%
- for( i = 0.0; i < 1000.0; i += 3.0 )%@NL@%
- {%@NL@%
- rad = -sin( (PI * (float) i) / 250.0 );%@NL@%
- locx = newx( (int) i );%@NL@%
- locy = newy( (int) (rad * 250.0) );%@NL@%
- _setpixel( locx, locy );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void draw_shapes( void )%@NL@%
- {%@NL@%
- _setlinestyle( 0xFFFF );%@NL@%
- _setfillmask( diagmask );%@NL@%
- _rectangle( _GBORDER, newx(50), newy(-325), newx(200), newy(-425) );%@NL@%
- _rectangle( _GFILLINTERIOR, newx(550), newy(-325), newx(700), newy(-425) );%@NL@%
- %@NL@%
- _setfillmask( linemask );%@NL@%
- _ellipse( _GBORDER, newx(50), newy(325), newx(200), newy(425) );%@NL@%
- _ellipse( _GFILLINTERIOR, newx(550), newy(325), newx(700), newy(425) );%@NL@%
- }%@NL@%
- %@NL@%
- void end_program( void )%@NL@%
- {%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- void draw_lines( void )%@NL@%
- {%@NL@%
- _rectangle( _GBORDER, 0, 0, maxx, maxy );%@NL@%
- %@AB@%/* _setcliprgn( 20, 20, maxx - 20, maxy - 20 ); */%@AE@%%@NL@%
- _setvieworg( 0, newy( 500 ) );%@NL@%
- %@NL@%
- _moveto( 0, 0 );%@NL@%
- _lineto( newx( 1000 ), 0 );%@NL@%
- _setlinestyle( 0xAA3C );%@NL@%
- _moveto( 0, newy( -250) );%@NL@%
- _lineto( newx( 1000 ), newy( -250 ) );%@NL@%
- %@NL@%
- _setlinestyle( 0x8888 );%@NL@%
- _moveto( 0, newy( 250 ) );%@NL@%
- _lineto( newx( 1000 ), newy( 250 ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STATIC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\STATIC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* STATIC.C: Demonstrate static variables. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void add_val( int value );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- add_val( 1 );%@NL@%
- add_val( 5 );%@NL@%
- add_val( 20 );%@NL@%
- }%@NL@%
- %@NL@%
- void add_val( int value )%@NL@%
- {%@NL@%
- static int methuselah;%@NL@%
- if( value == 1 )%@NL@%
- methuselah = 0;%@NL@%
- methuselah = methuselah + value;%@NL@%
- printf( "methuselah = %d\n", methuselah );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRING.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\STRING.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* STRING.C: Demonstrate string arrays. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int j;%@NL@%
- char c_array[] = "Hello";%@NL@%
- %@NL@%
- printf( "--- Values -------- --- Addresses -------\n\n" );%@NL@%
- %@NL@%
- for( j = 0; j < 6; j = j + 1 )%@NL@%
- {%@NL@%
- printf( "c_array[%d] = %x %c", j, c_array[j], c_array[j] );%@NL@%
- printf( "\t&c_array[%d] = %u\n", j, &c_array[j] );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SVBIN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SVBIN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SVBIN.C: Saves integer variables in binary format. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%ASIZE 10 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *ap;%@NL@%
- int zebra[ASIZE], acopy[ASIZE], bcopy[ASIZE];%@NL@%
- int i;%@NL@%
- %@NL@%
- for( i = 0; i < ASIZE; i++ )%@NL@%
- zebra[i] = 7700 + i;%@NL@%
- %@NL@%
- if( (ap = fopen( "binfile", "wb" )) != NULL )%@NL@%
- {%@NL@%
- fwrite( zebra, sizeof(zebra), 1, ap );%@NL@%
- fclose( ap );%@NL@%
- }%@NL@%
- else%@NL@%
- perror( "Write error" );%@NL@%
- %@NL@%
- if( (ap = fopen( "morebin", "wb" )) != NULL )%@NL@%
- {%@NL@%
- fwrite( &zebra[0], sizeof(zebra[0]), ASIZE, ap );%@NL@%
- fclose( ap );%@NL@%
- }%@NL@%
- else%@NL@%
- perror( "Write error" );%@NL@%
- %@NL@%
- if( (ap = fopen( "binfile", "rb" )) != NULL )%@NL@%
- {%@NL@%
- printf( "Hexadecimal values in binfile:\n" );%@NL@%
- while( (i = fgetc( ap )) != EOF )%@NL@%
- printf( "%02X ", i );%@NL@%
- rewind( ap );%@NL@%
- fread( acopy, sizeof(acopy), 1, ap );%@NL@%
- rewind( ap );%@NL@%
- fread( &bcopy[0], sizeof( bcopy[0] ), ASIZE, ap);%@NL@%
- for( i=0; i<ASIZE; i++ )%@NL@%
- printf( "\nItem %d = %d\t%d", i, acopy[i], bcopy[i] );%@NL@%
- fclose( ap );%@NL@%
- %@NL@%
- }%@NL@%
- else%@NL@%
- perror( "Read error" );%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SVTEXT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SVTEXT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SVTEXT.C: Save integer variables as text. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int list[] = { 53, -23456, 50, 500, 5000, -99 };%@NL@%
- extern int errno;%@NL@%
- char fname[] = "numtext";%@NL@%
- char temp[81];%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *fptr;%@NL@%
- int i;%@NL@%
- %@NL@%
- if( (fptr = fopen( "numtext","wt" )) != NULL )%@NL@%
- {%@NL@%
- for( i=0; i<6; i++ )%@NL@%
- fprintf( fptr, "Item %d: %6d \n", i, list[i] );%@NL@%
- fclose( fptr );%@NL@%
- }%@NL@%
- else%@NL@%
- printf( "Error: Couldn't create file.\n" );%@NL@%
- %@NL@%
- if( (fptr = fopen( "badname", "rt" )) != NULL )%@NL@%
- {%@NL@%
- %@AB@%/* do nothing */%@AE@%%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( "Error number: %d\n\t", errno );%@NL@%
- perror( "Couldn't open file BADNAME\n\t" );%@NL@%
- }%@NL@%
- %@NL@%
- if( (fptr = fopen( fname, "rt" )) != NULL )%@NL@%
- {%@NL@%
- list[0] = 0;%@NL@%
- fscanf( fptr, "Item %d: %d \n", &i, &list[0] );%@NL@%
- printf( "Values read from file:\t %d %d\n", i, list[0] );%@NL@%
- fgets( temp, 80, fptr );%@NL@%
- printf( "String from file: \t%s\n", temp );%@NL@%
- while( (i = fgetc( fptr )) != '\n' )%@NL@%
- printf( "char: %c \t ASCII: %d \n", i, i );%@NL@%
- rewind( fptr );%@NL@%
- printf( "Rewind to start -->\t%s", fgets( temp, 80, fptr ) );%@NL@%
- fclose( fptr );%@NL@%
- }%@NL@%
- else%@NL@%
- printf( "Trouble opening %s \n", fname );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SWITCH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\SWITCH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SWITCH.C: Demonstrate switch statement. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getch();%@NL@%
- switch( ch )%@NL@%
- {%@NL@%
- case 'b':%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- break;%@NL@%
- case '\r':%@NL@%
- printf( "Enter\n" );%@NL@%
- break;%@NL@%
- default:%@NL@%
- printf( "Bye bye" );%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TWODIM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\TWODIM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* TWODIM.C: Demonstrate multidimensional arrays. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int j, k;%@NL@%
- int i_array[2][3] = { { 176, 4069, 303 }, { 6, 55, 777 } };%@NL@%
- %@NL@%
- printf( "--- Values -------- --- Addresses -------\n\n" );%@NL@%
- %@NL@%
- for( j = 0; j < 2; j = j + 1 )%@NL@%
- {%@NL@%
- for( k = 0; k < 3; k = k + 1 )%@NL@%
- {%@NL@%
- printf( "i_array[%d][%d] = %d", j, k, i_array[j][k] );%@NL@%
- printf( "\t&i_array[%d][%d] = %u\n", j, k, &i_array[j][k] );%@NL@%
- }%@NL@%
- printf( "\n" );%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TYPES.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\TYPES.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* TYPES.C: Illustrate basic data types. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char char_val = 'a';%@NL@%
- int int_val = 543;%@NL@%
- float float_val = 11.1;%@NL@%
- double double_val = 66.123456789;%@NL@%
- printf( "char_val = %c\n", char_val );%@NL@%
- printf( "int_val = %d\n", int_val );%@NL@%
- printf( "float_val = %f\n", float_val );%@NL@%
- printf( "double_val = %2.9f\n", double_val );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VISIBLE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\VISIBLE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* VISIBLE.C: Demonstrate local visibility. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- void be_bop( void );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 10;%@NL@%
- be_bop();%@NL@%
- }%@NL@%
- %@NL@%
- void be_bop( void )%@NL@%
- {%@NL@%
- printf( "val = %d", val ); %@AB@%/* Error! */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VISIBLE1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\VISIBLE1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* VISIBLE1.C: Demonstrate local visibility. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void be_bop( int param );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 10;%@NL@%
- be_bop( val );%@NL@%
- }%@NL@%
- %@NL@%
- void be_bop( int param )%@NL@%
- {%@NL@%
- printf( "%d\n", param );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VISIBLE2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\VISIBLE2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* VISIBLE2.C: Demonstrate external visibility.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void be_bop( int param );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- be_bop( val ); %@AB@%/* Error! */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- int val = 10;%@NL@%
- %@NL@%
- void be_bop( int param )%@NL@%
- {%@NL@%
- printf( "val = %d\n", param );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VOLUME.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\VOLUME.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* VOLUME.C: Calculate sphere's volume. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%PI 3.14 %@NL@%
- %@NL@%
- float sphere( int rad );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float volume;%@NL@%
- int radius = 3;%@NL@%
- volume = sphere( radius );%@NL@%
- printf( "Volume: %f\n", volume );%@NL@%
- }%@NL@%
- %@NL@%
- float sphere( int rad )%@NL@%
- {%@NL@%
- float result;%@NL@%
- result = rad * rad * rad;%@NL@%
- result = 4 * PI * result;%@NL@%
- result = result / 3;%@NL@%
- return result;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WHILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\WHILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* WHILE.C: Demonstrate while loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int test = 10;%@NL@%
- %@NL@%
- while( test > 0 )%@NL@%
- {%@NL@%
- printf( "test = %d\n", test );%@NL@%
- test = test - 2;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRFILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC\QC25\WRFILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* WRFILE.C: Creates and writes to a disk file. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *fp;%@NL@%
- %@NL@%
- if( (fp = fopen( "c:\\testfile.asc","w" )) != NULL )%@NL@%
- {%@NL@%
- fputs( "Example string", fp );%@NL@%
- fputc( '\n', fp );%@NL@%
- fclose( fp );%@NL@%
- }%@NL@%
- else%@NL@%
- printf( "error message\n" );%@NL@%
- }%@NL@%
- %@1@%%@AH@%Proficient C - Sample Code%@EH@%%@AE@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ANSI_CPR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\ANSI_CPR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ansi_cpr -- report where the cursor is located%@NL@%
- %@AB@% * The position information is placed in the keyboard buffer%@NL@%
- %@AB@% * in the form ESC[rr;ccR where ESC is the value of the%@NL@%
- %@AB@% * ESCAPE character (\033) and r and c represent%@NL@%
- %@AB@% * decimal values of row and column data.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@NL@%
- void%@NL@%
- ansi_cpr(row, col)%@NL@%
- int *row,%@NL@%
- *col;%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* request a cursor position report */%@AE@%%@NL@%
- ANSI_DSR;%@NL@%
- %@NL@%
- %@AB@%/* toss the ESC and '[' */%@AE@%%@NL@%
- (void) getkey();%@NL@%
- (void) getkey();%@NL@%
- %@NL@%
- %@AB@%/* read the row number */%@AE@%%@NL@%
- *row = 10 * (getkey() - '0');%@NL@%
- *row = *row + getkey() - '0';%@NL@%
- %@NL@%
- %@AB@%/* toss the ';' separator */%@AE@%%@NL@%
- (void) getkey();%@NL@%
- %@NL@%
- %@AB@%/* read the column number */%@AE@%%@NL@%
- *col = 10 * (getkey() - '0');%@NL@%
- *col = *col + getkey() - '0';%@NL@%
- %@NL@%
- %@AB@%/* toss the trailing ('R') and return */%@AE@%%@NL@%
- (void) getkey();%@NL@%
- (void) getkey();%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ANSI_TST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\ANSI_TST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ansi_tst -- verify that the ANSI.SYS driver is loaded%@NL@%
- %@AB@% * (prints message and exits is ANSI driver not working)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TST_ROW 2 %@NL@%
- %@AI@%#define %@AE@%TST_COL 75 %@NL@%
- %@NL@%
- void%@NL@%
- ansi_tst()%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- static char *help[] = {%@NL@%
- "\n",%@NL@%
- "ANSI.SYS device driver not loaded:\n",%@NL@%
- " 1. Copy ANSI.SYS to your system disk.\n",%@NL@%
- " 2. Add the line device=ansi.sys to your\n",%@NL@%
- " CONFIG.SYS file and reboot your machine.\n",%@NL@%
- NULL%@NL@%
- };%@NL@%
- char **msg;%@NL@%
- %@NL@%
- extern int getstate();%@NL@%
- extern int readcur(int *, int *, int);%@NL@%
- %@NL@%
- getstate();%@NL@%
- ANSI_CUP(TST_ROW, TST_COL);%@NL@%
- readcur(&row, &col, Vpage);%@NL@%
- if (row != TST_ROW - 1 || col != TST_COL - 1) {%@NL@%
- for (msg = help; *msg != NULL; ++msg)%@NL@%
- fputs(*msg, stderr);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BEEP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\BEEP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * beep -- sound the terminal beeper%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%BEL 7 %@NL@%
- %@NL@%
- void%@NL@%
- beep()%@NL@%
- {%@NL@%
- putchar(BEL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CAT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\CAT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * cat -- concatenate files%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- char *cp;%@NL@%
- FILE *fp;%@NL@%
- BOOLEAN errflag, silent;%@NL@%
- static char pgm[MAXNAME + 1] = { "cat" };%@NL@%
- %@NL@%
- extern void getpname(char *, char *);%@NL@%
- extern int fcopy(FILE *, FILE *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind;%@NL@%
- extern char *optarg;%@NL@%
- %@NL@%
- %@AB@%/* use an alias if one is given to this program */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* process optional arguments, if any */%@AE@%%@NL@%
- errflag = FALSE;%@NL@%
- silent = FALSE;%@NL@%
- while ((ch = getopt(argc, argv, "s")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 's':%@NL@%
- %@AB@%/* don't complain about non-existent files */%@AE@%%@NL@%
- silent = TRUE;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* say what? */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- if (errflag == TRUE) {%@NL@%
- fprintf(stderr, "Usage: %s [-s] file...\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* process any remaining arguments */%@AE@%%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- if (argc == 0)%@NL@%
- %@AB@%/* no file names -- use standard input */%@AE@%%@NL@%
- if (fcopy(stdin, stdout) != 0) {%@NL@%
- fprintf(stderr, "error copying stdin");%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- else%@NL@%
- exit(0);%@NL@%
- %@NL@%
- %@AB@%/* copy the contents of each named file to standard output */%@AE@%%@NL@%
- for (; argc-- > 0; ++argv) {%@NL@%
- if ((fp = fopen(*argv, "r")) == NULL) {%@NL@%
- if (silent == FALSE)%@NL@%
- fprintf(stderr, "%s: can't open %s\n",%@NL@%
- pgm, *argv);%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (fcopy(fp, stdout) != 0) {%@NL@%
- fprintf(stderr, "%s: Error while copying %s",%@NL@%
- pgm, *argv);%@NL@%
- exit(3);%@NL@%
- }%@NL@%
- if (fclose(fp) != 0) {%@NL@%
- fprintf(stderr, "%s: Error closing %s",%@NL@%
- pgm, *argv);%@NL@%
- exit(4);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CLRSCRN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\CLRSCRN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * clrscrn -- clear the "visual" screen page%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- int%@NL@%
- clrscrn(a)%@NL@%
- unsigned int a; %@AB@%/* video attribute for new lines */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = SCROLL_UP;%@NL@%
- inregs.h.al = 0; %@AB@%/* blank entire window */%@AE@%%@NL@%
- inregs.h.bh = a; %@AB@%/* use specified attribute */%@AE@%%@NL@%
- inregs.h.bl = 0;%@NL@%
- inregs.x.cx = 0; %@AB@%/* upper left corner */%@AE@%%@NL@%
- inregs.h.dh = Maxrow[Vmode] - 1;%@AB@%/* bottom screen row */%@AE@%%@NL@%
- inregs.h.dl = Maxcol[Vmode] - 1;%@AB@%/* rightmost column */%@AE@%%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CLRW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\CLRW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * clrw -- clear specified region of "visual" screen page%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- clrw(t, l, b, r, a)%@NL@%
- int t; %@AB@%/* top row of region to clear */%@AE@%%@NL@%
- int l; %@AB@%/* left column */%@AE@%%@NL@%
- int b; %@AB@%/* bottom row */%@AE@%%@NL@%
- int r; %@AB@%/* right column */%@AE@%%@NL@%
- unsigned char a;%@AB@%/* attribute for cleared region */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = SCROLL_UP;%@AB@%/* scroll visual page up */%@AE@%%@NL@%
- inregs.h.al = 0; %@AB@%/* blank entire window */%@AE@%%@NL@%
- inregs.h.bh = a; %@AB@%/* attribute of blank lines */%@AE@%%@NL@%
- inregs.h.bl = 0;%@NL@%
- inregs.h.ch = t; %@AB@%/* upper left of scroll region */%@AE@%%@NL@%
- inregs.h.cl = l;%@NL@%
- inregs.h.dh = b; %@AB@%/* lower right of scroll region */%@AE@%%@NL@%
- inregs.h.dl = r;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COLORNUM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\COLORNUM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * colornum -- return the IBM number for the color%@NL@%
- %@AB@% * presented as a string; return -1 if no match.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\ibmcolor.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NCHARS 3 %@NL@%
- %@NL@%
- int%@NL@%
- colornum(name)%@NL@%
- char *name;%@NL@%
- {%@NL@%
- register int n;%@NL@%
- static struct color_st {%@NL@%
- char *c_name;%@NL@%
- int c_num;%@NL@%
- } colortab[] = {%@NL@%
- "black", IBM_BLACK,%@NL@%
- "blue", IBM_BLUE,%@NL@%
- "green", IBM_GREEN,%@NL@%
- "cyan", IBM_CYAN,%@NL@%
- "red", IBM_RED,%@NL@%
- "magenta", IBM_MAGENTA,%@NL@%
- "brown", IBM_BROWN,%@NL@%
- "white", IBM_WHITE,%@NL@%
- "normal", IBM_NORMAL,%@NL@%
- "bright", IBM_BRIGHT,%@NL@%
- "light", IBM_BRIGHT,%@NL@%
- "bold", IBM_BRIGHT,%@NL@%
- "yellow", IBM_BROWN + IBM_BRIGHT,%@NL@%
- "blink", IBM_BLINK,%@NL@%
- "reverse", IBM_REVERSE,%@NL@%
- "invisible", IBM_INVISIBLE,%@NL@%
- NULL, (-1)%@NL@%
- };%@NL@%
- %@NL@%
- (void) strlwr(name);%@NL@%
- for (n = 0; colortab[n].c_name != NULL; ++n)%@NL@%
- if ((strncmp(name, colortab[n].c_name, NCHARS)) == 0)%@NL@%
- return (colortab[n].c_num);%@NL@%
- return (-1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\03DOS\CP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * cp -- a simplified copy command%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- while ((ch = getc(stdin)) != EOF)%@NL@%
- putc(ch, stdout);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CPBLK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\11SCREEN\CPBLK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * cpblk -- copy a block of characters and attributes%@NL@%
- %@AB@% * while eliminating "snow" on a standard CGA display%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%BLKCNT 10 %@NL@%
- %@AI@%#define %@AE@%VSTAT 0x3DA %@NL@%
- %@AI@%#define %@AE@%VRBIT 8 %@NL@%
- %@AI@%#define %@AE@%WRDCNT 200 %@NL@%
- %@AI@%#define %@AE@%NBYTES (2 * WRDCNT) %@NL@%
- %@NL@%
- %@AB@%/* macro to synchronize with vertical retrace period */%@AE@%%@NL@%
- %@AI@%#define %@AE@%VSYNC while ((inp(VSTAT) & VRBIT) == VRBIT); \ %@NL@%
- while ((inp(VSTAT) & VRBIT) != VRBIT)%@NL@%
- %@NL@%
- int%@NL@%
- cpblk(src_os, src_seg, dest_os, dest_seg)%@NL@%
- unsigned int src_os, src_seg, dest_os, dest_seg;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- int n;%@NL@%
- register int delta;%@NL@%
- %@NL@%
- n = 0;%@NL@%
- delta = 0;%@NL@%
- for (i = 0; i < BLKCNT ; ++i) {%@NL@%
- %@AB@%/* copy a block of words during vertical retrace */%@AE@%%@NL@%
- VSYNC;%@NL@%
- movedata(src_seg, src_os + delta,%@NL@%
- dest_seg, dest_os + delta, NBYTES);%@NL@%
- n += WRDCNT;%@NL@%
- %@NL@%
- %@AB@%/* adjust buffer offset */%@AE@%%@NL@%
- delta += NBYTES;%@NL@%
- }%@NL@%
- %@NL@%
- return (n);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CURBACK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\CURBACK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * curback -- move cursor back (left); return the%@NL@%
- %@AB@% * value of the new column position%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- curback(n, pg)%@NL@%
- int n, pg;%@NL@%
- {%@NL@%
- int r, c;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * move the cursor left by up to n positions but %@NL@%
- %@AB@% * not past the beginning of the current line%@NL@%
- %@AB@% */%@AE@%%@NL@%
- readcur(&r, &c, pg);%@NL@%
- if (c - n < 0)%@NL@%
- c = 0;%@NL@%
- putcur(r, c, pg);%@NL@%
- return (c);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CURSOR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\CURSOR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * cursor -- interactively set cursor shape%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@NL@%
- %@AB@%/* additional drawing characters (others are defined in video.h) */%@AE@%%@NL@%
- %@AI@%#define %@AE@%DOT 254 %@NL@%
- %@AI@%#define %@AE@%NO_DOT 196 %@NL@%
- %@AI@%#define %@AE@%D_POINT 31 %@NL@%
- %@AI@%#define %@AE@%R_POINT 16 %@NL@%
- %@AI@%#define %@AE@%L_POINT 17 %@NL@%
- %@NL@%
- %@AB@%/* dimensions of the help frame */%@AE@%%@NL@%
- %@AI@%#define %@AE@%BOX_Y 6 %@NL@%
- %@AI@%#define %@AE@%BOX_X 30 %@NL@%
- %@NL@%
- %@AB@%/* upper-left row and column of big cursor */%@AE@%%@NL@%
- int Ulr;%@NL@%
- int Ulc;%@NL@%
- int Mid;%@NL@%
- %@NL@%
- %@AB@%/* cursor scan-line-selection modes */%@AE@%%@NL@%
- typedef enum { STARTSCAN, ENDSCAN } CMODE;%@NL@%
- %@NL@%
- int%@NL@%
- main()%@NL@%
- {%@NL@%
- int i, j;%@NL@%
- int ch;%@NL@%
- int start, end;%@NL@%
- int height, width;%@NL@%
- static char spoint[] = { "Start\020" }; %@AB@%/* contains right pointer */%@AE@%%@NL@%
- static char epoint[] = { "\021Stop" }; %@AB@%/* contains left pointer */%@AE@%%@NL@%
- static char title[] = { "CURSOR: Control cursor shape (V1.0)" };%@NL@%
- unsigned char%@NL@%
- oldattr, %@AB@%/* video attribute upon entry */%@AE@%%@NL@%
- headattr, %@AB@%/* video attribute of header */%@AE@%%@NL@%
- attr, %@AB@%/* primary video attribute */%@AE@%%@NL@%
- standout; %@AB@%/* highlighting video attribute */%@AE@%%@NL@%
- CMODE mode;%@NL@%
- %@NL@%
- static void drawdspy(int, int, int, int, int);%@NL@%
- static void drawstart(int, char *);%@NL@%
- static void drawend(int, int, char *);%@NL@%
- static void drawactive(int, int, CMODE);%@NL@%
- static void showhelp(int, int);%@NL@%
- %@NL@%
- %@AB@%/* get video information and initialize */%@AE@%%@NL@%
- getstate();%@NL@%
- Mid = Vwidth / 2;%@NL@%
- readca(&ch, &oldattr, Vpage); %@AB@%/* preserve user's video attribute */%@AE@%%@NL@%
- getctype(&start, &end, Vpage); %@AB@%/* and cursor shape */%@AE@%%@NL@%
- headattr = (WHT << 4) | BLK;%@NL@%
- %@NL@%
- %@AB@%/* set parameters based on video mode (default = CGA) */%@AE@%%@NL@%
- height = width = 8; %@AB@%/* use an 8 by 8 block character cell */%@AE@%%@NL@%
- attr = (BLU << 4) | CYAN | BRIGHT;%@NL@%
- standout = YEL;%@NL@%
- if (Vmode == MDA_M80) {%@NL@%
- %@AB@%/* uses a 14 by 9 dot block character cell */%@AE@%%@NL@%
- height = 14;%@NL@%
- width = 9;%@NL@%
- attr = NORMAL;%@NL@%
- standout = BWHT;%@NL@%
- }%@NL@%
- setctype(height + 1, height + 1); %@AB@%/* cursor off */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* basic text and layout */%@AE@%%@NL@%
- Ulr = 2;%@NL@%
- Ulc = Mid - width / 2;%@NL@%
- clrscrn(attr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- writeca(' ', headattr, Vwidth, Vpage);%@NL@%
- putcur(0, Mid - strlen(title) / 2, Vpage);%@NL@%
- writestr(title, Vpage);%@NL@%
- showhelp(Ulr + height + 1, Mid - BOX_X / 2);%@NL@%
- %@NL@%
- %@AB@%/* interactively select cursor shape */%@AE@%%@NL@%
- mode = STARTSCAN;%@NL@%
- drawdspy(start, end, standout, width, height);%@NL@%
- drawstart(start, spoint);%@NL@%
- drawend(end, width, epoint);%@NL@%
- drawactive(height, width, mode);%@NL@%
- while (1) {%@NL@%
- switch (ch = getkey()) {%@NL@%
- case K_UP:%@NL@%
- %@AB@%/* move up one scan line */%@AE@%%@NL@%
- if (mode == STARTSCAN)%@NL@%
- drawstart(start--, " ");%@NL@%
- else%@NL@%
- drawend(end--, width, " ");%@NL@%
- break;%@NL@%
- case K_DOWN:%@NL@%
- %@AB@%/* move down one scan line */%@AE@%%@NL@%
- if (mode == STARTSCAN)%@NL@%
- drawstart(start++, " ");%@NL@%
- else%@NL@%
- drawend(end++, width, " ");%@NL@%
- break;%@NL@%
- case K_LEFT:%@NL@%
- %@AB@%/* starting scan-line-selection mode */%@AE@%%@NL@%
- mode = STARTSCAN;%@NL@%
- drawactive(height, width, mode);%@NL@%
- continue;%@NL@%
- case K_RIGHT:%@NL@%
- %@AB@%/* ending scan-line-selection mode */%@AE@%%@NL@%
- mode = ENDSCAN;%@NL@%
- drawactive(height, width, mode);%@NL@%
- continue;%@NL@%
- case K_RETURN:%@NL@%
- %@AB@%/* set the new cursor shape */%@AE@%%@NL@%
- setctype(start, end);%@NL@%
- clrscrn(oldattr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* make corrections at cursor image boundaries */%@AE@%%@NL@%
- if (start < 0)%@NL@%
- start = 0;%@NL@%
- else if (start > height)%@NL@%
- start = height;%@NL@%
- if (end < 0)%@NL@%
- end = 0;%@NL@%
- else if (end >= height)%@NL@%
- end = height - 1;%@NL@%
- %@NL@%
- %@AB@%/* show updated cursor shape and pointers */%@AE@%%@NL@%
- drawdspy(start, end, standout, width, height);%@NL@%
- drawstart(start, spoint);%@NL@%
- drawend(end, width, epoint);%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- } %@AB@%/* end main() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * drawdspy -- draw a magnified image of a cursor with the%@NL@%
- %@AB@% * currently active scan lines depicted as a sequence of dots%@NL@%
- %@AB@% * and inactive lines depicted as straight lines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- drawdspy(s, e, a, w, h)%@NL@%
- int s; %@AB@%/* starting scan line */%@AE@%%@NL@%
- int e; %@AB@%/* ending scan line */%@AE@%%@NL@%
- int a; %@AB@%/* video attribute */%@AE@%%@NL@%
- int w; %@AB@%/* width */%@AE@%%@NL@%
- int h; %@AB@%/* height */%@AE@%%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* display an exploded image of each scan line */%@AE@%%@NL@%
- for (i = 0; i < h; ++i) {%@NL@%
- putcur(Ulr + i, Ulc, Vpage);%@NL@%
- if (s >= h)%@NL@%
- %@AB@%/* cursor is effectively off */%@AE@%%@NL@%
- writeca(NO_DOT, a, w, Vpage);%@NL@%
- else if ((s <= e && i >= s && i <= e) || %@AB@%/* a full block */%@AE@%%@NL@%
- (s > e && (i <= e || i >= s))) %@AB@%/* a split block */%@AE@%%@NL@%
- writeca(DOT, a, w, Vpage);%@NL@%
- else%@NL@%
- %@AB@%/* outside start/end range */%@AE@%%@NL@%
- writeca(NO_DOT, a, w, Vpage);%@NL@%
- }%@NL@%
- } %@AB@%/* end drawdspy() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * drawstart -- display a pointer to the displayed starting%@NL@%
- %@AB@% * scan line in the magnified cursor image%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- drawstart(s, sp)%@NL@%
- int s; %@AB@%/* starting scan line number */%@AE@%%@NL@%
- char *sp; %@AB@%/* visual pointer to the displayed starting scan line */%@AE@%%@NL@%
- {%@NL@%
- putcur(Ulr + s, Ulc - strlen(sp), Vpage);%@NL@%
- putstr(sp, Vpage);%@NL@%
- } %@AB@%/* end drawstart() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * drawend -- display a pointer to the displayed ending%@NL@%
- %@AB@% * scan line in the magnified cursor image%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- drawend(e, w, ep)%@NL@%
- int e; %@AB@%/* ending scan line number */%@AE@%%@NL@%
- int w; %@AB@%/* width of the cursor image */%@AE@%%@NL@%
- char *ep; %@AB@%/* visual pointer to the displayed ending scan line */%@AE@%%@NL@%
- {%@NL@%
- putcur(Ulr + e, Ulc + w, Vpage);%@NL@%
- putstr(ep, Vpage);%@NL@%
- } %@AB@%/* end drawend() */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- drawactive(h, w, m)%@NL@%
- int h, w;%@NL@%
- CMODE m;%@NL@%
- {%@NL@%
- int col;%@NL@%
- %@NL@%
- %@AB@%/* clear active selector row */%@AE@%%@NL@%
- putcur(Ulr - 1, Ulc, Vpage);%@NL@%
- writec(' ', w, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* point to active selector */%@AE@%%@NL@%
- col = (m == STARTSCAN) ? 0 : w - 1;%@NL@%
- putcur(Ulr - 1, Ulc + col, Vpage);%@NL@%
- writec(D_POINT, 1, Vpage);%@NL@%
- } %@AB@%/* end drawactive() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showhelp -- display a set of instructions about the%@NL@%
- %@AB@% * use of the cursor program in a fine-ruled box%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- showhelp(r, c)%@NL@%
- int r, c; %@AB@%/* upper-left corner of help frame */%@AE@%%@NL@%
- {%@NL@%
- static char title[] = { " Instructions " };%@NL@%
- extern int drawbox(int, int, int, int, int);%@NL@%
- %@NL@%
- %@AB@%/* fine-ruled box */%@AE@%%@NL@%
- clrw(r, c, r + BOX_Y, c + BOX_X, (WHT << 4) | GRN | BRIGHT);%@NL@%
- drawbox(r, c, r + BOX_Y, c + BOX_X, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* centered title */%@AE@%%@NL@%
- putcur(r, c + (BOX_X - strlen(title)) / 2, Vpage);%@NL@%
- putstr(title, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* display symbols and text using brute-force positioning */%@AE@%%@NL@%
- putcur(r + 2, c + 2, Vpage);%@NL@%
- put_ch(LEFTARROW, Vpage);%@NL@%
- put_ch(RIGHTARROW, Vpage);%@NL@%
- putstr(" Change selection mode", Vpage);%@NL@%
- putcur(r + 3, c + 2, Vpage);%@NL@%
- put_ch(UPARROW, Vpage);%@NL@%
- put_ch(DOWNARROW, Vpage);%@NL@%
- putstr(" Select scan lines", Vpage);%@NL@%
- putcur(r + 4, c + 2, Vpage);%@NL@%
- put_ch(L_POINT, Vpage);%@NL@%
- put_ch(LRC11, Vpage);%@NL@%
- putstr(" Set shape and exit", Vpage);%@NL@%
- } %@AB@%/* end showhelp() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DELAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\DELAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * delay -- provide a delay of ** approximately ** the%@NL@%
- %@AB@% * specified duration (resolution is about 0.055 second)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\timer.h> %@NL@%
- %@NL@%
- void%@NL@%
- delay(d)%@NL@%
- float d; %@AB@%/* duration in seconds and fractional seconds */%@AE@%%@NL@%
- {%@NL@%
- long ticks, then;%@NL@%
- extern long getticks();%@NL@%
- %@NL@%
- %@AB@%/* convert duration to number of PC clock ticks */%@AE@%%@NL@%
- ticks = d * TICKRATE;%@NL@%
- %@NL@%
- %@AB@%/* delay for the specified interval */%@AE@%%@NL@%
- then = getticks() + ticks;%@NL@%
- while (1)%@NL@%
- if (getticks() >= then)%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DRAWBOX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\DRAWBOX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * drawbox -- create a box with IBM line-drawing characters%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- int%@NL@%
- drawbox(top, lft, btm, rgt, pg)%@NL@%
- int top, lft, btm, rgt, pg;%@NL@%
- {%@NL@%
- int i;%@NL@%
- int x; %@AB@%/* interior line length for top and bottom segments */%@AE@%%@NL@%
- %@NL@%
- x = rgt - lft - 1;%@NL@%
- %@NL@%
- %@AB@%/* draw the top row */%@AE@%%@NL@%
- putcur(top, lft, pg);%@NL@%
- put_ch(ULC11, pg);%@NL@%
- writec(HBAR1, x, pg);%@NL@%
- putcur(top, rgt, pg);%@NL@%
- put_ch(URC11, pg);%@NL@%
- %@NL@%
- %@AB@%/* draw the sides */%@AE@%%@NL@%
- for (i = 1; i < btm - top; ++i)%@NL@%
- {%@NL@%
- putcur(top + i, lft, pg);%@NL@%
- put_ch(VBAR1, pg);%@NL@%
- putcur(top + i, rgt, pg);%@NL@%
- put_ch(VBAR1, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* draw the bottom row */%@AE@%%@NL@%
- putcur(btm, lft, pg);%@NL@%
- put_ch(LLC11, pg);%@NL@%
- writec(HBAR1, x, pg);%@NL@%
- putcur(btm, rgt, pg);%@NL@%
- put_ch(LRC11, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DRVPATH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\DRVPATH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * drvpath -- convert a drive name to a full pathname%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- char *%@NL@%
- drvpath(path)%@NL@%
- char path[]; %@AB@%/* path string */%@AE@%%@NL@%
- %@AB@%/* must be large enough to hold a full DOS path + NUL */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- static int drive(char);%@NL@%
- %@NL@%
- %@AB@%/* patch root directory onto drive name */%@AE@%%@NL@%
- strcat(path, "\\");%@NL@%
- %@NL@%
- %@AB@%/* set current directory path for drive from DOS */%@AE@%%@NL@%
- inregs.h.ah = GET_CUR_DIR;%@NL@%
- inregs.h.dl = drive(path[0]); %@AB@%/* convert to drive number */%@AE@%%@NL@%
- inregs.x.si = (unsigned)&path[3]; %@AB@%/* start of return string */%@AE@%%@NL@%
- intdos(&inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag ? (char *)NULL : path); %@NL@%
- }%@NL@%
- %@NL@%
- static int%@NL@%
- drive(dltr)%@NL@%
- char dltr; %@AB@%/* drive letter */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* 'A' (or 'a') => 1, 'B' (or 'b') => 2, etc. */%@AE@%%@NL@%
- return (tolower(dltr) - 'a' + 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DSPYTYPE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\11SCREEN\DSPYTYPE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * dspytype -- determine display adapter type%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MDA_SEG 0xB000 %@NL@%
- %@AI@%#define %@AE@%CGA_SEG 0xB800 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- extern int memchk(unsigned int, unsigned int);%@NL@%
- int mdaflag, egaflag, cgaflag;%@NL@%
- int ega_mem, ega_mode;%@NL@%
- unsigned int features, switches;%@NL@%
- static int memtab[] = {%@NL@%
- 64, 128, 192, 256%@NL@%
- };%@NL@%
- %@NL@%
- mdaflag = egaflag = cgaflag = 0;%@NL@%
- %@NL@%
- %@AB@%/* look for display adapters */%@AE@%%@NL@%
- if (ega_info(&ega_mem, &ega_mode, &features, &switches))%@NL@%
- ++egaflag;%@NL@%
- fputs("Enhanced graphics adapter ", stdout);%@NL@%
- if (egaflag) {%@NL@%
- fputs("installed\n", stdout);%@NL@%
- fprintf(stdout, "EGA memory size = %d-KB\n", memtab[ega_mem]);%@NL@%
- fprintf(stdout, "EGA is in %s mode\n",%@NL@%
- ega_mode ? "monochrome" : "color");%@NL@%
- }%@NL@%
- else%@NL@%
- fputs("not installed\n", stdout);%@NL@%
- %@NL@%
- if (egaflag && ega_mode == 0) {%@NL@%
- %@AB@%/* look for IBM monochrome memory */%@AE@%%@NL@%
- if (memchk(MDA_SEG, 0))%@NL@%
- ++mdaflag;%@NL@%
- }%@NL@%
- else {%@NL@%
- %@AB@%/* look for IBM monochrome memory */%@AE@%%@NL@%
- if (memchk(CGA_SEG, 0))%@NL@%
- ++cgaflag;%@NL@%
- }%@NL@%
- fputs("Monochrome adapter ", stdout);%@NL@%
- if (mdaflag)%@NL@%
- fputs("installed\n", stdout);%@NL@%
- else%@NL@%
- fputs("not installed\n", stdout);%@NL@%
- fputs("Color/graphics adapter ", stdout);%@NL@%
- if (cgaflag)%@NL@%
- fputs("installed\n", stdout);%@NL@%
- else%@NL@%
- fputs("not installed\n", stdout);%@NL@%
- %@NL@%
- %@AB@%/* report video settings */%@AE@%%@NL@%
- getstate();%@NL@%
- fprintf(stdout, "mode=%d width=%d page=%d\n", Vmode, Vwidth, Vpage);%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DUMP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\10DUMP\DUMP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * dump -- display contents of non-ASCII files in hex byte and%@NL@%
- %@AB@% * ASCII character forms (like the DOS debug dump option)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%STDINPUT 0 %@NL@%
- %@AI@%#define %@AE@%LINEWIDTH 80 %@NL@%
- %@NL@%
- main(argc,argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int ch;%@NL@%
- BOOLEAN sflag = FALSE,%@NL@%
- vflag = FALSE,%@NL@%
- errflag = FALSE;%@NL@%
- int fd;%@NL@%
- static char pgm[MAXNAME + 1] = { "dump" };%@NL@%
- %@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern char *optarg;%@NL@%
- extern int optind, opterr;%@NL@%
- extern void getpname(char *, char *);%@NL@%
- extern int hexdump(int, BOOLEAN);%@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- while ((ch = getopt(argc, argv, "sv")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 's': %@AB@%/* strip -- convert all non-ASCII to '.' */%@AE@%%@NL@%
- sflag = TRUE;%@NL@%
- break;%@NL@%
- case 'v': %@AB@%/* verbose -- tell user what's happening */%@AE@%%@NL@%
- vflag = TRUE;%@NL@%
- break;%@NL@%
- case '?': %@AB@%/* bad option */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- if (errflag == TRUE) {%@NL@%
- fprintf(stderr, "Usage: %s [-sv] [file...]\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- if (optind == argc) {%@NL@%
- if (setmode(STDINPUT, O_BINARY) == -1)%@NL@%
- fatal(pgm, "Cannot set binary mode", 2);%@NL@%
- hexdump(STDINPUT, sflag);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- for ( ; optind < argc; ++optind) {%@NL@%
- if ((fd = open(argv[optind], O_BINARY | O_RDONLY)) == -1) {%@NL@%
- fprintf(stderr,%@NL@%
- "%s: Error opening %s -- ", pgm, argv[optind]);%@NL@%
- perror("");%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (vflag == TRUE)%@NL@%
- fprintf(stdout, "\n%s:\n", argv[optind]);%@NL@%
- if (hexdump(fd, sflag) == FAILURE) {%@NL@%
- fprintf(stderr,%@NL@%
- "%s: Error reading %s -- ", pgm, argv[optind]);%@NL@%
- perror("");%@NL@%
- }%@NL@%
- if (close(fd) == -1)%@NL@%
- fatal(pgm, "Error closing input file", 3);%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EGA_INFO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\EGA_INFO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ega_info -- gather information about an EGA;%@NL@%
- %@AB@% * return a non-zero value if one is found%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%EGA_INFO 0x10 %@NL@%
- %@AI@%#define %@AE@%NMODES 2 %@NL@%
- %@AI@%#define %@AE@%NMEMSIZ 4 %@NL@%
- %@NL@%
- int%@NL@%
- ega_info(memsize, mode, features, switches)%@NL@%
- int *memsize; %@AB@%/* EGA memory size indicator: 0 = 64K */%@AE@%%@NL@%
- %@AB@%/* 1 = 128K; 2 = 192K; 3 = 256K */%@AE@%%@NL@%
- int *mode; %@AB@%/* 0 = color mode; 1 = mono mode */%@AE@%%@NL@%
- %@AB@%/* use getstate function to find out which mode */%@AE@%%@NL@%
- unsigned int%@NL@%
- *features, %@AB@%/* feature bit settings */%@AE@%%@NL@%
- *switches; %@AB@%/* EGA switch settings */%@AE@%%@NL@%
- {%@NL@%
- int result = 0;%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- %@AB@%/* request EGA information */%@AE@%%@NL@%
- inregs.h.ah = ALT_FUNCTION;%@NL@%
- inregs.h.bl = EGA_INFO;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- *memsize = outregs.h.bl;%@NL@%
- *mode = outregs.h.bh;%@NL@%
- *features = outregs.h.ch;%@NL@%
- *switches = outregs.h.cl;%@NL@%
- %@NL@%
- %@AB@%/* return non-zero if EGA installed */%@AE@%%@NL@%
- if (*memsize >= 0 && *memsize < NMEMSIZ && *mode >= 0 && *mode < NMODES)%@NL@%
- result = 1;%@NL@%
- return (result);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EQUIPCHK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\EQUIPCHK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * equipchk -- get equipment list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@AI@%#include %@AE@%<local\equip.h> %@NL@%
- %@NL@%
- struct EQUIP Eq;%@NL@%
- %@NL@%
- int%@NL@%
- equipchk()%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- %@AB@%/* call BIOS equipment check routine */%@AE@%%@NL@%
- int86(EQUIP_CK, &inregs, &outregs);%@NL@%
- %@NL@%
- %@AB@%/* extract data from returned data word */%@AE@%%@NL@%
- Eq.nprint = (outregs.x.ax & 0xC000) / 0x8000; %@NL@%
- Eq.game_io = ((outregs.x.ax & 0x1000) / 0x1000) ? 1 : 0;%@NL@%
- Eq.nrs232 = (outregs.x.ax & 0x0E00) /0x0200;%@NL@%
- Eq.ndrive = ((outregs.x.ax & 0x00C0) / 0x0040) + 1;%@NL@%
- Eq.vmode = (outregs.x.ax & 0x0030) / 0x0010;%@NL@%
- Eq.basemem = ((outregs.x.ax & 0x000C) / 0x0004) + 1;%@NL@%
- Eq.disksys = outregs.x.ax & 0x0001 == 1;%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FATAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\FATAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * fatal -- issue a diagnostic message and terminate%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- void%@NL@%
- fatal(pname, mesg, errlevel)%@NL@%
- char *pname; %@AB@%/* program name */%@AE@%%@NL@%
- char *mesg; %@AB@%/* message text */%@AE@%%@NL@%
- int errlevel; %@AB@%/* errorlevel (exit code) */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* display error message */%@AE@%%@NL@%
- fputs(pname, stderr);%@NL@%
- fputc(':', stderr);%@NL@%
- fputc(' ', stderr);%@NL@%
- fputs(mesg, stderr);%@NL@%
- %@NL@%
- %@AB@%/* return to DOS with the specified errorlevel */%@AE@%%@NL@%
- exit(errlevel);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FCONFIG.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\FCONFIG.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * fconfig -- return a FILE pointer to a local or%@NL@%
- %@AB@% * global configuration file, or NULL if none found%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- FILE *%@NL@%
- fconfig(varname, fname)%@NL@%
- char *varname;%@NL@%
- char *fname;%@NL@%
- {%@NL@%
- FILE *fp;%@NL@%
- char pname[MAXPATH + 1];%@NL@%
- char *p;%@NL@%
- %@NL@%
- %@AB@%/* look for a local configuration file */%@AE@%%@NL@%
- if ((fp = fopen(fname, "r")) != NULL)%@NL@%
- return (fp);%@NL@%
- %@NL@%
- %@AB@%/* look for a directory variable */%@AE@%%@NL@%
- if ((p = getenv(strupr(varname))) != NULL) {%@NL@%
- strcpy(pname, p);%@NL@%
- strcat(pname, "\\");%@NL@%
- strcat(pname, fname);%@NL@%
- if ((fp = fopen(pname, "r")) != NULL)%@NL@%
- return (fp);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* didn't find anything to read */%@AE@%%@NL@%
- return (NULL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FCOPY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\FCOPY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * fcopy -- copy input stream (fin) to output stream%@NL@%
- %@AB@% * (fout) and return an indication of success or failure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%BUFLEN 1024 %@NL@%
- %@NL@%
- int%@NL@%
- fcopy(fin, fout)%@NL@%
- FILE *fin, *fout;%@NL@%
- {%@NL@%
- int errcount = 0;%@NL@%
- char line[BUFLEN];%@NL@%
- register char *s;%@NL@%
- %@NL@%
- while ((s = fgets(line, BUFLEN, fin)) != NULL)%@NL@%
- if (fputs(s, fout) == EOF)%@NL@%
- ++errcount;%@NL@%
- if (ferror(fin))%@NL@%
- ++errcount;%@NL@%
- return (errcount); %@AB@%/* 0 if all went well */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FIRST_FM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\FIRST_FM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * first_fm - find first file match in work directory%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- first_fm(path, fa)%@NL@%
- char *path; %@AB@%/* pathname of directory */%@AE@%%@NL@%
- int fa; %@AB@%/* attribute(s) of file to match */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- %@AB@%/* find first matching file */%@AE@%%@NL@%
- inregs.h.ah = FIND_FIRST;%@NL@%
- inregs.x.cx = fa; %@NL@%
- inregs.x.dx = (unsigned int)path;%@NL@%
- (void)intdos(&inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETCTYPE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\GETCTYPE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getctype -- pass back cursor type info (scan lines) %@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%LO_NIBBLE 0x0F %@NL@%
- %@NL@%
- int%@NL@%
- getctype(start_scan, end_scan, pg)%@NL@%
- int *start_scan;%@AB@%/* starting scan line */%@AE@%%@NL@%
- int *end_scan; %@AB@%/* ending scan line */%@AE@%%@NL@%
- int pg; %@AB@%/* "visual" page */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.bh = pg;%@NL@%
- inregs.h.ah = GET_CUR;%@NL@%
- %@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- %@AB@%/* end_scan = low 4 bits of cl */%@AE@%%@NL@%
- *end_scan = outregs.h.cl & LO_NIBBLE;%@NL@%
- %@NL@%
- %@AB@%/* starting_scan = low 4 bits of ah */%@AE@%%@NL@%
- *start_scan = outregs.h.ch & LO_NIBBLE;%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETDRIVE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\GETDRIVE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getdrive -- return the number of the default drive%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- int getdrive()%@NL@%
- {%@NL@%
- return (bdos(CURRENT_DISK, 0, 0));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETKEY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\GETKEY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getkey -- return a code for single combo keystrokes%@NL@%
- %@AB@% * - returns a unique code for each keystroke or combination%@NL@%
- %@AB@% * - ignores "Ctrl-Break" input%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@NL@%
- int%@NL@%
- getkey()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- %@AB@%/* normal key codes */%@AE@%%@NL@%
- if ((ch = bdos(KEYIN, 0, 0) & LOBYTE) != '\0')%@NL@%
- return (ch);%@NL@%
- %@NL@%
- %@AB@%/* convert scan codes to unique internal codes */%@AE@%%@NL@%
- return ((bdos(KEYIN, 0, 0) & LOBYTE) | XF);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETNAME.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\GETNAME.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getname -- strip drive identifier and directory node%@NL@%
- %@AB@% * list, if any, from a pathname; returns a pointer to%@NL@%
- %@AB@% * the resulting filename[.ext] string or NULL for error%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXFSPEC 13 %@NL@%
- %@NL@%
- char *%@NL@%
- getname(path)%@NL@%
- char *path; %@AB@%/* string to modify */%@AE@%%@NL@%
- {%@NL@%
- register char *cp; %@AB@%/* character pointer */%@AE@%%@NL@%
- struct stat buf;%@NL@%
- %@NL@%
- %@AB@%/* try to get information about the pathname */%@AE@%%@NL@%
- if (stat(path, &buf) != 0)%@NL@%
- return (NULL); %@AB@%/* bad pathname */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* locate the end of the pathname string */%@AE@%%@NL@%
- cp = path;%@NL@%
- while (*cp != '\0')%@NL@%
- ++cp;%@NL@%
- --cp; %@AB@%/* went one too far */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* find the start of the filename part */%@AE@%%@NL@%
- while (cp > path && *cp != '\\' && *cp != ':' && *cp != '/')%@NL@%
- --cp;%@NL@%
- if (cp > path)%@NL@%
- ++cp; %@AB@%/* on a separator (\, :, or /) -- move one past */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* return the full filespec (filename[.ext]) */%@AE@%%@NL@%
- return (cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETOPT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\GETOPT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Copyright (c) 1984, 1985 AT&T%@NL@%
- %@AB@% * All Rights Reserved%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * ----- Author's Note -----%@NL@%
- %@AB@% * getopt() is reproduced with permission of the AT&T UNIX(R) System%@NL@%
- %@AB@% * Toolchest. This is a public domain version of getopt(3) that is%@NL@%
- %@AB@% * distributed to registered Toolchest participants.%@NL@%
- %@AB@% * Defining DOS_MODS alters the code slightly to obtain compatibility%@NL@%
- %@AB@% * with DOS and support libraries provided with most DOS C compilers.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%DOS_MODS %@NL@%
- %@NL@%
- %@AI@%#if %@AE@%defined (DOS_MODS) %@NL@%
- %@AB@%/* getopt() for DOS */%@AE@%%@NL@%
- %@AI@%#else %@AE@%%@NL@%
- %@AI@%#ident %@AE@% "@(#)getopt.c 1.9" %@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@AB@%/* 3.0 SID # 1.2 */%@AE@%%@NL@%
- %@AB@%/*LINTLIBRARY*/%@AE@%%@NL@%
- %@AI@%#define %@AE@%NULL 0 %@NL@%
- %@AI@%#define %@AE@%EOF (-1) %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * For this to work under versions of DOS prior to 3.00, argv[0]%@NL@%
- %@AB@% * must be set in main() to point to a valid program name or a%@NL@%
- %@AB@% * reasonable substitute string. (ARH, 10-8-86)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ERR(s, c) if(opterr){\ %@NL@%
- char errbuf[2];\%@NL@%
- errbuf[0] = c; errbuf[1] = '\n';\%@NL@%
- (void) write(2, argv[0], (unsigned)strlen(argv[0]));\%@NL@%
- (void) write(2, s, (unsigned)strlen(s));\%@NL@%
- (void) write(2, errbuf, 2);}%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%defined (DOS_MODS) %@NL@%
- %@AB@%/* permit function prototyping under DOS */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#else %@AE@%%@NL@%
- %@AB@%/* standard UNIX declarations */%@AE@%%@NL@%
- extern int strcmp();%@NL@%
- extern char *strchr();%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * The following line was moved here from the ERR definition%@NL@%
- %@AB@% * to prevent a "duplicate definition" error message when the%@NL@%
- %@AB@% * code is compiled under DOS. (ARH, 10-8-86)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- extern int strlen(), write();%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- int opterr = 1;%@NL@%
- int optind = 1;%@NL@%
- int optopt;%@NL@%
- char *optarg;%@NL@%
- %@NL@%
- int%@NL@%
- getopt(argc, argv, opts)%@NL@%
- int argc;%@NL@%
- char **argv, *opts;%@NL@%
- {%@NL@%
- static int sp = 1;%@NL@%
- register int c;%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- if(sp == 1)%@NL@%
- if(optind >= argc ||%@NL@%
- argv[optind][0] != '-' || argv[optind][1] == '\0')%@NL@%
- return(EOF);%@NL@%
- else if(strcmp(argv[optind], "--") == NULL) {%@NL@%
- optind++;%@NL@%
- return(EOF);%@NL@%
- }%@NL@%
- optopt = c = argv[optind][sp];%@NL@%
- if(c == ':' || (cp=strchr(opts, c)) == NULL) {%@NL@%
- ERR(": illegal option -- ", c);%@NL@%
- if(argv[optind][++sp] == '\0') {%@NL@%
- optind++;%@NL@%
- sp = 1;%@NL@%
- }%@NL@%
- return('?');%@NL@%
- }%@NL@%
- if(*++cp == ':') {%@NL@%
- if(argv[optind][sp+1] != '\0')%@NL@%
- optarg = &argv[optind++][sp+1];%@NL@%
- else if(++optind >= argc) {%@NL@%
- ERR(": option requires an argument -- ", c);%@NL@%
- sp = 1;%@NL@%
- return('?');%@NL@%
- } else%@NL@%
- optarg = argv[optind++];%@NL@%
- sp = 1;%@NL@%
- } else {%@NL@%
- if(argv[optind][++sp] == '\0') {%@NL@%
- sp = 1;%@NL@%
- optind++;%@NL@%
- }%@NL@%
- optarg = NULL;%@NL@%
- }%@NL@%
- return(c);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETPNAME.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\GETPNAME.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getpname -- extract the base name of a program from%@NL@%
- %@AB@% * the pathname string (deletes a drive specifier, any%@NL@%
- %@AB@% * leading path node information, and the extension)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@NL@%
- char *%@NL@%
- getpname(path, pname)%@NL@%
- char *path; %@AB@%/* full or relative pathname */%@AE@%%@NL@%
- char *pname; %@AB@%/* program name pointer */%@AE@%%@NL@%
- {%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- %@AB@%/* find the end of the pathname string */%@AE@%%@NL@%
- cp = path; %@AB@%/* start of pathname */%@AE@%%@NL@%
- while (*cp != '\0')%@NL@%
- ++cp;%@NL@%
- --cp; %@AB@%/* went one too far */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* find the start of the filename part */%@AE@%%@NL@%
- while (cp > path && *cp != '\\' && *cp != ':' && *cp != '/')%@NL@%
- --cp;%@NL@%
- if (cp > path)%@NL@%
- ++cp; %@AB@%/* move off the pathname separator */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* copy the filename part only */%@AE@%%@NL@%
- while ((*pname = tolower(*cp)) != '.' && *pname != '\0') {%@NL@%
- ++cp;%@NL@%
- ++pname;%@NL@%
- }%@NL@%
- *pname = '\0';%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETREPLY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\GETREPLY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getreply -- display a message and wait for a reply%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@AI@%#include %@AE@%"linebuf.h" %@NL@%
- %@NL@%
- char *%@NL@%
- getreply(row, col, width, mesg, lp, size, attr, pg)%@NL@%
- short row, col, width; %@AB@%/* window location and width */%@AE@%%@NL@%
- char *mesg; %@AB@%/* message text */%@AE@%%@NL@%
- LINEBUF *lp; %@AB@%/* line pointer */%@AE@%%@NL@%
- short size; %@AB@%/* size of line buffer */%@AE@%%@NL@%
- short attr; %@AB@%/* video attribute for response field */%@AE@%%@NL@%
- short pg; %@AB@%/* active display page */%@AE@%%@NL@%
- {%@NL@%
- int n, k, len;%@NL@%
- short mfw; %@AB@%/* message field width */%@AE@%%@NL@%
- short rfw; %@AB@%/* response field width */%@AE@%%@NL@%
- short ccol; %@AB@%/* visible cursor column */%@AE@%%@NL@%
- int msgflag; %@AB@%/* non-zero after a message is displayed */%@AE@%%@NL@%
- char *cp; %@AB@%/* character pointer */%@AE@%%@NL@%
- char *wp; %@AB@%/* pointer to window start */%@AE@%%@NL@%
- char *tmp; %@AB@%/* temporary char pointer */%@AE@%%@NL@%
- %@NL@%
- extern int writemsg(short, short, short, char *, char *, short);%@NL@%
- %@NL@%
- %@AB@%/* display the prompt string and calculate response field width */%@AE@%%@NL@%
- putcur(row, col, pg);%@NL@%
- mfw = writemsg(row, col, width, mesg, NULL, pg);%@NL@%
- rfw = width - mfw;%@NL@%
- writea(attr, rfw, pg);%@NL@%
- %@NL@%
- %@AB@%/* collect the user's response */%@AE@%%@NL@%
- memset(lp->l_buf, '\0', size);%@NL@%
- wp = cp = lp->l_buf;%@NL@%
- putcur(row, col + mfw, pg);%@NL@%
- msgflag = 0;%@NL@%
- while ((k = getkey()) != K_RETURN) {%@NL@%
- if (msgflag) {%@NL@%
- %@AB@%/* clear old messages */%@AE@%%@NL@%
- errmsg("");%@NL@%
- putcur(row, ccol, pg);%@NL@%
- msgflag = 0;%@NL@%
- }%@NL@%
- if (isascii(k) && isprint(k)) {%@NL@%
- len = strlen(cp);%@NL@%
- if (cp + len - lp->l_buf < size - 1) {%@NL@%
- memcpy(cp + 1, cp, len);%@NL@%
- *cp = k;%@NL@%
- ++cp;%@NL@%
- }%@NL@%
- else {%@NL@%
- errmsg("input buffer full");%@NL@%
- ++msgflag;%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- switch (k) {%@NL@%
- case K_LEFT:%@NL@%
- %@AB@%/* move left one character */%@AE@%%@NL@%
- if (cp > lp->l_buf)%@NL@%
- --cp;%@NL@%
- break;%@NL@%
- case K_RIGHT:%@NL@%
- %@AB@%/* move right one character */%@AE@%%@NL@%
- if (*cp != '\0')%@NL@%
- ++cp;%@NL@%
- break;%@NL@%
- case K_UP:%@NL@%
- %@AB@%/* pop a line off the stack */%@AE@%%@NL@%
- if (lp->l_prev != NULL) {%@NL@%
- lp = lp->l_prev;%@NL@%
- wp = cp = lp->l_buf;%@NL@%
- }%@NL@%
- break;%@NL@%
- case K_DOWN:%@NL@%
- %@AB@%/* push a line onto the stack */%@AE@%%@NL@%
- if (lp->l_next != NULL) {%@NL@%
- lp = lp->l_next;%@NL@%
- wp = cp = lp->l_buf;%@NL@%
- }%@NL@%
- break;%@NL@%
- case K_HOME:%@NL@%
- %@AB@%/* beginning of buffer */%@AE@%%@NL@%
- cp = lp->l_buf;%@NL@%
- break;%@NL@%
- case K_END:%@NL@%
- %@AB@%/* end of buffer */%@AE@%%@NL@%
- while (*cp != '\0')%@NL@%
- ++cp;%@NL@%
- break;%@NL@%
- case K_CTRLH:%@NL@%
- if (cp > lp->l_buf) {%@NL@%
- tmp = cp - 1;%@NL@%
- memcpy(tmp, cp, strlen(tmp));%@NL@%
- --cp;%@NL@%
- }%@NL@%
- break;%@NL@%
- case K_DEL:%@NL@%
- %@AB@%/* delete character at cursor */%@AE@%%@NL@%
- memcpy(cp, cp + 1, strlen(cp));%@NL@%
- break;%@NL@%
- case K_ESC:%@NL@%
- %@AB@%/* cancel current input */%@AE@%%@NL@%
- lp->l_buf[0] = '\0';%@NL@%
- putcur(row, col, pg);%@NL@%
- writec(' ', width, pg);%@NL@%
- return (NULL);%@NL@%
- default:%@NL@%
- errmsg("unknown command");%@NL@%
- ++msgflag;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* adjust the window pointer if necessary */%@AE@%%@NL@%
- if (cp < wp)%@NL@%
- wp = cp;%@NL@%
- else if (cp >= wp + rfw)%@NL@%
- wp = cp + 1 - rfw;%@NL@%
- %@NL@%
- %@AB@%/* display the reply window */%@AE@%%@NL@%
- ccol = col + mfw;%@NL@%
- writemsg(row, ccol, rfw, wp, NULL, pg);%@NL@%
- %@NL@%
- %@AB@%/* reposition the cursor */%@AE@%%@NL@%
- ccol = col + mfw + (cp - wp);%@NL@%
- putcur(row, ccol, pg);%@NL@%
- }%@NL@%
- putcur(row, col, pg);%@NL@%
- writec(' ', width, pg); %@AB@%/* blank message area */%@AE@%%@NL@%
- return (lp->l_buf);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETSTATE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\GETSTATE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getstate -- update video state structure%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- %@AB@%/* current video state/mode information */%@AE@%%@NL@%
- short Vmode;%@NL@%
- short Vwidth;%@NL@%
- short Vpage;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * video tables -- these tables of video parameters use%@NL@%
- %@AB@% * a value of -1 to indicate that an item is not supported%@NL@%
- %@AB@% * and 0 to indicate that an item has a variable value.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* video limit tables */%@AE@%%@NL@%
- short Maxrow[] = { %@NL@%
- %@AB@%/* CGA modes */%@AE@%%@NL@%
- 25, 25, 25, 25, 25, 25, 25,%@NL@%
- %@AB@%/* MDA mode */%@AE@%%@NL@%
- 25,%@NL@%
- %@AB@%/* PCjr modes */%@AE@%%@NL@%
- 25, 25, 25,%@NL@%
- %@AB@%/* not used */%@AE@%%@NL@%
- -1, -1,%@NL@%
- %@AB@%/* EGA modes */%@AE@%%@NL@%
- 25, 25, 25, 25, 43%@NL@%
- };%@NL@%
- %@NL@%
- short Maxcol[] = {%@NL@%
- %@AB@%/* CGA modes */%@AE@%%@NL@%
- 40, 40, 80, 80, 40, 40, 80,%@NL@%
- %@AB@%/* MDA mode */%@AE@%%@NL@%
- 80,%@NL@%
- %@AB@%/* PCjr modes */%@AE@%%@NL@%
- -1, 40, 80,%@NL@%
- %@AB@%/* not used */%@AE@%%@NL@%
- -1, -1,%@NL@%
- %@AB@%/* EGA modes */%@AE@%%@NL@%
- 80, 80, 80, 80%@NL@%
- };%@NL@%
- %@NL@%
- short Maxpage[] = {%@NL@%
- %@AB@%/* CGA modes */%@AE@%%@NL@%
- 8, 8, 4, 4, 1, 1, 1,%@NL@%
- %@AB@%/* MDA mode */%@AE@%%@NL@%
- 1,%@NL@%
- %@AB@%/* PCjr modes */%@AE@%%@NL@%
- 0, 0, 0,%@NL@%
- %@AB@%/* not used */%@AE@%%@NL@%
- -1, -1,%@NL@%
- %@AB@%/* EGA modes */%@AE@%%@NL@%
- 8, 4, 1, 1%@NL@%
- };%@NL@%
- %@NL@%
- int%@NL@%
- getstate()%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = GET_STATE;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- Vmode = outregs.h.al;%@NL@%
- Vwidth = outregs.h.ah;%@NL@%
- Vpage = outregs.h.bh;%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\GETSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getstr -- get a string from the keyboard%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@NL@%
- char *%@NL@%
- getstr(buf, width)%@NL@%
- char *buf;%@NL@%
- int width;%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- char *cp;%@NL@%
- %@NL@%
- %@AB@%/* function prototypes */%@AE@%%@NL@%
- extern int putcur(int, int, int);%@NL@%
- extern int readcur(int *, int *, int);%@NL@%
- extern int writec(char, int, int);%@NL@%
- extern int getkey();%@NL@%
- %@NL@%
- %@AB@%/* gather keyboard input into a string buffer */%@AE@%%@NL@%
- cp = buf;%@NL@%
- while ((*cp = getkey()) != K_RETURN && cp - buf < width) {%@NL@%
- switch (*cp) {%@NL@%
- case K_CTRLH:%@NL@%
- %@AB@%/* destructive backspace */%@AE@%%@NL@%
- if (cp > buf) {%@NL@%
- readcur(&row, &col, Vpage);%@NL@%
- putcur(row, col - 1, Vpage);%@NL@%
- writec(' ', 1, Vpage);%@NL@%
- --cp;%@NL@%
- }%@NL@%
- continue;%@NL@%
- case K_ESC:%@NL@%
- %@AB@%/* cancel string input operation */%@AE@%%@NL@%
- return (char *)NULL;%@NL@%
- }%@NL@%
- put_ch(*cp, Vpage);%@NL@%
- ++cp;%@NL@%
- }%@NL@%
- *cp = '\0';%@NL@%
- return (buf);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETTICKS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\GETTICKS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getticks -- get the current bios clock ticks value%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- long%@NL@%
- getticks()%@NL@%
- {%@NL@%
- long count;%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- %@AB@%/* get BIOS time of day as no. of ticks since midnight */%@AE@%%@NL@%
- inregs.h.ah = 0;%@NL@%
- int86(TOD, &inregs, &outregs);%@NL@%
- %@NL@%
- %@AB@%/* correct for possible rollover at 24 hours */%@AE@%%@NL@%
- count = (outregs.h.al != 0) ? 0x01800B0L : 0;%@NL@%
- %@NL@%
- %@AB@%/* add current day ticks */%@AE@%%@NL@%
- count += (outregs.x.dx + (outregs.x.cx << 16));%@NL@%
- %@NL@%
- return (count);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETXLINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\GETXLINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getxline -- get a line of text while expanding tabs,%@NL@%
- %@AB@% * put text into an array, and return a pointer to the%@NL@%
- %@AB@% * resulting null-terminated line%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- char *%@NL@%
- getxline(buf, size, fin)%@NL@%
- char *buf;%@NL@%
- int size;%@NL@%
- FILE *fin;%@NL@%
- {%@NL@%
- register int ch; %@AB@%/* input character */%@AE@%%@NL@%
- register char *cp; %@AB@%/* character pointer */%@AE@%%@NL@%
- %@NL@%
- extern BOOLEAN tabstop(int);%@NL@%
- %@NL@%
- cp = buf;%@NL@%
- while (--size > 0 && (ch = fgetc(fin)) != EOF) {%@NL@%
- if (ch == '\n') {%@NL@%
- *cp++ = ch;%@NL@%
- break;%@NL@%
- }%@NL@%
- else if (ch == '\t')%@NL@%
- do {%@NL@%
- *cp = ' ';%@NL@%
- } while (--size > 0 && (tabstop(++cp - buf) == FALSE));%@NL@%
- else%@NL@%
- *cp++ = ch & ASCII;%@NL@%
- }%@NL@%
- *cp = '\0';%@NL@%
- return ((ch == EOF && cp == buf) ? NULL : buf);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HEX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\HEX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * hex.c -- hex conversions routines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NIBBLE 0x000F %@NL@%
- %@NL@%
- char hextab[] = {%@NL@%
- '0', '1', '2', '3', '4', '5', '6', '7',%@NL@%
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * byte2hex -- convert a byte to a string%@NL@%
- %@AB@% * representation of its hexadecimal value%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char *%@NL@%
- byte2hex(data, buf)%@NL@%
- unsigned char data;%@NL@%
- char *buf;%@NL@%
- {%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- cp = buf;%@NL@%
- *cp++ = hextab[(data >> 4) & NIBBLE];%@NL@%
- *cp++ = hextab[data & NIBBLE];%@NL@%
- *cp = '\0';%@NL@%
- %@NL@%
- return (buf);%@NL@%
- } %@AB@%/* end byte2hex() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * word2hex -- convert a word to a string%@NL@%
- %@AB@% * representation of its hexadecimal value%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char *%@NL@%
- word2hex(data, buf)%@NL@%
- unsigned int data;%@NL@%
- char *buf;%@NL@%
- {%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- cp = buf;%@NL@%
- *cp++ = hextab[(data >> 12) & NIBBLE];%@NL@%
- *cp++ = hextab[(data >> 8) & NIBBLE];%@NL@%
- *cp++ = hextab[(data >> 4) & NIBBLE];%@NL@%
- *cp++ = hextab[data & NIBBLE];%@NL@%
- *cp = '\0';%@NL@%
- %@NL@%
- return (buf);%@NL@%
- } %@AB@%/* end word2hex() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HEX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\10DUMP\HEX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * hex.c -- hex conversions routines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NIBBLE 0x000F %@NL@%
- %@AI@%#define %@AE@%BYTE 0x00FF %@NL@%
- %@AI@%#define %@AE@%WORD 0xFFFF %@NL@%
- %@NL@%
- char hextab[] = {%@NL@%
- '0', '1', '2', '3', '4', '5', '6', '7',%@NL@%
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * byte2hex -- convert a byte to a string%@NL@%
- %@AB@% * representation of its hexadecimal value%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char *%@NL@%
- byte2hex(data, buf)%@NL@%
- unsigned char data;%@NL@%
- char *buf;%@NL@%
- {%@NL@%
- char *cp;%@NL@%
- unsigned int d;%@NL@%
- %@NL@%
- d = data & BYTE;%@NL@%
- cp = buf;%@NL@%
- *cp++ = hextab[(d >> 4) & NIBBLE];%@NL@%
- *cp++ = hextab[d & NIBBLE];%@NL@%
- *cp = '\0';%@NL@%
- %@NL@%
- return (buf);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * word2hex -- convert a word to a string%@NL@%
- %@AB@% * representation of its hexadecimal value%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char *%@NL@%
- word2hex(data, buf)%@NL@%
- unsigned int data;%@NL@%
- char *buf;%@NL@%
- {%@NL@%
- char *cp;%@NL@%
- unsigned int d;%@NL@%
- %@NL@%
- d = data & WORD;%@NL@%
- cp = buf;%@NL@%
- *cp++ = hextab[(d >> 12) & NIBBLE];%@NL@%
- *cp++ = hextab[(d >> 8) & NIBBLE];%@NL@%
- *cp++ = hextab[(d >> 4) & NIBBLE];%@NL@%
- *cp++ = hextab[d & NIBBLE];%@NL@%
- *cp = '\0';%@NL@%
- %@NL@%
- return (buf);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HEXDUMP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\10DUMP\HEXDUMP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * hexdump -- read data from an open file and "dump"%@NL@%
- %@AB@% * it in side-by-side hex and ASCII to standard output%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%LINEWIDTH 80 %@NL@%
- %@AI@%#define %@AE@%NBYTES 16 %@NL@%
- %@AI@%#define %@AE@%WORD 0xFFFF %@NL@%
- %@AI@%#define %@AE@%RGHTMARK 179 %@NL@%
- %@AI@%#define %@AE@%LEFTMARK 179 %@NL@%
- %@AI@%#define %@AE@%DEL 0x7F %@NL@%
- %@NL@%
- int hexdump(fd, strip)%@NL@%
- int fd;%@NL@%
- BOOLEAN strip;%@NL@%
- {%@NL@%
- unsigned char i;%@NL@%
- int n; %@AB@%/* bytes per read operation */%@AE@%%@NL@%
- unsigned long offset; %@AB@%/* bytes from start of file */%@AE@%%@NL@%
- char inbuf[BUFSIZ + 1], outbuf[LINEWIDTH + 1];%@NL@%
- char hexbuf[5];%@NL@%
- register char *inp, *outp;%@NL@%
- %@NL@%
- extern char *byte2hex(unsigned char, char *);%@NL@%
- extern char *word2hex(unsigned int, char *);%@NL@%
- %@NL@%
- offset = 0;%@NL@%
- while ((n = read(fd, inbuf, BUFSIZ)) != 0) {%@NL@%
- if (n == -1)%@NL@%
- return FAILURE;%@NL@%
- inp = inbuf;%@NL@%
- while (inp < inbuf + n) {%@NL@%
- outp = outbuf;%@NL@%
- %@NL@%
- %@AB@%/* offset in hex */%@AE@%%@NL@%
- outp += sprintf(outp, "%08lX",%@NL@%
- offset + (unsigned long)(inp - inbuf));%@NL@%
- *outp++ = ' ';%@NL@%
- %@NL@%
- %@AB@%/* block of bytes in hex */%@AE@%%@NL@%
- for (i = 0; i < NBYTES; ++i) {%@NL@%
- *outp++ = ' ';%@NL@%
- strcpy(outp, byte2hex(*inp++, hexbuf));%@NL@%
- outp += 2;%@NL@%
- }%@NL@%
- *outp++ = ' ';%@NL@%
- *outp++ = ' ';%@NL@%
- *outp++ = (strip == TRUE) ? '|' : LEFTMARK;%@NL@%
- %@NL@%
- %@AB@%/* same block of bytes in ASCII */%@AE@%%@NL@%
- inp -= NBYTES;%@NL@%
- for (i = 0; i < NBYTES; ++i) {%@NL@%
- if (strip == TRUE && (*inp < ' ' || *inp >= DEL))%@NL@%
- *outp = '.';%@NL@%
- else if (iscntrl(*inp))%@NL@%
- *outp = '.';%@NL@%
- else%@NL@%
- *outp = *inp;%@NL@%
- ++inp;%@NL@%
- ++outp;%@NL@%
- }%@NL@%
- *outp++ = (strip == TRUE) ? '|' : RGHTMARK;%@NL@%
- *outp++ = '\n';%@NL@%
- *outp = '\0';%@NL@%
- fputs(outbuf, stdout);%@NL@%
- }%@NL@%
- offset += n;%@NL@%
- }%@NL@%
- return SUCCESS;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INTERVAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\INTERVAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * interval -- report the interval given in seconds as%@NL@%
- %@AB@% * a human-readable null-terminated string%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- char *%@NL@%
- interval(seconds, buf)%@NL@%
- long seconds;%@NL@%
- char *buf;%@NL@%
- {%@NL@%
- int hh, mm, ss;%@NL@%
- long remainder;%@NL@%
- %@NL@%
- %@AB@%/* calculate the values */%@AE@%%@NL@%
- hh = seconds / 3600;%@NL@%
- remainder = seconds % 3600;%@NL@%
- mm = remainder / 60;%@NL@%
- ss = remainder - (mm * 60);%@NL@%
- sprintf(buf, "%02d:%02d:%02d\0", hh, mm, ss);%@NL@%
- %@NL@%
- return (buf);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ISCOLOR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\ISCOLOR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * iscolor -- return TRUE if a color display system is%@NL@%
- %@AB@% * in use and is set to one of the text modes%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- BOOLEAN%@NL@%
- iscolor()%@NL@%
- {%@NL@%
- getstate();%@NL@%
- if (Vmode != CGA_C40 || Vmode != CGA_C80)%@NL@%
- return TRUE;%@NL@%
- return FALSE;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%KBD_STAT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\KBD_STAT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * kbd_stat -- return the keyboard status%@NL@%
- %@AB@% * word (bit-significant)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@AI@%#include %@AE@%<local\keybdlib.h> %@NL@%
- %@NL@%
- unsigned char%@NL@%
- kbd_stat()%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = KBD_STATUS;%@NL@%
- int86(KEYBD_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return ((unsigned char)(outregs.h.al));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%KEYREADY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\KEYREADY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * keyready -- non-zero if the keyboard buffer%@NL@%
- %@AB@% * has any codes waiting%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- keyready()%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = CH_READY;%@NL@%
- intdos(&inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.h.al);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LAST_CH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\LAST_CH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * last_ch -- return a copy of the last character%@NL@%
- %@AB@% * before the NUL byte in a string%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char%@NL@%
- last_ch(s)%@NL@%
- char *s;%@NL@%
- {%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- %@AB@%/* find end of s */%@AE@%%@NL@%
- cp = s;%@NL@%
- while (*cp != '\0')%@NL@%
- ++cp;%@NL@%
- %@NL@%
- %@AB@%/* return previous character */%@AE@%%@NL@%
- --cp;%@NL@%
- return (*cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LINES.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\LINES.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * lines -- send newlines to the output stream%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- int%@NL@%
- lines(n, fp)%@NL@%
- int n;%@NL@%
- FILE *fp;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- %@NL@%
- for (i = 0; i < n; ++i)%@NL@%
- if (putc('\n', fp) == EOF && ferror(fp))%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* return number of newlines emitted */%@AE@%%@NL@%
- return (i);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\LS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls -- display a directory listing%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<signal.h> %@NL@%
- %@AI@%#include %@AE@%<search.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@AI@%#include %@AE@%"ls.h" %@NL@%
- %@NL@%
- %@AB@%/* allocation quantities */%@AE@%%@NL@%
- %@AI@%#define %@AE@%N_FILES 256 %@NL@%
- %@AI@%#define %@AE@%N_DIRS 16 %@NL@%
- %@NL@%
- %@AB@%/* global data */%@AE@%%@NL@%
- int Multicol = 0;%@NL@%
- int Filetype = 0;%@NL@%
- int Hidden = 0;%@NL@%
- int Longlist = 0;%@NL@%
- int Reverse = 0;%@NL@%
- int Modtime = 0;%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int ch, i;%@NL@%
- int errflag; %@AB@%/* error flag */%@AE@%%@NL@%
- char *ep; %@AB@%/* environment pointer */%@AE@%%@NL@%
- int status = 0; %@AB@%/* return status value */%@AE@%%@NL@%
- int fileattr; %@AB@%/* file attribute number */%@AE@%%@NL@%
- struct DTA buf; %@AB@%/* private disk buffer */%@AE@%%@NL@%
- char path[MAXPATH + 1]; %@AB@%/* working pathname */%@AE@%%@NL@%
- struct OUTBUF *fp, *fq; %@AB@%/* pointers to file array */%@AE@%%@NL@%
- char **dp, **dq; %@AB@%/* pointer to directory pointer array */%@AE@%%@NL@%
- int fbc = 1; %@AB@%/* file memory block allocation count */%@AE@%%@NL@%
- int dbc = 1; %@AB@%/* directory memory block allocation count */%@AE@%%@NL@%
- int nfiles; %@AB@%/* number of file elements */%@AE@%%@NL@%
- int ndirs; %@AB@%/* number of directory elements */%@AE@%%@NL@%
- %@NL@%
- static char pgm[MAXNAME + 1] = { "ls" };%@NL@%
- %@NL@%
- %@AB@%/* function prototypes */%@AE@%%@NL@%
- void getpname(char *, char *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind, opterr;%@NL@%
- extern char *optarg;%@NL@%
- extern char *drvpath(char *);%@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- extern void setdta(char *);%@NL@%
- extern int first_fm(char *, int);%@NL@%
- extern int next_fm();%@NL@%
- extern int ls_fcomp(struct OUTBUF *, struct OUTBUF *);%@NL@%
- extern int ls_dcomp(char *, char *);%@NL@%
- extern int ls_single(struct OUTBUF *, int);%@NL@%
- extern int ls_multi(struct OUTBUF *, int);%@NL@%
- extern int ls_dirx(char *, char *);%@NL@%
- int bailout();%@NL@%
- %@NL@%
- %@AB@%/* guarantee that needed DOS services are available */%@AE@%%@NL@%
- if (_osmajor < 2)%@NL@%
- fatal(pgm, "ls requires DOS 2.00 or later", 1);%@NL@%
- %@NL@%
- %@AB@%/* get program name from DOS (version 3.00 and later) */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* useful aliases (DOS version 3.00 and later) */%@AE@%%@NL@%
- if (strcmp(pgm, "lc") == 0)%@NL@%
- ++Multicol;%@NL@%
- if (strcmp(pgm, "lf") == 0) {%@NL@%
- ++Multicol;%@NL@%
- ++Filetype;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* prepare for emergencies */%@AE@%%@NL@%
- if (signal(SIGINT, bailout) == (int(*)())-1) {%@NL@%
- perror("Can't set SIGINT");%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* process optional arguments first */%@AE@%%@NL@%
- errflag = 0;%@NL@%
- while ((ch = getopt(argc, argv, "aCFlrt")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 'a':%@NL@%
- %@AB@%/* all files (hidden, system, etc.) */%@AE@%%@NL@%
- ++Hidden;%@NL@%
- break;%@NL@%
- case 'C':%@NL@%
- ++Multicol;%@NL@%
- break;%@NL@%
- case 'F':%@NL@%
- %@AB@%/* show file types (/=directory, *=executable) */%@AE@%%@NL@%
- ++Filetype;%@NL@%
- break;%@NL@%
- case 'l':%@NL@%
- %@AB@%/* long list (overrides multicolumn) */%@AE@%%@NL@%
- ++Longlist;%@NL@%
- break;%@NL@%
- case 'r':%@NL@%
- %@AB@%/* reverse sort */%@AE@%%@NL@%
- ++Reverse;%@NL@%
- break;%@NL@%
- case 't':%@NL@%
- %@AB@%/* sort by file modification time */%@AE@%%@NL@%
- ++Modtime;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- %@NL@%
- %@AB@%/* check for command-line errors */%@AE@%%@NL@%
- if (argc < 0 || errflag) {%@NL@%
- fprintf(stderr, "Usage: %s [-aCFlrt] [pathname ...]", pgm);%@NL@%
- exit(3);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* allocate initial file and directory storage areas */%@AE@%%@NL@%
- dp = dq = (char **)malloc(N_DIRS * sizeof (char *));%@NL@%
- if (dp == NULL)%@NL@%
- fatal(pgm, "Out of memory", 4);%@NL@%
- fp = fq = (struct OUTBUF *)malloc(N_FILES * sizeof (struct OUTBUF));%@NL@%
- if (fp == NULL)%@NL@%
- fatal(pgm, "Out of memory", 4);%@NL@%
- nfiles = ndirs = 0;%@NL@%
- %@NL@%
- %@AB@%/* use current directory if no args */%@AE@%%@NL@%
- if (argc == 0) {%@NL@%
- if (getcwd(path, MAXPATH) == NULL)%@NL@%
- fatal(pgm, "Cannot get current directory", 5);%@NL@%
- *dq = path;%@NL@%
- ndirs = 1;%@NL@%
- }%@NL@%
- else {%@NL@%
- %@AB@%/* use arguments as file and directory names */%@AE@%%@NL@%
- for ( ; argc-- > 0; ++argv) {%@NL@%
- strcpy(path, *argv);%@NL@%
- if (path[0] == '\\') {%@NL@%
- %@AB@%/* prepend default drive name */%@AE@%%@NL@%
- memcpy(path + 2, path, strlen(path) + 1);%@NL@%
- path[0] = 'a' + getdrive();%@NL@%
- path[1] = ':';%@NL@%
- }%@NL@%
- if (path[1] == ':' && path[2] == '\0' && drvpath(path) == NULL) {%@NL@%
- fprintf(stderr, "%s: Cannot get drive path", pgm);%@NL@%
- continue;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* establish private disk transfer area */%@AE@%%@NL@%
- setdta((char *)&buf);%@NL@%
- %@NL@%
- %@AB@%/* set file attribute for search */%@AE@%%@NL@%
- if (Hidden)%@NL@%
- fileattr = SUBDIR | HIDDEN | SYSTEM | READONLY;%@NL@%
- else%@NL@%
- fileattr = SUBDIR;%@NL@%
- if (first_fm(path, fileattr) != 0 && path[3] != '\0') {%@NL@%
- fprintf(stderr, "%s -- No such file or directory\n", path);%@NL@%
- continue;%@NL@%
- }%@NL@%
- if ((buf.d_attr & SUBDIR) == SUBDIR || path[3] == '\0') {%@NL@%
- %@AB@%/* path is a (sub)directory */%@AE@%%@NL@%
- *dq = strdup(path);%@NL@%
- if (++ndirs == dbc * N_DIRS) {%@NL@%
- ++dbc; %@AB@%/* increase space requirement */%@AE@%%@NL@%
- dp = (char **)realloc(dp, dbc * N_DIRS * sizeof (char *));%@NL@%
- if (dp == NULL)%@NL@%
- fatal(pgm, "Out of memory", 4);%@NL@%
- dq = dp + dbc * N_DIRS;%@NL@%
- }%@NL@%
- else%@NL@%
- ++dq;%@NL@%
- }%@NL@%
- else {%@NL@%
- fq->o_name = strdup(path);%@NL@%
- fq->o_mode = buf.d_attr;%@NL@%
- fq->o_date = buf.d_mdate;%@NL@%
- fq->o_time = buf.d_mtime;%@NL@%
- fq->o_size = buf.d_fsize;%@NL@%
- if (++nfiles == fbc * N_FILES) {%@NL@%
- ++fbc;%@NL@%
- fp = (struct OUTBUF *)realloc(fp, fbc * N_FILES * sizeof (struct OUTBUF));%@NL@%
- if (fp == NULL)%@NL@%
- fatal(pgm, "Out of memory", 4);%@NL@%
- fq = fp + fbc * N_FILES;%@NL@%
- }%@NL@%
- else%@NL@%
- ++fq;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* output file list, if any */%@AE@%%@NL@%
- if (nfiles > 0) {%@NL@%
- qsort(fp, nfiles, sizeof(struct OUTBUF), ls_fcomp);%@NL@%
- if (Longlist)%@NL@%
- ls_long(fp, nfiles);%@NL@%
- else if (Multicol)%@NL@%
- ls_multi(fp, nfiles);%@NL@%
- else%@NL@%
- ls_single(fp, nfiles);%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- free(fp);%@NL@%
- %@NL@%
- %@AB@%/* output directory lists, if any */%@AE@%%@NL@%
- if (ndirs == 1 && nfiles == 0) {%@NL@%
- %@AB@%/* expand directory and output without header */%@AE@%%@NL@%
- if (ls_dirx(pgm, *dp))%@NL@%
- fprintf(stderr, "%s -- empty directory\n", strlwr(*dp));%@NL@%
- }%@NL@%
- else if (ndirs > 0) {%@NL@%
- %@AB@%/* expand each directory and output with headers */%@AE@%%@NL@%
- dq = dp;%@NL@%
- qsort(dp, ndirs, sizeof(char *), ls_dcomp);%@NL@%
- while (ndirs-- > 0) {%@NL@%
- fprintf(stdout, "%s:\n", strlwr(*dq));%@NL@%
- if (ls_dirx(pgm, *dq++))%@NL@%
- fprintf(stderr, "%s -- empty directory\n",%@NL@%
- strlwr(*dq));%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * bailout -- optionally terminate upon interrupt%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int%@NL@%
- bailout()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- signal(SIGINT, bailout);%@NL@%
- printf("\nTerminate directory listing? ");%@NL@%
- scanf("%1s", &ch);%@NL@%
- if (ch == 'y' || ch == 'Y')%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LS_DIRX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\LS_DIRX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_dirx -- expand the contents of a directory using%@NL@%
- %@AB@% * the DOS first/next matching file functions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%DEBUG %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<signal.h> %@NL@%
- %@AI@%#include %@AE@%<search.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@AI@%#include %@AE@%"ls.h" %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NFILES 1024 %@NL@%
- %@NL@%
- extern int Recursive;%@NL@%
- extern int Longlist;%@NL@%
- extern int Multicol;%@NL@%
- extern int Hidden;%@NL@%
- %@NL@%
- int%@NL@%
- ls_dirx(pname, namep)%@NL@%
- char *pname;%@NL@%
- char *namep;%@NL@%
- {%@NL@%
- int status = 0; %@AB@%/* function return value */%@AE@%%@NL@%
- int n; %@AB@%/* number of items found */%@AE@%%@NL@%
- int fileattr; %@AB@%/* attributes of file-matching */%@AE@%%@NL@%
- struct DTA buf; %@AB@%/* disk transfer area */%@AE@%%@NL@%
- struct OUTBUF *bp, *bq; %@AB@%/* output buffer pointers */%@AE@%%@NL@%
- char path[MAXPATH + 1]; %@AB@%/* working path string */%@AE@%%@NL@%
- %@NL@%
- extern void setdta(char *);%@NL@%
- extern int first_fm(char *, int);%@NL@%
- extern int next_fm();%@NL@%
- extern int ls_fcomp(struct OUTBUF *, struct OUTBUF *);%@NL@%
- extern char last_ch(char *);%@NL@%
- %@NL@%
- %@AB@%/* allocate a buffer */%@AE@%%@NL@%
- bp = bq = (struct OUTBUF *)malloc(NFILES * sizeof(struct OUTBUF));%@NL@%
- if (bp == NULL)%@NL@%
- fatal(pname, "Out of memory");%@NL@%
- %@NL@%
- %@AB@%/* form name for directory search */%@AE@%%@NL@%
- strcpy(path, namep);%@NL@%
- if (last_ch(path) != '\\')%@NL@%
- strcat(path, "\\");%@NL@%
- strcat(path, "*.*");%@NL@%
- %@NL@%
- %@AB@%/* list the files found */%@AE@%%@NL@%
- n = 0;%@NL@%
- %@AB@%/* establish a private DTA */%@AE@%%@NL@%
- setdta((char *)&buf);%@NL@%
- %@AB@%/* select file attributes */%@AE@%%@NL@%
- if (Hidden)%@NL@%
- fileattr = SUBDIR | HIDDEN | SYSTEM | READONLY;%@NL@%
- else%@NL@%
- fileattr = SUBDIR;%@NL@%
- if (first_fm(path, fileattr) == 0) {%@NL@%
- %@AB@%/* add file or directory to the buffer */%@AE@%%@NL@%
- do {%@NL@%
- if (!Hidden && buf.d_fname[0] == '.')%@NL@%
- continue;%@NL@%
- bq->o_name = strdup(buf.d_fname);%@NL@%
- bq->o_mode = buf.d_attr;%@NL@%
- bq->o_size = buf.d_fsize;%@NL@%
- bq->o_date = buf.d_mdate;%@NL@%
- bq->o_time = buf.d_mtime;%@NL@%
- ++bq;%@NL@%
- ++n;%@NL@%
- setdta((char *)&buf); %@AB@%/* reset to our DTA */%@AE@%%@NL@%
- } while (next_fm() == 0);%@NL@%
- %@NL@%
- if (n > 0) {%@NL@%
- %@AB@%/* got some -- sort and list them */%@AE@%%@NL@%
- qsort(bp, n, sizeof(struct OUTBUF), ls_fcomp);%@NL@%
- if (Longlist)%@NL@%
- ls_long(bp, n);%@NL@%
- else if (Multicol)%@NL@%
- ls_multi(bp, n);%@NL@%
- else%@NL@%
- ls_single(bp, n);%@NL@%
- }%@NL@%
- }%@NL@%
- else %@NL@%
- ++status;%@NL@%
- free(bp);%@NL@%
- %@NL@%
- return (status);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LS_FCOMP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\LS_FCOMP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_fcomp -- file and directory comparison functions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"ls.h" %@NL@%
- %@NL@%
- extern int Modtime;%@NL@%
- extern int Reverse;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_fcomp -- compare two "file" items%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- ls_fcomp(s1, s2)%@NL@%
- struct OUTBUF *s1, *s2;%@NL@%
- {%@NL@%
- int result;%@NL@%
- %@NL@%
- if (Modtime) {%@NL@%
- if ((result = s1->o_date - s2->o_date) == 0)%@NL@%
- result = s1->o_time - s2->o_time;%@NL@%
- }%@NL@%
- else%@NL@%
- result = strcmp(s1->o_name, s2->o_name);%@NL@%
- %@NL@%
- return (Reverse ? -result : result);%@NL@%
- } %@AB@%/* end_fcomp() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * dcomp -- compare two "directory" items%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- ls_dcomp(s1, s2)%@NL@%
- char *s1, *s2;%@NL@%
- {%@NL@%
- int result;%@NL@%
- %@NL@%
- result = strcmp(s1, s2);%@NL@%
- %@NL@%
- return (Reverse ? -result : result);%@NL@%
- } %@AB@%/* end ls_dcomp() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LS_LIST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\LS_LIST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_list -- list functions (long, single, multi) for ls%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%"ls.h" %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXCOL 80 %@NL@%
- %@AI@%#define %@AE@%MONTH_SHIFT 5 %@NL@%
- %@AI@%#define %@AE@%MONTH_MASK 0x0F %@NL@%
- %@AI@%#define %@AE@%DAY_MASK 0x1F %@NL@%
- %@AI@%#define %@AE@%YEAR_SHIFT 9 %@NL@%
- %@AI@%#define %@AE@%DOS_EPOCH 80 %@NL@%
- %@AI@%#define %@AE@%HOUR_SHIFT 11 %@NL@%
- %@AI@%#define %@AE@%HOUR_MASK 0x1F %@NL@%
- %@AI@%#define %@AE@%MINUTE_SHIFT 5 %@NL@%
- %@AI@%#define %@AE@%MINUTE_MASK 0x3F %@NL@%
- %@NL@%
- extern int Filetype;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_long -- list items in "long" format (mode time size name)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- ls_long(buf, nelem)%@NL@%
- struct OUTBUF *buf;%@NL@%
- int nelem;%@NL@%
- {%@NL@%
- int n = 0;%@NL@%
- char modebuf[5];%@NL@%
- static void modestr(unsigned short, char *);%@NL@%
- %@NL@%
- while (nelem-- > 0) {%@NL@%
- %@AB@%/* convert mode number to a string */%@AE@%%@NL@%
- modestr(buf->o_mode, modebuf);%@NL@%
- printf("%s ", modebuf);%@NL@%
- %@NL@%
- %@AB@%/* display file size in bytes */%@AE@%%@NL@%
- if ((buf->o_mode & SUBDIR) == SUBDIR)%@NL@%
- printf(" ");%@NL@%
- else%@NL@%
- printf("%7ld ", buf->o_size);%@NL@%
- %@NL@%
- %@AB@%/* convert date and time values to formatted presentation */%@AE@%%@NL@%
- printf("%02d-%02d-%02d ", (buf->o_date >> MONTH_SHIFT) & MONTH_MASK,%@NL@%
- buf->o_date & DAY_MASK, (buf->o_date >> YEAR_SHIFT) + DOS_EPOCH);%@NL@%
- printf("%02d:%02d ", (buf->o_time >> HOUR_SHIFT) & HOUR_MASK,%@NL@%
- (buf->o_time >> MINUTE_SHIFT) & MINUTE_MASK);%@NL@%
- %@NL@%
- %@AB@%/* display filenames as lowercase strings */%@AE@%%@NL@%
- printf("%s\n", strlwr(buf->o_name));%@NL@%
- %@NL@%
- ++buf;%@NL@%
- ++n;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* tell caller how many entries were printed */%@AE@%%@NL@%
- return (n);%@NL@%
- } %@AB@%/* end ls_long() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_single -- list items in a single column%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- ls_single(buf, nelem)%@NL@%
- struct OUTBUF *buf;%@NL@%
- int nelem;%@NL@%
- {%@NL@%
- int n = 0;%@NL@%
- %@NL@%
- while (nelem-- > 0) {%@NL@%
- printf("%s", strlwr(buf->o_name));%@NL@%
- if (Filetype && (buf->o_mode & SUBDIR) == SUBDIR)%@NL@%
- putchar('\\');%@NL@%
- putchar('\n');%@NL@%
- ++buf;%@NL@%
- ++n;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* tell caller how many entries were printed */%@AE@%%@NL@%
- return (n);%@NL@%
- } %@AB@%/* end ls_single() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ls_multi -- list items in multiple columns that%@NL@%
- %@AB@% * vary in width and number based on longest item size%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- ls_multi(buf, nelem)%@NL@%
- struct OUTBUF *buf;%@NL@%
- int nelem;%@NL@%
- {%@NL@%
- int i, j;%@NL@%
- int errcount = 0;%@NL@%
- struct OUTBUF *tmp; %@AB@%/* temporary buffer pointer */%@AE@%%@NL@%
- struct OUTBUF *base; %@AB@%/* buffer pointer for multi-col output */%@AE@%%@NL@%
- int n; %@AB@%/* number of items in list */%@AE@%%@NL@%
- int len, maxlen; %@AB@%/* pathname lengths */%@AE@%%@NL@%
- int ncols; %@AB@%/* number of columns to output */%@AE@%%@NL@%
- int nlines; %@AB@%/* number of lines to output */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * get length of longest pathname and calculate number%@NL@%
- %@AB@% * of columns and lines (col width = maxlen + 1)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- tmp = buf;%@NL@%
- n = 0;%@NL@%
- maxlen = 0;%@NL@%
- for (tmp = buf, n = 0; n < nelem; ++tmp, ++n)%@NL@%
- if ((len = strlen(tmp->o_name)) > maxlen)%@NL@%
- maxlen = len;%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * use width of screen - 1 to allow for newline at end of%@NL@%
- %@AB@% * line and leave two spaces between entries (one for optional%@NL@%
- %@AB@% * file type flag)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ncols = (MAXCOL - 1) / (maxlen + 2);%@NL@%
- nlines = n / ncols;%@NL@%
- if (n % ncols)%@NL@%
- ++nlines;%@NL@%
- %@NL@%
- %@AB@%/* output multi-column list */%@AE@%%@NL@%
- base = buf;%@NL@%
- for (i = 0; i < nlines; ++i) {%@NL@%
- tmp = base;%@NL@%
- for (j = 0; j < ncols; ++j) {%@NL@%
- len = maxlen + 2;%@NL@%
- len -= printf("%s", strlwr(tmp->o_name));%@NL@%
- if (Filetype && (tmp->o_mode & SUBDIR) == SUBDIR) {%@NL@%
- putchar('\\');%@NL@%
- --len;%@NL@%
- }%@NL@%
- while (len-- > 0)%@NL@%
- putchar(' ');%@NL@%
- tmp += nlines;%@NL@%
- if (tmp - buf >= nelem)%@NL@%
- break;%@NL@%
- }%@NL@%
- putchar('\n');%@NL@%
- ++base;%@NL@%
- }%@NL@%
- %@NL@%
- return (errcount);%@NL@%
- } %@AB@%/* end ls_multi() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- static void%@NL@%
- modestr(mode, s)%@NL@%
- unsigned short mode; %@AB@%/* file mode number */%@AE@%%@NL@%
- char s[]; %@AB@%/* mode string buffer */%@AE@%%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* fill in the mode string to show what's set */%@AE@%%@NL@%
- s[0] = (mode & SUBDIR) == SUBDIR ? 'd' : '-';%@NL@%
- s[1] = (mode & HIDDEN) == HIDDEN ? 'h' : '-';%@NL@%
- s[2] = (mode & SYSTEM) == SYSTEM ? 's' : '-';%@NL@%
- s[3] = (mode & READONLY) == READONLY ? 'r' : '-';%@NL@%
- s[4] = '\0';%@NL@%
- } %@AB@%/* end modestr() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MEMCHK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\MEMCHK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * memchk -- look for random-access memory at%@NL@%
- %@AB@% * a specified location; return non-zero if found%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@NL@%
- int%@NL@%
- memchk(seg, os)%@NL@%
- unsigned int seg;%@NL@%
- unsigned int os;%@NL@%
- {%@NL@%
- unsigned char tstval, oldval, newval;%@NL@%
- unsigned int ds;%@NL@%
- struct SREGS segregs;%@NL@%
- %@NL@%
- %@AB@%/* get value of current data segment */%@AE@%%@NL@%
- segread(&segregs);%@NL@%
- ds = segregs.ds;%@NL@%
- %@NL@%
- %@AB@%/* save current contents of test location */%@AE@%%@NL@%
- movedata(seg, os, ds, (unsigned int)&oldval, 1);%@NL@%
- %@NL@%
- %@AB@%/* copy a known value into test location */%@AE@%%@NL@%
- tstval = 0xFC;%@NL@%
- movedata(ds, (unsigned int)&tstval, seg, os, 1);%@NL@%
- %@NL@%
- %@AB@%/* read test value back and comapre to value written */%@AE@%%@NL@%
- movedata(seg, os, ds, (unsigned int)&newval, 1);%@NL@%
- if (newval != tstval)%@NL@%
- return (0);%@NL@%
- %@NL@%
- %@AB@%/* restore original contents of test location */%@AE@%%@NL@%
- movedata(ds, (unsigned int)&oldval, seg, os, 1);%@NL@%
- %@NL@%
- return (1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MEMSIZE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\MEMSIZE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * memsize -- get memory size%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- memsize()%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- return (int86(MEM_SIZE, &inregs, &outregs));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MENUMODE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\MENUMODE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * menumode -- process user commands interactively%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@AI@%#include %@AE@%<local\ibmcolor.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@NL@%
- %@AB@%/* maximum color number */%@AE@%%@NL@%
- %@AI@%#define %@AE@%MAX_CNUM 15 %@NL@%
- %@NL@%
- void%@NL@%
- menumode()%@NL@%
- {%@NL@%
- register int ch;%@NL@%
- int foreground, background, border;%@NL@%
- extern void setattr(POSITION, int);%@NL@%
- extern void sc_cmds(int, int, int);%@NL@%
- %@NL@%
- %@AB@%/* default attributes */%@AE@%%@NL@%
- foreground = IBM_WHITE;%@NL@%
- background = IBM_BLACK;%@NL@%
- border = IBM_BLACK;%@NL@%
- %@NL@%
- ANSI_SGR(ANSI_NORMAL);%@NL@%
- setattr(FGND, foreground);%@NL@%
- setattr(BKGND, background);%@NL@%
- ANSI_ED;%@NL@%
- palette(0, border);%@NL@%
- sc_cmds(foreground, background, border);%@NL@%
- while ((ch = getkey()) != K_RETURN) {%@NL@%
- switch (ch) {%@NL@%
- case K_F1:%@NL@%
- %@AB@%/* decrement foreground color */%@AE@%%@NL@%
- if (--foreground < 0)%@NL@%
- foreground = MAX_CNUM;%@NL@%
- break;%@NL@%
- case K_F2:%@NL@%
- %@AB@%/* increment foreground color */%@AE@%%@NL@%
- if (++foreground > MAX_CNUM)%@NL@%
- foreground = 0;%@NL@%
- break;%@NL@%
- case K_F3:%@NL@%
- %@AB@%/* decrement background color */%@AE@%%@NL@%
- if (--background < 0)%@NL@%
- background = MAX_CNUM;%@NL@%
- break;%@NL@%
- case K_F4:%@NL@%
- %@AB@%/* increment background color */%@AE@%%@NL@%
- if (++background > MAX_CNUM)%@NL@%
- background = 0;%@NL@%
- break;%@NL@%
- case K_F5:%@NL@%
- %@AB@%/* decrement border color */%@AE@%%@NL@%
- if (--border < 0)%@NL@%
- border = MAX_CNUM;%@NL@%
- break;%@NL@%
- case K_F6:%@NL@%
- %@AB@%/* increment border color number */%@AE@%%@NL@%
- if (++border > MAX_CNUM)%@NL@%
- border = 0;%@NL@%
- break;%@NL@%
- default:%@NL@%
- continue;%@NL@%
- }%@NL@%
- ANSI_SGR(ANSI_NORMAL);%@NL@%
- setattr(FGND, foreground);%@NL@%
- setattr(BKGND, background);%@NL@%
- palette(0, border);%@NL@%
- ANSI_ED;%@NL@%
- sc_cmds(foreground, background, border);%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MESSAGE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\MESSAGE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * message -- routines used to display and clear%@NL@%
- %@AB@% * messages in a reserved message area%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"message.h" %@NL@%
- %@NL@%
- MESSAGE Ml;%@NL@%
- extern int writec(char, int, int);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * set up the message-line manager%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void%@NL@%
- initmsg(r, c, w, a, pg)%@NL@%
- int r; %@AB@%/* message row */%@AE@%%@NL@%
- int c; %@AB@%/* message column */%@AE@%%@NL@%
- int w; %@AB@%/* width of message field */%@AE@%%@NL@%
- unsigned char a; %@AB@%/* message field video attribute */%@AE@%%@NL@%
- int pg; %@AB@%/* active page for messages */%@AE@%%@NL@%
- {%@NL@%
- MESSAGE *mp;%@NL@%
- void clrmsg();%@NL@%
- %@NL@%
- mp = &Ml;%@NL@%
- mp->m_row = r;%@NL@%
- mp->m_col = c;%@NL@%
- mp->m_wid = w;%@NL@%
- mp->m_attr = a;%@NL@%
- mp->m_pg = pg;%@NL@%
- mp->m_flag = 1;%@NL@%
- clrmsg();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showmsg -- display a message and set the message flag%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void%@NL@%
- showmsg(msg)%@NL@%
- char *msg;%@NL@%
- {%@NL@%
- MESSAGE *mp;%@NL@%
- %@NL@%
- mp = &Ml;%@NL@%
- putcur(mp->m_row, mp->m_col, mp->m_pg);%@NL@%
- writec(' ', mp->m_wid, mp->m_pg);%@NL@%
- putstr(msg, mp->m_pg);%@NL@%
- mp->m_flag = 1;%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * clrmsg -- erase the message area and reset the message flag%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void%@NL@%
- clrmsg()%@NL@%
- {%@NL@%
- MESSAGE *mp;%@NL@%
- %@NL@%
- mp = &Ml;%@NL@%
- if (mp->m_flag != 0) {%@NL@%
- putcur(mp->m_row, mp->m_col, mp->m_pg);%@NL@%
- writec(' ', mp->m_wid, mp->m_pg);%@NL@%
- mp->m_flag = 0;%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\07CONFIG\MX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * mx -- control Epson MX-series printer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\printer.h> %@NL@%
- %@NL@%
- extern PRINTER prt; %@AB@%/* printer data */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int ch, font;%@NL@%
- BOOLEAN errflag; %@AB@%/* option error */%@AE@%%@NL@%
- BOOLEAN clrflag; %@AB@%/* clear special fonts */%@AE@%%@NL@%
- BOOLEAN rflag; %@AB@%/* hardware reset */%@AE@%%@NL@%
- BOOLEAN tflag; %@AB@%/* top-of-form */%@AE@%%@NL@%
- FILE *fout;%@NL@%
- static char pgm[MAXNAME + 1] = { "mx" };%@NL@%
- %@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- extern char *getpname(char *, char *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern char *optarg;%@NL@%
- extern int optind, opterr;%@NL@%
- extern int setprnt();%@NL@%
- extern int clrprnt(FILE *);%@NL@%
- extern int setfont(int, FILE *);%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- if (setprnt() == -1) {%@NL@%
- fprintf(stderr, "%s: Bad printer configuration\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* interpret command line */%@AE@%%@NL@%
- errflag = clrflag = rflag = tflag = FALSE;%@NL@%
- font = 0;%@NL@%
- fout = stdprn;%@NL@%
- while ((ch = getopt(argc, argv, "bcdefino:prtu")) != EOF) {%@NL@%
- switch (ch) {%@NL@%
- case 'b':%@NL@%
- %@AB@%/* set bold */%@AE@%%@NL@%
- font |= EMPHASIZED;%@NL@%
- break;%@NL@%
- case 'c':%@NL@%
- %@AB@%/* set compressed */%@AE@%%@NL@%
- font |= CONDENSED;%@NL@%
- break;%@NL@%
- case 'd':%@NL@%
- %@AB@%/* set double strike */%@AE@%%@NL@%
- font |= DOUBLE;%@NL@%
- break;%@NL@%
- case 'e':%@NL@%
- %@AB@%/* set double strike */%@AE@%%@NL@%
- font |= EXPANDED;%@NL@%
- break;%@NL@%
- case 'i':%@NL@%
- %@AB@%/* set italic */%@AE@%%@NL@%
- font |= ITALICS;%@NL@%
- break;%@NL@%
- case 'n':%@NL@%
- %@AB@%/* set normal (clear all special fonts) */%@AE@%%@NL@%
- clrflag = TRUE;%@NL@%
- break;%@NL@%
- case 'o':%@NL@%
- %@AB@%/* use specified output stream */%@AE@%%@NL@%
- if ((fout = fopen(optarg, "w")) == NULL)%@NL@%
- fatal(pgm, "cannot open output stream", 1);%@NL@%
- break;%@NL@%
- case 'p':%@NL@%
- %@AB@%/* preview control strings on stdout */%@AE@%%@NL@%
- fout = stdout;%@NL@%
- break;%@NL@%
- case 'r':%@NL@%
- %@AB@%/* hardware reset */%@AE@%%@NL@%
- rflag = TRUE;%@NL@%
- break;%@NL@%
- case 't':%@NL@%
- %@AB@%/* top of form */%@AE@%%@NL@%
- tflag = TRUE;%@NL@%
- break;%@NL@%
- case 'u':%@NL@%
- %@AB@%/* set underline */%@AE@%%@NL@%
- font |= UNDERLINE;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* unknown option */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* report errors, if any */%@AE@%%@NL@%
- if (errflag == TRUE || argc == 1) {%@NL@%
- fprintf(stderr, "Usage: %s -option\n", pgm);%@NL@%
- fprintf(stderr,%@NL@%
- "b=bold, c=compressed, d=double strike, e=expanded\n");%@NL@%
- fprintf(stderr,%@NL@%
- "i=italic, n=normal, o file=output to file\n");%@NL@%
- fprintf(stderr,%@NL@%
- "p=preview, r=reset, t=top-of-form, u=underline\n");%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* do hardware reset and formfeed first */%@AE@%%@NL@%
- if (rflag == TRUE)%@NL@%
- fputs(prt.p_init, fout);%@NL@%
- else if (tflag == TRUE)%@NL@%
- fputc('\f', fout);%@NL@%
- %@NL@%
- %@AB@%/* clear or set the aggregate font */%@AE@%%@NL@%
- if (clrflag == TRUE)%@NL@%
- clrprnt(fout);%@NL@%
- else if (setfont(font, fout) == FAILURE) {%@NL@%
- fprintf(stderr, "%s: Bad font spec\n", pgm);%@NL@%
- exit(3);%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NEXT_FM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\NEXT_FM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * next_fm - find next file match in work directory%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- next_fm()%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- %@AB@%/* find next matching file */%@AE@%%@NL@%
- inregs.h.ah = FIND_NEXT;%@NL@%
- (void)intdos(&inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NLERASE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\NLERASE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * nlerase -- replace the first newline in a string%@NL@%
- %@AB@% * with a null character%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char *%@NL@%
- nlerase(s)%@NL@%
- char *s;%@NL@%
- {%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- cp = s;%@NL@%
- while (*cp != '\n' && *cp != '\0')%@NL@%
- ++cp;%@NL@%
- *cp = '\0';%@NL@%
- %@NL@%
- return (s);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NOTES1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\04STDLIB\NOTES1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * notes1 -- add an entry to a "notes" text file%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * version 1: appends new data to NOTES.TXT in the%@NL@%
- %@AB@% * current directory -- uses local date/time stamp%@NL@%
- %@AB@% * as a header for each new entry%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *fp;%@NL@%
- static char notesfile[MAXPATH + 1] = { "notes.txt" };%@NL@%
- char ch;%@NL@%
- long ltime;%@NL@%
- static char pgm[MAXNAME + 1] = { "notes1" };%@NL@%
- %@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- %@NL@%
- %@AB@%/* try to open notes file in current directory */%@AE@%%@NL@%
- if ((fp = fopen(notesfile, "a")) == NULL)%@NL@%
- fatal(pgm, notesfile, 1);%@NL@%
- %@NL@%
- %@AB@%/* append a header and date/time tag */%@AE@%%@NL@%
- ltime = time(NULL);%@NL@%
- fprintf(stderr, "Appending to %s: %s",%@NL@%
- notesfile, ctime(<ime));%@NL@%
- fprintf(fp, "%s", ctime(<ime));%@NL@%
- %@NL@%
- %@AB@%/* append new text */%@AE@%%@NL@%
- while ((ch = getchar()) != EOF)%@NL@%
- putc(ch, fp);%@NL@%
- %@NL@%
- %@AB@%/* clean up */%@AE@%%@NL@%
- if (fclose(fp))%@NL@%
- fatal(pgm, notesfile, 2);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NOTES2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\04STDLIB\NOTES2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * notes2 -- add a date/time stamped entry to a%@NL@%
- %@AB@% * "notes" data file. Allow user to optionally%@NL@%
- %@AB@% * edit the data file upon completion of the entry.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<signal.h> %@NL@%
- %@AI@%#include %@AE@%<process.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AB@%/* length of date/time string */%@AE@%%@NL@%
- %@AI@%#define %@AE@%DT_STR 26 %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int n; %@AB@%/* number of lines added */%@AE@%%@NL@%
- int exitcode = 0;%@NL@%
- FILE *fp;%@NL@%
- static char notesfile[MAXPATH + 1] = { "notes.txt" };%@NL@%
- static char editname[MAXPATH + 1] = { "edlin" };%@NL@%
- char ch;%@NL@%
- char dt_stamp[DT_STR];%@NL@%
- char *s;%@NL@%
- long ltime;%@NL@%
- static char pgm[MAXNAME + 1] = { "notes3" };%@NL@%
- %@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- extern void getpname(char *, char *);%@NL@%
- static int addtxt(FILE *, FILE *);%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* locate the "notes" database file and open it */%@AE@%%@NL@%
- if (argc > 1)%@NL@%
- strcpy(notesfile, *++argv);%@NL@%
- else if (s = getenv("NOTESFILE"))%@NL@%
- strcpy(notesfile, s);%@NL@%
- if ((fp = fopen(notesfile, "a")) == NULL)%@NL@%
- fatal(pgm, notesfile, 1);%@NL@%
- %@NL@%
- %@AB@%/* disable Ctrl-Break interrupt */%@AE@%%@NL@%
- if (signal(SIGINT, SIG_IGN) == (int(*)())-1)%@NL@%
- perror("Cannot set signal");%@NL@%
- %@NL@%
- %@AB@%/* append a header and date/time tag */%@AE@%%@NL@%
- ltime = time(NULL);%@NL@%
- strcpy(dt_stamp, ctime(<ime));%@NL@%
- fprintf(stderr, "Appending to %s: %s", notesfile, dt_stamp);%@NL@%
- fprintf(fp, "\n%s", dt_stamp);%@NL@%
- %@NL@%
- %@AB@%/* add text to notes file */%@AE@%%@NL@%
- if ((n = addtxt(stdin, fp)) == 0) {%@NL@%
- fputs("No new text", stderr);%@NL@%
- if (fclose(fp))%@NL@%
- fatal(pgm, notesfile, 2);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- else%@NL@%
- fprintf(stderr, "%d line(s) added to %s\n", n, notesfile);%@NL@%
- if (fclose(fp))%@NL@%
- fatal(pgm, notesfile, 2);%@NL@%
- %@NL@%
- %@AB@%/* optionally edit text in the notes file */%@AE@%%@NL@%
- fprintf(stderr, "E + ENTER to edit; ENTER alone to quit: ");%@NL@%
- while ((ch = tolower(getchar())) != '\n')%@NL@%
- if (ch = 'e') {%@NL@%
- if (s = getenv("EDITOR"))%@NL@%
- strcpy(editname, s);%@NL@%
- if ((exitcode = spawnlp(P_WAIT, editname, editname,%@NL@%
- notesfile, NULL)) == -1)%@NL@%
- fatal(pgm, editname, 3);%@NL@%
- }%@NL@%
- exit(exitcode);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * addtxt -- append new text to notes file%@NL@%
- %@AB@% */%@AE@%%@NL@%
- static int addtxt(fin, fout)%@NL@%
- FILE *fin, *fout;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- int col = 0; %@AB@%/* column */%@AE@%%@NL@%
- int n = 0; %@AB@%/* number of lines added */%@AE@%%@NL@%
- %@NL@%
- while ((ch = fgetc(fin)) != EOF) {%@NL@%
- if (ch == '.' && col == 0) {%@NL@%
- ch = fgetc(fin); %@AB@%/* trash the newline */%@AE@%%@NL@%
- break;%@NL@%
- }%@NL@%
- fputc(ch, fout);%@NL@%
- if (ch == '\n') {%@NL@%
- col = 0;%@NL@%
- ++n;%@NL@%
- }%@NL@%
- else%@NL@%
- ++col;%@NL@%
- }%@NL@%
- return (n);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PALETTE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\PALETTE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * palette -- set graphics color values or border color%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- palette(id, color)%@NL@%
- unsigned int id, color;%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = PALETTE;%@NL@%
- inregs.h.bh = id;%@NL@%
- inregs.h.bl = color;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return(outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PARSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\PARSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * parse -- process a list of attribute specifications%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\ibmcolor.h> %@NL@%
- %@NL@%
- %@AB@%/* buffer length for string comparisons */%@AE@%%@NL@%
- %@AI@%#define %@AE@%NCHARS 3 %@NL@%
- %@AI@%#define %@AE@%C_MASK 0x7 %@NL@%
- %@NL@%
- void%@NL@%
- parse(nargs, argvec)%@NL@%
- int nargs; %@AB@%/* number of argument vectors */%@AE@%%@NL@%
- char *argvec[]; %@AB@%/* pointer to the argument vector array */%@AE@%%@NL@%
- {%@NL@%
- int i, intensity;%@NL@%
- int attribute;%@NL@%
- POSITION pos;%@NL@%
- char str[NCHARS + 1];%@NL@%
- extern int colornum(char *);%@NL@%
- extern void setattr(POSITION, int);%@NL@%
- %@NL@%
- %@AB@%/* clear all attributes */%@AE@%%@NL@%
- ANSI_SGR(ANSI_NORMAL);%@NL@%
- %@NL@%
- %@AB@%/* look for a single attribute specification */%@AE@%%@NL@%
- if (nargs == 2) {%@NL@%
- attribute = colornum(argvec[1]);%@NL@%
- switch (attribute) {%@NL@%
- case IBM_NORMAL:%@NL@%
- palette(0, IBM_BLACK);%@NL@%
- return;%@NL@%
- case IBM_REVERSE:%@NL@%
- ANSI_SGR(ANSI_REVERSE);%@NL@%
- palette(0, IBM_WHITE);%@NL@%
- return;%@NL@%
- case IBM_INVISIBLE:%@NL@%
- ANSI_SGR(ANSI_INVISIBLE);%@NL@%
- return;%@NL@%
- case IBM_BLINK:%@NL@%
- ANSI_SGR(ANSI_BLINK);%@NL@%
- return;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* must be separate attribute specifications */%@AE@%%@NL@%
- pos = FGND;%@NL@%
- intensity = 0;%@NL@%
- for (i = 1; i < nargs; ++i) {%@NL@%
- attribute = colornum(argvec[i]);%@NL@%
- if (attribute == -1) {%@NL@%
- ANSI_ED;%@NL@%
- fprintf(stderr, "\nIllegal parameter\n");%@NL@%
- exit (2);%@NL@%
- }%@NL@%
- if (attribute == IBM_BRIGHT) {%@NL@%
- intensity = IBM_BRIGHT;%@NL@%
- continue;%@NL@%
- }%@NL@%
- setattr(pos, attribute | intensity);%@NL@%
- if (pos == FGND)%@NL@%
- pos = BKGND;%@NL@%
- else if (pos == BKGND)%@NL@%
- pos = BDR;%@NL@%
- intensity = 0;%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr -- file printer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%"print.h" %@NL@%
- %@NL@%
- char Pagelist[MAXLINE];%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- BOOLEAN errflag;%@NL@%
- extern PRINT pcnf;%@NL@%
- static char pgm[MAXNAME + 1] = { "pr" };%@NL@%
- %@NL@%
- extern char *getpname(char *, char *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern char *optarg;%@NL@%
- extern int optind, opterr;%@NL@%
- extern int pr_gcnf(char *);%@NL@%
- extern pr_file(char *, int, char **);%@NL@%
- extern void pr_help(char *);%@NL@%
- extern void fixtabs(int);%@NL@%
- extern int setprnt();%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* do configuration */%@AE@%%@NL@%
- if (pr_gcnf(pgm) != 0) {%@NL@%
- fprintf(stderr, "%s: Configuration error", pgm);%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- if (setprnt() == -1) {%@NL@%
- fprintf(stderr, "%s: Bad printer configuration\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- fixtabs(pcnf.p_tabint);%@NL@%
- %@NL@%
- %@AB@%/* process command-line arguments */%@AE@%%@NL@%
- while ((ch = getopt(argc, argv, "efgh:l:no:ps:w:")) != EOF) {%@NL@%
- switch (ch) {%@NL@%
- case 'e':%@NL@%
- %@AB@%/* force "Epson-compatible " printer mode */%@AE@%%@NL@%
- pcnf.p_mode = 1;%@NL@%
- break;%@NL@%
- case 'f':%@NL@%
- %@AB@%/* use formfeed to eject a page */%@AE@%%@NL@%
- pcnf.p_ff = 1;%@NL@%
- break;%@NL@%
- case 'g':%@NL@%
- %@AB@%/* force "generic" printer mode */%@AE@%%@NL@%
- pcnf.p_mode = 0;%@NL@%
- break;%@NL@%
- case 'h':%@NL@%
- %@AB@%/* use specified header */%@AE@%%@NL@%
- strcpy(pcnf.p_hdr, optarg);%@NL@%
- break;%@NL@%
- case 'l':%@NL@%
- %@AB@%/* set lines per page */%@AE@%%@NL@%
- pcnf.p_len = atoi(optarg);%@NL@%
- break;%@NL@%
- case 'n':%@NL@%
- %@AB@%/* enable line numbering */%@AE@%%@NL@%
- pcnf.p_lnum = 1;%@NL@%
- break;%@NL@%
- case 'o':%@NL@%
- %@AB@%/* set left margin */%@AE@%%@NL@%
- pcnf.p_lmarg = atoi(optarg);%@NL@%
- break;%@NL@%
- case 'p':%@NL@%
- %@AB@%/* preview output on screen */%@AE@%%@NL@%
- strcpy(pcnf.p_dest, "");%@NL@%
- break;%@NL@%
- case 's':%@NL@%
- %@AB@%/* output selected pages */%@AE@%%@NL@%
- strcpy(Pagelist, optarg);%@NL@%
- break;%@NL@%
- case 'w':%@NL@%
- %@AB@%/* set page width in columns */%@AE@%%@NL@%
- pcnf.p_wid = atoi(optarg);%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* unknown option */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- if (errflag == TRUE) {%@NL@%
- pr_help(pgm);%@NL@%
- exit(3);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* print the files */%@AE@%%@NL@%
- pr_file(pgm, argc - optind, argv += optind);%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PRINTER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\PRINTER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * printer -- interface functions for printer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\printer.h> %@NL@%
- %@NL@%
- PRINTER prt; %@AB@%/* printer data */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setprnt -- install printer codes from configuration%@NL@%
- %@AB@% * file for printer (defaults to Epson MX/FX series)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NSELEM 13 %@NL@%
- %@NL@%
- int%@NL@%
- setprnt()%@NL@%
- {%@NL@%
- int n;%@NL@%
- char *s, line[MAXLINE];%@NL@%
- FILE *fp, *fconfig(char *, char *);%@NL@%
- %@NL@%
- %@AB@%/* use local or global config file, if any */%@AE@%%@NL@%
- if ((fp = fconfig("CONFIG", "printer.cnf")) != NULL) {%@NL@%
- n = 0;%@NL@%
- while (fgets(line, MAXLINE, fp) != NULL) {%@NL@%
- if ((s = strtok(line, " \t\n")) == NULL)%@NL@%
- return (-1);%@NL@%
- switch (n) {%@NL@%
- case 0:%@NL@%
- strcpy(prt.p_init, s);%@NL@%
- break;%@NL@%
- case 1:%@NL@%
- strcpy(prt.p_bold, s);%@NL@%
- break;%@NL@%
- case 2:%@NL@%
- strcpy(prt.p_ds, s);%@NL@%
- break;%@NL@%
- case 3:%@NL@%
- strcpy(prt.p_ital, s);%@NL@%
- break;%@NL@%
- case 4:%@NL@%
- strcpy(prt.p_cmp, s);%@NL@%
- break;%@NL@%
- case 5:%@NL@%
- strcpy(prt.p_exp, s);%@NL@%
- break;%@NL@%
- case 6:%@NL@%
- strcpy(prt.p_ul, s);%@NL@%
- break;%@NL@%
- case 7:%@NL@%
- strcpy(prt.p_xbold, s); %@NL@%
- break;%@NL@%
- case 8:%@NL@%
- strcpy(prt.p_xds, s);%@NL@%
- break;%@NL@%
- case 9:%@NL@%
- strcpy(prt.p_xital, s);%@NL@%
- break;%@NL@%
- case 10:%@NL@%
- strcpy(prt.p_xcmp, s);%@NL@%
- break;%@NL@%
- case 11:%@NL@%
- strcpy(prt.p_xexp, s);%@NL@%
- break;%@NL@%
- case 12:%@NL@%
- strcpy(prt.p_xul, s);%@NL@%
- break;%@NL@%
- default:%@NL@%
- %@AB@%/* too many lines */%@AE@%%@NL@%
- return (-1);%@NL@%
- }%@NL@%
- ++n;%@NL@%
- }%@NL@%
- if (n != NSELEM)%@NL@%
- %@AB@%/* probably not enough lines */%@AE@%%@NL@%
- return (-1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* or use Epson defaults */%@AE@%%@NL@%
- strcpy(prt.p_init, "\033@"); %@AB@%/* hardware reset */%@AE@%%@NL@%
- strcpy(prt.p_bold, "\033E"); %@AB@%/* emphasized mode */%@AE@%%@NL@%
- strcpy(prt.p_ds, "\033G"); %@AB@%/* double-strike mode */%@AE@%%@NL@%
- strcpy(prt.p_ital, "\0334"); %@AB@%/* italic mode */%@AE@%%@NL@%
- strcpy(prt.p_cmp, "\017"); %@AB@%/* condensed mode */%@AE@%%@NL@%
- strcpy(prt.p_exp, "\016"); %@AB@%/* expanded mode */%@AE@%%@NL@%
- strcpy(prt.p_ul, "\033-1"); %@AB@%/* underline mode */%@AE@%%@NL@%
- strcpy(prt.p_xbold, "\033F"); %@AB@%/* cancel emphasized mode */%@AE@%%@NL@%
- strcpy(prt.p_xds, "\033H"); %@AB@%/* cancel double-strike mode */%@AE@%%@NL@%
- strcpy(prt.p_xital, "\0335"); %@AB@%/* cancel italic mode */%@AE@%%@NL@%
- strcpy(prt.p_xcmp, "\022"); %@AB@%/* cancel condensed mode */%@AE@%%@NL@%
- strcpy(prt.p_xexp, "\024"); %@AB@%/* cancel expanded mode */%@AE@%%@NL@%
- strcpy(prt.p_xul, "\033-0"); %@AB@%/* cancel underline mode */%@AE@%%@NL@%
- %@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * clrprnt -- clear printer options to default values%@NL@%
- %@AB@% * (clears individual options to avoid the "paper creep"%@NL@%
- %@AB@% * that occurs with repeated printer resets and to avoid%@NL@%
- %@AB@% * changing the printer's notion of top-of-form position)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- clrprnt(fout)%@NL@%
- FILE *fout;%@NL@%
- {%@NL@%
- fputs(prt.p_xbold, fout); %@AB@%/* cancel emphasized mode */%@AE@%%@NL@%
- fputs(prt.p_xds, fout); %@AB@%/* cancel double-strike mode */%@AE@%%@NL@%
- fputs(prt.p_xital, fout); %@AB@%/* cancel italic mode */%@AE@%%@NL@%
- fputs(prt.p_xcmp, fout); %@AB@%/* cancel condensed mode */%@AE@%%@NL@%
- fputs(prt.p_xexp, fout); %@AB@%/* cancel expanded mode */%@AE@%%@NL@%
- fputs(prt.p_xul, fout); %@AB@%/* cancel underline mode */%@AE@%%@NL@%
- } %@AB@%/* end clrprnt() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setfont -- set the printing font to the type specified%@NL@%
- %@AB@% * by the argument (may be a compound font specification)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- setfont(ftype, fout)%@NL@%
- int ftype; %@AB@%/* font type specifier */%@AE@%%@NL@%
- FILE *fout; %@AB@%/* output stream */%@AE@%%@NL@%
- {%@NL@%
- clrprnt(fout);%@NL@%
- if ((ftype & CONDENSED) == CONDENSED)%@NL@%
- if ((ftype & DOUBLE) == DOUBLE ||%@NL@%
- (ftype & EMPHASIZED) == EMPHASIZED)%@NL@%
- return FAILURE;%@NL@%
- else if (*prt.p_cmp)%@NL@%
- fputs(prt.p_cmp, fout);%@NL@%
- if (*prt.p_ds && (ftype & DOUBLE) == DOUBLE)%@NL@%
- fputs(prt.p_ds, fout);%@NL@%
- if (*prt.p_bold && (ftype & EMPHASIZED) == EMPHASIZED)%@NL@%
- fputs(prt.p_bold, fout);%@NL@%
- if (*prt.p_exp && (ftype & EXPANDED) == EXPANDED)%@NL@%
- fputs(prt.p_exp, fout);%@NL@%
- if (*prt.p_ital && (ftype & ITALICS) == ITALICS)%@NL@%
- fputs(prt.p_ital, fout);%@NL@%
- if (*prt.p_ul && (ftype & UNDERLINE) == UNDERLINE)%@NL@%
- fputs(prt.p_ul, fout);%@NL@%
- %@NL@%
- return SUCCESS;%@NL@%
- } %@AB@%/* end setfont() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PRTSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\07CONFIG\PRTSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * prtstr -- send text string(s) to standard printer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- BOOLEAN errflag, lineflag;%@NL@%
- static char pgm[MAXNAME + 1] = { "prtstr" };%@NL@%
- FILE *fout;%@NL@%
- %@NL@%
- extern char *getpname(char *, char *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind, opterr;%@NL@%
- extern char *optarg;%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* process options, if any */%@AE@%%@NL@%
- errflag = FALSE;%@NL@%
- lineflag = TRUE;%@NL@%
- fout = stdprn;%@NL@%
- while ((ch = getopt(argc, argv, "np")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 'n':%@NL@%
- %@AB@%/* don't emit the trailing newline */%@AE@%%@NL@%
- lineflag = FALSE;%@NL@%
- break;%@NL@%
- case 'p':%@NL@%
- %@AB@%/* preview on stdout */%@AE@%%@NL@%
- fout = stdout;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* bad option */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- if (errflag == TRUE) {%@NL@%
- fprintf(stderr, "Usage: %s [-np] [string...]\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* print the string(s) */%@AE@%%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- while (argc-- > 1 ) {%@NL@%
- fputs(*argv++, fout);%@NL@%
- fputc(' ', fout);%@NL@%
- }%@NL@%
- fputs(*argv++, fout);%@NL@%
- if (lineflag == TRUE)%@NL@%
- fputc(' ', fout);%@NL@%
- if (lineflag == TRUE)%@NL@%
- fputc('\n', fout);%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR_CPY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR_CPY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr_cpy -- copy input stream to output stream%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\printer.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%"print.h" %@NL@%
- %@NL@%
- extern PRINT pcnf;%@NL@%
- extern char Pagelist[MAXLINE];%@NL@%
- extern long Highest;%@NL@%
- %@NL@%
- int%@NL@%
- pr_cpy(fin, fout, fname)%@NL@%
- FILE *fin;%@NL@%
- FILE *fout;%@NL@%
- char *fname;%@NL@%
- {%@NL@%
- int errcount = 0;%@NL@%
- unsigned int p_line; %@AB@%/* page-relative line number */%@AE@%%@NL@%
- long f_line; %@AB@%/* file-relative line number */%@AE@%%@NL@%
- long f_page; %@AB@%/* file-relative page number */%@AE@%%@NL@%
- int lnlen; %@AB@%/* line length */%@AE@%%@NL@%
- char line[MAXLINE]; %@AB@%/* input line buffer */%@AE@%%@NL@%
- struct stat tbuf; %@AB@%/* file information */%@AE@%%@NL@%
- long ltime; %@AB@%/* date and time */%@AE@%%@NL@%
- FILE *fnull, *fx; %@AB@%/* additional output file pointers */%@AE@%%@NL@%
- %@NL@%
- extern void mkslist(char *); %@AB@%/* make a selection list */%@AE@%%@NL@%
- extern int selected(long); %@AB@%/* is item in the list? */%@AE@%%@NL@%
- extern int spaces(int, FILE *); %@AB@%/* emit string of spaces */%@AE@%%@NL@%
- extern int setfont(int, FILE *);%@AB@%/* set printer font type */%@AE@%%@NL@%
- extern int clrprnt(FILE *); %@AB@%/* clear special fonts */%@AE@%%@NL@%
- extern int lines(int, FILE *); %@AB@%/* emit string of blank lines */%@AE@%%@NL@%
- static int fit(int, int); %@AB@%/* will line fit on page? */%@AE@%%@NL@%
- extern int pr_line(char *, FILE *, unsigned int);%@NL@%
- %@NL@%
- %@AB@%/* install page selection list, if any */%@AE@%%@NL@%
- if (Pagelist[0] != '\0') {%@NL@%
- %@AB@%/* open the NUL device for dumping output */%@AE@%%@NL@%
- if ((fnull = fopen("NUL", "w")) == NULL) {%@NL@%
- perror("Error opening NUL device");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- mkslist(Pagelist);%@NL@%
- }%@NL@%
- else%@NL@%
- Highest = BIGGEST;%@NL@%
- %@NL@%
- %@AB@%/* get date and time stamp */%@AE@%%@NL@%
- if (*fname == '\0')%@NL@%
- %@AB@%/* using stdin -- use today's date and time */%@AE@%%@NL@%
- ltime = time(NULL);%@NL@%
- else {%@NL@%
- if (stat(fname, &tbuf) == -1)%@NL@%
- return (-1);%@NL@%
- %@AB@%/* use file's modification time */%@AE@%%@NL@%
- ltime = tbuf.st_mtime;%@NL@%
- }%@NL@%
- p_line = 0;%@NL@%
- f_line = 1;%@NL@%
- f_page = 1;%@NL@%
- while ((lnlen = pr_getln(line, MAXLINE, fin)) > 0 ) {%@NL@%
- %@AB@%/* if formfeed or no room for line, eject page */%@AE@%%@NL@%
- if (line[0] == '\f' || !fit(lnlen, p_line)) {%@NL@%
- %@AB@%/* to top of next page */%@AE@%%@NL@%
- if (pcnf.p_ff == 0)%@NL@%
- lines(pcnf.p_len - p_line, fx);%@NL@%
- else%@NL@%
- fputc('\f', fx);%@NL@%
- p_line = 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if at top of page, print the header */%@AE@%%@NL@%
- if (p_line == 0) {%@NL@%
- if (f_page > Highest)%@NL@%
- break;%@NL@%
- fx = selected(f_page) ? fout : fnull;%@NL@%
- p_line += lines(pcnf.p_top1, fx);%@NL@%
- if (pcnf.p_mode != 0)%@NL@%
- setfont(EMPHASIZED, fx);%@NL@%
- spaces(pcnf.p_lmarg, fx);%@NL@%
- if (*pcnf.p_hdr != '\0') %@NL@%
- fprintf(fx, "%s ", pcnf.p_hdr);%@NL@%
- else if (*fname != '\0')%@NL@%
- fprintf(fx, "%s ", strupr(fname));%@NL@%
- fprintf(fx, "Page %u ", f_page++);%@NL@%
- fputs(ctime(<ime), fx);%@NL@%
- ++p_line;%@NL@%
- if (pcnf.p_mode != 0)%@NL@%
- setfont(pcnf.p_font, fx);%@NL@%
- p_line += lines(pcnf.p_top2, fx);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* OK to output the line */%@AE@%%@NL@%
- if (line[0] != '\f')%@NL@%
- p_line += pr_line(line, fx, f_line++);%@NL@%
- }%@NL@%
- if (ferror(fin) != 0)%@NL@%
- ++errcount;%@NL@%
- if (p_line > 0 && p_line < pcnf.p_len)%@NL@%
- if (pcnf.p_ff == 0)%@NL@%
- lines(pcnf.p_len - p_line, fx);%@NL@%
- else%@NL@%
- fputc('\f', fx);%@NL@%
- %@NL@%
- if (pcnf.p_mode != 0)%@NL@%
- clrprnt(fx);%@NL@%
- return (errcount);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * fit -- return non-zero value if enough physical%@NL@%
- %@AB@% * lines are available on the current page to take%@NL@%
- %@AB@% * the current logical line of text%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- NFLDWIDTH 8 %@AB@%/* width of number field */%@AE@%%@NL@%
- %@NL@%
- static int%@NL@%
- fit(len, ln)%@NL@%
- int len, ln;%@NL@%
- {%@NL@%
- int need, left; %@AB@%/* physical lines */%@AE@%%@NL@%
- int cols; %@AB@%/* columns of actual output */%@AE@%%@NL@%
- int lw; %@AB@%/* displayable line width */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* total need (columns -> physical lines) */%@AE@%%@NL@%
- cols = len + (pcnf.p_lnum > 0 ? NFLDWIDTH : 0);%@NL@%
- lw = pcnf.p_wid - pcnf.p_lmarg - pcnf.p_rmarg;%@NL@%
- need = 1 + cols / lw;%@NL@%
- %@NL@%
- %@AB@%/* lines remaining on page */%@AE@%%@NL@%
- left = pcnf.p_len - ln - pcnf.p_btm;%@NL@%
- %@NL@%
- return (need <= left ? 1 : 0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR_FILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR_FILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr_file -- process each filename or standard input%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%"print.h" %@NL@%
- %@NL@%
- int%@NL@%
- pr_file(pname, ac, av)%@NL@%
- char *pname;%@NL@%
- int ac;%@NL@%
- char **av;%@NL@%
- {%@NL@%
- int ch, errcount = 0;%@NL@%
- FILE *fin, *fout;%@NL@%
- extern PRINT pcnf;%@NL@%
- %@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- extern int pr_cpy(FILE *, FILE *, char *);%@NL@%
- %@NL@%
- %@AB@%/* open output stream only if not already open */%@AE@%%@NL@%
- if (*pcnf.p_dest == '\0' || strcmp(pcnf.p_dest, "CON") == 0)%@NL@%
- fout = stdout;%@NL@%
- else if (strcmp(pcnf.p_dest, "PRN") == 0)%@NL@%
- fout = stdprn;%@NL@%
- else if (strcmp(pcnf.p_dest, "AUX") == 0)%@NL@%
- fout = stdaux;%@NL@%
- else%@NL@%
- if ((fout = fopen(pcnf.p_dest, "w")) == NULL)%@NL@%
- fatal(pname, "Error open destination stream", 1);%@NL@%
- %@NL@%
- %@AB@%/* prepare input stream */%@AE@%%@NL@%
- if (ac == 0)%@NL@%
- pr_cpy(stdin, fout, "");%@NL@%
- else {%@NL@%
- for (; ac > 0; --ac, ++av) {%@NL@%
- if ((fin = fopen(*av, "r")) == NULL) {%@NL@%
- fprintf(stderr, "%s: Error opening %s",%@NL@%
- pname, *av);%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (pr_cpy(fin, fout, *av) == -1) {%@NL@%
- fprintf(stderr, "%s: Cannot stat %s",%@NL@%
- pname, *av);%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (fclose(fin) == EOF)%@NL@%
- fatal(pname, "Error closing input file", 2);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- return (errcount);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR_GCNF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR_GCNF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr_gcnf -- get configuration for pr program%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\printer.h> %@NL@%
- %@AI@%#include %@AE@%"print.h" %@NL@%
- %@NL@%
- %@AB@%/* expected number of configuration items */%@AE@%%@NL@%
- %@AI@%#define %@AE@%N_NBR 12 %@NL@%
- %@NL@%
- PRINT pcnf;%@NL@%
- %@NL@%
- int%@NL@%
- pr_gcnf(pname)%@NL@%
- char *pname;%@NL@%
- {%@NL@%
- char line[MAXLINE];%@NL@%
- char *s;%@NL@%
- int cnf[N_NBR];%@NL@%
- int n, errcount, good;%@NL@%
- FILE *fp, *fconfig(char *, char *);%@NL@%
- %@NL@%
- %@AB@%/* get configuration file values, if any */%@AE@%%@NL@%
- n = good = errcount = 0;%@NL@%
- if ((fp = fconfig("CONFIG", "pr.cnf")) != NULL) {%@NL@%
- while (n < N_NBR && (s = fgets(line, MAXLINE, fp)) != NULL) {%@NL@%
- cnf[n] = atoi(s);%@NL@%
- ++n;%@NL@%
- }%@NL@%
- if ((s = fgets(line, MAXLINE, fp)) == NULL)%@NL@%
- ++errcount;%@NL@%
- else%@NL@%
- strcpy(pcnf.p_dest, strtok(line, " \t\n"));%@NL@%
- if (n != N_NBR)%@NL@%
- ++errcount;%@NL@%
- if (errcount == 0)%@NL@%
- good = 1;%@NL@%
- if (fclose(fp) == -1)%@NL@%
- fatal(pname, "cannot close config file");%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* use config data is good; use defaults otherwise */%@AE@%%@NL@%
- pcnf.p_top1 = good ? cnf[0]: TOP1;%@NL@%
- pcnf.p_top2 = good ? cnf[1] : TOP2;%@NL@%
- pcnf.p_btm = good ? cnf[2] : BOTTOM;%@NL@%
- pcnf.p_wid = good ? cnf[3] : MAXPCOL;%@NL@%
- pcnf.p_lmarg = good ? cnf[4] : MARGIN;%@NL@%
- pcnf.p_rmarg = good ? cnf[5] : MARGIN;%@NL@%
- pcnf.p_len = good ? cnf[6] : PAGELEN;%@NL@%
- pcnf.p_lpi = good ? cnf[7] : LPI;%@NL@%
- pcnf.p_mode = good ? cnf[8] : 0;%@NL@%
- pcnf.p_lnum = good ? cnf[9] : 0;%@NL@%
- pcnf.p_ff = good ? cnf[10] : 0;%@NL@%
- pcnf.p_tabint = good ? cnf[11] : TABSPEC;%@NL@%
- if (!good)%@NL@%
- strcpy(pcnf.p_dest, "PRN");%@NL@%
- if (pcnf.p_mode == 1)%@NL@%
- pcnf.p_font = CONDENSED;%@NL@%
- strcpy(pcnf.p_hdr, "");%@NL@%
- %@NL@%
- return (errcount);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR_GETLN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR_GETLN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr_getln -- get a line of text while expanding tabs;%@NL@%
- %@AB@% * put text into an array and return the length of the line%@NL@%
- %@AB@% * including termination to the calling function.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- int%@NL@%
- pr_getln(s, lim, fin)%@NL@%
- char *s;%@NL@%
- int lim;%@NL@%
- FILE *fin;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- extern int tabstop(); %@AB@%/* query tabstop array */%@AE@%%@NL@%
- %@NL@%
- cp = s;%@NL@%
- while (--lim > 0 && (ch = fgetc(fin)) != EOF && ch != '\n' && ch != '\f') {%@NL@%
- if (ch == '\t')%@NL@%
- %@AB@%/* loop and store spaces until next tabstop */%@AE@%%@NL@%
- do%@NL@%
- *cp++ = ' ';%@NL@%
- while (--lim > 0 && tabstop(cp - s) == 0);%@NL@%
- else%@NL@%
- *cp++ = ch;%@NL@%
- }%@NL@%
- if (ch == EOF && cp - s == 0)%@NL@%
- ;%@NL@%
- else if (ch == EOF || ch == '\n')%@NL@%
- *cp++ = '\n'; %@AB@%/* assure correct line termination */%@AE@%%@NL@%
- else if (ch == '\f' && cp - s == 0) {%@NL@%
- *cp++ = '\f';%@NL@%
- fgetc(fin); %@AB@%/* toss the trailing newline */%@AE@%%@NL@%
- }%@NL@%
- *cp = '\0';%@NL@%
- %@NL@%
- return (cp - s);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR_HELP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR_HELP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr_help -- display an abbreviated manual page%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- void%@NL@%
- pr_help(pname)%@NL@%
- char *pname;%@NL@%
- {%@NL@%
- static char *m_str[] = {%@NL@%
- "The following options may be used singly or in combination:",%@NL@%
- "-e\t set Epson-compatible mode",%@NL@%
- "-f\t use formfeed to eject a page (default is newlines)",%@NL@%
- "-g\t use generic printer mode",%@NL@%
- "-h hdr\t use specified header instead of file name",%@NL@%
- "-l len\t set page length in lines (default = 66)",%@NL@%
- "-n\t enable line numbering (default = off)",%@NL@%
- "-o cols\t offset from left edge in columns (default = 5)",%@NL@%
- "-p\t preview output on screen (may be redirected)",%@NL@%
- "-s list\t print only selected pages",%@NL@%
- "-w cols\t line width in columns (default = 80)"%@NL@%
- };%@NL@%
- int i, n = sizeof (m_str)/ sizeof (char *);%@NL@%
- %@NL@%
- fprintf(stderr, "Usage: %s [options] file...\n\n", pname);%@NL@%
- for (i = 0; i < n; ++i)%@NL@%
- fprintf(stderr, "%s\n", m_str[i]);%@NL@%
- %@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PR_LINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\09PRINT\PR_LINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pr_line -- ouput a buffered logical line and%@NL@%
- %@AB@% * return a count of physical lines produced%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%"print.h" %@NL@%
- %@NL@%
- int%@NL@%
- pr_line(s, fout, rline)%@NL@%
- char *s; %@AB@%/* buffered line of text */%@AE@%%@NL@%
- FILE *fout; %@AB@%/* output stream */%@AE@%%@NL@%
- unsigned int rline; %@AB@%/* file-relative line number */%@AE@%%@NL@%
- {%@NL@%
- int c_cnt; %@AB@%/* character position in output line */%@AE@%%@NL@%
- int nlines; %@AB@%/* number of lines output */%@AE@%%@NL@%
- extern PRINT pcnf;%@NL@%
- %@NL@%
- extern int spaces(int, FILE *); %@AB@%/* emit string of spaces */%@AE@%%@NL@%
- %@NL@%
- nlines = 1;%@NL@%
- c_cnt = 0;%@NL@%
- %@NL@%
- %@AB@%/* output the left indentation, if any */%@AE@%%@NL@%
- c_cnt += spaces(pcnf.p_lmarg, fout);%@NL@%
- %@NL@%
- %@AB@%/* output the line number if numbering enabled */%@AE@%%@NL@%
- if (pcnf.p_lnum != 0)%@NL@%
- c_cnt += fprintf(fout, "%6u ", rline);%@NL@%
- %@NL@%
- %@AB@%/* output the text of the line */%@AE@%%@NL@%
- while (*s != '\0') {%@NL@%
- if (c_cnt > (pcnf.p_wid - pcnf.p_rmarg)) {%@NL@%
- fputc('\n', fout);%@NL@%
- ++nlines;%@NL@%
- c_cnt = 0;%@NL@%
- c_cnt = spaces(pcnf.p_lmarg, fout);%@NL@%
- }%@NL@%
- fputc(*s, fout);%@NL@%
- ++s;%@NL@%
- ++c_cnt;%@NL@%
- }%@NL@%
- %@NL@%
- return (nlines);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PUTCUR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\PUTCUR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * putcur -- put cursor at specified position (row, col) %@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- putcur(r, c, pg)%@NL@%
- unsigned int%@NL@%
- r, %@AB@%/* row */%@AE@%%@NL@%
- c, %@AB@%/* column */%@AE@%%@NL@%
- pg; %@AB@%/* screen page for writes */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = CUR_POS;%@NL@%
- inregs.h.bh = pg & 0x07;%@NL@%
- inregs.h.dh = r & 0xFF;%@NL@%
- inregs.h.dl = c & 0xFF;%@NL@%
- %@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- } %@AB@%/* end putcur() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PUTFLD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\PUTFLD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * putfld -- display a string in the prevailing%@NL@%
- %@AB@% * video attribute while compressing runs of a%@NL@%
- %@AB@% * single character, and pad the field to full width%@NL@%
- %@AB@% * with spaces if necessary%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- putfld(s, w, pg)%@NL@%
- register char *s; %@AB@%/* string to write */%@AE@%%@NL@%
- int w; %@AB@%/* field width */%@AE@%%@NL@%
- int pg; %@AB@%/* screen page for writes */%@AE@%%@NL@%
- {%@NL@%
- int r, c, cols;%@NL@%
- register int n;%@NL@%
- %@NL@%
- extern int putcur(int, int, int);%@NL@%
- extern int readcur(int *, int *, int);%@NL@%
- extern int writec(unsigned char, int, int);%@NL@%
- %@NL@%
- %@AB@%/* get starting (current) position */%@AE@%%@NL@%
- readcur(&r, &c, pg);%@NL@%
- %@NL@%
- %@AB@%/* write the string */%@AE@%%@NL@%
- for (n = 0; *s != '\0' && n < w; s += cols, n += cols) {%@NL@%
- putcur(r, c + n, pg);%@NL@%
- %@AB@%/* compress runs to a single call on writec() */%@AE@%%@NL@%
- cols = 1;%@NL@%
- while (*(s + cols) == *s && n + cols < w)%@NL@%
- ++cols;%@NL@%
- writec(*s, cols, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* pad the field, if necessary */%@AE@%%@NL@%
- if (n < w) {%@NL@%
- putcur(r, c + n, pg);%@NL@%
- writec(' ', w - n, pg);%@NL@%
- }%@NL@%
- %@NL@%
- return (w - n);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PUTSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\PUTSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * putstr -- display a character string in the%@NL@%
- %@AB@% * prevailing video attribute and return number%@NL@%
- %@AB@% * characters displayed%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- putstr(s, pg)%@NL@%
- register char *s;%@NL@%
- unsigned int pg;%@NL@%
- {%@NL@%
- unsigned int r, c, c0;%@NL@%
- %@NL@%
- readcur(&r, &c, pg);%@NL@%
- for (c0 = c; *s != '\0'; ++s, ++c) {%@NL@%
- putcur(r, c, pg);%@NL@%
- writec(*s, 1, pg);%@NL@%
- }%@NL@%
- putcur(r, c, pg);%@NL@%
- return (c - c0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PUT_CH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\PUT_CH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * put_ch -- display a character in the prevailing video%@NL@%
- %@AB@% * attribute and advance the cursor position%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- int%@NL@%
- put_ch(ch, pg)%@NL@%
- register char ch;%@NL@%
- int pg;%@NL@%
- {%@NL@%
- int r, c, c0;%@NL@%
- %@NL@%
- readcur(&r, &c, pg);%@NL@%
- writec(ch, 1, pg);%@NL@%
- putcur(r, ++c, pg);%@NL@%
- return (1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PWD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\PWD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * pwd -- print (display actually) the current directory pathname%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *path;%@NL@%
- %@NL@%
- if ((path = getcwd(NULL, MAXPATH)) == NULL) {%@NL@%
- perror("Error getting current directory");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- printf("%s\n", path);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- _setargv()%@NL@%
- {%@NL@%
- }%@NL@%
- %@NL@%
- _setenvp()%@NL@%
- {%@NL@%
- }%@NL@%
- %@NL@%
- _nullcheck()%@NL@%
- {%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%READCA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\READCA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * readca -- read character and attribute at current position%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int readca(ch, attr, pg)%@NL@%
- unsigned char *ch;%@NL@%
- unsigned char *attr;%@NL@%
- unsigned int pg; %@AB@%/* screen page for reads */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = READ_CHAR_ATTR;%@NL@%
- inregs.h.bh = pg; %@AB@%/* display page */%@AE@%%@NL@%
- %@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- *ch = outregs.h.al; %@AB@%/* character */%@AE@%%@NL@%
- *attr = outregs.h.ah; %@AB@%/* attribute */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* return the value in AX register */%@AE@%%@NL@%
- return (outregs.x.cflag);%@NL@%
- } %@AB@%/* end readca() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%READCUR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\READCUR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * readcur -- pass back the cursor position (row, col) %@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- unsigned int readcur(row, col, pg)%@NL@%
- unsigned int *row; %@AB@%/* current row */%@AE@%%@NL@%
- unsigned int *col; %@AB@%/* current column */%@AE@%%@NL@%
- unsigned int pg; %@AB@%/* screen page */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = GET_CUR;%@NL@%
- inregs.h.bh = pg;%@NL@%
- %@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- *col = outregs.h.dl; %@AB@%/* col */%@AE@%%@NL@%
- *row = outregs.h.dh; %@AB@%/* row */%@AE@%%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- } %@AB@%/* end readcur() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%READDOT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\READDOT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * readdot -- read the value of a pixel%@NL@%
- %@AB@% * (in graphics mode only)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- readdot(row, col, dcolor)%@NL@%
- int row, col;%@NL@%
- int *dcolor; %@AB@%/* pointer to dot color */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = READ_DOT;%@NL@%
- inregs.x.cx = col;%@NL@%
- inregs.x.dx = row;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- *dcolor = outregs.h.al;%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%REPLAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\03DOS\REPLAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * replay -- echo the command-line arguments%@NL@%
- %@AB@% * to standard output%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int i;%@NL@%
- char **p;%@NL@%
- static char pgm[MAXNAME + 1] = { "replay" };%@NL@%
- %@NL@%
- void getpname(char *, char *);%@NL@%
- %@NL@%
- %@AB@%/* get program name from DOS (version 3.00 and later) */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* check for arguments */%@AE@%%@NL@%
- if (argc == 1)%@NL@%
- exit(1); %@AB@%/* none given */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* echo the argument list, one per line */%@AE@%%@NL@%
- p = argv;%@NL@%
- printf("%s arguments:\n\n", pgm);%@NL@%
- for (--argc, ++argv; argc > 0; --argc, ++argv)%@NL@%
- printf("argv[%d] -> %s\n", argv - p, *argv);%@NL@%
- exit(0);%@NL@%
- } %@AB@%/* end main() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\RM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * rm -- remove file(s)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int ch;%@NL@%
- BOOLEAN errflag,%@NL@%
- iflag;%@NL@%
- %@NL@%
- static char pgm[MAXNAME + 1] = { "rm" };%@NL@%
- extern void getpname(char *, char *);%@NL@%
- static void do_rm(char *, char *, BOOLEAN);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind, opterr;%@NL@%
- extern char *optarg;%@NL@%
- %@NL@%
- %@AB@%/* get program name from DOS (version 3.00 and later) */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* process optional arguments first */%@AE@%%@NL@%
- errflag = iflag = FALSE;%@NL@%
- while ((ch = getopt(argc, argv, "i")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 'i':%@NL@%
- %@AB@%/* interactive -- requires confirmation */%@AE@%%@NL@%
- iflag = TRUE;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* say what? */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- %@NL@%
- if (argc <= 0 || errflag == TRUE) {%@NL@%
- fprintf(stderr, "%s [-i] file(s)\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* process remaining arguments */%@AE@%%@NL@%
- for (; argc-- > 0; ++argv)%@NL@%
- do_rm(pgm, *argv, iflag);%@NL@%
- %@NL@%
- exit(0);%@NL@%
- } %@AB@%/* end main() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * do_rm -- remove a file%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- do_rm(pname, fname, iflag)%@NL@%
- char *pname, *fname;%@NL@%
- BOOLEAN iflag;%@NL@%
- {%@NL@%
- int result = 0;%@NL@%
- struct stat statbuf;%@NL@%
- static BOOLEAN affirm();%@NL@%
- %@NL@%
- if (iflag == TRUE) {%@NL@%
- fprintf(stderr, "%s (y/n): ", fname);%@NL@%
- if (affirm() == FALSE)%@NL@%
- return;%@NL@%
- }%@NL@%
- if ((result = unlink(fname)) == -1) {%@NL@%
- fprintf(stderr, "%s: ", pname);%@NL@%
- perror(fname);%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * affirm -- return TRUE if the first character of the%@NL@%
- %@AB@% * user's response is 'y' or FALSE otherwise%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXSTR 64 %@NL@%
- %@NL@%
- static BOOLEAN%@NL@%
- affirm()%@NL@%
- {%@NL@%
- char line[MAXSTR + 1];%@NL@%
- char *response;%@NL@%
- %@NL@%
- response = fgets(line, MAXSTR, stdin); %@NL@%
- return (tolower(*response) == 'y' ? TRUE : FALSE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RUN_ONCE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\04STDLIB\RUN_ONCE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * run_once -- run a program one time and then%@NL@%
- %@AB@% * "hang" the system to prevent unwanted use%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<process.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- %@NL@%
- %@AB@%/* skip over the program name */%@AE@%%@NL@%
- ++argv;%@NL@%
- %@NL@%
- %@AB@%/* run the specified command line [pgmname arg(s)] */%@AE@%%@NL@%
- if (spawnvp(P_WAIT, *argv, argv) == -1)%@NL@%
- fatal("run_once", "Error running specified program", 1);%@NL@%
- fprintf(stderr, "Please turn off the power to the computer.\n");%@NL@%
- %@NL@%
- %@AB@%/* do nothing */%@AE@%%@NL@%
- FOREVER%@NL@%
- ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_BOX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_BOX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_box -- draw a box around the perimeter of a window%@NL@%
- %@AB@% * using the appropriate IBM graphics characters%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%<local\box.h> %@NL@%
- %@NL@%
- int%@NL@%
- sb_box(win, type, attr)%@NL@%
- struct REGION *win;%@NL@%
- short type;%@NL@%
- unsigned char attr;%@NL@%
- {%@NL@%
- register short r; %@AB@%/* row index */%@AE@%%@NL@%
- short x; %@AB@%/* interior horizontal line length */%@AE@%%@NL@%
- short maxr, maxc; %@AB@%/* maximum row and col values */%@AE@%%@NL@%
- BOXTYPE *boxp; %@AB@%/* pointer to box drawing character struct */%@AE@%%@NL@%
- static BOXTYPE box[] = {%@NL@%
- '+', '+', '+', '+', '-', '-', '|', '|',%@NL@%
- ULC11, URC11, LLC11, LRC11, HBAR1, HBAR1, VBAR1, VBAR1,%@NL@%
- ULC22, URC22, LLC22, LRC22, HBAR2, HBAR2, VBAR2, VBAR2,%@NL@%
- ULC12, URC12, LLC12, LRC12, HBAR1, HBAR1, VBAR2, VBAR2,%@NL@%
- ULC21, URC21, LLC21, LRC21, HBAR2, HBAR2, VBAR1, VBAR1,%@NL@%
- BLOCK, BLOCK, BLOCK, BLOCK, HBART, HBARB, BLOCK, BLOCK%@NL@%
- };%@NL@%
- %@NL@%
- boxp = &box[type];%@NL@%
- maxc = win->c1 - win->c0;%@NL@%
- maxr = win->r1 - win->r0;%@NL@%
- x = maxc - 1;%@NL@%
- %@NL@%
- %@AB@%/* draw top row */%@AE@%%@NL@%
- sb_move(win, 0, 0);%@NL@%
- sb_wca(win, boxp->ul, attr, 1);%@NL@%
- sb_move(win, 0, 1);%@NL@%
- sb_wca(win, boxp->tbar, attr, x);%@NL@%
- sb_move(win, 0, maxc);%@NL@%
- sb_wca(win, boxp->ur, attr, 1);%@NL@%
- %@NL@%
- %@AB@%/* draw left and right sides */%@AE@%%@NL@%
- for (r = 1; r < maxr; ++r) {%@NL@%
- sb_move(win, r, 0);%@NL@%
- sb_wca(win, boxp->lbar, attr, 1);%@NL@%
- sb_move(win, r, maxc);%@NL@%
- sb_wca(win, boxp->rbar, attr, 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* draw bottom row */%@AE@%%@NL@%
- sb_move(win, maxr, 0);%@NL@%
- sb_wca(win, boxp->ll, attr, 1);%@NL@%
- sb_move(win, maxr, 1);%@NL@%
- sb_wca(win, boxp->bbar, attr, x);%@NL@%
- sb_move(win, maxr, maxc);%@NL@%
- sb_wca(win, boxp->lr, attr, 1);%@NL@%
- %@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_FILL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_FILL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_fill -- fill region routines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_fill -- set all cells in a specified region%@NL@%
- %@AB@% * to the same character/attribute value%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_fill(win, ch, attr)%@NL@%
- struct REGION *win;%@NL@%
- unsigned char ch; %@AB@%/* fill character */%@AE@%%@NL@%
- unsigned char attr; %@AB@%/* fill attribute */%@AE@%%@NL@%
- {%@NL@%
- register int i, j;%@NL@%
- unsigned short ca;%@NL@%
- %@NL@%
- ca = (attr << 8) | ch;%@NL@%
- for (i = win->sr0; i <= win->sr1; ++i) {%@NL@%
- for (j = win->sc0; j <= win->sc1; ++j)%@NL@%
- Scrnbuf[i][j].cap = ca;%@NL@%
- if (win->sc0 < Sbuf.lcol[i])%@NL@%
- Sbuf.lcol[i] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[i])%@NL@%
- Sbuf.rcol[i] = win->sc1;%@NL@%
- }%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_fillc -- set all cells in a specified region%@NL@%
- %@AB@% * to the same character value; leave attributes undisturbed%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_fillc(win, ch)%@NL@%
- struct REGION *win;%@NL@%
- unsigned char ch; %@AB@%/* fill character */%@AE@%%@NL@%
- {%@NL@%
- register int i, j;%@NL@%
- %@NL@%
- for (i = win->sr0; i <= win->sr1; ++i) {%@NL@%
- for (j = win->sc0; j <= win->sc1; ++j)%@NL@%
- Scrnbuf[i][j].b.ch = ch;%@NL@%
- if (win->sc0 < Sbuf.lcol[i])%@NL@%
- Sbuf.lcol[i] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[i])%@NL@%
- Sbuf.rcol[i] = win->sc1;%@NL@%
- }%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_filla -- set all cells in a specified region%@NL@%
- %@AB@% * to the same attribute value; leave characters undisturbed%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_filla(win, attr)%@NL@%
- struct REGION *win;%@NL@%
- unsigned char attr; %@AB@%/* fill attribute */%@AE@%%@NL@%
- {%@NL@%
- register int i, j;%@NL@%
- %@NL@%
- for (i = win->sr0; i <= win->sr1; ++i) {%@NL@%
- for (j = win->sc0; j <= win->sc1; ++j)%@NL@%
- Scrnbuf[i][j].b.attr = attr;%@NL@%
- if (win->sc0 < Sbuf.lcol[i])%@NL@%
- Sbuf.lcol[i] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[i])%@NL@%
- Sbuf.rcol[i] = win->sc1;%@NL@%
- }%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_INIT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_INIT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_init -- initialize the buffered screen interface%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- %@AB@%/* global data declarations */%@AE@%%@NL@%
- struct BUFFER Sbuf; %@AB@%/* control information */%@AE@%%@NL@%
- union CELL Scrnbuf[SB_ROWS][SB_COLS]; %@AB@%/* screen buffer array */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_init()%@NL@%
- {%@NL@%
- int i;%@NL@%
- char *um; %@AB@%/* update mode */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* set initial parameter values */%@AE@%%@NL@%
- Sbuf.bp = &Scrnbuf[0][0];%@NL@%
- Sbuf.row = Sbuf.col = 0;%@NL@%
- for (i = 0; i < SB_ROWS; ++i) {%@NL@%
- Sbuf.lcol[i] = SB_COLS;%@NL@%
- Sbuf.rcol[i] = 0;%@NL@%
- }%@NL@%
- Sbuf.flags = 0;%@NL@%
- %@NL@%
- %@AB@%/* set screen update mode */%@AE@%%@NL@%
- um = strupr(getenv("UPDATEMODE"));%@NL@%
- if (um == NULL || strcmp(um, "BIOS") == 0)%@NL@%
- Sbuf.flags &= ~SB_DIRECT;%@NL@%
- else if (strcmp(um, "DIRECT") == 0)%@NL@%
- Sbuf.flags |= SB_DIRECT;%@NL@%
- else%@NL@%
- return SB_ERR;%@NL@%
- %@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_MOVE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_MOVE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_move -- move the screen buffer "cursor"%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- int%@NL@%
- sb_move(win, r, c)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- register short r, c; %@AB@%/* buffer row and column */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* don't change anything if request is out of range */%@AE@%%@NL@%
- if (r < 0 || r > win->r1 - win->r0 || c < 0 || c > win->c1 - win->c0)%@NL@%
- return SB_ERR;%@NL@%
- win->row = r;%@NL@%
- win->col = c;%@NL@%
- Sbuf.row = r + win->r0;%@NL@%
- Sbuf.col = c + win->c0;%@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_NEW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_NEW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_new -- prepare a new window (rectangular region)%@NL@%
- %@AB@% * and return a pointer to it%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- struct REGION *%@NL@%
- sb_new(top, left, height, width)%@NL@%
- int top; %@AB@%/* top row */%@AE@%%@NL@%
- int left; %@AB@%/* left column */%@AE@%%@NL@%
- int height; %@AB@%/* total rows */%@AE@%%@NL@%
- int width; %@AB@%/* total columns */%@AE@%%@NL@%
- {%@NL@%
- struct REGION *new;%@NL@%
- %@NL@%
- %@AB@%/* allocate the control data structure */%@AE@%%@NL@%
- new = (struct REGION *)malloc(sizeof (struct REGION));%@NL@%
- if (new != NULL) {%@NL@%
- new->r0 = new->sr0 = top;%@NL@%
- new->r1 = new->sr1 = top + height - 1;%@NL@%
- new->c0 = new->sc0 = left;%@NL@%
- new->c1 = new->sc1 = left + width - 1;%@NL@%
- new->row = new->col = 0;%@NL@%
- new->wflags = 0;%@NL@%
- }%@NL@%
- return (new);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_PUT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_PUT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_put -- routines to put characters and strings into the%@NL@%
- %@AB@% * screen buffer; the cursor location is altered%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_putc -- put a character into a screen buffer window%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_putc(win, ch)%@NL@%
- struct REGION *win;%@NL@%
- unsigned char ch;%@NL@%
- {%@NL@%
- short cmax, rmax;%@NL@%
- short lim;%@NL@%
- short noscroll = 0, puterr = 0;%@NL@%
- %@NL@%
- %@AB@%/* calculate screen buffer position and limits */%@AE@%%@NL@%
- cmax = win->c1 - win->c0;%@NL@%
- rmax = win->r1 - win->r0;%@NL@%
- Sbuf.row = win->r0 + win->row;%@NL@%
- Sbuf.col = win->c0 + win->col;%@NL@%
- %@NL@%
- %@AB@%/* process the character */%@AE@%%@NL@%
- switch (ch) {%@NL@%
- case '\b':%@NL@%
- %@AB@%/* non-destructive backspace */%@AE@%%@NL@%
- if (win->col > 0) {%@NL@%
- --win->col;%@NL@%
- Sbuf.col = win->c0 + win->col;%@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- else%@NL@%
- return SB_ERR;%@NL@%
- case '\n':%@NL@%
- %@AB@%/* clear trailing line segment */%@AE@%%@NL@%
- while (win->col < cmax)%@NL@%
- if (sb_putc(win, ' ') == SB_ERR)%@NL@%
- ++puterr;%@NL@%
- break;%@NL@%
- case '\t':%@NL@%
- %@AB@%/* convert tab to required number of spaces */%@AE@%%@NL@%
- lim = win->col + 8 - (win->col & 0x7);%@NL@%
- while (win->col < lim)%@NL@%
- if (sb_putc(win, ' ') == SB_ERR)%@NL@%
- ++puterr;%@NL@%
- break;%@NL@%
- default:%@NL@%
- %@AB@%/* if printable ASCII, place the character in the buffer */%@AE@%%@NL@%
- if (isascii(ch) && isprint(ch))%@NL@%
- Scrnbuf[Sbuf.row][Sbuf.col].b.ch = ch;%@NL@%
- if (Sbuf.col < Sbuf.lcol[Sbuf.row])%@NL@%
- Sbuf.lcol[Sbuf.row] = Sbuf.col;%@NL@%
- if (Sbuf.col > Sbuf.rcol[Sbuf.row])%@NL@%
- Sbuf.rcol[Sbuf.row] = Sbuf.col;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* update the cursor position */%@AE@%%@NL@%
- if (win->col < cmax)%@NL@%
- ++win->col;%@NL@%
- else if (win->row < rmax) {%@NL@%
- win->col = 0;%@NL@%
- ++win->row;%@NL@%
- }%@NL@%
- else if ((win->wflags & SB_SCROLL) == SB_SCROLL) {%@NL@%
- sb_scrl(win, 1);%@NL@%
- win->col = 0;%@NL@%
- win->row = rmax;%@NL@%
- }%@NL@%
- else%@NL@%
- ++noscroll;%@NL@%
- %@NL@%
- %@AB@%/* update screen buffer position */%@AE@%%@NL@%
- Sbuf.row = win->r0 + win->row;%@NL@%
- Sbuf.col = win->c0 + win->col;%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return ((noscroll || puterr) ? SB_ERR : SB_OK);%@NL@%
- } %@AB@%/* end sb_putc() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_puts -- put a string into the screen buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_puts(win, s)%@NL@%
- struct REGION *win;%@NL@%
- unsigned char *s;%@NL@%
- {%@NL@%
- while (*s)%@NL@%
- if (sb_putc(win, *s++) == SB_ERR)%@NL@%
- return SB_ERR;%@NL@%
- return SB_OK;%@NL@%
- } %@AB@%/* end sb_puts() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_READ.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_READ.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_read -- read character/attribute data%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- unsigned char%@NL@%
- sb_ra(win)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- {%@NL@%
- return (Scrnbuf[win->r0 + win->row][win->c0 + win->col].b.attr);%@NL@%
- } %@AB@%/* end sb_ra() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_rc -- read character from current location in screen buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- unsigned char%@NL@%
- sb_rc(win)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- {%@NL@%
- return (Scrnbuf[win->r0 + win->row][win->c0 + win->col].b.ch);%@NL@%
- } %@AB@%/* end sb_rc() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_rca -- read character/attribute pair from current%@NL@%
- %@AB@% * location in screen buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- unsigned short%@NL@%
- sb_rca(win)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- {%@NL@%
- return (Scrnbuf[win->r0 + win->row][win->c0 + win->col].cap);%@NL@%
- } %@AB@%/* end sb_rca() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_SCRL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_SCRL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_scrl -- scrolling routines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_scrl -- scroll the specified window%@NL@%
- %@AB@% * n lines (direction indicated by sign)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_scrl(win, n)%@NL@%
- struct REGION *win;%@NL@%
- short n; %@AB@%/* number of rows to scroll */%@AE@%%@NL@%
- {%@NL@%
- register short r, c;%@NL@%
- %@NL@%
- if (n == 0)%@NL@%
- %@AB@%/* clear the entire region to spaces */%@AE@%%@NL@%
- sb_fillc(win, ' ');%@NL@%
- else if (n > 0) {%@NL@%
- %@AB@%/* scroll n rows up */%@AE@%%@NL@%
- for (r = win->sr0; r <= win->sr1 - n; ++r) {%@NL@%
- for (c = win->sc0; c <= win->sc1; ++c)%@NL@%
- Scrnbuf[r][c] = Scrnbuf[r + n][c];%@NL@%
- if (win->sc0 < Sbuf.lcol[r])%@NL@%
- Sbuf.lcol[r] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[r])%@NL@%
- Sbuf.rcol[r] = win->sc1;%@NL@%
- }%@NL@%
- for ( ; r <= win->sr1; ++r) {%@NL@%
- for (c = win->sc0; c <= win->sc1; ++c)%@NL@%
- Scrnbuf[r][c].b.ch = ' ';%@NL@%
- if (win->sc0 < Sbuf.lcol[r])%@NL@%
- Sbuf.lcol[r] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[r])%@NL@%
- Sbuf.rcol[r] = win->sc1;%@NL@%
- }%@NL@%
- }%@NL@%
- else {%@NL@%
- %@AB@%/* scroll n rows down */%@AE@%%@NL@%
- n = -n;%@NL@%
- for (r = win->sr1; r >= win->sr0 + n; --r) {%@NL@%
- for (c = win->sc0; c <= win->sc1; ++c)%@NL@%
- Scrnbuf[r][c] = Scrnbuf[r - n][c];%@NL@%
- if (win->sc0 < Sbuf.lcol[r])%@NL@%
- Sbuf.lcol[r] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[r])%@NL@%
- Sbuf.rcol[r] = win->sc1;%@NL@%
- }%@NL@%
- for ( ; r >= win->sr0; --r) {%@NL@%
- for (c = win->sc0; c <= win->sc1; ++c)%@NL@%
- Scrnbuf[r][c].b.ch = ' ';%@NL@%
- if (win->sc0 < Sbuf.lcol[r])%@NL@%
- Sbuf.lcol[r] = win->sc0;%@NL@%
- if (win->sc1 > Sbuf.rcol[r])%@NL@%
- Sbuf.rcol[r] = win->sc1;%@NL@%
- }%@NL@%
- }%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- return SB_OK;%@NL@%
- } %@AB@%/* end sb_scrl() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_set_scrl -- set the scroll region boundaries%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_set_scrl(win, top, left, bottom, right)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- short top, left; %@AB@%/* upper-left corner */%@AE@%%@NL@%
- short bottom, right; %@AB@%/* lower-left corner */%@AE@%%@NL@%
- {%@NL@%
- if (top < 0 || left < 0 ||%@NL@%
- bottom > win->r1 - win->r0 || right > win->c1 - win->c0)%@NL@%
- return SB_ERR;%@NL@%
- win->sr0 = win->r0 + top;%@NL@%
- win->sc0 = win->c0 + left;%@NL@%
- win->sr1 = win->r0 + bottom - 1;%@NL@%
- win->sc1 = win->c0 + right - 1;%@NL@%
- return SB_OK;%@NL@%
- } %@AB@%/* end sb_set_scrl() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_SHOW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_SHOW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_show -- copy the screen buffer to display memory%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@% MDA_SEG 0xB000 %@NL@%
- %@AI@%#define %@AE@% CGA_SEG 0xB800 %@NL@%
- %@AI@%#define %@AE@%NBYTES (2 * SB_COLS) %@NL@%
- %@NL@%
- %@AB@%/* macro to synchronize with vertical retrace period */%@AE@%%@NL@%
- %@AI@%#define %@AE@%VSTAT 0x3DA %@NL@%
- %@AI@%#define %@AE@%VRBIT 8 %@NL@%
- %@AI@%#define %@AE@%VSYNC while ((inp(VSTAT) & VRBIT) == VRBIT); \ %@NL@%
- while ((inp(VSTAT) & VRBIT) != VRBIT)%@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- int%@NL@%
- sb_show(pg)%@NL@%
- short pg;%@NL@%
- {%@NL@%
- register short r, c;%@NL@%
- short n;%@NL@%
- short count, ncols;%@NL@%
- unsigned int src_os, dest_os;%@NL@%
- struct SREGS segregs;%@NL@%
- %@NL@%
- if ((Sbuf.flags & SB_DIRECT) == SB_DIRECT) {%@NL@%
- %@AB@%/* use the direct-screen interface */%@AE@%%@NL@%
- segread(&segregs);%@NL@%
- %@NL@%
- %@AB@%/* determine extent of changes */%@AE@%%@NL@%
- n = 0;%@NL@%
- for (r = 0; r < SB_ROWS; ++r)%@NL@%
- if (Sbuf.lcol[r] <= Sbuf.rcol[r])%@NL@%
- ++n;%@NL@%
- src_os = dest_os = 0;%@NL@%
- if (n <= 2)%@NL@%
- %@AB@%/* copy only rows that contain changes */%@AE@%%@NL@%
- for (r = 0; r < SB_ROWS; ++r) {%@NL@%
- if (Sbuf.lcol[r] <= Sbuf.rcol[r]) {%@NL@%
- %@AB@%/* copy blocks during vertical retrace */%@AE@%%@NL@%
- VSYNC;%@NL@%
- movedata(segregs.ds,%@NL@%
- (unsigned)&Scrnbuf[0][0] + src_os,%@NL@%
- CGA_SEG, dest_os, NBYTES);%@NL@%
- Sbuf.lcol[r] = SB_COLS;%@NL@%
- Sbuf.rcol[r] = 0;%@NL@%
- }%@NL@%
- src_os += SB_COLS;%@NL@%
- dest_os += NBYTES;%@NL@%
- }%@NL@%
- else {%@NL@%
- %@AB@%/* copy the entire buffer */%@AE@%%@NL@%
- count = 3 * NBYTES;%@NL@%
- ncols = 3 * SB_COLS;%@NL@%
- for (r = 0; r < SB_ROWS - 1; r += 3) {%@NL@%
- VSYNC;%@NL@%
- movedata(segregs.ds, (unsigned)&Scrnbuf[0][0]%@NL@%
- + src_os, CGA_SEG, dest_os, count);%@NL@%
- src_os += ncols;%@NL@%
- dest_os += count;%@NL@%
- }%@NL@%
- VSYNC;%@NL@%
- movedata(segregs.ds, (unsigned)&Scrnbuf[0][0] + src_os,%@NL@%
- CGA_SEG, dest_os, NBYTES);%@NL@%
- for (r = 0; r < SB_ROWS; ++r) {%@NL@%
- Sbuf.lcol[r] = SB_COLS;%@NL@%
- Sbuf.rcol[r] = 0;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- %@AB@%/* use the BIOS video interface */%@AE@%%@NL@%
- for (r = 0; r < SB_ROWS; ++r)%@NL@%
- %@AB@%/* copy only changed portions of lines */%@AE@%%@NL@%
- if (Sbuf.lcol[r] < SB_COLS && Sbuf.rcol[r] > 0) {%@NL@%
- for (c = Sbuf.lcol[r]; c <= Sbuf.rcol[r]; ++c) {%@NL@%
- putcur(r, c, pg);%@NL@%
- writeca(Scrnbuf[r][c].b.ch,%@NL@%
- Scrnbuf[r][c].b.attr, 1, pg);%@NL@%
- }%@NL@%
- Sbuf.lcol[r] = SB_COLS;%@NL@%
- Sbuf.rcol[r] = 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* the display now matches the buffer -- clear flag bit */%@AE@%%@NL@%
- Sbuf.flags &= ~SB_DELTA;%@NL@%
- %@NL@%
- return SB_OK;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_TEST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_TEST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_test -- driver for screen-buffer interface functions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%<local\box.h> %@NL@%
- %@AI@%#include %@AE@%"sb_test.h" %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%BEL 7 %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- char *s, line[MAXLINE];%@NL@%
- int k;%@NL@%
- short i;%@NL@%
- FILE *fp;%@NL@%
- char fname[MAXPATH];%@NL@%
- struct REGION *cmnd, *stat, *text, *help, *curwin;%@NL@%
- unsigned char cmndattr, statattr, textattr, helpattr, curattr;%@NL@%
- unsigned char ch, userattr;%@NL@%
- %@NL@%
- %@AB@%/* function prototypes */%@AE@%%@NL@%
- int sb_init();%@NL@%
- int sb_move(struct REGION *, short, short);%@NL@%
- struct REGION *sb_new(short, short, short, short);%@NL@%
- int sb_putc(struct REGION *, unsigned char);%@NL@%
- int sb_puts(struct REGION *, char *);%@NL@%
- int sb_show(short);%@NL@%
- int sb_fill(struct REGION *, unsigned char, unsigned char);%@NL@%
- char *get_fname(struct REGION *, char *, short);%@NL@%
- %@NL@%
- getstate();%@NL@%
- readca(&ch, &userattr, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* set up the screen buffer */%@AE@%%@NL@%
- if (sb_init() == SB_ERR) {%@NL@%
- fprintf(stderr, "Bad UPDATEMODE value in environment\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* set up windows and scrolling regions */%@AE@%%@NL@%
- cmnd = sb_new(CMND_ROW, CMND_COL, CMND_HT, CMND_WID);%@NL@%
- stat = sb_new(STAT_ROW, STAT_COL, STAT_HT, STAT_WID);%@NL@%
- text = sb_new(TEXT_ROW, TEXT_COL, TEXT_HT, TEXT_WID);%@NL@%
- help = sb_new(HELP_ROW, HELP_COL, HELP_HT, HELP_WID);%@NL@%
- text->wflags |= SB_SCROLL;%@NL@%
- sb_set_scrl(help, 1, 1, HELP_HT - 1, HELP_WID - 1);%@NL@%
- %@NL@%
- %@AB@%/* display each primary window in its own attribute */%@AE@%%@NL@%
- cmndattr = GRN;%@NL@%
- statattr = (WHT << 4) | BLK;%@NL@%
- textattr = (BLU << 4) | CYAN;%@NL@%
- helpattr = (GRN << 4) | YEL;%@NL@%
- sb_fill(cmnd, ' ', cmndattr);%@NL@%
- if (sb_move(cmnd, 0, 0) == SB_OK)%@NL@%
- sb_puts(cmnd, "SB_TEST (Version 1.0)");%@NL@%
- sb_fill(stat, ' ', statattr);%@NL@%
- if (sb_move(stat, 0, 0) == SB_OK)%@NL@%
- sb_puts(stat, "*** STATUS AREA ***");%@NL@%
- for (i = 0; i <= text->r1 - text->r0; ++i) {%@NL@%
- sb_move(text, i, 0);%@NL@%
- sb_wca(text, i + 'a', textattr,%@NL@%
- text->c1 - text->c0 + 1);%@NL@%
- }%@NL@%
- if (sb_move(text, 10, 25) == SB_OK)%@NL@%
- sb_puts(text, " *** TEXT DISPLAY AREA *** ");%@NL@%
- sb_show(Vpage);%@NL@%
- curwin = text;%@NL@%
- curattr = textattr;%@NL@%
- %@NL@%
- %@AB@%/* respond to user commands */%@AE@%%@NL@%
- while ((k = getkey()) != K_ESC) {%@NL@%
- switch (k) {%@NL@%
- case K_UP:%@NL@%
- sb_scrl(curwin, 1);%@NL@%
- break;%@NL@%
- case K_DOWN:%@NL@%
- sb_scrl(curwin, -1);%@NL@%
- break;%@NL@%
- case K_PGUP:%@NL@%
- sb_scrl(curwin, curwin->sr1 - curwin->sr0);%@NL@%
- break;%@NL@%
- case K_PGDN:%@NL@%
- sb_scrl(curwin, -(curwin->sr1 - curwin->sr0));%@NL@%
- break;%@NL@%
- case K_ALTC:%@NL@%
- %@AB@%/* clear the current window */%@AE@%%@NL@%
- sb_fill(curwin, ' ', curattr);%@NL@%
- break;%@NL@%
- case K_ALTH:%@NL@%
- %@AB@%/* display help */%@AE@%%@NL@%
- curwin = help;%@NL@%
- curattr = helpattr;%@NL@%
- for (i = 0; i < help->r1 - help->r0; ++i) {%@NL@%
- sb_move(help, i, 0);%@NL@%
- sb_wca(help, i + 'a', helpattr,%@NL@%
- help->c1 - help->c0 + 1);%@NL@%
- }%@NL@%
- sb_box(help, BOXBLK, helpattr);%@NL@%
- break;%@NL@%
- case K_ALTS:%@NL@%
- %@AB@%/* fill the command area with letters */%@AE@%%@NL@%
- curwin = stat;%@NL@%
- curattr = statattr;%@NL@%
- sb_fill(stat, 's', statattr);%@NL@%
- break;%@NL@%
- case K_ALTT:%@NL@%
- %@AB@%/* fill the text area */%@AE@%%@NL@%
- curwin = text;%@NL@%
- curattr = textattr;%@NL@%
- for (i = 0; i <= text->r1 - text->r0; ++i) {%@NL@%
- sb_move(text, i, 0);%@NL@%
- sb_wca(text, i + 'a', textattr,%@NL@%
- text->c1 - text->c0 + 1);%@NL@%
- }%@NL@%
- break;%@NL@%
- case K_ALTR:%@NL@%
- %@AB@%/* read a file into the current window */%@AE@%%@NL@%
- sb_fill(stat, ' ', statattr);%@NL@%
- sb_move(stat, 0, 0);%@NL@%
- sb_puts(stat, "File to read: ");%@NL@%
- sb_show(Vpage);%@NL@%
- (void)get_fname(stat, fname, MAXPATH);%@NL@%
- if ((fp = fopen(fname, "r")) == NULL) {%@NL@%
- sb_fill(stat, ' ', statattr);%@NL@%
- sb_move(stat, 0, 0);%@NL@%
- sb_puts(stat, "Cannot open ");%@NL@%
- sb_puts(stat, fname);%@NL@%
- }%@NL@%
- else {%@NL@%
- sb_fill(stat, ' ', statattr);%@NL@%
- sb_move(stat, 0, 0);%@NL@%
- sb_puts(stat, "File: ");%@NL@%
- sb_puts(stat, fname);%@NL@%
- sb_show(Vpage);%@NL@%
- sb_fill(text, ' ', textattr);%@NL@%
- sb_move(text, 0, 0);%@NL@%
- putcur(text->r0, text->c0, Vpage);%@NL@%
- while ((s = fgets(line, MAXLINE, fp)) != NULL) {%@NL@%
- if (sb_puts(text, s) == SB_ERR) {%@NL@%
- clrscrn(userattr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- fprintf(stderr, "puts error\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- sb_show(Vpage);%@NL@%
- }%@NL@%
- if (ferror(fp)) {%@NL@%
- putcur(text->r0, text->c0, Vpage);%@NL@%
- fprintf(stderr, "Error reading file\n");%@NL@%
- }%@NL@%
- fclose(fp);%@NL@%
- }%@NL@%
- break;%@NL@%
- default:%@NL@%
- %@AB@%/* say what? */%@AE@%%@NL@%
- fputc(BEL, stderr);%@NL@%
- continue;%@NL@%
- }%@NL@%
- if ((Sbuf.flags & SB_DELTA) == SB_DELTA)%@NL@%
- sb_show(Vpage);%@NL@%
- }%@NL@%
- %@NL@%
- clrscrn(userattr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * get_fname -- get a filename from the user%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- char *%@NL@%
- get_fname(win, path, lim)%@NL@%
- struct REGION *win;%@NL@%
- char *path;%@NL@%
- short lim;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- char *s;%@NL@%
- %@NL@%
- s = path;%@NL@%
- sb_show(Vpage);%@NL@%
- while ((ch = getch()) != K_RETURN) {%@NL@%
- if (ch == '\b')%@NL@%
- --s;%@NL@%
- else {%@NL@%
- sb_putc(win, ch);%@NL@%
- *s++ = ch;%@NL@%
- }%@NL@%
- sb_show(Vpage);%@NL@%
- }%@NL@%
- *s = '\0';%@NL@%
- return (path);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SB_WRITE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\12SBUF\SB_WRITE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_write -- screen buffer write routines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sbuf.h> %@NL@%
- %@NL@%
- extern struct BUFFER Sbuf;%@NL@%
- extern union CELL Scrnbuf[SB_ROWS][SB_COLS];%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_wa -- write an attribute to a region of the screen buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_wa(win, attr, n)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- unsigned char attr; %@AB@%/* attribute */%@AE@%%@NL@%
- short n; %@AB@%/* repetition count */%@AE@%%@NL@%
- {%@NL@%
- short i;%@NL@%
- short row;%@NL@%
- short col;%@NL@%
- %@NL@%
- i = n;%@NL@%
- row = win->r0 + win->row;%@NL@%
- col = win->c0 + win->col;%@NL@%
- while (i--)%@NL@%
- Scrnbuf[row][col + i].b.attr = attr;%@NL@%
- %@NL@%
- %@AB@%/* marked the changed region */%@AE@%%@NL@%
- if (col < Sbuf.lcol[row])%@NL@%
- Sbuf.lcol[row] = col;%@NL@%
- if (col + n > Sbuf.rcol[row])%@NL@%
- Sbuf.rcol[row] = col + n;%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return (i == 0) ? SB_OK : SB_ERR;%@NL@%
- } %@AB@%/* end sb_wa() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_wc -- write a character to a region of the screen buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_wc(win, ch, n)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- unsigned char ch; %@AB@%/* character */%@AE@%%@NL@%
- short n; %@AB@%/* repetition count */%@AE@%%@NL@%
- {%@NL@%
- short i;%@NL@%
- short row;%@NL@%
- short col;%@NL@%
- %@NL@%
- i = n;%@NL@%
- row = win->r0 + win->row;%@NL@%
- col = win->c0 + win->col;%@NL@%
- while (i--)%@NL@%
- Scrnbuf[row][col + i].b.ch = ch;%@NL@%
- %@NL@%
- %@AB@%/* marked the changed region */%@AE@%%@NL@%
- if (col < Sbuf.lcol[row])%@NL@%
- Sbuf.lcol[row] = col;%@NL@%
- if (col + n > Sbuf.rcol[row])%@NL@%
- Sbuf.rcol[row] = col + n;%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return (i == 0 ? SB_OK : SB_ERR);%@NL@%
- } %@AB@%/* end sb_wc() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sb_wca -- write a character/attribute pair to a region%@NL@%
- %@AB@% * of the screen buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- sb_wca(win, ch, attr, n)%@NL@%
- struct REGION *win; %@AB@%/* window pointer */%@AE@%%@NL@%
- unsigned char ch; %@AB@%/* character */%@AE@%%@NL@%
- unsigned char attr; %@AB@%/* attribute */%@AE@%%@NL@%
- short n; %@AB@%/* repetition count */%@AE@%%@NL@%
- {%@NL@%
- int i;%@NL@%
- short row;%@NL@%
- short col;%@NL@%
- %@NL@%
- i = n;%@NL@%
- row = win->r0 + win->row;%@NL@%
- col = win->c0 + win->col;%@NL@%
- while (i--)%@NL@%
- Scrnbuf[row][col + i].cap = (attr << 8) | ch;%@NL@%
- %@NL@%
- %@AB@%/* marked the changed region */%@AE@%%@NL@%
- if (col < Sbuf.lcol[row])%@NL@%
- Sbuf.lcol[row] = col;%@NL@%
- if (col + n > Sbuf.rcol[row])%@NL@%
- Sbuf.rcol[row] = col + n;%@NL@%
- Sbuf.flags |= SB_DELTA;%@NL@%
- %@NL@%
- return (i == 0 ? SB_OK : SB_ERR);%@NL@%
- } %@AB@%/* end sb_wca() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\SC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * SetColor (sc) -- set foreground, background, and border%@NL@%
- %@AB@% * attributes on systems equipped with color display systems%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Usage: sc [foreground [background [border]]]%@NL@%
- %@AB@% * sc [attribute]%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@AI@%#include %@AE@%<local\ibmcolor.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- extern void ansi_tst();%@NL@%
- extern BOOLEAN iscolor();%@NL@%
- extern void setattr(POSITION, int);%@NL@%
- extern void menumode();%@NL@%
- extern parse(int, char **);%@NL@%
- %@NL@%
- ansi_tst();%@NL@%
- if (iscolor() == FALSE) {%@NL@%
- fprintf(stderr, "\n\nSystem not in a color text mode.\n");%@NL@%
- fprintf(stderr, "Use the MODE command to set the mode.\n");%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* process either batch or interactive commands */%@AE@%%@NL@%
- if (argc > 1)%@NL@%
- %@AB@%/* batch mode processing */%@AE@%%@NL@%
- parse(argc, argv);%@NL@%
- else%@NL@%
- %@AB@%/* no command-line args -- interactive mode */%@AE@%%@NL@%
- menumode();%@NL@%
- %@NL@%
- ANSI_ED;%@NL@%
- exit (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCROLL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\SCROLL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * scroll -- scroll a region of the "visual" screen%@NL@%
- %@AB@% * page up or down by n rows (0 = initialize region)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- scroll(t, l, b, r, n, a)%@NL@%
- int t; %@AB@%/* top row of scroll region */%@AE@%%@NL@%
- int l; %@AB@%/* left column */%@AE@%%@NL@%
- int b; %@AB@%/* bottom row */%@AE@%%@NL@%
- int r; %@AB@%/* right column */%@AE@%%@NL@%
- int n; %@AB@%/* number of lines to scroll */%@AE@%%@NL@%
- %@AB@%/* sign indicates direction to scroll */%@AE@%%@NL@%
- %@AB@%/* 0 means scroll all lines in the region (initialize) */%@AE@%%@NL@%
- unsigned char a;%@AB@%/* attribute for new lines */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- if (n < 0) {%@NL@%
- %@AB@%/* scroll visual page down n lines */%@AE@%%@NL@%
- inregs.h.ah = SCROLL_DN;%@NL@%
- inregs.h.al = -n;%@NL@%
- }%@NL@%
- else {%@NL@%
- %@AB@%/* scroll visual page up n lines */%@AE@%%@NL@%
- inregs.h.ah = SCROLL_UP;%@NL@%
- inregs.h.al = n;%@NL@%
- }%@NL@%
- inregs.h.bh = a; %@AB@%/* attribute of blank lines */%@AE@%%@NL@%
- inregs.h.bl = 0;%@NL@%
- inregs.h.ch = t; %@AB@%/* upper-left of scroll region */%@AE@%%@NL@%
- inregs.h.cl = l;%@NL@%
- inregs.h.dh = b; %@AB@%/* lower-right of scroll region */%@AE@%%@NL@%
- inregs.h.dl = r;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SC_CMDS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\SC_CMDS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sc_cmds -- display command summary%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@NL@%
- void%@NL@%
- sc_cmds(fg, bkg, bdr)%@NL@%
- int fg, bkg, bdr;%@NL@%
- {%@NL@%
- static char *color_xlat[] = {%@NL@%
- "Black (0)", "Blue (1)", "Green (2)", "Cyan (3)",%@NL@%
- "Red (4)", "Magenta (5)", "Brown (6)", "White (7)",%@NL@%
- "Grey (8)", "Light blue (9)", "Light green (10)",%@NL@%
- "Light cyan (11)", "Light red (12)", "Light magenta (13)",%@NL@%
- "Yellow (14)", "Bright white (15)"%@NL@%
- };%@NL@%
- %@NL@%
- ANSI_CUP(2, 29);%@NL@%
- fputs("*** SetColor (SC) ***", stdout);%@NL@%
- ANSI_CUP(4, 17);%@NL@%
- fputs("Attribute Decrement Increment Current Value", stdout);%@NL@%
- ANSI_CUP(5, 17);%@NL@%
- fputs("--------- --------- --------- -------------", stdout);%@NL@%
- ANSI_CUP(6, 17);%@NL@%
- fputs("Foreground F1 F2", stdout);%@NL@%
- ANSI_CUP(7, 17);%@NL@%
- fputs("Background F3 F4", stdout);%@NL@%
- ANSI_CUP(8, 17);%@NL@%
- fputs("Border F5 F6", stdout);%@NL@%
- ANSI_CUP(6, 50);%@NL@%
- fputs(color_xlat[fg], stdout);%@NL@%
- ANSI_CUP(7, 50);%@NL@%
- fputs(color_xlat[bkg], stdout);%@NL@%
- ANSI_CUP(8, 50);%@NL@%
- fputs(color_xlat[bdr], stdout);%@NL@%
- ANSI_CUP(10, 17);%@NL@%
- fputs("Type RETURN to exit. SetColor/Version 2.2", stdout);%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SELECT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\SELECT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * select -- functions to create a selection table and%@NL@%
- %@AB@% * to determine whether an item is an entry in the table%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NRANGES 10 %@NL@%
- %@AI@%#define %@AE@%NDIGITS 5 %@NL@%
- %@NL@%
- struct slist_st {%@NL@%
- long int s_min;%@NL@%
- long int s_max;%@NL@%
- } Slist[NRANGES + 1];%@NL@%
- %@NL@%
- long Highest = 0;%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * mkslist -- create the selection lookup table%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- mkslist(list)%@NL@%
- char *list;%@NL@%
- {%@NL@%
- int i;%@NL@%
- char *listp, *s;%@NL@%
- long tmp;%@NL@%
- %@NL@%
- static long save_range();%@NL@%
- %@NL@%
- %@AB@%/* fill in table of selected items */%@AE@%%@NL@%
- if (*list == '\0') {%@NL@%
- %@AB@%/* if no list, select all */%@AE@%%@NL@%
- Slist[0].s_min = 0;%@NL@%
- Slist[0].s_max = Highest = BIGGEST;%@NL@%
- Slist[1].s_min = -1;%@NL@%
- }%@NL@%
- else {%@NL@%
- listp = list;%@NL@%
- for (i = 0; i < NRANGES; ++i) {%@NL@%
- if ((s = strtok(listp, ", \t")) == NULL)%@NL@%
- break;%@NL@%
- if ((tmp = save_range(i, s)) > Highest)%@NL@%
- Highest = tmp;%@NL@%
- listp = NULL;%@NL@%
- }%@NL@%
- Slist[i].s_min = -1;%@NL@%
- }%@NL@%
- return (0);%@NL@%
- } %@AB@%/* end mkslist() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * selected -- return non-zero value if the number%@NL@%
- %@AB@% * argument is a member of the selection list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- selected(n)%@NL@%
- unsigned int n;%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* look for converted number in selection list */%@AE@%%@NL@%
- for (i = 0; Slist[i].s_min != -1; ++i)%@NL@%
- if (n >= Slist[i].s_min && n <= Slist[i].s_max)%@NL@%
- return (1);%@NL@%
- return (0);%@NL@%
- } %@AB@%/* end selected() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * save_range -- convert a string number spec to a%@NL@%
- %@AB@% * numeric range in the selection table and return%@NL@%
- %@AB@% * the highest number in the range%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static long%@NL@%
- save_range(n, s)%@NL@%
- int n;%@NL@%
- char *s;%@NL@%
- {%@NL@%
- int radix = 10;%@NL@%
- char *cp, num[NDIGITS + 1];%@NL@%
- %@NL@%
- %@AB@%/* get the first (and possibly only) number */%@AE@%%@NL@%
- cp = num;%@NL@%
- while (*s != '\0' && *s != '-')%@NL@%
- *cp++ = *s++;%@NL@%
- *cp = '\0';%@NL@%
- Slist[n].s_min = atol(num);%@NL@%
- if (*s == '\0')%@NL@%
- %@AB@%/* pretty narrow range, huh? */%@AE@%%@NL@%
- return (Slist[n].s_max = Slist[n].s_min);%@NL@%
- %@NL@%
- %@AB@%/* get the second number */%@AE@%%@NL@%
- if (*++s == '\0')%@NL@%
- %@AB@%/* unspecified top end of range */%@AE@%%@NL@%
- Slist[n].s_max = BIGGEST;%@NL@%
- else {%@NL@%
- cp = num;%@NL@%
- while (*s != '\0' && *s != '-')%@NL@%
- *cp++ = *s++;%@NL@%
- *cp = '\0';%@NL@%
- Slist[n].s_max = atol(num);%@NL@%
- }%@NL@%
- return (Slist[n].s_max);%@NL@%
- } %@AB@%/* end save_range() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETATTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\SETATTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setattr -- execute an attribute update%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@AI@%#include %@AE@%<local\ibmcolor.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%C_MASK 0x7 %@NL@%
- %@NL@%
- void%@NL@%
- setattr(pos, attr)%@NL@%
- POSITION pos; %@AB@%/* attribute position */%@AE@%%@NL@%
- int attr; %@AB@%/* composite attribute number (base attr | intensity) */%@AE@%%@NL@%
- {%@NL@%
- static int ibm2ansi[] = {%@NL@%
- ANSI_BLACK, ANSI_BLUE, ANSI_GREEN, ANSI_CYAN,%@NL@%
- ANSI_RED, ANSI_MAGENTA, ANSI_BROWN, ANSI_WHITE%@NL@%
- };%@NL@%
- %@NL@%
- switch (pos) {%@NL@%
- case FGND:%@NL@%
- if (attr & IBM_BRIGHT)%@NL@%
- ANSI_SGR(ANSI_BOLD);%@NL@%
- ANSI_SGR(ibm2ansi[attr & C_MASK] + ANSI_FOREGROUND);%@NL@%
- break;%@NL@%
- case BKGND:%@NL@%
- if (attr & IBM_BRIGHT)%@NL@%
- ANSI_SGR(ANSI_BLINK);%@NL@%
- ANSI_SGR(ibm2ansi[attr & C_MASK] + ANSI_BACKGROUND);%@NL@%
- break;%@NL@%
- case BDR:%@NL@%
- palette(0, attr);%@NL@%
- break;%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETCTYPE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\SETCTYPE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setctype -- set the cursor start and end raster scan lines%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%LO_NIBBLE 0x0F %@NL@%
- %@AI@%#define %@AE@%CURSOR_OFF 0x2 %@NL@%
- %@AI@%#define %@AE@%MAXSCANLN 15 %@NL@%
- %@NL@%
- int%@NL@%
- setctype(start, end)%@NL@%
- int start; %@AB@%/* starting raster scan line */%@AE@%%@NL@%
- int end; %@AB@%/* ending raster scan line */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = CUR_TYPE;%@NL@%
- inregs.h.ch = start & LO_NIBBLE;%@NL@%
- inregs.h.cl = end & LO_NIBBLE;%@NL@%
- if (start >= MAXSCANLN) {%@NL@%
- inregs.h.ah |= CURSOR_OFF;%@NL@%
- inregs.h.al = MAXSCANLN;%@NL@%
- }%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETDTA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\SETDTA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setdta -- tell DOS where to do disk transfers%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- void%@NL@%
- setdta(bp)%@NL@%
- char *bp; %@AB@%/* pointer to byte-aligned disk transfer area */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = SET_DTA;%@NL@%
- inregs.x.dx = (unsigned int)bp;%@NL@%
- (void)intdos(&inregs, &outregs);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETFREQ.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\SETFREQ.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setfreq -- sets PC's tone generator to run%@NL@%
- %@AB@% * continuously at the specified frequency%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<local\timer.h> %@NL@%
- %@NL@%
- void%@NL@%
- setfreq(f)%@NL@%
- unsigned f; %@AB@%/* frequency in Hertz (approximate) */%@AE@%%@NL@%
- {%@NL@%
- unsigned divisor = TIMER_CLK / f;%@NL@%
- %@NL@%
- outp(TIMER_CTRL, TIMER_PREP); %@AB@%/* prepare timer */%@AE@%%@NL@%
- outp(TIMER_COUNT, (divisor & 0xFF)); %@AB@%/* low byte of divisor */%@AE@%%@NL@%
- outp(TIMER_COUNT, (divisor >> 8)); %@AB@%/* high byte of divisor */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETMYDIR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\03DOS\SETMYDIR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setmydir -- try to change the DOS environment%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- register char **p;%@NL@%
- static char var[] = { "MYDIR" };%@NL@%
- static char pgm[MAXNAME + 1] = { "setmydir" };%@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- extern void getpname(char *, char *);%@NL@%
- %@NL@%
- %@AB@%/* use an alias if one is given to this program */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* try to add the MYDIR variable to the environment */%@AE@%%@NL@%
- if (putenv("MYDIR=c:\\mydir") == -1)%@NL@%
- fatal(pgm, "Error changing environment", 1);%@NL@%
- %@NL@%
- %@AB@%/* display the environment for this process */%@AE@%%@NL@%
- for (p = environ; *p; p++) {%@NL@%
- printf("%s\n", *p);%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETPAGE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\SETPAGE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setpage -- select "visual" screen page for viewing%@NL@%
- %@AB@% * (the "active" page is the one being written to)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- int%@NL@%
- setpage(pg)%@NL@%
- int pg; %@AB@%/* visual screen page number */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- %@AB@%/* check page number against table */%@AE@%%@NL@%
- if (Maxpage[Vmode] > 0 && (pg < 0 || pg >= Maxpage[Vmode]))%@NL@%
- return (-1);%@NL@%
- %@NL@%
- %@AB@%/* change the visual page */%@AE@%%@NL@%
- inregs.h.ah = SET_PAGE;%@NL@%
- inregs.h.al = pg;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETVMODE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\SETVMODE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * setvmode -- set the video mode%@NL@%
- %@AB@% * (color/graphics systems only)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- %@AB@%/***********************************************************%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* mode # (m) description%@NL@%
- %@AB@%* ------------- ---------------------------------%@NL@%
- %@AB@%* PC MODES:%@NL@%
- %@AB@%* 0 40x25 Mono text (c/g default)%@NL@%
- %@AB@%* 1 40x25 Color text%@NL@%
- %@AB@%* 2 80x25 Mono text%@NL@%
- %@AB@%* 3 80x25 Color text%@NL@%
- %@AB@%* 4 320x200 4-color graphics (med res)%@NL@%
- %@AB@%* 5 320x200 Mono graphics (med res)%@NL@%
- %@AB@%* 6 640x200 2-color graphics (hi res)%@NL@%
- %@AB@%* 7 80x25 on monochrome adapter %@NL@%
- %@AB@%*%@NL@%
- %@AB@%* PCjr MODES:%@NL@%
- %@AB@%* 8 160x200 16-color graphics%@NL@%
- %@AB@%* 9 320x200 16-color graphics%@NL@%
- %@AB@%* 10 640x200 4-color fraphics%@NL@%
- %@AB@%*%@NL@%
- %@AB@%* EGA MODES:%@NL@%
- %@AB@%* 13 320x200 16-color graphics%@NL@%
- %@AB@%* 14 620x200 16-color graphics%@NL@%
- %@AB@%* 15 640x350 mono graphics%@NL@%
- %@AB@%* 16 640x350 color graphics (4- or 16-color)%@NL@%
- %@AB@%***********************************************************/%@AE@%%@NL@%
- %@NL@%
- int%@NL@%
- setvmode(vmode)%@NL@%
- unsigned int vmode; %@AB@%/* user-specified mode number */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = SET_MODE;%@NL@%
- inregs.h.al = vmode; %@AB@%/* value not checked */%@AE@%%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- %@AB@%/* update video structure */%@AE@%%@NL@%
- getstate();%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\10DUMP\SHOW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * show -- a filter that displays the contents of a file%@NL@%
- %@AB@% * in a way that is guaranteed to be displayable%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- FILE *fp;%@NL@%
- BOOLEAN sflag = FALSE; %@AB@%/* strip non-ASCII characters */%@AE@%%@NL@%
- BOOLEAN vflag = FALSE; %@AB@%/* verbose mode */%@AE@%%@NL@%
- BOOLEAN wflag = FALSE; %@AB@%/* filter typical word processing codes */%@AE@%%@NL@%
- BOOLEAN errflag = FALSE;%@NL@%
- static char pgm[] = { "show" };%@NL@%
- %@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern char *optarg;%@NL@%
- extern int optind, opterr;%@NL@%
- extern int showit(FILE *, BOOLEAN, BOOLEAN);%@NL@%
- extern void fatal(char *, char *, int);%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- while ((ch = getopt(argc, argv, "svw")) != EOF) {%@NL@%
- switch (ch) {%@NL@%
- case 's': %@AB@%/* strip non-ASCII characters */%@AE@%%@NL@%
- sflag = TRUE;%@NL@%
- break;%@NL@%
- case 'v': %@AB@%/* verbose */%@AE@%%@NL@%
- vflag = TRUE;%@NL@%
- break;%@NL@%
- case 'w': %@AB@%/* use word-processing conventions */%@AE@%%@NL@%
- wflag = sflag = TRUE;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* check for errors */%@AE@%%@NL@%
- if (errflag == TRUE) {%@NL@%
- fprintf(stderr, "Usage: %s [-sv] [file...]\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* if no file names, use standard input */%@AE@%%@NL@%
- if (optind == argc) {%@NL@%
- if (setmode(fileno(stdin), O_BINARY) == -1)%@NL@%
- fatal(pgm, "Cannot set binary mode on stdin", 2);%@NL@%
- showit(stdin, sflag, wflag);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* otherwise, process remainder of command line */%@AE@%%@NL@%
- for ( ; optind < argc; ++optind) {%@NL@%
- if ((fp = fopen(argv[optind], "rb")) == NULL) {%@NL@%
- fprintf(stderr,%@NL@%
- "%s: Error opening %s\n", pgm, argv[optind]);%@NL@%
- perror("");%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (vflag == TRUE)%@NL@%
- fprintf(stdout, "\n%s:\n", argv[optind]);%@NL@%
- if (showit(fp, sflag, wflag) != 0) {%@NL@%
- fprintf(stderr,%@NL@%
- "%s: Error reading %s\n", pgm, argv[optind]);%@NL@%
- perror("");%@NL@%
- }%@NL@%
- if (fclose(fp) == EOF)%@NL@%
- fatal(pgm, "Error closing input file", 2);%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWENV.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\03DOS\SHOWENV.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showenv -- display the values of any DOS variables%@NL@%
- %@AB@% * named on the invocation command line%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv, envp)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- char **envp;%@NL@%
- {%@NL@%
- register char *ep;%@NL@%
- static char pgm[MAXNAME + 1] = { "showenv" };%@NL@%
- extern void getpname(char *, char *);%@NL@%
- %@NL@%
- %@AB@%/* use an alias if one is given to this program */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* if no arguments, show full environment list */%@AE@%%@NL@%
- if (argc == 1)%@NL@%
- for (; *envp; ++envp)%@NL@%
- printf("%s\n", *envp);%@NL@%
- else {%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * treat all args as DOS variable names and%@NL@%
- %@AB@% * display values of only specified variables%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ++argv; %@AB@%/* skip past command name */%@AE@%%@NL@%
- --argc;%@NL@%
- while (argc > 0) {%@NL@%
- if ((ep = getenv(strupr(*argv))) == NULL)%@NL@%
- fprintf(stderr, "%s not defined\n", *argv);%@NL@%
- else%@NL@%
- printf("%s=%s\n", *argv, ep);%@NL@%
- ++argv;%@NL@%
- --argc;%@NL@%
- }%@NL@%
- }%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWIT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\10DUMP\SHOWIT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showit -- make non-printable characters in%@NL@%
- %@AB@% * the stream fp visible (or optionally strip them)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- int%@NL@%
- showit(fp, strip, wp)%@NL@%
- FILE *fp;%@NL@%
- BOOLEAN strip; %@AB@%/* strip non-ASCII codes */%@AE@%%@NL@%
- BOOLEAN wp; %@AB@%/* filter typical word processing codes */%@AE@%%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- clearerr(fp);%@NL@%
- while ((ch = getc(fp)) != EOF)%@NL@%
- if (isascii(ch) && (isprint(ch) || isspace(ch)))%@NL@%
- switch (ch) {%@NL@%
- case '\r':%@NL@%
- if (wp == TRUE) {%@NL@%
- if ((ch = getc(fp)) != '\n')%@NL@%
- ungetc(ch, fp);%@NL@%
- putchar('\r');%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- else%@NL@%
- putchar(ch);%@NL@%
- break;%@NL@%
- default:%@NL@%
- putchar(ch);%@NL@%
- break;%@NL@%
- }%@NL@%
- else if (strip == FALSE)%@NL@%
- printf("\\%02X", ch);%@NL@%
- else if (wp == TRUE && isprint(ch & ASCII))%@NL@%
- putchar(ch & ASCII);%@NL@%
- return (ferror(fp));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWTABS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\07CONFIG\SHOWTABS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showtabs -- graphically display tabstop settings%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXCOL 80 %@NL@%
- %@AI@%#define %@AE@%TABWIDTH 8 %@NL@%
- %@NL@%
- extern long Highest;%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int ch, i;%@NL@%
- int interval, tablist[MAXLINE + 1], *p;%@NL@%
- char *tabstr;%@NL@%
- BOOLEAN errflag, fflag, vflag;%@NL@%
- static char pgm[MAXNAME + 1] = { "showtabs" };%@NL@%
- %@NL@%
- extern char *getpname(char *, char *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern char *optarg;%@NL@%
- extern int optind, opterr;%@NL@%
- extern int mkslist(char *);%@NL@%
- extern int selected(long);%@NL@%
- extern void fixtabs(int);%@NL@%
- extern void vartabs(int *);%@NL@%
- extern int tabstop(int);%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* process command-line options */%@AE@%%@NL@%
- errflag = fflag = vflag = FALSE;%@NL@%
- interval = 0;%@NL@%
- while ((ch = getopt(argc, argv, "f:v:")) != EOF) {%@NL@%
- switch (ch) {%@NL@%
- case 'f':%@NL@%
- %@AB@%/* used fixed tabbing interval */%@AE@%%@NL@%
- if (vflag == FALSE) {%@NL@%
- fflag = TRUE;%@NL@%
- interval = atoi(optarg);%@NL@%
- }%@NL@%
- break;%@NL@%
- case 'v':%@NL@%
- %@AB@%/* use list of tabs */%@AE@%%@NL@%
- if (fflag == FALSE) {%@NL@%
- vflag = TRUE;%@NL@%
- strcpy(tabstr, optarg);%@NL@%
- }%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- if (errflag == TRUE) {%@NL@%
- fprintf(stderr, "Usage: %s [-f interval | -v tablist]\n", pgm);%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* set the tabstops */%@AE@%%@NL@%
- if (vflag == TRUE) {%@NL@%
- %@AB@%/* user-supplied variable tab list */%@AE@%%@NL@%
- mkslist(tabstr);%@NL@%
- p = tablist;%@NL@%
- for (i = 0; i < MAXLINE && i < Highest; ++i)%@NL@%
- *p++ = selected((long)i + 1) ? i : 0;%@NL@%
- *p = -1; %@AB@%/* terminate the list */%@AE@%%@NL@%
- vartabs(tablist);%@NL@%
- }%@NL@%
- else if (fflag == TRUE)%@NL@%
- %@AB@%/* user-supplied fixed tabbing interval */%@AE@%%@NL@%
- fixtabs(interval);%@NL@%
- else%@NL@%
- %@AB@%/* hardware default tabbing interval*/%@AE@%%@NL@%
- fixtabs(TABWIDTH);%@NL@%
- %@NL@%
- %@AB@%/* display current tabs settings */%@AE@%%@NL@%
- for (i = 0; i < MAXCOL; ++i)%@NL@%
- if (tabstop(i))%@NL@%
- fputc('T', stdout);%@NL@%
- else if ((i + 1) % 10 == 0)%@NL@%
- fputc('+', stdout);%@NL@%
- else%@NL@%
- fputc('-', stdout);%@NL@%
- fputc('\n', stdout);%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SOUND.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\SOUND.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sound -- produce a constant tone for a specified duration%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sound.h> %@NL@%
- %@NL@%
- void%@NL@%
- sound(f, dur)%@NL@%
- unsigned int f; %@AB@%/* frequency of pitch in hertz */%@AE@%%@NL@%
- float dur; %@AB@%/* in seconds and tenths of seconds */%@AE@%%@NL@%
- {%@NL@%
- extern void setfreq(unsigned int);%@NL@%
- extern void delay(float);%@NL@%
- %@NL@%
- %@AB@%/* set frequency in hertz */%@AE@%%@NL@%
- setfreq(f);%@NL@%
- %@NL@%
- %@AB@%/* turn the speaker on for specified duration */%@AE@%%@NL@%
- SPKR_ON;%@NL@%
- delay(dur);%@NL@%
- SPKR_OFF;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SOUNDS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\SOUNDS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sounds -- make various sounds on demand%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%ESC 27 %@NL@%
- %@NL@%
- extern void sound(unsigned int, float);%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- fprintf(stderr, "1=warble 2=error 3=confirm 4=warn\n");%@NL@%
- fprintf(stderr, "Esc=quit\n");%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- switch (ch) {%@NL@%
- case '1':%@NL@%
- warble();%@NL@%
- break;%@NL@%
- case '2':%@NL@%
- error();%@NL@%
- break;%@NL@%
- case '3':%@NL@%
- confirm();%@NL@%
- break;%@NL@%
- case '4':%@NL@%
- warn();%@NL@%
- break;%@NL@%
- }%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%CYCLES 3 %@NL@%
- %@AI@%#define %@AE@%LOTONE 600 %@NL@%
- %@AI@%#define %@AE@%HITONE 1200 %@NL@%
- %@AI@%#define %@AE@%PERIOD 0.1 %@NL@%
- %@NL@%
- warble()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < 2 * CYCLES; ++i)%@NL@%
- if (i % 2)%@NL@%
- sound(LOTONE, PERIOD);%@NL@%
- else%@NL@%
- sound(HITONE, PERIOD);%@NL@%
- }%@NL@%
- %@NL@%
- error()%@NL@%
- {%@NL@%
- float d = 0.15;%@NL@%
- %@NL@%
- sound(440, d);%@NL@%
- sound(220, d);%@NL@%
- }%@NL@%
- %@NL@%
- confirm()%@NL@%
- {%@NL@%
- float d = 0.15;%@NL@%
- %@NL@%
- sound(440, d);%@NL@%
- sound(880, d);%@NL@%
- }%@NL@%
- %@NL@%
- warn()%@NL@%
- {%@NL@%
- float d = 0.2;%@NL@%
- %@NL@%
- sound(100, d);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SPACES.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\SPACES.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * spaces -- send spaces (blanks) to the output stream%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- int%@NL@%
- spaces(n, fp)%@NL@%
- int n;%@NL@%
- FILE *fp;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- %@NL@%
- for (i = 0; i < n; ++i)%@NL@%
- if (putc(' ', fp) == EOF && ferror(fp))%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* return number of spaces emitted */%@AE@%%@NL@%
- return (i);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SPKR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\SPKR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * spkr -- turn speaker ON/OFF%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * no args => OFF%@NL@%
- %@AB@% * any arg(s) => ON%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\sound.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- %@AB@%/* turn speaker on or off */%@AE@%%@NL@%
- if (argc == 1)%@NL@%
- SPKR_OFF;%@NL@%
- else%@NL@%
- SPKR_ON;%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\11SCREEN\ST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * st -- screen test using cpblk function%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%CG_SEG 0xB800 %@NL@%
- %@AI@%#define %@AE@%MONO_SEG 0xB000 %@NL@%
- %@AI@%#define %@AE@%NBYTES 0x1000 %@NL@%
- %@AI@%#define %@AE@%PAGESIZ (NBYTES / 2) %@NL@%
- %@AI@%#define %@AE@%PG0_OS 0 %@NL@%
- %@AI@%#define %@AE@%PG1_OS PG0_OS + NBYTES %@NL@%
- %@AI@%#define %@AE@%ESC 27 %@NL@%
- %@AI@%#define %@AE@%MAXSCAN 14 %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int i;%@NL@%
- int k; %@AB@%/* user command character */%@AE@%%@NL@%
- int ca; %@AB@%/* character/attribute word */%@AE@%%@NL@%
- int ch; %@AB@%/* character value read */%@AE@%%@NL@%
- int row, col; %@AB@%/* cursor position upon entry */%@AE@%%@NL@%
- int c_start, c_end; %@AB@%/* cursor scan lines */%@AE@%%@NL@%
- unsigned char attr; %@AB@%/* saved video attribute */%@AE@%%@NL@%
- unsigned dseg; %@AB@%/* destination buffer segment */%@AE@%%@NL@%
- unsigned os; %@AB@%/* page offset in bytes */%@AE@%%@NL@%
- static unsigned sbuf[NBYTES]; %@AB@%/* screen buffer */%@AE@%%@NL@%
- unsigned *bp; %@AB@%/* screen element pointer */%@AE@%%@NL@%
- unsigned sseg; %@AB@%/* source segment */%@AE@%%@NL@%
- int special; %@AB@%/* use special copy routine */%@AE@%%@NL@%
- int apg, vpg; %@AB@%/* active and visual display pages */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* segment register values */%@AE@%%@NL@%
- struct SREGS segregs;%@NL@%
- %@NL@%
- extern void swap_int(int *, int *);%@NL@%
- %@NL@%
- static char pgm[] = { "st" }; %@AB@%/* program name */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* save user's current video state */%@AE@%%@NL@%
- getstate();%@NL@%
- readcur(&row, &col, Vpage);%@NL@%
- putcur(row - 1, 0, Vpage);%@NL@%
- readca(&ch, &attr, Vpage);%@NL@%
- getctype(&c_start, &c_end, Vpage);%@NL@%
- setctype(MAXSCAN, c_end);%@NL@%
- clrscrn(attr);%@NL@%
- putcur(1, 1, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* initialize destination segment */%@AE@%%@NL@%
- special = 1;%@NL@%
- fputs("ScreenTest (ST): ", stderr);%@NL@%
- if (Vmode == CGA_C80 || Vmode == CGA_M80) {%@NL@%
- dseg = CG_SEG;%@NL@%
- fprintf(stderr, "Using CGA mode %d", Vmode);%@NL@%
- }%@NL@%
- else if (Vmode == MDA_M80) {%@NL@%
- dseg = MONO_SEG;%@NL@%
- fprintf(stderr, "Using MDA (mode %d)", Vmode);%@NL@%
- special = 0;%@NL@%
- } else%@NL@%
- fprintf(stderr, "%s: Requires 80-column text mode\n", pgm);%@NL@%
- %@NL@%
- %@AB@%/* process command-line arguments */%@AE@%%@NL@%
- if (argc > 2) {%@NL@%
- fprintf(stderr, "Usage: %s [x]\n", pgm);%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- else if (argc == 2)%@NL@%
- special = 0; %@AB@%/* bypass special block move */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* get data segment value */%@AE@%%@NL@%
- segread(&segregs);%@NL@%
- sseg = segregs.ds;%@NL@%
- %@NL@%
- %@AB@%/* set up "active" and "visual" display pages */%@AE@%%@NL@%
- apg = 1; %@AB@%/* page being written to */%@AE@%%@NL@%
- vpg = 0; %@AB@%/* page being viewed */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* display buffers on the user's command */%@AE@%%@NL@%
- fprintf(stderr, " -- Type printable text; Esc=exit");%@NL@%
- while ((k = getkey()) != ESC) {%@NL@%
- if (isascii(k) && isprint(k)) {%@NL@%
- %@AB@%/* fill the buffer */%@AE@%%@NL@%
- ca = ((k % 0xEF) << 8) | k;%@NL@%
- for (bp = sbuf; bp - sbuf < PAGESIZ; ++bp)%@NL@%
- *bp = ca;%@NL@%
- if (Vmode == MDA_M80)%@NL@%
- os = 0;%@NL@%
- else%@NL@%
- os = (apg == 0) ? PG0_OS : PG1_OS;%@NL@%
- if (special)%@NL@%
- cpblk(sbuf, sseg, os, dseg);%@NL@%
- else%@NL@%
- movedata(sseg, sbuf, dseg, os, NBYTES);%@NL@%
- if (Vmode != MDA_M80) {%@NL@%
- swap_int(&apg, &vpg);%@NL@%
- setpage(vpg);%@NL@%
- }%@NL@%
- }%@NL@%
- else {%@NL@%
- clrscrn(attr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- writestr(" Type printable text; Esc = exit ", vpg);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* restore user's video conditions and return to DOS */%@AE@%%@NL@%
- setpage(Vpage);%@NL@%
- clrscrn(attr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- setctype(c_start, c_end);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRDUP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\STRDUP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * strdup -- duplicate a string%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- char *%@NL@%
- strdup(str)%@NL@%
- char *str;%@NL@%
- {%@NL@%
- char *buf;%@NL@%
- %@NL@%
- buf = malloc(strlen(str) + 1);%@NL@%
- return (buf == NULL ? buf : strcpy(buf, str));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRING.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\STRING.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * string -- emit a sequence of n repetitions of the%@NL@%
- %@AB@% * character ch %@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- int%@NL@%
- string(n, ch, fp)%@NL@%
- int n;%@NL@%
- char ch;%@NL@%
- FILE *fp;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- %@NL@%
- for (i = 0; i < n; ++i)%@NL@%
- if (fputc(ch, fp) == EOF && ferror(fp))%@NL@%
- break;%@NL@%
- %@NL@%
- %@AB@%/* return number of actual repetitions */%@AE@%%@NL@%
- return (i);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SWAP_INT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\11SCREEN\SWAP_INT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * swap_int -- exchange the values of the two integers%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void%@NL@%
- swap_int(p1, p2)%@NL@%
- register int *p1;%@NL@%
- register int *p2;%@NL@%
- {%@NL@%
- int tmp;%@NL@%
- %@NL@%
- %@AB@%/* exchange the values */%@AE@%%@NL@%
- tmp = *p1;%@NL@%
- *p1 = *p2;%@NL@%
- *p2 = tmp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SWEEP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\SWEEP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * sweep -- produce a sound that sweeps from%@NL@%
- %@AB@% * a low to a high frequency repeatedly until a%@NL@%
- %@AB@% * key is pressed%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<local\sound.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned int f;%@NL@%
- int d, n;%@NL@%
- extern void setfreq(unsigned int);%@NL@%
- %@NL@%
- SPKR_ON;%@NL@%
- while (1) {%@NL@%
- %@AB@%/* give user a way out */%@AE@%%@NL@%
- if (kbhit())%@NL@%
- break;%@NL@%
- n = 10;%@NL@%
- for (f = 100; f <= 5000; f += n) {%@NL@%
- setfreq(f);%@NL@%
- d = 1000;%@NL@%
- %@AB@%/* fake a short delay (machine dependednt) */%@AE@%%@NL@%
- while (d-- > 0)%@NL@%
- ;%@NL@%
- n += 10;%@NL@%
- }%@NL@%
- }%@NL@%
- SPKR_OFF;%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TABS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\TABS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * tabs -- a group of cooperating functions that set%@NL@%
- %@AB@% * and report the settings of "tabstops"%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- static char Tabstops[MAXLINE];%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * fixtabs -- set up fixed-interval tabstops%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void%@NL@%
- fixtabs(interval)%@NL@%
- register int interval;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- %@NL@%
- for (i = 0; i < MAXLINE; i++)%@NL@%
- Tabstops[i] = (i % interval == 0) ? 1 : 0;%@NL@%
- } %@AB@%/* end fixtabs() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vartabs -- set up variable tabstops from an array%@NL@%
- %@AB@% * integers terminated by a -1 entry%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void%@NL@%
- vartabs(list)%@NL@%
- int *list;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- %@NL@%
- %@AB@%/* initialize the tabstop array */%@AE@%%@NL@%
- for (i = 0; i < MAXLINE; ++i)%@NL@%
- Tabstops[i] = 0;%@NL@%
- %@NL@%
- %@AB@%/* set user-sprcified tabstops */%@AE@%%@NL@%
- while (*list != -1)%@NL@%
- Tabstops[*++list] = 1;%@NL@%
- } %@AB@%/* end vartabs() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * tabstop -- return non-zero if col is a tabstop%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int%@NL@%
- tabstop(col)%@NL@%
- register int col;%@NL@%
- {%@NL@%
- return (col >= MAXLINE ? 1 : Tabstops[col]);%@NL@%
- } %@AB@%/* end tabstop() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TEE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\TEE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * tee -- a "pipe fitter" for DOS%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- register int ch, n;%@NL@%
- static char openmode[] = { "w" };%@NL@%
- static char pgm[MAXPATH + 1] = { "tee" };%@NL@%
- FILE *fp[_NFILE]; %@AB@%/* array of file pointers */%@AE@%%@NL@%
- %@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind, opterr;%@NL@%
- extern char *optarg;%@NL@%
- extern void getpname(char *, char *);%@NL@%
- %@NL@%
- %@AB@%/* check for an alias */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(argv[0], pgm);%@NL@%
- %@NL@%
- %@AB@%/* process command-line options, if any */%@AE@%%@NL@%
- while ((ch = getopt(argc, argv, "a")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 'a':%@NL@%
- strcpy(openmode, "a");%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- break;%@NL@%
- }%@NL@%
- n = argc -= optind;%@NL@%
- argv += optind;%@NL@%
- %@NL@%
- %@AB@%/* check for errors */%@AE@%%@NL@%
- if (argc > _NFILE) {%@NL@%
- fprintf(stderr, "Too many files (max = %d)\n", _NFILE);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* open the output file(s) */%@AE@%%@NL@%
- for (n = 0; n < argc; ++n) {%@NL@%
- if ((fp[n] = fopen(argv[n], openmode)) == NULL) {%@NL@%
- fprintf(stderr, "Cannot open %s\n", argv[n]);%@NL@%
- continue;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* copy input to stdout plus opened file(s) */%@AE@%%@NL@%
- while ((ch = getchar()) != EOF) {%@NL@%
- putchar(ch);%@NL@%
- for (n = 0; n < argc; ++n)%@NL@%
- if (fp[n] != NULL)%@NL@%
- fputc(ch, fp[n]);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* close file(s) */%@AE@%%@NL@%
- if (fcloseall() == -1) {%@NL@%
- fprintf(stderr, "Error closing a file\n");%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TIMEDATA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\04STDLIB\TIMEDATA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * timedata -- time zone and time value tests%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- long now;%@NL@%
- struct tm *tbuf;%@NL@%
- %@NL@%
- %@AB@%/* get TZ data into global variables */%@AE@%%@NL@%
- tzset();%@NL@%
- %@NL@%
- %@AB@%/* display the global time values */%@AE@%%@NL@%
- printf("daylight savings time flag = %d\n", daylight);%@NL@%
- printf("difference (in seconds) from GMT = %ld\n", timezone);%@NL@%
- printf("standard time zone string is %s\n", tzname[0]);%@NL@%
- printf("daylight time zone string is %s\n", tzname[1]);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * display the current date and time values for%@NL@%
- %@AB@% * local and universal time%@NL@%
- %@AB@% */%@AE@%%@NL@%
- now = time(NULL);%@NL@%
- printf("\nctime():\t%s\n", ctime(&now));%@NL@%
- tbuf = localtime(&now);%@NL@%
- printf("local time:\t%s\n", asctime(tbuf));%@NL@%
- tbuf = gmtime(&now);%@NL@%
- printf("universal time:\t%s\n", asctime(tbuf));%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TIMER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\TIMER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * timer -- general purpose timer program; uses the%@NL@%
- %@AB@% * PC's intra-application communication area (ICA) as%@NL@%
- %@AB@% * a time and date buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NBYTES 16 %@NL@%
- %@AI@%#define %@AE@%ICA_SEG 0x4F %@NL@%
- %@AI@%#define %@AE@%MAXTNUM 3 %@NL@%
- %@AI@%#define %@AE@%TIMEMASK 0x3FFFFFFF %@NL@%
- %@AI@%#define %@AE@%FLAGBIT 0x80000000 %@NL@%
- %@AI@%#define %@AE@%IDBIT 0x40000000 %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int ch;%@NL@%
- char *cp; %@NL@%
- int tn; %@AB@%/* timer number */%@AE@%%@NL@%
- int errflag; %@AB@%/* error flag */%@AE@%%@NL@%
- int eflag; %@AB@%/* elapsed time flag */%@AE@%%@NL@%
- int sflag; %@AB@%/* start timer flag */%@AE@%%@NL@%
- char dest[MAXPATH + 1]; %@AB@%/* destination file name */%@AE@%%@NL@%
- char timestr[MAXLINE]; %@AB@%/* buffer for elapsed time string */%@AE@%%@NL@%
- long now; %@AB@%/* current time */%@AE@%%@NL@%
- long then; %@AB@%/* previously recorded time */%@AE@%%@NL@%
- FILE *fout;%@NL@%
- unsigned long tdata[MAXTNUM];%@NL@%
- %@NL@%
- struct SREGS segregs;%@NL@%
- %@NL@%
- static char pgm[MAXNAME + 1] = { "timer" };%@NL@%
- %@NL@%
- static void usage(char *, char *);%@NL@%
- extern char interval(long, char *);%@NL@%
- extern char *getpname(char *, char *);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind, opterr;%@NL@%
- extern char *optarg;%@NL@%
- %@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* process optional arguments */%@AE@%%@NL@%
- fout = stdout;%@NL@%
- tn = 0;%@NL@%
- errflag = eflag = sflag = 0;%@NL@%
- while ((ch = getopt(argc, argv, "0123ef:s")) != EOF) {%@NL@%
- switch (ch) {%@NL@%
- case 'e':%@NL@%
- %@AB@%/* report elapsed timing */%@AE@%%@NL@%
- ++eflag;%@NL@%
- break;%@NL@%
- case 'f':%@NL@%
- %@AB@%/* use specified log file or stream */%@AE@%%@NL@%
- strcpy(dest, optarg);%@NL@%
- if ((fout = fopen(dest, "a")) == NULL) {%@NL@%
- fprintf(stderr, "%s: Cannot open %s\n",%@NL@%
- pgm, dest);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- break;%@NL@%
- case 's':%@NL@%
- %@AB@%/* start (or restart) timing an interval */%@AE@%%@NL@%
- ++sflag;%@NL@%
- break;%@NL@%
- case '0':%@NL@%
- case '1':%@NL@%
- case '2':%@NL@%
- case '3':%@NL@%
- %@AB@%/* use specified timer */%@AE@%%@NL@%
- tn = ch - 0x30;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* bad option flag */%@AE@%%@NL@%
- ++errflag;%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- %@NL@%
- %@AB@%/* check for errors */%@AE@%%@NL@%
- if (errflag > 0 || argc > 0) %@NL@%
- usage(pgm, "Bad command line option(s)");%@NL@%
- %@NL@%
- segread(&segregs);%@NL@%
- %@NL@%
- %@AB@%/* report current date and time */%@AE@%%@NL@%
- now = time(NULL);%@NL@%
- fprintf(fout, "%s", ctime(&now));%@NL@%
- %@NL@%
- %@AB@%/* control and report timer data */%@AE@%%@NL@%
- if (eflag) {%@NL@%
- %@AB@%/* report elapsed time for specified timer */%@AE@%%@NL@%
- movedata(ICA_SEG, 0, segregs.ds, tdata, NBYTES);%@NL@%
- then = tdata[tn];%@NL@%
- if ((then & FLAGBIT) != FLAGBIT || (then & IDBIT) != IDBIT) {%@NL@%
- fprintf(stderr, "Timer database corrupted or not set\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- interval(now - (then & TIMEMASK), timestr);%@NL@%
- fprintf(stdout, "Elapsed time = %s\n", timestr);%@NL@%
- }%@NL@%
- if (sflag) {%@NL@%
- %@AB@%/* start (or restart) specified timer */%@AE@%%@NL@%
- movedata(ICA_SEG, 0, segregs.ds, tdata, NBYTES);%@NL@%
- tdata[tn] = (now & TIMEMASK) | FLAGBIT | IDBIT;%@NL@%
- movedata(segregs.ds, tdata, ICA_SEG, 0, NBYTES);%@NL@%
- }%@NL@%
- fputc('\n', fout);%@NL@%
- %@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * usage -- display a usage message and exit%@NL@%
- %@AB@% * with an error indication%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- usage(pname, mesg)%@NL@%
- char *pname;%@NL@%
- char *mesg;%@NL@%
- {%@NL@%
- fprintf(stderr, "%s\n", mesg);%@NL@%
- fprintf(stderr, "Usage: %s [-efs#]\n", pname);%@NL@%
- fprintf(stderr, "\t-e \tshow an elapsed time (must use start first)\n");%@NL@%
- fprintf(stderr, "\t-f file\tappend output to specified file\n");%@NL@%
- fprintf(stderr, "\t-s \tstart (or restart) an interval timer\n");%@NL@%
- fprintf(stderr, "\t-# \tselect a timer (0 to 3; default is 0)\n");%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TONE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\TONE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * tone -- set the frequency of the sound generator%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- extern void setfreq(unsigned int);%@NL@%
- %@NL@%
- if (argc != 2) {%@NL@%
- fprintf(stderr, "Usage: tone hertz\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* set the frequency in Hertz */%@AE@%%@NL@%
- setfreq(atoi(*++argv));%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TOUCH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\08FILE\TOUCH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * touch -- update modification time of file(s)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<sys\utime.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<errno.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AB@%/* error return -- big enough not to be mistaken for a bad file count */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ERR 0x7FFF %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int ch;%@NL@%
- int i;%@NL@%
- int badcount; %@AB@%/* # of files that can't be updated */%@AE@%%@NL@%
- struct stat statbuf; %@AB@%/* buffer for stat results */%@AE@%%@NL@%
- BOOLEAN errflag, %@AB@%/* error flag */%@AE@%%@NL@%
- cflag, %@AB@%/* creation flag */%@AE@%%@NL@%
- vflag; %@AB@%/* verbose flag */%@AE@%%@NL@%
- FILE *fp;%@NL@%
- %@NL@%
- static char pgm[MAXNAME + 1] = { "touch" };%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int optind, opterr;%@NL@%
- extern char *optarg;%@NL@%
- extern void getpname(char *, char *);%@NL@%
- static void usage(char *);%@NL@%
- %@NL@%
- %@AB@%/* get program name from DOS (version 3.00 and later) */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(argv[0], pgm);%@NL@%
- %@NL@%
- %@AB@%/* process optional arguments first */%@AE@%%@NL@%
- errflag = cflag = vflag = FALSE;%@NL@%
- badcount = 0;%@NL@%
- while ((ch = getopt(argc, argv, "cv")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 'c':%@NL@%
- %@AB@%/* don't create files */%@AE@%%@NL@%
- cflag = TRUE;%@NL@%
- break;%@NL@%
- case 'v':%@NL@%
- %@AB@%/* verbose -- report activity */%@AE@%%@NL@%
- vflag = TRUE;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- %@NL@%
- %@AB@%/* check for errors including no file names */%@AE@%%@NL@%
- if (errflag == TRUE || argc <= 0) {%@NL@%
- usage(pgm);%@NL@%
- exit(ERR);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* update modification times of files */%@AE@%%@NL@%
- for (; argc-- > 0; ++argv) {%@NL@%
- if (stat(*argv, &statbuf) == -1) {%@NL@%
- %@AB@%/* file doesn't exist */%@AE@%%@NL@%
- if (cflag == TRUE) {%@NL@%
- %@AB@%/* don't create it */%@AE@%%@NL@%
- ++badcount;%@NL@%
- continue;%@NL@%
- }%@NL@%
- else if ((fp = fopen(*argv, "w")) == NULL) {%@NL@%
- fprintf(stderr, "%s: Cannot create %s\n",%@NL@%
- pgm, *argv);%@NL@%
- ++badcount;%@NL@%
- continue;%@NL@%
- }%@NL@%
- else {%@NL@%
- if (fclose(fp) == EOF) {%@NL@%
- perror("Error closing file");%@NL@%
- exit(ERR);%@NL@%
- }%@NL@%
- if (stat(*argv, &statbuf) == -1) {%@NL@%
- fprintf(stderr, "%s: Cannot stat %s\n", pgm, *argv);%@NL@%
- ++badcount;%@NL@%
- continue;%@NL@%
- }%@NL@%
- }%@NL@%
- } %@NL@%
- if (utime(*argv, NULL) == -1) {%@NL@%
- ++badcount;%@NL@%
- perror("Error updating date/time stamp");%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (vflag == TRUE)%@NL@%
- fprintf(stderr, "Touched file %s\n", *argv);%@NL@%
- }%@NL@%
- %@NL@%
- exit(badcount);%@NL@%
- } %@AB@%/* end main() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * usage -- display an informative usage message%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- usage(pname)%@NL@%
- char *pname;%@NL@%
- {%@NL@%
- fprintf(stderr, "Usage: %s [-cv] file ...\n", pname);%@NL@%
- fprintf(stderr, "\t-c Do not create any files\n");%@NL@%
- fprintf(stderr, "\t-v Verbose mode -- report activities\n");%@NL@%
- } %@AB@%/* end usage() */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * dummy functions to show how to save a little space%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- _setenvp()%@NL@%
- {%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#ifndef %@AE@%DEBUG %@NL@%
- _nullcheck()%@NL@%
- {%@NL@%
- }%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TSTREPLY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\06USER\TSTREPLY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * tstreply -- test the getreply function%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%"linebuf.h" %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INPUT_ROW 0 %@NL@%
- %@AI@%#define %@AE@%INPUT_COL 40 %@NL@%
- %@AI@%#define %@AE@%WIDTH 40 %@NL@%
- %@NL@%
- int Apage = 0;%@NL@%
- BOOLEAN Silent = FALSE;%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- unsigned int r, c, ch, attr, revattr;%@NL@%
- char reply[MAXPATH + 1];%@NL@%
- LINEBUF buf;%@NL@%
- %@NL@%
- extern char *getreply(short, short, short,%@NL@%
- char *, LINEBUF *, short, short, short);%@NL@%
- %@NL@%
- %@AB@%/* process command line */%@AE@%%@NL@%
- if (argc == 2 && strcmp(argv[1], "-s") == 0)%@NL@%
- Silent = TRUE;%@NL@%
- else if (argc > 2) {%@NL@%
- fprintf(stderr, "Usage: tstreply [-s]\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* initial setup */%@AE@%%@NL@%
- getstate();%@NL@%
- readca(&ch, &attr, Apage);%@NL@%
- revattr = ((attr << 4) | (attr >> 4)) & 0x77;%@NL@%
- clrscrn(attr);%@NL@%
- putcur(0, 0, Apage);%@NL@%
- writestr("TSTREPLY", Apage);%@NL@%
- putcur(1, 0, Apage);%@NL@%
- writec(HLINE, Maxcol[Vmode] - 1, Apage);%@NL@%
- buf.l_buf = reply;%@NL@%
- buf.l_next = buf.l_prev = (LINEBUF *)NULL;%@NL@%
- %@NL@%
- %@AB@%/* demo getreply() */%@AE@%%@NL@%
- %@NL@%
- if (getreply(INPUT_ROW, INPUT_COL, WIDTH, "File: ", &buf,%@NL@%
- MAXPATH, revattr, 0) == NULL) {%@NL@%
- putcur(INPUT_ROW, INPUT_COL, Apage);%@NL@%
- writeca(' ', attr, WIDTH, Apage);%@NL@%
- putcur(2, 0, Apage);%@NL@%
- fprintf(stderr, "input aborted\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- putcur(INPUT_ROW, INPUT_COL, Apage);%@NL@%
- writeca(' ', attr, WIDTH, Apage);%@NL@%
- putcur(2, 0, Apage);%@NL@%
- fprintf(stderr, "reply = %s\n", reply);%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MSG_ROW 24 %@NL@%
- %@AI@%#define %@AE@%MSG_COL 0 %@NL@%
- %@NL@%
- int%@NL@%
- errmsg(mesg)%@NL@%
- char *mesg;%@NL@%
- {%@NL@%
- int n;%@NL@%
- extern void sound(unsigned int, float);%@NL@%
- %@NL@%
- putcur(MSG_ROW, MSG_COL, Apage);%@NL@%
- if ((n = strlen(mesg)) > 0) {%@NL@%
- writestr(mesg, Apage);%@NL@%
- if (Silent == FALSE)%@NL@%
- sound(100, 0.2);%@NL@%
- }%@NL@%
- else%@NL@%
- writec(' ', Maxcol[Vmode] - 1 - MSG_COL, Apage);%@NL@%
- return (n);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TSTSEL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\07CONFIG\TSTSEL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * tstsel -- test driver for the "select" functions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXTEST 20 %@NL@%
- %@AI@%#define %@AE@%NRANGES 10 %@NL@%
- %@AI@%#define %@AE@%NDIGITS 5 %@NL@%
- %@NL@%
- extern struct slist_st {%@NL@%
- long int s_min;%@NL@%
- long int s_max;%@NL@%
- } Slist[NRANGES + 1];%@NL@%
- %@NL@%
- main (argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int i;%@NL@%
- extern int mkslist(char *);%@NL@%
- extern int selected(unsigned int);%@NL@%
- static void showlist();%@NL@%
- %@NL@%
- if (argc != 2) {%@NL@%
- fprintf(stderr, "Usage: tstsel list\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- printf("argv[1] = %s\n", argv[1]);%@NL@%
- mkslist(argv[1]);%@NL@%
- showlist();%@NL@%
- for (i = 0; i < MAXTEST; ++i)%@NL@%
- printf("%2d -> %s\n", i, selected(i) ? "YES" : "NO");%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showlist -- display the contents of the select list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- static void%@NL@%
- showlist()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* scan the selection list and display values */%@AE@%%@NL@%
- for (i = 0; i <= NRANGES; ++i)%@NL@%
- printf("%2d %5ld %5ld\n", i, Slist[i].s_min, Slist[i].s_max);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%USERATTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\13ANSI\USERATTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * userattr -- set video attributes to user-specified values%@NL@%
- %@AB@% * (DOS environment parameters) or to reasonable defaults and%@NL@%
- %@AB@% * return success or a failure indication for bad attributes%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\ansi.h> %@NL@%
- %@AI@%#include %@AE@%<local\ibmcolor.h> %@NL@%
- %@NL@%
- int%@NL@%
- userattr(foreground, background, border)%@NL@%
- char *foreground, *background, *border;%@NL@%
- {%@NL@%
- register char *s;%@NL@%
- static int attrset(POSITION, char *);%@NL@%
- %@NL@%
- if ((s = getenv("FGND")) == NULL)%@NL@%
- s = foreground;%@NL@%
- if (attrset(FGND, s) == -1)%@NL@%
- return FAILURE;%@NL@%
- %@NL@%
- if ((s = getenv("BKGND")) == NULL)%@NL@%
- s = background;%@NL@%
- if (attrset(BKGND, s) == -1)%@NL@%
- return FAILURE;%@NL@%
- %@NL@%
- if ((s = getenv("BORDER")) == NULL)%@NL@%
- s = border;%@NL@%
- if (attrset(BDR, s) == -1)%@NL@%
- return FAILURE;%@NL@%
- %@NL@%
- return SUCCESS;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * attrset -- parse the color spec and try to set it.%@NL@%
- %@AB@% * return 0 if OK and -1 upon error (bad color number)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- static int%@NL@%
- attrset(apos, str)%@NL@%
- POSITION apos;%@NL@%
- register char *str;%@NL@%
- {%@NL@%
- register int attr;%@NL@%
- extern int colornum(char *);%@NL@%
- extern void setattr(POSITION, int);%@NL@%
- %@NL@%
- if ((attr = colornum(strtok(str, " \t"))) == IBM_BRIGHT)%@NL@%
- attr |= colornum(strtok(NULL, " \t"));%@NL@%
- if (attr >= 0)%@NL@%
- setattr(apos, attr);%@NL@%
- else%@NL@%
- return (-1);%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\DOS\VER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * ver -- get the MS-DOS (or PC-DOS) version number%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\doslib.h> %@NL@%
- %@NL@%
- %@AB@%/************************************************************%@NL@%
- %@AB@%* For MS-DOS versions prior to 2.00, the low byte (AL) of%@NL@%
- %@AB@%* the return value is zero. For versions 2.00 and beyond,%@NL@%
- %@AB@%* the low byte is the major version number and the high%@NL@%
- %@AB@%* byte (AH) is the minor version number.%@NL@%
- %@AB@%************************************************************/%@AE@%%@NL@%
- %@NL@%
- int ver()%@NL@%
- {%@NL@%
- return(bdos(DOS_VERSION, 0, 0));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\VF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf -- view a file using a full-screen window onto%@NL@%
- %@AB@% * an in-memory text file buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%"vf.h" %@NL@%
- %@NL@%
- extern int setctype(int, int);%@NL@%
- int Startscan, Endscan; %@AB@%/* cursor scan line range */%@AE@%%@NL@%
- unsigned char Attr; %@AB@%/* primary display attribute */%@AE@%%@NL@%
- unsigned char Revattr; %@AB@%/* reverse video for highlighting */%@AE@%%@NL@%
- unsigned char Usrattr; %@AB@%/* user's original attribute */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char **argv;%@NL@%
- {%@NL@%
- int ch;%@NL@%
- unsigned char chr;%@NL@%
- BOOLEAN errflag;%@NL@%
- BOOLEAN numbers;%@NL@%
- int errcode;%@NL@%
- FILE *fp;%@NL@%
- extern char *optarg;%@NL@%
- extern int optind;%@NL@%
- static char pgm[MAXNAME + 1] = { "vf" };%@NL@%
- %@NL@%
- %@AB@%/* function prototypes */%@AE@%%@NL@%
- void clean();%@NL@%
- extern clrscrn(unsigned char);%@NL@%
- extern void getpname(char *, char *);%@NL@%
- extern void fixtabs(int);%@NL@%
- extern void initmsg(int, int, int, unsigned char, int);%@NL@%
- extern int getopt(int, char **, char *);%@NL@%
- extern int vf_cmd(FILE *, char *, BOOLEAN);%@NL@%
- extern int readca(unsigned char *, unsigned char *, unsigned int);%@NL@%
- extern int getctype(int *, int *, int);%@NL@%
- %@NL@%
- errcode = 0;%@NL@%
- fixtabs(TABWIDTH);%@NL@%
- %@NL@%
- %@AB@%/* get program name from DOS (version 3.00 and later) */%@AE@%%@NL@%
- if (_osmajor >= 3)%@NL@%
- getpname(*argv, pgm);%@NL@%
- %@NL@%
- %@AB@%/* be sure we have needed DOS support */%@AE@%%@NL@%
- if (_osmajor < 2) {%@NL@%
- fprintf(stderr, "%s requires DOS 2.00 or later\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* process optional arguments first */%@AE@%%@NL@%
- errflag = numbers = FALSE;%@NL@%
- while ((ch = getopt(argc, argv, "n")) != EOF)%@NL@%
- switch (ch) {%@NL@%
- case 'n':%@NL@%
- %@AB@%/* turn on line numbering */%@AE@%%@NL@%
- numbers = TRUE;%@NL@%
- break;%@NL@%
- case '?':%@NL@%
- %@AB@%/* bad option */%@AE@%%@NL@%
- errflag = TRUE;%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* check for command-line errors */%@AE@%%@NL@%
- argc -= optind;%@NL@%
- argv += optind;%@NL@%
- if (errflag == TRUE || argc == 0) {%@NL@%
- fprintf(stderr, "Usage: %s [-n] file...\n", pgm);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* get current video attribute and set VF attributes */%@AE@%%@NL@%
- getstate();%@NL@%
- readca(&chr, &Usrattr, Vpage); %@AB@%/* save user's attribute settings */%@AE@%%@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * These colors are modified from those presented in the%@NL@%
- %@AB@% * book so that VF will work on all monochrome and%@NL@%
- %@AB@% * color systems the same way -- change them to suit%@NL@%
- %@AB@% * your own shade of reality and operating conditions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Attr = Usrattr; %@AB@%/* basic text attributes */%@AE@%%@NL@%
- %@AB@%/* reverse video for highlighting */%@AE@%%@NL@%
- Revattr = ((Attr & 0x7) << 4) | (Attr >> 4);%@NL@%
- clrscrn(Attr);%@NL@%
- %@NL@%
- %@AB@%/* save user's cursor shape and turn cursor off */%@AE@%%@NL@%
- getctype(&Startscan, &Endscan, Vpage);%@NL@%
- setctype(MAXSCAN, MAXSCAN);%@NL@%
- %@NL@%
- %@AB@%/* set up the message line manager */%@AE@%%@NL@%
- initmsg(MSGROW, MSGCOL, Maxcol[Vmode] - MSGCOL, Attr, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* display first screen page */%@AE@%%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- putstr("ViewFile/1.0 H=Help Q=Quit Esc=Next", Vpage);%@NL@%
- putcur(1, 0, Vpage);%@NL@%
- writea(Revattr, Maxcol[Vmode], Vpage);%@NL@%
- %@NL@%
- for (; argc-- > 0; ++argv) {%@NL@%
- if ((fp = fopen(*argv, "r")) == NULL) {%@NL@%
- fprintf(stderr, "%s: cannot open %s -- ", pgm, *argv);%@NL@%
- perror("");%@NL@%
- ++errcode;%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (vf_cmd(fp, *argv, numbers) != 0)%@NL@%
- break;%@NL@%
- fclose(fp);%@NL@%
- }%@NL@%
- clean();%@NL@%
- exit(errcode);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * clean -- restore the user's original conditions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- void%@NL@%
- clean()%@NL@%
- {%@NL@%
- %@AB@%/* set screen to user's attribute */%@AE@%%@NL@%
- clrscrn(Usrattr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* restore user's cursor shape */%@AE@%%@NL@%
- setctype(Startscan, Endscan);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VF_CMD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\VF_CMD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_cmd -- ViewFile command processor%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%"vf.h" %@NL@%
- %@AI@%#include %@AE@%"message.h" %@NL@%
- %@NL@%
- extern unsigned char Attr;%@NL@%
- %@NL@%
- int%@NL@%
- vf_cmd(fp, fname, numbers)%@NL@%
- FILE *fp;%@NL@%
- char *fname;%@NL@%
- BOOLEAN numbers;%@NL@%
- {%@NL@%
- register int i; %@AB@%/* general index */%@AE@%%@NL@%
- unsigned int offset; %@AB@%/* horizontal scroll offset */%@AE@%%@NL@%
- unsigned int n; %@AB@%/* relative line number */%@AE@%%@NL@%
- int memerr; %@AB@%/* flag for memory allocation errors */%@AE@%%@NL@%
- char *s, lbuf[MAXLINE]; %@AB@%/* input line buffer and pointer */%@AE@%%@NL@%
- int k; %@AB@%/* key code (see keydefs.h) */%@AE@%%@NL@%
- int radix = 10; %@AB@%/* base for number-to-character conversions */%@AE@%%@NL@%
- char number[17]; %@AB@%/* buffer for conversions */%@AE@%%@NL@%
- int errcount = 0; %@AB@%/* error counter */%@AE@%%@NL@%
- DNODE *tmp; %@AB@%/* pointer to buffer control nodes */%@AE@%%@NL@%
- DIRECTION srchdir; %@AB@%/* search direction */%@AE@%%@NL@%
- char *ss; %@AB@%/* pointer to search string */%@AE@%%@NL@%
- static char srchstr[MAXSTR] = { "" }; %@AB@%/* search string buffer */%@AE@%%@NL@%
- DNODE *head; %@AB@%/* pointer to starting node of text buffer list */%@AE@%%@NL@%
- DNODE *current; %@AB@%/* pointer to the current node (text line) */%@AE@%%@NL@%
- static DNODE *freelist; %@AB@%/* pointer to starting node of "free" list */%@AE@%%@NL@%
- %@AB@%/* initialized to 0 at runtime; retains value */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* function prototypes */%@AE@%%@NL@%
- static void prtshift(int, int);%@NL@%
- extern DNODE *vf_mklst();%@NL@%
- extern DNODE *vf_alloc(int);%@NL@%
- extern DNODE *vf_ins(DNODE *, DNODE *);%@NL@%
- extern DNODE *vf_del(DNODE *, DNODE *);%@NL@%
- extern DNODE *search(DNODE *, DIRECTION, char *);%@NL@%
- extern DNODE *gotoln(DNODE *);%@NL@%
- extern char *getxline(char *, int, FILE *);%@NL@%
- extern char *getsstr(char *);%@NL@%
- extern int clrscrn(unsigned char);%@NL@%
- extern void showhelp(unsigned char);%@NL@%
- extern void clrmsg();%@NL@%
- extern void vf_dspy(DNODE *, DNODE *, int, BOOLEAN);%@NL@%
- extern int putstr(char *, int);%@NL@%
- extern int writec(char, int, int);%@NL@%
- extern char *nlerase(char *);%@NL@%
- %@NL@%
- %@AB@%/* display the file name */%@AE@%%@NL@%
- offset = 0;%@NL@%
- putcur(HEADROW, 0, Vpage);%@NL@%
- writec(' ', Maxcol[Vmode], Vpage);%@NL@%
- putstr("File: ", Vpage);%@NL@%
- putstr(fname, Vpage);%@NL@%
- %@NL@%
- %@AB@%/* establish the text buffer */%@AE@%%@NL@%
- memerr = 0;%@NL@%
- if ((head = vf_mklst()) == NULL)%@NL@%
- ++memerr;%@NL@%
- if (freelist == NULL && (freelist = vf_alloc(N_NODES)) == NULL)%@NL@%
- ++memerr;%@NL@%
- if (memerr) {%@NL@%
- clean();%@NL@%
- fprintf(stderr, "Memory allocation error\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* read the file into the buffer */%@AE@%%@NL@%
- current = head;%@NL@%
- n = 0;%@NL@%
- while ((s = getxline(lbuf, MAXLINE, fp)) != NULL) {%@NL@%
- %@AB@%/* add a node to the list */%@AE@%%@NL@%
- if ((freelist = vf_ins(current, freelist)) == NULL)%@NL@%
- ++memerr;%@NL@%
- current = current->d_next;%@NL@%
- %@NL@%
- %@AB@%/* save the received text in a line buffer */%@AE@%%@NL@%
- if ((current->d_line = strdup(nlerase(s))) == NULL)%@NL@%
- ++memerr;%@NL@%
- if (memerr) {%@NL@%
- clean();%@NL@%
- fprintf(stderr, "File too big to load\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- current->d_lnum = ++n;%@NL@%
- current->d_flags = 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* show the file size as a count of lines */%@AE@%%@NL@%
- putstr(" (", Vpage);%@NL@%
- putstr(itoa(current->d_lnum, number, radix), Vpage);%@NL@%
- putstr(" lines)", Vpage);%@NL@%
- prtshift(offset, Vpage);%@NL@%
- current = head->d_next;%@NL@%
- vf_dspy(head, current, offset, numbers);%@NL@%
- %@NL@%
- %@AB@%/* process user commands */%@AE@%%@NL@%
- while ((k = getkey()) != K_ESC) {%@NL@%
- clrmsg();%@NL@%
- switch (k) {%@NL@%
- case 'b':%@NL@%
- case 'B':%@NL@%
- case K_HOME:%@NL@%
- current = head->d_next;%@NL@%
- break;%@NL@%
- case 'e':%@NL@%
- case 'E':%@NL@%
- case K_END:%@NL@%
- current = head->d_prev;%@NL@%
- i = NROWS - 1;%@NL@%
- while (i-- > 0)%@NL@%
- if (current->d_prev != head->d_next)%@NL@%
- current = current->d_prev;%@NL@%
- break;%@NL@%
- case K_PGUP:%@NL@%
- case 'u':%@NL@%
- case 'U':%@NL@%
- i = NROWS - OVERLAP;%@NL@%
- while (i-- > 0)%@NL@%
- if (current != head->d_next)%@NL@%
- current = current->d_prev;%@NL@%
- break;%@NL@%
- case K_PGDN:%@NL@%
- case 'd':%@NL@%
- case 'D':%@NL@%
- i = NROWS - OVERLAP;%@NL@%
- while (i-- > 0)%@NL@%
- if (current != head->d_prev)%@NL@%
- current = current->d_next;%@NL@%
- break;%@NL@%
- case K_UP:%@NL@%
- case '-':%@NL@%
- if (current == head->d_next)%@NL@%
- continue;%@NL@%
- current = current->d_prev;%@NL@%
- break;%@NL@%
- case K_DOWN:%@NL@%
- case '+':%@NL@%
- if (current == head->d_prev)%@NL@%
- continue;%@NL@%
- current = current->d_next;%@NL@%
- break;%@NL@%
- case K_RIGHT:%@NL@%
- case '>':%@NL@%
- case '.':%@NL@%
- if (offset < MAXLINE - SHIFTWIDTH)%@NL@%
- offset += SHIFTWIDTH;%@NL@%
- prtshift(offset, Vpage);%@NL@%
- break;%@NL@%
- case K_LEFT:%@NL@%
- case '<':%@NL@%
- case ',':%@NL@%
- if ((offset -= SHIFTWIDTH) < 0)%@NL@%
- offset = 0;%@NL@%
- prtshift(offset, Vpage);%@NL@%
- break;%@NL@%
- case K_ALTG:%@NL@%
- case 'g':%@NL@%
- case 'G':%@NL@%
- if ((tmp = gotoln(head)) == NULL)%@NL@%
- continue;%@NL@%
- current = tmp;%@NL@%
- break;%@NL@%
- case K_ALTH:%@NL@%
- case 'h':%@NL@%
- case 'H':%@NL@%
- case '?':%@NL@%
- showhelp(Attr);%@NL@%
- break;%@NL@%
- case K_ALTN:%@NL@%
- case 'n':%@NL@%
- case 'N':%@NL@%
- numbers = (numbers == TRUE) ? FALSE : TRUE;%@NL@%
- break;%@NL@%
- case K_ALTQ:%@NL@%
- case 'q':%@NL@%
- case 'Q':%@NL@%
- clrscrn(Attr);%@NL@%
- putcur(0, 0, Vpage);%@NL@%
- return (-1);%@NL@%
- case 'r':%@NL@%
- case 'R':%@NL@%
- case '\\':%@NL@%
- srchdir = BACKWARD;%@NL@%
- ss = getsstr(srchstr);%@NL@%
- if (ss == NULL)%@NL@%
- %@AB@%/* cancel search */%@AE@%%@NL@%
- break;%@NL@%
- if (strlen(ss) > 0)%@NL@%
- strcpy(srchstr, ss);%@NL@%
- if ((tmp = search(current, srchdir, srchstr)) == NULL)%@NL@%
- continue;%@NL@%
- current = tmp;%@NL@%
- break;%@NL@%
- case 's':%@NL@%
- case 'S':%@NL@%
- case '/':%@NL@%
- srchdir = FORWARD;%@NL@%
- ss = getsstr(srchstr);%@NL@%
- if (ss == NULL)%@NL@%
- %@AB@%/* cancel search */%@AE@%%@NL@%
- break;%@NL@%
- if (strlen(ss) > 0)%@NL@%
- strcpy(srchstr, ss);%@NL@%
- if ((tmp = search(current, srchdir, srchstr)) == NULL)%@NL@%
- continue;%@NL@%
- current = tmp;%@NL@%
- break;%@NL@%
- default:%@NL@%
- %@AB@%/* ignore all other keys */%@AE@%%@NL@%
- continue;%@NL@%
- }%@NL@%
- vf_dspy(head, current, offset, numbers);%@NL@%
- }%@NL@%
- clrmsg();%@NL@%
- %@NL@%
- %@AB@%/* release the allocated text buffer memory */%@AE@%%@NL@%
- while (head->d_next != head) {%@NL@%
- %@AB@%/* release text buffer */%@AE@%%@NL@%
- free(head->d_next->d_line);%@NL@%
- %@NL@%
- %@AB@%/* put node back on the freelist */%@AE@%%@NL@%
- freelist = vf_del(head->d_next, freelist);%@NL@%
- }%@NL@%
- %@AB@%/* release the list header node */%@AE@%%@NL@%
- free((char *)head);%@NL@%
- %@NL@%
- return (errcount);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * prtshift -- display the number of columns of horizontal shift%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%SHFTDSP 5 %@NL@%
- %@NL@%
- static void%@NL@%
- prtshift(amt, pg)%@NL@%
- int amt, pg;%@NL@%
- {%@NL@%
- char number[17];%@NL@%
- int radix = 10;%@NL@%
- %@NL@%
- %@AB@%/* clear the shift display area */%@AE@%%@NL@%
- putcur(1, Maxcol[Vmode] - 1 - SHFTDSP, pg);%@NL@%
- writec(' ', SHFTDSP, pg);%@NL@%
- %@NL@%
- %@AB@%/* display the new shift amount, if any */%@AE@%%@NL@%
- if (amt > 0) {%@NL@%
- putstr(itoa(amt, number, radix), pg);%@NL@%
- putstr("->", pg);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VF_DSPY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\VF_DSPY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_dspy -- display a screen page%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@AI@%#include %@AE@%"vf.h" %@NL@%
- %@NL@%
- %@AB@%/* number field width */%@AE@%%@NL@%
- %@AI@%#define %@AE@%NFW 8 %@NL@%
- %@NL@%
- void%@NL@%
- vf_dspy(buf, lp, os, numbers)%@NL@%
- DNODE *buf;%@NL@%
- register DNODE *lp;%@NL@%
- int os;%@NL@%
- BOOLEAN numbers;%@NL@%
- {%@NL@%
- register int i;%@NL@%
- int j;%@NL@%
- int textwidth;%@NL@%
- char *cp;%@NL@%
- char nbuf[NFW + 1];%@NL@%
- %@NL@%
- textwidth = Maxcol[Vmode];%@NL@%
- if (numbers == TRUE)%@NL@%
- textwidth -= NFW;%@NL@%
- %@NL@%
- for (i = 0; i < NROWS; ++i) {%@NL@%
- putcur(TOPROW + i, 0, Vpage);%@NL@%
- cp = lp->d_line;%@NL@%
- if (numbers == TRUE) {%@NL@%
- sprintf(nbuf, "%6u", lp->d_lnum);%@NL@%
- putfld(nbuf, NFW, Vpage);%@NL@%
- putcur(TOPROW + i, NFW, Vpage);%@NL@%
- }%@NL@%
- if (os < strlen(cp))%@NL@%
- putfld(cp + os, textwidth, Vpage);%@NL@%
- else%@NL@%
- writec(' ', textwidth, Vpage);%@NL@%
- if (lp == buf->d_prev) {%@NL@%
- ++i;%@NL@%
- break; %@AB@%/* no more displayable lines */%@AE@%%@NL@%
- }%@NL@%
- else%@NL@%
- lp = lp->d_next;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* clear and mark any unused lines */%@AE@%%@NL@%
- for ( ; i < NROWS; ++i) {%@NL@%
- putcur(i + TOPROW, 0, Vpage);%@NL@%
- writec(' ', Maxcol[Vmode], Vpage);%@NL@%
- writec('~', 1, Vpage);%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VF_LIST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\VF_LIST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_list -- linked list management functions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%"vf.h" %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_mklst -- create a new list by allocating a node,%@NL@%
- %@AB@% * making it point to itself, and setting its values%@NL@%
- %@AB@% * to zero (appropriately cast)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- DNODE *%@NL@%
- vf_mklst()%@NL@%
- {%@NL@%
- DNODE *new;%@NL@%
- %@NL@%
- new = (DNODE *)malloc(sizeof (DNODE));%@NL@%
- if (new != NULL) {%@NL@%
- new->d_next = new;%@NL@%
- new->d_prev = new;%@NL@%
- new->d_lnum = new->d_flags = 0;%@NL@%
- new->d_line = (char *)NULL;%@NL@%
- }%@NL@%
- return (new);%@NL@%
- } %@AB@%/* end vf_mklst() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_alloc -- create a pool of available nodes%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- DNODE *%@NL@%
- vf_alloc(n)%@NL@%
- int n;%@NL@%
- {%@NL@%
- register DNODE *new;%@NL@%
- register DNODE *tmp;%@NL@%
- %@NL@%
- %@AB@%/* allocate a block of n nodes */%@AE@%%@NL@%
- new = (DNODE *)malloc(n * sizeof (DNODE));%@NL@%
- %@NL@%
- %@AB@%/* if allocation OK, string the nodes in one direction */%@AE@%%@NL@%
- if (new != NULL) {%@NL@%
- for (tmp = new; 1 + tmp - new < n; tmp = tmp->d_next)%@NL@%
- tmp->d_next = tmp + 1;%@NL@%
- tmp->d_next = (DNODE *)NULL;%@NL@%
- }%@NL@%
- %@NL@%
- return (new); %@AB@%/* pointer to free list */%@AE@%%@NL@%
- } %@AB@%/* end vf_alloc() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_ins -- insert a node into a list after the specified node%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- DNODE *%@NL@%
- vf_ins(node, avail)%@NL@%
- DNODE *node, *avail;%@NL@%
- {%@NL@%
- DNODE *tmp;%@NL@%
- DNODE *vf_alloc(int);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * check freelist -- get another block of nodes%@NL@%
- %@AB@% * if the list is almost empty%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (avail->d_next == NULL)%@NL@%
- if ((avail->d_next = vf_alloc(N_NODES)) == NULL)%@NL@%
- %@AB@%/* not enough memory */%@AE@%%@NL@%
- return (DNODE *)NULL;%@NL@%
- %@NL@%
- %@AB@%/* get a node from the freelist */%@AE@%%@NL@%
- tmp = avail;%@NL@%
- avail = avail->d_next;%@NL@%
- %@NL@%
- %@AB@%/* insert the node into the list after node */%@AE@%%@NL@%
- tmp->d_prev = node;%@NL@%
- tmp->d_next = node->d_next;%@NL@%
- node->d_next->d_prev = tmp;%@NL@%
- node->d_next = tmp;%@NL@%
- %@NL@%
- %@AB@%/* point to next node in the freelist */%@AE@%%@NL@%
- return (avail);%@NL@%
- } %@AB@%/* end vf_ins() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_del -- delete a node from a list%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- DNODE *%@NL@%
- vf_del(node, avail)%@NL@%
- DNODE *node, *avail;%@NL@%
- {%@NL@%
- %@AB@%/* unlink the node from the list */%@AE@%%@NL@%
- node->d_prev->d_next = node->d_next;%@NL@%
- node->d_next->d_prev = node->d_prev;%@NL@%
- %@NL@%
- %@AB@%/* return the deleted node to the freelist */%@AE@%%@NL@%
- node->d_next = avail;%@NL@%
- avail = node;%@NL@%
- %@NL@%
- %@AB@%/* point to the new freelist node */%@AE@%%@NL@%
- return (avail);%@NL@%
- } %@AB@%/* end vf_del() */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VF_SRCH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\VF_SRCH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_srch -- search functions%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%"vf.h" %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * search -- search for a literal string in the buffer%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- DNODE *%@NL@%
- search(buf, dir, str)%@NL@%
- DNODE *buf;%@NL@%
- DIRECTION dir;%@NL@%
- char *str;%@NL@%
- {%@NL@%
- int n;%@NL@%
- register DNODE *lp;%@NL@%
- register char *cp;%@NL@%
- %@NL@%
- extern void showmsg(char *);%@NL@%
- %@NL@%
- %@AB@%/* try to find a match -- wraps around buffer boundaries */%@AE@%%@NL@%
- n = strlen(str);%@NL@%
- lp = (dir == FORWARD) ? buf->d_next : buf->d_prev;%@NL@%
- while (lp != buf) {%@NL@%
- if ((cp = lp->d_line) != NULL) %@AB@%/* skip over header node */%@AE@%%@NL@%
- while (*cp != '\n' && *cp != '\0') {%@NL@%
- if (strncmp(cp, str, n) == 0)%@NL@%
- return (lp);%@NL@%
- ++cp;%@NL@%
- }%@NL@%
- lp = (dir == FORWARD) ? lp->d_next : lp->d_prev;%@NL@%
- }%@NL@%
- showmsg("Not found");%@NL@%
- return ((DNODE *)NULL);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * getsstr -- prompt the user for a search string%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- extern int Startscan, Endscan;%@NL@%
- %@NL@%
- char *%@NL@%
- getsstr(str)%@NL@%
- char *str;%@NL@%
- {%@NL@%
- char line[MAXSTR];%@NL@%
- char *resp;%@NL@%
- %@NL@%
- extern int putstr(char *, int);%@NL@%
- extern char *getstr(char *, int);%@NL@%
- extern int put_ch(char, int);%@NL@%
- extern void showmsg(char *);%@NL@%
- extern void clrmsg();%@NL@%
- %@NL@%
- static char prompt[] = { "Search for: " };%@NL@%
- %@NL@%
- %@AB@%/* get search string */%@AE@%%@NL@%
- showmsg(prompt);%@NL@%
- setctype(Startscan, Endscan); %@AB@%/* cursor on */%@AE@%%@NL@%
- resp = getstr(line, MAXSTR - strlen(prompt));%@NL@%
- setctype(MAXSCAN, MAXSCAN); %@AB@%/* cursor off */%@AE@%%@NL@%
- if (resp == NULL)%@NL@%
- return (char *)NULL;%@NL@%
- if (strlen(resp) == 0)%@NL@%
- return (str);%@NL@%
- showmsg(resp);%@NL@%
- return (resp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VF_UTIL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\14VIEW\VF_UTIL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * vf_util -- utility functions for ViewFile%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\video.h> %@NL@%
- %@AI@%#include %@AE@%<local\keydefs.h> %@NL@%
- %@AI@%#include %@AE@%"vf.h" %@NL@%
- %@NL@%
- extern int Startscan, Endscan;%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NDIGITS 6 %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * gotoln -- jump to an absolute line number%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- DNODE *%@NL@%
- gotoln(buf)%@NL@%
- DNODE *buf;%@NL@%
- {%@NL@%
- register int ln;%@NL@%
- register DNODE *lp;%@NL@%
- char line[NDIGITS + 1];%@NL@%
- %@NL@%
- extern void showmsg(char *);%@NL@%
- extern char *getstr(char *, int);%@NL@%
- %@NL@%
- %@AB@%/* get line number from user */%@AE@%%@NL@%
- showmsg("Line number: ");%@NL@%
- setctype(Startscan, Endscan); %@AB@%/* cursor on */%@AE@%%@NL@%
- ln = atoi(getstr(line, NDIGITS + 1));%@NL@%
- setctype(MAXSCAN, MAXSCAN); %@AB@%/* cursor off */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* check boundary conditions */%@AE@%%@NL@%
- if (ln > buf->d_prev->d_lnum || ln <= 0) {%@NL@%
- showmsg("Line out of range");%@NL@%
- return ((DNODE *)NULL);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* find the line */%@AE@%%@NL@%
- for (lp = buf->d_next; ln != lp->d_lnum; lp = lp->d_next)%@NL@%
- ;%@NL@%
- return (lp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * showhelp -- display a help frame%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%HELPROW TOPROW + 3 %@NL@%
- %@AI@%#define %@AE@%HELPCOL 10 %@NL@%
- %@AI@%#define %@AE@%VBORDER 1 %@NL@%
- %@AI@%#define %@AE@%HBORDER 2 %@NL@%
- %@NL@%
- void%@NL@%
- showhelp(textattr)%@NL@%
- unsigned char textattr; %@AB@%/* attribute of text area */%@AE@%%@NL@%
- {%@NL@%
- register int i, n;%@NL@%
- int nlines, ncols;%@NL@%
- unsigned char helpattr;%@NL@%
- static char *help[] = {%@NL@%
- "PgUp (U) Scroll up the file one screen page",%@NL@%
- "PgDn (D) Scroll down the file one screen page",%@NL@%
- "Up arrow (-) Scroll up in the file one line",%@NL@%
- "Down arrow (+) Scroll down in the file one line",%@NL@%
- "Right arrow (>) Scroll right by 20 columns",%@NL@%
- "Left arrow (<) Scroll left by 20 columns",%@NL@%
- "Home (B) Go to beginning of file buffer",%@NL@%
- "End (E) Go to end of file buffer",%@NL@%
- "Alt-g (G) Go to a specified line in the buffer",%@NL@%
- "Alt-h (H or ?) Display this help frame",%@NL@%
- "Alt-n (N) Toggle line-numbering feature",%@NL@%
- "\\ (R) Reverse search for a literal text string",%@NL@%
- "/ (S) Search forward for a literal text string",%@NL@%
- "Esc Next file from list (quits if none)",%@NL@%
- "Alt-q (Q) Quit",%@NL@%
- "--------------------------------------------------------",%@NL@%
- " << Press a key to continue >>",%@NL@%
- (char *)NULL%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/* prepare help window */%@AE@%%@NL@%
- ncols = 0;%@NL@%
- for (i = 0; help[i] != (char *)NULL; ++i)%@NL@%
- if ((n = strlen(help[i])) > ncols)%@NL@%
- ncols = n;%@NL@%
- nlines = i - 1;%@NL@%
- --ncols;%@NL@%
- helpattr = (RED << 4) | BWHT;%@NL@%
- clrw(HELPROW - VBORDER, HELPCOL - HBORDER,%@NL@%
- HELPROW + nlines + VBORDER, HELPCOL + ncols + HBORDER,%@NL@%
- helpattr);%@NL@%
- drawbox(HELPROW - VBORDER, HELPCOL - HBORDER,%@NL@%
- HELPROW + nlines + VBORDER, HELPCOL + ncols + HBORDER,%@NL@%
- Vpage);%@NL@%
- %@NL@%
- %@AB@%/* display the help text */%@AE@%%@NL@%
- for (i = 0; help[i] != (char *)NULL; ++i) {%@NL@%
- putcur(HELPROW + i, HELPCOL, Vpage);%@NL@%
- putstr(help[i], Vpage);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* pause until told by a keypress to proceed */%@AE@%%@NL@%
- getkey();%@NL@%
- %@NL@%
- %@AB@%/* restore help display area to the text attribute */%@AE@%%@NL@%
- clrw(HELPROW - VBORDER, HELPCOL - HBORDER,%@NL@%
- HELPROW + nlines + VBORDER, HELPCOL + ncols + HBORDER,%@NL@%
- textattr);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WARN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\UTIL\WARN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * warn -- display a warning message in a highly%@NL@%
- %@AB@% * visible place; return number of characters written%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int%@NL@%
- warn(pname, mesg)%@NL@%
- char *pname, *mesg;%@NL@%
- {%@NL@%
- return (fprintf(stderr, "%s: %s\n", pname, mesg));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITEA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITEA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writea -- write attribute only to screen memory (faked by%@NL@%
- %@AB@% * reading char and attr and writing back the original%@NL@%
- %@AB@% * character and the new attribute at each position)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- int writea(a, n, pg)%@NL@%
- unsigned char a;%@AB@%/* video attribute */%@AE@%%@NL@%
- int n; %@AB@%/* number of positions to write */%@AE@%%@NL@%
- int pg; %@AB@%/* screen page */%@AE@%%@NL@%
- {%@NL@%
- int i;%@NL@%
- int status;%@NL@%
- unsigned short chx, attrx;%@NL@%
- unsigned short r, c;%@NL@%
- %@NL@%
- %@AB@%/* get starting (current) position */%@AE@%%@NL@%
- status = 0;%@NL@%
- status = readcur(&r, &c, pg);%@NL@%
- for (i = 0; i < n; ++i) {%@NL@%
- status += putcur(r, c + i, pg);%@NL@%
- status += readca(&chx, &attrx, pg);%@NL@%
- status += writeca(chx, a, 1, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* restore cursor position */%@AE@%%@NL@%
- status += putcur(r, c, pg);%@NL@%
- %@NL@%
- return (status);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITEC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITEC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writec -- write a character only%@NL@%
- %@AB@% * (leave attribute undisturbed)%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- writec(ch, count, pg)%@NL@%
- unsigned char ch; %@AB@%/* character */%@AE@%%@NL@%
- int count; %@AB@%/* repetitions */%@AE@%%@NL@%
- int pg; %@AB@%/* screen page for writes */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = WRITE_CHAR;%@NL@%
- inregs.h.al = ch;%@NL@%
- inregs.h.bh = pg;%@NL@%
- inregs.x.cx = count;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITECA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITECA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writeca -- write character and attribute to the screen%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- writeca(ch, attr, count, pg)%@NL@%
- unsigned char ch; %@AB@%/* character */%@AE@%%@NL@%
- unsigned char attr; %@AB@%/* attribute */%@AE@%%@NL@%
- int count; %@AB@%/* number of repetitions */%@AE@%%@NL@%
- int pg; %@AB@%/* screen page for writes */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = WRITE_CHAR_ATTR;%@NL@%
- inregs.h.al = ch;%@NL@%
- inregs.h.bh = pg;%@NL@%
- inregs.h.bl = attr;%@NL@%
- inregs.x.cx = count;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITEDOT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITEDOT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writedot -- display a dot at the specified position%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- writedot(r, c, color)%@NL@%
- int r, c; %@AB@%/* row and column cordinate */%@AE@%%@NL@%
- int color; %@AB@%/* dot (pixel) color */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = WRITE_DOT;%@NL@%
- inregs.h.al = color;%@NL@%
- inregs.x.cx = c;%@NL@%
- inregs.x.dx = r;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITEMSG.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITEMSG.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writemsg -- displays a message in a field of the prevailing%@NL@%
- %@AB@% * video attribute and returns the number of displayable message%@NL@%
- %@AB@% * characters written; truncates the message if its too long%@NL@%
- %@AB@% * to fit in the field%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- int writemsg(r, c, w, s1, s2, pg)%@NL@%
- int r, c, w ;%@NL@%
- char *s1, *s2;%@NL@%
- int pg;%@NL@%
- {%@NL@%
- int n = 0;%@NL@%
- char *cp;%@NL@%
- %@NL@%
- %@AB@%/* display first part of the message */%@AE@%%@NL@%
- if (s1 != NULL)%@NL@%
- for (cp = s1; *cp != '\0' && n < w; ++n, ++cp) {%@NL@%
- putcur(r, c + n, pg);%@NL@%
- writec(*cp, 1, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* display second part of the message */%@AE@%%@NL@%
- if (s2 != NULL)%@NL@%
- for (cp = s2; *cp != '\0' && n < w; ++n, ++cp) {%@NL@%
- putcur(r, c + n, pg);%@NL@%
- writec(*cp, 1, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* pad the remainder of the field, if any, with spaces */%@AE@%%@NL@%
- if (n < w) {%@NL@%
- putcur(r, c + n, pg);%@NL@%
- writec(' ', w - n, pg);%@NL@%
- }%@NL@%
- %@NL@%
- return (n);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITESTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITESTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writestr -- write a string in%@NL@%
- %@AB@% * the prevailing video attribute%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@NL@%
- int%@NL@%
- writestr(s, pg)%@NL@%
- register char *s; %@AB@%/* string to write */%@AE@%%@NL@%
- unsigned int pg; %@AB@%/* screen page for writes */%@AE@%%@NL@%
- {%@NL@%
- unsigned int r, c, c0;%@NL@%
- %@NL@%
- readcur(&r, &c, pg);%@NL@%
- for (c0 = c; *s != '\0'; ++s, ++c) {%@NL@%
- putcur(r, c, pg);%@NL@%
- writec(*s, 1, pg);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* restore cursor position and return # of characters displayed */%@AE@%%@NL@%
- putcur(r, c0, pg);%@NL@%
- return (c - c0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITETTY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\PROF_C\05OSLIB\BIOS\WRITETTY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * writetty -- write to screen using TTY interface%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<local\std.h> %@NL@%
- %@AI@%#include %@AE@%<local\bioslib.h> %@NL@%
- %@NL@%
- int%@NL@%
- writetty(ch, attr, pg)%@NL@%
- unsigned char ch; %@AB@%/* character */%@AE@%%@NL@%
- unsigned char attr; %@AB@%/* video attribute */%@AE@%%@NL@%
- int pg; %@AB@%/* screen page for writes */%@AE@%%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- %@NL@%
- inregs.h.ah = WRITE_TTY;%@NL@%
- inregs.h.al = ch;%@NL@%
- inregs.h.bl = attr;%@NL@%
- inregs.h.bh = pg;%@NL@%
- int86(VIDEO_IO, &inregs, &outregs);%@NL@%
- %@NL@%
- return (outregs.x.cflag);%@NL@%
- }%@NL@%
- %@1@%%@AH@%Quick-C Programming - Sample Code%@EH@%%@AE@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%12_10A.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\12_10A.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"texed.h" %@NL@%
- menu()%@NL@%
- {%@NL@%
- struct key_struct *kp, *Read_kbd();%@NL@%
- int cur_key, cur_move;%@NL@%
- %@NL@%
- kp = Read_kbd();%@NL@%
- cur_key = kp->key;%@NL@%
- cur_move = kp->move;%@NL@%
- if (cur_key == ERROR)%@NL@%
- return (cur_move);%@NL@%
- return (cur_key);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%12_10B.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\12_10B.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"texed.h" %@NL@%
- struct key_struct *Read_key()%@NL@%
- {%@NL@%
- struct key_struct k;%@NL@%
- %@NL@%
- k.key = getch();%@NL@%
- if (k.key == ERROR)%@NL@%
- k.move = getch();%@NL@%
- return (&k);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%12_8A.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\12_8A.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%OK 1 %@NL@%
- %@AI@%#define %@AE@%ERROR 0 %@NL@%
- menu()%@NL@%
- {%@NL@%
- struct key_struct {%@NL@%
- char key;%@NL@%
- unsigned char move;%@NL@%
- } *kp, *Read_kbd();%@NL@%
- int cur_key, cur_move;%@NL@%
- %@NL@%
- kp = Read_kbd();%@NL@%
- cur_key = kp->key;%@NL@%
- cur_move = kp->move;%@NL@%
- if (cur_key == ERROR)%@NL@%
- return (cur_move);%@NL@%
- return (cur_key);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%12_8B.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\12_8B.C%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%OK 1 %@NL@%
- %@AI@%#define %@AE@%ERROR 0 %@NL@%
- struct key_struct {%@NL@%
- char key;%@NL@%
- unsigned char move;%@NL@%
- };%@NL@%
- %@NL@%
- struct key_struct *Read_key()%@NL@%
- {%@NL@%
- struct key_struct k;%@NL@%
- %@NL@%
- k.key = getch();%@NL@%
- if (k.key == ERROR)%@NL@%
- k.move = getch();%@NL@%
- return (&k);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ACME.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\ACME.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* acme.c -- illustrate an assortment of the */%@AE@%%@NL@%
- %@AB@%/* C library string-handling routines */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <string.h> %@AB@%/* for strchr(), et al */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NAME_PATTERN \ %@NL@%
- "first<space>last or\n\%@NL@%
- first<space>middle<space>last"%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%ADDRESS_PATTERN \ %@NL@%
- "number<space>street<comma><space>city<comma>"%@NL@%
- %@NL@%
- char Buf[BUFSIZ]; %@AB@%/* global I/O buffer */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *ocp, *cp, *first, *last, *street, *city;%@NL@%
- void Prompt(), Cant();%@NL@%
- %@NL@%
- printf("Acme Employment Questionaire\n");%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Expect first<space>last or%@NL@%
- %@AB@% * first<space>middle<space>last%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Prompt("Full Name");%@NL@%
- %@AB@%/* search forward for a space */%@AE@%%@NL@%
- if ((cp = strchr(Buf,' ')) == NULL)%@NL@%
- Cant("First Name", NAME_PATTERN);%@NL@%
- *cp = '\0';%@NL@%
- first = strdup(Buf);%@NL@%
- *cp = ' ';%@NL@%
- %@NL@%
- %@AB@%/* Search back from end for a space */%@AE@%%@NL@%
- if ((cp = strrchr(Buf,' ')) == NULL)%@NL@%
- Cant("Last Name", NAME_PATTERN);%@NL@%
- last = strdup(++cp);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Expect number<space>street<comma><space>city<comma>%@NL@%
- %@AB@% */%@AE@%%@NL@%
- Prompt("Full Address");%@NL@%
- %@AB@%/* search forward for a comma */%@AE@%%@NL@%
- if ((cp = strchr(Buf,',')) == NULL)%@NL@%
- Cant("Street", ADDRESS_PATTERN);%@NL@%
- *cp = '\0';%@NL@%
- street = strdup(Buf);%@NL@%
- %@NL@%
- %@AB@%/* Search forward from last comma for next comma */%@AE@%%@NL@%
- if ((ocp = strchr(++cp,',')) == NULL)%@NL@%
- Cant("City", ADDRESS_PATTERN);%@NL@%
- *ocp = '\0';%@NL@%
- city = strdup(++cp);%@NL@%
- %@NL@%
- printf("\n\nYou Entered:\n");%@NL@%
- printf("\tFirst Name: \"%s\"\n", first);%@NL@%
- printf("\tLast Name: \"%s\"\n", last);%@NL@%
- printf("\tStreet: \"%s\"\n", street);%@NL@%
- printf("\tCity: \"%s\"\n", city);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Cant(char *what, char *pattern)%@NL@%
- {%@NL@%
- printf("\n\n\bFormat Error!!!\n");%@NL@%
- printf("Can't parse your %s.\n", what );%@NL@%
- printf("Expected an entry of the form:\n\n");%@NL@%
- printf("%s\n\nAborted\n", pattern);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- void Prompt(char *str)%@NL@%
- {%@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("\n%s: ", str );%@NL@%
- if (gets(Buf) == NULL || *Buf == '\0')%@NL@%
- {%@NL@%
- printf("Do you wish to quit? ");%@NL@%
- if (gets(Buf) == NULL || *Buf == 'y')%@NL@%
- exit (0);%@NL@%
- continue;%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ALERT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\ALERT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* alert.c -- sounds alarm by calling a */%@AE@%%@NL@%
- %@AB@%/* beep() function with a parameter */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- void beep(times); %@AB@%/* function declaration */%@AE@%%@NL@%
- printf("*** Alert! Alert! ***\n");%@NL@%
- beep(3); %@AB@%/* call beep() with parameter */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- void beep(times)%@NL@%
- int times; %@AB@%/* declare function parameter */%@AE@%%@NL@%
- {%@NL@%
- int count;%@NL@%
- %@NL@%
- %@AB@%/* check that parameter is between 1 and 4 */%@AE@%%@NL@%
- if ((times < 1) || (times > 4))%@NL@%
- {%@NL@%
- printf("Error in beep(): %d beeps specified.\n",%@NL@%
- times);%@NL@%
- printf("Specify one to four beeps");%@NL@%
- }%@NL@%
- else %@AB@%/* sound the beeps */%@AE@%%@NL@%
- for (count = 1; count <= times; count++)%@NL@%
- printf("\a"); %@AB@%/* "alert" escape sequence */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ALLCOLOR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\ALLCOLOR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* allcolor.c -- shows _ERESCOLOR 64-color palette */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed.*/%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Hit <g> to advance left palette, <G> to go back. */%@AE@%%@NL@%
- %@AB@%/* Hit <h> to advance right palette, <H> to go back. */%@AE@%%@NL@%
- %@AB@%/* Hit <Esc> to quit */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%MAXCOLORS 64 %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- long Ega_to_vga(int); %@AB@%/* color value conversion */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _ERESCOLOR;%@NL@%
- int xmax, ymax;%@NL@%
- int c1 = 1;%@NL@%
- int c2 = 4;%@NL@%
- char left[11];%@NL@%
- char right[11];%@NL@%
- int lpos, rpos;%@NL@%
- char ch;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr,"%d mode not supported\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- _setlogorg(vc.numxpixels/2, vc.numypixels/2);%@NL@%
- %@NL@%
- xmax = vc.numxpixels / 2 - 1;%@NL@%
- ymax = vc.numypixels / 2 - 1;%@NL@%
- lpos = vc.numxpixels/32 - 5;%@NL@%
- rpos = lpos + vc.numxpixels / 16;%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GFILLINTERIOR, -xmax, -ymax, 0, ymax);%@NL@%
- _setcolor(4);%@NL@%
- _rectangle(_GFILLINTERIOR, 1, -ymax, xmax, ymax);%@NL@%
- sprintf(left,"<-G %2d g->", c1);%@NL@%
- sprintf(right,"<-H %2d h->", c2);%@NL@%
- _settextcolor(6);%@NL@%
- _settextposition(0, 0);%@NL@%
- _outtext("Press Esc to quit");%@NL@%
- _settextposition(24, lpos);%@NL@%
- _outtext(left);%@NL@%
- _settextposition(24, rpos);%@NL@%
- _outtext(right);%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case 'g': c1 = (c1 + 1) % MAXCOLORS;%@NL@%
- _remappalette(1, Ega_to_vga(c1));%@NL@%
- break;%@NL@%
- case 'G': c1 = (c1 - 1) % MAXCOLORS;%@NL@%
- _remappalette(1, Ega_to_vga(c1));%@NL@%
- break;%@NL@%
- case 'h': c2 = (c2 + 1) % MAXCOLORS;%@NL@%
- _remappalette(4, Ega_to_vga(c2));%@NL@%
- break;%@NL@%
- case 'H': c2 = (c2 - 1) % MAXCOLORS;%@NL@%
- _remappalette(4, Ega_to_vga(c2));%@NL@%
- break;%@NL@%
- }%@NL@%
- sprintf(left,"<-G %2d ->g", c1);%@NL@%
- sprintf(right,"<-H %2d ->h", c2);%@NL@%
- _settextposition(0, 0);%@NL@%
- _outtext("Press Esc to quit");%@NL@%
- _settextposition(24, lpos);%@NL@%
- _outtext(left);%@NL@%
- _settextposition(24, rpos);%@NL@%
- _outtext(right);%@NL@%
- }%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- long Ega_to_vga(egacolor)%@NL@%
- int egacolor; %@AB@%/* ega color value */%@AE@%%@NL@%
- {%@NL@%
- static long vgavals[6] = {0x2A0000L, 0x002A00L, 0x00002AL,%@NL@%
- 0x150000L, 0x001500L, 0x000015L};%@NL@%
- long vgacolor = 0L; %@AB@%/* vga color value */%@AE@%%@NL@%
- int bit;%@NL@%
- %@NL@%
- for (bit = 0; bit < 6; bit++)%@NL@%
- vgacolor += ((egacolor >> bit) &1) * vgavals[bit];%@NL@%
- return (vgacolor);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ALLVGA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\ALLVGA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* allvga.c -- shows _MRES256COLOR 256K colors */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed.*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%FULLBRIGHT 64 %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- char label[2][7] = {"ACTIVE", " "};%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES256COLOR;%@NL@%
- int xmax, ymax;%@NL@%
- static long colors[2] = {_BLUE, _RED};%@NL@%
- char left[11];%@NL@%
- char right[11];%@NL@%
- int lpos, rpos;%@NL@%
- char ch;%@NL@%
- unsigned long blue = _BLUE >> 16;%@NL@%
- unsigned long green = 0L;%@NL@%
- unsigned long red = 0L;%@NL@%
- long color;%@NL@%
- short palnum = 0;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr,"%d mode not supported\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- _setlogorg(vc.numxpixels/2, vc.numypixels/2);%@NL@%
- %@NL@%
- xmax = vc.numxpixels / 2 - 1;%@NL@%
- ymax = vc.numypixels / 2 - 1;%@NL@%
- lpos = vc.numxpixels / 32 - 5;%@NL@%
- rpos = lpos + vc.numxpixels/16;%@NL@%
- _remappalette(2, _RED);%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GFILLINTERIOR, -xmax, -ymax, 0, ymax);%@NL@%
- _setcolor(2);%@NL@%
- _rectangle(_GFILLINTERIOR, 1, -ymax, xmax, ymax);%@NL@%
- sprintf(left," %6lxH ", colors[0]);%@NL@%
- sprintf(right," %6lxH ", colors[1]);%@NL@%
- _settextcolor(6);%@NL@%
- _settextposition(1, 1);%@NL@%
- _outtext("Press Tab to toggle panels, Esc to quit.");%@NL@%
- _settextposition(2, 1);%@NL@%
- _outtext("B increases blue level, b decreases it. ");%@NL@%
- _settextposition(3, 1);%@NL@%
- _outtext("G and g control green, R and r red. ");%@NL@%
- _settextposition(24, lpos);%@NL@%
- _outtext(left);%@NL@%
- _settextposition(24, rpos);%@NL@%
- _outtext(right);%@NL@%
- _settextposition(5, 7);%@NL@%
- _outtext(label[0]);%@NL@%
- _settextposition(5, 27);%@NL@%
- _outtext(label[1]);%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case '\t': _settextposition(5, 27);%@NL@%
- _outtext(label[palnum]);%@NL@%
- palnum ^= 1;%@NL@%
- blue = (colors[palnum] << 16) & 0x3F;%@NL@%
- green = (colors[palnum] << 8) & 0x3F;%@NL@%
- red = colors[palnum] & 0x3F;%@NL@%
- _settextposition(5, 7);%@NL@%
- _outtext(label[palnum]);%@NL@%
- break;%@NL@%
- case 'B': blue = (blue + 1) % FULLBRIGHT;%@NL@%
- colors[palnum] = blue << 16 |%@NL@%
- green << 8 | red;%@NL@%
- _remappalette(palnum + 1, colors[palnum]);%@NL@%
- %@NL@%
- break;%@NL@%
- case 'b': blue = (blue - 1) % FULLBRIGHT;%@NL@%
- colors[palnum] = blue << 16 |%@NL@%
- green << 8 | red;%@NL@%
- _remappalette(palnum + 1, colors[palnum]);%@NL@%
- %@NL@%
- break;%@NL@%
- case 'G': green = (green + 1) % FULLBRIGHT;%@NL@%
- colors[palnum] = blue << 16 |%@NL@%
- green << 8 | red;%@NL@%
- _remappalette(palnum + 1, colors[palnum]);%@NL@%
- %@NL@%
- break;%@NL@%
- case 'g': green = (green - 1) % FULLBRIGHT;%@NL@%
- colors[palnum] = blue << 16 |%@NL@%
- green << 8 | red;%@NL@%
- _remappalette(palnum + 1, colors[palnum]);%@NL@%
- %@NL@%
- break;%@NL@%
- case 'R': red = (red + 1) % FULLBRIGHT;%@NL@%
- colors[palnum] = blue << 16 |%@NL@%
- green << 8 | red;%@NL@%
- _remappalette(palnum + 1, colors[palnum]);%@NL@%
- %@NL@%
- break;%@NL@%
- case 'r': red = (red - 1) % FULLBRIGHT;%@NL@%
- colors[palnum] = blue << 16 |%@NL@%
- green << 8 | red;%@NL@%
- _remappalette(palnum + 1, colors[palnum]);%@NL@%
- %@NL@%
- break;%@NL@%
- %@NL@%
- }%@NL@%
- sprintf(left," %6lxH ", colors[0]);%@NL@%
- sprintf(right," %6lxH ", colors[1]);%@NL@%
- _settextposition(24, lpos);%@NL@%
- _outtext(left);%@NL@%
- _settextposition(24, rpos);%@NL@%
- _outtext(right);%@NL@%
- }%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ALPHABET.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\ALPHABET.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* ALPHABET.C -- uses for loop to */%@AE@%%@NL@%
- %@AB@%/* print lowercase alphabet */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- for (i = 'a'; i <= 'z'; i++)%@NL@%
- { %@NL@%
- printf("%c", i);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ANIMATE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\ANIMATE.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* ANIMATE.C -- animate a graphics character */%@AE@%%@NL@%
- %@AB@%/* until a key is pressed */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Special characters */%@AE@%%@NL@%
- %@AI@%#define %@AE@%RTARROW 175 %@NL@%
- %@AI@%#define %@AE@%LFTARROW 174 %@NL@%
- %@AI@%#define %@AE@%BLANK 32 %@NL@%
- %@AI@%#define %@AE@%BACKSPACE 8 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int pos, i, j = 1;%@NL@%
- while ( !kbhit() )%@NL@%
- {%@NL@%
- pos = 1;%@NL@%
- while (pos < 79)%@NL@%
- {%@NL@%
- putch(RTARROW);%@NL@%
- i = 1;%@NL@%
- while (i < 1000)%@NL@%
- {%@NL@%
- j = i + 10;%@NL@%
- i++;%@NL@%
- }%@NL@%
- putch(BACKSPACE);%@NL@%
- putch(BLANK);%@NL@%
- pos++;%@NL@%
- }%@NL@%
- while (pos > 1)%@NL@%
- {%@NL@%
- putch(LFTARROW);%@NL@%
- i = 1;%@NL@%
- while (i < 1000)%@NL@%
- {%@NL@%
- j = i + 10;%@NL@%
- i++;%@NL@%
- }%@NL@%
- putch(BACKSPACE);%@NL@%
- putch(BLANK);%@NL@%
- putch(BACKSPACE);%@NL@%
- putch(BACKSPACE);%@NL@%
- pos--;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARRAY1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\ARRAY1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* array1.c -- how to declare arrays legally */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%SIZEOARRAY 26 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char initials[26];%@NL@%
- int num_men[26], num_women[SIZEOARRAY];%@NL@%
- float ages[SIZEOARRAY * 2];%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARROW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\ARROW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* arrow.c -- fill inside and outside of a line */%@AE@%%@NL@%
- %@AB@%/* drawing */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- BKCOLS 16 %@AB@%/* use 16 background colors */%@AE@%%@NL@%
- long Bkcolors[BKCOLS] = {_BLACK, _BLUE, _GREEN, _CYAN,%@NL@%
- _RED, _MAGENTA, _BROWN, _WHITE,%@NL@%
- _GRAY, _LIGHTBLUE, _LIGHTGREEN,%@NL@%
- _LIGHTCYAN, _LIGHTRED, _LIGHTMAGENTA,%@NL@%
- _LIGHTYELLOW,_BRIGHTWHITE };%@NL@%
- char Mask[8] = {0x90, 0x68, 0x34, 0x19, 0x19, 0x34, 0x68,%@NL@%
- 0x90};%@NL@%
- char Outmask[8] = {0xff, 0x80, 0x80, 0x80, 0xff, 0x08, 0x08,%@NL@%
- 0x08};%@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- float x1, y1, x2, y2, x3, y3, y4, x5, y5;%@NL@%
- long bk = _BLUE;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- printf("Can't set mode %d.\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- %@NL@%
- x1 = 0.1 * vc.numxpixels;%@NL@%
- x2 = 0.7 * vc.numxpixels;%@NL@%
- x3 = 0.6 * vc.numxpixels;%@NL@%
- x5 = 0.9 * vc.numxpixels;%@NL@%
- y1 = 0.45 * vc.numypixels;%@NL@%
- y2 = 0.55 * vc.numypixels;%@NL@%
- y3 = 0.3 * vc.numypixels;%@NL@%
- y4 = 0.7 * vc.numypixels;%@NL@%
- y5 = 0.5 * vc.numypixels;%@NL@%
- _selectpalette(0);%@NL@%
- _setcolor(1);%@NL@%
- _moveto(x1, y1);%@NL@%
- _lineto(x2, y1);%@NL@%
- _lineto(x3, y3);%@NL@%
- _lineto(x5, y5);%@NL@%
- _lineto(x3, y4);%@NL@%
- _lineto(x2, y2);%@NL@%
- _lineto(x1, y2);%@NL@%
- _lineto(x1, y1);%@NL@%
- _setcolor(2);%@NL@%
- _setfillmask(Mask);%@NL@%
- _floodfill(x2, y5, 1) ;%@NL@%
- _setcolor(3);%@NL@%
- _setfillmask(Outmask); %@AB@%/* restores default mask */%@AE@%%@NL@%
- _floodfill(5, 5, 1) ;%@NL@%
- _settextcolor(1);%@NL@%
- _settextposition(23, 0);%@NL@%
- _outtext("Press <enter> to change background.");%@NL@%
- _settextposition(24, 0);%@NL@%
- _outtext("Press <esc> to end.");%@NL@%
- while (getch() != ESC)%@NL@%
- _setbkcolor(Bkcolors[++bk % BKCOLS]);%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ASGNKEY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\ASGNKEY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* asgnkey.c -- uses ansi.sys to assign meanings */%@AE@%%@NL@%
- %@AB@%/* to several function keys. */%@AE@%%@NL@%
- %@AB@%/* Note: This requires ANSI.SYS to be installed. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%KASSIGN(K, S) printf("\033[0;%d;\"%s\";13p", K, S) %@NL@%
- %@AB@%/* This macro assigns string S to key K */%@AE@%%@NL@%
- %@AI@%#define %@AE@%F5 63 %@NL@%
- %@AI@%#define %@AE@%F6 64 %@NL@%
- %@AI@%#define %@AE@%F7 65 %@NL@%
- %@AI@%#define %@AE@%F8 66 %@NL@%
- %@AI@%#define %@AE@%F9 67 %@NL@%
- %@AI@%#define %@AE@%F10 68 %@NL@%
- main()%@NL@%
- {%@NL@%
- KASSIGN(F5, "DIR *.C");%@NL@%
- KASSIGN(F6, "DIR *.H");%@NL@%
- KASSIGN(F7, "DIR *.OBJ");%@NL@%
- KASSIGN(F8, "DIR *.EXE");%@NL@%
- KASSIGN(F9, "DIR /W");%@NL@%
- KASSIGN(F10, "CD \\");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ASIMOV.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\ASIMOV.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* asimov.c -- illustrates how to initialize an */%@AE@%%@NL@%
- %@AB@%/* array with starting values */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXL 16 %@NL@%
- char Letters[MAXL] = { %@NL@%
- 'e', 'I', 'a', 'N', 'o', 'R', 'O', 'o',%@NL@%
- 'u', 't', 'o', 'R', 'l', 'o', 'B', 'b', %@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num, i;%@NL@%
- %@NL@%
- printf("Guess my identity with numbers.\n");%@NL@%
- printf("(any non number quits)\n\n");%@NL@%
- %@NL@%
- while (scanf("%d", &num) == 1)%@NL@%
- {%@NL@%
- if (num <= 0)%@NL@%
- {%@NL@%
- printf("Guesses must be above zero\n");%@NL@%
- continue;%@NL@%
- }%@NL@%
- for (i = 1; i <= num; ++i)%@NL@%
- {%@NL@%
- printf("%c", Letters[(i * num) % MAXL]);%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ATTRIB.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\ATTRIB.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* attrib.c -- this program illustrates attributes */%@AE@%%@NL@%
- %@AB@%/* program list: attrib.c, scrfun.c */%@AE@%%@NL@%
- %@AB@%/* user include files: scrn.h */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@AI@%#define %@AE@%PAGE 0 %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- char *Format = "This message is displayed using an "%@NL@%
- "attribute value of %2X hex (%s).";%@NL@%
- int Get_attrib(char *);%@NL@%
- void Print_attr(char *, unsigned char, unsigned char);%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@NL@%
- int attribute; %@AB@%/* value of attribute */%@AE@%%@NL@%
- char attr_str[9]; %@AB@%/* attr. in string form */%@AE@%%@NL@%
- char mesg[80];%@NL@%
- %@NL@%
- Clearscr();%@NL@%
- Home();%@NL@%
- printf("Enter an attribute as an 8-digit binary "%@NL@%
- "number, such as 00000111, and see a\n"%@NL@%
- "message displayed using that attribute."%@NL@%
- "Hit <Esc> to quit.\n"%@NL@%
- "Attribute = ");%@NL@%
- while ((attribute = Get_attrib(attr_str)) != -1)%@NL@%
- {%@NL@%
- Setcurs(10,0,PAGE);%@NL@%
- sprintf(mesg, Format, attribute, attr_str);%@NL@%
- Print_attr(mesg, attribute, PAGE);%@NL@%
- Setcurs(2, 12, PAGE);%@NL@%
- printf(" "); %@AB@%/* clear old display */%@AE@%%@NL@%
- Setcurs(2, 12, PAGE);%@NL@%
- }%@NL@%
- Clearscr();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* The following function reads in a binary number */%@AE@%%@NL@%
- %@AB@%/* as a sequence of 1s and 0s. It places the 1 and 0 */%@AE@%%@NL@%
- %@AB@%/* characters in a string whose address is passed as */%@AE@%%@NL@%
- %@AB@%/* an argument. It returns the numeric value of the */%@AE@%%@NL@%
- %@AB@%/* binary number. Bad input is summarily rejected. */%@AE@%%@NL@%
- %@AB@%/* The function returns -1 when you press Esc. */%@AE@%%@NL@%
- %@NL@%
- int Get_attrib(a_str)%@NL@%
- char a_str[]; %@AB@%/* attribute as binary string */%@AE@%%@NL@%
- {%@NL@%
- int attrib[8];%@NL@%
- int index = 7;%@NL@%
- int ch;%@NL@%
- int attribute = 0; %@AB@%/* attrib. as numeric value */%@AE@%%@NL@%
- int pow;%@NL@%
- %@NL@%
- a_str[8] = '\0'; %@AB@%/* terminate string */%@AE@%%@NL@%
- while ((index >= 0) && (ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch != '0' && ch != '1') %@AB@%/* bad input */%@AE@%%@NL@%
- putch('\a');%@NL@%
- else%@NL@%
- {%@NL@%
- putch(ch);%@NL@%
- a_str[index] = ch; %@AB@%/* string form */%@AE@%%@NL@%
- attrib[index--] = ch - '0'; %@AB@%/* numeric */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- if (ch == ESC)%@NL@%
- return (-1);%@NL@%
- else %@AB@%/* convert numeric array to a number */%@AE@%%@NL@%
- {%@NL@%
- for(index = 0, pow = 1; index < 8;%@NL@%
- index++, pow *= 2)%@NL@%
- attribute += attrib[index] * pow;%@NL@%
- return attribute;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* The following function prints the string str using */%@AE@%%@NL@%
- %@AB@%/* attribute attr on the indicated page. */%@AE@%%@NL@%
- %@AB@%/* It uses functions from the scrfun.c file. */%@AE@%%@NL@%
- %@NL@%
- void Print_attr(str, attr, page)%@NL@%
- char *str;%@NL@%
- unsigned char attr, page;%@NL@%
- {%@NL@%
- while (*str != '\0')%@NL@%
- {%@NL@%
- Write_ch_atr(*str++, attr , page, 1);%@NL@%
- Cursrt();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%AVGTEMP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\AVGTEMP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* avgtemp.c -- finds average temperature */%@AE@%%@NL@%
- %@AB@%/* for the week */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int t1, t2, t3, t4, t5, t6, t7;%@NL@%
- float avg;%@NL@%
- %@NL@%
- printf("Enter the high temperature for:\n");%@NL@%
- printf("Monday: ");%@NL@%
- scanf("%d", &t1);%@NL@%
- printf("Tuesday: ");%@NL@%
- scanf("%d", &t2);%@NL@%
- printf("Wednesday: ");%@NL@%
- scanf("%d", &t3);%@NL@%
- printf("Thursday: ");%@NL@%
- scanf("%d", &t4);%@NL@%
- printf("Friday: ");%@NL@%
- scanf("%d", &t5);%@NL@%
- printf("Saturday: ");%@NL@%
- scanf("%d", &t6);%@NL@%
- printf("Sunday: ");%@NL@%
- scanf("%d", &t7);%@NL@%
- %@NL@%
- %@AB@%/* calculate and display average */%@AE@%%@NL@%
- avg = (t1 + t2 + t3 + t4 + t5 + t6 + t7) / 7.0;%@NL@%
- %@AB@%/* divide by 7.0 to ensure float result */%@AE@%%@NL@%
- printf("The average high temperature for");%@NL@%
- printf(" this week was %5.2f degrees.\n", avg);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BACKWARD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\BACKWARD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* backward.c -- the backwards word displayer */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%SIZE 5 %@NL@%
- char word[SIZE] = "trap";%@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned int index;%@NL@%
- %@NL@%
- printf("%s backwards is ", word);%@NL@%
- for (index = SIZE - 2; index >= 0; index--)%@NL@%
- putchar(word[index]);%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BADPUTC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\BADPUTC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* badputc.c -- misusing putc() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *fp;%@NL@%
- int ch;%@NL@%
- %@NL@%
- if ((fp = fopen("junk", "w")) == NULL)%@NL@%
- exit(1);%@NL@%
- %@NL@%
- while ((ch = getchar()) != EOF)%@NL@%
- putc(fp, ch);%@NL@%
- fclose(fp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BADREF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\BADREF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* badref.c -- misusing a pointer */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- char name[81];%@NL@%
- char *pt_ch;%@NL@%
- %@NL@%
- printf("Enter your first name: -> ");%@NL@%
- scanf("%s", name);%@NL@%
- *pt_ch = name[1];%@NL@%
- printf("The second letter of your name is %c\n",%@NL@%
- *pt_ch );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BADSIGN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\BADSIGN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* badsign.c -- uncaught typo */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- { %@NL@%
- int i; %@NL@%
- int j = 1; %@NL@%
- %@NL@%
- for (i = 0; i < 10; i++)%@NL@%
- {%@NL@%
- j =+ 10; %@AB@%/* transposed += */%@AE@%%@NL@%
- printf("%4d ", j); %@NL@%
- }%@NL@%
- printf("\n"); %@NL@%
- } %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BIFFRED.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\BIFFRED.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* biffred.c -- strings in the string pool can be */%@AE@%%@NL@%
- %@AB@%/* manipulated via pointers */%@AE@%%@NL@%
- %@NL@%
- char Start[] = "start";%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *cp;%@NL@%
- int pass;%@NL@%
- %@NL@%
- for (pass = 0; pass < 2; ++pass)%@NL@%
- {%@NL@%
- printf("My name is FRED\n");%@NL@%
- %@NL@%
- cp = Start; %@NL@%
- %@NL@%
- while (*cp != 'F')%@NL@%
- ++cp;%@NL@%
- %@NL@%
- *cp = 'B';%@NL@%
- *++cp = 'I';%@NL@%
- *++cp = 'F';%@NL@%
- *++cp = 'F';%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BITOUT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\BITOUT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* bitout.c -- compiles one way on an IBM-PC and */%@AE@%%@NL@%
- %@AB@%/* another on a 68000 chip-based machine */%@AE@%%@NL@%
- %@NL@%
- CHIP_80286 %@AB@%/* don't define on a 68000 machine */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num;%@NL@%
- %@NL@%
- printf("Enter an integer number and I will print"%@NL@%
- " it out in binary\nNumber: ");%@NL@%
- %@NL@%
- if (scanf("%d", &num) != 1)%@NL@%
- {%@NL@%
- fprintf(stderr, "Not an integer\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- Bitout(num);%@NL@%
- }%@NL@%
- %@NL@%
- Bitout(unsigned int num)%@NL@%
- {%@NL@%
- int i, j;%@NL@%
- unsigned char *cp;%@NL@%
- %@NL@%
- cp = (char *)#%@NL@%
- %@NL@%
- defined(CHIP_80286) %@AB@%/* IBM-PC */%@AE@%%@NL@%
- for (i = 1; i >= 0; --i)%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- !defined(CHIP_80286) %@AB@%/* otherwise 68000 machine */%@AE@%%@NL@%
- for (i = 0; i < 4; ++i)%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- {%@NL@%
- for (j = 7; j >= 0; --j)%@NL@%
- putchar((cp[i] & (1 << j)) ? '1' : '0');%@NL@%
- }%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BITWISE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\BITWISE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* bitwise.c -- demonstrate the bitwise operators */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned int val1, val2, result;%@NL@%
- int ch;%@NL@%
- extern void show();%@NL@%
- %@NL@%
- while(1)%@NL@%
- {%@NL@%
- printf("\nval1: ");%@NL@%
- if (scanf("%d", &val1) != 1)%@NL@%
- break;%@NL@%
- %@NL@%
- printf("val2: ");%@NL@%
- if (scanf("%d", &val2) != 1)%@NL@%
- break;%@NL@%
- %@NL@%
- printf("\tval1 = ");%@NL@%
- show(val1);%@NL@%
- printf("\tval2 = ");%@NL@%
- show(val2);%@NL@%
- %@NL@%
- printf("Bitwise Operator: ");%@NL@%
- while ((ch = getchar()) == '\n')%@NL@%
- {%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (ch == EOF)%@NL@%
- break;%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case '&':%@NL@%
- result = val1 & val2;%@NL@%
- printf("Executing: result = val1 & val2;\n");%@NL@%
- break;%@NL@%
- case '|':%@NL@%
- result = val1 |= val2;%@NL@%
- printf("Executing: result = val1 | val2;\n");%@NL@%
- break;%@NL@%
- case '^':%@NL@%
- result = val1 ^= val2;%@NL@%
- printf("Executing: result = val1 ^ val2;\n");%@NL@%
- break;%@NL@%
- case '~':%@NL@%
- result = ~val1;%@NL@%
- printf("Executing: result = ~val1;\n");%@NL@%
- printf("\tresult = ");%@NL@%
- show(result);%@NL@%
- result = ~val2;%@NL@%
- printf("Executing: result = ~val2;\n");%@NL@%
- break;%@NL@%
- case '<':%@NL@%
- result = val1 <<= val2;%@NL@%
- printf("Executing: result = val1 <<val2;\n");%@NL@%
- break;%@NL@%
- case '>':%@NL@%
- result = val1 >>= val2;%@NL@%
- printf("Executing: result = val1 >>val2;\n");%@NL@%
- break;%@NL@%
- case 'q':%@NL@%
- case 'Q':%@NL@%
- return(0);%@NL@%
- default:%@NL@%
- continue;%@NL@%
- }%@NL@%
- printf("\tresult = ");%@NL@%
- show(result);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void bitout(unsigned char num[])%@NL@%
- {%@NL@%
- int bytes = 2, i, j;%@NL@%
- %@NL@%
- %@AB@%/* IBM PC stores ints low/hi. */%@AE@%%@NL@%
- for (i = bytes-1; i >= 0; --i)%@NL@%
- {%@NL@%
- for (j = 7; j >= 0; --j)%@NL@%
- {%@NL@%
- putchar((num[i]&(1<<j))?'1':'0');%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void show(unsigned int val)%@NL@%
- {%@NL@%
- extern void bitout();%@NL@%
- %@NL@%
- printf("(%05u decimal)", val);%@NL@%
- bitout(&val);%@NL@%
- printf(" binary\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BLANK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\BLANK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* blank.c -- blanks MDA screen */%@AE@%%@NL@%
- %@AB@%/* program list -- blank.c (outp() not in core lib) */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- CONTROLREG 0x3B8 %@AB@%/* control register MDA */%@AE@%%@NL@%
- %@AI@%#define %@AE@%DEFAULTSET 0x29 %@NL@%
- %@AI@%#define %@AE@%VIDEOOFF 0x21 %@NL@%
- main()%@NL@%
- {%@NL@%
- outp(CONTROLREG, VIDEOOFF);%@NL@%
- getch();%@NL@%
- outp(CONTROLREG, DEFAULTSET);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BOX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\BOX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* box.c -- demonstrate the result of initializing */%@AE@%%@NL@%
- %@AB@%/* a three-dimensional array */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static int cube[3][3][3] = {%@NL@%
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,%@NL@%
- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,%@NL@%
- 23, 24, 25, 26, 27 };%@NL@%
- int plane;%@NL@%
- extern void Draw_plane();%@NL@%
- %@NL@%
- for (plane = 0; plane < 3; ++plane)%@NL@%
- {%@NL@%
- Draw_plane(cube, plane);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void Draw_plane(int box[3][3][3], int slice)%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- %@NL@%
- printf("Plane[%d] =\n", slice);%@NL@%
- for (row = 0; row < 3; ++row)%@NL@%
- {%@NL@%
- for (col = 0; col < 3; ++col)%@NL@%
- {%@NL@%
- printf( "%2d ", box[slice][row][col]);%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BREAK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\BREAK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* break.c -- shows how to get out of loop with BREAK */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%TRUE 1 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int number;%@NL@%
- while (TRUE) %@AB@%/* endless loop */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* get a random number between 0 and 32767 */%@AE@%%@NL@%
- number = rand();%@NL@%
- printf("%d\n", number);%@NL@%
- %@NL@%
- %@AB@%/* break out of loop if random number */%@AE@%%@NL@%
- %@AB@%/* is greater than 32000 */%@AE@%%@NL@%
- if (number > 32000)%@NL@%
- break; %@AB@%/* exit WHILE loop */%@AE@%%@NL@%
- }%@NL@%
- printf("Broken out of WHILE loop.\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BUBSORT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\BUBSORT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* bubsort.c -- passing an array to a function */%@AE@%%@NL@%
- %@AB@%/* affects the original array */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NUMINTS 6 %@NL@%
- %@NL@%
- extern void Bub_sort();%@NL@%
- extern void Triple();%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num = 2, i;%@NL@%
- static int list[NUMINTS] = { 6, 5, 4, 3, 2, 1 };%@NL@%
- %@NL@%
- printf("num before Triple = %d\n", num);%@NL@%
- Triple(num);%@NL@%
- printf("num after Triple = %d\n", num);%@NL@%
- printf("list[0] before Triple = %d\n", list[0]);%@NL@%
- Triple(list[0]);%@NL@%
- printf("list[0] after Triple = %d\n", list[0]);%@NL@%
- %@NL@%
- printf("Before sorting -> ");%@NL@%
- for (i = 0; i < NUMINTS; ++i)%@NL@%
- {%@NL@%
- printf("%d ", list[i]);%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- Bub_sort(list);%@NL@%
- printf("After sorting -> ");%@NL@%
- for (i = 0; i < NUMINTS; ++i)%@NL@%
- {%@NL@%
- printf("%d ", list[i]);%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Triple(int x) %@AB@%/* function doesn't affect original */%@AE@%%@NL@%
- {%@NL@%
- x *= 3;%@NL@%
- }%@NL@%
- %@NL@%
- void Bub_sort(int vals[NUMINTS]) %@AB@%/* function changes original */%@AE@%%@NL@%
- {%@NL@%
- int i, j, temp;%@NL@%
- %@NL@%
- for (i = (NUMINTS - 1); i > 0; --i)%@NL@%
- {%@NL@%
- for (j = 0; j < i; ++j)%@NL@%
- {%@NL@%
- if (vals[j] > vals[j+1])%@NL@%
- {%@NL@%
- temp = vals[j];%@NL@%
- vals[j] = vals[j+1];%@NL@%
- vals[j+1] = temp;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BUG.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\BUG.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* bug.c -- shows how different levels of debugging */%@AE@%%@NL@%
- %@AB@%/* output can be produced using #if */%@AE@%%@NL@%
- %@NL@%
- DEBUG_LEVEL 2 %@AB@%/* 0 = none, 1-2 for debug */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ret;%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%(DEBUG_LEVEL == 2) %@NL@%
- fprintf(stderr, "Entering main()\n");%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%(DEBUG_LEVEL == 1) %@NL@%
- fprintf(stderr, "Calling sub()\n");%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- ret = sub();%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%(DEBUG_LEVEL == 1) %@NL@%
- fprintf(stderr, "sub() returned %d\n", ret);%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- %@AI@%#if %@AE@%(DEBUG_LEVEL == 2) %@NL@%
- fprintf(stderr, "Leaving main()\n");%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- sub()%@NL@%
- {%@NL@%
- return (5);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CARD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\CARD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* card.c -- demonstrates how to declare structures */%@AE@%%@NL@%
- %@AB@%/* and how to use structure members */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and stdin */%@AE@%%@NL@%
- <string.h> %@AB@%/* for strdup() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXN 79 %@NL@%
- %@NL@%
- struct cardstruct { %@AB@%/* global pattern */%@AE@%%@NL@%
- char *first, *last, *middle;%@NL@%
- long street_num;%@NL@%
- char *street, *city, *state;%@NL@%
- long zip;%@NL@%
- int area_code;%@NL@%
- long phone;%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *Str_Input();%@NL@%
- long Lint_Input();%@NL@%
- struct cardstruct card1;%@NL@%
- %@NL@%
- card1.first = Str_Input("First Name");%@NL@%
- card1.last = Str_Input("Last Name");%@NL@%
- card1.middle = Str_Input("Middle Name");%@NL@%
- card1.street_num = Lint_Input("Street Number");%@NL@%
- card1.street = Str_Input("Street Name");%@NL@%
- card1.city = Str_Input("City");%@NL@%
- card1.state = Str_Input("State");%@NL@%
- card1.zip = Lint_Input("Zip Code");%@NL@%
- card1.area_code = (int)Lint_Input("Area Code");%@NL@%
- card1.phone = Lint_Input("Phone Number");%@NL@%
- %@NL@%
- printf("\n\n");%@NL@%
- printf("%s %s %s\n", card1.first, card1.middle, %@NL@%
- card1.last);%@NL@%
- printf("%ld %s, %s, %s %ld\n", card1.street_num, %@NL@%
- card1.street, card1.city, card1.state,%@NL@%
- card1.zip);%@NL@%
- printf("(%d) %ld\n", card1.area_code, card1.phone);%@NL@%
- %@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- char *Str_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN+1], *ptr;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- buf[strlen(buf) - 1] = '\0'; %@AB@%/* strip '\n' */%@AE@%%@NL@%
- if (strlen(buf) == 0)%@NL@%
- exit(0);%@NL@%
- if ((ptr = strdup(buf)) == NULL)%@NL@%
- exit(0);%@NL@%
- return (ptr);%@NL@%
- }%@NL@%
- %@NL@%
- long Lint_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1];%@NL@%
- long num;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- if (sscanf(buf, "%ld", &num) != 1)%@NL@%
- exit(0);%@NL@%
- return (num);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CARD2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\CARD2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* card2.c -- demonstrates structure assignment and */%@AE@%%@NL@%
- %@AB@%/* how to pass a structure to a function */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and stdin */%@AE@%%@NL@%
- <string.h> %@AB@%/* for strdup() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXN 79 %@NL@%
- %@NL@%
- struct cardstruct { %@AB@%/* global pattern */%@AE@%%@NL@%
- char *first, *last, *middle;%@NL@%
- long street_num;%@NL@%
- char *street, *city, *state;%@NL@%
- long zip;%@NL@%
- int area_code;%@NL@%
- long phone;%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- char *Str_Input();%@NL@%
- long Lint_Input();%@NL@%
- struct cardstruct card1, card2;%@NL@%
- %@NL@%
- for (i = 0; i < 2; i++) %@AB@%/* do twice */%@AE@%%@NL@%
- {%@NL@%
- printf("\nCard %d:\n\n", i + 1);%@NL@%
- %@NL@%
- card1.first = Str_Input("First Name");%@NL@%
- card1.last = Str_Input("Last Name");%@NL@%
- card1.middle = Str_Input("Middle Name");%@NL@%
- card1.street_num = Lint_Input("Street Number");%@NL@%
- card1.street = Str_Input("Street Name");%@NL@%
- card1.city = Str_Input("City");%@NL@%
- card1.state = Str_Input("State");%@NL@%
- card1.zip = Lint_Input("Zip Code");%@NL@%
- card1.area_code = (int)Lint_Input("Area Code");%@NL@%
- card1.phone = Lint_Input("Phone Number");%@NL@%
- %@NL@%
- if (i == 0)%@NL@%
- card2 = card1; %@AB@%/* structure assignment */%@AE@%%@NL@%
- }%@NL@%
- Showcard(card2);%@NL@%
- Showcard(card1);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- Showcard(struct cardstruct card)%@NL@%
- {%@NL@%
- printf("\n\n");%@NL@%
- %@NL@%
- printf("%s %s %s\n", card.first, card.middle, %@NL@%
- card.last);%@NL@%
- printf("%ld %s, %s, %s %ld\n", card.street_num, %@NL@%
- card.street, card.city, card.state,%@NL@%
- card.zip);%@NL@%
- printf("(%d) %ld\n", card.area_code, card.phone);%@NL@%
- }%@NL@%
- %@NL@%
- char *Str_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1], *ptr;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- buf[strlen(buf) - 1] = '\0'; %@AB@%/* strip '\n' */%@AE@%%@NL@%
- if (strlen(buf) == 0)%@NL@%
- exit(0);%@NL@%
- if ((ptr = strdup(buf)) == NULL)%@NL@%
- exit(0);%@NL@%
- return (ptr);%@NL@%
- }%@NL@%
- %@NL@%
- long Lint_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1];%@NL@%
- long num;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- if (sscanf(buf, "%ld", &num) != 1)%@NL@%
- exit(0);%@NL@%
- return (num);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CARD3.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\CARD3.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* card3.c -- demonstrates pointers to structures */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and stdin */%@AE@%%@NL@%
- <string.h> %@AB@%/* for strdup() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXN 79 %@NL@%
- %@NL@%
- struct cardstruct { %@AB@%/* global pattern */%@AE@%%@NL@%
- char *first, *last, *middle;%@NL@%
- long street_num;%@NL@%
- char *street, *city, *state;%@NL@%
- long zip;%@NL@%
- int area_code;%@NL@%
- long phone;%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- char *Str_Input();%@NL@%
- long Lint_Input();%@NL@%
- struct cardstruct card1, card2;%@NL@%
- %@NL@%
- for (i = 0; i < 2; i++) %@AB@%/* do twice */%@AE@%%@NL@%
- {%@NL@%
- printf("\nCard %d:\n\n", i + 1);%@NL@%
- %@NL@%
- card1.first = Str_Input("First Name");%@NL@%
- card1.last = Str_Input("Last Name");%@NL@%
- card1.middle = Str_Input("Middle Name");%@NL@%
- card1.street_num = Lint_Input("Street Number");%@NL@%
- card1.street = Str_Input("Street Name");%@NL@%
- card1.city = Str_Input("City");%@NL@%
- card1.state = Str_Input("State");%@NL@%
- card1.zip = Lint_Input("Zip Code");%@NL@%
- card1.area_code = (int)Lint_Input("Area Code");%@NL@%
- card1.phone = Lint_Input("Phone Number");%@NL@%
- %@NL@%
- if (i == 0)%@NL@%
- card2 = card1;%@NL@%
- }%@NL@%
- Showcard(&card2); %@AB@%/* pass addresses of structures */%@AE@%%@NL@%
- Showcard(&card1);%@NL@%
- %@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- Showcard(cardptr)%@NL@%
- struct cardstruct *cardptr; %@AB@%/* pointer receives an address */%@AE@%%@NL@%
- {%@NL@%
- printf("\n\n");%@NL@%
- %@NL@%
- printf("%s %s %s\n", cardptr->first, cardptr->middle, %@NL@%
- cardptr->last);%@NL@%
- printf("%ld %s, %s, %s %ld\n", cardptr->street_num, %@NL@%
- cardptr->street, cardptr->city, cardptr->state,%@NL@%
- cardptr->zip);%@NL@%
- printf("(%d) %ld\n", cardptr->area_code, cardptr->phone);%@NL@%
- }%@NL@%
- %@NL@%
- char *Str_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1], *ptr;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- buf[strlen(buf) - 1] = '\0'; %@AB@%/* strip '\n' */%@AE@%%@NL@%
- if (strlen(buf) == 0)%@NL@%
- exit(0);%@NL@%
- if ((ptr = strdup(buf)) == NULL)%@NL@%
- exit(0);%@NL@%
- return (ptr);%@NL@%
- }%@NL@%
- %@NL@%
- long Lint_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1];%@NL@%
- long num;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- if (sscanf(buf, "%ld", &num) != 1)%@NL@%
- exit(0);%@NL@%
- return (num);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CCOPY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\CCOPY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ccopy.c -- Copies a file, cutting blank lines and */%@AE@%%@NL@%
- %@AB@%/* leading space from lines of copy */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for FILE, BUFSIZ, NULL */%@AE@%%@NL@%
- <ctype.h> %@AB@%/* for iswhite() */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- FILE *fp_in, *fp_out;%@NL@%
- char buf[BUFSIZ];%@NL@%
- char *cp;%@NL@%
- %@NL@%
- if (argc != 3)%@NL@%
- {%@NL@%
- printf("usage: ccopy infile outfile\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if ((fp_in = fopen(argv[1], "r")) == NULL)%@NL@%
- {%@NL@%
- printf("Can't open %s for reading.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if ((fp_out = fopen(argv[2], "w")) == NULL)%@NL@%
- {%@NL@%
- printf("Can't open %s for writing.\n", argv[2]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- printf("Copying and Crushing: %s->%s ...", %@NL@%
- argv[1], argv[2]);%@NL@%
- %@NL@%
- while (fgets(buf, BUFSIZ, fp_in) != NULL)%@NL@%
- {%@NL@%
- cp = buf;%@NL@%
- if (*cp == '\n') %@AB@%/* blank line */%@AE@%%@NL@%
- continue;%@NL@%
- while (isspace(*cp))%@NL@%
- {%@NL@%
- ++cp;%@NL@%
- }%@NL@%
- if (*cp == '\0') %@AB@%/* empty line */%@AE@%%@NL@%
- continue;%@NL@%
- if (fputs(cp, fp_out) == EOF)%@NL@%
- {%@NL@%
- printf("\nError writing %s.\n", argv[2]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- printf("Done\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CCOPY2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\CCOPY2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ccopy2.c -- copies a file, cutting blank lines and */%@AE@%%@NL@%
- %@AB@%/* leading space from lines of copy */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Modified to demonstrate stdout and stderr */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for FILE, BUFSIZ, NULL */%@AE@%%@NL@%
- <ctype.h> %@AB@%/* for iswhite() */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- FILE *fp_in, *fp_out;%@NL@%
- char buf[BUFSIZ];%@NL@%
- char *cp;%@NL@%
- %@NL@%
- if (argc < 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "usage: ccopy infile {outfile}\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if ((fp_in = fopen(argv[1], "r")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't open.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if (argc == 3)%@NL@%
- {%@NL@%
- if ((fp_out = fopen(argv[2], "w")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't open.\n", argv[2]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- fp_out = stdout;%@NL@%
- %@NL@%
- while (fgets(buf, BUFSIZ, fp_in) != NULL)%@NL@%
- {%@NL@%
- cp = buf;%@NL@%
- if (*cp == '\n') %@AB@%/* blank line */%@AE@%%@NL@%
- continue;%@NL@%
- while (isspace(*cp))%@NL@%
- {%@NL@%
- ++cp;%@NL@%
- }%@NL@%
- if (*cp == '\0') %@AB@%/* empty line */%@AE@%%@NL@%
- continue;%@NL@%
- if (fputs(cp, fp_out) == EOF)%@NL@%
- {%@NL@%
- fprintf(stderr, "Error writing.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- if (! feof(fp_in)) %@AB@%/* error reading? */%@AE@%%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error reading.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CH2000.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\CH2000.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ch2000.c -- fill screen with 2000 characters */%@AE@%%@NL@%
- %@AB@%/* This program demonstrates direct memory access */%@AE@%%@NL@%
- %@AB@%/* of video memory. It is set up for the MDA. */%@AE@%%@NL@%
- %@AB@%/* Assign CGAMEM instead of MONMEM to screen for */%@AE@%%@NL@%
- %@AB@%/* CGA and CGA-compatible modes. */%@AE@%%@NL@%
- %@AB@%/* Press a key to fill; press Esc to quit. */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- typedef unsigned short (far * VIDMEM);%@NL@%
- MONMEM ((VIDMEM) (0xB000L << 16)) %@AB@%/* monochrome */%@AE@%%@NL@%
- CGAMEM ((VIDMEM) (0xB800L << 16)) %@AB@%/* cga, ega */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%CHARS 2000 %@NL@%
- AMASK 0xFF %@AB@%/* keep attribute in range */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned ch; %@AB@%/* character to be displayed */%@AE@%%@NL@%
- unsigned attrib = 7; %@AB@%/* initial attribute */%@AE@%%@NL@%
- VIDMEM screen; %@AB@%/* pointer to video RAM */%@AE@%%@NL@%
- int offset; %@AB@%/* location on screen */%@AE@%%@NL@%
- %@NL@%
- screen = MONMEM; %@AB@%/* monochrome initialization */%@AE@%%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- for (offset = 0; offset < CHARS; offset++)%@NL@%
- *(screen + offset) = ((attrib++ & AMASK) << 8) | ch;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CH2001.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\CH2001.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ch2001.c -- fill screen with 2000 characters */%@AE@%%@NL@%
- %@AB@%/* This program demonstrates direct memory access */%@AE@%%@NL@%
- %@AB@%/* of video memory. It uses the current video mode */%@AE@%%@NL@%
- %@AB@%/* value to select the proper video RAM address. */%@AE@%%@NL@%
- %@AB@%/* Press a key to fill; press Esc to quit. */%@AE@%%@NL@%
- %@AB@%/* Program list: ch2001.c, scrfun.lib */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- typedef unsigned short (far * VIDMEM);%@NL@%
- MONMEM ((VIDMEM) (0xB000L << 16)) %@AB@%/* monochrome */%@AE@%%@NL@%
- CGAMEM ((VIDMEM) (0xB800L << 16)) %@AB@%/* cga, ega */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%CHARS 2000 %@NL@%
- %@AI@%#define %@AE@%AMASK 0xFF %@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned ch, mode;%@NL@%
- unsigned attrib = 7;%@NL@%
- VIDMEM screen; %@AB@%/* pointer to video RAM */%@AE@%%@NL@%
- int offset;%@NL@%
- %@NL@%
- if ((mode = Getvmode()) == TEXTMONO)%@NL@%
- screen = MONMEM;%@NL@%
- else if (mode == TEXTC80 || mode == TEXTBW80)%@NL@%
- screen = CGAMEM;%@NL@%
- else%@NL@%
- exit(1);%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- for (offset = 0; offset < CHARS; offset++)%@NL@%
- *(screen + offset) = ((attrib++ & AMASK) << 8) | ch;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHANGE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\CHANGE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* change.c -- a changemaking program demonstrates */%@AE@%%@NL@%
- %@AB@%/* how pointers advance the correct */%@AE@%%@NL@%
- %@AB@%/* number of bytes based on type */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NCOINS (4) %@NL@%
- CENT (0x9b) %@AB@%/* IBM PC cent character */%@AE@%%@NL@%
- %@AI@%#define %@AE@%WAIT printf("(Press any key to continue)"); \ %@NL@%
- getch(); printf("\n\n") %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static int coins[NCOINS] = {25, 10, 5, 1};%@NL@%
- int *coin_ptr, i = 0; %@NL@%
- int pennies1, pennies2, count;%@NL@%
- float amount;%@NL@%
- %@NL@%
- printf("Enter an amount and I will ");%@NL@%
- printf(" give you change.\nAmount: ");%@NL@%
- if (scanf("%f", &amount) != 1)%@NL@%
- {%@NL@%
- printf("I don't know how to change that!\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- pennies2 = pennies1 = (int)(amount * 100.0);%@NL@%
- %@NL@%
- coin_ptr = coins;%@NL@%
- for (i = 0; i < NCOINS; ++i)%@NL@%
- {%@NL@%
- WAIT;%@NL@%
- count = 0;%@NL@%
- while ((pennies1 -= coins[i]) >= -1)%@NL@%
- ++count;%@NL@%
- if (count > 0)%@NL@%
- {%@NL@%
- printf("%4d %2d%c", count, coins[i], CENT);%@NL@%
- printf(" coins by array offset.\n");%@NL@%
- }%@NL@%
- if (pennies1 == 0)%@NL@%
- break;%@NL@%
- pennies1 += coins[i];%@NL@%
- %@NL@%
- count = 0;%@NL@%
- while ((pennies2 -= *coin_ptr) >= -1)%@NL@%
- ++count;%@NL@%
- if (count > 0)%@NL@%
- {%@NL@%
- printf("%4d %2d%c", count, *coin_ptr, CENT);%@NL@%
- printf(" coins by pointer indirection.\n");%@NL@%
- }%@NL@%
- if (pennies2 == 0)%@NL@%
- break;%@NL@%
- pennies2 += *coin_ptr;%@NL@%
- ++coin_ptr;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHANGE2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\CHANGE2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* change2.c -- modified to demonstrate passing */%@AE@%%@NL@%
- %@AB@%/* an address to a function */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NCOINS (4) %@NL@%
- CENT (0x9b) %@AB@%/* IBM PC cent character */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static int coins[NCOINS] = {25, 10, 5, 1};%@NL@%
- int pennies;%@NL@%
- float amount;%@NL@%
- %@NL@%
- printf("Enter an amount and I will ");%@NL@%
- printf(" give you change.\nAmount: ");%@NL@%
- if (scanf("%f", &amount) != 1)%@NL@%
- {%@NL@%
- printf("I don't know how to change that!\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- pennies = (int)(amount * 100.0);%@NL@%
- %@NL@%
- Show_change( coins, &coins[NCOINS], pennies);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- Show_change( int amts[], int *end, int due)%@NL@%
- {%@NL@%
- int count;%@NL@%
- %@NL@%
- while ( amts < end ) %@AB@%/* compare pointers */%@AE@%%@NL@%
- {%@NL@%
- count = 0;%@NL@%
- while ((due -= *amts) >= -1)%@NL@%
- {%@NL@%
- ++count;%@NL@%
- }%@NL@%
- if (count > 0)%@NL@%
- printf("%4d %2d%c\n", count, *amts, CENT);%@NL@%
- if (due == 0)%@NL@%
- break;%@NL@%
- due += *amts;%@NL@%
- %@NL@%
- ++amts; %@AB@%/* increment a pointer */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHARS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\CHARS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* chars.c -- shows some variables of type char */%@AE@%%@NL@%
- %@AB@%/* as both characters and integers */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch1 = 'A', ch2 = 'a';%@NL@%
- %@NL@%
- printf("The character %c has ASCII code %d\n", ch1, ch1);%@NL@%
- printf("If you add ten, you get %c\n", ch1 + 10);%@NL@%
- printf("The character %c has ASCII code %d\n", ch2, ch2);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHOOSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\CHOOSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* choose.c -- an array of pointers to functions */%@AE@%%@NL@%
- %@AB@%/* used to create a menu */%@AE@%%@NL@%
- %@NL@%
- void Choice1(), Choice2(), Choice3();%@NL@%
- %@NL@%
- void (*Dochoice[3])() = {Choice1, Choice2, Choice3};%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- printf("Select 1, 2 or 3: ");%@NL@%
- ch = getch(); putch(ch);%@NL@%
- ch -= '1';%@NL@%
- if (ch < 0 || ch > 2)%@NL@%
- printf("\nNo such choice.\n");%@NL@%
- else%@NL@%
- Dochoice[ch]();%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Choice1(void) %@NL@%
- {%@NL@%
- printf("\nThis is choice 1\n");%@NL@%
- }%@NL@%
- %@NL@%
- void Choice2(void) %@NL@%
- {%@NL@%
- printf("\nThis is choice 2\n");%@NL@%
- }%@NL@%
- %@NL@%
- void Choice3(void) %@NL@%
- {%@NL@%
- printf("\nThis is choice 3\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COL256.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\COL256.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* col256.c -- show 256 colors in mode 19 */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%ROWS 16 %@NL@%
- %@AI@%#define %@AE@%COLS 16 %@NL@%
- main()%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES256COLOR;%@NL@%
- short xmax, ymax; %@AB@%/* screen size */%@AE@%%@NL@%
- short xcs[ROWS][COLS]; %@AB@%/* coordinates of the */%@AE@%%@NL@%
- short ycs[ROWS][COLS]; %@AB@%/* 256 rectangles */%@AE@%%@NL@%
- short row, col;%@NL@%
- %@NL@%
- %@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "%d mode not supported\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- %@NL@%
- xmax = vc.numxpixels - 1;%@NL@%
- ymax = vc.numypixels - 1;%@NL@%
- %@NL@%
- %@AB@%/* Compute an interior point for each rectangle. */%@AE@%%@NL@%
- for (col = 0; col < COLS; col++)%@NL@%
- for (row = 0; row < ROWS; row++)%@NL@%
- {%@NL@%
- xcs[row][col] = col * xmax / COLS + 5;%@NL@%
- ycs[row][col] = row * ymax / ROWS + 5;%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* draw outside boundary */%@AE@%%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GBORDER, 0, 0, xmax, ymax);%@NL@%
- %@NL@%
- %@AB@%/* draw gridwork */%@AE@%%@NL@%
- for (col = 1; col < COLS ; col++)%@NL@%
- {%@NL@%
- _moveto(col * (xmax + 1) / COLS, 0);%@NL@%
- _lineto(col * (xmax + 1) / COLS, ymax);%@NL@%
- }%@NL@%
- for (row = 1; row < ROWS; row++)%@NL@%
- {%@NL@%
- _moveto(0, row * (ymax + 1) / ROWS);%@NL@%
- _lineto(xmax, row * (ymax + 1) / ROWS);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* fill in rectangles with palette colors */%@AE@%%@NL@%
- for (col = 0; col < COLS; col++)%@NL@%
- for (row = 0; row < ROWS; row++)%@NL@%
- {%@NL@%
- _setcolor(row * ROWS + col);%@NL@%
- _floodfill(xcs[row][col], ycs[row][col],1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* terminate program */%@AE@%%@NL@%
- getch();%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONDITN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\CONDITN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* conditn.c -- attempt to use conditional op */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- { %@NL@%
- int n, m; %@NL@%
- %@NL@%
- n = 2; %@NL@%
- m = (n != 2) : 0 ? 1; %@AB@%/* almost right */%@AE@%%@NL@%
- printf("%d\n", m); %@NL@%
- } %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONTINUE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\CONTINUE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* continue.c -- shows CONTINUE in loop */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int sw = 0;%@NL@%
- char ch;%@NL@%
- while (1) %@AB@%/* endless loop */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* print current status */%@AE@%%@NL@%
- if (sw)%@NL@%
- printf("\nSwitch is ON\n");%@NL@%
- else%@NL@%
- printf("\nSwitch is OFF\n");%@NL@%
- %@NL@%
- printf("Do you want to quit? ");%@NL@%
- if (ch = getche() == 'y')%@NL@%
- break; %@AB@%/* exit loop on yes */%@AE@%%@NL@%
- %@NL@%
- printf("\nDo you want to toggle the switch? ");%@NL@%
- if (ch = getche() != 'y')%@NL@%
- continue; %@AB@%/* restart loop on yes */%@AE@%%@NL@%
- %@NL@%
- sw = !sw; %@AB@%/* toggle switch */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONTROL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\CONTROL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* control.c -- demonstrate string justification */%@AE@%%@NL@%
- %@AB@%/* using printf() */%@AE@%%@NL@%
- %@NL@%
- char Some_text[] = "Some Text";%@NL@%
- char Left_control[] = "<<%-15s>>";%@NL@%
- char Right_control[] = "<<%15s>>";%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("Select l)eft r)ight or q)uit: ");%@NL@%
- ch = getch();%@NL@%
- putch( ch );%@NL@%
- %@NL@%
- printf("\n\n");%@NL@%
- switch((int) ch)%@NL@%
- {%@NL@%
- case 'l':%@NL@%
- case 'L':%@NL@%
- printf(Left_control, Some_text);%@NL@%
- break;%@NL@%
- case 'r':%@NL@%
- case 'R':%@NL@%
- printf(Right_control, Some_text);%@NL@%
- break;%@NL@%
- case 'q':%@NL@%
- case 'Q':%@NL@%
- exit (0);%@NL@%
- default:%@NL@%
- printf("Huh?");%@NL@%
- break;%@NL@%
- }%@NL@%
- printf("\n\n");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONVERT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\CONVERT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* convert.c -- converts Farenheit temprature */%@AE@%%@NL@%
- %@AB@%/* to Centigrade; gets value from user */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float ftemp, ctemp;%@NL@%
- %@NL@%
- printf("What is the temprature in Farenheit? ");%@NL@%
- scanf("%f", &ftemp);%@NL@%
- ctemp = (ftemp - 32.0) * 5 / 9.0;%@NL@%
- %@NL@%
- printf("The temprature in Centigrade is %5.2f", ctemp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DBLBAR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\DBLBAR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* dblbar.c -- prints header using */%@AE@%%@NL@%
- %@AB@%/* line() function */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%DOUBLE_BAR 205 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- void line(); %@AB@%/* declare line() function */%@AE@%%@NL@%
- %@NL@%
- line(10); %@AB@%/* call line() function */%@AE@%%@NL@%
- printf("dblbar.c -- prints header using\n");%@NL@%
- printf("line() function\n");%@NL@%
- line(50); %@AB@%/* call line() again */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- void line() %@AB@%/* function definition */%@AE@%%@NL@%
- {%@NL@%
- int pos;%@NL@%
- for (pos = 1; pos <= 40; pos++)%@NL@%
- putch(DOUBLE_BAR);%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DEBUG.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\DEBUG.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* DEBUG.C -- for practice with debugger */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char response;%@NL@%
- int number, max_numbers = 5, count = 0, total = 0;%@NL@%
- float average;%@NL@%
- %@NL@%
- printf("Continue (y/n)? ");%@NL@%
- response = getche();%@NL@%
- while ((response != 'n') && (count < max_numbers))%@NL@%
- printf("\nEnter a number: ");%@NL@%
- scanf("%d", &number);%@NL@%
- total += number;%@NL@%
- printf("Continue (y/n)? ");%@NL@%
- response = getche();%@NL@%
- average = total / count;%@NL@%
- printf("\nTotal is %d\n", total);%@NL@%
- printf("Average is %f\n", average);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DIALOG.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\DIALOG.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* dialog.c -- a conversation using gets() and puts() */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and BUFSIZ */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%THE_QUESTION \ %@NL@%
- "And what is your view on the current price of corn\n\%@NL@%
- and the stability of our trade import balance?"%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char name[BUFSIZ],%@NL@%
- buf[BUFSIZ];%@NL@%
- extern char *gets();%@NL@%
- %@NL@%
- name[0] = '\0'; %@AB@%/* clear the name */%@AE@%%@NL@%
- %@NL@%
- puts("\n\nHi there. And what is your name?");%@NL@%
- %@NL@%
- if (gets(name) != NULL && name[0] != '\0')%@NL@%
- {%@NL@%
- printf("\nPleased to meet you, %s.\n", name);%@NL@%
- puts(THE_QUESTION);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * force an extra <enter> before replying.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- do%@NL@%
- {%@NL@%
- if (gets(buf) == NULL)%@NL@%
- break;%@NL@%
- %@NL@%
- } while (*buf != '\0'); %@AB@%/* wait for empty line */%@AE@%%@NL@%
- %@NL@%
- puts("Sorry. I needed to think about that.");%@NL@%
- printf("Nice talking to you, %s.\n", name);%@NL@%
- }%@NL@%
- else%@NL@%
- puts("How rude!");%@NL@%
- %@NL@%
- puts("Goodbye.");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DIGSUM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\DIGSUM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* digsum.c -- sum digits in input */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- int digits = 0; %@AB@%/* number of digits in input */%@AE@%%@NL@%
- int others = 0; %@AB@%/* number of non-digits in input */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- while ((ch = getchar()) != EOF)%@NL@%
- if (ch <= '0' && ch >= '9')%@NL@%
- others++;%@NL@%
- else%@NL@%
- digits++;%@NL@%
- printf("digits = %d, others = %d", digits, others);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DIRX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\DIRX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* dirx.c -- directory examples */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%SUBDIR "SUBDIR" %@NL@%
- %@AI@%#define %@AE@%SUBSUBDIR "SUBSUB" %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *current_dir;%@NL@%
- void Err();%@NL@%
- %@NL@%
- if ((current_dir = getcwd(NULL, 0)) == NULL)%@NL@%
- Err("getcwd()", "Can't get current directory.");%@NL@%
- %@NL@%
- if (mkdir(SUBDIR) != 0)%@NL@%
- Err( SUBSUBDIR, "Can't make directory." );%@NL@%
- %@NL@%
- if (chdir(SUBDIR) != 0)%@NL@%
- Err( SUBDIR, "Can't cd into directory." );%@NL@%
- %@NL@%
- if (mkdir(SUBSUBDIR) != 0)%@NL@%
- Err( SUBSUBDIR, "Can't make directory." );%@NL@%
- %@NL@%
- if (chdir(current_dir) != 0)%@NL@%
- Err( SUBDIR, "Can't cd back to." );%@NL@%
- %@NL@%
- if (rmdir(SUBDIR) != 0)%@NL@%
- Err( SUBDIR, "Can't remove directory." );%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Err(char *what, char *msg)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": %s\n", what, msg );%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\DO.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* DO.C -- a simple do-while loop */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i = 1;%@NL@%
- do%@NL@%
- {%@NL@%
- printf("%d\n", i);%@NL@%
- i++;%@NL@%
- }%@NL@%
- while (i < 11);%@NL@%
- printf("Done!\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DOTS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\DOTS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* dots.c -- illustrates the _setcolor(), _setpixel(), */%@AE@%%@NL@%
- %@AB@%/* and _selectpalette() functions from the */%@AE@%%@NL@%
- %@AB@%/* QuickC graphics library */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- BKCOLS 8 %@AB@%/* number of background colors */%@AE@%%@NL@%
- PALNUM 4 %@AB@%/* number of palettes */%@AE@%%@NL@%
- long Bkcolors[BKCOLS] = {_BLACK, _BLUE, _GREEN, _CYAN, _RED,%@NL@%
- _MAGENTA, _BROWN, _WHITE};%@NL@%
- main (argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- unsigned int col, row;%@NL@%
- short color = 0;%@NL@%
- int bkc_index = 1; %@AB@%/* blue background */%@AE@%%@NL@%
- short palette = 0; %@AB@%/* red, green, brown */%@AE@%%@NL@%
- int firstcol, firstrow, lastrow, lastcol;%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- int ch;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- %@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- printf("Can't do that mode.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- firstcol = vc.numxpixels / 5;%@NL@%
- firstrow = vc.numypixels / 5;%@NL@%
- lastcol = 4 * vc.numxpixels / 5;%@NL@%
- lastrow = 4 * vc.numypixels / 5;%@NL@%
- _selectpalette(palette);%@NL@%
- _setbkcolor (Bkcolors[bkc_index]);%@NL@%
- for (col = firstcol; col <= lastcol; ++col)%@NL@%
- {%@NL@%
- _setcolor((++color / 3) % vc.numcolors);%@NL@%
- for (row = firstrow; row <= lastrow; ++row)%@NL@%
- _setpixel(col, row);%@NL@%
- }%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch == 'p')%@NL@%
- _selectpalette(++palette % PALNUM);%@NL@%
- else if (ch == 'b')%@NL@%
- _setbkcolor(Bkcolors[++bkc_index % BKCOLS]);%@NL@%
- }%@NL@%
- _setvideomode(_DEFAULTMODE); %@AB@%/* reset orig. mode */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DOWHILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\DOWHILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* dowhile.c -- misuse of do while loop */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i = 0;%@NL@%
- %@NL@%
- do while (i < 10)%@NL@%
- {%@NL@%
- printf("Happy Fourth of July!\n");%@NL@%
- i++;%@NL@%
- }%@NL@%
- printf("VOOOM\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DOWHILE2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\DOWHILE2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* dowhile2.c -- ok use of do while loop */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i = 0;%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- printf("Happy Fourth of July!\n");%@NL@%
- i++;%@NL@%
- } while (i < 10) ;%@NL@%
- printf("VOOOM\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DRAWCHAR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\DRAWCHAR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* drawchar.c -- drawing module for grafdraw.c */%@AE@%%@NL@%
- %@AB@%/* translates keystrokes to graphic characters, */%@AE@%%@NL@%
- %@AB@%/* manages cursor control and function keys */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"keys.h" %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@AI@%#include %@AE@%"grafchar.h" %@NL@%
- extern unsigned char Grchr[]; %@AB@%/* defined in grafchar.c */%@AE@%%@NL@%
- %@NL@%
- void Draw_chars()%@NL@%
- {%@NL@%
- int ch, chout;%@NL@%
- unsigned char attrib = NORMAL;%@NL@%
- unsigned char draw = TRUE;%@NL@%
- %@NL@%
- chout = Grchr[0]; %@AB@%/* default graphics character */%@AE@%%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch >= '0' && ch <= '_')%@NL@%
- chout = Grchr[ch - '0'];%@NL@%
- %@AB@%/* this maps the 0 key to the first */%@AE@%%@NL@%
- %@AB@%/* graphics character, etc. */%@AE@%%@NL@%
- else if (ch == SPACE)%@NL@%
- chout = SPACE;%@NL@%
- else if (ch == 0) %@AB@%/* process cursor keys */%@AE@%%@NL@%
- { %@AB@%/* and function keys */%@AE@%%@NL@%
- ch = getch();%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case PU : draw = FALSE;%@NL@%
- break;%@NL@%
- case PD : draw = TRUE;%@NL@%
- break;%@NL@%
- case UP : if (draw)%@NL@%
- Write_ch_atr(chout, attrib,%@NL@%
- PAGE, 1);%@NL@%
- if (!Cursup())%@NL@%
- putch(BEEP);%@NL@%
- break;%@NL@%
- case DN : if (draw)%@NL@%
- Write_ch_atr(chout, attrib,%@NL@%
- PAGE, 1);%@NL@%
- if (!Cursdn_lim(BOTLINE))%@NL@%
- putch(BEEP);%@NL@%
- break;%@NL@%
- case LT : if (draw)%@NL@%
- Write_ch_atr(chout, attrib,%@NL@%
- PAGE, 1);%@NL@%
- if (!Curslt())%@NL@%
- putch(BEEP);%@NL@%
- break;%@NL@%
- case RT : if (draw)%@NL@%
- Write_ch_atr(chout, attrib,%@NL@%
- PAGE, 1);%@NL@%
- if (!Cursrt())%@NL@%
- putch(BEEP);%@NL@%
- break;%@NL@%
- case F1 : attrib = NORMAL; break;%@NL@%
- case F2 : attrib = VIDREV; break;%@NL@%
- case F3 : attrib ^= BLINK; break;%@NL@%
- case F4 : attrib ^= INTENSE; break;%@NL@%
- default : putch(BEEP);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EGATOVGA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\EGATOVGA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* egatovga.c -- converts ega color values to vga */%@AE@%%@NL@%
- %@AB@%/* color values. */%@AE@%%@NL@%
- %@NL@%
- long Ega_to_vga(egacolor)%@NL@%
- int egacolor; %@AB@%/* ega color value */%@AE@%%@NL@%
- {%@NL@%
- static long vgavals[6] = {0x2a0000L, 0x002a00L,%@NL@%
- 0x00002aL, 0x150000L,%@NL@%
- 0x001500L, 0x000015L};%@NL@%
- %@AB@%/* array holds VGA equivalents to EGA bits */%@AE@%%@NL@%
- long vgacolor = 0L; %@AB@%/* vga color value */%@AE@%%@NL@%
- int bit;%@NL@%
- %@NL@%
- %@AB@%/* convert each bit to equivalent, and sum */%@AE@%%@NL@%
- for (bit = 0; bit < 6; bit++)%@NL@%
- vgacolor += ((egacolor >> bit) &1) * vgavals[bit];%@NL@%
- return (vgacolor);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EGGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\EGGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* eggs.c -- draws colorful eggs */%@AE@%%@NL@%
- %@AB@%/* This program illustrates use of the video configuration */%@AE@%%@NL@%
- %@AB@%/* structure, the _ellipse() function, the effect of over- */%@AE@%%@NL@%
- %@AB@%/* lapping solid figures, and a the use of logical coordinates. */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- short xcent[3], ycent[3]; %@AB@%/* egg centers */%@AE@%%@NL@%
- short xsize, ysize; %@AB@%/* egg limits */%@AE@%%@NL@%
- int egg;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- printf("Can't open mode %d\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- xsize = 0.3 * vc.numxpixels;%@NL@%
- ysize = 0.3 * vc.numypixels;%@NL@%
- xcent[0] = 0.3 * vc.numxpixels;%@NL@%
- xcent[1] = 0.5 * vc.numxpixels;%@NL@%
- xcent[2] = 0.7 * vc.numxpixels;%@NL@%
- ycent[0] = ycent[2] = 0.4 * vc.numypixels;%@NL@%
- ycent[1] = 0.6 * vc.numypixels;%@NL@%
- %@NL@%
- _selectpalette(0);%@NL@%
- _setbkcolor(_MAGENTA);%@NL@%
- for (egg = 0; egg < 3; egg++)%@NL@%
- {%@NL@%
- _setlogorg(xcent[egg], ycent[egg]);%@NL@%
- _setcolor(egg + 1);%@NL@%
- _ellipse(_GFILLINTERIOR, -xsize, -ysize, xsize, ysize);%@NL@%
- }%@NL@%
- _settextposition(24, 0);%@NL@%
- _settextcolor(1);%@NL@%
- _outtext("Strike any key to terminate.");%@NL@%
- getch();%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ERR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\ERR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* err.c -- illustrates __FILE__ and __LINE__ in */%@AE@%%@NL@%
- %@AB@%/* tracing a small program */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%ERR printf("Tracing: \"%s\" line %d\n",\ %@NL@%
- __FILE__, __LINE__);%@NL@%
- main()%@NL@%
- {%@NL@%
- ERR%@NL@%
- err1();%@NL@%
- ERR%@NL@%
- err2();%@NL@%
- ERR%@NL@%
- }%@NL@%
- %@NL@%
- err1()%@NL@%
- {%@NL@%
- ERR%@NL@%
- err2();%@NL@%
- }%@NL@%
- %@NL@%
- err2()%@NL@%
- {%@NL@%
- ERR%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EXPO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\EXPO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* expo.c -- uses exp() function to */%@AE@%%@NL@%
- %@AB@%/* calculate powers */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int expo(number, power);%@NL@%
- int number, power;%@NL@%
- %@NL@%
- printf("Enter a number: ");%@NL@%
- scanf("%d", &number);%@NL@%
- printf("Raise to what power? ");%@NL@%
- scanf("%d", &power);%@NL@%
- %@NL@%
- printf("Result: %d", expo(number, power));%@NL@%
- }%@NL@%
- %@NL@%
- int expo(number, power)%@NL@%
- {%@NL@%
- int count, value;%@NL@%
- int total = 1; %@AB@%/* store value of calculation */%@AE@%%@NL@%
- if (power < 0) %@AB@%/* reject negative exponents */%@AE@%%@NL@%
- {%@NL@%
- printf("Error in expo(): negative exponent\n");%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- if (power == 0) %@AB@%/* any number to 0 power is 1 */%@AE@%%@NL@%
- return(1);%@NL@%
- %@NL@%
- if (power == 1) %@AB@%/* any number to 1 power is itself */%@AE@%%@NL@%
- return(number);%@NL@%
- %@NL@%
- %@AB@%/* calculate for power > 1 */%@AE@%%@NL@%
- for (count = 1; count <= power; count++)%@NL@%
- total *= number;%@NL@%
- return(total);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EXTERNAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\EXTERNAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* external.c -- shows an external variable */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%PI 3.14159 %@NL@%
- int length; %@AB@%/* external (global) variable */%@AE@%%@NL@%
- %@AB@%/* declared before main () */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- void square(), triangle(), circle();%@NL@%
- %@NL@%
- printf("What length do you want to use? ");%@NL@%
- scanf("%d", &length);%@NL@%
- %@NL@%
- square(); %@AB@%/* calculate areas */%@AE@%%@NL@%
- triangle();%@NL@%
- circle();%@NL@%
- }%@NL@%
- %@NL@%
- void square()%@NL@%
- {%@NL@%
- float area;%@NL@%
- area = length * length;%@NL@%
- printf("A square with sides of %d has an area of %f\n",%@NL@%
- length, area);%@NL@%
- }%@NL@%
- %@NL@%
- void triangle()%@NL@%
- {%@NL@%
- float area;%@NL@%
- area = (length * length) / 2;%@NL@%
- printf("A right triangle with sides of %d has an area %f\n",%@NL@%
- length, area);%@NL@%
- }%@NL@%
- %@NL@%
- void circle()%@NL@%
- {%@NL@%
- float area;%@NL@%
- area = (length * length * PI);%@NL@%
- printf("A circle with radius of %d has area of %f\n",%@NL@%
- length, area);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FIELDS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\FIELDS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* fields.c -- shows the same number with different */%@AE@%%@NL@%
- %@AB@%/* field widths and number of decimals */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float f = 123.4560;%@NL@%
- %@NL@%
- printf("%12.6f\n", f);%@NL@%
- printf("%8.4f\n", f);%@NL@%
- printf("%8.3f\n", f);%@NL@%
- printf("%8.2f\n", f);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\FILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* file.c -- the file I/O routines for texed */%@AE@%%@NL@%
- %@NL@%
- Load_file()%@NL@%
- {%@NL@%
- printf("\nLoading ..... done.\n");%@NL@%
- }%@NL@%
- %@NL@%
- Save_file()%@NL@%
- {%@NL@%
- printf("\nSaving ...... done.\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FLOATS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\FLOATS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* floats.c -- show floating values in regular */%@AE@%%@NL@%
- %@AB@%/* and exponential format */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float f1 = 2500.125, f2 = 0.0033, f3 = -50.99;%@NL@%
- %@NL@%
- printf("%f\t %e\n\n", f1, f1);%@NL@%
- printf("%f\t %e\n\n", f2, f2);%@NL@%
- printf("%f\t %e\n", f3, f3);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FMENU.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\FMENU.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* fmenu.c -- demonstrates file renaming, etc. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXPATH (80) %@NL@%
- char From_name[MAXPATH],%@NL@%
- To_name[MAXPATH];%@NL@%
- %@NL@%
- int Input(char *prompt, char buf[])%@NL@%
- {%@NL@%
- printf("%s: ", prompt);%@NL@%
- if (gets(buf) == NULL || *buf == '\0')%@NL@%
- return (0);%@NL@%
- return (1);%@NL@%
- }%@NL@%
- void Rename(void)%@NL@%
- {%@NL@%
- printf("->Rename/move\n");%@NL@%
- if (!Input("From", From_name)) return;%@NL@%
- if (!Input("To", To_name)) return;%@NL@%
- if (rename(From_name, To_name) != 0)%@NL@%
- perror("RENAME");%@NL@%
- else%@NL@%
- printf("Renamed: \"%s\" -> \"%s\"\n", %@NL@%
- From_name, To_name);%@NL@%
- }%@NL@%
- void Remove(void)%@NL@%
- {%@NL@%
- printf("->Remove\n");%@NL@%
- if (!Input("Remove", From_name)) return;%@NL@%
- if (!Input("Are You Sure", To_name)) return;%@NL@%
- if (*To_name != 'y' && *To_name != 'Y')%@NL@%
- return;%@NL@%
- if (remove(From_name) != 0)%@NL@%
- perror(From_name);%@NL@%
- else%@NL@%
- printf("Removed: \"%s\"\n", From_name);%@NL@%
- }%@NL@%
- void Maketemp(void)%@NL@%
- {%@NL@%
- printf("->Maketemp\n");%@NL@%
- if (!Input("In What Directory", From_name))%@NL@%
- return;%@NL@%
- (void)strcat(From_name, "\\XXXXXX");%@NL@%
- if (mktemp(From_name) == NULL)%@NL@%
- printf("Can't create a unique name.\n");%@NL@%
- else%@NL@%
- printf("Created: \"%s\"\n", From_name);%@NL@%
- }%@NL@%
- void Quit(void)%@NL@%
- {%@NL@%
- printf("->Quit\n");%@NL@%
- if (!Input("Are You Sure", From_name))%@NL@%
- return;%@NL@%
- if (*From_name != 'y' && *From_name != 'Y')%@NL@%
- return;%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static void (*doit[])() = {Rename, Remove, Maketemp, Quit};%@NL@%
- int ch;%@NL@%
- %@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("--------------------------------------------\n");%@NL@%
- printf("1) Rename/move a file or rename a directory.\n");%@NL@%
- printf("2) Remove a file.\n");%@NL@%
- printf("3) Make a unique temporary file.\n");%@NL@%
- printf("4) Quit.\n");%@NL@%
- printf("--------------------------------------------\n");%@NL@%
- printf("Select: ");%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- ch = getchar();%@NL@%
- } while (ch < '1' || ch > '4');%@NL@%
- getchar(); %@AB@%/* gobble trailing newline */%@AE@%%@NL@%
- printf("%c\n\n", ch);%@NL@%
- ch -= '1';%@NL@%
- doit[ch]();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FORLOOP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\FORLOOP.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* FORLOOP.C -- a simple for loop that */%@AE@%%@NL@%
- %@AB@%/* counts to ten */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- for (i = 1; i <= 10; i++)%@NL@%
- {%@NL@%
- printf("%d\n",i); %@AB@%/* body of loop */%@AE@%%@NL@%
- }%@NL@%
- printf("All done!\n");%@NL@%
- %@AB@%/* executed when i > 10 */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FORMATS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\FORMATS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* formats.c -- shows what happens when format */%@AE@%%@NL@%
- %@AB@%/* doesn't match data type */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i = 5;%@NL@%
- printf("As integer: %d\n", i);%@NL@%
- printf("As long integer: %ld\n", i);%@NL@%
- printf("As exponential: %e\n", i);%@NL@%
- printf("As float: %f\n", i);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GALAX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\GALAX.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GALAX.C -- creates an ellipse by selecting */%@AE@%%@NL@%
- %@AB@%/* from random pixels */%@AE@%%@NL@%
- %@NL@%
- <graph.h> %@AB@%/* for graphics */%@AE@%%@NL@%
- <math.h> %@AB@%/* for sqrt() */%@AE@%%@NL@%
- <conio.h> %@AB@%/* for kbhit() */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int pixels, radius = 50;%@NL@%
- double center_x = 320, center_y = 100,%@NL@%
- xpos, ypos;%@NL@%
- srand(0);%@NL@%
- _setvideomode(_HRESBW);%@NL@%
- _setcolor(1);%@NL@%
- for (pixels = 1; pixels < 25000; pixels++)%@NL@%
- {%@NL@%
- %@AB@%/* draws filled ellipse, due */%@AE@%%@NL@%
- %@AB@%/* to dimensions of hires screen */%@AE@%%@NL@%
- %@AB@%/* generate random location */%@AE@%%@NL@%
- xpos = rand() % 639;%@NL@%
- ypos = rand() % 199;%@NL@%
- if (sqrt %@AB@%/* is distance within radius? */%@AE@%%@NL@%
- ((xpos - center_x) * (xpos - center_x)%@NL@%
- + (ypos - center_y) * (ypos - center_y))%@NL@%
- < radius)%@NL@%
- _setpixel(xpos, ypos);%@NL@%
- if (kbhit() )%@NL@%
- break; %@AB@%/* exit if key pressed */%@AE@%%@NL@%
- }%@NL@%
- getch(); %@AB@%/* freeze screen until key pressed */%@AE@%%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETCH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\GETCH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* getch.c -- using getch() */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- int count = 1;%@NL@%
- %@NL@%
- printf("Please enter a word.\n");%@NL@%
- while (getch() != '\r')%@NL@%
- printf("%d.. ", count++);%@NL@%
- printf("\n%d characters altogether\n", count - 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETCHAR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\GETCHAR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* getchar.c -- using getchar() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- int count = 1;%@NL@%
- %@NL@%
- printf("Please enter a word.\n");%@NL@%
- while (getchar() != '\n') %@AB@%/* here it is */%@AE@%%@NL@%
- printf("%d.. ", count++);%@NL@%
- printf("\n%d characters altogether\n", count - 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETCHE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\GETCHE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* getche.c -- using getche() */%@AE@%%@NL@%
- <conio.h> %@AB@%/* note different file included */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- int count = 1;%@NL@%
- %@NL@%
- printf("Please enter a word.\n");%@NL@%
- while (getche() != '\r') %@AB@%/* changed comparison */%@AE@%%@NL@%
- printf("%d.. ", count++); %@NL@%
- printf("\n%d characters altogether\n", count - 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETCLOSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\GETCLOSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* getclose.c -- a number game using */%@AE@%%@NL@%
- %@AB@%/* random numbers */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TRUE 1 %@NL@%
- %@AI@%#define %@AE@%FALSE 0 %@NL@%
- %@NL@%
- %@AB@%/* external variables */%@AE@%%@NL@%
- int number, %@AB@%/* total number in current game */%@AE@%%@NL@%
- moves, %@AB@%/* number of moves in current game*/%@AE@%%@NL@%
- target, %@AB@%/* target number to reach */%@AE@%%@NL@%
- done, %@AB@%/* true if game is over */%@AE@%%@NL@%
- score, %@AB@%/* score of current game */%@AE@%%@NL@%
- wins = 0, %@AB@%/* number of games won */%@AE@%%@NL@%
- losses = 0, %@AB@%/* number of games lost */%@AE@%%@NL@%
- total = 0; %@AB@%/* total score */%@AE@%%@NL@%
- %@NL@%
- char move;%@NL@%
- %@NL@%
- %@AB@%/* function prototype declarations */%@AE@%%@NL@%
- void intro(void); %@AB@%/* tell player about game */%@AE@%%@NL@%
- char getyn(void); %@AB@%/* get yes/no response */%@AE@%%@NL@%
- int random(int num); %@AB@%/* random between 1 and num */%@AE@%%@NL@%
- void new_target(void); %@AB@%/* target number for game */%@AE@%%@NL@%
- char get_move(void); %@AB@%/* get player's move */%@AE@%%@NL@%
- void do_move(void); %@AB@%/* generate num from move */%@AE@%%@NL@%
- void check_move(void); %@AB@%/* won, lost, or continue? */%@AE@%%@NL@%
- void show_score(void); %@AB@%/* show score for game */%@AE@%%@NL@%
- void show_total(void); %@AB@%/* show total score */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- intro(); %@AB@%/* print instructions */%@AE@%%@NL@%
- %@NL@%
- while (TRUE) %@AB@%/* new games until user quits */%@AE@%%@NL@%
- {%@NL@%
- printf("\nDo you want to continue? ");%@NL@%
- if (getyn() != 'y')%@NL@%
- break; %@AB@%/* exit program */%@AE@%%@NL@%
- %@NL@%
- done = FALSE;%@NL@%
- number = moves = score = 0;%@NL@%
- new_target(); %@AB@%/* target number for this game */%@AE@%%@NL@%
- while (!done) %@AB@%/* play one game */%@AE@%%@NL@%
- {%@NL@%
- get_move();%@AB@%/* user selects random number */%@AE@%%@NL@%
- do_move(); %@AB@%/* generate random number */%@AE@%%@NL@%
- %@AB@%/* and add */%@AE@%%@NL@%
- check_move(); %@AB@%/* win, lose, or continue? */%@AE@%%@NL@%
- }%@NL@%
- show_score(); %@AB@%/* score for this game */%@AE@%%@NL@%
- show_total(); %@AB@%/* total score */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void intro(void)%@NL@%
- {%@NL@%
- printf("Welcome to Getclose\n\n");%@NL@%
- printf("The object of this game is to\n");%@NL@%
- printf("try to get as close to the target\n");%@NL@%
- printf("number as possible in as few\n");%@NL@%
- printf("moves as possible by choosing from\n");%@NL@%
- printf("various ranges of random numbers.\n");%@NL@%
- printf("You score if you get within 4 of the\n");%@NL@%
- printf("target; a 100 point bonus for hitting\n");%@NL@%
- printf("the target, but no score if you go over.\n\n");%@NL@%
- }%@NL@%
- %@NL@%
- char getyn(void)%@NL@%
- %@AB@%/* get yes or no answer */%@AE@%%@NL@%
- %@AB@%/* repeats until valid entry */%@AE@%%@NL@%
- {%@NL@%
- char ch; %@AB@%/* character to read and return */%@AE@%%@NL@%
- %@NL@%
- while (TRUE)%@NL@%
- {%@NL@%
- printf(" (y or n) ");%@NL@%
- ch = getche();%@NL@%
- printf("\n");%@NL@%
- if ((ch == 'y') || (ch == 'n'))%@NL@%
- %@AB@%/* valid response, break out of loop */%@AE@%%@NL@%
- break;%@NL@%
- %@AB@%/* give error message and loop again */%@AE@%%@NL@%
- printf("please enter ");%@NL@%
- }%@NL@%
- return(ch);%@NL@%
- }%@NL@%
- %@NL@%
- int random(int num)%@NL@%
- %@AB@%/* generate random number between 1 and num */%@AE@%%@NL@%
- %@AB@%/* doesn't use library function srand() because */%@AE@%%@NL@%
- %@AB@%/* we don't want the same seed each time */%@AE@%%@NL@%
- {%@NL@%
- long seconds, result;%@NL@%
- time(&seconds); %@AB@%/* randomize with system time */%@AE@%%@NL@%
- return (abs ((int)seconds * rand() % num) + 1);%@NL@%
- }%@NL@%
- %@NL@%
- void new_target(void)%@NL@%
- %@AB@%/* generate a new target number */%@AE@%%@NL@%
- %@AB@%/* between 50 and 99 */%@AE@%%@NL@%
- {%@NL@%
- target = 50 + random(49);%@NL@%
- printf("\nYour target for this game is %d\n",%@NL@%
- target);%@NL@%
- }%@NL@%
- %@NL@%
- char get_move(void)%@NL@%
- {%@NL@%
- while (TRUE)%@NL@%
- {%@NL@%
- printf("\nPick a random number from 1 to\n");%@NL@%
- printf("a) 5 b) 10 c) 25 d) 50 e) 100 ");%@NL@%
- move = getche();%@NL@%
- if ((move >= 'a') && (move <= 'e'))%@NL@%
- {%@NL@%
- ++moves; %@AB@%/* count the move */%@AE@%%@NL@%
- break; %@AB@%/* valid response */%@AE@%%@NL@%
- }%@NL@%
- %@AB@%/* invalid response, try again */%@AE@%%@NL@%
- printf("\nPlease type a, b, c, d, or e\n");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void do_move(void)%@NL@%
- {%@NL@%
- int num = 0; %@AB@%/* random value to obtain */%@AE@%%@NL@%
- switch (move)%@NL@%
- {%@NL@%
- case 'a' :%@NL@%
- num = random(5);%@NL@%
- break;%@NL@%
- case 'b' :%@NL@%
- num = random(10);%@NL@%
- break;%@NL@%
- case 'c' :%@NL@%
- num = random(25);%@NL@%
- break;%@NL@%
- case 'd' :%@NL@%
- num = random(50);%@NL@%
- break;%@NL@%
- case 'e' :%@NL@%
- num = random(100);%@NL@%
- break;%@NL@%
- }%@NL@%
- number += num; %@AB@%/* add new number to total */%@AE@%%@NL@%
- printf("\n\nYou got a %d. Number is now: %d ", num, number);%@NL@%
- printf("(Target is %d)\n", target);%@NL@%
- }%@NL@%
- %@NL@%
- void check_move(void)%@NL@%
- {%@NL@%
- int temp;%@NL@%
- if (number > target)%@NL@%
- {%@NL@%
- printf("\nYou went over! ");%@NL@%
- printf("No score this game.\n");%@NL@%
- losses++;%@NL@%
- done = TRUE; %@AB@%/* to break out of loop */%@AE@%%@NL@%
- }%@NL@%
- if (number == target)%@NL@%
- {%@NL@%
- printf("\nYou hit the target ");%@NL@%
- printf("for 100 bonus points!\n");%@NL@%
- score = (100 / moves) + 100;%@NL@%
- total += score;%@NL@%
- wins++;%@NL@%
- done = TRUE;%@NL@%
- }%@NL@%
- if ((number >= (target - 4)) && (number < target))%@NL@%
- {%@NL@%
- temp = 100 / moves;%@NL@%
- %@AB@%/* does player want to go for broke? */%@AE@%%@NL@%
- printf("\nTake %d points (y) or continue (n)? ",%@NL@%
- temp);%@NL@%
- if (getyn() == 'y')%@NL@%
- {%@NL@%
- score = temp;%@NL@%
- total += score;%@NL@%
- wins++;%@NL@%
- done = TRUE;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void show_score(void)%@NL@%
- {%@NL@%
- printf("\nYou scored %d points in %d moves.\n",%@NL@%
- score, moves);%@NL@%
- }%@NL@%
- %@NL@%
- void show_total(void)%@NL@%
- {%@NL@%
- printf("You have won %d games ", wins);%@NL@%
- printf("and lost %d.\n", losses);%@NL@%
- printf("Your total score is %d\n", total);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETPUT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\GETPUT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* getput.c -- illustrates _getimage(), _putimage(), */%@AE@%%@NL@%
- %@AB@%/* the image-background interaction, and */%@AE@%%@NL@%
- %@AB@%/* the aspect ratio */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- <stdlib.h> %@AB@%/* declares malloc() */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@NL@%
- %@AB@%/* The following variables describe various */%@AE@%%@NL@%
- %@AB@%/* coordinates and sizes. */%@AE@%%@NL@%
- %@AB@%/* They are declared externally so that they can be */%@AE@%%@NL@%
- %@AB@%/* shared easily by several functions. */%@AE@%%@NL@%
- int X1, Yb1, X2, Y2, Xdelta, Xside, Yside; %@AB@%/* image */%@AE@%%@NL@%
- int Xmid, Xmax, Ymid, Ymax; %@AB@%/* background */%@AE@%%@NL@%
- int Xps, Xpr, Xand, Xor, Xxor, Ytop, Ybot; %@AB@%/* copies */%@AE@%%@NL@%
- int X[3], Y[3];%@NL@%
- float Ar; %@AB@%/* aspect ratio */%@AE@%%@NL@%
- %@NL@%
- struct videoconfig Vc;%@NL@%
- char Mask[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0};%@NL@%
- void Initialize(void), Drawfig(void),%@NL@%
- Drawbackground(void), Drawcopies(void);%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "Can't handle mode %d\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- Initialize();%@NL@%
- Drawfig();%@NL@%
- Drawbackground();%@NL@%
- Drawcopies();%@NL@%
- _settextposition(1, 1);%@NL@%
- _outtext("Press a key to end");%@NL@%
- _settextposition(3, 1);%@NL@%
- _outtext("_GPSET _GPRESET _GAND");%@NL@%
- _settextposition(11, 5);%@NL@%
- _outtext("_GOR _GXOR");%@NL@%
- getch();%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- void Initialize()%@NL@%
- {%@NL@%
- _getvideoconfig(&Vc);%@NL@%
- Ar = (float) (10 * Vc.numypixels)/%@NL@%
- (6.5 * Vc.numxpixels);%@NL@%
- _setlogorg(0, 0);%@NL@%
- Xmid = Vc.numxpixels / 2;%@NL@%
- Ymid = Vc.numypixels / 2;%@NL@%
- Xmax = Vc.numxpixels - 1;%@NL@%
- Ymax = Vc.numypixels - 1;%@NL@%
- %@AB@%/* locate three background rectangles */%@AE@%%@NL@%
- X[0] = Xmid;%@NL@%
- Y[0] = 0;%@NL@%
- X[1] = Xmid;%@NL@%
- Y[1] = Ymid;%@NL@%
- X[2] = 0;%@NL@%
- Y[2] = Ymid;%@NL@%
- X1 = 0.2 * Vc.numxpixels;%@NL@%
- Yb1 = 0.2 * Vc.numypixels;%@NL@%
- Xdelta = 0.033 * Vc.numxpixels;%@NL@%
- Xside = 3 * Xdelta;%@NL@%
- Yside = 3 * Ar * Xdelta;%@NL@%
- X2 = X1 + Xside;%@NL@%
- Y2 = Yb1 + Yside;%@NL@%
- %@AB@%/* offsets for _putimage() */%@AE@%%@NL@%
- Xps = .05 * Vc.numxpixels;%@NL@%
- Xpr = .20 * Vc.numxpixels;%@NL@%
- Xand = 0.35 * Vc.numxpixels;%@NL@%
- Xor = .10 * Vc.numxpixels;%@NL@%
- Xxor = .30 * Vc.numxpixels;%@NL@%
- Ytop = .05 * Vc.numypixels;%@NL@%
- Ybot = 2 * Ytop + Yside;%@NL@%
- _selectpalette(0);%@NL@%
- }%@NL@%
- %@NL@%
- void Drawfig()%@NL@%
- {%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GFILLINTERIOR, X1, Yb1,%@NL@%
- X1 + Xdelta , Y2);%@NL@%
- _setcolor(2);%@NL@%
- _rectangle(_GFILLINTERIOR,X1 + Xdelta + 1, Yb1,%@NL@%
- X1 + 2 * Xdelta, Y2);%@NL@%
- _setcolor(3);%@NL@%
- _rectangle(_GFILLINTERIOR,X1 + 2 * Xdelta + 1,%@NL@%
- Yb1, X2, Y2);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Drawbackground()%@NL@%
- {%@NL@%
- _setfillmask(Mask);%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GFILLINTERIOR, Xmid, 0, Xmax - 1, Ymid - 1);%@NL@%
- _setcolor(2);%@NL@%
- _rectangle(_GFILLINTERIOR, Xmid, Ymid, Xmax, Ymax);%@NL@%
- _setcolor (3);%@NL@%
- _rectangle(_GFILLINTERIOR, 0, Ymid, Xmid - 1, Ymax);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Drawcopies()%@NL@%
- {%@NL@%
- int quad; %@AB@%/* quadrant used */%@AE@%%@NL@%
- char far *storage;%@NL@%
- %@NL@%
- storage = (char far *) malloc((unsigned)_imagesize(%@NL@%
- X1, Yb1, X2, Y2));%@NL@%
- _getimage(X1, Yb1, X2, Y2, storage);%@NL@%
- %@NL@%
- for (quad = 0; quad < 3; quad++)%@NL@%
- {%@NL@%
- _putimage(X[quad] + Xps, Y[quad] + Ytop,%@NL@%
- storage, _GPSET);%@NL@%
- _putimage(X[quad] + Xpr, Y[quad] + Ytop,%@NL@%
- storage, _GPRESET);%@NL@%
- _putimage (X[quad] + Xand, Y[quad] + Ytop,%@NL@%
- storage, _GAND);%@NL@%
- _putimage (X[quad] + Xor, Y[quad] + Ybot,%@NL@%
- storage, _GOR);%@NL@%
- _putimage(X[quad] + Xxor, Y[quad] + Ybot,%@NL@%
- storage, _GXOR);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETYN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\GETYN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* getyn.c -- calls char function getyn() */%@AE@%%@NL@%
- %@AB@%/* with error checking */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TRUE 1 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- char getyn();%@NL@%
- %@NL@%
- printf("Do you want to continue? ");%@NL@%
- if ((ch = getyn()) == 'y')%@NL@%
- printf("Answer was y\n");%@NL@%
- else%@NL@%
- printf("Answer was n\n");%@NL@%
- printf("Value of ch was %c\n", ch);%@NL@%
- }%@NL@%
- %@NL@%
- char getyn()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- while (TRUE)%@NL@%
- {%@NL@%
- printf(" (y or n) ");%@NL@%
- ch = getche();%@NL@%
- printf("\n");%@NL@%
- if ((ch == 'y') || (ch == 'n'))%@NL@%
- %@AB@%/* valid response, break out of loop */%@AE@%%@NL@%
- break;%@NL@%
- %@AB@%/* give error message and loop again */%@AE@%%@NL@%
- printf("please enter ");%@NL@%
- }%@NL@%
- return(ch);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GRAPHBOX.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\GRAPHBOX.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* GRAPHBOX.C -- defined to use PC-specific */%@AE@%%@NL@%
- %@AB@%/* graphics characters */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NL 10 %@NL@%
- %@AI@%#define %@AE@%CR 13 %@NL@%
- %@AI@%#define %@AE@%BLANK 32 %@NL@%
- %@AI@%#define %@AE@%UPLEFT 201 %@NL@%
- %@AI@%#define %@AE@%UPRIGHT 187 %@NL@%
- %@AI@%#define %@AE@%LOWLEFT 200 %@NL@%
- %@AI@%#define %@AE@%LOWRIGHT 188 %@NL@%
- %@AI@%#define %@AE@%LINE 205 %@NL@%
- %@AI@%#define %@AE@%SIDE 186 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i, j, height, width;%@NL@%
- %@NL@%
- %@AB@%/* get height and width from user */%@AE@%%@NL@%
- printf("How high a box do you want? ");%@NL@%
- scanf("%d", &height);%@NL@%
- printf("How wide do you want it to be? ");%@NL@%
- scanf("%d", &width);%@NL@%
- %@NL@%
- %@AB@%/* draw top of box */%@AE@%%@NL@%
- putch(UPLEFT);%@NL@%
- for (i = 0; i < (width - 2); i++)%@NL@%
- putch(LINE);%@NL@%
- putch(UPRIGHT);%@NL@%
- putch(NL);%@NL@%
- putch(CR); %@AB@%/* go to next line */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* draw sides of box */%@AE@%%@NL@%
- for (i = 0; i < height - 2; i++) %@AB@%/* outer loop */%@AE@%%@NL@%
- {%@NL@%
- putch(SIDE); %@AB@%/* left side */%@AE@%%@NL@%
- for (j = 0; j < (width - 2); j++) %@AB@%/* inner loop */%@AE@%%@NL@%
- {%@NL@%
- putch(BLANK);%@NL@%
- }%@NL@%
- putch(SIDE); %@AB@%/* right side */%@AE@%%@NL@%
- putch(NL);%@NL@%
- putch(CR); %@AB@%/* move to next line */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* draw bottom of box */%@AE@%%@NL@%
- putch(LOWLEFT);%@NL@%
- for (i = 0; i < (width - 2); i++)%@NL@%
- putch(LINE);%@NL@%
- putch(LOWRIGHT);%@NL@%
- putch(NL);%@NL@%
- putch(CR); %@AB@%/* box is done, move cursor to new line */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GRAPHCHA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\GRAPHCHA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* grafchar.c -- draws graphics characters with */%@AE@%%@NL@%
- %@AB@%/* attributes on the screen */%@AE@%%@NL@%
- %@AB@%/* Program list : grafchar.c, initstuf.c, drawchar.c, */%@AE@%%@NL@%
- %@AB@%/* scrfun.c */%@AE@%%@NL@%
- %@AB@%/* User include files: keys.h, scrn.h, grafchar.h */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"grafchar.h" %@NL@%
- unsigned char Grchr[NUMCHARS]; %@AB@%/* to store graphics set */%@AE@%%@NL@%
- void Init_stuff(void); %@AB@%/* in initstuf.c */%@AE@%%@NL@%
- void Draw_chars(void); %@AB@%/* in drawchar.c */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- Init_stuff(); %@AB@%/* initialize vital elements */%@AE@%%@NL@%
- Draw_chars(); %@AB@%/* map keys to graphics characters */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HARDWARE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\HARDWARE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* hardware.c -- shows a mixture of int, */%@AE@%%@NL@%
- %@AB@%/* float, and char types */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int threads = 8; %@AB@%/* threads per inch */%@AE@%%@NL@%
- float length = 1.25, %@AB@%/* length in inches */%@AE@%%@NL@%
- diameter = 0.425, %@AB@%/* diameter in inches */%@AE@%%@NL@%
- price = 0.89; %@AB@%/* price per hundred */%@AE@%%@NL@%
- char bin = 'A'; %@AB@%/* kept in bin A */%@AE@%%@NL@%
- long quantity = 42300; %@AB@%/* number in bin */%@AE@%%@NL@%
- %@NL@%
- printf("Screws: %d threads/inch\n%f inches long\n",%@NL@%
- threads, length);%@NL@%
- printf("%f diameter\n\n", diameter);%@NL@%
- printf("Price per 100: %f\n", price);%@NL@%
- printf("Stored in bin: %c\nQuantity on hand: %ld",%@NL@%
- bin, quantity);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HELLO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\HELLO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* hello.c -- legal ways to initialize strings as */%@AE@%%@NL@%
- %@AB@%/* arrays of char values */%@AE@%%@NL@%
- %@NL@%
- char Gphrase[] = { %@NL@%
- 'H','e','l','l','o','\n','\0' }; %@AB@%/* global initialization */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static char gphrase[] = {%@NL@%
- 'h','e','l','l','o','\n','\0' }; %@AB@%/* local initialization */%@AE@%%@NL@%
- %@NL@%
- printf("Global: %s\n", Gphrase);%@NL@%
- printf("Local: %s\n", gphrase);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HELP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\HELP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* help.c -- uses paging and direct memory access */%@AE@%%@NL@%
- %@AB@%/* to display a help screen */%@AE@%%@NL@%
- %@AB@%/* Program list: help.c, writestr.c, writechr.c, */%@AE@%%@NL@%
- %@AB@%/* scrfun.c */%@AE@%%@NL@%
- %@AB@%/* User include files: scrn.h, color.h */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"color.h" %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- typedef unsigned int (far * VIDMEM);%@NL@%
- %@AI@%#define %@AE@%CGAMEM ((VIDMEM) (0xB800L << 16)) %@NL@%
- %@AI@%#define %@AE@%PAGESIZE 2000 %@NL@%
- %@AI@%#define %@AE@%PAGEOFFSET 0x800L %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%ATTR1 (BG_BLUE | YELLOW) %@NL@%
- %@AI@%#define %@AE@%ATTR2 (BG_YELLOW | BLUE) %@NL@%
- %@AI@%#define %@AE@%ATTR3 (BG_RED | YELLOW | BLINK | INTENSE) %@NL@%
- %@AI@%#define %@AE@%CH1 (unsigned short) '\xB1' %@NL@%
- char *str1 = "Press ? key for help.";%@NL@%
- char *str2 = "Press Enter key to return.";%@NL@%
- char *str3 = "Press Esc key to quit.";%@NL@%
- char *str4 = "\xB1HELP!\xB1";%@NL@%
- void Write_chars(VIDMEM, unsigned short, unsigned%@NL@%
- short, unsigned short);%@NL@%
- void Write_str(VIDMEM, unsigned short, char *);%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- unsigned char page = 0;%@NL@%
- unsigned char mode;%@NL@%
- %@NL@%
- mode = Getvmode();%@NL@%
- if (mode != TEXTC80 && mode != TEXTBW80)%@NL@%
- {%@NL@%
- printf("Only modes 2 and 3 supported. Bye.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- Setpage (page);%@NL@%
- Write_chars(CGAMEM, '\0', ATTR2, PAGESIZE);%@NL@%
- Write_str(CGAMEM + 2 * COLS, ATTR1, str1);%@NL@%
- Write_str(CGAMEM + 2 * COLS, ATTR1, str1);%@NL@%
- Write_str(CGAMEM + 22 * COLS, ATTR1, str3);%@NL@%
- Write_chars(CGAMEM + PAGEOFFSET, '\0', ATTR1, PAGESIZE);%@NL@%
- Write_str(CGAMEM + PAGEOFFSET + 20 * COLS, ATTR2, str2);%@NL@%
- Write_str(CGAMEM + PAGEOFFSET + 22 * COLS, ATTR1, str3);%@NL@%
- Write_chars(CGAMEM + PAGEOFFSET + 10 * COLS + 36,%@NL@%
- CH1, ATTR3, 7);%@NL@%
- Write_str(CGAMEM + PAGEOFFSET + 11 * COLS + 36,%@NL@%
- ATTR3, str4);%@NL@%
- Write_chars(CGAMEM + PAGEOFFSET + 12 * COLS + 36,%@NL@%
- CH1, ATTR3, 7);%@NL@%
- %@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch == '?' && page == 0)%@NL@%
- Setpage (page = 1);%@NL@%
- else if (ch == '\r' && page == 1)%@NL@%
- Setpage(page = 0);%@NL@%
- }%@NL@%
- Write_chars(CGAMEM, '\0', NORMAL, PAGESIZE);%@NL@%
- Write_chars(CGAMEM + PAGEOFFSET, '\0', NORMAL, PAGESIZE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HEXOUT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\HEXOUT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* hexout.c -- print a floating point variable in */%@AE@%%@NL@%
- %@AB@%/* hexadecimal format */%@AE@%%@NL@%
- %@NL@%
- extern void Hexout();%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float fary[1];%@NL@%
- %@NL@%
- printf("Enter a floating point number\n");%@NL@%
- printf("(Any nonnumeric entry quits)\n\n");%@NL@%
- while (scanf("%f", &fary[0]) == 1)%@NL@%
- {%@NL@%
- Hexout(fary);%@NL@%
- }%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- void Hexout(unsigned char chary[])%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < sizeof(float); ++i)%@NL@%
- {%@NL@%
- printf("%02X ", chary[i]);%@NL@%
- }%@NL@%
- printf("\n\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%IBMIQ.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\IBMIQ.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ibmiq.c -- a short dialog */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- char name[80];%@NL@%
- int iq;%@NL@%
- %@NL@%
- printf("Enter your first name: -> ");%@NL@%
- scanf("%s", name);%@NL@%
- printf("Enter your IQ: -> ");%@NL@%
- scanf("%d", iq);%@NL@%
- printf("Well, %s, my IQ is %d!", name, 2 * iq - 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%IF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\IF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* if.c -- simple IF statement */%@AE@%%@NL@%
- %@NL@%
- char ch;%@NL@%
- main()%@NL@%
- {%@NL@%
- printf("Do you want to continue y/n? "); %@AB@%/* prompt */%@AE@%%@NL@%
- if (ch = getche() == 'y')%@NL@%
- printf("\nLet's continue ...\n"); %@AB@%/* if true */%@AE@%%@NL@%
- printf("\nAll done.\n"); %@AB@%/* always executed */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%IFELSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\IFELSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ifelse.c -- IF with ELSE */%@AE@%%@NL@%
- %@NL@%
- char ch;%@NL@%
- int num;%@NL@%
- main()%@NL@%
- {%@NL@%
- printf("Are you a new user? y/n? ");%@NL@%
- if (ch = getche() == 'y')%@NL@%
- {%@NL@%
- %@AB@%/* executed if IF is true */%@AE@%%@NL@%
- printf("\n\nYou must register to use this\n");%@NL@%
- printf("bulletin board. Please read\n");%@NL@%
- printf("Bulletin #1 first. Thank You.\n");%@NL@%
- }%@NL@%
- else%@NL@%
- %@AB@%/* executed if IF is false */%@AE@%%@NL@%
- {%@NL@%
- printf("\n\nEnter your secret number: ");%@NL@%
- scanf("d", &num);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INCDEC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\INCDEC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* incdec.c -- shows effect of */%@AE@%%@NL@%
- %@AB@%/* increments and decrements */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a = 10;%@NL@%
- %@NL@%
- printf("a is %d\n", a);%@NL@%
- printf("++a is %d\n", ++a);%@NL@%
- printf("--a sets a back to %d\n", --a);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INDEXER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\INDEXER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* indexer.c -- use indices to display an array */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- int code1[] = {2, 4, 6, 8};%@NL@%
- int code2[] = {1, 3, 7, 9};%@NL@%
- int code3[] = {5, 10, 15, 20};%@NL@%
- main()%@NL@%
- {%@NL@%
- int index;%@NL@%
- int size = (sizeof code2) / (sizeof (int));%@NL@%
- %@NL@%
- for ( index = 1; index <= size; size++)%@NL@%
- printf("%3d ", code2[index]);%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INDEXER2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\INDEXER2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* indexer2.c -- use indices to display an array */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- int code1[] = {2, 4, 6, 8};%@NL@%
- int code2[] = {1, 3, 7, 9};%@NL@%
- int code3[] = {5, 10, 15, 20};%@NL@%
- main()%@NL@%
- {%@NL@%
- int index;%@NL@%
- int size = (sizeof code2) / (sizeof (int));%@NL@%
- %@AB@%/* get number of elements in array */%@AE@%%@NL@%
- %@NL@%
- for ( index = 1; index <= size; index++)%@NL@%
- printf("%3d ", code2[index]);%@NL@%
- putchar('\n');%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INFLATE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\INFLATE.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* INFLATE.C -- shows multiple initialization */%@AE@%%@NL@%
- %@AB@%/* and calculations in for loop */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int year;%@NL@%
- float value, rate;%@NL@%
- printf("What do you think the inflation rate will be?");%@NL@%
- scanf("%f", &rate);%@NL@%
- printf("If the dollar is worth 100 cents in 1987\n");%@NL@%
- printf("and the inflation rate is %2.2f, then:\n", rate);%@NL@%
- %@NL@%
- for (year=1988, value = 1.0; year <=1999;%@NL@%
- value *= (1.0 - rate),%@NL@%
- printf("in %d the dollar will be worth", year),%@NL@%
- printf(" %2.0f cents\n", value * 100),%@NL@%
- ++year%@NL@%
- );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INITSTUF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\INITSTUF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* initstuf.c -- initializing module for grafchar.c */%@AE@%%@NL@%
- %@AB@%/* assign graphics character codes to an array */%@AE@%%@NL@%
- %@AB@%/* and initialize screen */%@AE@%%@NL@%
- %@NL@%
- "scrn.h" %@AB@%/* Clearscr(), Home(), Setcurs() */%@AE@%%@NL@%
- %@AI@%#include %@AE@%"grafchar.h" %@NL@%
- extern unsigned char Grchr[]; %@AB@%/* defined in grafchar.c */%@AE@%%@NL@%
- void Print_attr(char *, unsigned char, unsigned char);%@NL@%
- void Init_stuff()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- %@AB@%/* initialize array with graphics characters */%@AE@%%@NL@%
- for (i = 0; i < NUMCHARS; i++)%@NL@%
- Grchr[i] = GCSTART + i;%@NL@%
- Clearscr();%@NL@%
- Home();%@NL@%
- %@NL@%
- %@AB@%/* show key meanings at bottom of screen */%@AE@%%@NL@%
- Setcurs(BOTLINE + 1, 0, PAGE);%@NL@%
- for (i = 0; i < 40; i++) %@AB@%/* graphics chars */%@AE@%%@NL@%
- {%@NL@%
- putch(Grchr[i]);%@NL@%
- putch(SPACE);%@NL@%
- }%@NL@%
- Setcurs(BOTLINE + 2, 0, PAGE);%@NL@%
- for (i = 0; i < 40; i++) %@AB@%/* key assignments */%@AE@%%@NL@%
- {%@NL@%
- putch('0' + i);%@NL@%
- putch(SPACE);%@NL@%
- }%@NL@%
- Setcurs(BOTLINE + 3, 0, PAGE);%@NL@%
- for (i = 40; i < NUMCHARS; i++) %@AB@%/* second row */%@AE@%%@NL@%
- {%@NL@%
- putch(Grchr[i]);%@NL@%
- putch(SPACE);%@NL@%
- }%@NL@%
- %@AB@%/* show function key assignments */%@AE@%%@NL@%
- printf(" SPACE : ERASE PgUp : No Draw ");%@NL@%
- printf(" PgDn : Draw ESC : Quit");%@NL@%
- Setcurs(BOTLINE + 4, 0, PAGE);%@NL@%
- for (i = 40; i < NUMCHARS; i++) %@AB@%/* second row */%@AE@%%@NL@%
- {%@NL@%
- putch('0' + i);%@NL@%
- putch(SPACE);%@NL@%
- }%@NL@%
- %@AB@%/* more function key assignments */%@AE@%%@NL@%
- Print_attr("F1 : Normal ", NORMAL, PAGE);%@NL@%
- Print_attr("F2 : Reverse Video ", VIDREV, PAGE);%@NL@%
- Setcurs(BOTLINE + 5, 16, PAGE);%@NL@%
- Print_attr("F3 : Blinking ", NORMAL | BLINK, PAGE);%@NL@%
- Print_attr("F4 : Intense ", NORMAL | INTENSE, PAGE);%@NL@%
- Home();%@NL@%
- }%@NL@%
- %@NL@%
- void Print_attr(str, attr, page)%@NL@%
- char *str;%@NL@%
- unsigned char attr, page;%@NL@%
- {%@NL@%
- while (*str != '\0')%@NL@%
- {%@NL@%
- Write_ch_atr(*str++, attr, page, 1);%@NL@%
- Cursrt();%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INTVARS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\INTVARS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* intvars.c -- declare, define, and print */%@AE@%%@NL@%
- %@AB@%/* some integer variables */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@AB@%/* declare variables */%@AE@%%@NL@%
- int length, beam;%@NL@%
- unsigned int displacement;%@NL@%
- %@AB@%/* assign values to variables */%@AE@%%@NL@%
- length = 824;%@NL@%
- beam = 118;%@NL@%
- displacement = 41676;%@NL@%
- %@NL@%
- %@AB@%/* print out values */%@AE@%%@NL@%
- printf("The battleship Bismarck was %d feet long",%@NL@%
- length);%@NL@%
- printf(" with a beam of %d feet,\n", beam);%@NL@%
- printf("and displaced %u tons.\n", displacement);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INVERT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\INVERT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* invert.c -- combines character classification and */%@AE@%%@NL@%
- %@AB@%/* transformation to invert text */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <ctype.h> %@AB@%/* for toupper, et al */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char buf[BUFSIZ];%@NL@%
- int i;%@NL@%
- %@NL@%
- printf("Type in a line of text and I will invert it.\n");%@NL@%
- %@NL@%
- if (gets(buf) == NULL)%@NL@%
- exit(1);%@NL@%
- %@NL@%
- %@AB@%/* Print the string backwards. */%@AE@%%@NL@%
- for (i = (strlen(buf) -1); i >= 0; --i)%@NL@%
- {%@NL@%
- if (isupper(buf[i])) %@AB@%/* upper to lower */%@AE@%%@NL@%
- putchar(tolower(buf[i]));%@NL@%
- else if (islower(buf[i])) %@AB@%/* lower to upper */%@AE@%%@NL@%
- putchar(toupper(buf[i]));%@NL@%
- else%@NL@%
- putchar(buf[i]);%@NL@%
- }%@NL@%
- putchar('\n');%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%KEYS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\KEYS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* keys.c -- The keyboard input-handling routines */%@AE@%%@NL@%
- %@AB@%/* for the texed editor. */%@AE@%%@NL@%
- %@NL@%
- Edit_file()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- printf("\nYou are now in the editor.\n");%@NL@%
- printf("Press 'Q' to exit back to main menu.\n");%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- ch = getch();%@NL@%
- putch(ch);%@NL@%
- } while (ch != 'Q');%@NL@%
- %@NL@%
- printf("\n\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%L2WORDS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\L2WORDS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* l2words.c -- employ an array of pointers to */%@AE@%%@NL@%
- %@AB@%/* strings to bust a line of text */%@AE@%%@NL@%
- %@AB@%/* into its component words */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and BUFSIZ */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char **Line2words(); %@AB@%/* declare function type */%@AE@%%@NL@%
- char **list; %@AB@%/* pointer to pointer */%@AE@%%@NL@%
- char buf[BUFSIZ]; %@AB@%/* buffer for input */%@AE@%%@NL@%
- int count, i, quote_flag;%@NL@%
- %@NL@%
- printf("Enter a line of text and I will break\n");%@NL@%
- printf("it up for you.\n");%@NL@%
- %@NL@%
- if (gets(buf) == NULL)%@NL@%
- exit(1);%@NL@%
- %@NL@%
- list = Line2words(buf, &count);%@NL@%
- %@NL@%
- for (i = 0; i < count; i++)%@NL@%
- {%@NL@%
- quote_flag = 0;%@NL@%
- printf("<");%@NL@%
- if (list[i] != buf)%@NL@%
- {%@NL@%
- if( list[i][-1] == '"') %@AB@%/* negative subscript */%@AE@%%@NL@%
- {%@NL@%
- ++quote_flag;%@NL@%
- printf("\"");%@NL@%
- }%@NL@%
- }%@NL@%
- printf("%s", list[i]);%@NL@%
- %@NL@%
- if (quote_flag)%@NL@%
- printf("\"");%@NL@%
- %@NL@%
- printf(">\n");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXW 64 %@NL@%
- %@NL@%
- char **Line2words(char *line, int *count)%@NL@%
- {%@NL@%
- static char *words[MAXW];%@NL@%
- int index;%@NL@%
- %@NL@%
- index = 0; %@AB@%/* zero internal index */%@AE@%%@NL@%
- %@NL@%
- while (*line != '\0')%@NL@%
- {%@NL@%
- %@AB@%/* turn spaces and tabs into zeros */%@AE@%%@NL@%
- if (*line == ' ' || *line == '\t')%@NL@%
- {%@NL@%
- *(line++) = '\0';%@NL@%
- continue;%@NL@%
- }%@NL@%
- words[index] = line++; %@AB@%/* found a word */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* is it quoted? */%@AE@%%@NL@%
- if ( *(words[index]) == '"')%@NL@%
- {%@NL@%
- %@AB@%/* Yes, advance pointer to just past quote. */%@AE@%%@NL@%
- ++words[index];%@NL@%
- %@NL@%
- %@AB@%/* find next quote. */%@AE@%%@NL@%
- while (*line && *line != '"')%@NL@%
- {%@NL@%
- ++line;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* and turn it into a '\0'. */%@AE@%%@NL@%
- if (*line)%@NL@%
- *(line++) = '\0';%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* otherwise skip to next space */%@AE@%%@NL@%
- while (*line && *line != ' ' && *line != '\t')%@NL@%
- {%@NL@%
- ++line;%@NL@%
- }%@NL@%
- }%@NL@%
- if (++index == MAXW)%@NL@%
- break;%@NL@%
- }%@NL@%
- *count = index; %@AB@%/* set count via pointer */%@AE@%%@NL@%
- return (words); %@AB@%/* return address of array */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LEFTSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\LEFTSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* leftstr.c -- a C version of BASIC's LEFT$ */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- char *Leftstr(char *str, int cnt)%@NL@%
- {%@NL@%
- static char *cp = NULL;%@NL@%
- char *malloc();%@NL@%
- %@NL@%
- if (cnt > strlen(str))%@NL@%
- cnt = strlen(str);%@NL@%
- if (cp != NULL)%@NL@%
- free(cp);%@NL@%
- if ((cp = malloc(cnt + 1)) == NULL)%@NL@%
- return (NULL);%@NL@%
- strncpy(cp, str, cnt);%@NL@%
- return (cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LINES.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\LINES.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* lines.c -- calls line() with */%@AE@%%@NL@%
- %@AB@%/* five parameters */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- void line (x1, y1, x2, y2, color);%@NL@%
- %@NL@%
- int x1, x2, y1, y2, i, color;%@NL@%
- %@NL@%
- _setvideomode(_MRES16COLOR); %@AB@%/* 320 x 200 16 col. */%@AE@%%@NL@%
- srand(2); %@AB@%/* new random seed */%@AE@%%@NL@%
- for (i = 0; i < 100; i++)%@NL@%
- {%@NL@%
- x1 = rand() % 319; %@AB@%/* random coordinates */%@AE@%%@NL@%
- x2 = rand() % 319;%@NL@%
- y1 = rand() % 199;%@NL@%
- y2 = rand() % 199;%@NL@%
- color = (rand() % 14) + 1; %@AB@%/* random color 1-15 */%@AE@%%@NL@%
- line(x1, y1, x2, y2, color); %@AB@%/* draw a line */%@AE@%%@NL@%
- }%@NL@%
- while(!kbhit() ); %@AB@%/* wait for key to be hit */%@AE@%%@NL@%
- %@NL@%
- _setvideomode(_DEFAULTMODE); %@AB@%/* restore video mode */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- void line (x1, y1, x2, y2, color)%@NL@%
- int x1, y1, x2, y2, color;%@NL@%
- {%@NL@%
- _moveto(x1, y1); %@AB@%/* position at first endpoint */%@AE@%%@NL@%
- _setcolor(color);%@NL@%
- _lineto(x2, y2); %@AB@%/* draw line to second endpoint */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LINES43.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\LINES43.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* lines43.c -- leaves EGA in 43-line mode */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%VIDEO 0x10 %@NL@%
- %@AI@%#define %@AE@%SETVMODE 0 %@NL@%
- CHAR_GEN 0x11 %@AB@%/* an EGA BIOS function number */%@AE@%%@NL@%
- %@AI@%#define %@AE@%ROM8X8 0x12 %@NL@%
- %@AI@%#define %@AE@%BLOCK 0 %@NL@%
- %@AI@%#define %@AE@%TEXTC80 3 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETVMODE; %@AB@%/* set text mode */%@AE@%%@NL@%
- reg.h.al = TEXTC80;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- %@NL@%
- reg.h.ah = CHAR_GEN; %@AB@%/* char generator routine */%@AE@%%@NL@%
- reg.h.al = ROM8X8; %@AB@%/* use 8x8 ROM character box */%@AE@%%@NL@%
- reg.h.bl = BLOCK; %@AB@%/* copy to block 0 */%@AE@%%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LINE_CNT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\LINE_CNT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* line_cnt.c -- An overly active line counter */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- int lines = 0;%@NL@%
- %@NL@%
- while ( (ch = getchar() ) != EOF )%@NL@%
- if ( ch = '\n')%@NL@%
- lines++;%@NL@%
- printf("There were %d lines\n", lines);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LOCAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\LOCAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* local.c -- local variables defined */%@AE@%%@NL@%
- %@AB@%/* within functions */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int n = 12;%@NL@%
- int func1(), funct2();%@NL@%
- printf("n in main(): val %d ", n);%@NL@%
- printf("address %d\n", &n);%@NL@%
- %@NL@%
- printf("Calling func1()\n");%@NL@%
- func1();%@NL@%
- printf("Calling func2()\n");%@NL@%
- func2();%@NL@%
- }%@NL@%
- %@NL@%
- int func1()%@NL@%
- {%@NL@%
- int n = 8; %@AB@%/* local variable */%@AE@%%@NL@%
- printf("n in func1(): val %d ", n);%@NL@%
- printf("address %d\n", &n);%@NL@%
- }%@NL@%
- %@NL@%
- int func2()%@NL@%
- {%@NL@%
- int n = 20; %@AB@%/* local variable */%@AE@%%@NL@%
- printf("n in func2(): val %d ", n);%@NL@%
- printf("address %d\n", &n);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%M.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\M.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* m.c -- draw a letter M */%@AE@%%@NL@%
- %@AB@%/* using IF and CONTINUE */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* define characters */%@AE@%%@NL@%
- %@NL@%
- CH 'M' %@AB@%/* character to "draw" with */%@AE@%%@NL@%
- %@AI@%#define %@AE@%BLANK ' ' %@NL@%
- %@AI@%#define %@AE@%NL 10 %@NL@%
- %@AI@%#define %@AE@%CR 13 %@NL@%
- LEFT 20 %@AB@%/* left side of M */%@AE@%%@NL@%
- RIGHT 46 %@AB@%/* right side of M */%@AE@%%@NL@%
- BOTTOM 22 %@AB@%/* last line to use */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- int pos, line;%@NL@%
- %@AB@%/* space to left side */%@AE@%%@NL@%
- for (line = 1; line <= BOTTOM; line++)%@NL@%
- {%@NL@%
- for (pos = 1; pos < LEFT; pos++)%@NL@%
- {%@NL@%
- putch(BLANK);%@NL@%
- }%@NL@%
- putch(CH); %@AB@%/* draw left side */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* are we past midpoint? */%@AE@%%@NL@%
- if (line > ((RIGHT - LEFT) / 2))%@NL@%
- {%@NL@%
- %@AB@%/* yes, so just draw right side */%@AE@%%@NL@%
- for (pos = LEFT; pos < RIGHT; pos++)%@NL@%
- {%@NL@%
- putch(BLANK);%@NL@%
- }%@NL@%
- putch(CH);%@NL@%
- putch(NL);%@NL@%
- putch(CR);%@NL@%
- continue; %@AB@%/* start loop over, do next line */%@AE@%%@NL@%
- }%@NL@%
- %@AB@%/* not past midpoint, check for interior */%@AE@%%@NL@%
- for (pos = LEFT; pos < RIGHT; pos++)%@NL@%
- {%@NL@%
- if ((pos == (LEFT + line )) ||%@NL@%
- (pos == (RIGHT - line )))%@NL@%
- putch(CH);%@NL@%
- else%@NL@%
- putch(BLANK);%@NL@%
- }%@NL@%
- putch(CH);%@NL@%
- putch(NL);%@NL@%
- putch(CR); %@AB@%/* could also use printf("\n"); */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MAGIC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\MAGIC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* magic.c -- demonstrate use of a two-dimensional */%@AE@%%@NL@%
- %@AB@%/* array of type int */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static int square[3][3] = { 5, 8, 3, 4, 2, 0, 7, 1, 6 };%@NL@%
- int zrow = 1, zcol = 2; %@AB@%/* location of the zero */%@AE@%%@NL@%
- int num, row, col, i , j, rowdist, coldist;%@NL@%
- %@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("Swap what with zero?\n");%@NL@%
- printf("(Q to quit)\n");%@NL@%
- %@NL@%
- %@AB@%/* Print the square. */%@AE@%%@NL@%
- for (i = 0; i < 3; ++i)%@NL@%
- {%@NL@%
- for (j = 0; j < 3; ++j)%@NL@%
- {%@NL@%
- printf(" %d ", square[i][j] );%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Input the user number. */%@AE@%%@NL@%
- if ((num = getch()) == 'Q')%@NL@%
- exit(0);%@NL@%
- num -= '0';%@NL@%
- if (num < 1 || num > 9)%@NL@%
- {%@NL@%
- printf("Not a legal number.\n\n");%@NL@%
- continue;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Find that square. */%@AE@%%@NL@%
- for (row = 0; row < 3; ++row)%@NL@%
- {%@NL@%
- for(col = 0; col < 3; ++col)%@NL@%
- {%@NL@%
- if (num == square[row][col])%@NL@%
- {%@NL@%
- goto GOTIT;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- GOTIT:%@NL@%
- %@AB@%/* Check for a legal move. */%@AE@%%@NL@%
- if (row > 2 || col > 2)%@NL@%
- {%@NL@%
- printf("Bad Box Specification\n\n");%@NL@%
- continue;%@NL@%
- }%@NL@%
- rowdist = zrow - row;%@NL@%
- if (rowdist < 0) %@NL@%
- rowdist *= -1;%@NL@%
- coldist = zcol - col;%@NL@%
- if (coldist < 0) %@NL@%
- coldist *= -1;%@NL@%
- if (rowdist > 1 || coldist > 1)%@NL@%
- {%@NL@%
- printf("Not A Neighbor\n\n");%@NL@%
- continue;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Make the move. */%@AE@%%@NL@%
- square[zrow][zcol] = square[row][col];%@NL@%
- square[row][col] = 0;%@NL@%
- zrow = row;%@NL@%
- zcol = col;%@NL@%
- %@NL@%
- %@AB@%/* See if done, and solved. */%@AE@%%@NL@%
- for (i = 0; i < 3; ++i)%@NL@%
- {%@NL@%
- for (j = 0; j < 3; ++j)%@NL@%
- {%@NL@%
- if (square[i][j] != ((i * 3) + j))%@NL@%
- {%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- if ((i * j) == 9)%@NL@%
- break;%@NL@%
- }%@NL@%
- printf("\n\aYOU GOT IT !!!\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MASKS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\MASKS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* masks.c -- illustrates _setfillmask() and */%@AE@%%@NL@%
- %@AB@%/* _floodfill() */%@AE@%%@NL@%
- %@AB@%/* Program list: masks.c */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- unsigned char Inversemask[8];%@NL@%
- unsigned char Masks[3][8] = {%@NL@%
- {0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00},%@NL@%
- {0xff,0x80,0x80,0x80,0xff,0x08,0x08,0x08},%@NL@%
- {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa}};%@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- short xc, yc;%@NL@%
- short box, i;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr,"Can't set mode %d\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- xc = vc.numxpixels / 2;%@NL@%
- yc = vc.numypixels / 2;%@NL@%
- for (i = 0; i < 8; i++)%@NL@%
- Inversemask[i] = ~Masks[1][i];%@NL@%
- _setlogorg(xc, yc);%@NL@%
- _selectpalette(0);%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GBORDER, -xc + 1, -yc + 1, xc - 1, yc - 1);%@NL@%
- _moveto(-xc + 1, -yc / 3);%@NL@%
- _lineto(xc -1, -yc / 3);%@NL@%
- _moveto(-xc + 1, yc / 3);%@NL@%
- _lineto(xc -1, yc / 3);%@NL@%
- for (box = 0; box < 3; box++)%@NL@%
- {%@NL@%
- _setcolor(box + 1);%@NL@%
- _setfillmask(Masks[box]);%@NL@%
- _floodfill(0, (box - 1) * yc / 2, 1);%@NL@%
- }%@NL@%
- _settextposition(5, 10);%@NL@%
- _outtext("Press a key to continue");%@NL@%
- getch();%@NL@%
- _setcolor(3);%@NL@%
- _setfillmask(Inversemask);%@NL@%
- _floodfill (0, 0, 1);%@NL@%
- _setcolor(2);%@NL@%
- _setfillmask(Masks[0]);%@NL@%
- _floodfill(0, yc / 2, 1);%@NL@%
- _settextposition(5, 10);%@NL@%
- _outtext("Press a key to terminate");%@NL@%
- getch();%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MATH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\MATH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* math.c -- shows arithmetic and */%@AE@%%@NL@%
- %@AB@%/* precedence via expressions */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a = 10, b = 4, c = 2;%@NL@%
- %@NL@%
- %@AB@%/* simple arithmetic expressions */%@AE@%%@NL@%
- printf("99 + 2 = %d\n", 99 + 2); %@AB@%/* ints */%@AE@%%@NL@%
- printf("5 - 12 = %d\n", 5 - 12);%@NL@%
- printf("7.25 + 3.5 = %f\n", 7.25 + 3.5);%@NL@%
- %@AB@%/* floats */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* compare presedence on these */%@AE@%%@NL@%
- printf("20 * 20 + 40 = %d\n", 20 * 20 + 40);%@NL@%
- printf("20 * (20 + 40) = %d\n", 20 * (20 + 40));%@NL@%
- printf("a * a - c + b = %d\n", a * a - c + b);%@NL@%
- printf("a * (a - (c + b)) = %d\n",%@NL@%
- a * (a - (c + b)));%@NL@%
- %@NL@%
- %@AB@%/* compare integer and float division */%@AE@%%@NL@%
- %@NL@%
- printf("Integers: 5 / 2 = %d\n", 5 / 2);%@NL@%
- printf("Floats: 5.0 / 2.0 = %f\n", 5.0 / 2.0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MATHTEST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\MATHTEST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* mathtest.c -- driver for do_math() */%@AE@%%@NL@%
- %@AB@%/* Program list: mathtest.c (to link math functions) */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- double do_math(double);%@NL@%
- main()%@NL@%
- {%@NL@%
- double input, result;%@NL@%
- %@NL@%
- printf("Enter a number: ");%@NL@%
- while (scanf("%lf", &input) == 1)%@NL@%
- {%@NL@%
- result = do_math(input);%@NL@%
- printf("input = %.2e, result = %.2e\n", input,%@NL@%
- result);%@NL@%
- printf("Next number (q to quit): ");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- double do_math(x)%@NL@%
- double x;%@NL@%
- {%@NL@%
- return (sin (x) * exp (-x));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MENU.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\MENU.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* menu.c -- uses ansi.sys for cursor control and */%@AE@%%@NL@%
- %@AB@%/* for video reverse in a sample menu */%@AE@%%@NL@%
- %@AB@%/* Note: Requires that ANSI.SYS be installed. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- ITEMS 5 %@AB@%/* number of menu items */%@AE@%%@NL@%
- UP 72 %@AB@%/* scan code for up arrow */%@AE@%%@NL@%
- DOWN 80 %@AB@%/* scan code for down arrow */%@AE@%%@NL@%
- VIDREV "\033[7m" %@AB@%/* reverse video attribute */%@AE@%%@NL@%
- ATTOFF "\033[0m" %@AB@%/* turn attributes off */%@AE@%%@NL@%
- ED() printf("\033[2J") %@AB@%/* erase display */%@AE@%%@NL@%
- HOME() printf("\033[H") %@AB@%/* home the cursor */%@AE@%%@NL@%
- CUU(Y) printf("\033[%dA",Y); %@AB@%/* cursor up */%@AE@%%@NL@%
- CUD(Y) printf("\033[%dB",Y); %@AB@%/* cursor down */%@AE@%%@NL@%
- %@NL@%
- char *Menu[ITEMS] = {"Add a number to the list",%@NL@%
- "Delete a number from the list",%@NL@%
- "Clear the list",%@NL@%
- "Sum the list",%@NL@%
- "Quit"};%@NL@%
- char *Heading =%@NL@%
- "Use arrow keys to highlight choice. "%@NL@%
- "Use Enter key to select choice.";%@NL@%
- %@NL@%
- void showmenu(int);%@NL@%
- int getmesg(int);%@NL@%
- main()%@NL@%
- {%@NL@%
- int messno = 0; %@AB@%/* message to be highlighted */%@AE@%%@NL@%
- ED();%@NL@%
- showmenu(messno);%@NL@%
- while (messno != ITEMS - 1)%@NL@%
- {%@NL@%
- messno = getmesg(messno);%@NL@%
- ED();%@NL@%
- switch (messno)%@NL@%
- {%@NL@%
- case 0 :%@NL@%
- case 1 :%@NL@%
- case 2 :%@NL@%
- case 3 : printf("...pretending to work ...");%@NL@%
- printf("Hit any key to continue\n");%@NL@%
- getch();%@NL@%
- ED();%@NL@%
- showmenu(messno);%@NL@%
- break;%@NL@%
- case 4 : printf("Quitting!\n");%@NL@%
- break;%@NL@%
- default: printf("Programming error!\n");%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* showmenu() displays the menu */%@AE@%%@NL@%
- void showmenu(highlite)%@NL@%
- int highlite; %@AB@%/* message number to be highlighted */%@AE@%%@NL@%
- {%@NL@%
- int n;%@NL@%
- char *start;%@NL@%
- %@NL@%
- HOME();%@NL@%
- printf("%s", Heading);%@NL@%
- for (n = 0; n < ITEMS; n++)%@NL@%
- {%@NL@%
- if (n == highlite)%@NL@%
- start = VIDREV; %@AB@%/* turn on reverse video */%@AE@%%@NL@%
- else%@NL@%
- start = ATTOFF;%@NL@%
- printf("\n\n%s%s%s", start, Menu[n], ATTOFF);%@NL@%
- }%@NL@%
- HOME();%@NL@%
- CUD(2 + 2 * highlite);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* getmesg() selects a menu item */%@AE@%%@NL@%
- int getmesg(mnum)%@NL@%
- int mnum; %@AB@%/* current message number */%@AE@%%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- while ((ch = getch()) != '\r')%@NL@%
- if (ch == 0)%@NL@%
- {%@NL@%
- ch = getch();%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case UP : if (mnum > 0)%@NL@%
- {%@NL@%
- CUU(2);%@NL@%
- showmenu (--mnum);%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- CUD(2 * ITEMS - 2);%@NL@%
- showmenu(mnum=ITEMS-1);%@NL@%
- }%@NL@%
- break;%@NL@%
- case DOWN : if (mnum < ITEMS - 1)%@NL@%
- {%@NL@%
- CUD(2);%@NL@%
- showmenu(++mnum);%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- CUU(2 * ITEMS - 2);%@NL@%
- showmenu(mnum = 0);%@NL@%
- }%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- return mnum;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MIDSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\MIDSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* midstr.c -- a C version of BASIC's MID$ */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- char *Midstr(char *str, int where, int cnt)%@NL@%
- {%@NL@%
- static char *cp = NULL;%@NL@%
- char *malloc();%@NL@%
- %@NL@%
- if (cnt > strlen(str + where))%@NL@%
- cnt = strlen(str + where);%@NL@%
- if (cp != NULL)%@NL@%
- free(cp);%@NL@%
- if ((cp = malloc(cnt + 1)) == NULL)%@NL@%
- return (NULL);%@NL@%
- strncpy(cp, str+where, cnt);%@NL@%
- return (cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MISIDENT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\MISIDENT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* misident.c -- careless typing */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#defne %@AE@%BIG 3 %@NL@%
- main() %@NL@%
- { %@NL@%
- char ltr; %@NL@%
- integer num; %@NL@%
- %@NL@%
- num = 2 + BIG; %@NL@%
- lrt = 'a'; %@NL@%
- printf("%c %d\n", ltr, num); %@NL@%
- } %@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MIXED.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\MIXED.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* mixed.c -- shows the effects of mixing */%@AE@%%@NL@%
- %@AB@%/* data types in an expression */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i = 50, iresult;%@NL@%
- long l = 1000000, lresult;%@NL@%
- float f = 10.5, fresult;%@NL@%
- double d = 1000.005, dresult;%@NL@%
- %@NL@%
- fresult = i + f; %@AB@%/* int + float to float */%@AE@%%@NL@%
- printf("%f\n", fresult);%@NL@%
- %@NL@%
- fresult = i * f; %@AB@%/* int * float to float */%@AE@%%@NL@%
- printf("%f\n", fresult);%@NL@%
- %@NL@%
- lresult = l + f; %@AB@%/* long + int to long */%@AE@%%@NL@%
- printf("%f\n", lresult);%@NL@%
- %@NL@%
- printf("%f\n", d * f); %@AB@%/* double * float */%@AE@%%@NL@%
- %@AB@%/* to double */%@AE@%%@NL@%
- fresult = d * f; %@AB@%/* assigned to a float */%@AE@%%@NL@%
- printf("%f\n", fresult); %@AB@%/* loses some precision */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* debugging a division problem */%@AE@%%@NL@%
- %@NL@%
- iresult = i / l; %@AB@%/* int / long to int */%@AE@%%@NL@%
- printf("%d\n", iresult); %@AB@%/* whoops! loses result */%@AE@%%@NL@%
- printf("%ld\n", iresult); %@AB@%/* this won't fix it */%@AE@%%@NL@%
- fresult = i / l; %@AB@%/* store in float result */%@AE@%%@NL@%
- printf("%f\n", fresult); %@AB@%/* doesn't work */%@AE@%%@NL@%
- dresult = i / l; %@AB@%/* try a double */%@AE@%%@NL@%
- printf("%f\n", dresult); %@AB@%/* doesn't work */%@AE@%%@NL@%
- fresult = (float) i / l; %@AB@%/* try type cast */%@AE@%%@NL@%
- printf("%f\n", fresult); %@AB@%/* correct result */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MIXLOOPS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\MIXLOOPS.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* MIXLOOPS.C -- reads characters, */%@AE@%%@NL@%
- %@AB@%/* beeps for ASCII count */%@AE@%%@NL@%
- %@AB@%/* uses a while and a for */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- int i;%@NL@%
- %@NL@%
- while ((ch = getche()) != ' ') %@AB@%/* get a char. */%@AE@%%@NL@%
- {%@NL@%
- for (i = 'a'; i <= ch; ++i) %@AB@%/* count up to */%@AE@%%@NL@%
- { %@AB@%/* alphabet pos.*/%@AE@%%@NL@%
- printf("In FOR loop!\n");%@NL@%
- printf("\a"); %@AB@%/* sound beep each time */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MIXTYPES.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\MIXTYPES.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* mixtypes.c -- shows problem with calling */%@AE@%%@NL@%
- %@AB@%/* a function with wrong type parameter */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@AB@%/* didn't bother to declare int function */%@AE@%%@NL@%
- float n = 5.0;%@NL@%
- int i;%@NL@%
- %@NL@%
- printf("n in main() is %f\n", n);%@NL@%
- i = examine(n); %@AB@%/* pass float to function */%@AE@%%@NL@%
- printf("examine() returned n as %d\n", i);%@NL@%
- }%@NL@%
- %@NL@%
- examine(num) %@AB@%/* function didn't declare return type */%@AE@%%@NL@%
- {%@NL@%
- printf("examine() says n is %d\n", num);%@NL@%
- return(num);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MODEINFO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\MODEINFO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* modeinfo.c -- set modes and obtain information */%@AE@%%@NL@%
- %@AB@%/* Demonstrates _setvideomode() and _getvideoconfig() */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed.*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- struct videoconfig vc;%@NL@%
- int modes[15] ={_TEXTBW40, _TEXTC40, _TEXTBW80, _TEXTC80,%@NL@%
- _MRES4COLOR, _MRESNOCOLOR, _HRESBW, _TEXTMONO,%@NL@%
- _MRES16COLOR, _HRES16COLOR, _ERESNOCOLOR, _ERESCOLOR,%@NL@%
- _VRES2COLOR, _VRES16COLOR, _MRES256COLOR};%@NL@%
- char *Adapt(short), *Display(short);%@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < 15; i++)%@NL@%
- {%@NL@%
- if (_setvideomode(modes[i]))%@NL@%
- {%@NL@%
- _getvideoconfig(&vc);%@NL@%
- printf("video mode is %d\n", vc.mode);%@NL@%
- printf("number of columns is %d\n", vc.numtextcols);%@NL@%
- printf("number of colors is %d\n", vc.numcolors);%@NL@%
- printf("number of pages is %d\n", vc.numvideopages);%@NL@%
- printf("adapter is %s\n", Adapt(vc.adapter));%@NL@%
- printf("display is %s\n", Display(vc.monitor));%@NL@%
- printf("the adapter has %dK of memory\n",%@NL@%
- vc.memory);%@NL@%
- }%@NL@%
- else%@NL@%
- printf("mode %d not supported\n", modes[i]);%@NL@%
- printf("strike a key for next mode\n");%@NL@%
- getch();%@NL@%
- }%@NL@%
- _setvideomode (_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Adapt() returns a pointer to a string describing */%@AE@%%@NL@%
- %@AB@%/* the adapter characterized by adapt_num. */%@AE@%%@NL@%
- char *Adapt(adapt_num)%@NL@%
- short adapt_num; %@AB@%/* videoconfig.adapter value */%@AE@%%@NL@%
- {%@NL@%
- static char *anames[6] = {"Monochrome", "CGA", "EGA",%@NL@%
- "MCGA", "VGA", "Not known"};%@NL@%
- char *point;%@NL@%
- %@NL@%
- switch (adapt_num)%@NL@%
- {%@NL@%
- case _MDPA : point = anames[0];%@NL@%
- break;%@NL@%
- case _CGA : point = anames[1];%@NL@%
- break;%@NL@%
- case _EGA : point = anames[2];%@NL@%
- break;%@NL@%
- case _MCGA : point = anames[3];%@NL@%
- break;%@NL@%
- case _VGA : point = anames[4];%@NL@%
- break;%@NL@%
- default : point = anames[5];%@NL@%
- }%@NL@%
- return point;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Display() returns a pointer to a string describing */%@AE@%%@NL@%
- %@AB@%/* the monitor characterized by disp. */%@AE@%%@NL@%
- char *Display(disp)%@NL@%
- short disp; %@AB@%/* videoconfig.monitor value */%@AE@%%@NL@%
- {%@NL@%
- static char *types[5] = {"monochrome", "color",%@NL@%
- "enhanced color", "analog",%@NL@%
- "unknown"};%@NL@%
- char *point;%@NL@%
- %@NL@%
- if (disp & _MONO)%@NL@%
- point = types[0];%@NL@%
- else if (disp & _COLOR)%@NL@%
- point = types[1];%@NL@%
- else if (disp & _ENHCOLOR)%@NL@%
- point = types[2];%@NL@%
- else if (disp & _ANALOG)%@NL@%
- point = types[3];%@NL@%
- else%@NL@%
- point = types[4];%@NL@%
- return point;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MOIRE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\MOIRE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* moire.c -- variation on dots.c */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed*/%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- BKCOLS 8 %@AB@%/* number of background colors */%@AE@%%@NL@%
- PALNUM 4 %@AB@%/* number of palettes */%@AE@%%@NL@%
- long Bkcolors[BKCOLS] = {_BLACK, _BLUE, _GREEN, _CYAN, _RED,%@NL@%
- _MAGENTA, _BROWN, _WHITE};%@NL@%
- main (argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- unsigned int col, row;%@NL@%
- short color = 0;%@NL@%
- int bkc_index = 1; %@AB@%/* blue background */%@AE@%%@NL@%
- short palette = 0; %@AB@%/* red, green, brown */%@AE@%%@NL@%
- int firstcol, firstrow, lastrow, lastcol;%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- int ch;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- %@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- printf("Can't do that mode.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- firstcol = vc.numxpixels / 5;%@NL@%
- firstrow = vc.numypixels / 5;%@NL@%
- lastcol = 4 * vc.numxpixels / 5;%@NL@%
- lastrow = 4 * vc.numypixels / 5;%@NL@%
- _selectpalette(palette);%@NL@%
- _setbkcolor (Bkcolors[bkc_index]);%@NL@%
- for (col = firstcol; col <= lastcol; ++col)%@NL@%
- {%@NL@%
- %@NL@%
- for (row = firstrow; row <= lastrow; ++row)%@NL@%
- {%@NL@%
- _setcolor(((row*row + col*col)/10)%vc.numcolors);%@NL@%
- _setpixel(col, row);%@NL@%
- }%@NL@%
- }%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch == 'p')%@NL@%
- _selectpalette(++palette % PALNUM);%@NL@%
- else if (ch == 'b')%@NL@%
- _setbkcolor(Bkcolors[++bkc_index % BKCOLS]);%@NL@%
- }%@NL@%
- _setvideomode(_DEFAULTMODE); %@AB@%/* reset orig. mode */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NARROW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\NARROW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* narrow.c -- a choppy C program */%@AE@%%@NL@%
- %@NL@%
- main( )%@NL@%
- {%@NL@%
- printf%@NL@%
- ("Hello, and welcome to QuickC!\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ONELINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\ONELINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* oneline.c -- shows how printf() continues */%@AE@%%@NL@%
- %@AB@%/* on the same line */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf("All displayed on");%@NL@%
- printf("the same line, with no space");%@NL@%
- printf(" unless specified.");%@NL@%
- %@AB@%/* note added space in line above */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%OPEQUAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\OPEQUAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* opequal.c -- shows combination math/assignment */%@AE@%%@NL@%
- %@AB@%/* operators and increment operators */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int m = 10, n = 5;%@NL@%
- printf("Starting values: m = %d n = %d\n",%@NL@%
- m, n);%@NL@%
- %@NL@%
- %@AB@%/* combination of arithmetic and assignment */%@AE@%%@NL@%
- printf("m += 2 makes m %d\n", m += 2);%@NL@%
- printf("m -= n makes m %d\n", m -= n);%@NL@%
- printf("m *= 2 makes m %d\n", m *= 2);%@NL@%
- %@NL@%
- %@AB@%/* two ways to increment m */%@AE@%%@NL@%
- printf("m = m + 1 makes m %d\n",%@NL@%
- m = m + 1);%@NL@%
- printf("m += 1 makes m %d\n",%@NL@%
- m += 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PACK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\PACK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* pack.c -- demonstrates structure packing with */%@AE@%%@NL@%
- %@AB@%/* the #pragma pack() directive */%@AE@%%@NL@%
- %@NL@%
- pack(4) %@AB@%/* 1, 2 or 4 */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- struct {%@NL@%
- char ch1;%@NL@%
- int int1;%@NL@%
- char ch2;%@NL@%
- long int2;%@NL@%
- } s;%@NL@%
- %@NL@%
- printf("ch1 -> %lu\n", (unsigned long)(&s.ch1));%@NL@%
- printf("int1 -> %lu\n", (unsigned long)(&s.int1));%@NL@%
- printf("ch2 -> %lu\n", (unsigned long)(&s.ch2));%@NL@%
- printf("int2 -> %lu\n", (unsigned long)(&s.int2));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PASSWORD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\PASSWORD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* password.c -- requires a password to complete the */%@AE@%%@NL@%
- %@AB@%/* program; illustrates a use of getch() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#define %@AE@%GUESS_LIMIT 4 %@NL@%
- WORD_LIMIT 10 %@AB@%/* maximum length of password */%@AE@%%@NL@%
- %@AI@%#define %@AE@%TRUE 1 %@NL@%
- %@AI@%#define %@AE@%FALSE 0 %@NL@%
- char *Password = "I'mOk";%@NL@%
- main()%@NL@%
- {%@NL@%
- int g_count = 0; %@AB@%/* guesses taken */%@AE@%%@NL@%
- int w_count; %@AB@%/* letters accepted */%@AE@%%@NL@%
- int in_count; %@AB@%/* letters entered */%@AE@%%@NL@%
- char entry[WORD_LIMIT + 1];%@NL@%
- char ch;%@NL@%
- int correct, go_on;%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- puts("Enter the secret password.");%@NL@%
- in_count = w_count = 0;%@NL@%
- %@AB@%/* the following loop accepts no more chars */%@AE@%%@NL@%
- %@AB@%/* than entry[] will hold, but keeps track */%@AE@%%@NL@%
- %@AB@%/* of total number typed */%@AE@%%@NL@%
- while ((ch = getch()) != '\r')%@NL@%
- {%@NL@%
- if (w_count < WORD_LIMIT)%@NL@%
- entry[w_count++] = ch;%@NL@%
- in_count++;%@NL@%
- }%@NL@%
- entry[w_count] = '\0';%@NL@%
- if (in_count != w_count)%@NL@%
- correct = FALSE; %@AB@%/* too many chars */%@AE@%%@NL@%
- else%@NL@%
- correct = (strcmp(entry, Password) == 0);%@NL@%
- g_count++;%@NL@%
- go_on = !correct && g_count < GUESS_LIMIT;%@NL@%
- if (go_on)%@NL@%
- puts("\nNo good; try again.");%@NL@%
- } while (go_on);%@NL@%
- if (!correct)%@NL@%
- {%@NL@%
- puts("Sorry, no more guesses. Bye.");%@NL@%
- return(1);%@NL@%
- }%@NL@%
- puts("Welcome to Swiss bank account 2929100.");%@NL@%
- puts("Your current balance is $10,232,862.61.");%@NL@%
- return(0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PEEK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\PEEK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* peek.c -- demonstrates how to cast an int to a */%@AE@%%@NL@%
- %@AB@%/* pointer */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *mem_ptr;%@NL@%
- unsigned int address;%@NL@%
- %@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("Examine what memory location?\n");%@NL@%
- printf("Enter location in decimal: ");%@NL@%
- if (scanf("%u", &address) != 1)%@NL@%
- break;%@NL@%
- %@NL@%
- mem_ptr = (char *)address; %@AB@%/* cast */%@AE@%%@NL@%
- %@NL@%
- printf("The value in %u is 0x%02X\n",%@NL@%
- address, (unsigned char)*mem_ptr);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PHONE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\PHONE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* phone.c -- a telephone number mini-database that */%@AE@%%@NL@%
- %@AB@%/* demonstrates fseek() */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for FILE, BUFSIZ, NULL */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXL (128) %@NL@%
- char Name[MAXL];%@NL@%
- char Number[MAXL];%@NL@%
- char File[] = "C:\\TMP\\PHONE.DB";%@NL@%
- int Count;%@NL@%
- FILE *Fp;%@NL@%
- int Distance = (MAXL * MAXL);%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- if (argc == 1)%@NL@%
- Ask();%@NL@%
- else%@NL@%
- Find(argv[1]);%@NL@%
- %@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- Find(char *str)%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- if ((Fp = fopen(File, "r")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't Read\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- if (fread(&Count, 1, sizeof(int), Fp) != sizeof(int))%@NL@%
- {%@NL@%
- fprintf(stderr,"\"%s\": Error Reading\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- for (i = 0; i < Count; i++)%@NL@%
- {%@NL@%
- fread(Name, 1, MAXL, Fp);%@NL@%
- fread(Number, 1, MAXL, Fp);%@NL@%
- if (ferror(Fp))%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Reading.\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- if (strcmp(*str, *Name) == 0)%@NL@%
- {%@NL@%
- printf("Name: %s\n", Name);%@NL@%
- printf("Number: %s\n", Number);%@NL@%
- return;%@NL@%
- }%@NL@%
- }%@NL@%
- fprintf(stderr, "\"%s\": Not in database.\n", str);%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- Ask()%@NL@%
- {%@NL@%
- if ((Fp = fopen(File, "r+")) == NULL)%@NL@%
- Make();%@NL@%
- else if (fread(&Count, 1, sizeof(int),Fp) != sizeof(int))%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Reading\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- printf("Name: ");%@NL@%
- if (gets(Name) == NULL || *Name == '\0')%@NL@%
- return;%@NL@%
- printf("Number: ");%@NL@%
- if (gets(Number) == NULL || *Number == '\0')%@NL@%
- return;%@NL@%
- if (fseek(Fp, (long)(Distance * Count), SEEK_CUR) != 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Seeking.\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- fwrite(Name, 1, MAXL, Fp);%@NL@%
- fwrite(Number, 1, MAXL, Fp);%@NL@%
- if (ferror(Fp))%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Writing.\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- if (fseek(Fp, 0L, SEEK_SET) != 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Seeking.\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- ++Count;%@NL@%
- if (fwrite(&Count, 1, sizeof(int),Fp) != sizeof(int))%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Writing\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- return;%@NL@%
- }%@NL@%
- %@NL@%
- Make()%@NL@%
- {%@NL@%
- if ((Fp = fopen(File, "w+")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't Create\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- Count = 0;%@NL@%
- if (fwrite(&Count, 1, sizeof(int), Fp) != sizeof(int))%@NL@%
- {%@NL@%
- fprintf(stderr," \"%s\": Error Creating\n", File);%@NL@%
- exit (1);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PHWORD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\PHWORD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* phword.c -- generate all the possible words */%@AE@%%@NL@%
- %@AB@%/* in a phone number; demonstrates */%@AE@%%@NL@%
- %@AB@%/* functions that return addresses */%@AE@%%@NL@%
- %@NL@%
- MAXD (7) %@AB@%/* 7 digits max */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int digits[MAXD], ndigits = 0, line = 0;%@NL@%
- char *letters; %@NL@%
- signed char digit;%@NL@%
- int a, b, c, d, e, f, g;%@NL@%
- extern char *Range();%@NL@%
- %@NL@%
- printf("Enter Phone Number (7 digits): ");%@NL@%
- do%@NL@%
- {%@NL@%
- digit = getch() - '0';%@NL@%
- if (digit == ('-' - '0'))%@NL@%
- continue;%@NL@%
- if (digit < 0 || digit > 9)%@NL@%
- {%@NL@%
- printf("\nAborted: Non Digit\n");%@NL@%
- return(1);%@NL@%
- }%@NL@%
- digits[ndigits++] = digit;%@NL@%
- printf("%d", digit);%@NL@%
- } while (ndigits < 7);%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- for( a = 0; a < 3; ++a)%@NL@%
- for( b = 0; b < 3; ++b)%@NL@%
- for( c = 0; c < 3; ++c)%@NL@%
- for( d = 0; d < 3; ++d)%@NL@%
- for( e = 0; e < 3; ++e)%@NL@%
- for( f = 0; f < 3; ++f)%@NL@%
- for( g = 0; g < 3; ++g)%@NL@%
- {%@NL@%
- printf("%c", Range(digits[0])[a]);%@NL@%
- printf("%c", Range(digits[1])[b]);%@NL@%
- printf("%c", Range(digits[2])[c]);%@NL@%
- printf("%c", Range(digits[3])[d]);%@NL@%
- printf("%c", Range(digits[4])[e]);%@NL@%
- printf("%c", Range(digits[5])[f]);%@NL@%
- printf("%c", Range(digits[6])[g]);%@NL@%
- printf("\n");%@NL@%
- if (++line == 20)%@NL@%
- {%@NL@%
- printf("Press Any key for More");%@NL@%
- printf(" (or q to quit): ");%@NL@%
- if (getch() == 'q')%@NL@%
- return (0);%@NL@%
- printf("\n");%@NL@%
- line = 0;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- char *Range(int key)%@NL@%
- {%@NL@%
- static char keys[10][3] = {%@NL@%
- {'0', '0', '0' },%@NL@%
- {'1', '1', '1' },%@NL@%
- {'a', 'b', 'c' },%@NL@%
- {'d', 'e', 'f' },%@NL@%
- {'g', 'h', 'i' },%@NL@%
- {'j', 'k', 'l' },%@NL@%
- {'m', 'n', 'o' },%@NL@%
- {'p', 'r', 's' },%@NL@%
- {'t', 'u', 'v' },%@NL@%
- {'w', 'x', 'y' }%@NL@%
- };%@NL@%
- %@NL@%
- return (keys[key]);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PIXELS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\PIXELS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* pixels.c -- create shapes */%@AE@%%@NL@%
- %@AB@%/* from random pixels */%@AE@%%@NL@%
- %@NL@%
- <graph.h> %@AB@%/* for graphics */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int pixels, xpos, ypos;%@NL@%
- %@AB@%/* window coordinates */%@AE@%%@NL@%
- int xmin = 100, xmax = 540;%@NL@%
- int ymin = 50, ymax = 150;%@NL@%
- %@NL@%
- srand(0); %@AB@%/* init random nums */%@AE@%%@NL@%
- _setvideomode(_HRESBW); %@AB@%/* CGA 640 x 200 */%@AE@%%@NL@%
- _setcolor(1); %@AB@%/* white foreground */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* generate random pixel locations */%@AE@%%@NL@%
- for (pixels = 1; pixels < 10000; pixels++)%@NL@%
- {%@NL@%
- xpos = rand() % 639;%@NL@%
- ypos = rand() % 199;%@NL@%
- %@NL@%
- %@AB@%/* set pixel if within window */%@AE@%%@NL@%
- if ((xpos > xmin && xpos < xmax) &&%@NL@%
- (ypos > ymin && ypos < ymax))%@NL@%
- _setpixel(xpos, ypos);%@NL@%
- }%@NL@%
- getch(); %@AB@%/* freeze screen until key pressed */%@AE@%%@NL@%
- %@AB@%/* restore original video mode */%@AE@%%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%POINTER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\POINTER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* pointer.c -- demonstrates pointer declaration, */%@AE@%%@NL@%
- %@AB@%/* assignment, and use */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%WAIT printf("(press any key)"); getch(); \ %@NL@%
- printf("\n\n")%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num, *address_var;%@NL@%
- %@NL@%
- num = 0;%@NL@%
- address_var = #%@NL@%
- %@NL@%
- printf("The address of the variable ");%@NL@%
- printf("\"num\" is: 0x%04X\n", &num );%@NL@%
- printf("The value in the pointer ");%@NL@%
- printf("\"address_var\" is: 0x%04X\n", address_var);%@NL@%
- printf("The value in the variable ");%@NL@%
- printf("\"num\" is: %d\n", num );%@NL@%
- WAIT;%@NL@%
- printf("Since \"address_var\" points to \"num\"\n");%@NL@%
- printf("the value in ");%@NL@%
- printf("\"*address_var\" is: %d\n", *address_var);%@NL@%
- WAIT;%@NL@%
- printf("To verify this, let's store 3 in\n");%@NL@%
- printf("\"*address_var\", then print out ");%@NL@%
- printf("\"num\" and \"*address_var\"\n");%@NL@%
- printf("again.\n");%@NL@%
- WAIT;%@NL@%
- %@NL@%
- printf("Doing: *address_var = 3;\n\n");%@NL@%
- *address_var = 3;%@NL@%
- %@NL@%
- printf("The address of the variable ");%@NL@%
- printf("\"num\" is: 0x%04X\n", &num);%@NL@%
- printf("The value in the pointer ");%@NL@%
- printf("\"address_var\" is: 0x%04X\n", address_var);%@NL@%
- printf("The value in the variable ");%@NL@%
- printf("\"num\" is: %d\n", num);%@NL@%
- WAIT;%@NL@%
- printf("Since \"address_var\" points to \"num\"\n");%@NL@%
- printf("the value in ");%@NL@%
- printf("\"*address_var\" is: %d\n", *address_var);%@NL@%
- WAIT;%@NL@%
- %@NL@%
- printf("Now we will add 15 to \"num\" and print\n");%@NL@%
- printf("\"num\" and \"*address_var\" again.\n");%@NL@%
- WAIT;%@NL@%
- %@NL@%
- printf("Doing: num += 15;\n\n");%@NL@%
- num += 15;%@NL@%
- %@NL@%
- printf("The address of the variable ");%@NL@%
- printf("\"num\" is: 0x%04X\n", &num);%@NL@%
- printf("The value in the pointer ");%@NL@%
- printf("\"address_var\" is: 0x%04X\n", address_var);%@NL@%
- printf("The value in the variable ");%@NL@%
- printf("\"num\" is: %d\n", num);%@NL@%
- WAIT;%@NL@%
- printf("Since \"address_var\" points to \"num\"\n");%@NL@%
- printf("the value in ");%@NL@%
- printf("\"*address_var\" is: %d\n", *address_var);%@NL@%
- WAIT;%@NL@%
- %@NL@%
- printf("Doing: return (*address_var);\n\n");%@NL@%
- return (*address_var);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PORTINFO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\PORTINFO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* portinfo.c -- reads port values */%@AE@%%@NL@%
- %@AB@%/* program list -- portinfo.c (inp() not in core lib) */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned int portnum;%@NL@%
- int regvalue;%@NL@%
- %@NL@%
- printf("Enter number (in hex) of the port ");%@NL@%
- printf("you wish to read: ");%@NL@%
- while (scanf("%x", &portnum) == 1)%@NL@%
- {%@NL@%
- regvalue = inp(portnum);%@NL@%
- printf("\nValue returned for port %x is %d (decimal)"%@NL@%
- " %x (hex)\n", portnum, regvalue, regvalue);%@NL@%
- printf("Next port? (q to quit): ");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%POWER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\POWER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* power.c -- attempting to raise to a power */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- { %@NL@%
- int number; %@NL@%
- %@NL@%
- number = 10**3; %@AB@%/* raise 10 to 3rd power? */%@AE@%%@NL@%
- printf("%d\n", number); %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PREPOST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\PREPOST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* prepost.c -- shows effect of pre- */%@AE@%%@NL@%
- %@AB@%/* and post-increments */%@AE@%%@NL@%
- %@AB@%/* and decrements */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int b = 100;%@NL@%
- %@NL@%
- printf("b is %d\n", b);%@NL@%
- printf("b++ is still %d\n", b++);%@NL@%
- printf("but after it's used, ");%@NL@%
- printf("b is incremented to %d\n\n, b);%@NL@%
- %@NL@%
- printf("++b, on the other hand, ");%@NL@%
- printf("is immediately %d\n", ++b);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PROTO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\PROTO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* proto.c -- demonstrate function prototyping */%@AE@%%@NL@%
- %@AB@%/* and parameter checking */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float n = 9995.997;%@NL@%
- int i;%@NL@%
- int examine(int num); %@AB@%/* declare function */%@AE@%%@NL@%
- %@AB@%/* with prototype */%@AE@%%@NL@%
- %@NL@%
- printf("n in main() is %f\n", n);%@NL@%
- i = examine(n); %@AB@%/* pass float to function */%@AE@%%@NL@%
- printf("examine() returned n as %d\n", i);%@NL@%
- }%@NL@%
- %@NL@%
- int examine(num)%@NL@%
- {%@NL@%
- printf("examine() says n is %d\n", num);%@NL@%
- return(num);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%QCHELLO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP02\QCHELLO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* qchello.c -- a simple C program */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf("Hello, and welcome to QuickC!\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RACE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\RACE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* race.c -- race of the patterned circles */%@AE@%%@NL@%
- %@AB@%/* Illustrates animation with _getimage() and */%@AE@%%@NL@%
- %@AB@%/* _putimage(), random number use with srand() and */%@AE@%%@NL@%
- %@AB@%/* rand(), and system clock use with time() and */%@AE@%%@NL@%
- %@AB@%/* ftime().%@NL@%
- %@AB@%/* Program list: race.c (for srand(), rand(), and */%@AE@%%@NL@%
- %@AB@%/* ftime()) */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\timeb.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%END 25 %@NL@%
- %@AI@%#define %@AE@%FIGNUM 3 %@NL@%
- typedef char far *PTFRCHAR;%@NL@%
- PTFRCHAR Bufs[FIGNUM];%@NL@%
- unsigned char Masks[FIGNUM][8] = {%@NL@%
- {0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00},%@NL@%
- {0xF0,0xF0,0xF0,0xF0,0x0F,0x0F,0x0F,0x0F},%@NL@%
- {0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA}};%@NL@%
- short Xul[FIGNUM], Yul[FIGNUM]; %@AB@%/* figure locations */%@AE@%%@NL@%
- short Xsize, Ysize; %@AB@%/* figure size */%@AE@%%@NL@%
- struct videoconfig Vc;%@NL@%
- void Initialize(void);%@NL@%
- void Draw_n_store(void);%@NL@%
- void Move_figs(void);%@NL@%
- void Wait(double);%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr,"mode %d not supported\n",mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- Initialize();%@NL@%
- Draw_n_store();%@NL@%
- _settextcolor(2);%@NL@%
- _settextposition(1, 1);%@NL@%
- _outtext("Place your bets and type a key");%@NL@%
- _settextposition(25, 1);%@NL@%
- _outtext("Type a key again when done");%@NL@%
- getch();%@NL@%
- Move_figs();%@NL@%
- getch();%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- void Initialize()%@NL@%
- {%@NL@%
- int i;%@NL@%
- float ar; %@AB@%/* aspect ratio */%@AE@%%@NL@%
- %@NL@%
- _getvideoconfig(&Vc);%@NL@%
- ar = (float)(10 * Vc.numypixels) / (6.5 * Vc.numxpixels);%@NL@%
- %@AB@%/* set size, initial positions */%@AE@%%@NL@%
- Xsize = Vc.numxpixels / 30;%@NL@%
- Ysize = ar * Xsize;%@NL@%
- for(i = 0; i < FIGNUM; i++)%@NL@%
- {%@NL@%
- Xul[i] = 0;%@NL@%
- Yul[i] = (i + 1) * Vc.numypixels /%@NL@%
- (FIGNUM + 1);%@NL@%
- }%@NL@%
- _selectpalette(0);%@NL@%
- _setcolor(1);%@NL@%
- %@AB@%/* draw finish line */%@AE@%%@NL@%
- _moveto(END * Xsize, 0);%@NL@%
- _lineto(END * Xsize, Vc.numypixels - 1);%@NL@%
- }%@NL@%
- %@NL@%
- void Draw_n_store() %@AB@%/* draw images, save them */%@AE@%%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < FIGNUM; i++)%@NL@%
- {%@NL@%
- _setcolor(i + 1);%@NL@%
- _setfillmask(Masks[i]);%@NL@%
- _ellipse(_GFILLINTERIOR ,Xul[i], Yul[i],%@NL@%
- Xul[i] + Xsize, Yul[i] + Ysize);%@NL@%
- _ellipse(_GBORDER ,Xul[i], Yul[i],%@NL@%
- Xul[i] + Xsize, Yul[i] + Ysize);%@NL@%
- Bufs[i] = (PTFRCHAR) malloc((unsigned int)%@NL@%
- _imagesize(0,Yul[i], Xul[i] +%@NL@%
- Xsize, Yul[i] + Ysize));%@NL@%
- _getimage(Xul[i],Yul[i], Xul[i] + Xsize, Yul[i] +%@NL@%
- Ysize, Bufs[i]);%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- void Move_figs()%@NL@%
- {%@NL@%
- int i, j;%@NL@%
- static int dx[FIGNUM] = {0, 0, 0}; %@AB@%/* displacements */%@AE@%%@NL@%
- time_t tval;%@NL@%
- %@NL@%
- time(&tval); %@AB@%/* use the current time value */%@AE@%%@NL@%
- srand(tval); %@AB@%/* to initialize rand() */%@AE@%%@NL@%
- while (dx[0] < END && dx[1] < END && dx[2] < END)%@NL@%
- {%@NL@%
- for (i = 0; i < FIGNUM; i++)%@NL@%
- {%@NL@%
- %@AB@%/* advance the figure one position if */%@AE@%%@NL@%
- %@AB@%/* rand() returns an even number */%@AE@%%@NL@%
- if (rand() % 2 == 0)%@NL@%
- {%@NL@%
- %@AB@%/* erase old image */%@AE@%%@NL@%
- _putimage(dx[i] * Xsize, Yul[i],%@NL@%
- Bufs[i], _GXOR);%@NL@%
- %@AB@%/* redraw in new position */%@AE@%%@NL@%
- _putimage((1 + dx[i]) * Xsize, Yul[i],%@NL@%
- Bufs[i], _GPSET);%@NL@%
- dx[i]++;%@NL@%
- }%@NL@%
- }%@NL@%
- Wait(0.15);%@NL@%
- }%@NL@%
- for (j = 0; j < 5; j++)%@NL@%
- {%@NL@%
- for(i = 0; i < FIGNUM; i++)%@NL@%
- {%@NL@%
- %@AB@%/* flash winning figure */%@AE@%%@NL@%
- if (dx[i] >= END)%@NL@%
- {%@NL@%
- Wait(0.2);%@NL@%
- _putimage(dx[i] * Xsize,Yul[i],%@NL@%
- Bufs[i], _GPRESET);%@NL@%
- Wait(0.2);%@NL@%
- _putimage(dx[i] * Xsize,Yul[i],%@NL@%
- Bufs[i], _GPSET);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void Wait(pause) %@AB@%/* wait for pause seconds */%@AE@%%@NL@%
- double pause;%@NL@%
- {%@NL@%
- struct timeb start, end;%@NL@%
- long delay;%@NL@%
- %@NL@%
- delay = 1000 * pause; %@AB@%/* convert to milliseconds */%@AE@%%@NL@%
- ftime(&start);%@NL@%
- ftime(&end);%@NL@%
- while ((1000 * (end.time - start.time) +%@NL@%
- + end.millitm - start.millitm) < delay)%@NL@%
- ftime(&end);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%READKEY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\READKEY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* readkey.c -- contains the Readkey() function */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- KEYINTR 0x16 %@AB@%/* keyboard read interrupt */%@AE@%%@NL@%
- GETCHAR 0 %@AB@%/* read scancode function */%@AE@%%@NL@%
- struct SCANCODE {%@NL@%
- unsigned char ascii; %@AB@%/* ascii code */%@AE@%%@NL@%
- unsigned char scan; %@AB@%/* scan code */%@AE@%%@NL@%
- };%@NL@%
- %@NL@%
- struct SCANCODE Readkey()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- struct SCANCODE scancode;%@NL@%
- %@NL@%
- reg.h.ah = GETCHAR; %@AB@%/* specify function */%@AE@%%@NL@%
- int86(KEYINTR, ®, ®); %@AB@%/* note use of & oper.*/%@AE@%%@NL@%
- scancode.ascii = reg.h.al;%@NL@%
- scancode.scan = reg.h.ah;%@NL@%
- return (scancode);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RECALL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\RECALL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* recall.c -- displays previously stored screen, */%@AE@%%@NL@%
- %@AB@%/* including attributes. Uses DMA. */%@AE@%%@NL@%
- %@AB@%/* Program list: recall.c, scrfun.c */%@AE@%%@NL@%
- %@AB@%/* User include files: scrn.h, grafchar.h */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@AI@%#include %@AE@%"grafchar.h" %@NL@%
- %@NL@%
- main(ac, ar)%@NL@%
- int ac;%@NL@%
- char *ar[];%@NL@%
- {%@NL@%
- unsigned char mode;%@NL@%
- unsigned short char_attr;%@NL@%
- FILE *save;%@NL@%
- unsigned int offset;%@NL@%
- char filename[81];%@NL@%
- VIDMEM screen;%@NL@%
- %@NL@%
- if (ac < 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "Usage: %s filename\n", ar[0]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- if ((save = fopen(ar[1],"rb")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr, "Can't open %s\n", ar[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- if ((mode = Getvmode()) == TEXTMONO)%@NL@%
- screen = MONMEM;%@NL@%
- else if (mode == TEXTC80 || mode == TEXTBW80)%@NL@%
- screen = CGAMEM;%@NL@%
- else%@NL@%
- exit(1);%@NL@%
- %@NL@%
- Clearscr();%@NL@%
- for (offset = 0; offset < CHARS; offset++)%@NL@%
- {%@NL@%
- fread(&char_attr, 2, 1, save);%@NL@%
- screen[offset] = char_attr;%@NL@%
- }%@NL@%
- fclose(save);%@NL@%
- Setcurs(23, 0, PAGE);%@NL@%
- getch(); %@AB@%/* anti scrolling for QC environment */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RECEIPTS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\RECEIPTS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* receipts.c -- calculates gross and net */%@AE@%%@NL@%
- %@AB@%/* receipts on sales */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int units = 38; %@AB@%/* number sold */%@AE@%%@NL@%
- float price = 149.99, %@AB@%/* price per item */%@AE@%%@NL@%
- rate = 0.06; %@AB@%/* sales tax rate */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* variables to hold calculated totals */%@AE@%%@NL@%
- float gross, tax, net;%@NL@%
- %@NL@%
- %@AB@%/* perform calculations */%@AE@%%@NL@%
- net = units * price;%@NL@%
- tax = net * rate;%@NL@%
- gross = net + tax;%@NL@%
- %@NL@%
- %@AB@%/* print results */%@AE@%%@NL@%
- printf("\tSales Report\n");%@NL@%
- printf("Net sales: \t%6.2f\n", net);%@NL@%
- printf("Tax:\t\t %5.2f\n", tax);%@NL@%
- printf("Gross sales:\t%6.2f\n", gross);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RECT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\RECT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rect.c -- illustrates logical coordinates, */%@AE@%%@NL@%
- %@AB@%/* the _rectangle() and _setlinestyle() */%@AE@%%@NL@%
- %@AB@%/* functions */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%STYLES 5 %@NL@%
- short Linestyles[STYLES] = {0xFFFF, 0x8888, 0x7777,%@NL@%
- 0x00FF, 0x8787};%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES4COLOR;%@NL@%
- int xcent, ycent;%@NL@%
- int xsize, ysize;%@NL@%
- int i;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- printf("Can't open that mode.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- xcent = vc.numxpixels / 2 - 1;%@NL@%
- ycent = vc.numypixels / 2 - 1;%@NL@%
- _setlogorg(xcent, ycent);%@NL@%
- xsize = 0.9 * xcent;%@NL@%
- ysize = 0.9 * ycent;%@NL@%
- _selectpalette(1);%@NL@%
- _setcolor(3);%@NL@%
- _rectangle(_GBORDER, -xsize, -ysize, xsize, ysize);%@NL@%
- xsize *= 0.9;%@NL@%
- ysize *= 0.9;%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GFILLINTERIOR, -xsize, -ysize, xsize, ysize);%@NL@%
- for (i = 0; i < 16; i++)%@NL@%
- {%@NL@%
- _setcolor(((i % 2) == 0) ? 2 : 3);%@NL@%
- _setlinestyle(Linestyles[ i % 5 ]);%@NL@%
- xsize *= 0.9;%@NL@%
- ysize *= 0.9;%@NL@%
- _rectangle(_GBORDER, -xsize, -ysize, xsize, ysize);%@NL@%
- }%@NL@%
- getch(); %@AB@%/* Type a key to terminate. */%@AE@%%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RECURSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\RECURSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* recurse.c -- demonstrates recursion */%@AE@%%@NL@%
- %@NL@%
- int level = 1; %@AB@%/* recursion level */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- int num, result;%@NL@%
- %@NL@%
- printf("Factorial of what number? ");%@NL@%
- scanf("%d", &num);%@NL@%
- result = factorial(num);%@NL@%
- printf("Result is: %d\n", result);%@NL@%
- }%@NL@%
- %@NL@%
- factorial(number)%@NL@%
- {%@NL@%
- int result;%@NL@%
- printf("entering: ");%@NL@%
- printf("level %d. number = %d. &number = %d\n",%@NL@%
- level++, number, &number);%@NL@%
- %@NL@%
- if (number == 0)%@NL@%
- result = 1;%@NL@%
- else%@NL@%
- result = number * factorial(number - 1);%@NL@%
- %@NL@%
- printf("exiting : ");%@NL@%
- printf("level %d. number = %d. &number = %d. ",%@NL@%
- --level, number, &number);%@NL@%
- printf("result = %d\n", result);%@NL@%
- %@NL@%
- return(result);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%REKEY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\REKEY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rekey.c -- transliterates typed input */%@AE@%%@NL@%
- %@AB@%/* This program illustrates getch() and putch(). */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- ESC '\033' %@AB@%/* the escape key */%@AE@%%@NL@%
- char Newchars[] = "qwertyuiopasdfghjklzxcvbnm";%@NL@%
- %@AB@%/* values to be assigned to the a,b,c keys, etc. */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- printf("Type characters and see them transformed;\n");%@NL@%
- printf("Press the Esc key to terminate.\n");%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- if (islower(ch))%@NL@%
- putch(Newchars[ch - 'a']);%@NL@%
- else if (isupper(ch))%@NL@%
- {%@NL@%
- ch = tolower(ch);%@NL@%
- putch(toupper(Newchars[ch - 'a']));%@NL@%
- }%@NL@%
- else if (ch == '\r')%@NL@%
- {%@NL@%
- putch('\n');%@NL@%
- putch('\r');%@NL@%
- }%@NL@%
- else%@NL@%
- putch(ch);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RELATION.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\RELATION.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* relation.c -- shows effect of */%@AE@%%@NL@%
- %@AB@%/* relational operators */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a = 5, b = 3, c = 4;%@NL@%
- printf("a = %d\t b = %d\t c = %d\n", a, b, c);%@NL@%
- %@NL@%
- printf("Expression a > b has a value of %d\n",%@NL@%
- a > b);%@NL@%
- printf("Expression a == c has a value of %d\n",%@NL@%
- a == c);%@NL@%
- printf("Expression a > (b + c) has a value of %d\n",%@NL@%
- a > (b + c));%@NL@%
- printf("Expression a = b has a value of %d\n",%@NL@%
- a = b); %@AB@%/* what happened here? */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%REMOIRE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\REMOIRE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* remoire.c -- adds palette remapping to moire.c */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%MAXCOLORS 64 %@NL@%
- %@AI@%#define %@AE@%PALCOLORS 16 %@NL@%
- long Ega_to_vga(int);%@NL@%
- %@NL@%
- main (argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- unsigned int col, row;%@NL@%
- long colors[MAXCOLORS];%@NL@%
- long palette[PALCOLORS];%@NL@%
- int index;%@NL@%
- int shift = 1;%@NL@%
- int firstcol, firstrow, lastrow, lastcol;%@NL@%
- int mode = _ERESCOLOR;%@NL@%
- %@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- %@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- printf("Can't do that mode.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@AB@%/* Create array of all 64 color values. */%@AE@%%@NL@%
- for (index = 0; index < MAXCOLORS; index++)%@NL@%
- colors[index] = Ega_to_vga(index);%@NL@%
- %@AB@%/* Create array of 16 palette choices. */%@AE@%%@NL@%
- for (index = 0; index < PALCOLORS; index++)%@NL@%
- palette[index] = colors[index];%@NL@%
- _remapallpalette(palette);%@NL@%
- _getvideoconfig(&vc);%@NL@%
- firstcol = vc.numxpixels / 5;%@NL@%
- firstrow = vc.numypixels / 5;%@NL@%
- lastcol = 4 * vc.numxpixels / 5;%@NL@%
- lastrow = 4 * vc.numypixels / 5;%@NL@%
- %@NL@%
- for (col = firstcol; col <= lastcol; ++col)%@NL@%
- {%@NL@%
- for (row = firstrow; row <= lastrow; ++row)%@NL@%
- {%@NL@%
- _setcolor(((row * row + col * col) / 10)%@NL@%
- % vc.numcolors);%@NL@%
- _setpixel(col, row);%@NL@%
- }%@NL@%
- }%@NL@%
- _settextposition(1, 1);%@NL@%
- _outtext("Type a key to stop or start.");%@NL@%
- _settextposition(2, 1);%@NL@%
- _outtext("Type [Esc] while paused to quit.");%@NL@%
- do%@NL@%
- {%@NL@%
- while (!kbhit())%@NL@%
- {%@NL@%
- %@AB@%/* Set palette array to new color values. */%@AE@%%@NL@%
- for (index = 1; index < PALCOLORS; index++)%@NL@%
- palette[index] = (colors[(index + shift)%@NL@%
- % MAXCOLORS]);%@NL@%
- _remapallpalette(palette);%@NL@%
- shift++;%@NL@%
- }%@NL@%
- getch(); %@AB@%/* pause until key is typed */%@AE@%%@NL@%
- } while (getch() != ESC);%@NL@%
- %@NL@%
- _setvideomode(_DEFAULTMODE); %@AB@%/* reset orig. mode */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- long Ega_to_vga(egacolor)%@NL@%
- int egacolor; %@AB@%/* ega color value */%@AE@%%@NL@%
- {%@NL@%
- static long vgavals[6] = {0x2A0000L, 0x002A00L, 0x00002AL,%@NL@%
- 0x150000L, 0x001500L, 0x000015L};%@NL@%
- long vgacolor = 0L; %@AB@%/* vga color value */%@AE@%%@NL@%
- int bit;%@NL@%
- %@NL@%
- for (bit = 0; bit < 6; bit++)%@NL@%
- vgacolor += ((egacolor >> bit) &1) * vgavals[bit];%@NL@%
- return (vgacolor);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%REVERSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\REVERSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* reverse.c -- demonstrates an array of pointers */%@AE@%%@NL@%
- %@AB@%/* by reversing lines of text */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* for size_t */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXL 20 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *cptrs[MAXL]; %@AB@%/* array of pointers */%@AE@%%@NL@%
- char *cp;%@NL@%
- int count, i, j, ch;%@NL@%
- extern char *Getbyte();%@NL@%
- %@NL@%
- %@NL@%
- printf("Type in several lines of text, and I will\n");%@NL@%
- printf("print them back out in reverse order.\n");%@NL@%
- printf("(Any blank line ends input):\n");%@NL@%
- %@NL@%
- for (i = 0; i < MAXL; ++i)%@NL@%
- {%@NL@%
- cp = Getbyte();%@NL@%
- cptrs[i] = cp; %@AB@%/* assign address to pointer */%@AE@%%@NL@%
- count = 0;%@NL@%
- while ((ch = getchar()) != '\n') %@AB@%/* gather line */%@AE@%%@NL@%
- {%@NL@%
- *cp = ch;%@NL@%
- cp = Getbyte();%@NL@%
- ++count;%@NL@%
- }%@NL@%
- *cp = '\0';%@NL@%
- if (count == 0) %@AB@%/* all done if blank line */%@AE@%%@NL@%
- break;%@NL@%
- }%@NL@%
- printf("---------<reversed>---------\n");%@NL@%
- for (j = i-1; j >= 0; --j)%@NL@%
- {%@NL@%
- printf("%s\n", cptrs[j]);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- char *Getbyte(void)%@NL@%
- {%@NL@%
- char *cp;%@NL@%
- %@NL@%
- if ((cp = sbrk(1)) == (char *)-1)%@NL@%
- {%@NL@%
- printf("Panic: sbrk failed\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- return (cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%REVERSE2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\REVERSE2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* reverse2.c -- demonstrates a pointer to a pointer */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* for size_t */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXL 20 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *cptrs[MAXL];%@NL@%
- char **pp; %@AB@%/* pointer to pointer */%@AE@%%@NL@%
- char *cp;%@NL@%
- int count, i, ch;%@NL@%
- extern char *Getbyte();%@NL@%
- %@NL@%
- printf("Type in several lines of text, and I will\n");%@NL@%
- printf("print them back out in reverse order.\n");%@NL@%
- printf("(Any blank line ends input):\n");%@NL@%
- %@NL@%
- for (i = 0; i < MAXL; ++i)%@NL@%
- {%@NL@%
- cp = Getbyte();%@NL@%
- cptrs[i] = cp; %@AB@%/* assign address to pointer */%@AE@%%@NL@%
- count = 0;%@NL@%
- while ((ch = getchar()) != '\n') %@AB@%/* gather line */%@AE@%%@NL@%
- {%@NL@%
- *cp = ch;%@NL@%
- cp = Getbyte();%@NL@%
- ++count;%@NL@%
- }%@NL@%
- *cp = '\0';%@NL@%
- if (count == 0) %@AB@%/* all done if blank line */%@AE@%%@NL@%
- break;%@NL@%
- }%@NL@%
- printf("---------<reversed>---------\n");%@NL@%
- pp = &cptrs[i];%@NL@%
- while (pp >= cptrs)%@NL@%
- {%@NL@%
- printf("%s\n", *(pp--));%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- char *Getbyte(void)%@NL@%
- {%@NL@%
- char *cp;%@NL@%
- %@NL@%
- if ((cp = sbrk(1)) == (char *)-1)%@NL@%
- {%@NL@%
- printf("Panic: sbrk failed\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- return (cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RIGHTSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\RIGHTSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rightstr.c -- a C version of BASIC's RIGHT$ */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- char *Rightstr(char *str, int cnt)%@NL@%
- {%@NL@%
- static char *cp = NULL;%@NL@%
- char *malloc();%@NL@%
- %@NL@%
- if (cnt > strlen(str))%@NL@%
- cnt = strlen(str);%@NL@%
- if (cp != NULL)%@NL@%
- free(cp);%@NL@%
- if ((cp = malloc(cnt + 1)) == NULL)%@NL@%
- return (NULL);%@NL@%
- strcpy(cp, str + strlen(str) - cnt);%@NL@%
- return (cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%RINGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\RINGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rings.c -- shoots colored rings */%@AE@%%@NL@%
- %@AB@%/* This program illustrates _remapallpalette() and */%@AE@%%@NL@%
- %@AB@%/* how it can be used to produce the appearance of */%@AE@%%@NL@%
- %@AB@%/* motion. The program is intended for EGA modes 13, */%@AE@%%@NL@%
- %@AB@%/* 14, and 16. */%@AE@%%@NL@%
- %@AB@%/* Program list: rings.c */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@NL@%
- long Colors[16] = {_BLACK, _BLUE, _GREEN, _CYAN,%@NL@%
- _RED, _MAGENTA, _BROWN, _WHITE,%@NL@%
- _GRAY, _LIGHTBLUE, _LIGHTGREEN,%@NL@%
- _LIGHTCYAN, _LIGHTRED, _LIGHTMAGENTA,%@NL@%
- _LIGHTYELLOW,_BRIGHTWHITE };%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- float aspect;%@NL@%
- short xmax, ymax;%@NL@%
- long int newpalette[16];%@NL@%
- long int temp;%@NL@%
- int index;%@NL@%
- int hot1 = 1; %@AB@%/* first colored ring */%@AE@%%@NL@%
- int hot2 = 8; %@AB@%/* second colored ring */%@AE@%%@NL@%
- int mode = _ERESCOLOR;%@NL@%
- int ch;%@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (mode < 13)%@NL@%
- {%@NL@%
- fprintf(stderr,"Requires EGA or VGA mode\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr,"% d mode unavailable\n", mode);%@NL@%
- exit(2);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- _setlogorg(vc.numxpixels / 2 - 1, vc.numypixels / 2 - 1);%@NL@%
- aspect = (10.0 * vc.numypixels) / (6.5 * vc.numxpixels);%@NL@%
- ymax = vc.numypixels / 2 - 2;%@NL@%
- xmax = ymax / aspect;%@NL@%
- for (index = 2; index < 16; index++)%@NL@%
- newpalette[index] = _LIGHTBLUE;%@NL@%
- newpalette[0] = _GRAY;%@NL@%
- newpalette[hot1] = _RED;%@NL@%
- newpalette[hot2] = _LIGHTRED;%@NL@%
- _remapallpalette(newpalette); %@AB@%/* set initial palette */%@AE@%%@NL@%
- _setcolor(1);%@NL@%
- _ellipse(_GFILLINTERIOR, -xmax, -ymax, xmax, ymax);%@NL@%
- %@AB@%/* draw concentric circles */%@AE@%%@NL@%
- for (index = 2; index < 16; index++)%@NL@%
- {%@NL@%
- xmax /= 1.4;%@NL@%
- ymax /= 1.4;%@NL@%
- _setcolor(index);%@NL@%
- _ellipse(_GFILLINTERIOR, -xmax, -ymax, xmax, ymax);%@NL@%
- }%@NL@%
- do%@NL@%
- {%@NL@%
- while (!kbhit())%@NL@%
- {%@NL@%
- temp = newpalette[15];%@NL@%
- for(index = 15; index > 1; index--)%@NL@%
- newpalette[index] = newpalette[index - 1];%@NL@%
- newpalette[1] = temp;%@NL@%
- _remapallpalette(newpalette);%@NL@%
- hot1 = hot1 % 15 + 1; %@AB@%/* index of colored ring */%@AE@%%@NL@%
- hot2 = hot2 % 15 + 1;%@NL@%
- }%@NL@%
- ch = getch();%@NL@%
- if (ch > '1' && ch < '8') %@AB@%/* reassign colors */%@AE@%%@NL@%
- {%@NL@%
- newpalette[hot1] = Colors[ ch - '0'];%@NL@%
- newpalette[hot2] = Colors[ ch - '0' + 8];%@NL@%
- }%@NL@%
- } while (ch != ESC);%@NL@%
- _clearscreen(_GCLEARSCREEN);%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ROAMSCRN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\ROAMSCRN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* roamscrn.c -- puts text on screen, positions */%@AE@%%@NL@%
- %@AB@%/* cursor with arrow keys, uses F1 */%@AE@%%@NL@%
- %@AB@%/* and F2 to control video inverse. */%@AE@%%@NL@%
- %@AB@%/* program list -- roamscreen.c, scrfun.lib */%@AE@%%@NL@%
- %@AB@%/* user include files -- keys.h, scrn.h */%@AE@%%@NL@%
- %@AB@%/* Note: Activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%"keys.h" %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@AI@%#define %@AE@%BELL '\a' %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%PAGE 0 %@NL@%
- %@NL@%
- char *Heading =%@NL@%
- "Use standard keys to enter text. Use arrow keys to "%@NL@%
- "reposition cursor.\nUse F2 to turn on video inverse "%@NL@%
- "and F1 to turn it off.\nHit the ESC key to quit.\n";%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- unsigned char atr = NORMAL;%@NL@%
- %@NL@%
- Clearscr();%@NL@%
- Home();%@NL@%
- printf("%s", Heading);%@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch == '\r')%@NL@%
- {%@NL@%
- putch('\n');%@NL@%
- putch('\r');%@NL@%
- }%@NL@%
- else if (ch != 0)%@NL@%
- {%@NL@%
- Write_ch_atr(ch, atr, PAGE, 1);%@NL@%
- if (!Cursrt())%@NL@%
- putch(BELL);%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- ch = getch();%@NL@%
- switch (ch)%@NL@%
- {%@NL@%
- case F1 : atr = NORMAL; break;%@NL@%
- case F2 : atr = VIDREV; break;%@NL@%
- case UP : Rewrite(atr, PAGE);%@NL@%
- if (!Cursup())%@NL@%
- putch(BELL);%@NL@%
- break;%@NL@%
- case DN : Rewrite(atr, PAGE);%@NL@%
- if (!Cursdn())%@NL@%
- putch(BELL);%@NL@%
- break;%@NL@%
- case LT : Rewrite(atr, PAGE);%@NL@%
- if (!Curslt())%@NL@%
- putch(BELL);%@NL@%
- break;%@NL@%
- case RT : Rewrite(atr, PAGE);%@NL@%
- if (!Cursrt())%@NL@%
- putch(BELL);%@NL@%
- break;%@NL@%
- default : break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ROLO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\ROLO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rolo.c -- demonstrates pointers to structures */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and stdin */%@AE@%%@NL@%
- <string.h> %@AB@%/* for strdup() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXN 79 %@NL@%
- %@AI@%#define %@AE@%MAXCARDS 3 %@NL@%
- %@NL@%
- struct cardstruct { %@AB@%/* global pattern */%@AE@%%@NL@%
- char first[MAXN],%@NL@%
- last[MAXN],%@NL@%
- middle[MAXN];%@NL@%
- unsigned long street_no;%@NL@%
- char street[MAXN],%@NL@%
- city[MAXN],%@NL@%
- state[MAXN];%@NL@%
- unsigned long zip;%@NL@%
- unsigned int area;%@NL@%
- unsigned long phone;%@NL@%
- };%@NL@%
- %@NL@%
- struct cardstruct cards[MAXCARDS];%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < MAXCARDS; ++i)%@NL@%
- {%@NL@%
- printf("\n<card %d of %d>\n", i + 1, MAXCARDS);%@NL@%
- Input(&cards[i]);%@NL@%
- }%@NL@%
- for (i = 0; i < MAXCARDS; ++i)%@NL@%
- {%@NL@%
- printf("\n<%d> ", i + 1);%@NL@%
- Showcard(&cards[i]);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- Input(struct cardstruct *cardp)%@NL@%
- {%@NL@%
- char *Str_Input();%@NL@%
- long Lint_Input();%@NL@%
- %@NL@%
- strcpy(cardp->first,Str_Input("First Name"));%@NL@%
- strcpy(cardp->last,Str_Input("Last Name"));%@NL@%
- strcpy(cardp->middle,Str_Input("Middle Name"));%@NL@%
- cardp->street_no = Lint_Input("Street Number");%@NL@%
- strcpy(cardp->street,Str_Input("Street"));%@NL@%
- strcpy(cardp->city,Str_Input("City"));%@NL@%
- strcpy(cardp->state,Str_Input("State"));%@NL@%
- cardp->zip = Lint_Input("Zip Code");%@NL@%
- cardp->area = (int)Lint_Input("Area Code");%@NL@%
- cardp->phone = Lint_Input("Phone Number");%@NL@%
- }%@NL@%
- %@NL@%
- char *Str_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1], *ptr;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- buf[strlen(buf) - 1] = '\0'; %@AB@%/* strip '\n' */%@AE@%%@NL@%
- if (strlen(buf) == 0)%@NL@%
- exit(0);%@NL@%
- if ((ptr = strdup(buf)) == NULL)%@NL@%
- exit(0);%@NL@%
- return (ptr);%@NL@%
- }%@NL@%
- %@NL@%
- long Lint_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1];%@NL@%
- long num;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- if (sscanf(buf, "%ld", &num) != 1)%@NL@%
- exit(0);%@NL@%
- return (num);%@NL@%
- }%@NL@%
- %@NL@%
- Showcard(struct cardstruct *cardptr) %@NL@%
- {%@NL@%
- printf("\n\n");%@NL@%
- printf("%s %s %s\n", cardptr->first, cardptr->middle, %@NL@%
- cardptr->last);%@NL@%
- printf("%ld %s, %s, %s %ld\n", cardptr->street_no, %@NL@%
- cardptr->street, cardptr->city, cardptr->state,%@NL@%
- cardptr->zip);%@NL@%
- printf("(%d) %ld\n", cardptr->area, cardptr->phone);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ROLO2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\ROLO2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rolo2.c -- demonstrates a linked list */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and stdin */%@AE@%%@NL@%
- <string.h> %@AB@%/* for strdup() */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* for malloc() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXN 79 %@NL@%
- %@NL@%
- struct cardstruct { %@AB@%/* global pattern */%@AE@%%@NL@%
- char first[MAXN],%@NL@%
- last[MAXN],%@NL@%
- middle[MAXN];%@NL@%
- unsigned long street_no;%@NL@%
- char street[MAXN],%@NL@%
- city[MAXN],%@NL@%
- state[MAXN];%@NL@%
- unsigned long zip;%@NL@%
- unsigned int area;%@NL@%
- unsigned long phone;%@NL@%
- struct cardstruct *nextcard;%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- struct cardstruct card, *first, *current;%@NL@%
- %@NL@%
- first = (struct cardstruct *)malloc(sizeof(struct cardstruct));%@NL@%
- if(first == NULL)%@NL@%
- exit(1);%@NL@%
- if (Input(&card) != 0)%@NL@%
- exit(1);%@NL@%
- *first = card;%@NL@%
- current = first;%@NL@%
- %@NL@%
- while (Input(&card) == 0)%@NL@%
- {%@NL@%
- current->nextcard =%@NL@%
- (struct cardstruct *)malloc(sizeof(struct cardstruct));%@NL@%
- if(current->nextcard == NULL)%@NL@%
- exit(1);%@NL@%
- current = current->nextcard;%@NL@%
- *current = card;%@NL@%
- }%@NL@%
- current->nextcard = NULL;%@NL@%
- %@NL@%
- Dumplist(first);%@NL@%
- }%@NL@%
- %@NL@%
- Dumplist(struct cardstruct *head)%@NL@%
- {%@NL@%
- do%@NL@%
- {%@NL@%
- Showcard(head);%@NL@%
- } while ((head = head->nextcard) != NULL);%@NL@%
- }%@NL@%
- %@NL@%
- Showcard(struct cardstruct *cardptr)%@NL@%
- {%@NL@%
- printf("\n\n");%@NL@%
- %@NL@%
- printf("%s %s %s\n", cardptr->first, cardptr->middle, %@NL@%
- cardptr->last);%@NL@%
- printf("%ld %s, %s, %s %ld\n", cardptr->street_no, %@NL@%
- cardptr->street, cardptr->city, cardptr->state,%@NL@%
- cardptr->zip);%@NL@%
- printf("(%d) %ld\n", cardptr->area, cardptr->phone);%@NL@%
- }%@NL@%
- %@NL@%
- Input(struct cardstruct *cardp)%@NL@%
- {%@NL@%
- char *Str_Input();%@NL@%
- long Lint_Input();%@NL@%
- %@NL@%
- printf("\n<new card> (Empty first name Quits)\n");%@NL@%
- strcpy(cardp->first,Str_Input("First Name"));%@NL@%
- if (*(cardp->first) == '\0')%@NL@%
- return (1);%@NL@%
- strcpy(cardp->last,Str_Input("Last Name"));%@NL@%
- strcpy(cardp->middle,Str_Input("Middle Name"));%@NL@%
- cardp->street_no = Lint_Input("Street Number");%@NL@%
- strcpy(cardp->street,Str_Input("Street"));%@NL@%
- strcpy(cardp->city,Str_Input("City"));%@NL@%
- strcpy(cardp->state,Str_Input("State"));%@NL@%
- cardp->zip = Lint_Input("Zip Code");%@NL@%
- cardp->area = (int)Lint_Input("Area Code");%@NL@%
- cardp->phone = Lint_Input("Phone Number");%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- char *Str_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1], *ptr;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- buf[strlen(buf) - 1] = '\0'; %@AB@%/* strip '\n' */%@AE@%%@NL@%
- if ((ptr = strdup(buf)) == NULL)%@NL@%
- exit(0);%@NL@%
- return (ptr);%@NL@%
- }%@NL@%
- %@NL@%
- long Lint_Input(char *prompt)%@NL@%
- {%@NL@%
- char buf[MAXN + 1];%@NL@%
- long num;%@NL@%
- %@NL@%
- printf("%s: ", prompt);%@NL@%
- if (fgets(buf, MAXN, stdin) == NULL)%@NL@%
- exit(0);%@NL@%
- if (sscanf(buf, "%ld", &num) != 1)%@NL@%
- num = 0;%@NL@%
- return (num);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SADD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\SADD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* sadd.c -- a small adding machine that illustrates */%@AE@%%@NL@%
- %@AB@%/* the need for array bounds checking. */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int offset = 0, i, result = 0;%@NL@%
- int stack[3];%@NL@%
- %@NL@%
- while (scanf("%d", &stack[offset]) == 1)%@NL@%
- {%@NL@%
- ++offset;%@NL@%
- }%@NL@%
- for (i = 0; i < offset; ++i)%@NL@%
- {%@NL@%
- result += stack[i];%@NL@%
- }%@NL@%
- printf("-------------\n");%@NL@%
- printf("%d\n", result);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SADD2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\SADD2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* sadd2.c -- a small adding machine that includes */%@AE@%%@NL@%
- %@AB@%/* array bounds checking. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXSTAK 3 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int offset = 0, i, result = 0;%@NL@%
- int stack[MAXSTAK];%@NL@%
- %@NL@%
- while (scanf("%d", &stack[offset]) == 1)%@NL@%
- {%@NL@%
- if (++offset >= MAXSTAK)%@NL@%
- {%@NL@%
- printf("Stack Full\n");%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- for (i = 0; i < offset; ++i)%@NL@%
- {%@NL@%
- result += stack[i];%@NL@%
- }%@NL@%
- printf("-------------\n");%@NL@%
- printf("%d\n", result);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SAVEGRAF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\SAVEGRAF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* savegraf.c -- uses DMA to save screen of graphics */%@AE@%%@NL@%
- %@AB@%/* characters and attributes */%@AE@%%@NL@%
- %@AB@%/* Program list - savegraf.c, initstuf.c, drawchar.c, */%@AE@%%@NL@%
- %@AB@%/* savescrn.c, scrfun.c */%@AE@%%@NL@%
- %@AB@%/* User include files - scrn.h, keys.h, grafchar.h */%@AE@%%@NL@%
- %@AB@%/* Note: activate Screen Swapping On in Debug menu */%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AI@%#include %@AE@%"grafchar.h" %@NL@%
- unsigned char Grchr[NUMCHARS]; %@AB@%/* to store graphics set */%@AE@%%@NL@%
- void Init_stuff(void);%@NL@%
- void Draw_chars(void);%@NL@%
- void Save_screen(void); %@AB@%/* in savescrn.c */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- Init_stuff(); %@AB@%/* initialize vital elements */%@AE@%%@NL@%
- Draw_chars(); %@AB@%/* map keys to graphics characters */%@AE@%%@NL@%
- Setcurs(BOTLINE + 1, 0, PAGE);%@NL@%
- printf("%-80s", "Save screen? <y/n> ");%@NL@%
- Setcurs(BOTLINE + 1, 20, PAGE);%@NL@%
- ch = getche();%@NL@%
- if (ch == 'y' || ch == 'Y')%@NL@%
- Save_screen();%@NL@%
- Setcurs(BOTLINE + 2, 0, PAGE);%@NL@%
- printf("%-80s\n", "BYE!");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SAVESCRN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\SAVESCRN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* savescrn.c -- saves screen, including attribute */%@AE@%%@NL@%
- %@AB@%/* values, in a file */%@AE@%%@NL@%
- %@AB@%/* Uses direct memory access. */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for file-handling */%@AE@%%@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@AI@%#include %@AE@%"grafchar.h" %@NL@%
- void Save_screen()%@NL@%
- {%@NL@%
- FILE *save;%@NL@%
- char filename[80];%@NL@%
- unsigned char mode;%@NL@%
- unsigned short char_attr; %@AB@%/* character,attribute */%@AE@%%@NL@%
- int offset;%@NL@%
- VIDMEM screen;%@NL@%
- %@NL@%
- if ((mode = Getvmode()) == TEXTMONO)%@NL@%
- screen = MONMEM;%@NL@%
- else if (mode == TEXTC80 || mode == TEXTBW80)%@NL@%
- screen = CGAMEM;%@NL@%
- else%@NL@%
- exit(1);%@NL@%
- Setcurs(BOTLINE + 1, 0, PAGE);%@NL@%
- printf("Please enter name for save file: ");%@NL@%
- scanf("%s", filename);%@NL@%
- if ((save = fopen(filename,"wb")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr,"Can't open %s\n", filename);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- for (offset = 0; offset < CHARS; offset++)%@NL@%
- {%@NL@%
- char_attr = screen[offset];%@NL@%
- fwrite(&char_attr, 2, 1, save);%@NL@%
- }%@NL@%
- fclose(save);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCANCODE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\SCANCODE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scancode.c -- displays ASCII or scan code */%@AE@%%@NL@%
- %@AB@%/* This program illustrates using getch() to detect */%@AE@%%@NL@%
- %@AB@%/* special keys such as function keys. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- ESC '\033' %@AB@%/* ESC key */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- printf("Strike keys and see the codes!\n");%@NL@%
- printf("Press the Esc key to quit.\n");%@NL@%
- %@NL@%
- while ((ch = getch()) != ESC)%@NL@%
- {%@NL@%
- if (ch != 0)%@NL@%
- {%@NL@%
- if (ch <= 32) %@AB@%/* control characters */%@AE@%%@NL@%
- printf("^%c has ASCII code %d\n",%@NL@%
- ch + 64, ch);%@NL@%
- else%@NL@%
- printf("%c has ASCII code %d\n", ch, ch);%@NL@%
- }%@NL@%
- else %@AB@%/* ch IS 0 */%@AE@%%@NL@%
- {%@NL@%
- ch = getch(); %@AB@%/* get scan code */%@AE@%%@NL@%
- printf("Scan code is %d\n", ch);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCANLINE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\SCANLINE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scanline.c -- demonstrates how scanf() reads */%@AE@%%@NL@%
- %@AB@%/* the individual words of a line */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%INTRO \ %@NL@%
- "Type in lines of text. They will be printed out\n\%@NL@%
- one word per line, thus demonstrating scanf().\n\%@NL@%
- (Type Ctrl-Z to Quit)\n"%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char buf[512]; %@AB@%/* should be big enough */%@AE@%%@NL@%
- %@NL@%
- printf(INTRO);%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * scanf() returns the number of items%@NL@%
- %@AB@% * its control string matched.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while (scanf("%s", buf) == 1)%@NL@%
- {%@NL@%
- printf("%s\n", buf);%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCAPE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\SCAPE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scape.c -- uses nondefault EGA colors */%@AE@%%@NL@%
- %@AB@%/* If you load graphics.qlb, no program list is needed.*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%"egacolor.h" %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%SKY (b | B | g) %@NL@%
- %@AI@%#define %@AE@%OCEAN b %@NL@%
- %@AI@%#define %@AE@%SAND (R | g | b) %@NL@%
- %@AI@%#define %@AE@%SUN (R | G | r | g) %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _ERESCOLOR;%@NL@%
- short xmax, ymax, sunx, suny, sunsizex, sunsizey;%@NL@%
- float ar;%@NL@%
- %@NL@%
- %@NL@%
- if (argc > 1)%@NL@%
- mode = atoi(argv[1]);%@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr,"mode %d not supported\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- xmax = vc.numxpixels - 1;%@NL@%
- ymax = vc.numypixels - 1;%@NL@%
- sunx = 0.7 * xmax;%@NL@%
- suny = 0.2 * ymax;%@NL@%
- ar = (float)(10 * vc.numypixels) / (6.5 * vc.numxpixels);%@NL@%
- sunsizex = xmax / 30;%@NL@%
- sunsizey = ar * sunsizex;%@NL@%
- _remappalette(1, SKY);%@NL@%
- _remappalette(2, OCEAN);%@NL@%
- _remappalette(3, SAND);%@NL@%
- _remappalette(4, SUN);%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GFILLINTERIOR, 0, 0, xmax, 2 * ymax / 5);%@NL@%
- _setcolor(4);%@NL@%
- _ellipse(_GFILLINTERIOR, sunx - sunsizex, suny -%@NL@%
- sunsizey, sunx + sunsizex, suny + sunsizey);%@NL@%
- _setcolor(2);%@NL@%
- _rectangle(_GFILLINTERIOR, 0, 2 * ymax / 5, xmax,%@NL@%
- 2 * ymax / 3);%@NL@%
- _setcolor(3);%@NL@%
- _rectangle(_GFILLINTERIOR, 0, 2 * ymax / 3, xmax, ymax);%@NL@%
- getch();%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCORE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\SCORE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* score.c -- defines and prints */%@AE@%%@NL@%
- %@AB@%/* int and long vars */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@AB@%/* declare some int variables and assign values */%@AE@%%@NL@%
- %@AB@%/* to them in the same statement */%@AE@%%@NL@%
- %@NL@%
- int home = 5, visitors = 2, inning =7, attendance = 31300;%@NL@%
- long total_attendance = 1135477; %@AB@%/* long int */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* print out the values */%@AE@%%@NL@%
- %@NL@%
- printf("The score after %d innings is \n", inning);%@NL@%
- printf("Home team %d, Visitors %d.\n\n", home, visitors);%@NL@%
- printf("The attendance today is %d.\n", attendance);%@NL@%
- printf("Attendance this year to date is %ld.",%@NL@%
- total_attendance);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRANGE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\SCRANGE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrange.c -- illustrates scanf()'s control */%@AE@%%@NL@%
- %@AB@%/* directives */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char buf[512], %@AB@%/* should be big enough */%@AE@%%@NL@%
- dummy[2]; %@AB@%/* for \n and \0 */%@AE@%%@NL@%
- int num;%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- printf("Running:\n");%@NL@%
- printf("\tscanf(\"%%d\", &num);\n");%@NL@%
- printf("\tscanf(\"%%[^\\n]\", buf);\n");%@NL@%
- printf("\tscanf(\"%%[\\n]\", dummy);\n");%@NL@%
- %@NL@%
- printf("\nType enough to satisfy this:\n");%@NL@%
- printf("(Set num equal to zero to quit)\n");%@NL@%
- %@NL@%
- scanf("%d", &num);%@NL@%
- scanf("%[^\n]", buf);%@NL@%
- scanf("%[\n]", dummy);%@NL@%
- %@NL@%
- printf("\n\tnum = %d\n", num);%@NL@%
- printf("\tbuf[] = \"%s\"\n", buf);%@NL@%
- printf("\n\n");%@NL@%
- %@NL@%
- } while (num != 0) ;%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRFUN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\SCRFUN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrfun.c -- contains several video BIOS calls */%@AE@%%@NL@%
- %@AB@%/* Setcurs() sets the cursor position */%@AE@%%@NL@%
- %@AB@%/* Getcurs() gets the cursor postion */%@AE@%%@NL@%
- %@AB@%/* Setpage() sets the current video page */%@AE@%%@NL@%
- %@AB@%/* Setvmode() sets the video mode */%@AE@%%@NL@%
- %@AB@%/* Clearscr() clears the screen */%@AE@%%@NL@%
- %@AB@%/* Read_ch_atr() reads the character and */%@AE@%%@NL@%
- %@AB@%/* attribute at the cursor */%@AE@%%@NL@%
- %@AB@%/* Write_ch_atr() writes a character and */%@AE@%%@NL@%
- %@AB@%/* attribute at the cursor */%@AE@%%@NL@%
- %@AB@%/* Rewrite() rewrites a screen character */%@AE@%%@NL@%
- %@AB@%/* with a new attribute */%@AE@%%@NL@%
- %@AB@%/* Getvmode() gets the current video mode */%@AE@%%@NL@%
- %@AB@%/* Getpage() gets the current video page */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* The following functions use Setcurs() to move the */%@AE@%%@NL@%
- %@AB@%/* one position at a time up to a limit. */%@AE@%%@NL@%
- %@AB@%/* Curslt_lim() moves cursor one column left */%@AE@%%@NL@%
- %@AB@%/* Cursrt_lim() moves cursor one column right */%@AE@%%@NL@%
- %@AB@%/* Cursup_lim() moves cursor one line up */%@AE@%%@NL@%
- %@AB@%/* Cursdn_lim() moves cursor one line down */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* Programs using these functions should include the */%@AE@%%@NL@%
- %@AB@%/* scrn.h file */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@NL@%
- %@AB@%/* sets cursor to row, column, and page */%@AE@%%@NL@%
- void Setcurs(row, col, page)%@NL@%
- unsigned char row, col, page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETCURSOR;%@NL@%
- reg.h.dh = row;%@NL@%
- reg.h.dl = col;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* gets current cursor row, column for given page */%@AE@%%@NL@%
- void Getcurs(pr, pc, page)%@NL@%
- unsigned char *pr, *pc, page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = GETCURSOR;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- *pr = reg.h.dh; %@AB@%/* row number */%@AE@%%@NL@%
- *pc = reg.h.dl; %@AB@%/* column number */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* sets page to given value */%@AE@%%@NL@%
- void Setpage(page)%@NL@%
- unsigned char page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETPAGE;%@NL@%
- reg.h.al = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* sets video mode to given mode */%@AE@%%@NL@%
- void Setvmode(mode)%@NL@%
- unsigned char mode;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETMODE;%@NL@%
- reg.h.al = mode;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* clear the screen */%@AE@%%@NL@%
- void Clearscr()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SCROLL;%@NL@%
- reg.h.al = 0;%@NL@%
- reg.h.ch = 0;%@NL@%
- reg.h.cl = 0;%@NL@%
- reg.h.dh = ROWS - 1;%@NL@%
- reg.h.dl = COLS - 1;%@NL@%
- reg.h.bh = NORMAL;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* reads the character and attribute at the cursor */%@AE@%%@NL@%
- %@AB@%/* position on a given page */%@AE@%%@NL@%
- void Read_ch_atr(pc, pa, page)%@NL@%
- unsigned char *pc, *pa;%@NL@%
- unsigned char page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = READCHATR;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- *pc = reg.h.al; %@AB@%/* character at cursor */%@AE@%%@NL@%
- *pa = reg.h.ah; %@AB@%/* attribute at cursor */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* writes a given character and attribute at the */%@AE@%%@NL@%
- %@AB@%/* cursor on a given page for num times */%@AE@%%@NL@%
- void Write_ch_atr(ch, atr, page, num)%@NL@%
- unsigned char ch, atr, page;%@NL@%
- unsigned int num;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = WRITECHATR;%@NL@%
- reg.h.al = ch;%@NL@%
- reg.h.bl = atr;%@NL@%
- reg.h.bh = page;%@NL@%
- reg.x.cx = num;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* rewrites the character at the cursor using */%@AE@%%@NL@%
- %@AB@%/* attribute at */%@AE@%%@NL@%
- void Rewrite(at, page)%@NL@%
- unsigned char at, page;%@NL@%
- {%@NL@%
- unsigned char ch, atr;%@NL@%
- %@NL@%
- Read_ch_atr(&ch, &atr, page);%@NL@%
- Write_ch_atr(ch, at, page, 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* obtains the current video mode */%@AE@%%@NL@%
- unsigned char Getvmode()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = GETMODE;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- return reg.h.al;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* obtains the current video page */%@AE@%%@NL@%
- unsigned char Getpage()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = GETMODE;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- return reg.h.bh;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* moves cursor one column left, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Curslt_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (col > limit)%@NL@%
- Setcurs(row, col - 1, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* moves cursor one column right, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Cursrt_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (col < limit)%@NL@%
- Setcurs(row, col + 1, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* move cursor one row down, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Cursup_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (row > limit)%@NL@%
- Setcurs(row - 1, col, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* move cursor one row down, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Cursdn_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (row < limit)%@NL@%
- Setcurs(row + 1, col, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRFUN.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\SCRFUN.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrfun.c -- contains several video BIOS calls */%@AE@%%@NL@%
- %@AB@%/* Setcurs() sets the cursor position */%@AE@%%@NL@%
- %@AB@%/* Getcurs() gets the cursor postion */%@AE@%%@NL@%
- %@AB@%/* Setpage() sets the current video page */%@AE@%%@NL@%
- %@AB@%/* Setvmode() sets the video mode */%@AE@%%@NL@%
- %@AB@%/* Clearscr() clears the screen */%@AE@%%@NL@%
- %@AB@%/* Read_ch_atr() reads the character and */%@AE@%%@NL@%
- %@AB@%/* attribute at the cursor */%@AE@%%@NL@%
- %@AB@%/* Write_ch_atr() writes a character and */%@AE@%%@NL@%
- %@AB@%/* attribute at the cursor */%@AE@%%@NL@%
- %@AB@%/* Rewrite() rewrites a screen character */%@AE@%%@NL@%
- %@AB@%/* with a new attribute */%@AE@%%@NL@%
- %@AB@%/* Getvmode() gets the current video mode */%@AE@%%@NL@%
- %@AB@%/* Getpage() gets the current video page */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* The following functions use Setcurs() to move the */%@AE@%%@NL@%
- %@AB@%/* one position at a time up to a limit. */%@AE@%%@NL@%
- %@AB@%/* Curslt_lim() moves cursor one column left */%@AE@%%@NL@%
- %@AB@%/* Cursrt_lim() moves cursor one column right */%@AE@%%@NL@%
- %@AB@%/* Cursup_lim() moves cursor one line up */%@AE@%%@NL@%
- %@AB@%/* Cursdn_lim() moves cursor one line down */%@AE@%%@NL@%
- %@AB@%/* */%@AE@%%@NL@%
- %@AB@%/* Programs using these functions should include the */%@AE@%%@NL@%
- %@AB@%/* scrn.h file */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%"scrn.h" %@NL@%
- %@NL@%
- %@AB@%/* sets cursor to row, column, and page */%@AE@%%@NL@%
- void Setcurs(row, col, page)%@NL@%
- unsigned char row, col, page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETCURSOR;%@NL@%
- reg.h.dh = row;%@NL@%
- reg.h.dl = col;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* gets current cursor row, column for given page */%@AE@%%@NL@%
- void Getcurs(pr, pc, page)%@NL@%
- unsigned char *pr, *pc, page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = GETCURSOR;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- *pr = reg.h.dh; %@AB@%/* row number */%@AE@%%@NL@%
- *pc = reg.h.dl; %@AB@%/* column number */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* sets page to given value */%@AE@%%@NL@%
- void Setpage(page)%@NL@%
- unsigned char page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETPAGE;%@NL@%
- reg.h.al = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* sets video mode to given mode */%@AE@%%@NL@%
- void Setvmode(mode)%@NL@%
- unsigned char mode;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETMODE;%@NL@%
- reg.h.al = mode;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* clear the screen */%@AE@%%@NL@%
- void Clearscr()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SCROLL;%@NL@%
- reg.h.al = 0;%@NL@%
- reg.h.ch = 0;%@NL@%
- reg.h.cl = 0;%@NL@%
- reg.h.dh = ROWS - 1;%@NL@%
- reg.h.dl = COLS - 1;%@NL@%
- reg.h.bh = NORMAL;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* reads the character and attribute at the cursor */%@AE@%%@NL@%
- %@AB@%/* position on a given page */%@AE@%%@NL@%
- void Read_ch_atr(pc, pa, page)%@NL@%
- unsigned char *pc, *pa;%@NL@%
- unsigned char page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = READCHATR;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- *pc = reg.h.al; %@AB@%/* character at cursor */%@AE@%%@NL@%
- *pa = reg.h.ah; %@AB@%/* attribute at cursor */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* writes a given character and attribute at the */%@AE@%%@NL@%
- %@AB@%/* cursor on a given page for num times */%@AE@%%@NL@%
- void Write_ch_atr(ch, atr, page, num)%@NL@%
- unsigned char ch, atr, page;%@NL@%
- unsigned int num;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = WRITECHATR;%@NL@%
- reg.h.al = ch;%@NL@%
- reg.h.bl = atr;%@NL@%
- reg.h.bh = page;%@NL@%
- reg.x.cx = num;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* rewrites the character at the cursor using */%@AE@%%@NL@%
- %@AB@%/* attribute at */%@AE@%%@NL@%
- void Rewrite(at, page)%@NL@%
- unsigned char at, page;%@NL@%
- {%@NL@%
- unsigned char ch, atr;%@NL@%
- %@NL@%
- Read_ch_atr(&ch, &atr, page);%@NL@%
- Write_ch_atr(ch, at, page, 1);%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* obtains the current video mode */%@AE@%%@NL@%
- unsigned char Getvmode()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = GETMODE;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- return reg.h.al;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* obtains the current video page */%@AE@%%@NL@%
- unsigned char Getpage()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = GETMODE;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- return reg.h.bh;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* moves cursor one column left, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Curslt_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (col > limit)%@NL@%
- Setcurs(row, col - 1, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* moves cursor one column right, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Cursrt_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (col < limit)%@NL@%
- Setcurs(row, col + 1, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* move cursor one row down, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Cursup_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (row > limit)%@NL@%
- Setcurs(row - 1, col, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* move cursor one row down, but not past */%@AE@%%@NL@%
- %@AB@%/* the given limit */%@AE@%%@NL@%
- unsigned char Cursdn_lim(limit)%@NL@%
- unsigned char limit;%@NL@%
- {%@NL@%
- unsigned char row, col, page;%@NL@%
- unsigned char status = 1;%@NL@%
- %@NL@%
- Getcurs(&row, &col, page = Getpage());%@NL@%
- if (row < limit)%@NL@%
- Setcurs(row + 1, col, page);%@NL@%
- else%@NL@%
- status = 0;%@NL@%
- return status;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRINV.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\SCRINV.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrinv.c -- using a far pointer to access text */%@AE@%%@NL@%
- %@AB@%/* screen memory */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%ROWS 25 %@NL@%
- %@AI@%#define %@AE@%COLS 80 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int far *screenp;%@NL@%
- int temp, i;%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- %@AB@%/* use 0xB800000 for EGA or VGA */%@AE@%%@NL@%
- screenp = (int far *)0xB0000000;%@NL@%
- %@NL@%
- for (i = 0; i < ((ROWS*COLS)/2); ++i)%@NL@%
- {%@NL@%
- temp = screenp[i];%@NL@%
- screenp[i] = screenp[(ROWS*COLS)-i-1];%@NL@%
- screenp[(ROWS*COLS)-i-1] = temp;%@NL@%
- }%@NL@%
- } while (getch() != 'Q');%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRMENU.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\SCRMENU.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrmenu.c -- uses bit fields to modify your text */%@AE@%%@NL@%
- %@AB@%/* screen's attributes */%@AE@%%@NL@%
- %@NL@%
- char *Choice_Words[] = {%@NL@%
- "Quit",%@NL@%
- "Foreground",%@NL@%
- "Intensity",%@NL@%
- "Background",%@NL@%
- "Blinking"%@NL@%
- };%@NL@%
- enum Choices { %@NL@%
- Quit, %@NL@%
- Foreground, %@NL@%
- Intensity, %@NL@%
- Background, %@NL@%
- Blinking %@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/* use 0xB800000 for EGA or VGA */%@AE@%%@NL@%
- %@AI@%#define %@AE@%SCR_START (0xB0000000) %@NL@%
- %@AI@%#define %@AE@%SCR_SIZE (25 * 80) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- enum Choices choice;%@NL@%
- %@NL@%
- printf("Select from the following by number:\n");%@NL@%
- %@NL@%
- for (choice = Quit; choice <= Blinking; ++choice)%@NL@%
- {%@NL@%
- printf("%d. %s\n", choice, Choice_Words[choice]);%@NL@%
- }%@NL@%
- %@NL@%
- printf("\nWhich: ");%@NL@%
- do %@NL@%
- {%@NL@%
- choice = getch();%@NL@%
- choice -= '0';%@NL@%
- if (choice < Foreground || choice > Blinking)%@NL@%
- continue;%@NL@%
- Redraw(choice);%@NL@%
- } while (choice != Quit);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- Redraw(enum Choices field)%@NL@%
- {%@NL@%
- struct screen_char {%@NL@%
- unsigned int character :8,%@NL@%
- foreground :3,%@NL@%
- intensity :1,%@NL@%
- background :3,%@NL@%
- blink :1;%@NL@%
- } scrchar, far *sp, far *ep;%@NL@%
- %@NL@%
- sp = (struct screen_char far *)SCR_START;%@NL@%
- ep = sp + SCR_SIZE;%@NL@%
- %@NL@%
- while (sp < ep)%@NL@%
- {%@NL@%
- scrchar = *sp;%@NL@%
- switch (field)%@NL@%
- {%@NL@%
- case Foreground:%@NL@%
- scrchar.foreground = (scrchar.foreground)? 0 : 7;%@NL@%
- break;%@NL@%
- case Intensity:%@NL@%
- scrchar.intensity = (scrchar.intensity)? 0 : 1;%@NL@%
- break;%@NL@%
- case Background:%@NL@%
- scrchar.background = (scrchar.background)? 0 : 7;%@NL@%
- break;%@NL@%
- case Blinking:%@NL@%
- scrchar.blink = (scrchar.blink)? 0 : 1;%@NL@%
- break;%@NL@%
- }%@NL@%
- *(sp++) = scrchar;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRREST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\SCRREST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrrest.c -- demonstrates read() by restoring */%@AE@%%@NL@%
- %@AB@%/* text screen from any file. */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for stderr */%@AE@%%@NL@%
- <fcntl.h> %@AB@%/* for O_RDONLY | O_BINARY */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%SCRCHARS (25 * 80) %@NL@%
- int Buf[SCRCHARS];%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int *cp, *ep;%@NL@%
- int far *sp;%@NL@%
- int fd_in, bytes;%@NL@%
- %@NL@%
- if (argc != 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "usage: scrrest file.scr\n");%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- if ((fd_in = open(argv[1], O_RDONLY | O_BINARY)) < 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't open to read.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@AB@%/* Read it. */%@AE@%%@NL@%
- bytes = read(fd_in, Buf, SCRCHARS * 2);%@NL@%
- if (bytes < 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Reading.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if (bytes == 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Empty File.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@AB@%/* Copy the buffer to screen memory. */%@AE@%%@NL@%
- ep = &Buf[bytes / 2];%@NL@%
- cp = Buf;%@NL@%
- %@NL@%
- %@AB@%/* use 0xB800000 for EGA or VGA */%@AE@%%@NL@%
- sp = (int far *)(0xB0000000);%@NL@%
- for (; cp < ep; ++cp, ++sp)%@NL@%
- *sp = *cp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SCRSAVE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\SCRSAVE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* scrsave.c -- demonstrates write() by saving the */%@AE@%%@NL@%
- %@AB@%/* text screen to a file. */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for stderr */%@AE@%%@NL@%
- <fcntl.h> %@AB@%/* for O_CREAT | O_BINARY */%@AE@%%@NL@%
- <sys\types.h> %@AB@%/* for stat.h */%@AE@%%@NL@%
- <sys\stat.h> %@AB@%/* for S_IREAD | S_IWRITE */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%SCRCHARS (25 * 80) %@NL@%
- int Buf[SCRCHARS];%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int *cp, *ep, fname[16];%@NL@%
- int far *sp;%@NL@%
- int fd_out, bytes;%@NL@%
- %@NL@%
- if (argc != 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "usage: scrsave file\n");%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- if (strlen(argv[1]) > 8)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": File name too long.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- strcpy(fname, argv[1]);%@NL@%
- strcat(fname, ".SCR");%@NL@%
- if (access(fname, 0) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Won't overwrite.\n", fname);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if ((fd_out = open(fname, O_WRONLY|O_CREAT|O_BINARY,%@NL@%
- S_IREAD|S_IWRITE)) < 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't create.\n", fname);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@AB@%/* Copy the screen into a near buffer. */%@AE@%%@NL@%
- ep = &Buf[SCRCHARS - 1];%@NL@%
- cp = Buf;%@NL@%
- %@AB@%/* use 0xB800000 for EGA or VGA */%@AE@%%@NL@%
- sp = (int far *)(0xB0000000);%@NL@%
- for (; cp < ep; ++cp, ++sp)%@NL@%
- *cp = *sp;%@NL@%
- %@AB@%/* Write it. */%@AE@%%@NL@%
- bytes = write(fd_out, Buf, SCRCHARS * 2);%@NL@%
- if (bytes != SCRCHARS * 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error writing.\n", fname);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SETCURS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\SETCURS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* setcurs.c -- moves cursor, checks out Setcurs() */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%VIDEO 0x10 %@NL@%
- %@AI@%#define %@AE@%SETCURSOR 2 %@NL@%
- void Setcurs(unsigned char, unsigned char,%@NL@%
- unsigned char);%@NL@%
- main()%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- %@NL@%
- printf("Enter row and column: (q to quit)\n");%@NL@%
- while (scanf("%d %d", &row, &col) == 2)%@NL@%
- {%@NL@%
- Setcurs(row, col, 0);%@NL@%
- printf("Enter row and column: (q to quit)");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Setcurs() -- sets cursor to row, column, and page */%@AE@%%@NL@%
- void Setcurs(row, col, page)%@NL@%
- unsigned char row, col, page;%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- %@NL@%
- reg.h.ah = SETCURSOR;%@NL@%
- reg.h.dh = row;%@NL@%
- reg.h.dl = col;%@NL@%
- reg.h.bh = page;%@NL@%
- int86(VIDEO, ®, ®);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHIFTADD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\SHIFTADD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* shiftadd.c -- shift and add numbers */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int x = 0x12;%@NL@%
- int y;%@NL@%
- %@NL@%
- y = x << 8 + 2;%@NL@%
- printf("y is 0x%x\n", y);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHORTIF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\SHORTIF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* shortif.c -- shows 'shorthand' IF / ELSE */%@AE@%%@NL@%
- %@AB@%/* -- gets absolute value of number */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num, pos, abs;%@NL@%
- printf("Enter a whole number: ");%@NL@%
- scanf("%d", &num);%@NL@%
- %@NL@%
- pos = (num >= 0); %@AB@%/* is number positive? */%@AE@%%@NL@%
- %@NL@%
- abs = (pos) ? num : -num; %@AB@%/* assigns negative of */%@AE@%%@NL@%
- %@AB@%/* number if number is negative */%@AE@%%@NL@%
- if (pos)%@NL@%
- printf ("The number is positive.\n");%@NL@%
- else%@NL@%
- printf("The number is negative.\n");%@NL@%
- printf("Absolute value of number is: %d\n", abs);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOW2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\SHOW2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* show2.c -- shows how to use main()'s envp */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv, envp)%@NL@%
- int argc;%@NL@%
- char *argv[], *envp[];%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- printf("argc = %d\n", argc);%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- for (i = 0; i < argc; ++i)%@NL@%
- {%@NL@%
- printf("argv[%d] -> \"%s\"\n", i, argv[i]);%@NL@%
- }%@NL@%
- printf("argv[%d] -> NULL\n", i);%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- for (i= 0; envp[i] != NULL; ++i)%@NL@%
- {%@NL@%
- printf("envp[%d] -> \"%s\"\n", i, envp[i]);%@NL@%
- }%@NL@%
- printf("envp[%d] -> NULL\n", i);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWARGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\SHOWARGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* showargs.c -- shows how to access the arguments */%@AE@%%@NL@%
- %@AB@%/* passed to main() */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- printf("argc = %d\n", argc);%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- for (i = 0; i < argc; ++i)%@NL@%
- {%@NL@%
- printf("argv[%d] -> \"%s\"\n", i, argv[i]);%@NL@%
- }%@NL@%
- printf("argv[%d] -> NULL\n", i);%@NL@%
- printf("\n");%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SHOWCODE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\SHOWCODE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* showcode.c -- shows ASCII and scan codes for */%@AE@%%@NL@%
- %@AB@%/* keystrokes */%@AE@%%@NL@%
- %@AB@%/* Note: Set Screen Swapping On in the Debug menu. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- KEYINTR 0x16 %@AB@%/* keyboard read interrupt */%@AE@%%@NL@%
- GETCHAR 0 %@AB@%/* read scancode function */%@AE@%%@NL@%
- ESC '\033' %@AB@%/* escape key */%@AE@%%@NL@%
- struct SCANCODE {%@NL@%
- unsigned char ascii; %@AB@%/* ascii code */%@AE@%%@NL@%
- unsigned char scan; %@AB@%/* scan code */%@AE@%%@NL@%
- };%@NL@%
- struct SCANCODE Readkey();%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- struct SCANCODE keys;%@NL@%
- %@NL@%
- printf("Press keys to see their scancodes. ");%@NL@%
- printf("Press the Esc key to quit.\n");%@NL@%
- do {%@NL@%
- keys = Readkey();%@NL@%
- if (keys.ascii > 0 && keys.ascii < 040)%@NL@%
- printf("^%c: ascii = %3d, scan = %3d\n",%@NL@%
- keys.ascii + 0100, keys.ascii,%@NL@%
- keys.scan);%@NL@%
- else if (keys.ascii >= 40)%@NL@%
- printf(" %c: ascii = %3d, scan = %3d\n",%@NL@%
- keys.ascii, keys.ascii, keys.scan);%@NL@%
- else%@NL@%
- printf(" : ascii = %3d, scan = %3d\n",%@NL@%
- keys.ascii, keys.scan);%@NL@%
- } while (keys.ascii != ESC);%@NL@%
- }%@NL@%
- %@NL@%
- struct SCANCODE Readkey()%@NL@%
- {%@NL@%
- union REGS reg;%@NL@%
- struct SCANCODE scancode;%@NL@%
- %@NL@%
- reg.h.ah = GETCHAR;%@NL@%
- int86(KEYINTR, ®, ®);%@NL@%
- scancode.ascii = reg.h.al;%@NL@%
- scancode.scan = reg.h.ah;%@NL@%
- return (scancode);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SPECS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\SPECS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* specs.c -- shows printf() format */%@AE@%%@NL@%
- %@AB@%/* specifiers for numbers */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i = 122; %@AB@%/* ASCII code for 'z' */%@AE@%%@NL@%
- long l = 93000000; %@AB@%/* distance to Sun (miles) */%@AE@%%@NL@%
- float f = 192450.88; %@AB@%/* someone's bottom line */%@AE@%%@NL@%
- double d = 2.0e+030; %@AB@%/* mass of Sun (kg.) */%@AE@%%@NL@%
- %@NL@%
- printf("%d\n", i); %@AB@%/* integer as decimal */%@AE@%%@NL@%
- printf("%x\n", i); %@AB@%/* integer as hex */%@AE@%%@NL@%
- printf("%ld\n", l); %@AB@%/* long */%@AE@%%@NL@%
- printf("%f\n", f); %@AB@%/* float as decimal */%@AE@%%@NL@%
- printf("%e\n", f); %@AB@%/* float as exponential */%@AE@%%@NL@%
- printf("%f\n", d); %@AB@%/* double as decimal */%@AE@%%@NL@%
- printf("%d\n", d); %@AB@%/* double as exponential */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SQUARE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\SQUARE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* square.c -- a quiz to demonstrate passing */%@AE@%%@NL@%
- %@AB@%/* pointers and addresses in functions */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val, count, guess;%@NL@%
- %@NL@%
- for (count = 1; count < 255; ++count)%@NL@%
- {%@NL@%
- val = count;%@NL@%
- printf("\nWhat is the square of %d?\n", val);%@NL@%
- if (scanf("%d", &guess) != 1)%@NL@%
- return(0); %@AB@%/* non-number exits */%@AE@%%@NL@%
- %@NL@%
- if(Square(&val) != 0) %@AB@%/* pass val's address */%@AE@%%@NL@%
- {%@NL@%
- printf("Range Error\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if (val != guess)%@NL@%
- printf("Wrong. It is %d.\n", val);%@NL@%
- else%@NL@%
- printf("Right!\n");%@NL@%
- printf("Continue? ");%@NL@%
- if (getche() != 'y')%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- int Square(int *where)%@NL@%
- {%@NL@%
- if (*where > 181 || *where < -181)%@NL@%
- return (-1);%@NL@%
- *where = (*where) * (*where);%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SQUARE2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\SQUARE2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* LISTING 8-2 */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* square.c -- A quiz to demonstrate passing */%@AE@%%@NL@%
- %@AB@%/* pointers and addresses in functions. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val, count, guess;%@NL@%
- %@NL@%
- for (count = 1; count < 255; ++count)%@NL@%
- {%@NL@%
- val = count;%@NL@%
- printf("\nWhat is the square of %d?\n", val);%@NL@%
- if (scanf(" %d", &guess) != 1)%@NL@%
- return(0); %@AB@%/* non-number exits */%@AE@%%@NL@%
- %@NL@%
- if(Square(&val) != 0) %@AB@%/* pass val's address */%@AE@%%@NL@%
- {%@NL@%
- printf("Range Error\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- if (val != guess)%@NL@%
- printf("Wrong. It is %d.\n", val);%@NL@%
- else%@NL@%
- printf("Right!\n");%@NL@%
- %@NL@%
- %@NL@%
- printf("Continue? ");%@NL@%
- if (getche() != 'y')%@NL@%
- break;%@NL@%
- }%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- int Square(int *where)%@NL@%
- {%@NL@%
- if (*where > 181 || *where < -181)%@NL@%
- return (-1);%@NL@%
- *where = (*where) * (*where);%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STATIC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\STATIC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* static.c -- demonstrates a static variable */%@AE@%%@NL@%
- %@AB@%/* that holds count of lines, */%@AE@%%@NL@%
- %@AB@%/* words, and characters */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- void countline();%@NL@%
- printf("Type some lines of text.\n");%@NL@%
- printf("Start a line with a . to quit.\n\n");%@NL@%
- %@NL@%
- while (getche() != '.')%@NL@%
- countline(); %@AB@%/* accumulate word and */%@AE@%%@NL@%
- %@AB@%/* line counts */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- void countline()%@NL@%
- {%@NL@%
- static int words = 0; %@AB@%/* static variables */%@AE@%%@NL@%
- static int chars = 0;%@NL@%
- char ch;%@NL@%
- ++chars; %@AB@%/* count char typed when */%@AE@%%@NL@%
- %@AB@%/* function was called */%@AE@%%@NL@%
- %@NL@%
- while ((ch = getche()) != '\r')%@NL@%
- {%@NL@%
- ++chars;%@NL@%
- if (ch == ' ')%@NL@%
- ++words;%@NL@%
- }%@NL@%
- ++words; %@AB@%/* count last word */%@AE@%%@NL@%
- %@NL@%
- printf("\nWords so far %d. Chars. so far %d\n", words, chars);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRINGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\STRINGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* strings.c -- shows two ways to print */%@AE@%%@NL@%
- %@AB@%/* a string with printf() */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf("This uses a string literal by itself\n");%@NL@%
- printf("%s", "This plugs the literal into %s\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRINGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\STRINGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* strings.c -- opens a file and searches it for */%@AE@%%@NL@%
- %@AB@%/* possible strings */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for FILE, BUFSIZ & EOF */%@AE@%%@NL@%
- <ctype.h> %@AB@%/* for isprint() */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- FILE *fp;%@NL@%
- char buf[BUFSIZ];%@NL@%
- int ch, count;%@NL@%
- %@NL@%
- if (argc != 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "usage: strings file\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if ((fp = fopen(argv[1], "rb")) == NULL)%@NL@%
- {%@NL@%
- fprintf(stderr, "Can't open %s\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- count = 0;%@NL@%
- while ((ch = fgetc(fp)) != EOF)%@NL@%
- {%@NL@%
- if (! isprint(ch) || count >= (BUFSIZ - 1))%@NL@%
- {%@NL@%
- if (count > 5)%@NL@%
- {%@NL@%
- buf[count] = 0;%@NL@%
- puts(buf);%@NL@%
- }%@NL@%
- count = 0;%@NL@%
- continue;%@NL@%
- }%@NL@%
- buf[count++] = ch;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRIO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP13\STRIO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* strio.c -- uses cgets() and cputs() */%@AE@%%@NL@%
- %@AB@%/* program list -- strio.c (cgets() not in core library) */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%MAXSIZE 6 %@NL@%
- main()%@NL@%
- {%@NL@%
- char store[MAXSIZE + 2];%@NL@%
- %@NL@%
- store[0] = MAXSIZE; %@AB@%/* put limit in first element */%@AE@%%@NL@%
- cputs("What's your name?\n\r");%@NL@%
- cgets(store);%@NL@%
- cputs("\n\rI'll remember you, ");%@NL@%
- cputs(store + 2);%@NL@%
- cputs("!\n\r");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%STRPOOL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\STRPOOL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* strpool.c -- dumps the string pool to show how */%@AE@%%@NL@%
- %@AB@%/* quoted strings are stored */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%PHRASE \ %@NL@%
- "This is one long sentence that the compiler \%@NL@%
- combines into a single string."%@NL@%
- %@NL@%
- char Start[] = "start";%@NL@%
- char Long_phrase[] = PHRASE;%@NL@%
- char Short_phrase[] = "This is a short phrase";%@NL@%
- char Cent_string[] = "\x9b";%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static char local_phrase[] = "This is local";%@NL@%
- char *cp;%@NL@%
- %@NL@%
- printf("Dump of the string pool:\n");%@NL@%
- printf("-----------------------\n");%@NL@%
- %@NL@%
- printf("\""); %@AB@%/* print leading quote */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/*%@NL@%
- %@AB@% * Note that the address of a string can be%@NL@%
- %@AB@% * assigned to a pointer: cp = Start%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for (cp = Start; *cp != '^'; ++cp)%@NL@%
- {%@NL@%
- if (*cp == '\0') %@AB@%/* print '\0' as a quote */%@AE@%%@NL@%
- printf("\"\n\"");%@NL@%
- else if (*cp == '\n' ) %@AB@%/* print '\n' as '\' 'n' */%@AE@%%@NL@%
- printf("\\n");%@NL@%
- else%@NL@%
- printf("%c", *cp);%@NL@%
- }%@NL@%
- printf("^"); %@AB@%/* marks end */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SUMNUMS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\SUMNUMS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* sumnums.c -- type mismatch in function arguments */%@AE@%%@NL@%
- %@AB@%/* No function prototyping */%@AE@%%@NL@%
- %@NL@%
- int sums();%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- float a = 10.0;%@NL@%
- float b = 20.0;%@NL@%
- int c;%@NL@%
- %@NL@%
- c = sums(a, b);%@NL@%
- printf("sum of %.1f and %.1f is %d\n", a, b, c); ;%@NL@%
- }%@NL@%
- %@NL@%
- int sums(x, y)%@NL@%
- int x, y;%@NL@%
- {%@NL@%
- return (x + y);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SUMNUMS2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\SUMNUMS2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* sumnums2.c -- type mismatch in function arguments */%@AE@%%@NL@%
- %@AB@%/* Function prototyping */%@AE@%%@NL@%
- %@NL@%
- int sums(int, int);%@NL@%
- main()%@NL@%
- {%@NL@%
- float a = 10.0;%@NL@%
- float b = 20.0;%@NL@%
- int c;%@NL@%
- %@NL@%
- c = sums(a, b);%@NL@%
- printf("sum of %.1f and %.1f is %d\n", a, b, c);%@NL@%
- }%@NL@%
- int sums(x, y)%@NL@%
- int x, y;%@NL@%
- {%@NL@%
- return ( x + y);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%SWITCH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP05\SWITCH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* switch.c -- demonstrates switch statement */%@AE@%%@NL@%
- %@AB@%/* prints values according */%@AE@%%@NL@%
- %@AB@%/* to user's choice */%@AE@%%@NL@%
- %@NL@%
- <math.h> %@AB@%/* for sqrt() */%@AE@%%@NL@%
- %@AI@%#define %@AE@%TRUE 1 %@NL@%
- main()%@NL@%
- {%@NL@%
- char choice; %@AB@%/* routine wanted by user */%@AE@%%@NL@%
- int number; %@AB@%/* number entered by user */%@AE@%%@NL@%
- %@NL@%
- while (TRUE) %@AB@%/* endless loop */%@AE@%%@NL@%
- {%@NL@%
- printf("\nSelect value wanted:\n");%@NL@%
- printf("o = octal h = hex s = square\n");%@NL@%
- printf("r = square root q = quit: ");%@NL@%
- choice = getche(); printf("\n");%@NL@%
- %@NL@%
- if (choice == 'q')%@NL@%
- break; %@AB@%/* exits WHILE loop; ends program */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* rest of program executed if base <> 'q' */%@AE@%%@NL@%
- printf("Enter a whole number: ");%@NL@%
- scanf("%d", &number);%@NL@%
- %@NL@%
- switch (choice) %@AB@%/* print according to */%@AE@%%@NL@%
- %@AB@%/* choice requested */%@AE@%%@NL@%
- {%@NL@%
- case 'o': %@AB@%/* print octal */%@AE@%%@NL@%
- printf("Result: %o\n", number);%@NL@%
- break; %@AB@%/* break here in each case */%@AE@%%@NL@%
- %@AB@%/* exits the switch statement */%@AE@%%@NL@%
- %@NL@%
- case 'h': %@AB@%/* print hex */%@AE@%%@NL@%
- printf("Result: %x\n", number);%@NL@%
- break;%@NL@%
- %@NL@%
- case 's': %@AB@%/* square */%@AE@%%@NL@%
- printf("Result: %d\n", number * number);%@NL@%
- break;%@NL@%
- %@NL@%
- case 'r': %@AB@%/* square root */%@AE@%%@NL@%
- printf("Result: %f\n", sqrt(number) );%@NL@%
- break;%@NL@%
- %@NL@%
- default:%@NL@%
- printf("Choice must be o, h, s, r, or q\n");%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TABLE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\TABLE.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* TABLE.C -- prints square root, square, and cube */%@AE@%%@NL@%
- %@AB@%/* for the numbers 1 thru 9 */%@AE@%%@NL@%
- %@NL@%
- <math.h> %@AB@%/* include math functions so we */%@AE@%%@NL@%
- %@AB@%/* can do square root */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- printf("i\t sqrt(i)\tsquare(i)\tcube(i)\n\n");%@NL@%
- for (i = 1; i < 10; i++)%@NL@%
- %@AB@%/* beginning of body of loop */%@AE@%%@NL@%
- {%@NL@%
- printf("%d\t", i);%@NL@%
- printf("%f\t", sqrt(i));%@NL@%
- printf("%d\t\t", i * i);%@NL@%
- printf("%d\n", i * i * i);%@NL@%
- }%@NL@%
- %@AB@%/* end of body of loop */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TABS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\TABS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* tabs.c -- shows formatting with the \t */%@AE@%%@NL@%
- %@AB@%/* tab escape sequence */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int q1 = 338, q2 = 57, q3 = 1048, q4 = 778,%@NL@%
- %@AB@%/* quantity in bin */%@AE@%%@NL@%
- t1 = 6, t2 = 8, t3 = 12, t4 = 16;%@NL@%
- %@AB@%/* threads per inch */%@AE@%%@NL@%
- %@NL@%
- float s1 = 0.250, s2 = 0.500, s3 = 0.750, s4 = 1.0;%@NL@%
- %@AB@%/* size in inches */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* print table header */%@AE@%%@NL@%
- printf("number\t\t size\t\t threads\n");%@NL@%
- printf("in bin\t\t (inches)\t per inch\n\n");%@NL@%
- %@NL@%
- %@AB@%/* print lines of table */%@AE@%%@NL@%
- printf("%d\t\t %f\t %d\n", q1, s1, t1);%@NL@%
- printf("%d\t\t %f\t %d\n", q2, s2, t2);%@NL@%
- printf("%d\t\t %f\t %d\n", q3, s3, t3);%@NL@%
- printf("%d\t\t %f\t %d\n", q4, s4, t4);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TEST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\TEST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* test.c -- test the routines in basic.lib */%@AE@%%@NL@%
- %@AB@%/* Program list: test.c and basic.lib */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static char string[] = "This is a test.";%@NL@%
- char *cp, *Leftstr(), *Midstr(), *Rightstr();%@NL@%
- %@NL@%
- printf("Testing: \"%s\"\n", string);%@NL@%
- %@NL@%
- if ((cp = Leftstr(string, 4)) == NULL)%@NL@%
- {%@NL@%
- printf("Error in Leftstr()\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- printf("Leftstr() returned: \"%s\"\n", cp);%@NL@%
- %@NL@%
- if ((cp = Midstr(string, 4, 5)) == NULL)%@NL@%
- {%@NL@%
- printf("Error in Midstr()\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- printf("Midstr() returned: \"%s\"\n", cp);%@NL@%
- %@NL@%
- if ((cp = Rightstr(string, 5)) == NULL)%@NL@%
- {%@NL@%
- printf("Error in Rightstr()\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- printf("Rightstr() returned: \"%s\"\n", cp);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TESTER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP16\TESTER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* tester.c -- demonstrates the assert() macro */%@AE@%%@NL@%
- %@AB@%/* Program list: tester.c (to link math functions) */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<assert.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- float s1 = 3.0;%@NL@%
- float s2 = 4.0;%@NL@%
- float sumsq;%@NL@%
- float hypot;%@NL@%
- %@NL@%
- sumsq = s1*s1 - s2*s2;%@NL@%
- assert(sumsq >= 0);%@NL@%
- hypot = sqrt(sumsq);%@NL@%
- printf("hypotenuse is %.2f\n", hypot);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TEXED.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP12\TEXED.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* texed.c -- main entry point to the editor; the */%@AE@%%@NL@%
- %@AB@%/* menu and signal handlers are here */%@AE@%%@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- char ch;%@NL@%
- %@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("\nTexEd Main Menu\n");%@NL@%
- printf("Select from:\n");%@NL@%
- printf("0) Quit\n\n");%@NL@%
- printf("1) Load File\n");%@NL@%
- printf("2) Save File\n");%@NL@%
- printf("3) Edit File\n");%@NL@%
- printf("Which: ");%@NL@%
- do%@NL@%
- {%@NL@%
- ch = getch();%@NL@%
- ch -= '0';%@NL@%
- } while (ch < 0 || ch > 3);%@NL@%
- printf("%d\n\n", (int)ch);%@NL@%
- switch(ch)%@NL@%
- {%@NL@%
- case 0: exit(0);%@NL@%
- case 1: Load_file(); break;%@NL@%
- case 2: Save_file(); break;%@NL@%
- case 3: Edit_file(); break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TIMER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\TIMER.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* TIMER.C -- uses do loop to */%@AE@%%@NL@%
- %@AB@%/* check elapsed time */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- long start, end, %@AB@%/* starting and ending times */%@AE@%%@NL@%
- %@AB@%/* measured in seconds since */%@AE@%%@NL@%
- %@AB@%/* Jan. 1, 1970 */%@AE@%%@NL@%
- ltime; %@AB@%/* used to get val from time function */%@AE@%%@NL@%
- int seconds; %@AB@%/* elapsed time to be set */%@AE@%%@NL@%
- %@NL@%
- printf("QuickC Egg Timer\n");%@NL@%
- printf("Enter time to set in seconds: ");%@NL@%
- scanf("%d", &seconds);%@NL@%
- start = time(<ime); %@AB@%/* get system elapsed seconds */%@AE@%%@NL@%
- %@AB@%/* since 1-1-70 */%@AE@%%@NL@%
- end = start + seconds; %@AB@%/* calculate alarm time */%@AE@%%@NL@%
- %@NL@%
- do%@NL@%
- ; %@AB@%/* null statement for loop body */%@AE@%%@NL@%
- while (time(<ime) < end); %@AB@%/* wait for alarm time */%@AE@%%@NL@%
- %@NL@%
- printf("Time's Up!\a\a\a\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TIMER2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP06\TIMER2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* timer2.c -- interval timer */%@AE@%%@NL@%
- %@AB@%/* calls delay(), uses beep() */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@AB@%/* function declarations */%@AE@%%@NL@%
- void beep (times);%@NL@%
- void delay (seconds);%@NL@%
- %@NL@%
- %@AB@%/* variable declarations */%@AE@%%@NL@%
- int seconds, interval, tick;%@NL@%
- %@NL@%
- printf("Set for how many seconds? ");%@NL@%
- scanf("%d", &seconds);%@NL@%
- printf("Interval to show in seconds? ");%@NL@%
- scanf("%d", &interval);%@NL@%
- printf("Press a key to start timing\n");%@NL@%
- getch();%@NL@%
- %@NL@%
- tick = 0; %@AB@%/* run "clock" for */%@AE@%%@NL@%
- while (tick < seconds) %@AB@%/* time specified */%@AE@%%@NL@%
- {%@NL@%
- delay(interval); %@AB@%/* wait interval seconds */%@AE@%%@NL@%
- tick += interval;%@NL@%
- printf("%d\n", tick);%@NL@%
- beep(1);%@NL@%
- }%@NL@%
- beep(3);%@NL@%
- }%@NL@%
- %@NL@%
- void delay(seconds)%@NL@%
- %@AB@%/* wait for number of seconds specified */%@AE@%%@NL@%
- %@AB@%/* see TIMER.C in chapter 4 for details */%@AE@%%@NL@%
- %@AB@%/* on the library function time(). */%@AE@%%@NL@%
- %@NL@%
- int seconds; %@AB@%/* parameter declaration */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* variable declarations */%@AE@%%@NL@%
- long start, end, %@AB@%/* starting and ending times */%@AE@%%@NL@%
- %@AB@%/* measured in seconds since */%@AE@%%@NL@%
- %@AB@%/* Jan. 1, 1970 */%@AE@%%@NL@%
- ltime; %@AB@%/* used to get val from time function */%@AE@%%@NL@%
- %@NL@%
- start = time(<ime); %@AB@%/* get system elapsed seconds */%@AE@%%@NL@%
- %@AB@%/* since 1-1-70 */%@AE@%%@NL@%
- end = start + seconds; %@AB@%/* calculate alarm time */%@AE@%%@NL@%
- %@NL@%
- do%@NL@%
- ; %@AB@%/* null statement for loop body */%@AE@%%@NL@%
- while (time(<ime) < end); %@AB@%/* wait for end of time */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- void beep(times)%@NL@%
- %@AB@%/* parameter declaration */%@AE@%%@NL@%
- int times;%@NL@%
- {%@NL@%
- %@AB@%/* variable declaration */%@AE@%%@NL@%
- int count;%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* check that parameter is between 1 and 4 */%@AE@%%@NL@%
- if ((times < 1) || (times > 4))%@NL@%
- {%@NL@%
- printf("Error in beep(): %d beeps specified.\n",%@NL@%
- times);%@NL@%
- printf("Specify one to four beeps");%@NL@%
- }%@NL@%
- else %@AB@%/* sound the beeps */%@AE@%%@NL@%
- for (count = 1; count <= times; count++)%@NL@%
- printf("\a"); %@AB@%/* "alert" escape sequence */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TINY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\TINY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* tiny.c -- the smallest possible C */%@AE@%%@NL@%
- %@AB@%/* program with comments */%@AE@%%@NL@%
- %@NL@%
- main() %@AB@%/* function name and argument list */%@AE@%%@NL@%
- {%@NL@%
- %@AB@%/* function definition in braces */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TODAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\TODAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* today.c -- demonstrates using enum */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- enum week_days {%@NL@%
- monday = 1, %@AB@%/* start with 1 */%@AE@%%@NL@%
- tuesday,%@NL@%
- wednesday,%@NL@%
- thursday,%@NL@%
- friday,%@NL@%
- saturday,%@NL@%
- sunday%@NL@%
- } pay_day;%@NL@%
- %@NL@%
- static char *day_names[] = {%@NL@%
- "",%@NL@%
- "monday",%@NL@%
- "tuesday",%@NL@%
- "wednesday",%@NL@%
- "thursday",%@NL@%
- "friday",%@NL@%
- "saturday",%@NL@%
- "sunday"%@NL@%
- };%@NL@%
- %@NL@%
- printf("What day do you want to be paid on?\n");%@NL@%
- %@NL@%
- for (pay_day = monday; pay_day <= sunday; ++pay_day)%@NL@%
- {%@NL@%
- printf("%d. %s\n", pay_day, day_names[pay_day]);%@NL@%
- }%@NL@%
- %@NL@%
- printf("Which (%d-%d): ", monday, sunday);%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- pay_day = getch();%@NL@%
- pay_day -= '0';%@NL@%
- } while (pay_day < monday || pay_day > sunday);%@NL@%
- %@NL@%
- printf("%d\n\n", pay_day);%@NL@%
- %@NL@%
- printf("You selected %s\n", day_names[pay_day]);%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TOTAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\TOTAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* total.c -- how to build an array on the fly */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* for size_t */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int *iptr, count = 0, i, total;%@NL@%
- size_t bytes = sizeof(int);%@NL@%
- %@NL@%
- %@AB@%/* Start the array with room for one value. */%@AE@%%@NL@%
- if ((iptr = malloc(bytes)) == NULL)%@NL@%
- {%@NL@%
- printf("Oops, malloc failed\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- printf("Enter as many integer values as you want.\n");%@NL@%
- printf("I will build an array on the fly with them.\n");%@NL@%
- printf("(Any non-number means you are done.)\n");%@NL@%
- %@NL@%
- while (scanf("%d", &iptr[count]) == 1)%@NL@%
- {%@NL@%
- ++count;%@NL@%
- %@AB@%/* Enlarge the array. */%@AE@%%@NL@%
- if ((iptr = realloc(iptr,bytes*(count+1))) == NULL)%@NL@%
- {%@NL@%
- printf("Oops, realloc failed\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- total = 0;%@NL@%
- printf("You entered:\n");%@NL@%
- for (i = 0; i < count; i++)%@NL@%
- {%@NL@%
- printf("iptr[%d] = %d\n", i, iptr[i]);%@NL@%
- total += iptr[i];%@NL@%
- }%@NL@%
- printf("\nTotal: %d\n", total);%@NL@%
- return (0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TOTAL2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP08\TOTAL2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* total2.c -- how to build an array on the fly */%@AE@%%@NL@%
- %@AB@%/* using sbrk() */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* for size_t */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int *iptr, count = 0, i, total;%@NL@%
- size_t bytes = sizeof(int);%@NL@%
- %@NL@%
- %@AB@%/* Start the array with room for one value. */%@AE@%%@NL@%
- iptr = sbrk(0);%@NL@%
- if (sbrk(bytes) == (int *)-1)%@NL@%
- {%@NL@%
- printf("Oops, sbrk failed\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- printf("Enter as many integer values as you want.\n");%@NL@%
- printf("I will build an array on the fly with them.\n");%@NL@%
- printf("(Any non-number means you are done.)\n");%@NL@%
- %@NL@%
- while (scanf("%d", &iptr[count]) == 1)%@NL@%
- {%@NL@%
- ++count;%@NL@%
- %@AB@%/* Enlarge the array. */%@AE@%%@NL@%
- if (sbrk(bytes) == (int *)-1)%@NL@%
- {%@NL@%
- printf("Oops, sbrk failed\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- total = 0;%@NL@%
- for (i = 0; i < count; i++)%@NL@%
- total += iptr[i];%@NL@%
- %@AB@%/* just print the total this time */%@AE@%%@NL@%
- printf( "%d\n", total);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TRUTH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\TRUTH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* truth.c -- shows logical operators */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf("1 AND 1 is %d\n", 1 && 1);%@NL@%
- printf("1 AND 0 is %d\n", 1 && 0);%@NL@%
- printf("0 AND 0 is %d\n", 0 && 0);%@NL@%
- printf("1 OR 1 is %d\n", 1 || 1);%@NL@%
- printf("1 OR 0 is %d\n", 1 || 0);%@NL@%
- printf("0 OR 0 is %d\n", 0 || 0);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%TTT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\TTT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ttt.c -- a tic-tac-toe game demonstrates */%@AE@%%@NL@%
- %@AB@%/* passing two-dimensional arrays */%@AE@%%@NL@%
- %@AB@%/* to functions */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static char board[3][3] = {%@NL@%
- { '-', '-', '-' },%@NL@%
- { '-', '-', '-' },%@NL@%
- { '-', '-', '-' },%@NL@%
- };%@NL@%
- int row, col, ch;%@NL@%
- extern char Check_winner();%@NL@%
- extern void Make_move(), Draw_field();%@NL@%
- %@NL@%
- printf("You are X and make the first move.\n");%@NL@%
- while (1)%@NL@%
- {%@NL@%
- printf("Specify coordinate for your X.\n");%@NL@%
- printf("(eg, as a2, or Q to quit)\n");%@NL@%
- %@NL@%
- %@AB@%/* Print the square. */%@AE@%%@NL@%
- Draw_field(board);%@NL@%
- %@NL@%
- %@AB@%/* Input the user's coordinates. */%@AE@%%@NL@%
- if ((row = getch()) == 'Q')%@NL@%
- exit(0);%@NL@%
- row -= 'a';%@NL@%
- col = getch() - '1';%@NL@%
- %@NL@%
- %@AB@%/* Check for a legal move. */%@AE@%%@NL@%
- if (row < 0 || row > 2 || col < 0 || col > 2)%@NL@%
- {%@NL@%
- printf("Bad Square Specification\n\n");%@NL@%
- continue;%@NL@%
- }%@NL@%
- if (board[row][col] != '-')%@NL@%
- {%@NL@%
- printf("Sorry, Square Occupied\n\n");%@NL@%
- continue;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Make the move. */%@AE@%%@NL@%
- board[row][col] = 'X';%@NL@%
- if ((ch = Check_winner(board)) != '-' || ch == 't')%@NL@%
- break;%@NL@%
- Make_move(board);%@NL@%
- if ((ch = Check_winner(board)) != '-' || ch == 't')%@NL@%
- break;%@NL@%
- }%@NL@%
- Draw_field(board);%@NL@%
- if (ch == 't')%@NL@%
- printf("It's a tie!\n");%@NL@%
- else if (ch == 'X')%@NL@%
- printf("You win!\n");%@NL@%
- else%@NL@%
- printf("I win!\n");%@NL@%
- }%@NL@%
- %@NL@%
- char Check_winner(char field[][3])%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- %@NL@%
- for (row = col = 0; row < 3; ++row, ++col)%@NL@%
- {%@NL@%
- if (field[row][0] != '-' %@AB@%/* horizontal */%@AE@%%@NL@%
- && field[row][0] == field[row][1]%@NL@%
- && field[row][1] == field[row][2] )%@NL@%
- {%@NL@%
- return(field[row][0]);%@NL@%
- }%@NL@%
- if (field[0][col] != '-' %@AB@%/* vertical */%@AE@%%@NL@%
- && field[0][col] == field[1][col]%@NL@%
- && field[1][col] == field[2][col] )%@NL@%
- {%@NL@%
- return(field[0][col]);%@NL@%
- }%@NL@%
- }%@NL@%
- if (field[0][0] != '-' %@AB@%/* right diagonal */%@AE@%%@NL@%
- && field[0][0] == field[1][1]%@NL@%
- && field[1][1] == field[2][2] )%@NL@%
- {%@NL@%
- return(field[0][0]);%@NL@%
- }%@NL@%
- if (field[0][2] != '-' %@AB@%/* left diagonal */%@AE@%%@NL@%
- && field[0][2] == field[1][1]%@NL@%
- && field[1][1] == field[2][0] )%@NL@%
- {%@NL@%
- return(field[0][2]);%@NL@%
- }%@NL@%
- %@NL@%
- for (row = 0; row < 3; ++row) %@AB@%/* any moves left */%@AE@%%@NL@%
- {%@NL@%
- for (col = 0; col < 3; ++col)%@NL@%
- {%@NL@%
- if (field[row][col] == '-')%@NL@%
- {%@NL@%
- return('-');%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- return ('t');%@NL@%
- }%@NL@%
- %@NL@%
- void Make_move(char field[3][3])%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- %@NL@%
- for (row = 2; row >= 0; --row)%@NL@%
- {%@NL@%
- for (col = 2; col >= 0; --col)%@NL@%
- {%@NL@%
- if (field[row][col] == '-')%@NL@%
- {%@NL@%
- field[row][col] = 'O';%@NL@%
- return;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- void Draw_field(char field[][3])%@NL@%
- {%@NL@%
- int row, col;%@NL@%
- %@NL@%
- printf("\n 1 2 3\n\n");%@NL@%
- for (row = 0; row < 3; ++row)%@NL@%
- {%@NL@%
- printf("%c ", 'a'+row);%@NL@%
- for (col = 0; col < 3; ++col)%@NL@%
- {%@NL@%
- printf(" %c ", field[row][col] );%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%UDEMO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP11\UDEMO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* udemo.c -- demonstrates a union at work */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- char *Strings[6] = {%@NL@%
- "Quit",%@NL@%
- "line of text",%@NL@%
- "floating point double value",%@NL@%
- "long integer value",%@NL@%
- "floating point value",%@NL@%
- "integer value"%@NL@%
- };%@NL@%
- %@NL@%
- struct Unitstruct {%@NL@%
- union {%@NL@%
- char wtype[BUFSIZ];%@NL@%
- double dtype;%@NL@%
- long ltype;%@NL@%
- float ftype;%@NL@%
- int itype;%@NL@%
- } manyu;%@NL@%
- int type_in_union;%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- struct Unitstruct one_of_many;%@NL@%
- %@NL@%
- while ((one_of_many.type_in_union = Menu()) != 0)%@NL@%
- {%@NL@%
- Inputval(&one_of_many);%@NL@%
- Printval(&one_of_many);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- Inputval(struct Unitstruct *one_of_many)%@NL@%
- {%@NL@%
- printf("\nEnter a %s: ", Strings[one_of_many->type_in_union]);%@NL@%
- switch(one_of_many->type_in_union)%@NL@%
- {%@NL@%
- case 1: %@NL@%
- fgets(one_of_many->manyu.wtype, BUFSIZ, stdin);%@NL@%
- break;%@NL@%
- case 2:%@NL@%
- scanf("%lf", &(one_of_many->manyu.dtype));%@NL@%
- while (getchar() != '\n');%@NL@%
- break;%@NL@%
- case 3:%@NL@%
- scanf("%ld", &(one_of_many->manyu.ltype));%@NL@%
- while (getchar() != '\n');%@NL@%
- break;%@NL@%
- case 4:%@NL@%
- scanf("%f", &(one_of_many->manyu.ftype));%@NL@%
- while (getchar() != '\n');%@NL@%
- break;%@NL@%
- case 5:%@NL@%
- scanf("%i", &(one_of_many->manyu.itype));%@NL@%
- while (getchar() != '\n');%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- Printval(struct Unitstruct *one_of_many)%@NL@%
- {%@NL@%
- printf("The %s you entered\nwas: ", Strings[one_of_many->type_in_union]);%@NL@%
- switch (one_of_many->type_in_union)%@NL@%
- {%@NL@%
- case 1: %@NL@%
- fputs(one_of_many->manyu.wtype, stdout);%@NL@%
- break;%@NL@%
- case 2:%@NL@%
- printf("%lf", one_of_many->manyu.dtype);%@NL@%
- break;%@NL@%
- case 3:%@NL@%
- printf("%ld", one_of_many->manyu.ltype);%@NL@%
- break;%@NL@%
- case 4:%@NL@%
- printf("%f", one_of_many->manyu.ftype);%@NL@%
- break;%@NL@%
- case 5:%@NL@%
- printf("%i", one_of_many->manyu.itype);%@NL@%
- break;%@NL@%
- }%@NL@%
- printf("\n\n");%@NL@%
- }%@NL@%
- %@NL@%
- Menu()%@NL@%
- {%@NL@%
- int i;%@NL@%
- char ch;%@NL@%
- %@NL@%
- for (i = 0; i < 6; ++i)%@NL@%
- {%@NL@%
- printf("%d) %s\n", i, Strings[i]);%@NL@%
- }%@NL@%
- printf("Which: ");%@NL@%
- do%@NL@%
- {%@NL@%
- ch = getch();%@NL@%
- } while (ch < '0' || ch > '5');%@NL@%
- printf("%c\n", ch);%@NL@%
- return (ch - '0');%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%UNDOVER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\UNDOVER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* undover.c -- illustrates the effect of underinitializing and */%@AE@%%@NL@%
- %@AB@%/* overinitializing arrays. */%@AE@%%@NL@%
- %@NL@%
- int Primes[6] = { 1, 2, 3, 5, 7, 11 };%@NL@%
- %@AI@%#define %@AE@%NUMP (sizeof(Primes)/sizeof(int)) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- printf("The first %d primes are: ", NUMP);%@NL@%
- for (i = 0; i < NUMP; ++i)%@NL@%
- {%@NL@%
- printf("%d ", Primes[i]);%@NL@%
- }%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%UPITY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\UPITY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* upity.c -- makes an uppercase copy of a file using */%@AE@%%@NL@%
- %@AB@%/* fread() and fwrite() */%@AE@%%@NL@%
- %@NL@%
- <string.h> %@AB@%/* for strrchr() */%@AE@%%@NL@%
- <stdio.h> %@AB@%/* for NULL */%@AE@%%@NL@%
- <malloc.h> %@AB@%/* for malloc() */%@AE@%%@NL@%
- <ctype.h> %@AB@%/* for isupper() */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%HUNK 512 %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- char *cp, newname[128], *np;%@NL@%
- FILE *fp;%@NL@%
- int hunks = 0, bytes = 0, totbytes = 0;%@NL@%
- int i;%@NL@%
- if (argc != 2)%@NL@%
- {%@NL@%
- printf("usage: upity file\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- if ((fp = fopen(argv[1], "rb")) == NULL)%@NL@%
- {%@NL@%
- printf("\"%s\": Can't open.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- if ((cp = malloc(HUNK)) == NULL)%@NL@%
- {%@NL@%
- printf("Malloc Failed.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- while ((bytes = fread(cp + (HUNK * hunks), 1, HUNK, fp)) == HUNK)%@NL@%
- {%@NL@%
- totbytes += bytes;%@NL@%
- ++hunks;%@NL@%
- if ((cp = realloc(cp, HUNK + (HUNK * hunks))) == NULL)%@NL@%
- {%@NL@%
- printf("Realloc Failed.\n");%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- if (bytes < 0)%@NL@%
- {%@NL@%
- printf("\"%s\": Error Reading.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- totbytes += bytes;%@NL@%
- %@NL@%
- for (i = 0; i < totbytes; ++i)%@NL@%
- if (islower(cp[i]))%@NL@%
- cp[i] = toupper(cp[i]);%@NL@%
- %@NL@%
- (void)fclose(fp);%@NL@%
- %@NL@%
- if ((np = strrchr(argv[1], '.')) != NULL)%@NL@%
- *np = '\0';%@NL@%
- strcpy(newname, argv[1]);%@NL@%
- strcat(newname, ".up");%@NL@%
- if ((fp = fopen(newname, "wb")) == NULL)%@NL@%
- {%@NL@%
- printf("\"%s\": Can't open.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- if (fwrite(cp, 1, totbytes, fp) != totbytes)%@NL@%
- {%@NL@%
- printf("\"%s\": Error writing.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VARADDRS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\VARADDRS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* varaddrs.c -- use & operator to get */%@AE@%%@NL@%
- %@AB@%/* addresses of variables */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char c1, c2;%@NL@%
- int i;%@NL@%
- long l;%@NL@%
- float f;%@NL@%
- double d;%@NL@%
- %@NL@%
- printf("Address of c1 %d\n", &c1);%@NL@%
- printf("Address of c2 %d\n", &c2);%@NL@%
- printf("Address of i %d\n", &i);%@NL@%
- printf("Address of l %d\n", &l);%@NL@%
- printf("Address of f %d\n", &f);%@NL@%
- printf("Address of d %d\n", &d);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VARSIZE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP03\VARSIZE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* varsize.c -- shows amount of memory */%@AE@%%@NL@%
- %@AB@%/* by various types */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf("Size of a char is %d\n", sizeof(char));%@NL@%
- printf("Size of an int is %d\n", sizeof(int));%@NL@%
- printf("Size of a long is %d\n", sizeof(long));%@NL@%
- printf("Size of a float is %d\n", sizeof(float));%@NL@%
- printf("Size of a double is %d\n", sizeof(double));%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VGAMAP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP15\VGAMAP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* vgamap.c -- remaps the vga mode 19 palette */%@AE@%%@NL@%
- %@AB@%/* Program list: vgamap.c (for rand()) */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@%ESC '\033' %@NL@%
- %@AI@%#define %@AE@%PALSIZE 256 %@NL@%
- %@AI@%#define %@AE@%ROWS 16 %@NL@%
- %@AI@%#define %@AE@%COLS 16 %@NL@%
- %@AI@%#define %@AE@%MIDBLUE 0x190000L %@NL@%
- long newpal[PALSIZE]; %@AB@%/* array of color values */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _MRES256COLOR;%@NL@%
- short xmax, ymax;%@NL@%
- short xcs[ROWS][COLS];%@NL@%
- short ycs[ROWS][COLS];%@NL@%
- short row, col;%@NL@%
- long colorval; %@AB@%/* VGA color value */%@AE@%%@NL@%
- long index; %@AB@%/* looping index */%@AE@%%@NL@%
- short palval; %@AB@%/* palette value */%@AE@%%@NL@%
- int c_base; %@AB@%/* color base -- blue, green, or red */%@AE@%%@NL@%
- int ch;%@NL@%
- %@NL@%
- if (_setvideomode(mode) == 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "%d mode not supported\n", mode);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- _getvideoconfig(&vc);%@NL@%
- xmax = vc.numxpixels - 1;%@NL@%
- ymax = vc.numypixels - 1;%@NL@%
- for (col = 0; col < COLS; col++)%@NL@%
- for (row = 0; row < ROWS; row++)%@NL@%
- {%@NL@%
- xcs[row][col] = col * xmax / COLS + 5;%@NL@%
- ycs[row][col] = row * ymax / ROWS + 5;%@NL@%
- }%@NL@%
- _setcolor(1);%@NL@%
- _rectangle(_GBORDER, 0, 0, xmax, ymax);%@NL@%
- for (col = 1; col < COLS ; col++)%@NL@%
- {%@NL@%
- _moveto(col * (xmax + 1) / COLS, 0);%@NL@%
- _lineto(col * (xmax + 1) / COLS, ymax);%@NL@%
- }%@NL@%
- for (row = 1; row < ROWS; row++)%@NL@%
- {%@NL@%
- _moveto(0, row * (ymax + 1) / ROWS);%@NL@%
- _lineto(xmax, row * (ymax + 1) / ROWS);%@NL@%
- }%@NL@%
- %@NL@%
- for (col = 0; col < COLS; col++)%@NL@%
- for (row = 0; row < ROWS; row++)%@NL@%
- {%@NL@%
- _setcolor(row * ROWS + col);%@NL@%
- _floodfill(xcs[row][col], ycs[row][col],1);%@NL@%
- }%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* initialize newpal[] to 64 shades of blue, 64%@NL@%
- %@AB@% shades of green, 64 shades of red, and 64 shades%@NL@%
- %@AB@% of magenta */%@AE@%%@NL@%
- for (index = 0; index < 64; index++)%@NL@%
- {%@NL@%
- newpal[index] = index << 16;%@NL@%
- newpal[index + 64] = index << 8;%@NL@%
- newpal[index + 128] = index;%@NL@%
- newpal[index + 192] = index | MIDBLUE;%@NL@%
- }%@NL@%
- _remapallpalette(newpal);%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* set squares and colors randomly -- ESC%@NL@%
- %@AB@% terminates loop, and other keystrokes toggle%@NL@%
- %@AB@% it on and off */%@AE@%%@NL@%
- do%@NL@%
- {%@NL@%
- while (!kbhit())%@NL@%
- {%@NL@%
- palval = rand() % PALSIZE;%@NL@%
- colorval = 0L;%@NL@%
- for (c_base = 0; c_base < 3; c_base++)%@NL@%
- colorval += ((long) rand() % 64) <<%@NL@%
- (c_base * 8);%@NL@%
- _remappalette (palval, colorval);%@NL@%
- }%@NL@%
- ch = getch();%@NL@%
- if (ch != ESC)%@NL@%
- ch = getch();%@NL@%
- } while (ch != ESC);%@NL@%
- _setvideomode(_DEFAULTMODE);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%VIEW.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP10\VIEW.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* view.c -- demonstrates lseek() by displaying */%@AE@%%@NL@%
- %@AB@%/* a file and moving around in it */%@AE@%%@NL@%
- %@NL@%
- <fcntl.h> %@AB@%/* for open() */%@AE@%%@NL@%
- <stdio.h> %@AB@%/* for SEEK_CUR, etc. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%HUNK 512 %@NL@%
- %@AI@%#define %@AE@%MOVE 512L %@NL@%
- %@NL@%
- main(argc, argv)%@NL@%
- int argc;%@NL@%
- char *argv[];%@NL@%
- {%@NL@%
- char ch, buf[HUNK];%@NL@%
- long position = 0L;%@NL@%
- int bytes, eofflag = 0, fd_in;%@NL@%
- %@NL@%
- if (argc != 2)%@NL@%
- {%@NL@%
- fprintf(stderr, "Usage: view file\n");%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- %@NL@%
- if ((fd_in = open(argv[1], O_RDONLY)) < 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Can't open.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- %@NL@%
- for (;;)%@NL@%
- {%@NL@%
- bytes = read(fd_in, buf, HUNK);%@NL@%
- if (bytes == 0)%@NL@%
- {%@NL@%
- if (! eofflag)%@NL@%
- {%@NL@%
- fprintf(stderr, "\n<<at end of file>>\n");%@NL@%
- ++eofflag;%@NL@%
- }%@NL@%
- else%@NL@%
- exit(0);%@NL@%
- }%@NL@%
- else if (bytes < 0)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Reading.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- eofflag = 0;%@NL@%
- position = lseek(fd_in, 0L, SEEK_CUR);%@NL@%
- if (position == -1L)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Seeking.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- Print(buf, bytes);%@NL@%
- do%@NL@%
- {%@NL@%
- ch = getch();%@NL@%
- if (ch == 'q' || ch == 'Q')%@NL@%
- exit(0);%@NL@%
- } while (ch != '+' && ch != '-');%@NL@%
- %@NL@%
- if (ch == '-')%@NL@%
- {%@NL@%
- position = lseek(fd_in, -2 * MOVE, SEEK_CUR);%@NL@%
- if (position == -1L)%@NL@%
- {%@NL@%
- fprintf(stderr, "\"%s\": Error Seeking.\n", argv[1]);%@NL@%
- exit(1);%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- Print(char *buf, int cnt)%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < cnt; ++i, ++buf)%@NL@%
- {%@NL@%
- if (*buf < ' ' && *buf != '\n' && *buf != '\t')%@NL@%
- printf("^%c", *buf + '@');%@NL@%
- else%@NL@%
- putchar(*buf);%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WHATCHAR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP09\WHATCHAR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* whatchar.c -- demonstrates the character */%@AE@%%@NL@%
- %@AB@%/* classification routines in ctype.h */%@AE@%%@NL@%
- %@NL@%
- <stdio.h> %@AB@%/* for NULL and BUFSIZ */%@AE@%%@NL@%
- <ctype.h> %@AB@%/* for iscntl(), et al */%@AE@%%@NL@%
- %@AI@%#define %@AE@%MAXL 20 %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char buf[BUFSIZ];%@NL@%
- int i;%@NL@%
- %@NL@%
- printf("Enter a line of text (20 chars max):\n");%@NL@%
- if (gets(buf) == NULL)%@NL@%
- exit(1);%@NL@%
- %@NL@%
- for (i = 0; i < MAXL; ++i)%@NL@%
- {%@NL@%
- if (buf[i] == '\0')%@NL@%
- break;%@NL@%
- printf("'%c' ->", buf[i]);%@NL@%
- if (isalpha(buf[i])) printf(" isalpha");%@NL@%
- if (isascii(buf[i])) printf(" isascii");%@NL@%
- if (iscntrl(buf[i])) printf(" iscntrl");%@NL@%
- if (isgraph(buf[i])) printf(" isgraph");%@NL@%
- if (isprint(buf[i])) printf(" isprint");%@NL@%
- if (isdigit(buf[i])) printf(" isdigit");%@NL@%
- if (isupper(buf[i])) printf(" isupper");%@NL@%
- if (islower(buf[i])) printf(" islower");%@NL@%
- if (ispunct(buf[i])) printf(" ispunct");%@NL@%
- if (isspace(buf[i])) printf(" isspace");%@NL@%
- if (isalnum(buf[i])) printf(" isalnum");%@NL@%
- if (isxdigit(buf[i])) printf(" isxdigit");%@NL@%
- printf("\n");%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WHILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP04\WHILE.C%@AE@%%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* WHILE.C -- a simple while loop */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count = 1;%@NL@%
- %@NL@%
- while (count < 11) %@AB@%/* loop condition */%@AE@%%@NL@%
- %@AB@%/* body of loop */%@AE@%%@NL@%
- {%@NL@%
- printf("%d\n", count);%@NL@%
- count++ ;%@NL@%
- }%@NL@%
- printf("Done!\n");%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITECHR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\WRITECHR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* writechr.c -- writes char and attribute repeatedly */%@AE@%%@NL@%
- %@AB@%/* using DMA */%@AE@%%@NL@%
- %@AB@%/* write character ch with attribute attr num times */%@AE@%%@NL@%
- %@AB@%/* starting at location pstart -- uses array notation */%@AE@%%@NL@%
- %@NL@%
- typedef unsigned int (far * VIDMEM); %@NL@%
- %@NL@%
- void Write_chars(pstart, ch, attr, num)%@NL@%
- VIDMEM pstart;%@NL@%
- unsigned short ch, attr, num;%@NL@%
- {%@NL@%
- register count;%@NL@%
- unsigned short pair;%@NL@%
- %@NL@%
- pair = (attr << 8) | (ch & 0x00FF) ;%@NL@%
- for (count = 0; count < num; count++)%@NL@%
- pstart[count] = pair;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%WRITESTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP14\WRITESTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* writestr.c -- writes string and attribute using DMA */%@AE@%%@NL@%
- %@AB@%/* write the string str with attribute attr at */%@AE@%%@NL@%
- %@AB@%/* location pstart -- uses pointer notation. */%@AE@%%@NL@%
- %@NL@%
- typedef unsigned int (far * VIDMEM); %@NL@%
- %@NL@%
- void Write_str(pstart, attr, str)%@NL@%
- VIDMEM pstart;%@NL@%
- unsigned short attr;%@NL@%
- char *str;%@NL@%
- {%@NL@%
- while (*str != '\0')%@NL@%
- *pstart++ = (attr << 8) | (*str++ & 0x00FF);%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%XMAS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\QC_PROG\CHAP07\XMAS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* xmas.c -- fills an array with values, then passes */%@AE@%%@NL@%
- %@AB@%/* each of those values to a function. */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i, j, widths[20];%@NL@%
- void Center_out();%@NL@%
- %@NL@%
- for (i = 0, j = 1; i < 18; ++i, j += 2)%@NL@%
- {%@NL@%
- widths[i] = j;%@NL@%
- }%@NL@%
- widths[i++] = 3;%@NL@%
- widths[i] = 3;%@NL@%
- %@NL@%
- for (i = 0; i < 20; i++)%@NL@%
- {%@NL@%
- Center_out('X', widths[i]);%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- void Center_out(char character, int width)%@NL@%
- {%@NL@%
- int i;%@NL@%
- %@NL@%
- for (i = 0; i < ((80 - width) / 2); ++i)%@NL@%
- {%@NL@%
- putch(' ');%@NL@%
- }%@NL@%
- for (i = 0; i < width; ++i)%@NL@%
- {%@NL@%
- putch(character);%@NL@%
- }%@NL@%
- putch('\r');%@NL@%
- putch('\n');%@NL@%
- }%@NL@%
- %@1@%%@AH@%Misc. `C' Sample Code from Microsoft%@EH@%%@AE@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ABS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ABS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ABS.C: Demonstrate macros. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%ABS(value) ( (value) >= 0 ? (value) : -(value) ) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = -20;%@NL@%
- printf( "result = %d\n", ABS(val) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ALARM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ALARM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ALARM.C illustrates inline assembly and functions or keywords%@NL@%
- %@AB@% * related to Terminate-and-Stay-Resident programs. Functions include:%@NL@%
- %@AB@% * _dos_setvect _dos_getvect _dos_keep%@NL@%
- %@AB@% * _chain_intr _enable _disable%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Keywords:%@NL@%
- %@AB@% * interrupt _asm%@NL@%
- %@AB@% * Directive:%@NL@%
- %@AB@% * #pragma%@NL@%
- %@AB@% * Pragma:%@NL@%
- %@AB@% * check_stack check_pointer%@NL@%
- %@AB@% * Global variables:%@NL@%
- %@AB@% * _psp _amblksiz%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * WARNING: You must run ALARM from the DOS command line. The QC%@NL@%
- %@AB@% * environment does not permit TSRs to be installed from inside it, since%@NL@%
- %@AB@% * this would cause subsequent memory problems.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See HARDERR.C for another example of inline assembler. See MOVEMEM.C%@NL@%
- %@AB@% * for another pragma example.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@NL@%
- %@AB@%/* Stack and pointer checking off */%@AE@%%@NL@%
- %@AI@%#pragma %@AE@%check_stack( off ) %@NL@%
- %@AI@%#pragma %@AE@%check_pointer( off ) %@NL@%
- %@NL@%
- %@AB@%/* Inline assembler macro to sound a bell. Note that comments in macros must%@NL@%
- %@AB@% * be in the C format, not the assembler format.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%BEEP() _asm { \ %@NL@%
- _asm push bx %@AB@%/* Save register */%@AE@% \%@NL@%
- _asm sub bx, bx %@AB@%/* Page 0 */%@AE@% \%@NL@%
- _asm mov ax, 0E07h %@AB@%/* TTY bell */%@AE@% \%@NL@%
- _asm int 10h %@AB@%/* BIOS 10 */%@AE@% \%@NL@%
- _asm pop bx %@AB@%/* Restore */%@AE@% \%@NL@%
- }%@NL@%
- %@NL@%
- %@AI@%#define %@AE@%TICKPERMIN 1092L %@NL@%
- %@AI@%#define %@AE@%MINPERHOUR 60L %@NL@%
- enum BOOLEAN { FALSE, TRUE };%@NL@%
- %@NL@%
- %@AB@%/* Prototypes for interrupt functions */%@AE@%%@NL@%
- void (interrupt far *oldtimer)( void );%@NL@%
- void (interrupt far *oldvideo)( void );%@NL@%
- void interrupt far newtimer( void );%@NL@%
- void interrupt far newvideo( unsigned _es, unsigned _ds, unsigned _di,%@NL@%
- unsigned _si, unsigned _bp, unsigned _sp,%@NL@%
- unsigned _bx, unsigned _dx, unsigned _cx,%@NL@%
- unsigned _ax, unsigned _ip, unsigned _cs,%@NL@%
- unsigned _flags );%@NL@%
- %@NL@%
- %@AB@%/* Variables that will be accessed inside TSR must be global. */%@AE@%%@NL@%
- int ftimesup = FALSE, fintimer = FALSE, finvideo = FALSE;%@NL@%
- long goaltick;%@NL@%
- long far *pcurtick = (long far *)0x0000046cL;%@NL@%
- %@NL@%
- %@AB@%/* Huge pointers force compiler to do segment arithmetic for us. */%@AE@%%@NL@%
- char huge *tsrstack;%@NL@%
- char huge *appstack;%@NL@%
- char huge *tsrbottom;%@NL@%
- %@NL@%
- main( int argc, char **argv )%@NL@%
- {%@NL@%
- long minute, hour;%@NL@%
- unsigned tsrsize;%@NL@%
- %@NL@%
- %@AB@%/* Initialize stack and bottom of program. */%@AE@%%@NL@%
- _asm mov WORD PTR tsrstack[0], sp%@NL@%
- _asm mov WORD PTR tsrstack[2], ss%@NL@%
- FP_SEG( tsrbottom ) = _psp;%@NL@%
- FP_OFF( tsrbottom ) = 0;%@NL@%
- %@NL@%
- %@AB@%/* Use 16 paragraph heap (controlled through global in malloc.h). */%@AE@%%@NL@%
- _amblksiz = 256;%@NL@%
- %@NL@%
- %@AB@%/* Program size is:%@NL@%
- %@AB@% * top of stack%@NL@%
- %@AB@% * - bottom of program (converted to paragraphs)%@NL@%
- %@AB@% * + paragraphs in the heap plus%@NL@%
- %@AB@% * + one extra paragraph just to be safe%@NL@%
- %@AB@% */%@AE@%%@NL@%
- tsrsize = ((tsrstack - tsrbottom) >> 4) + (_amblksiz >> 4) + 1;%@NL@%
- %@NL@%
- %@AB@%/* If command-line, convert time to ticks past midnight. Time must%@NL@%
- %@AB@% * include 0 in first place (0930, not 930). Time must be later than%@NL@%
- %@AB@% * current time.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( argc < 2 )%@NL@%
- {%@NL@%
- puts( " Syntax: ALARM <hhmm> " );%@NL@%
- puts( " where <hhmm> is time (in military format) to ring alarm" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- minute = atol( argv[1] + 2 );%@NL@%
- argv[1][2] = 0;%@NL@%
- hour = atol( argv[1] );%@NL@%
- goaltick = (hour * MINPERHOUR * TICKPERMIN) + (minute * TICKPERMIN);%@NL@%
- if( *pcurtick > goaltick )%@NL@%
- {%@NL@%
- puts( "It's past that time now" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Replace existing timer and video routines with ours. */%@AE@%%@NL@%
- oldtimer = _dos_getvect( 0x1c );%@NL@%
- _dos_setvect( 0x1c, newtimer );%@NL@%
- oldvideo = _dos_getvect( 0x10 );%@NL@%
- _dos_setvect( 0x10, newvideo );%@NL@%
- %@NL@%
- %@AB@%/* Free the PSP segment and terminate with program resident. */%@AE@%%@NL@%
- _dos_freemem( _psp );%@NL@%
- _dos_keep( 0, tsrsize );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* newtimer - Our timer interrupt compares current time to goal. If earlier%@NL@%
- %@AB@% * it just continues. If later, it beeps and sets a flag to quit checking.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void interrupt far newtimer()%@NL@%
- {%@NL@%
- if( ftimesup )%@NL@%
- _chain_intr( oldtimer );%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* First execute the original timer interrupt. */%@AE@%%@NL@%
- (*oldtimer)();%@NL@%
- if( *pcurtick > goaltick )%@NL@%
- {%@NL@%
- %@AB@%/* If time is up, set flag so we'll never return. */%@AE@%%@NL@%
- ftimesup = TRUE;%@NL@%
- %@NL@%
- %@AB@%/* Save current stack of application, and set old stack of TSR.%@NL@%
- %@AB@% * This is for safety since we don't know the state of the%@NL@%
- %@AB@% * application stack, but we do know the state of our own stack.%@NL@%
- %@AB@% * Turn off interrupts during the stack switch.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _disable();%@NL@%
- _asm \%@NL@%
- {%@NL@%
- mov WORD PTR appstack[0], sp ; Save current stack%@NL@%
- mov WORD PTR appstack[2], ss%@NL@%
- mov sp, WORD PTR tsrstack[0] ; Load new stack%@NL@%
- mov ss, WORD PTR tsrstack[2]%@NL@%
- }%@NL@%
- _enable();%@NL@%
- %@NL@%
- %@AB@%/* Make sure we're not in video interrupt, then BEEP. This check%@NL@%
- %@AB@% * prevents the rare but potentially dangerous case of%@NL@%
- %@AB@% * calling INT 10 to beep while INT 10 is already running.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( finvideo )%@NL@%
- ;%@NL@%
- BEEP();%@NL@%
- BEEP();%@NL@%
- BEEP();%@NL@%
- %@NL@%
- %@AB@%/* Restore application stack. */%@AE@%%@NL@%
- _disable();%@NL@%
- _asm \%@NL@%
- {%@NL@%
- mov sp, WORD PTR appstack[0]%@NL@%
- mov ss, WORD PTR appstack[2]%@NL@%
- }%@NL@%
- _enable();%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* newvideo - This routine protects against reentering INT 10 while it is%@NL@%
- %@AB@% * already executing. This could be disastrous if the interrupt routine was%@NL@%
- %@AB@% * interrupted while it was accessing a hardware register.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void interrupt far newvideo( unsigned _es, unsigned _ds, unsigned _di,%@NL@%
- unsigned _si, unsigned _bp, unsigned _sp,%@NL@%
- unsigned _bx, unsigned _dx, unsigned _cx,%@NL@%
- unsigned _ax, unsigned _ip, unsigned _cs,%@NL@%
- unsigned _flags )%@NL@%
- {%@NL@%
- static unsigned save_bp;%@NL@%
- %@NL@%
- %@AB@%/* If not already in (most of the time), chain to original. */%@AE@%%@NL@%
- if( !finvideo )%@NL@%
- _chain_intr( oldvideo );%@NL@%
- else%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* Set the inside flag, then make sure all the real registers%@NL@%
- %@AB@% * that might be passed to an interrupt 10h match the parameter%@NL@%
- %@AB@% * registers. Some of the real registers may be modified by the%@NL@%
- %@AB@% * preceding code. Note that BP must be saved in a static (nonstack)%@NL@%
- %@AB@% * variable so that it can be retrieved without modifying the stack.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- finvideo = TRUE;%@NL@%
- _asm \%@NL@%
- {%@NL@%
- mov ax, _ax%@NL@%
- mov bx, _bx%@NL@%
- mov cx, _cx%@NL@%
- mov dx, _dx%@NL@%
- mov es, _es%@NL@%
- mov di, _di%@NL@%
- mov save_bp, bp%@NL@%
- mov bp, _bp%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Call the original interrupt. */%@AE@%%@NL@%
- (*oldvideo)();%@NL@%
- %@NL@%
- %@AB@%/* Make sure that any values returned in real registers by the%@NL@%
- %@AB@% * interrupt are updated in the parameter registers. Reset the flag.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _asm \%@NL@%
- {%@NL@%
- mov bp, save_bp%@NL@%
- mov _bp, bp%@NL@%
- mov _di, di%@NL@%
- mov _es, es%@NL@%
- mov _dx, dx%@NL@%
- mov _cx, cx%@NL@%
- mov _bx, bx%@NL@%
- mov _ax, ax%@NL@%
- }%@NL@%
- finvideo = FALSE;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ANIMATE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\ANIMATE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ANIMATE.C illustrates animation functions including:%@NL@%
- %@AB@% * _imagesize _getimage _putimage%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stddef.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- short action[5] = { _GPSET, _GPRESET, _GXOR, _GOR, _GAND };%@NL@%
- char *descrip[5] = { "PSET ", "PRESET", "XOR ", "OR ", "AND " };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char far *buffer;%@NL@%
- short i, x, y = 30;%@NL@%
- size_t imsize;%@NL@%
- short mode = _VRES16COLOR;%@NL@%
- %@NL@%
- while( !_setvideomode( mode ) ) %@AB@%/* Find best graphics mode */%@AE@%%@NL@%
- mode--;%@NL@%
- if (mode == _TEXTMONO )%@NL@%
- exit( 1 ); %@AB@%/* No graphics available */%@AE@%%@NL@%
- _setcolor( 3 );%@NL@%
- for ( i = 0; i < 5; i++ )%@NL@%
- {%@NL@%
- x = 50; y += 40;%@NL@%
- _settextposition( 1, 1 ); %@AB@%/* Display action type */%@AE@%%@NL@%
- _outtext( descrip[i] );%@NL@%
- %@AB@%/* Draw and measure ellipse */%@AE@%%@NL@%
- _ellipse( _GFILLINTERIOR, x - 15, y - 15, x + 15, y + 15 );%@NL@%
- imsize = (size_t)_imagesize( x - 16, y - 16, x + 16, y + 16 );%@NL@%
- buffer = (char far *)_fmalloc( imsize );%@NL@%
- if ( buffer == (char far *)NULL )%@NL@%
- exit( 1 );%@NL@%
- %@AB@%/* Get master copy of ellipse */%@AE@%%@NL@%
- _getimage( x - 16, y - 16, x + 16, y + 16, buffer );%@NL@%
- while( x < 260 ) %@AB@%/* Copy row of ellipses */%@AE@%%@NL@%
- { %@AB@%/* with specified action */%@AE@%%@NL@%
- x += 5;%@NL@%
- _putimage( x - 16, y - 16, buffer, action[i] );%@NL@%
- }%@NL@%
- _ffree( (char far *)buffer ); %@AB@%/* Free memory */%@AE@%%@NL@%
- getch();%@NL@%
- }%@NL@%
- exit( !_setvideomode( _DEFAULTMODE ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARGS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ARGS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARGS.C illustrates the following variables used for accessing%@NL@%
- %@AB@% * command-line arguments and environment variables:%@NL@%
- %@AB@% * argc argv envp%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Also illustrates getting a process ID with:%@NL@%
- %@AB@% * getpid%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<process.h> %@NL@%
- %@NL@%
- main( int argc, %@AB@%/* Number of strings in array argv */%@AE@%%@NL@%
- char *argv[], %@AB@%/* Array of command-line argument strings */%@AE@%%@NL@%
- char **envp ) %@AB@%/* Array of environment variable strings */%@AE@%%@NL@%
- {%@NL@%
- int count;%@NL@%
- %@NL@%
- %@AB@%/* Display each command-line argument. */%@AE@%%@NL@%
- printf( "\nCommand-line arguments:\n" );%@NL@%
- for( count = 0; count < argc; count++ )%@NL@%
- printf( " argv[%d] %s\n", count, argv[count] );%@NL@%
- %@NL@%
- %@AB@%/* Display each environment variable. */%@AE@%%@NL@%
- printf( "\nEnvironment variables:\n" );%@NL@%
- while( *envp != NULL )%@NL@%
- printf( " %s\n", *(envp++) );%@NL@%
- %@NL@%
- %@AB@%/* If run from DOS, shows different ID for DOS than for DOS shell.%@NL@%
- %@AB@% * If execed or spawned, shows ID of parent.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- printf( "\nProcess id of parent: %d", getpid() );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARGV.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ARGV.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARGV.C: Demonstrate accessing command-line arguments.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void show_args( char *argument );%@NL@%
- %@NL@%
- int main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count=0; count < argc; count++ )%@NL@%
- show_args( argv[count] );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- void show_args( char *argument )%@NL@%
- {%@NL@%
- printf( "%s\n", argument );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARGV1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ARGV1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARGV1.C: Demonstrate null pointers. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void show_args( char *argument );%@NL@%
- %@NL@%
- int main( int argc, char **argv )%@NL@%
- {%@NL@%
- while( *argv )%@NL@%
- show_args( *(argv++) );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- void show_args( char *argument )%@NL@%
- {%@NL@%
- printf( "%s\n", argument );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ARRAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ARRAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ARRAY.C: Demonstrate arrays. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int j, k;%@NL@%
- static int i_array[2][3] = { { 12, 2, 444 }, { 6, 55, 777 } };%@NL@%
- static char c_array[] = "Hello";%@NL@%
- %@NL@%
- printf( "--- Values -------- --- Addresses -------\n\n" );%@NL@%
- %@NL@%
- for( j = 0; j < 2; j = j + 1 )%@NL@%
- {%@NL@%
- for( k = 0; k < 3; k = k + 1 )%@NL@%
- {%@NL@%
- printf( "i_array[%d][%d] = %d", j, k, i_array[j][k] );%@NL@%
- printf( "\t&i_array[%d][%d] = %u\n", j, k, &i_array[j][k] );%@NL@%
- }%@NL@%
- printf( "\n" );%@NL@%
- }%@NL@%
- %@NL@%
- for( j = 0; j < 6; j = j + 1 )%@NL@%
- {%@NL@%
- printf( "c_array[%d] = %x %c", j, c_array[j], c_array[j] );%@NL@%
- printf( "\t&c_array[%d] = %u\n", j, &c_array[j] );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ASSERT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ASSERT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ASSERT.C illustrates function:%@NL@%
- %@AB@% * assert%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<assert.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXSTR 120 %@NL@%
- %@NL@%
- void chkstr( char *string ); %@AB@%/* Prototype */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char string1[MAXSTR], string2[MAXSTR];%@NL@%
- %@NL@%
- %@AB@%/* Do various processes on strings and check the results. If%@NL@%
- %@AB@% * none cause errors, force on error with empty string.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- printf( "Enter a string: " );%@NL@%
- gets( string1 );%@NL@%
- chkstr( string1 );%@NL@%
- %@NL@%
- printf( "Enter another string: " );%@NL@%
- gets( string2 );%@NL@%
- chkstr( string2 );%@NL@%
- %@NL@%
- strcat( string1, string2 );%@NL@%
- chkstr( string1 );%@NL@%
- printf( "string1 + string2 = %s\n", string1 );%@NL@%
- %@NL@%
- chkstr( "" );%@NL@%
- printf( "You'll never get here\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void chkstr( char *string )%@NL@%
- {%@NL@%
- assert( string != NULL ); %@AB@%/* Cannot be NULL */%@AE@%%@NL@%
- assert( *string != '\0' ); %@AB@%/* Cannot be empty */%@AE@%%@NL@%
- assert( strlen( string ) < MAXSTR ); %@AB@%/* Length must be positive */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ATEXIT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ATEXIT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ATEXIT.C illustrates:%@NL@%
- %@AB@% * atexit onexit%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- ANSI %@AB@%/* Comment out to try onexit */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Prototypes */%@AE@%%@NL@%
- void fn1( void ), fn2( void ), fn3( void ), fn4( void );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@NL@%
- %@AB@%/* atexit is ANSI standard. It returns 0 for success, nonzero%@NL@%
- %@AB@% * for fail.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#ifdef %@AE@%ANSI %@NL@%
- atexit( fn1 );%@NL@%
- atexit( fn2 );%@NL@%
- atexit( fn3 );%@NL@%
- atexit( fn4 );%@NL@%
- %@NL@%
- %@AB@%/* onexit is Microsoft extension. It returns pointer to function%@NL@%
- %@AB@% * for success, NULL for fail.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#else %@AE@%%@NL@%
- onexit( fn1 );%@NL@%
- onexit( fn2 );%@NL@%
- onexit( fn3 );%@NL@%
- onexit( fn4 );%@NL@%
- %@AI@%#endif %@AE@%%@NL@%
- %@NL@%
- printf( "This is executed first.\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void fn1()%@NL@%
- {%@NL@%
- printf( "next.\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void fn2()%@NL@%
- {%@NL@%
- printf( "executed " );%@NL@%
- }%@NL@%
- %@NL@%
- void fn3()%@NL@%
- {%@NL@%
- printf( "is " );%@NL@%
- }%@NL@%
- %@NL@%
- void fn4()%@NL@%
- {%@NL@%
- printf( "This " );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ATONUM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ATONUM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ATONUM.C illustrates string to number conversion functions including:%@NL@%
- %@AB@% * atof atoi atol gcvt%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * It also illustrates:%@NL@%
- %@AB@% * cgets cputs%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXSTR 100 %@NL@%
- %@NL@%
- char cnumbuf[MAXSTR] = { MAXSTR + 2, 0 };%@NL@%
- numbuf cnumbuf + 2 %@AB@%/* Actual buffer starts at byte 3 */%@AE@%%@NL@%
- char tmpbuf[MAXSTR];%@NL@%
- %@NL@%
- %@AB@%/* Numeric input and output without printf. */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- int integer;%@NL@%
- long longint;%@NL@%
- float real;%@NL@%
- %@NL@%
- %@AB@%/* Using cgets (rather than gets) allows use of DOS editing keys%@NL@%
- %@AB@% * (or of editing keys from DOS command line editors).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cputs( "Enter an integer: " );%@NL@%
- cgets( cnumbuf );%@NL@%
- cputs( "\n\r" ); %@AB@%/* cputs doesn't translate \n */%@AE@%%@NL@%
- integer = atoi( numbuf );%@NL@%
- strcpy( tmpbuf, numbuf );%@NL@%
- strcat( tmpbuf, " + " );%@NL@%
- %@NL@%
- cputs( "Enter a long integer: " );%@NL@%
- cgets( cnumbuf );%@NL@%
- cputs( "\n\r" );%@NL@%
- longint = atol( numbuf );%@NL@%
- strcat( tmpbuf, numbuf );%@NL@%
- strcat( tmpbuf, " + " );%@NL@%
- %@NL@%
- cputs( "Enter a floating point number: " );%@NL@%
- cgets( cnumbuf );%@NL@%
- cputs( "\n\r" );%@NL@%
- real = atof( numbuf );%@NL@%
- strcat( tmpbuf, numbuf );%@NL@%
- strcat( tmpbuf, " = " );%@NL@%
- %@NL@%
- gcvt( integer + longint + real, 4, numbuf );%@NL@%
- strcat( tmpbuf, numbuf );%@NL@%
- strcat( tmpbuf, "\n\r" );%@NL@%
- %@NL@%
- cputs( tmpbuf );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BADSEMI.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\BADSEMI.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BADSEMI.C: Misplaced semicolon. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count = 0; count < 500; count++ ); %@AB@%/* Error! */%@AE@%%@NL@%
- {%@NL@%
- printf( "count = %d\n", count );%@NL@%
- printf( "And the beat goes on...\n" );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BADSEMI1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\BADSEMI1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BADSEMI1.C: Misplaced semicolon. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count = 0; count < 500; count++ )%@NL@%
- ; %@AB@%/* Null statement */%@AE@%%@NL@%
- {%@NL@%
- printf( "count = %d\n", count );%@NL@%
- printf( "And the beat goes on...\n" );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BEEP.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\UTILITY\BEEP.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BEEP.C illustrates timing and port input and output functions%@NL@%
- %@AB@% * including:%@NL@%
- %@AB@% * inp outp clock%@NL@%
- %@AB@% * Also keyword:%@NL@%
- %@AB@% * enum%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * In addition to the delay use shown here, clock can be used as a%@NL@%
- %@AB@% * timer as shown in SIEVE.C.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- void beep( unsigned duration, unsigned frequency );%@NL@%
- void delay( clock_t wait );%@NL@%
- %@NL@%
- %@NL@%
- enum notes%@NL@%
- { %@AB@%/* Enumeration of notes and frequencies */%@AE@%%@NL@%
- C0 = 262, D0 = 296, E0 = 330, F0 = 349, G0 = 392, A0 = 440, B0 = 494,%@NL@%
- C1 = 523, D1 = 587, E1 = 659, F1 = 698, G1 = 784, A1 = 880, B1 = 988,%@NL@%
- EIGHTH = 125, QUARTER = 250, HALF = 500, WHOLE = 1000, END = 0%@NL@%
- } song[] =%@NL@%
- { %@AB@%/* Array initialized to notes of song */%@AE@%%@NL@%
- C1, HALF, G0, HALF, A0, HALF, E0, HALF, F0, HALF, E0, QUARTER,%@NL@%
- D0, QUARTER, C0, WHOLE, END%@NL@%
- };%@NL@%
- %@NL@%
- int main ()%@NL@%
- {%@NL@%
- int note = 0;%@NL@%
- %@NL@%
- while( song[note] )%@NL@%
- beep( song[note++], song[note++] );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* beep - sounds the speaker for a time specified in microseconds by%@NL@%
- %@AB@% * duration at a pitch specified in hertz by frequency.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void beep( unsigned duration, unsigned frequency )%@NL@%
- {%@NL@%
- int control;%@NL@%
- %@NL@%
- %@AB@%/* If frequency is 0, beep doesn't try to make a sound. It%@NL@%
- %@AB@% * just sleeps for the duration.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if (frequency)%@NL@%
- {%@NL@%
- %@AB@%/* 75 is the shortest reliable duration of a sound. */%@AE@%%@NL@%
- if( duration < 75 )%@NL@%
- duration = 75;%@NL@%
- %@NL@%
- %@AB@%/* Prepare timer by sending 10111100 to port 43. */%@AE@%%@NL@%
- outp( 0x43, 0xb6 );%@NL@%
- %@NL@%
- %@AB@%/* Divide input frequency by timer ticks per second and%@NL@%
- %@AB@% * write (byte by byte) to timer.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- frequency = (unsigned)(1193180L / frequency);%@NL@%
- outp( 0x42, (char)frequency );%@NL@%
- outp( 0x42, (char)(frequency >> 8) );%@NL@%
- %@NL@%
- %@AB@%/* Save speaker control byte. */%@AE@%%@NL@%
- control = inp( 0x61 );%@NL@%
- %@NL@%
- %@AB@%/* Turn on the speaker (with bits 0 and 1). */%@AE@%%@NL@%
- outp( 0x61, control | 0x3 );%@NL@%
- }%@NL@%
- %@NL@%
- delay( (clock_t)duration );%@NL@%
- %@NL@%
- %@AB@%/* Turn speaker back on if necessary. */%@AE@%%@NL@%
- if( frequency )%@NL@%
- outp( 0x61, control );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* delay - Pauses for a specified number of microseconds. */%@AE@%%@NL@%
- void delay( clock_t wait )%@NL@%
- {%@NL@%
- clock_t goal;%@NL@%
- %@NL@%
- goal = wait + clock();%@NL@%
- while( goal > clock() )%@NL@%
- ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BESSEL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\BESSEL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BESSEL.C illustrates Bessel functions including:%@NL@%
- %@AB@% * j0 j1 jn y0 y1 yn%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- double x = 2.387;%@NL@%
- int n = 3, c;%@NL@%
- %@NL@%
- printf( "Bessel functions for x = %f:\n", x );%@NL@%
- printf( " Kind\t\tOrder\t\Function\tResult\n\n" );%@NL@%
- printf( " First\t\t0\tj0( x )\t\t%f\n", j0( x ) );%@NL@%
- printf( " First\t\t1\tj1( x )\t\t%f\n", j1( x ) );%@NL@%
- for( c = 2; c < 10; c++ )%@NL@%
- printf( " First\t\t%d\tjn( n, x )\t%f\n", c, jn( c, x ) );%@NL@%
- %@NL@%
- printf( " Second\t0\ty0( x )\t\t%f\n", y0( x ) );%@NL@%
- printf( " Second\t1\ty1( x )\t\t%f\n", y1( x ) );%@NL@%
- for( c = 2; c < 10; c++ )%@NL@%
- printf( " Second\t%d\tyn( n, x )\t%f\n", c, yn( c, x ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BINTEXT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\BINTEXT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BINTEXT.C illustrates changing between binary and text modes for%@NL@%
- %@AB@% * stream I/O using function:%@NL@%
- %@AB@% * setmode%@NL@%
- %@AB@% * and global variable:%@NL@%
- %@AB@% * _fmode%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- <stdlib.h> %@AB@%/* For _fmode and exit */%@AE@%%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *htmp;%@NL@%
- char name[13];%@NL@%
- %@NL@%
- %@AB@%/* Set default mode to binary and open file. */%@AE@%%@NL@%
- _fmode = O_BINARY;%@NL@%
- if( (htmp = fopen( tmpnam( name ), "w+" )) == NULL )%@NL@%
- exit( 1 );%@NL@%
- fprintf( htmp, "\nThis\nis\nsome\nbinary\ntext.\n\n" );%@NL@%
- %@NL@%
- %@AB@%/* Flush buffer and change mode to text. */%@AE@%%@NL@%
- fflush( htmp );%@NL@%
- setmode( fileno( htmp ), O_TEXT );%@NL@%
- fprintf( htmp, "\nThis\nis\nsome\ntext\ntext.\n\n" );%@NL@%
- fclose( htmp );%@NL@%
- %@NL@%
- system( strcat( "TYPE ", name ) );%@NL@%
- remove( name );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BREAKER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\BREAKER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BREAKER.C: Demonstrate break statement. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press any key. Press TAB to quit.\n" );%@NL@%
- while( 1 )%@NL@%
- {%@NL@%
- ch = getche();%@NL@%
- if( ch == '\t' )%@NL@%
- {%@NL@%
- printf( "\a\nYou pressed TAB.\n" );%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BREAKER1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\BREAKER1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BREAKER1.C: Break only exits one loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press any key. Press RETURN to quit.\n" );%@NL@%
- do%@NL@%
- {%@NL@%
- while( ( ch = getche() ) != '\r' )%@NL@%
- {%@NL@%
- if( ch == '\t' )%@NL@%
- {%@NL@%
- printf( "\a\nYou pressed TAB.\n" );%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- } while( ch != '\r' );%@NL@%
- printf( "\nBye bye." );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%BUFTEST.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\BUFTEST.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* BUFTEST.C illustrates buffer control for stream I/O using functions:%@NL@%
- %@AB@% * setbuf setvbuf%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#define %@AE@%BUF2SIZ 2048 %@NL@%
- %@NL@%
- long countln( FILE *stream ); %@AB@%/* Prototype */%@AE@%%@NL@%
- char buf1[BUFSIZ], buf2[BUF2SIZ]; %@AB@%/* File buffers */%@AE@%%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- time_t start;%@NL@%
- FILE *stream;%@NL@%
- int c;%@NL@%
- %@NL@%
- %@AB@%/* Use our buffer with the default size. This gives us the option%@NL@%
- %@AB@% * of examining and/or modifying the buffer during I/0 (though the%@NL@%
- %@AB@% * example doesn't illustrate this).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( (stream = fopen( argv[1], "rt" )) == NULL )%@NL@%
- exit( 1 );%@NL@%
- setbuf( stream, buf1 );%@NL@%
- start = clock();%@NL@%
- c = countln( stream );%@NL@%
- printf( "Time: %5.2f\tBuffering: Normal\tBuffer size: %d\n",%@NL@%
- ((float)clock() - start) / CLK_TCK, BUFSIZ );%@NL@%
- %@NL@%
- %@AB@%/* Use a larger buffer. */%@AE@%%@NL@%
- if( (stream = fopen( argv[1], "rt" )) == NULL )%@NL@%
- exit( 1 );%@NL@%
- setvbuf( stream, buf2, _IOFBF, sizeof( buf2 ) );%@NL@%
- start = clock();%@NL@%
- c = countln( stream );%@NL@%
- printf( "Time: %5.2f\tBuffering: Normal\tBuffer size: %d\n",%@NL@%
- ((float)clock() - start) / CLK_TCK, BUF2SIZ );%@NL@%
- %@NL@%
- %@AB@%/* Try it with no buffering. */%@AE@%%@NL@%
- if( (stream = fopen( argv[1], "rt" )) == NULL )%@NL@%
- exit( 1 );%@NL@%
- setvbuf( stream, NULL, _IONBF, 0 );%@NL@%
- start = clock();%@NL@%
- c = countln( stream );%@NL@%
- printf( "Time: %5.2f\tBuffering: Normal\tBuffer size: %d\n",%@NL@%
- ((float)clock() - start) / CLK_TCK, 0 );%@NL@%
- %@NL@%
- printf( "File %s has %d lines", argv[1], c );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Count lines in text files and close file. */%@AE@%%@NL@%
- long countln( FILE *stream )%@NL@%
- {%@NL@%
- char linebuf[120];%@NL@%
- long c = 0;%@NL@%
- %@NL@%
- while( !feof( stream ) )%@NL@%
- {%@NL@%
- fgets( linebuf, 121, stream );%@NL@%
- ++c;%@NL@%
- }%@NL@%
- fclose( stream );%@NL@%
- return c;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CABS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MATH\CABS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CABS.C illustrates functions:%@NL@%
- %@AB@% * cabs hypot%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static struct complex ne = { 3.0, 4.0 }, se = { -3.0, -4.0 },%@NL@%
- sw = { -3.0, -4.0 }, nw = { -3.0, 4.0 };%@NL@%
- %@NL@%
- printf( "Absolute %4.1lf + %4.1lfi:\t\t%4.1f\n",%@NL@%
- ne.x, ne.y, cabs( ne ) );%@NL@%
- printf( "Absolute %4.1lf + %4.1lfi:\t\t%4.1f\n",%@NL@%
- sw.x, sw.y, cabs( sw ) );%@NL@%
- %@NL@%
- printf( "Hypotenuse of %4.1lf and %4.1lf:\t%4.1f\n",%@NL@%
- se.x, se.y, hypot( se.x, se.y ) );%@NL@%
- printf( "Hypotenuse of %4.1lf and %4.1lf:\t%4.1f\n",%@NL@%
- nw.x, nw.y, hypot( nw.x, nw.y ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CASE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\CASE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CASE.C illustrates case conversion and other conversions.%@NL@%
- %@AB@% * Functions illustrated include:%@NL@%
- %@AB@% * strupr toupper _toupper%@NL@%
- %@AB@% * strlwr tolower _tolower%@NL@%
- %@AB@% * strrev toascii%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@NL@%
- char mstring[] = "Dog Saw Dad Live On";%@NL@%
- char *ustring, *tstring, *estring;%@NL@%
- char *p;%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "Original:\t%s\n", mstring );%@NL@%
- %@NL@%
- %@AB@%/* Upper and lower case. */%@AE@%%@NL@%
- ustring = strupr( strdup( mstring ) );%@NL@%
- printf( "Upper case:\t%s\n", ustring );%@NL@%
- %@NL@%
- printf( "Lower case:\t%s\n", strlwr( ustring ) );%@NL@%
- %@NL@%
- %@AB@%/* Reverse case of each character. */%@AE@%%@NL@%
- tstring = strdup( mstring );%@NL@%
- for( p = tstring; *p; p++ )%@NL@%
- {%@NL@%
- if( isupper( *p ) )%@NL@%
- *p = tolower( *p );%@NL@%
- else%@NL@%
- *p = toupper( *p );%@NL@%
- %@NL@%
- %@AB@%/* This alternate code (commented out) shows how to use _tolower%@NL@%
- %@AB@% * and _toupper for the same purpose.%@NL@%
- %@AB@% if( isupper( *p ) )%@NL@%
- %@AB@% *p = _tolower( *p );%@NL@%
- %@AB@% else if( islower( *p ) )%@NL@%
- %@AB@% *p = _toupper( *p );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- }%@NL@%
- printf( "Toggle case:\t%s\n", tstring );%@NL@%
- %@NL@%
- %@AB@%/* Encode and decode string. The decoding technique will convert%@NL@%
- %@AB@% * WordStar-style strings, which have some high bits set.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- estring = strdup( mstring );%@NL@%
- for( p = estring; *p; p++ )%@NL@%
- *p = *p | 0x80;%@NL@%
- printf( "Encoded:\t%s\n", estring );%@NL@%
- %@NL@%
- for( p = estring; *p; p++ )%@NL@%
- *p = toascii( *p );%@NL@%
- printf( "Decoded:\t%s\n", estring );%@NL@%
- %@NL@%
- printf( "Reversed:\t%s\n", strrev( ustring ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CGA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\CGA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CGA.C: Demonstrates CGA colors */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- long bkcolor[8] = %@NL@%
- {_BLACK, _BLUE, _GREEN, _CYAN,%@NL@%
- _RED, _MAGENTA, _BROWN, _WHITE};%@NL@%
- %@NL@%
- char *bkcolor_name [] =%@NL@%
- {"_BLACK", "_BLUE", "_GREEN", "_CYAN",%@NL@%
- "_RED", "_MAGENTA", "_BROWN", "_WHITE"};%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i, j, k;%@NL@%
- _setvideomode( _MRES4COLOR );%@NL@%
- for( i=0; i<= 3; i++ )%@NL@%
- {%@NL@%
- _selectpalette( i );%@NL@%
- for( k=0; k <= 7; k++ )%@NL@%
- {%@NL@%
- _setbkcolor( bkcolor[k] );%@NL@%
- for( j=0; j<=3; j++ )%@NL@%
- {%@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "background color: %8s\n", bkcolor_name[k] );%@NL@%
- printf( "palette: %d\ncolor: %d\n", i, j );%@NL@%
- _setcolor( j );%@NL@%
- _rectangle( _GFILLINTERIOR, 160, 100, 320, 200 );%@NL@%
- getch();%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CGAPAL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\CGAPAL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CGAPAL.C illustrates CGA palettes using:%@NL@%
- %@AB@% * _selectpalette%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- long bkcolor[8] = { _BLACK, _BLUE, _GREEN, _CYAN,%@NL@%
- _RED, _MAGENTA, _BROWN, _WHITE };%@NL@%
- char *bkname [] = { "BLACK", "BLUE", "GREEN", "CYAN",%@NL@%
- "RED", "MAGENTA", "BROWN", "WHITE" };%@NL@%
- main()%@NL@%
- {%@NL@%
- int i, j, k;%@NL@%
- %@NL@%
- if ( !_setvideomode( _MRES4COLOR ) )%@NL@%
- exit( 1 );%@NL@%
- for( i = 0; i < 4; i++ )%@NL@%
- {%@NL@%
- _selectpalette( i );%@NL@%
- for( k = 0; k < 8; k++ )%@NL@%
- {%@NL@%
- _setbkcolor( bkcolor[k] );%@NL@%
- for( j = 0; j < 4; j++ )%@NL@%
- {%@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Background color: %8s\n", bkname[k] );%@NL@%
- printf( "Palette: %d\nColor: %d\n", i, j );%@NL@%
- _setcolor( j );%@NL@%
- _rectangle( _GFILLINTERIOR, 160, 100, 320, 200 );%@NL@%
- getch();%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- exit( !_setvideomode( _DEFAULTMODE ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHMOD1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\CHMOD1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CHMOD1.C illustrates reading and changing file attribute and time using:%@NL@%
- %@AB@% * access chmod utime%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See CHMOD2.C for a more powerful variation of this program using%@NL@%
- %@AB@% * _dos functions.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<sys\utime.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- enum FILEATTRIB { EXIST, WRITE = 2, READ = 4, READWRITE = 6 };%@NL@%
- %@NL@%
- %@AB@%/* Exist macro uses access */%@AE@%%@NL@%
- %@AI@%#define %@AE@%EXIST( name ) !access( name, EXIST ) %@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- if( !EXIST( argv[1] ) )%@NL@%
- {%@NL@%
- printf( "Syntax: CHMOD1 <filename>" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- if( !access( argv[1], WRITE ) )%@NL@%
- {%@NL@%
- printf( "File %s is read/write. Change to read only? ", argv[1] );%@NL@%
- %@NL@%
- %@AB@%/* Note: Use stdlib.h for function definition of toupper rather%@NL@%
- %@AB@% * than macro version in ctype.h. Macro side effects would cause%@NL@%
- %@AB@% * macro version to read two keys.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( toupper( getch() ) == 'Y' )%@NL@%
- chmod( argv[1], S_IREAD );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( "File %s is read only. Change to read/write? ", argv[1] );%@NL@%
- if( toupper( getch() ) == 'Y' )%@NL@%
- chmod( argv[1], S_IREAD | S_IWRITE );%@NL@%
- }%@NL@%
- %@NL@%
- printf( "\nUpdate file time to current time? " );%@NL@%
- if( toupper( getch() ) == 'Y' )%@NL@%
- utime( argv[1], NULL );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CHMOD2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\CHMOD2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CHMOD2.C illustrates reading and changing file attributes and file%@NL@%
- %@AB@% * time using:%@NL@%
- %@AB@% * _dos_getftime _dos_setftime%@NL@%
- %@AB@% * _dos_getfileattr _dos_setfileattr%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See CHMOD1.C for a simpler variation of this program using the utime,%@NL@%
- %@AB@% * access, and chmod functions.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@NL@%
- char *datestr( unsigned d, char *buf ); %@AB@%/* Prototypes */%@AE@%%@NL@%
- char *timestr( unsigned t, char *buf );%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- unsigned fdate, ftime, fattr;%@NL@%
- struct dosdate_t ddate;%@NL@%
- struct dostime_t dtime;%@NL@%
- int hsource;%@NL@%
- char timebuf[10], datebuf[10], *pkind;%@NL@%
- %@NL@%
- %@AB@%/* Open to get file handle and test for errors (such as nonexistence). */%@AE@%%@NL@%
- if( _dos_open( argv[1], O_RDONLY, &hsource ) )%@NL@%
- {%@NL@%
- printf( "Can't open file\n" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Get time, date, and attribute of file. */%@AE@%%@NL@%
- _dos_getftime( hsource, &fdate, &ftime );%@NL@%
- _dos_getfileattr( argv[1], &fattr );%@NL@%
- %@NL@%
- %@AB@%/* Convert information into formatted strings. */%@AE@%%@NL@%
- datestr( fdate, datebuf );%@NL@%
- timestr( ftime, timebuf );%@NL@%
- %@NL@%
- if( fattr & _A_SUBDIR )%@NL@%
- pkind = "Directory";%@NL@%
- else if( fattr & _A_VOLID )%@NL@%
- pkind = "Label";%@NL@%
- else%@NL@%
- pkind = "File";%@NL@%
- %@NL@%
- printf( "%-12s %-8s %-9s %-9s %s %s %s\n",%@NL@%
- "FILE", "TIME", "DATE", "KIND", "RDO", "HID", "SYS" );%@NL@%
- printf( "%-12s %8s %8s %-9s %c %c %c\n",%@NL@%
- argv[1], timebuf, datebuf, pkind,%@NL@%
- (fattr & _A_RDONLY) ? 'Y' : 'N',%@NL@%
- (fattr & _A_HIDDEN) ? 'Y' : 'N',%@NL@%
- (fattr & _A_SYSTEM) ? 'Y' : 'N' );%@NL@%
- %@NL@%
- %@AB@%/* Update file time or attribute. */%@AE@%%@NL@%
- printf( "Change: (T)ime (R)ead only (H)idden (S)ystem\n" );%@NL@%
- switch( toupper( getch() ) ) %@AB@%/* Use stdlib.h, not ctype.h */%@AE@%%@NL@%
- {%@NL@%
- case 'T': %@AB@%/* Set to current time */%@AE@%%@NL@%
- _dos_gettime( &dtime );%@NL@%
- _dos_getdate( &ddate );%@NL@%
- ftime = (dtime.hour << 11) | (dtime.minute << 5);%@NL@%
- fdate = ((ddate.year - 1980) << 9) | (ddate.month << 5) |%@NL@%
- ddate.day;%@NL@%
- _dos_setftime( hsource, fdate, ftime );%@NL@%
- break;%@NL@%
- case 'R': %@AB@%/* Toggle read only */%@AE@%%@NL@%
- _dos_setfileattr( argv[1], fattr ^ _A_RDONLY );%@NL@%
- break;%@NL@%
- case 'H': %@AB@%/* Toggle hidden */%@AE@%%@NL@%
- _dos_setfileattr( argv[1], fattr ^ _A_HIDDEN );%@NL@%
- break;%@NL@%
- case 'S': %@AB@%/* Toggle system */%@AE@%%@NL@%
- _dos_setfileattr( argv[1], fattr ^ _A_SYSTEM );%@NL@%
- break;%@NL@%
- }%@NL@%
- _dos_close( hsource );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Take unsigned time in the format: fedcba9876543210%@NL@%
- %@AB@% * s=2 sec incr, m=0-59, h=23 hhhhhmmmmmmsssss%@NL@%
- %@AB@% * Change to a 9-byte string (ignore seconds): hh:mm ?m%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *timestr( unsigned t, char *buf )%@NL@%
- {%@NL@%
- int h = (t >> 11) & 0x1f, m = (t >> 5) & 0x3f;%@NL@%
- %@NL@%
- sprintf( buf, "%2.2d:%02.2d %cm", h % 12, m, h > 11 ? 'p' : 'a' );%@NL@%
- return buf;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Take unsigned date in the format: fedcba9876543210%@NL@%
- %@AB@% * d=1-31, m=1-12, y=0-119 (1980-2099) yyyyyyymmmmddddd%@NL@%
- %@AB@% * Change to a 9-byte string: mm/dd/yy%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *datestr( unsigned d, char *buf )%@NL@%
- {%@NL@%
- sprintf( buf, "%2.2d/%02.2d/%02.2d",%@NL@%
- (d >> 5) & 0x0f, d & 0x1f, (d >> 9) + 80 );%@NL@%
- return buf;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CMPSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\CMPSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CMPSTR.C illustrates string and memory comparison functions including:%@NL@%
- %@AB@% * memcmp memicmp%@NL@%
- %@AB@% * strncmp strnicmp%@NL@%
- %@AB@% * strcmp stricmp strcmpi%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- char string1[] = "The quick brown dog jumps over the lazy fox";%@NL@%
- char string2[] = "The QUICK brown fox jumps over the lazy dog";%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char tmp[20];%@NL@%
- int result;%@NL@%
- %@NL@%
- printf( "Compare strings:\n\t\t%s\n\t\t%s\n\n", string1, string2 );%@NL@%
- %@NL@%
- printf( "Function:\tmemcmp\n" );%@NL@%
- result = memcmp( string1, string2 , 42 );%@NL@%
- if( result > 0 )%@NL@%
- strcpy( tmp, "greater than" );%@NL@%
- else if( result < 0 )%@NL@%
- strcpy( tmp, "less than" );%@NL@%
- else%@NL@%
- strcpy( tmp, "equal to" );%@NL@%
- printf( "Result:\t\tString 1 is %s than string 2\n\n", tmp );%@NL@%
- %@NL@%
- printf( "Function:\tmemicmp\n" );%@NL@%
- result = memicmp( string1, string2, 42 );%@NL@%
- if( result > 0 )%@NL@%
- strcpy( tmp, "greater than" );%@NL@%
- else if( result < 0 )%@NL@%
- strcpy( tmp, "less than" );%@NL@%
- else%@NL@%
- strcpy( tmp, "equal to" );%@NL@%
- printf( "Result:\t\tString 1 is %s than string 2\n\n", tmp );%@NL@%
- %@NL@%
- printf( "Function:\tstrncmp\n" );%@NL@%
- result = strncmp( string1, string2 , 42 );%@NL@%
- if( result > 0 )%@NL@%
- strcpy( tmp, "greater than" );%@NL@%
- else if( result < 0 )%@NL@%
- strcpy( tmp, "less than" );%@NL@%
- else%@NL@%
- strcpy( tmp, "equal to" );%@NL@%
- printf( "Result:\t\tString 1 is %s than string 2\n\n", tmp );%@NL@%
- %@NL@%
- printf( "Function:\tstrnicmp\n" );%@NL@%
- result = strnicmp( string1, string2, 42 );%@NL@%
- if( result > 0 )%@NL@%
- strcpy( tmp, "greater than" );%@NL@%
- else if( result < 0 )%@NL@%
- strcpy( tmp, "less than" );%@NL@%
- else%@NL@%
- strcpy( tmp, "equal to" );%@NL@%
- printf( "Result:\t\tString 1 is %s than string 2\n\n", tmp );%@NL@%
- %@NL@%
- printf( "Function:\tstrcmp\n" );%@NL@%
- result = strcmp( string1, string2 );%@NL@%
- if( result > 0 )%@NL@%
- strcpy( tmp, "greater than" );%@NL@%
- else if( result < 0 )%@NL@%
- strcpy( tmp, "less than" );%@NL@%
- else%@NL@%
- strcpy( tmp, "equal to" );%@NL@%
- printf( "Result:\t\tString 1 is %s than string 2\n\n", tmp );%@NL@%
- %@NL@%
- printf( "Function:\tstricmp or strcmpi\n" );%@NL@%
- result = stricmp( string1, string2 );%@NL@%
- %@AB@%/* strcmpi (commented out) is the same as stricmp.%@NL@%
- %@AB@% result = strcmpi( string1, string2 );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( result > 0 )%@NL@%
- strcpy( tmp, "greater than" );%@NL@%
- else if( result < 0 )%@NL@%
- strcpy( tmp, "less than" );%@NL@%
- else%@NL@%
- strcpy( tmp, "equal to" );%@NL@%
- printf( "Result:\t\tString 1 is %s than string 2\n", tmp );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COLOR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\COLOR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COLOR.C: Sets a medium resolution mode with maximum color choices */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- struct videoconfig vc;%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- if( _setvideomode( _MRES256COLOR ) )%@NL@%
- ;%@NL@%
- else if( _setvideomode( _MRES16COLOR ) )%@NL@%
- ;%@NL@%
- else if( _setvideomode( _MRES4COLOR ) )%@NL@%
- ;%@NL@%
- else {%@NL@%
- printf( "Error: No color graphics capability\n" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- _getvideoconfig( &vc );%@NL@%
- %@NL@%
- printf( "%d available colors\n", vc.numcolors );%@NL@%
- printf( "%d horizontal pixels\n", vc.numxpixels );%@NL@%
- printf( "%d vertical pixels\n", vc.numypixels );%@NL@%
- %@NL@%
- getch();%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COLTEXT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\COLTEXT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COLTEXT.C: Displays text in color */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- char buffer [80];%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int blink,fgd;%@NL@%
- long bgd;%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- printf( "Text color attributes:\n" );%@NL@%
- %@NL@%
- for( blink=0; blink<=16; blink+=16 ) %@NL@%
- {%@NL@%
- for( bgd=0; bgd<8; bgd++ ) %@NL@%
- {%@NL@%
- _setbkcolor( bgd );%@NL@%
- _settextposition( bgd + ((blink / 16) * 9) + 3, 1 );%@NL@%
- _settextcolor( 7 );%@NL@%
- sprintf( buffer, "Bgd: %d Fgd:", bgd );%@NL@%
- _outtext( buffer );%@NL@%
- %@NL@%
- for( fgd=0; fgd<16; fgd++ ) %@NL@%
- {%@NL@%
- _settextcolor( fgd+blink );%@NL@%
- sprintf( buffer, " %2d ", fgd+blink );%@NL@%
- _outtext( buffer );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\COM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COM.C illustrates serial port access using function:%@NL@%
- %@AB@% * _bios_serialcom%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned status, port;%@NL@%
- %@NL@%
- for( port = 0; port < 3; port++ )%@NL@%
- {%@NL@%
- status = _bios_serialcom( _COM_STATUS, port, 0 );%@NL@%
- %@NL@%
- %@AB@%/* Report status of each serial port and test whether there is a%@NL@%
- %@AB@% * modem for each. If data-set-ready and clear-to-send, modem exists.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- printf( "COM%c status: %.4X\tModem: %s\n",%@NL@%
- (char)port + '1', status,%@NL@%
- (status & 0x0030) ? "YES" : "NO" );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COMMA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\COMMA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COMMA.C: Demonstrate comma operator. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 5, val1 = 666, temp;%@NL@%
- temp = val, val = val1, val1 = temp;%@NL@%
- printf( "val = %d val1 = %d\n", val, val1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\CONT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CONT.C: Demonstrate continue statement. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count = 0; count < 10; count++ )%@NL@%
- {%@NL@%
- if( count > 3 )%@NL@%
- continue;%@NL@%
- printf( "count = %d\n", count );%@NL@%
- }%@NL@%
- printf( "Done!\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONT1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\CONT1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CONT1.C: Demonstrate alternative to continue. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count = 0; count < 10; count++ )%@NL@%
- {%@NL@%
- if( count < 4 )%@NL@%
- printf( "count = %d\n", count );%@NL@%
- }%@NL@%
- printf( "Done!\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CONVERT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\CONVERT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CONVERT.C: Demonstrate type conversions. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char c_val = 10;%@NL@%
- int i_val = 20;%@NL@%
- long l_val = 64000;%@NL@%
- float f_val = 3.1;%@NL@%
- int result;%@NL@%
- %@NL@%
- result = c_val + i_val + l_val + f_val; %@AB@%/* Error! */%@AE@%%@NL@%
- %@NL@%
- printf( "%d\n", result );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COPROC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MATH\COPROC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COPROC.C illustrates use of the status and control words of a floating%@NL@%
- %@AB@% * point coprocessor (or emulator). Functions illustrated include:%@NL@%
- %@AB@% * _clear87 _status87 _control87%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<float.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- double dx = 1e-40, dy;%@NL@%
- float fx, fy;%@NL@%
- unsigned status, control;%@NL@%
- char tmpstr[20];%@NL@%
- char *binstr( int num, char *buffer );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- printf( "Status Word Key:\n" );%@NL@%
- printf( "B\tBusy flag\n0-3\tCondition codes\nS\tStack top pointer\n" );%@NL@%
- printf( "E\tError summary\nF\tStack flag\nP\tPrecision exception\n" );%@NL@%
- printf( "U\tUnderflow exception\nO\tOverflow exception\n" );%@NL@%
- printf( "Z\tZero divide exception\nD\tDenormalized exception\n" );%@NL@%
- printf( "I\tInvalid operation exception\n\n" );%@NL@%
- %@NL@%
- binstr( _clear87(), tmpstr );%@NL@%
- printf( "B3SSS210EFPUOZDI Function\tCondition\n\n" );%@NL@%
- printf( "%16s _clear87\tAfter clearing\n", tmpstr );%@NL@%
- %@NL@%
- %@AB@%/* Storing double to float that hasn't enough precision for it%@NL@%
- %@AB@% * causes underflow and precision exceptions.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fx = dx;%@NL@%
- binstr( _status87(), tmpstr );%@NL@%
- printf( "%16s _status87\tAfter moving double to float\n", tmpstr );%@NL@%
- %@NL@%
- %@AB@%/* Storing float with lost precision back to double adds denormalized%@NL@%
- %@AB@% * exception (previous exceptions remain).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- dy = fx;%@NL@%
- binstr( _clear87(), tmpstr );%@NL@%
- printf( "%16s _clear87\tAfter moving float to double\n", tmpstr );%@NL@%
- %@NL@%
- %@AB@%/* Using clear87() erases previous exceptions. */%@AE@%%@NL@%
- fy = dy;%@NL@%
- binstr( _status87(), tmpstr );%@NL@%
- printf( "%16s _status87\tAfter moving double to float\n\n", tmpstr );%@NL@%
- %@NL@%
- getch();%@NL@%
- printf( "Control Word Key:\n" );%@NL@%
- printf( "i\tInfinity control\nr\tRounding control\n" );%@NL@%
- printf( "p\tPrecision control\ne\tInterrupt enable mask\n" );%@NL@%
- printf( "U\tUnderflow mask\nO\tOverflow mask\n" );%@NL@%
- printf( "Z\tZero divide mask\nD\tDenormalized mask\n" );%@NL@%
- printf( "I\tInvalid operation mask\n\n" );%@NL@%
- printf( "???irrppe?PUOZDI Result\n" );%@NL@%
- fy = .1;%@NL@%
- %@NL@%
- %@AB@%/* Show current control word. */%@AE@%%@NL@%
- binstr( _control87( 0, 0 ), tmpstr );%@NL@%
- printf( "%16s %.1f * %.1f = %.15e with initial precision\n",%@NL@%
- tmpstr, fy, fy, fy * fy );%@NL@%
- %@NL@%
- %@AB@%/* Set precision to 24 bits. */%@AE@%%@NL@%
- binstr( _control87( PC_24, MCW_PC ), tmpstr );%@NL@%
- printf( "%16s %.1f * %.1f = %.15e with 24 bit precision\n",%@NL@%
- tmpstr, fy, fy, fy * fy );%@NL@%
- %@NL@%
- %@AB@%/* Restore default. */%@AE@%%@NL@%
- binstr( _control87( CW_DEFAULT, 0xffff ), tmpstr );%@NL@%
- printf( "%16s %.1f * %.1f = %.15e with default precision\n",%@NL@%
- tmpstr, fy, fy, fy * fy );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Convert integer to string of 16 binary characters. */%@AE@%%@NL@%
- char *binstr( int num, char *buffer )%@NL@%
- {%@NL@%
- char tmp[17];%@NL@%
- int len;%@NL@%
- %@NL@%
- memset( buffer, '0', 16 );%@NL@%
- len = strlen( itoa( num, tmp, 2 ) );%@NL@%
- strcpy( buffer + 16 - len, tmp );%@NL@%
- return buffer;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%COPY2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\COPY2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* COPY2.C illustrates DOS file I/O and DOS memory allocation functions%@NL@%
- %@AB@% * including:%@NL@%
- %@AB@% * _dos_open _dos_close _dos_creatnew _dos_creat%@NL@%
- %@AB@% * _dos_read _dos_write _dos_allocmem _dos_free%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See COPY1.C for another version of the copyfile function.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int copyfile( char *source, char *destin ); %@AB@%/* Prototype */%@AE@%%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- if( argc == 3 )%@NL@%
- if( copyfile( argv[1], argv[2] ) )%@NL@%
- printf( "Copy failed\n" );%@NL@%
- else%@NL@%
- printf( "Copy successful\n" );%@NL@%
- else%@NL@%
- printf( " SYNTAX: COPY2 <source> <target>\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Function to copy one file to another (both specified by path).%@NL@%
- %@AB@% * Dynamically allocates memory for the file buffer. Prompts before%@NL@%
- %@AB@% * overwriting existing file. Returns 0 if successful, or an error%@NL@%
- %@AB@% * number if unsuccessful. This function uses dos functions only; no%@NL@%
- %@AB@% * standard C library functions are used.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@AI@%#define %@AE@%EXIST 80 %@NL@%
- enum ATTRIB { NORMAL, RDONLY, HIDDEN, SYSTEM = 4 };%@NL@%
- int copyfile( char *source, char *target )%@NL@%
- {%@NL@%
- char far *buf = NULL;%@NL@%
- static char prompt[] = "Target exists. Overwrite? ", newline[] = "\n\r";%@NL@%
- int hsource, htarget, ch;%@NL@%
- unsigned ret, segbuf, count;%@NL@%
- %@NL@%
- %@AB@%/* Attempt to dynamically allocate all of memory (0xffff paragraphs).%@NL@%
- %@AB@% * This will fail, but will return the amount actually available%@NL@%
- %@AB@% * in segbuf. Then allocate this amount.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _dos_allocmem( 0xffff, &segbuf );%@NL@%
- count = segbuf;%@NL@%
- if( ret = _dos_allocmem( count, &segbuf ) )%@NL@%
- return ret;%@NL@%
- FP_SEG( buf ) = segbuf;%@NL@%
- %@NL@%
- %@AB@%/* Open source file and create target, overwriting if necessary. */%@AE@%%@NL@%
- if( ret = _dos_open( source, O_RDONLY, &hsource ) )%@NL@%
- return ret;%@NL@%
- ret = _dos_creatnew( target, NORMAL, &htarget );%@NL@%
- if( ret == EXIST )%@NL@%
- {%@NL@%
- %@AB@%/* Use _dos_write to display prompts. Use bdos to call%@NL@%
- %@AB@% * function 1 to get and echo keystroke.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _dos_write( 1, prompt, sizeof( prompt ) - 1, &ch );%@NL@%
- ch = bdos( 1, 0, 0 ) & 0x00ff;%@NL@%
- if( (ch == 'y') || (ch == 'Y') )%@NL@%
- ret = _dos_creat( target, NORMAL, &htarget );%@NL@%
- _dos_write( 1, newline, sizeof( newline ) - 1, &ch );%@NL@%
- }%@NL@%
- if( ret )%@NL@%
- return ret;%@NL@%
- %@NL@%
- %@AB@%/* Read and write until there is nothing left. */%@AE@%%@NL@%
- while( count )%@NL@%
- {%@NL@%
- %@AB@%/* Read and write input. */%@AE@%%@NL@%
- if( (ret = _dos_read( hsource, buf, count, &count )) )%@NL@%
- return ret;%@NL@%
- if( (ret = _dos_write( htarget, buf, count, &count )) )%@NL@%
- return ret;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Close files and free memory. */%@AE@%%@NL@%
- _dos_close( hsource );%@NL@%
- _dos_close( htarget );%@NL@%
- _dos_freemem( segbuf );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%CPYSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\CPYSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* CPYSTR.C illustrate memory and string copy and move functions including:%@NL@%
- %@AB@% * memccpy memcpy memmove%@NL@%
- %@AB@% * strncpy strcpy strdup strlen%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@NL@%
- char string1[60] = "The quick brown dog jumps over the lazy fox";%@NL@%
- char string2[60] = "The quick brown fox jumps over the lazy dog";%@NL@%
- %@AB@%/* 1 2 3 4 5 *%@NL@%
- %@AB@% * 12345678901234567890123456789012345678901234567890 */%@AE@%%@NL@%
- main()%@NL@%
- {%@NL@%
- char buffer[61];%@NL@%
- char *pdest, *newstring;%@NL@%
- int pos;%@NL@%
- %@NL@%
- printf( "Function:\tmemccpy 60 characters or to character 's'\n" );%@NL@%
- printf( "Source:\t\t%s\n", string1 );%@NL@%
- pdest = memccpy( buffer, string1, 's', 60 );%@NL@%
- *pdest = '\0';%@NL@%
- printf( "Result:\t\t%s\n", buffer );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( buffer ) );%@NL@%
- %@NL@%
- pos = pdest - buffer;%@NL@%
- printf( "Function:\tstrcpy\n" );%@NL@%
- printf( "Source:\t\t%s\n", string2 + pos );%@NL@%
- pdest = strcpy( buffer + pos, string2 + pos );%@NL@%
- printf( "Result:\t\t%s\n", buffer );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( buffer ) );%@NL@%
- %@NL@%
- printf( "Function:\tmemcpy 20 characters\n" );%@NL@%
- printf( "Source:\t\t%s\n", string2 );%@NL@%
- memcpy( buffer, string2, 20 );%@NL@%
- printf( "Result:\t\t%s\n", buffer );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( buffer ) );%@NL@%
- %@NL@%
- printf( "Function:\tstrncpy 30 characters\n" );%@NL@%
- printf( "Source:\t\t%s\n", string1 + 20 );%@NL@%
- pdest = strncpy( buffer + 20, string1 + 20, 30 );%@NL@%
- printf( "Result:\t\t%s\n", buffer );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( buffer ) );%@NL@%
- %@NL@%
- getch();%@NL@%
- %@NL@%
- printf( "Function:\tstrdup\n" );%@NL@%
- printf( "Source:\t\t%s\n", buffer );%@NL@%
- newstring = strdup( buffer );%@NL@%
- printf( "Result:\t\t%s\n", newstring );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( newstring ) );%@NL@%
- %@NL@%
- %@AB@%/* Illustrate overlapping copy: memmove handles it correctly;%@NL@%
- %@AB@% * memcpy does not.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- printf( "Function:\tmemcpy with overlap\n" );%@NL@%
- printf( "Source:\t\t%s\n", string1 + 4 );%@NL@%
- printf( "Destination:\t%s\n", string1 + 10 );%@NL@%
- memcpy( string1 + 10, string1 + 4, 40 );%@NL@%
- printf( "Result:\t\t%s\n", string1 );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );%@NL@%
- %@NL@%
- printf( "Function:\tmemmove with overlap\n" );%@NL@%
- printf( "Source:\t\t%s\n", string2 + 4 );%@NL@%
- printf( "Destination:\t%s\n", string2 + 10 );%@NL@%
- memmove( string2 + 10, string2 + 4, 40 );%@NL@%
- printf( "Result:\t\t%s\n", string2 );%@NL@%
- printf( "Length:\t\t%d characters\n\n", strlen( string2 ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DECRMENT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\DECRMENT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DECRMENT.C: Demonstrate prefix and postfix operators.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- main()%@NL@%
- {%@NL@%
- int val, sample = 3, proton = 3;%@NL@%
- val = sample--;%@NL@%
- printf( "val = %d sample = %d\n", val, sample );%@NL@%
- val = --proton;%@NL@%
- printf( "val = %d proton = %d\n", val, proton );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DIRECT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\DIRECT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DIRECT.C illustrates directory functions and miscellaneous file%@NL@%
- %@AB@% * and other functions including:%@NL@%
- %@AB@% * getcwd mkdir chdir rmdir%@NL@%
- %@AB@% * system mktemp remove unlink%@NL@%
- %@AB@% * stat%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See NULLFILE.C for an example of fstat, which is similar to stat.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<sys/types.h> %@NL@%
- %@AI@%#include %@AE@%<sys/stat.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char cwd[_MAX_DIR];%@NL@%
- static char tmpdir[] = "DRXXXXXX";%@NL@%
- struct stat filestat;%@NL@%
- %@NL@%
- %@AB@%/* Get the current working directory. */%@AE@%%@NL@%
- getcwd( cwd, _MAX_DIR );%@NL@%
- %@NL@%
- %@AB@%/* Try to make temporary name for directory. */%@AE@%%@NL@%
- if( mktemp( tmpdir ) == NULL )%@NL@%
- {%@NL@%
- perror( "Can't make temporary directory" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Try to create a new directory, and if successful, change to it. */%@AE@%%@NL@%
- if( !mkdir( tmpdir ) )%@NL@%
- {%@NL@%
- chdir( tmpdir );%@NL@%
- %@NL@%
- %@AB@%/* Create and display a file to prove it. */%@AE@%%@NL@%
- system( "echo This is a test. > TEST.TXT" );%@NL@%
- system( "type test.txt" );%@NL@%
- %@NL@%
- %@AB@%/* Display some file statistics. */%@AE@%%@NL@%
- if( !stat( "TEST.TXT", &filestat ) )%@NL@%
- {%@NL@%
- printf( "File: TEST.TXT\n" );%@NL@%
- printf( "Drive %c:\n", filestat.st_dev + 'A' );%@NL@%
- printf( "Directory: %s\\%s\n", cwd + 2, tmpdir );%@NL@%
- printf( "Size: %ld\n", filestat.st_size );%@NL@%
- printf( "Created: %s", ctime( &filestat.st_atime ) );%@NL@%
- }%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* Delete file, go back to original directory, and remove%@NL@%
- %@AB@% * directory. Note that under DOS, remove is equivalent to unlink,%@NL@%
- %@AB@% * so this line could be used instead.%@NL@%
- %@AB@% unlink( "TEST.TXT" );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- remove( "TEST.TXT" );%@NL@%
- chdir( cwd );%@NL@%
- rmdir( tmpdir );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DISK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\DISK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DISK.C illustrates low-level disk access using functions:%@NL@%
- %@AB@% * _bios_disk _dos_getdiskfree%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- char far diskbuf[512];%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- unsigned status = 0, i;%@NL@%
- struct diskinfo_t di;%@NL@%
- struct diskfree_t df;%@NL@%
- unsigned char far *p, linebuf[17];%@NL@%
- %@NL@%
- if( argc != 5 )%@NL@%
- {%@NL@%
- printf( " SYNTAX: DISK <driveletter> <head> <track> <sector>" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- if( (di.drive = toupper( argv[1][0] ) - 'A' ) > 1 )%@NL@%
- {%@NL@%
- printf( "Must be floppy drive" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- di.head = atoi( argv[2] );%@NL@%
- di.track = atoi( argv[3] );%@NL@%
- di.sector = atoi( argv[4] );%@NL@%
- di.nsectors = 1;%@NL@%
- di.buffer = diskbuf;%@NL@%
- %@NL@%
- %@AB@%/* Get information about disk size. */%@AE@%%@NL@%
- if( _dos_getdiskfree( di.drive + 1, &df ) )%@NL@%
- exit( 1 );%@NL@%
- %@NL@%
- %@AB@%/* Try reading disk three times before giving up. */%@AE@%%@NL@%
- for( i = 0; i < 3; i++ )%@NL@%
- {%@NL@%
- status = _bios_disk( _DISK_READ, &di ) >> 8;%@NL@%
- if( !status )%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Display one sector. */%@AE@%%@NL@%
- if( status )%@NL@%
- printf( "Error: 0x%.2x\n", status );%@NL@%
- else%@NL@%
- {%@NL@%
- for( p = diskbuf, i = 0; p < (diskbuf + df.bytes_per_sector); p++ )%@NL@%
- {%@NL@%
- linebuf[i++] = (*p > 32) ? *p : '.';%@NL@%
- printf( "%.2x ", *p );%@NL@%
- if( i == 16 )%@NL@%
- {%@NL@%
- linebuf[i] = '\0';%@NL@%
- printf( " %16s\n", linebuf );%@NL@%
- i = 0;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\DO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DO.C: Demonstrate do loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int test = 10;%@NL@%
- do%@NL@%
- {%@NL@%
- printf( "test = %d\n", test );%@NL@%
- test -= 2;%@NL@%
- } while( test > 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%DOSMEM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MEMORY\DOSMEM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* DOSMEM.C illustrates functions:%@NL@%
- %@AB@% * _dos_allocmem _dos_setblock _dos_freemem%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See COPY2.C for another example of _dos_allocmem and _dos_freemem.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char far *buf = NULL, far *p;%@NL@%
- unsigned segbuf, maxbuf, size = 512;%@NL@%
- %@NL@%
- %@AB@%/* Allocate 512-byte buffer. Convert the size to paragraphs).%@NL@%
- %@AB@% * Assign the segment to the buffer. Fill with A's.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( _dos_allocmem( size >> 4, &segbuf ) )%@NL@%
- exit( 1 );%@NL@%
- FP_SEG( buf ) = segbuf;%@NL@%
- for( p = buf; p < (buf + size); p++ )%@NL@%
- *p = 'A';%@NL@%
- %@NL@%
- %@AB@%/* Double the allocation. Fill the second half with B's. */%@AE@%%@NL@%
- size *= 2;%@NL@%
- if( _dos_setblock( size >> 4, segbuf, &maxbuf ) )%@NL@%
- exit( 1 );%@NL@%
- FP_SEG( buf ) = segbuf;%@NL@%
- for( p = buf + (size / 2); p < (buf + size); p++ )%@NL@%
- *p = 'B';%@NL@%
- *(--p) = '\0';%@NL@%
- %@NL@%
- printf( "Memory available: %u paragraphs\n", maxbuf );%@NL@%
- printf( "Buffer at %Fp contains:\n%Fs", (int far *)buf, buf );%@NL@%
- %@NL@%
- %@AB@%/* Free memory */%@AE@%%@NL@%
- exit( !_dos_freemem( segbuf ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EGA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\EGA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EGA.C: Demonstrates EGA palettes */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- _setvideomode( _ERESCOLOR );%@NL@%
- _setcolor( 4 );%@NL@%
- _rectangle( _GFILLINTERIOR, 50, 50, 200, 200 );%@NL@%
- %@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Normal palette\n" );%@NL@%
- printf( "Press a key" );%@NL@%
- getch();%@NL@%
- %@NL@%
- _remappalette( 4, _BLUE );%@NL@%
- %@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Remapped palette\n" );%@NL@%
- printf( "Press a key" );%@NL@%
- getch();%@NL@%
- %@NL@%
- _remappalette( 4, _RED );%@NL@%
- %@NL@%
- _settextposition( 1, 1 );%@NL@%
- printf( "Restored palette\n" );%@NL@%
- printf( "Press a key to clear the screen" );%@NL@%
- getch();%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ELSE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ELSE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ELSE.C: Demonstrate else clause. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@% B_KEY 'b' %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getch();%@NL@%
- if( ch == B_KEY )%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- else%@NL@%
- printf( "Bye bye.\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ELSE1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ELSE1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ELSE1.C: Demonstrate else-if construct. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@% B_KEY 'b' %@NL@%
- %@AI@%#define %@AE@% ENTER_KEY '\r' %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getch();%@NL@%
- if( ch == B_KEY )%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- else%@NL@%
- if( ch == ENTER_KEY )%@NL@%
- printf( "What a boring selection...\n" );%@NL@%
- else%@NL@%
- printf( "Bye bye.\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EMPLOY1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\EMPLOY1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EMPLOY1.C: Demonstrate structure pointers. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@NL@%
- struct employee%@NL@%
- {%@NL@%
- char name[10];%@NL@%
- int months;%@NL@%
- float wage;%@NL@%
- };%@NL@%
- %@NL@%
- void display( struct employee *e_ptr );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static struct employee jones =%@NL@%
- {%@NL@%
- "Jones, J",%@NL@%
- 77,%@NL@%
- 13.68%@NL@%
- };%@NL@%
- %@NL@%
- display( &jones );%@NL@%
- }%@NL@%
- %@NL@%
- void display( struct employee *e_ptr )%@NL@%
- {%@NL@%
- printf( "Name: %s\n", e_ptr->name );%@NL@%
- printf( "Months of service: %d\n", e_ptr->months );%@NL@%
- printf( "Hourly wage: %6.2f\n", e_ptr->wage );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EMPLOYEE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\EMPLOYEE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EMPLOYEE.C: Demonstrate structures. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- struct employee%@NL@%
- {%@NL@%
- char name[10];%@NL@%
- int months;%@NL@%
- float wage;%@NL@%
- };%@NL@%
- %@NL@%
- void display( struct employee show );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- struct employee jones;%@NL@%
- %@NL@%
- strcpy( jones.name, "Jones, J" );%@NL@%
- jones.months = 77;%@NL@%
- jones.wage = 13.68;%@NL@%
- %@NL@%
- display( jones );%@NL@%
- }%@NL@%
- %@NL@%
- void display( struct employee show )%@NL@%
- {%@NL@%
- printf( "Name: %s\n", show.name );%@NL@%
- printf( "Months of service: %d\n", show.months );%@NL@%
- printf( "Hourly wage: %6.2f\n", show.wage );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ENVIRON1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\ENVIRON1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ENVIRON.C illustrates environment variable functions including:%@NL@%
- %@AB@% * getenv putenv _searchenv%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *pathvar, pathbuf[128], filebuf[128];%@NL@%
- %@NL@%
- %@AB@%/* Get the PATH environment variable and save a copy of it. */%@AE@%%@NL@%
- pathvar = getenv( "PATH" );%@NL@%
- strcpy( pathbuf, pathvar );%@NL@%
- printf( "Old PATH: %s\n", pathvar ? pathvar : "variable not set");%@NL@%
- %@NL@%
- %@AB@%/* Add a new directory to the path. */%@AE@%%@NL@%
- strcat( pathbuf, ";\\QC;" );%@NL@%
- if( putenv( pathbuf ) == -1 )%@NL@%
- {%@NL@%
- printf( "Failed\n");%@NL@%
- return 1;%@NL@%
- }%@NL@%
- else%@NL@%
- printf( "New PATH: %s\n", pathbuf );%@NL@%
- %@NL@%
- %@AB@%/* Search for file in the new path. */%@AE@%%@NL@%
- _searchenv( "QC.INI", "PATH", filebuf );%@NL@%
- if( *filebuf )%@NL@%
- printf( "QC.INI found at %s\n", filebuf );%@NL@%
- else%@NL@%
- printf( "QC.INI not found\n" );%@NL@%
- %@NL@%
- %@AB@%/* Restore original path. */%@AE@%%@NL@%
- if( putenv( pathvar ) == -1 )%@NL@%
- printf( "Failed\n");%@NL@%
- else%@NL@%
- printf( "Old PATH: %s\n", pathvar );%@NL@%
- return 0;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%ERROR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\ERROR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* ERROR.C illustrates stream file error handling. Functions illustrated%@NL@%
- %@AB@% * include:%@NL@%
- %@AB@% * ferror clearerr exit _exit%@NL@%
- %@AB@% * perror strerror _strerror%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The _exit routine is not specifically illustrated, but it is the same%@NL@%
- %@AB@% * as exit except that file buffers are not flushed and atexit and onexit%@NL@%
- %@AB@% * are not called.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<errno.h> %@NL@%
- enum BOOL { FALSE, TRUE };%@NL@%
- %@NL@%
- FILE *stream;%@NL@%
- char string[] = "This should never be written";%@NL@%
- void errortest( FILE *stream, char *msg, int fterm );%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- %@AB@%/* Open file and test to see if open caused error. If so, terminate. */%@AE@%%@NL@%
- stream = fopen( argv[1], "r" );%@NL@%
- errortest( stream, "Can't open file", TRUE );%@NL@%
- %@NL@%
- %@AB@%/* Try to write to a read-only file, then test to see if write%@NL@%
- %@AB@% * caused error. If so, clear error, but don't terminate.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fprintf( stream, "%s\n", string );%@NL@%
- errortest( stream, "Can't write file", FALSE );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Error test routine takes a stream, a message, and a flag telling whether%@NL@%
- %@AB@% * to terminate if there is an error.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void errortest( FILE *stream, char *msg, int fterm )%@NL@%
- {%@NL@%
- %@AB@%/* If stream doesn't exist (failed fopen) or if there is an error%@NL@%
- %@AB@% * on the stream, handle error.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( (stream == NULL) || (ferror( stream )) )%@NL@%
- {%@NL@%
- perror( msg );%@NL@%
- %@AB@%/* _strerror and strerror can be used to get the same result%@NL@%
- %@AB@% * as perror, as illustrated by these lines (commented out).%@NL@%
- %@AB@% printf( "%s: %s\n", msg, strerror( errno ) );%@NL@%
- %@AB@% printf( _strerror( msg ) );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Terminate or clear error, depending on terminate flag. */%@AE@%%@NL@%
- if( fterm )%@NL@%
- exit( errno );%@NL@%
- else%@NL@%
- clearerr( stream );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EXEC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\EXEC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EXEC.C illustrates the different versions of exec including:%@NL@%
- %@AB@% * execl execle execlp execlpe%@NL@%
- %@AB@% * execv execve execvp execvpe%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Although EXEC.C can exec any program, you can verify how different%@NL@%
- %@AB@% * versions handle arguments and environment by compiling and%@NL@%
- %@AB@% * specifying the sample program ARGS.C. See SPAWN.C for examples%@NL@%
- %@AB@% * of the similar spawn functions.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<process.h> %@NL@%
- %@NL@%
- char *my_env[] = %@AB@%/* Environment for exec?e */%@AE@%%@NL@%
- {%@NL@%
- "THIS=environment will be",%@NL@%
- "PASSED=to child by the",%@NL@%
- "SPAWN=functions",%@NL@%
- NULL%@NL@%
- };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *args[4], prog[80];%@NL@%
- int ch;%@NL@%
- %@NL@%
- printf( "Enter name of program to exec: " );%@NL@%
- gets( prog );%@NL@%
- printf( " 1. execl 2. execle 3. execlp 4. execlpe\n" );%@NL@%
- printf( " 5. execv 6. execve 7. execvp 8. execvpe\n" );%@NL@%
- printf( "Type a number from 1 to 8 (or 0 to quit): " );%@NL@%
- ch = getche();%@NL@%
- if( (ch < '1') || (ch > '8') )%@NL@%
- exit( 1 );%@NL@%
- printf( "\n\n" );%@NL@%
- %@NL@%
- %@AB@%/* Arguments for execv? */%@AE@%%@NL@%
- args[0] = prog; %@AB@%/* First argument ignored under most */%@AE@%%@NL@%
- args[1] = "exec??"; %@AB@%/* recent versions of DOS */%@AE@%%@NL@%
- args[2] = "two";%@NL@%
- args[3] = NULL;%@NL@%
- %@NL@%
- switch( ch )%@NL@%
- {%@NL@%
- case '1':%@NL@%
- execl( prog, prog, "execl", "two", NULL );%@NL@%
- break;%@NL@%
- case '2':%@NL@%
- execle( prog, prog, "execle", "two", NULL, my_env );%@NL@%
- break;%@NL@%
- case '3':%@NL@%
- execlp( prog, prog, "execlp", "two", NULL );%@NL@%
- break;%@NL@%
- case '4':%@NL@%
- execlpe( prog, prog, "execlpe", "two", NULL, my_env );%@NL@%
- break;%@NL@%
- case '5':%@NL@%
- execv( prog, args );%@NL@%
- break;%@NL@%
- case '6':%@NL@%
- execve( prog, args, my_env );%@NL@%
- break;%@NL@%
- case '7':%@NL@%
- execvp( prog, args );%@NL@%
- break;%@NL@%
- case '8':%@NL@%
- execvpe( prog, args, my_env );%@NL@%
- break;%@NL@%
- default:%@NL@%
- break;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* This point is only reached if exec fails. */%@AE@%%@NL@%
- printf( "\nProcess was not execed." );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EXTDIR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\EXTDIR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EXTDIR.C illustrates wild card handling using functions:%@NL@%
- %@AB@% * _dos_findfirst _dos_findnext sprintf%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\utime.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@NL@%
- long fileinfo( struct find_t *find ); %@AB@%/* Prototypes */%@AE@%%@NL@%
- char *timestr( unsigned d, char *buf );%@NL@%
- char *datestr( unsigned d, char *buf );%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- struct find_t find;%@NL@%
- long size;%@NL@%
- %@NL@%
- %@AB@%/* Find first matching file, then find additional matches. */%@AE@%%@NL@%
- if( !_dos_findfirst( argv[1], 0xffff, &find ) )%@NL@%
- {%@NL@%
- printf( "%-12s %-8s %-8s %-8s %-9s %s %s %s %s\n",%@NL@%
- "FILE", "SIZE", "TIME", "DATE", "KIND",%@NL@%
- "RDO", "HID", "SYS", "ARC" );%@NL@%
- size = fileinfo( &find );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( " SYNTAX: TOUCH <wildfilespec>" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- while( !_dos_findnext( &find ) )%@NL@%
- size += fileinfo( &find );%@NL@%
- printf( "%-12s %8ld\n\n", "Total", size );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- long fileinfo( struct find_t *pfind )%@NL@%
- {%@NL@%
- char timebuf[10], datebuf[10], *pkind;%@NL@%
- %@NL@%
- datestr( pfind->wr_date, datebuf );%@NL@%
- timestr( pfind->wr_time, timebuf );%@NL@%
- %@NL@%
- if( pfind->attrib & _A_SUBDIR )%@NL@%
- pkind = "Directory";%@NL@%
- else if( pfind->attrib & _A_VOLID )%@NL@%
- pkind = "Label";%@NL@%
- else%@NL@%
- pkind = "File";%@NL@%
- %@NL@%
- printf( "%-12s %8ld %8s %8s %-9s %c %c %c %c\n",%@NL@%
- pfind->name, pfind->size, timebuf, datebuf, pkind,%@NL@%
- (pfind->attrib & _A_RDONLY) ? 'Y' : 'N',%@NL@%
- (pfind->attrib & _A_HIDDEN) ? 'Y' : 'N',%@NL@%
- (pfind->attrib & _A_SYSTEM) ? 'Y' : 'N',%@NL@%
- (pfind->attrib & _A_ARCH) ? 'Y' : 'N' );%@NL@%
- return pfind->size;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Take unsigned time in the format: fedcba9876543210%@NL@%
- %@AB@% * s=2 sec incr, m=0-59, h=23 hhhhhmmmmmmsssss%@NL@%
- %@AB@% * Change to a 9-byte string (ignore seconds): hh:mm ?m%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *timestr( unsigned t, char *buf )%@NL@%
- {%@NL@%
- int h = (t >> 11) & 0x1f, m = (t >> 5) & 0x3f;%@NL@%
- %@NL@%
- sprintf( buf, "%2.2d:%02.2d %cm", h % 12, m, h > 11 ? 'p' : 'a' );%@NL@%
- return buf;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Take unsigned date in the format: fedcba9876543210%@NL@%
- %@AB@% * d=1-31, m=1-12, y=0-119 (1980-2099) yyyyyyymmmmddddd%@NL@%
- %@AB@% * Change to a 9-byte string: mm/dd/yy%@NL@%
- %@AB@% */%@AE@%%@NL@%
- char *datestr( unsigned d, char *buf )%@NL@%
- {%@NL@%
- sprintf( buf, "%2.2d/%02.2d/%02.2d",%@NL@%
- (d >> 5) & 0x0f, d & 0x1f, (d >> 9) + 80 );%@NL@%
- return buf;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%EXTERR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\EXTERR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* EXTERR.C illustrates function:%@NL@%
- %@AB@% * dosexterr%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- void errorinfo( void ); %@AB@%/* Prototype */%@AE@%%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- int hsource;%@NL@%
- %@NL@%
- %@AB@%/* Open to get file handle and test for errors. Try specifying%@NL@%
- %@AB@% * invalid files to show different errors.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( _dos_open( argv[1], O_RDWR, &hsource ) )%@NL@%
- errorinfo();%@NL@%
- printf( "No error\n" );%@NL@%
- _dos_close( hsource );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- void errorinfo()%@NL@%
- {%@NL@%
- struct DOSERROR err;%@NL@%
- static char *eclass[] =%@NL@%
- {%@NL@%
- "", "Out of Resource", "Temporary Situation", "Authorization",%@NL@%
- "Internal", "Hardware Failure", "System Failure", "Application Error",%@NL@%
- "Not Found", "Bad Format", "Locked", "Media", "Already Exists",%@NL@%
- "Unknown"%@NL@%
- };%@NL@%
- static char *eaction[] =%@NL@%
- {%@NL@%
- "", "Retry", "Delay Retry", "User", "Abort", "Immediate Exit",%@NL@%
- "Ignore", "Retry After User Intervention"%@NL@%
- };%@NL@%
- static char *elocus[] =%@NL@%
- {%@NL@%
- "", "Unknown", "Block Device", "Net", "Serial Device", "Memory"%@NL@%
- };%@NL@%
- %@NL@%
- %@NL@%
- %@AB@%/* Get error information and display class, action, and locus. */%@AE@%%@NL@%
- dosexterr( &err );%@NL@%
- printf( "Class:\t%s\nAction:\t%s\nLocus:\t%s\nAction\t",%@NL@%
- eclass[err.class], eaction[err.action], elocus[err.locus] );%@NL@%
- %@NL@%
- %@AB@%/* Errors that could be caused by sample _dos_open. You can expand%@NL@%
- %@AB@% * this list to handle others.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- switch( err.exterror )%@NL@%
- {%@NL@%
- case 2:%@NL@%
- printf( "File not found\n" );%@NL@%
- break;%@NL@%
- case 3:%@NL@%
- printf( "Path not found\n" );%@NL@%
- break;%@NL@%
- case 5:%@NL@%
- printf( "Access denied\n" );%@NL@%
- break;%@NL@%
- }%@NL@%
- exit( err.exterror );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FACTOR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FACTOR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FACTOR.C: Demonstrate functions.%@NL@%
- %@AB@% * NOTE: a value > 16 will overflow a long integer.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- long factor( int param );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int num;%@NL@%
- long result;%@NL@%
- %@AB@%/* Display a prompt */%@AE@%%@NL@%
- printf( "Type a number: " );%@NL@%
- %@AB@%/* Input a numeric value, assign to num */%@AE@%%@NL@%
- scanf( "%d", &num );%@NL@%
- result = factor( num );%@NL@%
- printf( "Factorial of %d is %ld\n", num, result );%@NL@%
- }%@NL@%
- %@NL@%
- long factor( int param )%@NL@%
- {%@NL@%
- long value = 1;%@NL@%
- while( param > 1 )%@NL@%
- {%@NL@%
- value = value * param;%@NL@%
- param = param - 1;%@NL@%
- }%@NL@%
- return value;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FCVT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FCVT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FCVT.C illustrates floating point to string conversion functions:%@NL@%
- %@AB@% * gcvt ecvt fcvt%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See MKFPSTR.C for an example of using the data returned by fcvt%@NL@%
- %@AB@% * to build a formatted string. See ATONUM.C for an example of using%@NL@%
- %@AB@% * the string returned by gcvt.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int decimal, sign;%@NL@%
- char *pnumstr;%@NL@%
- int precision = 7;%@NL@%
- char numbuf[50];%@NL@%
- double number1, number2;%@NL@%
- %@NL@%
- printf( "Enter two floating point numbers: " );%@NL@%
- scanf( "%lf %lf", &number1, &number2 );%@NL@%
- %@NL@%
- %@AB@%/* With gcvt, precision specifies total number of digits.%@NL@%
- %@AB@% * The decimal place and sign are inserted in the string.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- gcvt( number1 + number2, precision, numbuf );%@NL@%
- printf( "\nString produced by gcvt: %s\n", numbuf );%@NL@%
- printf( "Total digits: %d\n", precision );%@NL@%
- %@NL@%
- %@AB@%/* With ecvt, precision specifies total number of digits.%@NL@%
- %@AB@% * The decimal place and sign are provided for use in formatting.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pnumstr = ecvt( number1 + number2, precision, &decimal, &sign );%@NL@%
- printf( "\nString produced by ecvt: %s\nSign: %s\n",%@NL@%
- pnumstr, sign ? "-" : "+" );%@NL@%
- printf( "Digits left of decimal: %d\nTotal digits: %d\n",%@NL@%
- decimal, precision );%@NL@%
- %@NL@%
- %@AB@%/* With fcvt, precision specifies digits after decimal place.%@NL@%
- %@AB@% * The decimal place and sign are provided for use in formatting.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- pnumstr = fcvt( number1 + number2, precision, &decimal, &sign );%@NL@%
- printf( "\nString produced by fcvt: %s\nSign: %s\n",%@NL@%
- pnumstr, sign ? "-" : "+" );%@NL@%
- printf( "Digits left of decimal: %d\nDigits after decimal: %d\n",%@NL@%
- decimal, precision );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FIGURE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\FIGURE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FIGURE.C illustrates graphics drawing functions including:%@NL@%
- %@AB@% * _setpixel _lineto _moveto _rectangle _ellipse%@NL@%
- %@AB@% * _arc _pie%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Window versions of graphics drawing functions (such as _rectangle_w,%@NL@%
- %@AB@% * _ellipse_wxy, and _lineto_w) are illustrated in WINDOW.C and GEDIT.C.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- short x, y;%@NL@%
- short mode = _VRES16COLOR;%@NL@%
- %@NL@%
- while( !_setvideomode( mode ) ) %@AB@%/* Find best graphics mode */%@AE@%%@NL@%
- mode--;%@NL@%
- if( mode == _TEXTMONO )%@NL@%
- exit( 1 ); %@AB@%/* No graphics available */%@AE@%%@NL@%
- %@NL@%
- for( x = 10, y = 50; y < 90; x += 2, y += 3 )%@AB@%/* Draw pixels */%@AE@%%@NL@%
- _setpixel( x, y );%@NL@%
- getch();%@NL@%
- %@NL@%
- for( x = 60, y = 50; y < 90; y += 3 ) %@AB@%/* Draw lines */%@AE@%%@NL@%
- {%@NL@%
- _moveto( x, y );%@NL@%
- _lineto( x + 20, y );%@NL@%
- }%@NL@%
- getch();%@NL@%
- %@NL@%
- x = 110; y = 70; %@AB@%/* Draw rectangles */%@AE@%%@NL@%
- _rectangle( _GBORDER, x - 20, y - 20, x, y );%@NL@%
- _rectangle( _GFILLINTERIOR, x + 20, y + 20, x, y );%@NL@%
- getch();%@NL@%
- %@NL@%
- x = 160; %@AB@%/* Draw ellipses */%@AE@%%@NL@%
- _ellipse( _GBORDER, x - 20, y - 20, x, y );%@NL@%
- _ellipse( _GFILLINTERIOR, x + 20, y + 20, x, y );%@NL@%
- getch();%@NL@%
- %@NL@%
- x = 210; %@AB@%/* Draw arcs */%@AE@%%@NL@%
- _arc( x - 20, y - 20, x, y, x, y - 10, x - 10, y );%@NL@%
- _arc( x + 20, y + 20, x, y, x + 10, y + 20, x + 20, y + 10 );%@NL@%
- getch();%@NL@%
- %@NL@%
- x = 260; %@AB@%/* Draw pies */%@AE@%%@NL@%
- _pie( _GBORDER, x - 20, y - 20, x, y, x, y - 10, x - 10, y );%@NL@%
- _pie( _GFILLINTERIOR, x + 20, y + 20, x, y,%@NL@%
- x + 10, y + 20, x + 20, y + 10 );%@NL@%
- getch();%@NL@%
- %@NL@%
- exit( !_setvideomode( _DEFAULTMODE ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FILEONE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FILEONE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FILEONE.C: Visibility in multiple source files.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- int chico = 20, harpo = 30;%@NL@%
- extern void yonder( void );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- yonder();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FILETWO.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FILETWO.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FILETWO.C: Visibility in multiple source files.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void yonder( void )%@NL@%
- {%@NL@%
- extern int chico, harpo;%@NL@%
- printf( "chico = %d, harpo = %d\n", chico, harpo );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FILL.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\FILL.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FILL.C illustrates color, filling, and linestyle functions including:%@NL@%
- %@AB@% * _setlinestyle _setfillmask _setcolor%@NL@%
- %@AB@% * _getlinestyle _floodfill%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The _getfillmask function is not shown, but its use is similar to%@NL@%
- %@AB@% * _getlinestyle.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- short x, y, xinc, yinc, xwid, ywid;%@NL@%
- unsigned char fill[8];%@NL@%
- struct videoconfig vc;%@NL@%
- unsigned seed = (unsigned)time( 0L ); %@AB@%/* Different seed each time */%@AE@%%@NL@%
- short i, color, mode = _VRES16COLOR;%@NL@%
- %@NL@%
- while( !_setvideomode( mode ) ) %@AB@%/* Find best graphics mode */%@AE@%%@NL@%
- mode--;%@NL@%
- if (mode == _TEXTMONO )%@NL@%
- exit( 1 ); %@AB@%/* No graphics available */%@AE@%%@NL@%
- _getvideoconfig( &vc );%@NL@%
- %@NL@%
- xinc = vc.numxpixels / 8; %@AB@%/* Size variables to mode */%@AE@%%@NL@%
- yinc = vc.numxpixels / 8;%@NL@%
- xwid = (xinc / 2) - 4;%@NL@%
- ywid = (yinc / 2) - 4;%@NL@%
- %@NL@%
- %@AB@%/* Draw circles and lines with different patterns. */%@AE@%%@NL@%
- for( x = xinc; x <= (vc.numxpixels - xinc); x += xinc )%@NL@%
- {%@NL@%
- for( y = yinc; y <= (vc.numypixels - yinc); y += yinc )%@NL@%
- {%@NL@%
- %@AB@%/* Vary random seed, randomize fill and color. */%@AE@%%@NL@%
- srand( seed = (seed + 431) * 5 );%@NL@%
- for( i = 0; i < 8; i++ )%@NL@%
- fill[i] = rand();%@NL@%
- _setfillmask( fill );%@NL@%
- color = (rand() % vc.numcolors) + 1;%@NL@%
- _setcolor( color );%@NL@%
- %@NL@%
- %@AB@%/* Draw ellipse and fill with random color. */%@AE@%%@NL@%
- _ellipse( _GBORDER, x - xwid, y - ywid, x + xwid, y + ywid );%@NL@%
- _setcolor( (rand() % vc.numcolors) + 1 );%@NL@%
- _floodfill( x, y, color );%@NL@%
- %@NL@%
- %@AB@%/* Draw vertical and horizontal lines. Vertical line style%@NL@%
- %@AB@% * is opposite of (not) horizontal style. Since lines are%@NL@%
- %@AB@% * overdrawn with several linestyles, this has the effect of%@NL@%
- %@AB@% * combining colors and styles.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _setlinestyle( rand() );%@NL@%
- _moveto( 0, y + ywid + 4 );%@NL@%
- _lineto( vc.numxpixels - 1, y + ywid + 4 );%@NL@%
- _setlinestyle( ~_getlinestyle() );%@NL@%
- _moveto( x + xwid + 4, 0 );%@NL@%
- _lineto( x + xwid + 4, vc.numypixels - 1 );%@NL@%
- }%@NL@%
- }%@NL@%
- getch();%@NL@%
- exit( !_setvideomode( _DEFAULTMODE ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FINDSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FINDSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FINDSTR.C illustrates memory and string search functions including:%@NL@%
- %@AB@% * memchr strchr strrchr strstr%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int ch = 'r';%@NL@%
- char str[] = "lazy";%@NL@%
- char string[] = "The quick brown dog jumps over the lazy fox";%@NL@%
- char fmt1[] = " 1 2 3 4 5";%@NL@%
- char fmt2[] = "12345678901234567890123456789012345678901234567890";%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char *pdest;%@NL@%
- int result;%@NL@%
- %@NL@%
- printf( "String to be searched:\n\t\t%s\n", string );%@NL@%
- printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );%@NL@%
- %@NL@%
- printf( "Function:\tmemchr\n" );%@NL@%
- printf( "Search char:\t%c\n", ch );%@NL@%
- pdest = memchr( string, ch, sizeof( string ) );%@NL@%
- result = pdest - string + 1;%@NL@%
- if( pdest != NULL )%@NL@%
- printf( "Result:\t\t%c found at position %d\n\n", ch, result );%@NL@%
- else%@NL@%
- printf( "Result:\t\t%c not found\n" );%@NL@%
- %@NL@%
- printf( "Function:\tstrchr\n" );%@NL@%
- printf( "Search char:\t%c\n", ch );%@NL@%
- pdest = strchr( string, ch );%@NL@%
- result = pdest - string + 1;%@NL@%
- if( pdest != NULL )%@NL@%
- printf( "Result:\t\t%c found at position %d\n\n", ch, result );%@NL@%
- else%@NL@%
- printf( "Result:\t\t%c not found\n" );%@NL@%
- %@NL@%
- printf( "Function:\tstrrchr\n" );%@NL@%
- printf( "Search char:\t%c\n", ch );%@NL@%
- pdest = strrchr( string, ch );%@NL@%
- result = pdest - string + 1;%@NL@%
- if( pdest != NULL )%@NL@%
- printf( "Result:\t\t%c found at position %d\n\n", ch, result );%@NL@%
- else%@NL@%
- printf( "Result:\t\t%c not found\n" );%@NL@%
- %@NL@%
- printf( "Function:\tstrstr\n" );%@NL@%
- printf( "Search string:\t%s\n", str );%@NL@%
- pdest = strstr( string, str );%@NL@%
- result = pdest - string + 1;%@NL@%
- if( pdest != NULL )%@NL@%
- printf( "Result:\t\t%s found at position %d\n\n", str, result );%@NL@%
- else%@NL@%
- printf( "Result:\t\t%c not found\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FOR1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FOR1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FOR1.C: Demonstrate multiple expressions. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a, b;%@NL@%
- for( a = 256, b = 1; b < 512; a /= 2, b *= 2 )%@NL@%
- printf( "a = %d b = %d\n", a, b );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FOR2.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FOR2.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FOR2.C: Demonstrate variations on for loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- for( printf( "Type something\n" ); getche() != '\r'; )%@NL@%
- ; %@AB@%/* Null statement */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FOR3.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FOR3.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FOR3.C: Demonstrate similarity of for and while.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- %@NL@%
- for( count = 0; count < 10; count++ )%@NL@%
- printf( "count = %d\n", count );%@NL@%
- %@NL@%
- count = 0;%@NL@%
- while( count < 10 )%@NL@%
- {%@NL@%
- printf( "count = %d\n", count );%@NL@%
- count++;%@NL@%
- }%@NL@%
- %@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FOR4.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FOR4.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FOR.C: Demonstrate for loop. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int test;%@NL@%
- for( test = 10; test > 0; test -= 2 )%@NL@%
- printf( "test = %d\n", test );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FREECT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FREECT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FREECT.C illustrates the following heap functions:%@NL@%
- %@AB@% * _freect _memavl%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char near *bufs[64];%@NL@%
- unsigned request, avail, i;%@NL@%
- %@NL@%
- printf( "Near heap bytes free: %u\n\n", _memavl() );%@NL@%
- printf( "How many 1K buffers do you want from the near heap? " );%@NL@%
- scanf( "%d", &request );%@NL@%
- if( request > 64 )%@NL@%
- {%@NL@%
- printf( "There are only 64K in a segment.\n" );%@NL@%
- request = 64;%@NL@%
- }%@NL@%
- %@NL@%
- avail = _freect( 1024 );%@NL@%
- request = (avail > request) ? request : avail;%@NL@%
- printf( "You can have %d buffers\n", request );%@NL@%
- %@NL@%
- printf( "They are available at:\n");%@NL@%
- for( i = 0; i < request; i++ )%@NL@%
- {%@NL@%
- bufs[i] = (char near *)_nmalloc( 1024 );%@NL@%
- printf( "%2d %Fp ", i + 1, (char far *)bufs[i] );%@NL@%
- if( (i % 5) == 4 )%@NL@%
- printf( "\n" );%@NL@%
- }%@NL@%
- printf( "\n\nNear heap bytes free: %u\n\n", _memavl() );%@NL@%
- printf( "Freeing buffers . . ." );%@NL@%
- for( i = request; i; i-- )%@NL@%
- _nfree( bufs[i] );%@NL@%
- printf( "\n\nNear heap bytes free: %u", _memavl() );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FSAMPLER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\FSAMPLER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* SAMPLER.C: Display sample text in various fonts.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%NFONTS 6 %@NL@%
- %@NL@%
- main()%@NL@%
- %@NL@%
- {%@NL@%
- static unsigned char *text[2*NFONTS] =%@NL@%
- {%@NL@%
- "COURIER", "courier",%@NL@%
- "HELV", "helv",%@NL@%
- "TMS RMN", "tms rmn",%@NL@%
- "MODERN", "modern",%@NL@%
- "SCRIPT", "script",%@NL@%
- "ROMAN", "roman"%@NL@%
- };%@NL@%
- static unsigned char *face[NFONTS] =%@NL@%
- {%@NL@%
- "t'courier'",%@NL@%
- "t'helv'",%@NL@%
- "t'tms rmn'"%@NL@%
- "t'modern'"%@NL@%
- "t'script'"%@NL@%
- "t'roman'"%@NL@%
- };%@NL@%
- static unsigned char list[20];%@NL@%
- struct videoconfig vc;%@NL@%
- int mode = _VRES16COLOR;%@NL@%
- register i;%@NL@%
- %@NL@%
- %@AB@%/* Read header info from all .FON files in%@NL@%
- %@AB@% * current directory */%@AE@%%@NL@%
- %@NL@%
- if(_registerfonts( "*.FON" )<0 )%@NL@%
- {%@NL@%
- _outtext("Error: can't register fonts");%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Set highest available video mode */%@AE@%%@NL@%
- %@NL@%
- while( !_setvideomode( mode ) )%@NL@%
- mode--;%@NL@%
- if( mode == _TEXTMONO )%@NL@%
- exit ( 0 );%@NL@%
- %@NL@%
- %@AB@%/* Copy video configuration into structure vc */%@AE@%%@NL@%
- %@NL@%
- _getvideoconfig( &vc );%@NL@%
- %@NL@%
- %@AB@%/* Display six lines of sample text */%@AE@%%@NL@%
- %@NL@%
- for( i = 0; i<NFONTS; i++ )%@NL@%
- {%@NL@%
- strcpy( list, face[i] );%@NL@%
- strcat( list, "h30w24b" );%@NL@%
- %@NL@%
- if( !_setfont( list ) )%@NL@%
- {%@NL@%
- _setcolor( i + 1 );%@NL@%
- _moveto( 0, (i * vc.numypixels) / NFONTS );%@NL@%
- _outgtext( text[i * 2] );%@NL@%
- _moveto( vc.numxpixels / 2,%@NL@%
- (i * vc.numypixels) / NFONTS );%@NL@%
- _outgtext( text[(i * 2) + 1] );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _outtext( "Error: can't set font" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- }%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- %@NL@%
- %@AB@%/* Return memory when finished with fonts */%@AE@%%@NL@%
- %@NL@%
- _unregisterfonts();%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FUNCPTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FUNCPTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FUNCPTR.C: Demonstrate function pointers. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int (*func_ptr) ();%@NL@%
- func_ptr = printf;%@NL@%
- (*func_ptr) ( "Curiouser and curiouser...\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FUNCPTR1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\FUNCPTR1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FUNCPTR1.C: Passing function pointers as arguments.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void gimme_func( void (*func_ptr) () );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- gimme_func( puts );%@NL@%
- gimme_func( printf );%@NL@%
- }%@NL@%
- %@NL@%
- void gimme_func( void (*func_ptr) () )%@NL@%
- {%@NL@%
- (*func_ptr) ( "Ausgezeichnet!" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%FUNGET.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\FUNGET.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* FUNGET.C illustrates getting and ungetting characters from a file.%@NL@%
- %@AB@% * Functions illustrated include:%@NL@%
- %@AB@% * getc getchar ungetc%@NL@%
- %@AB@% * fgetc fgetchar%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Although getchar and fgetchar are not specifically used in the example,%@NL@%
- %@AB@% * they are equivalent to using getc or fgetc with stdin. See HEXDUMP.C%@NL@%
- %@AB@% * for another example of getc and fgetc.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- void getword( FILE *stream, char *buf );%@NL@%
- void skiptoword( FILE *stream );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char buffer[128];%@NL@%
- FILE *infile;%@NL@%
- %@NL@%
- printf( "Enter file name: " );%@NL@%
- gets( buffer );%@NL@%
- if( (infile = fopen( buffer, "rb" )) == NULL )%@NL@%
- {%@NL@%
- perror( "Can't open file" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Read each word and print reversed version. */%@AE@%%@NL@%
- while( 1 )%@NL@%
- {%@NL@%
- skiptoword( infile );%@NL@%
- getword( infile, buffer );%@NL@%
- puts( strrev( buffer ) );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Read one word (defined as a string of alphanumeric characters). */%@AE@%%@NL@%
- void getword( FILE *stream, char *p )%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- %@AB@%/* Macro version used here, but function version could be used:%@NL@%
- %@AB@% ch = fgetc( stream );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- ch = getc( stream ); %@AB@%/* Get characters until EOF */%@AE@%%@NL@%
- if( ch == EOF ) %@AB@%/* or non-alphanumeric */%@AE@%%@NL@%
- exit( 0 );%@NL@%
- *(p++) = (char)ch;%@NL@%
- } while( isalnum( ch ) );%@NL@%
- ungetc( ch, stream ); %@AB@%/* Put non-alphanumeric back */%@AE@%%@NL@%
- *(--p) = '\0'; %@AB@%/* Null-terminate */%@AE@%%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Throw away non-digit characters. */%@AE@%%@NL@%
- void skiptoword( FILE *stream )%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- do%@NL@%
- {%@NL@%
- ch = getc( stream );%@NL@%
- if( ch == EOF )%@NL@%
- exit( 0 );%@NL@%
- } while( !isalnum( ch ) );%@NL@%
- ungetc( ch, stream );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GETCH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\GETCH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GETCH.C illustrates how to process ASCII or extended keys.%@NL@%
- %@AB@% * Functions illustrated include:%@NL@%
- %@AB@% * getch getche%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int key;%@NL@%
- %@NL@%
- %@AB@%/* Read and display keys until ESC is pressed. */%@AE@%%@NL@%
- while( 1 )%@NL@%
- {%@NL@%
- %@AB@%/* If first key is 0, then get second extended. */%@AE@%%@NL@%
- if( !(key = getch()) )%@NL@%
- {%@NL@%
- key = getch();%@NL@%
- printf( "ASCII: no\tChar: NA\t" );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Otherwise there's only one key. */%@AE@%%@NL@%
- else%@NL@%
- printf( "ASCII: yes\tChar: %c \t", isgraph( key ) ? key : ' ' );%@NL@%
- %@NL@%
- printf( "Decimal: %d\tHex: %X\n", key, key );%@NL@%
- %@NL@%
- %@AB@%/* Echo character response to prompt. */%@AE@%%@NL@%
- if( key == 27)%@NL@%
- {%@NL@%
- printf( "Do you really want to quit? (Y/n) " );%@NL@%
- key = getche();%@NL@%
- printf( "\n" );%@NL@%
- if( (toupper( key ) == 'Y') || (key == 13) )%@NL@%
- break;%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GOODMAC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\GOODMAC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GOODMAC.C: Parentheses in macro arguments. */%@AE@%%@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%FOURX(arg) ( (arg) * 4 ) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val;%@NL@%
- val = FOURX( 2 + 3 );%@NL@%
- printf( "val = %d\n", val );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GOODSEMI.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\GOODSEMI.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GOODSEMI.C */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- for( count = 0; count < 500; count++ )%@NL@%
- {%@NL@%
- printf( "count = %d\n", count );%@NL@%
- printf( "And the beat goes on...\n" );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%GRAPHIC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\GRAPHIC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* GRAPHIC.C: Displays every graphics mode */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- struct videoconfig screen;%@NL@%
- int modes[12] =%@NL@%
- {%@NL@%
- _MRES4COLOR, _MRESNOCOLOR, _HRESBW,%@NL@%
- _HERCMONO,%@NL@%
- _MRES16COLOR, _HRES16COLOR, _ERESNOCOLOR, _ERESCOLOR,%@NL@%
- _VRES2COLOR, _VRES16COLOR, _MRES256COLOR%@NL@%
- };%@NL@%
- %@NL@%
- void print_menu( void );%@NL@%
- void show_mode( char );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char key;%@NL@%
- print_menu();%@NL@%
- while( (key = getch()) != 'x' )%@NL@%
- show_mode( key );%@NL@%
- }%@NL@%
- %@NL@%
- void print_menu( void )%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- printf( "Please choose a graphics mode\nType 'x' to exit.\n\n" );%@NL@%
- printf( "0 _MRES4COLOR\n1 _MRESNOCOLOR\n2 _HRESBW\n" );%@NL@%
- printf( "3 _HERCMONO\n4 _MRES16COLOR\n5 _HRES16COLOR\n" );%@NL@%
- printf( "6 _ERESNOCOLOR\n7 _ERESCOLOR\n" );%@NL@%
- printf( "8 _VRES2COLOR\n9 _VRES16COLOR\na _MRES256COLOR\n" );%@NL@%
- }%@NL@%
- %@NL@%
- void show_mode( char which )%@NL@%
- {%@NL@%
- int nc, i;%@NL@%
- int height, width;%@NL@%
- int mode = which;%@NL@%
- %@NL@%
- if( mode < '0' || mode > '9' )%@NL@%
- if( mode == 'a' )%@NL@%
- mode = '9' + 1;%@NL@%
- else if( mode == 'b' )%@NL@%
- mode = '9' + 2;%@NL@%
- else%@NL@%
- return;%@NL@%
- %@NL@%
- if( _setvideomode( modes[mode - '0'] ) )%@NL@%
- {%@NL@%
- _getvideoconfig( &screen );%@NL@%
- nc = screen.numcolors;%@NL@%
- width = screen.numxpixels/nc;%@NL@%
- height = screen.numypixels/2;%@NL@%
- for( i = 0; i < nc; i++ )%@NL@%
- {%@NL@%
- _setcolor( i );%@NL@%
- _rectangle( _GFILLINTERIOR, i * width, 0, (i + 1) * width, height );%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( " \nVideo mode %c is not available.\n", which);%@NL@%
- printf( "Please press a key.\n" );%@NL@%
- }%@NL@%
- getch();%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- print_menu();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HALLOC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MEMORY\HALLOC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* HALLOC.C illustrates dynamic allocation of huge memory using functions:%@NL@%
- %@AB@% * halloc hfree%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char huge *bigbuf, huge *p;%@NL@%
- long count = 100000L;%@NL@%
- %@NL@%
- %@AB@%/* Allocate huge buffer. */%@AE@%%@NL@%
- bigbuf = (char huge *)halloc( count, sizeof( char ) );%@NL@%
- if( bigbuf == NULL )%@NL@%
- {%@NL@%
- printf( "Insufficient memory" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Fill the buffer with characters. */%@AE@%%@NL@%
- for( p = bigbuf; count; count--, p++ )%@NL@%
- *p = (char)(count % 10) + '0';%@NL@%
- %@NL@%
- %@AB@%/* Free huge buffer. */%@AE@%%@NL@%
- hfree( bigbuf );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HARDERR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\HARDERR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* HARDERR.C illustrates handling of hardware errors using functions:%@NL@%
- %@AB@% * _harderr _hardresume _hardretn%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<direct.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@NL@%
- void far hardhandler( unsigned deverr, unsigned doserr, unsigned far *hdr );%@NL@%
- int _bios_str( char *p );%@NL@%
- %@NL@%
- main() %@NL@%
- {%@NL@%
- %@AB@%/* Install our hard error handler. */%@AE@%%@NL@%
- _harderr( hardhandler );%@NL@%
- %@NL@%
- %@AB@%/* Test it. */%@AE@%%@NL@%
- printf( "Make sure there is no disk in drive A:\n" );%@NL@%
- printf( "Press a key when ready...\n" );%@NL@%
- getch();%@NL@%
- if( mkdir( "a:\test" ) )%@NL@%
- {%@NL@%
- printf( "Failed" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( "Succeeded" );%@NL@%
- rmdir( "a:test" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Handler to deal with hard error codes. Since DOS is not reentrant,%@NL@%
- %@AB@% * it is not safe use DOS calls to do I/O within the DOS Critical Error%@NL@%
- %@AB@% * Handler (int 24h) used by _harderr. Therefore, screen output and%@NL@%
- %@AB@% * keyboard input must be done through the BIOS.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void far hardhandler( unsigned deverr, unsigned doserr, unsigned far *hdr )%@NL@%
- {%@NL@%
- int ch;%@NL@%
- static char buf[200], tmpbuf[10];%@NL@%
- %@NL@%
- %@AB@%/* Copy message to buffer, then use BIOS to print it. */%@AE@%%@NL@%
- strcpy( buf, "\n\rDevice error code: " );%@NL@%
- strcat( buf, itoa( deverr, tmpbuf, 10 ) );%@NL@%
- strcat( buf, "\n\rDOS error code: " );%@NL@%
- strcat( buf, itoa( doserr, tmpbuf, 10 ) );%@NL@%
- strcat( buf, "\n\r(R)etry, (F)ail, or (Q)uit? " );%@NL@%
- %@NL@%
- %@AB@%/* Use BIOS to write strings and get a key. */%@AE@%%@NL@%
- _bios_str( buf );%@NL@%
- ch = _bios_keybrd( _KEYBRD_READ ) & 0x00ff;%@NL@%
- _bios_str( "\n\r" );%@NL@%
- %@NL@%
- switch( ch )%@NL@%
- {%@NL@%
- case 'R':%@NL@%
- case 'r': %@AB@%/* Try again */%@AE@%%@NL@%
- default:%@NL@%
- _hardresume( _HARDERR_RETRY );%@NL@%
- case 'F':%@NL@%
- case 'f': %@AB@%/* Return to DOS with error code */%@AE@%%@NL@%
- _hardretn( doserr );%@NL@%
- case 'Q':%@NL@%
- case 'q': %@AB@%/* Quit program */%@AE@%%@NL@%
- _hardresume( _HARDERR_ABORT );%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Display a string using BIOS interrupt 0x0e (Write TTY). Return length%@NL@%
- %@AB@% * of string displayed.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int _bios_str( char *p )%@NL@%
- {%@NL@%
- union REGS inregs, outregs;%@NL@%
- char *start = p;%@NL@%
- %@NL@%
- inregs.h.ah = 0x0e;%@NL@%
- for( ; *p; p++ )%@NL@%
- {%@NL@%
- inregs.h.al = *p;%@NL@%
- int86( 0x10, &inregs, &outregs );%@NL@%
- }%@NL@%
- return p - start;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HEAPWALK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MEMORY\HEAPWALK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* HEAPWALK.C illustrates heap testing functions including:%@NL@%
- %@AB@% * _heapchk _fheapchk _nheapchk%@NL@%
- %@AB@% * _heapset _fheapset _nheapset%@NL@%
- %@AB@% * _heapwalk _fheapwalk _nheapwalk%@NL@%
- %@AB@% * _msize _fmsize _nmsize%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Only the model independent versions are shown. They map to the model%@NL@%
- %@AB@% * dependent versions, depending on the memory model.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<malloc.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@NL@%
- %@AB@%/* Macro to get a random integer within a specified range */%@AE@%%@NL@%
- %@AI@%#define %@AE@%getrandom( min, max ) ((rand() % (int)((max) - (min))) + (min) + 1) %@NL@%
- %@NL@%
- void heapdump( char fill );%@NL@%
- void heapstat( int status );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int *p[10], i;%@NL@%
- %@NL@%
- srand( (unsigned)time( 0L ) ); %@AB@%/* Seed with current time. */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Check heap status. Should be OK at start of heap. */%@AE@%%@NL@%
- heapstat( _heapchk() );%@NL@%
- %@NL@%
- %@AB@%/* Now do some operations that affect the heap. In this example,%@NL@%
- %@AB@% * allocate random-size blocks.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for( i = 0; i < 10; i++ )%@NL@%
- {%@NL@%
- if( (p[i] = (int *)calloc( getrandom( 1, 10000 ),%@NL@%
- sizeof( int ) )) == NULL )%@NL@%
- {%@NL@%
- --i;%@NL@%
- break;%@NL@%
- }%@NL@%
- printf( "Allocated %u at %p\n", _msize( p[i] ), (void far *)p[i] );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Fill all free blocks with the test character. */%@AE@%%@NL@%
- heapstat( _heapset( 254 ) );%@NL@%
- %@NL@%
- %@AB@%/* In a real program, you might do operations here on the allocated%@NL@%
- %@AB@% * buffers. Then do heapdump to make sure none of the operations wrote%@NL@%
- %@AB@% * to free blocks.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- heapdump( 254 );%@NL@%
- %@NL@%
- %@AB@%/* Do some more heap operations. */%@AE@%%@NL@%
- for( ; i >= 0; i-- )%@NL@%
- {%@NL@%
- free( p[i] );%@NL@%
- printf( "Deallocating %u at %p\n", _msize( p[i] ), (void far *)p[i] );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Check heap again. */%@AE@%%@NL@%
- heapdump( 254 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Test routine to check each block in the heap. */%@AE@%%@NL@%
- void heapdump( char fill )%@NL@%
- {%@NL@%
- struct _heapinfo hi;%@NL@%
- int heapstatus, i;%@NL@%
- char far *p;%@NL@%
- %@NL@%
- %@AB@%/* Walk through entries, displaying results and checking free blocks. */%@AE@%%@NL@%
- printf( "\nHeap dump:\n" );%@NL@%
- hi._pentry = NULL;%@NL@%
- while( (heapstatus = _heapwalk( &hi )) == _HEAPOK )%@NL@%
- {%@NL@%
- printf( "\n\t%s block at %p of size %u\t",%@NL@%
- hi._useflag == _USEDENTRY ? "USED" : "FREE",%@NL@%
- hi._pentry, hi._size );%@NL@%
- %@NL@%
- %@AB@%/* For free entries, check each byte to see that it still has%@NL@%
- %@AB@% * only the fill character.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( hi._useflag != _USEDENTRY )%@NL@%
- {%@NL@%
- for( p = (char far *)hi._pentry, i = 0; i < hi._size; p++, i++ )%@NL@%
- if( (char)*p != fill )%@NL@%
- break;%@NL@%
- if( i == hi._size )%@NL@%
- printf( "Not changed" );%@NL@%
- else%@NL@%
- printf( "Changed" );%@NL@%
- }%@NL@%
- }%@NL@%
- heapstat( heapstatus );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Report on the status returned by _heapwalk, _heapset, or _heapchk. */%@AE@%%@NL@%
- void heapstat( int status )%@NL@%
- {%@NL@%
- printf( "\nHeap status: " );%@NL@%
- switch( status )%@NL@%
- {%@NL@%
- case _HEAPOK:%@NL@%
- printf( "OK - heap is fine" );%@NL@%
- break;%@NL@%
- case _HEAPEMPTY:%@NL@%
- printf( "OK - empty heap" );%@NL@%
- break;%@NL@%
- case _HEAPEND:%@NL@%
- printf( "OK - end of heap" );%@NL@%
- break;%@NL@%
- case _HEAPBADPTR:%@NL@%
- printf( "ERROR - bad pointer to heap" );%@NL@%
- break;%@NL@%
- case _HEAPBADBEGIN:%@NL@%
- printf( "ERROR - bad start of heap" );%@NL@%
- break;%@NL@%
- case _HEAPBADNODE:%@NL@%
- printf( "ERROR - bad node in heap" );%@NL@%
- break;%@NL@%
- }%@NL@%
- printf( "\n\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HEXDUMP1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\HEXDUMP1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* HEXDUMP.C illustrates directory splitting and character stream I/O.%@NL@%
- %@AB@% * Functions illustrated include:%@NL@%
- %@AB@% * _splitpath _makepath%@NL@%
- %@AB@% * fgetc fputc fgetchar fputchar%@NL@%
- %@AB@% * getc putc getchar putchar%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * While fgetchar, getchar, fputchar, and putchar are not specifically%@NL@%
- %@AB@% * used in the example, they are equivalent to using fgetc or getc with%@NL@%
- %@AB@% * stdin, or to using fputc or putc with stdout. See FUNGET.C for another%@NL@%
- %@AB@% * example of fgetc and getc.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- FILE *infile, *outfile;%@NL@%
- char inpath[_MAX_PATH], outpath[_MAX_PATH];%@NL@%
- char drive[_MAX_DRIVE], dir[_MAX_DIR];%@NL@%
- char fname[_MAX_FNAME], ext[_MAX_EXT];%@NL@%
- int in, size;%@NL@%
- long i = 0L;%@NL@%
- %@NL@%
- %@AB@%/* Query for and open input file. */%@AE@%%@NL@%
- printf( "Enter input file name: " );%@NL@%
- gets( inpath );%@NL@%
- strcpy( outpath, inpath );%@NL@%
- if( (infile = fopen( inpath, "rb" )) == NULL )%@NL@%
- {%@NL@%
- printf( "Can't open input file" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Build output file by splitting path and rebuilding with%@NL@%
- %@AB@% * new extension.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- _splitpath( outpath, drive, dir, fname, ext );%@NL@%
- strcpy( ext, "hx" );%@NL@%
- _makepath( outpath, drive, dir, fname, ext );%@NL@%
- %@NL@%
- %@AB@%/* If file does not exist, open it */%@AE@%%@NL@%
- if( access( outpath, 0 ) )%@NL@%
- {%@NL@%
- outfile = fopen( outpath, "wb" );%@NL@%
- printf( "Creating %s from %s . . .\n", outpath, inpath );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( "Output file already exists" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- printf( "(B)yte or (W)ord: " );%@NL@%
- size = getche();%@NL@%
- %@NL@%
- %@AB@%/* Get each character from input and write to output. */%@AE@%%@NL@%
- while( !feof( infile ) )%@NL@%
- {%@NL@%
- if( (size == 'W') || (size == 'w') )%@NL@%
- {%@NL@%
- in = getw( infile );%@NL@%
- fprintf( outfile, " %.4X", in );%@NL@%
- if( !(++i % 8) )%@NL@%
- putw( 0x0D0A, outfile ); %@AB@%/* New line */%@AE@%%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* This example uses the fgetc and fputc functions. You%@NL@%
- %@AB@% * could also use the macro versions:%@NL@%
- %@AB@% in = getc( infile );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- in = fgetc( infile );%@NL@%
- fprintf( outfile, " %.2X", in );%@NL@%
- if( !(++i % 16) )%@NL@%
- {%@NL@%
- %@AB@%/* Macro version:%@NL@%
- %@AB@% putc( 13, outfile );%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fputc( 13, outfile ); %@AB@%/* New line */%@AE@%%@NL@%
- fputc( 10, outfile );%@NL@%
- }%@NL@%
- }%@NL@%
- }%@NL@%
- fclose( infile );%@NL@%
- fclose( outfile );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%HORIZON.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\HORIZON.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* HORIZON.C: VGA graphics with cycling of 256 colors */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%RED 0x0000003FL %@NL@%
- %@AI@%#define %@AE@%GRN 0x00003F00L %@NL@%
- %@AI@%#define %@AE@%BLU 0x003F0000L %@NL@%
- %@AI@%#define %@AE@%WHT 0x003F3F3FL %@NL@%
- %@AI@%#define %@AE@%STEP 21 %@NL@%
- %@NL@%
- struct videoconfig screen;%@NL@%
- long int rainbow[512];%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int i;%@NL@%
- long int col, gray;%@NL@%
- %@NL@%
- if( _setvideomode( _MRES256COLOR ) == 0 )%@NL@%
- {%@NL@%
- printf("This program requires a VGA card.\n" );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- for( col = 0; col < 64; col++ )%@NL@%
- {%@NL@%
- gray = col | (col << 8) | (col << 16);%@NL@%
- rainbow[col] = rainbow[col + 256] = BLU & gray;%@NL@%
- rainbow[col + 64] = rainbow[col + 64 + 256] = BLU | gray;%@NL@%
- rainbow[col + 128] = rainbow[col + 128 + 256] = RED | (WHT & ~gray);%@NL@%
- rainbow[col + 192] = rainbow[col + 192 + 256] = RED & ~gray;%@NL@%
- }%@NL@%
- _setvieworg( 160, 85 );%@NL@%
- %@NL@%
- for( i = 0; i < 255; i++ )%@NL@%
- {%@NL@%
- _setcolor( 255 - i );%@NL@%
- _moveto( i, i - 255 );%@NL@%
- _lineto( -i, 255 - i );%@NL@%
- _moveto( -i, i - 255 );%@NL@%
- _lineto( i, 255 - i );%@NL@%
- _ellipse( _GBORDER, -i, -i / 2, i, i / 2 );%@NL@%
- }%@NL@%
- for( i = 0; !kbhit(); i += STEP, i %= 256 )%@NL@%
- _remapallpalette( &(rainbow[i]) );%@NL@%
- %@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%IF1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\IF1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* IF.C: Demonstrate if statement. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#define %@AE@% B_KEY 'b' %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch;%@NL@%
- printf( "Press the b key to hear a bell.\n" );%@NL@%
- ch = getche();%@NL@%
- if( ch == B_KEY )%@NL@%
- printf( "Beep!\a\n" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INCMAC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\INCMAC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* INCMAC.C: Increment operator in macro argument.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%ABS(value) ( (value) >= 0 ? (value) : -(value) ) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static int array[4] = {3, -20, -555, 6};%@NL@%
- int *ptr = array;%@NL@%
- int val, count;%@NL@%
- for( count = 0; count < 4; count++ )%@NL@%
- {%@NL@%
- val = ABS(*ptr++); %@AB@%/* Error! */%@AE@%%@NL@%
- printf( "abs of array[%d] = %d\n", count, val );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INCMAC1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\INCMAC1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* INCMAC1.C: Increment operator in the for statement.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#define %@AE@%ABS(value) ( (value) >= 0 ? (value) : -(value) ) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- static int array[4] = {3, -20, -555, 6};%@NL@%
- int *ptr = array;%@NL@%
- int val, count;%@NL@%
- for( count = 0; count < 4; count++, ptr++ )%@NL@%
- {%@NL@%
- val = ABS(*ptr);%@NL@%
- printf( "abs of array[%d] = %d\n", count, val );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%INTMATH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MATH\INTMATH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* INTMATH.C illustrates integer math functions including:%@NL@%
- %@AB@% * abs labs min max div ldiv%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See MATH.C for an example of the similar fabs function.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int x, y;%@NL@%
- long lx, ly;%@NL@%
- div_t divres;%@NL@%
- ldiv_t ldivres;%@NL@%
- %@NL@%
- printf( "Enter two integers: " );%@NL@%
- scanf( "%d %d", &x, &y );%@NL@%
- %@NL@%
- printf("Function\tResult\n\n" );%@NL@%
- printf( "abs\t\tThe absolute value of %d is %d\n", x, abs( x ) );%@NL@%
- printf( "min\t\tThe lesser of %d and %d is %d\n", x, y, min( x, y ) );%@NL@%
- printf( "max\t\tThe greater of %d and %d is %d\n", x, y, max( x, y ) );%@NL@%
- divres = div( x, y );%@NL@%
- printf( "div\t\tFor %d / %d, quotient is %d and remainder is %d\n\n",%@NL@%
- x, y, divres.quot, divres.rem );%@NL@%
- %@NL@%
- printf( "Enter two long integers: " );%@NL@%
- scanf( "%ld %ld", &lx, &ly );%@NL@%
- %@NL@%
- printf("Function\tResult\n\n" );%@NL@%
- ldivres = ldiv( lx, ly );%@NL@%
- printf( "labs\t\tThe absolute value of %ld is %ld\n", lx, labs( lx ) );%@NL@%
- printf( "ldiv\t\tFor %ld / %ld, quotient is %ld and remainder is %ld\n",%@NL@%
- lx, ly, ldivres.quot, ldivres.rem );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%IS.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\IS.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* IS.C illustrates character classification functions including:%@NL@%
- %@AB@% * isprint isascii isalpha isalnum%@NL@%
- %@AB@% * isupper islower isdigit isxdigit%@NL@%
- %@AB@% * ispunct isspace iscntrl isgraph%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Console output is also shown using:%@NL@%
- %@AB@% * cprintf%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See PRINTF.C for additional examples of formatting for cprintf.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int ch;%@NL@%
- %@NL@%
- %@AB@%/* Display each ASCII character with character type table. */%@AE@%%@NL@%
- for( ch = 0; ch < 256; ch++ )%@NL@%
- {%@NL@%
- if( ch % 22 == 0 )%@NL@%
- {%@NL@%
- if( ch )%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* Note that cprintf does not convert "\n" to a CR/LF sequence.%@NL@%
- %@AB@% * You can specify this sequence with "\n\r".%@NL@%
- %@AB@% */%@AE@%%@NL@%
- cprintf( "\n\rNum Char ASCII Alpha AlNum Cap Low Digit " );%@NL@%
- cprintf( "XDigit Punct White CTRL Graph Print \n\r" );%@NL@%
- }%@NL@%
- cprintf( "%3d ", ch );%@NL@%
- %@NL@%
- %@AB@%/* Console output functions (cprint, cputs, and putch) display%@NL@%
- %@AB@% * graphic characters for all values except 7 (bell), 8 (backspace),%@NL@%
- %@AB@% * 10 (line feed), 13 (carriage return), and 255.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( ch == 7 || ch == 8 || ch == 10 || ch == 13 || ch == 255 )%@NL@%
- cprintf("NV" );%@NL@%
- else%@NL@%
- cprintf("%c ", ch );%@NL@%
- cprintf( "%5s", isascii( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%6s", isalpha( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%6s", isalnum( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%5s", isupper( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%4s", islower( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%5s", isdigit( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%7s", isxdigit( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%6s", ispunct( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%6s", isspace( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%5s", iscntrl( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%6s", isprint( ch ) ? "Y" : "N" );%@NL@%
- cprintf( "%6s\n\r", isgraph( ch ) ? "Y" : "N" );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%KBHIT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\KBHIT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* KBHIT.C illustrates:%@NL@%
- %@AB@% * kbhit%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@AB@%/* Display message until key is pressed. Use getch to throw key away. */%@AE@%%@NL@%
- while( !kbhit() )%@NL@%
- cputs( "Hit me!! " );%@NL@%
- getch();%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%KEYBRD.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\UTILITY\KEYBRD.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* KEYBRD.C illustrates:%@NL@%
- %@AB@% * _bios_keybrd%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- unsigned key, shift;%@NL@%
- unsigned char scan, ascii = 0;%@NL@%
- %@NL@%
- %@AB@%/* Read and display keys until ESC is pressed. */%@AE@%%@NL@%
- while( ascii != 27 )%@NL@%
- {%@NL@%
- %@AB@%/* Drain any keys in the keyboard type-ahead buffer, then get%@NL@%
- %@AB@% * the current key. If you want the last key typed rather than%@NL@%
- %@AB@% * the key currently being typed, omit the initial loop.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- while( _bios_keybrd( _KEYBRD_READY ) )%@NL@%
- _bios_keybrd( _KEYBRD_READ );%@NL@%
- key = _bios_keybrd( _KEYBRD_READ );%@NL@%
- %@NL@%
- %@AB@%/* Get shift state. */%@AE@%%@NL@%
- shift = _bios_keybrd( _KEYBRD_SHIFTSTATUS );%@NL@%
- %@NL@%
- %@AB@%/* Split key into scan and ascii parts. */%@AE@%%@NL@%
- scan = key >> 8;%@NL@%
- ascii = key & 0x00ff;%@NL@%
- %@NL@%
- %@AB@%/* Categorize key. */%@AE@%%@NL@%
- if( ascii )%@NL@%
- printf( "ASCII: yes\tChar: %c \t",%@NL@%
- isgraph( ascii ) ? ascii : ' ' );%@NL@%
- else%@NL@%
- printf( "ASCII: no\tChar: NA\t" );%@NL@%
- printf( "Code: %.2X\tScan: %.2X\t Shift: %.2X\n",%@NL@%
- ascii, scan, shift );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%LOCK.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\LOCK.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* LOCK.C illustrates network file sharing functions:%@NL@%
- %@AB@% * sopen locking%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Also the global variable:%@NL@%
- %@AB@% * _osmajor%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The program requires DOS 3.0 or higher. The DOS SHARE command must%@NL@%
- %@AB@% * be loaded. The locking mechanism will only work if the program is%@NL@%
- %@AB@% * run from a network drive.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<sys\locking.h> %@NL@%
- %@AI@%#include %@AE@%<share.h> %@NL@%
- <stdlib.h> %@AB@%/* For _osmajor and exit */%@AE@%%@NL@%
- %@NL@%
- void error( char *msg );%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- int handle, i;%@NL@%
- static char msg[] = "Are any of these bytes locked?";%@NL@%
- char buf[1];%@NL@%
- %@NL@%
- %@AB@%/* Check for DOS version >= 3.0 */%@AE@%%@NL@%
- if( _osmajor < 3 )%@NL@%
- error( "Must be DOS 3.0 or higher" );%@NL@%
- %@NL@%
- %@AB@%/* If no argument, write file and lock some bytes in it. */%@AE@%%@NL@%
- if( argc == 1 )%@NL@%
- {%@NL@%
- %@AB@%/* Open file with deny none sharing. */%@AE@%%@NL@%
- handle = sopen( "tmpfil", O_BINARY | O_RDWR | O_CREAT,%@NL@%
- SH_DENYNO, S_IREAD | S_IWRITE );%@NL@%
- if( handle == -1 )%@NL@%
- error( "Can't open file\n" );%@NL@%
- %@NL@%
- write( handle, msg, sizeof( msg ) - 1 );%@NL@%
- %@NL@%
- %@AB@%/* Lock 10 bytes starting at byte 10. */%@AE@%%@NL@%
- lseek( handle, 10L, SEEK_SET );%@NL@%
- if( locking( handle, LK_LOCK, 10L ) )%@NL@%
- error( "Locking failed\n" );%@NL@%
- printf( "Locked 10 bytes starting at byte 10\n" );%@NL@%
- %@NL@%
- system( "LOCK read" );%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* Unlock. */%@AE@%%@NL@%
- lseek( handle, 10L, SEEK_SET );%@NL@%
- locking( handle, LK_UNLCK, 10L );%@NL@%
- printf( "\nUnlocked 10 bytes starting at byte 10\n" );%@NL@%
- %@NL@%
- system( "LOCK read" );%@NL@%
- getch();%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* If argument, Try to read some locked bytes. */%@AE@%%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* Open file with deny none sharing. */%@AE@%%@NL@%
- handle = sopen( "tmpfil", O_BINARY | O_RDWR,%@NL@%
- SH_DENYNO, S_IREAD | S_IWRITE );%@NL@%
- if( handle == -1 )%@NL@%
- error( "Can't open file\n" );%@NL@%
- %@NL@%
- for( i = 0; i < sizeof( msg ) - 1; i++ )%@NL@%
- {%@NL@%
- %@AB@%/* Print characters until locked bytes are reached. */%@AE@%%@NL@%
- if( read( handle, buf, 1 ) == -1 )%@NL@%
- break;%@NL@%
- else%@NL@%
- putchar( *buf );%@NL@%
- }%@NL@%
- }%@NL@%
- close( handle );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- void error( char *errmsg )%@NL@%
- {%@NL@%
- printf( errmsg );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MATH.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MATH\MATH.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MATH.C illustrates floating point math functions including:%@NL@%
- %@AB@% * exp pow sqrt frexp%@NL@%
- %@AB@% * log log10 ldexp modf%@NL@%
- %@AB@% * ceil floor fabs fmod%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<float.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- double x, rx, y;%@NL@%
- int n;%@NL@%
- %@NL@%
- printf( "\nEnter a real number: " );%@NL@%
- scanf( "%lf", &x );%@NL@%
- %@NL@%
- printf( "Mantissa: %2.2lf\tExponent: %d\n", frexp( x, &n ), n );%@NL@%
- printf( "Fraction: %2.2lf\tInteger: %lf\n", modf( x, &y ), y );%@NL@%
- %@NL@%
- printf("\nFunction\tResult for %2.2f\n\n", x );%@NL@%
- if( (rx = exp( x )) && (errno != ERANGE) )%@NL@%
- printf( "exp\t\t%2.2f\n", rx );%@NL@%
- else%@NL@%
- errno = 0;%@NL@%
- if( x > 0.0 )%@NL@%
- printf( "log\t\t%2.2f\n", log( x ) );%@NL@%
- if( x > 0.0 )%@NL@%
- printf( "log10\t\t%2.2f\n", log10( x ) );%@NL@%
- if( x >= 0.0 )%@NL@%
- printf( "sqrt\t\t%2.2f\n", sqrt( x ) );%@NL@%
- printf( "ceil\t\t%2.2f\n", ceil( x ) );%@NL@%
- printf( "floor\t\t%2.2f\n", floor( x ) );%@NL@%
- printf( "fabs\t\t%2.2f\n", fabs( x ) );%@NL@%
- %@NL@%
- printf( "\nEnter another real number: " );%@NL@%
- scanf( "%lf", &y );%@NL@%
- printf("\nFunction\tResult for %2.2f and %2.2f\n\n", x, y );%@NL@%
- printf( "fmod\t\t%2.2f\n", fmod( x, y ) );%@NL@%
- rx = pow( x, y );%@NL@%
- if( (errno != ERANGE) && (errno != EDOM) )%@NL@%
- printf( "pow\t\t%2.2f\n", rx );%@NL@%
- else%@NL@%
- errno = 0;%@NL@%
- rx = hypot( x, y );%@NL@%
- if( errno != ERANGE )%@NL@%
- printf( "hypot\t\t%2.2f\n", hypot( x, y ) );%@NL@%
- else%@NL@%
- errno = 0;%@NL@%
- %@NL@%
- printf( "\nEnter an integer exponent: " );%@NL@%
- scanf( "%d", &n );%@NL@%
- rx = ldexp( x, n );%@NL@%
- if( errno != ERANGE )%@NL@%
- {%@NL@%
- printf("\nFunction\tResult for %2.2f to power %d\n\n", x, n );%@NL@%
- printf( "ldexp\t\t%2.2f\n", ldexp( x, n ) );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MATHERR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MATH\MATHERR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MATHERR.C illustrates writing an error routine for math functions.%@NL@%
- %@AB@% * The error function must be:%@NL@%
- %@AB@% * matherr%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * To use matherr, you must turn off the Extended Dictionary flag within%@NL@%
- %@AB@% * the QC environment (Options-Make-Linker Flags) or use the /NOE linker%@NL@%
- %@AB@% * option outside the environment. For example:%@NL@%
- %@AB@% * QCL matherr.c /link /NOE%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<math.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- %@AB@%/* Do several math operations that cause errors. The matherr%@NL@%
- %@AB@% * routine handles DOMAIN errors, but lets the system handle%@NL@%
- %@AB@% * other errors normally.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- printf( "log( -2.0 ) = %e\n", log( -2.0 ) );%@NL@%
- printf( "log10( -5.0 ) = %e\n", log10( -5.0 ) );%@NL@%
- printf( "log( 0.0 ) = %e\n", log( 0.0 ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Routine to handle several math errors caused by passing a negative%@NL@%
- %@AB@% * argument to log or log10 (DOMAIN errors). If this happens, matherr%@NL@%
- %@AB@% * returns the natural or base-10 logarithm of the absolute value of%@NL@%
- %@AB@% * the argument and suppresses the usual error message.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int matherr( struct exception *except )%@NL@%
- {%@NL@%
- %@AB@%/* Handle DOMAIN errors for log or log10. */%@AE@%%@NL@%
- if( except->type == DOMAIN )%@NL@%
- {%@NL@%
- if( strcmp( except->name, "log" ) == 0 )%@NL@%
- {%@NL@%
- except->retval = log( -(except->arg1) );%@NL@%
- printf( "Special: using absolute value: %s: DOMAIN error\n",%@NL@%
- except->name );%@NL@%
- return 1;%@NL@%
- }%@NL@%
- else if( strcmp( except->name, "log10" ) == 0 )%@NL@%
- {%@NL@%
- except->retval = log10( -(except->arg1) );%@NL@%
- printf( "Special: using absolute value: %s: DOMAIN error\n",%@NL@%
- except->name );%@NL@%
- return 1;%@NL@%
- }%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- printf( "Normal: " );%@NL@%
- return 0; %@AB@%/* Else use the default actions */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MENU.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\UTILITY\MENU.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MENU - Module of functions to put menus on the screen and handle keyboard%@NL@%
- %@AB@% * input. To use it, include the MENU.H file in your program. The following%@NL@%
- %@AB@% * functions are public:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Menu - Puts a menu on screen and reads input for it%@NL@%
- %@AB@% * Box - Puts a box on screen (fill it yourself)%@NL@%
- %@AB@% * GetKey - Gets ASCII or function key%@NL@%
- %@AB@% * _outchar - Displays character using current text position and color%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The following structures are defined:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * MENU - Defines menu colors, box type, and centering%@NL@%
- %@AB@% * ITEM - Defines text of menu item and index of highlight character%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The global variable "mnuAtrib" has type MENU. Change this variable to%@NL@%
- %@AB@% * change menu appearance.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@AI@%#include %@AE@%<stddef.h> %@NL@%
- %@AI@%#include %@AE@%<ctype.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@AI@%#include %@AE@%"menu.h" %@NL@%
- %@NL@%
- %@AB@%/* Default menu attribute. The default works for color or B&W. You can%@NL@%
- %@AB@% * override the default value by defining your own MENU variable and%@NL@%
- %@AB@% * assigning it to mnuAtrib. Or you can modify specific fields at%@NL@%
- %@AB@% * run time. For example, you could use a different attribute for color%@NL@%
- %@AB@% * than for black and white.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- struct MENU mnuAtrib =%@NL@%
- {%@NL@%
- _TBLACK, _TBLACK, _TWHITE, _TBRIGHTWHITE, _TBRIGHTWHITE,%@NL@%
- _TWHITE, _TWHITE, _TBLACK, _TWHITE, _TBLACK,%@NL@%
- TRUE,%@NL@%
- '┌', '┐', '┘', '└', '│', '─'%@NL@%
- };%@NL@%
- %@NL@%
- %@AB@%/* Menu - Puts menu on screen and reads menu input from keyboard. When a%@NL@%
- %@AB@% * highlighted hot key or ENTER is pressed, returns the index of the%@NL@%
- %@AB@% * selected menu item.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row and col - If "fCentered" attribute of "mnuAtrib" is true,%@NL@%
- %@AB@% * center row and column of menu; otherwise top left of menu%@NL@%
- %@AB@% * aItem - array of structure containing the text of each item%@NL@%
- %@AB@% * and the index of the highlighted hot key%@NL@%
- %@AB@% * iCur - index of the current selection--pass 0 for first item,%@NL@%
- %@AB@% * or maintain a static value%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: The index of the selected item%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: mnuAtrib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- int Menu( int row, int col, struct ITEM aItem[], int iCur )%@NL@%
- {%@NL@%
- int cItem, cchItem = 2; %@AB@%/* Counts of items and chars per item */%@AE@%%@NL@%
- int i, iPrev; %@AB@%/* Indexes - temporary and previous */%@AE@%%@NL@%
- int acchItem[MAXITEM]; %@AB@%/* Array of counts of character in items */%@AE@%%@NL@%
- char *pchT; %@AB@%/* Temporary character pointer */%@AE@%%@NL@%
- char achHilite[36]; %@AB@%/* Array for highlight characters */%@AE@%%@NL@%
- unsigned uKey; %@AB@%/* Unsigned key code */%@AE@%%@NL@%
- long bgColor; %@AB@%/* Screen color, position, and cursor */%@AE@%%@NL@%
- short fgColor;%@NL@%
- struct rccoord rc;%@NL@%
- unsigned fCursor;%@NL@%
- %@NL@%
- %@AB@%/* Save screen information. */%@AE@%%@NL@%
- fCursor = _displaycursor( _GCURSOROFF );%@NL@%
- bgColor = _getbkcolor();%@NL@%
- fgColor = _gettextcolor();%@NL@%
- rc = _gettextposition();%@NL@%
- %@NL@%
- %@AB@%/* Count items, find longest, and put count of each in array. Also,%@NL@%
- %@AB@% * put the highlighted character from each in a string.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- for( cItem = 0; aItem[cItem].achItem[0]; cItem++ )%@NL@%
- {%@NL@%
- acchItem[cItem] = strlen( aItem[cItem].achItem );%@NL@%
- cchItem = (acchItem[cItem] > cchItem) ? acchItem[cItem] : cchItem;%@NL@%
- i = aItem[cItem].iHilite;%@NL@%
- achHilite[cItem] = aItem[cItem].achItem[i];%@NL@%
- }%@NL@%
- cchItem += 2;%@NL@%
- achHilite[cItem] = 0; %@AB@%/* Null-terminate and lowercase string */%@AE@%%@NL@%
- strlwr( achHilite );%@NL@%
- %@NL@%
- %@AB@%/* Adjust if centered, and draw menu box. */%@AE@%%@NL@%
- if( mnuAtrib.fCentered )%@NL@%
- {%@NL@%
- row -= cItem / 2;%@NL@%
- col -= cchItem / 2;%@NL@%
- }%@NL@%
- Box( row++, col++, cItem, cchItem );%@NL@%
- %@NL@%
- %@AB@%/* Put items on menu. */%@AE@%%@NL@%
- for( i = 0; i < cItem; i++ )%@NL@%
- {%@NL@%
- if( i == iCur )%@NL@%
- Itemize( row + i, col, TRUE, aItem[i], cchItem - acchItem[i] );%@NL@%
- else%@NL@%
- Itemize( row + i, col, FALSE, aItem[i], cchItem - acchItem[i] );%@NL@%
- }%@NL@%
- %@NL@%
- while( TRUE )%@NL@%
- {%@NL@%
- %@AB@%/* Wait until a uKey is pressed, then evaluate it. */%@AE@%%@NL@%
- uKey = GetKey( WAIT );%@NL@%
- switch( uKey )%@NL@%
- {%@NL@%
- case U_UP: %@AB@%/* Up key */%@AE@%%@NL@%
- iPrev = iCur;%@NL@%
- iCur = (iCur > 0) ? (--iCur % cItem) : cItem - 1;%@NL@%
- break;%@NL@%
- case U_DN: %@AB@%/* Down key */%@AE@%%@NL@%
- iPrev = iCur;%@NL@%
- iCur = (iCur < cItem) ? (++iCur % cItem) : 0;%@NL@%
- break;%@NL@%
- default:%@NL@%
- if( uKey > 256 ) %@AB@%/* Ignore unknown function key */%@AE@%%@NL@%
- continue;%@NL@%
- pchT = strchr( achHilite, (char)tolower( uKey ) );%@NL@%
- if( pchT != NULL ) %@AB@%/* If in highlight string, */%@AE@%%@NL@%
- iCur = pchT - achHilite;%@AB@%/* evaluate and fall through */%@AE@%%@NL@%
- else%@NL@%
- continue; %@AB@%/* Ignore unkown ASCII key */%@AE@%%@NL@%
- case ENTER:%@NL@%
- _setbkcolor( bgColor );%@NL@%
- _settextcolor( fgColor );%@NL@%
- _settextposition( rc.row, rc.col );%@NL@%
- _displaycursor( fCursor );%@NL@%
- return iCur;%@NL@%
- }%@NL@%
- %@AB@%/* Redisplay current and previous. */%@AE@%%@NL@%
- Itemize( row + iCur, col, TRUE, aItem[iCur], cchItem - acchItem[iCur] );%@NL@%
- Itemize( row + iPrev, col, FALSE, aItem[iPrev], cchItem - acchItem[iPrev] );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Box - Draw menu box, filling interior with blanks of the border color.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row and col - upper left of box%@NL@%
- %@AB@% * rowLast and colLast - height and width%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: None%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: mnuAtrib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Box( int row, int col, int rowLast, int colLast )%@NL@%
- {%@NL@%
- int i;%@NL@%
- char achT[MAXITEM + 2]; %@AB@%/* Temporary array of characters */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Set color and position. */%@AE@%%@NL@%
- _settextposition( row, col );%@NL@%
- _settextcolor( mnuAtrib.fgBorder );%@NL@%
- _setbkcolor( mnuAtrib.bgBorder );%@NL@%
- %@NL@%
- %@AB@%/* Draw box top. */%@AE@%%@NL@%
- achT[0] = mnuAtrib.chNW;%@NL@%
- memset( achT + 1, mnuAtrib.chEW, colLast );%@NL@%
- achT[colLast + 1] = mnuAtrib.chNE;%@NL@%
- achT[colLast + 2] = 0;%@NL@%
- _outtext( achT );%@NL@%
- %@NL@%
- %@AB@%/* Draw box sides and center. */%@AE@%%@NL@%
- achT[0] = mnuAtrib.chNS;%@NL@%
- memset( achT + 1, ' ', colLast );%@NL@%
- achT[colLast + 1] = mnuAtrib.chNS;%@NL@%
- achT[colLast + 2] = 0;%@NL@%
- for( i = 1; i <= rowLast; ++i )%@NL@%
- {%@NL@%
- _settextposition( row + i, col );%@NL@%
- _outtext( achT );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Draw box bottom. */%@AE@%%@NL@%
- _settextposition( row + rowLast + 1, col );%@NL@%
- achT[0] = mnuAtrib.chSW;%@NL@%
- memset( achT + 1, mnuAtrib.chEW, colLast );%@NL@%
- achT[colLast + 1] = mnuAtrib.chSE;%@NL@%
- achT[colLast + 2] = 0;%@NL@%
- _outtext( achT );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Itemize - Display one (item) selection of a menu. This function%@NL@%
- %@AB@% * is normally only used internally by Menu.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: row and col - top left of menu%@NL@%
- %@AB@% * fCur - flag set if item is current selection%@NL@%
- %@AB@% * itm - structure containing item text and index of highlight%@NL@%
- %@AB@% * cBlank - count of blanks to fill%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: none%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Uses: mnuAtrib%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void Itemize( int row, int col, int fCur, struct ITEM itm, int cBlank )%@NL@%
- {%@NL@%
- int i;%@NL@%
- char achT[MAXITEM]; %@AB@%/* Temporary array of characters */%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* Set text position and color. */%@AE@%%@NL@%
- _settextposition( row, col );%@NL@%
- if( fCur )%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgSelect );%@NL@%
- _setbkcolor( mnuAtrib.bgSelect );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgNormal );%@NL@%
- _setbkcolor( mnuAtrib.bgNormal );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Display item and fill blanks. */%@AE@%%@NL@%
- strcat( strcpy( achT, " " ), itm.achItem );%@NL@%
- _outtext( achT );%@NL@%
- memset( achT, ' ', cBlank-- );%@NL@%
- achT[cBlank] = 0;%@NL@%
- _outtext( achT );%@NL@%
- %@NL@%
- %@AB@%/* Set position and color of highlight character, then display it. */%@AE@%%@NL@%
- i = itm.iHilite;%@NL@%
- _settextposition( row, col + i + 1 );%@NL@%
- if( fCur )%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgSelHilite );%@NL@%
- _setbkcolor( mnuAtrib.bgSelHilite );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- _settextcolor( mnuAtrib.fgNormHilite );%@NL@%
- _setbkcolor( mnuAtrib.bgNormHilite );%@NL@%
- }%@NL@%
- _outchar( itm.achItem[i] );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* GetKey - Gets a key from the keyboard. This routine distinguishes%@NL@%
- %@AB@% * between ASCII keys and function or control keys with different shift%@NL@%
- %@AB@% * states. It also accepts a flag to return immediately if no key is%@NL@%
- %@AB@% * available.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: fWait - Code to indicate how to handle keyboard buffer:%@NL@%
- %@AB@% * NO_WAIT Return 0 if no key in buffer, else return key%@NL@%
- %@AB@% * WAIT Return first key if available, else wait for key%@NL@%
- %@AB@% * CLEAR_WAIT Throw away any key in buffer and wait for new key%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: One of the following:%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Keytype High Byte Low Byte%@NL@%
- %@AB@% * ------- --------- --------%@NL@%
- %@AB@% * No key available (only with NO_WAIT) 0 0%@NL@%
- %@AB@% * ASCII value 0 ASCII code%@NL@%
- %@AB@% * Unshifted function or keypad 1 scan code%@NL@%
- %@AB@% * Shifted function or keypad 2 scan code%@NL@%
- %@AB@% * CTRL function or keypad 3 scan code%@NL@%
- %@AB@% * ALT function or keypad 4 scan code%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Note: getkey cannot return codes for keys not recognized by BIOS%@NL@%
- %@AB@% * int 16, such as the CTRL-UP or the 5 key on the numeric keypad.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- unsigned GetKey( int fWait )%@NL@%
- {%@NL@%
- unsigned uKey, uShift;%@NL@%
- %@NL@%
- %@AB@%/* If CLEAR_WAIT, drain the keyboard buffer. */%@AE@%%@NL@%
- if( fWait == CLEAR_WAIT )%@NL@%
- while( _bios_keybrd( _KEYBRD_READY ) )%@NL@%
- _bios_keybrd( _KEYBRD_READ );%@NL@%
- %@NL@%
- %@AB@%/* If NO_WAIT, return 0 if there is no key ready. */%@AE@%%@NL@%
- if( !fWait && !_bios_keybrd( _KEYBRD_READY ) )%@NL@%
- return FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Get key code. */%@AE@%%@NL@%
- uKey = _bios_keybrd( _KEYBRD_READ );%@NL@%
- %@NL@%
- %@AB@%/* If low byte is not zero, its an ASCII key. Check scan code to see%@NL@%
- %@AB@% * if it's on the numeric keypad. If not, clear high byte and return.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( uKey & 0x00ff )%@NL@%
- if( (uKey >> 8) < 69 )%@NL@%
- return( uKey & 0x00ff );%@NL@%
- %@NL@%
- %@AB@%/* For function keys and numeric keypad, put scan code in low byte%@NL@%
- %@AB@% * and shift state codes in high byte.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- uKey >>= 8;%@NL@%
- uShift = _bios_keybrd( _KEYBRD_SHIFTSTATUS ) & 0x000f;%@NL@%
- switch( uShift )%@NL@%
- {%@NL@%
- case 0:%@NL@%
- return( 0x0100 | uKey ); %@AB@%/* None (1) */%@AE@%%@NL@%
- case 1:%@NL@%
- case 2:%@NL@%
- case 3:%@NL@%
- return( 0x0200 | uKey ); %@AB@%/* Shift (2) */%@AE@%%@NL@%
- case 4:%@NL@%
- return( 0x0300 | uKey ); %@AB@%/* Control (3) */%@AE@%%@NL@%
- case 8:%@NL@%
- return( 0x0400 | uKey ); %@AB@%/* Alt (4) */%@AE@%%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* _outchar - Display a character. This is the character equivalent of%@NL@%
- %@AB@% * _outtext. It is affected by _settextposition, _settextcolor, and%@NL@%
- %@AB@% * _setbkcolor. It should not be used in loops. Build strings and then%@NL@%
- %@AB@% * _outtext to show multiple characters.%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Params: out - character to be displayed%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Return: none%@NL@%
- %@AB@% */%@AE@%%@NL@%
- void _outchar( char out )%@NL@%
- {%@NL@%
- static char achT[2] = " "; %@AB@%/* Temporary array of characters */%@AE@%%@NL@%
- %@NL@%
- achT[0] = out;%@NL@%
- _outtext( achT );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MKFPSTR.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\MKFPSTR.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MKFPSTR.C illustrates building and displaying floating point strings%@NL@%
- %@AB@% * without printf. Functions illustrated include:%@NL@%
- %@AB@% * strcat strncat cscanf fcvt%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int decimal, sign;%@NL@%
- int precision = 7;%@NL@%
- static char numbuf[50] = ""; %@NL@%
- char *pnumstr, tmpbuf[50];%@NL@%
- double number1, number2;%@NL@%
- %@NL@%
- cputs( "Enter two floating point numbers: " );%@NL@%
- cscanf( "%lf %lf", &number1, &number2 );%@NL@%
- putch( '\n' );%@NL@%
- %@NL@%
- %@AB@%/* Use information from fcvt to format number string. */%@AE@%%@NL@%
- pnumstr = fcvt( number1 + number2, precision, &decimal, &sign );%@NL@%
- %@NL@%
- %@AB@%/* Start with sign if negative. */%@AE@%%@NL@%
- if( sign )%@NL@%
- strcat( numbuf, "-" );%@NL@%
- %@NL@%
- if( decimal <= 0 )%@NL@%
- {%@NL@%
- %@AB@%/* If decimal is left of first digit (decimal negative), put%@NL@%
- %@AB@% * in leading zeros, then add digits.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- strcat( numbuf, "0." );%@NL@%
- memset( tmpbuf, '0', (size_t)abs( decimal ) );%@NL@%
- tmpbuf[abs( decimal )] = 0;%@NL@%
- strcat( numbuf, tmpbuf );%@NL@%
- strcat( numbuf, pnumstr );%@NL@%
- }%@NL@%
- else%@NL@%
- {%@NL@%
- %@AB@%/* If decimal is right of first digit, put in leading digits.%@NL@%
- %@AB@% * then add decimal and trailing digits.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- strncat( numbuf, pnumstr, (size_t)decimal );%@NL@%
- strcat( numbuf, "." );%@NL@%
- strcat( numbuf, pnumstr + decimal );%@NL@%
- }%@NL@%
- cputs( strcat( "Total is: ", numbuf ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MORE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\MORE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MORE.C illustrates line input and output using:%@NL@%
- %@AB@% * gets puts isatty fileno%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Like the DOS MORE command, it is a filter whose input and output can%@NL@%
- %@AB@% * be redirected.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<bios.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- long line = 0, page = 0;%@NL@%
- char tmp[128];%@NL@%
- %@NL@%
- %@AB@%/* Get each line from standard input and write to standard output. */%@AE@%%@NL@%
- while( 1 )%@NL@%
- {%@NL@%
- %@AB@%/* If standard out is the screen, wait for key after each screen. */%@AE@%%@NL@%
- if( isatty( fileno( stdout ) ) )%@NL@%
- {%@NL@%
- %@AB@%/* Wait for key every 23 lines. You must get the key directly%@NL@%
- %@AB@% * from the BIOS, since input is usually redirected.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( !(++line % 23 ) )%@NL@%
- _bios_keybrd( _KEYBRD_READ );%@NL@%
- }%@NL@%
- %@AB@%/* Must be redirected to file, so send a header every 58 lines. */%@AE@%%@NL@%
- else%@NL@%
- {%@NL@%
- if( !(line++ % 58) )%@NL@%
- printf( "\f\nPage: %d\n\n", ++page );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Get and put a line of text. */%@AE@%%@NL@%
- if( gets( tmp ) == NULL )%@NL@%
- break;%@NL@%
- puts( tmp );%@NL@%
- %@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%MOVEMEM.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\MEMORY\MOVEMEM.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* MOVEMEM.C illustrate direct memory access using functions:%@NL@%
- %@AB@% * movedata FP_SEG FP_OFF%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * Also illustrated:%@NL@%
- %@AB@% * pack pragma%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * See COPY2.C for another example of FP_SEG.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<memory.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@NL@%
- pack(1) %@AB@%/* Use pragma to force packing on byte boundaries. */%@AE@%%@NL@%
- %@NL@%
- struct LOWMEMVID%@NL@%
- {%@NL@%
- char vidmode; %@AB@%/* 0x449 */%@AE@%%@NL@%
- unsigned scrwid; %@AB@%/* 0x44A */%@AE@%%@NL@%
- unsigned scrlen; %@AB@%/* 0x44C */%@AE@%%@NL@%
- unsigned scroff; %@AB@%/* 0x44E */%@AE@%%@NL@%
- struct LOCATE%@NL@%
- {%@NL@%
- unsigned char col;%@NL@%
- unsigned char row;%@NL@%
- } csrpos[8]; %@AB@%/* 0x450 */%@AE@%%@NL@%
- struct CURSIZE%@NL@%
- {%@NL@%
- unsigned char end;%@NL@%
- unsigned char start;%@NL@%
- } csrsize; %@AB@%/* 0x460 */%@AE@%%@NL@%
- char page; %@AB@%/* 0x462 */%@AE@%%@NL@%
- } vid;%@NL@%
- struct LOWMEMVID far *pvid = &vid;%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int page;%@NL@%
- %@NL@%
- %@AB@%/* Move system information into uninitialized structure variable. */%@AE@%%@NL@%
- movedata( 0, 0x449, FP_SEG( pvid ), FP_OFF( pvid ), sizeof( vid ) );%@NL@%
- %@NL@%
- printf( "Move data from low memory 0000:0449 to structure at %Fp\n\n",%@NL@%
- (void far *)&vid );%@NL@%
- %@NL@%
- printf( "Mode:\t\t\t%u\n", vid.vidmode );%@NL@%
- printf( "Page:\t\t\t%u\n", vid.page );%@NL@%
- printf( "Screen width:\t\t%u\n", vid.scrwid );%@NL@%
- printf( "Screen length:\t\t%u\n", vid.scrlen );%@NL@%
- printf( "Cursor size:\t\tstart: %u\tend: %u\n",%@NL@%
- vid.csrsize.start, vid.csrsize.end );%@NL@%
- printf( "Cursor location:\t" );%@NL@%
- for( page = 0; page < 8; page++ )%@NL@%
- printf( "page:\t%u\tcolumn: %u\trow: %u\n\t\t\t",%@NL@%
- page, vid.csrpos[page].col, vid.csrpos[page].row );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NFORMAT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\NFORMAT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* NFORMAT.C: Prints numbers and a string. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int a = -765,%@NL@%
- b = 1,%@NL@%
- c = 44000,%@NL@%
- d = 33;%@NL@%
- float e = 1.33E8,%@NL@%
- f = -0.1234567,%@NL@%
- g = 12345.6789,%@NL@%
- h = 1.0;%@NL@%
- char i[80];%@NL@%
- %@NL@%
- strcpy( i, "word 1, word 2, word 3, word 4, word 5" );%@NL@%
- %@NL@%
- printf( "Unformatted:\n%d %d %d %d\n", a, b, c, d );%@NL@%
- printf( "%f %f %f %f\n", e, f, g, h );%@NL@%
- printf( "%s\n", i );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NOT.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\NOT.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* NOT.C: Demonstrate logical NOT operator. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 0;%@NL@%
- if( !val )%@NL@%
- printf( "val is zero" );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NULLFILE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\NULLFILE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* NULLFILE.C illustrates these functions:%@NL@%
- %@AB@% * chsize umask setmode%@NL@%
- %@AB@% * creat fstat%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<fcntl.h> %@NL@%
- %@AI@%#include %@AE@%<sys\types.h> %@NL@%
- %@AI@%#include %@AE@%<sys\stat.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int fhandle;%@NL@%
- long fsize;%@NL@%
- struct stat fstatus;%@NL@%
- char fname[80];%@NL@%
- %@NL@%
- %@AB@%/* Create a file of a specified length. */%@AE@%%@NL@%
- printf( "What dummy file do you want to create: " );%@NL@%
- gets( fname );%@NL@%
- if( !access( fname, 0 ) )%@NL@%
- {%@NL@%
- printf( "File exists" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Mask out write permission. This means that a later call to open%@NL@%
- %@AB@% * will not be able to set write permission. This is not particularly%@NL@%
- %@AB@% * useful in DOS, but umask is provided primarily for compatibility%@NL@%
- %@AB@% * with systems (such as Unix) that allow multiple permission levels.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- umask( S_IWRITE );%@NL@%
- %@NL@%
- %@AB@%/* Despite write request, file is read only because of mask. */%@AE@%%@NL@%
- if( (fhandle = creat( fname, S_IREAD | S_IWRITE )) == -1 )%@NL@%
- {%@NL@%
- printf( "File can't be created" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Since creat uses the default mode (usually text), you must%@NL@%
- %@AB@% * use setmode to make sure the mode is binary.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- setmode( fhandle, O_BINARY );%@NL@%
- %@NL@%
- printf( "How long do you want the file to be? " );%@NL@%
- scanf( "%ld", &fsize );%@NL@%
- chsize( fhandle, fsize );%@NL@%
- %@NL@%
- %@AB@%/* Display statistics. */%@AE@%%@NL@%
- fstat( fhandle, &fstatus );%@NL@%
- printf( "File: %s\n", fname );%@NL@%
- printf( "Size: %ld\n", fstatus.st_size );%@NL@%
- printf( "Drive %c:\n", fstatus.st_dev + 'A' );%@NL@%
- printf( "Permission: %s\n",%@NL@%
- (fstatus.st_mode & S_IWRITE) ? "Read/Write" : "Read Only" );%@NL@%
- printf( "Created: %s", ctime( &fstatus.st_atime ) );%@NL@%
- %@NL@%
- close( fhandle );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%NUMTOA.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\NUMTOA.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* NUMTOA.C illustrates number to string conversion functions including:%@NL@%
- %@AB@% * itoa ltoa ultoa%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int base, i;%@NL@%
- long l;%@NL@%
- unsigned long ul;%@NL@%
- char buffer[60];%@NL@%
- %@NL@%
- printf( "Enter an integer: " );%@NL@%
- scanf( "%d", &i );%@NL@%
- for( base = 2; base <= 16; base += 2 )%@NL@%
- {%@NL@%
- itoa( i, buffer, base );%@NL@%
- if( base != 10 )%@NL@%
- printf( "%d in base %d is: %s\n", i, base, buffer );%@NL@%
- }%@NL@%
- %@NL@%
- printf( "Enter a long integer: " );%@NL@%
- scanf( "%ld", &l );%@NL@%
- for( base = 2; base <= 16; base += 2 )%@NL@%
- {%@NL@%
- ltoa( l, buffer, base );%@NL@%
- if( base != 10 )%@NL@%
- printf( "%ld in base %d is: %s\n", l, base, buffer );%@NL@%
- }%@NL@%
- %@NL@%
- printf( "Enter an unsigned long integer: " );%@NL@%
- scanf( "%lu", &ul );%@NL@%
- for( base = 2; base <= 16; base += 2 )%@NL@%
- {%@NL@%
- ultoa( ul, buffer, base );%@NL@%
- if( base != 10 )%@NL@%
- printf( "%lu in base %d is: %s\n", ul, base, buffer );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PAGE.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\PAGE.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PAGE.C illustrates video page functions including:%@NL@%
- %@AB@% * _getactivepage _getvisualpage _setactivepage _setvisualpage%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<time.h> %@NL@%
- %@NL@%
- void delay( clock_t wait ); %@AB@%/* Prototype */%@AE@%%@NL@%
- char *jumper[] = { { "\\o/\n O \n/ \\" },%@NL@%
- { "_o_\n O \n( )" },%@NL@%
- { " o \n/O\\\n/ \\" },%@NL@%
- { " o \n O \n( )" }%@NL@%
- };%@NL@%
- main()%@NL@%
- {%@NL@%
- int i, oldvpage, oldapage, oldcursor;%@NL@%
- %@NL@%
- _clearscreen( _GCLEARSCREEN );%@NL@%
- oldcursor = _displaycursor( _GCURSOROFF );%@NL@%
- oldapage = _getactivepage();%@NL@%
- oldvpage = _getvisualpage();%@NL@%
- %@NL@%
- %@AB@%/* Draw image on each page */%@AE@%%@NL@%
- for( i = 0; i < 4; i++ )%@NL@%
- {%@NL@%
- _setactivepage( i );%@NL@%
- _settextposition( 1, 1 );%@NL@%
- _outtext( jumper[i] );%@NL@%
- }%@NL@%
- %@NL@%
- while( !kbhit() )%@NL@%
- %@AB@%/* Cycle through pages 0 to 3 */%@AE@%%@NL@%
- for( i = 0; i < 4; i++ )%@NL@%
- {%@NL@%
- _setvisualpage( i );%@NL@%
- delay( 100L );%@NL@%
- }%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* Restore original page and cursor. */%@AE@%%@NL@%
- _displaycursor( oldcursor );%@NL@%
- _setactivepage( oldapage );%@NL@%
- _setvisualpage( oldvpage );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* delay - Pauses for a specified number of microseconds. */%@AE@%%@NL@%
- void delay( clock_t wait )%@NL@%
- {%@NL@%
- clock_t goal;%@NL@%
- %@NL@%
- goal = wait + clock();%@NL@%
- while( goal > clock() )%@NL@%
- ;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PAGER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\FILE\PAGER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PAGER.C illustrates line input and output on stream text files.%@NL@%
- %@AB@% * Functions illustrated include:%@NL@%
- %@AB@% * fopen fclose fcloseall feof%@NL@%
- %@AB@% * fgets fputs rename%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<io.h> %@NL@%
- %@AI@%#include %@AE@%<dos.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- %@AI@%#define %@AE@%MAXSTRING 128 %@NL@%
- %@AI@%#define %@AE@%PAGESIZE 55 %@NL@%
- enum BOOL { FALSE, TRUE };%@NL@%
- %@NL@%
- void quit( int error );%@NL@%
- FILE *infile, *outfile;%@NL@%
- char outpath[] = "tmXXXXXX";%@NL@%
- %@NL@%
- main( int argc, char *argv[] )%@NL@%
- {%@NL@%
- char tmp[MAXSTRING];%@NL@%
- long line = 0, page = 1;%@NL@%
- int endflag = FALSE;%@NL@%
- %@NL@%
- %@AB@%/* Open file (from command line) and output (temporary) files. */%@AE@%%@NL@%
- if( (infile = fopen( argv[1], "rt" )) == NULL )%@NL@%
- quit( 1 );%@NL@%
- mktemp( outpath );%@NL@%
- if( (outfile = fopen( outpath, "wt" )) == NULL )%@NL@%
- quit( 2 );%@NL@%
- %@NL@%
- %@AB@%/* Get each line from input and write to output. */%@AE@%%@NL@%
- while( 1 )%@NL@%
- {%@NL@%
- %@AB@%/* Insert form feed and page header at the top of each page. */%@AE@%%@NL@%
- if( !(line++ % PAGESIZE) )%@NL@%
- fprintf( outfile, "\f\nPage %d\n\n", page++ );%@NL@%
- %@NL@%
- if( fgets( tmp, MAXSTRING - 1, infile ) == NULL )%@NL@%
- if( feof( infile ) )%@NL@%
- break;%@NL@%
- else%@NL@%
- quit( 3 );%@NL@%
- if( fputs( tmp, outfile ) == EOF )%@NL@%
- quit( 3 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Close files and move temporary file to original by deleting%@NL@%
- %@AB@% * original and renaming temporary.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- fcloseall();%@NL@%
- remove( argv[1] );%@NL@%
- rename( outpath, argv[1] );%@NL@%
- exit( 0 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Handle errors. */%@AE@%%@NL@%
- void quit( int error )%@NL@%
- {%@NL@%
- switch( error )%@NL@%
- {%@NL@%
- case 1:%@NL@%
- perror( "Can't open input file" );%@NL@%
- break;%@NL@%
- case 2:%@NL@%
- perror( "Can't open output file" );%@NL@%
- fclose( infile );%@NL@%
- break;%@NL@%
- case 3:%@NL@%
- perror( "Error processing file" );%@NL@%
- fclose( infile );%@NL@%
- fclose( outfile );%@NL@%
- remove( outpath );%@NL@%
- break;%@NL@%
- }%@NL@%
- exit( error );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PALETTE1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\GRAPHICS\PALETTE1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PALETTE.C illustrates functions for assigning color values to%@NL@%
- %@AB@% * color indexes. Functions illustrated include:%@NL@%
- %@AB@% * _remappalette _remapallpalette%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<graph.h> %@NL@%
- %@AI@%#include %@AE@%<conio.h> %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<stdlib.h> %@NL@%
- %@NL@%
- %@AB@%/* Macro for mixing Red, Green, and Blue elements of color */%@AE@%%@NL@%
- %@AI@%#define %@AE@%RGB(r,g,b) (((long) ((b) << 8 | (g)) << 8) | (r)) %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- short red, blue, green;%@NL@%
- short inc, i, mode, cells, x, y, xinc, yinc;%@NL@%
- long tmp, pal[256];%@NL@%
- char buf[40];%@NL@%
- struct videoconfig vc;%@NL@%
- %@NL@%
- %@AB@%/* Make sure all palette numbers are valid */%@AE@%%@NL@%
- for( i = 0; i < 256; i++ )%@NL@%
- pal[i] = _BLACK;%@NL@%
- %@NL@%
- %@AB@%/* Loop through each graphics mode that supports palettes. */%@AE@%%@NL@%
- for( mode = _MRES4COLOR; mode <= _MRES256COLOR; mode++ )%@NL@%
- {%@NL@%
- if( mode == _ERESNOCOLOR )%@NL@%
- mode++;%@NL@%
- if( !_setvideomode( mode ) )%@NL@%
- continue;%@NL@%
- %@NL@%
- %@AB@%/* Set variables for each mode. */%@AE@%%@NL@%
- _getvideoconfig( &vc );%@NL@%
- switch( vc.numcolors )%@NL@%
- {%@NL@%
- case 256: %@AB@%/* Active bits in this order: */%@AE@%%@NL@%
- cells = 13;%@NL@%
- inc = 12; %@AB@%/* ???????? ??bbbbbb ??gggggg ??rrrrrr */%@AE@%%@NL@%
- break;%@NL@%
- case 16:%@NL@%
- cells = 4;%@NL@%
- if( (vc.mode == _ERESCOLOR) || (vc.mode == _VRES16COLOR) )%@NL@%
- inc = 16; %@AB@%/* ???????? ??????bb ??????gg ??????rr */%@AE@%%@NL@%
- else%@NL@%
- inc = 32; %@AB@%/* ???????? ??????Bb ??????Gg ??????Rr */%@AE@%%@NL@%
- break;%@NL@%
- case 4:%@NL@%
- cells = 2;%@NL@%
- inc = 32; %@AB@%/* ???????? ??????Bb ??????Gg ??????Rr */%@AE@%%@NL@%
- break;%@NL@%
- default:%@NL@%
- continue;%@NL@%
- }%@NL@%
- xinc = vc.numxpixels / cells;%@NL@%
- yinc = vc.numypixels / cells;%@NL@%
- %@NL@%
- %@AB@%/* Fill palette arrays in BGR order */%@AE@%%@NL@%
- for( i = 0, blue = 0; blue < 64; blue += inc )%@NL@%
- for( green = 0; green < 64; green += inc )%@NL@%
- for( red = 0; red < 64; red += inc )%@NL@%
- {%@NL@%
- pal[i] = RGB( red, green, blue );%@NL@%
- %@AB@%/* Special case of using 6 bits to represent 16 colors.%@NL@%
- %@AB@% * If both bits are on for any color, intensity is set.%@NL@%
- %@AB@% * If one bit is set for a color, the color is on.%@NL@%
- %@AB@% */%@AE@%%@NL@%
- if( inc == 32 )%@NL@%
- pal[i + 8] = pal[i] | (pal[i] >> 1);%@NL@%
- i++;%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* If palettes available, remap all palettes at once. */%@AE@%%@NL@%
- if( !_remapallpalette( pal ) )%@NL@%
- {%@NL@%
- _setvideomode( _DEFAULTMODE );%@NL@%
- _outtext( "Palettes not available with this adapter" );%@NL@%
- exit( 1 );%@NL@%
- }%@NL@%
- %@NL@%
- %@AB@%/* Draw colored squares */%@AE@%%@NL@%
- for( i = 0, x = 0; x < vc.numxpixels; x += xinc )%@NL@%
- for( y = 0; y < vc.numypixels; y += yinc )%@NL@%
- {%@NL@%
- _setcolor( i++ );%@NL@%
- _rectangle( _GFILLINTERIOR, x, y, x + xinc, y + yinc );%@NL@%
- }%@NL@%
- sprintf( buf, "Mode %d has %d colors", vc.mode, vc.numcolors );%@NL@%
- _setcolor( vc.numcolors / 2 );%@NL@%
- _outtext( buf );%@NL@%
- getch();%@NL@%
- %@NL@%
- %@AB@%/* Change each palette entry separately in GRB order. */%@AE@%%@NL@%
- for( i = 0, green = 0; green < 64; green += inc )%@NL@%
- for( red = 0; red < 64; red += inc )%@NL@%
- for(blue = 0; blue < 64; blue += inc )%@NL@%
- {%@NL@%
- tmp = RGB( red, green, blue );%@NL@%
- _remappalette( i, tmp );%@NL@%
- if( inc == 32 )%@NL@%
- _remappalette( i + 8, tmp | (tmp >> 1) );%@NL@%
- i++;%@NL@%
- }%@NL@%
- getch();%@NL@%
- }%@NL@%
- exit( !_setvideomode( _DEFAULTMODE ) );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PARRAY.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PARRAY.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PARRAY.C: Demonstrate pointer to array. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int i_array[] = { 25, 300, 2, 12 };%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int *ptr;%@NL@%
- int count;%@NL@%
- ptr = &i_array[0];%@NL@%
- for( count = 0; count < 4 ; count++ )%@NL@%
- {%@NL@%
- printf( "array[%d] = %d\n", count, *ptr );%@NL@%
- ptr++;%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PARRAY1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PARRAY1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PARRAY1.C: Compact version of PARRAY.C. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- int i_array[] = { 25, 300, 2, 12 };%@NL@%
- %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- int *ptr = i_array;%@NL@%
- for( count = 0; count < 4 ; count++ )%@NL@%
- printf( "array[%d] = %d\n", count, *ptr++ );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PFUNC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PFUNC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PFUNC.C: Passing pointers to a function. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- void swap( int *ptr1, int *ptr2 );%@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int first = 1, second = 3;%@NL@%
- int *ptr = &second;%@NL@%
- printf( "first: %d second: %d\n", first, *ptr );%@NL@%
- swap( &first, ptr );%@NL@%
- printf( "first: %d second: %d\n", first, *ptr );%@NL@%
- }%@NL@%
- %@NL@%
- void swap( int *ptr1, int *ptr2 )%@NL@%
- {%@NL@%
- int temp;%@NL@%
- temp = *ptr1;%@NL@%
- *ptr1 = *ptr2;%@NL@%
- *ptr2 = temp;%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%POINTER.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\POINTER.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* POINTER.C: Demonstrate pointer basics. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int val = 25;%@NL@%
- int *ptr;%@NL@%
- ptr = &val;%@NL@%
- printf( " val = %d\n", val );%@NL@%
- printf( "*ptr = %d\n\n", *ptr );%@NL@%
- printf( "&val = %u\n", &val );%@NL@%
- printf( " ptr = %d\n", ptr );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PRINTF.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PRINTF.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PRINTF.C illustrates output formatting with:%@NL@%
- %@AB@% * printf%@NL@%
- %@AB@% *%@NL@%
- %@AB@% * The rules for formatting also apply to cprintf, sprintf, vfprintf,%@NL@%
- %@AB@% * vprintf, and vsprintf. For other examples of printf formatting,%@NL@%
- %@AB@% * see EXTDIR.C (sprintf), VPRINTF (vprintf), TABLE.C (fprintf),%@NL@%
- %@AB@% * ROTATE.C (printf), and IS.C (cprintf).%@NL@%
- %@AB@% */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char ch = 'h', *string = "computer";%@NL@%
- int count = 234, *ptr, hex = 0x10, oct = 010, dec = 10;%@NL@%
- double fp = 251.7366;%@NL@%
- %@NL@%
- %@AB@%/* Display integers. */%@AE@%%@NL@%
- printf("%d %+d %06d %X %x %o\n\n",%@NL@%
- count, count, count, count, count, count );%@NL@%
- %@NL@%
- %@AB@%/* Count characters printed. */%@AE@%%@NL@%
- printf( " V\n" );%@NL@%
- printf( "1234567890123%n45678901234567890\n", &count );%@NL@%
- printf( "Number of characters printed: %d\n\n", count );%@NL@%
- %@NL@%
- %@AB@%/* Display characters. */%@AE@%%@NL@%
- printf( "%10c%5c\n\n", ch, ch );%@NL@%
- %@NL@%
- %@AB@%/* Display strings. */%@AE@%%@NL@%
- printf( "%25s\n%25.4s\n\n", string, string );%@NL@%
- %@NL@%
- %@AB@%/* Display real numbers. */%@AE@%%@NL@%
- printf( "%f %.2f %e %E\n\n", fp, fp, fp, fp );%@NL@%
- %@NL@%
- %@AB@%/* Display in different radixes. */%@AE@%%@NL@%
- printf( "%i %i %i\n\n", hex, oct, dec );%@NL@%
- %@NL@%
- %@AB@%/* Display pointers. */%@AE@%%@NL@%
- ptr = &count;%@NL@%
- printf( "%Np %p %Fp\n", ptr, (int far *)ptr, (int far *)ptr );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PRTESC.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PRTESC.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PRTESC.C: Prints escape characters \",\n, and \t.%@NL@%
- %@AB@%*/%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@AI@%#include %@AE@%<string.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- char b[80];%@NL@%
- int i,j;%@NL@%
- %@NL@%
- strcpy( b, "and seven years ago\n" );%@NL@%
- printf( "\"Four score\n" );%@NL@%
- printf( b );%@NL@%
- printf( "\tone tab\n\t\ttwo tabs\n\t\t\tthree tabs\n" );%@NL@%
- i = sizeof( b );%@NL@%
- j = strlen( b );%@NL@%
- printf( "Size is %d\nLength is %d.\n", i, j );%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PSTRING.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PSTRING.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PSTRING.C: Demonstrate pointer to a string. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@NL@%
- main()%@NL@%
- {%@NL@%
- int count;%@NL@%
- static char name[] = "john";%@NL@%
- char *ptr = name;%@NL@%
- for( count = 0; count < 4; count++ )%@NL@%
- {%@NL@%
- printf( "name[%d]: %c\n", count, *ptr++ );%@NL@%
- }%@NL@%
- }%@NL@%
- %@NL@%
- %@NL@%
- %@2@%%@AH@%PSTRING1.C%@AE@%%@EH@%%@NL@%
- %@AS@%CD-ROM Disc Path: \SAMPCODE\C\OTHER\LEARN\PSTRING1.C%@AE@%%@NL@%
- %@NL@%
- %@AB@%/* PSTRING1.C: Look for null at string's end. */%@AE@%%@NL@%
- %@NL@%
- %@AI@%#include %@AE@%<stdio.h> %@NL@%
- %@