home *** CD-ROM | disk | FTP | other *** search
- * ------------------------------------------------------------------------
- * Program.....: EXPDEMO: Expand library v2.0 program, New version.
- * Author......: Pepijn Smits.
- * Date........: Jun 1991
- * Copyright...: (c)1991, Pepijn Smits Software, Rotterdam.
- * Notes.......: Clipper 5.01 Demo of Expand library v2.00
- * You may use parts of this program in Your own applications,
- * providing you do not distribute it in source code-form,
- * without mentionning the source (ie. Expand). Linking
- * without mentionning is thus OK (also applies to the library).
- * ------------------------------------------------------------------------
- * Compile and Link as Follows:
- * >Clipper EXPDEMO
- * >RTlink fi EXPDEMO li EXPAND [verbose] [/pll:base50]
- * Run EXPDEMO /BW for Black&White monitors on Color systems and Laptops
-
- SetupScreen()
- MyMenu()
- Set Color To
- @ MaxRow(),0
- Quit
-
- * ==================== MENU Routines =================
-
- Function MyMenu
- Local x
- Local Scr := ScrSave()
- /*
- Define the Menus choices in an Array, also place the Code to execute
- as the 5th array entry, as that one is not used by MouseMenu() itself.
- Each entry is: { Row, Col, MenuPrompt, Msg Code-Block, Menu Code-Block }
- */
- Local Mnu := { ;
- { 5, 31," Change Drive " , ;
- {||BottomMsg('Select the Default Drive')}, ;
- {||ChangeDrive() } }, ;
- { 6, 31," Directory Tree " , ;
- {||BottomMsg('Show Directory Tree')}, ;
- {||TreeTest() } }, ;
- { 7, 31," Show Status " , ;
- {||BottomMsg('Show Current status')} , ;
- {||Status() } }, ;
- { 8, 31," Write to 1-2-3 " , ;
- {||BottomMsg('Create a Sample .WK1 sheet')} , ;
- {||Test123() } }, ;
- { 9, 31," Real Uppercase " , ;
- {||BottomMsg('Test the Uppercase() function')} , ;
- {||TestUp() } }, ;
- { 10, 31," Dialing Voice " , ;
- {||BottomMsg('Use your Modem to Dial a number')} , ;
- {||TestDial() } }, ;
- { 11, 31," Reboot Computer " , ;
- {||BottomMsg('Reboot the Computer from program')}, ;
- {||if(ask('Reboot','Are you sure you want to reboot?'),Reboot(),NIL) } }, ;
- { 12, 31," Typematic Rate " , ;
- {||BottomMsg('Select the typematic rate')} , ;
- {||TestType() } }, ;
- { 13, 31," Environment Test " , ;
- {||BottomMsg('Test of Environment Functions')} , ;
- {||EnvTest() } }, ;
- { 14, 31," PRINT Tests " , ;
- {||BottomMsg('Use the PRINT interface')} , ;
- {||PRINTtest() } }, ;
- { 15, 31," ROM Scan Test " , ;
- {||BottomMsg('Let us have a look at what kind of Computer you have')}, ;
- {||ROMScanTest()} }, ;
- { 16, 31," Encode Test " , ;
- {||BottomMsg('Test the Encode() and Decode() functions')}, ;
- {||EncodeTest() } }, ;
- { 17, 31," Shell to DOS Test " , ;
- {||BottomMsg('Shell to DOS, with new PROMPT setting')}, ;
- {||DOSshell() } } }
-
- MyBox(4,29,18,51,'Menu')
- x := 1
- While x<>0
- x := MouseMenu(Mnu,x)
- if (x<>0)
- Eval(Mnu[x,5])
- else
- x := if(ask('Quit','Are you sure you want to Quit?'),0,1)
- end
- end
- ScrRestore(Scr)
- Return (NIL)
-
- * ==================== GENERAL SCREEN ROUTINES ===================
-
- Function SetupScreen
- Local i
-
- /* Fill Screen with ░'s by using RestScreen() */
- RestScreen(1,0,MaxRow(),MaxCol(),Replicate('░'+chr(7),(MaxCol()+1)*MaxRow()))
-
- /* Make a nice banner in the background */
- Set Color to
- for i := 1 to 8
- @ i+3,8 say StrTran(Banner(i," Expand"),chr(32),chr(176))
- @ i+12,8 say StrTran(Banner(i,"Library!"),chr(32),chr(176))
- next
-
- SetColor(NormColor())
- @ 0,0
- Center(0,' Clipper 5.01 » Expand Library v2.00 » Demonstration Program ')
-
- return (NIL)
-
- * ====================== Status =====================================
-
- Function Status
- /* Make a huge "OK" message */
- Local x := ScrSave()
-
- Msg('Status','Status is Coming right Up!',MsgColor())
-
- OkMsg('Status',;
- "DOS version : "+DosVersion()+";"+;
- "DOS default disk : "+Chr( GetDisk() + 65 )+':'+";"+;
- "Free disk space : "+Str(DiskSpace(),10)+" Bytes."+";"+;
- "Total disk space : "+Str(DiskTotal(),10)+" Bytes."+";"+;
- "Disk Fixed? : "+iif(DiskFixed(),'Yes.','No. ')+";"+;
- "Disk Remote? : "+iif(DiskRemote(),'Yes.','No. ')+";"+;
- "Valid drives are : A: thru "+Chr( LastDisk() + 65 )+':'+";"+;
- "PRINT installed? : "+iif(PrintThere(),'Yes.','No. ')+";"+;
- "My Name is : "+if( DOSmajor() < 3 ,'(Not available)',MyName() )+";"+;
- "Mouse Installed : "+iif(MouseThere(),'Yes.','No. ')+";"+;
- "The ROM is dated : "+DtoC( ROMdate() )+";"+;
- "Processor : "+CPUname()+";"+;
- "Append's Path : "+if(AppendThere(),AppendPath(),'(Not Installed)')+";"+;
- "Keyboard code : "+if(Len(KeybCode())=0,'US (Standard)',KeybCode()) )
-
- ScrRestore(x)
- Return (NIL)
-
- * ======================= MISC TEST ROUTINES ============================
-
- Function EncodeTest
- Local x
- x := Prompt('Encode Test','Enter string to Encode','')
- OkMsg('Encode Test','The Encoded string of;'+x+';is;'+Encode(x,'EXPAND')+;
- ';(Using EXPAND as key)',msgColor())
- Return (NIL)
-
- Function TestUp
- Local x := 'Préäçêköròtôÿpû, John (strange name huh?)'
- x := Alltrim(Prompt('Uppercase Test','Enter string to Uppercase',x))
- OkMsg('Uppercase Test','The Uppercase of;'+x+';is;'+Uppercase(x),msgColor())
- Return (NIL)
-
- Function ROMscanTest
- Local x
- x := (Prompt('ROM scan','Enter ID string to look for in ROM',''))
- if ROMscan(x)
- OkMsg('ROM scan','Well, It seems that you computer is a;'+;
- x+';(string was Found in ROM)',msgColor())
- else
- OkMsg('ROM scan','Sorry, but your computer is not a;'+;
- x+';(string was Not found in ROM)',msgColor())
- end
- Return (NIL)
-
- Function DOSshell
- Local Scr := ScrSave()
- if SetEnv('PROMPT','EXPAND DEMO Shell, Type EXIT to resume$_'+GetEnv('PROMPT'))
- * - Have to set Ptr to Env when Shelling, and restore current (of Course)
- set Color to
- cls
- Msg('Shell','Shelling to DOS',NormColor())
- @ MaxRow(),0
- x = EnvPtr(EnvOrig())
- !Command
- EnvPtr(x)
- * - Restoring Original Prompt. (Use Gete() and .Not. ReadEnv()!!)
- SetEnv('PROMPT',GetEnv('PROMPT'))
- else
- OkMsg('Shell Problem','Not enough room in environment to change PROMPT;Program will not Shell..')
- end
- scrRestore(Scr)
- Return (NIL)
-
- Function ChangeDrive
- Local i
- Local DriveMenu := {}
- For i := 0 to lastdisk()
- aAdd(DriveMenu, Chr(65+i)+":")
- Next
- i := MyAlert('Default drive','Select the New default drive',DriveMenu,MsgColor())
- if i != 0
- /* We're changing the Drive.. */
- if DOSvalue() >= 3.20
- /* Check for Logical drive acces if DOS 3.20 + */
- if GetDrive(i) <> 0
- if GetDrive(i) <> i
- OkMsg('Drive Select','Physical drive was not last accessed as this drive;'+;
- 'Enter Disk for Drive '+Chr(64+i)+':')
- SetDrive(i) /* Set the drive as Being last accessed */
- end
- end
- end
- SetDisk(i-1) /* select Default Disk */
- if GetDisk() <> i-1
- OkMsg('Invalid Drive','Sorry, It seems that drive '+chr(64+i)+': is invalid..')
- end
- end
- Return (NIL)
-
- Function Test123
- Local Scr := ScrSave()
- Msg('1-2-3 Test','Creating EXPAND.WK1..',MsgColor())
- if Create123('EXPAND.WK1',5,1)
- Width123(0,20)
- Width123(1,40)
- Write123(0,0,'Ah! There you are!')
- Write123(0,1,'Yes, I was just created by EXPAND.LIB!.')
- Write123(1,0,2342)
- Write123(1,1,'<- a number')
- Write123(2,0,7623.2393,2)
- Write123(2,1,'<- a number with 2 decimals..')
- Write123(3,0,date())
- Write123(3,1,'<- this should be today..')
- Write123(4,0,StoD('19670308'))
- Write123(4,1,'<- and this is my birthdate..')
- Write123(5,0,'That was it..')
- Write123(5,1,'Okidoki.. Return to the EXPAND.LIB now..')
- Close123()
- OkMsg('1-2-3 Test','Created EXPAND.WK1;Use 1-2-3 to see what is in it!',MsgColor())
- else
- okMsg('Error','Could not create EXPAND.WK1!',ErrColor())
- end
- scrRestore(Scr)
- return (NIL)
-
- Function TestDial
- Local port,prefix,Number,i
- Local prtMenu := {}
- Local Scr := ScrSave()
- for i := 1 to 4
- aAdd(prtMenu,'COM'+Str(i,1)+':')
- next
- Port := MyAlert('Voice Dial','Select port where Modem is connected',PrtMenu)
-
- /* If Port was selected, Go On */
- if Port<>0
- Port--
- /* Is there a Damn COM port anyway? */
- if IsPort(Port)
- prefix := If(MyAlert('Dial','Which dialing mode shall I use?',;
- {'Tone','Pulse'})=1,'ATDT','ATDP')
- Number := prompt('Dial','Please Enter Number to dial:','')
- Dtr(.t.,port)
- AtModem( prefix+Number+';',port)
- Msg('Dialing','Currently dialing;'+Number+';'+;
- 'Pick up phone any time and;press a key or the Mouse;when the phone rings')
- MouseKey()
- dtr(.f.,port)
- else
- OKmsg('Dial','You selected an Un-Installed Port!')
- end
- end
- ScrRestore(Scr)
- return (NIL)
-
- Function TestType
- Local x:=MyAlert('Typematic Rate','Set the Type-matic rate to',{"Fast","Slow","Don't care"})
- if x = 1
- fastkey()
- elseif x = 2
- slowkey()
- end
- return (NIL)
-
- Function PRINTtest
- okMsg('PRINT',"Sorry, haven't had the time to write the PRINT;"+;
- "test routines yet, but they all work allright;"+;
- "I can assure you that..")
- Return (NIL)
-
- * ===================== Directory Tree Routines ==========================
-
- Function TreeTest
- Local aTree := {}, aPath := {}, x, i
- Local Scr := ScrSave()
-
- SetColor(NormColor())
- MyBox(3,8,20,72,'Directory Tree')
-
- @ 4,11 say 'Select Directory:'
- @ 5,11 say replicate('─',59)
-
- /* Dirtree will scan the whole tree */
- Msg('Scanning',' Disk for directories..; ',MsgColor())
- SetColor(MsgColor())
-
- i := 1
- DirTree("\","\ (Root directory)",;
- aTree,aPath,{|s|Center(MidRow(),Str(i++,4))},"","")
-
- SetColor(NormColor())
- MouseChoice(6,11,19,69,aTree)
-
- OkMsg('Notice','By the way, directory;was not changed')
- ScrRestore(Scr)
-
- Return (NIL)
-
- /*
- DirTree: Nice recursive procedure that fills two Arrays
- With directory information
- */
-
- Procedure DirTree(cDir,cDirName,aTree,aPath,bMsg,s0,s1)
- Local aDir := {}
- Local x
- Local Code,DTA := Space(43)
-
- /* Add the current entries to the Tree data */
- aAdd(aTree,s0+cDirName)
- aAdd(aPath,cDir)
-
- /* Evaluate the Code block */
- Eval(bMsg,cDir)
-
- /* Get the directories in this dir */
- Code := FindFirst(cDir+'*.*',16,@DTA)
- While (Code=0) .and. ((FindName(DTA)='..') .or. (FindName(DTA)='.'))
- Code := FindNext(@DTA)
- end
-
- While Code=0
- if FindAttr(DTA)=16
- aAdd(aDir,FindName(@DTA))
- end
- code := FindNext(@DTA)
- End
-
- /* if any subdirectories */
- if len(aDir) > 0
- /* And now, recurse into the Tree... */
- for x := 1 to Len(aDir)-1
- DirTree(cDir+aDir[x]+'\',aDir[x],aTree,aPath,bMsg,s1+"├──",s1+"│ ")
- next
- x := Len(aDir)
- DirTree(cDir+aDir[x]+'\',aDir[x],aTree,aPath,bMsg,s1+"└──",s1+" ")
- endif
- /* That's it! */
- Return
-
- * =================== ENVIRONMENT TEST ROUTINES =======================
-
- Function EnvTest
- Local Scr := ScrSave()
- Local aEnv[EnvCount()]
- Local i
-
- for i:=1 to EnvCount()
- aEnv[i] := EnvStr(i)
- next
-
- MyBox(6,8,20,72,'Environment variables information')
-
- @ 8,11 say "Number of Enviroment strings....."+str(EnvCount())
- @ 9,11 say "Bytes in use by Environment......"+str(EnvUsed())
- @ 10,11 say "Bytes allocated to Environment..."+str(EnvSize())
- @ 12,11 say "The Environment strings:"
- @ 13,11 say Replicate('─',60)
-
- BottomMsg('Press Enter or Escape (or click) to resume, No editing allowed for security')
- MouseChoice(14,11,19,70,aEnv)
- ScrRestore(Scr)
- return (NIL)
-
- * ================== BASIC SCREEN ROUTINES =======================
-
- Function MidCol /* Middle Column value */
- Return (MaxCol()+1)/2
-
- Function MidRow /* Middle Row */
- Return (MaxRow()+1)/2
-
- Function ScrSave
- /* Saves screen and Status */
- Return ({PackScr(SaveScreen(0,0,MaxRow(),MaxCol())),Row(),Col(),SetColor()})
-
- Function ScrRestore(S)
- /* Restores It */
- Restscreen(0,0,MaxRow(),MaxCol(),UnpackScr(s[1]))
- DevPos(s[2],s[3])
- setColor(s[4])
- Return (NIL)
-
- Function Ask(Title,cText,Color)
- Return (MyAlert(Title,cText,{"No","Yes"},Color)=2)
-
- Function Center(Row,S)
- @ Row, (MidCol() - (Len(s)/2)) SAY S
- return (NIL)
-
- Function CenterBox(w,h,Title)
- MyBox(MidRow()-(h/2),MidCol()-(w/2),MidRow()+(h/2),MidCol()+(w/2),Title)
- Return (NIL)
-
- Function BottomMsg(s)
- Local C := SetColor(NormColor())
- @ MaxRow(),0
- @ MaxRow(),0 say s
- SetColor(C)
- Return (NIL)
-
- Function Msg(Title,cText,cColor)
- Local aText := aDelimit(cText)
- Local i := MidRow() - (Len(aText)/2)
- Local oldColor := SetColor(if(cColor<>NIL,cColor,SetColor()))
- CenterBox(aMaxLen(aText)+2,Len(aText)+2,Title)
- aEval(aText,{|s|Center(i++,s)})
- SetColor(oldColor)
- Return (NIL)
-
- Function Prompt(Title,Text,Default)
- Local Scr := ScrSave()
- Local x
- SetColor(MsgColor())
- Default := SubStr(Padr(Default,58),1,58)
- MyBox(9,9,12,71,Title)
- @ 10,11 say Text
- x := MouseGet(11,11,Default)
- ScrRestore(Scr)
- Return Alltrim(x)
-
- Function okMsg(Title,cText)
- MyAlert(Title,cText)
- Return (NIL)
-
- Function MyBox(t,l,b,r,Title)
- Shadow(t-1,l-3,b+1,r+3,if(ColorOn(),8,7))
- @ t-1,l-3 clear to b+1,r+3
- @ t,l TO b,r DOUBLE
- center(t,' '+title+' ')
- Return (NIL)
-
- * =================== Alternative Alert Function ===================
-
- Function MyAlert(cTitle,cMsg,aOptions,cColor)
- Local aMenu := {} /* Will contain Menu Choices */
- Local nTop,nLeft,nBottom,nRight
- Local x,MaxLen,SaveScr
- Local aMsg := aDelimit(cMsg) /* Expand cMsg into Array of strings */
-
- cColor := if(cColor=NIL,If(IsColor(),MsgColor(),''),cColor)
- aOptions := if(aOptions=NIL,{"Ok"},aOptions)
-
- x := 0 /* Get Length of Options Line */
- aEval(aOptions,{|s|x+=4+Len(s)}) /* 4 spaces more/option */
- MaxLen := Max(aMaxLen(aMsg),x) /* Max String length test */
- nTop := MidRow()-(Len(aMsg))/2 - 3 /* Set Coordinates */
- nLeft := MidCol()-(MaxLen)/2 - 2
- nBottom := nTop + len(aMsg) + 4
- nRight := nLeft + MaxLen + 3
- SaveScr := ScrSave()
- SetColor(cColor)
- MyBox(nTop,nLeft,nBottom,nRight,cTitle)
- x := MidCol()-x/2 /* Put options in aMenu (MouseMenu) */
- aEval(aOptions,{|s|aAdd(aMenu,{nBottom-2,x+1,' '+s+' '}),x+=4+len(s)})
- x := nTop+1 /* Draw strings */
- aEval(aMsg,{|s|Center(x++,s)})
-
- x := MouseMenu(aMenu) /* Get the option */
- ScrRestore(SaveScr)
- Return (x) /* And return the choice */
-
- Static Function aMaxLen(a)
- /* Return Length of largest string in array */
- Local MaxLen := 0
- aEval(a,{|s|MaxLen:=Max(Len(s),MaxLen)})
- return (MaxLen)
-
- Static Function aDelimit(cString,cDelimit)
- /* Split a semicolon (default) or otherwise delimited string into an Array */
- Local x,a := {}
- cDelimit := If(cDelimit=NIL,';',cDelimit)
- While (x := At(cDelimit,cString)) <>0
- aAdd(a,SubStr(cString,1,x-1))
- cString := SubStr(cString,x+Len(cDelimit))
- End
- aAdd(a,SubStr(cString,x+Len(cDelimit)))
- return (a)
-
- * ==================== COLOR selection Routines ====================
-
- Function ColorOn
- Return (isColor() .and. At("/BW",Upper(CommandLine()))=0)
-
- Function NormColor
- Return (if(ColorOn(),'BG+/B,N/BG',''))
-
- Function BoldColor
- Return (if(ColorOn(),'GR+/B,N/BG','w+/n,n/w'))
-
- Function InvColor
- Return (if(ColorOn(),'n/bg','n/w'))
-
- Function MsgColor
- Return (if(ColorOn(),'w+/BG,w+/n','n/w,w/m'))
-
- Function ErrColor
- Return (If(ColorOn(),'w+/R,w+/n','n/w,w/n'))
-