source: CIVL/include/impls/stdio.cvl@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[31bfa34]1/* stdio.cvl: a stateless I/O library similar to the C standard library stdio.
2 * The functions defined here are similar to those in stdio, but take an extra
3 * argument of type $filesystem. This is a handle type. A filesystem object
4 * encapsulates the state of the entire file system: all files and their contents.
5 *
6 */
[bf584ca]7 #ifndef __STDIO_CVL__
[f6ecaae]8 #define __STDIO_CVL__
[6f8bc6ea]9
[6185d35]10#include <civlc.cvh>
11#include <stdio.h>
[a1f42a0]12#include<civl-stdio.cvh>
[6185d35]13#include <seq.cvh>
[aaa9c8d]14
[e93c797]15#pragma CIVL ACSL
[aaa9c8d]16
[31bfa34]17/* ******************************* Types ******************************* */
18
19/* Represents an actual file: something with a name and contents.
20 * The name is a string (array of char). The contents is an
21 * array of strings: each entry is a "chunk" of the file; the
22 * file may be viewed as a concatenation of those chunks.
23 *
24 * A "point" in the file is represented by an ordered pair
25 * of integers (chunkIndex, characterIndex).
26 *
27 * The flags all have int type instead of boolean because
28 * CVC3 does not support tuples with boolean components.
29 * Zero is used for false, one for true.
30 * A file is an output file if it is ever written to.
31 * A file is an input file if it is ever read before being written to.
32 * A file can be both an input and an output file.
33 * A file is either a binary or text file. The kind is determined
34 * by how the file is opened.
35 * A file is either an ordinary character file or a wide character
36 * file. The orientation is determined by the first access to the
37 * file.
38 */
[a1f42a0]39struct $file {
[31bfa34]40 char name[]; /* name of file */
41 char contents[][]; /* list of strings which form file contents */
42 int isOutput; /* is this an output file? */
43 int isInput; /* is this an input file? */
44 int isBinary; /* is this a binary file (not text)? */
45 int isWide; /* does this file have wide orientation? */
[4bac71b]46 int length;
[a1f42a0]47};
[31bfa34]48
49/* A file system: a set of files. The files in the array can be
50 * sorted in some canonical way. $filesystem is a handle type. */
[a1f42a0]51struct CIVL_filesystem {
[31bfa34]52 $scope scope;
53 $file files[];
[a1f42a0]54};
[31bfa34]55
56
57/* Implements the C notion of a FILE, which is really a reference
58 * into a particular point of an actual file. Even if you are just
59 * reading the file, this FILE object changes since it contains a reference
60 * to the point of file you just read.
61 */
[6f8bc6ea]62struct FILE {
[31bfa34]63 $file *file; // the actual file to which this refers
64 $filesystem fs; // file system to which this FILE is associated
65 int pos1; // the chunk index (first index) in the contents
66 int pos2; // the character index (second index) in the contents
[556bc65]67 CIVL_File_mode mode; // stream mode
[31bfa34]68 int isOpen; // is this FILE open (0 or 1)?
[6f8bc6ea]69};
[31bfa34]70
71/* Creates a new empty file system, returning a handle to it. */
[6185d35]72/*@ depends_on \nothing;
73 @ assigns \nothing;
74 @ reads \nothing;
[d98b14a]75 @ executes_when \true;
[6185d35]76 @*/
[a1f42a0]77$atomic_f $filesystem $filesystem_create($scope scope){
[6185d35]78 $filesystem fileSys=($filesystem)$malloc(scope, sizeof(struct CIVL_filesystem));
79
80 fileSys->scope=scope;
81 $seq_init(&fileSys->files, 0, NULL);
82 return fileSys;
83}
[31bfa34]84
[6f8bc6ea]85void _fflush(void){
86 return;
87}
[f6ecaae]88
89#endif
Note: See TracBrowser for help on using the repository browser.