diff --git a/4coder_API.html b/4coder_API.html index 3ec9d69d..b0d1fd9c 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -2,7 +2,7 @@

4coder API

Table of Contents

§1 Introduction

This is the documentation for the 4cpp lexer version 1.1. The documentation is the newest piece of this lexer project so it may still have problems. What is here should be correct and mostly complete.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

This is the documentation for alpha 4.0.12 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

§2 4coder Systems

Coming Soon
-

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. +

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. If command_id is invalid a warning is posted to *messages*.

See Also

§3.3.2: exec_system_command

bool32 exec_system_command(
Application_Links *app,
View_Summary *view,
Buffer_Identifier buffer,
char *path,
int32_t path_len,
char *command,
int32_t command_len,
Command_Line_Interface_Flag flags
)
Parameters
view
If the view parameter is non-null it specifies a view to display the command's output buffer.
buffer
The buffer the command will output to is specified by the buffer parameter. See Buffer_Identifier for information on how this type specifies a buffer.
path
The path parameter specifies the path in which the command shall be executed. The string need not be null terminated.
path_len
The parameter path_len specifies the length of the path string.
command
The command parameter specifies the command that shall be executed. The string need not be null terminated.
command_len
The parameter command_len specifies the length of the command string.
flags
Flags for the behavior of the call are specified in the flags parameter.
Return
This call returns non-zero on success.
Description
A call to exec_system_command executes a command as if called from the command line, and sends the output to a buffer. The buffer identifier can either name a new buffer that does not exist, name a buffer that does @@ -70,33 +70,33 @@ GUI element that can overlap a buffer or other 4coder GUI. The contents of the can be changed after the call to start_query_bar and the query bar shown by 4coder will reflect the change. Since the bar stops showing when the command exits the only use for this call is in an interactive command that makes calls to get_user_input.


§3.3.47: end_query_bar

void end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter should be a bar pointer of a currently active query bar.
flags
This parameter is not currently used and should be 0 for now.
Description
Stops showing the particular query bar specified by the bar parameter.



§3.3.49: change_theme

void change_theme(
Application_Links *app,
char *name,
int32_t len
)
Parameters
name
The name parameter specifies the name of the theme to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call changes 4coder's color pallet to one of the built in themes.


§3.3.50: change_font

void change_font(
Application_Links *app,
char *name,
int32_t len,
bool32 apply_to_all_files
)
Parameters
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
apply_to_all_files
If this is set all open files change to this font. Usually this should be true -durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.51: buffer_set_font

void buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.52: set_theme_colors

void set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the +durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.51: buffer_set_font

void buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.52: buffer_get_font

int32_t buffer_get_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name_out,
int32_t name_max
)
No documentation generated for this function.

§3.3.53: set_theme_colors

void set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the struct's tag is set to the color code in the struct. If the tag value is invalid -no change is made to the color pallet.


§3.3.53: get_theme_colors

void get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the +no change is made to the color pallet.


§3.3.54: get_theme_colors

void get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the color from the slot in the main color pallet specified by the tag. If the tag -value is invalid the color is filled with black.


§3.3.54: directory_get_hot

int32_t directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently +value is invalid the color is filled with black.


§3.3.55: directory_get_hot

int32_t directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory.

In the future this will be deprecated and eliminated in favor of more flexible -directories controlled on the custom side.


§3.3.55: get_file_list

File_List get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in +directories controlled on the custom side.


§3.3.56: get_file_list

File_List get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in the specified directory. The File_List returned should be passed to free_file_list -when it is no longer in use.

§3.3.56: free_file_list

void free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.57: memory_allocate

void* memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used +when it is no longer in use.

§3.3.57: free_file_list

void free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.58: memory_allocate

void* memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used for infrequent, large allocations. The size of the block must be remembered -if it will be freed or if it's mem protection status will be changed.

See Also
memory_free

§3.3.58: memory_set_protection

