Syntax checker and auto-fixer tool for Fun source files.
More...
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bytecode.h"
#include "parser.h"
Go to the source code of this file.
|
| static void | usage (const char *prog) |
| | Print command-line usage for the funstx tool to stderr.
|
| static int | read_all (const char *path, char **out_buf, size_t *out_len) |
| | Read entire file into a newly allocated buffer.
|
| static int | write_all (const char *path, const char *buf, size_t len) |
| | Overwrite a file with the provided buffer.
|
| static int | is_word (int c) |
| | Determine whether a character is an identifier constituent.
|
| static char * | apply_fixes (const char *src, size_t len, size_t *out_len) |
| | Apply conservative style/syntax auto-fixes to a Fun source buffer.
|
| int | main (int argc, char **argv) |
| | Entry point for funstx.
|
Syntax checker and auto-fixer tool for Fun source files.
Definition in file funstx.c.
◆ apply_fixes()
| char * apply_fixes |
( |
const char * | src, |
|
|
size_t | len, |
|
|
size_t * | out_len ) |
|
static |
Apply conservative style/syntax auto-fixes to a Fun source buffer.
Fixes include:
- Normalize indentation to 2 spaces (tabs become 2 spaces per tab)
- Convert CRLF/CR line endings to LF
- Trim trailing spaces on each line
- Ensure the file ends with a single LF
- Normalize identifiers 'sint8/16/32/64' to 'int8/16/32/64' at word boundaries
Returns a newly allocated buffer containing the fixed content and writes the resulting length to out_len. Caller must free the returned buffer.
- Parameters
-
| src | Input buffer. |
| len | Input length. |
| out_len | Output length of fixed buffer. |
- Returns
- Newly malloc'd fixed buffer on success, or NULL on OOM.
Definition at line 116 of file funstx.c.
◆ is_word()
Determine whether a character is an identifier constituent.
- Parameters
-
| c | Character code (unsigned char promoted to int). |
- Returns
- Non-zero if c is '_' or an alphanumeric character.
Definition at line 94 of file funstx.c.
◆ main()
| int main |
( |
int | argc, |
|
|
char ** | argv ) |
Entry point for funstx.
Parses flags, optionally applies in-place fixes (–fix), and validates each provided Fun source file by attempting to parse it. With –quiet, only errors are printed; otherwise, prints "OK" for valid files.
- Parameters
-
| argc | Argument count. |
| argv | Argument vector. |
- Returns
- 0 if all files are valid (and fixes succeeded if requested), non-zero otherwise.
Definition at line 299 of file funstx.c.
◆ read_all()
| int read_all |
( |
const char * | path, |
|
|
char ** | out_buf, |
|
|
size_t * | out_len ) |
|
static |
Read entire file into a newly allocated buffer.
The returned buffer is NUL-terminated for convenience. Caller must free it.
- Parameters
-
| path | Path to file to read. |
| out_buf | Output pointer to receive malloc'd buffer. |
| out_len | Output length of the file (without the terminating NUL). |
- Returns
- 1 on success, 0 on failure.
Definition at line 41 of file funstx.c.
◆ usage()
| void usage |
( |
const char * | prog | ) |
|
|
static |
Print command-line usage for the funstx tool to stderr.
- Parameters
-
| prog | Program name (argv[0]). May be NULL. |
Definition at line 27 of file funstx.c.
◆ write_all()
| int write_all |
( |
const char * | path, |
|
|
const char * | buf, |
|
|
size_t | len ) |
|
static |
Overwrite a file with the provided buffer.
- Parameters
-
| path | Target file path. |
| buf | Buffer to write. |
| len | Number of bytes to write. |
- Returns
- 1 on success, 0 otherwise.
Definition at line 80 of file funstx.c.