Changeset 2dbaece in git


Ignore:
Timestamp:
Apr 19, 1999, 3:20:02 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
8f84077f2d1c4511800cf59ce694b703056f4be3
Parents:
0c1144a6ba3e88d5019506c97bc7e06c6fc5b59b
Message:
* added sprintf, fprintf, printf


git-svn-id: file:///usr/local/Singular/svn/trunk@2995 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/standard.lib

    r0c1144 r2dbaece  
    1 // $Id: standard.lib,v 1.27 1999-02-10 14:30:42 siebert Exp $
     1// $Id: standard.lib,v 1.28 1999-04-19 13:20:02 obachman Exp $
    22//////////////////////////////////////////////////////////////////////////////
    33
    4 version="$Id: standard.lib,v 1.27 1999-02-10 14:30:42 siebert Exp $";
     4version="$Id: standard.lib,v 1.28 1999-04-19 13:20:02 obachman Exp $";
    55info="
    66LIBRARY: standard.lib   PROCEDURES WHICH ARE ALWAYS LOADED AT START-UP
     
    2121 quotient5(m1,m2) computes with a real general element of m2 by adjoining
    2222                  a new variable
     23 sprintf(fmt,...)     returns fomatted string
     24 fprintf(link,fmt,..) writes formatted string to link
     25 printf(fmt,...)      displays formatted string
    2326";
    2427
     
    718721}
    719722
     723//////////////////////////////////////////////////////////////////
     724///
     725/// sprintf, fprintf printf
     726///
     727proc sprintf(string fmt, list #)
     728"USAGE:    sprintf(fmt, ...) fmt string
     729RETURN:   string
     730PURPOSE:  sprintf performs output formatting. The first argument is a format
     731          control string. Additional arguments may be required, depending on
     732          the contents of the control string. A series of output characters is
     733          generated as directed by the control string; these characters are
     734          returned as a string. The control string is simply text to be copied,
     735          except that the string may contain conversion specifications. Do
     736          'help print:' for a listing of valid conversion specifications.
     737NOTE:     If one of the additional arguments is a list, then it should be
     738          enclosed once more into a list() command, since passing a list
     739          as an argument flattens the list by one level.
     740SEE ALSO: fprintf, printf, print, string
     741EXAMPLE : example sprintf; shows an example
     742"
     743{
     744  if (size(fmt) <= 1)
     745  {
     746    return (fmt);
     747  }
     748  int next, l, nnext;
     749  string ret;
     750  list formats = "%l", "%s", "%2l", "%2s", "%t", "%;", "%p", "%b";
     751  while (1)
     752  {
     753    if (size(#) <= 0)
     754    {
     755      return (ret + fmt);
     756    }
     757    nnext = 0;
     758    while (1)
     759    {
     760      nnext = find(fmt, "%", nnext + 1);
     761      if (nnext == 0)
     762      {
     763        next = 0;
     764        break;
     765      }
     766      l = 1;
     767      while (l <= size(formats))
     768      {
     769        next = find(fmt, formats[l], nnext);
     770        if (next == nnext) break;
     771        l++;
     772      }
     773      if (next == nnext) break;
     774    }
     775    if (next == 0)
     776    {
     777      return (ret + fmt);
     778    }
     779    ret = ret + fmt[1, next - 1] + print(#[1], formats[l]);
     780    if (size(fmt) <= (next + size(formats[l]) - 1))
     781    {
     782      return (ret);
     783    }
     784    # = delete(#, 1);
     785    fmt = fmt[next + size(formats[l]), size(fmt)-next-size(formats[l]) + 1];
     786  }
     787}
     788example
     789{
     790  ring r=0,(x,y,z),dp;
     791  module m=[1,y],[0,x+z];
     792  intmat M=betti(mres(m,0));
     793  list l = r, m, M;
     794  string s = sprintf("s:%s, l:%l", 1, 2); s;
     795  s = sprintf("s:%s", l); s;
     796  s = sprintf("s:%s", list(l)); s;
     797  s = sprintf("2l:%2l", list(l)); s;
     798  s = sprintf("%p", list(l)); s;
     799  s = sprintf("%;", list(l)); s;
     800  s = sprintf("%b", M); s;
     801}
     802
     803proc printf(string fmt, list #)
     804"USAGE:    printf(fmt, ...) fmt string
     805RETURN:   none
     806PURPOSE:  printf performs output formatting. The first argument is a format
     807          control string. Additional arguments may be required, depending on
     808          the contents of the control string. A series of output characters is
     809          generated as directed by the control string; these characters are
     810          displayed (i.e. printed to standard out).
     811          The control string is simply text to be copied, except that the
     812          string may contain conversion specifications.
     813          Do 'help print:' for a listing of valid conversion specifications.
     814
     815NOTE:     If one of the additional arguments is a list, then it should be
     816          enclosed once more into a list() command, since passing a list
     817          as an argument flattens the list by one level.
     818SEE ALSO: sprintf, fprintf, print, string
     819EXAMPLE : example printf; shows an example
     820"
     821{
     822  write("", sprintf(fmt, #));
     823}
     824example
     825{
     826  ring r=0,(x,y,z),dp;
     827  module m=[1,y],[0,x+z];
     828  intmat M=betti(mres(m,0));
     829  list l = r, m, M;
     830  printf("s:%s, l:%l", 1, 2);
     831  printf("s:%s", l);
     832  printf("s:%s", list(l));
     833  printf("2l:%2l", list(l));
     834  printf("%p", list(l));
     835  printf("%;", list(l));
     836  printf("%b", M);
     837}
     838
     839
     840proc fprintf(link l, string fmt, list #)
     841"USAGE:    fprintf(l, fmt, ...) l link; fmt string
     842RETURN:   none
     843PURPOSE:  fprintf performs output formatting. The second argument is a format
     844          control string. Additional arguments may be required, depending on
     845          the contents of the control string. A series of output characters is
     846          generated as directed by the control string; these characters are
     847          written to the link l.
     848          The control string is simply text to be copied, except that the
     849          string may contain conversion specifications.
     850          Do 'help print:' for a listing of valid conversion specifications.
     851
     852NOTE:     If one of the additional arguments is a list, then it should be
     853          enclosed once more into a list() command, since passing a list
     854          as an argument flattens the list by one level.
     855SEE ALSO: sprintf, printf, print, string
     856EXAMPLE : example fprintf; shows an example
     857"
     858{
     859  write(l, sprintf(fmt, #));
     860}
     861example
     862{
     863  ring r=0,(x,y,z),dp;
     864  module m=[1,y],[0,x+z];
     865  intmat M=betti(mres(m,0));
     866  list l = r, m, M;
     867  link li = ""; // link to stdout
     868  fprintf(li, "s:%s, l:%l", 1, 2);
     869  fprintf(li, "s:%s", l);
     870  fprintf(li, "s:%s", list(l));
     871  fprintf(li, "2l:%2l", list(l));
     872  fprintf(li, "%p", list(l));
     873  fprintf(li, "%;", list(l));
     874  fprintf(li, "%b", M);
     875}
     876 
     877   
     878 
     879 
     880 
     881
    720882/*
    721883proc minres(list #)
Note: See TracChangeset for help on using the changeset viewer.