From: Erez Zadok Date: Mon, 15 Aug 2005 01:57:06 +0000 (+0000) Subject: consistify X-Git-Tag: before-clocktime-fixes~26 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=a0ac7619d34779fc5375f5d79d5a9c58629c28f6;p=am-utils-6.1.git consistify --- diff --git a/amd/sun2amd.c b/amd/sun2amd.c index 5fcd3b0..6cf3b1c 100644 --- a/amd/sun2amd.c +++ b/amd/sun2amd.c @@ -63,26 +63,26 @@ struct amu_global_options gopt; * the results to amd_out. */ static int -sun2amd_convert(FILE *sun_in, FILE *amd_out) -{ +sun2amd_convert(FILE *sun_in, FILE *amd_out) +{ char line_buff[INFO_MAX_LINE_LEN], *tmp, *key, *entry; int pos, line = 0, retval = 1; - + /* just to be safe */ memset(line_buff, 0, sizeof(line_buff)); - + /* Read the input line by line and do the conversion. */ while ((pos = file_read_line(line_buff, sizeof(line_buff), sun_in))) { line++; - + /* Make sure we have the whole line. */ if (line_buff[pos - 1] != '\n') { plog(XLOG_ERROR, "map line %d is too long", line); goto err; } - + line_buff[pos - 1] = '\0'; - + /* remove comments */ if ((tmp = strchr(line_buff, '#')) != NULL) { *tmp = '\0'; @@ -93,12 +93,12 @@ sun2amd_convert(FILE *sun_in, FILE *amd_out) while (*key != '\0' && isspace((int)*key)) { key++; } - + /* ignore blank lines */ if (*key == '\0') { continue; } - + /* find the end of the key and NULL terminate */ tmp = key; while (*tmp != '\0' && isspace((int)*tmp) == 0) { @@ -109,22 +109,22 @@ sun2amd_convert(FILE *sun_in, FILE *amd_out) goto err; } *tmp++ = '\0'; - if(*tmp == '\0') { + if (*tmp == '\0') { plog(XLOG_ERROR, "map line %d has no entry", line); goto err; } entry = tmp; - + /* convert the sun entry to an amd entry */ if ((tmp = sun_entry2amd(key, entry)) == NULL) { goto err; } - + if (fputs(tmp, amd_out) == EOF) { plog(XLOG_ERROR, "can't write amd entry on line %d: fputs: %s", line, strerror(errno)); goto err; } - + /* just to be safe */ memset(line_buff, 0, sizeof(line_buff)); } @@ -134,36 +134,36 @@ sun2amd_convert(FILE *sun_in, FILE *amd_out) err: return retval; -} +} -/* - * wrapper open function +/* + * wrapper open function */ static FILE * -sun2amd_open(const char *path, const char *mode) +sun2amd_open(const char *path, const char *mode) { FILE *retval = NULL; - + if ((retval = fopen(path,mode)) == NULL) { plog(XLOG_ERROR,"could not open file %s",path); } - + return retval; } -/* - * echo the usage and exit +/* + * echo the usage and exit */ static void -sun2amd_usage(void) +sun2amd_usage(void) { fprintf(stderr, "usage : sun2amd [-hH] [-i infile] [-o outfile]\n" "-h\thelp\n" "-i\tspecify an infile (defaults to stdin)\n" - "-o\tspecify an outfile (defaults to stdout)\n"); + "-o\tspecify an outfile (defaults to stdout)\n"); } @@ -173,29 +173,29 @@ main(int argc, char **argv) /* default in/out to stdin/stdout */ FILE *sun_in = stdin, *amd_out = stdout; int opt, retval = 1; - + while ((opt = getopt(argc, argv , "i:o:hH")) != -1) { switch (opt) { - + case 'i': if ((sun_in = sun2amd_open(optarg,"r")) == NULL) { goto err; } break; - + case 'o': if ((amd_out = sun2amd_open(optarg,"w")) == NULL) { goto err; } break; - + case 'h': case 'H': sun2amd_usage(); goto err; - } + } } - + retval = sun2amd_convert(sun_in,amd_out); err: diff --git a/amd/sun_map.c b/amd/sun_map.c index 7cc62ff..cdc8211 100644 --- a/amd/sun_map.c +++ b/amd/sun_map.c @@ -91,16 +91,16 @@ sun_list_add(struct sun_list *list, qelem *item) #define AMD_RHOST_KW "rhost:=" /* remote host */ #define AMD_RFS_KW "rfs:=" /* remote file system */ #define AMD_FS_KW "fs:=" /* local file system */ -#define AMD_TYPE_NFS_KW "type:=nfs;" /* fs type nfs */ +#define AMD_TYPE_NFS_KW "type:=nfs;" /* fs type nfs */ #define AMD_TYPE_AUTO_KW "type:=auto;" /* fs type auto */ #define AMD_MAP_FS_KW "fs:=${map};" /* set the mount map as current map */ #define AMD_MAP_PREF_KW "pref:=${key};" /* set the mount map as current map */ -#define SUN_KEY_SUB "&" /* Sun key subsitution */ +#define SUN_KEY_SUB "&" /* Sun key subsitution */ /* a set a Sun variable substitutions for map entries */ -#define SUN_ARCH "$ARCH" /* host architecture */ +#define SUN_ARCH "$ARCH" /* host architecture */ #define SUN_CPU "$CPU" /* processor type */ #define SUN_HOST "$HOST" /* host name */ #define SUN_OSNAME "$OSNAME" /* OS name */ @@ -126,14 +126,14 @@ sun_list_add(struct sun_list *list, qelem *item) * return - new string with str substitutions, NULL on error */ static char * -sun_strsub(const char *src, const char *str, const char *sub) +sun_strsub(const char *src, const char *str, const char *sub) { - + char *retval = NULL, *str_start, *str_end, *src_end; size_t total_size, first_half, second_half, sub_size; - + /* assign pointers to the start and end of str */ - if((str_start = strstr(src, str)) == NULL) { + if ((str_start = strstr(src, str)) == NULL) { return retval; } str_end = (strlen(str) - 1) + str_start; @@ -143,18 +143,18 @@ sun_strsub(const char *src, const char *str, const char *sub) /* size from the beginning of src to the start of str */ first_half = (size_t)(str_start - src); - + /* size from the end of str to the end of src */ second_half = (size_t)(src_end - str_end); - + sub_size = strlen(sub); - + total_size = (first_half + sub_size + second_half + 1); - + retval = (char*)xmalloc(total_size); memset(retval, 0, total_size); - /* + /* * Put together the string such that the first half is copied * followed the sub and second half. * @@ -166,13 +166,13 @@ sun_strsub(const char *src, const char *str, const char *sub) (void)strncat(retval, sub, sub_size); (void)strncat(retval, str_end + 1, second_half); - if((str_start = strstr(retval, str)) != NULL) { + if ((str_start = strstr(retval, str)) != NULL) { /* * If there is another occurrences of str call this function * recursively. */ char* tmp; - if((tmp = sun_strsub(retval, str, sub)) != NULL) { + if ((tmp = sun_strsub(retval, str, sub)) != NULL) { XFREE(retval); retval = tmp; } @@ -192,12 +192,12 @@ sun_strsub(const char *src, const char *str, const char *sub) * exist in src or error. */ static char * -sun_expand2amd(const char *str) +sun_expand2amd(const char *str) { - + char *retval = NULL, *tmp = NULL, *tmp2 = NULL; const char *pos; - + /* * Iterator through the string looking for '$' chars. For each '$' * found try to replace it with Sun variable substitions. If we @@ -215,7 +215,7 @@ sun_expand2amd(const char *str) tmp = tmp2; } - /* + /* * If a 'replace' does not retuen NULL than a variable was * successfully subsituted. */ @@ -236,7 +236,7 @@ sun_expand2amd(const char *str) if ((tmp2 = sun_strsub(tmp, SUN_OSNAME, AMD_OSNAME)) != NULL) { continue; } - /* + /* * os release - Amd doesn't hava a OS release var just usr os * version or now. */ @@ -252,16 +252,16 @@ sun_expand2amd(const char *str) continue; } } - if(tmp2 == NULL) { + if (tmp2 == NULL) { retval = tmp; } else { retval = tmp2; - if(tmp != NULL) { + if (tmp != NULL) { XFREE(tmp); } } - + return retval; } @@ -280,25 +280,25 @@ static void sun_append_str(char *dest, size_t destlen, const char *key, - const char *str) + const char *str) { char *sub = NULL, *sub2 = NULL, *out = NULL; /* By default we are going to just write the original string. */ out = (char*)str; - /* + /* * Resolve variable substititions in two steps; 1) replace any key * map substitutions with the entry key 2) expand any variable * substitutions i.e $HOST. - * + * * Try to replace the key substitution '&'. If this function returns * with a new string, one or more key subs. where replaced with the * entry key. */ if ((sub = sun_strsub(str, SUN_KEY_SUB, key)) != NULL) { out = sub; - /* + /* * Try to convert any variable substitutions. If this function * returns a new string one or more var subs where expanded. */ @@ -306,18 +306,18 @@ sun_append_str(char *dest, out = sub2; } } - /* + /* * Try to convert any variable substitutions. If this function * returns a new string one or more var subs where expanded. */ else if ((sub = sun_expand2amd(out)) != NULL) { out = sub; } - + if (out != NULL) { xstrlcat(dest, out, destlen); } - if (sub != NULL) { + if (sub != NULL) { XFREE(sub); } if (sub2 != NULL) { @@ -336,7 +336,7 @@ sun_append_str(char *dest, * param opt_list - list of Sun mount options */ static void -sun_opts2amd(char *dest, +sun_opts2amd(char *dest, size_t destlen, const char *key, const struct sun_opt *opt_list) @@ -344,12 +344,12 @@ sun_opts2amd(char *dest, const struct sun_opt *opt; xstrlcat(dest, AMD_OPTS_KW, destlen); - + /* Iterate through each option and append it to the buffer. */ for(opt = opt_list; opt != NULL; opt = NEXT(struct sun_opt, opt)) { sun_append_str(dest, destlen, key, opt->str); /* If there are more options add some commas. */ - if(NEXT(struct sun_opt, opt) != NULL) { + if (NEXT(struct sun_opt, opt) != NULL) { xstrlcat(dest, ",", destlen); } } @@ -460,8 +460,8 @@ sun_mountpts2amd(char *dest, * param s_entry - Sun entry */ static void -sun_nfs2amd(char *dest, - size_t destlen, +sun_nfs2amd(char *dest, + size_t destlen, const char *key, const struct sun_entry *s_entry) { @@ -479,7 +479,7 @@ sun_nfs2amd(char *dest, } else { /* multiple NFS mount points */ - + /* We need to setup a auto fs Amd automount point. */ xstrlcat(dest, AMD_TYPE_AUTO_KW, destlen); xstrlcat(dest, AMD_MAP_FS_KW, destlen); @@ -511,9 +511,9 @@ sun_entry2amd(const char *key, const char *s_entry) plog(XLOG_ERROR,"could not parse Sun style map"); goto err; } - + memset(line_buff, 0, sizeof(line_buff)); - + if (s_entry_obj->opt_list != NULL) { /* write the mount options to the buffer */ sun_opts2amd(line_buff, sizeof(line_buff), key, s_entry_obj->opt_list); @@ -540,7 +540,7 @@ sun_entry2amd(const char *key, const char *s_entry) plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.", s_entry_obj->fstype); goto err; - + } else if (NSTREQ(s_entry_obj->fstype, SUN_CACHEFS_TYPE, strlen(SUN_CACHEFS_TYPE))) { /* CacheFS Type */ diff --git a/amd/sun_map_parse.y b/amd/sun_map_parse.y index e2996fc..25904c0 100644 --- a/amd/sun_map_parse.y +++ b/amd/sun_map_parse.y @@ -138,7 +138,7 @@ entry : locations { entry = CALLOC(struct sun_entry); /* An fstype may have been defined in the 'options'. */ - if(tmpFsType != NULL) { + if (tmpFsType != NULL) { entry->fstype = tmpFsType; tmpFsType = NULL; } @@ -195,7 +195,7 @@ entry : locations { entry = CALLOC(struct sun_entry); /* An fstype may have been defined in the 'options'. */ - if(tmpFsType != NULL) { + if (tmpFsType != NULL) { entry->fstype = tmpFsType; tmpFsType = NULL; } @@ -383,22 +383,22 @@ options : option option : WORD { char *type; - + /* check if this is an fstype option */ if ((type = strstr($1,SUN_FSTYPE_STR)) != NULL) { /* parse out the fs type from the Sun fstype keyword */ if ((type = type + strlen(SUN_FSTYPE_STR)) != NULL) { - /* + /* * This global fstype str will be assigned to the current being * parsed later in the parsing. - */ + */ tmpFsType = strdup(type); } } else { - /* + /* * If it is not an fstype option allocate an opt struct and assign - * the value. + * the value. */ struct sun_opt *opt = CALLOC(struct sun_opt); opt->str = strdup($1); @@ -418,7 +418,7 @@ option : WORD { * The parser is designed to parse map entries with out the keys. For * example the entry: * - * usr -ro pluto:/usr/local + * usr -ro pluto:/usr/local * * should be passed to the parser as: * diff --git a/amd/sun_map_tok.l b/amd/sun_map_tok.l index 918b174..105a71d 100644 --- a/amd/sun_map_tok.l +++ b/amd/sun_map_tok.l @@ -88,8 +88,8 @@ void sun_map_tok_setbuff(const char* buff); const char *sun_map_tok_buff = NULL; #ifdef FLEX_SCANNER -/* - * The flex scanner uses the YY_INPUT to parse the input. +/* + * The flex scanner uses the YY_INPUT to parse the input. * We need to redefine it so that it can parse strings. * In addition to the above string buffer we need to have * a position pointer and a end pointer. @@ -108,14 +108,14 @@ int sun_map_input(char *buff, int maxsize); # define YY_INPUT(buff,result,maxsize) (result = sun_map_input(buff,maxsize)) #else -/* - * If this is not Flex than fall back to an AT&T style lex. +/* + * If this is not Flex than fall back to an AT&T style lex. * We can parse strings by redefining input and unput. */ #undef input #undef unput #define input() (*(char *)sun_map_tok_buff++) -#define unput(c) (*(char *)--sun_map_tok_buff = c) +#define unput(c) (*(char *)--sun_map_tok_buff = c) #endif /* FLEX_SCANNER */ @@ -214,7 +214,7 @@ sun_map_input(char *buff, int maxsize) return size; } -#else +#else void sun_map_tok_setbuff(const char* buff) {