coding style

This commit is contained in:
albert 2002-10-09 21:32:33 +00:00
parent a02618d62a
commit af89241571
9 changed files with 96 additions and 103 deletions

View File

@ -119,7 +119,6 @@
#include "top.h" /* new header for top specific things */
static int *cpu_mapping;
static int nr_cpu;
/*#######################################################################
*#### Startup routines: parse_options, get_options, ##############
@ -242,12 +241,10 @@ static void get_options(void)
char Options[256] = "";
int i;
nr_cpu = sysconf (_SC_NPROCESSORS_ONLN);
if (nr_cpu < 1) nr_cpu = 1;
cpu_mapping = (int *) xmalloc (sizeof (int) * nr_cpu);
cpu_mapping = (int *) xmalloc (sizeof (int) * smp_num_cpus);
/* read cpuname */
for (i=0; i< nr_cpu; i++) cpu_mapping[i]=i;
header_lines = 6 + nr_cpu;
for (i=0; i< smp_num_cpus; i++) cpu_mapping[i]=i;
header_lines = 6 + smp_num_cpus;
fp = fopen(SYS_TOPRC, "r");
if (fp != NULL) {
fgets(Options, 254, fp);
@ -504,7 +501,7 @@ int main(int argc, char **argv)
breakargv:
}
if (nr_cpu > 1 && CPU_states)
if (smp_num_cpus > 1 && CPU_states)
header_lines++;
meminfo(); /* need kb_main_total value filled in */

View File

@ -108,7 +108,7 @@ typedef struct symb {
} symb;
static const symb fail = { "?", 0 };
static const char *dash = "-";
static const char dash[] = "-";
/* These mostly rely on POSIX to make them zero. */

View File

@ -179,15 +179,12 @@ extern char** environ;
/* for ELF executables, notes are pushed before environment and args */
static unsigned long find_elf_note(unsigned long findme){
unsigned long *ep = (unsigned long *)environ;
unsigned long ret = 42;
while(*ep++);
// while(*ep++);
while(*ep){
// printf("%08lx %08lx %011ld %011ld%s\n",ep[0],ep[1],ep[0],ep[1],ep[0]==findme?" <<<":"");
if(ep[0]==findme) ret=ep[1];
if(ep[0]==findme) return ep[1];
ep+=2;
}
return ret;
return 42;
}
static void init_libproc(void) __attribute__((constructor));
@ -195,7 +192,7 @@ static void init_libproc(void){
/* ought to count CPUs in /proc/stat instead of relying
* on glibc, which foolishly tries to parse /proc/cpuinfo
*/
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF);
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF); // or _SC_NPROCESSORS_ONLN
if(smp_num_cpus<1) smp_num_cpus=1; /* SPARC glibc is buggy */
Hertz = find_elf_note(AT_CLKTCK);

View File

@ -39,7 +39,7 @@
#endif
static char *saved_personality_text = "You found a bug!";
static char saved_personality_text[] = "You found a bug!";
int all_processes = -1;
char *bsd_j_format = (char *)0xdeadbeef;

View File

