[nas] followon reindent patch: gram.y and lex.l

Paul Fox pgf at foxharp.boston.ma.us
Wed Jul 26 10:56:26 MDT 2006


i didn't do these yacc and lex files initially, but realized
there's enough code in there to make it worthwhile doing subsections
manually.  this also eliminates tabs.

paul

Index: dia/lex.l
===================================================================
--- dia/lex.l	(revision 165)
+++ dia/lex.l	(working copy)
@@ -10,58 +10,60 @@
 
 %}
 
-string				\"([^"]|\\.)*\"
-number				[0-9]+
+string                          \"([^"]|\\.)*\"
+number                          [0-9]+
 %%
 
-[Dd][Ee][Bb][Uu][Gg]			{ return CDEBUG; }
-[Vv][Ee][Rr][Bb][Oo][Ss][Ee]		{ return VERBOSE; }
+[Dd][Ee][Bb][Uu][Gg]                    { return CDEBUG; }
+[Vv][Ee][Rr][Bb][Oo][Ss][Ee]            { return VERBOSE; }
 [Rr][Ee][Ll][Ee][Aa][Ss][Ee][Dd][Ee][Vv][Ii][Cc][Ee]   { return RELEASEDEVICE;}
 [Ii][Nn][Pp][Uu][Tt][Ss][Ee][Cc][Tt][Ii][Oo][Nn] { return INPUTSECTION; }
 [Oo][Uu][Tt][Pp][Uu][Tt][Ss][Ee][Cc][Tt][Ii][Oo][Nn] { return OUTPUTSECTION; }
 [Ee][Nn][Dd]                            { return ENDSECTION; }
 [Gg][Aa][Ii][Nn]                        { return GAIN; }
 [Gg][Aa][Ii][Nn][Ss][Cc][Aa][Ll][Ee]    { return GAINSCALE; }
-[Ww][Oo][Rr][Dd][Ss][Ii][Zz][Ee]	{ return WORDSIZE; }
-[Ff][Rr][Aa][Gg][Ss][Ii][Zz][Ee]	{ return FRAGSIZE; }
-[Mm][Ii][Nn][Ff][Rr][Aa][Gg][Ss]	{ return MINFRAGS; }
-[Mm][Aa][Xx][Ff][Rr][Aa][Gg][Ss]	{ return MAXFRAGS; }
-[Nn][Uu][Mm][Cc][Hh][Aa][Nn][Ss]	{ return NUMCHANS; }
-[Mm][Aa][Xx][Rr][Aa][Tt][Ee]		{ return MAXRATE; }
-[Mm][Ii][Nn][Rr][Aa][Tt][Ee]		{ return MINRATE; }
-[Dd][Ee][Vv][Ii][Cc][Ee]		{ return DEVICE; }
-[Mm][Ii][Xx][Ee][Rr]			{ return MIXER; }
-[Rr][Ee][Aa][Dd][Ww][Rr][Ii][Tt][Ee]	{ return READWRITE; }
+[Ww][Oo][Rr][Dd][Ss][Ii][Zz][Ee]        { return WORDSIZE; }
+[Ff][Rr][Aa][Gg][Ss][Ii][Zz][Ee]        { return FRAGSIZE; }
+[Mm][Ii][Nn][Ff][Rr][Aa][Gg][Ss]        { return MINFRAGS; }
+[Mm][Aa][Xx][Ff][Rr][Aa][Gg][Ss]        { return MAXFRAGS; }
+[Nn][Uu][Mm][Cc][Hh][Aa][Nn][Ss]        { return NUMCHANS; }
+[Mm][Aa][Xx][Rr][Aa][Tt][Ee]            { return MAXRATE; }
+[Mm][Ii][Nn][Rr][Aa][Tt][Ee]            { return MINRATE; }
+[Dd][Ee][Vv][Ii][Cc][Ee]                { return DEVICE; }
+[Mm][Ii][Xx][Ee][Rr]                    { return MIXER; }
+[Rr][Ee][Aa][Dd][Ww][Rr][Ii][Tt][Ee]    { return READWRITE; }
 [Mm][Ii][Xx][Ee][Rr][Ii][Nn][Ii][Tt]    { return MIXERINIT; }
 [Oo][Uu][Tt][Dd][Ee][Vv][Tt][Yy][Pp][Ee]  { return OUTDEVTYPE; }
