Exemplo n.º 1
0
Arquivo: type.c Projeto: FDOS/freecom
int cmd_type(char *param)
{
    char buf[256];
    char **argv;
    int argc, opts, ec = E_None;
    int fd, len;

    if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
        return 1;

    /* Because no option was passed into scanCmdline() no
    	option can have been processed */
    assert(opts == 0);

    if(!argc) {
        error_req_param_missing();
        ec = E_Useage;
        goto errRet;
    }

    for(argc = 0; argv[argc]; ++argc) {
        if((fd = devopen(argv[argc], O_RDONLY)) == 0) {
            error_sfile_not_found(argv[argc]);
            ec = E_Other;
            break;
        }

        while((len = dos_read(fd, buf, sizeof(buf))) >= 0) {
            char *bufp, *p;
            if(cbreak) {
                dos_close(fd);
                ec = E_CBreak;
                goto errRet;
            }
            bufp = buf;
            for(p = buf; p < buf+len; p++) {
                if(*p == 26) break; /* CTRL-Z */
                if(*p == '\r' || *p == '\n') {
                    if(p > bufp) dos_write(1, bufp, p - bufp);
                    if(*p == '\n') dos_write(1, "\r\n", 2);
                    bufp = p + 1;
                }
            }
            dos_write(1, bufp, p - bufp);
            if (len < sizeof(buf) || *p == 26) break;
        }
        dos_close(fd);
        if(cbreak) {
            ec = E_CBreak;
            break;
        }
    }

errRet:
    freep(argv);

    return ec;
}
Exemplo n.º 2
0
BOOL FcbGetFileSize(xfcb FAR * lpXfcb)
{
  COUNT FcbDrive,
    FileNum;

  /* Build a traditional DOS file name                            */
  lpFcb = CommonFcbInit(lpXfcb, PriPathName, &FcbDrive);

  /* check for a device                                           */
  /* if we have an extension, can't be a device                   */
  if (IsDevice(PriPathName) || (lpFcb->fcb_recsiz == 0))
  {
    return FALSE;
  }
  FileNum = dos_open(PriPathName, O_RDONLY);
  if (FileNum >= 0)
  {
    LONG fsize;

    /* Get the size                                         */
    fsize = dos_getfsize(FileNum);

    /* compute the size and update the fcb                  */
    lpFcb->fcb_rndm = fsize / lpFcb->fcb_recsiz;
    if ((fsize % lpFcb->fcb_recsiz) != 0)
      ++lpFcb->fcb_rndm;

    /* close the file and leave                             */
    return dos_close(FileNum) == SUCCESS;
  }
  else
    return FALSE;
}
Exemplo n.º 3
0
Arquivo: openf.c Projeto: FDOS/freecom
int isDeviceName(char *const fnam)
{
  char *p;

  assert(fnam);

  if ((p = strpbrk(fnam, ":\\/")) != 0 /* has a colon or path component */
      && *p == ':'              /* has colon --> no path component */
      && p[1] == '\0'           /* at end of string */
      && p >= fnam + 2)
  {                             /* no simple drive letter */
    int fd;

    *p = '\0';                  /* strip off the colon to make it valid for DOS */

    /* open with read access only to prevent from creating
       disk fiels accidently */
    if ((fd = dos_open(fnam, O_RDONLY)) >= 0)
    {                           /* open OK */
      int rv;

      /* check for character device */
      rv = isadev(fd);
      dos_close(fd);
      if (rv)
        return 1;               /* is device name */
    }
    *p = ':';                   /* restore the original filename */
  }

  return 0;                     /* no device name */
}
Exemplo n.º 4
0
/*
 *  Routine to read in the start of the emudesk.inf file,
 *  expected to contain the #E and #Z lines.
 */
