1
0
Fork 0

Adjusting the directory structure.

This commit is contained in:
curt 1997-06-21 17:30:06 +00:00
parent 450a307fc2
commit 0583a1ecd4
5 changed files with 0 additions and 954 deletions

View file

@ -1,109 +0,0 @@
#---------------------------------------------------------------------------
# Makefile
#
# Written by Curtis Olson, started May 1997.
#
# Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id$
# (Log is kept at end of this file)
#---------------------------------------------------------------------------
TARGET = libScenery.a
CFILES = scanner.c parser.c common.c mesh.c
HFILES =
LFILES = scanner.l
YFILES = parser.y
OFILES = $(CFILES:.c=.o)
CC = gcc
CFLAGS = -g -Wall
# CFLAGS = -O2 -Wall
FLEX = flex -f -L
BISON = bison -v --no-lines
AR = ar
INCLUDES =
LIBS = -lfl
#---------------------------------------------------------------------------
# Primary Targets
#---------------------------------------------------------------------------
all: $(TARGET)
$(TARGET): $(OFILES) $(HFILES)
$(AR) rv $(TARGET) $(OFILES)
clean:
rm -f *.o $(TARGET) parser.output *~ core
realclean: clean
rm -f scanner.c parser.c
#---------------------------------------------------------------------------
# Secondary Targets
#---------------------------------------------------------------------------
scanner.c: scanner.l parser.h
$(FLEX) -oscanner.c scanner.l
scanner.o: scanner.c
$(CC) $(CFLAGS) -c scanner.c
parser.h: parser.y
$(BISON) -o parser.c -d parser.y
parser.c: parser.y common.h mesh.h scenery.h
$(BISON) -o parser.c parser.y
parser.o: parser.c
$(CC) $(CFLAGS) -c parser.c
common.o: common.c common.h
$(CC) $(CFLAGS) -c common.c
mesh.o: mesh.c mesh.h common.h
$(CC) $(CFLAGS) -c mesh.c
#---------------------------------------------------------------------------
# $Log$
# Revision 1.6 1997/06/21 17:12:55 curt
# Capitalized subdirectory names.
#
# Revision 1.5 1997/05/31 19:16:29 curt
# Elevator trim added.
#
# Revision 1.4 1997/05/27 17:48:50 curt
# Added -f flag to flex to generate a "fast" scanner.
#
# Revision 1.3 1997/05/23 15:40:40 curt
# Added GNU copyright headers.
#
# Revision 1.2 1997/05/17 00:17:01 curt
# Cosmetic changes.
#
# Revision 1.1 1997/05/16 16:07:02 curt
# Initial revision.
#

View file