-[Ff][Oo][Rr][Cc][Ee][Rr][Aa][Tt][Ee]	{ return FORCERATE; }
-[Aa][Uu][Tt][Oo][Oo][Pp][Ee][Nn]	{ return AUTOOPEN; }
+[Ff][Oo][Rr][Cc][Ee][Rr][Aa][Tt][Ee]    { return FORCERATE; }
+[Aa][Uu][Tt][Oo][Oo][Pp][Ee][Nn]        { return AUTOOPEN; }
 
 
-{string}			{ yylval.ptr = (char *)yytext; return STRING; }
-{number}			{ (void)sscanf((char *)yytext, "%d", &yylval.num);
-				  return (NUMBER);
-				}
+{string}                        { yylval.ptr = (char *)yytext; return STRING; }
+{number}                        { (void)sscanf((char *)yytext, "%d", &yylval.num);
+                                  return (NUMBER);
+                                }
 #+.*                            {;}
-[\t ]				{;}
+[\t ]                           {;}
 \n                              {Lineno++;}
-.				{
-				  fprintf (stderr, 
-					   "ignoring character \"%s\"\n",
-					   yytext);
-				}
+.                               {
+                                  fprintf (stderr, 
+                                           "ignoring character \"%s\"\n",
+                                           yytext);
+                                }
 %%
 #ifndef yywrap
-yywrap() { return(1);}
+yywrap()
+{
+    return (1);
+}
 #endif
 
 /* parser error reporting routine */
-void yyerror(char *s)
+void
+yyerror(char *s)
 {
-   fprintf(stderr, "lex.l: %s at or near '%s' on line %d.\n",
-           s,
-           yytext,
-           Lineno);
+    fprintf(stderr, "lex.l: %s at or near '%s' on line %d.\n",
+            s, yytext, Lineno);
 
-  return;
+    return;
 }
Index: dia/gram.y
===================================================================
--- dia/gram.y	(revision 165)
+++ dia/gram.y	(working copy)
@@ -13,7 +13,7 @@
 #include "aulog.h"
 #include "misc.h"
 
-static char	*ptr;
+static char     *ptr;
 static int parsebool(char *str);
 extern int yylineno;
 
@@ -38,121 +38,119 @@
 %start auconfig 
 
 %%
-auconfig	: globstmts sectconfigs
-		;
+auconfig        : globstmts sectconfigs
+                ;
 
-globstmts	: /* Empty */
-		| globstmts globstmt
-		;
+globstmts       : /* Empty */
+                | globstmts globstmt
+                ;
 
-globstmt	: VERBOSE
-			{ NasConfig.DoVerbose = TRUE; }
-		| CDEBUG number
-			{ NasConfig.DoDebug = $2 ; }
+globstmt        : VERBOSE
+                        { NasConfig.DoVerbose = TRUE; }
+                | CDEBUG number
+                        { NasConfig.DoDebug = $2 ; }
                 | RELEASEDEVICE string
                         {
-			  int j;
+                          int j;
 
-			  j = parsebool($2);
-			  if (j == -1)
-			    {
-				/* error - default to no */
-			      NasConfig.DoDeviceRelease = FALSE;
-			    }
-			  else
-			    NasConfig.DoDeviceRelease = j; 
-			}
+                          j = parsebool($2);
+                          if (j == -1) {
+                                /* error - default to no */
+                              NasConfig.DoDeviceRelease = FALSE;
+                          } else 
+                            NasConfig.DoDeviceRelease = j; 
+                        }
                 | MIXERINIT string
                         { ddaSetConfig(MIXERINIT, (void *)parsebool($2)); }  
                 | OUTDEVTYPE string
                         { ddaSetConfig(OUTDEVTYPE, (void *)$2); }  
-		;
+                ;
 
-sectconfigs	: /* Empty */
-		| sectconfigs sectconfig
-		;
+sectconfigs     : /* Empty */
+                | sectconfigs sectconfig
+                ;
 
-sectconfig	: inputconfig
-		| outputconfig
-		;
+sectconfig      : inputconfig
+                | outputconfig
+                ;
 
-inputconfig	: inputword stmts ENDSECTION
-		;
+inputconfig     : inputword stmts ENDSECTION
+                ;
 
-inputword	: INPUTSECTION
-			{ ddaSetConfig(CONF_SET_SECTION, (void *)INPUTSECTION); }
-		;
+inputword       : INPUTSECTION
+                        { ddaSetConfig(CONF_SET_SECTION, (void *)INPUTSECTION); }
+                ;
 
-outputconfig	: outputword stmts ENDSECTION
-		;
+outputconfig    : outputword stmts ENDSECTION
+                ;
 
-outputword	: OUTPUTSECTION
-			{ ddaSetConfig(CONF_SET_SECTION, (void *)OUTPUTSECTION); }
-		;
+outputword      : OUTPUTSECTION
+                        { ddaSetConfig(CONF_SET_SECTION, (void *)OUTPUTSECTION); }
+                ;
 
-stmts		: /* Empty */
-		| stmts stmt
-		;
+stmts           : /* Empty */
+                | stmts stmt
+                ;
 
