24.01.2014 Views

Codice

Codice

Codice

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

332 volume VI os16<br />

Sorgenti della libreria generale 333<br />

2811043 | if (format[f] == ’]’ && count > 0)<br />

2811044 | {<br />

2811045 | break;<br />

2811046 | }<br />

2811047 | //<br />

2811048 | // Check for an interval.<br />

2811049 | //<br />

2811050 | if (format[f+1] == ’-’<br />

2811051 | && format[f+2] != ’]’<br />

2811052 | && format[f+2] != 0)<br />

2811053 | {<br />

2811054 | //<br />

2811055 | // Interval.<br />

2811056 | //<br />

2811057 | for (index = format[f];<br />

2811058 | index 0 && *input != 0;<br />

2811091 | width--, ptr_char++, input++)<br />

2811092 | {<br />

2811093 | index = *input;<br />

2811094 | if (ascii[index])<br />

2811095 | {<br />

2811096 | if (!flag_star) *ptr_char = *input;<br />

2811097 | count++;<br />

2811098 | }<br />

2811099 | else<br />

2811100 | {<br />

2811101 | break;<br />

2811102 | }<br />

2811103 | }<br />

2811104 | //<br />

2811105 | if (count) consumed++;<br />

2811106 | if (count && !flag_star) assigned++;<br />

2811107 | //<br />

2811108 | f += 1;<br />

2811109 | }<br />

2811110 | else if (format[f] == ’p’)<br />

2811111 | {<br />

2811112 | //------------------------------------------ void *.<br />

2811113 | value_i = strtointmax (input, &next, 16, width);<br />

2811114 | if (input == next)<br />

2811115 | {<br />

2811116 | return (ass_or_eof (consumed, assigned));<br />

2811117 | }<br />

2811118 | consumed++;<br />

2811119 | if (!flag_star)<br />

2811120 | {<br />

2811121 | ptr_void = va_arg (ap, void **);<br />

2811122 | *ptr_void = (void *) ((int) value_i);<br />

2811123 | assigned++;<br />

2811124 | }<br />

2811125 | f += 1;<br />

2811126 | input = next;<br />

2811127 | }<br />

2811128 | else if (format[f] == ’n’)<br />

2811129 | {<br />

2811130 | //--------------- signed char, string index counter.<br />

2811131 | ptr_sint = va_arg (ap, signed int *);<br />

2811132 | *ptr_sint = (signed char) (input - start + scanned);<br />

2811133 | f += 1;<br />

2811134 | }<br />

2811135 | else<br />

2811136 | {<br />

2811137 | //---------------- unsupported or unknown specifier.<br />

2811138 | ;<br />

2811139 | }<br />

2811140 |<br />

2811141 | //------------------------------------------------------<br />

2811142 | // End of specifier.<br />

2811143 | //------------------------------------------------------<br />

2811144 |<br />

2811145 | width_string[0] = ’\0’;<br />

2811146 | specifier = 0;<br />

2811147 | specifier_flags = 0;<br />

2811148 | specifier_width = 0;<br />

2811149 | specifier_type = 0;<br />

2811150 | flag_star = 0;<br />

2811151 |<br />

2811152 | }<br />

2811153 | }<br />

2811154 | //<br />

2811155 | // The format or the input string is terminated.<br />

2811156 | //<br />

2811157 | if (&format[f] < end_format && stream)<br />

2811158 | {<br />

2811159 | //<br />

2811160 | // Only the input string is finished, and the input comes<br />

2811161 | // from a stream, so another read will be done.<br />

2811162 | //<br />

2811163 | scanned += (int) (input - start);<br />

2811164 | continue;<br />

2811165 | }<br />

2811166 | //<br />

2811167 | // The format string is terminated.<br />

2811168 | //<br />

2811169 | return (ass_or_eof (consumed, assigned));<br />

2811170 | }<br />

2811171 |}<br />

2811172 |//----------------------------------------------------------------------<br />

2811173 |static intmax_t<br />

2811174 |strtointmax (const char *restrict string, char **endptr,<br />

2811175 | int base, size_t max_width)<br />

2811176 |{<br />

2811177 | int i;<br />

2811178 | int d; // Digits counter.<br />

2811179 | int sign = +1;<br />

2811180 | intmax_t number;<br />

2811181 | intmax_t previous;<br />

2811182 | int digit;<br />

2811183 | //<br />

2811184 | bool flag_prefix_oct = 0;<br />

2811185 | bool flag_prefix_exa = 0;<br />

2811186 | bool flag_prefix_dec = 0;<br />

2811187 | //<br />

2811188 | // If the ‘max_width’ value is zero, fix it to the maximum<br />

2811189 | // that it can represent.<br />

2811190 | //<br />

2811191 | if (max_width == 0)<br />

2811192 | {<br />

2811193 | max_width = SIZE_MAX;<br />

2811194 | }<br />

2811195 | //<br />

2811196 | // Eat initial spaces, but if there are spaces, there is an<br />

2811197 | // error inside the calling function!<br />

2811198 | //<br />

2811199 | for (i = 0; isspace (string[i]); i++)<br />

2811200 | {<br />

2811201 | fprintf (stderr, "libc error: file \"%s\", line %i\n",<br />

2811202 | __FILE__, __LINE__);<br />

2811203 | ;<br />

2811204 | }<br />

2811205 | //<br />

2811206 | // Check sign. The ‘max_width’ counts also the sign, if there is<br />

2811207 | // one.<br />

2811208 | //<br />

2811209 | if (string[i] == ’+’)<br />

2811210 | {<br />

2811211 | sign = +1;<br />

2811212 | i++;<br />

2811213 | max_width--;<br />

2811214 | }<br />

2811215 | else if (string[i] == ’-’)<br />

2811216 | {<br />

2811217 | sign = -1;<br />

2811218 | i++;<br />

2811219 | max_width--;<br />

2811220 | }<br />

2811221 | //<br />

2811222 | // Check for prefix.<br />

2811223 | //<br />

2811224 | if (string[i] == ’0’)<br />

2811225 | {<br />

2811226 | if (string[i+1] == ’x’ || string[i+1] == ’X’)<br />

2811227 | {<br />

2811228 | flag_prefix_exa = 1;<br />

2811229 | }<br />

2811230 | if (isdigit (string[i+1]))<br />

2811231 | {<br />

2811232 | flag_prefix_oct = 1;<br />

2811233 | }<br />

2811234 | }<br />

2811235 | //<br />

2811236 | if (string[i] > ’0’ && string[i]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!