bool32 memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously -allocate by memory_allocate.

See Also
memory_allocate
Memory_Protect_Flags

§3.3.59: memory_free

void memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by -memory_allocate.

See Also
memory_allocate

§3.3.60: file_exists

bool32 file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.61: directory_cd

bool32 directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the +if it will be freed or if it's mem protection status will be changed.

See Also
memory_free

§3.3.59: memory_set_protection

bool32 memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously +allocate by memory_allocate.

See Also
memory_allocate
Memory_Protect_Flags

§3.3.60: memory_free

void memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by +memory_allocate.

See Also
memory_allocate

§3.3.61: file_exists

bool32 file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.62: directory_cd

bool32 directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the dir buffer. If the call succeeds the dir buffer is filled with the new directory and len is overwritten with the length of the new string in the buffer.

For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer will contain "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent -folders.


§3.3.62: get_4ed_path

bool32 get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.63: show_mouse_cursor

void show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also
Mouse_Cursor_Show_Type

§3.3.64: toggle_fullscreen

void toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. +folders.


§3.3.63: get_4ed_path

bool32 get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.64: show_mouse_cursor

void show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also
Mouse_Cursor_Show_Type

§3.3.65: toggle_fullscreen

void toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. The changes of full screen mode do not take effect until the end of the current frame. On Windows this call will not work unless 4coder was started in "stream mode". -Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.65: is_fullscreen

bool32 is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call +Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.66: is_fullscreen

bool32 is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call takes toggles that have already occured this frame into account. So it may return true even though the frame has not ended and actually put 4coder into full screen. If it returns true though, 4coder will definitely be full screen by the beginning of the next -frame if the state is not changed.


§3.3.66: send_exit_signal

void send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved +frame if the state is not changed.


§3.3.67: send_exit_signal

void send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved files this triggers a dialogue ensuring you're okay with closing.


§3.4 Type Descriptions

§3.4.1: bool32

typedef int32_t bool32;
Description
bool32 is an alias name to signal that an integer parameter or field is for true/false vales.


§3.4.2: int_color

typedef uint32_t int_color;
Description
int_color is an alias name to signal that an integer parameter or field is for a color value, colors are specified as 24 bit integers in 3 channels: 0xRRGGBB.


§3.4.3: Key_Code

