Antwort schreiben...
 
Themen-Optionen Thema durchsuchen
Alt 09.10.2012, 23:52   #71
leecher
Moderator
KBHIT

E r g e b n i s / R e s u l t

Checks the console for keyboard input.

B e s c h r e i b u n g / D e s c r i p t i o n

The KBHIT function checks the console for a recent keystroke. If the function returns TRUE, a keystroke is waiting in the buffer. The program can then call GETCH to get the keystroke.


S y n t a x

Code:
boolhit = call ('KBHIT')
P a r a m e t e r

R e t u r n s

KBHIT returns TRUE if a key has been pressed, otherwise, it returns FALSE

B e i s p i e l / E x a m p l e

Code:
attach 'CONIO'
WHILE CALL("KBHIT") = false
  PUT AT 1,1 "HIT ME"
END WHILE
PUT AT 1,1 CALL ("GETCH")
detach 'CONIO'
leecher ist offline   Mit Zitat antworten
Alt 09.10.2012, 23:59   #72
leecher
Moderator
GET_KEY

E r g e b n i s / R e s u l t

The same function as GETCH, but doesn't wait for a key pressed, if no character is in buffer, instead always returns immediately.

B e s c h r e i b u n g / D e s c r i p t i o n

See GETCH documentation.


S y n t a x

Code:
key = call ('GET_KEY')
P a r a m e t e r

R e t u r n s

See GETCH documentation.

B e i s p i e l / E x a m p l e

Code:
attach 'CONIO'
WHILE CALL("KBHIT") = false
  PUT AT 1,1 "HIT ME"
END WHILE
PUT AT 1,1 CALL ("GET_KEY")
detach 'CONIO'
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 00:40   #73
leecher
Moderator
GETXKEY

E r g e b n i s / R e s u l t

Returns the scancode of a character in the console buffer, if available.

B e s c h r e i b u n g / D e s c r i p t i o n

If there is a character in the Keyboard-buffer, return its scancode as a result.


S y n t a x

Code:
scode = call ('GETXKEY')
P a r a m e t e r

R e t u r n s

Scancode of the character in the keyboard buffer, if any

B e i s p i e l / E x a m p l e

Code:
attach 'CONIO'
WHILE CALL("KBHIT") = false
  PUT AT 1,1 "HIT ME"
END WHILE
PUT AT 1,1 CALL ("GETXKEY")  ! i.e., if you press F1, returns 315 (0x100+0x3B = 0x13B)
detach 'CONIO'
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 01:05   #74
leecher
Moderator
C_OPEN

E r g e b n i s / R e s u l t

The C_OPEN function opens the file specified by filename and returns a file descriptor to it.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_OPEN function opens the file specified by filename in the given mode and returns a file descriptor for later use by the other file-functions.

S y n t a x

Code:
fd = call ('C_OPEN' , filename, mode)
P a r a m e t e r

filename - Filename
mode - Type of access permitted

The character string mode specifies the type of access requested for the file, as follows:

"r"
Opens for reading. If the file does not exist or cannot be found, the fopen call fails.

"w"
Opens an empty file for writing. If the given file exists, its contents are destroyed.

"a"
Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn‚t exist.

"r+"
Opens for both reading and writing. (The file must exist.)

"w+"
Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"a+"
Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn‚t exist.


R e t u r n s

A valid file descriptor or -1 on error.
You have to close the file descriptor after work with the C_CLOSE function.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
fd = CALL ("C_OPEN", "FILE1.TXT", "r")
PUT CALL ("C_READ", fd, 10)
b = CALL("C_CLOSE", fd)
detach 'FILE0'
Angehängte Dateien
Dateityp: oac FILE0.OAC‎ (21.0 KB, 5x aufgerufen)
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 01:29   #75
leecher
Moderator
C_READ

E r g e b n i s / R e s u l t

The C_READ function reads data from a file previously opened by C_OPEN.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_READ function reads data from the file specified by the filedescriptor fd to a string. The maximum length can be 254 characters.

S y n t a x

Code:
res = call ('C_READ' , fd, len)
P a r a m e t e r

fd - The file descriptor you obtained from C_OPEN
len - The number of characters to read from file, 254 max.

R e t u r n s

A string containing the requested data plus an additional char at the end representing the return code.
If data could be read successfully, the return code is 0. On EOF, the return code is 1.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
fd = CALL ("C_OPEN", "FILE.TXT", "r")
ret = CALL ("C_READ", fd, 3)
lret = LENGTH(ret)
rc = EXTRACT(ret, lret, 1)
rcstr = EXTRACT(ret, 1, lret-1)
PUT AT 1,1 rc   ! Writes the return code to the first line, usually 0 
PUT AT 1,2 rcstr   ! Writes the string read to the second line
b = CALL("C_CLOSE", fd)
detach 'FILE0'
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 01:41   #76
leecher
Moderator
C_WRITE

