nam Kermit68K ttl Command line parser module * Kermit68K: source file K68CM4 * * Author: Roberto Bagnara (Bagnara@Iboinfn.Bitnet), * Bologna University, Physics Department, July 1987. * * All rights reserved to Bologna University, Italy. * * Permission is granted to any individual or institution * to use, copy, or redistribute this software so long as * it is not sold for profit, provided this copyright * notice is retained. * * Modification History: * * Version Date Who Comments * * 1.0.00 870701 Roberto Bagnara First official release use DefsFile Edition equ 0 psect K68Commands4,0,0,Edition,0,0 ********************************** CmdLnP ***************************** * * * Kermit68K command line parser. * * * * Entry conditions : none * * * * Exit conditions : none * * * *********************************************************************** CmdLnP: BSR GetCmdLP Try to get the command line pointer TST.B D0 Success ? BEQ CmdLnP10 No, return MOVEA.L A0,A5 Yes, load pointer for parser functions MOVEQ #-1,D7 Say no protocol commands yet SF D5 Set the connect before flag to false SF D6 Set the connect after flag to false CmdLnP1 LEA RecBuf(A6),A4 This pointer is used by DoCmLA MOVEA.L A4,A0 Put here the command line options BSR ParsWrd Try to get a word from command line TST.B D0 Success ? BLT.S CmdLnP2 No, exit loop CMPI.B #'-',(A4)+ Options begins with dash BNE DoCmLA4 Not an options, give usage info BSR DoCmLA Got an option, handle it BRA.S CmdLnP1 Loop until the whole line is parsed CmdLnP2 TST.B Local(A6) Are we running in local mode ? BNE.S CmdLnP4 Yes, no problem CMPI.B #SndSrvIS,D7 Are we issuing a get command ? BEQ.S CmdLnP3 Yes, fatal error MOVEQ #SndGCmdS,D7 Are we issuing a finish command ? BEQ.S CmdLnP3 Yes, fatal error TST.B D5 Are we connecting trough the host line ? BEQ.S CmdLnP4 No, all ok CmdLnP3 LEA LBReqStr(PC),A0 Give message about -l and -b need BRA FatalEr Return to system CmdLnP4 CMPI.B #SndFileS,D7 Are we sending a file ? BEQ.S CmdLnP5 Yes, set the display flag CMPI.B #RecFileS,D7 Are we receiving a file ? BEQ.S CmdLnP5 Yes, set the display flag CMPI.B #SndSrvIS,D7 Are we getting a file ? BEQ.S CmdLnP5 Yes, set the display flag TST.B Argumnt2(A6) No, has a file as-name been specified ? BEQ.S CmdLnP5 No, all is fine LEA ABadUStr(PC),A0 Yes, bad use of the -a option BRA FatalEr Give message and exit the program CmdLnP5 TST.B Local(A6) Are we running in local mode ? BEQ.S CmdLnP6 No ST Display(A6) Yes, set the display flag on CmdLnP6 TST.B TermOut(A6) Are we outputting to the terminal ? BEQ.S CmdLnP7 No SF Display(A6) Yes, set the display flag off CmdLnP7 TST.B Quiet(A6) Has quiet been requested ? BEQ.S CmdLnP8 No SF Display(A6) Yes, set the display flag off TST.B D5 Is the connect before flag on ? BEQ.S CmdLnP8 No BSR DoCONN Yes, connect to the remote host CmdLnP8 TST.B D7 We must invoke the protocol switcher ? BLT.S CmdLnP10 No, let's return BSR TrnsInit Yes, initialize any protocol thing BSR KPSwtch Enter the protocol switcher TST.B D6 Is the connect after flag on ? BEQ.S CmdLnP9 No, return the cc from the automaton BSR DoCONN Yes, connect to the remote host ST D0 Return a positive completion code CmdLnP9 BRA SysExod CmdLnP10 RTS ********************************** DoCmLA ***************************** * * * Handle command line arguments. * * * * Entry conditions : A4.L pointer to a null terminated * * string containing the command line * * argument(s) * * * * Exit conditions : none * * * *********************************************************************** DoCmLA TST.B (A4) Null option ? BEQ.S DoCmLA4 Yes, give an error message DoCmLA1 MOVE.B (A4)+,D0 Get the option letter BNE.S DoCmLA2 Not null, handle it RTS End of option bundling, return DoCmLA2 SUBI.B #97,D0 Map the option letter from zero on CMPI.B #22,D0 Above 'w' ? BHI DoCmLA4 Yes, error EXT.W D0 No, extend to word size ADD.W D0,D0 Scale by a factor of two MOVE.W DoCmLA3(PC,D0.W),D0 Load service routine relative address JMP DoCmLA3(PC,D0.W) Jump to the option service routine DoCmLA3 DC.W DoCmLA16-DoCmLA3 -a option, file as-name DC.W DoCmLA14-DoCmLA3 -b option, line baud rate DC.W DoCmLA25-DoCmLA3 -c command, connect before DC.W DoCmLA4-DoCmLA3 -d invalid DC.W DoCmLA4-DoCmLA3 -e invalid DC.W DoCmLA24-DoCmLA3 -f option, finish remote server DC.W DoCmLA23-DoCmLA3 -g command, get file(s) from server DC.W DoCmLA18-DoCmLA3 -h request, give usage informations DC.W DoCmLA7-DoCmLA3 -i option, treate files as binary DC.W DoCmLA4-DoCmLA3 -j invalid DC.W DoCmLA20-DoCmLA3 -k command, receive file(s) to terminal DC.W DoCmLA11-DoCmLA3 -l option, set communication line DC.W DoCmLA4-DoCmLA3 -m invalid DC.W DoCmLA4-DoCmLA26 -n command, connect after DC.W DoCmLA4-DoCmLA3 -o invalid DC.W DoCmLA15-DoCmLA3 -p option, communication line parity DC.W DoCmLA9-DoCmLA3 -q option, be quiet DC.W DoCmLA19-DoCmLA3 -r command, receive file(s) DC.W DoCmLA21-DoCmLA3 -s command, send file(s) DC.W DoCmLA10-DoCmLA3 -t option, line turnaround handshake DC.W DoCmLA4-DoCmLA3 -u invalid DC.W DoCmLA4-DoCmLA3 -v invalid DC.W DoCmLA8-DoCmLA3 -w option, file collisions warnings DoCmLA4 LEA InvArStr(PC),A0 No, invalid argument, fatal error BRA FatalEr DoCmLA5 LEA InvABStr(PC),A0 Invalid argument bundling, fatal error BRA FatalEr DoCmLA6 LEA CnfAcStr(PC),A0 Conflicting commands, fatal error BRA FatalEr *** -i image option *** DoCmLA7 ST Binary(A6) Treat files as binary BRA DoCmLA1 See if options are bundled *** -w warning option *** DoCmLA8 ST Warning(A6) Give file collisions warnings BRA DoCmLA1 See if options are bundled *** -q quiet option *** DoCmLA9 ST Quiet(A6) Yes, be quiet during file transfers BRA DoCmLA1 See if options are bundled *** -t line turnaround option *** DoCmLA10 ST Duplex(A6) Set half duplex on SF Flow(A6) Set flow control off ST TurnFlag(A6) Set line turnaround handshake on MOVE.B Asc_DC1,TurnChar(A6) Set XON as the turnaround character BRA DoCmLA1 See if options are bundled *** -l set line option *** DoCmLA11 TST.B (A4) Invalid argument bundling ? BNE.S DoCmLA5 Yes, error LEA DataBuf(A6),A0 No, put here the line name BSR ParsWrd Get the line name, if any TST.B D0 Has the line name been specified ? BLT.S DoCmLA12 No, error LEA DataBuf(A6),A0 Reload pointer to the parsed line name MOVEQ #RdWrOp,D0 Try to open the new line MOVEQ #HostLine,D1 This is the channel number BSR FilOpen Open, if possible TST.B D0 Ok ? BEQ.S DoCmLA13 No, give an error message LEA LineName(A6),A1 This is the line name string EXG A0,A1 Adjust pointers MOVEQ #LinNamML,D0 Maximum line name length BSR CopyStr Copy now LEA ConLinNm(PC),A1 Point to the console line name BSR CompStr Compare the two line names TST.B D0 Are equal ? SEQ Local(A6) If not we are local, remote otherwise BEQ DoCmLA1 If local, leave speed unchanged MOVE.L #-1,Speed(A6) If remote, say speed unknown RTS DoCmLA12 LEA MisLNStr(PC),A0 Give missing line name error BRA FatalEr DoCmLA13 LEA UnOpLStr(PC),A0 Give unable to open line error BRA FatalEr *** -b set line baud rate option *** DoCmLA14 TST.B (A4) Invalid argument bundling ? BNE DoCmLA5 Yes, error MOVEQ #50,D1 Valid range lower bound MOVE.L #19200,D2 Valid range upper bound BSR ParsNm Try to get a valid number specification TST.B D1 Valid number on input ? BLT FatalEr1 No, fatal error BSR ChkBaud Check if requested speed is supported TST.B D1 Ok ? BEQ FatalEr1 No, fatal error MOVE.L D0,Speed(A6) Yes, set the baud rate variable MOVE.L D0,D2 Pass baud rate to ChanCtrl MOVEQ #HostLine,D1 Pass channel number to ChanCtrl MOVEQ #SetBaud,D0 Pass request code to ChanCtrl BSR ChanCtrl Physically set the host line baud rate RTS *** -p set parity option *** DoCmLA15 TST.B (A4) Invalid argument bundling ? BNE DoCmLA5 Yes, error LEA ParTable(PC),A1 No, point to the parity keywords table ST D1 This keyword is mandatory BSR ParsKyW Look for a valid parity specification TST.B D0 Ok ? BLT FatalEr1 No, fatal error MOVE.B D0,Parity(A6) Yes, set parity to the requested value RTS *** -a file as-name option *** DoCmLA16 TST.B (A4) Invalid argument bundling ? BNE DoCmLA5 Yes, error LEA Argumnt2(A6),A0 No, put here the file as-name BSR ParsWrd Get the file as-name, if any TST.B D0 Has it been specified ? BLT.S DoCmLA17 No, error RTS DoCmLA17 LEA MsFlNStr(PC),A0 Give missing file name error message BSR FatalEr *** -h help request *** DoCmLA18 LEA UsageStr(PC),A0 Point to the usage string BSR ConWrite Write it to the terminal BRA DoCmLA1 See if options are bundled *** -r receive command *** DoCmLA19 TST.B D7 Conflicting commands ? BGE DoCmLA6 Yes, error MOVEQ #RecInitS,D7 Start state for the protocol automaton BRA DoCmLA1 See if options are bundled *** -k receive to terminal command *** DoCmLA20 TST.B D7 Conflicting commands ? BGE DoCmLA6 Yes, error ST TermOut(A6) We want output to the terminal line MOVEQ #RecInitS,D7 Start state for the protocol automaton BRA DoCmLA1 See if options are bundled *** -s send command *** DoCmLA21 TST.B D7 Conflicting commands ? BGE DoCmLA6 Yes, error TST.B (A4) Invalid argument bundling ? BNE DoCmLA5 Yes, error LEA Argumnt1(A6),A0 Point to file name string BSR ParsInF Try to get a valid input file name TST.B D0 Some error ? BLT.S DoCmLA22 Yes MOVEQ #SndInitS,D7 No, Send-Init is the start state RTS DoCmLA22 CMPI.B #-3,D0 Has a file name been specified ? BEQ.S DoCmLA17 No, give missing file name message RTS Yes, message already given, return *** -g get command *** DoCmLA23 TST.B D7 Conflicting commands ? BGE DoCmLA6 Yes, error TST.B (A4) Invalid argument bundling ? BNE DoCmLA5 Yes, error LEA Argumnt1(A6),A0 Point to file name string BSR ParsWrd Try to get a file name TST.B D0 Missing file name ? BLT.S DoCmLA17 Yes, give error message MOVE.B #'R',ServrCmd(A6) Get command MOVEQ #SndSrvIS,D7 Send-Server-Init is the start state RTS *** -f finish command *** DoCmLA24 TST.B D7 Conflicting commands ? BGE DoCmLA6 Yes, error SUBA.L A2,A2 No arguments for SetGCmd MOVEQ #'F',D0 Finish server command BSR SetGCmd Set up for generic commands MOVEQ #SndGCmdS,D7 BRA DoCmLA1 See if options are bundled *** -c connect before *** DoCmLA25 ST D5 Set the connect before flag on BRA DoCmLA1 See if options are bundled *** -n connect after *** DoCmLA26 ST D6 Set the connect after flag on BRA DoCmLA1 See if options are bundled FatalEr BSR ConWrite Write the message FatalEr1 SF D0 Set a bad completion code BRA SysExod Return it to system ends END