fdo#61256 - the Get.*Export methods also create and register styles
[LibreOffice.git] / dmake / parse.c
blob6f5aa7c63c32a74d6ab015d8b0eeb628f73281bb
1 /*
2 --
3 -- SYNOPSIS
4 -- Parse the input, and perform semantic analysis
5 --
6 -- DESCRIPTION
7 -- This file contains the routines that parse the input makefile and
8 -- call the appropriate routines to perform the semantic analysis and
9 -- build the internal dag.
11 -- AUTHOR
12 -- Dennis Vadura, dvadura@dmake.wticorp.com
14 -- WWW
15 -- http://dmake.wticorp.com/
17 -- COPYRIGHT
18 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
20 -- This program is NOT free software; you can redistribute it and/or
21 -- modify it under the terms of the Software License Agreement Provided
22 -- in the file <distribution-root>/readme/license.txt.
24 -- LOG
25 -- Use cvs log to obtain detailed change logs.
28 #include "extern.h"
31 PUBLIC void
32 Parse( fil )/*
33 ============== Parse the makefile input */
34 FILE *fil;
36 int rule = FALSE; /* have seen a recipe line */
37 char *p; /* termporary pointer into Buffer */
38 char *pTmpBuf;
40 DB_ENTER( "Parse" );
42 State = NORMAL_SCAN;
43 Group = FALSE; /* true if scanning a group rcpe */
44 while( TRUE ) {
45 if( Get_line( Buffer, fil ) ) {
46 if( Group ) Fatal( "Incomplete rule recipe group detected" );
48 /* If we are still in RULE_SCAN mode there might be unbound recipes. */
49 if( State == RULE_SCAN )
50 Bind_rules_to_targets( F_DEFAULT );
52 if( fil != NIL( FILE ) ) /* end of parsable input */
53 Closefile();
55 DB_VOID_RETURN;
57 else {
59 #ifdef _MPW
60 if ( Buffer[0] == 10 )
61 pTmpBuf = Buffer+1;
62 else
63 #endif
64 pTmpBuf = Buffer;
66 #ifdef _MPW
67 p = pTmpBuf;
68 while ( *p )
70 if ( *p == 10 )
71 *p = '\t';
72 p++;
74 #endif
76 switch( State ) {
77 case RULE_SCAN:
79 /* Check for the `[' that starts off a group recipe definition.
80 * It must appear as the first non-white space
81 * character in the line. */
83 p = DmStrSpn( Buffer, " \t\r\n" );
84 if( Set_group_attributes( p ) ) {
85 if( Group )
86 Fatal( "New group recipe begin found within group recipe." );
87 else if( rule )
88 Fatal( "Cannot mix single and group recipe lines." );
89 else
90 Group = TRUE;
92 rule = TRUE;
94 break; /* ignore the group start */
97 if( Group ) {
98 if( *p != ']' ) {
99 Add_recipe_to_list( pTmpBuf, TRUE, TRUE );
100 rule = TRUE;
102 else
103 State = NORMAL_SCAN;
105 else {
106 if( *pTmpBuf == '\t'
107 || (Notabs && *pTmpBuf == ' ') ) {
108 Add_recipe_to_list( pTmpBuf, FALSE, FALSE );
109 rule = TRUE;
111 else if( *p == ']' )
112 Fatal( "Found unmatched ']'" );
113 else if( *pTmpBuf ) /* Something that was no recipe. */
114 State = NORMAL_SCAN;
115 /* The only thing that was not handled was an empty line. */
118 if( State == RULE_SCAN ) break; /* ie. keep going */
120 Bind_rules_to_targets( (Group) ? F_GROUP: F_DEFAULT );
122 rule = FALSE;
123 if( Group ) {
124 Group = FALSE;
125 break;
127 /*FALLTRHOUGH*/
129 /* In this case we broke out of the rule scan because we do not
130 * have a recipe line that begins with a <TAB>, so lets
131 * try to scan the thing as a macro or rule definition. */
134 case NORMAL_SCAN:
135 if( !*pTmpBuf ) continue; /* we have null input line */
137 /* STUPID AUGMAKE uses "include" at the start of a line as
138 * a signal to include a new file, so let's look for it.
139 * if we see it replace it by .INCLUDE: and stick this back
140 * into the buffer. */
141 if( !strncmp( "include", pTmpBuf, 7 ) &&
142 (pTmpBuf[7] == ' ' || pTmpBuf[7] == '\t') )
144 char *tmp;
146 tmp = DmStrJoin( ".INCLUDE:", pTmpBuf+7, -1, FALSE );
147 strcpy( pTmpBuf, tmp );
148 FREE( tmp );
151 /* look for a macro definition, they all contain an = sign
152 * if we fail to recognize it as a legal macro op then try to
153 * parse the same line as a rule definition, it's one or the
154 * other */
156 if( Parse_macro(pTmpBuf, M_DEFAULT) ) break;/* it's a macro def*/
157 if( Parse_rule_def( &State ) ) break;/* it's a rule def */
159 /* if it is an empty or blank line then ignore it */
160 if( !*Buffer || *DmStrSpn( Buffer, " \t\r\n" ) == '\0' ) break;
162 /* otherwise assume it was a line of unrecognized input, or a
163 * recipe line out of place so print a message */
165 Fatal( "Expecting macro or rule defn, found neither" );
166 break;
168 default:
169 Fatal( "Internal -- UNKNOWN Parser state %d", State );