E r g e b n i s / R e s u l t

The C_WRITE function writes data to a file previously opened by C_OPEN.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_WRITE function writes data to the file specified by the filedescriptor fd. The maximum number of bytes to write can be 254 characters.

S y n t a x

Code:
res = call ('C_WRITE' , fd, str, len)
P a r a m e t e r

fd - The file descriptor you obtained from C_OPEN
str - The string which contains the data to write
len - The number of characters to write to the file, 254 max.

R e t u r n s

The number of bytes written or -1 on error.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
fd = CALL ("C_OPEN", "FILE.TXT", "w")
PUT CALL ("C_WRITE", fd, "blabla", 6)
b = CALL("C_CLOSE", fd)
detach 'FILE0'
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 01:45   #77
leecher
Moderator
C_CLOSE

E r g e b n i s / R e s u l t

The C_CLOSE function closes a file descriptor you obtained from C_OPEN.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_CLOSE function closes the filedescriptor fd.

S y n t a x

Code:
res = call ('C_CLOSE' , fd)
P a r a m e t e r

fd - The file descriptor you obtained from C_OPEN

R e t u r n s

0 on success, -1 on error.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
fd = CALL ("C_OPEN", "FILE.TXT", "w")
b = CALL("C_CLOSE", fd)
detach 'FILE0'
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 02:00   #78
leecher
Moderator
C_EOF

E r g e b n i s / R e s u l t

The C_EOF function tests for end-of-file.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_EOF function returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file. There is no error return.

S y n t a x

Code:
res = call ('C_EOF' , fd)
P a r a m e t e r

fd - The file descriptor you obtained from C_OPEN

R e t u r n s

1 on end of file, 0 if not.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
attach 'FILE1'
! Create empty file
fd = CALL ("C_OPEN", "FILE.TXT", "w")
b = CALL("C_CLOSE", fd)

! Try to read from empty file
fd = CALL ("C_OPEN", "FILE.TXT", "r")
PUT CALL ("C_EOF", fd) ! Returns 1, as file has 0 bytes and we are at EOF
b = CALL("C_CLOSE", fd)
detach 'FILE0'
detach 'FILE1'
Angehängte Dateien
Dateityp: oac FILE1.OAC‎ (12.5 KB, 3x aufgerufen)
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 02:08   #79
leecher
Moderator
C_LSEEK

E r g e b n i s / R e s u l t

The C_LSEEK function moves a file pointer to the specified location.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_LSEEK function moves the file pointer associated with the file descriptor fd to a new location that is offset bytes from origin. The next operation on the file occurs at the new location.

S y n t a x

Code:
res = call ('C_LSEEK' , fd, offset, origin)
P a r a m e t e r

fd - The file descriptor you obtained from C_OPEN
offset - Number of bytes from origin
origin - Initial position

origin can be one of the following values:
0 - Seek relative to begining of file
1 - Seek relative to current file position
2 - Seek relative to end of file

R e t u r n s

C_LSEEK returns the offset, in bytes, of the new position from the beginning of the file.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
attach 'FILE1'
fd = CALL ("C_OPEN", "FILE.TXT", "r")
PUT CALL ("C_LSEEK", fd, 0, 2) ! Seeks to end of file, therefore returns filesize
b = CALL("C_CLOSE", fd)
detach 'FILE0'
detach 'FILE1'
leecher ist offline   Mit Zitat antworten
Alt 10.10.2012, 02:13   #80
leecher
Moderator
C_TELL

E r g e b n i s / R e s u l t

The C_TELL function gets the current position of a file pointer.

B e s c h r e i b u n g / D e s c r i p t i o n

The C_TELL function gets the current position of the file pointer associated with the file descriptor fd.

S y n t a x

Code:
res = call ('C_TELL' , fd)
P a r a m e t e r

fd - The file descriptor you obtained from C_OPEN

R e t u r n s

C_TELL returns the offset, in bytes, of the current position from the beginning of the file or -1 on error.

B e i s p i e l / E x a m p l e

Code:
attach 'FILE0'
attach 'FILE1'
fd = CALL ("C_OPEN", "FILE.TXT", "w")
b = CALL ("C_WRITE", fd, "12345", 5)
PUT CALL ("C_TELL", fd) ! Returns 5 as this is the current offset in the file
b = CALL("C_CLOSE", fd)
detach 'FILE0'
detach 'FILE1'
leecher ist offline   Mit Zitat antworten


Antwort schreiben...

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche