Re^2: OEIS down?
Richard Mathar
mathar at strw.leidenuniv.nl
Sun Oct 29 22:50:25 CET 2006
mlb> From seqfan-owner at ext.jussieu.fr Sun Oct 29 17:13:40 2006
mlb> Date: Sun, 29 Oct 2006 08:12:00 -0800
mlb> To: seqfan at ext.jussieu.fr
mlb> From: Marc LeBrun <mlb at well.com>
mlb> Subject: Re: OEIS down?
mlb> ..
mlb> The only thing eMailing the internal format loses is the congeniality
mlb> of the web form. Hmm... come to think of it, it shouldn't be to hard
mlb> to make a little Java program that seqfans would run *locally* (ie on
mlb> their client machine, not the OEIS server), that would wrap the form
mlb> fields with the internal formatting and eMail it to the OEIS, CCing
mlb> whoever you want. Anyone out there interested in hacking something like this?
I've attached a Java wrapper for this task. Use documentation is in the
comments at the begin of the source code. Feedback is welcome.
(Would it be useful to convert comments in b-files into %C lines?)
Note that a shell script to test the line length could be s.th. like this
#!/bin/csh -f
# print lines of the standard input that are longer
# than 72 characters. Tabulator characters are expanded
# and counted according to the standard tabulator settings.
# mathar at qtp.ufl.edu, 20 Nov 95.
expand $* | awk 'length > 80 { print NR,$0}'
---
Richard J Mathar Tel (+31) (0) 71 527 8459
2300 RA Leiden E-mail mathar at strw.leidenuniv.nl
The Netherlands URL http://www.strw.leidenuniv.nl/~mathar
-------------- next part --------------
import java.lang.* ;
import java.util.* ;
import java.math.* ;
import java.io.* ;
/** Convert a OEIS b-text file into the tagged
* internal format.
*
* COMPILATION
*
* It is recommended to add your standard OEIS name and e-mail address
* between the two quotation marks below, where the variables myName
* and myEmail are assigned to empty strings, before compilation.
*
* javac btxt2oeis.java
*
* USAGE
*
* java btxt2oeis [-m] [Anumber] < b.txt > ...
*
* If the option '-m' is used, UNIX mail(1) commands are added to the
* standard output. The default is not to do this.
*
* If a number is added at the end of the command line, this is
* used as the OIES sequence number. The default is 1 as for new submissions.
*
* The standard input, as indicated above in the UNIX way of re-directing
* a file, is supposed to be of the b-file format. Lines starting with white
* space followed by the sharp (#) are ignored. Blank lines are also ignored.
* All other lines are supposed to contain the index and the number separated
* by white space...
*
* Complaints from within the program are sent to stderr.
*
* EXAMPLES
* java btxt2oeis 45 < primes.txt
* java btxt2oeis -m < b.txt
*
* NOTE
* The interface currently does not check that the sequence of first
* numbers in the standard input file is monotonic increasing.
*
* Submissions with two or less lines of approximately 80
* characters are punished by rising the "more" flag.
*
* @since 2006-10-29
* @author Richard J. Mathar
*/
class btxt2oeis
{
/** INSERT STH MORE EXPLICIT INTO THESE TWO EMPTY STRINGS */
String myName = "" ;
String myEmail = "" ;
/** The sequence of the integers */
Vector<BigInteger> a ;
/** the offset number */
int offs ;
/** the offset information for the first term >= 2 */
int offs2 ;
/** The OEIS sequence number */
int Anumb ;
boolean flagMore ;
boolean flagNonn ;
boolean mail ;
/** the maximum line length for the output lines */
final int outLLen = 80 ;
/** Constructor
*/
btxt2oeis(int A,boolean mailx)
{
a = new Vector() ;
Anumb=A ;
mail=mailx ;
/** no default for the offset */
offs = 0x7fffffff ;
flagMore = true ;
flagNonn = true ;
if ( myName.length() == 0)
myName = System.getProperty("user.name") ;
if ( myEmail.length() == 0)
{
myEmail = System.getProperty("user.name") ;
try
{
myEmail = myEmail.concat("(AT)"+System.getenv("DOMAINNAME")) ;
}
catch(Exception e)
{
}
}
}
/**
* @param num
*/
public void addInt(String num)
{
BigInteger n = new BigInteger(num) ;
a.add(n) ;
if ( n.compareTo(BigInteger.ZERO) == -1)
flagNonn =false ;
}
/** Check which term is first larger or equal to zero
* @return the second offset number for the %O lines
*/
int first2()
{
for(int i=0; i < a.size() ; i++)
{
if( a.elementAt(i).abs().compareTo(BigInteger.ONE) == 1)
return(i+1) ;
}
return(1) ;
}
/** Print the formatted output to stdout.
*
*/
public void print()
{
Formatter formatter = new Formatter(Locale.US) ;
formatter.format("A%06d",Anumb) ;
if( mail)
{
System.out.print("~s ") ;
if( Anumb == 1)
System.out.println("NEW SEQUENCE from "+myName) ;
else
System.out.println("COMMENT ON A"+formatter.toString()) ;
System.out.println("~c "+System.getProperty("user.name")) ;
}
System.out.println("%I "+formatter.toString()) ;
System.out.println("%C "+formatter.toString()) ;
int linSTU = 0 ;
/** Free space for the formatted output: outLLen minus
* 2 bytes for the EndNote flag, 1 for the blank, 7 for the Axxxxxx, 1 for the blank, reserved
* yields outLLen minus 11.
*/
String thisl = new String() ;
/* S, T, U lines for absolute values */
for(int i=0; i < a.size() && linSTU<3 ; i++)
{
String rep = a.elementAt(i).abs().toString() ;
if( thisl.length()+1+rep.length() <= outLLen-11)
{
if( thisl.length() == 0 )
thisl = rep ;
else
thisl=thisl.concat(","+rep) ;
}
else
{
thisl=thisl.concat(",") ;
System.out.println("%"+(char)('S'+linSTU) + " "+formatter.toString() + " " +thisl) ;
thisl=rep ;
linSTU++ ;
}
//System.out.println(""+a.elementAt(i)) ;
}
System.out.println("%"+(char)('S'+linSTU)+" "+formatter.toString() + " " +thisl) ;
/** Raise the 'more' flag if less than 2 lines of output had been filled*/
flagMore = ( linSTU < 2) ;
/* V, W, X lines for signed values */
if ( flagNonn == false)
{
linSTU = 0 ;
thisl = new String() ;
for(int i=0; i < a.size() && linSTU<3 ; i++)
{
String rep = a.elementAt(i).toString() ;
if( thisl.length()+1+rep.length() <= outLLen-11)
{
if( thisl.length() == 0 )
thisl = rep ;
else
thisl=thisl.concat(","+rep) ;
}
else
{
thisl=thisl.concat(",") ;
System.out.println("%"+(char)('V'+linSTU) + " "+formatter.toString() + " " +thisl) ;
thisl=rep ;
linSTU++ ;
}
}
System.out.println("%"+(char)('V'+linSTU)+" "+formatter.toString() + " " +thisl) ;
}
System.out.print("%K "+formatter.toString()) ;
if ( flagNonn)
System.out.print(" nonn") ;
else
System.out.print(" sign") ;
if ( flagMore)
System.out.print(",more") ;
System.out.println() ;
System.out.println("%O "+formatter.toString() + " " + offs+ ","+first2()) ;
Date now = new Date() ;
/* to do: date */
System.out.println("%A "+formatter.toString() + " " + myName +" (" + myEmail + "), "+ now.toString()) ;
}
public static void main(String [] args)
throws java.io.IOException
{
BufferedReader d = new BufferedReader(new InputStreamReader(System.in)) ;
/** default for the sequence number is 1 */
int A= 1 ;
int argno =0 ;
boolean mailx = false ;
while ( argno < args.length )
{
if ( args[argno].compareTo("-m") == 0 )
mailx =true ;
else
A = (new Integer(args[argno])).intValue() ;
argno++ ;
}
btxt2oeis oeis = new btxt2oeis(A,mailx) ;
String line = d.readLine() ;
while( line != null)
{
/* remove leading and trailing white space in the line */
line = line.trim() ;
/**
* Lines of the standard input that start with any or no white space
* followed by the hash and optionally more characters are ignored
* (comment lines)
*/
if( line.matches("(\\s)*#.*") )
;
/**
* lines of white space are ignored on input.
*/
else if( line.matches("(\\s)*") )
;
else if ( line.matches("[+-]?(\\d)+(\\s)+[+-]?(\\d)+") )
{
/* two signed numbers separated by white space ...*/
String [] twonu = line.split("(\\s)+",2) ;
/* use the first as the offset (if not yet done) */
Integer n=new Integer(twonu[0]) ;
if (n.intValue() < oeis.offs)
oeis.offs = n.intValue() ;
/* add the 2nd of these to the sequence */
oeis.addInt(twonu[1]) ;
}
else
System.err.println("ill-formatted " + line) ;
line = d.readLine() ;
}
oeis.print() ;
}
}
More information about the SeqFan
mailing list