| 1 | /* stdio.h: The CIVL representation of standard C library stdio.
|
|---|
| 2 | * Based on C11 Standard.
|
|---|
| 3 | */
|
|---|
| 4 | #ifdef __STDIO__
|
|---|
| 5 | #else
|
|---|
| 6 | #define __STDIO__
|
|---|
| 7 |
|
|---|
| 8 | /* Needed from stdarg.h: */
|
|---|
| 9 |
|
|---|
| 10 | typedef struct _ABC_va_list {
|
|---|
| 11 | int x;
|
|---|
| 12 | } va_list;
|
|---|
| 13 |
|
|---|
| 14 | /* Types */
|
|---|
| 15 |
|
|---|
| 16 | typedef unsigned long int size_t;
|
|---|
| 17 |
|
|---|
| 18 | /* Represents an actual file: something with a name and contents.
|
|---|
| 19 | * The name is a string (array of char). The contents is an
|
|---|
| 20 | * array of strings: each entry is a "chunk" of the file; the
|
|---|
| 21 | * file may be viewed as a concatenation of those chunks.
|
|---|
| 22 | */
|
|---|
| 23 | typedef struct CIVL_file_t {
|
|---|
| 24 | char name[]; /* name of file */
|
|---|
| 25 | char contents[][]; /* list of strings which form file contents */
|
|---|
| 26 | _Bool isOutput; /* is this an output file? */
|
|---|
| 27 | _Bool isInput; /* is this an input file? */
|
|---|
| 28 | _Bool isBinary; /* can be binary or text */
|
|---|
| 29 | _Bool isWide; /* wide orientation */
|
|---|
| 30 | } CIVL_file_t;
|
|---|
| 31 |
|
|---|
| 32 | /* Implements the C notion of a FILE, which is really a reference
|
|---|
| 33 | * into a particular point of an actual file. Even if you are just
|
|---|
| 34 | * reading the file, this FILE object changes since it contains a reference
|
|---|
| 35 | * to the point of file you just read.
|
|---|
| 36 | *
|
|---|
| 37 | */
|
|---|
| 38 | typedef struct FILE {
|
|---|
| 39 | CIVL_file_t *file; // the actual file to which this refers
|
|---|
| 40 | int pos1; // the chunk index (first index) in the contents
|
|---|
| 41 | int pos2; // the character index (second index) in the contents
|
|---|
| 42 | int mode; // Stream mode: r/w/a
|
|---|
| 43 | _Bool isOpen; // is this FILE open?
|
|---|
| 44 | } FILE;
|
|---|
| 45 |
|
|---|
| 46 | typedef int fpos_t;
|
|---|
| 47 |
|
|---|
| 48 | /* Macros */
|
|---|
| 49 |
|
|---|
| 50 | #define NULL ((void*)0)
|
|---|
| 51 | #define _IOFBF 1
|
|---|
| 52 | #define _IOLBF 2
|
|---|
| 53 | #define _IONBF 3
|
|---|
| 54 | #define BUFSIZ 100
|
|---|
| 55 | #define EOF (-100)
|
|---|
| 56 | #define FOPEN_MAX 100
|
|---|
| 57 | #define FILENAME_MAX 500
|
|---|
| 58 | #define L_tmpnam 500
|
|---|
| 59 | #define SEEK_CUR 1
|
|---|
| 60 | #define SEEK_END 2
|
|---|
| 61 | #define SEEK_SET 3
|
|---|
| 62 | #define TMP_MAX 100
|
|---|
| 63 | #define stdin (FILE*)0
|
|---|
| 64 | #define stdout (FILE*)1
|
|---|
| 65 | #define stderr (FILE*)2
|
|---|
| 66 |
|
|---|
| 67 | /* Global Variables */
|
|---|
| 68 |
|
|---|
| 69 | // inputs: none, using abstract functions instead
|
|---|
| 70 |
|
|---|
| 71 | // global state variables...
|
|---|
| 72 |
|
|---|
| 73 | /* The files in the file system. Initially empty array.
|
|---|
| 74 | * When a file is opened, a new actual file will be created
|
|---|
| 75 | * and added to this list, if a file by that name is not
|
|---|
| 76 | * already in this list. The state of this array and
|
|---|
| 77 | * the files in this array change during execution.
|
|---|
| 78 | */
|
|---|
| 79 | CIVL_file_t CIVL_files[];
|
|---|
| 80 |
|
|---|
| 81 | // outputs:
|
|---|
| 82 |
|
|---|
| 83 | /* The files which were modified or created are written here
|
|---|
| 84 | * at the end of the program. They constitute outputs of
|
|---|
| 85 | * the program. The files will be sorted in some canonical
|
|---|
| 86 | * way.
|
|---|
| 87 | */
|
|---|
| 88 | $output CIVL_file_t CIVL_output_files[];
|
|---|
| 89 |
|
|---|
| 90 | /* Function Prototypes */
|
|---|
| 91 |
|
|---|
| 92 | #include<stdio-common.h>
|
|---|
| 93 |
|
|---|
| 94 | #endif
|
|---|
| 95 |
|
|---|