home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.pdx.edu
/
2014.02.ftp.ee.pdx.edu.tar
/
ftp.ee.pdx.edu
/
oss
/
cvs-2004
/
OpenHamLog
/
Attic
/
AdifFileImport.java,v
next >
Wrap
Text File
|
2003-07-14
|
9KB
|
387 lines
head 1.4;
access;
symbols;
locks; strict;
comment @# @;
1.4
date 2003.07.14.19.37.56; author htodd; state dead;
branches;
next 1.3;
1.3
date 2003.07.09.06.21.09; author htodd; state Exp;
branches;
next 1.2;
1.2
date 2003.07.07.21.13.09; author htodd; state Exp;
branches;
next 1.1;
1.1
date 2003.07.07.00.52.04; author htodd; state Exp;
branches;
next ;
desc
@@
1.4
log
@Moving files and starting ant.
@
text
@/* file name : AdifFileImport.java
* authors : Hisashi T Fujinaka
* created : Sun Jul 6 17:08:33 2003
*
* Copyright (c) 2003 Hisashi T Fujinaka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
import java.io.*;
import java.util.*;
/**
*
*
* @@author Hisashi T Fujinaka
* @@version 0.1
*/
class Counter {
private int i = 1;
int read() {
return i;
}
void increment() {
i++;
}
}
/**
* AdifFileImport
*
* @@author Hisashi T Fujinaka
* @@version 0.1
*/
public class AdifFileImport {
private FileInputStream file;
private StreamTokenizer st;
private Hashtable fieldCount = new Hashtable();
/**
* AdifFileImport
*
* @@param filename
* @@throws FileNotFoundException
*/
AdifFileImport(String filename) throws FileNotFoundException {
try {
file = new FileInputStream(filename);
Reader r = new BufferedReader(new InputStreamReader(file));
st = new StreamTokenizer(r);
st.slashSlashComments(false);
st.slashStarComments(false);
st.lowerCaseMode(false);
st.ordinaryChar('.');
st.ordinaryChar('-');
st.ordinaryChar('\'');
st.wordChars('_','_');
} catch(FileNotFoundException e) {
System.out.println("Could not open " + filename);
throw e;
}
}
/**
* This method uses the StreamTokenizer and a hash table to count the number
* of occurences of the fields.
*/
void countFields() {
String s;
try {
// eat the header
if((st.nextToken() != StreamTokenizer.TT_EOF) &&
(st.ttype != '<')) {
while((st.nextToken() != StreamTokenizer.TT_EOF) &&
(st.ttype != '<')) {
}
} else {
System.out.println("No header");
switch(st.ttype) {
case StreamTokenizer.TT_EOL:
s = new String("EOL");
break;
case StreamTokenizer.TT_NUMBER:
s = Double.toString(st.nval);
break;
case StreamTokenizer.TT_WORD:
s = st.sval;
break;
default: // just a char
s = String.valueOf((char)st.ttype);
}
System.out.println(s);
}
if ((st.nextToken() != StreamTokenizer.TT_WORD) &&
(st.sval != "EOH")) {
System.out.println("Header error");
} else {
switch(st.ttype) {
case StreamTokenizer.TT_EOL:
s = new String("EOL");
break;
case StreamTokenizer.TT_NUMBER:
s = Double.toString(st.nval);
break;
case StreamTokenizer.TT_WORD:
s = st.sval;
break;
default: // just a char
s = String.valueOf((char)st.ttype);
}
System.out.println(s);
}
// start getting headers
do {
if(st.ttype != '<') {
// wait for <, which starts the data field
while((st.nextToken() != StreamTokenizer.TT_EOF) &&
(st.ttype != '<')) {
// we got an EOR without the <
if ((st.ttype == StreamTokenizer.TT_WORD) &&
(st.sval == "EOR")) {
}
//debug
switch(st.ttype) {
case StreamTokenizer.TT_EOL:
s = new String("EOL");
break;
case StreamTokenizer.TT_NUMBER:
s = Double.toString(st.nval);
break;
case StreamTokenizer.TT_WORD:
s = st.sval;
break;
default: // just a char
s = String.valueOf((char)st.ttype);
}
System.out.println(s);
//debug
}
if(st.nextToken() != StreamTokenizer.TT_EOF){
if(st.ttype == StreamTokenizer.TT_WORD) {
s = st.sval;
//debug
System.out.println(s);
if(fieldCount.containsKey(s)) {
((Counter)fieldCount.get(s)).increment();
} else {
fieldCount.put(s, new Counter());
}
} else {
// print out error cases
System.out.println("AARRGH");
switch(st.ttype) {
case StreamTokenizer.TT_EOL:
s = new String("EOL");
break;
case StreamTokenizer.TT_NUMBER:
s = Double.toString(st.nval);
break;
case StreamTokenizer.TT_WORD:
s = st.sval;
break;
default: // just a char
s = String.valueOf((char)st.ttype);
}
System.out.print("ADIF error, line: " + st.lineno() + " ");
System.out.println(s);
}
}
}
} while(st.nextToken() != StreamTokenizer.TT_EOF);
} catch(IOException e) {
System.out.println("st.nextToken() unsuccessful");
}
Enumeration keys = sortedKeys();
int numkeys = 0;
while(keys.hasMoreElements()) {
++numkeys;
String key = (String)keys.nextElement();
System.out.println(key + ": " + getCounter(key).read());
}
System.out.println("keys: " + numkeys);
}
/**
* This method merely closes the file.
*/
void cleanup() {
try {
file.close();
} catch(IOException e) {
System.out.println(
"file.close() unsuccessful");
}
}
Counter getCounter(String s) {
return (Counter)fieldCount.get(s);
}
Enumeration sortedKeys() {
Enumeration e = fieldCount.keys();
StrSortVector sv = new StrSortVector();
while(e.hasMoreElements())
sv.addElement((String)e.nextElement());
// This call forces a sort:
return sv.elements();
}
/**
* main
*
* @@param args
*/
public static void main(String[] args) {
try {
AdifFileImport afi = new AdifFileImport(args[0]);
afi.countFields();
afi.cleanup();
} catch(Exception e) {
e.printStackTrace();
}
}
}
@
1.3
log
@*** empty log message ***
@
text
@@
1.2
log
@Monday morning
@
text
@d40 2
a41 2
return i;
}
d44 2
a45 2
i++;
}
d71 3
d76 1
d85 2
a86 1
* count the fields in the adif file
d89 1
a89 1
int lineCount = 0;
d91 75
a165 6
while(st.nextToken() != StreamTokenizer.TT_EOF) {
if (StreamTokenizer.TT_EOL) {
++lineCount;
}
String s;
if((st.ttype != StreamTokenizer.TT_WORD) && (st.ttype == '<')) {
a166 3
if (st.ttype == StreamTokenizer.TT_EOL) {
++lineCount;
}
d169 4
d179 2
a180 2
// print out error cases
System.out.print("ADIF error, line: " + lineCount + " ");
d194 1
d199 1
a199 1
}
d203 8
d213 3
a246 6
Enumeration keys = afi.sortedKeys();
while(keys.hasMoreElements()) {
String key = (String)keys.nextElement();
System.out.println(key + ": " + afi.getCounter(key).read());
}
d253 1
a253 1
} ///:~
@
1.1
log
@new
@
text
@d38 8
a45 2
int read() { return i; }
void increment() { i++; }
d84 1
d87 3
d93 3
d104 2
a105 1
System.out.print("odd: ");
d114 1
a114 1
s = st.sval; // Already a String
d116 1
a116 1
default: // single character in ttype
a135 4
}
Enumeration keys() {
return fieldCount.keys();
@