- int nb = fread (pt, 1, BUFFERSIZE - (pt - buffer), fin);
- VERBOSE (DEBUG, fprintf (stdout, "buffer: %d\n", nb));
- pt = buffer;
- int i = 0;
- while (pt[i] != '\0') {
- if (pt[i++] == '\n') {
- pt[i - 1] = 0;
-
- /* process line */
- char *line = pt;
- VERBOSE (DEBUG, fprintf (stdout, "line: %d\n", strlen (line)));
- VERBOSE (DEBUG, fprintf (stdout, "out: %s\n", line));
- int k = 0;
- int begin = 0;
- while (line[k] != '\0') {
- switch (line[k]) {
- case ' ':
- case '\t':
- if (begin) trailing++;
+ memset (bufin, 0, sizeof (bufin));
+ memset (bufout, 0, sizeof (bufout));
+
+ /* read file */
+ nb = fread (bufin, 1, BUFFERSIZE, fin);
+ VERBOSE (DEBUG, fprintf (stdout, "buffer in: %d\n", nb));
+ if (errno != 0) {
+ VERBOSE (ERROR, fprintf (stderr, "can't read file (%d)\n", errno));
+ exit (1);
+ }
+
+ /* process line */
+ char *ptin = bufin;
+ char *ptout = bufout;
+ while (*ptin != '\0') {
+ VERBOSE (DEBUG, fprintf (stdout, "caracter: %c\n", *ptin));
+
+ /* manage comment */
+ if (comment > 0) {
+ if (((comment == 1) && (*ptin == '\n')) ||
+ ((comment == 2) && ((*ptin == '*') && (ptin[1] == '/')))) {
+ comment = 0;
+ }
+ special = 0;
+ *ptout++ = *ptin++;
+ continue;
+ }
+
+ /* manage indent */
+ switch (*ptin) {
+ case '/':
+ comment = (ptin[1] == '/') ? 1 : (ptin[1] == '*') ? 2 : 0;
+ if (begin) {
+ for (i = 0; i < nbindent * TABSIZE; i++) {
+ *ptout++ = ' ';
+ }
+ begin = 0;
+ }
+ *ptout++ = *ptin;
+ break;
+ case ' ':
+ case '\t':
+ if (begin == 0) {
+ if ((string) || (!space)) {
+ *ptout++ = *ptin;
+ }
+ }
+ break;
+ case '{':
+ *ptout++ = '\n';
+ for (i = 0; i < nbindent * TABSIZE; i++) {
+ *ptout++ = ' ';
+ }
+ *ptout++ = *ptin;
+ *ptout++ = '\n';
+ nbindent++;
+ newline = 1;
+ begin = 1;
+ break;
+ case '}':
+ *ptout++ = '\n';
+ nbindent--;
+ for (i = 0; i < nbindent * TABSIZE; i++) {
+ *ptout++ = ' ';
+ }
+ *ptout++ = *ptin;
+ if (ptin[1] != ';') {
+ *ptout++ = '\n';
+ }
+ newline = 1;
+ begin = 1;
+ break;
+ case ';':
+ *ptout++ = *ptin;
+ if (parent) {