/* * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. * * This file is part of Jam - see jam.c for Copyright information. */ /* * scan.c - the jam yacc scanner * * 12/26/93 (seiwald) - bump buf in yylex to 10240 - yuk. * 09/16/94 (seiwald) - check for overflows, unmatched {}'s, etc. * Also handle tokens abutting EOF by remembering * to return EOF now matter how many times yylex() * reinvokes yyline(). * 02/11/95 (seiwald) - honor only punctuation keywords if SCAN_PUNCT. * 07/27/95 (seiwald) - Include jamgram.h after scan.h, so that YYSTYPE is * defined before Linux's yacc tries to redefine it. * 01/10/01 (seiwald) - \ can now escape any whitespace char * 11/04/02 (seiwald) - const-ing for string literals */ # include "jam.h" # include "lists.h" # include "parse.h" # include "scan.h" # include "jamgram.h" # include "jambase.h" # include "newstr.h" struct keyword { const char *word; int type; } keywords[] = { # include "jamgramtab.h" { 0, 0 } } ; struct include { struct include *next; /* next serial include file */ const char *string; /* pointer into current line */ char **strings; /* for yyfparse() -- text to parse */ FILE *file; /* for yyfparse() -- file being read */ const char *fname; /* for yyfparse() -- file name */ int line; /* line counter for error messages */ char buf[ 512 ]; /* for yyfparse() -- line buffer */ } ; static struct include *incp = 0; /* current file; head of chain */ static int scanmode = SCAN_NORMAL; static int anyerrors = 0; static char *symdump( YYSTYPE *s ); # define BIGGEST_TOKEN 10240 /* no single token can be larger */ /* * Set parser mode: normal, string, or keyword */ void yymode( int n ) { scanmode = n; } void yyerror( const char *s ) { if( incp ) printf( "%s: line %d: ", incp->fname, incp->line ); printf( "%s at %s\n", s, symdump( &yylval ) ); ++anyerrors; } int yyanyerrors() { return anyerrors != 0; } void yyfparse( const char *s ) { struct include *i = (struct include *)malloc( sizeof( *i ) ); /* Push this onto the incp chain. */ i->string = ""; i->strings = 0; i->file = 0; i->fname = copystr( s ); i->line = 0; i->next = incp; incp = i; /* If the filename is "+", it means use the internal jambase. */ if( !strcmp( s, "+" ) ) i->strings = jambase; } /* * yyline() - read new line and return first character * * Fabricates a continuous stream of characters across include files, * returning EOF at the bitter end. */ int yyline() { struct include *i = incp; if( !incp ) return EOF; /* Once we start reading from the input stream, we reset the */ /* include insertion point so that the next include file becomes */ /* the head of the list. */ /* If there is more data in this line, return it. */ if( *i->string ) return *i->string++; /* If we're reading from an internal string list, go to the */ /* next string. */ if( i->strings ) { if( !*i->strings ) goto next; i->line++; i->string = *(i->strings++); return *i->string++; } /* If necessary, open the file */ if( !i->file ) { FILE *f = stdin; if( strcmp( i->fname, "-" ) && !( f = fopen( i->fname, "r" ) ) ) perror( i->fname ); i->file = f; } /* If there's another line in this file, start it. */ if( i->file && fgets( i->buf, sizeof( i->buf ), i->file ) ) { i->line++; i->string = i->buf; return *i->string++; } next: /* This include is done. */ /* Free it up and return EOF so yyparse() returns to parse_file(). */ incp = i->next; /* Close file, free name */ if( i->file && i->file != stdin ) fclose( i->file ); freestr( i->fname ); free( (char *)i ); return EOF; } /* * yylex() - set yylval to current token; return its type * * Macros to move things along: * * yychar() - return and advance character; invalid after EOF * yyprev() - back up one character; invalid before yychar() * * yychar() returns a continuous stream of characters, until it hits * the EOF of the current include file. */ # define yychar() ( *incp->string ? *incp->string++ : yyline() ) # define yyprev() ( incp->string-- ) int yylex() { int c; char buf[BIGGEST_TOKEN]; char *b = buf; if( !incp ) goto eof; /* Get first character (whitespace or of token) */ c = yychar(); if( scanmode == SCAN_STRING ) { /* If scanning for a string (action's {}'s), look for the */ /* closing brace. We handle matching braces, if they match! */ int nest = 1; while( c != EOF && b < buf + sizeof( buf ) ) { if( c == '{' ) nest++; if( c == '}' && !--nest ) break; *b++ = c; c = yychar(); } /* We ate the ending brace -- regurgitate it. */ if( c != EOF ) yyprev(); /* Check obvious errors. */ if( b == buf + sizeof( buf ) ) { yyerror( "action block too big" ); goto eof; } if( nest ) { yyerror( "unmatched {} in action block" ); goto eof; } *b = 0; yylval.type = STRING; yylval.string = newstr( buf ); } else { char *b = buf; struct keyword *k; int inquote = 0; int notkeyword; /* Eat white space */ for( ;; ) { /* Skip past white space */ while( c != EOF && isspace( c ) ) c = yychar(); /* Not a comment? Swallow up comment line. */ if( c != '#' ) break; while( ( c = yychar() ) != EOF && c != '\n' ) ; } /* c now points to the first character of a token. */ if( c == EOF ) goto eof; /* While scanning the word, disqualify it for (expensive) */ /* keyword lookup when we can: $anything, "anything", \anything */ notkeyword = c == '$'; /* look for white space to delimit word */ /* "'s get stripped but preserve white space */ /* \ protects next character */ while( c != EOF && b < buf + sizeof( buf ) && ( inquote || !isspace( c ) ) ) { if( c == '"' ) { /* begin or end " */ inquote = !inquote; notkeyword = 1; } else if( c != '\\' ) { /* normal char */ *b++ = c; } else if( ( c = yychar()) != EOF ) { /* \c */ *b++ = c; notkeyword = 1; } else { /* \EOF */ break; } c = yychar(); } /* Check obvious errors. */ if( b == buf + sizeof( buf ) ) { yyerror( "string too big" ); goto eof; } if( inquote ) { yyerror( "unmatched \" in string" ); goto eof; } /* We looked ahead a character - back up. */ if( c != EOF ) yyprev(); /* scan token table */ /* don't scan if it's obviously not a keyword or if its */ /* an alphabetic when were looking for punctuation */ *b = 0; yylval.type = ARG; if( !notkeyword && !( isalpha( *buf ) && scanmode == SCAN_PUNCT ) ) { for( k = keywords; k->word; k++ ) if( *buf == *k->word && !strcmp( k->word, buf ) ) { yylval.type = k->type; yylval.string = k->word; /* used by symdump */ break; } } if( yylval.type == ARG ) yylval.string = newstr( buf ); } if( DEBUG_SCAN ) printf( "scan %s\n", symdump( &yylval ) ); return yylval.type; eof: yylval.type = EOF; return yylval.type; } static char * symdump( YYSTYPE *s ) { static char buf[ BIGGEST_TOKEN + 20 ]; switch( s->type ) { case EOF: sprintf( buf, "EOF" ); break; case 0: sprintf( buf, "unknown symbol %s", s->string ); break; case ARG: sprintf( buf, "argument %s", s->string ); break; case STRING: sprintf( buf, "string \"%s\"", s->string ); break; default: sprintf( buf, "keyword %s", s->string ); break; } return buf; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 9904 | tony |
Port 2008.1 P4 to MVS Unix System Services. This is an onsite port carried out at Bank of America in Croydon. It's not pretty. There are some uglies in here which could probably be taken care of in better ways, but I was pressed for time. Here's the background to each of the issues I found: 1. The compiler really didn't like our Zeroconf code, and since building Avahi on the mainframe wasn't top of my agenda, I disabled it with some heinous ifdef's in client.cc. Sorry. The compiler was bitching about types of arguments being passed to zeroconf methods, and it wasn't obvious to me what the problem was either. I think we could use a -DUSE_ZEROCONF in our Jamrules for occasions like this; that would be cleaner than a platform ifdef in client.cc. With more time, it might be possible to make the zeroconf code compile on MVS, but getting dynamic loading working on that platform is ambitious I think. 2. The mapping code needed ifdefs too (again, sorry!). On MVS, C and C++ don't share the same linkage and qsort() is a C function so it (apparently) can't take a pointer to a C++ function. So, all the qsort() compare functions have to be declared as 'extern "C"'. See: http://publib.boulder.ibm.com/infocenter/zos/v1r9/index.jsp?topic=/com.ibm.zos.r9.bpxbd00/qsort.htm I didn't ifdef these as I don't think they'll do any harm on other platforms. 3. support/random.cc needed an ifdef (no big deal) 4. sys/netaddr.cc had to have a (correct) const removed since the MVS implementation of inet_addr takes a 'char *' argument instead of 'const char *'. I ifdef'd that to keep it clean on other platforms. 5. zlib/zconf.h had some old pragmas that no longer apply. 6. Jamrules: I reinstated the old rules from MVS builds, and made EBCDIC optional rather than compulsory. I also documented in it the environment variables we set to persuade the compilers on BofA's machine to behave. These may, or may not be required on other MVS boxes. No idea. Building Jam also had a few idiosyncracies: 1. Best to assume the yacc on MVS is broken. It was there, but not in great shape. I disabled it in Jambase and I think that's a sensible thing to do going forward. 2. yylineno() can't return a 'const int' on MVS. Not sure why it's defined that way on other platforms so I changed it to just returning an int. Hopefully that won't break elsewhere... There are three binaries being submitted here: jam - built from main bin.mvs/p4 - EBCDIC client bin.mvs/ascii/p4 - Non-EBCDIC client The ascii client identifies itself as such: P4/MVS/2008.1.ascii/164042 While unconventional, I thought that was the best plan so that if we take support calls on it, we'll get a clue. p4transfer.py: Transferred from production |
||
#6 | 9903 | Perforce staff |
Jam -dr now reports file/line numbers, at no small effort. New functionality documented in RELNOTES. p4transfer.py: Transferred from production |
||
#5 | 2493 | rmg |
Rewrite the past: update all jam's source with comments to reflect changes since about 2.3, very early 2001. Whitespace only change. === computer:1666: Change 37660 by seiwald@play-seiwald on 2002/11/06 22:41:35 Note: I regenerated jamgram.c on my linux 7.3 system prior to the submit, since patch was so unhappy trying to lay down the changes from Christopher's change. Presumably this is just due to different yacc/bison/whatever particulars on the system where Christopher made the changes originally. - rmg |
||
#4 | 2491 | rmg |
Some consting in jam to make it more compilable by C++ compilers. No functional change. === computer:1666: Change 37433 by perforce@perforce on 2002/10/30 16:08:51 Recreational const-ing of jam, for compilers that don't allow "string" to be passed as a non-const char *. This included a few places where we were modifying what could possibly have been read-only storage, oddly enough. No functional change. === computer:1666: Change 37602 by seiwald@play-seiwald on 2002/11/04 17:25:40 |
||
#3 | 1319 | rmg |
Jam 2.3 + Perforce's internal changes. This change is a drop of the Perforce internal Jam changes since the 2.3 public release. The individual changes represented herein are preserved in the //guest/richard_geiger/intjam/ branch. The intent of this drop is to provide a base, from which other contributors' Jam branches may be integrated into. It is not intended to become a packaged release in this state. We will be integrating changes from other users prior to creating the next packaged release. Please refer to the src/RELNOTES file for an overview of the changes present in this integration. - Richard Geiger Open Source Engineer at Perforce |
||
#2 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |