Skip to content

Commit daba810

Browse files
committed
Change the format of enum API docs.
1 parent b235370 commit daba810

2 files changed

Lines changed: 113 additions & 101 deletions

File tree

docs/api.md

Lines changed: 88 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,97 +2816,109 @@ int fs_snprintf(
28162816

28172817
# enum fs_result
28182818

2819-
| Name | Value |
2820-
|------|-------|
2821-
| `FS_SUCCESS` | `0` |
2822-
| `FS_ERROR` | `-1` |
2823-
| `FS_INVALID_ARGS` | `-2` |
2824-
| `FS_INVALID_OPERATION` | `-3` |
2825-
| `FS_OUT_OF_MEMORY` | `-4` |
2826-
| `FS_OUT_OF_RANGE` | `-5` |
2827-
| `FS_ACCESS_DENIED` | `-6` |
2828-
| `FS_DOES_NOT_EXIST` | `-7` |
2829-
| `FS_ALREADY_EXISTS` | `-8` |
2830-
| `FS_TOO_MANY_OPEN_FILES` | `-9` |
2831-
| `FS_INVALID_FILE` | `-10` |
2832-
| `FS_TOO_BIG` | `-11` |
2833-
| `FS_PATH_TOO_LONG` | `-12` |
2834-
| `FS_NAME_TOO_LONG` | `-13` |
2835-
| `FS_NOT_DIRECTORY` | `-14` |
2836-
| `FS_IS_DIRECTORY` | `-15` |
2837-
| `FS_DIRECTORY_NOT_EMPTY` | `-16` |
2838-
| `FS_AT_END` | `-17` |
2839-
| `FS_NO_SPACE` | `-18` |
2840-
| `FS_BUSY` | `-19` |
2841-
| `FS_IO_ERROR` | `-20` |
2842-
| `FS_INTERRUPT` | `-21` |
2843-
| `FS_UNAVAILABLE` | `-22` |
2844-
| `FS_ALREADY_IN_USE` | `-23` |
2845-
| `FS_BAD_ADDRESS` | `-24` |
2846-
| `FS_BAD_SEEK` | `-25` |
2847-
| `FS_BAD_PIPE` | `-26` |
2848-
| `FS_DEADLOCK` | `-27` |
2849-
| `FS_TOO_MANY_LINKS` | `-28` |
2850-
| `FS_NOT_IMPLEMENTED` | `-29` |
2851-
| `FS_NO_MESSAGE` | `-30` |
2852-
| `FS_BAD_MESSAGE` | `-31` |
2853-
| `FS_NO_DATA_AVAILABLE` | `-32` |
2854-
| `FS_INVALID_DATA` | `-33` |
2855-
| `FS_TIMEOUT` | `-34` |
2856-
| `FS_NO_NETWORK` | `-35` |
2857-
| `FS_NOT_UNIQUE` | `-36` |
2858-
| `FS_NOT_SOCKET` | `-37` |
2859-
| `FS_NO_ADDRESS` | `-38` |
2860-
| `FS_BAD_PROTOCOL` | `-39` |
2861-
| `FS_PROTOCOL_UNAVAILABLE` | `-40` |
2862-
| `FS_PROTOCOL_NOT_SUPPORTED` | `-41` |
2863-
| `FS_PROTOCOL_FAMILY_NOT_SUPPORTED` | `-42` |
2864-
| `FS_ADDRESS_FAMILY_NOT_SUPPORTED` | `-43` |
2865-
| `FS_SOCKET_NOT_SUPPORTED` | `-44` |
2866-
| `FS_CONNECTION_RESET` | `-45` |
2867-
| `FS_ALREADY_CONNECTED` | `-46` |
2868-
| `FS_NOT_CONNECTED` | `-47` |
2869-
| `FS_CONNECTION_REFUSED` | `-48` |
2870-
| `FS_NO_HOST` | `-49` |
2871-
| `FS_IN_PROGRESS` | `-50` |
2872-
| `FS_CANCELLED` | `-51` |
2873-
| `FS_MEMORY_ALREADY_MAPPED` | `-52` |
2874-
| `FS_DIFFERENT_DEVICE` | `-53` |
2875-
| `FS_CHECKSUM_MISMATCH` | `-100` |
2876-
| `FS_NO_BACKEND` | `-101` |
2877-
| `FS_NEEDS_MORE_INPUT` | `100` |
2878-
| `FS_HAS_MORE_OUTPUT` | `102` |
2819+
```c
2820+
enum fs_result
2821+
{
2822+
FS_SUCCESS = 0,
2823+
FS_ERROR = -1,
2824+
FS_INVALID_ARGS = -2,
2825+
FS_INVALID_OPERATION = -3,
2826+
FS_OUT_OF_MEMORY = -4,
2827+
FS_OUT_OF_RANGE = -5,
2828+
FS_ACCESS_DENIED = -6,
2829+
FS_DOES_NOT_EXIST = -7,
2830+
FS_ALREADY_EXISTS = -8,
2831+
FS_TOO_MANY_OPEN_FILES = -9,
2832+
FS_INVALID_FILE = -10,
2833+
FS_TOO_BIG = -11,
2834+
FS_PATH_TOO_LONG = -12,
2835+
FS_NAME_TOO_LONG = -13,
2836+
FS_NOT_DIRECTORY = -14,
2837+
FS_IS_DIRECTORY = -15,
2838+
FS_DIRECTORY_NOT_EMPTY = -16,
2839+
FS_AT_END = -17,
2840+
FS_NO_SPACE = -18,
2841+
FS_BUSY = -19,
2842+
FS_IO_ERROR = -20,
2843+
FS_INTERRUPT = -21,
2844+
FS_UNAVAILABLE = -22,
2845+
FS_ALREADY_IN_USE = -23,
2846+
FS_BAD_ADDRESS = -24,
2847+
FS_BAD_SEEK = -25,
2848+
FS_BAD_PIPE = -26,
2849+
FS_DEADLOCK = -27,
2850+
FS_TOO_MANY_LINKS = -28,
2851+
FS_NOT_IMPLEMENTED = -29,
2852+
FS_NO_MESSAGE = -30,
2853+
FS_BAD_MESSAGE = -31,
2854+
FS_NO_DATA_AVAILABLE = -32,
2855+
FS_INVALID_DATA = -33,
2856+
FS_TIMEOUT = -34,
2857+
FS_NO_NETWORK = -35,
2858+
FS_NOT_UNIQUE = -36,
2859+
FS_NOT_SOCKET = -37,
2860+
FS_NO_ADDRESS = -38,
2861+
FS_BAD_PROTOCOL = -39,
2862+
FS_PROTOCOL_UNAVAILABLE = -40,
2863+
FS_PROTOCOL_NOT_SUPPORTED = -41,
2864+
FS_PROTOCOL_FAMILY_NOT_SUPPORTED = -42,
2865+
FS_ADDRESS_FAMILY_NOT_SUPPORTED = -43,
2866+
FS_SOCKET_NOT_SUPPORTED = -44,
2867+
FS_CONNECTION_RESET = -45,
2868+
FS_ALREADY_CONNECTED = -46,
2869+
FS_NOT_CONNECTED = -47,
2870+
FS_CONNECTION_REFUSED = -48,
2871+
FS_NO_HOST = -49,
2872+
FS_IN_PROGRESS = -50,
2873+
FS_CANCELLED = -51,
2874+
FS_MEMORY_ALREADY_MAPPED = -52,
2875+
FS_DIFFERENT_DEVICE = -53,
2876+
FS_CHECKSUM_MISMATCH = -100,
2877+
FS_NO_BACKEND = -101,
2878+
FS_NEEDS_MORE_INPUT = 100,
2879+
FS_HAS_MORE_OUTPUT = 102,
2880+
};
2881+
```
28792882

28802883
---
28812884

28822885
# enum fs_seek_origin
28832886

2884-
| Name | Value |
2885-
|------|-------|
2886-
| `FS_SEEK_SET` | `0` |
2887-
| `FS_SEEK_CUR` | `1` |
2888-
| `FS_SEEK_END` | `2` |
2887+
```c
2888+
enum fs_seek_origin
2889+
{
2890+
FS_SEEK_SET = 0,
2891+
FS_SEEK_CUR = 1,
2892+
FS_SEEK_END = 2,
2893+
};
2894+
```
28892895

28902896
---
28912897

28922898
# enum fs_format
28932899

2894-
| Name |
2895-
|------|
2896-
| `FS_FORMAT_TEXT` |
2897-
| `FS_FORMAT_BINARY` |
2900+
```c
2901+
enum fs_format
2902+
{
2903+
FS_FORMAT_TEXT,
2904+
FS_FORMAT_BINARY,
2905+
};
2906+
```
28982907

28992908
---
29002909

29012910
# enum fs_sysdir_type
29022911

2903-
| Name |
2904-
|------|
2905-
| `FS_SYSDIR_HOME` |
2906-
| `FS_SYSDIR_TEMP` |
2907-
| `FS_SYSDIR_CONFIG` |
2908-
| `FS_SYSDIR_DATA` |
2909-
| `FS_SYSDIR_CACHE` |
2912+
```c
2913+
enum fs_sysdir_type
2914+
{
2915+
FS_SYSDIR_HOME,
2916+
FS_SYSDIR_TEMP,
2917+
FS_SYSDIR_CONFIG,
2918+
FS_SYSDIR_DATA,
2919+
FS_SYSDIR_CACHE,
2920+
};
2921+
```
29102922

29112923
---
29122924

tools/fsdoc.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,41 +2775,41 @@ static int fsdoc_output_markdown(fsdoc_context* pContext, const char* pOutputPat
27752775
fs_file_writef(pFile, "%s\n\n", pEnum->pDescription);
27762776
}
27772777

2778-
/* Values table */
2778+
/* Code block representation */
27792779
if (pEnum->pFirstValue != NULL) {
2780-
/* First, check if any values have explicit assignments */
2781-
int hasExplicitValues = 0;
2780+
/* First pass: find the maximum name length for alignment */
2781+
size_t maxNameLen = 0;
27822782
fsdoc_enum_value* pValue;
27832783
for (pValue = pEnum->pFirstValue; pValue != NULL; pValue = pValue->pNext) {
2784-
if (strlen(pValue->value) > 0) {
2785-
hasExplicitValues = 1;
2786-
break;
2784+
size_t nameLen = strlen(pValue->name);
2785+
if (nameLen > maxNameLen) {
2786+
maxNameLen = nameLen;
27872787
}
27882788
}
27892789

2790-
if (hasExplicitValues) {
2791-
/* Two-column table: Name and Value */
2792-
fs_file_writef(pFile, "| Name | Value |\n");
2793-
fs_file_writef(pFile, "|------|-------|\n");
2794-
2795-
for (pValue = pEnum->pFirstValue; pValue != NULL; pValue = pValue->pNext) {
2796-
fs_file_writef(pFile, "| `%s` | ", pValue->name);
2797-
if (strlen(pValue->value) > 0) {
2798-
fs_file_writef(pFile, "`%s`", pValue->value);
2790+
fs_file_writef(pFile, "```c\n");
2791+
fs_file_writef(pFile, "enum %s\n", pEnum->name);
2792+
fs_file_writef(pFile, "{\n");
2793+
2794+
for (pValue = pEnum->pFirstValue; pValue != NULL; pValue = pValue->pNext) {
2795+
fs_file_writef(pFile, " %s", pValue->name);
2796+
if (strlen(pValue->value) > 0) {
2797+
/* Calculate padding for alignment */
2798+
size_t nameLen = strlen(pValue->name);
2799+
size_t padding = maxNameLen - nameLen;
2800+
2801+
/* Add padding spaces */
2802+
for (size_t i = 0; i < padding; i++) {
2803+
fs_file_writef(pFile, " ");
27992804
}
2800-
fs_file_writef(pFile, " |\n");
2801-
}
2802-
} else {
2803-
/* Single-column table: Name only */
2804-
fs_file_writef(pFile, "| Name |\n");
2805-
fs_file_writef(pFile, "|------|\n");
2806-
2807-
for (pValue = pEnum->pFirstValue; pValue != NULL; pValue = pValue->pNext) {
2808-
fs_file_writef(pFile, "| `%s` |\n", pValue->name);
2805+
2806+
fs_file_writef(pFile, " = %s", pValue->value);
28092807
}
2808+
fs_file_writef(pFile, ",\n");
28102809
}
28112810

2812-
fs_file_writef(pFile, "\n");
2811+
fs_file_writef(pFile, "};\n");
2812+
fs_file_writef(pFile, "```\n\n");
28132813
}
28142814

28152815
fs_file_writef(pFile, "---\n\n");

0 commit comments

Comments
 (0)