@ -1,301 +0,0 @@
#!/usr/local/bin/perl
#
# dem2scene.pl -- Read in a dem data file, and output a more usable format.
#
# Written by Curtis Olson, started May 1997.
#
# Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id$
# (Log is kept at end of this file)
#---------------------------------------------------------------------------
use strict;
# declare variables
my($token);
my($i, $j);
my($arg);
my($res) = 1;
# "A" Record Information
my($dem_description, $dem_quadrangle);
my($dem_x1, $dem_y1, $dem_x2, $dem_y2, $dem_x3, $dem_y3, $dem_x4, $dem_y4);
my($dem_z1, $dem_z2);
my($dem_resolution, $dem_num_profiles);
# "B" Record Information
my($prof_row, $prof_col);
my($prof_num_rows, $prof_num_cols);
my($prof_x1, $prof_y1);
my($prof_data);
# set input record separator to be a space
$/ = " ";
# parse command line arguments
while ( $arg = shift(@ARGV) ) {
if ( $arg eq "-r" ) {
$res = shift(@ARGV);
if ( $res < 1 ) {
&usage();
}
} else {
&usage();
}
}
# print usage and die
sub usage {
die "Usage: $0 [ -r resval ]\n";
}
&read_a_record();
&output_scene_hdr();
$i = 0;
while ( $i < $dem_num_profiles ) {
&read_b_record();
&output_row();
$i++;
if ( $i < $dem_num_profiles ) {
# not on last record
for ( $j = 1; $j < $res; $j++ ) {
# print "skipping row\n";
&read_b_record();
}
}
}
&output_scene_close();
# read and parse DEM "A" record
sub read_a_record {
my($i);
# read initial descriptive header
while ( ($token = &next_token()) ne "_END_OF_FILE_" ) {
if ( $token !~ m/^NJ/ && $token !~ m/^NI/ ) {
$dem_description .= "$token ";
} else {
chop($dem_description);
$dem_quadrangle = $token;
last;
}
}
# print "'$dem_description' '$dem_quadrangle'\n";
# DEM level code, 3 reflects processing by DMA
&next_token();
# Pattern code, 1 indicates a regular elevation pattern
&next_token();
# Planimetric reference system code, 0 indicates geographic
# coordinate system.
&next_token();
# Zone code
&next_token();
# Map projection parameters (ignored)
for ($i = 0; $i < 15; $i++) {
&next_token();
}
# Units code, 3 represents arc-seconds as the unit of measure for
# ground planimetric coordinates throughout the file.
die "Unknown units code!\n" if ( &next_token() ne "3" );
# Units code; 2 represents meters as the unit of measure for
# elevation coordinates throughout the file.
die "Unknown units code!\n" if ( &next_token() ne "2" );
# Number (n) of sides in the polygon which defines the coverage of
# the DEM file (usually equal to 4).
die "Unknown polygon dimension!\n" if ( &next_token() ne "4" );
# Ground coordinates of bounding box in arc-seconds
$dem_x1 = &next_token();
$dem_y1 = &next_token();
$dem_x2 = &next_token();
$dem_y2 = &next_token();
$dem_x3 = &next_token();
$dem_y3 = &next_token();
$dem_x4 = &next_token();
$dem_y4 = &next_token();
# Minimum/maximum elevations in meters
$dem_z1 = &next_token();
$dem_z2 = &next_token();
# Counterclockwise angle from the primary axis of ground
# planimetric referenced to the primary axis of the DEM local
# reference system.
&next_token();
# Accuracy code; 0 indicates that a record of accuracy does not
# exist and that no record type C will follow.
# &next_token();
# DEM spacial resolution. Usually (3,3,1) (3,6,1) or (3,9,1)
# depending on latitude
$dem_resolution = &next_token();
# one dimensional arrays
&next_token();
# number of profiles
$dem_num_profiles = &next_token();
$dem_num_profiles = (($dem_num_profiles - 1) / $res) + 1;
}
# output the scene headers
sub output_scene_hdr {
my($dx, $dy, $dz);
printf("mesh %s_terrain {\n", $dem_quadrangle);
$dem_x1 =~ s/D/E/; $dem_x1 += 0.0;
$dem_y1 =~ s/D/E/; $dem_y1 += 0.0;
print " // This mesh is rooted at the following coordinates (in arc seconds)\n";
print " origin_lon = $dem_x1\n";
print " origin_lat = $dem_y1\n";
print "\n";
print " // Number of rows and columns (needed by the parser so it can create\n";
print " //the proper size structure\n";
print " rows = $dem_num_profiles\n";
print " cols = $dem_num_profiles\n"; # This isn't necessarily guaranteed
print "\n";
($dx, $dy, $dz) = $dem_resolution =~
m/(.............)(............)(............)/;
$dx *= $res;
$dy *= $res;
print " // Distance between x and y data points (in arc seconds)\n";
print " row_step = $dx\n";
print " col_step = $dy\n";
print "\n";
}
# output the scene close
sub output_scene_close {
print "\n";
print "}\n";
}
# read and parse DEM "B" record
sub read_b_record {
my($i, $j);
# row / column id of this profile
$prof_row = &next_token();
$prof_col = &next_token();
# Number of rows (elevations) and columns in this profile;
$prof_num_rows = &next_token();
$prof_num_cols = &next_token();
$prof_num_rows = (($prof_num_rows - 1) / $res) + 1;
# print "profile num rows = $prof_num_rows\n";
# Ground planimetric coordinates (arc-seconds) of the first
# elevation in the profile
$prof_x1 = &next_token();
$prof_y1 = &next_token();
# Elevation of local datum for the profile. Always zero for
# 1-degree DEM, the reference is mean sea level.
&next_token();
# Minimum and maximum elevations for the profile.
&next_token();
&next_token();
# One (usually) dimensional array ($prof_num_rows,1) of elevations
$prof_data = "";
$i = 0;
while ( $i < $prof_num_rows ) {
$prof_data .= &next_token();
$prof_data .= " ";
$i++;
if ( $i < $prof_num_rows ) {
# not on last data point
# skip the tokens to get requested resolution
for ($j = 1; $j < $res; $j++) {
# print "skipping ...\n";
&next_token();
}
}
}
chop($prof_data);
# print "$prof_data\n\n";
}
# output a row of data
sub output_row {
print " row = ($prof_data)\n";
}
# return next token from input stream
sub next_token {
my($token);
# print "in next token\n";
do {
$token = <>; chop($token);
if ( eof() ) {
$token = "_END_OF_FILE_";
}
} while ( $token eq "" );
# print "returning $token\n";
return $token;
}
while ( ($token = &next_token()) ne "_END_OF_FILE_" ) {
# print "'$token'\n";
}
#---------------------------------------------------------------------------
# $Log$
# Revision 1.2 1997/05/30 19:30:16 curt
# The LaRCsim flight model is starting to look like it is working.
#
# Revision 1.1 1997/05/27 21:56:02 curt
# Initial revision (with data skipping support)
#