@ -76,8 +76,8 @@ static const char *get_opt_arg(void){
static const char *parse_pid(char *str, sel_union *ret){
char *endp;
unsigned long num;
static const char *pidrange = "Process ID out of range.";
static const char *pidsyntax = "Process ID list syntax error.";
static const char pidrange[] = "Process ID out of range.";
static const char pidsyntax[] = "Process ID list syntax error.";
num = strtoul(str, &endp, 0);
if(*endp != '\0') return pidsyntax;
if(num<1) return pidrange;
@ -90,8 +90,8 @@ static const char *parse_uid(char *str, sel_union *ret){
struct passwd *passwd_data;
char *endp;
unsigned long num;
static const char *uidrange = "User ID out of range.";
static const char *uidexist = "User name does not exist.";
static const char uidrange[] = "User ID out of range.";
static const char uidexist[] = "User name does not exist.";
num = strtoul(str, &endp, 0);
if(*endp != '\0'){ /* hmmm, try as login name */
passwd_data = getpwnam(str);
@ -107,8 +107,8 @@ static const char *parse_gid(char *str, sel_union *ret){
struct group *group_data;
char *endp;
unsigned long num;
static const char *gidrange = "Group ID out of range.";
static const char *gidexist = "Group name does not exist.";
static const char gidrange[] = "Group ID out of range.";
static const char gidexist[] = "Group name does not exist.";
num = strtoul(str, &endp, 0);
if(*endp != '\0'){ /* hmmm, try as login name */
group_data = getgrnam(str);
@ -127,8 +127,8 @@ static const char *parse_cmd(char *str, sel_union *ret){
static const char *parse_tty(char *str, sel_union *ret){
struct stat sbuf;
static const char *missing = "TTY could not be found.";
static const char *not_tty = "List member was not a TTY.";
static const char missing[] = "TTY could not be found.";
static const char not_tty[] = "List member was not a TTY.";
char path[4096];
if(str[0]=='/'){
if(stat(str, &sbuf) >= 0) goto found_it;

View File

@ -400,7 +400,7 @@ static const char *long_sort_parse(sf_node *sfn){
* reparse as formatting codes.
*/
static const char *verify_short_sort(const char *arg){
const char *all = "CGJKMNPRSTUcfgjkmnoprstuvy+-";
const char all[] = "CGJKMNPRSTUcfgjkmnoprstuvy+-";
char checkoff[256];
int i;
const char *walk;

134
sysctl.c
View File

@ -39,33 +39,33 @@ static bool false = 0;
/*
* Function Prototypes
*/
int Usage(const char *name);
void Preload(const char *filename);
int WriteSetting(const char *setting);
int ReadSetting(const char *setting);
int DisplayAll(const char *path, bool ShowTableUtil);
static int Usage(const char *name);
static void Preload(const char *filename);
static int WriteSetting(const char *setting);
static int ReadSetting(const char *setting);
static int DisplayAll(const char *path, bool ShowTableUtil);
/*
* Globals...
*/
const char *PROC_PATH = "/proc/sys/";
const char *DEFAULT_PRELOAD = "/etc/sysctl.conf";
static const char PROC_PATH[] = "/proc/sys/";
static const char DEFAULT_PRELOAD[] = "/etc/sysctl.conf";
static bool PrintName;
static bool PrintNewline;
/* error messages */
const char *ERR_UNKNOWN_PARAMETER = "error: Unknown parameter '%s'\n";
const char *ERR_MALFORMED_SETTING = "error: Malformed setting '%s'\n";
const char *ERR_NO_EQUALS = "error: '%s' must be of the form name=value\n";
const char *ERR_INVALID_KEY = "error: '%s' is an unknown key\n";
const char *ERR_UNKNOWN_WRITING = "error: unknown error %d setting key '%s'\n";
const char *ERR_UNKNOWN_READING = "error: unknown error %d reading key '%s'\n";
const char *ERR_PERMISSION_DENIED = "error: permission denied on key '%s'\n";
const char *ERR_OPENING_DIR = "error: unable to open directory '%s'\n";
const char *ERR_PRELOAD_FILE = "error: unable to open preload file '%s'\n";
const char *WARN_BAD_LINE = "warning: %s(%d): invalid syntax, continuing...\n";
static const char ERR_UNKNOWN_PARAMETER[] = "error: Unknown parameter '%s'\n";
static const char ERR_MALFORMED_SETTING[] = "error: Malformed setting '%s'\n";
static const char ERR_NO_EQUALS[] = "error: '%s' must be of the form name=value\n";
static const char ERR_INVALID_KEY[] = "error: '%s' is an unknown key\n";
static const char ERR_UNKNOWN_WRITING[] = "error: unknown error %d setting key '%s'\n";
static const char ERR_UNKNOWN_READING[] = "error: unknown error %d reading key '%s'\n";
static const char ERR_PERMISSION_DENIED[] = "error: permission denied on key '%s'\n";
static const char ERR_OPENING_DIR[] = "error: unable to open directory '%s'\n";
static const char ERR_PRELOAD_FILE[] = "error: unable to open preload file '%s'\n";
static const char WARN_BAD_LINE[] = "warning: %s(%d): invalid syntax, continuing...\n";
static void slashdot(char *p, char old, char new){
@ -85,11 +85,11 @@ static void slashdot(char *p, char old, char new){
*
*/
int main(int argc, char **argv) {
const char *me = (const char *)basename(argv[0]);
bool SwitchesAllowed = true;
bool WriteMode = false;
int ReturnCode = 0;
const char *preloadfile = DEFAULT_PRELOAD;
const char *me = (const char *)basename(argv[0]);
bool SwitchesAllowed = true;
bool WriteMode = false;
int ReturnCode = 0;
const char *preloadfile = DEFAULT_PRELOAD;
PrintName = true;
PrintNewline = true;
@ -154,13 +154,13 @@ return ReturnCode;
* Display the usage format
*
*/
int Usage(const char *name) {
static int Usage(const char *name) {
printf("usage: %s [-n] variable ... \n"
" %s [-n] -w variable=value ... \n"
" %s [-n] -a \n"
" %s [-n] -p <file> (default /etc/sysctl.conf) \n"
" %s [-n] -A\n", name, name, name, name, name);
return -1;
return -1;
} /* end Usage() */
@ -168,24 +168,24 @@ return -1;
* Strip the leading and trailing spaces from a string
*
*/
char *StripLeadingAndTrailingSpaces(char *oneline) {
char *t;
static char *StripLeadingAndTrailingSpaces(char *oneline) {
char *t;
if (!oneline || !*oneline)
return oneline;
if (!oneline || !*oneline)
return oneline;
t = oneline;
t += strlen(oneline)-1;
t = oneline;
t += strlen(oneline)-1;
while ((*t == ' ' || *t == '\t' || *t == '\n' || *t == '\r') && t != oneline)
*t-- = 0;
while ((*t==' ' || *t=='\t' || *t=='\n' || *t=='\r') && t!=oneline)
*t-- = 0;
t = oneline;
t = oneline;
while ((*t == ' ' || *t == '\t') && *t != 0)
t++;
while ((*t==' ' || *t=='\t') && *t!=0)
t++;
return t;
return t;
} /* end StripLeadingAndTrailingSpaces() */
@ -195,13 +195,13 @@ return t;
* - we parse the file and then reform it (strip out whitespace)
*
*/
void Preload(const char *filename) {
FILE *fp;
char oneline[257];
char buffer[257];
char *t;
int n = 0;
char *name, *value;
static void Preload(const char *filename) {
FILE *fp;
char oneline[257];
char buffer[257];
char *t;
int n = 0;
char *name, *value;
if (!filename || ((fp = fopen(filename, "r")) == NULL)) {
fprintf(stderr, ERR_PRELOAD_FILE, filename);
@ -249,14 +249,14 @@ char *name, *value;
* Write a sysctl setting
*
*/
int WriteSetting(const char *setting) {
int rc = 0;
const char *name = setting;
const char *value;
const char *equals;
char *tmpname;
FILE *fp;
char *outname;
static int WriteSetting(const char *setting) {
int rc = 0;
const char *name = setting;
const char *value;
const char *equals;
char *tmpname;
FILE *fp;
char *outname;
if (!name) { /* probably don't want to display this err */
return 0;
@ -320,7 +320,7 @@ char *outname;
free(tmpname);
free(outname);
return rc;
return rc;
} /* end WriteSetting() */
@ -329,12 +329,12 @@ return rc;
* Read a sysctl setting
*
*/
int ReadSetting(const char *setting) {
int rc = 0;
char *tmpname, *outname;
char inbuf[1025];
const char *name = setting;
FILE *fp;
static int ReadSetting(const char *setting) {
int rc = 0;
char *tmpname, *outname;
char inbuf[1025];
const char *name = setting;
FILE *fp;
if (!setting || !*setting) {
fprintf(stderr, ERR_INVALID_KEY, setting);
@ -383,7 +383,7 @@ FILE *fp;
free(tmpname);
free(outname);
return rc;
return rc;
} /* end ReadSetting() */
@ -392,13 +392,13 @@ return rc;
* Display all the sysctl settings
*
*/
int DisplayAll(const char *path, bool ShowTableUtil) {
int rc = 0;
int rc2;
DIR *dp;
struct dirent *de;
char *tmpdir;
struct stat ts;
static int DisplayAll(const char *path, bool ShowTableUtil) {
int rc = 0;
int rc2;
DIR *dp;
struct dirent *de;
char *tmpdir;
struct stat ts;
dp = opendir(path);
@ -426,6 +426,6 @@ struct stat ts;
closedir(dp);
} /* endif */
return rc;
return rc;
} /* end DisplayAll() */

19
top.c
View File

@ -271,7 +271,7 @@ static const char *fmtmk (const char *fmts, ...)
* in some proc cmdlines, a choice was offered twix space or null. */
static char *strim (int sp, char *str)
{
static const char *ws = "\b\f\n\r\t\v";
static const char ws[] = "\b\f\n\r\t\v";
char *p;
if (sp)
@ -927,9 +927,8 @@ static void before (char *me)
#ifdef PRETEND4CPUS
Cpu_tot = 4;
#else
Cpu_tot = sysconf(_SC_NPROCESSORS_ONLN);
Cpu_tot = smp_num_cpus;
#endif
if (1 > Cpu_tot) Cpu_tot = 1;
Cpu_map = alloc_r(NULL, sizeof(int) * Cpu_tot);
for (i = 0; i < Cpu_tot; i++)
Cpu_map[i] = i;
@ -955,7 +954,7 @@ static void before (char *me)
* line c: contains w->summclr, msgsclr, headclr, taskclr */
static void configs_read (void)
{
static const char *err_rc = "bad rcfile, you should delete '%s'";
static const char err_rc[] = "bad rcfile, you should delete '%s'";
char fbuf[RCFBUFSIZ];
FILE *fp;
float delay = DEF_DELAY;
@ -1256,7 +1255,7 @@ static void display_fields (const char *fields, const char *xtra)
* Change order of displayed fields. */
static void fields_reorder (void)
{
static const char *prompt =
static const char prompt[] =
"Upper case letter moves field left, lower case right";
char c, *p;
int i;
@ -1286,7 +1285,7 @@ static void fields_reorder (void)
* Select sort field. */
static void fields_sort (void)
{
static const char *prompt =
static const char prompt[] =
"Select sort field via field letter, type any other key to return";
char phoney[PFLAGSSIZ];
char c, *p;
@ -1318,7 +1317,7 @@ static void fields_sort (void)
* Toggle displayed fields. */
static void fields_toggle (void)
{
static const char *prompt =
static const char prompt[] =
"Toggle fields via field letter, type any other key to return";
char c, *p;
int i;
@ -1420,7 +1419,7 @@ static void win_names (WIN_t *q, const char *name)
* Display a window/field group (ie. make it "current"). */
static void win_select (char ch)
{
static const char *prompt = "Choose field group (1 - 4)";
static const char prompt[] = "Choose field group (1 - 4)";
/* if there's no ch, it means we're supporting the normal do_key routine,
so we must try to get our own darn ch by begging the user... */
@ -2107,10 +2106,10 @@ static void show_a_task (WIN_t *q, proc_t *task)
static void do_key (unsigned c)
{
/* standardized 'secure mode' errors */
static const char *err_secure = "\aUnavailable in secure mode";
static const char err_secure[] = "\aUnavailable in secure mode";
#ifdef WARN_NOT_SMP
/* standardized 'smp' errors */
static const char *err_smp = "\aSorry, only 1 cpu detected";
static const char err_smp[] = "\aSorry, only 1 cpu detected";
#endif
switch (c) {

4
w.c
View File

@ -99,8 +99,8 @@ static time_t idletime(char *tty) {
/***** 7 character formatted login time */
static void print_logintime(time_t logt, FILE* fout) {
char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
*month [] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
char weekday[4][] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
month [4][] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec" };
time_t curt;
struct tm *logtm, *curtm;