typedef unsigned char Key_Code;
Description
Key_Code is the alias for key codes including raw codes and codes translated diff --git a/4coder_custom_api.h b/4coder_custom_api.h index b78bcdbf..b1e8075f 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -49,6 +49,7 @@ #define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int32_t len) #define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files) #define BUFFER_SET_FONT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len) +#define BUFFER_GET_FONT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) #define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity) @@ -115,6 +116,7 @@ typedef PRINT_MESSAGE_SIG(Print_Message_Function); typedef CHANGE_THEME_SIG(Change_Theme_Function); typedef CHANGE_FONT_SIG(Change_Font_Function); typedef BUFFER_SET_FONT_SIG(Buffer_Set_Font_Function); +typedef BUFFER_GET_FONT_SIG(Buffer_Get_Font_Function); typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function); typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function); typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function); @@ -183,6 +185,7 @@ Print_Message_Function *print_message; Change_Theme_Function *change_theme; Change_Font_Function *change_font; Buffer_Set_Font_Function *buffer_set_font; +Buffer_Get_Font_Function *buffer_get_font; Set_Theme_Colors_Function *set_theme_colors; Get_Theme_Colors_Function *get_theme_colors; Directory_Get_Hot_Function *directory_get_hot; @@ -250,6 +253,7 @@ Print_Message_Function *print_message_; Change_Theme_Function *change_theme_; Change_Font_Function *change_font_; Buffer_Set_Font_Function *buffer_set_font_; +Buffer_Get_Font_Function *buffer_get_font_; Set_Theme_Colors_Function *set_theme_colors_; Get_Theme_Colors_Function *get_theme_colors_; Directory_Get_Hot_Function *directory_get_hot_; @@ -325,6 +329,7 @@ app_links->print_message_ = Print_Message;\ app_links->change_theme_ = Change_Theme;\ app_links->change_font_ = Change_Font;\ app_links->buffer_set_font_ = Buffer_Set_Font;\ +app_links->buffer_get_font_ = Buffer_Get_Font;\ app_links->set_theme_colors_ = Set_Theme_Colors;\ app_links->get_theme_colors_ = Get_Theme_Colors;\ app_links->directory_get_hot_ = Directory_Get_Hot;\ @@ -392,6 +397,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len) static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme(app, name, len));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font(app, name, len, apply_to_all_files));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font(app, buffer, name, len));} +static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font(app, buffer, name_out, name_max));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));} @@ -459,6 +465,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len) static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme_(app, name, len));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font_(app, name, len, apply_to_all_files));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font_(app, buffer, name, len));} +static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font_(app, buffer, name_out, name_max));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));} diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index e5ad4bfc..5fa3e8ab 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -158,6 +158,22 @@ HOOK_SIG(my_exit){ return(1); } +// NOTE(allen|a4.0.12): This is for testing it may be removed and replaced with a better test for the buffer_get_font when you eventally read this and wonder what it's about. +CUSTOM_COMMAND_SIG(write_name_of_font){ + View_Summary view = get_active_view(app, AccessOpen); + Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen); + + char font_name[256]; + int32_t font_max = 256; + int32_t font_len = buffer_get_font(app, &buffer, font_name, font_max); + + if (font_len != 0){ + write_string(app, &view, &buffer, make_string(font_name, font_len)); + } + + print_message(app, literal("TRIED WRITING FONT NAME")); +} + CUSTOM_COMMAND_SIG(newline_or_goto_position){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); @@ -176,7 +192,7 @@ OPEN_FILE_HOOK_SIG(my_file_settings){ // NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated // and instead the buffer is passed as an explicit parameter through // the function call. That is where buffer_id comes from here. - uint32_t access = AccessProtected|AccessHidden; + uint32_t access = AccessAll; Buffer_Summary buffer = get_buffer(app, buffer_id, access); assert(buffer.exists); @@ -412,6 +428,8 @@ default_keys(Bind_Helper *context){ bind(context, '\n', MDFR_SHIFT, newline_or_goto_position); bind(context, ' ', MDFR_SHIFT, write_character); + bind(context, ';', MDFR_ALT, write_name_of_font); + end_map(context); } diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index e21fe9cf..fa595830 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -1965,15 +1965,18 @@ seek_command(alphanumeric_or_camel, left, BoundaryAlphanumeric | BoundaryCamelC // special string writing commands // +static void +write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){ + buffer_replace_range(app, buffer, view->cursor.pos, view->cursor.pos, string.str, string.size); + view_set_cursor(app, view, seek_pos(view->cursor.pos + string.size), 1); +} + static void write_string(Application_Links *app, String string){ uint32_t access = AccessOpen; View_Summary view = get_active_view(app, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); - buffer_replace_range(app, &buffer, - view.cursor.pos, view.cursor.pos, - string.str, string.size); - view_set_cursor(app, &view, seek_pos(view.cursor.pos + string.size), true); + write_string(app, &view, &buffer, string); } CUSTOM_COMMAND_SIG(write_increment){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index ce7b46a0..c428ffb7 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2071,6 +2071,26 @@ DOC(This call sets the display font of a particular buffer.) } } +API_EXPORT int32_t +Buffer_Get_Font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max) +{ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + Editing_File *file = imp_get_file(cmd, buffer); + + int32_t result = 0; + if (file){ + Font_Set *set = models->font_set; + String name = make_string_cap(name_out, 0, name_max); + if (font_set_get_name(set, file->settings.font_id, &name)){ + result = name.size; + } + } + + return(result); +} + API_EXPORT void Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count) /* diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 4a359957..886dc137 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -4558,7 +4558,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su Assert(view->file_data.file); Font_Set *font_set = models->font_set; - Font_Info *info = 0; i16 i = 1, count = (i16)models->font_set->count + 1; @@ -4577,7 +4576,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su i16 new_font_id = font_id; for (i = 1; i < count; ++i){ - info = get_font_info(font_set, i); + Font_Info *info = get_font_info(font_set, i); id.id[0] = (u64)i; if (i != font_id){ if (gui_do_font_button(target, id, i, info->name)){ diff --git a/4ed_font_set.cpp b/4ed_font_set.cpp index 386c906c..b2e11c80 100644 --- a/4ed_font_set.cpp +++ b/4ed_font_set.cpp @@ -204,18 +204,20 @@ font_set_add(Partition *partition, Font_Set *set, internal b32 font_set_find_pos(Font_Set *set, String name, u32 *position){ - b32 result; - u32 hash, i, j; - hash = font_hash(name); - i = hash % set->max; - j = i - 1; - if (j <= 1) j += set->max; + u32 hash = font_hash(name); + u32 i = hash % set->max; + u32 j = i - 1; + if (j <= 1){ + j += set->max; + } - result = 0; - Font_Table_Entry *entry; + b32 result = 0; for (; i != j; ++i){ - if (i == set->max) i = 0; - entry = set->entries + i; + if (i == set->max){ + i = 0; + } + + Font_Table_Entry *entry = set->entries + i; if (entry->hash == hash){ if (match_ss(name, entry->name)){ result = 1; @@ -228,16 +230,20 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){ return(result); } +internal b32 +font_set_get_name(Font_Set *set, i16 font_id, String *name){ + Font_Info *info = get_font_info(set, font_id); + b32 result = copy_checked_ss(name, info->name); + return(result); +} + internal b32 font_set_extract(Font_Set *set, String name, i16 *font_id){ - b32 result; u32 position; - - result = font_set_find_pos(set, name, &position); + b32 result = font_set_find_pos(set, name, &position); if (result){ *font_id = set->entries[position].font_id; } - return(result); } diff --git a/4ed_rendering.h b/4ed_rendering.h index fef4b342..eadb253f 100644 --- a/4ed_rendering.h +++ b/4ed_rendering.h @@ -102,17 +102,9 @@ typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip); #define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece) typedef Draw_Push_Piece_Sig(Draw_Push_Piece); -#define Font_Load_Sig(name) i32 name( \ - Render_Font *font_out, \ - char *filename, \ - char *fontname, \ - i32 pt_size, \ - i32 tab_width, \ - b32 store_texture) +#define Font_Load_Sig(name) i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture) typedef Font_Load_Sig(Font_Load); - - #define Release_Font_Sig(name) void name(Render_Font *font) typedef Release_Font_Sig(Release_Font); @@ -140,15 +132,15 @@ struct Font_Set{ Font_Info *info; Font_Table_Entry *entries; u32 count, max; - + void *font_block; Font_Slot free_slots; Font_Slot used_slots; - + //Font_Info_Load *font_info_load; Font_Load *font_load; Release_Font *release_font; - + b8 *font_used_flags; i16 used_this_frame; i16 live_max; @@ -159,7 +151,7 @@ struct Render_Target{ void *context; i32_Rect clip_boxes[5]; i32 clip_top; - i32 width, height; + i32 width, height; i32 bound_texture; u32 color; diff --git a/TODO.txt b/TODO.txt index 6c3b6694..d8cb636d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -177,9 +177,9 @@ ; [X] handle unclosed statements ; [X] wrapped line indication ; [X] additional width for nesting? +; [X] special indent rules in preprocessor body ; [X] handle comments -; [] solve the comment lead whitespace problem -; [] special indent rules in preprocessor body +; [] solve the comment lead whitespace problem ; [] fix issues when relexing happens in parallel ; [] remeasure version of measure_wraps