View file

@ -1,258 +0,0 @@
/**************************************************************************
* parser.y -- scenery file parser
*
* Written by Curtis Olson, started May 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
**************************************************************************/
/* C pass through */
%{
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "mesh.h"
#include "scenery.h"
/*#DEFINE YYDEBUG 1 */
/* interfacing with scanner.l (lex) */
extern int line_num;
extern char *yytext;
int push_input_stream ( char *input );
/* we must define this ourselves */
int yyerror(char *s);
/* handle for a mesh structure */
struct mesh *mesh_ptr;
%}
/* top level reserved words */
%token IncludeSym MeshSym RowSym ChunkSym BoundsSym PlaceSym
/* basic tokens */
%token Identifier Number StringLiteral
/* symbol tokens */
%token HashSym EqualSym LBraceSym RBraceSym LParenSym RParenSym CommaSym
/* error tokens */
%token BadStringLiteral ErrorMisc
/* Start Symbol */
%start start
/* Rules Section */
%%
start :
object_list
;
object_list :
object
| object_list object
;
object :
include
| mesh
| chunk
;
/* includes */
include :
HashSym IncludeSym StringLiteral
{
yytext = strip_quotes(yytext);
printf("Need to include %s\n", yytext);
push_input_stream(yytext);
}
;
/* terrain mesh rules */
mesh :
MeshSym
{
/* allocate a structure for this terrain mesh */
mesh_ptr = new_mesh();
}
Identifier LBraceSym mesh_body RBraceSym
{
/* The following two lines *SHOULD* be here, they are just temporarily
commented out until the scenery mngmt stuff gets hashed out. */
/* free up the mem used by this structure */
/* free(mesh_ptr->mesh_data); */
/* free(mesh_ptr); */
}
;
mesh_body :
mesh_header_list
{
/* We've read the headers, so allocate a pseudo 2d array */
mesh_ptr->mesh_data = new_mesh_data(mesh_ptr->rows, mesh_ptr->cols);
printf("Beginning to read mesh data\n");
}
mesh_row_list
;
mesh_header_list :
mesh_header
| mesh_header_list mesh_header
;
mesh_header :
Identifier
{
mesh_set_option_name(mesh_ptr, yytext);
}
EqualSym Number
{
mesh_set_option_value(mesh_ptr, yytext);
}
;
mesh_row_list :
mesh_row
| mesh_row_list mesh_row
;
mesh_row :
RowSym
{
/* printf("Ready to read a row\n"); */
mesh_ptr->cur_col = 0;
}
EqualSym LParenSym mesh_row_items RParenSym
{
mesh_ptr->cur_row++;
}
;
mesh_row_items :
mesh_item
| mesh_row_items mesh_item
;
mesh_item :
Number
{
/* mesh data is a pseudo 2d array */
mesh_ptr->mesh_data[mesh_ptr->cur_row * mesh_ptr->rows +
mesh_ptr->cur_col] = atof(yytext);
mesh_ptr->cur_col++;
}
;
/* chunk rules */
chunk : ChunkSym Identifier LBraceSym chunk_body RBraceSym
;
chunk_body : chunk_header_list chunk_bounds place_list
;
chunk_header_list : chunk_header
| chunk_header_list chunk_header
;
chunk_header : Identifier EqualSym StringLiteral
;
chunk_bounds : BoundsSym EqualSym LBraceSym
Number CommaSym
Number CommaSym
Number CommaSym
Number CommaSym
Number CommaSym
Number CommaSym
Number CommaSym
Number
RBraceSym
;
/* place rules */
place_list : place | place_list place
;
place : PlaceSym Identifier LBraceSym place_options_list RBraceSym
;
place_options_list : place_option | place_options_list place_option
;
place_option : Identifier EqualSym place_value
;
place_value : geodetic_coord | Number
;
geodetic_coord : LParenSym Number CommaSym Number CommaSym
Number RParenSym
;
/* C Function Section */
%%
int yyerror(char *s) {
printf("Error: %s at line %d.\n", s, line_num);
return 0;
}
/* this is a simple main for testing the parser */
/*
int main(int argc, char **argv) {
#ifdef YYDEBUG
yydebug = 1;
#endif
printf("input file = %s\n", argv[1]);
push_input_stream(argv[1]);
yyparse();
return 0;
}
*/
/* parse a scenery file */
int parse_scenery(char *file) {
int result;
printf("input file = %s\n", file);
push_input_stream(file);
result = yyparse();
/* return(result) */
return(mesh_ptr);
}

View file

