Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "mbl_read_int.h"
00032 #include <vcl_cstdio.h>
00033 #include <vcl_iostream.h>
00034
00035 const int MAX_LEN = 20;
00036
00037
00038 int RD_ReadInt1(const char* q_str, int default_int,
00039 int min_int, int max_int)
00040 {
00041 char reply[MAX_LEN];
00042
00043 while (true)
00044 {
00045 if (min_int==0 && max_int==0)
00046 vcl_cout<<q_str<<" ("<<default_int<<") :";
00047 else
00048 vcl_cout<<q_str<<" ["<<min_int<<".."<<max_int<<"] ("<<default_int<<") :";
00049 vcl_cout.flush();
00050
00051 if (vcl_fgets(reply,MAX_LEN,stdin)!=NULL)
00052 {
00053 int r = default_int;
00054 if (reply[0]=='\n' || vcl_sscanf(reply,"%d",&r)>0)
00055 return r;
00056 }
00057 }
00058 }
00059
00060 int mbl_read_int(const char* q_str, int default_int)
00061 {
00062 return RD_ReadInt1(q_str,default_int,0,0);
00063 }
00064
00065 int mbl_read_int(const char* q_str, int default_int,
00066 int min_int, int max_int)
00067 {
00068 while (true)
00069 {
00070 int R = RD_ReadInt1(q_str,default_int,min_int,max_int);
00071 if (R<min_int)
00072 vcl_cout<<R<<": must be at least "<<min_int<<"\n";
00073 else if (R>max_int)
00074 vcl_cout<<R<<": must be no more than "<<max_int<<"\n";
00075 else
00076 return R;
00077 }
00078 }