Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
funstx.c File Reference

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"
Include dependency graph for funstx.c:

Go to the source code of this file.

Functions

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.

Detailed Description

Syntax checker and auto-fixer tool for Fun source files.

Definition in file funstx.c.

Function Documentation

◆ 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
srcInput buffer.
lenInput length.
out_lenOutput 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()

int is_word ( int c)
static

Determine whether a character is an identifier constituent.

Parameters
cCharacter 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
argcArgument count.
argvArgument 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
pathPath to file to read.
out_bufOutput pointer to receive malloc'd buffer.
out_lenOutput 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
progProgram 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
pathTarget file path.
bufBuffer to write.
lenNumber of bytes to write.
Returns
1 on success, 0 otherwise.

Definition at line 80 of file funstx.c.