@@ -402,36 +402,27 @@ void _JsExtractSigil(JsDoc* doc, Node* node) {
402402}
403403
404404/* tokenizes the given string and returns the list of nodes */
405- Node * JsTokenizeString (const char * string ) {
406- JsDoc doc ;
407-
408- /* initialize our JS document object */
409- doc .head = NULL ;
410- doc .tail = NULL ;
411- doc .buffer = string ;
412- doc .length = strlen (string );
413- doc .offset = 0 ;
414-
405+ Node * JsTokenizeString (JsDoc * doc , const char * string ) {
415406 /* parse the JS */
416- while ((doc . offset < doc . length ) && (doc . buffer [doc . offset ])) {
407+ while ((doc -> offset < doc -> length ) && (doc -> buffer [doc -> offset ])) {
417408 /* allocate a new node */
418409 Node * node = JsAllocNode ();
419- if (!doc . head )
420- doc . head = node ;
421- if (!doc . tail )
422- doc . tail = node ;
410+ if (!doc -> head )
411+ doc -> head = node ;
412+ if (!doc -> tail )
413+ doc -> tail = node ;
423414
424415 /* parse the next node out of the JS */
425- if (doc . buffer [doc . offset ] == '/' ) {
426- if (doc . buffer [doc . offset + 1 ] == '*' )
427- _JsExtractBlockComment (& doc , node );
428- else if (doc . buffer [doc . offset + 1 ] == '/' )
429- _JsExtractLineComment (& doc , node );
416+ if (doc -> buffer [doc -> offset ] == '/' ) {
417+ if (doc -> buffer [doc -> offset + 1 ] == '*' )
418+ _JsExtractBlockComment (doc , node );
419+ else if (doc -> buffer [doc -> offset + 1 ] == '/' )
420+ _JsExtractLineComment (doc , node );
430421 else {
431422 /* could be "division" or "regexp", but need to know more about
432423 * our context...
433424 */
434- Node * last = doc . tail ;
425+ Node * last = doc -> tail ;
435426 char ch = 0 ;
436427
437428 /* find last non-whitespace, non-comment node */
@@ -443,34 +434,34 @@ Node* JsTokenizeString(const char* string) {
443434 /* see if we're "division" or "regexp" */
444435 if (nodeIsIDENTIFIER (last ) && nodeEquals (last , "return" )) {
445436 /* returning a regexp from a function */
446- _JsExtractLiteral (& doc , node );
437+ _JsExtractLiteral (doc , node );
447438 }
448439 else if (ch && ((ch == ')' ) || (ch == '.' ) || (ch == ']' ) || (charIsIdentifier (ch )))) {
449440 /* looks like an identifier; guess its division */
450- _JsExtractSigil (& doc , node );
441+ _JsExtractSigil (doc , node );
451442 }
452443 else {
453444 /* presume its a regexp */
454- _JsExtractLiteral (& doc , node );
445+ _JsExtractLiteral (doc , node );
455446 }
456447 }
457448 }
458- else if ((doc . buffer [doc . offset ] == '"' ) || (doc . buffer [doc . offset ] == '\'' ) || (doc . buffer [doc . offset ] == '`' ))
459- _JsExtractLiteral (& doc , node );
460- else if (charIsWhitespace (doc . buffer [doc . offset ]))
461- _JsExtractWhitespace (& doc , node );
462- else if (charIsIdentifier (doc . buffer [doc . offset ]))
463- _JsExtractIdentifier (& doc , node );
449+ else if ((doc -> buffer [doc -> offset ] == '"' ) || (doc -> buffer [doc -> offset ] == '\'' ) || (doc -> buffer [doc -> offset ] == '`' ))
450+ _JsExtractLiteral (doc , node );
451+ else if (charIsWhitespace (doc -> buffer [doc -> offset ]))
452+ _JsExtractWhitespace (doc , node );
453+ else if (charIsIdentifier (doc -> buffer [doc -> offset ]))
454+ _JsExtractIdentifier (doc , node );
464455 else
465- _JsExtractSigil (& doc , node );
456+ _JsExtractSigil (doc , node );
466457
467458 /* move ahead to the end of the parsed node */
468- doc . offset += node -> length ;
459+ doc -> offset += node -> length ;
469460
470461 /* add the node to our list of nodes */
471- if (node != doc . tail )
472- JsAppendNode (doc . tail , node );
473- doc . tail = node ;
462+ if (node != doc -> tail )
463+ JsAppendNode (doc -> tail , node );
464+ doc -> tail = node ;
474465
475466 /* some debugging info */
476467#ifdef DEBUG
@@ -480,17 +471,17 @@ Node* JsTokenizeString(const char* string) {
480471 printf ("%s: %s\n" , strNodeTypes [node -> type ], node -> contents );
481472 printf ("next: '" );
482473 for (idx = 0 ; idx <=10 ; idx ++ ) {
483- if ((doc . offset + idx ) >= doc . length ) break ;
484- if (!doc . buffer [doc . offset + idx ]) break ;
485- printf ("%c" , doc . buffer [doc . offset + idx ]);
474+ if ((doc -> offset + idx ) >= doc -> length ) break ;
475+ if (!doc -> buffer [doc -> offset + idx ]) break ;
476+ printf ("%c" , doc -> buffer [doc -> offset + idx ]);
486477 }
487478 printf ("'\n" );
488479 }
489480#endif
490481 }
491482
492483 /* return the node list */
493- return doc . head ;
484+ return doc -> head ;
494485}
495486
496487/* ****************************************************************************
@@ -687,8 +678,17 @@ Node* JsPruneNodes(Node *head) {
687678 */
688679char * JsMinify (const char * string ) {
689680 char * results ;
681+ JsDoc doc ;
682+
683+ /* initialize our JS document object */
684+ doc .head = NULL ;
685+ doc .tail = NULL ;
686+ doc .buffer = string ;
687+ doc .length = strlen (string );
688+ doc .offset = 0 ;
689+
690690 /* PASS 1: tokenize JS into a list of nodes */
691- Node * head = JsTokenizeString (string );
691+ Node * head = JsTokenizeString (& doc , string );
692692 if (!head ) return NULL ;
693693 /* PASS 2: collapse nodes */
694694 JsCollapseNodes (head );
0 commit comments