examples/fileman.c: Reindent to project coding style

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2018-12-25 19:37:42 +01:00
parent 8e34e4e417
commit 8566eb8384

View File

@ -76,8 +76,7 @@ char *progname;
/* When non-zero, this means the user is done using this program. */
int done;
char *
dupstr (char* s)
char *dupstr(char *s)
{
char *r;
@ -86,8 +85,7 @@ dupstr (char* s)
return (r);
}
int
main (int argc __attribute__((__unused__)), char **argv)
int main(int argc __attribute__ ((__unused__)), char **argv)
{
char *line, *s;
@ -98,8 +96,7 @@ main (int argc __attribute__((__unused__)), char **argv)
initialize_readline(); /* Bind our completer. */
/* Loop reading and executing lines until the user quits. */
for ( ; done == 0; )
{
for (; done == 0;) {
line = readline("FileMan: ");
if (!line)
@ -135,8 +132,7 @@ main (int argc __attribute__((__unused__)), char **argv)
}
/* Execute a command line. */
int
execute_line (char *line)
int execute_line(char *line)
{
register int i;
COMMAND *command;
@ -156,8 +152,7 @@ execute_line (char *line)
command = find_command(word);
if (!command)
{
if (!command) {
fprintf(stderr, "%s: No such command for FileMan.\n", word);
return (-1);
}
@ -174,8 +169,7 @@ execute_line (char *line)
/* Look up NAME as the name of a command, and return a pointer to that
command. Return a NULL pointer if NAME isn't a command name. */
COMMAND *
find_command (char *name)
COMMAND *find_command(char *name)
{
register int i;
@ -188,13 +182,11 @@ find_command (char *name)
/* Strip whitespace from the start and end of STRING. Return a pointer
into STRING. */
char *
stripwhite (char *string)
char *stripwhite(char *string)
{
register char *s, *t;
for (s = string; isspace (*s); s++)
;
for (s = string; isspace(*s); s++) ;
if (*s == 0)
return (s);
@ -219,8 +211,7 @@ char **fileman_completion(const char *, int, int);
/* Tell the GNU Readline library how to complete. We want to try to
complete on command names if this is the first word in the line, or
on filenames if not. */
void
initialize_readline ()
void initialize_readline()
{
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name = "FileMan";
@ -234,8 +225,8 @@ initialize_readline ()
complete. TEXT is the word to complete. We can use the entire
contents of rl_line_buffer in case we want to do some simple
parsing. Returnthe array of matches, or NULL if there aren't any. */
char **
fileman_completion (const char* text, int start, int end __attribute__((__unused__)))
char **fileman_completion(const char *text, int start, int end
__attribute__ ((__unused__)))
{
char **matches;
@ -253,8 +244,7 @@ fileman_completion (const char* text, int start, int end __attribute__((__unused
/* Generator function for command completion. STATE lets us
know whether to start from scratch; without any state
(i.e. STATE == 0), then we start at the top of the list. */
char *
command_generator (text, state)
char *command_generator(text, state)
const char *text;
int state;
{
@ -264,16 +254,14 @@ command_generator (text, state)
/* If this is a new word to complete, initialize now. This
includes saving the length of TEXT for efficiency, and
initializing the index variable to 0. */
if (!state)
{
if (!state) {
list_index = 0;
len = strlen(text);
}
/* Return the next name which partially matches from the
command list. */
while ((name = commands[list_index].name))
{
while ((name = commands[list_index].name)) {
list_index++;
if (strncmp(name, text, len) == 0)
@ -295,8 +283,7 @@ command_generator (text, state)
static char syscom[1024];
/* List the file(s) named in arg. */
int
com_list (char *arg)
int com_list(char *arg)
{
if (!arg)
arg = "";
@ -305,8 +292,7 @@ com_list (char *arg)
return (system(syscom));
}
int
com_view (char *arg)
int com_view(char *arg)
{
if (!valid_argument("view", arg))
return 1;
@ -315,14 +301,12 @@ com_view (char *arg)
return (system(syscom));
}
int
com_history(char* arg __attribute__((__unused__)))
int com_history(char *arg __attribute__ ((__unused__)))
{
const char *he;
/* rewind history */
while (el_prev_hist())
;
while (el_prev_hist()) ;
for (he = el_next_hist(); he != NULL; he = el_next_hist())
printf("%s\n", he);
@ -330,23 +314,20 @@ com_history(char* arg __attribute__((__unused__)))
return 0;
}
int
com_rename (char *arg __attribute__((__unused__)))
int com_rename(char *arg __attribute__ ((__unused__)))
{
too_dangerous("rename");
return (1);
}
int
com_stat (char *arg)
int com_stat(char *arg)
{
struct stat finfo;
if (!valid_argument("stat", arg))
return (1);
if (stat (arg, &finfo) == -1)
{
if (stat(arg, &finfo) == -1) {
perror(arg);
return (1);
}
@ -356,16 +337,14 @@ com_stat (char *arg)
printf("%s has %ld link%s, and is %lld byte%s in length.\n", arg,
(long)finfo.st_nlink,
(finfo.st_nlink == 1) ? "" : "s",
(long long) finfo.st_size,
(finfo.st_size == 1) ? "" : "s");
(long long)finfo.st_size, (finfo.st_size == 1) ? "" : "s");
printf("Inode Last Change at: %s", ctime(&finfo.st_ctime));
printf(" Last access at: %s", ctime(&finfo.st_atime));
printf(" Last modified at: %s", ctime(&finfo.st_mtime));
return (0);
}
int
com_delete (char *arg __attribute__((__unused__)))
int com_delete(char *arg __attribute__ ((__unused__)))
{
too_dangerous("delete");
return (1);
@ -373,30 +352,25 @@ com_delete (char *arg __attribute__((__unused__)))
/* Print out help for ARG, or for all of the commands if ARG is
not present. */
int
com_help (char *arg)
int com_help(char *arg)
{
register int i;
int printed = 0;
for (i = 0; commands[i].name; i++)
{
if (!*arg || (strcmp (arg, commands[i].name) == 0))
{
printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc);
for (i = 0; commands[i].name; i++) {
if (!*arg || (strcmp(arg, commands[i].name) == 0)) {
printf("%s\t\t%s.\n", commands[i].name,
commands[i].doc);
printed++;
}
}
if (!printed)
{
if (!printed) {
printf("No commands match `%s'. Possibilties are:\n", arg);
for (i = 0; commands[i].name; i++)
{
for (i = 0; commands[i].name; i++) {
/* Print in six columns. */
if (printed == 6)
{
if (printed == 6) {
printed = 0;
printf("\n");
}
@ -412,11 +386,9 @@ com_help (char *arg)
}
/* Change to the directory ARG. */
int
com_cd (char *arg)
{
if (chdir (arg) == -1)
int com_cd(char *arg)
{
if (chdir(arg) == -1) {
perror(arg);
return 1;
}
@ -426,14 +398,12 @@ com_cd (char *arg)
}
/* Print out the current working directory. */
int
com_pwd (char* ignore __attribute__((__unused__)))
int com_pwd(char *ignore __attribute__ ((__unused__)))
{
char dir[1024], *s;
s = (char *)getcwd(dir, sizeof(dir) - 1);
if (s == 0)
{
if (s == 0) {
printf("Error getting pwd: %s\n", dir);
return 1;
}
@ -444,30 +414,24 @@ com_pwd (char* ignore __attribute__((__unused__)))
/* The user wishes to quit using this program. Just set DONE
non-zero. */
int
com_quit (char *arg __attribute__((__unused__)))
int com_quit(char *arg __attribute__ ((__unused__)))
{
done = 1;
return (0);
}
/* Function which tells you that you can't do this. */
void
too_dangerous (char *caller)
void too_dangerous(char *caller)
{
fprintf (stderr,
"%s: Too dangerous for me to distribute.\n",
caller);
fprintf(stderr, "%s: Too dangerous for me to distribute.\n", caller);
fprintf(stderr, "Write it yourself.\n");
}
/* Return non-zero if ARG is a valid argument for CALLER,
else print an error message and return zero. */
int
valid_argument (char *caller, char *arg)
{
if (!arg || !*arg)
int valid_argument(char *caller, char *arg)
{
if (!arg || !*arg) {
fprintf(stderr, "%s: Argument required.\n", caller);
return (0);
}
@ -475,8 +439,7 @@ valid_argument (char *caller, char *arg)
return (1);
}
void *
xmalloc (size_t size)
void *xmalloc(size_t size)
{
register void *value = (void *)malloc(size);
if (value == 0)
@ -484,4 +447,9 @@ xmalloc (size_t size)
return value;
}
/**
* Local Variables:
* c-file-style: "k&r"
* c-basic-offset: 4
* End:
*/