-stmt		: error
-		| AUTOOPEN string
-			{
-			  ddaSetConfig(AUTOOPEN, (void *)parsebool($2));
-			}
-		| FORCERATE string
-			{
-			  ddaSetConfig(FORCERATE, (void *)parsebool($2));
-			}
-		| READWRITE string
-			{
-			  ddaSetConfig(READWRITE, (void *)parsebool($2));
-			}
-		| MIXER string
-			{
-			  ddaSetConfig(MIXER, (void *)$2);
-			}
-		| DEVICE string
-			{
-			  ddaSetConfig(DEVICE, (void *)$2);
-			}
-		| WORDSIZE number
-			{
-			  ddaSetConfig(WORDSIZE, (void *)$2);
-			}
-		| FRAGSIZE number
-			{ 
-			  ddaSetConfig(FRAGSIZE, (void *)$2);
-			}
-		| MINFRAGS number
-			{
-			  ddaSetConfig(MINFRAGS, (void *)$2);
-			}
-		| MAXFRAGS number
-			{
-			  ddaSetConfig(MAXFRAGS, (void *)$2);
-			}
-		| NUMCHANS number
-			{
-			  ddaSetConfig(NUMCHANS, (void *)$2);
-			}
-		| MAXRATE number
-			{ ddaSetConfig(MAXRATE, (void *)$2); }
-		| MINRATE number
-			{ ddaSetConfig(MINRATE, (void *)$2); }
-		| GAIN number
-			{ ddaSetConfig(GAIN, (void *)$2); }
-		| GAINSCALE number
-			{ ddaSetConfig(GAINSCALE, (void *)$2); }
+stmt            : error
+                | AUTOOPEN string
+                        {
+                          ddaSetConfig(AUTOOPEN, (void *)parsebool($2));
+                        }
+                | FORCERATE string
+                        {
+                          ddaSetConfig(FORCERATE, (void *)parsebool($2));
+                        }
+                | READWRITE string
+                        {
+                          ddaSetConfig(READWRITE, (void *)parsebool($2));
+                        }
+                | MIXER string
+                        {
+                          ddaSetConfig(MIXER, (void *)$2);
+                        }
+                | DEVICE string
+                        {
+                          ddaSetConfig(DEVICE, (void *)$2);
+                        }
+                | WORDSIZE number
+                        {
+                          ddaSetConfig(WORDSIZE, (void *)$2);
+                        }
+                | FRAGSIZE number
+                        { 
+                          ddaSetConfig(FRAGSIZE, (void *)$2);
+                        }
+                | MINFRAGS number
+                        {
+                          ddaSetConfig(MINFRAGS, (void *)$2);
+                        }
+                | MAXFRAGS number
+                        {
+                          ddaSetConfig(MAXFRAGS, (void *)$2);
+                        }
+                | NUMCHANS number
+                        {
+                          ddaSetConfig(NUMCHANS, (void *)$2);
+                        }
+                | MAXRATE number
+                        { ddaSetConfig(MAXRATE, (void *)$2); }
+                | MINRATE number
+                        { ddaSetConfig(MINRATE, (void *)$2); }
+                | GAIN number
+                        { ddaSetConfig(GAIN, (void *)$2); }
+                | GAINSCALE number
+                        { ddaSetConfig(GAINSCALE, (void *)$2); }
                 ;
 
-string		: STRING		{ ptr = (char *)malloc(strlen($1)+1);
-					  strcpy(ptr, $1);
-					  RemoveDQuote(ptr);
-					  $$ = ptr;
-					}
+string          : STRING                { ptr = (char *)malloc(strlen($1)+1);
+                                          strcpy(ptr, $1);
+                                          RemoveDQuote(ptr);
+                                          $$ = ptr;
+                                        }
                 ;
-number		: NUMBER		{ $$ = $1; }
-		;
+number          : NUMBER                { $$ = $1; }
+                ;
 
 %%
 
@@ -163,117 +161,111 @@
     register n;
     register count;
 
