diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-11-18 16:30:30 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-11-18 16:30:30 -0800 |
commit | 9992b8eb0e3366ff8a3948aa0b66a19c3c12c737 (patch) | |
tree | 6dda0fef85812016fbba9ea067c9d586092b506d /builtin_jobs.cpp | |
parent | bab69f26724028d16054a3daf5c78aad7c67bb2d (diff) |
Apply new indentation, brace, and whitespace style
Diffstat (limited to 'builtin_jobs.cpp')
-rw-r--r-- | builtin_jobs.cpp | 450 |
1 files changed, 225 insertions, 225 deletions
diff --git a/builtin_jobs.cpp b/builtin_jobs.cpp index 4725f5dd..ab2da51b 100644 --- a/builtin_jobs.cpp +++ b/builtin_jobs.cpp @@ -30,12 +30,12 @@ */ enum { - JOBS_DEFAULT, /**< Print lots of general info */ - JOBS_PRINT_PID, /**< Print pid of each process in job */ - JOBS_PRINT_COMMAND, /**< Print command name of each process in job */ - JOBS_PRINT_GROUP, /**< Print group id of job */ + JOBS_DEFAULT, /**< Print lots of general info */ + JOBS_PRINT_PID, /**< Print pid of each process in job */ + JOBS_PRINT_COMMAND, /**< Print command name of each process in job */ + JOBS_PRINT_GROUP, /**< Print group id of job */ } - ; +; @@ -43,113 +43,113 @@ enum /** Calculates the cpu usage (in percent) of the specified job. */ -static int cpu_use( const job_t *j ) +static int cpu_use(const job_t *j) { - double u=0; - process_t *p; + double u=0; + process_t *p; - for( p=j->first_process; p; p=p->next ) - { - struct timeval t; - int jiffies; - gettimeofday( &t, 0 ); - jiffies = proc_get_jiffies( p ); + for (p=j->first_process; p; p=p->next) + { + struct timeval t; + int jiffies; + gettimeofday(&t, 0); + jiffies = proc_get_jiffies(p); - double t1 = 1000000.0*p->last_time.tv_sec+p->last_time.tv_usec; - double t2 = 1000000.0*t.tv_sec+t.tv_usec; + double t1 = 1000000.0*p->last_time.tv_sec+p->last_time.tv_usec; + double t2 = 1000000.0*t.tv_sec+t.tv_usec; -/* fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n", - t1, t2, jiffies, p->last_jiffies ); -*/ + /* fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n", + t1, t2, jiffies, p->last_jiffies ); + */ - u += ((double)(jiffies-p->last_jiffies))/(t2-t1); - } - return u*1000000; + u += ((double)(jiffies-p->last_jiffies))/(t2-t1); + } + return u*1000000; } #endif /** Print information about the specified job */ -static void builtin_jobs_print( const job_t *j, int mode, int header ) +static void builtin_jobs_print(const job_t *j, int mode, int header) { - process_t *p; - switch( mode ) - { + process_t *p; + switch (mode) + { case JOBS_DEFAULT: { - if( header ) - { - /* - Print table header before first job - */ - stdout_buffer.append( _( L"Job\tGroup\t" )); + if (header) + { + /* + Print table header before first job + */ + stdout_buffer.append(_(L"Job\tGroup\t")); #ifdef HAVE__PROC_SELF_STAT - stdout_buffer.append( _( L"CPU\t" ) ); + stdout_buffer.append(_(L"CPU\t")); #endif - stdout_buffer.append( _( L"State\tCommand\n" ) ); - } + stdout_buffer.append(_(L"State\tCommand\n")); + } - append_format(stdout_buffer, L"%d\t%d\t", j->job_id, j->pgid ); + append_format(stdout_buffer, L"%d\t%d\t", j->job_id, j->pgid); #ifdef HAVE__PROC_SELF_STAT - append_format(stdout_buffer, L"%d%%\t", cpu_use(j) ); + append_format(stdout_buffer, L"%d%%\t", cpu_use(j)); #endif - stdout_buffer.append(job_is_stopped(j)?_(L"stopped"):_(L"running")); - stdout_buffer.append(L"\t"); - stdout_buffer.append(j->command_wcstr()); - stdout_buffer.append(L"\n"); - break; + stdout_buffer.append(job_is_stopped(j)?_(L"stopped"):_(L"running")); + stdout_buffer.append(L"\t"); + stdout_buffer.append(j->command_wcstr()); + stdout_buffer.append(L"\n"); + break; } case JOBS_PRINT_GROUP: { - if( header ) - { - /* - Print table header before first job - */ - stdout_buffer.append( _( L"Group\n" )); - } - append_format(stdout_buffer, L"%d\n", j->pgid ); - break; + if (header) + { + /* + Print table header before first job + */ + stdout_buffer.append(_(L"Group\n")); + } + append_format(stdout_buffer, L"%d\n", j->pgid); + break; } case JOBS_PRINT_PID: { - if( header ) - { - /* - Print table header before first job - */ - stdout_buffer.append( _( L"Procces\n" )); - } - - for( p=j->first_process; p; p=p->next ) - { - append_format(stdout_buffer, L"%d\n", p->pid ); - } - break; + if (header) + { + /* + Print table header before first job + */ + stdout_buffer.append(_(L"Procces\n")); + } + + for (p=j->first_process; p; p=p->next) + { + append_format(stdout_buffer, L"%d\n", p->pid); + } + break; } case JOBS_PRINT_COMMAND: { - if( header ) - { - /* - Print table header before first job - */ - stdout_buffer.append( _( L"Command\n" )); - } - - for( p=j->first_process; p; p=p->next ) - { - append_format(stdout_buffer, L"%ls\n", p->argv0() ); - } - break; + if (header) + { + /* + Print table header before first job + */ + stdout_buffer.append(_(L"Command\n")); + } + + for (p=j->first_process; p; p=p->next) + { + append_format(stdout_buffer, L"%ls\n", p->argv0()); + } + break; + } } - } } @@ -158,194 +158,194 @@ static void builtin_jobs_print( const job_t *j, int mode, int header ) /** The jobs builtin. Used fopr printing running jobs. Defined in builtin_jobs.c. */ -static int builtin_jobs( parser_t &parser, wchar_t **argv ) +static int builtin_jobs(parser_t &parser, wchar_t **argv) { - int argc=0; - int found=0; - int mode=JOBS_DEFAULT; - int print_last = 0; - const job_t *j; - - argc = builtin_count_args( argv ); - woptind=0; - - while( 1 ) - { - static const struct woption - long_options[] = - { - { - L"pid", no_argument, 0, 'p' - } - , - { - L"command", no_argument, 0, 'c' - } - , - { - L"group", no_argument, 0, 'g' - } - , - { - L"last", no_argument, 0, 'l' - } - , - { - L"help", no_argument, 0, 'h' - } - , + int argc=0; + int found=0; + int mode=JOBS_DEFAULT; + int print_last = 0; + const job_t *j; + + argc = builtin_count_args(argv); + woptind=0; + + while (1) + { + static const struct woption + long_options[] = { - 0, 0, 0, 0 + { + L"pid", no_argument, 0, 'p' + } + , + { + L"command", no_argument, 0, 'c' + } + , + { + L"group", no_argument, 0, 'g' + } + , + { + L"last", no_argument, 0, 'l' + } + , + { + L"help", no_argument, 0, 'h' + } + , + { + 0, 0, 0, 0 + } } - } - ; + ; - int opt_index = 0; + int opt_index = 0; - int opt = wgetopt_long( argc, - argv, - L"pclgh", - long_options, - &opt_index ); - if( opt == -1 ) - break; + int opt = wgetopt_long(argc, + argv, + L"pclgh", + long_options, + &opt_index); + if (opt == -1) + break; - switch( opt ) - { - case 0: - if(long_options[opt_index].flag != 0) - break; - append_format(stderr_buffer, - BUILTIN_ERR_UNKNOWN, - argv[0], - long_options[opt_index].name ); + switch (opt) + { + case 0: + if (long_options[opt_index].flag != 0) + break; + append_format(stderr_buffer, + BUILTIN_ERR_UNKNOWN, + argv[0], + long_options[opt_index].name); - builtin_print_help( parser, argv[0], stderr_buffer ); + builtin_print_help(parser, argv[0], stderr_buffer); - return 1; + return 1; - case 'p': - mode=JOBS_PRINT_PID; - break; + case 'p': + mode=JOBS_PRINT_PID; + break; - case 'c': - mode=JOBS_PRINT_COMMAND; - break; + case 'c': + mode=JOBS_PRINT_COMMAND; + break; - case 'g': - mode=JOBS_PRINT_GROUP; - break; + case 'g': + mode=JOBS_PRINT_GROUP; + break; - case 'l': - { - print_last = 1; - break; - } + case 'l': + { + print_last = 1; + break; + } - case 'h': - builtin_print_help( parser, argv[0], stdout_buffer ); - return 0; + case 'h': + builtin_print_help(parser, argv[0], stdout_buffer); + return 0; - case '?': - builtin_unknown_option( parser, argv[0], argv[woptind-1] ); - return 1; + case '?': + builtin_unknown_option(parser, argv[0], argv[woptind-1]); + return 1; + } } - } - /* - Do not babble if not interactive - */ - if( builtin_out_redirect ) - { - found=1; - } - - if( print_last ) - { /* - Ignore unconstructed jobs, i.e. ourself. + Do not babble if not interactive */ - job_iterator_t jobs; - const job_t *j; - while ((j = jobs.next())) + if (builtin_out_redirect) { - - if( (j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) ) - { - builtin_jobs_print( j, mode, !found ); - return 0; - } + found=1; } - } - else - { - if( woptind < argc ) + if (print_last) { - int i; + /* + Ignore unconstructed jobs, i.e. ourself. + */ + job_iterator_t jobs; + const job_t *j; + while ((j = jobs.next())) + { - found = 1; + if ((j->flags & JOB_CONSTRUCTED) && !job_is_completed(j)) + { + builtin_jobs_print(j, mode, !found); + return 0; + } + } - for( i=woptind; i<argc; i++ ) - { - int pid; - wchar_t *end; - errno=0; - pid=fish_wcstoi( argv[i], &end, 10 ); - if( errno || *end ) + } + else + { + if (woptind < argc) { - append_format(stderr_buffer, - _( L"%ls: '%ls' is not a job\n" ), - argv[0], - argv[i] ); - return 1; - } + int i; - j = job_get_from_pid( pid ); + found = 1; - if( j && !job_is_completed( j ) ) - { - builtin_jobs_print( j, mode, !found ); + for (i=woptind; i<argc; i++) + { + int pid; + wchar_t *end; + errno=0; + pid=fish_wcstoi(argv[i], &end, 10); + if (errno || *end) + { + append_format(stderr_buffer, + _(L"%ls: '%ls' is not a job\n"), + argv[0], + argv[i]); + return 1; + } + + j = job_get_from_pid(pid); + + if (j && !job_is_completed(j)) + { + builtin_jobs_print(j, mode, !found); + } + else + { + append_format(stderr_buffer, + _(L"%ls: No suitable job: %d\n"), + argv[0], + pid); + return 1; + } + } } else { - append_format(stderr_buffer, - _( L"%ls: No suitable job: %d\n" ), - argv[0], - pid ); - return 1; - } - } - } - else - { job_iterator_t jobs; const job_t *j; while ((j = jobs.next())) { - /* - Ignore unconstructed jobs, i.e. ourself. - */ - if( (j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) ) - { - builtin_jobs_print( j, mode, !found ); - found = 1; + /* + Ignore unconstructed jobs, i.e. ourself. + */ + if ((j->flags & JOB_CONSTRUCTED) && !job_is_completed(j)) + { + builtin_jobs_print(j, mode, !found); + found = 1; + } + } } - } } - } - if( !found ) - { - append_format(stdout_buffer, - _( L"%ls: There are no jobs\n" ), - argv[0] ); - } + if (!found) + { + append_format(stdout_buffer, + _(L"%ls: There are no jobs\n"), + argv[0]); + } - return 0; + return 0; } |