added some comments
This commit is contained in:
parent
12d0ac2d33
commit
7de932eeaa
1 changed files with 14 additions and 7 deletions
21
skratch.c
21
skratch.c
|
|
@ -10,14 +10,14 @@ struct Flags
|
|||
{
|
||||
int use_v;
|
||||
int use_s;
|
||||
char *suffix;
|
||||
char skratch_path[4096];
|
||||
char file_path[4096];
|
||||
char filename[255];
|
||||
char editor[255];
|
||||
char *suffix; // file suffix
|
||||
char skratch_path[4096]; // ~/.skratch
|
||||
char file_path[4096]; // ~/.skratch/<filename><suffix>
|
||||
char filename[255]; // skratch-XXXXXX
|
||||
char editor[255]; // editor to open file with
|
||||
};
|
||||
|
||||
|
||||
// sets f.editor using env vars
|
||||
void set_editor(struct Flags *f)
|
||||
{
|
||||
char *ed;
|
||||
|
|
@ -27,10 +27,11 @@ void set_editor(struct Flags *f)
|
|||
ed = getenv("EDITOR");
|
||||
if (ed)
|
||||
strcpy(f->editor, ed);
|
||||
else
|
||||
else //no env vars set
|
||||
strcpy(f->editor, "vi");
|
||||
}
|
||||
|
||||
// sets f.file_path and makes a file in ~/.skratch if needed
|
||||
int make_skratch_file(struct Flags *f)
|
||||
{
|
||||
char fp[4096];
|
||||
|
|
@ -53,6 +54,7 @@ int make_skratch_file(struct Flags *f)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// creates ~/.skratch if needed and sets f.skratch_path
|
||||
int make_skratch_path(struct Flags *f)
|
||||
{
|
||||
char sp[4096];
|
||||
|
|
@ -73,6 +75,8 @@ int make_skratch_path(struct Flags *f)
|
|||
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)
|
||||
{
|
||||
DIR *d = opendir(f->skratch_path);
|
||||
|
|
@ -102,6 +106,8 @@ int list_files(struct Flags *f, int delete)
|
|||
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)
|
||||
{
|
||||
list_files(f, 0);
|
||||
|
|
@ -115,6 +121,7 @@ int delete_files(struct Flags *f)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// handles arguments and runs the editor
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue