added some comments

This commit is contained in:
phixxy 2026-03-21 14:55:32 -07:00
parent 12d0ac2d33
commit 7de932eeaa

View file

@ -10,14 +10,14 @@ struct Flags
{ {
int use_v; int use_v;
int use_s; int use_s;
char *suffix; char *suffix; // file suffix
char skratch_path[4096]; char skratch_path[4096]; // ~/.skratch
char file_path[4096]; char file_path[4096]; // ~/.skratch/<filename><suffix>
char filename[255]; char filename[255]; // skratch-XXXXXX
char editor[255]; char editor[255]; // editor to open file with
}; };
// sets f.editor using env vars
void set_editor(struct Flags *f) void set_editor(struct Flags *f)
{ {
char *ed; char *ed;
@ -27,10 +27,11 @@ void set_editor(struct Flags *f)
ed = getenv("EDITOR"); ed = getenv("EDITOR");
if (ed) if (ed)
strcpy(f->editor, ed); strcpy(f->editor, ed);
else else //no env vars set
strcpy(f->editor, "vi"); strcpy(f->editor, "vi");
} }
// sets f.file_path and makes a file in ~/.skratch if needed
int make_skratch_file(struct Flags *f) int make_skratch_file(struct Flags *f)
{ {
char fp[4096]; char fp[4096];
@ -53,6 +54,7 @@ int make_skratch_file(struct Flags *f)
return 0; return 0;
} }
// creates ~/.skratch if needed and sets f.skratch_path
int make_skratch_path(struct Flags *f) int make_skratch_path(struct Flags *f)
{ {
char sp[4096]; char sp[4096];
@ -73,6 +75,8 @@ int make_skratch_path(struct Flags *f)
return 0; return 0;
} }
// lists files in f.skratch_path, with option to delete
// this should likely have all delete logic inside delete_files()
int list_files(struct Flags *f, int delete) int list_files(struct Flags *f, int delete)
{ {
DIR *d = opendir(f->skratch_path); DIR *d = opendir(f->skratch_path);
@ -102,6 +106,8 @@ int list_files(struct Flags *f, int delete)
return 0; return 0;
} }
// menu confirmation for deleting files in f.skratch_path
// there is a bug if the user has no input
int delete_files(struct Flags *f) int delete_files(struct Flags *f)
{ {
list_files(f, 0); list_files(f, 0);
@ -115,6 +121,7 @@ int delete_files(struct Flags *f)
return 0; return 0;
} }
// handles arguments and runs the editor
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt; int opt;