home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / miscutil / xnote663.lha / src / XNote.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-21  |  2.6 KB  |  114 lines

  1.  
  2. /***   Copyright 1992 by D.W.Reisig.   ***/
  3.  
  4. unsigned char Version[] = "$VER: XNote 1.0 04-May-92 © 1992 D.W.Reisig\n";
  5.  
  6. #include <exec/types.h>
  7. #include <exec/execbase.h>
  8. #include <workbench/startup.h>
  9. #include <libraries/dosextens.h>
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12.  
  13. #define COMMENTSIZE    80
  14. #define XBUFSIZE    512
  15.  
  16. extern VOID Quit(LONG ReturnValue, LONG Result2);
  17.  
  18. ULONG StdOut;
  19. UBYTE *ErrMsg, *PrgName;
  20.  
  21.  
  22. /*---------------------------------------------------------------------------*/
  23.  
  24. VOID main(LONG argc, UBYTE *argv[])
  25. {
  26.   //  static UWORD Pad;  //  Align FileInfoBlocks if necessary
  27.   static struct FileInfoBlock InfoBlock;
  28.   static UBYTE Usage0[] = "Syntax: ";
  29.   static UBYTE Usage1[] = " <file>\nFunction: Execute a filenote replacing '@' by <file>\n";
  30.   static UBYTE NoAccess[] = ": Could not access file\n";
  31.   static UBYTE XBuf[XBUFSIZE];
  32.   UBYTE *FileNameChar=&Usage1[48];  //*** Make it easy to change the keychar (@)
  33.   ULONG FileLock;
  34.   UBYTE *FileName;
  35.   LONG  ci, ni, di;
  36.   UBYTE c;
  37.  
  38.   if (argc == 0)
  39.     _exit(RETURN_FAIL);
  40.  
  41.   PrgName = argv[0];
  42.   StdOut = Output();
  43.   
  44.   //***  Check command
  45.   
  46.   if ((argc<2) || ((argc>1)&&(*argv[1]=='?'))){
  47.     Write(StdOut, Usage0, sizeof(Usage0)-1);
  48.     Write(StdOut, PrgName, strlen(PrgName));
  49.     Write(StdOut, Usage1, sizeof(Usage1)-1);
  50.     Quit(RETURN_ERROR, ERROR_REQUIRED_ARG_MISSING);
  51.   }
  52.   FileName = argv[1];
  53.  
  54.   //***  Get access to file
  55.  
  56.   FileLock = Lock(FileName, ACCESS_READ);
  57.   if (!FileLock){
  58.     ErrMsg = NoAccess;
  59.     Quit(RETURN_FAIL, IoErr());
  60.   }
  61.   if (!Examine(FileLock, &InfoBlock)){
  62.     UnLock(FileLock);
  63.     ErrMsg = NoAccess;
  64.     Quit(RETURN_FAIL, IoErr());
  65.   }
  66.   UnLock(FileLock);
  67.   
  68.   //***  Copy Comment to execute buffer, replacing each keychar by the filename
  69.  
  70.   for (ci=0, di=0; (c=InfoBlock.fib_Comment[ci]) && (ci<COMMENTSIZE); ++ci){
  71.     if (c==*FileNameChar){
  72.       XBuf[di++]='"';
  73.       for (ni=0; c=FileName[ni]; ++ni)
  74.         XBuf[di++]=c;
  75.       XBuf[di++]='"';
  76.     } else
  77.       XBuf[di++]=c;
  78.   }
  79.   XBuf[di]='\0';
  80.  
  81.   //***  Execute the command in XBuf
  82.  
  83.   if (!Execute(XBuf, NULL , NULL)){
  84.     ErrMsg = ": Execution filenote failed\n";
  85.     Quit(RETURN_FAIL, IoErr());
  86.   }
  87.  
  88.   Quit(RETURN_OK, 0);
  89. }
  90.  
  91. /*---------------------------------------------------------------------------*/
  92.  
  93.  
  94. VOID Quit(LONG ReturnValue, LONG Result2)
  95. {
  96.   
  97.   if (ErrMsg){
  98.     Write(StdOut, PrgName, strlen(PrgName));
  99.     Write(StdOut, ErrMsg, strlen(ErrMsg));
  100.   }
  101.  
  102.   ((struct Process *)FindTask(0))->pr_Result2 = Result2;
  103.  
  104.   _exit(ReturnValue);
  105. }
  106.  
  107. /*---------------------------------------------------------------------------*/
  108.  
  109. Nop()
  110. {
  111.   return(0);
  112. }
  113.  
  114.