|
|
1.1 ! root 1: .TH GETFIELDS 3 ! 2: .CT 2 data_man ! 3: .SH NAME ! 4: getfields, getmfields, setfields \(mi break a string into fields ! 5: .SH SYNOPSIS ! 6: .nf ! 7: .B int getfields(str, ptrs, nptrs) ! 8: .B char *str, **ptrs; ! 9: .PP ! 10: .B int getmfields(str, ptrs, nptrs) ! 11: .B char *str, **ptrs; ! 12: .PP ! 13: .B void setfields(fielddelim) ! 14: .B char *fielddelim; ! 15: .fi ! 16: .SH DESCRIPTION ! 17: .I Getfields ! 18: breaks the null-terminated string ! 19: .I str ! 20: into at most ! 21: .I nptrs ! 22: null-terminated fields and places pointers to the start of these fields in the array ! 23: .IR ptrs . ! 24: It returns the number of fields ! 25: and terminates the list of pointers with a zero pointer. ! 26: It overwrites some of the bytes in ! 27: .IR str . ! 28: If there are ! 29: .I nptr ! 30: or more fields, the list will not end with zero ! 31: and the last `field' will extend to the end of the ! 32: input string and may contain delimiters. ! 33: .PP ! 34: A field is defined as a maximal sequence of characters not in a set ! 35: of field delimiters. ! 36: Adjacent fields are separated by exactly one delimiter. ! 37: No field follows a delimiter at the end of string. ! 38: Thus a string of just two delimiter characters ! 39: contains two empty fields, ! 40: and a nonempty string with no delimiters contains ! 41: one field. ! 42: .PP ! 43: .I Getmfields ! 44: is the same as ! 45: .I getfields ! 46: except that fields are separated by maximal strings of ! 47: field delimiters rather than just one. ! 48: .PP ! 49: .I Setfields ! 50: makes the field delimiters (space and tab by default) ! 51: be the characters of the string ! 52: .I fielddelim. ! 53: .SH EXAMPLES ! 54: Print the words in a string, where words are non-whitespace ! 55: strings. ! 56: There is no bound on the number of words. ! 57: .EX ! 58: printwords(string) ! 59: char *string; ! 60: { ! 61: char *ptrs[2]; ! 62: int n; ! 63: setfields(" \et\en"); ! 64: for(n=2; n>=2; string=ptrs[1]) { ! 65: n = getmfields(string, ptrs, 2); ! 66: if(n == 0) ! 67: break; ! 68: if(ptrs[0][0] != 0) /* skip initial blanks */ ! 69: printf("%s\en", ptrs[0]); ! 70: } ! 71: } ! 72: .EE ! 73: .SH SEE ALSO ! 74: .IR string (3)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.