static void sh_rdinf(void)
{
    WORD    fh;
    LONG    size, ret;
    char    *pfile;
    char    tmpstr[MAX_LEN];

    infbuf[0] = 0;

    strcpy(tmpstr, INF_FILE_NAME);
    pfile = tmpstr;
    *pfile += dos_gdrv();                   /* set the drive        */

    ret = dos_open(pfile, ROPEN);
    if (ret < 0L)
        return;
    fh = (WORD)ret;

    /* NOTA BENE: all required info MUST be within INF_SIZE
     * bytes from the beginning of the file
     */
    size = dos_read(fh, INF_SIZE, infbuf);
    dos_close(fh);
    if (size < 0L)      /* if read error, force empty buffer */
        size = 0L;
    infbuf[size] = 0;
}
Exemplo n.º 5
0
VOID spol_gblk(VOID)
{
	BYTE    handle;

#if GEMDOS
	handle = Fopen( (const char *)spol_path, 0x0000 );
#else
	handle = dos_open( spol_path, 0x0000 );
#endif
	if (handle)
	{
#if GEMDOS
		Fseek( spol_fcnt, handle, 0x0000 );
		spol_cntr = (WORD)Fread( handle, SPLSIZE, (VOID *)spol_pbuf );
#else
		dos_lseek( handle, 0x0000, spol_fcnt );
		spol_cntr = dos_read( handle, SPLSIZE, spol_pbuf );
#endif
		if ( spol_cntr != SPLSIZE )
			spol_sts = TRUE;
		spol_fcnt += LW( spol_cntr );
#if GEMDOS
		Fclose( handle );
#else
		dos_close( handle );
#endif
		spol_ptr = spol_bufr;
	}
	else
	{
		spol_sts = TRUE;
		spol_cntr = 0;
	}
}
Exemplo n.º 6
0
Arquivo: res_r.c Projeto: FDOS/freecom
int enumFileResources(const char *const fnam
	, res_majorid_t id
	, res_callbackp_t fct
	, void * const arg)
{	resource_t res;
	unsigned long pos;
	int rc;
	int fd;

	assert(fct);
	if(!fnam)
		return -1;

	rc = 0;
#ifdef PTCHSIZE
	if((fd = open(fnam, O_RDONLY | O_BINARY)) < 0) {
#else
	if((fd = dos_open(fnam, O_RDONLY)) < 0) {
#endif
	 	rc = -1;
	 	dprintf(("[RES: Failed to open file: %s]\n", fnam));
#ifdef DEBUG
		perror("Open");
#endif
		/* resource file could be opened
			The first resource item is located at the end of the file,
			the var #("pos#(" is used to indicate the absolute position
			within the file as relative positioning is failing under
			NTFSdos {Tom Ehlert} */
	} else if((pos = filelength(fd)) != (unsigned long)-1L)
   	  while (1) {
		if(pos <= sizeof(res)				/* file corruption */
		 		/* read and verify the resource ID block */
		 || lseek(fd, pos -= sizeof(res), SEEK_SET) < 0		/* seek error */
	     || dos_read(fd, &res, sizeof(res)) != sizeof(res)		/* read error */
		 					/* file corruption as magic string is missing */
		 || memcmp(res.res_cookie, RES_COOKIE, sizeof(res.res_cookie)) != 0
		 		/* file corruption: not that many bytes left in file */
		 || pos < res.res_length
		 		/* failed to position to data block in the file */
		 || lseek(fd, pos -= res.res_length, SEEK_SET) < 0
		)
		 	break;
		 
		 if (res.res_majorID == id || id == RES_ID_ANY)
		 	if ((rc = fct(res.res_majorID
				 , res.res_minorID
				 , res.res_length
				 , fd
				 , arg)) != 0)
		    break;
	}  

	dos_close(fd);
	return rc;
}
Exemplo n.º 7
0
/*
 * Given the path to the file, open it and load the internal
 * partition table structure
 *
 * offset is the byte offset to the start of the volume system
 *
 * If test is 1 then additional tests are performed to make sure
 * it isn't a FAT or NTFS file system. This is used when autodetection
 * is being used to detect the volume system type.
 */
TSK_VS_INFO *
tsk_vs_dos_open(TSK_IMG_INFO * img_info, TSK_DADDR_T offset, uint8_t test)
{
    TSK_VS_INFO *vs;

    // clean up any errors that are lying around
    tsk_error_reset();

    vs = (TSK_VS_INFO *) tsk_malloc(sizeof(*vs));
    if (vs == NULL)
        return NULL;

    vs->vstype = TSK_VS_TYPE_DOS;
    vs->tag = TSK_VS_INFO_TAG;
    vs->img_info = img_info;

    vs->offset = offset;

    /* initialize settings */
    vs->part_list = NULL;
    vs->part_count = 0;
    vs->endian = 0;
    vs->block_size = img_info->sector_size;

    /* Assign functions */
    vs->close = dos_close;

    /* Load the partitions into the sorted list */
    if (dos_load_prim_table(vs, test)) {
        dos_close(vs);
        return NULL;
    }

    /* fill in the sorted list with the 'unknown' values */
    if (tsk_vs_part_unused(vs)) {
        dos_close(vs);
        return NULL;
    }

    return vs;
}
Exemplo n.º 8
0
/* 
 * Given the path to the file, open it and load the internal
 * partition table structure
 *
 * offset is the byte offset to the start of the volume system
 *
 * If test is 1 then additional tests are performed to make sure 
 * it isn't a FAT or NTFS file system
 */
MM_INFO *
dos_open(IMG_INFO * img_info, DADDR_T offset, uint8_t test)
{
    MM_INFO *mm = (MM_INFO *) mymalloc(sizeof(*mm));
    if (mm == NULL)
	return NULL;

    mm->mmtype = MM_DOS;
    mm->str_type = "DOS Partition Table";
    mm->img_info = img_info;

    mm->offset = offset;

    /* inititialize settings */
    mm->part_list = NULL;
    mm->first_part = mm->last_part = 0;
    mm->endian = 0;
    mm->dev_bsize = 512;
    mm->block_size = 512;


    /* Assign functions */
    mm->part_walk = dos_part_walk;
    mm->close = dos_close;

    /* Load the partitions into the sorted list */
    if (dos_load_prim_table(mm, test)) {
	dos_close(mm);
	return NULL;
    }

    /* fill in the sorted list with the 'unknown' values */
    if (mm_part_unused(mm)) {
	dos_close(mm);
	return NULL;
    }

    return mm;
}
Exemplo n.º 9
0
COUNT DosClose(COUNT hndl)
{
  psp FAR *p = MK_FP(cu_psp, 0);
  sft FAR *s;

  /* Test that the handle is valid                */
  if (hndl < 0)
    return DE_INVLDHNDL;

  /* Get the SFT block that contains the SFT      */
  if ((s = get_sft(hndl)) == (sft FAR *) - 1)
    return DE_INVLDHNDL;

  /* If this is not opened another error          */
  if (s->sft_count == 0)
    return DE_ACCESS;

  lpCurSft = (sfttbl FAR *) s;
/*
   remote sub sft_count.
 */
  if (s->sft_flags & SFT_FSHARED)
  {
    int2f_Remote_call(REM_CLOSE, 0, 0, 0, (VOID FAR *) s, 0, 0);
    p->ps_filetab[hndl] = 0xff;
    s->sft_flags = 0;
    return SUCCESS;
  }

  /* now just drop the count if a device, else    */
  /* call file system handler                     */
  if (s->sft_flags & SFT_FDEVICE)
  {
    p->ps_filetab[hndl] = 0xff;
    s->sft_count -= 1;
    return SUCCESS;
  }
  else
  {
    p->ps_filetab[hndl] = 0xff;
    s->sft_count -= 1;
    if (s->sft_count > 0)
      return SUCCESS;
    else
      return dos_close(s->sft_status);
  }
}
Exemplo n.º 10
0
BOOL FcbClose(xfcb FAR * lpXfcb)
{
  sft FAR *s;

  /* Convert to fcb if necessary                                  */
  lpFcb = ExtFcbToFcb(lpXfcb);

  /* Get the SFT block that contains the SFT      */
  if ((s = FcbGetSft(lpFcb->fcb_sftno)) == (sft FAR *) - 1)
    return FALSE;

  /* If this is not opened another error          */
  if (s->sft_count == 0)
    return FALSE;

  if (s->sft_flags & SFT_FSHARED)
  {
    int2f_Remote_call(REM_CLOSE, 0, 0, 0, (VOID FAR *) s, 0, 0);
  }

  /* now just drop the count if a device, else    */
  /* call file system handler                     */
  if (s->sft_flags & SFT_FDEVICE)
  {
    s->sft_count -= 1;
    return TRUE;
  }
  else
  {
    s->sft_count -= 1;
    if (s->sft_count > 0)
      return SUCCESS;
    else
    {
      /* change time and set file size                */
      dos_setftime(s->sft_status,
                   (date FAR *) & lpFcb->fcb_date,
                   (time FAR *) & lpFcb->fcb_time);
      dos_setfsize(s->sft_status,
                   lpFcb->fcb_fsize);
      return dos_close(s->sft_status) == SUCCESS;
    }
  }
}
Exemplo n.º 11
0
/*
 *  Routine to load program file pointed at by pfilespec, then create a
 *  new process context for it.  This is used to load a desk accessory.
 */
static void sndcli(BYTE *pfilespec)
{
    WORD    handle;
    WORD    err_ret;
    LONG    ldaddr, ret;

    KDEBUG(("sndcli(\"%s\")\n", (const char*)pfilespec));

    strcpy(D.s_cmd, pfilespec);

    ret = dos_open(D.s_cmd, ROPEN);
    if (ret >= 0L)
    {
        handle = (WORD)ret;
        err_ret = pgmld(handle, D.s_cmd, (LONG **)&ldaddr);
        dos_close(handle);
        /* create process to execute it */
        if (err_ret != -1)
            pstart(gotopgm, pfilespec, ldaddr);
    }
}
Exemplo n.º 12
0
static void sndcli(BYTE *pfilespec)
{
        register WORD   handle;
        WORD            err_ret;
        LONG            ldaddr;

#if DBG_GEMINIT
        kprintf("sndcli(\"%s\")\n", (const char*)pfilespec);
#endif
        strcpy(&D.s_cmd[0], pfilespec);

        handle = dos_open(D.s_cmd, ROPEN);
        if (!DOS_ERR)
        {
          err_ret = pgmld(handle, &D.s_cmd[0], (LONG **)&ldaddr);
          dos_close(handle);
                                                /* create process to    */
                                                /*   execute it         */
          if (err_ret != -1)
            pstart(gotopgm, pfilespec, ldaddr);
        }
}
Exemplo n.º 13
0
/*
 *  Perform the actual save of the EMUDESK.INF file
 */
static void save_to_disk(void)
{
    LONG ret, len;
    WNODE *w;
    WORD fh = -1;
    BYTE inf_file_name[sizeof(INF_FILE_NAME)];

    /* make sure user really wants to save the desktop */
    if (fun_alert(1, STSVINF) != 1)
        return;

    strcpy(inf_file_name, INF_FILE_NAME);
    inf_file_name[0] += gl_stdrv;   /* Adjust drive letter  */

    ret = dos_create(inf_file_name, 0);
    if (ret >= 0L)
    {
        fh = (WORD) ret;
        len = G.g_afsize - 1;
        ret = dos_write(fh, len, gl_afile);
        dos_close(fh);
        if (ret != len)             /* write error */
            ret = -1L;
    }
    if (ret < 0L)                   /* open error or write error */
        fun_alert(1, STNOINF);

    /*
     * now update any open windows for the directory containing
     * the saved file (as long as the file was created ok).
     */
    if (fh >= 0)                    /* file was created */
    {
        del_fname(inf_file_name);       /* convert to pathname ending in *.* */
        w = fold_wind(inf_file_name);   /* scan for matching windows */
        if (w)                          /* got one:                          */
            fun_rebld(w);               /* rebuild all matching open windows */
    }
}
Exemplo n.º 14
0
/*
*       Routine to read in the start of the emudesk.inf file,
*       expected to contain the #E and #Z lines.
*/
static void sh_rdinf(void)
{
        WORD    fh, size;
        char    *pfile;
        char    tmpstr[MAX_LEN];

        infbuf[0] = 0;

        strcpy(tmpstr, INF_FILE_NAME);
        pfile = tmpstr;
        *pfile += dos_gdrv();                   /* set the drive        */

        fh = dos_open(pfile, ROPEN);
        if ( !fh || DOS_ERR)
          return;
                                                /* NOTA BENE all required info */
                                                /*  MUST be within INF_SIZE    */
                                                /*  bytes from beg of file     */
        size = dos_read(fh, INF_SIZE, (LONG)infbuf);
        dos_close(fh);
        if (DOS_ERR)
          return;
        infbuf[size] = 0;
}
Exemplo n.º 15
0
/*
 * process the command line and execute the appropriate functions
 * full input/output redirection and piping are supported
 */
void parsecommandline(char *s, int redirect)
{
  char *in = 0;
  char *out = 0;
  char *fname0 = 0;
  char *fname1 = 0;
  char *nextcmd;

  int of_attrib = O_CREAT | O_TRUNC | O_WRONLY;
  int num;

  assert(s);

  dprintf(("[parsecommandline (%s)]\n", s));

#ifdef FEATURE_ALIASES
  aliasexpand(s, MAX_INTERNAL_COMMAND_SIZE);
  dprintf(("[alias expanded to (%s)]\n", s));
#endif

  if (tracemode)
  {                             /* Question after the variables expansion
                                   and make sure _all_ executed commands will
                                   honor the trace mode */
    /* 
     * Commands may be nested ("if errorlevel 1 echo done>test"). To
     * prevent redirecting FreeCOM prompts to user file, temporarily
     * revert redirection.
     */
    int redir_fdin, redir_fdout, answer;

    if (oldinfd != -1) {
        redir_fdin = dup (0);
        dup2 (oldinfd,  0);
    }
    if (oldoutfd != -1) {
        redir_fdout = dup (1);
        dup2 (oldoutfd, 1);
    }

    printprompt();
    outs(s);
    /* If the user hits ^Break, it has the same effect as
       usually: If he is in a batch file, he is asked if
       to abort all the batchfiles or just the current one */
    answer = userprompt(PROMPT_YES_NO);

    if (oldinfd  != -1) {
        dup2 (redir_fdin,  0);
        dos_close (redir_fdin);
    }
    if (oldoutfd != -1) {
        dup2 (redir_fdout, 1);
        dos_close (redir_fdout);
    }

    if (answer != 1) return;              /* "No" or ^Break   */
  }

  if(!redirect) {
  	docommand(s);
  	return;
  }

  assert(oldinfd == -1);  /* if fails something is wrong; should NEVER */
  assert(oldoutfd == -1); /* happen! -- 2000/01/13 ska*/

  num = get_redirection(s, &in, &out, &of_attrib);
  if (num < 0)                  /* error */
    goto abort;

  /* Set up the initial conditions ... */

  if (in || (num > 1))          /* Need to preserve stdin */
    oldinfd = dup(0);

  if (in)                       /* redirect input from this file name */
  {
    dos_close(0);
    if (0 != devopen(in, O_RDONLY))
    {
		error_redirect_from_file(in);
      goto abort;
    }
  }

  if (out || (num > 1))         /* Need to preserve stdout */
    oldoutfd = dup(1);

  /* Now do all but the last pipe command */
  while (num-- > 1)
  {
    dos_close(1);               /* Close current output file */
    if ((fname0 = tmpfn()) == 0)
      goto abort;
    dos_creat(fname0, 0);

    nextcmd = s + strlen(s) + 1;
    docommand(s);

    dos_close(1);
    dup2(oldoutfd, 1);

    dos_close(0);
    killtmpfn(fname1);          /* fname1 can by NULL */
    fname1 = fname0;
    fname0 = 0;
    dos_open(fname1, O_RDONLY);

    s = nextcmd;
  }

  /* Now set up the end conditions... */

  if (out)                      /* Final output to here */
  {
    dos_close(1);
    if (1 != devopen(out, of_attrib))
    {
		error_redirect_to_file(out);
      goto abort;
    }
  }
  else if (oldoutfd != -1)      /* Restore original stdout */
  {
    dos_close(1);
    dup2(oldoutfd, 1);
    dos_close(oldoutfd);
    oldoutfd = -1;
  }

  docommand(s);                 /* process final command */

abort:
  if (oldinfd != -1)            /* Restore original STDIN */
  {
    dos_close(0);
    dup2(oldinfd, 0);
    dos_close(oldinfd);
    oldinfd = -1;
  }

  if (oldoutfd != -1)           /* Restore original STDOUT */
  {
    dos_close(1);
    dup2(oldoutfd, 1);
    dos_close(oldoutfd);
    oldoutfd = -1;
  }

  killtmpfn(fname1);
  killtmpfn(fname0);

  if (out)
    free(out);

  if (in)
    free(in);
}
Exemplo n.º 16
0
Arquivo: MORE.C Projeto: FDOS/more
int
main (int argc, char **argv)
{
  char *s, *prompt;
  char drive[_MAX_DRIVE];		/* for _splitpath, _makepath */
  char dir[_MAX_DIR];			/* for _splitpath, _makepath */
  char file[_MAX_FNAME];		/* for _splitpath, _makepath */
  char ext[_MAX_EXT];			/* for _splitpath, _makepath */
  char fullpath[_MAX_PATH];		/* the full path after _makepath */

  int i;
  int next;				/* return value of more() function */
  int done;				/* flag for findfirst, findnext */
  int exitval;				/* exit value */

  int pfile;				/* file handle */
  struct ffblk ffblk;			/* findfirst, findnext block */
  nl_catd cat;				/* message catalog */
  int stdinhandle;
  int someFileFound;
  int more_prompt_needed = 0;


  GetScreenSize();

  /* Open the message catalog */

  cat = catopen ("more", 0);
  prompt = catgets (cat, 2, 0, "More");

  /* Evaluate the files on the command line */


  /* we want to use DOS to get characters from STDIN.
     STDIN MAY have been redirected, which is not acceptable to more
     
     however, we want to be able to work with CTTY COM1
     so using the BIOS isn't an option as well.
     
     so we duplicate STDIN to a new handle,
     and duplicate STDERR (possibly COM1) to STDIN
     
     then STDIN is available for character input again
  */

  stdinhandle = dos_dup(0);
  if (stdinhandle < 0)
    {
      printf("??\n");
      exit(1);
    }
	
  dos_close(0);	
	
  if (dos_dup2(2,0))
    {
      printf("???\n");
      exit(1);   
    }
	    
  for (i = 1; i < argc; i++)
    {
      /* Check if we are asking for help */
	
      if (argv[i][0] != '/')
	{
	  continue;
	}
      /* This is a flag character */

      /* Add any code here that deals with special flag chars */

      switch (argv[i][1])
	{
	case '?':
	case 'H':
	case 'h':
	  /* print usage and quit */

	  s = catgets (cat, 0, 0, "Display the contents of a text file one screen at a time");
	  printf ("MORE: %s\n", s);
	  usage (cat);
	  catclose (cat);
	  exit (0);
	  break;
	      
	case 't':
	case 'T':
	  if ( argv[i][2] < '1' || argv[i][2] > '9')
	    {
	      printf("MORE:%s\n",
		     catgets(cat,1,3,"option /Tabs must be /T1..9 (default 4)\n"));
	    			
	      exit(1);	
	    }
	  TABSIZE = argv[i][2] - '0';
	  break;	    		
	      

	default:
	  /* Not a recognized option */

	  s = catgets (cat, 1, 0, "Not a recognized option");
	  printf ("MORE: %s: %s\n", argv[i], s);
	  usage (cat);
	  catclose (cat);
	  exit (1);
	  break;
	} /* switch */
    } 
    
    
  someFileFound = 0;	
  for (i = 1; i < argc; i++)
    {
      /* Check if we are asking for help */

      if (argv[i][0] == '/')	/* arguments have been handled already */
      	{
	  continue;
      	}
      
      someFileFound = 1;	

      /* Assume a file.  Open it and display it. */

      /* Note that findfirst, findnext only return the base file
         name in ff_name, and not the path.  The search still
         works with a path, but you don't get it back.  So we
         have to preserve the full path to the file using
         _splitpath and _makepath. */

      _splitpath (argv[i], drive, dir, file, ext);
      done = findfirst (argv[i], &ffblk, 0);

      if (done)
	{
	  /* We were not able to find a file. Display a message and
	     set the exit value. */
	
	  s = catgets (cat, 1, 1, "No such file");
	  printf ( "MORE: %s: %s\n", argv[i], s);
	  exit(1);
	}

      while (!done)
	{
	  /* We have found a file, so open it and display it.  Set
	     the exit value to 'successful' */
	     
	  if (more_prompt_needed)
	    {
	      next = prompt_for_more(fullpath);
	      /* Find next file */
	      /* but only if user did not press 'Q' during more() */
	
	      if (next == 0)
		{
		  exit(0);
		}
	    }  

	  _makepath (fullpath, drive, dir, ffblk.ff_name, "");
	  pfile = dos_open (fullpath, 0);

	  if (pfile < 0)
	    {
	      s = catgets (cat, 1, 2, "Cannot open file");
	      printf ( "MORE: %s: %s\n", ffblk.ff_name, s);
	      exit(1);
	    }
	 
	  more_prompt_needed = 1; 
	  
	  more (pfile, ffblk.ff_name, prompt);
	  dos_close (pfile);
	  exitval = 0;


	  done = findnext (&ffblk);
	} /* while */
    } /* for */
    

  if (!someFileFound)		/* nothing done - use STDIN */
    {
      /* Process the standard input.  Return from more() is not used. */

      s = catgets (cat, 2, 1, "<STDIN>");
      more (stdinhandle, s, prompt);
      exitval = 0;
    }
    

  /* Done */

  catclose (cat);

  return exitval;
}
Exemplo n.º 17
0
/*
 *  Initialize the application list by reading in the EMUDESK.INF
 *  file, either from memory or from the disk if the shel_get
 *  indicates no message is there.
 */
void app_start(void)
{
    WORD i, x, y;
    ANODE *pa;
    WSAVE *pws;
    BYTE *pcurr, *ptmp, *pauto = NULL;
    WORD envr, xcnt, ycnt, xcent, wincnt, dummy;

    /* remember start drive */
    gl_stdrv = dos_gdrv();

    G.g_pbuff = gl_buffer;

    for (i = NUM_ANODES - 2; i >= 0; i--)
        G.g_alist[i].a_next = &G.g_alist[i + 1];
    G.g_ahead = (ANODE *) NULL;
    G.g_aavail = G.g_alist;
    G.g_alist[NUM_ANODES - 1].a_next = (ANODE *) NULL;

    app_rdicon();

    G.g_wicon = (12 * gl_wschar) + (2 * G.g_iblist[0].ib_xtext);
    G.g_hicon = G.g_iblist[0].ib_hicon + gl_hschar + 2;

    xcnt = G.g_wdesk / (G.g_wicon+MIN_WINT);/* icon count */
    G.g_icw = G.g_wdesk / xcnt;             /* width */

    ycnt = G.g_hdesk / (G.g_hicon+MIN_HINT);/* icon count */
    G.g_ich = G.g_hdesk / ycnt;             /* height */

    shel_get(gl_afile, SIZE_AFILE);
    if (gl_afile[0] != '#')                 /* invalid signature    */
    {                                       /*   so read from disk  */
        LONG ret;
        WORD fh;
        char inf_file_name[16];
        strcpy(inf_file_name, INF_FILE_NAME);
        inf_file_name[0] += gl_stdrv;         /* Adjust drive letter  */
        ret = dos_open(inf_file_name, 0x0);
        if (ret >= 0L)
        {
            fh = (WORD) ret;
            ret = dos_read(fh, SIZE_AFILE, gl_afile);
            G.g_afsize = (ret < 0L) ? 0L : ret;
            dos_close(fh);
            gl_afile[G.g_afsize] = '\0';
        }
    }

    /* If there's still no desktop.inf data, use built-in now: */
    if (gl_afile[0] != '#')
    {
        LONG drivemask;
        char *text;
        int icon_index = 0;
        int drive_x = 0, drive_y = 0;
        int trash_x, trash_y;
        int icon_type;
        char drive_letter;

        /* Environment and Windows */
        strcat(gl_afile, desk_inf_data1);

        /* Scan for valid drives: */
        drivemask = dos_sdrv(dos_gdrv());
        for (i = 0; i < BLKDEVNUM; i++)
        {
            if (drivemask&(1L<<i))
            {
                x = strlen(gl_afile);
                drive_x = icon_index % xcnt; /* x position */
                drive_y = icon_index / xcnt; /* y position */
                icon_type = (i > 1) ? 0 /* Hard disk */ : 1 /* Floppy */;
                drive_letter = 'A' + i;
                rsrc_gaddr(R_STRING, STDISK, (void **)&text);
                sprintf(gl_afile + x, "#M %02X %02X %02X FF %c %s %c@ @\r\n",
                        drive_x, drive_y, icon_type, drive_letter, text, drive_letter);
                icon_index++;
            }
        }

        /* Copy core data part 2 */
        strcat(gl_afile, desk_inf_data2);

        /* add Trash icon to end */
        x = strlen(gl_afile);
        trash_x = 0;            /* Left */
        trash_y = ycnt-1;       /* Bottom */
        if (drive_y >= trash_y) /* if the last drive icon overflows over */
            trash_x = xcnt-1;   /*  the trash row, force trash to right  */
        rsrc_gaddr(R_STRING, STTRASH, (void **)&text);
        sprintf(gl_afile + x, "#T %02X %02X 03 FF   %s@ @\r\n",
                trash_x, trash_y, text);
        G.g_afsize = strlen(gl_afile);
    }

    wincnt = 0;
    inf_rev_level = 0;
    pcurr = gl_afile;

    while(*pcurr)
    {
        if (*pcurr++ != '#')            /* look for start of line */
            continue;

        switch(*pcurr)
        {
        case 'R':                       /* revision level */
            pcurr++;
            pcurr = scan_2(pcurr,&inf_rev_level);
            break;
        case 'Z':                       /* autorun: Z nn pathname@ */
            pcurr = scan_str(pcurr+5,&pauto);   /* save pathname in buffer */
            break;                              /* (a bit wasteful)        */
        case 'T':                       /* Trash */
        case 'M':                       /* Media (Hard/Floppy)  */
        case 'G':                       /* GEM Application      */
        case 'Y':                       /* GEM App. with parms  */
        case 'F':                       /* File (DOS w/o parms) */
        case 'P':                       /* Parm (DOS w/ parms)  */
        case 'D':                       /* Directory            */
        case 'I':                       /* Executable file icon     */
        case 'N':                       /* Non-executable file icon */
            pa = app_alloc(TRUE);
            if (!pa)                    /* paranoia */
                return;
            pcurr = app_parse(pcurr, pa);
            if ((pa->a_type == AT_ISFILE) && pauto)
            {                           /* autorun exists & not yet merged */
                if (strcmp(pauto,pa->a_pappl) == 0)
                {
                    pa->a_flags |= AF_AUTORUN;  /* it's this program */
                    pauto = NULL;               /*  (and no other)   */
                }
            }
            break;
        case 'W':                       /* Window               */
            pcurr++;
            if (wincnt < NUM_WNODES)
            {
                pws = &G.g_cnxsave.cs_wnode[wincnt];
                pcurr = scan_2(pcurr, &dummy);
                pcurr = scan_2(pcurr, &pws->vsl_save);
/* BugFix       */
                pcurr = scan_2(pcurr, &pws->x_save);
                pws->x_save *= gl_wchar;
                pcurr = scan_2(pcurr, &pws->y_save);
                pws->y_save *= gl_hchar;
                pcurr = scan_2(pcurr, &pws->w_save);
                pws->w_save *= gl_wchar;
                pcurr = scan_2(pcurr, &pws->h_save);
                pws->h_save *= gl_hchar;
/* */
                pcurr = scan_2(pcurr, &pws->obid_save);
                ptmp = pws->pth_save;
                pcurr++;
                while(*pcurr != '@')
                    *ptmp++ = *pcurr++;
                *ptmp = '\0';
                wincnt += 1;
            }
            break;
        case 'E':                       /* Environment */
            pcurr++;
            pcurr = scan_2(pcurr, &envr);
            G.g_cnxsave.cs_view = ( (envr & INF_E1_VIEWTEXT) != 0);
            G.g_cnxsave.cs_sort = ( (envr & INF_E1_SORTMASK) >> 5);
            G.g_cnxsave.cs_confdel = ( (envr & INF_E1_CONFDEL) != 0);
            G.g_cnxsave.cs_confcpy = ( (envr & INF_E1_CONFCPY) != 0);
            G.g_cnxsave.cs_dblclick = envr & INF_E1_DCMASK;

            pcurr = scan_2(pcurr, &envr);
            G.g_cnxsave.cs_confovwr = ( (envr & INF_E2_ALLOWOVW) == 0);
            G.g_cnxsave.cs_mnuclick = ( (envr & INF_E2_MNUCLICK) != 0);
            menu_click(G.g_cnxsave.cs_mnuclick, 1); /* tell system */
            if (envr & INF_E2_IDTDATE)
                G.g_cnxsave.cs_datefmt = DATEFORM_IDT;
            else
                G.g_cnxsave.cs_datefmt = (envr & INF_E2_DAYMONTH) ? DATEFORM_DMY : DATEFORM_MDY;
            if (envr & INF_E2_IDTTIME)
                G.g_cnxsave.cs_timefmt = TIMEFORM_IDT;
            else
                G.g_cnxsave.cs_timefmt = (envr & INF_E2_24HCLOCK) ? TIMEFORM_24H : TIMEFORM_12H;
            sound(FALSE, !(envr & INF_E2_SOUND), 0);

            pcurr = scan_2(pcurr, &dummy);  /* skip video stuff */
            pcurr = scan_2(pcurr, &dummy);

            pcurr = scan_2(pcurr, &envr);
            if (envr & INF_E5_NOSORT)
                G.g_cnxsave.cs_sort = CS_NOSORT;
            break;
        }
    }

    for (pa = G.g_ahead; pa; pa = pa->a_next)
    {
        if (pa->a_flags & AF_ISDESK)
        {
            x = pa->a_xspot * G.g_icw;
            y = pa->a_yspot * G.g_ich + G.g_ydesk;
            snap_disk(x, y, &pa->a_xspot, &pa->a_yspot, 0, 0);
        }
    }

    /* set up outlines for dragging files displayed as icons */
    G.g_nmicon = 9;     /* number of points */
    memset(G.g_xyicon, 0, sizeof(G.g_xyicon));
    xcent = (G.g_wicon - G.g_iblist[0].ib_wicon) / 2;
    G.g_xyicon[0] = xcent;
    G.g_xyicon[2] = xcent;
    G.g_xyicon[3] = G.g_hicon-gl_hschar-2;
    G.g_xyicon[5] = G.g_hicon-gl_hschar-2;
    G.g_xyicon[7] = G.g_hicon;
    G.g_xyicon[8] = G.g_wicon;
    G.g_xyicon[9] = G.g_hicon;
    G.g_xyicon[10] = G.g_wicon;
    G.g_xyicon[11] = G.g_hicon-gl_hschar-2;
    G.g_xyicon[12] = G.g_wicon-xcent;
    G.g_xyicon[13] = G.g_hicon-gl_hschar-2;
    G.g_xyicon[14] = G.g_wicon-xcent;
    G.g_xyicon[16] = xcent;

    /* set up outlines for dragging files displayed as text */
    G.g_nmtext = 5;     /* number of points */
    memset(G.g_xytext, 0, sizeof(G.g_xytext));
    G.g_xytext[2] = gl_wchar * DRAG_BOX_WIDTH;
    G.g_xytext[4] = gl_wchar * DRAG_BOX_WIDTH;
    G.g_xytext[5] = gl_hchar;
    G.g_xytext[7] = gl_hchar;
}