Watcom C Library : _setgtextvector, setjmp, _setlinestyle, setlocale, setmode
Watcom C Reference/S 2021. 10. 27. 20:29
Watcom C Library Reference : _setgtextvector, setjmp, _setlinestyle, setlocale, setmode
_setgtextvector
Synopsis : #include <graph.h>
struct xycoord _FAR _setgtextvector( short x, short y );
Description : The _setgtextvector function sets the orientation for text output used by the _outgtext function to the vector specified by the arguments (x, y). Each of the arguments can have a value of -1, 0 or 1, allowing for text to be displayed at any multiple of a 45-degree angle. The default text orientation, for normal left-to-right text, is the vector (1, 0).
Returns : The _setgtextvector function returns, as an xycoord structure, the previous value of the text orientation vector.
See Also : _registerfonts, _unregisterfonts, _setfont, -getfontinfo, _outgtext, _getgtextextent, _getgtextvector
Example :
#include <conio.h>
#include <graph.h>
void main( )
{
struct xycoord old_vec;
_setvideomode( _VRES16COLOR );
old_vec = _getgtextvector( );
_setgtextvector( 0, -1 );
_moveto( 100, 100 );
_outgtext( "WATCOM Graphics" );
_setgtextvector( old_vec.xcoord, old_vec.ycoord );
getch( );
_setvideomode( _DEFAULTMODE );
}
Classification : PC Graphics
Systems : DOS, QNX
setjmp
Synopsis : #include <setjmp.h>
int setjmp( jmp_buf env );
Description : The setjmp function saves its calling environment in its jmp_buf argument, for subsequent use by the longjmp function.
In some cases, error handling can be implemented by using setjmp to record the point to nich a return will occur following an error. When an error is detected in a called function, that function uses longimp to jump back to the recorded position. The original function Which called setjmp must still be active (it cannot have returned to the function which called it).
Special care must be exercised to ensure that any side effects that are left undone (allocated memory, opened files, etc.) are satisfactorily handied.
Returns : The setjmp function returns zero when it is initially called. The return value will be non-zero if the return is the result of a call to the longjmp function. An if statement is often used to handle these two returns. When the return value is zero, the initial call to setjmp has been made; when the return value is non-zero, a return from a longjmp has just occurred.
See Also : longjmp
Example :
/* show LONGJMP, SETJMP */
#include <stdio.h>
#include <setjmp.h>
jmp_buf env;
void main( )
{
int ret_val;
ret_val = 293;
if( 0 == ( ret_val = setjmp ( env ) ) ) {
printf( "after setjmp %d\n", ret_val );
rtn( );
printf( "back from rtn %d\n", ret_val );
} else {
printf( "back from longjmp %d\n", ret_val );
}
}
void rtn( )
{
printf( "about to longjmp \n" );
longjmp( env, 14 ) ;
}
produces the following :
after setjmp 0
about to longjmp
back from longjmp 14
Classification : ANSI
Systems : MACRO
_setlinestyle
Synopsis : #include <graph.h>
void _FAR _setlinestyle( unsigned short style );
Description : The _setlinestyle function sets the current line-style mask to the value of the style argument.
The line-style mask determines the style by which lines and arcs are drawn. The mask is treated as an array of 16 bits. As a line is drawn, a pixel at a time, the bits in this array are cyclically tested. When a bit in the array is 1, the pixel value for the current point is set using the current color according to the current plotting action; otherwise, the pixel value for the point is left unchanged. A solid line would result from a value of 0xFFFF and a dashed line would result from a value of 0xF0F0
The default line style mask is 0xFFFF
Returns : The _setlinestyle function does not return a value.
See Also : _getlinestyle, _lineto, _rectangle, _polygon, _setplotaction
Example :
#include <conio.h>
#include <graph.h>
#define DASHED 0xf0f0
void main( )
{
unsigned old_style;
_setvideomode( _VRES16COLOR );
old_style = _getlinestyle( );
_setlinestyle( DASHED );
_rectangle( _GBORDER, 100, 100, 540, 380 );
_setlinestyle( old style );
getch( );
_setvideomode( _DEFAULTMODE );
}
produces the following :
Classification : PC Graphics
Systems : DOS, QNX
setlocale
Synopsis : #include <locale.h>
char *setlocale( int category, const char *locale );
Description : The setlocale function selects a portion of a program's locale according to the category given by category and the locale specified by locale. A locale affects the collating sequence (the order in which characters compare with one another), the way in which certain character-handling functions operate, the decimal-point character that is used in formatted input/output and string conversion, and the format and names used in the time string produced by the strftime function.
Potentially, there may be many such environments. WATCOM C supports only the "C" locale and so invoking this function will have no effect upon the behavior of a program at present.
The possible values for the argument category are as follows:
Category | Meaning |
LC_ALL | select entire environment |
LC_COLLATE | select collating sequence |
LC_CTYPE | select the character-handling |
LC_MONETARY | select monetary formatting information |
LC_NUMERIC | select the numeric-format environment |
LC_TIME | select the time-related environment |
At the start of a program, the equivalent of the following statement is executed.
setlocale( LC_ALL, "C" );
Returns : If the selection is successful, a string is returned to indicate the locale that was in effect before the function was invoked; otherwise, a NULL pointer is returned.
See Also : strcoll, strftime, strxfrm
Example :
#include <stdio.h>
#include <string.h>
#include <locale.h>
char src[] = { "A sample STRING" };
char dst[20];
void main( )
{
char *prev_locale;
size_t len;
/* set native locale */
prev_locale = setlocale( LC_ALL, "" );
printf( "%s\n", prev_locale );
len = strxfrm( dst, src, 20 );
printf( "%s (%u) \n", dst, len );
}
produces the following :
C
A sample STRING (15)
Classification : ANSI, POSIX 1003.1
Systems : All
setmode
Synopsis : #include <io.h>
#include <fcntl.h>
int setmode( int handle, int mode );
Description : The setmode function sets, at the operating system level, the translation mode to be the value of mode for the file whose file handle is given by handle. The mode, defined in the <fcntl.h> header file, can be one of:
Mode | Meaning |
O_TEXT | On input, a carriage-return character that immediately precedes a linefeed character is removed from the data that is read. On output, a carriage-return character is inserted before each linefeed character. |
O_BINARY | Data is read or written unchanged. |
Returns : If successful, the function returns the previous mode that was set for the file; otherwise, -1 is returned. When an error has occurred, errno contains a value indicating the type of error that has been detected.
See Also : chsize, close, creat, dup, dup2, eof, exec Functions, filelength, fileno, fstat, isatty, lseek, open, read, sopen, stat, tell, write, umask
Example :
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
void main( )
{
FILE *fp;
long count;
fp = fopen( "file", "rb" );
if( fp != NULL ) {
setmode( fileno( fp ), O_BINARY );
count = 0L;
while( fgetc ( fp) != EOF ) ++count;
printf( "File contains %lu characters\n", count );
fclose( fp );
}
}
Classification : WATCOM
Systems : All
This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).
WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)