home *** CD-ROM | disk | FTP | other *** search
-
- /*** Copyright 1992 by D.W.Reisig. ***/
-
- unsigned char Version[] = "$VER: XNote 1.0 04-May-92 © 1992 D.W.Reisig\n";
-
- #include <exec/types.h>
- #include <exec/execbase.h>
- #include <workbench/startup.h>
- #include <libraries/dosextens.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- #define COMMENTSIZE 80
- #define XBUFSIZE 512
-
- extern VOID Quit(LONG ReturnValue, LONG Result2);
-
- ULONG StdOut;
- UBYTE *ErrMsg, *PrgName;
-
-
- /*---------------------------------------------------------------------------*/
-
- VOID main(LONG argc, UBYTE *argv[])
- {
- // static UWORD Pad; // Align FileInfoBlocks if necessary
- static struct FileInfoBlock InfoBlock;
- static UBYTE Usage0[] = "Syntax: ";
- static UBYTE Usage1[] = " <file>\nFunction: Execute a filenote replacing '@' by <file>\n";
- static UBYTE NoAccess[] = ": Could not access file\n";
- static UBYTE XBuf[XBUFSIZE];
- UBYTE *FileNameChar=&Usage1[48]; //*** Make it easy to change the keychar (@)
- ULONG FileLock;
- UBYTE *FileName;
- LONG ci, ni, di;
- UBYTE c;
-
- if (argc == 0)
- _exit(RETURN_FAIL);
-
- PrgName = argv[0];
- StdOut = Output();
-
- //*** Check command
-
- if ((argc<2) || ((argc>1)&&(*argv[1]=='?'))){
- Write(StdOut, Usage0, sizeof(Usage0)-1);
- Write(StdOut, PrgName, strlen(PrgName));
- Write(StdOut, Usage1, sizeof(Usage1)-1);
- Quit(RETURN_ERROR, ERROR_REQUIRED_ARG_MISSING);
- }
- FileName = argv[1];
-
- //*** Get access to file
-
- FileLock = Lock(FileName, ACCESS_READ);
- if (!FileLock){
- ErrMsg = NoAccess;
- Quit(RETURN_FAIL, IoErr());
- }
- if (!Examine(FileLock, &InfoBlock)){
- UnLock(FileLock);
- ErrMsg = NoAccess;
- Quit(RETURN_FAIL, IoErr());
- }
- UnLock(FileLock);
-
- //*** Copy Comment to execute buffer, replacing each keychar by the filename
-
- for (ci=0, di=0; (c=InfoBlock.fib_Comment[ci]) && (ci<COMMENTSIZE); ++ci){
- if (c==*FileNameChar){
- XBuf[di++]='"';
- for (ni=0; c=FileName[ni]; ++ni)
- XBuf[di++]=c;
- XBuf[di++]='"';
- } else
- XBuf[di++]=c;
- }
- XBuf[di]='\0';
-
- //*** Execute the command in XBuf
-
- if (!Execute(XBuf, NULL , NULL)){
- ErrMsg = ": Execution filenote failed\n";
- Quit(RETURN_FAIL, IoErr());
- }
-
- Quit(RETURN_OK, 0);
- }
-
- /*---------------------------------------------------------------------------*/
-
-
- VOID Quit(LONG ReturnValue, LONG Result2)
- {
-
- if (ErrMsg){
- Write(StdOut, PrgName, strlen(PrgName));
- Write(StdOut, ErrMsg, strlen(ErrMsg));
- }
-
- ((struct Process *)FindTask(0))->pr_Result2 = Result2;
-
- _exit(ReturnValue);
- }
-
- /*---------------------------------------------------------------------------*/
-
- Nop()
- {
- return(0);
- }
-
-