-    for (i=str+1, o=str; *i && *i != '\"'; o++)
-    {
-	if (*i == '\\')
-	{
-	    switch (*++i)
-	    {
-	    case 'n':
-		*o = '\n';
-		i++;
-		break;
-	    case 'b':
-		*o = '\b';
-		i++;
-		break;
-	    case 'r':
-		*o = '\r';
-		i++;
-		break;
-	    case 't':
-		*o = '\t';
-		i++;
-		break;
-	    case 'f':
-		*o = '\f';
-		i++;
-		break;
-	    case '0':
-		if (*++i == 'x')
-		    goto hex;
-		else
-		    --i;
-	    case '1': case '2': case '3':
-	    case '4': case '5': case '6': case '7':
-		n = 0;
-		count = 0;
-		while (*i >= '0' && *i <= '7' && count < 3)
-		{
-		    n = (n<<3) + (*i++ - '0');
-		    count++;
-		}
-		*o = n;
-		break;
-	    hex:
-	    case 'x':
-		n = 0;
-		count = 0;
-		while (i++, count++ < 2)
-		{
-		    if (*i >= '0' && *i <= '9')
-			n = (n<<4) + (*i - '0');
-		    else if (*i >= 'a' && *i <= 'f')
-			n = (n<<4) + (*i - 'a') + 10;
-		    else if (*i >= 'A' && *i <= 'F')
-			n = (n<<4) + (*i - 'A') + 10;
-		    else
-			break;
-		}
-		*o = n;
-		break;
-	    case '\n':
-		i++;	/* punt */
-		o--;	/* to account for o++ at end of loop */
-		break;
-	    case '\"':
-	    case '\'':
-	    case '\\':
-	    default:
-		*o = *i++;
-		break;
-	    }
-	}
-	else
-	    *o = *i++;
+    for (i = str + 1, o = str; *i && *i != '\"'; o++) {
+        if (*i == '\\') {
+            switch (*++i) {
+            case 'n':
+                *o = '\n';
+                i++;
+                break;
+            case 'b':
+                *o = '\b';
+                i++;
+                break;
+            case 'r':
+                *o = '\r';
+                i++;
+                break;
+            case 't':
+                *o = '\t';
+                i++;
+                break;
+            case 'f':
+                *o = '\f';
+                i++;
+                break;
+            case '0':
+                if (*++i == 'x')
+                    goto hex;
+                else
+                    --i;
+            case '1':
+            case '2':
+            case '3':
+            case '4':
+            case '5':
+            case '6':
+            case '7':
+                n = 0;
+                count = 0;
+                while (*i >= '0' && *i <= '7' && count < 3) {
+                    n = (n << 3) + (*i++ - '0');
+                    count++;
+                }
+                *o = n;
+                break;
+              hex:
+            case 'x':
+                n = 0;
+                count = 0;
+                while (i++, count++ < 2) {
+                    if (*i >= '0' && *i <= '9')
+                        n = (n << 4) + (*i - '0');
+                    else if (*i >= 'a' && *i <= 'f')
+                        n = (n << 4) + (*i - 'a') + 10;
+                    else if (*i >= 'A' && *i <= 'F')
+                        n = (n << 4) + (*i - 'A') + 10;
+                    else
+                        break;
+                }
+                *o = n;
+                break;
+            case '\n':
+                i++;            /* punt */
+                o--;            /* to account for o++ at end of loop */
+                break;
+            case '\"':
+            case '\'':
+            case '\\':
+            default:
+                *o = *i++;
+                break;
+            }
+        } else
+            *o = *i++;
     }
     *o = '\0';
 }
 
-static int parsebool(char *str)
+static int
+parsebool(char *str)
 {
-  char *s;
+    char *s;
 
-  s = str;
+    s = str;
 
-  if (s == NULL)
-    return(-1);
+    if (s == NULL)
+        return (-1);
 
-  while(*s)
-    {
-      *s = (char)tolower(*s);
-      s++;
+    while (*s) {
+        *s = (char) tolower(*s);
+        s++;
     }
 
-  if (((char *)strstr("false", str) != NULL) ||
-      ((char *)strstr("no", str) != NULL)    ||
-      ((char *)strstr("0", str) != NULL)     ||
-      ((char *)strstr("off", str) != NULL))
-    {
-      return(FALSE);
+    if (((char *) strstr("false", str) != NULL) ||
+        ((char *) strstr("no", str) != NULL) ||
+        ((char *) strstr("0", str) != NULL) ||
+        ((char *) strstr("off", str) != NULL)) {
+        return (FALSE);
+    } else if (((char *) strstr("true", str) != NULL) ||
+               ((char *) strstr("yes", str) != NULL) ||
+               ((char *) strstr("1", str) != NULL) ||
+               ((char *) strstr("on", str) != NULL)) {
+        return (TRUE);
+    } else {
+        fprintf(stderr, "parsebool(): error parsing '%s', \n\t%s\n",
+                str,
+                "Value must be yes or no, true or false, or on or off.");
+        return (-1);
     }
-  else if (((char *)strstr("true", str) != NULL) ||
-           ((char *)strstr("yes", str) != NULL)  ||
-           ((char *)strstr("1", str) != NULL)    ||
-           ((char *)strstr("on", str) != NULL))
-    {
-      return(TRUE);
-    }
-  else
-    {
-      fprintf(stderr, "parsebool(): error parsing '%s', \n\t%s\n",
-              str,
-              "Value must be yes or no, true or false, or on or off.");
-      return(-1);
-    }
 }

=---------------------
 paul fox, pgf at foxharp.boston.ma.us (arlington, ma, where it's 81.0 degrees)



More information about the Nas mailing list