@ -1,241 +0,0 @@
/**************************************************************************
* scenery.l -- Lexical Analyzer for scenery files
*
* Written by Curtis Olson, started May 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* NOTE: Compiles with flex and gcc.
*
* $Id$
**************************************************************************/
/* C Pass Through */
%{
#include <stdio.h>
#include "parser.h"
int line_num = 1;
char c;
/* custom print routine */
static int scanner_debug = 0;
/* Routines to manage a stack of nested input buffers (for
processing the #include directive */
#define MAX_INCLUDE_DEPTH 10
static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
static int include_stack_ptr = 0;
int push_input_stream ( char *input ) {
FILE *yyin_save;
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
fprintf( stderr, "Scanner says: Includes nested too deeply\n" );
return(0);
}
/* save yyin in case the following fails */
yyin_save = yyin;
yyin = fopen( input, "r" );
if ( ! yyin ) {
fprintf( stderr, "Scanner says: cannot open '%s'\n", input );
/* The failed attempt destroyed yyin, so restore it */
yyin = yyin_save;
return(0);
}
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE) );
return(1);
}
int pop_input_stream () {
if ( --include_stack_ptr < 1 ) {
/* end of last input stream */
return(0);
} else {
/* end of current input stream, restore previous and continue */
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer( include_stack[include_stack_ptr] );
return(1);
}
}
%}
/* Definitions */
letter [A-Za-z]
digit [0-9]
connecter [_-]
ident {letter}({letter}|{digit}|{connecter})*
integer [+-]?{digit}+
plain_real {integer}"."{integer}
short_exp_real {integer}[Ee][+-]?{integer}
exp_real {plain_real}[Ee][+-]?{integer}
real [+-]?{plain_real}|{short_exp_real}|{exp_real}
number {real}|{integer}
string \"[^"\n]+\"
bad_string \"([^"\n]|\n)+\"
ws [ \t]+
other .
/* Rules */
%%
include { if ( scanner_debug ) {
printf("return IncludeSym\n");
}
return IncludeSym;
}
mesh { if ( scanner_debug ) {
printf("return MeshSym\n");
}
return MeshSym;
}
row { if ( scanner_debug ) {
printf("return RowSym\n");
}
return RowSym;
}
chunk { if ( scanner_debug ) {
printf("return ChunkSym\n");
}
return ChunkSym;
}
bounds { if ( scanner_debug ) {
printf("return BoundsSym\n");
}
return BoundsSym;
}
place { if ( scanner_debug ) {
printf("return PlaceSym\n");
}
return PlaceSym;
}
{ident} { if ( scanner_debug ) {
printf("return Identifier = %s\n", yytext);
}
return Identifier;
}
{number} { if ( scanner_debug ) {
printf("return Number\n");
}
return Number;
}
{string} { if ( scanner_debug ) {
printf("return StringLiteral = %s\n", yytext);
}
return StringLiteral;
}
{bad_string} { if ( scanner_debug ) {
printf("return BadStringLiteral = %s\n", yytext);
}
return BadStringLiteral;
}
"\n" { line_num++;
if ( scanner_debug ) {
printf("Line number = %d\n", line_num);
}
}
"#" { if ( scanner_debug ) {
printf("return HashSym\n");
}
return HashSym;
}
"=" { if ( scanner_debug ) {
printf("return EqualSym\n");
}
return EqualSym;
}
"," { if ( scanner_debug ) {
printf("return CommaSym\n");
}
return CommaSym;
}
"{" { if ( scanner_debug ) {
printf("return LBraceSym\n");
}
return LBraceSym;
}
"}" { if ( scanner_debug ) {
printf("return RBraceSym\n");
}
return RBraceSym;
}
"(" { if ( scanner_debug ) {
printf("return LParenSym\n");
}
return LParenSym;
}
")" { if ( scanner_debug ) {
printf("return RParenSym\n");
}
return RParenSym;
}
"//" { /* burn through "#" comment */
c = input();
while ( (c != '\n') ) {
c = input();
/* scanner_print("%c", c); */
}
unput(c);
/* line_num++; */
}
{ws} { ; }
{other} { if ( scanner_debug ) {
printf("Scanned some unexpected text = `%s'\n", yytext);
}
return ErrorMisc;
}
<<EOF>> { if ( pop_input_stream() == 0 ) {
/* End of last input stream */
yyterminate();
}
}

View file

@ -1,45 +0,0 @@
/**************************************************************************
* scenery.h -- data structures and routines for processing terrain meshes
*
* Written by Curtis Olson, started May 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef SCENERY_H
#define SCENERY_H
/* parse a scenery file */
int parse_scenery(char *file);
#endif SCENERY_H
/* $Log$
/* Revision 1.2 1997/05/23 15:40:43 curt
/* Added GNU copyright headers.
/*
* Revision 1.1 1997/05/16 16:07:07 curt
* Initial revision.
*
*/